data: don't ignore SIGPIPE
[nbdkit.git] / README.md
blob2e58d576cdb94ad6413fe593c0b8f983fd0246c7
1 ## NBD server with stable plugin ABI and permissive license
3 nbdkit is an NBD server.  NBD — Network Block Device — is a protocol
4 for accessing Block Devices (hard disks and disk-like things) over a
5 Network.
7 The key features of nbdkit are:
9 * Multithreaded NBD server written in C with good performance.
10 * Minimal dependencies for the basic server.
11 * Liberal license (BSD) allows nbdkit to be linked to proprietary
12   libraries or included in proprietary code.
13 * Well-documented, simple plugin API with a stable ABI guarantee.
14   Lets you export “unconventional” block devices easily.
15 * You can write plugins in C/C++, Go, Lua, Perl, Python, OCaml, Ruby,
16   Rust, shell script or Tcl.
17 * Filters can be stacked in front of plugins to transform the output.
19 For documentation, see the [docs directory](docs/).
21 For plugins and filters, see the [plugins](plugins/) and
22 [filters](filters/) directories.  Example plugins can be found in
23 `plugins/example*`.
25 There are many NBD clients, but the nbdkit project has a companion
26 client library called https://gitlab.com/nbdkit/libnbd
28 https://gitlab.com/nbdkit/nbdkit
30 ## License
32 This software is copyright (C) Red Hat Inc. and licensed under a BSD
33 license.  See [LICENSE](LICENSE) for details.
35 ## Building from source
37 ### Requirements
39 * Linux, macOS, Windows, FreeBSD, OpenBSD or Haiku
40 * GCC or Clang
41 * bash
42 * GNU make
44 Recommended for TLS (authentication and encryption) support, but it is
45 possible to build without it:
47 * gnutls >= 3.3.0
49 For Windows support see [the Windows section below](README.md#windows).
51 For macOS support see [the macOS section below](README.md#macos).
53 ### Optional dependencies
55 To build the man pages, you will optionally need to install:
57 * Perl
58 * Pod::Man and Pod::Simple (Perl libraries)
60 For SELinux socket labelling support:
62 * libselinux
64 For the gzip filter:
66 * zlib
68 For the xz filter:
70 * liblzma
72 For the memory plugin with allocator=zstd:
74 * zstd
76 For the curl (HTTP/FTP) plugin:
78 * libcurl
80 For the ssh plugin:
82 * libssh >= 0.8.0
83   (this is a different library from libssh2 - that will not work)
85 For the iso plugin:
87 * xorriso or genisoimage or mkisofs
89 For the floppy plugin:
91 * iconv (on Linux this is built into glibc, on other systems
92   it may be a separate library)
94 For the libvirt plugin:
96 * libvirt
98 For the libguestfs plugin, and to run parts of the test suite:
100 * libguestfs
101 * guestfish (from libguestfs)
103 For the ext2 filter:
105 * ext2fs
106 * com_err
108 For the linuxdisk plugin:
110 * mke2fs >= 1.42.10 (from e2fsprogs)
112 For the nbd plugin, to get URI and TLS support, and also to run parts
113 of the test suite:
115 * libnbd >= 0.9.8
117 For the bittorrent plugin:
119 * [libtorrent-rasterbar](https://www.libtorrent.org)
121 For the blkio plugin:
123 * [libblkio](https://libblkio.gitlab.io/libblkio)
125 For the containerized data importer (CDI) plugin:
127 * podman
128 * jq
130 For the Perl and example4 plugins:
132 * perl interpreter
133 * perl development libraries
134 * perl modules ExtUtils::Embed
136 For the Python plugin:
138 * python interpreter (version 3 only)
139 * python development libraries
140 * python unittest to run the test suite
141 * boto3 is required to run the S3 plugin written in Python
143 For the OCaml plugin:
145 * OCaml >= 4.03
147 For the Tcl plugin:
149 * Tcl development library and headers
151 For the Lua plugin:
153 * Lua development library and headers
155 For the Rust plugin:
157 * cargo (other dependencies will be downloaded at build time)
159 To be able to write plugins in golang:
161 * go >= 1.13
163 For bash tab completion:
165 * bash-completion >= 1.99
167 To test for memory leaks (`make check-valgrind`):
169 * valgrind program and development headers
171 For non-essential enhancements to the test suite:
173 * expect
174 * flake8
175 * hexdump
176 * ip, ss (from iproute package)
177 * jq
178 * losetup (from util-linux package)
179 * mke2fs (from e2fsprogs)
180 * nbdcopy, nbdinfo, nbdsh (from libnbd)
181 * qemu-img, qemu-io, qemu-nbd (usually shipped with qemu)
182 * sfdisk (from util-linux)
183 * socat
184 * stat (from coreutils)
186 ### Building
189 To build from tarball:         To build from git:
191                                autoreconf -i
192 ./configure                    ./configure
193 make                           make
194 make check                     make check
197 On FreeBSD and OpenBSD which do not have GNU make by default you must
198 use `gmake` instead of `make`.
200 To run nbdkit from the source directory, use the top level ./nbdkit
201 wrapper.  It will run nbdkit and plugins from the locally compiled
202 directory:
205 $ ./nbdkit example1 -f -v
206 ./server/nbdkit ./plugins/example1/.libs/nbdkit-example1-plugin.so -f -v
207 [etc]
210 Optionally run this command as root to install everything:
213 make install
216 ### Python
218 Since nbdkit >= 1.16, only Python >= 3.6 is supported.
220 By default nbdkit uses the Python version of the Python interpreter
221 called “python” on the current $PATH.  If you have parallel versions
222 of Python installed then you can choose a different version by setting
223 the PYTHON variable when configuring.  For example:
226 ./configure PYTHON=/usr/bin/python3.8
229 ### OCaml
231 Most recent (less than, say, 8 years old) versions of the OCaml
232 compiler should work.  By default the configure script should detect
233 the bytecode and native code compilers and enable either one or both.
235 To enable OCaml warnings and turn them into hard errors (developers only):
238 ./configure OCAMLOPTFLAGS="-warn-error +A-3"
241 ### Running the tests
243 To run the test suite:
246 make check
249 If there is a failure, look at the corresponding `tests/*.log` file
250 for debug information.
252 A few tests require root privileges, and are skipped by default.  To
253 run them you must do:
256 make check-root
259 If you have the proprietary VDDK library, you can test
260 [nbdkit-vddk-plugin](plugins/vddk/) against the library like this:
263 make check-vddk vddkdir=vmware-vix-disklib-distrib
266 ### Running the benchmarks
268 To run benchmarks:
271 make bench
274 ## Download tarballs
276 Tarballs are available from:
277 http://libguestfs.org/download/nbdkit
279 ## Downstream packagers
281 If you are packaging nbdkit, use:
284 ./configure --with-extra='...'
287 providing extra information about the distribution, and/or
288 distro-specific versions.  It helps us with troubleshooting bug
289 reports.  (Also, talk to us!)
291 ## Developers
293 Install the valgrind program and development headers.
295 Use:
298 ./configure --enable-gcc-warnings --enable-valgrind
301 When testing use:
304 make check
305 make check-valgrind
308 For development ideas, see the [TODO](TODO) file.
310 The upstream git repository is:
311 https://gitlab.com/nbdkit/nbdkit
313 Please send patches to the libguestfs mailing list:
314 https://www.redhat.com/mailman/listinfo/libguestfs
316 For further information, see:
317 https://libguestfs.org/
318 https://github.com/NetworkBlockDevice/nbd/blob/master/doc/proto.md
320 ## Address sanitizer (ASAN)
322 You can compile nbdkit with clang and ASAN with:
325 ./configure CC=clang CXX=clang++ \
326             CFLAGS="-O0 -g -fsanitize=address -fno-omit-frame-pointer" \
327             --disable-linker-script \
328             --disable-golang
329 make clean
330 make
331 ASAN_OPTIONS="allocator_may_return_null=1 detect_leaks=false" make check
334 ## Test coverage
337 ./configure CFLAGS="--coverage -g" LDFLAGS="--coverage -g"
338 make clean
339 make
340 make check
342 lcov -c -d . -o gcov.info
343 genhtml -o coverage gcov.info
346 Open your browser and examine the `coverage/` directory.  At the time
347 of writing (2020-04) test coverage of the server is reasonable, but
348 things are much worse for certain plugins and filters.
350 ## macOS
352 nbdkit works on macOS and is mostly feature complete.  Some tests may
353 fail or be skipped.
355 We have tested macOS 12 (Monterey) using MacPorts.  Other versions of
356 macOS and Homebrew may work too.
358 We installed the following MacPorts packages:
360 * autoconf
361 * autoconf-archive
362 * automake
363 * bash
364 * coreutils
365 * gcc
366 * gmake
367 * gsed
368 * jq
369 * libtool
370 * m4
371 * ocaml
372 * pkg-config
373 * qemu
374 * ranlib
376 We configured nbdkit using:
379 ./configure --enable-gcc-warnings --disable-perl \
380             CFLAGS="-g -O2 -I/opt/local/include" \
381             LDFLAGS="-L/opt/local/lib"
384 ## Windows
386 Experimentally, the server can be compiled on Windows or
387 cross-compiled from Linux using mingw-w64.  Only a small subset of
388 features are available.  To find out what is missing read the TODO
389 "Windows port".
391 Note that GCC or Clang is required even if you are compiling on
392 Windows because of some C language extensions we use.  MSVC will not
393 work.
395 ### Cross-compiling from Linux to Windows
397 For the rest of this section we talk about cross-compiling for Windows
398 using Linux and mingw-w64.  At a minimum you will need:
400 * mingw-w64 GCC
401 * mingw-w64 dlfcn
402 * mingw-w64 winpthreads
403 * mingw-w64 gnutls  (optional, but highly recommended)
404 * wine              (if you want to run it on Linux)
406 You may want to patch Wine with this patch which adds support for
407 AF_UNIX sockets.  It is needed to get most of the test suite to work,
408 but if you don't care about the -U option then it is not needed.
409 https://www.winehq.org/pipermail/wine-devel/2021-May/187049.html
411 Other mingw-w64 libraries may be installed which will add
412 functionality (see full list of requirements above), but you may end
413 up hitting areas we have not compiled or tested before.
415 To cross compile do:
418 mingw64-configure --disable-ocaml --disable-perl --disable-vddk
419 mingw64-make
422 You can test if the server is working by doing:
425 ./nbdkit.exe --dump-config
428 (This usually runs wine automatically.  If not, you may need to prefix
429 the command "wine nbdkit.exe ...")
431 To see which plugins and filters were compiled:
434 find plugins filters -name '*.dll'
437 You can run them under Wine without installing using eg:
440 ./nbdkit.exe -f -v memory 1G
443 You can run the test suite in the usual way:
446 mingw64-make check
449 ### Running the cross-compiled binary on Windows
451 To test the binary on a real Windows system you will need to copy
452 server/.libs/nbdkit.exe, any plugins and filters you need
453 (`plugins/*/.libs/*.dll` and `filters/*/.libs/*.dll`), and many mingw
454 DLLs (`libdl.dll`, `libgnutls.dll`, `libwinpthread.dll`, etc.).
456 Notes:
458 1. libtool creates files called nbdkit.exe in the top level directory
459 and in [server](server/).  These are the stripped binaries.  The
460 "real" binaries are located in hidden `.libs/` subdirectories.
462 2. The top level `.libs/nbdkit.exe` is the wrapper used to run nbdkit
463 from the build directory, not the server binary.  You need
464 `server/.libs/nbdkit.exe` instead.
466 3. To find the list of mingw DLLs I ran nbdkit.exe iteratively until
467 Windows stopped complaining about missing libraries.  You could also
468 use a tool like Dependency Walker.
470 If you copy everything into a single directory on the Windows server
471 then you should be able to run nbdkit normally, eg:
474 nbdkit.exe -f -v nbdkit-memory-plugin.dll 1G
477 You will probably need to open port 10809 on the Windows Firewall.