[lxc-devel] [lxd/master] lxd/storage/zfs: Improve defaults

stgraber on Github lxc-bot at linuxcontainers.org
Thu Jun 21 15:32:51 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180621/fd32de6f/attachment.bin>
-------------- next part --------------
From 5d1e70df7f4b8bc8376df2012df003bec896b480 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 21 Jun 2018 11:32:32 -0400
Subject: [PATCH] lxd/storage/zfs: Improve defaults
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/storage_zfs.go       | 15 ++-------------
 lxd/storage_zfs_utils.go | 45 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 13 deletions(-)

diff --git a/lxd/storage_zfs.go b/lxd/storage_zfs.go
index 94e0a3ab2..84238d614 100644
--- a/lxd/storage_zfs.go
+++ b/lxd/storage_zfs.go
@@ -237,19 +237,8 @@ func (s *storageZfs) zfsPoolCreate() error {
 				return fmt.Errorf("Provided ZFS pool (or dataset) isn't empty")
 			}
 
-			if err := zfsPoolVolumeSet(vdev, "", "mountpoint", "none"); err != nil {
-				return err
-			}
-
-			if err := zfsPoolVolumeSet(vdev, "", "setuid", "on"); err != nil {
-				return err
-			}
-
-			if err := zfsPoolVolumeSet(vdev, "", "exec", "on"); err != nil {
-				return err
-			}
-
-			if err := zfsPoolVolumeSet(vdev, "", "devices", "on"); err != nil {
+			err = zfsPoolApplyDefaults(vdev)
+			if err != nil {
 				return err
 			}
 		}
diff --git a/lxd/storage_zfs_utils.go b/lxd/storage_zfs_utils.go
index 60673d49b..ed173de1a 100644
--- a/lxd/storage_zfs_utils.go
+++ b/lxd/storage_zfs_utils.go
@@ -67,6 +67,9 @@ func zfsPoolCheck(pool string) error {
 func zfsPoolCreate(pool string, vdev string) error {
 	var output string
 	var err error
+
+	dataset := ""
+
 	if pool == "" {
 		output, err := shared.RunCommand(
 			"zfs", "create", "-p", "-o", "mountpoint=none", vdev)
@@ -74,6 +77,7 @@ func zfsPoolCreate(pool string, vdev string) error {
 			logger.Errorf("zfs create failed: %s.", output)
 			return fmt.Errorf("Failed to create ZFS filesystem: %s", output)
 		}
+		dataset = vdev
 	} else {
 		output, err = shared.RunCommand(
 			"zpool", "create", "-f", "-m", "none", "-O", "compression=on", pool, vdev)
@@ -81,6 +85,47 @@ func zfsPoolCreate(pool string, vdev string) error {
 			logger.Errorf("zfs create failed: %s.", output)
 			return fmt.Errorf("Failed to create the ZFS pool: %s", output)
 		}
+
+		dataset = pool
+	}
+
+	err = zfsPoolApplyDefaults(dataset)
+	if err != nil {
+		return err
+	}
+
+	return nil
+}
+
+func zfsPoolApplyDefaults(dataset string) error {
+	err := zfsPoolVolumeSet(dataset, "", "mountpoint", "none")
+	if err != nil {
+		return err
+	}
+
+	err = zfsPoolVolumeSet(dataset, "", "setuid", "on")
+	if err != nil {
+		return err
+	}
+
+	err = zfsPoolVolumeSet(dataset, "", "exec", "on")
+	if err != nil {
+		return err
+	}
+
+	err = zfsPoolVolumeSet(dataset, "", "devices", "on")
+	if err != nil {
+		return err
+	}
+
+	err = zfsPoolVolumeSet(dataset, "", "acltype", "posix")
+	if err != nil {
+		return err
+	}
+
+	err = zfsPoolVolumeSet(dataset, "", "xattr", "sa")
+	if err != nil {
+		return err
 	}
 
 	return nil


More information about the lxc-devel mailing list