1nbdkit-plugin(3)                    NBDKIT                    nbdkit-plugin(3)
2
3
4

NAME

6       nbdkit-plugin - how to write nbdkit plugins
7

SYNOPSIS

9        #define NBDKIT_API_VERSION 2
10        #include <nbdkit-plugin.h>
11
12        #define THREAD_MODEL NBDKIT_THREAD_MODEL_SERIALIZE_ALL_REQUESTS
13
14        static void *
15        myplugin_open (void)
16        {
17          /* create a handle ... */
18          return handle;
19        }
20
21        static struct nbdkit_plugin plugin = {
22          .name              = "myplugin",
23          .open              = myplugin_open,
24          .get_size          = myplugin_get_size,
25          .pread             = myplugin_pread,
26          .pwrite            = myplugin_pwrite,
27          /* etc */
28        };
29        NBDKIT_REGISTER_PLUGIN(plugin)
30
31       Compile the plugin as a shared library:
32
33        gcc -fPIC -shared myplugin.c -o myplugin.so
34
35       and load it into nbdkit:
36
37        nbdkit [--args ...] ./myplugin.so [key=value ...]
38
39       When debugging, use the -fv options:
40
41        nbdkit -fv ./myplugin.so [key=value ...]
42

DESCRIPTION

44       An nbdkit plugin is a new source device which can be served using the
45       Network Block Device (NBD) protocol.  This manual page describes how to
46       create an nbdkit plugin in C.
47
48       To see example plugins:
49       https://gitlab.com/nbdkit/nbdkit/tree/master/plugins
50
51       To write plugins in other languages, see: nbdkit-cc-plugin(3),
52       nbdkit-golang-plugin(3), nbdkit-lua-plugin(3), nbdkit-ocaml-plugin(3),
53       nbdkit-perl-plugin(3), nbdkit-python-plugin(3), nbdkit-ruby-plugin(3),
54       nbdkit-rust-plugin(3), nbdkit-sh-plugin(3), nbdkit-tcl-plugin(3) .
55
56   API and ABI guarantee for C plugins
57       Plugins written in C have an ABI guarantee: a plugin compiled against
58       an older version of nbdkit will still work correctly when loaded with a
59       newer nbdkit.  We also try (but cannot guarantee) to support plugins
60       compiled against a newer version of nbdkit when loaded with an older
61       nbdkit, although the plugin may have reduced functionality if it
62       depends on features only provided by newer nbdkit.
63
64       For plugins written in C, we also provide an API guarantee: a plugin
65       written against an older header will still compile unmodified with a
66       newer nbdkit.
67
68       The API guarantee does not always apply to plugins written in other
69       (non-C) languages which may have to adapt to changes when recompiled
70       against a newer nbdkit.
71

WRITING AN NBDKIT PLUGIN

73   "#define NBDKIT_API_VERSION 2"
74       Plugins must choose which API version they want to use, by defining
75       NBDKIT_API_VERSION before including "<nbdkit-plugin.h>" (or any other
76       nbdkit header).
77
78       If omitted, the default version is 1 for backwards-compatibility with
79