[lxc-devel] [lxd/master] container backup: fixes

brauner on Github lxc-bot at linuxcontainers.org
Tue May 15 14:10:22 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 364 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180515/bbfa91ed/attachment.bin>
-------------- next part --------------
From ba13954d9ada7c69436e5bcccf4f2e0a2bb7e5b6 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 15 May 2018 16:04:39 +0200
Subject: [PATCH 1/2] storage: handle ContainerRename() correctly

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 lxd/storage_btrfs.go | 11 +++++++++++
 lxd/storage_ceph.go  | 11 +++++++++++
 lxd/storage_dir.go   | 18 +++++++++---------
 lxd/storage_zfs.go   | 11 +++++++++++
 4 files changed, 42 insertions(+), 9 deletions(-)

diff --git a/lxd/storage_btrfs.go b/lxd/storage_btrfs.go
index 8679a28d9..f099b5f25 100644
--- a/lxd/storage_btrfs.go
+++ b/lxd/storage_btrfs.go
@@ -1092,6 +1092,17 @@ func (s *storageBtrfs) ContainerRename(container container, newName string) erro
 		}
 	}
 
+	backups, err := container.Backups()
+	if err != nil {
+		return err
+	}
+
+	for _, backup := range backups {
+		backupName := strings.Split(backup.Name(), "/")[1]
+		newName := fmt.Sprintf("%s/%s", newName, backupName)
+		s.ContainerBackupRename(backup, newName)
+	}
+
 	logger.Debugf("Renamed BTRFS storage volume for container \"%s\" from %s -> %s.", s.volume.Name, s.volume.Name, newName)
 	return nil
 }
diff --git a/lxd/storage_ceph.go b/lxd/storage_ceph.go
index c9d250fc4..ae4448d1c 100644
--- a/lxd/storage_ceph.go
+++ b/lxd/storage_ceph.go
@@ -1603,6 +1603,17 @@ func (s *storageCeph) ContainerRename(c container, newName string) error {
 		}
 	}
 
+	backups, err := c.Backups()
+	if err != nil {
+		return err
+	}
+
+	for _, backup := range backups {
+		backupName := strings.Split(backup.Name(), "/")[1]
+		newName := fmt.Sprintf("%s/%s", newName, backupName)
+		s.ContainerBackupRename(backup, newName)
+	}
+
 	logger.Debugf(`Renamed RBD storage volume for container "%s" from `+
 		`"%s" to "%s"`, oldName, oldName, newName)
 
diff --git a/lxd/storage_dir.go b/lxd/storage_dir.go
index 6807c062a..47b771979 100644
--- a/lxd/storage_dir.go
+++ b/lxd/storage_dir.go
@@ -794,15 +794,15 @@ func (s *storageDir) ContainerRename(container container, newName string) error
 		}
 	}
 
-	// Rename the backup mountpoint for the container if existing:
-	// ${POOL}/backups/<old_container_name> to ${POOL}/backups/<new_container_name>
-	oldBackupsMntPoint := getBackupMountPoint(s.pool.Name, container.Name())
-	newBackupsMntPoint := getBackupMountPoint(s.pool.Name, newName)
-	if shared.PathExists(oldBackupsMntPoint) {
-		err = os.Rename(oldBackupsMntPoint, newBackupsMntPoint)
-		if err != nil {
-			return err
-		}
+	backups, err := container.Backups()
+	if err != nil {
+		return err
+	}
+
+	for _, backup := range backups {
+		backupName := strings.Split(backup.Name(), "/")[1]
+		newName := fmt.Sprintf("%s/%s", newName, backupName)
+		s.ContainerBackupRename(backup, newName)
 	}
 
 	logger.Debugf("Renamed DIR storage volume for container \"%s\" from %s -> %s.", s.volume.Name, s.volume.Name, newName)
diff --git a/lxd/storage_zfs.go b/lxd/storage_zfs.go
index bed06c0f7..48d5e8f48 100644
--- a/lxd/storage_zfs.go
+++ b/lxd/storage_zfs.go
@@ -1335,6 +1335,17 @@ func (s *storageZfs) ContainerRename(container container, newName string) error
 		}
 	}
 
+	backups, err := container.Backups()
+	if err != nil {
+		return err
+	}
+
+	for _, backup := range backups {
+		backupName := strings.Split(backup.Name(), "/")[1]
+		newName := fmt.Sprintf("%s/%s", newName, backupName)
+		s.ContainerBackupRename(backup, newName)
+	}
+
 	revert = false
 
 	logger.Debugf("Renamed ZFS storage volume for container \"%s\" from %s -> %s.", s.volume.Name, s.volume.Name, newName)

From 4c8bb8ca98bb806d163ccec6ac6aa0253773629d Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 15 May 2018 16:09:33 +0200
Subject: [PATCH 2/2] storage: handle ContainerDelete() correctly

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 lxd/storage_btrfs.go | 10 ++++++++++
 lxd/storage_ceph.go  | 10 ++++++++++
 lxd/storage_dir.go   | 21 ++++++---------------
 lxd/storage_zfs.go   | 17 ++++++++++++++++-
 4 files changed, 42 insertions(+), 16 deletions(-)

diff --git a/lxd/storage_btrfs.go b/lxd/storage_btrfs.go
index f099b5f25..a97682345 100644
--- a/lxd/storage_btrfs.go
+++ b/lxd/storage_btrfs.go
@@ -889,6 +889,16 @@ func (s *storageBtrfs) ContainerDelete(container container) error {
 		}
 	}
 
+	backups, err := container.Backups()
+	if err != nil {
+		return err
+	}
+
+	for _, backup := range backups {
+		backupName := strings.Split(backup.Name(), "/")[1]
+		s.ContainerBackupDelete(backupName)
+	}
+
 	logger.Debugf("Deleted BTRFS storage volume for container \"%s\" on storage pool \"%s\".", s.volume.Name, s.pool.Name)
 	return nil
 }
diff --git a/lxd/storage_ceph.go b/lxd/storage_ceph.go
index ae4448d1c..65d4e40ce 100644
--- a/lxd/storage_ceph.go
+++ b/lxd/storage_ceph.go
@@ -1069,6 +1069,16 @@ func (s *storageCeph) ContainerDelete(container container) error {
 		`container "%s" for RBD storage volume on storage pool "%s"`,
 		containerMntPoint, containerName, s.pool.Name)
 
+	backups, err := container.Backups()
+	if err != nil {
+		return err
+	}
+
+	for _, backup := range backups {
+		backupName := strings.Split(backup.Name(), "/")[1]
+		s.ContainerBackupDelete(backupName)
+	}
+
 	logger.Debugf(`Deleted RBD storage volume for container "%s" on `+
 		`storage pool "%s"`, containerName, s.pool.Name)
 	return nil
diff --git a/lxd/storage_dir.go b/lxd/storage_dir.go
index 47b771979..730138f5b 100644
--- a/lxd/storage_dir.go
+++ b/lxd/storage_dir.go
@@ -592,23 +592,14 @@ func (s *storageDir) ContainerDelete(container container) error {
 		}
 	}
 
-	// Delete potential leftover backup mountpoints.
-	backupMntPoint := getBackupMountPoint(s.pool.Name, container.Name())
-	if shared.PathExists(backupMntPoint) {
-		err := os.RemoveAll(backupMntPoint)
-		if err != nil {
-			return err
-		}
+	backups, err := container.Backups()
+	if err != nil {
+		return err
 	}
 
-	// Delete potential leftover backup symlinks:
-	// ${LXD_DIR}/backups/<container_name> -> ${POOL}/backups/<container_name>
-	backupSymlink := shared.VarPath("backups", container.Name())
-	if shared.PathExists(backupSymlink) {
-		err := os.Remove(backupSymlink)
-		if err != nil {
-			return err
-		}
+	for _, backup := range backups {
+		backupName := strings.Split(backup.Name(), "/")[1]
+		s.ContainerBackupDelete(backupName)
 	}
 
 	logger.Debugf("Deleted DIR storage volume for container \"%s\" on storage pool \"%s\".", s.volume.Name, s.pool.Name)
diff --git a/lxd/storage_zfs.go b/lxd/storage_zfs.go
index 48d5e8f48..b441c393e 100644
--- a/lxd/storage_zfs.go
+++ b/lxd/storage_zfs.go
@@ -877,7 +877,22 @@ func (s *storageZfs) ContainerCanRestore(container container, sourceContainer co
 }
 
 func (s *storageZfs) ContainerDelete(container container) error {
-	return s.doContainerDelete(container.Name())
+	err := s.doContainerDelete(container.Name())
+	if err != nil {
+		return err
+	}
+
+	backups, err := container.Backups()
+	if err != nil {
+		return err
+	}
+
+	for _, backup := range backups {
+		backupName := strings.Split(backup.Name(), "/")[1]
+		s.ContainerBackupDelete(backupName)
+	}
+
+	return nil
 }
 
 func (s *storageZfs) copyWithoutSnapshotsSparse(target container, source container) error {


More information about the lxc-devel mailing list