summaryrefslogtreecommitdiffstats
path: root/block
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2021-12-09 07:31:23 +0100
committerJens Axboe <axboe@kernel.dk>2021-12-16 10:59:01 -0700
commit4be8a2eaff2e4473b6e8ad9a3857bc9b1e79c8ba (patch)
treef82dbf0a615afc6b89bf5831f3631b74e9d19961 /block
parent0aed2f162bbc7853fe91c0d70492ea73c4e9cb07 (diff)
downloadlinux-4be8a2eaff2e4473b6e8ad9a3857bc9b1e79c8ba.tar.bz2
block: refactor put_iocontext_active
Factor out a ioc_exit_icqs helper to tear down the icqs and the fold the rest of put_iocontext_active into exit_io_context. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Jan Kara <jack@suse.cz> Link: https://lore.kernel.org/r/20211209063131.18537-4-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block')
-rw-r--r--block/blk-ioc.c41
1 files changed, 14 insertions, 27 deletions
diff --git a/block/blk-ioc.c b/block/blk-ioc.c
index 9cde3906be3c..0380e33930e3 100644
--- a/block/blk-ioc.c
+++ b/block/blk-ioc.c
@@ -54,6 +54,16 @@ static void ioc_exit_icq(struct io_cq *icq)
icq->flags |= ICQ_EXITED;
}
+static void ioc_exit_icqs(struct io_context *ioc)
+{
+ struct io_cq *icq;
+
+ spin_lock_irq(&ioc->lock);
+ hlist_for_each_entry(icq, &ioc->icq_list, ioc_node)
+ ioc_exit_icq(icq);
+ spin_unlock_irq(&ioc->lock);
+}
+
/*
* Release an icq. Called with ioc locked for blk-mq, and with both ioc
* and queue locked for legacy.
@@ -169,32 +179,6 @@ void put_io_context(struct io_context *ioc)
}
EXPORT_SYMBOL_GPL(put_io_context);
-/**
- * put_io_context_active - put active reference on ioc
- * @ioc: ioc of interest
- *
- * Put an active reference to an ioc. If active reference reaches zero after
- * put, @ioc can never issue further IOs and ioscheds are notified.
- */
-static void put_io_context_active(struct io_context *ioc)
-{
- struct io_cq *icq;
-
- if (!atomic_dec_and_test(&ioc->active_ref))
- return;
-
- spin_lock_irq(&ioc->lock);
- hlist_for_each_entry(icq, &ioc->icq_list, ioc_node) {
- if (icq->flags & ICQ_EXITED)
- continue;
-
- ioc_exit_icq(icq);
- }
- spin_unlock_irq(&ioc->lock);
-
- put_io_context(ioc);
-}
-
/* Called by the exiting task */
void exit_io_context(struct task_struct *task)
{
@@ -205,7 +189,10 @@ void exit_io_context(struct task_struct *task)
task->io_context = NULL;
task_unlock(task);
- put_io_context_active(ioc);
+ if (atomic_dec_and_test(&ioc->active_ref)) {
+ ioc_exit_icqs(ioc);
+ put_io_context(ioc);
+ }
}
static void __ioc_clear_queue(struct list_head *icq_list)