@@ -47,6 +47,7 @@ endif
GENERATED_BLOCK_HEADERS = block/qapi-generated/qmp-commands.h
GENERATED_BLOCK_HEADERS += block/qapi-generated/qapi-types.h
GENERATED_BLOCK_HEADERS += block/qapi-generated/qapi-visit.h
+GENERATED_BLOCK_HEADERS += block/qapi-generated/qmp-commands-old.h
GENERATED_BLOCK_SOURCES = block/qapi-generated/qmp-marshal.c
GENERATED_BLOCK_SOURCES += block/qapi-generated/qapi-types.c
GENERATED_BLOCK_SOURCES += block/qapi-generated/qapi-visit.c
@@ -296,6 +297,12 @@ $(SRC_PATH)/qapi/block-core.json $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py)
$(gen-out-type) -o block/qapi-generated -m -i $<, \
" GEN $@")
+block/qapi-generated/qmp-commands-old.h: $(SRC_PATH)/qmp-commands.hx \
+block/qapi-generated/qmp-commands.h
+ $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< |\
+./scripts/filter_qmp_commands_old.py \
+$(SRC_PATH)/block/qapi-generated/qmp-commands.h > $@," GEN $@")
+
QGALIB_GEN=$(addprefix qga/qapi-generated/, qga-qapi-types.h qga-qapi-visit.h qga-qmp-commands.h)
$(qga-obj-y) qemu-ga.o: $(QGALIB_GEN)
new file mode 100755
@@ -0,0 +1,93 @@
+#!/usr/bin/env python
+#
+# qmp-commands-old.h filtering
+#
+# Copyright (C) 2014 Nodalink, EURL.
+#
+# Authors:
+# Benoit Canet <benoit.canet@irqsave.net>
+#
+# This work is licensed under the terms of the GNU GPL, version 2.
+# See the COPYING file in the top-level directory.
+
+""" The purpose of this script is to get a subset of qmp-command-old.h
+ suitable for use in one of the block commands. (qemu-nbd, qemu-io).
+ The result is printed on stdout.
+"""
+
+import sys
+import os
+
+def usage():
+ """ Print usage """
+ print "Usage:"
+ print "\tcat /path/to/qmp-commands-old.h|%s /path/to/qmp-command.h" %\
+ sys.argv[0]
+ sys.exit(1)
+
+def get_lines(filename):
+ """ Get the lines composing a file into a list """
+ if not os.path.exists(filename):
+ print "%s does not exists" % filename
+ sys.exit(1)
+ if not os.access(filename, os.R_OK):
+ print "%s is not readable" % filename
+ sys.exit(1)
+ with open(filename) as file_object:
+ return file_object.readlines()
+
+def build_filter_list(filename):
+ """ Build a list of qmp function that will be used as a filter """
+ result = []
+ lines = get_lines(filename)
+ for line in lines:
+ line = line.strip()
+ if not "(" in line:
+ continue
+ if not "input" in line:
+ continue
+ begining, _ = line.split('(')
+ component = begining.split(' ')
+ function = component[len(component) -1]
+ result.append(function)
+ return result
+
+def filter_and_print(to_filter, filter_list):
+ """ Filter the lines from to_filter with filter_list and print on stdout """
+ result = []
+ block = []
+ in_block = False
+ line = to_filter.readline()
+ while line:
+ if (".mhandler.cmd_new" in line or
+ ".mhandler.cmd_async" in line) and in_block:
+ _, end = line.strip().split("=")
+ function_name = end[:-1].strip()
+ if function_name not in filter_list and \
+ function_name != "do_qmp_capabilities" and \
+ function_name != "qmp_marshal_input_query_commands":
+ in_block = False
+ if in_block or "}" in line:
+ block.append(line)
+ if "{" in line:
+ block = [line]
+ in_block = True
+ if "}" in line and in_block:
+ block.append("\n")
+ in_block = False
+ result += block
+ line = to_filter.readline()
+ print "".join(result)
+
+def main():
+ """ Main function of the module """
+ if len(sys.argv) != 2:
+ usage()
+ to_filter = sys.stdin
+ filename = sys.argv[1]
+
+ filter_list = build_filter_list(filename)
+ filter_and_print(to_filter, filter_list)
+
+if __name__ == "__main__":
+ main()
Since qmp-command-olds.h is generated from qmp-commands.hx we will sometime want to include only a subset of it. For example when linking qapi block commands with qemu-nbd. Signed-off-by: Benoit Canet <benoit@irqsave.net> --- Makefile | 7 +++ scripts/filter_qmp_commands_old.py | 93 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100755 scripts/filter_qmp_commands_old.py