-#!/usr/bin/python
+#!/usr/bin/env python3
#
# Compares vmstate information stored in JSON format, obtained from
# the -dump-vmstate QEMU command.
# You should have received a copy of the GNU General Public License along
# with this program; if not, see <http://www.gnu.org/licenses/>.
-from __future__ import print_function
import argparse
import json
import sys
return True
# Some fields changed names between qemu versions. This list
- # is used to whitelist such changes in each section / description.
+ # is used to allow such changes in each section / description.
changed_names = {
'apic': ['timer', 'timer_expiry'],
'e1000': ['dev', 'parent_obj'],
return check_fields_match(fields["Description"]["name"],
substruct_fields[0]["field"], item)
+def size_total(entry):
+ size = entry["size"]
+ if "num" not in entry:
+ return size
+ return size * entry["num"]
def check_fields(src_fields, dest_fields, desc, sec):
# This function checks for all the fields in a section. If some
continue
if s_item["field"] == "unused" or d_item["field"] == "unused":
- if s_item["size"] == d_item["size"]:
+ s_size = size_total(s_item)
+ d_size = size_total(d_item)
+ if s_size == d_size:
continue
if d_item["field"] == "unused":
advance_dest = False
- unused_count = d_item["size"] - s_item["size"]
+ unused_count = d_size - s_size;
continue
if s_item["field"] == "unused":
advance_src = False
- unused_count = s_item["size"] - d_item["size"]
+ unused_count = s_size - d_size
continue
print("Section \"" + sec + "\",", end=' ')
if s["Name"] != d["Name"]:
print("Warning: checking incompatible machine types:", end=' ')
print("\"" + s["Name"] + "\", \"" + d["Name"] + "\"")
- return
def main():
help_text = "Parse JSON-formatted vmstate dumps from QEMU in files SRC and DEST. Checks whether migration from SRC to DEST QEMU versions would break based on the VMSTATE information contained within the JSON outputs. The JSON output is created from a QEMU invocation with the -dump-vmstate parameter and a filename argument to it. Other parameters to QEMU do not matter, except the -M (machine type) parameter."
parser = argparse.ArgumentParser(description=help_text)
- parser.add_argument('-s', '--src', type=file, required=True,
+ parser.add_argument('-s', '--src', type=argparse.FileType('r'),
+ required=True,
help='json dump from src qemu')
- parser.add_argument('-d', '--dest', type=file, required=True,
+ parser.add_argument('-d', '--dest', type=argparse.FileType('r'),
+ required=True,
help='json dump from dest qemu')
parser.add_argument('--reverse', required=False, default=False,
action='store_true',