diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 67776b4fd3..5c41a53051 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -557,49 +557,55 @@ static const struct virCapsGuestFeatureInfo virCapsGuestFeatureInfos[VIR_CAPS_GU }; +static void +virCapabilitiesAddGuestFeatureInternal(virCapsGuestPtr guest, + virCapsGuestFeatureType feature, + bool defaultOn, + bool toggle) +{ + guest->features[feature].present = true; + + if (virCapsGuestFeatureInfos[feature].togglesRequired) { + guest->features[feature].defaultOn = virTristateSwitchFromBool(defaultOn); + guest->features[feature].toggle = virTristateBoolFromBool(toggle); + } +} + + /** * virCapabilitiesAddGuestFeature: * @guest: guest to associate feature with - * @name: name of feature ('pae', 'acpi', 'apic') - * @defaultOn: true if it defaults to on - * @toggle: true if its state can be toggled + * @feature: feature to add * * Registers a feature for a guest domain. */ -virCapsGuestFeaturePtr +void virCapabilitiesAddGuestFeature(virCapsGuestPtr guest, - const char *name, - bool defaultOn, - bool toggle) + virCapsGuestFeatureType feature) { - virCapsGuestFeaturePtr feature = NULL; - bool togglesRequired = false; - size_t i; - - for (i = 0; i < VIR_CAPS_GUEST_FEATURE_TYPE_LAST; i++) { - if (STRNEQ(name, virCapsGuestFeatureInfos[i].name)) - continue; - - feature = guest->features + i; - togglesRequired = virCapsGuestFeatureInfos[i].togglesRequired; - } - - if (!feature) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("invalid feature '%s'"), name); - return NULL; - } - - feature->present = true; - - if (togglesRequired) { - feature->defaultOn = virTristateSwitchFromBool(defaultOn); - feature->toggle = virTristateBoolFromBool(toggle); - } - - return feature; + virCapabilitiesAddGuestFeatureInternal(guest, feature, false, false); } + +/** + * virCapabilitiesAddGuestFeatureWithToggle: + * @guest: guest to associate feature with + * @feature: feature to add + * @defaultOn: true if it defaults to on + * @toggle: true if its state can be toggled + * + * Registers a feature with toggles for a guest domain. + */ +void +virCapabilitiesAddGuestFeatureWithToggle(virCapsGuestPtr guest, + virCapsGuestFeatureType feature, + bool defaultOn, + bool toggle) +{ + virCapabilitiesAddGuestFeatureInternal(guest, feature, defaultOn, toggle); +} + + /** * virCapabilitiesHostSecModelAddBaseLabel * @secmodel: Security model to add a base label for diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index dd972b1a67..8a7137d7eb 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -283,11 +283,14 @@ virCapabilitiesAddGuestDomain(virCapsGuestPtr guest, int nmachines, virCapsGuestMachinePtr *machines); -virCapsGuestFeaturePtr +void virCapabilitiesAddGuestFeature(virCapsGuestPtr guest, - const char *name, - bool defaultOn, - bool toggle); + virCapsGuestFeatureType feature); +void +virCapabilitiesAddGuestFeatureWithToggle(virCapsGuestPtr guest, + virCapsGuestFeatureType feature, + bool defaultOn, + bool toggle); int virCapabilitiesAddStoragePool(virCapsPtr caps, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 5787338e92..4d0d03c580 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -46,6 +46,7 @@ virAccessPermStorageVolTypeToString; virCapabilitiesAddGuest; virCapabilitiesAddGuestDomain; virCapabilitiesAddGuestFeature; +virCapabilitiesAddGuestFeatureWithToggle; virCapabilitiesAddHostFeature; virCapabilitiesAddHostMigrateTransport; virCapabilitiesAddHostNUMACell; diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c index 3b88121dca..fe792e9a82 100644 --- a/src/libxl/libxl_capabilities.c +++ b/src/libxl/libxl_capabilities.c @@ -547,46 +547,26 @@ libxlCapsInitGuests(libxl_ctx *ctx, virCapsPtr caps) NULL) == NULL) return -1; - if (guest_archs[i].pae && - virCapabilitiesAddGuestFeature(guest, - "pae", - 1, - 0) == NULL) - return -1; + if (guest_archs[i].pae) + virCapabilitiesAddGuestFeature(guest, VIR_CAPS_GUEST_FEATURE_TYPE_PAE); - if (guest_archs[i].nonpae && - virCapabilitiesAddGuestFeature(guest, - "nonpae", - 1, - 0) == NULL) - return -1; + if (guest_archs[i].nonpae) + virCapabilitiesAddGuestFeature(guest, VIR_CAPS_GUEST_FEATURE_TYPE_NONPAE); - if (guest_archs[i].ia64_be && - virCapabilitiesAddGuestFeature(guest, - "ia64_be", - 1, - 0) == NULL) - return -1; + if (guest_archs[i].ia64_be) + virCapabilitiesAddGuestFeature(guest, VIR_CAPS_GUEST_FEATURE_TYPE_IA64_BE); if (guest_archs[i].hvm) { - if (virCapabilitiesAddGuestFeature(guest, - "acpi", - 1, - 1) == NULL) - return -1; + virCapabilitiesAddGuestFeatureWithToggle(guest, VIR_CAPS_GUEST_FEATURE_TYPE_ACPI, + true, true); - if (virCapabilitiesAddGuestFeature(guest, "apic", - 1, - 0) == NULL) - return -1; + virCapabilitiesAddGuestFeatureWithToggle(guest, VIR_CAPS_GUEST_FEATURE_TYPE_APIC, + true, false); } if (guest_archs[i].hvm || guest_archs[i].pvh) { - if (virCapabilitiesAddGuestFeature(guest, - "hap", - 1, - 1) == NULL) - return -1; + virCapabilitiesAddGuestFeatureWithToggle(guest, VIR_CAPS_GUEST_FEATURE_TYPE_HAP, + true, true); } } diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 7eb92b68af..b03abcd0d3 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -849,14 +849,10 @@ virQEMUCapsInitGuestFromBinary(virCapsPtr caps, /* CPU selection is always available, because all QEMU versions * we support can use at least '-cpu host' */ - if (!virCapabilitiesAddGuestFeature(guest, "cpuselection", true, false)) - goto cleanup; - - if (!virCapabilitiesAddGuestFeature(guest, "deviceboot", true, false)) - goto cleanup; - - if (!virCapabilitiesAddGuestFeature(guest, "disksnapshot", true, false)) - goto cleanup; + virCapabilitiesAddGuestFeature(guest, VIR_CAPS_GUEST_FEATURE_TYPE_CPUSELECTION); + virCapabilitiesAddGuestFeature(guest, VIR_CAPS_GUEST_FEATURE_TYPE_DEVICEBOOT); + virCapabilitiesAddGuestFeatureWithToggle(guest, VIR_CAPS_GUEST_FEATURE_TYPE_DISKSNAPSHOT, + true, false); if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_QEMU, @@ -877,20 +873,18 @@ virQEMUCapsInitGuestFromBinary(virCapsPtr caps, } } - if ((ARCH_IS_X86(guestarch) || guestarch == VIR_ARCH_AARCH64) && - virCapabilitiesAddGuestFeature(guest, "acpi", true, true) == NULL) { - goto cleanup; - } + if ((ARCH_IS_X86(guestarch) || guestarch == VIR_ARCH_AARCH64)) + virCapabilitiesAddGuestFeatureWithToggle(guest, VIR_CAPS_GUEST_FEATURE_TYPE_ACPI, + true, true); - if (ARCH_IS_X86(guestarch) && - virCapabilitiesAddGuestFeature(guest, "apic", true, false) == NULL) { - goto cleanup; - } + if (ARCH_IS_X86(guestarch)) + virCapabilitiesAddGuestFeatureWithToggle(guest, VIR_CAPS_GUEST_FEATURE_TYPE_APIC, + true, false); - if ((guestarch == VIR_ARCH_I686) && - (virCapabilitiesAddGuestFeature(guest, "pae", true, false) == NULL || - virCapabilitiesAddGuestFeature(guest, "nonpae", true, false) == NULL)) - goto cleanup; + if (guestarch == VIR_ARCH_I686) { + virCapabilitiesAddGuestFeature(guest, VIR_CAPS_GUEST_FEATURE_TYPE_PAE); + virCapabilitiesAddGuestFeature(guest, VIR_CAPS_GUEST_FEATURE_TYPE_NONPAE); + } ret = 0; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 331f721502..5883722d60 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -350,10 +350,8 @@ testBuildCapabilities(virConnectPtr conn) NULL) == NULL) goto error; - if (virCapabilitiesAddGuestFeature(guest, "pae", true, true) == NULL) - goto error; - if (virCapabilitiesAddGuestFeature(guest, "nonpae", true, true) == NULL) - goto error; + virCapabilitiesAddGuestFeature(guest, VIR_CAPS_GUEST_FEATURE_TYPE_PAE); + virCapabilitiesAddGuestFeature(guest, VIR_CAPS_GUEST_FEATURE_TYPE_NONPAE); } caps->host.nsecModels = 1; diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 1eaa56ccb3..6fe385e545 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -110,8 +110,7 @@ testQemuAddI686Guest(virCapsPtr caps) machines))) goto error; - if (!virCapabilitiesAddGuestFeature(guest, "cpuselection", true, false)) - goto error; + virCapabilitiesAddGuestFeature(guest, VIR_CAPS_GUEST_FEATURE_TYPE_CPUSELECTION); machines = NULL; @@ -161,8 +160,7 @@ testQemuAddX86_64Guest(virCapsPtr caps) machines))) goto error; - if (!virCapabilitiesAddGuestFeature(guest, "cpuselection", true, false)) - goto error; + virCapabilitiesAddGuestFeature(guest, VIR_CAPS_GUEST_FEATURE_TYPE_CPUSELECTION); machines = NULL;