From 063639877818c1d08c1cce47fe7f1949d3ee65aa Mon Sep 17 00:00:00 2001 From: Randy Bates Date: Thu, 30 Apr 2020 16:20:34 -0500 Subject: [PATCH] Initial coding --- plugins/wdc/wdc-nvme.c | 31 +++++++++++++++++++++++++++++++ plugins/wdc/wdc-nvme.h | 1 + 2 files changed, 32 insertions(+) diff --git a/plugins/wdc/wdc-nvme.c b/plugins/wdc/wdc-nvme.c index 791353b..548e14c 100644 --- a/plugins/wdc/wdc-nvme.c +++ b/plugins/wdc/wdc-nvme.c @@ -570,6 +570,8 @@ static int wdc_log_page_directory(int argc, char **argv, struct command *command static int wdc_do_drive_info(int fd, __u32 *result); static int wdc_vs_drive_info(int argc, char **argv, struct command *command, struct plugin *plugin); +static int wdc_vs_temperature_stats(int argc, char **argv, struct command *command, + struct plugin *plugin); /* Drive log data size */ struct wdc_log_size { @@ -6543,5 +6545,34 @@ static int wdc_vs_drive_info(int argc, char **argv, fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); return ret; } +static int wdc_vs_temperature_stats(int argc, char **argv, + struct command *command, struct plugin *plugin) +{ + const char *desc = "Send a vs-temperature-stats command."; + struct nvme_smart_log smart_log; + int fd, ret; + /* convert temperature from Kelvin to Celsius */ + + OPT_ARGS(opts) = { + OPT_END() + }; + fd = parse_and_open(argc, argv, desc, opts); + if (fd < 0) + return fd; + wdc_check_device(fd); + ret = nvme_smart_log(fd, NVME_NSID_ALL, &smart_log); + + if (ret == 0) { + int temperature = ((smart_log.temperature[1] << 8) | + smart_log.temperature[0]) - 273; + + printf("temperature : %d C\n", + temperature); + + } + + fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + return ret; +} diff --git a/plugins/wdc/wdc-nvme.h b/plugins/wdc/wdc-nvme.h index c6b2d3f..9c8e222 100644 --- a/plugins/wdc/wdc-nvme.h +++ b/plugins/wdc/wdc-nvme.h @@ -30,6 +30,7 @@ PLUGIN(NAME("wdc", "Western Digital vendor specific extensions"), ENTRY("log-page-directory", "WDC Get Log Page Directory", wdc_log_page_directory) ENTRY("namespace-resize", "WDC NamespaceDrive Resize", wdc_namespace_resize) ENTRY("vs-drive-info", "WDC Get Drive Info", wdc_vs_drive_info) + ENTRY("vs-temperature-stats", "WDC Get Temperature Stats", wdc_vs_temperature_stats) ) ); -- 2.49.0