Re: [PATCH 3/3] conf: capabilities: Refactor API for setting guest capability features

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Nov 12, 2019 at 02:33:46PM +0100, Peter Krempa wrote:
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:

consider using 'WithToggle' instead of Toggle

Jano

+ * @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

Attachment: signature.asc
Description: PGP signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux