Thread (24 messages) 24 messages, 5 authors, 2025-04-18
STALE436d
Revisions (5)
  1. v2 [diff vs current]
  2. v3 current
  3. v4 [diff vs current]
  4. v1 [diff vs current]
  5. v2 [diff vs current]

[RFC PATCH -next v3 04/10] nvmet: set WZDS and DRB if device supports BLK_FEAT_WRITE_ZEROES_UNMAP

From: Zhang Yi <hidden>
Date: 2025-03-18 07:44:15
Also in: dm-devel, linux-ext4, linux-fsdevel, linux-nvme, linux-scsi, linux-xfs, lkml
Subsystem: block layer, nvm express target driver, the rest · Maintainers: Jens Axboe, Christoph Hellwig, Sagi Grimberg, Chaitanya Kulkarni, Linus Torvalds

From: Zhang Yi <yi.zhang@huawei.com>

Set WZDS and DRB bit to the namespace dlfeat if the underlying block
device supports BLK_FEAT_WRITE_ZEROES_UNMAP, make the nvme target
device supports unmaped write zeroes command.

Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
---
 drivers/nvme/target/io-cmd-bdev.c | 4 ++++
 include/linux/blkdev.h            | 5 +++++
 2 files changed, 9 insertions(+)
diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c
index 83be0657e6df..0e8b35732492 100644
--- a/drivers/nvme/target/io-cmd-bdev.c
+++ b/drivers/nvme/target/io-cmd-bdev.c
@@ -46,6 +46,10 @@ void nvmet_bdev_set_limits(struct block_device *bdev, struct nvme_id_ns *id)
 	id->npda = id->npdg;
 	/* NOWS = Namespace Optimal Write Size */
 	id->nows = to0based(bdev_io_opt(bdev) / bdev_logical_block_size(bdev));
+
+	/* Set WZDS and DRB if device supports unmapped write zeroes */
+	if (bdev_unmap_write_zeroes(bdev))
+		id->dlfeat = (1 << 3) | 0x1;
 }
 
 void nvmet_bdev_ns_disable(struct nvmet_ns *ns)
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 5d280c7fba65..836738ab1fa6 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1344,6 +1344,11 @@ static inline unsigned int bdev_write_zeroes_sectors(struct block_device *bdev)
 	return bdev_limits(bdev)->max_write_zeroes_sectors;
 }
 
+static inline bool bdev_unmap_write_zeroes(struct block_device *bdev)
+{
+	return bdev_limits(bdev)->features & BLK_FEAT_WRITE_ZEROES_UNMAP;
+}
+
 static inline bool bdev_nonrot(struct block_device *bdev)
 {
 	return blk_queue_nonrot(bdev_get_queue(bdev));
-- 
2.46.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help