cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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