=head1 NAME

nbdkit-eval-plugin - write a shell script plugin on the command line

=head1 SYNOPSIS

 nbdkit eval get_size='SCRIPT' pread='SCRIPT' pwrite='SCRIPT' [...]

=head1 DESCRIPTION

C<nbdkit-eval-plugin> is an L<nbdkit(1)> plugin which allows you to
write custom plugins as shell scripts snippets ‘eval’d on the command
line.

A common alternative to this plugin is L<nbdkit-sh-plugin(3)>.  Both
plugins share the same source code and work in almost the same way.
You should read L<nbdkit-sh-plugin(3)> first.  It is easier to
describe the differences between the two plugins and look at the
examples below.

=over 4

=item *

L<nbdkit-sh-plugin(3)> plugins are written as a single script in a
separate file.  Eval plugins are shell script fragments written on the
nbdkit command line — there is no separate script file.

=item *

L<nbdkit-sh-plugin(3)> has no way to know if a method is missing or
not and so each C<can_*> method (eg. C<can_write>) must be written
explicitly.  In eval plugins you have the option of omitting C<can_*>
methods if the associated callback (eg. C<pwrite>) is defined.  In
this way eval plugins work more like regular nbdkit plugins.

=item *

Eval plugins can only use F</bin/sh> to run the script snippets, but
L<nbdkit-sh-plugin(3)> (in spite of the name) can run any executable.

=item *

There is no C<load> method (although there is an C<unload> method and
all other methods are identical).

=back

=head1 EXAMPLES

Create a 64M read-only disk of zeroes:

 nbdkit eval get_size=' echo 64M ' \
                pread=' dd if=/dev/zero count=$3 iflag=count_bytes '

The following command is the eval plugin equivalent of
L<nbdkit-file-plugin(1)> (except not as fast and missing many
features):

 nbdkit eval \
   config='ln -sf "$(realpath "$3")" $tmpdir/file' \
   get_size='stat -Lc %s $tmpdir/file' \
   pread='dd if=$tmpdir/file skip=$4 count=$3 iflag=count_bytes,skip_bytes' \
   pwrite='dd of=$tmpdir/file seek=$4 conv=notrunc oflag=seek_bytes' \
   file=disk.img

=head1 PARAMETERS

=over 4

=item B<after_fork=>SCRIPT

=item B<block_size=>SCRIPT

=item B<cache=>SCRIPT

=item B<can_cache=>SCRIPT

=item B<can_extents=>SCRIPT

=item B<can_fast_zero=>SCRIPT

=item B<can_flush=>SCRIPT

=item B<can_fua=>SCRIPT

=item B<can_multi_conn=>SCRIPT

=item B<can_trim=>SCRIPT

=item B<can_write=>SCRIPT

=item B<can_zero=>SCRIPT

=item B<close=>SCRIPT

=item B<config=>SCRIPT

=item B<config_complete=>SCRIPT

=item B<default_export=>SCRIPT

=item B<dump_plugin=>SCRIPT

=item B<export_description=>SCRIPT

=item B<extents=>SCRIPT

=item B<flush=>SCRIPT

=item B<get_ready=>SCRIPT

=item B<get_size=>SCRIPT

=item B<is_rotational=>SCRIPT

=item B<list_exports=>SCRIPT

=item B<default_export=>SCRIPT

=item B<open=>SCRIPT

=item B<pread=>SCRIPT

=item B<preconnect=>SCRIPT

=item B<pwrite=>SCRIPT

=item B<thread_model=>SCRIPT

=item B<trim=>SCRIPT

=item B<unload=>SCRIPT

=item B<zero=>SCRIPT

Define the script associated with each method.  C<SCRIPT> is a
fragment of shell script which is executed when nbdkit wants to invoke
the associated method.

If you are typing these commands at the shell, be careful about
quoting.  Normally you will need to enclose C<SCRIPT> in C<'...'>
(single quotes) to prevent it from being modified by your shell.

The script fragment behaves the same way as the corresponding method
in L<nbdkit-sh-plugin(3)>.  In particular, parameters are identical,
C<$tmpdir> is present and used in the same way, the exit code must be
one of the valid exit codes described in that manual page, and error
handling works the same way too.  Likewise, B<nbdkit --dump-plugin
eval> includes a line for B<max_known_status=> in nbdkit E<ge> 1.34.

Note that a C<config> callback will only handle keys not recognized as
callback names; when picking key=value pairs that you want your script
fragment to understand, be aware that if a future nbdkit release
creates a callback by that name, your C<config> script fragment will
no longer see that key.

All of these parameters are optional.

=item B<missing=>SCRIPT

The parameter C<missing> defines a script that will be called in place
of any other callback not explicitly provided.  If omitted, this
defaults to the script "exit 2".

=back

=head1 ENVIRONMENT VARIABLES

=over 4

=item C<tmpdir>

This is defined to the name of a temporary directory which can be used
by the script snippets.  It is deleted when nbdkit exits.

=back

=head1 FILES

=over 4

=item F</bin/sh>

Shell script fragments are executed using F</bin/sh>.

=item F<$plugindir/nbdkit-eval-plugin.so>

The plugin.

Use C<nbdkit --dump-config> to find the location of C<$plugindir>.

=back

=head1 VERSION

C<nbdkit-eval-plugin> first appeared in nbdkit 1.18.

=head1 SEE ALSO

L<nbdkit(1)>,
L<nbdkit-plugin(3)>,
L<nbdkit-sh-plugin(3)>,
L<nbdkit-cc-plugin(1)>.

=head1 AUTHORS

Richard W.M. Jones

=head1 COPYRIGHT

Copyright Red Hat
