From nobody Thu Sep 19 01:04:09 2024 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=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 1718187215885460.6412175035492; Wed, 12 Jun 2024 03:13:35 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 87109C84; Wed, 12 Jun 2024 06:13:34 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 68187E7A; Wed, 12 Jun 2024 06:04:34 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 0B98211B3; Wed, 12 Jun 2024 06:04:29 -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 4B03AB7F for ; Wed, 12 Jun 2024 06:04:05 -0400 (EDT) Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45C8TZlV032620 for ; Wed, 12 Jun 2024 10:04:04 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 3yq86x08gr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 12 Jun 2024 10:04:04 +0000 (GMT) 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 45C8p4Di008879 for ; Wed, 12 Jun 2024 10:04:03 GMT Received: from smtprelay04.wdc07v.mail.ibm.com ([172.16.1.71]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3yn4b3c1ve-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 12 Jun 2024 10:04:03 +0000 Received: from smtpav06.dal12v.mail.ibm.com (smtpav06.dal12v.mail.ibm.com [10.241.53.105]) by smtprelay04.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 45CA40Xs38470266 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Jun 2024 10:04:02 GMT Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1875C5805E; Wed, 12 Jun 2024 10:04:00 +0000 (GMT) Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2B8B458059; Wed, 12 Jun 2024 10:03:59 +0000 (GMT) Received: from libvirt-dev-u221.fyre.ibm.com (unknown [9.112.252.183]) by smtpav06.dal12v.mail.ibm.com (Postfix) with ESMTP; Wed, 12 Jun 2024 10:03:58 +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.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=pp1; bh=Mt/BynOuZFgkb CxKj/JPEqzZ5wr9B1AIhdyK+yDvP28=; b=Z92s50RL4emL0Kw3fFYgeFHCvYVwK EQODz+3KhqeDtvyMIEDCn3nfmjP3TCgS8/p+kbBm9tnS1ru9soO1TBnv/GaAjqFN S/nvmruCoru+1YipCcqOKVQNs95YNa6OFcgbju7zfvBCsR06gUjbb7P76NBFcgxF VG2/25Zn60zE4Q/qLF99Dak3M3y5wMYqIBvx70NBQ+wQEZBz8Lkdp7W0ZEsFBY7M diZ55eoRNwkhP7lqEczIHLWILTno82oa9IqXaHmuMlJc0nu11mMtRhN6tto1zNur ByOygbm9/0POHEnr2aJkAwW/osXCpzCLRWpOSqV1veCenO44AtI+qltZA== From: wucf@linux.ibm.com To: devel@lists.libvirt.org Cc: Chun Feng Wu Subject: [PATCH RFC v3 16/16] virsh: Add option "throttle-groups" to "attach_disk" Date: Wed, 12 Jun 2024 03:02:24 -0700 Message-Id: <20240612100224.2024439-17-wucf@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240612100224.2024439-1-wucf@linux.ibm.com> References: <20240612100224.2024439-1-wucf@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: qXX2E0yLoAeXuQbjHYMDaJ4mjBvtSDcy X-Proofpoint-ORIG-GUID: qXX2E0yLoAeXuQbjHYMDaJ4mjBvtSDcy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-12_06,2024-06-11_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=884 clxscore=1015 phishscore=0 malwarescore=0 adultscore=0 mlxscore=0 spamscore=0 suspectscore=0 bulkscore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2406120071 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: TD6LGLLOD3ZB22IC3LG435WEEKJTZQJU X-Message-ID-Hash: TD6LGLLOD3ZB22IC3LG435WEEKJTZQJU 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: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1718187217679100001 Content-Type: text/plain; charset="utf-8" From: Chun Feng Wu * 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 | 5 +++ tools/virsh-domain.c | 25 ++++++++++++- 3 files changed, 93 insertions(+), 1 deletion(-) diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c index 61362224a3..000cf65c99 100644 --- a/tools/virsh-completer-domain.c +++ b/tools/virsh-completer-domain.c @@ -248,6 +248,70 @@ virshDomainMigrateDisksCompleter(vshControl *ctl, } =20 =20 +static 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..95ec3e28df 100644 --- a/tools/virsh-completer-domain.h +++ b/tools/virsh-completer-domain.h @@ -41,6 +41,11 @@ virshDomainDiskTargetCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); =20 +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 f84a65451a..ec2330c8dd 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,6 +616,8 @@ 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_str =3D NULL; + g_autofree char **throttle_groups =3D NULL; int ret; unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; const char *stype =3D NULL; @@ -622,6 +629,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 +673,14 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) vshCommandOptString(ctl, cmd, "source-protocol", &source_protocol)= < 0 || vshCommandOptString(ctl, cmd, "source-host-name", &host_name) < 0 = || vshCommandOptString(ctl, cmd, "source-host-transport", &host_trans= port) < 0 || - vshCommandOptString(ctl, cmd, "source-host-socket", &host_socket) = < 0) + vshCommandOptString(ctl, cmd, "source-host-socket", &host_socket) = < 0 || + vshCommandOptString(ctl, cmd, "throttle-groups", &throttle_groups_= str) < 0) return false; =20 + if (throttle_groups_str) { + throttle_groups =3D g_strsplit(throttle_groups_str, ",", 0); + } + if (stype && (type =3D virshAttachDiskSourceTypeFromString(stype)) < 0) { vshError(ctl, _("Unknown source type: '%1$s'"), stype); @@ -714,6 +727,16 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) =20 virXMLFormatElement(&diskChildBuf, "driver", &driverAttrBuf, NULL); =20 + if (throttle_groups) { + char **iter; + for (iter =3D throttle_groups; *iter !=3D NULL; iter++) { + g_auto(virBuffer) throttleAttrBuf =3D VIR_BUFFER_INITIALIZER; + virBufferAsprintf(&throttleAttrBuf, " group=3D'%s'", *iter); + 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); --=20 2.34.1