bdev/nvme: Factor out finding I/O path, nvme_ns and qpair, at I/O submission

Fctor out getting nvme_ns and qpair pointers in _bdev_nvme_submit_request()
into a helper function bdev_nvme_find_io_path().

bdev_nvme_find_io_path() will be used for ocssd_bdev, and hence
locate it in common.h, inline it because it is used in I/O paths.

ocssd_bdev needs not spdk_nvme_ns but nvme_bdev_ns pointer in I/O paths,
and bdev_nvme_find_io_path() returns nvme_bdev_ns.

Besides, move inclusion of likely.h from bdev_nvme.c and bdev_ocssd.c
to common.h.

The next patch will apply bdev_nvme_find_io_path to ocssd_bdev.

By the following patches, bdev_nvme_find_io_path() will take ANA
state into consideration.

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I3817c9f56606021ebea90fdfbcf0656df9faba82
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5528
Community-CI: Broadcom CI
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Shuhei Matsumoto 2021-01-11 00:13:56 +09:00 committed by Tomasz Zawadzki
parent e946792fc4
commit bfef6cdb21
3 changed files with 45 additions and 24 deletions

View File

@ -44,7 +44,6 @@
#include "spdk/nvme_ocssd.h" #include "spdk/nvme_ocssd.h"
#include "spdk/thread.h" #include "spdk/thread.h"
#include "spdk/string.h" #include "spdk/string.h"
#include "spdk/likely.h"
#include "spdk/util.h" #include "spdk/util.h"
#include "spdk/bdev_module.h" #include "spdk/bdev_module.h"
@ -627,6 +626,8 @@ bdev_nvme_get_buf_cb(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io,
struct spdk_bdev *bdev = bdev_io->bdev; struct spdk_bdev *bdev = bdev_io->bdev;
struct nvme_bdev *nbdev = (struct nvme_bdev *)bdev->ctxt; struct nvme_bdev *nbdev = (struct nvme_bdev *)bdev->ctxt;
struct nvme_io_channel *nvme_ch = spdk_io_channel_get_ctx(ch); struct nvme_io_channel *nvme_ch = spdk_io_channel_get_ctx(ch);
struct nvme_bdev_ns *nvme_ns;
struct spdk_nvme_qpair *qpair;
int ret; int ret;
if (!success) { if (!success) {
@ -634,8 +635,13 @@ bdev_nvme_get_buf_cb(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io,
return; return;
} }
ret = bdev_nvme_readv(nbdev->nvme_ns->ns, if (spdk_unlikely(!bdev_nvme_find_io_path(nbdev, nvme_ch, &nvme_ns, &qpair))) {
nvme_ch->qpair, spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_FAILED);
return;
}
ret = bdev_nvme_readv(nvme_ns->ns,
qpair,
(struct nvme_bdev_io *)bdev_io->driver_ctx, (struct nvme_bdev_io *)bdev_io->driver_ctx,
bdev_io->u.bdev.iovs, bdev_io->u.bdev.iovs,
bdev_io->u.bdev.iovcnt, bdev_io->u.bdev.iovcnt,
@ -661,17 +667,18 @@ _bdev_nvme_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_
struct nvme_bdev *nbdev = (struct nvme_bdev *)bdev->ctxt; struct nvme_bdev *nbdev = (struct nvme_bdev *)bdev->ctxt;
struct nvme_bdev_io *nbdev_io = (struct nvme_bdev_io *)bdev_io->driver_ctx; struct nvme_bdev_io *nbdev_io = (struct nvme_bdev_io *)bdev_io->driver_ctx;
struct nvme_bdev_io *nbdev_io_to_abort; struct nvme_bdev_io *nbdev_io_to_abort;
struct nvme_bdev_ns *nvme_ns;
struct spdk_nvme_qpair *qpair;
if (nvme_ch->qpair == NULL) { if (spdk_unlikely(!bdev_nvme_find_io_path(nbdev, nvme_ch, &nvme_ns, &qpair))) {
/* The device is currently resetting */
return -1; return -1;
} }
switch (bdev_io->type) { switch (bdev_io->type) {
case SPDK_BDEV_IO_TYPE_READ: case SPDK_BDEV_IO_TYPE_READ:
if (bdev_io->u.bdev.iovs && bdev_io->u.bdev.iovs[0].iov_base) { if (bdev_io->u.bdev.iovs && bdev_io->u.bdev.iovs[0].iov_base) {
return bdev_nvme_readv(nbdev->nvme_ns->ns, return bdev_nvme_readv(nvme_ns->ns,
nvme_ch->qpair, qpair,
nbdev_io, nbdev_io,
bdev_io->u.bdev.iovs, bdev_io->u.bdev.iovs,
bdev_io->u.bdev.iovcnt, bdev_io->u.bdev.iovcnt,
@ -686,8 +693,8 @@ _bdev_nvme_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_
} }
case SPDK_BDEV_IO_TYPE_WRITE: case SPDK_BDEV_IO_TYPE_WRITE:
return bdev_nvme_writev(nbdev->nvme_ns->ns, return bdev_nvme_writev(nvme_ns->ns,
nvme_ch->qpair, qpair,
nbdev_io, nbdev_io,
bdev_io->u.bdev.iovs, bdev_io->u.bdev.iovs,
bdev_io->u.bdev.iovcnt, bdev_io->u.bdev.iovcnt,
@ -697,8 +704,8 @@ _bdev_nvme_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_
bdev->dif_check_flags); bdev->dif_check_flags);
case SPDK_BDEV_IO_TYPE_COMPARE: case SPDK_BDEV_IO_TYPE_COMPARE:
return bdev_nvme_comparev(nbdev->nvme_ns->ns, return bdev_nvme_comparev(nvme_ns->ns,
nvme_ch->qpair, qpair,
nbdev_io, nbdev_io,
bdev_io->u.bdev.iovs, bdev_io->u.bdev.iovs,
bdev_io->u.bdev.iovcnt, bdev_io->u.bdev.iovcnt,
@ -708,8 +715,8 @@ _bdev_nvme_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_
bdev->dif_check_flags); bdev->dif_check_flags);
case SPDK_BDEV_IO_TYPE_COMPARE_AND_WRITE: case SPDK_BDEV_IO_TYPE_COMPARE_AND_WRITE:
return bdev_nvme_comparev_and_writev(nbdev->nvme_ns->ns, return bdev_nvme_comparev_and_writev(nvme_ns->ns,
nvme_ch->qpair, qpair,
nbdev_io, nbdev_io,
bdev_io->u.bdev.iovs, bdev_io->u.bdev.iovs,
bdev_io->u.bdev.iovcnt, bdev_io->u.bdev.iovcnt,
@ -721,15 +728,15 @@ _bdev_nvme_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_
bdev->dif_check_flags); bdev->dif_check_flags);
case SPDK_BDEV_IO_TYPE_WRITE_ZEROES: case SPDK_BDEV_IO_TYPE_WRITE_ZEROES:
return bdev_nvme_unmap(nbdev->nvme_ns->ns, return bdev_nvme_unmap(nvme_ns->ns,
nvme_ch->qpair, qpair,
nbdev_io, nbdev_io,
bdev_io->u.bdev.offset_blocks, bdev_io->u.bdev.offset_blocks,
bdev_io->u.bdev.num_blocks); bdev_io->u.bdev.num_blocks);
case SPDK_BDEV_IO_TYPE_UNMAP: case SPDK_BDEV_IO_TYPE_UNMAP:
return bdev_nvme_unmap(nbdev->nvme_ns->ns, return bdev_nvme_unmap(nvme_ns->ns,
nvme_ch->qpair, qpair,
nbdev_io, nbdev_io,
bdev_io->u.bdev.offset_blocks, bdev_io->u.bdev.offset_blocks,
bdev_io->u.bdev.num_blocks); bdev_io->u.bdev.num_blocks);
@ -738,8 +745,8 @@ _bdev_nvme_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_
return bdev_nvme_reset(nvme_ch, nbdev_io); return bdev_nvme_reset(nvme_ch, nbdev_io);
case SPDK_BDEV_IO_TYPE_FLUSH: case SPDK_BDEV_IO_TYPE_FLUSH:
return bdev_nvme_flush(nbdev->nvme_ns->ns, return bdev_nvme_flush(nvme_ns->ns,
nvme_ch->qpair, qpair,
nbdev_io, nbdev_io,
bdev_io->u.bdev.offset_blocks, bdev_io->u.bdev.offset_blocks,
bdev_io->u.bdev.num_blocks); bdev_io->u.bdev.num_blocks);
@ -752,16 +759,16 @@ _bdev_nvme_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_
bdev_io->u.nvme_passthru.nbytes); bdev_io->u.nvme_passthru.nbytes);
case SPDK_BDEV_IO_TYPE_NVME_IO: case SPDK_BDEV_IO_TYPE_NVME_IO:
return bdev_nvme_io_passthru(nbdev->nvme_ns->ns, return bdev_nvme_io_passthru(nvme_ns->ns,
nvme_ch->qpair, qpair,
nbdev_io, nbdev_io,
&bdev_io->u.nvme_passthru.cmd, &bdev_io->u.nvme_passthru.cmd,
bdev_io->u.nvme_passthru.buf, bdev_io->u.nvme_passthru.buf,
bdev_io->u.nvme_passthru.nbytes); bdev_io->u.nvme_passthru.nbytes);
case SPDK_BDEV_IO_TYPE_NVME_IO_MD: case SPDK_BDEV_IO_TYPE_NVME_IO_MD:
return bdev_nvme_io_passthru_md(nbdev->nvme_ns->ns, return bdev_nvme_io_passthru_md(nvme_ns->ns,
nvme_ch->qpair, qpair,
nbdev_io, nbdev_io,
&bdev_io->u.nvme_passthru.cmd, &bdev_io->u.nvme_passthru.cmd,
bdev_io->u.nvme_passthru.buf, bdev_io->u.nvme_passthru.buf,

View File

@ -34,7 +34,6 @@
#include "spdk/stdinc.h" #include "spdk/stdinc.h"
#include "spdk/bdev_module.h" #include "spdk/bdev_module.h"
#include "spdk/bdev_zone.h" #include "spdk/bdev_zone.h"
#include "spdk/likely.h"
#include "spdk/log.h" #include "spdk/log.h"
#include "spdk/string.h" #include "spdk/string.h"
#include "spdk/util.h" #include "spdk/util.h"

View File

@ -34,6 +34,7 @@
#ifndef SPDK_COMMON_BDEV_NVME_H #ifndef SPDK_COMMON_BDEV_NVME_H
#define SPDK_COMMON_BDEV_NVME_H #define SPDK_COMMON_BDEV_NVME_H
#include "spdk/likely.h"
#include "spdk/nvme.h" #include "spdk/nvme.h"
#include "spdk/bdev_module.h" #include "spdk/bdev_module.h"
#include "spdk/opal.h" #include "spdk/opal.h"
@ -169,4 +170,18 @@ void nvme_bdev_ctrlr_destruct(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr);
void nvme_bdev_ctrlr_do_destruct(void *ctx); void nvme_bdev_ctrlr_do_destruct(void *ctx);
void nvme_bdev_ns_detach(struct nvme_bdev_ns *nvme_ns); void nvme_bdev_ns_detach(struct nvme_bdev_ns *nvme_ns);
static inline bool
bdev_nvme_find_io_path(struct nvme_bdev *nbdev, struct nvme_io_channel *nvme_ch,
struct nvme_bdev_ns **_nvme_ns, struct spdk_nvme_qpair **_qpair)
{
if (spdk_unlikely(nvme_ch->qpair == NULL)) {
/* The device is currently resetting. */
return false;
}
*_nvme_ns = nbdev->nvme_ns;
*_qpair = nvme_ch->qpair;
return true;
}
#endif /* SPDK_COMMON_BDEV_NVME_H */ #endif /* SPDK_COMMON_BDEV_NVME_H */