render / rpms / qemu

Forked from rpms/qemu 9 months ago
Clone

Blame 0108-block-set-device_list.tqe_prev-to-NULL-on-BDS-remova.patch

54cb13
From: Jeff Cody <jcody@redhat.com>
54cb13
Date: Mon, 1 Feb 2016 20:33:10 -0500
54cb13
Subject: [PATCH] block: set device_list.tqe_prev to NULL on BDS removal
54cb13
54cb13
This fixes a regression introduced with commit 3f09bfbc7.  Multiple
54cb13
bugs arise in conjunction with live snapshots and mirroring operations
54cb13
(which include active layer commit).
54cb13
54cb13
After a live snapshot occurs, the active layer and the base layer both
54cb13
have a non-NULL tqe_prev field in the device_list, although the base
54cb13
node's tqe_prev field points to a NULL entry.  This non-NULL tqe_prev
54cb13
field occurs after the bdrv_append() in the external snapshot calls
54cb13
change_parent_backing_link().
54cb13
54cb13
In change_parent_backing_link(), when the previous active layer is
54cb13
removed from device_list, the device_list.tqe_prev pointer is not
54cb13
set to NULL.
54cb13
54cb13
The operating scheme in the block layer is to indicate that a BDS belongs
54cb13
in the bdrv_states device_list iff the device_list.tqe_prev pointer
54cb13
is non-NULL.
54cb13
54cb13
This patch does two things:
54cb13
54cb13
1.) Introduces a new block layer helper bdrv_device_remove() to remove a
54cb13
    BDS from the device_list, and
54cb13
2.) uses that new API, which also fixes the regression once used in
54cb13
    change_parent_backing_link().
54cb13
54cb13
Signed-off-by: Jeff Cody <jcody@redhat.com>
54cb13
Message-id: 0cd51e11c0666c04ddb7c05293fe94afeb551e89.1454376655.git.jcody@redhat.com
54cb13
Reviewed-by: Max Reitz <mreitz@redhat.com>
54cb13
Signed-off-by: Max Reitz <mreitz@redhat.com>
54cb13
(cherry picked from commit f8aa905a4fec89863c82de4186352447d851871e)
54cb13
---
54cb13
 block.c               | 24 ++++++++++++++----------
54cb13
 blockdev.c            |  3 +--
54cb13
 include/block/block.h |  1 +
54cb13
 3 files changed, 16 insertions(+), 12 deletions(-)
54cb13
54cb13
diff --git a/block.c b/block.c
54cb13
index 3a7324b..3c172dd 100644
54cb13
--- a/block.c
54cb13
+++ b/block.c
54cb13
@@ -1976,21 +1976,25 @@ void bdrv_close_all(void)
54cb13
     }
54cb13
 }
54cb13
 
54cb13
+/* Note that bs->device_list.tqe_prev is initially null,
54cb13
+ * and gets set to non-null by QTAILQ_INSERT_TAIL().  Establish
54cb13
+ * the useful invariant "bs in bdrv_states iff bs->tqe_prev" by
54cb13
+ * resetting it to null on remove.  */
54cb13
+void bdrv_device_remove(BlockDriverState *bs)
54cb13
+{
54cb13
+    QTAILQ_REMOVE(&bdrv_states, bs, device_list);
54cb13
+    bs->device_list.tqe_prev = NULL;
54cb13
+}
54cb13
+
54cb13
 /* make a BlockDriverState anonymous by removing from bdrv_state and
54cb13
  * graph_bdrv_state list.
54cb13
    Also, NULL terminate the device_name to prevent double remove */
54cb13
 void bdrv_make_anon(BlockDriverState *bs)
54cb13
 {
54cb13
-    /*
54cb13
-     * Take care to remove bs from bdrv_states only when it's actually
54cb13
-     * in it.  Note that bs->device_list.tqe_prev is initially null,
54cb13
-     * and gets set to non-null by QTAILQ_INSERT_TAIL().  Establish
54cb13
-     * the useful invariant "bs in bdrv_states iff bs->tqe_prev" by
54cb13
-     * resetting it to null on remove.
54cb13
-     */
54cb13
+    /* Take care to remove bs from bdrv_states only when it's actually
54cb13
+     * in it. */
54cb13
     if (bs->device_list.tqe_prev) {
54cb13
-        QTAILQ_REMOVE(&bdrv_states, bs, device_list);
54cb13
-        bs->device_list.tqe_prev = NULL;
54cb13
+        bdrv_device_remove(bs);
54cb13
     }
54cb13
     if (bs->node_name[0] != '\0') {
54cb13
         QTAILQ_REMOVE(&graph_bdrv_states, bs, node_list);
54cb13
@@ -2031,7 +2035,7 @@ static void change_parent_backing_link(BlockDriverState *from,
54cb13
         if (!to->device_list.tqe_prev) {
54cb13
             QTAILQ_INSERT_BEFORE(from, to, device_list);
54cb13
         }
54cb13
-        QTAILQ_REMOVE(&bdrv_states, from, device_list);
54cb13
+        bdrv_device_remove(from);
54cb13
     }
54cb13
 }
54cb13
 
54cb13
diff --git a/blockdev.c b/blockdev.c
54cb13
index 80932e8..c236126 100644
54cb13
--- a/blockdev.c
54cb13
+++ b/blockdev.c
54cb13
@@ -2384,8 +2384,7 @@ void qmp_x_blockdev_remove_medium(const char *device, Error **errp)
54cb13
 
54cb13
     /* This follows the convention established by bdrv_make_anon() */
54cb13
     if (bs->device_list.tqe_prev) {
54cb13
-        QTAILQ_REMOVE(&bdrv_states, bs, device_list);
54cb13
-        bs->device_list.tqe_prev = NULL;
54cb13
+        bdrv_device_remove(bs);
54cb13
     }
54cb13
 
54cb13
     blk_remove_bs(blk);
54cb13
diff --git a/include/block/block.h b/include/block/block.h
54cb13
index 3477328..d83d420 100644
54cb13
--- a/include/block/block.h
54cb13
+++ b/include/block/block.h
54cb13
@@ -196,6 +196,7 @@ int bdrv_create(BlockDriver *drv, const char* filename,
54cb13
 int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp);
54cb13
 BlockDriverState *bdrv_new_root(void);
54cb13
 BlockDriverState *bdrv_new(void);
54cb13
+void bdrv_device_remove(BlockDriverState *bs);
54cb13
 void bdrv_make_anon(BlockDriverState *bs);
54cb13
 void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old);
54cb13
 void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top);