Blame SOURCES/kvm-block-quorum-Support-BDRV_REQ_WRITE_UNCHANGED.patch

ae23c9
From a3f3c2cb19e33574f3566843cba7e3ad253dc9af Mon Sep 17 00:00:00 2001
ae23c9
From: Max Reitz <mreitz@redhat.com>
ae23c9
Date: Mon, 18 Jun 2018 16:12:08 +0200
ae23c9
Subject: [PATCH 041/268] block/quorum: Support BDRV_REQ_WRITE_UNCHANGED
ae23c9
ae23c9
RH-Author: Max Reitz <mreitz@redhat.com>
ae23c9
Message-id: <20180618161212.14444-7-mreitz@redhat.com>
ae23c9
Patchwork-id: 80770
ae23c9
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 06/10] block/quorum: Support BDRV_REQ_WRITE_UNCHANGED
ae23c9
Bugzilla: 1518738
ae23c9
RH-Acked-by: John Snow <jsnow@redhat.com>
ae23c9
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
ae23c9
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
ae23c9
ae23c9
We just need to forward it to quorum's children (except in case of a
ae23c9
rewrite because of corruption), but for that we first have to support
ae23c9
flags in child requests at all.
ae23c9
ae23c9
Signed-off-by: Max Reitz <mreitz@redhat.com>
ae23c9
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
ae23c9
Reviewed-by: Alberto Garcia <berto@igalia.com>
ae23c9
Message-id: 20180421132929.21610-6-mreitz@redhat.com
ae23c9
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
ae23c9
Signed-off-by: Max Reitz <mreitz@redhat.com>
ae23c9
(cherry picked from commit 1b1a920b713af6af795d49d0e3d2a8a65020bf82)
ae23c9
Signed-off-by: Max Reitz <mreitz@redhat.com>
ae23c9
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
ae23c9
---
ae23c9
 block/quorum.c | 19 +++++++++++++------
ae23c9
 1 file changed, 13 insertions(+), 6 deletions(-)
ae23c9
ae23c9
diff --git a/block/quorum.c b/block/quorum.c
ae23c9
index f1f39ba..0d90a02 100644
ae23c9
--- a/block/quorum.c
ae23c9
+++ b/block/quorum.c
ae23c9
@@ -116,6 +116,7 @@ struct QuorumAIOCB {
ae23c9
     /* Request metadata */
ae23c9
     uint64_t offset;
ae23c9
     uint64_t bytes;
ae23c9
+    int flags;
ae23c9
 
ae23c9
     QEMUIOVector *qiov;         /* calling IOV */
ae23c9
 
ae23c9
@@ -158,7 +159,8 @@ static bool quorum_64bits_compare(QuorumVoteValue *a, QuorumVoteValue *b)
ae23c9
 static QuorumAIOCB *quorum_aio_get(BlockDriverState *bs,
ae23c9
                                    QEMUIOVector *qiov,
ae23c9
                                    uint64_t offset,
ae23c9
-                                   uint64_t bytes)
ae23c9
+                                   uint64_t bytes,
ae23c9
+                                   int flags)
ae23c9
 {
ae23c9
     BDRVQuorumState *s = bs->opaque;
ae23c9
     QuorumAIOCB *acb = g_new(QuorumAIOCB, 1);
ae23c9
@@ -169,6 +171,7 @@ static QuorumAIOCB *quorum_aio_get(BlockDriverState *bs,
ae23c9
         .bs                 = bs,
ae23c9
         .offset             = offset,
ae23c9
         .bytes              = bytes,
ae23c9
+        .flags              = flags,
ae23c9
         .qiov               = qiov,
ae23c9
         .votes.compare      = quorum_sha256_compare,
ae23c9
         .votes.vote_list    = QLIST_HEAD_INITIALIZER(acb.votes.vote_list),
ae23c9
@@ -272,9 +275,11 @@ static void quorum_rewrite_entry(void *opaque)
ae23c9
     BDRVQuorumState *s = acb->bs->opaque;
ae23c9
 
ae23c9
     /* Ignore any errors, it's just a correction attempt for already
ae23c9
-     * corrupted data. */
ae23c9
+     * corrupted data.
ae23c9
+     * Mask out BDRV_REQ_WRITE_UNCHANGED because this overwrites the
ae23c9
+     * area with different data from the other children. */
ae23c9
     bdrv_co_pwritev(s->children[co->idx], acb->offset, acb->bytes,
ae23c9
-                    acb->qiov, 0);
ae23c9
+                    acb->qiov, acb->flags & ~BDRV_REQ_WRITE_UNCHANGED);
ae23c9
 
ae23c9
     /* Wake up the caller after the last rewrite */
ae23c9
     acb->rewrite_count--;
ae23c9
@@ -674,7 +679,7 @@ static int quorum_co_preadv(BlockDriverState *bs, uint64_t offset,
ae23c9
                             uint64_t bytes, QEMUIOVector *qiov, int flags)
ae23c9
 {
ae23c9
     BDRVQuorumState *s = bs->opaque;
ae23c9
-    QuorumAIOCB *acb = quorum_aio_get(bs, qiov, offset, bytes);
ae23c9
+    QuorumAIOCB *acb = quorum_aio_get(bs, qiov, offset, bytes, flags);
ae23c9
     int ret;
ae23c9
 
ae23c9
     acb->is_read = true;
ae23c9
@@ -700,7 +705,7 @@ static void write_quorum_entry(void *opaque)
ae23c9
 
ae23c9
     sacb->bs = s->children[i]->bs;
ae23c9
     sacb->ret = bdrv_co_pwritev(s->children[i], acb->offset, acb->bytes,
ae23c9
-                                acb->qiov, 0);
ae23c9
+                                acb->qiov, acb->flags);
ae23c9
     if (sacb->ret == 0) {
ae23c9
         acb->success_count++;
ae23c9
     } else {
ae23c9
@@ -720,7 +725,7 @@ static int quorum_co_pwritev(BlockDriverState *bs, uint64_t offset,
ae23c9
                              uint64_t bytes, QEMUIOVector *qiov, int flags)
ae23c9
 {
ae23c9
     BDRVQuorumState *s = bs->opaque;
ae23c9
-    QuorumAIOCB *acb = quorum_aio_get(bs, qiov, offset, bytes);
ae23c9
+    QuorumAIOCB *acb = quorum_aio_get(bs, qiov, offset, bytes, flags);
ae23c9
     int i, ret;
ae23c9
 
ae23c9
     for (i = 0; i < s->num_children; i++) {
ae23c9
@@ -962,6 +967,8 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags,
ae23c9
     }
ae23c9
     s->next_child_index = s->num_children;
ae23c9
 
ae23c9
+    bs->supported_write_flags = BDRV_REQ_WRITE_UNCHANGED;
ae23c9
+
ae23c9
     g_free(opened);
ae23c9
     goto exit;
ae23c9
 
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9