[lxc-devel] [lxd/master] lxd/storage/btrfs: Fix recursive snapshots

stgraber on Github lxc-bot at linuxcontainers.org
Mon Jul 9 18:14:14 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 370 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180709/091dd058/attachment.bin>
-------------- next part --------------
From 866f48b8ee239366770b5e1cd45e56978d4da49d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 9 Jul 2018 14:13:15 -0400
Subject: [PATCH] lxd/storage/btrfs: Fix recursive snapshots
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #4731

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

diff --git a/lxd/storage_btrfs.go b/lxd/storage_btrfs.go
index 54666d2cd..17f6038bb 100644
--- a/lxd/storage_btrfs.go
+++ b/lxd/storage_btrfs.go
@@ -2232,12 +2232,6 @@ func (s *storageBtrfs) btrfsPoolVolumeSnapshot(source string, dest string, reado
 }
 
 func (s *storageBtrfs) btrfsPoolVolumesSnapshot(source string, dest string, readonly bool, recursive bool) error {
-	// First snapshot the root
-	err := s.btrfsPoolVolumeSnapshot(source, dest, readonly)
-	if err != nil {
-		return err
-	}
-
 	// Now snapshot all subvolumes of the root.
 	if recursive {
 		// Get a list of subvolumes of the root
@@ -2255,6 +2249,12 @@ func (s *storageBtrfs) btrfsPoolVolumesSnapshot(source string, dest string, read
 			logger.Warnf("Subvolumes detected, ignoring ro flag")
 		}
 
+		// First snapshot the root
+		err = s.btrfsPoolVolumeSnapshot(source, dest, readonly)
+		if err != nil {
+			return err
+		}
+
 		for _, subsubvol := range subsubvols {
 			// Clear the target for the subvol to use
 			os.Remove(path.Join(dest, subsubvol))
@@ -2264,6 +2264,11 @@ func (s *storageBtrfs) btrfsPoolVolumesSnapshot(source string, dest string, read
 				return err
 			}
 		}
+	} else {
+		err := s.btrfsPoolVolumeSnapshot(source, dest, readonly)
+		if err != nil {
+			return err
+		}
 	}
 
 	return nil


More information about the lxc-devel mailing list