From nobody Mon Feb 9 00:30:51 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1559145157; cv=none; d=zoho.com; s=zohoarc; b=QbpeDBWN2vbMqXkavrg0SOPVe6stdrenex6Y2a2ujQ6S334v/qlnE9mI1m6rj1DfJ136ZCWRL2HKWHy3AF9FmsH3tndSJpCbkDm1p//XoKie5dt1tY5vE2NWYODLQHF90wRWXz5HhWdUZUNhuVvR3BVXtY6vrKp8iVUEAK0Spz0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559145157; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=zbvaQdxwc+IK9z1AL+AVyvYsa8LRUv6Kf8sdysAZLts=; b=abJgRBwtZTHW/pE53k9TreL+K39ixLGTagkjEJh0QCWyhFlk1/pK6K/Bp1q9k4SD8rq2YfJpgPJGSNcltAg4xObIA09+ZN7QMm8EQqpK/4jXtt8FQTLhJOJWtvBLNO3UyuyAMNROZIpruXIL7u2QHsyrSR7xB5u76CQNZuGyDFo= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 155914515726698.83055049200755; Wed, 29 May 2019 08:52:37 -0700 (PDT) Received: from localhost ([127.0.0.1]:56939 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hW0sQ-0008Qk-9a for importer@patchew.org; Wed, 29 May 2019 11:52:30 -0400 Received: from eggs.gnu.org ([209.51.188.92]:54883) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hW0n9-0004V7-0V for qemu-devel@nongnu.org; Wed, 29 May 2019 11:47:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hW0n7-00053F-RP for qemu-devel@nongnu.org; Wed, 29 May 2019 11:47:02 -0400 Received: from relay.sw.ru ([185.231.240.75]:43142) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hW0n7-00051x-IO; Wed, 29 May 2019 11:47:01 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hW0n2-0004iP-Pv; Wed, 29 May 2019 18:46:56 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Wed, 29 May 2019 18:46:53 +0300 Message-Id: <20190529154654.95870-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190529154654.95870-1-vsementsov@virtuozzo.com> References: <20190529154654.95870-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v8 6/7] block: add lock/unlock range functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fam@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Introduce lock/unlock range functionality, based on serialized requests. This is needed to refactor backup, dropping local tracked-request-like synchronization. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- include/block/block_int.h | 4 ++++ block/io.c | 44 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index 1eebc7c8f3..9d9d4346e9 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -66,6 +66,7 @@ enum BdrvTrackedRequestType { BDRV_TRACKED_WRITE, BDRV_TRACKED_DISCARD, BDRV_TRACKED_TRUNCATE, + BDRV_TRACKED_LOCK, }; =20 typedef struct BdrvTrackedRequest { @@ -928,6 +929,9 @@ int coroutine_fn bdrv_co_preadv(BdrvChild *child, int coroutine_fn bdrv_co_pwritev(BdrvChild *child, int64_t offset, unsigned int bytes, QEMUIOVector *qiov, BdrvRequestFlags flags); +void *coroutine_fn bdrv_co_try_lock(BlockDriverState *bs, + int64_t offset, unsigned int bytes); +void coroutine_fn bdrv_co_unlock(void *opaque); =20 static inline int coroutine_fn bdrv_co_pread(BdrvChild *child, int64_t offset, unsigned int bytes, void *buf, BdrvRequestFlags flags) diff --git a/block/io.c b/block/io.c index c347f90722..488e01e0a1 100644 --- a/block/io.c +++ b/block/io.c @@ -720,6 +720,15 @@ void bdrv_dec_in_flight(BlockDriverState *bs) bdrv_wakeup(bs); } =20 +static bool ignore_intersection(BdrvTrackedRequest *a, BdrvTrackedRequest = *b) +{ + return a =3D=3D b || (!a->serialising && !b->serialising) || + (a->type =3D=3D BDRV_TRACKED_LOCK && b->type =3D=3D BDRV_TRACKED_R= EAD && + !b->serialising) || + (b->type =3D=3D BDRV_TRACKED_LOCK && a->type =3D=3D BDRV_TRACKED_R= EAD && + !a->serialising); +} + static bool coroutine_fn do_wait_serialising_requests(BdrvTrackedRequest *= self, bool wait) { @@ -736,7 +745,7 @@ static bool coroutine_fn do_wait_serialising_requests(B= drvTrackedRequest *self, retry =3D false; qemu_co_mutex_lock(&bs->reqs_lock); QLIST_FOREACH(req, &bs->tracked_requests, list) { - if (req =3D=3D self || (!req->serialising && !self->serialisin= g)) { + if (ignore_intersection(self, req)) { continue; } if (tracked_request_overlaps(req, self->overlap_offset, @@ -774,6 +783,12 @@ static bool coroutine_fn wait_serialising_requests(Bdr= vTrackedRequest *self) return do_wait_serialising_requests(self, true); } =20 +static bool coroutine_fn should_wait_serialising_requests( + BdrvTrackedRequest *self) +{ + return do_wait_serialising_requests(self, false); +} + static int bdrv_check_byte_request(BlockDriverState *bs, int64_t offset, size_t size) { @@ -3184,3 +3199,30 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, = PreallocMode prealloc, =20 return tco.ret; } + +void *coroutine_fn bdrv_co_try_lock(BlockDriverState *bs, + int64_t offset, unsigned int bytes) +{ + BdrvTrackedRequest *req =3D g_new(BdrvTrackedRequest, 1); + + tracked_request_begin(req, bs, offset, bytes, BDRV_TRACKED_LOCK); + mark_request_serialising(req, bdrv_get_cluster_size(bs)); + + if (should_wait_serialising_requests(req)) { + tracked_request_end(req); + g_free(req); + return NULL; + } + + return req; +} + +void coroutine_fn bdrv_co_unlock(void *opaque) +{ + BdrvTrackedRequest *req =3D opaque; + + assert(req->type =3D=3D BDRV_TRACKED_LOCK); + + tracked_request_end(req); + g_free(req); +} --=20 2.18.0