summaryrefslogtreecommitdiffstats
path: root/plugins/xenserver
diff options
context:
space:
mode:
authorRick Harris <rconradharris@gmail.com>2012-07-24 18:22:41 +0000
committerRick Harris <rconradharris@gmail.com>2012-07-24 18:26:57 +0000
commitdd54a15a7f3964addae3eef9a4eef30d22690b97 (patch)
tree3b56a4890c7263c4df215784d64777fde44d5734 /plugins/xenserver
parent013ab2fdfc2c8a0c74ecf3c2287fb6a36d8b6728 (diff)
downloadnova-dd54a15a7f3964addae3eef9a4eef30d22690b97.tar.gz
nova-dd54a15a7f3964addae3eef9a4eef30d22690b97.tar.xz
nova-dd54a15a7f3964addae3eef9a4eef30d22690b97.zip
Xen: Validate VHD footer timestamps.
This is a sanity check to ensure the footer timestamps on a VHD are reasonable (e.g. not in the future). This condition can occur if the local time for the source and destination machines in a migration are not in agreement, requiring an adjustment to /etc/localtime and/or NTP reconfiguration. Without this check there is a risk of importing a corrupt VHD into the SR causing the entire SR to become corrupted. Change-Id: I17228e50d6f54632f3bfc32a682e511f876517ec
Diffstat (limited to 'plugins/xenserver')
-rw-r--r--plugins/xenserver/xenapi/etc/xapi.d/plugins/utils.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/utils.py b/plugins/xenserver/xenapi/etc/xapi.d/plugins/utils.py
index 23165bba1..bd9286658 100644
--- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/utils.py
+++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/utils.py
@@ -156,6 +156,28 @@ def _assert_vhd_not_hidden(path):
locals())
+def _validate_footer_timestamp(vdi_path):
+ """
+ This check ensures that the timestamps listed in the VHD footer aren't in
+ the future. This can occur during a migration if the clocks on the the two
+ Dom0's are out-of-sync. This would corrupt the SR if it were imported, so
+ generate an exception to bail.
+ """
+ check_cmd = "vhd-util check -n %(vdi_path)s -p" % locals()
+ check_proc = make_subprocess(check_cmd, stdout=True, stderr=True)
+ out, err = finish_subprocess(
+ check_proc, check_cmd, ok_exit_codes=[0, 22])
+ first_line = out.splitlines()[0].strip()
+
+ if 'primary footer invalid' in first_line:
+ raise Exception("VDI '%(vdi_path)s' has timestamp in the future,"
+ " ensure source and destination host machines have"
+ " time set correctly" % locals())
+ elif check_proc.returncode != 0:
+ raise Exception("Unexpected output '%(out)s' from vhd-util" %
+ locals())
+
+
def _validate_vdi_chain(vdi_path):
"""
This check ensures that the parent pointers on the VHDs are valid
@@ -169,6 +191,7 @@ def _validate_vdi_chain(vdi_path):
out, err = finish_subprocess(
query_proc, query_cmd, ok_exit_codes=[0, 22])
first_line = out.splitlines()[0].strip()
+
if first_line.endswith(".vhd"):
return first_line
elif 'has no parent' in first_line:
@@ -182,6 +205,7 @@ def _validate_vdi_chain(vdi_path):
cur_path = vdi_path
while cur_path:
+ _validate_footer_timestamp(cur_path)
cur_path = get_parent_path(cur_path)