From nobody Wed Mar 12 17:51:51 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=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1741097811047573.2843176644789; Tue, 4 Mar 2025 06:16:51 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 53FF01187; Tue, 4 Mar 2025 09:16:50 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id E1A16156B; Tue, 4 Mar 2025 09:05:30 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id B9D591526; Tue, 4 Mar 2025 09:05:18 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 F1B421526 for ; Tue, 4 Mar 2025 09:04:51 -0500 (EST) Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-286-MeJazvuXMQiPdjLhd57xwA-1; Tue, 04 Mar 2025 09:04:39 -0500 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1EA6A1801A25 for ; Tue, 4 Mar 2025 14:04:39 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.210]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 237F319560AB; Tue, 4 Mar 2025 14:04:37 +0000 (UTC) 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_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,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=redhat.com; s=mimecast20190719; t=1741097091; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Rz9IbwaI4DsdgeC1oVTHnzRz/UdYtE4jQjjguEwSCJM=; b=Jq8vHCH9B2SaP9qFSmbcJY8pyUrGsu6RgyFUmGAsMlnj5iuwRYeT0WIyGk3Fo9JKzpX9Dz WHb4bBYu+nCWYL8HrSTioWA/8+S+UHgG1TjReTbZKbv3NTD0ZnyrjP+ciR0I/toR2KSt82 xgFe4lcHl9rvuxtQVAm7NgGew6WzKik= X-MC-Unique: MeJazvuXMQiPdjLhd57xwA-1 X-Mimecast-MFC-AGG-ID: MeJazvuXMQiPdjLhd57xwA_1741097079 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: devel@lists.libvirt.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH 13/19] src: add constants for domain stats 'block.' parameters Date: Tue, 4 Mar 2025 14:04:08 +0000 Message-ID: <20250304140414.3695867-14-berrange@redhat.com> In-Reply-To: <20250304140414.3695867-1-berrange@redhat.com> References: <20250304140414.3695867-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: U-IFY0KLTFe8LZEVIN4mXoenxEafVrQsPowwa073suc_1741097079 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: E65AV5USFRJC52BZPNIPIKUVCI5I5R4Z X-Message-ID-Hash: E65AV5USFRJC52BZPNIPIKUVCI5I5R4Z X-MailFrom: berrange@redhat.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: 1741097812559019000 Content-Type: text/plain; charset="utf-8" Contrary to most APIs returning typed parameters, there are no constants defined for the domain stats data keys. This is was because many of the keys needs to be dynamically constructed using one or more array index values. It is possible to define constants while still supporting dynamic array indexes by simply defining the prefixes and suffixes as constants. The consuming code can then combine the constants with array index value. With this approach, it is practical to add constants for the domain stats API keys. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Peter Krempa --- include/libvirt/libvirt-domain.h | 172 +++++++++++++++++++++++++++++++ src/libvirt-domain.c | 39 +------ src/qemu/qemu_driver.c | 79 ++++++++++---- 3 files changed, 233 insertions(+), 57 deletions(-) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index 33d73da501..0360e163ca 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -3291,6 +3291,178 @@ struct _virDomainStatsRecord { */ #define VIR_DOMAIN_STATS_NET_SUFFIX_TX_DROP ".tx.drop" =20 + +/** + * VIR_DOMAIN_STATS_BLOCK_COUNT: + * + * Number of block devices in the subsequent list, as unsigned int. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BLOCK_COUNT "block.count" + +/** + * VIR_DOMAIN_STATS_BLOCK_PREFIX: + * + * The parameter name prefix to access each disk entry. Concatenate the + * prefix, the entry number formatted as an unsigned integer and one of the + * block suffix parameters to form a complete parameter name. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BLOCK_PREFIX "block." + +/** + * VIR_DOMAIN_STATS_BLOCK_SUFFIX_NAME: + * + * Name of the block device as string. Matches the target name (vda/sda/hd= a) + * of the block device. If the backing chain is listed, this name is the = same + * for all host resources tied to the same guest device. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BLOCK_SUFFIX_NAME ".name" + +/** + * VIR_DOMAIN_STATS_BLOCK_SUFFIX_BACKINGINDEX: + * + * The index as unsigned int, only used when backing images= are + * listed. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BLOCK_SUFFIX_BACKINGINDEX ".backingIndex" + +/** + * VIR_DOMAIN_STATS_BLOCK_SUFFIX_PATH: + * + * Source of the block device as a string, if it is a file or block device + * (omitted for network sources and drives with no media inserted). + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BLOCK_SUFFIX_PATH ".path" + +/** + * VIR_DOMAIN_STATS_BLOCK_SUFFIX_RD_REQS: + * + * Number of read requests as unsigned long long. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BLOCK_SUFFIX_RD_REQS ".rd.reqs" + +/** + * VIR_DOMAIN_STATS_BLOCK_SUFFIX_RD_BYTES: + * + * Number of read bytes as unsigned long long. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BLOCK_SUFFIX_RD_BYTES ".rd.bytes" + +/** + * VIR_DOMAIN_STATS_BLOCK_SUFFIX_RD_TIMES: + * + * Total time (ns) spent on reads as unsigned long long. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BLOCK_SUFFIX_RD_TIMES ".rd.times" + +/** + * VIR_DOMAIN_STATS_BLOCK_SUFFIX_WR_REQS: + * + * Number of write requests as unsigned long long. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BLOCK_SUFFIX_WR_REQS ".wr.reqs" + +/** + * VIR_DOMAIN_STATS_BLOCK_SUFFIX_WR_BYTES: + * + * Number of written bytes as unsigned long long. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BLOCK_SUFFIX_WR_BYTES ".wr.bytes" + +/** + * VIR_DOMAIN_STATS_BLOCK_SUFFIX_WR_TIMES: + * + * Total time (ns) spent on writes as unsigned long long. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BLOCK_SUFFIX_WR_TIMES ".wr.times" + +/** + * VIR_DOMAIN_STATS_BLOCK_SUFFIX_FL_REQS: + * + * Total flush requests as unsigned long long. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BLOCK_SUFFIX_FL_REQS ".fl.reqs" + +/** + * VIR_DOMAIN_STATS_BLOCK_SUFFIX_FL_TIMES: + * + * Total time (ns) spent on cache flushing as unsigned long long. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BLOCK_SUFFIX_FL_TIMES ".fl.times" + +/** + * VIR_DOMAIN_STATS_BLOCK_SUFFIX_ERRORS: + * + * Xen only: the 'oo_req' value as unsigned long long. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BLOCK_SUFFIX_ERRORS ".errors" + +/** + * VIR_DOMAIN_STATS_BLOCK_SUFFIX_ALLOCATION: + * + * Offset of the highest written sector as unsigned long long. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BLOCK_SUFFIX_ALLOCATION ".allocation" + +/** + * VIR_DOMAIN_STATS_BLOCK_SUFFIX_CAPACITY: + * + * Logical size in bytes of the block device backing image as unsigned long + * long. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BLOCK_SUFFIX_CAPACITY ".capacity" + +/** + * VIR_DOMAIN_STATS_BLOCK_SUFFIX_PHYSICAL: + * + * Physical size in bytes of the container of the backing image as unsigned + * long long. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BLOCK_SUFFIX_PHYSICAL ".physical" + +/** + * VIR_DOMAIN_STATS_BLOCK_SUFFIX_THRESHOLD: + * + * Current threshold for delivering the VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD + * event in bytes as unsigned long long. See virDomainSetBlockThreshold. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BLOCK_SUFFIX_THRESHOLD ".threshold" + /** * virDomainStatsTypes: * diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index cf5d718a0c..90eecea641 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -12283,43 +12283,8 @@ virConnectGetDomainCapabilities(virConnectPtr conn, * VIR_CONNECT_GET_ALL_DOMAINS_STATS_BACKING to @flags will expand the * array to cover backing chains (block.count corresponds to the number * of host resources used together to provide the guest disks). - * The typed parameter keys are in this format: - * - * "block.count" - number of block devices in the subsequent list, - * as unsigned int. - * "block..name" - name of the block device as string. - * matches the target name (vda/sda/hda) of the - * block device. If the backing chain is listed, - * this name is the same for all host resources t= ied - * to the same guest device. - * "block..backingIndex" - unsigned int giving the - * index, only used when backing images - * are listed. - * "block..path" - string describing the source of block device <= num>, - * if it is a file or block device (omitted for n= etwork - * sources and drives with no media inserted). - * "block..rd.reqs" - number of read requests as unsigned long lo= ng. - * "block..rd.bytes" - number of read bytes as unsigned long long. - * "block..rd.times" - total time (ns) spent on reads as - * unsigned long long. - * "block..wr.reqs" - number of write requests as unsigned long l= ong. - * "block..wr.bytes" - number of written bytes as unsigned long l= ong. - * "block..wr.times" - total time (ns) spent on writes as - * unsigned long long. - * "block..fl.reqs" - total flush requests as unsigned long long. - * "block..fl.times" - total time (ns) spent on cache flushing as - * unsigned long long. - * "block..errors" - Xen only: the 'oo_req' value as - * unsigned long long. - * "block..allocation" - offset of the highest written sector - * as unsigned long long. - * "block..capacity" - logical size in bytes of the block device - * backing image as unsigned long long. - * "block..physical" - physical size in bytes of the container of= the - * backing image as unsigned long long. - * "block..threshold" - current threshold for delivering the - * VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD - * event in bytes. See virDomainSetBlockThre= shold. + * The VIR_DOMAIN_STATS_BLOCK_* constants define the known typed + * parameter keys. * * VIR_DOMAIN_STATS_PERF: * Return perf event statistics. diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1f1aa57b75..6f9e0270dc 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -17277,13 +17277,19 @@ qemuDomainGetStatsOneBlockFallback(virQEMUDriverC= onfig *cfg, } =20 if (src->allocation) - virTypedParamListAddULLong(params, src->allocation, "block.%zu.all= ocation", block_idx); + virTypedParamListAddULLong(params, src->allocation, + VIR_DOMAIN_STATS_BLOCK_PREFIX "%zu" + VIR_DOMAIN_STATS_BLOCK_SUFFIX_ALLOCATIO= N, block_idx); =20 if (src->capacity) - virTypedParamListAddULLong(params, src->capacity, "block.%zu.capac= ity", block_idx); + virTypedParamListAddULLong(params, src->capacity, + VIR_DOMAIN_STATS_BLOCK_PREFIX "%zu" + VIR_DOMAIN_STATS_BLOCK_SUFFIX_CAPACITY,= block_idx); =20 if (src->physical) - virTypedParamListAddULLong(params, src->physical, "block.%zu.physi= cal", block_idx); + virTypedParamListAddULLong(params, src->physical, + VIR_DOMAIN_STATS_BLOCK_PREFIX "%zu" + VIR_DOMAIN_STATS_BLOCK_SUFFIX_PHYSICAL,= block_idx); } =20 =20 @@ -17311,16 +17317,24 @@ qemuDomainGetStatsOneBlock(virQEMUDriverConfig *c= fg, if (!stats || !entryname || !(entry =3D virHashLookup(stats, entryname= ))) return; =20 - virTypedParamListAddULLong(params, entry->wr_highest_offset, "block.%z= u.allocation", block_idx); + virTypedParamListAddULLong(params, entry->wr_highest_offset, + VIR_DOMAIN_STATS_BLOCK_PREFIX "%zu" + VIR_DOMAIN_STATS_BLOCK_SUFFIX_ALLOCATION, b= lock_idx); =20 if (entry->capacity) - virTypedParamListAddULLong(params, entry->capacity, "block.%zu.cap= acity", block_idx); + virTypedParamListAddULLong(params, entry->capacity, + VIR_DOMAIN_STATS_BLOCK_PREFIX "%zu" + VIR_DOMAIN_STATS_BLOCK_SUFFIX_CAPACITY,= block_idx); =20 if (entry->physical) { - virTypedParamListAddULLong(params, entry->physical, "block.%zu.phy= sical", block_idx); + virTypedParamListAddULLong(params, entry->physical, + VIR_DOMAIN_STATS_BLOCK_PREFIX "%zu" + VIR_DOMAIN_STATS_BLOCK_SUFFIX_PHYSICAL,= block_idx); } else { if (qemuDomainStorageUpdatePhysical(cfg, dom, src) =3D=3D 0) { - virTypedParamListAddULLong(params, src->physical, "block.%zu.p= hysical", block_idx); + virTypedParamListAddULLong(params, src->physical, + VIR_DOMAIN_STATS_BLOCK_PREFIX "%zu" + VIR_DOMAIN_STATS_BLOCK_SUFFIX_PHYSI= CAL, block_idx); } } } @@ -17338,7 +17352,9 @@ qemuDomainGetStatsBlockExportBackendStorage(const c= har *entryname, return; =20 if (entry->write_threshold) - virTypedParamListAddULLong(params, entry->write_threshold, "block.= %zu.threshold", recordnr); + virTypedParamListAddULLong(params, entry->write_threshold, + VIR_DOMAIN_STATS_BLOCK_PREFIX "%zu" + VIR_DOMAIN_STATS_BLOCK_SUFFIX_THRESHOLD= , recordnr); } =20 =20 @@ -17356,14 +17372,30 @@ qemuDomainGetStatsBlockExportFrontend(const char = *frontendname, if (!stats || !frontendname || !(en =3D virHashLookup(stats, frontendn= ame))) return; =20 - virTypedParamListAddULLong(par, en->rd_req, "block.%zu.rd.reqs", idx); - virTypedParamListAddULLong(par, en->rd_bytes, "block.%zu.rd.bytes", id= x); - virTypedParamListAddULLong(par, en->rd_total_times, "block.%zu.rd.time= s", idx); - virTypedParamListAddULLong(par, en->wr_req, "block.%zu.wr.reqs", idx); - virTypedParamListAddULLong(par, en->wr_bytes, "block.%zu.wr.bytes", id= x); - virTypedParamListAddULLong(par, en->wr_total_times, "block.%zu.wr.time= s", idx); - virTypedParamListAddULLong(par, en->flush_req, "block.%zu.fl.reqs", id= x); - virTypedParamListAddULLong(par, en->flush_total_times, "block.%zu.fl.t= imes", idx); + virTypedParamListAddULLong(par, en->rd_req, + VIR_DOMAIN_STATS_BLOCK_PREFIX "%zu" + VIR_DOMAIN_STATS_BLOCK_SUFFIX_RD_REQS, idx); + virTypedParamListAddULLong(par, en->rd_bytes, + VIR_DOMAIN_STATS_BLOCK_PREFIX "%zu" + VIR_DOMAIN_STATS_BLOCK_SUFFIX_RD_BYTES, idx= ); + virTypedParamListAddULLong(par, en->rd_total_times, + VIR_DOMAIN_STATS_BLOCK_PREFIX "%zu" + VIR_DOMAIN_STATS_BLOCK_SUFFIX_RD_TIMES, idx= ); + virTypedParamListAddULLong(par, en->wr_req, + VIR_DOMAIN_STATS_BLOCK_PREFIX "%zu" + VIR_DOMAIN_STATS_BLOCK_SUFFIX_WR_REQS, idx); + virTypedParamListAddULLong(par, en->wr_bytes, + VIR_DOMAIN_STATS_BLOCK_PREFIX "%zu" + VIR_DOMAIN_STATS_BLOCK_SUFFIX_WR_BYTES, idx= ); + virTypedParamListAddULLong(par, en->wr_total_times, + VIR_DOMAIN_STATS_BLOCK_PREFIX "%zu" + VIR_DOMAIN_STATS_BLOCK_SUFFIX_WR_TIMES, idx= ); + virTypedParamListAddULLong(par, en->flush_req, + VIR_DOMAIN_STATS_BLOCK_PREFIX "%zu" + VIR_DOMAIN_STATS_BLOCK_SUFFIX_FL_REQS, idx); + virTypedParamListAddULLong(par, en->flush_total_times, + VIR_DOMAIN_STATS_BLOCK_PREFIX "%zu" + VIR_DOMAIN_STATS_BLOCK_SUFFIX_FL_TIMES, idx= ); } =20 =20 @@ -17373,13 +17405,19 @@ qemuDomainGetStatsBlockExportHeader(virDomainDisk= Def *disk, size_t recordnr, virTypedParamList *params) { - virTypedParamListAddString(params, disk->dst, "block.%zu.name", record= nr); + virTypedParamListAddString(params, disk->dst, + VIR_DOMAIN_STATS_BLOCK_PREFIX "%zu" + VIR_DOMAIN_STATS_BLOCK_SUFFIX_NAME, recordn= r); =20 if (virStorageSourceIsLocalStorage(src) && src->path) - virTypedParamListAddString(params, src->path, "block.%zu.path", re= cordnr); + virTypedParamListAddString(params, src->path, + VIR_DOMAIN_STATS_BLOCK_PREFIX "%zu" + VIR_DOMAIN_STATS_BLOCK_SUFFIX_PATH, rec= ordnr); =20 if (src->id) - virTypedParamListAddUInt(params, src->id, "block.%zu.backingIndex"= , recordnr); + virTypedParamListAddUInt(params, src->id, + VIR_DOMAIN_STATS_BLOCK_PREFIX "%zu" + VIR_DOMAIN_STATS_BLOCK_SUFFIX_BACKINGINDE= X, recordnr); } =20 =20 @@ -17550,7 +17588,8 @@ qemuDomainGetStatsBlock(virQEMUDriver *driver, &visited, visitBacking, cfg, dom= ); } =20 - virTypedParamListAddUInt(params, visited, "block.count"); + virTypedParamListAddUInt(params, visited, + VIR_DOMAIN_STATS_BLOCK_COUNT); virTypedParamListConcat(params, &blockparams); } =20 --=20 2.48.1