[lxc-devel] [lxd/master] zfs: try pool import

brauner on Github lxc-bot at linuxcontainers.org
Mon Oct 30 13:54:03 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 381 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20171030/b5a8e9c4/attachment.bin>
-------------- next part --------------
From 38380de4d3716dc38618d033470c44b63d09a321 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Mon, 30 Oct 2017 14:53:01 +0100
Subject: [PATCH] zfs: try pool import

Closes #3976.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 lxd/storage_zfs.go | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/lxd/storage_zfs.go b/lxd/storage_zfs.go
index e390c659f..55aacec77 100644
--- a/lxd/storage_zfs.go
+++ b/lxd/storage_zfs.go
@@ -87,24 +87,28 @@ func (s *storageZfs) StoragePoolCheck() error {
 	}
 
 	poolName := s.getOnDiskPoolName()
-	if filepath.IsAbs(source) {
-		if zfsFilesystemEntityExists(poolName, "") {
-			return nil
-		}
-		logger.Debugf("ZFS storage pool \"%s\" does not exist. Trying to import it.", poolName)
+	exists := zfsFilesystemEntityExists(poolName, "")
+	if exists {
+		return nil
+	}
 
+	logger.Debugf("ZFS storage pool \"%s\" does not exist. Trying to import it.", poolName)
+
+	var err error
+	var msg string
+	if filepath.IsAbs(source) {
 		disksPath := shared.VarPath("disks")
-		output, err := shared.RunCommand(
-			"zpool",
-			"import",
-			"-d", disksPath, poolName)
-		if err != nil {
-			return fmt.Errorf("ZFS storage pool \"%s\" could not be imported: %s", poolName, output)
-		}
+		msg, err = shared.RunCommand("zpool", "import", "-d", disksPath, poolName)
+	} else {
+		msg, err = shared.RunCommand("zpool", "import", poolName)
+	}
 
-		logger.Debugf("ZFS storage pool \"%s\" successfully imported.", poolName)
+	if err != nil {
+		return fmt.Errorf("ZFS storage pool \"%s\" could not be imported: %s", poolName, msg)
 	}
 
+
+	logger.Debugf("ZFS storage pool \"%s\" successfully imported.", poolName)
 	return nil
 }
 


More information about the lxc-devel mailing list