qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Vladimir Sementsov-Ogievskiy <v.sementsov-og@mail.ru>,
	qemu-devel@nongnu.org
Cc: eblake@redhat.com
Subject: Re: [PATCH v2 for-7.1 4/9] nbd: keep send_mutex/free_sema handling outside nbd_co_do_establish_connection
Date: Sat, 23 Apr 2022 10:34:54 +0200	[thread overview]
Message-ID: <8c4199f9-96ed-f1e7-4f89-cf599c95f552@redhat.com> (raw)
In-Reply-To: <db1afb67-5d7a-5c98-1564-6a3a637d138f@mail.ru>

On 4/16/22 13:54, Vladimir Sementsov-Ogievskiy wrote:
>> @@ -187,9 +187,6 @@ static void reconnect_delay_timer_cb(void *opaque)
>>       if (qatomic_load_acquire(&s->state) == 
>> NBD_CLIENT_CONNECTING_WAIT) {
>>           s->state = NBD_CLIENT_CONNECTING_NOWAIT;
>>           nbd_co_establish_connection_cancel(s->conn);
>> -        while (qemu_co_enter_next(&s->free_sema, NULL)) {
>> -            /* Resume all queued requests */
>> -        }
>>       }
>>       reconnect_delay_timer_del(s);
> 
> Seems, removing the timer is not needed here too. We do 
> nbd_co_establish_connection_cancel(), and timer will be removed in 
> nbd_reconnect_attempt anyway.
> 
> More over, we don't need to keep timer in the state at all: it should 
> become local thing for nbd_reconnect_attempt. A kind of call 
> nbd_co_do_establish_connection() with timeout. That could be refactored 
> later, using same way as in 4-5 patches of my "[PATCH v4 0/7] 
> copy-before-write: on-cbw-error and cbw-timeout" series.

Yes, good point.

>> nbd_reconnect_attempt(BDRVNBDState *s)
>>           s->ioc = NULL;
>>       }
>> -    nbd_co_do_establish_connection(s->bs, NULL);
>> +    qemu_co_mutex_unlock(&s->send_mutex);
>> +    nbd_co_do_establish_connection(s->bs, blocking, NULL);
>> +    qemu_co_mutex_lock(&s->send_mutex);
> 
> 
> Hmm. So, that breaks a critical section.
> 
> We can do it because in_flight=1 and we are not connected => all other 
> requests will wait in the queue.
> 
> Still. during nbd_co_do_establish_connection() state may become 
> CONNECTED. That theoretically means that parallel requests may start.
> 
> Is it bad? Seems not.. Bad thing that comes into my mind is that 
> parallel request fails, and go to reconnect, and start own timer, but we 
> remove it now after locking the mutex back. But that's not possible as 
> parallel request should wait for in-flight=0 to start own 
> reconnect-attempt. And that is not possible, as we keep our in-flight 
> point.

Yes that was even intended. :>  Synchronizing on in_flight == 0 before 
reconnecting is the important bit that simplifies a lot of things.

>> @@ -2049,7 +2046,6 @@ static void 
>> nbd_cancel_in_flight(BlockDriverState *bs)
>>       if (s->state == NBD_CLIENT_CONNECTING_WAIT) {
>>           s->state = NBD_CLIENT_CONNECTING_NOWAIT;
>> -        qemu_co_queue_restart_all(&s->free_sema);
> 
> As I understand, we always have one request running (or no requests at 
> all, but that's OK too) and it will wake all others (altogether, or they 
> will wake each other in a chain). So, we don't need to wake them here.

Exactly, the "let each coroutine wake up the next one" pattern can be 
generalized to the error cases because the wakeups cascade until 
in_flight becomes 0.

Paolo

>>       }
>>       nbd_co_establish_connection_cancel(s->conn);
> 
> 



  reply	other threads:[~2022-04-23  8:36 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-14 17:57 [PATCH v2 for-7.1 0/9] nbd: actually make s->state thread-safe Paolo Bonzini
2022-04-14 17:57 ` [PATCH v2 for-7.1 1/9] nbd: safeguard against waking up invalid coroutine Paolo Bonzini
2022-04-14 19:02   ` Eric Blake
2022-04-15  9:53   ` Vladimir Sementsov-Ogievskiy
2022-04-14 17:57 ` [PATCH v2 for-7.1 2/9] nbd: mark more coroutine_fns Paolo Bonzini
2022-04-15 10:12   ` Vladimir Sementsov-Ogievskiy
2022-04-14 17:57 ` [PATCH v2 for-7.1 3/9] nbd: remove peppering of nbd_client_connected Paolo Bonzini
2022-04-15 17:01   ` Vladimir Sementsov-Ogievskiy
2022-04-23  8:30     ` Paolo Bonzini
2022-04-14 17:57 ` [PATCH v2 for-7.1 4/9] nbd: keep send_mutex/free_sema handling outside nbd_co_do_establish_connection Paolo Bonzini
2022-04-14 19:11   ` Eric Blake
2022-04-16 11:54   ` Vladimir Sementsov-Ogievskiy
2022-04-23  8:34     ` Paolo Bonzini [this message]
2022-04-14 17:57 ` [PATCH v2 for-7.1 5/9] nbd: use a QemuMutex to synchronize yanking, reconnection and coroutines Paolo Bonzini
2022-04-14 19:33   ` Eric Blake
2022-04-16 12:18   ` Vladimir Sementsov-Ogievskiy
2022-04-23  8:37     ` Paolo Bonzini
2022-04-14 17:57 ` [PATCH v2 for-7.1 6/9] nbd: code motion and function renaming Paolo Bonzini
2022-04-14 19:37   ` Eric Blake
2022-04-16 12:37   ` Vladimir Sementsov-Ogievskiy
2022-04-23  8:38     ` Paolo Bonzini
2022-04-14 17:57 ` [PATCH v2 for-7.1 7/9] nbd: move s->state under requests_lock Paolo Bonzini
2022-04-14 19:40   ` Eric Blake
2022-04-16 13:37   ` Vladimir Sementsov-Ogievskiy
2022-04-14 17:57 ` [PATCH v2 for-7.1 8/9] nbd: take receive_mutex when reading requests[].receiving Paolo Bonzini
2022-04-14 19:42   ` Eric Blake
2022-04-16 13:54   ` Vladimir Sementsov-Ogievskiy
2022-04-14 17:57 ` [PATCH v2 for-7.1 9/9] nbd: document what is protected by the CoMutexes Paolo Bonzini
2022-04-14 19:42   ` Eric Blake
2022-04-16 14:00   ` Vladimir Sementsov-Ogievskiy
2022-04-23  8:41     ` Paolo Bonzini
2022-04-16 19:03 ` [PATCH v2 for-7.1 0/9] nbd: actually make s->state thread-safe Lukas Straub
2022-04-22 20:39   ` Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8c4199f9-96ed-f1e7-4f89-cf599c95f552@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=eblake@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=v.sementsov-og@mail.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).