bdev/nvme: Remove nvme_bdev_ctrlr parameter from create/destroy_qpair()

nvme_bdev_ctrlr pointer is already cached to nvme_io_channel.
Hence let's remove it from the helper functions, bdev_nvme_create_qpair()
and bdev_nvme_destroy_qpair().

The following minor fixes are done together in this patch.

Fix the error paths of bdev_nvme_create_qpair() because
bdev_nvme_destroy_qpair() cannot be used as is in this case.

When calling bdev_ocssd_destroy_io_channel(), check if nvme_ch->ocssd_ch
is not NULL instead of spdk_nvme_ctrlr_is_ocssd_supported().

Cache nvme_bdev_ctrlr to nvme_io_channel just before calling
bdev_nvme_create_qpair() because the pointer is more associated
with qpair.

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: Ic96b7d0fa27dd1f32d573eecdc9d4eacc5593bde
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5511
Community-CI: Broadcom CI
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
This commit is contained in:
Shuhei Matsumoto 2020-12-09 06:51:00 +09:00 committed by Tomasz Zawadzki
parent 4dc86079b7
commit eebd35116d

View File

@ -307,8 +307,7 @@ bdev_nvme_flush(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
} }
static void static void
bdev_nvme_destroy_qpair(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr, bdev_nvme_destroy_qpair(struct nvme_io_channel *nvme_ch)
struct nvme_io_channel *nvme_ch)
{ {
assert(nvme_ch->group != NULL); assert(nvme_ch->group != NULL);
@ -320,10 +319,9 @@ bdev_nvme_destroy_qpair(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr,
} }
static int static int
bdev_nvme_create_qpair(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr, bdev_nvme_create_qpair(struct nvme_io_channel *nvme_ch)
struct nvme_io_channel *nvme_ch)
{ {
struct spdk_nvme_ctrlr *ctrlr = nvme_bdev_ctrlr->ctrlr; struct spdk_nvme_ctrlr *ctrlr = nvme_ch->ctrlr->ctrlr;
struct spdk_nvme_io_qpair_opts opts; struct spdk_nvme_io_qpair_opts opts;
int rc; int rc;
@ -343,19 +341,22 @@ bdev_nvme_create_qpair(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr,
rc = spdk_nvme_poll_group_add(nvme_ch->group->group, nvme_ch->qpair); rc = spdk_nvme_poll_group_add(nvme_ch->group->group, nvme_ch->qpair);
if (rc != 0) { if (rc != 0) {
SPDK_ERRLOG("Unable to begin polling on NVMe Channel.\n"); SPDK_ERRLOG("Unable to begin polling on NVMe Channel.\n");
goto err; goto err_pg;
} }
rc = spdk_nvme_ctrlr_connect_io_qpair(ctrlr, nvme_ch->qpair); rc = spdk_nvme_ctrlr_connect_io_qpair(ctrlr, nvme_ch->qpair);
if (rc != 0) { if (rc != 0) {
SPDK_ERRLOG("Unable to connect I/O qpair.\n"); SPDK_ERRLOG("Unable to connect I/O qpair.\n");
goto err; goto err_connect;
} }
return 0; return 0;
err: err_connect:
bdev_nvme_destroy_qpair(nvme_bdev_ctrlr, nvme_ch); spdk_nvme_poll_group_remove(nvme_ch->group->group, nvme_ch->qpair);
err_pg:
spdk_nvme_ctrlr_free_io_qpair(nvme_ch->qpair);
return rc; return rc;
} }
@ -424,12 +425,11 @@ _bdev_nvme_reset_create_qpairs_done(struct spdk_io_channel_iter *i, int status)
static void static void
_bdev_nvme_reset_create_qpair(struct spdk_io_channel_iter *i) _bdev_nvme_reset_create_qpair(struct spdk_io_channel_iter *i)
{ {
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr = spdk_io_channel_iter_get_io_device(i);
struct spdk_io_channel *_ch = spdk_io_channel_iter_get_channel(i); struct spdk_io_channel *_ch = spdk_io_channel_iter_get_channel(i);
struct nvme_io_channel *nvme_ch = spdk_io_channel_get_ctx(_ch); struct nvme_io_channel *nvme_ch = spdk_io_channel_get_ctx(_ch);
int rc; int rc;
rc = bdev_nvme_create_qpair(nvme_bdev_ctrlr, nvme_ch); rc = bdev_nvme_create_qpair(nvme_ch);
spdk_for_each_channel_continue(i, rc); spdk_for_each_channel_continue(i, rc);
} }
@ -825,8 +825,6 @@ bdev_nvme_create_cb(void *io_device, void *ctx_buf)
struct spdk_io_channel *pg_ch = NULL; struct spdk_io_channel *pg_ch = NULL;
int rc; int rc;
nvme_ch->ctrlr = nvme_bdev_ctrlr;
if (spdk_nvme_ctrlr_is_ocssd_supported(nvme_bdev_ctrlr->ctrlr)) { if (spdk_nvme_ctrlr_is_ocssd_supported(nvme_bdev_ctrlr->ctrlr)) {
rc = bdev_ocssd_create_io_channel(nvme_ch); rc = bdev_ocssd_create_io_channel(nvme_ch);
if (rc != 0) { if (rc != 0) {
@ -850,7 +848,9 @@ bdev_nvme_create_cb(void *io_device, void *ctx_buf)
TAILQ_INIT(&nvme_ch->pending_resets); TAILQ_INIT(&nvme_ch->pending_resets);
rc = bdev_nvme_create_qpair(nvme_bdev_ctrlr, nvme_ch); nvme_ch->ctrlr = nvme_bdev_ctrlr;
rc = bdev_nvme_create_qpair(nvme_ch);
if (rc != 0) { if (rc != 0) {
goto err_qpair; goto err_qpair;
} }
@ -860,7 +860,7 @@ bdev_nvme_create_cb(void *io_device, void *ctx_buf)
err_qpair: err_qpair:
spdk_put_io_channel(pg_ch); spdk_put_io_channel(pg_ch);
err_pg_ch: err_pg_ch:
if (spdk_nvme_ctrlr_is_ocssd_supported(nvme_bdev_ctrlr->ctrlr)) { if (nvme_ch->ocssd_ch) {
bdev_ocssd_destroy_io_channel(nvme_ch); bdev_ocssd_destroy_io_channel(nvme_ch);
} }
@ -870,16 +870,15 @@ err_pg_ch:
static void static void
bdev_nvme_destroy_cb(void *io_device, void *ctx_buf) bdev_nvme_destroy_cb(void *io_device, void *ctx_buf)
{ {
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr = io_device;
struct nvme_io_channel *nvme_ch = ctx_buf; struct nvme_io_channel *nvme_ch = ctx_buf;
assert(nvme_ch->group != NULL); assert(nvme_ch->group != NULL);
if (spdk_nvme_ctrlr_is_ocssd_supported(nvme_bdev_ctrlr->ctrlr)) { if (nvme_ch->ocssd_ch != NULL) {
bdev_ocssd_destroy_io_channel(nvme_ch); bdev_ocssd_destroy_io_channel(nvme_ch);
} }
bdev_nvme_destroy_qpair(nvme_bdev_ctrlr, nvme_ch); bdev_nvme_destroy_qpair(nvme_ch);
spdk_put_io_channel(spdk_io_channel_from_ctx(nvme_ch->group)); spdk_put_io_channel(spdk_io_channel_from_ctx(nvme_ch->group));
} }