[PATCH v2] chardev/char-socket: Properly make qio connections non blocking

Sai Pavan Boddu posted 1 patch 4 years ago
Test docker-mingw@fedora passed
Test docker-quick@centos7 passed
Test checkpatch passed
Test FreeBSD passed
Test asan passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/1587289900-29485-1-git-send-email-sai.pavan.boddu@xilinx.com
Maintainers: "Marc-André Lureau" <marcandre.lureau@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>
chardev/char-socket.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH v2] chardev/char-socket: Properly make qio connections non blocking
Posted by Sai Pavan Boddu 4 years ago
In tcp_chr_sync_read function, there is a possibility of socket
disconnection during blocking read, then tcp_chr_hup function would clean up
the qio channel pointers(i.e ioc, sioc).

Signed-off-by: Sai Pavan Boddu <sai.pavan.boddu@xilinx.com>
---
Changes for V2:
	Place the guard around 'qio_channel_set_blocking' call to check connection status
	This fix is simpler than v1 and explains better about the issue.

 chardev/char-socket.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index 185fe38..e56b2f0 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -549,7 +549,9 @@ static int tcp_chr_sync_read(Chardev *chr, const uint8_t *buf, int len)
 
     qio_channel_set_blocking(s->ioc, true, NULL);
     size = tcp_chr_recv(chr, (void *) buf, len);
-    qio_channel_set_blocking(s->ioc, false, NULL);
+    if (s->state != TCP_CHARDEV_STATE_DISCONNECTED) {
+        qio_channel_set_blocking(s->ioc, false, NULL);
+    }
     if (size == 0) {
         /* connection closed */
         tcp_chr_disconnect(chr);
-- 
2.7.4


Re: [PATCH v2] chardev/char-socket: Properly make qio connections non blocking
Posted by Daniel P. Berrangé 4 years ago
On Sun, Apr 19, 2020 at 03:21:40PM +0530, Sai Pavan Boddu wrote:
> In tcp_chr_sync_read function, there is a possibility of socket
> disconnection during blocking read, then tcp_chr_hup function would clean up
> the qio channel pointers(i.e ioc, sioc).
> 
> Signed-off-by: Sai Pavan Boddu <sai.pavan.boddu@xilinx.com>
> ---
> Changes for V2:
> 	Place the guard around 'qio_channel_set_blocking' call to check connection status
> 	This fix is simpler than v1 and explains better about the issue.
> 
>  chardev/char-socket.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/chardev/char-socket.c b/chardev/char-socket.c
> index 185fe38..e56b2f0 100644
> --- a/chardev/char-socket.c
> +++ b/chardev/char-socket.c
> @@ -549,7 +549,9 @@ static int tcp_chr_sync_read(Chardev *chr, const uint8_t *buf, int len)
>  
>      qio_channel_set_blocking(s->ioc, true, NULL);
>      size = tcp_chr_recv(chr, (void *) buf, len);
> -    qio_channel_set_blocking(s->ioc, false, NULL);
> +    if (s->state != TCP_CHARDEV_STATE_DISCONNECTED) {
> +        qio_channel_set_blocking(s->ioc, false, NULL);
> +    }
>      if (size == 0) {
>          /* connection closed */
>          tcp_chr_disconnect(chr);

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|


Re: [PATCH v2] chardev/char-socket: Properly make qio connections non blocking
Posted by Paolo Bonzini 4 years ago
On 20/04/20 11:26, Daniel P. Berrangé wrote:
> On Sun, Apr 19, 2020 at 03:21:40PM +0530, Sai Pavan Boddu wrote:
>> In tcp_chr_sync_read function, there is a possibility of socket
>> disconnection during blocking read, then tcp_chr_hup function would clean up
>> the qio channel pointers(i.e ioc, sioc).
>>
>> Signed-off-by: Sai Pavan Boddu <sai.pavan.boddu@xilinx.com>
>> ---
>> Changes for V2:
>> 	Place the guard around 'qio_channel_set_blocking' call to check connection status
>> 	This fix is simpler than v1 and explains better about the issue.
>>
>>  chardev/char-socket.c | 4 +++-
>>  1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/chardev/char-socket.c b/chardev/char-socket.c
>> index 185fe38..e56b2f0 100644
>> --- a/chardev/char-socket.c
>> +++ b/chardev/char-socket.c
>> @@ -549,7 +549,9 @@ static int tcp_chr_sync_read(Chardev *chr, const uint8_t *buf, int len)
>>  
>>      qio_channel_set_blocking(s->ioc, true, NULL);
>>      size = tcp_chr_recv(chr, (void *) buf, len);
>> -    qio_channel_set_blocking(s->ioc, false, NULL);
>> +    if (s->state != TCP_CHARDEV_STATE_DISCONNECTED) {
>> +        qio_channel_set_blocking(s->ioc, false, NULL);
>> +    }
>>      if (size == 0) {
>>          /* connection closed */
>>          tcp_chr_disconnect(chr);
> 
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
> 
> 
> Regards,
> Daniel
> 

Queued, thanks.

Paolo