[lxc-devel] [lxd/master] Improve error handling

stgraber on Github lxc-bot at linuxcontainers.org
Tue Nov 6 16:42:14 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20181106/e486e8bc/attachment.bin>
-------------- next part --------------
From f0fce262aa684a337f9184bd47808c6665a4a50a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 5 Nov 2018 20:25:07 -0500
Subject: [PATCH 1/2] lxd/storage: Improve loop device errors
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/storage_cgo.go | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lxd/storage_cgo.go b/lxd/storage_cgo.go
index b0a3be5a17..7ffddd2e4d 100644
--- a/lxd/storage_cgo.go
+++ b/lxd/storage_cgo.go
@@ -307,9 +307,10 @@ func prepareLoopDev(source string, flags int) (*os.File, error) {
 	loopFd, err := C.prepare_loop_dev(cSource, (*C.char)(cLoopDev), C.int(flags))
 	if loopFd < 0 {
 		if err != nil {
-			return nil, fmt.Errorf("Failed to prepare loop device: %s", err)
+			return nil, fmt.Errorf("Failed to prepare loop device for '%s': %s", source, err)
 		}
-		return nil, fmt.Errorf("Failed to prepare loop device")
+
+		return nil, fmt.Errorf("Failed to prepare loop device for '%s'", source)
 	}
 
 	return os.NewFile(uintptr(loopFd), C.GoString((*C.char)(cLoopDev))), nil

From a42c9bf44765dbd27d0a423eecc71651cbb36734 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 6 Nov 2018 11:41:37 -0500
Subject: [PATCH 2/2] lxd/containers: Detect root disk pool changes
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/container_lxc.go | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 394e8e83e3..57e6d57da0 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -4111,6 +4111,13 @@ func (c *containerLXC) Update(args db.ContainerArgs, userRequested bool) error {
 		}
 	}
 
+	// Check for pool change
+	oldRootDiskDevicePool := oldExpandedDevices[oldRootDiskDeviceKey]["pool"]
+	newRootDiskDevicePool := c.expandedDevices[newRootDiskDeviceKey]["pool"]
+	if oldRootDiskDevicePool != newRootDiskDevicePool {
+		return fmt.Errorf("The storage pool of the root disk can only be changed through move")
+	}
+
 	// Deal with quota changes
 	oldRootDiskDeviceSize := oldExpandedDevices[oldRootDiskDeviceKey]["size"]
 	newRootDiskDeviceSize := c.expandedDevices[newRootDiskDeviceKey]["size"]


More information about the lxc-devel mailing list