Skip to content

Commit

Permalink
nvme: add EMVS support to sanitize command
Browse files Browse the repository at this point in the history
Add Enter Media Verification State (EMVS) support to sanitize
command.
TP4152 - Post-Sanitize Media Verification 2024.04.01 Ratified.

Signed-off-by: Francis Pravin <francis.p@samsung.com>
Reviewed-by: Steven Seungcheol Lee <sc108.lee@samsung.com>
  • Loading branch information
francispravin5 authored and igaw committed Oct 24, 2024
1 parent ae00ebf commit bccdb63
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -5173,11 +5173,13 @@ static int ns_rescan(int argc, char **argv, struct command *cmd, struct plugin *
static int sanitize_cmd(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Send a sanitize command.";
const char *emvs_desc = "Enter media verification state.";
const char *no_dealloc_desc = "No deallocate after sanitize.";
const char *oipbp_desc = "Overwrite invert pattern between passes.";
const char *owpass_desc = "Overwrite pass count.";
const char *ause_desc = "Allow unrestricted sanitize exit.";
const char *sanact_desc = "Sanitize action: 1 = Exit failure mode, 2 = Start block erase, 3 = Start overwrite, 4 = Start crypto erase";
const char *sanact_desc = "Sanitize action: 1 = Exit failure mode, 2 = Start block erase,"
"3 = Start overwrite, 4 = Start crypto erase, 5 = Exit media verification";
const char *ovrpat_desc = "Overwrite pattern.";

_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
Expand All @@ -5190,6 +5192,7 @@ static int sanitize_cmd(int argc, char **argv, struct command *cmd, struct plugi
bool ause;
__u8 sanact;
__u32 ovrpat;
bool emvs;
};

struct config cfg = {
Expand All @@ -5199,13 +5202,15 @@ static int sanitize_cmd(int argc, char **argv, struct command *cmd, struct plugi
.ause = false,
.sanact = 0,
.ovrpat = 0,
.emvs = false,
};

OPT_VALS(sanact) = {
VAL_BYTE("exit-failure", NVME_SANITIZE_SANACT_EXIT_FAILURE),
VAL_BYTE("start-block-erase", NVME_SANITIZE_SANACT_START_BLOCK_ERASE),
VAL_BYTE("start-overwrite", NVME_SANITIZE_SANACT_START_OVERWRITE),
VAL_BYTE("start-crypto-erase", NVME_SANITIZE_SANACT_START_CRYPTO_ERASE),
VAL_BYTE("exit-media-verification", NVME_SANITIZE_SANACT_EXIT_MEDIA_VERIF),
VAL_END()
};

Expand All @@ -5215,7 +5220,8 @@ static int sanitize_cmd(int argc, char **argv, struct command *cmd, struct plugi
OPT_BYTE("owpass", 'n', &cfg.owpass, owpass_desc),
OPT_FLAG("ause", 'u', &cfg.ause, ause_desc),
OPT_BYTE("sanact", 'a', &cfg.sanact, sanact_desc, sanact),
OPT_UINT("ovrpat", 'p', &cfg.ovrpat, ovrpat_desc));
OPT_UINT("ovrpat", 'p', &cfg.ovrpat, ovrpat_desc),
OPT_FLAG("emvs", 'e', &cfg.emvs, emvs_desc));

err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
Expand All @@ -5226,16 +5232,20 @@ static int sanitize_cmd(int argc, char **argv, struct command *cmd, struct plugi
case NVME_SANITIZE_SANACT_START_BLOCK_ERASE:
case NVME_SANITIZE_SANACT_START_OVERWRITE:
case NVME_SANITIZE_SANACT_START_CRYPTO_ERASE:
case NVME_SANITIZE_SANACT_EXIT_MEDIA_VERIF:
break;
default:
nvme_show_error("Invalid Sanitize Action");
return -EINVAL;
}

if (cfg.sanact == NVME_SANITIZE_SANACT_EXIT_FAILURE) {
if (cfg.ause || cfg.no_dealloc) {
if (cfg.ause || cfg.no_dealloc) {
if (cfg.sanact == NVME_SANITIZE_SANACT_EXIT_FAILURE) {
nvme_show_error("SANACT is Exit Failure Mode");
return -EINVAL;
} else if (cfg.sanact == NVME_SANITIZE_SANACT_EXIT_MEDIA_VERIF) {
nvme_show_error("SANACT is Exit Media Verification State");
return -EINVAL;
}
}

Expand All @@ -5260,7 +5270,9 @@ static int sanitize_cmd(int argc, char **argv, struct command *cmd, struct plugi
.nodas = cfg.no_dealloc,
.ovrpat = cfg.ovrpat,
.result = NULL,
.emvs = cfg.emvs,
};

err = nvme_cli_sanitize_nvm(dev, &args);
if (err < 0)
nvme_show_error("sanitize: %s", nvme_strerror(errno));
Expand Down

0 comments on commit bccdb63

Please sign in to comment.