Skip to content
Merged
3 changes: 2 additions & 1 deletion casadm/cas_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -2707,7 +2707,7 @@ int partition_set_config(struct kcas_io_classes *cnfg)
return result;
}

int partition_setup(unsigned int cache_id, const char *file)
int partition_setup(unsigned int cache_id, bool reclassify, const char *file)
{
int result = 0;
CSVFILE *in;
Expand Down Expand Up @@ -2739,6 +2739,7 @@ int partition_setup(unsigned int cache_id, const char *file)
}

if (0 == partition_get_config(in, cnfg, cache_id)) {
cnfg->repart_all = reclassify;
result = partition_set_config(cnfg);
} else {
result = FAILURE;
Expand Down
4 changes: 2 additions & 2 deletions casadm/cas_lib.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright(c) 2012-2022 Intel Corporation
* Copyright(c) 2024 Huawei Technologies
* Copyright(c) 2024-2025 Huawei Technologies
* Copyright(c) 2026 Unvertical
* SPDX-License-Identifier: BSD-3-Clause
*/
Expand Down Expand Up @@ -311,7 +311,7 @@ int flush_core(unsigned int cache_id, unsigned int core_id);
int check_cache_device(const char *device_path);

int partition_list(unsigned int cache_id, unsigned int output_format);
int partition_setup(unsigned int cache_id, const char *file);
int partition_setup(unsigned int cache_id, bool reclassify, const char *file);
int partition_is_name_valid(const char *name);

int cas_module_version(char *buff, int size);
Expand Down
17 changes: 16 additions & 1 deletion casadm/cas_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1528,6 +1528,7 @@ enum {

io_class_opt_cache_id,
io_class_opt_cache_file_load,
io_class_opt_keep_classification,
io_class_opt_output_format,

io_class_opt_io_class_id,
Expand Down Expand Up @@ -1585,6 +1586,14 @@ static cli_option io_class_params_options[] = {
.priv = (1 << io_class_opt_subcmd_configure)
| (1 << io_class_opt_flag_required)
},
[io_class_opt_keep_classification] = {
.short_name = 'k',
.long_name = "keep-classification",
.desc = "Prevents reclassification of data in IO classes with IDs matching previous configuration",
.args_count = 0,
.arg = NULL,
.priv = (1 << io_class_opt_subcmd_configure)
},
[io_class_opt_output_format] = {
.short_name = 'o',
.long_name = "output-format",
Expand Down Expand Up @@ -1650,6 +1659,7 @@ struct {
int io_class_id;
int cache_mode;
int io_class_prio;
bool reclassify;
int output_format;
uint32_t min;
uint32_t max;
Expand All @@ -1659,6 +1669,7 @@ struct {
.subcmd = io_class_opt_subcmd_unknown,
.cache_id = 0,
.file = "",
.reclassify = true,
.output_format = OUTPUT_FORMAT_DEFAULT
};

Expand Down Expand Up @@ -1695,6 +1706,10 @@ int io_class_handle_option(char *opt, const char **arg)
return FAILURE;

io_class_params_options[io_class_opt_output_format].priv |= (1 << io_class_opt_flag_set);
} else if (!strcmp(opt, "keep-classification")) {
io_class_params.reclassify = false;

io_class_params_options[io_class_opt_keep_classification].priv |= (1 << io_class_opt_flag_set);
}

return 0;
Expand Down Expand Up @@ -1751,7 +1766,7 @@ int io_class_handle() {
switch (io_class_params.subcmd) {
case io_class_opt_subcmd_configure:
return partition_setup(io_class_params.cache_id,
io_class_params.file);
io_class_params.reclassify, io_class_params.file);
case io_class_opt_subcmd_list:
return partition_list(io_class_params.cache_id,
io_class_params.output_format);
Expand Down
8 changes: 8 additions & 0 deletions casadm/casadm.8
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,14 @@ Identifier of cache instance <1-16384>.
.B -f, --file <FILE>
Configuration file containing IO class definition.

.TP
.B -k, --keep-classification
Keep classification of data cached in IO classes present in the new
configuration. By default data of all the IO classes is moved to the
unclassified IO class and gets classified again on next access. Data of IO
classes removed from the configuration is reclassified regardless of this
option.

.SH Options that are valid with --io-class --list (-C -L) are:
.TP
.B -i, --cache-id <ID>
Expand Down
3 changes: 3 additions & 0 deletions modules/cas_cache/layer_cache_management.c
Original file line number Diff line number Diff line change
Expand Up @@ -1785,12 +1785,15 @@ int cache_mngt_set_partitions(const char *cache_name, size_t name_len,

for (class_id = 0; class_id < OCF_USER_IO_CLASS_MAX; class_id++) {
io_class_cfg->config[class_id].class_id = class_id;
/* Data of removed IO classes is always reclassified */
io_class_cfg->config[class_id].repart = true;

if (!cfg->info[class_id].name[0]) {
io_class_cfg->config[class_id].class_id = class_id;
continue;
}

io_class_cfg->config[class_id].repart = cfg->repart_all;
io_class_info2cfg(class_id, &cfg->info[class_id],
&io_class_cfg->config[class_id]);
}
Expand Down
3 changes: 3 additions & 0 deletions modules/include/cas_ioctl_codes.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ struct kcas_io_classes {
/** Cache ID */
uint16_t cache_id;

/** Reclassify data of all IO classes, not only of the removed ones */
bool repart_all;

int ext_err_code;

/** IO class info */
Expand Down
2 changes: 1 addition & 1 deletion ocf
Submodule ocf updated 179 files
7 changes: 5 additions & 2 deletions test/functional/api/cas/cache.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#
# Copyright(c) 2019-2021 Intel Corporation
# Copyright(c) 2024-2026 Huawei Technologies Co., Ltd.
# Copyright(c) 2026 Unvertical
# SPDX-License-Identifier: BSD-3-Clause
#

Expand Down Expand Up @@ -174,8 +175,10 @@ def reset_counters(self) -> Output:
def set_cache_mode(self, cache_mode: CacheMode, flush=None) -> Output:
return casadm.set_cache_mode(cache_mode, self.cache_id, flush)

def load_io_class(self, file_path: str) -> Output:
return casadm.load_io_classes(self.cache_id, file_path)
def load_io_class(self, file_path: str, keep_classification: bool = False) -> Output:
return casadm.load_io_classes(
self.cache_id, file_path, keep_classification=keep_classification
)

def list_io_classes(self) -> list:
return get_io_class_list(self.cache_id)
Expand Down
12 changes: 10 additions & 2 deletions test/functional/api/cas/casadm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#
# Copyright(c) 2019-2022 Intel Corporation
# Copyright(c) 2024-2026 Huawei Technologies Co., Ltd.
# Copyright(c) 2026 Unvertical
# SPDX-License-Identifier: BSD-3-Clause
#

Expand Down Expand Up @@ -589,9 +590,16 @@ def flush_core(cache_id: int, core_id: int, shortcut: bool = False) -> Output:
return output


def load_io_classes(cache_id: int, file: str, shortcut: bool = False) -> Output:
def load_io_classes(
cache_id: int, file: str, shortcut: bool = False, keep_classification: bool = False
) -> Output:
output = TestRun.executor.run(
load_io_classes_cmd(cache_id=str(cache_id), file=file, shortcut=shortcut)
load_io_classes_cmd(
cache_id=str(cache_id),
file=file,
shortcut=shortcut,
keep_classification=keep_classification,
)
)
if output.exit_code != 0:
raise CmdException("Load IO class command failed.", output)
Expand Down
6 changes: 5 additions & 1 deletion test/functional/api/cas/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,14 @@ def flush_core_cmd(cache_id: str, core_id: str, shortcut: bool = False) -> str:
return casadm_bin + command


def load_io_classes_cmd(cache_id: str, file: str, shortcut: bool = False) -> str:
def load_io_classes_cmd(
cache_id: str, file: str, shortcut: bool = False, keep_classification: bool = False
) -> str:
command = " -C -C" if shortcut else " --io-class --load-config"
command += (" -i " if shortcut else " --cache-id ") + cache_id
command += (" -f " if shortcut else " --file ") + file
if keep_classification:
command += (" -k" if shortcut else " --keep-classification")
return casadm_bin + command


Expand Down
1 change: 1 addition & 0 deletions test/functional/api/cas/cli_help_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@
r"Options that are valid with --load-config \(-C\) are:",
r"-i --cache-id \<ID\> Identifier of cache instance \<1-16384\>",
r"-f --file \<FILE\> Configuration file containing IO class definition",
r"-k --keep-classification Prevents reclassification of data in IO classes with IDs matching previous configuration",
r"Lists currently configured IO classes:",
r"Usage: casadm --io-class --list --cache-id \<ID\> \[option\.\.\.\]",
r"Options that are valid with --list \(-L\) are:",
Expand Down
2 changes: 2 additions & 0 deletions test/functional/api/cas/ioclass_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ def generate_random_ioclass_list(count: int, max_priority: int = MAX_IO_CLASS_PR
),
]
for i in range(1, count - 1):
if random.choice([True, False]):
continue
random_list.append(
IoClass(
i,
Expand Down
6 changes: 4 additions & 2 deletions test/functional/tests/io_class/io_class_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@ def get_io_class_usage(cache, io_class_id, percent=False):
).usage_stats


def generate_and_load_random_io_class_config(cache):
def generate_and_load_random_io_class_config(cache, keep_classification=False):
random_list = IoClass.generate_random_ioclass_list(ioclass_config.MAX_IO_CLASS_ID + 1)
IoClass.save_list_to_config_file(random_list, add_default_rule=False)
cache.load_io_class(ioclass_config.default_config_file_path)
cache.load_io_class(
ioclass_config.default_config_file_path, keep_classification=keep_classification
)
return random_list


Expand Down
2 changes: 1 addition & 1 deletion test/functional/tests/io_class/test_io_class_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_io_class_export_configuration():
)

with TestRun.LOGGER.step(
"Create and load configuration file for 33 IO classes "
"Create and load random configuration file for up to 33 IO classes "
"with random names, allocation and priority values"
):
random_list = IoClass.generate_random_ioclass_list(33)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_io_class_eviction_pinned_after_unpin():

with TestRun.step("Unpin ioclass to and set its priority to be lower than second IO class"):
io_classes = [IoclassConfig(1, 11, 1, cores[0]), IoclassConfig(2, 10, 1, cores[1])]
_add_and_load_io_classes(cache.cache_id, io_classes)
_add_and_load_io_classes(cache.cache_id, io_classes, keep_classification=True)

with TestRun.step("Run dd on second io ioclass "):
run_io_dir(f"{io_classes[1].core.path}", usable_cache_size)
Expand All @@ -89,7 +89,7 @@ def _refresh_cache(cache):
cache.reset_counters()


def _add_and_load_io_classes(cache_id, io_classes: list):
def _add_and_load_io_classes(cache_id, io_classes: list, keep_classification=False):
ioclass_config.remove_ioclass_config()
ioclass_config.create_ioclass_config(False)

Expand All @@ -102,7 +102,11 @@ def _add_and_load_io_classes(cache_id, io_classes: list):
ioclass_config_path=ioclass_config.default_config_file_path,
)

casadm.load_io_classes(cache_id=cache_id, file=default_config_file_path)
casadm.load_io_classes(
cache_id=cache_id,
file=default_config_file_path,
keep_classification=keep_classification,
)


def prepare(cores_number=1, cache_size=Size(10, Unit.GibiByte), core_size=Size(5, Unit.GibiByte)):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ def test_ioclass_resize(cache_line_size, new_occupancy):
f"{io_class.max_occupancy:0.2f}",
)

casadm.load_io_classes(cache_id=cache.cache_id, file=default_config_file_path)
casadm.load_io_classes(
cache_id=cache.cache_id,
file=default_config_file_path,
keep_classification=True,
)

with TestRun.step("Perform IO with size equal to cache size"):
run_io_dir(f"{io_class.dir_path}/tmp_file", cache_size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_io_class_preserve_configuration():
cache.add_core(core_device)

with TestRun.step(
"Create and load configuration file for all IO classes with random names, "
"Create and load random configuration file with random names, "
"allocation and priority values."
):
generated_io_classes = generate_and_load_random_io_class_config(cache)
Expand Down
Loading
Loading