提交 39e83af8 编写于 作者: J Jason Gunthorpe

RDMA/core: Remove the ufile arg from rdma_alloc_begin_uobject

Now that all callers provide a non-NULL attrs the ufile is redundant.
Adjust things so that the context handling is done inside alloc_uobj,
and the ib_uverbs_get_ucontext_file() is avoided if we already have the
context.

Link: https://lore.kernel.org/r/1578504126-9400-13-git-send-email-yishaih@mellanox.comSigned-off-by: NYishai Hadas <yishaih@mellanox.com>
Signed-off-by: NJason Gunthorpe <jgg@mellanox.com>
上级 817d6576
...@@ -256,15 +256,20 @@ int __uobj_perform_destroy(const struct uverbs_api_object *obj, u32 id, ...@@ -256,15 +256,20 @@ int __uobj_perform_destroy(const struct uverbs_api_object *obj, u32 id,
} }
/* alloc_uobj must be undone by uverbs_destroy_uobject() */ /* alloc_uobj must be undone by uverbs_destroy_uobject() */
static struct ib_uobject *alloc_uobj(struct ib_uverbs_file *ufile, static struct ib_uobject *alloc_uobj(struct uverbs_attr_bundle *attrs,
const struct uverbs_api_object *obj) const struct uverbs_api_object *obj)
{ {
struct ib_uverbs_file *ufile = attrs->ufile;
struct ib_uobject *uobj; struct ib_uobject *uobj;
struct ib_ucontext *ucontext;
ucontext = ib_uverbs_get_ucontext_file(ufile); if (!attrs->context) {
struct ib_ucontext *ucontext =
ib_uverbs_get_ucontext_file(ufile);
if (IS_ERR(ucontext)) if (IS_ERR(ucontext))
return ERR_CAST(ucontext); return ERR_CAST(ucontext);
attrs->context = ucontext;
}
uobj = kzalloc(obj->type_attrs->obj_size, GFP_KERNEL); uobj = kzalloc(obj->type_attrs->obj_size, GFP_KERNEL);
if (!uobj) if (!uobj)
...@@ -274,7 +279,7 @@ static struct ib_uobject *alloc_uobj(struct ib_uverbs_file *ufile, ...@@ -274,7 +279,7 @@ static struct ib_uobject *alloc_uobj(struct ib_uverbs_file *ufile,
* The object is added to the list in the commit stage. * The object is added to the list in the commit stage.
*/ */
uobj->ufile = ufile; uobj->ufile = ufile;
uobj->context = ucontext; uobj->context = attrs->context;
INIT_LIST_HEAD(&uobj->list); INIT_LIST_HEAD(&uobj->list);
uobj->uapi_object = obj; uobj->uapi_object = obj;
/* /*
...@@ -417,12 +422,12 @@ struct ib_uobject *rdma_lookup_get_uobject(const struct uverbs_api_object *obj, ...@@ -417,12 +422,12 @@ struct ib_uobject *rdma_lookup_get_uobject(const struct uverbs_api_object *obj,
static struct ib_uobject * static struct ib_uobject *
alloc_begin_idr_uobject(const struct uverbs_api_object *obj, alloc_begin_idr_uobject(const struct uverbs_api_object *obj,
struct ib_uverbs_file *ufile) struct uverbs_attr_bundle *attrs)
{ {
int ret; int ret;
struct ib_uobject *uobj; struct ib_uobject *uobj;
uobj = alloc_uobj(ufile, obj); uobj = alloc_uobj(attrs, obj);
if (IS_ERR(uobj)) if (IS_ERR(uobj))
return uobj; return uobj;
...@@ -438,7 +443,7 @@ alloc_begin_idr_uobject(const struct uverbs_api_object *obj, ...@@ -438,7 +443,7 @@ alloc_begin_idr_uobject(const struct uverbs_api_object *obj,
return uobj; return uobj;
remove: remove:
xa_erase(&ufile->idr, uobj->id); xa_erase(&attrs->ufile->idr, uobj->id);
uobj_put: uobj_put:
uverbs_uobject_put(uobj); uverbs_uobject_put(uobj);
return ERR_PTR(ret); return ERR_PTR(ret);
...@@ -446,7 +451,7 @@ alloc_begin_idr_uobject(const struct uverbs_api_object *obj, ...@@ -446,7 +451,7 @@ alloc_begin_idr_uobject(const struct uverbs_api_object *obj,
static struct ib_uobject * static struct ib_uobject *
alloc_begin_fd_uobject(const struct uverbs_api_object *obj, alloc_begin_fd_uobject(const struct uverbs_api_object *obj,
struct ib_uverbs_file *ufile) struct uverbs_attr_bundle *attrs)
{ {
const struct uverbs_obj_fd_type *fd_type = const struct uverbs_obj_fd_type *fd_type =
container_of(obj->type_attrs, struct uverbs_obj_fd_type, type); container_of(obj->type_attrs, struct uverbs_obj_fd_type, type);
...@@ -461,7 +466,7 @@ alloc_begin_fd_uobject(const struct uverbs_api_object *obj, ...@@ -461,7 +466,7 @@ alloc_begin_fd_uobject(const struct uverbs_api_object *obj,
if (new_fd < 0) if (new_fd < 0)
return ERR_PTR(new_fd); return ERR_PTR(new_fd);
uobj = alloc_uobj(ufile, obj); uobj = alloc_uobj(attrs, obj);
if (IS_ERR(uobj)) if (IS_ERR(uobj))
goto err_fd; goto err_fd;
...@@ -475,7 +480,6 @@ alloc_begin_fd_uobject(const struct uverbs_api_object *obj, ...@@ -475,7 +480,6 @@ alloc_begin_fd_uobject(const struct uverbs_api_object *obj,
uobj->object = filp; uobj->object = filp;
uobj->id = new_fd; uobj->id = new_fd;
uobj->ufile = ufile;
return uobj; return uobj;
err_uobj: err_uobj:
...@@ -486,9 +490,9 @@ alloc_begin_fd_uobject(const struct uverbs_api_object *obj, ...@@ -486,9 +490,9 @@ alloc_begin_fd_uobject(const struct uverbs_api_object *obj,
} }
struct ib_uobject *rdma_alloc_begin_uobject(const struct uverbs_api_object *obj, struct ib_uobject *rdma_alloc_begin_uobject(const struct uverbs_api_object *obj,
struct ib_uverbs_file *ufile,
struct uverbs_attr_bundle *attrs) struct uverbs_attr_bundle *attrs)
{ {
struct ib_uverbs_file *ufile = attrs->ufile;
struct ib_uobject *ret; struct ib_uobject *ret;
if (IS_ERR(obj)) if (IS_ERR(obj))
...@@ -502,13 +506,11 @@ struct ib_uobject *rdma_alloc_begin_uobject(const struct uverbs_api_object *obj, ...@@ -502,13 +506,11 @@ struct ib_uobject *rdma_alloc_begin_uobject(const struct uverbs_api_object *obj,
if (!down_read_trylock(&ufile->hw_destroy_rwsem)) if (!down_read_trylock(&ufile->hw_destroy_rwsem))
return ERR_PTR(-EIO); return ERR_PTR(-EIO);
ret = obj->type_class->alloc_begin(obj, ufile); ret = obj->type_class->alloc_begin(obj, attrs);
if (IS_ERR(ret)) { if (IS_ERR(ret)) {
up_read(&ufile->hw_destroy_rwsem); up_read(&ufile->hw_destroy_rwsem);
return ret; return ret;
} }
if (attrs)
attrs->context = ret->context;
return ret; return ret;
} }
...@@ -930,7 +932,7 @@ uverbs_get_uobject_from_file(u16 object_id, enum uverbs_obj_access access, ...@@ -930,7 +932,7 @@ uverbs_get_uobject_from_file(u16 object_id, enum uverbs_obj_access access,
return rdma_lookup_get_uobject(obj, attrs->ufile, id, return rdma_lookup_get_uobject(obj, attrs->ufile, id,
UVERBS_LOOKUP_WRITE, attrs); UVERBS_LOOKUP_WRITE, attrs);
case UVERBS_ACCESS_NEW: case UVERBS_ACCESS_NEW:
return rdma_alloc_begin_uobject(obj, attrs->ufile, attrs); return rdma_alloc_begin_uobject(obj, attrs);
default: default:
WARN_ON(true); WARN_ON(true);
return ERR_PTR(-EOPNOTSUPP); return ERR_PTR(-EOPNOTSUPP);
......
...@@ -114,8 +114,7 @@ static inline struct ib_uobject * ...@@ -114,8 +114,7 @@ static inline struct ib_uobject *
__uobj_alloc(const struct uverbs_api_object *obj, __uobj_alloc(const struct uverbs_api_object *obj,
struct uverbs_attr_bundle *attrs, struct ib_device **ib_dev) struct uverbs_attr_bundle *attrs, struct ib_device **ib_dev)
{ {
struct ib_uobject *uobj = struct ib_uobject *uobj = rdma_alloc_begin_uobject(obj, attrs);
rdma_alloc_begin_uobject(obj, attrs->ufile, attrs);
if (!IS_ERR(uobj)) if (!IS_ERR(uobj))
*ib_dev = attrs->context->device; *ib_dev = attrs->context->device;
......
...@@ -83,7 +83,7 @@ enum rdma_lookup_mode { ...@@ -83,7 +83,7 @@ enum rdma_lookup_mode {
*/ */
struct uverbs_obj_type_class { struct uverbs_obj_type_class {
struct ib_uobject *(*alloc_begin)(const struct uverbs_api_object *obj, struct ib_uobject *(*alloc_begin)(const struct uverbs_api_object *obj,
struct ib_uverbs_file *ufile); struct uverbs_attr_bundle *attrs);
/* This consumes the kref on uobj */ /* This consumes the kref on uobj */
void (*alloc_commit)(struct ib_uobject *uobj); void (*alloc_commit)(struct ib_uobject *uobj);
/* This does not consume the kref on uobj */ /* This does not consume the kref on uobj */
...@@ -137,7 +137,6 @@ struct ib_uobject *rdma_lookup_get_uobject(const struct uverbs_api_object *obj, ...@@ -137,7 +137,6 @@ struct ib_uobject *rdma_lookup_get_uobject(const struct uverbs_api_object *obj,
void rdma_lookup_put_uobject(struct ib_uobject *uobj, void rdma_lookup_put_uobject(struct ib_uobject *uobj,
enum rdma_lookup_mode mode); enum rdma_lookup_mode mode);
struct ib_uobject *rdma_alloc_begin_uobject(const struct uverbs_api_object *obj, struct ib_uobject *rdma_alloc_begin_uobject(const struct uverbs_api_object *obj,
struct ib_uverbs_file *ufile,
struct uverbs_attr_bundle *attrs); struct uverbs_attr_bundle *attrs);
void rdma_alloc_abort_uobject(struct ib_uobject *uobj, void rdma_alloc_abort_uobject(struct ib_uobject *uobj,
struct uverbs_attr_bundle *attrs); struct uverbs_attr_bundle *attrs);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册