Remove the need to pass around strings and switch to the enum values instead. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/conf/capabilities.c | 68 ++++++++++++++++++---------------- src/conf/capabilities.h | 11 ++++-- src/libvirt_private.syms | 1 + src/libxl/libxl_capabilities.c | 46 +++++++---------------- src/qemu/qemu_capabilities.c | 34 +++++++---------- src/test/test_driver.c | 6 +-- tests/testutilsqemu.c | 6 +-- 7 files changed, 76 insertions(+), 96 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 1666e1e496..6e5dde7394 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; + virCapabilitiesAddGuestFeatureInternal(guest, feature, false, false); +} - if (togglesRequired) { - feature->defaultOn = virTristateSwitchFromBool(defaultOn); - feature->toggle = virTristateBoolFromBool(toggle); - } - return feature; +/** + * virCapabilitiesAddGuestFeatureToggle: + * @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 +virCapabilitiesAddGuestFeatureToggle(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..2d33adddeb 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 +virCapabilitiesAddGuestFeatureToggle(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 94509d6f43..f764837688 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -46,6 +46,7 @@ virAccessPermStorageVolTypeToString; virCapabilitiesAddGuest; virCapabilitiesAddGuestDomain; virCapabilitiesAddGuestFeature; +virCapabilitiesAddGuestFeatureToggle; virCapabilitiesAddHostFeature; virCapabilitiesAddHostMigrateTransport; virCapabilitiesAddHostNUMACell; diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c index 3b88121dca..ce1c63d518 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; - - if (virCapabilitiesAddGuestFeature(guest, "apic", - 1, - 0) == NULL) - return -1; + virCapabilitiesAddGuestFeatureToggle(guest, VIR_CAPS_GUEST_FEATURE_TYPE_ACPI, + true, true); + + virCapabilitiesAddGuestFeatureToggle(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; + virCapabilitiesAddGuestFeatureToggle(guest, VIR_CAPS_GUEST_FEATURE_TYPE_HAP, + true, true); } } diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index fc6473651c..ab14e0fdfe 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -850,14 +850,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); + virCapabilitiesAddGuestFeatureToggle(guest, VIR_CAPS_GUEST_FEATURE_TYPE_DISKSNAPSHOT, + true, false); if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_QEMU, @@ -878,20 +874,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)) + virCapabilitiesAddGuestFeatureToggle(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)) + virCapabilitiesAddGuestFeatureToggle(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 6c1c56d446..d1a83ffa3c 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 34a6bd2653..ca35e4ee75 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; -- 2.23.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list