From: John Garry <john.g.garry@oracle.com>
To: axboe@kernel.dk, song@kernel.org, yukuai3@huawei.com,
kbusch@kernel.org, hch@lst.de, sagi@grimberg.me,
James.Bottomley@HansenPartnership.com,
martin.petersen@oracle.com
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-raid@vger.kernel.org, linux-nvme@lists.infradead.org,
linux-scsi@vger.kernel.org, John Garry <john.g.garry@oracle.com>
Subject: [PATCH RFC 2/4] block: Add BLK_FEAT_ATOMIC_WRITES flag
Date: Tue, 3 Sep 2024 15:07:46 +0000 [thread overview]
Message-ID: <20240903150748.2179966-3-john.g.garry@oracle.com> (raw)
In-Reply-To: <20240903150748.2179966-1-john.g.garry@oracle.com>
For stacking devices, not all underlying bottom devices may support atomic
writes, so a feature flag would be helpful in deciding whether the top
device may support atomic writes.
Furthermore, even if all bottom devices support atomic writes, a md/dm
personality may not.
Add flag BLK_FEAT_ATOMIC_WRITES to decide whether a block device supports
atomic writes.
Signed-off-by: John Garry <john.g.garry@oracle.com>
---
block/blk-settings.c | 3 ++-
drivers/nvme/host/core.c | 3 +++
drivers/scsi/sd.c | 13 ++++++++++---
include/linux/blkdev.h | 3 +++
4 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/block/blk-settings.c b/block/blk-settings.c
index cd8a8eabc9a5..036e67f73116 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -176,7 +176,7 @@ static void blk_validate_atomic_write_limits(struct queue_limits *lim)
{
unsigned int boundary_sectors;
- if (!lim->atomic_write_hw_max)
+ if (!(lim->features & BLK_FEAT_ATOMIC_WRITES) || !lim->atomic_write_hw_max)
goto unsupported;
boundary_sectors = lim->atomic_write_hw_boundary >> SECTOR_SHIFT;
@@ -217,6 +217,7 @@ static void blk_validate_atomic_write_limits(struct queue_limits *lim)
lim->atomic_write_boundary_sectors = 0;
lim->atomic_write_unit_min = 0;
lim->atomic_write_unit_max = 0;
+ lim->features &= ~BLK_FEAT_ATOMIC_WRITES;
}
/*
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 0dc8bcc664f2..c70d8e7602bf 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1975,6 +1975,7 @@ static void nvme_update_atomic_write_disk_info(struct nvme_ns *ns,
lim->atomic_write_hw_boundary = boundary;
lim->atomic_write_hw_unit_min = bs;
lim->atomic_write_hw_unit_max = rounddown_pow_of_two(atomic_bs);
+ lim->features |= BLK_FEAT_ATOMIC_WRITES;
}
static u32 nvme_max_drv_segments(struct nvme_ctrl *ctrl)
@@ -2025,6 +2026,8 @@ static bool nvme_update_disk_info(struct nvme_ns *ns, struct nvme_id_ns *id,
atomic_bs = (1 + ns->ctrl->subsys->awupf) * bs;
nvme_update_atomic_write_disk_info(ns, id, lim, bs, atomic_bs);
+ } else {
+ lim->features &= ~BLK_FEAT_ATOMIC_WRITES;
}
if (id->nsfeat & NVME_NS_FEAT_IO_OPT) {
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 9db86943d04c..aecd05165ee8 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -948,7 +948,7 @@ static void sd_config_atomic(struct scsi_disk *sdkp, struct queue_limits *lim)
if ((!sdkp->max_atomic && !sdkp->max_atomic_with_boundary) ||
sdkp->protection_type == T10_PI_TYPE2_PROTECTION)
- return;
+ goto out_unsupported;
physical_block_size_sectors = sdkp->physical_block_size /
sdkp->device->sector_size;
@@ -988,15 +988,22 @@ static void sd_config_atomic(struct scsi_disk *sdkp, struct queue_limits *lim)
if (sdkp->atomic_alignment > 1) {
if (unit_min > 1 && unit_min % sdkp->atomic_alignment)
- return;
+ goto out_unsupported;
if (unit_max > 1 && unit_max % sdkp->atomic_alignment)
- return;
+ goto out_unsupported;
}
lim->atomic_write_hw_max = max_atomic * logical_block_size;
lim->atomic_write_hw_boundary = 0;
lim->atomic_write_hw_unit_min = unit_min * logical_block_size;
lim->atomic_write_hw_unit_max = unit_max * logical_block_size;
+
+ lim->features |= BLK_FEAT_ATOMIC_WRITES;
+ return;
+
+out_unsupported:
+ lim->features &= ~BLK_FEAT_ATOMIC_WRITES;
+ return;
}
static blk_status_t sd_setup_write_same16_cmnd(struct scsi_cmnd *cmd,
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index af8434e391fa..c8c6a496a6ed 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -332,6 +332,9 @@ typedef unsigned int __bitwise blk_features_t;
#define BLK_FEAT_RAID_PARTIAL_STRIPES_EXPENSIVE \
((__force blk_features_t)(1u << 15))
+/* device supports atomic writes */
+#define BLK_FEAT_ATOMIC_WRITES ((__force blk_features_t)(1u << 16))
+
/*
* Flags automatically inherited when stacking limits.
*/
--
2.31.1
next prev parent reply other threads:[~2024-09-03 15:08 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-03 15:07 [PATCH RFC 0/4] RAID0 atomic write support John Garry
2024-09-03 15:07 ` [PATCH RFC 1/4] block: Make bdev_can_atomic_write() robust against mis-aligned bdev size John Garry
2024-09-12 13:15 ` Christoph Hellwig
2024-09-12 14:58 ` John Garry
2024-09-12 15:07 ` Christoph Hellwig
2024-09-12 15:22 ` John Garry
2024-09-13 8:36 ` Hannes Reinecke
2024-09-03 15:07 ` John Garry [this message]
2024-09-12 13:16 ` [PATCH RFC 2/4] block: Add BLK_FEAT_ATOMIC_WRITES flag Christoph Hellwig
2024-09-12 14:58 ` John Garry
2024-09-03 15:07 ` [PATCH RFC 3/4] block: Support atomic writes limits for stacked devices John Garry
2024-09-12 13:16 ` Christoph Hellwig
2024-09-12 15:05 ` John Garry
2024-09-03 15:07 ` [PATCH RFC 4/4] md/raid0: Atomic write support John Garry
2024-09-12 13:18 ` Christoph Hellwig
2024-09-12 14:48 ` John Garry
2024-09-12 15:10 ` Christoph Hellwig
2024-09-12 15:38 ` John Garry
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=20240903150748.2179966-3-john.g.garry@oracle.com \
--to=john.g.garry@oracle.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=linux-raid@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=sagi@grimberg.me \
--cc=song@kernel.org \
--cc=yukuai3@huawei.com \
/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