Blame SOURCES/kvm-mirror-Make-sure-that-source-and-target-size-match.patch

ddf19c
From 98bf67db979927a5c7bbdc4a17c35d60b5f38e71 Mon Sep 17 00:00:00 2001
ddf19c
From: Kevin Wolf <kwolf@redhat.com>
ddf19c
Date: Wed, 3 Jun 2020 16:03:24 +0100
ddf19c
Subject: [PATCH 25/26] mirror: Make sure that source and target size match
ddf19c
ddf19c
RH-Author: Kevin Wolf <kwolf@redhat.com>
ddf19c
Message-id: <20200603160325.67506-11-kwolf@redhat.com>
ddf19c
Patchwork-id: 97110
ddf19c
O-Subject: [RHEL-AV-8.2.1 qemu-kvm PATCH v2 10/11] mirror: Make sure that source and target size match
ddf19c
Bugzilla: 1778593
ddf19c
RH-Acked-by: Eric Blake <eblake@redhat.com>
ddf19c
RH-Acked-by: Max Reitz <mreitz@redhat.com>
ddf19c
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
ddf19c
ddf19c
If the target is shorter than the source, mirror would copy data until
ddf19c
it reaches the end of the target and then fail with an I/O error when
ddf19c
trying to write past the end.
ddf19c
ddf19c
If the target is longer than the source, the mirror job would complete
ddf19c
successfully, but the target wouldn't actually be an accurate copy of
ddf19c
the source image (it would contain some additional garbage at the end).
ddf19c
ddf19c
Fix this by checking that both images have the same size when the job
ddf19c
starts.
ddf19c
ddf19c
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ddf19c
Reviewed-by: Eric Blake <eblake@redhat.com>
ddf19c
Message-Id: <20200511135825.219437-4-kwolf@redhat.com>
ddf19c
Reviewed-by: Max Reitz <mreitz@redhat.com>
ddf19c
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
ddf19c
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ddf19c
(cherry picked from commit e83dd6808c6e0975970f37b49b27cc37bb54eea8)
ddf19c
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ddf19c
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ddf19c
---
ddf19c
 block/mirror.c | 21 ++++++++++++---------
ddf19c
 1 file changed, 12 insertions(+), 9 deletions(-)
ddf19c
ddf19c
diff --git a/block/mirror.c b/block/mirror.c
ddf19c
index 5e5a521..0d32fca 100644
ddf19c
--- a/block/mirror.c
ddf19c
+++ b/block/mirror.c
ddf19c
@@ -859,6 +859,7 @@ static int coroutine_fn mirror_run(Job *job, Error **errp)
ddf19c
     BlockDriverState *target_bs = blk_bs(s->target);
ddf19c
     bool need_drain = true;
ddf19c
     int64_t length;
ddf19c
+    int64_t target_length;
ddf19c
     BlockDriverInfo bdi;
ddf19c
     char backing_filename[2]; /* we only need 2 characters because we are only
ddf19c
                                  checking for a NULL string */
ddf19c
@@ -874,24 +875,26 @@ static int coroutine_fn mirror_run(Job *job, Error **errp)
ddf19c
         goto immediate_exit;
ddf19c
     }
ddf19c
 
ddf19c
+    target_length = blk_getlength(s->target);
ddf19c
+    if (target_length < 0) {
ddf19c
+        ret = target_length;
ddf19c
+        goto immediate_exit;
ddf19c
+    }
ddf19c
+
ddf19c
     /* Active commit must resize the base image if its size differs from the
ddf19c
      * active layer. */
ddf19c
     if (s->base == blk_bs(s->target)) {
ddf19c
-        int64_t base_length;
ddf19c
-
ddf19c
-        base_length = blk_getlength(s->target);
ddf19c
-        if (base_length < 0) {
ddf19c
-            ret = base_length;
ddf19c
-            goto immediate_exit;
ddf19c
-        }
ddf19c
-
ddf19c
-        if (s->bdev_length > base_length) {
ddf19c
+        if (s->bdev_length > target_length) {
ddf19c
             ret = blk_truncate(s->target, s->bdev_length, false,
ddf19c
                                PREALLOC_MODE_OFF, NULL);
ddf19c
             if (ret < 0) {
ddf19c
                 goto immediate_exit;
ddf19c
             }
ddf19c
         }
ddf19c
+    } else if (s->bdev_length != target_length) {
ddf19c
+        error_setg(errp, "Source and target image have different sizes");
ddf19c
+        ret = -EINVAL;
ddf19c
+        goto immediate_exit;
ddf19c
     }
ddf19c
 
ddf19c
     if (s->bdev_length == 0) {
ddf19c
-- 
ddf19c
1.8.3.1
ddf19c