From nobody Sat Jan 4 23:27:08 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 1733750577939606.9608811519197; Mon, 9 Dec 2024 05:22:57 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 01A0D12C7; Mon, 9 Dec 2024 08:22:56 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 88AFB131A; Mon, 9 Dec 2024 08:19:56 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 4658A11C7; Mon, 9 Dec 2024 07:42:28 -0500 (EST) Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 5189511CD for ; Mon, 9 Dec 2024 07:42:27 -0500 (EST) Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-215909152c5so48958315ad.3 for ; Mon, 09 Dec 2024 04:42:27 -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.23 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 09 Dec 2024 04:42:25 -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.6 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_H3,RCVD_IN_MSPIKE_WL,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=1733748145; x=1734352945; 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=0N8Glv5C4z1Z16EMN+OiDaqq9J0L2AOFTklx7z0nzTc=; b=MhcDDDPmnB1YYdCcJw01KvqKPi6S/s5b5HHFPYg8mk1dwF/X7LjPhHPwi++eX2JN5M 0npFDoY4asacG13uxOWafZ7SZlG5AgDkLmGWr7StXh10fqvhNnUZWr5LJWymACtD08hs hz4A3s9mcezRZeJPcVZTP/2jGiWTo5ZBzjiSR6bpLo1aKa26fhMHuZ3C7X/MStdbBUqY e91UH4cardgzwCdxzIAadcXH6fnxyBm6tpdyclSgi92Yji1Po/y629HkCUdnr3LCJ5lM v5NsTkFQybzuvQC8Km8VYQwIO0MTj19IsbTqK/ZT9NFhXOkhz2j9BYVd/e6SM3T+ZDzb aKCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733748145; x=1734352945; 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=0N8Glv5C4z1Z16EMN+OiDaqq9J0L2AOFTklx7z0nzTc=; b=UNno1yEl3D5JpvQnVQKfESI2AmQRy2lCK/tBs+s8sQdify6hve/53q1L25UpYFoF7u WiSJkObXPmKk9hAoMsIew7y2SSLvuTq1KrbUySvqUTns46x0s10hS5NRnQOY5eqmeUyP 9i2jeBU8+fj0StzCm9O8q9OsvF/qZCpUWYCf3SOouwefOa2AWyEkWOFP3cCi+Ofe16Fr Uk6dp08lfljQxYPbCepRUF1Q+125Y2kQeODaElLjGEuLGnYA9vtqmhICu8tjKgl9+WyI aG4RJSnvlSCbiCdKAXulTgqP6xRgxigHQgahXZqU5pN4ACNYM7CoB+QbdRz8vIElq/5r TsXQ== X-Gm-Message-State: AOJu0Yy3Dgf1wBz7IhegWgXAPKjbI+8Ba1Cs1MZsYhUylnzx/7E14Ee9 iseLekjLqeJzgLWcBlcnUBJGS9MHS3ZqvyuMLlrrbgrx+piQbFw8DQLi5+02 X-Gm-Gg: ASbGnctPPHkazGWpsZ29CZhd9PS/5G1aothi6W0iMpYY1OwjBGMRkafDnTs+xzlPELx 3UMQs6DufxcarCb26XJCbi3GyGGGrL/FIB9t3D/a8+Smx2+wbzKb3tUpIvu38H20z7a3t2SvxQQ KcxusjFfd7K8HlOqb0VUPdFhR9+4gXycCGxozulkcy6HcYgvlFtgrjeHyXuTnGWqXrk4j6chz7L c+1b8wgOxNRRUxtt87d2TZCnRhhkWjH0X3lhv9uIrABq3HbVkSJh6E20L0HxVo/I0udVUC2L8vN aAa8sA== X-Google-Smtp-Source: AGHT+IFAWtfOqzGHTtheIBkhNiPwCvymHzMRM4bdI2Zvyv+jmm+AxeFFpuWN3RytaOa0Va7f4h1ZCQ== X-Received: by 2002:a17:902:d2d0:b0:216:591a:8544 with SMTP id d9443c01a7336-2166a0224a0mr4828255ad.34.1733748145559; Mon, 09 Dec 2024 04:42:25 -0800 (PST) From: Harikumar R To: devel@lists.libvirt.org Subject: [PATCH v6 03/18] config: Introduce ThrottleGroup and corresponding XML parsing Date: Mon, 9 Dec 2024 18:11:03 +0530 Message-Id: <20241209124118.39471-4-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: VUW7AKTYMM2S7EEVQLY3DN7YE7ON5NQZ X-Message-ID-Hash: VUW7AKTYMM2S7EEVQLY3DN7YE7ON5NQZ X-Mailman-Approved-At: Mon, 09 Dec 2024 13:19:44 -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: 1733750578721116600 Content-Type: text/plain; charset="utf-8" From: Chun Feng Wu Introduce throttlegroup into domain and provide corresponding methods * Define new struct 'virDomainThrottleGroupDef' and corresponding destructor * Add operations(Add, Update, Del, ByName, Copy, Free) for 'virDomainThrott= leGroupDef' * Update _virDomainDef to include virDomainThrottleGroupDef * Support new resource "Parse" and "Format" for operations between struct a= nd DOM XML * Make sure "group_name" is defined in xml Signed-off-by: Chun Feng Wu --- src/conf/domain_conf.c | 293 ++++++++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 27 ++++ src/conf/virconftypes.h | 2 + 3 files changed, 322 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 4ad8289b89..e5a002876f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -3790,6 +3790,32 @@ virDomainIOThreadIDDefArrayInit(virDomainDef *def, } =20 =20 +void +virDomainThrottleGroupDefFree(virDomainThrottleGroupDef *def) +{ + if (!def) + return; + g_free(def->group_name); + g_free(def); +} + + +static void +virDomainThrottleGroupDefArrayFree(virDomainThrottleGroupDef **def, + int nthrottlegroups) +{ + size_t i; + + if (!def) + return; + + for (i =3D 0; i < nthrottlegroups; i++) + virDomainThrottleGroupDefFree(def[i]); + + g_free(def); +} + + void virDomainResourceDefFree(virDomainResourceDef *resource) { @@ -4077,6 +4103,8 @@ void virDomainDefFree(virDomainDef *def) =20 virDomainIOThreadIDDefArrayFree(def->iothreadids, def->niothreadids); =20 + virDomainThrottleGroupDefArrayFree(def->throttlegroups, def->nthrottle= groups); + g_free(def->defaultIOThread); =20 virBitmapFree(def->cputune.emulatorpin); @@ -7822,6 +7850,120 @@ virDomainDiskDefIotuneParse(virDomainDiskDef *def, #undef PARSE_IOTUNE =20 =20 +#define PARSE_THROTTLEGROUP(val) \ + if (virXPathULongLong("string(./" #val ")", \ + ctxt, &group->val) =3D=3D -2) { \ + virReportError(VIR_ERR_XML_ERROR, \ + _("throttle group field '%1$s' must be an integer")= , #val); \ + return NULL; \ + } + + +static virDomainThrottleGroupDef * +virDomainThrottleGroupDefParseXML(xmlNodePtr node, + xmlXPathContextPtr ctxt) +{ + g_autoptr(virDomainThrottleGroupDef) group =3D g_new0(virDomainThrottl= eGroupDef, 1); + + VIR_XPATH_NODE_AUTORESTORE(ctxt) + ctxt->node =3D node; + + PARSE_THROTTLEGROUP(total_bytes_sec); + PARSE_THROTTLEGROUP(read_bytes_sec); + PARSE_THROTTLEGROUP(write_bytes_sec); + PARSE_THROTTLEGROUP(total_iops_sec); + PARSE_THROTTLEGROUP(read_iops_sec); + PARSE_THROTTLEGROUP(write_iops_sec); + + PARSE_THROTTLEGROUP(total_bytes_sec_max); + PARSE_THROTTLEGROUP(read_bytes_sec_max); + PARSE_THROTTLEGROUP(write_bytes_sec_max); + PARSE_THROTTLEGROUP(total_iops_sec_max); + PARSE_THROTTLEGROUP(read_iops_sec_max); + PARSE_THROTTLEGROUP(write_iops_sec_max); + + PARSE_THROTTLEGROUP(size_iops_sec); + + PARSE_THROTTLEGROUP(total_bytes_sec_max_length); + PARSE_THROTTLEGROUP(read_bytes_sec_max_length); + PARSE_THROTTLEGROUP(write_bytes_sec_max_length); + PARSE_THROTTLEGROUP(total_iops_sec_max_length); + PARSE_THROTTLEGROUP(read_iops_sec_max_length); + PARSE_THROTTLEGROUP(write_iops_sec_max_length); + + /* group_name is required */ + if (!(group->group_name =3D virXPathString("string(./group_name)", ctx= t))) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("missing group name")); + return NULL; + } + + return g_steal_pointer(&group); +} +#undef PARSE_THROTTLEGROUP + + +/** + * virDomainThrottleGroupByName: + * @def: domain definition + * @name: throttle group name + * + * search throttle group within domain definition + * by @name + * + * Returns a pointer to throttle group found. + */ +virDomainThrottleGroupDef * +virDomainThrottleGroupByName(const virDomainDef *def, + const char *name) +{ + size_t i; + + if (!def->throttlegroups || def->nthrottlegroups =3D=3D 0) + return NULL; + + for (i =3D 0; i < def->nthrottlegroups; i++) { + if (STREQ(def->throttlegroups[i]->group_name, name)) + return def->throttlegroups[i]; + } + + return NULL; +} + + +static int +virDomainDefThrottleGroupsParse(virDomainDef *def, + xmlXPathContextPtr ctxt) +{ + size_t i; + int n =3D 0; + g_autofree xmlNodePtr *nodes =3D NULL; + + if ((n =3D virXPathNodeSet("./throttlegroups/throttlegroup", ctxt, &no= des)) < 0) + return -1; + + if (n) + def->throttlegroups =3D g_new0(virDomainThrottleGroupDef *, n); + + for (i =3D 0; i < n; i++) { + g_autoptr(virDomainThrottleGroupDef) group =3D NULL; + + if (!(group =3D virDomainThrottleGroupDefParseXML(nodes[i], ctxt))= ) { + return -1; + } + + if (virDomainThrottleGroupByName(def, group->group_name)) { + virReportError(VIR_ERR_XML_ERROR, + _("duplicate group name '%1$s' found"), + group->group_name); + return -1; + } + def->throttlegroups[def->nthrottlegroups++] =3D g_steal_pointer(&g= roup); + } + return 0; +} + + static int virDomainDiskDefMirrorParse(virDomainDiskDef *def, xmlNodePtr cur, @@ -19163,6 +19305,9 @@ virDomainDefParseXML(xmlXPathContextPtr ctxt, if (virDomainDefParseBootOptions(def, ctxt, xmlopt, flags) < 0) return NULL; =20 + if (virDomainDefThrottleGroupsParse(def, ctxt) < 0) + return NULL; + /* analysis of the disk devices */ if ((n =3D virXPathNodeSet("./devices/disk", ctxt, &nodes)) < 0) return NULL; @@ -22438,6 +22583,95 @@ virDomainIOThreadIDDel(virDomainDef *def, } =20 =20 +/** + * virDomainThrottleGroupDefCopy: + * @src: throttle group to be copiped from + * @dst: throttle group to be copiped to + * + * copy throttle group content from @src to @dst + */ +void +virDomainThrottleGroupDefCopy(const virDomainThrottleGroupDef *src, + virDomainThrottleGroupDef *dst) +{ + *dst =3D *src; + dst->group_name =3D g_strdup(src->group_name); +} + + +/** + * virDomainThrottleGroupAdd: + * @def: domain definition + * @throttle_group: throttle group definition within domain + * + * add new throttle group into @def + * + * return a pointer to throttle group added + */ +virDomainThrottleGroupDef * +virDomainThrottleGroupAdd(virDomainDef *def, + virDomainThrottleGroupDef *throttle_group) +{ + virDomainThrottleGroupDef * new_group =3D g_new0(virDomainThrottleGro= upDef, 1); + virDomainThrottleGroupDefCopy(throttle_group, new_group); + VIR_APPEND_ELEMENT_COPY(def->throttlegroups, def->nthrottlegroups, new= _group); + return new_group; +} + + +/** + * virDomainThrottleGroupUpdate: + * @def: domain definition + * @info: throttle group definition within domain + * + * search existing throttle group within domain definition + * by group_name and then overwrite it with @info, + * it's to update existing throttle group + */ +void +virDomainThrottleGroupUpdate(virDomainDef *def, + virDomainThrottleGroupDef *info) +{ + size_t i; + + if (!info->group_name) + return; + + for (i =3D 0; i < def->nthrottlegroups; i++) { + virDomainThrottleGroupDef *t =3D def->throttlegroups[i]; + + if (STREQ_NULLABLE(t->group_name, info->group_name)) { + VIR_FREE(t->group_name); + virDomainThrottleGroupDefCopy(info, t); + } + } +} + + +/** + * virDomainThrottleGroupDel: + * @def: domain definition + * @name: throttle group name + * + * search existing throttle group within domain definition + * by group_name and then delete it with @name, + * it's to delete existing throttle group + */ +void +virDomainThrottleGroupDel(virDomainDef *def, + const char *name) +{ + size_t i; + for (i =3D 0; i < def->nthrottlegroups; i++) { + if (STREQ_NULLABLE(def->throttlegroups[i]->group_name, name)) { + virDomainThrottleGroupDefFree(def->throttlegroups[i]); + VIR_DELETE_ELEMENT(def->throttlegroups, i, def->nthrottlegroup= s); + return; + } + } +} + + static int virDomainEventActionDefFormat(virBuffer *buf, int type, @@ -27624,6 +27858,63 @@ virDomainDefIOThreadsFormat(virBuffer *buf, } =20 =20 +#define FORMAT_THROTTLE_GROUP(val) \ + if (group->val > 0) { \ + virBufferAsprintf(&childBuf, "<" #val ">%llu\n", \ + group->val); \ + } + + +static void +virDomainThrottleGroupFormat(virBuffer *buf, + virDomainThrottleGroupDef *group) +{ + g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); + + FORMAT_THROTTLE_GROUP(total_bytes_sec); + FORMAT_THROTTLE_GROUP(read_bytes_sec); + FORMAT_THROTTLE_GROUP(write_bytes_sec); + FORMAT_THROTTLE_GROUP(total_iops_sec); + FORMAT_THROTTLE_GROUP(read_iops_sec); + FORMAT_THROTTLE_GROUP(write_iops_sec); + + FORMAT_THROTTLE_GROUP(total_bytes_sec_max); + FORMAT_THROTTLE_GROUP(read_bytes_sec_max); + FORMAT_THROTTLE_GROUP(write_bytes_sec_max); + FORMAT_THROTTLE_GROUP(total_iops_sec_max); + FORMAT_THROTTLE_GROUP(read_iops_sec_max); + FORMAT_THROTTLE_GROUP(write_iops_sec_max); + + FORMAT_THROTTLE_GROUP(total_bytes_sec_max_length); + FORMAT_THROTTLE_GROUP(read_bytes_sec_max_length); + FORMAT_THROTTLE_GROUP(write_bytes_sec_max_length); + FORMAT_THROTTLE_GROUP(total_iops_sec_max_length); + FORMAT_THROTTLE_GROUP(read_iops_sec_max_length); + FORMAT_THROTTLE_GROUP(write_iops_sec_max_length); + + virBufferEscapeString(&childBuf, "%s\n", + group->group_name); + + virXMLFormatElement(buf, "throttlegroup", NULL, &childBuf); +} + +#undef FORMAT_THROTTLE_GROUP + +static void +virDomainDefThrottleGroupsFormat(virBuffer *buf, + const virDomainDef *def) +{ + g_auto(virBuffer) childrenBuf =3D VIR_BUFFER_INIT_CHILD(buf); + ssize_t n; + + for (n =3D 0; n < def->nthrottlegroups; n++) { + virDomainThrottleGroupFormat(&childrenBuf, def->throttlegroups[n]); + } + + virXMLFormatElement(buf, "throttlegroups", NULL, &childrenBuf); +} + + static void virDomainIOMMUDefFormat(virBuffer *buf, const virDomainIOMMUDef *iommu) @@ -28316,6 +28607,8 @@ virDomainDefFormatInternalSetRootName(virDomainDef = *def, =20 virDomainDefIOThreadsFormat(buf, def); =20 + virDomainDefThrottleGroupsFormat(buf, def); + if (virDomainCputuneDefFormat(buf, def, flags) < 0) return -1; =20 diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index a187ab4083..2f40d304b4 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3067,6 +3067,9 @@ struct _virDomainDef { =20 virDomainDefaultIOThreadDef *defaultIOThread; =20 + size_t nthrottlegroups; + virDomainThrottleGroupDef **throttlegroups; + virDomainCputune cputune; =20 virDomainResctrlDef **resctrls; @@ -4581,3 +4584,27 @@ virDomainObjGetMessages(virDomainObj *vm, =20 bool virDomainDefHasSpiceGraphics(const virDomainDef *def); + +void +virDomainThrottleGroupDefFree(virDomainThrottleGroupDef *def); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainThrottleGroupDef, virDomainThrottle= GroupDefFree); + +virDomainThrottleGroupDef * +virDomainThrottleGroupAdd(virDomainDef *def, + virDomainThrottleGroupDef *throttle_group); + +void +virDomainThrottleGroupUpdate(virDomainDef *def, + virDomainThrottleGroupDef *info); + +void +virDomainThrottleGroupDel(virDomainDef *def, + const char *name); + +virDomainThrottleGroupDef * +virDomainThrottleGroupByName(const virDomainDef *def, + const char *name); + +void +virDomainThrottleGroupDefCopy(const virDomainThrottleGroupDef *src, + virDomainThrottleGroupDef *dst); diff --git a/src/conf/virconftypes.h b/src/conf/virconftypes.h index 59be61cea4..1936ef6ab1 100644 --- a/src/conf/virconftypes.h +++ b/src/conf/virconftypes.h @@ -80,6 +80,8 @@ typedef struct _virDomainBlkiotune virDomainBlkiotune; =20 typedef struct _virDomainBlockIoTuneInfo virDomainBlockIoTuneInfo; =20 +typedef struct _virDomainBlockIoTuneInfo virDomainThrottleGroupDef; + typedef struct _virDomainCheckpointDef virDomainCheckpointDef; =20 typedef struct _virDomainCheckpointObj virDomainCheckpointObj; --=20 2.39.5 (Apple Git-154)