Whamcloud - gitweb
205c0ebc8ce8c173e223b818a4574e0024570f86
[fs/lustre-release.git] / lustre / tests / sanity-pcc.sh
1 #!/bin/bash
2 #
3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
5 #
6 # exit on error
7 set -e
8 set +o monitor
9
10 SRCDIR=$(dirname $0)
11 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/utils:$PATH:/sbin:/usr/sbin
12
13 ONLY=${ONLY:-"$*"}
14 # bug number for skipped test:
15 ALWAYS_EXCEPT=""
16 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
17
18 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
19
20 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
21
22 . $LUSTRE/tests/test-framework.sh
23 init_test_env $@
24 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
25 init_logging
26
27 MULTIOP=${MULTIOP:-multiop}
28 OPENFILE=${OPENFILE:-openfile}
29 MOUNT_2=${MOUNT_2:-"yes"}
30 FAIL_ON_ERROR=false
31
32 # script only handles up to 10 MDTs (because of MDT_PREFIX)
33 [ $MDSCOUNT -gt 9 ] &&
34         error "script cannot handle more than 9 MDTs, please fix" && exit
35
36 check_and_setup_lustre
37
38 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.12.52) ]]; then
39         skip_env "Need MDS version at least 2.12.52" && exit
40 fi
41
42 # $RUNAS_ID may get set incorrectly somewhere else
43 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
44         skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
45 fi
46 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
47 if getent group nobody; then
48         GROUP=nobody
49 elif getent group nogroup; then
50         GROUP=nogroup
51 else
52         error "No generic nobody group"
53 fi
54
55 build_test_filter
56
57 # if there is no CLIENT1 defined, some tests can be ran on localhost
58 CLIENT1=${CLIENT1:-$HOSTNAME}
59 # if CLIENT2 doesn't exist then use CLIENT1 instead
60 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
61 # $CLIENT2 == CLIENT1
62 # Exception is the test which need two separate nodes
63 CLIENT2=${CLIENT2:-$CLIENT1}
64
65 check_file_size()
66 {
67         local client="$1"
68         local fpath="$2"
69         local expected_size="$3"
70
71         size=$(do_facet $client stat "--printf=%s" $fpath)
72         [[ $size == "$expected_size" ]] || error \
73                 "expected $fpath size: $expected_size got: $size"
74 }
75
76 check_lpcc_sizes()
77 {
78         local client="$1"
79         local lpcc_fpath="$2"
80         local lustre_fpath="$3"
81         local expected_size="$4"
82
83         check_file_size $client $lpcc_fpath $expected_size
84         check_file_size $client $lustre_fpath $expected_size
85 }
86
87 check_file_data()
88 {
89         local client="$1"
90         local path="$2"
91         local expected_data="$3"
92
93         path_data=$(do_facet $client cat $path)
94         [[ "x$path_data" == "x$expected_data" ]] || error \
95                 "expected $path: $expected_data, got: $path_data"
96 }
97
98 check_lpcc_data()
99 {
100         local client="$1"
101         local lpcc_fpath="$2"
102         local lustre_fpath="$3"
103         local expected_data="$4"
104
105         check_file_data  "$client" "$lpcc_fpath" "$expected_data"
106         check_file_data  "$client" "$lustre_fpath" "$expected_data"
107 }
108
109 lpcc_fid2path()
110 {
111         local hsm_root="$1"
112         local lustre_path="$2"
113         local fid=$(path2fid $lustre_path)
114
115         local -a f_seq
116         local -a f_oid
117         local -a f_ver
118
119         f_seq=$(echo $fid | awk -F ':' '{print $1}')
120         f_oid=$(echo $fid | awk -F ':' '{print $2}')
121         f_ver=$(echo $fid | awk -F ':' '{print $3}')
122
123         printf "%s/%04x/%04x/%04x/%04x/%04x/%04x/%s" \
124                 $hsm_root $(($f_oid & 0xFFFF)) \
125                 $(($f_oid >> 16 & 0xFFFF)) \
126                 $(($f_seq & 0xFFFF)) \
127                 $(($f_seq >> 16 & 0xFFFF)) \
128                 $(($f_seq >> 32 & 0xFFFF)) \
129                 $(($f_seq >> 48 & 0xFFFF)) $fid
130 }
131
132 check_lpcc_state()
133 {
134         local lustre_path="$1"
135         local expected_state="$2"
136         local state=$(do_facet $SINGLEAGT $LFS pcc state $lustre_path |
137                         awk -F 'type: ' '{print $2}' | awk -F ',' '{print $1}')
138
139         [[ "x$state" == "x$expected_state" ]] || error \
140                 "$lustre_path expected pcc state: $expected_state, but got: $state"
141 }
142
143 # initiate variables
144 init_agt_vars
145
146 # populate MDT device array
147 get_mdt_devices
148
149 # cleanup from previous bad setup
150 kill_copytools
151
152 # for recovery tests, coordinator needs to be started at mount
153 # so force it
154 # the lustre conf must be without hsm on (like for sanity.sh)
155 echo "Set HSM on and start"
156 cdt_set_mount_state enabled
157 cdt_check_state enabled
158
159 echo "Set sanity-hsm HSM policy"
160 cdt_set_sanity_policy
161
162 # finished requests are quickly removed from list
163 set_hsm_param grace_delay 10
164
165 cleanup_pcc_mapping() {
166         do_facet $SINGLEAGT $LCTL pcc clear $MOUNT
167 }
168
169 setup_pcc_mapping() {
170         local hsm_root=$(hsm_root)
171
172         cleanup_pcc_mapping
173         do_facet $SINGLEAGT $LCTL pcc add $MOUNT $hsm_root \
174                 -p "$HSM_ARCHIVE_NUMBER\ 100"
175 }
176
177 lpcc_rw_test() {
178         local restore="$1"
179         local project="$2"
180         local project_id=100
181         local agt_facet=$SINGLEAGT
182         local hsm_root=$(hsm_root)
183         local file=$DIR/$tdir/$tfile
184         local -a state
185         local -a lpcc_path
186         local -a size
187
188         $project && enable_project_quota
189
190         do_facet $SINGLEAGT rm -rf $hsm_root
191         copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
192
193         is_project_quota_supported || project=false
194
195         do_facet $SINGLEAGT mkdir -p $DIR/$tdir
196         setup_pcc_mapping
197         $project && lfs project -sp $project_id $DIR/$tdir
198
199         do_facet $SINGLEAGT "echo -n attach_origin > $file"
200         if ! $project; then
201                 check_lpcc_state $file "none"
202                 do_facet $SINGLEAGT $LFS pcc attach -i \
203                         $HSM_ARCHIVE_NUMBER $file ||
204                         error "pcc attach $file failed"
205         fi
206
207         check_lpcc_state $file "readwrite"
208         # HSM released exists archived status
209         check_hsm_flags $file "0x0000000d"
210         lpcc_path=$(lpcc_fid2path $hsm_root $file)
211         check_lpcc_data $SINGLEAGT $lpcc_path $file "attach_origin"
212
213         do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=7654321 count=1
214         check_lpcc_sizes $SINGLEAGT $lpcc_path $file 7654321
215
216         do_facet $SINGLEAGT $TRUNCATE $file 1234567 ||
217                 error "truncate failed"
218         check_lpcc_sizes $SINGLEAGT $lpcc_path $file 1234567
219         check_lpcc_state $file "readwrite"
220
221         do_facet $SINGLEAGT "echo -n file_data > $file"
222         check_lpcc_state $file "readwrite"
223         # HSM released exists archived status
224         check_hsm_flags $file "0x0000000d"
225         check_lpcc_data $SINGLEAGT $lpcc_path $file "file_data"
226
227         if [ $CLIENTCOUNT -lt 2 -o $restore ]; then
228                 $LFS hsm_restore $file || error \
229                         "failed to restore $file"
230                 wait_request_state $(path2fid $file) RESTORE SUCCEED
231         else
232                 path_data=$(do_node $CLIENT2 cat $file)
233                 [[ "x$path_data" == "xfile_data" ]] || error \
234                         "expected file_data, got: $path_data"
235         fi
236
237         check_lpcc_state $file "none"
238         # HSM exists archived status
239         check_hsm_flags $file "0x00000009"
240
241         echo -n "new_data" > $file
242         check_lpcc_state $file "none"
243         # HSM exists dirty archived status
244         check_hsm_flags $file "0x0000000b"
245         check_file_data $SINGLEAGT $file "new_data"
246
247         echo "Attach and detach testing"
248         rm -f $file
249         do_facet $SINGLEAGT "echo -n new_data2 > $file"
250         if ! $project; then
251                 check_lpcc_state $file "none"
252                 do_facet $SINGLEAGT $LFS pcc attach -i \
253                         $HSM_ARCHIVE_NUMBER $file ||
254                         error "PCC attach $file failed"
255         fi
256         check_lpcc_state $file "readwrite"
257         # HSM released exists archived status
258         check_hsm_flags $file "0x0000000d"
259         do_facet $SINGLEAGT "echo -n attach_detach > $file"
260         do_facet $SINGLEAGT $LFS pcc detach $file ||
261                 error "PCC detach $file failed"
262         check_lpcc_state $file "none"
263         # HSM released exists archived status
264         check_hsm_flags $file "0x0000000d"
265         check_file_data $SINGLEAGT $file "attach_detach"
266
267         cleanup_pcc_mapping
268 }
269
270 test_1a() {
271         lpcc_rw_test true false
272 }
273 run_test 1a "Test manual lfs pcc attach with manual HSM restore"
274
275 test_1b() {
276         lpcc_rw_test false false
277 }
278 run_test 1b "Test manual lfs pcc attach with restore on remote access"
279
280 test_1c() {
281         lpcc_rw_test true true
282 }
283 run_test 1c "Test automated attach using Project ID with manual HSM restore"
284
285 test_1d() {
286         lpcc_rw_test false true
287 }
288 run_test 1d "Test Project ID with remote access"
289
290
291 #
292 # When a process created a LPCC file and holding the open,
293 # another process on the same client should be able to open the file.
294 #
295 test_2() {
296         local project_id=100
297         local agt_facet=$SINGLEAGT
298         local hsm_root=$(hsm_root)
299         local agt_host=$(facet_active_host $SINGLEAGT)
300
301         ! is_project_quota_supported &&
302                 skip "project quota is not supported" && return
303
304         enable_project_quota
305         copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
306         setup_pcc_mapping
307         file=$DIR/$tdir/multiop
308         mkdir -p $DIR/$tdir
309         rm -f $file
310
311         do_facet $SINGLEAGT $LFS project -sp $project_id $DIR/$tdir ||
312                 error "failed to set project quota"
313         rmultiop_start $agt_host $file O_c || error "open $file failed"
314         # HSM released exists archived status
315         check_hsm_flags $file "0x0000000d"
316         do_facet $SINGLEAGT "echo -n multiopen_data > $file" ||
317                 error "failed to echo multiopen_data to $file"
318
319         lpcc_path=$(lpcc_fid2path $hsm_root $file)
320         do_facet $SINGLEAGT ls -l $lpcc_path ||
321                 error "failed to ls $lpcc_path"
322         check_lpcc_data $SINGLEAGT $lpcc_path $file "multiopen_data"
323         # HSM released exists archived status
324         check_hsm_flags $file "0x0000000d"
325
326         rmultiop_stop $agt_host || error "close $file failed"
327         cleanup_pcc_mapping
328 }
329 run_test 2 "Test multi open when creating"
330
331 test_3() {
332         local file=$DIR/$tdir/$tfile
333
334         copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
335         setup_pcc_mapping
336
337         mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir failed"
338         dd if=/dev/zero of=$file bs=1024 count=1 ||
339                 error "failed to dd write to $file"
340
341         echo "Start to attach/detach the file: $file"
342         do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
343                 error "failed to attach file $file"
344         check_lpcc_state $file "readwrite"
345         do_facet $SINGLEAGT $LFS pcc detach $file ||
346                 error "failed to detach file $file"
347         check_lpcc_state $file "none"
348
349         echo "Repeat to attach/detach the same file: $file"
350         do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
351                 error "failed to attach file $file"
352         check_lpcc_state $file "readwrite"
353         do_facet $SINGLEAGT $LFS pcc detach $file ||
354                 error "failed to detach file $file"
355         check_lpcc_state $file "none"
356
357         cleanup_pcc_mapping
358 }
359 run_test 3 "Repeat attach/detach operations"
360
361 complete $SECONDS
362 check_and_cleanup_lustre
363 exit_status