Skip to content

Commit 0a05226

Browse files
author
Christoph Hellwig
committed
nvme: refactor nvme_validate_ns
Move the logic to revalidate the block_device size or remove the namespace from the caller into nvme_validate_ns. This removes the return value and thus the status code translation. Additionally it also catches non-permanent errors from nvme_update_ns_info using the existing logic. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Keith Busch <kbusch@kernel.org> Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com>
1 parent b2dc748 commit 0a05226

1 file changed

Lines changed: 17 additions & 20 deletions

File tree

drivers/nvme/host/core.c

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3899,6 +3899,7 @@ static void nvme_ns_remove(struct nvme_ns *ns)
38993899
if (test_and_set_bit(NVME_NS_REMOVING, &ns->flags))
39003900
return;
39013901

3902+
set_capacity(ns->disk, 0);
39023903
nvme_fault_inject_fini(&ns->fault_inject);
39033904

39043905
mutex_lock(&ns->ctrl->subsys->lock);
@@ -3936,58 +3937,54 @@ static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid)
39363937
}
39373938
}
39383939

3939-
static int nvme_validate_ns(struct nvme_ns *ns, struct nvme_ns_ids *ids)
3940+
static void nvme_validate_ns(struct nvme_ns *ns, struct nvme_ns_ids *ids)
39403941
{
39413942
struct nvme_ctrl *ctrl = ns->ctrl;
39423943
struct nvme_id_ns *id;
3943-
int ret = 0;
3944+
int ret = -ENODEV;
39443945

3945-
if (test_bit(NVME_NS_DEAD, &ns->flags)) {
3946-
set_capacity(ns->disk, 0);
3947-
return -ENODEV;
3948-
}
3946+
if (test_bit(NVME_NS_DEAD, &ns->flags))
3947+
goto out;
39493948

39503949
ret = nvme_identify_ns(ctrl, ns->head->ns_id, ids, &id);
39513950
if (ret)
39523951
goto out;
39533952

3953+
ret = -ENODEV;
39543954
if (!nvme_ns_ids_equal(&ns->head->ids, ids)) {
39553955
dev_err(ctrl->device,
39563956
"identifiers changed for nsid %d\n", ns->head->ns_id);
3957-
ret = -ENODEV;
3958-
goto free_id;
3957+
goto out_free_id;
39593958
}
39603959

39613960
ret = nvme_update_ns_info(ns, id);
3962-
free_id:
3961+
3962+
out_free_id:
39633963
kfree(id);
39643964
out:
39653965
/*
3966-
* Only fail the function if we got a fatal error back from the
3966+
* Only remove the namespace if we got a fatal error back from the
39673967
* device, otherwise ignore the error and just move on.
3968+
*
3969+
* TODO: we should probably schedule a delayed retry here.
39683970
*/
3969-
if (ret == -ENOMEM || (ret > 0 && !(ret & NVME_SC_DNR)))
3970-
ret = 0;
3971-
else if (ret > 0)
3972-
ret = blk_status_to_errno(nvme_error_status(ret));
3973-
return ret;
3971+
if (ret && ret != -ENOMEM && !(ret > 0 && !(ret & NVME_SC_DNR)))
3972+
nvme_ns_remove(ns);
3973+
else
3974+
revalidate_disk_size(ns->disk, true);
39743975
}
39753976

39763977
static void nvme_validate_or_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
39773978
{
39783979
struct nvme_ns_ids ids = { };
39793980
struct nvme_ns *ns;
3980-
int ret;
39813981

39823982
if (nvme_identify_ns_descs(ctrl, nsid, &ids))
39833983
return;
39843984

39853985
ns = nvme_find_get_ns(ctrl, nsid);
39863986
if (ns) {
3987-
ret = nvme_validate_ns(ns, &ids);
3988-
revalidate_disk_size(ns->disk, ret == 0);
3989-
if (ret)
3990-
nvme_ns_remove(ns);
3987+
nvme_validate_ns(ns, &ids);
39913988
nvme_put_ns(ns);
39923989
return;
39933990
}

0 commit comments

Comments
 (0)