Blame SOURCES/libvirt-qemu-capabilities-Extract-availability-of-new-cpu-hotplug-for-machine-types.patch

6ae9ed
From e8f1dbb6bb0d1d34615ccc7ae0a4cbc7b8afbe9f Mon Sep 17 00:00:00 2001
6ae9ed
Message-Id: <e8f1dbb6bb0d1d34615ccc7ae0a4cbc7b8afbe9f@dist-git>
6ae9ed
From: Peter Krempa <pkrempa@redhat.com>
6ae9ed
Date: Wed, 24 Aug 2016 16:11:21 -0400
6ae9ed
Subject: [PATCH] qemu: capabilities: Extract availability of new cpu hotplug
6ae9ed
 for machine types
6ae9ed
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1097930
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1224341
6ae9ed
6ae9ed
QEMU reports whether 'query-hotpluggable-cpus' is supported for a given
6ae9ed
machine type. Extract and cache the information using the capability
6ae9ed
cache.
6ae9ed
6ae9ed
When copying the capabilities for a new start of qemu, mask out the
6ae9ed
presence of QEMU_CAPS_QUERY_HOTPLUGGABLE_CPUS if the machine type
6ae9ed
doesn't support hotpluggable cpus.
6ae9ed
6ae9ed
(cherry picked from commit 920bbe5c15007b470a97cdc33353b17a7be5a55e)
6ae9ed
---
6ae9ed
 src/qemu/qemu_capabilities.c                     | 29 ++++++++++++-
6ae9ed
 src/qemu/qemu_capabilities.h                     |  2 +
6ae9ed
 src/qemu/qemu_monitor.h                          |  1 +
6ae9ed
 src/qemu/qemu_monitor_json.c                     |  3 ++
6ae9ed
 tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml | 54 ++++++++++++------------
6ae9ed
 5 files changed, 61 insertions(+), 28 deletions(-)
6ae9ed
6ae9ed
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
6ae9ed
index ffd54c5..5b68271 100644
6ae9ed
--- a/src/qemu/qemu_capabilities.c
6ae9ed
+++ b/src/qemu/qemu_capabilities.c
6ae9ed
@@ -347,6 +347,7 @@ struct virQEMUCapsMachineType {
6ae9ed
     char *name;
6ae9ed
     char *alias;
6ae9ed
     unsigned int maxCpus;
6ae9ed
+    bool hotplugCpus;
6ae9ed
 };
6ae9ed
 /*
6ae9ed
  * Update the XML parser/formatter when adding more
6ae9ed
@@ -546,6 +547,7 @@ virQEMUCapsParseMachineTypesStr(const char *output,
6ae9ed
         }
6ae9ed
         /* When parsing from command line we don't have information about maxCpus */
6ae9ed
         qemuCaps->machineTypes[qemuCaps->nmachineTypes-1].maxCpus = 0;
6ae9ed
+        qemuCaps->machineTypes[qemuCaps->nmachineTypes-1].hotplugCpus = false;
6ae9ed
     } while ((p = next));
6ae9ed
 
6ae9ed
 
6ae9ed
@@ -2041,6 +2043,7 @@ virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps)
6ae9ed
             VIR_STRDUP(ret->machineTypes[i].alias, qemuCaps->machineTypes[i].alias) < 0)
6ae9ed
             goto error;
6ae9ed
         ret->machineTypes[i].maxCpus = qemuCaps->machineTypes[i].maxCpus;
6ae9ed
+        ret->machineTypes[i].hotplugCpus = qemuCaps->machineTypes[i].hotplugCpus;
6ae9ed
     }
6ae9ed
 
6ae9ed
     return ret;
6ae9ed
@@ -2344,6 +2347,20 @@ int virQEMUCapsGetMachineMaxCpus(virQEMUCapsPtr qemuCaps,
6ae9ed
 }
6ae9ed
 
6ae9ed
 
6ae9ed
+bool virQEMUCapsGetMachineHotplugCpus(virQEMUCapsPtr qemuCaps,
6ae9ed
+                                      const char *name)
6ae9ed
+{
6ae9ed
+    size_t i;
6ae9ed
+
6ae9ed
+    for (i = 0; i < qemuCaps->nmachineTypes; i++) {
6ae9ed
+        if (STREQ_NULLABLE(qemuCaps->machineTypes[i].name, name))
6ae9ed
+            return qemuCaps->machineTypes[i].hotplugCpus;
6ae9ed
+    }
6ae9ed
+
6ae9ed
+    return false;
6ae9ed
+}
6ae9ed
+
6ae9ed
+
6ae9ed
 /**
6ae9ed
  * virQEMUCapsSetGICCapabilities:
6ae9ed
  * @qemuCaps: QEMU capabilities
6ae9ed
@@ -2498,6 +2515,7 @@ virQEMUCapsProbeQMPMachineTypes(virQEMUCapsPtr qemuCaps,
6ae9ed
             goto cleanup;
6ae9ed
 
6ae9ed
         mach->maxCpus = machines[i]->maxCpus;
6ae9ed
+        mach->hotplugCpus = machines[i]->hotplugCpus;
6ae9ed
 
6ae9ed
         if (machines[i]->isDefault)
6ae9ed
             defIdx = qemuCaps->nmachineTypes - 1;
6ae9ed
@@ -2756,7 +2774,7 @@ int virQEMUCapsProbeQMP(virQEMUCapsPtr qemuCaps,
6ae9ed
  *   ...
6ae9ed
  *   <cpu name="pentium3"/>
6ae9ed
  *   ...
6ae9ed
- *   <machine name="pc-1.0" alias="pc" maxCpus="4"/>
6ae9ed
+ *   <machine name="pc-1.0" alias="pc" hotplugCpus='yes' maxCpus="4"/>
6ae9ed
  *   ...
6ae9ed
  * </qemuCaps>
6ae9ed
  */
6ae9ed
@@ -2913,6 +2931,11 @@ virQEMUCapsLoadCache(virQEMUCapsPtr qemuCaps, const char *filename,
6ae9ed
                 goto cleanup;
6ae9ed
             }
6ae9ed
             VIR_FREE(str);
6ae9ed
+
6ae9ed
+            str = virXMLPropString(nodes[i], "hotplugCpus");
6ae9ed
+            if (STREQ_NULLABLE(str, "yes"))
6ae9ed
+                qemuCaps->machineTypes[i].hotplugCpus = true;
6ae9ed
+            VIR_FREE(str);
6ae9ed
         }
6ae9ed
     }
6ae9ed
     VIR_FREE(nodes);
6ae9ed
@@ -3046,6 +3069,8 @@ virQEMUCapsFormatCache(virQEMUCapsPtr qemuCaps,
6ae9ed
         if (qemuCaps->machineTypes[i].alias)
6ae9ed
             virBufferEscapeString(&buf, " alias='%s'",
6ae9ed
                               qemuCaps->machineTypes[i].alias);
6ae9ed
+        if (qemuCaps->machineTypes[i].hotplugCpus)
6ae9ed
+            virBufferAddLit(&buf, " hotplugCpus='yes'");
6ae9ed
         virBufferAsprintf(&buf, " maxCpus='%u'/>\n",
6ae9ed
                           qemuCaps->machineTypes[i].maxCpus);
6ae9ed
     }
6ae9ed
@@ -3836,6 +3861,8 @@ virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuCaps,
6ae9ed
             virQEMUCapsClear(qemuCaps, filter->flags[j]);
6ae9ed
     }
6ae9ed
 
6ae9ed
+    if (!virQEMUCapsGetMachineHotplugCpus(qemuCaps, machineType))
6ae9ed
+        virQEMUCapsClear(qemuCaps, QEMU_CAPS_QUERY_HOTPLUGGABLE_CPUS);
6ae9ed
 }
6ae9ed
 
6ae9ed
 
6ae9ed
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
6ae9ed
index 68d1ea8..e05c178 100644
6ae9ed
--- a/src/qemu/qemu_capabilities.h
6ae9ed
+++ b/src/qemu/qemu_capabilities.h
6ae9ed
@@ -427,6 +427,8 @@ const char *virQEMUCapsGetCanonicalMachine(virQEMUCapsPtr qemuCaps,
6ae9ed
                                            const char *name);
6ae9ed
 int virQEMUCapsGetMachineMaxCpus(virQEMUCapsPtr qemuCaps,
6ae9ed
                                  const char *name);
6ae9ed
+bool virQEMUCapsGetMachineHotplugCpus(virQEMUCapsPtr qemuCaps,
6ae9ed
+                                      const char *name);
6ae9ed
 int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps,
6ae9ed
                                    size_t *nmachines,
6ae9ed
                                    virCapsGuestMachinePtr **machines);
6ae9ed
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
6ae9ed
index 5ec2101..2269d60 100644
6ae9ed
--- a/src/qemu/qemu_monitor.h
6ae9ed
+++ b/src/qemu/qemu_monitor.h
6ae9ed
@@ -853,6 +853,7 @@ struct _qemuMonitorMachineInfo {
6ae9ed
     bool isDefault;
6ae9ed
     char *alias;
6ae9ed
     unsigned int maxCpus;
6ae9ed
+    bool hotplugCpus;
6ae9ed
 };
6ae9ed
 
6ae9ed
 int qemuMonitorGetMachines(qemuMonitorPtr mon,
6ae9ed
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
6ae9ed
index 5836e1e..8243b52 100644
6ae9ed
--- a/src/qemu/qemu_monitor_json.c
6ae9ed
+++ b/src/qemu/qemu_monitor_json.c
6ae9ed
@@ -4979,6 +4979,9 @@ int qemuMonitorJSONGetMachines(qemuMonitorPtr mon,
6ae9ed
                            _("query-machines reply has malformed 'cpu-max' data"));
6ae9ed
             goto cleanup;
6ae9ed
         }
6ae9ed
+
6ae9ed
+        ignore_value(virJSONValueObjectGetBoolean(child, "hotpluggable-cpus",
6ae9ed
+                                                  &info->hotplugCpus));
6ae9ed
     }
6ae9ed
 
6ae9ed
     ret = n;
6ae9ed
diff --git a/tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml b/tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml
6ae9ed
index 0f3c17a..8f878fe 100644
6ae9ed
--- a/tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml
6ae9ed
+++ b/tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml
6ae9ed
@@ -225,31 +225,31 @@
6ae9ed
   <cpu name='core2duo'/>
6ae9ed
   <cpu name='phenom'/>
6ae9ed
   <cpu name='qemu64'/>
6ae9ed
-  <machine name='pc-i440fx-2.7' alias='pc' maxCpus='255'/>
6ae9ed
-  <machine name='pc-0.12' maxCpus='255'/>
6ae9ed
-  <machine name='pc-i440fx-2.4' maxCpus='255'/>
6ae9ed
-  <machine name='pc-1.3' maxCpus='255'/>
6ae9ed
-  <machine name='pc-q35-2.7' alias='q35' maxCpus='255'/>
6ae9ed
-  <machine name='pc-q35-2.6' maxCpus='255'/>
6ae9ed
-  <machine name='pc-i440fx-1.7' maxCpus='255'/>
6ae9ed
-  <machine name='pc-i440fx-1.6' maxCpus='255'/>
6ae9ed
-  <machine name='pc-0.11' maxCpus='255'/>
6ae9ed
-  <machine name='pc-i440fx-2.3' maxCpus='255'/>
6ae9ed
-  <machine name='pc-0.10' maxCpus='255'/>
6ae9ed
-  <machine name='pc-1.2' maxCpus='255'/>
6ae9ed
-  <machine name='pc-i440fx-2.2' maxCpus='255'/>
6ae9ed
-  <machine name='isapc' maxCpus='1'/>
6ae9ed
-  <machine name='pc-q35-2.5' maxCpus='255'/>
6ae9ed
-  <machine name='pc-0.15' maxCpus='255'/>
6ae9ed
-  <machine name='pc-i440fx-1.5' maxCpus='255'/>
6ae9ed
-  <machine name='pc-0.14' maxCpus='255'/>
6ae9ed
-  <machine name='pc-i440fx-2.6' maxCpus='255'/>
6ae9ed
-  <machine name='pc-i440fx-1.4' maxCpus='255'/>
6ae9ed
-  <machine name='pc-i440fx-2.5' maxCpus='255'/>
6ae9ed
-  <machine name='pc-1.1' maxCpus='255'/>
6ae9ed
-  <machine name='pc-i440fx-2.1' maxCpus='255'/>
6ae9ed
-  <machine name='pc-1.0' maxCpus='255'/>
6ae9ed
-  <machine name='pc-i440fx-2.0' maxCpus='255'/>
6ae9ed
-  <machine name='pc-q35-2.4' maxCpus='255'/>
6ae9ed
-  <machine name='pc-0.13' maxCpus='255'/>
6ae9ed
+  <machine name='pc-i440fx-2.7' alias='pc' hotplugCpus='yes' maxCpus='255'/>
6ae9ed
+  <machine name='pc-0.12' hotplugCpus='yes' maxCpus='255'/>
6ae9ed
+  <machine name='pc-i440fx-2.4' hotplugCpus='yes' maxCpus='255'/>
6ae9ed
+  <machine name='pc-1.3' hotplugCpus='yes' maxCpus='255'/>
6ae9ed
+  <machine name='pc-q35-2.7' alias='q35' hotplugCpus='yes' maxCpus='255'/>
6ae9ed
+  <machine name='pc-q35-2.6' hotplugCpus='yes' maxCpus='255'/>
6ae9ed
+  <machine name='pc-i440fx-1.7' hotplugCpus='yes' maxCpus='255'/>
6ae9ed
+  <machine name='pc-i440fx-1.6' hotplugCpus='yes' maxCpus='255'/>
6ae9ed
+  <machine name='pc-0.11' hotplugCpus='yes' maxCpus='255'/>
6ae9ed
+  <machine name='pc-i440fx-2.3' hotplugCpus='yes' maxCpus='255'/>
6ae9ed
+  <machine name='pc-0.10' hotplugCpus='yes' maxCpus='255'/>
6ae9ed
+  <machine name='pc-1.2' hotplugCpus='yes' maxCpus='255'/>
6ae9ed
+  <machine name='pc-i440fx-2.2' hotplugCpus='yes' maxCpus='255'/>
6ae9ed
+  <machine name='isapc' hotplugCpus='yes' maxCpus='1'/>
6ae9ed
+  <machine name='pc-q35-2.5' hotplugCpus='yes' maxCpus='255'/>
6ae9ed
+  <machine name='pc-0.15' hotplugCpus='yes' maxCpus='255'/>
6ae9ed
+  <machine name='pc-i440fx-1.5' hotplugCpus='yes' maxCpus='255'/>
6ae9ed
+  <machine name='pc-0.14' hotplugCpus='yes' maxCpus='255'/>
6ae9ed
+  <machine name='pc-i440fx-2.6' hotplugCpus='yes' maxCpus='255'/>
6ae9ed
+  <machine name='pc-i440fx-1.4' hotplugCpus='yes' maxCpus='255'/>
6ae9ed
+  <machine name='pc-i440fx-2.5' hotplugCpus='yes' maxCpus='255'/>
6ae9ed
+  <machine name='pc-1.1' hotplugCpus='yes' maxCpus='255'/>
6ae9ed
+  <machine name='pc-i440fx-2.1' hotplugCpus='yes' maxCpus='255'/>
6ae9ed
+  <machine name='pc-1.0' hotplugCpus='yes' maxCpus='255'/>
6ae9ed
+  <machine name='pc-i440fx-2.0' hotplugCpus='yes' maxCpus='255'/>
6ae9ed
+  <machine name='pc-q35-2.4' hotplugCpus='yes' maxCpus='255'/>
6ae9ed
+  <machine name='pc-0.13' hotplugCpus='yes' maxCpus='255'/>
6ae9ed
 </qemuCaps>
6ae9ed
-- 
6ae9ed
2.10.0
6ae9ed