qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

qapi: factor out checking for keys

Introduce a new helper function to check if the given keys are known,
and if mandatory keys are present. The function will be reused in
other places in the following code changes.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20181213123724.4866-5-marcandre.lureau@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>

authored by

Marc-André Lureau and committed by
Markus Armbruster
563bd35d 1e381b65

+13 -7
+13 -7
scripts/qapi/common.py
··· 873 873 allow_metas=['struct']) 874 874 875 875 876 + def check_known_keys(info, source, keys, required, optional): 877 + for key in keys: 878 + if key not in required and key not in optional: 879 + raise QAPISemError(info, "Unknown key '%s' in %s" % (key, source)) 880 + 881 + for key in required: 882 + if key not in keys: 883 + raise QAPISemError(info, "Key '%s' is missing from %s" 884 + % (key, source)) 885 + 886 + 876 887 def check_keys(expr_elem, meta, required, optional=[]): 877 888 expr = expr_elem['expr'] 878 889 info = expr_elem['info'] ··· 880 891 if not isinstance(name, str): 881 892 raise QAPISemError(info, "'%s' key must have a string value" % meta) 882 893 required = required + [meta] 894 + source = "%s '%s'" % (meta, name) 895 + check_known_keys(info, source, expr.keys(), required, optional) 883 896 for (key, value) in expr.items(): 884 - if key not in required and key not in optional: 885 - raise QAPISemError(info, "Unknown key '%s' in %s '%s'" 886 - % (key, meta, name)) 887 897 if key in ['gen', 'success-response'] and value is not False: 888 898 raise QAPISemError(info, 889 899 "'%s' of %s '%s' should only use false value" ··· 895 905 % (key, meta, name)) 896 906 if key == 'if': 897 907 check_if(expr, info) 898 - for key in required: 899 - if key not in expr: 900 - raise QAPISemError(info, "Key '%s' is missing from %s '%s'" 901 - % (key, meta, name)) 902 908 903 909 904 910 def check_exprs(exprs):