[PATCH 1/6] nvme: simplify error logic in nvme_validate_ns()

Hannes Reinecke hare at suse.de
Fri Feb 26 02:10:18 EST 2021


On 2/26/21 2:13 AM, Chao Leng wrote:
> 
> 
> On 2021/2/25 18:55, Hannes Reinecke wrote:
>> We only should remove namespaces when we get fatal error back from
>> the device or when the namespace IDs have changed.
>> So instead of painfully masking out error numbers which might indicate
>> that the error should be ignored we could use an NVME status code
>> to indicated when the namespace should be removed.
>> That simplifies the final logic and makes it less error-prone.
>>
>> Signed-off-by: Hannes Reinecke <hare at suse.de>
>> ---
>>   drivers/nvme/host/core.c | 6 +++---
>>   1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
>> index d77f3f26d8d3..13ed7d3fbbb3 100644
>> --- a/drivers/nvme/host/core.c
>> +++ b/drivers/nvme/host/core.c
>> @@ -4036,7 +4036,7 @@ static void nvme_ns_remove_by_nsid(struct 
>> nvme_ctrl *ctrl, u32 nsid)
>>   static void nvme_validate_ns(struct nvme_ns *ns, struct nvme_ns_ids 
>> *ids)
>>   {
>>       struct nvme_id_ns *id;
>> -    int ret = -ENODEV;
>> +    int ret = NVME_SC_INVALID_NS | NVME_SC_DNR;
>>       if (test_bit(NVME_NS_DEAD, &ns->flags))
>>           goto out;
>> @@ -4045,7 +4045,7 @@ static void nvme_validate_ns(struct nvme_ns *ns, 
>> struct nvme_ns_ids *ids)
>>       if (ret)
>>           goto out;
>> -    ret = -ENODEV;
>> +    ret = NVME_SC_INVALID_NS | NVME_SC_DNR;
>>       if (!nvme_ns_ids_equal(&ns->head->ids, ids)) {
>>           dev_err(ns->ctrl->device,
>>               "identifiers changed for nsid %d\n", ns->head->ns_id);
>> @@ -4063,7 +4063,7 @@ static void nvme_validate_ns(struct nvme_ns *ns, 
>> struct nvme_ns_ids *ids)
>>        *
>>        * TODO: we should probably schedule a delayed retry here.
>>        */
>> -    if (ret && ret != -ENOMEM && !(ret > 0 && !(ret & NVME_SC_DNR)))
>> +    if (ret > 0 && (ret & NVME_SC_DNR))
> nvme_identify_ns may return -NODEV.
> if ret == -NODEV, also need to remove namespaces.

You are correct. Will be updating the patch.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare at suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer



More information about the Linux-nvme mailing list