qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: qemu-block@nongnu.org
Cc: fam@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com,
	wencongyang2@huawei.com, xiechanglong.d@gmail.com,
	qemu-devel@nongnu.org, armbru@redhat.com, jsnow@redhat.com,
	stefanha@redhat.com, den@openvz.org, mreitz@redhat.com
Subject: [PATCH v13 13/15] block: add lock/unlock range functions
Date: Fri, 20 Sep 2019 17:20:54 +0300	[thread overview]
Message-ID: <20190920142056.12778-14-vsementsov@virtuozzo.com> (raw)
In-Reply-To: <20190920142056.12778-1-vsementsov@virtuozzo.com>

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 <vsementsov@virtuozzo.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
---
 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 0422acdf1c..b59011ca97 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -65,6 +65,7 @@ enum BdrvTrackedRequestType {
     BDRV_TRACKED_WRITE,
     BDRV_TRACKED_DISCARD,
     BDRV_TRACKED_TRUNCATE,
+    BDRV_TRACKED_LOCK,
 };
 
 typedef struct BdrvTrackedRequest {
@@ -968,6 +969,9 @@ int coroutine_fn bdrv_co_pwritev(BdrvChild *child,
 int coroutine_fn bdrv_co_pwritev_part(BdrvChild *child,
     int64_t offset, unsigned int bytes,
     QEMUIOVector *qiov, size_t qiov_offset, 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);
 
 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 f5f7b7357c..a749583453 100644
--- a/block/io.c
+++ b/block/io.c
@@ -786,6 +786,15 @@ void bdrv_dec_in_flight(BlockDriverState *bs)
     bdrv_wakeup(bs);
 }
 
+static bool ignore_intersection(BdrvTrackedRequest *a, BdrvTrackedRequest *b)
+{
+    return a == b || (!a->serialising && !b->serialising) ||
+        (a->type == BDRV_TRACKED_LOCK && b->type == BDRV_TRACKED_READ &&
+         !b->serialising) ||
+        (b->type == BDRV_TRACKED_LOCK && a->type == BDRV_TRACKED_READ &&
+         !a->serialising);
+}
+
 static bool coroutine_fn do_wait_serialising_requests(BdrvTrackedRequest *self,
                                                       bool wait)
 {
@@ -802,7 +811,7 @@ static bool coroutine_fn do_wait_serialising_requests(BdrvTrackedRequest *self,
         retry = false;
         qemu_co_mutex_lock(&bs->reqs_lock);
         QLIST_FOREACH(req, &bs->tracked_requests, list) {
-            if (req == self || (!req->serialising && !self->serialising)) {
+            if (ignore_intersection(self, req)) {
                 continue;
             }
             if (tracked_request_overlaps(req, self->overlap_offset,
@@ -840,6 +849,12 @@ static bool coroutine_fn wait_serialising_requests(BdrvTrackedRequest *self)
     return do_wait_serialising_requests(self, true);
 }
 
+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)
 {
@@ -3378,3 +3393,30 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, PreallocMode prealloc,
 
     return tco.ret;
 }
+
+void *coroutine_fn bdrv_co_try_lock(BlockDriverState *bs,
+                                    int64_t offset, unsigned int bytes)
+{
+    BdrvTrackedRequest *req = 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 = opaque;
+
+    assert(req->type == BDRV_TRACKED_LOCK);
+
+    tracked_request_end(req);
+    g_free(req);
+}
-- 
2.21.0



  parent reply	other threads:[~2019-09-20 14:27 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-20 14:20 [PATCH v13 00/15] backup-top filter driver for backup Vladimir Sementsov-Ogievskiy
2019-09-20 14:20 ` [PATCH v13 01/15] block/backup: fix max_transfer handling for copy_range Vladimir Sementsov-Ogievskiy
2019-09-20 14:20 ` [PATCH v13 02/15] block/backup: fix backup_cow_with_offload for last cluster Vladimir Sementsov-Ogievskiy
2019-09-20 14:20 ` [PATCH v13 03/15] block/backup: split shareable copying part from backup_do_cow Vladimir Sementsov-Ogievskiy
2019-09-20 14:20 ` [PATCH v13 04/15] block/backup: improve comment about image fleecing Vladimir Sementsov-Ogievskiy
2019-09-20 14:20 ` [PATCH v13 05/15] block/backup: introduce BlockCopyState Vladimir Sementsov-Ogievskiy
2019-09-20 14:20 ` [PATCH v13 06/15] block/backup: fix block-comment style Vladimir Sementsov-Ogievskiy
2019-09-20 14:20 ` [PATCH v13 07/15] block: move block_copy from block/backup.c to separate file Vladimir Sementsov-Ogievskiy
2019-09-20 14:20 ` [PATCH v13 08/15] block: teach bdrv_debug_breakpoint skip filters with backing Vladimir Sementsov-Ogievskiy
2019-09-20 14:20 ` [PATCH v13 09/15] iotests: prepare 124 and 257 bitmap querying for backup-top filter Vladimir Sementsov-Ogievskiy
2019-09-20 14:20 ` [PATCH v13 10/15] iotests: 257: drop unused Drive.device field Vladimir Sementsov-Ogievskiy
2019-09-20 14:20 ` [PATCH v13 11/15] iotests: 257: drop device_add Vladimir Sementsov-Ogievskiy
2019-09-20 14:20 ` [PATCH v13 12/15] block/io: refactor wait_serialising_requests Vladimir Sementsov-Ogievskiy
2019-09-20 14:20 ` Vladimir Sementsov-Ogievskiy [this message]
2019-09-20 14:20 ` [PATCH v13 14/15] block: introduce backup-top filter driver Vladimir Sementsov-Ogievskiy
2019-09-20 14:20 ` [PATCH v13 15/15] block/backup: use backup-top instead of write notifiers Vladimir Sementsov-Ogievskiy
2019-09-20 15:55 ` [PATCH v13 00/15] backup-top filter driver for backup Max Reitz
2019-09-20 16:01   ` Vladimir Sementsov-Ogievskiy
2019-09-20 16:13     ` John Snow
2019-09-25 16:58 ` [PATCH 16/15 v13] block/block-copy: fix block_copy Vladimir Sementsov-Ogievskiy
2019-09-25 19:19 ` [PATCH v13 00/15] backup-top filter driver for backup Vladimir Sementsov-Ogievskiy
2019-09-25 19:28   ` Vladimir Sementsov-Ogievskiy
2019-09-26 11:26     ` Max Reitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190920142056.12778-14-vsementsov@virtuozzo.com \
    --to=vsementsov@virtuozzo.com \
    --cc=armbru@redhat.com \
    --cc=den@openvz.org \
    --cc=fam@euphon.net \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=wencongyang2@huawei.com \
    --cc=xiechanglong.d@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).