The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/7536

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
When migrating a snapshot to a main volume and using optimised transfer method, the original snapshot is also transferred.

We need to delete this, as it is not needed.

Fixes #7532

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
From 9679d8cd094f93be09fed09608b9b87f2f1548b1 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Tue, 16 Jun 2020 14:59:49 +0100
Subject: [PATCH] lxd/storage/drivers/driver/zfs/volumes: Remove snapshot when
 migrating as main volume

When migrating a snapshot to a main volume and using optimized transfer method, 
the original snapshot is also transferred.

We need to delete this, as it is not needed.

Fixes #7532

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/storage/drivers/driver_zfs_volumes.go | 28 +++++++++++++++++++----
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/lxd/storage/drivers/driver_zfs_volumes.go 
b/lxd/storage/drivers/driver_zfs_volumes.go
index 43caa00a55..3741c9f71b 100644
--- a/lxd/storage/drivers/driver_zfs_volumes.go
+++ b/lxd/storage/drivers/driver_zfs_volumes.go
@@ -646,13 +646,31 @@ func (d *zfs) CreateVolumeFromMigration(vol Volume, conn 
io.ReadWriteCloser, vol
                return err
        }
 
-       // Filter only the snapshots.
-       for _, entry := range entries {
-               if strings.HasPrefix(entry, "@snapshot-") {
-                       continue
+       // keepDataset returns whether to keep the data set or delete it. Data 
sets that are non-snapshots or
+       // snapshots that match the requested snapshots in 
volTargetArgs.Snapshots are kept. Any other snapshot
+       // data sets should be removed.
+       keepDataset := func(dataSetName string) bool {
+               // Keep non-snapshot data sets and snapshots that don't have 
the LXD snapshot prefix indicator.
+               dataSetSnapshotPrefix := "@snapshot-"
+               if !strings.HasPrefix(dataSetName, "@") || 
!strings.HasPrefix(dataSetName, dataSetSnapshotPrefix) {
+                       return false
+               }
+
+               // Check if snapshot data set matches one of the requested 
snapshots in volTargetArgs.Snapshots.
+               // If so, then keep it, otherwise request it be removed.
+               entrySnapName := strings.TrimPrefix(dataSetName, 
dataSetSnapshotPrefix)
+               for _, snapName := range volTargetArgs.Snapshots {
+                       if entrySnapName == snapName {
+                               return true // Keep snapshot data set if 
present in the requested snapshots list.
+                       }
                }
 
-               if strings.HasPrefix(entry, "@") {
+               return false // Delete any other snapshot data sets that have 
been transferred.
+       }
+
+       // Remove any snapshots that were transferred but are not needed.
+       for _, entry := range entries {
+               if !keepDataset(entry) {
                        _, err := shared.RunCommand("zfs", "destroy", 
fmt.Sprintf("%s%s", d.dataset(vol, false), entry))
                        if err != nil {
                                return err
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to