From nobody Sat Jan 4 23:40:19 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 1733750648962276.1105419083859; Mon, 9 Dec 2024 05:24:08 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id E88621347; Mon, 9 Dec 2024 08:24:07 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 5E7011365; Mon, 9 Dec 2024 08:20:01 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id F104311BE; Mon, 9 Dec 2024 07:42:32 -0500 (EST) Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (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 2D12E11CE for ; Mon, 9 Dec 2024 07:42:32 -0500 (EST) Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-21636268e43so16196895ad.2 for ; Mon, 09 Dec 2024 04:42:32 -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.28 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 09 Dec 2024 04:42:29 -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=1733748150; x=1734352950; 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=t7V9tNwk7j0QShqQFzwCgy9s1JNZRZga5qc7BV8lMyQ=; b=WC/ML6xXuWikBjgFr429Tae7ZQLUIZ2gklfQI/0H8SPnmoN3dp4TSHeLOb/z/NhPoH 3V4u1mm+njoa38tL1bz3YEeb9XR/SfBE/9ySraRo4/kKbr1017sD3006W6yGpL/OOrI5 dOUEAn2U2t8bGqnVTTPk1/10ZsNptvodyyQ4/obfwPPSvvbckaHWqQ3rEskX7XtgF8TE kvV2toWd9w2xYcCFI4IyXY+vq5zutCR4n8I06gPyfI/qFrwIs0hWStr0CW2LTbQ7e1zd wWjeaxlBoGlnH0TM329IX51pQ/5yufX5XPFWLjIYGVbd4biuukPK9tHZSpbXW0yHDxFs T1ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733748150; x=1734352950; 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=t7V9tNwk7j0QShqQFzwCgy9s1JNZRZga5qc7BV8lMyQ=; b=NSrAFEMBA2EgDDQJHqwJM+rtVlOxmGi7YHVwiqcZt69PoLC8zfJxI8aCrTG4a9r/n4 sryMsU+nK4zpkZO0z1El7SvCjd4iRm1GRpefI9yaK+LbpAq/R7SuC9sEHA5lNazETlPx 6s+blZHJZUWuy3a9vacVD8LfzCkWro9MZyR/w+U4ck6t2pk9qeJiaWurg8nvjaHy6tlC RxSs63BMpLai2UphYv6WXeH5v+FLL0TFmq27aYcZ2yZeLQgQpSTD8Vf9Om/+licJi+/y l4zibOWhJUPGgAvMaLD8j0MHekEqSRI7pw/v0a46IuA6gFfp2BjYK7sYKVCULBV9iQIR kgHw== X-Gm-Message-State: AOJu0Yzp9aDY8Ic0smHhrL/6jI7heU5decS4/LQ9HFcEM5V4oEbKl1nD TCKmooAfba/6iO8mb+VynFEdvWgo9edyHiBOdhEnvBU96jWiDZ0trgyufYRm X-Gm-Gg: ASbGncsHxRuv0xLN6knYMp5e2kKV1M0TRCvpew3k+I/5AeYkoAIQb0jchFvnjP+vuMm bvbtNqG8sVAhQAZ/29d8yEvJzx+VSghaqTT1iJTFtdQl1gpdi/14//uNhPCbMrFNH+SnjFGpUZ5 FEXSAaVO8vC1QUBDemxSt4ICGdrZY+p9zivO34f+l9+sPML2EFnG8NNH7zErWBX2e6Z+EoJxVR8 /uzGK5hq5WxqfyFaMtfqkoWBSzomubbODVoZEDMrbTawspWXcUPA8kLX9HiT9HOfMcKhrAOSenV FxFnnA== X-Google-Smtp-Source: AGHT+IGqyOq/zmOZctSUxPJ7IU3Btg5UWA78hhYB4ln/f+ybee8h/Ns3KRd9BXXffXXJejuK4ssD1g== X-Received: by 2002:a17:903:2349:b0:216:6769:9eea with SMTP id d9443c01a7336-2166a077425mr5625765ad.37.1733748150326; Mon, 09 Dec 2024 04:42:30 -0800 (PST) From: Harikumar R To: devel@lists.libvirt.org Subject: [PATCH v6 05/18] qemu: monitor: Add support for ThrottleGroup operations Date: Mon, 9 Dec 2024 18:11:05 +0530 Message-Id: <20241209124118.39471-6-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: IMNKAHPKJI6CQM4KSRWAWXVVJRMMHGQ3 X-Message-ID-Hash: IMNKAHPKJI6CQM4KSRWAWXVVJRMMHGQ3 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: 1733750650980116600 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 --- 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 73f37d26eb..6f3e04b888 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -3043,6 +3043,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 89a59dfd27..f608ff7179 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1071,6 +1071,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 1b4288b744..6cfe01cbca 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -4676,6 +4676,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 0214e9e9ff..cfb724ed37 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)