From nobody Mon Feb 9 04:28:14 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.24 as permitted sender) client-ip=209.132.183.24; envelope-from=libvir-list-bounces@redhat.com; helo=mx3-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.24 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by mx.zohomail.com with SMTPS id 1486746837518110.97353930156112; Fri, 10 Feb 2017 09:13:57 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v1AHASBT014044; Fri, 10 Feb 2017 12:10:28 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v1AH9q9l025790 for ; Fri, 10 Feb 2017 12:09:52 -0500 Received: from angien.brq.redhat.com (dhcp129-162.brq.redhat.com [10.34.129.162]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1AH9mjr022155; Fri, 10 Feb 2017 12:09:51 -0500 From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 10 Feb 2017 18:10:19 +0100 Message-Id: <23b19050952af6a45365df871f2055721ebb0ae8.1486746569.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 2/5] virsh: Implement command for virDomainSetVcpu called setvcpu 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-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add a simple virsh command handler which makes use of the new API. --- tools/virsh-domain.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++= ++++ tools/virsh.pod | 19 ++++++++++++ 2 files changed, 107 insertions(+) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 023ec8a8b..09a9f8203 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -7015,6 +7015,88 @@ cmdGuestvcpus(vshControl *ctl, const vshCmd *cmd) /* + * "setvcpu" command + */ +static const vshCmdInfo info_setvcpu[] =3D { + {.name =3D "help", + .data =3D N_("attach/detach vcpu or groups of threads") + }, + {.name =3D "desc", + .data =3D N_("Add or remove vcpus") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_setvcpu[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL, + {.name =3D "vcpulist", + .type =3D VSH_OT_DATA, + .flags =3D VSH_OFLAG_REQ, + .help =3D N_("ids of vcpus to manipulate") + }, + {.name =3D "enable", + .type =3D VSH_OT_BOOL, + .help =3D N_("enable cpus specified by cpumap") + }, + {.name =3D "disable", + .type =3D VSH_OT_BOOL, + .help =3D N_("disable cpus specified by cpumap") + }, + VIRSH_COMMON_OPT_DOMAIN_CONFIG, + VIRSH_COMMON_OPT_DOMAIN_LIVE, + VIRSH_COMMON_OPT_DOMAIN_CURRENT, + {.name =3D NULL} +}; + +static bool +cmdSetvcpu(vshControl *ctl, const vshCmd *cmd) +{ + virDomainPtr dom; + bool enable =3D vshCommandOptBool(cmd, "enable"); + bool disable =3D vshCommandOptBool(cmd, "disable"); + bool config =3D vshCommandOptBool(cmd, "config"); + bool live =3D vshCommandOptBool(cmd, "live"); + const char *vcpulist =3D NULL; + int state =3D 0; + bool ret =3D false; + unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; + + VSH_EXCLUSIVE_OPTIONS_VAR(enable, disable); + + VSH_EXCLUSIVE_OPTIONS("current", "live"); + VSH_EXCLUSIVE_OPTIONS("current", "config"); + + if (config) + flags |=3D VIR_DOMAIN_AFFECT_CONFIG; + if (live) + flags |=3D VIR_DOMAIN_AFFECT_LIVE; + + if (!(enable || disable)) { + vshError(ctl, "%s", _("one of --enable, --disable is required")); + return false; + } + + if (vshCommandOptStringReq(ctl, cmd, "vcpulist", &vcpulist)) + return false; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + if (enable) + state =3D 1; + + if (virDomainSetVcpu(dom, vcpulist, state, flags) < 0) + goto cleanup; + + ret =3D true; + + cleanup: + virDomainFree(dom); + return ret; +} + + +/* * "iothreadinfo" command */ static const vshCmdInfo info_iothreadinfo[] =3D { @@ -13951,5 +14033,11 @@ const vshCmdDef domManagementCmds[] =3D { .info =3D info_guestvcpus, .flags =3D 0 }, + {.name =3D "setvcpu", + .handler =3D cmdSetvcpu, + .opts =3D opts_setvcpu, + .info =3D info_setvcpu, + .flags =3D 0 + }, {.name =3D NULL} }; diff --git a/tools/virsh.pod b/tools/virsh.pod index a47040984..606792df1 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -2418,6 +2418,25 @@ be hot-plugged the next time the domain is booted. = As such, it must only be used with the I<--config> flag, and not with the I<--live> or the I<--curr= ent> flag. +=3Ditem B I I [I<--enable>] | [I<--disable>] +[[I<--live>] [I<--config>] | [I<--current>]] + +Change state of individual vCPUs using hot(un)plug mechanism. + +See B for information on format of I. Hypervisor driver= s may +require that I contains exactly vCPUs belonging to one hotplugga= ble +entity. This is usually just a single vCPU but certain architectures such = as +ppc64 require a full core to be specified at once. + +Note that hypervisors may refuse to disable certain vcpus such as vcpu 0 or +others. + +If I<--live> is specified, affect a running domain. +If I<--config> is specified, affect the next startup of a persistent domai= n. +If I<--current> is specified, affect the current domain state. This is the +default. Both I<--live> and I<--config> flags may be given, but I<--curren= t> is +exclusive. + =3Ditem B I [I<--mode MODE-LIST>] Gracefully shuts down a domain. This coordinates with the domain OS --=20 2.11.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list