summaryrefslogtreecommitdiffstats
path: root/plugins/netapp/netapp-nvme.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-07-14 18:28:04 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-07-16 15:12:07 +0000
commit589986012c4b3ab68e299a2eadca18f90080113b (patch)
treef29a53b04a1950cdddae69344bccb3f0146fa728 /plugins/netapp/netapp-nvme.c
parentReleasing debian version 1.16-4. (diff)
downloadnvme-cli-589986012c4b3ab68e299a2eadca18f90080113b.tar.xz
nvme-cli-589986012c4b3ab68e299a2eadca18f90080113b.zip
Merging upstream version 2.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'plugins/netapp/netapp-nvme.c')
-rw-r--r--plugins/netapp/netapp-nvme.c67
1 files changed, 37 insertions, 30 deletions
diff --git a/plugins/netapp/netapp-nvme.c b/plugins/netapp/netapp-nvme.c
index 15c3923..9630442 100644
--- a/plugins/netapp/netapp-nvme.c
+++ b/plugins/netapp/netapp-nvme.c
@@ -21,12 +21,13 @@
#include <unistd.h>
#include <errno.h>
#include <string.h>
-#include <sys/ioctl.h>
+#include <uuid/uuid.h>
+#include "common.h"
#include "nvme.h"
-#include "nvme-ioctl.h"
+#include "libnvme.h"
-#include "suffix.h"
+#include "util/suffix.h"
#define CREATE_CMD
#include "netapp-nvme.h"
@@ -56,17 +57,17 @@ enum {
static const char *dev_path = "/dev/";
struct smdevice_info {
- int nsid;
+ unsigned nsid;
struct nvme_id_ctrl ctrl;
struct nvme_id_ns ns;
char dev[265];
};
struct ontapdevice_info {
- int nsid;
+ unsigned nsid;
struct nvme_id_ctrl ctrl;
struct nvme_id_ns ns;
- char nsdesc[4096];
+ uuid_t uuid;
unsigned char log_data[ONTAP_C2_LOG_SIZE];
char dev[265];
};
@@ -105,24 +106,15 @@ static void netapp_nguid_to_str(char *str, __u8 *nguid)
static void netapp_get_ns_size(char *size, long long *lba,
struct nvme_id_ns *ns)
{
- *lba = 1 << ns->lbaf[(ns->flbas & 0x0F)].ds;
+ __u8 lba_index;
+ nvme_id_ns_flbas_to_lbaf_inuse(ns->flbas, &lba_index);
+ *lba = 1 << ns->lbaf[lba_index].ds;
double nsze = le64_to_cpu(ns->nsze) * (*lba);
const char *s_suffix = suffix_si_get(&nsze);
sprintf(size, "%.2f%sB", nsze, s_suffix);
}
-static void netapp_uuid_to_str(char *str, void *data)
-{
-#ifdef LIBUUID
- uuid_t uuid;
- struct nvme_ns_id_desc *desc = data;
-
- memcpy(uuid, data + sizeof(*desc), 16);
- uuid_unparse_lower(uuid, str);
-#endif
-}
-
static void ontap_labels_to_str(char *dst, char *src, int count)
{
int i;
@@ -249,6 +241,7 @@ static void netapp_smdevices_print(struct smdevice_info *devices, int count, int
"Volume ID %s, Controller %c, Access State %s, %s\n";
char columnstr[] = "%-16s %-30s %-30s %4d %32s %c %-12s %9s\n";
char *formatstr = basestr; /* default to "normal" output format */
+ __u8 lba_index;
if (format == NCOLUMN) {
/* for column output, change output string and print column headers */
@@ -265,11 +258,12 @@ static void netapp_smdevices_print(struct smdevice_info *devices, int count, int
else if (format == NJSON) {
/* prepare for json output */
root = json_create_object();
- json_devices = json_create_object();
+ json_devices = json_create_array();
}
for (i = 0; i < count; i++) {
- long long int lba = 1 << devices[i].ns.lbaf[(devices[i].ns.flbas & 0x0F)].ds;
+ nvme_id_ns_flbas_to_lbaf_inuse(devices[i].ns.flbas, &lba_index);
+ long long int lba = 1 << devices[i].ns.lbaf[lba_index].ds;
double nsze = le64_to_cpu(devices[i].ns.nsze) * lba;
const char *s_suffix = suffix_si_get(&nsze);
char size[128];
@@ -296,6 +290,8 @@ static void netapp_smdevices_print(struct smdevice_info *devices, int count, int
/* complete the json output */
json_object_add_value_array(root, "SMdevices", json_devices);
json_print_object(root, NULL);
+ printf("\n");
+ json_free_object(root);
}
}
@@ -331,13 +327,13 @@ static void netapp_ontapdevices_print(struct ontapdevice_info *devices,
} else if (format == NJSON) {
/* prepare for json output */
root = json_create_object();
- json_devices = json_create_object();
+ json_devices = json_create_array();
}
for (i = 0; i < count; i++) {
netapp_get_ns_size(size, &lba, &devices[i].ns);
- netapp_uuid_to_str(uuid_str, devices[i].nsdesc);
+ uuid_unparse_lower(devices[i].uuid, uuid_str);
netapp_get_ontap_labels(vsname, nspath, devices[i].log_data);
if (format == NJSON) {
@@ -354,16 +350,18 @@ static void netapp_ontapdevices_print(struct ontapdevice_info *devices,
/* complete the json output */
json_object_add_value_array(root, "ONTAPdevices", json_devices);
json_print_object(root, NULL);
+ printf("\n");
+ json_free_object(root);
}
}
static int nvme_get_ontap_c2_log(int fd, __u32 nsid, void *buf, __u32 buflen)
{
- struct nvme_admin_cmd get_log;
+ struct nvme_passthru_cmd get_log;
int err;
memset(buf, 0, buflen);
- memset(&get_log, 0, sizeof(struct nvme_admin_cmd));
+ memset(&get_log, 0, sizeof(struct nvme_passthru_cmd));
get_log.opcode = nvme_admin_get_log_page;
get_log.nsid = nsid;
@@ -378,7 +376,7 @@ static int nvme_get_ontap_c2_log(int fd, __u32 nsid, void *buf, __u32 buflen)
get_log.cdw10 |= ONTAP_C2_LOG_NSINFO_LSP << 8;
get_log.cdw11 = numdu;
- err = nvme_submit_admin_passthru(fd, &get_log);
+ err = nvme_submit_admin_passthru(fd, &get_log, NULL);
if (err) {
fprintf(stderr, "ioctl error %0x\n", err);
return 1;
@@ -402,8 +400,8 @@ static int netapp_smdevices_get_info(int fd, struct smdevice_info *item,
if (strncmp("NetApp E-Series", item->ctrl.mn, 15) != 0)
return 0; /* not the right model of controller */
- item->nsid = nvme_get_nsid(fd);
- err = nvme_identify_ns(fd, item->nsid, 0, &item->ns);
+ err = nvme_get_nsid(fd, &item->nsid);
+ err = nvme_identify_ns(fd, item->nsid, &item->ns);
if (err) {
fprintf(stderr, "Unable to identify namespace for %s (%s)\n",
dev, strerror(err));
@@ -418,6 +416,7 @@ static int netapp_ontapdevices_get_info(int fd, struct ontapdevice_info *item,
const char *dev)
{
int err;
+ void *nsdescs;
err = nvme_identify_ctrl(fd, &item->ctrl);
if (err) {
@@ -430,22 +429,30 @@ static int netapp_ontapdevices_get_info(int fd, struct ontapdevice_info *item,
/* not the right controller model */
return 0;
- item->nsid = nvme_get_nsid(fd);
+ err = nvme_get_nsid(fd, &item->nsid);
- err = nvme_identify_ns(fd, item->nsid, 0, &item->ns);
+ err = nvme_identify_ns(fd, item->nsid, &item->ns);
if (err) {
fprintf(stderr, "Unable to identify namespace for %s (%s)\n",
dev, strerror(err));
return 0;
}
- err = nvme_identify_ns_descs(fd, item->nsid, item->nsdesc);
+ if (posix_memalign(&nsdescs, getpagesize(), 0x1000)) {
+ fprintf(stderr, "Cannot allocate controller list payload\n");
+ return 0;
+ }
+
+ err = nvme_identify_ns_descs(fd, item->nsid, nsdescs);
if (err) {
fprintf(stderr, "Unable to identify namespace descriptor for %s (%s)\n",
dev, strerror(err));
return 0;
}
+ memcpy(item->uuid, nsdescs + sizeof(struct nvme_ns_id_desc), sizeof(item->uuid));
+ free(nsdescs);
+
err = nvme_get_ontap_c2_log(fd, item->nsid, item->log_data, ONTAP_C2_LOG_SIZE);
if (err) {
fprintf(stderr, "Unable to get log page data for %s (%s)\n",