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 MMAP_CAT=${MMAP_CAT:-mmap_cat}
30 MOUNT_2=${MOUNT_2:-"yes"}
33 # script only handles up to 10 MDTs (because of MDT_PREFIX)
34 [ $MDSCOUNT -gt 9 ] &&
35 error "script cannot handle more than 9 MDTs, please fix" && exit
37 check_and_setup_lustre
39 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.12.52) ]]; then
40 skip_env "Need MDS version at least 2.12.52" && exit
43 # $RUNAS_ID may get set incorrectly somewhere else
44 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
45 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
47 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
48 if getent group nobody; then
50 elif getent group nogroup; then
53 error "No generic nobody group"
58 # if there is no CLIENT1 defined, some tests can be ran on localhost
59 CLIENT1=${CLIENT1:-$HOSTNAME}
60 # if CLIENT2 doesn't exist then use CLIENT1 instead
61 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
63 # Exception is the test which need two separate nodes
64 CLIENT2=${CLIENT2:-$CLIENT1}
70 local expected_size="$3"
72 size=$(do_facet $client stat "--printf=%s" $fpath)
73 [[ $size == "$expected_size" ]] || error \
74 "expected $fpath size: $expected_size got: $size"
81 local lustre_fpath="$3"
82 local expected_size="$4"
84 check_file_size $client $lpcc_fpath $expected_size
85 check_file_size $client $lustre_fpath $expected_size
92 local expected_data="$3"
94 path_data=$(do_facet $client cat $path)
95 [[ "x$path_data" == "x$expected_data" ]] || error \
96 "expected $path: $expected_data, got: $path_data"
102 local lpcc_fpath="$2"
103 local lustre_fpath="$3"
104 local expected_data="$4"
106 check_file_data "$client" "$lpcc_fpath" "$expected_data"
107 check_file_data "$client" "$lustre_fpath" "$expected_data"
113 local lustre_path="$2"
114 local fid=$(path2fid $lustre_path)
120 f_seq=$(echo $fid | awk -F ':' '{print $1}')
121 f_oid=$(echo $fid | awk -F ':' '{print $2}')
122 f_ver=$(echo $fid | awk -F ':' '{print $3}')
124 printf "%s/%04x/%04x/%04x/%04x/%04x/%04x/%s" \
125 $hsm_root $(($f_oid & 0xFFFF)) \
126 $(($f_oid >> 16 & 0xFFFF)) \
127 $(($f_seq & 0xFFFF)) \
128 $(($f_seq >> 16 & 0xFFFF)) \
129 $(($f_seq >> 32 & 0xFFFF)) \
130 $(($f_seq >> 48 & 0xFFFF)) $fid
135 local lustre_path="$1"
136 local expected_state="$2"
137 local facet=${3:-$SINGLEAGT}
139 local state=$(do_facet $facet $myRUNAS $LFS pcc state $lustre_path |
140 awk -F 'type: ' '{print $2}' | awk -F ',' '{print $1}')
142 [[ "x$state" == "x$expected_state" ]] || error \
143 "$lustre_path expected pcc state: $expected_state, but got: $state"
149 # populate MDT device array
152 # cleanup from previous bad setup
155 # for recovery tests, coordinator needs to be started at mount
157 # the lustre conf must be without hsm on (like for sanity.sh)
158 echo "Set HSM on and start"
159 cdt_set_mount_state enabled
160 cdt_check_state enabled
162 echo "Set sanity-hsm HSM policy"
163 cdt_set_sanity_policy
165 # finished requests are quickly removed from list
166 set_hsm_param grace_delay 10
168 cleanup_pcc_mapping() {
169 local facet=${1:-$SINGLEAGT}
171 do_facet $facet $LCTL pcc clear $MOUNT
174 setup_pcc_mapping() {
175 local facet=${1:-$SINGLEAGT}
176 local hsm_root=${hsm_root:-$(hsm_root "$facet")}
179 [ -z "$param" ] && param="projid={100}\ rwid=$HSM_ARCHIVE_NUMBER"
180 stack_trap "cleanup_pcc_mapping $facet" EXIT
181 do_facet $facet $LCTL pcc add $MOUNT $hsm_root -p $param
188 local agt_facet=$SINGLEAGT
189 local hsm_root=$(hsm_root)
190 local file=$DIR/$tdir/$tfile
195 $project && enable_project_quota
197 do_facet $SINGLEAGT rm -rf $hsm_root
198 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
200 is_project_quota_supported || project=false
202 do_facet $SINGLEAGT mkdir -p $DIR/$tdir
204 $project && lfs project -sp $project_id $DIR/$tdir
206 do_facet $SINGLEAGT "echo -n attach_origin > $file"
208 check_lpcc_state $file "none"
209 do_facet $SINGLEAGT $LFS pcc attach -i \
210 $HSM_ARCHIVE_NUMBER $file ||
211 error "pcc attach $file failed"
214 check_lpcc_state $file "readwrite"
215 # HSM released exists archived status
216 check_hsm_flags $file "0x0000000d"
217 lpcc_path=$(lpcc_fid2path $hsm_root $file)
218 check_lpcc_data $SINGLEAGT $lpcc_path $file "attach_origin"
220 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=7654321 count=1
221 check_lpcc_sizes $SINGLEAGT $lpcc_path $file 7654321
223 do_facet $SINGLEAGT $TRUNCATE $file 1234567 ||
224 error "truncate failed"
225 check_lpcc_sizes $SINGLEAGT $lpcc_path $file 1234567
226 check_lpcc_state $file "readwrite"
228 do_facet $SINGLEAGT "echo -n file_data > $file"
229 check_lpcc_state $file "readwrite"
230 # HSM released exists archived status
231 check_hsm_flags $file "0x0000000d"
232 check_lpcc_data $SINGLEAGT $lpcc_path $file "file_data"
234 echo "Restore testing..."
235 if [ $CLIENTCOUNT -lt 2 -o $restore ]; then
236 $LFS hsm_restore $file || error \
237 "failed to restore $file"
238 wait_request_state $(path2fid $file) RESTORE SUCCEED
240 path_data=$(do_node $CLIENT2 cat $file)
241 [[ "x$path_data" == "xfile_data" ]] || error \
242 "expected file_data, got: $path_data"
245 check_lpcc_state $file "none"
246 # HSM exists archived status
247 check_hsm_flags $file "0x00000009"
249 echo -n "new_data" > $file
250 check_lpcc_state $file "none"
251 # HSM exists dirty archived status
252 check_hsm_flags $file "0x0000000b"
253 check_file_data $SINGLEAGT $file "new_data"
255 echo "Attach and detach testing"
257 do_facet $SINGLEAGT "echo -n new_data2 > $file"
259 check_lpcc_state $file "none"
260 do_facet $SINGLEAGT $LFS pcc attach -i \
261 $HSM_ARCHIVE_NUMBER $file ||
262 error "PCC attach $file failed"
264 check_lpcc_state $file "readwrite"
265 # HSM released exists archived status
266 check_hsm_flags $file "0x0000000d"
267 do_facet $SINGLEAGT "echo -n attach_detach > $file"
268 echo "Start to detach the $file"
269 do_facet $SINGLEAGT $LFS pcc detach $file ||
270 error "PCC detach $file failed"
271 check_lpcc_state $file "none"
272 # HSM released exists archived status
273 check_hsm_flags $file "0x0000000d"
274 check_file_data $SINGLEAGT $file "attach_detach"
278 lpcc_rw_test true false
280 run_test 1a "Test manual lfs pcc attach with manual HSM restore"
283 lpcc_rw_test false false
285 run_test 1b "Test manual lfs pcc attach with restore on remote access"
288 lpcc_rw_test true true
290 run_test 1c "Test automated attach using Project ID with manual HSM restore"
293 lpcc_rw_test false true
295 run_test 1d "Test Project ID with remote access"
298 local file=$DIR/$tdir/$tfile
299 local hsm_root=$(hsm_root)
302 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
304 $LCTL pcc list $MOUNT
305 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
306 chmod 777 $DIR/$tdir || error "chmod 777 $DIR/$tdir failed"
308 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
309 error "failed to dd write to $file"
310 do_facet $SINGLEAGT $RUNAS $LFS pcc attach -i $HSM_ARCHIVE_NUMBER \
311 $file || error "failed to attach file $file"
312 check_lpcc_state $file "readwrite"
313 do_facet $SINGLEAGT $RUNAS dd if=$file of=/dev/null bs=1024 count=1 ||
314 error "failed to dd read from $file"
315 do_facet $SINGLEAGT $RUNAS $TRUNCATE $file 256 ||
316 error "failed to truncate $file"
317 do_facet $SINGLEAGT $RUNAS $TRUNCATE $file 2048 ||
318 error "failed to truncate $file"
319 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
320 error "failed to dd write to $file"
321 check_lpcc_state $file "readwrite"
323 # non-root user is forbidden to access PCC file directly
324 lpcc_path=$(lpcc_fid2path $hsm_root $file)
325 do_facet $SINGLEAGT $RUNAS touch $lpcc_path &&
326 error "non-root user can touch access PCC file $lpcc_path"
327 do_facet $SINGLEAGT $RUNAS dd if=$lpcc_path of=/dev/null bs=1024 \
328 count=1 && error "non-root user can read PCC file $lpcc_path"
329 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$lpcc_path bs=1024 \
330 count=1 && error "non-root user can write PCC file $lpcc_path"
332 local perm=$(do_facet $SINGLEAGT stat -c %a $lpcc_path)
334 [[ $perm == "0" ]] || error "PCC file permission ($perm) is not zero"
336 do_facet $SINGLEAGT $RUNAS $LFS pcc detach $file ||
337 error "failed to detach file $file"
338 check_lpcc_state $file "none"
340 run_test 1e "Test RW-PCC with non-root user"
344 local agt_facet=$SINGLEAGT
345 local hsm_root=$(hsm_root)
346 local file=$DIR/$tdir/$tfile
348 ! is_project_quota_supported &&
349 skip "project quota is not supported"
352 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
354 do_facet $SINGLEAGT mkdir -p $DIR/$tdir
355 chmod 777 $DIR/$tdir || error "chmod 0777 $DIR/$tdir failed"
356 $LFS project -sp $project_id $DIR/$tdir ||
357 error "failed to set project for $DIR/$tdir"
359 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
360 error "failed to dd write to $file"
362 check_lpcc_state $file "readwrite"
363 do_facet $SINGLEAGT $RUNAS dd if=$file of=/dev/null bs=1024 count=1 ||
364 error "failed to dd read from $file"
365 do_facet $SINGLEAGT $RUNAS $TRUNCATE $file 256 ||
366 error "failed to truncate $file"
367 do_facet $SINGLEAGT $RUNAS $TRUNCATE $file 2048 ||
368 error "failed to truncate $file"
369 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
370 error "failed to dd write from $file"
371 check_lpcc_state $file "readwrite"
373 # non-root user is forbidden to access PCC file directly
374 lpcc_path=$(lpcc_fid2path $hsm_root $file)
375 do_facet $SINGLEAGT $RUNAS touch $lpcc_path &&
376 error "non-root user can touch access PCC file $lpcc_path"
377 do_facet $SINGLEAGT $RUNAS dd if=$lpcc_path of=/dev/null bs=1024 \
378 count=1 && error "non-root user can read PCC file $lpcc_path"
379 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$lpcc_path bs=1024 \
380 count=1 && error "non-root user can write PCC file $lpcc_path"
382 do_facet $SINGLEAGT $RUNAS $LFS pcc detach $file ||
383 error "failed to detach file $file"
384 check_lpcc_state $file "none"
386 run_test 1f "Test auto RW-PCC cache with non-root user"
389 local file=$DIR/$tfile
391 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
394 dd if=/dev/zero of=$file bs=1024 count=1 ||
395 error "failed to dd write to $file"
396 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 &&
397 error "non-root user can dd write to $file"
398 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
399 error "failed to attach file $file"
400 check_lpcc_state $file "readwrite"
401 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 &&
402 error "non-root user can dd write to $file"
403 chmod 777 $file || error "chmod 777 $file failed"
404 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
405 error "non-root user cannot write $file with permission (777)"
407 do_facet $SINGLEAGT $RUNAS $LFS pcc detach $file &&
408 error "non-root user or non owner can detach $file"
409 chown $RUNAS_ID $file || error "chown $RUNAS_ID $file failed"
410 do_facet $SINGLEAGT $RUNAS $LFS pcc detach $file ||
411 error "failed to detach file $file"
412 check_lpcc_state $file "none"
413 do_facet $SINGLEAGT $RUNAS dd if=$file of=/dev/null bs=1024 count=1 ||
414 error "non-root user cannot read to $file with permisson (777)"
416 run_test 1g "General permission test for RW-PCC"
419 # When a process created a LPCC file and holding the open,
420 # another process on the same client should be able to open the file.
424 local agt_facet=$SINGLEAGT
425 local hsm_root=$(hsm_root)
426 local agt_host=$(facet_active_host $SINGLEAGT)
428 ! is_project_quota_supported &&
429 skip "project quota is not supported" && return
432 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
434 file=$DIR/$tdir/multiop
438 do_facet $SINGLEAGT $LFS project -sp $project_id $DIR/$tdir ||
439 error "failed to set project quota"
440 rmultiop_start $agt_host $file O_c || error "open $file failed"
441 # HSM released exists archived status
442 check_hsm_flags $file "0x0000000d"
443 do_facet $SINGLEAGT "echo -n multiopen_data > $file" ||
444 error "failed to echo multiopen_data to $file"
446 lpcc_path=$(lpcc_fid2path $hsm_root $file)
447 do_facet $SINGLEAGT ls -l $lpcc_path ||
448 error "failed to ls $lpcc_path"
449 check_lpcc_data $SINGLEAGT $lpcc_path $file "multiopen_data"
450 # HSM released exists archived status
451 check_hsm_flags $file "0x0000000d"
453 rmultiop_stop $agt_host || error "close $file failed"
455 run_test 2a "Test multi open when creating"
457 get_remote_client() {
458 current_id=$(do_facet $SINGLEAGT hostname)
459 for client in ${CLIENTS//,/ }
461 r_id=$(do_node $client hostname)
462 if [ $r_id != $current_id ]; then
470 # When a process created a LPCC file and holding the open, another
471 # process on the different client should be able to open the file
472 # and perform IO on the file.
475 local agt_facet=$SINGLEAGT
476 local hsm_root=$(hsm_root)
477 local agt_host=$(facet_active_host $SINGLEAGT)
479 needclients 2 || return 0
481 remote_client=$(get_remote_client)
484 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
486 file=$DIR/$tdir/multiop
490 do_facet $SINGLEAGT "echo -n file_data > $file"
491 do_facet $SINGLEAGT lfs pcc attach -i $HSM_ARCHIVE_NUMBER \
492 $file || error "PCC attach $file failed"
493 check_lpcc_state $file "readwrite"
495 rmultiop_start $agt_host $file O_c || error "open $file failed"
497 do_node $remote_client "echo -n multiopen_data > $file"
499 # PCC cached file should be automatically detached
500 check_lpcc_state $file "none"
502 check_file_data $SINGLEAGT $file "multiopen_data"
503 rmultiop_stop $agt_host || error "close $file failed"
504 check_file_data $SINGLEAGT $file "multiopen_data"
506 do_node $remote_client cat $file || error \
507 "cat $file on remote client failed"
508 do_node $remote_client echo -n "multiopen_data" > $file \
509 || error "write $file on remote client failed"
511 run_test 2b "Test multi remote open when creating"
514 local agt_host=$(facet_active_host $SINGLEAGT)
515 local file=$DIR/$tdir/$tfile
516 local file2=$DIR2/$tdir/$tfile
519 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
524 do_facet $SINGLEAGT "echo -n file_data > $file"
525 do_facet $SINGLEAGT lfs pcc attach -i $HSM_ARCHIVE_NUMBER \
526 $file || error "PCC attach $file failed"
527 check_lpcc_state $file "readwrite"
529 rmultiop_start $agt_host $file O_c || error "open $file failed"
531 echo -n multiopen_data > $file2
533 # PCC cached file should be automatically detached
534 check_lpcc_state $file "none"
536 check_file_data $SINGLEAGT $file "multiopen_data"
537 rmultiop_stop $agt_host || error "close $file failed"
538 check_file_data $SINGLEAGT $file "multiopen_data"
540 cat $file2 || error "cat $file on mount $MOUNT2 failed"
541 echo -n "multiopen_data" > $file2 ||
542 error "write $file on mount $MOUNT2 failed"
544 run_test 2c "Test multi open on different mount points when creating"
547 local file=$DIR/$tdir/$tfile
549 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
552 mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir failed"
553 dd if=/dev/zero of=$file bs=1024 count=1 ||
554 error "failed to dd write to $file"
556 echo "Start to attach/detach the file: $file"
557 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
558 error "failed to attach file $file"
559 check_lpcc_state $file "readwrite"
560 do_facet $SINGLEAGT $LFS pcc detach $file ||
561 error "failed to detach file $file"
562 check_lpcc_state $file "none"
564 echo "Repeat to attach/detach the same file: $file"
565 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
566 error "failed to attach file $file"
567 check_lpcc_state $file "readwrite"
568 do_facet $SINGLEAGT $LFS pcc detach $file ||
569 error "failed to detach file $file"
570 check_lpcc_state $file "none"
572 run_test 3a "Repeat attach/detach operations"
576 local file=$DIR/$tdir/$tfile
578 needclients 3 || return 0
580 # Start all of the copytools and setup PCC
581 for n in $(seq $AGTCOUNT); do
582 copytool setup -f agt$n -a $n -m $MOUNT
583 setup_pcc_mapping agt$n "projid={100}\ rwid=$n"
586 mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir failed"
587 dd if=/dev/zero of=$file bs=1024 count=1 ||
588 error "failed to dd write to $file"
590 echo "Start to attach/detach $file on $agt1_HOST"
591 do_facet agt1 $LFS pcc attach -i 1 $file ||
592 error "failed to attach file $file"
593 check_lpcc_state $file "readwrite" agt1
594 do_facet agt1 $LFS pcc detach $file ||
595 error "failed to detach file $file"
596 check_lpcc_state $file "none" agt1
598 echo "Repeat to attach/detach $file on $agt2_HOST"
599 do_facet agt2 $LFS pcc attach -i 2 $file ||
600 error "failed to attach file $file"
601 check_lpcc_state $file "readwrite" agt2
602 do_facet agt2 $LFS pcc detach $file ||
603 error "failed to detach file $file"
604 check_lpcc_state $file "none" agt2
606 echo "Try attach on two agents"
607 do_facet agt1 $LFS pcc attach -i 1 $file ||
608 error "failed to attach file $file"
609 check_lpcc_state $file "readwrite" agt1
610 do_facet agt2 $LFS pcc attach -i 2 $file ||
611 error "failed to attach file $file"
612 check_lpcc_state $file "readwrite" agt2
613 # The later attach PCC agent should succeed,
614 # the former agent should be detached automatically.
615 check_lpcc_state $file "none" agt1
616 do_facet agt2 $LFS pcc detach $file ||
617 error "failed to detach file $file"
618 check_lpcc_state $file "none" agt2
620 run_test 3b "Repeat attach/detach operations on multiple clients"
625 ! is_project_quota_supported &&
626 skip "project quota is not supported" && return
629 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
632 mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir failed"
633 lfs project -sp $project_id $DIR/$tdir ||
634 error "lfs project -sp $project_id $DIR/$tdir failed"
636 # mmap_sanity tst7 failed on the local ext4 filesystem.
637 # It seems that Lustre filesystem does special process for tst 7.
638 # Thus, we exclude tst7 from the PCC testing.
639 $LUSTRE/tests/mmap_sanity -d $DIR/$tdir -m $DIR2/$tdir -e 7 ||
640 error "mmap_sanity test failed"
643 run_test 4 "Auto cache test for mmap"
646 local file=$DIR/$tfile
648 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
651 do_facet $SINGLEAGT "echo -n attach_mmap_data > $file" ||
652 error "echo $file failed"
654 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
655 error "failed to attach file $file"
656 check_lpcc_state $file "readwrite"
658 local content=$($MMAP_CAT $file)
660 [[ $content == "attach_mmap_data" ]] ||
661 error "mmap cat data mismatch: $content"
663 $LFS hsm_restore $file || error "failed to restore $file"
664 wait_request_state $(path2fid $file) RESTORE SUCCEED
665 check_lpcc_state $file "none"
667 content=$($MMAP_CAT $file)
668 [[ $content == "attach_mmap_data" ]] ||
669 error "mmap cat data mismatch: $content"
671 run_test 5 "Mmap & cat a RW-PCC cached file"
679 do_facet $facet mkdir -p $mntpt || error "mkdir -p $hsm_root failed"
680 stack_trap "do_facet $facet rm -rf $mntpt" EXIT
681 do_facet $facet dd if=/dev/zero of=$file bs=1M count=$size
682 stack_trap "do_facet $facet rm -f $file" EXIT
683 do_facet $facet mkfs.ext4 $file ||
684 error "mkfs.ext4 $file failed"
685 do_facet $facet file $file
686 do_facet $facet mount -t ext4 -o loop,usrquota,grpquota $file $mntpt ||
687 error "mount -o loop,usrquota,grpquota $file $mntpt failed"
688 stack_trap "do_facet $facet $UMOUNT $mntpt" EXIT
692 local loopfile="$TMP/$tfile"
693 local mntpt="/mnt/pcc.$tdir"
694 local hsm_root="$mntpt/$tdir"
695 local file=$DIR/$tfile
698 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
699 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
702 echo -n mmap_write_data > $file || error "echo write $file failed"
703 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
704 error "failed to attach file $file"
705 check_lpcc_state $file "readwrite"
707 do_facet $SINGLEAGT $MULTIOP $file OSMWUc ||
708 error "could not mmap $file"
709 check_lpcc_state $file "readwrite"
710 content=$(do_facet $SINGLEAGT $MMAP_CAT $file)
711 # After mmap write via multiop, the first character of each page
713 [[ $content == "nmap_write_data" ]] ||
714 error "mmap write data mismatch: $content"
715 check_lpcc_state $file "readwrite"
717 do_facet $SINGLEAGT $LFS pcc detach $file ||
718 error "failed to detach file $file"
720 content=$(do_facet $SINGLEAGT $MMAP_CAT $file)
721 [[ $content == "nmap_write_data" ]] ||
722 error "mmap write data mismatch: $content"
724 run_test 6 "Test mmap write on RW-PCC "
727 local loopfile="$TMP/$tfile"
728 local mntpt="/mnt/pcc.$tdir"
729 local hsm_root="$mntpt/$tdir"
730 local file=$DIR/$tfile
733 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
734 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
738 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
739 error "failed to attach file $file"
740 check_lpcc_state $file "readwrite"
741 check_file_data $SINGLEAGT $file "QQQQQ"
742 # define OBD_FAIL_LLITE_PCC_DETACH_MKWRITE 0x1412
743 do_facet $SINGLEAGT $LCTL set_param fail_loc=0x1412
744 # HSM released exists archived status
745 check_hsm_flags $file "0x0000000d"
747 # multiop mmap write increase the first character of each page with 1
748 do_facet $SINGLEAGT $MULTIOP $file OSMWUc ||
749 error "mmap write $file failed"
750 check_lpcc_state $file "none"
751 content=$(do_facet $SINGLEAGT $MMAP_CAT $file)
752 [[ $content == "RQQQQ" ]] || error "data mismatch: $content"
754 run_test 7a "Fake file detached between fault() and page_mkwrite() for RW-PCC"
757 local loopfile="$TMP/$tfile"
758 local mntpt="/mnt/pcc.$tdir"
759 local hsm_root="$mntpt/$tdir"
760 local file=$DIR/$tfile
764 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
765 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
769 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
770 error "failed to attach file $file"
771 check_lpcc_state $file "readwrite"
772 check_file_data $SINGLEAGT $file "QQQQQ"
773 # define OBD_FAIL_LLITE_PCC_MKWRITE_PAUSE 0x1413
774 do_facet $SINGLEAGT $LCTL set_param fail_loc=0x1413 fail_val=20
775 # HSM released exists archived status
776 check_hsm_flags $file "0x0000000d"
778 # multiop mmap write increase the first character of each page with 1
779 do_facet $SINGLEAGT $MULTIOP $file OSMWUc &
782 do_facet $SINGLEAGT $LFS pcc detach $file ||
783 error "failed to detach file $file"
785 wait $pid || error "multiop mmap write failed"
786 check_lpcc_state $file "none"
787 content=$(do_facet $SINGLEAGT $MMAP_CAT $file)
788 [[ $content == "RQQQQ" ]] || error "data mismatch: $content"
790 run_test 7b "Test the race with concurrent mkwrite and detach"
793 local file=$DIR/$tfile
795 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
799 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
800 error "failed to attach file $file"
801 check_lpcc_state $file "readwrite"
802 check_file_data $SINGLEAGT $file "QQQQQ"
804 # define OBD_FAIL_LLITE_PCC_FAKE_ERROR 0x1411
805 do_facet $SINGLEAGT $LCTL set_param fail_loc=0x1411
806 do_facet $SINGLEAGT "echo -n ENOSPC_write > $file"
807 # Above write will return -ENOSPC failure and retry the IO on normal
808 # IO path. It will restore the HSM released file.
809 check_lpcc_state $file "none"
810 check_file_data $SINGLEAGT $file "ENOSPC_write"
812 run_test 8 "Test fake -ENOSPC tolerance for RW-PCC"
815 local loopfile="$TMP/$tfile"
816 local mntpt="/mnt/pcc.9a"
817 local hsm_root="$mntpt/$tdir"
818 local file=$DIR/$tfile
820 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
822 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMVER" -h "$hsm_root"
824 do_facet $SINGLEAGT $LCTL pcc list $MOUNT
826 touch $file || error "touch $file failed"
827 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
828 error "fail to attach $file"
829 check_lpcc_state $file "readwrite"
830 # write 60M data, it is larger than the capacity of PCC backend
831 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1M count=60 ||
832 error "fail to dd write $file"
833 check_lpcc_state $file "none"
834 check_file_size $SINGLEAGT $file 62914560
836 run_test 9 "Test -ENOSPC tolerance on loop PCC device for RW-PCC"
838 test_usrgrp_quota() {
839 local loopfile="$TMP/$tfile"
840 local mntpt="/mnt/pcc.$tdir"
841 local hsm_root="$mntpt/$tdir"
845 [[ $ug == "g" ]] && id=$RUNAS_GID
847 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
848 do_facet $SINGLEAGT quotacheck -c$ug $mntpt ||
849 error "quotacheck -c$ug $mntpt failed"
850 do_facet $SINGLEAGT quotaon -$ug $mntpt ||
851 error "quotaon -$ug $mntpt failed"
852 do_facet $SINGLEAGT setquota -$ug $id 0 20480 0 0 $mntpt ||
853 error "setquota -$ug $id on $mntpt failed"
854 do_facet $SINGLEAGT repquota -${ug}vs $mntpt
856 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMVER" -h "$hsm_root"
858 do_facet $SINGLEAGT $LCTL pcc list $MOUNT
860 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
862 local file1=$DIR/$tdir/${ug}quotaA
863 local file2=$DIR/$tdir/${ug}quotaB
865 dd if=/dev/zero of=$file1 bs=1M count=15 ||
866 error "dd write $file1 failed"
867 dd if=/dev/zero of=$file2 bs=1M count=15 ||
868 error "dd write $file2 failed"
869 chown $RUNAS_ID:$RUNAS_GID $file1 ||
870 error "chown $RUNAS_ID:$RUNAS_GID $file1 failed"
871 chown $RUNAS_ID:$RUNAS_GID $file2 ||
872 error "chown $RUNAS_ID:$RUNAS_GID $file2 failed"
873 do_facet $SINGLEAGT $RUNAS $LFS pcc attach -i $HSM_ARCHIVE_NUMBER \
874 $file1 || error "attach $file1 failed"
875 do_facet $SINGLEAGT $RUNAS $LFS pcc attach -i $HSM_ARCHIVE_NUMBER \
876 $file2 && error "attach $file2 should fail due to quota limit"
877 check_lpcc_state $file1 "readwrite"
878 check_lpcc_state $file2 "none"
880 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file1 bs=1M count=30 ||
881 error "dd write $file1 failed"
882 # -EDQUOT error should be tolerated via fallback to normal Lustre path.
883 check_lpcc_state $file1 "none"
884 do_facet $SINGLEAGT $LFS pcc detach $file1 ||
885 error "failed to detach file $file"
890 test_usrgrp_quota "u"
892 run_test 10a "Test RW-PCC with user quota on loop PCC device"
895 test_usrgrp_quota "g"
897 run_test 10b "Test RW-PCC with group quota on loop PCC device"
900 local loopfile="$TMP/$tfile"
901 local mntpt="/mnt/pcc.$tdir"
902 local hsm_root="$mntpt/$tdir"
903 local file=$DIR/$tfile
907 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
908 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
911 do_facet $SINGLEAGT "echo -n QQQQQ > $file"
912 lpcc_path=$(lpcc_fid2path $hsm_root $file)
913 lpcc_dir=$(dirname $lpcc_path)
914 echo "Lustre file: $file LPCC dir: $lpcc_dir"
915 do_facet $SINGLEAGT mkdir -p $lpcc_dir ||
916 error "mkdir -p $lpcc_dir failed"
917 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
918 error "failed to attach $file"
919 check_lpcc_state $file "readwrite"
920 check_file_data $SINGLEAGT $file "QQQQQ"
921 do_facet $SINGLEAGT $LFS pcc detach $file ||
922 error "failed to detach $file"
923 rm $file || error "rm $file failed"
925 # The parent directory of the PCC file is immutable
926 do_facet $SINGLEAGT "echo -n immutable_dir > $file"
927 lpcc_path=$(lpcc_fid2path $hsm_root $file)
928 lpcc_dir=$(dirname $lpcc_path)
929 echo "Lustre file: $file LPCC dir: $lpcc_dir"
930 do_facet $SINGLEAGT mkdir -p $lpcc_dir ||
931 error "mkdir -p $lpcc_dir failed"
932 do_facet $SINGLEAGT chattr +i $lpcc_dir ||
933 error "chattr +i $lpcc_dir failed"
934 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file &&
935 error "attach $file with immutable directory should be failed"
936 do_facet $SINGLEAGT chattr -i $lpcc_dir ||
937 error "chattr -i $lpcc_dir failed"
938 rm $file || error "rm $file failed"
940 # The PCC file path is set to a directory
941 do_facet $SINGLEAGT "echo -n pcc_file_path_is_dir > $file"
942 lpcc_path=$(lpcc_fid2path $hsm_root $file)
943 do_facet $SINGLEAGT mkdir -p $lpcc_path ||
944 error "mkdir -p $lpcc_path failed"
945 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file &&
946 error "attach $file should fail as PCC path is a directory"
947 rm $file || error "rm $file failed"
949 run_test 11 "Test attach fault injection with simulated PCC file path"
952 local file=$DIR/$tfile
955 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
958 echo -n race_rw_attach_hsmremove > $file
959 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
960 error "attach $file failed"
961 do_facet $SINGLEAGT $LFS pcc detach $file || error "detach $file failed"
962 # HSM released exists archived status
963 check_hsm_flags $file "0x0000000d"
964 # define OBD_FAIL_LLITE_PCC_ATTACH_PAUSE 0x1414
965 do_facet $SINGLEAGT $LCTL set_param fail_loc=0x1414 fail_val=20
966 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file &
970 wait_request_state $(path2fid $file) RESTORE SUCCEED
971 $LFS hsm_remove $file || error "hsm remove $file failed"
972 wait $pid && error "RW-PCC attach $file should fail"
976 run_test 12 "RW-PCC attach races with concurrent HSM remove"
980 local rule="${idstr}={$2}"
982 local file=$DIR/$tdir/$tfile
984 setup_pcc_mapping $SINGLEAGT "$rule\ rwid=$HSM_ARCHIVE_NUMBER"
985 $LCTL pcc list $MOUNT
987 do_facet $SINGLEAGT mkdir -p $DIR/$tdir
988 chmod 777 $DIR/$tdir || error "chmod 0777 $DIR/$tdir failed"
990 rm -f $file || error "rm $file failed"
991 do_facet $SINGLEAGT $myRUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
992 error "failed to dd write to $file"
993 check_lpcc_state $file "readwrite"
994 do_facet $SINGLEAGT $myRUNAS dd if=$file of=/dev/null bs=1024 count=1 ||
995 error "failed to dd read from $file"
996 do_facet $SINGLEAGT $myRUNAS $TRUNCATE $file 256 ||
997 error "failed to truncate $file"
998 do_facet $SINGLEAGT $myRUNAS $TRUNCATE $file 2048 ||
999 error "failed to truncate $file"
1000 do_facet $SINGLEAGT $myRUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1001 error "failed to dd write from $file"
1002 check_lpcc_state $file "readwrite"
1004 do_facet $SINGLEAGT $myRUNAS $LFS pcc detach $file ||
1005 error "failed to detach file $file"
1006 check_lpcc_state $file "none"
1010 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1011 test_rule_id "u" "500" "runas -u 500"
1012 test_rule_id "g" "500" "runas -u 500 -g 500"
1014 run_test 13a "Test auto RW-PCC create caching for UID/GID rule"
1019 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1020 setup_pcc_mapping $SINGLEAGT \
1021 "fname={*.h5\ suffix.*\ Mid*dle}\ rwid=$HSM_ARCHIVE_NUMBER"
1022 $LCTL pcc list $MOUNT
1024 do_facet $SINGLEAGT mkdir -p $DIR/$tdir
1025 chmod 777 $DIR/$tdir || error "chmod 0777 $DIR/$tdir failed"
1027 file=$DIR/$tdir/prefix.h5
1028 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1024 count=1 ||
1029 error "failed to dd write to $file"
1030 check_lpcc_state $file "readwrite"
1031 do_facet $SINGLEAGT $myRUNAS $LFS pcc detach $file ||
1032 error "failed to detach file $file"
1033 check_lpcc_state $file "none"
1034 rm $file || error "rm $file failed"
1036 file=$DIR/$tdir/suffix.doc
1037 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1038 error "failed to dd write to $file"
1039 check_lpcc_state $file "readwrite"
1040 do_facet $SINGLEAGT $myRUNAS $LFS pcc detach $file ||
1041 error "failed to detach file $file"
1042 check_lpcc_state $file "none"
1043 rm $file || error "rm $file failed"
1045 file=$DIR/$tdir/MidPADdle
1046 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1047 error "failed to dd write to $file"
1048 check_lpcc_state $file "readwrite"
1049 do_facet $SINGLEAGT $myRUNAS $LFS pcc detach $file ||
1050 error "failed to detach file $file"
1051 check_lpcc_state $file "none"
1052 rm $file || error "rm $file failed"
1054 file=$DIR/$tdir/Midpad
1055 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1056 error "failed to dd write to $file"
1057 check_lpcc_state $file "none"
1058 rm $file || error "rm $file failed"
1060 run_test 13b "Test auto RW-PCC create caching for file name with wildcard"
1066 ! is_project_quota_supported &&
1067 echo "Skip project quota is not supported" && return 0
1069 enable_project_quota
1070 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1071 setup_pcc_mapping $SINGLEAGT \
1072 "projid={100\ 200}\&fname={*.h5},uid={500}\&gid={1000}\ rwid=$HSM_ARCHIVE_NUMBER"
1073 $LCTL pcc list $MOUNT
1074 do_facet $SINGLEAGT mkdir -p $DIR/$tdir
1075 chmod 777 $DIR/$tdir || error "chmod 0777 $DIR/$tdir failed"
1077 mkdir -p $DIR/$tdir/proj || error "mkdir $DIR/$tdir/proj failed"
1078 mkdir -p $DIR/$tdir/proj2 || error "mkdir $DIR/$tdir/proj2 failed"
1079 $LFS project -sp 100 $DIR/$tdir/proj ||
1080 error "failed to set project for $DIR/$tdir/proj"
1081 $LFS project -sp 200 $DIR/$tdir/proj2 ||
1082 error "failed to set project for $DIR/$tdir/proj2"
1084 file=$DIR/$tdir/proj/notcache
1085 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1024 count=1 ||
1086 error "failed to dd write to $file"
1087 check_lpcc_state $file "none"
1088 rm $file || error "rm $file failed"
1090 file=$DIR/$tdir/proj/autocache.h5
1091 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1024 count=1 ||
1092 error "failed to dd write to $file"
1093 check_lpcc_state $file "readwrite"
1094 do_facet $SINGLEAGT $LFS pcc detach $file ||
1095 error "failed to detach $file"
1096 rm $file || error "rm $file failed"
1098 file=$DIR/$tdir/proj2/notcache
1099 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1024 count=1 ||
1100 error "failed to dd write to $file"
1101 check_lpcc_state $file "none"
1102 rm $file || error "rm $file failed"
1104 file=$DIR/$tdir/proj2/autocache.h5
1105 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1024 count=1 ||
1106 error "failed to dd write to $file"
1107 check_lpcc_state $file "readwrite"
1108 do_facet $SINGLEAGT $LFS pcc detach $file ||
1109 error "failed to detach $file"
1110 rm $file || error "rm $file failed"
1112 file=$DIR/$tdir/ugidcache
1113 myRUNAS="runas -u 500 -g 1000"
1114 do_facet $SINGLEAGT $myRUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1115 error "failed to dd write to $file"
1116 check_lpcc_state $file "readwrite"
1117 do_facet $SINGLEAGT $LFS pcc detach $file ||
1118 error "failed to detach $file"
1119 rm $file || error "rm $file failed"
1121 run_test 13c "Check auto RW-PCC create caching for UID/GID/ProjID/fname rule"
1124 local file=$DIR/$tdir/$tfile
1126 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1129 mkdir -p $DIR/$tdir || error "mkdir -p $DIR/$tdir failed"
1130 do_facet $SINGLEAGT "echo -n autodetach_data > $file"
1131 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER \
1132 $file || error "PCC attach $file failed"
1133 check_lpcc_state $file "readwrite"
1135 # Revoke the layout lock, the PCC-cached file will be
1136 # detached automatically.
1137 do_facet $SINGLEAGT $LCTL \
1138 set_param ldlm.namespaces.*mdc*.lru_size=clear
1139 check_file_data $SINGLEAGT $file "autodetach_data"
1140 check_lpcc_state $file "none"
1142 run_test 14 "Revocation of the layout lock should detach the file automatically"
1145 local loopfile="$TMP/$tfile"
1146 local mntpt="/mnt/pcc.$tdir"
1147 local hsm_root="$mntpt/$tdir"
1148 local file=$DIR/$tdir/$tfile
1150 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1151 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1152 setup_pcc_mapping $SINGLEAGT \
1153 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ open_attach=1"
1155 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
1156 chmod 777 $DIR/$tdir || error "chmod 777 $DIR/$tdir failed"
1158 echo "Check open attach for non-root user"
1159 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1160 error "failed to dd write to $file"
1161 do_facet $SINGLEAGT $RUNAS $LFS pcc attach -i $HSM_ARCHIVE_NUMBER \
1162 $file || error "failed to attach file $file"
1163 do_facet $SINGLEAGT $RUNAS $LFS pcc state $file
1164 check_lpcc_state $file "readwrite" $SINGLEAGT "$RUNAS"
1165 # Revoke the layout lock, the PCC-cached file will be
1166 # detached automatically.
1167 do_facet $SINGLEAGT $LCTL \
1168 set_param ldlm.namespaces.*mdc*.lru_size=clear
1169 check_lpcc_state $file "readwrite" $SINGLEAGT "$RUNAS"
1170 # Detach the file directly, as the file layout generation
1171 # is not changed, so the file is still valid cached in PCC,
1172 # and can be reused from PCC cache directly.
1173 do_facet $SINGLEAGT $RUNAS $LFS pcc detach $file ||
1174 error "PCC detach $file failed"
1175 check_lpcc_state $file "readwrite" $SINGLEAGT "$RUNAS"
1176 do_facet $SINGLEAGT $RUNAS $LFS pcc detach $file ||
1177 error "PCC detach $file failed"
1178 rm $file || error "rm $file failed"
1180 echo "check open attach for root user"
1181 do_facet $SINGLEAGT "echo -n autoattach_data > $file"
1182 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER \
1183 $file || error "PCC attach $file failed"
1184 check_lpcc_state $file "readwrite"
1186 # Revoke the layout lock, the PCC-cached file will be
1187 # detached automatically.
1188 do_facet $SINGLEAGT $LCTL \
1189 set_param ldlm.namespaces.*mdc*.lru_size=clear
1190 check_file_data $SINGLEAGT $file "autoattach_data"
1191 check_lpcc_state $file "readwrite"
1193 # Detach the file directly, as the file layout generation
1194 # is not changed, so the file is still valid cached in PCC,
1195 # and can be reused from PCC cache directly.
1196 do_facet $SINGLEAGT $LFS pcc detach $file ||
1197 error "PCC detach $file failed"
1198 check_lpcc_state $file "readwrite"
1199 # HSM released exists archived status
1200 check_hsm_flags $file "0x0000000d"
1201 check_file_data $SINGLEAGT $file "autoattach_data"
1203 $LFS hsm_restore $file || error "failed to restore $file"
1204 wait_request_state $(path2fid $file) RESTORE SUCCEED
1205 check_lpcc_state $file "none"
1207 run_test 15 "Test auto attach at open when file is still valid cached"
1210 check_and_cleanup_lustre