From nobody Mon Feb 9 00:07:19 2026 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 1533821708407865.6134515822314; Thu, 9 Aug 2018 06:35:08 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 1A0FB3082149; Thu, 9 Aug 2018 13:35:06 +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 BD5E6587E5; Thu, 9 Aug 2018 13:35:05 +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 4DF491841C66; Thu, 9 Aug 2018 13:35:05 +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 w79DYoSG012160 for ; Thu, 9 Aug 2018 09:34:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id C666210CD7D2; Thu, 9 Aug 2018 13:34:50 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 63DFD10CD7CC for ; Thu, 9 Aug 2018 13:34:50 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 9 Aug 2018 15:34:39 +0200 Message-Id: <7d81280d3e128ca98b1348c1e457dd8ce84c858f.1533821288.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 1/6] virlockspace: Introduce VIR_LOCK_SPACE_ACQUIRE_METADATA flag 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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Thu, 09 Aug 2018 13:35:06 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This flag is going to be used to alter default behaviour of the lock. Firstly, it means we will lock different offset in the file (offset 1 instead of 0). Secondly, it means the lock acquiring will actually wait for the lock to be set (compared to default behaviour which is set or error out). Signed-off-by: Michal Privoznik --- src/util/virlockspace.c | 40 +++++++++++++++++++++++++++++++++------- src/util/virlockspace.h | 1 + 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/util/virlockspace.c b/src/util/virlockspace.c index 3364c843aa..a7ec0c05bf 100644 --- a/src/util/virlockspace.c +++ b/src/util/virlockspace.c @@ -111,6 +111,8 @@ static void virLockSpaceResourceFree(virLockSpaceResour= cePtr res) VIR_FREE(res); } =20 +#define DEFAULT_OFFSET 0 +#define METADATA_OFFSET 1 =20 static virLockSpaceResourcePtr virLockSpaceResourceNew(virLockSpacePtr lockspace, @@ -120,6 +122,18 @@ virLockSpaceResourceNew(virLockSpacePtr lockspace, { virLockSpaceResourcePtr res; bool shared =3D !!(flags & VIR_LOCK_SPACE_ACQUIRE_SHARED); + bool metadata =3D !!(flags & VIR_LOCK_SPACE_ACQUIRE_METADATA); + off_t start =3D DEFAULT_OFFSET; + bool waitForLock =3D false; + + if (metadata) { + /* We want the metadata lock to act like pthread mutex. + * This means waiting for the lock to be acquired. */ + waitForLock =3D true; + + /* Also, we are locking different offset. */ + start =3D METADATA_OFFSET; + } =20 if (VIR_ALLOC(res) < 0) return NULL; @@ -157,7 +171,7 @@ virLockSpaceResourceNew(virLockSpacePtr lockspace, goto error; } =20 - if (virFileLock(res->fd, shared, 0, 1, false) < 0) { + if (virFileLock(res->fd, shared, start, 1, waitForLock) < 0) { if (errno =3D=3D EACCES || errno =3D=3D EAGAIN) { virReportError(VIR_ERR_RESOURCE_BUSY, _("Lockspace resource '%s' is locked"), @@ -204,7 +218,7 @@ virLockSpaceResourceNew(virLockSpacePtr lockspace, goto error; } =20 - if (virFileLock(res->fd, shared, 0, 1, false) < 0) { + if (virFileLock(res->fd, shared, start, 1, waitForLock) < 0) { if (errno =3D=3D EACCES || errno =3D=3D EAGAIN) { virReportError(VIR_ERR_RESOURCE_BUSY, _("Lockspace resource '%s' is locked"), @@ -621,7 +635,15 @@ int virLockSpaceAcquireResource(virLockSpacePtr locksp= ace, 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_METADATA, -1); + + if (flags & VIR_LOCK_SPACE_ACQUIRE_METADATA && + flags & VIR_LOCK_SPACE_ACQUIRE_SHARED) { + virReportInvalidArg(flags, "%s", + _("metadata and shared are mutually exclusive"= )); + return -1; + } =20 virMutexLock(&lockspace->lock); =20 @@ -635,10 +657,14 @@ int virLockSpaceAcquireResource(virLockSpacePtr locks= pace, =20 goto done; } - virReportError(VIR_ERR_RESOURCE_BUSY, - _("Lockspace resource '%s' is locked"), - resname); - goto cleanup; + + if (!(res->flags & VIR_LOCK_SPACE_ACQUIRE_METADATA) || + !(flags & VIR_LOCK_SPACE_ACQUIRE_METADATA)) { + virReportError(VIR_ERR_RESOURCE_BUSY, + _("Lockspace resource '%s' is locked"), + resname); + goto cleanup; + } } =20 if (!(res =3D virLockSpaceResourceNew(lockspace, resname, flags, owner= ))) diff --git a/src/util/virlockspace.h b/src/util/virlockspace.h index 041cf20396..a9a3b2e73f 100644 --- a/src/util/virlockspace.h +++ b/src/util/virlockspace.h @@ -45,6 +45,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_METADATA =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