[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-block] [Qemu-devel] [PATCH 06/11] nbd: make it thread-safe
From: |
Eric Blake |
Subject: |
Re: [Qemu-block] [Qemu-devel] [PATCH 06/11] nbd: make it thread-safe |
Date: |
Wed, 31 May 2017 16:20:38 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 |
On 05/31/2017 04:43 AM, Paolo Bonzini wrote:
> Signed-off-by: Paolo Bonzini <address@hidden>
> ---
> block/nbd-client.c | 30 +++++++++---------------------
> 1 file changed, 9 insertions(+), 21 deletions(-)
>
> diff --git a/block/nbd-client.c b/block/nbd-client.c
> index 1e2952fdae..43e0292ac1 100644
> --- a/block/nbd-client.c
> +++ b/block/nbd-client.c
> @@ -114,6 +114,10 @@ static int nbd_co_send_request(BlockDriverState *bs,
> int rc, ret, i;
>
> qemu_co_mutex_lock(&s->send_mutex);
> + while (s->in_flight == MAX_NBD_REQUESTS) {
> + qemu_co_queue_wait(&s->free_sema, &s->send_mutex);
> + }
> + s->in_flight++;
Nice - if I'm not mistaken, this also solves
https://bugzilla.redhat.com/show_bug.cgi?id=1454582 - you have a while
loop here...
> -static void nbd_coroutine_start(NBDClientSession *s,
> - NBDRequest *request)
> -{
> - /* Poor man semaphore. The free_sema is locked when no other request
> - * can be accepted, and unlocked after receiving one reply. */
> - if (s->in_flight == MAX_NBD_REQUESTS) {
> - qemu_co_queue_wait(&s->free_sema, NULL);
> - assert(s->in_flight < MAX_NBD_REQUESTS);
> - }
...compared to the old code that only tried once, and could therefore
hit the assertion failure depending on thread load.
Reviewed-by: Eric Blake <address@hidden>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature
- Re: [Qemu-block] [Qemu-devel] [PATCH 01/11] qcow2: call CoQueue APIs under CoMutex, (continued)
- [Qemu-block] [PATCH 03/11] vdi: make it thread-safe, Paolo Bonzini, 2017/05/31
- [Qemu-block] [PATCH 02/11] coroutine-lock: add qemu_co_rwlock_downgrade and qemu_co_rwlock_upgrade, Paolo Bonzini, 2017/05/31
- [Qemu-block] [PATCH 04/11] vpc: make it thread-safe, Paolo Bonzini, 2017/05/31
- [Qemu-block] [PATCH 05/11] vvfat: make it thread-safe, Paolo Bonzini, 2017/05/31
- [Qemu-block] [PATCH 06/11] nbd: make it thread-safe, Paolo Bonzini, 2017/05/31
- Re: [Qemu-block] [Qemu-devel] [PATCH 06/11] nbd: make it thread-safe,
Eric Blake <=
- [Qemu-block] [PATCH 07/11] qed: move tail of qed_aio_write_main to qed_aio_write_{cow, alloc}, Paolo Bonzini, 2017/05/31
- [Qemu-block] [PATCH 08/11] block: invoke .bdrv_drain callback in coroutine context and from AioContext, Paolo Bonzini, 2017/05/31
- [Qemu-block] [PATCH 10/11] sheepdog: add queue_lock, Paolo Bonzini, 2017/05/31
- [Qemu-block] [PATCH 11/11] ssh: support I/O from any AioContext, Paolo Bonzini, 2017/05/31
- [Qemu-block] [PATCH 09/11] qed: protect table cache with CoMutex, Paolo Bonzini, 2017/05/31