nvmet: add revalidate ns sysfs attribute to handle device resize
Subsystems (2)
PATCH 1/1 nvmet: add revalidate ns sysfs attribute to handle device resize
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
--- 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(-)
drivers/nvme/target/configfs.c +14 -0
@@ -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
drivers/nvme/target/core.c +23 -0
@@ -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);
drivers/nvme/target/io-cmd-bdev.c +14 -2
@@ -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 ;
drivers/nvme/target/io-cmd-file.c +30 -12
64 lines not on this page · raw message
drivers/nvme/target/nvmet.h +3 -0
@@ -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);
Signature · 4 lines
_______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Sagi Grimberg
maintainerQuoted 8 lines
drivers/nvme/target/core.c +7
-0+int nvmet_ns_revalidate (struct nvmet_ns *ns) +{ +struct nvmet_subsys *subsys = ns->subsys; +int ret =0 ; + +mutex_lock (&subsys->lock); +if (!ns->enabled){
drivers/nvme/target/core.c void nvmet_ns_disable(struct nvmet_ns *ns) · line 639
Quoted 10 lines
drivers/nvme/target/core.c +10
-0+ 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);
Shouldn't that happen only of the size changed?
So what is the model here? have some udev rule to
trigger this?
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerQuoted 11 lines · Sagi Grimberg
Quoted 11 lines
drivers/nvme/target/core.c +11
-0+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){
Quoted 8 lines
drivers/nvme/target/core.c void nvmet_ns_disable(struct nvmet_ns *ns) · line 639
Quoted 6 lines
drivers/nvme/target/core.c +6
-0+ ret =nvmet_bdev_ns_revalidate (ns); + }else if (ns->file){ + ret =nvmet_file_ns_revalidate (ns); + } + +nvmet_ns_changed (subsys, ns->nsid);Shouldn't that happen only of the size changed?
s/of/if/ ?
I guess we could do a sanity check first.
Quoted 2 lines
So what is the model here? have some udev rule to
trigger this?
Well, even if there was a udev rule we can't directly rely on it. Mikhail actually talked with me about this at SDC, and I suggested to just implement a simple file to revalidate from userspace, as we have no good way to figure out if it changed in the kernel code.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Sagi Grimberg
maintainerQuoted 21 lines
Quoted 12 lines
Quoted 12 lines
drivers/nvme/target/core.c +11
-0+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){Quoted 8 lines
drivers/nvme/target/core.c void nvmet_ns_disable(struct nvmet_ns *ns) · line 639
Quoted 6 lines
drivers/nvme/target/core.c +6
-0+ ret =nvmet_bdev_ns_revalidate (ns); + }else if (ns->file){ + ret =nvmet_file_ns_revalidate (ns); + } + +nvmet_ns_changed (subsys, ns->nsid);Shouldn't that happen only of the size changed?
Quoted 1 line
s/of/if/ ?
Yes..
Quoted 6 lines
I guess we could do a sanity check first.
Quoted 2 lines
So what is the model here? have some udev rule to
trigger this?Well, even if there was a udev rule we can't directly rely on it.
What do you mean we can't rely on it?
I do understand that we'd have no triggers for file-backed namespaces.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerQuoted 5 lines · Sagi Grimberg
Quoted 1 line
Well, even if there was a udev rule we can't directly rely on it.
What do you mean we can't rely on it?
I do understand that we'd have no triggers for file-backed namespaces.
Do we have any generic way supported by all block device drivers to notify resizes? For files we could at least use dnotify/inotify/fsnotify/ etc in userspace.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Just posted an updated version with size check before triggering ns_changed.
Regarding the model, I’m managing both block devices and targets from userspace daemon, so just need any reliable way to update target ns size once I resized block device.
Quoted 23 lines · Sagi Grimberg
Quoted 9 lines
drivers/nvme/target/core.c +7
-0+int nvmet_ns_revalidate (struct nvmet_ns *ns) +{ +struct nvmet_subsys *subsys = ns->subsys; +int ret =0 ; + +mutex_lock (&subsys->lock); +if (!ns->enabled){drivers/nvme/target/core.c void nvmet_ns_disable(struct nvmet_ns *ns) · line 639
Quoted 10 lines
drivers/nvme/target/core.c +10
-0+ 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);Shouldn't that happen only of the size changed?
Quoted 2 lines
So what is the model here? have some udev rule to
trigger this?
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH v2 1/1 nvmet: add revalidate ns sysfs attribute to handle device resize
In reply to Mikhail MalyginFrom: Mikhail Malygin <[email protected]>
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
--- drivers/nvme/target/configfs.c | 14 +++++++++++ drivers/nvme/target/core.c | 31 +++++++++++++++++++++++ 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, 92 insertions(+), 14 deletions(-)
drivers/nvme/target/configfs.c +14 -0
@@ -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
drivers/nvme/target/core.c +31 -0
@@ -620,6 +620,37 @@ 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; +loff_t ns_size = ns->size; +u32 ns_blksize_shift = ns->blksize_shift; +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); + } + +if (ret){ + goto out_unlock; + } + +if (ns->size != ns_size || ns->blksize_shift != ns_blksize_shift){ +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);
drivers/nvme/target/io-cmd-bdev.c +14 -2
@@ -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 ;
drivers/nvme/target/io-cmd-file.c +30 -12
64 lines not on this page · raw message
drivers/nvme/target/nvmet.h +3 -0
@@ -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);
Signature · 4 lines
_______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Sagi Grimberg
maintainerThis looks fine to me,
Christoph, you happy with this version?
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Quoted 4 lines · Sagi Grimberg
This looks fine to me,
Christoph, you happy with this version?
Conceptually yes, but it really needs to at least follow the kernel style. I'm also not sure I'm happy about all the extra indirections, but I can be talked into it.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Just posted updated version with code style cleanup.
Quoted 11 lines · Christoph Hellwig
Quoted 4 lines · Sagi Grimberg
This looks fine to me,
Christoph, you happy with this version?
Conceptually yes, but it really needs to at least follow the kernel style. I'm also not sure I'm happy about all the extra indirections, but I can be talked into it.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH v3 1/1 nvmet: add revalidate ns sysfs attribute to handle device resize
In reply to Mikhail MalyginFrom: Mikhail Malygin <[email protected]>
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
--- drivers/nvme/target/configfs.c | 14 +++++++++++ drivers/nvme/target/core.c | 27 +++++++++++++++++++++ drivers/nvme/target/io-cmd-bdev.c | 16 +++++++++++-- drivers/nvme/target/io-cmd-file.c | 39 ++++++++++++++++++++++--------- drivers/nvme/target/nvmet.h | 3 +++ 5 files changed, 86 insertions(+), 13 deletions(-)
drivers/nvme/target/configfs.c +14 -0
@@ -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
drivers/nvme/target/core.c +27 -0
@@ -620,6 +620,33 @@ 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; +loff_t ns_size = ns->size; +u32 ns_blksize_shift = ns->blksize_shift; +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); + +if (ret) + goto out_unlock; + +if (ns->size != ns_size || ns->blksize_shift != ns_blksize_shift) +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);
drivers/nvme/target/io-cmd-bdev.c +14 -2
@@ -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 ;
drivers/nvme/target/io-cmd-file.c +28 -11
@@ -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,19 +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 ); + ret =nvmet_file_ns_read_size (ns); +if (ret) goto err; - 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 ); - ns->bvec_cache =kmem_cache_create ("nvmet-bvec" ,NVMET_MAX_MPOOL_BVEC *sizeof (struct bio_vec ),0 ,SLAB_HWCACHE_ALIGN ,NULL );
@@ -80,6 +92,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);
drivers/nvme/target/nvmet.h +3 -0
@@ -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);
Signature · 4 lines
_______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
drivers/nvme/target/configfs.c static ssize_t nvmet_ns_buffered_io_store(struct config_item *item, · line 556
Quoted 9 lines
drivers/nvme/target/configfs.c +9
-0+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;
Nit: no need to initialize ret, and we can use a normal if here:
ret = nvmet_ns_revalidate(ns); if (ret) return ret; return count;
drivers/nvme/target/io-cmd-bdev.c void nvmet_bdev_ns_disable(struct nvmet_ns *ns) · line 88
Quoted 5 lines
drivers/nvme/target/io-cmd-bdev.c +5
-0+int nvmet_bdev_ns_revalidate (struct nvmet_ns *ns) +{ +nvmet_bdev_ns_read_size (ns); +return 0 ; +}
I think we can just remove this wrapper.
drivers/nvme/target/io-cmd-file.c void nvmet_file_ns_disable(struct nvmet_ns *ns) · line 36
Quoted 7 lines
drivers/nvme/target/io-cmd-file.c +7
-0+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 );
Nit: you can add more arguments to the first line:
ret = vfs_getattr(&ns->file->f_path, &stat, STATX_SIZE, AT_STATX_FORCE_SYNC);
drivers/nvme/target/io-cmd-file.c int nvmet_file_ns_enable(struct nvmet_ns *ns) · line 98
Quoted 4 lines
drivers/nvme/target/io-cmd-file.c +4
-0+int nvmet_file_ns_revalidate (struct nvmet_ns *ns) +{ +return nvmet_file_ns_read_size (ns); +}
And we can just remove this wrapper as well.
Or in fact rename the low-level functions to *_revalidate which might be a little more obvious. But either way I don't think we need small wrappers.
Otherwise this looks good to me, thanks for doing the work!
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Thanks for the detailed feedback! Posted an updated version to the ml.
Quoted 47 lines · Christoph Hellwig
drivers/nvme/target/configfs.c static ssize_t nvmet_ns_buffered_io_store(struct config_item *item, · line 556
Quoted 10 lines
drivers/nvme/target/configfs.c +9
-0+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;Nit: no need to initialize ret, and we can use a normal if here:
ret = nvmet_ns_revalidate(ns); if (ret) return ret; return count;drivers/nvme/target/io-cmd-bdev.c void nvmet_bdev_ns_disable(struct nvmet_ns *ns) · line 88
Quoted 5 lines
drivers/nvme/target/io-cmd-bdev.c +5
-0+int nvmet_bdev_ns_revalidate (struct nvmet_ns *ns) +{ +nvmet_bdev_ns_read_size (ns); +return 0 ; +}I think we can just remove this wrapper.
drivers/nvme/target/io-cmd-file.c void nvmet_file_ns_disable(struct nvmet_ns *ns) · line 36
Quoted 7 lines
drivers/nvme/target/io-cmd-file.c +7
-0+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 );Nit: you can add more arguments to the first line:
ret = vfs_getattr(&ns->file->f_path, &stat, STATX_SIZE, AT_STATX_FORCE_SYNC);drivers/nvme/target/io-cmd-file.c int nvmet_file_ns_enable(struct nvmet_ns *ns) · line 98
Quoted 4 lines
drivers/nvme/target/io-cmd-file.c +4
-0+int nvmet_file_ns_revalidate (struct nvmet_ns *ns) +{ +return nvmet_file_ns_read_size (ns); +}And we can just remove this wrapper as well.
Quoted 5 lines
Or in fact rename the low-level functions to
*_revalidatewhich might be a little more obvious. But either way I don't think we need small wrappers.Otherwise this looks good to me, thanks for doing the work!
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH v4 1/1 nvmet: add revalidate ns sysfs attribute to handle device resize
In reply to Mikhail MalyginFrom: Mikhail Malygin <[email protected]>
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
--- drivers/nvme/target/configfs.c | 16 +++++++++++++++ drivers/nvme/target/core.c | 27 ++++++++++++++++++++++++ drivers/nvme/target/io-cmd-bdev.c | 10 +++++++-- drivers/nvme/target/io-cmd-file.c | 34 +++++++++++++++++++++---------- drivers/nvme/target/nvmet.h | 3 +++ 5 files changed, 77 insertions(+), 13 deletions(-)
drivers/nvme/target/configfs.c +16 -0
@@ -545,6 +545,21 @@ 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; + + ret =nvmet_ns_revalidate (ns); +if (ret) +return ret; + +return 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 +567,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
drivers/nvme/target/core.c +27 -0
@@ -620,6 +620,33 @@ 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; +loff_t ns_size = ns->size; +u32 ns_blksize_shift = ns->blksize_shift; +int ret =0 ; + +mutex_lock (&subsys->lock); +if (!ns->enabled) + goto out_unlock; + +if (ns->bdev) +nvmet_bdev_ns_read_size (ns); +else if (ns->file) + ret =nvmet_file_ns_read_size (ns); + +if (ret) + goto out_unlock; + +if (ns->size != ns_size || ns->blksize_shift != ns_blksize_shift) +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);
drivers/nvme/target/io-cmd-bdev.c +8 -2
@@ -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); } +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 ; }
drivers/nvme/target/io-cmd-file.c +23 -11
@@ -27,10 +27,30 @@ void nvmet_file_ns_disable(struct nvmet_ns *ns) } } +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,19 +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 ); + ret =nvmet_file_ns_read_size (ns); +if (ret) goto err; - 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 ); - ns->bvec_cache =kmem_cache_create ("nvmet-bvec" ,NVMET_MAX_MPOOL_BVEC *sizeof (struct bio_vec ),0 ,SLAB_HWCACHE_ALIGN ,NULL );
drivers/nvme/target/nvmet.h +3 -0
@@ -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); +void nvmet_bdev_ns_read_size (struct nvmet_ns *ns); +int nvmet_file_ns_read_size (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);
Signature · 4 lines
_______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Hi Mikhail,
Please some inline nit comments.
Quoted 4 lines · On 10/7/19 12:57 PM, [email protected] wrote:
From: Mikhail Malygin <[email protected]>
nit :-
Currently device size is cached inns->sizefield on namespace enable, so any device size change after that can't bee seen by initiator.
nit :- any device size change after that can't bee seen by the initiator.
Quoted 3 lines
This patch adds revalidate namespace attribute. Once it is written, target refreshes
ns->sizeproperty and callsnvmet_ns_changedso initator may perform namespace rescan
nit :- so initiator may perform namespace rescan.
Quoted 49 lines
Signed-off-by Mikhail Malygin <[email protected]>--- drivers/nvme/target/configfs.c | 16 +++++++++++++++ drivers/nvme/target/core.c | 27 ++++++++++++++++++++++++ drivers/nvme/target/io-cmd-bdev.c | 10 +++++++-- drivers/nvme/target/io-cmd-file.c | 34 +++++++++++++++++++++---------- drivers/nvme/target/nvmet.h | 3 +++ 5 files changed, 77 insertions(+), 13 deletions(-)drivers/nvme/target/configfs.c +16
-0@@ -545,6 +545,21 @@ 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; + + ret =nvmet_ns_revalidate (ns); +if (ret) +return ret; + +return 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 +567,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, #endifdrivers/nvme/target/core.c +0
-0
drivers/nvme/target/core.c void nvmet_ns_disable(struct nvmet_ns *ns) · line 628
Quoted 9 lines
drivers/nvme/target/core.c +6
-0@@ -620,6 +620,33 @@ 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; +loff_t ns_size = ns->size; +u32 ns_blksize_shift = ns->blksize_shift; +int ret =0 ;
nit:- Please consider :-
struct nvmet_subsys *subsys = ns->subsys; u32 ns_blksize_shift = ns->blksize_shift; loff_t ns_size = ns->size; int ret = 0;
drivers/nvme/target/core.c void nvmet_ns_disable(struct nvmet_ns *ns) · line 640
Quoted 12 lines
drivers/nvme/target/core.c +12
-0+ +mutex_lock (&subsys->lock); +if (!ns->enabled) + goto out_unlock; + +if (ns->bdev) +nvmet_bdev_ns_read_size (ns); +else if (ns->file) + ret =nvmet_file_ns_read_size (ns); + +if (ret) + goto out_unlock;
Nit:- since ret gets initialized as a part of the ns->file == true why not ?
if (ns->bdev)
nvmet_bdev_ns_read_size(ns);
else if (ns->file) {
ret = nvmet_file_ns_read_size(ns);
if (ret)
goto out_unlock
}Quoted 45 lines
drivers/nvme/target/core.c +9
-0+ +if (ns->size != ns_size || ns->blksize_shift != ns_blksize_shift) +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);drivers/nvme/target/io-cmd-bdev.c +8
-2@@ -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); } +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 ; }drivers/nvme/target/io-cmd-file.c +0
-0
drivers/nvme/target/io-cmd-file.c void nvmet_file_ns_disable(struct nvmet_ns *ns) · line 33
Quoted 7 lines
drivers/nvme/target/io-cmd-file.c +4
-0@@ -27,10 +27,30 @@ void nvmet_file_ns_disable(struct nvmet_ns *ns) } } +int nvmet_file_ns_read_size (struct nvmet_ns *ns) +{ +int ret; +struct kstat stat;
nit again :-
struct kstat stat; int ret;
Quoted 25 lines
drivers/nvme/target/io-cmd-file.c +17
-1+ + 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)
drivers/nvme/target/io-cmd-file.c int nvmet_file_ns_enable(struct nvmet_ns *ns) · line 66
Quoted 6 lines
drivers/nvme/target/io-cmd-file.c +1
-2@@ -43,19 +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 ); + ret =nvmet_file_ns_read_size (ns);
nit:- no need for following new line.
Quoted 29 lines
drivers/nvme/target/io-cmd-file.c +1
-8+if (ret) goto err; - 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 ); - ns->bvec_cache =kmem_cache_create ("nvmet-bvec" ,NVMET_MAX_MPOOL_BVEC *sizeof (struct bio_vec ),0 ,SLAB_HWCACHE_ALIGN ,NULL );drivers/nvme/target/nvmet.h +1
-0@@ -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);
drivers/nvme/target/nvmet.h int nvmet_bdev_ns_enable(struct nvmet_ns *ns); · line 493
Quoted 8 lines
drivers/nvme/target/nvmet.h +2
-0@@ -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); +void nvmet_bdev_ns_read_size (struct nvmet_ns *ns); +int nvmet_file_ns_read_size (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
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Thanks, posted an updated version.
Quoted 218 lines · Chaitanya Kulkarni
Hi Mikhail,
Please some inline nit comments.
Quoted 4 lines · On 10/7/19 12:57 PM, [email protected] wrote:
From: Mikhail Malygin <[email protected]>
nit :-
Currently device size is cached inns->sizefield on namespace enable, so any device size change after that can't bee seen by initiator.nit :- any device size change after that can't bee seen by the initiator.
Quoted 3 lines
This patch adds revalidate namespace attribute. Once it is written, target refreshes
ns->sizeproperty and callsnvmet_ns_changedso initator may perform namespace rescannit :- so initiator may perform namespace rescan.
Quoted 49 lines
Signed-off-by Mikhail Malygin <[email protected]>--- drivers/nvme/target/configfs.c | 16 +++++++++++++++ drivers/nvme/target/core.c | 27 ++++++++++++++++++++++++ drivers/nvme/target/io-cmd-bdev.c | 10 +++++++-- drivers/nvme/target/io-cmd-file.c | 34 +++++++++++++++++++++---------- drivers/nvme/target/nvmet.h | 3 +++ 5 files changed, 77 insertions(+), 13 deletions(-)drivers/nvme/target/configfs.c +16
-0@@ -545,6 +545,21 @@ 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; + + ret =nvmet_ns_revalidate (ns); +if (ret) +return ret; + +return 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 +567,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, #endifdrivers/nvme/target/core.c +0
-0drivers/nvme/target/core.c void nvmet_ns_disable(struct nvmet_ns *ns) · line 628
Quoted 9 lines
drivers/nvme/target/core.c +6
-0@@ -620,6 +620,33 @@ 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; +loff_t ns_size = ns->size; +u32 ns_blksize_shift = ns->blksize_shift; +int ret =0 ;nit:- Please consider :-
struct nvmet_subsys *subsys = ns->subsys; u32 ns_blksize_shift = ns->blksize_shift; loff_t ns_size = ns->size; int ret = 0;drivers/nvme/target/core.c void nvmet_ns_disable(struct nvmet_ns *ns) · line 640
Quoted 12 lines
drivers/nvme/target/core.c +12
-0+ +mutex_lock (&subsys->lock); +if (!ns->enabled) + goto out_unlock; + +if (ns->bdev) +nvmet_bdev_ns_read_size (ns); +else if (ns->file) + ret =nvmet_file_ns_read_size (ns); + +if (ret) + goto out_unlock;Nit:- since ret gets initialized as a part of the
ns->file== true why not ?if (ns->bdev) nvmet_bdev_ns_read_size(ns); else if (ns->file) { ret = nvmet_file_ns_read_size(ns); if (ret) goto out_unlock }Quoted 45 lines
drivers/nvme/target/core.c +9
-0+ +if (ns->size != ns_size || ns->blksize_shift != ns_blksize_shift) +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);drivers/nvme/target/io-cmd-bdev.c +8
-2@@ -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); } +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 ; }drivers/nvme/target/io-cmd-file.c +0
-0drivers/nvme/target/io-cmd-file.c void nvmet_file_ns_disable(struct nvmet_ns *ns) · line 33
Quoted 7 lines
drivers/nvme/target/io-cmd-file.c +4
-0@@ -27,10 +27,30 @@ void nvmet_file_ns_disable(struct nvmet_ns *ns) } } +int nvmet_file_ns_read_size (struct nvmet_ns *ns) +{ +int ret; +struct kstat stat;nit again :-
struct kstat stat; int ret;Quoted 25 lines
drivers/nvme/target/io-cmd-file.c +17
-1+ + 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)drivers/nvme/target/io-cmd-file.c int nvmet_file_ns_enable(struct nvmet_ns *ns) · line 66
Quoted 6 lines
drivers/nvme/target/io-cmd-file.c +1
-2@@ -43,19 +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 ); + ret =nvmet_file_ns_read_size (ns);nit:- no need for following new line.
Quoted 27 lines
drivers/nvme/target/io-cmd-file.c +1
-8+if (ret) goto err; - 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 ); - ns->bvec_cache =kmem_cache_create ("nvmet-bvec" ,NVMET_MAX_MPOOL_BVEC *sizeof (struct bio_vec ),0 ,SLAB_HWCACHE_ALIGN ,NULL );drivers/nvme/target/nvmet.h +1
-0@@ -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);
Quoted 11 lines
drivers/nvme/target/nvmet.h int nvmet_bdev_ns_enable(struct nvmet_ns *ns); · line 493
Quoted 10 lines
drivers/nvme/target/nvmet.h +2
-0@@ -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); +void nvmet_bdev_ns_read_size (struct nvmet_ns *ns); +int nvmet_file_ns_read_size (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
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Quoted 9 lines · On Mon, Oct 07, 2019 at 10:57:09PM +0300, [email protected] wrote:
From: Mikhail Malygin <[email protected]>
Currently device size is cached in
ns->sizefield 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 refreshesns->sizeproperty and callsnvmet_ns_changedso initator may perform namespace rescanSigned-off-by Mikhail Malygin <[email protected]>
Looks good,
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH v5 1/1 nvmet: add revalidate ns sysfs attribute to handle device resize
In reply to Mikhail MalyginFrom: Mikhail Malygin <[email protected]>
Currently device size is cached in ns->size field on namespace enable, so any device size change after that can't bee seen by the initiator. This patch adds revalidate namespace attribute. Once it is written, target refreshes ns->size property and calls nvmet_ns_changed so initiator may perform namespace rescan
--- drivers/nvme/target/configfs.c | 16 +++++++++++++++ drivers/nvme/target/core.c | 27 +++++++++++++++++++++++++ drivers/nvme/target/io-cmd-bdev.c | 10 ++++++++-- drivers/nvme/target/io-cmd-file.c | 33 ++++++++++++++++++++----------- drivers/nvme/target/nvmet.h | 3 +++ 5 files changed, 76 insertions(+), 13 deletions(-)
drivers/nvme/target/configfs.c +16 -0
@@ -545,6 +545,21 @@ 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; + + ret =nvmet_ns_revalidate (ns); +if (ret) +return ret; + +return 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 +567,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
drivers/nvme/target/core.c +27 -0
@@ -620,6 +620,33 @@ 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; +u32 ns_blksize_shift = ns->blksize_shift; +loff_t ns_size = ns->size; +int ret =0 ; + +mutex_lock (&subsys->lock); +if (!ns->enabled) + goto out_unlock; + +if (ns->bdev) +nvmet_bdev_ns_read_size (ns); +else if (ns->file) { + ret =nvmet_file_ns_read_size (ns); +if (ret) + goto out_unlock; + } + +if (ns->size != ns_size || ns->blksize_shift != ns_blksize_shift) +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);
drivers/nvme/target/io-cmd-bdev.c +8 -2
@@ -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); } +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 ; }
drivers/nvme/target/io-cmd-file.c +22 -11
@@ -27,10 +27,30 @@ void nvmet_file_ns_disable(struct nvmet_ns *ns) } } +int nvmet_file_ns_read_size (struct nvmet_ns *ns) +{ +struct kstat stat; +int ret; + + 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,19 +63,10 @@ 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 ); + ret =nvmet_file_ns_read_size (ns);if (ret) goto err; - 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 ); - ns->bvec_cache =kmem_cache_create ("nvmet-bvec" ,NVMET_MAX_MPOOL_BVEC *sizeof (struct bio_vec ),0 ,SLAB_HWCACHE_ALIGN ,NULL );
drivers/nvme/target/nvmet.h +3 -0
@@ -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); +void nvmet_bdev_ns_read_size (struct nvmet_ns *ns); +int nvmet_file_ns_read_size (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);
Signature · 4 lines
_______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Thanks foe this patch Mikhail.
Looks good.
Quoted 7 lines · On 10/8/19 5:29 AM, [email protected] wrote:
From: Mikhail Malygin<[email protected]>
Currently device size is cached in
ns->sizefield on namespace enable, so any device size change after that can't bee seen by the initiator. This patch adds revalidate namespace attribute. Once it is written, target refreshesns->sizeproperty and callsnvmet_ns_changedso initiator may perform namespace rescan
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme