From nobody Thu Nov 28 01:29:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1534245606459520.5804805658152; Tue, 14 Aug 2018 04:20:06 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 37AF430E685C; Tue, 14 Aug 2018 11:20:04 +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 E75F41073020; Tue, 14 Aug 2018 11:20:03 +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 8145A18037F4; Tue, 14 Aug 2018 11:20:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w7EBJlQw012402 for ; Tue, 14 Aug 2018 07:19:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 25B5E2027047; Tue, 14 Aug 2018 11:19:47 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id B8C782026D7E for ; Tue, 14 Aug 2018 11:19:46 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 14 Aug 2018 13:19:38 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 2/7] virlockspace: Introduce VIR_LOCK_SPACE_ACQUIRE_WAIT 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Tue, 14 Aug 2018 11:20:04 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This flag modifies the way the lock is acquired. It waits for the lock to be set instead of usual set-or-fail logic that happens without this flag. Signed-off-by: Michal Privoznik Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: John Ferlan --- src/util/virlockspace.c | 14 ++++++++++---- src/util/virlockspace.h | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/util/virlockspace.c b/src/util/virlockspace.c index 60bfef4c5f..d75a6d4a6e 100644 --- a/src/util/virlockspace.c +++ b/src/util/virlockspace.c @@ -122,6 +122,7 @@ virLockSpaceResourceNew(virLockSpacePtr lockspace, { virLockSpaceResourcePtr res; bool shared =3D !!(flags & VIR_LOCK_SPACE_ACQUIRE_SHARED); + bool waitForLock =3D !!(flags & VIR_LOCK_SPACE_ACQUIRE_WAIT); =20 if (VIR_ALLOC(res) < 0) return NULL; @@ -159,7 +160,7 @@ virLockSpaceResourceNew(virLockSpacePtr lockspace, goto error; } =20 - if (virFileLock(res->fd, shared, start, len, false) < 0) { + if (virFileLock(res->fd, shared, start, len, waitForLock) < 0)= { if (errno =3D=3D EACCES || errno =3D=3D EAGAIN) { virReportError(VIR_ERR_RESOURCE_BUSY, _("Lockspace resource '%s' is locked"), @@ -206,7 +207,7 @@ virLockSpaceResourceNew(virLockSpacePtr lockspace, goto error; } =20 - if (virFileLock(res->fd, shared, start, len, false) < 0) { + if (virFileLock(res->fd, shared, start, len, waitForLock) < 0) { if (errno =3D=3D EACCES || errno =3D=3D EAGAIN) { virReportError(VIR_ERR_RESOURCE_BUSY, _("Lockspace resource '%s' is locked"), @@ -625,11 +626,16 @@ int virLockSpaceAcquireResource(virLockSpacePtr locks= pace, lockspace, resname, flags, (unsigned long long)owner); =20 virCheckFlags(VIR_LOCK_SPACE_ACQUIRE_SHARED | - VIR_LOCK_SPACE_ACQUIRE_AUTOCREATE, -1); + VIR_LOCK_SPACE_ACQUIRE_AUTOCREATE | + VIR_LOCK_SPACE_ACQUIRE_WAIT, -1); + + VIR_EXCLUSIVE_FLAGS_RET(VIR_LOCK_SPACE_ACQUIRE_WAIT, + VIR_LOCK_SPACE_ACQUIRE_SHARED, -1); =20 virMutexLock(&lockspace->lock); =20 - if ((res =3D virHashLookup(lockspace->resources, resname))) { + if (!(flags & VIR_LOCK_SPACE_ACQUIRE_WAIT) && + (res =3D virHashLookup(lockspace->resources, resname))) { if ((res->flags & VIR_LOCK_SPACE_ACQUIRE_SHARED) && (flags & VIR_LOCK_SPACE_ACQUIRE_SHARED)) { =20 diff --git a/src/util/virlockspace.h b/src/util/virlockspace.h index 24f2c89be6..bfaed34d5b 100644 --- a/src/util/virlockspace.h +++ b/src/util/virlockspace.h @@ -47,6 +47,7 @@ int virLockSpaceDeleteResource(virLockSpacePtr lockspace, typedef enum { VIR_LOCK_SPACE_ACQUIRE_SHARED =3D (1 << 0), VIR_LOCK_SPACE_ACQUIRE_AUTOCREATE =3D (1 << 1), + VIR_LOCK_SPACE_ACQUIRE_WAIT =3D (1 << 2), } virLockSpaceAcquireFlags; =20 int virLockSpaceAcquireResource(virLockSpacePtr lockspace, --=20 2.16.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list