[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210806080302.298297-5-ming.lei@redhat.com>
Date: Fri, 6 Aug 2021 16:02:59 +0800
From: Ming Lei <ming.lei@...hat.com>
To: Jens Axboe <axboe@...nel.dk>
Cc: linux-kernel@...r.kernel.org, linux-block@...r.kernel.org,
Christoph Hellwig <hch@....de>,
Dan Schatzberg <schatzberg.dan@...il.com>,
Ming Lei <ming.lei@...hat.com>
Subject: [PATCH V4 4/7] loop: add __loop_free_idle_workers() for covering freeing workers in clearing FD
Add the helper, so we can remove the duplicated code for freeing all
workers in clearing FD.
Acked-by: Dan Schatzberg <schatzberg.dan@...il.com>
Signed-off-by: Ming Lei <ming.lei@...hat.com>
---
drivers/block/loop.c | 25 +++++++++++--------------
1 file changed, 11 insertions(+), 14 deletions(-)
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 6e65e46553f6..6e5c55d4552b 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -1207,16 +1207,14 @@ static void loop_set_timer(struct loop_device *lo)
schedule_delayed_work(&lo->idle_work, LOOP_IDLE_WORKER_TIMEOUT);
}
-static void loop_free_idle_workers(struct work_struct *work)
+static void __loop_free_idle_workers(struct loop_device *lo, bool force)
{
- struct loop_device *lo = container_of(work, struct loop_device,
- idle_work.work);
struct loop_worker *pos, *worker;
spin_lock(&lo->lo_work_lock);
list_for_each_entry_safe(worker, pos, &lo->idle_worker_list,
idle_list) {
- if (time_is_after_jiffies(worker->last_ran_at +
+ if (!force && time_is_after_jiffies(worker->last_ran_at +
LOOP_IDLE_WORKER_TIMEOUT))
break;
list_del(&worker->idle_list);
@@ -1229,6 +1227,14 @@ static void loop_free_idle_workers(struct work_struct *work)
spin_unlock(&lo->lo_work_lock);
}
+static void loop_free_idle_workers(struct work_struct *work)
+{
+ struct loop_device *lo = container_of(work, struct loop_device,
+ idle_work.work);
+
+ __loop_free_idle_workers(lo, false);
+}
+
static int loop_configure(struct loop_device *lo, fmode_t mode,
struct block_device *bdev,
const struct loop_config *config)
@@ -1376,7 +1382,6 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
int err = 0;
bool partscan = false;
int lo_number;
- struct loop_worker *pos, *worker;
/*
* Flush loop_configure() and loop_change_fd(). It is acceptable for
@@ -1409,15 +1414,7 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
blk_mq_freeze_queue(lo->lo_queue);
destroy_workqueue(lo->workqueue);
- spin_lock(&lo->lo_work_lock);
- list_for_each_entry_safe(worker, pos, &lo->idle_worker_list,
- idle_list) {
- list_del(&worker->idle_list);
- rb_erase(&worker->rb_node, &lo->worker_tree);
- css_put(worker->blkcg_css);
- kfree(worker);
- }
- spin_unlock(&lo->lo_work_lock);
+ __loop_free_idle_workers(lo, true);
cancel_delayed_work_sync(&lo->idle_work);
spin_lock_irq(&lo->lo_lock);
--
2.31.1
Powered by blists - more mailing lists