From nobody Mon Feb 9 11:47:15 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1646414996; cv=none; d=zohomail.com; s=zohoarc; b=XY5/UpReiv/xPu7qry13cAMNvfbV6swstOdj8+rshKTadaI5Cg3sEo442hXJZ0sbbs/cJS5vbVTrBQ/FQQj3EW0ctSXbosu6mzQIQyZsUkwohnwlMOgD37eJ32faVIdwyRMWbFTxhHghHNYESxIH9h8gXNj2JAZCrMxesN3V9f4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646414996; 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=Gdr8TjDkjLy5W7DExOHDVveJSeMoFA4QftzGqf+IoPE=; b=KFajlfK/+92IjsEN2zh+YsicfCzwVu5OFaGPY3KTqXE7B2VInt/2v3rYU5t7AGS3YtysFiV/+oqa+EAzli4IOrlCjRSPMnuNX17c7jQAFu88r6gRqBLftpMRERKs/3rxgEP97S3+Ur5pB+9/K8HdzppbHlxNcwXkp09cE9ycYCI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1646414996767496.09366486781767; Fri, 4 Mar 2022 09:29:56 -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-505-hXS_qlxZPW-M3F-7iziP8A-1; Fri, 04 Mar 2022 12:29:54 -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 6B7A65235; Fri, 4 Mar 2022 17:29:46 +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 4D137841C3; Fri, 4 Mar 2022 17:29:46 +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 EA0AA18087F0; Fri, 4 Mar 2022 17:29:44 +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 224HTPgi024594 for ; Fri, 4 Mar 2022 12:29:25 -0500 Received: by smtp.corp.redhat.com (Postfix) id D14397DE4C; Fri, 4 Mar 2022 17:29:25 +0000 (UTC) Received: from work.speedport.ip (unknown [10.39.195.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id 222EF86B48; Fri, 4 Mar 2022 17:29:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646414995; 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=Gdr8TjDkjLy5W7DExOHDVveJSeMoFA4QftzGqf+IoPE=; b=CXkCyZTzajE4OYQ9YkYolKcdyzt6DbzFopHdboJN46j91SB2H/pOX0i/drkbv2KEiDHCG6 YvVev45JRRwbjPLuxy8n0/+MToRnf2E0vVXmm3jVXWASSa4V797HdXROVlf+dULo7k94D3 9M3Iit8+nEPRn+X+KDY+Pu4cH1cCwas= X-MC-Unique: hXS_qlxZPW-M3F-7iziP8A-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 04/10] netdev: Use automatic mutex management Date: Fri, 4 Mar 2022 18:28:34 +0100 Message-Id: <20220304172840.66057-5-twiederh@redhat.com> In-Reply-To: <20220304172840.66057-1-twiederh@redhat.com> References: <20220304172840.66057-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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: 1646414998125100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake --- src/util/virnetdev.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index fcf679ec37..5df48af60c 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -3568,12 +3568,10 @@ virNetDevReserveName(const char *name) idstr =3D name + strlen(virNetDevGenNames[type].prefix); =20 if (virStrToLong_ui(idstr, NULL, 10, &id) >=3D 0) { - virMutexLock(&virNetDevGenNames[type].mutex); + VIR_LOCK_GUARD lock =3D virLockGuardLock(&virNetDevGenNames[type].= mutex); =20 if (virNetDevGenNames[type].lastID < (int)id) virNetDevGenNames[type].lastID =3D id; - - virMutexUnlock(&virNetDevGenNames[type].mutex); } } =20 @@ -3599,7 +3597,6 @@ virNetDevReserveName(const char *name) int virNetDevGenerateName(char **ifname, virNetDevGenNameType type) { - int id; const char *prefix =3D virNetDevGenNames[type].prefix; double maxIDd =3D pow(10, IFNAMSIZ - 1 - strlen(prefix)); int maxID =3D INT_MAX; @@ -3617,16 +3614,15 @@ virNetDevGenerateName(char **ifname, virNetDevGenNa= meType type) =20 do { g_autofree char *try =3D NULL; + int id =3D 0; =20 - virMutexLock(&virNetDevGenNames[type].mutex); - - id =3D ++virNetDevGenNames[type].lastID; + VIR_WITH_OBJECT_LOCK_GUARD(&virNetDevGenNames[type].mutex) { + id =3D ++virNetDevGenNames[type].lastID; =20 - /* reset before overflow */ - if (virNetDevGenNames[type].lastID >=3D maxID) - virNetDevGenNames[type].lastID =3D -1; - - virMutexUnlock(&virNetDevGenNames[type].mutex); + /* reset before overflow */ + if (virNetDevGenNames[type].lastID >=3D maxID) + virNetDevGenNames[type].lastID =3D -1; + } =20 if (*ifname) try =3D g_strdup_printf(*ifname, id); --=20 2.31.1