Merge exp obj create/activate
Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
parent
d0d17545eb
commit
5e2c1c15cf
@ -375,6 +375,36 @@ static int _cas_init_tag_set(struct cas_disk *dsk, struct blk_mq_tag_set *set)
|
||||
return blk_mq_alloc_tag_set(set);
|
||||
}
|
||||
|
||||
static int _cas_exp_obj_check_path(const char *dev_name)
|
||||
{
|
||||
struct file *exported;
|
||||
char *path;
|
||||
int result;
|
||||
|
||||
path = kmalloc(PATH_MAX, GFP_KERNEL);
|
||||
if (!path)
|
||||
return -ENOMEM;
|
||||
|
||||
snprintf(path, PATH_MAX, "/dev/%s", dev_name);
|
||||
|
||||
exported = filp_open(path, O_RDONLY, 0);
|
||||
|
||||
if (!IS_ERR_OR_NULL(exported)) {
|
||||
filp_close(exported, NULL);
|
||||
result = -EEXIST;
|
||||
|
||||
} else {
|
||||
/* failed to open file - it is safe to assume,
|
||||
* it does not exist
|
||||
*/
|
||||
result = 0;
|
||||
}
|
||||
|
||||
kfree(path);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int cas_exp_obj_create(struct cas_disk *dsk, const char *dev_name,
|
||||
struct module *owner, struct cas_exp_obj_ops *ops, void *priv)
|
||||
{
|
||||
@ -393,9 +423,18 @@ int cas_exp_obj_create(struct cas_disk *dsk, const char *dev_name,
|
||||
if (strlen(dev_name) >= DISK_NAME_LEN)
|
||||
return -EINVAL;
|
||||
|
||||
result = _cas_exp_obj_check_path(dev_name);
|
||||
if (result == -EEXIST) {
|
||||
printk(KERN_ERR "Could not activate exported object, "
|
||||
"because file /dev/%s exists.\n", dev_name);
|
||||
}
|
||||
|
||||
if (result)
|
||||
return result;
|
||||
|
||||
result = cas_exp_obj_alloc(dsk);
|
||||
if (result)
|
||||
goto error_exp_obj_alloc;
|
||||
return result;
|
||||
|
||||
exp_obj = dsk->exp_obj;
|
||||
|
||||
@ -451,8 +490,16 @@ int cas_exp_obj_create(struct cas_disk *dsk, const char *dev_name,
|
||||
goto error_set_geometry;
|
||||
}
|
||||
|
||||
add_disk(gd);
|
||||
|
||||
result = bd_claim_by_disk(dsk->bd, dsk, gd);
|
||||
if (result)
|
||||
goto error_bd_claim;
|
||||
|
||||
return 0;
|
||||
|
||||
error_bd_claim:
|
||||
del_gendisk(dsk->exp_obj->gd);
|
||||
error_set_geometry:
|
||||
exp_obj->private = NULL;
|
||||
_cas_exp_obj_clear_dev_t(dsk);
|
||||
@ -468,70 +515,10 @@ error_module_get:
|
||||
kfree(exp_obj->dev_name);
|
||||
error_kstrdup:
|
||||
cas_exp_obj_free(dsk);
|
||||
error_exp_obj_alloc:
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
static bool _cas_exp_obj_exists(const char *path)
|
||||
{
|
||||
struct file *exported;
|
||||
|
||||
exported = filp_open(path, O_RDONLY, 0);
|
||||
|
||||
if (!exported || IS_ERR(exported)) {
|
||||
/*failed to open file - it is safe to assume,
|
||||
* it does not exist
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
||||
filp_close(exported, NULL);
|
||||
return true;
|
||||
}
|
||||
|
||||
int cas_exp_obj_activate(struct cas_disk *dsk)
|
||||
{
|
||||
char *path;
|
||||
int result;
|
||||
|
||||
BUG_ON(!dsk);
|
||||
BUG_ON(!dsk->exp_obj);
|
||||
BUG_ON(!dsk->exp_obj->gd);
|
||||
BUG_ON(dsk->exp_obj->activated);
|
||||
|
||||
CAS_DEBUG_DISK_TRACE(dsk);
|
||||
|
||||
path = kmalloc(PATH_MAX, GFP_KERNEL);
|
||||
if (!path)
|
||||
return -ENOMEM;
|
||||
|
||||
snprintf(path, PATH_MAX, "/dev/%s", dsk->exp_obj->dev_name);
|
||||
if (_cas_exp_obj_exists(path)) {
|
||||
printk(KERN_ERR "Could not activate exported object, "
|
||||
"because file %s exists.\n", path);
|
||||
kfree(path);
|
||||
return -EEXIST;
|
||||
}
|
||||
kfree(path);
|
||||
|
||||
dsk->exp_obj->activated = true;
|
||||
add_disk(dsk->exp_obj->gd);
|
||||
|
||||
result = bd_claim_by_disk(dsk->bd, dsk, dsk->exp_obj->gd);
|
||||
if (result)
|
||||
goto error_bd_claim;
|
||||
|
||||
CAS_DEBUG_DISK(dsk, "Activated exp object %s", dsk->exp_obj->dev_name);
|
||||
|
||||
return 0;
|
||||
|
||||
error_bd_claim:
|
||||
del_gendisk(dsk->exp_obj->gd);
|
||||
dsk->exp_obj->activated = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
int cas_exp_obj_destroy(struct cas_disk *dsk)
|
||||
{
|
||||
struct cas_exp_obj *exp_obj;
|
||||
@ -545,11 +532,9 @@ int cas_exp_obj_destroy(struct cas_disk *dsk)
|
||||
|
||||
exp_obj = dsk->exp_obj;
|
||||
|
||||
if (dsk->exp_obj->activated) {
|
||||
bd_release_from_disk(dsk->bd, exp_obj->gd);
|
||||
_cas_exp_obj_clear_dev_t(dsk);
|
||||
del_gendisk(exp_obj->gd);
|
||||
}
|
||||
bd_release_from_disk(dsk->bd, exp_obj->gd);
|
||||
_cas_exp_obj_clear_dev_t(dsk);
|
||||
del_gendisk(exp_obj->gd);
|
||||
|
||||
if (exp_obj->queue)
|
||||
blk_cleanup_queue(exp_obj->queue);
|
||||
|
@ -33,8 +33,6 @@ struct cas_exp_obj {
|
||||
|
||||
struct module *owner;
|
||||
|
||||
bool activated;
|
||||
|
||||
struct cas_exp_obj_ops *ops;
|
||||
|
||||
const char *dev_name;
|
||||
@ -85,14 +83,6 @@ struct request_queue *cas_exp_obj_get_queue(struct cas_disk *dsk);
|
||||
*/
|
||||
struct gendisk *cas_exp_obj_get_gendisk(struct cas_disk *dsk);
|
||||
|
||||
/**
|
||||
* @brief Activate exported object (make it visible to OS
|
||||
* and allow I/O handling)
|
||||
* @param dsk Pointer to cas_disk structure representing a block device
|
||||
* @return 0 if success, errno if failure
|
||||
*/
|
||||
int cas_exp_obj_activate(struct cas_disk *dsk);
|
||||
|
||||
/**
|
||||
* @brief Lock exported object
|
||||
* @param dsk Pointer to cas_disk structure representing a block device
|
||||
|
@ -1389,10 +1389,6 @@ int cache_mngt_add_core_to_cache(const char *cache_name, size_t name_len,
|
||||
if (result)
|
||||
goto error_after_add_core;
|
||||
|
||||
result = kcas_core_activate_exported_object(core);
|
||||
if (result)
|
||||
goto error_after_create_exported_object;
|
||||
|
||||
result = core_id_from_name(&core_id, cfg->name);
|
||||
if (result)
|
||||
goto error_after_create_exported_object;
|
||||
@ -1768,8 +1764,6 @@ static int _cache_mngt_create_core_exp_obj(ocf_core_t core, void *cntx)
|
||||
if (result)
|
||||
return result;
|
||||
|
||||
result = kcas_core_activate_exported_object(core);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -1830,12 +1824,6 @@ static int cache_mngt_initialize_cache_exported_object(ocf_cache_t cache)
|
||||
if (result)
|
||||
return result;
|
||||
|
||||
result = kcas_cache_activate_exported_object(cache);
|
||||
if (result) {
|
||||
cache_mngt_destroy_cache_exp_obj(cache);
|
||||
return result;
|
||||
}
|
||||
|
||||
cache_priv->cache_exp_obj_initialized = true;
|
||||
|
||||
return 0;
|
||||
|
@ -601,19 +601,6 @@ err:
|
||||
/**
|
||||
* @brief this routine actually adds /dev/casM-N inode
|
||||
*/
|
||||
static int kcas_volume_activate_exported_object(ocf_volume_t volume,
|
||||
struct cas_exp_obj_ops *ops)
|
||||
{
|
||||
struct bd_object *bvol = bd_object(volume);
|
||||
int result;
|
||||
|
||||
result = cas_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);
|
||||
@ -638,23 +625,6 @@ int kcas_core_destroy_exported_object(ocf_core_t 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,
|
||||
&kcas_core_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;
|
||||
}
|
||||
|
||||
int kcas_cache_create_exported_object(ocf_cache_t cache)
|
||||
{
|
||||
ocf_volume_t volume = ocf_cache_get_volume(cache);
|
||||
@ -677,22 +647,6 @@ int kcas_cache_destroy_exported_object(ocf_cache_t cache)
|
||||
return kcas_volume_destroy_exported_object(volume);
|
||||
}
|
||||
|
||||
int kcas_cache_activate_exported_object(ocf_cache_t cache)
|
||||
{
|
||||
ocf_volume_t volume = ocf_cache_get_volume(cache);
|
||||
int result;
|
||||
|
||||
result = kcas_volume_activate_exported_object(volume,
|
||||
&kcas_cache_exp_obj_ops);
|
||||
if (result) {
|
||||
printk(KERN_ERR "Cannot activate cache %s exported object. "
|
||||
"Error code %d\n", ocf_cache_get_name(cache),
|
||||
result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static int kcas_core_lock_exported_object(ocf_core_t core, void *cntx)
|
||||
{
|
||||
int result;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright(c) 2012-2021 Intel Corporation
|
||||
* Copyright(c) 2012-2022 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
@ -9,12 +9,10 @@
|
||||
|
||||
int kcas_core_create_exported_object(ocf_core_t core);
|
||||
int kcas_core_destroy_exported_object(ocf_core_t core);
|
||||
int kcas_core_activate_exported_object(ocf_core_t core);
|
||||
|
||||
int kcas_cache_destroy_all_core_exported_objects(ocf_cache_t cache);
|
||||
|
||||
int kcas_cache_create_exported_object(ocf_cache_t cache);
|
||||
int kcas_cache_destroy_exported_object(ocf_cache_t cache);
|
||||
int kcas_cache_activate_exported_object(ocf_cache_t cache);
|
||||
|
||||
#endif /* __VOL_BLOCK_DEV_TOP_H__ */
|
||||
|
Loading…
Reference in New Issue
Block a user