Patches for 4.7
Just a collection of small and unrelated patches.
Keith Busch (3):
NVMe: Return ENODEV error on invalid namespace
NVMe: Short-cut removal on surprise hot-unplug
NVMe: Set capacity to 0 on all unusable namespaces
drivers/nvme/host/core.c | 36 ++++++++++++++++++++++++------------ drivers/nvme/host/nvme.h | 3 +++ drivers/nvme/host/pci.c | 8 ++++++-- 3 files changed, 33 insertions(+), 14 deletions(-)
Signature · 1 line
2.7.2
PATCH 1/3 NVMe: Return ENODEV error on invalid namespace
If there is no namespace associated with the request, return an error code that notifies the application the device isn't there.
--- drivers/nvme/host/nvme.h | 2 ++ drivers/nvme/host/pci.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/nvme/host/nvme.h +2 -0
@@ -193,6 +193,8 @@ static inline int nvme_error_status(u16 status)switch (status &0x7ff ) {case NVME_SC_SUCCESS :return 0 ; +case NVME_SC_INVALID_NS : +return -ENODEV ;case NVME_SC_CAP_EXCEEDED :return -ENOSPC ;default :
drivers/nvme/host/pci.c +2 -2
@@ -600,7 +600,7 @@ static int nvme_queue_rq(struct blk_mq_hw_ctx *hctx,if (ns && !test_bit (NVME_NS_DEAD , &ns->flags)) ret =BLK_MQ_RQ_QUEUE_BUSY ;else - ret =BLK_MQ_RQ_QUEUE_ERROR ; +blk_mq_end_request (req, -ENODEV );spin_unlock_irq (&nvmeq->q_lock); goto out; }
@@ -931,7 +931,7 @@ static void nvme_cancel_io(struct request *req, void *data, bool reserved) status =NVME_SC_ABORT_REQ ;if (blk_queue_dying (req->q)) - status |=NVME_SC_DNR ; + status =NVME_SC_INVALID_NS |NVME_SC_DNR ;blk_mq_complete_request (req, status); }
Signature · 1 line
2.7.2
PATCH 2/3 NVMe: Short-cut removal on surprise hot-unplug
In reply to Keith BuschThis patch adds a new state that when set has the core automatically kill request queues prior to removing namespaces. If PCI device is not present at the time the nvme driver's remove is called, we can kill all IO queues immediately instead of waiting for the watchdog thread to do that at its polling interval. This improves scenarios where multiple hot plug events occur at the same time since it doesn't block pci enumeration.
--- drivers/nvme/host/core.c | 12 ++++++++++++ drivers/nvme/host/nvme.h | 1 + drivers/nvme/host/pci.c | 4 ++++ 3 files changed, 17 insertions(+)
drivers/nvme/host/core.c +12 -0
@@ -95,6 +95,15 @@ bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl,break ; }break ; +case NVME_CTRL_DEAD : +switch (old_state) { +case NVME_CTRL_DELETING : + changed = true; +/* FALLTHRU */ +default : +break ; + } +break ;default :break ; }
@@ -1584,6 +1593,9 @@ void nvme_remove_namespaces(struct nvme_ctrl *ctrl) {struct nvme_ns *ns, *next; +if (ctrl->state ==NVME_CTRL_DEAD ) +nvme_kill_queues (ctrl); +mutex_lock (&ctrl->namespaces_mutex);list_for_each_entry_safe (ns, next, &ctrl->namespaces, list)nvme_ns_remove (ns);
drivers/nvme/host/nvme.h +1 -0
@@ -72,6 +72,7 @@ enum nvme_ctrl_state {NVME_CTRL_LIVE ,NVME_CTRL_RESETTING ,NVME_CTRL_DELETING , + NVME_CTRL_DEAD, }; struct nvme_ctrl {
drivers/nvme/host/pci.c +4 -0
@@ -2019,6 +2019,10 @@ static void nvme_remove(struct pci_dev *pdev)nvme_change_ctrl_state (&dev->ctrl,NVME_CTRL_DELETING );pci_set_drvdata (pdev,NULL ); + +if (!pci_device_is_present (pdev)) +nvme_change_ctrl_state (&dev->ctrl,NVME_CTRL_DEAD ); +nvme_uninit_ctrl (&dev->ctrl);nvme_dev_disable (dev, true);flush_work (&dev->reset_work);
Signature · 1 line
2.7.2
PATCH 3/3 NVMe: Set capacity to 0 on all unusable namespaces
In reply to Keith BuschSet the disk capacity to 0 if unable to identify a namespace for any reason. This way revalidating detached namespaces will be deleted quicker since dirty data can't be sync'ed.
--- drivers/nvme/host/core.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/nvme/host/core.c +12 -12
@@ -771,31 +771,27 @@ static void nvme_config_discard(struct nvme_ns *ns)static int nvme_revalidate_disk (struct gendisk *disk) {struct nvme_ns *ns = disk->private_data; -struct nvme_id_ns *id; +struct nvme_id_ns *id =NULL ;u8 lbaf, pi_type;u16 old_ms;unsigned short bs; -if (test_bit (NVME_NS_DEAD , &ns->flags)) { -set_capacity (disk,0 ); -return -ENODEV ; - } +if (test_bit (NVME_NS_DEAD , &ns->flags)) + goto no_dev; +if (nvme_identify_ns (ns->ctrl, ns->ns_id, &id)) {dev_warn (disk_to_dev (ns->disk),"%s: Identify failure\n" , __func__); -return -ENODEV ; - } -if (id->ncap ==0 ) { -kfree (id); -return -ENODEV ; + goto no_dev; } +if (id->ncap ==0 ) + goto no_dev;if (nvme_nvm_ns_supported (ns, id) && ns->type !=NVME_NS_LIGHTNVM ) {if (nvme_nvm_register (ns->queue, disk->disk_name)) {dev_warn (disk_to_dev (ns->disk),"%s: LightNVM init failure\n" , __func__); -kfree (id); -return -ENODEV ; + goto no_dev; } ns->type =NVME_NS_LIGHTNVM ; }
@@ -845,6 +841,10 @@ static int nvme_revalidate_disk(struct gendisk *disk)kfree (id);return 0 ; + no_dev: +kfree (id); +set_capacity (disk,0 ); +return -ENODEV ; }static char nvme_pr_type (enum pr_type type)
Signature · 1 line
2.7.2
PATCH 1/3 NVMe: Return ENODEV error on invalid namespace
In reply to Keith BuschQuoted 2 lines · Keith Busch
If there is no namespace associated with the request, return an error code that notifies the application the device isn't there.
I think we're heading in the wrong direction here. I actually had some discussion with Jens and Marting on how we should get rid of overloading random errnos in the block layer and instead have block layer error codes.
What applications care? And where are the meanings of these error codes documented?
PATCH 2/3 NVMe: Short-cut removal on surprise hot-unplug
In reply to Keith Buschdrivers/nvme/host/core.c void nvme_remove_namespaces(struct nvme_ctrl *ctrl) · line 1601
Quoted 10 lines
drivers/nvme/host/core.c +3
-0@@ -1584,6 +1593,9 @@ void nvme_remove_namespaces(struct nvme_ctrl *ctrl) {struct nvme_ns *ns, *next; +if (ctrl->state ==NVME_CTRL_DEAD ) +nvme_kill_queues (ctrl); +mutex_lock (&ctrl->namespaces_mutex);list_for_each_entry_safe (ns, next, &ctrl->namespaces, list)nvme_ns_remove (ns);
Not happy about so much magic.. At least add comments explaining why you're doing this, and that it's just an optimization.
PATCH 3/3 NVMe: Set capacity to 0 on all unusable namespaces
In reply to Keith BuschQuoted 40 lines · Keith Busch
Set the disk capacity to 0 if unable to identify a namespace for any reason. This way revalidating detached namespaces will be deleted quicker since dirty data can't be sync'ed.
Signed-off-by Keith Busch <keith.busch at intel.com>--- drivers/nvme/host/core.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)drivers/nvme/host/core.c +5
-10@@ -771,31 +771,27 @@ static void nvme_config_discard(struct nvme_ns *ns)static int nvme_revalidate_disk (struct gendisk *disk) {struct nvme_ns *ns = disk->private_data; -struct nvme_id_ns *id; +struct nvme_id_ns *id =NULL ;u8 lbaf, pi_type;u16 old_ms;unsigned short bs; -if (test_bit (NVME_NS_DEAD , &ns->flags)) { -set_capacity (disk,0 ); -return -ENODEV ; - } +if (test_bit (NVME_NS_DEAD , &ns->flags)) + goto no_dev; +if (nvme_identify_ns (ns->ctrl, ns->ns_id, &id)) {dev_warn (disk_to_dev (ns->disk),"%s: Identify failure\n" , __func__); -return -ENODEV ; - } -if (id->ncap ==0 ) { -kfree (id); -return -ENODEV ; + goto no_dev; }
drivers/nvme/host/core.c static void nvme_config_discard(struct nvme_ns *ns) · line 794
Quoted 10 lines
drivers/nvme/host/core.c +3
-2+if (id->ncap ==0 ) + goto no_dev;if (nvme_nvm_ns_supported (ns, id) && ns->type !=NVME_NS_LIGHTNVM ) {if (nvme_nvm_register (ns->queue, disk->disk_name)) {dev_warn (disk_to_dev (ns->disk),"%s: LightNVM init failure\n" , __func__); -kfree (id); -return -ENODEV ; + goto no_dev;
Not related to this patch, but: the lightnvm code really needs to go away here - the NVMe spec is clear that the Identify Namespace structure is NVM Command set specific, and our whole block device implementation shouldn't even be called for lightnvm.
Otherwise this looks fine to me,
PATCH 1/3 NVMe: Return ENODEV error on invalid namespace
In reply to Christoph HellwigQuoted 11 lines
-----Original Message-----
From: Christoph Hellwig [mailto:hch at infradead.org]
Sent: Tuesday, May 03, 2016 1:58 AM
To: Busch, Keith
Cc: Jens Axboe; Christoph Hellwig; linux-nvme at lists.infradead.org
Subject: Re: [PATCH-4.7 1/3] NVMe: Return ENODEV error on invalid namespaceQuoted 2 lines · Keith Busch
If there is no namespace associated with the request, return an error code that notifies the application the device isn't there.
Quoted 7 lines
I think we're heading in the wrong direction here. I actually had some discussion with Jens and Marting on how we should get rid of overloading random errnos in the block layer and instead have block layer error codes.
What applications care? And where are the meanings of these error codes documented?
This was added at the joint request from one OSV and IHV. I've no idea what they're software is doing with this, but they say it doesn't do the right thing with 'EIO'. ENODEV for invalid namespaces sounded like a reasonable error.
PATCH 1/3 NVMe: Return ENODEV error on invalid namespace
Quoted 4 lines · Keith
This was added at the joint request from one OSV and IHV. I've no idea what they're software is doing with this, but they say it doesn't do the right thing with 'EIO'. ENODEV for invalid namespaces sounded like a reasonable error.
Well, I'll have to say "no" to this until said OSV and IHV can explain why they need this in detail on linux-nvme. And even then we'll probably need a different solution for them.
PATCH 2/3 NVMe: Short-cut removal on surprise hot-unplug
In reply to Christoph HellwigQuoted 4 lines · Christoph Hellwig
Quoted 4 lines
drivers/nvme/host/core.c +0
-0@@ -1584,6 +1593,9 @@ void nvme_remove_namespaces(struct nvme_ctrl *ctrl) {struct nvme_ns *ns, *next;
Quoted 9 lines
drivers/nvme/host/core.c void nvme_remove_namespaces(struct nvme_ctrl *ctrl) · line 1601
Quoted 6 lines
drivers/nvme/host/core.c +3
-0+if (ctrl->state ==NVME_CTRL_DEAD ) +nvme_kill_queues (ctrl); +mutex_lock (&ctrl->namespaces_mutex);list_for_each_entry_safe (ns, next, &ctrl->namespaces, list)nvme_ns_remove (ns);Not happy about so much magic.. At least add comments explaining why you're doing this, and that it's just an optimization.
We could just call nvme_kill_queues from the pci driver's nvme_remove instead of adding the state. I just thought this was universally useful for a non-graceful disconnect.
PATCH 2/3 NVMe: Short-cut removal on surprise hot-unplug
Quoted 15 lines · Keith Busch
Quoted 4 lines · Christoph Hellwig
Quoted 4 lines
drivers/nvme/host/core.c +0
-0@@ -1584,6 +1593,9 @@ void nvme_remove_namespaces(struct nvme_ctrl *ctrl) {struct nvme_ns *ns, *next;Quoted 9 lines
drivers/nvme/host/core.c void nvme_remove_namespaces(struct nvme_ctrl *ctrl) · line 1601
Quoted 6 lines
drivers/nvme/host/core.c +3
-0+if (ctrl->state ==NVME_CTRL_DEAD ) +nvme_kill_queues (ctrl); +mutex_lock (&ctrl->namespaces_mutex);list_for_each_entry_safe (ns, next, &ctrl->namespaces, list)nvme_ns_remove (ns);Not happy about so much magic.. At least add comments explaining why you're doing this, and that it's just an optimization.
Quoted 3 lines
We could just call
nvme_kill_queuesfrom the pci driver'snvme_removeinstead of adding the state. I just thought this was universally useful for a non-graceful disconnect.
I think it's useful, it's just a little too magic to go without a comment. Can you add comments explaining it and resend?