failover detach
Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
This commit is contained in:
@@ -68,7 +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_standby] = "Standby",
|
||||
[ocf_cache_state_max] = "Unknown",
|
||||
};
|
||||
|
||||
@@ -782,6 +782,9 @@ struct cache_device *get_cache_device(const struct kcas_cache_info *info, bool b
|
||||
cache->id = cache_id;
|
||||
cache->state = info->info.state;
|
||||
|
||||
if (info->info.failover_detached)
|
||||
return NULL;
|
||||
|
||||
if (strncpy_s(cache->device, sizeof(cache->device),
|
||||
info->cache_path_name,
|
||||
sizeof(info->cache_path_name))) {
|
||||
@@ -2776,7 +2779,7 @@ 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);
|
||||
if (curr_cache->state & (1 << ocf_cache_state_passive)) {
|
||||
if (curr_cache->state & (1 << ocf_cache_state_standby)) {
|
||||
strncpy(mode_string, "-", sizeof(mode_string));
|
||||
} else {
|
||||
snprintf(mode_string, sizeof(mode_string), "%s",
|
||||
@@ -2973,3 +2976,39 @@ int zero_md(const char *cache_device, bool force)
|
||||
cas_printf(LOG_INFO, "OpenCAS's metadata wiped succesfully from device '%s'.\n", cache_device);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int cas_ioctl(int id, void *data)
|
||||
{
|
||||
int fd, result;
|
||||
|
||||
fd = open_ctrl_device();
|
||||
if (fd == -1)
|
||||
return FAILURE;
|
||||
|
||||
result = run_ioctl(fd, id, data);
|
||||
close(fd);
|
||||
|
||||
return result < 0 ? FAILURE : SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int failover_detach(int cache_id)
|
||||
{
|
||||
struct kcas_failover_detach data = {.cache_id = cache_id};
|
||||
|
||||
return cas_ioctl(KCAS_IOCTL_FAILOVER_DETACH, &data);
|
||||
}
|
||||
|
||||
int failover_activate(int cache_id, const char *cache_device)
|
||||
{
|
||||
struct kcas_failover_activate data = {.cache_id = cache_id};
|
||||
|
||||
if (cache_device) {
|
||||
if (set_device_path(data.cache_path, sizeof(data.cache_path),
|
||||
cache_device, MAX_STR_LEN) != SUCCESS) {
|
||||
return FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
return cas_ioctl(KCAS_IOCTL_FAILOVER_ACTIVATE, &data);
|
||||
}
|
||||
|
||||
@@ -204,6 +204,25 @@ int get_core_info(int fd, int cache_id, int core_id, struct kcas_core_info *info
|
||||
int remove_core(unsigned int cache_id, unsigned int core_id,
|
||||
bool detach, bool force_no_flush);
|
||||
|
||||
/**
|
||||
* @brief detach caching device from failover standby cache instance
|
||||
*
|
||||
* @param cache_id cache instance identifier
|
||||
*
|
||||
* @return 0 upon successful detach, 1 upon failure
|
||||
*/
|
||||
int failover_detach(int cache_id);
|
||||
|
||||
/**
|
||||
* @brief activate failover standby cache instance
|
||||
*
|
||||
* @param cache_id cache instance identifier
|
||||
* @param cache_device cache device path
|
||||
*
|
||||
* @return 0 upon successful detach, 1 upon failure
|
||||
*/
|
||||
int failover_activate(int cache_id, const char *cache_device);
|
||||
|
||||
/**
|
||||
* @brief remove inactive core device from a cache
|
||||
*
|
||||
|
||||
@@ -198,10 +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, "activate")) {
|
||||
command_args_values.state = CACHE_INIT_ACTIVATE;
|
||||
} else if (!strcmp(opt, "failover-standby")) {
|
||||
command_args_values.state = CACHE_INIT_STANDBY;
|
||||
} else if (!strcmp(opt, "cache-device")) {
|
||||
if(validate_device_name(arg[0]) == FAILURE)
|
||||
return FAILURE;
|
||||
@@ -247,8 +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)"},
|
||||
{'a', "activate", "Activate caching device after bind"},
|
||||
{'s', "failover-standby", "Start cache in standby mode for failover purpose (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},
|
||||
@@ -288,45 +285,34 @@ static int check_fs(const char* device)
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int handle_start()
|
||||
int validate_cache_path(const char* path)
|
||||
{
|
||||
int cache_device = 0;
|
||||
int status;
|
||||
int cache_device;
|
||||
struct stat device_info;
|
||||
|
||||
if (command_args_values.state == CACHE_INIT_LOAD && command_args_values.force) {
|
||||
cas_printf(LOG_ERR, "Use of 'load' and 'force' simultaneously is forbidden.\n");
|
||||
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);
|
||||
cache_device = open(path, O_RDONLY);
|
||||
|
||||
if (cache_device < 0) {
|
||||
cas_printf(LOG_ERR, "Couldn't open cache device %s.\n",
|
||||
command_args_values.cache_device);
|
||||
cas_printf(LOG_ERR, "Couldn't open cache device %s.\n", path);
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
if (fstat(cache_device, &device_info)) {
|
||||
close(cache_device);
|
||||
cas_printf(LOG_ERR, "Could not stat target device:%s!\n",
|
||||
command_args_values.cache_device);
|
||||
path);
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
if (!S_ISBLK(device_info.st_mode)) {
|
||||
close(cache_device);
|
||||
cas_printf(LOG_ERR, WRONG_DEVICE_ERROR NOT_BLOCK_ERROR,
|
||||
command_args_values.cache_device);
|
||||
path);
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
if (check_fs(command_args_values.cache_device)) {
|
||||
if (check_fs(path)) {
|
||||
close(cache_device);
|
||||
return FAILURE;
|
||||
}
|
||||
@@ -336,6 +322,26 @@ int handle_start()
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int handle_start()
|
||||
{
|
||||
int status;
|
||||
|
||||
if (command_args_values.state == CACHE_INIT_LOAD && command_args_values.force) {
|
||||
cas_printf(LOG_ERR, "Use of 'load' and 'force' simultaneously is forbidden.\n");
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
if (command_args_values.state == CACHE_INIT_STANDBY && command_args_values.force) {
|
||||
cas_printf(LOG_ERR, "Use of 'failover-standby' and 'force' simultaneously is forbidden.\n");
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
if (validate_cache_path(command_args_values.cache_device) == FAILURE)
|
||||
return FAILURE;
|
||||
|
||||
status = start_cache(command_args_values.cache_id,
|
||||
command_args_values.state,
|
||||
command_args_values.cache_device,
|
||||
@@ -1449,6 +1455,18 @@ int io_class_handle() {
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
|
||||
static cli_option failover_detach_options[] = {
|
||||
{'i', "cache-id", CACHE_ID_DESC, 1, "ID", CLI_OPTION_REQUIRED},
|
||||
{}
|
||||
};
|
||||
|
||||
static cli_option failover_activate_options[] = {
|
||||
{'i', "cache-id", CACHE_ID_DESC, 1, "ID", CLI_OPTION_REQUIRED},
|
||||
{'d', "cache-device", CACHE_DEVICE_DESC, 1, "DEVICE"},
|
||||
{}
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
* Script Commands
|
||||
******************************************************************************/
|
||||
@@ -1684,6 +1702,17 @@ int script_command_is_valid() {
|
||||
return result;
|
||||
}
|
||||
|
||||
int handle_failover_detach()
|
||||
{
|
||||
return failover_detach(command_args_values.cache_id);
|
||||
}
|
||||
|
||||
int handle_failover_activate()
|
||||
{
|
||||
return failover_activate(command_args_values.cache_id,
|
||||
command_args_values.cache_device);
|
||||
}
|
||||
|
||||
int script_handle() {
|
||||
if (script_cmd_unknown == command_args_values.script_subcmd) {
|
||||
cas_printf(LOG_ERR, "Invalid or missing first sub-command parameter\n");
|
||||
@@ -2094,6 +2123,30 @@ static cli_command cas_commands[] = {
|
||||
.flags = CLI_SU_REQUIRED,
|
||||
.help = NULL
|
||||
},
|
||||
{
|
||||
.name = "failover-detach",
|
||||
.desc = "Detach cache device from standby cache instance",
|
||||
.long_desc = "Detach cache device from standby cache instance. "
|
||||
"Cache continues to run in failover standby mode, "
|
||||
"awaiting activation on a new drive.",
|
||||
.options = failover_detach_options,
|
||||
.command_handle_opts = command_handle_option,
|
||||
.handle = handle_failover_detach,
|
||||
.flags = CLI_SU_REQUIRED,
|
||||
.help = NULL,
|
||||
|
||||
},
|
||||
{
|
||||
.name = "failover-activate",
|
||||
.desc = "Activate standby cache instance",
|
||||
.long_desc = NULL,
|
||||
.options = failover_activate_options,
|
||||
.command_handle_opts = command_handle_option,
|
||||
.handle = handle_failover_activate,
|
||||
.flags = CLI_SU_REQUIRED,
|
||||
.help = NULL,
|
||||
|
||||
},
|
||||
{
|
||||
.name = "script",
|
||||
.options = script_params_options,
|
||||
|
||||
@@ -538,10 +538,13 @@ int cache_stats_conf(int ctrl_fd, const struct kcas_cache_info *cache_info,
|
||||
char dev_path[MAX_STR_LEN];
|
||||
int inactive_cores;
|
||||
|
||||
if (!by_id_path && get_dev_path(cache_info->cache_path_name, dev_path, sizeof(dev_path)) == SUCCESS)
|
||||
if (strnlen(cache_info->cache_path_name, sizeof(cache_info->cache_path_name)) == 0) {
|
||||
cache_path = "-";
|
||||
} else if (!by_id_path && get_dev_path(cache_info->cache_path_name, dev_path, sizeof(dev_path)) == SUCCESS) {
|
||||
cache_path = dev_path;
|
||||
else
|
||||
} else {
|
||||
cache_path = cache_info->cache_path_name;
|
||||
}
|
||||
|
||||
flush_progress = calculate_flush_progress(cache_info->info.dirty,
|
||||
cache_info->info.flushed);
|
||||
|
||||
Reference in New Issue
Block a user