diff mbox series

[2/2] meson: move libmpathpersist test

Message ID 20200916162621.100141-3-pbonzini@redhat.com
State New
Headers show
Series meson: move libmpathpersist test | expand

Commit Message

Paolo Bonzini Sept. 16, 2020, 4:26 p.m. UTC
This is the first compiler/linker test that has been moved to Meson.
Add more section headings to keep things clearer.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 configure         | 77 +++------------------------------------------
 meson.build       | 80 ++++++++++++++++++++++++++++++++++++++++++-----
 meson_options.txt |  2 ++
 3 files changed, 78 insertions(+), 81 deletions(-)

Comments

Thomas Huth Sept. 16, 2020, 5:09 p.m. UTC | #1
On 16/09/2020 18.26, Paolo Bonzini wrote:
> This is the first compiler/linker test that has been moved to Meson.

> Add more section headings to keep things clearer.

> 

> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

> ---

>  configure         | 77 +++------------------------------------------

>  meson.build       | 80 ++++++++++++++++++++++++++++++++++++++++++-----

>  meson_options.txt |  2 ++

>  3 files changed, 78 insertions(+), 81 deletions(-)

[...]
> diff --git a/meson.build b/meson.build

> index 5092aec439..60ef988d9d 100644

> --- a/meson.build

> +++ b/meson.build

> @@ -86,6 +86,14 @@ if 'SPARSE_CFLAGS' in config_host

>                         'compile_commands.json'])

>  endif

>  

> +###########################################

> +# Target-specific checks and dependencies #

> +###########################################

> +

> +if targetos != 'linux' and get_option('mpath').enabled()

> +  error('Multipath is supported only on Linux')

> +endif

> +

>  m = cc.find_library('m', required: false)

>  util = cc.find_library('util', required: false)

>  winmm = []

> @@ -117,6 +125,11 @@ elif targetos == 'haiku'

>              cc.find_library('network'),

>              cc.find_library('bsd')]

>  endif

> +

> +################

> +# Dependencies #

> +################

> +

>  # The path to glib.h is added to all compilation commands.  This was

>  # grandfathered in from the QEMU Makefiles.

>  add_project_arguments(config_host['GLIB_CFLAGS'].split(),

> @@ -223,10 +236,6 @@ if 'CONFIG_SPICE' in config_host

>                               link_args: config_host['SPICE_LIBS'].split())

>  endif

>  rt = cc.find_library('rt', required: false)

> -libmpathpersist = not_found

> -if config_host.has_key('CONFIG_MPATH')

> -  libmpathpersist = cc.find_library('mpathpersist')

> -endif

>  libdl = not_found

>  if 'CONFIG_PLUGIN' in config_host

>    libdl = cc.find_library('dl', required: true)

> @@ -257,9 +266,62 @@ if 'CONFIG_CURL' in config_host

>                              link_args: config_host['CURL_LIBS'].split())

>  endif

>  libudev = not_found

> -if target_os == 'linux'

> -  libudev = dependency('libudev', static: enable_static)

> +if targetos == 'linux'

> +  libudev = dependency('libudev',

> +                       required: get_option('mpath'),

> +                       static: enable_static)

> +endif

> +

> +mpathpersist = not_found

> +if targetos == 'linux' and not get_option('mpath').disabled()

> +  libmultipath = cc.find_library('multipath',

> +                                 required: get_option('mpath'),

> +                                 static: enable_static)

> +  libmpathpersist = cc.find_library('mpathpersist',

> +                                    required: get_option('mpath'),

> +                                    static: enable_static)

> +  if libmultipath.found() and libmpathpersist.found() and libudev.found()

> +    if cc.links('''

> +      #include <libudev.h>

> +      #include <mpath_persist.h>

> +      unsigned mpath_mx_alloc_len = 1024;

> +      int logsink;

> +      static struct config *multipath_conf;

> +      extern struct udev *udev;

> +      extern struct config *get_multipath_config(void);

> +      extern void put_multipath_config(struct config *conf);

> +      struct udev *udev;

> +      struct config *get_multipath_config(void) { return multipath_conf; }

> +      void put_multipath_config(struct config *conf) { }

> +      int main(void) {

> +          udev = udev_new();

> +          multipath_conf = mpath_lib_init();

> +          return 0;

> +      }''', dependencies: [libmultipath, libmpathpersist, libudev])

> +      mpathpersist = declare_dependency(dependencies: [libmultipath, libmpathpersist, libudev])

> +      mpathpersist_new_api = true

> +    elif cc.links('''

> +      #include <libudev.h>

> +      #include <mpath_persist.h>

> +      unsigned mpath_mx_alloc_len = 1024;

> +      int logsink;

> +      int main(void) {

> +          struct udev *udev = udev_new();

> +          mpath_lib_init(udev);

> +          return 0;

> +      }''', dependencies: [libmultipath, libmpathpersist, libudev])

> +      mpathpersist = declare_dependency(dependencies: [libmultipath, libmpathpersist, libudev])

> +      mpathpersist_new_api = false

> +    else

> +      if get_option('mpath').enabled()

> +        error('Cannot detect libmpathpersist API')

> +      else

> +        warning('Cannot detect libmpathpersist API, disabling')

> +      endif

> +    endif

> +  endif

>  endif

> +


I just gave this a try on my laptop, but I'm seeing:

../../devel/qemu/meson.build:508:17: ERROR: Unknown variable
"mpathpersist_new_api".

... I guess it should only be printed if mpathpersist.found() ?

 Thomas
Paolo Bonzini Sept. 16, 2020, 5:17 p.m. UTC | #2
Yes, or easier the "false" assignment can be moved out of the "if".

Paolo

Il mer 16 set 2020, 19:09 Thomas Huth <thuth@redhat.com> ha scritto:

> On 16/09/2020 18.26, Paolo Bonzini wrote:

> > This is the first compiler/linker test that has been moved to Meson.

> > Add more section headings to keep things clearer.

> >

> > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

> > ---

> >  configure         | 77 +++------------------------------------------

> >  meson.build       | 80 ++++++++++++++++++++++++++++++++++++++++++-----

> >  meson_options.txt |  2 ++

> >  3 files changed, 78 insertions(+), 81 deletions(-)

> [...]

> > diff --git a/meson.build b/meson.build

> > index 5092aec439..60ef988d9d 100644

> > --- a/meson.build

> > +++ b/meson.build

> > @@ -86,6 +86,14 @@ if 'SPARSE_CFLAGS' in config_host

> >                         'compile_commands.json'])

> >  endif

> >

> > +###########################################

> > +# Target-specific checks and dependencies #

> > +###########################################

> > +

> > +if targetos != 'linux' and get_option('mpath').enabled()

> > +  error('Multipath is supported only on Linux')

> > +endif

> > +

> >  m = cc.find_library('m', required: false)

> >  util = cc.find_library('util', required: false)

> >  winmm = []

> > @@ -117,6 +125,11 @@ elif targetos == 'haiku'

> >              cc.find_library('network'),

> >              cc.find_library('bsd')]

> >  endif

> > +

> > +################

> > +# Dependencies #

> > +################

> > +

> >  # The path to glib.h is added to all compilation commands.  This was

> >  # grandfathered in from the QEMU Makefiles.

> >  add_project_arguments(config_host['GLIB_CFLAGS'].split(),

> > @@ -223,10 +236,6 @@ if 'CONFIG_SPICE' in config_host

> >                               link_args:

> config_host['SPICE_LIBS'].split())

> >  endif

> >  rt = cc.find_library('rt', required: false)

> > -libmpathpersist = not_found

> > -if config_host.has_key('CONFIG_MPATH')

> > -  libmpathpersist = cc.find_library('mpathpersist')

> > -endif

> >  libdl = not_found

> >  if 'CONFIG_PLUGIN' in config_host

> >    libdl = cc.find_library('dl', required: true)

> > @@ -257,9 +266,62 @@ if 'CONFIG_CURL' in config_host

> >                              link_args: config_host['CURL_LIBS'].split())

> >  endif

> >  libudev = not_found

> > -if target_os == 'linux'

> > -  libudev = dependency('libudev', static: enable_static)

> > +if targetos == 'linux'

> > +  libudev = dependency('libudev',

> > +                       required: get_option('mpath'),

> > +                       static: enable_static)

> > +endif

> > +

> > +mpathpersist = not_found

> > +if targetos == 'linux' and not get_option('mpath').disabled()

> > +  libmultipath = cc.find_library('multipath',

> > +                                 required: get_option('mpath'),

> > +                                 static: enable_static)

> > +  libmpathpersist = cc.find_library('mpathpersist',

> > +                                    required: get_option('mpath'),

> > +                                    static: enable_static)

> > +  if libmultipath.found() and libmpathpersist.found() and

> libudev.found()

> > +    if cc.links('''

> > +      #include <libudev.h>

> > +      #include <mpath_persist.h>

> > +      unsigned mpath_mx_alloc_len = 1024;

> > +      int logsink;

> > +      static struct config *multipath_conf;

> > +      extern struct udev *udev;

> > +      extern struct config *get_multipath_config(void);

> > +      extern void put_multipath_config(struct config *conf);

> > +      struct udev *udev;

> > +      struct config *get_multipath_config(void) { return

> multipath_conf; }

> > +      void put_multipath_config(struct config *conf) { }

> > +      int main(void) {

> > +          udev = udev_new();

> > +          multipath_conf = mpath_lib_init();

> > +          return 0;

> > +      }''', dependencies: [libmultipath, libmpathpersist, libudev])

> > +      mpathpersist = declare_dependency(dependencies: [libmultipath,

> libmpathpersist, libudev])

> > +      mpathpersist_new_api = true

> > +    elif cc.links('''

> > +      #include <libudev.h>

> > +      #include <mpath_persist.h>

> > +      unsigned mpath_mx_alloc_len = 1024;

> > +      int logsink;

> > +      int main(void) {

> > +          struct udev *udev = udev_new();

> > +          mpath_lib_init(udev);

> > +          return 0;

> > +      }''', dependencies: [libmultipath, libmpathpersist, libudev])

> > +      mpathpersist = declare_dependency(dependencies: [libmultipath,

> libmpathpersist, libudev])

> > +      mpathpersist_new_api = false

> > +    else

> > +      if get_option('mpath').enabled()

> > +        error('Cannot detect libmpathpersist API')

> > +      else

> > +        warning('Cannot detect libmpathpersist API, disabling')

> > +      endif

> > +    endif

> > +  endif

> >  endif

> > +

>

> I just gave this a try on my laptop, but I'm seeing:

>

> ../../devel/qemu/meson.build:508:17: ERROR: Unknown variable

> "mpathpersist_new_api".

>

> ... I guess it should only be printed if mpathpersist.found() ?

>

>  Thomas

>

>
<div dir="auto">Yes, or easier the &quot;false&quot; assignment can be moved out of the &quot;if&quot;.<div dir="auto"><br></div><div dir="auto">Paolo</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Il mer 16 set 2020, 19:09 Thomas Huth &lt;<a href="mailto:thuth@redhat.com">thuth@redhat.com</a>&gt; ha scritto:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 16/09/2020 18.26, Paolo Bonzini wrote:<br>
&gt; This is the first compiler/linker test that has been moved to Meson.<br>
&gt; Add more section headings to keep things clearer.<br>
&gt; <br>
&gt; Signed-off-by: Paolo Bonzini &lt;<a href="mailto:pbonzini@redhat.com" target="_blank" rel="noreferrer">pbonzini@redhat.com</a>&gt;<br>
&gt; ---<br>
&gt;  configure         | 77 +++------------------------------------------<br>
&gt;  meson.build       | 80 ++++++++++++++++++++++++++++++++++++++++++-----<br>
&gt;  meson_options.txt |  2 ++<br>
&gt;  3 files changed, 78 insertions(+), 81 deletions(-)<br>
[...]<br>
&gt; diff --git a/meson.build b/meson.build<br>
&gt; index 5092aec439..60ef988d9d 100644<br>
&gt; --- a/meson.build<br>
&gt; +++ b/meson.build<br>
&gt; @@ -86,6 +86,14 @@ if &#39;SPARSE_CFLAGS&#39; in config_host<br>
&gt;                         &#39;compile_commands.json&#39;])<br>
&gt;  endif<br>
&gt;  <br>
&gt; +###########################################<br>
&gt; +# Target-specific checks and dependencies #<br>
&gt; +###########################################<br>
&gt; +<br>
&gt; +if targetos != &#39;linux&#39; and get_option(&#39;mpath&#39;).enabled()<br>
&gt; +  error(&#39;Multipath is supported only on Linux&#39;)<br>
&gt; +endif<br>
&gt; +<br>
&gt;  m = cc.find_library(&#39;m&#39;, required: false)<br>
&gt;  util = cc.find_library(&#39;util&#39;, required: false)<br>
&gt;  winmm = []<br>
&gt; @@ -117,6 +125,11 @@ elif targetos == &#39;haiku&#39;<br>
&gt;              cc.find_library(&#39;network&#39;),<br>
&gt;              cc.find_library(&#39;bsd&#39;)]<br>
&gt;  endif<br>
&gt; +<br>
&gt; +################<br>
&gt; +# Dependencies #<br>
&gt; +################<br>
&gt; +<br>
&gt;  # The path to glib.h is added to all compilation commands.  This was<br>
&gt;  # grandfathered in from the QEMU Makefiles.<br>
&gt;  add_project_arguments(config_host[&#39;GLIB_CFLAGS&#39;].split(),<br>
&gt; @@ -223,10 +236,6 @@ if &#39;CONFIG_SPICE&#39; in config_host<br>
&gt;                               link_args: config_host[&#39;SPICE_LIBS&#39;].split())<br>
&gt;  endif<br>
&gt;  rt = cc.find_library(&#39;rt&#39;, required: false)<br>
&gt; -libmpathpersist = not_found<br>
&gt; -if config_host.has_key(&#39;CONFIG_MPATH&#39;)<br>
&gt; -  libmpathpersist = cc.find_library(&#39;mpathpersist&#39;)<br>
&gt; -endif<br>
&gt;  libdl = not_found<br>
&gt;  if &#39;CONFIG_PLUGIN&#39; in config_host<br>
&gt;    libdl = cc.find_library(&#39;dl&#39;, required: true)<br>
&gt; @@ -257,9 +266,62 @@ if &#39;CONFIG_CURL&#39; in config_host<br>
&gt;                              link_args: config_host[&#39;CURL_LIBS&#39;].split())<br>
&gt;  endif<br>
&gt;  libudev = not_found<br>
&gt; -if target_os == &#39;linux&#39;<br>
&gt; -  libudev = dependency(&#39;libudev&#39;, static: enable_static)<br>
&gt; +if targetos == &#39;linux&#39;<br>
&gt; +  libudev = dependency(&#39;libudev&#39;,<br>
&gt; +                       required: get_option(&#39;mpath&#39;),<br>
&gt; +                       static: enable_static)<br>
&gt; +endif<br>
&gt; +<br>
&gt; +mpathpersist = not_found<br>
&gt; +if targetos == &#39;linux&#39; and not get_option(&#39;mpath&#39;).disabled()<br>
&gt; +  libmultipath = cc.find_library(&#39;multipath&#39;,<br>
&gt; +                                 required: get_option(&#39;mpath&#39;),<br>
&gt; +                                 static: enable_static)<br>
&gt; +  libmpathpersist = cc.find_library(&#39;mpathpersist&#39;,<br>
&gt; +                                    required: get_option(&#39;mpath&#39;),<br>
&gt; +                                    static: enable_static)<br>
&gt; +  if libmultipath.found() and libmpathpersist.found() and libudev.found()<br>
&gt; +    if cc.links(&#39;&#39;&#39;<br>
&gt; +      #include &lt;libudev.h&gt;<br>
&gt; +      #include &lt;mpath_persist.h&gt;<br>
&gt; +      unsigned mpath_mx_alloc_len = 1024;<br>
&gt; +      int logsink;<br>
&gt; +      static struct config *multipath_conf;<br>
&gt; +      extern struct udev *udev;<br>
&gt; +      extern struct config *get_multipath_config(void);<br>
&gt; +      extern void put_multipath_config(struct config *conf);<br>
&gt; +      struct udev *udev;<br>
&gt; +      struct config *get_multipath_config(void) { return multipath_conf; }<br>
&gt; +      void put_multipath_config(struct config *conf) { }<br>
&gt; +      int main(void) {<br>
&gt; +          udev = udev_new();<br>
&gt; +          multipath_conf = mpath_lib_init();<br>
&gt; +          return 0;<br>
&gt; +      }&#39;&#39;&#39;, dependencies: [libmultipath, libmpathpersist, libudev])<br>
&gt; +      mpathpersist = declare_dependency(dependencies: [libmultipath, libmpathpersist, libudev])<br>
&gt; +      mpathpersist_new_api = true<br>
&gt; +    elif cc.links(&#39;&#39;&#39;<br>
&gt; +      #include &lt;libudev.h&gt;<br>
&gt; +      #include &lt;mpath_persist.h&gt;<br>
&gt; +      unsigned mpath_mx_alloc_len = 1024;<br>
&gt; +      int logsink;<br>
&gt; +      int main(void) {<br>
&gt; +          struct udev *udev = udev_new();<br>
&gt; +          mpath_lib_init(udev);<br>
&gt; +          return 0;<br>
&gt; +      }&#39;&#39;&#39;, dependencies: [libmultipath, libmpathpersist, libudev])<br>
&gt; +      mpathpersist = declare_dependency(dependencies: [libmultipath, libmpathpersist, libudev])<br>
&gt; +      mpathpersist_new_api = false<br>
&gt; +    else<br>
&gt; +      if get_option(&#39;mpath&#39;).enabled()<br>
&gt; +        error(&#39;Cannot detect libmpathpersist API&#39;)<br>
&gt; +      else<br>
&gt; +        warning(&#39;Cannot detect libmpathpersist API, disabling&#39;)<br>
&gt; +      endif<br>
&gt; +    endif<br>
&gt; +  endif<br>
&gt;  endif<br>
&gt; +<br>
<br>
I just gave this a try on my laptop, but I&#39;m seeing:<br>
<br>
../../devel/qemu/meson.build:508:17: ERROR: Unknown variable<br>
&quot;mpathpersist_new_api&quot;.<br>
<br>
... I guess it should only be printed if mpathpersist.found() ?<br>
<br>
 Thomas<br>
<br>
</blockquote></div>
diff mbox series

Patch

diff --git a/configure b/configure
index 83ccbc6d70..cc38516e06 100755
--- a/configure
+++ b/configure
@@ -371,7 +371,7 @@  netmap="no"
 sdl="auto"
 sdl_image="auto"
 virtfs=""
-mpath=""
+mpath="auto"
 vnc="enabled"
 sparse="no"
 vde=""
@@ -1084,9 +1084,9 @@  for opt do
   ;;
   --enable-virtfs) virtfs="yes"
   ;;
-  --disable-mpath) mpath="no"
+  --disable-mpath) mpath="disabled"
   ;;
-  --enable-mpath) mpath="yes"
+  --enable-mpath) mpath="enabled"
   ;;
   --disable-vnc) vnc="disabled"
   ;;
@@ -3823,57 +3823,6 @@  if test "$modules" = yes; then
     fi
 fi
 
-##########################################
-# libmpathpersist probe
-
-if test "$mpath" != "no" ; then
-  # probe for the new API
-  cat > $TMPC <<EOF
-#include <libudev.h>
-#include <mpath_persist.h>
-unsigned mpath_mx_alloc_len = 1024;
-int logsink;
-static struct config *multipath_conf;
-extern struct udev *udev;
-extern struct config *get_multipath_config(void);
-extern void put_multipath_config(struct config *conf);
-struct udev *udev;
-struct config *get_multipath_config(void) { return multipath_conf; }
-void put_multipath_config(struct config *conf) { }
-
-int main(void) {
-    udev = udev_new();
-    multipath_conf = mpath_lib_init();
-    return 0;
-}
-EOF
-  if compile_prog "" "-ludev -lmultipath -lmpathpersist" ; then
-    mpathpersist=yes
-    mpathpersist_new_api=yes
-  else
-    # probe for the old API
-    cat > $TMPC <<EOF
-#include <libudev.h>
-#include <mpath_persist.h>
-unsigned mpath_mx_alloc_len = 1024;
-int logsink;
-int main(void) {
-    struct udev *udev = udev_new();
-    mpath_lib_init(udev);
-    return 0;
-}
-EOF
-    if compile_prog "" "-ludev -lmultipath -lmpathpersist" ; then
-      mpathpersist=yes
-      mpathpersist_new_api=no
-    else
-      mpathpersist=no
-    fi
-  fi
-else
-  mpathpersist=no
-fi
-
 ##########################################
 # pthread probe
 PTHREADLIBS_LIST="-pthread -lpthread -lpthreadGC2"
@@ -6315,23 +6264,11 @@  if test "$softmmu" = yes ; then
       fi
       virtfs=no
     fi
-    if test "$mpath" != no && test "$mpathpersist" = yes ; then
-      mpath=yes
-    else
-      if test "$mpath" = yes; then
-        error_exit "Multipath requires libmpathpersist devel"
-      fi
-      mpath=no
-    fi
   else
     if test "$virtfs" = yes; then
       error_exit "VirtFS is supported only on Linux"
     fi
     virtfs=no
-    if test "$mpath" = yes; then
-      error_exit "Multipath is supported only on Linux"
-    fi
-    mpath=no
   fi
 fi
 
@@ -6872,12 +6809,6 @@  fi
 if test "$virtfs" = "yes" ; then
   echo "CONFIG_VIRTFS=y" >> $config_host_mak
 fi
-if test "$mpath" = "yes" ; then
-  echo "CONFIG_MPATH=y" >> $config_host_mak
-  if test "$mpathpersist_new_api" = "yes"; then
-    echo "CONFIG_MPATH_NEW_API=y" >> $config_host_mak
-  fi
-fi
 if test "$vhost_scsi" = "yes" ; then
   echo "CONFIG_VHOST_SCSI=y" >> $config_host_mak
 fi
@@ -7965,7 +7896,7 @@  NINJA=${ninja:-$PWD/ninjatool} $meson setup \
         -Dstrip=$(if test "$strip_opt" = yes; then echo true; else echo false; fi) \
         -Db_pie=$(if test "$pie" = yes; then echo true; else echo false; fi) \
         -Db_coverage=$(if test "$gcov" = yes; then echo true; else echo false; fi) \
-	-Dsdl=$sdl -Dsdl_image=$sdl_image \
+	-Dmpath=$mpath -Dsdl=$sdl -Dsdl_image=$sdl_image \
 	-Dvnc=$vnc -Dvnc_sasl=$vnc_sasl -Dvnc_jpeg=$vnc_jpeg -Dvnc_png=$vnc_png \
 	-Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f\
         $cross_arg \
diff --git a/meson.build b/meson.build
index 5092aec439..60ef988d9d 100644
--- a/meson.build
+++ b/meson.build
@@ -86,6 +86,14 @@  if 'SPARSE_CFLAGS' in config_host
                        'compile_commands.json'])
 endif
 
+###########################################
+# Target-specific checks and dependencies #
+###########################################
+
+if targetos != 'linux' and get_option('mpath').enabled()
+  error('Multipath is supported only on Linux')
+endif
+
 m = cc.find_library('m', required: false)
 util = cc.find_library('util', required: false)
 winmm = []
@@ -117,6 +125,11 @@  elif targetos == 'haiku'
             cc.find_library('network'),
             cc.find_library('bsd')]
 endif
+
+################
+# Dependencies #
+################
+
 # The path to glib.h is added to all compilation commands.  This was
 # grandfathered in from the QEMU Makefiles.
 add_project_arguments(config_host['GLIB_CFLAGS'].split(),
@@ -223,10 +236,6 @@  if 'CONFIG_SPICE' in config_host
                              link_args: config_host['SPICE_LIBS'].split())
 endif
 rt = cc.find_library('rt', required: false)
-libmpathpersist = not_found
-if config_host.has_key('CONFIG_MPATH')
-  libmpathpersist = cc.find_library('mpathpersist')
-endif
 libdl = not_found
 if 'CONFIG_PLUGIN' in config_host
   libdl = cc.find_library('dl', required: true)
@@ -257,9 +266,62 @@  if 'CONFIG_CURL' in config_host
                             link_args: config_host['CURL_LIBS'].split())
 endif
 libudev = not_found
-if target_os == 'linux'
-  libudev = dependency('libudev', static: enable_static)
+if targetos == 'linux'
+  libudev = dependency('libudev',
+                       required: get_option('mpath'),
+                       static: enable_static)
+endif
+
+mpathpersist = not_found
+if targetos == 'linux' and not get_option('mpath').disabled()
+  libmultipath = cc.find_library('multipath',
+                                 required: get_option('mpath'),
+                                 static: enable_static)
+  libmpathpersist = cc.find_library('mpathpersist',
+                                    required: get_option('mpath'),
+                                    static: enable_static)
+  if libmultipath.found() and libmpathpersist.found() and libudev.found()
+    if cc.links('''
+      #include <libudev.h>
+      #include <mpath_persist.h>
+      unsigned mpath_mx_alloc_len = 1024;
+      int logsink;
+      static struct config *multipath_conf;
+      extern struct udev *udev;
+      extern struct config *get_multipath_config(void);
+      extern void put_multipath_config(struct config *conf);
+      struct udev *udev;
+      struct config *get_multipath_config(void) { return multipath_conf; }
+      void put_multipath_config(struct config *conf) { }
+      int main(void) {
+          udev = udev_new();
+          multipath_conf = mpath_lib_init();
+          return 0;
+      }''', dependencies: [libmultipath, libmpathpersist, libudev])
+      mpathpersist = declare_dependency(dependencies: [libmultipath, libmpathpersist, libudev])
+      mpathpersist_new_api = true
+    elif cc.links('''
+      #include <libudev.h>
+      #include <mpath_persist.h>
+      unsigned mpath_mx_alloc_len = 1024;
+      int logsink;
+      int main(void) {
+          struct udev *udev = udev_new();
+          mpath_lib_init(udev);
+          return 0;
+      }''', dependencies: [libmultipath, libmpathpersist, libudev])
+      mpathpersist = declare_dependency(dependencies: [libmultipath, libmpathpersist, libudev])
+      mpathpersist_new_api = false
+    else
+      if get_option('mpath').enabled()
+        error('Cannot detect libmpathpersist API')
+      else
+        warning('Cannot detect libmpathpersist API, disabling')
+      endif
+    endif
+  endif
 endif
+
 brlapi = not_found
 if 'CONFIG_BRLAPI' in config_host
   brlapi = declare_dependency(link_args: config_host['BRLAPI_LIBS'].split())
@@ -447,6 +509,8 @@  has_gettid = cc.has_function('gettid')
 # Create config-host.h
 
 config_host_data.set('CONFIG_LIBUDEV', libudev.found())
+config_host_data.set('CONFIG_MPATH', mpathpersist.found())
+config_host_data.set('CONFIG_MPATH_NEW_API', mpathpersist_new_api)
 config_host_data.set('CONFIG_SDL', sdl.found())
 config_host_data.set('CONFIG_SDL_IMAGE', sdl_image.found())
 config_host_data.set('CONFIG_VNC', vnc.found())
@@ -1197,7 +1261,7 @@  if have_tools
 
     executable('qemu-pr-helper', files('scsi/qemu-pr-helper.c', 'scsi/utils.c'),
                dependencies: [authz, crypto, io, qom, qemuutil,
-                              libcap_ng, libudev, libmpathpersist],
+                              libcap_ng, mpathpersist],
                install: true)
   endif
 
@@ -1419,7 +1483,7 @@  summary_info += {'Audio drivers':     config_host['CONFIG_AUDIO_DRIVERS']}
 summary_info += {'Block whitelist (rw)': config_host['CONFIG_BDRV_RW_WHITELIST']}
 summary_info += {'Block whitelist (ro)': config_host['CONFIG_BDRV_RO_WHITELIST']}
 summary_info += {'VirtFS support':    config_host.has_key('CONFIG_VIRTFS')}
-summary_info += {'Multipath support': config_host.has_key('CONFIG_MPATH')}
+summary_info += {'Multipath support': mpathpersist.found()}
 summary_info += {'VNC support':       vnc.found()}
 if vnc.found()
   summary_info += {'VNC SASL support':  sasl.found()}
diff --git a/meson_options.txt b/meson_options.txt
index 543cf70043..b38a6ae92a 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -6,6 +6,8 @@  option('docdir', type : 'string', value : 'doc',
 option('gettext', type : 'boolean', value : true,
        description: 'Localization of the GTK+ user interface')
 
+option('mpath', type : 'feature', value : 'auto',
+       description: 'Multipath persistent reservation passthrough')
 option('sdl', type : 'feature', value : 'auto',
        description: 'SDL user interface')
 option('sdl_image', type : 'feature', value : 'auto',