* [Qemu-devel] [PATCH v2 1/3] qapi.py: Move common code to evaluate()
2013-06-21 15:46 [Qemu-devel] [PATCH v2 0/3] qapi: Top-level type reference for command definitions Kevin Wolf
@ 2013-06-21 15:46 ` Kevin Wolf
2013-06-21 15:46 ` [Qemu-devel] [PATCH v2 2/3] qapi.py: Allow top-level type reference for command definitions Kevin Wolf
2013-06-21 15:46 ` [Qemu-devel] [PATCH v2 3/3] qapi-schema: Use BlockdevSnapshot type for blockdev-snapshot-sync Kevin Wolf
2 siblings, 0 replies; 4+ messages in thread
From: Kevin Wolf @ 2013-06-21 15:46 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, armbru, stefanha, lcapitulino
Don't duplicate more code than is really necessary.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
scripts/qapi.py | 24 ++++++++++--------------
1 file changed, 10 insertions(+), 14 deletions(-)
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 02ad668..3a64769 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -76,12 +76,18 @@ def parse(tokens):
return tokens[0], tokens[1:]
def evaluate(string):
- return parse(map(lambda x: x, tokenize(string)))[0]
+ expr_eval = parse(map(lambda x: x, tokenize(string)))[0]
+
+ if expr_eval.has_key('enum'):
+ add_enum(expr_eval['enum'])
+ elif expr_eval.has_key('union'):
+ add_enum('%sKind' % expr_eval['union'])
+
+ return expr_eval
def parse_schema(fp):
exprs = []
expr = ''
- expr_eval = None
for line in fp:
if line.startswith('#') or line == '\n':
@@ -90,23 +96,13 @@ def parse_schema(fp):
if line.startswith(' '):
expr += line
elif expr:
- expr_eval = evaluate(expr)
- if expr_eval.has_key('enum'):
- add_enum(expr_eval['enum'])
- elif expr_eval.has_key('union'):
- add_enum('%sKind' % expr_eval['union'])
- exprs.append(expr_eval)
+ exprs.append(evaluate(expr))
expr = line
else:
expr += line
if expr:
- expr_eval = evaluate(expr)
- if expr_eval.has_key('enum'):
- add_enum(expr_eval['enum'])
- elif expr_eval.has_key('union'):
- add_enum('%sKind' % expr_eval['union'])
- exprs.append(expr_eval)
+ exprs.append(evaluate(expr))
return exprs
--
1.8.1.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH v2 2/3] qapi.py: Allow top-level type reference for command definitions
2013-06-21 15:46 [Qemu-devel] [PATCH v2 0/3] qapi: Top-level type reference for command definitions Kevin Wolf
2013-06-21 15:46 ` [Qemu-devel] [PATCH v2 1/3] qapi.py: Move common code to evaluate() Kevin Wolf
@ 2013-06-21 15:46 ` Kevin Wolf
2013-06-21 15:46 ` [Qemu-devel] [PATCH v2 3/3] qapi-schema: Use BlockdevSnapshot type for blockdev-snapshot-sync Kevin Wolf
2 siblings, 0 replies; 4+ messages in thread
From: Kevin Wolf @ 2013-06-21 15:46 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, armbru, stefanha, lcapitulino
If 'data' for a command definition isn't a dict, but a string, it is
taken as a (struct) type name and the fields of this struct are directly
used as parameters.
This is useful for transactionable commands that can use the same type
definition for both the transaction action and the arguments of the
standalone command.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
scripts/qapi.py | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 3a64769..e151659 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -82,6 +82,8 @@ def evaluate(string):
add_enum(expr_eval['enum'])
elif expr_eval.has_key('union'):
add_enum('%sKind' % expr_eval['union'])
+ elif expr_eval.has_key('type'):
+ add_struct(expr_eval)
return expr_eval
@@ -107,6 +109,11 @@ def parse_schema(fp):
return exprs
def parse_args(typeinfo):
+ if isinstance(typeinfo, basestring):
+ struct = find_struct(typeinfo)
+ assert struct != None
+ typeinfo = struct['data']
+
for member in typeinfo:
argname = member
argentry = typeinfo[member]
@@ -176,6 +183,18 @@ def type_name(name):
return name
enum_types = []
+struct_types = []
+
+def add_struct(definition):
+ global struct_types
+ struct_types.append(definition)
+
+def find_struct(name):
+ global struct_types
+ for struct in struct_types:
+ if struct['type'] == name:
+ return struct
+ return None
def add_enum(name):
global enum_types
--
1.8.1.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH v2 3/3] qapi-schema: Use BlockdevSnapshot type for blockdev-snapshot-sync
2013-06-21 15:46 [Qemu-devel] [PATCH v2 0/3] qapi: Top-level type reference for command definitions Kevin Wolf
2013-06-21 15:46 ` [Qemu-devel] [PATCH v2 1/3] qapi.py: Move common code to evaluate() Kevin Wolf
2013-06-21 15:46 ` [Qemu-devel] [PATCH v2 2/3] qapi.py: Allow top-level type reference for command definitions Kevin Wolf
@ 2013-06-21 15:46 ` Kevin Wolf
2 siblings, 0 replies; 4+ messages in thread
From: Kevin Wolf @ 2013-06-21 15:46 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, armbru, stefanha, lcapitulino
We don't have to duplicate the definition any more now that we may refer
to a type instead.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
qapi-schema.json | 14 ++------------
1 file changed, 2 insertions(+), 12 deletions(-)
diff --git a/qapi-schema.json b/qapi-schema.json
index a80ee40..54fbeef 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1652,16 +1652,7 @@
#
# Generates a synchronous snapshot of a block device.
#
-# @device: the name of the device to generate the snapshot from.
-#
-# @snapshot-file: the target of the new image. If the file exists, or if it
-# is a device, the snapshot will be created in the existing
-# file/device. If does not exist, a new file will be created.
-#
-# @format: #optional the format of the snapshot image, default is 'qcow2'.
-#
-# @mode: #optional whether and how QEMU should create a new image, default is
-# 'absolute-paths'.
+# For the arguments, see the documentation of BlockdevSnapshot.
#
# Returns: nothing on success
# If @device is not a valid block device, DeviceNotFound
@@ -1669,8 +1660,7 @@
# Since 0.14.0
##
{ 'command': 'blockdev-snapshot-sync',
- 'data': { 'device': 'str', 'snapshot-file': 'str', '*format': 'str',
- '*mode': 'NewImageMode'} }
+ 'data': 'BlockdevSnapshot' }
##
# @human-monitor-command:
--
1.8.1.4
^ permalink raw reply related [flat|nested] 4+ messages in thread