Blame SOURCES/kvm-block-package-preparation-code-in-qmp_transaction.patch

218e99
From 9845ad55c470e47c0074d92611bf9fb2903ab58a Mon Sep 17 00:00:00 2001
218e99
From: Kevin Wolf <kwolf@redhat.com>
218e99
Date: Mon, 9 Sep 2013 14:27:52 +0200
218e99
Subject: [PATCH 01/38] block: package preparation code in qmp_transaction()
218e99
218e99
RH-Author: Kevin Wolf <kwolf@redhat.com>
218e99
Message-id: <1378736903-18489-2-git-send-email-kwolf@redhat.com>
218e99
Patchwork-id: 54188
218e99
O-Subject: [RHEL-7.0 qemu-kvm PATCH 01/32] block: package preparation code in qmp_transaction()
218e99
Bugzilla: 1005818
218e99
RH-Acked-by: Fam Zheng <famz@redhat.com>
218e99
RH-Acked-by: Max Reitz <mreitz@redhat.com>
218e99
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
218e99
From: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
218e99
218e99
Bugzilla: 1005818
218e99
218e99
The code before really committing is moved into a function. Most
218e99
code is simply moved from qmp_transaction(), except that on fail it
218e99
just returns now. Other code such as input parsing is not touched,
218e99
to make it easier in review.
218e99
218e99
Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
218e99
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
218e99
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
218e99
Reviewed-by: Eric Blake <eblake@redhat.com>
218e99
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
218e99
(cherry picked from commit 9b9877ee9f1c27588a286f591852c0b7c0548b6a)
218e99
218e99
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
218e99
---
218e99
 blockdev.c | 139 ++++++++++++++++++++++++++++++++++---------------------------
218e99
 1 file changed, 77 insertions(+), 62 deletions(-)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 blockdev.c |  139 +++++++++++++++++++++++++++++++++---------------------------
218e99
 1 files changed, 77 insertions(+), 62 deletions(-)
218e99
218e99
diff --git a/blockdev.c b/blockdev.c
218e99
index 6500c47..1bff654 100644
218e99
--- a/blockdev.c
218e99
+++ b/blockdev.c
218e99
@@ -785,6 +785,78 @@ typedef struct BlkTransactionStates {
218e99
     QSIMPLEQ_ENTRY(BlkTransactionStates) entry;
218e99
 } BlkTransactionStates;
218e99
 
218e99
+static void external_snapshot_prepare(const char *device,
218e99
+                                      const char *format,
218e99
+                                      const char *new_image_file,
218e99
+                                      enum NewImageMode mode,
218e99
+                                      BlkTransactionStates *states,
218e99
+                                      Error **errp)
218e99
+{
218e99
+    BlockDriver *proto_drv;
218e99
+    BlockDriver *drv;
218e99
+    int flags, ret;
218e99
+    Error *local_err = NULL;
218e99
+
218e99
+    drv = bdrv_find_format(format);
218e99
+    if (!drv) {
218e99
+        error_set(errp, QERR_INVALID_BLOCK_FORMAT, format);
218e99
+        return;
218e99
+    }
218e99
+
218e99
+    states->old_bs = bdrv_find(device);
218e99
+    if (!states->old_bs) {
218e99
+        error_set(errp, QERR_DEVICE_NOT_FOUND, device);
218e99
+        return;
218e99
+    }
218e99
+
218e99
+    if (!bdrv_is_inserted(states->old_bs)) {
218e99
+        error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);
218e99
+        return;
218e99
+    }
218e99
+
218e99
+    if (bdrv_in_use(states->old_bs)) {
218e99
+        error_set(errp, QERR_DEVICE_IN_USE, device);
218e99
+        return;
218e99
+    }
218e99
+
218e99
+    if (!bdrv_is_read_only(states->old_bs)) {
218e99
+        if (bdrv_flush(states->old_bs)) {
218e99
+            error_set(errp, QERR_IO_ERROR);
218e99
+            return;
218e99
+        }
218e99
+    }
218e99
+
218e99
+    flags = states->old_bs->open_flags;
218e99
+
218e99
+    proto_drv = bdrv_find_protocol(new_image_file);
218e99
+    if (!proto_drv) {
218e99
+        error_set(errp, QERR_INVALID_BLOCK_FORMAT, format);
218e99
+        return;
218e99
+    }
218e99
+
218e99
+    /* create new image w/backing file */
218e99
+    if (mode != NEW_IMAGE_MODE_EXISTING) {
218e99
+        bdrv_img_create(new_image_file, format,
218e99
+                        states->old_bs->filename,
218e99
+                        states->old_bs->drv->format_name,
218e99
+                        NULL, -1, flags, &local_err, false);
218e99
+        if (error_is_set(&local_err)) {
218e99
+            error_propagate(errp, local_err);
218e99
+            return;
218e99
+        }
218e99
+    }
218e99
+
218e99
+    /* We will manually add the backing_hd field to the bs later */
218e99
+    states->new_bs = bdrv_new("");
218e99
+    /* TODO Inherit bs->options or only take explicit options with an
218e99
+     * extended QMP command? */
218e99
+    ret = bdrv_open(states->new_bs, new_image_file, NULL,
218e99
+                    flags | BDRV_O_NO_BACKING, drv);
218e99
+    if (ret != 0) {
218e99
+        error_set(errp, QERR_OPEN_FILE_FAILED, new_image_file);
218e99
+    }
218e99
+}
218e99
+
218e99
 /*
218e99
  * 'Atomic' group snapshots.  The snapshots are taken as a set, and if any fail
218e99
  *  then we do not pivot any of the devices in the group, and abandon the
218e99
@@ -792,7 +864,6 @@ typedef struct BlkTransactionStates {
218e99
  */
218e99
 void qmp_transaction(BlockdevActionList *dev_list, Error **errp)
218e99
 {
218e99
-    int ret = 0;
218e99
     BlockdevActionList *dev_entry = dev_list;
218e99
     BlkTransactionStates *states, *next;
218e99
     Error *local_err = NULL;
218e99
@@ -806,9 +877,6 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **errp)
218e99
     /* We don't do anything in this loop that commits us to the snapshot */
218e99
     while (NULL != dev_entry) {
218e99
         BlockdevAction *dev_info = NULL;
218e99
-        BlockDriver *proto_drv;
218e99
-        BlockDriver *drv;
218e99
-        int flags;
218e99
         enum NewImageMode mode;
218e99
         const char *new_image_file;
218e99
         const char *device;
218e99
@@ -831,70 +899,17 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **errp)
218e99
                 format = dev_info->blockdev_snapshot_sync->format;
218e99
             }
218e99
             mode = dev_info->blockdev_snapshot_sync->mode;
218e99
-            break;
218e99
-        default:
218e99
-            abort();
218e99
-        }
218e99
-
218e99
-        drv = bdrv_find_format(format);
218e99
-        if (!drv) {
218e99
-            error_set(errp, QERR_INVALID_BLOCK_FORMAT, format);
218e99
-            goto delete_and_fail;
218e99
-        }
218e99
-
218e99
-        states->old_bs = bdrv_find(device);
218e99
-        if (!states->old_bs) {
218e99
-            error_set(errp, QERR_DEVICE_NOT_FOUND, device);
218e99
-            goto delete_and_fail;
218e99
-        }
218e99
-
218e99
-        if (!bdrv_is_inserted(states->old_bs)) {
218e99
-            error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);
218e99
-            goto delete_and_fail;
218e99
-        }
218e99
-
218e99
-        if (bdrv_in_use(states->old_bs)) {
218e99
-            error_set(errp, QERR_DEVICE_IN_USE, device);
218e99
-            goto delete_and_fail;
218e99
-        }
218e99
-
218e99
-        if (!bdrv_is_read_only(states->old_bs)) {
218e99
-            if (bdrv_flush(states->old_bs)) {
218e99
-                error_set(errp, QERR_IO_ERROR);
218e99
-                goto delete_and_fail;
218e99
-            }
218e99
-        }
218e99
-
218e99
-        flags = states->old_bs->open_flags;
218e99
-
218e99
-        proto_drv = bdrv_find_protocol(new_image_file);
218e99
-        if (!proto_drv) {
218e99
-            error_set(errp, QERR_INVALID_BLOCK_FORMAT, format);
218e99
-            goto delete_and_fail;
218e99
-        }
218e99
-
218e99
-        /* create new image w/backing file */
218e99
-        if (mode != NEW_IMAGE_MODE_EXISTING) {
218e99
-            bdrv_img_create(new_image_file, format,
218e99
-                            states->old_bs->filename,
218e99
-                            states->old_bs->drv->format_name,
218e99
-                            NULL, -1, flags, &local_err, false);
218e99
+            external_snapshot_prepare(device, format, new_image_file,
218e99
+                                      mode, states, &local_err);
218e99
             if (error_is_set(&local_err)) {
218e99
                 error_propagate(errp, local_err);
218e99
                 goto delete_and_fail;
218e99
             }
218e99
+            break;
218e99
+        default:
218e99
+            abort();
218e99
         }
218e99
 
218e99
-        /* We will manually add the backing_hd field to the bs later */
218e99
-        states->new_bs = bdrv_new("");
218e99
-        /* TODO Inherit bs->options or only take explicit options with an
218e99
-         * extended QMP command? */
218e99
-        ret = bdrv_open(states->new_bs, new_image_file, NULL,
218e99
-                        flags | BDRV_O_NO_BACKING, drv);
218e99
-        if (ret != 0) {
218e99
-            error_set(errp, QERR_OPEN_FILE_FAILED, new_image_file);
218e99
-            goto delete_and_fail;
218e99
-        }
218e99
     }
218e99
 
218e99
 
218e99
-- 
218e99
1.7.1
218e99