cryptospore / 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

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