[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 21/48] nbd: Switch from close to eject notifier
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 21/48] nbd: Switch from close to eject notifier |
Date: |
Fri, 29 Jan 2016 18:37:27 +0100 |
From: Max Reitz <address@hidden>
The NBD code uses the BDS close notifier to determine when a medium is
ejected. However, now it should use the BB's BDS removal notifier for
that instead of the BDS's close notifier.
Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Fam Zheng <address@hidden>
Reviewed-by: Kevin Wolf <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
blockdev-nbd.c | 40 +++++-----------------------------------
nbd/server.c | 13 +++++++++++++
2 files changed, 18 insertions(+), 35 deletions(-)
diff --git a/blockdev-nbd.c b/blockdev-nbd.c
index 4a758ac..9d6a21c 100644
--- a/blockdev-nbd.c
+++ b/blockdev-nbd.c
@@ -45,37 +45,11 @@ void qmp_nbd_server_start(SocketAddress *addr, Error **errp)
}
}
-/*
- * Hook into the BlockBackend notifiers to close the export when the
- * backend is closed.
- */
-typedef struct NBDCloseNotifier {
- Notifier n;
- NBDExport *exp;
- QTAILQ_ENTRY(NBDCloseNotifier) next;
-} NBDCloseNotifier;
-
-static QTAILQ_HEAD(, NBDCloseNotifier) close_notifiers =
- QTAILQ_HEAD_INITIALIZER(close_notifiers);
-
-static void nbd_close_notifier(Notifier *n, void *data)
-{
- NBDCloseNotifier *cn = DO_UPCAST(NBDCloseNotifier, n, n);
-
- notifier_remove(&cn->n);
- QTAILQ_REMOVE(&close_notifiers, cn, next);
-
- nbd_export_close(cn->exp);
- nbd_export_put(cn->exp);
- g_free(cn);
-}
-
void qmp_nbd_server_add(const char *device, bool has_writable, bool writable,
Error **errp)
{
BlockBackend *blk;
NBDExport *exp;
- NBDCloseNotifier *n;
if (server_fd == -1) {
error_setg(errp, "NBD server not running");
@@ -113,19 +87,15 @@ void qmp_nbd_server_add(const char *device, bool
has_writable, bool writable,
nbd_export_set_name(exp, device);
- n = g_new0(NBDCloseNotifier, 1);
- n->n.notify = nbd_close_notifier;
- n->exp = exp;
- blk_add_close_notifier(blk, &n->n);
- QTAILQ_INSERT_TAIL(&close_notifiers, n, next);
+ /* The list of named exports has a strong reference to this export now and
+ * our only way of accessing it is through nbd_export_find(), so we can
drop
+ * the strong reference that is @exp. */
+ nbd_export_put(exp);
}
void qmp_nbd_server_stop(Error **errp)
{
- while (!QTAILQ_EMPTY(&close_notifiers)) {
- NBDCloseNotifier *cn = QTAILQ_FIRST(&close_notifiers);
- nbd_close_notifier(&cn->n, nbd_export_get_blockdev(cn->exp));
- }
+ nbd_export_close_all();
if (server_fd != -1) {
qemu_set_fd_handler(server_fd, NULL, NULL, NULL);
diff --git a/nbd/server.c b/nbd/server.c
index 5169b59..2045f7c 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -64,6 +64,8 @@ struct NBDExport {
QTAILQ_ENTRY(NBDExport) next;
AioContext *ctx;
+
+ Notifier eject_notifier;
};
static QTAILQ_HEAD(, NBDExport) exports = QTAILQ_HEAD_INITIALIZER(exports);
@@ -644,6 +646,12 @@ static void blk_aio_detach(void *opaque)
exp->ctx = NULL;
}
+static void nbd_eject_notifier(Notifier *n, void *data)
+{
+ NBDExport *exp = container_of(n, NBDExport, eject_notifier);
+ nbd_export_close(exp);
+}
+
NBDExport *nbd_export_new(BlockBackend *blk, off_t dev_offset, off_t size,
uint32_t nbdflags, void (*close)(NBDExport *),
Error **errp)
@@ -666,6 +674,10 @@ NBDExport *nbd_export_new(BlockBackend *blk, off_t
dev_offset, off_t size,
exp->ctx = blk_get_aio_context(blk);
blk_ref(blk);
blk_add_aio_context_notifier(blk, blk_aio_attached, blk_aio_detach, exp);
+
+ exp->eject_notifier.notify = nbd_eject_notifier;
+ blk_add_remove_bs_notifier(blk, &exp->eject_notifier);
+
/*
* NBD exports are used for non-shared storage migration. Make sure
* that BDRV_O_INACTIVE is cleared and the image is ready for write
@@ -745,6 +757,7 @@ void nbd_export_put(NBDExport *exp)
}
if (exp->blk) {
+ notifier_remove(&exp->eject_notifier);
blk_remove_aio_context_notifier(exp->blk, blk_aio_attached,
blk_aio_detach, exp);
blk_unref(exp->blk);
--
1.8.3.1
- [Qemu-devel] [PULL 02/48] blockdev: Fix 'change' for slot devices, (continued)
- [Qemu-devel] [PULL 02/48] blockdev: Fix 'change' for slot devices, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 12/48] iotests: Make _filter_nbd support more URL types, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 13/48] iotests: Make redirecting qemu's stderr optional, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 14/48] iotests: Add test for a nonexistent NBD export, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 16/48] block: Release named dirty bitmaps in bdrv_close(), Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 10/48] iotests: Move _filter_nbd into common.filter, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 15/48] block: Remove unused struct definition BlockFinishData, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 11/48] iotests: Make _filter_nbd drop log lines, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 17/48] iotests: Add test for eject under NBD server, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 08/48] iotests: Rename filter_nbd to _filter_nbd in 083, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 21/48] nbd: Switch from close to eject notifier,
Kevin Wolf <=
- [Qemu-devel] [PULL 22/48] block: Remove BDS close notifier, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 24/48] blockdev: Use blk_remove_bs() in do_drive_del(), Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 23/48] block: Use blk_remove_bs() in blk_delete(), Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 18/48] block: Add BB-BDS remove/insert notifiers, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 19/48] virtio-blk: Functions for op blocker management, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 20/48] virtio-scsi: Catch BDS-BB removal/insertion, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 25/48] block: Make bdrv_close() static, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 30/48] iotests: Add test for multiple BB on BDS tree, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 26/48] block: Add list of all BlockDriverStates, Kevin Wolf, 2016/01/29
- [Qemu-devel] [PULL 34/48] qcow: Assign bs->file->bs to file in qcow_co_get_block_status, Kevin Wolf, 2016/01/29