Enable cache attach

Signed-off-by: Michal Mielewczyk <michal.mielewczyk@huawei.com>
Signed-off-by: Rafal Stefanowski <rafal.stefanowski@huawei.com>
This commit is contained in:
Michal Mielewczyk
2023-08-23 08:15:16 +02:00
committed by Rafal Stefanowski
parent b480bbaf47
commit af8c75b20a
7 changed files with 186 additions and 6 deletions

View File

@@ -969,6 +969,7 @@ static int _start_cache(uint16_t cache_id, unsigned int cache_init,
int fd = 0;
struct kcas_start_cache cmd = {};
int status;
int ioctl = start ? KCAS_IOCTL_START_CACHE : KCAS_IOCTL_ATTACH_CACHE;
double min_free_ram_gb;
fd = open_ctrl_device();
@@ -993,9 +994,9 @@ static int _start_cache(uint16_t cache_id, unsigned int cache_init,
status = run_ioctl_interruptible_retry(
fd,
KCAS_IOCTL_START_CACHE,
ioctl,
&cmd,
"Starting cache",
start ? "Starting cache" : "Attaching device to cache",
cache_id,
OCF_CORE_ID_INVALID);
cache_id = cmd.cache_id;
@@ -1007,9 +1008,11 @@ static int _start_cache(uint16_t cache_id, unsigned int cache_init,
min_free_ram_gb /= GiB;
cas_printf(LOG_ERR, "Not enough free RAM.\n"
"You need at least %0.2fGB to start cache"
"You need at least %0.2fGB to %s cache"
" with cache line size equal %llukB.\n",
min_free_ram_gb, line_size / KiB);
min_free_ram_gb,
start ? "start" : "attach a device to",
line_size / KiB);
if (64 * KiB > line_size)
cas_printf(LOG_ERR, "Try with greater cache line size.\n");
@@ -1030,7 +1033,9 @@ static int _start_cache(uint16_t cache_id, unsigned int cache_init,
check_cache_state_incomplete(cache_id, fd);
close(fd);
cas_printf(LOG_INFO, "Successfully added cache instance %u\n", cache_id);
cas_printf(LOG_INFO, "Successfully %s %u\n",
start ? "added cache instance" : "attached device to cache",
cache_id);
return SUCCESS;
}
@@ -1043,6 +1048,12 @@ int start_cache(uint16_t cache_id, unsigned int cache_init,
line_size, force, true);
}
int attach_cache(uint16_t cache_id, const char *cache_device, int force)
{
return _start_cache(cache_id, CACHE_INIT_NEW, cache_device,
ocf_cache_mode_none, ocf_cache_line_size_none, force, false);
}
int stop_cache(uint16_t cache_id, int flush)
{
int fd = 0;

View File

@@ -1,5 +1,6 @@
/*
* Copyright(c) 2012-2022 Intel Corporation
* Copyright(c) 2024 Huawei Technologies
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -116,6 +117,8 @@ 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 attach_cache(uint16_t cache_id, const char *cache_device, int force);
#ifdef WI_AVAILABLE
#define CAS_CLI_HELP_START_CACHE_MODES "wt|wb|wa|pt|wi|wo"
#define CAS_CLI_HELP_SET_CACHE_MODES "wt|wb|wa|pt|wi|wo"

View File

@@ -332,6 +332,13 @@ static cli_option start_options[] = {
{0}
};
static cli_option attach_cache_options[] = {
{'d', "cache-device", CACHE_DEVICE_DESC, 1, "DEVICE", CLI_OPTION_REQUIRED},
{'i', "cache-id", CACHE_ID_DESC_LONG, 1, "ID", CLI_OPTION_REQUIRED},
{'f', "force", "Force attaching the cache device"},
{0}
};
static int check_fs(const char* device, bool force)
{
char cache_dev_path[MAX_STR_LEN];
@@ -405,6 +412,15 @@ int validate_cache_path(const char* path, bool force)
return SUCCESS;
}
int handle_cache_attach(void)
{
return attach_cache(
command_args_values.cache_id,
command_args_values.cache_device,
command_args_values.force
);
}
int handle_start()
{
int status;
@@ -2204,6 +2220,16 @@ static cli_command cas_commands[] = {
.flags = CLI_SU_REQUIRED,
.help = NULL,
},
{
.name = "attach-cache",
.desc = "Attach cache device",
.long_desc = NULL,
.options = attach_cache_options,
.command_handle_opts = start_cache_command_handle_option,
.handle = handle_cache_attach,
.flags = CLI_SU_REQUIRED,
.help = NULL,
},
{
.name = "stop-cache",
.short_name = 'T',