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>
#include "nvme.h"
#include "nvme-print.h"
#include "nvme-ioctl.h"
+#include "json.h"
#include "plugin.h"
#include "argconfig.h"
#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];
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)
}
}
-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;
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);
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;
json_array_add_value_object(psds, psd);
}
+ if(vs)
+ vs(ctrl->vs, root);
json_print_object(root, NULL);
printf("\n");
json_free_object(root);
#define NVME_PRINT_H
#include "nvme.h"
+#include "json.h"
#include <inttypes.h>
enum {
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);
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);
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 "\
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);
#include <stdbool.h>
#include <endian.h>
#include "plugin.h"
+#include "json.h"
#define unlikely(x) x
#include "linux/nvme.h"
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 */