[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 07/24] block: add BDRV_REQ_SERIALISING flag
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 07/24] block: add BDRV_REQ_SERIALISING flag |
Date: |
Tue, 10 Jul 2018 17:42:47 +0200 |
From: Vladimir Sementsov-Ogievskiy <address@hidden>
Serialized writes should be used in copy-on-write of backup(sync=none)
for image fleecing scheme.
We need to change an assert in bdrv_aligned_pwritev, added in
28de2dcd88de. The assert may fail now, because call to
wait_serialising_requests here may become first call to it for this
request with serializing flag set. It occurs if the request is aligned
(otherwise, we should already set serializing flag before calling
bdrv_aligned_pwritev and correspondingly waited for all intersecting
requests). However, for aligned requests, we should not care about
outdating of previously read data, as there no such data. Therefore,
let's just update an assert to not care about aligned requests.
Signed-off-by: Vladimir Sementsov-Ogievskiy <address@hidden>
Reviewed-by: Fam Zheng <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
include/block/block.h | 14 +++++++++++++-
block/io.c | 28 +++++++++++++++++++++++++++-
2 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/include/block/block.h b/include/block/block.h
index e474f2541b..a91f37bedf 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -70,8 +70,20 @@ typedef enum {
* content. */
BDRV_REQ_WRITE_UNCHANGED = 0x40,
+ /*
+ * BDRV_REQ_SERIALISING forces request serialisation for writes.
+ * It is used to ensure that writes to the backing file of a backup process
+ * target cannot race with a read of the backup target that defers to the
+ * backing file.
+ *
+ * Note, that BDRV_REQ_SERIALISING is _not_ opposite in meaning to
+ * BDRV_REQ_NO_SERIALISING. A more descriptive name for the latter might be
+ * _DO_NOT_WAIT_FOR_SERIALISING, except that is too long.
+ */
+ BDRV_REQ_SERIALISING = 0x80,
+
/* Mask of valid flags */
- BDRV_REQ_MASK = 0x7f,
+ BDRV_REQ_MASK = 0xff,
} BdrvRequestFlags;
typedef struct BlockSizes {
diff --git a/block/io.c b/block/io.c
index 75ab26fd58..6be9c40f23 100644
--- a/block/io.c
+++ b/block/io.c
@@ -637,6 +637,18 @@ static void mark_request_serialising(BdrvTrackedRequest
*req, uint64_t align)
req->overlap_bytes = MAX(req->overlap_bytes, overlap_bytes);
}
+static bool is_request_serialising_and_aligned(BdrvTrackedRequest *req)
+{
+ /*
+ * If the request is serialising, overlap_offset and overlap_bytes are set,
+ * so we can check if the request is aligned. Otherwise, don't care and
+ * return false.
+ */
+
+ return req->serialising && (req->offset == req->overlap_offset) &&
+ (req->bytes == req->overlap_bytes);
+}
+
/**
* Round a region to cluster boundaries
*/
@@ -1311,6 +1323,9 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChild
*child,
mark_request_serialising(req, bdrv_get_cluster_size(bs));
}
+ /* BDRV_REQ_SERIALISING is only for write operation */
+ assert(!(flags & BDRV_REQ_SERIALISING));
+
if (!(flags & BDRV_REQ_NO_SERIALISING)) {
wait_serialising_requests(req);
}
@@ -1594,8 +1609,14 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChild
*child,
/* BDRV_REQ_NO_SERIALISING is only for read operation */
assert(!(flags & BDRV_REQ_NO_SERIALISING));
+
+ if (flags & BDRV_REQ_SERIALISING) {
+ mark_request_serialising(req, bdrv_get_cluster_size(bs));
+ }
+
waited = wait_serialising_requests(req);
- assert(!waited || !req->serialising);
+ assert(!waited || !req->serialising ||
+ is_request_serialising_and_aligned(req));
assert(req->overlap_offset <= offset);
assert(offset + bytes <= req->overlap_offset + req->overlap_bytes);
if (flags & BDRV_REQ_WRITE_UNCHANGED) {
@@ -2949,6 +2970,8 @@ static int coroutine_fn bdrv_co_copy_range_internal(
tracked_request_begin(&req, src->bs, src_offset, bytes,
BDRV_TRACKED_READ);
+ /* BDRV_REQ_SERIALISING is only for write operation */
+ assert(!(read_flags & BDRV_REQ_SERIALISING));
if (!(read_flags & BDRV_REQ_NO_SERIALISING)) {
wait_serialising_requests(&req);
}
@@ -2968,6 +2991,9 @@ static int coroutine_fn bdrv_co_copy_range_internal(
/* BDRV_REQ_NO_SERIALISING is only for read operation */
assert(!(write_flags & BDRV_REQ_NO_SERIALISING));
+ if (write_flags & BDRV_REQ_SERIALISING) {
+ mark_request_serialising(&req, bdrv_get_cluster_size(dst->bs));
+ }
wait_serialising_requests(&req);
ret = dst->bs->drv->bdrv_co_copy_range_to(dst->bs,
--
2.13.6
- [Qemu-block] [PULL 00/24] Block layer patches, Kevin Wolf, 2018/07/10
- [Qemu-block] [PULL 03/24] block: Fix copy-on-read crash with partial final cluster, Kevin Wolf, 2018/07/10
- [Qemu-block] [PULL 01/24] block: Poll after drain on attaching a node, Kevin Wolf, 2018/07/10
- [Qemu-block] [PULL 02/24] test-bdrv-drain: Test bdrv_append() to drained node, Kevin Wolf, 2018/07/10
- [Qemu-block] [PULL 04/24] iotests: 222: Don't run with luks, Kevin Wolf, 2018/07/10
- [Qemu-block] [PULL 06/24] block: split flags in copy_range, Kevin Wolf, 2018/07/10
- [Qemu-block] [PULL 05/24] block/io: fix copy_range, Kevin Wolf, 2018/07/10
- [Qemu-block] [PULL 07/24] block: add BDRV_REQ_SERIALISING flag,
Kevin Wolf <=
- [Qemu-block] [PULL 11/24] Revert "block: Remove dead deprecation warning code", Kevin Wolf, 2018/07/10
- [Qemu-block] [PULL 08/24] block/backup: fix fleecing scheme: use serialized writes, Kevin Wolf, 2018/07/10
- [Qemu-block] [PULL 09/24] qapi/block-core.json: Add missing documentation for blklogwrites log-append option, Kevin Wolf, 2018/07/10
- [Qemu-block] [PULL 10/24] block/blklogwrites: Make sure the log sector size is not too small, Kevin Wolf, 2018/07/10
- [Qemu-block] [PULL 13/24] Revert "block: Remove deprecated -drive option addr", Kevin Wolf, 2018/07/10
- [Qemu-block] [PULL 15/24] block: Prefix file driver trace points with "file_", Kevin Wolf, 2018/07/10
- [Qemu-block] [PULL 12/24] Revert "block: Remove deprecated -drive option serial", Kevin Wolf, 2018/07/10
- [Qemu-block] [PULL 14/24] Revert "block: Remove deprecated -drive geometry options", Kevin Wolf, 2018/07/10
- [Qemu-block] [PULL 16/24] block: Add copy offloading trace points, Kevin Wolf, 2018/07/10
- [Qemu-block] [PULL 17/24] block: Use BdrvChild to discard, Kevin Wolf, 2018/07/10