The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/2453

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
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 <stgra...@ubuntu.com>
From 1035d781d3e6a5972bbb7b8b495daa19cdd94cfb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@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 <stgra...@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 != "" {
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to