From 0d1730af37606e8827d5beb5a0f64a6a3ee9eb82 Mon Sep 17 00:00:00 2001 From: Slawomir Jankowski Date: Thu, 9 Apr 2020 09:37:29 +0200 Subject: [PATCH 1/4] Modify *run_ioctl* function Make *run_ioctl* a simple wrapper for *ioctl* function. *run_ioctl_retry* is old *run_ioctl* function. Signed-off-by: Slawomir Jankowski --- casadm/cas_lib_utils.c | 13 ++++++++++++- casadm/cas_lib_utils.h | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/casadm/cas_lib_utils.c b/casadm/cas_lib_utils.c index b3ef085..da82788 100644 --- a/casadm/cas_lib_utils.c +++ b/casadm/cas_lib_utils.c @@ -469,12 +469,23 @@ int run_ioctl_interruptible(int fd, int command, void *cmd, } /* - * @brief ioctl wrapper that retries ioctl attempts within one second timeouts + * @brief ioctl wrapper * @param[in] fd as for IOCTL(2) * @param[in] command as for IOCTL(2) * @param[inout] cmd_info as for IOCTL(2) */ int run_ioctl(int fd, int command, void *cmd) +{ + return ioctl(fd, command, cmd); +} + +/* + * @brief ioctl wrapper that retries ioctl attempts within one second timeouts + * @param[in] fd as for IOCTL(2) + * @param[in] command as for IOCTL(2) + * @param[inout] cmd_info as for IOCTL(2) + */ +int run_ioctl_retry(int fd, int command, void *cmd) { int i, ret; struct timespec timeout = { diff --git a/casadm/cas_lib_utils.h b/casadm/cas_lib_utils.h index b707da8..77a9bf7 100644 --- a/casadm/cas_lib_utils.h +++ b/casadm/cas_lib_utils.h @@ -28,6 +28,7 @@ struct progress_status { void init_progress_bar(struct progress_status *ps); void print_progress_bar_or_indicator(float prog, struct progress_status *ps); int run_ioctl(int fd, int command, void *cmd); +int run_ioctl_retry(int fd, int command, void *cmd); int run_ioctl_interruptible(int fd, int command, void *cmd, char *friendly_name, int cache_id, int core_id); int open_ctrl_device(); From cfca19b02449b1f81b1dbda1ffa2886a64cb7406 Mon Sep 17 00:00:00 2001 From: Slawomir Jankowski Date: Thu, 9 Apr 2020 09:38:49 +0200 Subject: [PATCH 2/4] Use *run_ioctl* and *run_ioctl_retry* Signed-off-by: Slawomir Jankowski --- casadm/cas_lib_utils.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/casadm/cas_lib_utils.c b/casadm/cas_lib_utils.c index da82788..3a53806 100644 --- a/casadm/cas_lib_utils.c +++ b/casadm/cas_lib_utils.c @@ -457,7 +457,13 @@ int run_ioctl_interruptible(int fd, int command, void *cmd, pthread_sigmask(SIG_BLOCK, &sigset, NULL); pthread_create(&thread, 0, print_command_progress, &ps); - ioctl_res = run_ioctl(fd, command, cmd); + + if (retry) { + ioctl_res = run_ioctl_retry(fd, command, cmd); + } else { + ioctl_res = run_ioctl(fd, command, cmd); + } + if (!interrupted) { close(fdspipe[1]); } From db35d5a299d0371719fbba5be45543b80b40c9c5 Mon Sep 17 00:00:00 2001 From: Slawomir Jankowski Date: Thu, 9 Apr 2020 09:43:00 +0200 Subject: [PATCH 3/4] Modify *run_ioctl_interruptible* function Make *run_ioctl_interruptible* a wrapper for new function *run_ioctl_interruptible_retry_option*. Make new function *run_ioctl_interruptible_retry* - a wrapper for *run_ioctl_interruptible_retry_option*. *run_ioctl_interruptible_retry_option* is old *run_ioctl_interruptible* function with one more parameter to decide if call *run_ioctl* or *run_ioctl_retry*. Signed-off-by: Slawomir Jankowski --- casadm/cas_lib_utils.c | 32 ++++++++++++++++++++++++++++++-- casadm/cas_lib_utils.h | 2 ++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/casadm/cas_lib_utils.c b/casadm/cas_lib_utils.c index 3a53806..e9f0126 100644 --- a/casadm/cas_lib_utils.c +++ b/casadm/cas_lib_utils.c @@ -433,9 +433,10 @@ void *print_command_progress(void *th_arg) * Catch SIGINT signal. * @param friendly_name name of management operation that shall * be displayed in command prompt + * @param retry decide if ioctl attepmts should retry */ -int run_ioctl_interruptible(int fd, int command, void *cmd, - char *friendly_name, int cache_id, int core_id) +static int run_ioctl_interruptible_retry_option(int fd, int command, void *cmd, + char *friendly_name, int cache_id, int core_id, bool retry) { pthread_t thread; int ioctl_res; @@ -474,6 +475,33 @@ int run_ioctl_interruptible(int fd, int command, void *cmd, return ioctl_res; } +/* + * Run ioctl in a way that displays progressbar (if flushing operation takes longer) + * Catch SIGINT signal. + * @param friendly_name name of management operation that shall + * be displayed in command prompt + */ +int run_ioctl_interruptible(int fd, int command, void *cmd, + char *friendly_name, int cache_id, int core_id) +{ + return run_ioctl_interruptible_retry_option(fd, command, cmd, friendly_name, + cache_id, core_id, false); +} + +/* + * Run ioctl in a way that displays progressbar (if flushing operation + * takes longer) with retries. + * Catch SIGINT signal. + * @param friendly_name name of management operation that shall + * be displayed in command prompt + */ +int run_ioctl_interruptible_retry(int fd, int command, void *cmd, + char *friendly_name, int cache_id, int core_id) +{ + return run_ioctl_interruptible_retry_option(fd, command, cmd, friendly_name, + cache_id, core_id, true); +} + /* * @brief ioctl wrapper * @param[in] fd as for IOCTL(2) diff --git a/casadm/cas_lib_utils.h b/casadm/cas_lib_utils.h index 77a9bf7..a1c6a66 100644 --- a/casadm/cas_lib_utils.h +++ b/casadm/cas_lib_utils.h @@ -31,6 +31,8 @@ int run_ioctl(int fd, int command, void *cmd); int run_ioctl_retry(int fd, int command, void *cmd); int run_ioctl_interruptible(int fd, int command, void *cmd, char *friendly_name, int cache_id, int core_id); +int run_ioctl_interruptible_retry(int fd, int command, void *cmd, + char *friendly_name, int cache_id, int core_id); int open_ctrl_device(); int was_ioctl_interrupted(); void set_default_sig_handler(); From a9a85fb01f1b3b3b91c994881fd68d28252ac39f Mon Sep 17 00:00:00 2001 From: Slawomir Jankowski Date: Thu, 9 Apr 2020 09:45:09 +0200 Subject: [PATCH 4/4] Update use of *run_ioctl_interruptible* after changes Signed-off-by: Slawomir Jankowski --- casadm/cas_lib.c | 10 +++++----- casadm/upgrade.c | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/casadm/cas_lib.c b/casadm/cas_lib.c index 57b664d..c131c59 100644 --- a/casadm/cas_lib.c +++ b/casadm/cas_lib.c @@ -940,7 +940,7 @@ int start_cache(uint16_t cache_id, unsigned int cache_init, cmd.line_size = line_size; cmd.force = (uint8_t)force; - if (run_ioctl_interruptible(fd, KCAS_IOCTL_START_CACHE, &cmd, + if (run_ioctl_interruptible_retry(fd, KCAS_IOCTL_START_CACHE, &cmd, "Starting cache", cache_id, OCF_CORE_ID_INVALID) < 0) { close(fd); if (cmd.ext_err_code == OCF_ERR_NO_FREE_RAM) { @@ -1035,7 +1035,7 @@ int stop_cache(uint16_t cache_id, int flush) cmd.cache_id = cache_id; cmd.flush_data = flush; - if(run_ioctl_interruptible(fd, KCAS_IOCTL_STOP_CACHE, &cmd, "Stopping cache", + if(run_ioctl_interruptible_retry(fd, KCAS_IOCTL_STOP_CACHE, &cmd, "Stopping cache", cache_id, OCF_CORE_ID_INVALID) < 0) { close(fd); if (OCF_ERR_FLUSHING_INTERRUPTED == cmd.ext_err_code) { @@ -1122,7 +1122,7 @@ int set_cache_mode(unsigned int cache_mode, unsigned int cache_id, int flush) cmd.caching_mode = cache_mode; cmd.flush_data = flush; - if (run_ioctl_interruptible(fd, KCAS_IOCTL_SET_CACHE_STATE, &cmd, "Setting mode", + if (run_ioctl_interruptible_retry(fd, KCAS_IOCTL_SET_CACHE_STATE, &cmd, "Setting mode", cache_id, OCF_CORE_ID_INVALID) < 0) { close(fd); if (OCF_ERR_FLUSHING_INTERRUPTED == cmd.ext_err_code) { @@ -1951,7 +1951,7 @@ int flush_cache(unsigned int cache_id) memset(&cmd, 0, sizeof(cmd)); cmd.cache_id = cache_id; /* synchronous flag */ - if (run_ioctl_interruptible(fd, KCAS_IOCTL_FLUSH_CACHE, &cmd, "Flushing cache", + if (run_ioctl_interruptible_retry(fd, KCAS_IOCTL_FLUSH_CACHE, &cmd, "Flushing cache", cache_id, OCF_CORE_ID_INVALID) < 0) { close(fd); if (OCF_ERR_FLUSHING_INTERRUPTED == cmd.ext_err_code) { @@ -2004,7 +2004,7 @@ int flush_core(unsigned int cache_id, unsigned int core_id) return FAILURE; /* synchronous flag */ - if (run_ioctl_interruptible(fd, KCAS_IOCTL_FLUSH_CORE, &cmd, "Flushing core", cache_id, core_id) < 0) { + if (run_ioctl_interruptible_retry(fd, KCAS_IOCTL_FLUSH_CORE, &cmd, "Flushing core", cache_id, core_id) < 0) { close(fd); if (OCF_ERR_FLUSHING_INTERRUPTED == cmd.ext_err_code) { cas_printf(LOG_ERR, DIRTY_FLUSHING_WARNING); diff --git a/casadm/upgrade.c b/casadm/upgrade.c index cb94109..649566f 100644 --- a/casadm/upgrade.c +++ b/casadm/upgrade.c @@ -23,7 +23,7 @@ int upgrade_start() return -1; } - if (run_ioctl_interruptible(fd, KCAS_IOCTL_UPGRADE, &cmd_info, + 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) {