GCC 7.1 fixes
[zfs.git] / scripts / smb.sh
blob7cf6c4bc12fb11e870633b2ea88a3961df636952
1 #!/bin/bash
3 BASETANK="share"
4 DATE=`date "+%Y%m%d"`
6 TEST_SMBFS=0
7 TEST_DESTROY=0
9 if [ -z "$1" ]; then
10 echo "Usage: `basename $0` [unpack]<[smbfs][snapshot][all]>"
11 exit 1
14 set_onoff() {
15 type="$1"
16 dataset="$2"
17 toggle="$3"
19 current=`zfs get -H $type -o value $dataset`
20 if [ "$current" != "$toggle" ]; then
21 run "zfs set $type=$toggle $dataset"
25 check_exists() {
26 dataset="$1"
28 extra=""
29 [ -n "$2" ] && extra="$2"
31 zfs get all "$dataset" > /dev/null 2>&1
32 if [ $? != 0 ]; then
33 run "zfs create $extra $dataset"
37 check_shares() {
38 if [ "$TEST_SMBFS" == "1" ]; then
39 echo "Shares:"
40 echo "=> usershare list:"
41 net usershare list
42 echo
43 echo "=> /etc/dfs/sharetab:"
44 cat /etc/dfs/sharetab
45 echo
48 sleep 2
51 test_header() {
52 echo "TEST: $*"
53 echo "======================================"
56 run() {
57 cmd="$*"
59 echo "CMD: $cmd"
60 $cmd
63 # ---------
64 # Needs more work...
65 if echo "$*" | grep -qi "unpack"; then
66 zfs unmount -a
67 zfs unshare -a
68 run "zfs destroy -r $BASETANK/tests"
70 sh /etc/init.d/zfs stop
72 # for tid in `grep ^tid /proc/net/iet/volume | sed "s@.*:\([0-9].*\) name.*@\1@"`
73 # do
74 # ietadm --op delete --tid $tid
75 # done
77 set -e
78 rmmod `lsmod | grep ^z | grep -v zlib_deflate | sed 's@ .*@@'` spl zlib_deflate
80 pushd / > /dev/null
81 [ -f "tmp/zfs.tgz" ] && tar xzf tmp/zfs.tgz && rm tmp/zfs.tgz
82 [ -f "tmp/spl.tgz" ] && tar xzf tmp/spl.tgz && rm tmp/spl.tgz
83 popd > /dev/null
85 depmod -a
87 sh /etc/init.d/zfs start
88 set +e
91 # ---------
92 if echo "$*" | egrep -qi "smbfs|all"; then
93 check_exists $BASETANK/tests
95 TEST_SMBFS=1
97 test_header "Exists || Create"
98 str=
99 for volnr in 1 2 3; do
100 check_exists $BASETANK/tests/smbfs$volnr
102 str="$str $BASETANK/tests/smbfs$volnr"
103 done
104 run "zfs get sharesmb $str"
106 # Set sharesmb=on
107 test_header "Enable SMB share"
108 for volnr in 1 2 3; do
109 set_onoff sharesmb "$BASETANK/tests/smbfs$volnr" on
110 check_shares
111 done
113 # Share all
114 test_header "Share all (individually)"
115 for volnr in 1 2 3; do
116 run "zfs share $BASETANK/tests/smbfs$volnr"
117 check_shares
118 done
120 # Unshare all
121 test_header "Unshare all (individually)"
122 for volnr in 1 2 3; do
123 run "zfs unshare $BASETANK/tests/smbfs$volnr"
124 check_shares
125 done
127 # Change mountpoint - first unshare and then share individual
128 test_header "Change mount point (unshare ; share)"
129 mkdir -p /tests
130 set_onoff sharesmb "$str" off
131 for volnr in 3 1 2; do
132 run "zfs set mountpoint=/tests/smbfs$volnr $BASETANK/tests/smbfs$volnr"
133 echo "CMD: mount | grep ^$BASETANK/tests/smbfs$volnr"
134 mount | grep ^$BASETANK/tests/smbfs$volnr
135 echo
137 run "zfs mount $BASETANK/tests/smbfs$volnr"
138 echo "CMD: mount | grep ^$BASETANK/tests/smbfs$volnr"
139 mount | grep ^$BASETANK/tests/smbfs$volnr
140 echo
142 set_onoff sharesmb "$BASETANK/tests/smbfs$volnr" on
143 check_shares
145 run "zfs share $BASETANK/tests/smbfs$volnr"
146 check_shares
148 echo "-------------------"
149 done
151 # Change mountpoint - remounting
152 test_header "Change mount point (remounting)"
153 for volnr in 3 1 2; do
154 run "zfs set mountpoint=/$BASETANK/tests/smbfs$volnr $BASETANK/tests/smbfs$volnr"
155 echo "CMD: mount | grep ^$BASETANK/tests/smbfs$volnr"
156 mount | grep ^$BASETANK/tests/smbfs$volnr
157 echo
158 # => Doesn't seem to remount (!?)
160 run "zfs mount $BASETANK/tests/smbfs$volnr"
161 echo "CMD: mount | grep ^$BASETANK/tests/smbfs$volnr"
162 mount | grep ^$BASETANK/tests/smbfs$volnr
163 echo
164 # => Doesn't seem to reshare (!?)
166 check_shares
168 run "zfs share $BASETANK/tests/smbfs$volnr"
169 check_shares
171 echo "-------------------"
172 done
175 # ---------
176 if echo "$*" | egrep -qi "smbfs|all"; then
177 test_header "Unshare + Share all"
179 run "zfs share -a" ; check_shares
180 run "zfs unshare -a" ; check_shares
183 # ---------
184 if echo "$*" | grep -qi "snapshot|all"; then
185 test_header "Snapshots"
187 echo ; echo "-------------------"
188 check_exists $BASETANK/tests/destroy
189 check_exists $BASETANK/tests/destroy/destroy1
190 run "zfs destroy -r $BASETANK/tests/destroy"
192 echo ; echo "-------------------"
193 check_exists $BASETANK/tests/destroy
194 run "zfs snapshot $BASETANK/tests/destroy@$DATE"
195 run "zfs destroy -r $BASETANK/tests/destroy"
197 echo ; echo "-------------------"
198 check_exists $BASETANK/tests/destroy
199 run "zfs snapshot $BASETANK/tests/destroy@$DATE"
200 run "zfs destroy -r $BASETANK/tests/destroy@$DATE"
201 run "zfs destroy -r $BASETANK/tests/destroy"
204 if echo "$*" | egrep -qi "smbfs|snapshot|all"; then
205 test_header "Cleanup (Share all + Destroy all)"
207 run "zfs share -a"
208 check_shares
210 run "zfs destroy -r $BASETANK/tests"
211 check_shares
213 run "zfs list"