=head1 NAME

nbdkit-probing - how to probe for nbdkit configuration and plugins

=head1 SYNOPSIS

 nbdkit --dump-config

=for paragraph

 nbdkit PLUGIN --dump-plugin

=for paragraph

 nbdkit --version

=for paragraph

 nbdkit PLUGIN --version

=for paragraph

 nbdkit --filter=FILTER null --version

=for paragraph

 nbdkit --filter=FILTER null --dump-plugin

=head1 DESCRIPTION

You can query information about nbdkit and available plugins and
filters using the nbdkit binary.  This can include whether nbdkit is
installed, and whether plugins or filters are installed.

=head2 Query if nbdkit is installed

Use this command to see if the nbdkit program is installed:

 nbdkit --version

This will fail with an error and non-zero exit code if nbdkit is not
installed or not working.

=head2 Query basic configuration

 nbdkit --dump-config

lists information about how nbdkit was configured.  The most important
fields in the output are the name of the directory where nbdkit looks
for plugins and the version of nbdkit, eg:

 plugindir=/usr/lib64/nbdkit/plugins
 version=1.20.1
 version_major=1
 version_minor=20

=head2 Test nbdkit E<ge> version

To test if nbdkit E<ge> a particular version is installed, use the
I<--dump-config> option and look for the C<version_major> and
C<version_minor> fields:

 $ nbdkit --dump-config | grep ^version_minor
 version_minor=20
 $ major=$( nbdkit --dump-config | grep ^version_major | cut -d= -f2 )
 $ minor=$( nbdkit --dump-config | grep ^version_minor | cut -d= -f2 )
 $ if [ $major -eq 1 ] && [ $minor -lt 12 ]
   then echo 'nbdkit >= 1.12 is required'; exit 1; fi

These fields were first added in nbdkit 1.16.5 and were not present in
earlier versions.

You can also probe the minimum version using L<pkg-config(1)>.  See
L<nbdkit-plugin(3)/PKG-CONFIG/PKGCONF>.

=head2 Query information about a particular plugin

 nbdkit pluginname --dump-plugin

(where I<pluginname> is the name or full path of a plugin) will dump
information about that plugin, eg:

 $ nbdkit file --dump-plugin
 path=/usr/lib64/nbdkit/plugins/nbdkit-file-plugin.so
 name=file
 version=1.20.1
 api_version=1
 struct_size=176
 thread_model=serialize_requests
 [etc]

Plugins which ship with nbdkit usually have the same version as the
corresponding nbdkit binary.  The nbdkit binary will always be able to
utilize plugins compiled against an older version of the header;
however, newer plugins may not be fully supported by an older nbdkit
binary (for example, a plugin compiled with C<NBDKIT_API_VERSION> of 2
fails to load with an older nbdkit that only knows
C<NBDKIT_API_VERSION> 1).

=head2 Query information about a particular filter

You can use the I<--dump-plugin> option to dump information about a
filter, by using the null plugin with the I<--filter> parameter:

 $ nbdkit null --filter=qcow2dec --dump-plugin
 [...]
 qcow2dec_path=/usr/lib64/nbdkit/filters/nbdkit-qcow2dec-filter.so
 qcow2dec_name=qcow2dec
 qcow2dec_deflate=yes
 qcow2dec_zstd=yes

=head2 Detect if a plugin is installed

To find out if a plugin is installed (and working) in the plugin
directory, use:

 $ nbdkit foo --version
 nbdkit: error: cannot open plugin 'foo': /usr/lib64/nbdkit/plugins/nbdkit-foo-plugin.so: cannot open shared object file: No such file or directory
 Use 'nbdkit --help' or read the nbdkit(1) manual page for documentation.

This will fail with an error and non-zero exit code if the C<foo>
plugin cannot be loaded.

Note it is better to test for the existence of plugins this way rather
than just seeing if the F<.so> file exists, because nbdkit will load
the plugin and check that all its dependencies can be satisfied, and
also that plugin registration works.

=head2 List all plugins in the plugin directory

You could simply get the plugin directory (from I<--dump-config>) and
list all files in this directory called F<nbdkit-*-plugin.so>.

However a better test is to run I<--dump-plugin> (see above) on each
one to check that it is working and all of its dependencies are
installed.  A complete shell script which does this is:

 #!/bin/sh -
 plugindir=`nbdkit --dump-config | grep ^plugindir= | sed 's/[^=]*=//'`
 for f in $plugindir/nbdkit-*-plugin.so; do
     if nbdkit "$f" --version >/dev/null 2>&1; then
         b=`echo "$f" | sed 's,.*/nbdkit-\(.*\)-plugin.so$,\1,'`
         echo "$b ($f)"
     fi
 done

=head2 Detect if a filter is installed

To find out if a filter is installed (and working) use I<--version>
with the C<null> plugin and the name of the filter to test:

 nbdkit --version --filter=foo null

This will fail with an error and non-zero exit code if the C<foo>
filter cannot be loaded.

=head1 SEE ALSO

L<nbdkit(1)>.

=head1 AUTHORS

Eric Blake

Richard W.M. Jones

Pino Toscano

=head1 COPYRIGHT

Copyright Red Hat
