]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
nvme-cli: nvme gen-hostnqn use partition UUID on IBM
authorroot <root@ltczz405-lp2.aus.stglabs.ibm.com>
Wed, 15 Sep 2021 15:24:42 +0000 (11:24 -0400)
committerroot <root@ltczz405-lp2.aus.stglabs.ibm.com>
Wed, 15 Sep 2021 15:24:42 +0000 (11:24 -0400)
IBM POWER systems expose a platform created UUID in the device
tree. Use that as the UUID in the host NQN

Signed-Off-by: Wen Xiong <wenxiong@linux.vnet.ibm.com>
Reviewed-by: Brian King <brking@linux.vnet.ibm.com>
src/nvme/fabrics.c

index bdbcb8317b139dd12438767a310a33917160140a..cf0b168ba557d6036f2949b63403b4c641800e22 100644 (file)
@@ -590,6 +590,27 @@ out_free_log:
        return ret;
 }
 
+#define PATH_UUID_IBM  "/proc/device-tree/ibm,partition-uuid"
+
+int uuid_from_device_tree(char *system_uuid)
+{
+       char filename[PATH_MAX];
+       int f, len, ret;
+
+       sprintf(filename, "%s", PATH_UUID_IBM);
+       f = open(filename, O_RDONLY);
+       if (f < 0)
+               goto out_close;
+       len = read(f, system_uuid, 512);
+       if (len < 0)
+               goto out_close;
+
+out_close:
+       close(f);
+       ret = -ENXIO;
+       return strlen(system_uuid) ? 0 : ret;
+}
+
 #define PATH_DMI_ENTRIES       "/sys/firmware/dmi/entries"
 
 int uuid_from_dmi(char *system_uuid)
@@ -677,8 +698,11 @@ char *nvmf_hostnqn_generate()
 #endif
 
        ret = uuid_from_dmi(uuid_str);
-       if (ret < 0)
-               ret = uuid_from_systemd(uuid_str);
+       if (ret < 0) {
+               ret = uuid_from_device_tree(uuid_str);
+               if (ret < 0)
+                       ret = uuid_from_systemd(uuid_str);
+       }
 #ifdef CONFIG_LIBUUID
        if (ret < 0) {
                uuid_generate_random(uuid);