[lxc-devel] [lxd/master] zfs: Extra checks and config for ZFS pools

stgraber on Github lxc-bot at linuxcontainers.org
Tue Oct 4 09:20:37 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 559 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20161004/863dcc83/attachment.bin>
-------------- next part --------------
From 1035d781d3e6a5972bbb7b8b495daa19cdd94cfb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 4 Oct 2016 11:18:55 +0200
Subject: [PATCH] zfs: Extra checks and config for ZFS pools
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

LXD assumes that it completely owns whatever storage.zfs_pool_name
points to, so lets make sure it's always empty. Then to avoid potential
problems with the mounts LXD will make, set mountpoint=none.

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/storage_zfs.go | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/lxd/storage_zfs.go b/lxd/storage_zfs.go
index 59891f2..c65a0a9 100644
--- a/lxd/storage_zfs.go
+++ b/lxd/storage_zfs.go
@@ -74,6 +74,18 @@ func (s *storageZfs) Init(config map[string]interface{}) (storage, error) {
 		return s, fmt.Errorf("The 'zfs' tool isn't working properly")
 	}
 
+	output, err = exec.Command("zfs", "get", "mountpoint", "-H", "-o", "source", s.zfsPool).CombinedOutput()
+	if err != nil {
+		return s, fmt.Errorf("Unable to query ZFS mountpoint")
+	}
+
+	if strings.TrimSpace(string(output)) != "local" {
+		err = shared.RunCommand("zfs", "set", "mountpoint=none", s.zfsPool)
+		if err != nil {
+			return s, err
+		}
+	}
+
 	return s, nil
 }
 
@@ -1192,6 +1204,17 @@ func storageZFSValidatePoolName(d *Daemon, key string, value string) error {
 		}
 	}
 
+	// Confirm that the new pool is empty
+	s.zfsPool = value
+	subvols, err := s.zfsListSubvolumes("")
+	if err != nil {
+		return err
+	}
+
+	if len(subvols) > 0 {
+		return fmt.Errorf("Provided ZFS pool (or dataset) isn't empty")
+	}
+
 	// Confirm the old pool isn't in use anymore
 	oldPoolname := daemonConfig["storage.zfs_pool_name"].Get()
 	if oldPoolname != "" {


More information about the lxc-devel mailing list