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