3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
11 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/utils:$PATH:/sbin:/usr/sbin
14 # bug number for skipped test:
16 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
18 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
20 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
22 . $LUSTRE/tests/test-framework.sh
24 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
27 MULTIOP=${MULTIOP:-multiop}
28 OPENFILE=${OPENFILE:-openfile}
29 MOUNT_2=${MOUNT_2:-"yes"}
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
36 check_and_setup_lustre
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
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
46 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
47 if getent group nobody; then
49 elif getent group nogroup; then
52 error "No generic nobody group"
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
62 # Exception is the test which need two separate nodes
63 CLIENT2=${CLIENT2:-$CLIENT1}
69 local expected_size="$3"
71 size=$(do_facet $client stat "--printf=%s" $fpath)
72 [[ $size == "$expected_size" ]] || error \
73 "expected $fpath size: $expected_size got: $size"
80 local lustre_fpath="$3"
81 local expected_size="$4"
83 check_file_size $client $lpcc_fpath $expected_size
84 check_file_size $client $lustre_fpath $expected_size
91 local expected_data="$3"
93 path_data=$(do_facet $client cat $path)
94 [[ "x$path_data" == "x$expected_data" ]] || error \
95 "expected $path: $expected_data, got: $path_data"
101 local lpcc_fpath="$2"
102 local lustre_fpath="$3"
103 local expected_data="$4"
105 check_file_data "$client" "$lpcc_fpath" "$expected_data"
106 check_file_data "$client" "$lustre_fpath" "$expected_data"
112 local lustre_path="$2"
113 local fid=$(path2fid $lustre_path)
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}')
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
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}')
139 [[ "x$state" == "x$expected_state" ]] || error \
140 "$lustre_path expected pcc state: $expected_state, but got: $state"
146 # populate MDT device array
149 # cleanup from previous bad setup
152 # for recovery tests, coordinator needs to be started at mount
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
159 echo "Set sanity-hsm HSM policy"
160 cdt_set_sanity_policy
162 # finished requests are quickly removed from list
163 set_hsm_param grace_delay 10
165 cleanup_pcc_mapping() {
166 do_facet $SINGLEAGT $LCTL pcc clear $MOUNT
169 setup_pcc_mapping() {
170 local hsm_root=$(hsm_root)
173 do_facet $SINGLEAGT $LCTL pcc add $MOUNT $hsm_root \
174 -p "$HSM_ARCHIVE_NUMBER\ 100"
181 local agt_facet=$SINGLEAGT
182 local hsm_root=$(hsm_root)
183 local file=$DIR/$tdir/$tfile
188 $project && enable_project_quota
190 do_facet $SINGLEAGT rm -rf $hsm_root
191 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
193 is_project_quota_supported || project=false
195 do_facet $SINGLEAGT mkdir -p $DIR/$tdir
197 $project && lfs project -sp $project_id $DIR/$tdir
199 do_facet $SINGLEAGT "echo -n attach_origin > $file"
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"
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"
213 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=7654321 count=1
214 check_lpcc_sizes $SINGLEAGT $lpcc_path $file 7654321
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"
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"
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
232 path_data=$(do_node $CLIENT2 cat $file)
233 [[ "x$path_data" == "xfile_data" ]] || error \
234 "expected file_data, got: $path_data"
237 check_lpcc_state $file "none"
238 # HSM exists archived status
239 check_hsm_flags $file "0x00000009"
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"
247 echo "Attach and detach testing"
249 do_facet $SINGLEAGT "echo -n new_data2 > $file"
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"
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"
271 lpcc_rw_test true false
273 run_test 1a "Test manual lfs pcc attach with manual HSM restore"
276 lpcc_rw_test false false
278 run_test 1b "Test manual lfs pcc attach with restore on remote access"
281 lpcc_rw_test true true
283 run_test 1c "Test automated attach using Project ID with manual HSM restore"
286 lpcc_rw_test false true
288 run_test 1d "Test Project ID with remote access"
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.
297 local agt_facet=$SINGLEAGT
298 local hsm_root=$(hsm_root)
299 local agt_host=$(facet_active_host $SINGLEAGT)
301 ! is_project_quota_supported &&
302 skip "project quota is not supported" && return
305 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
307 file=$DIR/$tdir/multiop
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"
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"
326 rmultiop_stop $agt_host || error "close $file failed"
329 run_test 2 "Test multi open when creating"
332 local file=$DIR/$tdir/$tfile
334 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
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"
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"
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"
359 run_test 3 "Repeat attach/detach operations"
362 check_and_cleanup_lustre