From nobody Mon Feb 9 12:42:53 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=1646414996; cv=none; d=zohomail.com; s=zohoarc; b=dBBh+dis5poabhRft4p2RdJx3pEMzj0xLVFzPDVEp2KFY1+SFwEyrT4OD2OhMf6qN6D/AC/Vg4mqXRtBQkBd6ZbDqP9pxf2d+dyf5I3XOgN3uIf3ou7d4vd9Itl3PTo7hyrJjI5It6kovhSvjgT1POB14UzGhFsis/FUK2YHoYo= 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=pJ0c/UAJ6iExuoo2QrgM5WW4DEBjwczSp/J4+G17AlE=; b=dsvJFMMyTDN9hvyTVvXjDkw/cjiZgunOyFn8tySgj+ioPrkujHLRr0i20bcTa0nMV7QgUatoTFLmR0CflZrs5oE7mC5BQR1ark5dgLWrTT0bUFg5AM0zbBy3c0ToufDPCjxmwyHqOQsfgcqa4PjAV0iWVf6ogdGQVkalbBHYlPM= 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 1646414996436532.3074250920927; 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-620-C_VMF3aBNIu_ycFHw7S9bQ-1; Fri, 04 Mar 2022 12:29:52 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 45CEA1854E2F; Fri, 4 Mar 2022 17:29:46 +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 F314486586; Fri, 4 Mar 2022 17:29:45 +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 C7AD046F98; Fri, 4 Mar 2022 17:29:45 +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 224HTUkV024630 for ; Fri, 4 Mar 2022 12:29:30 -0500 Received: by smtp.corp.redhat.com (Postfix) id 907D284796; Fri, 4 Mar 2022 17:29:30 +0000 (UTC) Received: from work.speedport.ip (unknown [10.39.195.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id A4E5F7DE4C; Fri, 4 Mar 2022 17:29:29 +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=pJ0c/UAJ6iExuoo2QrgM5WW4DEBjwczSp/J4+G17AlE=; b=CTAYEjsO/DXGBcOuEWG/04W3XvcnGtuk0nHpjy6uz+w2n3CsmKRuSYH1N3rVv4YI5sXlF2 aaPHkPtGd1o12oY+agHNL4Hbic35ZjXolK8TB3eWe5kF+nyx0rbcB+mRhK/ALIKezhNGVk r98t/XKxaY0pYRWbudbOPktola/7NUc= X-MC-Unique: C_VMF3aBNIu_ycFHw7S9bQ-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 08/10] esx_vi: Use automatic mutex management Date: Fri, 4 Mar 2022 18:28:38 +0100 Message-Id: <20220304172840.66057-9-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.13 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: 1646414998145100002 Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake --- src/esx/esx_vi.c | 109 ++++++++++++++++++++--------------------------- 1 file changed, 47 insertions(+), 62 deletions(-) diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c index 36e9dc1d2c..b56d84fc43 100644 --- a/src/esx/esx_vi.c +++ b/src/esx/esx_vi.c @@ -380,17 +380,15 @@ esxVI_CURL_Download(esxVI_CURL *curl, const char *url= , char **content, range =3D g_strdup_printf("%llu-", offset); } =20 - virMutexLock(&curl->lock); + VIR_WITH_MUTEX_LOCK_GUARD(&curl->lock) { + curl_easy_setopt(curl->handle, CURLOPT_URL, url); + curl_easy_setopt(curl->handle, CURLOPT_RANGE, range); + curl_easy_setopt(curl->handle, CURLOPT_WRITEDATA, &buffer); + curl_easy_setopt(curl->handle, CURLOPT_UPLOAD, 0); + curl_easy_setopt(curl->handle, CURLOPT_HTTPGET, 1); =20 - curl_easy_setopt(curl->handle, CURLOPT_URL, url); - curl_easy_setopt(curl->handle, CURLOPT_RANGE, range); - curl_easy_setopt(curl->handle, CURLOPT_WRITEDATA, &buffer); - curl_easy_setopt(curl->handle, CURLOPT_UPLOAD, 0); - curl_easy_setopt(curl->handle, CURLOPT_HTTPGET, 1); - - responseCode =3D esxVI_CURL_Perform(curl, url); - - virMutexUnlock(&curl->lock); + responseCode =3D esxVI_CURL_Perform(curl, url); + } =20 if (responseCode < 0) { return -1; @@ -422,17 +420,15 @@ esxVI_CURL_Upload(esxVI_CURL *curl, const char *url, = const char *content) return -1; } =20 - virMutexLock(&curl->lock); + VIR_WITH_MUTEX_LOCK_GUARD(&curl->lock) { + curl_easy_setopt(curl->handle, CURLOPT_URL, url); + curl_easy_setopt(curl->handle, CURLOPT_RANGE, NULL); + curl_easy_setopt(curl->handle, CURLOPT_READDATA, &content); + curl_easy_setopt(curl->handle, CURLOPT_UPLOAD, 1); + curl_easy_setopt(curl->handle, CURLOPT_INFILESIZE, strlen(content)= ); =20 - curl_easy_setopt(curl->handle, CURLOPT_URL, url); - curl_easy_setopt(curl->handle, CURLOPT_RANGE, NULL); - curl_easy_setopt(curl->handle, CURLOPT_READDATA, &content); - curl_easy_setopt(curl->handle, CURLOPT_UPLOAD, 1); - curl_easy_setopt(curl->handle, CURLOPT_INFILESIZE, strlen(content)); - - responseCode =3D esxVI_CURL_Perform(curl, url); - - virMutexUnlock(&curl->lock); + responseCode =3D esxVI_CURL_Perform(curl, url); + } =20 if (responseCode < 0) { return -1; @@ -574,14 +570,12 @@ esxVI_SharedCURL_Add(esxVI_SharedCURL *shared, esxVI_= CURL *curl) } } =20 - virMutexLock(&curl->lock); + VIR_WITH_MUTEX_LOCK_GUARD(&curl->lock) { + curl_easy_setopt(curl->handle, CURLOPT_SHARE, shared->handle); =20 - curl_easy_setopt(curl->handle, CURLOPT_SHARE, shared->handle); - - curl->shared =3D shared; - ++shared->count; - - virMutexUnlock(&curl->lock); + curl->shared =3D shared; + ++shared->count; + } =20 return 0; } @@ -606,14 +600,12 @@ esxVI_SharedCURL_Remove(esxVI_SharedCURL *shared, esx= VI_CURL *curl) return -1; } =20 - virMutexLock(&curl->lock); - - curl_easy_setopt(curl->handle, CURLOPT_SHARE, NULL); - - curl->shared =3D NULL; - --shared->count; + VIR_WITH_MUTEX_LOCK_GUARD(&curl->lock) { + curl_easy_setopt(curl->handle, CURLOPT_SHARE, NULL); =20 - virMutexUnlock(&curl->lock); + curl->shared =3D NULL; + --shared->count; + } =20 return 0; } @@ -667,14 +659,12 @@ esxVI_MultiCURL_Add(esxVI_MultiCURL *multi, esxVI_CUR= L *curl) =20 } =20 - virMutexLock(&curl->lock); - - curl_multi_add_handle(multi->handle, curl->handle); - - curl->multi =3D multi; - ++multi->count; + VIR_WITH_MUTEX_LOCK_GUARD(&curl->lock) { + curl_multi_add_handle(multi->handle, curl->handle); =20 - virMutexUnlock(&curl->lock); + curl->multi =3D multi; + ++multi->count; + } =20 return 0; } @@ -701,14 +691,12 @@ esxVI_MultiCURL_Remove(esxVI_MultiCURL *multi, esxVI_= CURL *curl) return -1; } =20 - virMutexLock(&curl->lock); - - curl_multi_remove_handle(multi->handle, curl->handle); - - curl->multi =3D NULL; - --multi->count; + VIR_WITH_MUTEX_LOCK_GUARD(&curl->lock) { + curl_multi_remove_handle(multi->handle, curl->handle); =20 - virMutexUnlock(&curl->lock); + curl->multi =3D NULL; + --multi->count; + } =20 return 0; } @@ -1232,18 +1220,16 @@ esxVI_Context_Execute(esxVI_Context *ctx, const cha= r *methodName, if (esxVI_Response_Alloc(response) < 0) return -1; =20 - virMutexLock(&ctx->curl->lock); - - curl_easy_setopt(ctx->curl->handle, CURLOPT_URL, ctx->url); - curl_easy_setopt(ctx->curl->handle, CURLOPT_RANGE, NULL); - curl_easy_setopt(ctx->curl->handle, CURLOPT_WRITEDATA, &buffer); - curl_easy_setopt(ctx->curl->handle, CURLOPT_UPLOAD, 0); - curl_easy_setopt(ctx->curl->handle, CURLOPT_POSTFIELDS, request); - curl_easy_setopt(ctx->curl->handle, CURLOPT_POSTFIELDSIZE, strlen(requ= est)); - - (*response)->responseCode =3D esxVI_CURL_Perform(ctx->curl, ctx->url); + VIR_WITH_MUTEX_LOCK_GUARD(&ctx->curl->lock) { + curl_easy_setopt(ctx->curl->handle, CURLOPT_URL, ctx->url); + curl_easy_setopt(ctx->curl->handle, CURLOPT_RANGE, NULL); + curl_easy_setopt(ctx->curl->handle, CURLOPT_WRITEDATA, &buffer); + curl_easy_setopt(ctx->curl->handle, CURLOPT_UPLOAD, 0); + curl_easy_setopt(ctx->curl->handle, CURLOPT_POSTFIELDS, request); + curl_easy_setopt(ctx->curl->handle, CURLOPT_POSTFIELDSIZE, strlen(= request)); =20 - virMutexUnlock(&ctx->curl->lock); + (*response)->responseCode =3D esxVI_CURL_Perform(ctx->curl, ctx->u= rl); + } =20 if ((*response)->responseCode < 0) goto cleanup; @@ -1872,13 +1858,14 @@ esxVI_EnsureSession(esxVI_Context *ctx) esxVI_DynamicProperty *dynamicProperty =3D NULL; esxVI_UserSession *currentSession =3D NULL; g_autofree char *escapedPassword =3D NULL; + VIR_LOCK_GUARD lock =3D { NULL }; =20 if (!ctx->sessionLock) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid call, no m= utex")); return -1; } =20 - virMutexLock(ctx->sessionLock); + lock =3D virLockGuardLock(ctx->sessionLock); =20 if (!ctx->session) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid call, no s= ession")); @@ -1933,8 +1920,6 @@ esxVI_EnsureSession(esxVI_Context *ctx) result =3D 0; =20 cleanup: - virMutexUnlock(ctx->sessionLock); - esxVI_String_Free(&propertyNameList); esxVI_ObjectContent_Free(&sessionManager); esxVI_UserSession_Free(¤tSession); --=20 2.31.1