* [PATCH v2] block/rnbd: Remove a useless mutex
@ 2022-02-07 20:48 Christophe JAILLET
2022-02-08 6:24 ` Jinpu Wang
2022-02-08 13:58 ` Jens Axboe
0 siblings, 2 replies; 3+ messages in thread
From: Christophe JAILLET @ 2022-02-07 20:48 UTC (permalink / raw)
To: Md. Haris Iqbal, Jack Wang, Jens Axboe
Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linux-block
According to lib/idr.c,
The IDA handles its own locking. It is safe to call any of the IDA
functions without synchronisation in your code.
so the 'ida_lock' mutex can just be removed.
It is here only to protect some ida_simple_get()/ida_simple_remove() calls.
While at it, switch to ida_alloc_XXX()/ida_free() instead to
ida_simple_get()/ida_simple_remove().
The latter is deprecated and more verbose.
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
drivers/block/rnbd/rnbd-clt.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/drivers/block/rnbd/rnbd-clt.c b/drivers/block/rnbd/rnbd-clt.c
index 9a880d559ab8..1f63f308eb39 100644
--- a/drivers/block/rnbd/rnbd-clt.c
+++ b/drivers/block/rnbd/rnbd-clt.c
@@ -23,7 +23,6 @@ MODULE_LICENSE("GPL");
static int rnbd_client_major;
static DEFINE_IDA(index_ida);
-static DEFINE_MUTEX(ida_lock);
static DEFINE_MUTEX(sess_lock);
static LIST_HEAD(sess_list);
@@ -55,9 +54,7 @@ static void rnbd_clt_put_dev(struct rnbd_clt_dev *dev)
if (!refcount_dec_and_test(&dev->refcount))
return;
- mutex_lock(&ida_lock);
- ida_simple_remove(&index_ida, dev->clt_device_id);
- mutex_unlock(&ida_lock);
+ ida_free(&index_ida, dev->clt_device_id);
kfree(dev->hw_queues);
kfree(dev->pathname);
rnbd_clt_put_sess(dev->sess);
@@ -1460,10 +1457,8 @@ static struct rnbd_clt_dev *init_dev(struct rnbd_clt_session *sess,
goto out_alloc;
}
- mutex_lock(&ida_lock);
- ret = ida_simple_get(&index_ida, 0, 1 << (MINORBITS - RNBD_PART_BITS),
- GFP_KERNEL);
- mutex_unlock(&ida_lock);
+ ret = ida_alloc_max(&index_ida, 1 << (MINORBITS - RNBD_PART_BITS),
+ GFP_KERNEL);
if (ret < 0) {
pr_err("Failed to initialize device '%s' from session %s, allocating idr failed, err: %d\n",
pathname, sess->sessname, ret);
--
2.32.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] block/rnbd: Remove a useless mutex
2022-02-07 20:48 [PATCH v2] block/rnbd: Remove a useless mutex Christophe JAILLET
@ 2022-02-08 6:24 ` Jinpu Wang
2022-02-08 13:58 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Jinpu Wang @ 2022-02-08 6:24 UTC (permalink / raw)
To: Christophe JAILLET
Cc: Md. Haris Iqbal, Jens Axboe, linux-kernel, kernel-janitors, linux-block
On Mon, Feb 7, 2022 at 9:48 PM Christophe JAILLET
<christophe.jaillet@wanadoo.fr> wrote:
>
> According to lib/idr.c,
> The IDA handles its own locking. It is safe to call any of the IDA
> functions without synchronisation in your code.
>
> so the 'ida_lock' mutex can just be removed.
> It is here only to protect some ida_simple_get()/ida_simple_remove() calls.
>
> While at it, switch to ida_alloc_XXX()/ida_free() instead to
> ida_simple_get()/ida_simple_remove().
> The latter is deprecated and more verbose.
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Acked-by: Jack Wang <jinpu.wang@ionos.com>
Thanks!
> ---
> drivers/block/rnbd/rnbd-clt.c | 11 +++--------
> 1 file changed, 3 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/block/rnbd/rnbd-clt.c b/drivers/block/rnbd/rnbd-clt.c
> index 9a880d559ab8..1f63f308eb39 100644
> --- a/drivers/block/rnbd/rnbd-clt.c
> +++ b/drivers/block/rnbd/rnbd-clt.c
> @@ -23,7 +23,6 @@ MODULE_LICENSE("GPL");
>
> static int rnbd_client_major;
> static DEFINE_IDA(index_ida);
> -static DEFINE_MUTEX(ida_lock);
> static DEFINE_MUTEX(sess_lock);
> static LIST_HEAD(sess_list);
>
> @@ -55,9 +54,7 @@ static void rnbd_clt_put_dev(struct rnbd_clt_dev *dev)
> if (!refcount_dec_and_test(&dev->refcount))
> return;
>
> - mutex_lock(&ida_lock);
> - ida_simple_remove(&index_ida, dev->clt_device_id);
> - mutex_unlock(&ida_lock);
> + ida_free(&index_ida, dev->clt_device_id);
> kfree(dev->hw_queues);
> kfree(dev->pathname);
> rnbd_clt_put_sess(dev->sess);
> @@ -1460,10 +1457,8 @@ static struct rnbd_clt_dev *init_dev(struct rnbd_clt_session *sess,
> goto out_alloc;
> }
>
> - mutex_lock(&ida_lock);
> - ret = ida_simple_get(&index_ida, 0, 1 << (MINORBITS - RNBD_PART_BITS),
> - GFP_KERNEL);
> - mutex_unlock(&ida_lock);
> + ret = ida_alloc_max(&index_ida, 1 << (MINORBITS - RNBD_PART_BITS),
> + GFP_KERNEL);
> if (ret < 0) {
> pr_err("Failed to initialize device '%s' from session %s, allocating idr failed, err: %d\n",
> pathname, sess->sessname, ret);
> --
> 2.32.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] block/rnbd: Remove a useless mutex
2022-02-07 20:48 [PATCH v2] block/rnbd: Remove a useless mutex Christophe JAILLET
2022-02-08 6:24 ` Jinpu Wang
@ 2022-02-08 13:58 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2022-02-08 13:58 UTC (permalink / raw)
To: Christophe JAILLET, Md. Haris Iqbal, Jack Wang
Cc: linux-block, kernel-janitors, linux-kernel
On Mon, 7 Feb 2022 21:48:19 +0100, Christophe JAILLET wrote:
> According to lib/idr.c,
> The IDA handles its own locking. It is safe to call any of the IDA
> functions without synchronisation in your code.
>
> so the 'ida_lock' mutex can just be removed.
> It is here only to protect some ida_simple_get()/ida_simple_remove() calls.
>
> [...]
Applied, thanks!
[1/1] block/rnbd: Remove a useless mutex
commit: a41cdf83a63122e5c5fb8c8550b812b25a332577
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-02-08 13:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-07 20:48 [PATCH v2] block/rnbd: Remove a useless mutex Christophe JAILLET
2022-02-08 6:24 ` Jinpu Wang
2022-02-08 13:58 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).