From nobody Mon Feb 9 02:28:49 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1586526969; cv=none; d=zohomail.com; s=zohoarc; b=TnA0Z8AFxmUkuJIo/hI7neUdfLpmwIpM/n6nVH4A9DH3YjicTrnveWlLtLU2bFobcszv7nxuGDdzucZi/jROygyXgP+0XSshTYdVXT6ZxBNFzkHlCbHT4YEVMh0N0c4tt76rRjtLTEim/Sdc8gtyjhrqRgk/INfJXBeAkHm6VAU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586526969; 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=RmNs5YiTXO/L2Gdm3k171pCjy6haJpEiana+vjwvc4Y=; b=JqfPb1VLi1ye2fmv0RFJCOE1dETSQ3lCHAnLy97S4dPbjBcWxLGjTTRKAq/u+dm8NKstGvVHJDLaBOExqYrnk2M3bUdukGQDigg6yxn80BtI4bylgFfaXqA/LEa/bQ7eEOvASmowllKzoA55rfq5N6zzk+Rv7fdwQ7o1LcYL8E4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1586526969716639.4371191766066; Fri, 10 Apr 2020 06:56:09 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-486-emyKedM7PjWGYUVQ-pIFng-1; Fri, 10 Apr 2020 09:56:05 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id DC5B98017F6; Fri, 10 Apr 2020 13:55:59 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B4930272A3; Fri, 10 Apr 2020 13:55:59 +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 68A5C18089CF; Fri, 10 Apr 2020 13:55:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 03ADtdsb022916 for ; Fri, 10 Apr 2020 09:55:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id AB9FA10EE823; Fri, 10 Apr 2020 13:55:39 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A7C8F10EE826 for ; Fri, 10 Apr 2020 13:55:37 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B5A16185A78E for ; Fri, 10 Apr 2020 13:55:37 +0000 (UTC) Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-402--MdHEBJiOGaLGE4GkGDohw-1; Fri, 10 Apr 2020 09:55:35 -0400 Received: by mail-wm1-f65.google.com with SMTP id a201so2441134wme.1 for ; Fri, 10 Apr 2020 06:55:35 -0700 (PDT) Received: from localhost.localdomain (public-gprs377075.centertel.pl. [37.47.104.52]) by smtp.gmail.com with ESMTPSA id c11sm3066319wrt.24.2020.04.10.06.55.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Apr 2020 06:55:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586526968; 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=RmNs5YiTXO/L2Gdm3k171pCjy6haJpEiana+vjwvc4Y=; b=h3+Oc787Q8kS1eRQigSIB5iKzGpbpGflQ4hosQ6gjEA0F3cRjpXeGHn7l+AmzxRxROdTID jFeaSriPeQQyJ5DLXmYBzV323sk1krT5mfEcG7SQwEiuevMr1mQ/+AryaK+shVdtSOVBzG NP+pxDfiSkRG/6FzKDzvSAqM/bbO+Hw= X-MC-Unique: emyKedM7PjWGYUVQ-pIFng-1 X-MC-Unique: -MdHEBJiOGaLGE4GkGDohw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SHhxgxt3WYW0SLyJ1s4trYpsnNB6dJrOI0AIR6LDsWA=; b=d+pKxuD8R0rLspBW09tjlO7gk9pptUslKEoJcFsm0AmEdmfrQiR12gryiweDNLIxmS l3aGYFImfR8c0feriZRS/8YOTV3eCnMtuU7FD/a829vHphxcLa7lg6LiWwKGaZly48dK MRDmsRXdJRWcnqlujKUq8o0ayO4BJItfpXP6UqhlBzt8YE43Sq2e3+DwZRMNmZIsQlCh KVOrMVpCkj8A3ZhrlGX6k6oCCxcc3pPlIRaxbK1iKhAw5egBmWctaEF8W64xLoGS0Rxu dT2hDcIw9Hob3U7DtoXGS1c1C0YZOD9Af9AhZnq9SPpls8QOKFvrRA/JICXvGlWX/n48 0YCw== X-Gm-Message-State: AGi0PuZcuULuq2LL/DcCWj0zYbjQZGVdRNpnEKrSZ5L28jrmX9ChkOCx 2k8EWe22UiUK0A6AII3jzOeQYoVouNo= X-Google-Smtp-Source: APiQypJD/g7FQ1SIqAgu2gGf6q0Z35By0IjlzWIQxk4MOPVhA8kk0MaiQmJXuRF4Q6Tw10+GoAGlvQ== X-Received: by 2002:a7b:cbc6:: with SMTP id n6mr5644922wmi.155.1586526933724; Fri, 10 Apr 2020 06:55:33 -0700 (PDT) From: Rafael Fonseca To: libvir-list@redhat.com Subject: [PATCH 04/43] conf: virchrdev: convert virMutex to GMutex Date: Fri, 10 Apr 2020 15:54:31 +0200 Message-Id: <20200410135510.2148319-5-r4f4rfs@gmail.com> In-Reply-To: <20200410135510.2148319-1-r4f4rfs@gmail.com> References: <20200410135510.2148319-1-r4f4rfs@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 03ADtdsb022916 X-loop: libvir-list@redhat.com Cc: Rafael Fonseca 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.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Rafael Fonseca Reviewed-by: Pavel Mores --- src/conf/virchrdev.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/src/conf/virchrdev.c b/src/conf/virchrdev.c index 800e82869e..8280f8e188 100644 --- a/src/conf/virchrdev.c +++ b/src/conf/virchrdev.c @@ -44,7 +44,7 @@ VIR_LOG_INIT("conf.chrdev"); /* structure holding information about character devices * open in a given domain */ struct _virChrdevs { - virMutex lock; + GMutex lock; virHashTablePtr hash; }; =20 @@ -238,12 +238,10 @@ static void virChrdevFDStreamCloseCb(virStreamPtr st = G_GNUC_UNUSED, void *opaque) { virChrdevStreamInfoPtr priv =3D opaque; - virMutexLock(&priv->devs->lock); + g_autoptr(GMutexLocker) locker =3D g_mutex_locker_new(&priv->devs->loc= k); =20 /* remove entry from hash */ virHashRemoveEntry(priv->devs->hash, priv->path); - - virMutexUnlock(&priv->devs->lock); } =20 /** @@ -258,12 +256,7 @@ virChrdevsPtr virChrdevAlloc(void) if (VIR_ALLOC(devs) < 0) return NULL; =20 - if (virMutexInit(&devs->lock) < 0) { - virReportSystemError(errno, "%s", - _("Unable to init device stream mutex")); - VIR_FREE(devs); - return NULL; - } + g_mutex_init(&devs->lock); =20 /* there will hardly be any devices most of the time, the hash * does not have to be huge */ @@ -299,11 +292,11 @@ void virChrdevFree(virChrdevsPtr devs) if (!devs) return; =20 - virMutexLock(&devs->lock); + g_mutex_lock(&devs->lock); virHashForEach(devs->hash, virChrdevFreeClearCallbacks, NULL); virHashFree(devs->hash); - virMutexUnlock(&devs->lock); - virMutexDestroy(&devs->lock); + g_mutex_unlock(&devs->lock); + g_mutex_clear(&devs->lock); =20 VIR_FREE(devs); } @@ -334,6 +327,7 @@ int virChrdevOpen(virChrdevsPtr devs, char *path; int ret; bool added =3D false; + g_autoptr(GMutexLocker) locker =3D g_mutex_locker_new(&devs->lock); =20 switch (source->type) { case VIR_DOMAIN_CHR_TYPE_PTY: @@ -354,12 +348,9 @@ int virChrdevOpen(virChrdevsPtr devs, return -1; } =20 - virMutexLock(&devs->lock); - if ((ent =3D virHashLookup(devs->hash, path))) { if (!force) { /* entry found, device is busy */ - virMutexUnlock(&devs->lock); return 1; } else { /* terminate existing connection */ @@ -378,13 +369,11 @@ int virChrdevOpen(virChrdevsPtr devs, =20 /* create the lock file */ if ((ret =3D virChrdevLockFileCreate(path)) < 0) { - virMutexUnlock(&devs->lock); return ret; } =20 /* obtain a reference to the stream */ if (virStreamRef(st) < 0) { - virMutexUnlock(&devs->lock); return -1; } =20 @@ -428,7 +417,6 @@ int virChrdevOpen(virChrdevsPtr devs, cbdata, virChrdevFDStreamCloseCbFree); =20 - virMutexUnlock(&devs->lock); return 0; =20 error: @@ -440,7 +428,6 @@ int virChrdevOpen(virChrdevsPtr devs, if (cbdata) VIR_FREE(cbdata->path); VIR_FREE(cbdata); - virMutexUnlock(&devs->lock); virChrdevHashEntryFree(ent); return -1; } --=20 2.25.2