]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
Different file handle for metadata
authorKeith Busch <keith.busch@intel.com>
Wed, 14 Oct 2015 19:19:47 +0000 (13:19 -0600)
committerKeith Busch <keith.busch@intel.com>
Wed, 14 Oct 2015 19:19:47 +0000 (13:19 -0600)
Allow a user to specify a different file for metadata rather than assume
it is contigous with the data.

Signed-off-by: Keith Busch <keith.busch@intel.com>
Documentation/nvme-read.txt
Documentation/nvme-write.txt
nvme.c

index c08c53bf166895a1711fa56c3f49532771bc5f73..cd2f75ee95c0c1189c36cd82d6899ba00b356266 100644 (file)
@@ -14,6 +14,7 @@ SYNOPSIS
                        [--metadata-size=<size> | -y <size>]
                        [--ref-tag=<reftag> | -r <reftag>]
                        [--data=<data-file> | -d <data-file>]
+                       [--metadata=<metadata-file> | -M <metadata-file>]
                        [--prinfo=<prinfo> | -p <prinfo>]
                        [--app-tag-mask=<appmask> | -m <appmask>]
                        [--app-tag=<apptag> | -a <apptag>]
index d927bd6b4780c1e1b589e22e06eab6326a9452e9..f03e76173837b39356292531b66173ab1dbd1fe9 100644 (file)
@@ -14,6 +14,7 @@ SYNOPSIS
                        [--metadata-size=<size> | -y <size>]
                        [--ref-tag=<reftag> | -r <reftag>]
                        [--data=<data-file> | -d <data-file>]
+                       [--metadata=<metadata-file> | -M <metadata-file>]
                        [--prinfo=<prinfo> | -p <prinfo>]
                        [--app-tag-mask=<appmask> | -m <appmask>]
                        [--app-tag=<apptag> | -a <apptag>]
diff --git a/nvme.c b/nvme.c
index 52a6ffc1d281617af5f1cba59b9c750a2eff4140..182b5aa59f64203d08d4f264f30362ec7afdcf93 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -3144,14 +3144,18 @@ static int submit_io(int opcode, char *command, const char *desc,
        struct nvme_user_io io;
        struct timeval start_time, end_time;
        void *buffer, *mbuffer = NULL;
-       int err = 0, dfd = opcode & 1 ? STDIN_FILENO : STDOUT_FILENO;
+       int err = 0;
+       int dfd, mfd;
+       int flags = opcode & 1 ? O_RDONLY : O_WRONLY | O_CREAT;
+       int mode = S_IRUSR | S_IWUSR |S_IRGRP | S_IWGRP| S_IROTH;
 
        const char *start_block = "64-bit addr of first block to access";
        const char *block_count = "number of blocks on device to access";
        const char *data_size = "size of data in bytes";
        const char *metadata_size = "size of metadata in bytes";
        const char *ref_tag = "reference tag (for end to end PI)";
-       const char *data = "file";
+       const char *data = "data file";
+       const char *metadata = "metadata file";
        const char *prinfo = "PI and check field";
        const char *app_tag_mask = "app tag mask (for end to end PI)";
        const char *app_tag = "app tag (for end to end PI)";
@@ -3168,6 +3172,7 @@ static int submit_io(int opcode, char *command, const char *desc,
                __u32 metadata_size;
                __u32 ref_tag;
                char  *data;
+               char  *metadata;
                __u8  prinfo;
                __u8  app_tag_mask;
                __u32 app_tag;
@@ -3186,6 +3191,7 @@ static int submit_io(int opcode, char *command, const char *desc,
                .metadata_size   = 0,
                .ref_tag         = 0,
                .data            = "",
+               .metadata        = "",
                .prinfo          = 0,
                .app_tag_mask    = 0,
                .app_tag         = 0,
@@ -3204,6 +3210,8 @@ static int submit_io(int opcode, char *command, const char *desc,
                {"r",                 "NUM",  CFG_POSITIVE,    &defaults.ref_tag,           required_argument, ref_tag},
                {"data",              "FILE", CFG_STRING,      &defaults.data,              required_argument, data},
                {"d",                 "FILE", CFG_STRING,      &defaults.data,              required_argument, data},
+               {"metadata",          "FILE", CFG_STRING,      &defaults.metadata,          required_argument, metadata},
+               {"M",                 "FILE", CFG_STRING,      &defaults.metadata,          required_argument, metadata},
                {"prinfo",            "NUM",  CFG_BYTE,        &defaults.prinfo,            required_argument, prinfo},
                {"p",                 "NUM",  CFG_BYTE,        &defaults.prinfo,            required_argument, prinfo},
                {"app-tag-mask",      "NUM",  CFG_BYTE,        &defaults.app_tag_mask,      required_argument, app_tag_mask},
@@ -3223,6 +3231,7 @@ static int submit_io(int opcode, char *command, const char *desc,
                {0}
        };
 
+       dfd = mfd = opcode & 1 ? STDIN_FILENO : STDOUT_FILENO;
        argconfig_parse(argc, argv, desc, command_line_options,
                        &defaults, &cfg, sizeof(cfg));
 
@@ -3241,15 +3250,19 @@ static int submit_io(int opcode, char *command, const char *desc,
        if (cfg.force_unit_access)
                io.control |= NVME_RW_FUA;
        if (strlen(cfg.data)){
-               if (opcode & 1)
-                       dfd = open(cfg.data, O_RDONLY);
-               else
-                       dfd = open(cfg.data, O_WRONLY | O_CREAT,
-                                  S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP| S_IROTH);
+               dfd = open(cfg.data, flags, mode);
                if (dfd < 0) {
                        perror(cfg.data);
                        return EINVAL;
                }
+               mfd = dfd;
+       }
+       if (strlen(cfg.metadata)){
+               mfd = open(cfg.metadata, flags, mode);
+               if (mfd < 0) {
+                       perror(cfg.data);
+                       return EINVAL;
+               }
        }
        get_dev(1, argc, argv);
 
@@ -3264,7 +3277,8 @@ static int submit_io(int opcode, char *command, const char *desc,
                fprintf(stderr, "failed to read data buffer from input file\n");
                return EINVAL;
        }
-       if ((opcode & 1) && cfg.metadata_size && read(dfd, (void *)mbuffer, cfg.metadata_size) < 0) {
+       if ((opcode & 1) && cfg.metadata_size &&
+                               read(mfd, (void *)mbuffer, cfg.metadata_size) < 0) {
                fprintf(stderr, "failed to read meta-data buffer from input file\n");
                return EINVAL;
        }
@@ -3304,6 +3318,10 @@ static int submit_io(int opcode, char *command, const char *desc,
                if (!(opcode & 1) && write(dfd, (void *)buffer, cfg.data_size) < 0) {
                        fprintf(stderr, "failed to write buffer to output file\n");
                        return EINVAL;
+               } else if (!(opcode & 1) && cfg.metadata_size &&
+                               write(mfd, (void *)mbuffer, cfg.metadata_size) < 0) {
+                       fprintf(stderr, "failed to write meta-data buffer to output file\n");
+                       return EINVAL;
                } else
                        printf("%s: success\n", command);
        }