Commit 3511bd09 authored by Rafal Stefanowski's avatar Rafal Stefanowski Committed by Konrad Sztyber
Browse files

bdev/ocf: Update OCF to version 24.9



This patch includes all the essential changes needed for compatibility
with OCF 24.9.

1. Introduce IO forward mechanism

This functionality removes all memory allocations on the IO path by
creating abstractions which allow to pass all the needed information
to the bottom volume, using original buffers and IO requests already
allocated by the user, without the need for creating indirect IO
representations.
The responsibility for refcount accounting and error aggregation
was moved from IO engines to a new intermediate layer introduced by
forward IO.

2. Remove ocf_submit_* ops

Get rid of the code which has been superseded by forward IO.

3. Update queue creation API

Remove lock protecting queue list in the cache.
It's now properly protected by the OCF itself.

4. Use dedicated ocf_io_t type instead of struct ocf_io

5. Update OCF API usage

All those patches needed to be squashed in order to fulfill the
requirements of SPDK CI builds.

Change-Id: I81098f4732109677c2fc48558ac88b3527a8f12f
Signed-off-by: default avatarRafal Stefanowski <rafal.stefanowski@huawei.com>
Signed-off-by: default avatarRobert Baldyga <robert.baldyga@huawei.com>
Signed-off-by: default avatarAvi Halaf <avi.halaf@huawei.com>
Signed-off-by: default avatarAmir Haroush <amir.haroush@huawei.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/25397


Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Community-CI: Community CI Samsung <spdk.community.ci.samsung@gmail.com>
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 3291d077
Loading
Loading
Loading
Loading
+7 −12
Original line number Diff line number Diff line
@@ -269,31 +269,26 @@ vbdev_ocf_ctx_data_secure_erase(ctx_data_t *ctx_data)
int
vbdev_ocf_queue_create(ocf_cache_t cache, ocf_queue_t *queue, const struct ocf_queue_ops *ops)
{
	int rc;
	struct vbdev_ocf_cache_ctx *ctx = ocf_cache_get_priv(cache);

	pthread_mutex_lock(&ctx->lock);
	rc = ocf_queue_create(cache, queue, ops);
	pthread_mutex_unlock(&ctx->lock);
	return rc;
	return ocf_queue_create(cache, queue, ops);
}

int
vbdev_ocf_queue_create_mngt(ocf_cache_t cache, ocf_queue_t *queue, const struct ocf_queue_ops *ops)
{
	return ocf_queue_create_mngt(cache, queue, ops);
}

void
vbdev_ocf_queue_put(ocf_queue_t queue)
{
	ocf_cache_t cache = ocf_queue_get_cache(queue);
	struct vbdev_ocf_cache_ctx *ctx = ocf_cache_get_priv(cache);

	pthread_mutex_lock(&ctx->lock);
	ocf_queue_put(queue);
	pthread_mutex_unlock(&ctx->lock);
}

void
vbdev_ocf_cache_ctx_put(struct vbdev_ocf_cache_ctx *ctx)
{
	if (env_atomic_dec_return(&ctx->refcnt) == 0) {
		pthread_mutex_destroy(&ctx->lock);
		free(ctx);
	}
}
+2 −1
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ extern ocf_ctx_t vbdev_ocf_ctx;
/* Context of cache instance */
struct vbdev_ocf_cache_ctx {
	ocf_queue_t                  mngt_queue;
	pthread_mutex_t              lock;
	env_atomic                   refcnt;
};

@@ -32,6 +31,8 @@ void vbdev_ocf_ctx_cleanup(void);
/* Thread safe queue creation and deletion
 * These are wrappers for original ocf_queue_create() and ocf_queue_put() */
int vbdev_ocf_queue_create(ocf_cache_t cache, ocf_queue_t *queue, const struct ocf_queue_ops *ops);
int vbdev_ocf_queue_create_mngt(ocf_cache_t cache, ocf_queue_t *queue,
				const struct ocf_queue_ops *ops);
void vbdev_ocf_queue_put(ocf_queue_t queue);

#endif
+14 −14
Original line number Diff line number Diff line
@@ -119,10 +119,10 @@ is_ocf_cache_running(struct vbdev_ocf *vbdev)
}

static bool
is_ocf_cache_initializing(struct vbdev_ocf *vbdev)
is_ocf_cache_detached(struct vbdev_ocf *vbdev)
{
	if (vbdev->cache.attached && vbdev->ocf_cache) {
		return ocf_cache_is_initializing(vbdev->ocf_cache);
		return ocf_cache_is_detached(vbdev->ocf_cache);
	}
	return false;
}
@@ -141,7 +141,7 @@ get_other_cache_instance(struct vbdev_ocf *vbdev)
		if (strcmp(cmp->cache.name, vbdev->cache.name)) {
			continue;
		}
		if (is_ocf_cache_running(cmp) || is_ocf_cache_initializing(cmp)) {
		if (is_ocf_cache_running(cmp) || is_ocf_cache_detached(cmp)) {
			return cmp->ocf_cache;
		}
	}
@@ -543,9 +543,9 @@ vbdev_ocf_foreach(vbdev_ocf_foreach_fn fn, void *ctx)

/* Called from OCF when SPDK_IO is completed */
static void
vbdev_ocf_io_submit_cb(struct ocf_io *io, int error)
vbdev_ocf_io_submit_cb(ocf_io_t io, void *priv1, void *priv2, int error)
{
	struct spdk_bdev_io *bdev_io = io->priv1;
	struct spdk_bdev_io *bdev_io = priv1;

	if (error == 0) {
		spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_SUCCESS);
@@ -560,7 +560,7 @@ vbdev_ocf_io_submit_cb(struct ocf_io *io, int error)

/* Configure io parameters and send it to OCF */
static int
io_submit_to_ocf(struct spdk_bdev_io *bdev_io, struct ocf_io *io)
io_submit_to_ocf(struct spdk_bdev_io *bdev_io, ocf_io_t io)
{
	switch (bdev_io->type) {
	case SPDK_BDEV_IO_TYPE_WRITE:
@@ -586,7 +586,7 @@ static void
io_handle(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io)
{
	struct vbdev_ocf *vbdev = bdev_io->bdev->ctxt;
	struct ocf_io *io = NULL;
	ocf_io_t io = NULL;
	struct bdev_ocf_data *data = NULL;
	struct vbdev_ocf_qctx *qctx = spdk_io_channel_get_ctx(ch);
	uint64_t len = bdev_io->u.bdev.num_blocks * bdev_io->bdev->blocklen;
@@ -1009,6 +1009,7 @@ static void
start_cache_cmpl(ocf_cache_t cache, void *priv, int error)
{
	struct vbdev_ocf *vbdev = priv;
	uint64_t volume_size;
	uint64_t mem_needed;

	ocf_mngt_cache_unlock(cache);
@@ -1018,14 +1019,14 @@ start_cache_cmpl(ocf_cache_t cache, void *priv, int error)
			    error, vbdev->name);

		if (error == -OCF_ERR_NO_MEM) {
			ocf_mngt_get_ram_needed(cache, &vbdev->cfg.attach.device, &mem_needed);
			volume_size = vbdev->cache.bdev->blockcnt * vbdev->cache.bdev->blocklen;
			mem_needed = ocf_mngt_get_ram_needed(cache, volume_size);

			SPDK_NOTICELOG("Try to increase hugepage memory size or cache line size. "
				       "For your configuration:\nDevice size: %"PRIu64" bytes\n"
				       "Cache line size: %"PRIu64" bytes\nFree memory needed to start "
				       "cache: %"PRIu64" bytes\n", vbdev->cache.bdev->blockcnt *
				       vbdev->cache.bdev->blocklen, vbdev->cfg.cache.cache_line_size,
				       mem_needed);
				       "cache: %"PRIu64" bytes\n",
				       volume_size, vbdev->cfg.cache.cache_line_size, mem_needed);
		}

		vbdev_ocf_mngt_exit(vbdev, unregister_path_dirty, error);
@@ -1041,7 +1042,8 @@ create_management_queue(struct vbdev_ocf *vbdev)
	struct spdk_poller *mngt_poller;
	int rc;

	rc = vbdev_ocf_queue_create(vbdev->ocf_cache, &vbdev->cache_ctx->mngt_queue, &mngt_queue_ops);
	rc = vbdev_ocf_queue_create_mngt(vbdev->ocf_cache,
					 &vbdev->cache_ctx->mngt_queue, &mngt_queue_ops);
	if (rc) {
		SPDK_ERRLOG("Unable to create mngt_queue: %d\n", rc);
		return rc;
@@ -1054,7 +1056,6 @@ create_management_queue(struct vbdev_ocf *vbdev)
	}

	ocf_queue_set_priv(vbdev->cache_ctx->mngt_queue, mngt_poller);
	ocf_mngt_cache_set_mngt_queue(vbdev->ocf_cache, vbdev->cache_ctx->mngt_queue);

	return 0;
}
@@ -1099,7 +1100,6 @@ start_cache(struct vbdev_ocf *vbdev)
	}

	vbdev_ocf_cache_ctx_get(vbdev->cache_ctx);
	pthread_mutex_init(&vbdev->cache_ctx->lock, NULL);

	rc = ocf_mngt_cache_start(vbdev_ocf_ctx, &vbdev->ocf_cache, &vbdev->cfg.cache, NULL);
	if (rc) {
+165 −231
Original line number Diff line number Diff line
@@ -52,48 +52,7 @@ vbdev_ocf_volume_get_length(ocf_volume_t volume)
}

static int
vbdev_ocf_volume_io_set_data(struct ocf_io *io, ctx_data_t *data,
			     uint32_t offset)
{
	struct ocf_io_ctx *io_ctx = ocf_get_io_ctx(io);

	io_ctx->offset = offset;
	io_ctx->data = data;

	assert(io_ctx->data != NULL);
	if (io_ctx->data->iovs && offset >= io_ctx->data->size) {
		return -ENOBUFS;
	}

	return 0;
}

static ctx_data_t *
vbdev_ocf_volume_io_get_data(struct ocf_io *io)
{
	return ocf_get_io_ctx(io)->data;
}

static void
vbdev_ocf_volume_io_get(struct ocf_io *io)
{
	struct ocf_io_ctx *io_ctx = ocf_get_io_ctx(io);

	io_ctx->ref++;
}

static void
vbdev_ocf_volume_io_put(struct ocf_io *io)
{
	struct ocf_io_ctx *io_ctx = ocf_get_io_ctx(io);

	if (--io_ctx->ref) {
		return;
	}
}

static int
get_starting_vec(struct iovec *iovs, int iovcnt, int *offset)
get_starting_vec(struct iovec *iovs, int iovcnt, uint64_t *offset)
{
	int i;
	size_t off;
@@ -134,257 +93,236 @@ initialize_cpy_vector(struct iovec *cpy_vec, int cpy_vec_len, struct iovec *orig
	}
}

static unsigned int
vbdev_ocf_volume_get_max_io_size(ocf_volume_t volume)
{
	return 131072;
}

static void
vbdev_ocf_volume_submit_io_cb(struct spdk_bdev_io *bdev_io, bool success, void *opaque)
vbdev_forward_io_cb(struct spdk_bdev_io *bdev_io, bool success, void *opaque)
{
	struct ocf_io *io;
	struct ocf_io_ctx *io_ctx;
	ocf_forward_token_t token = (ocf_forward_token_t) opaque;

	assert(opaque);
	assert(token);

	io = opaque;
	io_ctx = ocf_get_io_ctx(io);
	assert(io_ctx != NULL);
	spdk_bdev_free_io(bdev_io);

	if (!success) {
		io_ctx->error = io_ctx->error ? : -OCF_ERR_IO;
	ocf_forward_end(token, success ? 0 : -OCF_ERR_IO);
}

	if (io_ctx->iovs_allocated && bdev_io != NULL) {
static void
vbdev_forward_io_free_iovs_cb(struct spdk_bdev_io *bdev_io, bool success, void *opaque)
{
	env_free(bdev_io->u.bdev.iovs);
	vbdev_forward_io_cb(bdev_io, success, opaque);
}

	if (io_ctx->error) {
		SPDK_DEBUGLOG(vbdev_ocf_volume,
			      "base returned error on io submission: %d\n", io_ctx->error);
	}
static struct spdk_io_channel *
vbdev_forward_get_channel(ocf_volume_t volume, ocf_forward_token_t token)
{
	struct vbdev_ocf_base *base =
		*((struct vbdev_ocf_base **)
		  ocf_volume_get_priv(volume));
	ocf_queue_t queue = ocf_forward_get_io_queue(token);
	struct vbdev_ocf_qctx *qctx;

	if (io->io_queue == NULL && io_ctx->ch != NULL) {
		spdk_put_io_channel(io_ctx->ch);
	if (unlikely(ocf_queue_is_mngt(queue))) {
		return base->management_channel;
	}

	vbdev_ocf_volume_io_put(io);
	if (bdev_io) {
		spdk_bdev_free_io(bdev_io);
	qctx = ocf_queue_get_priv(queue);
	if (unlikely(qctx == NULL)) {
		return NULL;
	}

	if (--io_ctx->rq_cnt == 0) {
		io->end(io, io_ctx->error);
	}
	return (base->is_cache) ? qctx->cache_ch : qctx->core_ch;
}

static int
prepare_submit(struct ocf_io *io)
static void
vbdev_forward_io(ocf_volume_t volume, ocf_forward_token_t token,
		 int dir, uint64_t addr, uint64_t bytes,
		 uint64_t offset)
{
	struct ocf_io_ctx *io_ctx = ocf_get_io_ctx(io);
	struct vbdev_ocf_qctx *qctx;
	struct vbdev_ocf_base *base;
	ocf_queue_t q = io->io_queue;
	ocf_cache_t cache;
	struct vbdev_ocf_cache_ctx *cctx;
	int rc = 0;
	struct vbdev_ocf_base *base =
		*((struct vbdev_ocf_base **)
		  ocf_volume_get_priv(volume));
	struct bdev_ocf_data *data = ocf_forward_get_data(token);
	struct spdk_io_channel *ch;
	spdk_bdev_io_completion_cb cb = vbdev_forward_io_cb;
	bool iovs_allocated = false;
	int iovcnt, skip, status = -1;
	struct iovec *iovs;

	io_ctx->rq_cnt++;
	if (io_ctx->rq_cnt != 1) {
		return 0;
	ch = vbdev_forward_get_channel(volume, token);
	if (unlikely(ch == NULL)) {
		ocf_forward_end(token, -EFAULT);
		return;
	}

	vbdev_ocf_volume_io_get(io);
	base = *((struct vbdev_ocf_base **)ocf_volume_get_priv(ocf_io_get_volume(io)));

	if (io->io_queue == NULL) {
		/* In case IO is initiated by OCF, queue is unknown
		 * so we have to get io channel ourselves */
		io_ctx->ch = spdk_bdev_get_io_channel(base->desc);
		if (io_ctx->ch == NULL) {
			return -EPERM;
		}
		return 0;
	if (bytes == data->size) {
		iovs = data->iovs;
		iovcnt = data->iovcnt;
	} else {
		skip = get_starting_vec(data->iovs, data->iovcnt, &offset);
		if (skip < 0) {
			SPDK_ERRLOG("Offset bigger than data size\n");
			ocf_forward_end(token, -OCF_ERR_IO);
			return;
		}

	cache = ocf_queue_get_cache(q);
	cctx = ocf_cache_get_priv(cache);
	if (cctx == NULL) {
		return -EFAULT;
	}
		iovcnt = data->iovcnt - skip;

	if (q == cctx->mngt_queue) {
		io_ctx->ch = base->management_channel;
		return 0;
		iovs_allocated = true;
		cb = vbdev_forward_io_free_iovs_cb;
		iovs = env_malloc(sizeof(*iovs) * iovcnt, ENV_MEM_NOIO);

		if (!iovs) {
			SPDK_ERRLOG("Allocation failed\n");
			ocf_forward_end(token, -OCF_ERR_NO_MEM);
			return;
		}

	qctx = ocf_queue_get_priv(q);
	if (qctx == NULL) {
		return -EFAULT;
		initialize_cpy_vector(iovs, data->iovcnt, &data->iovs[skip],
				      iovcnt, offset, bytes);
	}

	if (base->is_cache) {
		io_ctx->ch = qctx->cache_ch;
	} else {
		io_ctx->ch = qctx->core_ch;
	if (dir == OCF_READ) {
		status = spdk_bdev_readv(base->desc, ch, iovs, iovcnt,
					 addr, bytes, cb, (void *) token);
	} else if (dir == OCF_WRITE) {
		status = spdk_bdev_writev(base->desc, ch, iovs, iovcnt,
					  addr, bytes, cb, (void *) token);
	}

	return rc;
	if (unlikely(status)) {
		SPDK_ERRLOG("Submission failed with status=%d\n", status);
		/* Since callback is not called, we need to do it manually to free iovs */
		if (iovs_allocated) {
			env_free(iovs);
		}
		ocf_forward_end(token, (status == -ENOMEM) ? -OCF_ERR_NO_MEM : -OCF_ERR_IO);
	}
}

static void
vbdev_ocf_volume_submit_flush(struct ocf_io *io)
vbdev_forward_flush(ocf_volume_t volume, ocf_forward_token_t token)
{
	struct vbdev_ocf_base *base =
		*((struct vbdev_ocf_base **)
		  ocf_volume_get_priv(ocf_io_get_volume(io)));
	struct ocf_io_ctx *io_ctx = ocf_get_io_ctx(io);
		  ocf_volume_get_priv(volume));
	struct spdk_io_channel *ch;
	uint64_t bytes = base->bdev->blockcnt * base->bdev->blocklen;
	int status;

	status = prepare_submit(io);
	if (status) {
		SPDK_ERRLOG("Preparing io failed with status=%d\n", status);
		vbdev_ocf_volume_submit_io_cb(NULL, false, io);
	ch = vbdev_forward_get_channel(volume, token);
	if (unlikely(ch == NULL)) {
		ocf_forward_end(token, -EFAULT);
		return;
	}

	status = spdk_bdev_flush(
			 base->desc, io_ctx->ch,
			 io->addr, io->bytes,
			 vbdev_ocf_volume_submit_io_cb, io);
	if (status) {
		/* Since callback is not called, we need to do it manually to free io structures */
			 base->desc, ch, 0, bytes,
			 vbdev_forward_io_cb, (void *)token);
	if (unlikely(status)) {
		SPDK_ERRLOG("Submission failed with status=%d\n", status);
		vbdev_ocf_volume_submit_io_cb(NULL, false, io);
		ocf_forward_end(token, (status == -ENOMEM) ? -OCF_ERR_NO_MEM : -OCF_ERR_IO);
	}
}

static void
vbdev_ocf_volume_submit_io(struct ocf_io *io)
vbdev_forward_discard(ocf_volume_t volume, ocf_forward_token_t token,
		      uint64_t addr, uint64_t bytes)
{
	struct vbdev_ocf_base *base =
		*((struct vbdev_ocf_base **)
		  ocf_volume_get_priv(ocf_io_get_volume(io)));
	struct ocf_io_ctx *io_ctx = ocf_get_io_ctx(io);
	struct iovec *iovs;
	int iovcnt, status = 0, i, offset;
	uint64_t addr, len;

	if (io->flags == OCF_WRITE_FLUSH) {
		vbdev_ocf_volume_submit_flush(io);
		return;
	}
		  ocf_volume_get_priv(volume));
	struct spdk_io_channel *ch;
	int status = 0;

	status = prepare_submit(io);
	if (status) {
		SPDK_ERRLOG("Preparing io failed with status=%d\n", status);
		vbdev_ocf_volume_submit_io_cb(NULL, false, io);
	ch = vbdev_forward_get_channel(volume, token);
	if (unlikely(ch == NULL)) {
		ocf_forward_end(token, -EFAULT);
		return;
	}

	/* IO fields */
	addr = io->addr;
	len = io->bytes;
	offset = io_ctx->offset;

	if (len < io_ctx->data->size) {
		if (io_ctx->data->iovcnt == 1) {
			if (io->dir == OCF_READ) {
				status = spdk_bdev_read(base->desc, io_ctx->ch,
							io_ctx->data->iovs[0].iov_base + offset, addr, len,
							vbdev_ocf_volume_submit_io_cb, io);
			} else if (io->dir == OCF_WRITE) {
				status = spdk_bdev_write(base->desc, io_ctx->ch,
							 io_ctx->data->iovs[0].iov_base + offset, addr, len,
							 vbdev_ocf_volume_submit_io_cb, io);
	status = spdk_bdev_unmap(
			 base->desc, ch, addr, bytes,
			 vbdev_forward_io_cb, (void *)token);
	if (unlikely(status)) {
		SPDK_ERRLOG("Submission failed with status=%d\n", status);
		ocf_forward_end(token, (status == -ENOMEM) ? -OCF_ERR_NO_MEM : -OCF_ERR_IO);
	}
			goto end;
		} else {
			i = get_starting_vec(io_ctx->data->iovs, io_ctx->data->iovcnt, &offset);

			if (i < 0) {
				SPDK_ERRLOG("offset bigger than data size\n");
				vbdev_ocf_volume_submit_io_cb(NULL, false, io);
				return;
}

			iovcnt = io_ctx->data->iovcnt - i;

			io_ctx->iovs_allocated = true;
			iovs = env_malloc(sizeof(*iovs) * iovcnt, ENV_MEM_NOIO);

			if (!iovs) {
				SPDK_ERRLOG("allocation failed\n");
				vbdev_ocf_volume_submit_io_cb(NULL, false, io);
				return;
			}
struct vbdev_forward_io_simple_ctx {
	ocf_forward_token_t token;
	struct spdk_io_channel *ch;
};

			initialize_cpy_vector(iovs, io_ctx->data->iovcnt, &io_ctx->data->iovs[i],
					      iovcnt, offset, len);
		}
	} else {
		iovs = io_ctx->data->iovs;
		iovcnt = io_ctx->data->iovcnt;
	}
static void
vbdev_forward_io_simple_cb(struct spdk_bdev_io *bdev_io, bool success, void *opaque)
{
	struct vbdev_forward_io_simple_ctx *ctx = opaque;
	ocf_forward_token_t token = ctx->token;

	if (io->dir == OCF_READ) {
		status = spdk_bdev_readv(base->desc, io_ctx->ch,
					 iovs, iovcnt, addr, len, vbdev_ocf_volume_submit_io_cb, io);
	} else if (io->dir == OCF_WRITE) {
		status = spdk_bdev_writev(base->desc, io_ctx->ch,
					  iovs, iovcnt, addr, len, vbdev_ocf_volume_submit_io_cb, io);
	}
	assert(token);

end:
	if (status) {
		if (status == -ENOMEM) {
			io_ctx->error = -OCF_ERR_NO_MEM;
		} else {
			SPDK_ERRLOG("submission failed with status=%d\n", status);
		}
	spdk_bdev_free_io(bdev_io);
	spdk_put_io_channel(ctx->ch);
	env_free(ctx);

		/* Since callback is not called, we need to do it manually to free io structures */
		vbdev_ocf_volume_submit_io_cb(NULL, false, io);
	}
	ocf_forward_end(token, success ? 0 : -OCF_ERR_IO);
}

static void
vbdev_ocf_volume_submit_discard(struct ocf_io *io)
vbdev_forward_io_simple(ocf_volume_t volume, ocf_forward_token_t token,
			int dir, uint64_t addr, uint64_t bytes)
{
	struct vbdev_ocf_base *base =
		*((struct vbdev_ocf_base **)
		  ocf_volume_get_priv(ocf_io_get_volume(io)));
	struct ocf_io_ctx *io_ctx = ocf_get_io_ctx(io);
	int status = 0;

	status = prepare_submit(io);
	if (status) {
		SPDK_ERRLOG("Preparing io failed with status=%d\n", status);
		vbdev_ocf_volume_submit_io_cb(NULL, false, io);
		  ocf_volume_get_priv(volume));
	struct bdev_ocf_data *data = ocf_forward_get_data(token);
	struct vbdev_forward_io_simple_ctx *ctx;
	int status = -1;

	ctx = env_malloc(sizeof(*ctx), ENV_MEM_NOIO);
	if (unlikely(!ctx)) {
		ocf_forward_end(token, -OCF_ERR_NO_MEM);
		return;
	}

	status = spdk_bdev_unmap(
			 base->desc, io_ctx->ch,
			 io->addr, io->bytes,
			 vbdev_ocf_volume_submit_io_cb, io);
	if (status) {
		/* Since callback is not called, we need to do it manually to free io structures */
		SPDK_ERRLOG("Submission failed with status=%d\n", status);
		vbdev_ocf_volume_submit_io_cb(NULL, false, io);
	}
	/* Forward IO simple is used in context where queue is not available
	 * so we have to get io channel ourselves */
	ctx->ch = spdk_bdev_get_io_channel(base->desc);
	if (unlikely(ctx->ch == NULL)) {
		env_free(ctx);
		ocf_forward_end(token, -EFAULT);
		return;
	}

static void
vbdev_ocf_volume_submit_metadata(struct ocf_io *io)
{
	/* Implement with persistent metadata support */
	ctx->token = token;

	if (dir == OCF_READ) {
		status = spdk_bdev_readv(base->desc, ctx->ch, data->iovs,
					 data->iovcnt, addr, bytes,
					 vbdev_forward_io_simple_cb, ctx);
	} else if (dir == OCF_WRITE) {
		status = spdk_bdev_writev(base->desc, ctx->ch, data->iovs,
					  data->iovcnt, addr, bytes,
					  vbdev_forward_io_simple_cb, ctx);
	}

static unsigned int
vbdev_ocf_volume_get_max_io_size(ocf_volume_t volume)
{
	return 131072;
	if (unlikely(status)) {
		SPDK_ERRLOG("Submission failed with status=%d\n", status);
		spdk_put_io_channel(ctx->ch);
		env_free(ctx);
		ocf_forward_end(token, (status == -ENOMEM) ? -OCF_ERR_NO_MEM : -OCF_ERR_IO);
	}
}

static struct ocf_volume_properties vbdev_volume_props = {
	.name = "SPDK_block_device",
	.io_priv_size = sizeof(struct ocf_io_ctx),
	.volume_priv_size = sizeof(struct vbdev_ocf_base *),
	.caps = {
		.atomic_writes = 0 /* to enable need to have ops->submit_metadata */
@@ -393,15 +331,11 @@ static struct ocf_volume_properties vbdev_volume_props = {
		.open = vbdev_ocf_volume_open,
		.close = vbdev_ocf_volume_close,
		.get_length = vbdev_ocf_volume_get_length,
		.submit_io = vbdev_ocf_volume_submit_io,
		.submit_discard = vbdev_ocf_volume_submit_discard,
		.submit_flush = vbdev_ocf_volume_submit_flush,
		.get_max_io_size = vbdev_ocf_volume_get_max_io_size,
		.submit_metadata = vbdev_ocf_volume_submit_metadata,
	},
	.io_ops = {
		.set_data = vbdev_ocf_volume_io_set_data,
		.get_data = vbdev_ocf_volume_io_get_data,
		.forward_io = vbdev_forward_io,
		.forward_flush = vbdev_forward_flush,
		.forward_discard = vbdev_forward_discard,
		.forward_io_simple = vbdev_forward_io_simple,
	},
};

+0 −18
Original line number Diff line number Diff line
@@ -11,25 +11,7 @@
#include "ctx.h"
#include "data.h"

/* ocf_io context
 * It is initialized from io size and offset */
struct ocf_io_ctx {
	struct bdev_ocf_data *data;
	struct spdk_io_channel *ch;
	uint32_t offset;
	int ref;
	int rq_cnt;
	int error;
	bool iovs_allocated;
};

int vbdev_ocf_volume_init(void);
void vbdev_ocf_volume_cleanup(void);

static inline struct ocf_io_ctx *
ocf_get_io_ctx(struct ocf_io *io)
{
	return ocf_io_get_priv(io);
}

#endif
Loading