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
This commit is contained in:
Rick Harris
2012-07-24 18:22:41 +00:00
parent 013ab2fdfc
commit dd54a15a7f

View File

@@ -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)