summaryrefslogtreecommitdiffstats
path: root/nbd
diff options
context:
space:
mode:
authorMax Reitz <mreitz@redhat.com>2016-01-29 16:36:06 +0100
committerTimothy Pearson <tpearson@raptorengineering.com>2019-11-29 19:30:22 -0600
commit68c8477c1aaa6cf20b1e2a879662d368a6ab7972 (patch)
tree0eec8a9d8545da6c33da262b91c7ad56f52d1976 /nbd
parente1d01270df77e2c6a9bf83f23c947786e4f3840f (diff)
downloadhqemu-68c8477c1aaa6cf20b1e2a879662d368a6ab7972.zip
hqemu-68c8477c1aaa6cf20b1e2a879662d368a6ab7972.tar.gz
nbd: Switch from close to eject notifier
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 <mreitz@redhat.com> Reviewed-by: Fam Zheng <famz@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'nbd')
-rw-r--r--nbd/server.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/nbd/server.c b/nbd/server.c
index 7fa7f53..1ec79cf 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
@@ -747,6 +759,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);
OpenPOWER on IntegriCloud