[lxc-devel] [lxd/master] Bugfixes

stgraber on Github lxc-bot at linuxcontainers.org
Mon Mar 6 20:32:43 UTC 2017


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/20170306/507d0357/attachment.bin>
-------------- next part --------------
From fa8ca6cd7f34776a13d31f55b1bc9c3524616057 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 6 Mar 2017 13:37:46 -0500
Subject: [PATCH 1/2] storage: Harden the btrfs migration code
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #3024

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/patches.go | 23 ++++++++++++-----------
 lxd/storage.go |  1 -
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/lxd/patches.go b/lxd/patches.go
index e51443c..421994e 100644
--- a/lxd/patches.go
+++ b/lxd/patches.go
@@ -381,7 +381,7 @@ func upgradeFromStorageTypeBtrfs(name string, d *Daemon, defaultPoolName string,
 		// mv ${LXD_DIR}/containers/<container_name> ${LXD_DIR}/storage-pools/<pool>/<container_name>
 		oldContainerMntPoint := shared.VarPath("containers", ct)
 		newContainerMntPoint := getContainerMountPoint(defaultPoolName, ct)
-		if shared.PathExists(oldContainerMntPoint) {
+		if shared.PathExists(oldContainerMntPoint) && !shared.PathExists(newContainerMntPoint) {
 			err = os.Rename(oldContainerMntPoint, newContainerMntPoint)
 			if err != nil {
 				return err
@@ -451,15 +451,17 @@ func upgradeFromStorageTypeBtrfs(name string, d *Daemon, defaultPoolName string,
 			// readonly snapshots.
 			oldSnapshotMntPoint := shared.VarPath("snapshots", cs)
 			newSnapshotMntPoint := getSnapshotMountPoint(defaultPoolName, cs)
-			err = btrfsSnapshot(oldSnapshotMntPoint, newSnapshotMntPoint, true)
-			if err != nil {
-				return err
-			}
+			if shared.PathExists(oldSnapshotMntPoint) && !shared.PathExists(newSnapshotMntPoint) {
+				err = btrfsSnapshot(oldSnapshotMntPoint, newSnapshotMntPoint, true)
+				if err != nil {
+					return err
+				}
 
-			// Delete the old subvolume.
-			err = btrfsSubVolumesDelete(oldSnapshotMntPoint)
-			if err != nil {
-				return err
+				// Delete the old subvolume.
+				err = btrfsSubVolumesDelete(oldSnapshotMntPoint)
+				if err != nil {
+					return err
+				}
 			}
 		}
 
@@ -478,7 +480,6 @@ func upgradeFromStorageTypeBtrfs(name string, d *Daemon, defaultPoolName string,
 				}
 			}
 		}
-
 	}
 
 	// Insert storage volumes for images into the database. Images don't
@@ -520,7 +521,7 @@ func upgradeFromStorageTypeBtrfs(name string, d *Daemon, defaultPoolName string,
 
 		oldImageMntPoint := shared.VarPath("images", img+".btrfs")
 		newImageMntPoint := getImageMountPoint(defaultPoolName, img)
-		if shared.PathExists(oldImageMntPoint) {
+		if shared.PathExists(oldImageMntPoint) && !shared.PathExists(newImageMntPoint) {
 			err := os.Rename(oldImageMntPoint, newImageMntPoint)
 			if err != nil {
 				return err
diff --git a/lxd/storage.go b/lxd/storage.go
index 188037c..fb34784 100644
--- a/lxd/storage.go
+++ b/lxd/storage.go
@@ -480,7 +480,6 @@ func createContainerMountpoint(mountPoint string, mountPointSymlink string, priv
 		if err != nil {
 			return err
 		}
-
 	}
 
 	err = os.Chmod(mountPoint, mode)

From 544e129b870d96f5ac70377e996f956bc50731b4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 6 Mar 2017 14:56:57 -0500
Subject: [PATCH 2/2] storage: Deal with source not being btrfs
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #3024

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

diff --git a/lxd/patches.go b/lxd/patches.go
index 421994e..0827a2a 100644
--- a/lxd/patches.go
+++ b/lxd/patches.go
@@ -384,7 +384,24 @@ func upgradeFromStorageTypeBtrfs(name string, d *Daemon, defaultPoolName string,
 		if shared.PathExists(oldContainerMntPoint) && !shared.PathExists(newContainerMntPoint) {
 			err = os.Rename(oldContainerMntPoint, newContainerMntPoint)
 			if err != nil {
-				return err
+				err := btrfsSubVolumeCreate(newContainerMntPoint)
+				if err != nil {
+					return err
+				}
+
+				output, err := storageRsyncCopy(oldContainerMntPoint, newContainerMntPoint)
+				if err != nil {
+					shared.LogErrorf("Failed to rsync: %s: %s.", output, err)
+					return err
+				}
+
+				btrfsSubVolumesDelete(oldContainerMntPoint)
+				if shared.PathExists(oldContainerMntPoint) {
+					err = os.RemoveAll(oldContainerMntPoint)
+					if err != nil {
+						return err
+					}
+				}
 			}
 		}
 
@@ -454,13 +471,30 @@ func upgradeFromStorageTypeBtrfs(name string, d *Daemon, defaultPoolName string,
 			if shared.PathExists(oldSnapshotMntPoint) && !shared.PathExists(newSnapshotMntPoint) {
 				err = btrfsSnapshot(oldSnapshotMntPoint, newSnapshotMntPoint, true)
 				if err != nil {
-					return err
-				}
+					err := btrfsSubVolumeCreate(newSnapshotMntPoint)
+					if err != nil {
+						return err
+					}
 
-				// Delete the old subvolume.
-				err = btrfsSubVolumesDelete(oldSnapshotMntPoint)
-				if err != nil {
-					return err
+					output, err := storageRsyncCopy(oldSnapshotMntPoint, newSnapshotMntPoint)
+					if err != nil {
+						shared.LogErrorf("Failed to rsync: %s: %s.", output, err)
+						return err
+					}
+
+					btrfsSubVolumesDelete(oldSnapshotMntPoint)
+					if shared.PathExists(oldSnapshotMntPoint) {
+						err = os.RemoveAll(oldSnapshotMntPoint)
+						if err != nil {
+							return err
+						}
+					}
+				} else {
+					// Delete the old subvolume.
+					err = btrfsSubVolumesDelete(oldSnapshotMntPoint)
+					if err != nil {
+						return err
+					}
 				}
 			}
 		}


More information about the lxc-devel mailing list