[lxc-devel] [lxd/master] Fix hyphenated container names when creating backups

monstermunchkin on Github lxc-bot at linuxcontainers.org
Mon Dec 9 16:26:49 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 318 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20191209/6cc46ddd/attachment.bin>
-------------- next part --------------
From 191864ebf6b5d87ecbb577ebda0c80dd49315cc0 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Mon, 9 Dec 2019 17:22:42 +0100
Subject: [PATCH 1/2] lxd: Fix backup creation with hyphenated instance name on
 LVM

This fixes a bug where hyphenated instance names (e.g. test1-test2)
would fail to be exported when using LVM as the storage backend.

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 lxd/storage_lvm.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxd/storage_lvm.go b/lxd/storage_lvm.go
index 2c35f0fecd..122ac4a42e 100644
--- a/lxd/storage_lvm.go
+++ b/lxd/storage_lvm.go
@@ -1739,7 +1739,7 @@ func (s *storageLvm) ContainerBackupCreate(path string, backup backup.Backup, so
 	}
 	defer os.RemoveAll(tmpContainerMntPoint)
 
-	_, err = s.createSnapshotLV(source.Project(), poolName, source.Name(),
+	_, err = s.createSnapshotLV(source.Project(), poolName, containerNameToLVName(source.Name()),
 		storagePoolVolumeAPIEndpointContainers, containerNameToLVName(sourceLvmDatasetSnapshot),
 		storagePoolVolumeAPIEndpointContainers, false, s.useThinpool)
 	if err != nil {

From 58ce165541b75d1e6d104c1249535dd16142167a Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Mon, 9 Dec 2019 17:25:30 +0100
Subject: [PATCH 2/2] test/suites/backup: Test hyphenated container names

This tests hyphenated container names when creating backups.

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 test/suites/backup.sh | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/test/suites/backup.sh b/test/suites/backup.sh
index bfac561a23..5937cbebac 100644
--- a/test/suites/backup.sh
+++ b/test/suites/backup.sh
@@ -352,6 +352,14 @@ test_backup_export_with_project() {
   lxc delete --force c1
   rm -rf "${LXD_DIR}/optimized" "${LXD_DIR}/non-optimized"
 
+  # Check if hyphens cause issues when creating backups
+  lxc launch testimage c1-foo
+  lxc snapshot c1-foo
+
+  lxc export c1-foo "${LXD_DIR}/c1-foo.tar.gz"
+
+  lxc delete --force c1-foo
+
   if [ "$#" -ne 0 ]; then
     lxc image rm testimage
     lxc project switch default


More information about the lxc-devel mailing list