]> git.proxmox.com Git - mirror_qemu.git/commit - block/block-backend.c
block: make BlockBackend->quiesce_counter atomic
authorStefan Hajnoczi <stefanha@redhat.com>
Tue, 7 Mar 2023 21:04:25 +0000 (16:04 -0500)
committerKevin Wolf <kwolf@redhat.com>
Tue, 25 Apr 2023 11:15:21 +0000 (13:15 +0200)
commitc4d5bf99b7fccf8849316b9f5100525b1beb8237
tree9769d9318ce1d33ae3f458555d6f58ee55b071a9
parentac5f7bf8e208cd7893dbb1a9520559e569a4677c
block: make BlockBackend->quiesce_counter atomic

The main loop thread increments/decrements BlockBackend->quiesce_counter
when drained sections begin/end. The counter is read in the I/O code
path. Therefore this field is used to communicate between threads
without a lock.

Acquire/release are not necessary because the BlockBackend->in_flight
counter already uses sequentially consistent accesses and running I/O
requests hold that counter when blk_wait_while_drained() is called.
qatomic_read() can be used.

Use qatomic_fetch_inc()/qatomic_fetch_dec() for modifications even
though sequentially consistent atomic accesses are not strictly required
here. They are, however, nicer to read than multiple calls to
qatomic_read() and qatomic_set(). Since beginning and ending drain is
not a hot path the extra cost doesn't matter.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-Id: <20230307210427.269214-2-stefanha@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block/block-backend.c