ocf: add shared cache instance context
Introduce cache context structure that is going to be used
for sharing per cache info. For example: management queue,
cleaner_channel, cleaner_thread.
Lifetime of this structure ends with last vbdev that gets unregistered
and NOT when cache stops because cache does not have to be freed
there.
Signed-off-by: Vitaliy Mysak <vitaliy.mysak@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/451403 (master)
(cherry picked from commit 4e7fb25066
)
Change-Id: I66252084d7efda92edd10fb737c8e9c8169b4f6d
Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/457254
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
301d6e7c78
commit
58b41ea2b5
@ -288,6 +288,18 @@ vbdev_ocf_ctx_data_secure_erase(ctx_data_t *ctx_data)
|
||||
}
|
||||
}
|
||||
|
||||
void vbdev_ocf_cache_ctx_put(struct vbdev_ocf_cache_ctx *ctx)
|
||||
{
|
||||
if (env_atomic_dec_return(&ctx->refcnt) == 0) {
|
||||
free(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
void vbdev_ocf_cache_ctx_get(struct vbdev_ocf_cache_ctx *ctx)
|
||||
{
|
||||
env_atomic_inc(&ctx->refcnt);
|
||||
}
|
||||
|
||||
static int
|
||||
vbdev_ocf_ctx_cleaner_init(ocf_cleaner_t c)
|
||||
{
|
||||
|
@ -42,6 +42,14 @@ extern ocf_ctx_t vbdev_ocf_ctx;
|
||||
|
||||
#define SPDK_OBJECT 1
|
||||
|
||||
/* Context of cache instance */
|
||||
struct vbdev_ocf_cache_ctx {
|
||||
env_atomic refcnt;
|
||||
};
|
||||
|
||||
void vbdev_ocf_cache_ctx_put(struct vbdev_ocf_cache_ctx *ctx);
|
||||
void vbdev_ocf_cache_ctx_get(struct vbdev_ocf_cache_ctx *ctx);
|
||||
|
||||
int vbdev_ocf_ctx_init(void);
|
||||
void vbdev_ocf_ctx_cleanup(void);
|
||||
|
||||
|
@ -171,6 +171,7 @@ static void
|
||||
unregister_finish(struct vbdev_ocf *vbdev)
|
||||
{
|
||||
spdk_bdev_destruct_done(&vbdev->exp_bdev, vbdev->state.stop_status);
|
||||
vbdev_ocf_cache_ctx_put(vbdev->cache_ctx);
|
||||
vbdev_ocf_mngt_continue(vbdev, 0);
|
||||
}
|
||||
|
||||
@ -839,18 +840,31 @@ start_cache(struct vbdev_ocf *vbdev)
|
||||
vbdev->name, vbdev->cache.name);
|
||||
vbdev->ocf_cache = existing;
|
||||
vbdev->cache.id = ocf_cache_get_id(existing);
|
||||
vbdev->cache_ctx = ocf_cache_get_priv(existing);
|
||||
vbdev_ocf_cache_ctx_get(vbdev->cache_ctx);
|
||||
vbdev_ocf_mngt_continue(vbdev, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
vbdev->cache_ctx = calloc(1, sizeof(struct vbdev_ocf_cache_ctx));
|
||||
if (vbdev->cache_ctx == NULL) {
|
||||
vbdev->mngt_ctx.status = -ENOMEM;
|
||||
vbdev_ocf_mngt_stop(vbdev);
|
||||
return;
|
||||
}
|
||||
|
||||
vbdev_ocf_cache_ctx_get(vbdev->cache_ctx);
|
||||
|
||||
rc = ocf_mngt_cache_start(vbdev_ocf_ctx, &vbdev->ocf_cache, &vbdev->cfg.cache);
|
||||
if (rc) {
|
||||
vbdev_ocf_cache_ctx_put(vbdev->cache_ctx);
|
||||
vbdev->mngt_ctx.status = rc;
|
||||
vbdev_ocf_mngt_stop(vbdev);
|
||||
return;
|
||||
}
|
||||
|
||||
vbdev->cache.id = ocf_cache_get_id(vbdev->ocf_cache);
|
||||
ocf_cache_set_priv(vbdev->ocf_cache, vbdev->cache_ctx);
|
||||
|
||||
ocf_mngt_cache_attach(vbdev->ocf_cache, &vbdev->cfg.device, start_cache_cmpl, vbdev);
|
||||
}
|
||||
|
@ -156,6 +156,8 @@ struct vbdev_ocf {
|
||||
|
||||
/* Management context */
|
||||
struct vbdev_ocf_mngt_ctx mngt_ctx;
|
||||
/* Cache conext */
|
||||
struct vbdev_ocf_cache_ctx *cache_ctx;
|
||||
|
||||
/* Exposed SPDK bdev. Registered in bdev layer */
|
||||
struct spdk_bdev exp_bdev;
|
||||
|
Loading…
Reference in New Issue
Block a user