Introduce cache bind operation

Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
Robert Baldyga
2021-08-19 12:31:35 +02:00
parent c0110a4d01
commit 17aa424319
6 changed files with 120 additions and 47 deletions

View File

@@ -68,6 +68,7 @@ static const char *cache_states_name[ocf_cache_state_max + 1] = {
[ocf_cache_state_stopping] = "Stopping",
[ocf_cache_state_initializing] = "Initializing",
[ocf_cache_state_incomplete] = "Incomplete",
[ocf_cache_state_passive] = "Passive",
[ocf_cache_state_max] = "Unknown",
};
@@ -2775,8 +2776,12 @@ int list_caches(unsigned int list_format, bool by_id_path)
cache_mode_to_name(curr_cache->mode));
} else {
tmp_status = get_cache_state_name(curr_cache->state);
snprintf(mode_string, sizeof(mode_string), "%s",
cache_mode_to_name(curr_cache->mode));
if (curr_cache->state & (1 << ocf_cache_state_passive)) {
strncpy(mode_string, "-", sizeof(mode_string));
} else {
snprintf(mode_string, sizeof(mode_string), "%s",
cache_mode_to_name(curr_cache->mode));
}
}
fprintf(intermediate_file[1], TAG(TREE_BRANCH)

View File

@@ -198,6 +198,8 @@ int start_cache_command_handle_option(char *opt, const char **arg)
command_args_values.cache_id = atoi(arg[0]);
} else if (!strcmp(opt, "load")) {
command_args_values.state = CACHE_INIT_LOAD;
} else if (!strcmp(opt, "bind")) {
command_args_values.state = CACHE_INIT_BIND;
} else if (!strcmp(opt, "cache-device")) {
if(validate_device_name(arg[0]) == FAILURE)
return FAILURE;
@@ -243,6 +245,7 @@ static cli_option start_options[] = {
{'d', "cache-device", CACHE_DEVICE_DESC, 1, "DEVICE", CLI_OPTION_REQUIRED},
{'i', "cache-id", CACHE_ID_DESC_LONG, 1, "ID", 0},
{'l', "load", "Load cache metadata from caching device (DANGEROUS - see manual or Admin Guide for details)"},
{'b', "bind", "Bind caching device (DANGEROUS - see manual or Admin Guide for details)"},
{'f', "force", "Force the creation of cache instance"},
{'c', "cache-mode", "Set cache mode from available: {"CAS_CLI_HELP_START_CACHE_MODES"} "CAS_CLI_HELP_START_CACHE_MODES_FULL"; without this parameter Write-Through will be set by default", 1, "NAME"},
{'x', "cache-line-size", "Set cache line size in kibibytes: {4,8,16,32,64}[KiB] (default: %d)", 1, "NUMBER", CLI_OPTION_DEFAULT_INT, 0, 0, ocf_cache_line_size_default / KiB},
@@ -293,6 +296,11 @@ int handle_start()
return FAILURE;
}
if (command_args_values.state == CACHE_INIT_BIND && command_args_values.force) {
cas_printf(LOG_ERR, "Use of 'bind' and 'force' simultaneously is forbidden.\n");
return FAILURE;
}
cache_device = open(command_args_values.cache_device, O_RDONLY);
if (cache_device < 0) {