[lxc-devel] [lxd/master] Properly validate daemon keys on unset
stgraber on Github
lxc-bot at linuxcontainers.org
Wed Dec 7 00:29:45 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 370 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20161207/85aa98e9/attachment.bin>
-------------- next part --------------
From eaf33a3d1f4bc675da0746c7da8bfa31583dec04 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 7 Dec 2016 01:29:17 +0100
Subject: [PATCH] Properly validate daemon keys on unset
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Closes #2698
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxd/daemon_config.go | 11 ++++++++++-
lxd/storage_zfs.go | 18 +++++++++---------
2 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/lxd/daemon_config.go b/lxd/daemon_config.go
index 5af70ad..3a1ec33 100644
--- a/lxd/daemon_config.go
+++ b/lxd/daemon_config.go
@@ -49,8 +49,17 @@ func (k *daemonConfigKey) name() string {
}
func (k *daemonConfigKey) Validate(d *Daemon, value string) error {
- // No need to validate when unsetting
+ // Handle unsetting
if value == "" {
+ value = k.defaultValue
+
+ if k.validator != nil {
+ err := k.validator(d, k.name(), value)
+ if err != nil {
+ return err
+ }
+ }
+
return nil
}
diff --git a/lxd/storage_zfs.go b/lxd/storage_zfs.go
index 6e12f31..022c42b 100644
--- a/lxd/storage_zfs.go
+++ b/lxd/storage_zfs.go
@@ -1217,17 +1217,17 @@ func storageZFSValidatePoolName(d *Daemon, key string, value string) error {
if err != nil {
return fmt.Errorf("Invalid ZFS pool: %v", err)
}
- }
- // Confirm that the new pool is empty
- s.zfsPool = value
- subvols, err := s.zfsListSubvolumes("")
- if err != nil {
- return err
- }
+ // 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")
+ if len(subvols) > 0 {
+ return fmt.Errorf("Provided ZFS pool (or dataset) isn't empty")
+ }
}
// Confirm the old pool isn't in use anymore
More information about the lxc-devel
mailing list