From nobody Thu Apr 25 00:01:05 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; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1641896463274516.5626149769342; Tue, 11 Jan 2022 02:21:03 -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-669-qCTQwyKbPOW4f12GSlrgKQ-1; Tue, 11 Jan 2022 05:21:00 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 65F9F100C610; Tue, 11 Jan 2022 10:20:55 +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 D50C170D20; Tue, 11 Jan 2022 10:20:54 +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 692A14BB7C; Tue, 11 Jan 2022 10:20:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 20BAKqaR005350 for ; Tue, 11 Jan 2022 05:20:53 -0500 Received: by smtp.corp.redhat.com (Postfix) id DCEBC492D19; Tue, 11 Jan 2022 10:20:52 +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 D7D94492D18 for ; Tue, 11 Jan 2022 10:20:52 +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 BE56D8011A5 for ; Tue, 11 Jan 2022 10:20:52 +0000 (UTC) Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-2-jQRm20s2NCC-lZrsKdyNwQ-1; Tue, 11 Jan 2022 05:20:50 -0500 Received: by mail-pl1-f169.google.com with SMTP id e19so9757093plc.10 for ; Tue, 11 Jan 2022 02:20:50 -0800 (PST) Received: from anisinha-lenovo.ba.nuagenetworks.net ([115.96.198.102]) by smtp.googlemail.com with ESMTPSA id p37sm10877519pfh.97.2022.01.11.02.20.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jan 2022 02:20:48 -0800 (PST) X-MC-Unique: qCTQwyKbPOW4f12GSlrgKQ-1 X-MC-Unique: jQRm20s2NCC-lZrsKdyNwQ-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=RRKj4E8xQyqTbPEpoIUju7FXqQHMV9gzJU+Tu4gz6ZM=; b=3cycRNYa3RHkMnr33ZnIkcDQxTA4G02hhwQ2eOLMLLdBmJYFsrP2Q6SbVImb272jg/ YSP5sdIVnLmTqB3N0EQcMcBKQlTpzkjbUKuMqMmdWgfyPMcPo25kr2PfZaavlxuu/zG7 /kFCIY3+6E9dAxgZUMYFTOaHhEggv/tmh346fLeo9egc8hUuIyUlPfT9i81sh2nd9DUp jRH+pYKN2nzST4+f5hC1s7pYXUzBN0WLLyoC/56ofO38gcHjMH7R1jRNiKzauQ6DpMjH 6VfyrPk1ANkgQt7XzvpsLo0kVVSiUQziylxWh0FV+kio10G95jvCjPmF8y8ngDXNWNRo ufaw== X-Gm-Message-State: AOAM532DpaEm6/JFddQDavi0jChSd2JEi3zf+nTGsiYOL9RlcVo52t9a QG2oPcJvk0v/XkjaibFMEuWKbkroigmqD8gN X-Google-Smtp-Source: ABdhPJxeLCUj58z5x/t+htoo3thphIFGQdMtvSZDoZHnJCUjMUGsQtJxoD/WWjt7Sy4VZO63IRE75Q== X-Received: by 2002:a63:c6:: with SMTP id 189mr3453359pga.85.1641896449259; Tue, 11 Jan 2022 02:20:49 -0800 (PST) From: Ani Sinha To: libvir-list@redhat.com Subject: [PATCH v3] report error when virProcessGetStatInfo() is unable to parse data Date: Tue, 11 Jan 2022 15:50:43 +0530 Message-Id: <20220111102043.384822-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.85 on 10.11.54.9 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.11 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: 1641896464502100003 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 Reviewed-by: Michal Privoznik --- src/ch/ch_driver.c | 2 -- src/qemu/qemu_driver.c | 7 +------ src/util/virprocess.c | 9 +++++++-- 3 files changed, 8 insertions(+), 10 deletions(-) changelog: 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..9a17c93b08 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")); + return -1; } 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..709ec616de 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -1784,7 +1784,11 @@ virProcessGetStatInfo(unsigned long long *cpuTime, 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 +1885,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