From: root Date: Wed, 15 Sep 2021 15:24:42 +0000 (-0400) Subject: nvme-cli: nvme gen-hostnqn use partition UUID on IBM X-Git-Tag: v1.0-rc0~105^2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=62bac64627b7ee99c49f30a399240acf04c95d92;p=users%2Fsagi%2Flibnvme.git nvme-cli: nvme gen-hostnqn use partition UUID on IBM 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 Reviewed-by: Brian King --- diff --git a/src/nvme/fabrics.c b/src/nvme/fabrics.c index bdbcb831..cf0b168b 100644 --- a/src/nvme/fabrics.c +++ b/src/nvme/fabrics.c @@ -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);