From: Martin George Date: Wed, 16 Feb 2022 18:33:20 +0000 (+0530) Subject: netapp-nvme: fix nvme ns desc uuid handling for ontapdevices X-Git-Tag: v2.0-rc4~12^2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=476d0199c2bd9c414d20cb56d355b83bd304f3e6;p=users%2Fsagi%2Fnvme-cli.git netapp-nvme: fix nvme ns desc uuid handling for ontapdevices The nvme ns desc uuid handling in the NetApp plugin for ontapdevices is broken after the recent upgrade to libnvme. The uuid hanlding logic here was flawed to begin with, so rework this code to ensure the respective uuid descriptor itself is stored in the ontapdevice_info structure and processed appropriately. Signed-off-by: Martin George --- diff --git a/plugins/netapp/netapp-nvme.c b/plugins/netapp/netapp-nvme.c index e14a970b..d5c6d6cd 100644 --- a/plugins/netapp/netapp-nvme.c +++ b/plugins/netapp/netapp-nvme.c @@ -67,7 +67,7 @@ struct ontapdevice_info { unsigned nsid; struct nvme_id_ctrl ctrl; struct nvme_id_ns ns; - struct nvme_ns_id_desc nsdesc; + uuid_t uuid; unsigned char log_data[ONTAP_C2_LOG_SIZE]; char dev[265]; }; @@ -115,15 +115,6 @@ static void netapp_get_ns_size(char *size, long long *lba, sprintf(size, "%.2f%sB", nsze, s_suffix); } -static void netapp_uuid_to_str(char *str, void *data) -{ - uuid_t uuid; - struct nvme_ns_id_desc *desc = data; - - memcpy(uuid, data + sizeof(*desc), 16); - uuid_unparse_lower(uuid, str); -} - static void ontap_labels_to_str(char *dst, char *src, int count) { int i; @@ -340,7 +331,7 @@ static void netapp_ontapdevices_print(struct ontapdevice_info *devices, 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) { @@ -423,6 +414,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) { @@ -444,13 +436,20 @@ static int netapp_ontapdevices_get_info(int fd, struct ontapdevice_info *item, 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)); + 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",