summaryrefslogtreecommitdiffstats
path: root/plugins/scaleflux
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/scaleflux')
-rw-r--r--plugins/scaleflux/sfx-nvme.c78
1 files changed, 32 insertions, 46 deletions
diff --git a/plugins/scaleflux/sfx-nvme.c b/plugins/scaleflux/sfx-nvme.c
index df7f9a3..a6aaad5 100644
--- a/plugins/scaleflux/sfx-nvme.c
+++ b/plugins/scaleflux/sfx-nvme.c
@@ -6,21 +6,16 @@
#include <linux/fs.h>
#include <inttypes.h>
#include <asm/byteorder.h>
-#include <sys/ioctl.h>
#include <sys/sysinfo.h>
#include <sys/stat.h>
#include <unistd.h>
-#include "linux/nvme_ioctl.h"
-
+#include "common.h"
#include "nvme.h"
-#include "nvme-print.h"
-#include "nvme-ioctl.h"
-#include "nvme-status.h"
+#include "libnvme.h"
#include "plugin.h"
-
-#include "argconfig.h"
-#include "suffix.h"
+#include "linux/types.h"
+#include "nvme-print.h"
#define CREATE_CMD
#include "sfx-nvme.h"
@@ -114,38 +109,38 @@ struct nvme_additional_smart_log {
int nvme_change_cap(int fd, __u32 nsid, __u64 capacity)
{
- struct nvme_admin_cmd cmd = {
+ struct nvme_passthru_cmd cmd = {
.opcode = nvme_admin_change_cap,
.nsid = nsid,
.cdw10 = (capacity & 0xffffffff),
.cdw11 = (capacity >> 32),
};
- return nvme_submit_passthru(fd, NVME_IOCTL_ADMIN_CMD,&cmd);
+ return nvme_submit_admin_passthru(fd, &cmd, NULL);
}
int nvme_sfx_set_features(int fd, __u32 nsid, __u32 fid, __u32 value)
{
- struct nvme_admin_cmd cmd = {
+ struct nvme_passthru_cmd cmd = {
.opcode = nvme_admin_sfx_set_features,
.nsid = nsid,
.cdw10 = fid,
.cdw11 = value,
};
- return nvme_submit_passthru(fd, NVME_IOCTL_ADMIN_CMD,&cmd);
+ return nvme_submit_admin_passthru(fd, &cmd, NULL);
}
int nvme_sfx_get_features(int fd, __u32 nsid, __u32 fid, __u32 *result)
{
int err = 0;
- struct nvme_admin_cmd cmd = {
+ struct nvme_passthru_cmd cmd = {
.opcode = nvme_admin_sfx_get_features,
.nsid = nsid,
.cdw10 = fid,
};
- err = nvme_submit_passthru(fd, NVME_IOCTL_ADMIN_CMD,&cmd);
+ err = nvme_submit_admin_passthru(fd, &cmd, NULL);
if (!err && result) {
*result = cmd.result;
}
@@ -343,8 +338,8 @@ static int get_additional_smart_log(int argc, char **argv, struct command *cmd,
const char *json= "Dump output in json format";
struct config {
__u32 namespace_id;
- int raw_binary;
- int json;
+ bool raw_binary;
+ bool json;
};
struct config cfg = {
@@ -361,7 +356,7 @@ static int get_additional_smart_log(int argc, char **argv, struct command *cmd,
fd = parse_and_open(argc, argv, desc, opts);
- err = nvme_get_log(fd, cfg.namespace_id, 0xca, false, NVME_NO_LOG_LSP,
+ err = nvme_get_nsid_log(fd, false, 0xca, cfg.namespace_id,
sizeof(smart_log), (void *)&smart_log);
if (!err) {
if (cfg.json)
@@ -372,8 +367,7 @@ static int get_additional_smart_log(int argc, char **argv, struct command *cmd,
d_raw((unsigned char *)&smart_log, sizeof(smart_log));
}
else if (err > 0)
- fprintf(stderr, "NVMe Status:%s(%x)\n",
- nvme_status_to_string(err), err);
+ nvme_show_status(err);
return err;
}
@@ -428,8 +422,8 @@ static int get_lat_stats_log(int argc, char **argv, struct command *cmd, struct
const char *raw = "dump output in binary format";
const char *write = "Get write statistics (read default)";
struct config {
- int raw_binary;
- int write;
+ bool raw_binary;
+ bool write;
};
struct config cfg = {
@@ -443,22 +437,20 @@ static int get_lat_stats_log(int argc, char **argv, struct command *cmd, struct
fd = parse_and_open(argc, argv, desc, opts);
- err = nvme_get_log(fd, 0xffffffff, cfg.write ? 0xc3 : 0xc1, false, NVME_NO_LOG_LSP,
- sizeof(stats), (void *)&stats);
+ err = nvme_get_log_simple(fd, cfg.write ? 0xc3 : 0xc1, sizeof(stats), (void *)&stats);
if (!err) {
if (!cfg.raw_binary)
show_lat_stats(&stats, cfg.write);
else
d_raw((unsigned char *)&stats, sizeof(stats));
} else if (err > 0)
- fprintf(stderr, "NVMe Status:%s(%x)\n",
- nvme_status_to_string(err), err);
+ nvme_show_status(err);
return err;
}
int sfx_nvme_get_log(int fd, __u32 nsid, __u8 log_id, __u32 data_len, void *data)
{
- struct nvme_admin_cmd cmd = {
+ struct nvme_passthru_cmd cmd = {
.opcode = nvme_admin_get_log_page,
.nsid = nsid,
.addr = (__u64)(uintptr_t) data,
@@ -470,7 +462,7 @@ int sfx_nvme_get_log(int fd, __u32 nsid, __u8 log_id, __u32 data_len, void *data
cmd.cdw10 = log_id | (numdl << 16);
cmd.cdw11 = numdu;
- return nvme_submit_admin_passthru(fd, &cmd);
+ return nvme_submit_admin_passthru(fd, &cmd, NULL);
}
/**
@@ -583,8 +575,7 @@ static int sfx_get_bad_block(int argc, char **argv, struct command *cmd, struct
if (err < 0) {
perror("get-bad-block");
} else if (err != 0) {
- fprintf(stderr, "NVMe IO command error:%s(%x)\n",
- nvme_status_to_string(err), err);
+ nvme_show_status(err);
} else {
bd_table_show(data_buf, buf_size);
printf("ScaleFlux get bad block table: success\n");
@@ -616,8 +607,8 @@ static int query_cap_info(int argc, char **argv, struct command *cmd, struct plu
const char *raw = "dump output in binary format";
const char *json= "Dump output in json format";
struct config {
- int raw_binary;
- int json;
+ bool raw_binary;
+ bool json;
};
struct config cfg;
@@ -745,9 +736,9 @@ static int change_cap(int argc, char **argv, struct command *cmd, struct plugin
struct config {
__u64 cap_in_byte;
__u32 capacity_in_gb;
- int raw_binary;
- int json;
- int force;
+ bool raw_binary;
+ bool json;
+ bool force;
};
struct config cfg = {
@@ -790,8 +781,7 @@ static int change_cap(int argc, char **argv, struct command *cmd, struct plugin
if (err < 0)
perror("sfx-change-cap");
else if (err != 0)
- fprintf(stderr, "NVMe IO command error:%s(%x)\n",
- nvme_status_to_string(err), err);
+ nvme_show_status(err);
else {
printf("ScaleFlux change-capacity: success\n");
ioctl(fd, BLKRRPART);
@@ -863,7 +853,7 @@ static int sfx_set_feature(int argc, char **argv, struct command *cmd, struct pl
__u32 namespace_id;
__u32 feature_id;
__u32 value;
- __u32 force;
+ bool force;
};
struct config cfg = {
.namespace_id = 1,
@@ -902,14 +892,12 @@ static int sfx_set_feature(int argc, char **argv, struct command *cmd, struct pl
if (cfg.feature_id == SFX_FEAT_ATOMIC && cfg.value != 0) {
if (cfg.namespace_id != 0xffffffff) {
- err = nvme_identify_ns(fd, cfg.namespace_id, 0, &ns);
+ err = nvme_identify_ns(fd, cfg.namespace_id, &ns);
if (err) {
if (err < 0)
perror("identify-namespace");
else
- fprintf(stderr,
- "NVMe Admin command error:%s(%x)\n",
- nvme_status_to_string(err), err);
+ nvme_show_status(err);
return err;
}
/*
@@ -941,8 +929,7 @@ static int sfx_set_feature(int argc, char **argv, struct command *cmd, struct pl
printf("ScaleFlux set-feature:%#02x (%s), value:%d\n", cfg.feature_id,
sfx_feature_to_string(cfg.feature_id), cfg.value);
} else if (err > 0)
- fprintf(stderr, "NVMe Status:%s(%x)\n",
- nvme_status_to_string(err), err);
+ nvme_show_status(err);
return err;
}
@@ -990,8 +977,7 @@ static int sfx_get_feature(int argc, char **argv, struct command *cmd, struct pl
printf("ScaleFlux get-feature:%02x (%s), value:%d\n", cfg.feature_id,
sfx_feature_to_string(cfg.feature_id), result);
} else if (err > 0)
- fprintf(stderr, "NVMe Status:%s(%x)\n",
- nvme_status_to_string(err), err);
+ nvme_show_status(err);
return err;