From nobody Fri Dec 19 16:06:25 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=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1742320004; cv=none; d=zohomail.com; s=zohoarc; b=FEbn9xRbyAez52ZQPbK0LyXXGYfnBOo+FnnaLcVXJdimIbEjXR3fzTeFyDtwIq8xk6KtW/6lERT6dxi0lvkYpjrF4VyUvwjL3pMSy5PufWoPi/nvJCcxcfXqfTbIwGBI8b0kNQtjWxxXR0gKO/32HkLPTxvTqoM7I6bDzmDeEfA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1742320004; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=nf5gOJOj64Suh+h1EJ31kcjez5cDHHMH4mJECWIUyvU=; b=I0aVebpgLbgzP0uKgd//J2pJIxdtQbrq9EJ8vgttpsPWmnj+gu2mwoo0rECgAxD02w8+E22VP2jQoxExPwXOYGZ9BpGrUamq6SymC7TUD3uXXFxvBuaHtBJkPTyoN6Uo978g+UFtMRlUpok/VFxdn+HywBKPZ1KURN7eqsI4RRo= ARC-Authentication-Results: i=1; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1742320004504939.3352958591145; Tue, 18 Mar 2025 10:46:44 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id ECA1B108B; Tue, 18 Mar 2025 13:46:43 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id E8413173D; Tue, 18 Mar 2025 13:35:40 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 487D116D2; Tue, 18 Mar 2025 13:35:30 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 1A7DA172E for ; Tue, 18 Mar 2025 13:35:07 -0400 (EDT) Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-36-AzXqMXbVOKeSH6419qHn9Q-1; Tue, 18 Mar 2025 13:35:05 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7B2C51955DAC; Tue, 18 Mar 2025 17:35:04 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.6]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 281CE3001D11; Tue, 18 Mar 2025 17:35:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, 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=redhat.com; s=mimecast20190719; t=1742319306; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mFT+0af5PLlzlQDb1n9ptQO59oPZGocgRnl1wk4m8uU=; b=geaZqOKMRWUH+e3UW0tjDo9/ubNpoHbnidYflbnKU/uQ3uop7+rM/WGEMpT3nPJt2UhoUd 0D9uiMkFThyYDN0t6++ROVTem1AhSuYKz0jyXqdlEOdugYSeBZ3EeIXIKJ79iz+n8f20u4 A1J1jcUH34tjsfeGlAYeWZs+TeWOqsk= X-MC-Unique: AzXqMXbVOKeSH6419qHn9Q-1 X-Mimecast-MFC-AGG-ID: AzXqMXbVOKeSH6419qHn9Q_1742319304 To: devel@lists.libvirt.org Subject: [PATCH v9 16/17] virsh: Add support for throttle group operations Date: Tue, 18 Mar 2025 18:34:30 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: gFQeF0j2LipjzK66Z1YtNHoBQeGJmjwwbSdZp-rvZl8_1742319304 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: BG67TYD2PS2WHDLZSALV7VZLV5C3HIEW X-Message-ID-Hash: BG67TYD2PS2WHDLZSALV7VZLV5C3HIEW X-MailFrom: pkrempa@redhat.com 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; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Harikumar Rajkumar , harikumar.rajkumar@ibm.com 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: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1742320006405019000 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 * Update of code documentation comments. * Reimplement Get throttle group from XML. Signed-off-by: Harikumar Rajkumar a * Fixed memleaks * Rewrote getter to avoid extra copies * Simplified name extractor Reviewed-by: Peter Krempa Signed-off-by: Peter Krempa --- docs/manpages/virsh.rst | 134 ++++++++++++ tools/virsh-completer-domain.c | 45 ++++ tools/virsh-completer-domain.h | 9 + tools/virsh-domain.c | 368 ++++++++++++++++++++++++++++++++- 4 files changed, 555 insertions(+), 1 deletion(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index baced15dec..621c02fdbd 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -1139,6 +1139,140 @@ given, but *--current* is exclusive. For querying o= nly one of *--live*, is different depending on hypervisor. +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. + +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* +are specified, both live configuration and config are updated while setting +the description, but *--current* is exclusive. If no flag is specified, be= havior +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, then the a= ttempt +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. +If both *--live* and *--config* are specified, the *--config* option takes +precedence on getting the current description. + + +domthrottlegrouplist +-------------------- + +**Syntax:** + +:: + + domthrottlegrouplist domain [--inactive] + +Print a table showing names of all throttle groups +associated with *domain*. If *--inactive* is specified, query the +Throttlegroup data that will be used on the next boot, rather than those +currently in use by a running domain. + + blkiotune --------- diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c index 61362224a3..8c5fbb1e1b 100644 --- a/tools/virsh-completer-domain.c +++ b/tools/virsh-completer-domain.c @@ -248,6 +248,51 @@ virshDomainMigrateDisksCompleter(vshControl *ctl, } +char ** +virshGetThrottleGroupNames(xmlXPathContext *ctxt) +{ + g_auto(GStrv) groupNames =3D NULL; + g_autofree xmlNodePtr *groups =3D NULL; + int ngroups; + size_t i; + + if ((ngroups =3D virXPathNodeSet("./throttlegroups/throttlegroup", ctx= t, &groups)) < 0) + return NULL; + + 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)", ctx= t))) + return NULL; + } + + return g_steal_pointer(&groupNames); +} + + +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; + + virCheckFlags(0, NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) + return NULL; + + if (virshDomainGetXML(ctl, cmd, 0, &xmldoc, &ctxt) < 0) + return NULL; + + return virshGetThrottleGroupNames(ctxt); +} + + char ** virshDomainUndefineStorageDisksCompleter(vshControl *ctl, const vshCmd *cmd, diff --git a/tools/virsh-completer-domain.h b/tools/virsh-completer-domain.h index 27cf963912..82c907e4fe 100644 --- a/tools/virsh-completer-domain.h +++ b/tools/virsh-completer-domain.h @@ -21,6 +21,7 @@ #pragma once #include "vsh.h" +#include char ** virshDomainNameCompleter(vshControl *ctl, @@ -41,6 +42,14 @@ virshDomainDiskTargetCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); +char ** +virshGetThrottleGroupNames(xmlXPathContext *ctxt); + +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 755a9b63e4..e5f9cc0ea9 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -1374,7 +1374,7 @@ static const vshCmdOptDef opts_blkdeviotune[] =3D { VIRSH_COMMON_OPT_DOMAIN_CURRENT, {.name =3D NULL} }; -#undef VSH_OPTS_IOTUNE + static bool cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) @@ -1512,6 +1512,348 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) goto cleanup; } + +/* + * "domthrottlegrouplist" command + */ +static const vshCmdInfo info_domthrottlegrouplist =3D { + .help =3D N_("list all domain throttlegroups."), + .desc =3D N_("Get the summary of throttle groups for a domain."), +}; + + +static const vshCmdOptDef opts_domthrottlegrouplist[] =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; + g_autoptr(xmlDoc) xml =3D NULL; + g_autoptr(xmlXPathContext) ctxt =3D NULL; + g_auto(GStrv) groupNames =3D NULL; + char **n; + 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; + + if (!(table =3D vshTableNew(_("Name"), NULL))) + return false; + + if (!(groupNames =3D virshGetThrottleGroupNames(ctxt))) + return false; + + for (n =3D groupNames; *n; n++) { + if (vshTableRowAppend(table, *n, NULL) < 0) + return false; + } + + vshTablePrintToStdout(table, ctl); + + return true; +} + + +/* + * "domthrottlegroupset" command + */ +static const vshCmdInfo info_domthrottlegroupset =3D { + .help =3D N_("Add or update a throttling group."), + .desc =3D N_("Add or updte a throttling group."), +}; + + +static const vshCmdOptDef opts_domthrottlegroupset[] =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; +} + + +/* + * "domthrottlegroupdel" command + */ +static const vshCmdInfo info_domthrottlegroupdel =3D { + .help =3D N_("Delete a throttling group."), + .desc =3D N_("Delete a throttling group."), +}; + + +static const vshCmdOptDef opts_domthrottlegroupdel[] =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; +} + + +/* + * "domthrottlegroupinfo" command + */ +static const vshCmdInfo info_domthrottlegroupinfo =3D { + .help =3D N_("Get a throttling group."), + .desc =3D N_("Get a throttling group."), +}; + + +static const vshCmdOptDef opts_domthrottlegroupinfo[] =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") + }, + {.name =3D "inactive", + .type =3D VSH_OT_BOOL, + .help =3D N_("get inactive rather than running configuration") + }, + {.name =3D NULL} +}; + + +#define PARSE_THROTTLE_GROUP(val) \ + do { \ + g_autofree char *str =3D virXPathString("string(./" #val ")", ctxt= ); \ + if (str) \ + vshPrint(ctl, "%-15s: %s\n", #val, str); \ + } while (false) + +static bool +cmdThrottleGroupInfo(vshControl *ctl, + const vshCmd *cmd) +{ + const char *group_name =3D NULL; + unsigned int flags =3D 0; + g_autoptr(xmlDoc) xml =3D NULL; + g_autoptr(xmlXPathContext) ctxt =3D NULL; + g_autofree xmlNodePtr *node =3D NULL; + int n =3D 0; + size_t i; + + if (vshCommandOptBool(cmd, "inactive")) + flags |=3D VIR_DOMAIN_XML_INACTIVE; + + if (vshCommandOptString(ctl, cmd, "group-name", &group_name) < 0) + return false; + + if (virshDomainGetXML(ctl, cmd, flags, &xml, &ctxt) < 0) + return false; + + if ((n =3D virXPathNodeSet("/domain/throttlegroups/throttlegroup", ctx= t, &node)) < 0) + return false; + + for (i =3D 0; i < n; i++) { + g_autofree char *name =3D NULL; + VIR_XPATH_NODE_AUTORESTORE(ctxt); + ctxt->node =3D node[i]; + + name =3D virXPathString("string(./group_name)", ctxt); + + if (STRNEQ_NULLABLE(group_name, name)) + continue; + + PARSE_THROTTLE_GROUP(total_bytes_sec); + PARSE_THROTTLE_GROUP(read_bytes_sec); + PARSE_THROTTLE_GROUP(write_bytes_sec); + PARSE_THROTTLE_GROUP(total_iops_sec); + PARSE_THROTTLE_GROUP(read_iops_sec); + PARSE_THROTTLE_GROUP(write_iops_sec); + + PARSE_THROTTLE_GROUP(total_bytes_sec_max); + PARSE_THROTTLE_GROUP(read_bytes_sec_max); + PARSE_THROTTLE_GROUP(write_bytes_sec_max); + PARSE_THROTTLE_GROUP(total_iops_sec_max); + PARSE_THROTTLE_GROUP(read_iops_sec_max); + PARSE_THROTTLE_GROUP(write_iops_sec_max); + + PARSE_THROTTLE_GROUP(size_iops_sec); + + PARSE_THROTTLE_GROUP(total_bytes_sec_max_length); + PARSE_THROTTLE_GROUP(read_bytes_sec_max_length); + PARSE_THROTTLE_GROUP(write_bytes_sec_max_length); + PARSE_THROTTLE_GROUP(total_iops_sec_max_length); + PARSE_THROTTLE_GROUP(read_iops_sec_max_length); + PARSE_THROTTLE_GROUP(write_iops_sec_max_length); + } + + return true; +} +#undef PARSE_THROTTLE_GROUP + /* * "blkiotune" command */ @@ -13442,6 +13784,30 @@ const vshCmdDef domManagementCmds[] =3D { .info =3D &info_blkdeviotune, .flags =3D 0 }, + {.name =3D "domthrottlegroupset", + .handler =3D cmdThrottleGroupSet, + .opts =3D opts_domthrottlegroupset, + .info =3D &info_domthrottlegroupset, + .flags =3D 0 + }, + {.name =3D "domthrottlegroupdel", + .handler =3D cmdThrottleGroupDel, + .opts =3D opts_domthrottlegroupdel, + .info =3D &info_domthrottlegroupdel, + .flags =3D 0 + }, + {.name =3D "domthrottlegroupinfo", + .handler =3D cmdThrottleGroupInfo, + .opts =3D opts_domthrottlegroupinfo, + .info =3D &info_domthrottlegroupinfo, + .flags =3D 0 + }, + {.name =3D "domthrottlegrouplist", + .handler =3D cmdThrottleGroupList, + .opts =3D opts_domthrottlegrouplist, + .info =3D &info_domthrottlegrouplist, + .flags =3D 0 + }, {.name =3D "blkiotune", .handler =3D cmdBlkiotune, .opts =3D opts_blkiotune, --=20 2.48.1