[lxc-devel] [lxd/master] lxd/infiniband: Workaround weird sysfs behavior

stgraber on Github lxc-bot at linuxcontainers.org
Tue Aug 20 18:23:21 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 370 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190820/a0b903e3/attachment.bin>
-------------- next part --------------
From e2f575fb0467d8dedce613c62112999311cff815 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 20 Aug 2019 11:22:30 -0700
Subject: [PATCH] lxd/infiniband: Workaround weird sysfs behavior
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #6106

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/device/device_utils_infiniband.go | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/lxd/device/device_utils_infiniband.go b/lxd/device/device_utils_infiniband.go
index 57f2f2e2c5..17831bfa14 100644
--- a/lxd/device/device_utils_infiniband.go
+++ b/lxd/device/device_utils_infiniband.go
@@ -41,6 +41,15 @@ type IBF struct {
 	PerFunDevices  []string
 }
 
+func sysfsExists(path string) bool {
+	_, err := os.Lstat(path)
+	if err == nil {
+		return true
+	}
+
+	return false
+}
+
 // infinibandLoadDevices inspects the system and returns information about all infiniband devices.
 func infinibandLoadDevices() (map[string]IBF, error) {
 	// check if there are any infiniband devices.
@@ -86,6 +95,10 @@ func infinibandLoadDevices() (map[string]IBF, error) {
 	UseableDevices := make(map[string]IBF)
 	for _, IBDevName := range IBDevNames {
 		IBDevResourceFile := fmt.Sprintf("/sys/class/infiniband/%s/device/resource", IBDevName)
+		if !sysfsExists(IBDevResourceFile) {
+			continue
+		}
+
 		IBDevResourceBuf, err := ioutil.ReadFile(IBDevResourceFile)
 		if err != nil {
 			return nil, err
@@ -93,11 +106,12 @@ func infinibandLoadDevices() (map[string]IBF, error) {
 
 		for _, NetDevName := range NetDevNames {
 			NetDevResourceFile := fmt.Sprintf("/sys/class/net/%s/device/resource", NetDevName)
+			if !sysfsExists(NetDevResourceFile) {
+				continue
+			}
+
 			NetDevResourceBuf, err := ioutil.ReadFile(NetDevResourceFile)
 			if err != nil {
-				if os.IsNotExist(err) {
-					continue
-				}
 				return nil, err
 			}
 


More information about the lxc-devel mailing list