.\" Automatically generated by Pod::Man 4.07 (Pod::Simple 3.32) .\" .\" 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 .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . 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 .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "nbdkit-ruby-plugin 3" .TH nbdkit-ruby-plugin 3 "2016-06-21" "nbdkit" "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\-ruby\-plugin \- nbdkit ruby plugin .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& nbdkit ruby script=/path/to/plugin.rb [arguments...] .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\f(CW\*(C`nbdkit\-ruby\-plugin\*(C'\fR is an embedded Ruby interpreter for \&\fInbdkit\fR\|(1), allowing you to write nbdkit plugins in Ruby. .PP Broadly speaking, Ruby nbdkit plugins work like C ones, so you should read \fInbdkit\-plugin\fR\|(3) first. .SS "\s-1USING A RUBY NBDKIT PLUGIN\s0" .IX Subsection "USING A RUBY NBDKIT PLUGIN" Assuming you have a Ruby script which is an nbdkit plugin, you run it like this: .PP .Vb 1 \& nbdkit ruby script=/path/to/ruby.rb .Ve .PP You may have to add further \f(CW\*(C`key=value\*(C'\fR arguments to the command line. Read the Ruby script to see if it requires any. \f(CW\*(C`script=...\*(C'\fR \&\fImust\fR come first on the command line. .SH "WRITING A RUBY NBDKIT PLUGIN" .IX Header "WRITING A RUBY NBDKIT PLUGIN" There is an example Ruby nbdkit plugin called \f(CW\*(C`example.rb\*(C'\fR which ships with the nbdkit source. .PP To write a Ruby nbdkit plugin, you create a Ruby file which contains at least the following required functions: .PP .Vb 9 \& def open(readonly) \& # see below \& end \& def get_size(h) \& # see below \& end \& def pread(h, count, offset) \& # see below \& end .Ve .PP Note that the subroutines must have those literal names (like \f(CW\*(C`open\*(C'\fR), because the C part looks up and calls those functions directly. You may want to include documentation and globals (eg. for storing global state). Any other top level statements are run when the script is loaded, just like ordinary Ruby. .PP The file does not need to include a \f(CW\*(C`#!\*(C'\fR (hash-bang) at the top, and does not need to be executable. In fact it's a good idea not to do that, because running the plugin directly as a Ruby script won't work. .SS "\s-1EXCEPTIONS\s0" .IX Subsection "EXCEPTIONS" Ruby callbacks should throw exceptions to indicate errors. .SS "\s-1RUBY CALLBACKS\s0" .IX Subsection "RUBY CALLBACKS" This just documents the arguments to the callbacks in Ruby, and any way that they differ from the C callbacks. In all other respects they work the same way as the C callbacks, so you should go and read \&\fInbdkit\-plugin\fR\|(3). .ie n .IP """config""" 4 .el .IP "\f(CWconfig\fR" 4 .IX Item "config" (Optional) .Sp .Vb 3 \& def config(key, value) \& # no return value \& end .Ve .ie n .IP """config_complete""" 4 .el .IP "\f(CWconfig_complete\fR" 4 .IX Item "config_complete" (Optional) .Sp There are no arguments or return value. .ie n .IP """open""" 4 .el .IP "\f(CWopen\fR" 4 .IX Item "open" (Required) .Sp .Vb 3 \& def open(readonly) \& # return handle \& end .Ve .Sp You can return any non-nil Ruby value as the handle. It is passed back in subsequent calls. .ie n .IP """close""" 4 .el .IP "\f(CWclose\fR" 4 .IX Item "close" (Optional) .Sp .Vb 3 \& def close(h) \& # no return value \& end .Ve .ie n .IP """get_size""" 4 .el .IP "\f(CWget_size\fR" 4 .IX Item "get_size" (Required) .Sp .Vb 3 \& def get_size(h) \& # return the size of the disk \& end .Ve .ie n .IP """can_write""" 4 .el .IP "\f(CWcan_write\fR" 4 .IX Item "can_write" (Optional) .Sp .Vb 3 \& def can_write(h) \& # return a boolean \& end .Ve .ie n .IP """can_flush""" 4 .el .IP "\f(CWcan_flush\fR" 4 .IX Item "can_flush" (Optional) .Sp .Vb 3 \& def can_flush(h) \& # return a boolean \& end .Ve .ie n .IP """is_rotational""" 4 .el .IP "\f(CWis_rotational\fR" 4 .IX Item "is_rotational" (Optional) .Sp .Vb 3 \& def is_rotational(h) \& # return a boolean \& end .Ve .ie n .IP """can_trim""" 4 .el .IP "\f(CWcan_trim\fR" 4 .IX Item "can_trim" (Optional) .Sp .Vb 3 \& def can_trim(h) \& # return a boolean \& end .Ve .ie n .IP """pread""" 4 .el .IP "\f(CWpread\fR" 4 .IX Item "pread" (Required) .Sp .Vb 3 \& def pread(h, count, offset) \& # construct a string of length count bytes and return it \& end .Ve .Sp The body of your \f(CW\*(C`pread\*(C'\fR function should construct a string of length (at least) \f(CW\*(C`count\*(C'\fR bytes. You should read \f(CW\*(C`count\*(C'\fR bytes from the disk starting at \f(CW\*(C`offset\*(C'\fR. .Sp \&\s-1NBD\s0 only supports whole reads, so your function should try to read the whole region (perhaps requiring a loop). If the read fails or is partial, your function should throw an exception. .ie n .IP """pwrite""" 4 .el .IP "\f(CWpwrite\fR" 4 .IX Item "pwrite" (Optional) .Sp .Vb 4 \& def pwrite(h, buf, offset) \& length = buf.length \& # no return value \& end .Ve .Sp The body of your \f(CW\*(C`pwrite\*(C'\fR function should write the \f(CW\*(C`buf\*(C'\fR string to the disk. You should write \f(CW\*(C`count\*(C'\fR bytes to the disk starting at \&\f(CW\*(C`offset\*(C'\fR. .Sp \&\s-1NBD\s0 only supports whole writes, so your function should try to write the whole region (perhaps requiring a loop). If the write fails or is partial, your function should throw an exception. .ie n .IP """flush""" 4 .el .IP "\f(CWflush\fR" 4 .IX Item "flush" (Optional) .Sp .Vb 3 \& def flush(h) \& # no return value \& end .Ve .Sp The body of your \f(CW\*(C`flush\*(C'\fR function should do a \fIsync\fR\|(2) or \&\fIfdatasync\fR\|(2) or equivalent on the backing store. .ie n .IP """trim""" 4 .el .IP "\f(CWtrim\fR" 4 .IX Item "trim" (Optional) .Sp .Vb 3 \& def trim(h, count, offset) \& # no return value \& end .Ve .Sp The body of your \f(CW\*(C`trim\*(C'\fR function should \*(L"punch a hole\*(R" in the backing store. .SS "\s-1MISSING CALLBACKS\s0" .IX Subsection "MISSING CALLBACKS" .ie n .IP "Missing: ""load"" and ""unload""" 4 .el .IP "Missing: \f(CWload\fR and \f(CWunload\fR" 4 .IX Item "Missing: load and unload" These are not needed because you can just use ordinary Ruby constructs. .ie n .IP "Missing: ""name"", ""version"", ""longname"", ""description"", ""config_help""" 4 .el .IP "Missing: \f(CWname\fR, \f(CWversion\fR, \f(CWlongname\fR, \f(CWdescription\fR, \f(CWconfig_help\fR" 4 .IX Item "Missing: name, version, longname, description, config_help" These are not yet supported. .SS "\s-1THREADS\s0" .IX Subsection "THREADS" The thread model for Ruby callbacks currently cannot be set from Ruby. It is hard-coded in the C part to \&\f(CW\*(C`NBDKIT_THREAD_MODEL_SERIALIZE_ALL_REQUESTS\*(C'\fR. This may change or be settable in future. .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fInbdkit\fR\|(1), \&\fInbdkit\-plugin\fR\|(3), \&\fIruby\fR\|(1). .SH "AUTHORS" .IX Header "AUTHORS" Richard W.M. Jones .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright (C) 2013\-2016 Red Hat Inc. .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 \&\s-1THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS \s0''\s-1AS IS\s0'' \s-1AND 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 \s0(\s-1INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES\s0; \s-1LOSS OF USE, DATA, OR PROFITS\s0; \s-1OR BUSINESS INTERRUPTION\s0) \s-1HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \s0(\s-1INCLUDING NEGLIGENCE OR OTHERWISE\s0) \s-1ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\s0