From nobody Sat Apr 20 08:27:20 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; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com 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 1641924842703403.34779996067607; Tue, 11 Jan 2022 10:14:02 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-590-pm8v0XW3Phm24wiI0BaTNw-1; Tue, 11 Jan 2022 13:13:59 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B6A2F81EE61; Tue, 11 Jan 2022 18:13:54 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D201D82768; Tue, 11 Jan 2022 18:13:53 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5F6454CA93; Tue, 11 Jan 2022 18:13:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 20BIDnmO011012 for ; Tue, 11 Jan 2022 13:13:50 -0500 Received: by smtp.corp.redhat.com (Postfix) id BC6CD40CFD1F; Tue, 11 Jan 2022 18:13:49 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B717C40CFD1E for ; Tue, 11 Jan 2022 18:13:49 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9E988800B21 for ; Tue, 11 Jan 2022 18:13:49 +0000 (UTC) Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-474-v7GosSn1MlK6C8niqZ5yTg-1; Tue, 11 Jan 2022 13:13:47 -0500 Received: by mail-pj1-f42.google.com with SMTP id y16-20020a17090a6c9000b001b13ffaa625so6810355pjj.2 for ; Tue, 11 Jan 2022 10:13:47 -0800 (PST) Received: from anisinha-lenovo.ba.nuagenetworks.net ([115.96.154.238]) by smtp.googlemail.com with ESMTPSA id x4sm3226492pjn.56.2022.01.11.10.13.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jan 2022 10:13:45 -0800 (PST) X-MC-Unique: pm8v0XW3Phm24wiI0BaTNw-1 X-MC-Unique: v7GosSn1MlK6C8niqZ5yTg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=2b0eZ9IzYIty0e7dKuMLKgNMLTuRTZwWB9z2rqcIuOM=; b=G74iNOkxxAbk34+8TGjgAobw1hAJeXbc8XTXldyhYdjNyBmIEBtr29neSFzus/Retc CnJbhUGahpjafh/09meLokNcL4Q4VwObEe4qOUuBtO83d4IfG/IR+aJ/77xLQPK/Wi45 djan1HF5tHUmDpM2Sq4pGUsZ2mbswRCWzwIdxAVXl3m/54binRwbkaxTYTmKuAk0VVY8 CZOyTHVzudxhAzIVDqoLqVVttOv4vPAtcljn8qEq9lgSKfSAMrtJILydXpGJU6W/9Ne6 8nCG5I+2n6F9L1JDcmEhAyvvYK8cW+9lmqRx480JaaSvsn5sgOa/LiCQ8rYvNg9Xo4iY ECxw== X-Gm-Message-State: AOAM5313U7T2L8wE4AzvbsIwo9iES48Jft8k0Fn2TO87vHgYS0zB7q9X FFB2o72vFJ1bN5eRo19py29a2Nu4KxfNvpKh X-Google-Smtp-Source: ABdhPJw4jjqe+SW+5sKQWhrIhc//DaoC57X1O0f7F1Cn7z8yECv4M21MCrdBV6Qhx+3fTPWfNwKeoQ== X-Received: by 2002:a17:902:ea04:b0:14a:642a:accb with SMTP id s4-20020a170902ea0400b0014a642aaccbmr720012plg.13.1641924826015; Tue, 11 Jan 2022 10:13:46 -0800 (PST) From: Ani Sinha To: libvir-list@redhat.com Subject: [PATCH v4] report error when virProcessGetStatInfo() is unable to parse data Date: Tue, 11 Jan 2022 23:43:39 +0530 Message-Id: <20220111181339.434963-1-ani@anisinha.ca> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-loop: libvir-list@redhat.com Cc: Ani Sinha X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1641924844875100001 Content-Type: text/plain; charset="utf-8" Currently virProcessGetStatInfo() always returns success and only logs error when it is unable to parse the data. Make this function actually report the error and return a negative value in this error scenario. Fix the callers so that they do not override the error generated. Also fix non-linux implementation of this function so as to report error. Signed-off-by: Ani Sinha --- src/ch/ch_driver.c | 2 -- src/qemu/qemu_driver.c | 7 +------ src/util/virprocess.c | 17 +++++++++++++---- 3 files changed, 14 insertions(+), 12 deletions(-) changelog: v4: on freebsd error on the logs is a problem appaently. try to fix that. v3: fix non linux implementation v2: fix callers diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c index 53e0872207..3cbc668489 100644 --- a/src/ch/ch_driver.c +++ b/src/ch/ch_driver.c @@ -1073,8 +1073,6 @@ chDomainHelperGetVcpus(virDomainObj *vm, if (virProcessGetStatInfo(&vcpuinfo->cpuTime, &vcpuinfo->cpu, NULL, vm->pid, vcpupid) < 0) { - virReportSystemError(errno, "%s", - _("cannot get vCPU placement & pCPU = time")); return -1; } } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d3d76c003f..65ac5ef367 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1359,8 +1359,6 @@ qemuDomainHelperGetVcpus(virDomainObj *vm, if (virProcessGetStatInfo(&vcpuinfo->cpuTime, &vcpuinfo->cpu, NULL, vm->pid, vcpupid) < 0) { - virReportSystemError(errno, "%s", - _("cannot get vCPU placement & pCPU t= ime")); return -1; } } @@ -2521,8 +2519,6 @@ qemuDomainGetInfo(virDomainPtr dom, if (virDomainObjIsActive(vm)) { if (virProcessGetStatInfo(&(info->cpuTime), NULL, NULL, vm->pid, 0) < 0) { - virReportError(VIR_ERR_OPERATION_FAILED, "%s", - _("cannot read cputime for domain")); goto cleanup; } } @@ -10530,8 +10526,7 @@ qemuDomainMemoryStatsInternal(virQEMUDriver *driver, } =20 if (virProcessGetStatInfo(NULL, NULL, &rss, vm->pid, 0) < 0) { - virReportError(VIR_ERR_OPERATION_FAILED, "%s", - _("cannot get RSS for domain")); + virResetLastError(); } else { stats[ret].tag =3D VIR_DOMAIN_MEMORY_STAT_RSS; stats[ret].val =3D rss; diff --git a/src/util/virprocess.c b/src/util/virprocess.c index b559a4257e..cbb31441cc 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -1779,12 +1779,20 @@ virProcessGetStatInfo(unsigned long long *cpuTime, long rss =3D 0; int cpu =3D 0; =20 - if (!proc_stat || - virStrToLong_ullp(proc_stat[VIR_PROCESS_STAT_UTIME], NULL, 10, &us= ertime) < 0 || + if (!proc_stat) { + VIR_WARN("Unable to get proc stats from the kernel"); + return 0; + } + + if (virStrToLong_ullp(proc_stat[VIR_PROCESS_STAT_UTIME], NULL, 10, &us= ertime) < 0 || virStrToLong_ullp(proc_stat[VIR_PROCESS_STAT_STIME], NULL, 10, &sy= stime) < 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"); + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot parse process status data for pid '%d/%d'= "), + (int) pid, (int) tid); + + return -1; } =20 /* We got jiffies @@ -1881,7 +1889,8 @@ virProcessGetStatInfo(unsigned long long *cpuTime G_G= NUC_UNUSED, pid_t pid G_GNUC_UNUSED, pid_t tid G_GNUC_UNUSED) { - errno =3D ENOSYS; + virReportSystemError(ENOSYS, "%s", + _("Process statistics data is not supported on th= is platform")); return -1; } =20 --=20 2.25.1