Enable cache detach

Signed-off-by: Michal Mielewczyk <michal.mielewczyk@huawei.com>
Signed-off-by: Jan Musial <jan.musial@huawei.com>
This commit is contained in:
Michal Mielewczyk
2023-08-23 08:16:51 +02:00
committed by Rafal Stefanowski
parent af8c75b20a
commit 16690e1eab
7 changed files with 161 additions and 1 deletions

View File

@@ -1054,6 +1054,63 @@ int attach_cache(uint16_t cache_id, const char *cache_device, int force)
ocf_cache_mode_none, ocf_cache_line_size_none, force, false);
}
int detach_cache(uint16_t cache_id)
{
int fd = 0;
struct kcas_stop_cache cmd = {};
int ioctl_code = KCAS_IOCTL_DETACH_CACHE;
int status;
fd = open_ctrl_device();
if (fd == -1)
return FAILURE;
cmd.cache_id = cache_id;
cmd.flush_data = true;
status = run_ioctl_interruptible_retry(
fd,
ioctl_code,
&cmd,
"Detaching the device from cache",
cache_id,
OCF_CORE_ID_INVALID);
close(fd);
if (status < 0) {
if (OCF_ERR_FLUSHING_INTERRUPTED == cmd.ext_err_code) {
cas_printf(LOG_ERR,
"You have interrupted detaching the device "
"from cache %d. CAS continues to operate "
"normally.\n",
cache_id
);
return INTERRUPTED;
} else if (OCF_ERR_WRITE_CACHE == cmd.ext_err_code) {
cas_printf(LOG_ERR,
"Detached the device from cache %d "
"with errors\n",
cache_id
);
print_err(cmd.ext_err_code);
return FAILURE;
} else {
cas_printf(LOG_ERR,
"Error while detaching the device from"
" cache %d\n",
cache_id
);
print_err(cmd.ext_err_code);
return FAILURE;
}
}
cas_printf(LOG_INFO, "Successfully detached device from cache %hu\n",
cache_id);
return SUCCESS;
}
int stop_cache(uint16_t cache_id, int flush)
{
int fd = 0;
@@ -1082,7 +1139,6 @@ int stop_cache(uint16_t cache_id, int flush)
close(fd);
if (status < 0) {
if (OCF_ERR_FLUSHING_INTERRUPTED == cmd.ext_err_code) {
cas_printf(LOG_ERR,
"You have interrupted stopping of cache %d. "

View File

@@ -117,6 +117,7 @@ int start_cache(uint16_t cache_id, unsigned int cache_init,
ocf_cache_line_size_t line_size, int force);
int stop_cache(uint16_t cache_id, int flush);
int detach_cache(uint16_t cache_id);
int attach_cache(uint16_t cache_id, const char *cache_device, int force);
#ifdef WI_AVAILABLE

View File

@@ -421,6 +421,11 @@ int handle_cache_attach(void)
);
}
int handle_cache_detach(void)
{
return detach_cache(command_args_values.cache_id);
}
int handle_start()
{
int status;
@@ -543,6 +548,11 @@ static cli_option stop_options[] = {
{0}
};
static cli_option detach_options[] = {
{'i', "cache-id", CACHE_ID_DESC, 1, "ID", CLI_OPTION_REQUIRED},
{0}
};
int handle_stop()
{
return stop_cache(command_args_values.cache_id,
@@ -2230,6 +2240,16 @@ static cli_command cas_commands[] = {
.flags = CLI_SU_REQUIRED,
.help = NULL,
},
{
.name = "detach-cache",
.desc = "Detach cache device",
.long_desc = NULL,
.options = detach_options,
.command_handle_opts = command_handle_option,
.handle = handle_cache_detach,
.flags = CLI_SU_REQUIRED,
.help = NULL,
},
{
.name = "stop-cache",
.short_name = 'T',