From nobody Mon Feb 9 12:43:35 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=1644359618; cv=none; d=zohomail.com; s=zohoarc; b=ShG2b2fqbDHIWhE0rN4+HBC8pN92Xqgn0/mgaqm7ZcXmJOXgSP/Ui5jxQpI57IjlUZ/C9B33vCJkAdvKxCRGnFe8PJbZNoNpkrh2e5mW3YZP0ayOiWBmjRcGhTVp3niOCwoP3vjYdeXI5xTWiAQiRzxDlcJmlvY/u41FKm8981w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644359618; 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=/fuYmExAYHhYl/QNRWSwSwFK5MALS2/pmQfNIu+n46o=; b=b31PvyfEcDG0alUX9DzZUSyuIapqQtqXYwPI9zfib9sbINB9JXLT29t/5vNYLKKBEwS9AFw8o2pPV0ckwmn9p1g+ZEv5kD5TvD1MR1bJvcjOVTyZoIwksCJCpRxwcO8tY+1Ac7z1ovpjmGzaAJDpTJTsGQIrder4WpNg+AkaZ3E= 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 164435961853648.81980126641554; Tue, 8 Feb 2022 14:33:38 -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-270-2-2VHDmkNfWT0uvaZcRCXw-1; Tue, 08 Feb 2022 17:33:34 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BA8D85AB6; Tue, 8 Feb 2022 22:33:29 +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 9CC424CEFC; Tue, 8 Feb 2022 22:33:29 +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 446015005D; Tue, 8 Feb 2022 22:33:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 217DCJOw006305 for ; Mon, 7 Feb 2022 08:12:19 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5FBD61038AC9; Mon, 7 Feb 2022 13:12:19 +0000 (UTC) Received: from work.redhat.com (unknown [10.39.192.210]) by smtp.corp.redhat.com (Postfix) with ESMTP id AB3FB1038AC4; Mon, 7 Feb 2022 13:12:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644359618; 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=/fuYmExAYHhYl/QNRWSwSwFK5MALS2/pmQfNIu+n46o=; b=GUPfHQvLUgzp2VFUg+55xmckP7YaZ1HnSBnEVbV7pd0isKdw+Auut2CmXppj78jLchUAvU IMENB4EutynI8bs7THjqn0h76B+W4yKOEY2nQmZia+SwXPOxerNTUweaO58XTYJQEkTwjU Ea0hK2JgfIrlTnW7bHXE/DcOjFbSe70= X-MC-Unique: 2-2VHDmkNfWT0uvaZcRCXw-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 03/11] libxl: Use automatic memory management Date: Mon, 7 Feb 2022 14:12:06 +0100 Message-Id: <20220207131214.54855-4-twiederh@redhat.com> In-Reply-To: <20220207131214.54855-1-twiederh@redhat.com> References: <20220207131214.54855-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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.15 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: 1644359620574100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake --- src/libxl/libxl_conf.c | 8 ++------ src/libxl/libxl_conf.h | 12 ------------ src/libxl/libxl_logger.c | 20 +++++++++----------- 3 files changed, 11 insertions(+), 29 deletions(-) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index f062f8e958..a0fc51c74a 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -1815,12 +1815,8 @@ libxlDriverConfigInit(libxlDriverConfig *cfg) libxlDriverConfig * libxlDriverConfigGet(libxlDriverPrivate *driver) { - libxlDriverConfig *cfg; - - libxlDriverLock(driver); - cfg =3D virObjectRef(driver->config); - libxlDriverUnlock(driver); - return cfg; + VIR_LOCK_GUARD lock =3D virLockGuardLock(&driver->lock); + return virObjectRef(driver->config); } =20 int libxlDriverConfigLoadFile(libxlDriverConfig *cfg, diff --git a/src/libxl/libxl_conf.h b/src/libxl/libxl_conf.h index b74f455b69..16a7195bfd 100644 --- a/src/libxl/libxl_conf.h +++ b/src/libxl/libxl_conf.h @@ -219,15 +219,3 @@ libxlBuildDomainConfig(virPortAllocatorRange *graphics= ports, virDomainDef *def, libxlDriverConfig *cfg, libxl_domain_config *d_config); - -static inline void -libxlDriverLock(libxlDriverPrivate *driver) -{ - virMutexLock(&driver->lock); -} - -static inline void -libxlDriverUnlock(libxlDriverPrivate *driver) -{ - virMutexUnlock(&driver->lock); -} diff --git a/src/libxl/libxl_logger.c b/src/libxl/libxl_logger.c index 4708553f29..45cdc32f38 100644 --- a/src/libxl/libxl_logger.c +++ b/src/libxl/libxl_logger.c @@ -79,16 +79,16 @@ libvirt_vmessage(xentoollog_logger *logger_in, /* Should we print to a domain-specific log file? */ if ((start =3D strstr(message, ": Domain ")) && (end =3D strstr(start + 9, ":"))) { - FILE *domainLogFile; + FILE *domainLogFile =3D NULL; =20 VIR_DEBUG("Found domain log message"); =20 start =3D start + 9; *end =3D '\0'; =20 - virMutexLock(&lg->tableLock); - domainLogFile =3D virHashLookup(lg->files, start); - virMutexUnlock(&lg->tableLock); + VIR_WITH_MUTEX_LOCK_GUARD(&lg->tableLock) { + domainLogFile =3D virHashLookup(lg->files, start); + } if (domainLogFile) logFile =3D domainLogFile; =20 @@ -197,9 +197,9 @@ libxlLoggerOpenFile(libxlLogger *logger, path, g_strerror(errno)); return; } - virMutexLock(&logger->tableLock); - ignore_value(virHashAddEntry(logger->files, domidstr, logFile)); - virMutexUnlock(&logger->tableLock); + VIR_WITH_MUTEX_LOCK_GUARD(&logger->tableLock) { + ignore_value(virHashAddEntry(logger->files, domidstr, logFile)); + } =20 /* domain_config is non NULL only when starting a new domain */ if (domain_config) { @@ -211,10 +211,8 @@ libxlLoggerOpenFile(libxlLogger *logger, void libxlLoggerCloseFile(libxlLogger *logger, int id) { - g_autofree char *domidstr =3D NULL; - domidstr =3D g_strdup_printf("%d", id); + g_autofree char *domidstr =3D g_strdup_printf("%d", id); + VIR_LOCK_GUARD lock =3D virLockGuardLock(&logger->tableLock); =20 - virMutexLock(&logger->tableLock); ignore_value(virHashRemoveEntry(logger->files, domidstr)); - virMutexUnlock(&logger->tableLock); } --=20 2.31.1