refactor the nvme scanning and validation code
Subsystems (2)
Christoph Hellwig
maintainerHi all,
this series reworks how we can for and revalidate NVMe namespaces. The primary motive is to:
a) not update information like the block size without having the queue frozen
b) better structure the code for supporting multiple command sets
but it has all kinds of other minor fixes and cleanups as well.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerPATCH 1/20 block: optimize blk_queue_zoned_model for !CONFIG_BLK_DEV_ZONED
Always return BLK_ZONED_NONE if zoned device support is not enabled. This allows various compiler optimizations including the dead code elimination that we so like for avoiding ifdefs.
--- include/linux/blkdev.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
include/linux/blkdev.h +3 -1
@@ -692,7 +692,9 @@ static inline bool queue_is_mq(struct request_queue *q)static inline enum blk_zoned_model blk_queue_zoned_model (struct request_queue *q) { -return q->limits.zoned; +if (IS_ENABLED (CONFIG_BLK_DEV_ZONED )) +return q->limits.zoned; +return BLK_ZONED_NONE ; }static inline bool blk_queue_is_zoned (struct request_queue *q)
Signature · 7 lines
2.28.0 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 01/20] block: optimize blk_queue_zoned_model for !CONFIG_BLK_DEV_ZONED
Quoted 15 lines · Christoph Hellwig
Always return
BLK_ZONED_NONEif zoned device support is not enabled. This allows various compiler optimizations including the dead code elimination that we so like for avoiding ifdefs.Signed-off-by Christoph Hellwig <[email protected]>--- include/linux/blkdev.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)include/linux/blkdev.h +0
-0
include/linux/blkdev.h static inline bool queue_is_mq(struct request_queue *q) · line 700
Quoted 10 lines
include/linux/blkdev.h +3
-1@@ -692,7 +692,9 @@ static inline bool queue_is_mq(struct request_queue *q)static inline enum blk_zoned_model blk_queue_zoned_model (struct request_queue *q) { -return q->limits.zoned; +if (IS_ENABLED (CONFIG_BLK_DEV_ZONED )) +return q->limits.zoned; +return BLK_ZONED_NONE ; }static inline bool blk_queue_is_zoned (struct request_queue *q)
Looks good.
Signature · 7 lines
Damien Le Moal Western Digital Research _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 01/20] block: optimize blk_queue_zoned_model for !CONFIG_BLK_DEV_ZONED
In reply to Christoph HellwigLooks good, but seems misplaced in this set.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerRe: [PATCH 01/20] block: optimize blk_queue_zoned_model for !CONFIG_BLK_DEV_ZONED
Quoted 1 line · Sagi Grimberg
Looks good, but seems misplaced in this set.
It is needed by patch 2, so that calls to zone-specific code are optimized away for the !CONFIG_BLK_DEV_ZONED case.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 01/20] block: optimize blk_queue_zoned_model for !CONFIG_BLK_DEV_ZONED
In reply to Christoph HellwigQuoted 5 lines · Christoph Hellwig
Always return
BLK_ZONED_NONEif zoned device support is not enabled. This allows various compiler optimizations including the dead code elimination that we so like for avoiding ifdefs.Signed-off-by Christoph Hellwig <[email protected]>
Looks good.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerPATCH 2/20 nvme: fix initialization of the zone bitmaps
In reply to Christoph HellwigThe removal of the ->revalidate_disk method broke the initialization of the zone bitmaps, as nvme_revalidate_disk now never gets called during initialization.
Move the zone related code from nvme_revalidate_disk into a new helper in zns.c, and call it from nvme_alloc_ns in addition to nvme_validate_ns to ensure the zone bitmaps are initialized during probe.
--- drivers/nvme/host/core.c | 28 +++++----------------------- drivers/nvme/host/nvme.h | 1 + drivers/nvme/host/zns.c | 11 +++++++++++ 3 files changed, 17 insertions(+), 23 deletions(-)
drivers/nvme/host/core.c +5 -23
@@ -2202,28 +2202,6 @@ static int _nvme_revalidate_disk(struct gendisk *disk)return ret; } -static int nvme_revalidate_disk (struct gendisk *disk) -{ -int ret; - - ret =_nvme_revalidate_disk (disk); -if (ret) -return ret; - -#ifdef CONFIG_BLK_DEV_ZONED -if (blk_queue_is_zoned (disk->queue)) { -struct nvme_ns *ns = disk->private_data; -struct nvme_ctrl *ctrl = ns->ctrl; - - ret =blk_revalidate_disk_zones (disk,NULL ); -if (!ret) -blk_queue_max_zone_append_sectors (disk->queue, - ctrl->max_zone_append); - } -#endif -return ret; -} -static char nvme_pr_type (enum pr_type type) {switch (type) {
@@ -3958,6 +3936,8 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)if (__nvme_revalidate_disk (disk, id)) goto out_put_disk; +if (blk_queue_is_zoned (ns->queue) &&nvme_revalidate_zones (ns)) + goto out_put_disk;if ((ctrl->quirks &NVME_QUIRK_LIGHTNVM ) && id->vs[0 ] ==0x1 ) { ret =nvme_nvm_register (ns, disk_name, node);
@@ -4052,7 +4032,9 @@ static void nvme_validate_ns(struct nvme_ctrl *ctrl, unsigned nsid)return ; } - ret =nvme_revalidate_disk (ns->disk); + ret =_nvme_revalidate_disk (ns->disk); +if (!ret &&blk_queue_is_zoned (ns->queue)) + ret =nvme_revalidate_zones (ns);revalidate_disk_size (ns->disk, ret ==0 );if (ret)nvme_ns_remove (ns);
drivers/nvme/host/nvme.h +1 -0
@@ -758,6 +758,7 @@ static inline void nvme_mpath_start_freeze(struct nvme_subsystem *subsys) }#endif /* CONFIG_NVME_MULTIPATH */ +int nvme_revalidate_zones (struct nvme_ns *ns);#ifdef CONFIG_BLK_DEV_ZONED int nvme_update_zone_info (struct gendisk *disk,struct nvme_ns *ns,unsigned lbaf);
drivers/nvme/host/zns.c +11 -0
@@ -7,6 +7,17 @@#include <linux/vmalloc.h> #include "nvme.h" +int nvme_revalidate_zones (struct nvme_ns *ns) +{ +struct request_queue *q = ns->disk->queue; +int ret; + + ret =blk_revalidate_disk_zones (ns->disk,NULL ); +if (!ret) +blk_queue_max_zone_append_sectors (q, ns->ctrl->max_zone_append); +return ret; +} +static int nvme_set_max_append (struct nvme_ctrl *ctrl) {struct nvme_command c = { };
Signature · 7 lines
2.28.0 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 02/20] nvme: fix initialization of the zone bitmaps
Quoted 93 lines · Christoph Hellwig
The removal of the ->revalidate_disk method broke the initialization of the zone bitmaps, as
nvme_revalidate_disknow never gets called during initialization.Move the zone related code from
nvme_revalidate_diskinto a new helper inzns.c, and call it fromnvme_alloc_nsin addition tonvme_validate_nsto ensure the zone bitmaps are initialized during probe.Signed-off-by Christoph Hellwig <[email protected]>--- drivers/nvme/host/core.c | 28 +++++----------------------- drivers/nvme/host/nvme.h | 1 + drivers/nvme/host/zns.c | 11 +++++++++++ 3 files changed, 17 insertions(+), 23 deletions(-)drivers/nvme/host/core.c +5
-23@@ -2202,28 +2202,6 @@ static int _nvme_revalidate_disk(struct gendisk *disk)return ret; } -static int nvme_revalidate_disk (struct gendisk *disk) -{ -int ret; - - ret =_nvme_revalidate_disk (disk); -if (ret) -return ret; - -#ifdef CONFIG_BLK_DEV_ZONED -if (blk_queue_is_zoned (disk->queue)) { -struct nvme_ns *ns = disk->private_data; -struct nvme_ctrl *ctrl = ns->ctrl; - - ret =blk_revalidate_disk_zones (disk,NULL ); -if (!ret) -blk_queue_max_zone_append_sectors (disk->queue, - ctrl->max_zone_append); - } -#endif -return ret; -} -static char nvme_pr_type (enum pr_type type) {switch (type) {@@ -3958,6 +3936,8 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)if (__nvme_revalidate_disk (disk, id)) goto out_put_disk; +if (blk_queue_is_zoned (ns->queue) &&nvme_revalidate_zones (ns)) + goto out_put_disk;if ((ctrl->quirks &NVME_QUIRK_LIGHTNVM ) && id->vs[0 ] ==0x1 ) { ret =nvme_nvm_register (ns, disk_name, node);@@ -4052,7 +4032,9 @@ static void nvme_validate_ns(struct nvme_ctrl *ctrl, unsigned nsid)return ; } - ret =nvme_revalidate_disk (ns->disk); + ret =_nvme_revalidate_disk (ns->disk); +if (!ret &&blk_queue_is_zoned (ns->queue)) + ret =nvme_revalidate_zones (ns);revalidate_disk_size (ns->disk, ret ==0 );if (ret)nvme_ns_remove (ns);drivers/nvme/host/nvme.h +1
-0@@ -758,6 +758,7 @@ static inline void nvme_mpath_start_freeze(struct nvme_subsystem *subsys) }#endif /* CONFIG_NVME_MULTIPATH */ +int nvme_revalidate_zones (struct nvme_ns *ns);#ifdef CONFIG_BLK_DEV_ZONED int nvme_update_zone_info (struct gendisk *disk,struct nvme_ns *ns,unsigned lbaf);drivers/nvme/host/zns.c +4
-0@@ -7,6 +7,17 @@#include <linux/vmalloc.h> #include "nvme.h" +int nvme_revalidate_zones (struct nvme_ns *ns) +{ +struct request_queue *q = ns->disk->queue; +int ret;
drivers/nvme/host/zns.c line 23
Quoted 10 lines
drivers/nvme/host/zns.c +7
-0+ + ret =blk_revalidate_disk_zones (ns->disk,NULL ); +if (!ret) +blk_queue_max_zone_append_sectors (q, ns->ctrl->max_zone_append); +return ret; +} +static int nvme_set_max_append (struct nvme_ctrl *ctrl) {struct nvme_command c = { };
Looks good.
Signature · 7 lines
Damien Le Moal Western Digital Research _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 02/20] nvme: fix initialization of the zone bitmaps
In reply to Christoph HellwigQuoted 85 lines · Christoph Hellwig
The removal of the ->revalidate_disk method broke the initialization of the zone bitmaps, as
nvme_revalidate_disknow never gets called during initialization.Move the zone related code from
nvme_revalidate_diskinto a new helper inzns.c, and call it fromnvme_alloc_nsin addition tonvme_validate_nsto ensure the zone bitmaps are initialized during probe.Signed-off-by Christoph Hellwig <[email protected]>--- drivers/nvme/host/core.c | 28 +++++----------------------- drivers/nvme/host/nvme.h | 1 + drivers/nvme/host/zns.c | 11 +++++++++++ 3 files changed, 17 insertions(+), 23 deletions(-)drivers/nvme/host/core.c +5
-23@@ -2202,28 +2202,6 @@ static int _nvme_revalidate_disk(struct gendisk *disk)return ret; } -static int nvme_revalidate_disk (struct gendisk *disk) -{ -int ret; - - ret =_nvme_revalidate_disk (disk); -if (ret) -return ret; - -#ifdef CONFIG_BLK_DEV_ZONED -if (blk_queue_is_zoned (disk->queue)) { -struct nvme_ns *ns = disk->private_data; -struct nvme_ctrl *ctrl = ns->ctrl; - - ret =blk_revalidate_disk_zones (disk,NULL ); -if (!ret) -blk_queue_max_zone_append_sectors (disk->queue, - ctrl->max_zone_append); - } -#endif -return ret; -} -static char nvme_pr_type (enum pr_type type) {switch (type) {@@ -3958,6 +3936,8 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)if (__nvme_revalidate_disk (disk, id)) goto out_put_disk; +if (blk_queue_is_zoned (ns->queue) &&nvme_revalidate_zones (ns)) + goto out_put_disk;if ((ctrl->quirks &NVME_QUIRK_LIGHTNVM ) && id->vs[0 ] ==0x1 ) { ret =nvme_nvm_register (ns, disk_name, node);@@ -4052,7 +4032,9 @@ static void nvme_validate_ns(struct nvme_ctrl *ctrl, unsigned nsid)return ; } - ret =nvme_revalidate_disk (ns->disk); + ret =_nvme_revalidate_disk (ns->disk); +if (!ret &&blk_queue_is_zoned (ns->queue)) + ret =nvme_revalidate_zones (ns);revalidate_disk_size (ns->disk, ret ==0 );if (ret)nvme_ns_remove (ns);drivers/nvme/host/nvme.h +1
-0@@ -758,6 +758,7 @@ static inline void nvme_mpath_start_freeze(struct nvme_subsystem *subsys) }#endif /* CONFIG_NVME_MULTIPATH */ +int nvme_revalidate_zones (struct nvme_ns *ns);#ifdef CONFIG_BLK_DEV_ZONED int nvme_update_zone_info (struct gendisk *disk,struct nvme_ns *ns,unsigned lbaf);drivers/nvme/host/zns.c +0
-0
drivers/nvme/host/zns.c line 12
Quoted 6 lines
drivers/nvme/host/zns.c +3
-0@@ -7,6 +7,17 @@#include <linux/vmalloc.h> #include "nvme.h" +int nvme_revalidate_zones (struct nvme_ns *ns) +{ +struct request_queue *q = ns->disk->queue;
struct request_queue *q = ns->queue;
may be ?
Quoted 12 lines
drivers/nvme/host/zns.c +8
-0+int ret; + + ret =blk_revalidate_disk_zones (ns->disk,NULL ); +if (!ret) +blk_queue_max_zone_append_sectors (q, ns->ctrl->max_zone_append); +return ret; +} +static int nvme_set_max_append (struct nvme_ctrl *ctrl) {struct nvme_command c = { };
Signature · 7 lines
Damien Le Moal Western Digital Research _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerRe: [PATCH 02/20] nvme: fix initialization of the zone bitmaps
Quoted 7 lines · Damien Le Moal
drivers/nvme/host/zns.c line 12
Quoted 3 lines
drivers/nvme/host/zns.c +3
-0+int nvme_revalidate_zones (struct nvme_ns *ns) +{ +struct request_queue *q = ns->disk->queue;struct
request_queue*q =ns->queue;may be ?
That would indeed be a little shorted. But both should work the same.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Keith Busch
maintainerRe: [PATCH 02/20] nvme: fix initialization of the zone bitmaps
In reply to Christoph Hellwigdrivers/nvme/host/core.c static void nvme_validate_ns(struct nvme_ctrl *ctrl, unsigned nsid) · line 4037
Quoted 8 lines · Christoph Hellwig
drivers/nvme/host/core.c +3
-1@@ -4052,7 +4032,9 @@ static void nvme_validate_ns(struct nvme_ctrl *ctrl, unsigned nsid)return ; } - ret =nvme_revalidate_disk (ns->disk); + ret =_nvme_revalidate_disk (ns->disk); +if (!ret &&blk_queue_is_zoned (ns->queue)) + ret =nvme_revalidate_zones (ns);
This is a nifty trick: 'nvme_revalidate_zones' is declared but undefined for !CONFIG_BLK_DEV_ZONED, and the compiler doesn't care because patch 1 makes it known that the symbol is unreachable.
I'll remember that for future use to avoid implementing empty stub functions.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerPATCH 3/20 nvme: remove the disk argument to nvme_update_zone_info
In reply to Christoph HellwigThe queue can trivially be derived from the nvme_ns structure.
--- drivers/nvme/host/core.c | 2 +- drivers/nvme/host/nvme.h | 8 ++------ drivers/nvme/host/zns.c | 5 ++--- 3 files changed, 5 insertions(+), 10 deletions(-)
drivers/nvme/host/core.c +1 -1
@@ -2095,7 +2095,7 @@ static int __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id)case NVME_CSI_NVM :break ;case NVME_CSI_ZNS : - ret =nvme_update_zone_info (disk, ns, lbaf); + ret =nvme_update_zone_info (ns, lbaf);if (ret) { dev_warn(ctrl->device, "failed to add zoned namespace:%u ret:%d\n",
drivers/nvme/host/nvme.h +2 -6
@@ -760,9 +760,7 @@ static inline void nvme_mpath_start_freeze(struct nvme_subsystem *subsys)int nvme_revalidate_zones (struct nvme_ns *ns);#ifdef CONFIG_BLK_DEV_ZONED -int nvme_update_zone_info (struct gendisk *disk,struct nvme_ns *ns, -unsigned lbaf); - +int nvme_update_zone_info (struct nvme_ns *ns,unsigned lbaf);int nvme_report_zones (struct gendisk *disk,sector_t sector,unsigned int nr_zones,report_zones_cb cb,void *data);
@@ -779,9 +777,7 @@ static inline blk_status_t nvme_setup_zone_mgmt_send(struct nvme_ns *ns,return BLK_STS_NOTSUPP ; } -static inline int nvme_update_zone_info (struct gendisk *disk, -struct nvme_ns *ns, -unsigned lbaf) +static inline int nvme_update_zone_info (struct nvme_ns *ns,unsigned lbaf) {dev_warn (ns->ctrl->device,"Please enable CONFIG_BLK_DEV_ZONED to support ZNS devices\n" );
drivers/nvme/host/zns.c +2 -3
@@ -46,11 +46,10 @@ static int nvme_set_max_append(struct nvme_ctrl *ctrl)return 0 ; } -int nvme_update_zone_info (struct gendisk *disk,struct nvme_ns *ns, -unsigned lbaf) +int nvme_update_zone_info (struct nvme_ns *ns,unsigned lbaf) {struct nvme_effects_log *log = ns->head->effects; -struct request_queue *q = disk->queue; +struct request_queue *q = ns->queue;struct nvme_command c = { };struct nvme_id_ns_zns *id;int status;
Signature · 7 lines
2.28.0 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 03/20] nvme: remove the disk argument to nvme_update_zone_info
Quoted 57 lines · Christoph Hellwig
The queue can trivially be derived from the
nvme_nsstructure.Signed-off-by Christoph Hellwig <[email protected]>--- drivers/nvme/host/core.c | 2 +- drivers/nvme/host/nvme.h | 8 ++------ drivers/nvme/host/zns.c | 5 ++--- 3 files changed, 5 insertions(+), 10 deletions(-)drivers/nvme/host/core.c +1
-1@@ -2095,7 +2095,7 @@ static int __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id)case NVME_CSI_NVM :break ;case NVME_CSI_ZNS : - ret =nvme_update_zone_info (disk, ns, lbaf); + ret =nvme_update_zone_info (ns, lbaf);if (ret) { dev_warn(ctrl->device, "failed to add zoned namespace:%u ret:%d\n",drivers/nvme/host/nvme.h +2
-6@@ -760,9 +760,7 @@ static inline void nvme_mpath_start_freeze(struct nvme_subsystem *subsys)int nvme_revalidate_zones (struct nvme_ns *ns);#ifdef CONFIG_BLK_DEV_ZONED -int nvme_update_zone_info (struct gendisk *disk,struct nvme_ns *ns, -unsigned lbaf); - +int nvme_update_zone_info (struct nvme_ns *ns,unsigned lbaf);int nvme_report_zones (struct gendisk *disk,sector_t sector,unsigned int nr_zones,report_zones_cb cb,void *data);@@ -779,9 +777,7 @@ static inline blk_status_t nvme_setup_zone_mgmt_send(struct nvme_ns *ns,return BLK_STS_NOTSUPP ; } -static inline int nvme_update_zone_info (struct gendisk *disk, -struct nvme_ns *ns, -unsigned lbaf) +static inline int nvme_update_zone_info (struct nvme_ns *ns,unsigned lbaf) {dev_warn (ns->ctrl->device,"Please enable CONFIG_BLK_DEV_ZONED to support ZNS devices\n" );drivers/nvme/host/zns.c +0
-0@@ -46,11 +46,10 @@ static int nvme_set_max_append(struct nvme_ctrl *ctrl)return 0 ; }
drivers/nvme/host/zns.c static int nvme_set_max_append(struct nvme_ctrl *ctrl) · line 55
Quoted 10 lines
drivers/nvme/host/zns.c +2
-3-int nvme_update_zone_info (struct gendisk *disk,struct nvme_ns *ns, -unsigned lbaf) +int nvme_update_zone_info (struct nvme_ns *ns,unsigned lbaf) {struct nvme_effects_log *log = ns->head->effects; -struct request_queue *q = disk->queue; +struct request_queue *q = ns->queue;struct nvme_command c = { };struct nvme_id_ns_zns *id;int status;
Looks good.
Signature · 7 lines
Damien Le Moal Western Digital Research _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 03/20] nvme: remove the disk argument to nvme_update_zone_info
In reply to Christoph Hellwig_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 03/20] nvme: remove the disk argument to nvme_update_zone_info
In reply to Christoph HellwigQuoted 3 lines · Christoph Hellwig
The queue can trivially be derived from the
nvme_nsstructure.Signed-off-by Christoph Hellwig <[email protected]>
Looks good.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerPATCH 4/20 nvme: rename nvme_validate_ns to nvme_validate_or_alloc_ns
In reply to Christoph HellwigUse a slightly more descriptive name to enable reusing nvme_validate_ns in the next patch for a lower level function.
--- drivers/nvme/host/core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/nvme/host/core.c +3 -3
@@ -4021,7 +4021,7 @@ static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid) } } -static void nvme_validate_ns (struct nvme_ctrl *ctrl,unsigned nsid) +static void nvme_validate_or_alloc_ns (struct nvme_ctrl *ctrl,unsigned nsid) {struct nvme_ns *ns;int ret;
@@ -4083,7 +4083,7 @@ static int nvme_scan_ns_list(struct nvme_ctrl *ctrl)if (!nsid)/* end of the list? */ goto out; -nvme_validate_ns (ctrl, nsid); +nvme_validate_or_alloc_ns (ctrl, nsid);while (++prev < nsid)nvme_ns_remove_by_nsid (ctrl, prev); }
@@ -4106,7 +4106,7 @@ static void nvme_scan_ns_sequential(struct nvme_ctrl *ctrl)kfree (id);for (i =1 ; i <= nn; i++) -nvme_validate_ns (ctrl, i); +nvme_validate_or_alloc_ns (ctrl, i);nvme_remove_invalid_namespaces (ctrl, nn); }
Signature · 7 lines
2.28.0 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 04/20] nvme: rename nvme_validate_ns to nvme_validate_or_alloc_ns
Quoted 32 lines · Christoph Hellwig
Use a slightly more descriptive name to enable reusing
nvme_validate_nsin the next patch for a lower level function.Signed-off-by Christoph Hellwig <[email protected]>--- drivers/nvme/host/core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/nvme/host/core.c +2
-2@@ -4021,7 +4021,7 @@ static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid) } } -static void nvme_validate_ns (struct nvme_ctrl *ctrl,unsigned nsid) +static void nvme_validate_or_alloc_ns (struct nvme_ctrl *ctrl,unsigned nsid) {struct nvme_ns *ns;int ret;@@ -4083,7 +4083,7 @@ static int nvme_scan_ns_list(struct nvme_ctrl *ctrl)if (!nsid)/* end of the list? */ goto out; -nvme_validate_ns (ctrl, nsid); +nvme_validate_or_alloc_ns (ctrl, nsid);while (++prev < nsid)nvme_ns_remove_by_nsid (ctrl, prev); }
drivers/nvme/host/core.c static void nvme_scan_ns_sequential(struct nvme_ctrl *ctrl) · line 4112
Quoted 8 lines
drivers/nvme/host/core.c +1
-1@@ -4106,7 +4106,7 @@ static void nvme_scan_ns_sequential(struct nvme_ctrl *ctrl)kfree (id);for (i =1 ; i <= nn; i++) -nvme_validate_ns (ctrl, i); +nvme_validate_or_alloc_ns (ctrl, i);nvme_remove_invalid_namespaces (ctrl, nn); }
Looks good.
Signature · 7 lines
Damien Le Moal Western Digital Research _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 04/20] nvme: rename nvme_validate_ns to nvme_validate_or_alloc_ns
In reply to Christoph Hellwig_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 04/20] nvme: rename nvme_validate_ns to nvme_validate_or_alloc_ns
In reply to Christoph HellwigQuoted 4 lines · Christoph Hellwig
Use a slightly more descriptive name to enable reusing
nvme_validate_nsin the next patch for a lower level function.Signed-off-by Christoph Hellwig <[email protected]>
Looks good.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerPATCH 5/20 nvme: rename _nvme_revalidate_disk
In reply to Christoph HellwigRename _nvme_revalidate_disk to nvme_validate_ns to better describe what the function does, and pass the struct nvme_ns instead of the gendisk to better match the call chain.
--- drivers/nvme/host/core.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/nvme/host/core.c +6 -7
@@ -89,7 +89,7 @@ static dev_t nvme_chr_devt;static struct class *nvme_class;static struct class *nvme_subsys_class; -static int _nvme_revalidate_disk (struct gendisk *disk); +static int nvme_validate_ns (struct nvme_ns *ns);static void nvme_put_subsystem (struct nvme_subsystem *subsys);static void nvme_remove_invalid_namespaces (struct nvme_ctrl *ctrl,unsigned nsid);
@@ -1026,7 +1026,7 @@ static void nvme_update_formats(struct nvme_ctrl *ctrl, u32 *effects)down_read (&ctrl->namespaces_rwsem);list_for_each_entry (ns, &ctrl->namespaces, list) -if (_nvme_revalidate_disk (ns->disk)) +if (nvme_validate_ns (ns))nvme_set_queue_dying (ns);else if (blk_queue_is_zoned (ns->disk->queue)) {/*
@@ -2154,16 +2154,15 @@ static int __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id)return 0 ; } -static int _nvme_revalidate_disk (struct gendisk *disk) +static int nvme_validate_ns (struct nvme_ns *ns) { -struct nvme_ns *ns = disk->private_data;struct nvme_ctrl *ctrl = ns->ctrl;struct nvme_id_ns *id;struct nvme_ns_ids ids;int ret =0 ;if (test_bit (NVME_NS_DEAD , &ns->flags)) { -set_capacity (disk,0 ); +set_capacity (ns->disk,0 );return -ENODEV ; }
@@ -2187,7 +2186,7 @@ static int _nvme_revalidate_disk(struct gendisk *disk) goto free_id; } - ret =__nvme_revalidate_disk (disk, id); + ret =__nvme_revalidate_disk (ns->disk, id); free_id:kfree (id); out:
@@ -4032,7 +4031,7 @@ static void nvme_validate_or_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)return ; } - ret =_nvme_revalidate_disk (ns->disk); + ret =nvme_validate_ns (ns);if (!ret &&blk_queue_is_zoned (ns->queue)) ret =nvme_revalidate_zones (ns);revalidate_disk_size (ns->disk, ret ==0 );
Signature · 7 lines
2.28.0 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 05/20] nvme: rename _nvme_revalidate_disk
Quoted 61 lines · Christoph Hellwig
Rename
_nvme_revalidate_disktonvme_validate_nsto better describe what the function does, and pass the structnvme_nsinstead of the gendisk to better match the call chain.Signed-off-by Christoph Hellwig <[email protected]>--- drivers/nvme/host/core.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)drivers/nvme/host/core.c +5
-6@@ -89,7 +89,7 @@ static dev_t nvme_chr_devt;static struct class *nvme_class;static struct class *nvme_subsys_class; -static int _nvme_revalidate_disk (struct gendisk *disk); +static int nvme_validate_ns (struct nvme_ns *ns);static void nvme_put_subsystem (struct nvme_subsystem *subsys);static void nvme_remove_invalid_namespaces (struct nvme_ctrl *ctrl,unsigned nsid);@@ -1026,7 +1026,7 @@ static void nvme_update_formats(struct nvme_ctrl *ctrl, u32 *effects)down_read (&ctrl->namespaces_rwsem);list_for_each_entry (ns, &ctrl->namespaces, list) -if (_nvme_revalidate_disk (ns->disk)) +if (nvme_validate_ns (ns))nvme_set_queue_dying (ns);else if (blk_queue_is_zoned (ns->disk->queue)) {/* @@ -2154,16 +2154,15 @@ static int __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id)return 0 ; } -static int _nvme_revalidate_disk (struct gendisk *disk) +static int nvme_validate_ns (struct nvme_ns *ns) { -struct nvme_ns *ns = disk->private_data;struct nvme_ctrl *ctrl = ns->ctrl;struct nvme_id_ns *id;struct nvme_ns_ids ids;int ret =0 ;if (test_bit (NVME_NS_DEAD , &ns->flags)) { -set_capacity (disk,0 ); +set_capacity (ns->disk,0 );return -ENODEV ; }@@ -2187,7 +2186,7 @@ static int _nvme_revalidate_disk(struct gendisk *disk) goto free_id; } - ret =__nvme_revalidate_disk (disk, id); + ret =__nvme_revalidate_disk (ns->disk, id); free_id:kfree (id); out:
drivers/nvme/host/core.c static void nvme_validate_or_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) · line 4037
Quoted 8 lines
drivers/nvme/host/core.c +1
-1@@ -4032,7 +4031,7 @@ static void nvme_validate_or_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)return ; } - ret =_nvme_revalidate_disk (ns->disk); + ret =nvme_validate_ns (ns);if (!ret &&blk_queue_is_zoned (ns->queue)) ret =nvme_revalidate_zones (ns);revalidate_disk_size (ns->disk, ret ==0 );
Looks good.
Signature · 7 lines
Damien Le Moal Western Digital Research _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 05/20] nvme: rename _nvme_revalidate_disk
In reply to Christoph Hellwig_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 05/20] nvme: rename _nvme_revalidate_disk
In reply to Christoph HellwigQuoted 5 lines · Christoph Hellwig
Rename
_nvme_revalidate_disktonvme_validate_nsto better describe what the function does, and pass the structnvme_nsinstead of the gendisk to better match the call chain.Signed-off-by Christoph Hellwig <[email protected]>
Looks good.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerPATCH 6/20 nvme: rename __nvme_revalidate_disk
In reply to Christoph HellwigRename __nvme_revalidate_disk to nvme_update_ns_info and pass a namespace instead of the gendisk.
--- drivers/nvme/host/core.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/nvme/host/core.c +4 -5
@@ -2076,10 +2076,9 @@ static void nvme_set_chunk_sectors(struct nvme_ns *ns, struct nvme_id_ns *id)blk_queue_chunk_sectors (ns->queue, iob); } -static int __nvme_revalidate_disk (struct gendisk *disk,struct nvme_id_ns *id) +static int nvme_update_ns_info (struct nvme_ns *ns,struct nvme_id_ns *id) {unsigned lbaf = id->flbas &NVME_NS_FLBAS_LBA_MASK ; -struct nvme_ns *ns = disk->private_data;struct nvme_ctrl *ctrl = ns->ctrl;int ret;
@@ -2141,7 +2140,7 @@ static int __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id) }nvme_set_chunk_sectors (ns, id); -nvme_update_disk_info (disk, ns, id); +nvme_update_disk_info (ns->disk, ns, id);#ifdef CONFIG_NVME_MULTIPATH if (ns->head->disk) {nvme_update_disk_info (ns->head->disk, ns, id);
@@ -2186,7 +2185,7 @@ static int nvme_validate_ns(struct nvme_ns *ns) goto free_id; } - ret =__nvme_revalidate_disk (ns->disk, id); + ret =nvme_update_ns_info (ns, id); free_id:kfree (id); out:
@@ -3933,7 +3932,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)memcpy (disk->disk_name, disk_name,DISK_NAME_LEN ); ns->disk = disk; -if (__nvme_revalidate_disk (disk, id)) +if (nvme_update_ns_info (ns, id)) goto out_put_disk;if (blk_queue_is_zoned (ns->queue) &&nvme_revalidate_zones (ns)) goto out_put_disk;
Signature · 7 lines
2.28.0 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 06/20] nvme: rename __nvme_revalidate_disk
Quoted 44 lines · Christoph Hellwig
Rename
__nvme_revalidate_disktonvme_update_ns_infoand pass a namespace instead of the gendisk.Signed-off-by Christoph Hellwig <[email protected]>--- drivers/nvme/host/core.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)drivers/nvme/host/core.c +3
-4@@ -2076,10 +2076,9 @@ static void nvme_set_chunk_sectors(struct nvme_ns *ns, struct nvme_id_ns *id)blk_queue_chunk_sectors (ns->queue, iob); } -static int __nvme_revalidate_disk (struct gendisk *disk,struct nvme_id_ns *id) +static int nvme_update_ns_info (struct nvme_ns *ns,struct nvme_id_ns *id) {unsigned lbaf = id->flbas &NVME_NS_FLBAS_LBA_MASK ; -struct nvme_ns *ns = disk->private_data;struct nvme_ctrl *ctrl = ns->ctrl;int ret;@@ -2141,7 +2140,7 @@ static int __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id) }nvme_set_chunk_sectors (ns, id); -nvme_update_disk_info (disk, ns, id); +nvme_update_disk_info (ns->disk, ns, id);#ifdef CONFIG_NVME_MULTIPATH if (ns->head->disk) {nvme_update_disk_info (ns->head->disk, ns, id);@@ -2186,7 +2185,7 @@ static int nvme_validate_ns(struct nvme_ns *ns) goto free_id; } - ret =__nvme_revalidate_disk (ns->disk, id); + ret =nvme_update_ns_info (ns, id); free_id:kfree (id); out:
drivers/nvme/host/core.c static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) · line 3938
Quoted 8 lines
drivers/nvme/host/core.c +1
-1@@ -3933,7 +3932,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)memcpy (disk->disk_name, disk_name,DISK_NAME_LEN ); ns->disk = disk; -if (__nvme_revalidate_disk (disk, id)) +if (nvme_update_ns_info (ns, id)) goto out_put_disk;if (blk_queue_is_zoned (ns->queue) &&nvme_revalidate_zones (ns)) goto out_put_disk;
Looks good.
Signature · 7 lines
Damien Le Moal Western Digital Research _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 06/20] nvme: rename __nvme_revalidate_disk
In reply to Christoph Hellwig_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 06/20] nvme: rename __nvme_revalidate_disk
In reply to Christoph HellwigQuoted 4 lines · Christoph Hellwig
Rename
__nvme_revalidate_disktonvme_update_ns_infoand pass a namespace instead of the gendisk.Signed-off-by Christoph Hellwig <[email protected]>
Looks good.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerPATCH 7/20 nvme: lift the check for an unallocated namespace into nvme_identify_ns
In reply to Christoph HellwigMove the check from the two callers into the common helper.
--- drivers/nvme/host/core.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/nvme/host/core.c +8 -9
@@ -1381,9 +1381,16 @@ static int nvme_identify_ns(struct nvme_ctrl *ctrl, error =nvme_submit_sync_cmd (ctrl->admin_q, &c, *id,sizeof (**id));if (error) {dev_warn (ctrl->device,"Identify namespace failed (%d)\n" , error); -kfree (*id); + goto out_free_id; } + error = -ENODEV ; +if ((*id)->ncap ==0 )/* namespace not allocated or attached */ + goto out_free_id; +return 0 ; + +out_free_id: +kfree (*id);return error; }
@@ -2169,11 +2176,6 @@ static int nvme_validate_ns(struct nvme_ns *ns)if (ret) goto out; -if (id->ncap ==0 ) { - ret = -ENODEV ; - goto free_id; - } - ret =nvme_report_ns_ids (ctrl, ns->head->ns_id, id, &ids);if (ret) goto free_id;
@@ -3913,9 +3915,6 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)if (ret) goto out_free_queue; -if (id->ncap ==0 )/* no namespace (legacy quirk) */ - goto out_free_id; - ret =nvme_init_ns_head (ns, nsid, id);if (ret) goto out_free_id;
Signature · 7 lines
2.28.0 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 07/20] nvme: lift the check for an unallocated namespace into nvme_identify_ns
Quoted 12 lines · Christoph Hellwig
Move the check from the two callers into the common helper.
Signed-off-by Christoph Hellwig <[email protected]>--- drivers/nvme/host/core.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)drivers/nvme/host/core.c +0
-0
drivers/nvme/host/core.c static int nvme_identify_ns(struct nvme_ctrl *ctrl, · line 1387
Quoted 8 lines
drivers/nvme/host/core.c +2
-1@@ -1381,9 +1381,16 @@ static int nvme_identify_ns(struct nvme_ctrl *ctrl, error =nvme_submit_sync_cmd (ctrl->admin_q, &c, *id,sizeof (**id));if (error) {dev_warn (ctrl->device,"Identify namespace failed (%d)\n" , error); -kfree (*id); + goto out_free_id; } + error = -ENODEV ;
You could move this inside the if.
Quoted 22 lines
drivers/nvme/host/core.c +6
-5+if ((*id)->ncap ==0 )/* namespace not allocated or attached */ + goto out_free_id; +return 0 ; + +out_free_id: +kfree (*id);return error; }@@ -2169,11 +2176,6 @@ static int nvme_validate_ns(struct nvme_ns *ns)if (ret) goto out; -if (id->ncap ==0 ) { - ret = -ENODEV ; - goto free_id; - } - ret =nvme_report_ns_ids (ctrl, ns->head->ns_id, id, &ids);if (ret) goto free_id;
drivers/nvme/host/core.c static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) · line 3917
Quoted 5 lines
drivers/nvme/host/core.c +0
-2@@ -3913,9 +3915,6 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)if (ret) goto out_free_queue; -if (id->ncap ==0 )/* no namespace (legacy quirk) */ - goto out_free_id;
There is a call to nvme_identify_ns() above this, and I guess it is OK to assume that that function will never return success if the ns cap is 0, right ? If so, then this change looks OK.
Quoted 5 lines
drivers/nvme/host/core.c +0
-1- ret =nvme_init_ns_head (ns, nsid, id);if (ret) goto out_free_id;
Signature · 7 lines
Damien Le Moal Western Digital Research _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerRe: [PATCH 07/20] nvme: lift the check for an unallocated namespace into nvme_identify_ns
Quoted 12 lines · Damien Le Moal
Quoted 12 lines
drivers/nvme/host/core.c +1
-1@@ -1381,9 +1381,16 @@ static int nvme_identify_ns(struct nvme_ctrl *ctrl, error =nvme_submit_sync_cmd (ctrl->admin_q, &c, *id,sizeof (**id));if (error) {dev_warn (ctrl->device,"Identify namespace failed (%d)\n" , error); -kfree (*id); + goto out_free_id; }
Quoted 3 lines
drivers/nvme/host/core.c static int nvme_identify_ns(struct nvme_ctrl *ctrl, · line 1387
Quoted 1 line
drivers/nvme/host/core.c +1
-0+ error = -ENODEV ;You could move this inside the if.
I could. This is a pretty common style in Linux code, though.
Quoted 10 lines
drivers/nvme/host/core.c static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) · line 3917
Quoted 6 lines
drivers/nvme/host/core.c +0
-2@@ -3913,9 +3915,6 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)if (ret) goto out_free_queue; -if (id->ncap ==0 )/* no namespace (legacy quirk) */ - goto out_free_id;There is a call to
nvme_identify_ns()above this, and I guess it is OK to assume that that function will never return success if the ns cap is 0, right ? If so, then this change looks OK.
Well, ensuring that nvme_identify_ns returns an error if NCAP is 0 is all that this patch does in addition to removing the checks in the callers.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 07/20] nvme: lift the check for an unallocated namespace into nvme_identify_ns
In reply to Christoph Hellwig_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 07/20] nvme: lift the check for an unallocated namespace into nvme_identify_ns
In reply to Christoph HellwigQuoted 3 lines · Christoph Hellwig
Move the check from the two callers into the common helper.
Signed-off-by Christoph Hellwig <[email protected]>
Looks good.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerPATCH 8/20 nvme: call nvme_identify_ns as the first thing in nvme_alloc_ns_block
In reply to Christoph HellwigCheck if the namespace actually exists as the very first thing and don't bother with any extra work if not. This should speed up and simplify the sequential scanning for NVMe 1.0 devices.
--- drivers/nvme/host/core.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/nvme/host/core.c +7 -8
@@ -3887,9 +3887,12 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)char disk_name[DISK_NAME_LEN ];int node = ctrl->numa_node, flags =GENHD_FL_EXT_DEVT , ret; +if (nvme_identify_ns (ctrl, nsid, &id)) +return ; + ns =kzalloc_node (sizeof (*ns),GFP_KERNEL , node);if (!ns) -return ; + goto out_free_id; ns->queue =blk_mq_init_queue (ctrl->tagset);if (IS_ERR (ns->queue))
@@ -3911,13 +3914,9 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)blk_queue_logical_block_size (ns->queue,1 << ns->lba_shift);nvme_set_queue_limits (ctrl, ns->queue); - ret =nvme_identify_ns (ctrl, nsid, &id); -if (ret) - goto out_free_queue; - ret =nvme_init_ns_head (ns, nsid, id);if (ret) - goto out_free_id; + goto out_free_queue;nvme_set_disk_name (disk_name, ns, ctrl, &flags); disk =alloc_disk_node (0 , node);
@@ -3968,12 +3967,12 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)list_del_init (&ns->head->entry);mutex_unlock (&ctrl->subsys->lock);nvme_put_ns_head (ns->head); - out_free_id: -kfree (id); out_free_queue:blk_cleanup_queue (ns->queue); out_free_ns:kfree (ns); + out_free_id: +kfree (id); }static void nvme_ns_remove (struct nvme_ns *ns)
Signature · 7 lines
2.28.0 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 08/20] nvme: call nvme_identify_ns as the first thing in nvme_alloc_ns_block
Quoted 48 lines · Christoph Hellwig
Check if the namespace actually exists as the very first thing and don't bother with any extra work if not. This should speed up and simplify the sequential scanning for NVMe 1.0 devices.
Signed-off-by Christoph Hellwig <[email protected]>--- drivers/nvme/host/core.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)drivers/nvme/host/core.c +5
-7@@ -3887,9 +3887,12 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)char disk_name[DISK_NAME_LEN ];int node = ctrl->numa_node, flags =GENHD_FL_EXT_DEVT , ret; +if (nvme_identify_ns (ctrl, nsid, &id)) +return ; + ns =kzalloc_node (sizeof (*ns),GFP_KERNEL , node);if (!ns) -return ; + goto out_free_id; ns->queue =blk_mq_init_queue (ctrl->tagset);if (IS_ERR (ns->queue))@@ -3911,13 +3914,9 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)blk_queue_logical_block_size (ns->queue,1 << ns->lba_shift);nvme_set_queue_limits (ctrl, ns->queue); - ret =nvme_identify_ns (ctrl, nsid, &id); -if (ret) - goto out_free_queue; - ret =nvme_init_ns_head (ns, nsid, id);if (ret) - goto out_free_id; + goto out_free_queue;nvme_set_disk_name (disk_name, ns, ctrl, &flags); disk =alloc_disk_node (0 , node);@@ -3968,12 +3967,12 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)list_del_init (&ns->head->entry);mutex_unlock (&ctrl->subsys->lock);nvme_put_ns_head (ns->head); - out_free_id:
drivers/nvme/host/core.c static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) · line 3978
Quoted 10 lines
drivers/nvme/host/core.c +2
-1-kfree (id); out_free_queue:blk_cleanup_queue (ns->queue); out_free_ns:kfree (ns); + out_free_id: +kfree (id); }static void nvme_ns_remove (struct nvme_ns *ns)
Looks good.
Signature · 7 lines
Damien Le Moal Western Digital Research _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Sagi Grimberg
maintainerRe: [PATCH 08/20] nvme: call nvme_identify_ns as the first thing in nvme_alloc_ns_block
In reply to Christoph HellwigQuoted 4 lines
Check if the namespace actually exists as the very first thing and don't bother with any extra work if not. This should speed up and simplify the sequential scanning for NVMe 1.0 devices.
What exactly is this speeding up? Its just a few assignments+allocations
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerRe: [PATCH 08/20] nvme: call nvme_identify_ns as the first thing in nvme_alloc_ns_block
Quoted 6 lines · Sagi Grimberg
Quoted 4 lines
Check if the namespace actually exists as the very first thing and don't bother with any extra work if not. This should speed up and simplify the sequential scanning for NVMe 1.0 devices.
What exactly is this speeding up? Its just a few assignments+allocations
Yes, that is all. Although some of the block layer teardown can be a little more costly with various atomics. Nothing really major, but just simple work avoidance for a non-failure early exit path.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 08/20] nvme: call nvme_identify_ns as the first thing in nvme_alloc_ns_block
In reply to Christoph HellwigQuoted 5 lines · Christoph Hellwig
Check if the namespace actually exists as the very first thing and don't bother with any extra work if not. This should speed up and simplify the sequential scanning for NVMe 1.0 devices.
Signed-off-by Christoph Hellwig <[email protected]>
Looks good.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerPATCH 9/20 nvme: factor out a nvme_configure_metadata helper
In reply to Christoph HellwigFactor out a helper from nvme_update_ns_info that configures the per-namespaces metadata and PI settings. Also make sure the helpers clear the flags explicitly instead of all of ->features to allow for potentially reusing ->features for future non-metadata flags.
--- drivers/nvme/host/core.c | 78 ++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 31 deletions(-)
drivers/nvme/host/core.c +47 -31
@@ -1966,6 +1966,50 @@ static int nvme_setup_streams_ns(struct nvme_ctrl *ctrl, struct nvme_ns *ns,return 0 ; } +static int nvme_configure_metadata (struct nvme_ns *ns,struct nvme_id_ns *id) +{ +struct nvme_ctrl *ctrl = ns->ctrl; + +/* +* The PI implementation requires the metadata size to be equal to the +* t10 pi tuple size. +*/ + ns->ms =le16_to_cpu (id->lbaf[id->flbas &NVME_NS_FLBAS_LBA_MASK ].ms); +if (ns->ms ==sizeof (struct t10_pi_tuple )) + ns->pi_type = id->dps &NVME_NS_DPS_PI_MASK ; +else + ns->pi_type =0 ; + + ns->features &= ~(NVME_NS_METADATA_SUPPORTED |NVME_NS_EXT_LBAS ); +if (!ns->ms || !(ctrl->ops->flags &NVME_F_METADATA_SUPPORTED )) +return 0 ; +if (ctrl->ops->flags &NVME_F_FABRICS ) { +/* +* The NVMe over Fabrics specification only supports metadata as +* part of the extended data LBA. We rely on HCA/HBA support to +* remap the separate metadata buffer from the block layer. +*/ +if (WARN_ON_ONCE (!(id->flbas &NVME_NS_FLBAS_META_EXT ))) +return -EINVAL ; +if (ctrl->max_integrity_segments) + ns->features |= + (NVME_NS_METADATA_SUPPORTED |NVME_NS_EXT_LBAS ); + }else { +/* +* For PCIe controllers, we can't easily remap the separate +* metadata buffer from the block layer and thus require a +* separate metadata buffer for block layer metadata/PI support. +* We allow extended LBAs for the passthrough interface, though. +*/ +if (id->flbas &NVME_NS_FLBAS_META_EXT ) + ns->features |=NVME_NS_EXT_LBAS ; +else + ns->features |=NVME_NS_METADATA_SUPPORTED ; + } + +return 0 ; +} +static void nvme_update_disk_info (struct gendisk *disk,struct nvme_ns *ns,struct nvme_id_ns *id) {
@@ -2115,37 +2159,9 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id)return -ENODEV ; } - ns->features =0 ; - ns->ms =le16_to_cpu (id->lbaf[lbaf].ms); -/* the PI implementation requires metadata equal t10 pi tuple size */ -if (ns->ms ==sizeof (struct t10_pi_tuple )) - ns->pi_type = id->dps &NVME_NS_DPS_PI_MASK ; -else - ns->pi_type =0 ; - -if (ns->ms) { -/* -* For PCIe only the separate metadata pointer is supported, -* as the block layer supplies metadata in a separate bio_vec -* chain. For Fabrics, only metadata as part of extended data -* LBA is supported on the wire per the Fabrics specification, -* but the HBA/HCA will do the remapping from the separate -* metadata buffers for us. -*/ -if (id->flbas &NVME_NS_FLBAS_META_EXT ) { - ns->features |=NVME_NS_EXT_LBAS ; -if ((ctrl->ops->flags &NVME_F_FABRICS ) && - (ctrl->ops->flags &NVME_F_METADATA_SUPPORTED ) && - ctrl->max_integrity_segments) - ns->features |=NVME_NS_METADATA_SUPPORTED ; - }else { -if (WARN_ON_ONCE (ctrl->ops->flags &NVME_F_FABRICS )) -return -EINVAL ; -if (ctrl->ops->flags &NVME_F_METADATA_SUPPORTED ) - ns->features |=NVME_NS_METADATA_SUPPORTED ; - } - } - + ret =nvme_configure_metadata (ns, id); +if (ret) +return ret;nvme_set_chunk_sectors (ns, id);nvme_update_disk_info (ns->disk, ns, id);#ifdef CONFIG_NVME_MULTIPATH
Signature · 7 lines
2.28.0 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 09/20] nvme: factor out a nvme_configure_metadata helper
Quoted 97 lines · Christoph Hellwig
Factor out a helper from
nvme_update_ns_infothat configures the per-namespaces metadata and PI settings. Also make sure the helpers clear the flags explicitly instead of all of ->features to allow for potentially reusing ->features for future non-metadata flags.Signed-off-by Christoph Hellwig <[email protected]>--- drivers/nvme/host/core.c | 78 ++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 31 deletions(-)drivers/nvme/host/core.c +44
-27@@ -1966,6 +1966,50 @@ static int nvme_setup_streams_ns(struct nvme_ctrl *ctrl, struct nvme_ns *ns,return 0 ; } +static int nvme_configure_metadata (struct nvme_ns *ns,struct nvme_id_ns *id) +{ +struct nvme_ctrl *ctrl = ns->ctrl; + +/* +* The PI implementation requires the metadata size to be equal to the +* t10 pi tuple size. +*/ + ns->ms =le16_to_cpu (id->lbaf[id->flbas &NVME_NS_FLBAS_LBA_MASK ].ms); +if (ns->ms ==sizeof (struct t10_pi_tuple )) + ns->pi_type = id->dps &NVME_NS_DPS_PI_MASK ; +else + ns->pi_type =0 ; + + ns->features &= ~(NVME_NS_METADATA_SUPPORTED |NVME_NS_EXT_LBAS ); +if (!ns->ms || !(ctrl->ops->flags &NVME_F_METADATA_SUPPORTED )) +return 0 ; +if (ctrl->ops->flags &NVME_F_FABRICS ) { +/* +* The NVMe over Fabrics specification only supports metadata as +* part of the extended data LBA. We rely on HCA/HBA support to +* remap the separate metadata buffer from the block layer. +*/ +if (WARN_ON_ONCE (!(id->flbas &NVME_NS_FLBAS_META_EXT ))) +return -EINVAL ; +if (ctrl->max_integrity_segments) + ns->features |= + (NVME_NS_METADATA_SUPPORTED |NVME_NS_EXT_LBAS ); + }else { +/* +* For PCIe controllers, we can't easily remap the separate +* metadata buffer from the block layer and thus require a +* separate metadata buffer for block layer metadata/PI support. +* We allow extended LBAs for the passthrough interface, though. +*/ +if (id->flbas &NVME_NS_FLBAS_META_EXT ) + ns->features |=NVME_NS_EXT_LBAS ; +else + ns->features |=NVME_NS_METADATA_SUPPORTED ; + } + +return 0 ; +} +static void nvme_update_disk_info (struct gendisk *disk,struct nvme_ns *ns,struct nvme_id_ns *id) {@@ -2115,37 +2159,9 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id)return -ENODEV ; } - ns->features =0 ; - ns->ms =le16_to_cpu (id->lbaf[lbaf].ms); -/* the PI implementation requires metadata equal t10 pi tuple size */ -if (ns->ms ==sizeof (struct t10_pi_tuple )) - ns->pi_type = id->dps &NVME_NS_DPS_PI_MASK ; -else - ns->pi_type =0 ; - -if (ns->ms) { -/* -* For PCIe only the separate metadata pointer is supported, -* as the block layer supplies metadata in a separate bio_vec -* chain. For Fabrics, only metadata as part of extended data -* LBA is supported on the wire per the Fabrics specification, -* but the HBA/HCA will do the remapping from the separate -* metadata buffers for us. -*/ -if (id->flbas &NVME_NS_FLBAS_META_EXT ) { - ns->features |=NVME_NS_EXT_LBAS ; -if ((ctrl->ops->flags &NVME_F_FABRICS ) && - (ctrl->ops->flags &NVME_F_METADATA_SUPPORTED ) && - ctrl->max_integrity_segments) - ns->features |=NVME_NS_METADATA_SUPPORTED ; - }else { -if (WARN_ON_ONCE (ctrl->ops->flags &NVME_F_FABRICS )) -return -EINVAL ; -if (ctrl->ops->flags &NVME_F_METADATA_SUPPORTED )
drivers/nvme/host/core.c static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id) · line 2167
Quoted 10 lines
drivers/nvme/host/core.c +3
-4- ns->features |=NVME_NS_METADATA_SUPPORTED ; - } - } - + ret =nvme_configure_metadata (ns, id); +if (ret) +return ret;nvme_set_chunk_sectors (ns, id);nvme_update_disk_info (ns->disk, ns, id);#ifdef CONFIG_NVME_MULTIPATH
Looks OK to me.
Signature · 7 lines
Damien Le Moal Western Digital Research _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 09/20] nvme: factor out a nvme_configure_metadata helper
In reply to Christoph Hellwig_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 09/20] nvme: factor out a nvme_configure_metadata helper
In reply to Christoph HellwigQuoted 6 lines · Christoph Hellwig
Factor out a helper from
nvme_update_ns_infothat configures the per-namespaces metadata and PI settings. Also make sure the helpers clear the flags explicitly instead of all of ->features to allow for potentially reusing ->features for future non-metadata flags.Signed-off-by Christoph Hellwig <[email protected]>
Looks good.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerPATCH 10/20 nvme: freeze the queue over ->lba_shift updates
In reply to Christoph HellwigEnsure that there can't be any I/O in flight went we change the disk geometry in nvme_update_ns_info, most notable the LBA size by lifting the queue free from nvme_update_disk_info into the caller
--- drivers/nvme/host/core.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
drivers/nvme/host/core.c +14 -6
@@ -2021,7 +2021,7 @@ static void nvme_update_disk_info(struct gendisk *disk,/* unsupported block size, set capacity to 0 later */ bs = (1 <<9 ); } -blk_mq_freeze_queue (disk->queue); +blk_integrity_unregister (disk); atomic_bs = phys_bs = bs;
@@ -2086,8 +2086,6 @@ static void nvme_update_disk_info(struct gendisk *disk,set_disk_ro (disk, true); elseset_disk_ro (disk ,false ); - -blk_mq_unfreeze_queue (disk->queue); }static inline bool nvme_first_scan (struct gendisk *disk)
@@ -2133,6 +2131,7 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id)struct nvme_ctrl *ctrl = ns->ctrl;int ret; +blk_mq_freeze_queue (ns->disk->queue);/* * If identify namespace failed, use default 512 byte block size so * block layer can use before failing read/write for 0 capacity.
@@ -2150,30 +2149,39 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id)dev_warn (ctrl->device,"failed to add zoned namespace:%u ret:%d\n" , ns->head->ns_id, ret); -return ret; + goto out_unfreeze; }break ;default :dev_warn (ctrl->device,"unknown csi:%u ns:%u\n" , ns->head->ids.csi, ns->head->ns_id); -return -ENODEV ; + ret = -ENODEV ; + goto out_unfreeze; } ret =nvme_configure_metadata (ns, id);if (ret) -return ret; + goto out_unfreeze;nvme_set_chunk_sectors (ns, id);nvme_update_disk_info (ns->disk, ns, id); +blk_mq_unfreeze_queue (ns->disk->queue); +#ifdef CONFIG_NVME_MULTIPATH if (ns->head->disk) { +blk_mq_freeze_queue (ns->head->disk->queue);nvme_update_disk_info (ns->head->disk, ns, id);blk_stack_limits (&ns->head->disk->queue->limits, &ns->queue->limits,0 );blk_queue_update_readahead (ns->head->disk->queue);nvme_update_bdev_size (ns->head->disk); +blk_mq_unfreeze_queue (ns->head->disk->queue); }#endif return 0 ; + +out_unfreeze: +blk_mq_unfreeze_queue (ns->disk->queue); +return ret; }static int nvme_validate_ns (struct nvme_ns *ns)
Signature · 7 lines
2.28.0 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 10/20] nvme: freeze the queue over ->lba_shift updates
Quoted 73 lines · Christoph Hellwig
Ensure that there can't be any I/O in flight went we change the disk geometry in
nvme_update_ns_info, most notable the LBA size by lifting the queue free fromnvme_update_disk_infointo the callerSigned-off-by Christoph Hellwig <[email protected]>--- drivers/nvme/host/core.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)drivers/nvme/host/core.c +10
-6@@ -2021,7 +2021,7 @@ static void nvme_update_disk_info(struct gendisk *disk,/* unsupported block size, set capacity to 0 later */ bs = (1 <<9 ); } -blk_mq_freeze_queue (disk->queue); +blk_integrity_unregister (disk); atomic_bs = phys_bs = bs;@@ -2086,8 +2086,6 @@ static void nvme_update_disk_info(struct gendisk *disk,set_disk_ro (disk, true); elseset_disk_ro (disk ,false ); - -blk_mq_unfreeze_queue (disk->queue); }static inline bool nvme_first_scan (struct gendisk *disk)@@ -2133,6 +2131,7 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id)struct nvme_ctrl *ctrl = ns->ctrl;int ret; +blk_mq_freeze_queue (ns->disk->queue);/* * If identify namespace failed, use default 512 byte block size so * block layer can use before failing read/write for 0 capacity. @@ -2150,30 +2149,39 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id)dev_warn (ctrl->device,"failed to add zoned namespace:%u ret:%d\n" , ns->head->ns_id, ret); -return ret; + goto out_unfreeze; }break ;default :dev_warn (ctrl->device,"unknown csi:%u ns:%u\n" , ns->head->ids.csi, ns->head->ns_id); -return -ENODEV ; + ret = -ENODEV ; + goto out_unfreeze; } ret =nvme_configure_metadata (ns, id);if (ret) -return ret; + goto out_unfreeze;nvme_set_chunk_sectors (ns, id);nvme_update_disk_info (ns->disk, ns, id); +blk_mq_unfreeze_queue (ns->disk->queue); +#ifdef CONFIG_NVME_MULTIPATH if (ns->head->disk) { +blk_mq_freeze_queue (ns->head->disk->queue);nvme_update_disk_info (ns->head->disk, ns, id);blk_stack_limits (&ns->head->disk->queue->limits, &ns->queue->limits,0 );blk_queue_update_readahead (ns->head->disk->queue);nvme_update_bdev_size (ns->head->disk); +blk_mq_unfreeze_queue (ns->head->disk->queue);
drivers/nvme/host/core.c static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id) · line 2187
Quoted 10 lines
drivers/nvme/host/core.c +4
-0}#endif return 0 ; + +out_unfreeze: +blk_mq_unfreeze_queue (ns->disk->queue); +return ret; }static int nvme_validate_ns (struct nvme_ns *ns)
Looks good.
Signature · 7 lines
Damien Le Moal Western Digital Research _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Sagi Grimberg
maintainerRe: [PATCH 10/20] nvme: freeze the queue over ->lba_shift updates
In reply to Christoph HellwigQuoted 4 lines
Ensure that there can't be any I/O in flight went we change the disk geometry in
nvme_update_ns_info, most notable the LBA size by lifting the queue free fromnvme_update_disk_infointo the caller
The queue is frozen on the queue logical block size, why should we care about I/O while ns->lba_shift?
Quoted 70 lines
Signed-off-by Christoph Hellwig <[email protected]>--- drivers/nvme/host/core.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)drivers/nvme/host/core.c +10
-6@@ -2021,7 +2021,7 @@ static void nvme_update_disk_info(struct gendisk *disk,/* unsupported block size, set capacity to 0 later */ bs = (1 <<9 ); } -blk_mq_freeze_queue (disk->queue); +blk_integrity_unregister (disk); atomic_bs = phys_bs = bs;@@ -2086,8 +2086,6 @@ static void nvme_update_disk_info(struct gendisk *disk,set_disk_ro (disk, true); elseset_disk_ro (disk ,false ); - -blk_mq_unfreeze_queue (disk->queue); }static inline bool nvme_first_scan (struct gendisk *disk)@@ -2133,6 +2131,7 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id)struct nvme_ctrl *ctrl = ns->ctrl;int ret; +blk_mq_freeze_queue (ns->disk->queue);/* * If identify namespace failed, use default 512 byte block size so * block layer can use before failing read/write for 0 capacity. @@ -2150,30 +2149,39 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id)dev_warn (ctrl->device,"failed to add zoned namespace:%u ret:%d\n" , ns->head->ns_id, ret); -return ret; + goto out_unfreeze; }break ;default :dev_warn (ctrl->device,"unknown csi:%u ns:%u\n" , ns->head->ids.csi, ns->head->ns_id); -return -ENODEV ; + ret = -ENODEV ; + goto out_unfreeze; } ret =nvme_configure_metadata (ns, id);if (ret) -return ret; + goto out_unfreeze;nvme_set_chunk_sectors (ns, id);nvme_update_disk_info (ns->disk, ns, id); +blk_mq_unfreeze_queue (ns->disk->queue); +#ifdef CONFIG_NVME_MULTIPATH if (ns->head->disk) { +blk_mq_freeze_queue (ns->head->disk->queue);nvme_update_disk_info (ns->head->disk, ns, id);blk_stack_limits (&ns->head->disk->queue->limits, &ns->queue->limits,0 );blk_queue_update_readahead (ns->head->disk->queue);nvme_update_bdev_size (ns->head->disk); +blk_mq_unfreeze_queue (ns->head->disk->queue);
drivers/nvme/host/core.c static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id) · line 2187
Quoted 10 lines
drivers/nvme/host/core.c +4
-0}#endif return 0 ; + +out_unfreeze: +blk_mq_unfreeze_queue (ns->disk->queue); +return ret; }static int nvme_validate_ns (struct nvme_ns *ns)
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerRe: [PATCH 10/20] nvme: freeze the queue over ->lba_shift updates
Quoted 7 lines · Sagi Grimberg
Quoted 4 lines
Ensure that there can't be any I/O in flight went we change the disk geometry in
nvme_update_ns_info, most notable the LBA size by lifting the queue free fromnvme_update_disk_infointo the callerThe queue is frozen on the queue logical block size, why should we care about I/O while
ns->lba_shift?
Because we use it for all kinds of calculations in the I/O path. By moving all assignments into the frozen queue critical sections we avoid all possibly inconsistencies.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Sagi Grimberg
maintainerRe: [PATCH 10/20] nvme: freeze the queue over ->lba_shift updates
Quoted 11 lines
Quoted 7 lines
Quoted 4 lines
Ensure that there can't be any I/O in flight went we change the disk geometry in
nvme_update_ns_info, most notable the LBA size by lifting the queue free fromnvme_update_disk_infointo the callerThe queue is frozen on the queue logical block size, why should we care about I/O while
ns->lba_shift?Because we use it for all kinds of calculations in the I/O path. By moving all assignments into the frozen queue critical sections we avoid all possibly inconsistencies.
I'd think that it would be better to never use ns->lba_shift but rather the request queue block size and keep the queue freeze span only that mutation.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Sagi Grimberg
maintainerRe: [PATCH 10/20] nvme: freeze the queue over ->lba_shift updates
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
Ensure that there can't be any I/O in flight went we change the disk geometry in
nvme_update_ns_info, most notable the LBA size by lifting the queue free fromnvme_update_disk_infointo the callerThe queue is frozen on the queue logical block size, why should we care about I/O while
ns->lba_shift?
Quoted 7 lines
Quoted 3 lines
Because we use it for all kinds of calculations in the I/O path. By moving all assignments into the frozen queue critical sections we avoid all possibly inconsistencies.
I'd think that it would be better to never use
ns->lba_shiftbut rather the request queue block size and keep the queue freeze span only that mutation.
?
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerRe: [PATCH 10/20] nvme: freeze the queue over ->lba_shift updates
Quoted 12 lines · Sagi Grimberg
Quoted 12 lines
Quoted 11 lines
Quoted 7 lines
Quoted 4 lines
Ensure that there can't be any I/O in flight went we change the disk geometry in
nvme_update_ns_info, most notable the LBA size by lifting the queue free fromnvme_update_disk_infointo the callerThe queue is frozen on the queue logical block size, why should we care about I/O while
ns->lba_shift?Because we use it for all kinds of calculations in the I/O path. By moving all assignments into the frozen queue critical sections we avoid all possibly inconsistencies.
Quoted 5 lines
Quoted 3 lines
I'd think that it would be better to never use
ns->lba_shiftbut rather the request queue block size and keep the queue freeze span only that mutation.?
So that we'll need to multiply instead of shift in the I/O path? Maybe we could add a shift in the queue, but that's a much bigger change..
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerPATCH 11/20 nvme: clean up the check for too large logic block sizes
In reply to Christoph HellwigUse a single statement to set both the capacity and fake block size instead of two.
--- drivers/nvme/host/core.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/nvme/host/core.c +5 -8
@@ -2017,8 +2017,12 @@ static void nvme_update_disk_info(struct gendisk *disk,unsigned short bs =1 << ns->lba_shift;u32 atomic_bs, phys_bs, io_opt =0 ; +/* +* The block layer can't support LBA sizes larger than the page size +* yet, so catch this early and don't allow block I/O. +*/ if (ns->lba_shift >PAGE_SHIFT ) { -/* unsupported block size, set capacity to 0 later */ + capacity =0 ; bs = (1 <<9 ); }
@@ -2055,13 +2059,6 @@ static void nvme_update_disk_info(struct gendisk *disk,blk_queue_io_min (disk->queue, phys_bs);blk_queue_io_opt (disk->queue, io_opt); -/* -* The block layer can't support LBA sizes larger than the page size -* yet, so catch this early and don't allow block I/O. -*/ -if (ns->lba_shift >PAGE_SHIFT ) - capacity =0 ; -/* * Register a metadata profile for PI, or the plain non-integrity NVMe * metadata masquerading as Type 0 if supported, otherwise reject block
Signature · 7 lines
2.28.0 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 11/20] nvme: clean up the check for too large logic block sizes
Quoted 14 lines · Christoph Hellwig
Use a single statement to set both the capacity and fake block size instead of two.
Signed-off-by Christoph Hellwig <[email protected]>--- drivers/nvme/host/core.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)drivers/nvme/host/core.c +0
-0@@ -2017,8 +2017,12 @@ static void nvme_update_disk_info(struct gendisk *disk,unsigned short bs =1 << ns->lba_shift;
drivers/nvme/host/core.c static void nvme_update_disk_info(struct gendisk *disk, · line 2026
Quoted 10 lines
drivers/nvme/host/core.c +5
-1u32 atomic_bs, phys_bs, io_opt =0 ; +/* +* The block layer can't support LBA sizes larger than the page size +* yet, so catch this early and don't allow block I/O. +*/ if (ns->lba_shift >PAGE_SHIFT ) { -/* unsupported block size, set capacity to 0 later */ + capacity =0 ; bs = (1 <<9 );
bs = (1 << SECTOR_SHIFT);
is cleaner I think.
Quoted 17 lines
drivers/nvme/host/core.c +0
-7}@@ -2055,13 +2059,6 @@ static void nvme_update_disk_info(struct gendisk *disk,blk_queue_io_min (disk->queue, phys_bs);blk_queue_io_opt (disk->queue, io_opt); -/* -* The block layer can't support LBA sizes larger than the page size -* yet, so catch this early and don't allow block I/O. -*/ -if (ns->lba_shift >PAGE_SHIFT ) - capacity =0 ; -/* * Register a metadata profile for PI, or the plain non-integrity NVMe * metadata masquerading as Type 0 if supported, otherwise reject block
Signature · 7 lines
Damien Le Moal Western Digital Research _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerRe: [PATCH 11/20] nvme: clean up the check for too large logic block sizes
Quoted 8 lines · Damien Le Moal
drivers/nvme/host/core.c static void nvme_update_disk_info(struct gendisk *disk, · line 2026
Quoted 4 lines
drivers/nvme/host/core.c +1
-1if (ns->lba_shift >PAGE_SHIFT ) { -/* unsupported block size, set capacity to 0 later */ + capacity =0 ; bs = (1 <<9 );bs = (1 << SECTOR_SHIFT);is cleaner I think.
Maybe, but then again it is existing code I didn't even touch. And we have plenty of << 9 or >> 9, so we'd better address them all together if we want to bother.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Sagi Grimberg
maintainerRe: [PATCH 11/20] nvme: clean up the check for too large logic block sizes
In reply to Christoph HellwigQuoted 3 lines
Use a single statement to set both the capacity and fake block size instead of two.
I have some vague recollection why these needed to be split, but can't remember why...
Quoted 29 lines
Signed-off-by Christoph Hellwig <[email protected]>--- drivers/nvme/host/core.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)drivers/nvme/host/core.c +5
-1@@ -2017,8 +2017,12 @@ static void nvme_update_disk_info(struct gendisk *disk,unsigned short bs =1 << ns->lba_shift;u32 atomic_bs, phys_bs, io_opt =0 ; +/* +* The block layer can't support LBA sizes larger than the page size +* yet, so catch this early and don't allow block I/O. +*/ if (ns->lba_shift >PAGE_SHIFT ) { -/* unsupported block size, set capacity to 0 later */ + capacity =0 ; bs = (1 <<9 ); }@@ -2055,13 +2059,6 @@ static void nvme_update_disk_info(struct gendisk *disk,blk_queue_io_min (disk->queue, phys_bs);blk_queue_io_opt (disk->queue, io_opt);
drivers/nvme/host/core.c static void nvme_update_disk_info(struct gendisk *disk, · line 2064
Quoted 10 lines
drivers/nvme/host/core.c +0
-7-/* -* The block layer can't support LBA sizes larger than the page size -* yet, so catch this early and don't allow block I/O. -*/ -if (ns->lba_shift >PAGE_SHIFT ) - capacity =0 ; -/* * Register a metadata profile for PI, or the plain non-integrity NVMe * metadata masquerading as Type 0 if supported, otherwise reject block
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerRe: [PATCH 11/20] nvme: clean up the check for too large logic block sizes
Quoted 5 lines · Sagi Grimberg
Quoted 2 lines
Use a single statement to set both the capacity and fake block size instead of two.
I have some vague recollection why these needed to be split, but can't remember why...
Well, capacity isn't used between the old and the new assignment, so I can't see how this makes a difference. Might have been different in the past, though.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerPATCH 12/20 nvme: remove the 0 lba_shift check in nvme_update_ns_info
In reply to Christoph HellwigWe can't reach this code if Identify Namespace failed.
--- drivers/nvme/host/core.c | 6 ------ 1 file changed, 6 deletions(-)
drivers/nvme/host/core.c +0 -6
@@ -2129,13 +2129,7 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id)int ret;blk_mq_freeze_queue (ns->disk->queue); -/* -* If identify namespace failed, use default 512 byte block size so -* block layer can use before failing read/write for 0 capacity. -*/ ns->lba_shift = id->lbaf[lbaf].ds; -if (ns->lba_shift ==0 ) - ns->lba_shift =9 ;switch (ns->head->ids.csi) {case NVME_CSI_NVM :
Signature · 7 lines
2.28.0 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 12/20] nvme: remove the 0 lba_shift check in nvme_update_ns_info
Quoted 16 lines · Christoph Hellwig
We can't reach this code if Identify Namespace failed.
Signed-off-by Christoph Hellwig <[email protected]>--- drivers/nvme/host/core.c | 6 ------ 1 file changed, 6 deletions(-)drivers/nvme/host/core.c +0
-0@@ -2129,13 +2129,7 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id)int ret;blk_mq_freeze_queue (ns->disk->queue);
drivers/nvme/host/core.c static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id) · line 2135
Quoted 10 lines
drivers/nvme/host/core.c +0
-6-/* -* If identify namespace failed, use default 512 byte block size so -* block layer can use before failing read/write for 0 capacity. -*/ ns->lba_shift = id->lbaf[lbaf].ds; -if (ns->lba_shift ==0 ) - ns->lba_shift =9 ;switch (ns->head->ids.csi) {case NVME_CSI_NVM :
Looks good.
Signature · 7 lines
Damien Le Moal Western Digital Research _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 12/20] nvme: remove the 0 lba_shift check in nvme_update_ns_info
In reply to Christoph HellwigQuoted 2 lines
We can't reach this code if Identify Namespace failed.
Technically it'd be more accurate if you write we "We can no longer reach.." as this used to be the case, but otherwise looks good.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerRe: [PATCH 12/20] nvme: remove the 0 lba_shift check in nvme_update_ns_info
Quoted 7 lines · Sagi Grimberg
Quoted 2 lines
We can't reach this code if Identify Namespace failed.
Technically it'd be more accurate if you write we "We can no longer reach.." as this used to be the case, but otherwise looks good.
Reviewed-by Sagi Grimberg <[email protected]>
Ok, I've fixed this up.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 12/20] nvme: remove the 0 lba_shift check in nvme_update_ns_info
In reply to Christoph HellwigQuoted 3 lines · Christoph Hellwig
We can't reach this code if Identify Namespace failed.
Signed-off-by Christoph Hellwig <[email protected]>
Looks good.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerPATCH 13/20 nvme: set the queue limits in nvme_update_ns_info
In reply to Christoph HellwigOnly set the queue limits once we have the real block size. This also updates the limits on a rescan if needed.
--- drivers/nvme/host/core.c | 46 ++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 25 deletions(-)
drivers/nvme/host/core.c +21 -25
@@ -2010,6 +2010,26 @@ static int nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id)return 0 ; } +static void nvme_set_queue_limits (struct nvme_ctrl *ctrl, +struct request_queue *q) +{ +bool vwc = false; + +if (ctrl->max_hw_sectors) { +u32 max_segments = + (ctrl->max_hw_sectors / (NVME_CTRL_PAGE_SIZE >>9 )) +1 ; + + max_segments =min_not_zero (max_segments, ctrl->max_segments); +blk_queue_max_hw_sectors (q, ctrl->max_hw_sectors); +blk_queue_max_segments (q,min_t (u32, max_segments,USHRT_MAX )); + } +blk_queue_virt_boundary (q,NVME_CTRL_PAGE_SIZE -1 ); +blk_queue_dma_alignment (q,7 ); +if (ctrl->vwc &NVME_CTRL_VWC_PRESENT ) + vwc = true; +blk_queue_write_cache (q, vwc, vwc); +} +static void nvme_update_disk_info (struct gendisk *disk,struct nvme_ns *ns,struct nvme_id_ns *id) {
@@ -2130,6 +2150,7 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id)blk_mq_freeze_queue (ns->disk->queue); ns->lba_shift = id->lbaf[lbaf].ds; +nvme_set_queue_limits (ctrl, ns->queue);switch (ns->head->ids.csi) {case NVME_CSI_NVM :
@@ -2495,26 +2516,6 @@ int nvme_shutdown_ctrl(struct nvme_ctrl *ctrl) }EXPORT_SYMBOL_GPL (nvme_shutdown_ctrl); -static void nvme_set_queue_limits (struct nvme_ctrl *ctrl, -struct request_queue *q) -{ -bool vwc = false; - -if (ctrl->max_hw_sectors) { -u32 max_segments = - (ctrl->max_hw_sectors / (NVME_CTRL_PAGE_SIZE >>9 )) +1 ; - - max_segments =min_not_zero (max_segments, ctrl->max_segments); -blk_queue_max_hw_sectors (q, ctrl->max_hw_sectors); -blk_queue_max_segments (q,min_t (u32, max_segments,USHRT_MAX )); - } -blk_queue_virt_boundary (q,NVME_CTRL_PAGE_SIZE -1 ); -blk_queue_dma_alignment (q,7 ); -if (ctrl->vwc &NVME_CTRL_VWC_PRESENT ) - vwc = true; -blk_queue_write_cache (q, vwc, vwc); -} -static int nvme_configure_timestamp (struct nvme_ctrl *ctrl) {__le64 ts;
@@ -3922,12 +3923,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) ns->queue->queuedata = ns; ns->ctrl = ctrl; -kref_init (&ns->kref); - ns->lba_shift =9 ;/* set to a default value for 512 until disk is validated */ - -blk_queue_logical_block_size (ns->queue,1 << ns->lba_shift); -nvme_set_queue_limits (ctrl, ns->queue); ret =nvme_init_ns_head (ns, nsid, id);if (ret)
Signature · 7 lines
2.28.0 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 13/20] nvme: set the queue limits in nvme_update_ns_info
Quoted 14 lines · Christoph Hellwig
Only set the queue limits once we have the real block size. This also updates the limits on a rescan if needed.
Signed-off-by Christoph Hellwig <[email protected]>--- drivers/nvme/host/core.c | 46 ++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 25 deletions(-)drivers/nvme/host/core.c +0
-0@@ -2010,6 +2010,26 @@ static int nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id)return 0 ;
drivers/nvme/host/core.c static int nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id) · line 2020
Quoted 10 lines
drivers/nvme/host/core.c +8
-0} +static void nvme_set_queue_limits (struct nvme_ctrl *ctrl, +struct request_queue *q) +{ +bool vwc = false; + +if (ctrl->max_hw_sectors) { +u32 max_segments = + (ctrl->max_hw_sectors / (NVME_CTRL_PAGE_SIZE >>9 )) +1 ;
It would make the line longer, but using SECTOR_SHIFT instead of 9 would be cleaner...
Quoted 54 lines
drivers/nvme/host/core.c +13
-20+ + max_segments =min_not_zero (max_segments, ctrl->max_segments); +blk_queue_max_hw_sectors (q, ctrl->max_hw_sectors); +blk_queue_max_segments (q,min_t (u32, max_segments,USHRT_MAX )); + } +blk_queue_virt_boundary (q,NVME_CTRL_PAGE_SIZE -1 ); +blk_queue_dma_alignment (q,7 ); +if (ctrl->vwc &NVME_CTRL_VWC_PRESENT ) + vwc = true; +blk_queue_write_cache (q, vwc, vwc); +} +static void nvme_update_disk_info (struct gendisk *disk,struct nvme_ns *ns,struct nvme_id_ns *id) {@@ -2130,6 +2150,7 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id)blk_mq_freeze_queue (ns->disk->queue); ns->lba_shift = id->lbaf[lbaf].ds; +nvme_set_queue_limits (ctrl, ns->queue);switch (ns->head->ids.csi) {case NVME_CSI_NVM :@@ -2495,26 +2516,6 @@ int nvme_shutdown_ctrl(struct nvme_ctrl *ctrl) }EXPORT_SYMBOL_GPL (nvme_shutdown_ctrl); -static void nvme_set_queue_limits (struct nvme_ctrl *ctrl, -struct request_queue *q) -{ -bool vwc = false; - -if (ctrl->max_hw_sectors) { -u32 max_segments = - (ctrl->max_hw_sectors / (NVME_CTRL_PAGE_SIZE >>9 )) +1 ; - - max_segments =min_not_zero (max_segments, ctrl->max_segments); -blk_queue_max_hw_sectors (q, ctrl->max_hw_sectors); -blk_queue_max_segments (q,min_t (u32, max_segments,USHRT_MAX )); - } -blk_queue_virt_boundary (q,NVME_CTRL_PAGE_SIZE -1 ); -blk_queue_dma_alignment (q,7 ); -if (ctrl->vwc &NVME_CTRL_VWC_PRESENT ) - vwc = true; -blk_queue_write_cache (q, vwc, vwc); -} -static int nvme_configure_timestamp (struct nvme_ctrl *ctrl) {__le64 ts;@@ -3922,12 +3923,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) ns->queue->queuedata = ns;
drivers/nvme/host/core.c static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) · line 3929
Quoted 10 lines
drivers/nvme/host/core.c +0
-5ns->ctrl = ctrl; -kref_init (&ns->kref); - ns->lba_shift =9 ;/* set to a default value for 512 until disk is validated */ - -blk_queue_logical_block_size (ns->queue,1 << ns->lba_shift); -nvme_set_queue_limits (ctrl, ns->queue); ret =nvme_init_ns_head (ns, nsid, id);if (ret)
Apart from the nit above, looks good.
Signature · 7 lines
Damien Le Moal Western Digital Research _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 13/20] nvme: set the queue limits in nvme_update_ns_info
In reply to Christoph HellwigLooks good.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 13/20] nvme: set the queue limits in nvme_update_ns_info
In reply to Christoph HellwigQuoted 13 lines · Christoph Hellwig
Only set the queue limits once we have the real block size. This also updates the limits on a rescan if needed.
Signed-off-by Christoph Hellwig <[email protected]>--- drivers/nvme/host/core.c | 46 ++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 25 deletions(-)drivers/nvme/host/core.c +0
-0
drivers/nvme/host/core.c static int nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id) · line 2016
Quoted 7 lines
drivers/nvme/host/core.c +4
-0@@ -2010,6 +2010,26 @@ static int nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id)return 0 ; } +static void nvme_set_queue_limits (struct nvme_ctrl *ctrl, +struct request_queue *q) +{ +bool vwc = false;
nit:- If we are initializing vwc why not :-
bool vwc = ctrl->vwc & NVME_CTRL_VWC_PRESENT ? true : false;
and get rid of the if before call to blk_queue_write_cache() that way
all blk_queue_XXX() calls will look smooth.
Irrespective of that, looks good.
Quoted 6 lines
drivers/nvme/host/core.c +6
-0+ +if (ctrl->max_hw_sectors) { +u32 max_segments = + (ctrl->max_hw_sectors / (NVME_CTRL_PAGE_SIZE >>9 )) +1 ; + + max_segments =min_not_zero (max_segments, ctrl->max_segments);
drivers/nvme/host/core.c static int nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id) · line 2032
Quoted 10 lines
drivers/nvme/host/core.c +10
-0+blk_queue_max_hw_sectors (q, ctrl->max_hw_sectors); +blk_queue_max_segments (q,min_t (u32, max_segments,USHRT_MAX )); + } +blk_queue_virt_boundary (q,NVME_CTRL_PAGE_SIZE -1 ); +blk_queue_dma_alignment (q,7 ); +if (ctrl->vwc &NVME_CTRL_VWC_PRESENT ) + vwc = true; +blk_queue_write_cache (q, vwc, vwc); +} +
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerRe: [PATCH 13/20] nvme: set the queue limits in nvme_update_ns_info
Quoted 25 lines · Chaitanya Kulkarni
Quoted 13 lines · Christoph Hellwig
Only set the queue limits once we have the real block size. This also updates the limits on a rescan if needed.
Signed-off-by Christoph Hellwig <[email protected]>--- drivers/nvme/host/core.c | 46 ++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 25 deletions(-)drivers/nvme/host/core.c +0
-0drivers/nvme/host/core.c static int nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id) · line 2016
Quoted 7 lines
drivers/nvme/host/core.c +4
-0@@ -2010,6 +2010,26 @@ static int nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id)return 0 ; } +static void nvme_set_queue_limits (struct nvme_ctrl *ctrl, +struct request_queue *q) +{ +bool vwc = false;nit:- If we are initializing vwc why not :-
bool vwc =
ctrl->vwc&NVME_CTRL_VWC_PRESENT? true : false;
Quoted 7 lines
and get rid of the if before call to
blk_queue_write_cache()that wayall
blk_queue_XXX()calls will look smooth.Irrespective of that, looks good.
Reviewed-by Chaitanya Kulkarni <[email protected]>
This is just a code move. Feel free to send an incremental cleanup.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerPATCH 14/20 nvme: update the known admin effects
In reply to Christoph HellwigA Format NVM command can change the capabilities of namespaces, and Sanity does change the Logical Block Content, and must be serialized.
Also remove CSUPP bit for Format - it is not a mandatory command, and we don't check for the bit anyway.
--- drivers/nvme/host/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/nvme/host/core.c +2 -2
@@ -968,10 +968,10 @@ static u32 nvme_known_admin_effects(u8 opcode) {switch (opcode) {case nvme_admin_format_nvm: -return NVME_CMD_EFFECTS_CSUPP |NVME_CMD_EFFECTS_LBCC | +return NVME_CMD_EFFECTS_LBCC |NVME_CMD_EFFECTS_NCC |NVME_CMD_EFFECTS_CSE_MASK ;case nvme_admin_sanitize_nvm: -return NVME_CMD_EFFECTS_CSE_MASK ; +return NVME_CMD_EFFECTS_LBCC |NVME_CMD_EFFECTS_CSE_MASK ;default :break ; }
Signature · 7 lines
2.28.0 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 14/20] nvme: update the known admin effects
Quoted 2 lines · Christoph Hellwig
A Format NVM command can change the capabilities of namespaces, and Sanity does change the Logical Block Content, and must be serialized.
s/Sanity/sanitize
Quoted 17 lines
Also remove CSUPP bit for Format - it is not a mandatory command, and we don't check for the bit anyway.
Signed-off-by Christoph Hellwig <[email protected]>--- drivers/nvme/host/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/nvme/host/core.c +0
-0@@ -968,10 +968,10 @@ static u32 nvme_known_admin_effects(u8 opcode) {switch (opcode) {
drivers/nvme/host/core.c static u32 nvme_known_admin_effects(u8 opcode) · line 977
Quoted 10 lines
drivers/nvme/host/core.c +2
-2case nvme_admin_format_nvm: -return NVME_CMD_EFFECTS_CSUPP |NVME_CMD_EFFECTS_LBCC | +return NVME_CMD_EFFECTS_LBCC |NVME_CMD_EFFECTS_NCC |NVME_CMD_EFFECTS_CSE_MASK ;case nvme_admin_sanitize_nvm: -return NVME_CMD_EFFECTS_CSE_MASK ; +return NVME_CMD_EFFECTS_LBCC |NVME_CMD_EFFECTS_CSE_MASK ;default :break ; }
With the commit message fixed, looks good.
Signature · 7 lines
Damien Le Moal Western Digital Research _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 14/20] nvme: update the known admin effects
In reply to Christoph Hellwig_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 14/20] nvme: update the known admin effects
In reply to Christoph HellwigQuoted 7 lines · Christoph Hellwig
A Format NVM command can change the capabilities of namespaces, and Sanity does change the Logical Block Content, and must be serialized.
Also remove CSUPP bit for Format - it is not a mandatory command, and we don't check for the bit anyway.
Signed-off-by Christoph Hellwig <[email protected]>
Looks good.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerPATCH 15/20 nvme: remove nvme_update_formats
In reply to Christoph HellwigNow that the queue is frozen before updating ->lba_shift we can't hit the invalid references mentioned in the comment any more. More importantly this code would not have helped us if the format was changed by another controller or through implementation defined back channels.
--- drivers/nvme/host/core.c | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-)
drivers/nvme/host/core.c +2 -30
@@ -89,7 +89,6 @@ static dev_t nvme_chr_devt;static struct class *nvme_class;static struct class *nvme_subsys_class; -static int nvme_validate_ns (struct nvme_ns *ns);static void nvme_put_subsystem (struct nvme_subsystem *subsys);static void nvme_remove_invalid_namespaces (struct nvme_ctrl *ctrl,unsigned nsid);
@@ -1009,7 +1008,7 @@ static u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns *ns,* For simplicity, IO to all namespaces is quiesced even if the command * effects say only one namespace is affected. */ -if (effects & (NVME_CMD_EFFECTS_LBCC |NVME_CMD_EFFECTS_CSE_MASK )) { +if (effects &NVME_CMD_EFFECTS_CSE_MASK ) {mutex_lock (&ctrl->scan_lock);mutex_lock (&ctrl->subsys->lock);nvme_mpath_start_freeze (ctrl->subsys);
@@ -1020,36 +1019,9 @@ static u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns *ns,return effects; } -static void nvme_update_formats (struct nvme_ctrl *ctrl,u32 *effects) -{ -struct nvme_ns *ns; - -down_read (&ctrl->namespaces_rwsem); -list_for_each_entry (ns, &ctrl->namespaces, list) -if (nvme_validate_ns (ns)) -nvme_set_queue_dying (ns); -else if (blk_queue_is_zoned (ns->disk->queue)) { -/* -* IO commands are required to fully revalidate a zoned -* device. Force the command effects to trigger rescan -* work so report zones can run in a context with -* unfrozen IO queues. -*/ - *effects |=NVME_CMD_EFFECTS_NCC ; - } -up_read (&ctrl->namespaces_rwsem); -} -static void nvme_passthru_end (struct nvme_ctrl *ctrl,u32 effects) { -/* -* Revalidate LBA changes prior to unfreezing. This is necessary to -* prevent memory corruption if a logical block size was changed by -* this command. -*/ -if (effects &NVME_CMD_EFFECTS_LBCC ) -nvme_update_formats (ctrl, &effects); -if (effects & (NVME_CMD_EFFECTS_LBCC |NVME_CMD_EFFECTS_CSE_MASK )) { +if (effects &NVME_CMD_EFFECTS_CSE_MASK ) {nvme_unfreeze (ctrl);nvme_mpath_unfreeze (ctrl->subsys);mutex_unlock (&ctrl->subsys->lock);
Signature · 7 lines
2.28.0 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 15/20] nvme: remove nvme_update_formats
Quoted 60 lines · Christoph Hellwig
Now that the queue is frozen before updating ->lba_shift we can't hit the invalid references mentioned in the comment any more. More importantly this code would not have helped us if the format was changed by another controller or through implementation defined back channels.
Signed-off-by Christoph Hellwig <[email protected]>--- drivers/nvme/host/core.c | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-)drivers/nvme/host/core.c +1
-24@@ -89,7 +89,6 @@ static dev_t nvme_chr_devt;static struct class *nvme_class;static struct class *nvme_subsys_class; -static int nvme_validate_ns (struct nvme_ns *ns);static void nvme_put_subsystem (struct nvme_subsystem *subsys);static void nvme_remove_invalid_namespaces (struct nvme_ctrl *ctrl,unsigned nsid);@@ -1009,7 +1008,7 @@ static u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns *ns,* For simplicity, IO to all namespaces is quiesced even if the command * effects say only one namespace is affected. */ -if (effects & (NVME_CMD_EFFECTS_LBCC |NVME_CMD_EFFECTS_CSE_MASK )) { +if (effects &NVME_CMD_EFFECTS_CSE_MASK ) {mutex_lock (&ctrl->scan_lock);mutex_lock (&ctrl->subsys->lock);nvme_mpath_start_freeze (ctrl->subsys);@@ -1020,36 +1019,9 @@ static u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns *ns,return effects; } -static void nvme_update_formats (struct nvme_ctrl *ctrl,u32 *effects) -{ -struct nvme_ns *ns; - -down_read (&ctrl->namespaces_rwsem); -list_for_each_entry (ns, &ctrl->namespaces, list) -if (nvme_validate_ns (ns)) -nvme_set_queue_dying (ns); -else if (blk_queue_is_zoned (ns->disk->queue)) { -/* -* IO commands are required to fully revalidate a zoned -* device. Force the command effects to trigger rescan -* work so report zones can run in a context with -* unfrozen IO queues. -*/ - *effects |=NVME_CMD_EFFECTS_NCC ; - } -up_read (&ctrl->namespaces_rwsem); -} -static void nvme_passthru_end (struct nvme_ctrl *ctrl,u32 effects) { -/* -* Revalidate LBA changes prior to unfreezing. This is necessary to
drivers/nvme/host/core.c static u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns *ns, · line 1027
Quoted 10 lines
drivers/nvme/host/core.c +1
-6-* prevent memory corruption if a logical block size was changed by -* this command. -*/ -if (effects &NVME_CMD_EFFECTS_LBCC ) -nvme_update_formats (ctrl, &effects); -if (effects & (NVME_CMD_EFFECTS_LBCC |NVME_CMD_EFFECTS_CSE_MASK )) { +if (effects &NVME_CMD_EFFECTS_CSE_MASK ) {nvme_unfreeze (ctrl);nvme_mpath_unfreeze (ctrl->subsys);mutex_unlock (&ctrl->subsys->lock);
Looks OK, but I am not so knowledgeable in this area...
Anyway it does look consistent with the effect flags change in patch 14, so:
Signature · 7 lines
Damien Le Moal Western Digital Research _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerPATCH 16/20 nvme: revalidate zone bitmaps in nvme_update_ns_info
In reply to Christoph HellwigConsolidate the two calls into a single place.
--- drivers/nvme/host/core.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/nvme/host/core.c +6 -4
@@ -2150,6 +2150,12 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id)nvme_update_disk_info (ns->disk, ns, id);blk_mq_unfreeze_queue (ns->disk->queue); +if (blk_queue_is_zoned (ns->queue)) { + ret =nvme_revalidate_zones (ns); +if (ret) +return ret; + } +#ifdef CONFIG_NVME_MULTIPATH if (ns->head->disk) {blk_mq_freeze_queue (ns->head->disk->queue);
@@ -3915,8 +3921,6 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)if (nvme_update_ns_info (ns, id)) goto out_put_disk; -if (blk_queue_is_zoned (ns->queue) &&nvme_revalidate_zones (ns)) - goto out_put_disk;if ((ctrl->quirks &NVME_QUIRK_LIGHTNVM ) && id->vs[0 ] ==0x1 ) { ret =nvme_nvm_register (ns, disk_name, node);
@@ -4012,8 +4016,6 @@ static void nvme_validate_or_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) } ret =nvme_validate_ns (ns); -if (!ret &&blk_queue_is_zoned (ns->queue)) - ret =nvme_revalidate_zones (ns);revalidate_disk_size (ns->disk, ret ==0 );if (ret)nvme_ns_remove (ns);
Signature · 7 lines
2.28.0 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 16/20] nvme: revalidate zone bitmaps in nvme_update_ns_info
Quoted 12 lines · Christoph Hellwig
Consolidate the two calls into a single place.
Signed-off-by Christoph Hellwig <[email protected]>--- drivers/nvme/host/core.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/nvme/host/core.c +0
-0
drivers/nvme/host/core.c static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id) · line 2157
Quoted 8 lines
drivers/nvme/host/core.c +5
-0@@ -2150,6 +2150,12 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id)nvme_update_disk_info (ns->disk, ns, id);blk_mq_unfreeze_queue (ns->disk->queue); +if (blk_queue_is_zoned (ns->queue)) { + ret =nvme_revalidate_zones (ns); +if (ret) +return ret; + }
Is it OK to call this before nvme_update_ns_info() ?
Quoted 23 lines
drivers/nvme/host/core.c +1
-4+#ifdef CONFIG_NVME_MULTIPATH if (ns->head->disk) {blk_mq_freeze_queue (ns->head->disk->queue);@@ -3915,8 +3921,6 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)if (nvme_update_ns_info (ns, id)) goto out_put_disk; -if (blk_queue_is_zoned (ns->queue) &&nvme_revalidate_zones (ns)) - goto out_put_disk;if ((ctrl->quirks &NVME_QUIRK_LIGHTNVM ) && id->vs[0 ] ==0x1 ) { ret =nvme_nvm_register (ns, disk_name, node);@@ -4012,8 +4016,6 @@ static void nvme_validate_or_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) } ret =nvme_validate_ns (ns); -if (!ret &&blk_queue_is_zoned (ns->queue)) - ret =nvme_revalidate_zones (ns);revalidate_disk_size (ns->disk, ret ==0 );if (ret)nvme_ns_remove (ns);
Signature · 7 lines
Damien Le Moal Western Digital Research _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerRe: [PATCH 16/20] nvme: revalidate zone bitmaps in nvme_update_ns_info
Quoted 16 lines · Damien Le Moal
Quoted 15 lines · Christoph Hellwig
Consolidate the two calls into a single place.
Signed-off-by Christoph Hellwig <[email protected]>--- drivers/nvme/host/core.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/nvme/host/core.c +0
-0@@ -2150,6 +2150,12 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id)nvme_update_disk_info (ns->disk, ns, id);blk_mq_unfreeze_queue (ns->disk->queue);
Quoted 7 lines
drivers/nvme/host/core.c static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id) · line 2157
Quoted 5 lines
drivers/nvme/host/core.c +5
-0+if (blk_queue_is_zoned (ns->queue)) { + ret =nvme_revalidate_zones (ns); +if (ret) +return ret; + }Is it OK to call this before
nvme_update_ns_info()?
It is called after nvme_update_ns_info for the relevant gendisk, but before the one for the multipath node.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerPATCH 17/20 nvme: query namespae identifiers before adding the namespace
In reply to Christoph HellwigCheck the namespace identifier list first thing when scanning namespaces. This keeps the code to query the CSI common between the alloc and validate path, and helps to structure the code better for multiple command set support.
--- drivers/nvme/host/core.c | 116 ++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 63 deletions(-)
drivers/nvme/host/core.c +53 -63
@@ -1281,6 +1281,8 @@ static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl, unsigned nsid,int status, pos, len;void *data; +if (ctrl->vs <NVME_VS (1 ,3 ,0 ) && !nvme_multi_css (ctrl)) +return 0 ;if (ctrl->quirks &NVME_QUIRK_NO_NS_DESC_LIST )return 0 ;
@@ -1335,8 +1337,8 @@ static int nvme_identify_ns_list(struct nvme_ctrl *dev, unsigned nsid, __le32 *n NVME_IDENTIFY_DATA_SIZE); } -static int nvme_identify_ns (struct nvme_ctrl *ctrl, -unsigned nsid,struct nvme_id_ns **id) +static int nvme_identify_ns (struct nvme_ctrl *ctrl,unsigned nsid, +struct nvme_ns_ids *ids,struct nvme_id_ns **id) {struct nvme_command c = { };int error;
@@ -1359,6 +1361,14 @@ static int nvme_identify_ns(struct nvme_ctrl *ctrl, error = -ENODEV ;if ((*id)->ncap ==0 )/* namespace not allocated or attached */ goto out_free_id; + +if (ctrl->vs >=NVME_VS (1 ,1 ,0 ) && + !memchr_inv (ids->eui64,0 ,sizeof (ids->eui64))) +memcpy (ids->eui64, (*id)->eui64,sizeof (ids->eui64)); +if (ctrl->vs >=NVME_VS (1 ,2 ,0 ) && + !memchr_inv (ids->nguid,0 ,sizeof (ids->nguid))) +memcpy (ids->nguid, (*id)->nguid,sizeof (ids->nguid)); +return 0 ; out_free_id:
@@ -1884,20 +1894,6 @@ static void nvme_config_write_zeroes(struct gendisk *disk, struct nvme_ns *ns) nvme_lba_to_sect(ns, max_blocks)); } -static int nvme_report_ns_ids (struct nvme_ctrl *ctrl,unsigned int nsid, -struct nvme_id_ns *id,struct nvme_ns_ids *ids) -{ -memset (ids,0 ,sizeof (*ids)); - -if (ctrl->vs >=NVME_VS (1 ,1 ,0 )) -memcpy (ids->eui64, id->eui64,sizeof (id->eui64)); -if (ctrl->vs >=NVME_VS (1 ,2 ,0 )) -memcpy (ids->nguid, id->nguid,sizeof (id->nguid)); -if (ctrl->vs >=NVME_VS (1 ,3 ,0 ) ||nvme_multi_css (ctrl)) -return nvme_identify_ns_descs (ctrl, nsid, ids); -return 0 ; -} -static bool nvme_ns_ids_valid (struct nvme_ns_ids *ids) { return !uuid_is_null(&ids->uuid) ||
@@ -2117,30 +2113,16 @@ static void nvme_set_chunk_sectors(struct nvme_ns *ns, struct nvme_id_ns *id)static int nvme_update_ns_info (struct nvme_ns *ns,struct nvme_id_ns *id) {unsigned lbaf = id->flbas &NVME_NS_FLBAS_LBA_MASK ; -struct nvme_ctrl *ctrl = ns->ctrl;int ret;blk_mq_freeze_queue (ns->disk->queue); ns->lba_shift = id->lbaf[lbaf].ds; -nvme_set_queue_limits (ctrl, ns->queue); +nvme_set_queue_limits (ns->ctrl, ns->queue); -switch (ns->head->ids.csi) { -case NVME_CSI_NVM : -break ; -case NVME_CSI_ZNS : +if (ns->head->ids.csi ==NVME_CSI_ZNS ) { ret =nvme_update_zone_info (ns, lbaf); -if (ret) { -dev_warn (ctrl->device, -"failed to add zoned namespace:%u ret:%d\n" , - ns->head->ns_id, ret); +if (ret) goto out_unfreeze; - } -break ; -default : -dev_warn (ctrl->device,"unknown csi:%u ns:%u\n" , - ns->head->ids.csi, ns->head->ns_id); - ret = -ENODEV ; - goto out_unfreeze; } ret =nvme_configure_metadata (ns, id);
@@ -2174,11 +2156,10 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id)return ret; } -static int nvme_validate_ns (struct nvme_ns *ns) +static int nvme_validate_ns (struct nvme_ns *ns,struct nvme_ns_ids *ids) {struct nvme_ctrl *ctrl = ns->ctrl;struct nvme_id_ns *id; -struct nvme_ns_ids ids;int ret =0 ;if (test_bit (NVME_NS_DEAD , &ns->flags)) {
@@ -2186,15 +2167,11 @@ static int nvme_validate_ns(struct nvme_ns *ns)return -ENODEV ; } - ret =nvme_identify_ns (ctrl, ns->head->ns_id, &id); + ret =nvme_identify_ns (ctrl, ns->head->ns_id, ids, &id);if (ret) goto out; - ret =nvme_report_ns_ids (ctrl, ns->head->ns_id, id, &ids); -if (ret) - goto free_id; - -if (!nvme_ns_ids_equal (&ns->head->ids, &ids)) { +if (!nvme_ns_ids_equal (&ns->head->ids, ids)) {dev_err (ctrl->device,"identifiers changed for nsid %d\n" , ns->head->ns_id); ret = -ENODEV ;
@@ -3794,25 +3771,16 @@ static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl, }static int nvme_init_ns_head (struct nvme_ns *ns,unsigned nsid, -struct nvme_id_ns *id) +struct nvme_ns_ids *ids,bool is_shared) {struct nvme_ctrl *ctrl = ns->ctrl; -bool is_shared = id->nmic &NVME_NS_NMIC_SHARED ;struct nvme_ns_head *head =NULL ; -struct nvme_ns_ids ids;int ret =0 ; - ret =nvme_report_ns_ids (ctrl, nsid, id, &ids); -if (ret) { -if (ret <0 ) -return ret; -return blk_status_to_errno (nvme_error_status (ret)); - } -mutex_lock (&ctrl->subsys->lock); head =nvme_find_ns_head (ctrl->subsys, nsid);if (!head) { - head =nvme_alloc_ns_head (ctrl, nsid, &ids); + head =nvme_alloc_ns_head (ctrl, nsid, ids);if (IS_ERR (head)) { ret =PTR_ERR (head); goto out_unlock;
@@ -3825,7 +3793,7 @@ static int nvme_init_ns_head(struct nvme_ns *ns, unsigned nsid, "Duplicate unshared namespace %d\n", nsid); goto out_put_ns_head; } -if (!nvme_ns_ids_equal (&head->ids, &ids)) { +if (!nvme_ns_ids_equal (&head->ids, ids)) {dev_err (ctrl->device,"IDs don't match for shared namespace %d\n" , nsid);
@@ -3873,7 +3841,8 @@ struct nvme_ns *nvme_find_get_ns(struct nvme_ctrl *ctrl, unsigned nsid) }EXPORT_SYMBOL_NS_GPL (nvme_find_get_ns,NVME_TARGET_PASSTHRU ); -static void nvme_alloc_ns (struct nvme_ctrl *ctrl,unsigned nsid) +static void nvme_alloc_ns (struct nvme_ctrl *ctrl,unsigned nsid, +struct nvme_ns_ids *ids) {struct nvme_ns *ns;struct gendisk *disk;
@@ -3881,7 +3850,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)char disk_name[DISK_NAME_LEN ];int node = ctrl->numa_node, flags =GENHD_FL_EXT_DEVT , ret; -if (nvme_identify_ns (ctrl, nsid, &id)) +if (nvme_identify_ns (ctrl, nsid, ids, &id))return ; ns =kzalloc_node (sizeof (*ns),GFP_KERNEL , node);
@@ -3903,7 +3872,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) ns->ctrl = ctrl;kref_init (&ns->kref); - ret =nvme_init_ns_head (ns, nsid, id); + ret =nvme_init_ns_head (ns, nsid, ids, id->nmic &NVME_NS_NMIC_SHARED );if (ret) goto out_free_queue;nvme_set_disk_name (disk_name, ns, ctrl, &flags);
@@ -4006,20 +3975,41 @@ static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid)static void nvme_validate_or_alloc_ns (struct nvme_ctrl *ctrl,unsigned nsid) { +struct nvme_ns_ids ids = { };struct nvme_ns *ns;int ret; +if (nvme_identify_ns_descs (ctrl, nsid, &ids)) +return ; + ns =nvme_find_get_ns (ctrl, nsid); -if (!ns) { -nvme_alloc_ns (ctrl, nsid); +if (ns) { + ret =nvme_validate_ns (ns, &ids); +revalidate_disk_size (ns->disk, ret ==0 ); +if (ret) +nvme_ns_remove (ns); +nvme_put_ns (ns);return ; } - ret =nvme_validate_ns (ns); -revalidate_disk_size (ns->disk, ret ==0 ); -if (ret) -nvme_ns_remove (ns); -nvme_put_ns (ns); +switch (ids.csi) { +case NVME_CSI_NVM : +nvme_alloc_ns (ctrl, nsid, &ids); +break ; +case NVME_CSI_ZNS : +if (!IS_ENABLED (CONFIG_BLK_DEV_ZONED )) { +dev_warn (ctrl->device, +"nsid %u not supported without CONFIG_BLK_DEV_ZONED\n" , + nsid); +break ; + } +nvme_alloc_ns (ctrl, nsid, &ids); +break ; +default : +dev_warn (ctrl->device,"unknown csi %u for nsid %u\n" , + ids.csi, nsid); +break ; + } } static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl,
Signature · 7 lines
2.28.0 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 17/20] nvme: query namespae identifiers before adding the namespace
Quoted 240 lines · Christoph Hellwig
Check the namespace identifier list first thing when scanning namespaces. This keeps the code to query the CSI common between the alloc and validate path, and helps to structure the code better for multiple command set support.
Signed-off-by Christoph Hellwig <[email protected]>--- drivers/nvme/host/core.c | 116 ++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 63 deletions(-)drivers/nvme/host/core.c +46
-63@@ -1281,6 +1281,8 @@ static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl, unsigned nsid,int status, pos, len;void *data; +if (ctrl->vs <NVME_VS (1 ,3 ,0 ) && !nvme_multi_css (ctrl)) +return 0 ;if (ctrl->quirks &NVME_QUIRK_NO_NS_DESC_LIST )return 0 ;@@ -1335,8 +1337,8 @@ static int nvme_identify_ns_list(struct nvme_ctrl *dev, unsigned nsid, __le32 *n NVME_IDENTIFY_DATA_SIZE); } -static int nvme_identify_ns (struct nvme_ctrl *ctrl, -unsigned nsid,struct nvme_id_ns **id) +static int nvme_identify_ns (struct nvme_ctrl *ctrl,unsigned nsid, +struct nvme_ns_ids *ids,struct nvme_id_ns **id) {struct nvme_command c = { };int error;@@ -1359,6 +1361,14 @@ static int nvme_identify_ns(struct nvme_ctrl *ctrl, error = -ENODEV ;if ((*id)->ncap ==0 )/* namespace not allocated or attached */ goto out_free_id; + +if (ctrl->vs >=NVME_VS (1 ,1 ,0 ) && + !memchr_inv (ids->eui64,0 ,sizeof (ids->eui64))) +memcpy (ids->eui64, (*id)->eui64,sizeof (ids->eui64)); +if (ctrl->vs >=NVME_VS (1 ,2 ,0 ) && + !memchr_inv (ids->nguid,0 ,sizeof (ids->nguid))) +memcpy (ids->nguid, (*id)->nguid,sizeof (ids->nguid)); +return 0 ; out_free_id:@@ -1884,20 +1894,6 @@ static void nvme_config_write_zeroes(struct gendisk *disk, struct nvme_ns *ns) nvme_lba_to_sect(ns, max_blocks)); } -static int nvme_report_ns_ids (struct nvme_ctrl *ctrl,unsigned int nsid, -struct nvme_id_ns *id,struct nvme_ns_ids *ids) -{ -memset (ids,0 ,sizeof (*ids)); - -if (ctrl->vs >=NVME_VS (1 ,1 ,0 )) -memcpy (ids->eui64, id->eui64,sizeof (id->eui64)); -if (ctrl->vs >=NVME_VS (1 ,2 ,0 )) -memcpy (ids->nguid, id->nguid,sizeof (id->nguid)); -if (ctrl->vs >=NVME_VS (1 ,3 ,0 ) ||nvme_multi_css (ctrl)) -return nvme_identify_ns_descs (ctrl, nsid, ids); -return 0 ; -} -static bool nvme_ns_ids_valid (struct nvme_ns_ids *ids) { return !uuid_is_null(&ids->uuid) ||@@ -2117,30 +2113,16 @@ static void nvme_set_chunk_sectors(struct nvme_ns *ns, struct nvme_id_ns *id)static int nvme_update_ns_info (struct nvme_ns *ns,struct nvme_id_ns *id) {unsigned lbaf = id->flbas &NVME_NS_FLBAS_LBA_MASK ; -struct nvme_ctrl *ctrl = ns->ctrl;int ret;blk_mq_freeze_queue (ns->disk->queue); ns->lba_shift = id->lbaf[lbaf].ds; -nvme_set_queue_limits (ctrl, ns->queue); +nvme_set_queue_limits (ns->ctrl, ns->queue); -switch (ns->head->ids.csi) { -case NVME_CSI_NVM : -break ; -case NVME_CSI_ZNS : +if (ns->head->ids.csi ==NVME_CSI_ZNS ) { ret =nvme_update_zone_info (ns, lbaf); -if (ret) { -dev_warn (ctrl->device, -"failed to add zoned namespace:%u ret:%d\n" , - ns->head->ns_id, ret); +if (ret) goto out_unfreeze; - } -break ; -default : -dev_warn (ctrl->device,"unknown csi:%u ns:%u\n" , - ns->head->ids.csi, ns->head->ns_id); - ret = -ENODEV ; - goto out_unfreeze; } ret =nvme_configure_metadata (ns, id);@@ -2174,11 +2156,10 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id)return ret; } -static int nvme_validate_ns (struct nvme_ns *ns) +static int nvme_validate_ns (struct nvme_ns *ns,struct nvme_ns_ids *ids) {struct nvme_ctrl *ctrl = ns->ctrl;struct nvme_id_ns *id; -struct nvme_ns_ids ids;int ret =0 ;if (test_bit (NVME_NS_DEAD , &ns->flags)) {@@ -2186,15 +2167,11 @@ static int nvme_validate_ns(struct nvme_ns *ns)return -ENODEV ; } - ret =nvme_identify_ns (ctrl, ns->head->ns_id, &id); + ret =nvme_identify_ns (ctrl, ns->head->ns_id, ids, &id);if (ret) goto out; - ret =nvme_report_ns_ids (ctrl, ns->head->ns_id, id, &ids); -if (ret) - goto free_id; - -if (!nvme_ns_ids_equal (&ns->head->ids, &ids)) { +if (!nvme_ns_ids_equal (&ns->head->ids, ids)) {dev_err (ctrl->device,"identifiers changed for nsid %d\n" , ns->head->ns_id); ret = -ENODEV ;@@ -3794,25 +3771,16 @@ static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl, }static int nvme_init_ns_head (struct nvme_ns *ns,unsigned nsid, -struct nvme_id_ns *id) +struct nvme_ns_ids *ids,bool is_shared) {struct nvme_ctrl *ctrl = ns->ctrl; -bool is_shared = id->nmic &NVME_NS_NMIC_SHARED ;struct nvme_ns_head *head =NULL ; -struct nvme_ns_ids ids;int ret =0 ; - ret =nvme_report_ns_ids (ctrl, nsid, id, &ids); -if (ret) { -if (ret <0 ) -return ret; -return blk_status_to_errno (nvme_error_status (ret)); - } -mutex_lock (&ctrl->subsys->lock); head =nvme_find_ns_head (ctrl->subsys, nsid);if (!head) { - head =nvme_alloc_ns_head (ctrl, nsid, &ids); + head =nvme_alloc_ns_head (ctrl, nsid, ids);if (IS_ERR (head)) { ret =PTR_ERR (head); goto out_unlock;@@ -3825,7 +3793,7 @@ static int nvme_init_ns_head(struct nvme_ns *ns, unsigned nsid, "Duplicate unshared namespace %d\n", nsid); goto out_put_ns_head; } -if (!nvme_ns_ids_equal (&head->ids, &ids)) { +if (!nvme_ns_ids_equal (&head->ids, ids)) {dev_err (ctrl->device,"IDs don't match for shared namespace %d\n" , nsid);@@ -3873,7 +3841,8 @@ struct nvme_ns *nvme_find_get_ns(struct nvme_ctrl *ctrl, unsigned nsid) }EXPORT_SYMBOL_NS_GPL (nvme_find_get_ns,NVME_TARGET_PASSTHRU ); -static void nvme_alloc_ns (struct nvme_ctrl *ctrl,unsigned nsid) +static void nvme_alloc_ns (struct nvme_ctrl *ctrl,unsigned nsid, +struct nvme_ns_ids *ids) {struct nvme_ns *ns;struct gendisk *disk;@@ -3881,7 +3850,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)char disk_name[DISK_NAME_LEN ];int node = ctrl->numa_node, flags =GENHD_FL_EXT_DEVT , ret; -if (nvme_identify_ns (ctrl, nsid, &id)) +if (nvme_identify_ns (ctrl, nsid, ids, &id))return ; ns =kzalloc_node (sizeof (*ns),GFP_KERNEL , node);@@ -3903,7 +3872,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) ns->ctrl = ctrl;kref_init (&ns->kref); - ret =nvme_init_ns_head (ns, nsid, id); + ret =nvme_init_ns_head (ns, nsid, ids, id->nmic &NVME_NS_NMIC_SHARED );if (ret) goto out_free_queue;nvme_set_disk_name (disk_name, ns, ctrl, &flags);@@ -4006,20 +3975,41 @@ static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid)static void nvme_validate_or_alloc_ns (struct nvme_ctrl *ctrl,unsigned nsid) { +struct nvme_ns_ids ids = { };struct nvme_ns *ns;int ret; +if (nvme_identify_ns_descs (ctrl, nsid, &ids)) +return ; + ns =nvme_find_get_ns (ctrl, nsid); -if (!ns) { -nvme_alloc_ns (ctrl, nsid); +if (ns) { + ret =nvme_validate_ns (ns, &ids); +revalidate_disk_size (ns->disk, ret ==0 ); +if (ret) +nvme_ns_remove (ns); +nvme_put_ns (ns);return ; } - ret =nvme_validate_ns (ns); -revalidate_disk_size (ns->disk, ret ==0 ); -if (ret) -nvme_ns_remove (ns); -nvme_put_ns (ns); +switch (ids.csi) { +case NVME_CSI_NVM : +nvme_alloc_ns (ctrl, nsid, &ids); +break ; +case NVME_CSI_ZNS : +if (!IS_ENABLED (CONFIG_BLK_DEV_ZONED )) { +dev_warn (ctrl->device, +"nsid %u not supported without CONFIG_BLK_DEV_ZONED\n" , + nsid); +break ; + }
drivers/nvme/host/core.c static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid) · line 4015
Quoted 10 lines
drivers/nvme/host/core.c +7
-0+nvme_alloc_ns (ctrl, nsid, &ids); +break ; +default : +dev_warn (ctrl->device,"unknown csi %u for nsid %u\n" , + ids.csi, nsid); +break ; + } } static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl,
Looks good.
Signature · 7 lines
Damien Le Moal Western Digital Research _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 17/20] nvme: query namespae identifiers before adding the namespace
In reply to Christoph HellwigQuoted 9 lines · Christoph Hellwig
Check the namespace identifier list first thing when scanning namespaces. This keeps the code to query the CSI common between the alloc and validate path, and helps to structure the code better for multiple command set support.
Signed-off-by Christoph Hellwig <[email protected]>--- drivers/nvme/host/core.c | 116 ++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 63 deletions(-)
For the subject of this patch:
s/namespae/namespace
In your v1 series, you had a separate patch for:
"
nvme: remove the namespace identifier verification in __nvme_validate_ns
None of the identifiers (including the new CSI) can cange over the life time of a namespace, so don't bother with the extra query here. "
which now seems to have been squashed with this patch.
Squashing it is fine, but perhaps you could add that information in this commit message?
Kind regards,
Niklas
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 17/20] nvme: query namespae identifiers before adding the namespace
Quoted 21 lines · Niklas Cassel
Quoted 9 lines · Christoph Hellwig
Check the namespace identifier list first thing when scanning namespaces. This keeps the code to query the CSI common between the alloc and validate path, and helps to structure the code better for multiple command set support.
Signed-off-by Christoph Hellwig <[email protected]>--- drivers/nvme/host/core.c | 116 ++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 63 deletions(-)For the subject of this patch:
s/namespae/namespaceIn your v1 series, you had a separate patch for:
"
nvme: remove the namespace identifier verification in__nvme_validate_ns
Quoted 8 lines
None of the identifiers (including the new CSI) can cange over the life time of a namespace, so don't bother with the extra query here. "
which now seems to have been squashed with this patch.
Squashing it is fine, but perhaps you could add that information in this commit message?
Hm..
I now see that nvme_validate_or_alloc_ns() in v2 of this series does a nvme_identify_ns_descs(), while nvme_validate_or_alloc_ns() in v1 doesnt.
I don't see a change log, but considering this, my suggestion that you the above sentence from the squashed v1 commit no longer makes sense.
What was the reason for this change?
Kind regards,
Niklas
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerRe: [PATCH 17/20] nvme: query namespae identifiers before adding the namespace
Quoted 2 lines · Niklas Cassel
Quoted 2 lines
For the subject of this patch:
s/namespae/namespace
Fixed and force pushed.
Quoted 13 lines
Quoted 10 lines
nvme: remove the namespace identifier verification in
__nvme_validate_nsNone of the identifiers (including the new CSI) can cange over the life time of a namespace, so don't bother with the extra query here. "
which now seems to have been squashed with this patch.
Squashing it is fine, but perhaps you could add that information in this commit message?
Hm..
Quoted 7 lines
I now see that
nvme_validate_or_alloc_ns()in v2 of this series does anvme_identify_ns_descs(), whilenvme_validate_or_alloc_ns()in v1 doesnt.I don't see a change log, but considering this, my suggestion that you the above sentence from the squashed v1 commit no longer makes sense.
What was the reason for this change?
Where does this this still show up in a change log?
The isn't much point in checking the changing identifiers, but we pretty much get it for free, so..
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 17/20] nvme: query namespae identifiers before adding the namespace
Quoted 22 lines · Christoph Hellwig
Quoted 2 lines · Niklas Cassel
Quoted 2 lines
For the subject of this patch:
s/namespae/namespaceFixed and force pushed.
Quoted 16 lines
Quoted 10 lines
nvme: remove the namespace identifier verification in
__nvme_validate_nsNone of the identifiers (including the new CSI) can cange over the life time of a namespace, so don't bother with the extra query here. "
which now seems to have been squashed with this patch.
Squashing it is fine, but perhaps you could add that information in this commit message?
Hm..
I now see that
nvme_validate_or_alloc_ns()in v2 of this series does anvme_identify_ns_descs(), whilenvme_validate_or_alloc_ns()in v1 doesnt.
Quoted 6 lines
Quoted 4 lines
I don't see a change log, but considering this, my suggestion that you the above sentence from the squashed v1 commit no longer makes sense.
What was the reason for this change?
Where does this this still show up in a change log?
The sentence only exists in the V1 patch series,
not in the V2 patch series. So that is all good.
My questions is rather:
In V1 nvme_validate_or_alloc_ns():
http://git.infradead.org/users/hch/misc.git/blob/refs/heads/nvme-scanning-cleanup:/drivers/nvme/host/core.c#l3975
You will only call nvme_identify_ns_descs() once, and once only per NSID, in the nvme_alloc_ns() path.
Subsequent calls that goes through the nvme_validate_ns() path will not call nvme_identify_ns_descs().
In V2 nvme_validate_or_alloc_ns():
http://git.infradead.org/users/hch/misc.git/blob/refs/heads/nvme-scanning-cleanup.2:/drivers/nvme/host/core.c#l3971
You will call nvme_identify_ns_descs() both for the initial nvme_alloc_ns() path, but then also in each subsequent call, which goes through the nvme_validate_ns() path.
V1 seems more optimized.
Since we know that none of the identifiers can change during the lifetime of a namespace, why not do like V1, and only call it in the nvme_alloc_ns() path?
Something like this:
static void nvme_validate_or_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
{
...
ns = nvme_find_get_ns(ctrl, nsid);
if (ns) {
nvme_validate_ns(ns, &ids);
nvme_put_ns(ns);
return;
}
/* only fetch the ns id desc list if we didn't find a ns */
if (nvme_identify_ns_descs(ctrl, nsid, &ids))
return;
switch (ids.csi) {
...
}
...
}Is there something I'm missing, or why did you change this between V1 and V2?
Kind regards,
Niklas
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerRe: [PATCH 17/20] nvme: query namespae identifiers before adding the namespace
Quoted 1 line · Niklas Cassel
Is there something I'm missing, or why did you change this between V1 and V2?
rescan is not exactly a common fast path.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerPATCH 18/20 nvme: move nvme_validate_ns
In reply to Christoph HellwigMove nvme_validate_ns just above its only remaining caller.
--- drivers/nvme/host/core.c | 74 ++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 37 deletions(-)
drivers/nvme/host/core.c +37 -37
@@ -2156,43 +2156,6 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id)return ret; } -static int nvme_validate_ns (struct nvme_ns *ns,struct nvme_ns_ids *ids) -{ -struct nvme_ctrl *ctrl = ns->ctrl; -struct nvme_id_ns *id; -int ret =0 ; - -if (test_bit (NVME_NS_DEAD , &ns->flags)) { -set_capacity (ns->disk,0 ); -return -ENODEV ; - } - - ret =nvme_identify_ns (ctrl, ns->head->ns_id, ids, &id); -if (ret) - goto out; - -if (!nvme_ns_ids_equal (&ns->head->ids, ids)) { -dev_err (ctrl->device, -"identifiers changed for nsid %d\n" , ns->head->ns_id); - ret = -ENODEV ; - goto free_id; - } - - ret =nvme_update_ns_info (ns, id); -free_id: -kfree (id); -out: -/* -* Only fail the function if we got a fatal error back from the -* device, otherwise ignore the error and just move on. -*/ -if (ret == -ENOMEM || (ret >0 && !(ret &NVME_SC_DNR ))) - ret =0 ; -else if (ret >0 ) - ret =blk_status_to_errno (nvme_error_status (ret)); -return ret; -} -static char nvme_pr_type (enum pr_type type) {switch (type) {
@@ -3973,6 +3936,43 @@ static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid) } } +static int nvme_validate_ns (struct nvme_ns *ns,struct nvme_ns_ids *ids) +{ +struct nvme_ctrl *ctrl = ns->ctrl; +struct nvme_id_ns *id; +int ret =0 ; + +if (test_bit (NVME_NS_DEAD , &ns->flags)) { +set_capacity (ns->disk,0 ); +return -ENODEV ; + } + + ret =nvme_identify_ns (ctrl, ns->head->ns_id, ids, &id); +if (ret) + goto out; + +if (!nvme_ns_ids_equal (&ns->head->ids, ids)) { +dev_err (ctrl->device, +"identifiers changed for nsid %d\n" , ns->head->ns_id); + ret = -ENODEV ; + goto free_id; + } + + ret =nvme_update_ns_info (ns, id); +free_id: +kfree (id); +out: +/* +* Only fail the function if we got a fatal error back from the +* device, otherwise ignore the error and just move on. +*/ +if (ret == -ENOMEM || (ret >0 && !(ret &NVME_SC_DNR ))) + ret =0 ; +else if (ret >0 ) + ret =blk_status_to_errno (nvme_error_status (ret)); +return ret; +} +static void nvme_validate_or_alloc_ns (struct nvme_ctrl *ctrl,unsigned nsid) {struct nvme_ns_ids ids = { };
Signature · 7 lines
2.28.0 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 18/20] nvme: move nvme_validate_ns
Quoted 90 lines · Christoph Hellwig
Move
nvme_validate_nsjust above its only remaining caller.Signed-off-by Christoph Hellwig <[email protected]>--- drivers/nvme/host/core.c | 74 ++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 37 deletions(-)drivers/nvme/host/core.c +30
-37@@ -2156,43 +2156,6 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id)return ret; } -static int nvme_validate_ns (struct nvme_ns *ns,struct nvme_ns_ids *ids) -{ -struct nvme_ctrl *ctrl = ns->ctrl; -struct nvme_id_ns *id; -int ret =0 ; - -if (test_bit (NVME_NS_DEAD , &ns->flags)) { -set_capacity (ns->disk,0 ); -return -ENODEV ; - } - - ret =nvme_identify_ns (ctrl, ns->head->ns_id, ids, &id); -if (ret) - goto out; - -if (!nvme_ns_ids_equal (&ns->head->ids, ids)) { -dev_err (ctrl->device, -"identifiers changed for nsid %d\n" , ns->head->ns_id); - ret = -ENODEV ; - goto free_id; - } - - ret =nvme_update_ns_info (ns, id); -free_id: -kfree (id); -out: -/* -* Only fail the function if we got a fatal error back from the -* device, otherwise ignore the error and just move on. -*/ -if (ret == -ENOMEM || (ret >0 && !(ret &NVME_SC_DNR ))) - ret =0 ; -else if (ret >0 ) - ret =blk_status_to_errno (nvme_error_status (ret)); -return ret; -} -static char nvme_pr_type (enum pr_type type) {switch (type) {@@ -3973,6 +3936,43 @@ static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid) } } +static int nvme_validate_ns (struct nvme_ns *ns,struct nvme_ns_ids *ids) +{ +struct nvme_ctrl *ctrl = ns->ctrl; +struct nvme_id_ns *id; +int ret =0 ; + +if (test_bit (NVME_NS_DEAD , &ns->flags)) { +set_capacity (ns->disk,0 ); +return -ENODEV ; + } + + ret =nvme_identify_ns (ctrl, ns->head->ns_id, ids, &id); +if (ret) + goto out; + +if (!nvme_ns_ids_equal (&ns->head->ids, ids)) { +dev_err (ctrl->device, +"identifiers changed for nsid %d\n" , ns->head->ns_id); + ret = -ENODEV ; + goto free_id; + } + + ret =nvme_update_ns_info (ns, id); +free_id: +kfree (id); +out: +/* +* Only fail the function if we got a fatal error back from the +* device, otherwise ignore the error and just move on. +*/
drivers/nvme/host/core.c static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid) · line 3978
Quoted 10 lines
drivers/nvme/host/core.c +7
-0+if (ret == -ENOMEM || (ret >0 && !(ret &NVME_SC_DNR ))) + ret =0 ; +else if (ret >0 ) + ret =blk_status_to_errno (nvme_error_status (ret)); +return ret; +} +static void nvme_validate_or_alloc_ns (struct nvme_ctrl *ctrl,unsigned nsid) {struct nvme_ns_ids ids = { };
Looks good.
Signature · 7 lines
Damien Le Moal Western Digital Research _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 18/20] nvme: move nvme_validate_ns
In reply to Christoph HellwigQuoted 56 lines · Christoph Hellwig
Move
nvme_validate_nsjust above its only remaining caller.Signed-off-by Christoph Hellwig <[email protected]>--- drivers/nvme/host/core.c | 74 ++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 37 deletions(-)drivers/nvme/host/core.c +0
-37@@ -2156,43 +2156,6 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id)return ret; } -static int nvme_validate_ns (struct nvme_ns *ns,struct nvme_ns_ids *ids) -{ -struct nvme_ctrl *ctrl = ns->ctrl; -struct nvme_id_ns *id; -int ret =0 ; - -if (test_bit (NVME_NS_DEAD , &ns->flags)) { -set_capacity (ns->disk,0 ); -return -ENODEV ; - } - - ret =nvme_identify_ns (ctrl, ns->head->ns_id, ids, &id); -if (ret) - goto out; - -if (!nvme_ns_ids_equal (&ns->head->ids, ids)) { -dev_err (ctrl->device, -"identifiers changed for nsid %d\n" , ns->head->ns_id); - ret = -ENODEV ; - goto free_id; - } - - ret =nvme_update_ns_info (ns, id); -free_id: -kfree (id); -out: -/* -* Only fail the function if we got a fatal error back from the -* device, otherwise ignore the error and just move on. -*/ -if (ret == -ENOMEM || (ret >0 && !(ret &NVME_SC_DNR ))) - ret =0 ; -else if (ret >0 ) - ret =blk_status_to_errno (nvme_error_status (ret)); -return ret; -} -static char nvme_pr_type (enum pr_type type) {switch (type) {
drivers/nvme/host/core.c static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid) · line 3941
Quoted 6 lines
drivers/nvme/host/core.c +3
-0@@ -3973,6 +3936,43 @@ static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid) } } +static int nvme_validate_ns (struct nvme_ns *ns,struct nvme_ns_ids *ids) +{ +struct nvme_ctrl *ctrl = ns->ctrl;
the ctrl variable only accessed twice and there is enough space for using
ns->ctrl so that we will not exceed the 80 char, consider removing that and using
ns->ctrl ?
drivers/nvme/host/core.c static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid) · line 3944
Quoted 3 lines
drivers/nvme/host/core.c +3
-0+struct nvme_id_ns *id; +int ret =0 ; +
no need to initialize ret it is getting overwritten nvme_identify_ns() before
the first access or ret = -ENODEV and return ret on test_bit(NVME_NS_DEAD)
error case.
Quoted 24 lines
drivers/nvme/host/core.c +24
-0+if (test_bit (NVME_NS_DEAD , &ns->flags)) { +set_capacity (ns->disk,0 ); +return -ENODEV ; + } + + ret =nvme_identify_ns (ctrl, ns->head->ns_id, ids, &id); +if (ret) + goto out; + +if (!nvme_ns_ids_equal (&ns->head->ids, ids)) { +dev_err (ctrl->device, +"identifiers changed for nsid %d\n" , ns->head->ns_id); + ret = -ENODEV ; + goto free_id; + } + + ret =nvme_update_ns_info (ns, id); +free_id: +kfree (id); +out: +/* +* Only fail the function if we got a fatal error back from the +* device, otherwise ignore the error and just move on. +*/
drivers/nvme/host/core.c static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid) · line 3978
Quoted 10 lines
drivers/nvme/host/core.c +7
-0+if (ret == -ENOMEM || (ret >0 && !(ret &NVME_SC_DNR ))) + ret =0 ; +else if (ret >0 ) + ret =blk_status_to_errno (nvme_error_status (ret)); +return ret; +} +static void nvme_validate_or_alloc_ns (struct nvme_ctrl *ctrl,unsigned nsid) {struct nvme_ns_ids ids = { };
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerRe: [PATCH 18/20] nvme: move nvme_validate_ns
Quoted 18 lines · Chaitanya Kulkarni
drivers/nvme/host/core.c static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid) · line 3941
Quoted 3 lines
drivers/nvme/host/core.c +3
-0+static int nvme_validate_ns (struct nvme_ns *ns,struct nvme_ns_ids *ids) +{ +struct nvme_ctrl *ctrl = ns->ctrl;the ctrl variable only accessed twice and there is enough space for using
ns->ctrlso that we will not exceed the 80 char, consider removing that and using
ns->ctrl?drivers/nvme/host/core.c static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid) · line 3944
Quoted 3 lines
drivers/nvme/host/core.c +3
-0+struct nvme_id_ns *id; +int ret =0 ; +no need to initialize ret it is getting overwritten
nvme_identify_ns()before
Quoted 3 lines
the first access or ret =
-ENODEVand return ret ontest_bit(NVME_NS_DEAD)error case.
This patch is a pure code move. But I think all of your comments are taken care of later anyway.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerPATCH 19/20 nvme: refactor nvme_validate_ns
In reply to Christoph HellwigMove the logic to revalidate the block_device size or remove the namespace from the caller into nvme_validate_ns. This removes the return value and thus the status code translation. Additionally it also catches non-permanent errors from nvme_update_ns_info using the existing logic.
--- drivers/nvme/host/core.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-)
drivers/nvme/host/core.c +17 -20
@@ -3899,6 +3899,7 @@ static void nvme_ns_remove(struct nvme_ns *ns)if (test_and_set_bit (NVME_NS_REMOVING , &ns->flags))return ; +set_capacity (ns->disk,0 );nvme_fault_inject_fini (&ns->fault_inject);mutex_lock (&ns->ctrl->subsys->lock);
@@ -3936,58 +3937,54 @@ static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid) } } -static int nvme_validate_ns (struct nvme_ns *ns,struct nvme_ns_ids *ids) +static void nvme_validate_ns (struct nvme_ns *ns,struct nvme_ns_ids *ids) {struct nvme_ctrl *ctrl = ns->ctrl;struct nvme_id_ns *id; -int ret =0 ; +int ret = -ENODEV ; -if (test_bit (NVME_NS_DEAD , &ns->flags)) { -set_capacity (ns->disk,0 ); -return -ENODEV ; - } +if (test_bit (NVME_NS_DEAD , &ns->flags)) + goto out; ret =nvme_identify_ns (ctrl, ns->head->ns_id, ids, &id);if (ret) goto out; + ret = -ENODEV ;if (!nvme_ns_ids_equal (&ns->head->ids, ids)) {dev_err (ctrl->device,"identifiers changed for nsid %d\n" , ns->head->ns_id); - ret = -ENODEV ; - goto free_id; + goto out_free_id; } ret =nvme_update_ns_info (ns, id); -free_id: + +out_free_id:kfree (id); out:/* -* Only fail the function if we got a fatal error back from the +* Only remove the namespace if we got a fatal error back from the * device, otherwise ignore the error and just move on. +* +* TODO: we should probably schedule a delayed retry here. */ -if (ret == -ENOMEM || (ret >0 && !(ret &NVME_SC_DNR ))) - ret =0 ; -else if (ret >0 ) - ret =blk_status_to_errno (nvme_error_status (ret)); -return ret; +if (ret && ret != -ENOMEM && !(ret >0 && !(ret &NVME_SC_DNR ))) +nvme_ns_remove (ns); +else +revalidate_disk_size (ns->disk, true); }static void nvme_validate_or_alloc_ns (struct nvme_ctrl *ctrl,unsigned nsid) {struct nvme_ns_ids ids = { };struct nvme_ns *ns; -int ret;if (nvme_identify_ns_descs (ctrl, nsid, &ids))return ; ns =nvme_find_get_ns (ctrl, nsid);if (ns) { - ret =nvme_validate_ns (ns, &ids); -revalidate_disk_size (ns->disk, ret ==0 ); -if (ret) -nvme_ns_remove (ns); +nvme_validate_ns (ns, &ids);nvme_put_ns (ns);return ; }
Signature · 7 lines
2.28.0 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 19/20] nvme: refactor nvme_validate_ns
Quoted 24 lines · Christoph Hellwig
Move the logic to revalidate the
block_devicesize or remove the namespace from the caller intonvme_validate_ns. This removes the return value and thus the status code translation. Additionally it also catches non-permanent errors fromnvme_update_ns_infousing the existing logic.Signed-off-by Christoph Hellwig <[email protected]>--- drivers/nvme/host/core.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-)drivers/nvme/host/core.c +1
-0@@ -3899,6 +3899,7 @@ static void nvme_ns_remove(struct nvme_ns *ns)if (test_and_set_bit (NVME_NS_REMOVING , &ns->flags))return ; +set_capacity (ns->disk,0 );nvme_fault_inject_fini (&ns->fault_inject);mutex_lock (&ns->ctrl->subsys->lock);
drivers/nvme/host/core.c static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid) · line 3944
Quoted 10 lines
drivers/nvme/host/core.c +2
-2@@ -3936,58 +3937,54 @@ static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid) } } -static int nvme_validate_ns (struct nvme_ns *ns,struct nvme_ns_ids *ids) +static void nvme_validate_ns (struct nvme_ns *ns,struct nvme_ns_ids *ids) {struct nvme_ctrl *ctrl = ns->ctrl;struct nvme_id_ns *id; -int ret =0 ; +int ret = -ENODEV ;
No assignment needed. nvme_identify_ns() will overwrite it.
Quoted 55 lines
drivers/nvme/host/core.c +13
-14-if (test_bit (NVME_NS_DEAD , &ns->flags)) { -set_capacity (ns->disk,0 ); -return -ENODEV ; - } +if (test_bit (NVME_NS_DEAD , &ns->flags)) + goto out; ret =nvme_identify_ns (ctrl, ns->head->ns_id, ids, &id);if (ret) goto out; + ret = -ENODEV ;if (!nvme_ns_ids_equal (&ns->head->ids, ids)) {dev_err (ctrl->device,"identifiers changed for nsid %d\n" , ns->head->ns_id); - ret = -ENODEV ; - goto free_id; + goto out_free_id; } ret =nvme_update_ns_info (ns, id); -free_id: + +out_free_id:kfree (id); out:/* -* Only fail the function if we got a fatal error back from the +* Only remove the namespace if we got a fatal error back from the * device, otherwise ignore the error and just move on. +* +* TODO: we should probably schedule a delayed retry here. */ -if (ret == -ENOMEM || (ret >0 && !(ret &NVME_SC_DNR ))) - ret =0 ; -else if (ret >0 ) - ret =blk_status_to_errno (nvme_error_status (ret)); -return ret; +if (ret && ret != -ENOMEM && !(ret >0 && !(ret &NVME_SC_DNR ))) +nvme_ns_remove (ns); +else +revalidate_disk_size (ns->disk, true); }static void nvme_validate_or_alloc_ns (struct nvme_ctrl *ctrl,unsigned nsid) {struct nvme_ns_ids ids = { };struct nvme_ns *ns; -int ret;if (nvme_identify_ns_descs (ctrl, nsid, &ids))return ; ns =nvme_find_get_ns (ctrl, nsid);
drivers/nvme/host/core.c static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid)
Quoted 10 lines
drivers/nvme/host/core.c +1
-4if (ns) { - ret =nvme_validate_ns (ns, &ids); -revalidate_disk_size (ns->disk, ret ==0 ); -if (ret) -nvme_ns_remove (ns); +nvme_validate_ns (ns, &ids);nvme_put_ns (ns);return ; }
With the nit above corrected,
Signature · 7 lines
Damien Le Moal Western Digital Research _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerRe: [PATCH 19/20] nvme: refactor nvme_validate_ns
Quoted 39 lines · Damien Le Moal
Quoted 24 lines · Christoph Hellwig
Move the logic to revalidate the
block_devicesize or remove the namespace from the caller intonvme_validate_ns. This removes the return value and thus the status code translation. Additionally it also catches non-permanent errors fromnvme_update_ns_infousing the existing logic.Signed-off-by Christoph Hellwig <[email protected]>--- drivers/nvme/host/core.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-)drivers/nvme/host/core.c +1
-0@@ -3899,6 +3899,7 @@ static void nvme_ns_remove(struct nvme_ns *ns)if (test_and_set_bit (NVME_NS_REMOVING , &ns->flags))return ; +set_capacity (ns->disk,0 );nvme_fault_inject_fini (&ns->fault_inject);mutex_lock (&ns->ctrl->subsys->lock);drivers/nvme/host/core.c static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid) · line 3944
Quoted 10 lines
drivers/nvme/host/core.c +2
-2@@ -3936,58 +3937,54 @@ static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid) } } -static int nvme_validate_ns (struct nvme_ns *ns,struct nvme_ns_ids *ids) +static void nvme_validate_ns (struct nvme_ns *ns,struct nvme_ns_ids *ids) {struct nvme_ctrl *ctrl = ns->ctrl;struct nvme_id_ns *id; -int ret =0 ; +int ret = -ENODEV ;No assignment needed.
nvme_identify_ns()will overwrite it.Quoted 1 line
Quoted 6 lines
drivers/nvme/host/core.c static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid) · line 3947
Quoted 6 lines
drivers/nvme/host/core.c +2
-4-if (test_bit (NVME_NS_DEAD , &ns->flags)) { -set_capacity (ns->disk,0 ); -return -ENODEV ; - } +if (test_bit (NVME_NS_DEAD , &ns->flags)) + goto out;
.. but we can already jump to out here, so we do actually need it.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerPATCH 20/20 nvme: remove nvme_identify_ns_list
In reply to Christoph HellwigJust fold it into the only caller.
--- drivers/nvme/host/core.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
drivers/nvme/host/core.c +8 -12
@@ -1326,17 +1326,6 @@ static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl, unsigned nsid,return status; } -static int nvme_identify_ns_list (struct nvme_ctrl *dev,unsigned nsid,__le32 *ns_list) -{ -struct nvme_command c = { }; - - c.identify.opcode = nvme_admin_identify; - c.identify.cns =NVME_ID_CNS_NS_ACTIVE_LIST ; - c.identify.nsid =cpu_to_le32 (nsid); -return nvme_submit_sync_cmd (dev->admin_q, &c, ns_list, -NVME_IDENTIFY_DATA_SIZE ); -} -static int nvme_identify_ns (struct nvme_ctrl *ctrl,unsigned nsid,struct nvme_ns_ids *ids,struct nvme_id_ns **id) {
@@ -4042,7 +4031,14 @@ static int nvme_scan_ns_list(struct nvme_ctrl *ctrl)return -ENOMEM ;for (;;) { - ret =nvme_identify_ns_list (ctrl, prev, ns_list); +struct nvme_command cmd = { + .identify.opcode = nvme_admin_identify, + .identify.cns =NVME_ID_CNS_NS_ACTIVE_LIST , + .identify.nsid =cpu_to_le32 (prev), + }; + + ret =nvme_submit_sync_cmd (ctrl->admin_q, &cmd, ns_list, +NVME_IDENTIFY_DATA_SIZE );if (ret) goto free;
Signature · 7 lines
2.28.0 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 20/20] nvme: remove nvme_identify_ns_list
Quoted 3 lines · Christoph Hellwig
Just fold it into the only caller.
Signed-off-by Christoph Hellwig <[email protected]>
Looks good.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
The series looks good to me.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerI've pulled this into nvme-5.10 with the minor cleanups pointed out during review.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme