[lxc-devel] [lxd/master] lvm: use lvmized container name

brauner on Github lxc-bot at linuxcontainers.org
Wed Mar 1 22:57:54 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 604 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170301/ff420da9/attachment.bin>
-------------- next part --------------
From 8d25ece6652cef5413a70a1a9804b99976ef9cc3 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 1 Mar 2017 23:41:40 +0100
Subject: [PATCH] lvm: use lvmized container name

LVM has some very specific naming requirements for logical volumes. We have a
specific function that turns a container name into a valid logical volume name.
The only thing left to do is to actual use that valid logical volume name...

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 lxd/storage_lvm.go       |  4 ++--
 test/suites/snapshots.sh | 12 ++++++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/lxd/storage_lvm.go b/lxd/storage_lvm.go
index 6bcf02d..d473b84 100644
--- a/lxd/storage_lvm.go
+++ b/lxd/storage_lvm.go
@@ -1553,9 +1553,9 @@ func (s *storageLvm) ContainerRestore(container container, sourceContainer conta
 	}
 
 	poolName := s.getOnDiskPoolName()
-	err = s.removeLV(poolName, storagePoolVolumeApiEndpointContainers, destName)
+	err = s.removeLV(poolName, storagePoolVolumeApiEndpointContainers, destLvName)
 	if err != nil {
-		shared.LogErrorf(fmt.Sprintf("Failed to remove \"%s\": %s.", destName, err))
+		shared.LogErrorf(fmt.Sprintf("Failed to remove \"%s\": %s.", destLvName, err))
 	}
 
 	_, err = s.createSnapshotLV(poolName, srcLvName, storagePoolVolumeApiEndpointContainers, destLvName, storagePoolVolumeApiEndpointContainers, false)
diff --git a/test/suites/snapshots.sh b/test/suites/snapshots.sh
index b1bb5eb..5169c30 100644
--- a/test/suites/snapshots.sh
+++ b/test/suites/snapshots.sh
@@ -154,6 +154,18 @@ test_snap_restore() {
   lxc stop --force bar
 
   lxc delete bar
+
+  # Test if container's with hyphen's in their names are treated correctly.
+  if [ "${LXD_BACKEND}" = "lvm" ]; then
+	  lxc launch testimage a-b
+	  lxc snapshot a-b base
+	  lxc restore a-b base
+
+	  lxc snapshot a-b c-d
+	  lxc restore a-b c-d
+
+	  lxc delete -f a-b
+  fi
 }
 
 restore_and_compare_fs() {


More information about the lxc-devel mailing list