[lxc-devel] [lxd/master] lxd/storage/btrfs: Fix migration from snapshot

stgraber on Github lxc-bot at linuxcontainers.org
Thu May 7 21:25:33 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200507/78397936/attachment.bin>
-------------- next part --------------
From d5c19186f2b8339b55f1fb7e96121d8c7d4795f6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 7 May 2020 17:25:05 -0400
Subject: [PATCH] lxd/storage/btrfs: Fix migration from snapshot
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/drivers/driver_btrfs_utils.go   | 8 ++++++++
 lxd/storage/drivers/driver_btrfs_volumes.go | 5 ++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/lxd/storage/drivers/driver_btrfs_utils.go b/lxd/storage/drivers/driver_btrfs_utils.go
index a9b897701d..6ce0fbac91 100644
--- a/lxd/storage/drivers/driver_btrfs_utils.go
+++ b/lxd/storage/drivers/driver_btrfs_utils.go
@@ -484,6 +484,14 @@ func (d *btrfs) metadataHeader(vol Volume, snapshots []string) (*BTRFSMetaDataHe
 		return nil, err
 	}
 
+	// If vol is a snapshot itself, we need to fixup the metadata.
+	if vol.IsSnapshot() {
+		subVols[0].Readonly = false
+		for i := range subVols {
+			subVols[i].Snapshot = ""
+		}
+	}
+
 	migrationHeader.Subvolumes = append(migrationHeader.Subvolumes, subVols...)
 	return &migrationHeader, nil
 }
diff --git a/lxd/storage/drivers/driver_btrfs_volumes.go b/lxd/storage/drivers/driver_btrfs_volumes.go
index 2dbb3361d8..bdac8afacc 100644
--- a/lxd/storage/drivers/driver_btrfs_volumes.go
+++ b/lxd/storage/drivers/driver_btrfs_volumes.go
@@ -728,7 +728,10 @@ func (d *btrfs) MigrateVolume(vol Volume, conn io.ReadWriteCloser, volSrcArgs *m
 	// sendVolume sends a volume and its subvolumes (if negotiated subvolumes feature) to recipient.
 	sendVolume := func(v Volume, sourcePrefix string, parentPrefix string) error {
 		snapName := "" // Default to empty if volume isn't a snapshot and is main volume.
-		if v.IsSnapshot() {
+
+		// Detect snapshot by comparing to main volume.
+		// We can't use IsSnapshot() as the main vol may itself be a snapshot.
+		if v.name != vol.name {
 			_, snapName, _ = shared.InstanceGetParentAndSnapshotName(v.name)
 		}
 


More information about the lxc-devel mailing list