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

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 b37c0705def278447eb5a0908386c1720ea646f7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com>
Date: Mon, 16 Sep 2019 09:48:07 +0200
Subject: [PATCH 1/2] lxd/resources: Don't fail on non-ATA drives
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/storage.go | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/lxd/resources/storage.go b/lxd/resources/storage.go
index 0a0fe6a1ad..24ce38ec46 100644
--- a/lxd/resources/storage.go
+++ b/lxd/resources/storage.go
@@ -22,11 +22,7 @@ var sysClassBlock = "/sys/class/block"
 func storageAddDriveInfo(devicePath string, disk *api.ResourcesStorageDisk) 
error {
        // Attempt to open the device path
        f, err := os.Open(devicePath)
-       if err != nil {
-               if !os.IsPermission(err) && !os.IsNotExist(err) {
-                       return err
-               }
-       } else {
+       if err == nil {
                defer f.Close()
                fd := int(f.Fd())
 

From 16665a3cfe271e573d9e28a6dc18500a74f89d75 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com>
Date: Mon, 16 Sep 2019 09:48:42 +0200
Subject: [PATCH 2/2] lxd/resources: Cleanup disk type and add cdrom
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/storage.go | 48 +++++++++++++++++++++-------------------
 1 file changed, 25 insertions(+), 23 deletions(-)

diff --git a/lxd/resources/storage.go b/lxd/resources/storage.go
index 24ce38ec46..b62c4f8052 100644
--- a/lxd/resources/storage.go
+++ b/lxd/resources/storage.go
@@ -45,6 +45,7 @@ func storageAddDriveInfo(devicePath string, disk 
*api.ResourcesStorageDisk) erro
                }
                defer f.Close()
 
+               udevProperties := map[string]string{}
                udevInfo := bufio.NewScanner(f)
                for udevInfo.Scan() {
                        line := strings.TrimSpace(udevInfo.Text())
@@ -60,35 +61,36 @@ func storageAddDriveInfo(devicePath string, disk 
*api.ResourcesStorageDisk) erro
 
                        key := strings.TrimSpace(fields[0])
                        value := strings.TrimSpace(fields[1])
+                       udevProperties[key] = value
+               }
 
-                       // Finer grained disk type
-                       if key == "E:ID_ATA_SATA" && value == "1" {
-                               disk.Type = "sata"
-                       }
+               // Finer grained disk type
+               if udevProperties["E:ID_CDROM"] == "1" {
+                       disk.Type = "cdrom"
+               } else if udevProperties["E:ID_USB_DRIVER"] == "usb-storage" {
+                       disk.Type = "usb"
+               } else if udevProperties["E:ID_ATA_SATA"] == "1" {
+                       disk.Type = "sata"
+               }
 
-                       if key == "E:ID_USB_DRIVER" && value == "usb-storage" {
-                               disk.Type = "usb"
-                       }
+               // Model revision number
+               if udevProperties["E:ID_REVISION"] != "" && disk.ModelRevision 
== "" {
+                       disk.ModelRevision = udevProperties["E:ID_REVISION"]
+               }
 
-                       // Model revision number
-                       if key == "E:ID_REVISION" && disk.ModelRevision == "" {
-                               disk.ModelRevision = value
-                       }
+               // Serial number
+               if udevProperties["E:ID_SERIAL_SHORT"] != "" && disk.Serial == 
"" {
+                       disk.Serial = udevProperties["E:ID_SERIAL_SHORT"]
+               }
 
-                       // Serial number
-                       if key == "E:ID_SERIAL_SHORT" && disk.Serial == "" {
-                               disk.Serial = value
+               // Rotation per minute
+               if udevProperties["E:ID_ATA_ROTATION_RATE_RPM"] != "" && 
disk.RPM == 0 {
+                       valueUint, err := 
strconv.ParseUint(udevProperties["E:ID_ATA_ROTATION_RATE_RPM"], 10, 64)
+                       if err != nil {
+                               return errors.Wrap(err, "Failed to parse RPM 
value")
                        }
 
-                       // Rotation per minute
-                       if key == "E:ID_ATA_ROTATION_RATE_RPM" && disk.RPM == 0 
{
-                               valueUint, err := strconv.ParseUint(value, 10, 
64)
-                               if err != nil {
-                                       return errors.Wrap(err, "Failed to 
parse RPM value")
-                               }
-
-                               disk.RPM = valueUint
-                       }
+                       disk.RPM = valueUint
                }
        }
 
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to