libvirt: Fix device hot-plug on 7.0.0

The QEMU base version on 7.2+dfsg-7+deb12u5 was still causing
incompatibilities other than the ones fixed in [1].
When hot-plugging devices to instances, the error was still occurring
and extra cherry-picks [2-4] were required to be brought from master
in order to fix bug/2083929.

Patch 0014-qemu-remove-support-for-generating-yes-no-boolean-op.patch
was not strictly necessary for this fix, but it helped to smooth the
package build with the other two patches in place.

When we decide to uprev libvirt, this change will no longer be needed.

[1] https://opendev.org/starlingx/virt/commit/a4fad169adb97d5d7d6fd1ae6510db8c24fd6f3
[2] libvirt/libvirt/-/commit/29318399667114b3dd8a054f7ef898b3ba74828d
[3] libvirt/libvirt/-/commit/4f33b817b2926198ec626f10c3fca1c8aaececf6
[4] libvirt/libvirt/-/commit/f763b6e43900605308df8dbca16e4702033947e9

Test Plan:
PASS - build-pkgs -c -p libvirt
PASS - build-stx-images.sh --only stx-libvirt
PASS - Re-apply STX-O with new stx-libvirt image
PASS - Launch VM with 1 bootable volume
PASS - Attach 1 extra volume to the VM
PASS - Live-migrate the VM

Bug: 2083929

Change-Id: I19bcce19fb006e9023505e0c9d6aa67c4c0cb827
Signed-off-by: Thales Elero Cervi <thaleselero.cervi@windriver.com>
Co-authored-by: Daniel Caires <DanielMarques.Caires@windriver.com>
This commit is contained in:
Thales Elero Cervi 2024-10-17 15:46:57 -03:00
parent b158f13b17
commit 7a7256da11
4 changed files with 667 additions and 0 deletions

View File

@ -0,0 +1,261 @@
From 29318399667114b3dd8a054f7ef898b3ba74828d Mon Sep 17 00:00:00 2001
From: Daniel Berrange <berrange@redhat.com>
Date: Tue, 16 Feb 2021 12:36:15 +0000
Subject: [PATCH] qemu: remove support for generating yes|no boolean options
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
All callers are now using the on|off syntax, so yes|no is a unreachable
code path.
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
[ Patch defuzzed for libvirt 7.0.0]
Signed-off-by: Thales Elero Cervi <thaleselero.cervi@windriver.com>
---
src/util/virqemu.c | 48 +++++++++++++------------------------
src/util/virqemu.h | 10 +++-----
tests/qemucommandutiltest.c | 10 ++++----
3 files changed, 24 insertions(+), 44 deletions(-)
diff --git a/src/util/virqemu.c b/src/util/virqemu.c
index a6011e5..aa322be 100644
--- a/src/util/virqemu.c
+++ b/src/util/virqemu.c
@@ -37,7 +37,6 @@ struct virQEMUCommandLineJSONIteratorData {
const char *prefix;
virBufferPtr buf;
const char *skipKey;
- bool onOff;
virQEMUBuildCommandLineJSONArrayFormatFunc arrayFunc;
};
@@ -47,7 +46,6 @@ virQEMUBuildCommandLineJSONRecurse(const char *key,
virJSONValuePtr value,
virBufferPtr buf,
const char *skipKey,
- bool onOff,
virQEMUBuildCommandLineJSONArrayFormatFunc arrayFunc,
bool nested);
@@ -57,8 +55,7 @@ int
virQEMUBuildCommandLineJSONArrayBitmap(const char *key,
virJSONValuePtr array,
virBufferPtr buf,
- const char *skipKey G_GNUC_UNUSED,
- bool onOff G_GNUC_UNUSED)
+ const char *skipKey G_GNUC_UNUSED)
{
ssize_t pos = -1;
ssize_t end;
@@ -87,8 +84,7 @@ int
virQEMUBuildCommandLineJSONArrayNumbered(const char *key,
virJSONValuePtr array,
virBufferPtr buf,
- const char *skipKey,
- bool onOff)
+ const char *skipKey)
{
virJSONValuePtr member;
size_t i;
@@ -99,7 +95,7 @@ virQEMUBuildCommandLineJSONArrayNumbered(const char *key,
member = virJSONValueArrayGet((virJSONValuePtr) array, i);
prefix = g_strdup_printf("%s.%zu", key, i);
- if (virQEMUBuildCommandLineJSONRecurse(prefix, member, buf, skipKey, onOff,
+ if (virQEMUBuildCommandLineJSONRecurse(prefix, member, buf, skipKey,
virQEMUBuildCommandLineJSONArrayNumbered,
true) < 0)
return 0;
@@ -125,8 +121,7 @@ static int
virQEMUBuildCommandLineJSONArrayObjectsStr(const char *key,
virJSONValuePtr array,
virBufferPtr buf,
- const char *skipKey G_GNUC_UNUSED,
- bool onOff G_GNUC_UNUSED)
+ const char *skipKey G_GNUC_UNUSED)
{
g_auto(virBuffer) tmp = VIR_BUFFER_INITIALIZER;
size_t i;
@@ -163,11 +158,11 @@ virQEMUBuildCommandLineJSONIterate(const char *key,
tmpkey = g_strdup_printf("%s.%s", data->prefix, key);
return virQEMUBuildCommandLineJSONRecurse(tmpkey, value, data->buf,
- data->skipKey, data->onOff,
+ data->skipKey,
data->arrayFunc, false);
} else {
return virQEMUBuildCommandLineJSONRecurse(key, value, data->buf,
- data->skipKey, data->onOff,
+ data->skipKey,
data->arrayFunc, false);
}
}
@@ -178,11 +173,10 @@ virQEMUBuildCommandLineJSONRecurse(const char *key,
virJSONValuePtr value,
virBufferPtr buf,
const char *skipKey,
- bool onOff,
virQEMUBuildCommandLineJSONArrayFormatFunc arrayFunc,
bool nested)
{
- struct virQEMUCommandLineJSONIteratorData data = { key, buf, skipKey, onOff, arrayFunc };
+ struct virQEMUCommandLineJSONIteratorData data = { key, buf, skipKey, arrayFunc };
virJSONType type = virJSONValueGetType(value);
virJSONValuePtr elem;
bool tmp;
@@ -207,18 +201,10 @@ virQEMUBuildCommandLineJSONRecurse(const char *key,
case VIR_JSON_TYPE_BOOLEAN:
virJSONValueGetBoolean(value, &tmp);
- if (onOff) {
- if (tmp)
- virBufferAsprintf(buf, "%s=on,", key);
- else
- virBufferAsprintf(buf, "%s=off,", key);
- } else {
- if (tmp)
- virBufferAsprintf(buf, "%s=yes,", key);
- else
- virBufferAsprintf(buf, "%s=no,", key);
- }
-
+ if (tmp)
+ virBufferAsprintf(buf, "%s=on,", key);
+ else
+ virBufferAsprintf(buf, "%s=off,", key);
break;
case VIR_JSON_TYPE_ARRAY:
@@ -229,7 +215,7 @@ virQEMUBuildCommandLineJSONRecurse(const char *key,
return -1;
}
- if (!arrayFunc || arrayFunc(key, value, buf, skipKey, onOff) < 0) {
+ if (!arrayFunc || arrayFunc(key, value, buf, skipKey) < 0) {
/* fallback, treat the array as a non-bitmap, adding the key
* for each member */
for (i = 0; i < virJSONValueArraySize(value); i++) {
@@ -237,7 +223,7 @@ virQEMUBuildCommandLineJSONRecurse(const char *key,
/* recurse to avoid duplicating code */
if (virQEMUBuildCommandLineJSONRecurse(key, elem, buf, skipKey,
- onOff, arrayFunc, true) < 0)
+ arrayFunc, true) < 0)
return -1;
}
}
@@ -265,7 +251,6 @@ virQEMUBuildCommandLineJSONRecurse(const char *key,
* @value: json object containing the value
* @buf: otuput buffer
* @skipKey: name of key that will be handled separately by caller
- * @onOff: Use 'on' and 'off' for boolean values rather than 'yes' and 'no'
* @arrayFunc: array formatter function to allow for different syntax
*
* Formats JSON value object into command line parameters suitable for use with
@@ -277,10 +262,9 @@ int
virQEMUBuildCommandLineJSON(virJSONValuePtr value,
virBufferPtr buf,
const char *skipKey,
- bool onOff,
virQEMUBuildCommandLineJSONArrayFormatFunc array)
{
- if (virQEMUBuildCommandLineJSONRecurse(NULL, value, buf, skipKey, onOff, array, false) < 0)
+ if (virQEMUBuildCommandLineJSONRecurse(NULL, value, buf, skipKey, array, false) < 0)
return -1;
virBufferTrim(buf, ",");
@@ -311,7 +295,7 @@ virQEMUBuildNetdevCommandlineFromJSON(virJSONValuePtr props,
virBufferAsprintf(&buf, "%s,", type);
- if (virQEMUBuildCommandLineJSON(props, &buf, "type", true,
+ if (virQEMUBuildCommandLineJSON(props, &buf, "type",
virQEMUBuildCommandLineJSONArrayObjectsStr) < 0)
return NULL;
@@ -348,7 +332,7 @@ virQEMUBuildDriveCommandlineFromJSON(virJSONValuePtr srcdef)
{
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
- if (virQEMUBuildCommandLineJSON(srcdef, &buf, NULL, false,
+ if (virQEMUBuildCommandLineJSON(srcdef, &buf, NULL,
virQEMUBuildCommandLineJSONArrayNumbered) < 0)
return NULL;
diff --git a/src/util/virqemu.h b/src/util/virqemu.h
index b81efc7..849b7df 100644
--- a/src/util/virqemu.h
+++ b/src/util/virqemu.h
@@ -29,23 +29,19 @@
typedef int (*virQEMUBuildCommandLineJSONArrayFormatFunc)(const char *key,
virJSONValuePtr array,
virBufferPtr buf,
- const char *skipKey,
- bool onOff);
+ const char *skipKey);
int virQEMUBuildCommandLineJSONArrayBitmap(const char *key,
virJSONValuePtr array,
virBufferPtr buf,
- const char *skipKey,
- bool onOff);
+ const char *skipKey);
int virQEMUBuildCommandLineJSONArrayNumbered(const char *key,
virJSONValuePtr array,
virBufferPtr buf,
- const char *skipKey,
- bool onOff);
+ const char *skipKey);
int virQEMUBuildCommandLineJSON(virJSONValuePtr value,
virBufferPtr buf,
const char *skipKey,
- bool onOff,
virQEMUBuildCommandLineJSONArrayFormatFunc array);
char *
diff --git a/tests/qemucommandutiltest.c b/tests/qemucommandutiltest.c
index 305f59e..6291c3b 100644
--- a/tests/qemucommandutiltest.c
+++ b/tests/qemucommandutiltest.c
@@ -47,7 +47,7 @@ testQemuCommandBuildFromJSON(const void *opaque)
return -1;
}
- if (virQEMUBuildCommandLineJSON(val, &buf, NULL, false, data->arrayfunc) < 0) {
+ if (virQEMUBuildCommandLineJSON(val, &buf, NULL, data->arrayfunc) < 0) {
fprintf(stderr,
"\nvirQEMUBuildCommandlineJSON failed process JSON:\n%s\n",
data->props);
@@ -99,8 +99,8 @@ mymain(void)
DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"string\":\"qwer\"}", "string=qwer");
DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"string\":\"qw,e,r\"}", "string=qw,,e,,r");
DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"number\":1234}", "number=1234");
- DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"boolean\":true}", "boolean=yes");
- DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"boolean\":false}", "boolean=no");
+ DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"boolean\":true}", "boolean=on");
+ DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"boolean\":false}", "boolean=off");
DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"bitmap\":[]}", NULL);
DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"bitmap\":[0]}", "bitmap=0");
DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"bitmap\":[1,3,5]}",
@@ -113,14 +113,14 @@ mymain(void)
DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"array\":[\"bleah\",\"qwerty\",1]}",
"array=bleah,array=qwerty,array=1");
DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"boolean\":true,\"hyphen-name\":1234,\"some_string\":\"bleah\"}",
- "boolean=yes,hyphen-name=1234,some_string=bleah");
+ "boolean=on,hyphen-name=1234,some_string=bleah");
DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"nest\": {\"boolean\":true,"
"\"hyphen-name\":1234,"
"\"some_string\":\"bleah\","
"\"bleah\":\"bl,eah\""
"}"
"}",
- "nest.boolean=yes,nest.hyphen-name=1234,"
+ "nest.boolean=on,nest.hyphen-name=1234,"
"nest.some_string=bleah,nest.bleah=bl,,eah");
DO_TEST_COMMAND_DRIVE_FROM_JSON("{\"driver\":\"gluster\","
"\"volume\":\"test\","
--
2.34.1

View File

@ -0,0 +1,369 @@
From 4f33b817b2926198ec626f10c3fca1c8aaececf6 Mon Sep 17 00:00:00 2001
From: Peter Krempa <pkrempa@redhat.com>
Date: Fri, 12 Mar 2021 15:44:19 +0100
Subject: [PATCH] qemu: command: Use JSON for QAPIfied -object directly
Skip the lossy conversion to legacy commandline arguments by using the
JSON props directly when -object is QAPIfied. This avoids issues with
conversion of bitmaps and also allows validation of the generated JSON
against the QMP schema in the tests.
Since the new approach is triggered by a qemu capability the code
from 'virQEMUBuildObjectCommandlineFromJSON' in util/virqemu.c was moved
to 'qemuBuildObjectCommandlineFromJSON' in qemu/qemu_command.c which has
the virQEMUCaps type.
Some functions needed to be modified to propagate qemuCaps.
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
[ Patch defuzzed for libvirt 7.0.0]
Signed-off-by: Thales Elero Cervi <thaleselero.cervi@windriver.com>
---
src/libvirt_private.syms | 1 -
src/qemu/qemu_command.c | 106 +++++++++++++++++++++++++++------------
src/util/virqemu.c | 24 ---------
src/util/virqemu.h | 3 --
4 files changed, 73 insertions(+), 61 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index c325040..e96bf96 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2955,7 +2955,6 @@ virQEMUBuildCommandLineJSONArrayBitmap;
virQEMUBuildCommandLineJSONArrayNumbered;
virQEMUBuildDriveCommandlineFromJSON;
virQEMUBuildNetdevCommandlineFromJSON;
-virQEMUBuildObjectCommandlineFromJSON;
# util/virrandom.h
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 9f972a8..dafa85b 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -177,6 +177,32 @@ VIR_ENUM_IMPL(qemuNumaPolicy,
);
+static int
+qemuBuildObjectCommandlineFromJSON(virBuffer *buf,
+ virJSONValue *props,
+ virQEMUCaps *qemuCaps)
+{
+ const char *type = virJSONValueObjectGetString(props, "qom-type");
+ const char *alias = virJSONValueObjectGetString(props, "id");
+
+ if (!type || !alias) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("missing 'type'(%s) or 'alias'(%s) field of QOM 'object'"),
+ NULLSTR(type), NULLSTR(alias));
+ return -1;
+ }
+
+ if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_QAPIFIED)) {
+ return virJSONValueToBuffer(props, buf, false);
+ } else {
+ virBufferAsprintf(buf, "%s,", type);
+
+ return virQEMUBuildCommandLineJSON(props, buf, "qom-type",
+ virQEMUBuildCommandLineJSONArrayBitmap);
+ }
+}
+
+
/**
* qemuBuildMasterKeyCommandLine:
* @cmd: the command to modify
@@ -690,6 +716,7 @@ qemuBuildSecretInfoProps(qemuDomainSecretInfoPtr secinfo,
* qemuBuildObjectSecretCommandLine:
* @cmd: the command to modify
* @secinfo: pointer to the secret info object
+ * @qemuCaps: qemu capabilities
*
* If the secinfo is available and associated with an AES secret,
* then format the command line for the secret object. This object
@@ -700,7 +727,8 @@ qemuBuildSecretInfoProps(qemuDomainSecretInfoPtr secinfo,
*/
static int
qemuBuildObjectSecretCommandLine(virCommandPtr cmd,
- qemuDomainSecretInfoPtr secinfo)
+ qemuDomainSecretInfoPtr secinfo,
+ virQEMUCaps *qemuCaps)
{
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
g_autoptr(virJSONValue) props = NULL;
@@ -708,7 +736,7 @@ qemuBuildObjectSecretCommandLine(virCommandPtr cmd,
if (qemuBuildSecretInfoProps(secinfo, &props) < 0)
return -1;
- if (virQEMUBuildObjectCommandlineFromJSON(&buf, props) < 0)
+ if (qemuBuildObjectCommandlineFromJSON(&buf, props, qemuCaps) < 0)
return -1;
virCommandAddArg(cmd, "-object");
@@ -876,7 +904,7 @@ qemuBuildTLSx509CommandLine(virCommandPtr cmd,
certEncSecretAlias, qemuCaps, &props) < 0)
return -1;
- if (virQEMUBuildObjectCommandlineFromJSON(&buf, props) < 0)
+ if (qemuBuildObjectCommandlineFromJSON(&buf, props, qemuCaps) < 0)
return -1;
virCommandAddArg(cmd, "-object");
@@ -1981,14 +2009,15 @@ qemuBuildFloppyCommandLineControllerOptions(virCommandPtr cmd,
static int
qemuBuildObjectCommandline(virCommandPtr cmd,
- virJSONValuePtr objProps)
+ virJSONValuePtr objProps,
+ virQEMUCaps *qemuCaps)
{
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
if (!objProps)
return 0;
- if (virQEMUBuildObjectCommandlineFromJSON(&buf, objProps) < 0)
+ if (qemuBuildObjectCommandlineFromJSON(&buf, objProps, qemuCaps) < 0)
return -1;
virCommandAddArg(cmd, "-object");
@@ -2000,16 +2029,17 @@ qemuBuildObjectCommandline(virCommandPtr cmd,
static int
qemuBuildBlockStorageSourceAttachDataCommandline(virCommandPtr cmd,
- qemuBlockStorageSourceAttachDataPtr data)
+ qemuBlockStorageSourceAttachDataPtr data,
+ virQEMUCaps *qemuCaps)
{
char *tmp;
- if (qemuBuildObjectCommandline(cmd, data->prmgrProps) < 0 ||
- qemuBuildObjectCommandline(cmd, data->authsecretProps) < 0 ||
- qemuBuildObjectCommandline(cmd, data->encryptsecretProps) < 0 ||
- qemuBuildObjectCommandline(cmd, data->httpcookiesecretProps) < 0 ||
- qemuBuildObjectCommandline(cmd, data->tlsKeySecretProps) < 0 ||
- qemuBuildObjectCommandline(cmd, data->tlsProps) < 0)
+ if (qemuBuildObjectCommandline(cmd, data->prmgrProps, qemuCaps) < 0 ||
+ qemuBuildObjectCommandline(cmd, data->authsecretProps, qemuCaps) < 0 ||
+ qemuBuildObjectCommandline(cmd, data->encryptsecretProps, qemuCaps) < 0 ||
+ qemuBuildObjectCommandline(cmd, data->httpcookiesecretProps, qemuCaps) < 0 ||
+ qemuBuildObjectCommandline(cmd, data->tlsKeySecretProps, qemuCaps) < 0 ||
+ qemuBuildObjectCommandline(cmd, data->tlsProps, qemuCaps) < 0)
return -1;
if (data->driveCmd)
@@ -2072,7 +2102,8 @@ qemuBuildDiskSourceCommandLine(virCommandPtr cmd,
for (i = data->nsrcdata; i > 0; i--) {
if (qemuBuildBlockStorageSourceAttachDataCommandline(cmd,
- data->srcdata[i - 1]) < 0)
+ data->srcdata[i - 1],
+ qemuCaps) < 0)
return -1;
}
@@ -3271,7 +3302,7 @@ qemuBuildMemoryCellBackendStr(virDomainDefPtr def,
priv, def, &mem, false)) < 0)
return -1;
- if (virQEMUBuildObjectCommandlineFromJSON(buf, props) < 0)
+ if (qemuBuildObjectCommandlineFromJSON(buf, props, priv->qemuCaps) < 0)
return -1;
return rc;
@@ -3300,7 +3331,7 @@ qemuBuildMemoryDimmBackendStr(virBufferPtr buf,
priv, def, mem, true) < 0)
return -1;
- if (virQEMUBuildObjectCommandlineFromJSON(buf, props) < 0)
+ if (qemuBuildObjectCommandlineFromJSON(buf, props, priv->qemuCaps) < 0)
return -1;
return 0;
@@ -4886,7 +4917,8 @@ qemuBuildChrChardevStr(virLogManagerPtr logManager,
* functions can just check the config fields */
if (chrSourcePriv && chrSourcePriv->secinfo) {
if (qemuBuildObjectSecretCommandLine(cmd,
- chrSourcePriv->secinfo) < 0)
+ chrSourcePriv->secinfo,
+ qemuCaps) < 0)
return NULL;
tlsCertEncSecAlias = chrSourcePriv->secinfo->s.aes.alias;
@@ -5124,7 +5156,7 @@ qemuBuildHostdevSCSICommandLine(virCommandPtr cmd,
if (!(data = qemuBuildHostdevSCSIAttachPrepare(hostdev, &backendAlias, qemuCaps)))
return -1;
- if (qemuBuildBlockStorageSourceAttachDataCommandline(cmd, data) < 0)
+ if (qemuBuildBlockStorageSourceAttachDataCommandline(cmd, data, qemuCaps) < 0)
return -1;
virCommandAddArg(cmd, "-device");
@@ -5530,7 +5562,7 @@ qemuBuildRNGCommandLine(virLogManagerPtr logManager,
if (qemuBuildRNGBackendProps(rng, &props) < 0)
return -1;
- rc = virQEMUBuildObjectCommandlineFromJSON(&buf, props);
+ rc = qemuBuildObjectCommandlineFromJSON(&buf, props, qemuCaps);
if (rc < 0)
return -1;
@@ -7099,7 +7131,7 @@ qemuBuildMemCommandLineMemoryDefaultBackend(virCommandPtr cmd,
priv, def, &mem, false) < 0)
return -1;
- if (virQEMUBuildObjectCommandlineFromJSON(&buf, props) < 0)
+ if (qemuBuildObjectCommandlineFromJSON(&buf, props, priv->qemuCaps) < 0)
return -1;
virCommandAddArg(cmd, "-object");
@@ -7172,25 +7204,31 @@ qemuBuildMemCommandLine(virCommandPtr cmd,
static int
qemuBuildIOThreadCommandLine(virCommandPtr cmd,
- const virDomainDef *def)
+ const virDomainDef *def,
+ virQEMUCaps *qemuCaps)
{
size_t i;
if (def->niothreadids == 0)
return 0;
- /* Create iothread objects using the defined iothreadids list
- * and the defined id and name from the list. These may be used
- * by a disk definition which will associate to an iothread by
- * supplying a value of an id from the list
- */
for (i = 0; i < def->niothreadids; i++) {
+ g_autoptr(virJSONValue) props = NULL;
+ g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
+ g_autofree char *alias = g_strdup_printf("iothread%u", def->iothreadids[i]->iothread_id);
+
+ if (qemuMonitorCreateObjectProps(&props, "iothread", alias, NULL) < 0)
+ return -1;
+
+ if (qemuBuildObjectCommandlineFromJSON(&buf, props, qemuCaps) < 0)
+ return -1;
+
virCommandAddArg(cmd, "-object");
- virCommandAddArgFormat(cmd, "iothread,id=iothread%u",
- def->iothreadids[i]->iothread_id);
+ virCommandAddArgBuffer(cmd, &buf);
}
return 0;
+
}
@@ -7613,7 +7651,8 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg,
if (gfxPriv->secinfo) {
if (qemuBuildObjectSecretCommandLine(cmd,
- gfxPriv->secinfo) < 0)
+ gfxPriv->secinfo,
+ qemuCaps) < 0)
return -1;
secretAlias = gfxPriv->secinfo->s.aes.alias;
}
@@ -8658,7 +8697,7 @@ qemuBuildShmemCommandLine(virLogManagerPtr logManager,
if (!(memProps = qemuBuildShmemBackendMemProps(shmem)))
return -1;
- rc = virQEMUBuildObjectCommandlineFromJSON(&buf, memProps);
+ rc = qemuBuildObjectCommandlineFromJSON(&buf, memProps, qemuCaps);
if (rc < 0)
return -1;
@@ -9523,7 +9562,7 @@ qemuBuildManagedPRCommandLine(virCommandPtr cmd,
if (!(props = qemuBuildPRManagedManagerInfoProps(priv)))
return -1;
- if (virQEMUBuildObjectCommandlineFromJSON(&buf, props) < 0)
+ if (qemuBuildObjectCommandlineFromJSON(&buf, props, priv->qemuCaps) < 0)
return -1;
virCommandAddArg(cmd, "-object");
@@ -9547,7 +9586,8 @@ qemuBuildPflashBlockdevOne(virCommandPtr cmd,
for (i = data->nsrcdata; i > 0; i--) {
if (qemuBuildBlockStorageSourceAttachDataCommandline(cmd,
- data->srcdata[i - 1]) < 0)
+ data->srcdata[i - 1],
+ qemuCaps) < 0)
return -1;
}
@@ -9612,7 +9652,7 @@ qemuBuildDBusVMStateCommandLine(virCommandPtr cmd,
if (!(props = qemuBuildDBusVMStateInfoProps(driver, vm)))
return -1;
- if (virQEMUBuildObjectCommandlineFromJSON(&buf, props) < 0)
+ if (qemuBuildObjectCommandlineFromJSON(&buf, props, priv->qemuCaps) < 0)
return -1;
virCommandAddArg(cmd, "-object");
@@ -9890,7 +9930,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
if (qemuBuildSmpCommandLine(cmd, def, qemuCaps) < 0)
return NULL;
- if (qemuBuildIOThreadCommandLine(cmd, def) < 0)
+ if (qemuBuildIOThreadCommandLine(cmd, def, qemuCaps) < 0)
return NULL;
if (virDomainNumaGetNodeCount(def->numa) &&
diff --git a/src/util/virqemu.c b/src/util/virqemu.c
index aa322be..a1f57de 100644
--- a/src/util/virqemu.c
+++ b/src/util/virqemu.c
@@ -303,30 +303,6 @@ virQEMUBuildNetdevCommandlineFromJSON(virJSONValuePtr props,
}
-int
-virQEMUBuildObjectCommandlineFromJSON(virBufferPtr buf,
- virJSONValuePtr objprops)
-{
- const char *type = virJSONValueObjectGetString(objprops, "qom-type");
- const char *alias = virJSONValueObjectGetString(objprops, "id");
-
- if (!type || !alias) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("missing 'type'(%s) or 'alias'(%s) field of QOM 'object'"),
- NULLSTR(type), NULLSTR(alias));
- return -1;
- }
-
- virBufferAsprintf(buf, "%s,", type);
-
- if (virQEMUBuildCommandLineJSON(objprops, buf, "qom-type", false,
- virQEMUBuildCommandLineJSONArrayBitmap) < 0)
- return -1;
-
- return 0;
-}
-
-
char *
virQEMUBuildDriveCommandlineFromJSON(virJSONValuePtr srcdef)
{
diff --git a/src/util/virqemu.h b/src/util/virqemu.h
index 849b7df..361abdd 100644
--- a/src/util/virqemu.h
+++ b/src/util/virqemu.h
@@ -48,9 +48,6 @@ char *
virQEMUBuildNetdevCommandlineFromJSON(virJSONValuePtr props,
bool rawjson);
-int virQEMUBuildObjectCommandlineFromJSON(virBufferPtr buf,
- virJSONValuePtr objprops);
-
char *virQEMUBuildDriveCommandlineFromJSON(virJSONValuePtr src);
void virQEMUBuildBufferEscapeComma(virBufferPtr buf, const char *str);
--
2.34.1

View File

@ -0,0 +1,34 @@
From f763b6e43900605308df8dbca16e4702033947e9 Mon Sep 17 00:00:00 2001
From: Peter Krempa <pkrempa@redhat.com>
Date: Fri, 12 Mar 2021 16:28:11 +0100
Subject: [PATCH] qemu: capabilities: Enable detection of
QEMU_CAPS_OBJECT_QAPIFIED
Base the detection on the presence of the 'secret' qom-type entry, which
isn't conditionally compiled in qemu.
All caps-based test now switch to using JSON for -object.
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
[ Patch defuzzed for libvirt 7.0.0]
Signed-off-by: Thales Elero Cervi <thaleselero.cervi@windriver.com>
---
src/qemu/qemu_capabilities.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index fba718f..81fece7 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1537,6 +1537,7 @@ static struct virQEMUCapsStringFlags virQEMUCapsQMPSchemaQueries[] = {
{ "migrate-set-parameters/arg-type/xbzrle-cache-size", QEMU_CAPS_MIGRATION_PARAM_XBZRLE_CACHE_SIZE },
{ "set-numa-node/arg-type/+hmat-lb", QEMU_CAPS_NUMA_HMAT },
{ "netdev_add/arg-type/+vhost-vdpa", QEMU_CAPS_NETDEV_VHOST_VDPA },
+ { "object-add/arg-type/qom-type/^secret", QEMU_CAPS_OBJECT_QAPIFIED },
};
typedef struct _virQEMUCapsObjectTypeProps virQEMUCapsObjectTypeProps;
--
2.34.1

View File

@ -25,3 +25,6 @@ CVE-2024-2494.patch
0011-qemu-monitor-Make-wrapping-of-props-of-object-add-op.patch
0012-qemuMonitorCreateObjectPropsWrap-Open-code-in-qemuBu.patch
0013-qemu-monitor-Don-t-add-props-wrapper-if-qemu-has-QEM.patch
0014-qemu-remove-support-for-generating-yes-no-boolean-op.patch
0015-qemu-command-Use-JSON-for-QAPIfied-object-directly.patch
0016-qemu-capabilities-Enable-detection-of-QEMU_CAPS_OBJE.patch