[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v9 12/16] blockdev: Keep track of monitor-owned BDS
From: |
Max Reitz |
Subject: |
[Qemu-block] [PATCH v9 12/16] blockdev: Keep track of monitor-owned BDS |
Date: |
Fri, 29 Jan 2016 16:36:12 +0100 |
As a side effect, we can now make x-blockdev-del's check whether a BDS
is actually owned by the monitor explicit.
Signed-off-by: Max Reitz <address@hidden>
---
blockdev.c | 28 +++++++++++++++++++++++++++-
include/block/block_int.h | 4 ++++
stubs/Makefile.objs | 1 +
stubs/blockdev-close-all-bdrv-states.c | 5 +++++
4 files changed, 37 insertions(+), 1 deletion(-)
create mode 100644 stubs/blockdev-close-all-bdrv-states.c
diff --git a/blockdev.c b/blockdev.c
index 09d4621..35e1e5c 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -50,6 +50,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",
@@ -702,6 +705,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)
{
@@ -3875,12 +3891,15 @@ 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)) {
if (blk) {
blk_unref(blk);
} else {
+ QTAILQ_REMOVE(&monitor_bdrv_states, bs, monitor_list);
bdrv_unref(bs);
}
error_setg(errp, "blockdev-add doesn't support encrypted devices");
@@ -3940,7 +3959,13 @@ void qmp_x_blockdev_del(bool has_id, const char *id,
goto out;
}
- if (bs->refcnt > 1 || !QLIST_EMPTY(&bs->parents)) {
+ if (!blk && !bs->monitor_list.tqe_prev) {
+ error_setg(errp, "Node %s is not owned by the monitor",
+ bs->node_name);
+ goto out;
+ }
+
+ if (bs->refcnt > 1) {
error_setg(errp, "Block device %s is in use",
bdrv_get_device_or_node_name(bs));
goto out;
@@ -3950,6 +3975,7 @@ void qmp_x_blockdev_del(bool has_id, const char *id,
if (blk) {
blk_unref(blk);
} else {
+ QTAILQ_REMOVE(&monitor_bdrv_states, bs, monitor_list);
bdrv_unref(bs);
}
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 26c4e74..9ef823a 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -446,6 +446,8 @@ struct BlockDriverState {
QTAILQ_ENTRY(BlockDriverState) device_list;
/* element of the list of all BlockDriverStates (all_bdrv_states) */
QTAILQ_ENTRY(BlockDriverState) bs_list;
+ /* element of the list of monitor-owned BDS */
+ QTAILQ_ENTRY(BlockDriverState) monitor_list;
QLIST_HEAD(, BdrvDirtyBitmap) dirty_bitmaps;
int refcnt;
@@ -708,4 +710,6 @@ bool bdrv_requests_pending(BlockDriverState *bs);
void bdrv_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap **out);
void bdrv_undo_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap *in);
+void blockdev_close_all_bdrv_states(void);
+
#endif /* BLOCK_INT_H */
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index d7898a0..e922de9 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 += clock-warp.o
stub-obj-y += cpu-get-clock.o
stub-obj-y += cpu-get-icount.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.7.0
- [Qemu-block] [PATCH v9 01/16] block: Release named dirty bitmaps in bdrv_close(), (continued)
- [Qemu-block] [PATCH v9 01/16] block: Release named dirty bitmaps in bdrv_close(), Max Reitz, 2016/01/29
- [Qemu-block] [PATCH v9 03/16] block: Add BB-BDS remove/insert notifiers, Max Reitz, 2016/01/29
- [Qemu-block] [PATCH v9 02/16] iotests: Add test for eject under NBD server, Max Reitz, 2016/01/29
- [Qemu-block] [PATCH v9 04/16] virtio-blk: Functions for op blocker management, Max Reitz, 2016/01/29
- [Qemu-block] [PATCH v9 05/16] virtio-scsi: Catch BDS-BB removal/insertion, Max Reitz, 2016/01/29
- [Qemu-block] [PATCH v9 06/16] nbd: Switch from close to eject notifier, Max Reitz, 2016/01/29
- [Qemu-block] [PATCH v9 07/16] block: Remove BDS close notifier, Max Reitz, 2016/01/29
- [Qemu-block] [PATCH v9 09/16] blockdev: Use blk_remove_bs() in do_drive_del(), Max Reitz, 2016/01/29
- [Qemu-block] [PATCH v9 08/16] block: Use blk_remove_bs() in blk_delete(), Max Reitz, 2016/01/29
- [Qemu-block] [PATCH v9 11/16] block: Add list of all BlockDriverStates, Max Reitz, 2016/01/29
- [Qemu-block] [PATCH v9 12/16] blockdev: Keep track of monitor-owned BDS,
Max Reitz <=
- [Qemu-block] [PATCH v9 10/16] block: Make bdrv_close() static, Max Reitz, 2016/01/29
- [Qemu-block] [PATCH v9 13/16] block: Add blk_remove_all_bs(), Max Reitz, 2016/01/29
- [Qemu-block] [PATCH v9 15/16] iotests: Add test for multiple BB on BDS tree, Max Reitz, 2016/01/29
- [Qemu-block] [PATCH v9 14/16] block: Rewrite bdrv_close_all(), Max Reitz, 2016/01/29
- [Qemu-block] [PATCH v9 16/16] iotests: Add test for block jobs and BDS ejection, Max Reitz, 2016/01/29