[PATCH 0/7] qemu: Don't use hardcoded QOM path for vcpu

Peter Krempa (7): qemuMonitorJSONGetCPUx86Data: Unexport qemuProcessUpdateAndVerifyCPU: Refactor cleanup qemu: monitor: Don't hardcode QOM path of first CPU qemu: domain: Store 'qomPath' in qemuDomainVcpuPrivate qemu: process: Move cpu flag querying after code probing cpus qemu: process: Move call to qemuProcessRefreshCPU after cpu probe qemu: process: Don't use hardcoded QOM path for cpu for probing flags src/qemu/qemu_domain.c | 3 ++ src/qemu/qemu_domain.h | 2 ++ src/qemu/qemu_monitor.c | 17 +++++++---- src/qemu/qemu_monitor.h | 3 ++ src/qemu/qemu_monitor_json.c | 40 +++++++++++++++----------- src/qemu/qemu_monitor_json.h | 8 ++---- src/qemu/qemu_process.c | 55 ++++++++++++++++++++++-------------- tests/qemumonitorjsontest.c | 2 ++ 8 files changed, 82 insertions(+), 48 deletions(-) -- 2.34.1

The function is used only as a helper in src/qemu/qemu_monitor_json.c Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_monitor_json.c | 2 +- src/qemu/qemu_monitor_json.h | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index b0b513683b..d81456bcad 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -7024,7 +7024,7 @@ qemuMonitorJSONParseCPUx86Features(virJSONValue *data) } -int +static int qemuMonitorJSONGetCPUx86Data(qemuMonitor *mon, const char *property, virCPUData **cpudata) diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index 64d9ebdaa3..be66c545c9 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -646,11 +646,6 @@ int qemuMonitorJSONGetDeviceAliases(qemuMonitor *mon, char ***aliases); -int -qemuMonitorJSONGetCPUx86Data(qemuMonitor *mon, - const char *property, - virCPUData **cpudata); - int qemuMonitorJSONGetGuestCPUx86(qemuMonitor *mon, virCPUData **data, -- 2.34.1

Use automatic memory clearing and remove the 'ret' variable. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_process.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index ea586e54c1..d080ab1c49 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4335,25 +4335,19 @@ qemuProcessUpdateAndVerifyCPU(virQEMUDriver *driver, virDomainObj *vm, qemuDomainAsyncJob asyncJob) { - virCPUData *cpu = NULL; - virCPUData *disabled = NULL; - int ret = -1; + g_autoptr(virCPUData) cpu = NULL; + g_autoptr(virCPUData) disabled = NULL; if (qemuProcessFetchGuestCPU(driver, vm, asyncJob, &cpu, &disabled) < 0) - goto cleanup; + return -1; if (qemuProcessVerifyCPU(vm, cpu) < 0) - goto cleanup; + return -1; if (qemuProcessUpdateLiveGuestCPU(vm, cpu, disabled) < 0) - goto cleanup; - - ret = 0; + return -1; - cleanup: - virCPUDataFree(cpu); - virCPUDataFree(disabled); - return ret; + return 0; } -- 2.34.1

Convert all code using the 'QOM_CPU_PATH' macro to accept the QOM path as an argument. For now the new helper for fetching the path 'qemuProcessGetVCPUQOMPath' will always return the same hard-coded value. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_monitor.c | 17 ++++++++++------ src/qemu/qemu_monitor.h | 3 +++ src/qemu/qemu_monitor_json.c | 38 ++++++++++++++++++++++-------------- src/qemu/qemu_monitor_json.h | 3 +++ src/qemu/qemu_process.c | 15 ++++++++++++-- tests/qemumonitorjsontest.c | 2 ++ 6 files changed, 55 insertions(+), 23 deletions(-) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index babf9e62fb..a79ccabdca 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -3887,6 +3887,7 @@ qemuMonitorSetDomainLog(qemuMonitor *mon, /** * qemuMonitorJSONGetGuestCPUx86: * @mon: Pointer to the monitor + * @cpuQOMPath: QOM path of a CPU to probe * @data: returns the cpu data * @disabled: returns the CPU data for features which were disabled by QEMU * @@ -3897,10 +3898,11 @@ qemuMonitorSetDomainLog(qemuMonitor *mon, */ int qemuMonitorGetGuestCPUx86(qemuMonitor *mon, + const char *cpuQOMPath, virCPUData **data, virCPUData **disabled) { - VIR_DEBUG("data=%p disabled=%p", data, disabled); + VIR_DEBUG("cpuQOMPath=%s data=%p disabled=%p", cpuQOMPath, data, disabled); QEMU_CHECK_MONITOR(mon); @@ -3908,7 +3910,7 @@ qemuMonitorGetGuestCPUx86(qemuMonitor *mon, if (disabled) *disabled = NULL; - return qemuMonitorJSONGetGuestCPUx86(mon, data, disabled); + return qemuMonitorJSONGetGuestCPUx86(mon, cpuQOMPath, data, disabled); } @@ -3916,6 +3918,7 @@ qemuMonitorGetGuestCPUx86(qemuMonitor *mon, * qemuMonitorGetGuestCPU: * @mon: Pointer to the monitor * @arch: CPU architecture + * @cpuQOMPath: QOM path of a CPU to probe * @translate: callback for translating CPU feature names from QEMU to libvirt * @opaque: data for @translate callback * @enabled: returns the CPU data for all enabled features @@ -3929,13 +3932,14 @@ qemuMonitorGetGuestCPUx86(qemuMonitor *mon, int qemuMonitorGetGuestCPU(qemuMonitor *mon, virArch arch, + const char *cpuQOMPath, qemuMonitorCPUFeatureTranslationCallback translate, void *opaque, virCPUData **enabled, virCPUData **disabled) { - VIR_DEBUG("arch=%s translate=%p opaque=%p enabled=%p disabled=%p", - virArchToString(arch), translate, opaque, enabled, disabled); + VIR_DEBUG("arch=%s cpuQOMPath=%s translate=%p opaque=%p enabled=%p disabled=%p", + virArchToString(arch), cpuQOMPath, translate, opaque, enabled, disabled); QEMU_CHECK_MONITOR(mon); @@ -3943,7 +3947,7 @@ qemuMonitorGetGuestCPU(qemuMonitor *mon, if (disabled) *disabled = NULL; - return qemuMonitorJSONGetGuestCPU(mon, arch, translate, opaque, + return qemuMonitorJSONGetGuestCPU(mon, arch, cpuQOMPath, translate, opaque, enabled, disabled); } @@ -4416,11 +4420,12 @@ qemuMonitorGetJobInfo(qemuMonitor *mon, */ int qemuMonitorGetCPUMigratable(qemuMonitor *mon, + const char *cpuQOMPath, bool *migratable) { QEMU_CHECK_MONITOR(mon); - return qemuMonitorJSONGetCPUMigratable(mon, migratable); + return qemuMonitorJSONGetCPUMigratable(mon, cpuQOMPath, migratable); } diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 9b2e4e1421..11ecda97de 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1348,6 +1348,7 @@ void qemuMonitorSetDomainLog(qemuMonitor *mon, virFreeCallback destroy); int qemuMonitorGetGuestCPUx86(qemuMonitor *mon, + const char *cpuQOMPath, virCPUData **data, virCPUData **disabled); @@ -1356,6 +1357,7 @@ typedef const char *(*qemuMonitorCPUFeatureTranslationCallback)(const char *name int qemuMonitorGetGuestCPU(qemuMonitor *mon, virArch arch, + const char *cpuQOMPath, qemuMonitorCPUFeatureTranslationCallback translate, void *opaque, virCPUData **enabled, @@ -1489,6 +1491,7 @@ int qemuMonitorGetJobInfo(qemuMonitor *mon, int qemuMonitorGetCPUMigratable(qemuMonitor *mon, + const char *cpuQOMPath, bool *migratable); int diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index d81456bcad..8e1501d91f 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -48,8 +48,6 @@ VIR_LOG_INIT("qemu.qemu_monitor_json"); -#define QOM_CPU_PATH "/machine/unattached/device[0]" - #define LINE_ENDING "\r\n" VIR_ENUM_IMPL(qemuMonitorJob, @@ -7026,6 +7024,7 @@ qemuMonitorJSONParseCPUx86Features(virJSONValue *data) static int qemuMonitorJSONGetCPUx86Data(qemuMonitor *mon, + const char *cpuQOMPath, const char *property, virCPUData **cpudata) { @@ -7034,7 +7033,7 @@ qemuMonitorJSONGetCPUx86Data(qemuMonitor *mon, virJSONValue *data; if (!(cmd = qemuMonitorJSONMakeCommand("qom-get", - "s:path", QOM_CPU_PATH, + "s:path", cpuQOMPath, "s:property", property, NULL))) return -1; @@ -7058,7 +7057,8 @@ qemuMonitorJSONGetCPUx86Data(qemuMonitor *mon, * of a guest CPU, and 1 if the feature is supported. */ static int -qemuMonitorJSONCheckCPUx86(qemuMonitor *mon) +qemuMonitorJSONCheckCPUx86(qemuMonitor *mon, + const char *cpuQOMPath) { g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; @@ -7067,7 +7067,7 @@ qemuMonitorJSONCheckCPUx86(qemuMonitor *mon) size_t n; if (!(cmd = qemuMonitorJSONMakeCommand("qom-list", - "s:path", QOM_CPU_PATH, + "s:path", cpuQOMPath, NULL))) return -1; @@ -7102,6 +7102,7 @@ qemuMonitorJSONCheckCPUx86(qemuMonitor *mon) /** * qemuMonitorJSONGetGuestCPUx86: * @mon: Pointer to the monitor + * @cpuQOMPath: QOM path of a CPU to probe * @data: returns the cpu data of the guest * @disabled: returns the CPU data for features which were disabled by QEMU * @@ -7112,6 +7113,7 @@ qemuMonitorJSONCheckCPUx86(qemuMonitor *mon) */ int qemuMonitorJSONGetGuestCPUx86(qemuMonitor *mon, + const char *cpuQOMPath, virCPUData **data, virCPUData **disabled) { @@ -7119,17 +7121,17 @@ qemuMonitorJSONGetGuestCPUx86(qemuMonitor *mon, g_autoptr(virCPUData) cpuDisabled = NULL; int rc; - if ((rc = qemuMonitorJSONCheckCPUx86(mon)) < 0) + if ((rc = qemuMonitorJSONCheckCPUx86(mon, cpuQOMPath)) < 0) return -1; else if (!rc) return -2; - if (qemuMonitorJSONGetCPUx86Data(mon, "feature-words", + if (qemuMonitorJSONGetCPUx86Data(mon, cpuQOMPath, "feature-words", &cpuEnabled) < 0) return -1; if (disabled && - qemuMonitorJSONGetCPUx86Data(mon, "filtered-features", + qemuMonitorJSONGetCPUx86Data(mon, cpuQOMPath, "filtered-features", &cpuDisabled) < 0) return -1; @@ -7142,6 +7144,7 @@ qemuMonitorJSONGetGuestCPUx86(qemuMonitor *mon, static int qemuMonitorJSONGetCPUProperties(qemuMonitor *mon, + const char *cpuQOMPath, char ***props) { g_autoptr(virJSONValue) cmd = NULL; @@ -7150,7 +7153,7 @@ qemuMonitorJSONGetCPUProperties(qemuMonitor *mon, *props = NULL; if (!(cmd = qemuMonitorJSONMakeCommand("qom-list", - "s:path", QOM_CPU_PATH, + "s:path", cpuQOMPath, NULL))) return -1; @@ -7166,6 +7169,7 @@ qemuMonitorJSONGetCPUProperties(qemuMonitor *mon, static int qemuMonitorJSONGetCPUData(qemuMonitor *mon, + const char *cpuQOMPath, qemuMonitorCPUFeatureTranslationCallback translate, void *opaque, virCPUData *data) @@ -7174,13 +7178,13 @@ qemuMonitorJSONGetCPUData(qemuMonitor *mon, g_auto(GStrv) props = NULL; char **p; - if (qemuMonitorJSONGetCPUProperties(mon, &props) < 0) + if (qemuMonitorJSONGetCPUProperties(mon, cpuQOMPath, &props) < 0) return -1; for (p = props; p && *p; p++) { const char *name = *p; - if (qemuMonitorJSONGetObjectProperty(mon, QOM_CPU_PATH, name, &prop) < 0) + if (qemuMonitorJSONGetObjectProperty(mon, cpuQOMPath, name, &prop) < 0) return -1; if (!prop.val.b) @@ -7199,6 +7203,7 @@ qemuMonitorJSONGetCPUData(qemuMonitor *mon, static int qemuMonitorJSONGetCPUDataDisabled(qemuMonitor *mon, + const char *cpuQOMPath, qemuMonitorCPUFeatureTranslationCallback translate, void *opaque, virCPUData *data) @@ -7206,7 +7211,7 @@ qemuMonitorJSONGetCPUDataDisabled(qemuMonitor *mon, g_auto(GStrv) props = NULL; char **p; - if (qemuMonitorJSONGetStringListProperty(mon, QOM_CPU_PATH, + if (qemuMonitorJSONGetStringListProperty(mon, cpuQOMPath, "unavailable-features", &props) < 0) return -1; @@ -7228,6 +7233,7 @@ qemuMonitorJSONGetCPUDataDisabled(qemuMonitor *mon, * qemuMonitorJSONGetGuestCPU: * @mon: Pointer to the monitor * @arch: CPU architecture + * @cpuQOMPath: QOM path of a CPU to probe * @translate: callback for translating CPU feature names from QEMU to libvirt * @opaque: data for @translate callback * @enabled: returns the CPU data for all enabled features @@ -7241,6 +7247,7 @@ qemuMonitorJSONGetCPUDataDisabled(qemuMonitor *mon, int qemuMonitorJSONGetGuestCPU(qemuMonitor *mon, virArch arch, + const char *cpuQOMPath, qemuMonitorCPUFeatureTranslationCallback translate, void *opaque, virCPUData **enabled, @@ -7253,11 +7260,11 @@ qemuMonitorJSONGetGuestCPU(qemuMonitor *mon, !(cpuDisabled = virCPUDataNew(arch))) return -1; - if (qemuMonitorJSONGetCPUData(mon, translate, opaque, cpuEnabled) < 0) + if (qemuMonitorJSONGetCPUData(mon, cpuQOMPath, translate, opaque, cpuEnabled) < 0) return -1; if (disabled && - qemuMonitorJSONGetCPUDataDisabled(mon, translate, opaque, cpuDisabled) < 0) + qemuMonitorJSONGetCPUDataDisabled(mon, cpuQOMPath, translate, opaque, cpuDisabled) < 0) return -1; *enabled = g_steal_pointer(&cpuEnabled); @@ -8671,13 +8678,14 @@ qemuMonitorJSONGetJobInfo(qemuMonitor *mon, int qemuMonitorJSONGetCPUMigratable(qemuMonitor *mon, + const char *cpuQOMPath, bool *migratable) { g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; if (!(cmd = qemuMonitorJSONMakeCommand("qom-get", - "s:path", QOM_CPU_PATH, + "s:path", cpuQOMPath, "s:property", "migratable", NULL))) return -1; diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index be66c545c9..309d1fb409 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -648,12 +648,14 @@ qemuMonitorJSONGetDeviceAliases(qemuMonitor *mon, int qemuMonitorJSONGetGuestCPUx86(qemuMonitor *mon, + const char *cpuQOMPath, virCPUData **data, virCPUData **disabled); int qemuMonitorJSONGetGuestCPU(qemuMonitor *mon, virArch arch, + const char *cpuQOMPath, qemuMonitorCPUFeatureTranslationCallback translate, void *opaque, virCPUData **enabled, @@ -846,6 +848,7 @@ qemuMonitorJSONSetDBusVMStateIdList(qemuMonitor *mon, int qemuMonitorJSONGetCPUMigratable(qemuMonitor *mon, + const char *cpuQOMPath, bool *migratable); int diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index d080ab1c49..10e76583cf 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4224,6 +4224,14 @@ qemuProcessTranslateCPUFeatures(const char *name, } +/* returns the QOM path to the first vcpu */ +static const char * +qemuProcessGetVCPUQOMPath(void) +{ + return "/machine/unattached/device[0]"; +} + + static int qemuProcessFetchGuestCPU(virQEMUDriver *driver, virDomainObj *vm, @@ -4234,6 +4242,7 @@ qemuProcessFetchGuestCPU(virQEMUDriver *driver, qemuDomainObjPrivate *priv = vm->privateData; g_autoptr(virCPUData) dataEnabled = NULL; g_autoptr(virCPUData) dataDisabled = NULL; + const char *cpuQOMPath = qemuProcessGetVCPUQOMPath(); bool generic; int rc; @@ -4251,10 +4260,11 @@ qemuProcessFetchGuestCPU(virQEMUDriver *driver, if (generic) { rc = qemuMonitorGetGuestCPU(priv->mon, vm->def->os.arch, + cpuQOMPath, qemuProcessTranslateCPUFeatures, priv->qemuCaps, &dataEnabled, &dataDisabled); } else { - rc = qemuMonitorGetGuestCPUx86(priv->mon, &dataEnabled, &dataDisabled); + rc = qemuMonitorGetGuestCPUx86(priv->mon, cpuQOMPath, &dataEnabled, &dataDisabled); } qemuDomainObjExitMonitor(driver, vm); @@ -8455,6 +8465,7 @@ qemuProcessRefreshCPUMigratability(virQEMUDriver *driver, { qemuDomainObjPrivate *priv = vm->privateData; virDomainDef *def = vm->def; + const char *cpuQOMPath = qemuProcessGetVCPUQOMPath(); bool migratable; int rc; @@ -8473,7 +8484,7 @@ qemuProcessRefreshCPUMigratability(virQEMUDriver *driver, if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0) return -1; - rc = qemuMonitorGetCPUMigratable(priv->mon, &migratable); + rc = qemuMonitorGetCPUMigratable(priv->mon, cpuQOMPath, &migratable); qemuDomainObjExitMonitor(driver, vm); if (rc < 0) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 48e2a457ab..7987182a82 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -2186,6 +2186,7 @@ testQemuMonitorJSONGetCPUData(const void *opaque) return -1; if (qemuMonitorJSONGetGuestCPUx86(qemuMonitorTestGetMonitor(test), + "dummy", &cpuData, NULL) < 0) return -1; @@ -2221,6 +2222,7 @@ testQemuMonitorJSONGetNonExistingCPUData(const void *opaque) return -1; rv = qemuMonitorJSONGetGuestCPUx86(qemuMonitorTestGetMonitor(test), + "dummy", &cpuData, NULL); if (rv != -2) { virReportError(VIR_ERR_INTERNAL_ERROR, -- 2.34.1

The QOM path will be needed by code which is querying the cpu flags via 'qom-get' and thus needs a valid QOM path to the vCPU. Add it into the private data and transfer from the queried data. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_domain.c | 3 +++ src/qemu/qemu_domain.h | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 14b585c6e9..015f635dc8 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -821,6 +821,7 @@ qemuDomainVcpuPrivateDispose(void *obj) g_free(priv->type); g_free(priv->alias); virJSONValueFree(priv->props); + g_free(priv->qomPath); return; } @@ -9550,6 +9551,8 @@ qemuDomainRefreshVcpuInfo(virQEMUDriver *driver, vcpupriv->props = g_steal_pointer(&info[i].props); vcpupriv->enable_id = info[i].id; vcpupriv->qemu_id = info[i].qemu_id; + g_free(vcpupriv->qomPath); + vcpupriv->qomPath = g_steal_pointer(&info[i].qom_path); if (hotplug && state) { vcpu->online = info[i].online; diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 78474b3f73..8bf1c91049 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -316,6 +316,8 @@ struct _qemuDomainVcpuPrivate { int thread_id; int node_id; int vcpus; + + char *qomPath; }; #define QEMU_DOMAIN_VCPU_PRIVATE(vcpu) \ -- 2.34.1

On a Monday in 2022, Peter Krempa wrote:
The QOM path will be needed by code which is querying the cpu flags via 'qom-get' and thus needs a valid QOM path to the vCPU.
Add it into the private data and transfer from the queried data.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_domain.c | 3 +++ src/qemu/qemu_domain.h | 2 ++ 2 files changed, 5 insertions(+)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 14b585c6e9..015f635dc8 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -821,6 +821,7 @@ qemuDomainVcpuPrivateDispose(void *obj) g_free(priv->type); g_free(priv->alias); virJSONValueFree(priv->props); + g_free(priv->qomPath); return; }
@@ -9550,6 +9551,8 @@ qemuDomainRefreshVcpuInfo(virQEMUDriver *driver, vcpupriv->props = g_steal_pointer(&info[i].props); vcpupriv->enable_id = info[i].id; vcpupriv->qemu_id = info[i].qemu_id; + g_free(vcpupriv->qomPath); + vcpupriv->qomPath = g_steal_pointer(&info[i].qom_path);
Since this now copies qom_path, a followup patch to this comment in struct _qemuMonitorCPUInfo might be needed: /* internal for use in the matching code */ char *qom_path; Jano

On Mon, Feb 07, 2022 at 17:35:29 +0100, Ján Tomko wrote:
On a Monday in 2022, Peter Krempa wrote:
The QOM path will be needed by code which is querying the cpu flags via 'qom-get' and thus needs a valid QOM path to the vCPU.
Add it into the private data and transfer from the queried data.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> ---
[...]
@@ -9550,6 +9551,8 @@ qemuDomainRefreshVcpuInfo(virQEMUDriver *driver, vcpupriv->props = g_steal_pointer(&info[i].props); vcpupriv->enable_id = info[i].id; vcpupriv->qemu_id = info[i].qemu_id; + g_free(vcpupriv->qomPath); + vcpupriv->qomPath = g_steal_pointer(&info[i].qom_path);
Since this now copies qom_path, a followup patch to this comment in struct _qemuMonitorCPUInfo might be needed:
/* internal for use in the matching code */ char *qom_path;
I've deleted the comment as part of this patch as the name of the variable is self-explaining and pushed the series. Thanks for the review!

Upcoming changes will require that we have a proper QOM path for cpus when querying the flags as qemu is going to change it. By moving the flag probing code later we'll already probe the QOM paths so no re-query will be needed. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_process.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 10e76583cf..f99b14b846 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7573,10 +7573,6 @@ qemuProcessLaunch(virConnectPtr conn, if (qemuConnectAgent(driver, vm) < 0) goto cleanup; - VIR_DEBUG("Verifying and updating provided guest CPU"); - if (qemuProcessUpdateAndVerifyCPU(driver, vm, asyncJob) < 0) - goto cleanup; - VIR_DEBUG("setting up hotpluggable cpus"); if (qemuDomainHasHotpluggableStartupVcpus(vm->def)) { if (qemuDomainRefreshVcpuInfo(driver, vm, asyncJob, false) < 0) @@ -7598,6 +7594,10 @@ qemuProcessLaunch(virConnectPtr conn, qemuDomainVcpuPersistOrder(vm->def); + VIR_DEBUG("Verifying and updating provided guest CPU"); + if (qemuProcessUpdateAndVerifyCPU(driver, vm, asyncJob) < 0) + goto cleanup; + VIR_DEBUG("Detecting IOThread PIDs"); if (qemuProcessDetectIOThreadPIDs(driver, vm, asyncJob) < 0) goto cleanup; -- 2.34.1

Similarly to previous commit we need to probe the vcpus first. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_process.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index f99b14b846..bd9c6ed747 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8850,14 +8850,14 @@ qemuProcessReconnect(void *opaque) ignore_value(qemuSecurityCheckAllLabel(driver->securityManager, obj->def)); - if (qemuProcessRefreshCPU(driver, obj) < 0) - goto error; - if (qemuDomainRefreshVcpuInfo(driver, obj, QEMU_ASYNC_JOB_NONE, true) < 0) goto error; qemuDomainVcpuPersistOrder(obj->def); + if (qemuProcessRefreshCPU(driver, obj) < 0) + goto error; + if (qemuDomainUpdateMemoryDeviceInfo(driver, obj, QEMU_ASYNC_JOB_NONE) < 0) goto error; -- 2.34.1

Modify 'qemuProcessGetVCPUQOMPath' to take the detected QOM path of the first vCPU which is always present as the QOM path used our code probing CPU flags via 'qom-get'. This is needed as upcoming qemu will change it. Resolves: https://gitlab.com/libvirt/libvirt/-/issues/272 Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2051451 Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_process.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index bd9c6ed747..eeda2a92ef 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4226,8 +4226,16 @@ qemuProcessTranslateCPUFeatures(const char *name, /* returns the QOM path to the first vcpu */ static const char * -qemuProcessGetVCPUQOMPath(void) +qemuProcessGetVCPUQOMPath(virDomainObj *vm) { + virDomainVcpuDef *vcpu = virDomainDefGetVcpu(vm->def, 0); + qemuDomainVcpuPrivate *vcpupriv; + + if (vcpu && + (vcpupriv = QEMU_DOMAIN_VCPU_PRIVATE(vcpu)) && + vcpupriv->qomPath) + return vcpupriv->qomPath; + return "/machine/unattached/device[0]"; } @@ -4242,7 +4250,7 @@ qemuProcessFetchGuestCPU(virQEMUDriver *driver, qemuDomainObjPrivate *priv = vm->privateData; g_autoptr(virCPUData) dataEnabled = NULL; g_autoptr(virCPUData) dataDisabled = NULL; - const char *cpuQOMPath = qemuProcessGetVCPUQOMPath(); + const char *cpuQOMPath = qemuProcessGetVCPUQOMPath(vm); bool generic; int rc; @@ -8465,7 +8473,7 @@ qemuProcessRefreshCPUMigratability(virQEMUDriver *driver, { qemuDomainObjPrivate *priv = vm->privateData; virDomainDef *def = vm->def; - const char *cpuQOMPath = qemuProcessGetVCPUQOMPath(); + const char *cpuQOMPath = qemuProcessGetVCPUQOMPath(vm); bool migratable; int rc; -- 2.34.1

On a Monday in 2022, Peter Krempa wrote:
Peter Krempa (7): qemuMonitorJSONGetCPUx86Data: Unexport qemuProcessUpdateAndVerifyCPU: Refactor cleanup qemu: monitor: Don't hardcode QOM path of first CPU qemu: domain: Store 'qomPath' in qemuDomainVcpuPrivate qemu: process: Move cpu flag querying after code probing cpus qemu: process: Move call to qemuProcessRefreshCPU after cpu probe qemu: process: Don't use hardcoded QOM path for cpu for probing flags
src/qemu/qemu_domain.c | 3 ++ src/qemu/qemu_domain.h | 2 ++ src/qemu/qemu_monitor.c | 17 +++++++---- src/qemu/qemu_monitor.h | 3 ++ src/qemu/qemu_monitor_json.c | 40 +++++++++++++++----------- src/qemu/qemu_monitor_json.h | 8 ++---- src/qemu/qemu_process.c | 55 ++++++++++++++++++++++-------------- tests/qemumonitorjsontest.c | 2 ++ 8 files changed, 82 insertions(+), 48 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (2)
-
Ján Tomko
-
Peter Krempa