[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 21/32] block: add blk_in_drain() API
From: |
Kevin Wolf |
Subject: |
[PULL 21/32] block: add blk_in_drain() API |
Date: |
Tue, 30 May 2023 18:32:28 +0200 |
From: Stefan Hajnoczi <stefanha@redhat.com>
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>
Message-Id: <20230516190238.8401-10-stefanha@redhat.com>
Signed-off-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 2074ac6760..241f643507 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1287,6 +1287,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
- [PULL 26/32] block/export: don't require AioContext lock around blk_exp_ref/unref(), (continued)
- [PULL 26/32] block/export: don't require AioContext lock around blk_exp_ref/unref(), Kevin Wolf, 2023/05/30
- [PULL 22/32] block: drain from main loop thread in bdrv_co_yield_to_drain(), Kevin Wolf, 2023/05/30
- [PULL 30/32] virtio-scsi: implement BlockDevOps->drained_begin(), Kevin Wolf, 2023/05/30
- [PULL 07/32] raw-format: Fix open with 'file' in iothread, Kevin Wolf, 2023/05/30
- [PULL 11/32] iotests: Make verify_virtio_scsi_pci_or_ccw() public, Kevin Wolf, 2023/05/30
- [PULL 09/32] block: Take AioContext lock in bdrv_open_driver(), Kevin Wolf, 2023/05/30
- [PULL 14/32] hw/qdev: introduce qdev_is_realized() helper, Kevin Wolf, 2023/05/30
- [PULL 12/32] iotests: Test blockdev-create in iothread, Kevin Wolf, 2023/05/30
- [PULL 10/32] block: Fix AioContext locking in bdrv_insert_node(), Kevin Wolf, 2023/05/30
- [PULL 23/32] xen-block: implement BlockDevOps->drained_begin(), Kevin Wolf, 2023/05/30
- [PULL 21/32] block: add blk_in_drain() API,
Kevin Wolf <=
- [PULL 13/32] block-backend: split blk_do_set_aio_context(), Kevin Wolf, 2023/05/30
- [PULL 20/32] hw/xen: do not use aio_set_fd_handler(is_external=true) in xen_xenstore, Kevin Wolf, 2023/05/30
- [PULL 25/32] block/export: rewrite vduse-blk drain code, Kevin Wolf, 2023/05/30
- [PULL 27/32] block/fuse: do not set is_external=true on FUSE fd, Kevin Wolf, 2023/05/30
- [PULL 28/32] virtio: make it possible to detach host notifier from any thread, Kevin Wolf, 2023/05/30
- [PULL 31/32] virtio: do not set is_external=true on host notifiers, Kevin Wolf, 2023/05/30
- [PULL 29/32] virtio-blk: implement BlockDevOps->drained_begin(), Kevin Wolf, 2023/05/30
- [PULL 32/32] aio: remove aio_disable_external() API, Kevin Wolf, 2023/05/30
- Re: [PULL 00/32] Block layer patches, Richard Henderson, 2023/05/30