[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v6 09/20] block: add blk_in_drain() API
From: |
Stefan Hajnoczi |
Subject: |
[PATCH v6 09/20] block: add blk_in_drain() API |
Date: |
Tue, 16 May 2023 15:02:27 -0400 |
The BlockBackend quiesce_counter is greater than zero during drained
sections. Add an API to check whether the BlockBackend is in a drained
section.
The next patch will use this API.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
---
include/sysemu/block-backend-global-state.h | 1 +
block/block-backend.c | 7 +++++++
2 files changed, 8 insertions(+)
diff --git a/include/sysemu/block-backend-global-state.h
b/include/sysemu/block-backend-global-state.h
index fa83f9389c..184e667ebd 100644
--- a/include/sysemu/block-backend-global-state.h
+++ b/include/sysemu/block-backend-global-state.h
@@ -81,6 +81,7 @@ void blk_activate(BlockBackend *blk, Error **errp);
int blk_make_zero(BlockBackend *blk, BdrvRequestFlags flags);
void blk_aio_cancel(BlockAIOCB *acb);
int blk_commit_all(void);
+bool blk_in_drain(BlockBackend *blk);
void blk_drain(BlockBackend *blk);
void blk_drain_all(void);
void blk_set_on_error(BlockBackend *blk, BlockdevOnError on_read_error,
diff --git a/block/block-backend.c b/block/block-backend.c
index 68087437ac..3a5949ecce 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1270,6 +1270,13 @@ blk_check_byte_request(BlockBackend *blk, int64_t
offset, int64_t bytes)
return 0;
}
+/* Are we currently in a drained section? */
+bool blk_in_drain(BlockBackend *blk)
+{
+ GLOBAL_STATE_CODE(); /* change to IO_OR_GS_CODE(), if necessary */
+ return qatomic_read(&blk->quiesce_counter);
+}
+
/* To be called between exactly one pair of blk_inc/dec_in_flight() */
static void coroutine_fn blk_wait_while_drained(BlockBackend *blk)
{
--
2.40.1
- [PATCH v6 00/20] block: remove aio_disable_external() API, Stefan Hajnoczi, 2023/05/16
- [PATCH v6 01/20] block-backend: split blk_do_set_aio_context(), Stefan Hajnoczi, 2023/05/16
- [PATCH v6 02/20] hw/qdev: introduce qdev_is_realized() helper, Stefan Hajnoczi, 2023/05/16
- [PATCH v6 03/20] virtio-scsi: avoid race between unplug and transport event, Stefan Hajnoczi, 2023/05/16
- [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 <=
- [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, 2023/05/16
- [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