[lxc-devel] [lxd/master] lxd/storage: Fix importing preseed dump

stgraber on Github lxc-bot at linuxcontainers.org
Mon Oct 29 19:30:41 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 370 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20181029/c494e50a/attachment.bin>
-------------- next part --------------
From ba8048264f2afe0f73510ad4887c918aeb2644d6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 29 Oct 2018 15:19:07 -0400
Subject: [PATCH] lxd/storage: Fix importing preseed dump
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #5199

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/storage_btrfs.go | 15 ++++++++-------
 lxd/storage_lvm.go   | 16 +++++++++-------
 lxd/storage_zfs.go   | 12 +++++++-----
 3 files changed, 24 insertions(+), 19 deletions(-)

diff --git a/lxd/storage_btrfs.go b/lxd/storage_btrfs.go
index dafefed339..eb07da717a 100644
--- a/lxd/storage_btrfs.go
+++ b/lxd/storage_btrfs.go
@@ -130,8 +130,9 @@ func (s *storageBtrfs) StoragePoolCreate() error {
 		source = shared.HostPath(s.pool.Config["source"])
 	}
 
-	if source == "" {
-		source = filepath.Join(shared.VarPath("disks"), fmt.Sprintf("%s.img", s.pool.Name))
+	defaultSource := filepath.Join(shared.VarPath("disks"), fmt.Sprintf("%s.img", s.pool.Name))
+	if source == "" || source == defaultSource {
+		source = defaultSource
 		s.pool.Config["source"] = source
 
 		f, err := os.Create(source)
@@ -173,22 +174,22 @@ func (s *storageBtrfs) StoragePoolCreate() error {
 				if isBtrfsSubVolume(source) {
 					subvols, err := btrfsSubVolumesGet(source)
 					if err != nil {
-						return fmt.Errorf("could not determine if existing BTRFS subvolume ist empty: %s", err)
+						return fmt.Errorf("Could not determine if existing BTRFS subvolume ist empty: %s", err)
 					}
 					if len(subvols) > 0 {
-						return fmt.Errorf("requested BTRFS subvolume exists but is not empty")
+						return fmt.Errorf("Requested BTRFS subvolume exists but is not empty")
 					}
 				} else {
 					cleanSource := filepath.Clean(source)
 					lxdDir := shared.VarPath()
 					poolMntPoint := getStoragePoolMountPoint(s.pool.Name)
 					if shared.PathExists(source) && !isOnBtrfs(source) {
-						return fmt.Errorf("existing path is neither a BTRFS subvolume nor does it reside on a BTRFS filesystem")
+						return fmt.Errorf("Existing path is neither a BTRFS subvolume nor does it reside on a BTRFS filesystem")
 					} else if strings.HasPrefix(cleanSource, lxdDir) {
 						if cleanSource != poolMntPoint {
 							return fmt.Errorf("BTRFS subvolumes requests in LXD directory \"%s\" are only valid under \"%s\"\n(e.g. source=%s)", shared.VarPath(), shared.VarPath("storage-pools"), poolMntPoint)
 						} else if s.s.OS.BackingFS != "btrfs" {
-							return fmt.Errorf("creation of BTRFS subvolume requested but \"%s\" does not reside on BTRFS filesystem", source)
+							return fmt.Errorf("Creation of BTRFS subvolume requested but \"%s\" does not reside on BTRFS filesystem", source)
 						}
 					}
 
@@ -199,7 +200,7 @@ func (s *storageBtrfs) StoragePoolCreate() error {
 				}
 			}
 		} else {
-			return fmt.Errorf("invalid \"source\" property")
+			return fmt.Errorf("Invalid \"source\" property")
 		}
 	}
 
diff --git a/lxd/storage_lvm.go b/lxd/storage_lvm.go
index 24f30e0fd6..a2aaed90f2 100644
--- a/lxd/storage_lvm.go
+++ b/lxd/storage_lvm.go
@@ -147,8 +147,9 @@ func (s *storageLvm) StoragePoolCreate() error {
 		}
 	}()
 
-	if source == "" {
-		source = filepath.Join(shared.VarPath("disks"), fmt.Sprintf("%s.img", s.pool.Name))
+	defaultSource := filepath.Join(shared.VarPath("disks"), fmt.Sprintf("%s.img", s.pool.Name))
+	if source == "" || source == defaultSource {
+		source = defaultSource
 		s.pool.Config["source"] = source
 
 		if s.pool.Config["lvm.vg_name"] == "" {
@@ -206,7 +207,7 @@ func (s *storageLvm) StoragePoolCreate() error {
 		if filepath.IsAbs(source) {
 			pvName = source
 			if !shared.IsBlockdevPath(pvName) {
-				return fmt.Errorf("custom loop file locations are not supported")
+				return fmt.Errorf("Custom loop file locations are not supported")
 			}
 
 			if s.pool.Config["lvm.vg_name"] == "" {
@@ -231,10 +232,11 @@ func (s *storageLvm) StoragePoolCreate() error {
 			// The physical volume must already consist
 			pvExisted = true
 			vgName = source
-			if s.pool.Config["lvm.vg_name"] != "" {
+			if s.pool.Config["lvm.vg_name"] != "" && s.pool.Config["lvm.vg_name"] != vgName {
 				// User gave us something weird.
-				return fmt.Errorf("invalid combination of \"source\" and \"zfs.pool_name\" property")
+				return fmt.Errorf("Invalid combination of \"source\" and \"lvm.vg_name\" property")
 			}
+
 			s.pool.Config["lvm.vg_name"] = vgName
 			s.vgName = vgName
 
@@ -245,7 +247,7 @@ func (s *storageLvm) StoragePoolCreate() error {
 
 			// Volume group must exist but doesn't.
 			if !vgExisted {
-				return fmt.Errorf("the requested volume group \"%s\" does not exist", vgName)
+				return fmt.Errorf("The requested volume group \"%s\" does not exist", vgName)
 			}
 		}
 	}
@@ -259,7 +261,7 @@ func (s *storageLvm) StoragePoolCreate() error {
 
 		output, err := shared.TryRunCommand("pvcreate", pvName)
 		if err != nil {
-			return fmt.Errorf("failed to create the physical volume for the lvm storage pool: %s", output)
+			return fmt.Errorf("Failed to create the physical volume for the lvm storage pool: %s", output)
 		}
 		defer func() {
 			if tryUndo {
diff --git a/lxd/storage_zfs.go b/lxd/storage_zfs.go
index 8383205ce0..1bafaf6bf8 100644
--- a/lxd/storage_zfs.go
+++ b/lxd/storage_zfs.go
@@ -161,8 +161,9 @@ func (s *storageZfs) zfsPoolCreate() error {
 
 	zpoolName := s.getOnDiskPoolName()
 	vdev := s.pool.Config["source"]
-	if vdev == "" {
-		vdev = filepath.Join(shared.VarPath("disks"), fmt.Sprintf("%s.img", s.pool.Name))
+	defaultVdev := filepath.Join(shared.VarPath("disks"), fmt.Sprintf("%s.img", s.pool.Name))
+	if vdev == "" || vdev == defaultVdev {
+		vdev = defaultVdev
 		s.pool.Config["source"] = vdev
 
 		if s.pool.Config["zfs.pool_name"] == "" {
@@ -199,7 +200,7 @@ func (s *storageZfs) zfsPoolCreate() error {
 
 		if filepath.IsAbs(vdev) {
 			if !shared.IsBlockdevPath(vdev) {
-				return fmt.Errorf("custom loop file locations are not supported")
+				return fmt.Errorf("Custom loop file locations are not supported")
 			}
 
 			if s.pool.Config["zfs.pool_name"] == "" {
@@ -219,9 +220,10 @@ func (s *storageZfs) zfsPoolCreate() error {
 				return err
 			}
 		} else {
-			if s.pool.Config["zfs.pool_name"] != "" {
-				return fmt.Errorf("invalid combination of \"source\" and \"zfs.pool_name\" property")
+			if s.pool.Config["zfs.pool_name"] != "" && s.pool.Config["zfs.pool_name"] != vdev {
+				return fmt.Errorf("Invalid combination of \"source\" and \"zfs.pool_name\" property")
 			}
+
 			s.pool.Config["zfs.pool_name"] = vdev
 			s.dataset = vdev
 


More information about the lxc-devel mailing list