File: nbdkit-eval-plugin.pod

package info (click to toggle)
nbdkit 1.42.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,696 kB
  • sloc: ansic: 59,224; sh: 16,793; makefile: 6,463; python: 1,837; cpp: 1,116; ml: 504; perl: 502; tcl: 62
file content (212 lines) | stat: -rw-r--r-- 4,913 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
=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