Check for preexisting FS before standby init
Signed-off-by: Michal Mielewczyk <michal.mielewczyk@intel.com>
This commit is contained in:
parent
798a4c9c99
commit
a90839f286
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright(c) 2012-2021 Intel Corporation
|
* Copyright(c) 2012-2022 Intel Corporation
|
||||||
* SPDX-License-Identifier: BSD-3-Clause
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -329,7 +329,7 @@ static cli_option start_options[] = {
|
|||||||
{0}
|
{0}
|
||||||
};
|
};
|
||||||
|
|
||||||
static int check_fs(const char* device)
|
static int check_fs(const char* device, bool force)
|
||||||
{
|
{
|
||||||
char cache_dev_path[MAX_STR_LEN];
|
char cache_dev_path[MAX_STR_LEN];
|
||||||
static const char fsck_cmd[] = "/sbin/fsck -n %s > /dev/null 2>&1";
|
static const char fsck_cmd[] = "/sbin/fsck -n %s > /dev/null 2>&1";
|
||||||
@ -344,7 +344,7 @@ static int check_fs(const char* device)
|
|||||||
snprintf(buff, sizeof(buff), fsck_cmd, cache_dev_path);
|
snprintf(buff, sizeof(buff), fsck_cmd, cache_dev_path);
|
||||||
|
|
||||||
if (!system(buff)) {
|
if (!system(buff)) {
|
||||||
if (command_args_values.force) {
|
if (force) {
|
||||||
cas_printf(LOG_INFO, "A filesystem existed on %s. "
|
cas_printf(LOG_INFO, "A filesystem existed on %s. "
|
||||||
"Data may have been lost\n",
|
"Data may have been lost\n",
|
||||||
device);
|
device);
|
||||||
@ -362,7 +362,7 @@ static int check_fs(const char* device)
|
|||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int validate_cache_path(const char* path)
|
int validate_cache_path(const char* path, bool force)
|
||||||
{
|
{
|
||||||
int cache_device;
|
int cache_device;
|
||||||
struct stat device_info;
|
struct stat device_info;
|
||||||
@ -389,7 +389,7 @@ int validate_cache_path(const char* path)
|
|||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (check_fs(path)) {
|
if (check_fs(path, force)) {
|
||||||
close(cache_device);
|
close(cache_device);
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
@ -426,8 +426,10 @@ int handle_start()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (validate_cache_path(command_args_values.cache_device) == FAILURE)
|
if (validate_cache_path(command_args_values.cache_device,
|
||||||
|
command_args_values.force) == FAILURE) {
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
status = start_cache(command_args_values.cache_id,
|
status = start_cache(command_args_values.cache_id,
|
||||||
command_args_values.state,
|
command_args_values.state,
|
||||||
@ -2114,6 +2116,11 @@ int standby_handle() {
|
|||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (validate_cache_path(standby_params.cache_device,
|
||||||
|
standby_params.force) == FAILURE) {
|
||||||
|
return FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
switch (standby_params.subcmd) {
|
switch (standby_params.subcmd) {
|
||||||
case standby_opt_subcmd_init:
|
case standby_opt_subcmd_init:
|
||||||
return standby_init(standby_params.cache_id,
|
return standby_init(standby_params.cache_id,
|
||||||
|
Loading…
Reference in New Issue
Block a user