1nbdkit-eval-plugin(1) NBDKIT nbdkit-eval-plugin(1)
2
3
4
6 nbdkit-eval-plugin - write a shell script plugin on the command line
7
9 nbdkit eval get_size='SCRIPT' pread='SCRIPT' pwrite='SCRIPT' [...]
10
12 "nbdkit-eval-plugin" is an nbdkit(1) plugin which allows you to write
13 custom plugins as shell scripts snippets ‘eval’d on the command line.
14
15 A common alternative to this plugin is nbdkit-sh-plugin(1). Both
16 plugins share the same source code and work in almost the same way.
17 You should read nbdkit-sh-plugin(1) first. It is easier to describe
18 the differences between the two plugins and look at the examples below.
19
20 · nbdkit-sh-plugin(1) plugins are written as a single script in a
21 separate file. Eval plugins are shell script fragments written on
22 the nbdkit command line — there is no separate script file.
23
24 · nbdkit-sh-plugin(1) has no way to know if a method is missing or
25 not and so each "can_*" method (eg. "can_write") must be written
26 explicitly. In eval plugins you have the option of omitting
27 "can_*" methods if the associated callback (eg. "pwrite") is
28 defined. In this way eval plugins work more like regular nbdkit
29 plugins.
30
31 · Eval plugins can only use /bin/sh to run the script snippets, but
32 nbdkit-sh-plugin(1) (in spite of the name) can run any executable.
33
34 · There is no "load" method (although there is an "unload" method and
35 all other methods are identical).
36
38 Create a 64M read-only disk of zeroes:
39
40 nbdkit eval get_size=' echo 64M ' \
41 pread=' dd if=/dev/zero count=$3 iflag=count_bytes '
42
43 The following command is the eval plugin equivalent of
44 nbdkit-file-plugin(1) (except not as fast and missing many features):
45
46 nbdkit eval \
47 config='ln -sf "$(realpath "$3")" $tmpdir/file' \
48 get_size='stat -Lc %s $tmpdir/file' \
49 pread='dd if=$tmpdir/file skip=$4 count=$3 iflag=count_bytes,skip_bytes' \
50 pwrite='dd of=$tmpdir/file seek=$4 conv=notrunc oflag=seek_bytes' \
51 file=disk.img
52
54 cache=SCRIPT
55 can_cache=SCRIPT
56 can_extents=SCRIPT
57 can_fast_zero=SCRIPT
58 can_flush=SCRIPT
59 can_fua=SCRIPT
60 can_multi_conn=SCRIPT
61 can_trim=SCRIPT
62 can_write=SCRIPT
63 can_zero=SCRIPT
64 close=SCRIPT
65 config=SCRIPT
66 config_complete=SCRIPT
67 dump_plugin=SCRIPT
68 extents=SCRIPT
69 flush=SCRIPT
70 get_ready=SCRIPT
71 get_size=SCRIPT
72 is_rotational=SCRIPT
73 open=SCRIPT
74 pread=SCRIPT
75 preconnect=SCRIPT
76 pwrite=SCRIPT
77 thread_model=SCRIPT
78 trim=SCRIPT
79 unload=SCRIPT
80 zero=SCRIPT
81 Define the script associated with each method. "SCRIPT" is a
82 fragment of shell script which is executed when nbdkit wants to
83 invoke the associated method.
84
85 If you are typing these commands at the shell, be careful about
86 quoting. Normally you will need to enclose "SCRIPT" in '...'
87 (single quotes) to prevent it from being modified by your shell.
88
89 The script fragment behaves the same way as the corresponding
90 method in nbdkit-sh-plugin(1). In particular, parameters are
91 identical, $tmpdir is present and used in the same way, the exit
92 code must be one of the valid exit codes described in that manual
93 page, and error handling works the same way too.
94
95 Note that a "config" callback will only handle keys not recognized
96 as callback names; when picking key=value pairs that you want your
97 script fragment to understand, be aware that if a future nbdkit
98 release creates a callback by that name, your "config" script
99 fragment will no longer see that key.
100
101 All of these parameters are optional.
102
103 missing=SCRIPT
104 The parameter "missing" defines a script that will be called in
105 place of any other callback not explicitly provided. If omitted,
106 this defaults to the script "exit 2".
107
109 "tmpdir"
110 This is defined to the name of a temporary directory which can be
111 used by the script snippets. It is deleted when nbdkit exits.
112
114 /bin/sh
115 Shell script fragments are executed using /bin/sh.
116
117 $plugindir/nbdkit-eval-plugin.so
118 The plugin.
119
120 Use "nbdkit --dump-config" to find the location of $plugindir.
121
123 "nbdkit-eval-plugin" first appeared in nbdkit 1.18.
124
126 nbdkit(1), nbdkit-plugin(3), nbdkit-sh-plugin(1).
127
129 Richard W.M. Jones
130
132 Copyright (C) 2019 Red Hat Inc.
133
135 Redistribution and use in source and binary forms, with or without
136 modification, are permitted provided that the following conditions are
137 met:
138
139 · Redistributions of source code must retain the above copyright
140 notice, this list of conditions and the following disclaimer.
141
142 · Redistributions in binary form must reproduce the above copyright
143 notice, this list of conditions and the following disclaimer in the
144 documentation and/or other materials provided with the
145 distribution.
146
147 · Neither the name of Red Hat nor the names of its contributors may
148 be used to endorse or promote products derived from this software
149 without specific prior written permission.
150
151 THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND ANY
152 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
153 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
154 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR CONTRIBUTORS BE
155 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
156 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
157 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
158 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
159 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
160 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
161 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
162
163
164
165nbdkit-1.18.4 2020-04-16 nbdkit-eval-plugin(1)