[lxc-devel] [lxd/master] Storage: Fix VM unified image unpack for dir and btrfs drivers

tomponline on Github lxc-bot at linuxcontainers.org
Mon May 18 12:29:31 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 723 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200518/f57e0522/attachment.bin>
-------------- next part --------------
From 51b8879f617926ca57a5c543a57ee53385bce77d Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Mon, 18 May 2020 13:20:48 +0100
Subject: [PATCH 1/2] lxd/rsync: Adds optional rsync arguments to LocalCopy

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/rsync/rsync.go | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lxd/rsync/rsync.go b/lxd/rsync/rsync.go
index 6b18c743e1..8f811ff4f8 100644
--- a/lxd/rsync/rsync.go
+++ b/lxd/rsync/rsync.go
@@ -19,7 +19,7 @@ import (
 )
 
 // LocalCopy copies a directory using rsync (with the --devices option).
-func LocalCopy(source string, dest string, bwlimit string, xattrs bool) (string, error) {
+func LocalCopy(source string, dest string, bwlimit string, xattrs bool, rsyncArgs ...string) (string, error) {
 	err := os.MkdirAll(dest, 0755)
 	if err != nil {
 		return "", err
@@ -52,10 +52,15 @@ func LocalCopy(source string, dest string, bwlimit string, xattrs bool) (string,
 		args = append(args, "--bwlimit", bwlimit)
 	}
 
+	if len(rsyncArgs) > 0 {
+		args = append(args, rsyncArgs...)
+	}
+
 	args = append(args,
 		rsyncVerbosity,
 		shared.AddSlash(source),
 		dest)
+
 	msg, err := shared.RunCommand("rsync", args...)
 	if err != nil {
 		runError, ok := err.(shared.RunError)

From 54c54b7603e3d8c66fe7e20adf98042c6dbada67 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Mon, 18 May 2020 13:22:02 +0100
Subject: [PATCH 2/2] lxd/storage/utils: Fixes ImageUnpack to not erase
 generated rootfs block file when doing rsync

If the storage driver was either `dir` or `btrfs` then the generated rootfs block file was removed when unpacking unified tarballs.

This was silently erroring because the storage driver then went ahead and created a blank rootfs block file, but the resulting VM wasn't bootable.

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/storage/utils.go | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lxd/storage/utils.go b/lxd/storage/utils.go
index 587cc4b4c5..9ebcef3531 100644
--- a/lxd/storage/utils.go
+++ b/lxd/storage/utils.go
@@ -514,8 +514,9 @@ func ImageUnpack(imageFile, destPath, destBlockFile string, blockBackend, runnin
 			return errors.Wrapf(err, "Failed to remove %q", imgPath)
 		}
 
-		// Transfer the content.
-		_, err = rsync.LocalCopy(tempDir, destPath, "", true)
+		// Transfer the content excluding the destBlockFile name so that we don't delete the block file
+		// created above if the storage driver stores image files in the same directory as destPath.
+		_, err = rsync.LocalCopy(tempDir, destPath, "", true, "--exclude", filepath.Base(destBlockFile))
 		if err != nil {
 			return err
 		}


More information about the lxc-devel mailing list