Commit e49f77ec authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Tomasz Zawadzki
Browse files

bdev/nvme: find_io_path() returns io_path instead of ns and qpair



We have io_path structure now and returning io_path rather than
ns and qpair match the function name. The following patches will
cache the returned io_path into nvme_bdev_io.

Signed-off-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I5d773da18591fc324667f6b5c489a38f497bf3d8
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9295


Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
parent c19ec843
Loading
Loading
Loading
Loading
+82 −74
Original line number Original line Diff line number Diff line
@@ -151,43 +151,42 @@ static void nvme_ctrlr_populate_namespaces_done(struct nvme_ctrlr *nvme_ctrlr,
		struct nvme_async_probe_ctx *ctx);
		struct nvme_async_probe_ctx *ctx);
static int bdev_nvme_library_init(void);
static int bdev_nvme_library_init(void);
static void bdev_nvme_library_fini(void);
static void bdev_nvme_library_fini(void);
static int bdev_nvme_readv(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
static int bdev_nvme_readv(struct nvme_io_path *io_path,
			   struct nvme_bdev_io *bio,
			   struct nvme_bdev_io *bio,
			   struct iovec *iov, int iovcnt, void *md, uint64_t lba_count, uint64_t lba,
			   struct iovec *iov, int iovcnt, void *md, uint64_t lba_count, uint64_t lba,
			   uint32_t flags, struct spdk_bdev_ext_io_opts *ext_opts);
			   uint32_t flags, struct spdk_bdev_ext_io_opts *ext_opts);
static int bdev_nvme_no_pi_readv(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
static int bdev_nvme_no_pi_readv(struct nvme_io_path *io_path,
				 struct nvme_bdev_io *bio,
				 struct nvme_bdev_io *bio,
				 struct iovec *iov, int iovcnt, void *md, uint64_t lba_count, uint64_t lba);
				 struct iovec *iov, int iovcnt, void *md, uint64_t lba_count, uint64_t lba);
static int bdev_nvme_writev(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
static int bdev_nvme_writev(struct nvme_io_path *io_path,
			    struct nvme_bdev_io *bio,
			    struct nvme_bdev_io *bio,
			    struct iovec *iov, int iovcnt, void *md, uint64_t lba_count, uint64_t lba,
			    struct iovec *iov, int iovcnt, void *md, uint64_t lba_count, uint64_t lba,
			    uint32_t flags, struct spdk_bdev_ext_io_opts *ext_opts);
			    uint32_t flags, struct spdk_bdev_ext_io_opts *ext_opts);
static int bdev_nvme_zone_appendv(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
static int bdev_nvme_zone_appendv(struct nvme_io_path *io_path,
				  struct nvme_bdev_io *bio,
				  struct nvme_bdev_io *bio,
				  struct iovec *iov, int iovcnt, void *md, uint64_t lba_count,
				  struct iovec *iov, int iovcnt, void *md, uint64_t lba_count,
				  uint64_t zslba, uint32_t flags);
				  uint64_t zslba, uint32_t flags);
static int bdev_nvme_comparev(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
static int bdev_nvme_comparev(struct nvme_io_path *io_path,
			      struct nvme_bdev_io *bio,
			      struct nvme_bdev_io *bio,
			      struct iovec *iov, int iovcnt, void *md, uint64_t lba_count, uint64_t lba,
			      struct iovec *iov, int iovcnt, void *md, uint64_t lba_count, uint64_t lba,
			      uint32_t flags);
			      uint32_t flags);
static int bdev_nvme_comparev_and_writev(struct spdk_nvme_ns *ns,
static int bdev_nvme_comparev_and_writev(struct nvme_io_path *io_path,
		struct spdk_nvme_qpair *qpair,
		struct nvme_bdev_io *bio, struct iovec *cmp_iov, int cmp_iovcnt, struct iovec *write_iov,
		struct nvme_bdev_io *bio, struct iovec *cmp_iov, int cmp_iovcnt, struct iovec *write_iov,
		int write_iovcnt, void *md, uint64_t lba_count, uint64_t lba,
		int write_iovcnt, void *md, uint64_t lba_count, uint64_t lba,
		uint32_t flags);
		uint32_t flags);
static int bdev_nvme_get_zone_info(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
static int bdev_nvme_get_zone_info(struct nvme_io_path *io_path,
				   struct nvme_bdev_io *bio, uint64_t zone_id, uint32_t num_zones,
				   struct nvme_bdev_io *bio, uint64_t zone_id, uint32_t num_zones,
				   struct spdk_bdev_zone_info *info);
				   struct spdk_bdev_zone_info *info);
static int bdev_nvme_zone_management(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
static int bdev_nvme_zone_management(struct nvme_io_path *io_path,
				     struct nvme_bdev_io *bio, uint64_t zone_id,
				     struct nvme_bdev_io *bio, uint64_t zone_id,
				     enum spdk_bdev_zone_action action);
				     enum spdk_bdev_zone_action action);
static int bdev_nvme_admin_passthru(struct nvme_bdev_channel *nbdev_ch,
static int bdev_nvme_admin_passthru(struct nvme_bdev_channel *nbdev_ch,
				    struct nvme_bdev_io *bio,
				    struct nvme_bdev_io *bio,
				    struct spdk_nvme_cmd *cmd, void *buf, size_t nbytes);
				    struct spdk_nvme_cmd *cmd, void *buf, size_t nbytes);
static int bdev_nvme_io_passthru(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
static int bdev_nvme_io_passthru(struct nvme_io_path *io_path,
				 struct nvme_bdev_io *bio,
				 struct nvme_bdev_io *bio,
				 struct spdk_nvme_cmd *cmd, void *buf, size_t nbytes);
				 struct spdk_nvme_cmd *cmd, void *buf, size_t nbytes);
static int bdev_nvme_io_passthru_md(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
static int bdev_nvme_io_passthru_md(struct nvme_io_path *io_path,
				    struct nvme_bdev_io *bio,
				    struct nvme_bdev_io *bio,
				    struct spdk_nvme_cmd *cmd, void *buf, size_t nbytes, void *md_buf, size_t md_len);
				    struct spdk_nvme_cmd *cmd, void *buf, size_t nbytes, void *md_buf, size_t md_len);
static int bdev_nvme_abort(struct nvme_bdev_channel *nbdev_ch,
static int bdev_nvme_abort(struct nvme_bdev_channel *nbdev_ch,
@@ -646,9 +645,8 @@ bdev_nvme_destroy_bdev_channel_cb(void *io_device, void *ctx_buf)
	_bdev_nvme_delete_io_paths(nbdev_ch);
	_bdev_nvme_delete_io_paths(nbdev_ch);
}
}


static inline bool
static inline struct nvme_io_path *
bdev_nvme_find_io_path(struct nvme_bdev_channel *nbdev_ch,
bdev_nvme_find_io_path(struct nvme_bdev_channel *nbdev_ch)
		       struct spdk_nvme_ns **_ns, struct spdk_nvme_qpair **_qpair)
{
{
	struct nvme_io_path *io_path;
	struct nvme_io_path *io_path;


@@ -658,12 +656,10 @@ bdev_nvme_find_io_path(struct nvme_bdev_channel *nbdev_ch,
			continue;
			continue;
		}
		}


		*_ns = io_path->nvme_ns->ns;
		return io_path;
		*_qpair = io_path->ctrlr_ch->qpair;
		return true;
	}
	}


	return false;
	return NULL;
}
}


static inline void
static inline void
@@ -819,7 +815,7 @@ bdev_nvme_destruct(void *ctx)
}
}


static int
static int
bdev_nvme_flush(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
bdev_nvme_flush(struct nvme_io_path *io_path,
		struct nvme_bdev_io *bio, uint64_t offset, uint64_t nbytes)
		struct nvme_bdev_io *bio, uint64_t offset, uint64_t nbytes)
{
{
	bdev_nvme_io_complete(bio, 0);
	bdev_nvme_io_complete(bio, 0);
@@ -1230,13 +1226,13 @@ bdev_nvme_failover(struct nvme_ctrlr *nvme_ctrlr, bool remove)
}
}


static int
static int
bdev_nvme_unmap(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
bdev_nvme_unmap(struct nvme_io_path *io_path,
		struct nvme_bdev_io *bio,
		struct nvme_bdev_io *bio,
		uint64_t offset_blocks,
		uint64_t offset_blocks,
		uint64_t num_blocks);
		uint64_t num_blocks);


static int
static int
bdev_nvme_write_zeroes(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
bdev_nvme_write_zeroes(struct nvme_io_path *io_path,
		       struct nvme_bdev_io *bio,
		       struct nvme_bdev_io *bio,
		       uint64_t offset_blocks,
		       uint64_t offset_blocks,
		       uint64_t num_blocks);
		       uint64_t num_blocks);
@@ -1248,8 +1244,7 @@ bdev_nvme_get_buf_cb(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io,
	struct nvme_bdev_io *bio = (struct nvme_bdev_io *)bdev_io->driver_ctx;
	struct nvme_bdev_io *bio = (struct nvme_bdev_io *)bdev_io->driver_ctx;
	struct spdk_bdev *bdev = bdev_io->bdev;
	struct spdk_bdev *bdev = bdev_io->bdev;
	struct nvme_bdev_channel *nbdev_ch = spdk_io_channel_get_ctx(ch);
	struct nvme_bdev_channel *nbdev_ch = spdk_io_channel_get_ctx(ch);
	struct spdk_nvme_ns *ns;
	struct nvme_io_path *io_path;
	struct spdk_nvme_qpair *qpair;
	int ret;
	int ret;


	if (!success) {
	if (!success) {
@@ -1257,13 +1252,13 @@ bdev_nvme_get_buf_cb(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io,
		goto exit;
		goto exit;
	}
	}


	if (spdk_unlikely(!bdev_nvme_find_io_path(nbdev_ch, &ns, &qpair))) {
	io_path = bdev_nvme_find_io_path(nbdev_ch);
	if (spdk_unlikely(!io_path)) {
		ret = -ENXIO;
		ret = -ENXIO;
		goto exit;
		goto exit;
	}
	}


	ret = bdev_nvme_readv(ns,
	ret = bdev_nvme_readv(io_path,
			      qpair,
			      bio,
			      bio,
			      bdev_io->u.bdev.iovs,
			      bdev_io->u.bdev.iovs,
			      bdev_io->u.bdev.iovcnt,
			      bdev_io->u.bdev.iovcnt,
@@ -1286,11 +1281,11 @@ bdev_nvme_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_i
	struct spdk_bdev *bdev = bdev_io->bdev;
	struct spdk_bdev *bdev = bdev_io->bdev;
	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 spdk_nvme_ns *ns;
	struct nvme_io_path *io_path;
	struct spdk_nvme_qpair *qpair;
	int rc = 0;
	int rc = 0;


	if (spdk_unlikely(!bdev_nvme_find_io_path(nbdev_ch, &ns, &qpair))) {
	io_path = bdev_nvme_find_io_path(nbdev_ch);
	if (spdk_unlikely(!io_path)) {
		rc = -ENXIO;
		rc = -ENXIO;
		goto exit;
		goto exit;
	}
	}
@@ -1298,8 +1293,7 @@ bdev_nvme_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_i
	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) {
			rc = bdev_nvme_readv(ns,
			rc = bdev_nvme_readv(io_path,
					     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,
@@ -1315,8 +1309,7 @@ bdev_nvme_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_i
		}
		}
		break;
		break;
	case SPDK_BDEV_IO_TYPE_WRITE:
	case SPDK_BDEV_IO_TYPE_WRITE:
		rc = bdev_nvme_writev(ns,
		rc = bdev_nvme_writev(io_path,
				      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,
@@ -1327,8 +1320,7 @@ bdev_nvme_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_i
				      bdev_io->internal.ext_opts);
				      bdev_io->internal.ext_opts);
		break;
		break;
	case SPDK_BDEV_IO_TYPE_COMPARE:
	case SPDK_BDEV_IO_TYPE_COMPARE:
		rc = bdev_nvme_comparev(ns,
		rc = bdev_nvme_comparev(io_path,
					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,
@@ -1338,8 +1330,7 @@ bdev_nvme_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_i
					bdev->dif_check_flags);
					bdev->dif_check_flags);
		break;
		break;
	case SPDK_BDEV_IO_TYPE_COMPARE_AND_WRITE:
	case SPDK_BDEV_IO_TYPE_COMPARE_AND_WRITE:
		rc = bdev_nvme_comparev_and_writev(ns,
		rc = bdev_nvme_comparev_and_writev(io_path,
						   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,
@@ -1351,14 +1342,13 @@ bdev_nvme_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_i
						   bdev->dif_check_flags);
						   bdev->dif_check_flags);
		break;
		break;
	case SPDK_BDEV_IO_TYPE_UNMAP:
	case SPDK_BDEV_IO_TYPE_UNMAP:
		rc = bdev_nvme_unmap(ns,
		rc = bdev_nvme_unmap(io_path,
				     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);
		break;
		break;
	case SPDK_BDEV_IO_TYPE_WRITE_ZEROES:
	case SPDK_BDEV_IO_TYPE_WRITE_ZEROES:
		rc =  bdev_nvme_write_zeroes(ns, qpair,
		rc =  bdev_nvme_write_zeroes(io_path,
					     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);
@@ -1367,15 +1357,13 @@ bdev_nvme_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_i
		rc = bdev_nvme_reset_io(nbdev_ch, nbdev_io);
		rc = bdev_nvme_reset_io(nbdev_ch, nbdev_io);
		break;
		break;
	case SPDK_BDEV_IO_TYPE_FLUSH:
	case SPDK_BDEV_IO_TYPE_FLUSH:
		rc = bdev_nvme_flush(ns,
		rc = bdev_nvme_flush(io_path,
				     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);
		break;
		break;
	case SPDK_BDEV_IO_TYPE_ZONE_APPEND:
	case SPDK_BDEV_IO_TYPE_ZONE_APPEND:
		rc = bdev_nvme_zone_appendv(ns,
		rc = bdev_nvme_zone_appendv(io_path,
					    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,
@@ -1385,16 +1373,14 @@ bdev_nvme_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_i
					    bdev->dif_check_flags);
					    bdev->dif_check_flags);
		break;
		break;
	case SPDK_BDEV_IO_TYPE_GET_ZONE_INFO:
	case SPDK_BDEV_IO_TYPE_GET_ZONE_INFO:
		rc = bdev_nvme_get_zone_info(ns,
		rc = bdev_nvme_get_zone_info(io_path,
					     qpair,
					     nbdev_io,
					     nbdev_io,
					     bdev_io->u.zone_mgmt.zone_id,
					     bdev_io->u.zone_mgmt.zone_id,
					     bdev_io->u.zone_mgmt.num_zones,
					     bdev_io->u.zone_mgmt.num_zones,
					     bdev_io->u.zone_mgmt.buf);
					     bdev_io->u.zone_mgmt.buf);
		break;
		break;
	case SPDK_BDEV_IO_TYPE_ZONE_MANAGEMENT:
	case SPDK_BDEV_IO_TYPE_ZONE_MANAGEMENT:
		rc = bdev_nvme_zone_management(ns,
		rc = bdev_nvme_zone_management(io_path,
					       qpair,
					       nbdev_io,
					       nbdev_io,
					       bdev_io->u.zone_mgmt.zone_id,
					       bdev_io->u.zone_mgmt.zone_id,
					       bdev_io->u.zone_mgmt.zone_action);
					       bdev_io->u.zone_mgmt.zone_action);
@@ -1407,16 +1393,14 @@ bdev_nvme_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_i
					      bdev_io->u.nvme_passthru.nbytes);
					      bdev_io->u.nvme_passthru.nbytes);
		break;
		break;
	case SPDK_BDEV_IO_TYPE_NVME_IO:
	case SPDK_BDEV_IO_TYPE_NVME_IO:
		rc = bdev_nvme_io_passthru(ns,
		rc = bdev_nvme_io_passthru(io_path,
					   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);
		break;
		break;
	case SPDK_BDEV_IO_TYPE_NVME_IO_MD:
	case SPDK_BDEV_IO_TYPE_NVME_IO_MD:
		rc = bdev_nvme_io_passthru_md(ns,
		rc = bdev_nvme_io_passthru_md(io_path,
					      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,
@@ -3579,8 +3563,7 @@ bdev_nvme_readv_done(void *ref, const struct spdk_nvme_cpl *cpl)
	struct nvme_bdev_io *bio = ref;
	struct nvme_bdev_io *bio = ref;
	struct spdk_bdev_io *bdev_io = spdk_bdev_io_from_ctx(bio);
	struct spdk_bdev_io *bdev_io = spdk_bdev_io_from_ctx(bio);
	struct nvme_bdev_channel *nbdev_ch;
	struct nvme_bdev_channel *nbdev_ch;
	struct spdk_nvme_ns *ns;
	struct nvme_io_path *io_path;
	struct spdk_nvme_qpair *qpair;
	int ret;
	int ret;


	if (spdk_unlikely(spdk_nvme_cpl_is_pi_error(cpl))) {
	if (spdk_unlikely(spdk_nvme_cpl_is_pi_error(cpl))) {
@@ -3592,10 +3575,10 @@ bdev_nvme_readv_done(void *ref, const struct spdk_nvme_cpl *cpl)


		nbdev_ch = spdk_io_channel_get_ctx(spdk_bdev_io_get_io_channel(bdev_io));
		nbdev_ch = spdk_io_channel_get_ctx(spdk_bdev_io_get_io_channel(bdev_io));


		if (spdk_likely(bdev_nvme_find_io_path(nbdev_ch, &ns, &qpair))) {
		io_path = bdev_nvme_find_io_path(nbdev_ch);
		if (spdk_likely(io_path)) {
			/* Read without PI checking to verify PI error. */
			/* Read without PI checking to verify PI error. */
			ret = bdev_nvme_no_pi_readv(ns,
			ret = bdev_nvme_no_pi_readv(io_path,
						    qpair,
						    bio,
						    bio,
						    bdev_io->u.bdev.iovs,
						    bdev_io->u.bdev.iovs,
						    bdev_io->u.bdev.iovcnt,
						    bdev_io->u.bdev.iovcnt,
@@ -3746,6 +3729,7 @@ bdev_nvme_get_zone_info_done(void *ref, const struct spdk_nvme_cpl *cpl)
	struct spdk_bdev_zone_info *info = bdev_io->u.zone_mgmt.buf;
	struct spdk_bdev_zone_info *info = bdev_io->u.zone_mgmt.buf;
	uint64_t max_zones_per_buf, i;
	uint64_t max_zones_per_buf, i;
	uint32_t zone_report_bufsize;
	uint32_t zone_report_bufsize;
	struct nvme_io_path *io_path;
	struct spdk_nvme_ns *ns;
	struct spdk_nvme_ns *ns;
	struct spdk_nvme_qpair *qpair;
	struct spdk_nvme_qpair *qpair;
	int ret;
	int ret;
@@ -3754,11 +3738,15 @@ bdev_nvme_get_zone_info_done(void *ref, const struct spdk_nvme_cpl *cpl)
		goto out_complete_io_nvme_cpl;
		goto out_complete_io_nvme_cpl;
	}
	}


	if (!bdev_nvme_find_io_path(nbdev_ch, &ns, &qpair)) {
	io_path = bdev_nvme_find_io_path(nbdev_ch);
	if (!io_path) {
		ret = -ENXIO;
		ret = -ENXIO;
		goto out_complete_io_ret;
		goto out_complete_io_ret;
	}
	}


	ns = io_path->nvme_ns->ns;
	qpair = io_path->ctrlr_ch->qpair;

	zone_report_bufsize = spdk_nvme_ns_get_max_io_xfer_size(ns);
	zone_report_bufsize = spdk_nvme_ns_get_max_io_xfer_size(ns);
	max_zones_per_buf = (zone_report_bufsize - sizeof(*bio->zone_report_buf)) /
	max_zones_per_buf = (zone_report_bufsize - sizeof(*bio->zone_report_buf)) /
			    sizeof(bio->zone_report_buf->descs[0]);
			    sizeof(bio->zone_report_buf->descs[0]);
@@ -3948,7 +3936,7 @@ bdev_nvme_queued_next_fused_sge(void *ref, void **address, uint32_t *length)
}
}


static int
static int
bdev_nvme_no_pi_readv(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
bdev_nvme_no_pi_readv(struct nvme_io_path *io_path,
		      struct nvme_bdev_io *bio, struct iovec *iov, int iovcnt,
		      struct nvme_bdev_io *bio, struct iovec *iov, int iovcnt,
		      void *md, uint64_t lba_count, uint64_t lba)
		      void *md, uint64_t lba_count, uint64_t lba)
{
{
@@ -3962,7 +3950,8 @@ bdev_nvme_no_pi_readv(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
	bio->iovpos = 0;
	bio->iovpos = 0;
	bio->iov_offset = 0;
	bio->iov_offset = 0;


	rc = spdk_nvme_ns_cmd_readv_with_md(ns, qpair, lba, lba_count,
	rc = spdk_nvme_ns_cmd_readv_with_md(io_path->nvme_ns->ns, io_path->ctrlr_ch->qpair,
					    lba, lba_count,
					    bdev_nvme_no_pi_readv_done, bio, 0,
					    bdev_nvme_no_pi_readv_done, bio, 0,
					    bdev_nvme_queued_reset_sgl, bdev_nvme_queued_next_sge,
					    bdev_nvme_queued_reset_sgl, bdev_nvme_queued_next_sge,
					    md, 0, 0);
					    md, 0, 0);
@@ -3974,11 +3963,13 @@ bdev_nvme_no_pi_readv(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
}
}


static int
static int
bdev_nvme_readv(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
bdev_nvme_readv(struct nvme_io_path *io_path,
		struct nvme_bdev_io *bio, struct iovec *iov, int iovcnt,
		struct nvme_bdev_io *bio, struct iovec *iov, int iovcnt,
		void *md, uint64_t lba_count, uint64_t lba, uint32_t flags,
		void *md, uint64_t lba_count, uint64_t lba, uint32_t flags,
		struct spdk_bdev_ext_io_opts *ext_opts)
		struct spdk_bdev_ext_io_opts *ext_opts)
{
{
	struct spdk_nvme_ns *ns = io_path->nvme_ns->ns;
	struct spdk_nvme_qpair *qpair = io_path->ctrlr_ch->qpair;
	int rc;
	int rc;


	SPDK_DEBUGLOG(bdev_nvme, "read %" PRIu64 " blocks with offset %#" PRIx64 "\n",
	SPDK_DEBUGLOG(bdev_nvme, "read %" PRIu64 " blocks with offset %#" PRIx64 "\n",
@@ -4020,11 +4011,13 @@ bdev_nvme_readv(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
}
}


static int
static int
bdev_nvme_writev(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
bdev_nvme_writev(struct nvme_io_path *io_path,
		 struct nvme_bdev_io *bio,
		 struct nvme_bdev_io *bio,
		 struct iovec *iov, int iovcnt, void *md, uint64_t lba_count, uint64_t lba,
		 struct iovec *iov, int iovcnt, void *md, uint64_t lba_count, uint64_t lba,
		 uint32_t flags, struct spdk_bdev_ext_io_opts *ext_opts)
		 uint32_t flags, struct spdk_bdev_ext_io_opts *ext_opts)
{
{
	struct spdk_nvme_ns *ns = io_path->nvme_ns->ns;
	struct spdk_nvme_qpair *qpair = io_path->ctrlr_ch->qpair;
	int rc;
	int rc;


	SPDK_DEBUGLOG(bdev_nvme, "write %" PRIu64 " blocks with offset %#" PRIx64 "\n",
	SPDK_DEBUGLOG(bdev_nvme, "write %" PRIu64 " blocks with offset %#" PRIx64 "\n",
@@ -4066,11 +4059,13 @@ bdev_nvme_writev(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
}
}


static int
static int
bdev_nvme_zone_appendv(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
bdev_nvme_zone_appendv(struct nvme_io_path *io_path,
		       struct nvme_bdev_io *bio,
		       struct nvme_bdev_io *bio,
		       struct iovec *iov, int iovcnt, void *md, uint64_t lba_count, uint64_t zslba,
		       struct iovec *iov, int iovcnt, void *md, uint64_t lba_count, uint64_t zslba,
		       uint32_t flags)
		       uint32_t flags)
{
{
	struct spdk_nvme_ns *ns = io_path->nvme_ns->ns;
	struct spdk_nvme_qpair *qpair = io_path->ctrlr_ch->qpair;
	int rc;
	int rc;


	SPDK_DEBUGLOG(bdev_nvme, "zone append %" PRIu64 " blocks to zone start lba %#" PRIx64 "\n",
	SPDK_DEBUGLOG(bdev_nvme, "zone append %" PRIu64 " blocks to zone start lba %#" PRIx64 "\n",
@@ -4101,7 +4096,7 @@ bdev_nvme_zone_appendv(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
}
}


static int
static int
bdev_nvme_comparev(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
bdev_nvme_comparev(struct nvme_io_path *io_path,
		   struct nvme_bdev_io *bio,
		   struct nvme_bdev_io *bio,
		   struct iovec *iov, int iovcnt, void *md, uint64_t lba_count, uint64_t lba,
		   struct iovec *iov, int iovcnt, void *md, uint64_t lba_count, uint64_t lba,
		   uint32_t flags)
		   uint32_t flags)
@@ -4116,7 +4111,8 @@ bdev_nvme_comparev(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
	bio->iovpos = 0;
	bio->iovpos = 0;
	bio->iov_offset = 0;
	bio->iov_offset = 0;


	rc = spdk_nvme_ns_cmd_comparev_with_md(ns, qpair, lba, lba_count,
	rc = spdk_nvme_ns_cmd_comparev_with_md(io_path->nvme_ns->ns, io_path->ctrlr_ch->qpair,
					       lba, lba_count,
					       bdev_nvme_comparev_done, bio, flags,
					       bdev_nvme_comparev_done, bio, flags,
					       bdev_nvme_queued_reset_sgl, bdev_nvme_queued_next_sge,
					       bdev_nvme_queued_reset_sgl, bdev_nvme_queued_next_sge,
					       md, 0, 0);
					       md, 0, 0);
@@ -4128,11 +4124,13 @@ bdev_nvme_comparev(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
}
}


static int
static int
bdev_nvme_comparev_and_writev(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
bdev_nvme_comparev_and_writev(struct nvme_io_path *io_path,
			      struct nvme_bdev_io *bio, struct iovec *cmp_iov, int cmp_iovcnt,
			      struct nvme_bdev_io *bio, struct iovec *cmp_iov, int cmp_iovcnt,
			      struct iovec *write_iov, int write_iovcnt,
			      struct iovec *write_iov, int write_iovcnt,
			      void *md, uint64_t lba_count, uint64_t lba, uint32_t flags)
			      void *md, uint64_t lba_count, uint64_t lba, uint32_t flags)
{
{
	struct spdk_nvme_ns *ns = io_path->nvme_ns->ns;
	struct spdk_nvme_qpair *qpair = io_path->ctrlr_ch->qpair;
	struct spdk_bdev_io *bdev_io = spdk_bdev_io_from_ctx(bio);
	struct spdk_bdev_io *bdev_io = spdk_bdev_io_from_ctx(bio);
	int rc;
	int rc;


@@ -4184,7 +4182,7 @@ bdev_nvme_comparev_and_writev(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *q
}
}


static int
static int
bdev_nvme_unmap(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
bdev_nvme_unmap(struct nvme_io_path *io_path,
		struct nvme_bdev_io *bio,
		struct nvme_bdev_io *bio,
		uint64_t offset_blocks,
		uint64_t offset_blocks,
		uint64_t num_blocks)
		uint64_t num_blocks)
@@ -4224,7 +4222,8 @@ bdev_nvme_unmap(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
	range->length = remaining;
	range->length = remaining;
	range->starting_lba = offset;
	range->starting_lba = offset;


	rc = spdk_nvme_ns_cmd_dataset_management(ns, qpair,
	rc = spdk_nvme_ns_cmd_dataset_management(io_path->nvme_ns->ns,
			io_path->ctrlr_ch->qpair,
			SPDK_NVME_DSM_ATTR_DEALLOCATE,
			SPDK_NVME_DSM_ATTR_DEALLOCATE,
			dsm_ranges, num_ranges,
			dsm_ranges, num_ranges,
			bdev_nvme_queued_done, bio);
			bdev_nvme_queued_done, bio);
@@ -4233,7 +4232,7 @@ bdev_nvme_unmap(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
}
}


static int
static int
bdev_nvme_write_zeroes(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
bdev_nvme_write_zeroes(struct nvme_io_path *io_path,
		       struct nvme_bdev_io *bio,
		       struct nvme_bdev_io *bio,
		       uint64_t offset_blocks,
		       uint64_t offset_blocks,
		       uint64_t num_blocks)
		       uint64_t num_blocks)
@@ -4243,17 +4242,19 @@ bdev_nvme_write_zeroes(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
		return -EINVAL;
		return -EINVAL;
	}
	}


	return spdk_nvme_ns_cmd_write_zeroes(ns, qpair,
	return spdk_nvme_ns_cmd_write_zeroes(io_path->nvme_ns->ns, io_path->ctrlr_ch->qpair,
					     offset_blocks, num_blocks,
					     offset_blocks, num_blocks,
					     bdev_nvme_queued_done, bio,
					     bdev_nvme_queued_done, bio,
					     0);
					     0);
}
}


static int
static int
bdev_nvme_get_zone_info(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
bdev_nvme_get_zone_info(struct nvme_io_path *io_path,
			struct nvme_bdev_io *bio, uint64_t zone_id, uint32_t num_zones,
			struct nvme_bdev_io *bio, uint64_t zone_id, uint32_t num_zones,
			struct spdk_bdev_zone_info *info)
			struct spdk_bdev_zone_info *info)
{
{
	struct spdk_nvme_ns *ns = io_path->nvme_ns->ns;
	struct spdk_nvme_qpair *qpair = io_path->ctrlr_ch->qpair;
	uint32_t zone_report_bufsize = spdk_nvme_ns_get_max_io_xfer_size(ns);
	uint32_t zone_report_bufsize = spdk_nvme_ns_get_max_io_xfer_size(ns);
	uint64_t zone_size = spdk_nvme_zns_ns_get_zone_size_sectors(ns);
	uint64_t zone_size = spdk_nvme_zns_ns_get_zone_size_sectors(ns);
	uint64_t total_zones = spdk_nvme_zns_ns_get_num_zones(ns);
	uint64_t total_zones = spdk_nvme_zns_ns_get_num_zones(ns);
@@ -4280,10 +4281,13 @@ bdev_nvme_get_zone_info(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
}
}


static int
static int
bdev_nvme_zone_management(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
bdev_nvme_zone_management(struct nvme_io_path *io_path,
			  struct nvme_bdev_io *bio, uint64_t zone_id,
			  struct nvme_bdev_io *bio, uint64_t zone_id,
			  enum spdk_bdev_zone_action action)
			  enum spdk_bdev_zone_action action)
{
{
	struct spdk_nvme_ns *ns = io_path->nvme_ns->ns;
	struct spdk_nvme_qpair *qpair = io_path->ctrlr_ch->qpair;

	switch (action) {
	switch (action) {
	case SPDK_BDEV_ZONE_CLOSE:
	case SPDK_BDEV_ZONE_CLOSE:
		return spdk_nvme_zns_close_zone(ns, qpair, zone_id, false,
		return spdk_nvme_zns_close_zone(ns, qpair, zone_id, false,
@@ -4336,10 +4340,12 @@ bdev_nvme_admin_passthru(struct nvme_bdev_channel *nbdev_ch, struct nvme_bdev_io
}
}


static int
static int
bdev_nvme_io_passthru(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
bdev_nvme_io_passthru(struct nvme_io_path *io_path,
		      struct nvme_bdev_io *bio,
		      struct nvme_bdev_io *bio,
		      struct spdk_nvme_cmd *cmd, void *buf, size_t nbytes)
		      struct spdk_nvme_cmd *cmd, void *buf, size_t nbytes)
{
{
	struct spdk_nvme_ns *ns = io_path->nvme_ns->ns;
	struct spdk_nvme_qpair *qpair = io_path->ctrlr_ch->qpair;
	uint32_t max_xfer_size = spdk_nvme_ns_get_max_io_xfer_size(ns);
	uint32_t max_xfer_size = spdk_nvme_ns_get_max_io_xfer_size(ns);
	struct spdk_nvme_ctrlr *ctrlr = spdk_nvme_ns_get_ctrlr(ns);
	struct spdk_nvme_ctrlr *ctrlr = spdk_nvme_ns_get_ctrlr(ns);


@@ -4359,10 +4365,12 @@ bdev_nvme_io_passthru(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
}
}


static int
static int
bdev_nvme_io_passthru_md(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
bdev_nvme_io_passthru_md(struct nvme_io_path *io_path,
			 struct nvme_bdev_io *bio,
			 struct nvme_bdev_io *bio,
			 struct spdk_nvme_cmd *cmd, void *buf, size_t nbytes, void *md_buf, size_t md_len)
			 struct spdk_nvme_cmd *cmd, void *buf, size_t nbytes, void *md_buf, size_t md_len)
{
{
	struct spdk_nvme_ns *ns = io_path->nvme_ns->ns;
	struct spdk_nvme_qpair *qpair = io_path->ctrlr_ch->qpair;
	size_t nr_sectors = nbytes / spdk_nvme_ns_get_extended_sector_size(ns);
	size_t nr_sectors = nbytes / spdk_nvme_ns_get_extended_sector_size(ns);
	uint32_t max_xfer_size = spdk_nvme_ns_get_max_io_xfer_size(ns);
	uint32_t max_xfer_size = spdk_nvme_ns_get_max_io_xfer_size(ns);
	struct spdk_nvme_ctrlr *ctrlr = spdk_nvme_ns_get_ctrlr(ns);
	struct spdk_nvme_ctrlr *ctrlr = spdk_nvme_ns_get_ctrlr(ns);
+18 −9
Original line number Original line Diff line number Diff line
@@ -1912,10 +1912,13 @@ ut_test_submit_nvme_cmd(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io
			enum spdk_bdev_io_type io_type)
			enum spdk_bdev_io_type io_type)
{
{
	struct nvme_bdev_channel *nbdev_ch = spdk_io_channel_get_ctx(ch);
	struct nvme_bdev_channel *nbdev_ch = spdk_io_channel_get_ctx(ch);
	struct spdk_nvme_ns *ns = NULL;
	struct nvme_io_path *io_path;
	struct spdk_nvme_qpair *qpair = NULL;
	struct spdk_nvme_qpair *qpair;


	CU_ASSERT(bdev_nvme_find_io_path(nbdev_ch, &ns, &qpair));
	io_path = bdev_nvme_find_io_path(nbdev_ch);
	SPDK_CU_ASSERT_FATAL(io_path != NULL);
	qpair = io_path->ctrlr_ch->qpair;
	SPDK_CU_ASSERT_FATAL(qpair != NULL);


	bdev_io->type = io_type;
	bdev_io->type = io_type;
	bdev_io->internal.in_submit_request = true;
	bdev_io->internal.in_submit_request = true;
@@ -1937,10 +1940,13 @@ ut_test_submit_nop(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io,
		   enum spdk_bdev_io_type io_type)
		   enum spdk_bdev_io_type io_type)
{
{
	struct nvme_bdev_channel *nbdev_ch = spdk_io_channel_get_ctx(ch);
	struct nvme_bdev_channel *nbdev_ch = spdk_io_channel_get_ctx(ch);
	struct spdk_nvme_ns *ns = NULL;
	struct nvme_io_path *io_path;
	struct spdk_nvme_qpair *qpair = NULL;
	struct spdk_nvme_qpair *qpair;


	CU_ASSERT(bdev_nvme_find_io_path(nbdev_ch, &ns, &qpair));
	io_path = bdev_nvme_find_io_path(nbdev_ch);
	SPDK_CU_ASSERT_FATAL(io_path != NULL);
	qpair = io_path->ctrlr_ch->qpair;
	SPDK_CU_ASSERT_FATAL(qpair != NULL);


	bdev_io->type = io_type;
	bdev_io->type = io_type;
	bdev_io->internal.in_submit_request = true;
	bdev_io->internal.in_submit_request = true;
@@ -1958,10 +1964,13 @@ ut_test_submit_fused_nvme_cmd(struct spdk_io_channel *ch, struct spdk_bdev_io *b
	struct nvme_bdev_channel *nbdev_ch = spdk_io_channel_get_ctx(ch);
	struct nvme_bdev_channel *nbdev_ch = spdk_io_channel_get_ctx(ch);
	struct nvme_bdev_io *bio = (struct nvme_bdev_io *)bdev_io->driver_ctx;
	struct nvme_bdev_io *bio = (struct nvme_bdev_io *)bdev_io->driver_ctx;
	struct ut_nvme_req *req;
	struct ut_nvme_req *req;
	struct spdk_nvme_ns *ns = NULL;
	struct nvme_io_path *io_path;
	struct spdk_nvme_qpair *qpair = NULL;
	struct spdk_nvme_qpair *qpair;


	CU_ASSERT(bdev_nvme_find_io_path(nbdev_ch, &ns, &qpair));
	io_path = bdev_nvme_find_io_path(nbdev_ch);
	SPDK_CU_ASSERT_FATAL(io_path != NULL);
	qpair = io_path->ctrlr_ch->qpair;
	SPDK_CU_ASSERT_FATAL(qpair != NULL);


	/* Only compare and write now. */
	/* Only compare and write now. */
	bdev_io->type = SPDK_BDEV_IO_TYPE_COMPARE_AND_WRITE;
	bdev_io->type = SPDK_BDEV_IO_TYPE_COMPARE_AND_WRITE;