nvme: fix regression with MD RAID
cover nvme: fix regression with MD RAID
Hi all,
ever since the implementation NVMe-oF does not work together with MD RAID. MD RAID expects the device to return an I/O error on failure, and to remove the block device if the underlying hardware is removed.
This is contrary to the implementation of NVMe-oF, which will keep on retrying I/O while the controller is being reset, and will only remove the block device once the last _user_ is gone.
These patches fixup this situation by adding a new sysfs attribute 'fail_if_no_path'. When this attribute is set we will return I/O errors as soon as no paths are available anymore, and will remove the block device once the last controller holding a path to the namespace is removed (ie after all reconnect attempts for that controllers are exhausted).
This is a rework of the earlier path by Keith Busch ('nvme-mpath: delete disk after last connection'). Kudos to him for suggesting this approach.
Hannes Reinecke (2):
nvme: add 'fail_if_no_path' sysfs attribute
nvme: delete disk when last path is gone
drivers/nvme/host/core.c | 6 +++++ drivers/nvme/host/multipath.c | 46 ++++++++++++++++++++++++++++++++--- drivers/nvme/host/nvme.h | 19 +++++++++++++-- 3 files changed, 66 insertions(+), 5 deletions(-)
Signature · 7 lines
2.29.2 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH 1/2 nvme: add 'fail_if_no_path' sysfs attribute
In some setups like RAID or cluster we need to return an I/O error once all paths are unavailable to allow the upper layers to start their own error recovery (like redirecting I/O to other mirrors). This patch adds a sysfs attribute 'fail_if_no_path' to allow the admin to enable that behaviour instead of the current 'queue until a path becomes available' policy.
--- drivers/nvme/host/core.c | 5 ++++ drivers/nvme/host/multipath.c | 43 +++++++++++++++++++++++++++++++++-- drivers/nvme/host/nvme.h | 2 ++ 3 files changed, 48 insertions(+), 2 deletions(-)
drivers/nvme/host/core.c +5 -0
@@ -3464,6 +3464,7 @@ static struct attribute *nvme_ns_id_attrs[] = {#ifdef CONFIG_NVME_MULTIPATH &dev_attr_ana_grpid.attr, &dev_attr_ana_state.attr, + &dev_attr_fail_if_no_path.attr, #endif NULL, };
@@ -3494,6 +3495,10 @@ static umode_t nvme_ns_id_attrs_are_visible(struct kobject *kobj,if (!nvme_ctrl_use_ana (nvme_get_ns_from_dev (dev)->ctrl)) return 0; } +if (a == &dev_attr_fail_if_no_path.attr) { +if (dev_to_disk (dev)->fops == &nvme_bdev_ops) +return 0 ; + }#endif return a->mode; }
drivers/nvme/host/multipath.c +41 -2
57 lines not on this page · raw message
drivers/nvme/host/nvme.h +2 -0
@@ -418,6 +418,7 @@ struct nvme_ns_head {struct mutex lock;unsigned long flags;#define NVME_NSHEAD_DISK_LIVE 0 +#define NVME_NSHEAD_FAIL_IF_NO_PATH 1struct nvme_ns __rcu *current_path[];#endif };
@@ -694,6 +695,7 @@ static inline void nvme_trace_bio_complete(struct request *req)extern struct device_attribute dev_attr_ana_grpid;extern struct device_attribute dev_attr_ana_state; +extern struct device_attribute dev_attr_fail_if_no_path;extern struct device_attribute subsys_attr_iopolicy;#else
Signature · 7 lines
2.29.2 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH 2/2 nvme: delete disk when last path is gone
In reply to Hannes ReineckeThe multipath code currently deletes the disk only after all references to it are dropped rather than when the last path to that disk is lost. This has been reported to cause problems with some use cases like MD RAID.
This patch implements an alternative behaviour of deleting the disk when the last path is gone, ie the same behaviour as non-multipathed nvme devices. The new behaviour will be selected with the 'fail_if_no_path' attribute, as returning it's arguably the same functionality.
--- drivers/nvme/host/core.c | 1 + drivers/nvme/host/multipath.c | 3 ++- drivers/nvme/host/nvme.h | 17 +++++++++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-)
drivers/nvme/host/core.c +1 -0
@@ -542,6 +542,7 @@ static void nvme_free_ns_head(struct kref *ref) container_of(ref, struct nvme_ns_head, ref);nvme_mpath_remove_disk (head); +nvme_mpath_put_disk (head);ida_simple_remove (&head->subsys->ns_ida, head->instance);cleanup_srcu_struct (&head->srcu);nvme_put_subsystem (head->subsys);
drivers/nvme/host/multipath.c +2 -1
@@ -724,6 +724,8 @@ void nvme_mpath_add_disk(struct nvme_ns *ns, struct nvme_id_ns *id)void nvme_mpath_remove_disk (struct nvme_ns_head *head) { +if (test_bit (NVME_NSHEAD_FAIL_IF_NO_PATH , &head->flags)) +return ;if (!head->disk)return ;if (head->disk->flags &GENHD_FL_UP )
@@ -741,7 +743,6 @@ void nvme_mpath_remove_disk(struct nvme_ns_head *head)*/ head->disk->queue =NULL ; } -put_disk (head->disk); }int nvme_mpath_init (struct nvme_ctrl *ctrl,struct nvme_id_ctrl *id)
drivers/nvme/host/nvme.h +15 -2
@@ -681,8 +681,12 @@ static inline void nvme_mpath_check_last_path(struct nvme_ns *ns) {struct nvme_ns_head *head = ns->head; -if (head->disk &&list_empty (&head->list)) -kblockd_schedule_work (&head->requeue_work); +if (head->disk &&list_empty (&head->list)) { +if (test_bit (NVME_NSHEAD_FAIL_IF_NO_PATH , &head->flags)) +nvme_mpath_remove_disk (head); +else +kblockd_schedule_work (&head->requeue_work); + } }static inline void nvme_trace_bio_complete (struct request *req)
@@ -693,6 +697,12 @@ static inline void nvme_trace_bio_complete(struct request *req)trace_block_bio_complete (ns->head->disk->queue, req->bio); } +static inline void nvme_mpath_put_disk (struct nvme_ns_head *head) +{ +if (head->disk) +put_disk (head->disk); +} +extern struct device_attribute dev_attr_ana_grpid;extern struct device_attribute dev_attr_ana_state;extern struct device_attribute dev_attr_fail_if_no_path;
@@ -731,6 +741,9 @@ static inline void nvme_mpath_add_disk(struct nvme_ns *ns,static inline void nvme_mpath_remove_disk (struct nvme_ns_head *head) { } +static inline void nvme_mpath_put_disk (struct nvme_ns_head *head) +{ +}static inline bool nvme_mpath_clear_current_path (struct nvme_ns *ns) {return false;
Signature · 7 lines
2.29.2 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 1/2] nvme: add 'fail_if_no_path' sysfs attribute
In reply to Hannes ReineckeQuoted 42 lines · Hannes Reinecke
In some setups like RAID or cluster we need to return an I/O error once all paths are unavailable to allow the upper layers to start their own error recovery (like redirecting I/O to other mirrors). This patch adds a sysfs attribute '
fail_if_no_path' to allow the admin to enable that behaviour instead of the current 'queue until a path becomes available' policy.Signed-off-by Hannes Reinecke <[email protected]>--- drivers/nvme/host/core.c | 5 ++++ drivers/nvme/host/multipath.c | 43 +++++++++++++++++++++++++++++++++-- drivers/nvme/host/nvme.h | 2 ++ 3 files changed, 48 insertions(+), 2 deletions(-)drivers/nvme/host/core.c +5
-0@@ -3464,6 +3464,7 @@ static struct attribute *nvme_ns_id_attrs[] = {#ifdef CONFIG_NVME_MULTIPATH &dev_attr_ana_grpid.attr, &dev_attr_ana_state.attr, + &dev_attr_fail_if_no_path.attr, #endif NULL, };@@ -3494,6 +3495,10 @@ static umode_t nvme_ns_id_attrs_are_visible(struct kobject *kobj,if (!nvme_ctrl_use_ana (nvme_get_ns_from_dev (dev)->ctrl)) return 0; } +if (a == &dev_attr_fail_if_no_path.attr) { +if (dev_to_disk (dev)->fops == &nvme_bdev_ops) +return 0 ; + }#endif return a->mode; }drivers/nvme/host/multipath.c +0
-0
drivers/nvme/host/multipath.c static bool nvme_available_path(struct nvme_ns_head *head) · line 291
Quoted 9 lines
drivers/nvme/host/multipath.c +6
-0@@ -283,10 +283,18 @@ static bool nvme_available_path(struct nvme_ns_head *head)continue ;switch (ns->ctrl->state) {case NVME_CTRL_LIVE : +if (!test_bit (NVME_NSHEAD_FAIL_IF_NO_PATH , + &head->flags)) +return true; +if (ns->ana_state !=NVME_ANA_INACCESSIBLE && + ns->ana_state !=NVME_ANA_PERSISTENT_LOSS ) +return true;
It looks like it needs to prevent fallthru here with return false. It causes following warning:
drivers/nvme/host/multipath.c: In function ‘nvme_available_path’:
drivers/nvme/host/multipath.c:289:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
289 | if (ns->ana_state != NVME_ANA_INACCESSIBLE &&
| ^
drivers/nvme/host/multipath.c:292:3: note: here
292 | case NVME_CTRL_RESETTING:
| ^~~~drivers/nvme/host/multipath.c +1 -0
@@ -289,6 +289,7 @@ static bool nvme_available_path(struct nvme_ns_head *head)if (ns->ana_state !=NVME_ANA_INACCESSIBLE && ns->ana_state !=NVME_ANA_PERSISTENT_LOSS )return true; +return false;case NVME_CTRL_RESETTING :
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 2/2] nvme: delete disk when last path is gone
In reply to Hannes ReineckeQuoted 55 lines · Hannes Reinecke
The multipath code currently deletes the disk only after all references to it are dropped rather than when the last path to that disk is lost. This has been reported to cause problems with some use cases like MD RAID.
This patch implements an alternative behaviour of deleting the disk when the last path is gone, ie the same behaviour as non-multipathed nvme devices. The new behaviour will be selected with the '
fail_if_no_path' attribute, as returning it's arguably the same functionality.Suggested-by Keith Busch <[email protected]>Signed-off-by Hannes Reinecke <[email protected]>--- drivers/nvme/host/core.c | 1 + drivers/nvme/host/multipath.c | 3 ++- drivers/nvme/host/nvme.h | 17 +++++++++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-)drivers/nvme/host/core.c +1
-0@@ -542,6 +542,7 @@ static void nvme_free_ns_head(struct kref *ref) container_of(ref, struct nvme_ns_head, ref);nvme_mpath_remove_disk (head); +nvme_mpath_put_disk (head);ida_simple_remove (&head->subsys->ns_ida, head->instance);cleanup_srcu_struct (&head->srcu);nvme_put_subsystem (head->subsys);drivers/nvme/host/multipath.c +2
-1@@ -724,6 +724,8 @@ void nvme_mpath_add_disk(struct nvme_ns *ns, struct nvme_id_ns *id)void nvme_mpath_remove_disk (struct nvme_ns_head *head) { +if (test_bit (NVME_NSHEAD_FAIL_IF_NO_PATH , &head->flags)) +return ;if (!head->disk)return ;if (head->disk->flags &GENHD_FL_UP )@@ -741,7 +743,6 @@ void nvme_mpath_remove_disk(struct nvme_ns_head *head)*/ head->disk->queue =NULL ; } -put_disk (head->disk); }int nvme_mpath_init (struct nvme_ctrl *ctrl,struct nvme_id_ctrl *id)drivers/nvme/host/nvme.h +0
-0
drivers/nvme/host/nvme.h static inline void nvme_mpath_check_last_path(struct nvme_ns *ns) · line 686
Quoted 8 lines
drivers/nvme/host/nvme.h +3
-2@@ -681,8 +681,12 @@ static inline void nvme_mpath_check_last_path(struct nvme_ns *ns) {struct nvme_ns_head *head = ns->head; -if (head->disk &&list_empty (&head->list)) -kblockd_schedule_work (&head->requeue_work); +if (head->disk &&list_empty (&head->list)) { +if (test_bit (NVME_NSHEAD_FAIL_IF_NO_PATH , &head->flags)) +nvme_mpath_remove_disk (head);
Does it need to call nvme_mpath_remove_disk here ? It looks like it returns with nothing right away if NVME_NSHEAD_FAIL_IF_NO_PATH is set.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 2/2] nvme: delete disk when last path is gone
Quoted 59 lines · Minwoo Im
Quoted 58 lines · Hannes Reinecke
The multipath code currently deletes the disk only after all references to it are dropped rather than when the last path to that disk is lost. This has been reported to cause problems with some use cases like MD RAID.
This patch implements an alternative behaviour of deleting the disk when the last path is gone, ie the same behaviour as non-multipathed nvme devices. The new behaviour will be selected with the '
fail_if_no_path' attribute, as returning it's arguably the same functionality.Suggested-by Keith Busch <[email protected]>Signed-off-by Hannes Reinecke <[email protected]>--- drivers/nvme/host/core.c | 1 + drivers/nvme/host/multipath.c | 3 ++- drivers/nvme/host/nvme.h | 17 +++++++++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-)drivers/nvme/host/core.c +1
-0@@ -542,6 +542,7 @@ static void nvme_free_ns_head(struct kref *ref) container_of(ref, struct nvme_ns_head, ref);nvme_mpath_remove_disk (head); +nvme_mpath_put_disk (head);ida_simple_remove (&head->subsys->ns_ida, head->instance);cleanup_srcu_struct (&head->srcu);nvme_put_subsystem (head->subsys);drivers/nvme/host/multipath.c +2
-1@@ -724,6 +724,8 @@ void nvme_mpath_add_disk(struct nvme_ns *ns, struct nvme_id_ns *id)void nvme_mpath_remove_disk (struct nvme_ns_head *head) { +if (test_bit (NVME_NSHEAD_FAIL_IF_NO_PATH , &head->flags)) +return ;if (!head->disk)return ;if (head->disk->flags &GENHD_FL_UP )@@ -741,7 +743,6 @@ void nvme_mpath_remove_disk(struct nvme_ns_head *head)*/ head->disk->queue =NULL ; } -put_disk (head->disk); }int nvme_mpath_init (struct nvme_ctrl *ctrl,struct nvme_id_ctrl *id)drivers/nvme/host/nvme.h +0
-0@@ -681,8 +681,12 @@ static inline void nvme_mpath_check_last_path(struct nvme_ns *ns) {struct nvme_ns_head *head = ns->head;
Quoted 9 lines
drivers/nvme/host/nvme.h static inline void nvme_mpath_check_last_path(struct nvme_ns *ns) · line 686
Quoted 5 lines
drivers/nvme/host/nvme.h +3
-2-if (head->disk &&list_empty (&head->list)) -kblockd_schedule_work (&head->requeue_work); +if (head->disk &&list_empty (&head->list)) { +if (test_bit (NVME_NSHEAD_FAIL_IF_NO_PATH , &head->flags)) +nvme_mpath_remove_disk (head);Does it need to call
nvme_mpath_remove_diskhere ? It looks like it returns with nothing right away ifNVME_NSHEAD_FAIL_IF_NO_PATHis set.
Argl. Yes, you are correct.
I'll be reworking that one.
Cheers,
Hannes
Signature · 9 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), GF: Felix Imendörffer _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerI don't see any regression here, even if the new features sound useful.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Quoted 2 lines · Christoph Hellwig
I don't see any regression here, even if the new features sound useful.
Have you ever tried MD RAID on nvme-of?
Without this patch MD RAID will _stop_ I/O until the controller reconnects.
If it does. If it doesn't, the controller gets removed (so after some 300 seconds), and MD RAID will get an I/O error, finally. But then you reconnect the failed path, and you end up with a _different_ nvme namespace device.
Requiring you to do manual handholding get the MD RAID into shape again.
With this patch it 'just works' without any interaction.
One might argue if that constitutes a regression (as it's been the behaviour since day 1), but it certainly is impaired functionality as compared to other drivers/subsystems like SCSI. And we can't have that, can we?
Cheers,
Hannes
Signature · 9 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Sagi Grimberg
maintainerRe: [PATCH 2/2] nvme: delete disk when last path is gone
In reply to Hannes ReineckeQuoted 4 lines
The multipath code currently deletes the disk only after all references to it are dropped rather than when the last path to that disk is lost. This has been reported to cause problems with some use cases like MD RAID.
What is the exact problem?
Can you describe what the problem you see now and what you expect to see (unrelated to patch #1)?
Quoted 3 lines
This patch implements an alternative behaviour of deleting the disk when the last path is gone, ie the same behaviour as non-multipathed nvme devices.
But we also don't remove the non-multipath'd nvme device until the last reference drops (e.g. if you have a mounted filesystem on top).
This would be the equivalent to running raid on top of dm-mpath on top of scsi devices right? And if all the mpath device nodes go away the mpath device is deleted even if it has an open reference to it?
Quoted 2 lines
The new behaviour will be selected with the '
fail_if_no_path' attribute, as returning it's arguably the same functionality.
But its not the same functionality.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Sagi Grimberg
maintainerRe: [PATCH 1/2] nvme: add 'fail_if_no_path' sysfs attribute
In reply to Hannes ReineckeQuoted 6 lines · Hannes Reinecke
In some setups like RAID or cluster we need to return an I/O error once all paths are unavailable to allow the upper layers to start their own error recovery (like redirecting I/O to other mirrors). This patch adds a sysfs attribute '
fail_if_no_path' to allow the admin to enable that behaviour instead of the current 'queue until a path becomes available' policy.
Doesn't the same happen today if all the controllers are set with fail_io_fast_tmo=0? nvme_available_path will return false if all the paths have NVME_CTRL_FAILFAST_EXPIRED set.
I think that fail_io_fast_tmo should be settable via sysfs and I think I requested that during the various submission iterations...
I'm not sure this should be controlled on the individual namespace level...
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 1/2] nvme: add 'fail_if_no_path' sysfs attribute
Quoted 10 lines · Sagi Grimberg
Quoted 6 lines · Hannes Reinecke
In some setups like RAID or cluster we need to return an I/O error once all paths are unavailable to allow the upper layers to start their own error recovery (like redirecting I/O to other mirrors). This patch adds a sysfs attribute '
fail_if_no_path' to allow the admin to enable that behaviour instead of the current 'queue until a path becomes available' policy.
Quoted 8 lines
Doesn't the same happen today if all the controllers are set with fail_io_fast_tmo=0?
nvme_available_pathwill return false if all the paths haveNVME_CTRL_FAILFAST_EXPIREDset.I think that
fail_io_fast_tmoshould be settable via sysfs and I think I requested that during the various submission iterations...I'm not sure this should be controlled on the individual namespace level...
Indeed, you are right; using 'fast_io_fail_tmo' works as well here.
So I'll be redoing the patch series and will be replacing this patch with another one adding a per-controller 'fast_io_fail_tmo' sysfs attribute.
Cheers,
Hannes
Signature · 9 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 2/2] nvme: delete disk when last path is gone
In reply to Sagi GrimbergQuoted 10 lines · Sagi Grimberg
Quoted 4 lines
The multipath code currently deletes the disk only after all references to it are dropped rather than when the last path to that disk is lost. This has been reported to cause problems with some use cases like MD RAID.
What is the exact problem?
Can you describe what the problem you see now and what you expect to see (unrelated to patch #1)?
The problem is a difference in behaviour between multipathed and non-multipathed namespaces (ie whether 'CMIC' is set or not). If the CMIC bit is _not_ set, the disk device will be removed once
the controller is gone; if the CMIC bit is set the disk device will be retained, and only removed once the last _reference_ is dropped.
This is causing customer issues, as some vendors produce nearly identical PCI NVMe devices, which differ in the CMIC bit. So depending on which device the customer uses, he might be getting on or the other behaviour.
And this is causing issues when said customer deploys MD RAID on thems;
with one set of devices PCI hotplug works, with the other set of devices it doesn't.
Quoted 7 lines
Quoted 3 lines
This patch implements an alternative behaviour of deleting the disk when the last path is gone, ie the same behaviour as non-multipathed nvme devices.
But we also don't remove the non-multipath'd nvme device until the last reference drops (e.g. if you have a mounted filesystem on top).
Au contraire.
When doing PCI hotplug the controller is removed (in the non-multipathed case), and calling 'put_disk()' during nvme_free_ns().
When doing PCI hotplug in the non-multipathed case, the controller is removed, too, but put_disk() is only called on the namespace itself; the 'nshead' disk is still kept around, and put_disk() on the 'nshead' disk is only called after the last reference is dropped.
Quoted 4 lines
This would be the equivalent to running raid on top of dm-mpath on top of scsi devices right? And if all the mpath device nodes go away the mpath device is deleted even if it has an open reference to it?
See above. The prime motivator behind this patch is to get equivalent behaviour between multipathed and non-multipathed devices. It just so happens that MD RAID exercises this particular issue.
Quoted 4 lines
Quoted 2 lines
The new behaviour will be selected with the '
fail_if_no_path' attribute, as returning it's arguably the same functionality.But its not the same functionality.
Agreed. But as the first patch will be dropped (see my other mail) I'll be redoing the patchset anyway.
Cheers,
Hannes
Signature · 9 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme