From d88ed0ab97ac61aab64ef4b6bc6b89092387ffe3 Mon Sep 17 00:00:00 2001 From: "Pradipta Kr. Banerjee" Date: Mon, 27 Apr 2015 11:25:01 +0530 Subject: [PATCH] Handle system UUID retrieval for Power(ppc64) Systems This patch adds requisite support to retrieve system uuid details for Power systems. Power systems do not have DMI data. However most of the relevant details are either in /proc or /sys. For baremetal servers, the UID is available in /proc/device-tree/system-id. For guests the UUID is available in /proc/device-tree/vm,uuid inside the guest. Guest's /proc filesystem do not have /proc/device-tree/system-id Example On baremetal system $cat /proc/device-tree/system-id 2122AAA On a guest VM $cat /proc/device-tree/vm,uuid 4b1a1a7e-079e-479c-8072-d8108f31050c Signed-off-by: Pradipta Kr. Banerjee --- utils/sysfs/sysfs.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/utils/sysfs/sysfs.go b/utils/sysfs/sysfs.go index d33b9d00..f1568b66 100644 --- a/utils/sysfs/sysfs.go +++ b/utils/sysfs/sysfs.go @@ -24,10 +24,11 @@ import ( ) const ( - blockDir = "/sys/block" - cacheDir = "/sys/devices/system/cpu/cpu" - netDir = "/sys/class/net" - dmiDir = "/sys/class/dmi" + blockDir = "/sys/block" + cacheDir = "/sys/devices/system/cpu/cpu" + netDir = "/sys/class/net" + dmiDir = "/sys/class/dmi" + ppcDevTree = "/proc/device-tree" ) type CacheInfo struct { @@ -235,7 +236,15 @@ func (self *realSysFs) GetCacheInfo(id int, name string) (CacheInfo, error) { func (self *realSysFs) GetSystemUUID() (string, error) { id, err := ioutil.ReadFile(path.Join(dmiDir, "id", "product_uuid")) if err != nil { - return "", err + //If running on baremetal Power then UID is /proc/device-tree/system-id + id, err = ioutil.ReadFile(path.Join(ppcDevTree, "system-id")) + if err != nil { + //If running on a KVM guest on Power then UUID is /proc/device-tree/vm,uuid + id, err = ioutil.ReadFile(path.Join(ppcDevTree, "vm,uuid")) + if err != nil { + return "", err + } + } } return strings.TrimSpace(string(id)), nil }