[lxc-devel] [lxd/master] container: fix vfio logic

brauner on Github lxc-bot at linuxcontainers.org
Sat Oct 21 10:07:15 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 364 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20171021/b4a698d9/attachment.bin>
-------------- next part --------------
From e7abce0b0281e38d0b3032b4a6997be1ca9b6b52 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 21 Oct 2017 11:46:58 +0200
Subject: [PATCH] container: fix vfio logic

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 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
 		}
 	}
 


More information about the lxc-devel mailing list