diff --git a/modules/cas_cache/layer_cache_management.c b/modules/cas_cache/layer_cache_management.c index 0c4d128..b88972d 100644 --- a/modules/cas_cache/layer_cache_management.c +++ b/modules/cas_cache/layer_cache_management.c @@ -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: diff --git a/modules/cas_cache/volume/vol_block_dev_top.c b/modules/cas_cache/volume/vol_block_dev_top.c index 1db0b60..98480fa 100644 --- a/modules/cas_cache/volume/vol_block_dev_top.c +++ b/modules/cas_cache/volume/vol_block_dev_top.c @@ -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( diff --git a/modules/cas_disk/exp_obj.c b/modules/cas_disk/exp_obj.c index a6a4c04..17202f8 100644 --- a/modules/cas_disk/exp_obj.c +++ b/modules/cas_disk/exp_obj.c @@ -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);