summaryrefslogtreecommitdiffstats
path: root/plugins/scaleflux/sfx-nvme.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/scaleflux/sfx-nvme.c')
-rw-r--r--plugins/scaleflux/sfx-nvme.c149
1 files changed, 77 insertions, 72 deletions
diff --git a/plugins/scaleflux/sfx-nvme.c b/plugins/scaleflux/sfx-nvme.c
index 0740e43..a776664 100644
--- a/plugins/scaleflux/sfx-nvme.c
+++ b/plugins/scaleflux/sfx-nvme.c
@@ -398,17 +398,18 @@ static void show_sfx_smart_log(struct nvme_additional_smart_log *smart,
static int get_additional_smart_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
struct nvme_additional_smart_log smart_log;
- int err, fd;
char *desc = "Get ScaleFlux vendor specific additional smart log (optionally, "\
"for the specified namespace), and show it.";
const char *namespace = "(optional) desired namespace";
const char *raw = "dump output in binary format";
const char *json= "Dump output in json format";
+ struct nvme_dev *dev;
struct config {
__u32 namespace_id;
bool raw_binary;
bool json;
};
+ int err;
struct config cfg = {
.namespace_id = 0xffffffff,
@@ -422,24 +423,25 @@ static int get_additional_smart_log(int argc, char **argv, struct command *cmd,
};
- fd = parse_and_open(argc, argv, desc, opts);
- if (fd < 0) {
- return fd;
- }
+ err = parse_and_open(&dev, argc, argv, desc, opts);
+ if (err)
+ return err;
- err = nvme_get_nsid_log(fd, false, 0xca, cfg.namespace_id,
- sizeof(smart_log), (void *)&smart_log);
+ err = nvme_get_nsid_log(dev_fd(dev), false, 0xca, cfg.namespace_id,
+ sizeof(smart_log), (void *)&smart_log);
if (!err) {
if (cfg.json)
- show_sfx_smart_log_jsn(&smart_log, cfg.namespace_id, devicename);
+ show_sfx_smart_log_jsn(&smart_log, cfg.namespace_id,
+ dev->name);
else if (!cfg.raw_binary)
- show_sfx_smart_log(&smart_log, cfg.namespace_id, devicename);
+ show_sfx_smart_log(&smart_log, cfg.namespace_id,
+ dev->name);
else
d_raw((unsigned char *)&smart_log, sizeof(smart_log));
}
else if (err > 0)
nvme_show_status(err);
- close(fd);
+ dev_close(dev);
return err;
}
@@ -609,22 +611,23 @@ static void show_lat_stats_myrtle(struct sfx_lat_stats_myrtle *stats, int write)
for (i = 0; i < 64; i++)
printf("Bucket %2d: %u\n", i, stats->bucket_19[i]);
- printf("\nAverage latency statistics %lld\n", stats->average);
+ printf("\nAverage latency statistics %" PRIu64 "\n",
+ (uint64_t)stats->average);
}
static int get_lat_stats_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
struct sfx_lat_stats stats;
- int err, fd;
-
char *desc = "Get ScaleFlux Latency Statistics log and show it.";
const char *raw = "dump output in binary format";
const char *write = "Get write statistics (read default)";
+ struct nvme_dev *dev;
struct config {
bool raw_binary;
bool write;
};
+ int err;
struct config cfg = {
};
@@ -635,12 +638,12 @@ static int get_lat_stats_log(int argc, char **argv, struct command *cmd, struct
OPT_END()
};
- fd = parse_and_open(argc, argv, desc, opts);
- if (fd < 0) {
- return fd;
- }
+ err = parse_and_open(&dev, argc, argv, desc, opts);
+ if (err)
+ return err;
- err = nvme_get_log_simple(fd, cfg.write ? 0xc3 : 0xc1, sizeof(stats), (void *)&stats);
+ err = nvme_get_log_simple(dev_fd(dev), cfg.write ? 0xc3 : 0xc1,
+ sizeof(stats), (void *)&stats);
if (!err) {
if ((stats.ver.maj == VANDA_MAJOR_IDX) && (stats.ver.min == VANDA_MINOR_IDX)) {
if (!cfg.raw_binary) {
@@ -660,7 +663,7 @@ static int get_lat_stats_log(int argc, char **argv, struct command *cmd, struct
}
} else if (err > 0)
nvme_show_status(err);
- close(fd);
+ dev_close(dev);
return err;
}
@@ -764,9 +767,9 @@ static void bd_table_show(unsigned char *bd_table, __u64 table_size)
*/
static int sfx_get_bad_block(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
- int fd;
- unsigned char *data_buf;
const __u64 buf_size = 256*4096*sizeof(unsigned char);
+ unsigned char *data_buf;
+ struct nvme_dev *dev;
int err = 0;
char *desc = "Get bad block table of sfx block device.";
@@ -775,19 +778,18 @@ static int sfx_get_bad_block(int argc, char **argv, struct command *cmd, struct
OPT_END()
};
- fd = parse_and_open(argc, argv, desc, opts);
- if (fd < 0) {
- return fd;
- }
+ err = parse_and_open(&dev, argc, argv, desc, opts);
+ if (err)
+ return err;
data_buf = malloc(buf_size);
if (!data_buf) {
fprintf(stderr, "malloc fail, errno %d\r\n", errno);
- close(fd);
+ dev_close(dev);
return -1;
}
- err = get_bb_table(fd, 0xffffffff, data_buf, buf_size);
+ err = get_bb_table(dev_fd(dev), 0xffffffff, data_buf, buf_size);
if (err < 0) {
perror("get-bad-block");
} else if (err != 0) {
@@ -798,7 +800,7 @@ static int sfx_get_bad_block(int argc, char **argv, struct command *cmd, struct
}
free(data_buf);
- close(fd);
+ dev_close(dev);
return 0;
}
@@ -819,25 +821,25 @@ static void show_cap_info(struct sfx_freespace_ctx *ctx)
static int query_cap_info(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
struct sfx_freespace_ctx ctx = { 0 };
- int err = 0, fd;
char *desc = "query current capacity info";
const char *raw = "dump output in binary format";
+ struct nvme_dev *dev;
struct config {
bool raw_binary;
};
struct config cfg;
+ int err = 0;
OPT_ARGS(opts) = {
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw),
OPT_END()
};
- fd = parse_and_open(argc, argv, desc, opts);
- if (fd < 0) {
- return fd;
- }
+ err = parse_and_open(&dev, argc, argv, desc, opts);
+ if (err)
+ return err;
- if (nvme_query_cap(fd, 0xffffffff, sizeof(ctx), &ctx)) {
+ if (nvme_query_cap(dev_fd(dev), 0xffffffff, sizeof(ctx), &ctx)) {
perror("sfx-query-cap");
err = -1;
}
@@ -849,7 +851,7 @@ static int query_cap_info(int argc, char **argv, struct command *cmd, struct plu
d_raw((unsigned char *)&ctx, sizeof(ctx));
}
}
- close(fd);
+ dev_close(dev);
return err;
}
@@ -939,14 +941,15 @@ static int sfx_confirm_change(const char *str)
static int change_cap(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
- int err = -1, fd;
char *desc = "dynamic change capacity";
const char *cap_gb = "cap size in GB";
const char *cap_byte = "cap size in byte";
const char *force = "The \"I know what I'm doing\" flag, skip confirmation before sending command";
+ struct nvme_dev *dev;
__u64 cap_in_4k = 0;
__u64 cap_in_sec = 0;
int shrink = 0;
+ int err = -1;
struct config {
__u64 cap_in_byte;
@@ -967,10 +970,9 @@ static int change_cap(int argc, char **argv, struct command *cmd, struct plugin
OPT_END()
};
- fd = parse_and_open(argc, argv, desc, opts);
- if (fd < 0) {
- return fd;
- }
+ err = parse_and_open(&dev, argc, argv, desc, opts);
+ if (err)
+ return err;
cap_in_sec = IDEMA_CAP(cfg.capacity_in_gb);
cap_in_4k = cap_in_sec >> 3;
@@ -979,27 +981,27 @@ static int change_cap(int argc, char **argv, struct command *cmd, struct plugin
printf("%dG %"PRIu64"B %"PRIu64" 4K\n",
cfg.capacity_in_gb, (uint64_t)cfg.cap_in_byte, (uint64_t)cap_in_4k);
- if (change_sanity_check(fd, cap_in_4k, &shrink)) {
+ if (change_sanity_check(dev_fd(dev), cap_in_4k, &shrink)) {
printf("ScaleFlux change-capacity: fail\n");
- close(fd);
+ dev_close(dev);
return err;
}
if (!cfg.force && shrink && !sfx_confirm_change("Changing Cap may irrevocably delete this device's data")) {
- close(fd);
+ dev_close(dev);
return 0;
}
- err = nvme_change_cap(fd, 0xffffffff, cap_in_4k);
+ err = nvme_change_cap(dev_fd(dev), 0xffffffff, cap_in_4k);
if (err < 0)
perror("sfx-change-cap");
else if (err != 0)
nvme_show_status(err);
else {
printf("ScaleFlux change-capacity: success\n");
- ioctl(fd, BLKRRPART);
+ ioctl(dev_fd(dev), BLKRRPART);
}
- close(fd);
+ dev_close(dev);
return err;
}
@@ -1051,7 +1053,6 @@ char *sfx_feature_to_string(int feature)
static int sfx_set_feature(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
- int err = 0, fd;
char *desc = "ScaleFlux internal set features\n"
"feature id 1: ATOMIC\n"
"value 0: Disable atomic write\n"
@@ -1060,8 +1061,9 @@ static int sfx_set_feature(int argc, char **argv, struct command *cmd, struct pl
const char *feature_id = "hex feature name (required)";
const char *namespace_id = "desired namespace";
const char *force = "The \"I know what I'm doing\" flag, skip confirmation before sending command";
-
+ struct nvme_dev *dev;
struct nvme_id_ns ns;
+ int err = 0;
struct config {
__u32 namespace_id;
@@ -1084,37 +1086,37 @@ static int sfx_set_feature(int argc, char **argv, struct command *cmd, struct pl
OPT_END()
};
- fd = parse_and_open(argc, argv, desc, opts);
- if (fd < 0) {
- return fd;
- }
+ err = parse_and_open(&dev, argc, argv, desc, opts);
+ if (err)
+ return err;
if (!cfg.feature_id) {
fprintf(stderr, "feature-id required param\n");
- close(fd);
+ dev_close(dev);
return EINVAL;
}
if (cfg.feature_id == SFX_FEAT_CLR_CARD) {
/*Warning for clean card*/
if (!cfg.force && !sfx_confirm_change("Going to clean device's data, confirm umount fs and try again")) {
- close(fd);
+ dev_close(dev);
return 0;
} else {
- return sfx_clean_card(fd);
+ return sfx_clean_card(dev_fd(dev));
}
}
if (cfg.feature_id == SFX_FEAT_ATOMIC && cfg.value != 0) {
if (cfg.namespace_id != 0xffffffff) {
- err = nvme_identify_ns(fd, cfg.namespace_id, &ns);
+ err = nvme_identify_ns(dev_fd(dev), cfg.namespace_id,
+ &ns);
if (err) {
if (err < 0)
perror("identify-namespace");
else
nvme_show_status(err);
- close(fd);
+ dev_close(dev);
return err;
}
/*
@@ -1122,29 +1124,31 @@ static int sfx_set_feature(int argc, char **argv, struct command *cmd, struct pl
*/
if ((ns.flbas & 0xf) != 1) {
printf("Please change-sector size to 4K, then retry\n");
- close(fd);
+ dev_close(dev);
return EFAULT;
}
}
} else if (cfg.feature_id == SFX_FEAT_UP_P_CAP) {
if (cfg.value <= 0) {
fprintf(stderr, "Invalid Param\n");
- close(fd);
+ dev_close(dev);
return EINVAL;
}
/*Warning for change pacp by GB*/
if (!cfg.force && !sfx_confirm_change("Changing physical capacity may irrevocably delete this device's data")) {
- close(fd);
+ dev_close(dev);
return 0;
}
}
- err = nvme_sfx_set_features(fd, cfg.namespace_id, cfg.feature_id, cfg.value);
+ err = nvme_sfx_set_features(dev_fd(dev), cfg.namespace_id,
+ cfg.feature_id,
+ cfg.value);
if (err < 0) {
perror("ScaleFlux-set-feature");
- close(fd);
+ dev_close(dev);
return errno;
} else if (!err) {
printf("ScaleFlux set-feature:%#02x (%s), value:%d\n", cfg.feature_id,
@@ -1152,18 +1156,19 @@ static int sfx_set_feature(int argc, char **argv, struct command *cmd, struct pl
} else if (err > 0)
nvme_show_status(err);
- close(fd);
+ dev_close(dev);
return err;
}
static int sfx_get_feature(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
- int err = 0, fd;
char *desc = "ScaleFlux internal set features\n"
"feature id 1: ATOMIC";
const char *feature_id = "hex feature name (required)";
const char *namespace_id = "desired namespace";
+ struct nvme_dev *dev;
__u32 result = 0;
+ int err = 0;
struct config {
__u32 namespace_id;
@@ -1180,21 +1185,21 @@ static int sfx_get_feature(int argc, char **argv, struct command *cmd, struct pl
OPT_END()
};
- fd = parse_and_open(argc, argv, desc, opts);
- if (fd < 0) {
- return fd;
- }
+ err = parse_and_open(&dev, argc, argv, desc, opts);
+ if (err)
+ return err;
if (!cfg.feature_id) {
fprintf(stderr, "feature-id required param\n");
- close(fd);
+ dev_close(dev);
return EINVAL;
}
- err = nvme_sfx_get_features(fd, cfg.namespace_id, cfg.feature_id, &result);
+ err = nvme_sfx_get_features(dev_fd(dev), cfg.namespace_id,
+ cfg.feature_id, &result);
if (err < 0) {
perror("ScaleFlux-get-feature");
- close(fd);
+ dev_close(dev);
return errno;
} else if (!err) {
printf("ScaleFlux get-feature:%02x (%s), value:%d\n", cfg.feature_id,
@@ -1202,7 +1207,7 @@ static int sfx_get_feature(int argc, char **argv, struct command *cmd, struct pl
} else if (err > 0)
nvme_show_status(err);
- close(fd);
+ dev_close(dev);
return err;
}