From nobody Tue Sep 9 23:40:50 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 1748756619980956.1386708800218; Sat, 31 May 2025 22:43:39 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 049881395; Sun, 1 Jun 2025 01:43:38 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 2D12E138C; Sun, 1 Jun 2025 01:42:03 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 681371492; Sun, 1 Jun 2025 01:41:57 -0400 (EDT) Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (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 C2BDB13DF for ; Sun, 1 Jun 2025 01:41:48 -0400 (EDT) Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-ad69e4f2100so496498766b.2 for ; Sat, 31 May 2025 22:41:48 -0700 (PDT) Received: from tulp.my.domain (80-115-115-199.cable.dynamic.v4.ziggo.nl. [80.115.115.199]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-adb35af4456sm399732266b.182.2025.05.31.22.41.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 31 May 2025 22:41:45 -0700 (PDT) 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=1748756507; x=1749361307; 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=zKEmnObCvXKV05vB+/kKLXcReihnIAS6JkEvROMtZ+Q=; b=nBPtoA1XBzj1uPishsPPKtSxZTWYM5OVWHVM3juAVctQfmH2PHN4F2V7qCyHWbCnzK iP8CJb36StsyENSQTgZ7ESj0NwBIlNuo4yfaEFWYSIizpauxpxAuyqLC8rKqqXCz1u5d /3EU6FS1xCp2DmyGjJ5zFpW8AG4coNs6OS4lQZlOwlM7QKZvGWm7ipU7nVE+lhNdB7J1 Tq1Qb1lfid1ugKGffKZUPtkv5iVWLzlGlrwP491ZEox13TG5f6GiLOngd9Q4IV4k9eTm IZoJvZu2URwOvcdGOU8eqccggN69sQsR3q/CV7pu2QcQxV1xQebLB5CWLnrwE0FPDlxb 9r0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748756507; x=1749361307; 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=zKEmnObCvXKV05vB+/kKLXcReihnIAS6JkEvROMtZ+Q=; b=NF9gv8F64RrDRy3+KcSy9xg9aUvY6ODR7yxfiakDlS2427kzqNY6O4QNCWvqN4KzIJ eWKE/OyT6qmUF1Xn+X2r/6YohccC1TQDI1FWynE0atGXRpyZEhepnVAZOaUwPEC2uTms TR92/E2+TN/W35NtxbIJc+CbrVd1DrZ6YbOB29ye/yAH5RfMdV/wsWt+6X4rjkeUrzov R89BnO2C4AGipIUJmyLBkpaVSG886NTlDA5PwagIKTi9jq6AafL4YSSlujCoBk/JP7qi 4n93iWJhPNk/1Mmv9OR70JTMOhJq20tPfVZRFiDJ+OJxKZu0IOhkg0TqKcxi2G5sMkpc j+YA== X-Gm-Message-State: AOJu0Yy4faJYSgIK8+OmLvAeF3B1u0LMQaTBRpANd0P+DjhVw7U6GBra NdxN9QcX6b1W0ojkBbEOs7oNVfPtcUkoH6nWxSKAB0OS0K+6C44dURzbSq/3JOFI6q4= X-Gm-Gg: ASbGncs/061aEWTcFSSwrlIVyJPH03WPK7/cE5/F87jh58CNux60ws4Lyr8iFSujGi9 y9ALkwui76yg6PCmceQ6HHSn+1M4Txm+T9o6/g9OShOZP4h2rBhd7TxHSPB/Ue+hiCO1lVGDm4Z 7tgoPeLl7EgLvJYAUG6srvMfnbJV14AC/Wma//ctPbqcLpsJcvXZ+ULETMfZF1wR9bVUSNjneu4 yNWNde71+6BGSYR4+mS/aHJtJ+5NGNhsBBa2U52inkUIGvzxj7rGEGb+JDo4yt2FAJwhangPvRD eAkEYiplRlJR67Kw5tk0O/kXIy9FZ3C6P0goml+PJ0QDX3WX+lLCtZTHeY6rKAKZ4rtmVWSDRQl FjOj8FWFIHoSq+1kaOQg7OPDL X-Google-Smtp-Source: AGHT+IH/4HY5JX7GX8XpszDDcVavdgQJEYLxL33u/mahx9loUJcawRROCDE1K0+pKGfAlIPw9OoWRw== X-Received: by 2002:a17:907:3e08:b0:ad8:8c52:d61f with SMTP id a640c23a62f3a-adb36bf1976mr674604366b.35.1748756506906; Sat, 31 May 2025 22:41:46 -0700 (PDT) From: Roman Bogorodskiy To: devel@lists.libvirt.org Subject: [PATCH v2 4/4] bhyve: implement domainBlockStats Date: Sun, 1 Jun 2025 07:40:26 +0200 Message-ID: <20250601054026.59551-5-bogorodskiy@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250601054026.59551-1-bogorodskiy@gmail.com> References: <20250601054026.59551-1-bogorodskiy@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: HXMEXOXCHBM5NAHJAND45OXBWJPGXYGO X-Message-ID-Hash: HXMEXOXCHBM5NAHJAND45OXBWJPGXYGO X-MailFrom: bogorodskiy@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: Roman Bogorodskiy 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: 1748756622195116600 Content-Type: text/plain; charset="utf-8" Implement domainBlockStats for the bhyve driver. Only the read/write operations counts are reported as FreeBSD apparently doesn't support accumulative bytes read or written, though real-time data is available via rctl(8). There's also no information about the errors. Signed-off-by: Roman Bogorodskiy --- src/bhyve/bhyve_driver.c | 56 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 70e28c7e0b..acec98d100 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -24,6 +24,9 @@ =20 #include #include +#include +#include +#include =20 #include "virerror.h" #include "datatypes.h" @@ -1707,6 +1710,58 @@ bhyveDomainMemoryStats(virDomainPtr domain, =20 #undef BHYVE_SET_MEMSTAT =20 +static struct kinfo_proc *bhyveDomainProcGetInfo(pid_t pid) +{ + int mib[4]; + size_t len =3D 4; + struct kinfo_proc *p =3D g_malloc0(sizeof(struct kinfo_proc)); + + sysctlnametomib("kern.proc.pid", mib, &len); + len =3D sizeof(struct kinfo_proc); + mib[3] =3D pid; + + if (sysctl(mib, 4, p, &len, NULL, 0) < 0) { + virReportSystemError(errno, "%s", + _("Unable to query process stats")); + return NULL; + } + + return p; +} + +static int +bhyveDomainBlockStats(virDomainPtr domain, + const char *path G_GNUC_UNUSED, + virDomainBlockStatsPtr stats) +{ + virDomainObj *vm; + int ret =3D -1; + g_autofree struct kinfo_proc *p =3D NULL; + + if (!(vm =3D bhyveDomObjFromDomain(domain))) + goto cleanup; + + if (virDomainObjCheckActive(vm) < 0) + goto cleanup; + + if (virDomainBlockStatsEnsureACL(domain->conn, vm->def) < 0) + goto cleanup; + + if ((p =3D bhyveDomainProcGetInfo(vm->pid)) =3D=3D NULL) + goto cleanup; + + stats->rd_req =3D p->ki_rusage.ru_inblock; + stats->wr_req =3D p->ki_rusage.ru_oublock; + stats->rd_bytes =3D -1; + stats->wr_bytes =3D -1; + stats->errs =3D -1; + + ret =3D 0; + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + static virHypervisorDriver bhyveHypervisorDriver =3D { .name =3D "bhyve", .connectURIProbe =3D bhyveConnectURIProbe, @@ -1769,6 +1824,7 @@ static virHypervisorDriver bhyveHypervisorDriver =3D { .connectGetDomainCapabilities =3D bhyveConnectGetDomainCapabilities, /= * 2.1.0 */ .domainInterfaceStats =3D bhyveDomainInterfaceStats, /* 11.5.0 */ .domainMemoryStats =3D bhyveDomainMemoryStats, /* 11.5.0 */ + .domainBlockStats =3D bhyveDomainBlockStats, /* 11.5.0 */ }; =20 =20 --=20 2.49.0