[libvirt] [PATCH 00/30] conf: eliminate use of virCapsPtr for parsing/formatting XML

The virCapsPtr object is a serious source of performance problems for the QEMU driver, because populating it means probing every QEMU system emulator binary installed on the host. This is is crazy because parsing any single XML document only ever needs information about a single QEMU binary. We've already done a great job of untangling stuff with the post-parse and validation functions, but the job was never quite finished. This series tackles the last pieces so that parsing & formatting XML will never use the virCapsPtr object directly. Some of the virt drivers will still use virCapsPtr in their private callbacks, but the QEMU driver will instead use the QEMU emulator capabilities cache directly. The first ten patches are the key bits of work to remove use of the virCapsPtr parameter from domain XML APIs. The next thirteen patches remove the (now unused) virCapsPtr parameter from the domain XML APIs & their callers. The final six patches help various QEMU driver APIs stop relying on the virCapsPtr, so that it is no longer even created at startup. This has a nice benefit on libvirtd startup tie when all 30 QEMU emulators are installed, reducing it from 4 seconds down to a fraction of a second. More work is still needed to follow on from this... A couple of places in the QEMU driver still use virCapsPtr - The virConnectGetVersion API. - The virNodeGetSecurityModel API. - virDomainGetResctrlMonData API. In all cases we just need to move to store the relevant data directly in virQEMUDriverPtr, and not use the virCaps. next, apps can use virDomainGetCapabilities to fetch info about a specific QEMU binary they care about to avoid the cost of the virConnectGetCapabilities API. There are still times when apps need info in virConnectGetCapabilities and this will annoyingly probe all QEMU binaries, even though the app doesn't want the guest info. virConnectGetCapabilities is one of our very early APIs which now flags parameter, so this problem is unfixable in that API. I'm thus included to introduce a new virNodeGetCapabilities that is specifically only returning information about the host hypervisor. Essentially the <capabilities> schema, but only the <host> sub-tree. I do, however, wonder if even this is overkill & we should aim for a much more fine grained way for reporting host capabilities. eg if an app wants the host CPU, do they really want to pay the penality to probe host cache nformation, or NUMA topology and vica-verca. I'm not sure what the right kind of tradeoff here is, whether we should try individual APIs, or have one API and a set of flags to control what info is filled in. Daniel P. Berrangé (30): qemu: cache host arch separately from virCapsPtr qemu: add machines & arch to fake test capabilities cache conf: sanitize virDomainSaveStatus & virDomainSaveConfig APIs conf: sanitize virDomainObjFormat & virDomainDefFormat* APIs conf: pass in default architecture via domain XML options conf: move virt type / os type / arch validation to post-parse conf: don't use passed in caps in post parse method conf: pass netprefix in the domain parser config struct conf: move seclabel validation into post-parse phase conf: pass default sec model in parser config conf: drop virCapsPtr param from assign addresses callback conf: drop virCapsPtr param from basic post parse callback conf: drop virCapsPtr param from post parse data alloc callback conf: drop virCapsPtr param from post parse callback conf: drop virCapsPtr param from device post parse callback conf: drop virCapsPtr param from domain validate callback conf: drop virCapsPtr param from domain formatting APIs conf: drop virCapsPtr param from domain post parse & validate APIs conf: drop virCapsPtr param from domain parse APIs conf: drop virCapsPtr param from domain APIs for copying config conf: drop virCapsPtr param from APIs for saving domains conf: drop virCapsPtr param from domain obj list APIs conf: drop virCapsPtr param from snapshot & checkpoint APIs qemu: drop virCapsPtr param & vars from many APIs conf: move NUMA capabilities into self contained object qemu: use NUMA capabilities object directly conf: make virCPUDef into a ref counted struct qemu: use host CPU object directly qemu: directly create virResctrlInfo ignoring capabilities qemu: stop creating capabilities at driver startup docs/formatdomain.html.in | 6 +- src/bhyve/bhyve_domain.c | 16 +- src/bhyve/bhyve_driver.c | 46 +- src/bhyve/bhyve_process.c | 22 +- src/conf/capabilities.c | 217 +++++--- src/conf/capabilities.h | 34 +- src/conf/checkpoint_conf.c | 21 +- src/conf/checkpoint_conf.h | 2 - src/conf/cpu_conf.c | 29 +- src/conf/cpu_conf.h | 4 + src/conf/domain_conf.c | 404 ++++++-------- src/conf/domain_conf.h | 84 ++- src/conf/snapshot_conf.c | 28 +- src/conf/snapshot_conf.h | 3 - src/conf/virconftypes.h | 3 + src/conf/virdomainobjlist.c | 9 +- src/conf/virdomainobjlist.h | 1 - src/cpu/cpu.c | 3 +- src/cpu/cpu_arm.c | 5 +- src/cpu/cpu_ppc64.c | 3 +- src/cpu/cpu_x86.c | 6 +- src/esx/esx_driver.c | 14 +- src/hyperv/hyperv_driver.c | 1 + src/libvirt_private.syms | 18 +- src/libxl/libxl_capabilities.c | 23 +- src/libxl/libxl_conf.c | 3 +- src/libxl/libxl_conf.h | 2 +- src/libxl/libxl_domain.c | 37 +- src/libxl/libxl_driver.c | 83 ++- src/libxl/libxl_migration.c | 20 +- src/libxl/xen_xl.c | 13 +- src/libxl/xen_xm.c | 2 +- src/lxc/lxc_conf.c | 9 +- src/lxc/lxc_conf.h | 2 +- src/lxc/lxc_controller.c | 44 +- src/lxc/lxc_domain.c | 13 +- src/lxc/lxc_driver.c | 98 ++-- src/lxc/lxc_native.c | 4 +- src/lxc/lxc_process.c | 20 +- src/openvz/openvz_conf.c | 62 ++- src/openvz/openvz_conf.h | 1 + src/openvz/openvz_driver.c | 64 +-- src/phyp/phyp_driver.c | 26 +- src/qemu/qemu_capabilities.c | 176 ++++--- src/qemu/qemu_capabilities.h | 12 +- src/qemu/qemu_capspriv.h | 10 + src/qemu/qemu_checkpoint.c | 32 +- src/qemu/qemu_checkpoint.h | 1 - src/qemu/qemu_command.c | 6 +- src/qemu/qemu_conf.c | 57 +- src/qemu/qemu_conf.h | 18 +- src/qemu/qemu_domain.c | 108 ++-- src/qemu/qemu_domain.h | 1 - src/qemu/qemu_driver.c | 293 ++++------- src/qemu/qemu_hotplug.c | 8 +- src/qemu/qemu_migration.c | 36 +- src/qemu/qemu_migration_cookie.c | 8 +- src/qemu/qemu_process.c | 196 +++---- src/security/virt-aa-helper.c | 2 +- src/test/test_driver.c | 45 +- src/util/virresctrl.h | 2 + src/vbox/vbox_common.c | 16 +- src/vmware/vmware_conf.c | 2 +- src/vmware/vmware_driver.c | 25 +- src/vmx/vmx.c | 23 +- src/vmx/vmx.h | 2 +- src/vz/vz_driver.c | 29 +- tests/Makefile.am | 17 +- tests/bhyveargv2xmltest.c | 2 +- tests/bhyvexml2argvtest.c | 2 +- tests/cputest.c | 11 +- tests/domaincapstest.c | 14 +- tests/domainconftest.c | 2 +- tests/libxlxml2domconfigtest.c | 22 +- tests/lxcconf2xmltest.c | 17 +- tests/lxcxml2xmltest.c | 13 +- tests/openvzutilstest.c | 8 +- tests/qemuagenttest.c | 2 +- tests/qemublocktest.c | 2 +- tests/qemucapabilitiestest.c | 9 +- tests/qemudomaincheckpointxml2xmltest.c | 4 +- tests/qemudomainsnapshotxml2xmltest.c | 4 +- tests/qemuhotplugtest.c | 11 +- tests/qemumemlocktest.c | 6 +- tests/qemusecuritytest.c | 1 - tests/qemuxml2argvtest.c | 35 +- tests/qemuxml2xmltest.c | 4 +- tests/securityselinuxlabeltest.c | 2 +- tests/testutils.c | 39 +- tests/testutils.h | 5 +- tests/testutilslxc.c | 34 +- tests/testutilslxc.h | 4 + tests/testutilsqemu.c | 670 +++++++----------------- tests/testutilsqemu.h | 9 +- tests/testutilsxen.c | 34 +- tests/testutilsxen.h | 9 +- tests/vircaps2xmltest.c | 6 +- tests/vircapstest.c | 11 +- tests/vmx2xmltest.c | 4 +- tests/xlconfigtest.c | 27 +- tests/xmconfigtest.c | 23 +- tests/xml2vmxtest.c | 4 +- 102 files changed, 1687 insertions(+), 1993 deletions(-) -- 2.23.0

As part of a goal to eliminate the need to use virCapsPtr for anything other than the virConnectGetCapabilies() API impl, cache the host arch against the QEMU driver struct and use that field directly. In the tests we move virArchFromHost() globally in testutils.c so that every test runs with a fixed default architecture reported. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/qemu/qemu_capabilities.c | 20 ++++++++++---------- src/qemu/qemu_capabilities.h | 6 +++--- src/qemu/qemu_command.c | 6 +----- src/qemu/qemu_conf.c | 6 +----- src/qemu/qemu_conf.h | 3 +++ src/qemu/qemu_domain.c | 8 ++++---- src/qemu/qemu_driver.c | 3 ++- src/qemu/qemu_process.c | 14 +++++++------- tests/domaincapstest.c | 2 +- tests/qemumemlocktest.c | 4 ++-- tests/qemuxml2argvtest.c | 16 ++++++++-------- tests/testutils.c | 9 +++++++++ tests/testutils.h | 2 ++ tests/testutilsqemu.c | 11 ++++++++--- tests/testutilsqemu.h | 4 ++-- 15 files changed, 63 insertions(+), 51 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index edb128c881..cfc16ba63e 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2096,7 +2096,7 @@ virQEMUCapsSetHostModel(virQEMUCapsPtr qemuCaps, bool virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps, - virCapsPtr caps, + virArch hostarch, virDomainVirtType type, virCPUMode mode) { @@ -2105,7 +2105,7 @@ virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps, switch (mode) { case VIR_CPU_MODE_HOST_PASSTHROUGH: return type == VIR_DOMAIN_VIRT_KVM && - virQEMUCapsGuestIsNative(caps->host.arch, qemuCaps->arch); + virQEMUCapsGuestIsNative(hostarch, qemuCaps->arch); case VIR_CPU_MODE_HOST_MODEL: return !!virQEMUCapsGetHostModel(qemuCaps, type, @@ -5412,22 +5412,22 @@ virQEMUCapsFillDomainOSCaps(virDomainCapsOSPtr os, static void -virQEMUCapsFillDomainCPUCaps(virCapsPtr caps, - virQEMUCapsPtr qemuCaps, +virQEMUCapsFillDomainCPUCaps(virQEMUCapsPtr qemuCaps, + virArch hostarch, virDomainCapsPtr domCaps) { - if (virQEMUCapsIsCPUModeSupported(qemuCaps, caps, domCaps->virttype, + if (virQEMUCapsIsCPUModeSupported(qemuCaps, hostarch, domCaps->virttype, VIR_CPU_MODE_HOST_PASSTHROUGH)) domCaps->cpu.hostPassthrough = true; - if (virQEMUCapsIsCPUModeSupported(qemuCaps, caps, domCaps->virttype, + if (virQEMUCapsIsCPUModeSupported(qemuCaps, hostarch, domCaps->virttype, VIR_CPU_MODE_HOST_MODEL)) { virCPUDefPtr cpu = virQEMUCapsGetHostModel(qemuCaps, domCaps->virttype, VIR_QEMU_CAPS_HOST_CPU_REPORTED); domCaps->cpu.hostModel = virCPUDefCopy(cpu); } - if (virQEMUCapsIsCPUModeSupported(qemuCaps, caps, domCaps->virttype, + if (virQEMUCapsIsCPUModeSupported(qemuCaps, hostarch, domCaps->virttype, VIR_CPU_MODE_CUSTOM)) { const char *blacklist[] = { "host", NULL }; VIR_AUTOSTRINGLIST models = NULL; @@ -5746,9 +5746,9 @@ virQEMUCapsFillDomainFeatureSEVCaps(virQEMUCapsPtr qemuCaps, int -virQEMUCapsFillDomainCaps(virCapsPtr caps, +virQEMUCapsFillDomainCaps(virQEMUCapsPtr qemuCaps, + virArch hostarch, virDomainCapsPtr domCaps, - virQEMUCapsPtr qemuCaps, bool privileged, virFirmwarePtr *firmwares, size_t nfirmwares) @@ -5781,7 +5781,7 @@ virQEMUCapsFillDomainCaps(virCapsPtr caps, firmwares, nfirmwares) < 0) return -1; - virQEMUCapsFillDomainCPUCaps(caps, qemuCaps, domCaps); + virQEMUCapsFillDomainCPUCaps(qemuCaps, hostarch, domCaps); virQEMUCapsFillDomainDeviceDiskCaps(qemuCaps, domCaps->machine, disk); virQEMUCapsFillDomainDeviceGraphicsCaps(qemuCaps, graphics); virQEMUCapsFillDomainDeviceVideoCaps(qemuCaps, video); diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 4d7d836e8c..399496796d 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -604,7 +604,7 @@ int virQEMUCapsGetCPUFeatures(virQEMUCapsPtr qemuCaps, char ***features); bool virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps, - virCapsPtr caps, + virArch hostarch, virDomainVirtType type, virCPUMode mode); const char *virQEMUCapsGetCanonicalMachine(virQEMUCapsPtr qemuCaps, @@ -665,9 +665,9 @@ int virQEMUCapsInitGuestFromBinary(virCapsPtr caps, virQEMUCapsPtr qemuCaps, virArch guestarch); -int virQEMUCapsFillDomainCaps(virCapsPtr caps, +int virQEMUCapsFillDomainCaps(virQEMUCapsPtr qemuCaps, + virArch hostarch, virDomainCapsPtr domCaps, - virQEMUCapsPtr qemuCaps, bool privileged, virFirmwarePtr *firmwares, size_t nfirmwares); diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 3465d28b84..49a0dad8d4 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6657,18 +6657,14 @@ qemuBuildCpuModelArgStr(virQEMUDriverPtr driver, virQEMUCapsPtr qemuCaps) { size_t i; - g_autoptr(virCaps) caps = NULL; virCPUDefPtr cpu = def->cpu; - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - return -1; - switch ((virCPUMode) cpu->mode) { case VIR_CPU_MODE_HOST_PASSTHROUGH: virBufferAddLit(buf, "host"); if (def->os.arch == VIR_ARCH_ARMV7L && - caps->host.arch == VIR_ARCH_AARCH64) { + driver->hostarch == VIR_ARCH_AARCH64) { if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_CPU_AARCH64_OFF)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("QEMU binary does not support CPU " diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 30637b21ac..53658c80e8 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1341,7 +1341,6 @@ virQEMUDriverGetDomainCapabilities(virQEMUDriverPtr driver, virDomainVirtType virttype) { g_autoptr(virDomainCaps) domCaps = NULL; - g_autoptr(virCaps) caps = NULL; g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver); virHashTablePtr domCapsCache = virQEMUCapsGetDomainCapsCache(qemuCaps); struct virQEMUDriverSearchDomcapsData data = { @@ -1351,9 +1350,6 @@ virQEMUDriverGetDomainCapabilities(virQEMUDriverPtr driver, .virttype = virttype, }; - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - return NULL; - domCaps = virHashSearch(domCapsCache, virQEMUDriverSearchDomcaps, &data, NULL); if (!domCaps) { @@ -1364,7 +1360,7 @@ virQEMUDriverGetDomainCapabilities(virQEMUDriverPtr driver, data.arch, data.virttype))) return NULL; - if (virQEMUCapsFillDomainCaps(caps, domCaps, qemuCaps, + if (virQEMUCapsFillDomainCaps(qemuCaps, driver->hostarch, domCaps, driver->privileged, cfg->firmwares, cfg->nfirmwares) < 0) return NULL; diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 95b33a1093..7c56226b8c 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -262,6 +262,9 @@ struct _virQEMUDriver { */ virCapsPtr caps; + /* Immutable value */ + virArch hostarch; + /* Immutable pointer, Immutable object */ virDomainXMLOptionPtr xmlopt; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 470d342afc..939e6fc01c 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4446,7 +4446,7 @@ qemuDomainDefVcpusPostParse(virDomainDefPtr def) static int qemuDomainDefSetDefaultCPU(virDomainDefPtr def, - virCapsPtr caps, + virArch hostarch, virQEMUCapsPtr qemuCaps) { const char *model; @@ -4484,7 +4484,7 @@ qemuDomainDefSetDefaultCPU(virDomainDefPtr def, if (STREQ(model, "host")) { if (ARCH_IS_S390(def->os.arch) && - virQEMUCapsIsCPUModeSupported(qemuCaps, caps, def->virtType, + virQEMUCapsIsCPUModeSupported(qemuCaps, hostarch, def->virtType, VIR_CPU_MODE_HOST_MODEL)) { def->cpu->mode = VIR_CPU_MODE_HOST_MODEL; } else { @@ -4691,7 +4691,7 @@ qemuDomainDefPostParseBasic(virDomainDefPtr def, static int qemuDomainDefPostParse(virDomainDefPtr def, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, unsigned int parseFlags, void *opaque, void *parseOpaque) @@ -4723,7 +4723,7 @@ qemuDomainDefPostParse(virDomainDefPtr def, if (qemuCanonicalizeMachine(def, qemuCaps) < 0) return -1; - if (qemuDomainDefSetDefaultCPU(def, caps, qemuCaps) < 0) + if (qemuDomainDefSetDefaultCPU(def, driver->hostarch, qemuCaps) < 0) return -1; qemuDomainDefEnableDefaultFeatures(def, qemuCaps); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1911073f3e..594b683b80 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -673,6 +673,7 @@ qemuStateInitialize(bool privileged, qemu_driver->inhibitOpaque = opaque; qemu_driver->privileged = privileged; + qemu_driver->hostarch = virArchFromHost(); if (!(qemu_driver->domains = virDomainObjListNew())) goto error; @@ -13418,7 +13419,7 @@ qemuConnectCompareCPU(virConnectPtr conn, if (!(caps = virQEMUDriverGetCapabilities(driver, false))) return VIR_CPU_COMPARE_ERROR; - return virCPUCompareXML(caps->host.arch, caps->host.cpu, + return virCPUCompareXML(driver->hostarch, caps->host.cpu, xmlDesc, failIncompatible); } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 75ee3893c6..480fcd075d 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6047,7 +6047,7 @@ qemuProcessDropUnknownCPUFeatures(const char *name, static int qemuProcessUpdateGuestCPU(virDomainDefPtr def, virQEMUCapsPtr qemuCaps, - virCapsPtr caps, + virArch hostarch, unsigned int flags) { if (!def->cpu) @@ -6069,7 +6069,7 @@ qemuProcessUpdateGuestCPU(virDomainDefPtr def, def->cpu->mode = VIR_CPU_MODE_CUSTOM; } - if (!virQEMUCapsIsCPUModeSupported(qemuCaps, caps, def->virtType, + if (!virQEMUCapsIsCPUModeSupported(qemuCaps, hostarch, def->virtType, def->cpu->mode)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("CPU mode '%s' for %s %s domain on %s host is not " @@ -6077,11 +6077,11 @@ qemuProcessUpdateGuestCPU(virDomainDefPtr def, virCPUModeTypeToString(def->cpu->mode), virArchToString(def->os.arch), virDomainVirtTypeToString(def->virtType), - virArchToString(caps->host.arch)); + virArchToString(hostarch)); return -1; } - if (virCPUConvertLegacy(caps->host.arch, def->cpu) < 0) + if (virCPUConvertLegacy(hostarch, def->cpu) < 0) return -1; /* nothing to update for host-passthrough */ @@ -6089,7 +6089,7 @@ qemuProcessUpdateGuestCPU(virDomainDefPtr def, g_autoptr(virDomainCapsCPUModels) cpuModels = NULL; if (def->cpu->check == VIR_CPU_CHECK_PARTIAL && - virCPUCompare(caps->host.arch, + virCPUCompare(hostarch, virQEMUCapsGetHostModel(qemuCaps, def->virtType, VIR_QEMU_CAPS_HOST_CPU_FULL), def->cpu, true) < 0) @@ -6351,7 +6351,7 @@ qemuProcessPrepareDomain(virQEMUDriverPtr driver, priv->pausedReason = VIR_DOMAIN_PAUSED_UNKNOWN; VIR_DEBUG("Updating guest CPU definition"); - if (qemuProcessUpdateGuestCPU(vm->def, priv->qemuCaps, caps, flags) < 0) + if (qemuProcessUpdateGuestCPU(vm->def, priv->qemuCaps, driver->hostarch, flags) < 0) goto cleanup; for (i = 0; i < vm->def->nshmems; i++) @@ -7825,7 +7825,7 @@ qemuProcessRefreshCPU(virQEMUDriverPtr driver, if (!caps) return -1; - if (!virQEMUCapsGuestIsNative(caps->host.arch, vm->def->os.arch) || + if (!virQEMUCapsGuestIsNative(driver->hostarch, vm->def->os.arch) || !caps->host.cpu || !vm->def->cpu) { ret = 0; diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c index c6700f7e78..94e5831706 100644 --- a/tests/domaincapstest.c +++ b/tests/domaincapstest.c @@ -106,7 +106,7 @@ fillQemuCaps(virDomainCapsPtr domCaps, if (!domCaps->machine) domCaps->machine = g_strdup(virQEMUCapsGetPreferredMachine(qemuCaps, virtType)); - if (virQEMUCapsFillDomainCaps(caps, domCaps, qemuCaps, + if (virQEMUCapsFillDomainCaps(qemuCaps, caps->host.arch, domCaps, false, cfg->firmwares, cfg->nfirmwares) < 0) diff --git a/tests/qemumemlocktest.c b/tests/qemumemlocktest.c index ef3bfa0345..55f65dcb6a 100644 --- a/tests/qemumemlocktest.c +++ b/tests/qemumemlocktest.c @@ -101,7 +101,7 @@ mymain(void) * ensure settings are prioritized as expected. */ - qemuTestSetHostArch(driver.caps, VIR_ARCH_X86_64); + qemuTestSetHostArch(&driver, VIR_ARCH_X86_64); DO_TEST("pc-kvm", 0); DO_TEST("pc-tcg", 0); @@ -115,7 +115,7 @@ mymain(void) DO_TEST("pc-hardlimit+locked+hostdev", 2147483648); DO_TEST("pc-locked+hostdev", VIR_DOMAIN_MEMORY_PARAM_UNLIMITED); - qemuTestSetHostArch(driver.caps, VIR_ARCH_PPC64); + qemuTestSetHostArch(&driver, VIR_ARCH_PPC64); if (!(qemuCaps = virQEMUCapsNew())) { ret = -1; goto cleanup; diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 86b8899921..546cdae245 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -413,7 +413,7 @@ testCompareXMLToArgv(const void *data) qemuDomainObjPrivatePtr priv = NULL; if (info->arch != VIR_ARCH_NONE && info->arch != VIR_ARCH_X86_64) - qemuTestSetHostArch(driver.caps, info->arch); + qemuTestSetHostArch(&driver, info->arch); memset(&monitor_chr, 0, sizeof(monitor_chr)); @@ -584,7 +584,7 @@ testCompareXMLToArgv(const void *data) virObjectUnref(conn); VIR_FREE(migrateURI); if (info->arch != VIR_ARCH_NONE && info->arch != VIR_ARCH_X86_64) - qemuTestSetHostArch(driver.caps, VIR_ARCH_NONE); + qemuTestSetHostArch(&driver, VIR_ARCH_NONE); return ret; } @@ -1724,11 +1724,11 @@ mymain(void) DO_TEST("cpu-host-passthrough", QEMU_CAPS_KVM); DO_TEST_FAILURE("cpu-qemu-host-passthrough", QEMU_CAPS_KVM); - qemuTestSetHostArch(driver.caps, VIR_ARCH_S390X); + qemuTestSetHostArch(&driver, VIR_ARCH_S390X); DO_TEST("cpu-s390-zEC12", QEMU_CAPS_KVM, QEMU_CAPS_CCW, QEMU_CAPS_VIRTIO_S390); DO_TEST("cpu-s390-features", QEMU_CAPS_KVM, QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION); DO_TEST_FAILURE("cpu-s390-features", QEMU_CAPS_KVM); - qemuTestSetHostArch(driver.caps, VIR_ARCH_NONE); + qemuTestSetHostArch(&driver, VIR_ARCH_NONE); qemuTestSetHostCPU(driver.caps, cpuHaswell); DO_TEST("cpu-Haswell", QEMU_CAPS_KVM); @@ -1855,7 +1855,7 @@ mymain(void) QEMU_CAPS_DEVICE_SPAPR_VTY); DO_TEST_PARSE_ERROR("pseries-no-parallel", NONE); - qemuTestSetHostArch(driver.caps, VIR_ARCH_PPC64); + qemuTestSetHostArch(&driver, VIR_ARCH_PPC64); DO_TEST("pseries-cpu-compat", QEMU_CAPS_KVM, QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE, QEMU_CAPS_DEVICE_SPAPR_VTY); @@ -1877,7 +1877,7 @@ mymain(void) QEMU_CAPS_DEVICE_SPAPR_VTY); qemuTestSetHostCPU(driver.caps, NULL); - qemuTestSetHostArch(driver.caps, VIR_ARCH_NONE); + qemuTestSetHostArch(&driver, VIR_ARCH_NONE); DO_TEST("pseries-panic-missing", QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE, @@ -2552,7 +2552,7 @@ mymain(void) QEMU_CAPS_DEVICE_VIRTIO_RNG, QEMU_CAPS_OBJECT_RNG_RANDOM); DO_TEST("aarch64-virt-default-nic", QEMU_CAPS_DEVICE_VIRTIO_MMIO); - qemuTestSetHostArch(driver.caps, VIR_ARCH_AARCH64); + qemuTestSetHostArch(&driver, VIR_ARCH_AARCH64); DO_TEST("aarch64-cpu-passthrough", QEMU_CAPS_DEVICE_VIRTIO_MMIO, QEMU_CAPS_KVM); @@ -2668,7 +2668,7 @@ mymain(void) /* SVE aarch64 CPU features work on modern QEMU */ DO_TEST_CAPS_ARCH_LATEST("aarch64-features-sve", "aarch64"); - qemuTestSetHostArch(driver.caps, VIR_ARCH_NONE); + qemuTestSetHostArch(&driver, VIR_ARCH_NONE); DO_TEST("kvm-pit-delay", QEMU_CAPS_KVM_PIT_TICK_POLICY); DO_TEST("kvm-pit-discard", QEMU_CAPS_KVM_PIT_TICK_POLICY); diff --git a/tests/testutils.c b/tests/testutils.c index d9c0d5abbe..387ba55908 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -60,6 +60,15 @@ static virBitmapPtr testBitmap; char *progname; static char *perl; +virArch virTestHostArch = VIR_ARCH_X86_64; + +virArch +virArchFromHost(void) +{ + return virTestHostArch; +} + + static int virTestUseTerminalColors(void) { return isatty(STDOUT_FILENO); diff --git a/tests/testutils.h b/tests/testutils.h index 76090c5522..c3f2cee85f 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -43,6 +43,8 @@ extern char *progname; # error Fix Makefile.am #endif +extern virArch virTestHostArch; + int virTestRun(const char *title, int (*body)(const void *data), const void *data); diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 4cb128559a..97f63e7d5d 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -576,13 +576,16 @@ virCapsPtr testQemuCapsInit(void) void -qemuTestSetHostArch(virCapsPtr caps, +qemuTestSetHostArch(virQEMUDriverPtr driver, virArch arch) { if (arch == VIR_ARCH_NONE) arch = VIR_ARCH_X86_64; - caps->host.arch = arch; - qemuTestSetHostCPU(caps, NULL); + + virTestHostArch = arch; + driver->hostarch = virArchFromHost(); + driver->caps->host.arch = virArchFromHost(); + qemuTestSetHostCPU(driver->caps, NULL); } @@ -694,6 +697,8 @@ int qemuTestDriverInit(virQEMUDriver *driver) if (virMutexInit(&driver->lock) < 0) return -1; + driver->hostarch = virArchFromHost(); + driver->config = virQEMUDriverConfigNew(false); if (!driver->config) goto error; diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h index da3bf3ab7a..8dcc930ac3 100644 --- a/tests/testutilsqemu.h +++ b/tests/testutilsqemu.h @@ -80,8 +80,8 @@ extern virCPUDefPtr cpuHaswell; extern virCPUDefPtr cpuPower8; extern virCPUDefPtr cpuPower9; -void qemuTestSetHostArch(virCapsPtr caps, - virArch arch); +void qemuTestSetHostArch(virQEMUDriverPtr driver, + virArch arch); void qemuTestSetHostCPU(virCapsPtr caps, virCPUDefPtr cpu); -- 2.23.0

Currently the virQEMUCapsPtr objects are just empty. Future patches are going to expect them to contain real data. Start off by populating the machine types and arch information. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/qemu/qemu_capabilities.c | 70 +++-- src/qemu/qemu_capspriv.h | 10 + tests/qemuxml2argvtest.c | 9 +- tests/testutilsqemu.c | 594 ++++++++--------------------------- 4 files changed, 190 insertions(+), 493 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index cfc16ba63e..c02ff5b941 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2434,49 +2434,72 @@ static const char *preferredMachines[] = verify(G_N_ELEMENTS(preferredMachines) == VIR_ARCH_LAST); +void +virQEMUCapsAddMachine(virQEMUCapsPtr qemuCaps, + virDomainVirtType virtType, + const char *name, + const char *alias, + const char *defaultCPU, + int maxCpus, + bool hotplugCpus, + bool isDefault) +{ + virQEMUCapsAccelPtr accel = virQEMUCapsGetAccel(qemuCaps, virtType); + virQEMUCapsMachineTypePtr mach; + + accel->machineTypes = g_renew(virQEMUCapsMachineType, + accel->machineTypes, + ++accel->nmachineTypes); + + mach = &(accel->machineTypes[accel->nmachineTypes - 1]); + + mach->alias = g_strdup(alias); + mach->name = g_strdup(name); + mach->defaultCPU = g_strdup(defaultCPU); + + mach->maxCpus = maxCpus; + mach->hotplugCpus = hotplugCpus; + + mach->qemuDefault = isDefault; +} + static int virQEMUCapsProbeQMPMachineTypes(virQEMUCapsPtr qemuCaps, - virQEMUCapsAccelPtr accel, + virDomainVirtType virtType, qemuMonitorPtr mon) { qemuMonitorMachineInfoPtr *machines = NULL; int nmachines = 0; - int ret = -1; size_t i; ssize_t defIdx = -1; ssize_t preferredIdx = -1; const char *preferredMachine = preferredMachines[qemuCaps->arch]; + virQEMUCapsAccelPtr accel = virQEMUCapsGetAccel(qemuCaps, virtType); if ((nmachines = qemuMonitorGetMachines(mon, &machines)) < 0) return -1; - if (VIR_ALLOC_N(accel->machineTypes, nmachines) < 0) - goto cleanup; - for (i = 0; i < nmachines; i++) { - virQEMUCapsMachineTypePtr mach; if (STREQ(machines[i]->name, "none")) continue; - mach = &(accel->machineTypes[accel->nmachineTypes++]); - - mach->alias = g_strdup(machines[i]->alias); - mach->name = g_strdup(machines[i]->name); - mach->defaultCPU = g_strdup(machines[i]->defaultCPU); - - mach->maxCpus = machines[i]->maxCpus; - mach->hotplugCpus = machines[i]->hotplugCpus; + virQEMUCapsAddMachine(qemuCaps, + virtType, + machines[i]->name, + machines[i]->alias, + machines[i]->defaultCPU, + machines[i]->maxCpus, + machines[i]->hotplugCpus, + machines[i]->isDefault); if (preferredMachine && - (STREQ_NULLABLE(mach->alias, preferredMachine) || - STREQ(mach->name, preferredMachine))) { + (STREQ_NULLABLE(machines[i]->alias, preferredMachine) || + STREQ(machines[i]->name, preferredMachine))) { preferredIdx = accel->nmachineTypes - 1; } - if (machines[i]->isDefault) { - mach->qemuDefault = true; + if (machines[i]->isDefault) defIdx = accel->nmachineTypes - 1; - } } /* @@ -2493,13 +2516,10 @@ virQEMUCapsProbeQMPMachineTypes(virQEMUCapsPtr qemuCaps, if (preferredIdx != -1) virQEMUCapsSetDefaultMachine(accel, preferredIdx); - ret = 0; - - cleanup: for (i = 0; i < nmachines; i++) qemuMonitorMachineInfoFree(machines[i]); VIR_FREE(machines); - return ret; + return 0; } @@ -4745,7 +4765,7 @@ virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps, return -1; if (virQEMUCapsProbeQMPDevices(qemuCaps, mon) < 0) return -1; - if (virQEMUCapsProbeQMPMachineTypes(qemuCaps, accel, mon) < 0) + if (virQEMUCapsProbeQMPMachineTypes(qemuCaps, type, mon) < 0) return -1; if (virQEMUCapsProbeQMPMachineProps(qemuCaps, type, mon) < 0) return -1; @@ -4788,7 +4808,7 @@ virQEMUCapsInitQMPMonitorTCG(virQEMUCapsPtr qemuCaps, if (virQEMUCapsProbeQMPHostCPU(qemuCaps, accel, mon, VIR_DOMAIN_VIRT_QEMU) < 0) return -1; - if (virQEMUCapsProbeQMPMachineTypes(qemuCaps, accel, mon) < 0) + if (virQEMUCapsProbeQMPMachineTypes(qemuCaps, VIR_DOMAIN_VIRT_QEMU, mon) < 0) return -1; return 0; diff --git a/src/qemu/qemu_capspriv.h b/src/qemu/qemu_capspriv.h index 9fc3f43f32..9059ee3059 100644 --- a/src/qemu/qemu_capspriv.h +++ b/src/qemu/qemu_capspriv.h @@ -104,3 +104,13 @@ virQEMUCapsSetMicrocodeVersion(virQEMUCapsPtr qemuCaps, void virQEMUCapsStripMachineAliases(virQEMUCapsPtr qemuCaps); + +void +virQEMUCapsAddMachine(virQEMUCapsPtr qemuCaps, + virDomainVirtType virtType, + const char *name, + const char *alias, + const char *defaultCPU, + int maxCpus, + bool hotplugCpus, + bool isDefault); diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 546cdae245..6890de101b 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -475,9 +475,12 @@ testCompareXMLToArgv(const void *data) if (qemuProcessPrepareMonitorChr(&monitor_chr, priv->libDir) < 0) goto cleanup; - if (!(info->flags & FLAG_REAL_CAPS) && - testUpdateQEMUCaps(info, vm, driver.caps) < 0) - goto cleanup; + if (!(info->flags & FLAG_REAL_CAPS)) { + if (testUpdateQEMUCaps(info, vm, driver.caps) < 0) + goto cleanup; + if (qemuTestCapsCacheInsert(driver.qemuCapsCache, info->qemuCaps) < 0) + goto cleanup; + } log = virTestLogContentAndReset(); VIR_FREE(log); diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 97f63e7d5d..0ca690a1ed 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -20,149 +20,115 @@ virCPUDefPtr cpuHaswell; virCPUDefPtr cpuPower8; virCPUDefPtr cpuPower9; -typedef enum { - TEST_UTILS_QEMU_BIN_I686, - TEST_UTILS_QEMU_BIN_X86_64, - TEST_UTILS_QEMU_BIN_AARCH64, - TEST_UTILS_QEMU_BIN_ARM, - TEST_UTILS_QEMU_BIN_PPC64, - TEST_UTILS_QEMU_BIN_PPC, - TEST_UTILS_QEMU_BIN_RISCV32, - TEST_UTILS_QEMU_BIN_RISCV64, - TEST_UTILS_QEMU_BIN_S390X -} QEMUBinType; - -static const char *QEMUBinList[] = { - "/usr/bin/qemu-system-i386", - "/usr/bin/qemu-system-x86_64", - "/usr/bin/qemu-system-aarch64", - "/usr/bin/qemu-system-arm", - "/usr/bin/qemu-system-ppc64", - "/usr/bin/qemu-system-ppc", - "/usr/bin/qemu-system-riscv32", - "/usr/bin/qemu-system-riscv64", - "/usr/bin/qemu-system-s390x" -}; - - -static virCapsGuestMachinePtr *testQemuAllocMachines(int *nmachines) -{ - virCapsGuestMachinePtr *machines; - static const char *const x86_machines[] = { - "pc", "isapc" - }; - - machines = virCapabilitiesAllocMachines(x86_machines, - G_N_ELEMENTS(x86_machines)); - if (machines == NULL) - return NULL; - - *nmachines = G_N_ELEMENTS(x86_machines); - return machines; -} - -/* Newer versions of qemu have versioned machine types to allow - * compatibility with older releases. - * The 'pc' machine type is an alias of the newest machine type. - */ -static virCapsGuestMachinePtr *testQemuAllocNewerMachines(int *nmachines) -{ - virCapsGuestMachinePtr *machines; - char *canonical; - static const char *const x86_machines[] = { - "pc-0.11", "pc", "pc-0.10", "isapc" - }; - - canonical = g_strdup(x86_machines[0]); - - machines = virCapabilitiesAllocMachines(x86_machines, - G_N_ELEMENTS(x86_machines)); - if (machines == NULL) { - VIR_FREE(canonical); - return NULL; - } +static const char *qemu_emulators[VIR_ARCH_LAST] = { + [VIR_ARCH_I686] = "/usr/bin/qemu-system-i386", + [VIR_ARCH_X86_64] = "/usr/bin/qemu-system-x86_64", + [VIR_ARCH_AARCH64] = "/usr/bin/qemu-system-aarch64", + [VIR_ARCH_ARMV7L] = "/usr/bin/qemu-system-arm", + [VIR_ARCH_PPC64] = "/usr/bin/qemu-system-ppc64", + [VIR_ARCH_PPC] = "/usr/bin/qemu-system-ppc", + [VIR_ARCH_RISCV32] = "/usr/bin/qemu-system-riscv32", + [VIR_ARCH_RISCV64] = "/usr/bin/qemu-system-riscv64", + [VIR_ARCH_S390X] = "/usr/bin/qemu-system-s390x" +}; - machines[1]->canonical = canonical; +static const virArch arch_alias[VIR_ARCH_LAST] = { + [VIR_ARCH_PPC64LE] = VIR_ARCH_PPC64, + [VIR_ARCH_ARMV6L] = VIR_ARCH_ARMV7L, +}; - *nmachines = G_N_ELEMENTS(x86_machines); +static const char *const i386_machines[] = { + "pc", "isapc", NULL +}; +static const char *const x86_64_machines_kvm[] = { + "pc", "isapc", NULL +}; +static const char *const x86_64_machines_qemu[] = { + "pc-0.11", "pc", "pc-0.10", "isapc", NULL +}; +static const char *const aarch64_machines[] = { + "virt", NULL +}; +static const char *const arm_machines[] = { + "vexpress-a9", "vexpress-a15", "versatilepb", NULL +}; +static const char *const ppc64_machines[] = { + "pseries", NULL +}; +static const char *const ppc_machines[] = { + "g3beige", "mac99", "prep", "ppce500", NULL +}; +static const char *const riscv32_machines[] = { + "spike_v1.10", "spike_v1.9.1", "sifive_e", "virt", "sifive_u", NULL +}; +static const char *const riscv64_machines[] = { + "spike_v1.10", "spike_v1.9.1", "sifive_e", "virt", "sifive_u", NULL +}; +static const char *const s390x_machines[] = { + "s390-virtio", "s390-ccw-virtio", NULL +}; - return machines; -} +static const char *const *qemu_machines[VIR_ARCH_LAST] = { + [VIR_ARCH_I686] = i386_machines, + [VIR_ARCH_X86_64] = x86_64_machines_qemu, + [VIR_ARCH_AARCH64] = aarch64_machines, + [VIR_ARCH_ARMV7L] = arm_machines, + [VIR_ARCH_PPC64] = ppc64_machines, + [VIR_ARCH_PPC] = ppc_machines, + [VIR_ARCH_RISCV32] = riscv32_machines, + [VIR_ARCH_RISCV64] = riscv64_machines, + [VIR_ARCH_S390X] = s390x_machines, +}; +static const char *const *kvm_machines[VIR_ARCH_LAST] = { + [VIR_ARCH_I686] = i386_machines, + [VIR_ARCH_X86_64] = x86_64_machines_kvm, + [VIR_ARCH_AARCH64] = aarch64_machines, + [VIR_ARCH_ARMV7L] = arm_machines, + [VIR_ARCH_PPC64] = ppc64_machines, + [VIR_ARCH_PPC] = ppc_machines, + [VIR_ARCH_RISCV32] = riscv32_machines, + [VIR_ARCH_RISCV64] = riscv64_machines, + [VIR_ARCH_S390X] = s390x_machines, +}; static int -testQemuAddI686Guest(virCapsPtr caps) +testQemuAddGuest(virCapsPtr caps, + virArch arch) { - int nmachines = 0; + size_t nmachines; virCapsGuestMachinePtr *machines = NULL; virCapsGuestPtr guest; + virArch emu_arch = arch; - if (!(machines = testQemuAllocMachines(&nmachines))) - goto error; - - if (!(guest = virCapabilitiesAddGuest(caps, - VIR_DOMAIN_OSTYPE_HVM, - VIR_ARCH_I686, - QEMUBinList[TEST_UTILS_QEMU_BIN_I686], - NULL, - nmachines, - machines))) - goto error; - - virCapabilitiesAddGuestFeature(guest, VIR_CAPS_GUEST_FEATURE_TYPE_CPUSELECTION); - - machines = NULL; - - if (!virCapabilitiesAddGuestDomain(guest, - VIR_DOMAIN_VIRT_QEMU, - NULL, - NULL, - 0, - NULL)) - goto error; - - if (!(machines = testQemuAllocMachines(&nmachines))) - goto error; - - if (!virCapabilitiesAddGuestDomain(guest, - VIR_DOMAIN_VIRT_KVM, - QEMUBinList[TEST_UTILS_QEMU_BIN_I686], - NULL, - nmachines, - machines)) - goto error; - - return 0; - - error: - virCapabilitiesFreeMachines(machines, nmachines); - return -1; -} - + if (arch_alias[arch] != VIR_ARCH_NONE) + emu_arch = arch_alias[arch]; -static int -testQemuAddX86_64Guest(virCapsPtr caps) -{ - int nmachines = 0; - virCapsGuestMachinePtr *machines = NULL; - virCapsGuestPtr guest; + if (qemu_emulators[emu_arch] == NULL) + return 0; - if (!(machines = testQemuAllocNewerMachines(&nmachines))) + nmachines = g_strv_length((gchar **)qemu_machines[emu_arch]); + machines = virCapabilitiesAllocMachines(qemu_machines[emu_arch], + nmachines); + if (machines == NULL) goto error; if (!(guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, - VIR_ARCH_X86_64, - QEMUBinList[TEST_UTILS_QEMU_BIN_X86_64], + arch, + qemu_emulators[emu_arch], NULL, nmachines, machines))) goto error; - virCapabilitiesAddGuestFeature(guest, VIR_CAPS_GUEST_FEATURE_TYPE_CPUSELECTION); - machines = NULL; + nmachines = 0; + + if (arch == VIR_ARCH_I686 || + arch == VIR_ARCH_X86_64) + virCapabilitiesAddGuestFeature(guest, VIR_CAPS_GUEST_FEATURE_TYPE_CPUSELECTION); if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_QEMU, @@ -172,27 +138,20 @@ testQemuAddX86_64Guest(virCapsPtr caps) NULL)) goto error; - if (!(machines = testQemuAllocMachines(&nmachines))) + nmachines = g_strv_length((char **)kvm_machines[emu_arch]); + machines = virCapabilitiesAllocMachines(kvm_machines[emu_arch], + nmachines); + if (machines == NULL) goto error; if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_KVM, - QEMUBinList[TEST_UTILS_QEMU_BIN_X86_64], + qemu_emulators[emu_arch], NULL, nmachines, machines)) goto error; - machines = NULL; - - if (!virCapabilitiesAddGuestDomain(guest, - VIR_DOMAIN_VIRT_KVM, - QEMUBinList[TEST_UTILS_QEMU_BIN_X86_64], - NULL, - 0, - NULL)) - goto error; - return 0; error: @@ -201,295 +160,10 @@ testQemuAddX86_64Guest(virCapsPtr caps) } -static int testQemuAddPPC64Guest(virCapsPtr caps) -{ - static const char *machine[] = { "pseries" }; - virCapsGuestMachinePtr *machines = NULL; - virCapsGuestPtr guest; - - machines = virCapabilitiesAllocMachines(machine, 1); - if (!machines) - goto error; - - guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_PPC64, - QEMUBinList[TEST_UTILS_QEMU_BIN_PPC64], - NULL, 1, machines); - if (!guest) - goto error; - - if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_QEMU, NULL, NULL, 0, NULL)) - goto error; - if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_KVM, - NULL, NULL, 0, NULL)) - goto error; - - return 0; - - error: - /* No way to free a guest? */ - virCapabilitiesFreeMachines(machines, 1); - return -1; -} - -static int testQemuAddPPC64LEGuest(virCapsPtr caps) -{ - static const char *machine[] = { "pseries" }; - virCapsGuestMachinePtr *machines = NULL; - virCapsGuestPtr guest; - - machines = virCapabilitiesAllocMachines(machine, 1); - if (!machines) - goto error; - - guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_PPC64LE, - QEMUBinList[TEST_UTILS_QEMU_BIN_PPC64], - NULL, 1, machines); - if (!guest) - goto error; - - if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_QEMU, NULL, NULL, 0, NULL)) - goto error; - if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_KVM, - NULL, NULL, 0, NULL)) - goto error; - - return 0; - - error: - /* No way to free a guest? */ - virCapabilitiesFreeMachines(machines, 1); - return -1; -} - -static int testQemuAddPPCGuest(virCapsPtr caps) -{ - static const char *machine[] = { "g3beige", - "mac99", - "prep", - "ppce500" }; - virCapsGuestMachinePtr *machines = NULL; - virCapsGuestPtr guest; - - machines = virCapabilitiesAllocMachines(machine, 1); - if (!machines) - goto error; - - guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_PPC, - QEMUBinList[TEST_UTILS_QEMU_BIN_PPC], - NULL, 1, machines); - if (!guest) - goto error; - - if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_QEMU, NULL, NULL, 0, NULL)) - goto error; - if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_KVM, - NULL, NULL, 0, NULL)) - goto error; - - return 0; - - error: - /* No way to free a guest? */ - virCapabilitiesFreeMachines(machines, 1); - return -1; -} - -static int testQemuAddRISCV32Guest(virCapsPtr caps) -{ - static const char *names[] = { "spike_v1.10", - "spike_v1.9.1", - "sifive_e", - "virt", - "sifive_u" }; - static const int nmachines = G_N_ELEMENTS(names); - virCapsGuestMachinePtr *machines = NULL; - virCapsGuestPtr guest; - - machines = virCapabilitiesAllocMachines(names, nmachines); - if (!machines) - goto error; - - guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_RISCV32, - QEMUBinList[TEST_UTILS_QEMU_BIN_RISCV32], - NULL, nmachines, machines); - if (!guest) - goto error; - - if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_QEMU, NULL, NULL, 0, NULL)) - goto error; - - return 0; - - error: - virCapabilitiesFreeMachines(machines, nmachines); - return -1; -} - -static int testQemuAddRISCV64Guest(virCapsPtr caps) -{ - static const char *names[] = { "spike_v1.10", - "spike_v1.9.1", - "sifive_e", - "virt", - "sifive_u" }; - static const int nmachines = G_N_ELEMENTS(names); - virCapsGuestMachinePtr *machines = NULL; - virCapsGuestPtr guest; - - machines = virCapabilitiesAllocMachines(names, nmachines); - if (!machines) - goto error; - - guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_RISCV64, - QEMUBinList[TEST_UTILS_QEMU_BIN_RISCV64], - NULL, nmachines, machines); - if (!guest) - goto error; - - if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_QEMU, NULL, NULL, 0, NULL)) - goto error; - - return 0; - - error: - virCapabilitiesFreeMachines(machines, nmachines); - return -1; -} - -static int testQemuAddS390Guest(virCapsPtr caps) -{ - static const char *s390_machines[] = { "s390-virtio", - "s390-ccw-virtio" }; - virCapsGuestMachinePtr *machines = NULL; - virCapsGuestPtr guest; - - machines = virCapabilitiesAllocMachines(s390_machines, - G_N_ELEMENTS(s390_machines)); - if (!machines) - goto error; - - guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_S390X, - QEMUBinList[TEST_UTILS_QEMU_BIN_S390X], - NULL, - G_N_ELEMENTS(s390_machines), - machines); - if (!guest) - goto error; - - if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_QEMU, NULL, NULL, 0, NULL)) - goto error; - if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_KVM, - NULL, NULL, 0, NULL)) - goto error; - - return 0; - - error: - virCapabilitiesFreeMachines(machines, G_N_ELEMENTS(s390_machines)); - return -1; -} - -static int testQemuAddArm6Guest(virCapsPtr caps) -{ - static const char *machines[] = { "versatilepb" }; - virCapsGuestMachinePtr *capsmachines = NULL; - virCapsGuestPtr guest; - - capsmachines = virCapabilitiesAllocMachines(machines, - G_N_ELEMENTS(machines)); - if (!capsmachines) - goto error; - - guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_ARMV6L, - QEMUBinList[TEST_UTILS_QEMU_BIN_ARM], - NULL, - G_N_ELEMENTS(machines), - capsmachines); - if (!guest) - goto error; - - if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_QEMU, NULL, NULL, 0, NULL)) - goto error; - if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_KVM, - NULL, NULL, 0, NULL)) - goto error; - - return 0; - - error: - virCapabilitiesFreeMachines(capsmachines, G_N_ELEMENTS(machines)); - return -1; -} - -static int testQemuAddArm7Guest(virCapsPtr caps) -{ - static const char *machines[] = { "vexpress-a9", - "vexpress-a15", - "versatilepb" }; - virCapsGuestMachinePtr *capsmachines = NULL; - virCapsGuestPtr guest; - - capsmachines = virCapabilitiesAllocMachines(machines, - G_N_ELEMENTS(machines)); - if (!capsmachines) - goto error; - - guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_ARMV7L, - QEMUBinList[TEST_UTILS_QEMU_BIN_ARM], - NULL, - G_N_ELEMENTS(machines), - capsmachines); - if (!guest) - goto error; - - if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_QEMU, NULL, NULL, 0, NULL)) - goto error; - if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_KVM, - NULL, NULL, 0, NULL)) - goto error; - - return 0; - - error: - virCapabilitiesFreeMachines(capsmachines, G_N_ELEMENTS(machines)); - return -1; -} - -static int testQemuAddAARCH64Guest(virCapsPtr caps) -{ - static const char *machines[] = { "virt"}; - virCapsGuestMachinePtr *capsmachines = NULL; - virCapsGuestPtr guest; - - capsmachines = virCapabilitiesAllocMachines(machines, - G_N_ELEMENTS(machines)); - if (!capsmachines) - goto error; - - guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_AARCH64, - QEMUBinList[TEST_UTILS_QEMU_BIN_AARCH64], - NULL, - G_N_ELEMENTS(machines), - capsmachines); - if (!guest) - goto error; - - if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_QEMU, NULL, NULL, 0, NULL)) - goto error; - if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_KVM, - NULL, NULL, 0, NULL)) - goto error; - - return 0; - - error: - virCapabilitiesFreeMachines(capsmachines, G_N_ELEMENTS(machines)); - return -1; -} - virCapsPtr testQemuCapsInit(void) { virCapsPtr caps; + size_t i; if (!(caps = virCapabilitiesNew(VIR_ARCH_X86_64, false, false))) return NULL; @@ -518,38 +192,10 @@ virCapsPtr testQemuCapsInit(void) if (virTestCapsBuildNUMATopology(caps, 3) < 0) goto cleanup; - if (testQemuAddI686Guest(caps) < 0) - goto cleanup; - - if (testQemuAddX86_64Guest(caps) < 0) - goto cleanup; - - if (testQemuAddPPC64Guest(caps)) - goto cleanup; - - if (testQemuAddPPC64LEGuest(caps)) - goto cleanup; - - if (testQemuAddPPCGuest(caps)) - goto cleanup; - - if (testQemuAddRISCV32Guest(caps) < 0) - goto cleanup; - - if (testQemuAddRISCV64Guest(caps) < 0) - goto cleanup; - - if (testQemuAddS390Guest(caps)) - goto cleanup; - - if (testQemuAddArm6Guest(caps)) - goto cleanup; - - if (testQemuAddArm7Guest(caps)) - goto cleanup; - - if (testQemuAddAARCH64Guest(caps)) - goto cleanup; + for (i = 0; i < VIR_ARCH_LAST; i++) { + if (testQemuAddGuest(caps, i) < 0) + goto cleanup; + } if (virTestGetDebug()) { char *caps_str; @@ -658,27 +304,45 @@ void qemuTestDriverFree(virQEMUDriver *driver) int qemuTestCapsCacheInsert(virFileCachePtr cache, virQEMUCapsPtr caps) { - size_t i; - virQEMUCapsPtr tmpCaps; + size_t i, j; - if (caps) { - tmpCaps = caps; - } else { - if (!(tmpCaps = virQEMUCapsNew())) - return -ENOMEM; - } - - for (i = 0; i < G_N_ELEMENTS(QEMUBinList); i++) { - virObjectRef(tmpCaps); - if (virFileCacheInsertData(cache, QEMUBinList[i], tmpCaps) < 0) { + for (i = 0; i < G_N_ELEMENTS(qemu_emulators); i++) { + virQEMUCapsPtr tmpCaps; + if (qemu_emulators[i] == NULL) + continue; + if (caps) { + tmpCaps = virQEMUCapsNewCopy(caps); + } else { + tmpCaps = virQEMUCapsNew(); + } + virQEMUCapsSetArch(tmpCaps, i); + for (j = 0; qemu_machines[i][j] != NULL; j++) { + virQEMUCapsAddMachine(tmpCaps, + VIR_DOMAIN_VIRT_QEMU, + qemu_machines[i][j], + NULL, + NULL, + 0, + false, + false); + } + for (j = 0; kvm_machines[i][j] != NULL; j++) { + virQEMUCapsAddMachine(tmpCaps, + VIR_DOMAIN_VIRT_KVM, + kvm_machines[i][j], + NULL, + NULL, + 0, + false, + false); + virQEMUCapsSet(tmpCaps, QEMU_CAPS_KVM); + } + if (virFileCacheInsertData(cache, qemu_emulators[i], tmpCaps) < 0) { virObjectUnref(tmpCaps); return -1; } } - if (!caps) - virObjectUnref(tmpCaps); - return 0; } -- 2.23.0

Our normal practice is for the object type to be the name prefix, and the object instance be the first parameter passed in. Rename these to virDomainObjSave and virDomainDefSave moving their primary parameter to be the first one. Ensure that the xml options are passed into both functions in prep for future work. Finally enforce checking of the return type and mark all parameters as non-NULL. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/bhyve/bhyve_driver.c | 4 +- src/bhyve/bhyve_process.c | 10 ++- src/conf/domain_conf.c | 31 +++++----- src/conf/domain_conf.h | 26 ++++---- src/libvirt_private.syms | 5 +- src/libxl/libxl_domain.c | 2 +- src/libxl/libxl_driver.c | 35 ++++++----- src/libxl/libxl_migration.c | 6 +- src/lxc/lxc_driver.c | 39 ++++++------ src/lxc/lxc_process.c | 6 +- src/qemu/qemu_domain.c | 6 +- src/qemu/qemu_driver.c | 119 ++++++++++++++++++------------------ src/qemu/qemu_hotplug.c | 8 +-- src/qemu/qemu_migration.c | 8 +-- src/qemu/qemu_process.c | 36 +++++------ 15 files changed, 171 insertions(+), 170 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index d40ae1cd23..b8a206bb1e 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -545,8 +545,8 @@ bhyveDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flag def = NULL; vm->persistent = 1; - if (virDomainSaveConfig(BHYVE_CONFIG_DIR, caps, - vm->newDef ? vm->newDef : vm->def) < 0) { + if (virDomainDefSave(vm->newDef ? vm->newDef : vm->def, + privconn->xmlopt, caps, BHYVE_CONFIG_DIR) < 0) { virDomainObjListRemove(privconn->domains, vm); goto cleanup; } diff --git a/src/bhyve/bhyve_process.c b/src/bhyve/bhyve_process.c index 13123fdce3..c10e5500c9 100644 --- a/src/bhyve/bhyve_process.c +++ b/src/bhyve/bhyve_process.c @@ -211,9 +211,8 @@ virBhyveProcessStart(virConnectPtr conn, virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, reason); priv->mon = bhyveMonitorOpen(vm, driver); - if (virDomainSaveStatus(driver->xmlopt, - BHYVE_STATE_DIR, - vm, caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, caps, + BHYVE_STATE_DIR) < 0) goto cleanup; ret = 0; @@ -430,9 +429,8 @@ virBhyveProcessReconnect(virDomainObjPtr vm, vm->def->id = -1; virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_UNKNOWN); - ignore_value(virDomainSaveStatus(data->driver->xmlopt, - BHYVE_STATE_DIR, - vm, caps)); + ignore_value(virDomainObjSave(vm, data->driver->xmlopt, caps, + BHYVE_STATE_DIR)); } virObjectUnref(caps); diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9580884747..87bbb2d263 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -29014,10 +29014,10 @@ virDomainDefCompatibleDevice(virDomainDefPtr def, return 0; } -int -virDomainSaveXML(const char *configDir, - virDomainDefPtr def, - const char *xml) +static int +virDomainDefSaveXML(virDomainDefPtr def, + const char *configDir, + const char *xml) { char uuidstr[VIR_UUID_STRING_BUFLEN]; g_autofree char *configFile = NULL; @@ -29042,23 +29042,24 @@ virDomainSaveXML(const char *configDir, } int -virDomainSaveConfig(const char *configDir, - virCapsPtr caps, - virDomainDefPtr def) +virDomainDefSave(virDomainDefPtr def, + virDomainXMLOptionPtr xmlopt G_GNUC_UNUSED, + virCapsPtr caps, + const char *configDir) { g_autofree char *xml = NULL; if (!(xml = virDomainDefFormat(def, caps, VIR_DOMAIN_DEF_FORMAT_SECURE))) return -1; - return virDomainSaveXML(configDir, def, xml); + return virDomainDefSaveXML(def, configDir, xml); } int -virDomainSaveStatus(virDomainXMLOptionPtr xmlopt, - const char *statusDir, - virDomainObjPtr obj, - virCapsPtr caps) +virDomainObjSave(virDomainObjPtr obj, + virDomainXMLOptionPtr xmlopt, + virCapsPtr caps, + const char *statusDir) { unsigned int flags = (VIR_DOMAIN_DEF_FORMAT_SECURE | VIR_DOMAIN_DEF_FORMAT_STATUS | @@ -29071,7 +29072,7 @@ virDomainSaveStatus(virDomainXMLOptionPtr xmlopt, if (!(xml = virDomainObjFormat(xmlopt, obj, caps, flags))) return -1; - return virDomainSaveXML(statusDir, obj->def, xml); + return virDomainDefSaveXML(obj->def, statusDir, xml); } @@ -30173,7 +30174,7 @@ virDomainObjSetMetadata(virDomainObjPtr vm, if (virDomainDefSetMetadata(def, type, metadata, key, uri) < 0) return -1; - if (virDomainSaveStatus(xmlopt, stateDir, vm, caps) < 0) + if (virDomainObjSave(vm, xmlopt, caps, stateDir) < 0) return -1; } @@ -30182,7 +30183,7 @@ virDomainObjSetMetadata(virDomainObjPtr vm, uri) < 0) return -1; - if (virDomainSaveConfig(configDir, caps, persistentDef) < 0) + if (virDomainDefSave(persistentDef, xmlopt, caps, configDir) < 0) return -1; } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 49cb6970e6..d1c375092e 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3289,17 +3289,21 @@ ssize_t virDomainRedirdevDefFind(virDomainDefPtr def, virDomainRedirdevDefPtr redirdev); virDomainRedirdevDefPtr virDomainRedirdevDefRemove(virDomainDefPtr def, size_t idx); -int virDomainSaveXML(const char *configDir, - virDomainDefPtr def, - const char *xml); - -int virDomainSaveConfig(const char *configDir, - virCapsPtr caps, - virDomainDefPtr def); -int virDomainSaveStatus(virDomainXMLOptionPtr xmlopt, - const char *statusDir, - virDomainObjPtr obj, - virCapsPtr caps) G_GNUC_WARN_UNUSED_RESULT; +int virDomainDefSave(virDomainDefPtr def, + virDomainXMLOptionPtr xmlopt, + virCapsPtr caps, + const char *configDir) + G_GNUC_WARN_UNUSED_RESULT + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) + ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4); + +int virDomainObjSave(virDomainObjPtr obj, + virDomainXMLOptionPtr xmlopt, + virCapsPtr caps, + const char *statusDir) + G_GNUC_WARN_UNUSED_RESULT + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) + ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4); typedef void (*virDomainLoadConfigNotify)(virDomainObjPtr dom, int newDomain, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 0864de030b..7bacf02f0c 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -309,6 +309,7 @@ virDomainDefParseFile; virDomainDefParseNode; virDomainDefParseString; virDomainDefPostParse; +virDomainDefSave; virDomainDefSetMemoryTotal; virDomainDefSetVcpus; virDomainDefSetVcpusMax; @@ -526,6 +527,7 @@ virDomainObjNew; virDomainObjParseFile; virDomainObjParseNode; virDomainObjRemoveTransientDef; +virDomainObjSave; virDomainObjSetDefTransient; virDomainObjSetMetadata; virDomainObjSetState; @@ -555,9 +557,6 @@ virDomainRNGModelTypeToString; virDomainRNGRemove; virDomainRunningReasonTypeFromString; virDomainRunningReasonTypeToString; -virDomainSaveConfig; -virDomainSaveStatus; -virDomainSaveXML; virDomainSCSIDriveAddressIsUsed; virDomainSeclabelTypeFromString; virDomainSeclabelTypeToString; diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 90ea2c9ece..9b9b17b173 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -1463,7 +1463,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, VIR_DOMAIN_PAUSED_USER); } - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, cfg->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->caps, cfg->stateDir) < 0) goto destroy_dom; if (virAtomicIntInc(&driver->nactive) == 1 && driver->inhibitCallback) diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 44a74e8779..b885cf0d00 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -453,7 +453,7 @@ libxlReconnectDomain(virDomainObjPtr vm, libxlReconnectNotifyNets(vm->def); - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, cfg->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->caps, cfg->stateDir) < 0) VIR_WARN("Cannot update XML for running Xen guest %s", vm->def->name); /* now that we know it's reconnected call the hook if present */ @@ -1188,7 +1188,7 @@ libxlDomainSuspend(virDomainPtr dom) VIR_DOMAIN_EVENT_SUSPENDED_PAUSED); } - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, cfg->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->caps, cfg->stateDir) < 0) goto endjob; ret = 0; @@ -1242,7 +1242,7 @@ libxlDomainResume(virDomainPtr dom) VIR_DOMAIN_EVENT_RESUMED_UNPAUSED); } - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, cfg->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->caps, cfg->stateDir) < 0) goto endjob; ret = 0; @@ -1667,7 +1667,7 @@ libxlDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem, virDomainDefSetMemoryTotal(persistentDef, newmem); if (persistentDef->mem.cur_balloon > newmem) persistentDef->mem.cur_balloon = newmem; - ret = virDomainSaveConfig(cfg->configDir, cfg->caps, persistentDef); + ret = virDomainDefSave(persistentDef, driver->xmlopt, cfg->caps, cfg->configDir); goto endjob; } @@ -1700,7 +1700,7 @@ libxlDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem, if (flags & VIR_DOMAIN_MEM_CONFIG) { sa_assert(persistentDef); persistentDef->mem.cur_balloon = newmem; - ret = virDomainSaveConfig(cfg->configDir, cfg->caps, persistentDef); + ret = virDomainDefSave(persistentDef, driver->xmlopt, cfg->caps, cfg->configDir); goto endjob; } } @@ -2351,13 +2351,13 @@ libxlDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus, ret = 0; if (flags & VIR_DOMAIN_VCPU_LIVE) { - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, cfg->caps) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, cfg->caps, cfg->stateDir) < 0) { VIR_WARN("Unable to save status on vm %s after changing vcpus", vm->def->name); } } if (flags & VIR_DOMAIN_VCPU_CONFIG) { - if (virDomainSaveConfig(cfg->configDir, cfg->caps, def) < 0) { + if (virDomainDefSave(def, driver->xmlopt, cfg->caps, cfg->configDir) < 0) { VIR_WARN("Unable to save configuration of vm %s after changing vcpus", vm->def->name); } @@ -2507,9 +2507,9 @@ libxlDomainPinVcpuFlags(virDomainPtr dom, unsigned int vcpu, ret = 0; if (flags & VIR_DOMAIN_AFFECT_LIVE) { - ret = virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, cfg->caps); + ret = virDomainObjSave(vm, driver->xmlopt, cfg->caps, cfg->stateDir); } else if (flags & VIR_DOMAIN_AFFECT_CONFIG) { - ret = virDomainSaveConfig(cfg->configDir, cfg->caps, targetDef); + ret = virDomainDefSave(targetDef, driver->xmlopt, cfg->caps, cfg->configDir); } endjob: @@ -2869,9 +2869,8 @@ libxlDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flag vm->persistent = 1; - if (virDomainSaveConfig(cfg->configDir, - cfg->caps, - vm->newDef ? vm->newDef : vm->def) < 0) { + if (virDomainDefSave(vm->newDef ? vm->newDef : vm->def, + driver->xmlopt, cfg->caps, cfg->configDir) < 0) { virDomainObjListRemove(driver->domains, vm); goto cleanup; } @@ -4145,7 +4144,7 @@ libxlDomainAttachDeviceFlags(virDomainPtr dom, const char *xml, * update domain status forcibly because the domain status may be * changed even if we attach the device failed. */ - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, cfg->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->caps, cfg->stateDir) < 0) goto endjob; } @@ -4153,7 +4152,7 @@ libxlDomainAttachDeviceFlags(virDomainPtr dom, const char *xml, /* Finally, if no error until here, we can save config. */ if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) { - ret = virDomainSaveConfig(cfg->configDir, cfg->caps, vmdef); + ret = virDomainDefSave(vmdef, driver->xmlopt, cfg->caps, cfg->configDir); if (!ret) { virDomainObjAssignDef(vm, vmdef, false, NULL); vmdef = NULL; @@ -4236,7 +4235,7 @@ libxlDomainDetachDeviceFlags(virDomainPtr dom, const char *xml, * update domain status forcibly because the domain status may be * changed even if we attach the device failed. */ - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, cfg->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->caps, cfg->stateDir) < 0) goto endjob; } @@ -4244,7 +4243,7 @@ libxlDomainDetachDeviceFlags(virDomainPtr dom, const char *xml, /* Finally, if no error until here, we can save config. */ if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) { - ret = virDomainSaveConfig(cfg->configDir, cfg->caps, vmdef); + ret = virDomainDefSave(vmdef, driver->xmlopt, cfg->caps, cfg->configDir); if (!ret) { virDomainObjAssignDef(vm, vmdef, false, NULL); vmdef = NULL; @@ -4324,13 +4323,13 @@ libxlDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml, * update domain status forcibly because the domain status may be * changed even if we attach the device failed. */ - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, cfg->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->caps, cfg->stateDir) < 0) ret = -1; } /* Finally, if no error until here, we can save config. */ if (!ret && (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG)) { - ret = virDomainSaveConfig(cfg->configDir, cfg->caps, vmdef); + ret = virDomainDefSave(vmdef, driver->xmlopt, cfg->caps, cfg->configDir); if (!ret) { virDomainObjAssignDef(vm, vmdef, false, NULL); vmdef = NULL; diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c index 3f87c35b1c..65ff8271a7 100644 --- a/src/libxl/libxl_migration.c +++ b/src/libxl/libxl_migration.c @@ -1326,7 +1326,7 @@ libxlDomainMigrationDstFinish(virConnectPtr dconn, driver->xmlopt, vm, NULL))) goto cleanup; - if (virDomainSaveConfig(cfg->configDir, cfg->caps, vmdef) < 0) + if (virDomainDefSave(vmdef, driver->xmlopt, cfg->caps, cfg->configDir) < 0) goto cleanup; event = virDomainEventLifecycleNewFromObj(vm, @@ -1338,7 +1338,7 @@ libxlDomainMigrationDstFinish(virConnectPtr dconn, event = NULL; } - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, cfg->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->caps, cfg->stateDir) < 0) goto cleanup; dom = virGetDomain(dconn, vm->def->name, vm->def->uuid, vm->def->id); @@ -1388,7 +1388,7 @@ libxlDomainMigrationSrcConfirm(libxlDriverPrivatePtr driver, VIR_DOMAIN_PAUSED_MIGRATION); event = virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_SUSPENDED, VIR_DOMAIN_EVENT_SUSPENDED_MIGRATED); - ignore_value(virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, cfg->caps)); + ignore_value(virDomainObjSave(vm, driver->xmlopt, cfg->caps, cfg->stateDir)); } goto cleanup; } diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 826bf074e3..cb0ab6e0d5 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -443,8 +443,8 @@ lxcDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) def = NULL; vm->persistent = 1; - if (virDomainSaveConfig(cfg->configDir, driver->caps, - vm->newDef ? vm->newDef : vm->def) < 0) { + if (virDomainDefSave(vm->newDef ? vm->newDef : vm->def, + driver->xmlopt, driver->caps, cfg->configDir) < 0) { virDomainObjListRemove(driver->domains, vm); goto cleanup; } @@ -677,8 +677,8 @@ static int lxcDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem, virDomainDefSetMemoryTotal(persistentDef, newmem); if (persistentDef->mem.cur_balloon > newmem) persistentDef->mem.cur_balloon = newmem; - if (virDomainSaveConfig(cfg->configDir, driver->caps, - persistentDef) < 0) + if (virDomainDefSave(persistentDef, + driver->xmlopt, driver->caps, cfg->configDir) < 0) goto endjob; } } else { @@ -705,14 +705,14 @@ static int lxcDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem, } def->mem.cur_balloon = newmem; - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) goto endjob; } if (persistentDef) { persistentDef->mem.cur_balloon = newmem; - if (virDomainSaveConfig(cfg->configDir, driver->caps, - persistentDef) < 0) + if (virDomainDefSave(persistentDef, + driver->xmlopt, driver->caps, cfg->configDir) < 0) goto endjob; } } @@ -857,11 +857,11 @@ lxcDomainSetMemoryParameters(virDomainPtr dom, #undef VIR_SET_MEM_PARAMETER if (def && - virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) goto endjob; if (persistentDef && - virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef) < 0) + virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, cfg->configDir) < 0) goto endjob; /* QEMU and LXC implementations are identical */ @@ -1967,12 +1967,13 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr dom, } } - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) goto endjob; if (persistentDef) { - rc = virDomainSaveConfig(cfg->configDir, driver->caps, persistentDefCopy); + rc = virDomainDefSave(persistentDefCopy, driver->xmlopt, driver->caps, + cfg->configDir); if (rc < 0) goto endjob; @@ -2672,7 +2673,7 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, } } - if (virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef) < 0) + if (virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, cfg->configDir) < 0) ret = -1; } @@ -3029,7 +3030,7 @@ static int lxcDomainSuspend(virDomainPtr dom) VIR_DOMAIN_EVENT_SUSPENDED_PAUSED); } - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) goto endjob; ret = 0; @@ -3086,7 +3087,7 @@ static int lxcDomainResume(virDomainPtr dom) VIR_DOMAIN_EVENT_RESUMED_UNPAUSED); } - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) goto endjob; ret = 0; @@ -4743,7 +4744,7 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom, * changed even if we failed to attach the device. For example, * a new controller may be created. */ - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { ret = -1; goto endjob; } @@ -4751,7 +4752,7 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom, /* Finally, if no error until here, we can save config. */ if (flags & VIR_DOMAIN_AFFECT_CONFIG) { - ret = virDomainSaveConfig(cfg->configDir, driver->caps, vmdef); + ret = virDomainDefSave(vmdef, driver->xmlopt, driver->caps, cfg->configDir); if (!ret) { virDomainObjAssignDef(vm, vmdef, false, NULL); vmdef = NULL; @@ -4830,7 +4831,7 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom, if (lxcDomainUpdateDeviceConfig(vmdef, dev) < 0) goto endjob; - if (virDomainSaveConfig(cfg->configDir, driver->caps, vmdef) < 0) + if (virDomainDefSave(vmdef, driver->xmlopt, driver->caps, cfg->configDir) < 0) goto endjob; virDomainObjAssignDef(vm, vmdef, false, NULL); @@ -4917,7 +4918,7 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom, * changed even if we failed to attach the device. For example, * a new controller may be created. */ - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { ret = -1; goto endjob; } @@ -4925,7 +4926,7 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom, /* Finally, if no error until here, we can save config. */ if (flags & VIR_DOMAIN_AFFECT_CONFIG) { - ret = virDomainSaveConfig(cfg->configDir, driver->caps, vmdef); + ret = virDomainDefSave(vmdef, driver->xmlopt, driver->caps, cfg->configDir); if (!ret) { virDomainObjAssignDef(vm, vmdef, false, NULL); vmdef = NULL; diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 9b62a93096..cae8bbacb5 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -790,7 +790,7 @@ static void virLXCProcessMonitorInitNotify(virLXCMonitorPtr mon G_GNUC_UNUSED, } virDomainAuditInit(vm, initpid, inode); - if (virDomainSaveStatus(lxc_driver->xmlopt, cfg->stateDir, vm, lxc_driver->caps) < 0) + if (virDomainObjSave(vm, lxc_driver->xmlopt, lxc_driver->caps, cfg->stateDir) < 0) VIR_WARN("Cannot update XML with PID for LXC %s", vm->def->name); virObjectUnlock(vm); @@ -1457,7 +1457,7 @@ int virLXCProcessStart(virConnectPtr conn, /* Write domain status to disk for the controller to * read when it starts */ - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) goto cleanup; /* Allow the child to exec the controller */ @@ -1696,7 +1696,7 @@ virLXCProcessReconnectDomain(virDomainObjPtr vm, virLXCProcessReconnectNotifyNets(vm->def); - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) VIR_WARN("Cannot update XML for running LXC guest %s", vm->def->name); /* now that we know it's reconnected call the hook if present */ diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 939e6fc01c..ad08e29bb3 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -8168,7 +8168,7 @@ qemuDomainObjSaveStatus(virQEMUDriverPtr driver, virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); if (virDomainObjIsActive(obj)) { - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, obj, driver->caps) < 0) + if (virDomainObjSave(obj, driver->xmlopt, driver->caps, cfg->stateDir) < 0) VIR_WARN("Failed to save status on vm %s", obj->def->name); } @@ -8200,7 +8200,7 @@ qemuDomainSaveConfig(virDomainObjPtr obj) cfg = virQEMUDriverGetConfig(driver); - if (virDomainSaveConfig(cfg->configDir, driver->caps, def) < 0) + if (virDomainDefSave(def, driver->xmlopt, driver->caps, cfg->configDir) < 0) VIR_WARN("Failed to save config of vm %s", obj->def->name); } @@ -10073,7 +10073,7 @@ qemuDomainSetFakeReboot(virQEMUDriverPtr driver, priv->fakeReboot = value; - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) VIR_WARN("Failed to save status on vm %s", vm->def->name); cleanup: diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 594b683b80..b274542c3e 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1860,7 +1860,7 @@ static int qemuDomainSuspend(virDomainPtr dom) if (qemuProcessStopCPUs(driver, vm, reason, QEMU_ASYNC_JOB_NONE) < 0) goto endjob; } - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) goto endjob; ret = 0; @@ -1918,7 +1918,7 @@ static int qemuDomainResume(virDomainPtr dom) goto endjob; } } - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) goto endjob; ret = 0; @@ -2360,8 +2360,8 @@ static int qemuDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem, if (persistentDef->mem.cur_balloon > newmem) persistentDef->mem.cur_balloon = newmem; - ret = virDomainSaveConfig(cfg->configDir, driver->caps, - persistentDef); + ret = virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, + cfg->configDir); goto endjob; } @@ -2400,8 +2400,8 @@ static int qemuDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem, if (persistentDef) { persistentDef->mem.cur_balloon = newmem; - ret = virDomainSaveConfig(cfg->configDir, driver->caps, - persistentDef); + ret = virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, + cfg->configDir); goto endjob; } } @@ -2475,7 +2475,7 @@ static int qemuDomainSetMemoryStatsPeriod(virDomainPtr dom, int period, } def->memballoon->period = period; - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) goto endjob; } @@ -2487,7 +2487,7 @@ static int qemuDomainSetMemoryStatsPeriod(virDomainPtr dom, int period, goto endjob; } persistentDef->memballoon->period = period; - ret = virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef); + ret = virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, cfg->configDir); goto endjob; } @@ -4201,7 +4201,7 @@ processGuestPanicEvent(virQEMUDriverPtr driver, virObjectEventStateQueue(driver->domainEventState, event); - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { VIR_WARN("Unable to save status on vm %s after state change", vm->def->name); } @@ -4281,7 +4281,7 @@ processDeviceDeletedEvent(virQEMUDriverPtr driver, goto endjob; } - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) VIR_WARN("unable to save domain status after removing device %s", devAlias); @@ -4649,7 +4649,7 @@ processSerialChangedEvent(virQEMUDriverPtr driver, dev.data.chr->state = newstate; - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) VIR_WARN("unable to save status of domain %s after updating state of " "channel %s", vm->def->name, devAlias); @@ -4975,7 +4975,7 @@ qemuDomainSetVcpusMax(virQEMUDriverPtr driver, if (virDomainDefSetVcpusMax(persistentDef, nvcpus, driver->xmlopt) < 0) return -1; - if (virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef) < 0) + if (virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, cfg->configDir) < 0) return -1; return 0; @@ -5104,7 +5104,7 @@ qemuDomainPinVcpuLive(virDomainObjPtr vm, vcpuinfo->cpumask = tmpmap; tmpmap = NULL; - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) goto cleanup; if (g_snprintf(paramField, VIR_TYPED_PARAM_FIELD_LENGTH, @@ -5187,7 +5187,7 @@ qemuDomainPinVcpuFlags(virDomainPtr dom, vcpuinfo->cpumask = pcpumap; pcpumap = NULL; - ret = virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef); + ret = virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, cfg->configDir); goto endjob; } @@ -5319,7 +5319,7 @@ qemuDomainPinEmulator(virDomainPtr dom, if (!(def->cputune.emulatorpin = virBitmapNewCopy(pcpumap))) goto endjob; - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) goto endjob; str = virBitmapFormat(pcpumap); @@ -5339,7 +5339,7 @@ qemuDomainPinEmulator(virDomainPtr dom, if (!(persistentDef->cputune.emulatorpin = virBitmapNewCopy(pcpumap))) goto endjob; - ret = virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef); + ret = virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, cfg->configDir); goto endjob; } @@ -5799,7 +5799,7 @@ qemuDomainPinIOThread(virDomainPtr dom, if (virProcessSetAffinity(iothrid->thread_id, pcpumap) < 0) goto endjob; - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) goto endjob; if (g_snprintf(paramField, VIR_TYPED_PARAM_FIELD_LENGTH, @@ -5832,7 +5832,7 @@ qemuDomainPinIOThread(virDomainPtr dom, iothrid->cpumask = cpumask; iothrid->autofill = false; - ret = virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef); + ret = virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, cfg->configDir); goto endjob; } @@ -6250,7 +6250,7 @@ qemuDomainChgIOThread(virQEMUDriverPtr driver, } - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) goto endjob; } @@ -6282,8 +6282,8 @@ qemuDomainChgIOThread(virQEMUDriverPtr driver, break; } - if (virDomainSaveConfig(cfg->configDir, driver->caps, - persistentDef) < 0) + if (virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, + cfg->configDir) < 0) goto endjob; } @@ -6894,7 +6894,7 @@ qemuDomainSaveImageStartVM(virConnectPtr conn, "%s", _("failed to resume domain")); goto cleanup; } - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { VIR_WARN("Failed to save status on vm %s", vm->def->name); goto cleanup; } @@ -7608,8 +7608,8 @@ qemuDomainDefineXMLFlags(virConnectPtr conn, vm->persistent = 1; - if (virDomainSaveConfig(cfg->configDir, driver->caps, - vm->newDef ? vm->newDef : vm->def) < 0) { + if (virDomainDefSave(vm->newDef ? vm->newDef : vm->def, + driver->xmlopt, driver->caps, cfg->configDir) < 0) { if (oldDef) { /* There is backup so this VM was defined before. * Just restore the backup. */ @@ -8674,13 +8674,13 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObjPtr vm, * changed even if we failed to attach the device. For example, * a new controller may be created. */ - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) goto cleanup; } /* Finally, if no error until here, we can save config. */ if (flags & VIR_DOMAIN_AFFECT_CONFIG) { - if (virDomainSaveConfig(cfg->configDir, driver->caps, vmdef) < 0) + if (virDomainDefSave(vmdef, driver->xmlopt, driver->caps, cfg->configDir) < 0) goto cleanup; virDomainObjAssignDef(vm, vmdef, false, NULL); @@ -8827,7 +8827,7 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom, * changed even if we failed to attach the device. For example, * a new controller may be created. */ - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { ret = -1; goto endjob; } @@ -8835,7 +8835,7 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom, /* Finally, if no error until here, we can save config. */ if (flags & VIR_DOMAIN_AFFECT_CONFIG) { - ret = virDomainSaveConfig(cfg->configDir, driver->caps, vmdef); + ret = virDomainDefSave(vmdef, driver->xmlopt, driver->caps, cfg->configDir); if (!ret) { virDomainObjAssignDef(vm, vmdef, false, NULL); vmdef = NULL; @@ -8925,13 +8925,13 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriverPtr driver, * changed even if we failed to attach the device. For example, * a new controller may be created. */ - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, caps, cfg->stateDir) < 0) goto cleanup; } /* Finally, if no error until here, we can save config. */ if (flags & VIR_DOMAIN_AFFECT_CONFIG) { - if (virDomainSaveConfig(cfg->configDir, caps, vmdef) < 0) + if (virDomainDefSave(vmdef, driver->xmlopt, caps, cfg->configDir) < 0) goto cleanup; virDomainObjAssignDef(vm, vmdef, false, NULL); @@ -9009,7 +9009,7 @@ qemuDomainDetachDeviceAliasLiveAndConfig(virQEMUDriverPtr driver, } if (vmdef) { - if (virDomainSaveConfig(cfg->configDir, caps, vmdef) < 0) + if (virDomainDefSave(vmdef, driver->xmlopt, caps, cfg->configDir) < 0) goto cleanup; virDomainObjAssignDef(vm, vmdef, false, NULL); vmdef = NULL; @@ -9591,7 +9591,7 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, } } - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) goto endjob; } if (ret < 0) @@ -9626,7 +9626,7 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, } } - if (virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef) < 0) + if (virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, cfg->configDir) < 0) ret = -1; } @@ -9856,11 +9856,11 @@ qemuDomainSetMemoryParameters(virDomainPtr dom, #undef VIR_SET_MEM_PARAMETER if (def && - virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) goto endjob; if (persistentDef && - virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef) < 0) + virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, cfg->configDir) < 0) goto endjob; /* QEMU and LXC implementations are identical */ @@ -10123,7 +10123,7 @@ qemuDomainSetNumaParameters(virDomainPtr dom, -1, mode, nodeset) < 0) goto endjob; - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) goto endjob; } @@ -10134,7 +10134,7 @@ qemuDomainSetNumaParameters(virDomainPtr dom, -1, mode, nodeset) < 0) goto endjob; - if (virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef) < 0) + if (virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, cfg->configDir) < 0) goto endjob; } @@ -10316,7 +10316,7 @@ qemuDomainSetPerfEvents(virDomainPtr dom, VIR_TRISTATE_BOOL_YES : VIR_TRISTATE_BOOL_NO; } - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) goto endjob; } @@ -10330,7 +10330,7 @@ qemuDomainSetPerfEvents(virDomainPtr dom, VIR_TRISTATE_BOOL_YES : VIR_TRISTATE_BOOL_NO; } - if (virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef) < 0) + if (virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, cfg->configDir) < 0) goto endjob; } @@ -10792,7 +10792,7 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom, } } - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, caps, cfg->stateDir) < 0) goto endjob; if (eventNparams) { @@ -10802,7 +10802,8 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom, } if (persistentDef) { - rc = virDomainSaveConfig(cfg->configDir, driver->caps, persistentDefCopy); + rc = virDomainDefSave(persistentDefCopy, driver->xmlopt, caps, + cfg->configDir); if (rc < 0) goto endjob; @@ -11640,7 +11641,7 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom, goto endjob; } - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) goto endjob; } @@ -11665,7 +11666,7 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom, } } - if (virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef) < 0) + if (virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, cfg->configDir) < 0) goto endjob; } @@ -14626,7 +14627,7 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver, defdisk->src = g_steal_pointer(&newsrc); } - if (virDomainSaveConfig(cfg->configDir, driver->caps, vm->def) < 0) + if (virDomainDefSave(vm->def, driver->xmlopt, driver->caps, cfg->configDir) < 0) goto cleanup; ret = 0; @@ -15563,9 +15564,9 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver, if (rc < 0) goto cleanup; - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0 || - (vm->newDef && virDomainSaveConfig(cfg->configDir, driver->caps, - vm->newDef) < 0)) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0 || + (vm->newDef && virDomainDefSave(vm->newDef, driver->xmlopt, driver->caps, + cfg->configDir) < 0)) goto cleanup; ret = 0; @@ -16861,8 +16862,8 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, } } if (ret == 0 && defined && vm->persistent && - !(ret = virDomainSaveConfig(cfg->configDir, driver->caps, - vm->newDef ? vm->newDef : vm->def))) { + !(ret = virDomainDefSave(vm->newDef ? vm->newDef : vm->def, + driver->xmlopt, driver->caps, cfg->configDir))) { detail = VIR_DOMAIN_EVENT_DEFINED_FROM_SNAPSHOT; virObjectEventStateQueue(driver->domainEventState, virDomainEventLifecycleNewFromObj(vm, @@ -17667,7 +17668,7 @@ qemuDomainBlockJobAbort(virDomainPtr dom, job->state = QEMU_BLOCKJOB_STATE_ABORTING; } - ignore_value(virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps)); + ignore_value(virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir)); if (!async) { qemuBlockJobUpdate(vm, job, QEMU_ASYNC_JOB_NONE); @@ -19245,8 +19246,7 @@ qemuDomainSetBlockIoTune(virDomainPtr dom, if (virDomainDiskSetBlockIOTune(disk, &info) < 0) goto endjob; - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, - vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) goto endjob; if (eventNparams) { @@ -19271,8 +19271,8 @@ qemuDomainSetBlockIoTune(virDomainPtr dom, if (virDomainDiskSetBlockIOTune(conf_disk, &info) < 0) goto endjob; - if (virDomainSaveConfig(cfg->configDir, driver->caps, - persistentDef) < 0) + if (virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, + cfg->configDir) < 0) goto endjob; } @@ -21873,7 +21873,7 @@ qemuDomainRenameCallback(virDomainObjPtr vm, vm->def->name = new_dom_name; new_dom_name = NULL; - if (virDomainSaveConfig(cfg->configDir, driver->caps, vm->def) < 0) + if (virDomainDefSave(vm->def, driver->xmlopt, driver->caps, cfg->configDir) < 0) goto rollback; if (virFileExists(old_dom_cfg_file) && @@ -22397,16 +22397,15 @@ qemuDomainSetLifecycleAction(virDomainPtr dom, qemuDomainModifyLifecycleAction(def, type, action); - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, - vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) goto endjob; } if (persistentDef) { qemuDomainModifyLifecycleAction(persistentDef, type, action); - if (virDomainSaveConfig(cfg->configDir, driver->caps, - persistentDef) < 0) + if (virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, + cfg->configDir) < 0) goto endjob; } @@ -22701,7 +22700,7 @@ qemuDomainAgentSetResponseTimeout(virDomainPtr dom, QEMU_DOMAIN_PRIVATE(vm)->agentTimeout = timeout; if (virDomainObjIsActive(vm) && - virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) goto cleanup; ret = 0; diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index d4eacaf099..da32a845e1 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -5980,7 +5980,7 @@ qemuDomainHotplugDelVcpu(virQEMUDriverPtr driver, qemuDomainVcpuPersistOrder(vm->def); - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) goto cleanup; ret = 0; @@ -6055,7 +6055,7 @@ qemuDomainHotplugAddVcpu(virQEMUDriverPtr driver, qemuDomainVcpuPersistOrder(vm->def); - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) goto cleanup; ret = 0; @@ -6313,7 +6313,7 @@ qemuDomainSetVcpusInternal(virQEMUDriverPtr driver, if (persistentDef) { qemuDomainSetVcpusConfig(persistentDef, nvcpus, hotpluggable); - if (virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef) < 0) + if (virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, cfg->configDir) < 0) goto cleanup; } @@ -6513,7 +6513,7 @@ qemuDomainSetVcpuInternal(virQEMUDriverPtr driver, if (persistentDef) { qemuDomainSetVcpuConfig(persistentDef, map, state); - if (virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef) < 0) + if (virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, cfg->configDir) < 0) goto cleanup; } diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index dabdda2715..e9470cc62c 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -1008,7 +1008,7 @@ qemuMigrationSrcNBDStorageCopy(virQEMUDriverPtr driver, tlsAlias, flags) < 0) return -1; - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { VIR_WARN("Failed to save status on vm %s", vm->def->name); return -1; } @@ -2991,7 +2991,7 @@ qemuMigrationSrcConfirmPhase(virQEMUDriverPtr driver, qemuMigrationParamsReset(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT, priv->job.migParams, priv->job.apiFlags); - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) VIR_WARN("Failed to save status on vm %s", vm->def->name); } @@ -4842,7 +4842,7 @@ qemuMigrationDstPersist(virQEMUDriverPtr driver, priv->qemuCaps))) goto error; - if (virDomainSaveConfig(cfg->configDir, driver->caps, vmdef) < 0 && + if (virDomainDefSave(vmdef, driver->xmlopt, driver->caps, cfg->configDir) < 0 && !ignoreSaveError) goto error; @@ -5095,7 +5095,7 @@ qemuMigrationDstFinish(virQEMUDriverPtr driver, } if (virDomainObjIsActive(vm) && - virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) VIR_WARN("Failed to save status on vm %s", vm->def->name); /* Guest is successfully running, so cancel previous auto destroy */ diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 480fcd075d..79ac5f3d95 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -411,7 +411,7 @@ qemuProcessHandleReset(qemuMonitorPtr mon G_GNUC_UNUSED, if (priv->agent) qemuAgentNotifyEvent(priv->agent, QEMU_AGENT_EVENT_RESET); - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) VIR_WARN("Failed to save status on vm %s", vm->def->name); if (vm->def->onReboot == VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY || @@ -493,7 +493,7 @@ qemuProcessFakeReboot(void *opaque) goto endjob; } - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { VIR_WARN("Unable to save status on vm %s after state change", vm->def->name); } @@ -614,7 +614,7 @@ qemuProcessHandleShutdown(qemuMonitorPtr mon G_GNUC_UNUSED, VIR_DOMAIN_EVENT_SHUTDOWN, detail); - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { VIR_WARN("Unable to save status on vm %s after state change", vm->def->name); } @@ -680,7 +680,7 @@ qemuProcessHandleStop(qemuMonitorPtr mon G_GNUC_UNUSED, VIR_WARN("Unable to release lease on %s", vm->def->name); VIR_DEBUG("Preserving lock state '%s'", NULLSTR(priv->lockState)); - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { VIR_WARN("Unable to save status on vm %s after state change", vm->def->name); } @@ -726,7 +726,7 @@ qemuProcessHandleResume(qemuMonitorPtr mon G_GNUC_UNUSED, VIR_DOMAIN_EVENT_RESUMED, eventDetail); - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { VIR_WARN("Unable to save status on vm %s after state change", vm->def->name); } @@ -769,7 +769,7 @@ qemuProcessHandleRTCChange(qemuMonitorPtr mon G_GNUC_UNUSED, offset += vm->def->clock.data.variable.adjustment0; vm->def->clock.data.variable.adjustment = offset; - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) VIR_WARN("unable to save domain status with RTC change"); } @@ -812,7 +812,7 @@ qemuProcessHandleWatchdog(qemuMonitorPtr mon G_GNUC_UNUSED, VIR_WARN("Unable to release lease on %s", vm->def->name); VIR_DEBUG("Preserving lock state '%s'", NULLSTR(priv->lockState)); - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { VIR_WARN("Unable to save status on vm %s after watchdog event", vm->def->name); } @@ -904,7 +904,7 @@ qemuProcessHandleIOError(qemuMonitorPtr mon G_GNUC_UNUSED, VIR_WARN("Unable to release lease on %s", vm->def->name); VIR_DEBUG("Preserving lock state '%s'", NULLSTR(priv->lockState)); - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) VIR_WARN("Unable to save status on vm %s after IO error", vm->def->name); } virObjectUnlock(vm); @@ -1149,7 +1149,7 @@ qemuProcessHandleTrayChange(qemuMonitorPtr mon G_GNUC_UNUSED, else if (reason == VIR_DOMAIN_EVENT_TRAY_CHANGE_CLOSE) disk->tray_status = VIR_DOMAIN_DISK_TRAY_CLOSED; - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { VIR_WARN("Unable to save status on vm %s after tray moved event", vm->def->name); } @@ -1189,7 +1189,7 @@ qemuProcessHandlePMWakeup(qemuMonitorPtr mon G_GNUC_UNUSED, VIR_DOMAIN_EVENT_STARTED, VIR_DOMAIN_EVENT_STARTED_WAKEUP); - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { VIR_WARN("Unable to save status on vm %s after wakeup event", vm->def->name); } @@ -1227,7 +1227,7 @@ qemuProcessHandlePMSuspend(qemuMonitorPtr mon G_GNUC_UNUSED, VIR_DOMAIN_EVENT_PMSUSPENDED, VIR_DOMAIN_EVENT_PMSUSPENDED_MEMORY); - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { VIR_WARN("Unable to save status on vm %s after suspend event", vm->def->name); } @@ -1261,7 +1261,7 @@ qemuProcessHandleBalloonChange(qemuMonitorPtr mon G_GNUC_UNUSED, vm->def->mem.cur_balloon, actual); vm->def->mem.cur_balloon = actual; - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) VIR_WARN("unable to save domain status with balloon change"); virObjectUnlock(vm); @@ -1296,7 +1296,7 @@ qemuProcessHandlePMSuspendDisk(qemuMonitorPtr mon G_GNUC_UNUSED, VIR_DOMAIN_EVENT_PMSUSPENDED, VIR_DOMAIN_EVENT_PMSUSPENDED_DISK); - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { VIR_WARN("Unable to save status on vm %s after suspend event", vm->def->name); } @@ -1669,7 +1669,7 @@ qemuProcessHandleMigrationStatus(qemuMonitorPtr mon G_GNUC_UNUSED, VIR_DOMAIN_EVENT_SUSPENDED, VIR_DOMAIN_EVENT_SUSPENDED_POSTCOPY); - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { VIR_WARN("Unable to save status on vm %s after state change", vm->def->name); } @@ -3105,7 +3105,7 @@ qemuProcessUpdateVideoRamSize(virQEMUDriverPtr driver, return -1; cfg = virQEMUDriverGetConfig(driver); - ret = virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps); + ret = virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir); virObjectUnref(cfg); return ret; @@ -6860,7 +6860,7 @@ qemuProcessLaunch(virConnectPtr conn, } VIR_DEBUG("Writing early domain status to disk"); - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) goto cleanup; VIR_DEBUG("Waiting for handshake from child"); @@ -7118,7 +7118,7 @@ qemuProcessFinishStartup(virQEMUDriverPtr driver, } VIR_DEBUG("Writing domain status to disk"); - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) + if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) goto cleanup; if (qemuProcessStartHook(driver, vm, @@ -8221,7 +8221,7 @@ qemuProcessReconnect(void *opaque) } /* update domain state XML with possibly updated state in virDomainObj */ - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, obj, driver->caps) < 0) + if (virDomainObjSave(obj, driver->xmlopt, driver->caps, cfg->stateDir) < 0) goto error; /* Run an hook to allow admins to do some magic */ -- 2.23.0

Moving their instance parameter to be the first one, and give consistent ordering of other parameters across all functions. Ensure that the xml options are passed into both functions in prep for future work. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/bhyve/bhyve_driver.c | 4 +-- src/conf/checkpoint_conf.c | 4 +-- src/conf/domain_conf.c | 39 ++++++++++++---------- src/conf/domain_conf.h | 28 +++++++++++----- src/conf/snapshot_conf.c | 10 +++--- src/esx/esx_driver.c | 4 +-- src/hyperv/hyperv_driver.c | 3 +- src/libxl/libxl_domain.c | 12 +++---- src/libxl/libxl_driver.c | 8 ++--- src/libxl/libxl_migration.c | 4 +-- src/lxc/lxc_driver.c | 4 +-- src/lxc/lxc_process.c | 12 +++---- src/openvz/openvz_conf.c | 55 +++++++++++++++++++++++++++++++ src/openvz/openvz_conf.h | 1 + src/openvz/openvz_driver.c | 56 ++------------------------------ src/phyp/phyp_driver.c | 2 +- src/qemu/qemu_domain.c | 5 ++- src/security/security_apparmor.c | 2 +- src/test/test_driver.c | 8 +++-- src/vbox/vbox_common.c | 2 +- src/vmware/vmware_driver.c | 4 +-- src/vz/vz_driver.c | 4 +-- tests/Makefile.am | 3 +- tests/lxcconf2xmltest.c | 2 +- tests/openvzutilstest.c | 4 ++- tests/qemuhotplugtest.c | 6 ++-- tests/qemuxml2xmltest.c | 2 +- tests/testutils.c | 2 +- tests/vmx2xmltest.c | 2 +- tests/xlconfigtest.c | 3 +- tests/xmconfigtest.c | 2 +- 31 files changed, 161 insertions(+), 136 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index b8a206bb1e..18b5d1e950 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -495,7 +495,7 @@ bhyveDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) if (!caps) goto cleanup; - ret = virDomainDefFormat(vm->def, caps, + ret = virDomainDefFormat(vm->def, privconn->xmlopt, caps, virDomainDefFormatConvertXMLFlags(flags)); virObjectUnref(caps); @@ -1583,7 +1583,7 @@ bhyveConnectDomainXMLFromNative(virConnectPtr conn, if (def == NULL) goto cleanup; - xml = virDomainDefFormat(def, capabilities, 0); + xml = virDomainDefFormat(def, privconn->xmlopt, capabilities, 0); cleanup: virObjectUnref(capabilities); diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c index 36076c13df..cb2d83796c 100644 --- a/src/conf/checkpoint_conf.c +++ b/src/conf/checkpoint_conf.c @@ -489,8 +489,8 @@ virDomainCheckpointDefFormatInternal(virBufferPtr buf, } if (!(flags & VIR_DOMAIN_CHECKPOINT_FORMAT_NO_DOMAIN) && - virDomainDefFormatInternal(def->parent.dom, caps, domainflags, buf, - xmlopt) < 0) + virDomainDefFormatInternal(def->parent.dom, xmlopt, + caps, buf, domainflags) < 0) goto error; virBufferAdjustIndent(buf, -2); diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 87bbb2d263..781bf9d2d4 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -23600,8 +23600,8 @@ virDomainDefCheckABIStabilityFlags(virDomainDefPtr src, error: virErrorPreserveLast(&err); - strSrc = virDomainDefFormat(src, NULL, 0); - strDst = virDomainDefFormat(dst, NULL, 0); + strSrc = virDomainDefFormat(src, xmlopt, NULL, 0); + strDst = virDomainDefFormat(dst, xmlopt, NULL, 0); VIR_DEBUG("XMLs that failed stability check were: src=\"%s\", dst=\"%s\"", NULLSTR(strSrc), NULLSTR(strDst)); @@ -28286,13 +28286,13 @@ virDomainDefFormatFeatures(virBufferPtr buf, int virDomainDefFormatInternal(virDomainDefPtr def, + virDomainXMLOptionPtr xmlopt, virCapsPtr caps, - unsigned int flags, virBufferPtr buf, - virDomainXMLOptionPtr xmlopt) + unsigned int flags) { - return virDomainDefFormatInternalSetRootName(def, caps, flags, buf, - xmlopt, "domain"); + return virDomainDefFormatInternalSetRootName(def, xmlopt, caps, buf, + "domain", flags); } @@ -28302,11 +28302,11 @@ virDomainDefFormatInternal(virDomainDefPtr def, * Return -1 on failure. */ int virDomainDefFormatInternalSetRootName(virDomainDefPtr def, + virDomainXMLOptionPtr xmlopt, virCapsPtr caps, - unsigned int flags, virBufferPtr buf, - virDomainXMLOptionPtr xmlopt, - const char *rootname) + const char *rootname, + unsigned int flags) { unsigned char *uuid; char uuidstr[VIR_UUID_STRING_BUFLEN]; @@ -28843,12 +28843,15 @@ unsigned int virDomainDefFormatConvertXMLFlags(unsigned int flags) char * -virDomainDefFormat(virDomainDefPtr def, virCapsPtr caps, unsigned int flags) +virDomainDefFormat(virDomainDefPtr def, + virDomainXMLOptionPtr xmlopt, + virCapsPtr caps, + unsigned int flags) { virBuffer buf = VIR_BUFFER_INITIALIZER; virCheckFlags(VIR_DOMAIN_DEF_FORMAT_COMMON_FLAGS, NULL); - if (virDomainDefFormatInternal(def, caps, flags, &buf, NULL) < 0) + if (virDomainDefFormatInternal(def, xmlopt, caps, &buf, flags) < 0) return NULL; return virBufferContentAndReset(&buf); @@ -28856,8 +28859,8 @@ virDomainDefFormat(virDomainDefPtr def, virCapsPtr caps, unsigned int flags) char * -virDomainObjFormat(virDomainXMLOptionPtr xmlopt, - virDomainObjPtr obj, +virDomainObjFormat(virDomainObjPtr obj, + virDomainXMLOptionPtr xmlopt, virCapsPtr caps, unsigned int flags) { @@ -28883,7 +28886,7 @@ virDomainObjFormat(virDomainXMLOptionPtr xmlopt, xmlopt->privateData.format(&buf, obj) < 0) goto error; - if (virDomainDefFormatInternal(obj->def, caps, flags, &buf, xmlopt) < 0) + if (virDomainDefFormatInternal(obj->def, xmlopt, caps, &buf, flags) < 0) goto error; virBufferAdjustIndent(&buf, -2); @@ -29043,13 +29046,13 @@ virDomainDefSaveXML(virDomainDefPtr def, int virDomainDefSave(virDomainDefPtr def, - virDomainXMLOptionPtr xmlopt G_GNUC_UNUSED, + virDomainXMLOptionPtr xmlopt, virCapsPtr caps, const char *configDir) { g_autofree char *xml = NULL; - if (!(xml = virDomainDefFormat(def, caps, VIR_DOMAIN_DEF_FORMAT_SECURE))) + if (!(xml = virDomainDefFormat(def, xmlopt, caps, VIR_DOMAIN_DEF_FORMAT_SECURE))) return -1; return virDomainDefSaveXML(def, configDir, xml); @@ -29069,7 +29072,7 @@ virDomainObjSave(virDomainObjPtr obj, g_autofree char *xml = NULL; - if (!(xml = virDomainObjFormat(xmlopt, obj, caps, flags))) + if (!(xml = virDomainObjFormat(obj, xmlopt, caps, flags))) return -1; return virDomainDefSaveXML(obj->def, statusDir, xml); @@ -29373,7 +29376,7 @@ virDomainDefCopy(virDomainDefPtr src, format_flags |= VIR_DOMAIN_DEF_FORMAT_INACTIVE | VIR_DOMAIN_DEF_FORMAT_MIGRATABLE; /* Easiest to clone via a round-trip through XML. */ - if (!(xml = virDomainDefFormat(src, caps, format_flags))) + if (!(xml = virDomainDefFormat(src, xmlopt, caps, format_flags))) return NULL; return virDomainDefParseString(xml, caps, xmlopt, parseOpaque, parse_flags); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index d1c375092e..f7a611d5ef 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3101,23 +3101,33 @@ void virDomainIOThreadIDDel(virDomainDefPtr def, unsigned int iothread_id); unsigned int virDomainDefFormatConvertXMLFlags(unsigned int flags); char *virDomainDefFormat(virDomainDefPtr def, + virDomainXMLOptionPtr xmlopt, virCapsPtr caps, - unsigned int flags); -char *virDomainObjFormat(virDomainXMLOptionPtr xmlopt, - virDomainObjPtr obj, + unsigned int flags) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) + ATTRIBUTE_NONNULL(3); +char *virDomainObjFormat(virDomainObjPtr obj, + virDomainXMLOptionPtr xmlopt, virCapsPtr caps, - unsigned int flags); + unsigned int flags) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) + ATTRIBUTE_NONNULL(3); int virDomainDefFormatInternal(virDomainDefPtr def, + virDomainXMLOptionPtr xmlopt, virCapsPtr caps, - unsigned int flags, virBufferPtr buf, - virDomainXMLOptionPtr xmlopt); + unsigned int flags) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) + ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4); int virDomainDefFormatInternalSetRootName(virDomainDefPtr def, + virDomainXMLOptionPtr xmlopt, virCapsPtr caps, - unsigned int flags, virBufferPtr buf, - virDomainXMLOptionPtr xmlopt, - const char *rootname); + const char *rootname, + unsigned int flags) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) + ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4) + ATTRIBUTE_NONNULL(5); int virDomainDiskSourceFormat(virBufferPtr buf, virStorageSourcePtr src, diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index a0509041be..0bf7d497e4 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -891,8 +891,8 @@ virDomainSnapshotDefFormatInternal(virBufferPtr buf, } if (def->parent.dom) { - if (virDomainDefFormatInternal(def->parent.dom, caps, domainflags, buf, - xmlopt) < 0) + if (virDomainDefFormatInternal(def->parent.dom, xmlopt, + caps, buf, domainflags) < 0) goto error; } else if (uuidstr) { virBufferAddLit(buf, "<domain>\n"); @@ -903,9 +903,9 @@ virDomainSnapshotDefFormatInternal(virBufferPtr buf, } if (def->parent.inactiveDom) { - if (virDomainDefFormatInternalSetRootName(def->parent.inactiveDom, caps, - domainflags, buf, xmlopt, - "inactiveDomain") < 0) + if (virDomainDefFormatInternalSetRootName(def->parent.inactiveDom, xmlopt, + caps, buf, "inactiveDomain", + domainflags) < 0) goto error; } diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index f8ee6db75f..81ff502769 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -2648,7 +2648,7 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) if (powerState != esxVI_VirtualMachinePowerState_PoweredOff) def->id = id; - xml = virDomainDefFormat(def, priv->caps, + xml = virDomainDefFormat(def, priv->xmlopt, priv->caps, virDomainDefFormatConvertXMLFlags(flags)); } @@ -2706,7 +2706,7 @@ esxConnectDomainXMLFromNative(virConnectPtr conn, const char *nativeFormat, def = virVMXParseConfig(&ctx, priv->xmlopt, priv->caps, nativeConfig); if (def) - xml = virDomainDefFormat(def, priv->caps, + xml = virDomainDefFormat(def, priv->xmlopt, priv->caps, VIR_DOMAIN_DEF_FORMAT_INACTIVE); virDomainDefFree(def); diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 3a2f6602bc..ff9370d728 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -886,7 +886,8 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) /* FIXME: devices section is totally missing */ - xml = virDomainDefFormat(def, NULL, + /* XXX xmlopts must be non-NULL */ + xml = virDomainDefFormat(def, NULL, NULL, virDomainDefFormatConvertXMLFlags(flags)); cleanup: diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 9b9b17b173..19905442c1 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -844,7 +844,7 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver, /* now that we know it's stopped call the hook if present */ if (virHookPresent(VIR_HOOK_DRIVER_LIBXL)) { - char *xml = virDomainDefFormat(vm->def, cfg->caps, 0); + char *xml = virDomainDefFormat(vm->def, driver->xmlopt, cfg->caps, 0); /* we can't stop the operation even if the script raised an error */ ignore_value(virHookCall(VIR_HOOK_DRIVER_LIBXL, vm->def->name, @@ -913,7 +913,7 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver, /* The "release" hook cleans up additional resources */ if (virHookPresent(VIR_HOOK_DRIVER_LIBXL)) { - char *xml = virDomainDefFormat(vm->def, cfg->caps, 0); + char *xml = virDomainDefFormat(vm->def, driver->xmlopt, cfg->caps, 0); /* we can't stop the operation even if the script raised an error */ ignore_value(virHookCall(VIR_HOOK_DRIVER_LIBXL, vm->def->name, @@ -1320,7 +1320,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver, /* Run an early hook to set-up missing devices */ if (virHookPresent(VIR_HOOK_DRIVER_LIBXL)) { - char *xml = virDomainDefFormat(vm->def, cfg->caps, 0); + char *xml = virDomainDefFormat(vm->def, driver->xmlopt, cfg->caps, 0); int hookret; hookret = virHookCall(VIR_HOOK_DRIVER_LIBXL, vm->def->name, @@ -1358,7 +1358,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver, /* now that we know it is about to start call the hook if present */ if (virHookPresent(VIR_HOOK_DRIVER_LIBXL)) { - char *xml = virDomainDefFormat(vm->def, cfg->caps, 0); + char *xml = virDomainDefFormat(vm->def, driver->xmlopt, cfg->caps, 0); int hookret; hookret = virHookCall(VIR_HOOK_DRIVER_LIBXL, vm->def->name, @@ -1443,7 +1443,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver, libxlDomainCreateChannelPTY(vm->def, cfg->ctx); #endif - if ((dom_xml = virDomainDefFormat(vm->def, cfg->caps, 0)) == NULL) + if ((dom_xml = virDomainDefFormat(vm->def, driver->xmlopt, cfg->caps, 0)) == NULL) goto destroy_dom; if (libxl_userdata_store(cfg->ctx, domid, "libvirt-xml", @@ -1471,7 +1471,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver, /* finally we can call the 'started' hook script if any */ if (virHookPresent(VIR_HOOK_DRIVER_LIBXL)) { - char *xml = virDomainDefFormat(vm->def, cfg->caps, 0); + char *xml = virDomainDefFormat(vm->def, driver->xmlopt, cfg->caps, 0); int hookret; hookret = virHookCall(VIR_HOOK_DRIVER_LIBXL, vm->def->name, diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index b885cf0d00..dc0d9b58f3 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -459,7 +459,7 @@ libxlReconnectDomain(virDomainObjPtr vm, /* now that we know it's reconnected call the hook if present */ if (virHookPresent(VIR_HOOK_DRIVER_LIBXL) && STRNEQ("Domain-0", vm->def->name)) { - char *xml = virDomainDefFormat(vm->def, cfg->caps, 0); + char *xml = virDomainDefFormat(vm->def, driver->xmlopt, cfg->caps, 0); int hookret; /* we can't stop the operation even if the script raised an error */ @@ -1828,7 +1828,7 @@ libxlDoDomainSave(libxlDriverPrivatePtr driver, goto cleanup; } - if ((xml = virDomainDefFormat(vm->def, cfg->caps, 0)) == NULL) + if ((xml = virDomainDefFormat(vm->def, driver->xmlopt, cfg->caps, 0)) == NULL) goto cleanup; xml_len = strlen(xml) + 1; @@ -2652,7 +2652,7 @@ libxlDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) else def = vm->def; - ret = virDomainDefFormat(def, cfg->caps, + ret = virDomainDefFormat(def, driver->xmlopt, cfg->caps, virDomainDefFormatConvertXMLFlags(flags)); cleanup: @@ -2703,7 +2703,7 @@ libxlConnectDomainXMLFromNative(virConnectPtr conn, goto cleanup; } - xml = virDomainDefFormat(def, cfg->caps, VIR_DOMAIN_DEF_FORMAT_INACTIVE); + xml = virDomainDefFormat(def, driver->xmlopt, cfg->caps, VIR_DOMAIN_DEF_FORMAT_INACTIVE); cleanup: virDomainDefFree(def); diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c index 65ff8271a7..25a58f8018 100644 --- a/src/libxl/libxl_migration.c +++ b/src/libxl/libxl_migration.c @@ -420,7 +420,7 @@ libxlDomainMigrationSrcBegin(virConnectPtr conn, if (!libxlDomainMigrationIsAllowed(def)) goto endjob; - xml = virDomainDefFormat(def, cfg->caps, VIR_DOMAIN_DEF_FORMAT_SECURE); + xml = virDomainDefFormat(def, driver->xmlopt, cfg->caps, VIR_DOMAIN_DEF_FORMAT_SECURE); /* Valid xml means success! EndJob in the confirm phase */ if (xml) goto cleanup; @@ -494,7 +494,7 @@ libxlDomainMigrationPrepareAny(virConnectPtr dconn, char *xml; int hookret; - if (!(xml = virDomainDefFormat(*def, cfg->caps, + if (!(xml = virDomainDefFormat(*def, driver->xmlopt, cfg->caps, VIR_DOMAIN_XML_SECURE | VIR_DOMAIN_XML_MIGRATABLE))) return -1; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index cb0ab6e0d5..6c12543274 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -987,7 +987,7 @@ static char *lxcDomainGetXMLDesc(virDomainPtr dom, ret = virDomainDefFormat((flags & VIR_DOMAIN_XML_INACTIVE) && vm->newDef ? vm->newDef : vm->def, - driver->caps, + driver->xmlopt, driver->caps, virDomainDefFormatConvertXMLFlags(flags)); cleanup: @@ -1019,7 +1019,7 @@ static char *lxcConnectDomainXMLFromNative(virConnectPtr conn, if (!(def = lxcParseConfigString(nativeConfig, caps, driver->xmlopt))) goto cleanup; - xml = virDomainDefFormat(def, caps, 0); + xml = virDomainDefFormat(def, driver->xmlopt, caps, 0); cleanup: virObjectUnref(caps); diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index cae8bbacb5..c1b8b6aa09 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -171,7 +171,7 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver, /* now that we know it's stopped call the hook if present */ if (virHookPresent(VIR_HOOK_DRIVER_LXC)) { - char *xml = virDomainDefFormat(vm->def, driver->caps, 0); + char *xml = virDomainDefFormat(vm->def, driver->xmlopt, driver->caps, 0); /* we can't stop the operation even if the script raised an error */ virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name, @@ -248,7 +248,7 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver, /* The "release" hook cleans up additional resources */ if (virHookPresent(VIR_HOOK_DRIVER_LXC)) { - char *xml = virDomainDefFormat(vm->def, driver->caps, 0); + char *xml = virDomainDefFormat(vm->def, driver->xmlopt, driver->caps, 0); /* we can't stop the operation even if the script raised an error */ virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name, @@ -1271,7 +1271,7 @@ int virLXCProcessStart(virConnectPtr conn, /* Run an early hook to set-up missing devices */ if (virHookPresent(VIR_HOOK_DRIVER_LXC)) { - char *xml = virDomainDefFormat(vm->def, driver->caps, 0); + char *xml = virDomainDefFormat(vm->def, driver->xmlopt, driver->caps, 0); int hookret; hookret = virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name, @@ -1379,7 +1379,7 @@ int virLXCProcessStart(virConnectPtr conn, /* now that we know it is about to start call the hook if present */ if (virHookPresent(VIR_HOOK_DRIVER_LXC)) { - char *xml = virDomainDefFormat(vm->def, driver->caps, 0); + char *xml = virDomainDefFormat(vm->def, driver->xmlopt, driver->caps, 0); int hookret; hookret = virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name, @@ -1521,7 +1521,7 @@ int virLXCProcessStart(virConnectPtr conn, /* finally we can call the 'started' hook script if any */ if (virHookPresent(VIR_HOOK_DRIVER_LXC)) { - char *xml = virDomainDefFormat(vm->def, driver->caps, 0); + char *xml = virDomainDefFormat(vm->def, driver->xmlopt, driver->caps, 0); int hookret; hookret = virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name, @@ -1701,7 +1701,7 @@ virLXCProcessReconnectDomain(virDomainObjPtr vm, /* now that we know it's reconnected call the hook if present */ if (virHookPresent(VIR_HOOK_DRIVER_LXC)) { - char *xml = virDomainDefFormat(vm->def, driver->caps, 0); + char *xml = virDomainDefFormat(vm->def, driver->xmlopt, driver->caps, 0); int hookret; /* we can't stop the operation even if the script raised an error */ diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index 7676656af1..8a05aa0504 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -1078,3 +1078,58 @@ int openvzGetVEID(const char *name) _("Failed to parse vzlist output")); return -1; } + + +static int +openvzDomainDefPostParse(virDomainDefPtr def, + virCapsPtr caps G_GNUC_UNUSED, + unsigned int parseFlags G_GNUC_UNUSED, + void *opaque G_GNUC_UNUSED, + void *parseOpaque G_GNUC_UNUSED) +{ + /* fill the init path */ + if (def->os.type == VIR_DOMAIN_OSTYPE_EXE && !def->os.init) + def->os.init = g_strdup("/sbin/init"); + + return 0; +} + + +static int +openvzDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, + const virDomainDef *def G_GNUC_UNUSED, + virCapsPtr caps G_GNUC_UNUSED, + unsigned int parseFlags G_GNUC_UNUSED, + void *opaque G_GNUC_UNUSED, + void *parseOpaque G_GNUC_UNUSED) +{ + if (dev->type == VIR_DOMAIN_DEVICE_CHR && + dev->data.chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE && + dev->data.chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_NONE) + dev->data.chr->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_OPENVZ; + + /* forbid capabilities mode hostdev in this kind of hypervisor */ + if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV && + dev->data.hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("hostdev mode 'capabilities' is not " + "supported in %s"), + virDomainVirtTypeToString(def->virtType)); + return -1; + } + + return 0; +} + + +virDomainDefParserConfig openvzDomainDefParserConfig = { + .domainPostParseCallback = openvzDomainDefPostParse, + .devicesPostParseCallback = openvzDomainDeviceDefPostParse, + .features = VIR_DOMAIN_DEF_FEATURE_NAME_SLASH, +}; + +virDomainXMLOptionPtr openvzXMLOption(void) +{ + return virDomainXMLOptionNew(&openvzDomainDefParserConfig, + NULL, NULL, NULL, NULL); +} diff --git a/src/openvz/openvz_conf.h b/src/openvz/openvz_conf.h index cd42d697ce..6463c1704a 100644 --- a/src/openvz/openvz_conf.h +++ b/src/openvz/openvz_conf.h @@ -63,3 +63,4 @@ int strtoI(const char *str); int openvzSetDefinedUUID(int vpsid, unsigned char *uuid); int openvzGetVEID(const char *name); int openvzReadNetworkConf(virDomainDefPtr def, int veid); +virDomainXMLOptionPtr openvzXMLOption(void); diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index e07b3b302d..e479ebf58d 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -110,55 +110,6 @@ openvzDomObjFromDomain(struct openvz_driver *driver, } -static int -openvzDomainDefPostParse(virDomainDefPtr def, - virCapsPtr caps G_GNUC_UNUSED, - unsigned int parseFlags G_GNUC_UNUSED, - void *opaque G_GNUC_UNUSED, - void *parseOpaque G_GNUC_UNUSED) -{ - /* fill the init path */ - if (def->os.type == VIR_DOMAIN_OSTYPE_EXE && !def->os.init) - def->os.init = g_strdup("/sbin/init"); - - return 0; -} - - -static int -openvzDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, - const virDomainDef *def G_GNUC_UNUSED, - virCapsPtr caps G_GNUC_UNUSED, - unsigned int parseFlags G_GNUC_UNUSED, - void *opaque G_GNUC_UNUSED, - void *parseOpaque G_GNUC_UNUSED) -{ - if (dev->type == VIR_DOMAIN_DEVICE_CHR && - dev->data.chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE && - dev->data.chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_NONE) - dev->data.chr->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_OPENVZ; - - /* forbid capabilities mode hostdev in this kind of hypervisor */ - if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV && - dev->data.hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("hostdev mode 'capabilities' is not " - "supported in %s"), - virDomainVirtTypeToString(def->virtType)); - return -1; - } - - return 0; -} - - -virDomainDefParserConfig openvzDomainDefParserConfig = { - .domainPostParseCallback = openvzDomainDefPostParse, - .devicesPostParseCallback = openvzDomainDeviceDefPostParse, - .features = VIR_DOMAIN_DEF_FEATURE_NAME_SLASH, -}; - - /* generate arguments to create OpenVZ container return -1 - error 0 - OK @@ -522,7 +473,7 @@ static char *openvzDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { if (!(vm = openvzDomObjFromDomain(driver, dom->uuid))) return NULL; - ret = virDomainDefFormat(vm->def, driver->caps, + ret = virDomainDefFormat(vm->def, driver->xmlopt, driver->caps, virDomainDefFormatConvertXMLFlags(flags)); virDomainObjEndAPI(&vm); @@ -1360,8 +1311,7 @@ static virDrvOpenStatus openvzConnectOpen(virConnectPtr conn, if (!(driver->caps = openvzCapsInit())) goto cleanup; - if (!(driver->xmlopt = virDomainXMLOptionNew(&openvzDomainDefParserConfig, - NULL, NULL, NULL, NULL))) + if (!(driver->xmlopt = openvzXMLOption())) goto cleanup; if (openvzLoadDomains(driver) < 0) @@ -2117,7 +2067,7 @@ openvzDomainMigrateBegin3Params(virDomainPtr domain, goto cleanup; } - xml = virDomainDefFormat(vm->def, driver->caps, + xml = virDomainDefFormat(vm->def, driver->xmlopt, driver->caps, VIR_DOMAIN_DEF_FORMAT_SECURE); cleanup: diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index bdfe78e035..5e00ef6448 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -3247,7 +3247,7 @@ phypDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) if (virDomainDefSetVcpus(&def, vcpus) < 0) goto err; - return virDomainDefFormat(&def, phyp_driver->caps, + return virDomainDefFormat(&def, phyp_driver->xmlopt, phyp_driver->caps, virDomainDefFormatConvertXMLFlags(flags)); err: diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index ad08e29bb3..91d5e796bb 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -9198,9 +9198,8 @@ qemuDomainDefFormatBufInternal(virQEMUDriverPtr driver, } format: - ret = virDomainDefFormatInternal(def, caps, - virDomainDefFormatConvertXMLFlags(flags), - buf, driver->xmlopt); + ret = virDomainDefFormatInternal(def, driver->xmlopt, caps, buf, + virDomainDefFormatConvertXMLFlags(flags)); cleanup: virDomainDefFree(copy); diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c index 21560b2330..6da79203d7 100644 --- a/src/security/security_apparmor.c +++ b/src/security/security_apparmor.c @@ -168,7 +168,7 @@ load_profile(virSecurityManagerPtr mgr G_GNUC_UNUSED, char *xml = NULL; virCommandPtr cmd = NULL; - xml = virDomainDefFormat(def, NULL, VIR_DOMAIN_DEF_FORMAT_SECURE); + xml = virDomainDefFormat(def, NULL, NULL, VIR_DOMAIN_DEF_FORMAT_SECURE); if (!xml) goto cleanup; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 5883722d60..e7ec537bb0 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -2177,7 +2177,8 @@ testDomainSaveImageWrite(testDriverPtr driver, int fd = -1; g_autofree char *xml = NULL; - xml = virDomainDefFormat(def, driver->caps, VIR_DOMAIN_DEF_FORMAT_SECURE); + xml = virDomainDefFormat(def, driver->xmlopt, driver->caps, + VIR_DOMAIN_DEF_FORMAT_SECURE); if (xml == NULL) { virReportSystemError(errno, @@ -2466,7 +2467,8 @@ testDomainSaveImageGetXMLDesc(virConnectPtr conn, if ((fd = testDomainSaveImageOpen(privconn, path, &def)) < 0) goto cleanup; - ret = virDomainDefFormat(def, privconn->caps, VIR_DOMAIN_DEF_FORMAT_SECURE); + ret = virDomainDefFormat(def, privconn->xmlopt, privconn->caps, + VIR_DOMAIN_DEF_FORMAT_SECURE); cleanup: virDomainDefFree(def); @@ -3177,7 +3179,7 @@ static char *testDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) def = (flags & VIR_DOMAIN_XML_INACTIVE) && privdom->newDef ? privdom->newDef : privdom->def; - ret = virDomainDefFormat(def, privconn->caps, + ret = virDomainDefFormat(def, privconn->xmlopt, privconn->caps, virDomainDefFormatConvertXMLFlags(flags)); virDomainObjEndAPI(&privdom); diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index de98dc5c84..0d22c94e06 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -4126,7 +4126,7 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) /* dump USB devices/filters if active */ vboxHostDeviceGetXMLDesc(data, def, machine); - ret = virDomainDefFormat(def, data->caps, + ret = virDomainDefFormat(def, data->xmlopt, data->caps, virDomainDefFormatConvertXMLFlags(flags)); cleanup: diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index 83974531d5..c0071fc18c 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -935,7 +935,7 @@ vmwareDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) if (!(vm = vmwareDomObjFromDomain(driver, dom->uuid))) return NULL; - ret = virDomainDefFormat(vm->def, driver->caps, + ret = virDomainDefFormat(vm->def, driver->xmlopt, driver->caps, virDomainDefFormatConvertXMLFlags(flags)); virDomainObjEndAPI(&vm); @@ -968,7 +968,7 @@ vmwareConnectDomainXMLFromNative(virConnectPtr conn, const char *nativeFormat, def = virVMXParseConfig(&ctx, driver->xmlopt, driver->caps, nativeConfig); if (def != NULL) - xml = virDomainDefFormat(def, driver->caps, + xml = virDomainDefFormat(def, driver->xmlopt, driver->caps, VIR_DOMAIN_DEF_FORMAT_INACTIVE); virDomainDefFree(def); diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 6b925653d5..1166b77b2c 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -728,7 +728,7 @@ vzDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) def = (flags & VIR_DOMAIN_XML_INACTIVE) && dom->newDef ? dom->newDef : dom->def; - ret = virDomainDefFormat(def, privconn->driver->caps, flags); + ret = virDomainDefFormat(def, driver->xmlopt, privconn->driver->caps, flags); cleanup: virDomainObjEndAPI(&dom); @@ -2872,7 +2872,7 @@ vzDomainMigrateBeginStep(virDomainObjPtr dom, | VZ_MIGRATION_COOKIE_DOMAIN_NAME) < 0) return NULL; - return virDomainDefFormat(dom->def, driver->caps, + return virDomainDefFormat(dom->def, driver->xmlopt, driver->caps, VIR_DOMAIN_XML_MIGRATABLE); } diff --git a/tests/Makefile.am b/tests/Makefile.am index cbe8e86224..465c176ffd 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -747,7 +747,8 @@ if WITH_OPENVZ openvzutilstest_SOURCES = \ openvzutilstest.c \ testutils.c testutils.h -openvzutilstest_LDADD = $(LDADDS) +openvzutilstest_LDADD = $(LDADDS) \ + ../src/libvirt_driver_openvz.la else ! WITH_OPENVZ EXTRA_DIST += openvzutilstest.c endif ! WITH_OPENVZ diff --git a/tests/lxcconf2xmltest.c b/tests/lxcconf2xmltest.c index c52c6e7fd7..7adc23be9f 100644 --- a/tests/lxcconf2xmltest.c +++ b/tests/lxcconf2xmltest.c @@ -42,7 +42,7 @@ testCompareXMLToConfigFiles(const char *xmlfile, if (testSanitizeDef(vmdef) < 0) goto fail; - if (!(actualxml = virDomainDefFormat(vmdef, caps, 0))) + if (!(actualxml = virDomainDefFormat(vmdef, xmlopt, caps, 0))) goto fail; if (virTestCompareToFile(actualxml, xmlfile) < 0) diff --git a/tests/openvzutilstest.c b/tests/openvzutilstest.c index 83969197c6..f43867ddc9 100644 --- a/tests/openvzutilstest.c +++ b/tests/openvzutilstest.c @@ -98,6 +98,7 @@ testReadNetworkConf(const void *data G_GNUC_UNUSED) " </interface>\n" " </devices>\n" "</domain>\n"; + virDomainXMLOptionPtr xmlopt = openvzXMLOption(); if (!(def = virDomainDefNew())) goto cleanup; @@ -112,7 +113,7 @@ testReadNetworkConf(const void *data G_GNUC_UNUSED) goto cleanup; } - actual = virDomainDefFormat(def, NULL, VIR_DOMAIN_DEF_FORMAT_INACTIVE); + actual = virDomainDefFormat(def, xmlopt, NULL, VIR_DOMAIN_DEF_FORMAT_INACTIVE); if (actual == NULL) { fprintf(stderr, "ERROR: %s\n", virGetLastErrorMessage()); @@ -127,6 +128,7 @@ testReadNetworkConf(const void *data G_GNUC_UNUSED) result = 0; cleanup: + virObjectUnref(xmlopt); VIR_FREE(actual); virDomainDefFree(def); diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c index 7278a6a6ba..9fbc1e1a64 100644 --- a/tests/qemuhotplugtest.c +++ b/tests/qemuhotplugtest.c @@ -200,7 +200,7 @@ testQemuHotplugCheckResult(virDomainObjPtr vm, char *actual; int ret; - actual = virDomainDefFormat(vm->def, driver.caps, + actual = virDomainDefFormat(vm->def, driver.xmlopt, driver.caps, VIR_DOMAIN_DEF_FORMAT_SECURE); if (!actual) return -1; @@ -466,7 +466,7 @@ testQemuHotplugCpuFinalize(struct testQemuHotplugCpuData *data) char *configXML = NULL; if (data->file_xml_res_live) { - if (!(activeXML = virDomainDefFormat(data->vm->def, driver.caps, + if (!(activeXML = virDomainDefFormat(data->vm->def, driver.xmlopt, driver.caps, VIR_DOMAIN_DEF_FORMAT_SECURE))) goto cleanup; @@ -475,7 +475,7 @@ testQemuHotplugCpuFinalize(struct testQemuHotplugCpuData *data) } if (data->file_xml_res_conf) { - if (!(configXML = virDomainDefFormat(data->vm->newDef, driver.caps, + if (!(configXML = virDomainDefFormat(data->vm->newDef, driver.xmlopt, driver.caps, VIR_DOMAIN_DEF_FORMAT_SECURE | VIR_DOMAIN_DEF_FORMAT_INACTIVE))) goto cleanup; diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 8b43f35f06..a8f7dd4e1b 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -68,7 +68,7 @@ testCompareStatusXMLToXMLFiles(const void *opaque) goto cleanup; } - if (!(actual = virDomainObjFormat(driver.xmlopt, obj, NULL, + if (!(actual = virDomainObjFormat(obj, driver.xmlopt, NULL, VIR_DOMAIN_DEF_FORMAT_SECURE | VIR_DOMAIN_DEF_FORMAT_STATUS | VIR_DOMAIN_DEF_FORMAT_ACTUAL_NET | diff --git a/tests/testutils.c b/tests/testutils.c index 387ba55908..ffcb56ca86 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -1140,7 +1140,7 @@ testCompareDomXML2XMLFiles(virCapsPtr caps, virDomainXMLOptionPtr xmlopt, goto out; } - if (!(actual = virDomainDefFormat(def, caps, format_flags))) { + if (!(actual = virDomainDefFormat(def, xmlopt, caps, format_flags))) { result = TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_FORMAT; goto out; } diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index ad7b3360c3..72ee2a38c8 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -84,7 +84,7 @@ testCompareFiles(const char *vmx, const char *xml) goto cleanup; } - if (!(formatted = virDomainDefFormat(def, caps, + if (!(formatted = virDomainDefFormat(def, xmlopt, caps, VIR_DOMAIN_DEF_FORMAT_SECURE))) goto cleanup; diff --git a/tests/xlconfigtest.c b/tests/xlconfigtest.c index 5a094e3b0e..890d8bf2b4 100644 --- a/tests/xlconfigtest.c +++ b/tests/xlconfigtest.c @@ -146,7 +146,8 @@ testCompareFormatXML(const char *xlcfg, const char *xml, bool replaceVars) if (!(def = xenParseXL(conf, caps, xmlopt))) goto fail; - if (!(gotxml = virDomainDefFormat(def, caps, VIR_DOMAIN_XML_INACTIVE | + if (!(gotxml = virDomainDefFormat(def, xmlopt, caps, + VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_SECURE))) goto fail; diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c index 82f4908a63..4a4d4192db 100644 --- a/tests/xmconfigtest.c +++ b/tests/xmconfigtest.c @@ -100,7 +100,7 @@ testCompareFormatXML(const char *xmcfg, const char *xml) if (!(def = xenParseXM(conf, caps, xmlopt))) goto fail; - if (!(gotxml = virDomainDefFormat(def, caps, VIR_DOMAIN_DEF_FORMAT_SECURE))) + if (!(gotxml = virDomainDefFormat(def, xmlopt, caps, VIR_DOMAIN_DEF_FORMAT_SECURE))) goto fail; if (virTestCompareToFile(gotxml, xml) < 0) -- 2.23.0

When parsing the guest XML we must fill in the default guest arch if it is not already present because later parts of the parsing process need this information. If no arch is specified we lookup the first guest in the capabilities data matching the os type and virt type. In most cases this will result in picking the host architecture but there are some exceptions... - The test driver is hardcoded to always use i686 arch - The VMWare/ESX drivers will always place i686 guests ahead of x86_64 guests in capabilities, so effectively they always use i686 - The QEMU driver can potentially return any arch at all depending on what combination of QEMU binaries are installed. The domain XML hardware configurations are inherently architecture specific in many places. As a result whomever/whatever created the domain XML will have had a particular architecture in mind when specifying the config. In pretty much any sensible case this arch will have been the native host architecture. i686 on x86_64 is the only sensible divergance because both these archs are compatible from a domaain XML config POV. IOW, although the QEMU driver can pick an almost arbitrary arch as its default, in the real world no application or user is likely to be relying on this default arch being anything other than native. With all this in mind, it is reasonable to change the XML parser to allow the default architecture to be passed via the domain XML options struct. If no info is explicitly given then it is safe & sane to pick the host native architecture as the default for the guest. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- docs/formatdomain.html.in | 6 +++++- src/conf/domain_conf.c | 12 +++++++++--- src/conf/domain_conf.h | 1 + src/test/test_driver.c | 1 + src/vmware/vmware_driver.c | 1 + src/vmx/vmx.c | 1 + 6 files changed, 18 insertions(+), 4 deletions(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 6df4a8b26e..d7092761c5 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -175,7 +175,11 @@ and <a id="attributeOSTypeMachine"><code>machine</code></a> referring to the machine type. The <a href="formatcaps.html">Capabilities XML</a> provides details on allowed values for - these. <span class="since">Since 0.0.1</span></dd> + these. If <code>arch</code> is omitted then for most hypervisor + drivers, the host native arch will be chosen. For the <code>test</code>, + <code>ESX</code> and <code>VMWare</code> hypervisor drivers, however, + the <code>i686</code> arch will always be chosen even on an + <code>x86_64</code> host. <span class="since">Since 0.0.1</span></dd> <dt><a id="elementLoader"><code>loader</code></a></dt> <dd>The optional <code>loader</code> tag refers to a firmware blob, which is specified by absolute path, diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 781bf9d2d4..1c2b8f26ed 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19565,6 +19565,7 @@ virDomainCachetuneDefParse(virDomainDefPtr def, static int virDomainDefParseCaps(virDomainDefPtr def, xmlXPathContextPtr ctxt, + virDomainXMLOptionPtr xmlopt, virCapsPtr caps, unsigned int flags) { @@ -19625,6 +19626,13 @@ virDomainDefParseCaps(virDomainDefPtr def, return -1; } + if (def->os.arch == VIR_ARCH_NONE) { + if (xmlopt && xmlopt->config.defArch != VIR_ARCH_NONE) + def->os.arch = xmlopt->config.defArch; + else + def->os.arch = virArchFromHost(); + } + if (!(capsdata = virCapabilitiesDomainDataLookup(caps, def->os.type, def->os.arch, def->virtType, @@ -19633,8 +19641,6 @@ virDomainDefParseCaps(virDomainDefPtr def, return -1; virResetLastError(); } else { - if (!def->os.arch) - def->os.arch = capsdata->arch; if (!def->os.machine) def->os.machine = g_strdup(capsdata->machinetype); } @@ -19792,7 +19798,7 @@ virDomainDefParseXML(xmlDocPtr xml, id = -1; def->id = (int)id; - if (virDomainDefParseCaps(def, ctxt, caps, flags) < 0) + if (virDomainDefParseCaps(def, ctxt, xmlopt, caps, flags) < 0) goto error; /* Extract domain name */ diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index f7a611d5ef..e1622f2112 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2705,6 +2705,7 @@ struct _virDomainDefParserConfig { /* data */ unsigned int features; /* virDomainDefFeatures */ unsigned char macPrefix[VIR_MAC_PREFIX_BUFLEN]; + virArch defArch; }; typedef void *(*virDomainXMLPrivateDataAllocFunc)(void *); diff --git a/src/test/test_driver.c b/src/test/test_driver.c index e7ec537bb0..f2700d90bc 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -424,6 +424,7 @@ testDriverNew(void) VIR_DOMAIN_DEF_FEATURE_USER_ALIAS | VIR_DOMAIN_DEF_FEATURE_FW_AUTOSELECT | VIR_DOMAIN_DEF_FEATURE_NET_MODEL_STRING, + .defArch = VIR_ARCH_I686, }; virDomainXMLPrivateDataCallbacks privatecb = { .alloc = testDomainObjPrivateAlloc, diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index c0071fc18c..bab4fdb82b 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -139,6 +139,7 @@ vmwareDomainDeviceDefPostParse(virDomainDeviceDefPtr dev G_GNUC_UNUSED, virDomainDefParserConfig vmwareDomainDefParserConfig = { .devicesPostParseCallback = vmwareDomainDeviceDefPostParse, .domainPostParseCallback = vmwareDomainDefPostParse, + .defArch = VIR_ARCH_I686, }; static virDomainXMLOptionPtr diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 0ccc4eefe6..c4af7b1ce9 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -556,6 +556,7 @@ static virDomainDefParserConfig virVMXDomainDefParserConfig = { .features = (VIR_DOMAIN_DEF_FEATURE_WIDE_SCSI | VIR_DOMAIN_DEF_FEATURE_NAME_SLASH | VIR_DOMAIN_DEF_FEATURE_NO_BOOT_ORDER), + .defArch = VIR_ARCH_I686, }; struct virVMXDomainDefNamespaceData { -- 2.23.0

The XML parser currently calls virCapabilitiesDomainDataLookup during parsing to find the domain capabilities matching the triple (virt type, os type, arch) This is, however, bogus with the QEMU driver as it assumes that there is an emulator known to the default driver capabilities that matches this triple. It is entirely possible for the driver to be parsing an XML file with a custom emulator path specified pointing to a binary that doesn't exist in the default driver capabilities. This will, for example be the case on a RHEL host which only installs the host native emulator to /usr/bin. The user can have built a custom QEMU for non-native arches into $HOME and wish to use that. Aside from validation, this call is also used to fill in a machine type for the guest if not otherwise specified. Again, this data may be incorrect for the QEMU driver because it is not taking account of the emulator binary that is referenced. To start fixing this, move the validation to the post-parse callbacks where more intelligent driver specific logic can be applied. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/bhyve/bhyve_domain.c | 7 ++++++- src/conf/capabilities.c | 17 +++++++++++++++++ src/conf/capabilities.h | 7 +++++++ src/conf/domain_conf.c | 19 ++----------------- src/libvirt_private.syms | 1 + src/libxl/libxl_domain.c | 7 ++++++- src/lxc/lxc_domain.c | 5 +++++ src/openvz/openvz_conf.c | 7 ++++++- src/phyp/phyp_driver.c | 9 +++++++-- src/qemu/qemu_domain.c | 19 +++++++++++++++---- src/vmware/vmware_driver.c | 9 +++++++-- src/vmx/vmx.c | 9 +++++++-- src/vz/vz_driver.c | 7 ++++++- 13 files changed, 92 insertions(+), 31 deletions(-) diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c index 7d24bb602f..575f141b53 100644 --- a/src/bhyve/bhyve_domain.c +++ b/src/bhyve/bhyve_domain.c @@ -74,11 +74,16 @@ bhyveDomainDefNeedsISAController(virDomainDefPtr def) static int bhyveDomainDefPostParse(virDomainDefPtr def, - virCapsPtr caps G_GNUC_UNUSED, + virCapsPtr caps, unsigned int parseFlags G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED, void *parseOpaque G_GNUC_UNUSED) { + if (!virCapabilitiesDomainSupported(caps, def->os.type, + def->os.arch, + def->virtType)) + return -1; + /* Add an implicit PCI root controller */ if (virDomainDefMaybeAddController(def, VIR_DOMAIN_CONTROLLER_TYPE_PCI, 0, VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT) < 0) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index ff7d265621..748dd64273 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -816,6 +816,23 @@ virCapabilitiesDomainDataLookup(virCapsPtr caps, } +bool +virCapabilitiesDomainSupported(virCapsPtr caps, + int ostype, + virArch arch, + int virttype) +{ + g_autofree virCapsDomainDataPtr capsdata = NULL; + + capsdata = virCapabilitiesDomainDataLookup(caps, ostype, + arch, + virttype, + NULL, NULL); + + return capsdata != NULL; +} + + int virCapabilitiesAddStoragePool(virCapsPtr caps, int poolType) diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index 8a7137d7eb..c39fe0de08 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -309,6 +309,13 @@ virCapabilitiesDomainDataLookup(virCapsPtr caps, const char *emulator, const char *machinetype); +bool +virCapabilitiesDomainSupported(virCapsPtr caps, + int ostype, + virArch arch, + int domaintype); + + void virCapabilitiesClearHostNUMACellCPUTopology(virCapsHostNUMACellCPUPtr cpu, size_t ncpus); diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1c2b8f26ed..6abe15f721 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19565,14 +19565,11 @@ virDomainCachetuneDefParse(virDomainDefPtr def, static int virDomainDefParseCaps(virDomainDefPtr def, xmlXPathContextPtr ctxt, - virDomainXMLOptionPtr xmlopt, - virCapsPtr caps, - unsigned int flags) + virDomainXMLOptionPtr xmlopt) { g_autofree char *virttype = NULL; g_autofree char *arch = NULL; g_autofree char *ostype = NULL; - g_autofree virCapsDomainDataPtr capsdata = NULL; virttype = virXPathString("string(./@type)", ctxt); ostype = virXPathString("string(./os/type[1])", ctxt); @@ -19633,18 +19630,6 @@ virDomainDefParseCaps(virDomainDefPtr def, def->os.arch = virArchFromHost(); } - if (!(capsdata = virCapabilitiesDomainDataLookup(caps, def->os.type, - def->os.arch, - def->virtType, - NULL, NULL))) { - if (!(flags & VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE)) - return -1; - virResetLastError(); - } else { - if (!def->os.machine) - def->os.machine = g_strdup(capsdata->machinetype); - } - return 0; } @@ -19798,7 +19783,7 @@ virDomainDefParseXML(xmlDocPtr xml, id = -1; def->id = (int)id; - if (virDomainDefParseCaps(def, ctxt, xmlopt, caps, flags) < 0) + if (virDomainDefParseCaps(def, ctxt, xmlopt) < 0) goto error; /* Extract domain name */ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 7bacf02f0c..74ca8585ee 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -54,6 +54,7 @@ virCapabilitiesAddStoragePool; virCapabilitiesAllocMachines; virCapabilitiesClearHostNUMACellCPUTopology; virCapabilitiesDomainDataLookup; +virCapabilitiesDomainSupported; virCapabilitiesFormatXML; virCapabilitiesFreeGuest; virCapabilitiesFreeMachines; diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 19905442c1..ad9424155a 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -367,11 +367,16 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, static int libxlDomainDefPostParse(virDomainDefPtr def, - virCapsPtr caps G_GNUC_UNUSED, + virCapsPtr caps, unsigned int parseFlags G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED, void *parseOpaque G_GNUC_UNUSED) { + if (!virCapabilitiesDomainSupported(caps, def->os.type, + def->os.arch, + def->virtType)) + return -1; + /* Xen PV domains always have a PV console, so add one to the domain config * via post-parse callback if not explicitly specified in the XML. */ if (def->os.type != VIR_DOMAIN_OSTYPE_HVM && def->nconsoles == 0) { diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c index 4339d305a9..b505a91c1c 100644 --- a/src/lxc/lxc_domain.c +++ b/src/lxc/lxc_domain.c @@ -356,6 +356,11 @@ virLXCDomainDefPostParse(virDomainDefPtr def, void *opaque G_GNUC_UNUSED, void *parseOpaque G_GNUC_UNUSED) { + if (!virCapabilitiesDomainSupported(caps, def->os.type, + def->os.arch, + def->virtType)) + return -1; + /* check for emulator and create a default one if needed */ if (!def->emulator && !(def->emulator = virDomainDefGetDefaultEmulator(def, caps))) diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index 8a05aa0504..de8be1ed7d 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -1082,11 +1082,16 @@ int openvzGetVEID(const char *name) static int openvzDomainDefPostParse(virDomainDefPtr def, - virCapsPtr caps G_GNUC_UNUSED, + virCapsPtr caps, unsigned int parseFlags G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED, void *parseOpaque G_GNUC_UNUSED) { + if (!virCapabilitiesDomainSupported(caps, def->os.type, + def->os.arch, + def->virtType)) + return -1; + /* fill the init path */ if (def->os.type == VIR_DOMAIN_OSTYPE_EXE && !def->os.init) def->os.init = g_strdup("/sbin/init"); diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 5e00ef6448..218d6f5b5c 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -1061,12 +1061,17 @@ openSSHSession(virConnectPtr conn, virConnectAuthPtr auth, static int -phypDomainDefPostParse(virDomainDefPtr def G_GNUC_UNUSED, - virCapsPtr caps G_GNUC_UNUSED, +phypDomainDefPostParse(virDomainDefPtr def, + virCapsPtr caps, unsigned int parseFlags G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED, void *parseOpaque G_GNUC_UNUSED) { + if (!virCapabilitiesDomainSupported(caps, def->os.type, + def->os.arch, + def->virtType)) + return -1; + return 0; } diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 91d5e796bb..b0e87a05c2 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4691,7 +4691,7 @@ qemuDomainDefPostParseBasic(virDomainDefPtr def, static int qemuDomainDefPostParse(virDomainDefPtr def, - virCapsPtr caps G_GNUC_UNUSED, + virCapsPtr caps, unsigned int parseFlags, void *opaque, void *parseOpaque) @@ -4703,6 +4703,11 @@ qemuDomainDefPostParse(virDomainDefPtr def, * with the capabilities populated. */ virQEMUCapsPtr qemuCaps = parseOpaque; + if (!virCapabilitiesDomainSupported(caps, def->os.type, + def->os.arch, + def->virtType)) + return -1; + if (def->os.bootloader || def->os.bootloaderArgs) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("bootloader is not supported by QEMU")); @@ -4710,9 +4715,15 @@ qemuDomainDefPostParse(virDomainDefPtr def, } if (!def->os.machine) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("missing machine type")); - return -1; + g_autofree virCapsDomainDataPtr capsdata = NULL; + + if (!(capsdata = virCapabilitiesDomainDataLookup(caps, def->os.type, + def->os.arch, + def->virtType, + NULL, NULL))) { + return -1; + } + def->os.machine = g_strdup(capsdata->machinetype); } qemuDomainNVRAMPathGenerate(cfg, def); diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index bab4fdb82b..be0adb1e45 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -116,12 +116,17 @@ vmwareDataFreeFunc(void *data) } static int -vmwareDomainDefPostParse(virDomainDefPtr def G_GNUC_UNUSED, - virCapsPtr caps G_GNUC_UNUSED, +vmwareDomainDefPostParse(virDomainDefPtr def, + virCapsPtr caps, unsigned int parseFlags G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED, void *parseOpaque G_GNUC_UNUSED) { + if (!virCapabilitiesDomainSupported(caps, def->os.type, + def->os.arch, + def->virtType)) + return -1; + return 0; } diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index c4af7b1ce9..c2a06daecb 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -529,12 +529,17 @@ VIR_ENUM_IMPL(virVMXControllerModelSCSI, */ static int -virVMXDomainDefPostParse(virDomainDefPtr def G_GNUC_UNUSED, - virCapsPtr caps G_GNUC_UNUSED, +virVMXDomainDefPostParse(virDomainDefPtr def, + virCapsPtr caps, unsigned int parseFlags G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED, void *parseOpaque G_GNUC_UNUSED) { + if (!virCapabilitiesDomainSupported(caps, def->os.type, + def->os.arch, + def->virtType)) + return -1; + return 0; } diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 1166b77b2c..66b15737a2 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -241,11 +241,16 @@ vzDomainDefAddDefaultInputDevices(virDomainDefPtr def) static int vzDomainDefPostParse(virDomainDefPtr def, - virCapsPtr caps G_GNUC_UNUSED, + virCapsPtr caps, unsigned int parseFlags G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED, void *parseOpaque G_GNUC_UNUSED) { + if (!virCapabilitiesDomainSupported(caps, def->os.type, + def->os.arch, + def->virtType)) + return -1; + if (vzDomainDefAddDefaultInputDevices(def) < 0) return -1; -- 2.23.0

On 12/4/19 9:20 AM, Daniel P. Berrangé wrote:
The XML parser currently calls virCapabilitiesDomainDataLookup during parsing to find the domain capabilities matching the triple
(virt type, os type, arch)
This is, however, bogus with the QEMU driver as it assumes that there is an emulator known to the default driver capabilities that matches this triple. It is entirely possible for the driver to be parsing an XML file with a custom emulator path specified pointing to a binary that doesn't exist in the default driver capabilities. This will, for example be the case on a RHEL host which only installs the host native emulator to /usr/bin. The user can have built a custom QEMU for non-native arches into $HOME and wish to use that.
Aside from validation, this call is also used to fill in a machine type for the guest if not otherwise specified. Again, this data may be incorrect for the QEMU driver because it is not taking account of the emulator binary that is referenced.
To start fixing this, move the validation to the post-parse callbacks where more intelligent driver specific logic can be applied.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/bhyve/bhyve_domain.c | 7 ++++++- src/conf/capabilities.c | 17 +++++++++++++++++ src/conf/capabilities.h | 7 +++++++ src/conf/domain_conf.c | 19 ++----------------- src/libvirt_private.syms | 1 + src/libxl/libxl_domain.c | 7 ++++++- src/lxc/lxc_domain.c | 5 +++++ src/openvz/openvz_conf.c | 7 ++++++- src/phyp/phyp_driver.c | 9 +++++++-- src/qemu/qemu_domain.c | 19 +++++++++++++++---- src/vmware/vmware_driver.c | 9 +++++++-- src/vmx/vmx.c | 9 +++++++-- src/vz/vz_driver.c | 7 ++++++- 13 files changed, 92 insertions(+), 31 deletions(-)
diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c index 7d24bb602f..575f141b53 100644 --- a/src/bhyve/bhyve_domain.c +++ b/src/bhyve/bhyve_domain.c @@ -74,11 +74,16 @@ bhyveDomainDefNeedsISAController(virDomainDefPtr def)
static int bhyveDomainDefPostParse(virDomainDefPtr def, - virCapsPtr caps G_GNUC_UNUSED, + virCapsPtr caps, unsigned int parseFlags G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED, void *parseOpaque G_GNUC_UNUSED) { + if (!virCapabilitiesDomainSupported(caps, def->os.type, + def->os.arch, + def->virtType)) + return -1; + /* Add an implicit PCI root controller */ if (virDomainDefMaybeAddController(def, VIR_DOMAIN_CONTROLLER_TYPE_PCI, 0, VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT) < 0) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index ff7d265621..748dd64273 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -816,6 +816,23 @@ virCapabilitiesDomainDataLookup(virCapsPtr caps, }
+bool +virCapabilitiesDomainSupported(virCapsPtr caps, + int ostype, + virArch arch, + int virttype) +{ + g_autofree virCapsDomainDataPtr capsdata = NULL; + + capsdata = virCapabilitiesDomainDataLookup(caps, ostype, + arch, + virttype, + NULL, NULL); + + return capsdata != NULL; +} + + int virCapabilitiesAddStoragePool(virCapsPtr caps, int poolType) diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index 8a7137d7eb..c39fe0de08 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -309,6 +309,13 @@ virCapabilitiesDomainDataLookup(virCapsPtr caps, const char *emulator, const char *machinetype);
+bool +virCapabilitiesDomainSupported(virCapsPtr caps, + int ostype, + virArch arch, + int domaintype); + + void virCapabilitiesClearHostNUMACellCPUTopology(virCapsHostNUMACellCPUPtr cpu, size_t ncpus); diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1c2b8f26ed..6abe15f721 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19565,14 +19565,11 @@ virDomainCachetuneDefParse(virDomainDefPtr def, static int virDomainDefParseCaps(virDomainDefPtr def, xmlXPathContextPtr ctxt, - virDomainXMLOptionPtr xmlopt, - virCapsPtr caps, - unsigned int flags) + virDomainXMLOptionPtr xmlopt) { g_autofree char *virttype = NULL; g_autofree char *arch = NULL; g_autofree char *ostype = NULL; - g_autofree virCapsDomainDataPtr capsdata = NULL;
virttype = virXPathString("string(./@type)", ctxt); ostype = virXPathString("string(./os/type[1])", ctxt); @@ -19633,18 +19630,6 @@ virDomainDefParseCaps(virDomainDefPtr def, def->os.arch = virArchFromHost(); }
- if (!(capsdata = virCapabilitiesDomainDataLookup(caps, def->os.type, - def->os.arch, - def->virtType, - NULL, NULL))) { - if (!(flags & VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE)) - return -1; - virResetLastError(); - } else { - if (!def->os.machine) - def->os.machine = g_strdup(capsdata->machinetype); - } - return 0; }
This series is a move in the right direction IMO, there's a couple issues though. We drop the VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE protection here, by moving the equivalent into the PostParse callback and not the Validate callback. This reintroduces the recurring problem of VMs disappearing on libvirt restart, if host capabilities change. There is VIR_DOMAIN_DEF_PARSE_ALLOW_POST_PARSE_FAIL, which has different behavior, all these error checks would need to 'return 1', but I think drivers need specially handling for this so I'm not sure if it's a simple change like that. Another issue: other drivers use the machine= setting too, libxl at least. This appears to drop filling in a default machine type for them, at least at XML parse time. Thanks, Cole

On Mon, Dec 09, 2019 at 01:21:05PM -0500, Cole Robinson wrote:
On 12/4/19 9:20 AM, Daniel P. Berrangé wrote:
The XML parser currently calls virCapabilitiesDomainDataLookup during parsing to find the domain capabilities matching the triple
(virt type, os type, arch)
This is, however, bogus with the QEMU driver as it assumes that there is an emulator known to the default driver capabilities that matches this triple. It is entirely possible for the driver to be parsing an XML file with a custom emulator path specified pointing to a binary that doesn't exist in the default driver capabilities. This will, for example be the case on a RHEL host which only installs the host native emulator to /usr/bin. The user can have built a custom QEMU for non-native arches into $HOME and wish to use that.
Aside from validation, this call is also used to fill in a machine type for the guest if not otherwise specified. Again, this data may be incorrect for the QEMU driver because it is not taking account of the emulator binary that is referenced.
To start fixing this, move the validation to the post-parse callbacks where more intelligent driver specific logic can be applied.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/bhyve/bhyve_domain.c | 7 ++++++- src/conf/capabilities.c | 17 +++++++++++++++++ src/conf/capabilities.h | 7 +++++++ src/conf/domain_conf.c | 19 ++----------------- src/libvirt_private.syms | 1 + src/libxl/libxl_domain.c | 7 ++++++- src/lxc/lxc_domain.c | 5 +++++ src/openvz/openvz_conf.c | 7 ++++++- src/phyp/phyp_driver.c | 9 +++++++-- src/qemu/qemu_domain.c | 19 +++++++++++++++---- src/vmware/vmware_driver.c | 9 +++++++-- src/vmx/vmx.c | 9 +++++++-- src/vz/vz_driver.c | 7 ++++++- 13 files changed, 92 insertions(+), 31 deletions(-)
diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c index 7d24bb602f..575f141b53 100644 --- a/src/bhyve/bhyve_domain.c +++ b/src/bhyve/bhyve_domain.c @@ -74,11 +74,16 @@ bhyveDomainDefNeedsISAController(virDomainDefPtr def)
static int bhyveDomainDefPostParse(virDomainDefPtr def, - virCapsPtr caps G_GNUC_UNUSED, + virCapsPtr caps, unsigned int parseFlags G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED, void *parseOpaque G_GNUC_UNUSED) { + if (!virCapabilitiesDomainSupported(caps, def->os.type, + def->os.arch, + def->virtType)) + return -1; + /* Add an implicit PCI root controller */ if (virDomainDefMaybeAddController(def, VIR_DOMAIN_CONTROLLER_TYPE_PCI, 0, VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT) < 0) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index ff7d265621..748dd64273 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -816,6 +816,23 @@ virCapabilitiesDomainDataLookup(virCapsPtr caps, }
+bool +virCapabilitiesDomainSupported(virCapsPtr caps, + int ostype, + virArch arch, + int virttype) +{ + g_autofree virCapsDomainDataPtr capsdata = NULL; + + capsdata = virCapabilitiesDomainDataLookup(caps, ostype, + arch, + virttype, + NULL, NULL); + + return capsdata != NULL; +} + + int virCapabilitiesAddStoragePool(virCapsPtr caps, int poolType) diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index 8a7137d7eb..c39fe0de08 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -309,6 +309,13 @@ virCapabilitiesDomainDataLookup(virCapsPtr caps, const char *emulator, const char *machinetype);
+bool +virCapabilitiesDomainSupported(virCapsPtr caps, + int ostype, + virArch arch, + int domaintype); + + void virCapabilitiesClearHostNUMACellCPUTopology(virCapsHostNUMACellCPUPtr cpu, size_t ncpus); diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1c2b8f26ed..6abe15f721 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19565,14 +19565,11 @@ virDomainCachetuneDefParse(virDomainDefPtr def, static int virDomainDefParseCaps(virDomainDefPtr def, xmlXPathContextPtr ctxt, - virDomainXMLOptionPtr xmlopt, - virCapsPtr caps, - unsigned int flags) + virDomainXMLOptionPtr xmlopt) { g_autofree char *virttype = NULL; g_autofree char *arch = NULL; g_autofree char *ostype = NULL; - g_autofree virCapsDomainDataPtr capsdata = NULL;
virttype = virXPathString("string(./@type)", ctxt); ostype = virXPathString("string(./os/type[1])", ctxt); @@ -19633,18 +19630,6 @@ virDomainDefParseCaps(virDomainDefPtr def, def->os.arch = virArchFromHost(); }
- if (!(capsdata = virCapabilitiesDomainDataLookup(caps, def->os.type, - def->os.arch, - def->virtType, - NULL, NULL))) { - if (!(flags & VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE)) - return -1; - virResetLastError(); - } else { - if (!def->os.machine) - def->os.machine = g_strdup(capsdata->machinetype); - } - return 0; }
This series is a move in the right direction IMO, there's a couple issues though.
We drop the VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE protection here, by moving the equivalent into the PostParse callback and not the Validate callback. This reintroduces the recurring problem of VMs disappearing on libvirt restart, if host capabilities change.
There is VIR_DOMAIN_DEF_PARSE_ALLOW_POST_PARSE_FAIL, which has different behavior, all these error checks would need to 'return 1', but I think drivers need specially handling for this so I'm not sure if it's a simple change like that.
Oh, I was mislead in my reading of qemuDomainDefPostParse, as I saw that it already returned error when os.machine is NULL, but I didn't realize we'd never even be calling qemuDomainDefPostParse in that case, as the virDomainDefParseCaps() willl have caused it to be skipped.
Another issue: other drivers use the machine= setting too, libxl at least. This appears to drop filling in a default machine type for them, at least at XML parse time.
I thought that was the case too, but I couln't find any functional use of def->os.machine in any of the other drivers: $ git grep os.machine | grep -v -E '(qemu|conf)/' libvirt-domain.c: * "os.machine" - the machine hardware name as a string libxl/libxl_conf.c: def->os.machine); libxl/xen_common.c: def->os.machine = g_strdup(capsdata->machinetype); vbox/vbox_common.c: VIR_DEBUG("def->os.machine %s", def->os.machine); vz/vz_sdk.c: if (def->os.machine != NULL || def->os.bootmenu != 0 || that libxl_conf.c usage is just an error message The xen_common.c usage is just when parsing XM/XL config files, so output only. The vz_sdk.c usage reports error for any non-NULL machine I guess there is a difference in that if the user does dumpxml for a libxl guest we've no longer filled in the machine. I can fix that, but it doesn't look like it'll have a functional effect. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

On Tue, Dec 10, 2019 at 10:57:44AM +0000, Daniel P. Berrangé wrote:
On Mon, Dec 09, 2019 at 01:21:05PM -0500, Cole Robinson wrote:
On 12/4/19 9:20 AM, Daniel P. Berrangé wrote:
The XML parser currently calls virCapabilitiesDomainDataLookup during parsing to find the domain capabilities matching the triple
(virt type, os type, arch)
This is, however, bogus with the QEMU driver as it assumes that there is an emulator known to the default driver capabilities that matches this triple. It is entirely possible for the driver to be parsing an XML file with a custom emulator path specified pointing to a binary that doesn't exist in the default driver capabilities. This will, for example be the case on a RHEL host which only installs the host native emulator to /usr/bin. The user can have built a custom QEMU for non-native arches into $HOME and wish to use that.
Aside from validation, this call is also used to fill in a machine type for the guest if not otherwise specified. Again, this data may be incorrect for the QEMU driver because it is not taking account of the emulator binary that is referenced.
To start fixing this, move the validation to the post-parse callbacks where more intelligent driver specific logic can be applied.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/bhyve/bhyve_domain.c | 7 ++++++- src/conf/capabilities.c | 17 +++++++++++++++++ src/conf/capabilities.h | 7 +++++++ src/conf/domain_conf.c | 19 ++----------------- src/libvirt_private.syms | 1 + src/libxl/libxl_domain.c | 7 ++++++- src/lxc/lxc_domain.c | 5 +++++ src/openvz/openvz_conf.c | 7 ++++++- src/phyp/phyp_driver.c | 9 +++++++-- src/qemu/qemu_domain.c | 19 +++++++++++++++---- src/vmware/vmware_driver.c | 9 +++++++-- src/vmx/vmx.c | 9 +++++++-- src/vz/vz_driver.c | 7 ++++++- 13 files changed, 92 insertions(+), 31 deletions(-)
diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c index 7d24bb602f..575f141b53 100644 --- a/src/bhyve/bhyve_domain.c +++ b/src/bhyve/bhyve_domain.c @@ -74,11 +74,16 @@ bhyveDomainDefNeedsISAController(virDomainDefPtr def)
static int bhyveDomainDefPostParse(virDomainDefPtr def, - virCapsPtr caps G_GNUC_UNUSED, + virCapsPtr caps, unsigned int parseFlags G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED, void *parseOpaque G_GNUC_UNUSED) { + if (!virCapabilitiesDomainSupported(caps, def->os.type, + def->os.arch, + def->virtType)) + return -1; + /* Add an implicit PCI root controller */ if (virDomainDefMaybeAddController(def, VIR_DOMAIN_CONTROLLER_TYPE_PCI, 0, VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT) < 0) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index ff7d265621..748dd64273 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -816,6 +816,23 @@ virCapabilitiesDomainDataLookup(virCapsPtr caps, }
+bool +virCapabilitiesDomainSupported(virCapsPtr caps, + int ostype, + virArch arch, + int virttype) +{ + g_autofree virCapsDomainDataPtr capsdata = NULL; + + capsdata = virCapabilitiesDomainDataLookup(caps, ostype, + arch, + virttype, + NULL, NULL); + + return capsdata != NULL; +} + + int virCapabilitiesAddStoragePool(virCapsPtr caps, int poolType) diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index 8a7137d7eb..c39fe0de08 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -309,6 +309,13 @@ virCapabilitiesDomainDataLookup(virCapsPtr caps, const char *emulator, const char *machinetype);
+bool +virCapabilitiesDomainSupported(virCapsPtr caps, + int ostype, + virArch arch, + int domaintype); + + void virCapabilitiesClearHostNUMACellCPUTopology(virCapsHostNUMACellCPUPtr cpu, size_t ncpus); diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1c2b8f26ed..6abe15f721 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19565,14 +19565,11 @@ virDomainCachetuneDefParse(virDomainDefPtr def, static int virDomainDefParseCaps(virDomainDefPtr def, xmlXPathContextPtr ctxt, - virDomainXMLOptionPtr xmlopt, - virCapsPtr caps, - unsigned int flags) + virDomainXMLOptionPtr xmlopt) { g_autofree char *virttype = NULL; g_autofree char *arch = NULL; g_autofree char *ostype = NULL; - g_autofree virCapsDomainDataPtr capsdata = NULL;
virttype = virXPathString("string(./@type)", ctxt); ostype = virXPathString("string(./os/type[1])", ctxt); @@ -19633,18 +19630,6 @@ virDomainDefParseCaps(virDomainDefPtr def, def->os.arch = virArchFromHost(); }
- if (!(capsdata = virCapabilitiesDomainDataLookup(caps, def->os.type, - def->os.arch, - def->virtType, - NULL, NULL))) { - if (!(flags & VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE)) - return -1; - virResetLastError(); - } else { - if (!def->os.machine) - def->os.machine = g_strdup(capsdata->machinetype); - } - return 0; }
This series is a move in the right direction IMO, there's a couple issues though.
We drop the VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE protection here, by moving the equivalent into the PostParse callback and not the Validate callback. This reintroduces the recurring problem of VMs disappearing on libvirt restart, if host capabilities change.
There is VIR_DOMAIN_DEF_PARSE_ALLOW_POST_PARSE_FAIL, which has different behavior, all these error checks would need to 'return 1', but I think drivers need specially handling for this so I'm not sure if it's a simple change like that.
Oh, I was mislead in my reading of qemuDomainDefPostParse, as I saw that it already returned error when os.machine is NULL, but I didn't realize we'd never even be calling qemuDomainDefPostParse in that case, as the virDomainDefParseCaps() willl have caused it to be skipped.
On looking again I realized that I did in fact know about this problem already, but I mistakenly fixed it in a later patch in this series: commit 4a4132b4625778cf80acb9c92d06351b44468ac3 Author: Daniel P. Berrangé <berrange@redhat.com> Date: Tue Dec 3 10:49:49 2019 +0000 conf: don't use passed in caps in post parse method that patch was a bit stupid though as it refetched the qemu caps. On the plus side it accidentally fixed a segv with a patch from a few weeks ago that review missed. I've sent a small fix for the immediate stupid part of my commit above. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

On 12/10/19 5:57 AM, Daniel P. Berrangé wrote:
Another issue: other drivers use the machine= setting too, libxl at least. This appears to drop filling in a default machine type for them, at least at XML parse time.
I thought that was the case too, but I couln't find any functional use of def->os.machine in any of the other drivers:
$ git grep os.machine | grep -v -E '(qemu|conf)/' libvirt-domain.c: * "os.machine" - the machine hardware name as a string libxl/libxl_conf.c: def->os.machine); libxl/xen_common.c: def->os.machine = g_strdup(capsdata->machinetype); vbox/vbox_common.c: VIR_DEBUG("def->os.machine %s", def->os.machine); vz/vz_sdk.c: if (def->os.machine != NULL || def->os.bootmenu != 0 ||
that libxl_conf.c usage is just an error message
The xen_common.c usage is just when parsing XM/XL config files, so output only.
The vz_sdk.c usage reports error for any non-NULL machine
I guess there is a difference in that if the user does dumpxml for a libxl guest we've no longer filled in the machine. I can fix that, but it doesn't look like it'll have a functional effect.
Check grep for 'xenfv' and 'xenpv', domaincapabilities does some machine value handling, and virt-manager will use the reported VM machine value and feed it back to domaincapabilities, so it could be used in a round about way. Thanks, Cole

On Tue, Dec 10, 2019 at 11:32:18AM -0500, Cole Robinson wrote:
On 12/10/19 5:57 AM, Daniel P. Berrangé wrote:
Another issue: other drivers use the machine= setting too, libxl at least. This appears to drop filling in a default machine type for them, at least at XML parse time.
I thought that was the case too, but I couln't find any functional use of def->os.machine in any of the other drivers:
$ git grep os.machine | grep -v -E '(qemu|conf)/' libvirt-domain.c: * "os.machine" - the machine hardware name as a string libxl/libxl_conf.c: def->os.machine); libxl/xen_common.c: def->os.machine = g_strdup(capsdata->machinetype); vbox/vbox_common.c: VIR_DEBUG("def->os.machine %s", def->os.machine); vz/vz_sdk.c: if (def->os.machine != NULL || def->os.bootmenu != 0 ||
that libxl_conf.c usage is just an error message
The xen_common.c usage is just when parsing XM/XL config files, so output only.
The vz_sdk.c usage reports error for any non-NULL machine
I guess there is a difference in that if the user does dumpxml for a libxl guest we've no longer filled in the machine. I can fix that, but it doesn't look like it'll have a functional effect.
Check grep for 'xenfv' and 'xenpv', domaincapabilities does some machine value handling, and virt-manager will use the reported VM machine value and feed it back to domaincapabilities, so it could be used in a round about way.
Yes, I can see the dom capabilities reports them, and apps can of coure put them in the XML they feed in, but AFAICT the libxl driver will not do anything with the values provided when defining/starting a guest Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

To enable the virCapsPtr parameter to the post parse method to be eliminated, the drivers must fetch the virCapsPtr from their own driver via the opaque parameter, or use an alternative approach to validate the parsed data. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/bhyve/bhyve_domain.c | 10 +++++-- src/esx/esx_driver.c | 2 +- src/libxl/libxl_conf.c | 3 ++- src/libxl/libxl_conf.h | 2 +- src/libxl/libxl_domain.c | 9 ++++--- src/libxl/libxl_driver.c | 2 +- src/lxc/lxc_conf.c | 3 ++- src/lxc/lxc_conf.h | 2 +- src/lxc/lxc_controller.c | 44 ++++++++++++++++++++++++------- src/lxc/lxc_domain.c | 8 ++++-- src/lxc/lxc_driver.c | 2 +- src/openvz/openvz_conf.c | 10 ++++--- src/openvz/openvz_conf.h | 2 +- src/openvz/openvz_driver.c | 2 +- src/phyp/phyp_driver.c | 8 +++--- src/qemu/qemu_capabilities.c | 38 +++++++++++++++++++++++++++ src/qemu/qemu_capabilities.h | 4 +++ src/qemu/qemu_domain.c | 48 +++++++++++++++++++++------------- src/vmware/vmware_driver.c | 11 ++++---- src/vmx/vmx.c | 8 +++--- src/vmx/vmx.h | 2 +- src/vz/vz_driver.c | 15 ++++++----- tests/Makefile.am | 14 +++++++--- tests/libxlxml2domconfigtest.c | 22 +++++----------- tests/lxcconf2xmltest.c | 17 ++++-------- tests/lxcxml2xmltest.c | 13 +++------ tests/openvzutilstest.c | 10 ++++--- tests/testutilslxc.c | 34 +++++++++++++++++++++++- tests/testutilslxc.h | 4 +++ tests/testutilsxen.c | 34 +++++++++++++++++++++++- tests/testutilsxen.h | 9 ++++--- tests/vmx2xmltest.c | 2 +- tests/xlconfigtest.c | 26 ++++++++---------- tests/xmconfigtest.c | 23 +++++++--------- tests/xml2vmxtest.c | 2 +- 35 files changed, 301 insertions(+), 144 deletions(-) diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c index 575f141b53..eebf5a7650 100644 --- a/src/bhyve/bhyve_domain.c +++ b/src/bhyve/bhyve_domain.c @@ -20,6 +20,7 @@ #include <config.h> +#include "bhyve_driver.h" #include "bhyve_conf.h" #include "bhyve_device.h" #include "bhyve_domain.h" @@ -74,11 +75,16 @@ bhyveDomainDefNeedsISAController(virDomainDefPtr def) static int bhyveDomainDefPostParse(virDomainDefPtr def, - virCapsPtr caps, + virCapsPtr _caps G_GNUC_UNUSED, unsigned int parseFlags G_GNUC_UNUSED, - void *opaque G_GNUC_UNUSED, + void *opaque, void *parseOpaque G_GNUC_UNUSED) { + bhyveConnPtr driver = opaque; + g_autoptr(virCaps) caps = bhyveDriverGetCapabilities(driver); + if (!caps) + return -1; + if (!virCapabilitiesDomainSupported(caps, def->os.type, def->os.arch, def->virtType)) diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 81ff502769..2db89c7986 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -928,7 +928,7 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, if (!priv->caps) goto cleanup; - if (!(priv->xmlopt = virVMXDomainXMLConfInit())) + if (!(priv->xmlopt = virVMXDomainXMLConfInit(priv->caps))) goto cleanup; conn->privateData = priv; diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 37fe360067..132e04b147 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -2470,8 +2470,9 @@ libxlBuildDomainConfig(virPortAllocatorRangePtr graphicsports, } virDomainXMLOptionPtr -libxlCreateXMLConf(void) +libxlCreateXMLConf(libxlDriverPrivatePtr driver) { + libxlDomainDefParserConfig.priv = driver; return virDomainXMLOptionNew(&libxlDomainDefParserConfig, &libxlDomainXMLPrivateDataCallbacks, NULL, NULL, NULL); diff --git a/src/libxl/libxl_conf.h b/src/libxl/libxl_conf.h index 305c8c41ef..4b5d240684 100644 --- a/src/libxl/libxl_conf.h +++ b/src/libxl/libxl_conf.h @@ -207,7 +207,7 @@ libxlMakeUSB(virDomainHostdevDefPtr hostdev, libxl_device_usbdev *usbdev); #endif virDomainXMLOptionPtr -libxlCreateXMLConf(void); +libxlCreateXMLConf(libxlDriverPrivatePtr driver); #ifdef LIBXL_HAVE_DEVICE_CHANNEL # define LIBXL_ATTR_UNUSED diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index ad9424155a..f202f0fc3e 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -367,12 +367,15 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, static int libxlDomainDefPostParse(virDomainDefPtr def, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, unsigned int parseFlags G_GNUC_UNUSED, - void *opaque G_GNUC_UNUSED, + void *opaque, void *parseOpaque G_GNUC_UNUSED) { - if (!virCapabilitiesDomainSupported(caps, def->os.type, + libxlDriverPrivatePtr driver = opaque; + g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver); + + if (!virCapabilitiesDomainSupported(cfg->caps, def->os.type, def->os.arch, def->virtType)) return -1; diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index dc0d9b58f3..fac3c1db49 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -769,7 +769,7 @@ libxlStateInitialize(bool privileged, goto error; } - if (!(libxl_driver->xmlopt = libxlCreateXMLConf())) + if (!(libxl_driver->xmlopt = libxlCreateXMLConf(libxl_driver))) goto error; /* Add Domain-0 */ diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c index de9793e523..2e866973ce 100644 --- a/src/lxc/lxc_conf.c +++ b/src/lxc/lxc_conf.c @@ -207,8 +207,9 @@ virCapsPtr virLXCDriverGetCapabilities(virLXCDriverPtr driver, virDomainXMLOptionPtr -lxcDomainXMLConfInit(void) +lxcDomainXMLConfInit(virLXCDriverPtr driver) { + virLXCDriverDomainDefParserConfig.priv = driver; return virDomainXMLOptionNew(&virLXCDriverDomainDefParserConfig, &virLXCDriverPrivateDataCallbacks, &virLXCDriverDomainXMLNamespace, diff --git a/src/lxc/lxc_conf.h b/src/lxc/lxc_conf.h index 12a201db38..59782d9cb2 100644 --- a/src/lxc/lxc_conf.h +++ b/src/lxc/lxc_conf.h @@ -112,7 +112,7 @@ int virLXCLoadDriverConfig(virLXCDriverConfigPtr cfg, virCapsPtr virLXCDriverCapsInit(virLXCDriverPtr driver); virCapsPtr virLXCDriverGetCapabilities(virLXCDriverPtr driver, bool refresh); -virDomainXMLOptionPtr lxcDomainXMLConfInit(void); +virDomainXMLOptionPtr lxcDomainXMLConfInit(virLXCDriverPtr driver); static inline void lxcDriverLock(virLXCDriverPtr driver) { diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 2b9d6481df..c869e2e7c4 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -159,11 +159,41 @@ static void virLXCControllerQuitTimer(int timer G_GNUC_UNUSED, void *opaque) } +static virLXCDriverPtr +virLXCControllerDriverNew(void) +{ + virLXCDriverPtr driver = g_new0(virLXCDriver, 1); + + if (virMutexInit(&driver->lock) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("cannot initialize mutex")); + g_free(driver); + return NULL; + } + + driver->caps = virLXCDriverCapsInit(NULL); + driver->xmlopt = lxcDomainXMLConfInit(driver); + + return driver; +} + + +static void +virLXCControllerDriverFree(virLXCDriverPtr driver) +{ + if (!driver) + return; + virObjectUnref(driver->xmlopt); + virObjectUnref(driver->caps); + virMutexDestroy(&driver->lock); + g_free(driver); +} + + static virLXCControllerPtr virLXCControllerNew(const char *name) { virLXCControllerPtr ctrl = NULL; - virCapsPtr caps = NULL; - virDomainXMLOptionPtr xmlopt = NULL; + virLXCDriverPtr driver = NULL; char *configFile = NULL; if (VIR_ALLOC(ctrl) < 0) @@ -174,10 +204,7 @@ static virLXCControllerPtr virLXCControllerNew(const char *name) ctrl->name = g_strdup(name); - if (!(caps = virLXCDriverCapsInit(NULL))) - goto error; - - if (!(xmlopt = lxcDomainXMLConfInit())) + if (!(driver = virLXCControllerDriverNew())) goto error; if ((configFile = virDomainConfigFile(LXC_STATE_DIR, @@ -185,7 +212,7 @@ static virLXCControllerPtr virLXCControllerNew(const char *name) goto error; if ((ctrl->vm = virDomainObjParseFile(configFile, - caps, xmlopt, + driver->caps, driver->xmlopt, 0)) == NULL) goto error; ctrl->def = ctrl->vm->def; @@ -197,8 +224,7 @@ static virLXCControllerPtr virLXCControllerNew(const char *name) cleanup: VIR_FREE(configFile); - virObjectUnref(caps); - virObjectUnref(xmlopt); + virLXCControllerDriverFree(driver); return ctrl; error: diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c index b505a91c1c..bc54beeadf 100644 --- a/src/lxc/lxc_domain.c +++ b/src/lxc/lxc_domain.c @@ -351,11 +351,15 @@ virDomainXMLPrivateDataCallbacks virLXCDriverPrivateDataCallbacks = { static int virLXCDomainDefPostParse(virDomainDefPtr def, - virCapsPtr caps, + virCapsPtr _caps G_GNUC_UNUSED, unsigned int parseFlags G_GNUC_UNUSED, - void *opaque G_GNUC_UNUSED, + void *opaque, void *parseOpaque G_GNUC_UNUSED) { + virLXCDriverPtr driver = opaque; + g_autoptr(virCaps) caps = virLXCDriverGetCapabilities(driver, false); + if (!caps) + return -1; if (!virCapabilitiesDomainSupported(caps, def->os.type, def->os.arch, def->virtType)) diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 6c12543274..f28e20d756 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1584,7 +1584,7 @@ static int lxcStateInitialize(bool privileged, if (!(caps = virLXCDriverGetCapabilities(lxc_driver, true))) goto cleanup; - if (!(lxc_driver->xmlopt = lxcDomainXMLConfInit())) + if (!(lxc_driver->xmlopt = lxcDomainXMLConfInit(lxc_driver))) goto cleanup; if (!(lxc_driver->closeCallbacks = virCloseCallbacksNew())) diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index de8be1ed7d..5060e704a5 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -1082,12 +1082,13 @@ int openvzGetVEID(const char *name) static int openvzDomainDefPostParse(virDomainDefPtr def, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, unsigned int parseFlags G_GNUC_UNUSED, - void *opaque G_GNUC_UNUSED, + void *opaque, void *parseOpaque G_GNUC_UNUSED) { - if (!virCapabilitiesDomainSupported(caps, def->os.type, + struct openvz_driver *driver = opaque; + if (!virCapabilitiesDomainSupported(driver->caps, def->os.type, def->os.arch, def->virtType)) return -1; @@ -1133,8 +1134,9 @@ virDomainDefParserConfig openvzDomainDefParserConfig = { .features = VIR_DOMAIN_DEF_FEATURE_NAME_SLASH, }; -virDomainXMLOptionPtr openvzXMLOption(void) +virDomainXMLOptionPtr openvzXMLOption(struct openvz_driver *driver) { + openvzDomainDefParserConfig.priv = driver; return virDomainXMLOptionNew(&openvzDomainDefParserConfig, NULL, NULL, NULL, NULL); } diff --git a/src/openvz/openvz_conf.h b/src/openvz/openvz_conf.h index 6463c1704a..9892f39481 100644 --- a/src/openvz/openvz_conf.h +++ b/src/openvz/openvz_conf.h @@ -63,4 +63,4 @@ int strtoI(const char *str); int openvzSetDefinedUUID(int vpsid, unsigned char *uuid); int openvzGetVEID(const char *name); int openvzReadNetworkConf(virDomainDefPtr def, int veid); -virDomainXMLOptionPtr openvzXMLOption(void); +virDomainXMLOptionPtr openvzXMLOption(struct openvz_driver *driver); diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index e479ebf58d..9b93bc5ca0 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -1311,7 +1311,7 @@ static virDrvOpenStatus openvzConnectOpen(virConnectPtr conn, if (!(driver->caps = openvzCapsInit())) goto cleanup; - if (!(driver->xmlopt = openvzXMLOption())) + if (!(driver->xmlopt = openvzXMLOption(driver))) goto cleanup; if (openvzLoadDomains(driver) < 0) diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 218d6f5b5c..05860b7dbe 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -1062,12 +1062,13 @@ openSSHSession(virConnectPtr conn, virConnectAuthPtr auth, static int phypDomainDefPostParse(virDomainDefPtr def, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, unsigned int parseFlags G_GNUC_UNUSED, - void *opaque G_GNUC_UNUSED, + void *opaque, void *parseOpaque G_GNUC_UNUSED) { - if (!virCapabilitiesDomainSupported(caps, def->os.type, + phyp_driverPtr driver = opaque; + if (!virCapabilitiesDomainSupported(driver->caps, def->os.type, def->os.arch, def->virtType)) return -1; @@ -1157,6 +1158,7 @@ phypConnectOpen(virConnectPtr conn, if ((phyp_driver->caps = phypCapsInit()) == NULL) goto failure; + virPhypDriverDomainDefParserConfig.priv = phyp_driver; if (!(phyp_driver->xmlopt = virDomainXMLOptionNew(&virPhypDriverDomainDefParserConfig, NULL, NULL, NULL, NULL))) goto failure; diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index c02ff5b941..7a62dfb1a2 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2094,6 +2094,44 @@ virQEMUCapsSetHostModel(virQEMUCapsPtr qemuCaps, } +bool +virQEMUCapsIsArchSupported(virQEMUCapsPtr qemuCaps, + virArch arch) +{ + if (arch == qemuCaps->arch) + return true; + + if (qemuCaps->arch == VIR_ARCH_X86_64 && arch == VIR_ARCH_I686) + return true; + + if (qemuCaps->arch == VIR_ARCH_AARCH64 && arch == VIR_ARCH_ARMV7L) + return true; + + if (qemuCaps->arch == VIR_ARCH_ARMV7L && arch == VIR_ARCH_ARMV6L) + return true; + + if (qemuCaps->arch == VIR_ARCH_PPC64 && arch == VIR_ARCH_PPC64LE) + return true; + + return false; +} + + +bool +virQEMUCapsIsVirtTypeSupported(virQEMUCapsPtr qemuCaps, + virDomainVirtType virtType) +{ + if (virtType == VIR_DOMAIN_VIRT_QEMU) + return true; + + if (virtType == VIR_DOMAIN_VIRT_KVM && + virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) + return true; + + return false; +} + + bool virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps, virArch hostarch, diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 399496796d..a8a5c38d73 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -603,6 +603,10 @@ int virQEMUCapsGetCPUFeatures(virQEMUCapsPtr qemuCaps, bool migratable, char ***features); +bool virQEMUCapsIsArchSupported(virQEMUCapsPtr qemuCaps, + virArch arch); +bool virQEMUCapsIsVirtTypeSupported(virQEMUCapsPtr qemuCaps, + virDomainVirtType virtType); bool virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps, virArch hostarch, virDomainVirtType type, diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index b0e87a05c2..0076349558 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4691,22 +4691,40 @@ qemuDomainDefPostParseBasic(virDomainDefPtr def, static int qemuDomainDefPostParse(virDomainDefPtr def, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, unsigned int parseFlags, void *opaque, - void *parseOpaque) + void *parseOpaque G_GNUC_UNUSED) { virQEMUDriverPtr driver = opaque; g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver); - /* Note that qemuCaps may be NULL when this function is called. This - * function shall not fail in that case. It will be re-run on VM startup - * with the capabilities populated. */ - virQEMUCapsPtr qemuCaps = parseOpaque; + g_autoptr(virQEMUCaps) qemuCaps = NULL; + + if (!(qemuCaps = virQEMUCapsCacheLookup(driver->qemuCapsCache, + def->emulator))) { + return 1; + } + + if (def->os.type != VIR_DOMAIN_OSTYPE_HVM) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Emulator '%s' does not support os type '%s'"), + def->emulator, virDomainOSTypeToString(def->os.type)); + return -1; + } - if (!virCapabilitiesDomainSupported(caps, def->os.type, - def->os.arch, - def->virtType)) + if (!virQEMUCapsIsArchSupported(qemuCaps, def->os.arch)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Emulator '%s' does not support arch '%s'"), + def->emulator, virArchToString(def->os.arch)); return -1; + } + + if (!virQEMUCapsIsVirtTypeSupported(qemuCaps, def->virtType)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Emulator '%s' does not support virt type '%s'"), + def->emulator, virDomainVirtTypeToString(def->virtType)); + return -1; + } if (def->os.bootloader || def->os.bootloaderArgs) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", @@ -4715,15 +4733,9 @@ qemuDomainDefPostParse(virDomainDefPtr def, } if (!def->os.machine) { - g_autofree virCapsDomainDataPtr capsdata = NULL; - - if (!(capsdata = virCapabilitiesDomainDataLookup(caps, def->os.type, - def->os.arch, - def->virtType, - NULL, NULL))) { - return -1; - } - def->os.machine = g_strdup(capsdata->machinetype); + const char *machine = virQEMUCapsGetPreferredMachine(qemuCaps, + def->virtType); + def->os.machine = g_strdup(machine); } qemuDomainNVRAMPathGenerate(cfg, def); diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index be0adb1e45..308a941f8a 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -117,12 +117,13 @@ vmwareDataFreeFunc(void *data) static int vmwareDomainDefPostParse(virDomainDefPtr def, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, unsigned int parseFlags G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED, void *parseOpaque G_GNUC_UNUSED) { - if (!virCapabilitiesDomainSupported(caps, def->os.type, + struct vmware_driver *driver = opaque; + if (!virCapabilitiesDomainSupported(driver->caps, def->os.type, def->os.arch, def->virtType)) return -1; @@ -148,11 +149,11 @@ virDomainDefParserConfig vmwareDomainDefParserConfig = { }; static virDomainXMLOptionPtr -vmwareDomainXMLConfigInit(void) +vmwareDomainXMLConfigInit(struct vmware_driver *driver) { virDomainXMLPrivateDataCallbacks priv = { .alloc = vmwareDataAllocFunc, .free = vmwareDataFreeFunc }; - + vmwareDomainDefParserConfig.priv = driver; return virDomainXMLOptionNew(&vmwareDomainDefParserConfig, &priv, NULL, NULL, NULL); } @@ -235,7 +236,7 @@ vmwareConnectOpen(virConnectPtr conn, if (!(driver->caps = vmwareCapsInit())) goto cleanup; - if (!(driver->xmlopt = vmwareDomainXMLConfigInit())) + if (!(driver->xmlopt = vmwareDomainXMLConfigInit(driver))) goto cleanup; if (vmwareLoadDomains(driver) < 0) diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index c2a06daecb..958b168891 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -530,11 +530,12 @@ VIR_ENUM_IMPL(virVMXControllerModelSCSI, static int virVMXDomainDefPostParse(virDomainDefPtr def, - virCapsPtr caps, + virCapsPtr _caps G_GNUC_UNUSED, unsigned int parseFlags G_GNUC_UNUSED, - void *opaque G_GNUC_UNUSED, + void *opaque, void *parseOpaque G_GNUC_UNUSED) { + virCapsPtr caps = opaque; if (!virCapabilitiesDomainSupported(caps, def->os.type, def->os.arch, def->virtType)) @@ -612,8 +613,9 @@ static virXMLNamespace virVMXDomainXMLNamespace = { }; virDomainXMLOptionPtr -virVMXDomainXMLConfInit(void) +virVMXDomainXMLConfInit(virCapsPtr caps) { + virVMXDomainDefParserConfig.priv = caps; return virDomainXMLOptionNew(&virVMXDomainDefParserConfig, NULL, &virVMXDomainXMLNamespace, NULL, NULL); } diff --git a/src/vmx/vmx.h b/src/vmx/vmx.h index 18478ac0ae..63f47822fb 100644 --- a/src/vmx/vmx.h +++ b/src/vmx/vmx.h @@ -29,7 +29,7 @@ typedef struct _virVMXContext virVMXContext; -virDomainXMLOptionPtr virVMXDomainXMLConfInit(void); +virDomainXMLOptionPtr virVMXDomainXMLConfInit(virCapsPtr caps); /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 66b15737a2..a0d1efb9dd 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -241,12 +241,13 @@ vzDomainDefAddDefaultInputDevices(virDomainDefPtr def) static int vzDomainDefPostParse(virDomainDefPtr def, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, unsigned int parseFlags G_GNUC_UNUSED, - void *opaque G_GNUC_UNUSED, + void *opaque, void *parseOpaque G_GNUC_UNUSED) { - if (!virCapabilitiesDomainSupported(caps, def->os.type, + vzDriverPtr driver = opaque; + if (!virCapabilitiesDomainSupported(driver->caps, def->os.type, def->os.arch, def->virtType)) return -1; @@ -289,10 +290,12 @@ vzDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, static int vzDomainDeviceDefValidate(const virDomainDeviceDef *dev, const virDomainDef *def, - void *opaque G_GNUC_UNUSED) + void *opaque) { + vzDriverPtr driver = opaque; + if (dev->type == VIR_DOMAIN_DEVICE_DISK) - return vzCheckUnsupportedDisk(def, dev->data.disk, opaque); + return vzCheckUnsupportedDisk(def, dev->data.disk, driver->vzCaps); else if (dev->type == VIR_DOMAIN_DEVICE_GRAPHICS) return vzCheckUnsupportedGraphics(dev->data.graphics); @@ -323,7 +326,7 @@ vzDriverObjNew(void) if (!(driver = virObjectLockableNew(vzDriverClass))) return NULL; - vzDomainDefParserConfig.priv = &driver->vzCaps; + vzDomainDefParserConfig.priv = driver; if (!(driver->caps = vzBuildCapabilities()) || !(driver->xmlopt = virDomainXMLOptionNew(&vzDomainDefParserConfig, diff --git a/tests/Makefile.am b/tests/Makefile.am index 465c176ffd..4873b85db3 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1046,11 +1046,17 @@ endif WITH_LXC if WITH_QEMU vircapstest_SOURCES += testutilsqemu.c testutilsqemu.h endif WITH_QEMU +vircapstest_LDADD = if WITH_QEMU -vircapstest_LDADD = $(qemu_LDADDS) -else ! WITH_QEMU -vircapstest_LDADD = $(LDADDS) -endif ! WITH_QEMU +vircapstest_LDADD += ../src/libvirt_driver_qemu_impl.la +if WITH_DTRACE_PROBES +vircapstest_LDADD += ../src/libvirt_qemu_probes.lo +endif WITH_DTRACE_PROBES +endif WITH_QEMU +if WITH_LXC +vircapstest_LDADD += ../src/libvirt_driver_lxc_impl.la +endif WITH_LXC +vircapstest_LDADD += $(LDADDS) libdomaincapsmock_la_SOURCES = domaincapsmock.c libdomaincapsmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) diff --git a/tests/libxlxml2domconfigtest.c b/tests/libxlxml2domconfigtest.c index 5bda6db360..5c8dcf8503 100644 --- a/tests/libxlxml2domconfigtest.c +++ b/tests/libxlxml2domconfigtest.c @@ -41,7 +41,7 @@ # define VIR_FROM_THIS VIR_FROM_LIBXL -static virCapsPtr caps; +static libxlDriverPrivatePtr driver; static int testCompareXMLToDomConfig(const char *xmlfile, @@ -50,19 +50,13 @@ testCompareXMLToDomConfig(const char *xmlfile, int ret = -1; libxl_domain_config actualconfig; libxl_domain_config expectconfig; - libxlDriverConfigPtr cfg; xentoollog_logger *log = NULL; virPortAllocatorRangePtr gports = NULL; - virDomainXMLOptionPtr xmlopt = NULL; virDomainDefPtr vmdef = NULL; char *actualjson = NULL; char *tempjson = NULL; char *expectjson = NULL; - - if (!(cfg = libxlDriverConfigNew())) - return -1; - - cfg->caps = caps; + g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver); libxl_domain_config_init(&actualconfig); libxl_domain_config_init(&expectconfig); @@ -82,10 +76,7 @@ testCompareXMLToDomConfig(const char *xmlfile, if (!(gports = virPortAllocatorRangeNew("vnc", 5900, 6000))) goto cleanup; - if (!(xmlopt = libxlCreateXMLConf())) - goto cleanup; - - if (!(vmdef = virDomainDefParseFile(xmlfile, caps, xmlopt, + if (!(vmdef = virDomainDefParseFile(xmlfile, cfg->caps, driver->xmlopt, NULL, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; @@ -128,12 +119,9 @@ testCompareXMLToDomConfig(const char *xmlfile, VIR_FREE(tempjson); virDomainDefFree(vmdef); virPortAllocatorRangeFree(gports); - virObjectUnref(xmlopt); libxl_domain_config_dispose(&actualconfig); libxl_domain_config_dispose(&expectconfig); xtl_logger_destroy(log); - cfg->caps = NULL; - virObjectUnref(cfg); return ret; } @@ -177,7 +165,7 @@ mymain(void) return EXIT_FAILURE; } - if ((caps = testXLInitCaps()) == NULL) + if ((driver = testXLInitDriver()) == NULL) return EXIT_FAILURE; # define DO_TEST(name) \ @@ -216,6 +204,8 @@ mymain(void) unlink("libxl-driver.log"); + testXLFreeDriver(driver); + return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/lxcconf2xmltest.c b/tests/lxcconf2xmltest.c index 7adc23be9f..fffe9cbf1a 100644 --- a/tests/lxcconf2xmltest.c +++ b/tests/lxcconf2xmltest.c @@ -10,8 +10,7 @@ # define VIR_FROM_THIS VIR_FROM_NONE -static virCapsPtr caps; -static virDomainXMLOptionPtr xmlopt; +static virLXCDriverPtr driver; static int testSanitizeDef(virDomainDefPtr vmdef) { @@ -34,7 +33,7 @@ testCompareXMLToConfigFiles(const char *xmlfile, if (virTestLoadFile(configfile, &config) < 0) goto fail; - vmdef = lxcParseConfigString(config, caps, xmlopt); + vmdef = lxcParseConfigString(config, driver->caps, driver->xmlopt); if ((vmdef && expectError) || (!vmdef && !expectError)) goto fail; @@ -42,7 +41,7 @@ testCompareXMLToConfigFiles(const char *xmlfile, if (testSanitizeDef(vmdef) < 0) goto fail; - if (!(actualxml = virDomainDefFormat(vmdef, xmlopt, caps, 0))) + if (!(actualxml = virDomainDefFormat(vmdef, driver->xmlopt, driver->caps, 0))) goto fail; if (virTestCompareToFile(actualxml, xmlfile) < 0) @@ -109,14 +108,9 @@ mymain(void) { int ret = EXIT_SUCCESS; - if (!(caps = testLXCCapsInit())) + if (!(driver = testLXCDriverInit())) return EXIT_FAILURE; - if (!(xmlopt = lxcDomainXMLConfInit())) { - virObjectUnref(caps); - return EXIT_FAILURE; - } - # define DO_TEST(name, expectError) \ do { \ const struct testInfo info = { name, expectError }; \ @@ -166,8 +160,7 @@ mymain(void) DO_TEST3("blkiotune", false); DO_TEST3("ethernet", false); - virObjectUnref(xmlopt); - virObjectUnref(caps); + testLXCDriverFree(driver); return ret; } diff --git a/tests/lxcxml2xmltest.c b/tests/lxcxml2xmltest.c index 6a720503a9..7b05f7d016 100644 --- a/tests/lxcxml2xmltest.c +++ b/tests/lxcxml2xmltest.c @@ -16,8 +16,7 @@ # define VIR_FROM_THIS VIR_FROM_NONE -static virCapsPtr caps; -static virDomainXMLOptionPtr xmlopt; +static virLXCDriverPtr driver; struct testInfo { const char *name; @@ -39,7 +38,7 @@ testCompareXMLToXMLHelper(const void *data) xml_out = g_strdup_printf("%s/lxcxml2xmloutdata/lxc-%s.xml", abs_srcdir, info->name); - ret = testCompareDomXML2XMLFiles(caps, xmlopt, xml_in, + ret = testCompareDomXML2XMLFiles(driver->caps, driver->xmlopt, xml_in, info->different ? xml_out : xml_in, !info->inactive_only, info->parse_flags, @@ -55,10 +54,7 @@ mymain(void) { int ret = 0; - if ((caps = testLXCCapsInit()) == NULL) - return EXIT_FAILURE; - - if (!(xmlopt = lxcDomainXMLConfInit())) + if (!(driver = testLXCDriverInit())) return EXIT_FAILURE; # define DO_TEST_FULL(name, is_different, inactive, parse_flags) \ @@ -95,8 +91,7 @@ mymain(void) DO_TEST("initdir"); DO_TEST("inituser"); - virObjectUnref(caps); - virObjectUnref(xmlopt); + testLXCDriverFree(driver); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/openvzutilstest.c b/tests/openvzutilstest.c index f43867ddc9..681f1a52a0 100644 --- a/tests/openvzutilstest.c +++ b/tests/openvzutilstest.c @@ -98,7 +98,10 @@ testReadNetworkConf(const void *data G_GNUC_UNUSED) " </interface>\n" " </devices>\n" "</domain>\n"; - virDomainXMLOptionPtr xmlopt = openvzXMLOption(); + struct openvz_driver driver = {0}; + + driver.xmlopt = openvzXMLOption(&driver); + driver.caps = openvzCapsInit(); if (!(def = virDomainDefNew())) goto cleanup; @@ -113,7 +116,7 @@ testReadNetworkConf(const void *data G_GNUC_UNUSED) goto cleanup; } - actual = virDomainDefFormat(def, xmlopt, NULL, VIR_DOMAIN_DEF_FORMAT_INACTIVE); + actual = virDomainDefFormat(def, driver.xmlopt, driver.caps, VIR_DOMAIN_DEF_FORMAT_INACTIVE); if (actual == NULL) { fprintf(stderr, "ERROR: %s\n", virGetLastErrorMessage()); @@ -128,7 +131,8 @@ testReadNetworkConf(const void *data G_GNUC_UNUSED) result = 0; cleanup: - virObjectUnref(xmlopt); + virObjectUnref(driver.xmlopt); + virObjectUnref(driver.caps); VIR_FREE(actual); virDomainDefFree(def); diff --git a/tests/testutilslxc.c b/tests/testutilslxc.c index eed18304c4..b5e2f542e7 100644 --- a/tests/testutilslxc.c +++ b/tests/testutilslxc.c @@ -6,8 +6,10 @@ # include "viralloc.h" # include "domain_conf.h" +# define VIR_FROM_THIS VIR_FROM_LXC -virCapsPtr testLXCCapsInit(void) +virCapsPtr +testLXCCapsInit(void) { virCapsPtr caps; virCapsGuestPtr guest; @@ -54,4 +56,34 @@ virCapsPtr testLXCCapsInit(void) virObjectUnref(caps); return NULL; } + + +virLXCDriverPtr +testLXCDriverInit(void) +{ + virLXCDriverPtr driver = g_new0(virLXCDriver, 1); + + if (virMutexInit(&driver->lock) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", "cannot initialize mutex"); + g_free(driver); + return NULL; + } + + driver->caps = testLXCCapsInit(); + driver->xmlopt = lxcDomainXMLConfInit(driver); + + return driver; +} + + +void +testLXCDriverFree(virLXCDriverPtr driver) +{ + virObjectUnref(driver->xmlopt); + virObjectUnref(driver->caps); + virMutexDestroy(&driver->lock); + g_free(driver); +} + #endif diff --git a/tests/testutilslxc.h b/tests/testutilslxc.h index 6339f88734..fe170540b5 100644 --- a/tests/testutilslxc.h +++ b/tests/testutilslxc.h @@ -18,7 +18,11 @@ #include "capabilities.h" +#include "lxc/lxc_conf.h" + #define FAKEDEVDIR0 "/fakedevdir0/bla/fasl" #define FAKEDEVDIR1 "/fakedevdir1/bla/fasl" virCapsPtr testLXCCapsInit(void); +virLXCDriverPtr testLXCDriverInit(void); +void testLXCDriverFree(virLXCDriverPtr driver); diff --git a/tests/testutilsxen.c b/tests/testutilsxen.c index 314d96abe8..75cd42ec43 100644 --- a/tests/testutilsxen.c +++ b/tests/testutilsxen.c @@ -6,7 +6,9 @@ #include "testutilshostcpus.h" #include "domain_conf.h" -virCapsPtr +#define VIR_FROM_THIS VIR_FROM_LIBXL + +static virCapsPtr testXLInitCaps(void) { virCapsPtr caps; @@ -79,3 +81,33 @@ testXLInitCaps(void) virObjectUnref(caps); return NULL; } + + +libxlDriverPrivatePtr testXLInitDriver(void) +{ + libxlDriverPrivatePtr driver = g_new0(libxlDriverPrivate, 1); + + if (virMutexInit(&driver->lock) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", "cannot initialize mutex"); + g_free(driver); + return NULL; + } + + driver->config = libxlDriverConfigNew(); + + driver->config->caps = testXLInitCaps(); + + driver->xmlopt = libxlCreateXMLConf(driver); + + return driver; +} + +void testXLFreeDriver(libxlDriverPrivatePtr driver) +{ + virObjectUnref(driver->config->caps); + virObjectUnref(driver->config); + virObjectUnref(driver->xmlopt); + virMutexDestroy(&driver->lock); + g_free(driver); +} diff --git a/tests/testutilsxen.h b/tests/testutilsxen.h index 95dadb04c4..a31d3d9047 100644 --- a/tests/testutilsxen.h +++ b/tests/testutilsxen.h @@ -18,7 +18,10 @@ #include "capabilities.h" #ifdef WITH_LIBXL -# include "libxl/libxl_capabilities.h" -#endif +# include "libxl/libxl_conf.h" -virCapsPtr testXLInitCaps(void); +libxlDriverPrivatePtr testXLInitDriver(void); + +void testXLFreeDriver(libxlDriverPrivatePtr driver); + +#endif /* WITH_LIBXL */ diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index 72ee2a38c8..beb82cbd7c 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -186,7 +186,7 @@ mymain(void) if (caps == NULL) return EXIT_FAILURE; - if (!(xmlopt = virVMXDomainXMLConfInit())) + if (!(xmlopt = virVMXDomainXMLConfInit(caps))) return EXIT_FAILURE; ctx.opaque = NULL; diff --git a/tests/xlconfigtest.c b/tests/xlconfigtest.c index 890d8bf2b4..d077933ca9 100644 --- a/tests/xlconfigtest.c +++ b/tests/xlconfigtest.c @@ -36,9 +36,7 @@ #define VIR_FROM_THIS VIR_FROM_NONE -static virCapsPtr caps; -static virDomainXMLOptionPtr xmlopt; - +static libxlDriverPrivatePtr driver; /* * This function provides a mechanism to replace variables in test @@ -74,6 +72,7 @@ testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars) int ret = -1; virDomainDefPtr def = NULL; char *replacedXML = NULL; + g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver); if (VIR_ALLOC_N(gotxlcfgData, wrote) < 0) goto fail; @@ -84,16 +83,16 @@ testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars) if (replaceVars) { if (!(replacedXML = testReplaceVarsXML(xml))) goto fail; - if (!(def = virDomainDefParseString(replacedXML, caps, xmlopt, + if (!(def = virDomainDefParseString(replacedXML, cfg->caps, driver->xmlopt, NULL, VIR_DOMAIN_XML_INACTIVE))) goto fail; } else { - if (!(def = virDomainDefParseFile(xml, caps, xmlopt, + if (!(def = virDomainDefParseFile(xml, cfg->caps, driver->xmlopt, NULL, VIR_DOMAIN_XML_INACTIVE))) goto fail; } - if (!virDomainDefCheckABIStability(def, def, xmlopt)) { + if (!virDomainDefCheckABIStability(def, def, driver->xmlopt)) { fprintf(stderr, "ABI stability check failed on %s", xml); goto fail; } @@ -133,6 +132,7 @@ testCompareFormatXML(const char *xlcfg, const char *xml, bool replaceVars) virConnectPtr conn; virDomainDefPtr def = NULL; char *replacedXML = NULL; + g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver); conn = virGetConnect(); if (!conn) goto fail; @@ -143,10 +143,10 @@ testCompareFormatXML(const char *xlcfg, const char *xml, bool replaceVars) if (!(conf = virConfReadString(xlcfgData, 0))) goto fail; - if (!(def = xenParseXL(conf, caps, xmlopt))) + if (!(def = xenParseXL(conf, cfg->caps, driver->xmlopt))) goto fail; - if (!(gotxml = virDomainDefFormat(def, xmlopt, caps, + if (!(gotxml = virDomainDefFormat(def, driver->xmlopt, cfg->caps, VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_SECURE))) goto fail; @@ -208,10 +208,7 @@ mymain(void) { int ret = 0; - if (!(caps = testXLInitCaps())) - return EXIT_FAILURE; - - if (!(xmlopt = libxlCreateXMLConf())) + if (!(driver = testXLInitDriver())) return EXIT_FAILURE; #define DO_TEST_PARSE(name, replace) \ @@ -303,10 +300,9 @@ mymain(void) DO_TEST("usb"); DO_TEST("usbctrl"); - virObjectUnref(caps); - virObjectUnref(xmlopt); + testXLFreeDriver(driver); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -VIR_TEST_MAIN(mymain) +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("xl")) diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c index 4a4d4192db..6971ad76e2 100644 --- a/tests/xmconfigtest.c +++ b/tests/xmconfigtest.c @@ -34,8 +34,7 @@ #define VIR_FROM_THIS VIR_FROM_NONE -static virCapsPtr caps; -static virDomainXMLOptionPtr xmlopt; +static libxlDriverPrivatePtr driver; static int testCompareParseXML(const char *xmcfg, const char *xml) @@ -46,6 +45,7 @@ testCompareParseXML(const char *xmcfg, const char *xml) virConnectPtr conn = NULL; int wrote = 4096; virDomainDefPtr def = NULL; + g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver); if (VIR_ALLOC_N(gotxmcfgData, wrote) < 0) goto fail; @@ -53,11 +53,11 @@ testCompareParseXML(const char *xmcfg, const char *xml) conn = virGetConnect(); if (!conn) goto fail; - if (!(def = virDomainDefParseFile(xml, caps, xmlopt, NULL, + if (!(def = virDomainDefParseFile(xml, cfg->caps, driver->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto fail; - if (!virDomainDefCheckABIStability(def, def, xmlopt)) { + if (!virDomainDefCheckABIStability(def, def, driver->xmlopt)) { fprintf(stderr, "ABI stability check failed on %s", xml); goto fail; } @@ -90,6 +90,7 @@ testCompareFormatXML(const char *xmcfg, const char *xml) g_autoptr(virConf) conf = NULL; int ret = -1; virDomainDefPtr def = NULL; + g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver); if (virTestLoadFile(xmcfg, &xmcfgData) < 0) goto fail; @@ -97,10 +98,10 @@ testCompareFormatXML(const char *xmcfg, const char *xml) if (!(conf = virConfReadString(xmcfgData, 0))) goto fail; - if (!(def = xenParseXM(conf, caps, xmlopt))) + if (!(def = xenParseXM(conf, cfg->caps, driver->xmlopt))) goto fail; - if (!(gotxml = virDomainDefFormat(def, xmlopt, caps, VIR_DOMAIN_DEF_FORMAT_SECURE))) + if (!(gotxml = virDomainDefFormat(def, driver->xmlopt, cfg->caps, VIR_DOMAIN_DEF_FORMAT_SECURE))) goto fail; if (virTestCompareToFile(gotxml, xml) < 0) @@ -152,10 +153,7 @@ mymain(void) { int ret = 0; - if (!(caps = testXLInitCaps())) - return EXIT_FAILURE; - - if (!(xmlopt = libxlCreateXMLConf())) + if (!(driver = testXLInitDriver())) return EXIT_FAILURE; #define DO_TEST_PARSE(name) \ @@ -225,10 +223,9 @@ mymain(void) DO_TEST("disk-drv-blktap-raw"); DO_TEST("disk-drv-blktap2-raw"); - virObjectUnref(caps); - virObjectUnref(xmlopt); + testXLFreeDriver(driver); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -VIR_TEST_MAIN(mymain) +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("xl")) diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c index 8dc37f265a..39781beafd 100644 --- a/tests/xml2vmxtest.c +++ b/tests/xml2vmxtest.c @@ -207,7 +207,7 @@ mymain(void) if (caps == NULL) return EXIT_FAILURE; - if (!(xmlopt = virVMXDomainXMLConfInit())) + if (!(xmlopt = virVMXDomainXMLConfInit(caps))) return EXIT_FAILURE; ctx.opaque = NULL; -- 2.23.0

Instead of using the virCapsPtr information, pass the driver specific netprefix in the domain parser struct. This eliminates one more use of virCapsPtr from the XML parsing/formatting code. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/conf/domain_conf.c | 24 +++++++----------------- src/conf/domain_conf.h | 3 ++- src/libxl/libxl_domain.c | 1 + 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6abe15f721..b45ca4a4d0 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11446,7 +11446,6 @@ static virDomainNetDefPtr virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, xmlNodePtr node, xmlXPathContextPtr ctxt, - char *prefix, unsigned int flags) { virDomainNetDefPtr def; @@ -11494,6 +11493,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, g_autofree char *vhostuser_type = NULL; g_autofree char *trustGuestRxFilters = NULL; g_autofree char *vhost_path = NULL; + const char *prefix = xmlopt ? xmlopt->config.netPrefix : NULL; if (!(def = virDomainNetDefNew(xmlopt))) return NULL; @@ -16385,7 +16385,6 @@ virDomainDeviceDefParse(const char *xmlStr, xmlNodePtr node; g_autoptr(xmlXPathContext) ctxt = NULL; g_autofree virDomainDeviceDefPtr dev = NULL; - char *netprefix; if (!(xml = virXMLParseStringCtxt(xmlStr, _("(device_definition)"), &ctxt))) return NULL; @@ -16428,9 +16427,7 @@ virDomainDeviceDefParse(const char *xmlStr, return NULL; break; case VIR_DOMAIN_DEVICE_NET: - netprefix = caps->host.netprefix; - if (!(dev->data.net = virDomainNetDefParseXML(xmlopt, node, ctxt, - netprefix, flags))) + if (!(dev->data.net = virDomainNetDefParseXML(xmlopt, node, ctxt, flags))) return NULL; break; case VIR_DOMAIN_DEVICE_INPUT: @@ -19759,7 +19756,6 @@ virDomainDefParseXML(xmlDocPtr xml, bool usb_none = false; bool usb_other = false; bool usb_master = false; - char *netprefix = NULL; g_autofree xmlNodePtr *nodes = NULL; g_autofree char *tmp = NULL; @@ -20872,12 +20868,10 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; if (n && VIR_ALLOC_N(def->nets, n) < 0) goto error; - netprefix = caps->host.netprefix; for (i = 0; i < n; i++) { virDomainNetDefPtr net = virDomainNetDefParseXML(xmlopt, nodes[i], ctxt, - netprefix, flags); if (!net) goto error; @@ -25362,7 +25356,7 @@ virDomainChrSourceReconnectDefFormat(virBufferPtr buf, int virDomainNetDefFormat(virBufferPtr buf, virDomainNetDefPtr def, - char *prefix, + virDomainXMLOptionPtr xmlopt, unsigned int flags) { virDomainNetType actualType = virDomainNetGetActualType(def); @@ -25372,6 +25366,7 @@ virDomainNetDefFormat(virBufferPtr buf, virDomainHostdevDefPtr hostdef = NULL; char macstr[VIR_MAC_STRING_BUFLEN]; g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER; + const char *prefix = xmlopt ? xmlopt->config.netPrefix : NULL; /* publicActual is true if we should report the current state in * def->data.network.actual *instead of* the config (*not* in @@ -28294,7 +28289,7 @@ virDomainDefFormatInternal(virDomainDefPtr def, int virDomainDefFormatInternalSetRootName(virDomainDefPtr def, virDomainXMLOptionPtr xmlopt, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, virBufferPtr buf, const char *rootname, unsigned int flags) @@ -28304,7 +28299,6 @@ virDomainDefFormatInternalSetRootName(virDomainDefPtr def, const char *type = NULL; int n; size_t i; - char *netprefix = NULL; virCheckFlags(VIR_DOMAIN_DEF_FORMAT_COMMON_FLAGS | VIR_DOMAIN_DEF_FORMAT_STATUS | @@ -28660,10 +28654,8 @@ virDomainDefFormatInternalSetRootName(virDomainDefPtr def, if (virDomainFSDefFormat(buf, def->fss[n], flags) < 0) goto error; - if (caps) - netprefix = caps->host.netprefix; for (n = 0; n < def->nnets; n++) - if (virDomainNetDefFormat(buf, def->nets[n], netprefix, flags) < 0) + if (virDomainNetDefFormat(buf, def->nets[n], xmlopt, flags) < 0) goto error; for (n = 0; n < def->nsmartcards; n++) @@ -29834,7 +29826,6 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src, g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; int flags = VIR_DOMAIN_DEF_FORMAT_INACTIVE | VIR_DOMAIN_DEF_FORMAT_SECURE; int rc = -1; - char *netprefix; g_autofree char *xmlStr = NULL; switch ((virDomainDeviceType) src->type) { @@ -29848,8 +29839,7 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src, rc = virDomainFSDefFormat(&buf, src->data.fs, flags); break; case VIR_DOMAIN_DEVICE_NET: - netprefix = caps->host.netprefix; - rc = virDomainNetDefFormat(&buf, src->data.net, netprefix, flags); + rc = virDomainNetDefFormat(&buf, src->data.net, xmlopt, flags); break; case VIR_DOMAIN_DEVICE_INPUT: rc = virDomainInputDefFormat(&buf, src->data.input, flags); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index e1622f2112..037cebae64 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2706,6 +2706,7 @@ struct _virDomainDefParserConfig { unsigned int features; /* virDomainDefFeatures */ unsigned char macPrefix[VIR_MAC_PREFIX_BUFLEN]; virArch defArch; + const char *netPrefix; }; typedef void *(*virDomainXMLPrivateDataAllocFunc)(void *); @@ -3146,7 +3147,7 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf, int virDomainNetDefFormat(virBufferPtr buf, virDomainNetDefPtr def, - char *prefix, + virDomainXMLOptionPtr xmlopt, unsigned int flags); typedef enum { diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index f202f0fc3e..dfac04bf59 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -437,6 +437,7 @@ libxlDomainDefPostParse(virDomainDefPtr def, virDomainDefParserConfig libxlDomainDefParserConfig = { .macPrefix = { 0x00, 0x16, 0x3e }, + .netPrefix = LIBXL_GENERATED_PREFIX_XEN, .devicesPostParseCallback = libxlDomainDeviceDefPostParse, .domainPostParseCallback = libxlDomainDefPostParse, .features = VIR_DOMAIN_DEF_FEATURE_NET_MODEL_STRING, -- 2.23.0

Currently the disk and chardev seclabels are validated immediately at the time their data is parsed. This forces the parser to fill in the top level secmodel at time of parsing which is an undesirable thing. This validation conceptually should be done in the post-parse phase instead. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/conf/domain_conf.c | 196 ++++++++++++++++++----------------------- src/conf/domain_conf.h | 1 - src/qemu/qemu_driver.c | 2 +- tests/qemublocktest.c | 2 +- 4 files changed, 90 insertions(+), 111 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b45ca4a4d0..f037702ac2 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5936,8 +5936,42 @@ virDomainDiskAddressDiskBusCompatibility(virDomainDiskBus bus, static int -virDomainDiskDefValidate(const virDomainDiskDef *disk) +virSecurityDeviceLabelDefValidateXML(virSecurityDeviceLabelDefPtr *seclabels, + size_t nseclabels, + virSecurityLabelDefPtr *vmSeclabels, + size_t nvmSeclabels) +{ + virSecurityDeviceLabelDefPtr seclabel; + size_t i; + size_t j; + + for (i = 0; i < nseclabels; i++) { + seclabel = seclabels[i]; + + /* find the security label that it's being overridden */ + for (j = 0; j < nvmSeclabels; j++) { + if (STRNEQ_NULLABLE(vmSeclabels[j]->model, seclabel->model)) + continue; + + if (!vmSeclabels[j]->relabel) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("label overrides require relabeling to be " + "enabled at the domain level")); + return -1; + } + } + } + + return 0; +} + + +static int +virDomainDiskDefValidate(const virDomainDef *def, + const virDomainDiskDef *disk) { + virStorageSourcePtr next; + /* Validate LUN configuration */ if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) { /* volumes haven't been translated at this point, so accept them */ @@ -5991,6 +6025,14 @@ virDomainDiskDefValidate(const virDomainDiskDef *disk) return -1; } + for (next = disk->src; next; next = next->backingStore) { + if (virSecurityDeviceLabelDefValidateXML(next->seclabels, + next->nseclabels, + def->seclabels, + def->nseclabels) < 0) + return -1; + } + return 0; } @@ -6014,10 +6056,11 @@ virDomainDefHasUSB(const virDomainDef *def) static int -virDomainChrSourceDefValidate(const virDomainChrSourceDef *def, - const virDomainChrDef *chr_def) +virDomainChrSourceDefValidate(const virDomainChrSourceDef *src_def, + const virDomainChrDef *chr_def, + const virDomainDef *def) { - switch ((virDomainChrType) def->type) { + switch ((virDomainChrType) src_def->type) { case VIR_DOMAIN_CHR_TYPE_NULL: case VIR_DOMAIN_CHR_TYPE_PTY: case VIR_DOMAIN_CHR_TYPE_VC: @@ -6029,7 +6072,7 @@ virDomainChrSourceDefValidate(const virDomainChrSourceDef *def, case VIR_DOMAIN_CHR_TYPE_FILE: case VIR_DOMAIN_CHR_TYPE_DEV: case VIR_DOMAIN_CHR_TYPE_PIPE: - if (!def->data.file.path) { + if (!src_def->data.file.path) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing source path attribute for char device")); return -1; @@ -6037,13 +6080,13 @@ virDomainChrSourceDefValidate(const virDomainChrSourceDef *def, break; case VIR_DOMAIN_CHR_TYPE_NMDM: - if (!def->data.nmdm.master) { + if (!src_def->data.nmdm.master) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing master path attribute for nmdm device")); return -1; } - if (!def->data.nmdm.slave) { + if (!src_def->data.nmdm.slave) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing slave path attribute for nmdm device")); return -1; @@ -6051,19 +6094,19 @@ virDomainChrSourceDefValidate(const virDomainChrSourceDef *def, break; case VIR_DOMAIN_CHR_TYPE_TCP: - if (!def->data.tcp.host) { + if (!src_def->data.tcp.host) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing source host attribute for char device")); return -1; } - if (!def->data.tcp.service) { + if (!src_def->data.tcp.service) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing source service attribute for char device")); return -1; } - if (def->data.tcp.listen && def->data.tcp.reconnect.enabled) { + if (src_def->data.tcp.listen && src_def->data.tcp.reconnect.enabled) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("chardev reconnect is possible only for connect mode")); return -1; @@ -6071,7 +6114,7 @@ virDomainChrSourceDefValidate(const virDomainChrSourceDef *def, break; case VIR_DOMAIN_CHR_TYPE_UDP: - if (!def->data.udp.connectService) { + if (!src_def->data.udp.connectService) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing source service attribute for char device")); return -1; @@ -6082,7 +6125,7 @@ virDomainChrSourceDefValidate(const virDomainChrSourceDef *def, /* The source path can be auto generated for certain specific * types of channels, but in most cases we should report an * error if the user didn't provide it */ - if (!def->data.nix.path && + if (!src_def->data.nix.path && !(chr_def && chr_def->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL && (chr_def->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_XEN || @@ -6092,7 +6135,7 @@ virDomainChrSourceDefValidate(const virDomainChrSourceDef *def, return -1; } - if (def->data.nix.listen && def->data.nix.reconnect.enabled) { + if (src_def->data.nix.listen && src_def->data.nix.reconnect.enabled) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("chardev reconnect is possible only for connect mode")); return -1; @@ -6100,13 +6143,13 @@ virDomainChrSourceDefValidate(const virDomainChrSourceDef *def, break; case VIR_DOMAIN_CHR_TYPE_SPICEPORT: - if (!def->data.spiceport.channel) { + if (!src_def->data.spiceport.channel) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing source channel attribute for char device")); return -1; } - if (strspn(def->data.spiceport.channel, - SERIAL_CHANNEL_NAME_CHARS) < strlen(def->data.spiceport.channel)) { + if (strspn(src_def->data.spiceport.channel, + SERIAL_CHANNEL_NAME_CHARS) < strlen(src_def->data.spiceport.channel)) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("Invalid character in source channel for char device")); return -1; @@ -6114,6 +6157,12 @@ virDomainChrSourceDefValidate(const virDomainChrSourceDef *def, break; } + if (virSecurityDeviceLabelDefValidateXML(src_def->seclabels, + src_def->nseclabels, + def->seclabels, + def->nseclabels) < 0) + return -1; + return 0; } @@ -6130,7 +6179,7 @@ virDomainRedirdevDefValidate(const virDomainDef *def, return -1; } - return virDomainChrSourceDefValidate(redirdev->source, NULL); + return virDomainChrSourceDefValidate(redirdev->source, NULL, def); } @@ -6253,27 +6302,30 @@ virDomainControllerDefValidate(const virDomainControllerDef *controller) static int -virDomainChrDefValidate(const virDomainChrDef *chr) +virDomainChrDefValidate(const virDomainChrDef *chr, + const virDomainDef *def) { - return virDomainChrSourceDefValidate(chr->source, chr); + return virDomainChrSourceDefValidate(chr->source, chr, def); } static int -virDomainSmartcardDefValidate(const virDomainSmartcardDef *smartcard) +virDomainSmartcardDefValidate(const virDomainSmartcardDef *smartcard, + const virDomainDef *def) { if (smartcard->type == VIR_DOMAIN_SMARTCARD_TYPE_PASSTHROUGH) - return virDomainChrSourceDefValidate(smartcard->data.passthru, NULL); + return virDomainChrSourceDefValidate(smartcard->data.passthru, NULL, def); return 0; } static int -virDomainRNGDefValidate(const virDomainRNGDef *rng) +virDomainRNGDefValidate(const virDomainRNGDef *rng, + const virDomainDef *def) { if (rng->backend == VIR_DOMAIN_RNG_BACKEND_EGD) - return virDomainChrSourceDefValidate(rng->source.chardev, NULL); + return virDomainChrSourceDefValidate(rng->source.chardev, NULL, def); return 0; } @@ -6470,7 +6522,7 @@ virDomainDeviceDefValidateInternal(const virDomainDeviceDef *dev, { switch ((virDomainDeviceType) dev->type) { case VIR_DOMAIN_DEVICE_DISK: - return virDomainDiskDefValidate(dev->data.disk); + return virDomainDiskDefValidate(def, dev->data.disk); case VIR_DOMAIN_DEVICE_REDIRDEV: return virDomainRedirdevDefValidate(def, dev->data.redirdev); @@ -6482,13 +6534,13 @@ virDomainDeviceDefValidateInternal(const virDomainDeviceDef *dev, return virDomainControllerDefValidate(dev->data.controller); case VIR_DOMAIN_DEVICE_CHR: - return virDomainChrDefValidate(dev->data.chr); + return virDomainChrDefValidate(dev->data.chr, def); case VIR_DOMAIN_DEVICE_SMARTCARD: - return virDomainSmartcardDefValidate(dev->data.smartcard); + return virDomainSmartcardDefValidate(dev->data.smartcard, def); case VIR_DOMAIN_DEVICE_RNG: - return virDomainRNGDefValidate(dev->data.rng); + return virDomainRNGDefValidate(dev->data.rng, def); case VIR_DOMAIN_DEVICE_HOSTDEV: return virDomainHostdevDefValidate(dev->data.hostdev); @@ -9044,37 +9096,6 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceLabelDefPtr **seclabels_rtn, } -static int -virSecurityDeviceLabelDefValidateXML(virSecurityDeviceLabelDefPtr *seclabels, - size_t nseclabels, - virSecurityLabelDefPtr *vmSeclabels, - size_t nvmSeclabels) -{ - virSecurityDeviceLabelDefPtr seclabel; - size_t i; - size_t j; - - for (i = 0; i < nseclabels; i++) { - seclabel = seclabels[i]; - - /* find the security label that it's being overridden */ - for (j = 0; j < nvmSeclabels; j++) { - if (STRNEQ_NULLABLE(vmSeclabels[j]->model, seclabel->model)) - continue; - - if (!vmSeclabels[j]->relabel) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("label overrides require relabeling to be " - "enabled at the domain level")); - return -1; - } - } - } - - return 0; -} - - /* Parse the XML definition for a lease */ static virDomainLeaseDefPtr @@ -9703,9 +9724,7 @@ virDomainDiskSourceDefParseAuthValidate(const virStorageSource *src) static int -virDomainDiskDefParseValidate(const virDomainDiskDef *def, - virSecurityLabelDefPtr *vmSeclabels, - size_t nvmSeclabels) +virDomainDiskDefParseValidate(const virDomainDiskDef *def) { virStorageSourcePtr next; @@ -9796,12 +9815,6 @@ virDomainDiskDefParseValidate(const virDomainDiskDef *def, return -1; } } - - if (virSecurityDeviceLabelDefValidateXML(next->seclabels, - next->nseclabels, - vmSeclabels, - nvmSeclabels) < 0) - return -1; } return 0; @@ -9958,8 +9971,6 @@ static virDomainDiskDefPtr virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, xmlNodePtr node, xmlXPathContextPtr ctxt, - virSecurityLabelDefPtr* vmSeclabels, - int nvmSeclabels, unsigned int flags) { virDomainDiskDefPtr def; @@ -10362,7 +10373,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, virDomainDiskDefParsePrivateData(ctxt, def, xmlopt) < 0) goto error; - if (virDomainDiskDefParseValidate(def, vmSeclabels, nvmSeclabels) < 0) + if (virDomainDiskDefParseValidate(def) < 0) goto error; cleanup: @@ -12652,9 +12663,7 @@ static int virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def, xmlNodePtr cur, unsigned int flags, virDomainChrDefPtr chr_def, - xmlXPathContextPtr ctxt, - virSecurityLabelDefPtr* vmSeclabels, - int nvmSeclabels) + xmlXPathContextPtr ctxt) { bool logParsed = false; bool protocolParsed = false; @@ -12737,11 +12746,7 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def, if (virSecurityDeviceLabelDefParseXML(&def->seclabels, &def->nseclabels, ctxt, - flags) < 0 || - virSecurityDeviceLabelDefValidateXML(def->seclabels, - def->nseclabels, - vmSeclabels, - nvmSeclabels) < 0) { + flags) < 0) { ctxt->node = saved_node; goto error; } @@ -12878,8 +12883,6 @@ static virDomainChrDefPtr virDomainChrDefParseXML(virDomainXMLOptionPtr xmlopt, xmlXPathContextPtr ctxt, xmlNodePtr node, - virSecurityLabelDefPtr* vmSeclabels, - int nvmSeclabels, unsigned int flags) { xmlNodePtr cur; @@ -12926,7 +12929,7 @@ virDomainChrDefParseXML(virDomainXMLOptionPtr xmlopt, goto error; if (virDomainChrSourceDefParseXML(def->source, node->children, flags, def, - ctxt, vmSeclabels, nvmSeclabels) < 0) + ctxt) < 0) goto error; if (def->source->type == VIR_DOMAIN_CHR_TYPE_SPICEVMC) { @@ -13057,7 +13060,7 @@ virDomainSmartcardDefParseXML(virDomainXMLOptionPtr xmlopt, cur = node->children; if (virDomainChrSourceDefParseXML(def->data.passthru, cur, flags, - NULL, ctxt, NULL, 0) < 0) + NULL, ctxt) < 0) goto error; if (def->data.passthru->type == VIR_DOMAIN_CHR_TYPE_SPICEVMC) { @@ -14692,7 +14695,7 @@ virDomainRNGDefParseXML(virDomainXMLOptionPtr xmlopt, if (virDomainChrSourceDefParseXML(def->source.chardev, backends[0]->children, flags, - NULL, ctxt, NULL, 0) < 0) + NULL, ctxt) < 0) goto error; break; @@ -15713,7 +15716,7 @@ virDomainRedirdevDefParseXML(virDomainXMLOptionPtr xmlopt, /* boot gets parsed in virDomainDeviceInfoParseXML * source gets parsed in virDomainChrSourceDefParseXML */ if (virDomainChrSourceDefParseXML(def->source, cur, flags, - NULL, ctxt, NULL, 0) < 0) + NULL, ctxt) < 0) goto error; if (def->source->type == VIR_DOMAIN_CHR_TYPE_SPICEVMC) @@ -16413,8 +16416,6 @@ virDomainDeviceDefParse(const char *xmlStr, switch ((virDomainDeviceType) dev->type) { case VIR_DOMAIN_DEVICE_DISK: if (!(dev->data.disk = virDomainDiskDefParseXML(xmlopt, node, ctxt, - def->seclabels, - def->nseclabels, flags))) return NULL; break; @@ -16484,8 +16485,6 @@ virDomainDeviceDefParse(const char *xmlStr, if (!(dev->data.chr = virDomainChrDefParseXML(xmlopt, ctxt, node, - def->seclabels, - def->nseclabels, flags))) return NULL; break; @@ -16552,14 +16551,11 @@ virDomainDeviceDefParse(const char *xmlStr, virDomainDiskDefPtr virDomainDiskDefParse(const char *xmlStr, - const virDomainDef *def, virDomainXMLOptionPtr xmlopt, unsigned int flags) { g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; - virSecurityLabelDefPtr *seclabels = NULL; - size_t nseclabels = 0; if (!(xml = virXMLParseStringCtxt(xmlStr, _("(disk_definition)"), &ctxt))) return NULL; @@ -16571,13 +16567,7 @@ virDomainDiskDefParse(const char *xmlStr, return NULL; } - if (def) { - seclabels = def->seclabels; - nseclabels = def->nseclabels; - } - - return virDomainDiskDefParseXML(xmlopt, ctxt->node, ctxt, - seclabels, nseclabels, flags); + return virDomainDiskDefParseXML(xmlopt, ctxt->node, ctxt, flags); } @@ -20767,8 +20757,6 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainDiskDefPtr disk = virDomainDiskDefParseXML(xmlopt, nodes[i], ctxt, - def->seclabels, - def->nseclabels, flags); if (!disk) goto error; @@ -20919,8 +20907,6 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainChrDefPtr chr = virDomainChrDefParseXML(xmlopt, ctxt, nodes[i], - def->seclabels, - def->nseclabels, flags); if (!chr) goto error; @@ -20947,8 +20933,6 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainChrDefPtr chr = virDomainChrDefParseXML(xmlopt, ctxt, nodes[i], - def->seclabels, - def->nseclabels, flags); if (!chr) goto error; @@ -20977,8 +20961,6 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainChrDefPtr chr = virDomainChrDefParseXML(xmlopt, ctxt, nodes[i], - def->seclabels, - def->nseclabels, flags); if (!chr) goto error; @@ -20997,8 +20979,6 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainChrDefPtr chr = virDomainChrDefParseXML(xmlopt, ctxt, nodes[i], - def->seclabels, - def->nseclabels, flags); if (!chr) goto error; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 037cebae64..e85d3bd5b5 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3044,7 +3044,6 @@ virDomainDeviceDefPtr virDomainDeviceDefParse(const char *xmlStr, void *parseOpaque, unsigned int flags); virDomainDiskDefPtr virDomainDiskDefParse(const char *xmlStr, - const virDomainDef *def, virDomainXMLOptionPtr xmlopt, unsigned int flags); virDomainDefPtr virDomainDefParseString(const char *xmlStr, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index b274542c3e..891ca28d94 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -18435,7 +18435,7 @@ qemuDomainBlockCopy(virDomainPtr dom, const char *disk, const char *destxml, } } - if (!(diskdef = virDomainDiskDefParse(destxml, vm->def, driver->xmlopt, + if (!(diskdef = virDomainDiskDefParse(destxml, driver->xmlopt, VIR_DOMAIN_DEF_PARSE_INACTIVE | VIR_DOMAIN_DEF_PARSE_DISK_SOURCE))) goto cleanup; diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c index fcdbcefb5d..2c170548ec 100644 --- a/tests/qemublocktest.c +++ b/tests/qemublocktest.c @@ -200,7 +200,7 @@ testQemuDiskXMLToProps(const void *opaque) goto cleanup; /* qemu stores node names in the status XML portion */ - if (!(disk = virDomainDiskDefParse(xmlstr, NULL, data->driver->xmlopt, + if (!(disk = virDomainDiskDefParse(xmlstr, data->driver->xmlopt, VIR_DOMAIN_DEF_PARSE_STATUS))) goto cleanup; -- 2.23.0

Instead of using the virCapsPtr to get the default security model, pass this in via the parser config. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/conf/domain_conf.c | 14 +++++++------- src/conf/domain_conf.h | 1 + src/qemu/qemu_conf.c | 4 +++- src/qemu/qemu_conf.h | 3 ++- src/qemu/qemu_driver.c | 11 ++++++++++- tests/testutilsqemu.c | 2 +- 6 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f037702ac2..8acc91de74 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8911,13 +8911,12 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, static int virSecurityLabelDefsParseXML(virDomainDefPtr def, xmlXPathContextPtr ctxt, - virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, unsigned int flags) { VIR_XPATH_NODE_AUTORESTORE(ctxt); size_t i = 0, j; int n; - virCapsHostPtr host = &caps->host; g_autofree xmlNodePtr *list = NULL; /* Allocate a security labels based on XML */ @@ -8960,15 +8959,16 @@ virSecurityLabelDefsParseXML(virDomainDefPtr def, */ if (def->nseclabels == 1 && !def->seclabels[0]->model && - host->nsecModels > 0) { + xmlopt != NULL && + xmlopt->config.defSecModel != NULL) { if (def->seclabels[0]->type == VIR_DOMAIN_SECLABEL_NONE || (def->seclabels[0]->type == VIR_DOMAIN_SECLABEL_DYNAMIC && !def->seclabels[0]->baselabel && (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE))) { /* Copy model from host. */ VIR_DEBUG("Found seclabel without a model, using '%s'", - host->secModels[0].model); - def->seclabels[0]->model = g_strdup(host->secModels[0].model); + xmlopt->config.defSecModel); + def->seclabels[0]->model = g_strdup(xmlopt->config.defSecModel); if (STREQ(def->seclabels[0]->model, "none") && flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) { @@ -19733,7 +19733,7 @@ virDomainMemorytuneDefParse(virDomainDefPtr def, static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, xmlXPathContextPtr ctxt, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, virDomainXMLOptionPtr xmlopt, unsigned int flags) { @@ -19841,7 +19841,7 @@ virDomainDefParseXML(xmlDocPtr xml, /* analysis of security label, done early even though we format it * late, so devices can refer to this for defaults */ if (!(flags & VIR_DOMAIN_DEF_PARSE_SKIP_SECLABEL)) { - if (virSecurityLabelDefsParseXML(def, ctxt, caps, flags) == -1) + if (virSecurityLabelDefsParseXML(def, ctxt, xmlopt, flags) == -1) goto error; } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index e85d3bd5b5..af57e288e9 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2707,6 +2707,7 @@ struct _virDomainDefParserConfig { unsigned char macPrefix[VIR_MAC_PREFIX_BUFLEN]; virArch defArch; const char *netPrefix; + const char *defSecModel; }; typedef void *(*virDomainXMLPrivateDataAllocFunc)(void *); diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 53658c80e8..053bcc7e02 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1191,9 +1191,11 @@ virQEMUDriverIsPrivileged(virQEMUDriverPtr driver) } virDomainXMLOptionPtr -virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver) +virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver, + const char *defsecmodel) { virQEMUDriverDomainDefParserConfig.priv = driver; + virQEMUDriverDomainDefParserConfig.defSecModel = defsecmodel; return virDomainXMLOptionNew(&virQEMUDriverDomainDefParserConfig, &virQEMUDriverPrivateDataCallbacks, &virQEMUDriverDomainXMLNamespace, diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 7c56226b8c..8b6c2a95d4 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -366,7 +366,8 @@ int qemuRemoveSharedDisk(virQEMUDriverPtr driver, int qemuSetUnprivSGIO(virDomainDeviceDefPtr dev); int qemuDriverAllocateID(virQEMUDriverPtr driver); -virDomainXMLOptionPtr virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver); +virDomainXMLOptionPtr virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver, + const char *defsecmodel); int qemuTranslateSnapshotDiskSourcePool(virDomainSnapshotDiskDefPtr def); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 891ca28d94..93a92dad36 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -656,6 +656,8 @@ qemuStateInitialize(bool privileged, g_autofree char *memoryBackingPath = NULL; bool autostart = true; size_t i; + const char *defsecmodel = NULL; + g_autofree virSecurityManagerPtr *sec_managers = NULL; if (VIR_ALLOC(qemu_driver) < 0) return VIR_DRV_STATE_INIT_ERROR; @@ -916,7 +918,14 @@ qemuStateInitialize(bool privileged, if ((qemu_driver->caps = virQEMUDriverCreateCapabilities(qemu_driver)) == NULL) goto error; - if (!(qemu_driver->xmlopt = virQEMUDriverCreateXMLConf(qemu_driver))) + if (!(sec_managers = qemuSecurityGetNested(qemu_driver->securityManager))) + goto error; + + if (sec_managers[0] != NULL) + defsecmodel = qemuSecurityGetModel(sec_managers[0]); + + if (!(qemu_driver->xmlopt = virQEMUDriverCreateXMLConf(qemu_driver, + defsecmodel))) goto error; /* If hugetlbfs is present, then we need to create a sub-directory within diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 0ca690a1ed..c24b3098a5 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -402,7 +402,7 @@ int qemuTestDriverInit(virQEMUDriver *driver) if (!driver->qemuCapsCache) goto error; - driver->xmlopt = virQEMUDriverCreateXMLConf(driver); + driver->xmlopt = virQEMUDriverCreateXMLConf(driver, "none"); if (!driver->xmlopt) goto error; -- 2.23.0

The virCapsPtr param is not used by any of the virt drivers providing this callback. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/bhyve/bhyve_domain.c | 1 - src/conf/domain_conf.c | 2 +- src/conf/domain_conf.h | 1 - src/qemu/qemu_domain.c | 1 - 4 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c index eebf5a7650..a321be54f4 100644 --- a/src/bhyve/bhyve_domain.c +++ b/src/bhyve/bhyve_domain.c @@ -167,7 +167,6 @@ bhyveDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, static int bhyveDomainDefAssignAddresses(virDomainDef *def, - virCapsPtr caps G_GNUC_UNUSED, unsigned int parseFlags G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED, void *parseOpaque G_GNUC_UNUSED) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 8acc91de74..8dd1ff1017 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5870,7 +5870,7 @@ virDomainDefPostParse(virDomainDefPtr def, goto cleanup; if (xmlopt->config.assignAddressesCallback) { - ret = xmlopt->config.assignAddressesCallback(def, caps, parseFlags, + ret = xmlopt->config.assignAddressesCallback(def, parseFlags, xmlopt->config.priv, data.parseOpaque); if (virDomainDefPostParseCheckFailure(def, parseFlags, ret) < 0) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index af57e288e9..7e925f45d8 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2660,7 +2660,6 @@ typedef int (*virDomainDeviceDefPostParseCallback)(virDomainDeviceDefPtr dev, * @opaque is opaque data set by driver (usually pointer to driver * private data). */ typedef int (*virDomainDefAssignAddressesCallback)(virDomainDef *def, - virCapsPtr caps, unsigned int parseFlags, void *opaque, void *parseOpaque); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 0076349558..362d644475 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -8116,7 +8116,6 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, static int qemuDomainDefAssignAddresses(virDomainDef *def, - virCapsPtr caps G_GNUC_UNUSED, unsigned int parseFlags G_GNUC_UNUSED, void *opaque, void *parseOpaque) -- 2.23.0

The QEMU impl of the callback can directly use the QEMU capabilities cache to resolve the emulator binary name, allowing virCapsPtr to be dropped. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/conf/domain_conf.c | 2 +- src/conf/domain_conf.h | 1 - src/qemu/qemu_capabilities.c | 28 ++++++++++++++++++++-------- src/qemu/qemu_capabilities.h | 2 ++ src/qemu/qemu_domain.c | 11 +++++++---- tests/testutilsqemu.c | 16 ++++++++++++++++ 6 files changed, 46 insertions(+), 14 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 8dd1ff1017..7327752810 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5824,7 +5824,7 @@ virDomainDefPostParse(virDomainDefPtr def, /* call the basic post parse callback */ if (xmlopt->config.domainPostParseBasicCallback) { - ret = xmlopt->config.domainPostParseBasicCallback(def, caps, + ret = xmlopt->config.domainPostParseBasicCallback(def, xmlopt->config.priv); if (virDomainDefPostParseCheckFailure(def, parseFlags, ret) < 0) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 7e925f45d8..cdbd42351f 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2627,7 +2627,6 @@ typedef enum { * parseOpaque is used. This callback is run prior to * virDomainDefPostParseCallback. */ typedef int (*virDomainDefPostParseBasicCallback)(virDomainDefPtr def, - virCapsPtr caps, void *opaque); /* Called once after everything else has been parsed, for adjusting diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 7a62dfb1a2..bfe59a1eff 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -799,16 +799,12 @@ virQEMUCapsFindBinaryForArch(virArch hostarch, return ret; } -static int -virQEMUCapsInitGuest(virCapsPtr caps, - virFileCachePtr cache, - virArch hostarch, - virArch guestarch) + +char * +virQEMUCapsGetDefaultEmulator(virArch hostarch, + virArch guestarch) { char *binary = NULL; - virQEMUCapsPtr qemuCaps = NULL; - int ret = -1; - /* Check for existence of base emulator, or alternate base * which can be used with magic cpu choice */ @@ -819,6 +815,22 @@ virQEMUCapsInitGuest(virCapsPtr caps, if (virQEMUCapsGuestIsNative(hostarch, guestarch) && !binary) binary = g_strdup("/usr/libexec/qemu-kvm"); + return binary; +} + + +static int +virQEMUCapsInitGuest(virCapsPtr caps, + virFileCachePtr cache, + virArch hostarch, + virArch guestarch) +{ + char *binary = NULL; + virQEMUCapsPtr qemuCaps = NULL; + int ret = -1; + + binary = virQEMUCapsGetDefaultEmulator(hostarch, guestarch); + /* Ignore binary if extracting version info fails */ if (binary) { if (!(qemuCaps = virQEMUCapsCacheLookup(cache, binary))) { diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index a8a5c38d73..9b380574f5 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -627,6 +627,8 @@ const char *virQEMUCapsGetMachineDefaultCPU(virQEMUCapsPtr qemuCaps, void virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuCaps, virDomainVirtType virtType, const char *machineType); +char * virQEMUCapsGetDefaultEmulator(virArch hostarch, + virArch guestarch); virFileCachePtr virQEMUCapsCacheNew(const char *libDir, const char *cacheDir, diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 362d644475..3c06b8a104 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4677,13 +4677,16 @@ qemuDomainDefTsegPostParse(virDomainDefPtr def, static int qemuDomainDefPostParseBasic(virDomainDefPtr def, - virCapsPtr caps, void *opaque G_GNUC_UNUSED) { + virQEMUDriverPtr driver = opaque; + /* check for emulator and create a default one if needed */ - if (!def->emulator && - !(def->emulator = virDomainDefGetDefaultEmulator(def, caps))) - return 1; + if (!def->emulator) { + if (!(def->emulator = virQEMUCapsGetDefaultEmulator( + driver->hostarch, def->os.arch))) + return 1; + } return 0; } diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index c24b3098a5..38be2cfe42 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -93,6 +93,22 @@ static const char *const *kvm_machines[VIR_ARCH_LAST] = { [VIR_ARCH_S390X] = s390x_machines, }; + +char * +virFindFileInPath(const char *file) +{ + if (g_str_has_prefix(file, "qemu-system") || + g_str_equal(file, "qemu-kvm")) { + return g_strdup_printf("/usr/bin/%s", file); + } + + /* Nothing in tests should be relying on real files + * in host OS, so we return NULL as to try to force + * an error in such a case + */ + return NULL; +} + static int testQemuAddGuest(virCapsPtr caps, virArch arch) -- 2.23.0

The only user of this callback did not require the virCapsPtr parameter. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/conf/domain_conf.c | 4 ++-- src/conf/domain_conf.h | 1 - src/qemu/qemu_domain.c | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7327752810..164c313ac6 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5498,7 +5498,7 @@ virDomainDeviceDefPostParseOne(virDomainDeviceDefPtr dev, int ret; if (!parseOpaque && xmlopt->config.domainPostParseDataAlloc) { - if (xmlopt->config.domainPostParseDataAlloc(def, caps, flags, + if (xmlopt->config.domainPostParseDataAlloc(def, flags, xmlopt->config.priv, &data) < 0) return -1; @@ -5833,7 +5833,7 @@ virDomainDefPostParse(virDomainDefPtr def, if (!data.parseOpaque && xmlopt->config.domainPostParseDataAlloc) { - ret = xmlopt->config.domainPostParseDataAlloc(def, caps, parseFlags, + ret = xmlopt->config.domainPostParseDataAlloc(def, parseFlags, xmlopt->config.priv, &data.parseOpaque); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index cdbd42351f..86d0b47a66 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2664,7 +2664,6 @@ typedef int (*virDomainDefAssignAddressesCallback)(virDomainDef *def, void *parseOpaque); typedef int (*virDomainDefPostParseDataAlloc)(const virDomainDef *def, - virCapsPtr caps, unsigned int parseFlags, void *opaque, void **parseOpaque); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 3c06b8a104..70683eb83a 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -8143,7 +8143,6 @@ qemuDomainDefAssignAddresses(virDomainDef *def, static int qemuDomainPostParseDataAlloc(const virDomainDef *def, - virCapsPtr caps G_GNUC_UNUSED, unsigned int parseFlags G_GNUC_UNUSED, void *opaque, void **parseOpaque) -- 2.23.0

No impl of this callback requires the virCapsPtr anymore. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/bhyve/bhyve_domain.c | 1 - src/conf/domain_conf.c | 2 +- src/conf/domain_conf.h | 1 - src/libxl/libxl_domain.c | 1 - src/lxc/lxc_domain.c | 1 - src/openvz/openvz_conf.c | 1 - src/phyp/phyp_driver.c | 1 - src/qemu/qemu_domain.c | 1 - src/vmware/vmware_driver.c | 1 - src/vmx/vmx.c | 1 - src/vz/vz_driver.c | 1 - 11 files changed, 1 insertion(+), 11 deletions(-) diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c index a321be54f4..c8d33b4e00 100644 --- a/src/bhyve/bhyve_domain.c +++ b/src/bhyve/bhyve_domain.c @@ -75,7 +75,6 @@ bhyveDomainDefNeedsISAController(virDomainDefPtr def) static int bhyveDomainDefPostParse(virDomainDefPtr def, - virCapsPtr _caps G_GNUC_UNUSED, unsigned int parseFlags G_GNUC_UNUSED, void *opaque, void *parseOpaque G_GNUC_UNUSED) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 164c313ac6..f2452f6df2 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5849,7 +5849,7 @@ virDomainDefPostParse(virDomainDefPtr def, /* call the domain config callback */ if (xmlopt->config.domainPostParseCallback) { - ret = xmlopt->config.domainPostParseCallback(def, caps, parseFlags, + ret = xmlopt->config.domainPostParseCallback(def, parseFlags, xmlopt->config.priv, data.parseOpaque); if (virDomainDefPostParseCheckFailure(def, parseFlags, ret) < 0) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 86d0b47a66..7a5bfd00ed 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2638,7 +2638,6 @@ typedef int (*virDomainDefPostParseBasicCallback)(virDomainDefPtr def, * value and the failure is noted in def->postParseFailed. Drivers should then * re-run the post parse callback when attempting to use such definition. */ typedef int (*virDomainDefPostParseCallback)(virDomainDefPtr def, - virCapsPtr caps, unsigned int parseFlags, void *opaque, void *parseOpaque); diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index dfac04bf59..2524d17eb4 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -367,7 +367,6 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, static int libxlDomainDefPostParse(virDomainDefPtr def, - virCapsPtr caps G_GNUC_UNUSED, unsigned int parseFlags G_GNUC_UNUSED, void *opaque, void *parseOpaque G_GNUC_UNUSED) diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c index bc54beeadf..8b27bc95af 100644 --- a/src/lxc/lxc_domain.c +++ b/src/lxc/lxc_domain.c @@ -351,7 +351,6 @@ virDomainXMLPrivateDataCallbacks virLXCDriverPrivateDataCallbacks = { static int virLXCDomainDefPostParse(virDomainDefPtr def, - virCapsPtr _caps G_GNUC_UNUSED, unsigned int parseFlags G_GNUC_UNUSED, void *opaque, void *parseOpaque G_GNUC_UNUSED) diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index 5060e704a5..5057f9652e 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -1082,7 +1082,6 @@ int openvzGetVEID(const char *name) static int openvzDomainDefPostParse(virDomainDefPtr def, - virCapsPtr caps G_GNUC_UNUSED, unsigned int parseFlags G_GNUC_UNUSED, void *opaque, void *parseOpaque G_GNUC_UNUSED) diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 05860b7dbe..3c809378c3 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -1062,7 +1062,6 @@ openSSHSession(virConnectPtr conn, virConnectAuthPtr auth, static int phypDomainDefPostParse(virDomainDefPtr def, - virCapsPtr caps G_GNUC_UNUSED, unsigned int parseFlags G_GNUC_UNUSED, void *opaque, void *parseOpaque G_GNUC_UNUSED) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 70683eb83a..6aa50dda0b 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4694,7 +4694,6 @@ qemuDomainDefPostParseBasic(virDomainDefPtr def, static int qemuDomainDefPostParse(virDomainDefPtr def, - virCapsPtr caps G_GNUC_UNUSED, unsigned int parseFlags, void *opaque, void *parseOpaque G_GNUC_UNUSED) diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index 308a941f8a..301f43d9e8 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -117,7 +117,6 @@ vmwareDataFreeFunc(void *data) static int vmwareDomainDefPostParse(virDomainDefPtr def, - virCapsPtr caps G_GNUC_UNUSED, unsigned int parseFlags G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED, void *parseOpaque G_GNUC_UNUSED) diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 958b168891..3f8324ce89 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -530,7 +530,6 @@ VIR_ENUM_IMPL(virVMXControllerModelSCSI, static int virVMXDomainDefPostParse(virDomainDefPtr def, - virCapsPtr _caps G_GNUC_UNUSED, unsigned int parseFlags G_GNUC_UNUSED, void *opaque, void *parseOpaque G_GNUC_UNUSED) diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index a0d1efb9dd..f54bdd49db 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -241,7 +241,6 @@ vzDomainDefAddDefaultInputDevices(virDomainDefPtr def) static int vzDomainDefPostParse(virDomainDefPtr def, - virCapsPtr caps G_GNUC_UNUSED, unsigned int parseFlags G_GNUC_UNUSED, void *opaque, void *parseOpaque G_GNUC_UNUSED) -- 2.23.0

None of the impls of this callback require the virCapsPtr param. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/bhyve/bhyve_domain.c | 1 - src/conf/domain_conf.c | 20 +++++++------------- src/conf/domain_conf.h | 1 - src/libxl/libxl_domain.c | 1 - src/lxc/lxc_domain.c | 1 - src/openvz/openvz_conf.c | 1 - src/phyp/phyp_driver.c | 1 - src/qemu/qemu_domain.c | 1 - src/vmware/vmware_driver.c | 1 - src/vmx/vmx.c | 1 - src/vz/vz_driver.c | 1 - 11 files changed, 7 insertions(+), 23 deletions(-) diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c index c8d33b4e00..82910ea261 100644 --- a/src/bhyve/bhyve_domain.c +++ b/src/bhyve/bhyve_domain.c @@ -132,7 +132,6 @@ bhyveDomainDiskDefAssignAddress(bhyveConnPtr driver, static int bhyveDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, const virDomainDef *def, - virCapsPtr caps G_GNUC_UNUSED, unsigned int parseFlags G_GNUC_UNUSED, void *opaque, void *parseOpaque G_GNUC_UNUSED) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f2452f6df2..ef6c8d3f75 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5207,7 +5207,6 @@ virDomainVsockDefPostParse(virDomainVsockDefPtr vsock) static int virDomainDeviceDefPostParseCommon(virDomainDeviceDefPtr dev, const virDomainDef *def, - virCapsPtr caps G_GNUC_UNUSED, unsigned int parseFlags G_GNUC_UNUSED, virDomainXMLOptionPtr xmlopt) { @@ -5462,7 +5461,6 @@ virDomainDeviceDefPostParseCheckFeatures(virDomainDeviceDefPtr dev, static int virDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, const virDomainDef *def, - virCapsPtr caps, unsigned int flags, virDomainXMLOptionPtr xmlopt, void *parseOpaque) @@ -5470,14 +5468,14 @@ virDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, int ret; if (xmlopt->config.devicesPostParseCallback) { - ret = xmlopt->config.devicesPostParseCallback(dev, def, caps, flags, + ret = xmlopt->config.devicesPostParseCallback(dev, def, flags, xmlopt->config.priv, parseOpaque); if (ret < 0) return ret; } - if ((ret = virDomainDeviceDefPostParseCommon(dev, def, caps, flags, xmlopt)) < 0) + if ((ret = virDomainDeviceDefPostParseCommon(dev, def, flags, xmlopt)) < 0) return ret; if (virDomainDeviceDefPostParseCheckFeatures(dev, xmlopt) < 0) @@ -5489,7 +5487,6 @@ virDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, static int virDomainDeviceDefPostParseOne(virDomainDeviceDefPtr dev, const virDomainDef *def, - virCapsPtr caps, unsigned int flags, virDomainXMLOptionPtr xmlopt, void *parseOpaque) @@ -5505,7 +5502,7 @@ virDomainDeviceDefPostParseOne(virDomainDeviceDefPtr dev, parseOpaque = data; } - ret = virDomainDeviceDefPostParse(dev, def, caps, flags, xmlopt, parseOpaque); + ret = virDomainDeviceDefPostParse(dev, def, flags, xmlopt, parseOpaque); if (data && xmlopt->config.domainPostParseDataFree) xmlopt->config.domainPostParseDataFree(data); @@ -5515,7 +5512,6 @@ virDomainDeviceDefPostParseOne(virDomainDeviceDefPtr dev, struct virDomainDefPostParseDeviceIteratorData { - virCapsPtr caps; virDomainXMLOptionPtr xmlopt; void *parseOpaque; unsigned int parseFlags; @@ -5529,7 +5525,7 @@ virDomainDefPostParseDeviceIterator(virDomainDefPtr def, void *opaque) { struct virDomainDefPostParseDeviceIteratorData *data = opaque; - return virDomainDeviceDefPostParse(dev, def, data->caps, + return virDomainDeviceDefPostParse(dev, def, data->parseFlags, data->xmlopt, data->parseOpaque); } @@ -5806,7 +5802,7 @@ virDomainDefPostParseCheckFailure(virDomainDefPtr def, int virDomainDefPostParse(virDomainDefPtr def, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, unsigned int parseFlags, virDomainXMLOptionPtr xmlopt, void *parseOpaque) @@ -5814,7 +5810,6 @@ virDomainDefPostParse(virDomainDefPtr def, int ret = -1; bool localParseOpaque = false; struct virDomainDefPostParseDeviceIteratorData data = { - .caps = caps, .xmlopt = xmlopt, .parseFlags = parseFlags, .parseOpaque = parseOpaque, @@ -7117,7 +7112,6 @@ virDomainDefValidate(virDomainDefPtr def, virDomainXMLOptionPtr xmlopt) { struct virDomainDefPostParseDeviceIteratorData data = { - .caps = caps, .xmlopt = xmlopt, .parseFlags = parseFlags, }; @@ -16379,7 +16373,7 @@ virDomainVsockDefParseXML(virDomainXMLOptionPtr xmlopt, virDomainDeviceDefPtr virDomainDeviceDefParse(const char *xmlStr, const virDomainDef *def, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, virDomainXMLOptionPtr xmlopt, void *parseOpaque, unsigned int flags) @@ -16537,7 +16531,7 @@ virDomainDeviceDefParse(const char *xmlStr, } /* callback to fill driver specific device aspects */ - if (virDomainDeviceDefPostParseOne(dev, def, caps, flags, + if (virDomainDeviceDefPostParseOne(dev, def, flags, xmlopt, parseOpaque) < 0) return NULL; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 7a5bfd00ed..9864296be1 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2648,7 +2648,6 @@ typedef int (*virDomainDefPostParseCallback)(virDomainDefPtr def, * private data). */ typedef int (*virDomainDeviceDefPostParseCallback)(virDomainDeviceDefPtr dev, const virDomainDef *def, - virCapsPtr caps, unsigned int parseFlags, void *opaque, void *parseOpaque); diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 2524d17eb4..dfc8d8b611 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -278,7 +278,6 @@ virDomainXMLPrivateDataCallbacks libxlDomainXMLPrivateDataCallbacks = { static int libxlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, const virDomainDef *def, - virCapsPtr caps G_GNUC_UNUSED, unsigned int parseFlags G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED, void *parseOpaque G_GNUC_UNUSED) diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c index 8b27bc95af..2439ec4f4b 100644 --- a/src/lxc/lxc_domain.c +++ b/src/lxc/lxc_domain.c @@ -376,7 +376,6 @@ virLXCDomainDefPostParse(virDomainDefPtr def, static int virLXCDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, const virDomainDef *def G_GNUC_UNUSED, - virCapsPtr caps G_GNUC_UNUSED, unsigned int parseFlags G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED, void *parseOpaque G_GNUC_UNUSED) diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index 5057f9652e..a15d68d37f 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -1103,7 +1103,6 @@ openvzDomainDefPostParse(virDomainDefPtr def, static int openvzDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, const virDomainDef *def G_GNUC_UNUSED, - virCapsPtr caps G_GNUC_UNUSED, unsigned int parseFlags G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED, void *parseOpaque G_GNUC_UNUSED) diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 3c809378c3..b22063642e 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -1079,7 +1079,6 @@ phypDomainDefPostParse(virDomainDefPtr def, static int phypDomainDeviceDefPostParse(virDomainDeviceDefPtr dev G_GNUC_UNUSED, const virDomainDef *def G_GNUC_UNUSED, - virCapsPtr caps G_GNUC_UNUSED, unsigned int parseFlags G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED, void *parseOpaque G_GNUC_UNUSED) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 6aa50dda0b..8ac6a0f842 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -8032,7 +8032,6 @@ qemuDomainHostdevDefPostParse(virDomainHostdevDefPtr hostdev, static int qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, const virDomainDef *def, - virCapsPtr caps G_GNUC_UNUSED, unsigned int parseFlags, void *opaque, void *parseOpaque) diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index 301f43d9e8..eb2fcd438b 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -133,7 +133,6 @@ vmwareDomainDefPostParse(virDomainDefPtr def, static int vmwareDomainDeviceDefPostParse(virDomainDeviceDefPtr dev G_GNUC_UNUSED, const virDomainDef *def G_GNUC_UNUSED, - virCapsPtr caps G_GNUC_UNUSED, unsigned int parseFlags G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED, void *parseOpaque G_GNUC_UNUSED) diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 3f8324ce89..093092b701 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -546,7 +546,6 @@ virVMXDomainDefPostParse(virDomainDefPtr def, static int virVMXDomainDevicesDefPostParse(virDomainDeviceDefPtr dev G_GNUC_UNUSED, const virDomainDef *def G_GNUC_UNUSED, - virCapsPtr caps G_GNUC_UNUSED, unsigned int parseFlags G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED, void *parseOpaque G_GNUC_UNUSED) diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index f54bdd49db..78aa85825a 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -271,7 +271,6 @@ vzDomainDefValidate(const virDomainDef *def, static int vzDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, const virDomainDef *def, - virCapsPtr caps G_GNUC_UNUSED, unsigned int parseFlags G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED, void *parseOpaque G_GNUC_UNUSED) -- 2.23.0

None of the impls of this callback require the virCapsPtr param. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/conf/domain_conf.c | 4 ++-- src/conf/domain_conf.h | 1 - src/qemu/qemu_domain.c | 1 - src/vz/vz_driver.c | 1 - 4 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ef6c8d3f75..7431aad0cf 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7107,7 +7107,7 @@ virDomainDefValidateInternal(const virDomainDef *def, */ int virDomainDefValidate(virDomainDefPtr def, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, unsigned int parseFlags, virDomainXMLOptionPtr xmlopt) { @@ -7122,7 +7122,7 @@ virDomainDefValidate(virDomainDefPtr def, /* call the domain config callback */ if (xmlopt->config.domainValidateCallback && - xmlopt->config.domainValidateCallback(def, caps, xmlopt->config.priv) < 0) + xmlopt->config.domainValidateCallback(def, xmlopt->config.priv) < 0) return -1; /* iterate the devices */ diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 9864296be1..bbe73f1182 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2671,7 +2671,6 @@ typedef void (*virDomainDefPostParseDataFree)(void *parseOpaque); * for configurations that were previously accepted. This shall not modify the * config. */ typedef int (*virDomainDefValidateCallback)(const virDomainDef *def, - virCapsPtr caps, void *opaque); /* Called once per device, for adjusting per-device settings while diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 8ac6a0f842..49b6008d5c 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4972,7 +4972,6 @@ qemuDomainValidateCpuCount(const virDomainDef *def, static int qemuDomainDefValidate(const virDomainDef *def, - virCapsPtr caps G_GNUC_UNUSED, void *opaque) { virQEMUDriverPtr driver = opaque; diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 78aa85825a..35baab1b82 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -259,7 +259,6 @@ vzDomainDefPostParse(virDomainDefPtr def, static int vzDomainDefValidate(const virDomainDef *def, - virCapsPtr caps G_GNUC_UNUSED, void *opaque) { if (vzCheckUnsupportedControllers(def, opaque) < 0) -- 2.23.0

This parameter is now unused and can be removed entirely. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/bhyve/bhyve_driver.c | 16 ++-------------- src/conf/checkpoint_conf.c | 4 ++-- src/conf/domain_conf.c | 26 +++++++++++--------------- src/conf/domain_conf.h | 4 ---- src/conf/snapshot_conf.c | 6 +++--- src/esx/esx_driver.c | 4 ++-- src/hyperv/hyperv_driver.c | 2 +- src/libxl/libxl_domain.c | 12 ++++++------ src/libxl/libxl_driver.c | 8 ++++---- src/libxl/libxl_migration.c | 4 ++-- src/lxc/lxc_driver.c | 4 ++-- src/lxc/lxc_process.c | 12 ++++++------ src/openvz/openvz_driver.c | 4 ++-- src/phyp/phyp_driver.c | 2 +- src/qemu/qemu_domain.c | 2 +- src/security/security_apparmor.c | 2 +- src/test/test_driver.c | 6 +++--- src/vbox/vbox_common.c | 2 +- src/vmware/vmware_driver.c | 4 ++-- src/vz/vz_driver.c | 4 ++-- tests/bhyveargv2xmltest.c | 2 +- tests/lxcconf2xmltest.c | 2 +- tests/openvzutilstest.c | 2 +- tests/qemuhotplugtest.c | 6 +++--- tests/qemuxml2xmltest.c | 2 +- tests/testutils.c | 2 +- tests/vmx2xmltest.c | 2 +- tests/xlconfigtest.c | 2 +- tests/xmconfigtest.c | 2 +- 29 files changed, 65 insertions(+), 85 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 18b5d1e950..8432044b60 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -480,7 +480,6 @@ bhyveDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) { bhyveConnPtr privconn = domain->conn->privateData; virDomainObjPtr vm; - virCapsPtr caps = NULL; char *ret = NULL; virCheckFlags(VIR_DOMAIN_XML_COMMON_FLAGS, NULL); @@ -491,14 +490,9 @@ bhyveDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) if (virDomainGetXMLDescEnsureACL(domain->conn, vm->def, flags) < 0) goto cleanup; - caps = bhyveDriverGetCapabilities(privconn); - if (!caps) - goto cleanup; - - ret = virDomainDefFormat(vm->def, privconn->xmlopt, caps, + ret = virDomainDefFormat(vm->def, privconn->xmlopt, virDomainDefFormatConvertXMLFlags(flags)); - virObjectUnref(caps); cleanup: virDomainObjEndAPI(&vm); return ret; @@ -1561,7 +1555,6 @@ bhyveConnectDomainXMLFromNative(virConnectPtr conn, char *xml = NULL; virDomainDefPtr def = NULL; bhyveConnPtr privconn = conn->privateData; - virCapsPtr capabilities = NULL; unsigned caps = bhyveDriverGetCaps(conn); virCheckFlags(0, NULL); @@ -1569,10 +1562,6 @@ bhyveConnectDomainXMLFromNative(virConnectPtr conn, if (virConnectDomainXMLFromNativeEnsureACL(conn) < 0) return NULL; - capabilities = bhyveDriverGetCapabilities(privconn); - if (!capabilities) - return NULL; - if (STRNEQ(nativeFormat, BHYVE_CONFIG_FORMAT_ARGV)) { virReportError(VIR_ERR_INVALID_ARG, _("unsupported config type %s"), nativeFormat); @@ -1583,10 +1572,9 @@ bhyveConnectDomainXMLFromNative(virConnectPtr conn, if (def == NULL) goto cleanup; - xml = virDomainDefFormat(def, privconn->xmlopt, capabilities, 0); + xml = virDomainDefFormat(def, privconn->xmlopt, 0); cleanup: - virObjectUnref(capabilities); virDomainDefFree(def); return xml; } diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c index cb2d83796c..37cc8e5e6c 100644 --- a/src/conf/checkpoint_conf.c +++ b/src/conf/checkpoint_conf.c @@ -446,7 +446,7 @@ virDomainCheckpointDiskDefFormat(virBufferPtr buf, static int virDomainCheckpointDefFormatInternal(virBufferPtr buf, virDomainCheckpointDefPtr def, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, virDomainXMLOptionPtr xmlopt, unsigned int flags) { @@ -490,7 +490,7 @@ virDomainCheckpointDefFormatInternal(virBufferPtr buf, if (!(flags & VIR_DOMAIN_CHECKPOINT_FORMAT_NO_DOMAIN) && virDomainDefFormatInternal(def->parent.dom, xmlopt, - caps, buf, domainflags) < 0) + buf, domainflags) < 0) goto error; virBufferAdjustIndent(buf, -2); diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7431aad0cf..44e56976d9 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -23559,8 +23559,8 @@ virDomainDefCheckABIStabilityFlags(virDomainDefPtr src, error: virErrorPreserveLast(&err); - strSrc = virDomainDefFormat(src, xmlopt, NULL, 0); - strDst = virDomainDefFormat(dst, xmlopt, NULL, 0); + strSrc = virDomainDefFormat(src, xmlopt, 0); + strDst = virDomainDefFormat(dst, xmlopt, 0); VIR_DEBUG("XMLs that failed stability check were: src=\"%s\", dst=\"%s\"", NULLSTR(strSrc), NULLSTR(strDst)); @@ -28247,11 +28247,10 @@ virDomainDefFormatFeatures(virBufferPtr buf, int virDomainDefFormatInternal(virDomainDefPtr def, virDomainXMLOptionPtr xmlopt, - virCapsPtr caps, virBufferPtr buf, unsigned int flags) { - return virDomainDefFormatInternalSetRootName(def, xmlopt, caps, buf, + return virDomainDefFormatInternalSetRootName(def, xmlopt, buf, "domain", flags); } @@ -28263,7 +28262,6 @@ virDomainDefFormatInternal(virDomainDefPtr def, int virDomainDefFormatInternalSetRootName(virDomainDefPtr def, virDomainXMLOptionPtr xmlopt, - virCapsPtr caps G_GNUC_UNUSED, virBufferPtr buf, const char *rootname, unsigned int flags) @@ -28802,13 +28800,12 @@ unsigned int virDomainDefFormatConvertXMLFlags(unsigned int flags) char * virDomainDefFormat(virDomainDefPtr def, virDomainXMLOptionPtr xmlopt, - virCapsPtr caps, unsigned int flags) { virBuffer buf = VIR_BUFFER_INITIALIZER; virCheckFlags(VIR_DOMAIN_DEF_FORMAT_COMMON_FLAGS, NULL); - if (virDomainDefFormatInternal(def, xmlopt, caps, &buf, flags) < 0) + if (virDomainDefFormatInternal(def, xmlopt, &buf, flags) < 0) return NULL; return virBufferContentAndReset(&buf); @@ -28818,7 +28815,6 @@ virDomainDefFormat(virDomainDefPtr def, char * virDomainObjFormat(virDomainObjPtr obj, virDomainXMLOptionPtr xmlopt, - virCapsPtr caps, unsigned int flags) { g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; @@ -28843,7 +28839,7 @@ virDomainObjFormat(virDomainObjPtr obj, xmlopt->privateData.format(&buf, obj) < 0) goto error; - if (virDomainDefFormatInternal(obj->def, xmlopt, caps, &buf, flags) < 0) + if (virDomainDefFormatInternal(obj->def, xmlopt, &buf, flags) < 0) goto error; virBufferAdjustIndent(&buf, -2); @@ -29004,12 +29000,12 @@ virDomainDefSaveXML(virDomainDefPtr def, int virDomainDefSave(virDomainDefPtr def, virDomainXMLOptionPtr xmlopt, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, const char *configDir) { g_autofree char *xml = NULL; - if (!(xml = virDomainDefFormat(def, xmlopt, caps, VIR_DOMAIN_DEF_FORMAT_SECURE))) + if (!(xml = virDomainDefFormat(def, xmlopt, VIR_DOMAIN_DEF_FORMAT_SECURE))) return -1; return virDomainDefSaveXML(def, configDir, xml); @@ -29018,7 +29014,7 @@ virDomainDefSave(virDomainDefPtr def, int virDomainObjSave(virDomainObjPtr obj, virDomainXMLOptionPtr xmlopt, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, const char *statusDir) { unsigned int flags = (VIR_DOMAIN_DEF_FORMAT_SECURE | @@ -29029,7 +29025,7 @@ virDomainObjSave(virDomainObjPtr obj, g_autofree char *xml = NULL; - if (!(xml = virDomainObjFormat(obj, xmlopt, caps, flags))) + if (!(xml = virDomainObjFormat(obj, xmlopt, flags))) return -1; return virDomainDefSaveXML(obj->def, statusDir, xml); @@ -29319,7 +29315,7 @@ virDomainUSBDeviceDefForeach(virDomainDefPtr def, * snapshots). */ virDomainDefPtr virDomainDefCopy(virDomainDefPtr src, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, virDomainXMLOptionPtr xmlopt, void *parseOpaque, bool migratable) @@ -29333,7 +29329,7 @@ virDomainDefCopy(virDomainDefPtr src, format_flags |= VIR_DOMAIN_DEF_FORMAT_INACTIVE | VIR_DOMAIN_DEF_FORMAT_MIGRATABLE; /* Easiest to clone via a round-trip through XML. */ - if (!(xml = virDomainDefFormat(src, xmlopt, caps, format_flags))) + if (!(xml = virDomainDefFormat(src, xmlopt, format_flags))) return NULL; return virDomainDefParseString(xml, caps, xmlopt, parseOpaque, parse_flags); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index bbe73f1182..b98fe5eba5 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3098,26 +3098,22 @@ unsigned int virDomainDefFormatConvertXMLFlags(unsigned int flags); char *virDomainDefFormat(virDomainDefPtr def, virDomainXMLOptionPtr xmlopt, - virCapsPtr caps, unsigned int flags) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); char *virDomainObjFormat(virDomainObjPtr obj, virDomainXMLOptionPtr xmlopt, - virCapsPtr caps, unsigned int flags) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); int virDomainDefFormatInternal(virDomainDefPtr def, virDomainXMLOptionPtr xmlopt, - virCapsPtr caps, virBufferPtr buf, unsigned int flags) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4); int virDomainDefFormatInternalSetRootName(virDomainDefPtr def, virDomainXMLOptionPtr xmlopt, - virCapsPtr caps, virBufferPtr buf, const char *rootname, unsigned int flags) diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index 0bf7d497e4..015d54a128 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -838,7 +838,7 @@ static int virDomainSnapshotDefFormatInternal(virBufferPtr buf, const char *uuidstr, virDomainSnapshotDefPtr def, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, virDomainXMLOptionPtr xmlopt, unsigned int flags) { @@ -892,7 +892,7 @@ virDomainSnapshotDefFormatInternal(virBufferPtr buf, if (def->parent.dom) { if (virDomainDefFormatInternal(def->parent.dom, xmlopt, - caps, buf, domainflags) < 0) + buf, domainflags) < 0) goto error; } else if (uuidstr) { virBufferAddLit(buf, "<domain>\n"); @@ -904,7 +904,7 @@ virDomainSnapshotDefFormatInternal(virBufferPtr buf, if (def->parent.inactiveDom) { if (virDomainDefFormatInternalSetRootName(def->parent.inactiveDom, xmlopt, - caps, buf, "inactiveDomain", + buf, "inactiveDomain", domainflags) < 0) goto error; } diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 2db89c7986..8e3da589c9 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -2648,7 +2648,7 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) if (powerState != esxVI_VirtualMachinePowerState_PoweredOff) def->id = id; - xml = virDomainDefFormat(def, priv->xmlopt, priv->caps, + xml = virDomainDefFormat(def, priv->xmlopt, virDomainDefFormatConvertXMLFlags(flags)); } @@ -2706,7 +2706,7 @@ esxConnectDomainXMLFromNative(virConnectPtr conn, const char *nativeFormat, def = virVMXParseConfig(&ctx, priv->xmlopt, priv->caps, nativeConfig); if (def) - xml = virDomainDefFormat(def, priv->xmlopt, priv->caps, + xml = virDomainDefFormat(def, priv->xmlopt, VIR_DOMAIN_DEF_FORMAT_INACTIVE); virDomainDefFree(def); diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index ff9370d728..c9d22ec7c4 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -887,7 +887,7 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) /* FIXME: devices section is totally missing */ /* XXX xmlopts must be non-NULL */ - xml = virDomainDefFormat(def, NULL, NULL, + xml = virDomainDefFormat(def, NULL, virDomainDefFormatConvertXMLFlags(flags)); cleanup: diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index dfc8d8b611..f4f1781bae 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -851,7 +851,7 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver, /* now that we know it's stopped call the hook if present */ if (virHookPresent(VIR_HOOK_DRIVER_LIBXL)) { - char *xml = virDomainDefFormat(vm->def, driver->xmlopt, cfg->caps, 0); + char *xml = virDomainDefFormat(vm->def, driver->xmlopt, 0); /* we can't stop the operation even if the script raised an error */ ignore_value(virHookCall(VIR_HOOK_DRIVER_LIBXL, vm->def->name, @@ -920,7 +920,7 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver, /* The "release" hook cleans up additional resources */ if (virHookPresent(VIR_HOOK_DRIVER_LIBXL)) { - char *xml = virDomainDefFormat(vm->def, driver->xmlopt, cfg->caps, 0); + char *xml = virDomainDefFormat(vm->def, driver->xmlopt, 0); /* we can't stop the operation even if the script raised an error */ ignore_value(virHookCall(VIR_HOOK_DRIVER_LIBXL, vm->def->name, @@ -1327,7 +1327,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver, /* Run an early hook to set-up missing devices */ if (virHookPresent(VIR_HOOK_DRIVER_LIBXL)) { - char *xml = virDomainDefFormat(vm->def, driver->xmlopt, cfg->caps, 0); + char *xml = virDomainDefFormat(vm->def, driver->xmlopt, 0); int hookret; hookret = virHookCall(VIR_HOOK_DRIVER_LIBXL, vm->def->name, @@ -1365,7 +1365,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver, /* now that we know it is about to start call the hook if present */ if (virHookPresent(VIR_HOOK_DRIVER_LIBXL)) { - char *xml = virDomainDefFormat(vm->def, driver->xmlopt, cfg->caps, 0); + char *xml = virDomainDefFormat(vm->def, driver->xmlopt, 0); int hookret; hookret = virHookCall(VIR_HOOK_DRIVER_LIBXL, vm->def->name, @@ -1450,7 +1450,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver, libxlDomainCreateChannelPTY(vm->def, cfg->ctx); #endif - if ((dom_xml = virDomainDefFormat(vm->def, driver->xmlopt, cfg->caps, 0)) == NULL) + if ((dom_xml = virDomainDefFormat(vm->def, driver->xmlopt, 0)) == NULL) goto destroy_dom; if (libxl_userdata_store(cfg->ctx, domid, "libvirt-xml", @@ -1478,7 +1478,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver, /* finally we can call the 'started' hook script if any */ if (virHookPresent(VIR_HOOK_DRIVER_LIBXL)) { - char *xml = virDomainDefFormat(vm->def, driver->xmlopt, cfg->caps, 0); + char *xml = virDomainDefFormat(vm->def, driver->xmlopt, 0); int hookret; hookret = virHookCall(VIR_HOOK_DRIVER_LIBXL, vm->def->name, diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index fac3c1db49..ed754452f0 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -459,7 +459,7 @@ libxlReconnectDomain(virDomainObjPtr vm, /* now that we know it's reconnected call the hook if present */ if (virHookPresent(VIR_HOOK_DRIVER_LIBXL) && STRNEQ("Domain-0", vm->def->name)) { - char *xml = virDomainDefFormat(vm->def, driver->xmlopt, cfg->caps, 0); + char *xml = virDomainDefFormat(vm->def, driver->xmlopt, 0); int hookret; /* we can't stop the operation even if the script raised an error */ @@ -1828,7 +1828,7 @@ libxlDoDomainSave(libxlDriverPrivatePtr driver, goto cleanup; } - if ((xml = virDomainDefFormat(vm->def, driver->xmlopt, cfg->caps, 0)) == NULL) + if ((xml = virDomainDefFormat(vm->def, driver->xmlopt, 0)) == NULL) goto cleanup; xml_len = strlen(xml) + 1; @@ -2652,7 +2652,7 @@ libxlDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) else def = vm->def; - ret = virDomainDefFormat(def, driver->xmlopt, cfg->caps, + ret = virDomainDefFormat(def, driver->xmlopt, virDomainDefFormatConvertXMLFlags(flags)); cleanup: @@ -2703,7 +2703,7 @@ libxlConnectDomainXMLFromNative(virConnectPtr conn, goto cleanup; } - xml = virDomainDefFormat(def, driver->xmlopt, cfg->caps, VIR_DOMAIN_DEF_FORMAT_INACTIVE); + xml = virDomainDefFormat(def, driver->xmlopt, VIR_DOMAIN_DEF_FORMAT_INACTIVE); cleanup: virDomainDefFree(def); diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c index 25a58f8018..f9bd004b2e 100644 --- a/src/libxl/libxl_migration.c +++ b/src/libxl/libxl_migration.c @@ -420,7 +420,7 @@ libxlDomainMigrationSrcBegin(virConnectPtr conn, if (!libxlDomainMigrationIsAllowed(def)) goto endjob; - xml = virDomainDefFormat(def, driver->xmlopt, cfg->caps, VIR_DOMAIN_DEF_FORMAT_SECURE); + xml = virDomainDefFormat(def, driver->xmlopt, VIR_DOMAIN_DEF_FORMAT_SECURE); /* Valid xml means success! EndJob in the confirm phase */ if (xml) goto cleanup; @@ -494,7 +494,7 @@ libxlDomainMigrationPrepareAny(virConnectPtr dconn, char *xml; int hookret; - if (!(xml = virDomainDefFormat(*def, driver->xmlopt, cfg->caps, + if (!(xml = virDomainDefFormat(*def, driver->xmlopt, VIR_DOMAIN_XML_SECURE | VIR_DOMAIN_XML_MIGRATABLE))) return -1; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index f28e20d756..4639e603e0 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -987,7 +987,7 @@ static char *lxcDomainGetXMLDesc(virDomainPtr dom, ret = virDomainDefFormat((flags & VIR_DOMAIN_XML_INACTIVE) && vm->newDef ? vm->newDef : vm->def, - driver->xmlopt, driver->caps, + driver->xmlopt, virDomainDefFormatConvertXMLFlags(flags)); cleanup: @@ -1019,7 +1019,7 @@ static char *lxcConnectDomainXMLFromNative(virConnectPtr conn, if (!(def = lxcParseConfigString(nativeConfig, caps, driver->xmlopt))) goto cleanup; - xml = virDomainDefFormat(def, driver->xmlopt, caps, 0); + xml = virDomainDefFormat(def, driver->xmlopt, 0); cleanup: virObjectUnref(caps); diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index c1b8b6aa09..cd8ee4975b 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -171,7 +171,7 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver, /* now that we know it's stopped call the hook if present */ if (virHookPresent(VIR_HOOK_DRIVER_LXC)) { - char *xml = virDomainDefFormat(vm->def, driver->xmlopt, driver->caps, 0); + char *xml = virDomainDefFormat(vm->def, driver->xmlopt, 0); /* we can't stop the operation even if the script raised an error */ virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name, @@ -248,7 +248,7 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver, /* The "release" hook cleans up additional resources */ if (virHookPresent(VIR_HOOK_DRIVER_LXC)) { - char *xml = virDomainDefFormat(vm->def, driver->xmlopt, driver->caps, 0); + char *xml = virDomainDefFormat(vm->def, driver->xmlopt, 0); /* we can't stop the operation even if the script raised an error */ virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name, @@ -1271,7 +1271,7 @@ int virLXCProcessStart(virConnectPtr conn, /* Run an early hook to set-up missing devices */ if (virHookPresent(VIR_HOOK_DRIVER_LXC)) { - char *xml = virDomainDefFormat(vm->def, driver->xmlopt, driver->caps, 0); + char *xml = virDomainDefFormat(vm->def, driver->xmlopt, 0); int hookret; hookret = virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name, @@ -1379,7 +1379,7 @@ int virLXCProcessStart(virConnectPtr conn, /* now that we know it is about to start call the hook if present */ if (virHookPresent(VIR_HOOK_DRIVER_LXC)) { - char *xml = virDomainDefFormat(vm->def, driver->xmlopt, driver->caps, 0); + char *xml = virDomainDefFormat(vm->def, driver->xmlopt, 0); int hookret; hookret = virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name, @@ -1521,7 +1521,7 @@ int virLXCProcessStart(virConnectPtr conn, /* finally we can call the 'started' hook script if any */ if (virHookPresent(VIR_HOOK_DRIVER_LXC)) { - char *xml = virDomainDefFormat(vm->def, driver->xmlopt, driver->caps, 0); + char *xml = virDomainDefFormat(vm->def, driver->xmlopt, 0); int hookret; hookret = virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name, @@ -1701,7 +1701,7 @@ virLXCProcessReconnectDomain(virDomainObjPtr vm, /* now that we know it's reconnected call the hook if present */ if (virHookPresent(VIR_HOOK_DRIVER_LXC)) { - char *xml = virDomainDefFormat(vm->def, driver->xmlopt, driver->caps, 0); + char *xml = virDomainDefFormat(vm->def, driver->xmlopt, 0); int hookret; /* we can't stop the operation even if the script raised an error */ diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 9b93bc5ca0..33c28a2721 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -473,7 +473,7 @@ static char *openvzDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { if (!(vm = openvzDomObjFromDomain(driver, dom->uuid))) return NULL; - ret = virDomainDefFormat(vm->def, driver->xmlopt, driver->caps, + ret = virDomainDefFormat(vm->def, driver->xmlopt, virDomainDefFormatConvertXMLFlags(flags)); virDomainObjEndAPI(&vm); @@ -2067,7 +2067,7 @@ openvzDomainMigrateBegin3Params(virDomainPtr domain, goto cleanup; } - xml = virDomainDefFormat(vm->def, driver->xmlopt, driver->caps, + xml = virDomainDefFormat(vm->def, driver->xmlopt, VIR_DOMAIN_DEF_FORMAT_SECURE); cleanup: diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index b22063642e..a5cb1b91b3 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -3252,7 +3252,7 @@ phypDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) if (virDomainDefSetVcpus(&def, vcpus) < 0) goto err; - return virDomainDefFormat(&def, phyp_driver->xmlopt, phyp_driver->caps, + return virDomainDefFormat(&def, phyp_driver->xmlopt, virDomainDefFormatConvertXMLFlags(flags)); err: diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 49b6008d5c..926ec80ec8 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -9219,7 +9219,7 @@ qemuDomainDefFormatBufInternal(virQEMUDriverPtr driver, } format: - ret = virDomainDefFormatInternal(def, driver->xmlopt, caps, buf, + ret = virDomainDefFormatInternal(def, driver->xmlopt, buf, virDomainDefFormatConvertXMLFlags(flags)); cleanup: diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c index 6da79203d7..21560b2330 100644 --- a/src/security/security_apparmor.c +++ b/src/security/security_apparmor.c @@ -168,7 +168,7 @@ load_profile(virSecurityManagerPtr mgr G_GNUC_UNUSED, char *xml = NULL; virCommandPtr cmd = NULL; - xml = virDomainDefFormat(def, NULL, NULL, VIR_DOMAIN_DEF_FORMAT_SECURE); + xml = virDomainDefFormat(def, NULL, VIR_DOMAIN_DEF_FORMAT_SECURE); if (!xml) goto cleanup; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index f2700d90bc..630cfa1574 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -2178,7 +2178,7 @@ testDomainSaveImageWrite(testDriverPtr driver, int fd = -1; g_autofree char *xml = NULL; - xml = virDomainDefFormat(def, driver->xmlopt, driver->caps, + xml = virDomainDefFormat(def, driver->xmlopt, VIR_DOMAIN_DEF_FORMAT_SECURE); if (xml == NULL) { @@ -2468,7 +2468,7 @@ testDomainSaveImageGetXMLDesc(virConnectPtr conn, if ((fd = testDomainSaveImageOpen(privconn, path, &def)) < 0) goto cleanup; - ret = virDomainDefFormat(def, privconn->xmlopt, privconn->caps, + ret = virDomainDefFormat(def, privconn->xmlopt, VIR_DOMAIN_DEF_FORMAT_SECURE); cleanup: @@ -3180,7 +3180,7 @@ static char *testDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) def = (flags & VIR_DOMAIN_XML_INACTIVE) && privdom->newDef ? privdom->newDef : privdom->def; - ret = virDomainDefFormat(def, privconn->xmlopt, privconn->caps, + ret = virDomainDefFormat(def, privconn->xmlopt, virDomainDefFormatConvertXMLFlags(flags)); virDomainObjEndAPI(&privdom); diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 0d22c94e06..1feb76c0a5 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -4126,7 +4126,7 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) /* dump USB devices/filters if active */ vboxHostDeviceGetXMLDesc(data, def, machine); - ret = virDomainDefFormat(def, data->xmlopt, data->caps, + ret = virDomainDefFormat(def, data->xmlopt, virDomainDefFormatConvertXMLFlags(flags)); cleanup: diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index eb2fcd438b..b30c8847d3 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -940,7 +940,7 @@ vmwareDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) if (!(vm = vmwareDomObjFromDomain(driver, dom->uuid))) return NULL; - ret = virDomainDefFormat(vm->def, driver->xmlopt, driver->caps, + ret = virDomainDefFormat(vm->def, driver->xmlopt, virDomainDefFormatConvertXMLFlags(flags)); virDomainObjEndAPI(&vm); @@ -973,7 +973,7 @@ vmwareConnectDomainXMLFromNative(virConnectPtr conn, const char *nativeFormat, def = virVMXParseConfig(&ctx, driver->xmlopt, driver->caps, nativeConfig); if (def != NULL) - xml = virDomainDefFormat(def, driver->xmlopt, driver->caps, + xml = virDomainDefFormat(def, driver->xmlopt, VIR_DOMAIN_DEF_FORMAT_INACTIVE); virDomainDefFree(def); diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 35baab1b82..a76c56334d 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -733,7 +733,7 @@ vzDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) def = (flags & VIR_DOMAIN_XML_INACTIVE) && dom->newDef ? dom->newDef : dom->def; - ret = virDomainDefFormat(def, driver->xmlopt, privconn->driver->caps, flags); + ret = virDomainDefFormat(def, driver->xmlopt, flags); cleanup: virDomainObjEndAPI(&dom); @@ -2877,7 +2877,7 @@ vzDomainMigrateBeginStep(virDomainObjPtr dom, | VZ_MIGRATION_COOKIE_DOMAIN_NAME) < 0) return NULL; - return virDomainDefFormat(dom->def, driver->xmlopt, driver->caps, + return virDomainDefFormat(dom->def, driver->xmlopt, VIR_DOMAIN_XML_MIGRATABLE); } diff --git a/tests/bhyveargv2xmltest.c b/tests/bhyveargv2xmltest.c index 5e39face33..735cc4b338 100644 --- a/tests/bhyveargv2xmltest.c +++ b/tests/bhyveargv2xmltest.c @@ -77,7 +77,7 @@ testCompareXMLToArgvFiles(const char *xmlfile, goto fail; } - if (vmdef && !(actualxml = virDomainDefFormat(vmdef, driver.caps, 0))) + if (vmdef && !(actualxml = virDomainDefFormat(vmdef, driver.xmlopt, 0))) goto fail; if (vmdef && virTestCompareToFile(actualxml, xmlfile) < 0) diff --git a/tests/lxcconf2xmltest.c b/tests/lxcconf2xmltest.c index fffe9cbf1a..ba0c7a1a0c 100644 --- a/tests/lxcconf2xmltest.c +++ b/tests/lxcconf2xmltest.c @@ -41,7 +41,7 @@ testCompareXMLToConfigFiles(const char *xmlfile, if (testSanitizeDef(vmdef) < 0) goto fail; - if (!(actualxml = virDomainDefFormat(vmdef, driver->xmlopt, driver->caps, 0))) + if (!(actualxml = virDomainDefFormat(vmdef, driver->xmlopt, 0))) goto fail; if (virTestCompareToFile(actualxml, xmlfile) < 0) diff --git a/tests/openvzutilstest.c b/tests/openvzutilstest.c index 681f1a52a0..c395b9dc19 100644 --- a/tests/openvzutilstest.c +++ b/tests/openvzutilstest.c @@ -116,7 +116,7 @@ testReadNetworkConf(const void *data G_GNUC_UNUSED) goto cleanup; } - actual = virDomainDefFormat(def, driver.xmlopt, driver.caps, VIR_DOMAIN_DEF_FORMAT_INACTIVE); + actual = virDomainDefFormat(def, driver.xmlopt, VIR_DOMAIN_DEF_FORMAT_INACTIVE); if (actual == NULL) { fprintf(stderr, "ERROR: %s\n", virGetLastErrorMessage()); diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c index 9fbc1e1a64..b1e53505be 100644 --- a/tests/qemuhotplugtest.c +++ b/tests/qemuhotplugtest.c @@ -200,7 +200,7 @@ testQemuHotplugCheckResult(virDomainObjPtr vm, char *actual; int ret; - actual = virDomainDefFormat(vm->def, driver.xmlopt, driver.caps, + actual = virDomainDefFormat(vm->def, driver.xmlopt, VIR_DOMAIN_DEF_FORMAT_SECURE); if (!actual) return -1; @@ -466,7 +466,7 @@ testQemuHotplugCpuFinalize(struct testQemuHotplugCpuData *data) char *configXML = NULL; if (data->file_xml_res_live) { - if (!(activeXML = virDomainDefFormat(data->vm->def, driver.xmlopt, driver.caps, + if (!(activeXML = virDomainDefFormat(data->vm->def, driver.xmlopt, VIR_DOMAIN_DEF_FORMAT_SECURE))) goto cleanup; @@ -475,7 +475,7 @@ testQemuHotplugCpuFinalize(struct testQemuHotplugCpuData *data) } if (data->file_xml_res_conf) { - if (!(configXML = virDomainDefFormat(data->vm->newDef, driver.xmlopt, driver.caps, + if (!(configXML = virDomainDefFormat(data->vm->newDef, driver.xmlopt, VIR_DOMAIN_DEF_FORMAT_SECURE | VIR_DOMAIN_DEF_FORMAT_INACTIVE))) goto cleanup; diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index a8f7dd4e1b..f849869735 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -68,7 +68,7 @@ testCompareStatusXMLToXMLFiles(const void *opaque) goto cleanup; } - if (!(actual = virDomainObjFormat(obj, driver.xmlopt, NULL, + if (!(actual = virDomainObjFormat(obj, driver.xmlopt, VIR_DOMAIN_DEF_FORMAT_SECURE | VIR_DOMAIN_DEF_FORMAT_STATUS | VIR_DOMAIN_DEF_FORMAT_ACTUAL_NET | diff --git a/tests/testutils.c b/tests/testutils.c index ffcb56ca86..94a0e9068f 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -1140,7 +1140,7 @@ testCompareDomXML2XMLFiles(virCapsPtr caps, virDomainXMLOptionPtr xmlopt, goto out; } - if (!(actual = virDomainDefFormat(def, xmlopt, caps, format_flags))) { + if (!(actual = virDomainDefFormat(def, xmlopt, format_flags))) { result = TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_FORMAT; goto out; } diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index beb82cbd7c..8d7b8ba2a4 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -84,7 +84,7 @@ testCompareFiles(const char *vmx, const char *xml) goto cleanup; } - if (!(formatted = virDomainDefFormat(def, xmlopt, caps, + if (!(formatted = virDomainDefFormat(def, xmlopt, VIR_DOMAIN_DEF_FORMAT_SECURE))) goto cleanup; diff --git a/tests/xlconfigtest.c b/tests/xlconfigtest.c index d077933ca9..cdc2c37ed3 100644 --- a/tests/xlconfigtest.c +++ b/tests/xlconfigtest.c @@ -146,7 +146,7 @@ testCompareFormatXML(const char *xlcfg, const char *xml, bool replaceVars) if (!(def = xenParseXL(conf, cfg->caps, driver->xmlopt))) goto fail; - if (!(gotxml = virDomainDefFormat(def, driver->xmlopt, cfg->caps, + if (!(gotxml = virDomainDefFormat(def, driver->xmlopt, VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_SECURE))) goto fail; diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c index 6971ad76e2..f8652e228c 100644 --- a/tests/xmconfigtest.c +++ b/tests/xmconfigtest.c @@ -101,7 +101,7 @@ testCompareFormatXML(const char *xmcfg, const char *xml) if (!(def = xenParseXM(conf, cfg->caps, driver->xmlopt))) goto fail; - if (!(gotxml = virDomainDefFormat(def, driver->xmlopt, cfg->caps, VIR_DOMAIN_DEF_FORMAT_SECURE))) + if (!(gotxml = virDomainDefFormat(def, driver->xmlopt, VIR_DOMAIN_DEF_FORMAT_SECURE))) goto fail; if (virTestCompareToFile(gotxml, xml) < 0) -- 2.23.0

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/conf/domain_conf.c | 10 ++++------ src/conf/domain_conf.h | 2 -- src/libxl/xen_xl.c | 2 +- src/libxl/xen_xm.c | 2 +- src/lxc/lxc_native.c | 4 ++-- src/qemu/qemu_driver.c | 12 ++++++------ src/qemu/qemu_process.c | 4 ++-- src/vmx/vmx.c | 4 ++-- 8 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 44e56976d9..b1384a1487 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5802,7 +5802,6 @@ virDomainDefPostParseCheckFailure(virDomainDefPtr def, int virDomainDefPostParse(virDomainDefPtr def, - virCapsPtr caps G_GNUC_UNUSED, unsigned int parseFlags, virDomainXMLOptionPtr xmlopt, void *parseOpaque) @@ -7107,7 +7106,6 @@ virDomainDefValidateInternal(const virDomainDef *def, */ int virDomainDefValidate(virDomainDefPtr def, - virCapsPtr caps G_GNUC_UNUSED, unsigned int parseFlags, virDomainXMLOptionPtr xmlopt) { @@ -21518,11 +21516,11 @@ virDomainObjParseXML(xmlDocPtr xml, parseOpaque = xmlopt->privateData.getParseOpaque(obj); /* callback to fill driver specific domain aspects */ - if (virDomainDefPostParse(obj->def, caps, flags, xmlopt, parseOpaque) < 0) + if (virDomainDefPostParse(obj->def, flags, xmlopt, parseOpaque) < 0) goto error; /* validate configuration */ - if (virDomainDefValidate(obj->def, caps, flags, xmlopt) < 0) + if (virDomainDefValidate(obj->def, flags, xmlopt) < 0) goto error; return obj; @@ -21607,11 +21605,11 @@ virDomainDefParseNode(xmlDocPtr xml, return NULL; /* callback to fill driver specific domain aspects */ - if (virDomainDefPostParse(def, caps, flags, xmlopt, parseOpaque) < 0) + if (virDomainDefPostParse(def, flags, xmlopt, parseOpaque) < 0) return NULL; /* validate configuration */ - if (virDomainDefValidate(def, caps, flags, xmlopt) < 0) + if (virDomainDefValidate(def, flags, xmlopt) < 0) return NULL; return g_steal_pointer(&def); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index b98fe5eba5..4f3c9fdc8b 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2783,7 +2783,6 @@ virDomainSCSIDriveAddressIsUsed(const virDomainDef *def, const virDomainDeviceDriveAddress *addr); int virDomainDefPostParse(virDomainDefPtr def, - virCapsPtr caps, unsigned int parseFlags, virDomainXMLOptionPtr xmlopt, void *parseOpaque); @@ -2796,7 +2795,6 @@ int virDomainDeviceValidateAliasForHotplug(virDomainObjPtr vm, bool virDomainDeviceAliasIsUserAlias(const char *aliasStr); int virDomainDefValidate(virDomainDefPtr def, - virCapsPtr caps, unsigned int parseFlags, virDomainXMLOptionPtr xmlopt); diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c index 396adf6dac..18ea4a8d95 100644 --- a/src/libxl/xen_xl.c +++ b/src/libxl/xen_xl.c @@ -1213,7 +1213,7 @@ xenParseXL(virConfPtr conf, if (xenParseXLChannel(conf, def) < 0) goto cleanup; - if (virDomainDefPostParse(def, caps, VIR_DOMAIN_DEF_PARSE_ABI_UPDATE, + if (virDomainDefPostParse(def, VIR_DOMAIN_DEF_PARSE_ABI_UPDATE, xmlopt, NULL) < 0) goto cleanup; diff --git a/src/libxl/xen_xm.c b/src/libxl/xen_xm.c index 88cf9ac5b0..1b462d0487 100644 --- a/src/libxl/xen_xm.c +++ b/src/libxl/xen_xm.c @@ -467,7 +467,7 @@ xenParseXM(virConfPtr conf, if (xenParseXMInputDevs(conf, def) < 0) goto cleanup; - if (virDomainDefPostParse(def, caps, VIR_DOMAIN_DEF_PARSE_ABI_UPDATE, + if (virDomainDefPostParse(def, VIR_DOMAIN_DEF_PARSE_ABI_UPDATE, xmlopt, NULL) < 0) goto cleanup; diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index 7e696fd2f0..e9b83653b5 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -1055,7 +1055,7 @@ lxcSetCapDrop(virDomainDefPtr def, virConfPtr properties) virDomainDefPtr lxcParseConfigString(const char *config, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, virDomainXMLOptionPtr xmlopt) { virDomainDefPtr vmdef = NULL; @@ -1166,7 +1166,7 @@ lxcParseConfigString(const char *config, /* lxc.cap.drop */ lxcSetCapDrop(vmdef, properties); - if (virDomainDefPostParse(vmdef, caps, VIR_DOMAIN_DEF_PARSE_ABI_UPDATE, + if (virDomainDefPostParse(vmdef, VIR_DOMAIN_DEF_PARSE_ABI_UPDATE, xmlopt, NULL) < 0) goto error; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 93a92dad36..32eae175ed 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -8101,7 +8101,7 @@ qemuCheckDiskConfigAgainstDomain(const virDomainDef *def, static int qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef, virDomainDeviceDefPtr dev, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, virQEMUCapsPtr qemuCaps, unsigned int parse_flags, virDomainXMLOptionPtr xmlopt) @@ -8301,7 +8301,7 @@ qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef, return -1; } - if (virDomainDefPostParse(vmdef, caps, parse_flags, xmlopt, qemuCaps) < 0) + if (virDomainDefPostParse(vmdef, parse_flags, xmlopt, qemuCaps) < 0) return -1; return 0; @@ -8311,7 +8311,7 @@ qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef, static int qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef, virDomainDeviceDefPtr dev, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, virQEMUCapsPtr qemuCaps, unsigned int parse_flags, virDomainXMLOptionPtr xmlopt) @@ -8494,7 +8494,7 @@ qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef, return -1; } - if (virDomainDefPostParse(vmdef, caps, parse_flags, xmlopt, qemuCaps) < 0) + if (virDomainDefPostParse(vmdef, parse_flags, xmlopt, qemuCaps) < 0) return -1; return 0; @@ -8503,7 +8503,7 @@ qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef, static int qemuDomainUpdateDeviceConfig(virDomainDefPtr vmdef, virDomainDeviceDefPtr dev, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, virQEMUCapsPtr qemuCaps, unsigned int parse_flags, virDomainXMLOptionPtr xmlopt) @@ -8602,7 +8602,7 @@ qemuDomainUpdateDeviceConfig(virDomainDefPtr vmdef, return -1; } - if (virDomainDefPostParse(vmdef, caps, parse_flags, xmlopt, qemuCaps) < 0) + if (virDomainDefPostParse(vmdef, parse_flags, xmlopt, qemuCaps) < 0) return -1; return 0; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 79ac5f3d95..33ebdce01e 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5382,7 +5382,7 @@ qemuProcessStartValidate(virQEMUDriverPtr driver, * VM that was running before (migration, snapshots, save). It's more * important to start such VM than keep the configuration clean */ if ((flags & VIR_QEMU_PROCESS_START_NEW) && - virDomainDefValidate(vm->def, caps, 0, driver->xmlopt) < 0) + virDomainDefValidate(vm->def, 0, driver->xmlopt) < 0) return -1; if (qemuProcessStartValidateGraphics(vm) < 0) @@ -5581,7 +5581,7 @@ qemuProcessInit(virQEMUDriverPtr driver, VIR_DEBUG("re-running the post parse callback"); /* we don't have the private copy of qemuCaps at this point */ - if (virDomainDefPostParse(vm->def, caps, 0, driver->xmlopt, NULL) < 0) + if (virDomainDefPostParse(vm->def, 0, driver->xmlopt, NULL) < 0) goto cleanup; } diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 093092b701..df5eafbd44 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -1276,7 +1276,7 @@ virVMXConfigScanResultsCollector(const char* name, virDomainDefPtr virVMXParseConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, const char *vmx) { bool success = false; @@ -1845,7 +1845,7 @@ virVMXParseConfig(virVMXContext *ctx, } } - if (virDomainDefPostParse(def, caps, VIR_DOMAIN_DEF_PARSE_ABI_UPDATE, + if (virDomainDefPostParse(def, VIR_DOMAIN_DEF_PARSE_ABI_UPDATE, xmlopt, NULL) < 0) goto cleanup; -- 2.23.0

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/bhyve/bhyve_driver.c | 17 +++--------- src/conf/checkpoint_conf.c | 4 +-- src/conf/domain_conf.c | 29 +++++++------------- src/conf/domain_conf.h | 6 ----- src/conf/snapshot_conf.c | 6 ++--- src/conf/virdomainobjlist.c | 8 +++--- src/esx/esx_driver.c | 4 +-- src/libxl/libxl_domain.c | 4 +-- src/libxl/libxl_driver.c | 18 ++++++------- src/libxl/libxl_migration.c | 7 +++-- src/lxc/lxc_controller.c | 2 +- src/lxc/lxc_driver.c | 10 +++---- src/openvz/openvz_driver.c | 8 +++--- src/phyp/phyp_driver.c | 4 +-- src/qemu/qemu_checkpoint.c | 4 +-- src/qemu/qemu_domain.c | 7 +---- src/qemu/qemu_driver.c | 46 ++++++++------------------------ src/qemu/qemu_migration.c | 21 +++------------ src/qemu/qemu_migration_cookie.c | 8 +----- src/security/virt-aa-helper.c | 2 +- src/test/test_driver.c | 10 +++---- src/vbox/vbox_common.c | 6 ++--- src/vmware/vmware_driver.c | 4 +-- src/vz/vz_driver.c | 4 +-- tests/bhyvexml2argvtest.c | 2 +- tests/domainconftest.c | 2 +- tests/libxlxml2domconfigtest.c | 2 +- tests/qemuagenttest.c | 2 +- tests/qemuhotplugtest.c | 3 +-- tests/qemumemlocktest.c | 2 +- tests/qemusecuritytest.c | 1 - tests/qemuxml2argvtest.c | 2 +- tests/qemuxml2xmltest.c | 2 +- tests/securityselinuxlabeltest.c | 2 +- tests/testutils.c | 5 ++-- tests/xlconfigtest.c | 4 +-- tests/xmconfigtest.c | 2 +- tests/xml2vmxtest.c | 2 +- 38 files changed, 97 insertions(+), 175 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 8432044b60..0e627f2dc8 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -519,7 +519,7 @@ bhyveDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flag if (!caps) return NULL; - if ((def = virDomainDefParseString(xml, caps, privconn->xmlopt, + if ((def = virDomainDefParseString(xml, privconn->xmlopt, NULL, parse_flags)) == NULL) goto cleanup; @@ -681,7 +681,6 @@ bhyveConnectDomainXMLToNative(virConnectPtr conn, bhyveConnPtr privconn = conn->privateData; virDomainDefPtr def = NULL; virCommandPtr cmd = NULL, loadcmd = NULL; - virCapsPtr caps = NULL; char *ret = NULL; virCheckFlags(0, NULL); @@ -695,10 +694,7 @@ bhyveConnectDomainXMLToNative(virConnectPtr conn, goto cleanup; } - if (!(caps = bhyveDriverGetCapabilities(privconn))) - goto cleanup; - - if (!(def = virDomainDefParseString(xmlData, caps, privconn->xmlopt, + if (!(def = virDomainDefParseString(xmlData, privconn->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; @@ -741,7 +737,6 @@ bhyveConnectDomainXMLToNative(virConnectPtr conn, virCommandFree(loadcmd); virCommandFree(cmd); virDomainDefFree(def); - virObjectUnref(caps); return ret; } @@ -898,7 +893,6 @@ bhyveDomainCreateXML(virConnectPtr conn, virDomainDefPtr def = NULL; virDomainObjPtr vm = NULL; virObjectEventPtr event = NULL; - virCapsPtr caps = NULL; unsigned int start_flags = 0; unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE; @@ -910,11 +904,7 @@ bhyveDomainCreateXML(virConnectPtr conn, if (flags & VIR_DOMAIN_START_AUTODESTROY) start_flags |= VIR_BHYVE_PROCESS_START_AUTODESTROY; - caps = bhyveDriverGetCapabilities(privconn); - if (!caps) - return NULL; - - if ((def = virDomainDefParseString(xml, caps, privconn->xmlopt, + if ((def = virDomainDefParseString(xml, privconn->xmlopt, NULL, parse_flags)) == NULL) goto cleanup; @@ -947,7 +937,6 @@ bhyveDomainCreateXML(virConnectPtr conn, dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id); cleanup: - virObjectUnref(caps); virDomainDefFree(def); virDomainObjEndAPI(&vm); virObjectEventStateQueue(privconn->domainEventState, event); diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c index 37cc8e5e6c..581e382b6d 100644 --- a/src/conf/checkpoint_conf.c +++ b/src/conf/checkpoint_conf.c @@ -121,7 +121,7 @@ virDomainCheckpointDiskDefParseXML(xmlNodePtr node, */ static virDomainCheckpointDefPtr virDomainCheckpointDefParse(xmlXPathContextPtr ctxt, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, virDomainXMLOptionPtr xmlopt, void *parseOpaque, unsigned int flags) @@ -170,7 +170,7 @@ virDomainCheckpointDefParse(xmlXPathContextPtr ctxt, return NULL; } def->parent.dom = virDomainDefParseNode(ctxt->node->doc, domainNode, - caps, xmlopt, parseOpaque, + xmlopt, parseOpaque, domainflags); if (!def->parent.dom) return NULL; diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b1384a1487..00b5da8d52 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -16371,7 +16371,6 @@ virDomainVsockDefParseXML(virDomainXMLOptionPtr xmlopt, virDomainDeviceDefPtr virDomainDeviceDefParse(const char *xmlStr, const virDomainDef *def, - virCapsPtr caps G_GNUC_UNUSED, virDomainXMLOptionPtr xmlopt, void *parseOpaque, unsigned int flags) @@ -19725,7 +19724,6 @@ virDomainMemorytuneDefParse(virDomainDefPtr def, static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, xmlXPathContextPtr ctxt, - virCapsPtr caps G_GNUC_UNUSED, virDomainXMLOptionPtr xmlopt, unsigned int flags) { @@ -21430,7 +21428,6 @@ virDomainDefParseXML(xmlDocPtr xml, static virDomainObjPtr virDomainObjParseXML(xmlDocPtr xml, xmlXPathContextPtr ctxt, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, unsigned int flags) { @@ -21457,7 +21454,7 @@ virDomainObjParseXML(xmlDocPtr xml, oldnode = ctxt->node; ctxt->node = config; - obj->def = virDomainDefParseXML(xml, ctxt, caps, xmlopt, flags); + obj->def = virDomainDefParseXML(xml, ctxt, xmlopt, flags); ctxt->node = oldnode; if (!obj->def) goto error; @@ -21534,7 +21531,6 @@ virDomainObjParseXML(xmlDocPtr xml, static virDomainDefPtr virDomainDefParse(const char *xmlStr, const char *filename, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, void *parseOpaque, unsigned int flags) @@ -21556,7 +21552,7 @@ virDomainDefParse(const char *xmlStr, goto cleanup; } - def = virDomainDefParseNode(xml, root, caps, xmlopt, parseOpaque, flags); + def = virDomainDefParseNode(xml, root, xmlopt, parseOpaque, flags); cleanup: xmlFreeDoc(xml); @@ -21566,29 +21562,26 @@ virDomainDefParse(const char *xmlStr, virDomainDefPtr virDomainDefParseString(const char *xmlStr, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, void *parseOpaque, unsigned int flags) { - return virDomainDefParse(xmlStr, NULL, caps, xmlopt, parseOpaque, flags); + return virDomainDefParse(xmlStr, NULL, xmlopt, parseOpaque, flags); } virDomainDefPtr virDomainDefParseFile(const char *filename, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, void *parseOpaque, unsigned int flags) { - return virDomainDefParse(NULL, filename, caps, xmlopt, parseOpaque, flags); + return virDomainDefParse(NULL, filename, xmlopt, parseOpaque, flags); } virDomainDefPtr virDomainDefParseNode(xmlDocPtr xml, xmlNodePtr root, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, void *parseOpaque, unsigned int flags) @@ -21601,7 +21594,7 @@ virDomainDefParseNode(xmlDocPtr xml, ctxt->node = root; - if (!(def = virDomainDefParseXML(xml, ctxt, caps, xmlopt, flags))) + if (!(def = virDomainDefParseXML(xml, ctxt, xmlopt, flags))) return NULL; /* callback to fill driver specific domain aspects */ @@ -21619,7 +21612,6 @@ virDomainDefParseNode(xmlDocPtr xml, virDomainObjPtr virDomainObjParseNode(xmlDocPtr xml, xmlNodePtr root, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, unsigned int flags) { @@ -21637,13 +21629,12 @@ virDomainObjParseNode(xmlDocPtr xml, return NULL; ctxt->node = root; - return virDomainObjParseXML(xml, ctxt, caps, xmlopt, flags); + return virDomainObjParseXML(xml, ctxt, xmlopt, flags); } virDomainObjPtr virDomainObjParseFile(const char *filename, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, unsigned int flags) { @@ -21653,7 +21644,7 @@ virDomainObjParseFile(const char *filename, if ((xml = virXMLParseFile(filename))) { obj = virDomainObjParseNode(xml, xmlDocGetRootElement(xml), - caps, xmlopt, flags); + xmlopt, flags); xmlFreeDoc(xml); } @@ -29330,7 +29321,7 @@ virDomainDefCopy(virDomainDefPtr src, if (!(xml = virDomainDefFormat(src, xmlopt, format_flags))) return NULL; - return virDomainDefParseString(xml, caps, xmlopt, parseOpaque, parse_flags); + return virDomainDefParseString(xml, xmlopt, parseOpaque, parse_flags); } virDomainDefPtr @@ -29787,7 +29778,7 @@ virDomainNetFindByName(virDomainDefPtr def, virDomainDeviceDefPtr virDomainDeviceDefCopy(virDomainDeviceDefPtr src, const virDomainDef *def, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, virDomainXMLOptionPtr xmlopt, void *parseOpaque) { @@ -29875,7 +29866,7 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src, return NULL; xmlStr = virBufferContentAndReset(&buf); - return virDomainDeviceDefParse(xmlStr, def, caps, xmlopt, parseOpaque, + return virDomainDeviceDefParse(xmlStr, def, xmlopt, parseOpaque, VIR_DOMAIN_DEF_PARSE_INACTIVE | VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE); } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 4f3c9fdc8b..5255c8190e 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3032,7 +3032,6 @@ typedef enum { virDomainDeviceDefPtr virDomainDeviceDefParse(const char *xmlStr, const virDomainDef *def, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, void *parseOpaque, unsigned int flags); @@ -3040,28 +3039,23 @@ virDomainDiskDefPtr virDomainDiskDefParse(const char *xmlStr, virDomainXMLOptionPtr xmlopt, unsigned int flags); virDomainDefPtr virDomainDefParseString(const char *xmlStr, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, void *parseOpaque, unsigned int flags); virDomainDefPtr virDomainDefParseFile(const char *filename, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, void *parseOpaque, unsigned int flags); virDomainDefPtr virDomainDefParseNode(xmlDocPtr doc, xmlNodePtr root, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, void *parseOpaque, unsigned int flags); virDomainObjPtr virDomainObjParseNode(xmlDocPtr xml, xmlNodePtr root, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, unsigned int flags); virDomainObjPtr virDomainObjParseFile(const char *filename, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, unsigned int flags); diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index 015d54a128..af882c6048 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -222,7 +222,7 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node, */ static virDomainSnapshotDefPtr virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, virDomainXMLOptionPtr xmlopt, void *parseOpaque, bool *current, @@ -301,7 +301,7 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, goto cleanup; } def->parent.dom = virDomainDefParseNode(ctxt->node->doc, domainNode, - caps, xmlopt, parseOpaque, + xmlopt, parseOpaque, domainflags); if (!def->parent.dom) goto cleanup; @@ -314,7 +314,7 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, * parent.dom for config and live XML. */ if ((inactiveDomNode = virXPathNode("./inactiveDomain", ctxt))) { def->parent.inactiveDom = virDomainDefParseNode(ctxt->node->doc, inactiveDomNode, - caps, xmlopt, NULL, domainflags); + xmlopt, NULL, domainflags); if (!def->parent.inactiveDom) goto cleanup; } diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c index 744dd87296..ae18a4544f 100644 --- a/src/conf/virdomainobjlist.c +++ b/src/conf/virdomainobjlist.c @@ -483,7 +483,7 @@ virDomainObjListRename(virDomainObjListPtr doms, static virDomainObjPtr virDomainObjListLoadConfig(virDomainObjListPtr doms, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, virDomainXMLOptionPtr xmlopt, const char *configDir, const char *autostartDir, @@ -499,7 +499,7 @@ virDomainObjListLoadConfig(virDomainObjListPtr doms, if ((configFile = virDomainConfigFile(configDir, name)) == NULL) goto error; - if (!(def = virDomainDefParseFile(configFile, caps, xmlopt, NULL, + if (!(def = virDomainDefParseFile(configFile, xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE | VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE | VIR_DOMAIN_DEF_PARSE_ALLOW_POST_PARSE_FAIL))) @@ -536,7 +536,7 @@ static virDomainObjPtr virDomainObjListLoadStatus(virDomainObjListPtr doms, const char *statusDir, const char *name, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, virDomainXMLOptionPtr xmlopt, virDomainLoadConfigNotify notify, void *opaque) @@ -548,7 +548,7 @@ virDomainObjListLoadStatus(virDomainObjListPtr doms, if ((statusFile = virDomainConfigFile(statusDir, name)) == NULL) goto error; - if (!(obj = virDomainObjParseFile(statusFile, caps, xmlopt, + if (!(obj = virDomainObjParseFile(statusFile, xmlopt, VIR_DOMAIN_DEF_PARSE_STATUS | VIR_DOMAIN_DEF_PARSE_ACTUAL_NET | VIR_DOMAIN_DEF_PARSE_PCI_ORIG_STATES | diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 8e3da589c9..9cfdd3bf49 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -2744,7 +2744,7 @@ esxConnectDomainXMLToNative(virConnectPtr conn, const char *nativeFormat, if (virtualHW_version < 0) return NULL; - def = virDomainDefParseString(domainXml, priv->caps, priv->xmlopt, + def = virDomainDefParseString(domainXml, priv->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE); if (!def) @@ -2960,7 +2960,7 @@ esxDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) return NULL; /* Parse domain XML */ - def = virDomainDefParseString(xml, priv->caps, priv->xmlopt, + def = virDomainDefParseString(xml, priv->xmlopt, NULL, parse_flags); if (!def) diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index f4f1781bae..fea20ba477 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -732,7 +732,7 @@ libxlDomainManagedSavePath(libxlDriverPrivatePtr driver, virDomainObjPtr vm) */ int libxlDomainSaveImageOpen(libxlDriverPrivatePtr driver, - libxlDriverConfigPtr cfg, + libxlDriverConfigPtr cfg G_GNUC_UNUSED, const char *from, virDomainDefPtr *ret_def, libxlSavefileHeaderPtr ret_hdr) @@ -780,7 +780,7 @@ libxlDomainSaveImageOpen(libxlDriverPrivatePtr driver, goto error; } - if (!(def = virDomainDefParseString(xml, cfg->caps, driver->xmlopt, NULL, + if (!(def = virDomainDefParseString(xml, driver->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE | VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE))) goto error; diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index ed754452f0..abf359ad1b 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -1042,7 +1042,7 @@ libxlDomainCreateXML(virConnectPtr conn, const char *xml, if (flags & VIR_DOMAIN_START_VALIDATE) parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA; - if (!(def = virDomainDefParseString(xml, cfg->caps, driver->xmlopt, + if (!(def = virDomainDefParseString(xml, driver->xmlopt, NULL, parse_flags))) goto cleanup; @@ -2730,7 +2730,7 @@ libxlConnectDomainXMLToNative(virConnectPtr conn, const char * nativeFormat, goto cleanup; if (!(def = virDomainDefParseString(domainXml, - cfg->caps, driver->xmlopt, NULL, + driver->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; @@ -2850,7 +2850,7 @@ libxlDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flag if (flags & VIR_DOMAIN_DEFINE_VALIDATE) parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA; - if (!(def = virDomainDefParseString(xml, cfg->caps, driver->xmlopt, + if (!(def = virDomainDefParseString(xml, driver->xmlopt, NULL, parse_flags))) goto cleanup; @@ -4116,7 +4116,7 @@ libxlDomainAttachDeviceFlags(virDomainPtr dom, const char *xml, if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) { if (!(dev = virDomainDeviceDefParse(xml, vm->def, - cfg->caps, driver->xmlopt, NULL, + driver->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto endjob; @@ -4133,7 +4133,7 @@ libxlDomainAttachDeviceFlags(virDomainPtr dom, const char *xml, /* If dev exists it was created to modify the domain config. Free it. */ virDomainDeviceDefFree(dev); if (!(dev = virDomainDeviceDefParse(xml, vm->def, - cfg->caps, driver->xmlopt, NULL, + driver->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto endjob; @@ -4205,7 +4205,7 @@ libxlDomainDetachDeviceFlags(virDomainPtr dom, const char *xml, if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) { if (!(dev = virDomainDeviceDefParse(xml, vm->def, - cfg->caps, driver->xmlopt, NULL, + driver->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE | VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE))) goto endjob; @@ -4223,7 +4223,7 @@ libxlDomainDetachDeviceFlags(virDomainPtr dom, const char *xml, /* If dev exists it was created to modify the domain config. Free it. */ virDomainDeviceDefFree(dev); if (!(dev = virDomainDeviceDefParse(xml, vm->def, - cfg->caps, driver->xmlopt, NULL, + driver->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE | VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE))) goto endjob; @@ -4293,7 +4293,7 @@ libxlDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml, if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) { if (!(dev = virDomainDeviceDefParse(xml, vm->def, - cfg->caps, driver->xmlopt, NULL, + driver->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; @@ -4312,7 +4312,7 @@ libxlDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml, /* If dev exists it was created to modify the domain config. Free it. */ virDomainDeviceDefFree(dev); if (!(dev = virDomainDeviceDefParse(xml, vm->def, - cfg->caps, driver->xmlopt, NULL, + driver->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c index f9bd004b2e..d744816510 100644 --- a/src/libxl/libxl_migration.c +++ b/src/libxl/libxl_migration.c @@ -402,7 +402,7 @@ libxlDomainMigrationSrcBegin(virConnectPtr conn, goto endjob; if (xmlin) { - if (!(tmpdef = virDomainDefParseString(xmlin, cfg->caps, + if (!(tmpdef = virDomainDefParseString(xmlin, driver->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE | @@ -450,7 +450,7 @@ libxlDomainMigrationDstPrepareDef(libxlDriverPrivatePtr driver, return NULL; } - if (!(def = virDomainDefParseString(dom_xml, cfg->caps, driver->xmlopt, + if (!(def = virDomainDefParseString(dom_xml, driver->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE | VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE))) @@ -477,7 +477,6 @@ libxlDomainMigrationPrepareAny(virConnectPtr dconn, bool *taint_hook) { libxlDriverPrivatePtr driver = dconn->privateData; - libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); if (libxlMigrationEatCookie(cookiein, cookieinlen, mig) < 0) return -1; @@ -514,7 +513,7 @@ libxlDomainMigrationPrepareAny(virConnectPtr dconn, virDomainDefPtr newdef; VIR_DEBUG("Using hook-filtered domain XML: %s", *xmlout); - newdef = virDomainDefParseString(*xmlout, cfg->caps, driver->xmlopt, + newdef = virDomainDefParseString(*xmlout, driver->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE | VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE); diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index c869e2e7c4..e572c3f5fd 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -212,7 +212,7 @@ static virLXCControllerPtr virLXCControllerNew(const char *name) goto error; if ((ctrl->vm = virDomainObjParseFile(configFile, - driver->caps, driver->xmlopt, + driver->xmlopt, 0)) == NULL) goto error; ctrl->def = ctrl->vm->def; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 4639e603e0..1ef15bfcf8 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -416,7 +416,7 @@ lxcDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) if (!(caps = virLXCDriverGetCapabilities(driver, false))) goto cleanup; - if (!(def = virDomainDefParseString(xml, caps, driver->xmlopt, + if (!(def = virDomainDefParseString(xml, driver->xmlopt, NULL, parse_flags))) goto cleanup; @@ -1164,7 +1164,7 @@ lxcDomainCreateXMLWithFiles(virConnectPtr conn, if (!(caps = virLXCDriverGetCapabilities(driver, false))) goto cleanup; - if (!(def = virDomainDefParseString(xml, caps, driver->xmlopt, + if (!(def = virDomainDefParseString(xml, driver->xmlopt, NULL, parse_flags))) goto cleanup; @@ -4699,7 +4699,7 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom, goto endjob; dev = dev_copy = virDomainDeviceDefParse(xml, vm->def, - caps, driver->xmlopt, NULL, + driver->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE); if (dev == NULL) goto endjob; @@ -4818,7 +4818,7 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom, if (!(caps = virLXCDriverGetCapabilities(driver, false))) goto endjob; - if (!(dev = virDomainDeviceDefParse(xml, vm->def, caps, driver->xmlopt, NULL, + if (!(dev = virDomainDeviceDefParse(xml, vm->def, driver->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto endjob; @@ -4882,7 +4882,7 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom, goto endjob; dev = dev_copy = virDomainDeviceDefParse(xml, vm->def, - caps, driver->xmlopt, NULL, + driver->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE | VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE); if (dev == NULL) diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 33c28a2721..0c472601d3 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -858,7 +858,7 @@ openvzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int fla parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA; openvzDriverLock(driver); - if ((vmdef = virDomainDefParseString(xml, driver->caps, driver->xmlopt, + if ((vmdef = virDomainDefParseString(xml, driver->xmlopt, NULL, parse_flags)) == NULL) goto cleanup; @@ -948,7 +948,7 @@ openvzDomainCreateXML(virConnectPtr conn, const char *xml, parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA; openvzDriverLock(driver); - if ((vmdef = virDomainDefParseString(xml, driver->caps, driver->xmlopt, + if ((vmdef = virDomainDefParseString(xml, driver->xmlopt, NULL, parse_flags)) == NULL) goto cleanup; @@ -1909,7 +1909,7 @@ openvzDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml, if (!(def = virDomainObjGetOneDef(vm, flags))) goto cleanup; - dev = virDomainDeviceDefParse(xml, def, driver->caps, driver->xmlopt, NULL, + dev = virDomainDeviceDefParse(xml, def, driver->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE); if (!dev) goto cleanup; @@ -2113,7 +2113,7 @@ openvzDomainMigratePrepare3Params(virConnectPtr dconn, goto error; } - if (!(def = virDomainDefParseString(dom_xml, driver->caps, driver->xmlopt, + if (!(def = virDomainDefParseString(dom_xml, driver->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE | VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE))) diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index a5cb1b91b3..640d90585a 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -1684,7 +1684,7 @@ phypDomainAttachDeviceFlags(virDomainPtr domain, def->os.type = VIR_DOMAIN_OSTYPE_LINUX; - dev = virDomainDeviceDefParse(xml, def, phyp_driver->caps, NULL, NULL, + dev = virDomainDeviceDefParse(xml, def, NULL, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE); if (!dev) goto cleanup; @@ -3531,7 +3531,7 @@ phypDomainCreateXML(virConnectPtr conn, if (flags & VIR_DOMAIN_START_VALIDATE) parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA; - if (!(def = virDomainDefParseString(xml, phyp_driver->caps, + if (!(def = virDomainDefParseString(xml, phyp_driver->xmlopt, NULL, parse_flags))) diff --git a/src/qemu/qemu_checkpoint.c b/src/qemu/qemu_checkpoint.c index d5af6b99bf..a601030637 100644 --- a/src/qemu/qemu_checkpoint.c +++ b/src/qemu/qemu_checkpoint.c @@ -239,7 +239,7 @@ qemuCheckpointDiscardAllMetadata(virQEMUDriverPtr driver, /* Called inside job lock */ static int qemuCheckpointPrepare(virQEMUDriverPtr driver, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, virDomainObjPtr vm, virDomainCheckpointDefPtr def) { @@ -253,7 +253,7 @@ qemuCheckpointPrepare(virQEMUDriverPtr driver, if (!(xml = qemuDomainDefFormatLive(driver, priv->qemuCaps, vm->def, priv->origCPU, true, true)) || - !(def->parent.dom = virDomainDefParseString(xml, caps, driver->xmlopt, + !(def->parent.dom = virDomainDefParseString(xml, driver->xmlopt, priv->qemuCaps, VIR_DOMAIN_DEF_PARSE_INACTIVE | VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE))) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 926ec80ec8..4c589eec05 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -8976,17 +8976,12 @@ qemuDomainDefFromXML(virQEMUDriverPtr driver, virQEMUCapsPtr qemuCaps, const char *xml) { - virCapsPtr caps; virDomainDefPtr def; - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - return NULL; - - def = virDomainDefParseString(xml, caps, driver->xmlopt, qemuCaps, + def = virDomainDefParseString(xml, driver->xmlopt, qemuCaps, VIR_DOMAIN_DEF_PARSE_INACTIVE | VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE); - virObjectUnref(caps); return def; } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 32eae175ed..00788e7aca 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1748,7 +1748,6 @@ static virDomainPtr qemuDomainCreateXML(virConnectPtr conn, virObjectEventPtr event = NULL; virObjectEventPtr event2 = NULL; unsigned int start_flags = VIR_QEMU_PROCESS_START_COLD; - g_autoptr(virCaps) caps = NULL; unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE | VIR_DOMAIN_DEF_PARSE_ABI_UPDATE; @@ -1765,10 +1764,7 @@ static virDomainPtr qemuDomainCreateXML(virConnectPtr conn, virNWFilterReadLockFilterUpdates(); - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; - - if (!(def = virDomainDefParseString(xml, caps, driver->xmlopt, + if (!(def = virDomainDefParseString(xml, driver->xmlopt, NULL, parse_flags))) goto cleanup; @@ -3277,13 +3273,9 @@ qemuDomainSaveInternal(virQEMUDriverPtr driver, int ret = -1; virObjectEventPtr event = NULL; qemuDomainObjPrivatePtr priv = vm->privateData; - g_autoptr(virCaps) caps = NULL; virQEMUSaveDataPtr data = NULL; qemuDomainSaveCookiePtr cookie = NULL; - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; - if (!qemuMigrationSrcIsAllowed(driver, vm, false, 0)) goto cleanup; @@ -3326,7 +3318,7 @@ qemuDomainSaveInternal(virQEMUDriverPtr driver, if (xmlin) { virDomainDefPtr def = NULL; - if (!(def = virDomainDefParseString(xmlin, caps, driver->xmlopt, + if (!(def = virDomainDefParseString(xmlin, driver->xmlopt, priv->qemuCaps, VIR_DOMAIN_DEF_PARSE_INACTIVE | VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE))) { @@ -6581,12 +6573,8 @@ qemuDomainSaveImageUpdateDef(virQEMUDriverPtr driver, virDomainDefPtr ret = NULL; virDomainDefPtr newdef_migr = NULL; virDomainDefPtr newdef = NULL; - g_autoptr(virCaps) caps = NULL; - - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; - if (!(newdef = virDomainDefParseString(newxml, caps, driver->xmlopt, NULL, + if (!(newdef = virDomainDefParseString(newxml, driver->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; @@ -6659,7 +6647,6 @@ qemuDomainSaveImageOpen(virQEMUDriverPtr driver, virQEMUSaveHeaderPtr header; virDomainDefPtr def = NULL; int oflags = open_write ? O_RDWR : O_RDONLY; - g_autoptr(virCaps) caps = NULL; size_t xml_len; size_t cookie_len; @@ -6673,9 +6660,6 @@ qemuDomainSaveImageOpen(virQEMUDriverPtr driver, oflags |= directFlag; } - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto error; - if ((fd = qemuOpenFile(driver, NULL, path, oflags, NULL)) < 0) goto error; if (bypass_cache && @@ -6770,7 +6754,7 @@ qemuDomainSaveImageOpen(virQEMUDriverPtr driver, } /* Create a domain from this XML */ - if (!(def = virDomainDefParseString(data->xml, caps, driver->xmlopt, qemuCaps, + if (!(def = virDomainDefParseString(data->xml, driver->xmlopt, qemuCaps, VIR_DOMAIN_DEF_PARSE_INACTIVE | VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE))) goto error; @@ -7343,7 +7327,6 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn, virCommandPtr cmd = NULL; char *ret = NULL; size_t i; - g_autoptr(virCaps) caps = NULL; virCheckFlags(0, NULL); @@ -7356,13 +7339,10 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn, goto cleanup; } - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; - if (!(vm = virDomainObjNew(driver->xmlopt))) goto cleanup; - if (!(vm->def = virDomainDefParseString(xmlData, caps, driver->xmlopt, NULL, + if (!(vm->def = virDomainDefParseString(xmlData, driver->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE | VIR_DOMAIN_DEF_PARSE_ABI_UPDATE))) goto cleanup; @@ -7587,7 +7567,6 @@ qemuDomainDefineXMLFlags(virConnectPtr conn, virDomainPtr dom = NULL; virObjectEventPtr event = NULL; g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver); - g_autoptr(virCaps) caps = NULL; unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE | VIR_DOMAIN_DEF_PARSE_ABI_UPDATE; @@ -7596,10 +7575,7 @@ qemuDomainDefineXMLFlags(virConnectPtr conn, if (flags & VIR_DOMAIN_DEFINE_VALIDATE) parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA; - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; - - if (!(def = virDomainDefParseString(xml, caps, driver->xmlopt, + if (!(def = virDomainDefParseString(xml, driver->xmlopt, NULL, parse_flags))) goto cleanup; @@ -8641,7 +8617,7 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObjPtr vm, if (!vmdef) goto cleanup; - if (!(devConf = virDomainDeviceDefParse(xml, vmdef, caps, + if (!(devConf = virDomainDeviceDefParse(xml, vmdef, driver->xmlopt, priv->qemuCaps, parse_flags))) goto cleanup; @@ -8662,7 +8638,7 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObjPtr vm, } if (flags & VIR_DOMAIN_AFFECT_LIVE) { - if (!(devLive = virDomainDeviceDefParse(xml, vm->def, caps, + if (!(devLive = virDomainDeviceDefParse(xml, vm->def, driver->xmlopt, priv->qemuCaps, parse_flags))) goto cleanup; @@ -8793,7 +8769,7 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom, !(flags & VIR_DOMAIN_AFFECT_LIVE)) parse_flags |= VIR_DOMAIN_DEF_PARSE_INACTIVE; - dev = dev_copy = virDomainDeviceDefParse(xml, vm->def, caps, + dev = dev_copy = virDomainDeviceDefParse(xml, vm->def, driver->xmlopt, priv->qemuCaps, parse_flags); if (dev == NULL) @@ -8890,7 +8866,7 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriverPtr driver, !(flags & VIR_DOMAIN_AFFECT_LIVE)) parse_flags |= VIR_DOMAIN_DEF_PARSE_INACTIVE; - dev = dev_copy = virDomainDeviceDefParse(xml, vm->def, caps, + dev = dev_copy = virDomainDeviceDefParse(xml, vm->def, driver->xmlopt, priv->qemuCaps, parse_flags); if (dev == NULL) @@ -15930,7 +15906,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain, if (!(xml = qemuDomainDefFormatLive(driver, priv->qemuCaps, vm->def, priv->origCPU, true, true)) || - !(def->parent.dom = virDomainDefParseString(xml, caps, driver->xmlopt, + !(def->parent.dom = virDomainDefParseString(xml, driver->xmlopt, priv->qemuCaps, VIR_DOMAIN_DEF_PARSE_INACTIVE | VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE))) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index e9470cc62c..9086a3a95a 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -1945,7 +1945,6 @@ qemuMigrationSrcBeginPhase(virQEMUDriverPtr driver, qemuMigrationCookiePtr mig = NULL; virDomainDefPtr def = NULL; qemuDomainObjPrivatePtr priv = vm->privateData; - virCapsPtr caps = NULL; unsigned int cookieFlags = QEMU_MIGRATION_COOKIE_LOCKSTATE; VIR_DEBUG("driver=%p, vm=%p, xmlin=%s, dname=%s," @@ -1955,9 +1954,6 @@ qemuMigrationSrcBeginPhase(virQEMUDriverPtr driver, cookieout, cookieoutlen, nmigrate_disks, migrate_disks, flags); - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; - /* Only set the phase if we are inside QEMU_ASYNC_JOB_MIGRATION_OUT. * Otherwise we will start the async job later in the perform phase losing * change protection. @@ -2074,7 +2070,7 @@ qemuMigrationSrcBeginPhase(virQEMUDriverPtr driver, } if (xmlin) { - if (!(def = virDomainDefParseString(xmlin, caps, driver->xmlopt, priv->qemuCaps, + if (!(def = virDomainDefParseString(xmlin, driver->xmlopt, priv->qemuCaps, VIR_DOMAIN_DEF_PARSE_INACTIVE | VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE))) goto cleanup; @@ -2090,7 +2086,6 @@ qemuMigrationSrcBeginPhase(virQEMUDriverPtr driver, cleanup: qemuMigrationCookieFree(mig); - virObjectUnref(caps); virDomainDefFree(def); return rv; } @@ -2289,7 +2284,6 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver, char *xmlout = NULL; unsigned int cookieFlags; unsigned int startFlags; - virCapsPtr caps = NULL; qemuProcessIncomingDefPtr incoming = NULL; bool taint_hook = false; bool stopProcess = false; @@ -2340,9 +2334,6 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver, goto cleanup; } - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; - if (!qemuMigrationSrcIsAllowedHostdev(*def)) goto cleanup; @@ -2371,7 +2362,7 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver, virDomainDefPtr newdef; VIR_DEBUG("Using hook-filtered domain XML: %s", xmlout); - newdef = virDomainDefParseString(xmlout, caps, driver->xmlopt, NULL, + newdef = virDomainDefParseString(xmlout, driver->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE | VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE); if (!newdef) @@ -2619,7 +2610,6 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver, virDomainObjEndAPI(&vm); virObjectEventStateQueue(driver->domainEventState, event); qemuMigrationCookieFree(mig); - virObjectUnref(caps); virNWFilterUnlockFilterUpdates(); virErrorRestore(&origErr); return ret; @@ -2857,7 +2847,6 @@ qemuMigrationAnyPrepareDef(virQEMUDriverPtr driver, const char *dname, char **origname) { - virCapsPtr caps = NULL; virDomainDefPtr def; char *name = NULL; @@ -2867,10 +2856,7 @@ qemuMigrationAnyPrepareDef(virQEMUDriverPtr driver, return NULL; } - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - return NULL; - - if (!(def = virDomainDefParseString(dom_xml, caps, driver->xmlopt, + if (!(def = virDomainDefParseString(dom_xml, driver->xmlopt, qemuCaps, VIR_DOMAIN_DEF_PARSE_INACTIVE | VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE))) @@ -2882,7 +2868,6 @@ qemuMigrationAnyPrepareDef(virQEMUDriverPtr driver, } cleanup: - virObjectUnref(caps); if (def && origname) *origname = name; else diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_cookie.c index 33b3529f8c..9cfb08951c 100644 --- a/src/qemu/qemu_migration_cookie.c +++ b/src/qemu/qemu_migration_cookie.c @@ -1198,10 +1198,6 @@ qemuMigrationCookieXMLParse(qemuMigrationCookiePtr mig, xmlNodePtr *nodes = NULL; size_t i; int n; - virCapsPtr caps = NULL; - - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto error; /* We don't store the uuid, name, hostname, or hostuuid * values. We just compare them to local data to do some @@ -1330,7 +1326,7 @@ qemuMigrationCookieXMLParse(qemuMigrationCookiePtr mig, goto error; } mig->persistent = virDomainDefParseNode(doc, nodes[0], - caps, driver->xmlopt, qemuCaps, + driver->xmlopt, qemuCaps, VIR_DOMAIN_DEF_PARSE_INACTIVE | VIR_DOMAIN_DEF_PARSE_ABI_UPDATE_MIGRATION | VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE); @@ -1369,13 +1365,11 @@ qemuMigrationCookieXMLParse(qemuMigrationCookiePtr mig, !(mig->caps = qemuMigrationCookieCapsXMLParse(ctxt))) goto error; - virObjectUnref(caps); return 0; error: VIR_FREE(tmp); VIR_FREE(nodes); - virObjectUnref(caps); return -1; } diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 820db5b911..c93dddb228 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -690,7 +690,7 @@ get_definition(vahControl * ctl, const char *xmlStr) } ctl->def = virDomainDefParseString(xmlStr, - ctl->caps, ctl->xmlopt, NULL, + ctl->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_SKIP_SECLABEL | VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE); diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 630cfa1574..c5c533d369 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -945,7 +945,7 @@ testParseDomains(testDriverPtr privconn, goto error; def = virDomainDefParseNode(ctxt->doc, node, - privconn->caps, privconn->xmlopt, NULL, + privconn->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE); if (!def) goto error; @@ -1678,7 +1678,7 @@ testDomainCreateXML(virConnectPtr conn, const char *xml, parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA; virObjectLock(privconn); - if ((def = virDomainDefParseString(xml, privconn->caps, privconn->xmlopt, + if ((def = virDomainDefParseString(xml, privconn->xmlopt, NULL, parse_flags)) == NULL) goto cleanup; @@ -2294,7 +2294,7 @@ testDomainSaveImageOpen(testDriverPtr driver, } xml[len] = '\0'; - if (!(def = virDomainDefParseString(xml, driver->caps, driver->xmlopt, NULL, + if (!(def = virDomainDefParseString(xml, driver->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE | VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE))) goto error; @@ -2437,7 +2437,7 @@ testDomainSaveImageDefineXML(virConnectPtr conn, goto cleanup; VIR_FORCE_CLOSE(fd); - if ((newdef = virDomainDefParseString(dxml, privconn->caps, privconn->xmlopt, NULL, + if ((newdef = virDomainDefParseString(dxml, privconn->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE)) == NULL) goto cleanup; @@ -3989,7 +3989,7 @@ static virDomainPtr testDomainDefineXMLFlags(virConnectPtr conn, if (flags & VIR_DOMAIN_DEFINE_VALIDATE) parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA; - if ((def = virDomainDefParseString(xml, privconn->caps, privconn->xmlopt, + if ((def = virDomainDefParseString(xml, privconn->xmlopt, NULL, parse_flags)) == NULL) goto cleanup; diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 1feb76c0a5..1703120928 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -1858,7 +1858,7 @@ vboxDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags if (!data->vboxObj) return ret; - if (!(def = virDomainDefParseString(xml, data->caps, data->xmlopt, + if (!(def = virDomainDefParseString(xml, data->xmlopt, NULL, parse_flags))) return ret; @@ -4257,7 +4257,7 @@ static int vboxDomainAttachDeviceImpl(virDomainPtr dom, def->os.type = VIR_DOMAIN_OSTYPE_HVM; - dev = virDomainDeviceDefParse(xml, def, data->caps, data->xmlopt, NULL, + dev = virDomainDeviceDefParse(xml, def, data->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE); if (dev == NULL) goto cleanup; @@ -4376,7 +4376,7 @@ static int vboxDomainDetachDevice(virDomainPtr dom, const char *xml) def->os.type = VIR_DOMAIN_OSTYPE_HVM; - dev = virDomainDeviceDefParse(xml, def, data->caps, data->xmlopt, NULL, + dev = virDomainDeviceDefParse(xml, def, data->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE | VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE); if (dev == NULL) diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index b30c8847d3..32c81b13a0 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -421,7 +421,7 @@ vmwareDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int fla ctx.datacenterPath = NULL; vmwareDriverLock(driver); - if ((vmdef = virDomainDefParseString(xml, driver->caps, driver->xmlopt, + if ((vmdef = virDomainDefParseString(xml, driver->xmlopt, NULL, parse_flags)) == NULL) goto cleanup; @@ -683,7 +683,7 @@ vmwareDomainCreateXML(virConnectPtr conn, const char *xml, vmwareDriverLock(driver); - if ((vmdef = virDomainDefParseString(xml, driver->caps, driver->xmlopt, + if ((vmdef = virDomainDefParseString(xml, driver->xmlopt, NULL, parse_flags)) == NULL) goto cleanup; diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index a76c56334d..0acdcb9760 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -792,7 +792,7 @@ vzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) if (flags & VIR_DOMAIN_DEFINE_VALIDATE) parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA; - if ((def = virDomainDefParseString(xml, driver->caps, driver->xmlopt, + if ((def = virDomainDefParseString(xml, driver->xmlopt, NULL, parse_flags)) == NULL) goto cleanup; @@ -2992,7 +2992,7 @@ vzDomainMigratePrepare3Params(virConnectPtr conn, | VZ_MIGRATION_COOKIE_DOMAIN_NAME) < 0) goto cleanup; - if (!(def = virDomainDefParseString(dom_xml, driver->caps, driver->xmlopt, + if (!(def = virDomainDefParseString(dom_xml, driver->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; diff --git a/tests/bhyvexml2argvtest.c b/tests/bhyvexml2argvtest.c index f5dbb4e154..3c9c61f024 100644 --- a/tests/bhyvexml2argvtest.c +++ b/tests/bhyvexml2argvtest.c @@ -35,7 +35,7 @@ static int testCompareXMLToArgvFiles(const char *xml, if (!(conn = virGetConnect())) goto out; - if (!(vmdef = virDomainDefParseFile(xml, driver.caps, driver.xmlopt, + if (!(vmdef = virDomainDefParseFile(xml, driver.xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE))) { if (flags & FLAG_EXPECT_PARSE_ERROR) { ret = 0; diff --git a/tests/domainconftest.c b/tests/domainconftest.c index f48c3ca682..754ef2eb3d 100644 --- a/tests/domainconftest.c +++ b/tests/domainconftest.c @@ -49,7 +49,7 @@ static int testGetFilesystem(const void *opaque) filename = g_strdup_printf("%s/domainconfdata/%s.xml", abs_srcdir, data->filename); - if (!(def = virDomainDefParseFile(filename, caps, xmlopt, NULL, 0))) + if (!(def = virDomainDefParseFile(filename, xmlopt, NULL, 0))) goto cleanup; fsdef = virDomainGetFilesystemForTarget(def, diff --git a/tests/libxlxml2domconfigtest.c b/tests/libxlxml2domconfigtest.c index 5c8dcf8503..35f0ce8f7d 100644 --- a/tests/libxlxml2domconfigtest.c +++ b/tests/libxlxml2domconfigtest.c @@ -76,7 +76,7 @@ testCompareXMLToDomConfig(const char *xmlfile, if (!(gports = virPortAllocatorRangeNew("vnc", 5900, 6000))) goto cleanup; - if (!(vmdef = virDomainDefParseFile(xmlfile, cfg->caps, driver->xmlopt, + if (!(vmdef = virDomainDefParseFile(xmlfile, driver->xmlopt, NULL, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; diff --git a/tests/qemuagenttest.c b/tests/qemuagenttest.c index 9dbbfb3cfe..d8824b8f09 100644 --- a/tests/qemuagenttest.c +++ b/tests/qemuagenttest.c @@ -185,7 +185,7 @@ testQemuAgentGetFSInfoCommon(virDomainXMLOptionPtr xmlopt, domain_filename = g_strdup_printf("%s/qemuagentdata/fsinfo.xml", abs_srcdir); - if (!(ret_def = virDomainDefParseFile(domain_filename, driver.caps, xmlopt, + if (!(ret_def = virDomainDefParseFile(domain_filename, xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c index b1e53505be..e80545056d 100644 --- a/tests/qemuhotplugtest.c +++ b/tests/qemuhotplugtest.c @@ -87,7 +87,6 @@ qemuHotplugCreateObjects(virDomainXMLOptionPtr xmlopt, return -1; if (!((*vm)->def = virDomainDefParseString(domxml, - driver.caps, driver.xmlopt, NULL, parseFlags))) @@ -277,7 +276,7 @@ testQemuHotplug(const void *data) device_parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE; if (!(dev = virDomainDeviceDefParse(device_xml, vm->def, - caps, driver.xmlopt, NULL, + driver.xmlopt, NULL, device_parse_flags))) goto cleanup; diff --git a/tests/qemumemlocktest.c b/tests/qemumemlocktest.c index 55f65dcb6a..986dfb77bd 100644 --- a/tests/qemumemlocktest.c +++ b/tests/qemumemlocktest.c @@ -37,7 +37,7 @@ testCompareMemLock(const void *data) xml = g_strdup_printf("%s/qemumemlockdata/qemumemlock-%s.xml", abs_srcdir, info->name); - if (!(def = virDomainDefParseFile(xml, driver.caps, driver.xmlopt, NULL, + if (!(def = virDomainDefParseFile(xml, driver.xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE))) { goto cleanup; } diff --git a/tests/qemusecuritytest.c b/tests/qemusecuritytest.c index 8c0a48bb65..380c3fed8c 100644 --- a/tests/qemusecuritytest.c +++ b/tests/qemusecuritytest.c @@ -68,7 +68,6 @@ prepareObjects(virQEMUDriverPtr driver, return -1; if (!(vm->def = virDomainDefParseString(domxml, - driver->caps, driver->xmlopt, NULL, 0))) diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 6890de101b..fe8fa776be 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -450,7 +450,7 @@ testCompareXMLToArgv(const void *data) parseFlags |= VIR_DOMAIN_DEF_PARSE_INACTIVE; if (!(vm->def = virDomainDefParseFile(info->infile, - driver.caps, driver.xmlopt, + driver.xmlopt, NULL, parseFlags))) { if (flags & FLAG_EXPECT_PARSE_ERROR) goto ok; diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index f849869735..e5bbd8dec4 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -58,7 +58,7 @@ testCompareStatusXMLToXMLFiles(const void *opaque) char *actual = NULL; int ret = -1; - if (!(obj = virDomainObjParseFile(data->infile, driver.caps, driver.xmlopt, + if (!(obj = virDomainObjParseFile(data->infile, driver.xmlopt, VIR_DOMAIN_DEF_PARSE_STATUS | VIR_DOMAIN_DEF_PARSE_ACTUAL_NET | VIR_DOMAIN_DEF_PARSE_PCI_ORIG_STATES | diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabeltest.c index cbc7018e27..192f2dc84f 100644 --- a/tests/securityselinuxlabeltest.c +++ b/tests/securityselinuxlabeltest.c @@ -175,7 +175,7 @@ testSELinuxLoadDef(const char *testname) xmlfile = g_strdup_printf("%s/securityselinuxlabeldata/%s.xml", abs_srcdir, testname); - if (!(def = virDomainDefParseFile(xmlfile, driver.caps, driver.xmlopt, + if (!(def = virDomainDefParseFile(xmlfile, driver.xmlopt, NULL, 0))) goto cleanup; diff --git a/tests/testutils.c b/tests/testutils.c index 94a0e9068f..c55450de96 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -1107,7 +1107,8 @@ virDomainXMLOptionPtr virTestGenericDomainXMLConfInit(void) int -testCompareDomXML2XMLFiles(virCapsPtr caps, virDomainXMLOptionPtr xmlopt, +testCompareDomXML2XMLFiles(virCapsPtr caps G_GNUC_UNUSED, + virDomainXMLOptionPtr xmlopt, const char *infile, const char *outfile, bool live, unsigned int parseFlags, testCompareDomXML2XMLResult expectResult) @@ -1129,7 +1130,7 @@ testCompareDomXML2XMLFiles(virCapsPtr caps, virDomainXMLOptionPtr xmlopt, if (!live) format_flags |= VIR_DOMAIN_DEF_FORMAT_INACTIVE; - if (!(def = virDomainDefParseFile(infile, caps, xmlopt, NULL, parse_flags))) { + if (!(def = virDomainDefParseFile(infile, xmlopt, NULL, parse_flags))) { result = TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE; goto out; } diff --git a/tests/xlconfigtest.c b/tests/xlconfigtest.c index cdc2c37ed3..3c0469be85 100644 --- a/tests/xlconfigtest.c +++ b/tests/xlconfigtest.c @@ -83,11 +83,11 @@ testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars) if (replaceVars) { if (!(replacedXML = testReplaceVarsXML(xml))) goto fail; - if (!(def = virDomainDefParseString(replacedXML, cfg->caps, driver->xmlopt, + if (!(def = virDomainDefParseString(replacedXML, driver->xmlopt, NULL, VIR_DOMAIN_XML_INACTIVE))) goto fail; } else { - if (!(def = virDomainDefParseFile(xml, cfg->caps, driver->xmlopt, + if (!(def = virDomainDefParseFile(xml, driver->xmlopt, NULL, VIR_DOMAIN_XML_INACTIVE))) goto fail; } diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c index f8652e228c..7e324eb5d2 100644 --- a/tests/xmconfigtest.c +++ b/tests/xmconfigtest.c @@ -53,7 +53,7 @@ testCompareParseXML(const char *xmcfg, const char *xml) conn = virGetConnect(); if (!conn) goto fail; - if (!(def = virDomainDefParseFile(xml, cfg->caps, driver->xmlopt, NULL, + if (!(def = virDomainDefParseFile(xml, driver->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto fail; diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c index 39781beafd..8f0a2a72a4 100644 --- a/tests/xml2vmxtest.c +++ b/tests/xml2vmxtest.c @@ -74,7 +74,7 @@ testCompareFiles(const char *xml, const char *vmx, int virtualHW_version) char *formatted = NULL; virDomainDefPtr def = NULL; - def = virDomainDefParseFile(xml, caps, xmlopt, NULL, + def = virDomainDefParseFile(xml, xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE); if (def == NULL) -- 2.23.0

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/conf/domain_conf.c | 17 ++++++----------- src/conf/domain_conf.h | 9 ++------- src/libxl/libxl_domain.c | 6 +++--- src/libxl/libxl_driver.c | 15 ++++++--------- src/libxl/libxl_migration.c | 3 +-- src/lxc/lxc_driver.c | 22 ++++++---------------- src/lxc/lxc_process.c | 2 +- src/qemu/qemu_domain.c | 7 +------ src/qemu/qemu_driver.c | 26 +++++++++++--------------- src/qemu/qemu_migration.c | 2 +- src/qemu/qemu_process.c | 2 +- src/test/test_driver.c | 7 ++----- tests/qemuhotplugtest.c | 2 +- 13 files changed, 42 insertions(+), 78 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 00b5da8d52..011e104220 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -3670,8 +3670,7 @@ virDomainObjWaitUntil(virDomainObjPtr vm, * @return 0 on success, -1 on failure */ int -virDomainObjSetDefTransient(virCapsPtr caps, - virDomainXMLOptionPtr xmlopt, +virDomainObjSetDefTransient(virDomainXMLOptionPtr xmlopt, virDomainObjPtr domain, void *parseOpaque) { @@ -3683,7 +3682,7 @@ virDomainObjSetDefTransient(virCapsPtr caps, if (domain->newDef) return 0; - if (!(domain->newDef = virDomainDefCopy(domain->def, caps, xmlopt, + if (!(domain->newDef = virDomainDefCopy(domain->def, xmlopt, parseOpaque, false))) goto out; @@ -3721,13 +3720,12 @@ virDomainObjRemoveTransientDef(virDomainObjPtr domain) * @return NULL on error, virDOmainDefPtr on success */ virDomainDefPtr -virDomainObjGetPersistentDef(virCapsPtr caps, - virDomainXMLOptionPtr xmlopt, +virDomainObjGetPersistentDef(virDomainXMLOptionPtr xmlopt, virDomainObjPtr domain, void *parseOpaque) { if (virDomainObjIsActive(domain) && - virDomainObjSetDefTransient(caps, xmlopt, domain, parseOpaque) < 0) + virDomainObjSetDefTransient(xmlopt, domain, parseOpaque) < 0) return NULL; if (domain->newDef) @@ -29304,7 +29302,6 @@ virDomainUSBDeviceDefForeach(virDomainDefPtr def, * snapshots). */ virDomainDefPtr virDomainDefCopy(virDomainDefPtr src, - virCapsPtr caps G_GNUC_UNUSED, virDomainXMLOptionPtr xmlopt, void *parseOpaque, bool migratable) @@ -29326,14 +29323,13 @@ virDomainDefCopy(virDomainDefPtr src, virDomainDefPtr virDomainObjCopyPersistentDef(virDomainObjPtr dom, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, void *parseOpaque) { virDomainDefPtr cur; - cur = virDomainObjGetPersistentDef(caps, xmlopt, dom, parseOpaque); - return virDomainDefCopy(cur, caps, xmlopt, parseOpaque, false); + cur = virDomainObjGetPersistentDef(xmlopt, dom, parseOpaque); + return virDomainDefCopy(cur, xmlopt, parseOpaque, false); } @@ -29778,7 +29774,6 @@ virDomainNetFindByName(virDomainDefPtr def, virDomainDeviceDefPtr virDomainDeviceDefCopy(virDomainDeviceDefPtr src, const virDomainDef *def, - virCapsPtr caps G_GNUC_UNUSED, virDomainXMLOptionPtr xmlopt, void *parseOpaque) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 5255c8190e..1aac01a386 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2895,7 +2895,6 @@ void virDomainShmemDefFree(virDomainShmemDefPtr def); void virDomainDeviceDefFree(virDomainDeviceDefPtr def); virDomainDeviceDefPtr virDomainDeviceDefCopy(virDomainDeviceDefPtr src, const virDomainDef *def, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, void *parseOpaque); virDomainDeviceInfoPtr virDomainDeviceGetInfo(virDomainDeviceDefPtr device); @@ -2936,14 +2935,12 @@ void virDomainObjAssignDef(virDomainObjPtr domain, virDomainDefPtr def, bool live, virDomainDefPtr *oldDef); -int virDomainObjSetDefTransient(virCapsPtr caps, - virDomainXMLOptionPtr xmlopt, +int virDomainObjSetDefTransient(virDomainXMLOptionPtr xmlopt, virDomainObjPtr domain, void *parseOpaque); void virDomainObjRemoveTransientDef(virDomainObjPtr domain); virDomainDefPtr -virDomainObjGetPersistentDef(virCapsPtr caps, - virDomainXMLOptionPtr xmlopt, +virDomainObjGetPersistentDef(virDomainXMLOptionPtr xmlopt, virDomainObjPtr domain, void *parseOpaque); @@ -2960,12 +2957,10 @@ virDomainDefPtr virDomainObjGetOneDefState(virDomainObjPtr vm, virDomainDefPtr virDomainObjGetOneDef(virDomainObjPtr vm, unsigned int flags); virDomainDefPtr virDomainDefCopy(virDomainDefPtr src, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, void *parseOpaque, bool migratable); virDomainDefPtr virDomainObjCopyPersistentDef(virDomainObjPtr dom, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, void *parseOpaque); diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index fea20ba477..0ad511c373 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -1322,7 +1322,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver, VIR_FREE(managed_save_path); } - if (virDomainObjSetDefTransient(cfg->caps, driver->xmlopt, vm, NULL) < 0) + if (virDomainObjSetDefTransient(driver->xmlopt, vm, NULL) < 0) goto cleanup; /* Run an early hook to set-up missing devices */ @@ -1550,8 +1550,8 @@ libxlDomainDefCheckABIStability(libxlDriverPrivatePtr driver, g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver); bool ret = false; - if (!(migratableDefSrc = virDomainDefCopy(src, cfg->caps, driver->xmlopt, NULL, true)) || - !(migratableDefDst = virDomainDefCopy(dst, cfg->caps, driver->xmlopt, NULL, true))) + if (!(migratableDefSrc = virDomainDefCopy(src, driver->xmlopt, NULL, true)) || + !(migratableDefDst = virDomainDefCopy(dst, driver->xmlopt, NULL, true))) goto cleanup; ret = virDomainDefCheckABIStability(migratableDefSrc, diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index abf359ad1b..11a08ed68a 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -1601,7 +1601,7 @@ libxlDomainGetMaxMemory(virDomainPtr dom) * domain configuration if needed. Return -1 on error. */ static int -virDomainLiveConfigHelperMethod(virCapsPtr caps, +virDomainLiveConfigHelperMethod(virCapsPtr caps G_GNUC_UNUSED, virDomainXMLOptionPtr xmlopt, virDomainObjPtr dom, unsigned int *flags, @@ -1611,7 +1611,7 @@ virDomainLiveConfigHelperMethod(virCapsPtr caps, return -1; if (*flags & VIR_DOMAIN_AFFECT_CONFIG) { - if (!(*persistentDef = virDomainObjGetPersistentDef(caps, xmlopt, dom, NULL))) { + if (!(*persistentDef = virDomainObjGetPersistentDef(xmlopt, dom, NULL))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Get persistent config failed")); return -1; @@ -2298,7 +2298,7 @@ libxlDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus, goto endjob; } - if (!(def = virDomainObjGetPersistentDef(cfg->caps, driver->xmlopt, vm, NULL))) + if (!(def = virDomainObjGetPersistentDef(driver->xmlopt, vm, NULL))) goto endjob; maplen = VIR_CPU_MAPLEN(nvcpus); @@ -4121,8 +4121,7 @@ libxlDomainAttachDeviceFlags(virDomainPtr dom, const char *xml, goto endjob; /* Make a copy for updated domain. */ - if (!(vmdef = virDomainObjCopyPersistentDef(vm, cfg->caps, - driver->xmlopt, NULL))) + if (!(vmdef = virDomainObjCopyPersistentDef(vm, driver->xmlopt, NULL))) goto endjob; if (libxlDomainAttachDeviceConfig(vmdef, dev) < 0) @@ -4211,8 +4210,7 @@ libxlDomainDetachDeviceFlags(virDomainPtr dom, const char *xml, goto endjob; /* Make a copy for updated domain. */ - if (!(vmdef = virDomainObjCopyPersistentDef(vm, cfg->caps, - driver->xmlopt, NULL))) + if (!(vmdef = virDomainObjCopyPersistentDef(vm, driver->xmlopt, NULL))) goto endjob; if (libxlDomainDetachDeviceConfig(vmdef, dev) < 0) @@ -4298,8 +4296,7 @@ libxlDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml, goto cleanup; /* Make a copy for updated domain. */ - if (!(vmdef = virDomainObjCopyPersistentDef(vm, cfg->caps, - driver->xmlopt, NULL))) + if (!(vmdef = virDomainObjCopyPersistentDef(vm, driver->xmlopt, NULL))) goto cleanup; if ((ret = libxlDomainUpdateDeviceConfig(vmdef, dev)) < 0) diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c index d744816510..0d10da1811 100644 --- a/src/libxl/libxl_migration.c +++ b/src/libxl/libxl_migration.c @@ -1321,8 +1321,7 @@ libxlDomainMigrationDstFinish(virConnectPtr dconn, virDomainDefPtr vmdef; vm->persistent = 1; - if (!(vmdef = virDomainObjGetPersistentDef(cfg->caps, - driver->xmlopt, vm, NULL))) + if (!(vmdef = virDomainObjGetPersistentDef(driver->xmlopt, vm, NULL))) goto cleanup; if (virDomainDefSave(vmdef, driver->xmlopt, cfg->caps, cfg->configDir) < 0) diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 1ef15bfcf8..55945bafcd 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1907,7 +1907,7 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr dom, if (persistentDef) { /* Make a copy for updated domain. */ - persistentDefCopy = virDomainObjCopyPersistentDef(vm, caps, driver->xmlopt, NULL); + persistentDefCopy = virDomainObjCopyPersistentDef(vm, driver->xmlopt, NULL); if (!persistentDefCopy) goto endjob; } @@ -4673,7 +4673,6 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom, unsigned int flags) { virLXCDriverPtr driver = dom->conn->privateData; - virCapsPtr caps = NULL; virDomainObjPtr vm = NULL; virDomainDefPtr vmdef = NULL; virDomainDeviceDefPtr dev = NULL, dev_copy = NULL; @@ -4692,9 +4691,6 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom, if (virLXCDomainObjBeginJob(driver, vm, LXC_JOB_MODIFY) < 0) goto cleanup; - if (!(caps = virLXCDriverGetCapabilities(driver, false))) - goto endjob; - if (virDomainObjUpdateModificationImpact(vm, &flags) < 0) goto endjob; @@ -4711,14 +4707,14 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom, * to CONFIG takes one instance. */ dev_copy = virDomainDeviceDefCopy(dev, vm->def, - caps, driver->xmlopt, NULL); + driver->xmlopt, NULL); if (!dev_copy) goto endjob; } if (flags & VIR_DOMAIN_AFFECT_CONFIG) { /* Make a copy for updated domain. */ - vmdef = virDomainObjCopyPersistentDef(vm, caps, driver->xmlopt, NULL); + vmdef = virDomainObjCopyPersistentDef(vm, driver->xmlopt, NULL); if (!vmdef) goto endjob; @@ -4768,7 +4764,6 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom, virDomainDeviceDefFree(dev_copy); virDomainDeviceDefFree(dev); virDomainObjEndAPI(&vm); - virObjectUnref(caps); virObjectUnref(cfg); return ret; } @@ -4787,7 +4782,6 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom, unsigned int flags) { virLXCDriverPtr driver = dom->conn->privateData; - virCapsPtr caps = NULL; virDomainObjPtr vm = NULL; virDomainDefPtr vmdef = NULL; virDomainDeviceDefPtr dev = NULL; @@ -4815,15 +4809,12 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom, goto endjob; } - if (!(caps = virLXCDriverGetCapabilities(driver, false))) - goto endjob; - if (!(dev = virDomainDeviceDefParse(xml, vm->def, driver->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto endjob; /* Make a copy for updated domain. */ - if (!(vmdef = virDomainObjCopyPersistentDef(vm, caps, driver->xmlopt, NULL))) + if (!(vmdef = virDomainObjCopyPersistentDef(vm, driver->xmlopt, NULL))) goto endjob; /* virDomainDefCompatibleDevice call is delayed until we know the @@ -4845,7 +4836,6 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom, virDomainDefFree(vmdef); virDomainDeviceDefFree(dev); virDomainObjEndAPI(&vm); - virObjectUnref(caps); virObjectUnref(cfg); return ret; } @@ -4895,14 +4885,14 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom, * to CONFIG takes one instance. */ dev_copy = virDomainDeviceDefCopy(dev, vm->def, - caps, driver->xmlopt, NULL); + driver->xmlopt, NULL); if (!dev_copy) goto endjob; } if (flags & VIR_DOMAIN_AFFECT_CONFIG) { /* Make a copy for updated domain. */ - vmdef = virDomainObjCopyPersistentDef(vm, caps, driver->xmlopt, NULL); + vmdef = virDomainObjCopyPersistentDef(vm, driver->xmlopt, NULL); if (!vmdef) goto endjob; diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index cd8ee4975b..e648d490c8 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -1266,7 +1266,7 @@ int virLXCProcessStart(virConnectPtr conn, * report implicit runtime defaults in the XML, like vnc listen/socket */ VIR_DEBUG("Setting current domain def as transient"); - if (virDomainObjSetDefTransient(caps, driver->xmlopt, vm, NULL) < 0) + if (virDomainObjSetDefTransient(driver->xmlopt, vm, NULL) < 0) goto cleanup; /* Run an early hook to set-up missing devices */ diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 4c589eec05..3abd37e25d 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -9035,17 +9035,13 @@ qemuDomainDefFormatBufInternal(virQEMUDriverPtr driver, { int ret = -1; virDomainDefPtr copy = NULL; - virCapsPtr caps = NULL; virCheckFlags(VIR_DOMAIN_XML_COMMON_FLAGS | VIR_DOMAIN_XML_UPDATE_CPU, -1); - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; - if (!(flags & (VIR_DOMAIN_XML_UPDATE_CPU | VIR_DOMAIN_XML_MIGRATABLE))) goto format; - if (!(copy = virDomainDefCopy(def, caps, driver->xmlopt, qemuCaps, + if (!(copy = virDomainDefCopy(def, driver->xmlopt, qemuCaps, flags & VIR_DOMAIN_XML_MIGRATABLE))) goto cleanup; @@ -9219,7 +9215,6 @@ qemuDomainDefFormatBufInternal(virQEMUDriverPtr driver, cleanup: virDomainDefFree(copy); - virObjectUnref(caps); return ret; } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 00788e7aca..a3b470d7b8 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -8612,7 +8612,7 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObjPtr vm, * rely on the correct vm->def or vm->newDef being passed, so call the * device parse based on which definition is in use */ if (flags & VIR_DOMAIN_AFFECT_CONFIG) { - vmdef = virDomainObjCopyPersistentDef(vm, caps, driver->xmlopt, + vmdef = virDomainObjCopyPersistentDef(vm, driver->xmlopt, priv->qemuCaps); if (!vmdef) goto cleanup; @@ -8781,7 +8781,7 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom, * create a deep copy of device as adding * to CONFIG takes one instance. */ - dev_copy = virDomainDeviceDefCopy(dev, vm->def, caps, + dev_copy = virDomainDeviceDefCopy(dev, vm->def, driver->xmlopt, priv->qemuCaps); if (!dev_copy) goto endjob; @@ -8789,7 +8789,7 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom, if (flags & VIR_DOMAIN_AFFECT_CONFIG) { /* Make a copy for updated domain. */ - vmdef = virDomainObjCopyPersistentDef(vm, caps, driver->xmlopt, + vmdef = virDomainObjCopyPersistentDef(vm, driver->xmlopt, priv->qemuCaps); if (!vmdef) goto endjob; @@ -8878,7 +8878,7 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriverPtr driver, * create a deep copy of device as adding * to CONFIG takes one instance. */ - dev_copy = virDomainDeviceDefCopy(dev, vm->def, caps, + dev_copy = virDomainDeviceDefCopy(dev, vm->def, driver->xmlopt, priv->qemuCaps); if (!dev_copy) goto cleanup; @@ -8886,7 +8886,7 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriverPtr driver, if (flags & VIR_DOMAIN_AFFECT_CONFIG) { /* Make a copy for updated domain. */ - vmdef = virDomainObjCopyPersistentDef(vm, caps, driver->xmlopt, priv->qemuCaps); + vmdef = virDomainObjCopyPersistentDef(vm, driver->xmlopt, priv->qemuCaps); if (!vmdef) goto cleanup; @@ -8967,7 +8967,7 @@ qemuDomainDetachDeviceAliasLiveAndConfig(virQEMUDriverPtr driver, if (persistentDef) { virDomainDeviceDef dev; - if (!(vmdef = virDomainObjCopyPersistentDef(vm, caps, driver->xmlopt, + if (!(vmdef = virDomainObjCopyPersistentDef(vm, driver->xmlopt, priv->qemuCaps))) goto cleanup; @@ -10570,7 +10570,7 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom, if (persistentDef) { /* Make a copy for updated domain. */ - if (!(persistentDefCopy = virDomainObjCopyPersistentDef(vm, caps, + if (!(persistentDefCopy = virDomainObjCopyPersistentDef(vm, driver->xmlopt, priv->qemuCaps))) goto endjob; @@ -15913,7 +15913,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain, goto endjob; if (vm->newDef) { - def->parent.inactiveDom = virDomainDefCopy(vm->newDef, caps, + def->parent.inactiveDom = virDomainDefCopy(vm->newDef, driver->xmlopt, priv->qemuCaps, true); if (!def->parent.inactiveDom) goto endjob; @@ -16441,7 +16441,6 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, virDomainDefPtr config = NULL; virDomainDefPtr inactiveConfig = NULL; g_autoptr(virQEMUDriverConfig) cfg = NULL; - g_autoptr(virCaps) caps = NULL; bool was_stopped = false; qemuDomainSaveCookiePtr cookie; virCPUDefPtr origCPU = NULL; @@ -16478,9 +16477,6 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, if (virDomainRevertToSnapshotEnsureACL(snapshot->domain->conn, vm->def) < 0) goto cleanup; - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; - if (qemuDomainHasBlockjob(vm, false)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("domain has active block job")); @@ -16532,14 +16528,14 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, } if (snap->def->dom) { - config = virDomainDefCopy(snap->def->dom, caps, + config = virDomainDefCopy(snap->def->dom, driver->xmlopt, priv->qemuCaps, true); if (!config) goto endjob; } if (snap->def->inactiveDom) { - inactiveConfig = virDomainDefCopy(snap->def->inactiveDom, caps, + inactiveConfig = virDomainDefCopy(snap->def->inactiveDom, driver->xmlopt, priv->qemuCaps, true); if (!inactiveConfig) goto endjob; @@ -16552,7 +16548,7 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, */ if (snapdef->state == VIR_DOMAIN_SNAPSHOT_RUNNING || snapdef->state == VIR_DOMAIN_SNAPSHOT_PAUSED) { - inactiveConfig = virDomainDefCopy(snap->def->dom, caps, + inactiveConfig = virDomainDefCopy(snap->def->dom, driver->xmlopt, priv->qemuCaps, true); if (!inactiveConfig) goto endjob; diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 9086a3a95a..1a6c179999 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -4823,7 +4823,7 @@ qemuMigrationDstPersist(virQEMUDriverPtr driver, oldDef = vm->newDef; vm->newDef = qemuMigrationCookieGetPersistent(mig); - if (!(vmdef = virDomainObjGetPersistentDef(caps, driver->xmlopt, vm, + if (!(vmdef = virDomainObjGetPersistentDef(driver->xmlopt, vm, priv->qemuCaps))) goto error; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 33ebdce01e..0302d0489b 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5600,7 +5600,7 @@ qemuProcessInit(virQEMUDriverPtr driver, * report implicit runtime defaults in the XML, like vnc listen/socket */ VIR_DEBUG("Setting current domain def as transient"); - if (virDomainObjSetDefTransient(caps, driver->xmlopt, vm, priv->qemuCaps) < 0) + if (virDomainObjSetDefTransient(driver->xmlopt, vm, priv->qemuCaps) < 0) goto cleanup; if (flags & VIR_QEMU_PROCESS_START_PRETEND) { diff --git a/src/test/test_driver.c b/src/test/test_driver.c index c5c533d369..02f6175e2f 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -696,8 +696,7 @@ testDomainStartState(testDriverPtr privconn, virDomainObjSetState(dom, VIR_DOMAIN_RUNNING, reason); dom->def->id = virAtomicIntAdd(&privconn->nextDomID, 1); - if (virDomainObjSetDefTransient(privconn->caps, - privconn->xmlopt, + if (virDomainObjSetDefTransient(privconn->xmlopt, dom, NULL) < 0) { goto cleanup; } @@ -8571,7 +8570,6 @@ testDomainSnapshotCreateXML(virDomainPtr domain, goto cleanup; } else { if (!(def->parent.dom = virDomainDefCopy(vm->def, - privconn->caps, privconn->xmlopt, NULL, true))) @@ -8794,7 +8792,7 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, virDomainSnapshotSetCurrent(vm->snapshots, NULL); - config = virDomainDefCopy(snap->def->dom, privconn->caps, + config = virDomainDefCopy(snap->def->dom, privconn->xmlopt, NULL, true); if (!config) goto cleanup; @@ -9027,7 +9025,6 @@ testDomainCheckpointCreateXML(virDomainPtr domain, goto cleanup; } else { if (!(def->parent.dom = virDomainDefCopy(vm->def, - privconn->caps, privconn->xmlopt, NULL, true))) diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c index e80545056d..8e7273b673 100644 --- a/tests/qemuhotplugtest.c +++ b/tests/qemuhotplugtest.c @@ -427,7 +427,7 @@ testQemuHotplugCpuPrepare(const char *test, /* create vm->newDef */ data->vm->persistent = true; - if (virDomainObjSetDefTransient(caps, driver.xmlopt, data->vm, NULL) < 0) + if (virDomainObjSetDefTransient(driver.xmlopt, data->vm, NULL) < 0) goto error; priv = data->vm->privateData; -- 2.23.0

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/bhyve/bhyve_driver.c | 9 +-- src/bhyve/bhyve_process.c | 16 +----- src/conf/domain_conf.c | 7 +-- src/conf/domain_conf.h | 3 - src/libxl/libxl_domain.c | 2 +- src/libxl/libxl_driver.c | 34 +++++------ src/libxl/libxl_migration.c | 6 +- src/lxc/lxc_driver.c | 39 ++++++------- src/lxc/lxc_process.c | 6 +- src/qemu/qemu_domain.c | 6 +- src/qemu/qemu_driver.c | 110 +++++++++++++++++------------------- src/qemu/qemu_hotplug.c | 8 +-- src/qemu/qemu_migration.c | 8 +-- src/qemu/qemu_process.c | 36 ++++++------ src/test/test_driver.c | 2 +- 15 files changed, 128 insertions(+), 164 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 0e627f2dc8..eecd6532f7 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -540,7 +540,7 @@ bhyveDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flag vm->persistent = 1; if (virDomainDefSave(vm->newDef ? vm->newDef : vm->def, - privconn->xmlopt, caps, BHYVE_CONFIG_DIR) < 0) { + privconn->xmlopt, BHYVE_CONFIG_DIR) < 0) { virDomainObjListRemove(privconn->domains, vm); goto cleanup; } @@ -1063,7 +1063,6 @@ bhyveDomainSetMetadata(virDomainPtr dom, { bhyveConnPtr privconn = dom->conn->privateData; virDomainObjPtr vm; - virCapsPtr caps = NULL; int ret = -1; virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | @@ -1075,10 +1074,7 @@ bhyveDomainSetMetadata(virDomainPtr dom, if (virDomainSetMetadataEnsureACL(dom->conn, vm->def, flags) < 0) goto cleanup; - if (!(caps = bhyveDriverGetCapabilities(privconn))) - goto cleanup; - - ret = virDomainObjSetMetadata(vm, type, metadata, key, uri, caps, + ret = virDomainObjSetMetadata(vm, type, metadata, key, uri, privconn->xmlopt, BHYVE_STATE_DIR, BHYVE_CONFIG_DIR, flags); @@ -1090,7 +1086,6 @@ bhyveDomainSetMetadata(virDomainPtr dom, cleanup: - virObjectUnref(caps); virDomainObjEndAPI(&vm); return ret; } diff --git a/src/bhyve/bhyve_process.c b/src/bhyve/bhyve_process.c index c10e5500c9..519604f898 100644 --- a/src/bhyve/bhyve_process.c +++ b/src/bhyve/bhyve_process.c @@ -110,14 +110,9 @@ virBhyveProcessStart(virConnectPtr conn, bhyveConnPtr privconn = conn->privateData; bhyveDomainObjPrivatePtr priv = vm->privateData; int ret = -1, rc; - virCapsPtr caps = NULL; logfile = g_strdup_printf("%s/%s.log", BHYVE_LOG_DIR, vm->def->name); - caps = bhyveDriverGetCapabilities(privconn); - if (!caps) - goto cleanup; - if ((logfd = open(logfile, O_WRONLY | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR)) < 0) { virReportSystemError(errno, @@ -211,14 +206,13 @@ virBhyveProcessStart(virConnectPtr conn, virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, reason); priv->mon = bhyveMonitorOpen(vm, driver); - if (virDomainObjSave(vm, driver->xmlopt, caps, + if (virDomainObjSave(vm, driver->xmlopt, BHYVE_STATE_DIR) < 0) goto cleanup; ret = 0; cleanup: - virObjectUnref(caps); if (devicemap != NULL) { rc = unlink(devmap_file); if (rc < 0 && errno != ENOENT) @@ -384,7 +378,6 @@ virBhyveProcessReconnect(virDomainObjPtr vm, char *expected_proctitle = NULL; bhyveDomainObjPrivatePtr priv = vm->privateData; int ret = -1; - virCapsPtr caps = NULL; if (!virDomainObjIsActive(vm)) return 0; @@ -392,10 +385,6 @@ virBhyveProcessReconnect(virDomainObjPtr vm, if (!vm->pid) return 0; - caps = bhyveDriverGetCapabilities(data->driver); - if (!caps) - return -1; - virObjectLock(vm); kp = kvm_getprocs(data->kd, KERN_PROC_PID, vm->pid, &nprocs); @@ -429,11 +418,10 @@ virBhyveProcessReconnect(virDomainObjPtr vm, vm->def->id = -1; virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_UNKNOWN); - ignore_value(virDomainObjSave(vm, data->driver->xmlopt, caps, + ignore_value(virDomainObjSave(vm, data->driver->xmlopt, BHYVE_STATE_DIR)); } - virObjectUnref(caps); virObjectUnlock(vm); VIR_FREE(expected_proctitle); diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 011e104220..64084d37d5 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -28987,7 +28987,6 @@ virDomainDefSaveXML(virDomainDefPtr def, int virDomainDefSave(virDomainDefPtr def, virDomainXMLOptionPtr xmlopt, - virCapsPtr caps G_GNUC_UNUSED, const char *configDir) { g_autofree char *xml = NULL; @@ -29001,7 +29000,6 @@ virDomainDefSave(virDomainDefPtr def, int virDomainObjSave(virDomainObjPtr obj, virDomainXMLOptionPtr xmlopt, - virCapsPtr caps G_GNUC_UNUSED, const char *statusDir) { unsigned int flags = (VIR_DOMAIN_DEF_FORMAT_SECURE | @@ -30093,7 +30091,6 @@ virDomainObjSetMetadata(virDomainObjPtr vm, const char *metadata, const char *key, const char *uri, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, const char *stateDir, const char *configDir, @@ -30112,7 +30109,7 @@ virDomainObjSetMetadata(virDomainObjPtr vm, if (virDomainDefSetMetadata(def, type, metadata, key, uri) < 0) return -1; - if (virDomainObjSave(vm, xmlopt, caps, stateDir) < 0) + if (virDomainObjSave(vm, xmlopt, stateDir) < 0) return -1; } @@ -30121,7 +30118,7 @@ virDomainObjSetMetadata(virDomainObjPtr vm, uri) < 0) return -1; - if (virDomainDefSave(persistentDef, xmlopt, caps, configDir) < 0) + if (virDomainDefSave(persistentDef, xmlopt, configDir) < 0) return -1; } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 1aac01a386..a4d80c0863 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3280,7 +3280,6 @@ virDomainRedirdevDefPtr virDomainRedirdevDefRemove(virDomainDefPtr def, size_t i int virDomainDefSave(virDomainDefPtr def, virDomainXMLOptionPtr xmlopt, - virCapsPtr caps, const char *configDir) G_GNUC_WARN_UNUSED_RESULT ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) @@ -3288,7 +3287,6 @@ int virDomainDefSave(virDomainDefPtr def, int virDomainObjSave(virDomainObjPtr obj, virDomainXMLOptionPtr xmlopt, - virCapsPtr caps, const char *statusDir) G_GNUC_WARN_UNUSED_RESULT ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) @@ -3538,7 +3536,6 @@ int virDomainObjSetMetadata(virDomainObjPtr vm, const char *metadata, const char *key, const char *uri, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, const char *stateDir, const char *configDir, diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 0ad511c373..ff9502d3bb 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -1470,7 +1470,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, VIR_DOMAIN_PAUSED_USER); } - if (virDomainObjSave(vm, driver->xmlopt, cfg->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto destroy_dom; if (virAtomicIntInc(&driver->nactive) == 1 && driver->inhibitCallback) diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 11a08ed68a..cdb1296aa3 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -453,7 +453,7 @@ libxlReconnectDomain(virDomainObjPtr vm, libxlReconnectNotifyNets(vm->def); - if (virDomainObjSave(vm, driver->xmlopt, cfg->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) VIR_WARN("Cannot update XML for running Xen guest %s", vm->def->name); /* now that we know it's reconnected call the hook if present */ @@ -1188,7 +1188,7 @@ libxlDomainSuspend(virDomainPtr dom) VIR_DOMAIN_EVENT_SUSPENDED_PAUSED); } - if (virDomainObjSave(vm, driver->xmlopt, cfg->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto endjob; ret = 0; @@ -1242,7 +1242,7 @@ libxlDomainResume(virDomainPtr dom) VIR_DOMAIN_EVENT_RESUMED_UNPAUSED); } - if (virDomainObjSave(vm, driver->xmlopt, cfg->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto endjob; ret = 0; @@ -1667,7 +1667,7 @@ libxlDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem, virDomainDefSetMemoryTotal(persistentDef, newmem); if (persistentDef->mem.cur_balloon > newmem) persistentDef->mem.cur_balloon = newmem; - ret = virDomainDefSave(persistentDef, driver->xmlopt, cfg->caps, cfg->configDir); + ret = virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir); goto endjob; } @@ -1700,7 +1700,7 @@ libxlDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem, if (flags & VIR_DOMAIN_MEM_CONFIG) { sa_assert(persistentDef); persistentDef->mem.cur_balloon = newmem; - ret = virDomainDefSave(persistentDef, driver->xmlopt, cfg->caps, cfg->configDir); + ret = virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir); goto endjob; } } @@ -2351,13 +2351,13 @@ libxlDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus, ret = 0; if (flags & VIR_DOMAIN_VCPU_LIVE) { - if (virDomainObjSave(vm, driver->xmlopt, cfg->caps, cfg->stateDir) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) { VIR_WARN("Unable to save status on vm %s after changing vcpus", vm->def->name); } } if (flags & VIR_DOMAIN_VCPU_CONFIG) { - if (virDomainDefSave(def, driver->xmlopt, cfg->caps, cfg->configDir) < 0) { + if (virDomainDefSave(def, driver->xmlopt, cfg->configDir) < 0) { VIR_WARN("Unable to save configuration of vm %s after changing vcpus", vm->def->name); } @@ -2507,9 +2507,9 @@ libxlDomainPinVcpuFlags(virDomainPtr dom, unsigned int vcpu, ret = 0; if (flags & VIR_DOMAIN_AFFECT_LIVE) { - ret = virDomainObjSave(vm, driver->xmlopt, cfg->caps, cfg->stateDir); + ret = virDomainObjSave(vm, driver->xmlopt, cfg->stateDir); } else if (flags & VIR_DOMAIN_AFFECT_CONFIG) { - ret = virDomainDefSave(targetDef, driver->xmlopt, cfg->caps, cfg->configDir); + ret = virDomainDefSave(targetDef, driver->xmlopt, cfg->configDir); } endjob: @@ -2870,7 +2870,7 @@ libxlDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flag vm->persistent = 1; if (virDomainDefSave(vm->newDef ? vm->newDef : vm->def, - driver->xmlopt, cfg->caps, cfg->configDir) < 0) { + driver->xmlopt, cfg->configDir) < 0) { virDomainObjListRemove(driver->domains, vm); goto cleanup; } @@ -4143,7 +4143,7 @@ libxlDomainAttachDeviceFlags(virDomainPtr dom, const char *xml, * update domain status forcibly because the domain status may be * changed even if we attach the device failed. */ - if (virDomainObjSave(vm, driver->xmlopt, cfg->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto endjob; } @@ -4151,7 +4151,7 @@ libxlDomainAttachDeviceFlags(virDomainPtr dom, const char *xml, /* Finally, if no error until here, we can save config. */ if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) { - ret = virDomainDefSave(vmdef, driver->xmlopt, cfg->caps, cfg->configDir); + ret = virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir); if (!ret) { virDomainObjAssignDef(vm, vmdef, false, NULL); vmdef = NULL; @@ -4233,7 +4233,7 @@ libxlDomainDetachDeviceFlags(virDomainPtr dom, const char *xml, * update domain status forcibly because the domain status may be * changed even if we attach the device failed. */ - if (virDomainObjSave(vm, driver->xmlopt, cfg->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto endjob; } @@ -4241,7 +4241,7 @@ libxlDomainDetachDeviceFlags(virDomainPtr dom, const char *xml, /* Finally, if no error until here, we can save config. */ if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) { - ret = virDomainDefSave(vmdef, driver->xmlopt, cfg->caps, cfg->configDir); + ret = virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir); if (!ret) { virDomainObjAssignDef(vm, vmdef, false, NULL); vmdef = NULL; @@ -4320,13 +4320,13 @@ libxlDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml, * update domain status forcibly because the domain status may be * changed even if we attach the device failed. */ - if (virDomainObjSave(vm, driver->xmlopt, cfg->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) ret = -1; } /* Finally, if no error until here, we can save config. */ if (!ret && (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG)) { - ret = virDomainDefSave(vmdef, driver->xmlopt, cfg->caps, cfg->configDir); + ret = virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir); if (!ret) { virDomainObjAssignDef(vm, vmdef, false, NULL); vmdef = NULL; @@ -6526,7 +6526,7 @@ libxlDomainSetMetadata(virDomainPtr dom, if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0) goto cleanup; - ret = virDomainObjSetMetadata(vm, type, metadata, key, uri, cfg->caps, + ret = virDomainObjSetMetadata(vm, type, metadata, key, uri, driver->xmlopt, cfg->stateDir, cfg->configDir, flags); diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c index 0d10da1811..404c437a22 100644 --- a/src/libxl/libxl_migration.c +++ b/src/libxl/libxl_migration.c @@ -1324,7 +1324,7 @@ libxlDomainMigrationDstFinish(virConnectPtr dconn, if (!(vmdef = virDomainObjGetPersistentDef(driver->xmlopt, vm, NULL))) goto cleanup; - if (virDomainDefSave(vmdef, driver->xmlopt, cfg->caps, cfg->configDir) < 0) + if (virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir) < 0) goto cleanup; event = virDomainEventLifecycleNewFromObj(vm, @@ -1336,7 +1336,7 @@ libxlDomainMigrationDstFinish(virConnectPtr dconn, event = NULL; } - if (virDomainObjSave(vm, driver->xmlopt, cfg->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto cleanup; dom = virGetDomain(dconn, vm->def->name, vm->def->uuid, vm->def->id); @@ -1386,7 +1386,7 @@ libxlDomainMigrationSrcConfirm(libxlDriverPrivatePtr driver, VIR_DOMAIN_PAUSED_MIGRATION); event = virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_SUSPENDED, VIR_DOMAIN_EVENT_SUSPENDED_MIGRATED); - ignore_value(virDomainObjSave(vm, driver->xmlopt, cfg->caps, cfg->stateDir)); + ignore_value(virDomainObjSave(vm, driver->xmlopt, cfg->stateDir)); } goto cleanup; } diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 55945bafcd..3467b07538 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -444,7 +444,7 @@ lxcDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) vm->persistent = 1; if (virDomainDefSave(vm->newDef ? vm->newDef : vm->def, - driver->xmlopt, driver->caps, cfg->configDir) < 0) { + driver->xmlopt, cfg->configDir) < 0) { virDomainObjListRemove(driver->domains, vm); goto cleanup; } @@ -678,7 +678,7 @@ static int lxcDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem, if (persistentDef->mem.cur_balloon > newmem) persistentDef->mem.cur_balloon = newmem; if (virDomainDefSave(persistentDef, - driver->xmlopt, driver->caps, cfg->configDir) < 0) + driver->xmlopt, cfg->configDir) < 0) goto endjob; } } else { @@ -705,14 +705,14 @@ static int lxcDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem, } def->mem.cur_balloon = newmem; - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto endjob; } if (persistentDef) { persistentDef->mem.cur_balloon = newmem; if (virDomainDefSave(persistentDef, - driver->xmlopt, driver->caps, cfg->configDir) < 0) + driver->xmlopt, cfg->configDir) < 0) goto endjob; } } @@ -857,11 +857,11 @@ lxcDomainSetMemoryParameters(virDomainPtr dom, #undef VIR_SET_MEM_PARAMETER if (def && - virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto endjob; if (persistentDef && - virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, cfg->configDir) < 0) + virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir) < 0) goto endjob; /* QEMU and LXC implementations are identical */ @@ -1967,12 +1967,12 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr dom, } } - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto endjob; if (persistentDef) { - rc = virDomainDefSave(persistentDefCopy, driver->xmlopt, driver->caps, + rc = virDomainDefSave(persistentDefCopy, driver->xmlopt, cfg->configDir); if (rc < 0) goto endjob; @@ -2673,7 +2673,7 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, } } - if (virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, cfg->configDir) < 0) + if (virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir) < 0) ret = -1; } @@ -3030,7 +3030,7 @@ static int lxcDomainSuspend(virDomainPtr dom) VIR_DOMAIN_EVENT_SUSPENDED_PAUSED); } - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto endjob; ret = 0; @@ -3087,7 +3087,7 @@ static int lxcDomainResume(virDomainPtr dom) VIR_DOMAIN_EVENT_RESUMED_UNPAUSED); } - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto endjob; ret = 0; @@ -4740,7 +4740,7 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom, * changed even if we failed to attach the device. For example, * a new controller may be created. */ - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) { ret = -1; goto endjob; } @@ -4748,7 +4748,7 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom, /* Finally, if no error until here, we can save config. */ if (flags & VIR_DOMAIN_AFFECT_CONFIG) { - ret = virDomainDefSave(vmdef, driver->xmlopt, driver->caps, cfg->configDir); + ret = virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir); if (!ret) { virDomainObjAssignDef(vm, vmdef, false, NULL); vmdef = NULL; @@ -4822,7 +4822,7 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom, if (lxcDomainUpdateDeviceConfig(vmdef, dev) < 0) goto endjob; - if (virDomainDefSave(vmdef, driver->xmlopt, driver->caps, cfg->configDir) < 0) + if (virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir) < 0) goto endjob; virDomainObjAssignDef(vm, vmdef, false, NULL); @@ -4908,7 +4908,7 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom, * changed even if we failed to attach the device. For example, * a new controller may be created. */ - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) { ret = -1; goto endjob; } @@ -4916,7 +4916,7 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom, /* Finally, if no error until here, we can save config. */ if (flags & VIR_DOMAIN_AFFECT_CONFIG) { - ret = virDomainDefSave(vmdef, driver->xmlopt, driver->caps, cfg->configDir); + ret = virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir); if (!ret) { virDomainObjAssignDef(vm, vmdef, false, NULL); vmdef = NULL; @@ -5207,7 +5207,6 @@ lxcDomainSetMetadata(virDomainPtr dom, virLXCDriverPtr driver = dom->conn->privateData; virDomainObjPtr vm; virLXCDriverConfigPtr cfg = NULL; - virCapsPtr caps = NULL; int ret = -1; virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | @@ -5221,13 +5220,10 @@ lxcDomainSetMetadata(virDomainPtr dom, if (virDomainSetMetadataEnsureACL(dom->conn, vm->def, flags) < 0) goto cleanup; - if (!(caps = virLXCDriverGetCapabilities(driver, false))) - goto cleanup; - if (virLXCDomainObjBeginJob(driver, vm, LXC_JOB_MODIFY) < 0) goto cleanup; - ret = virDomainObjSetMetadata(vm, type, metadata, key, uri, caps, + ret = virDomainObjSetMetadata(vm, type, metadata, key, uri, driver->xmlopt, cfg->stateDir, cfg->configDir, flags); @@ -5241,7 +5237,6 @@ lxcDomainSetMetadata(virDomainPtr dom, cleanup: virDomainObjEndAPI(&vm); - virObjectUnref(caps); virObjectUnref(cfg); return ret; } diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index e648d490c8..3688973abf 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -790,7 +790,7 @@ static void virLXCProcessMonitorInitNotify(virLXCMonitorPtr mon G_GNUC_UNUSED, } virDomainAuditInit(vm, initpid, inode); - if (virDomainObjSave(vm, lxc_driver->xmlopt, lxc_driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, lxc_driver->xmlopt, cfg->stateDir) < 0) VIR_WARN("Cannot update XML with PID for LXC %s", vm->def->name); virObjectUnlock(vm); @@ -1457,7 +1457,7 @@ int virLXCProcessStart(virConnectPtr conn, /* Write domain status to disk for the controller to * read when it starts */ - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto cleanup; /* Allow the child to exec the controller */ @@ -1696,7 +1696,7 @@ virLXCProcessReconnectDomain(virDomainObjPtr vm, virLXCProcessReconnectNotifyNets(vm->def); - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) VIR_WARN("Cannot update XML for running LXC guest %s", vm->def->name); /* now that we know it's reconnected call the hook if present */ diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 3abd37e25d..ee99759ded 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -8189,7 +8189,7 @@ qemuDomainObjSaveStatus(virQEMUDriverPtr driver, virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); if (virDomainObjIsActive(obj)) { - if (virDomainObjSave(obj, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(obj, driver->xmlopt, cfg->stateDir) < 0) VIR_WARN("Failed to save status on vm %s", obj->def->name); } @@ -8221,7 +8221,7 @@ qemuDomainSaveConfig(virDomainObjPtr obj) cfg = virQEMUDriverGetConfig(driver); - if (virDomainDefSave(def, driver->xmlopt, driver->caps, cfg->configDir) < 0) + if (virDomainDefSave(def, driver->xmlopt, cfg->configDir) < 0) VIR_WARN("Failed to save config of vm %s", obj->def->name); } @@ -10083,7 +10083,7 @@ qemuDomainSetFakeReboot(virQEMUDriverPtr driver, priv->fakeReboot = value; - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) VIR_WARN("Failed to save status on vm %s", vm->def->name); cleanup: diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index a3b470d7b8..91cf3fb21a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1865,7 +1865,7 @@ static int qemuDomainSuspend(virDomainPtr dom) if (qemuProcessStopCPUs(driver, vm, reason, QEMU_ASYNC_JOB_NONE) < 0) goto endjob; } - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto endjob; ret = 0; @@ -1923,7 +1923,7 @@ static int qemuDomainResume(virDomainPtr dom) goto endjob; } } - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto endjob; ret = 0; @@ -2365,7 +2365,7 @@ static int qemuDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem, if (persistentDef->mem.cur_balloon > newmem) persistentDef->mem.cur_balloon = newmem; - ret = virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, + ret = virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir); goto endjob; } @@ -2405,7 +2405,7 @@ static int qemuDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem, if (persistentDef) { persistentDef->mem.cur_balloon = newmem; - ret = virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, + ret = virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir); goto endjob; } @@ -2480,7 +2480,7 @@ static int qemuDomainSetMemoryStatsPeriod(virDomainPtr dom, int period, } def->memballoon->period = period; - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto endjob; } @@ -2492,7 +2492,7 @@ static int qemuDomainSetMemoryStatsPeriod(virDomainPtr dom, int period, goto endjob; } persistentDef->memballoon->period = period; - ret = virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, cfg->configDir); + ret = virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir); goto endjob; } @@ -4202,7 +4202,7 @@ processGuestPanicEvent(virQEMUDriverPtr driver, virObjectEventStateQueue(driver->domainEventState, event); - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) { VIR_WARN("Unable to save status on vm %s after state change", vm->def->name); } @@ -4282,7 +4282,7 @@ processDeviceDeletedEvent(virQEMUDriverPtr driver, goto endjob; } - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) VIR_WARN("unable to save domain status after removing device %s", devAlias); @@ -4650,7 +4650,7 @@ processSerialChangedEvent(virQEMUDriverPtr driver, dev.data.chr->state = newstate; - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) VIR_WARN("unable to save status of domain %s after updating state of " "channel %s", vm->def->name, devAlias); @@ -4976,7 +4976,7 @@ qemuDomainSetVcpusMax(virQEMUDriverPtr driver, if (virDomainDefSetVcpusMax(persistentDef, nvcpus, driver->xmlopt) < 0) return -1; - if (virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, cfg->configDir) < 0) + if (virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir) < 0) return -1; return 0; @@ -5105,7 +5105,7 @@ qemuDomainPinVcpuLive(virDomainObjPtr vm, vcpuinfo->cpumask = tmpmap; tmpmap = NULL; - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto cleanup; if (g_snprintf(paramField, VIR_TYPED_PARAM_FIELD_LENGTH, @@ -5188,7 +5188,7 @@ qemuDomainPinVcpuFlags(virDomainPtr dom, vcpuinfo->cpumask = pcpumap; pcpumap = NULL; - ret = virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, cfg->configDir); + ret = virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir); goto endjob; } @@ -5320,7 +5320,7 @@ qemuDomainPinEmulator(virDomainPtr dom, if (!(def->cputune.emulatorpin = virBitmapNewCopy(pcpumap))) goto endjob; - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto endjob; str = virBitmapFormat(pcpumap); @@ -5340,7 +5340,7 @@ qemuDomainPinEmulator(virDomainPtr dom, if (!(persistentDef->cputune.emulatorpin = virBitmapNewCopy(pcpumap))) goto endjob; - ret = virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, cfg->configDir); + ret = virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir); goto endjob; } @@ -5800,7 +5800,7 @@ qemuDomainPinIOThread(virDomainPtr dom, if (virProcessSetAffinity(iothrid->thread_id, pcpumap) < 0) goto endjob; - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto endjob; if (g_snprintf(paramField, VIR_TYPED_PARAM_FIELD_LENGTH, @@ -5833,7 +5833,7 @@ qemuDomainPinIOThread(virDomainPtr dom, iothrid->cpumask = cpumask; iothrid->autofill = false; - ret = virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, cfg->configDir); + ret = virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir); goto endjob; } @@ -6251,7 +6251,7 @@ qemuDomainChgIOThread(virQEMUDriverPtr driver, } - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto endjob; } @@ -6283,7 +6283,7 @@ qemuDomainChgIOThread(virQEMUDriverPtr driver, break; } - if (virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, + if (virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir) < 0) goto endjob; } @@ -6887,7 +6887,7 @@ qemuDomainSaveImageStartVM(virConnectPtr conn, "%s", _("failed to resume domain")); goto cleanup; } - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) { VIR_WARN("Failed to save status on vm %s", vm->def->name); goto cleanup; } @@ -7594,7 +7594,7 @@ qemuDomainDefineXMLFlags(virConnectPtr conn, vm->persistent = 1; if (virDomainDefSave(vm->newDef ? vm->newDef : vm->def, - driver->xmlopt, driver->caps, cfg->configDir) < 0) { + driver->xmlopt, cfg->configDir) < 0) { if (oldDef) { /* There is backup so this VM was defined before. * Just restore the backup. */ @@ -8659,13 +8659,13 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObjPtr vm, * changed even if we failed to attach the device. For example, * a new controller may be created. */ - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto cleanup; } /* Finally, if no error until here, we can save config. */ if (flags & VIR_DOMAIN_AFFECT_CONFIG) { - if (virDomainDefSave(vmdef, driver->xmlopt, driver->caps, cfg->configDir) < 0) + if (virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir) < 0) goto cleanup; virDomainObjAssignDef(vm, vmdef, false, NULL); @@ -8812,7 +8812,7 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom, * changed even if we failed to attach the device. For example, * a new controller may be created. */ - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) { ret = -1; goto endjob; } @@ -8820,7 +8820,7 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom, /* Finally, if no error until here, we can save config. */ if (flags & VIR_DOMAIN_AFFECT_CONFIG) { - ret = virDomainDefSave(vmdef, driver->xmlopt, driver->caps, cfg->configDir); + ret = virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir); if (!ret) { virDomainObjAssignDef(vm, vmdef, false, NULL); vmdef = NULL; @@ -8910,13 +8910,13 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriverPtr driver, * changed even if we failed to attach the device. For example, * a new controller may be created. */ - if (virDomainObjSave(vm, driver->xmlopt, caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto cleanup; } /* Finally, if no error until here, we can save config. */ if (flags & VIR_DOMAIN_AFFECT_CONFIG) { - if (virDomainDefSave(vmdef, driver->xmlopt, caps, cfg->configDir) < 0) + if (virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir) < 0) goto cleanup; virDomainObjAssignDef(vm, vmdef, false, NULL); @@ -8994,7 +8994,7 @@ qemuDomainDetachDeviceAliasLiveAndConfig(virQEMUDriverPtr driver, } if (vmdef) { - if (virDomainDefSave(vmdef, driver->xmlopt, caps, cfg->configDir) < 0) + if (virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir) < 0) goto cleanup; virDomainObjAssignDef(vm, vmdef, false, NULL); vmdef = NULL; @@ -9576,7 +9576,7 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, } } - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto endjob; } if (ret < 0) @@ -9611,7 +9611,7 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, } } - if (virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, cfg->configDir) < 0) + if (virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir) < 0) ret = -1; } @@ -9841,11 +9841,11 @@ qemuDomainSetMemoryParameters(virDomainPtr dom, #undef VIR_SET_MEM_PARAMETER if (def && - virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto endjob; if (persistentDef && - virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, cfg->configDir) < 0) + virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir) < 0) goto endjob; /* QEMU and LXC implementations are identical */ @@ -10108,7 +10108,7 @@ qemuDomainSetNumaParameters(virDomainPtr dom, -1, mode, nodeset) < 0) goto endjob; - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto endjob; } @@ -10119,7 +10119,7 @@ qemuDomainSetNumaParameters(virDomainPtr dom, -1, mode, nodeset) < 0) goto endjob; - if (virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, cfg->configDir) < 0) + if (virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir) < 0) goto endjob; } @@ -10301,7 +10301,7 @@ qemuDomainSetPerfEvents(virDomainPtr dom, VIR_TRISTATE_BOOL_YES : VIR_TRISTATE_BOOL_NO; } - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto endjob; } @@ -10315,7 +10315,7 @@ qemuDomainSetPerfEvents(virDomainPtr dom, VIR_TRISTATE_BOOL_YES : VIR_TRISTATE_BOOL_NO; } - if (virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, cfg->configDir) < 0) + if (virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir) < 0) goto endjob; } @@ -10513,7 +10513,6 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom, int ret = -1; int rc; g_autoptr(virQEMUDriverConfig) cfg = NULL; - g_autoptr(virCaps) caps = NULL; qemuDomainObjPrivatePtr priv; virObjectEventPtr event = NULL; virTypedParameterPtr eventParams = NULL; @@ -10559,9 +10558,6 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom, goto cleanup; } - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; - if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) goto cleanup; @@ -10777,7 +10773,7 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom, } } - if (virDomainObjSave(vm, driver->xmlopt, caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto endjob; if (eventNparams) { @@ -10787,7 +10783,7 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom, } if (persistentDef) { - rc = virDomainDefSave(persistentDefCopy, driver->xmlopt, caps, + rc = virDomainDefSave(persistentDefCopy, driver->xmlopt, cfg->configDir); if (rc < 0) goto endjob; @@ -11626,7 +11622,7 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom, goto endjob; } - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto endjob; } @@ -11651,7 +11647,7 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom, } } - if (virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, cfg->configDir) < 0) + if (virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir) < 0) goto endjob; } @@ -14612,7 +14608,7 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver, defdisk->src = g_steal_pointer(&newsrc); } - if (virDomainDefSave(vm->def, driver->xmlopt, driver->caps, cfg->configDir) < 0) + if (virDomainDefSave(vm->def, driver->xmlopt, cfg->configDir) < 0) goto cleanup; ret = 0; @@ -15549,8 +15545,8 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver, if (rc < 0) goto cleanup; - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0 || - (vm->newDef && virDomainDefSave(vm->newDef, driver->xmlopt, driver->caps, + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0 || + (vm->newDef && virDomainDefSave(vm->newDef, driver->xmlopt, cfg->configDir) < 0)) goto cleanup; @@ -16844,7 +16840,7 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, } if (ret == 0 && defined && vm->persistent && !(ret = virDomainDefSave(vm->newDef ? vm->newDef : vm->def, - driver->xmlopt, driver->caps, cfg->configDir))) { + driver->xmlopt, cfg->configDir))) { detail = VIR_DOMAIN_EVENT_DEFINED_FROM_SNAPSHOT; virObjectEventStateQueue(driver->domainEventState, virDomainEventLifecycleNewFromObj(vm, @@ -17649,7 +17645,7 @@ qemuDomainBlockJobAbort(virDomainPtr dom, job->state = QEMU_BLOCKJOB_STATE_ABORTING; } - ignore_value(virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir)); + ignore_value(virDomainObjSave(vm, driver->xmlopt, cfg->stateDir)); if (!async) { qemuBlockJobUpdate(vm, job, QEMU_ASYNC_JOB_NONE); @@ -19227,7 +19223,7 @@ qemuDomainSetBlockIoTune(virDomainPtr dom, if (virDomainDiskSetBlockIOTune(disk, &info) < 0) goto endjob; - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto endjob; if (eventNparams) { @@ -19252,7 +19248,7 @@ qemuDomainSetBlockIoTune(virDomainPtr dom, if (virDomainDiskSetBlockIOTune(conf_disk, &info) < 0) goto endjob; - if (virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, + if (virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir) < 0) goto endjob; } @@ -19513,7 +19509,6 @@ qemuDomainSetMetadata(virDomainPtr dom, virQEMUDriverPtr driver = dom->conn->privateData; virDomainObjPtr vm; g_autoptr(virQEMUDriverConfig) cfg = NULL; - g_autoptr(virCaps) caps = NULL; int ret = -1; virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | @@ -19527,13 +19522,10 @@ qemuDomainSetMetadata(virDomainPtr dom, if (virDomainSetMetadataEnsureACL(dom->conn, vm->def, flags) < 0) goto cleanup; - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; - if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) goto cleanup; - ret = virDomainObjSetMetadata(vm, type, metadata, key, uri, caps, + ret = virDomainObjSetMetadata(vm, type, metadata, key, uri, driver->xmlopt, cfg->stateDir, cfg->configDir, flags); @@ -21854,7 +21846,7 @@ qemuDomainRenameCallback(virDomainObjPtr vm, vm->def->name = new_dom_name; new_dom_name = NULL; - if (virDomainDefSave(vm->def, driver->xmlopt, driver->caps, cfg->configDir) < 0) + if (virDomainDefSave(vm->def, driver->xmlopt, cfg->configDir) < 0) goto rollback; if (virFileExists(old_dom_cfg_file) && @@ -22378,14 +22370,14 @@ qemuDomainSetLifecycleAction(virDomainPtr dom, qemuDomainModifyLifecycleAction(def, type, action); - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto endjob; } if (persistentDef) { qemuDomainModifyLifecycleAction(persistentDef, type, action); - if (virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, + if (virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir) < 0) goto endjob; } @@ -22681,7 +22673,7 @@ qemuDomainAgentSetResponseTimeout(virDomainPtr dom, QEMU_DOMAIN_PRIVATE(vm)->agentTimeout = timeout; if (virDomainObjIsActive(vm) && - virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto cleanup; ret = 0; diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index da32a845e1..930f4283c8 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -5980,7 +5980,7 @@ qemuDomainHotplugDelVcpu(virQEMUDriverPtr driver, qemuDomainVcpuPersistOrder(vm->def); - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto cleanup; ret = 0; @@ -6055,7 +6055,7 @@ qemuDomainHotplugAddVcpu(virQEMUDriverPtr driver, qemuDomainVcpuPersistOrder(vm->def); - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto cleanup; ret = 0; @@ -6313,7 +6313,7 @@ qemuDomainSetVcpusInternal(virQEMUDriverPtr driver, if (persistentDef) { qemuDomainSetVcpusConfig(persistentDef, nvcpus, hotpluggable); - if (virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, cfg->configDir) < 0) + if (virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir) < 0) goto cleanup; } @@ -6513,7 +6513,7 @@ qemuDomainSetVcpuInternal(virQEMUDriverPtr driver, if (persistentDef) { qemuDomainSetVcpuConfig(persistentDef, map, state); - if (virDomainDefSave(persistentDef, driver->xmlopt, driver->caps, cfg->configDir) < 0) + if (virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir) < 0) goto cleanup; } diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 1a6c179999..c7f9acadeb 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -1008,7 +1008,7 @@ qemuMigrationSrcNBDStorageCopy(virQEMUDriverPtr driver, tlsAlias, flags) < 0) return -1; - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) { VIR_WARN("Failed to save status on vm %s", vm->def->name); return -1; } @@ -2976,7 +2976,7 @@ qemuMigrationSrcConfirmPhase(virQEMUDriverPtr driver, qemuMigrationParamsReset(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT, priv->job.migParams, priv->job.apiFlags); - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) VIR_WARN("Failed to save status on vm %s", vm->def->name); } @@ -4827,7 +4827,7 @@ qemuMigrationDstPersist(virQEMUDriverPtr driver, priv->qemuCaps))) goto error; - if (virDomainDefSave(vmdef, driver->xmlopt, driver->caps, cfg->configDir) < 0 && + if (virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir) < 0 && !ignoreSaveError) goto error; @@ -5080,7 +5080,7 @@ qemuMigrationDstFinish(virQEMUDriverPtr driver, } if (virDomainObjIsActive(vm) && - virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) VIR_WARN("Failed to save status on vm %s", vm->def->name); /* Guest is successfully running, so cancel previous auto destroy */ diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 0302d0489b..7a0cbc109f 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -411,7 +411,7 @@ qemuProcessHandleReset(qemuMonitorPtr mon G_GNUC_UNUSED, if (priv->agent) qemuAgentNotifyEvent(priv->agent, QEMU_AGENT_EVENT_RESET); - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) VIR_WARN("Failed to save status on vm %s", vm->def->name); if (vm->def->onReboot == VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY || @@ -493,7 +493,7 @@ qemuProcessFakeReboot(void *opaque) goto endjob; } - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) { VIR_WARN("Unable to save status on vm %s after state change", vm->def->name); } @@ -614,7 +614,7 @@ qemuProcessHandleShutdown(qemuMonitorPtr mon G_GNUC_UNUSED, VIR_DOMAIN_EVENT_SHUTDOWN, detail); - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) { VIR_WARN("Unable to save status on vm %s after state change", vm->def->name); } @@ -680,7 +680,7 @@ qemuProcessHandleStop(qemuMonitorPtr mon G_GNUC_UNUSED, VIR_WARN("Unable to release lease on %s", vm->def->name); VIR_DEBUG("Preserving lock state '%s'", NULLSTR(priv->lockState)); - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) { VIR_WARN("Unable to save status on vm %s after state change", vm->def->name); } @@ -726,7 +726,7 @@ qemuProcessHandleResume(qemuMonitorPtr mon G_GNUC_UNUSED, VIR_DOMAIN_EVENT_RESUMED, eventDetail); - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) { VIR_WARN("Unable to save status on vm %s after state change", vm->def->name); } @@ -769,7 +769,7 @@ qemuProcessHandleRTCChange(qemuMonitorPtr mon G_GNUC_UNUSED, offset += vm->def->clock.data.variable.adjustment0; vm->def->clock.data.variable.adjustment = offset; - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) VIR_WARN("unable to save domain status with RTC change"); } @@ -812,7 +812,7 @@ qemuProcessHandleWatchdog(qemuMonitorPtr mon G_GNUC_UNUSED, VIR_WARN("Unable to release lease on %s", vm->def->name); VIR_DEBUG("Preserving lock state '%s'", NULLSTR(priv->lockState)); - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) { VIR_WARN("Unable to save status on vm %s after watchdog event", vm->def->name); } @@ -904,7 +904,7 @@ qemuProcessHandleIOError(qemuMonitorPtr mon G_GNUC_UNUSED, VIR_WARN("Unable to release lease on %s", vm->def->name); VIR_DEBUG("Preserving lock state '%s'", NULLSTR(priv->lockState)); - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) VIR_WARN("Unable to save status on vm %s after IO error", vm->def->name); } virObjectUnlock(vm); @@ -1149,7 +1149,7 @@ qemuProcessHandleTrayChange(qemuMonitorPtr mon G_GNUC_UNUSED, else if (reason == VIR_DOMAIN_EVENT_TRAY_CHANGE_CLOSE) disk->tray_status = VIR_DOMAIN_DISK_TRAY_CLOSED; - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) { VIR_WARN("Unable to save status on vm %s after tray moved event", vm->def->name); } @@ -1189,7 +1189,7 @@ qemuProcessHandlePMWakeup(qemuMonitorPtr mon G_GNUC_UNUSED, VIR_DOMAIN_EVENT_STARTED, VIR_DOMAIN_EVENT_STARTED_WAKEUP); - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) { VIR_WARN("Unable to save status on vm %s after wakeup event", vm->def->name); } @@ -1227,7 +1227,7 @@ qemuProcessHandlePMSuspend(qemuMonitorPtr mon G_GNUC_UNUSED, VIR_DOMAIN_EVENT_PMSUSPENDED, VIR_DOMAIN_EVENT_PMSUSPENDED_MEMORY); - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) { VIR_WARN("Unable to save status on vm %s after suspend event", vm->def->name); } @@ -1261,7 +1261,7 @@ qemuProcessHandleBalloonChange(qemuMonitorPtr mon G_GNUC_UNUSED, vm->def->mem.cur_balloon, actual); vm->def->mem.cur_balloon = actual; - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) VIR_WARN("unable to save domain status with balloon change"); virObjectUnlock(vm); @@ -1296,7 +1296,7 @@ qemuProcessHandlePMSuspendDisk(qemuMonitorPtr mon G_GNUC_UNUSED, VIR_DOMAIN_EVENT_PMSUSPENDED, VIR_DOMAIN_EVENT_PMSUSPENDED_DISK); - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) { VIR_WARN("Unable to save status on vm %s after suspend event", vm->def->name); } @@ -1669,7 +1669,7 @@ qemuProcessHandleMigrationStatus(qemuMonitorPtr mon G_GNUC_UNUSED, VIR_DOMAIN_EVENT_SUSPENDED, VIR_DOMAIN_EVENT_SUSPENDED_POSTCOPY); - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) { + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) { VIR_WARN("Unable to save status on vm %s after state change", vm->def->name); } @@ -3105,7 +3105,7 @@ qemuProcessUpdateVideoRamSize(virQEMUDriverPtr driver, return -1; cfg = virQEMUDriverGetConfig(driver); - ret = virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir); + ret = virDomainObjSave(vm, driver->xmlopt, cfg->stateDir); virObjectUnref(cfg); return ret; @@ -6860,7 +6860,7 @@ qemuProcessLaunch(virConnectPtr conn, } VIR_DEBUG("Writing early domain status to disk"); - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto cleanup; VIR_DEBUG("Waiting for handshake from child"); @@ -7118,7 +7118,7 @@ qemuProcessFinishStartup(virQEMUDriverPtr driver, } VIR_DEBUG("Writing domain status to disk"); - if (virDomainObjSave(vm, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto cleanup; if (qemuProcessStartHook(driver, vm, @@ -8221,7 +8221,7 @@ qemuProcessReconnect(void *opaque) } /* update domain state XML with possibly updated state in virDomainObj */ - if (virDomainObjSave(obj, driver->xmlopt, driver->caps, cfg->stateDir) < 0) + if (virDomainObjSave(obj, driver->xmlopt, cfg->stateDir) < 0) goto error; /* Run an hook to allow admins to do some magic */ diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 02f6175e2f..788d5d3676 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4066,7 +4066,7 @@ static int testDomainSetMetadata(virDomainPtr dom, return -1; ret = virDomainObjSetMetadata(privdom, type, metadata, key, uri, - privconn->caps, privconn->xmlopt, + privconn->xmlopt, NULL, NULL, flags); if (ret == 0) { -- 2.23.0

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/bhyve/bhyve_driver.c | 2 -- src/conf/virdomainobjlist.c | 5 ----- src/conf/virdomainobjlist.h | 1 - src/libxl/libxl_driver.c | 3 --- src/lxc/lxc_driver.c | 14 -------------- src/qemu/qemu_driver.c | 8 +------- 6 files changed, 1 insertion(+), 32 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index eecd6532f7..a764b4d4ed 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -1249,7 +1249,6 @@ bhyveStateInitialize(bool privileged, if (virDomainObjListLoadAllConfigs(bhyve_driver->domains, BHYVE_STATE_DIR, NULL, true, - bhyve_driver->caps, bhyve_driver->xmlopt, NULL, NULL) < 0) goto cleanup; @@ -1257,7 +1256,6 @@ bhyveStateInitialize(bool privileged, if (virDomainObjListLoadAllConfigs(bhyve_driver->domains, BHYVE_CONFIG_DIR, BHYVE_AUTOSTART_DIR, false, - bhyve_driver->caps, bhyve_driver->xmlopt, NULL, NULL) < 0) goto cleanup; diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c index ae18a4544f..417025ae9f 100644 --- a/src/conf/virdomainobjlist.c +++ b/src/conf/virdomainobjlist.c @@ -483,7 +483,6 @@ virDomainObjListRename(virDomainObjListPtr doms, static virDomainObjPtr virDomainObjListLoadConfig(virDomainObjListPtr doms, - virCapsPtr caps G_GNUC_UNUSED, virDomainXMLOptionPtr xmlopt, const char *configDir, const char *autostartDir, @@ -536,7 +535,6 @@ static virDomainObjPtr virDomainObjListLoadStatus(virDomainObjListPtr doms, const char *statusDir, const char *name, - virCapsPtr caps G_GNUC_UNUSED, virDomainXMLOptionPtr xmlopt, virDomainLoadConfigNotify notify, void *opaque) @@ -586,7 +584,6 @@ virDomainObjListLoadAllConfigs(virDomainObjListPtr doms, const char *configDir, const char *autostartDir, bool liveStatus, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, virDomainLoadConfigNotify notify, void *opaque) @@ -616,13 +613,11 @@ virDomainObjListLoadAllConfigs(virDomainObjListPtr doms, dom = virDomainObjListLoadStatus(doms, configDir, entry->d_name, - caps, xmlopt, notify, opaque); else dom = virDomainObjListLoadConfig(doms, - caps, xmlopt, configDir, autostartDir, diff --git a/src/conf/virdomainobjlist.h b/src/conf/virdomainobjlist.h index da5ec8a57c..6150e13aa4 100644 --- a/src/conf/virdomainobjlist.h +++ b/src/conf/virdomainobjlist.h @@ -66,7 +66,6 @@ int virDomainObjListLoadAllConfigs(virDomainObjListPtr doms, const char *configDir, const char *autostartDir, bool liveStatus, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, virDomainLoadConfigNotify notify, void *opaque); diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index cdb1296aa3..568277c714 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -781,7 +781,6 @@ libxlStateInitialize(bool privileged, cfg->stateDir, cfg->autostartDir, true, - cfg->caps, libxl_driver->xmlopt, NULL, NULL) < 0) goto error; @@ -793,7 +792,6 @@ libxlStateInitialize(bool privileged, cfg->configDir, cfg->autostartDir, false, - cfg->caps, libxl_driver->xmlopt, NULL, NULL) < 0) goto error; @@ -833,7 +831,6 @@ libxlStateReload(void) cfg->configDir, cfg->autostartDir, true, - cfg->caps, libxl_driver->xmlopt, NULL, libxl_driver); diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 3467b07538..b40a96b4ce 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1529,7 +1529,6 @@ static int lxcStateInitialize(bool privileged, virStateInhibitCallback callback G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED) { - virCapsPtr caps = NULL; virLXCDriverConfigPtr cfg = NULL; bool autostart = true; @@ -1581,9 +1580,6 @@ static int lxcStateInitialize(bool privileged, if (!(lxc_driver->hostdevMgr = virHostdevManagerGetDefault())) goto cleanup; - if (!(caps = virLXCDriverGetCapabilities(lxc_driver, true))) - goto cleanup; - if (!(lxc_driver->xmlopt = lxcDomainXMLConfInit(lxc_driver))) goto cleanup; @@ -1605,7 +1601,6 @@ static int lxcStateInitialize(bool privileged, if (virDomainObjListLoadAllConfigs(lxc_driver->domains, cfg->stateDir, NULL, true, - caps, lxc_driver->xmlopt, NULL, NULL) < 0) goto cleanup; @@ -1616,7 +1611,6 @@ static int lxcStateInitialize(bool privileged, if (virDomainObjListLoadAllConfigs(lxc_driver->domains, cfg->configDir, cfg->autostartDir, false, - caps, lxc_driver->xmlopt, NULL, NULL) < 0) goto cleanup; @@ -1627,11 +1621,9 @@ static int lxcStateInitialize(bool privileged, if (autostart) virLXCProcessAutostartAll(lxc_driver); - virObjectUnref(caps); return VIR_DRV_STATE_INIT_COMPLETE; cleanup: - virObjectUnref(caps); lxcStateCleanup(); return VIR_DRV_STATE_INIT_ERROR; } @@ -1659,23 +1651,17 @@ static int lxcStateReload(void) { virLXCDriverConfigPtr cfg = NULL; - virCapsPtr caps = NULL; if (!lxc_driver) return 0; - if (!(caps = virLXCDriverGetCapabilities(lxc_driver, false))) - return -1; - cfg = virLXCDriverGetConfig(lxc_driver); virDomainObjListLoadAllConfigs(lxc_driver->domains, cfg->configDir, cfg->autostartDir, false, - caps, lxc_driver->xmlopt, lxcNotifyLoadDomain, lxc_driver); - virObjectUnref(caps); virObjectUnref(cfg); return 0; } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 91cf3fb21a..0aefe8cd2a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -972,7 +972,6 @@ qemuStateInitialize(bool privileged, if (virDomainObjListLoadAllConfigs(qemu_driver->domains, cfg->stateDir, NULL, true, - qemu_driver->caps, qemu_driver->xmlopt, NULL, NULL) < 0) goto error; @@ -994,7 +993,6 @@ qemuStateInitialize(bool privileged, if (virDomainObjListLoadAllConfigs(qemu_driver->domains, cfg->configDir, cfg->autostartDir, false, - qemu_driver->caps, qemu_driver->xmlopt, NULL, NULL) < 0) goto error; @@ -1059,19 +1057,15 @@ static int qemuStateReload(void) { g_autoptr(virQEMUDriverConfig) cfg = NULL; - g_autoptr(virCaps) caps = NULL; if (!qemu_driver) return 0; - if (!(caps = virQEMUDriverGetCapabilities(qemu_driver, false))) - return 0; - cfg = virQEMUDriverGetConfig(qemu_driver); virDomainObjListLoadAllConfigs(qemu_driver->domains, cfg->configDir, cfg->autostartDir, false, - caps, qemu_driver->xmlopt, + qemu_driver->xmlopt, qemuNotifyLoadDomain, qemu_driver); return 0; } -- 2.23.0

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/conf/checkpoint_conf.c | 15 ++++----------- src/conf/checkpoint_conf.h | 2 -- src/conf/snapshot_conf.c | 14 ++++---------- src/conf/snapshot_conf.h | 3 --- src/esx/esx_driver.c | 4 ++-- src/qemu/qemu_checkpoint.c | 8 ++++---- src/qemu/qemu_domain.c | 4 ++-- src/qemu/qemu_driver.c | 20 ++++---------------- src/test/test_driver.c | 8 +++----- src/vbox/vbox_common.c | 6 ++---- tests/qemudomaincheckpointxml2xmltest.c | 4 ++-- tests/qemudomainsnapshotxml2xmltest.c | 4 ++-- 12 files changed, 29 insertions(+), 63 deletions(-) diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c index 581e382b6d..26bcfc16b7 100644 --- a/src/conf/checkpoint_conf.c +++ b/src/conf/checkpoint_conf.c @@ -115,13 +115,10 @@ virDomainCheckpointDiskDefParseXML(xmlNodePtr node, return 0; } -/* flags is bitwise-or of virDomainCheckpointParseFlags. If flags - * does not include VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE, then caps - * is ignored. +/* flags is bitwise-or of virDomainCheckpointParseFlags. */ static virDomainCheckpointDefPtr virDomainCheckpointDefParse(xmlXPathContextPtr ctxt, - virCapsPtr caps G_GNUC_UNUSED, virDomainXMLOptionPtr xmlopt, void *parseOpaque, unsigned int flags) @@ -201,7 +198,6 @@ virDomainCheckpointDefParse(xmlXPathContextPtr ctxt, static virDomainCheckpointDefPtr virDomainCheckpointDefParseNode(xmlDocPtr xml, xmlNodePtr root, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, void *parseOpaque, unsigned int flags) @@ -227,12 +223,11 @@ virDomainCheckpointDefParseNode(xmlDocPtr xml, return NULL; ctxt->node = root; - return virDomainCheckpointDefParse(ctxt, caps, xmlopt, parseOpaque, flags); + return virDomainCheckpointDefParse(ctxt, xmlopt, parseOpaque, flags); } virDomainCheckpointDefPtr virDomainCheckpointDefParseString(const char *xmlStr, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, void *parseOpaque, unsigned int flags) @@ -244,7 +239,7 @@ virDomainCheckpointDefParseString(const char *xmlStr, if ((xml = virXMLParse(NULL, xmlStr, _("(domain_checkpoint)")))) { xmlKeepBlanksDefault(keepBlanksDefault); ret = virDomainCheckpointDefParseNode(xml, xmlDocGetRootElement(xml), - caps, xmlopt, parseOpaque, flags); + xmlopt, parseOpaque, flags); xmlFreeDoc(xml); } xmlKeepBlanksDefault(keepBlanksDefault); @@ -446,7 +441,6 @@ virDomainCheckpointDiskDefFormat(virBufferPtr buf, static int virDomainCheckpointDefFormatInternal(virBufferPtr buf, virDomainCheckpointDefPtr def, - virCapsPtr caps G_GNUC_UNUSED, virDomainXMLOptionPtr xmlopt, unsigned int flags) { @@ -505,7 +499,6 @@ virDomainCheckpointDefFormatInternal(virBufferPtr buf, char * virDomainCheckpointDefFormat(virDomainCheckpointDefPtr def, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, unsigned int flags) { @@ -514,7 +507,7 @@ virDomainCheckpointDefFormat(virDomainCheckpointDefPtr def, virCheckFlags(VIR_DOMAIN_CHECKPOINT_FORMAT_SECURE | VIR_DOMAIN_CHECKPOINT_FORMAT_NO_DOMAIN | VIR_DOMAIN_CHECKPOINT_FORMAT_SIZE, NULL); - if (virDomainCheckpointDefFormatInternal(&buf, def, caps, xmlopt, + if (virDomainCheckpointDefFormatInternal(&buf, def, xmlopt, flags) < 0) return NULL; diff --git a/src/conf/checkpoint_conf.h b/src/conf/checkpoint_conf.h index 982096abed..ee5d210593 100644 --- a/src/conf/checkpoint_conf.h +++ b/src/conf/checkpoint_conf.h @@ -74,7 +74,6 @@ virDomainCheckpointFormatConvertXMLFlags(unsigned int flags); virDomainCheckpointDefPtr virDomainCheckpointDefParseString(const char *xmlStr, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, void *parseOpaque, unsigned int flags); @@ -84,7 +83,6 @@ virDomainCheckpointDefNew(void); char * virDomainCheckpointDefFormat(virDomainCheckpointDefPtr def, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, unsigned int flags); diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index af882c6048..2bd4d6a276 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -216,13 +216,11 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node, } /* flags is bitwise-or of virDomainSnapshotParseFlags. - * If flags does not include VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE, then - * caps are ignored. If flags does not include + * If flags does not include * VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL, then current is ignored. */ static virDomainSnapshotDefPtr virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, - virCapsPtr caps G_GNUC_UNUSED, virDomainXMLOptionPtr xmlopt, void *parseOpaque, bool *current, @@ -420,7 +418,6 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, virDomainSnapshotDefPtr virDomainSnapshotDefParseNode(xmlDocPtr xml, xmlNodePtr root, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, void *parseOpaque, bool *current, @@ -449,12 +446,11 @@ virDomainSnapshotDefParseNode(xmlDocPtr xml, return NULL; ctxt->node = root; - return virDomainSnapshotDefParse(ctxt, caps, xmlopt, parseOpaque, current, flags); + return virDomainSnapshotDefParse(ctxt, xmlopt, parseOpaque, current, flags); } virDomainSnapshotDefPtr virDomainSnapshotDefParseString(const char *xmlStr, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, void *parseOpaque, bool *current, @@ -467,7 +463,7 @@ virDomainSnapshotDefParseString(const char *xmlStr, if ((xml = virXMLParse(NULL, xmlStr, _("(domain_snapshot)")))) { xmlKeepBlanksDefault(keepBlanksDefault); ret = virDomainSnapshotDefParseNode(xml, xmlDocGetRootElement(xml), - caps, xmlopt, parseOpaque, + xmlopt, parseOpaque, current, flags); xmlFreeDoc(xml); } @@ -838,7 +834,6 @@ static int virDomainSnapshotDefFormatInternal(virBufferPtr buf, const char *uuidstr, virDomainSnapshotDefPtr def, - virCapsPtr caps G_GNUC_UNUSED, virDomainXMLOptionPtr xmlopt, unsigned int flags) { @@ -931,7 +926,6 @@ virDomainSnapshotDefFormatInternal(virBufferPtr buf, char * virDomainSnapshotDefFormat(const char *uuidstr, virDomainSnapshotDefPtr def, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, unsigned int flags) { @@ -940,7 +934,7 @@ virDomainSnapshotDefFormat(const char *uuidstr, virCheckFlags(VIR_DOMAIN_SNAPSHOT_FORMAT_SECURE | VIR_DOMAIN_SNAPSHOT_FORMAT_INTERNAL | VIR_DOMAIN_SNAPSHOT_FORMAT_CURRENT, NULL); - if (virDomainSnapshotDefFormatInternal(&buf, uuidstr, def, caps, + if (virDomainSnapshotDefFormatInternal(&buf, uuidstr, def, xmlopt, flags) < 0) return NULL; diff --git a/src/conf/snapshot_conf.h b/src/conf/snapshot_conf.h index b0b52e6a34..c02d0fa263 100644 --- a/src/conf/snapshot_conf.h +++ b/src/conf/snapshot_conf.h @@ -107,14 +107,12 @@ typedef enum { unsigned int virDomainSnapshotFormatConvertXMLFlags(unsigned int flags); virDomainSnapshotDefPtr virDomainSnapshotDefParseString(const char *xmlStr, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, void *parseOpaque, bool *current, unsigned int flags); virDomainSnapshotDefPtr virDomainSnapshotDefParseNode(xmlDocPtr xml, xmlNodePtr root, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, void *parseOpaque, bool *current, @@ -122,7 +120,6 @@ virDomainSnapshotDefPtr virDomainSnapshotDefParseNode(xmlDocPtr xml, virDomainSnapshotDefPtr virDomainSnapshotDefNew(void); char *virDomainSnapshotDefFormat(const char *uuidstr, virDomainSnapshotDefPtr def, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, unsigned int flags); int virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr snapshot, diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 9cfdd3bf49..0ede65279a 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -4075,7 +4075,7 @@ esxDomainSnapshotCreateXML(virDomainPtr domain, const char *xmlDesc, if (esxVI_EnsureSession(priv->primary) < 0) return NULL; - def = virDomainSnapshotDefParseString(xmlDesc, priv->caps, + def = virDomainSnapshotDefParseString(xmlDesc, priv->xmlopt, NULL, NULL, parse_flags); if (!def) @@ -4176,7 +4176,7 @@ esxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot, virUUIDFormat(snapshot->domain->uuid, uuid_string); - xml = virDomainSnapshotDefFormat(uuid_string, &def, priv->caps, priv->xmlopt, + xml = virDomainSnapshotDefFormat(uuid_string, &def, priv->xmlopt, 0); cleanup: diff --git a/src/qemu/qemu_checkpoint.c b/src/qemu/qemu_checkpoint.c index a601030637..2101932a28 100644 --- a/src/qemu/qemu_checkpoint.c +++ b/src/qemu/qemu_checkpoint.c @@ -78,7 +78,7 @@ qemuCheckpointObjFromCheckpoint(virDomainObjPtr vm, static int qemuCheckpointWriteMetadata(virDomainObjPtr vm, virDomainMomentObjPtr checkpoint, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, virDomainXMLOptionPtr xmlopt, const char *checkpointDir) { @@ -88,7 +88,7 @@ qemuCheckpointWriteMetadata(virDomainObjPtr vm, g_autofree char *chkDir = NULL; g_autofree char *chkFile = NULL; - newxml = virDomainCheckpointDefFormat(def, caps, xmlopt, flags); + newxml = virDomainCheckpointDefFormat(def, xmlopt, flags); if (newxml == NULL) return -1; @@ -494,7 +494,7 @@ qemuCheckpointCreateXML(virDomainPtr domain, return NULL; } - if (!(def = virDomainCheckpointDefParseString(xmlDesc, caps, driver->xmlopt, + if (!(def = virDomainCheckpointDefParseString(xmlDesc, driver->xmlopt, priv->qemuCaps, parse_flags))) return NULL; /* Unlike snapshots, the RNG schema already ensured a sane filename. */ @@ -548,7 +548,7 @@ qemuCheckpointGetXMLDesc(virDomainObjPtr vm, chkdef = virDomainCheckpointObjGetDef(chk); format_flags = virDomainCheckpointFormatConvertXMLFlags(flags); - return virDomainCheckpointDefFormat(chkdef, driver->caps, driver->xmlopt, + return virDomainCheckpointDefFormat(chkdef, driver->xmlopt, format_flags); } diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index ee99759ded..594c4d5400 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -9714,7 +9714,7 @@ qemuFindQemuImgBinary(virQEMUDriverPtr driver) int qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm, virDomainMomentObjPtr snapshot, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, virDomainXMLOptionPtr xmlopt, const char *snapshotDir) { @@ -9730,7 +9730,7 @@ qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm, if (virDomainSnapshotGetCurrent(vm->snapshots) == snapshot) flags |= VIR_DOMAIN_SNAPSHOT_FORMAT_CURRENT; virUUIDFormat(vm->def->uuid, uuidstr); - newxml = virDomainSnapshotDefFormat(uuidstr, def, caps, xmlopt, flags); + newxml = virDomainSnapshotDefFormat(uuidstr, def, xmlopt, flags); if (newxml == NULL) return -1; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 0aefe8cd2a..b544bed7c1 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -393,7 +393,6 @@ qemuDomainSnapshotLoad(virDomainObjPtr vm, VIR_DOMAIN_SNAPSHOT_PARSE_DISKS | VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL); int ret = -1; - g_autoptr(virCaps) caps = NULL; int direrr; qemuDomainObjPrivatePtr priv; @@ -409,9 +408,6 @@ qemuDomainSnapshotLoad(virDomainObjPtr vm, goto cleanup; } - if (!(caps = virQEMUDriverGetCapabilities(qemu_driver, false))) - goto cleanup; - VIR_INFO("Scanning for snapshots for domain %s in %s", vm->def->name, snapDir); @@ -440,7 +436,7 @@ qemuDomainSnapshotLoad(virDomainObjPtr vm, continue; } - def = virDomainSnapshotDefParseString(xmlStr, caps, + def = virDomainSnapshotDefParseString(xmlStr, qemu_driver->xmlopt, priv->qemuCaps, &cur, flags); @@ -506,7 +502,6 @@ qemuDomainCheckpointLoad(virDomainObjPtr vm, virDomainMomentObjPtr current = NULL; unsigned int flags = VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE; int ret = -1; - g_autoptr(virCaps) caps = NULL; int direrr; qemuDomainObjPrivatePtr priv; @@ -521,9 +516,6 @@ qemuDomainCheckpointLoad(virDomainObjPtr vm, goto cleanup; } - if (!(caps = virQEMUDriverGetCapabilities(qemu_driver, false))) - goto cleanup; - VIR_INFO("Scanning for checkpoints for domain %s in %s", vm->def->name, chkDir); @@ -552,7 +544,7 @@ qemuDomainCheckpointLoad(virDomainObjPtr vm, continue; } - def = virDomainCheckpointDefParseString(xmlStr, caps, + def = virDomainCheckpointDefParseString(xmlStr, qemu_driver->xmlopt, priv->qemuCaps, flags); @@ -15751,7 +15743,6 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain, int align_location = VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL; bool align_match = true; g_autoptr(virQEMUDriverConfig) cfg = NULL; - g_autoptr(virCaps) caps = NULL; qemuDomainObjPrivatePtr priv; virDomainSnapshotState state; g_autoptr(virDomainSnapshotDef) def = NULL; @@ -15792,9 +15783,6 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain, if (qemuDomainSupportsCheckpointsBlockjobs(vm) < 0) goto cleanup; - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; - if (!vm->persistent && (flags & VIR_DOMAIN_SNAPSHOT_CREATE_HALT)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("cannot halt after transient domain snapshot")); @@ -15807,7 +15795,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain, if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_VALIDATE) parse_flags |= VIR_DOMAIN_SNAPSHOT_PARSE_VALIDATE; - if (!(def = virDomainSnapshotDefParseString(xmlDesc, caps, driver->xmlopt, + if (!(def = virDomainSnapshotDefParseString(xmlDesc, driver->xmlopt, priv->qemuCaps, NULL, parse_flags))) goto cleanup; @@ -16336,7 +16324,7 @@ qemuDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot, virUUIDFormat(snapshot->domain->uuid, uuidstr); xml = virDomainSnapshotDefFormat(uuidstr, virDomainSnapshotObjGetDef(snap), - driver->caps, driver->xmlopt, + driver->xmlopt, virDomainSnapshotFormatConvertXMLFlags(flags)); cleanup: diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 788d5d3676..f3d6061625 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -884,7 +884,6 @@ testParseDomainSnapshots(testDriverPtr privconn, goto error; def = virDomainSnapshotDefParseNode(ctxt->doc, node, - privconn->caps, privconn->xmlopt, NULL, &cur, @@ -8413,7 +8412,7 @@ testDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot, virUUIDFormat(snapshot->domain->uuid, uuidstr); xml = virDomainSnapshotDefFormat(uuidstr, virDomainSnapshotObjGetDef(snap), - privconn->caps, privconn->xmlopt, + privconn->xmlopt, virDomainSnapshotFormatConvertXMLFlags(flags)); cleanup: @@ -8557,7 +8556,6 @@ testDomainSnapshotCreateXML(virDomainPtr domain, parse_flags |= VIR_DOMAIN_SNAPSHOT_PARSE_VALIDATE; if (!(def = virDomainSnapshotDefParseString(xmlDesc, - privconn->caps, privconn->xmlopt, NULL, NULL, parse_flags))) @@ -9013,7 +9011,7 @@ testDomainCheckpointCreateXML(virDomainPtr domain, goto cleanup; } - if (!(def = virDomainCheckpointDefParseString(xmlDesc, privconn->caps, + if (!(def = virDomainCheckpointDefParseString(xmlDesc, privconn->xmlopt, NULL, parse_flags))) goto cleanup; @@ -9216,7 +9214,7 @@ testDomainCheckpointGetXMLDesc(virDomainCheckpointPtr checkpoint, } format_flags = virDomainCheckpointFormatConvertXMLFlags(flags); - xml = virDomainCheckpointDefFormat(chkdef, privconn->caps, + xml = virDomainCheckpointDefFormat(chkdef, privconn->xmlopt, format_flags); cleanup: diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 1703120928..2930a2f0e1 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -5301,7 +5301,6 @@ vboxSnapshotRedefine(virDomainPtr dom, currentSnapshotXmlFilePath = g_strdup_printf("%s%s.xml", machineLocationPath, snapshotMachineDesc->currentSnapshot); char *snapshotContent = virDomainSnapshotDefFormat(NULL, def, - data->caps, data->xmlopt, VIR_DOMAIN_SNAPSHOT_FORMAT_SECURE); if (snapshotContent == NULL) { @@ -5431,7 +5430,7 @@ vboxDomainSnapshotCreateXML(virDomainPtr dom, if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_VALIDATE) parse_flags |= VIR_DOMAIN_SNAPSHOT_PARSE_VALIDATE; - if (!(def = virDomainSnapshotDefParseString(xmlDesc, data->caps, + if (!(def = virDomainSnapshotDefParseString(xmlDesc, data->xmlopt, NULL, NULL, parse_flags))) goto cleanup; @@ -6244,7 +6243,7 @@ static char *vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot, virUUIDFormat(dom->uuid, uuidstr); memcpy(defdom->uuid, dom->uuid, VIR_UUID_BUFLEN); - ret = virDomainSnapshotDefFormat(uuidstr, def, data->caps, data->xmlopt, 0); + ret = virDomainSnapshotDefFormat(uuidstr, def, data->xmlopt, 0); cleanup: VBOX_RELEASE(parent); @@ -6858,7 +6857,6 @@ vboxDomainSnapshotDeleteMetadataOnly(virDomainSnapshotPtr snapshot) goto cleanup; } def = virDomainSnapshotDefParseString(defXml, - data->caps, data->xmlopt, NULL, NULL, VIR_DOMAIN_SNAPSHOT_PARSE_DISKS | VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE); diff --git a/tests/qemudomaincheckpointxml2xmltest.c b/tests/qemudomaincheckpointxml2xmltest.c index 49e8cddeb3..4d6904a592 100644 --- a/tests/qemudomaincheckpointxml2xmltest.c +++ b/tests/qemudomaincheckpointxml2xmltest.c @@ -53,7 +53,7 @@ testCompareXMLToXMLFiles(const char *inxml, virTestLoadFile(outxml, &outXmlData) < 0) return -1; - if (!(def = virDomainCheckpointDefParseString(inXmlData, driver.caps, + if (!(def = virDomainCheckpointDefParseString(inXmlData, driver.xmlopt, NULL, parseflags))) { if (flags & TEST_INVALID) @@ -91,7 +91,7 @@ testCompareXMLToXMLFiles(const char *inxml, if (!def->parent.dom) formatflags |= VIR_DOMAIN_CHECKPOINT_FORMAT_NO_DOMAIN; - if (!(actual = virDomainCheckpointDefFormat(def, driver.caps, + if (!(actual = virDomainCheckpointDefFormat(def, driver.xmlopt, formatflags))) return -1; diff --git a/tests/qemudomainsnapshotxml2xmltest.c b/tests/qemudomainsnapshotxml2xmltest.c index fd3bb04e26..6bff5d14f5 100644 --- a/tests/qemudomainsnapshotxml2xmltest.c +++ b/tests/qemudomainsnapshotxml2xmltest.c @@ -54,7 +54,7 @@ testCompareXMLToXMLFiles(const char *inxml, if (virTestLoadFile(outxml, &outXmlData) < 0) goto cleanup; - if (!(def = virDomainSnapshotDefParseString(inXmlData, driver.caps, + if (!(def = virDomainSnapshotDefParseString(inXmlData, driver.xmlopt, NULL, &cur, parseflags))) goto cleanup; @@ -69,7 +69,7 @@ testCompareXMLToXMLFiles(const char *inxml, def->state = VIR_DOMAIN_RUNNING; } - if (!(actual = virDomainSnapshotDefFormat(uuid, def, driver.caps, + if (!(actual = virDomainSnapshotDefFormat(uuid, def, driver.xmlopt, formatflags))) goto cleanup; -- 2.23.0

Now that the domain XML APIs don't use virCapsPtr we can stop passing it around many QEMU driver methods. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/qemu/qemu_checkpoint.c | 24 +++++++---------------- src/qemu/qemu_checkpoint.h | 1 - src/qemu/qemu_domain.c | 3 +-- src/qemu/qemu_domain.h | 1 - src/qemu/qemu_driver.c | 39 +++++++++----------------------------- src/qemu/qemu_process.c | 10 ---------- 6 files changed, 17 insertions(+), 61 deletions(-) diff --git a/src/qemu/qemu_checkpoint.c b/src/qemu/qemu_checkpoint.c index 2101932a28..30f65630ca 100644 --- a/src/qemu/qemu_checkpoint.c +++ b/src/qemu/qemu_checkpoint.c @@ -78,7 +78,6 @@ qemuCheckpointObjFromCheckpoint(virDomainObjPtr vm, static int qemuCheckpointWriteMetadata(virDomainObjPtr vm, virDomainMomentObjPtr checkpoint, - virCapsPtr caps G_GNUC_UNUSED, virDomainXMLOptionPtr xmlopt, const char *checkpointDir) { @@ -197,7 +196,7 @@ qemuCheckpointDiscard(virQEMUDriverPtr driver, virDomainCheckpointSetCurrent(vm->checkpoints, NULL); if (update_parent && parent) { virDomainCheckpointSetCurrent(vm->checkpoints, parent); - if (qemuCheckpointWriteMetadata(vm, parent, driver->caps, + if (qemuCheckpointWriteMetadata(vm, parent, driver->xmlopt, cfg->checkpointDir) < 0) { VIR_WARN("failed to set parent checkpoint '%s' as current", @@ -239,7 +238,6 @@ qemuCheckpointDiscardAllMetadata(virQEMUDriverPtr driver, /* Called inside job lock */ static int qemuCheckpointPrepare(virQEMUDriverPtr driver, - virCapsPtr caps G_GNUC_UNUSED, virDomainObjPtr vm, virDomainCheckpointDefPtr def) { @@ -373,7 +371,6 @@ qemuCheckpointRedefine(virQEMUDriverPtr driver, int qemuCheckpointCreateCommon(virQEMUDriverPtr driver, virDomainObjPtr vm, - virCapsPtr caps, virDomainCheckpointDefPtr *def, virJSONValuePtr *actions, virDomainMomentObjPtr *chk) @@ -381,7 +378,7 @@ qemuCheckpointCreateCommon(virQEMUDriverPtr driver, g_autoptr(virJSONValue) tmpactions = NULL; virDomainMomentObjPtr parent; - if (qemuCheckpointPrepare(driver, caps, vm, *def) < 0) + if (qemuCheckpointPrepare(driver, vm, *def) < 0) return -1; if ((parent = virDomainCheckpointGetCurrent(vm->checkpoints))) @@ -406,14 +403,13 @@ qemuCheckpointCreateCommon(virQEMUDriverPtr driver, static virDomainMomentObjPtr qemuCheckpointCreate(virQEMUDriverPtr driver, virDomainObjPtr vm, - virCapsPtr caps, virDomainCheckpointDefPtr *def) { g_autoptr(virJSONValue) actions = NULL; virDomainMomentObjPtr chk = NULL; int rc; - if (qemuCheckpointCreateCommon(driver, vm, caps, def, &actions, &chk) < 0) + if (qemuCheckpointCreateCommon(driver, vm, def, &actions, &chk) < 0) return NULL; qemuDomainObjEnterMonitor(driver, vm); @@ -437,7 +433,7 @@ qemuCheckpointCreateFinalize(virQEMUDriverPtr driver, if (update_current) virDomainCheckpointSetCurrent(vm->checkpoints, chk); - if (qemuCheckpointWriteMetadata(vm, chk, driver->caps, + if (qemuCheckpointWriteMetadata(vm, chk, driver->xmlopt, cfg->checkpointDir) < 0) { /* if writing of metadata fails, error out rather than trying @@ -469,7 +465,6 @@ qemuCheckpointCreateXML(virDomainPtr domain, bool redefine = flags & VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE; unsigned int parse_flags = 0; g_autoptr(virQEMUDriverConfig) cfg = NULL; - g_autoptr(virCaps) caps = NULL; g_autoptr(virDomainCheckpointDef) def = NULL; virCheckFlags(VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE, NULL); @@ -485,9 +480,6 @@ qemuCheckpointCreateXML(virDomainPtr domain, return NULL; } - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - return NULL; - if (!virDomainObjIsActive(vm)) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("cannot create checkpoint for inactive domain")); @@ -506,7 +498,7 @@ qemuCheckpointCreateXML(virDomainPtr domain, if (redefine) { chk = qemuCheckpointRedefine(driver, vm, &def, &update_current); } else { - chk = qemuCheckpointCreate(driver, vm, caps, &def); + chk = qemuCheckpointCreate(driver, vm, &def); } if (!chk) @@ -557,7 +549,6 @@ struct virQEMUCheckpointReparent { const char *dir; virDomainMomentObjPtr parent; virDomainObjPtr vm; - virCapsPtr caps; virDomainXMLOptionPtr xmlopt; int err; }; @@ -579,7 +570,7 @@ qemuCheckpointReparentChildren(void *payload, if (rep->parent->def) moment->def->parent_name = g_strdup(rep->parent->def->name); - rep->err = qemuCheckpointWriteMetadata(rep->vm, moment, rep->caps, + rep->err = qemuCheckpointWriteMetadata(rep->vm, moment, rep->xmlopt, rep->dir); return 0; } @@ -639,7 +630,7 @@ qemuCheckpointDelete(virDomainObjPtr vm, if (rem.found) { virDomainCheckpointSetCurrent(vm->checkpoints, chk); if (flags & VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN_ONLY) { - if (qemuCheckpointWriteMetadata(vm, chk, driver->caps, + if (qemuCheckpointWriteMetadata(vm, chk, driver->xmlopt, cfg->checkpointDir) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -655,7 +646,6 @@ qemuCheckpointDelete(virDomainObjPtr vm, rep.parent = chk->parent; rep.vm = vm; rep.err = 0; - rep.caps = driver->caps; rep.xmlopt = driver->xmlopt; virDomainMomentForEachChild(chk, qemuCheckpointReparentChildren, &rep); diff --git a/src/qemu/qemu_checkpoint.h b/src/qemu/qemu_checkpoint.h index d0ea8f000f..00548beec9 100644 --- a/src/qemu/qemu_checkpoint.h +++ b/src/qemu/qemu_checkpoint.h @@ -57,7 +57,6 @@ qemuCheckpointDelete(virDomainObjPtr vm, int qemuCheckpointCreateCommon(virQEMUDriverPtr driver, virDomainObjPtr vm, - virCapsPtr caps, virDomainCheckpointDefPtr *def, virJSONValuePtr *actions, virDomainMomentObjPtr *chk); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 594c4d5400..84813ded40 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -9714,7 +9714,6 @@ qemuFindQemuImgBinary(virQEMUDriverPtr driver) int qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm, virDomainMomentObjPtr snapshot, - virCapsPtr caps G_GNUC_UNUSED, virDomainXMLOptionPtr xmlopt, const char *snapshotDir) { @@ -9887,7 +9886,7 @@ qemuDomainSnapshotDiscard(virQEMUDriverPtr driver, snap->def->parent_name); } else { virDomainSnapshotSetCurrent(vm->snapshots, parentsnap); - if (qemuDomainSnapshotWriteMetadata(vm, parentsnap, driver->caps, + if (qemuDomainSnapshotWriteMetadata(vm, parentsnap, driver->xmlopt, cfg->snapshotDir) < 0) { VIR_WARN("failed to set parent snapshot '%s' as current", diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index f626d3a54c..3bbb0b2e44 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -763,7 +763,6 @@ const char *qemuFindQemuImgBinary(virQEMUDriverPtr driver); int qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm, virDomainMomentObjPtr snapshot, - virCapsPtr caps, virDomainXMLOptionPtr xmlopt, const char *snapshotDir); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index b544bed7c1..ae6facc829 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -8063,7 +8063,6 @@ qemuCheckDiskConfigAgainstDomain(const virDomainDef *def, static int qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef, virDomainDeviceDefPtr dev, - virCapsPtr caps G_GNUC_UNUSED, virQEMUCapsPtr qemuCaps, unsigned int parse_flags, virDomainXMLOptionPtr xmlopt) @@ -8273,7 +8272,6 @@ qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef, static int qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef, virDomainDeviceDefPtr dev, - virCapsPtr caps G_GNUC_UNUSED, virQEMUCapsPtr qemuCaps, unsigned int parse_flags, virDomainXMLOptionPtr xmlopt) @@ -8465,7 +8463,6 @@ qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef, static int qemuDomainUpdateDeviceConfig(virDomainDefPtr vmdef, virDomainDeviceDefPtr dev, - virCapsPtr caps G_GNUC_UNUSED, virQEMUCapsPtr qemuCaps, unsigned int parse_flags, virDomainXMLOptionPtr xmlopt) @@ -8582,7 +8579,6 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObjPtr vm, virDomainDeviceDefPtr devConf = NULL; virDomainDeviceDefPtr devLive = NULL; int ret = -1; - g_autoptr(virCaps) caps = NULL; unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE | VIR_DOMAIN_DEF_PARSE_ABI_UPDATE; @@ -8591,9 +8587,6 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObjPtr vm, cfg = virQEMUDriverGetConfig(driver); - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; - /* The config and live post processing address auto-generation algorithms * rely on the correct vm->def or vm->newDef being passed, so call the * device parse based on which definition is in use */ @@ -8617,7 +8610,7 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObjPtr vm, false) < 0) goto cleanup; - if (qemuDomainAttachDeviceConfig(vmdef, devConf, caps, priv->qemuCaps, + if (qemuDomainAttachDeviceConfig(vmdef, devConf, priv->qemuCaps, parse_flags, driver->xmlopt) < 0) goto cleanup; @@ -8723,7 +8716,6 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom, bool force = (flags & VIR_DOMAIN_DEVICE_MODIFY_FORCE) != 0; int ret = -1; g_autoptr(virQEMUDriverConfig) cfg = NULL; - g_autoptr(virCaps) caps = NULL; unsigned int parse_flags = 0; virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | @@ -8734,9 +8726,6 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom, cfg = virQEMUDriverGetConfig(driver); - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; - if (!(vm = qemuDomainObjFromDomain(dom))) goto cleanup; @@ -8782,7 +8771,7 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom, /* virDomainDefCompatibleDevice call is delayed until we know the * device we're going to update. */ - if ((ret = qemuDomainUpdateDeviceConfig(vmdef, dev, caps, priv->qemuCaps, + if ((ret = qemuDomainUpdateDeviceConfig(vmdef, dev, priv->qemuCaps, parse_flags, driver->xmlopt)) < 0) goto endjob; @@ -8833,7 +8822,6 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriverPtr driver, unsigned int flags) { qemuDomainObjPrivatePtr priv = vm->privateData; - g_autoptr(virCaps) caps = NULL; g_autoptr(virQEMUDriverConfig) cfg = NULL; virDomainDeviceDefPtr dev = NULL, dev_copy = NULL; unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE; @@ -8843,9 +8831,6 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriverPtr driver, virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1); - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; - cfg = virQEMUDriverGetConfig(driver); if ((flags & VIR_DOMAIN_AFFECT_CONFIG) && @@ -8876,7 +8861,7 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriverPtr driver, if (!vmdef) goto cleanup; - if (qemuDomainDetachDeviceConfig(vmdef, dev, caps, priv->qemuCaps, + if (qemuDomainDetachDeviceConfig(vmdef, dev, priv->qemuCaps, parse_flags, driver->xmlopt) < 0) goto cleanup; @@ -8927,7 +8912,6 @@ qemuDomainDetachDeviceAliasLiveAndConfig(virQEMUDriverPtr driver, unsigned int flags) { qemuDomainObjPrivatePtr priv = vm->privateData; - g_autoptr(virCaps) caps = NULL; g_autoptr(virQEMUDriverConfig) cfg = NULL; virDomainDefPtr def = NULL; virDomainDefPtr persistentDef = NULL; @@ -8938,9 +8922,6 @@ qemuDomainDetachDeviceAliasLiveAndConfig(virQEMUDriverPtr driver, virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1); - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; - cfg = virQEMUDriverGetConfig(driver); if ((flags & VIR_DOMAIN_AFFECT_CONFIG) && @@ -8960,7 +8941,7 @@ qemuDomainDetachDeviceAliasLiveAndConfig(virQEMUDriverPtr driver, if (virDomainDefFindDevice(vmdef, alias, &dev, true) < 0) goto cleanup; - if (qemuDomainDetachDeviceConfig(vmdef, &dev, caps, priv->qemuCaps, + if (qemuDomainDetachDeviceConfig(vmdef, &dev, priv->qemuCaps, parse_flags, driver->xmlopt) < 0) goto cleanup; } @@ -15987,7 +15968,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain, if (snapshot && !(flags & VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA)) { if (update_current) virDomainSnapshotSetCurrent(vm->snapshots, snap); - if (qemuDomainSnapshotWriteMetadata(vm, snap, driver->caps, + if (qemuDomainSnapshotWriteMetadata(vm, snap, driver->xmlopt, cfg->snapshotDir) < 0) { /* if writing of metadata fails, error out rather than trying @@ -16813,7 +16794,7 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, cleanup: if (ret == 0) { virDomainSnapshotSetCurrent(vm->snapshots, snap); - if (qemuDomainSnapshotWriteMetadata(vm, snap, driver->caps, + if (qemuDomainSnapshotWriteMetadata(vm, snap, driver->xmlopt, cfg->snapshotDir) < 0) { virDomainSnapshotSetCurrent(vm->snapshots, NULL); @@ -16847,11 +16828,10 @@ struct _virQEMUMomentReparent { const char *dir; virDomainMomentObjPtr parent; virDomainObjPtr vm; - virCapsPtr caps; virDomainXMLOptionPtr xmlopt; int err; int (*writeMetadata)(virDomainObjPtr, virDomainMomentObjPtr, - virCapsPtr, virDomainXMLOptionPtr, const char *); + virDomainXMLOptionPtr, const char *); }; @@ -16871,7 +16851,7 @@ qemuDomainMomentReparentChildren(void *payload, if (rep->parent->def) moment->def->parent_name = g_strdup(rep->parent->def->name); - rep->err = rep->writeMetadata(rep->vm, moment, rep->caps, rep->xmlopt, + rep->err = rep->writeMetadata(rep->vm, moment, rep->xmlopt, rep->dir); return 0; } @@ -16942,7 +16922,7 @@ qemuDomainSnapshotDelete(virDomainSnapshotPtr snapshot, if (rem.found) { virDomainSnapshotSetCurrent(vm->snapshots, snap); if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) { - if (qemuDomainSnapshotWriteMetadata(vm, snap, driver->caps, + if (qemuDomainSnapshotWriteMetadata(vm, snap, driver->xmlopt, cfg->snapshotDir) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -16958,7 +16938,6 @@ qemuDomainSnapshotDelete(virDomainSnapshotPtr snapshot, rep.parent = snap->parent; rep.vm = vm; rep.err = 0; - rep.caps = driver->caps; rep.xmlopt = driver->xmlopt; rep.writeMetadata = qemuDomainSnapshotWriteMetadata; virDomainMomentForEachChild(snap, diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 7a0cbc109f..4287ed0830 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6725,7 +6725,6 @@ qemuProcessLaunch(virConnectPtr conn, virCommandPtr cmd = NULL; struct qemuProcessHookData hookData; virQEMUDriverConfigPtr cfg; - virCapsPtr caps = NULL; size_t nnicindexes = 0; int *nicindexes = NULL; size_t i; @@ -6762,9 +6761,6 @@ qemuProcessLaunch(virConnectPtr conn, /* We don't increase cfg's reference counter here. */ hookData.cfg = cfg; - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; - VIR_DEBUG("Creating domain log file"); if (!(logCtxt = qemuDomainLogContextNew(driver, vm, QEMU_DOMAIN_LOG_CONTEXT_MODE_START))) { @@ -7042,7 +7038,6 @@ qemuProcessLaunch(virConnectPtr conn, virCommandFree(cmd); virObjectUnref(logCtxt); virObjectUnref(cfg); - virObjectUnref(caps); VIR_FREE(nicindexes); return ret; } @@ -8007,7 +8002,6 @@ qemuProcessReconnect(void *opaque) size_t i; unsigned int stopFlags = 0; bool jobStarted = false; - virCapsPtr caps = NULL; bool retry = true; bool tryMonReconn = false; @@ -8022,9 +8016,6 @@ qemuProcessReconnect(void *opaque) cfg = virQEMUDriverGetConfig(driver); priv = obj->privateData; - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto error; - if (qemuDomainObjBeginJob(driver, obj, QEMU_JOB_MODIFY) < 0) goto error; jobStarted = true; @@ -8255,7 +8246,6 @@ qemuProcessReconnect(void *opaque) } virDomainObjEndAPI(&obj); virObjectUnref(cfg); - virObjectUnref(caps); virNWFilterUnlockFilterUpdates(); virIdentitySetCurrent(NULL); return; -- 2.23.0

The NUMA cells are stored directly in the virCapsHostPtr struct. This moves them into their own struct allowing them to be stored independantly of the rest of the host capabilities. The change is used as an excuse to switch the representation to use a GPtrArray too. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/conf/capabilities.c | 200 +++++++++++++++++++-------------- src/conf/capabilities.h | 27 +++-- src/conf/virconftypes.h | 3 + src/libvirt_private.syms | 10 +- src/libxl/libxl_capabilities.c | 20 ++-- src/lxc/lxc_conf.c | 6 +- src/openvz/openvz_conf.c | 2 +- src/phyp/phyp_driver.c | 7 +- src/qemu/qemu_capabilities.c | 6 +- src/qemu/qemu_domain.c | 11 +- src/qemu/qemu_migration.c | 5 - src/qemu/qemu_process.c | 2 +- src/test/test_driver.c | 9 +- src/vbox/vbox_common.c | 2 +- src/vmware/vmware_conf.c | 2 +- src/vz/vz_driver.c | 2 +- tests/testutils.c | 23 ++-- tests/testutils.h | 3 +- tests/testutilsqemu.c | 2 +- tests/vircaps2xmltest.c | 6 +- tests/vircapstest.c | 11 +- 21 files changed, 194 insertions(+), 165 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 748dd64273..7021283310 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -182,14 +182,19 @@ virCapabilitiesFreeStoragePool(virCapsStoragePoolPtr pool) void -virCapabilitiesFreeNUMAInfo(virCapsPtr caps) +virCapabilitiesHostNUMAUnref(virCapsHostNUMAPtr caps) { - size_t i; + if (g_atomic_int_dec_and_test(&caps->refs)) { + g_ptr_array_unref(caps->cells); + + VIR_FREE(caps); + } +} - for (i = 0; i < caps->host.nnumaCell; i++) - virCapabilitiesFreeHostNUMACell(caps->host.numaCell[i]); - VIR_FREE(caps->host.numaCell); - caps->host.nnumaCell = 0; +void +virCapabilitiesHostNUMARef(virCapsHostNUMAPtr caps) +{ + g_atomic_int_inc(&caps->refs); } static void @@ -234,7 +239,8 @@ virCapsDispose(void *object) VIR_FREE(caps->host.features[i]); VIR_FREE(caps->host.features); - virCapabilitiesFreeNUMAInfo(caps); + if (caps->host.numa) + virCapabilitiesHostNUMAUnref(caps->host.numa); for (i = 0; i < caps->host.nmigrateTrans; i++) VIR_FREE(caps->host.migrateTrans[i]); @@ -320,7 +326,7 @@ virCapabilitiesSetNetPrefix(virCapsPtr caps, /** - * virCapabilitiesAddHostNUMACell: + * virCapabilitiesHostNUMAAddCell: * @caps: capabilities to extend * @num: ID number of NUMA cell * @mem: Total size of memory in the NUMA node (in KiB) @@ -334,8 +340,8 @@ virCapabilitiesSetNetPrefix(virCapsPtr caps, * Registers a new NUMA cell for a host, passing in a * array of CPU IDs belonging to the cell */ -int -virCapabilitiesAddHostNUMACell(virCapsPtr caps, +void +virCapabilitiesHostNUMAAddCell(virCapsHostNUMAPtr caps, int num, unsigned long long mem, int ncpus, @@ -345,14 +351,7 @@ virCapabilitiesAddHostNUMACell(virCapsPtr caps, int npageinfo, virCapsHostNUMACellPageInfoPtr pageinfo) { - virCapsHostNUMACellPtr cell; - - if (VIR_RESIZE_N(caps->host.numaCell, caps->host.nnumaCell_max, - caps->host.nnumaCell, 1) < 0) - return -1; - - if (VIR_ALLOC(cell) < 0) - return -1; + virCapsHostNUMACellPtr cell = g_new0(virCapsHostNUMACell, 1); cell->num = num; cell->mem = mem; @@ -363,9 +362,7 @@ virCapabilitiesAddHostNUMACell(virCapsPtr caps, cell->npageinfo = npageinfo; cell->pageinfo = pageinfo; - caps->host.numaCell[caps->host.nnumaCell++] = cell; - - return 0; + g_ptr_array_add(caps->cells, cell); } @@ -857,9 +854,8 @@ virCapabilitiesAddStoragePool(virCapsPtr caps, static int -virCapabilitiesFormatNUMATopology(virBufferPtr buf, - size_t ncells, - virCapsHostNUMACellPtr *cells) +virCapabilitiesHostNUMAFormat(virCapsHostNUMAPtr caps, + virBufferPtr buf) { size_t i; size_t j; @@ -867,48 +863,49 @@ virCapabilitiesFormatNUMATopology(virBufferPtr buf, virBufferAddLit(buf, "<topology>\n"); virBufferAdjustIndent(buf, 2); - virBufferAsprintf(buf, "<cells num='%zu'>\n", ncells); + virBufferAsprintf(buf, "<cells num='%d'>\n", caps->cells->len); virBufferAdjustIndent(buf, 2); - for (i = 0; i < ncells; i++) { - virBufferAsprintf(buf, "<cell id='%d'>\n", cells[i]->num); + for (i = 0; i < caps->cells->len; i++) { + virCapsHostNUMACellPtr cell = g_ptr_array_index(caps->cells, i); + virBufferAsprintf(buf, "<cell id='%d'>\n", cell->num); virBufferAdjustIndent(buf, 2); /* Print out the numacell memory total if it is available */ - if (cells[i]->mem) + if (cell->mem) virBufferAsprintf(buf, "<memory unit='KiB'>%llu</memory>\n", - cells[i]->mem); + cell->mem); - for (j = 0; j < cells[i]->npageinfo; j++) { + for (j = 0; j < cell->npageinfo; j++) { virBufferAsprintf(buf, "<pages unit='KiB' size='%u'>%llu</pages>\n", - cells[i]->pageinfo[j].size, - cells[i]->pageinfo[j].avail); + cell->pageinfo[j].size, + cell->pageinfo[j].avail); } - if (cells[i]->nsiblings) { + if (cell->nsiblings) { virBufferAddLit(buf, "<distances>\n"); virBufferAdjustIndent(buf, 2); - for (j = 0; j < cells[i]->nsiblings; j++) { + for (j = 0; j < cell->nsiblings; j++) { virBufferAsprintf(buf, "<sibling id='%d' value='%d'/>\n", - cells[i]->siblings[j].node, - cells[i]->siblings[j].distance); + cell->siblings[j].node, + cell->siblings[j].distance); } virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "</distances>\n"); } - virBufferAsprintf(buf, "<cpus num='%d'>\n", cells[i]->ncpus); + virBufferAsprintf(buf, "<cpus num='%d'>\n", cell->ncpus); virBufferAdjustIndent(buf, 2); - for (j = 0; j < cells[i]->ncpus; j++) { - virBufferAsprintf(buf, "<cpu id='%d'", cells[i]->cpus[j].id); + for (j = 0; j < cell->ncpus; j++) { + virBufferAsprintf(buf, "<cpu id='%d'", cell->cpus[j].id); - if (cells[i]->cpus[j].siblings) { - if (!(siblings = virBitmapFormat(cells[i]->cpus[j].siblings))) + if (cell->cpus[j].siblings) { + if (!(siblings = virBitmapFormat(cell->cpus[j].siblings))) return -1; virBufferAsprintf(buf, " socket_id='%d' core_id='%d' siblings='%s'", - cells[i]->cpus[j].socket_id, - cells[i]->cpus[j].core_id, + cell->cpus[j].socket_id, + cell->cpus[j].core_id, siblings); VIR_FREE(siblings); } @@ -1187,9 +1184,8 @@ virCapabilitiesFormatHostXML(virCapsHostPtr host, virBufferAsprintf(buf, "<netprefix>%s</netprefix>\n", host->netprefix); - if (host->nnumaCell && - virCapabilitiesFormatNUMATopology(buf, host->nnumaCell, - host->numaCell) < 0) + if (host->numa && + virCapabilitiesHostNUMAFormat(host->numa, buf) < 0) goto error; if (virCapabilitiesFormatCaches(buf, &host->cache) < 0) @@ -1394,14 +1390,15 @@ virCapabilitiesFormatXML(virCapsPtr caps) /* get the maximum ID of cpus in the host */ static unsigned int -virCapabilitiesGetHostMaxcpu(virCapsPtr caps) +virCapabilitiesHostNUMAGetMaxcpu(virCapsHostNUMAPtr caps) { unsigned int maxcpu = 0; size_t node; size_t cpu; - for (node = 0; node < caps->host.nnumaCell; node++) { - virCapsHostNUMACellPtr cell = caps->host.numaCell[node]; + for (node = 0; node < caps->cells->len; node++) { + virCapsHostNUMACellPtr cell = + g_ptr_array_index(caps->cells, node); for (cpu = 0; cpu < cell->ncpus; cpu++) { if (cell->cpus[cpu].id > maxcpu) @@ -1414,19 +1411,19 @@ virCapabilitiesGetHostMaxcpu(virCapsPtr caps) /* set cpus of a numa node in the bitmask */ static int -virCapabilitiesGetCpusForNode(virCapsPtr caps, - size_t node, - virBitmapPtr cpumask) +virCapabilitiesHostNUMAGetCellCpus(virCapsHostNUMAPtr caps, + size_t node, + virBitmapPtr cpumask) { virCapsHostNUMACellPtr cell = NULL; size_t cpu; size_t i; /* The numa node numbers can be non-contiguous. Ex: 0,1,16,17. */ - for (i = 0; i < caps->host.nnumaCell; i++) { - if (caps->host.numaCell[i]->num == node) { - cell = caps->host.numaCell[i]; + for (i = 0; i < caps->cells->len; i++) { + cell = g_ptr_array_index(caps->cells, i); + if (cell->num == node) break; - } + cell = NULL; } for (cpu = 0; cell && cpu < cell->ncpus; cpu++) { @@ -1443,11 +1440,11 @@ virCapabilitiesGetCpusForNode(virCapsPtr caps, } virBitmapPtr -virCapabilitiesGetCpusForNodemask(virCapsPtr caps, - virBitmapPtr nodemask) +virCapabilitiesHostNUMAGetCpus(virCapsHostNUMAPtr caps, + virBitmapPtr nodemask) { virBitmapPtr ret = NULL; - unsigned int maxcpu = virCapabilitiesGetHostMaxcpu(caps); + unsigned int maxcpu = virCapabilitiesHostNUMAGetMaxcpu(caps); ssize_t node = -1; if (!(ret = virBitmapNew(maxcpu + 1))) @@ -1455,7 +1452,7 @@ virCapabilitiesGetCpusForNodemask(virCapsPtr caps, while ((node = virBitmapNextSetBit(nodemask, node)) >= 0) { - if (virCapabilitiesGetCpusForNode(caps, node, ret) < 0) { + if (virCapabilitiesHostNUMAGetCellCpus(caps, node, ret) < 0) { virBitmapFree(ret); return NULL; } @@ -1591,7 +1588,7 @@ virCapabilitiesGetNUMAPagesInfo(int node, static int -virCapabilitiesInitNUMAFake(virCapsPtr caps) +virCapabilitiesHostNUMAInitFake(virCapsHostNUMAPtr caps) { virNodeInfo nodeinfo; virCapsHostNUMACellCPUPtr cpus; @@ -1631,16 +1628,18 @@ virCapabilitiesInitNUMAFake(virCapsPtr caps) } } - if (virCapabilitiesAddHostNUMACell(caps, 0, - nodeinfo.memory, + caps = g_new0(virCapsHostNUMA, 1); + caps->cells = g_ptr_array_new_with_free_func( + (GDestroyNotify)virCapabilitiesFreeHostNUMACell); + virCapabilitiesHostNUMAAddCell(caps, 0, + nodeinfo.memory, #ifdef __linux__ - onlinecpus, cpus, + onlinecpus, cpus, #else - ncpus, cpus, + ncpus, cpus, #endif - 0, NULL, - 0, NULL) < 0) - goto error; + 0, NULL, + 0, NULL); return 0; @@ -1651,8 +1650,9 @@ virCapabilitiesInitNUMAFake(virCapsPtr caps) return -1; } -int -virCapabilitiesInitNUMA(virCapsPtr caps) + +static int +virCapabilitiesHostNUMAInitReal(virCapsHostNUMAPtr caps) { int n; unsigned long long memory; @@ -1665,12 +1665,8 @@ virCapabilitiesInitNUMA(virCapsPtr caps) int ret = -1; int ncpus = 0; int cpu; - bool topology_failed = false; int max_node; - if (!virNumaIsAvailable()) - return virCapabilitiesInitNUMAFake(caps); - if ((max_node = virNumaGetMaxNode()) < 0) goto cleanup; @@ -1690,10 +1686,8 @@ virCapabilitiesInitNUMA(virCapsPtr caps) for (i = 0; i < virBitmapSize(cpumap); i++) { if (virBitmapIsBitSet(cpumap, i)) { - if (virCapabilitiesFillCPUInfo(i, cpus + cpu++) < 0) { - topology_failed = true; - virResetLastError(); - } + if (virCapabilitiesFillCPUInfo(i, cpus + cpu++) < 0) + goto cleanup; } } @@ -1707,11 +1701,10 @@ virCapabilitiesInitNUMA(virCapsPtr caps) virNumaGetNodeMemory(n, &memory, NULL); memory >>= 10; - if (virCapabilitiesAddHostNUMACell(caps, n, memory, - ncpus, cpus, - nsiblings, siblings, - npageinfo, pageinfo) < 0) - goto cleanup; + virCapabilitiesHostNUMAAddCell(caps, n, memory, + ncpus, cpus, + nsiblings, siblings, + npageinfo, pageinfo); cpus = NULL; siblings = NULL; @@ -1723,9 +1716,6 @@ virCapabilitiesInitNUMA(virCapsPtr caps) ret = 0; cleanup: - if ((topology_failed || ret < 0) && cpus) - virCapabilitiesClearHostNUMACellCPUTopology(cpus, ncpus); - virBitmapFree(cpumap); VIR_FREE(cpus); VIR_FREE(siblings); @@ -1733,6 +1723,44 @@ virCapabilitiesInitNUMA(virCapsPtr caps) return ret; } + +virCapsHostNUMAPtr +virCapabilitiesHostNUMANew(void) +{ + virCapsHostNUMAPtr caps = NULL; + + caps = g_new0(virCapsHostNUMA, 1); + caps->refs = 1; + caps->cells = g_ptr_array_new_with_free_func( + (GDestroyNotify)virCapabilitiesFreeHostNUMACell); + + return caps; +} + + +virCapsHostNUMAPtr +virCapabilitiesHostNUMANewHost(void) +{ + virCapsHostNUMAPtr caps = virCapabilitiesHostNUMANew(); + + if (virNumaIsAvailable()) { + if (virCapabilitiesHostNUMAInitReal(caps) == 0) + return caps; + + virCapabilitiesHostNUMAUnref(caps); + caps = virCapabilitiesHostNUMANew(); + VIR_WARN("Failed to query host NUMA topology, faking single NUMA node"); + } + + if (virCapabilitiesHostNUMAInitFake(caps) < 0) { + virCapabilitiesHostNUMAUnref(caps); + return NULL; + } + + return caps; +} + + int virCapabilitiesInitPages(virCapsPtr caps) { diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index c39fe0de08..f604e7b95e 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -113,6 +113,11 @@ struct _virCapsHostNUMACell { virCapsHostNUMACellPageInfoPtr pageinfo; }; +struct _virCapsHostNUMA { + gint refs; + GPtrArray *cells; +}; + struct _virCapsHostSecModelLabel { char *type; char *label; @@ -168,9 +173,8 @@ struct _virCapsHost { size_t nmigrateTrans; size_t nmigrateTrans_max; char **migrateTrans; - size_t nnumaCell; - size_t nnumaCell_max; - virCapsHostNUMACellPtr *numaCell; + + virCapsHostNUMAPtr numa; virResctrlInfoPtr resctrl; @@ -225,7 +229,11 @@ virCapabilitiesNew(virArch hostarch, bool liveMigrate); void -virCapabilitiesFreeNUMAInfo(virCapsPtr caps); +virCapabilitiesHostNUMAUnref(virCapsHostNUMAPtr caps); +void +virCapabilitiesHostNUMARef(virCapsHostNUMAPtr caps); + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCapsHostNUMA, virCapabilitiesHostNUMAUnref); int virCapabilitiesAddHostFeature(virCapsPtr caps, @@ -239,8 +247,8 @@ int virCapabilitiesSetNetPrefix(virCapsPtr caps, const char *prefix); -int -virCapabilitiesAddHostNUMACell(virCapsPtr caps, +void +virCapabilitiesHostNUMAAddCell(virCapsHostNUMAPtr caps, int num, unsigned long long mem, int ncpus, @@ -323,14 +331,15 @@ virCapabilitiesClearHostNUMACellCPUTopology(virCapsHostNUMACellCPUPtr cpu, char * virCapabilitiesFormatXML(virCapsPtr caps); -virBitmapPtr virCapabilitiesGetCpusForNodemask(virCapsPtr caps, - virBitmapPtr nodemask); +virBitmapPtr virCapabilitiesHostNUMAGetCpus(virCapsHostNUMAPtr caps, + virBitmapPtr nodemask); int virCapabilitiesGetNodeInfo(virNodeInfoPtr nodeinfo); int virCapabilitiesInitPages(virCapsPtr caps); -int virCapabilitiesInitNUMA(virCapsPtr caps); +virCapsHostNUMAPtr virCapabilitiesHostNUMANew(void); +virCapsHostNUMAPtr virCapabilitiesHostNUMANewHost(void); bool virCapsHostCacheBankEquals(virCapsHostCacheBankPtr a, virCapsHostCacheBankPtr b); diff --git a/src/conf/virconftypes.h b/src/conf/virconftypes.h index 462842f324..2c91d3f331 100644 --- a/src/conf/virconftypes.h +++ b/src/conf/virconftypes.h @@ -66,6 +66,9 @@ typedef virCapsHostMemBW *virCapsHostMemBWPtr; typedef struct _virCapsHostMemBWNode virCapsHostMemBWNode; typedef virCapsHostMemBWNode *virCapsHostMemBWNodePtr; +typedef struct _virCapsHostNUMA virCapsHostNUMA; +typedef virCapsHostNUMA *virCapsHostNUMAPtr; + typedef struct _virCapsHostNUMACell virCapsHostNUMACell; typedef virCapsHostNUMACell *virCapsHostNUMACellPtr; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 74ca8585ee..0465ce8fc1 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -49,7 +49,6 @@ virCapabilitiesAddGuestFeature; virCapabilitiesAddGuestFeatureWithToggle; virCapabilitiesAddHostFeature; virCapabilitiesAddHostMigrateTransport; -virCapabilitiesAddHostNUMACell; virCapabilitiesAddStoragePool; virCapabilitiesAllocMachines; virCapabilitiesClearHostNUMACellCPUTopology; @@ -58,13 +57,16 @@ virCapabilitiesDomainSupported; virCapabilitiesFormatXML; virCapabilitiesFreeGuest; virCapabilitiesFreeMachines; -virCapabilitiesFreeNUMAInfo; -virCapabilitiesGetCpusForNodemask; virCapabilitiesGetNodeInfo; virCapabilitiesHostInitIOMMU; +virCapabilitiesHostNUMAAddCell; +virCapabilitiesHostNUMAGetCpus; +virCapabilitiesHostNUMANew; +virCapabilitiesHostNUMANewHost; +virCapabilitiesHostNUMARef; +virCapabilitiesHostNUMAUnref; virCapabilitiesHostSecModelAddBaseLabel; virCapabilitiesInitCaches; -virCapabilitiesInitNUMA; virCapabilitiesInitPages; virCapabilitiesNew; virCapabilitiesSetHostCPU; diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c index c920c2aec5..e2327474fa 100644 --- a/src/libxl/libxl_capabilities.c +++ b/src/libxl/libxl_capabilities.c @@ -320,6 +320,7 @@ libxlCapsInitNuma(libxl_ctx *ctx, virCapsPtr caps) } } + caps->host.numa = virCapabilitiesHostNUMANew(); for (i = 0; i < nr_nodes; i++) { if (numa_info[i].size == LIBXL_NUMAINFO_INVALID_ENTRY) continue; @@ -337,15 +338,11 @@ libxlCapsInitNuma(libxl_ctx *ctx, virCapsPtr caps) } } - if (virCapabilitiesAddHostNUMACell(caps, i, - numa_info[i].size / 1024, - nr_cpus_node[i], cpus[i], - nr_siblings, siblings, - 0, NULL) < 0) { - virCapabilitiesClearHostNUMACellCPUTopology(cpus[i], - nr_cpus_node[i]); - goto cleanup; - } + virCapabilitiesHostNUMAAddCell(caps->host.numa, i, + numa_info[i].size / 1024, + nr_cpus_node[i], cpus[i], + nr_siblings, siblings, + 0, NULL); /* This is safe, as the CPU list is now stored in the NUMA cell */ cpus[i] = NULL; @@ -357,7 +354,10 @@ libxlCapsInitNuma(libxl_ctx *ctx, virCapsPtr caps) if (ret != 0) { for (i = 0; cpus && i < nr_nodes; i++) VIR_FREE(cpus[i]); - virCapabilitiesFreeNUMAInfo(caps); + if (caps->host.numa) { + virCapabilitiesHostNUMAUnref(caps->host.numa); + caps->host.numa = NULL; + } VIR_FREE(siblings); } diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c index 2e866973ce..2df1537b22 100644 --- a/src/lxc/lxc_conf.c +++ b/src/lxc/lxc_conf.c @@ -70,10 +70,8 @@ virCapsPtr virLXCDriverCapsInit(virLXCDriverPtr driver) * unexpected failures. We don't want to break the lxc * driver in this scenario, so log errors & carry on */ - if (virCapabilitiesInitNUMA(caps) < 0) { - virCapabilitiesFreeNUMAInfo(caps); - VIR_WARN("Failed to query host NUMA topology, disabling NUMA capabilities"); - } + if (!(caps->host.numa = virCapabilitiesHostNUMANewHost())) + goto error; if (virCapabilitiesInitCaches(caps) < 0) VIR_WARN("Failed to get host CPU cache info"); diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index a15d68d37f..971adaf71c 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -155,7 +155,7 @@ virCapsPtr openvzCapsInit(void) false, false)) == NULL) goto no_memory; - if (virCapabilitiesInitNUMA(caps) < 0) + if (!(caps->host.numa = virCapabilitiesHostNUMANewHost())) goto no_memory; if (virCapabilitiesInitCaches(caps) < 0) diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 640d90585a..6bd37a6925 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -322,11 +322,8 @@ phypCapsInit(void) * unexpected failures. We don't want to break the QEMU * driver in this scenario, so log errors & carry on */ - if (virCapabilitiesInitNUMA(caps) < 0) { - virCapabilitiesFreeNUMAInfo(caps); - VIR_WARN - ("Failed to query host NUMA topology, disabling NUMA capabilities"); - } + if (!(caps->host.numa = virCapabilitiesHostNUMANewHost())) + goto no_memory; if (virCapabilitiesInitCaches(caps) < 0) VIR_WARN("Failed to get host CPU cache info"); diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index bfe59a1eff..ea3558a3db 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -1036,10 +1036,8 @@ virQEMUCapsInit(virFileCachePtr cache) * unexpected failures. We don't want to break the QEMU * driver in this scenario, so log errors & carry on */ - if (virCapabilitiesInitNUMA(caps) < 0) { - virCapabilitiesFreeNUMAInfo(caps); - VIR_WARN("Failed to query host NUMA topology, disabling NUMA capabilities"); - } + if (!(caps->host.numa = virCapabilitiesHostNUMANewHost())) + goto error; if (virCapabilitiesInitCaches(caps) < 0) VIR_WARN("Failed to get host CPU cache info"); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 84813ded40..e1cbffa935 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -2941,8 +2941,11 @@ qemuDomainObjPrivateXMLParseAutomaticPlacement(xmlXPathContextPtr ctxt, /* Figure out how big the nodeset bitmap needs to be. * This is necessary because NUMA node IDs are not guaranteed to * start from 0 or be densely allocated */ - for (i = 0; i < caps->host.nnumaCell; i++) - nodesetSize = MAX(nodesetSize, caps->host.numaCell[i]->num + 1); + for (i = 0; i < caps->host.numa->cells->len; i++) { + virCapsHostNUMACellPtr cell = + g_ptr_array_index(caps->host.numa->cells, i); + nodesetSize = MAX(nodesetSize, cell->num + 1); + } if (nodeset && virBitmapParse(nodeset, &priv->autoNodeset, nodesetSize) < 0) @@ -2954,8 +2957,8 @@ qemuDomainObjPrivateXMLParseAutomaticPlacement(xmlXPathContextPtr ctxt, } else { /* autoNodeset is present in this case, since otherwise we wouldn't * reach this code */ - if (!(priv->autoCpuset = virCapabilitiesGetCpusForNodemask(caps, - priv->autoNodeset))) + if (!(priv->autoCpuset = virCapabilitiesHostNUMAGetCpus(caps->host.numa, + priv->autoNodeset))) goto cleanup; } diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index c7f9acadeb..bb10e8b2ef 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -4809,16 +4809,12 @@ qemuMigrationDstPersist(virQEMUDriverPtr driver, { virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); qemuDomainObjPrivatePtr priv = vm->privateData; - virCapsPtr caps = NULL; virDomainDefPtr vmdef; virDomainDefPtr oldDef = NULL; unsigned int oldPersist = vm->persistent; virObjectEventPtr event; int ret = -1; - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; - vm->persistent = 1; oldDef = vm->newDef; vm->newDef = qemuMigrationCookieGetPersistent(mig); @@ -4842,7 +4838,6 @@ qemuMigrationDstPersist(virQEMUDriverPtr driver, cleanup: virDomainDefFree(oldDef); - virObjectUnref(caps); virObjectUnref(cfg); return ret; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 4287ed0830..623ea761e1 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6161,7 +6161,7 @@ qemuProcessPrepareDomainNUMAPlacement(virDomainObjPtr vm, /* numad may return a nodeset that only contains cpus but cgroups don't play * well with that. Set the autoCpuset from all cpus from that nodeset, but * assign autoNodeset only with nodes containing memory. */ - if (!(priv->autoCpuset = virCapabilitiesGetCpusForNodemask(caps, numadNodeset))) + if (!(priv->autoCpuset = virCapabilitiesHostNUMAGetCpus(caps->host.numa, numadNodeset))) goto cleanup; virBitmapIntersect(numadNodeset, hostMemoryNodeset); diff --git a/src/test/test_driver.c b/src/test/test_driver.c index f3d6061625..2e4ecfd0ff 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -302,6 +302,7 @@ testBuildCapabilities(virConnectPtr conn) caps->host.pagesSize[caps->host.nPagesSize++] = 2048; caps->host.pagesSize[caps->host.nPagesSize++] = 1024 * 1024; + caps->host.numa = virCapabilitiesHostNUMANew(); for (i = 0; i < privconn->numCells; i++) { virCapsHostNUMACellCPUPtr cpu_cells; virCapsHostNUMACellPageInfoPtr pages; @@ -326,10 +327,10 @@ testBuildCapabilities(virConnectPtr conn) pages[0].avail = privconn->cells[i].mem / pages[0].size; - if (virCapabilitiesAddHostNUMACell(caps, i, privconn->cells[i].mem, - privconn->cells[i].numCpus, - cpu_cells, 0, NULL, nPages, pages) < 0) - goto error; + virCapabilitiesHostNUMAAddCell(caps->host.numa, + i, privconn->cells[i].mem, + privconn->cells[i].numCpus, + cpu_cells, 0, NULL, nPages, pages); } for (i = 0; i < G_N_ELEMENTS(guest_types); i++) { diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 2930a2f0e1..5957ae52c4 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -76,7 +76,7 @@ vboxCapsInit(void) false, false)) == NULL) goto no_memory; - if (virCapabilitiesInitNUMA(caps) < 0) + if (!(caps->host.numa = virCapabilitiesHostNUMANewHost())) goto no_memory; if (virCapabilitiesInitCaches(caps) < 0) diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index ef7696a496..9f7d874c12 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -71,7 +71,7 @@ vmwareCapsInit(void) false, false)) == NULL) goto error; - if (virCapabilitiesInitNUMA(caps) < 0) + if (!(caps->host.numa = virCapabilitiesHostNUMANewHost())) goto error; if (virCapabilitiesInitCaches(caps) < 0) diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 0acdcb9760..9e8ea676e0 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -116,7 +116,7 @@ vzBuildCapabilities(void) false, false)) == NULL) return NULL; - if (virCapabilitiesInitNUMA(caps) < 0) + if (!(caps->host.numa = virCapabilitiesHostNUMANewHost())) goto error; if (virCapabilitiesInitCaches(caps) < 0) diff --git a/tests/testutils.c b/tests/testutils.c index c55450de96..7a0d306eb7 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -1053,10 +1053,10 @@ virCapsPtr virTestGenericCapsInit(void) * Build NUMA topology with cell id starting from (0 + seq) * for testing */ -int -virTestCapsBuildNUMATopology(virCapsPtr caps, - int seq) +virCapsHostNUMAPtr +virTestCapsBuildNUMATopology(int seq) { + virCapsHostNUMAPtr caps = virCapabilitiesHostNUMANew(); virCapsHostNUMACellCPUPtr cell_cpus = NULL; int core_id, cell_id; int id; @@ -1077,22 +1077,21 @@ virTestCapsBuildNUMATopology(virCapsPtr caps, } id++; - if (virCapabilitiesAddHostNUMACell(caps, cell_id + seq, - MAX_MEM_IN_CELL, - MAX_CPUS_IN_CELL, cell_cpus, - VIR_ARCH_NONE, NULL, - VIR_ARCH_NONE, NULL) < 0) - goto error; + virCapabilitiesHostNUMAAddCell(caps, cell_id + seq, + MAX_MEM_IN_CELL, + MAX_CPUS_IN_CELL, cell_cpus, + VIR_ARCH_NONE, NULL, + VIR_ARCH_NONE, NULL); cell_cpus = NULL; } - return 0; + return caps; error: - virCapabilitiesClearHostNUMACellCPUTopology(cell_cpus, MAX_CPUS_IN_CELL); + virCapabilitiesHostNUMAUnref(caps); VIR_FREE(cell_cpus); - return -1; + return NULL; } static virDomainDefParserConfig virTestGenericDomainDefParserConfig = { diff --git a/tests/testutils.h b/tests/testutils.h index c3f2cee85f..dcb7cc4c04 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -157,8 +157,7 @@ int virTestMain(int argc, #define VIR_TEST_MOCK(mock) (abs_builddir "/.libs/lib" mock "mock" MOCK_EXT) virCapsPtr virTestGenericCapsInit(void); -int virTestCapsBuildNUMATopology(virCapsPtr caps, - int seq); +virCapsHostNUMAPtr virTestCapsBuildNUMATopology(int seq); virDomainXMLOptionPtr virTestGenericDomainXMLConfInit(void); typedef enum { diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 38be2cfe42..731775adc0 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -205,7 +205,7 @@ virCapsPtr testQemuCapsInit(void) * Build a NUMA topology with cell_id (NUMA node id * being 3(0 + 3),4(1 + 3), 5 and 6 */ - if (virTestCapsBuildNUMATopology(caps, 3) < 0) + if (!(caps->host.numa = virTestCapsBuildNUMATopology(3))) goto cleanup; for (i = 0; i < VIR_ARCH_LAST; i++) { diff --git a/tests/vircaps2xmltest.c b/tests/vircaps2xmltest.c index 32c8f95303..6c08a26ec4 100644 --- a/tests/vircaps2xmltest.c +++ b/tests/vircaps2xmltest.c @@ -58,8 +58,10 @@ test_virCapabilities(const void *opaque) if (!caps) goto cleanup; - if (virCapabilitiesInitNUMA(caps) < 0 || - virCapabilitiesInitCaches(caps) < 0) + if (!(caps->host.numa = virCapabilitiesHostNUMANewHost())) + goto cleanup; + + if (virCapabilitiesInitCaches(caps) < 0) goto cleanup; virFileWrapperClearPrefixes(); diff --git a/tests/vircapstest.c b/tests/vircapstest.c index 8c5982c9ac..6251ade1a1 100644 --- a/tests/vircapstest.c +++ b/tests/vircapstest.c @@ -35,27 +35,22 @@ test_virCapabilitiesGetCpusForNodemask(const void *data G_GNUC_UNUSED) const char *nodestr = "3,4,5,6"; virBitmapPtr nodemask = NULL; virBitmapPtr cpumap = NULL; - virCapsPtr caps = NULL; + g_autoptr(virCapsHostNUMA) caps = NULL; int mask_size = 8; int ret = -1; - - if (!(caps = virCapabilitiesNew(VIR_ARCH_X86_64, false, false))) - goto error; - - if (virTestCapsBuildNUMATopology(caps, 3) < 0) + if (!(caps = virTestCapsBuildNUMATopology(3))) goto error; if (virBitmapParse(nodestr, &nodemask, mask_size) < 0) goto error; - if (!(cpumap = virCapabilitiesGetCpusForNodemask(caps, nodemask))) + if (!(cpumap = virCapabilitiesHostNUMAGetCpus(caps, nodemask))) goto error; ret = 0; error: - virObjectUnref(caps); virBitmapFree(nodemask); virBitmapFree(cpumap); return ret; -- 2.23.0

Avoid grabbing the whole virCapsPtr object when we only need the NUMA information. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/qemu/qemu_capabilities.c | 7 ------- src/qemu/qemu_conf.c | 17 +++++++++++++++ src/qemu/qemu_conf.h | 6 ++++++ src/qemu/qemu_domain.c | 10 ++++----- src/qemu/qemu_process.c | 40 +++++++++++++++--------------------- tests/testutilsqemu.c | 18 +++++++++++----- 6 files changed, 57 insertions(+), 41 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index ea3558a3db..66bee49d6f 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -1032,13 +1032,6 @@ virQEMUCapsInit(virFileCachePtr cache) true, true)) == NULL) goto error; - /* Some machines have problematic NUMA topology causing - * unexpected failures. We don't want to break the QEMU - * driver in this scenario, so log errors & carry on - */ - if (!(caps->host.numa = virCapabilitiesHostNUMANewHost())) - goto error; - if (virCapabilitiesInitCaches(caps) < 0) VIR_WARN("Failed to get host CPU cache info"); diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 053bcc7e02..ba3001ccd0 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1204,6 +1204,22 @@ virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver, } +virCapsHostNUMAPtr +virQEMUDriverGetHostNUMACaps(virQEMUDriverPtr driver) +{ + qemuDriverLock(driver); + + if (!driver->hostnuma) + driver->hostnuma = virCapabilitiesHostNUMANewHost(); + + qemuDriverUnlock(driver); + + virCapabilitiesHostNUMARef(driver->hostnuma); + + return driver->hostnuma; +} + + virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver) { size_t i, j; @@ -1255,6 +1271,7 @@ virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver) "DOI \"%s\"", model, doi); } + caps->host.numa = virQEMUDriverGetHostNUMACaps(driver); return g_steal_pointer(&caps); } diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 8b6c2a95d4..2d03df9171 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -262,6 +262,11 @@ struct _virQEMUDriver { */ virCapsPtr caps; + /* Lazy initialized on first use, immutable thereafter. + * Require lock to get the pointer & do optional initialization + */ + virCapsHostNUMAPtr hostnuma; + /* Immutable value */ virArch hostarch; @@ -319,6 +324,7 @@ virQEMUDriverConfigSetDefaults(virQEMUDriverConfigPtr cfg); virQEMUDriverConfigPtr virQEMUDriverGetConfig(virQEMUDriverPtr driver); bool virQEMUDriverIsPrivileged(virQEMUDriverPtr driver); +virCapsHostNUMAPtr virQEMUDriverGetHostNUMACaps(virQEMUDriverPtr driver); virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver); virCapsPtr virQEMUDriverGetCapabilities(virQEMUDriverPtr driver, bool refresh); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index e1cbffa935..a18da01bf9 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -2922,7 +2922,7 @@ qemuDomainObjPrivateXMLParseAutomaticPlacement(xmlXPathContextPtr ctxt, qemuDomainObjPrivatePtr priv, virQEMUDriverPtr driver) { - virCapsPtr caps = NULL; + g_autoptr(virCapsHostNUMA) caps = NULL; char *nodeset; char *cpuset; int nodesetSize = 0; @@ -2935,15 +2935,15 @@ qemuDomainObjPrivateXMLParseAutomaticPlacement(xmlXPathContextPtr ctxt, if (!nodeset && !cpuset) return 0; - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) + if (!(caps = virQEMUDriverGetHostNUMACaps(driver))) goto cleanup; /* Figure out how big the nodeset bitmap needs to be. * This is necessary because NUMA node IDs are not guaranteed to * start from 0 or be densely allocated */ - for (i = 0; i < caps->host.numa->cells->len; i++) { + for (i = 0; i < caps->cells->len; i++) { virCapsHostNUMACellPtr cell = - g_ptr_array_index(caps->host.numa->cells, i); + g_ptr_array_index(caps->cells, i); nodesetSize = MAX(nodesetSize, cell->num + 1); } @@ -2957,7 +2957,7 @@ qemuDomainObjPrivateXMLParseAutomaticPlacement(xmlXPathContextPtr ctxt, } else { /* autoNodeset is present in this case, since otherwise we wouldn't * reach this code */ - if (!(priv->autoCpuset = virCapabilitiesHostNUMAGetCpus(caps->host.numa, + if (!(priv->autoCpuset = virCapabilitiesHostNUMAGetCpus(caps, priv->autoNodeset))) goto cleanup; } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 623ea761e1..cc89ff8571 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6129,14 +6129,14 @@ qemuProcessUpdateGuestCPU(virDomainDefPtr def, static int -qemuProcessPrepareDomainNUMAPlacement(virDomainObjPtr vm, - virCapsPtr caps) +qemuProcessPrepareDomainNUMAPlacement(virQEMUDriverPtr driver, + virDomainObjPtr vm) { qemuDomainObjPrivatePtr priv = vm->privateData; - char *nodeset = NULL; - virBitmapPtr numadNodeset = NULL; - virBitmapPtr hostMemoryNodeset = NULL; - int ret = -1; + g_autofree char *nodeset = NULL; + g_autoptr(virBitmap) numadNodeset = NULL; + g_autoptr(virBitmap) hostMemoryNodeset = NULL; + g_autoptr(virCapsHostNUMA) caps = NULL; /* Get the advisory nodeset from numad if 'placement' of * either <vcpu> or <numatune> is 'auto'. @@ -6148,33 +6148,30 @@ qemuProcessPrepareDomainNUMAPlacement(virDomainObjPtr vm, virDomainDefGetMemoryTotal(vm->def)); if (!nodeset) - goto cleanup; + return -1; if (!(hostMemoryNodeset = virNumaGetHostMemoryNodeset())) - goto cleanup; + return -1; VIR_DEBUG("Nodeset returned from numad: %s", nodeset); if (virBitmapParse(nodeset, &numadNodeset, VIR_DOMAIN_CPUMASK_LEN) < 0) - goto cleanup; + return -1; + + if (!(caps = virQEMUDriverGetHostNUMACaps(driver))) + return -1; /* numad may return a nodeset that only contains cpus but cgroups don't play * well with that. Set the autoCpuset from all cpus from that nodeset, but * assign autoNodeset only with nodes containing memory. */ - if (!(priv->autoCpuset = virCapabilitiesHostNUMAGetCpus(caps->host.numa, numadNodeset))) - goto cleanup; + if (!(priv->autoCpuset = virCapabilitiesHostNUMAGetCpus(caps, numadNodeset))) + return -1; virBitmapIntersect(numadNodeset, hostMemoryNodeset); priv->autoNodeset = g_steal_pointer(&numadNodeset); - ret = 0; - - cleanup: - VIR_FREE(nodeset); - virBitmapFree(numadNodeset); - virBitmapFree(hostMemoryNodeset); - return ret; + return 0; } @@ -6252,10 +6249,6 @@ qemuProcessPrepareDomain(virQEMUDriverPtr driver, size_t i; qemuDomainObjPrivatePtr priv = vm->privateData; virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); - virCapsPtr caps; - - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; priv->machineName = qemuDomainGetMachineName(vm); if (!priv->machineName) @@ -6271,7 +6264,7 @@ qemuProcessPrepareDomain(virQEMUDriverPtr driver, } virDomainAuditSecurityLabel(vm, true); - if (qemuProcessPrepareDomainNUMAPlacement(vm, caps) < 0) + if (qemuProcessPrepareDomainNUMAPlacement(driver, vm) < 0) goto cleanup; } @@ -6359,7 +6352,6 @@ qemuProcessPrepareDomain(virQEMUDriverPtr driver, ret = 0; cleanup: - virObjectUnref(caps); virObjectUnref(cfg); return ret; } diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 731775adc0..fb9b85747a 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -109,6 +109,18 @@ virFindFileInPath(const char *file) return NULL; } + +virCapsHostNUMAPtr +virCapabilitiesHostNUMANewHost(void) +{ + /* + * Build a NUMA topology with cell_id (NUMA node id + * being 3(0 + 3),4(1 + 3), 5 and 6 + */ + return virTestCapsBuildNUMATopology(3); +} + + static int testQemuAddGuest(virCapsPtr caps, virArch arch) @@ -201,11 +213,7 @@ virCapsPtr testQemuCapsInit(void) qemuTestSetHostCPU(caps, NULL); - /* - * Build a NUMA topology with cell_id (NUMA node id - * being 3(0 + 3),4(1 + 3), 5 and 6 - */ - if (!(caps->host.numa = virTestCapsBuildNUMATopology(3))) + if (!(caps->host.numa = virCapabilitiesHostNUMANewHost())) goto cleanup; for (i = 0; i < VIR_ARCH_LAST; i++) { -- 2.23.0

Annoyingly there was no existing constructor, and identifying all the places which do a VIR_ALLOC(cpu) is a bit error prone. Hopefully this has found & converted them all. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/conf/cpu_conf.c | 29 ++++++++++++++++++++++------- src/conf/cpu_conf.h | 4 ++++ src/cpu/cpu.c | 3 +-- src/cpu/cpu_arm.c | 5 +---- src/cpu/cpu_ppc64.c | 3 +-- src/cpu/cpu_x86.c | 6 ++---- src/libvirt_private.syms | 2 ++ src/libxl/libxl_capabilities.c | 3 +-- src/libxl/xen_xl.c | 11 +++-------- src/qemu/qemu_capabilities.c | 8 ++------ src/qemu/qemu_domain.c | 2 +- src/vmx/vmx.c | 3 +-- tests/cputest.c | 11 +++-------- 13 files changed, 44 insertions(+), 46 deletions(-) diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 4542bcb7bd..7490d6bf73 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -82,6 +82,13 @@ VIR_ENUM_IMPL(virCPUCacheMode, ); +virCPUDefPtr virCPUDefNew(void) +{ + virCPUDefPtr cpu = g_new0(virCPUDef, 1); + cpu->refs = 1; + return cpu; +} + void virCPUDefFreeFeatures(virCPUDefPtr def) { @@ -104,16 +111,24 @@ virCPUDefFreeModel(virCPUDefPtr def) virCPUDefFreeFeatures(def); } +void +virCPUDefRef(virCPUDefPtr def) +{ + g_atomic_int_inc(&def->refs); +} + void virCPUDefFree(virCPUDefPtr def) { if (!def) return; - virCPUDefFreeModel(def); - VIR_FREE(def->cache); - VIR_FREE(def->tsc); - VIR_FREE(def); + if (g_atomic_int_dec_and_test(&def->refs)) { + virCPUDefFreeModel(def); + VIR_FREE(def->cache); + VIR_FREE(def->tsc); + VIR_FREE(def); + } } @@ -214,9 +229,10 @@ virCPUDefCopyWithoutModel(const virCPUDef *cpu) { virCPUDefPtr copy; - if (!cpu || VIR_ALLOC(copy) < 0) + if (!cpu) return NULL; + copy = virCPUDefNew(); copy->type = cpu->type; copy->mode = cpu->mode; copy->match = cpu->match; @@ -340,8 +356,7 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt, goto cleanup; } - if (VIR_ALLOC(def) < 0) - goto cleanup; + def = virCPUDefNew(); if (type == VIR_CPU_TYPE_AUTO) { if (virXPathBoolean("boolean(./arch)", ctxt)) { diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h index 96fda3e6b3..ec3d2379cf 100644 --- a/src/conf/cpu_conf.h +++ b/src/conf/cpu_conf.h @@ -122,6 +122,7 @@ struct _virCPUCacheDef { typedef struct _virCPUDef virCPUDef; typedef virCPUDef *virCPUDefPtr; struct _virCPUDef { + int refs; int type; /* enum virCPUType */ int mode; /* enum virCPUMode */ int match; /* enum virCPUMatch */ @@ -142,6 +143,7 @@ struct _virCPUDef { virHostCPUTscInfoPtr tsc; }; +virCPUDefPtr virCPUDefNew(void); void ATTRIBUTE_NONNULL(1) virCPUDefFreeFeatures(virCPUDefPtr def); @@ -149,6 +151,8 @@ virCPUDefFreeFeatures(virCPUDefPtr def); void ATTRIBUTE_NONNULL(1) virCPUDefFreeModel(virCPUDefPtr def); +void +virCPUDefRef(virCPUDefPtr def); void virCPUDefFree(virCPUDefPtr def); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCPUDef, virCPUDefFree); diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index 40f725fd21..a2ae5b8c07 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -393,8 +393,7 @@ virCPUGetHost(virArch arch, if (!(driver = cpuGetSubDriver(arch))) return NULL; - if (VIR_ALLOC(cpu) < 0) - return NULL; + cpu = virCPUDefNew(); switch (type) { case VIR_CPU_TYPE_HOST: diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c index 70dba6021c..ee5802198f 100644 --- a/src/cpu/cpu_arm.c +++ b/src/cpu/cpu_arm.c @@ -211,10 +211,7 @@ virCPUarmBaseline(virCPUDefPtr *cpus, { virCPUDefPtr cpu = NULL; - if (VIR_ALLOC(cpu) < 0) { - virCPUDefFree(cpu); - return NULL; - } + cpu = virCPUDefNew(); cpu->model = g_strdup(cpus[0]->model); diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c index 3236a9616e..818f1ec699 100644 --- a/src/cpu/cpu_ppc64.c +++ b/src/cpu/cpu_ppc64.c @@ -757,8 +757,7 @@ virCPUppc64Baseline(virCPUDefPtr *cpus, } } - if (VIR_ALLOC(cpu) < 0) - goto error; + cpu = virCPUDefNew(); cpu->model = g_strdup(model->name); diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index c83cab0c53..1e913cc9fa 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -775,8 +775,7 @@ x86DataToCPU(const virCPUx86Data *data, virCPUx86Data modelData = VIR_CPU_X86_DATA_INIT; virCPUx86VendorPtr vendor; - if (VIR_ALLOC(cpu) < 0) - goto error; + cpu = virCPUDefNew(); cpu->model = g_strdup(model->name); @@ -2807,8 +2806,7 @@ virCPUx86Baseline(virCPUDefPtr *cpus, if (!(base_model = x86ModelFromCPU(cpus[0], map, -1))) goto error; - if (VIR_ALLOC(cpu) < 0) - goto error; + cpu = virCPUDefNew(); cpu->type = VIR_CPU_TYPE_GUEST; cpu->match = VIR_CPU_MATCH_EXACT; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 0465ce8fc1..defa527306 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -104,8 +104,10 @@ virCPUDefFreeModel; virCPUDefIsEqual; virCPUDefListFree; virCPUDefListParse; +virCPUDefNew; virCPUDefParseXML; virCPUDefParseXMLString; +virCPUDefRef; virCPUDefStealModel; virCPUDefUpdateFeature; virCPUModeTypeToString; diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c index e2327474fa..e9f958cd8a 100644 --- a/src/libxl/libxl_capabilities.c +++ b/src/libxl/libxl_capabilities.c @@ -169,8 +169,7 @@ libxlCapsInitCPU(virCapsPtr caps, libxl_physinfo *phy_info, if (!phy_info->hw_cap[0]) return 0; - if (VIR_ALLOC(cpu) < 0) - goto error; + cpu = virCPUDefNew(); host_pae = phy_info->hw_cap[0] & LIBXL_X86_FEATURE_PAE_MASK; if (host_pae && diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c index 18ea4a8d95..cdff71f11b 100644 --- a/src/libxl/xen_xl.c +++ b/src/libxl/xen_xl.c @@ -177,10 +177,7 @@ xenParseXLOS(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps) } if (!def->cpu) { - virCPUDefPtr cpu; - if (VIR_ALLOC(cpu) < 0) - return -1; - + virCPUDefPtr cpu = virCPUDefNew(); cpu->mode = VIR_CPU_MODE_HOST_PASSTHROUGH; cpu->type = VIR_CPU_TYPE_GUEST; cpu->nfeatures = 0; @@ -266,8 +263,7 @@ xenParseXLCPUID(virConfPtr conf, virDomainDefPtr def) return 0; if (!def->cpu) { - if (VIR_ALLOC(def->cpu) < 0) - goto cleanup; + def->cpu = virCPUDefNew(); def->cpu->mode = VIR_CPU_MODE_HOST_PASSTHROUGH; def->cpu->type = VIR_CPU_TYPE_GUEST; def->cpu->nfeatures = 0; @@ -445,8 +441,7 @@ xenParseXLVnuma(virConfPtr conf, if (!virDomainNumaSetNodeCount(numa, nr_nodes)) goto cleanup; - if (VIR_ALLOC(cpu) < 0) - goto cleanup; + cpu = virCPUDefNew(); list = list->list; while (list) { diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 66bee49d6f..16c4331b13 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2720,8 +2720,7 @@ virQEMUCapsProbeQMPHostCPU(virQEMUCapsPtr qemuCaps, if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION)) return 0; - if (VIR_ALLOC(cpu) < 0) - goto cleanup; + cpu = virCPUDefNew(); cpu->model = g_strdup(model); @@ -3355,10 +3354,7 @@ virQEMUCapsInitCPUModel(virQEMUCapsPtr qemuCaps, static virCPUDefPtr virQEMUCapsNewHostCPUModel(void) { - virCPUDefPtr cpu; - - if (VIR_ALLOC(cpu) < 0) - return NULL; + virCPUDefPtr cpu = virCPUDefNew(); cpu->type = VIR_CPU_TYPE_GUEST; cpu->mode = VIR_CPU_MODE_CUSTOM; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index a18da01bf9..29a417e931 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4481,7 +4481,7 @@ qemuDomainDefSetDefaultCPU(virDomainDefPtr def, } if (!def->cpu) - def->cpu = g_new0(virCPUDef, 1); + def->cpu = virCPUDefNew(); def->cpu->type = VIR_CPU_TYPE_GUEST; diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index df5eafbd44..37211b7c62 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -1475,8 +1475,7 @@ virVMXParseConfig(virVMXContext *ctx, goto cleanup; if (coresPerSocket > 1) { - if (VIR_ALLOC(cpu) < 0) - goto cleanup; + cpu = virCPUDefNew(); cpu->type = VIR_CPU_TYPE_GUEST; cpu->mode = VIR_CPU_MODE_CUSTOM; diff --git a/tests/cputest.c b/tests/cputest.c index b883ba7b80..fd86344ea4 100644 --- a/tests/cputest.c +++ b/tests/cputest.c @@ -482,8 +482,7 @@ cpuTestMakeQEMUCaps(const struct data *data) if (!(testMon = qemuMonitorTestNewFromFile(json, driver.xmlopt, true))) goto error; - if (VIR_ALLOC(cpu) < 0) - goto cleanup; + cpu = virCPUDefNew(); cpu->model = g_strdup("host"); @@ -584,9 +583,7 @@ cpuTestCPUID(bool guest, const void *arg) !(hostData = virCPUDataParse(host))) goto cleanup; - if (VIR_ALLOC(cpu) < 0) - goto cleanup; - + cpu = virCPUDefNew(); cpu->arch = hostData->arch; if (guest) { cpu->type = VIR_CPU_TYPE_GUEST; @@ -889,9 +886,7 @@ cpuTestJSONCPUID(const void *arg) if (!(qemuCaps = cpuTestMakeQEMUCaps(data))) goto cleanup; - if (VIR_ALLOC(cpu) < 0) - goto cleanup; - + cpu = virCPUDefNew(); cpu->arch = data->arch; cpu->type = VIR_CPU_TYPE_GUEST; cpu->match = VIR_CPU_MATCH_EXACT; -- 2.23.0

Avoid grabbing the whole virCapsPtr object when we only need the host CPU information. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/qemu/qemu_capabilities.c | 3 -- src/qemu/qemu_conf.c | 17 +++++++++ src/qemu/qemu_conf.h | 6 ++++ src/qemu/qemu_driver.c | 6 ++-- src/qemu/qemu_process.c | 68 +++++++++++++++--------------------- tests/domaincapstest.c | 14 +++----- tests/qemucapabilitiestest.c | 9 ++--- tests/qemuxml2argvtest.c | 8 ++--- tests/testutilsqemu.c | 49 +++++++++++--------------- tests/testutilsqemu.h | 5 ++- 10 files changed, 89 insertions(+), 96 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 16c4331b13..1b395a2570 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -1035,9 +1035,6 @@ virQEMUCapsInit(virFileCachePtr cache) if (virCapabilitiesInitCaches(caps) < 0) VIR_WARN("Failed to get host CPU cache info"); - if (!(caps->host.cpu = virCPUProbeHost(caps->host.arch))) - VIR_WARN("Failed to get host CPU"); - /* Add the power management features of the host */ if (virNodeSuspendGetTargetMask(&caps->host.powerMgmt) < 0) VIR_WARN("Failed to get host power management capabilities"); diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index ba3001ccd0..9df4ae1230 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1220,6 +1220,22 @@ virQEMUDriverGetHostNUMACaps(virQEMUDriverPtr driver) } +virCPUDefPtr +virQEMUDriverGetHostCPU(virQEMUDriverPtr driver) +{ + qemuDriverLock(driver); + + if (!driver->hostcpu) + driver->hostcpu = virCPUProbeHost(virArchFromHost()); + + qemuDriverUnlock(driver); + + virCPUDefRef(driver->hostcpu); + + return driver->hostcpu; +} + + virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver) { size_t i, j; @@ -1272,6 +1288,7 @@ virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver) } caps->host.numa = virQEMUDriverGetHostNUMACaps(driver); + caps->host.cpu = virQEMUDriverGetHostCPU(driver); return g_steal_pointer(&caps); } diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 2d03df9171..d2e0bd97e1 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -267,6 +267,11 @@ struct _virQEMUDriver { */ virCapsHostNUMAPtr hostnuma; + /* Lazy initialized on first use, immutable thereafter. + * Require lock to get the pointer & do optional initialization + */ + virCPUDefPtr hostcpu; + /* Immutable value */ virArch hostarch; @@ -325,6 +330,7 @@ virQEMUDriverConfigPtr virQEMUDriverGetConfig(virQEMUDriverPtr driver); bool virQEMUDriverIsPrivileged(virQEMUDriverPtr driver); virCapsHostNUMAPtr virQEMUDriverGetHostNUMACaps(virQEMUDriverPtr driver); +virCPUDefPtr virQEMUDriverGetHostCPU(virQEMUDriverPtr driver); virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver); virCapsPtr virQEMUDriverGetCapabilities(virQEMUDriverPtr driver, bool refresh); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ae6facc829..1fe310e16c 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -13354,7 +13354,7 @@ qemuConnectCompareCPU(virConnectPtr conn, unsigned int flags) { virQEMUDriverPtr driver = conn->privateData; - g_autoptr(virCaps) caps = NULL; + g_autoptr(virCPUDef) cpu = NULL; bool failIncompatible; virCheckFlags(VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE, @@ -13365,10 +13365,10 @@ qemuConnectCompareCPU(virConnectPtr conn, failIncompatible = !!(flags & VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE); - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) + if (!(cpu = virQEMUDriverGetHostCPU(driver))) return VIR_CPU_COMPARE_ERROR; - return virCPUCompareXML(driver->hostarch, caps->host.cpu, + return virCPUCompareXML(driver->hostarch, cpu, xmlDesc, failIncompatible); } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index cc89ff8571..3a3860b1a3 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5291,12 +5291,13 @@ qemuProcessStartValidateDisks(virDomainObjPtr vm, static int -qemuProcessStartValidateTSC(virDomainObjPtr vm, - virCapsPtr caps) +qemuProcessStartValidateTSC(virQEMUDriverPtr driver, + virDomainObjPtr vm) { size_t i; unsigned long long freq = 0; virHostCPUTscInfoPtr tsc; + g_autoptr(virCPUDef) cpu = NULL; for (i = 0; i < vm->def->clock.ntimers; i++) { virDomainTimerDefPtr timer = vm->def->clock.timers[i]; @@ -5313,12 +5314,13 @@ qemuProcessStartValidateTSC(virDomainObjPtr vm, VIR_DEBUG("Requested TSC frequency %llu Hz", freq); - if (!caps->host.cpu || !caps->host.cpu->tsc) { + cpu = virQEMUDriverGetHostCPU(driver); + if (!cpu || !cpu->tsc) { VIR_DEBUG("Host TSC frequency could not be probed"); return 0; } - tsc = caps->host.cpu->tsc; + tsc = cpu->tsc; VIR_DEBUG("Host TSC frequency %llu Hz, scaling %s", tsc->frequency, virTristateBoolTypeToString(tsc->scaling)); @@ -5356,7 +5358,6 @@ static int qemuProcessStartValidate(virQEMUDriverPtr driver, virDomainObjPtr vm, virQEMUCapsPtr qemuCaps, - virCapsPtr caps, unsigned int flags) { if (!(flags & VIR_QEMU_PROCESS_START_PRETEND)) { @@ -5424,7 +5425,7 @@ qemuProcessStartValidate(virQEMUDriverPtr driver, if (qemuProcessStartValidateDisks(vm, qemuCaps) < 0) return -1; - if (qemuProcessStartValidateTSC(vm, caps) < 0) + if (qemuProcessStartValidateTSC(driver, vm) < 0) return -1; VIR_DEBUG("Checking for any possible (non-fatal) issues"); @@ -5555,7 +5556,6 @@ qemuProcessInit(virQEMUDriverPtr driver, bool migration, unsigned int flags) { - virCapsPtr caps = NULL; qemuDomainObjPrivatePtr priv = vm->privateData; int stopFlags; virCPUDefPtr origCPU = NULL; @@ -5572,9 +5572,6 @@ qemuProcessInit(virQEMUDriverPtr driver, goto cleanup; } - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; - /* in case when the post parse callback failed we need to re-run it on the * old config prior we start the VM */ if (vm->def->postParseFailed) { @@ -5592,7 +5589,7 @@ qemuProcessInit(virQEMUDriverPtr driver, if (qemuDomainUpdateCPU(vm, updatedCPU, &origCPU) < 0) goto cleanup; - if (qemuProcessStartValidate(driver, vm, priv->qemuCaps, caps, flags) < 0) + if (qemuProcessStartValidate(driver, vm, priv->qemuCaps, flags) < 0) goto cleanup; /* Do this upfront, so any part of the startup process can add @@ -5632,7 +5629,6 @@ qemuProcessInit(virQEMUDriverPtr driver, cleanup: virCPUDefFree(origCPU); - virObjectUnref(caps); return ret; stop: @@ -7803,20 +7799,20 @@ static int qemuProcessRefreshCPU(virQEMUDriverPtr driver, virDomainObjPtr vm) { - virCapsPtr caps = virQEMUDriverGetCapabilities(driver, false); qemuDomainObjPrivatePtr priv = vm->privateData; - virCPUDefPtr host = NULL; - virCPUDefPtr cpu = NULL; - int ret = -1; + g_autoptr(virCPUDef) host = NULL; + g_autoptr(virCPUDef) hostmig = NULL; + g_autoptr(virCPUDef) cpu = NULL; - if (!caps) - return -1; + if (!virQEMUCapsGuestIsNative(driver->hostarch, vm->def->os.arch)) + return 0; - if (!virQEMUCapsGuestIsNative(driver->hostarch, vm->def->os.arch) || - !caps->host.cpu || - !vm->def->cpu) { - ret = 0; - goto cleanup; + if (!vm->def->cpu) + return 0; + + if (!(host = virQEMUDriverGetHostCPU(driver))) { + virResetLastError(); + return 0; } /* If the domain with a host-model CPU was started by an old libvirt @@ -7825,20 +7821,20 @@ qemuProcessRefreshCPU(virQEMUDriverPtr driver, * running domain. */ if (vm->def->cpu->mode == VIR_CPU_MODE_HOST_MODEL) { - if (!(host = virCPUCopyMigratable(caps->host.cpu->arch, caps->host.cpu))) - goto cleanup; + if (!(hostmig = virCPUCopyMigratable(host->arch, host))) + return -1; - if (!(cpu = virCPUDefCopyWithoutModel(host)) || - virCPUDefCopyModelFilter(cpu, host, false, + if (!(cpu = virCPUDefCopyWithoutModel(hostmig)) || + virCPUDefCopyModelFilter(cpu, hostmig, false, virQEMUCapsCPUFilterFeatures, - &caps->host.cpu->arch) < 0) - goto cleanup; + &host->arch) < 0) + return -1; if (virCPUUpdate(vm->def->os.arch, vm->def->cpu, cpu) < 0) - goto cleanup; + return -1; if (qemuProcessUpdateCPU(driver, vm, QEMU_ASYNC_JOB_NONE) < 0) - goto cleanup; + return -1; } else if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION)) { /* We only try to fix CPUs when the libvirt/QEMU combo used to start * the domain did not know about query-cpu-model-expansion in which @@ -7846,16 +7842,10 @@ qemuProcessRefreshCPU(virQEMUDriverPtr driver, * doesn't know about. */ if (qemuDomainFixupCPUs(vm, &priv->origCPU) < 0) - goto cleanup; + return -1; } - ret = 0; - - cleanup: - virCPUDefFree(cpu); - virCPUDefFree(host); - virObjectUnref(caps); - return ret; + return 0; } diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c index 94e5831706..a4a443b1d6 100644 --- a/tests/domaincapstest.c +++ b/tests/domaincapstest.c @@ -54,8 +54,7 @@ fillStringValues(virDomainCapsStringValuesPtr values, ...) # include "testutilshostcpus.h" static int -fakeHostCPU(virCapsPtr caps, - virArch arch) +fakeHostCPU(virArch arch) { virCPUDefPtr cpu; @@ -66,7 +65,7 @@ fakeHostCPU(virCapsPtr caps, return -1; } - qemuTestSetHostCPU(caps, cpu); + qemuTestSetHostCPU(NULL, arch, cpu); return 0; } @@ -80,17 +79,15 @@ fillQemuCaps(virDomainCapsPtr domCaps, { int ret = -1; char *path = NULL; - virCapsPtr caps = NULL; virQEMUCapsPtr qemuCaps = NULL; virDomainCapsLoaderPtr loader = &domCaps->os.loader; virDomainVirtType virtType; - if (!(caps = virCapabilitiesNew(domCaps->arch, false, false)) || - fakeHostCPU(caps, domCaps->arch) < 0) + if (fakeHostCPU(domCaps->arch) < 0) goto cleanup; path = g_strdup_printf("%s/%s.%s.xml", TEST_QEMU_CAPS_PATH, name, arch); - if (!(qemuCaps = qemuTestParseCapabilities(caps, path))) + if (!(qemuCaps = qemuTestParseCapabilitiesArch(domCaps->arch, path))) goto cleanup; if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) @@ -106,7 +103,7 @@ fillQemuCaps(virDomainCapsPtr domCaps, if (!domCaps->machine) domCaps->machine = g_strdup(virQEMUCapsGetPreferredMachine(qemuCaps, virtType)); - if (virQEMUCapsFillDomainCaps(qemuCaps, caps->host.arch, domCaps, + if (virQEMUCapsFillDomainCaps(qemuCaps, domCaps->arch, domCaps, false, cfg->firmwares, cfg->nfirmwares) < 0) @@ -134,7 +131,6 @@ fillQemuCaps(virDomainCapsPtr domCaps, ret = 0; cleanup: - virObjectUnref(caps); virObjectUnref(qemuCaps); VIR_FREE(path); return ret; diff --git a/tests/qemucapabilitiestest.c b/tests/qemucapabilitiestest.c index 3d3e6b6d57..b38c0f6f65 100644 --- a/tests/qemucapabilitiestest.c +++ b/tests/qemucapabilitiestest.c @@ -144,7 +144,6 @@ testQemuCapsCopy(const void *opaque) int ret = -1; const testQemuData *data = opaque; char *capsFile = NULL; - virCapsPtr caps = NULL; virQEMUCapsPtr orig = NULL; virQEMUCapsPtr copy = NULL; char *actual = NULL; @@ -153,11 +152,8 @@ testQemuCapsCopy(const void *opaque) data->outputDir, data->prefix, data->version, data->archName); - if (!(caps = virCapabilitiesNew(virArchFromString(data->archName), - false, false))) - goto cleanup; - - if (!(orig = qemuTestParseCapabilities(caps, capsFile))) + if (!(orig = qemuTestParseCapabilitiesArch( + virArchFromString(data->archName), capsFile))) goto cleanup; if (!(copy = virQEMUCapsNewCopy(orig))) @@ -173,7 +169,6 @@ testQemuCapsCopy(const void *opaque) cleanup: VIR_FREE(capsFile); - virObjectUnref(caps); virObjectUnref(orig); virObjectUnref(copy); VIR_FREE(actual); diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index fe8fa776be..ba4a92ec0a 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1733,7 +1733,7 @@ mymain(void) DO_TEST_FAILURE("cpu-s390-features", QEMU_CAPS_KVM); qemuTestSetHostArch(&driver, VIR_ARCH_NONE); - qemuTestSetHostCPU(driver.caps, cpuHaswell); + qemuTestSetHostCPU(&driver, driver.hostarch, cpuHaswell); DO_TEST("cpu-Haswell", QEMU_CAPS_KVM); DO_TEST("cpu-Haswell2", QEMU_CAPS_KVM); DO_TEST("cpu-Haswell3", QEMU_CAPS_KVM); @@ -1744,7 +1744,7 @@ mymain(void) DO_TEST_CAPS_VER("cpu-tsc-frequency", "4.0.0"); DO_TEST_CAPS_VER("cpu-translation", "4.0.0"); DO_TEST_CAPS_LATEST("cpu-translation"); - qemuTestSetHostCPU(driver.caps, NULL); + qemuTestSetHostCPU(&driver, driver.hostarch, NULL); DO_TEST("encrypted-disk", QEMU_CAPS_QCOW2_LUKS, QEMU_CAPS_OBJECT_SECRET); DO_TEST("encrypted-disk-usage", QEMU_CAPS_QCOW2_LUKS, QEMU_CAPS_OBJECT_SECRET); @@ -1873,12 +1873,12 @@ mymain(void) QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE, QEMU_CAPS_KVM); - qemuTestSetHostCPU(driver.caps, cpuPower9); + qemuTestSetHostCPU(&driver, driver.hostarch, cpuPower9); DO_TEST("pseries-cpu-compat-power9", QEMU_CAPS_KVM, QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE, QEMU_CAPS_DEVICE_SPAPR_VTY); - qemuTestSetHostCPU(driver.caps, NULL); + qemuTestSetHostCPU(&driver, driver.hostarch, NULL); qemuTestSetHostArch(&driver, VIR_ARCH_NONE); diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index fb9b85747a..6fd121855d 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -205,14 +205,6 @@ virCapsPtr testQemuCapsInit(void) caps->host.secModels[0].model = g_strdup("none"); caps->host.secModels[0].doi = g_strdup("0"); - if (!(cpuDefault = virCPUDefCopy(&cpuDefaultData)) || - !(cpuHaswell = virCPUDefCopy(&cpuHaswellData)) || - !(cpuPower8 = virCPUDefCopy(&cpuPower8Data)) || - !(cpuPower9 = virCPUDefCopy(&cpuPower9Data))) - goto cleanup; - - qemuTestSetHostCPU(caps, NULL); - if (!(caps->host.numa = virCapabilitiesHostNUMANewHost())) goto cleanup; @@ -237,9 +229,6 @@ virCapsPtr testQemuCapsInit(void) cleanup: caps->host.cpu = NULL; - virCPUDefFree(cpuDefault); - virCPUDefFree(cpuHaswell); - virCPUDefFree(cpuPower8); virObjectUnref(caps); return NULL; } @@ -255,16 +244,15 @@ qemuTestSetHostArch(virQEMUDriverPtr driver, virTestHostArch = arch; driver->hostarch = virArchFromHost(); driver->caps->host.arch = virArchFromHost(); - qemuTestSetHostCPU(driver->caps, NULL); + qemuTestSetHostCPU(driver, arch, NULL); } void -qemuTestSetHostCPU(virCapsPtr caps, +qemuTestSetHostCPU(virQEMUDriverPtr driver, + virArch arch, virCPUDefPtr cpu) { - virArch arch = caps->host.arch; - if (!cpu) { if (ARCH_IS_X86(arch)) cpu = cpuDefault; @@ -274,11 +262,19 @@ qemuTestSetHostCPU(virCapsPtr caps, unsetenv("VIR_TEST_MOCK_FAKE_HOST_CPU"); if (cpu) { - caps->host.arch = cpu->arch; if (cpu->model) setenv("VIR_TEST_MOCK_FAKE_HOST_CPU", cpu->model, 1); } - caps->host.cpu = cpu; + if (driver) { + if (cpu) + driver->caps->host.arch = cpu->arch; + driver->caps->host.cpu = cpu; + + virCPUDefFree(driver->hostcpu); + if (cpu) + virCPUDefRef(cpu); + driver->hostcpu = cpu; + } } @@ -300,17 +296,6 @@ qemuTestParseCapabilitiesArch(virArch arch, } -virQEMUCapsPtr -qemuTestParseCapabilities(virCapsPtr caps, - const char *capsFile) -{ - if (!caps) - return NULL; - - return qemuTestParseCapabilitiesArch(caps->host.arch, capsFile); -} - - void qemuTestDriverFree(virQEMUDriver *driver) { virMutexDestroy(&driver->lock); @@ -382,6 +367,12 @@ int qemuTestDriverInit(virQEMUDriver *driver) memset(driver, 0, sizeof(*driver)); + if (!(cpuDefault = virCPUDefCopy(&cpuDefaultData)) || + !(cpuHaswell = virCPUDefCopy(&cpuHaswellData)) || + !(cpuPower8 = virCPUDefCopy(&cpuPower8Data)) || + !(cpuPower9 = virCPUDefCopy(&cpuPower9Data))) + return -1; + if (virMutexInit(&driver->lock) < 0) return -1; @@ -439,6 +430,8 @@ int qemuTestDriverInit(virQEMUDriver *driver) if (!(driver->securityManager = virSecurityManagerNewStack(mgr))) goto error; + qemuTestSetHostCPU(driver, driver->hostarch, NULL); + return 0; error: diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h index 8dcc930ac3..edee6e450c 100644 --- a/tests/testutilsqemu.h +++ b/tests/testutilsqemu.h @@ -72,8 +72,6 @@ virDomainXMLOptionPtr testQemuXMLConfInit(void); virQEMUCapsPtr qemuTestParseCapabilitiesArch(virArch arch, const char *capsFile); -virQEMUCapsPtr qemuTestParseCapabilities(virCapsPtr caps, - const char *capsFile); extern virCPUDefPtr cpuDefault; extern virCPUDefPtr cpuHaswell; @@ -82,7 +80,8 @@ extern virCPUDefPtr cpuPower9; void qemuTestSetHostArch(virQEMUDriverPtr driver, virArch arch); -void qemuTestSetHostCPU(virCapsPtr caps, +void qemuTestSetHostCPU(virQEMUDriverPtr driver, + virArch arch, virCPUDefPtr cpu); int qemuTestDriverInit(virQEMUDriver *driver); -- 2.23.0

We always refresh the capabilities object when using virResctrlInfo during process startup. This is undesirable overhead, because we can just directly create a virResctrlInfo instead. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/qemu/qemu_process.c | 24 ++++++++---------------- src/util/virresctrl.h | 2 ++ 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 3a3860b1a3..2b35680abc 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2724,29 +2724,24 @@ qemuProcessSetupEmulator(virDomainObjPtr vm) static int -qemuProcessResctrlCreate(virQEMUDriverPtr driver, - virDomainObjPtr vm) +qemuProcessResctrlCreate(virDomainObjPtr vm) { - int ret = -1; size_t i = 0; - virCapsPtr caps = NULL; qemuDomainObjPrivatePtr priv = vm->privateData; + g_autoptr(virResctrlInfo) resctrl = NULL; if (!vm->def->nresctrls) return 0; - /* Force capability refresh since resctrl info can change - * XXX: move cache info into virresctrl so caps are not needed */ - caps = virQEMUDriverGetCapabilities(driver, true); - if (!caps) + if (!(resctrl = virResctrlInfoNew())) return -1; for (i = 0; i < vm->def->nresctrls; i++) { size_t j = 0; - if (virResctrlAllocCreate(caps->host.resctrl, + if (virResctrlAllocCreate(resctrl, vm->def->resctrls[i]->alloc, priv->machineName) < 0) - goto cleanup; + return -1; for (j = 0; j < vm->def->resctrls[i]->nmonitors; j++) { virDomainResctrlMonDefPtr mon = NULL; @@ -2754,14 +2749,11 @@ qemuProcessResctrlCreate(virQEMUDriverPtr driver, mon = vm->def->resctrls[i]->monitors[j]; if (virResctrlMonitorCreate(mon->instance, priv->machineName) < 0) - goto cleanup; + return -1; } } - ret = 0; - cleanup: - virObjectUnref(caps); - return ret; + return 0; } @@ -6882,7 +6874,7 @@ qemuProcessLaunch(virConnectPtr conn, goto cleanup; VIR_DEBUG("Setting up resctrl"); - if (qemuProcessResctrlCreate(driver, vm) < 0) + if (qemuProcessResctrlCreate(vm) < 0) goto cleanup; VIR_DEBUG("Setting up managed PR daemon"); diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h index 3dd7c96348..759320d0fd 100644 --- a/src/util/virresctrl.h +++ b/src/util/virresctrl.h @@ -100,6 +100,8 @@ typedef virResctrlInfo *virResctrlInfoPtr; virResctrlInfoPtr virResctrlInfoNew(void); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virResctrlInfo, virObjectUnref); + int virResctrlInfoGetCache(virResctrlInfoPtr resctrl, unsigned int level, -- 2.23.0

Now that nearly all internal APIs use the QEMU capabilities or other QEMU driver data directly, there's no compelling benefit to create virCapsPtr at driver startup. Skipping this means we don't probe capabilities for all 30 system emulator targets at startup, only those emulators which are referenced by an XML doc. This massively improves libvirtd startup time when the capabilities cache is not populated. It even improves startup time when the cache is up to date, as we don't bother to load files from the cache until we need them. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/qemu/qemu_conf.c | 13 +++++++------ src/qemu/qemu_driver.c | 3 --- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 9df4ae1230..c24c99d129 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1318,13 +1318,14 @@ virCapsPtr virQEMUDriverGetCapabilities(virQEMUDriverPtr driver, driver->caps = caps; } else { qemuDriverLock(driver); - } - if (driver->caps->nguests == 0 && !refresh) { - VIR_DEBUG("Capabilities didn't detect any guests. Forcing a " - "refresh."); - qemuDriverUnlock(driver); - return virQEMUDriverGetCapabilities(driver, true); + if (driver->caps == NULL || + driver->caps->nguests == 0) { + VIR_DEBUG("Capabilities didn't detect any guests. Forcing a " + "refresh."); + qemuDriverUnlock(driver); + return virQEMUDriverGetCapabilities(driver, true); + } } ret = virObjectRef(driver->caps); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1fe310e16c..f50af3ee94 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -907,9 +907,6 @@ qemuStateInitialize(bool privileged, if (!qemu_driver->qemuCapsCache) goto error; - if ((qemu_driver->caps = virQEMUDriverCreateCapabilities(qemu_driver)) == NULL) - goto error; - if (!(sec_managers = qemuSecurityGetNested(qemu_driver->securityManager))) goto error; -- 2.23.0

On 12/4/19 3:20 PM, Daniel P. Berrangé wrote:
The virCapsPtr object is a serious source of performance problems for the QEMU driver, because populating it means probing every QEMU system emulator binary installed on the host.
This is is crazy because parsing any single XML document only ever needs information about a single QEMU binary.
We've already done a great job of untangling stuff with the post-parse and validation functions, but the job was never quite finished. This series tackles the last pieces so that parsing & formatting XML will never use the virCapsPtr object directly. Some of the virt drivers will still use virCapsPtr in their private callbacks, but the QEMU driver will instead use the QEMU emulator capabilities cache directly.
The first ten patches are the key bits of work to remove use of the virCapsPtr parameter from domain XML APIs.
The next thirteen patches remove the (now unused) virCapsPtr parameter from the domain XML APIs & their callers.
The final six patches help various QEMU driver APIs stop relying on the virCapsPtr, so that it is no longer even created at startup.
This has a nice benefit on libvirtd startup tie when all 30 QEMU emulators are installed, reducing it from 4 seconds down to a fraction of a second.
More work is still needed to follow on from this...
A couple of places in the QEMU driver still use virCapsPtr
- The virConnectGetVersion API. - The virNodeGetSecurityModel API. - virDomainGetResctrlMonData API.
In all cases we just need to move to store the relevant data directly in virQEMUDriverPtr, and not use the virCaps.
next, apps can use virDomainGetCapabilities to fetch info about a specific QEMU binary they care about to avoid the cost of the virConnectGetCapabilities API.
There are still times when apps need info in virConnectGetCapabilities and this will annoyingly probe all QEMU binaries, even though the app doesn't want the guest info.
virConnectGetCapabilities is one of our very early APIs which now flags parameter, so this problem is unfixable in that API.
I'm thus included to introduce a new virNodeGetCapabilities that is specifically only returning information about the host hypervisor. Essentially the <capabilities> schema, but only the <host> sub-tree.
I do, however, wonder if even this is overkill & we should aim for a much more fine grained way for reporting host capabilities.
eg if an app wants the host CPU, do they really want to pay the penality to probe host cache nformation, or NUMA topology and vica-verca.
I'm not sure what the right kind of tradeoff here is, whether we should try individual APIs, or have one API and a set of flags to control what info is filled in.
Daniel P. Berrangé (30): qemu: cache host arch separately from virCapsPtr qemu: add machines & arch to fake test capabilities cache conf: sanitize virDomainSaveStatus & virDomainSaveConfig APIs conf: sanitize virDomainObjFormat & virDomainDefFormat* APIs conf: pass in default architecture via domain XML options conf: move virt type / os type / arch validation to post-parse conf: don't use passed in caps in post parse method conf: pass netprefix in the domain parser config struct conf: move seclabel validation into post-parse phase conf: pass default sec model in parser config conf: drop virCapsPtr param from assign addresses callback conf: drop virCapsPtr param from basic post parse callback conf: drop virCapsPtr param from post parse data alloc callback conf: drop virCapsPtr param from post parse callback conf: drop virCapsPtr param from device post parse callback conf: drop virCapsPtr param from domain validate callback conf: drop virCapsPtr param from domain formatting APIs conf: drop virCapsPtr param from domain post parse & validate APIs conf: drop virCapsPtr param from domain parse APIs conf: drop virCapsPtr param from domain APIs for copying config conf: drop virCapsPtr param from APIs for saving domains conf: drop virCapsPtr param from domain obj list APIs conf: drop virCapsPtr param from snapshot & checkpoint APIs qemu: drop virCapsPtr param & vars from many APIs conf: move NUMA capabilities into self contained object qemu: use NUMA capabilities object directly conf: make virCPUDef into a ref counted struct qemu: use host CPU object directly qemu: directly create virResctrlInfo ignoring capabilities qemu: stop creating capabilities at driver startup
docs/formatdomain.html.in | 6 +- src/bhyve/bhyve_domain.c | 16 +- src/bhyve/bhyve_driver.c | 46 +- src/bhyve/bhyve_process.c | 22 +- src/conf/capabilities.c | 217 +++++--- src/conf/capabilities.h | 34 +- src/conf/checkpoint_conf.c | 21 +- src/conf/checkpoint_conf.h | 2 - src/conf/cpu_conf.c | 29 +- src/conf/cpu_conf.h | 4 + src/conf/domain_conf.c | 404 ++++++-------- src/conf/domain_conf.h | 84 ++- src/conf/snapshot_conf.c | 28 +- src/conf/snapshot_conf.h | 3 - src/conf/virconftypes.h | 3 + src/conf/virdomainobjlist.c | 9 +- src/conf/virdomainobjlist.h | 1 - src/cpu/cpu.c | 3 +- src/cpu/cpu_arm.c | 5 +- src/cpu/cpu_ppc64.c | 3 +- src/cpu/cpu_x86.c | 6 +- src/esx/esx_driver.c | 14 +- src/hyperv/hyperv_driver.c | 1 + src/libvirt_private.syms | 18 +- src/libxl/libxl_capabilities.c | 23 +- src/libxl/libxl_conf.c | 3 +- src/libxl/libxl_conf.h | 2 +- src/libxl/libxl_domain.c | 37 +- src/libxl/libxl_driver.c | 83 ++- src/libxl/libxl_migration.c | 20 +- src/libxl/xen_xl.c | 13 +- src/libxl/xen_xm.c | 2 +- src/lxc/lxc_conf.c | 9 +- src/lxc/lxc_conf.h | 2 +- src/lxc/lxc_controller.c | 44 +- src/lxc/lxc_domain.c | 13 +- src/lxc/lxc_driver.c | 98 ++-- src/lxc/lxc_native.c | 4 +- src/lxc/lxc_process.c | 20 +- src/openvz/openvz_conf.c | 62 ++- src/openvz/openvz_conf.h | 1 + src/openvz/openvz_driver.c | 64 +-- src/phyp/phyp_driver.c | 26 +- src/qemu/qemu_capabilities.c | 176 ++++--- src/qemu/qemu_capabilities.h | 12 +- src/qemu/qemu_capspriv.h | 10 + src/qemu/qemu_checkpoint.c | 32 +- src/qemu/qemu_checkpoint.h | 1 - src/qemu/qemu_command.c | 6 +- src/qemu/qemu_conf.c | 57 +- src/qemu/qemu_conf.h | 18 +- src/qemu/qemu_domain.c | 108 ++-- src/qemu/qemu_domain.h | 1 - src/qemu/qemu_driver.c | 293 ++++------- src/qemu/qemu_hotplug.c | 8 +- src/qemu/qemu_migration.c | 36 +- src/qemu/qemu_migration_cookie.c | 8 +- src/qemu/qemu_process.c | 196 +++---- src/security/virt-aa-helper.c | 2 +- src/test/test_driver.c | 45 +- src/util/virresctrl.h | 2 + src/vbox/vbox_common.c | 16 +- src/vmware/vmware_conf.c | 2 +- src/vmware/vmware_driver.c | 25 +- src/vmx/vmx.c | 23 +- src/vmx/vmx.h | 2 +- src/vz/vz_driver.c | 29 +- tests/Makefile.am | 17 +- tests/bhyveargv2xmltest.c | 2 +- tests/bhyvexml2argvtest.c | 2 +- tests/cputest.c | 11 +- tests/domaincapstest.c | 14 +- tests/domainconftest.c | 2 +- tests/libxlxml2domconfigtest.c | 22 +- tests/lxcconf2xmltest.c | 17 +- tests/lxcxml2xmltest.c | 13 +- tests/openvzutilstest.c | 8 +- tests/qemuagenttest.c | 2 +- tests/qemublocktest.c | 2 +- tests/qemucapabilitiestest.c | 9 +- tests/qemudomaincheckpointxml2xmltest.c | 4 +- tests/qemudomainsnapshotxml2xmltest.c | 4 +- tests/qemuhotplugtest.c | 11 +- tests/qemumemlocktest.c | 6 +- tests/qemusecuritytest.c | 1 - tests/qemuxml2argvtest.c | 35 +- tests/qemuxml2xmltest.c | 4 +- tests/securityselinuxlabeltest.c | 2 +- tests/testutils.c | 39 +- tests/testutils.h | 5 +- tests/testutilslxc.c | 34 +- tests/testutilslxc.h | 4 + tests/testutilsqemu.c | 670 +++++++----------------- tests/testutilsqemu.h | 9 +- tests/testutilsxen.c | 34 +- tests/testutilsxen.h | 9 +- tests/vircaps2xmltest.c | 6 +- tests/vircapstest.c | 11 +- tests/vmx2xmltest.c | 4 +- tests/xlconfigtest.c | 27 +- tests/xmconfigtest.c | 23 +- tests/xml2vmxtest.c | 4 +- 102 files changed, 1687 insertions(+), 1993 deletions(-)
Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Michal
participants (3)
-
Cole Robinson
-
Daniel P. Berrangé
-
Michal Privoznik