Fully remove format nvme command

Since there is no kernel-kernel api available to communicate
with nvme driver it is more convenient to use some nvme-dedicated
software (e.g. nvme-cli) to manage nvme devices.
It is even not possible to format nvme device with CAS using current
implementation on newest kernels.

Signed-off-by: Michal Rakowski <michal.rakowski@intel.com>
Signed-off-by: Michal Mielewczyk <michal.mielewczyk@intel.com>
This commit is contained in:
Michal Rakowski
2020-06-19 11:38:32 +02:00
committed by Michal Mielewczyk
parent 91f0cbf6aa
commit 1cd1db2b45
9 changed files with 3 additions and 822 deletions

View File

@@ -2785,92 +2785,6 @@ int list_caches(unsigned int list_format)
return result;
}
int _get_cas_capabilites(struct kcas_capabilites *caps, int quiet)
{
static bool retrieved = false;
static struct kcas_capabilites caps_buf;
int status = SUCCESS;
int ctrl_fd;
if (!retrieved) {
if (quiet) {
ctrl_fd = open_ctrl_device_quiet();
} else {
ctrl_fd = open_ctrl_device();
}
if (ctrl_fd < 0) {
if (!quiet)
print_err(KCAS_ERR_SYSTEM);
return FAILURE;
}
status = ioctl(ctrl_fd, KCAS_IOCTL_GET_CAPABILITIES, &caps_buf);
close(ctrl_fd);
if (status) {
return FAILURE;
}
retrieved = true;
}
memcpy_s(caps, sizeof(*caps), &caps_buf, sizeof(caps_buf));
return status;
}
int get_cas_capabilites_quiet(struct kcas_capabilites *caps)
{
return _get_cas_capabilites(caps, true);
}
int get_cas_capabilites(struct kcas_capabilites *caps)
{
return _get_cas_capabilites(caps, false);
}
int nvme_format(const char *device_path, int metadata_mode, int force)
{
struct kcas_nvme_format cmd_info;
int fd;
int result = 0;
strncpy_s(cmd_info.device_path_name,
sizeof(cmd_info.device_path_name), device_path,
strnlen_s(device_path, sizeof(cmd_info.device_path_name)));
switch (metadata_mode) {
case METADATA_MODE_NORMAL:
cmd_info.metadata_mode = CAS_METADATA_MODE_NORMAL;
break;
case METADATA_MODE_ATOMIC:
cmd_info.metadata_mode = CAS_METADATA_MODE_ATOMIC;
break;
default:
return FAILURE;
}
cmd_info.force = force;
fd = open_ctrl_device();
if (fd == -1)
return FAILURE;
/* Format NVMe */
result = run_ioctl(fd, KCAS_IOCTL_NVME_FORMAT, &cmd_info);
close(fd);
if (result) {
result = cmd_info.ext_err_code ? : KCAS_ERR_SYSTEM;
cas_printf(LOG_INFO, "Changing NVMe format failed!\n");
print_err(result);
return FAILURE;
}
cas_printf(LOG_INFO, "Changing NVMe format succeeded.\n"
"IMPORTANT: Reboot is required!\n");
return SUCCESS;
}
int _check_cache_device(const char *device_path,
struct kcas_cache_check_device *cmd_info)
{

View File

@@ -226,11 +226,6 @@ int purge_core(unsigned int cache_id, unsigned int core_id);
int flush_cache(unsigned int cache_id);
int flush_core(unsigned int cache_id, unsigned int core_id);
int get_cas_capabilites_quiet(struct kcas_capabilites *caps);
int get_cas_capabilites(struct kcas_capabilites *caps);
int nvme_format(const char *device_path, int metadata_mode, int force);
int check_cache_device(const char *device_path);
int partition_list(unsigned int cache_id, unsigned int output_format);

View File

@@ -1697,128 +1697,6 @@ int script_handle() {
return FAILURE;
}
/*******************************************************************************
* NVMe Commands
******************************************************************************/
enum {
nvme_opt_subcmd_format = 0,
nvme_opt_device,
nvme_opt_force,
nvme_opt_flag_required,
nvme_opt_flag_set,
nvme_opt_subcmd_unknown,
};
/* NVMe command options */
static cli_option nvme_options[] = {
[nvme_opt_subcmd_format] = {
.short_name = 'F',
.long_name = "format",
.desc = "Change NVMe metadata mode {normal|atomic} WARNING: Reboot required!",
.args_count = 1,
.arg = "MODE",
.flags = CLI_OPTION_REQUIRED,
},
[nvme_opt_device] = {
.short_name = 'd',
.long_name = "device",
.desc = "NVMe device to be formatted",
.args_count = 1,
.arg = "DEVICE",
.flags = CLI_OPTION_REQUIRED,
},
[nvme_opt_force] = {
.short_name = 'f',
.long_name = "force",
.desc = "Force NVMe format",
.args_count = 0,
.arg = NULL,
.flags = CLI_OPTION_OPTIONAL_ARG,
},
{0}
};
struct {
const char *device;
int metadata_mode;
int force;
} static nvme_params = {
.device = "",
.metadata_mode = 0,
.force = 0,
};
/* Parser of option for IO class command */
int nvme_handle_option(char *opt, const char **arg)
{
if (!strcmp(opt, "device")) {
nvme_params.device = arg[0];
} else if (!strcmp(opt, "format")) {
nvme_params.metadata_mode = validate_str_metadata_mode(arg[0]);
if (METADATA_MODE_INVALID == nvme_params.metadata_mode)
return FAILURE;
} else if (!strcmp(opt, "force")) {
nvme_params.force = 1;
} else {
return FAILURE;
}
return 0;
}
static int handle_nvme_format()
{
struct kcas_capabilites cas_capabilites;
static const char fsck_cmd[] = "/sbin/fsck -n %s > /dev/null 2>&1";
static const uint32_t size = MAX_STR_LEN + sizeof(fsck_cmd) + 1;
char nvme_dev_path[MAX_STR_LEN];
char buff[size];
if (get_cas_capabilites(&cas_capabilites)) {
cas_printf(LOG_ERR, "Can't obtain CAS capabilities\n");
return FAILURE;
}
if (!cas_capabilites.nvme_format) {
cas_printf(LOG_ERR, "Command is not supported by current kernel\n");
return FAILURE;
}
if (get_dev_path(nvme_params.device, nvme_dev_path,
sizeof(nvme_dev_path))) {
cas_printf(LOG_ERR, "Device does not exist\n");
return FAILURE;
}
snprintf(buff, sizeof(buff), fsck_cmd, nvme_dev_path);
if (!system(buff)) {
if (nvme_params.force) {
cas_printf(LOG_INFO, "A filesystem existed on %s. "
"Data may have been lost\n",
nvme_params.device);
} else {
/* file system on cache device */
cas_printf(LOG_ERR, "A filesystem exists on %s. "
"Specify the --force option if you "
"wish to format the device anyway.\n"
"Note: this may result in loss of data\n",
nvme_params.device);
return FAILURE;
}
}
return nvme_format(nvme_dev_path, nvme_params.metadata_mode,
nvme_params.force);
}
static cli_option version_options[] = {
{
.short_name = 'o',
@@ -1891,12 +1769,6 @@ void io_class_help(app *app_values, cli_command *cmd)
char option_name[MAX_STR_LEN];
cli_option* iter = &(cmd->options[0]);
struct kcas_capabilites caps;
if (get_cas_capabilites(&caps)) {
memset(&caps, 0, sizeof(caps));
}
/* Print usage */
cas_printf(LOG_INFO, "Usage: %s --%s {", app_values->name, cmd->name);
print_options_usage(cmd->options, "|", io_class_print_subcmd, 0);
@@ -2149,17 +2021,6 @@ static cli_command cas_commands[] = {
.flags = CLI_SU_REQUIRED,
.help = io_class_help,
},
{
.name = "nvme",
.short_name = 'N',
.desc = "Manage NVMe namespace",
.long_desc = NULL,
.options = nvme_options,
.command_handle_opts = nvme_handle_option,
.handle = handle_nvme_format,
.flags = CLI_SU_REQUIRED,
.help = NULL,
},
{
.name = "version",
.short_name = 'V',

View File

@@ -184,11 +184,6 @@ struct {
KCAS_ERR_DEV_PENDING,
"Device opens or mount are pending to this cache"
},
{
KCAS_ERR_DIRTY_EXISTS_NVME,
"Cache device contains dirty data.\nIf you want to format it, "
"please use --force option.\nWarning: all data will be lost!"
},
{
KCAS_ERR_FILE_EXISTS,
"Could not create exported object because file in /dev "
@@ -212,22 +207,10 @@ struct {
KCAS_ERR_ROLLBACK,
"Cannot restore previous configuration"
},
{
KCAS_ERR_NOT_NVME,
"Given block device is not NVMe"
},
{
KCAS_ERR_FORMAT_FAILED,
"Failed to format NVMe device"
},
{
KCAS_ERR_NVME_BAD_FORMAT,
"NVMe is formatted to unsupported format"
},
{
KCAS_ERR_UNSUPPORTED_LBA_FORMAT,
"Specified LBA format is not supported by the NVMe device"
},
{
KCAS_ERR_CONTAINS_PART,
"Device contains partitions.\nIf you want to continue, "