提交 da820e1c 编写于 作者: P Peter Krempa

virQEMUBuildNetdevCommandlineFromJSON: Prepare for quirky 'guestfwd'

QEMU models guestfwd as:

 'guestfwd': [
                 { "str": "tcp:10.0.2.1:4600-chardev:charchannel0" },
                 { "str": "...."},
             ]

but the command line as:

guestfwd=tcp:10.0.2.1:4600-chardev:charchannel0,guestfwd=...

I guess the original idea was to make it extensible while not worrying
about adding another object for it. Either way it requires us to add yet
another JSON->cmdline convertor for arrays.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NEric Blake <eblake@redhat.com>
上级 b6738ffc
......@@ -109,6 +109,43 @@ virQEMUBuildCommandLineJSONArrayNumbered(const char *key,
}
/**
* This array convertor is for quirky cases where the QMP schema mandates an
* array of objects with only one attribute 'str' which needs to be formatted as
* repeated key-value pairs without the 'str' being printed:
*
* 'guestfwd': [
* { "str": "tcp:10.0.2.1:4600-chardev:charchannel0" },
* { "str": "...."},
* ]
*
* guestfwd=tcp:10.0.2.1:4600-chardev:charchannel0,guestfwd=...
*/
static int
virQEMUBuildCommandLineJSONArrayObjectsStr(const char *key,
virJSONValuePtr array,
virBufferPtr buf,
const char *skipKey G_GNUC_UNUSED,
bool onOff G_GNUC_UNUSED)
{
g_auto(virBuffer) tmp = VIR_BUFFER_INITIALIZER;
size_t i;
for (i = 0; i < virJSONValueArraySize(array); i++) {
virJSONValuePtr member = virJSONValueArrayGet(array, i);
const char *str = virJSONValueObjectGetString(member, "str");
if (!str)
return -1;
virBufferAsprintf(&tmp, "%s=%s,", key, str);
}
virBufferAddBuffer(buf, &tmp);
return 0;
}
/* internal iterator to handle nested object formatting */
static int
virQEMUBuildCommandLineJSONIterate(const char *key,
......@@ -267,7 +304,8 @@ virQEMUBuildNetdevCommandlineFromJSON(virJSONValuePtr props)
virBufferAsprintf(&buf, "%s,", type);
if (virQEMUBuildCommandLineJSON(props, &buf, "type", true, NULL) < 0)
if (virQEMUBuildCommandLineJSON(props, &buf, "type", true,
virQEMUBuildCommandLineJSONArrayObjectsStr) < 0)
return NULL;
return virBufferContentAndReset(&buf);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册