[libvirt] [PATCH] [PATCH] vcpupin: add clear feature

Yi Wang wang.yi59 at zte.com.cn
Thu Jan 4 10:46:32 UTC 2018


We can't clear vcpupin settings of XML once we did vcpupin
command, this is not convenient under some condition such
as migration.

This patch introduces clear feature, which can clear vcpuin
setting of XML.

Signed-off-by: Yi Wang <wang.yi59 at zte.com.cn>
Signed-off-by: Xi Xu <xu.xi8 at zte.com.cn>
---
 include/libvirt/libvirt-domain.h |  1 +
 src/qemu/qemu_driver.c           | 24 +++++++++++++++++++-----
 tools/virsh-domain.c             |  5 ++++-
 tools/virsh.pod                  |  1 +
 4 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index 4048acf..7b171df 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -1837,6 +1837,7 @@ typedef enum {
     VIR_DOMAIN_VCPU_MAXIMUM = (1 << 2), /* Max rather than current count */
     VIR_DOMAIN_VCPU_GUEST   = (1 << 3), /* Modify state of the cpu in the guest */
     VIR_DOMAIN_VCPU_HOTPLUGGABLE = (1 << 4), /* Make vcpus added hot(un)pluggable */
+    VIR_DOMAIN_VCPU_CLEAR = (1 << 5), /* Clear vcpus pin info */
 } virDomainVcpuFlags;
 
 int                     virDomainSetVcpus       (virDomainPtr domain,
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 97b194b..9e8759f 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -5001,7 +5001,7 @@ qemuDomainPinVcpuLive(virDomainObjPtr vm,
                       int vcpu,
                       virQEMUDriverPtr driver,
                       virQEMUDriverConfigPtr cfg,
-                      virBitmapPtr cpumap)
+                      virBitmapPtr cpumap, bool clear)
 {
     virBitmapPtr tmpmap = NULL;
     virDomainVcpuDefPtr vcpuinfo;
@@ -5049,7 +5049,12 @@ qemuDomainPinVcpuLive(virDomainObjPtr vm,
     }
 
     virBitmapFree(vcpuinfo->cpumask);
-    vcpuinfo->cpumask = tmpmap;
+    if (clear) {
+        virBitmapFree(tmpmap);
+        vcpuinfo->cpumask = NULL;
+    } else {
+        vcpuinfo->cpumask = tmpmap;
+    }
     tmpmap = NULL;
 
     if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0)
@@ -5093,9 +5098,11 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
     virBitmapPtr pcpumap = NULL;
     virDomainVcpuDefPtr vcpuinfo = NULL;
     virQEMUDriverConfigPtr cfg = NULL;
+    bool clear = false;
 
     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
-                  VIR_DOMAIN_AFFECT_CONFIG, -1);
+                  VIR_DOMAIN_AFFECT_CONFIG |
+                  VIR_DOMAIN_VCPU_CLEAR, -1);
 
     cfg = virQEMUDriverGetConfig(driver);
 
@@ -5111,6 +5118,8 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
     if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
         goto endjob;
 
+    clear = !!(flags & VIR_DOMAIN_VCPU_CLEAR);
+
     if ((def && def->virtType == VIR_DOMAIN_VIRT_QEMU) ||
         (persistentDef && persistentDef->virtType == VIR_DOMAIN_VIRT_QEMU)) {
         virReportError(VIR_ERR_OPERATION_FAILED, "%s",
@@ -5136,12 +5145,17 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
     }
 
     if (def &&
-        qemuDomainPinVcpuLive(vm, def, vcpu, driver, cfg, pcpumap) < 0)
+        qemuDomainPinVcpuLive(vm, def, vcpu, driver, cfg, pcpumap, clear) < 0)
         goto endjob;
 
     if (persistentDef) {
         virBitmapFree(vcpuinfo->cpumask);
-        vcpuinfo->cpumask = pcpumap;
+        if (clear) {
+            virBitmapFree(pcpumap);
+            vcpuinfo->cpumask = NULL;
+        } else {
+            vcpuinfo->cpumask = pcpumap;
+        }
         pcpumap = NULL;
 
         ret = virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef);
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 93cb020..4bad9e7 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -6860,7 +6860,7 @@ virshParseCPUList(vshControl *ctl, int *cpumaplen,
     unsigned char *cpumap = NULL;
     virBitmapPtr map = NULL;
 
-    if (cpulist[0] == 'r') {
+    if (cpulist[0] == 'r' || STREQ("clear", cpulist)) {
         if (!(map = virBitmapNew(maxcpu)))
             return NULL;
         virBitmapSetAll(map);
@@ -6938,6 +6938,9 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
     }
 
+    if (STREQ(cpulist, "clear"))
+        flags |= VIR_DOMAIN_VCPU_CLEAR;
+
     /* Pin mode: pinning specified vcpu to specified physical cpus*/
     if (!(cpumap = virshParseCPUList(ctl, &cpumaplen, cpulist, maxcpu)))
         goto cleanup;
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 69cc423..caaa230 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -2857,6 +2857,7 @@ I<cpulist> is a list of physical CPU numbers. Its syntax is a comma
 separated list and a special markup using '-' and '^' (ex. '0-4', '0-3,^2') can
 also be allowed. The '-' denotes the range and the '^' denotes exclusive.
 For pinning the I<vcpu> to all physical cpus specify 'r' as a I<cpulist>.
+For clearing pinning info, specify 'clear' as a I<cpulist>.
 If I<--live> is specified, affect a running guest.
 If I<--config> is specified, affect the next boot of a persistent guest.
 If I<--current> is specified, affect the current guest state.
-- 
1.8.3.1




More information about the libvir-list mailing list