[lxc-devel] [lxd/master] lxd/storage/zfs: Set volmode=none for VM datasets

stgraber on Github lxc-bot at linuxcontainers.org
Tue Feb 25 19:30:23 UTC 2020


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/20200225/df19ceff/attachment.bin>
-------------- next part --------------
From 036c45195add519ddd8050954d638102f37d036e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 25 Feb 2020 14:29:53 -0500
Subject: [PATCH] lxd/storage/zfs: Set volmode=none for VM datasets
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/patches.go                            |  1 +
 lxd/storage/drivers/driver_btrfs.go       |  1 +
 lxd/storage/drivers/driver_ceph.go        |  1 +
 lxd/storage/drivers/driver_cephfs.go      |  1 +
 lxd/storage/drivers/driver_dir.go         |  1 +
 lxd/storage/drivers/driver_lvm.go         |  1 +
 lxd/storage/drivers/driver_zfs.go         |  9 ++++++++-
 lxd/storage/drivers/driver_zfs_patches.go | 15 +++++++++++++++
 8 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/lxd/patches.go b/lxd/patches.go
index 05dbf1adf3..62a0de238b 100644
--- a/lxd/patches.go
+++ b/lxd/patches.go
@@ -83,6 +83,7 @@ var patches = []patch{
 	{name: "storage_zfs_mount", run: patchGenericStorage},
 	{name: "network_pid_files", run: patchNetworkPIDFiles},
 	{name: "storage_create_vm_again", run: patchGenericStorage},
+	{name: "storage_zfs_volmode", run: patchGenericStorage},
 }
 
 type patch struct {
diff --git a/lxd/storage/drivers/driver_btrfs.go b/lxd/storage/drivers/driver_btrfs.go
index f541cd3514..499d01216d 100644
--- a/lxd/storage/drivers/driver_btrfs.go
+++ b/lxd/storage/drivers/driver_btrfs.go
@@ -32,6 +32,7 @@ func (d *btrfs) load() error {
 		"storage_create_vm":       nil,
 		"storage_zfs_mount":       nil,
 		"storage_create_vm_again": nil,
+		"storage_zfs_volmode":     nil,
 	}
 
 	// Done if previously loaded.
diff --git a/lxd/storage/drivers/driver_ceph.go b/lxd/storage/drivers/driver_ceph.go
index 3b5a016fbe..668981aff5 100644
--- a/lxd/storage/drivers/driver_ceph.go
+++ b/lxd/storage/drivers/driver_ceph.go
@@ -31,6 +31,7 @@ func (d *ceph) load() error {
 		"storage_create_vm":       nil,
 		"storage_zfs_mount":       nil,
 		"storage_create_vm_again": nil,
+		"storage_zfs_volmode":     nil,
 	}
 
 	// Done if previously loaded.
diff --git a/lxd/storage/drivers/driver_cephfs.go b/lxd/storage/drivers/driver_cephfs.go
index 9ed2056185..e7c2b6c089 100644
--- a/lxd/storage/drivers/driver_cephfs.go
+++ b/lxd/storage/drivers/driver_cephfs.go
@@ -30,6 +30,7 @@ func (d *cephfs) load() error {
 		"storage_create_vm":       nil,
 		"storage_zfs_mount":       nil,
 		"storage_create_vm_again": nil,
+		"storage_zfs_volmode":     nil,
 	}
 
 	// Done if previously loaded.
diff --git a/lxd/storage/drivers/driver_dir.go b/lxd/storage/drivers/driver_dir.go
index a30208b40b..4bbded29df 100644
--- a/lxd/storage/drivers/driver_dir.go
+++ b/lxd/storage/drivers/driver_dir.go
@@ -23,6 +23,7 @@ func (d *dir) load() error {
 		"storage_create_vm":       nil,
 		"storage_zfs_mount":       nil,
 		"storage_create_vm_again": nil,
+		"storage_zfs_volmode":     nil,
 	}
 
 	return nil
diff --git a/lxd/storage/drivers/driver_lvm.go b/lxd/storage/drivers/driver_lvm.go
index f75d217f83..f4cf461ca3 100644
--- a/lxd/storage/drivers/driver_lvm.go
+++ b/lxd/storage/drivers/driver_lvm.go
@@ -35,6 +35,7 @@ func (d *lvm) load() error {
 		"storage_create_vm":       nil,
 		"storage_zfs_mount":       nil,
 		"storage_create_vm_again": nil,
+		"storage_zfs_volmode":     nil,
 	}
 
 	// Done if previously loaded.
diff --git a/lxd/storage/drivers/driver_zfs.go b/lxd/storage/drivers/driver_zfs.go
index 5c6c9ef8ed..d4c584afe5 100644
--- a/lxd/storage/drivers/driver_zfs.go
+++ b/lxd/storage/drivers/driver_zfs.go
@@ -43,6 +43,7 @@ func (d *zfs) load() error {
 		"storage_create_vm":       d.patchStorageCreateVM,
 		"storage_zfs_mount":       d.patchStorageZFSMount,
 		"storage_create_vm_again": nil,
+		"storage_zfs_volmode":     d.patchStorageZFSVolMode,
 	}
 
 	// Done if previously loaded.
@@ -241,7 +242,13 @@ func (d *zfs) Create() error {
 
 	// Create the initial datasets.
 	for _, dataset := range d.initialDatasets() {
-		err := d.createDataset(filepath.Join(d.config["zfs.pool_name"], dataset), "mountpoint=none")
+
+		properties := []string{"mountpoint=none"}
+		if shared.StringInSlice(dataset, []string{"virtual-machines", "deleted/virtual-machines"}) {
+			properties = append(properties, "volmode=none")
+		}
+
+		err := d.createDataset(filepath.Join(d.config["zfs.pool_name"], dataset), properties...)
 		if err != nil {
 			return err
 		}
diff --git a/lxd/storage/drivers/driver_zfs_patches.go b/lxd/storage/drivers/driver_zfs_patches.go
index 336b7b350e..ae147a7834 100644
--- a/lxd/storage/drivers/driver_zfs_patches.go
+++ b/lxd/storage/drivers/driver_zfs_patches.go
@@ -86,3 +86,18 @@ func (d *zfs) patchStorageZFSMount() error {
 
 	return nil
 }
+
+func (d *zfs) patchStorageZFSVolMode() error {
+	// Set volmode=none on the parent virtual-machines directory
+	err := d.setDatasetProperties(filepath.Join(d.config["zfs.pool_name"], "virtual-machines"), "volmode=none")
+	if err != nil {
+		return err
+	}
+
+	err = d.setDatasetProperties(filepath.Join(d.config["zfs.pool_name"], "deleted", "virtual-machines"), "volmode=none")
+	if err != nil {
+		return err
+	}
+
+	return nil
+}


More information about the lxc-devel mailing list