From: Mikhail Malygin <m.malygin@yadro.com>
To: <linux-nvme@lists.infradead.org>
Cc: Christoph Hellwig <hch@lst.de>, Mikhail Malygin <m.malygin@yadro.com>
Subject: [PATCH] nvmet: add revalidate ns sysfs attribute to handle device resize
Date: Fri, 27 Sep 2019 02:19:40 +0300 [thread overview]
Message-ID: <20190926231940.7494-1-m.malygin@yadro.com> (raw)
Currently device size is cached in ns->size field on namespace enable, so
any device size change after that can't bee seen by initiator.
This patch adds revalidate namespace attribute. Once it is written,
target refreshes ns->size property and calls nvmet_ns_changed
so initator may perform namespace rescan
Signed-off-by: Mikhail Malygin <m.malygin@yadro.com>
---
drivers/nvme/target/configfs.c | 14 +++++++++++
drivers/nvme/target/core.c | 23 +++++++++++++++++
drivers/nvme/target/io-cmd-bdev.c | 16 ++++++++++--
drivers/nvme/target/io-cmd-file.c | 42 ++++++++++++++++++++++---------
drivers/nvme/target/nvmet.h | 3 +++
5 files changed, 84 insertions(+), 14 deletions(-)
diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c
index 98613a45bd3b..06566ad1d197 100644
--- a/drivers/nvme/target/configfs.c
+++ b/drivers/nvme/target/configfs.c
@@ -545,6 +545,19 @@ static ssize_t nvmet_ns_buffered_io_store(struct config_item *item,
CONFIGFS_ATTR(nvmet_ns_, buffered_io);
+static ssize_t nvmet_ns_revalidate_store(struct config_item *item,
+ const char *page, size_t count)
+{
+ struct nvmet_ns *ns = to_nvmet_ns(item);
+ int ret = 0;
+
+ ret = nvmet_ns_revalidate(ns);
+
+ return ret ? ret : count;
+}
+
+CONFIGFS_ATTR_WO(nvmet_ns_, revalidate);
+
static struct configfs_attribute *nvmet_ns_attrs[] = {
&nvmet_ns_attr_device_path,
&nvmet_ns_attr_device_nguid,
@@ -552,6 +565,7 @@ static struct configfs_attribute *nvmet_ns_attrs[] = {
&nvmet_ns_attr_ana_grpid,
&nvmet_ns_attr_enable,
&nvmet_ns_attr_buffered_io,
+ &nvmet_ns_attr_revalidate,
#ifdef CONFIG_PCI_P2PDMA
&nvmet_ns_attr_p2pmem,
#endif
diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index 3a67e244e568..1d90803e3c9a 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -620,6 +620,29 @@ void nvmet_ns_disable(struct nvmet_ns *ns)
mutex_unlock(&subsys->lock);
}
+int nvmet_ns_revalidate(struct nvmet_ns *ns)
+{
+ struct nvmet_subsys *subsys = ns->subsys;
+ int ret = 0;
+
+ mutex_lock(&subsys->lock);
+ if(!ns->enabled){
+ goto out_unlock;
+ }
+
+ if(ns->bdev){
+ ret = nvmet_bdev_ns_revalidate(ns);
+ }else if(ns->file){
+ ret = nvmet_file_ns_revalidate(ns);
+ }
+
+ nvmet_ns_changed(subsys, ns->nsid);
+
+out_unlock:
+ mutex_unlock(&subsys->lock);
+ return ret;
+}
+
void nvmet_ns_free(struct nvmet_ns *ns)
{
nvmet_ns_disable(ns);
diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c
index de0bff70ebb6..ea55bbe93813 100644
--- a/drivers/nvme/target/io-cmd-bdev.c
+++ b/drivers/nvme/target/io-cmd-bdev.c
@@ -47,6 +47,12 @@ void nvmet_bdev_set_limits(struct block_device *bdev, struct nvme_id_ns *id)
id->nows = to0based(ql->io_opt / ql->logical_block_size);
}
+static void nvmet_bdev_ns_read_size(struct nvmet_ns *ns)
+{
+ ns->size = i_size_read(ns->bdev->bd_inode);
+ ns->blksize_shift = blksize_bits(bdev_logical_block_size(ns->bdev));
+}
+
int nvmet_bdev_ns_enable(struct nvmet_ns *ns)
{
int ret;
@@ -62,8 +68,8 @@ int nvmet_bdev_ns_enable(struct nvmet_ns *ns)
ns->bdev = NULL;
return ret;
}
- ns->size = i_size_read(ns->bdev->bd_inode);
- ns->blksize_shift = blksize_bits(bdev_logical_block_size(ns->bdev));
+
+ nvmet_bdev_ns_read_size(ns);
return 0;
}
@@ -75,6 +81,12 @@ void nvmet_bdev_ns_disable(struct nvmet_ns *ns)
}
}
+int nvmet_bdev_ns_revalidate(struct nvmet_ns *ns)
+{
+ nvmet_bdev_ns_read_size(ns);
+ return 0;
+}
+
static u16 blk_to_nvme_status(struct nvmet_req *req, blk_status_t blk_sts)
{
u16 status = NVME_SC_SUCCESS;
diff --git a/drivers/nvme/target/io-cmd-file.c b/drivers/nvme/target/io-cmd-file.c
index 05453f5d1448..84a2d664d39a 100644
--- a/drivers/nvme/target/io-cmd-file.c
+++ b/drivers/nvme/target/io-cmd-file.c
@@ -27,10 +27,30 @@ void nvmet_file_ns_disable(struct nvmet_ns *ns)
}
}
+static int nvmet_file_ns_read_size(struct nvmet_ns *ns)
+{
+ int ret;
+ struct kstat stat;
+
+ ret = vfs_getattr(&ns->file->f_path,
+ &stat, STATX_SIZE, AT_STATX_FORCE_SYNC);
+ if (ret)
+ return ret;
+
+ ns->size = stat.size;
+ /*
+ * i_blkbits can be greater than the universally accepted upper bound,
+ * so make sure we export a sane namespace lba_shift.
+ */
+ ns->blksize_shift = min_t(u8,
+ file_inode(ns->file)->i_blkbits, 12);
+
+ return 0;
+}
+
int nvmet_file_ns_enable(struct nvmet_ns *ns)
{
int flags = O_RDWR | O_LARGEFILE;
- struct kstat stat;
int ret;
if (!ns->buffered_io)
@@ -43,18 +63,11 @@ int nvmet_file_ns_enable(struct nvmet_ns *ns)
return PTR_ERR(ns->file);
}
- ret = vfs_getattr(&ns->file->f_path,
- &stat, STATX_SIZE, AT_STATX_FORCE_SYNC);
- if (ret)
- goto err;
+ ret = nvmet_file_ns_read_size(ns);
- ns->size = stat.size;
- /*
- * i_blkbits can be greater than the universally accepted upper bound,
- * so make sure we export a sane namespace lba_shift.
- */
- ns->blksize_shift = min_t(u8,
- file_inode(ns->file)->i_blkbits, 12);
+ if(ret){
+ goto err;
+ }
ns->bvec_cache = kmem_cache_create("nvmet-bvec",
NVMET_MAX_MPOOL_BVEC * sizeof(struct bio_vec),
@@ -80,6 +93,11 @@ int nvmet_file_ns_enable(struct nvmet_ns *ns)
return ret;
}
+int nvmet_file_ns_revalidate(struct nvmet_ns *ns)
+{
+ return nvmet_file_ns_read_size(ns);
+}
+
static void nvmet_file_init_bvec(struct bio_vec *bv, struct scatterlist *sg)
{
bv->bv_page = sg_page(sg);
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index c51f8dd01dc4..a9453e63e5dd 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -408,6 +408,7 @@ struct nvmet_ns *nvmet_find_namespace(struct nvmet_ctrl *ctrl, __le32 nsid);
void nvmet_put_namespace(struct nvmet_ns *ns);
int nvmet_ns_enable(struct nvmet_ns *ns);
void nvmet_ns_disable(struct nvmet_ns *ns);
+int nvmet_ns_revalidate(struct nvmet_ns *ns);
struct nvmet_ns *nvmet_ns_alloc(struct nvmet_subsys *subsys, u32 nsid);
void nvmet_ns_free(struct nvmet_ns *ns);
@@ -485,6 +486,8 @@ int nvmet_bdev_ns_enable(struct nvmet_ns *ns);
int nvmet_file_ns_enable(struct nvmet_ns *ns);
void nvmet_bdev_ns_disable(struct nvmet_ns *ns);
void nvmet_file_ns_disable(struct nvmet_ns *ns);
+int nvmet_bdev_ns_revalidate(struct nvmet_ns *ns);
+int nvmet_file_ns_revalidate(struct nvmet_ns *ns);
u16 nvmet_bdev_flush(struct nvmet_req *req);
u16 nvmet_file_flush(struct nvmet_req *req);
void nvmet_ns_changed(struct nvmet_subsys *subsys, u32 nsid);
--
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
next reply other threads:[~2019-09-26 23:20 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-26 23:19 Mikhail Malygin [this message]
2019-09-27 17:24 ` [PATCH] nvmet: add revalidate ns sysfs attribute to handle device resize Sagi Grimberg
2019-09-27 22:13 ` Christoph Hellwig
2019-09-27 22:34 ` Sagi Grimberg
2019-09-27 22:51 ` Christoph Hellwig
2019-09-30 15:16 ` Mikhail Malygin
2019-09-30 15:02 ` [PATCH v2] " m.malygin
2019-10-05 0:03 ` Sagi Grimberg
2019-10-06 10:12 ` Christoph Hellwig
2019-10-07 7:45 ` Mikhail Malygin
2019-10-07 7:39 ` [PATCH v3] " m.malygin
2019-10-07 16:56 ` Christoph Hellwig
2019-10-07 19:58 ` Mikhail Malygin
2019-10-07 19:57 ` [PATCH v4] " m.malygin
2019-10-08 2:30 ` Chaitanya Kulkarni
2019-10-08 12:30 ` Mikhail Malygin
2019-10-08 7:16 ` Christoph Hellwig
2019-10-08 12:29 ` [PATCH v5] " m.malygin
2019-10-08 17:27 ` Chaitanya Kulkarni
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=20190926231940.7494-1-m.malygin@yadro.com \
--to=m.malygin@yadro.com \
--cc=hch@lst.de \
--cc=linux-nvme@lists.infradead.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;
as well as URLs for NNTP newsgroup(s).