[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL v2 49/50] block: set device_list.tqe_prev to NULL on
From: |
Max Reitz |
Subject: |
[Qemu-devel] [PULL v2 49/50] block: set device_list.tqe_prev to NULL on BDS removal |
Date: |
Tue, 2 Feb 2016 18:35:42 +0100 |
From: Jeff Cody <address@hidden>
This fixes a regression introduced with commit 3f09bfbc7. Multiple
bugs arise in conjunction with live snapshots and mirroring operations
(which include active layer commit).
After a live snapshot occurs, the active layer and the base layer both
have a non-NULL tqe_prev field in the device_list, although the base
node's tqe_prev field points to a NULL entry. This non-NULL tqe_prev
field occurs after the bdrv_append() in the external snapshot calls
change_parent_backing_link().
In change_parent_backing_link(), when the previous active layer is
removed from device_list, the device_list.tqe_prev pointer is not
set to NULL.
The operating scheme in the block layer is to indicate that a BDS belongs
in the bdrv_states device_list iff the device_list.tqe_prev pointer
is non-NULL.
This patch does two things:
1.) Introduces a new block layer helper bdrv_device_remove() to remove a
BDS from the device_list, and
2.) uses that new API, which also fixes the regression once used in
change_parent_backing_link().
Signed-off-by: Jeff Cody <address@hidden>
Message-id: address@hidden
Reviewed-by: Max Reitz <address@hidden>
Signed-off-by: Max Reitz <address@hidden>
---
block.c | 24 ++++++++++++++----------
blockdev.c | 3 +--
include/block/block.h | 1 +
3 files changed, 16 insertions(+), 12 deletions(-)
diff --git a/block.c b/block.c
index ff1aafc..dff3a3a 100644
--- a/block.c
+++ b/block.c
@@ -2242,21 +2242,25 @@ void bdrv_close_all(void)
}
}
+/* Note that bs->device_list.tqe_prev is initially null,
+ * and gets set to non-null by QTAILQ_INSERT_TAIL(). Establish
+ * the useful invariant "bs in bdrv_states iff bs->tqe_prev" by
+ * resetting it to null on remove. */
+void bdrv_device_remove(BlockDriverState *bs)
+{
+ QTAILQ_REMOVE(&bdrv_states, bs, device_list);
+ bs->device_list.tqe_prev = NULL;
+}
+
/* make a BlockDriverState anonymous by removing from bdrv_state and
* graph_bdrv_state list.
Also, NULL terminate the device_name to prevent double remove */
void bdrv_make_anon(BlockDriverState *bs)
{
- /*
- * Take care to remove bs from bdrv_states only when it's actually
- * in it. Note that bs->device_list.tqe_prev is initially null,
- * and gets set to non-null by QTAILQ_INSERT_TAIL(). Establish
- * the useful invariant "bs in bdrv_states iff bs->tqe_prev" by
- * resetting it to null on remove.
- */
+ /* Take care to remove bs from bdrv_states only when it's actually
+ * in it. */
if (bs->device_list.tqe_prev) {
- QTAILQ_REMOVE(&bdrv_states, bs, device_list);
- bs->device_list.tqe_prev = NULL;
+ bdrv_device_remove(bs);
}
if (bs->node_name[0] != '\0') {
QTAILQ_REMOVE(&graph_bdrv_states, bs, node_list);
@@ -2297,7 +2301,7 @@ static void change_parent_backing_link(BlockDriverState
*from,
if (!to->device_list.tqe_prev) {
QTAILQ_INSERT_BEFORE(from, to, device_list);
}
- QTAILQ_REMOVE(&bdrv_states, from, device_list);
+ bdrv_device_remove(from);
}
}
diff --git a/blockdev.c b/blockdev.c
index 35e1e5c..be4ca44 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -2408,8 +2408,7 @@ void qmp_x_blockdev_remove_medium(const char *device,
Error **errp)
/* This follows the convention established by bdrv_make_anon() */
if (bs->device_list.tqe_prev) {
- QTAILQ_REMOVE(&bdrv_states, bs, device_list);
- bs->device_list.tqe_prev = NULL;
+ bdrv_device_remove(bs);
}
blk_remove_bs(blk);
diff --git a/include/block/block.h b/include/block/block.h
index 0035ad8..1c4f4d8 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -199,6 +199,7 @@ int bdrv_create(BlockDriver *drv, const char* filename,
int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp);
BlockDriverState *bdrv_new_root(void);
BlockDriverState *bdrv_new(void);
+void bdrv_device_remove(BlockDriverState *bs);
void bdrv_make_anon(BlockDriverState *bs);
void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top);
void bdrv_replace_in_backing_chain(BlockDriverState *old,
--
2.7.0
- [Qemu-devel] [PULL v2 40/50] sheepdog: Assign bs to file in sd_co_get_block_status, (continued)
- [Qemu-devel] [PULL v2 40/50] sheepdog: Assign bs to file in sd_co_get_block_status, Max Reitz, 2016/02/02
- [Qemu-devel] [PULL v2 41/50] vdi: Assign bs->file->bs to file in vdi_co_get_block_status, Max Reitz, 2016/02/02
- [Qemu-devel] [PULL v2 39/50] qed: Assign bs->file->bs to file in bdrv_qed_co_get_block_status, Max Reitz, 2016/02/02
- [Qemu-devel] [PULL v2 42/50] vpc: Assign bs->file->bs to file in vpc_co_get_block_status, Max Reitz, 2016/02/02
- [Qemu-devel] [PULL v2 43/50] vmdk: Fix calculation of block status's offset, Max Reitz, 2016/02/02
- [Qemu-devel] [PULL v2 44/50] vmdk: Return extent's file in bdrv_get_block_status, Max Reitz, 2016/02/02
- [Qemu-devel] [PULL v2 46/50] qemu-img: In "map", use the returned "file" from bdrv_get_block_status, Max Reitz, 2016/02/02
- [Qemu-devel] [PULL v2 45/50] block: Use returned *file in bdrv_co_get_block_status, Max Reitz, 2016/02/02
- [Qemu-devel] [PULL v2 47/50] qemu-img: Make MapEntry a QAPI struct, Max Reitz, 2016/02/02
- [Qemu-devel] [PULL v2 48/50] iotests: Add "qemu-img map" test for VMDK extents, Max Reitz, 2016/02/02
- [Qemu-devel] [PULL v2 49/50] block: set device_list.tqe_prev to NULL on BDS removal,
Max Reitz <=
- [Qemu-devel] [PULL v2 50/50] block: qemu-iotests - add test for snapshot, commit, snapshot bug, Max Reitz, 2016/02/02
- Re: [Qemu-devel] [PULL v2 00/50] Block patches, Peter Maydell, 2016/02/02