提交 0f63ef1d 编写于 作者: L Leon Romanovsky 提交者: Jason Gunthorpe

RDMA/core: Align abort/commit object scheme for write() and ioctl() paths

Create the same logic flow for the write() interface as we have for the
ioctl() path by making sure that the object is committed or aborted
automatically after HW object creation.

Link: https://lore.kernel.org/r/20200719052223.75245-2-leon@kernel.orgSigned-off-by: NLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: NJason Gunthorpe <jgg@nvidia.com>
上级 c94e272b
...@@ -601,6 +601,7 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, ...@@ -601,6 +601,7 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
memset(bundle.attr_present, 0, sizeof(bundle.attr_present)); memset(bundle.attr_present, 0, sizeof(bundle.attr_present));
bundle.ufile = file; bundle.ufile = file;
bundle.context = NULL; /* only valid if bundle has uobject */ bundle.context = NULL; /* only valid if bundle has uobject */
bundle.uobject = NULL;
if (!method_elm->is_ex) { if (!method_elm->is_ex) {
size_t in_len = hdr.in_words * 4 - sizeof(hdr); size_t in_len = hdr.in_words * 4 - sizeof(hdr);
size_t out_len = hdr.out_words * 4; size_t out_len = hdr.out_words * 4;
...@@ -664,6 +665,9 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, ...@@ -664,6 +665,9 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
} }
ret = method_elm->handler(&bundle); ret = method_elm->handler(&bundle);
if (bundle.uobject)
uverbs_finalize_object(bundle.uobject, UVERBS_ACCESS_NEW, true,
!ret, &bundle);
out_unlock: out_unlock:
srcu_read_unlock(&file->device->disassociate_srcu, srcu_key); srcu_read_unlock(&file->device->disassociate_srcu, srcu_key);
return (ret) ? : count; return (ret) ? : count;
......
...@@ -38,7 +38,12 @@ static int UVERBS_HANDLER(UVERBS_METHOD_INVOKE_WRITE)( ...@@ -38,7 +38,12 @@ static int UVERBS_HANDLER(UVERBS_METHOD_INVOKE_WRITE)(
attrs->ucore.outlen < method_elm->resp_size) attrs->ucore.outlen < method_elm->resp_size)
return -ENOSPC; return -ENOSPC;
return method_elm->handler(attrs); attrs->uobject = NULL;
rc = method_elm->handler(attrs);
if (attrs->uobject)
uverbs_finalize_object(attrs->uobject, UVERBS_ACCESS_NEW, true,
!rc, attrs);
return rc;
} }
DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_INVOKE_WRITE, DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_INVOKE_WRITE,
......
...@@ -652,6 +652,7 @@ struct uverbs_attr_bundle { ...@@ -652,6 +652,7 @@ struct uverbs_attr_bundle {
struct ib_udata ucore; struct ib_udata ucore;
struct ib_uverbs_file *ufile; struct ib_uverbs_file *ufile;
struct ib_ucontext *context; struct ib_ucontext *context;
struct ib_uobject *uobject;
DECLARE_BITMAP(attr_present, UVERBS_API_ATTR_BKEY_LEN); DECLARE_BITMAP(attr_present, UVERBS_API_ATTR_BKEY_LEN);
struct uverbs_attr attrs[]; struct uverbs_attr attrs[];
}; };
......
...@@ -110,6 +110,20 @@ static inline void uobj_alloc_abort(struct ib_uobject *uobj, ...@@ -110,6 +110,20 @@ static inline void uobj_alloc_abort(struct ib_uobject *uobj,
rdma_alloc_abort_uobject(uobj, attrs, false); rdma_alloc_abort_uobject(uobj, attrs, false);
} }
static inline void uobj_finalize_uobj_create(struct ib_uobject *uobj,
struct uverbs_attr_bundle *attrs)
{
/*
* Tell the core code that the write() handler has completed
* initializing the object and that the core should commit or
* abort this object based upon the return code from the write()
* method. Similar to what uverbs_finalize_uobj_create() does for
* ioctl()
*/
WARN_ON(attrs->uobject);
attrs->uobject = uobj;
}
static inline struct ib_uobject * 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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册