]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme-cli: id-ctrl: Add vendor fields in JSON id-ctrl.
authorChaitanya Kulkarni <chaitanya.kulkarni@hgst.com>
Wed, 1 Mar 2017 02:14:07 +0000 (18:14 -0800)
committerKeith Busch <keith.busch@intel.com>
Wed, 1 Mar 2017 15:14:14 +0000 (10:14 -0500)
As a part of the id-ctrl command vendor specific callback is issued.
This patch allows the vendor-specific callback to print the extended
vendor unique (ctrl->vs) information from identify controller
data structure in the JSON format. It also enables id-ctrl command
to print vendor specific fields along with generic id-ctrl fields
in one JSON object. This modifies Intel plug-in which is the only
one uses extended id-ctrl (cs->vs) information in current
implementation.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@hgst.com>
intel-nvme.c
nvme-print.c
nvme-print.h
nvme.c
nvme.h

index 1863e7bfb254ce4983aea8c3bbd3867c421ce998..df0155a815fb5ef04fb7c8ae8b5c9152b07c36c6 100644 (file)
@@ -12,6 +12,7 @@
 #include "nvme.h"
 #include "nvme-print.h"
 #include "nvme-ioctl.h"
+#include "json.h"
 #include "plugin.h"
 
 #include "argconfig.h"
@@ -20,7 +21,7 @@
 #define CREATE_CMD
 #include "intel-nvme.h"
 
-static void intel_id_ctrl(__u8 *vs)
+static void intel_id_ctrl(__u8 *vs, struct json_object *root)
 {
        char bl[9];
         char health[21];
@@ -28,12 +29,18 @@ static void intel_id_ctrl(__u8 *vs)
        memcpy(bl, &vs[28], sizeof(bl));
        memcpy(health, &vs[4], sizeof(health));
 
-        bl[sizeof(bl) - 1] = '\0';
-        health[sizeof(health) - 1] = '\0';
-
-       printf("ss      : %d\n", vs[3]);
-       printf("health  : %s\n", health[0] ? health : "healthy");
-       printf("bl      : %s\n", bl);
+       bl[sizeof(bl) - 1] = '\0';
+       health[sizeof(health) - 1] = '\0';
+
+       if (root) {
+               json_object_add_value_int(root, "ss", vs[3]);
+               json_object_add_value_string(root, "health", health[0] ? health : "healthy");
+               json_object_add_value_string(root, "bl", bl);
+       } else {
+               printf("ss      : %d\n", vs[3]);
+               printf("health  : %s\n", health[0] ? health : "healthy");
+               printf("bl      : %s\n", bl);
+       }
 }
 
 static int id_ctrl(int argc, char **argv, struct command *cmd, struct plugin *plugin)
index 526efd4d8b1250c621173805d5825fbeebd4f6eb..6f40303c22c6223189ba4316db68e204dc398a62 100644 (file)
@@ -590,7 +590,7 @@ static void show_nvme_id_ctrl_power(struct nvme_id_ctrl *ctrl)
        }
 }
 
-void __show_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode, void (*vendor_show)(__u8 *vs))
+void __show_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode, void (*vendor_show)(__u8 *vs, struct json_object *root))
 {
        int human = mode & HUMAN, vs = mode & VS;
 
@@ -675,7 +675,7 @@ void __show_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode, void (*ve
 
        show_nvme_id_ctrl_power(ctrl);
        if (vendor_show)
-               vendor_show(ctrl->vs);
+               vendor_show(ctrl->vs, NULL);
        else if (vs) {
                printf("vs[]:\n");
                d(ctrl->vs, sizeof(ctrl->vs), 16, 1);
@@ -1262,7 +1262,7 @@ void json_nvme_id_ns(struct nvme_id_ns *ns, unsigned int mode)
        json_free_object(root);
 }
 
-void json_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode)
+void json_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode, void (*vs)(__u8 *vs, struct json_object *root))
 {
        struct json_object *root;
        struct json_array *psds;
@@ -1356,6 +1356,8 @@ void json_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode)
                json_array_add_value_object(psds, psd);
        }
 
+       if(vs)
+               vs(ctrl->vs, root);
        json_print_object(root, NULL);
        printf("\n");
        json_free_object(root);
index 6a9e77fe7999480c12590c03d0a040d9f1559f2e..f5e4c8f4d157f02b0c90fadc4589adc34e31967e 100644 (file)
@@ -2,6 +2,7 @@
 #define NVME_PRINT_H
 
 #include "nvme.h"
+#include "json.h"
 #include <inttypes.h>
 
 enum {
@@ -16,7 +17,7 @@ void d_raw(unsigned char *buf, unsigned len);
 
 uint64_t int48_to_long(__u8 *data);
 
-void __show_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode, void (*vendor_show)(__u8 *vs));
+void __show_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode, void (*vendor_show)(__u8 *vs, struct json_object *root));
 void show_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode);
 void show_nvme_id_ns(struct nvme_id_ns *ns, unsigned int flags);
 void show_nvme_resv_report(struct nvme_reservation_status *status);
@@ -32,7 +33,7 @@ char *nvme_status_to_string(__u32 status);
 char *nvme_select_to_string(int sel);
 char *nvme_feature_to_string(int feature);
 
-void json_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode);
+void json_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode, void (*vendor_show)(__u8 *vs, struct json_object *root));
 void json_nvme_id_ns(struct nvme_id_ns *ns, unsigned int flags);
 void json_nvme_resv_report(struct nvme_reservation_status *status);
 void json_error_log(struct nvme_error_log_page *err_log, int entries, const char *devname);
diff --git a/nvme.c b/nvme.c
index a6651ca52c6649fb44020bb4fe07abf30d0208d6..246736d1153658a8f8fa49c431ec46e752ced0b6 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -883,7 +883,7 @@ static int get_nsid(int fd)
        return nsid;
 }
 
-int __id_ctrl(int argc, char **argv, struct command *cmd, struct plugin *plugin, void (*vs)(__u8 *vs))
+int __id_ctrl(int argc, char **argv, struct command *cmd, struct plugin *plugin, void (*vs)(__u8 *vs, struct json_object *root))
 {
        const char *desc = "Send an Identify Controller command to "\
                "the given device and report information about the specified "\
@@ -936,7 +936,7 @@ int __id_ctrl(int argc, char **argv, struct command *cmd, struct plugin *plugin,
                if (fmt == BINARY)
                        d_raw((unsigned char *)&ctrl, sizeof(ctrl));
                else if (fmt == JSON)
-                       json_nvme_id_ctrl(&ctrl, flags);
+                       json_nvme_id_ctrl(&ctrl, flags, vs);
                else {
                        printf("NVME Identify Controller:\n");
                        __show_nvme_id_ctrl(&ctrl, flags, vs);
diff --git a/nvme.h b/nvme.h
index 5481916f87a826dc9ffab52561ee065aca981b37..d3d8a93a00d6b3d46da4e688e75d84c4f10c0fb9 100644 (file)
--- a/nvme.h
+++ b/nvme.h
@@ -18,6 +18,7 @@
 #include <stdbool.h>
 #include <endian.h>
 #include "plugin.h"
+#include "json.h"
 
 #define unlikely(x) x
 #include "linux/nvme.h"
@@ -156,6 +157,6 @@ int parse_and_open(int argc, char **argv, const char *desc,
 
 extern const char *devicename;
 
-int __id_ctrl(int argc, char **argv, struct command *cmd, struct plugin *plugin, void (*vs)(__u8 *vs));
+int __id_ctrl(int argc, char **argv, struct command *cmd, struct plugin *plugin, void (*vs)(__u8 *vs, struct json_object *root));
 
 #endif /* _NVME_H */