[lxc-devel] [lxd/master] Re-import images in pools if volume.block.filesystem has changed

albertodonato on Github lxc-bot at linuxcontainers.org
Wed Sep 20 11:52:12 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 313 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170920/42fb00f0/attachment.bin>
-------------- next part --------------
From 4f5ee725266351b009dab37bc0ea613b9bd4dabf Mon Sep 17 00:00:00 2001
From: Alberto Donato <alberto.donato at canonical.com>
Date: Wed, 20 Sep 2017 13:33:10 +0200
Subject: [PATCH 1/2] storage/lvm: re-import image on thinpool-based pools if
 volume filesystem has changed

Signed-off-by: Alberto Donato <alberto.donato at canonical.com>
---
 lxd/storage_lvm_utils.go | 15 +++++++++++++++
 test/suites/storage.sh   |  6 +++++-
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/lxd/storage_lvm_utils.go b/lxd/storage_lvm_utils.go
index 1383e0c6e..e86f9b88c 100644
--- a/lxd/storage_lvm_utils.go
+++ b/lxd/storage_lvm_utils.go
@@ -538,6 +538,21 @@ func (s *storageLvm) containerCreateFromImageThinLv(c container, fp string) erro
 
 		var imgerr error
 		ok, _ := storageLVExists(imageLvmDevPath)
+		if ok {
+			_, volume, err := db.StoragePoolVolumeGetType(s.s.DB, fp, db.StoragePoolVolumeTypeImage, s.poolID)
+			if err != nil {
+				return err
+			}
+			if volume.Config["block.filesystem"] != s.getLvmFilesystem() {
+				// The storage pool volume.blockfilesystem property has changed, re-import the image
+				err := s.ImageDelete(fp)
+				if err != nil {
+					return err
+				}
+				ok = false
+			}
+		}
+
 		if !ok {
 			imgerr = s.ImageCreate(fp)
 		}
diff --git a/test/suites/storage.sh b/test/suites/storage.sh
index 4342d83b0..ade738b76 100644
--- a/test/suites/storage.sh
+++ b/test/suites/storage.sh
@@ -373,6 +373,10 @@ test_storage() {
       lxc launch testimage c12pool15 -s "lxdtest-$(basename "${LXD_DIR}")-non-thinpool-pool15"
       lxc list -c b c12pool15 | grep "lxdtest-$(basename "${LXD_DIR}")-non-thinpool-pool15"
 
+      # Test that changing block filesystem works
+      lxc storage set "lxdtest-$(basename "${LXD_DIR}")-pool6" volume.block.filesystem xfs
+      lxc init testimage c1pool6 -s "lxdtest-$(basename "${LXD_DIR}")-pool6"
+
       lxc storage volume create "lxdtest-$(basename "${LXD_DIR}")-pool6" c10pool6
       lxc storage volume attach "lxdtest-$(basename "${LXD_DIR}")-pool6" c10pool6 c10pool6 testDevice /opt
       ! lxc storage volume attach "lxdtest-$(basename "${LXD_DIR}")-pool6" c10pool6 c10pool6 testDevice2 /opt
@@ -562,6 +566,7 @@ test_storage() {
     lxc storage volume delete "lxdtest-$(basename "${LXD_DIR}")-pool5" c11pool5
 
     if [ "$lxd_backend" = "lvm" ]; then
+      lxc delete -f c1pool6
       lxc delete -f c10pool6
       lxc delete -f c12pool6
 
@@ -579,7 +584,6 @@ test_storage() {
 
       lxc delete -f c10pool15
       lxc delete -f c12pool15
-
       lxc storage volume delete "lxdtest-$(basename "${LXD_DIR}")-pool6" c10pool6
       lxc storage volume delete "lxdtest-$(basename "${LXD_DIR}")-pool6"  c12pool6
       lxc storage volume delete "lxdtest-$(basename "${LXD_DIR}")-pool11" c10pool11

From f1ab1709b7751c77af5a41a2b6b0e7da2700c4e5 Mon Sep 17 00:00:00 2001
From: Alberto Donato <alberto.donato at canonical.com>
Date: Wed, 20 Sep 2017 13:41:06 +0200
Subject: [PATCH 2/2] storage/storage: re-import image if volume filesystem has
 changed

Signed-off-by: Alberto Donato <alberto.donato at canonical.com>
---
 lxd/storage_ceph.go                | 21 +++++++++++++++++++--
 test/suites/storage_driver_ceph.sh |  4 ++++
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/lxd/storage_ceph.go b/lxd/storage_ceph.go
index c73a4b4d8..3a29cfc16 100644
--- a/lxd/storage_ceph.go
+++ b/lxd/storage_ceph.go
@@ -878,8 +878,25 @@ func (s *storageCeph) ContainerCreateFromImage(container container, fingerprint
 		lxdStorageMapLock.Unlock()
 
 		var imgerr error
-		if !cephRBDVolumeExists(s.ClusterName, s.OSDPoolName,
-			fingerprint, storagePoolVolumeTypeNameImage, s.UserName) {
+		ok := cephRBDVolumeExists(s.ClusterName, s.OSDPoolName,
+			fingerprint, storagePoolVolumeTypeNameImage, s.UserName)
+
+		if ok {
+			_, volume, err := db.StoragePoolVolumeGetType(s.s.DB, fingerprint, db.StoragePoolVolumeTypeImage, s.poolID)
+			if err != nil {
+				return err
+			}
+			if volume.Config["block.filesystem"] != s.getRBDFilesystem() {
+				// The storage pool volume.blockfilesystem property has changed, re-import the image
+				err := s.ImageDelete(fingerprint)
+				if err != nil {
+					return err
+				}
+				ok = false
+			}
+		}
+
+		if !ok {
 			imgerr = s.ImageCreate(fingerprint)
 		}
 
diff --git a/test/suites/storage_driver_ceph.sh b/test/suites/storage_driver_ceph.sh
index f8a31b9c2..0fa97c08f 100644
--- a/test/suites/storage_driver_ceph.sh
+++ b/test/suites/storage_driver_ceph.sh
@@ -55,6 +55,9 @@ test_storage_driver_ceph() {
     lxc launch testimage c4pool2 -s "lxdtest-$(basename "${LXD_DIR}")-pool2"
     lxc list -c b c4pool2 | grep "lxdtest-$(basename "${LXD_DIR}")-pool2"
 
+    lxc storage set "lxdtest-$(basename "${LXD_DIR}")-pool1" volume.block.filesystem xfs
+    lxc init testimage c5pool1 -s "lxdtest-$(basename "${LXD_DIR}")-pool1"
+
     # Test whether dependency tracking is working correctly. We should be able
     # to create a container, copy it, which leads to a dependency relation
     # between the source container's storage volume and the copied container's
@@ -107,6 +110,7 @@ test_storage_driver_ceph() {
 
     lxc delete -f c1pool1
     lxc delete -f c3pool1
+    lxc delete -f c5pool1
 
     lxc delete -f c4pool2
     lxc delete -f c2pool2


More information about the lxc-devel mailing list