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

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) ===
Signed-off-by: Christian Brauner <[email protected]>
From e7abce0b0281e38d0b3032b4a6997be1ca9b6b52 Mon Sep 17 00:00:00 2001
From: Christian Brauner <[email protected]>
Date: Sat, 21 Oct 2017 11:46:58 +0200
Subject: [PATCH] container: fix vfio logic

Signed-off-by: Christian Brauner <[email protected]>
---
 lxd/container_lxc.go | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index a12718c32..558ae48d4 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -6064,41 +6064,38 @@ func (c *containerLXC) fillVfioNetworkDevice(name 
string, m types.Device, reserv
        }
 
        // Check if any VFs are already enabled
-       vf := ""
        nicName := ""
        for i := 0; i < sriovNum; i++ {
-               vf = fmt.Sprintf("virtfn%d", i)
-               if 
!shared.PathExists(fmt.Sprintf("/sys/class/net/%s/device/%s/net", m["parent"], 
vf)) {
-                       vf = ""
+               if 
!shared.PathExists(fmt.Sprintf("/sys/class/net/%s/device/virtfn%d/net", 
m["parent"], i)) {
                        continue
                }
 
                // Check if VF is already in use
-               empty, err := 
shared.PathIsEmpty(fmt.Sprintf("/sys/class/net/%s/device/%s/net", m["parent"], 
vf))
+               empty, err := 
shared.PathIsEmpty(fmt.Sprintf("/sys/class/net/%s/device/virtfn%d/net", 
m["parent"], i))
                if err != nil {
                        return nil, err
                }
                if empty {
-                       vf = ""
                        continue
                }
 
-               vf = fmt.Sprintf("/sys/class/net/%s/device/%s/net", 
m["parent"], vf)
+               vf := fmt.Sprintf("/sys/class/net/%s/device/virtfn%d/net", 
m["parent"], i)
                ents, err := ioutil.ReadDir(vf)
                if err != nil {
                        return nil, err
                }
-               if len(ents) == 0 || len(ents) > 1 {
+
+               if len(ents) != 1 {
                        continue
                }
 
+               // another nic device entry called dibs
                if shared.StringInSlice(ents[0].Name(), reserved) {
                        continue
                }
 
+               // found a free one
                nicName = ents[0].Name()
-
-               // found free VF
                break
        }
 
@@ -6114,22 +6111,25 @@ func (c *containerLXC) fillVfioNetworkDevice(name 
string, m types.Device, reserv
                }
 
                // use next free VF index
-               vf = fmt.Sprintf("virtfn%d", sriovNum+1)
-
                for i := sriovNum + 1; i < sriovTotal; i++ {
-                       vf = fmt.Sprintf("/sys/class/net/%s/device/%s/net", 
m["parent"], vf)
+                       vf := 
fmt.Sprintf("/sys/class/net/%s/device/virtfn%d/net", m["parent"], i)
                        ents, err := ioutil.ReadDir(vf)
                        if err != nil {
                                return nil, err
                        }
-                       if len(ents) == 0 || len(ents) > 1 {
+
+                       if len(ents) != 1 {
                                return nil, fmt.Errorf("Failed to determine 
unique device name")
                        }
+
+                       // another nic device entry called dibs
                        if shared.StringInSlice(ents[0].Name(), reserved) {
                                continue
                        }
 
+                       // found a free one
                        nicName = ents[0].Name()
+                       break
                }
        }
 
_______________________________________________
lxc-devel mailing list
[email protected]
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to