5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # * Neither the name of Red Hat nor the names of its contributors may be
17 # used to endorse or promote products derived from this software without
18 # specific prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
21 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
24 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 sockdir
=$
(mktemp
-d /tmp
/nbdkit-test-socks.XXXXXX
)
50 # Prep images, and check that qemu-io understands the actions we plan on
51 # doing. We can't test trim+FUA, since qemu-io won't expose that.
52 $TRUNCATE -s 1M fua.img
53 if ! qemu-io
-f raw
-t none
-c flush
-c 'w -f -z 0 64k' fua.img
; then
54 echo "$0: missing or broken qemu-io"
59 # For easier debugging, dump the final log files before removing them
64 echo "Log $i file contents:"
72 # Run parallel nbdkit; to compare the logs and see what changes.
73 # 1: fuamode=none (default): client should send flush instead
74 # 2: fuamode=emulate: log shows that blocksize optimizes fua to flush
75 # 3: fuamode=native: log shows that blocksize preserves fua
76 # 4: fuamode=force: log shows that fua is always enabled
77 # 5: fuamode=pass: fua flag and flush unchanged
78 # 6: fuamode=discard: discard all fua and flush
79 start_nbdkit
-P fua1.pid
-U $sockdir/fua1.sock \
80 --filter=log
--filter=fua \
81 file logfile
=fua1.log fua.img
82 start_nbdkit
-P fua2.pid
-U $sockdir/fua2.sock \
83 --filter=blocksize
--filter=log
--filter=fua \
84 file logfile
=fua2.log fua.img fuamode
=emulate maxdata
=4k maxlen
=4k
85 start_nbdkit
-P fua3.pid
-U $sockdir/fua3.sock \
86 --filter=blocksize
--filter=log
--filter=fua \
87 file logfile
=fua3.log fua.img fuamode
=native maxdata
=4k maxlen
=4k
88 start_nbdkit
-P fua4.pid
-U $sockdir/fua4.sock \
89 --filter=fua
--filter=log \
90 file logfile
=fua4.log fua.img fuamode
=force
91 start_nbdkit
-P fua5.pid
-U $sockdir/fua5.sock \
92 --filter=fua
--filter=log \
93 file logfile
=fua5.log fua.img fuamode
=pass
94 start_nbdkit
-P fua6.pid
-U $sockdir/fua6.sock \
95 --filter=fua
--filter=log \
96 file logfile
=fua6.log fua.img fuamode
=discard
98 # Perform a flush, write, and zero, first without then with FUA
101 qemu-io
-f raw
-t none
-c flush
-c "w $f 0 64k" -c "w -z $f 64k 64k" \
102 "nbd+unix://?socket=$sockdir/fua$i.sock"
106 # Test 1: no fua sent over wire, qemu-io sent more flushes in place of fua
107 if grep 'fua=1' fua1.log
; then
108 echo "filter should have prevented fua"
111 test $
(grep -c 'connection=1 Flush' fua1.log
) -lt \
112 $
(grep -c 'connection=2 Flush' fua1.log
)
114 # Test 2: either last part of split has fua, or a flush is added, but
115 # all earlier parts of the transaction do not have fua
116 flush1
=$
(grep -c 'connection=1 Flush' fua2.log ||
:)
117 flush2
=$
(grep -c 'connection=2 Flush' fua2.log ||
:)
118 fua
=$
(grep -c 'connection=2.*fua=1 .*\.' fua2.log ||
:)
119 test $
(( $flush2 - $flush1 + $fua )) = 2
121 # Test 3: every part of split has fua, and no flushes are added
122 flush1
=$
(grep -c 'connection=1 Flush' fua3.log ||
:)
123 flush2
=$
(grep -c 'connection=2 Flush' fua3.log ||
:)
124 test $flush1 = $flush2
125 test $
(grep -c 'connection=2.*fua=1 .*\.' fua3.log
) = 32
127 # Test 4: flush is no-op, and every transaction has fua
128 if grep 'fua=0' fua4.log
; then
129 echo "filter should have forced fua"
132 if grep 'Flush' fua4.log
; then
133 echo "filter should have elided flush"
137 # Test 5: Flush should be passed through.
138 # There should also be one set of fua=0 and a second set of fua=1.
139 grep 'Flush' fua5.log
140 grep 'connection=1 Write.*fua=0' fua5.log
141 grep 'connection=2 Write.*fua=1' fua5.log
142 grep 'connection=1 Zero.*fua=0' fua5.log
143 grep 'connection=2 Zero.*fua=1' fua5.log
145 # Test 6: Flush and fua=1 must not appear.
146 if grep 'Flush' fua6.log
; then
147 echo "filter should have elided flush"
150 if grep -E '(Write|Zero).*fua=1' fua6.log
; then
151 echo "filter should have elided fua"