From nobody Sun May 19 03:12:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1674035911; cv=none; d=zohomail.com; s=zohoarc; b=n93wG9+DUitVZbYCd1iBbrsyxbc/CBJaBxWN+FbpHY1kv8wgKPMRWJUvfHW8iIAQsPEx0kEBdVcQFHHhGAyXvCPMCJClmz/xCSxZk7WiGu9Lfz8rk/NKd9nDEmZsNyEbH1Nz9h8YooRBD2huq1z9K+1Mx5wDHe2TtPhNIFZ50pU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674035911; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NlvYKc3B7lJT64GfayRpy5sQDuypt9/NhDePLcvU9Qk=; b=IQrNy/WCR9iM602VIjq33l0jgEOog6/C27Q/cIGaJ3KcgjLXGGjLVzl+xH6QoCkXqKmlUYpGvAlLVJPze1ZgNism3KJs1rqEUO0JG4qmrJXjtl3zI5HzBR7oOn03YVWtQNSU/HLPUH1x2P169jK2y6SLd+nTYTx18ovIXVg/DR0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1674035911717949.9302904353751; Wed, 18 Jan 2023 01:58:31 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-508-BEpii7CmPN-OLXVsauRjFA-1; Wed, 18 Jan 2023 04:58:25 -0500 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B6F5E3C02197; Wed, 18 Jan 2023 09:58:23 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id A014A492B02; Wed, 18 Jan 2023 09:58:23 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 45CDC1947043; Wed, 18 Jan 2023 09:58:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id DFAF719465B7 for ; Wed, 18 Jan 2023 09:58:21 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id C26F62026D68; Wed, 18 Jan 2023 09:58:21 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6954F2026D4B for ; Wed, 18 Jan 2023 09:58:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674035910; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=NlvYKc3B7lJT64GfayRpy5sQDuypt9/NhDePLcvU9Qk=; b=cS6gGKdAr/tOdJ+jVKK1a6U9G7zod8kK20E/cgg3mGvrDMSuTmsb8KgQs869iFeIZRbQQy RW5fuDSz+/Q9TbQfu0ybXizvqs/pkbscgbAXRIomproLSqFAu01Dqk18UKjAJrnwtrzyWM 3jy0EA4YcDf5HA7NDznSYWmgO319CJQ= X-MC-Unique: BEpii7CmPN-OLXVsauRjFA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 1/3] src: Don't use virReportSystemError() on virProcessGetStatInfo() failure Date: Wed, 18 Jan 2023 10:58:17 +0100 Message-Id: <9f90055e7e4ac9c9f97601e3685a0d63a2dd3c88.1674035810.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1674035913837100007 Content-Type: text/plain; charset="utf-8"; x-default="true" Firstly, the virProcessGetStatInfo() does not fail really. But even if it did, it sets correct errno only sometimes (and even that is done in a helper it's calling - virProcessGetStat() and even there it's the case only in very few error paths). Therefore, using virReportSystemError() to report errors is very misleading. Use plain virReportError() instead. Luckily, there are only two places where the former was used: chDomainHelperGetVcpus() and qemuDomainHelperGetVcpus() (not a big surprise since CH driver is heavily inspired by QEMU driver). Signed-off-by: Michal Privoznik Reviewed-by: Martin Kletzander --- src/ch/ch_driver.c | 4 ++-- src/qemu/qemu_driver.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c index db2a66d131..12fbe31c24 100644 --- a/src/ch/ch_driver.c +++ b/src/ch/ch_driver.c @@ -1079,8 +1079,8 @@ chDomainHelperGetVcpus(virDomainObj *vm, NULL, NULL, &vcpuinfo->cpu, NULL, vm->pid, vcpupid) < 0) { - virReportSystemError(errno, "%s", - _("cannot get vCPU placement & pCPU = time")); + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("cannot get vCPU placement & pCPU time")); return -1; } } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d6879175fe..c576c601ad 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1355,8 +1355,8 @@ qemuDomainHelperGetVcpus(virDomainObj *vm, NULL, NULL, &vcpuinfo->cpu, NULL, vm->pid, vcpupid) < 0) { - virReportSystemError(errno, "%s", - _("cannot get vCPU placement & pCPU t= ime")); + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("cannot get vCPU placement & pCPU time")); return -1; } } --=20 2.38.2 From nobody Sun May 19 03:12:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1674035910; cv=none; d=zohomail.com; s=zohoarc; b=QXzwSR/gW8Vc7PLO63NFxbe2HLvbh3ie1Xa3cMmnSS12FSykaleUF+YVovsa1iKV8u8K8mRm6IDgpIYmJ3nY1CilMnV1W7d/8LEXa1Y2HbQMKmBhAD8zW6lyhC52c9JohB7JB0kz+kwoWYIM0SMbF/vkknxHJY8aCGoDyXNhOxw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674035910; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VV/brd7ZLtWmGPK3mHrF8hBAXr2m2TRPQDynRCL0hGo=; b=lJsDhah2+qqZh2lTOkvWOX3I5vHSKx4WNEEXyKnKeUwQ8msuAutOZFiD+LjlMKf7JKl6WIazGcpb5JPYmI9Nw3pXf2dP6T0d5kLSQMKoXROSnRYgeVFomaViA2FHRBuKv9a/oZTd2umzsQAdsyrKC67gnpNFs4ne2mrb4c3Exzw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1674035910647627.9393955767873; Wed, 18 Jan 2023 01:58:30 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-118-Dnide2ooMNuN1vmO5oWM_g-1; Wed, 18 Jan 2023 04:58:26 -0500 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1F94629324B8; Wed, 18 Jan 2023 09:58:24 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 08CFE492B02; Wed, 18 Jan 2023 09:58:24 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id DE8F31946A6D; Wed, 18 Jan 2023 09:58:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 7C55C19465B7 for ; Wed, 18 Jan 2023 09:58:22 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 5F2402026D68; Wed, 18 Jan 2023 09:58:22 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 065A12026D4B for ; Wed, 18 Jan 2023 09:58:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674035909; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=VV/brd7ZLtWmGPK3mHrF8hBAXr2m2TRPQDynRCL0hGo=; b=QbGeI5XaP87CmKHbu0shxMsBlKX76NfdaxtS50xxR9y250PpE5YyPPf4MX+EqxcHcNiC2k T+92Yhox6936RSqMwJBZK68o+wGPqR6jS53FFONdXe55qMo8I2dcK/MLXohJoJXJ1Yr6us PTLDJDz383cgkhOnibVsybSvLlZU1MM= X-MC-Unique: Dnide2ooMNuN1vmO5oWM_g-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 2/3] virprocess: Make virProcessGetStatInfo() fail if unable to parse data Date: Wed, 18 Jan 2023 10:58:18 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1674035911830100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Yeah, we've already seen this commit (v8.0.0-rc2~4) and also its revert (v8.1.0-rc1~345). While the original idea was sound, the implementation was less so and it changed behaviour of some public APIs (e.g. whilst getting stats for a running guest was best effort it started to return errors). Signed-off-by: Michal Privoznik --- src/qemu/qemu_driver.c | 11 ++++------- src/util/virprocess.c | 28 +++++++--------------------- 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index c576c601ad..25c681bfd2 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -2508,13 +2508,10 @@ qemuDomainGetInfo(virDomainPtr dom, } =20 if (virDomainObjIsActive(vm)) { - if (virProcessGetStatInfo(&(info->cpuTime), NULL, NULL, - NULL, NULL, - vm->pid, 0) < 0) { - virReportError(VIR_ERR_OPERATION_FAILED, "%s", - _("cannot read cputime for domain")); - goto cleanup; - } + /* Specifically ignore the error here. QEMU's PID might be already= gone + * even though the check above says it's still active. */ + virProcessGetStatInfo(&(info->cpuTime), NULL, + NULL, NULL, NULL, vm->pid, 0); } =20 if (VIR_ASSIGN_IS_OVERFLOW(info->nrVirtCpu, virDomainDefGetVcpus(vm->d= ef))) { diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 39ca5de811..800af29537 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -1761,7 +1761,7 @@ virProcessGetStatInfo(unsigned long long *cpuTime, virStrToLong_ullp(proc_stat[VIR_PROCESS_STAT_STIME], NULL, 10, &st= ime) < 0 || virStrToLong_l(proc_stat[VIR_PROCESS_STAT_RSS], NULL, 10, &rss) < = 0 || virStrToLong_i(proc_stat[VIR_PROCESS_STAT_PROCESSOR], NULL, 10, &c= pu) < 0) { - VIR_WARN("cannot parse process status data"); + return -1; } =20 utime *=3D jiff2nsec; @@ -1778,7 +1778,6 @@ virProcessGetStatInfo(unsigned long long *cpuTime, if (vm_rss) *vm_rss =3D rss * virGetSystemPageSizeKB(); =20 - VIR_DEBUG("Got status for %d/%d user=3D%llu sys=3D%llu cpu=3D%d rss=3D= %ld", (int) pid, tid, utime, stime, cpu, rss); =20 @@ -1852,28 +1851,15 @@ virProcessGetSchedInfo(unsigned long long *cpuWait, =20 #else int -virProcessGetStatInfo(unsigned long long *cpuTime, - unsigned long long *userTime, - unsigned long long *sysTime, - int *lastCpu, - long *vm_rss, +virProcessGetStatInfo(unsigned long long *cpuTime G_GNUC_UNUSED, + unsigned long long *userTime G_GNUC_UNUSED, + unsigned long long *sysTime G_GNUC_UNUSED, + int *lastCpu G_GNUC_UNUSED, + long *vm_rss G_GNUC_UNUSED, pid_t pid G_GNUC_UNUSED, pid_t tid G_GNUC_UNUSED) { - /* We don't have a way to collect this information on non-Linux - * platforms, so just report neutral values */ - if (cpuTime) - *cpuTime =3D 0; - if (userTime) - *userTime =3D 0; - if (sysTime) - *sysTime =3D 0; - if (lastCpu) - *lastCpu =3D 0; - if (vm_rss) - *vm_rss =3D 0; - - return 0; + return -1; } =20 int --=20 2.38.2 From nobody Sun May 19 03:12:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1674035912; cv=none; d=zohomail.com; s=zohoarc; b=GB9to6Ci3Lnl8NyWlBp0d8flmBK9rU0JOjhITeSOW2qYwz4la1rpAtIa5KVOCkQ2/zxfCxrn9ATHMchE8wPmMuYBoDcC+o22fSOxa7vVqqUsoi4YdKeuFNuGYy7lf6Snkv3yrEw1Hv9I5ppqbCY0yr0wmYuusbjIA1XiC/4y60g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674035912; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aWk3FHJAbcRZboniAYjYjEFhLqlk6NFDx6trJ0Ee6ds=; b=bkHLyy7IQAYwt4At6C/3gzytE+iOTjBvjMObLidBulEyW0p8v1S19aIHnkFyzes3AD0Fis7oU9N3KUI0eDHxsdFwzC/3FzSwWVWn98SF09bdrZdHWVPvQiRHah8c3HDLp+8pNAVR65Gyizhfb3hmYuOPIQWMZULazOwDhLPDnEw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1674035912092518.6676651544175; Wed, 18 Jan 2023 01:58:32 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-151-uU-fTWXdNjmuWyknLgewqA-1; Wed, 18 Jan 2023 04:58:27 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9B2321C0755A; Wed, 18 Jan 2023 09:58:24 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 834622166B2A; Wed, 18 Jan 2023 09:58:24 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2852E1947044; Wed, 18 Jan 2023 09:58:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 272EE19465B7 for ; Wed, 18 Jan 2023 09:58:23 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id F07F22026D68; Wed, 18 Jan 2023 09:58:22 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 977DD2026D4B for ; Wed, 18 Jan 2023 09:58:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674035909; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=aWk3FHJAbcRZboniAYjYjEFhLqlk6NFDx6trJ0Ee6ds=; b=GiyjHx/LKh6QQoL9ZRCjOH4mVJcde7MXpWtNAojD0qhxiwWFSxPSDCwtimf7QcVnEFgjiI QR+s4w6LZQeguxYksd39RSy6pQ59tCEOhzPT2ymyst4QZNKIVZVyezQ1cQUPuYmzYfm8/b pq44bziTBMlaHMz4awmmPHIz0q9zBt0= X-MC-Unique: uU-fTWXdNjmuWyknLgewqA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 3/3] qemu: Provide virDomainGetCPUStats() implementation for session connection Date: Wed, 18 Jan 2023 10:58:19 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1674035913850100008 Content-Type: text/plain; charset="utf-8"; x-default="true" We have virDomainGetCPUStats() API which offers querying statistics on host CPU usage by given guest. And it works in two modes: getting overall stats (@start_cpu =3D=3D -1, @ncpus =3D=3D 1) or getting per host CPU usage. For the QEMU driver it is implemented by looking into values stored in corresponding cpuacct CGroup controller. Well, this works for system instances, where libvirt has permissions to create CGroups and place QEMU process into them. But it does not fly for session connection, where no CGroups are set up. Fortunately, we can do something similar to v8.8.0-rc1~95 and use virProcessGetStatInfo() to fill the overall stats. Unfortunately, I haven't found any source of per host CPU usage, so we just continue throwing an error in that case. Signed-off-by: Michal Privoznik Reviewed-by: Martin Kletzander --- src/qemu/qemu_driver.c | 52 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 25c681bfd2..cc10dd87e2 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -16006,6 +16006,50 @@ qemuDomainGetMetadata(virDomainPtr dom, return ret; } =20 +#define QEMU_CPU_STATS_PROC_TOTAL 3 + +static int +qemuDomainGetCPUStatsProc(virDomainObj *vm, + virTypedParameterPtr params, + unsigned int nparams) +{ + unsigned long long cpuTime =3D 0; + unsigned long long userTime =3D 0; + unsigned long long sysTime =3D 0; + + if (nparams =3D=3D 0) { + /* return supported number of params */ + return QEMU_CPU_STATS_PROC_TOTAL; + } + + if (virProcessGetStatInfo(&cpuTime, &userTime, &sysTime, + NULL, NULL, vm->pid, 0) < 0) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("cannot read cputime for domain")); + return -1; + } + + if (virTypedParameterAssign(¶ms[0], VIR_DOMAIN_CPU_STATS_CPUTIME, + VIR_TYPED_PARAM_ULLONG, cpuTime) < 0) + return -1; + + if (nparams > 1 && + virTypedParameterAssign(¶ms[1], VIR_DOMAIN_CPU_STATS_USERTIME, + VIR_TYPED_PARAM_ULLONG, userTime) < 0) + return -1; + + if (nparams > 2 && + virTypedParameterAssign(¶ms[2], VIR_DOMAIN_CPU_STATS_SYSTEMTIM= E, + VIR_TYPED_PARAM_ULLONG, sysTime) < 0) + return -1; + + if (nparams > 3) + nparams =3D 3; + + return nparams; +} + +#undef QEMU_CPU_STATS_PROC_TOTAL =20 static int qemuDomainGetCPUStats(virDomainPtr domain, @@ -16034,8 +16078,12 @@ qemuDomainGetCPUStats(virDomainPtr domain, goto cleanup; =20 if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPUACC= T)) { - virReportError(VIR_ERR_OPERATION_INVALID, - "%s", _("cgroup CPUACCT controller is not mounted")= ); + if (start_cpu =3D=3D -1) { + ret =3D qemuDomainGetCPUStatsProc(vm, params, nparams); + } else { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("cgroup CPUACCT controller is not mounted")); + } goto cleanup; } =20 --=20 2.38.2