public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>,
	Chandan Babu R <chandanbabu@kernel.org>,
	Keith Busch <kbusch@kernel.org>
Cc: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org,
	linux-xfs@vger.kernel.org
Subject: [PATCH 4/5] block: move await_bio_chain to bio.c
Date: Tue, 12 Mar 2024 08:48:25 -0600	[thread overview]
Message-ID: <20240312144826.1045212-5-hch@lst.de> (raw)
In-Reply-To: <20240312144826.1045212-1-hch@lst.de>

we'll want to use it from more than blk-lib.c, so this seems like
the better place.  Also rename it so that the name starts with bio_.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/bio.c     | 20 ++++++++++++++++++++
 block/blk-lib.c | 28 ++++------------------------
 block/blk.h     |  1 +
 3 files changed, 25 insertions(+), 24 deletions(-)

diff --git a/block/bio.c b/block/bio.c
index 32ff538b29e564..33972deed87fb3 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1396,6 +1396,26 @@ int submit_bio_wait(struct bio *bio)
 }
 EXPORT_SYMBOL(submit_bio_wait);
 
+static void bio_wait_end_io(struct bio *bio)
+{
+	complete(bio->bi_private);
+	bio_put(bio);
+}
+
+/*
+ * bio_await_chain - ends @bio and waits for every chained bio to complete
+ */
+void bio_await_chain(struct bio *bio)
+{
+	DECLARE_COMPLETION_ONSTACK_MAP(done,
+			bio->bi_bdev->bd_disk->lockdep_map);
+
+	bio->bi_private = &done;
+	bio->bi_end_io = bio_wait_end_io;
+	bio_endio(bio);
+	blk_wait_io(&done);
+}
+
 void __bio_advance(struct bio *bio, unsigned bytes)
 {
 	if (bio_integrity(bio))
diff --git a/block/blk-lib.c b/block/blk-lib.c
index fd97f4dd34e7f4..8021bc3831d56a 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -35,26 +35,6 @@ static sector_t bio_discard_limit(struct block_device *bdev, sector_t sector)
 	return round_down(UINT_MAX, discard_granularity) >> SECTOR_SHIFT;
 }
 
-static void await_bio_endio(struct bio *bio)
-{
-	complete(bio->bi_private);
-	bio_put(bio);
-}
-
-/*
- * await_bio_chain - ends @bio and waits for every chained bio to complete
- */
-static void await_bio_chain(struct bio *bio)
-{
-	DECLARE_COMPLETION_ONSTACK_MAP(done,
-			bio->bi_bdev->bd_disk->lockdep_map);
-
-	bio->bi_private = &done;
-	bio->bi_end_io = await_bio_endio;
-	bio_endio(bio);
-	blk_wait_io(&done);
-}
-
 struct bio *blk_alloc_discard_bio(struct block_device *bdev,
 		sector_t *sector, sector_t *nr_sects, gfp_t gfp_mask)
 {
@@ -93,7 +73,7 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
 	}
 
 	if (*biop)
-		await_bio_chain(*biop);
+		bio_await_chain(*biop);
 	return -EINTR;
 }
 EXPORT_SYMBOL(__blkdev_issue_discard);
@@ -158,7 +138,7 @@ static int __blkdev_issue_write_zeroes(struct block_device *bdev,
 		sector += len;
 		cond_resched();
 		if (fatal_signal_pending(current)) {
-			await_bio_chain(bio);
+			bio_await_chain(bio);
 			return -EINTR;
 		}
 	}
@@ -206,7 +186,7 @@ static int __blkdev_issue_zero_pages(struct block_device *bdev,
 		}
 		cond_resched();
 		if (fatal_signal_pending(current)) {
-			await_bio_chain(bio);
+			bio_await_chain(bio);
 			return -EINTR;
 		}
 	}
@@ -352,7 +332,7 @@ int blkdev_issue_secure_erase(struct block_device *bdev, sector_t sector,
 		nr_sects -= len;
 		cond_resched();
 		if (fatal_signal_pending(current)) {
-			await_bio_chain(bio);
+			bio_await_chain(bio);
 			ret = -EINTR;
 			bio = NULL;
 			break;
diff --git a/block/blk.h b/block/blk.h
index a19b7b42e6503c..78528bfbd58c37 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -38,6 +38,7 @@ void __blk_mq_unfreeze_queue(struct request_queue *q, bool force_atomic);
 void blk_queue_start_drain(struct request_queue *q);
 int __bio_queue_enter(struct request_queue *q, struct bio *bio);
 void submit_bio_noacct_nocheck(struct bio *bio);
+void bio_await_chain(struct bio *bio);
 
 static inline bool blk_try_enter_queue(struct request_queue *q, bool pm)
 {
-- 
2.39.2


  parent reply	other threads:[~2024-03-12 14:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-12 14:48 RFCv2: fix fatal signal handling in __blkdev_issue_discard Christoph Hellwig
2024-03-12 14:48 ` [PATCH 1/5] block: move discard checks into the ioctl handler Christoph Hellwig
2024-03-12 14:48 ` [PATCH 2/5] block: add a bio_chain_and_submit helper Christoph Hellwig
2024-03-12 14:48 ` [PATCH 3/5] block: add a blk_alloc_discard_bio helper Christoph Hellwig
2024-03-12 14:48 ` Christoph Hellwig [this message]
2024-03-12 14:48 ` [PATCH 5/5] block: don't allow fatal signals to interrupt (__)blkdev_issue_discard Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240312144826.1045212-5-hch@lst.de \
    --to=hch@lst.de \
    --cc=axboe@kernel.dk \
    --cc=chandanbabu@kernel.org \
    --cc=kbusch@kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox