aboutsummaryrefslogtreecommitdiff
path: root/blockdev-nbd.c
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2019-09-16 21:39:17 -0500
committerEric Blake <eblake@redhat.com>2019-09-24 07:30:19 -0500
commit61bc846d8c58535af6884b637a4005dd6111ea95 (patch)
treea5c98306bdac3b6311aa472745ec81879a3cbdb2 /blockdev-nbd.c
parentb4961249af0403fa55aae57c4c8806b24f7a7b33 (diff)
nbd: Grab aio context lock in more places
When iothreads are in use, the failure to grab the aio context results in an assertion failure when trying to unlock things during blk_unref, when trying to unlock a mutex that was not locked. In short, all calls to nbd_export_put need to done while within the correct aio context. But since nbd_export_put can recursively reach itself via nbd_export_close, and recursively grabbing the context would deadlock, we can't do the context grab directly in those functions, but must do so in their callers. Hoist the use of the correct aio_context from nbd_export_new() to its caller qmp_nbd_server_add(). Then tweak qmp_nbd_server_remove(), nbd_eject_notifier(), and nbd_esport_close_all() to grab the right context, so that all callers during qemu now own the context before nbd_export_put() can call blk_unref(). Remaining uses in qemu-nbd don't matter (since that use case does not support iothreads). Suggested-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Eric Blake <eblake@redhat.com> Message-Id: <20190917023917.32226-1-eblake@redhat.com> Reviewed-by: Sergio Lopez <slp@redhat.com>
Diffstat (limited to 'blockdev-nbd.c')
-rw-r--r--blockdev-nbd.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/blockdev-nbd.c b/blockdev-nbd.c
index 213f226ac1..6a8b206e1d 100644
--- a/blockdev-nbd.c
+++ b/blockdev-nbd.c
@@ -151,6 +151,7 @@ void qmp_nbd_server_add(const char *device, bool has_name, const char *name,
BlockBackend *on_eject_blk;
NBDExport *exp;
int64_t len;
+ AioContext *aio_context;
if (!nbd_server) {
error_setg(errp, "NBD server not running");
@@ -173,11 +174,13 @@ void qmp_nbd_server_add(const char *device, bool has_name, const char *name,
return;
}
+ aio_context = bdrv_get_aio_context(bs);
+ aio_context_acquire(aio_context);
len = bdrv_getlength(bs);
if (len < 0) {
error_setg_errno(errp, -len,
"Failed to determine the NBD export's length");
- return;
+ goto out;
}
if (!has_writable) {
@@ -190,13 +193,16 @@ void qmp_nbd_server_add(const char *device, bool has_name, const char *name,
exp = nbd_export_new(bs, 0, len, name, NULL, bitmap, !writable, !writable,
NULL, false, on_eject_blk, errp);
if (!exp) {
- return;
+ goto out;
}
/* 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);
+
+ out:
+ aio_context_release(aio_context);
}
void qmp_nbd_server_remove(const char *name,
@@ -204,6 +210,7 @@ void qmp_nbd_server_remove(const char *name,
Error **errp)
{
NBDExport *exp;
+ AioContext *aio_context;
if (!nbd_server) {
error_setg(errp, "NBD server not running");
@@ -220,7 +227,10 @@ void qmp_nbd_server_remove(const char *name,
mode = NBD_SERVER_REMOVE_MODE_SAFE;
}
+ aio_context = nbd_export_aio_context(exp);
+ aio_context_acquire(aio_context);
nbd_export_remove(exp, mode, errp);
+ aio_context_release(aio_context);
}
void qmp_nbd_server_stop(Error **errp)