Fix error handling in IO ocf_mngt_cache_io_classes_configure

Modifying _ocf_mngt_io_class_configure and _ocf_mngt_io_class_remove
to never return -OCF_ERR_IO_CLASS_NOT_EXIST error code. This
return code was ignored by the caller anyway. In _ocf_mngt_io_class_remove
-OCF_ERR_IO_CLASS_NOT_EXIST indicated the IO class is already
removed, which is not an error. In _ocf_mngt_io_class_configure
-OCF_ERR_IO_CLASS_NOT_EXIST indicated empty IO class name, which
is actualy invalid input. This change made it possible to remove
erroneous error handling for -OCF_ERR_IO_CLASS_NOT_EXIST case in
ocf_mngt_cache_io_classes_configure.

This change fixes IO class configuration.

Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
This commit is contained in:
Adam Rutkowski 2019-09-24 21:09:02 -04:00
parent ed1ae71992
commit 727a6d2e4b

View File

@ -117,8 +117,8 @@ static int _ocf_mngt_io_class_configure(ocf_cache_t cache,
return -OCF_ERR_INVAL; return -OCF_ERR_INVAL;
} }
if (!name || !name[0]) if (!name[0])
return -OCF_ERR_IO_CLASS_NOT_EXIST; return -OCF_ERR_INVAL;
if (part_id == PARTITION_DEFAULT) { if (part_id == PARTITION_DEFAULT) {
/* Special behavior for default partition */ /* Special behavior for default partition */
@ -175,12 +175,11 @@ static int _ocf_mngt_io_class_configure(ocf_cache_t cache,
return result; return result;
} }
static int _ocf_mngt_io_class_remove(ocf_cache_t cache, static void _ocf_mngt_io_class_remove(ocf_cache_t cache,
const struct ocf_mngt_io_class_config *cfg) const struct ocf_mngt_io_class_config *cfg)
{ {
struct ocf_user_part *dest_part; struct ocf_user_part *dest_part;
ocf_part_id_t part_id = cfg->class_id; ocf_part_id_t part_id = cfg->class_id;
int result;
dest_part = &cache->user_parts[part_id]; dest_part = &cache->user_parts[part_id];
@ -190,37 +189,30 @@ static int _ocf_mngt_io_class_remove(ocf_cache_t cache,
ocf_cache_log(cache, log_info, ocf_cache_log(cache, log_info,
"Cannot remove unclassified IO class, " "Cannot remove unclassified IO class, "
"id: %u [ ERROR ]\n", part_id); "id: %u [ ERROR ]\n", part_id);
return 0; return;
} }
if (ocf_part_is_valid(dest_part)) { if (!ocf_part_is_valid(dest_part)) {
/* Does not exist */
return;
}
result = 0;
ocf_part_set_valid(cache, part_id, false); ocf_part_set_valid(cache, part_id, false);
ocf_cache_log(cache, log_info, ocf_cache_log(cache, log_info,
"Removing IO class, id: %u [ %s ]\n", "Removing IO class, id: %u [ OK ]\n", part_id);
part_id, result ? "ERROR" : "OK");
} else {
/* Does not exist */
result = -OCF_ERR_IO_CLASS_NOT_EXIST;
}
return result;
} }
static int _ocf_mngt_io_class_edit(ocf_cache_t cache, static int _ocf_mngt_io_class_edit(ocf_cache_t cache,
const struct ocf_mngt_io_class_config *cfg) const struct ocf_mngt_io_class_config *cfg)
{ {
int result; int result = 0;
if (cfg->name) { if (cfg->name)
result = _ocf_mngt_io_class_configure(cache, cfg); result = _ocf_mngt_io_class_configure(cache, cfg);
} else { else
result = _ocf_mngt_io_class_remove(cache, cfg); _ocf_mngt_io_class_remove(cache, cfg);
}
return result; return result;
} }
@ -284,7 +276,7 @@ int ocf_mngt_cache_io_classes_configure(ocf_cache_t cache,
for (i = 0; i < OCF_IO_CLASS_MAX; i++) { for (i = 0; i < OCF_IO_CLASS_MAX; i++) {
result = _ocf_mngt_io_class_edit(cache, &cfg->config[i]); result = _ocf_mngt_io_class_edit(cache, &cfg->config[i]);
if (result && result != -OCF_ERR_IO_CLASS_NOT_EXIST) { if (result) {
ocf_cache_log(cache, log_err, ocf_cache_log(cache, log_err,
"Failed to set new io class config\n"); "Failed to set new io class config\n");
goto out_edit; goto out_edit;