From: Christoph Hellwig <hch@lst.de>
To: Joel Granados <j.granados@samsung.com>,
kbusch@kernel.org, sagi@grimberg.me
Cc: joshi.k@samsung.com, linux-nvme@lists.infradead.org,
gost.dev@samsung.com, k.jensen@samsung.com,
"Javier González" <javier.gonz@samsung.com>,
"Chaitanya Kulkarni" <kch@nvidia.com>
Subject: [PATCH 4/5] nvme: factor out a nvme_ns_is_readonly helper
Date: Mon, 18 Jul 2022 07:25:02 +0200 [thread overview]
Message-ID: <20220718052503.235270-5-hch@lst.de> (raw)
In-Reply-To: <20220718052503.235270-1-hch@lst.de>
Add a little helper to check if a namespace should be marked read-only
that uses a new is_readonly flag in the nvme_ns_info structure.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Javier González <javier.gonz@samsung.com>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Kanchan Joshi <joshi.k@samsung.com>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
---
drivers/nvme/host/core.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 659068f90165c..dca7580f785a8 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -36,6 +36,7 @@ struct nvme_ns_info {
u32 nsid;
__le32 anagrpid;
bool is_shared;
+ bool is_readonly;
bool is_ready;
};
@@ -1447,6 +1448,7 @@ static int nvme_ns_info_from_identify(struct nvme_ctrl *ctrl,
return ret;
info->anagrpid = id->anagrpid;
info->is_shared = id->nmic & NVME_NS_NMIC_SHARED;
+ info->is_readonly = id->nsattr & NVME_NS_ATTR_RO;
info->is_ready = true;
if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) {
dev_info(ctrl->device,
@@ -1482,6 +1484,7 @@ static int nvme_ns_info_from_id_cs_indep(struct nvme_ctrl *ctrl,
if (!ret) {
info->anagrpid = id->anagrpid;
info->is_shared = id->nmic & NVME_NS_NMIC_SHARED;
+ info->is_readonly = id->nsattr & NVME_NS_ATTR_RO;
info->is_ready = id->nstat & NVME_NSTAT_NRDY;
}
kfree(id);
@@ -1909,6 +1912,11 @@ static void nvme_update_disk_info(struct gendisk *disk,
ns->ctrl->max_zeroes_sectors);
}
+static bool nvme_ns_is_readonly(struct nvme_ns *ns, struct nvme_ns_info *info)
+{
+ return info->is_readonly || test_bit(NVME_NS_FORCE_RO, &ns->flags);
+}
+
static inline bool nvme_first_scan(struct gendisk *disk)
{
/* nvme_alloc_ns() scans the disk prior to adding it */
@@ -1972,8 +1980,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
goto out_unfreeze;
}
- set_disk_ro(ns->disk, (id->nsattr & NVME_NS_ATTR_RO) ||
- test_bit(NVME_NS_FORCE_RO, &ns->flags));
+ set_disk_ro(ns->disk, nvme_ns_is_readonly(ns, info));
set_bit(NVME_NS_READY, &ns->flags);
blk_mq_unfreeze_queue(ns->disk->queue);
@@ -1986,9 +1993,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
if (nvme_ns_head_multipath(ns->head)) {
blk_mq_freeze_queue(ns->head->disk->queue);
nvme_update_disk_info(ns->head->disk, ns, id);
- set_disk_ro(ns->head->disk,
- (id->nsattr & NVME_NS_ATTR_RO) ||
- test_bit(NVME_NS_FORCE_RO, &ns->flags));
+ set_disk_ro(ns->head->disk, nvme_ns_is_readonly(ns, info));
nvme_mpath_revalidate_paths(ns);
blk_stack_limits(&ns->head->disk->queue->limits,
&ns->queue->limits, 0);
--
2.30.2
next prev parent reply other threads:[~2022-07-18 5:25 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-18 5:24 enable generic interface (/dev/ngX) for unknown command sets v2 Christoph Hellwig
2022-07-18 5:24 ` [PATCH 1/5] nvme: rename nvme_validate_or_alloc_ns to nvme_scan_ns Christoph Hellwig
2022-07-19 13:07 ` Joel Granados
2022-07-18 5:25 ` [PATCH 2/5] nvme: generalize the nvme_multi_css check in nvme_scan_ns Christoph Hellwig
2022-07-18 5:25 ` [PATCH 3/5] nvme: refactor namespace probing Christoph Hellwig
2022-07-19 7:08 ` Kanchan Joshi
2022-07-19 13:00 ` Joel Granados
2022-07-19 14:37 ` Christoph Hellwig
2022-07-20 8:11 ` Joel Granados
2022-07-20 8:19 ` Joel Granados
2022-07-20 9:02 ` Christoph Hellwig
2022-07-20 12:15 ` Joel Granados
2022-07-18 5:25 ` Christoph Hellwig [this message]
2022-07-18 5:25 ` [PATCH 5/5] nvme: enable generic interface (/dev/ngXnY) for unknown command sets Christoph Hellwig
2022-07-21 22:14 ` enable generic interface (/dev/ngX) for unknown command sets v2 Sagi Grimberg
-- strict thread matches above, loose matches on Subject: below --
2022-07-13 5:49 enable generic interface (/dev/ngX) for unknown command sets Christoph Hellwig
2022-07-13 5:49 ` [PATCH 4/5] nvme: factor out a nvme_ns_is_readonly helper Christoph Hellwig
2022-07-13 7:55 ` Chaitanya Kulkarni
2022-07-13 9:23 ` Sagi Grimberg
2022-07-13 10:26 ` Kanchan Joshi
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=20220718052503.235270-5-hch@lst.de \
--to=hch@lst.de \
--cc=gost.dev@samsung.com \
--cc=j.granados@samsung.com \
--cc=javier.gonz@samsung.com \
--cc=joshi.k@samsung.com \
--cc=k.jensen@samsung.com \
--cc=kbusch@kernel.org \
--cc=kch@nvidia.com \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
/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.