From: David Judkovics <djudkovi@xxxxxxxxxxxxx> This function is utilized by the new virsh hypervisor-cpu-models command. The CPU models are read directly from the QEMU capabilities file, which contains a list of all models queried from the hypervisor. Signed-off-by: David Judkovics <djudkovi@xxxxxxxxxxxxx> Signed-off-by: Collin Walling <walling@xxxxxxxxxxxxx> Reviewed-by: Boris Fiuczynski <fiuczy@xxxxxxxxxxxxx> Signed-off-by: Boris Fiuczynski <fiuczy@xxxxxxxxxxxxx> --- src/qemu/qemu_driver.c | 59 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d2eddbd9ae..1a795cebd0 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11948,6 +11948,64 @@ qemuConnectBaselineHypervisorCPU(virConnectPtr conn, } +static int +qemuConnectGetHypervisorCPUModelNames(virConnectPtr conn, + const char *emulator, + const char *archStr, + const char *machine, + const char *virttypeStr, + char ***models, + unsigned int flags) +{ + virQEMUDriver *driver = conn->privateData; + g_autoptr(virQEMUCaps) qemuCaps = NULL; + virArch arch; + virDomainVirtType virttype; + g_autoptr(virDomainCaps) domCaps = NULL; + size_t i = 0; + + virDomainCapsCPUModel *customModels = NULL; + int customNumModels; + + virCheckFlags(0, -1); + + if (virConnectGetHypervisorCPUModelNamesEnsureACL(conn) < 0) + return -1; + + qemuCaps = virQEMUCapsCacheLookupDefault(driver->qemuCapsCache, + emulator, + archStr, + virttypeStr, + machine, + &arch, + &virttype, + &machine); + if (!qemuCaps) + return -1; + + if (!(domCaps = virQEMUDriverGetDomainCapabilities(driver, + qemuCaps, + machine, + arch, + virttype))) + return -1; + + customModels = domCaps->cpu.custom->models; + customNumModels = domCaps->cpu.custom->nmodels; + + if (models) { + *models = g_new0(char *, customNumModels); + for (i = 0; i < customNumModels; i++) { + (*models)[i] = g_strdup(customModels[i].name); + VIR_DEBUG("adding models[%zu] = name[%s]", + i, customModels[i].name); + } + } + + return customNumModels; +} + + static int qemuDomainGetJobInfoMigrationStats(virDomainObj *vm, virDomainJobData *jobData) @@ -20289,6 +20347,7 @@ static virHypervisorDriver qemuHypervisorDriver = { .domainSetLifecycleAction = qemuDomainSetLifecycleAction, /* 3.9.0 */ .connectCompareHypervisorCPU = qemuConnectCompareHypervisorCPU, /* 4.4.0 */ .connectBaselineHypervisorCPU = qemuConnectBaselineHypervisorCPU, /* 4.4.0 */ + .connectGetHypervisorCPUModelNames = qemuConnectGetHypervisorCPUModelNames, /* 11.1.0 */ .nodeGetSEVInfo = qemuNodeGetSEVInfo, /* 4.5.0 */ .domainGetLaunchSecurityInfo = qemuDomainGetLaunchSecurityInfo, /* 4.5.0 */ .domainCheckpointCreateXML = qemuDomainCheckpointCreateXML, /* 5.6.0 */ -- 2.47.0