summaryrefslogtreecommitdiffstats
path: root/plugins/shannon
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-11-05 18:23:30 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-11-05 18:23:30 +0000
commit4ed089396bc7f14bcb94e80f0f9f4757fd8c48b7 (patch)
tree866986558761a9709a7af1940ba607128a45f775 /plugins/shannon
parentReleasing debian version 2.1.2-2. (diff)
downloadnvme-cli-4ed089396bc7f14bcb94e80f0f9f4757fd8c48b7.tar.xz
nvme-cli-4ed089396bc7f14bcb94e80f0f9f4757fd8c48b7.zip
Merging upstream version 2.2.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'plugins/shannon')
-rw-r--r--plugins/shannon/shannon-nvme.c56
1 files changed, 30 insertions, 26 deletions
diff --git a/plugins/shannon/shannon-nvme.c b/plugins/shannon/shannon-nvme.c
index 220638f..424b3f7 100644
--- a/plugins/shannon/shannon-nvme.c
+++ b/plugins/shannon/shannon-nvme.c
@@ -117,15 +117,16 @@ static void show_shannon_smart_log(struct nvme_shannon_smart_log *smart,
static int get_additional_smart_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
struct nvme_shannon_smart_log smart_log;
- int err, fd;
char *desc = "Get Shannon 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";
+ struct nvme_dev *dev;
struct config {
__u32 namespace_id;
bool raw_binary;
};
+ int err;
struct config cfg = {
.namespace_id = NVME_NSID_ALL,
@@ -137,20 +138,21 @@ static int get_additional_smart_log(int argc, char **argv, struct command *cmd,
OPT_END()
};
- fd = parse_and_open(argc, argv, desc, opts);
- if (fd < 0)
- return fd;
- err = nvme_get_nsid_log(fd, false, 0xca, cfg.namespace_id,
- sizeof(smart_log), &smart_log);
+ err = parse_and_open(&dev, argc, argv, desc, opts);
+ if (err)
+ return err;
+ err = nvme_get_nsid_log(dev_fd(dev), false, 0xca, cfg.namespace_id,
+ sizeof(smart_log), &smart_log);
if (!err) {
if (!cfg.raw_binary)
- show_shannon_smart_log(&smart_log, cfg.namespace_id, devicename);
+ show_shannon_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;
}
@@ -174,9 +176,10 @@ static int get_additional_feature(int argc, char **argv, struct command *cmd, st
const char *data_len = "buffer len (if) data is returned";
const char *cdw11 = "dword 11 for interrupt vector config";
const char *human_readable = "show infos in readable format";
- int err, fd;
- __u32 result;
+ struct nvme_dev *dev;
void *buf = NULL;
+ __u32 result;
+ int err;
struct config {
__u32 namespace_id;
@@ -207,24 +210,24 @@ static int get_additional_feature(int argc, char **argv, struct command *cmd, st
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.sel > 7) {
fprintf(stderr, "invalid 'select' param:%d\n", cfg.sel);
- close(fd);
+ dev_close(dev);
return EINVAL;
}
if (!cfg.feature_id) {
fprintf(stderr, "feature-id required param\n");
- close(fd);
+ dev_close(dev);
return EINVAL;
}
if (cfg.data_len) {
if (posix_memalign(&buf, getpagesize(), cfg.data_len))
{
- close(fd);
+ dev_close(dev);
exit(ENOMEM);
}
memset(buf, 0, cfg.data_len);
@@ -232,7 +235,7 @@ static int get_additional_feature(int argc, char **argv, struct command *cmd, st
struct nvme_get_features_args args = {
.args_size = sizeof(args),
- .fd = fd,
+ .fd = dev_fd(dev),
.fid = cfg.feature_id,
.nsid = cfg.namespace_id,
.sel = cfg.sel,
@@ -286,10 +289,11 @@ static int set_additional_feature(int argc, char **argv, struct command *cmd, st
const char *data = "optional file for feature data (default stdin)";
const char *value = "new value of feature (required)";
const char *save = "specifies that the controller shall save the attribute";
- int err, fd;
- __u32 result;
- void *buf = NULL;
int ffd = STDIN_FILENO;
+ struct nvme_dev *dev;
+ void *buf = NULL;
+ __u32 result;
+ int err;
struct config {
char *file;
@@ -319,20 +323,20 @@ static int set_additional_feature(int argc, char **argv, struct command *cmd, st
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.data_len) {
if (posix_memalign(&buf, getpagesize(), cfg.data_len)){
fprintf(stderr, "can not allocate feature payload\n");
- close(fd);
+ dev_close(dev);
return ENOMEM;
}
memset(buf, 0, cfg.data_len);
@@ -357,7 +361,7 @@ static int set_additional_feature(int argc, char **argv, struct command *cmd, st
struct nvme_set_features_args args = {
.args_size = sizeof(args),
- .fd = fd,
+ .fd = dev_fd(dev),
.fid = cfg.feature_id,
.nsid = cfg.namespace_id,
.cdw11 = cfg.value,