On 04.05.21 10:25, Vladimir Sementsov-Ogievskiy wrote:
Instead of relying on aio context lock, let's make use of atomic
operations.
The tricky place is bdrv_write_threshold_check_write(): we want
atomically unset bs->write_threshold_offset iff
offset + bytes > bs->write_threshold_offset
We don't have such atomic operation, so let's go in a loop:
This could also be solved by untangling the overloaded meaning of
write_threshold_offset – if we had an additional boolean
write_threshold_check, then this wouldn’t be a problem, and we could do
this:
if (end > bdrv_write_threshold_get(bs)) {
if (qatomic_xchg(&bs->write_threshold_check, false) == true) {
qapi_event_send(...);
}
}
However, the problem then becomes thinking about the memory access
semantics, because if some other thread sets the threshold offset and
enables the threshold check, we need to ensure that we see the updated
offset here...
So I suppose your loop is simpler then.
1. fetch wtr atomically
2. if condition satisfied, try cmpxchg (if not satisfied, we are done,
don't send event)
3. if cmpxchg succeeded, we are done (send event), else go to [1]
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsement...@virtuozzo.com>
---
block/write-threshold.c | 32 +++++++++++++++++---------------
1 file changed, 17 insertions(+), 15 deletions(-)
Reviewed-by: Max Reitz <mre...@redhat.com>