├── .cirrus.yml ├── .dir-locals.el ├── .editorconfig ├── .gitattributes ├── .gitignore ├── .gitlab-ci.yml ├── COPYING.LIB ├── Makefile.am ├── README.md ├── SECURITY ├── TODO ├── bash-completion ├── Makefile.am ├── README └── nbdsh ├── ci ├── README.rst ├── build.sh ├── buildenv │ ├── almalinux-8.sh │ ├── alpine-315.sh │ ├── alpine-edge.sh │ ├── centos-stream-8.sh │ ├── debian-10-cross-i686.sh │ ├── debian-10.sh │ ├── debian-11-cross-i686.sh │ ├── debian-11.sh │ ├── debian-sid.sh │ ├── fedora-36.sh │ ├── fedora-37.sh │ ├── fedora-rawhide.sh │ ├── opensuse-leap-153.sh │ ├── opensuse-leap-154.sh │ ├── opensuse-tumbleweed.sh │ ├── ubuntu-1804.sh │ └── ubuntu-2004.sh ├── cirrus │ ├── build.yml │ ├── freebsd-12.vars │ ├── freebsd-13.vars │ ├── freebsd-current.vars │ └── macos-13.vars ├── containers │ ├── almalinux-8.Dockerfile │ ├── alpine-315.Dockerfile │ ├── alpine-edge.Dockerfile │ ├── centos-stream-8.Dockerfile │ ├── debian-10-cross-i686.Dockerfile │ ├── debian-10.Dockerfile │ ├── debian-11-cross-i686.Dockerfile │ ├── debian-11.Dockerfile │ ├── debian-sid.Dockerfile │ ├── fedora-36.Dockerfile │ ├── fedora-37.Dockerfile │ ├── fedora-rawhide.Dockerfile │ ├── opensuse-leap-153.Dockerfile │ ├── opensuse-leap-154.Dockerfile │ ├── opensuse-tumbleweed.Dockerfile │ ├── ubuntu-1804.Dockerfile │ └── ubuntu-2004.Dockerfile ├── gitlab.yml ├── gitlab │ ├── build-templates.yml │ ├── builds.yml │ ├── container-templates.yml │ └── containers.yml ├── manifest.yml └── skipped_tests ├── common-rules.mk ├── common ├── include │ ├── Makefile.am │ ├── ansi-colours.h │ ├── array-size.h │ ├── byte-swapping.h │ ├── checked-overflow.h │ ├── compiler-macros.h │ ├── isaligned.h │ ├── ispowerof2.h │ ├── iszero.h │ ├── minmax.h │ ├── rounding.h │ ├── static-assert.h │ ├── test-array-size.c │ ├── test-byte-swapping.c │ ├── test-checked-overflow.c │ ├── test-isaligned.c │ ├── test-ispowerof2.c │ ├── test-iszero.c │ ├── test-minmax.c │ └── unique-name.h └── utils │ ├── Makefile.am │ ├── bench.h │ ├── const-string-vector.h │ ├── human-size.c │ ├── human-size.h │ ├── nbdkit-string.h │ ├── string-vector.h │ ├── test-human-size.c │ ├── test-vector.c │ ├── vector.c │ ├── vector.h │ ├── version.c │ └── version.h ├── configure.ac ├── copy ├── Makefile.am ├── copy-block-to-nbd.sh ├── copy-file-to-file.sh ├── copy-file-to-nbd.sh ├── copy-file-to-null.sh ├── copy-file-to-qcow2-compressed.sh ├── copy-file-to-qcow2.sh ├── copy-nbd-error.sh ├── copy-nbd-to-block.sh ├── copy-nbd-to-file.sh ├── copy-nbd-to-hexdump.sh ├── copy-nbd-to-nbd.sh ├── copy-nbd-to-nbd2.sh ├── copy-nbd-to-null.sh ├── copy-nbd-to-small-block-error.sh ├── copy-nbd-to-small-nbd-error.sh ├── copy-nbd-to-sparse-file.sh ├── copy-nbd-to-stdout.sh ├── copy-progress-bar.sh ├── copy-sparse-allocated.sh ├── copy-sparse-no-extents.sh ├── copy-sparse-request-size.sh ├── copy-sparse-to-stream.sh ├── copy-sparse.sh ├── copy-stdin-to-nbd.sh ├── copy-stdin-to-null.sh ├── copy-tls.sh ├── copy-zero-to-nbd.sh ├── copy-zero-to-null.sh ├── file-ops.c ├── main.c ├── multi-thread-copying.c ├── nbd-ops.c ├── nbdcopy.h ├── nbdcopy.pod ├── null-ops.c ├── pipe-ops.c ├── progress.c ├── synch-copying.c ├── test-long-options.sh ├── test-short-options.sh ├── test-verbose.sh └── test-version.sh ├── docs ├── Makefile.am ├── libnbd-release-notes-1.10.pod ├── libnbd-release-notes-1.12.pod ├── libnbd-release-notes-1.14.pod ├── libnbd-release-notes-1.2.pod ├── libnbd-release-notes-1.4.pod ├── libnbd-release-notes-1.6.pod ├── libnbd-release-notes-1.8.pod ├── libnbd-security.pod ├── libnbd.pod ├── nbd_close.3 ├── nbd_create.pod ├── nbd_get_errno.3 └── nbd_get_error.3 ├── dump ├── Makefile.am ├── dump-data.sh ├── dump-empty-qcow2.sh ├── dump-pattern.sh ├── dump.c ├── nbddump.pod ├── test-long-options.sh ├── test-short-options.sh └── test-version.sh ├── examples ├── LICENSE-FOR-EXAMPLES ├── Makefile.am ├── aio-connect-read.c ├── batched-read-write.c ├── connect-command.c ├── copy-libev.c ├── encryption.c ├── fetch-first-sector.c ├── get-size.c ├── glib-main-loop.c ├── list-exports.c ├── open-qcow2.c ├── reads-and-writes.c ├── server-flags.c ├── strict-structured-reads.c └── threaded-reads-and-writes.c ├── fuse ├── Makefile.am ├── nbdfuse.c ├── nbdfuse.h ├── nbdfuse.pod ├── operations.c ├── test-errors.sh ├── test-file-mode.sh ├── test-long-options.sh ├── test-nbdkit-command.sh ├── test-nbdkit-file-null.sh ├── test-nbdkit.sh ├── test-parallel.sh ├── test-pattern.sh ├── test-qcow2.sh ├── test-short-options.sh ├── test-trim.sh ├── test-unix.sh ├── test-version.sh └── test-zero.sh ├── fuzzing ├── Makefile.am ├── README ├── libnbd-fuzz-wrapper.c ├── libnbd-libfuzzer-test.c └── testcase_dir │ ├── newstyle │ ├── newstyle-commands │ └── oldstyle ├── generator ├── API.ml ├── API.mli ├── C.ml ├── C.mli ├── GoLang.ml ├── GoLang.mli ├── Makefile.am ├── OCaml.ml ├── OCaml.mli ├── Python.ml ├── Python.mli ├── README.state-machine.md ├── generator.ml ├── state_machine.ml ├── state_machine.mli ├── state_machine_generator.ml ├── state_machine_generator.mli ├── states-connect-socket-activation.c ├── states-connect.c ├── states-issue-command.c ├── states-magic.c ├── states-newstyle-opt-export-name.c ├── states-newstyle-opt-go.c ├── states-newstyle-opt-list.c ├── states-newstyle-opt-meta-context.c ├── states-newstyle-opt-starttls.c ├── states-newstyle-opt-structured-reply.c ├── states-newstyle.c ├── states-oldstyle.c ├── states-reply-simple.c ├── states-reply-structured.c ├── states-reply.c ├── states.c ├── utils.ml └── utils.mli ├── golang ├── .gitignore ├── LICENSE ├── Makefile.am ├── README.md ├── aio_buffer.go ├── callbacks.go ├── configure │ ├── go.mod │ └── test.go ├── examples │ ├── LICENSE-FOR-EXAMPLES │ ├── Makefile.am │ ├── aio_copy │ │ ├── aio_copy.go │ │ └── go.mod │ ├── get_size │ │ ├── get_size.go │ │ └── go.mod │ ├── read_first_sector │ │ ├── go.mod │ │ └── read_first_sector.go │ └── simple_copy │ │ ├── go.mod │ │ └── simple_copy.go ├── go.mod ├── handle.go ├── libnbd-golang.pod ├── libnbd_010_load_test.go ├── libnbd_020_aio_buffer_test.go ├── libnbd_100_handle_test.go ├── libnbd_110_defaults_test.go ├── libnbd_120_set_non_defaults_test.go ├── libnbd_200_connect_command_test.go ├── libnbd_210_opt_abort_test.go ├── libnbd_220_opt_list_test.go ├── libnbd_230_opt_info_test.go ├── libnbd_240_opt_list_meta_test.go ├── libnbd_245_opt_list_meta_queries_test.go ├── libnbd_250_opt_set_meta_test.go ├── libnbd_255_opt_set_meta_queries_test.go ├── libnbd_300_get_size_test.go ├── libnbd_400_pread_test.go ├── libnbd_405_pread_structured_test.go ├── libnbd_410_pwrite_test.go ├── libnbd_460_block_status_test.go ├── libnbd_500_aio_pread_test.go ├── libnbd_510_aio_pwrite_test.go ├── libnbd_590_aio_copy_test.go ├── libnbd_600_debug_callback_test.go ├── libnbd_610_error_test.go ├── libnbd_620_stats_test.go ├── make-dist.sh └── run-tests.sh ├── html └── pod.css ├── include └── Makefile.am ├── info ├── Makefile.am ├── can.c ├── info-atomic-output.sh ├── info-can-connect.sh ├── info-can-read.sh ├── info-can-zero.sh ├── info-can.sh ├── info-cmd-json.sh ├── info-cmd-map-totals.sh ├── info-cmd-size.sh ├── info-description-qemu.sh ├── info-description.sh ├── info-is-read-only.sh ├── info-json.sh ├── info-list-json-qemu.sh ├── info-list-json.sh ├── info-list-qemu.sh ├── info-list-uris.sh ├── info-list.sh ├── info-map-base-allocation-json.sh ├── info-map-base-allocation-large.sh ├── info-map-base-allocation-weird.sh ├── info-map-base-allocation-zero.sh ├── info-map-base-allocation.sh ├── info-map-qemu-allocation-depth.sh ├── info-map-qemu-dirty-bitmap.sh ├── info-map-totals-json.sh ├── info-map-totals.sh ├── info-null.sh ├── info-oldstyle.sh ├── info-packets.sh ├── info-size.sh ├── info-text.sh ├── info-uri-nbds.sh ├── info-uri.sh ├── list.c ├── main.c ├── map.c ├── nbdinfo.h ├── nbdinfo.pod ├── show.c ├── size.c ├── test-long-options.sh ├── test-short-options.sh ├── test-version.sh └── utils.c ├── interop ├── Makefile.am ├── dirty-bitmap.c ├── dirty-bitmap.sh ├── interop-qemu-block-size.sh ├── interop-qemu-storage-daemon.sh ├── interop.c ├── list-exports-nbd-config ├── list-exports-test-dir │ ├── disk1 │ └── disk2 ├── list-exports.c ├── nbd-server-tls.conf.in ├── socket-activation.c ├── structured-read.c └── structured-read.sh ├── lib ├── Makefile.am ├── aio.c ├── connect.c ├── crypto.c ├── debug.c ├── disconnect.c ├── errors.c ├── flags.c ├── handle.c ├── internal.h ├── is-state.c ├── libnbd.pc.in ├── local │ └── libnbd.pc.in ├── nbd-protocol.h ├── opt.c ├── poll.c ├── protocol.c ├── rw.c ├── socket.c ├── test-fork-safe-assert.c ├── test-fork-safe-assert.sh ├── test-fork-safe-execvpe.c ├── test-fork-safe-execvpe.sh ├── uri.c └── utils.c ├── m4 ├── ac_c_compile_flags.m4 ├── ax_pthread.m4 └── ocaml.m4 ├── ocaml ├── META.in ├── Makefile.am ├── buffer.c ├── examples │ ├── LICENSE-FOR-EXAMPLES │ ├── Makefile.am │ ├── asynch_copy.ml │ ├── extents.ml │ ├── get_size.ml │ ├── open_qcow2.ml │ └── server_flags.ml ├── handle.c ├── helpers.c ├── libnbd-ocaml.pod ├── nbd-c.h └── tests │ ├── Makefile.am │ ├── test_010_import.ml │ ├── test_100_handle.ml │ ├── test_105_with_handle.ml │ ├── test_110_defaults.ml │ ├── test_120_set_non_defaults.ml │ ├── test_130_private_data.ml │ ├── test_140_explicit_close.ml │ ├── test_200_connect_command.ml │ ├── test_210_opt_abort.ml │ ├── test_220_opt_list.ml │ ├── test_230_opt_info.ml │ ├── test_240_opt_list_meta.ml │ ├── test_245_opt_list_meta_queries.ml │ ├── test_250_opt_set_meta.ml │ ├── test_255_opt_set_meta_queries.ml │ ├── test_300_get_size.ml │ ├── test_400_pread.ml │ ├── test_405_pread_structured.ml │ ├── test_410_pwrite.ml │ ├── test_460_block_status.ml │ ├── test_500_aio_pread.ml │ ├── test_505_aio_pread_structured_callback.ml │ ├── test_510_aio_pwrite.ml │ ├── test_580_aio_connect.ml │ ├── test_590_aio_copy.ml │ ├── test_600_debug_callback.ml │ ├── test_610_exception.ml │ └── test_620_stats.ml ├── podwrapper.pl.in ├── python ├── .flake8 ├── Makefile.am ├── examples │ ├── LICENSE-FOR-EXAMPLES │ └── checksum.py ├── handle.c ├── nbdsh.py ├── pycodestyle.sh ├── run-python-tests.in ├── t │ ├── 010-import.py │ ├── 100-handle.py │ ├── 105-with-handle.py │ ├── 110-defaults.py │ ├── 120-set-non-defaults.py │ ├── 140-explicit-close.py │ ├── 200-connect-command.py │ ├── 210-opt-abort.py │ ├── 220-opt-list.py │ ├── 230-opt-info.py │ ├── 240-opt-list-meta.py │ ├── 245-opt-list-meta-queries.py │ ├── 250-opt-set-meta.py │ ├── 255-opt-set-meta-queries.py │ ├── 300-get-size.py │ ├── 400-pread.py │ ├── 405-pread-structured.py │ ├── 410-pwrite.py │ ├── 460-block-status.py │ ├── 500-aio-pread.py │ ├── 505-aio-pread-callback.py │ ├── 510-aio-pwrite.py │ ├── 580-aio-is-zero.py │ ├── 585-aio-buffer-share.py │ ├── 590-aio-copy.py │ ├── 600-debug-callback.py │ ├── 610-exception.py │ └── 620-stats.py ├── test-aio-connect-unix.sh └── utils.c ├── run.in ├── scripts └── git.orderfile ├── sh ├── Makefile.am ├── examples │ ├── LICENSE-FOR-EXAMPLES │ └── hexdump.sh ├── nbdsh.in ├── nbdsh.pod ├── test-context.sh ├── test-error.sh ├── test-help.sh ├── test-implicit-handle.sh ├── test-long-options.sh ├── test-pattern.sh ├── test-short-options.sh ├── test-verbose.sh └── test-version.sh ├── subdir-rules.mk ├── tests ├── Makefile.am ├── aio-connect-port.c ├── aio-connect.c ├── aio-parallel-load-tls.sh ├── aio-parallel-load.c ├── aio-parallel-load.sh ├── aio-parallel-tls.sh ├── aio-parallel.c ├── aio-parallel.sh ├── close-null.c ├── closure-lifetimes.c ├── compile-c.c ├── compile-cxx.cpp ├── compile-header-only.c ├── compile-iso-c99.c ├── connect-systemd-socket-activation.c ├── connect-tcp.c ├── connect-tcp6.c ├── connect-tls.c ├── connect-unix.c ├── connect-uri-nbd-vsock.sh ├── connect-uri.c ├── debug-environment.c ├── debug.c ├── dlopen.c ├── eflags-plugin.sh ├── eflags.c ├── errors-bad-cookie.c ├── errors-bitmask.c ├── errors-client-oversize.c ├── errors-client-unadvertised-cmd.c ├── errors-client-unaligned.c ├── errors-client-unknown-flags.c ├── errors-client-zerosize.c ├── errors-connect-null.c ├── errors-connect-twice.c ├── errors-enum.c ├── errors-multiple-disconnects.c ├── errors-name-too-long.c ├── errors-not-connected.c ├── errors-not-negotiating.c ├── errors-notify-not-blocked.c ├── errors-poll-no-fd.c ├── errors-pread-structured.c ├── errors-server-invalid-offset.c ├── errors-server-oversize.c ├── errors-server-unadvertised-cmd.c ├── errors-server-unaligned.c ├── errors-server-unknown-flags.c ├── errors-server-zerosize.c ├── export-name.c ├── functions.sh.in ├── get-size.c ├── get-version.c ├── make-pki.sh ├── meta-base-allocation.c ├── meta-base-allocation.sh ├── newstyle-limited.c ├── oldstyle.c ├── opt-abort.c ├── opt-info.c ├── opt-info.sh ├── opt-list-meta-queries.c ├── opt-list-meta.c ├── opt-list.c ├── opt-list.sh ├── opt-set-meta-queries.c ├── opt-set-meta.c ├── opt-starttls.c ├── opt-structured-twice.c ├── pick-a-port.c ├── pick-a-port.h ├── pread-initialize.c ├── private-data.c ├── read-only-flag.c ├── read-write-flag.c ├── requires.c ├── requires.h ├── server-death.c ├── shutdown-flags.c ├── synch-parallel-tls.sh ├── synch-parallel.c └── synch-parallel.sh ├── ublk ├── Makefile.am ├── nbdublk.c ├── nbdublk.h ├── nbdublk.pod ├── not.cpp └── tgt.c └── valgrind ├── Makefile.am ├── glibc.suppressions ├── gnutls.suppressions ├── libnbd.suppressions └── ocaml.suppressions /.cirrus.yml: -------------------------------------------------------------------------------- 1 | # This file is here only for Cirrus CI to notice this repository 2 | # The builds are run automatically using cirrus-ci command 3 | # See ci/README.rst for details 4 | -------------------------------------------------------------------------------- /.dir-locals.el: -------------------------------------------------------------------------------- 1 | ;;; Directory Local Variables 2 | ;;; For more information see (info "(emacs) Directory Variables") 3 | ((autoconf-mode . ((indent-tabs-mode . nil))) 4 | (c-mode . ((indent-tabs-mode . nil) 5 | (c-basic-offset . 2)))) 6 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # https://editorconfig.org/ 2 | 3 | root = true 4 | 5 | [*] 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | charset = utf-8 11 | 12 | [*.pod] 13 | # Indented code samples in pod require trailing whitespace 14 | trim_trailing_whitespace = false 15 | 16 | [{*.py,*.py.in,*.pl,*.pl.in,*.sh,*.sh.in}] 17 | indent_size = 4 18 | 19 | [{*.go,go.mod,go.sum}] 20 | # Match gofmt style 21 | indent_style = tab 22 | indent_size = 4 23 | 24 | [{Makefile,Makefile.in,Makefile.am,*.mk}] 25 | # Make requires tabs. 26 | indent_style = tab 27 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Use various builtin diff parsers 2 | *.py diff=python 3 | *.c diff=cpp 4 | *.h diff=cpp 5 | *.go diff=golang 6 | *.md diff=markdown 7 | 8 | # Use the following one-time config to get nicer diffs of various files: 9 | # git config diff.ml.xfuncname '^(type|and|val|let) .*=' 10 | # git config diff.ml-api.xfuncname '^(let .*=| "[^"]*", \{$)' 11 | # git config diff.mli.xfuncname '^(type|and|val|module) ' 12 | # git config diff.states.xfuncname '^([a-zA-Z_].*| [A-Z._0-9]*:$)' 13 | *.ml diff=ml 14 | *.mli diff=mli 15 | API.ml diff=ml-api 16 | generator/states-*.c diff=states 17 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | variables: 2 | GIT_DEPTH: 100 3 | DOCKER_DRIVER: overlay2 4 | 5 | stages: 6 | - containers 7 | - builds 8 | - sanity_checks 9 | 10 | .script_variables: &script_variables | 11 | export MAKEFLAGS="-j $(getconf _NPROCESSORS_ONLN)" 12 | export CCACHE_BASEDIR="$(pwd)" 13 | export CCACHE_DIR="$CCACHE_BASEDIR/ccache" 14 | export CCACHE_MAXSIZE="500M" 15 | export PATH="$CCACHE_WRAPPERSDIR:$PATH" 16 | 17 | include: '/ci/gitlab.yml' 18 | 19 | .base_build_job: 20 | cache: 21 | paths: 22 | - ccache/ 23 | key: "$CI_JOB_NAME" 24 | script: 25 | - *script_variables 26 | - ci/build.sh 27 | artifacts: 28 | paths: 29 | - "config.log" 30 | - "**/test-suite.log" 31 | public: true 32 | when: always 33 | expire_in: 1 week 34 | 35 | .native_build_job_prebuilt_env: 36 | extends: 37 | - .base_build_job 38 | - .gitlab_native_build_job_prebuilt_env 39 | 40 | .native_build_job_local_env: 41 | extends: 42 | - .base_build_job 43 | - .gitlab_native_build_job_local_env 44 | 45 | .cross_build_job_prebuilt_env: 46 | extends: 47 | - .base_build_job 48 | - .gitlab_cross_build_job_prebuilt_env 49 | 50 | .cross_build_job_local_env: 51 | extends: 52 | - .base_build_job 53 | - .gitlab_cross_build_job_local_env 54 | -------------------------------------------------------------------------------- /SECURITY: -------------------------------------------------------------------------------- 1 | If you think you've found a serious or potential security bug that you 2 | don't want to report on a public mailing list, then send email to both 3 | and . 4 | 5 | Make it clear in the email Subject line that it's a serious or 6 | security-related bug in libnbd. 7 | 8 | You can also sign and/or encrypt messages using our GPG public keys 9 | available on the usual keyservers. 10 | available on the usual keyservers, or online here: 11 | https://download.libguestfs.org/libguestfs.keyring 12 | 13 | For information about past security issues, see 14 | docs/libnbd-security.pod, or the libnbd-security(1) man page if you 15 | have installed libnbd, also available online here: 16 | http://libguestfs.org/libnbd-security.3.html 17 | -------------------------------------------------------------------------------- /bash-completion/Makefile.am: -------------------------------------------------------------------------------- 1 | # nbd client library in userspace 2 | # Copyright Red Hat 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 2 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | include $(top_srcdir)/subdir-rules.mk 19 | 20 | EXTRA_DIST = \ 21 | README \ 22 | nbdsh \ 23 | $(NULL) 24 | 25 | if HAVE_BASH_COMPLETION 26 | 27 | bashcomp_DATA = nbddump nbdfuse nbdsh nbdublk 28 | 29 | if HAVE_LIBXML2 30 | bashcomp_DATA += nbdcopy nbdinfo 31 | endif HAVE_LIBXML2 32 | 33 | nbdcopy: nbdsh 34 | rm -f $@ 35 | $(LN_S) $(srcdir)/nbdsh $@ 36 | 37 | nbddump: nbdsh 38 | rm -f $@ 39 | $(LN_S) $(srcdir)/nbdsh $@ 40 | 41 | nbdfuse: nbdsh 42 | rm -f $@ 43 | $(LN_S) $(srcdir)/nbdsh $@ 44 | 45 | nbdinfo: nbdsh 46 | rm -f $@ 47 | $(LN_S) $(srcdir)/nbdsh $@ 48 | 49 | nbdublk: nbdsh 50 | rm -f $@ 51 | $(LN_S) $(srcdir)/nbdsh $@ 52 | 53 | CLEANFILES += nbdcopy nbddump nbdfuse nbdinfo nbdublk 54 | 55 | endif 56 | -------------------------------------------------------------------------------- /bash-completion/README: -------------------------------------------------------------------------------- 1 | This directory contains the scripts for tab-completing commands in 2 | bash. Note these new-style demand-loaded scripts require 3 | bash-completion >= 1.99. 4 | 5 | Tip: To test the bash completions without having to install them, 6 | simply start a new shell and run this command: 7 | 8 | ./run bash 9 | source ./bash-completion/nbdsh 10 | -------------------------------------------------------------------------------- /ci/buildenv/alpine-315.sh: -------------------------------------------------------------------------------- 1 | # THIS FILE WAS AUTO-GENERATED 2 | # 3 | # $ lcitool manifest ci/manifest.yml 4 | # 5 | # https://gitlab.com/libvirt/libvirt-ci 6 | 7 | function install_buildenv() { 8 | apk update 9 | apk upgrade 10 | apk add \ 11 | autoconf \ 12 | automake \ 13 | bash-completion \ 14 | ca-certificates \ 15 | ccache \ 16 | clang \ 17 | diffutils \ 18 | fuse3 \ 19 | fuse3-dev \ 20 | g++ \ 21 | gcc \ 22 | git \ 23 | glib-dev \ 24 | gnutls-dev \ 25 | gnutls-utils \ 26 | go \ 27 | hexdump \ 28 | iproute2 \ 29 | jq \ 30 | libev-dev \ 31 | libtool \ 32 | libxml2-dev \ 33 | make \ 34 | musl-dev \ 35 | nbd \ 36 | nbd-client \ 37 | ocaml \ 38 | ocaml-findlib-dev \ 39 | ocaml-ocamldoc \ 40 | perl \ 41 | pkgconf \ 42 | py3-flake8 \ 43 | python3-dev \ 44 | qemu \ 45 | qemu-img \ 46 | sed \ 47 | valgrind 48 | apk list | sort > /packages.txt 49 | mkdir -p /usr/libexec/ccache-wrappers 50 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/c++ 51 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/cc 52 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/clang 53 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/g++ 54 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/gcc 55 | } 56 | 57 | export CCACHE_WRAPPERSDIR="/usr/libexec/ccache-wrappers" 58 | export LANG="en_US.UTF-8" 59 | export MAKE="/usr/bin/make" 60 | -------------------------------------------------------------------------------- /ci/buildenv/alpine-edge.sh: -------------------------------------------------------------------------------- 1 | # THIS FILE WAS AUTO-GENERATED 2 | # 3 | # $ lcitool manifest ci/manifest.yml 4 | # 5 | # https://gitlab.com/libvirt/libvirt-ci 6 | 7 | function install_buildenv() { 8 | apk update 9 | apk upgrade 10 | apk add \ 11 | autoconf \ 12 | automake \ 13 | bash-completion \ 14 | ca-certificates \ 15 | ccache \ 16 | clang \ 17 | diffutils \ 18 | fuse3 \ 19 | fuse3-dev \ 20 | g++ \ 21 | gcc \ 22 | git \ 23 | glib-dev \ 24 | gnutls-dev \ 25 | gnutls-utils \ 26 | go \ 27 | hexdump \ 28 | iproute2 \ 29 | jq \ 30 | libev-dev \ 31 | libtool \ 32 | libxml2-dev \ 33 | make \ 34 | musl-dev \ 35 | nbd \ 36 | nbd-client \ 37 | ocaml \ 38 | ocaml-findlib-dev \ 39 | ocaml-ocamldoc \ 40 | perl \ 41 | pkgconf \ 42 | py3-flake8 \ 43 | python3-dev \ 44 | qemu \ 45 | qemu-img \ 46 | sed \ 47 | valgrind 48 | apk list | sort > /packages.txt 49 | mkdir -p /usr/libexec/ccache-wrappers 50 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/c++ 51 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/cc 52 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/clang 53 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/g++ 54 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/gcc 55 | } 56 | 57 | export CCACHE_WRAPPERSDIR="/usr/libexec/ccache-wrappers" 58 | export LANG="en_US.UTF-8" 59 | export MAKE="/usr/bin/make" 60 | -------------------------------------------------------------------------------- /ci/buildenv/fedora-36.sh: -------------------------------------------------------------------------------- 1 | # THIS FILE WAS AUTO-GENERATED 2 | # 3 | # $ lcitool manifest ci/manifest.yml 4 | # 5 | # https://gitlab.com/libvirt/libvirt-ci 6 | 7 | function install_buildenv() { 8 | dnf update -y 9 | dnf install -y \ 10 | autoconf \ 11 | automake \ 12 | bash-completion \ 13 | ca-certificates \ 14 | ccache \ 15 | clang \ 16 | diffutils \ 17 | fuse3 \ 18 | fuse3-devel \ 19 | gcc \ 20 | gcc-c++ \ 21 | git \ 22 | glib2-devel \ 23 | glibc-devel \ 24 | glibc-langpack-en \ 25 | gnutls-devel \ 26 | gnutls-utils \ 27 | golang \ 28 | iproute \ 29 | jq \ 30 | libev-devel \ 31 | libtool \ 32 | libxml2-devel \ 33 | make \ 34 | nbd \ 35 | nbdkit \ 36 | ocaml \ 37 | ocaml-findlib \ 38 | ocamldoc \ 39 | perl-Pod-Simple \ 40 | perl-base \ 41 | perl-podlators \ 42 | pkgconfig \ 43 | python3-devel \ 44 | python3-flake8 \ 45 | qemu-img \ 46 | qemu-kvm \ 47 | sed \ 48 | util-linux \ 49 | valgrind 50 | rpm -qa | sort > /packages.txt 51 | mkdir -p /usr/libexec/ccache-wrappers 52 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/c++ 53 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/cc 54 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/clang 55 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/g++ 56 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/gcc 57 | } 58 | 59 | export CCACHE_WRAPPERSDIR="/usr/libexec/ccache-wrappers" 60 | export LANG="en_US.UTF-8" 61 | export MAKE="/usr/bin/make" 62 | -------------------------------------------------------------------------------- /ci/buildenv/fedora-37.sh: -------------------------------------------------------------------------------- 1 | # THIS FILE WAS AUTO-GENERATED 2 | # 3 | # $ lcitool manifest ci/manifest.yml 4 | # 5 | # https://gitlab.com/libvirt/libvirt-ci 6 | 7 | function install_buildenv() { 8 | dnf update -y 9 | dnf install -y \ 10 | autoconf \ 11 | automake \ 12 | bash-completion \ 13 | ca-certificates \ 14 | ccache \ 15 | clang \ 16 | diffutils \ 17 | fuse3 \ 18 | fuse3-devel \ 19 | gcc \ 20 | gcc-c++ \ 21 | git \ 22 | glib2-devel \ 23 | glibc-devel \ 24 | glibc-langpack-en \ 25 | gnutls-devel \ 26 | gnutls-utils \ 27 | golang \ 28 | iproute \ 29 | jq \ 30 | libev-devel \ 31 | libtool \ 32 | libxml2-devel \ 33 | make \ 34 | nbd \ 35 | nbdkit \ 36 | ocaml \ 37 | ocaml-findlib \ 38 | ocamldoc \ 39 | perl-Pod-Simple \ 40 | perl-base \ 41 | perl-podlators \ 42 | pkgconfig \ 43 | python3-devel \ 44 | python3-flake8 \ 45 | qemu-img \ 46 | qemu-kvm \ 47 | sed \ 48 | util-linux \ 49 | valgrind 50 | rpm -qa | sort > /packages.txt 51 | mkdir -p /usr/libexec/ccache-wrappers 52 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/c++ 53 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/cc 54 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/clang 55 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/g++ 56 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/gcc 57 | } 58 | 59 | export CCACHE_WRAPPERSDIR="/usr/libexec/ccache-wrappers" 60 | export LANG="en_US.UTF-8" 61 | export MAKE="/usr/bin/make" 62 | -------------------------------------------------------------------------------- /ci/buildenv/fedora-rawhide.sh: -------------------------------------------------------------------------------- 1 | # THIS FILE WAS AUTO-GENERATED 2 | # 3 | # $ lcitool manifest ci/manifest.yml 4 | # 5 | # https://gitlab.com/libvirt/libvirt-ci 6 | 7 | function install_buildenv() { 8 | dnf update -y --nogpgcheck fedora-gpg-keys 9 | dnf distro-sync -y 10 | dnf install -y \ 11 | autoconf \ 12 | automake \ 13 | bash-completion \ 14 | ca-certificates \ 15 | ccache \ 16 | clang \ 17 | diffutils \ 18 | fuse3 \ 19 | fuse3-devel \ 20 | gcc \ 21 | gcc-c++ \ 22 | git \ 23 | glib2-devel \ 24 | glibc-devel \ 25 | glibc-langpack-en \ 26 | gnutls-devel \ 27 | gnutls-utils \ 28 | golang \ 29 | iproute \ 30 | jq \ 31 | libev-devel \ 32 | libtool \ 33 | libxml2-devel \ 34 | make \ 35 | nbd \ 36 | nbdkit \ 37 | ocaml \ 38 | ocaml-findlib \ 39 | ocamldoc \ 40 | perl-Pod-Simple \ 41 | perl-base \ 42 | perl-podlators \ 43 | pkgconfig \ 44 | python3-devel \ 45 | python3-flake8 \ 46 | qemu-img \ 47 | qemu-kvm \ 48 | sed \ 49 | util-linux \ 50 | valgrind 51 | rpm -qa | sort > /packages.txt 52 | mkdir -p /usr/libexec/ccache-wrappers 53 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/c++ 54 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/cc 55 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/clang 56 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/g++ 57 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/gcc 58 | } 59 | 60 | export CCACHE_WRAPPERSDIR="/usr/libexec/ccache-wrappers" 61 | export LANG="en_US.UTF-8" 62 | export MAKE="/usr/bin/make" 63 | -------------------------------------------------------------------------------- /ci/cirrus/build.yml: -------------------------------------------------------------------------------- 1 | @CIRRUS_VM_INSTANCE_TYPE@: 2 | @CIRRUS_VM_IMAGE_SELECTOR@: @CIRRUS_VM_IMAGE_NAME@ 3 | 4 | env: 5 | CI_REPOSITORY_URL: "@CI_REPOSITORY_URL@" 6 | CI_COMMIT_REF_NAME: "@CI_COMMIT_REF_NAME@" 7 | CI_COMMIT_SHA: "@CI_COMMIT_SHA@" 8 | PATH: "@PATH@" 9 | PKG_CONFIG_PATH: "@PKG_CONFIG_PATH@" 10 | PYTHON: "@PYTHON@" 11 | MAKE: "@MAKE@" 12 | 13 | build_task: 14 | install_script: 15 | - @UPDATE_COMMAND@ 16 | - @UPGRADE_COMMAND@ 17 | - @INSTALL_COMMAND@ @PKGS@ 18 | - if test -n "@PYPI_PKGS@" ; then @PIP3@ install @PYPI_PKGS@ ; fi 19 | clone_script: 20 | - git clone --depth 100 "$CI_REPOSITORY_URL" . 21 | - git fetch origin "$CI_COMMIT_REF_NAME" 22 | - git reset --hard "$CI_COMMIT_SHA" 23 | build_script: 24 | - ci/build.sh 25 | -------------------------------------------------------------------------------- /ci/cirrus/freebsd-12.vars: -------------------------------------------------------------------------------- 1 | # THIS FILE WAS AUTO-GENERATED 2 | # 3 | # $ lcitool manifest ci/manifest.yml 4 | # 5 | # https://gitlab.com/libvirt/libvirt-ci 6 | 7 | CCACHE='/usr/local/bin/ccache' 8 | CPAN_PKGS='' 9 | CROSS_PKGS='' 10 | MAKE='/usr/local/bin/gmake' 11 | NINJA='/usr/local/bin/ninja' 12 | PACKAGING_COMMAND='pkg' 13 | PIP3='/usr/local/bin/pip-3.8' 14 | PKGS='autoconf automake bash-completion ca_root_nss ccache diffutils fusefs-libs3 git glib gmake gnutls go gsed jq libev libtool libxml2 nbd-server nbdkit ocaml ocaml-findlib p5-Pod-Simple perl5 pkgconf py39-flake8 python3 qemu valgrind' 15 | PYPI_PKGS='' 16 | PYTHON='/usr/local/bin/python3' 17 | -------------------------------------------------------------------------------- /ci/cirrus/freebsd-13.vars: -------------------------------------------------------------------------------- 1 | # THIS FILE WAS AUTO-GENERATED 2 | # 3 | # $ lcitool manifest ci/manifest.yml 4 | # 5 | # https://gitlab.com/libvirt/libvirt-ci 6 | 7 | CCACHE='/usr/local/bin/ccache' 8 | CPAN_PKGS='' 9 | CROSS_PKGS='' 10 | MAKE='/usr/local/bin/gmake' 11 | NINJA='/usr/local/bin/ninja' 12 | PACKAGING_COMMAND='pkg' 13 | PIP3='/usr/local/bin/pip-3.8' 14 | PKGS='autoconf automake bash-completion ca_root_nss ccache diffutils fusefs-libs3 git glib gmake gnutls go gsed jq libev libtool libxml2 nbd-server nbdkit ocaml ocaml-findlib p5-Pod-Simple perl5 pkgconf py39-flake8 python3 qemu valgrind' 15 | PYPI_PKGS='' 16 | PYTHON='/usr/local/bin/python3' 17 | -------------------------------------------------------------------------------- /ci/cirrus/freebsd-current.vars: -------------------------------------------------------------------------------- 1 | # THIS FILE WAS AUTO-GENERATED 2 | # 3 | # $ lcitool manifest ci/manifest.yml 4 | # 5 | # https://gitlab.com/libvirt/libvirt-ci 6 | 7 | CCACHE='/usr/local/bin/ccache' 8 | CPAN_PKGS='' 9 | CROSS_PKGS='' 10 | MAKE='/usr/local/bin/gmake' 11 | NINJA='/usr/local/bin/ninja' 12 | PACKAGING_COMMAND='pkg' 13 | PIP3='/usr/local/bin/pip-3.8' 14 | PKGS='autoconf automake bash-completion ca_root_nss ccache diffutils fusefs-libs3 git glib gmake gnutls go gsed jq libev libtool libxml2 nbd-server nbdkit ocaml ocaml-findlib p5-Pod-Simple perl5 pkgconf py39-flake8 python3 qemu valgrind' 15 | PYPI_PKGS='' 16 | PYTHON='/usr/local/bin/python3' 17 | -------------------------------------------------------------------------------- /ci/cirrus/macos-13.vars: -------------------------------------------------------------------------------- 1 | # THIS FILE WAS AUTO-GENERATED 2 | # 3 | # $ lcitool manifest ci/manifest.yml 4 | # 5 | # https://gitlab.com/libvirt/libvirt-ci 6 | 7 | CCACHE='/opt/homebrew/bin/ccache' 8 | CPAN_PKGS='' 9 | CROSS_PKGS='' 10 | MAKE='/opt/homebrew/bin/gmake' 11 | NINJA='/opt/homebrew/bin/ninja' 12 | PACKAGING_COMMAND='brew' 13 | PIP3='/opt/homebrew/bin/pip3' 14 | PKGS='autoconf automake bash-completion ccache diffutils flake8 git glib gnu-sed gnutls golang jq libev libtool libxml2 make ocaml ocaml-findlib perl pkg-config python3 qemu' 15 | PYPI_PKGS='' 16 | PYTHON='/opt/homebrew/bin/python3' 17 | -------------------------------------------------------------------------------- /ci/containers/alpine-315.Dockerfile: -------------------------------------------------------------------------------- 1 | # THIS FILE WAS AUTO-GENERATED 2 | # 3 | # $ lcitool manifest ci/manifest.yml 4 | # 5 | # https://gitlab.com/libvirt/libvirt-ci 6 | 7 | FROM docker.io/library/alpine:3.15 8 | 9 | RUN apk update && \ 10 | apk upgrade && \ 11 | apk add \ 12 | autoconf \ 13 | automake \ 14 | bash-completion \ 15 | ca-certificates \ 16 | ccache \ 17 | clang \ 18 | diffutils \ 19 | fuse3 \ 20 | fuse3-dev \ 21 | g++ \ 22 | gcc \ 23 | git \ 24 | glib-dev \ 25 | gnutls-dev \ 26 | gnutls-utils \ 27 | go \ 28 | hexdump \ 29 | iproute2 \ 30 | jq \ 31 | libev-dev \ 32 | libtool \ 33 | libxml2-dev \ 34 | make \ 35 | musl-dev \ 36 | nbd \ 37 | nbd-client \ 38 | ocaml \ 39 | ocaml-findlib-dev \ 40 | ocaml-ocamldoc \ 41 | perl \ 42 | pkgconf \ 43 | py3-flake8 \ 44 | python3-dev \ 45 | qemu \ 46 | qemu-img \ 47 | sed \ 48 | valgrind && \ 49 | apk list | sort > /packages.txt && \ 50 | mkdir -p /usr/libexec/ccache-wrappers && \ 51 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/c++ && \ 52 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/cc && \ 53 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/clang && \ 54 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/g++ && \ 55 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/gcc 56 | 57 | ENV CCACHE_WRAPPERSDIR "/usr/libexec/ccache-wrappers" 58 | ENV LANG "en_US.UTF-8" 59 | ENV MAKE "/usr/bin/make" 60 | -------------------------------------------------------------------------------- /ci/containers/alpine-edge.Dockerfile: -------------------------------------------------------------------------------- 1 | # THIS FILE WAS AUTO-GENERATED 2 | # 3 | # $ lcitool manifest ci/manifest.yml 4 | # 5 | # https://gitlab.com/libvirt/libvirt-ci 6 | 7 | FROM docker.io/library/alpine:edge 8 | 9 | RUN apk update && \ 10 | apk upgrade && \ 11 | apk add \ 12 | autoconf \ 13 | automake \ 14 | bash-completion \ 15 | ca-certificates \ 16 | ccache \ 17 | clang \ 18 | diffutils \ 19 | fuse3 \ 20 | fuse3-dev \ 21 | g++ \ 22 | gcc \ 23 | git \ 24 | glib-dev \ 25 | gnutls-dev \ 26 | gnutls-utils \ 27 | go \ 28 | hexdump \ 29 | iproute2 \ 30 | jq \ 31 | libev-dev \ 32 | libtool \ 33 | libxml2-dev \ 34 | make \ 35 | musl-dev \ 36 | nbd \ 37 | nbd-client \ 38 | ocaml \ 39 | ocaml-findlib-dev \ 40 | ocaml-ocamldoc \ 41 | perl \ 42 | pkgconf \ 43 | py3-flake8 \ 44 | python3-dev \ 45 | qemu \ 46 | qemu-img \ 47 | sed \ 48 | valgrind && \ 49 | apk list | sort > /packages.txt && \ 50 | mkdir -p /usr/libexec/ccache-wrappers && \ 51 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/c++ && \ 52 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/cc && \ 53 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/clang && \ 54 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/g++ && \ 55 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/gcc 56 | 57 | ENV CCACHE_WRAPPERSDIR "/usr/libexec/ccache-wrappers" 58 | ENV LANG "en_US.UTF-8" 59 | ENV MAKE "/usr/bin/make" 60 | -------------------------------------------------------------------------------- /ci/gitlab/container-templates.yml: -------------------------------------------------------------------------------- 1 | # THIS FILE WAS AUTO-GENERATED 2 | # 3 | # $ lcitool manifest ci/manifest.yml 4 | # 5 | # https://gitlab.com/libvirt/libvirt-ci 6 | 7 | 8 | # We want to publish containers with tag 'latest': 9 | # 10 | # - In upstream, for push to default branch with CI changes. 11 | # - In upstream, on request, for scheduled/manual pipelines 12 | # against default branch 13 | # 14 | # Note: never publish from merge requests since they have non-committed code 15 | # 16 | .container_job: 17 | image: docker:stable 18 | stage: containers 19 | interruptible: false 20 | needs: [] 21 | services: 22 | - docker:dind 23 | before_script: 24 | - export TAG="$CI_REGISTRY_IMAGE/ci-$NAME:latest" 25 | - docker info 26 | - docker login "$CI_REGISTRY" -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" 27 | script: 28 | - docker build --tag "$TAG" -f "ci/containers/$NAME.Dockerfile" ci/containers ; 29 | - docker push "$TAG" 30 | after_script: 31 | - docker logout 32 | rules: 33 | # upstream: publish containers if there were CI changes on the default branch 34 | - if: '$CI_PROJECT_NAMESPACE == $RUN_UPSTREAM_NAMESPACE && $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' 35 | when: on_success 36 | changes: 37 | - ci/gitlab/container-templates.yml 38 | - ci/containers/$NAME.Dockerfile 39 | 40 | # upstream: allow force re-publishing containers on default branch for web/api/scheduled pipelines 41 | - if: '$CI_PROJECT_NAMESPACE == $RUN_UPSTREAM_NAMESPACE && $CI_PIPELINE_SOURCE =~ /(web|api|schedule)/ && $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH && $RUN_CONTAINER_BUILDS == "1"' 42 | when: on_success 43 | 44 | # upstream+forks: that's all folks 45 | - when: never 46 | -------------------------------------------------------------------------------- /ci/skipped_tests: -------------------------------------------------------------------------------- 1 | # Old nbd-server, tests deadlock, old qemu-img version 2 | ^Ubuntu-18\.04$;interop/interop-nbd-server interop/interop-nbd-server-tls interop/list-exports-nbd-server interop/structured-read.sh 3 | 4 | # Debian 10 has weird golang issues (old golang anyway) and old qemu-img 5 | ^Debian GNU/Linux-10;golang/run-tests.sh interop/structured-read.sh 6 | 7 | # CentOS (stream) 8 probably has an older, buggy version of nbdkit and is not updated 8 | ^CentOS .*8$;info/info-uri.sh info/info-list-uris.sh interop/list-exports-nbdkit 9 | -------------------------------------------------------------------------------- /common-rules.mk: -------------------------------------------------------------------------------- 1 | # nbd client library in userspace 2 | # Copyright Red Hat 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 2 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | # common-rules.mk is included in every Makefile.am. 19 | # subdir-rules.mk is included only in subdirectories. 20 | 21 | # Convenient list terminator 22 | NULL = 23 | 24 | CLEANFILES = *~ 25 | 26 | $(generator_built): $(top_builddir)/generator/stamp-generator 27 | 28 | $(top_builddir)/generator/stamp-generator: \ 29 | $(wildcard $(top_srcdir)/generator/*.ml) \ 30 | $(wildcard $(top_srcdir)/generator/*.mli) \ 31 | $(wildcard $(top_srcdir)/generator/states*.c) 32 | $(MAKE) -C $(top_builddir)/generator stamp-generator 33 | -------------------------------------------------------------------------------- /common/utils/human-size.c: -------------------------------------------------------------------------------- 1 | /* nbd client library in userspace 2 | * Copyright Red Hat 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "human-size.h" 28 | 29 | char * 30 | human_size (char *buf, uint64_t bytes, bool *human) 31 | { 32 | static const char ext[][2] = { "E", "P", "T", "G", "M", "K", "" }; 33 | size_t i; 34 | 35 | if (buf == NULL) { 36 | buf = malloc (HUMAN_SIZE_LONGEST); 37 | if (buf == NULL) 38 | return NULL; 39 | } 40 | 41 | /* Work out which extension to use, if any. */ 42 | i = 6; 43 | if (bytes != 0) { 44 | while ((bytes & 1023) == 0) { 45 | bytes >>= 10; 46 | i--; 47 | } 48 | } 49 | 50 | /* Set the flag to true if we're going to add a human-readable extension. */ 51 | if (human) 52 | *human = ext[i][0] != '\0'; 53 | 54 | snprintf (buf, HUMAN_SIZE_LONGEST, "%" PRIu64 "%s", bytes, ext[i]); 55 | return buf; 56 | } 57 | -------------------------------------------------------------------------------- /common/utils/version.h: -------------------------------------------------------------------------------- 1 | /* nbd client library in userspace 2 | * Copyright Red Hat 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef LIBNBD_VERSION_H 20 | #define LIBNBD_VERSION_H 21 | 22 | /* This function is used in the command line utilities to display the 23 | * version of the tool and the library. It can be that the library 24 | * version is different (because of dynamic linking) but that would 25 | * usually indicate a packaging error. program_name should be the 26 | * program name, eg. "nbdcopy". 27 | */ 28 | extern void display_version (const char *program_name); 29 | 30 | #endif /* LIBNBD_INTERNAL_H */ 31 | -------------------------------------------------------------------------------- /copy/copy-file-to-file.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | requires cmp --version 25 | requires dd --version 26 | requires dd oflag=seek_bytes $file 31 | if [ "$(stat -c %s $file)" -ne $(( 10 * 1024 * 1024 )) ]; then 32 | echo "$0: incorrect amount of data copied" 33 | exit 1 34 | fi 35 | -------------------------------------------------------------------------------- /copy/copy-progress-bar.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | requires dd if=/dev/null of=/dev/null 25 | requires test -r /dev/urandom 26 | 27 | file=copy-progress-bar.file 28 | file2=copy-progress-bar.file2 29 | file3=copy-progress-bar.file3 30 | cleanup_fn rm -f $file $file2 $file3 31 | 32 | dd if=/dev/urandom of=$file bs=512 count=1 33 | 34 | # Check that a regular progress bar works. 35 | # This writes to stderr 36 | $VG nbdcopy --progress $file $file2 37 | 38 | # Check that a machine-readable progress bar works. 39 | exec 3>$file3 40 | $VG nbdcopy --progress=3 $file $file2 41 | exec 3>&- 42 | 43 | cat $file3 44 | 45 | # 100/100 must always be printed. 46 | grep "100/100" $file3 47 | -------------------------------------------------------------------------------- /copy/copy-sparse-to-stream.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # Stream from a sparse NBD source. The NBD source uses a bandwidth 20 | # limiter so this will be very slow unless nbdcopy correctly handles 21 | # extents. 22 | 23 | . ../tests/functions.sh 24 | 25 | set -e 26 | set -x 27 | 28 | requires nbdkit --version 29 | requires nbdkit --exit-with-parent --version 30 | requires nbdkit data --version 31 | requires nbdkit --version --filter=rate null 32 | 33 | # Copy rate is 512Kbps. nbdcopy should only need to copy two 32Kbyte 34 | # extents (2 * 32 * 8 = 512) so this should not take longer than a 35 | # second. But if nbdcopy is ignoring extents it will take much, much 36 | # longer. 37 | $VG nbdcopy -- \ 38 | [ nbdkit --exit-with-parent \ 39 | data data=' 1 @1073741823 1 ' \ 40 | --filter=rate rate=512K \ 41 | ] \ 42 | - >/dev/null 43 | -------------------------------------------------------------------------------- /copy/copy-stdin-to-nbd.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | requires nbdkit --exit-with-parent --version 25 | requires dd if=/dev/null of=/dev/null 26 | 27 | dd if=/dev/zero bs=1M count=10 | 28 | $VG nbdcopy -- - [ nbdkit --exit-with-parent -v memory size=10M ] 29 | -------------------------------------------------------------------------------- /copy/copy-stdin-to-null.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | requires dd if=/dev/null of=/dev/null 25 | 26 | dd if=/dev/zero bs=1M count=10 | $VG nbdcopy - null: 27 | -------------------------------------------------------------------------------- /copy/copy-zero-to-nbd.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | requires nbdkit --exit-with-parent --version 25 | 26 | pidfile=copy-zero-to-nbd.pid 27 | sock=$(mktemp -u /tmp/libnbd-test-copy.XXXXXX) 28 | cleanup_fn rm -f $pidfile $sock 29 | 30 | nbdkit --exit-with-parent -f -v -P $pidfile -U $sock memory size=10M & 31 | # Wait for the pidfile to appear. 32 | for i in {1..60}; do 33 | if test -f $pidfile; then 34 | break 35 | fi 36 | sleep 1 37 | done 38 | if ! test -f $pidfile; then 39 | echo "$0: nbdkit did not start up" 40 | exit 1 41 | fi 42 | 43 | $VG nbdcopy -p /dev/null "nbd+unix:///?socket=$sock" 44 | -------------------------------------------------------------------------------- /copy/copy-zero-to-null.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | $VG nbdcopy -p /dev/null null: 25 | -------------------------------------------------------------------------------- /copy/test-long-options.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # Test that nbdcopy --long-options looks sane. 20 | 21 | . ../tests/functions.sh 22 | set -e 23 | set -x 24 | 25 | output=test-long-options.out 26 | cleanup_fn rm -f $output 27 | 28 | $VG nbdcopy --long-options > $output 29 | if [ $? != 0 ]; then 30 | echo "$0: unexpected exit status" 31 | fail=1 32 | fi 33 | cat $output 34 | grep -- --allocated $output 35 | grep -- --threads $output 36 | grep -- --version $output 37 | -------------------------------------------------------------------------------- /copy/test-short-options.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # Test that nbdcopy --short-options looks sane. 20 | 21 | . ../tests/functions.sh 22 | set -e 23 | set -x 24 | 25 | output=test-short-options.out 26 | cleanup_fn rm -f $output 27 | 28 | $VG nbdcopy --short-options > $output 29 | if [ $? != 0 ]; then 30 | echo "$0: unexpected exit status" 31 | fail=1 32 | fi 33 | cat $output 34 | grep -- -C $output 35 | grep -- -R $output 36 | grep -- -V $output 37 | -------------------------------------------------------------------------------- /copy/test-verbose.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # Test that nbdcopy -v/--verbose looks sane. 20 | 21 | . ../tests/functions.sh 22 | 23 | set -e 24 | set -x 25 | 26 | requires nbdkit --version 27 | requires nbdkit memory --version 28 | 29 | file=test-verbose.out 30 | cleanup_fn rm -f $file 31 | 32 | $VG nbdcopy -v -- [ nbdkit memory size=1M ] null: 2>$file 33 | 34 | cat $file 35 | 36 | # Check some known strings appear in the output. 37 | grep '^nbdcopy: src: nbd_ops' $file 38 | grep '^nbdcopy: src: size=1048576 (1M)' $file 39 | grep '^nbdcopy: dst: null_ops' $file 40 | -------------------------------------------------------------------------------- /copy/test-version.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # Test that nbdcopy --version looks sane. 20 | 21 | fail=0 22 | output=$($VG nbdcopy --version) 23 | if [ $? != 0 ]; then 24 | echo "$0: unexpected exit status" 25 | fail=1 26 | fi 27 | if [ "$output" != "nbdcopy $EXPECTED_VERSION 28 | libnbd $EXPECTED_VERSION" ]; then 29 | echo "$0: unexpected output" 30 | fail=1 31 | fi 32 | echo "$output" 33 | exit $fail 34 | -------------------------------------------------------------------------------- /docs/libnbd-security.pod: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | libnbd-security - information about past security issues in libnbd 4 | 5 | =head1 DESCRIPTION 6 | 7 | This page details past security issues found in libnbd. 8 | 9 | For how to report new security issues, see the C file in the 10 | top level source directory, also available online here: 11 | L 12 | 13 | =head2 CVE-2019-14842 14 | protocol downgrade attack when using C 15 | 16 | See the full announcement and links to mitigation, tests and fixes 17 | here: 18 | L 19 | 20 | =head2 remote code execution vulnerability 21 | 22 | See the full announcement here: 23 | L 24 | 25 | =head2 CVE-2021-20286 26 | denial of service when using L 27 | 28 | See the full announcement here: 29 | L 30 | 31 | =head2 CVE-2022-0485 32 | silent data corruption when using L 33 | 34 | See the full announcement here: 35 | L 36 | 37 | =head1 SEE ALSO 38 | 39 | L. 40 | 41 | =head1 AUTHORS 42 | 43 | Eric Blake 44 | 45 | Richard W.M. Jones 46 | 47 | =head1 COPYRIGHT 48 | 49 | Copyright Red Hat 50 | -------------------------------------------------------------------------------- /docs/nbd_close.3: -------------------------------------------------------------------------------- 1 | .so man3/nbd_create.3 2 | -------------------------------------------------------------------------------- /docs/nbd_get_errno.3: -------------------------------------------------------------------------------- 1 | .so man3/nbd_create.3 2 | -------------------------------------------------------------------------------- /docs/nbd_get_error.3: -------------------------------------------------------------------------------- 1 | .so man3/nbd_create.3 2 | -------------------------------------------------------------------------------- /dump/dump-empty-qcow2.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | requires $QEMU_NBD --version 25 | requires qemu-img --version 26 | 27 | file=dump-empty-qcow2.qcow2 28 | output=dump-empty-qcow2.out 29 | rm -f $file $output 30 | cleanup_fn rm -f $file $output 31 | 32 | size=1G 33 | 34 | # Create a large, empty qcow2 file. 35 | qemu-img create -f qcow2 $file $size 36 | 37 | # Dump it and check the output. 38 | nbddump -- [ $QEMU_NBD -r -f qcow2 $file ] > $output 39 | cat $output 40 | 41 | if [ "$(cat $output)" != '0000000000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 42 | * 43 | 003ffffff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|' ]; then 44 | echo "$0: unexpected output from nbddump command" 45 | exit 1 46 | fi 47 | -------------------------------------------------------------------------------- /dump/test-long-options.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # Test that nbddump --long-options looks sane. 20 | 21 | . ../tests/functions.sh 22 | set -e 23 | set -x 24 | 25 | output=test-long-options.out 26 | cleanup_fn rm -f $output 27 | 28 | $VG nbddump --long-options > $output 29 | if [ $? != 0 ]; then 30 | echo "$0: unexpected exit status" 31 | fail=1 32 | fi 33 | cat $output 34 | grep -- --length $output 35 | grep -- --version $output 36 | -------------------------------------------------------------------------------- /dump/test-short-options.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # Test that nbddump --short-options looks sane. 20 | 21 | . ../tests/functions.sh 22 | set -e 23 | set -x 24 | 25 | output=test-short-options.out 26 | cleanup_fn rm -f $output 27 | 28 | $VG nbddump --short-options > $output 29 | if [ $? != 0 ]; then 30 | echo "$0: unexpected exit status" 31 | fail=1 32 | fi 33 | cat $output 34 | grep -- -n $output 35 | grep -- -V $output 36 | -------------------------------------------------------------------------------- /dump/test-version.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # Test that nbddump --version looks sane. 20 | 21 | fail=0 22 | output=$($VG nbddump --version) 23 | if [ $? != 0 ]; then 24 | echo "$0: unexpected exit status" 25 | fail=1 26 | fi 27 | if [ "$output" != "nbddump $EXPECTED_VERSION 28 | libnbd $EXPECTED_VERSION" ]; then 29 | echo "$0: unexpected output" 30 | fail=1 31 | fi 32 | echo "$output" 33 | exit $fail 34 | -------------------------------------------------------------------------------- /examples/fetch-first-sector.c: -------------------------------------------------------------------------------- 1 | /* This example shows how to connect to an NBD server 2 | * and fetch and print the first sector (usually the 3 | * boot sector or partition table or filesystem 4 | * superblock). 5 | * 6 | * You can test it with nbdkit like this: 7 | * 8 | * nbdkit -U - floppy . \ 9 | * --run './fetch-first-sector $unixsocket' 10 | * 11 | * The nbdkit floppy plugin creates an MBR disk so the 12 | * first sector is the partition table. 13 | */ 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | 20 | int 21 | main (int argc, char *argv[]) 22 | { 23 | struct nbd_handle *nbd; 24 | char buf[512]; 25 | FILE *pp; 26 | 27 | if (argc != 2) { 28 | fprintf (stderr, "%s socket\n", argv[0]); 29 | exit (EXIT_FAILURE); 30 | } 31 | 32 | /* Create the libnbd handle. */ 33 | nbd = nbd_create (); 34 | if (nbd == NULL) { 35 | fprintf (stderr, "%s\n", nbd_get_error ()); 36 | exit (EXIT_FAILURE); 37 | } 38 | 39 | /* Connect to the NBD server over a 40 | * Unix domain socket. 41 | */ 42 | if (nbd_connect_unix (nbd, argv[1]) == -1) { 43 | fprintf (stderr, "%s\n", nbd_get_error ()); 44 | exit (EXIT_FAILURE); 45 | } 46 | 47 | /* Read the first sector synchronously. */ 48 | if (nbd_pread (nbd, buf, sizeof buf, 0, 0) == -1) { 49 | fprintf (stderr, "%s\n", nbd_get_error ()); 50 | exit (EXIT_FAILURE); 51 | } 52 | 53 | /* Close the libnbd handle. */ 54 | nbd_close (nbd); 55 | 56 | /* Print the first sector. */ 57 | pp = popen ("hexdump -C", "w"); 58 | if (pp == NULL) { 59 | perror ("popen: hexdump"); 60 | exit (EXIT_FAILURE); 61 | } 62 | fwrite (buf, sizeof buf, 1, pp); 63 | pclose (pp); 64 | 65 | exit (EXIT_SUCCESS); 66 | } 67 | -------------------------------------------------------------------------------- /examples/get-size.c: -------------------------------------------------------------------------------- 1 | /* This example shows how to connect to an NBD 2 | * server and read the size of the disk. 3 | * 4 | * You can test it with nbdkit like this: 5 | * 6 | * nbdkit -U - memory 1M \ 7 | * --run './get-size $unixsocket' 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | int 18 | main (int argc, char *argv[]) 19 | { 20 | struct nbd_handle *nbd; 21 | int64_t size; 22 | 23 | if (argc != 2) { 24 | fprintf (stderr, "%s socket\n", argv[0]); 25 | exit (EXIT_FAILURE); 26 | } 27 | 28 | /* Create the libnbd handle. */ 29 | nbd = nbd_create (); 30 | if (nbd == NULL) { 31 | fprintf (stderr, "%s\n", nbd_get_error ()); 32 | exit (EXIT_FAILURE); 33 | } 34 | 35 | /* Connect to the NBD server over a 36 | * Unix domain socket. 37 | */ 38 | if (nbd_connect_unix (nbd, argv[1]) == -1) { 39 | fprintf (stderr, "%s\n", nbd_get_error ()); 40 | exit (EXIT_FAILURE); 41 | } 42 | 43 | /* Read the size in bytes and print it. */ 44 | size = nbd_get_size (nbd); 45 | if (size == -1) { 46 | fprintf (stderr, "%s\n", nbd_get_error ()); 47 | exit (EXIT_FAILURE); 48 | } 49 | printf ("%s: size = %" PRIi64 " bytes\n", 50 | argv[1], size); 51 | 52 | /* Close the libnbd handle. */ 53 | nbd_close (nbd); 54 | 55 | exit (EXIT_SUCCESS); 56 | } 57 | -------------------------------------------------------------------------------- /examples/open-qcow2.c: -------------------------------------------------------------------------------- 1 | /* This example shows how to use qemu-nbd 2 | * to open a local qcow2 file. 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | int 12 | main (int argc, const char *argv[]) 13 | { 14 | const char *filename; 15 | struct nbd_handle *nbd; 16 | char buf[512]; 17 | FILE *fp; 18 | 19 | if (argc != 2) { 20 | fprintf (stderr, "open-qcow2 file.qcow2\n"); 21 | exit (EXIT_FAILURE); 22 | } 23 | filename = argv[1]; 24 | 25 | /* Create the libnbd handle. */ 26 | nbd = nbd_create (); 27 | if (nbd == NULL) { 28 | fprintf (stderr, "%s\n", nbd_get_error ()); 29 | exit (EXIT_FAILURE); 30 | } 31 | 32 | /* Run qemu-nbd as a subprocess using 33 | * systemd socket activation. 34 | */ 35 | char *args[] = { 36 | "qemu-nbd", "-f", "qcow2", 37 | (char *) filename, 38 | NULL 39 | }; 40 | if (nbd_connect_systemd_socket_activation (nbd, 41 | args) == -1) { 42 | fprintf (stderr, "%s\n", nbd_get_error ()); 43 | exit (EXIT_FAILURE); 44 | } 45 | 46 | /* Read the first sector and print it. */ 47 | if (nbd_pread (nbd, buf, sizeof buf, 0, 0) == -1) { 48 | fprintf (stderr, "%s\n", nbd_get_error ()); 49 | exit (EXIT_FAILURE); 50 | } 51 | 52 | fp = popen ("hexdump -C", "w"); 53 | if (fp == NULL) { 54 | perror ("popen: hexdump"); 55 | exit (EXIT_FAILURE); 56 | } 57 | fwrite (buf, sizeof buf, 1, fp); 58 | pclose (fp); 59 | 60 | /* Close the libnbd handle. */ 61 | nbd_close (nbd); 62 | 63 | exit (EXIT_SUCCESS); 64 | } 65 | -------------------------------------------------------------------------------- /fuse/nbdfuse.h: -------------------------------------------------------------------------------- 1 | /* NBD client library in userspace 2 | * Copyright Red Hat 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef LIBNBD_NBDFUSE_H 20 | #define LIBNBD_NBDFUSE_H 21 | 22 | #include 23 | #include 24 | 25 | /* Define fuse API version and include the header file in one place so 26 | * we can be sure to get the same API in all source files. 27 | */ 28 | #define FUSE_USE_VERSION 35 29 | #include 30 | 31 | #include "vector.h" 32 | 33 | DEFINE_VECTOR_TYPE (handles, struct nbd_handle *); 34 | 35 | extern handles nbd; 36 | extern unsigned connections; 37 | extern bool readonly; 38 | extern bool file_mode; 39 | extern struct timespec start_t; 40 | extern char *filename; 41 | extern uint64_t size; 42 | extern bool verbose; 43 | 44 | extern struct fuse_operations nbdfuse_operations; 45 | extern void start_operations_threads (void); 46 | 47 | #endif /* LIBNBD_NBDFUSE_H */ 48 | -------------------------------------------------------------------------------- /fuse/test-long-options.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # Test that nbdfuse --long-options looks sane. 20 | 21 | . ../tests/functions.sh 22 | set -e 23 | set -x 24 | 25 | output=test-long-options.out 26 | cleanup_fn rm -f $output 27 | 28 | $VG nbdfuse --long-options > $output 29 | if [ $? != 0 ]; then 30 | echo "$0: unexpected exit status" 31 | fail=1 32 | fi 33 | cat $output 34 | grep -- --fuse-help $output 35 | grep -- --readonly $output 36 | grep -- --version $output 37 | -------------------------------------------------------------------------------- /fuse/test-short-options.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # Test that nbdfuse --short-options looks sane. 20 | 21 | . ../tests/functions.sh 22 | set -e 23 | set -x 24 | 25 | output=test-short-options.out 26 | cleanup_fn rm -f $output 27 | 28 | $VG nbdfuse --short-options > $output 29 | if [ $? != 0 ]; then 30 | echo "$0: unexpected exit status" 31 | fail=1 32 | fi 33 | cat $output 34 | grep -- -o $output 35 | grep -- -P $output 36 | grep -- -V $output 37 | -------------------------------------------------------------------------------- /fuse/test-version.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # Test that nbdfuse --version looks sane. 20 | 21 | fail=0 22 | output=$($VG nbdfuse --version) 23 | if [ $? != 0 ]; then 24 | echo "$0: unexpected exit status" 25 | fail=1 26 | fi 27 | if [ "$output" != "nbdfuse $EXPECTED_VERSION 28 | libnbd $EXPECTED_VERSION" ]; then 29 | echo "$0: unexpected output" 30 | fail=1 31 | fi 32 | echo "$output" 33 | exit $fail 34 | -------------------------------------------------------------------------------- /fuzzing/Makefile.am: -------------------------------------------------------------------------------- 1 | # nbd client library in userspace 2 | # Copyright Red Hat 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 2 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | include $(top_srcdir)/subdir-rules.mk 19 | 20 | EXTRA_DIST = \ 21 | README \ 22 | testcase_dir/newstyle \ 23 | testcase_dir/newstyle-commands \ 24 | testcase_dir/oldstyle \ 25 | $(NULL) 26 | 27 | noinst_PROGRAMS = libnbd-fuzz-wrapper 28 | if ENABLE_LIBFUZZER 29 | noinst_PROGRAMS += libnbd-libfuzzer-test 30 | endif 31 | 32 | libnbd_fuzz_wrapper_SOURCES = libnbd-fuzz-wrapper.c 33 | libnbd_fuzz_wrapper_CPPFLAGS = -I$(top_srcdir)/include 34 | libnbd_fuzz_wrapper_CFLAGS = $(WARNINGS_CFLAGS) 35 | libnbd_fuzz_wrapper_LDADD = $(top_builddir)/lib/libnbd.la 36 | 37 | libnbd_libfuzzer_test_SOURCES = libnbd-libfuzzer-test.c 38 | libnbd_libfuzzer_test_CPPFLAGS = -I$(top_srcdir)/include 39 | libnbd_libfuzzer_test_CFLAGS = $(WARNINGS_CFLAGS) 40 | libnbd_libfuzzer_test_LDADD = $(top_builddir)/lib/libnbd.la 41 | -------------------------------------------------------------------------------- /fuzzing/testcase_dir/newstyle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libguestfs/libnbd/9075f68ffc8bed320d0d1d46f1f0456d10626878/fuzzing/testcase_dir/newstyle -------------------------------------------------------------------------------- /fuzzing/testcase_dir/newstyle-commands: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libguestfs/libnbd/9075f68ffc8bed320d0d1d46f1f0456d10626878/fuzzing/testcase_dir/newstyle-commands -------------------------------------------------------------------------------- /fuzzing/testcase_dir/oldstyle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libguestfs/libnbd/9075f68ffc8bed320d0d1d46f1f0456d10626878/fuzzing/testcase_dir/oldstyle -------------------------------------------------------------------------------- /generator/GoLang.mli: -------------------------------------------------------------------------------- 1 | (* nbd client library in userspace: generator 2 | * Copyright Red Hat 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | *) 18 | 19 | val generate_golang_bindings_go : unit -> unit 20 | val generate_golang_closures_go : unit -> unit 21 | val generate_golang_wrappers_go : unit -> unit 22 | val generate_golang_wrappers_h : unit -> unit 23 | -------------------------------------------------------------------------------- /generator/OCaml.mli: -------------------------------------------------------------------------------- 1 | (* hey emacs, this is OCaml code: -*- tuareg -*- *) 2 | (* nbd client library in userspace: generator 3 | * Copyright Red Hat 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | *) 19 | 20 | val generate_ocaml_nbd_mli : unit -> unit 21 | val generate_ocaml_nbd_ml : unit -> unit 22 | val generate_ocaml_nbd_c : unit -> unit 23 | -------------------------------------------------------------------------------- /generator/Python.mli: -------------------------------------------------------------------------------- 1 | (* hey emacs, this is OCaml code: -*- tuareg -*- *) 2 | (* nbd client library in userspace: Python bindings 3 | * Copyright Red Hat 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | *) 19 | 20 | val generate_python_methods_h : unit -> unit 21 | val generate_python_libnbdmod_c : unit -> unit 22 | val generate_python_methods_c : unit -> unit 23 | val generate_python_nbd_py : unit -> unit 24 | -------------------------------------------------------------------------------- /generator/state_machine_generator.mli: -------------------------------------------------------------------------------- 1 | (* hey emacs, this is OCaml code: -*- tuareg -*- *) 2 | (* nbd client library in userspace: generate the code for the state machine 3 | * Copyright Red Hat 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | *) 19 | 20 | val generate_lib_states_h : unit -> unit 21 | val generate_lib_states_c : unit -> unit 22 | val generate_lib_states_run_c : unit -> unit 23 | -------------------------------------------------------------------------------- /golang/.gitignore: -------------------------------------------------------------------------------- 1 | /bindings.go 2 | /closures.go 3 | /wrappers.go 4 | /wrappers.h 5 | -------------------------------------------------------------------------------- /golang/README.md: -------------------------------------------------------------------------------- 1 | # Libnbd Go binding 2 | 3 | This module provides access to Network Block Device (NBD) servers from 4 | the Go programming language, using the libnbd library. 5 | 6 | Please see the manual to learn how to use this module: 7 | https://libguestfs.org/libnbd-golang.3.html 8 | 9 | This is part of libnbd, please check the project at: 10 | https://gitlab.com/nbdkit/libnbd 11 | 12 | ## License 13 | 14 | The software is Copyright Red Hat and licensed under the GNU 15 | Lesser General Public License version 2 or above (LGPLv2+). See 16 | the file `LICENSE` for details. 17 | -------------------------------------------------------------------------------- /golang/configure/go.mod: -------------------------------------------------------------------------------- 1 | module libguestfs.org/configure 2 | 3 | // First version of golang with working module support. 4 | go 1.13 5 | -------------------------------------------------------------------------------- /golang/configure/test.go: -------------------------------------------------------------------------------- 1 | /* libnbd Go configuration test 2 | * Copyright Red Hat 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | /* This is called from ./configure to check that golang works 20 | * and is above the minimum required version. 21 | */ 22 | 23 | package main 24 | 25 | import ( 26 | "fmt" 27 | "runtime" 28 | ) 29 | 30 | func main() { 31 | fmt.Println(runtime.Version()) 32 | 33 | /* XXX Check for minimum runtime.Version() >= "go1.1.1" 34 | * Unfortunately go version numbers are not easy to parse. 35 | * They have the 3 formats "goX.Y.Z", "release.rN" or 36 | * "weekly.YYYY-MM-DD". The latter two formats are mostly 37 | * useless, and the first one is hard to parse. See also 38 | * cmpGoVersion in 39 | * http://web.archive.org/web/20130402235148/http://golang.org/src/cmd/go/get.go?m=text 40 | */ 41 | } 42 | -------------------------------------------------------------------------------- /golang/examples/aio_copy/go.mod: -------------------------------------------------------------------------------- 1 | module main 2 | 3 | replace libguestfs.org/libnbd => ../../ 4 | require libguestfs.org/libnbd v1.11.5 5 | -------------------------------------------------------------------------------- /golang/examples/get_size/go.mod: -------------------------------------------------------------------------------- 1 | module main 2 | 3 | replace libguestfs.org/libnbd => ../../ 4 | require libguestfs.org/libnbd v1.0.0 5 | -------------------------------------------------------------------------------- /golang/examples/read_first_sector/go.mod: -------------------------------------------------------------------------------- 1 | module main 2 | 3 | replace libguestfs.org/libnbd => ../../ 4 | require libguestfs.org/libnbd v1.0.0 5 | -------------------------------------------------------------------------------- /golang/examples/simple_copy/go.mod: -------------------------------------------------------------------------------- 1 | module main 2 | 3 | replace libguestfs.org/libnbd => ../../ 4 | require libguestfs.org/libnbd v1.11.5 5 | -------------------------------------------------------------------------------- /golang/go.mod: -------------------------------------------------------------------------------- 1 | module libguestfs.org/libnbd 2 | 3 | // First version of golang with working module support. 4 | go 1.13 5 | -------------------------------------------------------------------------------- /golang/libnbd-golang.pod: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | libnbd-golang - how to use libnbd from Go 4 | 5 | =head1 SYNOPSIS 6 | 7 | import "libguestfs.org/libnbd" 8 | 9 | h, err := libnbd.Create() 10 | if err != nil { 11 | panic(err) 12 | } 13 | defer h.Close() 14 | uri := "nbd://localhost" 15 | err = h.ConnectUri(uri) 16 | if err != nil { 17 | panic(err) 18 | } 19 | size, err := h.GetSize() 20 | if err != nil { 21 | panic(err) 22 | } 23 | fmt.Printf("size of %s = %d\n", uri, size) 24 | 25 | =head1 DESCRIPTION 26 | 27 | This manual page documents how to use libnbd to access Network Block 28 | Device (NBD) servers from the Go programming language. The Go 29 | bindings work very similarly to the C bindings so you should start by 30 | reading L. 31 | 32 | =head1 HANDLES 33 | 34 | Create a libnbd handle of type C by calling C. 35 | 36 | You can either close the handle explicitly by a deferred call to 37 | C or it will be closed automatically when it is garbage 38 | collected. 39 | 40 | =head1 ERRORS 41 | 42 | Most calls return either a single C or a pair 43 | C<(ret, LibnbdError)>. 44 | 45 | =head1 EXAMPLES 46 | 47 | This directory contains examples written in Go: 48 | 49 | L 50 | 51 | =head1 SEE ALSO 52 | 53 | L. 54 | 55 | =head1 AUTHORS 56 | 57 | Richard W.M. Jones 58 | 59 | =head1 COPYRIGHT 60 | 61 | Copyright Red Hat 62 | -------------------------------------------------------------------------------- /golang/libnbd_010_load_test.go: -------------------------------------------------------------------------------- 1 | /* libnbd golang tests 2 | * Copyright Red Hat 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | package libnbd 20 | 21 | import "testing" 22 | 23 | func Test010Load(t *testing.T) { 24 | /* Nothing - just test that the library can be linked to. */ 25 | } 26 | -------------------------------------------------------------------------------- /golang/libnbd_100_handle_test.go: -------------------------------------------------------------------------------- 1 | /* libnbd golang tests 2 | * Copyright Red Hat 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | package libnbd 20 | 21 | import "testing" 22 | 23 | func Test100Handle(t *testing.T) { 24 | h, err := Create() 25 | if err != nil { 26 | t.Fatalf("could not create handle: %s", err) 27 | } 28 | h.Close() 29 | } 30 | -------------------------------------------------------------------------------- /golang/libnbd_200_connect_command_test.go: -------------------------------------------------------------------------------- 1 | /* libnbd golang tests 2 | * Copyright Red Hat 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | package libnbd 20 | 21 | import "testing" 22 | 23 | func Test200ConnectCommand(t *testing.T) { 24 | h, err := Create() 25 | if err != nil { 26 | t.Fatalf("could not create handle: %s", err) 27 | } 28 | defer h.Close() 29 | 30 | err = h.ConnectCommand([]string{ 31 | "nbdkit", "-s", "--exit-with-parent", "-v", "null", 32 | }) 33 | if err != nil { 34 | t.Fatalf("could not connect: %s", err) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /golang/libnbd_300_get_size_test.go: -------------------------------------------------------------------------------- 1 | /* libnbd golang tests 2 | * Copyright Red Hat 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | package libnbd 20 | 21 | import "fmt" 22 | import "testing" 23 | 24 | func Test300GetSize(t *testing.T) { 25 | expected := uint64(1048576) 26 | 27 | h, err := Create() 28 | if err != nil { 29 | t.Fatalf("could not create handle: %s", err) 30 | } 31 | defer h.Close() 32 | 33 | err = h.ConnectCommand([]string{ 34 | "nbdkit", "-s", "--exit-with-parent", "-v", "null", 35 | fmt.Sprintf("size=%d", expected), 36 | }) 37 | if err != nil { 38 | t.Fatalf("could not connect: %s", err) 39 | } 40 | actual, err := h.GetSize() 41 | if err != nil { 42 | t.Fatalf("%s", err) 43 | } 44 | if actual != expected { 45 | t.Fatalf("actual %d != expected %d", actual, expected) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /golang/libnbd_400_pread_test.go: -------------------------------------------------------------------------------- 1 | /* libnbd golang tests 2 | * Copyright Red Hat 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | package libnbd 20 | 21 | import "bytes" 22 | import "encoding/binary" 23 | import "testing" 24 | 25 | func Test400PRead(t *testing.T) { 26 | h, err := Create() 27 | if err != nil { 28 | t.Fatalf("could not create handle: %s", err) 29 | } 30 | defer h.Close() 31 | 32 | err = h.ConnectCommand([]string{ 33 | "nbdkit", "-s", "--exit-with-parent", "-v", 34 | "pattern", "size=512", 35 | }) 36 | if err != nil { 37 | t.Fatalf("could not connect: %s", err) 38 | } 39 | 40 | buf := make([]byte, 512) 41 | err = h.Pread(buf, 0, nil) 42 | if err != nil { 43 | t.Fatalf("%s", err) 44 | } 45 | 46 | // Expected data. 47 | expected := make([]byte, 512) 48 | for i := 0; i < 512; i += 8 { 49 | binary.BigEndian.PutUint64(expected[i:i+8], uint64(i)) 50 | } 51 | 52 | if !bytes.Equal(buf, expected) { 53 | t.Fatalf("did not read expected data") 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /golang/libnbd_410_pwrite_test.go: -------------------------------------------------------------------------------- 1 | /* libnbd golang tests 2 | * Copyright Red Hat 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | package libnbd 20 | 21 | import "bytes" 22 | import "testing" 23 | 24 | func Test410PWrite(t *testing.T) { 25 | h, err := Create() 26 | if err != nil { 27 | t.Fatalf("could not create handle: %s", err) 28 | } 29 | defer h.Close() 30 | 31 | err = h.ConnectCommand([]string{ 32 | "nbdkit", "-s", "--exit-with-parent", "-v", 33 | "memory", "size=512", 34 | }) 35 | if err != nil { 36 | t.Fatalf("could not connect: %s", err) 37 | } 38 | 39 | /* Write a pattern and read it back. */ 40 | buf := make([]byte, 512) 41 | for i := 0; i < 512; i += 2 { 42 | buf[i] = 0x55 43 | buf[i+1] = 0xAA 44 | } 45 | err = h.Pwrite(buf, 0, nil) 46 | if err != nil { 47 | t.Fatalf("%s", err) 48 | } 49 | buf2 := make([]byte, 512) 50 | err = h.Pread(buf2, 0, nil) 51 | if err != nil { 52 | t.Fatalf("%s", err) 53 | } 54 | 55 | if !bytes.Equal(buf, buf2) { 56 | t.Fatalf("did not read back same data as written") 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /golang/libnbd_600_debug_callback_test.go: -------------------------------------------------------------------------------- 1 | /* libnbd golang tests 2 | * Copyright Red Hat 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | package libnbd 20 | 21 | import "fmt" 22 | import "testing" 23 | 24 | var msgs []string 25 | 26 | func f(context string, msg string) int { 27 | fmt.Printf("debug callback called: context=%s msg=%s\n", 28 | context, msg) 29 | msgs = append(msgs, context, msg) 30 | return 0 31 | } 32 | 33 | func Test600DebugCallback(t *testing.T) { 34 | h, err := Create() 35 | if err != nil { 36 | t.Fatalf("could not create handle: %s", err) 37 | } 38 | defer h.Close() 39 | 40 | err = h.SetDebugCallback(f) 41 | if err != nil { 42 | t.Fatalf("%s", err) 43 | } 44 | err = h.ConnectCommand([]string{ 45 | "nbdkit", "-s", "--exit-with-parent", "null", 46 | }) 47 | if err != nil { 48 | t.Fatalf("%s", err) 49 | } 50 | err = h.Shutdown(nil) 51 | if err != nil { 52 | t.Fatalf("%s", err) 53 | } 54 | 55 | fmt.Printf("msgs = %s\n", msgs) 56 | } 57 | -------------------------------------------------------------------------------- /golang/libnbd_610_error_test.go: -------------------------------------------------------------------------------- 1 | /* libnbd golang tests 2 | * Copyright Red Hat 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | package libnbd 20 | 21 | import "syscall" 22 | import "testing" 23 | 24 | func Test610Error(t *testing.T) { 25 | h, err := Create() 26 | if err != nil { 27 | t.Fatalf("could not create handle: %s", err) 28 | } 29 | defer h.Close() 30 | 31 | /* This will always return an error because the handle is 32 | not connected. */ 33 | buf := make([]byte, 512) 34 | err = h.Pread(buf, 0, nil) 35 | if err == nil { 36 | t.Fatalf("expected an error from operation") 37 | } else if err.(*LibnbdError).Errno != syscall.ENOTCONN { 38 | t.Fatalf("unexpected error: %s", err) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /golang/run-tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash - 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | requires nbdkit --version 25 | 26 | # The -count=1 parameter is the "idiomatic way to bypass test caching". 27 | # https://golang.org/doc/go1.10#test 28 | # The -v option enables verbose output. 29 | $GOLANG test -count=1 -v 30 | 31 | # Run the only benchmarks with 10 milliseconds timeout to make sure they 32 | # do not break by mistake, without overloading the CI. For performance 33 | # testing run "go test" directly. 34 | # The -run=- parameter is the way to match no test, assuming that no test or 35 | # sub test contains "-" in the name. 36 | $GOLANG test -run=- -bench=. -benchtime=10ms 37 | -------------------------------------------------------------------------------- /include/Makefile.am: -------------------------------------------------------------------------------- 1 | # nbd client library in userspace 2 | # Copyright Red Hat 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 2 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | include $(top_srcdir)/subdir-rules.mk 19 | 20 | generator_built = libnbd.h 21 | 22 | EXTRA_DIST = $(generator_built) 23 | 24 | BUILT_SOURCES = $(generator_built) 25 | 26 | include_HEADERS = \ 27 | libnbd.h \ 28 | $(NULL) 29 | -------------------------------------------------------------------------------- /info/info-atomic-output.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | # Eval plugin was added in 1.18. 25 | # --run $uri option was added in 1.14. 26 | # So checking for the eval plugin is sufficient. 27 | requires nbdkit eval --version 28 | 29 | out=info-atomic-output.out 30 | cleanup_fn rm -f $out 31 | 32 | nbdkit -U - eval open='echo EIO fail >&2; exit 1' \ 33 | --run '$VG nbdinfo --size "$uri"' > $out ||: 34 | test ! -s $out 35 | -------------------------------------------------------------------------------- /info/info-can-connect.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | # --can connect always returns true. 25 | 26 | requires nbdkit --no-sr null --version 27 | 28 | nbdkit -v -U - null \ 29 | --run '$VG nbdinfo --can connect "nbd+unix:///?socket=$unixsocket"' 30 | 31 | # --is tls is false for unencrypted connections. 32 | 33 | st=0 34 | nbdkit -v -U - null \ 35 | --run '$VG nbdinfo --is tls "nbd+unix:///?socket=$unixsocket"' || st=$? 36 | test $st = 2 37 | -------------------------------------------------------------------------------- /info/info-can-read.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | # --can read always returns true. 25 | 26 | requires nbdkit null --version 27 | 28 | nbdkit -v -U - null \ 29 | --run '$VG nbdinfo --can read "nbd+unix:///?socket=$unixsocket"' 30 | -------------------------------------------------------------------------------- /info/info-can-zero.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | # nbdkit emulates zeroing so we have to use the nozero filter to test 25 | # the negative case below. 26 | 27 | requires nbdkit null --version 28 | requires nbdkit null --filter=nozero --version 29 | 30 | nbdkit -v -U - null \ 31 | --run '$VG nbdinfo --can zero "nbd+unix:///?socket=$unixsocket"' 32 | 33 | nbdkit -v -U - null \ 34 | --filter=nozero \ 35 | --run '! $VG nbdinfo --can zero "nbd+unix:///?socket=$unixsocket"' 36 | -------------------------------------------------------------------------------- /info/info-cmd-json.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | requires nbdkit --version 25 | requires nbdkit memory --version 26 | requires jq --version 27 | 28 | out=info-cmd-json.out 29 | cleanup_fn rm -f $out 30 | 31 | $VG nbdinfo --json -- [ nbdkit -r memory size=1M ] > $out 32 | jq . < $out 33 | test $( jq -r '.protocol' < $out ) != "newstyle" 34 | test $( jq -r '.exports[0]."export-size"' < $out ) != "null" 35 | test $( jq -r '.exports[0].is_read_only' < $out ) = "true" 36 | -------------------------------------------------------------------------------- /info/info-cmd-map-totals.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | requires nbdkit --version 25 | requires nbdkit -U - null --run 'test "$uri" != ""' 26 | requires tr --version 27 | 28 | out=info-cmd-map-totals.out 29 | cleanup_fn rm -f $out 30 | rm -f $out 31 | 32 | # The sparse allocator used by nbdkit-data-plugin uses a 32K page 33 | # size, and extents are always aligned with this. 34 | $VG nbdinfo --map --totals [ nbdkit data data='1 @131072 2' size=1M ] > $out 35 | 36 | cat $out 37 | 38 | if [ "$(tr -s ' ' < $out)" != " 65536 6.2% 0 data 39 | 983040 93.8% 3 hole,zero" ]; then 40 | echo "$0: unexpected output from nbdinfo --map" 41 | exit 1 42 | fi 43 | -------------------------------------------------------------------------------- /info/info-cmd-size.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | requires nbdkit --version 25 | requires nbdkit memory --version 26 | 27 | out=info-cmd-size.out 28 | cleanup_fn rm -f $out 29 | 30 | $VG nbdinfo --size [ nbdkit memory size=$((512*1024*1024)) ] > $out 31 | test "$(cat $out)" -eq $((512*1024*1024)) 32 | -------------------------------------------------------------------------------- /info/info-description-qemu.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | requires $QEMU_NBD --pid-file=test.pid --version 25 | requires truncate --version 26 | 27 | img=info-description-qemu.img 28 | out=info-description-qemu.out 29 | pid=info-description-qemu.pid 30 | sock=$(mktemp -u /tmp/libnbd-test-info.XXXXXX) 31 | cleanup_fn rm -f $img $out $pid $sock 32 | rm -f $img $out $pid $sock 33 | 34 | truncate -s 1M $img 35 | $QEMU_NBD -f raw -t --socket=$sock --pid-file=$pid -x "hello" -D "world" $img & 36 | cleanup_fn kill $! 37 | 38 | wait_for_pidfile qemu-nbd $pid 39 | 40 | $VG nbdinfo "nbd+unix:///hello?socket=$sock" > $out 41 | cat $out 42 | 43 | grep 'export="hello":' $out 44 | grep 'description: world' $out 45 | grep 'export-size: 1048576' $out 46 | -------------------------------------------------------------------------------- /info/info-description.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | requires nbdkit --filter=exportname memory --version 25 | 26 | out=info-description.out 27 | cleanup_fn rm -f $out 28 | rm -f $out 29 | 30 | nbdkit -U - --filter=exportname memory 1M \ 31 | default-export=hello exportdesc=fixed:world \ 32 | --run '$VG nbdinfo "$uri"' > $out 33 | cat $out 34 | 35 | grep 'export="hello":' $out 36 | grep 'description: world' $out 37 | grep 'export-size: 1048576' $out 38 | -------------------------------------------------------------------------------- /info/info-is-read-only.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | # Test --is read-only and --can write. 25 | 26 | requires nbdkit --version 27 | requires nbdkit null --version 28 | 29 | nbdkit -U - -r null \ 30 | --run '$VG nbdinfo --is read-only "nbd+unix:///?socket=$unixsocket"' 31 | nbdkit -U - -r null \ 32 | --run '! $VG nbdinfo --can write "nbd+unix:///?socket=$unixsocket"' 33 | nbdkit -U - null \ 34 | --run '$VG nbdinfo --can write "nbd+unix:///?socket=$unixsocket"' 35 | nbdkit -U - null \ 36 | --run '! $VG nbdinfo --is read-only "nbd+unix:///?socket=$unixsocket"' 37 | -------------------------------------------------------------------------------- /info/info-json.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | requires nbdkit --version 25 | requires nbdkit memory --version 26 | requires nbdkit -U - null --run 'test "$uri" != ""' 27 | requires jq --version 28 | 29 | out=info-json.out 30 | cleanup_fn rm -f $out 31 | 32 | nbdkit -U - -r memory size=1M --run '$VG nbdinfo --json "$uri"' > $out 33 | jq . < $out 34 | test $( jq -r '.protocol' < $out ) != "newstyle" 35 | test $( jq -r '.exports[0]."export-size"' < $out ) != "null" 36 | test $( jq -r '.exports[0].is_read_only' < $out ) = "true" 37 | test $( jq -r '.exports[0].contexts[] | select(. == "base:allocation")' \ 38 | < $out ) = "base:allocation" 39 | -------------------------------------------------------------------------------- /info/info-map-base-allocation-large.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | requires nbdkit --version 25 | requires nbdkit -U - null --run 'test "$uri" != ""' 26 | requires tr --version 27 | 28 | out=info-base-allocation-large.out 29 | cleanup_fn rm -f $out 30 | rm -f $out 31 | 32 | # The sparse allocator used by nbdkit-data-plugin uses a 32K page 33 | # size, and extents are always aligned with this. 34 | nbdkit -U - data data='1 @131072 2 @6442450944 3' size=8G \ 35 | --run '$VG nbdinfo --map "$uri"' > $out 36 | 37 | cat $out 38 | 39 | if [ "$(tr -s ' ' < $out)" != " 0 32768 0 data 40 | 32768 98304 3 hole,zero 41 | 131072 32768 0 data 42 | 163840 6442287104 3 hole,zero 43 | 6442450944 32768 0 data 44 | 6442483712 2147450880 3 hole,zero" ]; then 45 | echo "$0: unexpected output from nbdinfo --map" 46 | exit 1 47 | fi 48 | -------------------------------------------------------------------------------- /info/info-map-base-allocation-weird.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | requires nbdkit --version 25 | requires nbdkit -U - null --run 'test "$uri" != ""' 26 | requires nbdkit sh --version 27 | requires tr --version 28 | 29 | out=info-base-allocation-weird.out 30 | cleanup_fn rm -f $out 31 | rm -f $out 32 | 33 | # This is a "weird" server that returns extents that are all 1 byte. 34 | nbdkit -U - sh - \ 35 | --run '$VG nbdinfo --map "$uri"' > $out <<'EOF' 36 | case "$1" in 37 | get_size) echo 32 ;; 38 | pread) dd if=/dev/zero count=$3 iflag=count_bytes ;; 39 | can_extents) exit 0 ;; 40 | extents) echo $4 1 `[ $4 -ge 16 ] && [ $4 -le 19 ]; echo $?`;; 41 | *) exit 2 ;; 42 | esac 43 | EOF 44 | 45 | cat $out 46 | 47 | if [ "$(tr -s ' ' < $out)" != " 0 16 1 hole 48 | 16 4 0 data 49 | 20 12 1 hole" ]; then 50 | echo "$0: unexpected output from nbdinfo --map" 51 | exit 1 52 | fi 53 | -------------------------------------------------------------------------------- /info/info-map-base-allocation-zero.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | requires nbdkit --version 25 | requires nbdkit -U - null --run 'test "$uri" != ""' 26 | 27 | out=info-base-allocation-zero.out 28 | cleanup_fn rm -f $out 29 | rm -f $out 30 | 31 | nbdkit -U - null --run '$VG nbdinfo --map "$uri"' > $out 32 | 33 | cat $out 34 | 35 | if [ "$(cat $out)" != "" ]; then 36 | echo "$0: unexpected output from nbdinfo --map" 37 | exit 1 38 | fi 39 | -------------------------------------------------------------------------------- /info/info-map-base-allocation.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | requires nbdkit --version 25 | requires nbdkit -U - null --run 'test "$uri" != ""' 26 | requires tr --version 27 | 28 | out=info-base-allocation.out 29 | cleanup_fn rm -f $out 30 | rm -f $out 31 | 32 | # The sparse allocator used by nbdkit-data-plugin uses a 32K page 33 | # size, and extents are always aligned with this. 34 | nbdkit -U - data data='1 @131072 2' size=1M \ 35 | --run '$VG nbdinfo --map "$uri"' > $out 36 | 37 | cat $out 38 | 39 | if [ "$(tr -s ' ' < $out)" != " 0 32768 0 data 40 | 32768 98304 3 hole,zero 41 | 131072 32768 0 data 42 | 163840 884736 3 hole,zero" ]; then 43 | echo "$0: unexpected output from nbdinfo --map" 44 | exit 1 45 | fi 46 | -------------------------------------------------------------------------------- /info/info-map-totals.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | requires nbdkit --version 25 | requires nbdkit -U - null --run 'test "$uri" != ""' 26 | requires tr --version 27 | 28 | out=info-map-totals.out 29 | cleanup_fn rm -f $out 30 | rm -f $out 31 | 32 | # The sparse allocator used by nbdkit-data-plugin uses a 32K page 33 | # size, and extents are always aligned with this. 34 | nbdkit -U - data data='1 @131072 2' size=1M \ 35 | --run '$VG nbdinfo --map --totals "$uri"' > $out 36 | 37 | cat $out 38 | 39 | if [ "$(tr -s ' ' < $out)" != " 65536 6.2% 0 data 40 | 983040 93.8% 3 hole,zero" ]; then 41 | echo "$0: unexpected output from nbdinfo --map" 42 | exit 1 43 | fi 44 | -------------------------------------------------------------------------------- /info/info-null.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | requires nbdkit --version 25 | requires nbdkit null --version 26 | requires nbdkit -U - null --run 'test "$uri" != ""' 27 | 28 | out=info-null.out 29 | cleanup_fn rm -f $out 30 | 31 | nbdkit -U - null \ 32 | --run '$VG nbdinfo --list "$uri"' > $out 33 | cat $out 34 | grep 'export-size: 0$' $out 35 | -------------------------------------------------------------------------------- /info/info-oldstyle.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | requires nbdkit --version 25 | requires nbdkit memory --version 26 | 27 | out=info-oldstyle.out 28 | cleanup_fn rm -f $out 29 | 30 | nbdkit --oldstyle -U - memory size=1M \ 31 | --run '$VG nbdinfo "nbd+unix:///?socket=$unixsocket"' > $out 32 | cat $out 33 | grep "protocol: oldstyle" $out 34 | -------------------------------------------------------------------------------- /info/info-packets.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | requires nbdkit --version 25 | requires nbdkit --no-sr memory --version 26 | 27 | out=info-packets.out 28 | cleanup_fn rm -f $out 29 | 30 | nbdkit --no-sr -U - memory size=1M \ 31 | --run '$VG nbdinfo "nbd+unix:///?socket=$unixsocket"' > $out 32 | cat $out 33 | grep "protocol: .*using simple packets" $out 34 | 35 | nbdkit -U - memory size=1M \ 36 | --run '$VG nbdinfo "nbd+unix:///?socket=$unixsocket"' > $out 37 | cat $out 38 | grep "protocol: .*using structured packets" $out 39 | -------------------------------------------------------------------------------- /info/info-size.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | requires nbdkit --version 25 | requires nbdkit memory --version 26 | 27 | out=info-size.out 28 | cleanup_fn rm -f $out 29 | 30 | nbdkit -U - memory size=$((512*1024*1024)) \ 31 | --run '$VG nbdinfo --size "nbd+unix:///?socket=$unixsocket"' > $out 32 | test "$(cat $out)" -eq $((512*1024*1024)) 33 | -------------------------------------------------------------------------------- /info/info-text.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | requires nbdkit --version 25 | requires nbdkit memory --version 26 | 27 | # This test requires nbdkit >= 1.12. 28 | minor=$( nbdkit --dump-config | grep ^version_minor | cut -d= -f2 ) 29 | requires test $minor -ge 12 30 | 31 | out=info-text.out 32 | cleanup_fn rm -f $out 33 | 34 | nbdkit -U - memory size=1M \ 35 | --run '$VG nbdinfo "nbd+unix:///?socket=$unixsocket"' > $out 36 | cat $out 37 | grep "export-size: $((1024*1024))" $out 38 | grep "uri: nbd+unix:///?socket=" $out 39 | sed -n '/contexts:/ { N; p; q; }' $out | grep . 40 | -------------------------------------------------------------------------------- /info/size.c: -------------------------------------------------------------------------------- 1 | /* NBD client library in userspace 2 | * Copyright Red Hat 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | #include "nbdinfo.h" 28 | 29 | void 30 | do_size (void) 31 | { 32 | int64_t size; 33 | 34 | size = nbd_get_size (nbd); 35 | if (size == -1) { 36 | fprintf (stderr, "%s: %s\n", progname, nbd_get_error ()); 37 | exit (EXIT_FAILURE); 38 | } 39 | 40 | fprintf (fp, "%" PRIi64 "\n", size); 41 | } 42 | -------------------------------------------------------------------------------- /info/test-long-options.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # Test that nbdinfo --long-options looks sane. 20 | 21 | . ../tests/functions.sh 22 | set -e 23 | set -x 24 | 25 | output=test-long-options.out 26 | cleanup_fn rm -f $output 27 | 28 | $VG nbdinfo --long-options > $output 29 | if [ $? != 0 ]; then 30 | echo "$0: unexpected exit status" 31 | fail=1 32 | fi 33 | cat $output 34 | grep -- --list $output 35 | grep -- --map $output 36 | grep -- --version $output 37 | -------------------------------------------------------------------------------- /info/test-short-options.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # Test that nbdinfo --short-options looks sane. 20 | 21 | . ../tests/functions.sh 22 | set -e 23 | set -x 24 | 25 | output=test-short-options.out 26 | cleanup_fn rm -f $output 27 | 28 | $VG nbdinfo --short-options > $output 29 | if [ $? != 0 ]; then 30 | echo "$0: unexpected exit status" 31 | fail=1 32 | fi 33 | cat $output 34 | grep -- -L $output 35 | grep -- -V $output 36 | -------------------------------------------------------------------------------- /info/test-version.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # Test that nbdinfo --version looks sane. 20 | 21 | fail=0 22 | output=$($VG nbdinfo --version) 23 | if [ $? != 0 ]; then 24 | echo "$0: unexpected exit status" 25 | fail=1 26 | fi 27 | if [ "$output" != "nbdinfo $EXPECTED_VERSION 28 | libnbd $EXPECTED_VERSION" ]; then 29 | echo "$0: unexpected output" 30 | fail=1 31 | fi 32 | echo "$output" 33 | exit $fail 34 | -------------------------------------------------------------------------------- /info/utils.c: -------------------------------------------------------------------------------- 1 | /* NBD client library in userspace 2 | * Copyright Red Hat 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | #include "nbdinfo.h" 25 | 26 | void 27 | print_json_string (const char *str) 28 | { 29 | const unsigned char *s = (const unsigned char *)str; 30 | fputc ('"', fp); 31 | for (; *s; s++) { 32 | switch (*s) { 33 | case '\\': 34 | case '"': 35 | fputc ('\\', fp); 36 | fputc (*s, fp); 37 | break; 38 | default: 39 | if (*s < ' ') 40 | fprintf (fp, "\\u%04x", *s); 41 | else 42 | fputc (*s, fp); 43 | } 44 | } 45 | fputc ('"', fp); 46 | } 47 | -------------------------------------------------------------------------------- /interop/list-exports-nbd-config: -------------------------------------------------------------------------------- 1 | [generic] 2 | allowlist = true 3 | [disk1] 4 | exportname = /dev/null 5 | [disk2] 6 | exportname = /dev/null 7 | -------------------------------------------------------------------------------- /interop/list-exports-test-dir/disk1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libguestfs/libnbd/9075f68ffc8bed320d0d1d46f1f0456d10626878/interop/list-exports-test-dir/disk1 -------------------------------------------------------------------------------- /interop/list-exports-test-dir/disk2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libguestfs/libnbd/9075f68ffc8bed320d0d1d46f1f0456d10626878/interop/list-exports-test-dir/disk2 -------------------------------------------------------------------------------- /interop/nbd-server-tls.conf.in: -------------------------------------------------------------------------------- 1 | [generic] 2 | cacertfile = @abs_top_builddir@/tests/pki/ca-cert.pem 3 | certfile = @abs_top_builddir@/tests/pki/server-cert.pem 4 | keyfile = @abs_top_builddir@/tests/pki/server-key.pem 5 | #force_tls = 1 6 | -------------------------------------------------------------------------------- /interop/structured-read.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # Test structured read callbacks. 20 | 21 | source ../tests/functions.sh 22 | set -e 23 | set -x 24 | 25 | requires qemu-img --version 26 | requires qemu-io --version 27 | requires qemu-nbd --version 28 | 29 | files="structured-read.qcow2" 30 | rm -f $files 31 | cleanup_fn rm -f $files 32 | 33 | # Create file with cluster size 512 and contents all 1 except for single 34 | # 512-byte hole at offset 2048 35 | qemu-img create -f qcow2 -o cluster_size=512,compat=v3 structured-read.qcow2 3k 36 | qemu-io -d unmap -f qcow2 -c 'w -P 1 0 3k' -c 'w -zu 2k 512' \ 37 | structured-read.qcow2 38 | 39 | # Run the test. 40 | $VG ./structured-read qemu-nbd -f qcow2 structured-read.qcow2 41 | -------------------------------------------------------------------------------- /lib/libnbd.pc.in: -------------------------------------------------------------------------------- 1 | # nbd client library in userspace 2 | # @configure_input@ 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | prefix=@prefix@ 20 | exec_prefix=@exec_prefix@ 21 | libdir=@libdir@ 22 | includedir=@includedir@ 23 | 24 | Name: @PACKAGE_NAME@ 25 | Version: @PACKAGE_VERSION@ 26 | Description: NBD client library in userspace 27 | Requires: 28 | Cflags: 29 | Libs: -lnbd 30 | -------------------------------------------------------------------------------- /lib/local/libnbd.pc.in: -------------------------------------------------------------------------------- 1 | # nbd client library in userspace 2 | # @configure_input@ 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # Dummy pkg-config file which is used to allow out of tree packages to 20 | # be configured against the libnbd tree without libnbd needing to be 21 | # installed. 22 | # 23 | # Note if you are using the ./run script then you don't need to worry 24 | # about this because the script sets PKG_CONFIG_PATH correctly. 25 | 26 | prefix=@abs_top_builddir@ 27 | exec_prefix=@abs_top_builddir@ 28 | libdir=@abs_top_builddir@/lib/.libs 29 | includedir=@abs_top_srcdir@/include 30 | 31 | Name: @PACKAGE_NAME@ 32 | Version: @PACKAGE_VERSION@ 33 | Description: NBD client library in userspace 34 | Requires: 35 | Cflags: -I${includedir} 36 | Libs: -L${libdir} -lnbd 37 | -------------------------------------------------------------------------------- /lib/test-fork-safe-assert.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | set +e 20 | 21 | ./test-fork-safe-assert 2>test-fork-safe-assert.err 22 | exit_status=$? 23 | 24 | set -e 25 | 26 | test $exit_status -gt 128 27 | signal_name=$(kill -l $exit_status) 28 | test "x$signal_name" = xABRT || test "x$signal_name" = xSIGABRT 29 | 30 | ptrn="^test-fork-safe-assert\\.c:[0-9]+: main: Assertion \`FALSE' failed\\.\$" 31 | grep -E -q -- "$ptrn" test-fork-safe-assert.err 32 | grep -v -q "\`TRUE'" test-fork-safe-assert.err 33 | -------------------------------------------------------------------------------- /m4/ac_c_compile_flags.m4: -------------------------------------------------------------------------------- 1 | # This program is free software; you can redistribute it and/or modify 2 | # it under the terms of the GNU General Public License as published by 3 | # the Free Software Foundation; either version 2 of the License, or 4 | # (at your option) any later version. 5 | # 6 | # This program is distributed in the hope that it will be useful, 7 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 8 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 | # GNU General Public License for more details. 10 | # 11 | # You should have received a copy of the GNU General Public License 12 | # along with this program; if not, write to the Free Software 13 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 14 | 15 | # Originally from: 16 | # https://github.com/WinterMute/prboom/blob/master/autotools/ac_c_compile_flags.m4 17 | # RWMJ: I adapted it to add the extra parameters and fixed a few bugs. 18 | 19 | # AC_C_COMPILE_FLAGS(VAR, FLAGS TO TEST, [CFLAGS_FOR_TEST = $CFLAGS]) 20 | # ---------------------------------------------------------- 21 | # Check if compiler flag $2 is supported, if so add it to $1. 22 | # Extra CFLAGS for the test can be passed in $3. 23 | AC_DEFUN([AC_C_COMPILE_FLAGS],[ 24 | CFLAGS_FOR_TEST="m4_default([$3], [$CFLAGS])" 25 | for flag in $2 26 | do 27 | AC_MSG_CHECKING(whether the compiler supports $flag) 28 | SAVED_CFLAGS="$CFLAGS" 29 | CFLAGS="$CFLAGS_FOR_TEST $flag" 30 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM() 31 | ],[ 32 | AC_MSG_RESULT(yes) 33 | $1="${$1} $flag" 34 | ],[AC_MSG_RESULT(no)]) 35 | CFLAGS="$SAVED_CFLAGS" 36 | done 37 | ]) 38 | -------------------------------------------------------------------------------- /ocaml/META.in: -------------------------------------------------------------------------------- 1 | name="nbd" 2 | version="@PACKAGE_VERSION@" 3 | description="libnbd bindings for OCaml" 4 | requires="unix" 5 | archive(byte)="mlnbd.cma" 6 | archive(native)="mlnbd.cmxa" 7 | -------------------------------------------------------------------------------- /ocaml/examples/extents.ml: -------------------------------------------------------------------------------- 1 | open Printf 2 | 3 | let () = 4 | NBD.with_handle ( 5 | fun nbd -> 6 | NBD.add_meta_context nbd "base:allocation"; 7 | NBD.connect_command nbd 8 | ["nbdkit"; "-s"; "--exit-with-parent"; "-r"; 9 | "sparse-random"; "8G"]; 10 | 11 | (* Read the extents and print them. *) 12 | let size = NBD.get_size nbd in 13 | let fetch_offset = ref 0_L in 14 | while !fetch_offset < size do 15 | let remaining = Int64.sub size !fetch_offset in 16 | let fetch_size = min remaining 0x8000_0000_L in 17 | NBD.block_status nbd fetch_size !fetch_offset ( 18 | fun meta _ entries err -> 19 | printf "nbd_block_status callback: meta=%s err=%d\n" meta !err; 20 | if meta = "base:allocation" then ( 21 | printf "index\t%16s %16s %s\n" "offset" "length" "flags"; 22 | for i = 0 to Array.length entries / 2 - 1 do 23 | let len = entries.(i*2) 24 | and flags = 25 | match entries.(i*2+1) with 26 | | 0_L -> "data" 27 | | 1_L -> "hole" 28 | | 2_L -> "zero" 29 | | 3_L -> "hole+zero" 30 | | unknown -> sprintf "unknown (%Ld)" unknown in 31 | printf "%d:\t%16Ld %16Ld %s\n" i !fetch_offset len flags; 32 | fetch_offset := Int64.add !fetch_offset len 33 | done; 34 | ); 35 | 0 36 | ) (* NBD.block_status *) 37 | done 38 | ) 39 | -------------------------------------------------------------------------------- /ocaml/examples/get_size.ml: -------------------------------------------------------------------------------- 1 | (* This example is similar to nbdinfo --size . It connects to an 2 | * NBD URI and queries the size of the default export. To try it out 3 | * do this from the top build directory: 4 | * 5 | * nbdkit -U - null 1G --run './run ocaml/examples/get_size.opt $uri' 6 | *) 7 | 8 | open Printf 9 | 10 | let () = 11 | if Array.length Sys.argv <> 2 then 12 | failwith "usage: get_size URI"; 13 | let uri = Sys.argv.(1) in 14 | 15 | NBD.with_handle ( 16 | fun nbd -> 17 | (* Connect to the NBD URI. *) 18 | NBD.connect_uri nbd uri; 19 | 20 | let size = NBD.get_size nbd in 21 | printf "uri = %s size = %Ld\n" uri size 22 | ) 23 | -------------------------------------------------------------------------------- /ocaml/examples/open_qcow2.ml: -------------------------------------------------------------------------------- 1 | (* Open a qcow2 file using an external NBD server (qemu-nbd). *) 2 | 3 | open Printf 4 | 5 | let () = 6 | if Array.length Sys.argv <> 2 then 7 | failwith "usage: open_qcow2 file.qcow2"; 8 | let filename = Sys.argv.(1) in 9 | 10 | NBD.with_handle ( 11 | fun nbd -> 12 | (* Run qemu-nbd as a subprocess using 13 | * systemd socket activation. 14 | *) 15 | let args = [ "qemu-nbd"; "-f"; "qcow2"; filename ] in 16 | NBD.connect_systemd_socket_activation nbd args; 17 | 18 | (* Read the first sector of raw data. *) 19 | let buf = Bytes.create 512 and offset = 0_L in 20 | NBD.pread nbd buf offset; 21 | 22 | (* Hexdump it. *) 23 | let chan = Unix.open_process_out "hexdump -C" in 24 | output_bytes chan buf; 25 | ignore (Unix.close_process_out chan) 26 | 27 | (* The qemu-nbd server will exit when we close the 28 | * handle (implicitly closed by NBD.with_handle). 29 | *) 30 | ) 31 | -------------------------------------------------------------------------------- /ocaml/tests/test_010_import.ml: -------------------------------------------------------------------------------- 1 | (* hey emacs, this is OCaml code: -*- tuareg -*- *) 2 | (* libnbd OCaml test case 3 | * Copyright Red Hat 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | *) 19 | 20 | (* nothing - just checks we can link with libnbd *) 21 | -------------------------------------------------------------------------------- /ocaml/tests/test_100_handle.ml: -------------------------------------------------------------------------------- 1 | (* hey emacs, this is OCaml code: -*- tuareg -*- *) 2 | (* libnbd OCaml test case 3 | * Copyright Red Hat 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | *) 19 | 20 | let () = 21 | let nbd = NBD.create () in 22 | ignore nbd 23 | 24 | let () = Gc.compact () 25 | -------------------------------------------------------------------------------- /ocaml/tests/test_105_with_handle.ml: -------------------------------------------------------------------------------- 1 | (* hey emacs, this is OCaml code: -*- tuareg -*- *) 2 | (* libnbd OCaml test case 3 | * Copyright Red Hat 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | *) 19 | 20 | exception Test 21 | 22 | let () = 23 | NBD.with_handle (fun nbd -> ()); 24 | 25 | (try 26 | ignore (NBD.with_handle (fun nbd -> raise Test)); 27 | assert false 28 | with Test -> () (* expected *) 29 | | exn -> failwith (Printexc.to_string exn) 30 | ); 31 | 32 | (* Were two handles created above? 33 | * XXX How to test if close was called twice? 34 | *) 35 | let h = NBD.get_handle_name (NBD.create ()) in 36 | assert (h = "nbd3") 37 | 38 | let () = Gc.compact () 39 | -------------------------------------------------------------------------------- /ocaml/tests/test_110_defaults.ml: -------------------------------------------------------------------------------- 1 | (* hey emacs, this is OCaml code: -*- tuareg -*- *) 2 | (* libnbd OCaml test case 3 | * Copyright Red Hat 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | *) 19 | 20 | let () = 21 | NBD.with_handle ( 22 | fun nbd -> 23 | let name = NBD.get_export_name nbd in 24 | assert (name = ""); 25 | let info = NBD.get_full_info nbd in 26 | assert (not info); 27 | let tls = NBD.get_tls nbd in 28 | assert (tls = NBD.TLS.DISABLE); 29 | let sr = NBD.get_request_structured_replies nbd in 30 | assert sr; 31 | let meta = NBD.get_request_meta_context nbd in 32 | assert meta; 33 | let bs = NBD.get_request_block_size nbd in 34 | assert bs; 35 | let init = NBD.get_pread_initialize nbd in 36 | assert init; 37 | let flags = NBD.get_handshake_flags nbd in 38 | assert (flags = NBD.HANDSHAKE_FLAG.mask); 39 | let opt = NBD.get_opt_mode nbd in 40 | assert (not opt) 41 | ) 42 | 43 | let () = Gc.compact () 44 | -------------------------------------------------------------------------------- /ocaml/tests/test_130_private_data.ml: -------------------------------------------------------------------------------- 1 | (* hey emacs, this is OCaml code: -*- tuareg -*- *) 2 | (* libnbd OCaml test case 3 | * Copyright Red Hat 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | *) 19 | 20 | let () = 21 | let nbd = NBD.create () in 22 | assert (NBD.get_private_data nbd == 0); 23 | assert (NBD.set_private_data nbd 42 == 0); 24 | assert (NBD.get_private_data nbd == 42) 25 | 26 | let () = Gc.compact () 27 | -------------------------------------------------------------------------------- /ocaml/tests/test_200_connect_command.ml: -------------------------------------------------------------------------------- 1 | (* hey emacs, this is OCaml code: -*- tuareg -*- *) 2 | (* libnbd OCaml test case 3 | * Copyright Red Hat 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | *) 19 | 20 | let () = 21 | NBD.with_handle ( 22 | fun nbd -> 23 | NBD.connect_command nbd 24 | ["nbdkit"; "-s"; "--exit-with-parent"; "-v"; 25 | "null"] 26 | ) 27 | 28 | let () = Gc.compact () 29 | -------------------------------------------------------------------------------- /ocaml/tests/test_210_opt_abort.ml: -------------------------------------------------------------------------------- 1 | (* hey emacs, this is OCaml code: -*- tuareg -*- *) 2 | (* libnbd OCaml test case 3 | * Copyright Red Hat 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | *) 19 | 20 | let () = 21 | let nbd = NBD.create () in 22 | NBD.set_opt_mode nbd true; 23 | NBD.connect_command nbd 24 | ["nbdkit"; "-s"; "--exit-with-parent"; "-v"; "null"]; 25 | let proto = NBD.get_protocol nbd in 26 | assert (proto = "newstyle-fixed"); 27 | let sr = NBD.get_structured_replies_negotiated nbd in 28 | assert sr; 29 | NBD.opt_abort nbd; 30 | let closed = NBD.aio_is_closed nbd in 31 | assert closed; 32 | try 33 | let _ = NBD.get_size nbd in 34 | assert false 35 | with 36 | NBD.Error (errstr, errno) -> 37 | () 38 | 39 | let () = Gc.compact () 40 | -------------------------------------------------------------------------------- /ocaml/tests/test_300_get_size.ml: -------------------------------------------------------------------------------- 1 | (* hey emacs, this is OCaml code: -*- tuareg -*- *) 2 | (* libnbd OCaml test case 3 | * Copyright Red Hat 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | *) 19 | 20 | open Printf 21 | 22 | let expected = 1048576_L 23 | 24 | let () = 25 | let nbd = NBD.create () in 26 | NBD.connect_command nbd 27 | ["nbdkit"; "-s"; "--exit-with-parent"; "-v"; "null"; 28 | sprintf "size=%Ld" expected]; 29 | let actual = NBD.get_size nbd in 30 | 31 | assert (actual = expected) 32 | 33 | let () = Gc.compact () 34 | -------------------------------------------------------------------------------- /ocaml/tests/test_600_debug_callback.ml: -------------------------------------------------------------------------------- 1 | (* hey emacs, this is OCaml code: -*- tuareg -*- *) 2 | (* libnbd OCaml test case 3 | * Copyright Red Hat 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | *) 19 | 20 | let messages = ref [] 21 | let f id context msg = 22 | assert (id = 42); 23 | messages := !messages @ [msg]; 24 | 0 25 | 26 | let () = 27 | let nbd = NBD.create () in 28 | NBD.set_debug_callback nbd (f 42); 29 | 30 | NBD.connect_command nbd ["nbdkit"; "-s"; "--exit-with-parent"; "null"]; 31 | NBD.shutdown nbd; 32 | 33 | print_endline "<<<"; 34 | List.iter print_endline !messages; 35 | print_endline ">>>" 36 | 37 | let () = Gc.compact () 38 | -------------------------------------------------------------------------------- /ocaml/tests/test_610_exception.ml: -------------------------------------------------------------------------------- 1 | (* hey emacs, this is OCaml code: -*- tuareg -*- *) 2 | (* libnbd OCaml test case 3 | * Copyright Red Hat 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | *) 19 | 20 | open Printf 21 | 22 | let () = 23 | let nbd = NBD.create () in 24 | 25 | try 26 | (* This will always throw an exception because the handle is not 27 | * connected. 28 | *) 29 | NBD.pread nbd (Bytes.create 512) 0_L 30 | with 31 | NBD.Error (errstr, errno) -> 32 | printf "string = %s\n" errstr; 33 | printf "errno = %s\n" 34 | (match errno with None -> "None" | Some err -> Unix.error_message err); 35 | Gc.compact (); 36 | exit 0 ;; 37 | 38 | (* If we reach here then we didn't catch the exception above. *) 39 | exit 1 40 | -------------------------------------------------------------------------------- /python/.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | # Print the source code generating the error/warning in question. 3 | show_source = True 4 | 5 | # Count the number of occurrences of each error/warning code and print a report. 6 | statistics = True 7 | -------------------------------------------------------------------------------- /python/pycodestyle.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | requires flake8 --version 25 | 26 | d="$abs_top_srcdir"/python 27 | test -f "$d"/nbd.py 28 | flake8 "$d"/nbd.py "$d"/nbdsh.py "$d"/examples/*.py "$d"/t/*.py 29 | -------------------------------------------------------------------------------- /python/run-python-tests.in: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # libnbd: derived from: hivex Python bindings 3 | # Copyright Red Hat 4 | # 5 | # This program is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 2 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | set -e 20 | shopt -s nullglob 21 | export srcdir=@srcdir@ 22 | 23 | for f in @srcdir@/t/*.py; do 24 | basename "$f" 25 | $PYTHON "$f" 26 | done 27 | -------------------------------------------------------------------------------- /python/t/010-import.py: -------------------------------------------------------------------------------- 1 | # libnbd Python bindings 2 | # Copyright Red Hat 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | import nbd 19 | 20 | assert id(nbd) 21 | -------------------------------------------------------------------------------- /python/t/100-handle.py: -------------------------------------------------------------------------------- 1 | # libnbd Python bindings 2 | # Copyright Red Hat 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | import nbd 19 | 20 | h = nbd.NBD() 21 | -------------------------------------------------------------------------------- /python/t/105-with-handle.py: -------------------------------------------------------------------------------- 1 | # libnbd Python bindings 2 | # Copyright Red Hat 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | import nbd 19 | 20 | with nbd.nbd() as h: 21 | assert h.get_handle_name().startswith("nbd") 22 | -------------------------------------------------------------------------------- /python/t/110-defaults.py: -------------------------------------------------------------------------------- 1 | # libnbd Python bindings 2 | # Copyright Red Hat 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | import nbd 19 | 20 | h = nbd.NBD() 21 | assert h.get_export_name() == "" 22 | assert h.get_full_info() is False 23 | assert h.get_tls() == nbd.TLS_DISABLE 24 | assert h.get_request_structured_replies() is True 25 | assert h.get_request_meta_context() is True 26 | assert h.get_request_block_size() is True 27 | assert h.get_pread_initialize() is True 28 | assert h.get_handshake_flags() == nbd.HANDSHAKE_FLAG_MASK 29 | assert h.get_opt_mode() is False 30 | -------------------------------------------------------------------------------- /python/t/200-connect-command.py: -------------------------------------------------------------------------------- 1 | # libnbd Python bindings 2 | # Copyright Red Hat 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | import nbd 19 | 20 | h = nbd.NBD() 21 | h.connect_command(["nbdkit", "-s", "--exit-with-parent", "-v", "null"]) 22 | -------------------------------------------------------------------------------- /python/t/210-opt-abort.py: -------------------------------------------------------------------------------- 1 | # libnbd Python bindings 2 | # Copyright Red Hat 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | import nbd 19 | import errno 20 | 21 | h = nbd.NBD() 22 | h.set_opt_mode(True) 23 | h.connect_command(["nbdkit", "-s", "--exit-with-parent", "-v", "null"]) 24 | assert h.get_protocol() == "newstyle-fixed" 25 | assert h.get_structured_replies_negotiated() 26 | h.opt_abort() 27 | assert h.aio_is_closed() 28 | try: 29 | h.get_size() 30 | assert False 31 | except nbd.Error as ex: 32 | assert ex.errnum == errno.EINVAL 33 | -------------------------------------------------------------------------------- /python/t/300-get-size.py: -------------------------------------------------------------------------------- 1 | # libnbd Python bindings 2 | # Copyright Red Hat 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | import nbd 19 | 20 | expected = 1048576 21 | 22 | h = nbd.NBD() 23 | h.connect_command(["nbdkit", "-s", "--exit-with-parent", "-v", "null", 24 | "size=%d" % expected]) 25 | actual = h.get_size() 26 | 27 | assert actual == expected 28 | -------------------------------------------------------------------------------- /python/t/410-pwrite.py: -------------------------------------------------------------------------------- 1 | # libnbd Python bindings 2 | # Copyright Red Hat 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | import os 19 | 20 | import nbd 21 | 22 | buf1 = bytearray(512) 23 | buf1[10] = 1 24 | buf1[510] = 0x55 25 | buf1[511] = 0xAA 26 | 27 | datafile = "410-pwrite.data" 28 | 29 | with open(datafile, "wb") as f: 30 | f.truncate(512) 31 | 32 | h = nbd.NBD() 33 | h.connect_command(["nbdkit", "-s", "--exit-with-parent", "-v", 34 | "file", datafile]) 35 | h.pwrite(buf1, 0, nbd.CMD_FLAG_FUA) 36 | buf2 = h.pread(512, 0) 37 | 38 | assert buf1 == buf2 39 | 40 | with open(datafile, "rb") as f: 41 | content = f.read() 42 | 43 | assert buf1 == content 44 | 45 | os.unlink(datafile) 46 | -------------------------------------------------------------------------------- /python/t/600-debug-callback.py: -------------------------------------------------------------------------------- 1 | # libnbd Python bindings 2 | # Copyright Red Hat 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | import nbd 19 | 20 | h = nbd.NBD() 21 | 22 | messages = [] 23 | 24 | 25 | def f(id, context, msg): 26 | global messages 27 | 28 | assert id == 42 29 | messages.append(msg) 30 | 31 | 32 | h.set_debug_callback(lambda *args: f(42, *args)) 33 | 34 | h.connect_command(["nbdkit", "-s", "--exit-with-parent", "null"]) 35 | h.shutdown() 36 | 37 | # Try to trigger garbage collection of h 38 | h = None 39 | 40 | print("%r" % messages) 41 | -------------------------------------------------------------------------------- /python/t/610-exception.py: -------------------------------------------------------------------------------- 1 | # libnbd Python bindings 2 | # Copyright Red Hat 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | import nbd 19 | 20 | h = nbd.NBD() 21 | 22 | try: 23 | # This will always throw an exception because the handle is not 24 | # connected. 25 | h.pread(0, 0) 26 | except nbd.Error as ex: 27 | print("string = %s" % ex.string) 28 | print("errno = %s" % ex.errno) 29 | print("errnum = %d" % ex.errnum) 30 | exit(0) 31 | 32 | # If we reach here then we didn't catch the exception above. 33 | exit(1) 34 | -------------------------------------------------------------------------------- /python/test-aio-connect-unix.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | . ../tests/functions.sh 20 | 21 | set -e 22 | set -x 23 | 24 | requires nbdkit --version 25 | requires $PYTHON --version 26 | 27 | nbdkit -U - null --run '$PYTHON -c " 28 | import nbd 29 | import sys 30 | h = nbd.NBD() 31 | addr = sys.argv[1] 32 | h.aio_connect(addr) 33 | while h.aio_is_connecting(): 34 | h.poll(1) 35 | assert h.aio_is_ready() 36 | " "$unixsocket"' 37 | -------------------------------------------------------------------------------- /scripts/git.orderfile: -------------------------------------------------------------------------------- 1 | # nbd client library in userspace 2 | # Copyright Red Hat 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 2 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | # You can use this to change the ordering of files within patches to 19 | # make them easier to follow. 20 | # 21 | # Use: 22 | # git diff -O scripts/git.orderfile 23 | # 24 | # Or make the change permanently by doing: 25 | # git config diff.orderFile scripts/git.orderfile 26 | 27 | # Documentation. 28 | docs/* 29 | *.pod 30 | 31 | # Build files. 32 | configure.ac 33 | Makefile.am 34 | 35 | # Source header files. 36 | lib/*.h 37 | common/*.h 38 | common/*/*.h 39 | 40 | # Generator files. 41 | generator/generator 42 | generator/* 43 | 44 | # Source files. 45 | lib/*.c 46 | lib/* 47 | common/* 48 | 49 | # Language bindings. 50 | python/* 51 | ocaml/* 52 | 53 | # Tests. 54 | tests/* 55 | examples/* 56 | interop/* 57 | 58 | # Anything else last. 59 | -------------------------------------------------------------------------------- /sh/examples/hexdump.sh: -------------------------------------------------------------------------------- 1 | nbdsh -c - <<'EOF' 2 | from subprocess import * 3 | 4 | h.connect_uri("nbd://localhost") 5 | bootsect = h.pread(512, 0) 6 | p = Popen("hexdump -C", shell=True, stdin=PIPE) 7 | p.stdin.write(bootsect) 8 | EOF 9 | -------------------------------------------------------------------------------- /sh/nbdsh.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh - 2 | # Copyright Red Hat 3 | # 4 | # @configure_input@ 5 | # 6 | # This library is free software; you can redistribute it and/or 7 | # modify it under the terms of the GNU Lesser General Public 8 | # License as published by the Free Software Foundation; either 9 | # version 2 of the License, or (at your option) any later version. 10 | # 11 | # This library is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public 17 | # License along with this library; if not, write to the Free Software 18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | # macOS's System Integrity Protection (SIP) misfeature removes the 21 | # DYLD_LIBRARY_PATH environment variable when passed to Apple (only) 22 | # binaries such as /bin/sh above. We must restore it here. Confine 23 | # this hack to Darwin only so it doesn't cause potential security 24 | # issues on normal platforms. 25 | case "@host_os@" in 26 | darwin*) 27 | if test -z "$DYLD_LIBRARY_PATH" && test -n "$_DYLD_LIBRARY_PATH"; then 28 | DYLD_LIBRARY_PATH="$_DYLD_LIBRARY_PATH" 29 | export DYLD_LIBRARY_PATH 30 | fi 31 | ;; 32 | esac 33 | 34 | # Test if /bin/sh supports exec -a option (only supported in bash 4.2 35 | # and above, and not part of POSIX). 36 | if /bin/sh -c 'exec -a test true' 2>/dev/null; then 37 | exec -a nbdsh @PYTHON@ -mnbd "$@" 38 | else 39 | exec @PYTHON@ -mnbd "$@" 40 | fi 41 | -------------------------------------------------------------------------------- /sh/test-help.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # Test that nbdsh --help looks sane. 20 | 21 | fail=0 22 | output=$(nbdsh --help) 23 | if [ $? != 0 ]; then 24 | echo "$0: unexpected exit status" 25 | fail=1 26 | fi 27 | if [[ ! ( "$output" =~ "usage:" && "$output" =~ "manual page" ) ]]; then 28 | echo "$0: unexpected output" 29 | fail=1 30 | fi 31 | echo "$output" 32 | exit $fail 33 | -------------------------------------------------------------------------------- /sh/test-implicit-handle.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # Test the implicit handle (h) and the -n option. 20 | 21 | . ../tests/functions.sh 22 | set -e 23 | 24 | $VG nbdsh -c ' 25 | assert h is not None 26 | assert isinstance(h, nbd.NBD) 27 | assert isinstance(h.get_debug(), bool) 28 | ' 29 | 30 | $VG nbdsh -n -c ' 31 | try: 32 | h 33 | except NameError: 34 | exit(0) 35 | else: 36 | import sys 37 | print("h should not be defined", file=sys.stderr) 38 | exit(1) 39 | ' 40 | -------------------------------------------------------------------------------- /sh/test-long-options.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # Test that nbdsh --long-options looks sane. 20 | 21 | . ../tests/functions.sh 22 | set -e 23 | set -x 24 | 25 | output=test-long-options.out 26 | cleanup_fn rm -f $output 27 | 28 | $VG nbdsh --long-options > $output 29 | if [ $? != 0 ]; then 30 | echo "$0: unexpected exit status" 31 | fail=1 32 | fi 33 | cat $output 34 | grep -- --command $output 35 | grep -- --uri $output 36 | grep -- --version $output 37 | -------------------------------------------------------------------------------- /sh/test-pattern.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # Test interaction with nbdkit, and for correct global handling over -c. 20 | 21 | . ../tests/functions.sh 22 | requires nbdkit --exit-with-parent --version 23 | requires nbdsh -c 'exit(not h.supports_uri())' 24 | 25 | sock=$(mktemp -u /tmp/libnbd-test-nbdsh.XXXXXX) 26 | pidfile=test-pattern.pid 27 | cleanup_fn rm -f $sock $pidfile 28 | nbdkit -v -P $pidfile --exit-with-parent -U $sock pattern size=1m & 29 | 30 | # Wait for the pidfile to appear. 31 | for i in {1..60}; do 32 | if test -f "$pidfile"; then 33 | break 34 | fi 35 | sleep 1 36 | done 37 | if ! test -f "$pidfile"; then 38 | echo "$0: nbdkit PID file $pidfile was not created" 39 | exit 1 40 | fi 41 | 42 | nbdsh -u "nbd+unix://?socket=$sock" \ 43 | -c ' 44 | def size(): 45 | return h.get_size() 46 | ' \ 47 | -c 'assert 1024*1024 == size()' \ 48 | -c 'assert h.pread(8, 8) == b"\x00\x00\x00\x00\x00\x00\x00\x08"' 49 | -------------------------------------------------------------------------------- /sh/test-short-options.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # Test that nbdsh --short-options looks sane. 20 | 21 | . ../tests/functions.sh 22 | set -e 23 | set -x 24 | 25 | output=test-short-options.out 26 | cleanup_fn rm -f $output 27 | 28 | $VG nbdsh --short-options > $output 29 | if [ $? != 0 ]; then 30 | echo "$0: unexpected exit status" 31 | fail=1 32 | fi 33 | cat $output 34 | grep -- -c $output 35 | grep -- -u $output 36 | grep -- -V $output 37 | -------------------------------------------------------------------------------- /sh/test-verbose.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # Test that nbdsh --verbose looks sane. 20 | 21 | . ../tests/functions.sh 22 | set -e 23 | 24 | unset LIBNBD_DEBUG 25 | 26 | $VG nbdsh -c 'assert h.get_debug() == False' 27 | $VG nbdsh -v -c 'assert h.get_debug() == True' 28 | -------------------------------------------------------------------------------- /sh/test-version.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # Test that nbdsh --version looks sane. 20 | 21 | fail=0 22 | output=$($VG nbdsh --version) 23 | if [ $? != 0 ]; then 24 | echo "$0: unexpected exit status" 25 | fail=1 26 | fi 27 | if [ "$output" != "nbdsh $EXPECTED_VERSION 28 | libnbd $EXPECTED_VERSION" ]; then 29 | echo "$0: unexpected output" 30 | fail=1 31 | fi 32 | echo "$output" 33 | exit $fail 34 | -------------------------------------------------------------------------------- /tests/aio-parallel-load-tls.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # Test AIO random load. 20 | 21 | . ../tests/functions.sh 22 | 23 | set -e 24 | set -x 25 | 26 | requires nbdkit --tls-verify-peer -U - null --run 'exit 0' 27 | 28 | nbdkit -U - --tls=require --tls-verify-peer --tls-psk=keys.psk \ 29 | memory size=64M \ 30 | --run '$VG ./aio-parallel-load-tls $unixsocket' 31 | -------------------------------------------------------------------------------- /tests/aio-parallel-load.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # Test AIO random load. 20 | 21 | nbdkit -U - memory size=64M \ 22 | --run './aio-parallel-load $unixsocket' 23 | -------------------------------------------------------------------------------- /tests/aio-parallel-tls.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # Test AIO parallel data integrity. 20 | 21 | . ../tests/functions.sh 22 | 23 | set -e 24 | set -x 25 | 26 | requires nbdkit --tls-verify-peer -U - null --run 'exit 0' 27 | 28 | nbdkit -U - --tls=require --tls-verify-peer --tls-psk=keys.psk \ 29 | --filter=cow \ 30 | pattern size=64M \ 31 | --run '$VG ./aio-parallel-tls $unixsocket' 32 | -------------------------------------------------------------------------------- /tests/aio-parallel.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # Test AIO parallel data integrity. 20 | 21 | nbdkit -U - \ 22 | --filter=cow \ 23 | pattern size=64M \ 24 | --run '$VG ./aio-parallel $unixsocket' 25 | -------------------------------------------------------------------------------- /tests/close-null.c: -------------------------------------------------------------------------------- 1 | /* NBD client library in userspace 2 | * Copyright Red Hat 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | /* Check that nbd_close (NULL) works. */ 20 | 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | int 29 | main (int argc, char *argv[]) 30 | { 31 | /* This should be ignored. */ 32 | nbd_close (NULL); 33 | exit (EXIT_SUCCESS); 34 | } 35 | -------------------------------------------------------------------------------- /tests/compile-c.c: -------------------------------------------------------------------------------- 1 | /* NBD client library in userspace 2 | * Copyright Red Hat 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | /* Compile, open and close a handle. */ 20 | 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | int 27 | main (int argc, char *argv[]) 28 | { 29 | struct nbd_handle *nbd; 30 | 31 | nbd = nbd_create (); 32 | if (nbd == NULL) { 33 | fprintf (stderr, "%s\n", nbd_get_error ()); 34 | exit (EXIT_FAILURE); 35 | } 36 | 37 | nbd_close (nbd); 38 | exit (EXIT_SUCCESS); 39 | } 40 | -------------------------------------------------------------------------------- /tests/compile-cxx.cpp: -------------------------------------------------------------------------------- 1 | /* NBD client library in userspace 2 | * Copyright Red Hat 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | /* Test compilation with C++. */ 20 | 21 | #ifndef __cplusplus 22 | #error "this test should be compiled with a C++ compiler" 23 | #endif 24 | 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | using namespace std; 31 | 32 | int 33 | main () 34 | { 35 | struct nbd_handle *nbd; 36 | 37 | nbd = nbd_create (); 38 | if (nbd == NULL) { 39 | cerr << nbd_get_error () << endl; 40 | exit (EXIT_FAILURE); 41 | } 42 | 43 | cout << nbd_get_package_name (nbd) 44 | << " " 45 | << nbd_get_version (nbd) 46 | << endl; 47 | 48 | nbd_close (nbd); 49 | exit (EXIT_SUCCESS); 50 | } 51 | -------------------------------------------------------------------------------- /tests/compile-header-only.c: -------------------------------------------------------------------------------- 1 | /* NBD client library in userspace 2 | * Copyright Red Hat 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | /* Check that does not require any other headers. */ 20 | 21 | #include 22 | 23 | int 24 | main (int argc, char *argv[]) 25 | { 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /tests/compile-iso-c99.c: -------------------------------------------------------------------------------- 1 | /* NBD client library in userspace 2 | * Copyright Red Hat 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | /* Test that (only simple) programs can be compiled by an ISO C99 20 | * compiler. 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | int 29 | main (int argc, char *argv[]) 30 | { 31 | struct nbd_handle *nbd; 32 | 33 | nbd = nbd_create (); 34 | if (nbd == NULL) { 35 | fprintf (stderr, "%s\n", nbd_get_error ()); 36 | exit (EXIT_FAILURE); 37 | } 38 | 39 | nbd_close (nbd); 40 | exit (EXIT_SUCCESS); 41 | } 42 | -------------------------------------------------------------------------------- /tests/meta-base-allocation.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # This is used to test metadata context "base:allocation". 20 | # See tests/meta-base-allocation.c and test 460 in language bindings. 21 | 22 | case "$1" in 23 | thread_model) 24 | echo parallel 25 | ;; 26 | get_size) 27 | echo 65536 28 | ;; 29 | pread) 30 | dd if=/dev/zero count=$3 iflag=count_bytes 31 | ;; 32 | can_extents) 33 | exit 0 34 | ;; 35 | extents) 36 | echo 0 8192 37 | echo 8192 8192 hole 38 | echo 16384 16384 hole,zero 39 | echo 32768 16384 zero 40 | echo 49152 16384 41 | ;; 42 | *) 43 | exit 2 44 | ;; 45 | esac 46 | -------------------------------------------------------------------------------- /tests/opt-info.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # This is used to test nbd_opt_info in various language bindings. 20 | # See tests/opt-info.c and test 230 in language bindings. 21 | 22 | # Export "a" is unavailable, other exports reflect their name as content. 23 | # Export "b" is writeable, others are read-only. 24 | # Thus, size and read-only status can be used to check info/go requests. 25 | 26 | case "$1" in 27 | open) 28 | if test "$3" = a; then 29 | echo ENOENT export not available >&2 30 | exit 1 31 | fi 32 | echo "$3" ;; 33 | get_size) 34 | printf %s "$2" | wc -c ;; 35 | can_write) 36 | if test "$2" != b; then 37 | exit 3; 38 | fi ;; 39 | pread) 40 | printf %s "$2" | dd bs=1 count=$3 skip=$4 ;; 41 | pwrite) 42 | dd of=/dev/null ;; 43 | *) 44 | exit 2 ;; 45 | esac 46 | -------------------------------------------------------------------------------- /tests/opt-list.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # This is used to test nbd_opt_list in various language bindings. 20 | # See tests/opt-list.c and test 220 in language bindings. 21 | 22 | case "$1" in 23 | config) 24 | if [ "$2" != mode ]; then echo EINVAL >&2; exit 1; fi 25 | echo "$3" > "$tmpdir/mode" ;; 26 | list_exports) 27 | read i < "$tmpdir/mode" 28 | case $i in 29 | 0) echo EINVAL listing not supported >&2; exit 1 ;; 30 | 1) echo NAMES; echo a; echo b ;; 31 | 2) echo NAMES ;; 32 | *) echo NAMES; echo a ;; 33 | esac ;; 34 | get_size) 35 | echo 512 ;; 36 | pread) 37 | dd bs=1 if=/dev/zero count=$3 ;; 38 | *) 39 | exit 2 ;; 40 | esac 41 | -------------------------------------------------------------------------------- /tests/pick-a-port.h: -------------------------------------------------------------------------------- 1 | /* NBD client library in userspace 2 | * Copyright Red Hat 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef LIBNBD_PICK_A_PORT 20 | #define LIBNBD_PICK_A_PORT 21 | 22 | extern int pick_a_port (void); 23 | 24 | #endif /* LIBNBD_PICK_A_PORT */ 25 | -------------------------------------------------------------------------------- /tests/requires.h: -------------------------------------------------------------------------------- 1 | /* NBD client library in userspace 2 | * Copyright Red Hat 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef LIBNBD_REQUIRES 20 | #define LIBNBD_REQUIRES 21 | 22 | extern void requires (const char *cmd); 23 | extern void requires_not (const char *cmd); 24 | 25 | /* Some specific tests using the requires() mechanism. */ 26 | extern void requires_qemu_nbd_tls_support (const char *qemu_nbd); 27 | extern void requires_qemu_nbd_tls_psk_support (const char *qemu_nbd); 28 | extern void requires_nbd_server_supports_inetd (const char *nbd_server); 29 | 30 | #endif /* LIBNBD_REQUIRES */ 31 | -------------------------------------------------------------------------------- /tests/synch-parallel-tls.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # Test synchronous parallel high level API requests. 20 | 21 | . ../tests/functions.sh 22 | 23 | set -e 24 | set -x 25 | 26 | requires nbdkit --tls-verify-peer -U - null --run 'exit 0' 27 | 28 | nbdkit -U - --tls=require --tls-verify-peer --tls-psk=keys.psk \ 29 | --filter=cow \ 30 | pattern size=8M \ 31 | --run './synch-parallel-tls $unixsocket' 32 | -------------------------------------------------------------------------------- /tests/synch-parallel.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nbd client library in userspace 3 | # Copyright Red Hat 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | # Test synchronous parallel high level API requests. 20 | 21 | nbdkit -U - \ 22 | --filter=cow \ 23 | pattern size=8M \ 24 | --run '$VG ./synch-parallel $unixsocket' 25 | -------------------------------------------------------------------------------- /ublk/nbdublk.h: -------------------------------------------------------------------------------- 1 | /* NBD client library in userspace 2 | * Copyright Red Hat 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef LIBNBD_NBDUBLK_H 20 | #define LIBNBD_NBDUBLK_H 21 | 22 | #include 23 | 24 | #include 25 | 26 | #include "vector.h" 27 | 28 | DEFINE_VECTOR_TYPE (handles, struct nbd_handle *); 29 | 30 | #define UBLKSRV_TGT_TYPE_NBD 0 31 | 32 | extern handles nbd; 33 | extern unsigned connections; 34 | extern bool readonly; 35 | extern bool rotational; 36 | extern bool can_fua; 37 | extern char *filename; 38 | extern uint64_t size; 39 | extern uint64_t min_block_size; 40 | extern uint64_t pref_block_size; 41 | extern bool verbose; 42 | 43 | extern struct ublksrv_tgt_type tgt_type; 44 | 45 | extern int start_daemon (struct ublksrv_ctrl_dev *dev); 46 | 47 | #endif /* LIBNBD_NBDUBLK_H */ 48 | -------------------------------------------------------------------------------- /ublk/not.cpp: -------------------------------------------------------------------------------- 1 | /* NBD client library in userspace 2 | * Copyright Red Hat 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #include 20 | 21 | /* This file does nothing except to force nbdublk to be linked as a 22 | * C++ program because libublksrv requires it. 23 | */ 24 | -------------------------------------------------------------------------------- /valgrind/Makefile.am: -------------------------------------------------------------------------------- 1 | # nbd client library in userspace 2 | # Copyright Red Hat 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 2 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | include $(top_srcdir)/subdir-rules.mk 19 | 20 | suppressions_files = $(wildcard $(srcdir)/*.suppressions) 21 | 22 | EXTRA_DIST = $(suppressions_files) 23 | 24 | noinst_DATA = suppressions 25 | 26 | suppressions: $(suppressions_files) 27 | rm -f $@ $@-t 28 | cat $(suppressions_files) > $@-t 29 | mv $@-t $@ 30 | chmod 0444 $@ 31 | 32 | DISTCLEANFILES = suppressions 33 | -------------------------------------------------------------------------------- /valgrind/glibc.suppressions: -------------------------------------------------------------------------------- 1 | # nbd client library in userspace 2 | # Copyright Red Hat 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 2 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | # bindtextdomain leaks. 19 | { 20 | glibc_1 21 | Memcheck:Leak 22 | ... 23 | fun:bindtextdomain 24 | } 25 | 26 | # pthread_exit. 27 | { 28 | glibc_2a 29 | Memcheck:Leak 30 | ... 31 | fun:pthread_exit 32 | } 33 | { 34 | glibc_2b 35 | Memcheck:Leak 36 | ... 37 | fun:dlopen@@* 38 | } 39 | 40 | # Allow thread-local storage from pthread_create to leak. 41 | { 42 | glibc_3 43 | Memcheck:Leak 44 | fun:calloc 45 | ... 46 | fun:_dl_allocate_tls 47 | } 48 | 49 | # Same as above, but for glibc 2.34. 50 | { 51 | glibc_4 52 | Memcheck:Leak 53 | fun:malloc 54 | ... 55 | fun:allocate_dtv_entry 56 | } 57 | 58 | # This is another leak from pthread_create added in glibc 2.34. 59 | { 60 | glibc_5 61 | Memcheck:Leak 62 | fun:malloc 63 | ... 64 | fun:__printf_chk 65 | } 66 | -------------------------------------------------------------------------------- /valgrind/gnutls.suppressions: -------------------------------------------------------------------------------- 1 | # nbd client library in userspace 2 | # Copyright Red Hat 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 2 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | # gnutls_x509_trust_list_add_system_trust leaks everything. 19 | { 20 | gnutls_1 21 | Memcheck:Leak 22 | ... 23 | fun:gnutls_x509_trust_list_add_system_trust 24 | } 25 | -------------------------------------------------------------------------------- /valgrind/libnbd.suppressions: -------------------------------------------------------------------------------- 1 | # nbd client library in userspace 2 | # Copyright Red Hat 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 2 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | # It's not properly guaranteed that the per-thread error context is or 19 | # can always be freed in multi-threaded programs that call exit before 20 | # all threads have shut down (even if all handles are closed). So 21 | # suppress this error. 22 | { 23 | libnbd_1 24 | Memcheck:Leak 25 | fun:calloc 26 | ... 27 | fun:nbd_internal_set_error_context 28 | fun:nbd_create 29 | } 30 | --------------------------------------------------------------------------------