The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/6689
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) === 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.parr...@canonical.com>
From 9244c1d74e63dfe122a1a9cbe1d9ffe24e10713f Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@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.parr...@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()
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel