summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRick Harris <rconradharris@gmail.com>2012-06-08 00:15:41 +0000
committerRick Harris <rconradharris@gmail.com>2012-06-08 17:46:06 +0000
commit93ca3da26bad785b1f30c3be5947de4f9f6d14af (patch)
treea288db344254f9577f3849fbc30a9fd3bcdc223a
parent01ad153b338c9df264e86b8211e82a811ae6332c (diff)
Avoid partially finished cache files.
`VDI.copy` stores half-completed files directly in the SR where we may inadvertenly make use of them. To avoid these 'half-baked' records, we compare its current size to its expected size. Fixes bug 1009750 Change-Id: I0f279ce69bfa0842a6bc74f19fd61462c6013b28
-rw-r--r--nova/virt/xenapi/vm_utils.py27
1 files changed, 24 insertions, 3 deletions
diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py
index e7fc20639..42ba21d9e 100644
--- a/nova/virt/xenapi/vm_utils.py
+++ b/nova/virt/xenapi/vm_utils.py
@@ -413,9 +413,25 @@ def get_sr_path(session):
def find_cached_image(session, image_id, sr_ref):
"""Returns the vdi-ref of the cached image."""
for vdi_ref, vdi_rec in _get_all_vdis_in_sr(session, sr_ref):
- if ('image-id' in vdi_rec['other_config'] and
- vdi_rec['other_config']['image-id'] == image_id):
- return vdi_ref
+ other_config = vdi_rec['other_config']
+
+ try:
+ image_id_match = other_config['image-id'] == image_id
+ except KeyError:
+ image_id_match = False
+
+ # NOTE(sirp): `VDI.copy` stores the partially-completed file in the SR.
+ # In order to avoid these half-baked files, we compare its current size
+ # to the expected size pulled from the original cache file.
+ try:
+ size_match = (other_config['expected_physical_utilisation'] ==
+ vdi_rec['physical_utilisation'])
+ except KeyError:
+ size_match = False
+
+ if image_id_match and size_match:
+ return vdi_ref
+
return None
@@ -616,6 +632,11 @@ def _create_cached_image(context, session, instance, image, image_type):
vdi_ref, 'nova_disk_type',
vdi_type)
+ vdi_rec = session.call_xenapi('VDI.get_record', vdi_ref)
+ session.call_xenapi('VDI.add_to_other_config',
+ vdi_ref, 'expected_physical_utilisation',
+ vdi_rec['physical_utilisation'])
+
if vdi_type == 'swap':
session.call_xenapi('VDI.add_to_other_config',
root_vdi_ref, 'swap-disk',