From nobody Fri May 3 07:01:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1553739677290768.3340134415932; Wed, 27 Mar 2019 19:21:17 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A9D05308794D; Thu, 28 Mar 2019 02:21:14 +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 7625E19C5A; Thu, 28 Mar 2019 02:21:13 +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 1DAE641F3D; Thu, 28 Mar 2019 02:21:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2S2L6lm012213 for ; Wed, 27 Mar 2019 22:21:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id E73975D75F; Thu, 28 Mar 2019 02:21:06 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-59.phx2.redhat.com [10.3.116.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id DC9965D6B3; Thu, 28 Mar 2019 02:21:02 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 27 Mar 2019 21:20:58 -0500 Message-Id: <20190328022058.22442-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: jtomko@redhat.com Subject: [libvirt] [PATCH] virsh: Don't infloop on snapshot/storage_vol failure 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: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Thu, 28 Mar 2019 02:21:16 +0000 (UTC) Most of our completers used the pattern: if ((nITEM =3D virITEMListAll()) < 0) return NULL; but the virDomainSnapshot and virStorageVolume completers were instead using goto error because of a prior allocation. If the ListAll fails with -1, the cleanup label was running a loop of 'size_t i < int nITEM', which is an extreme waste of CPU cycles. Reported-by: J=C3=A1n Tomko Signed-off-by: Eric Blake Reviewed-by: J=C3=A1n Tomko --- This one is a bug fix, so worth having in 5.2. tools/virsh-completer.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index c4adbb70d0..e9ef9b99f9 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -278,6 +278,7 @@ virshStorageVolNameCompleter(vshControl *ctl, virshControlPtr priv =3D ctl->privData; virStoragePoolPtr pool =3D NULL; virStorageVolPtr *vols =3D NULL; + int rc; int nvols =3D 0; size_t i =3D 0; char **ret =3D NULL; @@ -290,8 +291,9 @@ virshStorageVolNameCompleter(vshControl *ctl, if (!(pool =3D virshCommandOptPool(ctl, cmd, "pool", NULL))) return NULL; - if ((nvols =3D virStoragePoolListAllVolumes(pool, &vols, flags)) < 0) + if ((rc =3D virStoragePoolListAllVolumes(pool, &vols, flags)) < 0) goto error; + nvols =3D rc; if (VIR_ALLOC_N(ret, nvols + 1) < 0) goto error; @@ -631,6 +633,7 @@ virshSnapshotNameCompleter(vshControl *ctl, virshControlPtr priv =3D ctl->privData; virDomainPtr dom =3D NULL; virDomainSnapshotPtr *snapshots =3D NULL; + int rc; int nsnapshots =3D 0; size_t i =3D 0; char **ret =3D NULL; @@ -643,8 +646,9 @@ virshSnapshotNameCompleter(vshControl *ctl, if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) return NULL; - if ((nsnapshots =3D virDomainListAllSnapshots(dom, &snapshots, flags))= < 0) + if ((rc =3D virDomainListAllSnapshots(dom, &snapshots, flags)) < 0) goto error; + nsnapshots =3D rc; if (VIR_ALLOC_N(ret, nsnapshots + 1) < 0) goto error; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list