Revert "ci: skip "lib/test-fork-safe-execvpe.sh" on Alpine Linux"
[libnbd.git] / copy / copy-block-to-nbd.sh
blob34197893d329848db4a95a554980e09e798ebe8a
1 #!/usr/bin/env bash
2 # nbd client library in userspace
3 # Copyright Red Hat
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.
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.
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
19 . ../tests/functions.sh
21 set -e
22 set -x
24 requires_root
25 requires_caps cap_sys_admin
26 requires nbdkit --exit-with-parent --version
27 requires test -r /sys/module/nbd
28 requires nbd-client --version
29 # /dev/nbd0 must not be in use.
30 requires_not nbd-client -c /dev/nbd0
32 pidfile=copy-block-to-nbd.pid
33 sock=$(mktemp -u /tmp/libnbd-test-copy.XXXXXX)
34 cleanup_fn rm -f $pidfile $sock
35 cleanup_fn nbd-client -d /dev/nbd0
37 # Run an nbdkit server to act as the backing for /dev/nbd0.
38 nbdkit --exit-with-parent -f -v -P $pidfile -U $sock pattern size=5M &
39 # Wait for the pidfile to appear.
40 for i in {1..60}; do
41 if test -f $pidfile; then
42 break
44 sleep 1
45 done
46 if ! test -f $pidfile; then
47 echo "$0: nbdkit did not start up"
48 exit 1
51 nbd-client -unix $sock /dev/nbd0 -b 512
53 $VG nbdcopy -- /dev/nbd0 [ nbdkit --exit-with-parent -v memory 5M ]