From nobody Thu May 9 23:48:39 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=1695740413; cv=none; d=zohomail.com; s=zohoarc; b=YeMpZG0Q4p7uph0xNXTT0ObyyCZX2vEDHfuRyIVWBeZynAQuXwMYMX+JQGRxxdmFhppjXOfNIXj1nKxw8uzPA4QKBCKvZu0rpkqZVPGXSlAWIFmmHMncrSEhVcaU5Zl/Tw81T8vVXASuve8gLfPMvQWTCi3r6q/rRdYK6b974cA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695740413; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=07gFhcKFZUwkZ3rxhyJfm/ItTeCNHlFG4hItXz4RYOM=; b=XXu6eFeNwaptfR6P75STYz0yWUyAKq9DjY4YoCshH1ScW0rK7xgJdoNedJFSijHBx+oWvKgdMbQrlKX2XTyAbyopt0sb5TsNnFXRnlRN/5+oB1YljlzKeEdLK9EbXay538bxCrr7YlMAZFulc/I/7W9nnMgiUWiY11eGRMdMM/4= 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 1695740413915817.9779660725065; Tue, 26 Sep 2023 08:00:13 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-495-TWZ1gVSePrGG_ARd5kDqkw-1; Tue, 26 Sep 2023 11:00:08 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (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 23017101A53B; Tue, 26 Sep 2023 15:00:04 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 60992400F36; Tue, 26 Sep 2023 15:00:03 +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 22598194658D; Tue, 26 Sep 2023 14:59:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2BCF8194658C for ; Tue, 26 Sep 2023 13:56:26 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 18FAEC03292; Tue, 26 Sep 2023 13:56:26 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 12335C15BB8 for ; Tue, 26 Sep 2023 13:56:26 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 E55CE85A5BA for ; Tue, 26 Sep 2023 13:56:25 +0000 (UTC) Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-446-fLvOehlcMVCWFMChnaXtbA-1; Tue, 26 Sep 2023 09:56:24 -0400 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-993d7ca4607so737864866b.1 for ; Tue, 26 Sep 2023 06:56:24 -0700 (PDT) Received: from wheatley.localdomain (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id v5-20020a1709064e8500b00993470682e5sm7766952eju.32.2023.09.26.06.56.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 06:56:22 -0700 (PDT) Received: from wheatley.brq.redhat.com (wheatley.k8r.cz [127.0.0.1]) by wheatley.localdomain (Postfix) with ESMTP id 34EF115125FC4 for ; Tue, 26 Sep 2023 15:56:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695740412; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=07gFhcKFZUwkZ3rxhyJfm/ItTeCNHlFG4hItXz4RYOM=; b=J4ofwtlx+v0h3W4osavVY4RCLJdpVBEhJ8UVnNfWRpRTCZR5wgbeo4tCEG+YYcvaV3G64X FvLEmvZcqyFKdwctVCc/O7KfAX8uWo3ADVK6m95M5asG9fmlkDlJbxsd+1Wjtg65Gm+ojJ z6uwwLHlZG5u7zpsNghun1np6cGb8x4= X-MC-Unique: TWZ1gVSePrGG_ARd5kDqkw-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: fLvOehlcMVCWFMChnaXtbA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695736583; x=1696341383; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=07gFhcKFZUwkZ3rxhyJfm/ItTeCNHlFG4hItXz4RYOM=; b=A+EsdtJCdm9CGW1BpeQiesa8MbIwtGdZ1BYj17DG8JB0IuPGfHSE+tzsYKd14/STuG rPatWZfa3iNeKl67bTjQKnHofklQ3Vb+mC4DLkeInHU0E6/ZKBF5kDBfvToMO+r5mPJ0 boRu8bg7exkhLcKyZtJmDoyrZT7r6OtZv4L1BMDT57ruzU7ELQ6T+LjW7ZK4be+k4h1Q T6p7SjfBOSryYZ0WID+SnryrbLK47htI5b0720zqnWlQru+2tNg26mqQz5MskLfa5HWj LEJW8zlgxQrU4oJ7r80PIs/yPbLNX5HTod2l+edchwHLr5xmNgJOTHX0Rbyet1eswYrf 2IUA== X-Gm-Message-State: AOJu0YzKdYC8hTKqPGemaPZ+S7/c+guc+V3cfzV7JX75r/Kd25eTRb6T 7teuxUpltBZkSnz/mmI9haTOo1aS5AkY3DniiNpo5Y1UwCHlIQgwEvOjcu7fE7kL6rT9IkAfYPn 4Z6im999BwetRqRuPuaVrB6EQkOr4l8oNTYrzCItLHAldwibta0mnCt0VGm7wISvnvharyC0uM0 gd7bg= X-Received: by 2002:a17:907:1de6:b0:9ae:57b8:ad1b with SMTP id og38-20020a1709071de600b009ae57b8ad1bmr9089772ejc.21.1695736583282; Tue, 26 Sep 2023 06:56:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHMyvn3qfOqD+bw+8yLHl4wbMgW59qgTD5APtBkDWsbs+YAA5o4FxOVx5nyk/DRfVfrYrnz/Q== X-Received: by 2002:a17:907:1de6:b0:9ae:57b8:ad1b with SMTP id og38-20020a1709071de600b009ae57b8ad1bmr9089758ejc.21.1695736582862; Tue, 26 Sep 2023 06:56:22 -0700 (PDT) From: Martin Kletzander To: libvir-list@redhat.com Subject: [PATCH] virsh: Account for return values in virNodeGetFreePages Date: Tue, 26 Sep 2023 15:56:19 +0200 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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: 1695740415341100001 Content-Type: text/plain; charset="utf-8"; x-default="true" The function returns how many array items were filled in, but virsh never checked for anything other than errors. Just to make sure this does not report invalid data, even though the only possibility would be reporting 0 free pages, check the returned data so that possible errors are detected. Signed-off-by: Martin Kletzander Reviewed-by: Michal Privoznik --- tools/virsh-host.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/tools/virsh-host.c b/tools/virsh-host.c index 21aca5f6dc83..411648197895 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -328,6 +328,8 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) bool cellno =3D vshCommandOptBool(cmd, "cellno"); bool pagesz =3D vshCommandOptBool(cmd, "pagesize"); virshControl *priv =3D ctl->privData; + bool pagesize_missing =3D false; + int rv =3D -1; =20 VSH_EXCLUSIVE_OPTIONS_VAR(all, cellno); =20 @@ -407,16 +409,22 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) goto cleanup; } =20 - if (virNodeGetFreePages(priv->conn, npages, pagesize, - cell, 1, counts, 0) < 0) + rv =3D virNodeGetFreePages(priv->conn, npages, pagesize, + cell, 1, counts, 0); + if (rv < 0) goto cleanup; =20 + if (rv < npages) { + pagesize_missing =3D true; + vshError(ctl, _("Did not get all free page data for node %= 1$d"), cell); + continue; + } + vshPrint(ctl, _("Node %1$d:\n"), cell); for (j =3D 0; j < npages; j++) vshPrint(ctl, "%uKiB: %lld\n", pagesize[j], counts[j]); vshPrint(ctl, "%c", '\n'); } - } else { if (!cellno) { vshError(ctl, "%s", _("missing cellno argument")); @@ -443,14 +451,22 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) =20 counts =3D g_new0(unsigned long long, 1); =20 - if (virNodeGetFreePages(priv->conn, 1, pagesize, - cell, 1, counts, 0) < 0) + rv =3D virNodeGetFreePages(priv->conn, 1, pagesize, + cell, 1, counts, 0); + if (rv < 0) goto cleanup; =20 + if (rv =3D=3D 0) { + vshError(ctl, + "Could not get count of free %uKiB pages, no data ret= urned", + *pagesize); + goto cleanup; + } + vshPrint(ctl, "%uKiB: %lld\n", *pagesize, counts[0]); } =20 - ret =3D true; + ret =3D !pagesize_missing; cleanup: VIR_FREE(nodes); return ret; --=20 2.42.0