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

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) ===
Lets not completely fail startup/update on things the user cannot do
anything about. It's almost impossible to know what devices we can set
block limits on, so if we can't, just move on.

Closes #1568

Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
From af1239c6d8fa46838bff758823cdbddaff906fea Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com>
Date: Fri, 5 Feb 2016 09:11:44 +0100
Subject: [PATCH] Make blkio limits more robust
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Lets not completely fail startup/update on things the user cannot do
anything about. It's almost impossible to know what devices we can set
block limits on, so if we can't, just move on.

Closes #1568

Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
---
 lxd/container_lxc.go | 68 +++++++++++++++++++++++++++++++++-------------------
 1 file changed, 43 insertions(+), 25 deletions(-)

diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 325bb41..50a21dd 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -563,37 +563,51 @@ func (c *containerLXC) initLXC() error {
                        }
                }
 
-               diskLimits, err := c.getDiskLimits()
-               if err != nil {
-                       return err
+               hasDiskLimits := false
+               for _, m := range c.expandedDevices {
+                       if m["type"] != "disk" {
+                               continue
+                       }
+
+                       if m["limits.read"] != "" || m["limits.write"] != "" || 
m["limits.max"] != "" {
+                               hasDiskLimits = true
+                               break
+                       }
                }
 
-               for block, limit := range diskLimits {
-                       if limit.readBps > 0 {
-                               err = lxcSetConfigItem(cc, 
"lxc.cgroup.blkio.throttle.read_bps_device", fmt.Sprintf("%s %d", block, 
limit.readBps))
-                               if err != nil {
-                                       return err
-                               }
+               if hasDiskLimits {
+                       diskLimits, err := c.getDiskLimits()
+                       if err != nil {
+                               return err
                        }
 
-                       if limit.readIops > 0 {
-                               err = lxcSetConfigItem(cc, 
"lxc.cgroup.blkio.throttle.read_iops_device", fmt.Sprintf("%s %d", block, 
limit.readIops))
-                               if err != nil {
-                                       return err
+                       for block, limit := range diskLimits {
+                               if limit.readBps > 0 {
+                                       err = lxcSetConfigItem(cc, 
"lxc.cgroup.blkio.throttle.read_bps_device", fmt.Sprintf("%s %d", block, 
limit.readBps))
+                                       if err != nil {
+                                               return err
+                                       }
                                }
-                       }
 
-                       if limit.writeBps > 0 {
-                               err = lxcSetConfigItem(cc, 
"lxc.cgroup.blkio.throttle.write_bps_device", fmt.Sprintf("%s %d", block, 
limit.writeBps))
-                               if err != nil {
-                                       return err
+                               if limit.readIops > 0 {
+                                       err = lxcSetConfigItem(cc, 
"lxc.cgroup.blkio.throttle.read_iops_device", fmt.Sprintf("%s %d", block, 
limit.readIops))
+                                       if err != nil {
+                                               return err
+                                       }
                                }
-                       }
 
-                       if limit.writeIops > 0 {
-                               err = lxcSetConfigItem(cc, 
"lxc.cgroup.blkio.throttle.write_iops_device", fmt.Sprintf("%s %d", block, 
limit.writeIops))
-                               if err != nil {
-                                       return err
+                               if limit.writeBps > 0 {
+                                       err = lxcSetConfigItem(cc, 
"lxc.cgroup.blkio.throttle.write_bps_device", fmt.Sprintf("%s %d", block, 
limit.writeBps))
+                                       if err != nil {
+                                               return err
+                                       }
+                               }
+
+                               if limit.writeIops > 0 {
+                                       err = lxcSetConfigItem(cc, 
"lxc.cgroup.blkio.throttle.write_iops_device", fmt.Sprintf("%s %d", block, 
limit.writeIops))
+                                       if err != nil {
+                                               return err
+                                       }
                                }
                        }
                }
@@ -3508,14 +3522,18 @@ func (c *containerLXC) getDiskLimits() 
(map[string]deviceBlockLimit, error) {
                device := deviceBlockLimit{readBps: readBps, readIops: 
readIops, writeBps: writeBps, writeIops: writeIops}
 
                for _, block := range blocks {
-                       dev := strings.TrimPrefix(block, "/dev/")
+                       if !strings.HasPrefix(block, "/dev/") {
+                               continue
+                       }
 
+                       dev := strings.TrimPrefix(block, "/dev/")
                        if strings.Contains(dev, "/") {
                                continue
                        }
 
                        if 
!shared.PathExists(fmt.Sprintf("/sys/class/block/%s/dev", dev)) {
-                               return nil, fmt.Errorf("Disk %s is missing 
/sys/class/block entry", dev)
+                               shared.Log.Error("Disk is missing 
/sys/class/block entry", log.Ctx{"device": dev})
+                               continue
                        }
 
                        block, err := 
ioutil.ReadFile(fmt.Sprintf("/sys/class/block/%s/dev", dev))
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to