]> git.proxmox.com Git - mirror_qemu.git/commitdiff
block: add blk_in_drain() API
authorStefan Hajnoczi <stefanha@redhat.com>
Tue, 16 May 2023 19:02:27 +0000 (15:02 -0400)
committerKevin Wolf <kwolf@redhat.com>
Tue, 30 May 2023 15:32:02 +0000 (17:32 +0200)
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>
block/block-backend.c
include/sysemu/block-backend-global-state.h

index 2074ac6760c1804457ba002fa8c8eba1f4d5609b..241f6435074a03cab809bde0f26fb8568db9d90e 100644 (file)
@@ -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)
 {
index fa83f9389c3caf6237274104b411ea2b9eb5df79..184e667ebd8929ac71df9666bfa5ccac800694e2 100644 (file)
@@ -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,