block: Crude initial implementation of -blockdev
v2 cover block: Crude initial implementation of -blockdev
This is based on "[PATCH 00/24] QemuOpts util/cutils: Fix and clean up number conversions".
v2: Support KEY=VALUE,... syntax as well.
Markus Armbruster (2):
util/qemu-option: New opt_parse_qdict()
block: Crude initial implementation of -blockdev
include/qemu/option.h | 3 ++ qemu-options.hx | 3 ++ tests/test-qemu-opts.c | 132 +++++++++++++++++++++++++++++++++++++++++++++++++ util/qemu-option.c | 131 ++++++++++++++++++++++++++++++++++++++++++++++++ vl.c | 51 +++++++++++++++++++ 5 files changed, 320 insertions(+)
Signature · 1 line
2.7.4
RFC PATCH v2 2/2 block: Crude initial implementation of -blockdev
The new command line option -blockdev works like QMP command blockdev-add.
The option argument may be given in JSON syntax, exactly as in QMP. Example usage:
-blockdev '{"node-name": "foo", "driver": "raw", "file": {"driver": "file", "filename": "foo.img"} }'The JSON argument doesn't exactly blend into the existing option syntax, so the traditional KEY=VALUE,... syntax is also supported, using dotted keys to do the nesting:
-blockdev node-name=foo,driver=raw,file.driver=file,file.filename=foo.img
Note that calling qmp_blockdev_add() (say via qmp_marshal_block_add()) right away would crash. We need to stash the configuration for later instead. This is crudely done, and bypasses QemuOpts, even though storing configuration is what QemuOpts is for. Need to revamp option infrastructure to support QAPI types like BlockdevOptions.
--- qemu-options.hx | 3 +++ vl.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+)
qemu-options.hx +3 -0
@@ -512,6 +512,9 @@ Use @var{file} as CD-ROM image (you cannot use @option{-hdc} and using @file{/dev/cdrom} as filename (@pxref{host_drives}). ETEXI +DEF("blockdev", HAS_ARG, QEMU_OPTION_blockdev, + "-blockdev FIXME document\n", QEMU_OPTION_blockdev) + DEF("drive", HAS_ARG, QEMU_OPTION_drive, "-drive [file=file][,if=type][,bus=n][,unit=m][,media=d][,index=i]\n" " [,cyls=c,heads=h,secs=s[,trans=t]][,snapshot=on|off]\n"
vl.c +51 -0
75 lines not on this page · raw message
Signature · 1 line
2.7.4
RFC PATCH v2 1/2 util/qemu-option: New opt_parse_qdict()
In reply to Markus Armbrusteropt_parse_qdict() parses KEY=VALUE,... into a QDict. Works like qemu_opts_parse(), except:
* Returns a QDict instead of a QemuOpts (d'oh).
* It supports nesting, unlike QemuOpts: a KEY is split into key components at '.' (dotted key convention; the block layer does something similar on top of QemuOpts). The key components are QDict keys, and the last one's value is updated to VALUE.
* Each key component may be up to 127 bytes long. qemu_opts_parse() limits the entire key to 127 bytes.
* Overlong key components are rejected. qemu_opts_parse() silently truncates them.
* Empty key components are rejected. qemu_opts_parse() happily accepts empty keys.
* It does not store the returned value. qemu_opts_parse() stores it in the QemuOptsList.
* It does not treat parameter "id" specially. qemu_opts_parse() ignores all but the first "id", and fails when its value isn't id_wellformed(), or duplicate (a QemuOpts with the same ID is already stored). It also screws up when a value contains ",id=".
I intend to grow this into a saner replacement for QemuOpts. It'll take time, though.
--- include/qemu/option.h | 3 ++ tests/test-qemu-opts.c | 132 +++++++++++++++++++++++++++++++++++++++++++++++++ util/qemu-option.c | 131 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 266 insertions(+)
include/qemu/option.h +3 -0
@@ -132,4 +132,7 @@ void qemu_opts_print_help(QemuOptsList *list);void qemu_opts_free (QemuOptsList *list);QemuOptsList *qemu_opts_append (QemuOptsList *dst,QemuOptsList *list); +QDict *opt_parse_qdict (const char *params,const char *implied_key, +Error **errp); +#endif
tests/test-qemu-opts.c +132 -0
144 lines not on this page · raw message
util/qemu-option.c +131 -0
134 lines not on this page · raw message
Signature · 1 line
2.7.4
Quoted 4 lines · Markus Armbruster
This is based on "[PATCH 00/24] QemuOpts util/cutils: Fix and clean up number conversions".
v2: Support KEY=VALUE,... syntax as well.
Forgot to mention: the thing collapses when KEY has a type other than string. There's one reason this is marked RFC...