yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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