File: info-can.sh

package info (click to toggle)
libnbd 1.24.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,956 kB
  • sloc: ansic: 55,063; ml: 12,326; sh: 8,817; python: 4,757; makefile: 3,036; perl: 165; cpp: 24
file content (154 lines) | stat: -rwxr-xr-x 4,070 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env bash
# nbd client library in userspace
# Copyright Red Hat
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

. ../tests/functions.sh

set -e
set -x

requires $NBDKIT --version
requires bash -c "$NBDKIT sh --dump-plugin | grep has_can_cache=1"

# --is read-only and --can write are tested in info-is-read-only.sh

# --is tls is tested in info-uri-nbds.sh and info-is-tls.sh

# --can connect is tested in info-can-connect.sh

# --can read is tested in info-can-read.sh

# --can zero is tested in info-can-zero.sh

# --cannot is tested in info-cannot.sh

# --can df is hard to test.  nbdkit newstyle probably always sets this
# and oldstyle never, but that feels like depending a bit too much on
# the implementation.

# --can block-status-payload is not supported by nbdkit yet. Testing
# is done during interop/block-status-payload.sh with new-enough qemu.

# --has structured-reply is not a per-export setting, but rather
# something set on the server as a whole.

$NBDKIT -v -U - sh - \
        --run '$VG nbdinfo --has structured-reply "nbd+unix:///?socket=$unixsocket"' <<'EOF'
case "$1" in
  get_size) echo 1024 ;;
  pread) ;;
  *) exit 2 ;;
esac
EOF

st=0
$NBDKIT -v -U - --no-sr sh - \
        --run '$VG nbdinfo --has structured-reply "nbd+unix:///?socket=$unixsocket"' <<'EOF' || st=$?
case "$1" in
  get_size) echo 1024 ;;
  pread) ;;
  *) exit 2 ;;
esac
EOF
test $st = 2

# --has extended-headers cannot be positively tested until nbdkit gains
# --no-eh support.  Otherwise, it is similar to --has structured-reply.

no_eh=
if $NBDKIT --no-eh --help >/dev/null 2>/dev/null; then
    no_eh=--no-eh
    $NBDKIT -v -U - sh - \
            --run '$VG nbdinfo --has extended-headers "nbd+unix:///?socket=$unixsocket"' <<'EOF'
case "$1" in
  get_size) echo 1024 ;;
  pread) ;;
  *) exit 2 ;;
esac
EOF
fi

st=0
$NBDKIT -v -U - $no_eh sh - \
        --run '$VG nbdinfo --has extended-headers "nbd+unix:///?socket=$unixsocket"' <<'EOF' || st=$?
case "$1" in
  get_size) echo 1024 ;;
  pread) ;;
  *) exit 2 ;;
esac
EOF
test $st = 2

# --can cache and --can fua require special handling because in
# nbdkit-sh-plugin we must print "native" or "none".  Also the can_fua
# flag is only sent if the export is writable (hence can_write below).

for flag in cache fua; do
    export flag
    $NBDKIT -v -U - sh - \
            --run '$VG nbdinfo --can $flag "nbd+unix:///?socket=$unixsocket"' <<'EOF'
case "$1" in
  get_size) echo 1024 ;;
  pread) ;;
  can_write) ;;
  can_$flag) echo native ;;
  *) exit 2 ;;
esac
EOF

    st=0
    $NBDKIT -v -U - sh - \
            --run '$VG nbdinfo --can $flag "nbd+unix:///?socket=$unixsocket"' <<'EOF' || st=$?
case "$1" in
  get_size) echo 1024 ;;
  pread) ;;
  can_write) ;;
  can_$flag) echo none ;;
  *) exit 2 ;;
esac
EOF
    test $st = 2
done

# These ones are normal booleans.

for flag in fast_zero flush multi_conn trim ; do
    export flag
    $NBDKIT -v -U - sh - \
            --run '$VG nbdinfo --can $flag "nbd+unix:///?socket=$unixsocket"' <<'EOF'
case "$1" in
  get_size) echo 1024 ;;
  pread) ;;
  can_write) ;;
  can_$flag) exit 0 ;;
  *) exit 2 ;;
esac
EOF

    st=0
    $NBDKIT -v -U - sh - \
            --run '$VG nbdinfo --can $flag "nbd+unix:///?socket=$unixsocket"' <<'EOF' || st=$?
case "$1" in
  get_size) echo 1024 ;;
  pread) ;;
  can_write) ;;
  can_$flag) exit 3 ;;
  *) exit 2 ;;
esac
EOF
    test $st = 2
done