From nobody Sun May 5 19:40:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582308679; cv=none; d=zohomail.com; s=zohoarc; b=ZLj0hdpO+Ta7d+Yyu9tNEOYXw3qrxraDzZFMHBRrMIcyOXBCjZn+Rv/NwIlav/cs74Hf+oLxJVNHcm77W2iAulbkA88xNE4ee8aS1+GY1pwxPkLKHGIIf211NNBbnzGNZOA2MQtN7Npa3/Lg+bJQufcUFDbtQS/n2jBcU1VVjBQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582308679; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=oEq9SHw9Yx4SkPYeVqtOb4Y02Ep1FHH3+FgW7Bi40/8=; b=LhwshygXmYoRev2xA55IW6N2m5EORhl0mStz29SUcgyPIWTUUVpAz7MyEQdBw0nNY8+zo4XmXRebt1pHZnrUvf3fYpn5LG/Hi+Ykb+4ys9dgYI2jWEPlMdbl6CTGQ+sy3yTZlB0yI/qPi6t42eCze7Yr86BCc2/kNigezsS9ugI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1582308679530281.89044098715317; Fri, 21 Feb 2020 10:11:19 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-165-RaCIbesnMaOJ1DdPraKa3w-1; Fri, 21 Feb 2020 13:11:15 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4130A107BAA4; Fri, 21 Feb 2020 18:11:08 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5200160CCC; Fri, 21 Feb 2020 18:11:07 +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 5202418089C8; Fri, 21 Feb 2020 18:11:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 01LIB2Wk017495 for ; Fri, 21 Feb 2020 13:11:02 -0500 Received: by smtp.corp.redhat.com (Postfix) id 01EF41649EE; Fri, 21 Feb 2020 18:11:02 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F14581649F6 for ; Fri, 21 Feb 2020 18:10:59 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C53C6185A78F for ; Fri, 21 Feb 2020 18:10:59 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-215-7hiZDb44OjKvYweQNStJHQ-1; Fri, 21 Feb 2020 13:10:56 -0500 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01LI5Wk5111182 for ; Fri, 21 Feb 2020 13:10:56 -0500 Received: from ppma04dal.us.ibm.com (7a.29.35a9.ip4.static.sl-reverse.com [169.53.41.122]) by mx0b-001b2d01.pphosted.com with ESMTP id 2yac0u9v8q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Feb 2020 13:10:55 -0500 Received: from pps.filterd (ppma04dal.us.ibm.com [127.0.0.1]) by ppma04dal.us.ibm.com (8.16.0.27/8.16.0.27) with SMTP id 01LIAqac018721 for ; Fri, 21 Feb 2020 18:10:54 GMT Received: from b01cxnp23033.gho.pok.ibm.com (b01cxnp23033.gho.pok.ibm.com [9.57.198.28]) by ppma04dal.us.ibm.com with ESMTP id 2y6897mrda-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Feb 2020 18:10:54 +0000 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp23033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 01LIArD549217982 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Feb 2020 18:10:53 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 15696112070; Fri, 21 Feb 2020 18:10:53 +0000 (GMT) Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B06EA112067; Fri, 21 Feb 2020 18:10:52 +0000 (GMT) Received: from localhost (unknown [9.85.166.207]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP; Fri, 21 Feb 2020 18:10:52 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582308678; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=oEq9SHw9Yx4SkPYeVqtOb4Y02Ep1FHH3+FgW7Bi40/8=; b=PiJ6MnmeDWtK+smvfeHp5IwOPLriPy+0kC/0bvDhYKBvnMLdT+bhQuOy+tLjedJ8sR//Ir LiVQLsKYAPewWlG5t5tpUD6vAPjalqLEMmn03WvgDI6h/lAPx3IWoPTJOoY9jqUHBceZOu 6qFZc/nNsedJVqQvq1vCQhAufhkC6H0= X-MC-Unique: RaCIbesnMaOJ1DdPraKa3w-1 X-MC-Unique: 7hiZDb44OjKvYweQNStJHQ-1 From: "Mauro S. M. Rodrigues" To: libvir-list@redhat.com Subject: [PATCH] util: virhostcpu: Fail when fetching CPU Stats for invalid cpu Date: Fri, 21 Feb 2020 15:10:45 -0300 Message-Id: <20200221181045.469759-1-maurosr@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.572 definitions=2020-02-21_06:2020-02-21, 2020-02-21 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 bulkscore=0 adultscore=0 spamscore=0 mlxscore=0 impostorscore=0 malwarescore=0 clxscore=1011 priorityscore=1501 suspectscore=1 mlxlogscore=940 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002210138 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 01LIB2Wk017495 X-loop: libvir-list@redhat.com Cc: maurosr@linux.vnet.ibm.com 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.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" virHostCPUGetStatsLinux walks through every cpu in /proc/stat until it finds cpu%cpuNum that matches with the requested cpu. If none is found it logs the error but it should return -1, instead of 0. Otherwise virsh nodecpustats --cpu and API bindings don't fail properly, printing a blank line instead of an error message. This patch also includes an additional test for virhostcputest to avoid this regression to happen again in the future. Reported-by: Satheesh Rajendran Signed-off-by: Mauro S. M. Rodrigues Reviewed-by: Christian Ehrhardt Reviewed-by: Michal Privoznik Tested-by: Christian Ehrhardt --- src/util/virhostcpu.c | 2 +- tests/virhostcputest.c | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index 81293eea8c..20c8d0ce6c 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -847,7 +847,7 @@ virHostCPUGetStatsLinux(FILE *procstat, _("Invalid cpuNum in %s"), __FUNCTION__); =20 - return 0; + return -1; } =20 =20 diff --git a/tests/virhostcputest.c b/tests/virhostcputest.c index 7865b61578..2f569d8bd4 100644 --- a/tests/virhostcputest.c +++ b/tests/virhostcputest.c @@ -258,14 +258,17 @@ mymain(void) if (virTestRun(nodeData[i].testName, linuxTestHostCPU, &nodeData[i= ]) !=3D 0) ret =3D -1; =20 -# define DO_TEST_CPU_STATS(name, ncpus) \ +# define DO_TEST_CPU_STATS(name, ncpus, shouldFail) \ do { \ static struct nodeCPUStatsData data =3D { name, ncpus }; \ - if (virTestRun("CPU stats " name, linuxTestNodeCPUStats, &data) < = 0) \ + if ((virTestRun("CPU stats " name, \ + linuxTestNodeCPUStats, \ + &data) < 0) !=3D shouldFail) \ ret =3D -1; \ } while (0) =20 - DO_TEST_CPU_STATS("24cpu", 24); + DO_TEST_CPU_STATS("24cpu", 24, false); + DO_TEST_CPU_STATS("24cpu", 25, true); =20 return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } --=20 2.24.1