From nobody Mon Apr 29 02:09:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1518424276864971.7792533704458; Mon, 12 Feb 2018 00:31:16 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8EA122C98; Mon, 12 Feb 2018 08:31:15 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CBC0D5D965; Mon, 12 Feb 2018 08:31:14 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B50524A46C; Mon, 12 Feb 2018 08:31:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w1C8VCic023704 for ; Mon, 12 Feb 2018 03:31:12 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4828960BEC; Mon, 12 Feb 2018 08:31:12 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 418B960BE7 for ; Mon, 12 Feb 2018 08:31:08 +0000 (UTC) Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.217.80.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ABE7278540 for ; Mon, 12 Feb 2018 08:31:06 +0000 (UTC) Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id B3D0C93EB080511A0176 for ; Mon, 12 Feb 2018 16:31:04 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id w1C8UurU064240 for ; Mon, 12 Feb 2018 16:30:56 +0800 (GMT-8) (envelope-from wang.yi59@zte.com.cn) Received: from fox-host8.localdomain ([10.74.120.8]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2018021216305916-4590421 ; Mon, 12 Feb 2018 16:30:59 +0800 From: Yi Wang To: libvir-list@redhat.com Date: Mon, 12 Feb 2018 03:54:21 -0500 Message-Id: <1518425661-46982-1-git-send-email-wang.yi59@zte.com.cn> X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2018-02-12 16:30:59, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2018-02-12 16:30:56, Serialize complete at 2018-02-12 16:30:56 X-MAIL: mse01.zte.com.cn w1C8UurU064240 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 12 Feb 2018 08:31:07 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 12 Feb 2018 08:31:07 +0000 (UTC) for IP:'63.217.80.70' DOMAIN:'mxhk.zte.com.cn' HELO:'mxhk.zte.com.cn' FROM:'wang.yi59@zte.com.cn' RCPT:'' X-RedHat-Spam-Score: -2.311 (RCVD_IN_DNSWL_MED, SPF_PASS, T_RP_MATCHES_RCVD) 63.217.80.70 mxhk.zte.com.cn 63.217.80.70 mxhk.zte.com.cn X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: wang.yi59@zte.com.cn, Liu.Jianjun3@zte.com.cn, xu.xi8@zte.com.cn Subject: [libvirt] [PATCH v2] vcpupin: add clear feature X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 12 Feb 2018 08:31:15 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We can't clear vcpupin settings of XML once we did vcpupin command, this is not convenient under some condition such as migration to a host with less CPUs. This patch introduces clear feature, which can clear vcpuin setting of XML using a 'c' option. Signed-off-by: Yi Wang Signed-off-by: Xi Xu --- include/libvirt/libvirt-domain.h | 11 +++++++++++ src/qemu/qemu_driver.c | 32 ++++++++++++++++++++++++-------- tools/virsh-domain.c | 5 ++++- tools/virsh.pod | 1 + 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index 4048acf..46f4e77 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -1847,6 +1847,17 @@ int virDomainSetVcpusFlags (vir= DomainPtr domain, int virDomainGetVcpusFlags (virDomainPtr domain, unsigned int flags); =20 +/* Flags for controlling virtual CPU pinning. */ +typedef enum { + /* See virDomainModificationImpact for these flags. */ + VIR_DOMAIN_VCPU_PIN_CURRENT =3D VIR_DOMAIN_AFFECT_CURRENT, + VIR_DOMAIN_VCPU_PIN_LIVE =3D VIR_DOMAIN_AFFECT_LIVE, + VIR_DOMAIN_VCPU_PIN_CONFIG =3D VIR_DOMAIN_AFFECT_CONFIG, + + /* Additionally, these flags may be bitwise-OR'd in. */ + VIR_DOMAIN_VCPU_PIN_CLEAR =3D (1 << 2), /* Clear vcpus pin info */ +} virDomainVcpuPinFlags; + int virDomainPinVcpu (virDomainPtr domain, unsigned int vcpu, unsigned char *cpumap, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index bbce5bd..fe1f62f 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5056,7 +5056,8 @@ qemuDomainPinVcpuLive(virDomainObjPtr vm, int vcpu, virQEMUDriverPtr driver, virQEMUDriverConfigPtr cfg, - virBitmapPtr cpumap) + virBitmapPtr cpumap, + bool clear) { virBitmapPtr tmpmap =3D NULL; virDomainVcpuDefPtr vcpuinfo; @@ -5069,6 +5070,7 @@ qemuDomainPinVcpuLive(virDomainObjPtr vm, int eventNparams =3D 0; int eventMaxparams =3D 0; int ret =3D -1; + virBitmapPtr targetMap =3D NULL; =20 if (!qemuDomainHasVcpuPids(vm)) { virReportError(VIR_ERR_OPERATION_INVALID, @@ -5083,10 +5085,15 @@ qemuDomainPinVcpuLive(virDomainObjPtr vm, goto cleanup; } =20 - if (!(tmpmap =3D virBitmapNewCopy(cpumap))) - goto cleanup; + if (clear) { + targetMap =3D virHostCPUGetOnlineBitmap(); + } else { + targetMap =3D cpumap; + if (!(tmpmap =3D virBitmapNewCopy(cpumap))) + goto cleanup; + } =20 - if (!(str =3D virBitmapFormat(cpumap))) + if (!(str =3D virBitmapFormat(targetMap))) goto cleanup; =20 if (vcpuinfo->online) { @@ -5095,11 +5102,11 @@ qemuDomainPinVcpuLive(virDomainObjPtr vm, if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_VCPU, v= cpu, false, &cgroup_vcpu) < 0) goto cleanup; - if (qemuSetupCgroupCpusetCpus(cgroup_vcpu, cpumap) < 0) + if (qemuSetupCgroupCpusetCpus(cgroup_vcpu, targetMap) < 0) goto cleanup; } =20 - if (virProcessSetAffinity(qemuDomainGetVcpuPid(vm, vcpu), cpumap) = < 0) + if (virProcessSetAffinity(qemuDomainGetVcpuPid(vm, vcpu), targetMa= p) < 0) goto cleanup; } =20 @@ -5128,6 +5135,8 @@ qemuDomainPinVcpuLive(virDomainObjPtr vm, virCgroupFree(&cgroup_vcpu); VIR_FREE(str); qemuDomainEventQueue(driver, event); + if (clear) + virBitmapFree(targetMap); return ret; } =20 @@ -5148,9 +5157,11 @@ qemuDomainPinVcpuFlags(virDomainPtr dom, virBitmapPtr pcpumap =3D NULL; virDomainVcpuDefPtr vcpuinfo =3D NULL; virQEMUDriverConfigPtr cfg =3D NULL; + bool clear =3D false; =20 virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | - VIR_DOMAIN_AFFECT_CONFIG, -1); + VIR_DOMAIN_AFFECT_CONFIG | + VIR_DOMAIN_VCPU_PIN_CLEAR, -1); =20 cfg =3D virQEMUDriverGetConfig(driver); =20 @@ -5166,6 +5177,8 @@ qemuDomainPinVcpuFlags(virDomainPtr dom, if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0) goto endjob; =20 + clear =3D !!(flags & VIR_DOMAIN_VCPU_PIN_CLEAR); + if ((def && def->virtType =3D=3D VIR_DOMAIN_VIRT_QEMU) || (persistentDef && persistentDef->virtType =3D=3D VIR_DOMAIN_VIRT_Q= EMU)) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", @@ -5191,7 +5204,7 @@ qemuDomainPinVcpuFlags(virDomainPtr dom, } =20 if (def && - qemuDomainPinVcpuLive(vm, def, vcpu, driver, cfg, pcpumap) < 0) + qemuDomainPinVcpuLive(vm, def, vcpu, driver, cfg, pcpumap, clear) = < 0) goto endjob; =20 if (persistentDef) { @@ -5199,6 +5212,9 @@ qemuDomainPinVcpuFlags(virDomainPtr dom, vcpuinfo->cpumask =3D pcpumap; pcpumap =3D NULL; =20 + if (clear) + virBitmapFree(vcpuinfo->cpumask); + ret =3D virDomainSaveConfig(cfg->configDir, driver->caps, persiste= ntDef); goto endjob; } diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 5a0e0c1..4981ecc 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -6863,7 +6863,7 @@ virshParseCPUList(vshControl *ctl, int *cpumaplen, unsigned char *cpumap =3D NULL; virBitmapPtr map =3D NULL; =20 - if (cpulist[0] =3D=3D 'r') { + if (cpulist[0] =3D=3D 'r' || cpulist[0] =3D=3D 'c') { if (!(map =3D virBitmapNew(maxcpu))) return NULL; virBitmapSetAll(map); @@ -6941,6 +6941,9 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd) goto cleanup; } =20 + if (STREQ(cpulist, "c")) + flags |=3D VIR_DOMAIN_VCPU_PIN_CLEAR; + /* Pin mode: pinning specified vcpu to specified physical cpus*/ if (!(cpumap =3D virshParseCPUList(ctl, &cpumaplen, cpulist, maxcpu))) goto cleanup; diff --git a/tools/virsh.pod b/tools/virsh.pod index 69cc423..d5a1779 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -2857,6 +2857,7 @@ I is a list of physical CPU numbers. Its syn= tax 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 to all physical cpus specify 'r' as a I. +For clearing pinning info, specify 'c' as a I. 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. --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list