diff --git a/casadm/Makefile b/casadm/Makefile index 558aab7..4dbe255 100644 --- a/casadm/Makefile +++ b/casadm/Makefile @@ -56,7 +56,6 @@ OBJS += statistics_view.o OBJS += statistics_view_raw_csv.o OBJS += csvparse.o OBJS += extended_err_msg.o -OBJS += upgrade.o OBJS += safeclib/memmove_s.o OBJS += safeclib/memcpy_s.o OBJS += safeclib/memset_s.o diff --git a/casadm/cas_main.c b/casadm/cas_main.c index 2808b14..0ae91c8 100644 --- a/casadm/cas_main.c +++ b/casadm/cas_main.c @@ -21,7 +21,6 @@ #include "cas_lib_utils.h" #include "safeclib/safe_str_lib.h" #include -#include "upgrade.h" #include "statistics_view.h" #define HELP_HEADER OCF_PREFIX_LONG @@ -1447,8 +1446,7 @@ enum { script_cmd_min_id = 0, - script_cmd_upgrade = script_cmd_min_id, - script_cmd_check_cache_device, + script_cmd_check_cache_device = script_cmd_min_id, script_cmd_add_core, script_cmd_remove_core, @@ -1478,14 +1476,6 @@ enum { * script_opt_* .priv fields contains id of commands, where they can be used */ static cli_option script_params_options[] = { - [script_cmd_upgrade] = { - .short_name = 0, - .long_name = "upgrade-in-flight", - .args_count = 0, - .arg = NULL, - .priv = 0, - .flags = CLI_COMMAND_HIDDEN, - }, [script_cmd_check_cache_device] = { .short_name = 0, .long_name = "check-cache-device", @@ -1696,8 +1686,6 @@ int script_handle() { switch (command_args_values.script_subcmd) { case script_cmd_check_cache_device: return check_cache_device(command_args_values.cache_device); - case script_cmd_upgrade: - return upgrade_start(); case script_cmd_add_core: return add_core( command_args_values.cache_id, diff --git a/casadm/extended_err_msg.c b/casadm/extended_err_msg.c index 96a6c5d..8881403 100644 --- a/casadm/extended_err_msg.c +++ b/casadm/extended_err_msg.c @@ -197,10 +197,6 @@ struct { "Could not create exported object because file in /dev " "directory exists" }, - { - KCAS_ERR_IN_UPGRADE, - "Operation not allowed. CAS is in upgrade state" - }, { KCAS_ERR_UNALIGNED, "Cache device logical sector size is greater than core device " @@ -208,9 +204,6 @@ struct { "on current cache device \nor try other device with the same " "logical sector size as core device." }, - { - KCAS_ERR_NO_STORED_CONF, - "Internal kernel module error" }, { KCAS_ERR_ROLLBACK, "Cannot restore previous configuration" diff --git a/casadm/upgrade.c b/casadm/upgrade.c deleted file mode 100644 index 48f8c62..0000000 --- a/casadm/upgrade.c +++ /dev/null @@ -1,40 +0,0 @@ -/* -* Copyright(c) 2012-2021 Intel Corporation -* SPDX-License-Identifier: BSD-3-Clause-Clear -*/ -#include -#include -#include -#include -#include -#include -#include "cas_lib.h" -#include "cas_lib_utils.h" -#include - -extern cas_printf_t cas_printf; - -int upgrade_start() -{ - int fd; - struct kcas_upgrade cmd_info; - - if ((fd = open_ctrl_device()) == -1) { - return -1; - } - - if (run_ioctl_interruptible_retry(fd, KCAS_IOCTL_UPGRADE, &cmd_info, - "Starting upgrade", 0, OCF_CORE_ID_INVALID) < 0) { - close(fd); - if (OCF_ERR_FLUSHING_INTERRUPTED == cmd_info.ext_err_code) { - return INTERRUPTED; - } else { - cas_printf(LOG_ERR, "Error starting upgrade\n"); - print_err(cmd_info.ext_err_code); - return FAILURE; - } - } - - close(fd); - return SUCCESS; -} diff --git a/casadm/upgrade.h b/casadm/upgrade.h deleted file mode 100644 index ecff3ea..0000000 --- a/casadm/upgrade.h +++ /dev/null @@ -1,11 +0,0 @@ -/* -* Copyright(c) 2012-2021 Intel Corporation -* SPDX-License-Identifier: BSD-3-Clause-Clear -*/ - -#ifndef _UPGRADE_H -#define _UPGRADE_H - -int upgrade_start(); - -#endif diff --git a/modules/cas_cache/cas_cache.h b/modules/cas_cache/cas_cache.h index 94f2d3b..e05a320 100644 --- a/modules/cas_cache/cas_cache.h +++ b/modules/cas_cache/cas_cache.h @@ -12,7 +12,6 @@ #include #include "linux_kernel_version.h" -#include "layer_upgrade.h" #include "control.h" #include "layer_cache_management.h" #include "service_ui_ioctl.h" @@ -21,6 +20,7 @@ #include "classifier.h" #include "context.h" #include +#include "../cas_disk/cas_disk.h" #define CAS_KERN_EMERG KERN_EMERG OCF_PREFIX_SHORT #define CAS_KERN_ALERT KERN_ALERT OCF_PREFIX_SHORT @@ -76,7 +76,6 @@ struct casdsk_functions_mapper { struct module *owner, struct casdsk_exp_obj_ops *ops); void(*casdsk_exp_obj_free)(struct casdsk_disk *dsk); struct request_queue *(*casdsk_disk_get_queue)(struct casdsk_disk *dsk); - void (*casdsk_store_config)(size_t n_blobs, struct casdsk_props_conf *blobs); struct block_device *(*casdsk_disk_get_blkdev)(struct casdsk_disk *dsk); struct request_queue *(*casdsk_exp_obj_get_queue)(struct casdsk_disk *dsk); uint32_t (*casdsk_get_version)(void); @@ -84,7 +83,6 @@ struct casdsk_functions_mapper { struct casdsk_disk *(*casdsk_disk_claim)(const char *path, void *private); int (*casdsk_exp_obj_unlock)(struct casdsk_disk *dsk); int (*casdsk_disk_set_pt)(struct casdsk_disk *dsk); - size_t (*casdsk_get_stored_config)(struct casdsk_props_conf **blobs); struct gendisk *(*casdsk_disk_get_gendisk)(struct casdsk_disk *dsk); int (*casdsk_disk_attach) (struct casdsk_disk *dsk, struct module *owner, struct casdsk_exp_obj_ops *ops); @@ -92,7 +90,6 @@ struct casdsk_functions_mapper { int (*casdsk_exp_obj_activate)(struct casdsk_disk *dsk); bool (*casdsk_exp_obj_activated)(struct casdsk_disk *ds); int (*casdsk_exp_obj_lock)(struct casdsk_disk *dsk); - void (*casdsk_free_stored_config)(void); struct casdsk_disk *(*casdsk_disk_open)(const char *path, void *private); int (*casdsk_disk_clear_pt)(struct casdsk_disk *dsk); struct gendisk *(*casdsk_exp_obj_get_gendisk)(struct casdsk_disk *dsk); diff --git a/modules/cas_cache/layer_cache_management.c b/modules/cas_cache/layer_cache_management.c index 224a646..dc1b976 100644 --- a/modules/cas_cache/layer_cache_management.c +++ b/modules/cas_cache/layer_cache_management.c @@ -1191,11 +1191,6 @@ int cache_mngt_prepare_core_cfg(struct ocf_mngt_core_config *cfg, cfg->uuid.size = strnlen(cmd_info->core_path_name, MAX_STR_LEN) + 1; cfg->try_add = cmd_info->try_add; - if (cas_upgrade_is_in_upgrade()) { - cfg->volume_type = BLOCK_DEVICE_VOLUME; - return 0; - } - if (!cas_bdev_exist(cfg->uuid.data)) return -OCF_ERR_INVAL_VOLUME_TYPE; @@ -2512,20 +2507,12 @@ int cache_mngt_exit_instance(const char *cache_name, size_t name_len, int flush) goto unlock; } - if (!cas_upgrade_is_in_upgrade()) { - /* If we are not in upgrade - destroy cache devices */ - status = block_dev_destroy_all_exported_objects(cache); - if (status != 0) { - printk(KERN_WARNING - "Failed to remove all cached devices\n"); - goto stop_thread; - } - } else { - /* - * We are being switched to upgrade in flight mode - - * wait for finishing pending core requests - */ - cache_mngt_wait_for_rq_finish(cache); + /* Destroy cache devices */ + status = block_dev_destroy_all_exported_objects(cache); + if (status != 0) { + printk(KERN_WARNING + "Failed to remove all cached devices\n"); + goto stop_thread; } /* Flush cache again. This time we don't allow interruption. */ diff --git a/modules/cas_cache/layer_upgrade.c b/modules/cas_cache/layer_upgrade.c deleted file mode 100644 index 7500e3a..0000000 --- a/modules/cas_cache/layer_upgrade.c +++ /dev/null @@ -1,1660 +0,0 @@ -/* -* Copyright(c) 2012-2021 Intel Corporation -* SPDX-License-Identifier: BSD-3-Clause-Clear -*/ - -#include "cas_cache.h" - -#define CAS_UPGRADE_DEBUG 0 - -#if 1 == CAS_UPGRADE_DEBUG -#define CAS_DEBUG_TRACE() \ - printk(KERN_INFO "[Upgrade] %s\n", __func__) - -#define CAS_DEBUG_MSG(msg) \ - printk(KERN_INFO "[Upgrade] %s - %s\n", __func__, msg) - -#define CAS_DEBUG_PARAM(format, ...) \ - printk(KERN_INFO "[Upgrade] %s - "format"\n", \ - __func__, ##__VA_ARGS__) -#else -#define CAS_DEBUG_TRACE() -#define CAS_DEBUG_MSG(msg) -#define CAS_DEBUG_PARAM(format, ...) -#endif - -extern u32 max_writeback_queue_size; -extern u32 writeback_queue_unblock_size; -extern u32 metadata_layout; -extern u32 unaligned_io; -extern u32 seq_cut_off_mb; -extern u32 use_io_scheduler; - -typedef int (*restore_callback_t) (struct cas_properties *cache_props); - -static void _cas_upgrade_clear_state(void) -{ - in_upgrade = false; -} - -static void _cas_upgrade_set_state(void) -{ - in_upgrade = true; -} - -bool cas_upgrade_is_in_upgrade(void) -{ - return in_upgrade; -} - -/* - * Caches parameters to serialize - * +------------+-------------------------------+---------------+ - * |Group | Key | Type | - * |------------|-------------------------------|---------------| - * |cache | cache_name | string | - * |cache | cache_path | string | - * |cache | cache_type | uint | - * |cache | cache_line_size | uint | - * |cache | cache_evp_policy | uint | - * |cache | cache_mode | uint | - * |cache | cache_seq_cutoff_thresh | uint | - * |cache | cache_seq_cutoff_policy | uint | - * |------------|-------------------------------|---------------| - * |core | core_no | uint | - * |core | core_X_name | string | - * |core | core_X_path | string | - * |core | core_X_type | uint | - * |------------|-------------------------------|---------------| - * |promotion | promotion_policy | uint | - * |promotion | nhit_insertion_threshold| uint | - * |promotion | nhit_insertion_trigger | uint | - * |------------|-------------------------------|---------------| - * |flush | flush_cleaning_policy | uint | - * |flush | flush_wake_up_time | uint | - * |flush | flush_staleness_time | uint | - * |flush | flush_max_buffers | uint | - * |flush | flush_threshold | uint | - * |flush | flush_acp_wake_up_time | uint | - * |flush | flush_acp_max_buffers | uint | - * |------------|-------------------------------|---------------| - * |io_class | io_class_no | uint | - * |io_class | io_class_X_name | string | - * |io_class | io_class_X_id | uint | - * |io_class | io_class_X_max | uint | - * |io_class | io_class_X_min | uint | - * |io_class | io_class_X_cache_mode | uint | - * |io_class | io_class_X_prio | uint | - * +------------+-------------------------------+---------------+ - * - */ - -#define UPGRADE_IFACE_VERSION_STR "upgrade_iface_version" - -#define CACHE_NAME_STR "cache_name" -#define CACHE_PATH_STR "cache_path" -#define CACHE_LINE_SIZE_STR "cache_line_size" -#define CACHE_TYPE_STR "cache_type" -#define CACHE_MODE_STR "cache_mode" - -#define CORE_NO_STR "core_no" -#define CORE_NAME_STR "core_%lu_name" -#define CORE_PATH_STR "core_%lu_path" -#define CORE_SEQ_CUTOFF_THRESHOLD_STR "core_%lu_seq_cutoff_thresh" -#define CORE_SEQ_CUTOFF_POLICY_STR "core_%lu_seq_cutoff_policy" - -#define PROMOTION_POLICY_STR "promotion_policy" -#define PROMOTION_NHIT_INSERTION_STR "nhit_insertion_threshold" -#define PROMOTION_NHIT_TRIGGER_STR "nhit_trigger_threshold" - -#define CLEANING_POLICY_STR "flush_cleaning_policy" -#define CLEANING_ALRU_WAKEUP_TIME_STR "flush_wakeup_time" -#define CLEANING_ALRU_STALENESS_TIME_STR "flush_staleness_time" -#define CLEANING_ALRU_MAX_BUFFERS_STR "flush_max_buffers" -#define CLEANING_ALRU_TRESHOLD_STR "flush_threshold" -#define CLEANING_ACP_WAKEUP_TIME_STR "flush_acp_wakeup_time" -#define CLEANING_ACP_MAX_BUFFERS_STR "flush_acp_max_buffers" - -#define IO_CLASS_NO_STR "io_class_no" -#define IO_CLASS_NAME_STR "io_class_%lu_name" -#define IO_CLASS_MIN_STR "io_class_%lu_min" -#define IO_CLASS_ID_STR "io_class_%lu_id" -#define IO_CLASS_MAX_STR "io_class_%lu_max" -#define IO_CLASS_PRIO_STR "io_class_%lu_prio" -#define IO_CLASS_CACHE_MODE_STR "io_class_%lu_cache_mode" - -#define CAS_UPGRADE_IFACE_VERSION_19_03_00 190300 -#define CAS_UPGRADE_IFACE_VERSION_19_09_00 190900 -#define CAS_UPGRADE_IFACE_CURRENT_VERSION CAS_UPGRADE_IFACE_VERSION_19_09_00 - -static int _cas_upgrade_dump_cache_conf_main(ocf_cache_t cache, - struct cas_properties *cache_props) -{ - int result = 0; - - CAS_DEBUG_TRACE(); - - result = cas_properties_add_uint(cache_props, UPGRADE_IFACE_VERSION_STR, - (uint64_t) CAS_UPGRADE_IFACE_CURRENT_VERSION, - CAS_PROPERTIES_CONST); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Error during adding interface version\n"); - return result; - } - - result = cas_properties_add_string(cache_props, CACHE_NAME_STR, - ocf_cache_get_name(cache), - CAS_PROPERTIES_CONST); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Error during adding cache_name\n"); - return result; - } - - result = cas_properties_add_string(cache_props, CACHE_PATH_STR, - ocf_cache_get_uuid(cache)->data, - CAS_PROPERTIES_CONST); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Error during adding cache_path\n"); - return result; - } - - result = cas_properties_add_uint(cache_props, CACHE_LINE_SIZE_STR, - (uint64_t) ocf_cache_get_line_size(cache), - CAS_PROPERTIES_CONST); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Error during adding cache_line_size\n"); - return result; - } - - result = cas_properties_add_uint(cache_props, CACHE_TYPE_STR, - (uint64_t) ocf_cache_get_type_id(cache), - CAS_PROPERTIES_CONST); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT OCF_PREFIX_SHORT - "Error during adding cache_type\n"); - return result; - } - - result = cas_properties_add_uint(cache_props, CACHE_MODE_STR, - (uint64_t) ocf_cache_get_mode(cache), - CAS_PROPERTIES_CONST); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT OCF_PREFIX_SHORT - "Error during adding cache_mode\n"); - return result; - } - - return result; -} - -struct _ocf_core_visitor_ctx { - struct cas_properties *cache_props; - int i; - int error; -}; - -int _cas_upgrade_core_visitor(ocf_core_t core, void *cntx) -{ - int result = 0; - char *value = NULL; - struct _ocf_core_visitor_ctx *core_visitor_ctx = - (struct _ocf_core_visitor_ctx*) cntx; - struct cas_properties *cache_props = core_visitor_ctx->cache_props; - unsigned long core_no = 0; - - core_visitor_ctx->i++; - core_no = core_visitor_ctx->i; - - value = kmalloc(sizeof(*value) * MAX_STR_LEN, GFP_KERNEL); - if (value == NULL) { - result = -OCF_ERR_NO_MEM; - return result; - } - - result = snprintf(value, MAX_STR_LEN, CORE_NAME_STR, core_no); - if (result < 0) - goto err; - - result = cas_properties_add_string(cache_props, value, - ocf_core_get_name(core), CAS_PROPERTIES_CONST); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT OCF_PREFIX_SHORT - "Error during adding core id\n"); - goto err; - } - - result = snprintf(value, MAX_STR_LEN, CORE_PATH_STR, - core_no); - if (result < 0) - goto err; - - result = cas_properties_add_string(cache_props, value, - ocf_core_get_uuid(core)->data, CAS_PROPERTIES_CONST); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT OCF_PREFIX_SHORT - "Error during adding core path\n"); - goto err; - } - - result = snprintf(value, MAX_STR_LEN, CORE_SEQ_CUTOFF_POLICY_STR, core_no); - if (result < 0) - goto err; - - result = cas_properties_add_uint(cache_props, value, - (uint64_t) ocf_core_get_seq_cutoff_policy(core), - CAS_PROPERTIES_CONST); - if (result) { - printk(KERN_ERR "Error during adding core seq cutoff policy\n"); - goto err; - } - - result = snprintf(value, MAX_STR_LEN, CORE_SEQ_CUTOFF_THRESHOLD_STR, core_no); - if (result < 0) - goto err; - - result = cas_properties_add_uint(cache_props, value, - (uint64_t) ocf_core_get_seq_cutoff_threshold(core), - CAS_PROPERTIES_CONST); - if (result) { - printk(KERN_ERR "Error during adding core seq cutoff threshold\n"); - goto err; - } - -err: - kfree(value); - core_visitor_ctx->error = result; - return result; -} - -static int _cas_upgrade_dump_cache_conf_cores(ocf_cache_t device, - struct cas_properties *cache_props) -{ - int result = 0; - struct _ocf_core_visitor_ctx core_visitor_ctx; - char *value = NULL; - - CAS_DEBUG_TRACE(); - - value = kmalloc(sizeof(*value) * MAX_STR_LEN, GFP_KERNEL); - if (value == NULL) { - result = -OCF_ERR_NO_MEM; - return result; - } - - result = cas_properties_add_uint(cache_props, CORE_NO_STR, - (uint64_t) ocf_cache_get_core_count(device), - CAS_PROPERTIES_NON_CONST); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT OCF_PREFIX_SHORT - "Error during adding cores number\n"); - goto err; - } - - memset(&core_visitor_ctx, 0, sizeof(core_visitor_ctx)); - core_visitor_ctx.cache_props = cache_props; - - result |= ocf_core_visit(device, _cas_upgrade_core_visitor, - &core_visitor_ctx, true); - if (core_visitor_ctx.error) { - result = core_visitor_ctx.error; - goto err; - } - - if (core_visitor_ctx.i > ocf_cache_get_core_count(device)) { - result = -OCF_ERR_INVAL; - goto err; - } - -err: - kfree(value); - return result; -} - -static int _cas_upgrade_dump_cache_conf_promotion(ocf_cache_t cache, - struct cas_properties *cache_props) -{ - uint32_t promotion_type = ocf_promotion_default; - uint32_t nhit_insertion_threshold; - uint32_t nhit_trigger_threshold; - - int result = 0; - - result = cache_mngt_get_promotion_policy(cache, &promotion_type); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Unable to get promotion policy type\n"); - return result; - } - - if (promotion_type == ocf_promotion_nhit) { - result |= cache_mngt_get_promotion_param(cache, - ocf_promotion_nhit, ocf_nhit_insertion_threshold, - &nhit_insertion_threshold); - result |= cache_mngt_get_promotion_param(cache, - ocf_promotion_nhit, ocf_nhit_trigger_threshold, - &nhit_trigger_threshold); - } - - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Unable to get promotion policy params\n"); - return result; - } - - result = cas_properties_add_uint(cache_props, PROMOTION_POLICY_STR, - promotion_type, CAS_PROPERTIES_CONST); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Error during adding promotion policy type\n"); - return result; - } - - if (promotion_type == ocf_promotion_nhit) { - result = cas_properties_add_uint(cache_props, - PROMOTION_NHIT_INSERTION_STR, - nhit_insertion_threshold, - CAS_PROPERTIES_CONST); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Error during adding nhit insertion " - "threshold\n"); - return result; - } - - result = cas_properties_add_uint(cache_props, - PROMOTION_NHIT_TRIGGER_STR, - nhit_trigger_threshold, - CAS_PROPERTIES_CONST); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Error during adding nhit trigger " - "threshold\n"); - return result; - } - } - - return result; -} - -static int _cas_upgrade_dump_cache_conf_flush(ocf_cache_t cache, - struct cas_properties *cache_props) -{ - uint32_t cleaning_type; - uint32_t alru_thread_wakeup_time; - uint32_t alru_stale_buffer_time; - uint32_t alru_flush_max_buffers; - uint32_t alru_activity_threshold; - uint32_t acp_thread_wakeup_time; - uint32_t acp_flush_max_buffers; - - int result = 0; - - CAS_DEBUG_TRACE(); - - result |= cache_mngt_get_cleaning_policy(cache, &cleaning_type); - result |= cache_mngt_get_cleaning_param(cache, ocf_cleaning_alru, - ocf_alru_wake_up_time, &alru_thread_wakeup_time); - result |= cache_mngt_get_cleaning_param(cache, ocf_cleaning_alru, - ocf_alru_stale_buffer_time, &alru_stale_buffer_time); - result |= cache_mngt_get_cleaning_param(cache, ocf_cleaning_alru, - ocf_alru_flush_max_buffers, &alru_flush_max_buffers); - result |= cache_mngt_get_cleaning_param(cache, ocf_cleaning_alru, - ocf_alru_activity_threshold, &alru_activity_threshold); - result |= cache_mngt_get_cleaning_param(cache, ocf_cleaning_acp, - ocf_acp_wake_up_time, &acp_thread_wakeup_time); - result |= cache_mngt_get_cleaning_param(cache, ocf_cleaning_acp, - ocf_acp_flush_max_buffers, &acp_flush_max_buffers); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Unable to get cleaning policy params\n"); - return result; - } - - result = cas_properties_add_uint(cache_props, CLEANING_POLICY_STR, - cleaning_type, CAS_PROPERTIES_CONST); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Error during adding cleaning policy type\n"); - return result; - } - - result = cas_properties_add_uint(cache_props, - CLEANING_ALRU_WAKEUP_TIME_STR, - alru_thread_wakeup_time, CAS_PROPERTIES_CONST); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Error during adding alru wakeup time\n"); - return result; - } - - result = cas_properties_add_uint(cache_props, - CLEANING_ALRU_STALENESS_TIME_STR, - alru_stale_buffer_time, CAS_PROPERTIES_CONST); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Error during adding alru staleness time\n"); - return result; - } - - result = cas_properties_add_uint(cache_props, - CLEANING_ALRU_MAX_BUFFERS_STR, - alru_flush_max_buffers, CAS_PROPERTIES_CONST); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Error during adding alru max flush buffers\n"); - return result; - } - - result = cas_properties_add_uint(cache_props, - CLEANING_ALRU_TRESHOLD_STR, - alru_activity_threshold, CAS_PROPERTIES_CONST); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Error during adding alru flush threshold\n"); - return result; - } - - result = cas_properties_add_uint(cache_props, - CLEANING_ACP_WAKEUP_TIME_STR, - acp_thread_wakeup_time, CAS_PROPERTIES_CONST); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Error during adding acp wakeup time\n"); - return result; - } - - result = cas_properties_add_uint(cache_props, - CLEANING_ACP_MAX_BUFFERS_STR, - acp_flush_max_buffers, CAS_PROPERTIES_CONST); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Error during adding acp max flush buffers\n"); - return result; - } - - return result; -} - -struct _cas_upgrade_dump_io_class_visit_ctx { - struct cas_properties *cache_props; - uint32_t io_class_counter; - int error; -}; - -int _cas_upgrade_dump_io_class_visitor(ocf_cache_t cache, - uint32_t io_class_id, void *ctx) -{ - int result = 0; - struct ocf_io_class_info *info = NULL; - struct _cas_upgrade_dump_io_class_visit_ctx *io_class_visit_ctx = - (struct _cas_upgrade_dump_io_class_visit_ctx*) ctx; - char *key = NULL; - struct cas_properties *cache_props = io_class_visit_ctx->cache_props; - unsigned long io_class_counter; - - CAS_DEBUG_TRACE(); - - key = kmalloc(sizeof(*key) * 4096, GFP_KERNEL); - if (key == NULL) { - result = -OCF_ERR_NO_MEM; - return result; - } - - info = kmalloc(sizeof(*info), GFP_KERNEL); - if (info == NULL) { - result = -OCF_ERR_NO_MEM; - goto error; - } - - result = ocf_cache_io_class_get_info(cache, io_class_id, info); - if (result) - goto error; - - io_class_visit_ctx->io_class_counter++; - io_class_counter = io_class_visit_ctx->io_class_counter; - - result = snprintf(key, MAX_STR_LEN, - IO_CLASS_NAME_STR, io_class_counter); - if (result < 0) - goto error; - - result = cas_properties_add_string(cache_props, key, - info->name, CAS_PROPERTIES_CONST); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Error during adding io class name\n"); - goto error; - } - - result = snprintf(key, MAX_STR_LEN, - IO_CLASS_MIN_STR, io_class_counter); - if (result < 0) - goto error; - - result = cas_properties_add_uint(cache_props, key, - info->min_size, CAS_PROPERTIES_CONST); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Error during adding io class min size\n"); - goto error; - } - - result = snprintf(key, MAX_STR_LEN, - IO_CLASS_ID_STR, io_class_counter); - if (result < 0) - goto error; - - result = cas_properties_add_uint(cache_props, key, - io_class_id, CAS_PROPERTIES_CONST); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Error during adding io class id\n"); - goto error; - } - - result = snprintf(key, MAX_STR_LEN, - IO_CLASS_MAX_STR, io_class_counter); - if (result < 0) - goto error; - - result = cas_properties_add_uint(cache_props, key, - info->max_size, CAS_PROPERTIES_CONST); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Error during adding io class max size\n"); - goto error; - } - - result = snprintf(key, MAX_STR_LEN, - IO_CLASS_PRIO_STR, io_class_counter); - if (result < 0) - goto error; - - result = cas_properties_add_uint(cache_props, key, - info->priority, CAS_PROPERTIES_CONST); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Error during adding io class priority\n"); - goto error; - } - - result = snprintf(key, MAX_STR_LEN, - IO_CLASS_CACHE_MODE_STR, io_class_counter); - if (result < 0) - goto error; - - result = cas_properties_add_uint(cache_props, key, - info->cache_mode, CAS_PROPERTIES_CONST); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Error during adding io class cache mode\n"); - goto error; - } - -error: - kfree(key); - kfree(info); - io_class_visit_ctx->error = result; - return result; - -} - -static int _cas_upgrade_dump_cache_conf_io_class(ocf_cache_t cache, - struct cas_properties *cache_props) -{ - int result = 0; - struct _cas_upgrade_dump_io_class_visit_ctx io_class_visit_ctx; - - CAS_DEBUG_TRACE(); - - result = cas_properties_add_uint(cache_props, IO_CLASS_NO_STR, 0, - CAS_PROPERTIES_NON_CONST); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Error during adding io class number\n"); - goto error_after_alloc_buffer; - } - - memset(&io_class_visit_ctx, 0, sizeof(io_class_visit_ctx)); - io_class_visit_ctx.cache_props = cache_props; - - ocf_io_class_visit(cache, _cas_upgrade_dump_io_class_visitor, - &io_class_visit_ctx); - if (io_class_visit_ctx.error) { - result = io_class_visit_ctx.error; - goto error_after_alloc_buffer; - } - - result = cas_properties_add_uint(cache_props, IO_CLASS_NO_STR, - io_class_visit_ctx.io_class_counter, - CAS_PROPERTIES_CONST); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Error during adding io class number\n"); - goto error_after_alloc_buffer; - } - -error_after_alloc_buffer: - - return result; -} - -static int _cas_upgrade_dump_cache_conf(ocf_cache_t device, - struct cas_properties *cache_props) -{ - int result = 0; - - CAS_DEBUG_TRACE(); - - result = _cas_upgrade_dump_cache_conf_main(device, cache_props); - if (result) - return result; - - result = _cas_upgrade_dump_cache_conf_cores(device, cache_props); - if (result) - return result; - - result = _cas_upgrade_dump_cache_conf_flush(device, cache_props); - if (result) - return result; - - result = _cas_upgrade_dump_cache_conf_promotion(device, cache_props); - if (result) - return result; - - result = _cas_upgrade_dump_cache_conf_io_class(device, cache_props); - if (result) - return result; - - return result; -} - -static void _cas_upgrade_destroy_props_array( - struct cas_properties **caches_props_array, int count) -{ - int i; - - CAS_DEBUG_TRACE(); - - for (i = 0; i < count ; i++) { - if (caches_props_array[i] && !IS_ERR(caches_props_array[i])) - cas_properties_destroy(caches_props_array[i]); - caches_props_array[i] = NULL; - } - -} - -static int _cas_upgrade_init_props_array( - struct cas_properties **caches_props_array, int count) -{ - int i, result = 0; - - CAS_DEBUG_TRACE(); - - for (i = 0; i < count ; i++) { - caches_props_array[i] = cas_properties_create(); - if (IS_ERR(caches_props_array[i])) { - result = PTR_ERR(caches_props_array[i]); - break; - } - } - - if (result) - _cas_upgrade_destroy_props_array(caches_props_array, i); - - return result; -} - -struct _cas_cache_dump_conf_visitor_ctx { - struct cas_properties **caches_props_array; - struct casdsk_props_conf *caches_serialized_conf; - int i; - int error; - -}; - -int _cas_upgrade_dump_cache_conf_visitor(ocf_cache_t cache, void *cntx) -{ - int result = 0; - - struct _cas_cache_dump_conf_visitor_ctx *cache_visit_ctx = - (struct _cas_cache_dump_conf_visitor_ctx*) cntx; - struct cas_properties **caches_props_array = - cache_visit_ctx->caches_props_array; - struct casdsk_props_conf *caches_serialized_conf = - cache_visit_ctx->caches_serialized_conf; - - result = _cas_upgrade_dump_cache_conf(cache, - caches_props_array[cache_visit_ctx->i]); - if (result) - goto error; - - result = cas_properties_serialize( - caches_props_array[cache_visit_ctx->i], - &caches_serialized_conf[cache_visit_ctx->i]); - -error: - cache_visit_ctx->i++; - cache_visit_ctx->error = result; - return result; -} - -static int _cas_upgrade_dump_conf(void) -{ - int result = 0, i = 0; - size_t caches_no = 0; - struct casdsk_props_conf *caches_serialized_conf = NULL; - struct _cas_cache_dump_conf_visitor_ctx cache_visit_ctx; - struct cas_properties **caches_props_array; - - CAS_DEBUG_TRACE(); - - caches_no = ocf_mngt_cache_get_count(cas_ctx); - if (caches_no == 0) - return 0; - - caches_props_array = kcalloc(caches_no, - sizeof(*caches_props_array), GFP_KERNEL); - if (caches_props_array == NULL) { - result = -OCF_ERR_NO_MEM; - return result; - } - - caches_serialized_conf = kcalloc(caches_no, - sizeof(*caches_serialized_conf), GFP_KERNEL); - if (caches_serialized_conf == NULL) { - kfree(caches_props_array); - result = -OCF_ERR_NO_MEM; - return result; - } - - result = _cas_upgrade_init_props_array(caches_props_array, caches_no); - if (result) { - kfree(caches_props_array); - kfree(caches_serialized_conf); - return result; - } - - /* Set up visitor context */ - memset(&cache_visit_ctx, 0, sizeof(cache_visit_ctx)); - cache_visit_ctx.caches_props_array = caches_props_array; - cache_visit_ctx.caches_serialized_conf = caches_serialized_conf; - - result = ocf_mngt_cache_visit(cas_ctx, _cas_upgrade_dump_cache_conf_visitor, - &cache_visit_ctx); - if (result || cache_visit_ctx.error) { - result |= cache_visit_ctx.error; - goto err_after_init_props_array; - } - - CAS_DEBUG_MSG("End of dump"); - - casdisk_functions.casdsk_store_config(caches_no, caches_serialized_conf); - - CAS_DEBUG_MSG("Configuration stored to idisk"); - -err_after_init_props_array: - if (result) { - CAS_DEBUG_MSG("End of dump: ERROR"); - for (; i >= 0; i--) - kfree(caches_serialized_conf[i].buffer); - - kfree(caches_serialized_conf); - caches_no = 0; - } - _cas_upgrade_destroy_props_array(caches_props_array, caches_no); - kfree(caches_props_array); - return result; -} - -int cas_upgrade_set_pt_and_flush_visitor_core(ocf_core_t core, void *cntx) -{ - int *result = (int*) cntx; - ocf_volume_t vol; - - vol = ocf_core_get_volume(core); - *result = casdisk_functions.casdsk_disk_set_pt(bd_object(vol)->dsk); - - return *result; -} - -int _cas_upgrade_set_pt_and_flush_visitor_cache(ocf_cache_t cache, void *cntx) -{ - int *result = (int*) cntx; - const char *cache_name = ocf_cache_get_name(cache); - - *result = cache_mngt_set_cache_mode(cache_name, - OCF_CACHE_NAME_SIZE, ocf_cache_mode_pt, false); - if (*result) - return *result; - - *result = cache_mngt_flush_device(cache_name, OCF_CACHE_NAME_SIZE); - if (*result) - return *result; - - ocf_core_visit(cache, cas_upgrade_set_pt_and_flush_visitor_core, - result, true); - - return *result; -} - -static int _cas_upgrade_set_pt_and_flush(void) -{ - int result = 0, r = 0; - - CAS_DEBUG_TRACE(); - - r = ocf_mngt_cache_visit_reverse(cas_ctx, - _cas_upgrade_set_pt_and_flush_visitor_cache, &result); - result |= r; - - return result; -} - -int _cas_upgrade_stop_devices_visitor_wait(ocf_cache_t cache, void *cntx) -{ - cache_mngt_wait_for_rq_finish(cache); - - return 0; -} - -int _cas_upgrade_stop_devices_visitor_exit(ocf_cache_t cache, void *cntx) -{ - int *result = (int*) cntx; - - *result = cache_mngt_exit_instance(ocf_cache_get_name(cache), - OCF_CACHE_NAME_SIZE, true); - - return *result; -} - -static int _cas_upgrade_stop_devices(void) -{ - int result = 0, r = 0; - - CAS_DEBUG_TRACE(); - - r = ocf_mngt_cache_visit(cas_ctx, _cas_upgrade_stop_devices_visitor_wait, - NULL); - if (r) - return r; - - r = ocf_mngt_cache_visit_reverse(cas_ctx, - _cas_upgrade_stop_devices_visitor_exit, &result); - result |= r; - - return result; -} - -static int _cas_upgrade_restore_conf_main(struct cas_properties *cache_props, - char *cache_name) -{ - int result = 0; - uint64_t cache_mode, cache_line_size; - uint64_t cache_type, version; - char *cache_path = NULL; - struct ocf_mngt_cache_config cfg = {}; - struct ocf_mngt_cache_device_config device_cfg = {}; - struct atomic_dev_params atomic_params = {}; - - CAS_DEBUG_TRACE(); - - cache_path = kzalloc(sizeof(*cache_path) * MAX_STR_LEN, GFP_KERNEL); - if (cache_path == NULL) { - result = -OCF_ERR_NO_MEM; - return result; - } - - result = cas_properties_get_uint(cache_props, UPGRADE_IFACE_VERSION_STR, - &version); - if (result) - goto error; - - result = cas_properties_get_string(cache_props, CACHE_NAME_STR, - cache_name, OCF_CACHE_NAME_SIZE); - if (result) - goto error; - - result = cas_properties_get_string(cache_props, CACHE_PATH_STR, - cache_path, MAX_STR_LEN); - if (result) - goto error; - - result = cas_properties_get_uint(cache_props, CACHE_TYPE_STR, - &cache_type); - if (result) - goto error; - - result = cas_properties_get_uint(cache_props, CACHE_LINE_SIZE_STR, - &cache_line_size); - if (result) - goto error; - - result = cas_properties_get_uint(cache_props, CACHE_MODE_STR, - &cache_mode); - if (result) - goto error; - - if (cache_mode >= ocf_cache_mode_max) - cache_mode = ocf_cache_mode_default; - - strncpy(cfg.name, cache_name, OCF_CACHE_NAME_SIZE - 1); - cfg.cache_mode = cache_mode; - /* cfg.eviction_policy = TODO */ - cfg.cache_line_size = cache_line_size; - cfg.metadata_layout = metadata_layout; - cfg.pt_unaligned_io = !unaligned_io; - cfg.use_submit_io_fast = !use_io_scheduler; - cfg.locked = true; - cfg.metadata_volatile = false; - - cfg.backfill.max_queue_size = max_writeback_queue_size; - cfg.backfill.queue_unblock_size = writeback_queue_unblock_size; - - device_cfg.uuid.data = cache_path; - device_cfg.uuid.size = strnlen(cache_path, MAX_STR_LEN) + 1; - device_cfg.volume_type = cache_type; - device_cfg.cache_line_size = cache_line_size; - device_cfg.perform_test = true; - device_cfg.force = true; - - if (device_cfg.volume_type == ATOMIC_DEVICE_VOLUME) { - result = cas_blk_identify_type_atomic(device_cfg.uuid.data, - &device_cfg.volume_type, &atomic_params); - if (result) - goto error; - if (device_cfg.volume_type != ATOMIC_DEVICE_VOLUME) { - result = -OCF_ERR_INVAL_VOLUME_TYPE; - goto error; - } - device_cfg.volume_params = &atomic_params; - } - - result = cache_mngt_init_instance(&cfg, &device_cfg, NULL); - -error: - kfree(cache_path); - return result; -} - -static int _cas_upgrade_restore_conf_core(struct cas_properties *cache_props, - ocf_cache_t cache) -{ - int result = 0; - unsigned long i = 0; - uint64_t core_no, version; - - char *core_path = NULL; - char *key = NULL; - struct ocf_mngt_core_config cfg = {}; - - CAS_DEBUG_TRACE(); - - key = kmalloc(sizeof(*key) * MAX_STR_LEN, GFP_KERNEL); - if (key == NULL) { - result = -OCF_ERR_NO_MEM; - return result; - } - - core_path = kzalloc(sizeof(*core_path) * MAX_STR_LEN, GFP_KERNEL); - if (core_path == NULL) { - kfree(key); - result = -OCF_ERR_NO_MEM; - return result; - } - - result = cas_properties_get_uint(cache_props, UPGRADE_IFACE_VERSION_STR, - &version); - if (result) - goto error; - - result = cas_properties_get_uint(cache_props, CORE_NO_STR, &core_no); - if (result) - goto error; - - for (i = 1; i < core_no + 1; i++) { - result = snprintf(key, MAX_STR_LEN, CORE_PATH_STR, i); - if (result < 0) - goto error; - - result = cas_properties_get_string(cache_props, key, - core_path, MAX_STR_LEN); - if (result) - goto error; - - result = snprintf(key, MAX_STR_LEN, CORE_NAME_STR, i); - if (result < 0) - goto error; - - result = cas_properties_get_string(cache_props, key, - cfg.name, OCF_CORE_NAME_SIZE); - if (result) - goto error; - - cfg.try_add = 0; - cfg.volume_type = BLOCK_DEVICE_VOLUME; - cfg.uuid.data = core_path; - cfg.uuid.size = strnlen(core_path, MAX_STR_LEN) + 1; - - result = cache_mngt_add_core_to_cache(ocf_cache_get_name(cache), - OCF_CACHE_NAME_SIZE, &cfg, NULL); - if (result) - goto error; - } - -error: - kfree(key); - kfree(core_path); - return result; -} - -static int _cas_upgrade_restore_conf_flush(struct cas_properties *cache_props, - ocf_cache_t cache) -{ - uint64_t cleaning_type; - uint64_t alru_thread_wakeup_time = OCF_ALRU_DEFAULT_WAKE_UP; - uint64_t alru_stale_buffer_time = OCF_ALRU_DEFAULT_STALENESS_TIME; - uint64_t alru_flush_max_buffers = OCF_ALRU_DEFAULT_FLUSH_MAX_BUFFERS; - uint64_t alru_activity_threshold = OCF_ALRU_DEFAULT_ACTIVITY_THRESHOLD; - uint64_t acp_thread_wakeup_time = OCF_ACP_DEFAULT_WAKE_UP; - uint64_t acp_flush_max_buffers = OCF_ACP_DEFAULT_FLUSH_MAX_BUFFERS; - uint64_t version; - int result = 0; - - CAS_DEBUG_TRACE(); - - result = cas_properties_get_uint(cache_props, UPGRADE_IFACE_VERSION_STR, - &version); - if (result) - return result; - - result = cas_properties_get_uint(cache_props, - CLEANING_POLICY_STR, &cleaning_type); - if (result) - return result; - - if (cleaning_type >= ocf_cleaning_max) - cleaning_type = ocf_cleaning_default; - - /* - * CLEANING_ALRU_WAKEUP_TIME PARAM - */ - - result = cas_properties_get_uint(cache_props, - CLEANING_ALRU_WAKEUP_TIME_STR, - &alru_thread_wakeup_time); - if (result) - return result; - - /* - * CLEANING_ALRU_STALENESS_TIME PARAM - */ - - result = cas_properties_get_uint(cache_props, - CLEANING_ALRU_STALENESS_TIME_STR, - &alru_stale_buffer_time); - if (result) - return result; - - /* - * CLEANING_ALRU_MAX_BUFFERS PARAM - */ - - result = cas_properties_get_uint(cache_props, - CLEANING_ALRU_MAX_BUFFERS_STR, - &alru_flush_max_buffers); - if (result) - return result; - - /* - * CLEANING_ALRU_TRESHOLD PARAM - */ - - result = cas_properties_get_uint(cache_props, - CLEANING_ALRU_TRESHOLD_STR, - &alru_activity_threshold); - if (result) - return result; - - /* - * CLEANING_ACP_WAKEUP_TIME PARAM - */ - - result = cas_properties_get_uint(cache_props, - CLEANING_ACP_WAKEUP_TIME_STR, - &acp_thread_wakeup_time); - if (result) - return result; - - /* - * CLEANING_ACP_MAX_BUFFERS PARAM - */ - - result = cas_properties_get_uint(cache_props, - CLEANING_ACP_MAX_BUFFERS_STR, - &acp_flush_max_buffers); - if (result) - return result; - - result |= cache_mngt_set_cleaning_policy(cache, cleaning_type); - result |= cache_mngt_set_cleaning_param(cache, ocf_cleaning_alru, - ocf_alru_wake_up_time, alru_thread_wakeup_time); - result |= cache_mngt_set_cleaning_param(cache, ocf_cleaning_alru, - ocf_alru_stale_buffer_time, alru_stale_buffer_time); - result |= cache_mngt_set_cleaning_param(cache, ocf_cleaning_alru, - ocf_alru_flush_max_buffers, alru_flush_max_buffers); - result |= cache_mngt_set_cleaning_param(cache, ocf_cleaning_alru, - ocf_alru_activity_threshold, alru_activity_threshold); - result |= cache_mngt_set_cleaning_param(cache, ocf_cleaning_acp, - ocf_acp_wake_up_time, acp_thread_wakeup_time); - result |= cache_mngt_set_cleaning_param(cache, ocf_cleaning_acp, - ocf_acp_flush_max_buffers, acp_flush_max_buffers); - - return result; -} - -static int _cas_upgrade_restore_conf_promotion(struct cas_properties *cache_props, - ocf_cache_t cache) -{ - uint64_t promotion_type; - uint64_t nhit_insertion_threshold; - uint64_t nhit_trigger_threshold; - - int result = 0; - - result = cas_properties_get_uint(cache_props, PROMOTION_POLICY_STR, - &promotion_type); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT "Couldn't retrieve promotion " - "policy type \n"); - goto out; - } - - result = cache_mngt_set_promotion_policy(cache, promotion_type); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT "Couldn't set promotion policy\n"); - goto out; - } - - if (promotion_type != ocf_promotion_nhit) - goto out; - - result = cas_properties_get_uint(cache_props, - PROMOTION_NHIT_INSERTION_STR, &nhit_insertion_threshold); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT "Couldn't retrieve NHIT insertion " - "threshold parameter \n"); - goto out; - } - - result = cas_properties_get_uint(cache_props, - PROMOTION_NHIT_TRIGGER_STR, &nhit_trigger_threshold); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT "Couldn't retrieve NHIT insertion " - "trigger parameter \n"); - goto out; - } - - result = cache_mngt_set_promotion_param(cache, ocf_promotion_nhit, - ocf_nhit_insertion_threshold, nhit_insertion_threshold); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT "Couldn't set NHIT insertion " - "threshold parameter \n"); - goto out; - } - - result = cache_mngt_set_promotion_param(cache, ocf_promotion_nhit, - ocf_nhit_trigger_threshold, nhit_trigger_threshold); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT "Couldn't set NHIT trigger " - "threshold parameter \n"); - goto out; - } - -out: - return result; -} - -static int _cas_upgrade_restore_conf_io_class( - struct cas_properties *cache_props, ocf_cache_t cache) -{ - int result = 0; - unsigned long i = 0; - uint64_t io_class_no, min_size, max_size, priority, cache_mode, part_id; - char *name = NULL; - char *key = NULL; - struct kcas_io_classes *cfg; - - CAS_DEBUG_TRACE(); - - key = kzalloc(sizeof(*key) * MAX_STR_LEN, GFP_KERNEL); - if (key == NULL) { - result = -OCF_ERR_NO_MEM; - return result; - } - - name = kzalloc(sizeof(*name) * MAX_STR_LEN, GFP_KERNEL); - if (name == NULL) { - kfree(key); - result = -OCF_ERR_NO_MEM; - return result; - } - - cfg = kzalloc(KCAS_IO_CLASSES_SIZE, GFP_KERNEL); - if (cfg == NULL) { - kfree(key); - kfree(name); - result = -OCF_ERR_NO_MEM; - return result; - } - - result = cas_properties_get_uint(cache_props, IO_CLASS_NO_STR, - &io_class_no); - if (result) - goto error_after_alloc_buffers; - - for (i = 1; i < io_class_no + 1; i++) { - result = snprintf(key, MAX_STR_LEN, IO_CLASS_NAME_STR, i); - if (result < 0) - goto error_after_alloc_buffers; - - result = cas_properties_get_string(cache_props, key, name, - MAX_STR_LEN); - if (result) - goto error_after_alloc_buffers; - - result = snprintf(key, MAX_STR_LEN, IO_CLASS_ID_STR, i); - if (result < 0) - goto error_after_alloc_buffers; - - result = cas_properties_get_uint(cache_props, key, &part_id); - if (result) - goto error_after_alloc_buffers; - - result = snprintf(key, MAX_STR_LEN, IO_CLASS_MIN_STR, i); - if (result < 0) - goto error_after_alloc_buffers; - - result = cas_properties_get_uint(cache_props, key, &min_size); - if (result) - goto error_after_alloc_buffers; - - result = snprintf(key, MAX_STR_LEN, IO_CLASS_MAX_STR, i); - if (result < 0) - goto error_after_alloc_buffers; - - result = cas_properties_get_uint(cache_props, key, &max_size); - if (result) - goto error_after_alloc_buffers; - - result = snprintf(key, MAX_STR_LEN, IO_CLASS_PRIO_STR, i); - if (result < 0) - goto error_after_alloc_buffers; - - result = cas_properties_get_uint(cache_props, key, &priority); - if (result) - goto error_after_alloc_buffers; - - result = snprintf(key, MAX_STR_LEN, IO_CLASS_CACHE_MODE_STR, i); - if (result < 0) - goto error_after_alloc_buffers; - - result = cas_properties_get_uint(cache_props, key, &cache_mode); - if (result) - goto error_after_alloc_buffers; - - result = env_strncpy(cfg->info[part_id].name, OCF_IO_CLASS_NAME_MAX, - name, OCF_IO_CLASS_NAME_MAX); - if (result) - goto error_after_alloc_buffers; - - cfg->info[part_id].priority = (int16_t)priority; - cfg->info[part_id].cache_mode = (ocf_cache_mode_t)cache_mode; - cfg->info[part_id].max_size = (uint32_t)max_size; - cfg->info[part_id].min_size = (uint32_t)min_size; - } - - result = cache_mngt_set_partitions(ocf_cache_get_name(cache), - OCF_CACHE_NAME_SIZE, cfg); - -error_after_alloc_buffers: - kfree(key); - kfree(name); - kfree(cfg); - return result; -} - -static int _cas_upgrade_restore_cache(struct cas_properties *cache_props) -{ - int result = 0; - char cache_name[OCF_CACHE_NAME_SIZE]; - ocf_cache_t cache; - - CAS_DEBUG_TRACE(); - - result = _cas_upgrade_restore_conf_main(cache_props, cache_name); - if (result) - return result; - - result = ocf_mngt_cache_get_by_name(cas_ctx, cache_name, - OCF_CACHE_NAME_SIZE, &cache); - if (result) - return result; - - result = _cas_upgrade_restore_conf_core(cache_props, cache); - if (result) - goto error; - - result = _cas_upgrade_restore_conf_flush(cache_props, cache); - if (result) - goto error; - - result = _cas_upgrade_restore_conf_promotion(cache_props, cache); - if (result) - goto error; - - result = _cas_upgrade_restore_conf_io_class(cache_props, cache); - if (result) - goto error; - -error: - ocf_mngt_cache_put(cache); - return result; -} - -int _cas_upgrade_restore_cache_mode_visitor(ocf_core_t core, void *cntx) -{ - int *result = (int*) cntx; - ocf_volume_t vol; - - vol = ocf_core_get_volume(core); - *result = casdisk_functions.casdsk_disk_clear_pt(bd_object(vol)->dsk); - - return *result; -} - -static int _cas_upgrade_restore_cache_mode(struct cas_properties *cache_props) -{ - int result = 0; - uint64_t cache_mode; - char cache_name[OCF_CACHE_NAME_SIZE]; - ocf_cache_t cache; - - CAS_DEBUG_TRACE(); - - result = cas_properties_get_string(cache_props, CACHE_NAME_STR, - cache_name, OCF_CACHE_NAME_SIZE); - if (result) - return result; - - result = ocf_mngt_cache_get_by_name(cas_ctx, cache_name, - OCF_CACHE_NAME_SIZE, &cache); - if (result) - return result; - - result = cas_properties_get_uint(cache_props, CACHE_MODE_STR, - &cache_mode); - if (result) - goto error; - - if (ocf_cache_get_mode(cache) != cache_mode) { - result = cache_mngt_set_cache_mode(ocf_cache_get_name(cache), - OCF_CACHE_NAME_SIZE, cache_mode, false); - if (result) - goto error; - - result |= ocf_core_visit(cache, - _cas_upgrade_restore_cache_mode_visitor, &result, true); - } - -error: - ocf_mngt_cache_put(cache); - return result; -} - -static int _cas_upgrade_restore_cache_after_error( - struct cas_properties *cache_props) -{ - int result = 0; - char cache_name[OCF_CACHE_NAME_SIZE]; - ocf_cache_t cache = NULL; - - CAS_DEBUG_TRACE(); - - result = cas_properties_get_string(cache_props, CACHE_NAME_STR, - cache_name, OCF_CACHE_NAME_SIZE); - if (result) - return result; - - result = ocf_mngt_cache_get_by_name(cas_ctx, cache_name, - OCF_CACHE_NAME_SIZE, &cache); - if (result == -OCF_ERR_CACHE_NOT_EXIST) { - result = _cas_upgrade_restore_cache(cache_props); - } else if (result == 0) { - result = _cas_upgrade_restore_cache_mode(cache_props); - ocf_mngt_cache_put(cache); - } - - return result; -} - -static int _cas_upgrade_restore_configuration( - struct casdsk_props_conf *caches_props_serialized_array, - size_t caches_no, restore_callback_t restore_callback) -{ - int result = 0, i = 0; - struct cas_properties **caches_props_array = NULL; - - CAS_DEBUG_TRACE(); - - caches_props_array = kcalloc(caches_no, sizeof(*caches_props_array), - GFP_KERNEL); - if (!caches_props_array) { - result = -OCF_ERR_NO_MEM; - return result; - } - - for (i = 0; i < caches_no; i++) { - caches_props_array[i] = cas_properites_parse( - &caches_props_serialized_array[i]); - if (IS_ERR(caches_props_array[i])) { - result = PTR_ERR(caches_props_array[i]); - break; - } - - if (caches_props_array[i]) { -#if 1 == CAS_UPGRADE_DEBUG - cas_properties_print(caches_props_array[i]); -#endif - result = restore_callback(caches_props_array[i]); - if (result) { - cas_properties_print(caches_props_array[i]); - break; - } - } - } - - _cas_upgrade_destroy_props_array(caches_props_array, caches_no); - kfree(caches_props_array); - return result; -} - -struct casdsk_props_conf *caches_serialized_conf_init; -size_t caches_no_init; - -int cas_upgrade_get_configuration(void) -{ - int result = 0; - struct casdsk_props_conf *buffer = NULL; - - CAS_DEBUG_TRACE(); - - caches_no_init = casdisk_functions.casdsk_get_stored_config(&buffer); - if (caches_no_init == 0 || !buffer) - return -KCAS_ERR_NO_STORED_CONF; - - _cas_upgrade_set_state(); - - caches_serialized_conf_init = buffer; - - return result; -} - -int cas_upgrade_check_ctx_visitor(ocf_cache_t cache, void *cntx) -{ - int result = ocf_cache_is_incomplete(cache); - - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Upgrade error. Cannot start upgrade in flight" - " %s is in incomplete state\n", - ocf_cache_get_name(cache)); - } - - return result; -} - -static int _cas_cache_attached_check_visitor(ocf_cache_t cache, void *cntx) -{ - if (!ocf_cache_is_device_attached(cache)) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Upgrade error. Cannot start upgrade in flight" - " when cache drive is detached!\n"); - return 1; - } - - return 0; -} - -static int _cas_upgrade_check_ctx_state(void) -{ - if (ocf_mngt_core_pool_get_count(cas_ctx)) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Upgrade error. Cannot start upgrade in flight" - " when core pool list is not empty\n"); - return -KCAS_ERR_CORE_POOL_NOT_EMPTY; - } - - if (ocf_mngt_cache_visit(cas_ctx ,_cas_cache_attached_check_visitor, - NULL)) { - return -KCAS_ERR_NO_CACHE_ATTACHED; - } - - if (ocf_mngt_cache_visit(cas_ctx, cas_upgrade_check_ctx_visitor, - NULL)) { - return -OCF_ERR_CACHE_IN_INCOMPLETE_STATE; - } - - return 0; -} - -int cas_upgrade(void) -{ - int result = 0, result_rollback = 0; - restore_callback_t restore_callback = NULL; - - CAS_DEBUG_TRACE(); - - result = _cas_upgrade_check_ctx_state(); - if (result) - return result; - - _cas_upgrade_set_state(); - - result = _cas_upgrade_dump_conf(); - if (result) - goto dump_err; - - result = _cas_upgrade_set_pt_and_flush(); - if (result) { - restore_callback = _cas_upgrade_restore_cache_mode; - goto upgrade_err; - } - - result = _cas_upgrade_stop_devices(); - if (result) { - restore_callback = _cas_upgrade_restore_cache_after_error; - goto upgrade_err; - } - - return 0; - -upgrade_err: - printk(KERN_ERR OCF_PREFIX_SHORT "Upgrade error. Start rollback"); - result_rollback = cas_upgrade_get_configuration(); - if (result_rollback != -KCAS_ERR_NO_STORED_CONF) { - result_rollback = _cas_upgrade_restore_configuration( - caches_serialized_conf_init, caches_no_init, - restore_callback); - } else { - /* nothing to rool back - that's good */ - result_rollback = 0; - } - if (result_rollback) { - /* rollback error */ - /* TODO: FIXME this path loses information about original cache - mode if we managed to switch to PT - configuration stored in - inteldisk will be freed before returning from this function. - */ - result = -KCAS_ERR_ROLLBACK; - } - - casdisk_functions.casdsk_free_stored_config(); - -dump_err: - _cas_upgrade_clear_state(); - return result; -} - -int cas_upgrade_finish(void) -{ - int result = 0, rollback_result = 0; - - CAS_DEBUG_TRACE(); - - result = _cas_upgrade_restore_configuration(caches_serialized_conf_init, - caches_no_init, _cas_upgrade_restore_cache); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Error during restoring configuration\n"); - rollback_result = _cas_upgrade_set_pt_and_flush(); - if (rollback_result) - result = rollback_result; - - rollback_result = _cas_upgrade_stop_devices(); - if (rollback_result) - result = rollback_result; - } else { - /* - * Remove configuration only in case when restoring finished - * successfully - */ - casdisk_functions.casdsk_free_stored_config(); - } - - _cas_upgrade_clear_state(); - - return result; -} - -static int _cas_upgrade_restore_noop(struct cas_properties *cache_props) -{ - return 0; -} - -int cas_upgrade_verify(void) -{ - int result = 0; - - CAS_DEBUG_TRACE(); - - result = _cas_upgrade_restore_configuration(caches_serialized_conf_init, - caches_no_init, - _cas_upgrade_restore_noop); - - return result; -} diff --git a/modules/cas_cache/layer_upgrade.h b/modules/cas_cache/layer_upgrade.h deleted file mode 100644 index e77aa3c..0000000 --- a/modules/cas_cache/layer_upgrade.h +++ /dev/null @@ -1,46 +0,0 @@ -/* -* Copyright(c) 2012-2021 Intel Corporation -* SPDX-License-Identifier: BSD-3-Clause-Clear -*/ - -#ifndef __LAYER_UPGRADE_H - -#define __LAYER_UPGRADE_H - -#include "cas_cache/cas_cache.h" - -extern bool in_upgrade; - -/** - * @brief Check that CAS is in upgarde state - * @return true if is or false if isn't - */ -bool cas_upgrade_is_in_upgrade(void); - -/** - * @brief Check that caches configuration is stored at casdsk - * @return 0 if exist - */ -int cas_upgrade_get_configuration(void); - -/** - * @brief Start upgrade in flight procedure, dump configuration, - * switch caches to PT and close caches - * @return result - */ -int cas_upgrade(void); - -/** - * @brief Finish upgrade in new CAS module - restore all caches - * @return result of restoring - */ -int cas_upgrade_finish(void); - -/** - * @brief Try to parse configuration stored in casdisk - * @return result of verification - */ -int cas_upgrade_verify(void); - -#endif /* __LAYER_UPGRADE_H */ - diff --git a/modules/cas_cache/main.c b/modules/cas_cache/main.c index 527d5d1..e9e84b4 100644 --- a/modules/cas_cache/main.c +++ b/modules/cas_cache/main.c @@ -21,10 +21,6 @@ MODULE_PARM_DESC(writeback_queue_unblock_size, "Cache writeback queue size (60000) at which queue " "is unblocked when blocked"); -u32 dry_run; -module_param(dry_run, uint, (S_IRUSR | S_IRGRP)); -MODULE_PARM_DESC(dry_run, "Perform dry run on module load"); - u32 use_io_scheduler = 1; module_param(use_io_scheduler, uint, (S_IRUSR | S_IRGRP)); MODULE_PARM_DESC(use_io_scheduler, @@ -47,7 +43,6 @@ MODULE_PARM_DESC(seq_cut_off_mb, "Sequential cut off threshold in MiB. 0 - disable"); /* globals */ -bool in_upgrade; ocf_ctx_t cas_ctx; struct casdsk_functions_mapper casdisk_functions; @@ -94,7 +89,6 @@ int static cas_casdisk_lookup_funtions(void) cas_lookup_symbol(casdsk_exp_obj_create); cas_lookup_symbol(casdsk_exp_obj_free); cas_lookup_symbol(casdsk_disk_get_queue); - cas_lookup_symbol(casdsk_store_config); cas_lookup_symbol(casdsk_disk_get_blkdev); cas_lookup_symbol(casdsk_exp_obj_get_queue); cas_lookup_symbol(casdsk_get_version); @@ -102,14 +96,12 @@ int static cas_casdisk_lookup_funtions(void) cas_lookup_symbol(casdsk_disk_claim); cas_lookup_symbol(casdsk_exp_obj_unlock); cas_lookup_symbol(casdsk_disk_set_pt); - cas_lookup_symbol(casdsk_get_stored_config); cas_lookup_symbol(casdsk_disk_get_gendisk); cas_lookup_symbol(casdsk_disk_attach); cas_lookup_symbol(casdsk_disk_set_attached); cas_lookup_symbol(casdsk_exp_obj_activate); cas_lookup_symbol(casdsk_exp_obj_activated); cas_lookup_symbol(casdsk_exp_obj_lock); - cas_lookup_symbol(casdsk_free_stored_config); cas_lookup_symbol(casdsk_disk_open); cas_lookup_symbol(casdsk_disk_clear_pt); cas_lookup_symbol(casdsk_exp_obj_get_gendisk); @@ -171,31 +163,6 @@ static int __init cas_init_module(void) return result; } - result = cas_upgrade_get_configuration(); - if (-KCAS_ERR_NO_STORED_CONF == result) { - printk(KERN_INFO OCF_PREFIX_SHORT - "Not found configuration for upgrade. " - "Standard module initialization.\n"); - } else { - if (!dry_run) { - result = cas_upgrade_finish(); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Error during finish upgrade, " - "result: %d\n", result); - goto error_cas_ctx_init; - } - } else { - result = cas_upgrade_verify(); - if (result) { - printk(KERN_ERR OCF_PREFIX_SHORT - "Error during upgrade " - "verification\n"); - goto error_cas_ctx_init; - } - } - } - result = cas_ctrl_device_init(); if (result) { printk(KERN_ERR OCF_PREFIX_SHORT diff --git a/modules/cas_cache/service_ui_ioctl.c b/modules/cas_cache/service_ui_ioctl.c index 2fc0246..13c196a 100644 --- a/modules/cas_cache/service_ui_ioctl.c +++ b/modules/cas_cache/service_ui_ioctl.c @@ -46,15 +46,6 @@ long cas_service_ioctl_ctrl(struct file *filp, unsigned int cmd, return -EPERM; } - if (cas_upgrade_is_in_upgrade() && - cmd != KCAS_IOCTL_CACHE_INFO && - cmd != KCAS_IOCTL_LIST_CACHE && - cmd != KCAS_IOCTL_GET_CACHE_COUNT && - cmd != KCAS_IOCTL_CORE_INFO && - cmd != KCAS_IOCTL_PARTITION_INFO) { - return -EFAULT; - } - switch (cmd) { case KCAS_IOCTL_START_CACHE: { struct kcas_start_cache *cmd_info; @@ -315,16 +306,6 @@ long cas_service_ioctl_ctrl(struct file *filp, unsigned int cmd, RETURN_CMD_RESULT(cmd_info, arg, retval > 0 ? 0 : retval); } - case KCAS_IOCTL_UPGRADE: { - struct kcas_upgrade *cmd_info; - - GET_CMD_INFO(cmd_info, arg); - - retval = cas_upgrade(); - - RETURN_CMD_RESULT(cmd_info, arg, retval); - } - case KCAS_IOCTL_GET_CORE_POOL_COUNT: { struct kcas_core_pool_count *cmd_info; diff --git a/modules/cas_cache/utils/cas_cache_utils.h b/modules/cas_cache/utils/cas_cache_utils.h index 21fe0e9..99870e1 100644 --- a/modules/cas_cache/utils/cas_cache_utils.h +++ b/modules/cas_cache/utils/cas_cache_utils.h @@ -8,6 +8,5 @@ #define __CAS_UTILS_H__ #include "utils_nvme.h" -#include "utils_properties.h" #endif /* __CAS_UTILS_H__ */ diff --git a/modules/cas_cache/utils/cas_err.h b/modules/cas_cache/utils/cas_err.h index 0f2b087..64fec7d 100644 --- a/modules/cas_cache/utils/cas_err.h +++ b/modules/cas_cache/utils/cas_err.h @@ -56,9 +56,7 @@ struct { { KCAS_ERR_INV_IOCTL, EINVAL }, { KCAS_ERR_DEV_PENDING, EBUSY }, { KCAS_ERR_FILE_EXISTS, EEXIST }, - { KCAS_ERR_IN_UPGRADE, EFAULT }, { KCAS_ERR_UNALIGNED, EINVAL }, - { KCAS_ERR_NO_STORED_CONF, EINTR }, { KCAS_ERR_ROLLBACK, EFAULT }, { KCAS_ERR_NVME_BAD_FORMAT, EINVAL }, { KCAS_ERR_CONTAINS_PART, EINVAL }, diff --git a/modules/cas_cache/utils/utils_properties.c b/modules/cas_cache/utils/utils_properties.c deleted file mode 100644 index 1a91853..0000000 --- a/modules/cas_cache/utils/utils_properties.c +++ /dev/null @@ -1,769 +0,0 @@ -/* -* Copyright(c) 2012-2021 Intel Corporation -* SPDX-License-Identifier: BSD-3-Clause-Clear -*/ - -#include "cas_cache.h" - -#define INTERNAL_CALL 0 -#define EXTERNAL_CALL 1 - -#define CAS_PROPERTIES_VERSION 101 - -#define VERSION_STR ".version" - -/* - * Difference between constant and non constant entry is store in LSB - * e.g.: - * cas_property_string in binary 0000 1010 - * cas_property_string_const in binary 0000 1011 - */ - -#define CAS_PROP_UNCONST(type) (type & ~CAS_PROPERTIES_CONST) -#define CAS_PROP_CHECK_CONST(type) (type & CAS_PROPERTIES_CONST) - -enum cas_property_type { - cas_property_string = 10, - cas_property_string_const = - (cas_property_string | CAS_PROPERTIES_CONST), - cas_property_sint = 16, - cas_property_sint_const = (cas_property_sint | CAS_PROPERTIES_CONST), - cas_property_uint = 74, - cas_property_uint_const = (cas_property_uint | CAS_PROPERTIES_CONST), -}; - -struct cas_properties { - struct list_head list; -}; - -struct _cas_property { - uint8_t type; - char *key; - struct list_head item; - union { - void *value; - uint64_t value_uint; - int64_t value_sint; - }; -}; - -struct cas_properties *cas_properties_create(void) -{ - struct cas_properties *props; - int result; - - props = kzalloc(sizeof(*props), GFP_KERNEL); - if (!props) - return ERR_PTR(-ENOMEM); - - INIT_LIST_HEAD(&props->list); - - result = cas_properties_add_uint(props, VERSION_STR, - CAS_PROPERTIES_VERSION, CAS_PROPERTIES_CONST); - if (result) { - kfree(props); - return ERR_PTR(result); - } - - result = cas_properties_add_uint(props, ".size", 0, - CAS_PROPERTIES_NON_CONST); - if (result) { - kfree(props); - return ERR_PTR(result); - } - - return props; -} - -void cas_properties_destroy(struct cas_properties *props) -{ - struct list_head *curr, *tmp; - struct _cas_property *entry; - - list_for_each_safe(curr, tmp, &props->list) { - entry = list_entry(curr, struct _cas_property, item); - list_del(curr); - if (cas_property_string == CAS_PROP_UNCONST(entry->type)) - kfree(entry->value); - kfree(entry->key); - kfree(entry); - } - - kfree(props); -} - -static uint64_t _cas_prop_get_size(struct cas_properties *props) -{ - struct list_head *curr; - struct _cas_property *entry; - uint64_t size_all = 0; - - list_for_each(curr, &props->list) { - entry = list_entry(curr, struct _cas_property, item); - - size_all += cas_prop_strnlen(entry->key, MAX_STRING_SIZE) + 1; - size_all += sizeof(entry->type); - - switch (CAS_PROP_UNCONST(entry->type)) { - case cas_property_string: - size_all += cas_prop_strnlen(entry->value, - MAX_STRING_SIZE) + 1; - break; - case cas_property_sint: - size_all += sizeof(entry->value_sint); - break; - case cas_property_uint: - size_all += sizeof(entry->value_uint); - break; - default: - return 0; - } - } - - return size_all; -} - -static int _cas_prop_serialize_string(char *buffer, const uint64_t size, - uint64_t *offset, char *value) -{ - uint64_t str_size = 0; - - str_size = cas_prop_strnlen(value, MAX_STRING_SIZE) + 1; - - if ((*offset + str_size) > size) - return -ENOMEM; - - memcpy(buffer + *offset, value, str_size); - *offset += str_size; - - return 0; -} - -static int _cas_prop_parse_string(const char *buffer, const uint64_t size, - uint64_t *offset, char **str) -{ - char *tmp_str = NULL; - uint64_t str_size = 0; - - if (*offset >= size) - return -ENOMEM; - - str_size = cas_prop_strnlen(&buffer[*offset], size - *offset ) + 1; - - if (str_size > size - *offset) { - /* no null terminator at the end of buffer */ - return -ENOMEM; - } - - tmp_str = kstrdup(&buffer[*offset], GFP_KERNEL); - if (!tmp_str) - return -ENOMEM; - - *offset += str_size; - *str = tmp_str; - - return 0; -} - -static int _cas_prop_serialize_int(char *buffer, const uint64_t size, - uint64_t *offset, uint64_t number) -{ - int32_t i; - - /* - * To prevent issue connected with byte order we - * serialize integer byte by byte. - */ - for (i = 0; i < sizeof(number); i++) { - char byte = number & 0xFF; - - if (*offset < size) - buffer[*offset] = byte; - else - return -ENOMEM; - - (*offset)++; - number = number >> 8; - } - - return 0; -} - -static int _cas_prop_serialize_uint(char *buffer, const uint64_t size, - uint64_t *offset, uint64_t number) -{ - return _cas_prop_serialize_int(buffer, size, offset, number); -} - - -static int _cas_prop_serialize_sint(char *buffer, const uint64_t size, - uint64_t *offset, int64_t number) -{ - return _cas_prop_serialize_int(buffer, size, offset, (uint64_t) number); - -} - -static int _cas_prop_parse_int(const char *buffer, - const uint64_t size, uint64_t *offset, uint64_t *number) -{ - int32_t i; - uint64_t byte; - - *number = 0; - - /* - * To prevent issue connected with byte order we - * parse integer byte by byte. - */ - for (i = 0; i < sizeof(*number); i++) { - if (*offset >= size) - return -ENOMEM; - - byte = buffer[*offset] & 0xFF; - byte = byte << (i * 8); - - *number |= byte; - - (*offset)++; - } - - return 0; -} - -static int _cas_prop_parse_uint(const char *buffer, - const uint64_t size, uint64_t *offset, uint64_t *number) -{ - return _cas_prop_parse_int(buffer, size, offset, number); -} - -static int _cas_prop_parse_sint(const char *buffer, - const uint64_t size, uint64_t *offset, int64_t *number) -{ - return _cas_prop_parse_int(buffer, size, offset, (uint64_t *) number); -} - -static int _cas_prop_serialize(struct _cas_property *entry, void *buffer, - const uint64_t size, uint64_t *offset) -{ - uint64_t item_size = 0; - void *item; - int result = 0; - - if (*offset > size) - return -ENOMEM; - - /* - * Each entry is represented in buffer in order as below - * (e.g. in case we have entry with integer) : - * <----- entry -----> - * <- key -><-type-><- integer -> - * <- X bytes -><1 byte><- 8 byte -> - * | | | | - */ - - /* - * First step - serialize key - */ - - item_size = cas_prop_strnlen(entry->key, MAX_STRING_SIZE) + 1; - item = entry->key; - - if ((*offset + item_size) > size) - return -ENOMEM; - - memcpy(buffer + *offset, item, item_size); - *offset += item_size; - - /* - * Second step - serialize type - */ - - item_size = sizeof(entry->type); - item = &entry->type; - - if ((*offset + item_size) > size) - return -ENOMEM; - - memcpy(buffer + *offset, item, item_size); - *offset += item_size; - - /* - * Third step - serialize value - */ - - switch (CAS_PROP_UNCONST(entry->type)) { - case cas_property_string: - /* Serialize string */ - result = _cas_prop_serialize_string(buffer, size, offset, - entry->value); - break; - case cas_property_sint: - /* Serialize signed integer */ - result = _cas_prop_serialize_sint(buffer, size, offset, - entry->value_uint); - break; - case cas_property_uint: - /* Serialize unsigned integer */ - result = _cas_prop_serialize_uint(buffer, size, offset, - entry->value_uint); - break; - default: - result = -EINVAL; - break; - } - - return result; -} - -int cas_properties_serialize(struct cas_properties *props, - struct casdsk_props_conf *caches_serialized_conf) -{ - int result = 0; - uint64_t offset = 0, size; - uint16_t crc = 0; - void *buffer; - struct list_head *curr; - struct _cas_property *entry; - - size = _cas_prop_get_size(props); - if (size == 0) - return -EINVAL; - - buffer = vzalloc(size); - if (!buffer) - return -ENOMEM; - - /* - * Update first entry on list - size of buffer - */ - result = cas_properties_add_uint(props, ".size", size, - CAS_PROPERTIES_CONST); - if (result) - goto error_after_buffer_allocation; - - /* - * Serialize each entry, one by one - */ - list_for_each(curr, &props->list) { - entry = list_entry(curr, struct _cas_property, item); - result = _cas_prop_serialize(entry, buffer, size, &offset); - if (result) - goto error_after_buffer_allocation; - } - - crc = crc16(0, buffer, size); - - caches_serialized_conf->buffer = buffer; - caches_serialized_conf->size = size; - caches_serialized_conf->crc = crc; - return result; - -error_after_buffer_allocation: - vfree(buffer); - return result; -} - -void cas_properties_print(struct cas_properties *props) -{ - struct list_head *curr; - struct _cas_property *entry; - char *abc; - - /* - * Serialize each entry, one by one - */ - list_for_each(curr, &props->list) { - entry = list_entry(curr, struct _cas_property, item); - printk(KERN_DEBUG "[Upgrade] Key: %s", entry->key); - switch (CAS_PROP_UNCONST(entry->type)) { - case cas_property_string: - printk(", string, "); - abc = (char *)entry->value; - printk("Value: %s ", abc); - break; - case cas_property_sint: - break; - case cas_property_uint: - printk(", uint, "); - printk("Value: %llu ", entry->value_uint); - break; - default: - printk("Invalid type!"); - break; - } - printk("\n"); - } -} - -static int _cas_prop_parse_version(const char *buffer, uint64_t *offset, - uint64_t *version, int trigger) -{ - int result = 0; - char *key = NULL; - uint8_t type; - - result = _cas_prop_parse_string(buffer, strlen(VERSION_STR) + 1, - offset, &key); - if (result) - goto error_during_parse_key; - - if (strcmp(VERSION_STR, key)) { - result = -EINVAL; - goto error_after_parse_key; - } - - type = buffer[*offset]; - if (cas_property_uint_const != type) { - result = -EINVAL; - goto error_after_parse_key; - } - *offset += sizeof(type); - - result = _cas_prop_parse_uint(buffer, - strlen(VERSION_STR) + 1 + sizeof(type) + - sizeof(*version), offset, version); - if (result) - goto error_after_parse_key; - - /* - * In case that is external call - * we don't need check version. - */ - if (trigger == INTERNAL_CALL && *version != CAS_PROPERTIES_VERSION) { - printk(KERN_ERR "Version of interface using to parse is " - "different than version used to serialize\n"); - result = -EPERM; - } - -error_after_parse_key: - kfree(key); -error_during_parse_key: - return result; -} - -int cas_properites_parse_version(struct casdsk_props_conf *caches_serialized_conf, - uint64_t *version) -{ - uint64_t offset = 0; - char *buffer = NULL; - - buffer = (char *) caches_serialized_conf->buffer; - if (!buffer) - return -EINVAL; - - return _cas_prop_parse_version(buffer, &offset, version, EXTERNAL_CALL); -} - -struct cas_properties * -cas_properites_parse(struct casdsk_props_conf *caches_serialized_conf) -{ - struct cas_properties *props; - char *key = NULL, *value = NULL, *buffer = NULL; - int result; - uint8_t type; - uint64_t uint_value, size = 0, offset = 0, version = 0; - uint16_t crc; - int64_t sint_value; - bool constant = false; - - props = cas_properties_create(); - if (IS_ERR(props)) - return ERR_PTR(-ENOMEM); - - if (!caches_serialized_conf) { - result = -EINVAL; - goto error_after_props_allocation; - } - - buffer = (char *) caches_serialized_conf->buffer; - if (!buffer) { - result = -EINVAL; - goto error_after_props_allocation; - } - - size = caches_serialized_conf->size; - crc = crc16(0, buffer, size); - if (crc != caches_serialized_conf->crc) { - printk(KERN_ERR "Cache configuration corrupted"); - result = -EINVAL; - goto error_after_props_allocation; - } - - /* - * Parse first entry on list - version of interface used to - * serialization - */ - result = _cas_prop_parse_version(buffer, &offset, &version, - INTERNAL_CALL); - if (result) - goto error_after_props_allocation; - - while (offset < size) { - /* - * Parse key of entry - */ - result = _cas_prop_parse_string(buffer, size, &offset, &key); - if (result) - goto error_after_props_allocation; - - /* - * Parse type of entry - */ - if (offset + sizeof(type) > size) { - kfree(key); - goto error_after_props_allocation; - } - - memcpy(&type, buffer + offset, sizeof(type)); - offset += sizeof(type); - - constant = CAS_PROP_CHECK_CONST(type); - type = CAS_PROP_UNCONST(type); - - switch (type) { - case cas_property_string: - /* Parse string */ - result = _cas_prop_parse_string(buffer, size, &offset, - &value); - if (result) - break; - - /* - * Add new entry with string to CAS properties instance - */ - result |= cas_properties_add_string(props, key, value, - constant); - kfree(value); - break; - case cas_property_sint: - /* Parse signed integer */ - result = _cas_prop_parse_sint(buffer, size, &offset, - &sint_value); - /* Add new entry with signed integer to CAS properties - * instance - */ - result |= cas_properties_add_sint(props, key, - sint_value, constant); - break; - case cas_property_uint: - /* Parse unsigned integer */ - result = _cas_prop_parse_uint(buffer, size, &offset, - &uint_value); - /* Add new entry with unsigned integer to CAS properties - * instance - */ - result |= cas_properties_add_uint(props, key, - uint_value, constant); - break; - default: - result = -EINVAL; - break; - } - - /* - * In case when we added new entry, - * we not need hold key value longer. - */ - kfree(key); - - if (result) - goto error_after_props_allocation; - } - - return props; - -error_after_props_allocation: - cas_properties_destroy(props); - return ERR_PTR(result); -} - -static struct _cas_property *_cas_prop_find(const struct cas_properties *props, - const char *key) -{ - struct list_head *curr; - struct _cas_property *entry; - - list_for_each(curr, &props->list) { - entry = list_entry(curr, struct _cas_property, item); - if (strncmp(key, entry->key, MAX_STRING_SIZE) == 0) - return entry; - } - return ERR_PTR(-ENOENT); -} - -static struct _cas_property *_cas_prop_alloc_entry_key(const char *key) -{ - struct _cas_property *entry; - - entry = kzalloc(sizeof(*entry), GFP_KERNEL); - if (!entry) - return ERR_PTR(-ENOMEM); - - entry->key = kstrdup(key, GFP_KERNEL); - if (!entry->key) { - kfree(entry); - return ERR_PTR(-ENOMEM); - } - - INIT_LIST_HEAD(&entry->item); - - return entry; -} - -/* - * ADD - */ - -int cas_properties_add_uint(struct cas_properties *props, const char *key, - uint64_t value, bool constant) -{ - struct _cas_property *entry; - - /* - * Looks for entry with same key, - * if it is exist - update, if not - create new - */ - entry = _cas_prop_find(props, key); - if (IS_ERR(entry)) { - entry = _cas_prop_alloc_entry_key(key); - if (IS_ERR(entry)) - return PTR_ERR(entry); - list_add_tail(&entry->item, &props->list); - } else if (cas_property_uint != entry->type) { - /* - * We can update only non constant entry, - * so we need compare type only with non constant type. - */ - return -EINVAL; - } - - entry->type = constant ? cas_property_uint_const : cas_property_uint; - entry->value_uint = value; - - return 0; -} - -int cas_properties_add_sint(struct cas_properties *props, const char *key, - int64_t value, bool constant) -{ - struct _cas_property *entry; - - /* - * Looks for entry with same key, - * if it is exist - update, if not - create new - */ - entry = _cas_prop_find(props, key); - if (IS_ERR(entry)) { - entry = _cas_prop_alloc_entry_key(key); - if (IS_ERR(entry)) - return PTR_ERR(entry); - list_add_tail(&entry->item, &props->list); - } else if (cas_property_sint != entry->type) { - /* - * We can update only non constant entry, - * so we need compare type only with non constant type. - */ - return -EINVAL; - } - - entry->type = constant ? cas_property_sint_const : cas_property_sint; - entry->value_sint = value; - - return 0; -} - -int cas_properties_add_string(struct cas_properties *props, const char *key, - const char *value, bool constant) -{ - struct _cas_property *entry; - char *tmp_value = NULL; - - tmp_value = kstrdup(value, GFP_KERNEL); - if (!tmp_value) - return -ENOMEM; - - /* - * Looks for entry with same key, - * if it is exist - update, if not - create new - */ - entry = _cas_prop_find(props, key); - if (IS_ERR(entry)) { - entry = _cas_prop_alloc_entry_key(key); - if (IS_ERR(entry)) { - kfree(tmp_value); - return PTR_ERR(entry); - } - list_add_tail(&entry->item, &props->list); - } else { - if (cas_property_string != entry->type) { - /* - * We can update only non constant entry, - * so we need compare type only with non constant type. - */ - kfree(tmp_value); - return -EINVAL; - } - - kfree(entry->value); - } - - entry->type = constant ? cas_property_string_const : - cas_property_string; - entry->value = tmp_value; - - return 0; -} - -/* - * GET - */ - -int cas_properties_get_uint(struct cas_properties *props, const char *key, - uint64_t *value) -{ - struct _cas_property *entry; - - entry = _cas_prop_find(props, key); - if ((IS_ERR(entry) == 0) && (cas_property_uint == - CAS_PROP_UNCONST(entry->type))) { - *value = entry->value_uint; - return 0; - } - - return IS_ERR(entry) ? PTR_ERR(entry) : -EINVAL; -} - -int cas_properties_get_sint(struct cas_properties *props, const char *key, - int64_t *value) -{ - struct _cas_property *entry; - - entry = _cas_prop_find(props, key); - if ((IS_ERR(entry) == 0) && (cas_property_sint == - CAS_PROP_UNCONST(entry->type))) { - *value = entry->value_sint; - return 0; - } - - return IS_ERR(entry) ? PTR_ERR(entry) : -EINVAL; -} - -int cas_properties_get_string(struct cas_properties *props, const char *key, - char *value, uint32_t size) -{ - struct _cas_property *entry; - - entry = _cas_prop_find(props, key); - if ((IS_ERR(entry) == 0) && (cas_property_string == - CAS_PROP_UNCONST(entry->type))) { - /* Check if size of destination memory is enough */ - if (size < cas_prop_strnlen(entry->value, MAX_STRING_SIZE) + 1) - return -ENOMEM; - - cas_prop_strncpy(value, size, entry->value, - cas_prop_strnlen(entry->value, MAX_STRING_SIZE)); - return 0; - } - - return IS_ERR(entry) ? PTR_ERR(entry) : -EINVAL; -} diff --git a/modules/cas_cache/utils/utils_properties.h b/modules/cas_cache/utils/utils_properties.h deleted file mode 100644 index c498d2f..0000000 --- a/modules/cas_cache/utils/utils_properties.h +++ /dev/null @@ -1,153 +0,0 @@ -/* -* Copyright(c) 2012-2021 Intel Corporation -* SPDX-License-Identifier: BSD-3-Clause-Clear -*/ - -#ifndef UTILS_PROPERTIES_H_ -#define UTILS_PROPERTIES_H_ - -#ifdef __KERNEL__ -#define cas_prop_strncpy(dest, dest_size, src, src_size) \ - strlcpy(dest, src, dest_size) -#define cas_prop_strnlen(string, size) strnlen(string, size) -#else -#define cas_prop_strncpy(dest, dest_size, src, src_size) \ - strncpy(dest, src, src_size) -#define cas_prop_strnlen(string, size) strlen(string) -#endif - -#include "../../cas_disk/cas_disk.h" - -#define MAX_STRING_SIZE 4095 - -#define CAS_PROPERTIES_NON_CONST false -#define CAS_PROPERTIES_CONST true - -/** - * @file utils_properties.h - * @brief CAS cache interface for collect and serialization CAS properties - */ - -/** - * @brief Handler for instance of CAS properties - */ -struct cas_properties; - -/** - * @brief Initialize instance of CAS properties - * - * @return Handler to instance of interface - */ -struct cas_properties *cas_properties_create(void); - -/** - * @brief De-initialize instance of CAS properties - * - * @param props Handler to instance to de-initialize - */ -void cas_properties_destroy(struct cas_properties *props); - -/** - * @brief Serialize given CAS properties instance to continuous buffer - * - * @param props instance of CAS properties - * @param idisk conf instance of CAS properties - * @return result of serialize CAS properties - */ -int cas_properties_serialize(struct cas_properties *props, - struct casdsk_props_conf *caches_serialized_conf); - -/** - * @brief Parse of first entry given continuous buffer to get version of - * interface which been used to serialize - * - * @param buffer pointer to continuous buffer with serialized CAS properties - * @param version pointer to memory where we will put version - * @return result of getting version, 0 success - */ -int cas_properites_parse_version(struct casdsk_props_conf *caches_serialized_conf, - uint64_t *version); - -/** - * @brief Parse of given continuous buffer to CAS properties instance - * - * @param buffer pointer to continuous buffer with serialized CAS properties - * @return handler to CAS properties instance - */ -struct cas_properties * -cas_properites_parse(struct casdsk_props_conf *caches_serialized_conf); - -/** - * @brief Add unsigned integer to CAS properties instance - * - * @param props CAS properties instance to add variable - * @param key key paired with variable - * @param value value of variable - * @param private if true value cannot be updated - * @return result of adding 0 success - */ -int cas_properties_add_uint(struct cas_properties *props, const char *key, - uint64_t value, bool private); - -/** - * @brief Add signed integer to CAS properties instance - * - * @param props CAS properties instance to add variable - * @param key key paired with variable - * @param value value of variable - * @param private if true value cannot be updated - * @return result of adding 0 success - */ -int cas_properties_add_sint(struct cas_properties *props, const char *key, - int64_t value, bool private); - -/** - * @brief Add string to CAS properties instance - * - * @param props CAS properties instance to add variable - * @param key key paired with variable - * @param value value of variable - * @param private if true value cannot be updated - * @return result of adding 0 success - */ -int cas_properties_add_string(struct cas_properties *props, const char *key, - const char *value, bool private); - -/** - * @brief Get unsigned integer to CAS properties instance - * - * @param props CAS properties instance to add variable - * @param key key paired with variable - * @param value pointer to memory where we will put value - * @return result of getting 0 success - */ -int cas_properties_get_uint(struct cas_properties *props, const char *key, - uint64_t *value); - -/** - * @brief Get signed integer to CAS properties instance - * - * @param props CAS properties instance to add variable - * @param key key paired with variable - * @param value pointer to memory where we will put value - * @return result of getting 0 success - */ -int cas_properties_get_sint(struct cas_properties *props, const char *key, - int64_t *value); - -/** - * @brief Get string integer to CAS properties instance - * - * @param props CAS properties instance to add variable - * @param key key paired with variable - * @param value pointer to memory where we will put value - * @param size size of destination memory - * @return result of getting 0 success, 1 error, 2 not enough space - * in destination - */ -int cas_properties_get_string(struct cas_properties *props, const char *key, - char *value, uint32_t size); - - -void cas_properties_print(struct cas_properties *props); -#endif /* UTILS_PROPERTIES_H_ */ diff --git a/modules/cas_cache/volume/vol_block_dev_bottom.c b/modules/cas_cache/volume/vol_block_dev_bottom.c index 8777a17..49846d4 100644 --- a/modules/cas_cache/volume/vol_block_dev_bottom.c +++ b/modules/cas_cache/volume/vol_block_dev_bottom.c @@ -33,13 +33,7 @@ int block_dev_open_object(ocf_volume_t vol, void *volume_params) return 0; } - if (unlikely(true == cas_upgrade_is_in_upgrade())) { - dsk = casdisk_functions.casdsk_disk_claim(uuid->data, NULL); - casdisk_functions.casdsk_disk_set_attached(dsk); - } else { - dsk = casdisk_functions.casdsk_disk_open(uuid->data, NULL); - } - + dsk = casdisk_functions.casdsk_disk_open(uuid->data, NULL); if (IS_ERR_OR_NULL(dsk)) { int error = PTR_ERR(dsk) ?: -EINVAL; @@ -62,12 +56,7 @@ void block_dev_close_object(ocf_volume_t vol) if (bdobj->opened_by_bdev) return; - if (likely(!cas_upgrade_is_in_upgrade())) { - casdisk_functions.casdsk_disk_close(bdobj->dsk); - } else { - casdisk_functions.casdsk_disk_set_pt(bdobj->dsk); - casdisk_functions.casdsk_disk_detach(bdobj->dsk); - } + casdisk_functions.casdsk_disk_close(bdobj->dsk); } unsigned int block_dev_get_max_io_size(ocf_volume_t vol) diff --git a/modules/cas_cache/volume/vol_block_dev_top.c b/modules/cas_cache/volume/vol_block_dev_top.c index 28dd486..d50f78d 100644 --- a/modules/cas_cache/volume/vol_block_dev_top.c +++ b/modules/cas_cache/volume/vol_block_dev_top.c @@ -458,16 +458,10 @@ int block_dev_activate_exported_object(ocf_core_t core) ocf_cache_t cache = ocf_core_get_cache(core); struct bd_object *bvol = bd_object(obj); - if (!cas_upgrade_is_in_upgrade()) { - ret = casdisk_functions.casdsk_exp_obj_activate(bvol->dsk); + ret = casdisk_functions.casdsk_exp_obj_activate(bvol->dsk); + if (ret) { if (-EEXIST == ret) ret = KCAS_ERR_FILE_EXISTS; - } else { - ret = casdisk_functions.casdsk_disk_attach(bvol->dsk, THIS_MODULE, - &_blockdev_exp_obj_ops); - } - - if (ret) { printk(KERN_ERR "Cannot activate exported object, %s.%s. " "Error code %d\n", ocf_cache_get_name(cache), ocf_core_get_name(core), ret); @@ -506,11 +500,6 @@ int block_dev_create_exported_object(ocf_core_t core) goto end; } - if (cas_upgrade_is_in_upgrade()) { - bvol->expobj_valid = true; - return 0; - } - bvol->expobj_wq = alloc_workqueue("expobj_wq%s-%s", WQ_MEM_RECLAIM | WQ_HIGHPRI, 0, get_cache_id_string(cache), diff --git a/modules/cas_disk/cas_disk.h b/modules/cas_disk/cas_disk.h index cbc8911..aab24de 100644 --- a/modules/cas_disk/cas_disk.h +++ b/modules/cas_disk/cas_disk.h @@ -31,40 +31,12 @@ struct casdsk_exp_obj_ops { struct bio *bio, void *private); }; -/** - * Stored configuration buffer description - */ -struct casdsk_props_conf { - void *buffer; - size_t size; - uint16_t crc; -}; - /** * @brief Get version of cas_disk interface * @return cas_disk interface version */ uint32_t casdsk_get_version(void); -/** - * @brief Store configuration buffers in cas_disk - * @param n_blobs Number of configuration buffers - * @param blobs Array of configuration buffers structures - */ -void casdsk_store_config(size_t n_blobs, struct casdsk_props_conf *blobs); - -/** - * @brief Get previously stored configuration buffers - * @param blobs Where to store pointer to configuration buffers array - * @return Number of stored configuration buffers - */ -size_t casdsk_get_stored_config(struct casdsk_props_conf **blobs); - -/** - * @brief Free resources related to stored configuration buffers - */ -void casdsk_free_stored_config(void); - /** * @brief Open block device * @param path Path to block device diff --git a/modules/cas_disk/cas_disk_defs.h b/modules/cas_disk/cas_disk_defs.h index 24ae5a2..9122a6f 100644 --- a/modules/cas_disk/cas_disk_defs.h +++ b/modules/cas_disk/cas_disk_defs.h @@ -12,11 +12,6 @@ #include #include -struct casdsk_stored_config { - size_t n_blobs; - struct casdsk_props_conf *blobs; -}; - struct casdsk_module { struct mutex lock; @@ -31,8 +26,6 @@ struct casdsk_module { struct kmem_cache *pending_rqs_cache; struct kobject kobj; - - struct casdsk_stored_config config; }; extern struct casdsk_module *casdsk_module; diff --git a/modules/cas_disk/main.c b/modules/cas_disk/main.c index 5fd22a6..c6c7b6d 100644 --- a/modules/cas_disk/main.c +++ b/modules/cas_disk/main.c @@ -20,9 +20,6 @@ MODULE_VERSION(CAS_VERSION); static int iface_version = CASDSK_IFACE_VERSION; module_param(iface_version, int, (S_IRUSR | S_IRGRP)); -static int upgrade_in_progress = 0; -module_param(upgrade_in_progress, int, (S_IRUSR | S_IRGRP)); - struct casdsk_module *casdsk_module; uint32_t casdsk_get_version(void) @@ -31,46 +28,6 @@ uint32_t casdsk_get_version(void) } EXPORT_SYMBOL(casdsk_get_version); -static void _casdsk_module_free_config(struct casdsk_module *mod) -{ - int i; - - if (mod->config.blobs) { - for (i = 0; i < mod->config.n_blobs; i++) - vfree(mod->config.blobs[i].buffer); - kfree(mod->config.blobs); - - mod->config.blobs = NULL; - mod->config.n_blobs = 0; - } -} - -void casdsk_store_config(size_t n_blobs, struct casdsk_props_conf *blobs) -{ - upgrade_in_progress = 1; - _casdsk_module_free_config(casdsk_module); - casdsk_module->config.blobs = blobs; - casdsk_module->config.n_blobs = n_blobs; -} -EXPORT_SYMBOL(casdsk_store_config); - -size_t casdsk_get_stored_config(struct casdsk_props_conf **blobs) -{ - BUG_ON(!blobs); - - *blobs = casdsk_module->config.blobs; - return casdsk_module->config.n_blobs; -} -EXPORT_SYMBOL(casdsk_get_stored_config); - -void casdsk_free_stored_config(void) -{ - CASDSK_DEBUG_TRACE(); - _casdsk_module_free_config(casdsk_module); - upgrade_in_progress = 0; -} -EXPORT_SYMBOL(casdsk_free_stored_config); - static void _casdsk_module_release(struct kobject *kobj) { struct casdsk_module *mod; @@ -82,8 +39,6 @@ static void _casdsk_module_release(struct kobject *kobj) mod = container_of(kobj, struct casdsk_module, kobj); BUG_ON(!mod); - _casdsk_module_free_config(mod); - kfree(mod); } diff --git a/modules/include/cas_ioctl_codes.h b/modules/include/cas_ioctl_codes.h index 28c58c1..0f3bce7 100644 --- a/modules/include/cas_ioctl_codes.h +++ b/modules/include/cas_ioctl_codes.h @@ -290,10 +290,6 @@ struct kcas_capabilites { int ext_err_code; }; -struct kcas_upgrade { - int ext_err_code; -}; - /** * Format NVMe namespace. */ @@ -404,7 +400,7 @@ struct kcas_get_cache_param { * 16 * KCAS_IOCTL_GET_CACHE_COUNT * OK * * 17 * KCAS_IOCTL_LIST_CACHE * OK * * 18 * KCAS_IOCTL_GET_CAPABILITIES * DEPRECATED * - * 19 * KCAS_IOCTL_UPGRADE * OK * + * 19 * KCAS_IOCTL_UPGRADE * DEPRACATED * * 20 * KCAS_IOCTL_NVME_FORMAT * DEPRECATED * * 21 * KCAS_IOCTL_START_CACHE * OK * * 22 * KCAS_IOCTL_INSERT_CORE * OK * @@ -465,9 +461,6 @@ struct kcas_get_cache_param { /** Provides capabilites of installed open cas module */ #define KCAS_IOCTL_GET_CAPABILITIES _IOWR(KCAS_IOCTL_MAGIC, 18, struct kcas_capabilites) -/** Start upgrade in flight procedure */ -#define KCAS_IOCTL_UPGRADE _IOR(KCAS_IOCTL_MAGIC, 19, struct kcas_upgrade) - /** Format NVMe namespace to support selected metadata mode */ #define KCAS_IOCTL_NVME_FORMAT _IOWR(KCAS_IOCTL_MAGIC, 20, struct kcas_nvme_format) @@ -551,16 +544,10 @@ enum kcas_error { */ KCAS_ERR_FILE_EXISTS, - /** CAS is under upgrade */ - KCAS_ERR_IN_UPGRADE, - /** Cache device sector size is greater than core device %s sector size */ KCAS_ERR_UNALIGNED, - /** No caches configuration for upgrade in flight */ - KCAS_ERR_NO_STORED_CONF, - /** Cannot roll-back previous configuration */ KCAS_ERR_ROLLBACK, diff --git a/test/functional/api/cas/version.py b/test/functional/api/cas/version.py index c4b0ad8..99cd6ac 100644 --- a/test/functional/api/cas/version.py +++ b/test/functional/api/cas/version.py @@ -17,9 +17,6 @@ class CasVersion: self.type = release_type self.base = f"{self.main}.{self.major}.{self.minor}" - def can_be_upgraded(self): - return self.main >= 20 - def __str__(self): return f"{self.main}.{self.major}.{self.minor}.{self.pr}" \ f"{'.' + self.type if self.type is not None else ''}" @@ -46,7 +43,3 @@ def get_available_cas_versions(): versions = [CasVersion.from_git_tag(tag) for tag in release_tags] return versions - - -def get_upgradable_cas_versions(): - return [v for v in get_available_cas_versions() if v.can_be_upgraded()] diff --git a/utils/opencas.py b/utils/opencas.py index 274a64b..abc1c57 100644 --- a/utils/opencas.py +++ b/utils/opencas.py @@ -153,11 +153,6 @@ class casadm: '--file', ioclass_file] return cls.run_cmd(cmd) - @classmethod - def start_upgrade(cls): - cmd = [cls.casadm_path, '--script', '--upgrade-in-flight'] - - return cls.run_cmd(cmd) # Configuration file parser diff --git a/utils/upgrade b/utils/upgrade deleted file mode 100755 index 64f349f..0000000 --- a/utils/upgrade +++ /dev/null @@ -1,426 +0,0 @@ -#!/usr/bin/python3 -# -# Copyright(c) 2019-2021 Intel Corporation -# SPDX-License-Identifier: BSD-3-Clause-Clear -# - -import logging -import sys -import argparse -import subprocess -import os -from pathlib import Path -from shutil import copy - -import opencas -from upgrade_utils import ( - yn_prompt, - Failure, - Success, - Warn, - Abort, - StateMachine, - UpgradeState, - insert_module, - remove_module, - get_device_sysfs_path, - get_device_schedulers, - set_device_scheduler, - drop_os_caches, -) - -LOG_FILE = "/var/log/opencas-upgrade/upgrade.log" -COMPILATION_LOG = "/var/log/opencas-upgrade/build.log" -INIT_CONFIG_FILE_TMP_PATH = "/tmp/opencas_upgrade_backup.conf" - -CAS_CACHE_KEY = "CAS Cache Kernel Module" -CAS_DISK_KEY = "CAS Disk Kernel Module" -CAS_CLI_KEY = "CAS CLI Utility" - -CAS_DISK_MIN_VER = 20 - -OCL_BUILD_ROOT = f"{os.path.dirname(__file__)}/.." - - -class InitUpgrade(UpgradeState): - log = "Performing initial checks" - will_prompt = True - - class NotInstalled(Warn): - pass - - def do_work(self): - if self.state_machine.params["force"]: - self.will_prompt = False - elif yn_prompt("Proceed with upgrade procedure?") == "n": - return Abort("User aborted") - - try: - version = opencas.get_cas_version() - except FileNotFoundError: - return self.NotInstalled(f"Couldn't detect current CAS version") - except Exception as e: - return Failure(f"Failed to get current version of CAS {e}") - - # Although there shouldn't be any problem with upgrade from CAS 19.9 to newer, this feature - # is not full validated so it is disabled by default. - if (int(version[CAS_DISK_KEY].split('.')[0]) < CAS_DISK_MIN_VER): - return Failure(f"Minimal cas_disk version required to perform upgrade is 20.01!") - - if version[CAS_CLI_KEY] != version[CAS_CACHE_KEY]: - return Failure("Mismatch between CLI and cas_cache version") - - active_devices = opencas.get_devices_state() - - if any([device["status"] != "Running" for device in active_devices["caches"].values()]): - return Failure("Incomplete configuration. Run casadm -L to review CAS state!") - - if len(active_devices["core_pool"]) != 0: - return Failure("Incomplete configuration. Run casadm -L to review CAS state!") - - if os.path.isfile(opencas.cas_config.default_location): - try: - copy(opencas.cas_config.default_location, INIT_CONFIG_FILE_TMP_PATH) - except IOError: - return Failure("Could not save init config file backup") - else: - logging.info("Init config file not found") - - return Success() - - -class BuildCas(UpgradeState): - log = "Compiling Open CAS" - - def do_work(self): - with open(COMPILATION_LOG, "w") as build_log: - logging.info("Running ./configure for CAS") - p = subprocess.run( - ["./configure"], cwd=OCL_BUILD_ROOT, stdout=build_log, stderr=build_log - ) - if p.returncode: - return Failure(f"Configuration of Open CAS failed. Build log: {COMPILATION_LOG}") - - logging.info("Compiling CAS") - p = subprocess.run( - ["make", "-j"], cwd=OCL_BUILD_ROOT, stdout=build_log, stderr=build_log - ) - if p.returncode: - return Failure(f"Compilation of Open CAS failed. Build log: {COMPILATION_LOG}") - - return Success() - - -class RestoreInitConfig(UpgradeState): - log = "Restore original init config file" - - def do_work(self): - if not os.path.isfile(INIT_CONFIG_FILE_TMP_PATH): - logging.warning("Init config backup file not found") - return Success() - - try: - copy(INIT_CONFIG_FILE_TMP_PATH, opencas.cas_config.default_location) - except IOError: - logging.error(f"Failed to restore original init config file from " - f"{INIT_CONFIG_FILE_TMP_PATH}. Configuration has to be restored manually.") - return Failure() - - os.remove(INIT_CONFIG_FILE_TMP_PATH) - return Success() - - -class InstallCas(UpgradeState): - log = "Installing new Open CAS files" - - def do_work(self): - with open(COMPILATION_LOG, "a") as install_log: - p = subprocess.run( - ["make", "install"], cwd=OCL_BUILD_ROOT, stdout=install_log, stderr=install_log - ) - - if p.returncode: - return Failure( - f"Installation of Open CAS failed. Installation log: {COMPILATION_LOG}" - ) - - return Success() - - -class InsertModule(UpgradeState): - module_path = f"{OCL_BUILD_ROOT}/modules/cas_cache/cas_cache.ko" - options = {"installed": False} - - def do_work(self): - try: - insert_module(self.module_path, **self.options) - except Exception as e: - return Failure(f"Couldn't load module {self.module_path}. Reason: {e}") - - return Success() - - -class InsertNewModule(InsertModule): - log = "Try to insert new caching module" - - -class DryRun(InsertModule): - log = "Perform dry run to check upgrade data integrity" - options = {"installed": False, "dry_run": 1} - - def do_work(self): - result = super().do_work() - if not isinstance(result, Success): - return Failure("Dry run failed") - - try: - logging.info( - "Insert with dry_run set succeeded. Removing module to attempt final insertion." - ) - remove_module("cas_cache") - except Exception as e: - return Failure(f"Could not unload module. Reason: {e}") - - return result - - -class InsertInstalledModule(InsertModule): - log = "Restore old cas_cache module" - module_path = "cas_cache" - options = {"installed": True} - - -class PrepareForUpgrade(UpgradeState): - log = "Preparing Open CAS for upgrade" - - def do_work(self): - try: - logging.info("Switching CAS to upgrade mode") - opencas.casadm.start_upgrade() - except opencas.casadm.CasadmError as e: - return Failure(e) - - return Success() - - -class RemoveModule(UpgradeState): - log = "Removing cas_cache module" - - def do_work(self): - try: - logging.info("Removing cas_cache module") - remove_module("cas_cache") - except Exception as e: - return Failure(f"Failed to remove cas_cache module. Reason: {e}") - - return Success() - - -class SetSchedulersToNoop(UpgradeState): - log = "Setting core devices schedulers to noop" - - def do_work(self): - unique_core_sysfs_devices = { - get_device_sysfs_path(core["device"]) - for core in opencas.get_devices_state()["cores"].values() - } - - self.state_machine.schedulers = {} - for core_sysfs_path in unique_core_sysfs_devices: - current, available = get_device_schedulers(core_sysfs_path) - self.state_machine.schedulers[core_sysfs_path] = current - - if current in ["noop", "none"]: - logging.info(f"Core {core_sysfs_path} already uses {current} scheduler. Skipping.") - elif "noop" in available: - logging.info(f"Switching scheduler for {core_sysfs_path}: {current} => noop") - set_device_scheduler(core_sysfs_path, "noop") - elif "none" in available: - logging.info(f"Switching scheduler for {core_sysfs_path}: {current} => none") - set_device_scheduler(core_sysfs_path, "none") - else: - logging.info(f"No appropriate scheduler available for {core_sysfs_path}. Skipping.") - - return Success() - - -class RestoreCoreSchedulers(UpgradeState): - log = "Restoring core devices schedulers" - - def do_work(self): - for core_sysfs_path, scheduler in self.state_machine.schedulers.items(): - current = get_device_schedulers(core_sysfs_path)[0] - if scheduler in ["noop", "none"]: - logging.info( - f"Device {core_sysfs_path} already uses {scheduler} scheduler. Skipping." - ) - else: - logging.info(f"Switching scheduler for {core_sysfs_path}: {current} => {scheduler}") - set_device_scheduler(core_sysfs_path, scheduler) - - return Success() - - -class DropCaches(UpgradeState): - log = "Drop OS caches to ensure memory availability" - - def do_work(self): - logging.info("Dropping slab and page caches using procfs") - drop_os_caches() - - return Success() - - -class InstallStateMachine(StateMachine): - transition_map = { - BuildCas: {Success: InstallCas}, - InstallCas: {"default": None}, - "default": None, - } - - -class RegularInstall(UpgradeState): - log = "Installing Open CAS" - will_prompt = True - - def do_work(self): - if ( - yn_prompt("Previous CAS installation not detected. Perform regular installation?") - == "n" - ): - return Abort("User aborted") - - sm = InstallStateMachine(BuildCas) - result = sm.run() - - return result - - -class UpgradeStateMachine(StateMachine): - """ - This class implements whole CAS in-flight upgrade procedure. - - +-------------+ not +---------------+ - |InitUpgrade +----------->+RegularInstall | - +------+------+ installed | | - | | +---------+ | - v | |BuildCas | | - +------+------+ fail | +---+-----+ | - |BuildCas +------+ | | | - +------+------+ | | v | - | | | +---+-----+ | - v | | |Install | | - +------+------+ fail | | +---------+ | - |SetToNoop +------+ | | - +------+------+ | +----------+----+ - | | | - v +----------------+ - +------+------+ fail | - |PrepareForUpg+-------------------+ | - +------+------+ | | - | | | - v | | - +------+------+ fail | | - |RemoveModule +-------------------+ | - +------+------+ | | - | | | - v | | - +------+------+ fail | | - |DropCaches +-------------------+ | - +------+------+ | | - | | | - v | | - +------+------+ fail | | - |DryRun +--------+ | | - +------+------+ | | | - | | | | - v | | | - +------+------+ fail | | | - |InsertNew +--------+ | | - +------+------+ | | | - | | | | - v | | | - +------+------+ fail | | | - |InstallCas +--------+ | | - +------+------+ v | | - | +------+--------+ | | - | |InsertInstalled| | | - v +------+--------+ | | - +------+------+ | | | - |RestoreConfig+<-------+ | | - +------+------+ | | - | | | - v | | - +------+------+ | | - |RestoreSched +<------------------+ | - +------+------+ v - | +------+---+ - +---------------------->+ END | - +----------+ - - """ - - transition_map = { - InitUpgrade: {Success: BuildCas, InitUpgrade.NotInstalled: RegularInstall}, - RegularInstall: {"default": None}, - BuildCas: {Success: SetSchedulersToNoop}, - SetSchedulersToNoop: {Success: PrepareForUpgrade}, - PrepareForUpgrade: {Success: RemoveModule, Failure: RestoreCoreSchedulers}, - RemoveModule: {Success: DropCaches, Failure: RestoreCoreSchedulers}, - DropCaches: {Success: DryRun, Failure: RestoreCoreSchedulers}, - DryRun: {Success: InsertNewModule, Failure: InsertInstalledModule}, - InsertNewModule: {Success: InstallCas, Failure: InsertInstalledModule}, - InstallCas: {Success: RestoreInitConfig, Failure: InsertInstalledModule}, - InsertInstalledModule: {"default": RestoreInitConfig}, - RestoreInitConfig: {"default": RestoreCoreSchedulers}, - RestoreCoreSchedulers: {"default": None}, - "default": None, - } - - -def start(args): - logging.info(">>> Starting OpenCAS upgrade procedure") - s = UpgradeStateMachine(InitUpgrade, force=args.force) - result = s.run() - - if not isinstance(result, Success): - print(f"Upgrade failed. Reason: {result}") - exit_code = 1 - else: - print("Upgrade completed successfully!") - exit_code = 0 - - print(f"Full upgrade log: {LOG_FILE}") - - return exit_code - - -def main(): - Path(LOG_FILE).parent.mkdir(mode=0o700, parents=True, exist_ok=True) - console_handler = logging.StreamHandler() - console_handler.setLevel(logging.INFO) - logging.basicConfig( - level=logging.DEBUG, - format="%(asctime)s [%(levelname)-5.5s] %(message)s", - handlers=[logging.FileHandler(LOG_FILE)], - ) - - parser = argparse.ArgumentParser(prog=__file__) - subparsers = parser.add_subparsers(title="actions") - - parser_start = subparsers.add_parser( - "start", help="Upgrade Open CAS in flight to current version" - ) - parser_start.add_argument("--force", action="store_true", help="Skip prompts") - parser_start.set_defaults(func=start) - - if len(sys.argv[1:]) == 0: - parser.print_help() - return 1 - else: - args = parser.parse_args(sys.argv[1:]) - return args.func(args) - - -if __name__ == "__main__": - sys.exit(main())