]> www.infradead.org Git - users/hch/nvme-cli.git/commitdiff
Add print for directive receive
authorKeith Busch <kbusch@kernel.org>
Tue, 29 Oct 2019 14:28:20 +0000 (23:28 +0900)
committerKeith Busch <kbusch@kernel.org>
Thu, 7 Nov 2019 23:01:39 +0000 (08:01 +0900)
Signed-off-by: Keith Busch <kbusch@kernel.org>
nvme-print.c
nvme-print.h
nvme.c

index 3a4be3a4e46a1b05e3e6f63dc8deb25eba90b613..4e64b0bbbfbfdcddb347413a1979fe2eb62bd127 100644 (file)
@@ -3820,10 +3820,11 @@ static void nvme_show_host_mem_buffer(struct nvme_host_mem_buffer *hmb)
        printf("\tHost Memory Buffer Size                  (HSIZE): %u\n", hmb->hsize);
 }
 
-void nvme_directive_show_fields(__u8 dtype, __u8 doper, unsigned int result, unsigned char *buf)
+static void nvme_directive_show_fields(__u8 dtype, __u8 doper, unsigned int result, unsigned char *buf)
 {
         __u8 *field = buf;
         int count, i;
+
         switch (dtype) {
         case NVME_DIR_IDENTIFY:
                 switch (doper) {
@@ -3871,6 +3872,23 @@ void nvme_directive_show_fields(__u8 dtype, __u8 doper, unsigned int result, uns
         return;
 }
 
+void nvme_directive_show(__u8 type, __u8 oper, __u16 spec, __u32 nsid, __u32 result,
+       void *buf, __u32 len, enum nvme_print_flags flags)
+{
+       if (flags & BINARY) {
+               if (buf)
+                       return d_raw(buf, len);
+               return;
+       }
+
+       printf("dir-receive: type:%#x operation:%#x spec:%#x nsid:%#x result:%#x\n",
+               type, oper, spec, nsid, result);
+       if (flags & VERBOSE)
+               nvme_directive_show_fields(type, oper, result, buf);
+       else if (buf)
+               d(buf, len, 16, 1);
+}
+
 static const char *nvme_plm_window(__u32 plm)
 {
        switch (plm & 0x7) {
index 6b78078bf2ed2898da84acdb7f1e1f13186e1ca8..29f09829f0c7a75a2dbee3801cbe3af494e084ee 100644 (file)
@@ -55,7 +55,8 @@ void nvme_show_id_uuid_list(const struct nvme_id_uuid_list *uuid_list,
        enum nvme_print_flags flags);
 
 void nvme_feature_show_fields(__u32 fid, unsigned int result, unsigned char *buf);
-void nvme_directive_show_fields(__u8 dtype, __u8 doper, unsigned int result, unsigned char *buf);
+void nvme_directive_show(__u8 type, __u8 oper, __u16 spec, __u32 nsid, __u32 result,
+       void *buf, __u32 len, enum nvme_print_flags flags);
 void nvme_show_select_result(__u32 result);
 
 const char *nvme_status_to_string(__u32 status);
diff --git a/nvme.c b/nvme.c
index 997251bbc53b9c682ff02899216f74cdda637eb3..30450efbf2a52a58691cddf99c0fa32c6b1e2bf0 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -4459,6 +4459,8 @@ static int dir_receive(int argc, char **argv, struct command *cmd, struct plugin
        const char *doper = "directive operation";
        const char *nsr = "namespace stream requested";
        const char *human_readable = "show directive in readable format";
+
+       enum nvme_print_flags flags = NORMAL;
        int err, fd;
        __u32 result;
        __u32 dw12 = 0;
@@ -4500,6 +4502,11 @@ static int dir_receive(int argc, char **argv, struct command *cmd, struct plugin
        if (fd < 0)
                goto ret;
 
+       if (cfg.human_readable)
+               flags |= VERBOSE;
+       if (cfg.raw_binary)
+               flags = BINARY;
+
        switch (cfg.dtype) {
        case NVME_DIR_IDENTIFY:
                switch (cfg.doper) {
@@ -4548,28 +4555,15 @@ static int dir_receive(int argc, char **argv, struct command *cmd, struct plugin
 
        err = nvme_dir_recv(fd, cfg.namespace_id, cfg.dspec, cfg.dtype, cfg.doper,
                        cfg.data_len, dw12, buf, &result);
-       if (err < 0) {
-               perror("dir-receive");
-               goto free;
-       }
-
-       if (!err) {
-               printf("dir-receive: type %#x, operation %#x, spec %#x, nsid %#x, result %#x \n",
-                               cfg.dtype, cfg.doper, cfg.dspec, cfg.namespace_id, result);
-               if (cfg.human_readable)
-                       nvme_directive_show_fields(cfg.dtype, cfg.doper, result, buf);
-               else {
-                       if (buf) {
-                               if (!cfg.raw_binary)
-                                       d(buf, cfg.data_len, 16, 1);
-                               else
-                                       d_raw(buf, cfg.data_len);
-                       }
-               }
-       }
+       if (!err)
+               nvme_directive_show(cfg.dtype, cfg.doper, cfg.dspec,
+                                   cfg.namespace_id, result, buf, cfg.data_len,
+                                   flags);
        else if (err > 0)
                nvme_show_status(err);
-free:
+       else if (err < 0)
+               perror("dir-receive");
+
        if (cfg.data_len)
                free(buf);
 close_fd:
@@ -4765,14 +4759,12 @@ static int passthru(int argc, char **argv, int ioctl_cmd, const char *desc, stru
                } else if (data && cfg.read)
                        d_raw((unsigned char *)data, cfg.data_len);
        }
-
 free_data:
        if (cfg.data_len)
                nvme_free(data, huge);
 free_metadata:
        if (cfg.metadata_len)
                free(metadata);
-
 close_wfd:
        if (strlen(cfg.input_file))
                close(wfd);
@@ -4864,7 +4856,6 @@ static int disconnect_all_cmd(int argc, char **argv, struct command *command, st
 void register_extension(struct plugin *plugin)
 {
        plugin->parent = &nvme;
-
        nvme.extensions->tail->next = plugin;
        nvme.extensions->tail = plugin;
 }