bdev/nvme: handle the case for no valid ns when creating bdev
Change-Id: I46d564523ea20bc7c79a3896dfb024d3d5172a93 Signed-off-by: GangCao <gang.cao@intel.com> Reviewed-on: https://review.gerrithub.io/379911 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
4c65ffdfbe
commit
4f1ba029b3
@ -135,7 +135,7 @@ static pthread_mutex_t g_bdev_nvme_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static TAILQ_HEAD(, nvme_ctrlr) g_nvme_ctrlrs = TAILQ_HEAD_INITIALIZER(g_nvme_ctrlrs);
|
||||
static TAILQ_HEAD(, nvme_bdev) g_nvme_bdevs = TAILQ_HEAD_INITIALIZER(g_nvme_bdevs);
|
||||
|
||||
static void nvme_ctrlr_create_bdevs(struct nvme_ctrlr *nvme_ctrlr);
|
||||
static int nvme_ctrlr_create_bdevs(struct nvme_ctrlr *nvme_ctrlr);
|
||||
static int bdev_nvme_library_init(void);
|
||||
static void bdev_nvme_library_fini(void);
|
||||
static int bdev_nvme_queue_cmd(struct nvme_bdev *bdev, struct spdk_nvme_qpair *qpair,
|
||||
@ -830,7 +830,13 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
|
||||
|
||||
spdk_io_device_register(ctrlr, bdev_nvme_create_cb, bdev_nvme_destroy_cb,
|
||||
sizeof(struct nvme_io_channel));
|
||||
nvme_ctrlr_create_bdevs(nvme_ctrlr);
|
||||
|
||||
if (nvme_ctrlr_create_bdevs(nvme_ctrlr) != 0) {
|
||||
spdk_io_device_unregister(ctrlr, NULL);
|
||||
free(nvme_ctrlr->name);
|
||||
free(nvme_ctrlr);
|
||||
return;
|
||||
}
|
||||
|
||||
spdk_bdev_poller_start(&nvme_ctrlr->adminq_timer_poller, bdev_nvme_poll_adminq, ctrlr,
|
||||
spdk_env_get_current_core(), g_nvme_adminq_poll_timeout_us);
|
||||
@ -1092,7 +1098,7 @@ bdev_nvme_library_fini(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
static int
|
||||
nvme_ctrlr_create_bdevs(struct nvme_ctrlr *nvme_ctrlr)
|
||||
{
|
||||
struct nvme_bdev *bdev;
|
||||
@ -1100,6 +1106,7 @@ nvme_ctrlr_create_bdevs(struct nvme_ctrlr *nvme_ctrlr)
|
||||
struct spdk_nvme_ns *ns;
|
||||
const struct spdk_nvme_ctrlr_data *cdata;
|
||||
int ns_id, num_ns;
|
||||
int bdev_created = 0;
|
||||
|
||||
num_ns = spdk_nvme_ctrlr_get_num_ns(ctrlr);
|
||||
cdata = spdk_nvme_ctrlr_get_data(ctrlr);
|
||||
@ -1118,7 +1125,7 @@ nvme_ctrlr_create_bdevs(struct nvme_ctrlr *nvme_ctrlr)
|
||||
|
||||
bdev = calloc(1, sizeof(*bdev));
|
||||
if (!bdev) {
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
bdev->nvme_ctrlr = nvme_ctrlr;
|
||||
@ -1128,7 +1135,7 @@ nvme_ctrlr_create_bdevs(struct nvme_ctrlr *nvme_ctrlr)
|
||||
bdev->disk.name = spdk_sprintf_alloc("%sn%d", nvme_ctrlr->name, spdk_nvme_ns_get_id(ns));
|
||||
if (!bdev->disk.name) {
|
||||
free(bdev);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
bdev->disk.product_name = "NVMe disk";
|
||||
|
||||
@ -1146,7 +1153,11 @@ nvme_ctrlr_create_bdevs(struct nvme_ctrlr *nvme_ctrlr)
|
||||
spdk_bdev_register(&bdev->disk);
|
||||
|
||||
TAILQ_INSERT_TAIL(&g_nvme_bdevs, bdev, link);
|
||||
|
||||
bdev_created++;
|
||||
}
|
||||
|
||||
return (bdev_created > 0) ? 0 : -1;
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
x
Reference in New Issue
Block a user