From nobody Mon Feb 9 23:38:14 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=1665479196; cv=none; d=zohomail.com; s=zohoarc; b=AkXAVovvu7HUSL0bCpQlfHEogb6QX2Uf4SN6CThDUpISlSCzJEsL/gg9VFNeidMogbaVCsE25G245q6juRgQf+MijYXV8ddxUIJXkJFZLuZymNcD1Nh6lkzsm6UQTDvLssEL8PPjmiuCh6C9R1HZ21RAOrdbszad0OZGhLQJoKA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665479196; h=Content-Type:Content-Transfer-Encoding:Cc: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=kA9+H0wk402bEFRN+xGEPmxUujMUR3ag4MsdEOk5bBA=; b=hE0KbuxwZZEMC9+clKRDZ8gHI8Wj221ydZZq+BSYM+8+l8/97LwjnVEiI0pYyr31qq9MW0qzP3nLjUwdJxgG8sed5VTbHzH4ZFy3GYSyuuVgLj/x6TigTDLGxE++dmgW5xLTxxVxOkXegxa1NGUqyDbLUKSCOZn3DeLbH7F2828= 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 1665479196356110.00159499938582; Tue, 11 Oct 2022 02:06:36 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-262-dy5v5WSLNGO5OeoSnOBW_A-1; Tue, 11 Oct 2022 05:06:33 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 02A48299E740; Tue, 11 Oct 2022 09:06:32 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id E43199E70; Tue, 11 Oct 2022 09:06:31 +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 82C091946A45; Tue, 11 Oct 2022 09:06:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id DC2AB19465A0 for ; Tue, 11 Oct 2022 09:06:24 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id BF0C61121319; Tue, 11 Oct 2022 09:06:24 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.33.36.126]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2588F1121314; Tue, 11 Oct 2022 09:06:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665479195; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=kA9+H0wk402bEFRN+xGEPmxUujMUR3ag4MsdEOk5bBA=; b=RcY2v7I0D2WafPz0t/Xx7qhYY1pAhMyam9yimRvr/0Lnr+XLW8QAn4liiWthJBotIYrUF8 SnD6bDRyG6tGy7QPgeEq7+NqifqDFT+jCBxQe0jpuFN5SfGdw6nrhr9h52bPB5MG6S0dt8 LHMqDDf4ekWh+FLgutPttbC+QrBbpX0= X-MC-Unique: dy5v5WSLNGO5OeoSnOBW_A-1 X-Original-To: libvir-list@listman.corp.redhat.com From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH v2 1/2] conf: define autoptr func for virCapsHostCacheBankFree Date: Tue, 11 Oct 2022 10:06:20 +0100 Message-Id: <20221011090621.1712993-2-berrange@redhat.com> In-Reply-To: <20221011090621.1712993-1-berrange@redhat.com> References: <20221011090621.1712993-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: , Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1665479198309100003 This lets us simplify the cleanup paths when populating the host cache bank information in capabilities XML. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/conf/capabilities.c | 34 ++++++++++++++-------------------- src/conf/capabilities.h | 3 +++ 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 1a7ebf4a13..d693d38f3c 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -2150,9 +2150,7 @@ virCapabilitiesInitCaches(virCaps *caps) size_t i =3D 0; g_autoptr(virBitmap) cpus =3D NULL; ssize_t pos =3D -1; - int ret =3D -1; struct dirent *ent =3D NULL; - virCapsHostCacheBank *bank =3D NULL; const virResctrlMonitorType montype =3D VIR_RESCTRL_MONITOR_TYPE_CACHE; const char *prefix =3D virResctrlMonitorPrefixTypeToString(montype); =20 @@ -2172,10 +2170,11 @@ virCapabilitiesInitCaches(virCaps *caps) int rv =3D -1; g_autoptr(DIR) dirp =3D NULL; g_autofree char *path =3D g_strdup_printf("%s/cpu/cpu%zd/cache/", = SYSFS_SYSTEM_PATH, pos); + g_autoptr(virCapsHostCacheBank) bank =3D NULL; =20 rv =3D virDirOpenIfExists(&dirp, path); if (rv < 0) - goto cleanup; + return -1; =20 if (!dirp) continue; @@ -2191,7 +2190,7 @@ virCapabilitiesInitCaches(virCaps *caps) if (virFileReadValueUint(&level, "%s/cpu/cpu%zd/cache/%s/level", SYSFS_SYSTEM_PATH, pos, ent->d_name) = < 0) - goto cleanup; + return -1; =20 if (level < cache_min_level) continue; @@ -2202,33 +2201,33 @@ virCapabilitiesInitCaches(virCaps *caps) if (virFileReadValueUint(&bank->id, "%s/cpu/cpu%zd/cache/%s/id", SYSFS_SYSTEM_PATH, pos, ent->d_name) = < 0) - goto cleanup; + return -1; =20 if (virFileReadValueUint(&bank->level, "%s/cpu/cpu%zd/cache/%s/level", SYSFS_SYSTEM_PATH, pos, ent->d_name) = < 0) - goto cleanup; + return -1; =20 if (virFileReadValueString(&type, "%s/cpu/cpu%zd/cache/%s/type", SYSFS_SYSTEM_PATH, pos, ent->d_name= ) < 0) - goto cleanup; + return -1; =20 if (virFileReadValueScaledInt(&bank->size, "%s/cpu/cpu%zd/cache/%s/size", SYSFS_SYSTEM_PATH, pos, ent->d_n= ame) < 0) - goto cleanup; + return -1; =20 if (virFileReadValueBitmap(&bank->cpus, "%s/cpu/cpu%zd/cache/%s/shared_cpu_= list", SYSFS_SYSTEM_PATH, pos, ent->d_name= ) < 0) - goto cleanup; + return -1; =20 kernel_type =3D virCacheKernelTypeFromString(type); if (kernel_type < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unknown cache type '%s'"), type); - goto cleanup; + return -1; } =20 bank->type =3D kernel_type; @@ -2244,15 +2243,13 @@ virCapabilitiesInitCaches(virCaps *caps) bank->size, &bank->ncontrols, &bank->controls) < 0) - goto cleanup; + return -1; =20 VIR_APPEND_ELEMENT(caps->host.cache.banks, caps->host.cach= e.nbanks, bank); } - - g_clear_pointer(&bank, virCapsHostCacheBankFree); } if (rv < 0) - goto cleanup; + return -1; } =20 /* Sort the array in order for the tests to be predictable. This way = we can @@ -2264,16 +2261,13 @@ virCapabilitiesInitCaches(virCaps *caps) } =20 if (virCapabilitiesInitResctrlMemory(caps) < 0) - goto cleanup; + return -1; =20 if (virResctrlInfoGetMonitorPrefix(caps->host.resctrl, prefix, &caps->host.cache.monitor) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - virCapsHostCacheBankFree(bank); - return ret; + return 0; } =20 =20 diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index 6fe7818b2e..ef6e8ab685 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -137,6 +137,9 @@ struct _virCapsHostCacheBank { virResctrlInfoPerCache **controls; }; =20 +void virCapsHostCacheBankFree(virCapsHostCacheBank *ptr); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCapsHostCacheBank, virCapsHostCacheBankFr= ee); + struct _virCapsHostCache { size_t nbanks; virCapsHostCacheBank **banks; --=20 2.37.3