[PATCH v2 25/26] tests: replace qemu_set_nonblock()

marcandre.lureau@redhat.com posted 26 patches 3 years, 5 months ago
Maintainers: Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>, Gerd Hoffmann <kraxel@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Jason Wang <jasowang@redhat.com>, Eric Blake <eblake@redhat.com>, Vladimir Sementsov-Ogievskiy <v.sementsov-og@mail.ru>, Michael Roth <michael.roth@amd.com>, Alexander Bulekov <alxndr@bu.edu>, Bandan Das <bsd@redhat.com>, Stefan Hajnoczi <stefanha@redhat.com>, Thomas Huth <thuth@redhat.com>, Darren Kenny <darren.kenny@oracle.com>, Qiuhao Li <Qiuhao.Li@outlook.com>, Laurent Vivier <lvivier@redhat.com>, Igor Mammedov <imammedo@redhat.com>, Ani Sinha <ani@anisinha.ca>, John Snow <jsnow@redhat.com>, Fam Zheng <fam@euphon.net>, Peter Maydell <peter.maydell@linaro.org>, "Cédric Le Goater" <clg@kaod.org>, Andrew Jeffery <andrew@aj.id.au>, Joel Stanley <joel@jms.id.au>, Dmitry Fleytman <dmitry.fleytman@gmail.com>, Hannes Reinecke <hare@suse.com>, "Philippe Mathieu-Daudé" <f4bug@amsat.org>, Bin Meng <bin.meng@windriver.com>, Su Hang <suhang16@mails.ucas.ac.cn>, Daniel Henrique Barboza <danielhb413@gmail.com>, David Gibson <david@gibson.dropbear.id.au>, Greg Kurz <groug@kaod.org>, Coiby Xu <Coiby.Xu@gmail.com>, Juan Quintela <quintela@redhat.com>, "Dr. David Alan Gilbert" <dgilbert@redhat.com>, Havard Skinnemoen <hskinnemoen@google.com>, Tyrone Ting <kfting@nuvoton.com>, Keith Busch <kbusch@kernel.org>, Klaus Jensen <its@irrelevant.dk>, Markus Armbruster <armbru@redhat.com>, Zhang Chen <chen.zhang@intel.com>, Li Zhijian <lizhijian@fujitsu.com>, Stefan Berger <stefanb@linux.vnet.ibm.com>, Amit Shah <amit@kernel.org>, Vikram Garhwal <fnu.vikram@xilinx.com>, Francisco Iglesias <francisco.iglesias@xilinx.com>, Stefan Weil <sw@weilnetz.de>
There is a newer version of this series
[PATCH v2 25/26] tests: replace qemu_set_nonblock()
Posted by marcandre.lureau@redhat.com 3 years, 5 months ago
From: Marc-André Lureau <marcandre.lureau@redhat.com>

The call is POSIX-specific. Use the dedicated GLib API.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 tests/qtest/vhost-user-test.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c
index ee30f5479648..a2cec8768462 100644
--- a/tests/qtest/vhost-user-test.c
+++ b/tests/qtest/vhost-user-test.c
@@ -302,6 +302,7 @@ static int chr_can_read(void *opaque)
 
 static void chr_read(void *opaque, const uint8_t *buf, int size)
 {
+    g_autoptr(GError) err = NULL;
     TestServer *s = opaque;
     CharBackend *chr = &s->chr;
     VhostUserMsg msg;
@@ -394,7 +395,8 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)
          * The receive function forces it to be blocking,
          * so revert it back to non-blocking.
          */
-        qemu_set_nonblock(fd);
+        g_unix_set_fd_nonblocking(fd, true, &err);
+        g_assert_no_error(err);
         break;
 
     case VHOST_USER_SET_LOG_BASE:
-- 
2.36.0


Re: [PATCH v2 25/26] tests: replace qemu_set_nonblock()
Posted by Daniel P. Berrangé 3 years, 4 months ago
On Tue, Apr 26, 2022 at 01:27:14PM +0400, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> The call is POSIX-specific. Use the dedicated GLib API.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  tests/qtest/vhost-user-test.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

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


With 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 25/26] tests: replace qemu_set_nonblock()
Posted by Thomas Huth 3 years, 5 months ago
On 26/04/2022 11.27, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> The call is POSIX-specific. Use the dedicated GLib API.

g_unix_set_fd_nonblocking() is also available on Unix-like systems according 
to its name, I suppose? So what's the advantage of this change?

  Thomas


> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>   tests/qtest/vhost-user-test.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c
> index ee30f5479648..a2cec8768462 100644
> --- a/tests/qtest/vhost-user-test.c
> +++ b/tests/qtest/vhost-user-test.c
> @@ -302,6 +302,7 @@ static int chr_can_read(void *opaque)
>   
>   static void chr_read(void *opaque, const uint8_t *buf, int size)
>   {
> +    g_autoptr(GError) err = NULL;
>       TestServer *s = opaque;
>       CharBackend *chr = &s->chr;
>       VhostUserMsg msg;
> @@ -394,7 +395,8 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)
>            * The receive function forces it to be blocking,
>            * so revert it back to non-blocking.
>            */
> -        qemu_set_nonblock(fd);
> +        g_unix_set_fd_nonblocking(fd, true, &err);
> +        g_assert_no_error(err);
>           break;
>   
>       case VHOST_USER_SET_LOG_BASE:


Re: [PATCH v2 25/26] tests: replace qemu_set_nonblock()
Posted by Marc-André Lureau 3 years, 5 months ago
Hi

On Wed, Apr 27, 2022 at 1:41 PM Thomas Huth <thuth@redhat.com> wrote:
>
> On 26/04/2022 11.27, marcandre.lureau@redhat.com wrote:
> > From: Marc-André Lureau <marcandre.lureau@redhat.com>
> >
> > The call is POSIX-specific. Use the dedicated GLib API.
>
> g_unix_set_fd_nonblocking() is also available on Unix-like systems according
> to its name, I suppose? So what's the advantage of this change?
>

This is a preliminary patch before the last patch
(https://patchew.org/QEMU/20220426092715.3931705-1-marcandre.lureau@redhat.com/20220426092715.3931705-27-marcandre.lureau@redhat.com/)

We should reserve qemu_socket_set_*block() usage to socket-like fd.

thanks


>   Thomas
>
>
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >   tests/qtest/vhost-user-test.c | 4 +++-
> >   1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c
> > index ee30f5479648..a2cec8768462 100644
> > --- a/tests/qtest/vhost-user-test.c
> > +++ b/tests/qtest/vhost-user-test.c
> > @@ -302,6 +302,7 @@ static int chr_can_read(void *opaque)
> >
> >   static void chr_read(void *opaque, const uint8_t *buf, int size)
> >   {
> > +    g_autoptr(GError) err = NULL;
> >       TestServer *s = opaque;
> >       CharBackend *chr = &s->chr;
> >       VhostUserMsg msg;
> > @@ -394,7 +395,8 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)
> >            * The receive function forces it to be blocking,
> >            * so revert it back to non-blocking.
> >            */
> > -        qemu_set_nonblock(fd);
> > +        g_unix_set_fd_nonblocking(fd, true, &err);
> > +        g_assert_no_error(err);
> >           break;
> >
> >       case VHOST_USER_SET_LOG_BASE:
>
Re: [PATCH v2 25/26] tests: replace qemu_set_nonblock()
Posted by Thomas Huth 3 years, 5 months ago
On 27/04/2022 12.33, Marc-André Lureau wrote:
> Hi
> 
> On Wed, Apr 27, 2022 at 1:41 PM Thomas Huth <thuth@redhat.com> wrote:
>>
>> On 26/04/2022 11.27, marcandre.lureau@redhat.com wrote:
>>> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>>>
>>> The call is POSIX-specific. Use the dedicated GLib API.
>>
>> g_unix_set_fd_nonblocking() is also available on Unix-like systems according
>> to its name, I suppose? So what's the advantage of this change?
>>
> 
> This is a preliminary patch before the last patch
> (https://patchew.org/QEMU/20220426092715.3931705-1-marcandre.lureau@redhat.com/20220426092715.3931705-27-marcandre.lureau@redhat.com/)
> 
> We should reserve qemu_socket_set_*block() usage to socket-like fd.

Ok, makes sense now, thanks.

Reviewed-by: Thomas Huth <thuth@redhat.com>

PS: In case you respin, it might make sense to add a sentence à la "We're 
going to limit qemu_set_nonblock() to sockets only" to the commit description.