Blame SOURCES/kvm-block-resize-backing-image-during-active-layer-commi.patch

0a122b
From 31c90390db10329e2e7da072492fa7ec728abed0 Mon Sep 17 00:00:00 2001
0a122b
From: Jeffrey Cody <jcody@redhat.com>
0a122b
Date: Tue, 11 Feb 2014 16:14:26 +0100
0a122b
Subject: [PATCH 20/28] block: resize backing image during active layer commit, if needed
0a122b
0a122b
RH-Author: Jeffrey Cody <jcody@redhat.com>
0a122b
Message-id: <b725bb85bfb2d59275a3a8b1a6c3c2c6341567c3.1392134912.git.jcody@redhat.com>
0a122b
Patchwork-id: 57216
0a122b
O-Subject: [RHEL7 qemu-kvm PATCH 2/6] block: resize backing image during active layer commit, if needed
0a122b
Bugzilla: 1047254
0a122b
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
0a122b
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
0a122b
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
0a122b
0a122b
If the top image to commit is the active layer, and also larger than
0a122b
the base image, then an I/O error will likely be returned during
0a122b
block-commit.
0a122b
0a122b
For instance, if we have a base image with a virtual size 10G, and a
0a122b
active layer image of size 20G, then committing the snapshot via
0a122b
'block-commit' will likely fail.
0a122b
0a122b
This will automatically attempt to resize the base image, if the
0a122b
active layer image to be committed is larger.
0a122b
0a122b
Signed-off-by: Jeff Cody <jcody@redhat.com>
0a122b
Reviewed-by: Eric Blake <eblake@redhat.com>
0a122b
Reviewed-by: Benoit Canet <benoit@irqsave.net>
0a122b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
0a122b
(cherry picked from commit 4da83585961631bfc10831dd26c4afda2a8b23e8)
0a122b
---
0a122b
 block/mirror.c | 38 ++++++++++++++++++++++++++++++++++++++
0a122b
 1 file changed, 38 insertions(+)
0a122b
0a122b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
0a122b
---
0a122b
 block/mirror.c |   38 ++++++++++++++++++++++++++++++++++++++
0a122b
 1 files changed, 38 insertions(+), 0 deletions(-)
0a122b
0a122b
diff --git a/block/mirror.c b/block/mirror.c
0a122b
index 6e1f9b1..ba1428b 100644
0a122b
--- a/block/mirror.c
0a122b
+++ b/block/mirror.c
0a122b
@@ -627,11 +627,49 @@ void commit_active_start(BlockDriverState *bs, BlockDriverState *base,
0a122b
                          BlockDriverCompletionFunc *cb,
0a122b
                          void *opaque, Error **errp)
0a122b
 {
0a122b
+    int64_t length, base_length;
0a122b
+    int orig_base_flags;
0a122b
+
0a122b
+    orig_base_flags = bdrv_get_flags(base);
0a122b
+
0a122b
     if (bdrv_reopen(base, bs->open_flags, errp)) {
0a122b
         return;
0a122b
     }
0a122b
+
0a122b
+    length = bdrv_getlength(bs);
0a122b
+    if (length < 0) {
0a122b
+        error_setg(errp, "Unable to determine length of %s", bs->filename);
0a122b
+        goto error_restore_flags;
0a122b
+    }
0a122b
+
0a122b
+    base_length = bdrv_getlength(base);
0a122b
+    if (base_length < 0) {
0a122b
+        error_setg(errp, "Unable to determine length of %s", base->filename);
0a122b
+        goto error_restore_flags;
0a122b
+    }
0a122b
+
0a122b
+    if (length > base_length) {
0a122b
+        if (bdrv_truncate(base, length) < 0) {
0a122b
+            error_setg(errp, "Top image %s is larger than base image %s, and "
0a122b
+                             "resize of base image failed",
0a122b
+                             bs->filename, base->filename);
0a122b
+            goto error_restore_flags;
0a122b
+        }
0a122b
+    }
0a122b
+
0a122b
     bdrv_ref(base);
0a122b
     mirror_start_job(bs, base, speed, 0, 0,
0a122b
                      on_error, on_error, cb, opaque, errp,
0a122b
                      &commit_active_job_driver, false, base);
0a122b
+    if (error_is_set(errp)) {
0a122b
+        goto error_restore_flags;
0a122b
+    }
0a122b
+
0a122b
+    return;
0a122b
+
0a122b
+error_restore_flags:
0a122b
+    /* ignore error and errp for bdrv_reopen, because we want to propagate
0a122b
+     * the original error */
0a122b
+    bdrv_reopen(base, orig_base_flags, NULL);
0a122b
+    return;
0a122b
 }
0a122b
-- 
0a122b
1.7.1
0a122b