[lxc-devel] [lxd/master] Fix daemonConfig handling of storage

stgraber on Github lxc-bot at linuxcontainers.org
Wed Apr 27 17:30:08 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 517 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160427/deaa643b/attachment.bin>
-------------- next part --------------
From 92063e973fccce02cbced6a3d39591d87f14efd4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 27 Apr 2016 13:19:38 -0400
Subject: [PATCH] Fix daemonConfig handling of storage
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Storage functions unfortunately have the habit of reading the daemon
configuration, so we need to at least temporarily set daemonConfig to
the right value...

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/daemon.go        | 10 +++++-----
 lxd/daemon_config.go | 25 +++++++++++--------------
 2 files changed, 16 insertions(+), 19 deletions(-)

diff --git a/lxd/daemon.go b/lxd/daemon.go
index 4e3f635..8a150cc 100644
--- a/lxd/daemon.go
+++ b/lxd/daemon.go
@@ -344,27 +344,27 @@ func (d *Daemon) createCmd(version string, c Command) {
 	})
 }
 
-func (d *Daemon) SetupStorageDriver(driver string) error {
+func (d *Daemon) SetupStorageDriver() error {
 	var err error
 
 	lvmVgName := daemonConfig["storage.lvm_vg_name"].Get()
 	zfsPoolName := daemonConfig["storage.zfs_pool_name"].Get()
 
-	if driver == "lvm" || lvmVgName != "" {
+	if lvmVgName != "" {
 		d.Storage, err = newStorage(d, storageTypeLvm)
 		if err != nil {
 			shared.Logf("Could not initialize storage type LVM: %s - falling back to dir", err)
 		} else {
 			return nil
 		}
-	} else if driver == "zfs" || zfsPoolName != "" {
+	} else if zfsPoolName != "" {
 		d.Storage, err = newStorage(d, storageTypeZfs)
 		if err != nil {
 			shared.Logf("Could not initialize storage type ZFS: %s - falling back to dir", err)
 		} else {
 			return nil
 		}
-	} else if driver == "btrfs" || d.BackingFs == "btrfs" {
+	} else if d.BackingFs == "btrfs" {
 		d.Storage, err = newStorage(d, storageTypeBtrfs)
 		if err != nil {
 			shared.Logf("Could not initialize storage type btrfs: %s - falling back to dir", err)
@@ -743,7 +743,7 @@ func (d *Daemon) Init() error {
 
 	/* Setup the storage driver */
 	if !d.MockMode {
-		err = d.SetupStorageDriver("")
+		err = d.SetupStorageDriver()
 		if err != nil {
 			return fmt.Errorf("Failed to setup storage: %s", err)
 		}
diff --git a/lxd/daemon_config.go b/lxd/daemon_config.go
index e9ff6a5..1fda2cb 100644
--- a/lxd/daemon_config.go
+++ b/lxd/daemon_config.go
@@ -253,23 +253,20 @@ func daemonConfigSetPassword(d *Daemon, key string, value string) (string, error
 }
 
 func daemonConfigSetStorage(d *Daemon, key string, value string) (string, error) {
-	driver := ""
-
-	// Guess the driver name from the key
-	switch key {
-	case "storage.lvm_vg_name":
-		driver = "lvm"
-	case "storage.zfs_pool_name":
-		driver = "zfs"
-	}
+	// The storage driver looks at daemonConfig so just set it temporarily
+	daemonConfigLock.Lock()
+	oldValue := daemonConfig[key].Get()
+	daemonConfig[key].currentValue = value
+	daemonConfigLock.Unlock()
 
-	// Should never actually hit this
-	if driver == "" {
-		return "", fmt.Errorf("Invalid storage key: %s", key)
-	}
+	defer func() {
+		daemonConfigLock.Lock()
+		daemonConfig[key].currentValue = oldValue
+		daemonConfigLock.Unlock()
+	}()
 
 	// Update the current storage driver
-	err := d.SetupStorageDriver(driver)
+	err := d.SetupStorageDriver()
 	if err != nil {
 		return "", err
 	}


More information about the lxc-devel mailing list