summaryrefslogtreecommitdiffstats
path: root/nova/virt
diff options
context:
space:
mode:
authorRafi Khardalian <rafi@metacloud.com>2013-05-29 21:26:19 +0000
committerRafi Khardalian <rafi@metacloud.com>2013-06-05 22:00:12 +0000
commit6e768363450774cfee90e41aa5c40af780d3e04a (patch)
tree23c62b22088edb250028f3c1f110b136f7043daf /nova/virt
parentc9695c1d734593a30c5b36626c73e4eb1cb277bc (diff)
Regenerate missing resized backing files
Fixes bug 1185588 The only way to reliably determine whether we are using a legacy (pre-Grizzly) backing structure is to look at the backing file reference for the instance/disk itself. Thus, if we determine the backing file contains an underscore, we use the value following it as our legacy_backing_size, which is then used to create the necessary backing file. Change-Id: I145f71068c972a604e5361ae79d6315286136786
Diffstat (limited to 'nova/virt')
-rwxr-xr-xnova/virt/libvirt/imagebackend.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/nova/virt/libvirt/imagebackend.py b/nova/virt/libvirt/imagebackend.py
index 3d394fb79..844d9dfde 100755
--- a/nova/virt/libvirt/imagebackend.py
+++ b/nova/virt/libvirt/imagebackend.py
@@ -250,8 +250,33 @@ class Qcow2(Image):
if size:
disk.extend(target, size)
+ # Download the unmodified base image unless we already have a copy.
if not os.path.exists(base):
prepare_template(target=base, *args, **kwargs)
+
+ legacy_backing_size = None
+ legacy_base = base
+
+ # Determine whether an existing qcow2 disk uses a legacy backing by
+ # actually looking at the image itself and parsing the output of the
+ # backing file it expects to be using.
+ if os.path.exists(self.path):
+ backing_path = libvirt_utils.get_disk_backing_file(self.path)
+ backing_file = os.path.basename(backing_path)
+ backing_parts = backing_file.rpartition('_')
+ if backing_file != backing_parts[-1] and \
+ backing_parts[-1].isdigit():
+ legacy_backing_size = int(backing_parts[-1])
+ legacy_base += '_%d' % legacy_backing_size
+ legacy_backing_size *= 1024 * 1024 * 1024
+
+ # Create the legacy backing file if necessary.
+ if legacy_backing_size:
+ if not os.path.exists(legacy_base):
+ with utils.remove_path_on_error(legacy_base):
+ libvirt_utils.copy_image(base, legacy_base)
+ disk.extend(legacy_base, legacy_backing_size)
+
# NOTE(cfb): Having a flavor that sets the root size to 0 and having
# nova effectively ignore that size and use the size of the
# image is considered a feature at this time, not a bug.