Commit 663365207c for qemu.org

commit 663365207c90e278131dabd94630e11ea076b747
Author: Denis V. Lunev <den@openvz.org>
Date:   Fri Oct 30 02:06:11 2026 +0100

    util/co-shared-resource: skip the mutex for an empty request

    Getting or putting nothing cannot change the pool, yet both calls take
    the mutex, and co_put_to_shres() also wakes every waiter to find the
    pool unchanged. Return early when n is zero.

    block-copy is about to reserve nothing for write-zeroes tasks the target
    serves without a buffer, which makes such calls the common case for a
    mostly-zero image.

    Suggested-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
    Signed-off-by: Denis V. Lunev <den@openvz.org>
    CC: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
    CC: John Snow <jsnow@redhat.com>
    CC: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
    Message-ID: <20261030010613.1612771-12-den@openvz.org>
    Reviewed-by: Eric Blake <eblake@redhat.com>
    Signed-off-by: Eric Blake <eblake@redhat.com>

diff --git a/util/qemu-co-shared-resource.c b/util/qemu-co-shared-resource.c
index 752eb5a1c5..f9b6af0072 100644
--- a/util/qemu-co-shared-resource.c
+++ b/util/qemu-co-shared-resource.c
@@ -69,6 +69,10 @@ static bool co_try_get_from_shres_locked(SharedResource *s, uint64_t n)
 void coroutine_fn co_get_from_shres(SharedResource *s, uint64_t n)
 {
     assert(n <= s->total);
+    if (!n) {
+        return;
+    }
+
     QEMU_LOCK_GUARD(&s->lock);
     while (!co_try_get_from_shres_locked(s, n)) {
         qemu_co_queue_wait(&s->queue, &s->lock);
@@ -77,6 +81,10 @@ void coroutine_fn co_get_from_shres(SharedResource *s, uint64_t n)

 void coroutine_fn co_put_to_shres(SharedResource *s, uint64_t n)
 {
+    if (!n) {
+        return;
+    }
+
     QEMU_LOCK_GUARD(&s->lock);
     assert(s->total - s->available >= n);
     s->available += n;