diff --git a/lib/bdev/ocf/ctx.h b/lib/bdev/ocf/ctx.h index 2a77e5a53..807eca1da 100644 --- a/lib/bdev/ocf/ctx.h +++ b/lib/bdev/ocf/ctx.h @@ -44,6 +44,7 @@ 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; }; diff --git a/lib/bdev/ocf/vbdev_ocf.c b/lib/bdev/ocf/vbdev_ocf.c index e9a4cba01..1681c3a79 100644 --- a/lib/bdev/ocf/vbdev_ocf.c +++ b/lib/bdev/ocf/vbdev_ocf.c @@ -244,7 +244,9 @@ stop_vbdev_cmpl(ocf_cache_t cache, void *priv, int error) { struct vbdev_ocf *vbdev = priv; + vbdev_ocf_queue_put(vbdev->cache_ctx->mngt_queue); ocf_mngt_cache_unlock(cache); + vbdev_ocf_mngt_continue(vbdev, error); } @@ -653,7 +655,8 @@ static struct spdk_bdev_fn_table cache_dev_fn_table = { /* Poller function for the OCF queue * We execute OCF requests here synchronously */ -static int queue_poll(void *opaque) +static int +queue_poll(void *opaque) { struct vbdev_ocf_qcxt *qctx = opaque; uint32_t iono = ocf_queue_pending_io(qctx->queue); @@ -745,6 +748,49 @@ io_device_destroy_cb(void *io_device, void *ctx_buf) vbdev_ocf_queue_put(qctx->queue); } +/* OCF management queue deinitialization */ +static void +vbdev_ocf_ctx_mngt_queue_stop(ocf_queue_t q) +{ + struct spdk_poller *poller = ocf_queue_get_priv(q); + + if (poller) { + spdk_poller_unregister(&poller); + } +} + +static int +mngt_queue_poll(void *opaque) +{ + ocf_queue_t q = opaque; + uint32_t iono = ocf_queue_pending_io(q); + int i, max = spdk_min(32, iono); + + for (i = 0; i < max; i++) { + ocf_queue_run_single(q); + } + + if (iono > 0) { + return 1; + } else { + return 0; + } +} + +static void +vbdev_ocf_ctx_mngt_queue_kick(ocf_queue_t q) +{ +} + +/* Queue ops is an interface for running queue thread + * stop() operation in called just before queue gets destroyed */ +const struct ocf_queue_ops mngt_queue_ops = { + .kick_sync = NULL, + .kick = vbdev_ocf_ctx_mngt_queue_kick, + .stop = vbdev_ocf_ctx_mngt_queue_stop, +}; + +/* Create exported spdk object */ static void finish_register(struct vbdev_ocf *vbdev) { @@ -821,6 +867,30 @@ start_cache_cmpl(ocf_cache_t cache, void *priv, int error) vbdev_ocf_mngt_continue(vbdev, error); } +static int +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); + if (rc) { + SPDK_ERRLOG("Unable to create mngt_queue: %d\n", rc); + return rc; + } + + mngt_poller = spdk_poller_register(mngt_queue_poll, vbdev->cache_ctx->mngt_queue, 100); + if (mngt_poller == NULL) { + SPDK_ERRLOG("Unable to initiate mngt request: %s", spdk_strerror(ENOMEM)); + return -ENOMEM; + } + + 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; +} + /* Start OCF cache, attach caching device */ static void start_cache(struct vbdev_ocf *vbdev) @@ -867,6 +937,15 @@ start_cache(struct vbdev_ocf *vbdev) vbdev->cache.id = ocf_cache_get_id(vbdev->ocf_cache); ocf_cache_set_priv(vbdev->ocf_cache, vbdev->cache_ctx); + rc = create_management_queue(vbdev); + if (rc) { + SPDK_ERRLOG("Unable to create mngt_queue: %d\n", rc); + vbdev_ocf_cache_ctx_put(vbdev->cache_ctx); + vbdev->mngt_ctx.status = rc; + vbdev_ocf_mngt_stop(vbdev); + return; + } + ocf_mngt_cache_attach(vbdev->ocf_cache, &vbdev->cfg.device, start_cache_cmpl, vbdev); } diff --git a/ocf b/ocf index 56f4d3492..08a5b9d2a 160000 --- a/ocf +++ b/ocf @@ -1 +1 @@ -Subproject commit 56f4d34920ceeb650cdbc7362fc6a775f61a19a3 +Subproject commit 08a5b9d2a4dcc894abb88d90117858237c3a39a1