diff mbox series

block/rnbd-clt: Avoid flush_workqueue(system_long_wq) usage

Message ID 20220413121315.63684-1-jinpu.wang@ionos.com (mailing list archive)
State New, archived
Headers show
Series block/rnbd-clt: Avoid flush_workqueue(system_long_wq) usage | expand

Commit Message

Jinpu Wang April 13, 2022, 12:13 p.m. UTC
Flushing system-wide workqueues is dangerous and will be forbidden.

Replace system_long_wq with local rnbd_clt_wq.

Link: https://lkml.kernel.org/r/49925af7-78a8-a3dd-bce6-cfc02e1a9236@I-love.SAKURA.ne.jp

Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: Jack Wang <jinpu.wang@ionos.com>
Reviewed-by: Santosh Kumar Pradhan <santosh.pradhan@ionos.com>
---
 drivers/block/rnbd/rnbd-clt.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

Comments

Tetsuo Handa April 13, 2022, 12:25 p.m. UTC | #1
Thanks for a patch.

On 2022/04/13 21:13, Jack Wang wrote:
> @@ -1792,6 +1793,13 @@ static int __init rnbd_client_init(void)
>  		       err);
>  		unregister_blkdev(rnbd_client_major, "rnbd");

I think you want

		return err;

here so that alloc_workqueue() won't be called when
rnbd_clt_create_sysfs_files() returned an error.

>  	}
> +	rnbd_clt_wq = alloc_workqueue("rnbd_clt_wq", 0, 0);
> +	if (!rnbd_clt_wq) {
> +		pr_err("Failed to load module, alloc_workqueue failed.\n");
> +		rnbd_clt_destroy_sysfs_files();
> +		unregister_blkdev(rnbd_client_major, "rnbd");
> +		err = -ENOMEM;
> +	}
>  
>  	return err;
>  }
Jinpu Wang April 13, 2022, 12:35 p.m. UTC | #2
On Wed, Apr 13, 2022 at 2:26 PM Tetsuo Handa
<penguin-kernel@i-love.sakura.ne.jp> wrote:
>
> Thanks for a patch.
>
> On 2022/04/13 21:13, Jack Wang wrote:
> > @@ -1792,6 +1793,13 @@ static int __init rnbd_client_init(void)
> >                      err);
> >               unregister_blkdev(rnbd_client_major, "rnbd");
>
> I think you want
>
>                 return err;
>
> here so that alloc_workqueue() won't be called when
> rnbd_clt_create_sysfs_files() returned an error.
right, I just fixed it, and sent new version.
>
> >       }
> > +     rnbd_clt_wq = alloc_workqueue("rnbd_clt_wq", 0, 0);
> > +     if (!rnbd_clt_wq) {
> > +             pr_err("Failed to load module, alloc_workqueue failed.\n");
> > +             rnbd_clt_destroy_sysfs_files();
> > +             unregister_blkdev(rnbd_client_major, "rnbd");
> > +             err = -ENOMEM;
> > +     }
> >
> >       return err;
> >  }
diff mbox series

Patch

diff --git a/drivers/block/rnbd/rnbd-clt.c b/drivers/block/rnbd/rnbd-clt.c
index b66e8840b94b..1cb34649a875 100644
--- a/drivers/block/rnbd/rnbd-clt.c
+++ b/drivers/block/rnbd/rnbd-clt.c
@@ -25,6 +25,7 @@  static int rnbd_client_major;
 static DEFINE_IDA(index_ida);
 static DEFINE_MUTEX(sess_lock);
 static LIST_HEAD(sess_list);
+static struct workqueue_struct *rnbd_clt_wq;
 
 /*
  * Maximum number of partitions an instance can have.
@@ -1761,12 +1762,12 @@  static void rnbd_destroy_sessions(void)
 			 * procedure takes minutes.
 			 */
 			INIT_WORK(&dev->unmap_on_rmmod_work, unmap_device_work);
-			queue_work(system_long_wq, &dev->unmap_on_rmmod_work);
+			queue_work(rnbd_clt_wq, &dev->unmap_on_rmmod_work);
 		}
 		rnbd_clt_put_sess(sess);
 	}
 	/* Wait for all scheduled unmap works */
-	flush_workqueue(system_long_wq);
+	flush_workqueue(rnbd_clt_wq);
 	WARN_ON(!list_empty(&sess_list));
 }
 
@@ -1792,6 +1793,13 @@  static int __init rnbd_client_init(void)
 		       err);
 		unregister_blkdev(rnbd_client_major, "rnbd");
 	}
+	rnbd_clt_wq = alloc_workqueue("rnbd_clt_wq", 0, 0);
+	if (!rnbd_clt_wq) {
+		pr_err("Failed to load module, alloc_workqueue failed.\n");
+		rnbd_clt_destroy_sysfs_files();
+		unregister_blkdev(rnbd_client_major, "rnbd");
+		err = -ENOMEM;
+	}
 
 	return err;
 }
@@ -1801,6 +1809,7 @@  static void __exit rnbd_client_exit(void)
 	rnbd_destroy_sessions();
 	unregister_blkdev(rnbd_client_major, "rnbd");
 	ida_destroy(&index_ida);
+	destroy_workqueue(rnbd_clt_wq);
 }
 
 module_init(rnbd_client_init);