[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v6 14/20] block/export: don't require AioContext lock around blk_
From: |
Stefan Hajnoczi |
Subject: |
[PATCH v6 14/20] block/export: don't require AioContext lock around blk_exp_ref/unref() |
Date: |
Tue, 16 May 2023 15:02:32 -0400 |
The FUSE export calls blk_exp_ref/unref() without the AioContext lock.
Instead of fixing the FUSE export, adjust blk_exp_ref/unref() so they
work without the AioContext lock. This way it's less error-prone.
Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
---
include/block/export.h | 2 ++
block/export/export.c | 13 ++++++-------
block/export/vduse-blk.c | 4 ----
3 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/include/block/export.h b/include/block/export.h
index 7feb02e10d..f2fe0f8078 100644
--- a/include/block/export.h
+++ b/include/block/export.h
@@ -57,6 +57,8 @@ struct BlockExport {
* Reference count for this block export. This includes strong references
* both from the owner (qemu-nbd or the monitor) and clients connected to
* the export.
+ *
+ * Use atomics to access this field.
*/
int refcount;
diff --git a/block/export/export.c b/block/export/export.c
index 62c7c22d45..ab007e9d31 100644
--- a/block/export/export.c
+++ b/block/export/export.c
@@ -202,11 +202,10 @@ fail:
return NULL;
}
-/* Callers must hold exp->ctx lock */
void blk_exp_ref(BlockExport *exp)
{
- assert(exp->refcount > 0);
- exp->refcount++;
+ assert(qatomic_read(&exp->refcount) > 0);
+ qatomic_inc(&exp->refcount);
}
/* Runs in the main thread */
@@ -229,11 +228,10 @@ static void blk_exp_delete_bh(void *opaque)
aio_context_release(aio_context);
}
-/* Callers must hold exp->ctx lock */
void blk_exp_unref(BlockExport *exp)
{
- assert(exp->refcount > 0);
- if (--exp->refcount == 0) {
+ assert(qatomic_read(&exp->refcount) > 0);
+ if (qatomic_fetch_dec(&exp->refcount) == 1) {
/* Touch the block_exports list only in the main thread */
aio_bh_schedule_oneshot(qemu_get_aio_context(), blk_exp_delete_bh,
exp);
@@ -341,7 +339,8 @@ void qmp_block_export_del(const char *id,
if (!has_mode) {
mode = BLOCK_EXPORT_REMOVE_MODE_SAFE;
}
- if (mode == BLOCK_EXPORT_REMOVE_MODE_SAFE && exp->refcount > 1) {
+ if (mode == BLOCK_EXPORT_REMOVE_MODE_SAFE &&
+ qatomic_read(&exp->refcount) > 1) {
error_setg(errp, "export '%s' still in use", exp->id);
error_append_hint(errp, "Use mode='hard' to force client "
"disconnect\n");
diff --git a/block/export/vduse-blk.c b/block/export/vduse-blk.c
index a25556fe04..e0455551f9 100644
--- a/block/export/vduse-blk.c
+++ b/block/export/vduse-blk.c
@@ -44,9 +44,7 @@ static void vduse_blk_inflight_inc(VduseBlkExport *vblk_exp)
{
if (qatomic_fetch_inc(&vblk_exp->inflight) == 0) {
/* Prevent export from being deleted */
- aio_context_acquire(vblk_exp->export.ctx);
blk_exp_ref(&vblk_exp->export);
- aio_context_release(vblk_exp->export.ctx);
}
}
@@ -57,9 +55,7 @@ static void vduse_blk_inflight_dec(VduseBlkExport *vblk_exp)
aio_wait_kick();
/* Now the export can be deleted */
- aio_context_acquire(vblk_exp->export.ctx);
blk_exp_unref(&vblk_exp->export);
- aio_context_release(vblk_exp->export.ctx);
}
}
--
2.40.1
- [PATCH v6 04/20] virtio-scsi: stop using aio_disable_external() during unplug, (continued)
- [PATCH v6 04/20] virtio-scsi: stop using aio_disable_external() during unplug, Stefan Hajnoczi, 2023/05/16
- [PATCH v6 05/20] util/vhost-user-server: rename refcount to in_flight counter, Stefan Hajnoczi, 2023/05/16
- [PATCH v6 07/20] block/export: stop using is_external in vhost-user-blk server, Stefan Hajnoczi, 2023/05/16
- [PATCH v6 06/20] block/export: wait for vhost-user-blk requests when draining, Stefan Hajnoczi, 2023/05/16
- [PATCH v6 08/20] hw/xen: do not use aio_set_fd_handler(is_external=true) in xen_xenstore, Stefan Hajnoczi, 2023/05/16
- [PATCH v6 09/20] block: add blk_in_drain() API, Stefan Hajnoczi, 2023/05/16
- [PATCH v6 10/20] block: drain from main loop thread in bdrv_co_yield_to_drain(), Stefan Hajnoczi, 2023/05/16
- [PATCH v6 11/20] xen-block: implement BlockDevOps->drained_begin(), Stefan Hajnoczi, 2023/05/16
- [PATCH v6 12/20] hw/xen: do not set is_external=true on evtchn fds, Stefan Hajnoczi, 2023/05/16
- [PATCH v6 13/20] block/export: rewrite vduse-blk drain code, Stefan Hajnoczi, 2023/05/16
- [PATCH v6 14/20] block/export: don't require AioContext lock around blk_exp_ref/unref(),
Stefan Hajnoczi <=
- [PATCH v6 15/20] block/fuse: do not set is_external=true on FUSE fd, Stefan Hajnoczi, 2023/05/16
- [PATCH v6 17/20] virtio-blk: implement BlockDevOps->drained_begin(), Stefan Hajnoczi, 2023/05/16
- [PATCH v6 16/20] virtio: make it possible to detach host notifier from any thread, Stefan Hajnoczi, 2023/05/16
- [PATCH v6 19/20] virtio: do not set is_external=true on host notifiers, Stefan Hajnoczi, 2023/05/16
- [PATCH v6 18/20] virtio-scsi: implement BlockDevOps->drained_begin(), Stefan Hajnoczi, 2023/05/16
- [PATCH v6 20/20] aio: remove aio_disable_external() API, Stefan Hajnoczi, 2023/05/16
- Re: [PATCH v6 00/20] block: remove aio_disable_external() API, Kevin Wolf, 2023/05/30