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

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) ===
Moves Volume validation to use a Volume struct so that volume type and content type can be used during validation if needed.
From f8961702f4e343a8343a0a664e0f50842e76f93c Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Thu, 31 Oct 2019 08:40:02 +0000
Subject: [PATCH 1/5] lxd/storage/drivers/interface: Modifies ValidateVolume
 definition

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/storage/drivers/interface.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxd/storage/drivers/interface.go b/lxd/storage/drivers/interface.go
index c7d79fd84b..13f071a6c2 100644
--- a/lxd/storage/drivers/interface.go
+++ b/lxd/storage/drivers/interface.go
@@ -30,7 +30,7 @@ type Driver interface {
        GetResources() (*api.ResourcesStoragePool, error)
 
        // Volumes.
-       ValidateVolume(volConfig map[string]string, removeUnknownKeys bool) 
error
+       ValidateVolume(vol Volume, removeUnknownKeys bool) error
        CreateVolume(vol Volume, filler func(path string) error, op 
*operations.Operation) error
        CreateVolumeFromCopy(vol Volume, srcVol Volume, copySnapshots bool, op 
*operations.Operation) error
        DeleteVolume(volType VolumeType, volName string, op 
*operations.Operation) error

From 9b4b2f9ddb5ef55b03f6f911d2503102110d7701 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Wed, 30 Oct 2019 15:30:26 +0000
Subject: [PATCH 2/5] lxd/storage/utils: Updates ValidateVolume usage

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/storage/utils.go | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lxd/storage/utils.go b/lxd/storage/utils.go
index 801bbbbadb..5f9d890497 100644
--- a/lxd/storage/utils.go
+++ b/lxd/storage/utils.go
@@ -525,7 +525,9 @@ func VolumeValidateConfig(name string, config 
map[string]string, parentPool *api
        // Validate volume config using the new driver interface if supported.
        driver, err := drivers.Load(nil, parentPool.Driver, parentPool.Name, 
parentPool.Config, nil, validateVolumeCommonRules)
        if err != drivers.ErrUnknownDriver {
-               return driver.ValidateVolume(config, false)
+               // Note: This legacy validation function doesn't have the 
concept of validating
+               // different volumes types, so the types are hard coded as 
Custom and FS.
+               return driver.ValidateVolume(drivers.NewVolume(driver, 
parentPool.Name, drivers.VolumeTypeCustom, drivers.ContentTypeFS, name, 
config), false)
        }
 
        // Otherwise fallback to doing legacy validation.

From 4977c33f9459db8e232bd3d0268c142634ffb372 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Wed, 30 Oct 2019 15:34:36 +0000
Subject: [PATCH 3/5] lxd/storage/backend/lxd: Updates use of validate function

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/storage/backend_lxd.go | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lxd/storage/backend_lxd.go b/lxd/storage/backend_lxd.go
index 0df7451bf9..a74ad48f35 100644
--- a/lxd/storage/backend_lxd.go
+++ b/lxd/storage/backend_lxd.go
@@ -409,7 +409,7 @@ func (b *lxdBackend) CreateCustomVolumeFromMigration(conn 
io.ReadWriteCloser, ar
        }()
 
        // Check the supplied config and remove any fields not relevant for 
destination pool type.
-       err := b.driver.ValidateVolume(args.Config, true)
+       err := b.driver.ValidateVolume(b.newVolume(drivers.VolumeTypeCustom, 
drivers.ContentTypeFS, args.Name, args.Config), true)
        if err != nil {
                return err
        }
@@ -511,7 +511,7 @@ func (b *lxdBackend) RenameCustomVolume(volName string, 
newVolName string, op *o
 
 // UpdateCustomVolume applies the supplied config to the volume.
 func (b *lxdBackend) UpdateCustomVolume(volName, newDesc string, newConfig 
map[string]string, op *operations.Operation) error {
-       err := b.driver.ValidateVolume(newConfig, false)
+       err := b.driver.ValidateVolume(b.newVolume(drivers.VolumeTypeCustom, 
drivers.ContentTypeFS, volName, newConfig), false)
        if err != nil {
                return err
        }

From 49e3abcaaf5127abd9eba86bba34e1507a8bb259 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Wed, 30 Oct 2019 15:35:28 +0000
Subject: [PATCH 4/5] lxd/storage/drivers/driver/common: Updates validate
 function

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/storage/drivers/driver_common.go | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lxd/storage/drivers/driver_common.go 
b/lxd/storage/drivers/driver_common.go
index b2298ff330..bf6dc8e158 100644
--- a/lxd/storage/drivers/driver_common.go
+++ b/lxd/storage/drivers/driver_common.go
@@ -28,7 +28,7 @@ func (d *common) init(state *state.State, name string, config 
map[string]string,
 // This functions has a removeUnknownKeys option that if set to true will 
remove any unknown fields
 // (excluding those starting with "user.") which can be used when translating 
a volume config to a
 // different storage driver that has different options.
-func (d *common) validateVolume(volConfig map[string]string, driverRules 
map[string]func(value string) error, removeUnknownKeys bool) error {
+func (d *common) validateVolume(vol Volume, driverRules map[string]func(value 
string) error, removeUnknownKeys bool) error {
        checkedFields := map[string]struct{}{}
 
        // Get rules common for all drivers.
@@ -42,14 +42,14 @@ func (d *common) validateVolume(volConfig 
map[string]string, driverRules map[str
        // Run the validator against each field.
        for k, validator := range rules {
                checkedFields[k] = struct{}{} //Mark field as checked.
-               err := validator(volConfig[k])
+               err := validator(vol.config[k])
                if err != nil {
                        return fmt.Errorf("Invalid value for volume option %s: 
%v", k, err)
                }
        }
 
        // Look for any unchecked fields, as these are unknown fields and 
validation should fail.
-       for k := range volConfig {
+       for k := range vol.config {
                _, checked := checkedFields[k]
                if checked {
                        continue
@@ -61,7 +61,7 @@ func (d *common) validateVolume(volConfig map[string]string, 
driverRules map[str
                }
 
                if removeUnknownKeys {
-                       delete(volConfig, k)
+                       delete(vol.config, k)
                } else {
                        return fmt.Errorf("Invalid volume option: %s", k)
                }

From cede0accee3ca0e56c9b6cc995a680cf9af674d1 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Wed, 30 Oct 2019 15:35:59 +0000
Subject: [PATCH 5/5] lxd/storage/drivers/driver/dir: Updates validation
 function

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/storage/drivers/driver_dir.go | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lxd/storage/drivers/driver_dir.go 
b/lxd/storage/drivers/driver_dir.go
index edf76c019e..61cfb9deb4 100644
--- a/lxd/storage/drivers/driver_dir.go
+++ b/lxd/storage/drivers/driver_dir.go
@@ -120,8 +120,8 @@ func (d *dir) GetResources() (*api.ResourcesStoragePool, 
error) {
 }
 
 // ValidateVolume validates the supplied volume config.
-func (d *dir) ValidateVolume(volConfig map[string]string, removeUnknownKeys 
bool) error {
-       return d.validateVolume(volConfig, nil, removeUnknownKeys)
+func (d *dir) ValidateVolume(vol Volume, removeUnknownKeys bool) error {
+       return d.validateVolume(vol, nil, removeUnknownKeys)
 }
 
 // HasVolume indicates whether a specific volume exists on the storage pool.
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to