[PATCH v2 1/5] qemu: Split virQEMUCapsInitArchQMPBasic()

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

 



Instead of having a single function that probes the
architecture from the monitor and then sets a bunch of
basic capabilities based on it, have a separate function
for each part: virQEMUCapsInitQMPArch() only sets the
architecture, and virQEMUCapsInitQMPBasicArch() only sets
the capabilities.

This split will be useful later on, when we will want to
set basic capabilities from the test suite without having
to go through the pain of mocking the monitor.
---
This is 99% pure code motion; however, an early 'return -1'
has been converted to the equivalent 'goto cleanup'.

 src/qemu/qemu_capabilities.c | 42 +++++++++++++++++++++++++++++++-----------
 1 file changed, 31 insertions(+), 11 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index f51141b..eec2ee4 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -4177,18 +4177,25 @@ virQEMUCapsInitQMPBasic(virQEMUCapsPtr qemuCaps)
     virQEMUCapsSet(qemuCaps, QEMU_CAPS_DISPLAY);
 }
 
-/* Capabilities that are architecture depending
- * initialized for QEMU.
+
+/**
+ * virQEMUCapsInitQMPArch:
+ * @qemuCaps: QEMU capabilities
+ * @mon: QEMU monitor
+ *
+ * Initialize the architecture for @qemuCaps by asking @mon.
+ *
+ * Returns: 0 on success, <0 on failure
  */
 static int
-virQEMUCapsInitArchQMPBasic(virQEMUCapsPtr qemuCaps,
+virQEMUCapsInitQMPArch(virQEMUCapsPtr qemuCaps,
                             qemuMonitorPtr mon)
 {
     char *archstr = NULL;
     int ret = -1;
 
     if (!(archstr = qemuMonitorGetTargetArch(mon)))
-        return -1;
+        goto cleanup;
 
     if ((qemuCaps->arch = virQEMUCapsArchFromString(archstr)) == VIR_ARCH_NONE) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -4196,18 +4203,29 @@ virQEMUCapsInitArchQMPBasic(virQEMUCapsPtr qemuCaps,
         goto cleanup;
     }
 
+    ret = 0;
+
+ cleanup:
+    VIR_FREE(archstr);
+    return ret;
+}
+
+
+/**
+ * virQEMUCapsInitQMPBasicArch:
+ * @qemuCaps: QEMU capabilities
+ *
+ * Initialize @qemuCaps with basic architecture-dependent capabilities.
+ */
+static void
+virQEMUCapsInitQMPBasicArch(virQEMUCapsPtr qemuCaps)
+{
     /* ACPI/HPET/KVM PIT are x86 specific */
     if (ARCH_IS_X86(qemuCaps->arch)) {
         virQEMUCapsSet(qemuCaps, QEMU_CAPS_NO_ACPI);
         virQEMUCapsSet(qemuCaps, QEMU_CAPS_NO_HPET);
         virQEMUCapsSet(qemuCaps, QEMU_CAPS_NO_KVM_PIT);
     }
-
-    ret = 0;
-
- cleanup:
-    VIR_FREE(archstr);
-    return ret;
 }
 
 
@@ -4432,9 +4450,11 @@ virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps,
 
     virQEMUCapsInitQMPBasic(qemuCaps);
 
-    if (virQEMUCapsInitArchQMPBasic(qemuCaps, mon) < 0)
+    if (virQEMUCapsInitQMPArch(qemuCaps, mon) < 0)
         goto cleanup;
 
+    virQEMUCapsInitQMPBasicArch(qemuCaps);
+
     /* USB option is supported v1.3.0 onwards */
     if (qemuCaps->version >= 1003000)
         virQEMUCapsSet(qemuCaps, QEMU_CAPS_MACHINE_USB_OPT);
-- 
2.7.4

--
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