Skip to content

Commit 4d34796

Browse files
francispravin5igaw
authored andcommitted
nvme: add Namespace Zeroes support to Write Zeroes command
Added the Namespace Zeroes (NSZ) support to Write Zeroes command. Also, fixed the dtype limitation (bit 22:20). TP4160 - WZSL Limit Modification Signed-off-by: Francis Pravin <[email protected]> Reviewed-by: Steven Seungcheol Lee <[email protected]>
1 parent d035094 commit 4d34796

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

nvme.c

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6900,6 +6900,7 @@ static int write_zeroes(int argc, char **argv, struct command *cmd, struct plugi
69006900
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
69016901
__u8 sts = 0, pif = 0;
69026902
__u16 control = 0;
6903+
__u32 result = 0;
69036904
int err;
69046905

69056906
const char *desc =
@@ -6909,6 +6910,7 @@ static int write_zeroes(int argc, char **argv, struct command *cmd, struct plugi
69096910
const char *storage_tag_check =
69106911
"This bit specifies the Storage Tag field shall be checked as\n"
69116912
"part of end-to-end data protection processing";
6913+
const char *nsz = "Clear all logical blocks to zero in the entire namespace";
69126914

69136915
struct config {
69146916
__u32 namespace_id;
@@ -6925,23 +6927,25 @@ static int write_zeroes(int argc, char **argv, struct command *cmd, struct plugi
69256927
__u64 storage_tag;
69266928
bool storage_tag_check;
69276929
__u16 dspec;
6930+
bool nsz;
69286931
};
69296932

69306933
struct config cfg = {
69316934
.namespace_id = 0,
69326935
.start_block = 0,
69336936
.block_count = 0,
6934-
.dtype = 0,
6935-
.deac = false,
6937+
.dtype = 0,
6938+
.deac = false,
69366939
.limited_retry = false,
69376940
.force_unit_access = false,
6938-
.prinfo = 0,
6939-
.ref_tag = 0,
6941+
.prinfo = 0,
6942+
.ref_tag = 0,
69406943
.app_tag_mask = 0,
6941-
.app_tag = 0,
6944+
.app_tag = 0,
69426945
.storage_tag = 0,
69436946
.storage_tag_check = false,
6944-
.dspec = 0,
6947+
.dspec = 0,
6948+
.nsz = false,
69456949
};
69466950

69476951
NVME_ARGS(opts,
@@ -6958,7 +6962,8 @@ static int write_zeroes(int argc, char **argv, struct command *cmd, struct plugi
69586962
OPT_SHRT("app-tag", 'a', &cfg.app_tag, app_tag),
69596963
OPT_SUFFIX("storage-tag", 'S', &cfg.storage_tag, storage_tag),
69606964
OPT_FLAG("storage-tag-check", 'C', &cfg.storage_tag_check, storage_tag_check),
6961-
OPT_SHRT("dir-spec", 'D', &cfg.dspec, dspec_w_dtype));
6965+
OPT_SHRT("dir-spec", 'D', &cfg.dspec, dspec_w_dtype),
6966+
OPT_FLAG("namespace-zeroes", 'Z', &cfg.nsz, nsz));
69626967

69636968
err = parse_and_open(&dev, argc, argv, desc, opts);
69646969
if (err)
@@ -6967,7 +6972,7 @@ static int write_zeroes(int argc, char **argv, struct command *cmd, struct plugi
69676972
if (cfg.prinfo > 0xf)
69686973
return -EINVAL;
69696974

6970-
if (cfg.dtype > 0xf) {
6975+
if (cfg.dtype > 0x7) {
69716976
nvme_show_error("Invalid directive type, %x", cfg.dtype);
69726977
return -EINVAL;
69736978
}
@@ -6981,6 +6986,8 @@ static int write_zeroes(int argc, char **argv, struct command *cmd, struct plugi
69816986
control |= NVME_IO_DEAC;
69826987
if (cfg.storage_tag_check)
69836988
control |= NVME_IO_STC;
6989+
if (cfg.nsz)
6990+
control |= NVME_IO_NSZ;
69846991
control |= (cfg.dtype << 4);
69856992
if (!cfg.namespace_id) {
69866993
err = nvme_get_nsid(dev_fd(dev), &cfg.namespace_id);
@@ -7017,7 +7024,7 @@ static int write_zeroes(int argc, char **argv, struct command *cmd, struct plugi
70177024

70187025
struct nvme_io_args args = {
70197026
.args_size = sizeof(args),
7020-
.fd = dev_fd(dev),
7027+
.fd = dev_fd(dev),
70217028
.nsid = cfg.namespace_id,
70227029
.slba = cfg.start_block,
70237030
.nlb = cfg.block_count,
@@ -7030,15 +7037,22 @@ static int write_zeroes(int argc, char **argv, struct command *cmd, struct plugi
70307037
.storage_tag = cfg.storage_tag,
70317038
.dspec = cfg.dspec,
70327039
.timeout = nvme_cfg.timeout,
7033-
.result = NULL,
7040+
.result = &result,
70347041
};
70357042
err = nvme_write_zeros(&args);
70367043
if (err < 0)
70377044
nvme_show_error("write-zeroes: %s", nvme_strerror(errno));
70387045
else if (err != 0)
70397046
nvme_show_status(err);
7040-
else
7047+
else {
70417048
printf("NVME Write Zeroes Success\n");
7049+
if (cfg.nsz && argconfig_parse_seen(opts, "verbose")) {
7050+
if (result & 0x1)
7051+
printf("All logical blocks in the entire namespace cleared to zero\n");
7052+
else
7053+
printf("%d logical blocks cleared to zero\n", cfg.block_count);
7054+
}
7055+
}
70427056

70437057
return err;
70447058
}

0 commit comments

Comments
 (0)