mirror of https://gitee.com/openkylin/linux.git
IB/uverbs: Add a uobj_perform_destroy helper
This consolidates a bunch of repeated code patterns into a helper. Signed-off-by: Jason Gunthorpe <jgg@mellanox.com> Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
This commit is contained in:
parent
422e3d37ed
commit
c33e73af21
|
@ -128,6 +128,28 @@ static int uverbs_try_lock_object(struct ib_uobject *uobj, bool exclusive)
|
|||
return atomic_cmpxchg(&uobj->usecnt, 0, -1) == 0 ? 0 : -EBUSY;
|
||||
}
|
||||
|
||||
/*
|
||||
* Does both rdma_lookup_get_uobject() and rdma_remove_commit_uobject(), then
|
||||
* returns success_res on success (negative errno on failure). For use by
|
||||
* callers that do not need the uobj.
|
||||
*/
|
||||
int __uobj_perform_destroy(const struct uverbs_obj_type *type, int id,
|
||||
struct ib_uverbs_file *ufile, int success_res)
|
||||
{
|
||||
struct ib_uobject *uobj;
|
||||
int ret;
|
||||
|
||||
uobj = rdma_lookup_get_uobject(type, ufile->ucontext, id, true);
|
||||
if (IS_ERR(uobj))
|
||||
return PTR_ERR(uobj);
|
||||
|
||||
ret = rdma_remove_commit_uobject(uobj);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return success_res;
|
||||
}
|
||||
|
||||
static struct ib_uobject *alloc_uobj(struct ib_ucontext *context,
|
||||
const struct uverbs_obj_type *type)
|
||||
{
|
||||
|
|
|
@ -367,20 +367,12 @@ ssize_t ib_uverbs_dealloc_pd(struct ib_uverbs_file *file,
|
|||
int in_len, int out_len)
|
||||
{
|
||||
struct ib_uverbs_dealloc_pd cmd;
|
||||
struct ib_uobject *uobj;
|
||||
int ret;
|
||||
|
||||
if (copy_from_user(&cmd, buf, sizeof cmd))
|
||||
return -EFAULT;
|
||||
|
||||
uobj = uobj_get_write(UVERBS_OBJECT_PD, cmd.pd_handle,
|
||||
file->ucontext);
|
||||
if (IS_ERR(uobj))
|
||||
return PTR_ERR(uobj);
|
||||
|
||||
ret = uobj_remove_commit(uobj);
|
||||
|
||||
return ret ?: in_len;
|
||||
return uobj_perform_destroy(UVERBS_OBJECT_PD, cmd.pd_handle, file,
|
||||
in_len);
|
||||
}
|
||||
|
||||
struct xrcd_table_entry {
|
||||
|
@ -597,19 +589,12 @@ ssize_t ib_uverbs_close_xrcd(struct ib_uverbs_file *file,
|
|||
int out_len)
|
||||
{
|
||||
struct ib_uverbs_close_xrcd cmd;
|
||||
struct ib_uobject *uobj;
|
||||
int ret = 0;
|
||||
|
||||
if (copy_from_user(&cmd, buf, sizeof cmd))
|
||||
return -EFAULT;
|
||||
|
||||
uobj = uobj_get_write(UVERBS_OBJECT_XRCD, cmd.xrcd_handle,
|
||||
file->ucontext);
|
||||
if (IS_ERR(uobj))
|
||||
return PTR_ERR(uobj);
|
||||
|
||||
ret = uobj_remove_commit(uobj);
|
||||
return ret ?: in_len;
|
||||
return uobj_perform_destroy(UVERBS_OBJECT_XRCD, cmd.xrcd_handle, file,
|
||||
in_len);
|
||||
}
|
||||
|
||||
int ib_uverbs_dealloc_xrcd(struct ib_uobject *uobject,
|
||||
|
@ -829,20 +814,12 @@ ssize_t ib_uverbs_dereg_mr(struct ib_uverbs_file *file,
|
|||
int out_len)
|
||||
{
|
||||
struct ib_uverbs_dereg_mr cmd;
|
||||
struct ib_uobject *uobj;
|
||||
int ret = -EINVAL;
|
||||
|
||||
if (copy_from_user(&cmd, buf, sizeof cmd))
|
||||
return -EFAULT;
|
||||
|
||||
uobj = uobj_get_write(UVERBS_OBJECT_MR, cmd.mr_handle,
|
||||
file->ucontext);
|
||||
if (IS_ERR(uobj))
|
||||
return PTR_ERR(uobj);
|
||||
|
||||
ret = uobj_remove_commit(uobj);
|
||||
|
||||
return ret ?: in_len;
|
||||
return uobj_perform_destroy(UVERBS_OBJECT_MR, cmd.mr_handle, file,
|
||||
in_len);
|
||||
}
|
||||
|
||||
ssize_t ib_uverbs_alloc_mw(struct ib_uverbs_file *file,
|
||||
|
@ -921,19 +898,12 @@ ssize_t ib_uverbs_dealloc_mw(struct ib_uverbs_file *file,
|
|||
int out_len)
|
||||
{
|
||||
struct ib_uverbs_dealloc_mw cmd;
|
||||
struct ib_uobject *uobj;
|
||||
int ret = -EINVAL;
|
||||
|
||||
if (copy_from_user(&cmd, buf, sizeof(cmd)))
|
||||
return -EFAULT;
|
||||
|
||||
uobj = uobj_get_write(UVERBS_OBJECT_MW, cmd.mw_handle,
|
||||
file->ucontext);
|
||||
if (IS_ERR(uobj))
|
||||
return PTR_ERR(uobj);
|
||||
|
||||
ret = uobj_remove_commit(uobj);
|
||||
return ret ?: in_len;
|
||||
return uobj_perform_destroy(UVERBS_OBJECT_MW, cmd.mw_handle, file,
|
||||
in_len);
|
||||
}
|
||||
|
||||
ssize_t ib_uverbs_create_comp_channel(struct ib_uverbs_file *file,
|
||||
|
@ -2641,19 +2611,12 @@ ssize_t ib_uverbs_destroy_ah(struct ib_uverbs_file *file,
|
|||
const char __user *buf, int in_len, int out_len)
|
||||
{
|
||||
struct ib_uverbs_destroy_ah cmd;
|
||||
struct ib_uobject *uobj;
|
||||
int ret;
|
||||
|
||||
if (copy_from_user(&cmd, buf, sizeof cmd))
|
||||
return -EFAULT;
|
||||
|
||||
uobj = uobj_get_write(UVERBS_OBJECT_AH, cmd.ah_handle,
|
||||
file->ucontext);
|
||||
if (IS_ERR(uobj))
|
||||
return PTR_ERR(uobj);
|
||||
|
||||
ret = uobj_remove_commit(uobj);
|
||||
return ret ?: in_len;
|
||||
return uobj_perform_destroy(UVERBS_OBJECT_AH, cmd.ah_handle, file,
|
||||
in_len);
|
||||
}
|
||||
|
||||
ssize_t ib_uverbs_attach_mcast(struct ib_uverbs_file *file,
|
||||
|
@ -3445,7 +3408,6 @@ int ib_uverbs_ex_destroy_rwq_ind_table(struct ib_uverbs_file *file,
|
|||
struct ib_udata *uhw)
|
||||
{
|
||||
struct ib_uverbs_ex_destroy_rwq_ind_table cmd = {};
|
||||
struct ib_uobject *uobj;
|
||||
int ret;
|
||||
size_t required_cmd_sz;
|
||||
|
||||
|
@ -3466,12 +3428,8 @@ int ib_uverbs_ex_destroy_rwq_ind_table(struct ib_uverbs_file *file,
|
|||
if (cmd.comp_mask)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
uobj = uobj_get_write(UVERBS_OBJECT_RWQ_IND_TBL, cmd.ind_tbl_handle,
|
||||
file->ucontext);
|
||||
if (IS_ERR(uobj))
|
||||
return PTR_ERR(uobj);
|
||||
|
||||
return uobj_remove_commit(uobj);
|
||||
return uobj_perform_destroy(UVERBS_OBJECT_RWQ_IND_TBL,
|
||||
cmd.ind_tbl_handle, file, 0);
|
||||
}
|
||||
|
||||
int ib_uverbs_ex_create_flow(struct ib_uverbs_file *file,
|
||||
|
@ -3658,7 +3616,6 @@ int ib_uverbs_ex_destroy_flow(struct ib_uverbs_file *file,
|
|||
struct ib_udata *uhw)
|
||||
{
|
||||
struct ib_uverbs_destroy_flow cmd;
|
||||
struct ib_uobject *uobj;
|
||||
int ret;
|
||||
|
||||
if (ucore->inlen < sizeof(cmd))
|
||||
|
@ -3671,13 +3628,8 @@ int ib_uverbs_ex_destroy_flow(struct ib_uverbs_file *file,
|
|||
if (cmd.comp_mask)
|
||||
return -EINVAL;
|
||||
|
||||
uobj = uobj_get_write(UVERBS_OBJECT_FLOW, cmd.flow_handle,
|
||||
file->ucontext);
|
||||
if (IS_ERR(uobj))
|
||||
return PTR_ERR(uobj);
|
||||
|
||||
ret = uobj_remove_commit(uobj);
|
||||
return ret;
|
||||
return uobj_perform_destroy(UVERBS_OBJECT_FLOW, cmd.flow_handle, file,
|
||||
0);
|
||||
}
|
||||
|
||||
static int __uverbs_create_xsrq(struct ib_uverbs_file *file,
|
||||
|
|
|
@ -71,6 +71,11 @@ static inline struct ib_uobject *__uobj_get(const struct uverbs_obj_type *type,
|
|||
#define uobj_get_write(_type, _id, _ucontext) \
|
||||
__uobj_get(uobj_get_type(_type), true, _ucontext, _id)
|
||||
|
||||
int __uobj_perform_destroy(const struct uverbs_obj_type *type, int id,
|
||||
struct ib_uverbs_file *ufile, int success_res);
|
||||
#define uobj_perform_destroy(_type, _id, _ufile, _success_res) \
|
||||
__uobj_perform_destroy(uobj_get_type(_type), _id, _ufile, _success_res)
|
||||
|
||||
static inline void uobj_put_read(struct ib_uobject *uobj)
|
||||
{
|
||||
rdma_lookup_put_uobject(uobj, false);
|
||||
|
|
Loading…
Reference in New Issue