summaryrefslogtreecommitdiffstats
path: root/plugins/virtium/virtium-nvme.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/virtium/virtium-nvme.c')
-rw-r--r--plugins/virtium/virtium-nvme.c71
1 files changed, 30 insertions, 41 deletions
diff --git a/plugins/virtium/virtium-nvme.c b/plugins/virtium/virtium-nvme.c
index b8cefe6..c8df126 100644
--- a/plugins/virtium/virtium-nvme.c
+++ b/plugins/virtium/virtium-nvme.c
@@ -14,6 +14,7 @@
#include "nvme.h"
#include "libnvme.h"
#include "plugin.h"
+#include "util/types.h"
#define CREATE_CMD
#include "virtium-nvme.h"
@@ -51,18 +52,6 @@ struct vtview_save_log_settings {
const char* test_name;
};
-static long double int128_to_double(__u8 *data)
-{
- int i;
- long double result = 0;
-
- for (i = 0; i < 16; i++) {
- result *= 256;
- result += data[15 - i];
- }
- return result;
-}
-
static void vt_initialize_header_buffer(struct vtview_log_header *pbuff)
{
memset(pbuff->path, 0, sizeof(pbuff->path));
@@ -151,25 +140,25 @@ static void vt_convert_smart_data_to_human_readable_format(struct vtview_smart_l
strcat(text, tempbuff);
snprintf(tempbuff, sizeof(tempbuff), "Percentage_Used;%u;", smart->raw_smart.percent_used);
strcat(text, tempbuff);
- snprintf(tempbuff, sizeof(tempbuff), "Data_Units_Read;%0.Lf;", int128_to_double(smart->raw_smart.data_units_read));
+ snprintf(tempbuff, sizeof(tempbuff), "Data_Units_Read;%s;", uint128_t_to_string(le128_to_cpu(smart->raw_smart.data_units_read)));
strcat(text, tempbuff);
- snprintf(tempbuff, sizeof(tempbuff), "Data_Units_Written;%0.Lf;", int128_to_double(smart->raw_smart.data_units_written));
+ snprintf(tempbuff, sizeof(tempbuff), "Data_Units_Written;%s;", uint128_t_to_string(le128_to_cpu(smart->raw_smart.data_units_written)));
strcat(text, tempbuff);
- snprintf(tempbuff, sizeof(tempbuff), "Host_Read_Commands;%0.Lf;", int128_to_double(smart->raw_smart.host_reads));
+ snprintf(tempbuff, sizeof(tempbuff), "Host_Read_Commands;%s;", uint128_t_to_string(le128_to_cpu(smart->raw_smart.host_reads)));
strcat(text, tempbuff);
- snprintf(tempbuff, sizeof(tempbuff), "Host_Write_Commands;%0.Lf;", int128_to_double(smart->raw_smart.host_writes));
+ snprintf(tempbuff, sizeof(tempbuff), "Host_Write_Commands;%s;", uint128_t_to_string(le128_to_cpu(smart->raw_smart.host_writes)));
strcat(text, tempbuff);
- snprintf(tempbuff, sizeof(tempbuff), "Controller_Busy_Time;%0.Lf;", int128_to_double(smart->raw_smart.ctrl_busy_time));
+ snprintf(tempbuff, sizeof(tempbuff), "Controller_Busy_Time;%s;", uint128_t_to_string(le128_to_cpu(smart->raw_smart.ctrl_busy_time)));
strcat(text, tempbuff);
- snprintf(tempbuff, sizeof(tempbuff), "Power_Cycles;%0.Lf;", int128_to_double(smart->raw_smart.power_cycles));
+ snprintf(tempbuff, sizeof(tempbuff), "Power_Cycles;%s;", uint128_t_to_string(le128_to_cpu(smart->raw_smart.power_cycles)));
strcat(text, tempbuff);
- snprintf(tempbuff, sizeof(tempbuff), "Power_On_Hours;%0.Lf;", int128_to_double(smart->raw_smart.power_on_hours));
+ snprintf(tempbuff, sizeof(tempbuff), "Power_On_Hours;%s;", uint128_t_to_string(le128_to_cpu(smart->raw_smart.power_on_hours)));
strcat(text, tempbuff);
- snprintf(tempbuff, sizeof(tempbuff), "Unsafe_Shutdowns;%0.Lf;", int128_to_double(smart->raw_smart.unsafe_shutdowns));
+ snprintf(tempbuff, sizeof(tempbuff), "Unsafe_Shutdowns;%s;", uint128_t_to_string(le128_to_cpu(smart->raw_smart.unsafe_shutdowns)));
strcat(text, tempbuff);
- snprintf(tempbuff, sizeof(tempbuff), "Media_Errors;%0.Lf;", int128_to_double(smart->raw_smart.media_errors));
+ snprintf(tempbuff, sizeof(tempbuff), "Media_Errors;%s;", uint128_t_to_string(le128_to_cpu(smart->raw_smart.media_errors)));
strcat(text, tempbuff);
- snprintf(tempbuff, sizeof(tempbuff), "Num_Err_Log_Entries;%0.Lf;", int128_to_double(smart->raw_smart.num_err_log_entries));
+ snprintf(tempbuff, sizeof(tempbuff), "Num_Err_Log_Entries;%s;", uint128_t_to_string(le128_to_cpu(smart->raw_smart.num_err_log_entries)));
strcat(text, tempbuff);
snprintf(tempbuff, sizeof(tempbuff), "Warning_Temperature_Time;%u;", le32_to_cpu(smart->raw_smart.warning_temp_time));
strcat(text, tempbuff);
@@ -927,8 +916,7 @@ static void vt_parse_detail_identify(const struct nvme_id_ctrl *ctrl)
static int vt_save_smart_to_vtview_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
- int err = 0;
- int fd, ret;
+ int ret, err = 0;
long int total_time = 0;
long int freq_time = 0;
long int cur_time = 0;
@@ -949,6 +937,7 @@ static int vt_save_smart_to_vtview_log(int argc, char **argv, struct command *cm
const char *freq = "(optional) How often you want to log SMART data (0.25 = 15' , 0.5 = 30' , 1 = 1 hour, 2 = 2 hours, etc.). Default = 10 hours.";
const char *output_file = "(optional) Name of the log file (give it a name that easy for you to remember what the test is). You can leave it blank too, we will take care it for you.";
const char *test_name = "(optional) Name of the test you are doing. We use this as part of the name of the log file.";
+ struct nvme_dev *dev;
struct vtview_save_log_settings cfg = {
.run_time_hrs = 20,
@@ -975,10 +964,10 @@ static int vt_save_smart_to_vtview_log(int argc, char **argv, struct command *cm
strcpy(path, argv[1]);
}
- fd = parse_and_open(argc, argv, desc, opts);
- if (fd < 0) {
- printf("Error parse and open (fd = %d)\n", fd);
- return (fd);
+ err = parse_and_open(&dev, argc, argv, desc, opts);
+ if (err) {
+ printf("Error parse and open (err = %d)\n", err);
+ return err;
}
printf("Running...\n");
@@ -986,10 +975,10 @@ static int vt_save_smart_to_vtview_log(int argc, char **argv, struct command *cm
printf("Running for %lf hour(s)\n", cfg.run_time_hrs);
printf("Logging SMART data for every %lf hour(s)\n", cfg.log_record_frequency_hrs);
- ret = vt_update_vtview_log_header(fd, path, &cfg);
+ ret = vt_update_vtview_log_header(dev_fd(dev), path, &cfg);
if (ret) {
err = EINVAL;
- close(fd);
+ dev_close(dev);
return (err);
}
@@ -1009,7 +998,7 @@ static int vt_save_smart_to_vtview_log(int argc, char **argv, struct command *cm
if(cur_time >= end_time)
break;
- ret = vt_add_entry_to_log(fd, path, &cfg);
+ ret = vt_add_entry_to_log(dev_fd(dev), path, &cfg);
if (ret) {
printf("Cannot update driver log\n");
break;
@@ -1021,15 +1010,15 @@ static int vt_save_smart_to_vtview_log(int argc, char **argv, struct command *cm
fflush(stdout);
}
- close (fd);
+ dev_close(dev);
return (err);
}
static int vt_show_identify(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
- int err = 0;
- int fd ,ret;
+ int ret, err = 0;
struct nvme_id_ctrl ctrl;
+ struct nvme_dev *dev;
char *desc = "Parse identify data to json format\n\n"
"Typical usages:\n\n"
"virtium show-identify /dev/yourDevice\n";
@@ -1038,16 +1027,16 @@ static int vt_show_identify(int argc, char **argv, struct command *cmd, struct p
OPT_END()
};
- fd = parse_and_open(argc, argv, desc, opts);
- if (fd < 0) {
- printf("Error parse and open (fd = %d)\n", fd);
- return (fd);
+ err = parse_and_open(&dev, argc, argv, desc, opts);
+ if (err) {
+ printf("Error parse and open (err = %d)\n", err);
+ return err;
}
- ret = nvme_identify_ctrl(fd, &ctrl);
+ ret = nvme_identify_ctrl(dev_fd(dev), &ctrl);
if (ret) {
printf("Cannot read identify device\n");
- close (fd);
+ dev_close(dev);
return (-1);
}
@@ -1055,6 +1044,6 @@ static int vt_show_identify(int argc, char **argv, struct command *cmd, struct p
vt_process_string(ctrl.mn, sizeof(ctrl.mn));
vt_parse_detail_identify(&ctrl);
- close(fd);
+ dev_close(dev);
return (err);
}