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

qemu-storage-daemon: Add --object option

Add a command line option to create user-creatable QOM objects.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20200224143008.13362-9-kwolf@redhat.com>
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>

+49 -1
+1 -1
Makefile.objs
··· 31 31 # storage-daemon-obj-y is code used by qemu-storage-daemon (these objects are 32 32 # used for system emulation, too, but specified separately there) 33 33 34 - storage-daemon-obj-y = block/ 34 + storage-daemon-obj-y = block/ qom/ 35 35 storage-daemon-obj-y += blockdev.o iothread.o 36 36 37 37 ######################################################################
+47
qemu-storage-daemon.c
··· 33 33 #include "qapi/error.h" 34 34 #include "qapi/qapi-visit-block-core.h" 35 35 #include "qapi/qapi-commands-block-core.h" 36 + #include "qapi/qmp/qdict.h" 36 37 #include "qapi/qobject-input-visitor.h" 37 38 38 39 #include "qemu-common.h" 39 40 #include "qemu-version.h" 40 41 #include "qemu/config-file.h" 41 42 #include "qemu/error-report.h" 43 + #include "qemu/help_option.h" 42 44 #include "qemu/log.h" 43 45 #include "qemu/main-loop.h" 44 46 #include "qemu/module.h" 47 + #include "qemu/option.h" 48 + #include "qom/object_interfaces.h" 45 49 46 50 #include "trace/control.h" 47 51 ··· 63 67 " [,driver specific parameters...]\n" 64 68 " configure a block backend\n" 65 69 "\n" 70 + " --object help list object types that can be added\n" 71 + " --object <type>,help list properties for the given object type\n" 72 + " --object <type>[,<property>=<value>...]\n" 73 + " create a new object of type <type>, setting\n" 74 + " properties in the order they are specified. Note\n" 75 + " that the 'id' property must be set.\n" 76 + " See the qemu(1) man page for documentation of the\n" 77 + " objects that can be added.\n" 78 + "\n" 66 79 QEMU_HELP_BOTTOM "\n", 67 80 error_get_progname()); 68 81 } 69 82 70 83 enum { 71 84 OPTION_BLOCKDEV = 256, 85 + OPTION_OBJECT, 86 + }; 87 + 88 + static QemuOptsList qemu_object_opts = { 89 + .name = "object", 90 + .implied_opt_name = "qom-type", 91 + .head = QTAILQ_HEAD_INITIALIZER(qemu_object_opts.head), 92 + .desc = { 93 + { } 94 + }, 72 95 }; 73 96 74 97 static void process_options(int argc, char *argv[]) ··· 78 101 static const struct option long_options[] = { 79 102 {"blockdev", required_argument, NULL, OPTION_BLOCKDEV}, 80 103 {"help", no_argument, NULL, 'h'}, 104 + {"object", required_argument, NULL, OPTION_OBJECT}, 81 105 {"trace", required_argument, NULL, 'T'}, 82 106 {"version", no_argument, NULL, 'V'}, 83 107 {0, 0, 0, 0} ··· 119 143 120 144 qmp_blockdev_add(options, &error_fatal); 121 145 qapi_free_BlockdevOptions(options); 146 + break; 147 + } 148 + case OPTION_OBJECT: 149 + { 150 + QemuOpts *opts; 151 + const char *type; 152 + QDict *args; 153 + QObject *ret_data = NULL; 154 + 155 + /* FIXME The keyval parser rejects 'help' arguments, so we must 156 + * unconditionall try QemuOpts first. */ 157 + opts = qemu_opts_parse(&qemu_object_opts, 158 + optarg, true, &error_fatal); 159 + type = qemu_opt_get(opts, "qom-type"); 160 + if (type && user_creatable_print_help(type, opts)) { 161 + exit(EXIT_SUCCESS); 162 + } 163 + qemu_opts_del(opts); 164 + 165 + args = keyval_parse(optarg, "qom-type", &error_fatal); 166 + qmp_object_add(args, &ret_data, &error_fatal); 167 + qobject_unref(args); 168 + qobject_unref(ret_data); 122 169 break; 123 170 } 124 171 default:
+1
qom/Makefile.objs
··· 2 2 qom-obj-y += object_interfaces.o 3 3 4 4 common-obj-$(CONFIG_SOFTMMU) += qom-hmp-cmds.o qom-qmp-cmds.o 5 + storage-daemon-obj-y += qom-qmp-cmds.o