[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 09/11] blockdev: Keep track of monitor-owned BDS
From: |
Max Reitz |
Subject: |
[Qemu-devel] [PATCH v4 09/11] blockdev: Keep track of monitor-owned BDS |
Date: |
Fri, 27 Feb 2015 11:43:58 -0500 |
...and release the reference on bdrv_close_all().
Signed-off-by: Max Reitz <address@hidden>
---
block.c | 5 +++++
blockdev.c | 18 ++++++++++++++++++
include/block/block_int.h | 4 ++++
stubs/Makefile.objs | 1 +
stubs/blockdev-close-all-bdrv-states.c | 5 +++++
5 files changed, 33 insertions(+)
create mode 100644 stubs/blockdev-close-all-bdrv-states.c
diff --git a/block.c b/block.c
index 819c54d..0b0792c 100644
--- a/block.c
+++ b/block.c
@@ -1943,6 +1943,8 @@ void bdrv_close_all(void)
{
BlockDriverState *bs;
+ blockdev_close_all_bdrv_states();
+
QTAILQ_FOREACH(bs, &bdrv_states, device_list) {
AioContext *aio_context = bdrv_get_aio_context(bs);
@@ -2090,6 +2092,9 @@ static void bdrv_move_feature_fields(BlockDriverState
*bs_dest,
/* keep the same entry in bdrv_states */
bs_dest->device_list = bs_src->device_list;
+ /* keep the same entry in the list of monitor-owned BDS */
+ bs_dest->monitor_list = bs_src->monitor_list;
+
bs_dest->blk = bs_src->blk;
memcpy(bs_dest->op_blockers, bs_src->op_blockers,
diff --git a/blockdev.c b/blockdev.c
index e5f5ebc..535e83f 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -47,6 +47,9 @@
#include "trace.h"
#include "sysemu/arch_init.h"
+static QTAILQ_HEAD(, BlockDriverState) monitor_bdrv_states =
+ QTAILQ_HEAD_INITIALIZER(monitor_bdrv_states);
+
static const char *const if_name[IF_COUNT] = {
[IF_NONE] = "none",
[IF_IDE] = "ide",
@@ -648,6 +651,19 @@ fail:
return NULL;
}
+void blockdev_close_all_bdrv_states(void)
+{
+ BlockDriverState *bs, *next_bs;
+
+ QTAILQ_FOREACH_SAFE(bs, &monitor_bdrv_states, monitor_list, next_bs) {
+ AioContext *ctx = bdrv_get_aio_context(bs);
+
+ aio_context_acquire(ctx);
+ bdrv_unref(bs);
+ aio_context_release(ctx);
+ }
+}
+
static void qemu_opt_rename(QemuOpts *opts, const char *from, const char *to,
Error **errp)
{
@@ -3166,6 +3182,8 @@ void qmp_blockdev_add(BlockdevOptions *options, Error
**errp)
if (!bs) {
goto fail;
}
+
+ QTAILQ_INSERT_TAIL(&monitor_bdrv_states, bs, monitor_list);
}
if (bs && bdrv_key_required(bs)) {
diff --git a/include/block/block_int.h b/include/block/block_int.h
index b2c1d87..1b01f45 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -399,6 +399,8 @@ struct BlockDriverState {
QTAILQ_ENTRY(BlockDriverState) node_list;
/* element of the list of "drives" the guest sees */
QTAILQ_ENTRY(BlockDriverState) device_list;
+ /* element of the list of monitor-owned BDS */
+ QTAILQ_ENTRY(BlockDriverState) monitor_list;
QLIST_HEAD(, BdrvDirtyBitmap) dirty_bitmaps;
int refcnt;
@@ -622,4 +624,6 @@ bool blk_dev_is_tray_open(BlockBackend *blk);
bool blk_dev_is_medium_locked(BlockBackend *blk);
void blk_dev_resize_cb(BlockBackend *blk);
+void blockdev_close_all_bdrv_states(void);
+
#endif /* BLOCK_INT_H */
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index 5e347d0..9169a09 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -1,5 +1,6 @@
stub-obj-y += arch-query-cpu-def.o
stub-obj-y += bdrv-commit-all.o
+stub-obj-y += blockdev-close-all-bdrv-states.o
stub-obj-y += chr-baum-init.o
stub-obj-y += chr-msmouse.o
stub-obj-y += chr-testdev.o
diff --git a/stubs/blockdev-close-all-bdrv-states.c
b/stubs/blockdev-close-all-bdrv-states.c
new file mode 100644
index 0000000..12d2442
--- /dev/null
+++ b/stubs/blockdev-close-all-bdrv-states.c
@@ -0,0 +1,5 @@
+#include "block/block_int.h"
+
+void blockdev_close_all_bdrv_states(void)
+{
+}
--
2.1.0
- [Qemu-devel] [PATCH v4 00/11] block: Rework bdrv_close_all(), Max Reitz, 2015/02/27
- [Qemu-devel] [PATCH v4 02/11] iotests: Make redirecting qemu's stderr optional, Max Reitz, 2015/02/27
- [Qemu-devel] [PATCH v4 07/11] blockdev: Use blk_remove_bs() in do_drive_del(), Max Reitz, 2015/02/27
- [Qemu-devel] [PATCH v4 01/11] iotests: Move _filter_nbd into common.filter, Max Reitz, 2015/02/27
- [Qemu-devel] [PATCH v4 09/11] blockdev: Keep track of monitor-owned BDS,
Max Reitz <=
- [Qemu-devel] [PATCH v4 03/11] iotests: Add test for eject under NBD server, Max Reitz, 2015/02/27
- [Qemu-devel] [PATCH v4 05/11] block: Move BDS close notifiers into BB, Max Reitz, 2015/02/27
- [Qemu-devel] [PATCH v4 10/11] block: Eject BDS tree from BB at bdrv_close_all(), Max Reitz, 2015/02/27
- [Qemu-devel] [PATCH v4 06/11] block: Use blk_remove_bs() in blk_delete(), Max Reitz, 2015/02/27
- [Qemu-devel] [PATCH v4 04/11] quorum: Fix close path, Max Reitz, 2015/02/27
- [Qemu-devel] [PATCH v4 11/11] iotests: Add test for multiple BB on BDS tree, Max Reitz, 2015/02/27
- [Qemu-devel] [PATCH v4 08/11] block: Make bdrv_close() static, Max Reitz, 2015/02/27