2 # nbd client library in userspace
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 # Test interop with qemu-nbd block sizes.
21 source ..
/tests
/functions.sh
25 # versions of qemu-nbd older than 4.0 reported inaccurate block sizes
26 # Use 'qemu-nbd --list' as our witness, it was also added in 4.0
27 requires qemu-nbd
--list --version
28 requires nbdsh
--version
29 requires qemu-img
--version
30 requires truncate
--version
31 requires timeout
--version
33 f
="qemu-block-size.raw"
34 sock
=$
(mktemp
-u /tmp
/interop-qemu.XXXXXX
)
36 cleanup_fn
rm -f $f $sock
38 truncate
--size=10M
$f
42 # run_test FMT REQUEST EXP_INFO EXP_GO
45 # No -t or -e, so qemu-nbd should exit once nbdsh disconnects
46 timeout
60s qemu-nbd
-k $sock $1 $f &
48 # Wait for the socket to appear
50 if test -e $sock; then
58 sock = os.environ["sock"]
61 assert h.get_request_block_size()
62 h.set_request_block_size($2)
63 assert h.get_request_block_size() is $2
66 if not h.aio_is_negotiating():
68 exit(77) # Oldstyle negotiation lacks block size advertisement
72 assert h.get_block_size(nbd.SIZE_MINIMUM) == $3
77 assert h.get_block_size(nbd.SIZE_MINIMUM) == $4
83 echo "$0: skipping: qemu-nbd too old for this test"
85 elif [ $st != 0 ]; then
91 # Without '-f raw', qemu-nbd forces sector granularity to prevent writing
92 # to sector 0 from changing the disk type. However, if the client does
93 # not request block sizes, it reports a size then errors out for NBD_OPT_INFO,
94 # while fudging size for NBD_OPT_GO.
95 run_test
'' True
512 512
98 # With '-f raw', qemu-nbd always exposes byte-level granularity for files.
99 run_test
'-f raw' True
1 1
100 run_test
'-f raw' False
1 1