The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/6651
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) === Back in https://github.com/lxc/lxd/pull/6641 @stgraber modified `lxdBackend.newVolume()` to merge the pool's `volume.*` keys into the volume's config (stripping the `volume.` prefix). In order to do this safely the PR also copies the supplied `volConfig` so that any modifications do not affecting the external config map passed in. Unfortunately this has had 2 negative side effects: 1. In `CreateVolumeFromMigration` the incoming config is validated and if some keys are not suitable for the target storage pool the validation process removed them. However the change to copy the supplied config when creating a new volume struct prevented this from bubbling up to the function that creates the database row (luckily the DB row create function itself also does validation and detected this issue). 2. We don't want to store merged config from the pool into the new volume DB row, so we need a way to differentiate between pool config and volume config, yet still be able to merge the two when retrieving specific keys (so that pool's volume config is applied when not overridden in volume config). This PR fixes this by making the following changes: - Removes pool config expansion from `lxdBackend.newVolume()`. - Instead stores a copy of pool config inside the `Volume` struct. - Keeps the copying of supplied `volConfig` inside `Volume struct`. - Adds `Volume.Config()` to allow external access to the current (unexpanded) volume config which may have been modified during validation. - Adds `Volume.ExpandedConfig(key)` function to allow access to an expanded view of a single config key which will then apply the pool's volume config if a key is not defined in the volume config itself. - Updates use of `vol.config["key"]` to `vol.ExpandedConfig("key")` where appropriate.
From 40a26daa80f7b29c266d070100320afaca27b5a0 Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Thu, 19 Dec 2019 14:50:31 +0000 Subject: [PATCH 01/15] lxd/revert: Adds revert helper package for running revert functions in reverse order Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/revert/revert.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 lxd/revert/revert.go diff --git a/lxd/revert/revert.go b/lxd/revert/revert.go new file mode 100644 index 0000000000..df4a3b2578 --- /dev/null +++ b/lxd/revert/revert.go @@ -0,0 +1,33 @@ +package revert + +// Reverter is a helper type to manage revert functions. +type Reverter struct { + revertFuncs []func() +} + +// New returns a new Reverter. +func New() *Reverter { + return &Reverter{} +} + +// Add adds a revert function to the list to be run when Revert() is called. +func (r *Reverter) Add(f func()) { + r.revertFuncs = append(r.revertFuncs, f) +} + +// Fail runs any revert functions in the reverse order they were added. +// Should be used with defer or when a task has encountered an error and needs to be reverted. +func (r *Reverter) Fail() { + funcCount := len(r.revertFuncs) + for k := range r.revertFuncs { + // Run the revert functions in reverse order. + k = funcCount - 1 - k + r.revertFuncs[k]() + } +} + +// Success clears the revert functions previously added. +// Should be called on successful completion of a task to prevent revert functions from being run. +func (r *Reverter) Success() { + r.revertFuncs = nil +} From 6848271fa0b09152d3b09ebb681849c9c18b1322 Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Thu, 19 Dec 2019 15:05:19 +0000 Subject: [PATCH 02/15] lxd/revert/revert/test: Adds revert tests Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/revert/revert_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 lxd/revert/revert_test.go diff --git a/lxd/revert/revert_test.go b/lxd/revert/revert_test.go new file mode 100644 index 0000000000..20b0fefb7b --- /dev/null +++ b/lxd/revert/revert_test.go @@ -0,0 +1,31 @@ +package revert_test + +import ( + "fmt" + + "github.com/lxc/lxd/lxd/revert" +) + +func ExampleReverter_fail() { + revert := revert.New() + defer revert.Fail() + + revert.Add(func() { fmt.Println("1st step") }) + revert.Add(func() { fmt.Println("2nd step") }) + + return // Revert functions are run in reverse order on return. + // Output: 2nd step + // 1st step +} + +func ExampleReverter_success() { + revert := revert.New() + defer revert.Fail() + + revert.Add(func() { fmt.Println("1st step") }) + revert.Add(func() { fmt.Println("2nd step") }) + + revert.Success() // Revert functions added are not run on return. + return + // Output: +} From 92b3349ba58177c33c7cb12aee2b54cb372d972b Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Thu, 19 Dec 2019 14:59:34 +0000 Subject: [PATCH 03/15] lxd/storage/backend/lxd: Updates to use revert pkg rather than custom revertFuncs slice Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/storage/backend_lxd.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/lxd/storage/backend_lxd.go b/lxd/storage/backend_lxd.go index 3bc2029119..1c7a0794cb 100644 --- a/lxd/storage/backend_lxd.go +++ b/lxd/storage/backend_lxd.go @@ -15,6 +15,7 @@ import ( "github.com/lxc/lxd/lxd/migration" "github.com/lxc/lxd/lxd/operations" "github.com/lxc/lxd/lxd/project" + "github.com/lxc/lxd/lxd/revert" "github.com/lxc/lxd/lxd/state" "github.com/lxc/lxd/lxd/storage/drivers" "github.com/lxc/lxd/lxd/storage/locking" @@ -449,12 +450,8 @@ func (b *lxdBackend) CreateInstanceFromBackup(srcBackup backup.Info, srcData io. // We will apply the config as part of the post hook function returned if driver needs to. vol := b.newVolume(drivers.VolumeTypeContainer, drivers.ContentTypeFS, volStorageName, nil) - revertFuncs := []func(){} - defer func() { - for _, revertFunc := range revertFuncs { - revertFunc() - } - }() + revert := revert.New() + defer revert.Fail() // Unpack the backup into the new storage volume(s). volPostHook, revertHook, err := b.driver.CreateVolumeFromBackup(vol, srcBackup.Snapshots, srcData, srcBackup.OptimizedStorage, op) @@ -463,7 +460,7 @@ func (b *lxdBackend) CreateInstanceFromBackup(srcBackup backup.Info, srcData io. } if revertHook != nil { - revertFuncs = append(revertFuncs, revertHook) + revert.Add(revertHook) } err = b.ensureInstanceSymlink(instancetype.Container, srcBackup.Project, srcBackup.Name, vol.MountPath()) @@ -471,7 +468,7 @@ func (b *lxdBackend) CreateInstanceFromBackup(srcBackup backup.Info, srcData io. return nil, nil, err } - revertFuncs = append(revertFuncs, func() { + revert.Add(func() { b.removeInstanceSymlink(instancetype.Container, srcBackup.Project, srcBackup.Name) }) @@ -481,7 +478,7 @@ func (b *lxdBackend) CreateInstanceFromBackup(srcBackup backup.Info, srcData io. return nil, nil, err } - revertFuncs = append(revertFuncs, func() { + revert.Add(func() { b.removeInstanceSnapshotSymlinkIfUnused(instancetype.Container, srcBackup.Project, srcBackup.Name) }) } @@ -520,7 +517,7 @@ func (b *lxdBackend) CreateInstanceFromBackup(srcBackup backup.Info, srcData io. } } - revertFuncs = nil + revert.Success() return postHook, revertHook, nil } From 9e58b8e80bb925a53381e7726f80fd3eae898f1e Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Thu, 19 Dec 2019 15:00:08 +0000 Subject: [PATCH 04/15] lxd/storage/drivers/driver/dir: Updates to use revert pkg rather than custom revertFuncs slice Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/storage/drivers/driver_dir_utils.go | 18 +++++++----------- lxd/storage/drivers/driver_dir_volumes.go | 20 +++++++------------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/lxd/storage/drivers/driver_dir_utils.go b/lxd/storage/drivers/driver_dir_utils.go index aee2a289d6..f13bb1cae7 100644 --- a/lxd/storage/drivers/driver_dir_utils.go +++ b/lxd/storage/drivers/driver_dir_utils.go @@ -3,6 +3,7 @@ package drivers import ( "fmt" + "github.com/lxc/lxd/lxd/revert" "github.com/lxc/lxd/lxd/storage/quota" log "github.com/lxc/lxd/shared/log15" "github.com/lxc/lxd/shared/units" @@ -29,10 +30,8 @@ func (d *dir) setupInitialQuota(vol Volume) (func(), error) { return nil, err } - // Define a function to revert the quota being setup. - revertFunc := func() { - d.deleteQuota(volPath, volID) - } + revert := revert.New() + defer revert.Fail() // Initialise the volume's quota using the volume ID. err = d.initQuota(volPath, volID) @@ -40,12 +39,9 @@ func (d *dir) setupInitialQuota(vol Volume) (func(), error) { return nil, err } - revert := true - defer func() { - if revert { - revertFunc() - } - }() + // Define a function to revert the quota being setup. + revertFunc := func() { d.deleteQuota(volPath, volID) } + revert.Add(revertFunc) // Set the quota. err = d.setQuota(volPath, volID, vol.config["size"]) @@ -53,7 +49,7 @@ func (d *dir) setupInitialQuota(vol Volume) (func(), error) { return nil, err } - revert = false + revert.Success() return revertFunc, nil } diff --git a/lxd/storage/drivers/driver_dir_volumes.go b/lxd/storage/drivers/driver_dir_volumes.go index bda0866ef1..53291ee4a4 100644 --- a/lxd/storage/drivers/driver_dir_volumes.go +++ b/lxd/storage/drivers/driver_dir_volumes.go @@ -8,6 +8,7 @@ import ( "github.com/lxc/lxd/lxd/migration" "github.com/lxc/lxd/lxd/operations" + "github.com/lxc/lxd/lxd/revert" "github.com/lxc/lxd/lxd/rsync" "github.com/lxc/lxd/lxd/storage/quota" "github.com/lxc/lxd/shared" @@ -18,18 +19,15 @@ import ( func (d *dir) CreateVolume(vol Volume, filler *VolumeFiller, op *operations.Operation) error { volPath := vol.MountPath() + revert := revert.New() + defer revert.Fail() + // Create the volume itself. err := vol.EnsureMountPath() if err != nil { return err } - - revertPath := true - defer func() { - if revertPath { - os.RemoveAll(volPath) - } - }() + revert.Add(func() { os.RemoveAll(volPath) }) // Create sparse loopback file if volume is block. rootBlockPath := "" @@ -46,11 +44,7 @@ func (d *dir) CreateVolume(vol Volume, filler *VolumeFiller, op *operations.Oper } if revertFunc != nil { - defer func() { - if revertPath { - revertFunc() - } - }() + revert.Add(revertFunc) } } @@ -72,7 +66,7 @@ func (d *dir) CreateVolume(vol Volume, filler *VolumeFiller, op *operations.Oper } } - revertPath = false + revert.Success() return nil } From 84a4afe5fb284312fcf3303c265df36fc4c0e8b0 Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Fri, 20 Dec 2019 11:48:26 +0000 Subject: [PATCH 05/15] lxd/storage/drivers/volume: Differentiates between volume config and pool config - Stores pool config inside Volume. - Allows external access to volume config via Config() function. - Allows access to "expanded" config keys using ExpandedConfig(key) function which first checks if key exists in Volume config and if not looks for "volume.{key}" in pool's config. Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/storage/drivers/volume.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lxd/storage/drivers/volume.go b/lxd/storage/drivers/volume.go index 94db9c6973..055b233040 100644 --- a/lxd/storage/drivers/volume.go +++ b/lxd/storage/drivers/volume.go @@ -50,6 +50,7 @@ var BaseDirectories = map[VolumeType][]string{ type Volume struct { name string pool string + poolConfig map[string]string volType VolumeType contentType ContentType config map[string]string @@ -57,10 +58,11 @@ type Volume struct { } // NewVolume instantiates a new Volume struct. -func NewVolume(driver Driver, poolName string, volType VolumeType, contentType ContentType, volName string, volConfig map[string]string) Volume { +func NewVolume(driver Driver, poolName string, volType VolumeType, contentType ContentType, volName string, volConfig, poolConfig map[string]string) Volume { return Volume{ name: volName, pool: poolName, + poolConfig: poolConfig, volType: volType, contentType: contentType, config: volConfig, @@ -73,6 +75,21 @@ func (v Volume) Name() string { return v.name } +// Config returns the volumes (unexpanded) config. +func (v Volume) Config() map[string]string { + return v.config +} + +// ExpandedConfig returns either the value of the volume's config key or the pool's config "volume.{key}" value. +func (v Volume) ExpandedConfig(key string) string { + volVal, ok := v.config[key] + if !ok { + return volVal + } + + return v.poolConfig[fmt.Sprintf("volume.%s", key)] +} + // NewSnapshot instantiates a new Volume struct representing a snapshot of the parent volume. func (v Volume) NewSnapshot(snapshotName string) (Volume, error) { if v.IsSnapshot() { @@ -80,7 +97,7 @@ func (v Volume) NewSnapshot(snapshotName string) (Volume, error) { } fullSnapName := GetSnapshotVolumeName(v.name, snapshotName) - return NewVolume(v.driver, v.pool, v.volType, v.contentType, fullSnapName, v.config), nil + return NewVolume(v.driver, v.pool, v.volType, v.contentType, fullSnapName, v.config, v.poolConfig), nil } // IsSnapshot indicates if volume is a snapshot. From 1e87b944338b73eec0186937019c5b8f55d8477e Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Fri, 20 Dec 2019 11:50:53 +0000 Subject: [PATCH 06/15] lxd/storage/backend/lxd: Removes expansion of pool's volume config into volume config in newVolume() Instead stores pool config inside volume to allow read-time expansion of config. This was because during validation we should only be validating (and potentially removing keys during migration validation) the volume's config. We need to ensure the volume's config stays intact and is not merged with the pool's volume config, so post-validation it can be used to store in database. Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/storage/backend_lxd.go | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/lxd/storage/backend_lxd.go b/lxd/storage/backend_lxd.go index 1c7a0794cb..7edd920e75 100644 --- a/lxd/storage/backend_lxd.go +++ b/lxd/storage/backend_lxd.go @@ -116,30 +116,21 @@ func (b *lxdBackend) create(localOnly bool, op *operations.Operation) error { return nil } -// newVolume returns a new Volume instance. +// newVolume returns a new Volume instance containing copies of the supplied volume config and the pools config, func (b *lxdBackend) newVolume(volType drivers.VolumeType, contentType drivers.ContentType, volName string, volConfig map[string]string) drivers.Volume { - // Copy the config map. + // Copy the config map to avoid internal modifications affecting external state. newConfig := map[string]string{} for k, v := range volConfig { newConfig[k] = v } - // And now expand it with the pool data. + // Copy the pool config map to avoid internal modifications affecting external state. + newPoolConfig := map[string]string{} for k, v := range b.db.Config { - if !strings.HasPrefix(k, "volume.") { - continue - } - - fields := strings.SplitN(k, "volume.", 2) - name := fields[1] - - _, ok := newConfig[name] - if !ok { - newConfig[name] = v - } + newPoolConfig[k] = v } - return drivers.NewVolume(b.driver, b.name, volType, contentType, volName, newConfig) + return drivers.NewVolume(b.driver, b.name, volType, contentType, volName, newConfig, newPoolConfig) } // GetResources returns utilisation information about the pool. From 4266f6c8b3cc42cc8099cecba9fd508b03e8889a Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Fri, 20 Dec 2019 11:53:33 +0000 Subject: [PATCH 07/15] lxd/storage/backend/lxd: Updates CreateCustomVolumeFromMigration to use Volume.Config() to create DB record Instead of using args.Config which isn't modified during validation and would leave invalid keys potentially when doing cross-pool migrations. Volume.Config() also doesn't merge the pool's volume config, so this is suitable for storing as a new volume row. Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/storage/backend_lxd.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lxd/storage/backend_lxd.go b/lxd/storage/backend_lxd.go index 7edd920e75..a67de4aa4b 100644 --- a/lxd/storage/backend_lxd.go +++ b/lxd/storage/backend_lxd.go @@ -2149,13 +2149,14 @@ 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(b.newVolume(drivers.VolumeTypeCustom, drivers.ContentTypeFS, args.Name, args.Config), true) + vol := b.newVolume(drivers.VolumeTypeCustom, drivers.ContentTypeFS, args.Name, args.Config) + err := b.driver.ValidateVolume(vol, true) if err != nil { return err } // Create database entry for new storage volume. - err = VolumeDBCreate(b.state, "default", b.name, args.Name, args.Description, db.StoragePoolVolumeTypeNameCustom, false, args.Config) + err = VolumeDBCreate(b.state, "default", b.name, args.Name, args.Description, db.StoragePoolVolumeTypeNameCustom, false, vol.Config()) if err != nil { return err } @@ -2167,7 +2168,7 @@ func (b *lxdBackend) CreateCustomVolumeFromMigration(conn io.ReadWriteCloser, ar newSnapshotName := drivers.GetSnapshotVolumeName(args.Name, snapName) // Create database entry for new storage volume snapshot. - err = VolumeDBCreate(b.state, "default", b.name, newSnapshotName, args.Description, db.StoragePoolVolumeTypeNameCustom, true, args.Config) + err = VolumeDBCreate(b.state, "default", b.name, newSnapshotName, args.Description, db.StoragePoolVolumeTypeNameCustom, true, vol.Config()) if err != nil { return err } @@ -2176,7 +2177,6 @@ func (b *lxdBackend) CreateCustomVolumeFromMigration(conn io.ReadWriteCloser, ar } } - vol := b.newVolume(drivers.VolumeTypeCustom, drivers.ContentTypeFS, args.Name, args.Config) err = b.driver.CreateVolumeFromMigration(vol, conn, args, nil, op) if err != nil { conn.Close() From fb4053ff9ccd46fe50d0f56ebcc9f3f7a508f636 Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Fri, 20 Dec 2019 11:55:01 +0000 Subject: [PATCH 08/15] lxd/storage/utils: drivers.NewVolume usage Signed-off-by: Thomas Parrott <thomas.parr...@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 22f24f7bae..9a461d02e3 100644 --- a/lxd/storage/utils.go +++ b/lxd/storage/utils.go @@ -394,7 +394,7 @@ func VolumeValidateConfig(s *state.State, name string, config map[string]string, if err != drivers.ErrUnknownDriver { // 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) + return driver.ValidateVolume(drivers.NewVolume(driver, parentPool.Name, drivers.VolumeTypeCustom, drivers.ContentTypeFS, name, config, parentPool.Config), false) } // Otherwise fallback to doing legacy validation. From 3f7c78159f146f72a009079ada50dc67dafabc63 Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Fri, 20 Dec 2019 11:55:39 +0000 Subject: [PATCH 09/15] lxd/storage/drivers/driver/cephfs/volumes: drivers.NewVolume usage Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/storage/drivers/driver_cephfs_volumes.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lxd/storage/drivers/driver_cephfs_volumes.go b/lxd/storage/drivers/driver_cephfs_volumes.go index 62119fa5ff..284f5160df 100644 --- a/lxd/storage/drivers/driver_cephfs_volumes.go +++ b/lxd/storage/drivers/driver_cephfs_volumes.go @@ -80,7 +80,7 @@ func (d *cephfs) CreateVolumeFromCopy(vol Volume, srcVol Volume, copySnapshots b for _, snapName := range revertSnaps { fullSnapName := GetSnapshotVolumeName(vol.name, snapName) - snapVol := NewVolume(d, d.name, vol.volType, vol.contentType, fullSnapName, vol.config) + snapVol := NewVolume(d, d.name, vol.volType, vol.contentType, fullSnapName, vol.config, vol.poolConfig) d.DeleteVolumeSnapshot(snapVol, op) } @@ -161,7 +161,7 @@ func (d *cephfs) CreateVolumeFromMigration(vol Volume, conn io.ReadWriteCloser, // Remove any paths created if we are reverting. for _, snapName := range revertSnaps { fullSnapName := GetSnapshotVolumeName(vol.name, snapName) - snapVol := NewVolume(d, d.name, vol.volType, vol.contentType, fullSnapName, vol.config) + snapVol := NewVolume(d, d.name, vol.volType, vol.contentType, fullSnapName, vol.config, vol.poolConfig) d.DeleteVolumeSnapshot(snapVol, op) } @@ -187,7 +187,7 @@ func (d *cephfs) CreateVolumeFromMigration(vol Volume, conn io.ReadWriteCloser, } fullSnapName := GetSnapshotVolumeName(vol.name, snapName) - snapVol := NewVolume(d, d.name, vol.volType, vol.contentType, fullSnapName, vol.config) + snapVol := NewVolume(d, d.name, vol.volType, vol.contentType, fullSnapName, vol.config, vol.poolConfig) // Create the snapshot itself. err = d.CreateVolumeSnapshot(snapVol, op) From 6cffe5a785b26eef9296876a00c3772170ce5eaf Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Fri, 20 Dec 2019 11:56:05 +0000 Subject: [PATCH 10/15] lxd/storage/drivers/driver/cephfs/volumes: vol.ExpandedConfig usage Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/storage/drivers/driver_cephfs_volumes.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lxd/storage/drivers/driver_cephfs_volumes.go b/lxd/storage/drivers/driver_cephfs_volumes.go index 284f5160df..cf3e99292a 100644 --- a/lxd/storage/drivers/driver_cephfs_volumes.go +++ b/lxd/storage/drivers/driver_cephfs_volumes.go @@ -119,7 +119,7 @@ func (d *cephfs) CreateVolumeFromCopy(vol Volume, srcVol Volume, copySnapshots b } // Apply the volume quota if specified. - err = d.SetVolumeQuota(vol, vol.config["size"], op) + err = d.SetVolumeQuota(vol, vol.ExpandedConfig("size"), op) if err != nil { return err } @@ -200,7 +200,7 @@ func (d *cephfs) CreateVolumeFromMigration(vol Volume, conn io.ReadWriteCloser, } // Apply the volume quota if specified. - err = d.SetVolumeQuota(vol, vol.config["size"], op) + err = d.SetVolumeQuota(vol, vol.ExpandedConfig("size"), op) if err != nil { return err } From 489f8db0a73cb1a8b2012caea9ea573e6ec7fa13 Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Fri, 20 Dec 2019 11:56:24 +0000 Subject: [PATCH 11/15] lxd/storage/drivers/driver/cephfs/volumes: Comments Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/storage/drivers/driver_cephfs_volumes.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lxd/storage/drivers/driver_cephfs_volumes.go b/lxd/storage/drivers/driver_cephfs_volumes.go index cf3e99292a..a1cb7ebde9 100644 --- a/lxd/storage/drivers/driver_cephfs_volumes.go +++ b/lxd/storage/drivers/driver_cephfs_volumes.go @@ -267,7 +267,7 @@ func (d *cephfs) HasVolume(vol Volume) bool { return d.vfsHasVolume(vol) } -// ValidateVolume validates the supplied volume config. +// ValidateVolume validates the supplied volume config. Optionally removes invalid keys from the volume's config. func (d *cephfs) ValidateVolume(vol Volume, removeUnknownKeys bool) error { return d.validateVolume(vol, nil, removeUnknownKeys) } From 9270ab701eead8c2ae39fee18d66e2a327aa8b91 Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Fri, 20 Dec 2019 11:56:44 +0000 Subject: [PATCH 12/15] lxd/storage/drivers/driver/dir/utils: vol.ExpandedConfig usage Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/storage/drivers/driver_dir_utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lxd/storage/drivers/driver_dir_utils.go b/lxd/storage/drivers/driver_dir_utils.go index f13bb1cae7..83157ac9ef 100644 --- a/lxd/storage/drivers/driver_dir_utils.go +++ b/lxd/storage/drivers/driver_dir_utils.go @@ -44,7 +44,7 @@ func (d *dir) setupInitialQuota(vol Volume) (func(), error) { revert.Add(revertFunc) // Set the quota. - err = d.setQuota(volPath, volID, vol.config["size"]) + err = d.setQuota(volPath, volID, vol.ExpandedConfig("size")) if err != nil { return nil, err } From 8a633898c355fae3eb316f72a36d6671b8c3bbca Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Fri, 20 Dec 2019 11:57:57 +0000 Subject: [PATCH 13/15] lxd/storage/drivers/driver/dir/volumes: Comments Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/storage/drivers/driver_dir_volumes.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lxd/storage/drivers/driver_dir_volumes.go b/lxd/storage/drivers/driver_dir_volumes.go index 53291ee4a4..274be5a84f 100644 --- a/lxd/storage/drivers/driver_dir_volumes.go +++ b/lxd/storage/drivers/driver_dir_volumes.go @@ -186,7 +186,7 @@ func (d *dir) HasVolume(vol Volume) bool { return d.vfsHasVolume(vol) } -// ValidateVolume validates the supplied volume config. +// ValidateVolume validates the supplied volume config. Optionally removes invalid keys from the volume's config. func (d *dir) ValidateVolume(vol Volume, removeUnknownKeys bool) error { return d.validateVolume(vol, nil, removeUnknownKeys) } From 9265b6c73e652ba73d53118a399b38a829001c39 Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Fri, 20 Dec 2019 11:58:20 +0000 Subject: [PATCH 14/15] lxd/storage/drivers/generic: NewVolume usage Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/storage/drivers/generic.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lxd/storage/drivers/generic.go b/lxd/storage/drivers/generic.go index 5102677e90..8b16b79be0 100644 --- a/lxd/storage/drivers/generic.go +++ b/lxd/storage/drivers/generic.go @@ -38,7 +38,7 @@ func genericCopyVolume(d Driver, applyQuota func(vol Volume) (func(), error), vo // Remove any paths created if we are reverting. for _, snapName := range revertSnaps { fullSnapName := GetSnapshotVolumeName(vol.name, snapName) - snapVol := NewVolume(d, d.Name(), vol.volType, vol.contentType, fullSnapName, vol.config) + snapVol := NewVolume(d, d.Name(), vol.volType, vol.contentType, fullSnapName, vol.config, vol.poolConfig) d.DeleteVolumeSnapshot(snapVol, op) } @@ -60,7 +60,7 @@ func genericCopyVolume(d Driver, applyQuota func(vol Volume) (func(), error), vo }, op) fullSnapName := GetSnapshotVolumeName(vol.name, snapName) - snapVol := NewVolume(d, d.Name(), vol.volType, vol.contentType, fullSnapName, vol.config) + snapVol := NewVolume(d, d.Name(), vol.volType, vol.contentType, fullSnapName, vol.config, vol.poolConfig) // Create the snapshot itself. err = d.CreateVolumeSnapshot(snapVol, op) @@ -115,7 +115,7 @@ func genericCreateVolumeFromMigration(d Driver, applyQuota func(vol Volume) (fun // Remove any paths created if we are reverting. for _, snapName := range revertSnaps { fullSnapName := GetSnapshotVolumeName(vol.Name(), snapName) - snapVol := NewVolume(d, d.Name(), vol.volType, vol.contentType, fullSnapName, vol.config) + snapVol := NewVolume(d, d.Name(), vol.volType, vol.contentType, fullSnapName, vol.config, vol.poolConfig) d.DeleteVolumeSnapshot(snapVol, op) } @@ -142,7 +142,7 @@ func genericCreateVolumeFromMigration(d Driver, applyQuota func(vol Volume) (fun // Create the snapshot itself. fullSnapshotName := GetSnapshotVolumeName(vol.name, snapName) - snapVol := NewVolume(d, d.Name(), vol.volType, vol.contentType, fullSnapshotName, vol.config) + snapVol := NewVolume(d, d.Name(), vol.volType, vol.contentType, fullSnapshotName, vol.config, vol.poolConfig) err = d.CreateVolumeSnapshot(snapVol, op) if err != nil { @@ -205,7 +205,7 @@ func genericBackupUnpack(d Driver, vol Volume, snapshots []string, srcData io.Re revertHook := func() { for _, snapName := range snapshots { fullSnapshotName := GetSnapshotVolumeName(vol.name, snapName) - snapVol := NewVolume(d, d.Name(), vol.volType, vol.contentType, fullSnapshotName, vol.config) + snapVol := NewVolume(d, d.Name(), vol.volType, vol.contentType, fullSnapshotName, vol.config, vol.poolConfig) d.DeleteVolumeSnapshot(snapVol, op) } @@ -259,7 +259,7 @@ func genericBackupUnpack(d Driver, vol Volume, snapshots []string, srcData io.Re } fullSnapshotName := GetSnapshotVolumeName(vol.name, snapName) - snapVol := NewVolume(d, d.Name(), vol.volType, vol.contentType, fullSnapshotName, vol.config) + snapVol := NewVolume(d, d.Name(), vol.volType, vol.contentType, fullSnapshotName, vol.config, vol.poolConfig) err = d.CreateVolumeSnapshot(snapVol, op) if err != nil { return nil, nil, err From fdec985e30f1e93736a9cd7065a2f3a8bebea451 Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Fri, 20 Dec 2019 11:58:40 +0000 Subject: [PATCH 15/15] lxd/storage/drivers/utils: vol.ExpandedConfig usage Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/storage/drivers/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lxd/storage/drivers/utils.go b/lxd/storage/drivers/utils.go index a2230b18ab..355c94517d 100644 --- a/lxd/storage/drivers/utils.go +++ b/lxd/storage/drivers/utils.go @@ -248,7 +248,7 @@ func createSparseFile(filePath string, sizeBytes int64) error { // ensureVolumeBlockFile creates or resizes the raw block file for a volume. func ensureVolumeBlockFile(vol Volume, path string) error { - blockSize := vol.config["size"] + blockSize := vol.ExpandedConfig("size") if blockSize == "" { blockSize = defaultBlockSize }
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel