Reflect cache attach API changes in example

Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
Robert Baldyga 2022-05-13 20:02:33 +02:00 committed by Jan Musial
parent b847fa9a61
commit bc0e28f1c6

View File

@ -72,6 +72,9 @@ int initialize_cache(ocf_ctx_t ctx, ocf_cache_t *cache)
{ {
struct ocf_mngt_cache_config cache_cfg = { .name = "cache1" }; struct ocf_mngt_cache_config cache_cfg = { .name = "cache1" };
struct ocf_mngt_cache_attach_config attach_cfg = { }; struct ocf_mngt_cache_attach_config attach_cfg = { };
ocf_volume_t volume;
ocf_volume_type_t type;
struct ocf_volume_uuid uuid;
struct cache_priv *cache_priv; struct cache_priv *cache_priv;
struct simple_context context; struct simple_context context;
int ret; int ret;
@ -92,20 +95,28 @@ int initialize_cache(ocf_ctx_t ctx, ocf_cache_t *cache)
cache_cfg.metadata_volatile = true; cache_cfg.metadata_volatile = true;
/* Cache deivce (volume) configuration */ /* Cache deivce (volume) configuration */
ocf_mngt_cache_attach_config_set_default(&attach_cfg); type = ocf_ctx_get_volume_type(ctx, VOL_TYPE);
attach_cfg.device.volume_type = VOL_TYPE; ret = ocf_uuid_set_str(&uuid, "cache");
ret = ocf_uuid_set_str(&attach_cfg.device.uuid, "cache");
if (ret) if (ret)
goto err_sem; goto err_sem;
ret = ocf_volume_create(&volume, type, &uuid);
if (ret)
goto err_sem;
ocf_mngt_cache_attach_config_set_default(&attach_cfg);
attach_cfg.device.volume = volume;
/* /*
* Allocate cache private structure. We can not initialize it * Allocate cache private structure. We can not initialize it
* on stack, as it may be used in various async contexts * on stack, as it may be used in various async contexts
* throughout the entire live span of cache object. * throughout the entire live span of cache object.
*/ */
cache_priv = malloc(sizeof(*cache_priv)); cache_priv = malloc(sizeof(*cache_priv));
if (!cache_priv) if (!cache_priv) {
return -ENOMEM; ret = -ENOMEM;
goto err_vol;
}
/* Start cache */ /* Start cache */
ret = ocf_mngt_cache_start(ctx, cache, &cache_cfg, NULL); ret = ocf_mngt_cache_start(ctx, cache, &cache_cfg, NULL);
@ -157,6 +168,8 @@ err_cache:
ocf_queue_put(cache_priv->mngt_queue); ocf_queue_put(cache_priv->mngt_queue);
err_priv: err_priv:
free(cache_priv); free(cache_priv);
err_vol:
ocf_volume_destroy(&volume);
err_sem: err_sem:
sem_destroy(&context.sem); sem_destroy(&context.sem);
return ret; return ret;