From nobody Mon Feb 9 11:47:16 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=1645103103; cv=none; d=zohomail.com; s=zohoarc; b=cnJg1Ro4XGyZdIsLPTzWDkRb3J5Ulr586bmXxboS/aLkwPKCO/+21fIzCJX4iEOvEsgUIEgQjh8tdO/t5aN9N7fCJ3z2GPbhSTBMoA/EJQUSkyI7Qr0uNpq9yhKf3u96ElkG4nt077KCTKdyugkiJfZRUyiMQ1M1f9C9w2RjkiM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645103103; 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=Wk3Uxs8OaHDHv/Er0xKrbQeJWW10ZholxzciPDviYSyXjqD1xnoyODHeOfSV7uqJ4s1Sq/ITGtB8w76THigPdUXE/uQPXwDnjVgnVHl3Ww0EDsr7gdcYAM7xNhI6RT4NndxAcwNJrq7wXu440W3uy7IOmK88Jw0CEt6xY/cptbE= 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 1645103103068436.4803900411217; Thu, 17 Feb 2022 05:05:03 -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-65-UPWoHDBJNn-Oz-KTr-vGAw-1; Thu, 17 Feb 2022 08:04:02 -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 C4DA61006AA3; Thu, 17 Feb 2022 13:03:56 +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 6B7CF6FB87; Thu, 17 Feb 2022 13:03:56 +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 3E6221832A39; Thu, 17 Feb 2022 13:03:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21HD1Ec2031242 for ; Thu, 17 Feb 2022 08:01:14 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3B9032B3DD; Thu, 17 Feb 2022 13:01:14 +0000 (UTC) Received: from work.speedport.ip (unknown [10.39.194.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7C4FE2B3A7; Thu, 17 Feb 2022 13:01:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1645103102; 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=gBFxyULtFW5Jxgkog1WpFsjDijdM5uEuM7yqUUfB9Kv+NdT+Ue+QepRVZeUHy+A3t0oraR ytAYmxSquvQxHEERKO7e6nwoPCnqQ5QFDZeEQfDhbEYMrpFFf1kCAsa3l/w8qWwR1LLewm p0Tpx85XSL+W8l0kD93iPB0k2FlY23w= X-MC-Unique: UPWoHDBJNn-Oz-KTr-vGAw-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 08/11] esx_vi: Use automatic mutex management Date: Thu, 17 Feb 2022 14:01:00 +0100 Message-Id: <20220217130103.18543-9-twiederh@redhat.com> In-Reply-To: <20220217130103.18543-1-twiederh@redhat.com> References: <20220217130103.18543-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: 1645103107477100001 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