From nobody Sun Feb 8 17:46:51 2026 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; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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=1638454972; cv=none; d=zohomail.com; s=zohoarc; b=IIXE4poGkesFkHGmJzELcbRxk6seCx76as5NZJPyKm5YdWJn4AEP7r/IrzGhA83Zgd2HEP2zMYD8QxMn88RwD+N+6amcCeB8azBAf1btcDVXOk1nAk590wPB5b4CNEXIUNCe2sZceKfiV7BGwLqS37To3KsyYLtn/gbUVXbBodw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638454972; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Kp5g2ISe5T0wg8mNNuS+wfOSkhBNcrCSfV2yAbsuJ/Q=; b=lyk5S3vNUU9+9yNmTwFg/f2GpKSisIY3PsJXc2XRQVDNI/UQeOFazV5Mp6nkHFL5Y6CFf6+kA/talEHG9z1w+sGhbbbUISQH2pnTiKQ1AsTtm/kRYNpb/qD6cKaCaW6i3wdycUl+lqVzESPb9830jTS7jlibZzytif5WBD4P+sA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1638454972772251.1546083871781; Thu, 2 Dec 2021 06:22:52 -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-16--m4WO22rPVaG4bQqLVzBmA-1; Thu, 02 Dec 2021 09:22:50 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0C5AB1926DA1; Thu, 2 Dec 2021 14:22:44 +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 B7AB810023AE; Thu, 2 Dec 2021 14:22:42 +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 D5DCF4BB7C; Thu, 2 Dec 2021 14:22:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1B2EMC8G026698 for ; Thu, 2 Dec 2021 09:22:12 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0E08776608; Thu, 2 Dec 2021 14:22:12 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8ADC877E21 for ; Thu, 2 Dec 2021 14:22:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1638454971; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Kp5g2ISe5T0wg8mNNuS+wfOSkhBNcrCSfV2yAbsuJ/Q=; b=Otm6e0dzLOceQXSNYiAR0WNmgGvjYxJutWYHea56OhFSiUWw213X8UHlXslDRle4cG9XuP Tiam+Pl9+sLznfxway17Fp3SAYZSRb30rlzoi2yaltbVqPUloK8z1Ip9saVXGuakt3Tjgd Hc1ijQUhqXhEvIWM16X5rcWxI4r31Nk= X-MC-Unique: -m4WO22rPVaG4bQqLVzBmA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 3/3] qemuConnectGetAllDomainStats: Simplify qemuDomainGetStats() error handling Date: Thu, 2 Dec 2021 15:22:07 +0100 Message-Id: <1e62fc566b808649ab78fcee58df5f8d88335584.1638454853.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.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.84 on 10.5.11.22 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-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1638454973675100001 Content-Type: text/plain; charset="utf-8" In qemuConnectGetAllDomainStats() there a loop that iterates over all domains that stats are to be fetched for. Within this loop the qemuDomainGetStats() is called which is responsible for fetching stats for an individual domain. Now, the code that handles successful and failure cases is almost the same. Rework it, so that the code is deduplicated. Note, that the check for !tmp is dropped because upon successful return from qemuDomainGetStats() it is always allocated. Signed-off-by: Michal Privoznik --- src/qemu/qemu_driver.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f12a5aef11..6333d0af36 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -18830,6 +18830,10 @@ qemuConnectGetAllDomainStats(virConnectPtr conn, unsigned int privflags =3D 0; unsigned int requestedStats =3D stats; unsigned int domflags =3D 0; + int rc; + + if (flags & VIR_CONNECT_GET_ALL_DOMAINS_STATS_BACKING) + domflags |=3D QEMU_DOMAIN_STATS_BACKING; =20 virObjectLock(vm); =20 @@ -18854,23 +18858,17 @@ qemuConnectGetAllDomainStats(virConnectPtr conn, } /* else: without a job it's still possible to gather some data */ =20 - if (flags & VIR_CONNECT_GET_ALL_DOMAINS_STATS_BACKING) - domflags |=3D QEMU_DOMAIN_STATS_BACKING; - if (qemuDomainGetStats(conn, vm, requestedStats, &tmp, domflags) <= 0) { - if (HAVE_JOB(domflags) && vm) - qemuDomainObjEndJob(driver, vm); - - virObjectUnlock(vm); - goto cleanup; - } - - if (tmp) - tmpstats[nstats++] =3D tmp; + rc =3D qemuDomainGetStats(conn, vm, requestedStats, &tmp, domflags= ); =20 if (HAVE_JOB(domflags)) qemuDomainObjEndJob(driver, vm); =20 virObjectUnlock(vm); + + if (rc < 0) + goto cleanup; + + tmpstats[nstats++] =3D tmp; } =20 *retStats =3D g_steal_pointer(&tmpstats); --=20 2.32.0