'-compat' as a modern implementation based on QAPI already takes JSON as the argument. Convert our code to use it directly. QEMU declares the ised QAPI types as: { 'enum': 'CompatPolicyInput', 'data': [ 'accept', 'reject', 'crash' ] } { 'enum': 'CompatPolicyOutput', 'data': [ 'accept', 'hide' ] } { 'struct': 'CompatPolicy', 'data': { '*deprecated-input': 'CompatPolicyInput', '*deprecated-output': 'CompatPolicyOutput' } } Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/qemu/qemu_command.c | 28 ++++++++++++------- .../qemu-ns.x86_64-latest.args | 2 +- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 292335cc62..2c02aa41ef 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -10535,11 +10535,14 @@ qemuBuildCompatDeprecatedCommandLine(virCommand *cmd, virDomainDef *def, virQEMUCaps *qemuCaps) { - g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; + g_autoptr(virJSONValue) props = NULL; + g_autofree char *propsstr = NULL; qemuDomainXmlNsDef *nsdata = def->namespaceData; qemuCommnadDeprecationBehavior behavior = QEMU_COMMAND_DEPRECATION_BEHAVIOR_NONE; const char *behaviorStr = cfg->deprecationBehavior; int tmp; + const char *deprecatedOutput = "hide"; + const char *deprecatedInput = NULL; if (nsdata && nsdata->deprecationBehavior) behaviorStr = nsdata->deprecationBehavior; @@ -10562,30 +10565,35 @@ qemuBuildCompatDeprecatedCommandLine(virCommand *cmd, return; } - /* all active options hide output fields from qemu */ - virBufferAddLit(&buf, "deprecated-output=hide,"); - switch (behavior) { case QEMU_COMMAND_DEPRECATION_BEHAVIOR_OMIT: case QEMU_COMMAND_DEPRECATION_BEHAVIOR_NONE: case QEMU_COMMAND_DEPRECATION_BEHAVIOR_LAST: default: - /* output field hiding is default for all cases */ + deprecatedOutput = "hide"; break; case QEMU_COMMAND_DEPRECATION_BEHAVIOR_REJECT: - virBufferAddLit(&buf, "deprecated-input=reject,"); + deprecatedOutput = "hide"; + deprecatedInput = "reject"; break; case QEMU_COMMAND_DEPRECATION_BEHAVIOR_CRASH: - virBufferAddLit(&buf, "deprecated-input=crash,"); + deprecatedOutput = "hide"; + deprecatedInput = "crash"; break; } - virBufferTrim(&buf, ","); + if (virJSONValueObjectAdd(&props, + "S:deprecated-output", deprecatedOutput, + "S:deprecated-input", deprecatedInput, + NULL) < 0) + return; - virCommandAddArg(cmd, "-compat"); - virCommandAddArgBuffer(cmd, &buf); + if (!(propsstr = virJSONValueToString(props, false))) + return; + + virCommandAddArgList(cmd, "-compat", propsstr, NULL); } diff --git a/tests/qemuxml2argvdata/qemu-ns.x86_64-latest.args b/tests/qemuxml2argvdata/qemu-ns.x86_64-latest.args index 34688dbcf4..4e9d1c0133 100644 --- a/tests/qemuxml2argvdata/qemu-ns.x86_64-latest.args +++ b/tests/qemuxml2argvdata/qemu-ns.x86_64-latest.args @@ -10,7 +10,7 @@ NS=ns \ BAR='' \ /usr/bin/qemu-system-i386 \ -name guest=QEMUGuest1,debug-threads=on \ --compat deprecated-output=hide,deprecated-input=crash \ +-compat '{"deprecated-output":"hide","deprecated-input":"crash"}' \ -S \ -object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/tmp/lib/domain--1-QEMUGuest1/master-key.aes"}' \ -machine pc,accel=tcg,usb=off,dump-guest-core=off,memory-backend=pc.ram \ -- 2.31.1