[lxc-devel] [lxd/master] lxd/storage/backend/lxd: Applies root disk quota as part of backup import post hook
tomponline on Github
lxc-bot at linuxcontainers.org
Fri Jan 10 09:17:31 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 473 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200110/49a95e6d/attachment.bin>
-------------- next part --------------
From 9244c1d74e63dfe122a1a9cbe1d9ffe24e10713f Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Fri, 10 Jan 2020 09:15:29 +0000
Subject: [PATCH] lxd/storage/backend/lxd: Applies root disk quota as part of
backup import post hook
Ensures that if an instance's root disk config has a size property this is applied on import.
Fixes #6687
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
lxd/storage/backend_lxd.go | 52 +++++++++++++++++++++++++-------------
1 file changed, 34 insertions(+), 18 deletions(-)
diff --git a/lxd/storage/backend_lxd.go b/lxd/storage/backend_lxd.go
index 41409f25eb..91fff54628 100644
--- a/lxd/storage/backend_lxd.go
+++ b/lxd/storage/backend_lxd.go
@@ -480,32 +480,48 @@ func (b *lxdBackend) CreateInstanceFromBackup(srcBackup backup.Info, srcData io.
}
var postHook func(instance.Instance) error
- if volPostHook != nil {
- // Create a post hook function that will use the instance (that will be created) to
- // setup a new volume containing the instance's root disk device's config so that
- // the driver's post hook function can access that config to perform any post
- // instance creation setup.
- postHook = func(inst instance.Instance) error {
- // Get the root disk device config.
- rootDiskConf, err := b.instanceRootVolumeConfig(inst)
+
+ // Create a post hook function that will use the instance (that will be created) to setup a new volume
+ // containing the instance's root disk device's config so that the driver's post hook function can access
+ // that config to perform any post instance creation setup.
+ postHook = func(inst instance.Instance) error {
+ // Get the root disk device config.
+ rootDiskConf, err := b.instanceRootVolumeConfig(inst)
+ if err != nil {
+ return err
+ }
+
+ // Get the volume name on storage.
+ volStorageName := project.Prefix(inst.Project(), inst.Name())
+
+ volType, err := InstanceTypeToVolumeType(inst.Type())
+ if err != nil {
+ return err
+ }
+
+ contentType := InstanceContentType(inst)
+
+ // If the driver returned a post hook, run it now.
+ if volPostHook != nil {
+ // Initialise new volume containing root disk config supplied in instance.
+ vol := b.newVolume(volType, contentType, volStorageName, rootDiskConf)
+ err = volPostHook(vol)
if err != nil {
return err
}
+ }
- // Get the volume name on storage.
- volStorageName := project.Prefix(inst.Project(), inst.Name())
-
- volType, err := InstanceTypeToVolumeType(inst.Type())
+ // Apply quota config from root device if its set. Should be done after driver's post hook if set
+ // so that any volume initialisation has been completed first.
+ if rootDiskConf["size"] != "" {
+ logger.Debug("Applying volume quota from root disk config", log.Ctx{"size": rootDiskConf["size"]})
+ err = b.driver.SetVolumeQuota(vol, rootDiskConf["size"], op)
if err != nil {
return err
}
-
- contentType := InstanceContentType(inst)
-
- // Initialise new volume containing root disk config supplied in instance.
- vol := b.newVolume(volType, contentType, volStorageName, rootDiskConf)
- return volPostHook(vol)
}
+
+ return nil
}
revert.Success()
More information about the lxc-devel
mailing list