From nobody Mon Feb 9 08:29:50 2026 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=reject dis=none) header.from=linux.ibm.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1712888416916491.1174901087975; Thu, 11 Apr 2024 19:20:16 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id DC50A17DB; Thu, 11 Apr 2024 22:20:15 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 41CAC1797; Thu, 11 Apr 2024 22:04:55 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 869F117D6; Thu, 11 Apr 2024 22:04:46 -0400 (EDT) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 0176B1805 for ; Thu, 11 Apr 2024 22:03:23 -0400 (EDT) Received: from pps.filterd (m0353724.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43C1L1lp013654 for ; Fri, 12 Apr 2024 02:03:23 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xet2p05rs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 12 Apr 2024 02:03:23 +0000 Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 43BNK9nC016971 for ; Fri, 12 Apr 2024 02:03:22 GMT Received: from smtprelay04.dal12v.mail.ibm.com ([172.16.1.6]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3xbke2xpcd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 12 Apr 2024 02:03:22 +0000 Received: from smtpav05.dal12v.mail.ibm.com (smtpav05.dal12v.mail.ibm.com [10.241.53.104]) by smtprelay04.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 43C23J0F21299840 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Apr 2024 02:03:21 GMT Received: from smtpav05.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A8A145805D; Fri, 12 Apr 2024 02:03:19 +0000 (GMT) Received: from smtpav05.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AAC9E58056; Fri, 12 Apr 2024 02:03:18 +0000 (GMT) Received: from libvirt-dev-u221.fyre.ibm.com (unknown [9.112.252.183]) by smtpav05.dal12v.mail.ibm.com (Postfix) with ESMTP; Fri, 12 Apr 2024 02:03:18 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 From: wucf@linux.ibm.com To: devel@lists.libvirt.org Cc: Chun Feng Wu Subject: [PATCH RFC v2 10/12] virsh: Add support for throttle group operations Date: Thu, 11 Apr 2024 19:01:58 -0700 Message-Id: <20240412020200.2418776-11-wucf@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240412020200.2418776-1-wucf@linux.ibm.com> References: <20240412020200.2418776-1-wucf@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: D1uX8FG_bm3AulBRy4q1aetXlKrK-m9b X-Proofpoint-GUID: D1uX8FG_bm3AulBRy4q1aetXlKrK-m9b X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-11_14,2024-04-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 spamscore=0 impostorscore=0 priorityscore=1501 adultscore=0 lowpriorityscore=0 clxscore=1015 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404120013 Message-ID-Hash: LMJ4DRJL7AZYD7MUSGUP43MRI36PITE5 X-Message-ID-Hash: LMJ4DRJL7AZYD7MUSGUP43MRI36PITE5 X-MailFrom: wucf@linux.ibm.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 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: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1712888418638100001 From: Chun Feng Wu * Add new cmds: throttlegroupset, throttlegrouplist, throttlegroupinfo, thr= ottlegroupdel * Update "attach_disk" to support new option: throttle-groups to form filter chain in QEMU for specific disk Signed-off-by: Chun Feng Wu --- tools/virsh-completer-domain.c | 64 +++++ tools/virsh-completer-domain.h | 10 + tools/virsh-domain.c | 471 +++++++++++++++++++++++++++++++++ 3 files changed, 545 insertions(+) diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c index 2891d1399c..e4e5775c5c 100644 --- a/tools/virsh-completer-domain.c +++ b/tools/virsh-completer-domain.c @@ -248,6 +248,70 @@ virshDomainMigrateDisksCompleter(vshControl *ctl, } =20 =20 +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; + int ngroups; + size_t i; + g_auto(GStrv) tmp =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; + + ngroups =3D virXPathNodeSet("./throttlegroups/throttlegroup", ctxt, &g= roups); + if (ngroups < 0) + return NULL; + + tmp =3D g_new0(char *, ngroups + 1); + + for (i =3D 0; i < ngroups; i++) { + ctxt->node =3D groups[i]; + if (!(tmp[i] =3D virXPathString("string(./group_name)", ctxt))) + return NULL; + } + + return g_steal_pointer(&tmp); +} + + +static char ** +virshDomainThrottleGroupListCompleter(vshControl *ctl, + const vshCmd *cmd, + const char *argname) +{ + const char *curval =3D NULL; + g_auto(GStrv) groups =3D virshDomainThrottleGroupCompleter(ctl, cmd, 0= ); + + if (vshCommandOptStringQuiet(ctl, cmd, argname, &curval) < 0) + return NULL; + + if (!groups) + return NULL; + + return virshCommaStringListComplete(curval, (const char **) groups); +} + + +char ** +virshDomainThrottleGroupsCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int completeflags G_GNUC_UNUSE= D) +{ + return virshDomainThrottleGroupListCompleter(ctl, cmd, "throttle-group= s"); +} + + char ** virshDomainUndefineStorageDisksCompleter(vshControl *ctl, const vshCmd *cmd, diff --git a/tools/virsh-completer-domain.h b/tools/virsh-completer-domain.h index 27cf963912..4ac29c4876 100644 --- a/tools/virsh-completer-domain.h +++ b/tools/virsh-completer-domain.h @@ -41,6 +41,16 @@ virshDomainDiskTargetCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); =20 +char ** +virshDomainThrottleGroupCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + +char ** +virshDomainThrottleGroupsCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int completeflags); + char ** virshDomainInterfaceStateCompleter(vshControl *ctl, const vshCmd *cmd, diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 3d9c48629a..07a53a9a4c 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -522,6 +522,11 @@ static const vshCmdOptDef opts_attach_disk[] =3D { .type =3D VSH_OT_STRING, .help =3D N_("host socket for source of disk device") }, + {.name =3D "throttle-groups", + .type =3D VSH_OT_STRING, + .completer =3D virshDomainThrottleGroupsCompleter, + .help =3D N_("comma separated list of throttle groups to be applied") + }, VIRSH_COMMON_OPT_DOMAIN_PERSISTENT, VIRSH_COMMON_OPT_DOMAIN_CONFIG, VIRSH_COMMON_OPT_DOMAIN_LIVE, @@ -611,7 +616,10 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) const char *host_name =3D NULL; const char *host_transport =3D NULL; const char *host_socket =3D NULL; + const char *throttle_groups =3D NULL; + g_autofree char **groups =3D NULL; int ret; + size_t i; unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; const char *stype =3D NULL; int type =3D VIR_STORAGE_TYPE_NONE; @@ -622,6 +630,7 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) g_auto(virBuffer) sourceAttrBuf =3D VIR_BUFFER_INITIALIZER; g_auto(virBuffer) sourceChildBuf =3D VIR_BUFFER_INIT_CHILD(&diskChildB= uf); g_auto(virBuffer) hostAttrBuf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) throttleChildBuf =3D VIR_BUFFER_INITIALIZER; g_autofree char *xml =3D NULL; struct stat st; bool current =3D vshCommandOptBool(cmd, "current"); @@ -665,9 +674,14 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) vshCommandOptStringReq(ctl, cmd, "source-protocol", &source_protoc= ol) < 0 || vshCommandOptStringReq(ctl, cmd, "source-host-name", &host_name) <= 0 || vshCommandOptStringReq(ctl, cmd, "source-host-transport", &host_tr= ansport) < 0 || + vshCommandOptStringReq(ctl, cmd, "throttle-groups", &throttle_grou= ps) < 0 || vshCommandOptStringReq(ctl, cmd, "source-host-socket", &host_socke= t) < 0) return false; =20 + if (throttle_groups) { + groups =3D g_strsplit(throttle_groups, ",", 0); + } + if (stype && (type =3D virshAttachDiskSourceTypeFromString(stype)) < 0) { vshError(ctl, _("Unknown source type: '%1$s'"), stype); @@ -714,6 +728,15 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) =20 virXMLFormatElement(&diskChildBuf, "driver", &driverAttrBuf, NULL); =20 + if (groups) { + for (i =3D 0; i < (g_strv_length(groups)); i++) { + g_auto(virBuffer) throttleAttrBuf =3D VIR_BUFFER_INITIALIZER; + virBufferAsprintf(&throttleAttrBuf, " group=3D'%s'", groups[i]= ); + virXMLFormatElement(&throttleChildBuf, "throttlefilter", &thro= ttleAttrBuf, NULL); + } + virXMLFormatElement(&diskChildBuf, "throttlefilters", NULL, &throt= tleChildBuf); + } + switch ((enum virshAttachDiskSourceType) type) { case VIRSH_ATTACH_DISK_SOURCE_TYPE_FILE: virBufferEscapeString(&sourceAttrBuf, " file=3D'%s'", source); @@ -1509,6 +1532,430 @@ 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; + 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; + + ngroups =3D virXPathNodeSet("./throttlegroups/throttlegroup", ctxt, &g= roups); + if (ngroups < 0) + return false; + + table =3D vshTableNew(_("Name"), NULL); + + if (!table) + return false; + + for (i =3D 0; i < ngroups; i++) { + g_autofree char *name =3D NULL; + ctxt->node =3D groups[i]; + name =3D virXPathString("string(./group_name)", ctxt); + if (vshTableRowAppend(table, name, 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 virshCompleteEmpty, + .help =3D N_("throttle group name") + }, + {.name =3D "total-bytes-sec", + .type =3D VSH_OT_INT, + .help =3D N_("total throughput limit, as scaled integer (default byte= s)") + }, + {.name =3D "read-bytes-sec", + .type =3D VSH_OT_INT, + .help =3D N_("read throughput limit, as scaled integer (default bytes= )") + }, + {.name =3D "write-bytes-sec", + .type =3D VSH_OT_INT, + .help =3D N_("write throughput limit, as scaled integer (default byt= es)") + }, + {.name =3D "total-iops-sec", + .type =3D VSH_OT_INT, + .help =3D N_("total I/O operations limit per second") + }, + {.name =3D "read-iops-sec", + .type =3D VSH_OT_INT, + .help =3D N_("read I/O operations limit per second") + }, + {.name =3D "write-iops-sec", + .type =3D VSH_OT_INT, + .help =3D N_("write I/O operations limit per second") + }, + {.name =3D "total-bytes-sec-max", + .type =3D VSH_OT_INT, + .help =3D N_("total max, as scaled integer (default bytes)") + }, + {.name =3D "read-bytes-sec-max", + .type =3D VSH_OT_INT, + .help =3D N_("read max, as scaled integer (default bytes)") + }, + {.name =3D "write-bytes-sec-max", + .type =3D VSH_OT_INT, + .help =3D N_("write max, as scaled integer (default bytes)") + }, + {.name =3D "total-iops-sec-max", + .type =3D VSH_OT_INT, + .help =3D N_("total I/O operations max") + }, + {.name =3D "read-iops-sec-max", + .type =3D VSH_OT_INT, + .help =3D N_("read I/O operations max") + }, + {.name =3D "write-iops-sec-max", + .type =3D VSH_OT_INT, + .help =3D N_("write I/O operations max") + }, + {.name =3D "size-iops-sec", + .type =3D VSH_OT_INT, + .help =3D N_("I/O size in bytes") + }, + {.name =3D "total-bytes-sec-max-length", + .type =3D VSH_OT_INT, + .help =3D N_("duration in seconds to allow total max bytes") + }, + {.name =3D "read-bytes-sec-max-length", + .type =3D VSH_OT_INT, + .help =3D N_("duration in seconds to allow read max bytes") + }, + {.name =3D "write-bytes-sec-max-length", + .type =3D VSH_OT_INT, + .help =3D N_("duration in seconds to allow write max bytes") + }, + {.name =3D "total-iops-sec-max-length", + .type =3D VSH_OT_INT, + .help =3D N_("duration in seconds to allow total I/O operations max") + }, + {.name =3D "read-iops-sec-max-length", + .type =3D VSH_OT_INT, + .help =3D N_("duration in seconds to allow read I/O operations max") + }, + {.name =3D "write-iops-sec-max-length", + .type =3D VSH_OT_INT, + .help =3D N_("duration in seconds to allow write I/O operations max") + }, + VIRSH_COMMON_OPT_DOMAIN_CONFIG, + VIRSH_COMMON_OPT_DOMAIN_LIVE, + VIRSH_COMMON_OPT_DOMAIN_CURRENT, + {.name =3D NULL} +}; + + +static bool +cmdThrottleGroupSet(vshControl *ctl, + const vshCmd *cmd) +{ + g_autoptr(virshDomain) dom =3D NULL; + const char *name; + 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, &name))) + 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 (vshCommandOptStringReq(ctl, cmd, "group-name", &group_name) < 0) { + vshError(ctl, "%s", _("Unable to parse group-name parameter")); + 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 change 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 virshCompleteEmpty, + .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 (vshCommandOptStringReq(ctl, cmd, "group-name", &group_name) < 0) { + vshError(ctl, "%s", _("Unable to parse group-name parameter")); + 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 virshCompleteEmpty, + .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 *name; + 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, &name))) + goto cleanup; + + if (vshCommandOptStringReq(ctl, cmd, "group-name", &group_name) < 0) { + vshError(ctl, "%s", _("Unable to parse group-name parameter")); + goto cleanup; + } + + /* Get number of params */ + if (nparams =3D=3D 0) { + if (virDomainGetThrottleGroup(dom, NULL, NULL, &nparams, flags) != =3D 0) { + vshError(ctl, "%s", + _("Unable to get number of throttle group parameters"= )); + goto cleanup; + } + + if (nparams =3D=3D 0) { + ret =3D true; + goto cleanup; + } + + params =3D g_new0(virTypedParameter, nparams); + } + + /* Request with nparams */ + if (virDomainGetThrottleGroup(dom, group_name, params, &nparams, flags= ) !=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 */ @@ -13423,6 +13870,30 @@ const vshCmdDef domManagementCmds[] =3D { .info =3D &info_blkdeviotune, .flags =3D 0 }, + {.name =3D "throttlegroupset", + .handler =3D cmdThrottleGroupSet, + .opts =3D opts_throttlegroupset, + .info =3D &info_throttlegroupset, + .flags =3D 0 + }, + {.name =3D "throttlegroupdel", + .handler =3D cmdThrottleGroupDel, + .opts =3D opts_throttlegroupdel, + .info =3D &info_throttlegroupdel, + .flags =3D 0 + }, + {.name =3D "throttlegroupinfo", + .handler =3D cmdThrottleGroupInfo, + .opts =3D opts_throttlegroupinfo, + .info =3D &info_throttlegroupinfo, + .flags =3D 0 + }, + {.name =3D "throttlegrouplist", + .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.34.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org