From nobody Sat Jan 4 23:19:58 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1733751170382240.5469285682168; Mon, 9 Dec 2024 05:32:50 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 714E91253; Mon, 9 Dec 2024 08:32:49 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 5D81213DF; Mon, 9 Dec 2024 08:20:27 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 4214411C9; Mon, 9 Dec 2024 07:43:00 -0500 (EST) Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id D28E111CE for ; Mon, 9 Dec 2024 07:42:58 -0500 (EST) Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2163dc5155fso10125795ad.0 for ; Mon, 09 Dec 2024 04:42:58 -0800 (PST) Received: from localhost.localdomain ([120.60.110.156]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-2164d103993sm18113195ad.193.2024.12.09.04.42.55 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 09 Dec 2024 04:42:56 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733748177; x=1734352977; darn=lists.libvirt.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=masJ3T08JoIixbp9a25hsnvTjQj6JYFm4ii9gaTWNXs=; b=GPT4CdS6l1eQTqqZCjxE2fdR4b0onV47xNTT6pUz13eBur1VTPyxUpz0WMUjl+59xz wPQyiwU1wD1FTDbMlTRi5XL9mqrD4YezAR7LypmWH8ffPYjCGOST5dF0cT9WhPkvNB5T pP2/4Ef/dz90SW03/agwEroc4TGQsQRIwBXiuVYQXM03orDmexkIVGj/vdS+wc/f9Iuy aRA8q2wQX7s6XWoG3u+5/ZWidnfd49Nv/zqXnk6WQF0JCCbcKA39j/Vgrjx9wv1Po2QK BrjXBhdzea+fFeqXPqnFUGz12b98QMCIJ4NSzKyoLn60VR2zIdu4JCkktskRkcqmH+Ru Dm3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733748177; x=1734352977; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=masJ3T08JoIixbp9a25hsnvTjQj6JYFm4ii9gaTWNXs=; b=X771tLJYNFHppV+1Dw1lPy2oLChrkbMdKV6D8NUXiYGe8HzEA2DLby5YZ/eplxntjW VgTbp+QvAI1ZvRjYhuuooqTWx+1hf11v1i3c8C5TzWPTPSMCrz2HET3yyRmUANB4GUOG 9XBSpOndrAp27pymylYOJeVpLjx/eGYJJ21BYvrVzcXAiFRNdgIfRfsnjRtvWS9lQQUu Pnr52zJcGUZcm0F8Np1vyP03Mh8kHkNN2ISsR0gzPUME0c1BHlrw9d7vExVZ2Sre60Q4 ueVeTgCtjXApQkiRZdUZxIpY0ATekCF7GsowgOUBLGViyBJ5mxBkE3eG4dyOsW/gH4zL ncPA== X-Gm-Message-State: AOJu0YybzF+SO0kYfIylVHIKwYP5PkkQYHsgTuapLM3Z+suJKicPluvB Opg+krnuRytU96laMqi8eG12BnZ7EpY4ds5/6gLQUuTag3im29KZ+8bv/+2P X-Gm-Gg: ASbGncuBUortAzxZ6qi0YXDD40qTll8+j9FPmWhDf0lcA+r/LIsT1U7s/i7PsiwP5sn 0v7jzkTLl1syD80blyRGQ1QDrnYOqBYiSimC8v20ZlcCjaMt3XwrlQf8MnQmaDti2VYdW9u6Hg4 whRjs33EfpaMFb4i9ZcLjkJh5uTo/FCbuKCU+dOBZOLpCJKgDuH1bU/s/APrGMooOY+4B6zTGvM FpkrqebDU8rcKKHmeVM3+kRB/1MkdtoI3U+RBukwPVp8XMStd8/KaozIk8zaETkMBtlDHrG56HV Dsdgqg== X-Google-Smtp-Source: AGHT+IFL/0UBMTM1Xr+DBWO58PwqtfZI6xGdcSIso9qqQ1Lh2MDRNf73uUTWyuHq+/4vryg2q3sU/g== X-Received: by 2002:a17:902:f542:b0:215:5d8c:7e47 with SMTP id d9443c01a7336-21614db1638mr208151795ad.36.1733748177312; Mon, 09 Dec 2024 04:42:57 -0800 (PST) From: Harikumar R To: devel@lists.libvirt.org Subject: [PATCH v6 16/18] virsh: Add support for throttle group operations Date: Mon, 9 Dec 2024 18:11:16 +0530 Message-Id: <20241209124118.39471-17-harirajkumar230@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241209124118.39471-1-harirajkumar230@gmail.com> References: <20241209124118.39471-1-harirajkumar230@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MailFrom: harirajkumar230@gmail.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0 Message-ID-Hash: 667YLTLXJKVP7CVNY4CY3XB3WGLZLUQK X-Message-ID-Hash: 667YLTLXJKVP7CVNY4CY3XB3WGLZLUQK X-Mailman-Approved-At: Mon, 09 Dec 2024 13:19:48 -0500 CC: earulana@in.ibm.com, sanjeev.ranjan@ibm.com, harikumar.rajkumar@ibm.com, Chun Feng Wu X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1733751171702116600 Content-Type: text/plain; charset="utf-8" From: Chun Feng Wu Implement new throttle cmds * Add new virsh cmds: domthrottlegroupset, domthrottlegrouplist, domthrottlegroupinfo, domthrottlegroupdel * Add doc for new cmds at docs/manpages/virsh.rst * Add cmd helper "virshDomainThrottleGroupCompleter", which is used by domthrottlegroupset, domthrottlegroupinfo, domthrottlegroupdel Signed-off-by: Chun Feng Wu --- docs/manpages/virsh.rst | 132 +++++++++++++ tools/virsh-completer-domain.c | 55 ++++++ tools/virsh-completer-domain.h | 11 ++ tools/virsh-domain.c | 349 ++++++++++++++++++++++++++++++++- 4 files changed, 546 insertions(+), 1 deletion(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 2e525d3fac..c1ed028844 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -1122,6 +1122,138 @@ given, but *--current* is exclusive. For querying o= nly one of *--live*, is different depending on hypervisor. =20 =20 +domthrottlegroupset +------------------- + +**Syntax:** + +:: + + domthrottlegroupset domain group-name [[--config] [--live] | [--current= ]] + [[total-bytes-sec] | [read-bytes-sec] [write-bytes-sec]] + [[total-iops-sec] | [read-iops-sec] [write-iops-sec]] + [[total-bytes-sec-max] | [read-bytes-sec-max] [write-bytes-sec-max]] + [[total-iops-sec-max] | [read-iops-sec-max] [write-iops-sec-max]] + [[total-bytes-sec-max-length] | + [read-bytes-sec-max-length] [write-bytes-sec-max-length]] + [[total-iops-sec-max-length] | + [read-iops-sec-max-length] [write-iops-sec-max-length]] + [size-iops-sec] + +Add or update a throttle group against specific *domain*. +*group-name* specifies a unique throttle group name, which defines limit, = and +will be referenced by drives. +*domain* (see also ``domblklist`` for listing these names). + +If no limit is specified, default them as all zeros, which will fail, +Otherwise, set limits with these flags: +*--total-bytes-sec* specifies total throughput limit as a scaled integer, = the +default being bytes per second if no suffix is specified. +*--read-bytes-sec* specifies read throughput limit as a scaled integer, the +default being bytes per second if no suffix is specified. +*--write-bytes-sec* specifies write throughput limit as a scaled integer, = the +default being bytes per second if no suffix is specified. +*--total-iops-sec* specifies total I/O operations limit per second. +*--read-iops-sec* specifies read I/O operations limit per second. +*--write-iops-sec* specifies write I/O operations limit per second. +*--total-bytes-sec-max* specifies maximum total throughput limit as a scal= ed +integer, the default being bytes per second if no suffix is specified +*--read-bytes-sec-max* specifies maximum read throughput limit as a scaled +integer, the default being bytes per second if no suffix is specified. +*--write-bytes-sec-max* specifies maximum write throughput limit as a scal= ed +integer, the default being bytes per second if no suffix is specified. +*--total-iops-sec-max* specifies maximum total I/O operations limit per se= cond. +*--read-iops-sec-max* specifies maximum read I/O operations limit per seco= nd. +*--write-iops-sec-max* specifies maximum write I/O operations limit per se= cond. +*--total-bytes-sec-max-length* specifies duration in seconds to allow maxi= mum +total throughput limit. +*--read-bytes-sec-max-length* specifies duration in seconds to allow maxim= um +read throughput limit. +*--write-bytes-sec-max-length* specifies duration in seconds to allow maxi= mum +write throughput limit. +*--total-iops-sec-max-length* specifies duration in seconds to allow maxim= um +total I/O operations limit. +*--read-iops-sec-max-length* specifies duration in seconds to allow maximum +read I/O operations limit. +*--write-iops-sec-max-length* specifies duration in seconds to allow maxim= um +write I/O operations limit. +*--size-iops-sec* specifies size I/O operations limit per second. + +Bytes and iops values are independent, but setting only one value (such +as --read-bytes-sec) resets the other two in that category to unlimited. +An explicit 0 also clears any limit. A non-zero value for a given total +cannot be mixed with non-zero values for read or write. + +It is up to the hypervisor to determine how to handle the length values. +For the QEMU hypervisor, if an I/O limit value or maximum value is set, +then the default value of 1 second will be displayed. Supplying a 0 will +reset the value back to the default. + +If *--live* is specified, affect a running guest. +If *--config* is specified, affect the next start of a persistent guest. +If *--current* is specified, it is equivalent to either *--live* or +*--config*, depending on the current state of the guest. +When setting the disk io parameters both *--live* and *--config* flags may= be +given, but *--current* is exclusive. If no flag is specified, behavior +is different depending on hypervisor. + + +domthrottlegroupdel +------------------- + +**Syntax:** + +:: + + domthrottlegroupdel domain group-name [[--config] [--live] | [--current= ]] + +Delete a Throttlegroup from the domain using the specified *group-name*. +If an Throttlegroup is currently referenced by a disk resource such as via= the +``attach-disk`` command, then the attempt to remove the Throttlegroup will= fail. +If the *group-name* does not exist an error will occur. + +If *--live* is specified, affect a running guest. If the guest is not +running an error is returned. +If *--config* is specified, affect the next start of a persistent guest. +If *--current* is specified, it is equivalent to either *--live* or +*--config*, depending on the current state of the guest. + + +domthrottlegroupinfo +-------------------- + +**Syntax:** + +:: + + domthrottlegroupinfo domain group-name [[--config] [--live] | [--curren= t]] + +Display domain Throttlegroup information including I/O limits setting. + +If *--live* is specified, get the Throttlegroup data from the running gues= t. If +the guest is not running, an error is returned. +If *--config* is specified, get the Throttlegroup data from the next start= of +a persistent guest. +If *--current* is specified or *--live* and *--config* are not specified, +then get the Throttlegroup data based on the current guest state, which can +either be live or offline. + + +domthrottlegrouplist +-------------------- + +**Syntax:** + +:: + + domthrottlegrouplist domain [--inactive] + +Print a table showing names of all throttle groups +associated with *domain*. If *--inactive* is specified, query the +block devices that will be used on the next boot, rather than those +currently in use by a running domain. + + blkiotune --------- =20 diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c index 61362224a3..3b0df15c13 100644 --- a/tools/virsh-completer-domain.c +++ b/tools/virsh-completer-domain.c @@ -248,6 +248,61 @@ virshDomainMigrateDisksCompleter(vshControl *ctl, } =20 =20 +int +virshGetThrottleGroupNames(xmlXPathContext *ctxt, + xmlNodePtr **groups, + char ***groupNames) +{ + int ngroups; + size_t i; + + ngroups =3D virXPathNodeSet("./throttlegroups/throttlegroup", ctxt, gr= oups); + if (ngroups < 0) + return -1; + + *groupNames =3D g_new0(char *, ngroups + 1); + + for (i =3D 0; i < ngroups; i++) { + ctxt->node =3D (*groups)[i]; + if (!((*groupNames)[i] =3D virXPathString("string(./group_name)", = ctxt))) { + g_strfreev(*groupNames); + *groupNames =3D NULL; + return -1; + } + } + + return ngroups; +} + + +char ** +virshDomainThrottleGroupCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags) +{ + virshControl *priv =3D ctl->privData; + g_autoptr(xmlDoc) xmldoc =3D NULL; + g_autoptr(xmlXPathContext) ctxt =3D NULL; + g_autofree xmlNodePtr *groups =3D NULL; + g_auto(GStrv) groupNames =3D NULL; + int ngroups; + + virCheckFlags(0, NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) + return NULL; + + if (virshDomainGetXML(ctl, cmd, 0, &xmldoc, &ctxt) < 0) + return NULL; + + ngroups =3D virshGetThrottleGroupNames(ctxt, &groups, &groupNames); + if (ngroups < 0) + return NULL; + + return g_steal_pointer(&groupNames); +} + + char ** virshDomainUndefineStorageDisksCompleter(vshControl *ctl, const vshCmd *cmd, diff --git a/tools/virsh-completer-domain.h b/tools/virsh-completer-domain.h index 27cf963912..680b3fc018 100644 --- a/tools/virsh-completer-domain.h +++ b/tools/virsh-completer-domain.h @@ -21,6 +21,7 @@ #pragma once =20 #include "vsh.h" +#include =20 char ** virshDomainNameCompleter(vshControl *ctl, @@ -41,6 +42,16 @@ virshDomainDiskTargetCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); =20 +int +virshGetThrottleGroupNames(xmlXPathContext *ctxt, + xmlNodePtr **groups, + char ***groupNames); + +char ** +virshDomainThrottleGroupCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + char ** virshDomainInterfaceStateCompleter(vshControl *ctl, const vshCmd *cmd, diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 6eea5f176b..b7004979c6 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -1375,7 +1375,7 @@ static const vshCmdOptDef opts_blkdeviotune[] =3D { VIRSH_COMMON_OPT_DOMAIN_CURRENT, {.name =3D NULL} }; -#undef VSH_OPTS_IOTUNE + =20 static bool cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) @@ -1513,6 +1513,329 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) goto cleanup; } =20 + +/* + * "throttlegrouplist" command + */ +static const vshCmdInfo info_throttlegrouplist =3D { + .help =3D N_("list all domain throttlegroups."), + .desc =3D N_("Get the summary of throttle groups for a domain."), +}; + + +static const vshCmdOptDef opts_throttlegrouplist[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "inactive", + .type =3D VSH_OT_BOOL, + .help =3D N_("get inactive rather than running configuration") + }, + {.name =3D NULL} +}; + + +static bool +cmdThrottleGroupList(vshControl *ctl, + const vshCmd *cmd) +{ + unsigned int flags =3D 0; + size_t i; + g_autoptr(xmlDoc) xml =3D NULL; + g_autoptr(xmlXPathContext) ctxt =3D NULL; + g_autofree xmlNodePtr *groups =3D NULL; + g_auto(GStrv) groupNames =3D NULL; + ssize_t ngroups; + g_autoptr(vshTable) table =3D NULL; + + if (vshCommandOptBool(cmd, "inactive")) + flags |=3D VIR_DOMAIN_XML_INACTIVE; + + if (virshDomainGetXML(ctl, cmd, flags, &xml, &ctxt) < 0) + return false; + + table =3D vshTableNew(_("Name"), NULL); + + if (!table) + return false; + + ngroups =3D virshGetThrottleGroupNames(ctxt, &groups, &groupNames); + for (i =3D 0; i < ngroups; i++) { + if (vshTableRowAppend(table, groupNames[i], NULL) < 0) + return false; + } + + vshTablePrintToStdout(table, ctl); + + return true; +} + + +/* + * "throttlegroupset" command + */ +static const vshCmdInfo info_throttlegroupset =3D { + .help =3D N_("Add or update a throttling group."), + .desc =3D N_("Add or updte a throttling group."), +}; + + +static const vshCmdOptDef opts_throttlegroupset[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "group-name", + .type =3D VSH_OT_STRING, + .positional =3D true, + .required =3D true, + .completer =3D virshDomainThrottleGroupCompleter, + .help =3D N_("throttle group name") + }, + VSH_OPTS_IOTUNE(), + VIRSH_COMMON_OPT_DOMAIN_CONFIG, + VIRSH_COMMON_OPT_DOMAIN_LIVE, + VIRSH_COMMON_OPT_DOMAIN_CURRENT, + {.name =3D NULL} +}; +#undef VSH_OPTS_IOTUNE + + +static bool +cmdThrottleGroupSet(vshControl *ctl, + const vshCmd *cmd) +{ + g_autoptr(virshDomain) dom =3D NULL; + const char *group_name =3D NULL; + unsigned long long value; + int nparams =3D 0; + int maxparams =3D 0; + virTypedParameterPtr params =3D NULL; + unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; + int rv =3D 0; + bool current =3D vshCommandOptBool(cmd, "current"); + bool config =3D vshCommandOptBool(cmd, "config"); + bool live =3D vshCommandOptBool(cmd, "live"); + bool ret =3D false; + + VSH_EXCLUSIVE_OPTIONS_VAR(current, live); + VSH_EXCLUSIVE_OPTIONS_VAR(current, config); + + if (config) + flags |=3D VIR_DOMAIN_AFFECT_CONFIG; + if (live) + flags |=3D VIR_DOMAIN_AFFECT_LIVE; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + goto cleanup; + + +#define VSH_SET_THROTTLE_GROUP_SCALED(PARAM, CONST) \ + if ((rv =3D vshCommandOptScaledInt(ctl, cmd, #PARAM, &value, \ + 1, ULLONG_MAX)) < 0) { \ + goto interror; \ + } else if (rv > 0) { \ + if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams, \ + VIR_DOMAIN_BLOCK_IOTUNE_##CONST, \ + value) < 0) \ + goto save_error; \ + } + + VSH_SET_THROTTLE_GROUP_SCALED(total-bytes-sec, TOTAL_BYTES_SEC); + VSH_SET_THROTTLE_GROUP_SCALED(read-bytes-sec, READ_BYTES_SEC); + VSH_SET_THROTTLE_GROUP_SCALED(write-bytes-sec, WRITE_BYTES_SEC); + VSH_SET_THROTTLE_GROUP_SCALED(total-bytes-sec-max, TOTAL_BYTES_SEC_MAX= ); + VSH_SET_THROTTLE_GROUP_SCALED(read-bytes-sec-max, READ_BYTES_SEC_MAX); + VSH_SET_THROTTLE_GROUP_SCALED(write-bytes-sec-max, WRITE_BYTES_SEC_MAX= ); +#undef VSH_SET_THROTTLE_GROUP_SCALED + +#define VSH_SET_THROTTLE_GROUP(PARAM, CONST) \ + if ((rv =3D vshCommandOptULongLong(ctl, cmd, #PARAM, &value)) < 0) { \ + goto interror; \ + } else if (rv > 0) { \ + if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams, \ + VIR_DOMAIN_BLOCK_IOTUNE_##CONST, \ + value) < 0) \ + goto save_error; \ + } + + VSH_SET_THROTTLE_GROUP(total-iops-sec, TOTAL_IOPS_SEC); + VSH_SET_THROTTLE_GROUP(read-iops-sec, READ_IOPS_SEC); + VSH_SET_THROTTLE_GROUP(write-iops-sec, WRITE_IOPS_SEC); + VSH_SET_THROTTLE_GROUP(total-iops-sec-max, TOTAL_IOPS_SEC_MAX); + VSH_SET_THROTTLE_GROUP(read-iops-sec-max, READ_IOPS_SEC_MAX); + VSH_SET_THROTTLE_GROUP(write-iops-sec-max, WRITE_IOPS_SEC_MAX); + VSH_SET_THROTTLE_GROUP(size-iops-sec, SIZE_IOPS_SEC); + + VSH_SET_THROTTLE_GROUP(total-bytes-sec-max-length, TOTAL_BYTES_SEC_MAX= _LENGTH); + VSH_SET_THROTTLE_GROUP(read-bytes-sec-max-length, READ_BYTES_SEC_MAX_L= ENGTH); + VSH_SET_THROTTLE_GROUP(write-bytes-sec-max-length, WRITE_BYTES_SEC_MAX= _LENGTH); + VSH_SET_THROTTLE_GROUP(total-iops-sec-max-length, TOTAL_IOPS_SEC_MAX_L= ENGTH); + VSH_SET_THROTTLE_GROUP(read-iops-sec-max-length, READ_IOPS_SEC_MAX_LEN= GTH); + VSH_SET_THROTTLE_GROUP(write-iops-sec-max-length, WRITE_IOPS_SEC_MAX_L= ENGTH); +#undef VSH_SET_THROTTLE_GROUP + + if (vshCommandOptString(ctl, cmd, "group-name", &group_name) < 0) { + goto cleanup; + } + + if (group_name) { + if (virTypedParamsAddString(¶ms, &nparams, &maxparams, + VIR_DOMAIN_BLOCK_IOTUNE_GROUP_NAME, + group_name) < 0) + goto save_error; + } + + if (virDomainSetThrottleGroup(dom, group_name, params, nparams, flags)= < 0) + goto error; + vshPrintExtra(ctl, "%s", _("Throttle group set successfully\n")); + + ret =3D true; + + cleanup: + virTypedParamsFree(params, nparams); + return ret; + + save_error: + vshSaveLibvirtError(); + error: + vshError(ctl, "%s", _("Unable to set throttle group")); + goto cleanup; + + interror: + vshError(ctl, "%s", _("Unable to parse integer parameter")); + goto cleanup; +} + + +/* + * "throttlegroupdel" command + */ +static const vshCmdInfo info_throttlegroupdel =3D { + .help =3D N_("Delete a throttling group."), + .desc =3D N_("Delete a throttling group."), +}; + + +static const vshCmdOptDef opts_throttlegroupdel[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "group-name", + .type =3D VSH_OT_STRING, + .positional =3D true, + .required =3D true, + .completer =3D virshDomainThrottleGroupCompleter, + .help =3D N_("throttle group name") + }, + VIRSH_COMMON_OPT_DOMAIN_CONFIG, + VIRSH_COMMON_OPT_DOMAIN_LIVE, + VIRSH_COMMON_OPT_DOMAIN_CURRENT, + {.name =3D NULL} +}; + + +static bool +cmdThrottleGroupDel(vshControl *ctl, + const vshCmd *cmd) +{ + g_autoptr(virshDomain) dom =3D NULL; + const char *group_name =3D NULL; + bool config =3D vshCommandOptBool(cmd, "config"); + bool live =3D vshCommandOptBool(cmd, "live"); + bool current =3D vshCommandOptBool(cmd, "current"); + unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; + + VSH_EXCLUSIVE_OPTIONS_VAR(current, live); + VSH_EXCLUSIVE_OPTIONS_VAR(current, config); + + if (config) + flags |=3D VIR_DOMAIN_AFFECT_CONFIG; + if (live) + flags |=3D VIR_DOMAIN_AFFECT_LIVE; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + if (vshCommandOptString(ctl, cmd, "group-name", &group_name) < 0) { + return false; + } + + if (virDomainDelThrottleGroup(dom, group_name, flags) < 0) + return false; + vshPrintExtra(ctl, "%s", _("Throttle group deleted successfully\n")); + + return true; +} + + +/* + * "throttlegroupinfo" command + */ +static const vshCmdInfo info_throttlegroupinfo =3D { + .help =3D N_("Get a throttling group."), + .desc =3D N_("Get a throttling group."), +}; + + +static const vshCmdOptDef opts_throttlegroupinfo[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "group-name", + .type =3D VSH_OT_STRING, + .positional =3D true, + .required =3D true, + .completer =3D virshDomainThrottleGroupCompleter, + .help =3D N_("throttle group name") + }, + VIRSH_COMMON_OPT_DOMAIN_CONFIG, + VIRSH_COMMON_OPT_DOMAIN_LIVE, + VIRSH_COMMON_OPT_DOMAIN_CURRENT, + {.name =3D NULL} +}; + + +static bool +cmdThrottleGroupInfo(vshControl *ctl, + const vshCmd *cmd) +{ + g_autoptr(virshDomain) dom =3D NULL; + const char *group_name =3D NULL; + int nparams =3D 0; + virTypedParameterPtr params =3D NULL; + unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; + size_t i; + bool current =3D vshCommandOptBool(cmd, "current"); + bool config =3D vshCommandOptBool(cmd, "config"); + bool live =3D vshCommandOptBool(cmd, "live"); + bool ret =3D false; + + VSH_EXCLUSIVE_OPTIONS_VAR(current, live); + VSH_EXCLUSIVE_OPTIONS_VAR(current, config); + + if (config) + flags |=3D VIR_DOMAIN_AFFECT_CONFIG; + if (live) + flags |=3D VIR_DOMAIN_AFFECT_LIVE; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + goto cleanup; + + if (vshCommandOptString(ctl, cmd, "group-name", &group_name) < 0) { + goto cleanup; + } + + if (virDomainGetThrottleGroup(dom, group_name, ¶ms, &nparams, flag= s) !=3D 0) { + vshError(ctl, "%s", + _("Unable to get throttle group parameters")); + goto cleanup; + } + + for (i =3D 0; i < nparams; i++) { + g_autofree char *str =3D vshGetTypedParamValue(ctl, ¶ms[i]); + vshPrint(ctl, "%-15s: %s\n", params[i].field, str); + } + + ret =3D true; + + cleanup: + virTypedParamsFree(params, nparams); + return ret; +} + + /* * "blkiotune" command */ @@ -13408,6 +13731,30 @@ const vshCmdDef domManagementCmds[] =3D { .info =3D &info_blkdeviotune, .flags =3D 0 }, + {.name =3D "domthrottlegroupset", + .handler =3D cmdThrottleGroupSet, + .opts =3D opts_throttlegroupset, + .info =3D &info_throttlegroupset, + .flags =3D 0 + }, + {.name =3D "domthrottlegroupdel", + .handler =3D cmdThrottleGroupDel, + .opts =3D opts_throttlegroupdel, + .info =3D &info_throttlegroupdel, + .flags =3D 0 + }, + {.name =3D "domthrottlegroupinfo", + .handler =3D cmdThrottleGroupInfo, + .opts =3D opts_throttlegroupinfo, + .info =3D &info_throttlegroupinfo, + .flags =3D 0 + }, + {.name =3D "domthrottlegrouplist", + .handler =3D cmdThrottleGroupList, + .opts =3D opts_throttlegrouplist, + .info =3D &info_throttlegrouplist, + .flags =3D 0 + }, {.name =3D "blkiotune", .handler =3D cmdBlkiotune, .opts =3D opts_blkiotune, --=20 2.39.5 (Apple Git-154)