nvme/ctrlr: Always access namespaces via getter function
Signed-off-by: Evgeniy Kochetov <evgeniik@nvidia.com> Change-Id: I16e327c0c0485057dc90a87cae316c4d6b62720d Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6504 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
65ff07719d
commit
f0e248586e
@ -738,7 +738,8 @@ nvme_ctrlr_update_ns_ana_states(const struct spdk_nvme_ana_group_descriptor *des
|
||||
continue;
|
||||
}
|
||||
|
||||
ns = &ctrlr->ns[nsid - 1];
|
||||
ns = spdk_nvme_ctrlr_get_ns(ctrlr, nsid);
|
||||
assert(ns != NULL);
|
||||
|
||||
ns->ana_group_id = desc->ana_group_id;
|
||||
ns->ana_state = desc->ana_state;
|
||||
@ -2534,9 +2535,10 @@ nvme_ctrlr_update_namespaces(struct spdk_nvme_ctrlr *ctrlr)
|
||||
bool ns_is_active;
|
||||
|
||||
for (i = 0; i < nn; i++) {
|
||||
struct spdk_nvme_ns *ns = &ctrlr->ns[i];
|
||||
uint32_t nsid = i + 1;
|
||||
struct spdk_nvme_ns *ns = spdk_nvme_ctrlr_get_ns(ctrlr, nsid);
|
||||
|
||||
assert(ns != NULL);
|
||||
nsdata = &ns->nsdata;
|
||||
ns_is_active = spdk_nvme_ctrlr_is_active_ns(ctrlr, nsid);
|
||||
|
||||
@ -3834,7 +3836,8 @@ spdk_nvme_ctrlr_attach_ns(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid,
|
||||
return res;
|
||||
}
|
||||
|
||||
ns = &ctrlr->ns[nsid - 1];
|
||||
ns = spdk_nvme_ctrlr_get_ns(ctrlr, nsid);
|
||||
assert(ns != NULL);
|
||||
return nvme_ns_construct(ns, nsid, ctrlr);
|
||||
}
|
||||
|
||||
@ -3876,7 +3879,8 @@ spdk_nvme_ctrlr_detach_ns(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid,
|
||||
return res;
|
||||
}
|
||||
|
||||
ns = &ctrlr->ns[nsid - 1];
|
||||
ns = spdk_nvme_ctrlr_get_ns(ctrlr, nsid);
|
||||
assert(ns != NULL);
|
||||
/* Inactive NS */
|
||||
nvme_ns_destruct(ns);
|
||||
|
||||
@ -3915,7 +3919,8 @@ spdk_nvme_ctrlr_create_ns(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_ns_dat
|
||||
|
||||
assert(nsid > 0);
|
||||
|
||||
ns = &ctrlr->ns[nsid - 1];
|
||||
ns = spdk_nvme_ctrlr_get_ns(ctrlr, nsid);
|
||||
assert(ns != NULL);
|
||||
/* Inactive NS */
|
||||
res = nvme_ns_construct(ns, nsid, ctrlr);
|
||||
if (res) {
|
||||
@ -3962,7 +3967,8 @@ spdk_nvme_ctrlr_delete_ns(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid)
|
||||
return res;
|
||||
}
|
||||
|
||||
ns = &ctrlr->ns[nsid - 1];
|
||||
ns = spdk_nvme_ctrlr_get_ns(ctrlr, nsid);
|
||||
assert(ns != NULL);
|
||||
nvme_ns_destruct(ns);
|
||||
|
||||
return 0;
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*-
|
||||
* BSD LICENSE
|
||||
*
|
||||
* Copyright (c) Intel Corporation.
|
||||
* All rights reserved.
|
||||
* Copyright (c) Intel Corporation. All rights reserved.
|
||||
* Copyright (c) 2021 Mellanox Technologies LTD. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -93,8 +93,9 @@ spdk_nvme_ctrlr_cmd_io_raw_with_md(struct spdk_nvme_ctrlr *ctrlr,
|
||||
|
||||
/* Caculate metadata length */
|
||||
if (md_buf) {
|
||||
struct spdk_nvme_ns *ns = &ctrlr->ns[cmd->nsid - 1];
|
||||
struct spdk_nvme_ns *ns = spdk_nvme_ctrlr_get_ns(ctrlr, cmd->nsid);
|
||||
|
||||
assert(ns != NULL);
|
||||
assert(ns->sector_size != 0);
|
||||
md_len = len / ns->sector_size * ns->md_size;
|
||||
}
|
||||
|
@ -2,8 +2,8 @@
|
||||
/*-
|
||||
* BSD LICENSE
|
||||
*
|
||||
* Copyright (c) Intel Corporation.
|
||||
* All rights reserved.
|
||||
* Copyright (c) Intel Corporation. All rights reserved.
|
||||
* Copyright (c) 2021 Mellanox Technologies LTD. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -368,7 +368,17 @@ nvme_ctrlr_submit_admin_request(struct spdk_nvme_ctrlr *ctrlr, struct nvme_reque
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define DECLARE_AND_CONSTRUCT_CTRLR() \
|
||||
struct spdk_nvme_ns *
|
||||
spdk_nvme_ctrlr_get_ns(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid)
|
||||
{
|
||||
if (nsid < 1 || nsid > ctrlr->num_ns) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &ctrlr->ns[nsid - 1];
|
||||
}
|
||||
|
||||
#define DECLARE_AND_CONSTRUCT_CTRLR() \
|
||||
struct spdk_nvme_ctrlr ctrlr = {}; \
|
||||
struct spdk_nvme_qpair adminq = {}; \
|
||||
struct nvme_request req; \
|
||||
|
Loading…
Reference in New Issue
Block a user