From nobody Tue Nov 18 08:01:13 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 1731939243010598.570276776687; Mon, 18 Nov 2024 06:14:03 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id DA63F1C34; Mon, 18 Nov 2024 09:14:01 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 7BFF11BC1; Mon, 18 Nov 2024 09:10:30 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 39A9D1A01; Mon, 18 Nov 2024 08:55:01 -0500 (EST) Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 6BC5219F5 for ; Mon, 18 Nov 2024 08:55:00 -0500 (EST) Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-7242f559a9fso4203032b3a.1 for ; Mon, 18 Nov 2024 05:55:00 -0800 (PST) Received: from localhost.localdomain ([2409:40f4:9:7d39:e991:fcfb:15ab:ce58]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-72477135ecbsm6113482b3a.84.2024.11.18.05.54.56 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Nov 2024 05:54:57 -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_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=1731938099; x=1732542899; 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=WfgwwzN9TsDvSU4VMvK6aSegOFRF7Uxlh15PJs1JQe8=; b=ZmUP0r16AnwLYiEBHRo20LqYnX5YgCyvputOplrcRAM4NfB9mnSyM9cKLzGGIe19uP Tip52sAPSD4EOOoWBZzA06X+F/lVQ6pePyYO5mWef7obkgzscrUpJb/P8d/1kFYi/Pe2 YssU6/uyA7QwkCijOF38lF6YjOKCx7lp/9tnC6Isc4eIKJjQ8qJYd1Nvk2FRIPw0fNfd 9zM+wt7/SQO1Y4mxGBipy9HibVkheMvRbHHXW+6E9BZDokkSvF+zmg/IAj+SHi+l9RMh +5dgQfycmx0dJs0S/GgWXugyrQjUOG77/qAIHQ7O0JSGANgdZLxRgAEASmUDbf1skx0y Ls0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731938099; x=1732542899; 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=WfgwwzN9TsDvSU4VMvK6aSegOFRF7Uxlh15PJs1JQe8=; b=VUzS+2vL0omCUzUjkv7KzRxwr84sW4EnbVw1AOYDSsjsA7mPXBHjPuQXRv8G1cULvd CBEmmhSarRBb+NS4hxi7YK/IVnK7x3ZW3BmJ05pXTQlzGAlN2c8xUAsF90TJcu0fr3Ku P35UKyNddcLhW43dGSE0F9WWDWM1DeBZB+kBPjHL8Cu/LyiEVGa3RReruBWr1OTjE0wn 0Hr58vUii3boSyyc32Hu3JfZ1z1c58kHo1mVLsHzeGhNVffewO6QjSgf8XcQ/MAadfXH +joWGnoYPWPSRHOmo7p21QYeOrrRzs8Z76BhjU8soxS3uuo+qEQsSTve2+Vgb8/88POW 80UA== X-Gm-Message-State: AOJu0YyYF7eUHmvoNC0gkeT84p1R3XQDxL3mIJr7uERdQK/uY+TL9R2m MwShpqso9CmnTgWUJYid6o+NG/8Zbnez/xUC5MmW89sUYrirokPyw9BAH8zI X-Google-Smtp-Source: AGHT+IFW9phVaC72Ut0BRdBh1cjuYOGFQ/aNCbHumMYiAgSTyvSn3j1KtZrMGEpWYoTcoinpGv43xQ== X-Received: by 2002:a05:6a00:b4b:b0:714:2069:d90e with SMTP id d2e1a72fcca58-72476f7dcbemr16411872b3a.26.1731938098356; Mon, 18 Nov 2024 05:54:58 -0800 (PST) From: Harikumar R To: devel@lists.libvirt.org Subject: [PATCH v5 05/18] qemu: monitor: Add support for ThrottleGroup operations Date: Mon, 18 Nov 2024 19:24:13 +0530 Message-Id: <20241118135426.37643-6-harirajkumar230@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241118135426.37643-1-harirajkumar230@gmail.com> References: <20241118135426.37643-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: X6JRWLNY5NG3PHBYTYJHTPONZZN3SW2O X-Message-ID-Hash: X6JRWLNY5NG3PHBYTYJHTPONZZN3SW2O X-Mailman-Approved-At: Mon, 18 Nov 2024 14:10:14 -0500 CC: harikumar.rajkumar@ibm.com, sanjeev.ranjan@ibm.com, earulana@in.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: 1731939244511116600 Content-Type: text/plain; charset="utf-8" From: Chun Feng Wu This change contains QMP requests for ThrottleGroup * ThrottleGroup is updated through "qemuMonitorJSONUpdateThrottleGroup" * ThrottleGroup is retrieved through "qemuMonitorJSONGetThrottleGroup" * ThrottleGroup is deleted by reusing "qemuMonitorDelObject" * ThrottleGroup is added by reusing "qemuMonitorAddObject" * "qemuMonitorMakeThrottleGroupLimits" will be used by building qemu cmd as= well Signed-off-by: Chun Feng Wu Reviewed-by: Peter Krempa --- src/qemu/qemu_monitor.c | 34 +++++++++ src/qemu/qemu_monitor.h | 14 ++++ src/qemu/qemu_monitor_json.c | 134 +++++++++++++++++++++++++++++++++++ src/qemu/qemu_monitor_json.h | 14 ++++ 4 files changed, 196 insertions(+) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index fd888e2468..a908e17606 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -3027,6 +3027,40 @@ qemuMonitorGetBlockIoThrottle(qemuMonitor *mon, } =20 =20 +int +qemuMonitorThrottleGroupLimits(virJSONValue *limits, + const virDomainThrottleGroupDef *group) +{ + return qemuMonitorMakeThrottleGroupLimits(limits, group); +} + + +int +qemuMonitorUpdateThrottleGroup(qemuMonitor *mon, + const char *qomid, + virDomainBlockIoTuneInfo *info) +{ + VIR_DEBUG("qomid=3D%s, info=3D%p", qomid, info); + + QEMU_CHECK_MONITOR(mon); + + return qemuMonitorJSONUpdateThrottleGroup(mon, qomid, info); +} + + +int +qemuMonitorGetThrottleGroup(qemuMonitor *mon, + const char *groupname, + virDomainBlockIoTuneInfo *reply) +{ + VIR_DEBUG("throttle-group=3D%s, reply=3D%p", groupname, reply); + + QEMU_CHECK_MONITOR(mon); + + return qemuMonitorJSONGetThrottleGroup(mon, groupname, reply); +} + + int qemuMonitorVMStatusToPausedReason(const char *status) { diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 035c9a7e3c..483aa016ba 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1063,6 +1063,20 @@ int qemuMonitorGetBlockIoThrottle(qemuMonitor *mon, const char *qdevid, virDomainBlockIoTuneInfo *reply); =20 +int +qemuMonitorThrottleGroupLimits(virJSONValue *limits, + const virDomainThrottleGroupDef *group); + +int +qemuMonitorUpdateThrottleGroup(qemuMonitor *mon, + const char *qomid, + virDomainBlockIoTuneInfo *info); + +int +qemuMonitorGetThrottleGroup(qemuMonitor *mon, + const char *groupname, + virDomainBlockIoTuneInfo *reply); + int qemuMonitorSystemWakeup(qemuMonitor *mon); =20 int qemuMonitorGetVersion(qemuMonitor *mon, diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index c594b33106..887ce8e7f5 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -4666,6 +4666,140 @@ int qemuMonitorJSONGetBlockIoThrottle(qemuMonitor *= mon, return qemuMonitorJSONBlockIoThrottleInfo(devices, qdevid, reply); } =20 + +int +qemuMonitorMakeThrottleGroupLimits(virJSONValue *limits, + const virDomainThrottleGroupDef *group) +{ + if (virJSONValueObjectAdd(&limits, + "P:bps-total", group->total_bytes_sec, + "P:bps-read", group->read_bytes_sec, + "P:bps-write", group->write_bytes_sec, + "P:iops-total", group->total_iops_sec, + "P:iops-read", group->read_iops_sec, + "P:iops-write", group->write_iops_sec, + "P:bps-total-max", group->total_bytes_sec_ma= x, + "P:bps-read-max", group->read_bytes_sec_max, + "P:bps-write-max", group->write_bytes_sec_ma= x, + "P:iops-total-max", group->total_iops_sec_ma= x, + "P:iops-read-max", group->read_iops_sec_max, + "P:iops-write-max", group->write_iops_sec_ma= x, + "P:iops-size", group->size_iops_sec, + /* avoid error from QEMU: "the burst length = cannot be 0" for throttlelimits + * when setting max-length + */ + "P:bps-total-max-length", group->total_bytes= _sec_max_length, + "P:bps-read-max-length", group->read_bytes_s= ec_max_length, + "P:bps-write-max-length", group->write_bytes= _sec_max_length, + "P:iops-total-max-length", group->total_iops= _sec_max_length, + "P:iops-read-max-length", group->read_iops_s= ec_max_length, + "P:iops-write-max-length", group->write_iops= _sec_max_length, + NULL) < 0) + return -1; + + return 0; +} + + +int +qemuMonitorJSONUpdateThrottleGroup(qemuMonitor *mon, + const char *qomid, + virDomainBlockIoTuneInfo *info) +{ + g_autoptr(virJSONValue) cmd =3D NULL; + g_autoptr(virJSONValue) result =3D NULL; + g_autoptr(virJSONValue) limits =3D virJSONValueNewObject(); + /* prefix group name with "throttle-" in QOM */ + g_autofree char *prefixed_group_name =3D g_strdup_printf("throttle-%s"= , qomid); + + if (qemuMonitorMakeThrottleGroupLimits(limits, info) < 0) + return -1; + + if (!(cmd =3D qemuMonitorJSONMakeCommand("qom-set", + "s:property", "limits", + "s:path", prefixed_group_name, + "a:value", &limits, + NULL))) + return -1; + + if (qemuMonitorJSONCommand(mon, cmd, &result) < 0) + return -1; + + if (qemuMonitorJSONCheckError(cmd, result) < 0) + return -1; + + return 0; +} + + +#define GET_THROTTLE_GROUP_VALUE(FIELD, STORE) \ + if (virJSONValueObjectHasKey(ret, FIELD)) { \ + if (virJSONValueObjectGetNumberUlong(ret, FIELD, &reply->STORE) < = 0) { \ + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, \ + _("value of throttle group field '%1$s' is malforme= d"), \ + #STORE); \ + return -1; \ + } \ + } + + +int +qemuMonitorJSONGetThrottleGroup(qemuMonitor *mon, + const char *gname, + virDomainBlockIoTuneInfo *reply) +{ + g_autoptr(virJSONValue) cmd =3D NULL; + g_autoptr(virJSONValue) result =3D NULL; + g_autofree char *groupCopy =3D NULL; + virJSONValue *ret; + + /* prefix group name with "throttle-" in QOM */ + g_autofree char *path =3D g_strdup_printf("/objects/throttle-%s", gnam= e); + if (!(cmd =3D qemuMonitorJSONMakeCommand("qom-get", + "s:path", path, + "s:property", "limits", + NULL))) + return -1; + + if (qemuMonitorJSONCommand(mon, cmd, &result) < 0) + return -1; + + if (qemuMonitorJSONCheckError(cmd, result) < 0) + return -1; + + if (!(ret =3D qemuMonitorJSONGetReply(cmd, result, VIR_JSON_TYPE_OBJEC= T))) + return -1; + + GET_THROTTLE_GROUP_VALUE("bps-total", total_bytes_sec); + GET_THROTTLE_GROUP_VALUE("bps-read", read_bytes_sec); + GET_THROTTLE_GROUP_VALUE("bps-write", write_bytes_sec); + GET_THROTTLE_GROUP_VALUE("iops-total", total_iops_sec); + GET_THROTTLE_GROUP_VALUE("iops-read", read_iops_sec); + GET_THROTTLE_GROUP_VALUE("iops-write", write_iops_sec); + + GET_THROTTLE_GROUP_VALUE("bps-total-max", total_bytes_sec_max); + GET_THROTTLE_GROUP_VALUE("bps-read-max", read_bytes_sec_max); + GET_THROTTLE_GROUP_VALUE("bps-write-max", write_bytes_sec_max); + GET_THROTTLE_GROUP_VALUE("iops-total-max", total_iops_sec_max); + GET_THROTTLE_GROUP_VALUE("iops-read-max", read_iops_sec_max); + GET_THROTTLE_GROUP_VALUE("iops-write-max", write_iops_sec_max); + GET_THROTTLE_GROUP_VALUE("iops-size", size_iops_sec); + + GET_THROTTLE_GROUP_VALUE("bps-total-max-length", total_bytes_sec_max_l= ength); + GET_THROTTLE_GROUP_VALUE("bps-read-max-length", read_bytes_sec_max_len= gth); + GET_THROTTLE_GROUP_VALUE("bps-write-max-length", write_bytes_sec_max_l= ength); + GET_THROTTLE_GROUP_VALUE("iops-total-max-length", total_iops_sec_max_l= ength); + GET_THROTTLE_GROUP_VALUE("iops-read-max-length", read_iops_sec_max_len= gth); + GET_THROTTLE_GROUP_VALUE("iops-write-max-length", write_iops_sec_max_l= ength); + + groupCopy =3D g_strdup(gname); + reply->group_name =3D g_steal_pointer(&groupCopy); + + return 0; +} +#undef GET_THROTTLE_GROUP_VALUE + + int qemuMonitorJSONSystemWakeup(qemuMonitor *mon) { g_autoptr(virJSONValue) cmd =3D NULL; diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index ab3c2cb7c8..57b6a2dafa 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -375,6 +375,20 @@ qemuMonitorJSONSetBlockIoThrottle(qemuMonitor *mon, const char *qomid, virDomainBlockIoTuneInfo *info); =20 +int +qemuMonitorMakeThrottleGroupLimits(virJSONValue *limits, + const virDomainThrottleGroupDef *group); + +int +qemuMonitorJSONUpdateThrottleGroup(qemuMonitor *mon, + const char *qomid, + virDomainBlockIoTuneInfo *info); + +int +qemuMonitorJSONGetThrottleGroup(qemuMonitor *mon, + const char *gname, + virDomainBlockIoTuneInfo *reply); + int qemuMonitorJSONGetBlockIoThrottle(qemuMonitor *mon, const char *qdevid, --=20 2.39.5 (Apple Git-154)