From 7cc66c0ab196f84f930983ef772ea4cc4dd4ba1c Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Wed, 24 Nov 2021 10:40:25 +0900 Subject: [PATCH] bdev/nvme: Check if ns can be shared when configuring multipath We had not checked the bit 0 of the Namespace Multipath I/O and Namespace Sharing Capabilities (NMIC) field in the Identify Namespace data structure. If the bit 0 of the NMIC is zero, it is likely that namespaces are not identical. We should check if the value of the NMIC first, and do it in this patch. Additionally, it is not usual if the bit 0 of the CMIC and the bit 0 of the NMIC do not match. So in unit tests rename the parameter multi_ctrlr by multipath for ut_attach_ctrlr() and use it for the value of the NMIC. Signed-off-by: Shuhei Matsumoto Change-Id: I6aa7cbcc99be2507dbf18930f7b585a9ea7d0f90 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10380 Community-CI: Broadcom CI Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Jim Harris Reviewed-by: Aleksey Marchuk --- module/bdev/nvme/bdev_nvme.c | 7 +++++++ test/unit/lib/bdev/nvme/bdev_nvme.c/bdev_nvme_ut.c | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/module/bdev/nvme/bdev_nvme.c b/module/bdev/nvme/bdev_nvme.c index 7e0ecf5bd..3abbaf684 100644 --- a/module/bdev/nvme/bdev_nvme.c +++ b/module/bdev/nvme/bdev_nvme.c @@ -2604,6 +2604,13 @@ static int nvme_bdev_add_ns(struct nvme_bdev *bdev, struct nvme_ns *nvme_ns) { struct nvme_ns *tmp_ns; + const struct spdk_nvme_ns_data *nsdata; + + nsdata = spdk_nvme_ns_get_data(nvme_ns->ns); + if (!nsdata->nmic.can_share) { + SPDK_ERRLOG("Namespace cannot be shared.\n"); + return -EINVAL; + } pthread_mutex_lock(&bdev->mutex); diff --git a/test/unit/lib/bdev/nvme/bdev_nvme.c/bdev_nvme_ut.c b/test/unit/lib/bdev/nvme/bdev_nvme.c/bdev_nvme_ut.c index 318dc1688..0b1a47b16 100644 --- a/test/unit/lib/bdev/nvme/bdev_nvme.c/bdev_nvme_ut.c +++ b/test/unit/lib/bdev/nvme/bdev_nvme.c/bdev_nvme_ut.c @@ -371,7 +371,7 @@ spdk_nvme_transport_id_compare(const struct spdk_nvme_transport_id *trid1, static struct spdk_nvme_ctrlr * ut_attach_ctrlr(const struct spdk_nvme_transport_id *trid, uint32_t num_ns, - bool ana_reporting, bool multi_ctrlr) + bool ana_reporting, bool multipath) { struct spdk_nvme_ctrlr *ctrlr; uint32_t i; @@ -413,6 +413,7 @@ ut_attach_ctrlr(const struct spdk_nvme_transport_id *trid, uint32_t num_ns, ctrlr->ns[i].is_active = true; ctrlr->ns[i].ana_state = SPDK_NVME_ANA_OPTIMIZED_STATE; ctrlr->nsdata[i].nsze = 1024; + ctrlr->nsdata[i].nmic.can_share = multipath; } ctrlr->cdata.nn = num_ns; @@ -420,7 +421,7 @@ ut_attach_ctrlr(const struct spdk_nvme_transport_id *trid, uint32_t num_ns, } ctrlr->cdata.cntlid = ++g_ut_cntlid; - ctrlr->cdata.cmic.multi_ctrlr = multi_ctrlr; + ctrlr->cdata.cmic.multi_ctrlr = multipath; ctrlr->cdata.cmic.ana_reporting = ana_reporting; ctrlr->trid = *trid; TAILQ_INIT(&ctrlr->active_io_qpairs);