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

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) ===

From 8cff6f4a05b44e0a73c49998b576f0bc96aeb837 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com>
Date: Mon, 7 Oct 2019 11:31:07 -0400
Subject: [PATCH 1/3] api: Add resources_network_firmware extension
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
---
 doc/api-extensions.md | 3 +++
 shared/version/api.go | 1 +
 2 files changed, 4 insertions(+)

diff --git a/doc/api-extensions.md b/doc/api-extensions.md
index 6265130eb3..57b73118b7 100644
--- a/doc/api-extensions.md
+++ b/doc/api-extensions.md
@@ -845,3 +845,6 @@ roles that the member serves in the cluster.
 
 ## images\_expiry
 This allows for editing of the expiry date on images.
+
+## resources\_network\_firmware
+Adds a FirmwareVersion field to network card entries.
diff --git a/shared/version/api.go b/shared/version/api.go
index 90ec0a95f6..dd118706e4 100644
--- a/shared/version/api.go
+++ b/shared/version/api.go
@@ -169,6 +169,7 @@ var APIExtensions = []string{
        "resources_disk_sata",
        "clustering_roles",
        "images_expiry",
+       "resources_network_firmware",
 }
 
 // APIExtensionsCount returns the number of available API extensions.

From f2bd6bd839f46ab17616f90004bffc5f8547c26d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com>
Date: Mon, 7 Oct 2019 11:31:26 -0400
Subject: [PATCH 2/3] shared/api: Add FirmwareVersion to ResourcesNetworkCard
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
---
 shared/api/resource.go | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/shared/api/resource.go b/shared/api/resource.go
index 815e5a4b09..f2a9619d15 100644
--- a/shared/api/resource.go
+++ b/shared/api/resource.go
@@ -155,6 +155,9 @@ type ResourcesNetworkCard struct {
        VendorID  string `json:"vendor_id,omitempty" yaml:"vendor_id,omitempty"`
        Product   string `json:"product,omitempty" yaml:"product,omitempty"`
        ProductID string `json:"product_id,omitempty" 
yaml:"product_id,omitempty"`
+
+       // API extension: resources_network_firmware
+       FirmwareVersion string `json:"firmware_version,omitempty" 
yaml:"firmware_version,omitempty"`
 }
 
 // ResourcesNetworkCardPort represents a network port on the system

From f4b364015c190698c75ac1c9a9f457057fb33db3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com>
Date: Mon, 7 Oct 2019 11:31:45 -0400
Subject: [PATCH 3/3] lxd/resources/network: Add FirmwareVersion retrieval
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
---
 lxd/resources/network.go         |  6 ++++-
 lxd/resources/network_ethtool.go | 44 +++++++++++++++++++++++++++++++-
 2 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/lxd/resources/network.go b/lxd/resources/network.go
index 09d40f7e5c..96330c823c 100644
--- a/lxd/resources/network.go
+++ b/lxd/resources/network.go
@@ -242,10 +242,14 @@ func networkAddDeviceInfo(devicePath string, pciDB 
*pcidb.PCIDB, uname unix.Utsn
                                continue
                        }
 
-                       ethtoolAddInfo(info)
+                       ethtoolAddPortInfo(info)
 
                        card.Ports = append(card.Ports, *info)
                }
+
+               if len(card.Ports) > 0 {
+                       ethtoolAddCardInfo(card.Ports[0].ID, card)
+               }
        }
 
        return nil
diff --git a/lxd/resources/network_ethtool.go b/lxd/resources/network_ethtool.go
index f0a733079e..1ff8ed5d44 100644
--- a/lxd/resources/network_ethtool.go
+++ b/lxd/resources/network_ethtool.go
@@ -1,6 +1,7 @@
 package resources
 
 import (
+       "bytes"
        "unsafe"
 
        "github.com/pkg/errors"
@@ -90,12 +91,53 @@ type ethtoolCmd struct {
        reserved      [2]uint32
 }
 
+type ethtoolDrvInfo struct {
+       cmd         uint32
+       driver      [32]byte
+       version     [32]byte
+       fwVersion   [32]byte
+       busInfo     [32]byte
+       reserved1   [32]byte
+       reserved2   [16]byte
+       nStats      uint32
+       testinfoLen uint32
+       eedumpLen   uint32
+       regDumpLen  uint32
+}
+
 type ethtoolValue struct {
        cmd  uint32
        data uint32
 }
 
-func ethtoolAddInfo(info *api.ResourcesNetworkCardPort) error {
+func ethtoolAddCardInfo(name string, info *api.ResourcesNetworkCard) error {
+       // Open FD
+       ethtoolFd, err := unix.Socket(unix.AF_INET, unix.SOCK_DGRAM, 
unix.IPPROTO_IP)
+       if err != nil {
+               return errors.Wrap(err, "Failed to open IPPROTO_IP socket")
+       }
+       defer unix.Close(ethtoolFd)
+
+       // Driver info
+       ethDrvInfo := ethtoolDrvInfo{
+               cmd: 0x00000003,
+       }
+       req := ethtoolReq{
+               data: uintptr(unsafe.Pointer(&ethDrvInfo)),
+       }
+       copy(req.name[:], []byte(name))
+
+       _, _, errno := unix.Syscall(unix.SYS_IOCTL, uintptr(ethtoolFd), 
unix.SIOCETHTOOL, uintptr(unsafe.Pointer(&req)))
+       if errno != 0 {
+               return errors.Wrap(unix.Errno(errno), "Failed to 
ETHTOOL_GDRVINFO")
+       }
+
+       info.FirmwareVersion = string(bytes.Trim(ethDrvInfo.fwVersion[:], 
"\x00"))
+
+       return nil
+}
+
+func ethtoolAddPortInfo(info *api.ResourcesNetworkCardPort) error {
        // Open FD
        ethtoolFd, err := unix.Socket(unix.AF_INET, unix.SOCK_DGRAM, 
unix.IPPROTO_IP)
        if err != nil {
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to