Skip to content

Commit 7209089

Browse files
committed
nvme: add --block-size option to io commands to bypass identify commands.
When specified, the --block-size is used as the logical block size in bytes, and the --metadata-size is used as the metadata size in bytes. Signed-off-by: Nate Thornton <[email protected]>
1 parent 5d8902a commit 7209089

File tree

1 file changed

+43
-32
lines changed

1 file changed

+43
-32
lines changed

nvme.c

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8188,6 +8188,8 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char
81888188
__u16 ms;
81898189

81908190
const char *start_block_addr = "64-bit addr of first block to access";
8191+
const char *block_size = "if specified, logical block size in bytes;\n"
8192+
"discovered by identify namespace otherwise";
81918193
const char *data_size = "size of data in bytes";
81928194
const char *metadata_size = "size of metadata in bytes";
81938195
const char *data = "data file";
@@ -8205,6 +8207,7 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char
82058207
__u32 namespace_id;
82068208
__u64 start_block;
82078209
__u16 block_count;
8210+
__u16 block_size;
82088211
__u64 data_size;
82098212
__u64 metadata_size;
82108213
__u64 ref_tag;
@@ -8229,6 +8232,7 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char
82298232
.namespace_id = 0,
82308233
.start_block = 0,
82318234
.block_count = 0,
8235+
.block_size = 0,
82328236
.data_size = 0,
82338237
.metadata_size = 0,
82348238
.ref_tag = 0,
@@ -8253,6 +8257,7 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char
82538257
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id_desired),
82548258
OPT_SUFFIX("start-block", 's', &cfg.start_block, start_block_addr),
82558259
OPT_SHRT("block-count", 'c', &cfg.block_count, block_count),
8260+
OPT_SHRT("block-size", 'b', &cfg.block_size, block_size),
82568261
OPT_SUFFIX("data-size", 'z', &cfg.data_size, data_size),
82578262
OPT_SUFFIX("metadata-size", 'y', &cfg.metadata_size, metadata_size),
82588263
OPT_SUFFIX("ref-tag", 'r', &cfg.ref_tag, ref_tag),
@@ -8353,40 +8358,49 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char
83538358
return -EINVAL;
83548359
}
83558360

8356-
ns = nvme_alloc(sizeof(*ns));
8357-
if (!ns)
8358-
return -ENOMEM;
8359-
8360-
err = nvme_cli_identify_ns(dev, cfg.namespace_id, ns);
8361-
if (err > 0) {
8362-
nvme_show_status(err);
8363-
return err;
8364-
} else if (err < 0) {
8365-
nvme_show_error("identify namespace: %s", nvme_strerror(errno));
8366-
return err;
8361+
if (cfg.block_size) {
8362+
logical_block_size = cfg.block_size;
8363+
ms = cfg.metadata_size;
83678364
}
8365+
else {
8366+
ns = nvme_alloc(sizeof(*ns));
8367+
if (!ns)
8368+
return -ENOMEM;
83688369

8369-
nvme_id_ns_flbas_to_lbaf_inuse(ns->flbas, &lba_index);
8370-
logical_block_size = 1 << ns->lbaf[lba_index].ds;
8371-
ms = le16_to_cpu(ns->lbaf[lba_index].ms);
8370+
err = nvme_cli_identify_ns(dev, cfg.namespace_id, ns);
8371+
if (err > 0) {
8372+
nvme_show_status(err);
8373+
return err;
8374+
} else if (err < 0) {
8375+
nvme_show_error("identify namespace: %s", nvme_strerror(errno));
8376+
return err;
8377+
}
83728378

8373-
nvm_ns = nvme_alloc(sizeof(*nvm_ns));
8374-
if (!nvm_ns)
8375-
return -ENOMEM;
8379+
nvme_id_ns_flbas_to_lbaf_inuse(ns->flbas, &lba_index);
8380+
logical_block_size = 1 << ns->lbaf[lba_index].ds;
8381+
ms = le16_to_cpu(ns->lbaf[lba_index].ms);
83768382

8377-
err = nvme_identify_ns_csi(dev_fd(dev), cfg.namespace_id, 0, NVME_CSI_NVM, nvm_ns);
8378-
if (!err)
8379-
get_pif_sts(ns, nvm_ns, &pif, &sts);
8383+
nvm_ns = nvme_alloc(sizeof(*nvm_ns));
8384+
if (!nvm_ns)
8385+
return -ENOMEM;
83808386

8381-
pi_size = (pif == NVME_NVM_PIF_16B_GUARD) ? 8 : 16;
8382-
if (NVME_FLBAS_META_EXT(ns->flbas)) {
8383-
/*
8384-
* No meta data is transferred for PRACT=1 and MD=PI size:
8385-
* 5.2.2.1 Protection Information and Write Commands
8386-
* 5.2.2.2 Protection Information and Read Commands
8387-
*/
8388-
if (!((cfg.prinfo & 0x8) != 0 && ms == pi_size))
8389-
logical_block_size += ms;
8387+
err = nvme_identify_ns_csi(dev_fd(dev), cfg.namespace_id, 0, NVME_CSI_NVM, nvm_ns);
8388+
if (!err)
8389+
get_pif_sts(ns, nvm_ns, &pif, &sts);
8390+
8391+
pi_size = (pif == NVME_NVM_PIF_16B_GUARD) ? 8 : 16;
8392+
if (NVME_FLBAS_META_EXT(ns->flbas)) {
8393+
/*
8394+
* No meta data is transferred for PRACT=1 and MD=PI size:
8395+
* 5.2.2.1 Protection Information and Write Commands
8396+
* 5.2.2.2 Protection Information and Read Commands
8397+
*/
8398+
if (!((cfg.prinfo & 0x8) != 0 && ms == pi_size))
8399+
logical_block_size += ms;
8400+
}
8401+
8402+
if (invalid_tags(cfg.storage_tag, cfg.ref_tag, sts, pif))
8403+
return -EINVAL;
83908404
}
83918405

83928406
buffer_size = ((long long)cfg.block_count + 1) * logical_block_size;
@@ -8426,9 +8440,6 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char
84268440
memset(mbuffer, 0, mbuffer_size);
84278441
}
84288442

8429-
if (invalid_tags(cfg.storage_tag, cfg.ref_tag, sts, pif))
8430-
return -EINVAL;
8431-
84328443
if (opcode & 1) {
84338444
err = read(dfd, (void *)buffer, cfg.data_size);
84348445
if (err < 0) {

0 commit comments

Comments
 (0)