IB/uverbs: Refactor uverbs_finalize_objects
uverbs_finalize_objects is currently used only to commit or abort objects. Since we want to add automatic allocation/free of PTR_IN attributes, moving it to uverbs_ioctl.c and renamit it to uverbs_finalize_attrs. Signed-off-by: Matan Barak <matanb@mellanox.com> Signed-off-by: Leon Romanovsky <leonro@mellanox.com> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
This commit is contained in:
committed by
Jason Gunthorpe
parent
1114b0a8a8
commit
9442d8bf1d
@@ -779,43 +779,3 @@ int uverbs_finalize_object(struct ib_uobject *uobj,
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int uverbs_finalize_objects(struct uverbs_attr_bundle *attrs_bundle,
|
|
||||||
struct uverbs_attr_spec_hash * const *spec_hash,
|
|
||||||
size_t num,
|
|
||||||
bool commit)
|
|
||||||
{
|
|
||||||
unsigned int i;
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
for (i = 0; i < num; i++) {
|
|
||||||
struct uverbs_attr_bundle_hash *curr_bundle =
|
|
||||||
&attrs_bundle->hash[i];
|
|
||||||
const struct uverbs_attr_spec_hash *curr_spec_bucket =
|
|
||||||
spec_hash[i];
|
|
||||||
unsigned int j;
|
|
||||||
|
|
||||||
for (j = 0; j < curr_bundle->num_attrs; j++) {
|
|
||||||
struct uverbs_attr *attr;
|
|
||||||
const struct uverbs_attr_spec *spec;
|
|
||||||
|
|
||||||
if (!uverbs_attr_is_valid_in_hash(curr_bundle, j))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
attr = &curr_bundle->attrs[j];
|
|
||||||
spec = &curr_spec_bucket->attrs[j];
|
|
||||||
|
|
||||||
if (spec->type == UVERBS_ATTR_TYPE_IDR ||
|
|
||||||
spec->type == UVERBS_ATTR_TYPE_FD) {
|
|
||||||
int current_ret;
|
|
||||||
|
|
||||||
current_ret = uverbs_finalize_object(attr->obj_attr.uobject,
|
|
||||||
spec->obj.access,
|
|
||||||
commit);
|
|
||||||
if (!ret)
|
|
||||||
ret = current_ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -94,9 +94,6 @@ struct ib_uobject *uverbs_get_uobject_from_context(const struct uverbs_obj_type
|
|||||||
struct ib_ucontext *ucontext,
|
struct ib_ucontext *ucontext,
|
||||||
enum uverbs_obj_access access,
|
enum uverbs_obj_access access,
|
||||||
int id);
|
int id);
|
||||||
int uverbs_finalize_object(struct ib_uobject *uobj,
|
|
||||||
enum uverbs_obj_access access,
|
|
||||||
bool commit);
|
|
||||||
/*
|
/*
|
||||||
* Note that certain finalize stages could return a status:
|
* Note that certain finalize stages could return a status:
|
||||||
* (a) alloc_commit could return a failure if the object is committed at the
|
* (a) alloc_commit could return a failure if the object is committed at the
|
||||||
@@ -112,9 +109,8 @@ int uverbs_finalize_object(struct ib_uobject *uobj,
|
|||||||
* function. For example, this could happen when we couldn't destroy an
|
* function. For example, this could happen when we couldn't destroy an
|
||||||
* object.
|
* object.
|
||||||
*/
|
*/
|
||||||
int uverbs_finalize_objects(struct uverbs_attr_bundle *attrs_bundle,
|
int uverbs_finalize_object(struct ib_uobject *uobj,
|
||||||
struct uverbs_attr_spec_hash * const *spec_hash,
|
enum uverbs_obj_access access,
|
||||||
size_t num,
|
bool commit);
|
||||||
bool commit);
|
|
||||||
|
|
||||||
#endif /* RDMA_CORE_H */
|
#endif /* RDMA_CORE_H */
|
||||||
|
|||||||
@@ -167,6 +167,45 @@ static int uverbs_process_attr(struct ib_device *ibdev,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int uverbs_finalize_attrs(struct uverbs_attr_bundle *attrs_bundle,
|
||||||
|
struct uverbs_attr_spec_hash *const *spec_hash,
|
||||||
|
size_t num, bool commit)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < num; i++) {
|
||||||
|
struct uverbs_attr_bundle_hash *curr_bundle =
|
||||||
|
&attrs_bundle->hash[i];
|
||||||
|
const struct uverbs_attr_spec_hash *curr_spec_bucket =
|
||||||
|
spec_hash[i];
|
||||||
|
unsigned int j;
|
||||||
|
|
||||||
|
for (j = 0; j < curr_bundle->num_attrs; j++) {
|
||||||
|
struct uverbs_attr *attr;
|
||||||
|
const struct uverbs_attr_spec *spec;
|
||||||
|
|
||||||
|
if (!uverbs_attr_is_valid_in_hash(curr_bundle, j))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
attr = &curr_bundle->attrs[j];
|
||||||
|
spec = &curr_spec_bucket->attrs[j];
|
||||||
|
|
||||||
|
if (spec->type == UVERBS_ATTR_TYPE_IDR ||
|
||||||
|
spec->type == UVERBS_ATTR_TYPE_FD) {
|
||||||
|
int current_ret;
|
||||||
|
|
||||||
|
current_ret = uverbs_finalize_object(
|
||||||
|
attr->obj_attr.uobject,
|
||||||
|
spec->obj.access, commit);
|
||||||
|
if (!ret)
|
||||||
|
ret = current_ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static int uverbs_uattrs_process(struct ib_device *ibdev,
|
static int uverbs_uattrs_process(struct ib_device *ibdev,
|
||||||
struct ib_ucontext *ucontext,
|
struct ib_ucontext *ucontext,
|
||||||
const struct ib_uverbs_attr *uattrs,
|
const struct ib_uverbs_attr *uattrs,
|
||||||
@@ -187,10 +226,10 @@ static int uverbs_uattrs_process(struct ib_device *ibdev,
|
|||||||
ret = uverbs_ns_idx(&attr_id, method->num_buckets);
|
ret = uverbs_ns_idx(&attr_id, method->num_buckets);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (uattr->flags & UVERBS_ATTR_F_MANDATORY) {
|
if (uattr->flags & UVERBS_ATTR_F_MANDATORY) {
|
||||||
uverbs_finalize_objects(attr_bundle,
|
uverbs_finalize_attrs(attr_bundle,
|
||||||
method->attr_buckets,
|
method->attr_buckets,
|
||||||
num_given_buckets,
|
num_given_buckets,
|
||||||
false);
|
false);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@@ -208,10 +247,10 @@ static int uverbs_uattrs_process(struct ib_device *ibdev,
|
|||||||
attr_spec_bucket, &attr_bundle->hash[ret],
|
attr_spec_bucket, &attr_bundle->hash[ret],
|
||||||
uattr_ptr++);
|
uattr_ptr++);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
uverbs_finalize_objects(attr_bundle,
|
uverbs_finalize_attrs(attr_bundle,
|
||||||
method->attr_buckets,
|
method->attr_buckets,
|
||||||
num_given_buckets,
|
num_given_buckets,
|
||||||
false);
|
false);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -271,10 +310,10 @@ static int uverbs_handle_method(struct ib_uverbs_attr __user *uattr_ptr,
|
|||||||
|
|
||||||
ret = method_spec->handler(ibdev, ufile, attr_bundle);
|
ret = method_spec->handler(ibdev, ufile, attr_bundle);
|
||||||
cleanup:
|
cleanup:
|
||||||
finalize_ret = uverbs_finalize_objects(attr_bundle,
|
finalize_ret = uverbs_finalize_attrs(attr_bundle,
|
||||||
method_spec->attr_buckets,
|
method_spec->attr_buckets,
|
||||||
attr_bundle->num_buckets,
|
attr_bundle->num_buckets,
|
||||||
!ret);
|
!ret);
|
||||||
|
|
||||||
return ret ? ret : finalize_ret;
|
return ret ? ret : finalize_ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user