[lxc-devel] [lxd/master] Storage validation

tomponline on Github lxc-bot at linuxcontainers.org
Mon Dec 16 08:57:51 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20191216/aa090ffa/attachment.bin>
-------------- next part --------------
From 0566477254af787e3002dfec97de15ae4af92fe9 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Mon, 16 Dec 2019 08:54:51 +0000
Subject: [PATCH 1/3] lxc/storage/utils: Updates validateVolumeCommonRules to
 accept volume argument

This is so the common validation fields can be vol type, content type and block backing aware.

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

diff --git a/lxd/storage/utils.go b/lxd/storage/utils.go
index 1ec383dcbc..cd34c2c596 100644
--- a/lxd/storage/utils.go
+++ b/lxd/storage/utils.go
@@ -610,7 +610,7 @@ func VolumePropertiesTranslate(targetConfig map[string]string, targetParentPoolD
 }
 
 // validateVolumeCommonRules returns a map of volume config rules common to all drivers.
-func validateVolumeCommonRules() map[string]func(string) error {
+func validateVolumeCommonRules(vol drivers.Volume) map[string]func(string) error {
 	return map[string]func(string) error{
 		"security.shifted":    shared.IsBool,
 		"security.unmapped":   shared.IsBool,

From 828ad32d8d07bcb4caeb81e6393ff4eb95e49596 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Mon, 16 Dec 2019 08:55:47 +0000
Subject: [PATCH 2/3] lxd/storage/drivers/volume: Exposes BlockBacking property
 from storage driver via IsBlockBacked()

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/storage/drivers/volume.go | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lxd/storage/drivers/volume.go b/lxd/storage/drivers/volume.go
index 8cddd9fe8c..b04c3d3e4b 100644
--- a/lxd/storage/drivers/volume.go
+++ b/lxd/storage/drivers/volume.go
@@ -173,3 +173,8 @@ func (v Volume) Snapshots(op *operations.Operation) ([]Volume, error) {
 
 	return snapVols, nil
 }
+
+// IsBlockBacked indicates whether storage device is block backed.
+func (v Volume) IsBlockBacked() bool {
+	return v.driver.Info().BlockBacking
+}

From 5cbd3738a707bcf54ef6324e3ceaf3ed0b88e1f8 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Mon, 16 Dec 2019 08:56:31 +0000
Subject: [PATCH 3/3] lxd/storage: Updates commonVolRulesFunc usage

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/storage/drivers/driver_common.go | 18 +++++++++---------
 lxd/storage/drivers/interface.go     |  2 +-
 lxd/storage/drivers/load.go          |  4 ++--
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/lxd/storage/drivers/driver_common.go b/lxd/storage/drivers/driver_common.go
index 0cc95e996c..591577f5dd 100644
--- a/lxd/storage/drivers/driver_common.go
+++ b/lxd/storage/drivers/driver_common.go
@@ -16,19 +16,19 @@ import (
 )
 
 type common struct {
-	name           string
-	config         map[string]string
-	getVolID       func(volType VolumeType, volName string) (int64, error)
-	getCommonRules func() map[string]func(string) error
-	state          *state.State
-	logger         logger.Logger
+	name                 string
+	config               map[string]string
+	getVolID             func(volType VolumeType, volName string) (int64, error)
+	getCommonVolumeRules func(vol Volume) map[string]func(string) error
+	state                *state.State
+	logger               logger.Logger
 }
 
-func (d *common) init(state *state.State, name string, config map[string]string, logger logger.Logger, volIDFunc func(volType VolumeType, volName string) (int64, error), commonRulesFunc func() map[string]func(string) error) error {
+func (d *common) init(state *state.State, name string, config map[string]string, logger logger.Logger, volIDFunc func(volType VolumeType, volName string) (int64, error), commonVolRulesFunc func(vol Volume) map[string]func(string) error) error {
 	d.name = name
 	d.config = config
 	d.getVolID = volIDFunc
-	d.getCommonRules = commonRulesFunc
+	d.getCommonVolumeRules = commonVolRulesFunc
 	d.state = state
 	d.logger = logger
 
@@ -47,7 +47,7 @@ func (d *common) validateVolume(vol Volume, driverRules map[string]func(value st
 	checkedFields := map[string]struct{}{}
 
 	// Get rules common for all drivers.
-	rules := d.getCommonRules()
+	rules := d.getCommonVolumeRules(vol)
 
 	// Merge driver specific rules into common rules.
 	for field, validator := range driverRules {
diff --git a/lxd/storage/drivers/interface.go b/lxd/storage/drivers/interface.go
index e0bad2ee89..c5f7d063ec 100644
--- a/lxd/storage/drivers/interface.go
+++ b/lxd/storage/drivers/interface.go
@@ -14,7 +14,7 @@ import (
 type driver interface {
 	Driver
 
-	init(state *state.State, name string, config map[string]string, logger logger.Logger, volIDFunc func(volType VolumeType, volName string) (int64, error), commonRulesFunc func() map[string]func(string) error) error
+	init(state *state.State, name string, config map[string]string, logger logger.Logger, volIDFunc func(volType VolumeType, volName string) (int64, error), commonRulesFunc func(vol Volume) map[string]func(string) error) error
 	load() error
 }
 
diff --git a/lxd/storage/drivers/load.go b/lxd/storage/drivers/load.go
index 84e8dc2cc7..974dd17699 100644
--- a/lxd/storage/drivers/load.go
+++ b/lxd/storage/drivers/load.go
@@ -11,7 +11,7 @@ var drivers = map[string]func() driver{
 }
 
 // Load returns a Driver for an existing low-level storage pool.
-func Load(state *state.State, driverName string, name string, config map[string]string, logger logger.Logger, volIDFunc func(volType VolumeType, volName string) (int64, error), commonRulesFunc func() map[string]func(string) error) (Driver, error) {
+func Load(state *state.State, driverName string, name string, config map[string]string, logger logger.Logger, volIDFunc func(volType VolumeType, volName string) (int64, error), commonVolRulesFunc func(vol Volume) map[string]func(string) error) (Driver, error) {
 	// Locate the driver loader.
 	driverFunc, ok := drivers[driverName]
 	if !ok {
@@ -19,7 +19,7 @@ func Load(state *state.State, driverName string, name string, config map[string]
 	}
 
 	d := driverFunc()
-	err := d.init(state, name, config, logger, volIDFunc, commonRulesFunc)
+	err := d.init(state, name, config, logger, volIDFunc, commonVolRulesFunc)
 	if err != nil {
 		return nil, err
 	}


More information about the lxc-devel mailing list