Rework exported object management functions
Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
parent
471e9829c0
commit
1dd8f12242
@ -1344,11 +1344,11 @@ int cache_mngt_add_core_to_cache(const char *cache_name, size_t name_len,
|
|||||||
if (result)
|
if (result)
|
||||||
goto error_affter_lock;
|
goto error_affter_lock;
|
||||||
|
|
||||||
result = block_dev_create_exported_object(core);
|
result = kcas_core_create_exported_object(core);
|
||||||
if (result)
|
if (result)
|
||||||
goto error_after_add_core;
|
goto error_after_add_core;
|
||||||
|
|
||||||
result = block_dev_activate_exported_object(core);
|
result = kcas_core_activate_exported_object(core);
|
||||||
if (result)
|
if (result)
|
||||||
goto error_after_create_exported_object;
|
goto error_after_create_exported_object;
|
||||||
|
|
||||||
@ -1366,7 +1366,7 @@ int cache_mngt_add_core_to_cache(const char *cache_name, size_t name_len,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error_after_create_exported_object:
|
error_after_create_exported_object:
|
||||||
block_dev_destroy_exported_object(core);
|
kcas_core_destroy_exported_object(core);
|
||||||
|
|
||||||
error_after_add_core:
|
error_after_add_core:
|
||||||
init_completion(&remove_context.cmpl);
|
init_completion(&remove_context.cmpl);
|
||||||
@ -1386,11 +1386,11 @@ static int _cache_mngt_create_exported_object(ocf_core_t core, void *cntx)
|
|||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
result = block_dev_create_exported_object(core);
|
result = kcas_core_create_exported_object(core);
|
||||||
if (result)
|
if (result)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
result = block_dev_activate_exported_object(core);
|
result = kcas_core_activate_exported_object(core);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -1485,7 +1485,7 @@ static int _cache_mngt_remove_core_prepare(ocf_cache_t cache, ocf_core_t core,
|
|||||||
if (!core_active)
|
if (!core_active)
|
||||||
return -OCF_ERR_CORE_IN_INACTIVE_STATE;
|
return -OCF_ERR_CORE_IN_INACTIVE_STATE;
|
||||||
|
|
||||||
result = block_dev_destroy_exported_object(core);
|
result = kcas_core_destroy_exported_object(core);
|
||||||
if (result)
|
if (result)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
@ -1589,7 +1589,7 @@ int cache_mngt_remove_inactive_core(struct kcas_remove_inactive *cmd)
|
|||||||
* exported object, instead of trying rolling this back we rather
|
* exported object, instead of trying rolling this back we rather
|
||||||
* inform user about error.
|
* inform user about error.
|
||||||
*/
|
*/
|
||||||
result = block_dev_destroy_exported_object(core);
|
result = kcas_core_destroy_exported_object(core);
|
||||||
if (result)
|
if (result)
|
||||||
goto unlock;
|
goto unlock;
|
||||||
|
|
||||||
@ -1728,7 +1728,7 @@ out_get:
|
|||||||
|
|
||||||
static int _cache_mngt_destroy_exported_object(ocf_core_t core, void *cntx)
|
static int _cache_mngt_destroy_exported_object(ocf_core_t core, void *cntx)
|
||||||
{
|
{
|
||||||
if (block_dev_destroy_exported_object(core)) {
|
if (kcas_core_destroy_exported_object(core)) {
|
||||||
ocf_cache_t cache = ocf_core_get_cache(core);
|
ocf_cache_t cache = ocf_core_get_cache(core);
|
||||||
|
|
||||||
printk(KERN_ERR "Cannot to destroy exported object, %s.%s\n",
|
printk(KERN_ERR "Cannot to destroy exported object, %s.%s\n",
|
||||||
@ -2491,7 +2491,7 @@ int cache_mngt_exit_instance(const char *cache_name, size_t name_len, int flush)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Destroy cache devices */
|
/* Destroy cache devices */
|
||||||
status = block_dev_destroy_all_exported_objects(cache);
|
status = kcas_cache_destroy_all_core_exported_objects(cache);
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
printk(KERN_WARNING
|
printk(KERN_WARNING
|
||||||
"Failed to remove all cached devices\n");
|
"Failed to remove all cached devices\n");
|
||||||
|
@ -448,27 +448,10 @@ static struct casdsk_exp_obj_ops _blockdev_exp_obj_ops = {
|
|||||||
.submit_bio = _blockdev_submit_bio,
|
.submit_bio = _blockdev_submit_bio,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/****************************************
|
||||||
* @brief this routine actually adds /dev/casM-N inode
|
* Exported object management functions *
|
||||||
*/
|
****************************************/
|
||||||
int block_dev_activate_exported_object(ocf_core_t core)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
ocf_volume_t obj = ocf_core_get_volume(core);
|
|
||||||
ocf_cache_t cache = ocf_core_get_cache(core);
|
|
||||||
struct bd_object *bvol = bd_object(obj);
|
|
||||||
|
|
||||||
ret = casdisk_functions.casdsk_exp_obj_activate(bvol->dsk);
|
|
||||||
if (ret) {
|
|
||||||
if (-EEXIST == ret)
|
|
||||||
ret = KCAS_ERR_FILE_EXISTS;
|
|
||||||
printk(KERN_ERR "Cannot activate exported object, %s.%s. "
|
|
||||||
"Error code %d\n", ocf_cache_get_name(cache),
|
|
||||||
ocf_core_get_name(core), ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char *get_cache_id_string(ocf_cache_t cache)
|
static const char *get_cache_id_string(ocf_cache_t cache)
|
||||||
{
|
{
|
||||||
@ -480,37 +463,31 @@ static const char *get_core_id_string(ocf_core_t core)
|
|||||||
return ocf_core_get_name(core) + sizeof("core") - 1;
|
return ocf_core_get_name(core) + sizeof("core") - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int block_dev_create_exported_object(ocf_core_t core)
|
static int kcas_volume_create_exported_object(ocf_volume_t volume,
|
||||||
|
const char *name, void *priv, struct casdsk_exp_obj_ops *ops)
|
||||||
{
|
{
|
||||||
ocf_volume_t obj = ocf_core_get_volume(core);
|
struct bd_object *bvol = bd_object(volume);
|
||||||
ocf_cache_t cache = ocf_core_get_cache(core);
|
const struct ocf_volume_uuid *uuid = ocf_volume_get_uuid(volume);
|
||||||
struct bd_object *bvol = bd_object(obj);
|
|
||||||
const struct ocf_volume_uuid *uuid = ocf_volume_get_uuid(obj);
|
|
||||||
char dev_name[DISK_NAME_LEN];
|
char dev_name[DISK_NAME_LEN];
|
||||||
struct casdsk_disk *dsk;
|
struct casdsk_disk *dsk;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
snprintf(dev_name, DISK_NAME_LEN, "cas%s-%s",
|
dsk = casdisk_functions.casdsk_disk_claim(uuid->data, priv);
|
||||||
get_cache_id_string(cache),
|
|
||||||
get_core_id_string(core));
|
|
||||||
|
|
||||||
dsk = casdisk_functions.casdsk_disk_claim(uuid->data, core);
|
|
||||||
if (dsk != bvol->dsk) {
|
if (dsk != bvol->dsk) {
|
||||||
result = -KCAS_ERR_SYSTEM;
|
result = -KCAS_ERR_SYSTEM;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
bvol->expobj_wq = alloc_workqueue("expobj_wq%s-%s",
|
bvol->expobj_wq = alloc_workqueue("expobj_wq_%s",
|
||||||
WQ_MEM_RECLAIM | WQ_HIGHPRI, 0,
|
WQ_MEM_RECLAIM | WQ_HIGHPRI, 0,
|
||||||
get_cache_id_string(cache),
|
name);
|
||||||
get_core_id_string(core));
|
|
||||||
if (!bvol->expobj_wq) {
|
if (!bvol->expobj_wq) {
|
||||||
result = -ENOMEM;
|
result = -ENOMEM;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = casdisk_functions.casdsk_exp_obj_create(dsk, dev_name,
|
result = casdisk_functions.casdsk_exp_obj_create(dsk, name,
|
||||||
THIS_MODULE, &_blockdev_exp_obj_ops);
|
THIS_MODULE, ops);
|
||||||
if (result) {
|
if (result) {
|
||||||
destroy_workqueue(bvol->expobj_wq);
|
destroy_workqueue(bvol->expobj_wq);
|
||||||
goto end;
|
goto end;
|
||||||
@ -526,34 +503,87 @@ end:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int block_dev_destroy_exported_object(ocf_core_t core)
|
static int kcas_volume_destroy_exported_object(ocf_volume_t volume)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
struct bd_object *bvol = bd_object(volume);
|
||||||
ocf_volume_t obj = ocf_core_get_volume(core);
|
int result;
|
||||||
struct bd_object *bvol = bd_object(obj);
|
|
||||||
|
|
||||||
if (!bvol->expobj_valid)
|
if (!bvol->expobj_valid)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ret = casdisk_functions.casdsk_exp_obj_lock(bvol->dsk);
|
result = casdisk_functions.casdsk_exp_obj_lock(bvol->dsk);
|
||||||
if (ret) {
|
if (result == -EBUSY)
|
||||||
if (-EBUSY == ret)
|
return -KCAS_ERR_DEV_PENDING;
|
||||||
ret = -KCAS_ERR_DEV_PENDING;
|
else if (result)
|
||||||
return ret;
|
return result;
|
||||||
}
|
|
||||||
|
|
||||||
ret = casdisk_functions.casdsk_exp_obj_destroy(bvol->dsk);
|
result = casdisk_functions.casdsk_exp_obj_destroy(bvol->dsk);
|
||||||
if (!ret)
|
if (!result)
|
||||||
bvol->expobj_valid = false;
|
bvol->expobj_valid = false;
|
||||||
|
|
||||||
destroy_workqueue(bvol->expobj_wq);
|
destroy_workqueue(bvol->expobj_wq);
|
||||||
|
|
||||||
casdisk_functions.casdsk_exp_obj_unlock(bvol->dsk);
|
casdisk_functions.casdsk_exp_obj_unlock(bvol->dsk);
|
||||||
|
|
||||||
return ret;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _block_dev_lock_exported_object(ocf_core_t core, void *cntx)
|
/**
|
||||||
|
* @brief this routine actually adds /dev/casM-N inode
|
||||||
|
*/
|
||||||
|
static int kcas_volume_activate_exported_object(ocf_volume_t volume,
|
||||||
|
struct casdsk_exp_obj_ops *ops)
|
||||||
|
{
|
||||||
|
struct bd_object *bvol = bd_object(volume);
|
||||||
|
int result;
|
||||||
|
|
||||||
|
result = casdisk_functions.casdsk_exp_obj_activate(bvol->dsk);
|
||||||
|
if (result == -EEXIST)
|
||||||
|
result = -KCAS_ERR_FILE_EXISTS;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int kcas_core_create_exported_object(ocf_core_t core)
|
||||||
|
{
|
||||||
|
ocf_cache_t cache = ocf_core_get_cache(core);
|
||||||
|
ocf_volume_t volume = ocf_core_get_volume(core);
|
||||||
|
char dev_name[DISK_NAME_LEN];
|
||||||
|
|
||||||
|
snprintf(dev_name, DISK_NAME_LEN, "cas%s-%s",
|
||||||
|
get_cache_id_string(cache),
|
||||||
|
get_core_id_string(core));
|
||||||
|
|
||||||
|
return kcas_volume_create_exported_object(volume, dev_name, core,
|
||||||
|
&_blockdev_exp_obj_ops);
|
||||||
|
}
|
||||||
|
|
||||||
|
int kcas_core_destroy_exported_object(ocf_core_t core)
|
||||||
|
{
|
||||||
|
ocf_volume_t volume = ocf_core_get_volume(core);
|
||||||
|
|
||||||
|
return kcas_volume_destroy_exported_object(volume);
|
||||||
|
}
|
||||||
|
|
||||||
|
int kcas_core_activate_exported_object(ocf_core_t core)
|
||||||
|
{
|
||||||
|
ocf_cache_t cache = ocf_core_get_cache(core);
|
||||||
|
ocf_volume_t volume = ocf_core_get_volume(core);
|
||||||
|
int result;
|
||||||
|
|
||||||
|
result = kcas_volume_activate_exported_object(volume,
|
||||||
|
&_blockdev_exp_obj_ops);
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
printk(KERN_ERR "Cannot activate exported object, %s.%s. "
|
||||||
|
"Error code %d\n", ocf_cache_get_name(cache),
|
||||||
|
ocf_core_get_name(core), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int kcas_core_lock_exported_object(ocf_core_t core, void *cntx)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
struct bd_object *bvol = bd_object(
|
struct bd_object *bvol = bd_object(
|
||||||
@ -575,7 +605,7 @@ static int _block_dev_lock_exported_object(ocf_core_t core, void *cntx)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _block_dev_unlock_exported_object(ocf_core_t core, void *cntx)
|
static int kcas_core_unlock_exported_object(ocf_core_t core, void *cntx)
|
||||||
{
|
{
|
||||||
struct bd_object *bvol = bd_object(
|
struct bd_object *bvol = bd_object(
|
||||||
ocf_core_get_volume(core));
|
ocf_core_get_volume(core));
|
||||||
@ -588,7 +618,7 @@ static int _block_dev_unlock_exported_object(ocf_core_t core, void *cntx)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _block_dev_stop_exported_object(ocf_core_t core, void *cntx)
|
static int kcas_core_stop_exported_object(ocf_core_t core, void *cntx)
|
||||||
{
|
{
|
||||||
struct bd_object *bvol = bd_object(
|
struct bd_object *bvol = bd_object(
|
||||||
ocf_core_get_volume(core));
|
ocf_core_get_volume(core));
|
||||||
@ -613,31 +643,31 @@ static int _block_dev_stop_exported_object(ocf_core_t core, void *cntx)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _block_dev_free_exported_object(ocf_core_t core, void *cntx)
|
static int kcas_core_free_exported_object(ocf_core_t core, void *cntx)
|
||||||
{
|
{
|
||||||
struct bd_object *bvol = bd_object(
|
struct bd_object *bvol = bd_object(ocf_core_get_volume(core));
|
||||||
ocf_core_get_volume(core));
|
|
||||||
|
|
||||||
casdisk_functions.casdsk_exp_obj_free(bvol->dsk);
|
casdisk_functions.casdsk_exp_obj_free(bvol->dsk);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int block_dev_destroy_all_exported_objects(ocf_cache_t cache)
|
int kcas_cache_destroy_all_core_exported_objects(ocf_cache_t cache)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
/* Try lock exported objects */
|
/* Try lock exported objects */
|
||||||
result = ocf_core_visit(cache, _block_dev_lock_exported_object, NULL,
|
result = ocf_core_visit(cache, kcas_core_lock_exported_object, NULL,
|
||||||
true);
|
true);
|
||||||
if (result) {
|
if (result) {
|
||||||
/* Failure, unlock already locked exported objects */
|
/* Failure, unlock already locked exported objects */
|
||||||
ocf_core_visit(cache, _block_dev_unlock_exported_object, NULL,
|
ocf_core_visit(cache, kcas_core_unlock_exported_object, NULL,
|
||||||
true);
|
true);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ocf_core_visit(cache, _block_dev_stop_exported_object, NULL, true);
|
ocf_core_visit(cache, kcas_core_stop_exported_object, NULL, true);
|
||||||
|
ocf_core_visit(cache, kcas_core_free_exported_object, NULL, true);
|
||||||
|
|
||||||
return ocf_core_visit(cache, _block_dev_free_exported_object, NULL,
|
return 0;
|
||||||
true);
|
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,11 @@
|
|||||||
#ifndef __VOL_BLOCK_DEV_TOP_H__
|
#ifndef __VOL_BLOCK_DEV_TOP_H__
|
||||||
#define __VOL_BLOCK_DEV_TOP_H__
|
#define __VOL_BLOCK_DEV_TOP_H__
|
||||||
|
|
||||||
int block_dev_activate_exported_object(ocf_core_t core);
|
int kcas_core_activate_exported_object(ocf_core_t core);
|
||||||
|
|
||||||
int block_dev_create_exported_object(ocf_core_t core);
|
int kcas_core_create_exported_object(ocf_core_t core);
|
||||||
|
|
||||||
int block_dev_destroy_all_exported_objects(ocf_cache_t cache);
|
int kcas_cache_destroy_all_core_exported_objects(ocf_cache_t cache);
|
||||||
int block_dev_destroy_exported_object(ocf_core_t core);
|
int kcas_core_destroy_exported_object(ocf_core_t core);
|
||||||
|
|
||||||
#endif /* __VOL_BLOCK_DEV_TOP_H__ */
|
#endif /* __VOL_BLOCK_DEV_TOP_H__ */
|
||||||
|
Loading…
Reference in New Issue
Block a user