Update Red Hat Copyright Notices
[nbdkit.git] / plugins / eval / nbdkit-eval-plugin.pod
bloba19c393214b1a18344386ea5b7b242cd50c41666
1 =head1 NAME
3 nbdkit-eval-plugin - write a shell script plugin on the command line
5 =head1 SYNOPSIS
7  nbdkit eval get_size='SCRIPT' pread='SCRIPT' pwrite='SCRIPT' [...]
9 =head1 DESCRIPTION
11 C<nbdkit-eval-plugin> is an L<nbdkit(1)> plugin which allows you to
12 write custom plugins as shell scripts snippets ‘eval’d on the command
13 line.
15 A common alternative to this plugin is L<nbdkit-sh-plugin(1)>.  Both
16 plugins share the same source code and work in almost the same way.
17 You should read L<nbdkit-sh-plugin(1)> first.  It is easier to
18 describe the differences between the two plugins and look at the
19 examples below.
21 =over 4
23 =item *
25 L<nbdkit-sh-plugin(1)> plugins are written as a single script in a
26 separate file.  Eval plugins are shell script fragments written on the
27 nbdkit command line — there is no separate script file.
29 =item *
31 L<nbdkit-sh-plugin(1)> has no way to know if a method is missing or
32 not and so each C<can_*> method (eg. C<can_write>) must be written
33 explicitly.  In eval plugins you have the option of omitting C<can_*>
34 methods if the associated callback (eg. C<pwrite>) is defined.  In
35 this way eval plugins work more like regular nbdkit plugins.
37 =item *
39 Eval plugins can only use F</bin/sh> to run the script snippets, but
40 L<nbdkit-sh-plugin(1)> (in spite of the name) can run any executable.
42 =item *
44 There is no C<load> method (although there is an C<unload> method and
45 all other methods are identical).
47 =back
49 =head1 EXAMPLES
51 Create a 64M read-only disk of zeroes:
53  nbdkit eval get_size=' echo 64M ' \
54                 pread=' dd if=/dev/zero count=$3 iflag=count_bytes '
56 The following command is the eval plugin equivalent of
57 L<nbdkit-file-plugin(1)> (except not as fast and missing many
58 features):
60  nbdkit eval \
61    config='ln -sf "$(realpath "$3")" $tmpdir/file' \
62    get_size='stat -Lc %s $tmpdir/file' \
63    pread='dd if=$tmpdir/file skip=$4 count=$3 iflag=count_bytes,skip_bytes' \
64    pwrite='dd of=$tmpdir/file seek=$4 conv=notrunc oflag=seek_bytes' \
65    file=disk.img
67 =head1 PARAMETERS
69 =over 4
71 =item B<after_fork=>SCRIPT
73 =item B<block_size=>SCRIPT
75 =item B<cache=>SCRIPT
77 =item B<can_cache=>SCRIPT
79 =item B<can_extents=>SCRIPT
81 =item B<can_fast_zero=>SCRIPT
83 =item B<can_flush=>SCRIPT
85 =item B<can_fua=>SCRIPT
87 =item B<can_multi_conn=>SCRIPT
89 =item B<can_trim=>SCRIPT
91 =item B<can_write=>SCRIPT
93 =item B<can_zero=>SCRIPT
95 =item B<close=>SCRIPT
97 =item B<config=>SCRIPT
99 =item B<config_complete=>SCRIPT
101 =item B<default_export=>SCRIPT
103 =item B<dump_plugin=>SCRIPT
105 =item B<export_description=>SCRIPT
107 =item B<extents=>SCRIPT
109 =item B<flush=>SCRIPT
111 =item B<get_ready=>SCRIPT
113 =item B<get_size=>SCRIPT
115 =item B<is_rotational=>SCRIPT
117 =item B<list_exports=>SCRIPT
119 =item B<default_export=>SCRIPT
121 =item B<open=>SCRIPT
123 =item B<pread=>SCRIPT
125 =item B<preconnect=>SCRIPT
127 =item B<pwrite=>SCRIPT
129 =item B<thread_model=>SCRIPT
131 =item B<trim=>SCRIPT
133 =item B<unload=>SCRIPT
135 =item B<zero=>SCRIPT
137 Define the script associated with each method.  C<SCRIPT> is a
138 fragment of shell script which is executed when nbdkit wants to invoke
139 the associated method.
141 If you are typing these commands at the shell, be careful about
142 quoting.  Normally you will need to enclose C<SCRIPT> in C<'...'>
143 (single quotes) to prevent it from being modified by your shell.
145 The script fragment behaves the same way as the corresponding method
146 in L<nbdkit-sh-plugin(1)>.  In particular, parameters are identical,
147 C<$tmpdir> is present and used in the same way, the exit code must be
148 one of the valid exit codes described in that manual page, and error
149 handling works the same way too.  Likewise, B<nbdkit --dump-plugin
150 eval> includes a line for B<max_known_status=> in nbdkit E<ge> 1.34.
152 Note that a C<config> callback will only handle keys not recognized as
153 callback names; when picking key=value pairs that you want your script
154 fragment to understand, be aware that if a future nbdkit release
155 creates a callback by that name, your C<config> script fragment will
156 no longer see that key.
158 All of these parameters are optional.
160 =item B<missing=>SCRIPT
162 The parameter C<missing> defines a script that will be called in place
163 of any other callback not explicitly provided.  If omitted, this
164 defaults to the script "exit 2".
166 =back
168 =head1 ENVIRONMENT VARIABLES
170 =over 4
172 =item C<tmpdir>
174 This is defined to the name of a temporary directory which can be used
175 by the script snippets.  It is deleted when nbdkit exits.
177 =back
179 =head1 FILES
181 =over 4
183 =item F</bin/sh>
185 Shell script fragments are executed using F</bin/sh>.
187 =item F<$plugindir/nbdkit-eval-plugin.so>
189 The plugin.
191 Use C<nbdkit --dump-config> to find the location of C<$plugindir>.
193 =back
195 =head1 VERSION
197 C<nbdkit-eval-plugin> first appeared in nbdkit 1.18.
199 =head1 SEE ALSO
201 L<nbdkit(1)>,
202 L<nbdkit-plugin(3)>,
203 L<nbdkit-sh-plugin(1)>.
204 L<nbdkit-cc-plugin(1)>.
206 =head1 AUTHORS
208 Richard W.M. Jones
210 =head1 COPYRIGHT
212 Copyright Red Hat