Blame SOURCES/0008-nvme-cli-nvme-gen-hostnqn-use-partition-UUID-on-IBM-.patch

35de48
From db50dbf5692325cfef8fb77e56e1e44af83a022e Mon Sep 17 00:00:00 2001
35de48
From: Maurizio Lombardi <mlombard@redhat.com>
35de48
Date: Wed, 29 Jun 2022 16:47:30 +0200
35de48
Subject: [PATCH 1/7] nvme-cli: nvme gen-hostnqn use partition UUID on IBM
35de48
 POWER
35de48
35de48
Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
35de48
---
35de48
 nvme.c | 27 +++++++++++++++++++++++++--
35de48
 1 file changed, 25 insertions(+), 2 deletions(-)
35de48
35de48
diff --git a/nvme.c b/nvme.c
35de48
index 5beeac78..0535ed2b 100644
35de48
--- a/nvme.c
35de48
+++ b/nvme.c
35de48
@@ -6516,6 +6516,26 @@ static int admin_passthru(int argc, char **argv, struct command *cmd, struct plu
35de48
 	return passthru(argc, argv, NVME_IOCTL_ADMIN_CMD, 1, desc, cmd);
35de48
 }
35de48
 
35de48
+#define PATH_UUID_IBM	"/proc/device-tree/ibm,partition-uuid"
35de48
+
35de48
+static int uuid_from_device_tree(char *system_uuid)
35de48
+{
35de48
+	ssize_t len;
35de48
+	int f;
35de48
+
35de48
+	f = open(PATH_UUID_IBM, O_RDONLY);
35de48
+	if (f < 0)
35de48
+		return -ENXIO;
35de48
+
35de48
+	memset(system_uuid, 0, 37);
35de48
+	len = read(f, system_uuid, 37 - 1);
35de48
+	close(f);
35de48
+	if (len < 0)
35de48
+		return -ENXIO;
35de48
+
35de48
+	return strlen(system_uuid) ? 0 : -ENXIO;
35de48
+}
35de48
+
35de48
 static int gen_hostnqn_cmd(int argc, char **argv, struct command *command, struct plugin *plugin)
35de48
 {
35de48
 	int ret;
35de48
@@ -6525,8 +6545,11 @@ static int gen_hostnqn_cmd(int argc, char **argv, struct command *command, struc
35de48
 #endif
35de48
 
35de48
 	ret = uuid_from_dmi(uuid_str);
35de48
-	if (ret < 0)
35de48
-		ret = uuid_from_systemd(uuid_str);
35de48
+	if (ret < 0) {
35de48
+		ret = uuid_from_device_tree(uuid_str);
35de48
+		if (ret < 0)
35de48
+			ret = uuid_from_systemd(uuid_str);
35de48
+	}
35de48
 #ifdef LIBUUID
35de48
 	if (ret < 0) {
35de48
 		uuid_generate_random(uuid);
35de48
-- 
35de48
2.31.1
35de48