nvme multipath support V7
Subsystems (2)
Christoph Hellwig
maintainerHi all,
this series adds support for multipathing, that is accessing nvme namespaces through multiple controllers to the nvme core driver.
I think we are pretty much done with with very little changes in the last reposts. Unless I hear objections I plan to send this to Jens tomorrow with the remaining NVMe updates.
It is a very thin and efficient implementation that relies on close cooperation with other bits of the nvme driver, and few small and simple block helpers.
Compared to dm-multipath the important differences are how management of the paths is done, and how the I/O path works.
Management of the paths is fully integrated into the nvme driver, for each newly found nvme controller we check if there are other controllers that refer to the same subsystem, and if so we link them up in the nvme driver. Then for each namespace found we check if the namespace id and identifiers match to check if we have multiple controllers that refer to the same namespaces. For now path availability is based entirely on the controller status, which at least for fabrics will be continuously updated based on the mandatory keep alive timer. Once the Asynchronous Namespace Access (ANA) proposal passes in NVMe we will also get per-namespace states in addition to that, but for now any details of that remain confidential to NVMe members.
The I/O path is very different from the existing multipath drivers, which is enabled by the fact that NVMe (unlike SCSI) does not support partial completions - a controller will either complete a whole command or not, but never only complete parts of it. Because of that there is no need to clone bios or requests - the I/O path simply redirects the I/O to a suitable path. For successful commands multipath is not in the completion stack at all. For failed commands we decide if the error could be a path failure, and if yes remove the bios from the request structure and requeue them before completing the request. All together this means there is no performance degradation compared to normal nvme operation when using the multipath device node (at least not until I find a dual ported DRAM backed device :))
A git tree is available at:
git://git.infradead.org/users/hch/block.git nvme-mpath
gitweb:
http://git.infradead.org/users/hch/block.git/shortlog/refs/heads/nvme-mpath
Changes since V6:
- added slaves/holder directories (Hannes)
- trivial rebase on top of the latest nvme-4.15 changes
Changes since V5:
- dropped various prep patches merged into the nvme tree
- removed a leftover debug printk
- small cleanups to blk_steal_bio
- add a sysfs attribute for hidden gendisks
- don't complete cancelled requests if another path is available
- use the instance index for device naming
- make the multipath code optional at compile time
- don't use the multipath node for single-controller subsystems
- add a module_option to disable multipathing (temporarily)
Changes since V4:
- add a refcount to release the device in struct nvme_subsystem
- use the instance to name the nvme_subsystems in sysfs
- remove a NULL check before nvme_put_ns_head
- take a ns_head reference in ->open
- improve open protection for GENHD_FL_HIDDEN
- add poll support for the mpath device
Changes since V3:
- new block layer support for hidden gendisks
- a couple new patches to refactor device handling before the actual multipath support
- don't expose per-controller block device nodes
- use /dev/nvmeXnZ as the device nodes for the whole subsystem.
- expose subsystems in sysfs (Hannes Reinecke)
- fix a subsystem leak when duplicate NQNs are found
- fix up some names
- don't clear current_path if freeing a different namespace
Changes since V2:
- don't create duplicate subsystems on reset (Keith Bush)
- free requests properly when failing over in I/O completion (Keith Bush)
- new devices names: /dev/nvm-sub%dn%d
- expose the namespace identification sysfs files for the mpath nodes
Changes since V1:
- introduce new nvme_ns_ids structure to clean up identifier handling
- generic_make_request_fast is now named direct_make_request and calls generic_make_request_checks
- reset bi_disk on resubmission
- create sysfs links between the existing nvme namespace block devices and the new share mpath device
- temporarily added the timeout patches from James, this should go into
nvme-4.14, though
Christoph Hellwig
maintainerPATCH 1/7 nvme: track subsystems
This adds a new nvme_subsystem structure so that we can track multiple controllers that belong to a single subsystem. For now we only use it to store the NQN, and to check that we don't have duplicate NQNs unless the involved subsystems support multiple controllers.
Includes code originally from Hannes Reinecke to expose the subsystems in sysfs.
--- drivers/nvme/host/core.c | 210 ++++++++++++++++++++++++++++++++++++++------ drivers/nvme/host/fabrics.c | 4 +- drivers/nvme/host/nvme.h | 27 ++++-- 3 files changed, 205 insertions(+), 36 deletions(-)
drivers/nvme/host/core.c +181 -29
@@ -68,9 +68,14 @@ MODULE_PARM_DESC(streams, "turn on support for Streams write directives");struct workqueue_struct *nvme_wq;EXPORT_SYMBOL_GPL (nvme_wq); +static DEFINE_IDA (nvme_subsystems_ida); +static LIST_HEAD (nvme_subsystems); +static DEFINE_MUTEX (nvme_subsystems_lock); +static DEFINE_IDA (nvme_instance_ida);static dev_t nvme_chr_devt;static struct class *nvme_class; +static struct class *nvme_subsys_class;static void nvme_ns_remove (struct nvme_ns *ns);static int nvme_revalidate_disk (struct gendisk *disk);
@@ -1803,14 +1808,15 @@ static bool quirk_matches(const struct nvme_id_ctrl *id,string_matches (id->fr, q->fr,sizeof (id->fr)); } -static void nvme_init_subnqn (struct nvme_ctrl *ctrl,struct nvme_id_ctrl *id) +static void nvme_init_subnqn (struct nvme_subsystem *subsys,struct nvme_ctrl *ctrl, +struct nvme_id_ctrl *id) {size_t nqnlen;int off; nqnlen =strnlen (id->subnqn,NVMF_NQN_SIZE );if (nqnlen >0 && nqnlen <NVMF_NQN_SIZE ) { -strncpy (ctrl->subnqn, id->subnqn,NVMF_NQN_SIZE ); +strncpy (subsys->subnqn, id->subnqn,NVMF_NQN_SIZE );return ; }
@@ -1818,14 +1824,140 @@ static void nvme_init_subnqn(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)dev_warn (ctrl->device,"missing or invalid SUBNQN field.\n" );/* Generate a "fake" NQN per Figure 254 in NVMe 1.3 + ECN 001 */ - off =snprintf (ctrl->subnqn,NVMF_NQN_SIZE , + off =snprintf (subsys->subnqn,NVMF_NQN_SIZE ,"nqn.2014.08.org.nvmexpress:%4x%4x" ,le16_to_cpu (id->vid),le16_to_cpu (id->ssvid)); -memcpy (ctrl->subnqn + off, id->sn,sizeof (id->sn)); +memcpy (subsys->subnqn + off, id->sn,sizeof (id->sn)); off +=sizeof (id->sn); -memcpy (ctrl->subnqn + off, id->mn,sizeof (id->mn)); +memcpy (subsys->subnqn + off, id->mn,sizeof (id->mn)); off +=sizeof (id->mn); -memset (ctrl->subnqn + off,0 ,sizeof (ctrl->subnqn) - off); +memset (subsys->subnqn + off,0 ,sizeof (subsys->subnqn) - off); +} + +static void __nvme_release_subsystem (struct nvme_subsystem *subsys) +{ +ida_simple_remove (&nvme_subsystems_ida, subsys->instance); +kfree (subsys); +} + +static void nvme_release_subsystem (struct device *dev) +{ +__nvme_release_subsystem (container_of(dev ,struct nvme_subsystem ,dev )); +} + +static void nvme_destroy_subsystem (struct kref *ref) +{ +struct nvme_subsystem *subsys = + container_of(ref, struct nvme_subsystem, ref); + +mutex_lock (&nvme_subsystems_lock); +list_del (&subsys->entry); +mutex_unlock (&nvme_subsystems_lock); + +device_del (&subsys->dev); +put_device (&subsys->dev); +} + +static void nvme_put_subsystem (struct nvme_subsystem *subsys) +{ +kref_put (&subsys->ref, nvme_destroy_subsystem); +} + +static struct nvme_subsystem *__nvme_find_get_subsystem (const char *subsysnqn) +{ +struct nvme_subsystem *subsys; + +lockdep_assert_held (&nvme_subsystems_lock); + +list_for_each_entry (subsys, &nvme_subsystems, entry) { +if (strcmp (subsys->subnqn, subsysnqn)) +continue ; +if (!kref_get_unless_zero (&subsys->ref)) +continue ; +return subsys; + } + +return NULL ; +} + +static int nvme_init_subsystem (struct nvme_ctrl *ctrl,struct nvme_id_ctrl *id) +{ +struct nvme_subsystem *subsys, *found; +int ret; + + subsys =kzalloc (sizeof (*subsys),GFP_KERNEL ); +if (!subsys) +return -ENOMEM ; + ret =ida_simple_get (&nvme_subsystems_ida,0 ,0 ,GFP_KERNEL ); +if (ret <0 ) { +kfree (subsys); +return ret; + } + subsys->instance = ret; +mutex_init (&subsys->lock); +kref_init (&subsys->ref); +INIT_LIST_HEAD (&subsys->ctrls); +nvme_init_subnqn (subsys, ctrl, id); +memcpy (subsys->serial, id->sn,sizeof (subsys->serial)); +memcpy (subsys->model, id->mn,sizeof (subsys->model)); +memcpy (subsys->firmware_rev, id->fr,sizeof (subsys->firmware_rev)); + subsys->vendor_id =le16_to_cpu (id->vid); + subsys->cmic = id->cmic; + + subsys->dev.class = nvme_subsys_class; + subsys->dev.release = nvme_release_subsystem; +dev_set_name (&subsys->dev,"nvme-subsys%d" , subsys->instance); +device_initialize (&subsys->dev); + +mutex_lock (&nvme_subsystems_lock); + found =__nvme_find_get_subsystem (subsys->subnqn); +if (found) { +/* +* Verify that the subsystem actually supports multiple +* controllers, else bail out. +*/ +if (!(id->cmic & (1 <<1 ))) { +dev_err (ctrl->device, +"ignoring ctrl due to duplicate subnqn (%s).\n" , + found->subnqn); +nvme_put_subsystem (found); + ret = -EINVAL ; + goto out_unlock; + } + +__nvme_release_subsystem (subsys); + subsys = found; + }else { + ret =device_add (&subsys->dev); +if (ret) { +dev_err (ctrl->device, +"failed to register subsystem device.\n" ); + goto out_unlock; + } +list_add_tail (&subsys->entry, &nvme_subsystems); + } + + ctrl->subsys = subsys; +mutex_unlock (&nvme_subsystems_lock); + +if (sysfs_create_link (&subsys->dev.kobj, &ctrl->device->kobj, +dev_name (ctrl->device))) { +dev_err (ctrl->device, +"failed to create sysfs link from subsystem.\n" ); +/* the transport driver will eventually put the subsystem */ +return -EINVAL ; + } + +mutex_lock (&subsys->lock); +list_add_tail (&ctrl->subsys_entry, &subsys->ctrls); +mutex_unlock (&subsys->lock); + +return 0 ; + +out_unlock: +mutex_unlock (&nvme_subsystems_lock); +put_device (&subsys->dev); +return ret; } static int nvme_get_log(struct nvme_ctrl *ctrl, u8 log_page, void *log,
@@ -1900,9 +2032,13 @@ int nvme_init_identify(struct nvme_ctrl *ctrl)return ret; } -nvme_init_subnqn (ctrl, id); -if (!ctrl->identified) { +int i; + + ret =nvme_init_subsystem (ctrl, id); +if (ret) + goto out_free; +/* * Check for quirks. Quirk can depend on firmware version, * so, in principle, the set of quirks present can change
@@ -1911,9 +2047,6 @@ int nvme_init_identify(struct nvme_ctrl *ctrl)* the device, but we'd have to make sure that the driver * behaves intelligently if the quirks change. */ - -int i; -for (i =0 ; i <ARRAY_SIZE (core_quirks); i++) {if (quirk_matches (id, &core_quirks[i])) ctrl->quirks |= core_quirks[i].quirks;
@@ -1926,14 +2059,10 @@ int nvme_init_identify(struct nvme_ctrl *ctrl) } ctrl->oacs =le16_to_cpu (id->oacs); - ctrl->vid =le16_to_cpu (id->vid); ctrl->oncs =le16_to_cpup (&id->oncs);atomic_set (&ctrl->abort_limit, id->acl +1 ); ctrl->vwc = id->vwc; ctrl->cntlid =le16_to_cpup (&id->cntlid); -memcpy (ctrl->serial, id->sn,sizeof (id->sn)); -memcpy (ctrl->model, id->mn,sizeof (id->mn)); -memcpy (ctrl->firmware_rev, id->fr,sizeof (id->fr));if (id->mdts) max_hw_sectors =1 << (id->mdts + page_shift -9 );else
@@ -2136,9 +2265,9 @@ static ssize_t wwid_show(struct device *dev, struct device_attribute *attr, char *buf) {struct nvme_ns *ns =nvme_get_ns_from_dev (dev); -struct nvme_ctrl *ctrl = ns->ctrl; -int serial_len =sizeof (ctrl->serial); -int model_len =sizeof (ctrl->model); +struct nvme_subsystem *subsys = ns->ctrl->subsys; +int serial_len =sizeof (subsys->serial); +int model_len =sizeof (subsys->model);if (!uuid_is_null (&ns->uuid))return sprintf (buf,"uuid.%pU\n" , &ns->uuid);
@@ -2149,15 +2278,16 @@ static ssize_t wwid_show(struct device *dev, struct device_attribute *attr,if (memchr_inv (ns->eui,0 ,sizeof (ns->eui)))return sprintf (buf,"eui.%8phN\n" , ns->eui); -while (serial_len >0 && (ctrl->serial[serial_len -1 ] ==' ' || - ctrl->serial[serial_len -1 ] =='\0' )) +while (serial_len >0 && (subsys->serial[serial_len -1 ] ==' ' || + subsys->serial[serial_len -1 ] =='\0' )) serial_len--; -while (model_len >0 && (ctrl->model[model_len -1 ] ==' ' || - ctrl->model[model_len -1 ] =='\0' )) +while (model_len >0 && (subsys->model[model_len -1 ] ==' ' || + subsys->model[model_len -1 ] =='\0' )) model_len--; -return sprintf (buf,"nvme.%04x-%*phN-%*phN-%08x\n" , ctrl->vid, - serial_len, ctrl->serial, model_len, ctrl->model, ns->ns_id); +return sprintf (buf,"nvme.%04x-%*phN-%*phN-%08x\n" , subsys->vendor_id, + serial_len, subsys->serial, model_len, subsys->model, + ns->ns_id); } static DEVICE_ATTR(wwid, S_IRUGO, wwid_show, NULL);
@@ -2243,10 +2373,15 @@ static ssize_t field##_show(struct device *dev, \ struct device_attribute *attr, char *buf) \ { \ struct nvme_ctrl *ctrl = dev_get_drvdata(dev); \ -return sprintf (buf,"%.*s\n" , (int )sizeof (ctrl->field), ctrl->field); \ +return sprintf (buf,"%.*s\n" , \ + (int )sizeof (ctrl->subsys->field), ctrl->subsys->field); \ } \ static DEVICE_ATTR(field, S_IRUGO, field##_show, NULL); +nvme_show_str_function (model); +nvme_show_str_function (serial); +nvme_show_str_function (firmware_rev); +#define nvme_show_int_function (field) \ static ssize_t field##_show(struct device *dev, \ struct device_attribute *attr, char *buf) \
@@ -2256,9 +2391,6 @@ static ssize_t field##_show(struct device *dev, \ } \ static DEVICE_ATTR(field, S_IRUGO, field##_show, NULL); -nvme_show_str_function (model); -nvme_show_str_function (serial); -nvme_show_str_function (firmware_rev);nvme_show_int_function (cntlid); static ssize_t nvme_sysfs_delete(struct device *dev,
@@ -2312,7 +2444,7 @@ static ssize_t nvme_sysfs_show_subsysnqn(struct device *dev, {struct nvme_ctrl *ctrl =dev_get_drvdata (dev); -return snprintf (buf,PAGE_SIZE ,"%s\n" , ctrl->subnqn); +return snprintf (buf,PAGE_SIZE ,"%s\n" , ctrl->subsys->subnqn); } static DEVICE_ATTR(subsysnqn, S_IRUGO, nvme_sysfs_show_subsysnqn, NULL);
@@ -2816,12 +2948,23 @@ static void nvme_free_ctrl(struct device *dev) {struct nvme_ctrl *ctrl = container_of(dev, struct nvme_ctrl, ctrl_device); +struct nvme_subsystem *subsys = ctrl->subsys;ida_simple_remove (&nvme_instance_ida, ctrl->instance);ida_destroy (&ctrl->ns_ida);kfree (ctrl->effects); +if (subsys) { +mutex_lock (&subsys->lock); +list_del (&ctrl->subsys_entry); +mutex_unlock (&subsys->lock); +sysfs_remove_link (&subsys->dev.kobj,dev_name (ctrl->device)); + } + ctrl->ops->free_ctrl (ctrl); + +if (subsys) +nvme_put_subsystem (subsys); }/*
@@ -3021,8 +3164,15 @@ int __init nvme_core_init(void) goto unregister_chrdev; } + nvme_subsys_class =class_create (THIS_MODULE ,"nvme-subsystem" ); +if (IS_ERR (nvme_subsys_class)) { + result =PTR_ERR (nvme_subsys_class); + goto destroy_class; + }return 0 ; +destroy_class: +class_destroy (nvme_class); unregister_chrdev:unregister_chrdev_region (nvme_chr_devt,NVME_MINORS ); destroy_wq:
@@ -3032,6 +3182,8 @@ int __init nvme_core_init(void)void nvme_core_exit (void ) { +ida_destroy (&nvme_subsystems_ida); +class_destroy (nvme_subsys_class);class_destroy (nvme_class);unregister_chrdev_region (nvme_chr_devt,NVME_MINORS );destroy_workqueue (nvme_wq);
drivers/nvme/host/fabrics.c +2 -2
@@ -882,10 +882,10 @@ nvmf_create_ctrl(struct device *dev, const char *buf, size_t count) goto out_unlock; } -if (strcmp (ctrl->subnqn, opts->subsysnqn)) { +if (strcmp (ctrl->subsys->subnqn, opts->subsysnqn)) {dev_warn (ctrl->device,"controller returned incorrect NQN: \"%s\".\n" , - ctrl->subnqn); + ctrl->subsys->subnqn);up_read (&nvmf_transports_rwsem);nvme_delete_ctrl_sync (ctrl);return ERR_PTR (-EINVAL );
drivers/nvme/host/nvme.h +22 -5
@@ -140,13 +140,12 @@ struct nvme_ctrl {struct work_struct reset_work;struct work_struct delete_work; +struct nvme_subsystem *subsys; +struct list_head subsys_entry; +struct opal_dev *opal_dev;char name[12 ]; -char serial[20 ]; -char model[40 ]; -char firmware_rev[8 ]; -char subnqn[NVMF_NQN_SIZE ];u16 cntlid;u32 ctrl_config;
@@ -157,7 +156,6 @@ struct nvme_ctrl {u32 page_size;u32 max_hw_sectors;u16 oncs; -u16 vid;u16 oacs;u16 nssa;u16 nr_streams;
@@ -200,6 +198,25 @@ struct nvme_ctrl {struct nvmf_ctrl_options *opts; }; +struct nvme_subsystem { +int instance; +struct device dev; +/* +* Because we unregister the device on the last put we need +* a separate refcount. +*/ +struct kref ref; +struct list_head entry; +struct mutex lock; +struct list_head ctrls; +char subnqn[NVMF_NQN_SIZE ]; +char serial[20 ]; +char model[40 ]; +char firmware_rev[8 ]; +u8 cmic; +u16 vendor_id; +}; +struct nvme_ns {struct list_head list;
Signature · 1 line
2.14.2
Re: [PATCH 1/7] nvme: track subsystems
Christoph,
Quoted 7 lines
This adds a new
nvme_subsystemstructure so that we can track multiple controllers that belong to a single subsystem. For now we only use it to store the NQN, and to check that we don't have duplicate NQNs unless the involved subsystems support multiple controllers.Includes code originally from Hannes Reinecke to expose the subsystems in sysfs.
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Christoph Hellwig
maintainerPATCH 2/7 nvme: introduce a nvme_ns_ids structure
In reply to Christoph HellwigThis allows us to manage the various uniqueue namespace identifiers together instead needing various variables and arguments.
--- drivers/nvme/host/core.c | 69 +++++++++++++++++++++++++++--------------------- drivers/nvme/host/nvme.h | 14 +++++++--- 2 files changed, 49 insertions(+), 34 deletions(-)
drivers/nvme/host/core.c +39 -30
@@ -796,7 +796,7 @@ static int nvme_identify_ctrl(struct nvme_ctrl *dev, struct nvme_id_ctrl **id) }static int nvme_identify_ns_descs (struct nvme_ctrl *ctrl,unsigned nsid, -u8 *eui64,u8 *nguid,uuid_t *uuid) +struct nvme_ns_ids *ids) {struct nvme_command c = { };int status;
@@ -832,7 +832,7 @@ static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl, unsigned nsid, goto free_data; } len =NVME_NIDT_EUI64_LEN ; -memcpy (eui64, data + pos +sizeof (*cur), len); +memcpy (ids->eui64, data + pos +sizeof (*cur), len);break ;case NVME_NIDT_NGUID :if (cur->nidl !=NVME_NIDT_NGUID_LEN ) {
@@ -842,7 +842,7 @@ static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl, unsigned nsid, goto free_data; } len =NVME_NIDT_NGUID_LEN ; -memcpy (nguid, data + pos +sizeof (*cur), len); +memcpy (ids->nguid, data + pos +sizeof (*cur), len);break ;case NVME_NIDT_UUID :if (cur->nidl !=NVME_NIDT_UUID_LEN ) {
@@ -852,7 +852,7 @@ static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl, unsigned nsid, goto free_data; } len =NVME_NIDT_UUID_LEN ; -uuid_copy (uuid, data + pos +sizeof (*cur)); +uuid_copy (&ids->uuid, data + pos +sizeof (*cur));break ;default :/* Skip unnkown types */
@@ -1232,22 +1232,31 @@ static void nvme_config_discard(struct nvme_ctrl *ctrl, }static void nvme_report_ns_ids (struct nvme_ctrl *ctrl,unsigned int nsid, -struct nvme_id_ns *id,u8 *eui64,u8 *nguid,uuid_t *uuid) +struct nvme_id_ns *id,struct nvme_ns_ids *ids) { +memset (ids,0 ,sizeof (*ids)); +if (ctrl->vs >=NVME_VS (1 ,1 ,0 )) -memcpy (eui64, id->eui64,sizeof (id->eui64)); +memcpy (ids->eui64, id->eui64,sizeof (id->eui64));if (ctrl->vs >=NVME_VS (1 ,2 ,0 )) -memcpy (nguid, id->nguid,sizeof (id->nguid)); +memcpy (ids->nguid, id->nguid,sizeof (id->nguid));if (ctrl->vs >=NVME_VS (1 ,3 ,0 )) {/* Don't treat error as fatal we potentially * already have a NGUID or EUI-64 */ -if (nvme_identify_ns_descs (ctrl, nsid, eui64, nguid, uuid)) +if (nvme_identify_ns_descs (ctrl, nsid, ids))dev_warn (ctrl->device,"%s: Identify Descriptors failed\n" , __func__); } } +static bool nvme_ns_ids_equal (struct nvme_ns_ids *a,struct nvme_ns_ids *b) +{ +return uuid_equal (&a->uuid, &b->uuid) && +memcmp (&a->nguid, &b->nguid,sizeof (a->nguid)) ==0 && +memcmp (&a->eui64, &b->eui64,sizeof (a->eui64)) ==0 ; +} +static void nvme_update_disk_info (struct gendisk *disk,struct nvme_ns *ns,struct nvme_id_ns *id) {
@@ -1303,8 +1312,7 @@ static int nvme_revalidate_disk(struct gendisk *disk)struct nvme_ns *ns = disk->private_data;struct nvme_ctrl *ctrl = ns->ctrl;struct nvme_id_ns *id; -u8 eui64[8 ] = {0 }, nguid[16 ] = {0 }; -uuid_t uuid = uuid_null; +struct nvme_ns_ids ids;int ret =0 ;if (test_bit (NVME_NS_DEAD , &ns->flags)) {
@@ -1321,10 +1329,8 @@ static int nvme_revalidate_disk(struct gendisk *disk) goto out; } -nvme_report_ns_ids (ctrl, ns->ns_id, id, eui64, nguid, &uuid); -if (!uuid_equal (&ns->uuid, &uuid) || -memcmp (&ns->nguid, &nguid,sizeof (ns->nguid)) || -memcmp (&ns->eui, &eui64,sizeof (ns->eui))) { +nvme_report_ns_ids (ctrl, ns->ns_id, id, &ids); +if (!nvme_ns_ids_equal (&ns->ids, &ids)) {dev_err (ctrl->device,"identifiers changed for nsid %d\n" , ns->ns_id); ret = -ENODEV ;
@@ -2265,18 +2271,19 @@ static ssize_t wwid_show(struct device *dev, struct device_attribute *attr, char *buf) {struct nvme_ns *ns =nvme_get_ns_from_dev (dev); +struct nvme_ns_ids *ids = &ns->ids;struct nvme_subsystem *subsys = ns->ctrl->subsys;int serial_len =sizeof (subsys->serial);int model_len =sizeof (subsys->model); -if (!uuid_is_null (&ns->uuid)) -return sprintf (buf,"uuid.%pU\n" , &ns->uuid); +if (!uuid_is_null (&ids->uuid)) +return sprintf (buf,"uuid.%pU\n" , &ids->uuid); -if (memchr_inv (ns->nguid,0 ,sizeof (ns->nguid))) -return sprintf (buf,"eui.%16phN\n" , ns->nguid); +if (memchr_inv (ids->nguid,0 ,sizeof (ids->nguid))) +return sprintf (buf,"eui.%16phN\n" , ids->nguid); -if (memchr_inv (ns->eui,0 ,sizeof (ns->eui))) -return sprintf (buf,"eui.%8phN\n" , ns->eui); +if (memchr_inv (ids->eui64,0 ,sizeof (ids->eui64))) +return sprintf (buf,"eui.%8phN\n" , ids->eui64);while (serial_len >0 && (subsys->serial[serial_len -1 ] ==' ' || subsys->serial[serial_len -1 ] =='\0' ))
@@ -2295,7 +2302,7 @@ static ssize_t nguid_show(struct device *dev, struct device_attribute *attr, char *buf) {struct nvme_ns *ns =nvme_get_ns_from_dev (dev); -return sprintf (buf,"%pU\n" , ns->nguid); +return sprintf (buf,"%pU\n" , ns->ids.nguid); } static DEVICE_ATTR(nguid, S_IRUGO, nguid_show, NULL);
@@ -2303,16 +2310,17 @@ static ssize_t uuid_show(struct device *dev, struct device_attribute *attr, char *buf) {struct nvme_ns *ns =nvme_get_ns_from_dev (dev); +struct nvme_ns_ids *ids = &ns->ids;/* For backward compatibility expose the NGUID to userspace if * we have no UUID set */ -if (uuid_is_null (&ns->uuid)) { +if (uuid_is_null (&ids->uuid)) {printk_ratelimited (KERN_WARNING "No UUID available providing old NGUID\n" ); -return sprintf (buf,"%pU\n" , ns->nguid); +return sprintf (buf,"%pU\n" , ids->nguid); } -return sprintf (buf,"%pU\n" , &ns->uuid); +return sprintf (buf,"%pU\n" , &ids->uuid); } static DEVICE_ATTR(uuid, S_IRUGO, uuid_show, NULL);
@@ -2320,7 +2328,7 @@ static ssize_t eui_show(struct device *dev, struct device_attribute *attr, char *buf) {struct nvme_ns *ns =nvme_get_ns_from_dev (dev); -return sprintf (buf,"%8ph\n" , ns->eui); +return sprintf (buf,"%8ph\n" , ns->ids.eui64); } static DEVICE_ATTR(eui, S_IRUGO, eui_show, NULL);
@@ -2346,18 +2354,19 @@ static umode_t nvme_ns_attrs_are_visible(struct kobject *kobj, { struct device *dev = container_of(kobj, struct device, kobj);struct nvme_ns *ns =nvme_get_ns_from_dev (dev); +struct nvme_ns_ids *ids = &ns->ids;if (a == &dev_attr_uuid.attr) { -if (uuid_is_null (&ns->uuid) || - !memchr_inv (ns->nguid,0 ,sizeof (ns->nguid))) +if (uuid_is_null (&ids->uuid) || + !memchr_inv (ids->nguid,0 ,sizeof (ids->nguid)))return 0 ; }if (a == &dev_attr_nguid.attr) { -if (!memchr_inv (ns->nguid,0 ,sizeof (ns->nguid))) +if (!memchr_inv (ids->nguid,0 ,sizeof (ids->nguid)))return 0 ; }if (a == &dev_attr_eui.attr) { -if (!memchr_inv (ns->eui,0 ,sizeof (ns->eui))) +if (!memchr_inv (ids->eui64,0 ,sizeof (ids->eui64)))return 0 ; }return a->mode;
@@ -2590,7 +2599,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)if (id->ncap ==0 ) goto out_free_id; -nvme_report_ns_ids (ctrl, ns->ns_id, id, ns->eui, ns->nguid, &ns->uuid); +nvme_report_ns_ids (ctrl, ns->ns_id, id, &ns->ids);if ((ctrl->quirks &NVME_QUIRK_LIGHTNVM ) && id->vs[0 ] ==0x1 ) {if (nvme_nvm_register (ns, disk_name, node)) {
drivers/nvme/host/nvme.h +10 -4
@@ -217,6 +217,15 @@ struct nvme_subsystem {u16 vendor_id; }; +/* +* Container structure for uniqueue namespace identifiers. +*/ +struct nvme_ns_ids { +u8 eui64[8 ]; +u8 nguid[16 ]; +uuid_t uuid; +}; +struct nvme_ns {struct list_head list;
@@ -227,11 +236,8 @@ struct nvme_ns {struct kref kref;int instance; -u8 eui[8 ]; -u8 nguid[16 ]; -uuid_t uuid; -unsigned ns_id; +struct nvme_ns_ids ids;int lba_shift;u16 ms;u16 sgs;
Signature · 1 line
2.14.2
Re: [PATCH 2/7] nvme: introduce a nvme_ns_ids structure
Christoph,
Quoted 2 lines
This allows us to manage the various uniqueue namespace identifiers together instead needing various variables and arguments.
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Christoph Hellwig
maintainerPATCH 3/7 nvme: track shared namespaces
In reply to Christoph HellwigIntroduce a new struct nvme_ns_head that holds information about an actual namespace, unlike struct nvme_ns, which only holds the per-controller namespace information. For private namespaces there is a 1:1 relation of the two, but for shared namespaces this lets us discover all the paths to it. For now only the identifiers are moved to the new structure, but most of the information in struct nvme_ns should eventually move over.
To allow lockless path lookup the list of nvme_ns structures per nvme_ns_head is protected by SRCU, which requires freeing the nvme_ns structure through call_srcu.
--- drivers/nvme/host/core.c | 220 +++++++++++++++++++++++++++++++++++-------- drivers/nvme/host/lightnvm.c | 14 +-- drivers/nvme/host/nvme.h | 26 ++++- 3 files changed, 210 insertions(+), 50 deletions(-)
drivers/nvme/host/core.c +181 -39
@@ -291,6 +291,22 @@ bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl, }EXPORT_SYMBOL_GPL (nvme_change_ctrl_state); +static void nvme_free_ns_head (struct kref *ref) +{ +struct nvme_ns_head *head = + container_of(ref, struct nvme_ns_head, ref); + +ida_simple_remove (&head->subsys->ns_ida, head->instance); +list_del_init (&head->entry); +cleanup_srcu_struct (&head->srcu); +kfree (head); +} + +static void nvme_put_ns_head (struct nvme_ns_head *head) +{ +kref_put (&head->ref, nvme_free_ns_head); +} +static void nvme_free_ns (struct kref *kref) { struct nvme_ns *ns = container_of(kref, struct nvme_ns, kref);
@@ -299,7 +315,7 @@ static void nvme_free_ns(struct kref *kref)nvme_nvm_unregister (ns);put_disk (ns->disk); -ida_simple_remove (&ns->ctrl->ns_ida, ns->instance); +nvme_put_ns_head (ns->head);nvme_put_ctrl (ns->ctrl);kfree (ns); }
@@ -435,7 +451,7 @@ static inline void nvme_setup_flush(struct nvme_ns *ns, {memset (cmnd,0 ,sizeof (*cmnd)); cmnd->common.opcode = nvme_cmd_flush; - cmnd->common.nsid =cpu_to_le32 (ns->ns_id); + cmnd->common.nsid =cpu_to_le32 (ns->head->ns_id); } static blk_status_t nvme_setup_discard(struct nvme_ns *ns, struct request *req,
@@ -466,7 +482,7 @@ static blk_status_t nvme_setup_discard(struct nvme_ns *ns, struct request *req,memset (cmnd,0 ,sizeof (*cmnd)); cmnd->dsm.opcode = nvme_cmd_dsm; - cmnd->dsm.nsid =cpu_to_le32 (ns->ns_id); + cmnd->dsm.nsid =cpu_to_le32 (ns->head->ns_id); cmnd->dsm.nr =cpu_to_le32 (segments -1 ); cmnd->dsm.attributes =cpu_to_le32 (NVME_DSMGMT_AD );
@@ -495,7 +511,7 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns,memset (cmnd,0 ,sizeof (*cmnd)); cmnd->rw.opcode = (rq_data_dir (req) ? nvme_cmd_write : nvme_cmd_read); - cmnd->rw.nsid =cpu_to_le32 (ns->ns_id); + cmnd->rw.nsid =cpu_to_le32 (ns->head->ns_id); cmnd->rw.slba =cpu_to_le64 (nvme_block_nr (ns,blk_rq_pos (req))); cmnd->rw.length =cpu_to_le16 ((blk_rq_bytes (req) >> ns->lba_shift) -1 );
@@ -986,7 +1002,7 @@ static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio)memset (&c,0 ,sizeof (c)); c.rw.opcode = io.opcode; c.rw.flags = io.flags; - c.rw.nsid =cpu_to_le32 (ns->ns_id); + c.rw.nsid =cpu_to_le32 (ns->head->ns_id); c.rw.slba =cpu_to_le64 (io.slba); c.rw.length =cpu_to_le16 (io.nblocks); c.rw.control =cpu_to_le16 (io.control);
@@ -1129,7 +1145,7 @@ static int nvme_ioctl(struct block_device *bdev, fmode_t mode,switch (cmd) {case NVME_IOCTL_ID :force_successful_syscall_return (); -return ns->ns_id; +return ns->head->ns_id;case NVME_IOCTL_ADMIN_CMD :return nvme_user_cmd (ns->ctrl,NULL , (void __user *)arg);case NVME_IOCTL_IO_CMD :
@@ -1250,6 +1266,13 @@ static void nvme_report_ns_ids(struct nvme_ctrl *ctrl, unsigned int nsid, } } +static bool nvme_ns_ids_valid (struct nvme_ns_ids *ids) +{ +return !uuid_is_null (&ids->uuid) || +memchr_inv (ids->nguid,0 ,sizeof (ids->nguid)) || +memchr_inv (ids->eui64,0 ,sizeof (ids->eui64)); +} +static bool nvme_ns_ids_equal (struct nvme_ns_ids *a,struct nvme_ns_ids *b) { return uuid_equal(&a->uuid, &b->uuid) &&
@@ -1320,7 +1343,7 @@ static int nvme_revalidate_disk(struct gendisk *disk)return -ENODEV ; } - id =nvme_identify_ns (ctrl, ns->ns_id); + id =nvme_identify_ns (ctrl, ns->head->ns_id);if (!id)return -ENODEV ;
@@ -1329,10 +1352,10 @@ static int nvme_revalidate_disk(struct gendisk *disk) goto out; } -nvme_report_ns_ids (ctrl, ns->ns_id, id, &ids); -if (!nvme_ns_ids_equal (&ns->ids, &ids)) { +nvme_report_ns_ids (ctrl, ns->head->ns_id, id, &ids); +if (!nvme_ns_ids_equal (&ns->head->ids, &ids)) {dev_err (ctrl->device, -"identifiers changed for nsid %d\n" , ns->ns_id); +"identifiers changed for nsid %d\n" , ns->head->ns_id); ret = -ENODEV ; }
@@ -1373,7 +1396,7 @@ static int nvme_pr_command(struct block_device *bdev, u32 cdw10,memset (&c,0 ,sizeof (c)); c.common.opcode = op; - c.common.nsid =cpu_to_le32 (ns->ns_id); + c.common.nsid =cpu_to_le32 (ns->head->ns_id); c.common.cdw10[0 ] =cpu_to_le32 (cdw10);return nvme_submit_sync_cmd (ns->queue, &c, data,16 );
@@ -1860,6 +1883,7 @@ static void nvme_destroy_subsystem(struct kref *ref)list_del (&subsys->entry);mutex_unlock (&nvme_subsystems_lock); +ida_destroy (&subsys->ns_ida);device_del (&subsys->dev);put_device (&subsys->dev); }
@@ -1903,6 +1927,7 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)mutex_init (&subsys->lock);kref_init (&subsys->ref);INIT_LIST_HEAD (&subsys->ctrls); +INIT_LIST_HEAD (&subsys->nsheads);nvme_init_subnqn (subsys, ctrl, id);memcpy (subsys->serial, id->sn,sizeof (subsys->serial));memcpy (subsys->model, id->mn,sizeof (subsys->model));
@@ -1940,6 +1965,7 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) "failed to register subsystem device.\n"); goto out_unlock; } +ida_init (&subsys->ns_ida);list_add_tail (&subsys->entry, &nvme_subsystems); }
@@ -2271,7 +2297,7 @@ static ssize_t wwid_show(struct device *dev, struct device_attribute *attr, char *buf) {struct nvme_ns *ns =nvme_get_ns_from_dev (dev); -struct nvme_ns_ids *ids = &ns->ids; +struct nvme_ns_ids *ids = &ns->head->ids;struct nvme_subsystem *subsys = ns->ctrl->subsys;int serial_len =sizeof (subsys->serial);int model_len =sizeof (subsys->model);
@@ -2294,7 +2320,7 @@ static ssize_t wwid_show(struct device *dev, struct device_attribute *attr,return sprintf (buf,"nvme.%04x-%*phN-%*phN-%08x\n" , subsys->vendor_id, serial_len, subsys->serial, model_len, subsys->model, - ns->ns_id); + ns->head->ns_id); } static DEVICE_ATTR(wwid, S_IRUGO, wwid_show, NULL);
@@ -2302,7 +2328,7 @@ static ssize_t nguid_show(struct device *dev, struct device_attribute *attr, char *buf) {struct nvme_ns *ns =nvme_get_ns_from_dev (dev); -return sprintf (buf,"%pU\n" , ns->ids.nguid); +return sprintf (buf,"%pU\n" , ns->head->ids.nguid); } static DEVICE_ATTR(nguid, S_IRUGO, nguid_show, NULL);
@@ -2310,7 +2336,7 @@ static ssize_t uuid_show(struct device *dev, struct device_attribute *attr, char *buf) {struct nvme_ns *ns =nvme_get_ns_from_dev (dev); -struct nvme_ns_ids *ids = &ns->ids; +struct nvme_ns_ids *ids = &ns->head->ids;/* For backward compatibility expose the NGUID to userspace if * we have no UUID set
@@ -2328,7 +2354,7 @@ static ssize_t eui_show(struct device *dev, struct device_attribute *attr, char *buf) {struct nvme_ns *ns =nvme_get_ns_from_dev (dev); -return sprintf (buf,"%8ph\n" , ns->ids.eui64); +return sprintf (buf,"%8ph\n" , ns->head->ids.eui64); } static DEVICE_ATTR(eui, S_IRUGO, eui_show, NULL);
@@ -2336,7 +2362,7 @@ static ssize_t nsid_show(struct device *dev, struct device_attribute *attr, char *buf) {struct nvme_ns *ns =nvme_get_ns_from_dev (dev); -return sprintf (buf,"%d\n" , ns->ns_id); +return sprintf (buf,"%d\n" , ns->head->ns_id); } static DEVICE_ATTR(nsid, S_IRUGO, nsid_show, NULL);
@@ -2354,7 +2380,7 @@ static umode_t nvme_ns_attrs_are_visible(struct kobject *kobj, { struct device *dev = container_of(kobj, struct device, kobj);struct nvme_ns *ns =nvme_get_ns_from_dev (dev); -struct nvme_ns_ids *ids = &ns->ids; +struct nvme_ns_ids *ids = &ns->head->ids;if (a == &dev_attr_uuid.attr) { if (uuid_is_null(&ids->uuid) ||
@@ -2506,12 +2532,124 @@ static const struct attribute_group *nvme_dev_attr_groups[] = { NULL, }; +static struct nvme_ns_head *__nvme_find_ns_head (struct nvme_subsystem *subsys, +unsigned nsid) +{ +struct nvme_ns_head *h; + +lockdep_assert_held (&subsys->lock); + +list_for_each_entry (h, &subsys->nsheads, entry) { +if (h->ns_id == nsid &&kref_get_unless_zero (&h->ref)) +return h; + } + +return NULL ; +} + +static int __nvme_check_ids (struct nvme_subsystem *subsys, +struct nvme_ns_head *new) +{ +struct nvme_ns_head *h; + +lockdep_assert_held (&subsys->lock); + +list_for_each_entry (h, &subsys->nsheads, entry) { +if (nvme_ns_ids_valid (&new->ids) && +nvme_ns_ids_equal (&new->ids, &h->ids)) +return -EINVAL ; + } + +return 0 ; +} + +static struct nvme_ns_head *nvme_alloc_ns_head (struct nvme_ctrl *ctrl, +unsigned nsid,struct nvme_id_ns *id) +{ +struct nvme_ns_head *head; +int ret = -ENOMEM ; + + head =kzalloc (sizeof (*head),GFP_KERNEL ); +if (!head) + goto out; + ret =ida_simple_get (&ctrl->subsys->ns_ida,1 ,0 ,GFP_KERNEL ); +if (ret <0 ) + goto out_free_head; + head->instance = ret; +INIT_LIST_HEAD (&head->list); +init_srcu_struct (&head->srcu); + head->subsys = ctrl->subsys; + head->ns_id = nsid; +kref_init (&head->ref); + +nvme_report_ns_ids (ctrl, nsid, id, &head->ids); + + ret =__nvme_check_ids (ctrl->subsys, head); +if (ret) { +dev_err (ctrl->device, +"duplicate IDs for nsid %d\n" , nsid); + goto out_cleanup_srcu; + } + +list_add_tail (&head->entry, &ctrl->subsys->nsheads); +return head; +out_cleanup_srcu: +cleanup_srcu_struct (&head->srcu); +ida_simple_remove (&ctrl->subsys->ns_ida, head->instance); +out_free_head: +kfree (head); +out: +return ERR_PTR (ret); +} + +static int nvme_init_ns_head (struct nvme_ns *ns,unsigned nsid, +struct nvme_id_ns *id,bool *new) +{ +struct nvme_ctrl *ctrl = ns->ctrl; +bool is_shared = id->nmic & (1 <<0 ); +struct nvme_ns_head *head =NULL ; +int ret =0 ; + +mutex_lock (&ctrl->subsys->lock); +if (is_shared) + head =__nvme_find_ns_head (ctrl->subsys, nsid); +if (!head) { + head =nvme_alloc_ns_head (ctrl, nsid, id); +if (IS_ERR (head)) { + ret =PTR_ERR (head); + goto out_unlock; + } + + *new = true; + }else { +struct nvme_ns_ids ids; + +nvme_report_ns_ids (ctrl, nsid, id, &ids); +if (!nvme_ns_ids_equal (&head->ids, &ids)) { +dev_err (ctrl->device, +"IDs don't match for shared namespace %d\n" , + nsid); + ret = -EINVAL ; + goto out_unlock; + } + + *new = false; + } + +list_add_tail (&ns->siblings, &head->list); + ns->head = head; + +out_unlock: +mutex_unlock (&ctrl->subsys->lock); +return ret; +} +static int ns_cmp (void *priv,struct list_head *a,struct list_head *b) { struct nvme_ns *nsa = container_of(a, struct nvme_ns, list); struct nvme_ns *nsb = container_of(b, struct nvme_ns, list); -return nsa->ns_id - nsb->ns_id; +return nsa->head->ns_id - nsb->head->ns_id; }static struct nvme_ns *nvme_find_get_ns (struct nvme_ctrl *ctrl,unsigned nsid)
@@ -2520,13 +2658,13 @@ static struct nvme_ns *nvme_find_get_ns(struct nvme_ctrl *ctrl, unsigned nsid)mutex_lock (&ctrl->namespaces_mutex);list_for_each_entry (ns, &ctrl->namespaces, list) { -if (ns->ns_id == nsid) { +if (ns->head->ns_id == nsid) {if (!kref_get_unless_zero (&ns->kref))continue ; ret = ns;break ; } -if (ns->ns_id > nsid) +if (ns->head->ns_id > nsid)break ; }mutex_unlock (&ctrl->namespaces_mutex);
@@ -2541,7 +2679,7 @@ static int nvme_setup_streams_ns(struct nvme_ctrl *ctrl, struct nvme_ns *ns)if (!ctrl->nr_streams)return 0 ; - ret =nvme_get_stream_params (ctrl, &s, ns->ns_id); + ret =nvme_get_stream_params (ctrl, &s, ns->head->ns_id);if (ret)return ret;
@@ -2566,32 +2704,26 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)struct nvme_id_ns *id;char disk_name[DISK_NAME_LEN ];int node =dev_to_node (ctrl->dev); +bool new = true; ns =kzalloc_node (sizeof (*ns),GFP_KERNEL , node);if (!ns)return ; - ns->instance =ida_simple_get (&ctrl->ns_ida,1 ,0 ,GFP_KERNEL ); -if (ns->instance <0 ) - goto out_free_ns; - ns->queue =blk_mq_init_queue (ctrl->tagset);if (IS_ERR (ns->queue)) - goto out_release_instance; + goto out_free_ns;queue_flag_set_unlocked (QUEUE_FLAG_NONROT , ns->queue); ns->queue->queuedata = ns; ns->ctrl = ctrl;kref_init (&ns->kref); - ns->ns_id = nsid; 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);nvme_setup_streams_ns (ctrl, ns); -sprintf (disk_name,"nvme%dn%d" , ctrl->instance, ns->instance); - id =nvme_identify_ns (ctrl, nsid);if (!id) goto out_free_queue;
@@ -2599,18 +2731,21 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)if (id->ncap ==0 ) goto out_free_id; -nvme_report_ns_ids (ctrl, ns->ns_id, id, &ns->ids); +if (nvme_init_ns_head (ns, nsid, id, &new)) + goto out_free_id; + +sprintf (disk_name,"nvme%dn%d" , ctrl->instance, ns->head->instance);if ((ctrl->quirks &NVME_QUIRK_LIGHTNVM ) && id->vs[0 ] ==0x1 ) {if (nvme_nvm_register (ns, disk_name, node)) {dev_warn (ctrl->device,"LightNVM init failure\n" ); - goto out_free_id; + goto out_unlink_ns; } } disk =alloc_disk_node (0 , node);if (!disk) - goto out_free_id; + goto out_unlink_ns; disk->fops = &nvme_fops; disk->private_data = ns;
@@ -2638,18 +2773,22 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)pr_warn ("%s: failed to register lightnvm sysfs group for identification\n" , ns->disk->disk_name);return ; + out_unlink_ns: +mutex_lock (&ctrl->subsys->lock); +list_del_rcu (&ns->siblings); +mutex_unlock (&ctrl->subsys->lock); out_free_id:kfree (id); out_free_queue:blk_cleanup_queue (ns->queue); - out_release_instance: -ida_simple_remove (&ctrl->ns_ida, ns->instance); out_free_ns:kfree (ns); }static void nvme_ns_remove (struct nvme_ns *ns) { +struct nvme_ns_head *head = ns->head; +if (test_and_set_bit (NVME_NS_REMOVING , &ns->flags))return ;
@@ -2664,10 +2803,16 @@ static void nvme_ns_remove(struct nvme_ns *ns)blk_cleanup_queue (ns->queue); } +mutex_lock (&ns->ctrl->subsys->lock); +if (head) +list_del_rcu (&ns->siblings); +mutex_unlock (&ns->ctrl->subsys->lock); +mutex_lock (&ns->ctrl->namespaces_mutex);list_del_init (&ns->list);mutex_unlock (&ns->ctrl->namespaces_mutex); +synchronize_srcu (&head->srcu);nvme_put_ns (ns); }
@@ -2690,7 +2835,7 @@ static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl,struct nvme_ns *ns, *next;list_for_each_entry_safe (ns, next, &ctrl->namespaces, list) { -if (ns->ns_id > nsid) +if (ns->head->ns_id > nsid)nvme_ns_remove (ns); } }
@@ -2960,7 +3105,6 @@ static void nvme_free_ctrl(struct device *dev)struct nvme_subsystem *subsys = ctrl->subsys;ida_simple_remove (&nvme_instance_ida, ctrl->instance); -ida_destroy (&ctrl->ns_ida);kfree (ctrl->effects);if (subsys) {
@@ -3021,8 +3165,6 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,if (ret) goto out_free_name; -ida_init (&ctrl->ns_ida); -/* * Initialize latency tolerance controls. The sysfs files won't * be visible to userspace unless the device actually supports APST.
drivers/nvme/host/lightnvm.c +7 -7
@@ -305,7 +305,7 @@ static int nvme_nvm_identity(struct nvm_dev *nvmdev, struct nvm_id *nvm_id)int ret; c.identity.opcode = nvme_nvm_admin_identity; - c.identity.nsid =cpu_to_le32 (ns->ns_id); + c.identity.nsid =cpu_to_le32 (ns->head->ns_id); c.identity.chnl_off =0 ; nvme_nvm_id =kmalloc (sizeof (struct nvme_nvm_id ),GFP_KERNEL );
@@ -344,7 +344,7 @@ static int nvme_nvm_get_l2p_tbl(struct nvm_dev *nvmdev, u64 slba, u32 nlb,int ret =0 ; c.l2p.opcode = nvme_nvm_admin_get_l2p_tbl; - c.l2p.nsid =cpu_to_le32 (ns->ns_id); + c.l2p.nsid =cpu_to_le32 (ns->head->ns_id); entries =kmalloc (len,GFP_KERNEL );if (!entries)return -ENOMEM ;
@@ -402,7 +402,7 @@ static int nvme_nvm_get_bb_tbl(struct nvm_dev *nvmdev, struct ppa_addr ppa,int ret =0 ; c.get_bb.opcode = nvme_nvm_admin_get_bb_tbl; - c.get_bb.nsid =cpu_to_le32 (ns->ns_id); + c.get_bb.nsid =cpu_to_le32 (ns->head->ns_id); c.get_bb.spba =cpu_to_le64 (ppa.ppa); bb_tbl =kzalloc (tblsz,GFP_KERNEL );
@@ -452,7 +452,7 @@ static int nvme_nvm_set_bb_tbl(struct nvm_dev *nvmdev, struct ppa_addr *ppas,int ret =0 ; c.set_bb.opcode = nvme_nvm_admin_set_bb_tbl; - c.set_bb.nsid =cpu_to_le32 (ns->ns_id); + c.set_bb.nsid =cpu_to_le32 (ns->head->ns_id); c.set_bb.spba =cpu_to_le64 (ppas->ppa); c.set_bb.nlb =cpu_to_le16 (nr_ppas -1 ); c.set_bb.value = type;
@@ -469,7 +469,7 @@ static inline void nvme_nvm_rqtocmd(struct nvm_rq *rqd, struct nvme_ns *ns, struct nvme_nvm_command *c) { c->ph_rw.opcode = rqd->opcode; - c->ph_rw.nsid =cpu_to_le32 (ns->ns_id); + c->ph_rw.nsid =cpu_to_le32 (ns->head->ns_id); c->ph_rw.spba =cpu_to_le64 (rqd->ppa_addr.ppa); c->ph_rw.metadata =cpu_to_le64 (rqd->dma_meta_list); c->ph_rw.control =cpu_to_le16 (rqd->flags);
@@ -731,7 +731,7 @@ static int nvme_nvm_submit_vio(struct nvme_ns *ns,memset (&c,0 ,sizeof (c)); c.ph_rw.opcode = vio.opcode; - c.ph_rw.nsid =cpu_to_le32 (ns->ns_id); + c.ph_rw.nsid =cpu_to_le32 (ns->head->ns_id); c.ph_rw.control =cpu_to_le16 (vio.control); c.ph_rw.length =cpu_to_le16 (vio.nppas);
@@ -768,7 +768,7 @@ static int nvme_nvm_user_vcmd(struct nvme_ns *ns, int admin,memset (&c,0 ,sizeof (c)); c.common.opcode = vcmd.opcode; - c.common.nsid =cpu_to_le32 (ns->ns_id); + c.common.nsid =cpu_to_le32 (ns->head->ns_id); c.common.cdw2[0 ] =cpu_to_le32 (vcmd.cdw2); c.common.cdw2[1 ] =cpu_to_le32 (vcmd.cdw3);/* cdw11-12 */
drivers/nvme/host/nvme.h +22 -4
@@ -136,7 +136,6 @@ struct nvme_ctrl {struct device ctrl_device;struct device *device;/* char device */ struct cdev cdev; -struct ida ns_ida;struct work_struct reset_work;struct work_struct delete_work;
@@ -209,12 +208,14 @@ struct nvme_subsystem {struct list_head entry;struct mutex lock;struct list_head ctrls; +struct list_head nsheads;char subnqn[NVMF_NQN_SIZE ];char serial[20 ];char model[40 ];char firmware_rev[8 ];u8 cmic;u16 vendor_id; +struct ida ns_ida; };/*
@@ -226,18 +227,35 @@ struct nvme_ns_ids {uuid_t uuid; }; +/* +* Anchor structure for namespaces. There is one for each namespace in a +* NVMe subsystem that any of our controllers can see, and the namespace +* structure for each controller is chained of it. For private namespaces +* there is a 1:1 relation to our namespace structures, that is ->list +* only ever has a single entry for private namespaces. +*/ +struct nvme_ns_head { +struct list_head list; +struct srcu_struct srcu; +struct nvme_subsystem *subsys; +unsigned ns_id; +struct nvme_ns_ids ids; +struct list_head entry; +struct kref ref; +int instance; +}; +struct nvme_ns {struct list_head list;struct nvme_ctrl *ctrl;struct request_queue *queue;struct gendisk *disk; +struct list_head siblings;struct nvm_dev *ndev;struct kref kref; -int instance; +struct nvme_ns_head *head; -unsigned ns_id; -struct nvme_ns_ids ids;int lba_shift;u16 ms;u16 sgs;
Signature · 1 line
2.14.2
Re: [PATCH 3/7] nvme: track shared namespaces
Christoph,
Quoted 11 lines
Introduce a new struct
nvme_ns_headthat holds information about an actual namespace, unlike structnvme_ns, which only holds the per-controller namespace information. For private namespaces there is a 1:1 relation of the two, but for shared namespaces this lets us discover all the paths to it. For now only the identifiers are moved to the new structure, but most of the information in structnvme_nsshould eventually move over.To allow lockless path lookup the list of
nvme_nsstructures pernvme_ns_headis protected by SRCU, which requires freeing thenvme_nsstructure throughcall_srcu.
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Christoph Hellwig
maintainerPATCH 4/7 nvme: implement multipath access to nvme subsystems
In reply to Christoph HellwigThis patch adds native multipath support to the nvme driver. For each namespace we create only single block device node, which can be used to access that namespace through any of the controllers that refer to it. The gendisk for each controllers path to the name space still exists inside the kernel, but is hidden from userspace. The character device nodes are still available on a per-controller basis. A new link from the sysfs directory for the subsystem allows to find all controllers for a given subsystem.
Currently we will always send I/O to the first available path, this will be changed once the NVMe Asynchronous Namespace Access (ANA) TP is ratified and implemented, at which point we will look at the ANA state for each namespace. Another possibility that was prototyped is to use the path that is closes to the submitting NUMA code, which will be mostly interesting for PCI, but might also be useful for RDMA or FC transports in the future. There is not plan to implement round robin or I/O service time path selectors, as those are not scalable with the performance rates provided by NVMe.
The multipath device will go away once all paths to it disappear, any delay to keep it alive needs to be implemented at the controller level.
--- drivers/nvme/host/Kconfig | 9 ++ drivers/nvme/host/Makefile | 1 + drivers/nvme/host/core.c | 133 +++++++++++++++++++--- drivers/nvme/host/multipath.c | 255 ++++++++++++++++++++++++++++++++++++++++++ drivers/nvme/host/nvme.h | 57 ++++++++++ 5 files changed, 440 insertions(+), 15 deletions(-) create mode 100644 drivers/nvme/host/multipath.c
drivers/nvme/host/Kconfig +9 -0
@@ -13,6 +13,15 @@ config BLK_DEV_NVME To compile this driver as a module, choose M here: the module will be called nvme. +config NVME_MULTIPATH + bool "NVMe multipath support" + depends on NVME_CORE + ---help--- + This option enables support for multipath access to NVMe + subsystems. If this option is enabled only a single + /dev/nvneXnY device will show up for each NVMe namespaces, + even if it is accessible through multiple controllers. + config NVME_FABRICS tristate
drivers/nvme/host/Makefile +1 -0
@@ -5,6 +5,7 @@ obj-$(CONFIG_NVME_RDMA) += nvme-rdma.o obj-$(CONFIG_NVME_FC) += nvme-fc.o nvme-core-y := core.o +nvme-core-$(CONFIG_NVME_MULTIPATH) += multipath.o nvme-core-$(CONFIG_NVM) += lightnvm.o nvme-y += pci.o
drivers/nvme/host/core.c +118 -15
238 lines not on this page · raw message
drivers/nvme/host/multipath.c new file +255 -0
255 lines not on this page · raw message
drivers/nvme/host/nvme.h +57 -0
75 lines not on this page · raw message
Signature · 1 line
2.14.2
Re: [PATCH 4/7] nvme: implement multipath access to nvme subsystems
drivers/nvme/host/Kconfig config BLK_DEV_NVME · line 22
Quoted 7 lines · Christoph Hellwig
drivers/nvme/host/Kconfig +7
-0+config NVME_MULTIPATH + bool "NVMe multipath support" + depends on NVME_CORE + ---help--- + This option enables support for multipath access to NVMe + subsystems. If this option is enabled only a single + /dev/nvneXnY device will show up for each NVMe namespaces,
Minor typo: should be /dev/nvmeXnY.
Otherwise, everything in the series looks good to me and testing on my dual port devices hasn't found any problems.
For the whole series:
Re: [PATCH 4/7] nvme: implement multipath access to nvme subsystems
In reply to Christoph HellwigChristoph,
Quoted 19 lines
This patch adds native multipath support to the nvme driver. For each namespace we create only single block device node, which can be used to access that namespace through any of the controllers that refer to it. The gendisk for each controllers path to the name space still exists inside the kernel, but is hidden from userspace. The character device nodes are still available on a per-controller basis. A new link from the sysfs directory for the subsystem allows to find all controllers for a given subsystem.
Currently we will always send I/O to the first available path, this will be changed once the NVMe Asynchronous Namespace Access (ANA) TP is ratified and implemented, at which point we will look at the ANA state for each namespace. Another possibility that was prototyped is to use the path that is closes to the submitting NUMA code, which will be mostly interesting for PCI, but might also be useful for RDMA or FC transports in the future. There is not plan to implement round robin or I/O service time path selectors, as those are not scalable with the performance rates provided by NVMe.
Quoted 3 lines
The multipath device will go away once all paths to it disappear, any delay to keep it alive needs to be implemented at the controller level.
Beautiful!
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Re: [PATCH 4/7] nvme: implement multipath access to nvme subsystems
In reply to Christoph HellwigAhh, I incorporated non-multipath disks into the mix and observing some trouble. Details below:
Quoted 8 lines · Christoph Hellwig
drivers/nvme/host/core.c +8
-0+#ifdef CONFIG_NVME_MULTIPATH +if (ns->head->disk) { +sprintf (disk_name,"nvme%dc%dn%d" , ctrl->subsys->instance, + ctrl->cntlid, ns->head->instance); + flags =GENHD_FL_HIDDEN ; + } else +#endif +sprintf (disk_name,"nvme%dn%d" , ctrl->instance, ns->head->instance);
...
Quoted 16 lines
drivers/nvme/host/multipath.c new file +16
-0+int nvme_mpath_alloc_disk (struct nvme_ctrl *ctrl,struct nvme_ns_head *head) +{ +struct request_queue *q; +bool vwc = false; + +bio_list_init (&head->requeue_list); +spin_lock_init (&head->requeue_lock); +INIT_WORK (&head->requeue_work, nvme_requeue_work); + +/* +* Add a multipath node if the subsystems supports multiple controllers. +* We also do this for private namespaces as the namespace sharing data could +* change after a rescan. +*/ +if (!(ctrl->subsys->cmic & (1 <<1 )) || !multipath) +return 0 ;
...
drivers/nvme/host/multipath.c line 228
Quoted 2 lines
drivers/nvme/host/multipath.c new file +2
-0+sprintf (head->disk->disk_name,"nvme%dn%d" , + ctrl->subsys->instance, head->instance);
If we've CMIC capabilities, we'll use the subsys->instance; if we don't have CMIC, we use the ctrl->instance.
Since the two instances are independent of each other, they can create duplicate names.
To fix, I think we'll need to always use the subsys instance for consistency if CONFIG_NVME_MULTIPATH=y.
---
@@ -2837,8 +2826,10 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
ctrl->cntlid, ns->head->instance);
flags = GENHD_FL_HIDDEN;
} else
+ sprintf(disk_name, "nvme%dn%d", ctrl->subsys->instance, ns->head->instance);
+#else
+ sprintf(disk_name, "nvme%dn%d", ctrl->instance, ns->head->instance);
#endif
- sprintf(disk_name, "nvme%dn%d", ctrl->instance, ns->head->instance);
if ((ctrl->quirks & NVME_QUIRK_LIGHTNVM) && id->vs[0] == 0x1) {
if (nvme_nvm_register(ns, disk_name, node)) {
--
This may confuse some people since the block device's name will not always match up to the controller's chardev name, but I don't see another way to do it.
Christoph Hellwig
maintainerRe: [PATCH 4/7] nvme: implement multipath access to nvme subsystems
Quoted 8 lines
If we've CMIC capabilities, we'll use the
subsys->instance; if we don't have CMIC, we use thectrl->instance.Since the two instances are independent of each other, they can create duplicate names.
To fix, I think we'll need to always use the subsys instance for consistency if
CONFIG_NVME_MULTIPATH=y.
Yes, we should. But once we do that we should just always use subsys->instance, as it will always be the same as ctrl->instance for CONFIG_NVME_MULTIPATH=n.
Christoph Hellwig
maintainerRe: [PATCH 4/7] nvme: implement multipath access to nvme subsystems
Quoted 6 lines · Christoph Hellwig
Quoted 6 lines
If we've CMIC capabilities, we'll use the
subsys->instance; if we don't have CMIC, we use thectrl->instance.Since the two instances are independent of each other, they can create duplicate names.
Quoted 6 lines
Quoted 2 lines
To fix, I think we'll need to always use the subsys instance for consistency if
CONFIG_NVME_MULTIPATH=y.Yes, we should. But once we do that we should just always use
subsys->instance, as it will always be the same asctrl->instanceforCONFIG_NVME_MULTIPATH=n.
Scrap that. Of course they aren't always the same in the CONFIG_NVME_MULTIPATH=n. We'll need your patch as-is.
Re: [PATCH 4/7] nvme: implement multipath access to nvme subsystems
In reply to Christoph HellwigQuoted 19 lines · Christoph Hellwig
This patch adds native multipath support to the nvme driver. For each namespace we create only single block device node, which can be used to access that namespace through any of the controllers that refer to it. The gendisk for each controllers path to the name space still exists inside the kernel, but is hidden from userspace. The character device nodes are still available on a per-controller basis. A new link from the sysfs directory for the subsystem allows to find all controllers for a given subsystem.
Currently we will always send I/O to the first available path, this will be changed once the NVMe Asynchronous Namespace Access (ANA) TP is ratified and implemented, at which point we will look at the ANA state for each namespace. Another possibility that was prototyped is to use the path that is closes to the submitting NUMA code, which will be mostly interesting for PCI, but might also be useful for RDMA or FC transports in the future. There is not plan to implement round robin or I/O service time path selectors, as those are not scalable with the performance rates provided by NVMe.
Quoted 5 lines
The multipath device will go away once all paths to it disappear, any delay to keep it alive needs to be implemented at the controller level.
Signed-off-by Christoph Hellwig <[email protected]>
Your 0th header speaks to the NVMe multipath IO path leveraging NVMe's lack of partial completion but I think it'd be useful to have this header (that actually gets committed) speak to it.
Quoted 5 lines
drivers/nvme/host/multipath.c new file +0
-0
...
drivers/nvme/host/multipath.c line 34
Quoted 13 lines
drivers/nvme/host/multipath.c new file +13
-0+void nvme_failover_req (struct request *req) +{ +struct nvme_ns *ns = req->q->queuedata; +unsigned long flags; + +spin_lock_irqsave (&ns->head->requeue_lock, flags); +blk_steal_bios (&ns->head->requeue_list, req); +spin_unlock_irqrestore (&ns->head->requeue_lock, flags); +blk_mq_end_request (req,0 ); + +nvme_reset_ctrl (ns->ctrl); +kblockd_schedule_work (&ns->head->requeue_work); +}
Also, the block core patch to introduce blk_steal_bios() already went in but should there be a QUEUE_FLAG that gets set by drivers like NVMe that don't support partial completion?
This would make it easier for other future drivers to know whether they can use a more optimized IO path.
Mike
Christoph Hellwig
maintainerRe: [PATCH 4/7] nvme: implement multipath access to nvme subsystems
Quoted 3 lines · Mike Snitzer
Your 0th header speaks to the NVMe multipath IO path leveraging NVMe's lack of partial completion but I think it'd be useful to have this header (that actually gets committed) speak to it.
There is a comment above blk_steal_bios to this respect, which is in the tree.
Quoted 6 lines
Also, the block core patch to introduce
blk_steal_bios()already went in but should there be aQUEUE_FLAGthat gets set by drivers like NVMe that don't support partial completion?This would make it easier for other future drivers to know whether they can use a more optimized IO path.
As-is there is not real need for this. But if you want to use a similar path in dm-multipath feel free to add the flag when needed.
Re: [PATCH 4/7] nvme: implement multipath access to nvme subsystems
In reply to Christoph HellwigQuoted 24 lines · Christoph Hellwig
This patch adds native multipath support to the nvme driver. For each namespace we create only single block device node, which can be used to access that namespace through any of the controllers that refer to it. The gendisk for each controllers path to the name space still exists inside the kernel, but is hidden from userspace. The character device nodes are still available on a per-controller basis. A new link from the sysfs directory for the subsystem allows to find all controllers for a given subsystem.
Currently we will always send I/O to the first available path, this will be changed once the NVMe Asynchronous Namespace Access (ANA) TP is ratified and implemented, at which point we will look at the ANA state for each namespace. Another possibility that was prototyped is to use the path that is closes to the submitting NUMA code, which will be mostly interesting for PCI, but might also be useful for RDMA or FC transports in the future. There is not plan to implement round robin or I/O service time path selectors, as those are not scalable with the performance rates provided by NVMe.
The multipath device will go away once all paths to it disappear, any delay to keep it alive needs to be implemented at the controller level.
Signed-off-by Christoph Hellwig <[email protected]>
Quoted 9 lines
--- drivers/nvme/host/Kconfig | 9 ++ drivers/nvme/host/Makefile | 1 + drivers/nvme/host/core.c | 133 +++++++++++++++++++--- drivers/nvme/host/multipath.c | 255 ++++++++++++++++++++++++++++++++++++++++++ drivers/nvme/host/nvme.h | 57 ++++++++++ 5 files changed, 440 insertions(+), 15 deletions(-) create mode 100644 drivers/nvme/host/multipath.c
After much discussion I'm finally fine with this.
Cheers,
Hannes
Signature · 5 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG Nürnberg)
Christoph Hellwig
maintainerPATCH 5/7 nvme: also expose the namespace identification sysfs files for mpath nodes
In reply to Christoph HellwigWe do this by adding a helper that returns the ns_head for a device that can belong to either the per-controller or per-subsystem block device nodes, and otherwise reuse all the existing code.
--- drivers/nvme/host/core.c | 57 +++++++++++++++++++++++-------------------- drivers/nvme/host/multipath.c | 6 +++++ drivers/nvme/host/nvme.h | 1 + 3 files changed, 38 insertions(+), 26 deletions(-)
drivers/nvme/host/core.c +31 -26
@@ -2381,12 +2381,22 @@ static ssize_t nvme_sysfs_rescan(struct device *dev, } static DEVICE_ATTR(rescan_controller, S_IWUSR, NULL, nvme_sysfs_rescan); +static inline struct nvme_ns_head *dev_to_ns_head (struct device *dev) +{ +struct gendisk *disk =dev_to_disk (dev); + +if (disk->fops == &nvme_fops) +return nvme_get_ns_from_dev (dev)->head; +else +return disk->private_data; +} +static ssize_t wwid_show (struct device *dev,struct device_attribute *attr, -char *buf) +char *buf) { -struct nvme_ns *ns =nvme_get_ns_from_dev (dev); -struct nvme_ns_ids *ids = &ns->head->ids; -struct nvme_subsystem *subsys = ns->ctrl->subsys; +struct nvme_ns_head *head =dev_to_ns_head (dev); +struct nvme_ns_ids *ids = &head->ids; +struct nvme_subsystem *subsys = head->subsys;int serial_len =sizeof (subsys->serial);int model_len =sizeof (subsys->model);
@@ -2408,23 +2418,21 @@ static ssize_t wwid_show(struct device *dev, struct device_attribute *attr,return sprintf (buf,"nvme.%04x-%*phN-%*phN-%08x\n" , subsys->vendor_id, serial_len, subsys->serial, model_len, subsys->model, - ns->head->ns_id); + head->ns_id); } static DEVICE_ATTR(wwid, S_IRUGO, wwid_show, NULL);static ssize_t nguid_show (struct device *dev,struct device_attribute *attr, -char *buf) +char *buf) { -struct nvme_ns *ns =nvme_get_ns_from_dev (dev); -return sprintf (buf,"%pU\n" , ns->head->ids.nguid); +return sprintf (buf,"%pU\n" ,dev_to_ns_head (dev)->ids.nguid); } static DEVICE_ATTR(nguid, S_IRUGO, nguid_show, NULL);static ssize_t uuid_show (struct device *dev,struct device_attribute *attr, -char *buf) +char *buf) { -struct nvme_ns *ns =nvme_get_ns_from_dev (dev); -struct nvme_ns_ids *ids = &ns->head->ids; +struct nvme_ns_ids *ids = &dev_to_ns_head (dev)->ids;/* For backward compatibility expose the NGUID to userspace if * we have no UUID set
@@ -2439,22 +2447,20 @@ static ssize_t uuid_show(struct device *dev, struct device_attribute *attr, static DEVICE_ATTR(uuid, S_IRUGO, uuid_show, NULL);static ssize_t eui_show (struct device *dev,struct device_attribute *attr, -char *buf) +char *buf) { -struct nvme_ns *ns =nvme_get_ns_from_dev (dev); -return sprintf (buf,"%8ph\n" , ns->head->ids.eui64); +return sprintf (buf,"%8ph\n" ,dev_to_ns_head (dev)->ids.eui64); } static DEVICE_ATTR(eui, S_IRUGO, eui_show, NULL);static ssize_t nsid_show (struct device *dev,struct device_attribute *attr, -char *buf) +char *buf) { -struct nvme_ns *ns =nvme_get_ns_from_dev (dev); -return sprintf (buf,"%d\n" , ns->head->ns_id); +return sprintf (buf,"%d\n" ,dev_to_ns_head (dev)->ns_id); } static DEVICE_ATTR(nsid, S_IRUGO, nsid_show, NULL); -static struct attribute *nvme_ns_attrs[] = { +static struct attribute *nvme_ns_id_attrs[] = { &dev_attr_wwid.attr, &dev_attr_uuid.attr, &dev_attr_nguid.attr,
@@ -2463,12 +2469,11 @@ static struct attribute *nvme_ns_attrs[] = { NULL, }; -static umode_t nvme_ns_attrs_are_visible (struct kobject *kobj, +static umode_t nvme_ns_id_attrs_are_visible (struct kobject *kobj,struct attribute *a,int n) { struct device *dev = container_of(kobj, struct device, kobj); -struct nvme_ns *ns =nvme_get_ns_from_dev (dev); -struct nvme_ns_ids *ids = &ns->head->ids; +struct nvme_ns_ids *ids = &dev_to_ns_head (dev)->ids;if (a == &dev_attr_uuid.attr) { if (uuid_is_null(&ids->uuid) ||
@@ -2486,9 +2491,9 @@ static umode_t nvme_ns_attrs_are_visible(struct kobject *kobj,return a->mode; } -static const struct attribute_group nvme_ns_attr_group = { - .attrs = nvme_ns_attrs, - .is_visible = nvme_ns_attrs_are_visible, +const struct attribute_group nvme_ns_id_attr_group = { + .attrs = nvme_ns_id_attrs, + .is_visible = nvme_ns_id_attrs_are_visible, };#define nvme_show_str_function (field) \
@@ -2865,7 +2870,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)device_add_disk (ctrl->device, ns->disk);if (sysfs_create_group (&disk_to_dev (ns->disk)->kobj, - &nvme_ns_attr_group)) + &nvme_ns_id_attr_group))pr_warn ("%s: failed to create sysfs group for identification\n" , ns->disk->disk_name);if (ns->ndev &&nvme_nvm_register_sysfs (ns))
@@ -2898,7 +2903,7 @@ static void nvme_ns_remove(struct nvme_ns *ns)if (blk_get_integrity (ns->disk))blk_integrity_unregister (ns->disk);sysfs_remove_group (&disk_to_dev (ns->disk)->kobj, - &nvme_ns_attr_group); + &nvme_ns_id_attr_group);if (ns->ndev)nvme_nvm_unregister_sysfs (ns);del_gendisk (ns->disk);
drivers/nvme/host/multipath.c +6 -0
@@ -239,12 +239,18 @@ void nvme_mpath_add_disk(struct nvme_ns_head *head)if (!head->disk)return ;device_add_disk (&head->subsys->dev, head->disk); +if (sysfs_create_group (&disk_to_dev (head->disk)->kobj, + &nvme_ns_id_attr_group)) +pr_warn ("%s: failed to create sysfs group for identification\n" , + head->disk->disk_name); }void nvme_mpath_remove_disk (struct nvme_ns_head *head) {if (!head->disk)return ; +sysfs_remove_group (&disk_to_dev (head->disk)->kobj, + &nvme_ns_id_attr_group);del_gendisk (head->disk);blk_set_queue_dying (head->disk->queue);/* make sure all pending bios are cleaned up */
drivers/nvme/host/nvme.h +1 -0
@@ -395,6 +395,7 @@ int nvme_reset_ctrl(struct nvme_ctrl *ctrl);int nvme_delete_ctrl (struct nvme_ctrl *ctrl);int nvme_delete_ctrl_sync (struct nvme_ctrl *ctrl); +extern const struct attribute_group nvme_ns_id_attr_group;extern const struct block_device_operations nvme_ns_head_ops;#ifdef CONFIG_NVME_MULTIPATH
Signature · 1 line
2.14.2
Re: [PATCH 5/7] nvme: also expose the namespace identification sysfs files for mpath nodes
Christoph,
Quoted 3 lines
We do this by adding a helper that returns the
ns_headfor a device that can belong to either the per-controller or per-subsystem block device nodes, and otherwise reuse all the existing code.
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Re: [PATCH 5/7] nvme: also expose the namespace identification sysfs files for mpath nodes
In reply to Christoph HellwigQuoted 8 lines · Christoph Hellwig
We do this by adding a helper that returns the
ns_headfor a device that can belong to either the per-controller or per-subsystem block device nodes, and otherwise reuse all the existing code.Signed-off-by Christoph Hellwig <[email protected]>Reviewed-by Keith Busch <[email protected]>Reviewed-by Sagi Grimberg <[email protected]>Reviewed-by Johannes Thumshirn <[email protected]>
Quoted 6 lines
--- drivers/nvme/host/core.c | 57 +++++++++++++++++++++++-------------------- drivers/nvme/host/multipath.c | 6 +++++ drivers/nvme/host/nvme.h | 1 + 3 files changed, 38 insertions(+), 26 deletions(-)
In principle, yes, but I would like to have some more info (like subsysnqn, and maybe 'model' etc) in the subsys sysfs entry, too. But this can be handled in a later patch, so:
Cheers,
Hannes
Signature · 5 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG Nürnberg)
Christoph Hellwig
maintainerPATCH 6/7 block: create 'slaves' and 'holders' entries for hidden gendisks
In reply to Christoph HellwigFrom: Hannes Reinecke <[email protected]>
When creating nvme multipath devices we should populate the 'slaves' and 'holders' directorys properly to aid userspace topology detection.
--- block/genhd.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
block/genhd.c +7 -7
@@ -585,14 +585,14 @@ static void register_disk(struct device *parent, struct gendisk *disk)*/ pm_runtime_set_memalloc_noio (ddev, true); + disk->part0.holder_dir =kobject_create_and_add ("holders" , &ddev->kobj); + disk->slave_dir =kobject_create_and_add ("slaves" , &ddev->kobj); +if (disk->flags &GENHD_FL_HIDDEN ) {dev_set_uevent_suppress (ddev,0 );return ; } - disk->part0.holder_dir =kobject_create_and_add ("holders" , &ddev->kobj); - disk->slave_dir =kobject_create_and_add ("slaves" , &ddev->kobj); -/* No minors to use for partitions */ if (!disk_part_scan_enabled (disk)) goto exit;
@@ -728,11 +728,11 @@ void del_gendisk(struct gendisk *disk)WARN_ON (1 ); } -if (!(disk->flags &GENHD_FL_HIDDEN )) { +if (!(disk->flags &GENHD_FL_HIDDEN ))blk_unregister_region (disk_devt (disk), disk->minors); -kobject_put (disk->part0.holder_dir); -kobject_put (disk->slave_dir); - } + +kobject_put (disk->part0.holder_dir); +kobject_put (disk->slave_dir);part_stat_set_all (&disk->part0,0 ); disk->part0.stamp =0 ;
Signature · 1 line
2.14.2
Re: [PATCH 6/7] block: create 'slaves' and 'holders' entries for hidden gendisks
Christoph,
Quoted 4 lines
From: Hannes Reinecke <[email protected]>
When creating nvme multipath devices we should populate the 'slaves' and 'holders' directorys properly to aid userspace topology detection.
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Christoph Hellwig
maintainerPATCH 7/7 nvme: create 'slaves' and 'holders' entries for hidden controllers
In reply to Christoph HellwigFrom: Hannes Reinecke <[email protected]>
When creating nvme multipath devices we should populate the 'slaves' and 'holders' directorys properly to aid userspace topology detection.
--- drivers/nvme/host/core.c | 2 ++ drivers/nvme/host/multipath.c | 30 ++++++++++++++++++++++++++++++ drivers/nvme/host/nvme.h | 8 ++++++++ 3 files changed, 40 insertions(+)
drivers/nvme/host/core.c +2 -0
@@ -2879,6 +2879,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)if (new)nvme_mpath_add_disk (ns->head); +nvme_mpath_add_disk_links (ns);return ; out_unlink_ns:mutex_lock (&ctrl->subsys->lock);
@@ -2902,6 +2903,7 @@ static void nvme_ns_remove(struct nvme_ns *ns)if (ns->disk && ns->disk->flags &GENHD_FL_UP ) {if (blk_get_integrity (ns->disk))blk_integrity_unregister (ns->disk); +nvme_mpath_remove_disk_links (ns);sysfs_remove_group (&disk_to_dev (ns->disk)->kobj, &nvme_ns_id_attr_group);if (ns->ndev)
drivers/nvme/host/multipath.c +30 -0
@@ -245,6 +245,25 @@ void nvme_mpath_add_disk(struct nvme_ns_head *head) head->disk->disk_name); } +void nvme_mpath_add_disk_links (struct nvme_ns *ns) +{ +struct kobject *slave_disk_kobj, *holder_disk_kobj; + +if (!ns->head->disk) +return ; + + slave_disk_kobj = &disk_to_dev (ns->disk)->kobj; +if (sysfs_create_link (ns->head->disk->slave_dir, slave_disk_kobj, +kobject_name (slave_disk_kobj))) +return ; + + holder_disk_kobj = &disk_to_dev (ns->head->disk)->kobj; +if (sysfs_create_link (ns->disk->part0.holder_dir, holder_disk_kobj, +kobject_name (holder_disk_kobj))) +sysfs_remove_link (ns->head->disk->slave_dir, +kobject_name (slave_disk_kobj)); +} +void nvme_mpath_remove_disk (struct nvme_ns_head *head) {if (!head->disk)
@@ -259,3 +278,14 @@ void nvme_mpath_remove_disk(struct nvme_ns_head *head)blk_cleanup_queue (head->disk->queue);put_disk (head->disk); } + +void nvme_mpath_remove_disk_links (struct nvme_ns *ns) +{ +if (!ns->head->disk) +return ; + +sysfs_remove_link (ns->disk->part0.holder_dir, +kobject_name (&disk_to_dev (ns->head->disk)->kobj)); +sysfs_remove_link (ns->head->disk->slave_dir, +kobject_name (&disk_to_dev (ns->disk)->kobj)); +}
drivers/nvme/host/nvme.h +8 -0
@@ -404,7 +404,9 @@ bool nvme_req_needs_failover(struct request *req);void nvme_kick_requeue_lists (struct nvme_ctrl *ctrl);int nvme_mpath_alloc_disk (struct nvme_ctrl *ctrl,struct nvme_ns_head *head);void nvme_mpath_add_disk (struct nvme_ns_head *head); +void nvme_mpath_add_disk_links (struct nvme_ns *ns);void nvme_mpath_remove_disk (struct nvme_ns_head *head); +void nvme_mpath_remove_disk_links (struct nvme_ns *ns);static inline void nvme_mpath_clear_current_path (struct nvme_ns *ns) {
@@ -436,6 +438,12 @@ static inline void nvme_mpath_add_disk(struct nvme_ns_head *head)static inline void nvme_mpath_remove_disk (struct nvme_ns_head *head) { } +static inline void nvme_mpath_add_disk_links (struct nvme_ns *ns) +{ +} +static inline void nvme_mpath_remove_disk_links (struct nvme_ns *ns) +{ +}static inline void nvme_mpath_clear_current_path (struct nvme_ns *ns) { }
Signature · 1 line
2.14.2
Re: [PATCH 7/7] nvme: create 'slaves' and 'holders' entries for hidden controllers
Christoph,
Quoted 4 lines
From: Hannes Reinecke <[email protected]>
When creating nvme multipath devices we should populate the 'slaves' and 'holders' directorys properly to aid userspace topology detection.
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Christoph Hellwig
maintainerI've updated the git tree with the Kconfig type fix, the instance fixup from Keith (plus extensive comments explaning the issue) and the various reviews. I'll wait for the buildbot a and do a little more manual testing and will send it to Jens in the afternoon.
Hi everyone-
I'd like to do some testing on NVMe multipath in an NVMeoF environment. I'm running Ubuntu kernel 4.15.15 and I've set up my kernel NVMeoF target to expose a namespace through two separate ports, then mounted the name space through both ports to my dual ported initiator, but I didn't see any multipath device created. I'm probably missing some steps. :)
Rather than send a bunch of dumb questions to the list, are there more detailed instructions or examples around for setting up the native NVMe multipath in an NVMeoF environment that I might review? A basic step by step example of setting up a simple configuration would be super helpful.
Thanks,
Joe
Quoted 110 lines
-----Original Message-----
From: Linux-nvme [mailto:linux-nvme-bounces at lists.infradead.org] On Behalf Of Christoph Hellwig
Sent: Thursday, November 9, 2017 9:45 AM
To: Busch, Keith <keith.busch at intel.com>; Sagi Grimberg <sagi at grimberg.me>
Cc: Jens Axboe <axboe at kernel.dk>; linux-block at vger.kernel.org; Hannes Reinecke <hare at suse.de>; linux-nvme at lists.infradead.org; Johannes Thumshirn <jthumshirn at suse.de>
Subject: nvme multipath support V7Hi all,
this series adds support for multipathing, that is accessing nvme namespaces through multiple controllers to the nvme core driver.
I think we are pretty much done with with very little changes in the last reposts. Unless I hear objections I plan to send this to Jens tomorrow with the remaining NVMe updates.
It is a very thin and efficient implementation that relies on close cooperation with other bits of the nvme driver, and few small and simple block helpers.
Compared to dm-multipath the important differences are how management of the paths is done, and how the I/O path works.
Management of the paths is fully integrated into the nvme driver, for each newly found nvme controller we check if there are other controllers that refer to the same subsystem, and if so we link them up in the nvme driver. Then for each namespace found we check if the namespace id and identifiers match to check if we have multiple controllers that refer to the same namespaces. For now path availability is based entirely on the controller status, which at least for fabrics will be continuously updated based on the mandatory keep alive timer. Once the Asynchronous Namespace Access (ANA) proposal passes in NVMe we will also get per-namespace states in addition to that, but for now any details of that remain confidential to NVMe members.
The I/O path is very different from the existing multipath drivers, which is enabled by the fact that NVMe (unlike SCSI) does not support partial completions - a controller will either complete a whole command or not, but never only complete parts of it. Because of that there is no need to clone bios or requests - the I/O path simply redirects the I/O to a suitable path. For successful commands multipath is not in the completion stack at all. For failed commands we decide if the error could be a path failure, and if yes remove the bios from the request structure and requeue them before completing the request. All together this means there is no performance degradation compared to normal nvme operation when using the multipath device node (at least not until I find a dual ported DRAM backed device :))
A git tree is available at:
git://git.infradead.org/users/hch/block.gitnvme-mpathgitweb:
http://git.infradead.org/users/hch/block.git/shortlog/refs/heads/nvme-mpath
Changes since V6:
- added slaves/holder directories (Hannes)
- trivial rebase on top of the latest nvme-4.15 changesChanges since V5:
- dropped various prep patches merged into the nvme tree
- removed a leftover debug printk
- small cleanups toblk_steal_bio
- add a sysfs attribute for hidden gendisks
- don't complete cancelled requests if another path is available
- use the instance index for device naming
- make the multipath code optional at compile time
- don't use the multipath node for single-controller subsystems
- add amodule_optionto disable multipathing (temporarily)Changes since V4:
- add a refcount to release the device in structnvme_subsystem
- use the instance to name thenvme_subsystemsin sysfs
- remove a NULL check beforenvme_put_ns_head
- take ans_headreference in ->open
- improve open protection forGENHD_FL_HIDDEN
- add poll support for the mpath deviceChanges since V3:
- new block layer support for hidden gendisks
- a couple new patches to refactor device handling before the actual multipath support
- don't expose per-controller block device nodes
- use/dev/nvmeXnZas the device nodes for the whole subsystem.
- expose subsystems in sysfs (Hannes Reinecke)
- fix a subsystem leak when duplicate NQNs are found
- fix up some names
- don't clearcurrent_pathif freeing a different namespaceChanges since V2:
- don't create duplicate subsystems on reset (Keith Bush)
- free requests properly when failing over in I/O completion (Keith Bush)
- new devices names: /dev/nvm-sub%dn%d
- expose the namespace identification sysfs files for the mpath nodesChanges since V1:
- introduce newnvme_ns_idsstructure to clean up identifier handling
-generic_make_request_fastis now nameddirect_make_requestand callsgeneric_make_request_checks
- resetbi_diskon resubmission
- create sysfs links between the existing nvme namespace block devices and the new share mpath device
- temporarily added the timeout patches from James, this should go intonvme-4.14, though_______________________________________________
Linux-nvme mailing list
Linux-nvme at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme