Re: [libvirt] [PATCH 2/7] qemu: Probe GIC capabilities

2016-04-19 Thread Cole Robinson
On 04/18/2016 01:43 PM, Andrea Bolognani wrote:
> QEMU introduced the query-gic-capabilities QMP command
> with commit 4468d4e0f383: use the command, if available,
> to probe available GIC capabilities.
> 
> The information obtained is stored in a virQEMUCaps
> instance, and will be later used to fill in a
> virDomainCaps instance.
> ---
> Changes from RFC:
> 
>   * Free qemuCaps->gicCapabilities when needed
> 
>   * Always return NULL when no capabilities have been found
> 
>   * Don't allocate (n+1) elements to store (n) capabilities
> 
>   * Check for ARM consistently with the rest of the code
> 
>   * Reference QEMU commit
> 
>   * Leave two empty lines between functions
> 
>   * Document all functions
> 
>  src/qemu/qemu_capabilities.c |  42 
>  src/qemu/qemu_monitor.c  |  17 +++
>  src/qemu/qemu_monitor.h  |   4 ++
>  src/qemu/qemu_monitor_json.c | 115 
> +++
>  src/qemu/qemu_monitor_json.h |   4 ++
>  src/util/virgic.h|  13 +
>  6 files changed, 195 insertions(+)

ACK

- Cole

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


[libvirt] [PATCH 2/7] qemu: Probe GIC capabilities

2016-04-18 Thread Andrea Bolognani
QEMU introduced the query-gic-capabilities QMP command
with commit 4468d4e0f383: use the command, if available,
to probe available GIC capabilities.

The information obtained is stored in a virQEMUCaps
instance, and will be later used to fill in a
virDomainCaps instance.
---
Changes from RFC:

  * Free qemuCaps->gicCapabilities when needed

  * Always return NULL when no capabilities have been found

  * Don't allocate (n+1) elements to store (n) capabilities

  * Check for ARM consistently with the rest of the code

  * Reference QEMU commit

  * Leave two empty lines between functions

  * Document all functions

 src/qemu/qemu_capabilities.c |  42 
 src/qemu/qemu_monitor.c  |  17 +++
 src/qemu/qemu_monitor.h  |   4 ++
 src/qemu/qemu_monitor_json.c | 115 +++
 src/qemu/qemu_monitor_json.h |   4 ++
 src/util/virgic.h|  13 +
 6 files changed, 195 insertions(+)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 9ae7b27..4afc6b6 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -358,6 +358,9 @@ struct _virQEMUCaps {
 char **machineTypes;
 char **machineAliases;
 unsigned int *machineMaxCpus;
+
+size_t ngicCapabilities;
+virGICCapability *gicCapabilities;
 };
 
 struct virQEMUCapsSearchData {
@@ -2082,6 +2085,8 @@ void virQEMUCapsDispose(void *obj)
 
 VIR_FREE(qemuCaps->package);
 VIR_FREE(qemuCaps->binary);
+
+VIR_FREE(qemuCaps->gicCapabilities);
 }
 
 void
@@ -2696,6 +2701,34 @@ virQEMUCapsProbeQMPMigrationCapabilities(virQEMUCapsPtr 
qemuCaps,
 return 0;
 }
 
+/**
+ * virQEMUCapsProbeQMPGICCapabilities:
+ * @qemuCaps: QEMU binary capabilities
+ * @mon: QEMU monitor
+ *
+ * Use @mon to obtain information about the GIC capabilities for the
+ * corresponding QEMU binary, and store them in @qemuCaps.
+ *
+ * Returns: 0 on success, <0 on failure
+ */
+static int
+virQEMUCapsProbeQMPGICCapabilities(virQEMUCapsPtr qemuCaps,
+   qemuMonitorPtr mon)
+{
+virGICCapability *caps = NULL;
+int ncaps;
+
+if ((ncaps = qemuMonitorGetGICCapabilities(mon, &caps)) < 0)
+return -1;
+
+VIR_FREE(qemuCaps->gicCapabilities);
+
+qemuCaps->gicCapabilities = caps;
+qemuCaps->ngicCapabilities = ncaps;
+
+return 0;
+}
+
 int virQEMUCapsProbeQMP(virQEMUCapsPtr qemuCaps,
 qemuMonitorPtr mon)
 {
@@ -3047,6 +3080,9 @@ virQEMUCapsReset(virQEMUCapsPtr qemuCaps)
 VIR_FREE(qemuCaps->machineAliases);
 VIR_FREE(qemuCaps->machineMaxCpus);
 qemuCaps->nmachineTypes = 0;
+
+VIR_FREE(qemuCaps->gicCapabilities);
+qemuCaps->ngicCapabilities = 0;
 }
 
 
@@ -3411,6 +3447,12 @@ virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps,
 if (virQEMUCapsProbeQMPMigrationCapabilities(qemuCaps, mon) < 0)
 goto cleanup;
 
+/* GIC capabilities, eg. available GIC versions */
+if ((qemuCaps->arch == VIR_ARCH_AARCH64 ||
+ qemuCaps->arch == VIR_ARCH_ARMV7L) &&
+virQEMUCapsProbeQMPGICCapabilities(qemuCaps, mon) < 0)
+goto cleanup;
+
 ret = 0;
  cleanup:
 return ret;
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 83551a8..7c9ea71 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3580,6 +3580,23 @@ qemuMonitorSetMigrationCapability(qemuMonitorPtr mon,
 }
 
 
+/**
+ * qemuMonitorGetGICCapabilities:
+ * @mon: QEMU monitor
+ * @capabilities: where to store the GIC capabilities
+ *
+ * See qemuMonitorJSONGetGICCapabilities().
+ */
+int
+qemuMonitorGetGICCapabilities(qemuMonitorPtr mon,
+  virGICCapability **capabilities)
+{
+QEMU_CHECK_MONITOR_JSON(mon);
+
+return qemuMonitorJSONGetGICCapabilities(mon, capabilities);
+}
+
+
 int
 qemuMonitorNBDServerStart(qemuMonitorPtr mon,
   const char *host,
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index bd5d006..470c729 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -34,6 +34,7 @@
 # include "virnetdev.h"
 # include "device_conf.h"
 # include "cpu/cpu.h"
+# include "util/virgic.h"
 
 typedef struct _qemuMonitor qemuMonitor;
 typedef qemuMonitor *qemuMonitorPtr;
@@ -583,6 +584,9 @@ int qemuMonitorSetMigrationCapability(qemuMonitorPtr mon,
   qemuMonitorMigrationCaps capability,
   bool state);
 
+int qemuMonitorGetGICCapabilities(qemuMonitorPtr mon,
+  virGICCapability **capabilities);
+
 typedef enum {
   QEMU_MONITOR_MIGRATE_BACKGROUND  = 1 << 0,
   QEMU_MONITOR_MIGRATE_NON_SHARED_DISK  = 1 << 1, /* migration with non-shared 
storage with full disk copy */
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 29d6c8c..7bb9976 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -5855,6 +5855,121 @@ qemu