bdev/nvme: Refactor namespace comparison in add_trid()
In other places, nvme_ns->populated has been used to check an namespace is active for an existing nvme_bdev_ctrlr. We do not need to call spdk_nvme_ctrlr_is_active_ns() again. Follow it in this patch. Besides, factor out the namespace comparison into a small helper function bdev_nvme_compare_ns(). It will be used to check if two controllers have the common namespace for ANA multipath. Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Change-Id: I8aad2f58aae1fd45ca0dd981dded1c406f215ac0 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5359 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
This commit is contained in:
parent
f85b860d27
commit
db436f2dc0
@ -1782,13 +1782,24 @@ nvme_ctrlr_populate_namespaces_done(struct nvme_async_probe_ctx *ctx)
|
|||||||
populate_namespaces_cb(ctx, j, 0);
|
populate_namespaces_cb(ctx, j, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
bdev_nvme_compare_ns(struct spdk_nvme_ns *ns1, struct spdk_nvme_ns *ns2)
|
||||||
|
{
|
||||||
|
const struct spdk_nvme_ns_data *nsdata1, *nsdata2;
|
||||||
|
|
||||||
|
nsdata1 = spdk_nvme_ns_get_data(ns1);
|
||||||
|
nsdata2 = spdk_nvme_ns_get_data(ns2);
|
||||||
|
|
||||||
|
return memcmp(nsdata1->nguid, nsdata2->nguid, sizeof(nsdata1->nguid));
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
bdev_nvme_add_trid(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr, struct spdk_nvme_ctrlr *new_ctrlr,
|
bdev_nvme_add_trid(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr, struct spdk_nvme_ctrlr *new_ctrlr,
|
||||||
struct spdk_nvme_transport_id *trid)
|
struct spdk_nvme_transport_id *trid)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i, nsid;
|
||||||
struct spdk_nvme_ns *ns, *new_ns;
|
struct nvme_bdev_ns *nvme_ns;
|
||||||
const struct spdk_nvme_ns_data *ns_data, *new_ns_data;
|
struct spdk_nvme_ns *new_ns;
|
||||||
struct nvme_bdev_ctrlr_trid *new_trid;
|
struct nvme_bdev_ctrlr_trid *new_trid;
|
||||||
|
|
||||||
assert(nvme_bdev_ctrlr != NULL);
|
assert(nvme_bdev_ctrlr != NULL);
|
||||||
@ -1819,19 +1830,18 @@ bdev_nvme_add_trid(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr, struct spdk_nvme_ctr
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 1; i <= nvme_bdev_ctrlr->num_ns; i++) {
|
for (i = 0; i < nvme_bdev_ctrlr->num_ns; i++) {
|
||||||
if (!spdk_nvme_ctrlr_is_active_ns(nvme_bdev_ctrlr->ctrlr, i)) {
|
nsid = i + 1;
|
||||||
|
|
||||||
|
nvme_ns = nvme_bdev_ctrlr->namespaces[i];
|
||||||
|
if (!nvme_ns->populated) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ns = spdk_nvme_ctrlr_get_ns(nvme_bdev_ctrlr->ctrlr, i);
|
new_ns = spdk_nvme_ctrlr_get_ns(new_ctrlr, nsid);
|
||||||
new_ns = spdk_nvme_ctrlr_get_ns(new_ctrlr, i);
|
|
||||||
assert(ns != NULL);
|
|
||||||
assert(new_ns != NULL);
|
assert(new_ns != NULL);
|
||||||
|
|
||||||
ns_data = spdk_nvme_ns_get_data(ns);
|
if (bdev_nvme_compare_ns(nvme_ns->ns, new_ns) != 0) {
|
||||||
new_ns_data = spdk_nvme_ns_get_data(new_ns);
|
|
||||||
if (memcmp(ns_data->nguid, new_ns_data->nguid, sizeof(ns_data->nguid))) {
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user