Commit 4dfd5321 authored by Matthew Wilcox's avatar Matthew Wilcox Committed by Jason Gunthorpe

ucma: Convert multicast_idr to XArray

Signed-off-by: default avatarMatthew Wilcox <willy@infradead.org>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent 9bcb8940
...@@ -104,7 +104,7 @@ struct ucma_context { ...@@ -104,7 +104,7 @@ struct ucma_context {
struct ucma_multicast { struct ucma_multicast {
struct ucma_context *ctx; struct ucma_context *ctx;
int id; u32 id;
int events_reported; int events_reported;
u64 uid; u64 uid;
...@@ -124,7 +124,7 @@ struct ucma_event { ...@@ -124,7 +124,7 @@ struct ucma_event {
static DEFINE_MUTEX(mut); static DEFINE_MUTEX(mut);
static DEFINE_IDR(ctx_idr); static DEFINE_IDR(ctx_idr);
static DEFINE_IDR(multicast_idr); static DEFINE_XARRAY_ALLOC(multicast_table);
static const struct file_operations ucma_fops; static const struct file_operations ucma_fops;
...@@ -238,13 +238,10 @@ static struct ucma_multicast* ucma_alloc_multicast(struct ucma_context *ctx) ...@@ -238,13 +238,10 @@ static struct ucma_multicast* ucma_alloc_multicast(struct ucma_context *ctx)
if (!mc) if (!mc)
return NULL; return NULL;
mutex_lock(&mut); mc->ctx = ctx;
mc->id = idr_alloc(&multicast_idr, NULL, 0, 0, GFP_KERNEL); if (xa_alloc(&multicast_table, &mc->id, NULL, xa_limit_32b, GFP_KERNEL))
mutex_unlock(&mut);
if (mc->id < 0)
goto error; goto error;
mc->ctx = ctx;
list_add_tail(&mc->list, &ctx->mc_list); list_add_tail(&mc->list, &ctx->mc_list);
return mc; return mc;
...@@ -540,7 +537,7 @@ static void ucma_cleanup_multicast(struct ucma_context *ctx) ...@@ -540,7 +537,7 @@ static void ucma_cleanup_multicast(struct ucma_context *ctx)
mutex_lock(&mut); mutex_lock(&mut);
list_for_each_entry_safe(mc, tmp, &ctx->mc_list, list) { list_for_each_entry_safe(mc, tmp, &ctx->mc_list, list) {
list_del(&mc->list); list_del(&mc->list);
idr_remove(&multicast_idr, mc->id); xa_erase(&multicast_table, mc->id);
kfree(mc); kfree(mc);
} }
mutex_unlock(&mut); mutex_unlock(&mut);
...@@ -1431,9 +1428,7 @@ static ssize_t ucma_process_join(struct ucma_file *file, ...@@ -1431,9 +1428,7 @@ static ssize_t ucma_process_join(struct ucma_file *file,
goto err3; goto err3;
} }
mutex_lock(&mut); xa_store(&multicast_table, mc->id, mc, 0);
idr_replace(&multicast_idr, mc, mc->id);
mutex_unlock(&mut);
mutex_unlock(&file->mut); mutex_unlock(&file->mut);
ucma_put_ctx(ctx); ucma_put_ctx(ctx);
...@@ -1443,9 +1438,7 @@ static ssize_t ucma_process_join(struct ucma_file *file, ...@@ -1443,9 +1438,7 @@ static ssize_t ucma_process_join(struct ucma_file *file,
rdma_leave_multicast(ctx->cm_id, (struct sockaddr *) &mc->addr); rdma_leave_multicast(ctx->cm_id, (struct sockaddr *) &mc->addr);
ucma_cleanup_mc_events(mc); ucma_cleanup_mc_events(mc);
err2: err2:
mutex_lock(&mut); xa_erase(&multicast_table, mc->id);
idr_remove(&multicast_idr, mc->id);
mutex_unlock(&mut);
list_del(&mc->list); list_del(&mc->list);
kfree(mc); kfree(mc);
err1: err1:
...@@ -1507,8 +1500,8 @@ static ssize_t ucma_leave_multicast(struct ucma_file *file, ...@@ -1507,8 +1500,8 @@ static ssize_t ucma_leave_multicast(struct ucma_file *file,
if (copy_from_user(&cmd, inbuf, sizeof(cmd))) if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
return -EFAULT; return -EFAULT;
mutex_lock(&mut); xa_lock(&multicast_table);
mc = idr_find(&multicast_idr, cmd.id); mc = xa_load(&multicast_table, cmd.id);
if (!mc) if (!mc)
mc = ERR_PTR(-ENOENT); mc = ERR_PTR(-ENOENT);
else if (mc->ctx->file != file) else if (mc->ctx->file != file)
...@@ -1516,8 +1509,8 @@ static ssize_t ucma_leave_multicast(struct ucma_file *file, ...@@ -1516,8 +1509,8 @@ static ssize_t ucma_leave_multicast(struct ucma_file *file,
else if (!atomic_inc_not_zero(&mc->ctx->ref)) else if (!atomic_inc_not_zero(&mc->ctx->ref))
mc = ERR_PTR(-ENXIO); mc = ERR_PTR(-ENXIO);
else else
idr_remove(&multicast_idr, mc->id); __xa_erase(&multicast_table, mc->id);
mutex_unlock(&mut); xa_unlock(&multicast_table);
if (IS_ERR(mc)) { if (IS_ERR(mc)) {
ret = PTR_ERR(mc); ret = PTR_ERR(mc);
...@@ -1846,7 +1839,6 @@ static void __exit ucma_cleanup(void) ...@@ -1846,7 +1839,6 @@ static void __exit ucma_cleanup(void)
device_remove_file(ucma_misc.this_device, &dev_attr_abi_version); device_remove_file(ucma_misc.this_device, &dev_attr_abi_version);
misc_deregister(&ucma_misc); misc_deregister(&ucma_misc);
idr_destroy(&ctx_idr); idr_destroy(&ctx_idr);
idr_destroy(&multicast_idr);
} }
module_init(ucma_init); module_init(ucma_init);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment