.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Podwrapper::Man 1.38.1 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "nbdkit-eval-plugin 1" .TH nbdkit-eval-plugin 1 2024-04-21 nbdkit-1.38.1 NBDKIT .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME nbdkit\-eval\-plugin \- write a shell script plugin on the command line .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& nbdkit eval get_size=\*(AqSCRIPT\*(Aq pread=\*(AqSCRIPT\*(Aq pwrite=\*(AqSCRIPT\*(Aq [...] .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" \&\f(CW\*(C`nbdkit\-eval\-plugin\*(C'\fR is an \fBnbdkit\fR\|(1) plugin which allows you to write custom plugins as shell scripts snippets ‘eval’d on the command line. .PP A common alternative to this plugin is \fBnbdkit\-sh\-plugin\fR\|(1). Both plugins share the same source code and work in almost the same way. You should read \fBnbdkit\-sh\-plugin\fR\|(1) first. It is easier to describe the differences between the two plugins and look at the examples below. .IP \(bu 4 \&\fBnbdkit\-sh\-plugin\fR\|(1) 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. .IP \(bu 4 \&\fBnbdkit\-sh\-plugin\fR\|(1) has no way to know if a method is missing or not and so each \f(CW\*(C`can_*\*(C'\fR method (eg. \f(CW\*(C`can_write\*(C'\fR) must be written explicitly. In eval plugins you have the option of omitting \f(CW\*(C`can_*\*(C'\fR methods if the associated callback (eg. \f(CW\*(C`pwrite\*(C'\fR) is defined. In this way eval plugins work more like regular nbdkit plugins. .IP \(bu 4 Eval plugins can only use \fI/bin/sh\fR to run the script snippets, but \&\fBnbdkit\-sh\-plugin\fR\|(1) (in spite of the name) can run any executable. .IP \(bu 4 There is no \f(CW\*(C`load\*(C'\fR method (although there is an \f(CW\*(C`unload\*(C'\fR method and all other methods are identical). .SH EXAMPLES .IX Header "EXAMPLES" Create a 64M read-only disk of zeroes: .PP .Vb 2 \& nbdkit eval get_size=\*(Aq echo 64M \*(Aq \e \& pread=\*(Aq dd if=/dev/zero count=$3 iflag=count_bytes \*(Aq .Ve .PP The following command is the eval plugin equivalent of \&\fBnbdkit\-file\-plugin\fR\|(1) (except not as fast and missing many features): .PP .Vb 6 \& nbdkit eval \e \& config=\*(Aqln \-sf "$(realpath "$3")" $tmpdir/file\*(Aq \e \& get_size=\*(Aqstat \-Lc %s $tmpdir/file\*(Aq \e \& pread=\*(Aqdd if=$tmpdir/file skip=$4 count=$3 iflag=count_bytes,skip_bytes\*(Aq \e \& pwrite=\*(Aqdd of=$tmpdir/file seek=$4 conv=notrunc oflag=seek_bytes\*(Aq \e \& file=disk.img .Ve .SH PARAMETERS .IX Header "PARAMETERS" .IP \fBafter_fork=\fRSCRIPT 4 .IX Item "after_fork=SCRIPT" .PD 0 .IP \fBblock_size=\fRSCRIPT 4 .IX Item "block_size=SCRIPT" .IP \fBcache=\fRSCRIPT 4 .IX Item "cache=SCRIPT" .IP \fBcan_cache=\fRSCRIPT 4 .IX Item "can_cache=SCRIPT" .IP \fBcan_extents=\fRSCRIPT 4 .IX Item "can_extents=SCRIPT" .IP \fBcan_fast_zero=\fRSCRIPT 4 .IX Item "can_fast_zero=SCRIPT" .IP \fBcan_flush=\fRSCRIPT 4 .IX Item "can_flush=SCRIPT" .IP \fBcan_fua=\fRSCRIPT 4 .IX Item "can_fua=SCRIPT" .IP \fBcan_multi_conn=\fRSCRIPT 4 .IX Item "can_multi_conn=SCRIPT" .IP \fBcan_trim=\fRSCRIPT 4 .IX Item "can_trim=SCRIPT" .IP \fBcan_write=\fRSCRIPT 4 .IX Item "can_write=SCRIPT" .IP \fBcan_zero=\fRSCRIPT 4 .IX Item "can_zero=SCRIPT" .IP \fBclose=\fRSCRIPT 4 .IX Item "close=SCRIPT" .IP \fBconfig=\fRSCRIPT 4 .IX Item "config=SCRIPT" .IP \fBconfig_complete=\fRSCRIPT 4 .IX Item "config_complete=SCRIPT" .IP \fBdefault_export=\fRSCRIPT 4 .IX Item "default_export=SCRIPT" .IP \fBdump_plugin=\fRSCRIPT 4 .IX Item "dump_plugin=SCRIPT" .IP \fBexport_description=\fRSCRIPT 4 .IX Item "export_description=SCRIPT" .IP \fBextents=\fRSCRIPT 4 .IX Item "extents=SCRIPT" .IP \fBflush=\fRSCRIPT 4 .IX Item "flush=SCRIPT" .IP \fBget_ready=\fRSCRIPT 4 .IX Item "get_ready=SCRIPT" .IP \fBget_size=\fRSCRIPT 4 .IX Item "get_size=SCRIPT" .IP \fBis_rotational=\fRSCRIPT 4 .IX Item "is_rotational=SCRIPT" .IP \fBlist_exports=\fRSCRIPT 4 .IX Item "list_exports=SCRIPT" .IP \fBdefault_export=\fRSCRIPT 4 .IX Item "default_export=SCRIPT" .IP \fBopen=\fRSCRIPT 4 .IX Item "open=SCRIPT" .IP \fBpread=\fRSCRIPT 4 .IX Item "pread=SCRIPT" .IP \fBpreconnect=\fRSCRIPT 4 .IX Item "preconnect=SCRIPT" .IP \fBpwrite=\fRSCRIPT 4 .IX Item "pwrite=SCRIPT" .IP \fBthread_model=\fRSCRIPT 4 .IX Item "thread_model=SCRIPT" .IP \fBtrim=\fRSCRIPT 4 .IX Item "trim=SCRIPT" .IP \fBunload=\fRSCRIPT 4 .IX Item "unload=SCRIPT" .IP \fBzero=\fRSCRIPT 4 .IX Item "zero=SCRIPT" .PD Define the script associated with each method. \f(CW\*(C`SCRIPT\*(C'\fR is a fragment of shell script which is executed when nbdkit wants to invoke the associated method. .Sp If you are typing these commands at the shell, be careful about quoting. Normally you will need to enclose \f(CW\*(C`SCRIPT\*(C'\fR in \f(CW\*(Aq...\*(Aq\fR (single quotes) to prevent it from being modified by your shell. .Sp The script fragment behaves the same way as the corresponding method in \fBnbdkit\-sh\-plugin\fR\|(1). In particular, parameters are identical, \&\f(CW$tmpdir\fR 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, \fBnbdkit \-\-dump\-plugin eval\fR includes a line for \fBmax_known_status=\fR in nbdkit ≥ 1.34. .Sp Note that a \f(CW\*(C`config\*(C'\fR 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 \f(CW\*(C`config\*(C'\fR script fragment will no longer see that key. .Sp All of these parameters are optional. .IP \fBmissing=\fRSCRIPT 4 .IX Item "missing=SCRIPT" The parameter \f(CW\*(C`missing\*(C'\fR 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". .SH "ENVIRONMENT VARIABLES" .IX Header "ENVIRONMENT VARIABLES" .ie n .IP """tmpdir""" 4 .el .IP \f(CWtmpdir\fR 4 .IX Item "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. .SH FILES .IX Header "FILES" .IP \fI/bin/sh\fR 4 .IX Item "/bin/sh" Shell script fragments are executed using \fI/bin/sh\fR. .ie n .IP \fR\fI$plugindir\fR\fI/nbdkit\-eval\-plugin.so\fR 4 .el .IP \fR\f(CI$plugindir\fR\fI/nbdkit\-eval\-plugin.so\fR 4 .IX Item "$plugindir/nbdkit-eval-plugin.so" The plugin. .Sp Use \f(CW\*(C`nbdkit \-\-dump\-config\*(C'\fR to find the location of \f(CW$plugindir\fR. .SH VERSION .IX Header "VERSION" \&\f(CW\*(C`nbdkit\-eval\-plugin\*(C'\fR first appeared in nbdkit 1.18. .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fBnbdkit\fR\|(1), \&\fBnbdkit\-plugin\fR\|(3), \&\fBnbdkit\-sh\-plugin\fR\|(1). \&\fBnbdkit\-cc\-plugin\fR\|(1). .SH AUTHORS .IX Header "AUTHORS" Richard W.M. Jones .SH COPYRIGHT .IX Header "COPYRIGHT" Copyright Red Hat .SH LICENSE .IX Header "LICENSE" Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: .IP \(bu 4 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. .IP \(bu 4 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. .IP \(bu 4 Neither the name of Red Hat nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. .PP THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.