From: Damien Le Moal <dlemoal@kernel.org>
To: linux-block@vger.kernel.org, Jens Axboe <axboe@kernel.dk>,
dm-devel@lists.linux.dev, Mike Snitzer <snitzer@kernel.org>,
Mikulas Patocka <mpatocka@redhat.com>
Cc: Bart Van Assche <bvanassche@acm.org>
Subject: [PATCH v2 1/4] block: Introduce bio_needs_zone_write_plugging()
Date: Wed, 25 Jun 2025 14:59:05 +0900 [thread overview]
Message-ID: <20250625055908.456235-2-dlemoal@kernel.org> (raw)
In-Reply-To: <20250625055908.456235-1-dlemoal@kernel.org>
In preparation for fixing device mapper zone write handling, introduce
the helper function bio_needs_zone_write_plugging() to test if a BIO
requires handling through zone write plugging. This function returns
true for any write operation to a zoned block device. For zone append
opertions, true is returned only if the device requires zone append
emulation with regular writes.
Fixes: f211268ed1f9 ("dm: Use the block layer zone append emulation")
Cc: stable@vger.kernel.org
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
---
block/blk-zoned.c | 40 ++++++++++++++++++++++++++++++++++++++++
include/linux/blkdev.h | 9 +++++++++
2 files changed, 49 insertions(+)
diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 55e64ca869d7..9d38b94cad0d 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -1129,6 +1129,46 @@ static void blk_zone_wplug_handle_native_zone_append(struct bio *bio)
disk_put_zone_wplug(zwplug);
}
+/**
+ * bio_needs_zone_write_plugging - Check if a BIO needs to be handled with zone
+ * write plugging
+ * @bio: The BIO being submitted
+ *
+ * Return true whenever @bio execution needs to be handled through zone
+ * write plugging. Return false otherwise.
+ */
+bool bio_needs_zone_write_plugging(struct bio *bio)
+{
+ enum req_op op = bio_op(bio);
+
+ if (!bdev_is_zoned(bio->bi_bdev) || !op_is_write(op))
+ return false;
+
+ /* Already handled ? */
+ if (bio_flagged(bio, BIO_ZONE_WRITE_PLUGGING))
+ return false;
+
+ /* Ignore empty flush */
+ if (op_is_flush(bio->bi_opf) && !bio_sectors(bio))
+ return false;
+
+ /*
+ * Regular writes and write zeroes need to be handled through zone
+ * write plugging. Zone append operations only need zone write plugging
+ * if they are emulated.
+ */
+ switch (op) {
+ case REQ_OP_ZONE_APPEND:
+ return bdev_emulates_zone_append(bio->bi_bdev);
+ case REQ_OP_WRITE:
+ case REQ_OP_WRITE_ZEROES:
+ return true;
+ default:
+ return false;
+ }
+}
+EXPORT_SYMBOL_GPL(bio_needs_zone_write_plugging);
+
/**
* blk_zone_plug_bio - Handle a zone write BIO with zone write plugging
* @bio: The BIO being submitted
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index c2b3ddea8b6d..d455057bfaa3 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -848,6 +848,9 @@ static inline unsigned int disk_nr_zones(struct gendisk *disk)
{
return disk->nr_zones;
}
+
+bool bio_needs_zone_write_plugging(struct bio *bio);
+
bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs);
/**
@@ -877,6 +880,12 @@ static inline unsigned int disk_nr_zones(struct gendisk *disk)
{
return 0;
}
+
+static inline bool bio_needs_zone_write_plugging(struct bio *bio)
+{
+ return false;
+}
+
static inline bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs)
{
return false;
--
2.49.0
next prev parent reply other threads:[~2025-06-25 6:01 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-25 5:59 [PATCH v2 0/4] Fix write operation handling for zoned DM devices Damien Le Moal
2025-06-25 5:59 ` Damien Le Moal [this message]
2025-06-25 6:12 ` [PATCH v2 1/4] block: Introduce bio_needs_zone_write_plugging() Christoph Hellwig
2025-06-25 6:14 ` Damien Le Moal
2025-06-25 6:18 ` Christoph Hellwig
2025-06-25 6:17 ` Damien Le Moal
2025-06-25 5:59 ` [PATCH v2 2/4] dm: Always split write BIOs to zoned device limits Damien Le Moal
2025-06-25 6:15 ` Christoph Hellwig
2025-06-25 6:15 ` Damien Le Moal
2025-06-25 5:59 ` [PATCH v2 3/4] dm: dm-crypt: Do not split write operations with zoned targets Damien Le Moal
2025-06-25 10:19 ` Mikulas Patocka
2025-06-25 12:54 ` Damien Le Moal
2025-06-25 14:03 ` Mikulas Patocka
2025-06-25 14:43 ` Damien Le Moal
2025-06-25 16:33 ` Mikulas Patocka
2025-06-25 5:59 ` [PATCH v2 4/4] dm: Check for forbidden splitting of zone write operations Damien Le Moal
2025-06-25 6:16 ` 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=20250625055908.456235-2-dlemoal@kernel.org \
--to=dlemoal@kernel.org \
--cc=axboe@kernel.dk \
--cc=bvanassche@acm.org \
--cc=dm-devel@lists.linux.dev \
--cc=linux-block@vger.kernel.org \
--cc=mpatocka@redhat.com \
--cc=snitzer@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.