diff mbox series

[2/2] Allow building vhost-user in BSD

Message ID 20220302113644.43717-3-slp@redhat.com (mailing list archive)
State New, archived
Headers show
Series Enable vhost-user to be used on BSD systems | expand

Commit Message

Sergio Lopez March 2, 2022, 11:36 a.m. UTC
With the possibility of using pipefd as a replacement on operating
systems that doesn't support eventfd, vhost-user can also work on BSD
systems.

This change allows enabling vhost-user on BSD platforms too and
makes libvhost_user (which still depends on eventfd) a linux-only
feature.

Signed-off-by: Sergio Lopez <slp@redhat.com>
---
 configure   | 5 +++--
 meson.build | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

Comments

Paolo Bonzini March 2, 2022, 5:10 p.m. UTC | #1
On 3/2/22 12:36, Sergio Lopez wrote:
> With the possibility of using pipefd as a replacement on operating
> systems that doesn't support eventfd, vhost-user can also work on BSD
> systems.
> 
> This change allows enabling vhost-user on BSD platforms too and
> makes libvhost_user (which still depends on eventfd) a linux-only
> feature.
> 
> Signed-off-by: Sergio Lopez <slp@redhat.com>

I would just check for !windows.

Paolo

> ---
>   configure   | 5 +++--
>   meson.build | 2 +-
>   2 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/configure b/configure
> index c56ed53ee3..93aa22e345 100755
> --- a/configure
> +++ b/configure
> @@ -1659,8 +1659,9 @@ fi
>   # vhost interdependencies and host support
>   
>   # vhost backends
> -if test "$vhost_user" = "yes" && test "$linux" != "yes"; then
> -  error_exit "vhost-user is only available on Linux"
> +if test "$vhost_user" = "yes" && \
> +    test "$linux" != "yes" && test "$bsd" != "yes" ; then
> +  error_exit "vhost-user is only available on Linux and BSD"
>   fi
>   test "$vhost_vdpa" = "" && vhost_vdpa=$linux
>   if test "$vhost_vdpa" = "yes" && test "$linux" != "yes"; then
> diff --git a/meson.build b/meson.build
> index 8df40bfac4..f2bc439c30 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -2701,7 +2701,7 @@ if have_system or have_user
>   endif
>   
>   vhost_user = not_found
> -if 'CONFIG_VHOST_USER' in config_host
> +if targetos == 'linux' and 'CONFIG_VHOST_USER' in config_host
>     libvhost_user = subproject('libvhost-user')
>     vhost_user = libvhost_user.get_variable('vhost_user_dep')
>   endif
Philippe Mathieu-Daudé March 2, 2022, 5:18 p.m. UTC | #2
On 2/3/22 18:10, Paolo Bonzini wrote:
> On 3/2/22 12:36, Sergio Lopez wrote:
>> With the possibility of using pipefd as a replacement on operating
>> systems that doesn't support eventfd, vhost-user can also work on BSD
>> systems.
>>
>> This change allows enabling vhost-user on BSD platforms too and
>> makes libvhost_user (which still depends on eventfd) a linux-only
>> feature.
>>
>> Signed-off-by: Sergio Lopez <slp@redhat.com>
> 
> I would just check for !windows.

What about Darwin / Haiku / Illumnos?
Sergio Lopez March 2, 2022, 5:31 p.m. UTC | #3
On Wed, Mar 02, 2022 at 06:18:59PM +0100, Philippe Mathieu-Daudé wrote:
> On 2/3/22 18:10, Paolo Bonzini wrote:
> > On 3/2/22 12:36, Sergio Lopez wrote:
> > > With the possibility of using pipefd as a replacement on operating
> > > systems that doesn't support eventfd, vhost-user can also work on BSD
> > > systems.
> > > 
> > > This change allows enabling vhost-user on BSD platforms too and
> > > makes libvhost_user (which still depends on eventfd) a linux-only
> > > feature.
> > > 
> > > Signed-off-by: Sergio Lopez <slp@redhat.com>
> > 
> > I would just check for !windows.
> 
> What about Darwin / Haiku / Illumnos?

It should work on every system providing pipe() or pipe2(), so I guess
Paolo's right, every platform except Windows. FWIW, I already tested
it with Darwin.

Thanks,
Sergio.
Philippe Mathieu-Daudé March 2, 2022, 5:38 p.m. UTC | #4
On 2/3/22 18:31, Sergio Lopez wrote:
> On Wed, Mar 02, 2022 at 06:18:59PM +0100, Philippe Mathieu-Daudé wrote:
>> On 2/3/22 18:10, Paolo Bonzini wrote:
>>> On 3/2/22 12:36, Sergio Lopez wrote:
>>>> With the possibility of using pipefd as a replacement on operating
>>>> systems that doesn't support eventfd, vhost-user can also work on BSD
>>>> systems.
>>>>
>>>> This change allows enabling vhost-user on BSD platforms too and
>>>> makes libvhost_user (which still depends on eventfd) a linux-only
>>>> feature.
>>>>
>>>> Signed-off-by: Sergio Lopez <slp@redhat.com>
>>>
>>> I would just check for !windows.
>>
>> What about Darwin / Haiku / Illumnos?
> 
> It should work on every system providing pipe() or pipe2(), so I guess
> Paolo's right, every platform except Windows. FWIW, I already tested
> it with Darwin.

Wow, nice.

So maybe simply check for pipe/pipe2 rather than !windows?
Sergio Lopez March 2, 2022, 5:49 p.m. UTC | #5
On Wed, Mar 02, 2022 at 06:38:07PM +0100, Philippe Mathieu-Daudé wrote:
> On 2/3/22 18:31, Sergio Lopez wrote:
> > On Wed, Mar 02, 2022 at 06:18:59PM +0100, Philippe Mathieu-Daudé wrote:
> > > On 2/3/22 18:10, Paolo Bonzini wrote:
> > > > On 3/2/22 12:36, Sergio Lopez wrote:
> > > > > With the possibility of using pipefd as a replacement on operating
> > > > > systems that doesn't support eventfd, vhost-user can also work on BSD
> > > > > systems.
> > > > > 
> > > > > This change allows enabling vhost-user on BSD platforms too and
> > > > > makes libvhost_user (which still depends on eventfd) a linux-only
> > > > > feature.
> > > > > 
> > > > > Signed-off-by: Sergio Lopez <slp@redhat.com>
> > > > 
> > > > I would just check for !windows.
> > > 
> > > What about Darwin / Haiku / Illumnos?
> > 
> > It should work on every system providing pipe() or pipe2(), so I guess
> > Paolo's right, every platform except Windows. FWIW, I already tested
> > it with Darwin.
> 
> Wow, nice.
> 
> So maybe simply check for pipe/pipe2 rather than !windows?
> 

Is it worth it? In "configure", CONFIG_POSIX is set to "y" if the
target isn't "mingw32", and CONFIG_POSIX brings "util/oslib-posix.c"
into the build, which expects to have either pipe or pipe2.

Thanks,
Sergio.
Daniel P. Berrangé March 2, 2022, 5:55 p.m. UTC | #6
On Wed, Mar 02, 2022 at 06:38:07PM +0100, Philippe Mathieu-Daudé wrote:
> On 2/3/22 18:31, Sergio Lopez wrote:
> > On Wed, Mar 02, 2022 at 06:18:59PM +0100, Philippe Mathieu-Daudé wrote:
> > > On 2/3/22 18:10, Paolo Bonzini wrote:
> > > > On 3/2/22 12:36, Sergio Lopez wrote:
> > > > > With the possibility of using pipefd as a replacement on operating
> > > > > systems that doesn't support eventfd, vhost-user can also work on BSD
> > > > > systems.
> > > > > 
> > > > > This change allows enabling vhost-user on BSD platforms too and
> > > > > makes libvhost_user (which still depends on eventfd) a linux-only
> > > > > feature.
> > > > > 
> > > > > Signed-off-by: Sergio Lopez <slp@redhat.com>
> > > > 
> > > > I would just check for !windows.
> > > 
> > > What about Darwin / Haiku / Illumnos?
> > 
> > It should work on every system providing pipe() or pipe2(), so I guess
> > Paolo's right, every platform except Windows. FWIW, I already tested
> > it with Darwin.
> 
> Wow, nice.
> 
> So maybe simply check for pipe/pipe2 rather than !windows?

NB that would make the check more fragile.

We already use pipe/pipe2 without checking for it, because its
usage is confined to oslib-posix.c and we know all POSIX
OS have it. There is no impl at all of qemu_pipe in oslib-win.c
and the declaration is masked out too in the header file.

Thus if we check for pipe2 and windows did ever implement it,
then we would actually break the windows build due to qemu_pipe
not existing. 

IOW, checking !windows matches our logic for picking oslib-posix.c
in builds and so is better than checking for pipe directly.

Regards,
Daniel
Paolo Bonzini March 2, 2022, 6:05 p.m. UTC | #7
On 3/2/22 18:38, Philippe Mathieu-Daudé wrote:
> On 2/3/22 18:31, Sergio Lopez wrote:
>> On Wed, Mar 02, 2022 at 06:18:59PM +0100, Philippe Mathieu-Daudé wrote:
>>> On 2/3/22 18:10, Paolo Bonzini wrote:
>>>> On 3/2/22 12:36, Sergio Lopez wrote:
>>>>> With the possibility of using pipefd as a replacement on operating
>>>>> systems that doesn't support eventfd, vhost-user can also work on BSD
>>>>> systems.
>>>>>
>>>>> This change allows enabling vhost-user on BSD platforms too and
>>>>> makes libvhost_user (which still depends on eventfd) a linux-only
>>>>> feature.
>>>>>
>>>>> Signed-off-by: Sergio Lopez <slp@redhat.com>
>>>>
>>>> I would just check for !windows.
>>>
>>> What about Darwin / Haiku / Illumnos?
>>
>> It should work on every system providing pipe() or pipe2(), so I guess
>> Paolo's right, every platform except Windows. FWIW, I already tested
>> it with Darwin.
> 
> Wow, nice.
> 
> So maybe simply check for pipe/pipe2 rather than !windows?

What you really need is not pipes, but AF_UNIX.

Paolo
Daniel P. Berrangé March 2, 2022, 6:26 p.m. UTC | #8
On Wed, Mar 02, 2022 at 07:05:32PM +0100, Paolo Bonzini wrote:
> On 3/2/22 18:38, Philippe Mathieu-Daudé wrote:
> > On 2/3/22 18:31, Sergio Lopez wrote:
> > > On Wed, Mar 02, 2022 at 06:18:59PM +0100, Philippe Mathieu-Daudé wrote:
> > > > On 2/3/22 18:10, Paolo Bonzini wrote:
> > > > > On 3/2/22 12:36, Sergio Lopez wrote:
> > > > > > With the possibility of using pipefd as a replacement on operating
> > > > > > systems that doesn't support eventfd, vhost-user can also work on BSD
> > > > > > systems.
> > > > > > 
> > > > > > This change allows enabling vhost-user on BSD platforms too and
> > > > > > makes libvhost_user (which still depends on eventfd) a linux-only
> > > > > > feature.
> > > > > > 
> > > > > > Signed-off-by: Sergio Lopez <slp@redhat.com>
> > > > > 
> > > > > I would just check for !windows.
> > > > 
> > > > What about Darwin / Haiku / Illumnos?
> > > 
> > > It should work on every system providing pipe() or pipe2(), so I guess
> > > Paolo's right, every platform except Windows. FWIW, I already tested
> > > it with Darwin.
> > 
> > Wow, nice.
> > 
> > So maybe simply check for pipe/pipe2 rather than !windows?
> 
> What you really need is not pipes, but AF_UNIX.

Recent Windows has AF_UNIX so don't check for that ! What you really
need is AF_UNIX and FD passing and pipes and probably more POSIX
only features ...

Regards,
Daniel
Philippe Mathieu-Daudé March 2, 2022, 7:22 p.m. UTC | #9
On 2/3/22 18:55, Daniel P. Berrangé wrote:
> On Wed, Mar 02, 2022 at 06:38:07PM +0100, Philippe Mathieu-Daudé wrote:
>> On 2/3/22 18:31, Sergio Lopez wrote:
>>> On Wed, Mar 02, 2022 at 06:18:59PM +0100, Philippe Mathieu-Daudé wrote:
>>>> On 2/3/22 18:10, Paolo Bonzini wrote:
>>>>> On 3/2/22 12:36, Sergio Lopez wrote:
>>>>>> With the possibility of using pipefd as a replacement on operating
>>>>>> systems that doesn't support eventfd, vhost-user can also work on BSD
>>>>>> systems.
>>>>>>
>>>>>> This change allows enabling vhost-user on BSD platforms too and
>>>>>> makes libvhost_user (which still depends on eventfd) a linux-only
>>>>>> feature.
>>>>>>
>>>>>> Signed-off-by: Sergio Lopez <slp@redhat.com>
>>>>>
>>>>> I would just check for !windows.
>>>>
>>>> What about Darwin / Haiku / Illumnos?
>>>
>>> It should work on every system providing pipe() or pipe2(), so I guess
>>> Paolo's right, every platform except Windows. FWIW, I already tested
>>> it with Darwin.
>>
>> Wow, nice.
>>
>> So maybe simply check for pipe/pipe2 rather than !windows?
> 
> NB that would make the check more fragile.
> 
> We already use pipe/pipe2 without checking for it, because its
> usage is confined to oslib-posix.c and we know all POSIX
> OS have it. There is no impl at all of qemu_pipe in oslib-win.c
> and the declaration is masked out too in the header file.
> 
> Thus if we check for pipe2 and windows did ever implement it,
> then we would actually break the windows build due to qemu_pipe
> not existing.
> 
> IOW, checking !windows matches our logic for picking oslib-posix.c
> in builds and so is better than checking for pipe directly.

OK I see, thanks.
diff mbox series

Patch

diff --git a/configure b/configure
index c56ed53ee3..93aa22e345 100755
--- a/configure
+++ b/configure
@@ -1659,8 +1659,9 @@  fi
 # vhost interdependencies and host support
 
 # vhost backends
-if test "$vhost_user" = "yes" && test "$linux" != "yes"; then
-  error_exit "vhost-user is only available on Linux"
+if test "$vhost_user" = "yes" && \
+    test "$linux" != "yes" && test "$bsd" != "yes" ; then
+  error_exit "vhost-user is only available on Linux and BSD"
 fi
 test "$vhost_vdpa" = "" && vhost_vdpa=$linux
 if test "$vhost_vdpa" = "yes" && test "$linux" != "yes"; then
diff --git a/meson.build b/meson.build
index 8df40bfac4..f2bc439c30 100644
--- a/meson.build
+++ b/meson.build
@@ -2701,7 +2701,7 @@  if have_system or have_user
 endif
 
 vhost_user = not_found
-if 'CONFIG_VHOST_USER' in config_host
+if targetos == 'linux' and 'CONFIG_VHOST_USER' in config_host
   libvhost_user = subproject('libvhost-user')
   vhost_user = libvhost_user.get_variable('vhost_user_dep')
 endif