Commit 245271b6 authored by Yankun Li's avatar Yankun Li Committed by Konrad Sztyber
Browse files

bdev/compress: change the calling mode of vol and comp module



Use struct spdk_reduce_backing_io to encapsulate request parameters
for backing bdev. Easy to put in wait queue when no bdev_io.

Use _comp_reduce_submit_backing_io instead of _comp_reduce_unmap,
_comp_reduce_writev, and _comp_reduce_readv.

Change-Id: Ie8d6043a20e601558260323409702163ea1c0f17
Signed-off-by: default avatarYankun Li <845245370@qq.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/24259


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarGangCao <gang.cao@intel.com>
parent 73edfc05
Loading
Loading
Loading
Loading
+18 −7
Original line number Diff line number Diff line
@@ -87,15 +87,25 @@ struct spdk_reduce_vol_cb_args {
	void			*cb_arg;
};

struct spdk_reduce_backing_dev {
	void (*readv)(struct spdk_reduce_backing_dev *dev, struct iovec *iov, int iovcnt,
		      uint64_t lba, uint32_t lba_count, struct spdk_reduce_vol_cb_args *args);
enum spdk_reduce_backing_io_type {
	SPDK_REDUCE_BACKING_IO_WRITE,
	SPDK_REDUCE_BACKING_IO_READ,
	SPDK_REDUCE_BACKING_IO_UNMAP,
};

	void (*writev)(struct spdk_reduce_backing_dev *dev, struct iovec *iov, int iovcnt,
		       uint64_t lba, uint32_t lba_count, struct spdk_reduce_vol_cb_args *args);
struct spdk_reduce_backing_io {
	struct spdk_reduce_backing_dev    *dev;
	struct iovec                      *iov;
	uint32_t                          iovcnt;
	uint64_t                          lba;
	uint32_t                          lba_count;
	struct spdk_reduce_vol_cb_args    *backing_cb_args;
	enum spdk_reduce_backing_io_type  backing_io_type;
	char                              user_ctx[0];
};

	void (*unmap)(struct spdk_reduce_backing_dev *dev,
		      uint64_t lba, uint32_t lba_count, struct spdk_reduce_vol_cb_args *args);
struct spdk_reduce_backing_dev {
	void (*submit_backing_io)(struct spdk_reduce_backing_io *backing_io);

	void (*compress)(struct spdk_reduce_backing_dev *dev,
			 struct iovec *src_iov, int src_iovcnt,
@@ -111,6 +121,7 @@ struct spdk_reduce_backing_dev {
	uint32_t	blocklen;
	bool		sgl_in;
	bool		sgl_out;
	uint32_t        user_ctx_size;
};

/**
+2 −2
Original line number Diff line number Diff line
@@ -6,8 +6,8 @@
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk

SO_VER := 6
SO_MINOR := 1
SO_VER := 7
SO_MINOR := 0

C_SRCS = reduce.c
LIBNAME = reduce
+136 −33
Original line number Diff line number Diff line
@@ -99,6 +99,7 @@ struct spdk_reduce_vol_request {
	int					iovcnt;
	int					num_backing_ops;
	uint32_t				num_io_units;
	struct spdk_reduce_backing_io           *backing_io;
	bool					chunk_is_compressed;
	bool					copy_after_decompress;
	uint64_t				offset;
@@ -135,6 +136,8 @@ struct spdk_reduce_vol {
	/* Single contiguous buffer used for all request buffers for this volume. */
	uint8_t					*buf_mem;
	struct iovec                            *buf_iov_mem;
	/* Single contiguous buffer used for backing io buffers for this volume. */
	uint8_t                                 *buf_backing_io_mem;
};

static void _start_readv_request(struct spdk_reduce_vol_request *req);
@@ -305,6 +308,7 @@ struct reduce_init_load_ctx {
	void					*cb_arg;
	struct iovec				iov[LOAD_IOV_COUNT];
	void					*path;
	struct spdk_reduce_backing_io           *backing_io;
};

static inline bool
@@ -351,6 +355,7 @@ static int
_allocate_vol_requests(struct spdk_reduce_vol *vol)
{
	struct spdk_reduce_vol_request *req;
	struct spdk_reduce_backing_dev *backing_dev = vol->backing_dev;
	uint32_t reqs_in_2mb_page, huge_pages_needed;
	uint8_t *buffer, *buffer_end;
	int i = 0;
@@ -392,12 +397,28 @@ _allocate_vol_requests(struct spdk_reduce_vol *vol)
		return -ENOMEM;
	}

	vol->buf_backing_io_mem = calloc(REDUCE_NUM_VOL_REQUESTS, (sizeof(struct spdk_reduce_backing_io) +
					 backing_dev->user_ctx_size) * vol->backing_io_units_per_chunk);
	if (vol->buf_backing_io_mem == NULL) {
		free(vol->request_mem);
		free(vol->buf_iov_mem);
		spdk_free(vol->buf_mem);
		vol->request_mem = NULL;
		vol->buf_iov_mem = NULL;
		vol->buf_mem = NULL;
		return -ENOMEM;
	}

	buffer = vol->buf_mem;
	buffer_end = buffer + VALUE_2MB * huge_pages_needed;

	for (i = 0; i < REDUCE_NUM_VOL_REQUESTS; i++) {
		req = &vol->request_mem[i];
		TAILQ_INSERT_HEAD(&vol->free_requests, req, tailq);
		req->backing_io = (struct spdk_reduce_backing_io *)(vol->buf_backing_io_mem + i *
				  (sizeof(struct spdk_reduce_backing_io) + backing_dev->user_ctx_size) *
				  vol->backing_io_units_per_chunk);

		req->decomp_buf_iov = &vol->buf_iov_mem[(2 * i) * vol->backing_io_units_per_chunk];
		req->comp_buf_iov = &vol->buf_iov_mem[(2 * i + 1) * vol->backing_io_units_per_chunk];

@@ -416,10 +437,12 @@ _allocate_vol_requests(struct spdk_reduce_vol *vol)
	}

	if (rc) {
		free(vol->buf_backing_io_mem);
		free(vol->buf_iov_mem);
		free(vol->request_mem);
		spdk_free(vol->buf_mem);
		vol->buf_mem = NULL;
		vol->buf_backing_io_mem = NULL;
		vol->buf_iov_mem = NULL;
		vol->request_mem = NULL;
	}
@@ -432,6 +455,7 @@ _init_load_cleanup(struct spdk_reduce_vol *vol, struct reduce_init_load_ctx *ctx
{
	if (ctx != NULL) {
		spdk_free(ctx->path);
		free(ctx->backing_io);
		free(ctx);
	}

@@ -444,6 +468,7 @@ _init_load_cleanup(struct spdk_reduce_vol *vol, struct reduce_init_load_ctx *ctx
		spdk_bit_array_free(&vol->allocated_chunk_maps);
		spdk_bit_array_free(&vol->allocated_backing_io_units);
		free(vol->request_mem);
		free(vol->buf_backing_io_mem);
		free(vol->buf_iov_mem);
		spdk_free(vol->buf_mem);
		free(vol);
@@ -503,14 +528,22 @@ _init_write_path_cpl(void *cb_arg, int reduce_errno)
{
	struct reduce_init_load_ctx *init_ctx = cb_arg;
	struct spdk_reduce_vol *vol = init_ctx->vol;
	struct spdk_reduce_backing_io *backing_io = init_ctx->backing_io;

	init_ctx->iov[0].iov_base = vol->backing_super;
	init_ctx->iov[0].iov_len = sizeof(*vol->backing_super);
	init_ctx->backing_cb_args.cb_fn = _init_write_super_cpl;
	init_ctx->backing_cb_args.cb_arg = init_ctx;
	vol->backing_dev->writev(vol->backing_dev, init_ctx->iov, 1,
				 0, sizeof(*vol->backing_super) / vol->backing_dev->blocklen,
				 &init_ctx->backing_cb_args);

	backing_io->dev = vol->backing_dev;
	backing_io->iov = init_ctx->iov;
	backing_io->iovcnt = 1;
	backing_io->lba = 0;
	backing_io->lba_count = sizeof(*vol->backing_super) / vol->backing_dev->blocklen;
	backing_io->backing_cb_args = &init_ctx->backing_cb_args;
	backing_io->backing_io_type = SPDK_REDUCE_BACKING_IO_WRITE;

	vol->backing_dev->submit_backing_io(backing_io);
}

static int
@@ -546,6 +579,7 @@ spdk_reduce_vol_init(struct spdk_reduce_vol_params *params,
{
	struct spdk_reduce_vol *vol;
	struct reduce_init_load_ctx *init_ctx;
	struct spdk_reduce_backing_io *backing_io;
	uint64_t backing_dev_size;
	size_t mapped_len;
	int dir_len, max_dir_len, rc;
@@ -582,8 +616,7 @@ spdk_reduce_vol_init(struct spdk_reduce_vol_params *params,
		return;
	}

	if (backing_dev->readv == NULL || backing_dev->writev == NULL ||
	    backing_dev->unmap == NULL) {
	if (backing_dev->submit_backing_io == NULL) {
		SPDK_ERRLOG("backing_dev function pointer not specified\n");
		cb_fn(cb_arg, NULL, -EINVAL);
		return;
@@ -614,6 +647,14 @@ spdk_reduce_vol_init(struct spdk_reduce_vol_params *params,
		return;
	}

	backing_io = calloc(1, sizeof(*backing_io) + backing_dev->user_ctx_size);
	if (backing_io == NULL) {
		cb_fn(cb_arg, NULL, -ENOMEM);
		_init_load_cleanup(vol, init_ctx);
		return;
	}
	init_ctx->backing_io = backing_io;

	init_ctx->path = spdk_zmalloc(REDUCE_PATH_MAX, 0, NULL,
				      SPDK_ENV_LCORE_ID_ANY, SPDK_MALLOC_DMA);
	if (init_ctx->path == NULL) {
@@ -691,10 +732,15 @@ spdk_reduce_vol_init(struct spdk_reduce_vol_params *params,
	 *  super block to guarantee we don't get the super block written without the
	 *  the path if the system crashed in the middle of a write operation.
	 */
	vol->backing_dev->writev(vol->backing_dev, init_ctx->iov, 1,
				 REDUCE_BACKING_DEV_PATH_OFFSET / vol->backing_dev->blocklen,
				 REDUCE_PATH_MAX / vol->backing_dev->blocklen,
				 &init_ctx->backing_cb_args);
	backing_io->dev = vol->backing_dev;
	backing_io->iov = init_ctx->iov;
	backing_io->iovcnt = 1;
	backing_io->lba = REDUCE_BACKING_DEV_PATH_OFFSET / vol->backing_dev->blocklen;
	backing_io->lba_count = REDUCE_PATH_MAX / vol->backing_dev->blocklen;
	backing_io->backing_cb_args = &init_ctx->backing_cb_args;
	backing_io->backing_io_type = SPDK_REDUCE_BACKING_IO_WRITE;

	vol->backing_dev->submit_backing_io(backing_io);
}

static void destroy_load_cb(void *cb_arg, struct spdk_reduce_vol *vol, int reduce_errno);
@@ -810,9 +856,9 @@ spdk_reduce_vol_load(struct spdk_reduce_backing_dev *backing_dev,
{
	struct spdk_reduce_vol *vol;
	struct reduce_init_load_ctx *load_ctx;
	struct spdk_reduce_backing_io *backing_io;

	if (backing_dev->readv == NULL || backing_dev->writev == NULL ||
	    backing_dev->unmap == NULL) {
	if (backing_dev->submit_backing_io == NULL) {
		SPDK_ERRLOG("backing_dev function pointer not specified\n");
		cb_fn(cb_arg, NULL, -EINVAL);
		return;
@@ -845,6 +891,15 @@ spdk_reduce_vol_load(struct spdk_reduce_backing_dev *backing_dev,
		return;
	}

	backing_io = calloc(1, sizeof(*backing_io) + backing_dev->user_ctx_size);
	if (backing_io == NULL) {
		_init_load_cleanup(vol, load_ctx);
		cb_fn(cb_arg, NULL, -ENOMEM);
		return;
	}

	load_ctx->backing_io = backing_io;

	load_ctx->path = spdk_zmalloc(REDUCE_PATH_MAX, 64, NULL,
				      SPDK_ENV_LCORE_ID_ANY, SPDK_MALLOC_DMA);
	if (load_ctx->path == NULL) {
@@ -861,12 +916,18 @@ spdk_reduce_vol_load(struct spdk_reduce_backing_dev *backing_dev,
	load_ctx->iov[0].iov_len = sizeof(*vol->backing_super);
	load_ctx->iov[1].iov_base = load_ctx->path;
	load_ctx->iov[1].iov_len = REDUCE_PATH_MAX;
	backing_io->dev = vol->backing_dev;
	backing_io->iov = load_ctx->iov;
	backing_io->iovcnt = LOAD_IOV_COUNT;
	backing_io->lba = 0;
	backing_io->lba_count = (sizeof(*vol->backing_super) + REDUCE_PATH_MAX) /
				vol->backing_dev->blocklen;
	backing_io->backing_cb_args = &load_ctx->backing_cb_args;
	backing_io->backing_io_type = SPDK_REDUCE_BACKING_IO_READ;

	load_ctx->backing_cb_args.cb_fn = _load_read_super_and_path_cpl;
	load_ctx->backing_cb_args.cb_arg = load_ctx;
	vol->backing_dev->readv(vol->backing_dev, load_ctx->iov, LOAD_IOV_COUNT, 0,
				(sizeof(*vol->backing_super) + REDUCE_PATH_MAX) /
				vol->backing_dev->blocklen,
				&load_ctx->backing_cb_args);
	vol->backing_dev->submit_backing_io(backing_io);
}

void
@@ -897,6 +958,7 @@ struct reduce_destroy_ctx {
	struct spdk_reduce_vol_cb_args		backing_cb_args;
	int					reduce_errno;
	char					pm_path[REDUCE_PATH_MAX];
	struct spdk_reduce_backing_io           *backing_io;
};

static void
@@ -917,6 +979,7 @@ destroy_unload_cpl(void *cb_arg, int reduce_errno)
	 */
	destroy_ctx->cb_fn(destroy_ctx->cb_arg, destroy_ctx->reduce_errno);
	spdk_free(destroy_ctx->super);
	free(destroy_ctx->backing_io);
	free(destroy_ctx);
}

@@ -934,6 +997,7 @@ static void
destroy_load_cb(void *cb_arg, struct spdk_reduce_vol *vol, int reduce_errno)
{
	struct reduce_destroy_ctx *destroy_ctx = cb_arg;
	struct spdk_reduce_backing_io *backing_io = destroy_ctx->backing_io;

	if (reduce_errno != 0) {
		destroy_ctx->cb_fn(destroy_ctx->cb_arg, reduce_errno);
@@ -948,9 +1012,16 @@ destroy_load_cb(void *cb_arg, struct spdk_reduce_vol *vol, int reduce_errno)
	destroy_ctx->iov.iov_len = sizeof(*destroy_ctx->super);
	destroy_ctx->backing_cb_args.cb_fn = _destroy_zero_super_cpl;
	destroy_ctx->backing_cb_args.cb_arg = destroy_ctx;
	vol->backing_dev->writev(vol->backing_dev, &destroy_ctx->iov, 1, 0,
				 sizeof(*destroy_ctx->super) / vol->backing_dev->blocklen,
				 &destroy_ctx->backing_cb_args);

	backing_io->dev = vol->backing_dev;
	backing_io->iov = &destroy_ctx->iov;
	backing_io->iovcnt = 1;
	backing_io->lba = 0;
	backing_io->lba_count = sizeof(*destroy_ctx->super) / vol->backing_dev->blocklen;
	backing_io->backing_cb_args = &destroy_ctx->backing_cb_args;
	backing_io->backing_io_type = SPDK_REDUCE_BACKING_IO_WRITE;

	vol->backing_dev->submit_backing_io(backing_io);
}

void
@@ -958,6 +1029,7 @@ spdk_reduce_vol_destroy(struct spdk_reduce_backing_dev *backing_dev,
			spdk_reduce_vol_op_complete cb_fn, void *cb_arg)
{
	struct reduce_destroy_ctx *destroy_ctx;
	struct spdk_reduce_backing_io *backing_io;

	destroy_ctx = calloc(1, sizeof(*destroy_ctx));
	if (destroy_ctx == NULL) {
@@ -965,10 +1037,20 @@ spdk_reduce_vol_destroy(struct spdk_reduce_backing_dev *backing_dev,
		return;
	}

	backing_io = calloc(1, sizeof(*backing_io) + backing_dev->user_ctx_size);
	if (backing_io == NULL) {
		free(destroy_ctx);
		cb_fn(cb_arg, -ENOMEM);
		return;
	}

	destroy_ctx->backing_io = backing_io;

	destroy_ctx->super = spdk_zmalloc(sizeof(*destroy_ctx->super), 64, NULL,
					  SPDK_ENV_LCORE_ID_ANY, SPDK_MALLOC_DMA);
	if (destroy_ctx->super == NULL) {
		free(destroy_ctx);
		free(backing_io);
		cb_fn(cb_arg, -ENOMEM);
		return;
	}
@@ -1078,6 +1160,19 @@ _write_write_done(void *_req, int reduce_errno)
	_reduce_vol_complete_req(req, 0);
}

static struct spdk_reduce_backing_io *
_reduce_vol_req_get_backing_io(struct spdk_reduce_vol_request *req, uint32_t index)
{
	struct spdk_reduce_backing_dev *backing_dev = req->vol->backing_dev;
	struct spdk_reduce_backing_io *backing_io;

	backing_io = (struct spdk_reduce_backing_io *)((uint8_t *)req->backing_io +
			(sizeof(*backing_io) + backing_dev->user_ctx_size) * index);

	return backing_io;

}

struct reduce_merged_io_desc {
	uint64_t io_unit_index;
	uint32_t num_io_units;
@@ -1088,6 +1183,7 @@ _issue_backing_ops_without_merge(struct spdk_reduce_vol_request *req, struct spd
				 reduce_request_fn next_fn, bool is_write)
{
	struct iovec *iov;
	struct spdk_reduce_backing_io *backing_io;
	uint8_t *buf;
	uint32_t i;

@@ -1103,17 +1199,21 @@ _issue_backing_ops_without_merge(struct spdk_reduce_vol_request *req, struct spd
	req->backing_cb_args.cb_fn = next_fn;
	req->backing_cb_args.cb_arg = req;
	for (i = 0; i < req->num_io_units; i++) {
		backing_io = _reduce_vol_req_get_backing_io(req, i);
		iov[i].iov_base = buf + i * vol->params.backing_io_unit_size;
		iov[i].iov_len = vol->params.backing_io_unit_size;
		backing_io->dev  = vol->backing_dev;
		backing_io->iov = &iov[i];
		backing_io->iovcnt = 1;
		backing_io->lba = req->chunk->io_unit_index[i] * vol->backing_lba_per_io_unit;
		backing_io->lba_count = vol->backing_lba_per_io_unit;
		backing_io->backing_cb_args = &req->backing_cb_args;
		if (is_write) {
			vol->backing_dev->writev(vol->backing_dev, &iov[i], 1,
						 req->chunk->io_unit_index[i] * vol->backing_lba_per_io_unit,
						 vol->backing_lba_per_io_unit, &req->backing_cb_args);
			backing_io->backing_io_type = SPDK_REDUCE_BACKING_IO_WRITE;
		} else {
			vol->backing_dev->readv(vol->backing_dev, &iov[i], 1,
						req->chunk->io_unit_index[i] * vol->backing_lba_per_io_unit,
						vol->backing_lba_per_io_unit, &req->backing_cb_args);
			backing_io->backing_io_type = SPDK_REDUCE_BACKING_IO_READ;
		}
		vol->backing_dev->submit_backing_io(backing_io);
	}
}

@@ -1122,6 +1222,7 @@ _issue_backing_ops(struct spdk_reduce_vol_request *req, struct spdk_reduce_vol *
		   reduce_request_fn next_fn, bool is_write)
{
	struct iovec *iov;
	struct spdk_reduce_backing_io *backing_io;
	struct reduce_merged_io_desc merged_io_desc[4];
	uint8_t *buf;
	bool merge = false;
@@ -1171,19 +1272,21 @@ _issue_backing_ops(struct spdk_reduce_vol_request *req, struct spdk_reduce_vol *
	req->backing_cb_args.cb_fn = next_fn;
	req->backing_cb_args.cb_arg = req;
	for (i = 0; i < num_io; i++) {
		backing_io = _reduce_vol_req_get_backing_io(req, i);
		iov[i].iov_base = buf + io_unit_counts * vol->params.backing_io_unit_size;
		iov[i].iov_len = vol->params.backing_io_unit_size * merged_io_desc[i].num_io_units;
		backing_io->dev  = vol->backing_dev;
		backing_io->iov = &iov[i];
		backing_io->iovcnt = 1;
		backing_io->lba = merged_io_desc[i].io_unit_index * vol->backing_lba_per_io_unit;
		backing_io->lba_count = vol->backing_lba_per_io_unit * merged_io_desc[i].num_io_units;
		backing_io->backing_cb_args = &req->backing_cb_args;
		if (is_write) {
			vol->backing_dev->writev(vol->backing_dev, &iov[i], 1,
						 merged_io_desc[i].io_unit_index * vol->backing_lba_per_io_unit,
						 vol->backing_lba_per_io_unit * merged_io_desc[i].num_io_units,
						 &req->backing_cb_args);
			backing_io->backing_io_type = SPDK_REDUCE_BACKING_IO_WRITE;
		} else {
			vol->backing_dev->readv(vol->backing_dev, &iov[i], 1,
						merged_io_desc[i].io_unit_index * vol->backing_lba_per_io_unit,
						vol->backing_lba_per_io_unit * merged_io_desc[i].num_io_units,
						&req->backing_cb_args);
			backing_io->backing_io_type = SPDK_REDUCE_BACKING_IO_READ;
		}
		vol->backing_dev->submit_backing_io(backing_io);

		/* Collects the number of processed I/O. */
		io_unit_counts += merged_io_desc[i].num_io_units;
+49 −33
Original line number Diff line number Diff line
@@ -596,82 +596,100 @@ comp_reduce_io_cb(struct spdk_bdev_io *bdev_io, bool success, void *arg)
	cb_args->cb_fn(cb_args->cb_arg, reduce_errno);
}

/* This is the function provided to the reduceLib for sending reads directly to
 * the backing device.
 */
static void
_comp_reduce_readv(struct spdk_reduce_backing_dev *dev, struct iovec *iov, int iovcnt,
		   uint64_t lba, uint32_t lba_count, struct spdk_reduce_vol_cb_args *args)
_comp_backing_bdev_read(struct spdk_reduce_backing_io *backing_io)
{
	struct vbdev_compress *comp_bdev = SPDK_CONTAINEROF(dev, struct vbdev_compress,
	struct spdk_reduce_vol_cb_args *backing_cb_args = backing_io->backing_cb_args;
	struct vbdev_compress *comp_bdev = SPDK_CONTAINEROF(backing_io->dev, struct vbdev_compress,
					   backing_dev);
	int rc;

	rc = spdk_bdev_readv_blocks(comp_bdev->base_desc, comp_bdev->base_ch,
				    iov, iovcnt, lba, lba_count,
				    backing_io->iov, backing_io->iovcnt,
				    backing_io->lba, backing_io->lba_count,
				    comp_reduce_io_cb,
				    args);
				    backing_cb_args);

	if (rc) {
		if (rc == -ENOMEM) {
			SPDK_ERRLOG("No memory, start to queue io.\n");
			/* TODO: there's no bdev_io to queue */
		} else {
			SPDK_ERRLOG("submitting readv request\n");
			SPDK_ERRLOG("submitting readv request, rc=%d\n", rc);
		}
		args->cb_fn(args->cb_arg, rc);
		backing_cb_args->cb_fn(backing_cb_args->cb_arg, rc);
	}
}

/* This is the function provided to the reduceLib for sending writes directly to
 * the backing device.
 */
static void
_comp_reduce_writev(struct spdk_reduce_backing_dev *dev, struct iovec *iov, int iovcnt,
		    uint64_t lba, uint32_t lba_count, struct spdk_reduce_vol_cb_args *args)
_comp_backing_bdev_write(struct spdk_reduce_backing_io  *backing_io)
{
	struct vbdev_compress *comp_bdev = SPDK_CONTAINEROF(dev, struct vbdev_compress,
	struct spdk_reduce_vol_cb_args *backing_cb_args = backing_io->backing_cb_args;
	struct vbdev_compress *comp_bdev = SPDK_CONTAINEROF(backing_io->dev, struct vbdev_compress,
					   backing_dev);
	int rc;

	rc = spdk_bdev_writev_blocks(comp_bdev->base_desc, comp_bdev->base_ch,
				     iov, iovcnt, lba, lba_count,
				     backing_io->iov, backing_io->iovcnt,
				     backing_io->lba, backing_io->lba_count,
				     comp_reduce_io_cb,
				     args);
				     backing_cb_args);

	if (rc) {
		if (rc == -ENOMEM) {
			SPDK_ERRLOG("No memory, start to queue io.\n");
			/* TODO: there's no bdev_io to queue */
		} else {
			SPDK_ERRLOG("error submitting writev request\n");
			SPDK_ERRLOG("error submitting writev request, rc=%d\n", rc);
		}
		args->cb_fn(args->cb_arg, rc);
		backing_cb_args->cb_fn(backing_cb_args->cb_arg, rc);
	}
}

/* This is the function provided to the reduceLib for sending unmaps directly to
 * the backing device.
 */
static void
_comp_reduce_unmap(struct spdk_reduce_backing_dev *dev,
		   uint64_t lba, uint32_t lba_count, struct spdk_reduce_vol_cb_args *args)
_comp_backing_bdev_unmap(struct spdk_reduce_backing_io *backing_io)
{
	struct vbdev_compress *comp_bdev = SPDK_CONTAINEROF(dev, struct vbdev_compress,
	struct spdk_reduce_vol_cb_args *backing_cb_args = backing_io->backing_cb_args;
	struct vbdev_compress *comp_bdev = SPDK_CONTAINEROF(backing_io->dev, struct vbdev_compress,
					   backing_dev);
	int rc;

	rc = spdk_bdev_unmap_blocks(comp_bdev->base_desc, comp_bdev->base_ch,
				    lba, lba_count,
				    backing_io->lba, backing_io->lba_count,
				    comp_reduce_io_cb,
				    args);
				    backing_cb_args);

	if (rc) {
		if (rc == -ENOMEM) {
			SPDK_ERRLOG("No memory, start to queue io.\n");
			/* TODO: there's no bdev_io to queue */
		} else {
			SPDK_ERRLOG("submitting unmap request\n");
			SPDK_ERRLOG("submitting unmap request, rc=%d\n", rc);
		}
		backing_cb_args->cb_fn(backing_cb_args->cb_arg, rc);
	}
		args->cb_fn(args->cb_arg, rc);
}

/* This is the function provided to the reduceLib for sending reads/writes/unmaps
 * directly to the backing device.
 */
static void
_comp_reduce_submit_backing_io(struct spdk_reduce_backing_io *backing_io)
{
	switch (backing_io->backing_io_type) {
	case SPDK_REDUCE_BACKING_IO_WRITE:
		_comp_backing_bdev_write(backing_io);
		break;
	case SPDK_REDUCE_BACKING_IO_READ:
		_comp_backing_bdev_read(backing_io);
		break;
	case SPDK_REDUCE_BACKING_IO_UNMAP:
		_comp_backing_bdev_unmap(backing_io);
		break;
	default:
		SPDK_ERRLOG("Unknown I/O type %d\n", backing_io->backing_io_type);
		backing_io->backing_cb_args->cb_fn(backing_io->backing_cb_args->cb_arg, -EINVAL);
		break;
	}
}

@@ -739,9 +757,7 @@ _prepare_for_load_init(struct spdk_bdev_desc *bdev_desc, uint32_t lb_size)
		return NULL;
	}

	comp_bdev->backing_dev.unmap = _comp_reduce_unmap;
	comp_bdev->backing_dev.readv = _comp_reduce_readv;
	comp_bdev->backing_dev.writev = _comp_reduce_writev;
	comp_bdev->backing_dev.submit_backing_io = _comp_reduce_submit_backing_io;
	comp_bdev->backing_dev.compress = _comp_reduce_compress;
	comp_bdev->backing_dev.decompress = _comp_reduce_decompress;

+1 −3
Original line number Diff line number Diff line
@@ -208,9 +208,7 @@ test_setup(void)
	spdk_set_thread(thread);

	g_comp_bdev.reduce_thread = thread;
	g_comp_bdev.backing_dev.unmap = _comp_reduce_unmap;
	g_comp_bdev.backing_dev.readv = _comp_reduce_readv;
	g_comp_bdev.backing_dev.writev = _comp_reduce_writev;
	g_comp_bdev.backing_dev.submit_backing_io = _comp_reduce_submit_backing_io;
	g_comp_bdev.backing_dev.compress = _comp_reduce_compress;
	g_comp_bdev.backing_dev.decompress = _comp_reduce_decompress;
	g_comp_bdev.backing_dev.blocklen = 512;
Loading