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/cas_lib_utils.c b/casadm/cas_lib_utils.c index b3ef085..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; @@ -457,7 +458,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]); } @@ -469,12 +476,50 @@ int run_ioctl_interruptible(int fd, int command, void *cmd, } /* - * @brief ioctl wrapper that retries ioctl attempts within one second timeouts + * 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) * @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..a1c6a66 100644 --- a/casadm/cas_lib_utils.h +++ b/casadm/cas_lib_utils.h @@ -28,8 +28,11 @@ 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 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(); 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) {