tests: Skip test if file extents are not support
[nbdkit.git] / tests / test-multi-conn-plugin.sh
blob5d627a0736169d21a0394bd472c4850dab071560
1 #!/usr/bin/env bash
2 # nbdkit
3 # Copyright (C) 2018-2021 Red Hat Inc.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met:
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
31 # SUCH DAMAGE.
33 # Test plugin used by test-multi-conn.sh.
34 # This plugin purposefully maintains a per-connection cache.
35 # An optional parameter tightfua=true controls whether FUA acts on
36 # just the given region, or on all pending ops in the current connection.
37 # Note that an earlier cached write on one connection can overwrite a later
38 # FUA write on another connection - this is okay (the client is buggy if
39 # it ever sends overlapping writes without coordinating flushes and still
40 # expects any particular write to occur last).
42 get_export() {
43 case $1 in
44 */*) export="$tmpdir/$(dirname $1)" conn=$(basename $1) ;;
45 *) export="$tmpdir" conn=$1 ;;
46 esac
48 fill_cache() {
49 if test ! -f "$export/$conn"; then
50 cp "$export/0" "$export/$conn"
53 do_fua() {
54 case ,$3, in
55 *,fua,*)
56 if test -f "$tmpdir/strictfua"; then
57 dd of="$export/0" if="$export/$conn" skip=$2 seek=$2 count=$1 \
58 conv=notrunc iflag=count_bytes,skip_bytes oflag=seek_bytes
59 else
60 do_flush
61 fi ;;
62 esac
64 do_flush() {
65 if test -f "$export/$conn-replay"; then
66 while read cnt off; do
67 dd of="$export/0" if="$export/$conn" skip=$off seek=$off count=$cnt \
68 conv=notrunc iflag=count_bytes,skip_bytes oflag=seek_bytes
69 done < "$export/$conn-replay"
71 rm -f "$export/$conn" "$export/$conn-replay"
73 case "$1" in
74 config)
75 case $2 in
76 strictfua)
77 case $3 in
78 true | on | 1) touch "$tmpdir/strictfua" ;;
79 false | off | 0) ;;
80 *) echo "unknown value for strictfua $3" >&2; exit 1 ;;
81 esac ;;
82 *) echo "unknown config key $2" >&2; exit 1 ;;
83 esac
85 get_ready)
86 printf "%-32s" 'Initial contents' > "$tmpdir/0"
87 echo 0 > "$tmpdir/counter"
89 get_size)
90 echo 32
92 can_write | can_zero | can_trim | can_flush)
93 exit 0
95 can_fua | can_cache)
96 echo native
98 open)
99 read i < "$tmpdir/counter"
100 i=$((i+1))
101 echo $i > "$tmpdir/counter"
102 if test -z "$3"; then
103 echo $i
104 else
105 mkdir -p "$tmpdir/$3" || exit 1
106 cp "$tmpdir/0" "$tmpdir/$3/0"
107 echo "$3/$i"
110 pread)
111 get_export $2
112 fill_cache
113 dd if="$export/$conn" skip=$4 count=$3 iflag=count_bytes,skip_bytes
115 cache)
116 get_export $2
117 fill_cache
119 pwrite)
120 get_export $2
121 fill_cache
122 dd of="$export/$conn" seek=$4 conv=notrunc oflag=seek_bytes
123 echo $3 $4 >> "$export/$conn-replay"
124 do_fua $3 $4 $5
126 zero | trim)
127 get_export $2
128 fill_cache
129 dd of="$export/$conn" if="/dev/zero" count=$3 seek=$4 conv=notrunc\
130 oflag=seek_bytes iflag=count_bytes
131 echo $3 $4 >> "$export/$conn-replay"
132 do_fua $3 $4 $5
134 flush)
135 get_export $2
136 do_flush
139 exit 2
141 esac