Fix exported object cleanup in case of cache stop failure

In case of error during cache stop exported object is not being restored after destroying.
This may result in bug in case of calling stop once more.
This commit fixes this issue - exported objects are restored.

Signed-off-by: Michal Rakowski <michal.rakowski@intel.com>
This commit is contained in:
Michal Rakowski 2019-07-16 16:12:43 +02:00
parent ee6cba515a
commit eee7a0e220
3 changed files with 29 additions and 3 deletions

View File

@ -1646,7 +1646,7 @@ int cache_mngt_exit_instance(ocf_cache_id_t id, int flush)
/* Stop cache device */
status = _cache_mngt_cache_stop_sync(cache);
if (status && status != -OCF_ERR_WRITE_CACHE)
goto unlock;
goto restore_exp_obj;
if (!status && flush_status)
status = -KCAS_ERR_STOPPED_DIRTY;
@ -1658,6 +1658,24 @@ int cache_mngt_exit_instance(ocf_cache_id_t id, int flush)
ocf_queue_put(cache_priv->mngt_queue);
vfree(cache_priv);
ocf_mngt_cache_unlock(cache);
ocf_mngt_cache_put(cache);
return status;
restore_exp_obj:
if (block_dev_create_all_exported_objects(cache)) {
/* Print error msg but do not change return err code to inform user why
* stop failed originally. */
printk(KERN_WARNING
"Failed to restore (create) all exported objects!\n");
goto unlock;
}
if (block_dev_activate_all_exported_objects(cache)) {
block_dev_destroy_all_exported_objects(cache);
printk(KERN_WARNING
"Failed to restore (activate) all exported objects!\n");
}
unlock:
ocf_mngt_cache_unlock(cache);
put:

View File

@ -894,6 +894,7 @@ int block_dev_activate_all_exported_objects(ocf_cache_t cache)
return ocf_core_visit(cache, _block_dev_activate_exported_object, NULL,
true);
}
int block_dev_create_exported_object(ocf_core_t core)
{
ocf_volume_t obj = ocf_core_get_volume(core);
@ -925,7 +926,8 @@ int block_dev_create_exported_object(ocf_core_t core)
return result;
}
static int _block_dev_create_exported_object_visitor(ocf_core_t core, void *cntx){
static int _block_dev_create_exported_object_visitor(ocf_core_t core, void *cntx)
{
return block_dev_create_exported_object(core);
}
@ -934,6 +936,7 @@ int block_dev_create_all_exported_objects(ocf_cache_t cache)
return ocf_core_visit(cache, _block_dev_create_exported_object_visitor, NULL,
true);
}
int block_dev_destroy_exported_object(ocf_core_t core)
{
int ret = 0;
@ -1033,8 +1036,10 @@ int block_dev_destroy_all_exported_objects(ocf_cache_t cache)
ocf_core_visit(cache, _block_dev_stop_exported_object, NULL, true);
block_dev_free_all_exported_objects(cache);
return 0;
}
static int _block_dev_free_exported_object(ocf_core_t core, void *cntx)
{
struct bd_object *bvol = bd_object(

View File

@ -724,7 +724,10 @@ int casdsk_exp_obj_destroy(struct casdsk_disk *dsk)
struct casdsk_exp_obj *exp_obj;
BUG_ON(!dsk);
BUG_ON(!dsk->exp_obj);
if (!dsk->exp_obj)
return -ENODEV;
BUG_ON(!dsk->exp_obj->locked_bd);
CASDSK_DEBUG_DISK_TRACE(dsk);