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

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) ===
Closes #6765

Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
From 7b0b77b217e5315f3f4d48b7f88af199e0ef3347 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com>
Date: Fri, 24 Jan 2020 12:02:35 +0200
Subject: [PATCH] lxd/patches: Reset ZFS mountpoint/canmount
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #6765

Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
---
 lxd/patches.go                            |  7 +--
 lxd/storage/drivers/driver_btrfs.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         |  1 +
 lxd/storage/drivers/driver_zfs_patches.go | 62 +++++++++++++++++++++++
 7 files changed, 71 insertions(+), 3 deletions(-)

diff --git a/lxd/patches.go b/lxd/patches.go
index 5be31ce745..046310a72a 100644
--- a/lxd/patches.go
+++ b/lxd/patches.go
@@ -78,7 +78,8 @@ var patches = []patch{
        {name: "storage_api_rename_container_snapshots_dir_again_again", run: 
patchStorageApiRenameContainerSnapshotsDir},
        {name: "clustering_add_roles", run: patchClusteringAddRoles},
        {name: "clustering_add_roles_again", run: patchClusteringAddRoles},
-       {name: "storage_create_vm", run: patchStorageCreateVM},
+       {name: "storage_create_vm", run: patchGenericStorage},
+       {name: "storage_zfs_mount", run: patchGenericStorage},
 }
 
 type patch struct {
@@ -132,7 +133,7 @@ func patchesApplyAll(d *Daemon) error {
 }
 
 // Patches begin here
-func patchStorageCreateVM(name string, d *Daemon) error {
+func patchGenericStorage(name string, d *Daemon) error {
        // Load all the pools.
        pools, _ := d.cluster.StoragePools()
 
@@ -143,7 +144,7 @@ func patchStorageCreateVM(name string, d *Daemon) error {
                                return err
                        }
 
-                       err = pool.ApplyPatch("storage_create_vm")
+                       err = pool.ApplyPatch(name)
                        if err != nil {
                                return err
                        }
diff --git a/lxd/storage/drivers/driver_btrfs.go 
b/lxd/storage/drivers/driver_btrfs.go
index 999145eee2..93423a7dbd 100644
--- a/lxd/storage/drivers/driver_btrfs.go
+++ b/lxd/storage/drivers/driver_btrfs.go
@@ -30,6 +30,7 @@ func (d *btrfs) load() error {
        // Register the patches.
        d.patches = map[string]func() error{
                "storage_create_vm": nil,
+               "storage_zfs_mount": nil,
        }
 
        // Done if previously loaded.
diff --git a/lxd/storage/drivers/driver_cephfs.go 
b/lxd/storage/drivers/driver_cephfs.go
index 37ee7bde83..2ffb1a46c6 100644
--- a/lxd/storage/drivers/driver_cephfs.go
+++ b/lxd/storage/drivers/driver_cephfs.go
@@ -28,6 +28,7 @@ func (d *cephfs) load() error {
        // Register the patches.
        d.patches = map[string]func() error{
                "storage_create_vm": nil,
+               "storage_zfs_mount": nil,
        }
 
        // Done if previously loaded.
diff --git a/lxd/storage/drivers/driver_dir.go 
b/lxd/storage/drivers/driver_dir.go
index 027cee0b3f..f1e8e89ea5 100644
--- a/lxd/storage/drivers/driver_dir.go
+++ b/lxd/storage/drivers/driver_dir.go
@@ -21,6 +21,7 @@ func (d *dir) load() error {
        // Register the patches.
        d.patches = map[string]func() error{
                "storage_create_vm": nil,
+               "storage_zfs_mount": nil,
        }
 
        return nil
diff --git a/lxd/storage/drivers/driver_lvm.go 
b/lxd/storage/drivers/driver_lvm.go
index 90e984f014..8a614af018 100644
--- a/lxd/storage/drivers/driver_lvm.go
+++ b/lxd/storage/drivers/driver_lvm.go
@@ -33,6 +33,7 @@ func (d *lvm) load() error {
        // Register the patches.
        d.patches = map[string]func() error{
                "storage_create_vm": nil,
+               "storage_zfs_mount": nil,
        }
 
        // Done if previously loaded.
diff --git a/lxd/storage/drivers/driver_zfs.go 
b/lxd/storage/drivers/driver_zfs.go
index 6c07712001..707b6bf25d 100644
--- a/lxd/storage/drivers/driver_zfs.go
+++ b/lxd/storage/drivers/driver_zfs.go
@@ -41,6 +41,7 @@ func (d *zfs) load() error {
        // Register the patches.
        d.patches = map[string]func() error{
                "storage_create_vm": d.patchStorageCreateVM,
+               "storage_zfs_mount": d.patchStorageZFSMount,
        }
 
        // Done if previously loaded.
diff --git a/lxd/storage/drivers/driver_zfs_patches.go 
b/lxd/storage/drivers/driver_zfs_patches.go
index fc6eccd146..5fc1a9803b 100644
--- a/lxd/storage/drivers/driver_zfs_patches.go
+++ b/lxd/storage/drivers/driver_zfs_patches.go
@@ -1,7 +1,11 @@
 package drivers
 
 import (
+       "fmt"
        "path/filepath"
+       "strings"
+
+       "github.com/lxc/lxd/shared"
 )
 
 func (d *zfs) patchStorageCreateVM() error {
@@ -19,3 +23,61 @@ func (d *zfs) patchStorageCreateVM() error {
 
        return nil
 }
+
+func (d *zfs) patchStorageZFSMount() error {
+       datasets, err := d.getDatasets(d.config["zfs.pool_name"])
+       if err != nil {
+               return err
+       }
+
+       for _, dataset := range datasets {
+               // Skip snapshots.
+               if strings.Contains(dataset, "@") {
+                       continue
+               }
+
+               // Skip block devices.
+               if strings.HasSuffix(dataset, ".block") {
+                       continue
+               }
+
+               // Skip top level.
+               if !strings.Contains(dataset, "/") {
+                       continue
+               }
+
+               // We only care about containers, images and custom volumes.
+               if !shared.StringInSlice(strings.SplitN(dataset, "/", 2)[0], 
[]string{"containers", "images", "custom"}) {
+                       continue
+               }
+
+               // Apply mountpoint changes.
+               oldMountPoint, err := 
d.getDatasetProperty(filepath.Join(d.config["zfs.pool_name"], dataset), 
"mountpoint")
+               if err != nil {
+                       return err
+               }
+               newMountPoint := filepath.Join(shared.VarPath("storage-pools", 
d.name, dataset))
+
+               if oldMountPoint != newMountPoint {
+                       err := 
d.setDatasetProperties(filepath.Join(d.config["zfs.pool_name"], dataset), 
fmt.Sprintf("mountpoint=%s", newMountPoint), "canmount=noauto")
+                       if err != nil {
+                               return err
+                       }
+               }
+
+               // Apply canmount changes.
+               oldCanMount, err := 
d.getDatasetProperty(filepath.Join(d.config["zfs.pool_name"], dataset), 
"canmount")
+               if err != nil {
+                       return err
+               }
+
+               if oldCanMount != "noauto" {
+                       err := 
d.setDatasetProperties(filepath.Join(d.config["zfs.pool_name"], dataset), 
"canmount=noauto")
+                       if err != nil {
+                               return err
+                       }
+               }
+       }
+
+       return nil
+}
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to