From nobody Sun Dec 7 08:46:59 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 1739984732332304.11371907214084; Wed, 19 Feb 2025 09:05:32 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 484281BDC; Wed, 19 Feb 2025 12:05:31 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id BFDAD1D51; Wed, 19 Feb 2025 12:02:11 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id CBCC11D10; Wed, 19 Feb 2025 12:02:07 -0500 (EST) Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 CAD391BE9 for ; Wed, 19 Feb 2025 12:01:49 -0500 (EST) Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-2211cd4463cso76168095ad.2 for ; Wed, 19 Feb 2025 09:01:49 -0800 (PST) Received: from localhost.localdomain ([2001:4490:4ea9:8374:8512:e327:fdaf:a56e]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-220d558fe3asm106651545ad.234.2025.02.19.09.01.45 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 19 Feb 2025 09:01:47 -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.8 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=1739984508; x=1740589308; 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=fpJHO/HCfOJlVfStqbJF++IS7GuxRAH/0jsUUNwiXp0=; b=FUF3mCJm9hO4VClKQUBlKATa2of367SugzPVqvnHmN3ezZoPeZaLkcbKRk080JLzge e3rOdk7yl5xfJa2SVNc1uk5HoianYkY4Vb7hpiCDsFPO7pUwGbg73D+0EKJgmEfYc73E n67vKd32UYc4hWFyT05eMSWS2gUkjO+ksjtM4SvbwsXDP+GHXl1IhHTjgZF3n54qhvcQ jz1IR9Dh6JNuqyVh/qXsrqkHM+FWu3eRgR6TExsdQlCmnwhj8YKe68461WUXTBZAfIsu 4r3q3Y0JRZTKFWLKT2jHue/5QsiJ6v6JhkduJ2nSTNPVsdEehPOBGEndyfIxEc2v3OUq AZpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739984508; x=1740589308; 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=fpJHO/HCfOJlVfStqbJF++IS7GuxRAH/0jsUUNwiXp0=; b=EyAxewRABOmMT5ursmlwdJyPj9snOtC7N/YZU3u3YM5sAbC1QNt6Fy8tWPvriLf0qt laJ87S4PRlnTm1f1t944ECA1uyCcR0PQCaTeCeQe0eGfI4h7Ng0wSBQOSVaOPTR69YmA IPBkuS1BOIW9OYuRY/nUq8vDP6vUfZTEpS4x3dD1f/hIXevNbWrBos1MU9aKcXF+bC6T JsJJvwaDVgzAnJRKvj7KheEOp0rvwI+9JD3Q7Mt/QB0N0OtIvLTYTJEeSIzpFHf5vOAn TG/0+Az6IJyKQREEM3/gCum3HIoT7aMjowoY+pBZB7ONzWmljLOB5x5Q8s7VmidDbET1 +wow== X-Gm-Message-State: AOJu0YzmM7zRkg9MQKAtlBJ8a8BQ5FebCaHuou2Je3/KMzW7g+RAAZHg 8ZgsAKy6GqU7KynkmbfezPX11K2DRS6piRIDFrMEpDD55NBKr8DHaLU3nqFX X-Gm-Gg: ASbGncu+LaOu5ftYUDRBRDpKQyIHQPJf4xNDO2GVJylNHdfvmMJmnY9dEMr8Q7KsJP7 gvcYPpy7PfzOqAzlLQ3AJF9gtD6bzXTRdU4hpQijuVqrjCMLmOFHdrW8nCnlny40UWawFsODflU yR0BvcCL7YKM6iAX9aosRGhuEM6Kvea0I02uoFcaLukTH40A+pY8iaE+rM8nCym/fE3nkAoMEK3 LdZLUDqfdyCynbHjylWdiZnlAShPemHPr3u63PH8/ThsBjYv8GoU5olVzFPDglq8VbrVxvOQP8D NDUMBSDwEFhWWQE+0/NDaPUm+CQMWX4Cx/WH13vRao1WWOi81uxw7s/o/g== X-Google-Smtp-Source: AGHT+IE6hadOTy5/RYQGkVUiw31J0Qu1HaZ6ajWkzvwf1SPqEOsAsm3LEVW1PWbLahCfTE8NXkUK/g== X-Received: by 2002:a17:903:60d:b0:215:aee1:7e3e with SMTP id d9443c01a7336-2210401368dmr231187825ad.5.1739984507901; Wed, 19 Feb 2025 09:01:47 -0800 (PST) From: Harikumar Rajkumar To: devel@lists.libvirt.org Subject: [PATCH v8 05/18] qemu: monitor: Add support for ThrottleGroup operations Date: Wed, 19 Feb 2025 22:27:09 +0530 Message-Id: <20250219165722.26348-6-harirajkumar230@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250219165722.26348-1-harirajkumar230@gmail.com> References: <20250219165722.26348-1-harirajkumar230@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 3I4ULJMNPHTFKEKRL7PHHXKOU3XBPOV5 X-Message-ID-Hash: 3I4ULJMNPHTFKEKRL7PHHXKOU3XBPOV5 X-MailFrom: harirajkumar230@gmail.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: sanjeev.ranjan@ibm.com, harikumar.rajkumar@ibm.com, earulana@in.ibm.com, Chun Feng Wu , Harikumar Rajkumar 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: 1739984733381019100 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 * change throttle group config conversions P to U allow zero. * Apply suggested coding style changes. Signed-off-by: Harikumar Rajkumar Reviewed-by: Peter Krempa --- src/qemu/qemu_monitor.c | 34 +++++++++ src/qemu/qemu_monitor.h | 14 ++++ src/qemu/qemu_monitor_json.c | 129 +++++++++++++++++++++++++++++++++++ src/qemu/qemu_monitor_json.h | 14 ++++ 4 files changed, 191 insertions(+) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index c069d17265..015f8f11cc 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -3037,6 +3037,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 f7b9263b64..7b58d988d8 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1074,6 +1074,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 554572b13d..572fdb944d 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -4685,6 +4685,135 @@ int qemuMonitorJSONGetBlockIoThrottle(qemuMonitor *= mon, return qemuMonitorJSONBlockIoThrottleInfo(devices, qdevid, reply); } =20 + +int +qemuMonitorMakeThrottleGroupLimits(virJSONValue *limits, + const virDomainThrottleGroupDef *group) +{ + if (virJSONValueObjectAdd(&limits, + "U:bps-total", group->total_bytes_sec, + "U:bps-read", group->read_bytes_sec, + "U:bps-write", group->write_bytes_sec, + "U:iops-total", group->total_iops_sec, + "U:iops-read", group->read_iops_sec, + "U:iops-write", group->write_iops_sec, + "U:bps-total-max", group->total_bytes_sec_ma= x, + "U:bps-read-max", group->read_bytes_sec_max, + "U:bps-write-max", group->write_bytes_sec_ma= x, + "U:iops-total-max", group->total_iops_sec_ma= x, + "U:iops-read-max", group->read_iops_sec_max, + "U:iops-write-max", group->write_iops_sec_ma= x, + "U:iops-size", group->size_iops_sec, + "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(); + + if (qemuMonitorMakeThrottleGroupLimits(limits, info) < 0) + return -1; + + if (!(cmd =3D qemuMonitorJSONMakeCommand("qom-set", + "s:property", "limits", + "s:path", qomid, + "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 25e3ae2cbb..23c845ac76 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)