[lxc-devel] [lxd/master] btrfs: workaround btrfs bug

brauner on Github lxc-bot at linuxcontainers.org
Mon Sep 25 15:51:18 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 748 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170925/2d9bdaa6/attachment.bin>
-------------- next part --------------
From 41bb04eb3c847ef2ef099a8aaf91a47acabfc13b Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Mon, 25 Sep 2017 17:48:13 +0200
Subject: [PATCH 1/2] btrfs: remove dependency on symlink

Only use the proper mountpoints on the storage pools.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 lxd/storage_btrfs.go | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/lxd/storage_btrfs.go b/lxd/storage_btrfs.go
index 2d791360d..9d8a32589 100644
--- a/lxd/storage_btrfs.go
+++ b/lxd/storage_btrfs.go
@@ -1832,8 +1832,6 @@ func (s *btrfsMigrationSourceDriver) SendWhileRunning(conn *websocket.Conn, op *
 
 		migrationSendSnapshot := fmt.Sprintf("%s/.migration-send", tmpContainerMntPoint)
 		snapshotMntPoint := getSnapshotMountPoint(containerPool, containerName)
-		if s.container.IsSnapshot() {
-		}
 		err = s.btrfs.btrfsPoolVolumesSnapshot(snapshotMntPoint, migrationSendSnapshot, true)
 		if err != nil {
 			return err
@@ -1888,14 +1886,17 @@ func (s *btrfsMigrationSourceDriver) SendWhileRunning(conn *websocket.Conn, op *
 }
 
 func (s *btrfsMigrationSourceDriver) SendAfterCheckpoint(conn *websocket.Conn, bwlimit string) error {
-	tmpPath := containerPath(fmt.Sprintf("%s/.migration-send", s.container.Name()), true)
+	tmpPath := getSnapshotMountPoint(s.btrfs.pool.Name,
+		fmt.Sprintf("%s/.migration-send", s.container.Name()))
 	err := os.MkdirAll(tmpPath, 0700)
 	if err != nil {
 		return err
 	}
 
 	s.stoppedSnapName = fmt.Sprintf("%s/.root", tmpPath)
-	err = s.btrfs.btrfsPoolVolumesSnapshot(s.container.Path(), s.stoppedSnapName, true)
+	parentName, _, _ := containerGetParentAndSnapshotName(s.container.Name())
+	containerMntPt := getContainerMountPoint(s.btrfs.pool.Name, parentName)
+	err = s.btrfs.btrfsPoolVolumesSnapshot(containerMntPt, s.stoppedSnapName, true)
 	if err != nil {
 		return err
 	}
@@ -1956,7 +1957,7 @@ func (s *storageBtrfs) MigrationSource(c container, containerOnly bool) (Migrati
 
 	if !containerOnly {
 		for _, snap := range snapshots {
-			btrfsPath := snap.Path()
+			btrfsPath := getSnapshotMountPoint(s.pool.Name, snap.Name())
 			driver.btrfsSnapshotNames = append(driver.btrfsSnapshotNames, btrfsPath)
 		}
 	}

From 85fdec4de93db6ceede914dc1c9b6aff09b4254c Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Mon, 25 Sep 2017 17:48:44 +0200
Subject: [PATCH 2/2] btrfs: workaround btrfs bug

It seems that btrfs v4.12.1 allows:

        (1) btrfs send -p <ro-snap-1> <ro-snap-0>

but disallows

        (2) btrfs send <ro-snap-0> -p <ro-snap-1>

Code-wise it assumes that <ro-snap-1> is always found at optind == 1. I
reported upstream and might patch this once they told me which direction they
want to go with this. Until then, work around it.

Closes #3843.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 lxd/storage_btrfs.go | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lxd/storage_btrfs.go b/lxd/storage_btrfs.go
index 9d8a32589..06d0c924b 100644
--- a/lxd/storage_btrfs.go
+++ b/lxd/storage_btrfs.go
@@ -1766,10 +1766,11 @@ func (s *btrfsMigrationSourceDriver) Snapshots() []container {
 }
 
 func (s *btrfsMigrationSourceDriver) send(conn *websocket.Conn, btrfsPath string, btrfsParent string, readWrapper func(io.ReadCloser) io.ReadCloser) error {
-	args := []string{"send", btrfsPath}
+	args := []string{"send"}
 	if btrfsParent != "" {
 		args = append(args, "-p", btrfsParent)
 	}
+	args = append(args, btrfsPath)
 
 	cmd := exec.Command("btrfs", args...)
 


More information about the lxc-devel mailing list