The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/6108

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Closes #6106

Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
From e2f575fb0467d8dedce613c62112999311cff815 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@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 <stgra...@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
                        }
 
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to