yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
9ae3a8
From bff9b33a3c4e0757c1e779ebedbffa391d926ecb Mon Sep 17 00:00:00 2001
9ae3a8
From: Max Reitz <mreitz@redhat.com>
9ae3a8
Date: Mon, 4 Nov 2013 22:31:52 +0100
9ae3a8
Subject: [PATCH 01/87] block: drop bs_snapshots global variable
9ae3a8
9ae3a8
RH-Author: Max Reitz <mreitz@redhat.com>
9ae3a8
Message-id: <1383604354-12743-2-git-send-email-mreitz@redhat.com>
9ae3a8
Patchwork-id: 55301
9ae3a8
O-Subject: [RHEL-7.0 qemu-kvm PATCH 01/43] block: drop bs_snapshots global variable
9ae3a8
Bugzilla: 1026524
9ae3a8
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
RH-Acked-by: Fam Zheng <famz@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
9ae3a8
From: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
9ae3a8
BZ: 1026524
9ae3a8
9ae3a8
The bs_snapshots global variable points to the BlockDriverState which
9ae3a8
will be used to save vmstate.  This is really a savevm.c concept but was
9ae3a8
moved into block.c:bdrv_snapshots() when it became clear that hotplug
9ae3a8
could result in a dangling pointer.
9ae3a8
9ae3a8
While auditing the block layer's global state I came upon bs_snapshots
9ae3a8
and realized that a variable is not necessary here.  Simply find the
9ae3a8
first BlockDriverState capable of internal snapshots each time this is
9ae3a8
needed.
9ae3a8
9ae3a8
The behavior of bdrv_snapshots() is preserved across hotplug because new
9ae3a8
drives are always appended to the bdrv_states list.  This means that
9ae3a8
calling the new find_vmstate_bs() function is idempotent - it returns
9ae3a8
the same BlockDriverState unless it was hot-unplugged.
9ae3a8
9ae3a8
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
Reviewed-by: Eric Blake <eblake@redhat.com>
9ae3a8
Reviewed-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
9ae3a8
Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
(cherry picked from commit 29d782710f87f01991bfc85cd9bef7d15280a5e2)
9ae3a8
9ae3a8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9ae3a8
---
9ae3a8
 block.c               | 28 ----------------------------
9ae3a8
 include/block/block.h |  1 -
9ae3a8
 savevm.c              | 19 +++++++++++++++----
9ae3a8
 3 files changed, 15 insertions(+), 33 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 block.c               |   28 ----------------------------
9ae3a8
 include/block/block.h |    1 -
9ae3a8
 savevm.c              |   19 +++++++++++++++----
9ae3a8
 3 files changed, 15 insertions(+), 33 deletions(-)
9ae3a8
9ae3a8
diff --git a/block.c b/block.c
9ae3a8
index fdff92f..84a3a8d 100644
9ae3a8
--- a/block.c
9ae3a8
+++ b/block.c
9ae3a8
@@ -99,9 +99,6 @@ static QTAILQ_HEAD(, BlockDriverState) bdrv_states =
9ae3a8
 static QLIST_HEAD(, BlockDriver) bdrv_drivers =
9ae3a8
     QLIST_HEAD_INITIALIZER(bdrv_drivers);
9ae3a8
 
9ae3a8
-/* The device to use for VM snapshots */
9ae3a8
-static BlockDriverState *bs_snapshots;
9ae3a8
-
9ae3a8
 /* If non-zero, use only whitelisted block drivers */
9ae3a8
 static int use_bdrv_whitelist;
9ae3a8
 
9ae3a8
@@ -1384,9 +1381,6 @@ void bdrv_close(BlockDriverState *bs)
9ae3a8
     notifier_list_notify(&bs->close_notifiers, bs);
9ae3a8
 
9ae3a8
     if (bs->drv) {
9ae3a8
-        if (bs == bs_snapshots) {
9ae3a8
-            bs_snapshots = NULL;
9ae3a8
-        }
9ae3a8
         if (bs->backing_hd) {
9ae3a8
             bdrv_delete(bs->backing_hd);
9ae3a8
             bs->backing_hd = NULL;
9ae3a8
@@ -1619,7 +1613,6 @@ void bdrv_delete(BlockDriverState *bs)
9ae3a8
 
9ae3a8
     bdrv_close(bs);
9ae3a8
 
9ae3a8
-    assert(bs != bs_snapshots);
9ae3a8
     g_free(bs);
9ae3a8
 }
9ae3a8
 
9ae3a8
@@ -1663,9 +1656,6 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops,
9ae3a8
 {
9ae3a8
     bs->dev_ops = ops;
9ae3a8
     bs->dev_opaque = opaque;
9ae3a8
-    if (bdrv_dev_has_removable_media(bs) && bs == bs_snapshots) {
9ae3a8
-        bs_snapshots = NULL;
9ae3a8
-    }
9ae3a8
 }
9ae3a8
 
9ae3a8
 void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv,
9ae3a8
@@ -3493,24 +3483,6 @@ int bdrv_is_snapshot(BlockDriverState *bs)
9ae3a8
     return !!(bs->open_flags & BDRV_O_SNAPSHOT);
9ae3a8
 }
9ae3a8
 
9ae3a8
-BlockDriverState *bdrv_snapshots(void)
9ae3a8
-{
9ae3a8
-    BlockDriverState *bs;
9ae3a8
-
9ae3a8
-    if (bs_snapshots) {
9ae3a8
-        return bs_snapshots;
9ae3a8
-    }
9ae3a8
-
9ae3a8
-    bs = NULL;
9ae3a8
-    while ((bs = bdrv_next(bs))) {
9ae3a8
-        if (bdrv_can_snapshot(bs)) {
9ae3a8
-            bs_snapshots = bs;
9ae3a8
-            return bs;
9ae3a8
-        }
9ae3a8
-    }
9ae3a8
-    return NULL;
9ae3a8
-}
9ae3a8
-
9ae3a8
 int bdrv_snapshot_create(BlockDriverState *bs,
9ae3a8
                          QEMUSnapshotInfo *sn_info)
9ae3a8
 {
9ae3a8
diff --git a/include/block/block.h b/include/block/block.h
9ae3a8
index bc1f5f6..3b3f40e 100644
9ae3a8
--- a/include/block/block.h
9ae3a8
+++ b/include/block/block.h
9ae3a8
@@ -362,7 +362,6 @@ BlockInfo *bdrv_query_info(BlockDriverState *s);
9ae3a8
 BlockStats *bdrv_query_stats(const BlockDriverState *bs);
9ae3a8
 int bdrv_can_snapshot(BlockDriverState *bs);
9ae3a8
 int bdrv_is_snapshot(BlockDriverState *bs);
9ae3a8
-BlockDriverState *bdrv_snapshots(void);
9ae3a8
 int bdrv_snapshot_create(BlockDriverState *bs,
9ae3a8
                          QEMUSnapshotInfo *sn_info);
9ae3a8
 int bdrv_snapshot_goto(BlockDriverState *bs,
9ae3a8
diff --git a/savevm.c b/savevm.c
9ae3a8
index 1ed7f05..d9f3787 100644
9ae3a8
--- a/savevm.c
9ae3a8
+++ b/savevm.c
9ae3a8
@@ -2262,6 +2262,17 @@ out:
9ae3a8
     return ret;
9ae3a8
 }
9ae3a8
 
9ae3a8
+static BlockDriverState *find_vmstate_bs(void)
9ae3a8
+{
9ae3a8
+    BlockDriverState *bs = NULL;
9ae3a8
+    while ((bs = bdrv_next(bs))) {
9ae3a8
+        if (bdrv_can_snapshot(bs)) {
9ae3a8
+            return bs;
9ae3a8
+        }
9ae3a8
+    }
9ae3a8
+    return NULL;
9ae3a8
+}
9ae3a8
+
9ae3a8
 static int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
9ae3a8
                               const char *name)
9ae3a8
 {
9ae3a8
@@ -2338,7 +2349,7 @@ void do_savevm(Monitor *mon, const QDict *qdict)
9ae3a8
         }
9ae3a8
     }
9ae3a8
 
9ae3a8
-    bs = bdrv_snapshots();
9ae3a8
+    bs = find_vmstate_bs();
9ae3a8
     if (!bs) {
9ae3a8
         monitor_printf(mon, "No block device can accept snapshots\n");
9ae3a8
         return;
9ae3a8
@@ -2440,7 +2451,7 @@ int load_vmstate(const char *name)
9ae3a8
     QEMUFile *f;
9ae3a8
     int ret;
9ae3a8
 
9ae3a8
-    bs_vm_state = bdrv_snapshots();
9ae3a8
+    bs_vm_state = find_vmstate_bs();
9ae3a8
     if (!bs_vm_state) {
9ae3a8
         error_report("No block device supports snapshots");
9ae3a8
         return -ENOTSUP;
9ae3a8
@@ -2519,7 +2530,7 @@ void do_delvm(Monitor *mon, const QDict *qdict)
9ae3a8
     int ret;
9ae3a8
     const char *name = qdict_get_str(qdict, "name");
9ae3a8
 
9ae3a8
-    bs = bdrv_snapshots();
9ae3a8
+    bs = find_vmstate_bs();
9ae3a8
     if (!bs) {
9ae3a8
         monitor_printf(mon, "No block device supports snapshots\n");
9ae3a8
         return;
9ae3a8
@@ -2551,7 +2562,7 @@ void do_info_snapshots(Monitor *mon, const QDict *qdict)
9ae3a8
     int *available_snapshots;
9ae3a8
     char buf[256];
9ae3a8
 
9ae3a8
-    bs = bdrv_snapshots();
9ae3a8
+    bs = find_vmstate_bs();
9ae3a8
     if (!bs) {
9ae3a8
         monitor_printf(mon, "No available block device supports snapshots\n");
9ae3a8
         return;
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8