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 [[ "$MDS1_VERSION" -lt $(version_code 2.12.52) ]]; then
40 skip "Need MDS version at least 2.12.52"
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
190 do_facet $facet mkdir -p $mntpt || error "mkdir -p $hsm_root failed"
191 stack_trap "do_facet $facet rm -rf $mntpt" EXIT
192 do_facet $facet dd if=/dev/zero of=$file bs=1M count=$size
193 stack_trap "do_facet $facet rm -f $file" EXIT
194 do_facet $facet mkfs.ext4 $file ||
195 error "mkfs.ext4 $file failed"
196 do_facet $facet file $file
197 do_facet $facet mount -t ext4 -o loop,usrquota,grpquota $file $mntpt ||
198 error "mount -o loop,usrquota,grpquota $file $mntpt failed"
199 stack_trap "do_facet $facet $UMOUNT $mntpt" EXIT
206 local agt_facet=$SINGLEAGT
207 local loopfile="$TMP/$tfile"
208 local mntpt="/mnt/pcc.$tdir"
209 local hsm_root="$mntpt/$tdir"
210 local file=$DIR/$tdir/$tfile
215 $project && enable_project_quota
217 do_facet $SINGLEAGT rm -rf $hsm_root
218 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
219 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
221 is_project_quota_supported || project=false
223 do_facet $SINGLEAGT mkdir -p $DIR/$tdir
225 $project && lfs project -sp $project_id $DIR/$tdir
227 do_facet $SINGLEAGT "echo -n attach_origin > $file"
229 check_lpcc_state $file "none"
230 do_facet $SINGLEAGT $LFS pcc attach -i \
231 $HSM_ARCHIVE_NUMBER $file ||
232 error "pcc attach $file failed"
235 check_lpcc_state $file "readwrite"
236 # HSM released exists archived status
237 check_hsm_flags $file "0x0000000d"
238 lpcc_path=$(lpcc_fid2path $hsm_root $file)
239 check_lpcc_data $SINGLEAGT $lpcc_path $file "attach_origin"
241 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=7654321 count=1
242 check_lpcc_sizes $SINGLEAGT $lpcc_path $file 7654321
244 do_facet $SINGLEAGT $TRUNCATE $file 1234567 ||
245 error "truncate failed"
246 check_lpcc_sizes $SINGLEAGT $lpcc_path $file 1234567
247 check_lpcc_state $file "readwrite"
249 do_facet $SINGLEAGT "echo -n file_data > $file"
250 check_lpcc_state $file "readwrite"
251 # HSM released exists archived status
252 check_hsm_flags $file "0x0000000d"
253 check_lpcc_data $SINGLEAGT $lpcc_path $file "file_data"
255 echo "Restore testing..."
256 if [ $CLIENTCOUNT -lt 2 -o $restore ]; then
257 $LFS hsm_restore $file || error \
258 "failed to restore $file"
259 wait_request_state $(path2fid $file) RESTORE SUCCEED
261 path_data=$(do_node $CLIENT2 cat $file)
262 [[ "x$path_data" == "xfile_data" ]] || error \
263 "expected file_data, got: $path_data"
266 check_lpcc_state $file "none"
267 # HSM exists archived status
268 check_hsm_flags $file "0x00000009"
270 echo -n "new_data" > $file
271 check_lpcc_state $file "none"
272 # HSM exists dirty archived status
273 check_hsm_flags $file "0x0000000b"
274 check_file_data $SINGLEAGT $file "new_data"
276 echo "Attach and detach testing"
278 do_facet $SINGLEAGT "echo -n new_data2 > $file"
280 check_lpcc_state $file "none"
281 do_facet $SINGLEAGT $LFS pcc attach -i \
282 $HSM_ARCHIVE_NUMBER $file ||
283 error "PCC attach $file failed"
285 check_lpcc_state $file "readwrite"
286 # HSM released exists archived status
287 check_hsm_flags $file "0x0000000d"
288 do_facet $SINGLEAGT "echo -n attach_detach > $file"
289 echo "Start to detach the $file"
290 do_facet $SINGLEAGT $LFS pcc detach $file ||
291 error "PCC detach $file failed"
292 wait_request_state $(path2fid $file) REMOVE SUCCEED
294 check_lpcc_state $file "none"
295 # The file is removed from PCC
296 check_hsm_flags $file "0x00000000"
297 check_file_data $SINGLEAGT $file "attach_detach"
301 lpcc_rw_test true false
303 run_test 1a "Test manual lfs pcc attach with manual HSM restore"
306 lpcc_rw_test false false
308 run_test 1b "Test manual lfs pcc attach with restore on remote access"
311 lpcc_rw_test true true
313 run_test 1c "Test automated attach using Project ID with manual HSM restore"
316 lpcc_rw_test false true
318 run_test 1d "Test Project ID with remote access"
321 local file=$DIR/$tdir/$tfile
322 local hsm_root=$(hsm_root)
325 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
326 setup_pcc_mapping $SINGLEAGT \
327 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0"
328 $LCTL pcc list $MOUNT
329 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
330 chmod 777 $DIR/$tdir || error "chmod 777 $DIR/$tdir failed"
332 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
333 error "failed to dd write to $file"
334 do_facet $SINGLEAGT $RUNAS $LFS pcc attach -i $HSM_ARCHIVE_NUMBER \
335 $file || error "failed to attach file $file"
336 check_lpcc_state $file "readwrite"
337 do_facet $SINGLEAGT $RUNAS dd if=$file of=/dev/null bs=1024 count=1 ||
338 error "failed to dd read from $file"
339 do_facet $SINGLEAGT $RUNAS $TRUNCATE $file 256 ||
340 error "failed to truncate $file"
341 do_facet $SINGLEAGT $RUNAS $TRUNCATE $file 2048 ||
342 error "failed to truncate $file"
343 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
344 error "failed to dd write to $file"
345 check_lpcc_state $file "readwrite"
347 do_facet $SINGLEAGT $RUNAS $LFS pcc detach -k $file ||
348 error "failed to detach file $file"
349 check_lpcc_state $file "none"
351 # non-root user is forbidden to access PCC file directly
352 lpcc_path=$(lpcc_fid2path $hsm_root $file)
353 do_facet $SINGLEAGT $RUNAS touch $lpcc_path &&
354 error "non-root user can touch access PCC file $lpcc_path"
355 do_facet $SINGLEAGT $RUNAS dd if=$lpcc_path of=/dev/null bs=1024 \
356 count=1 && error "non-root user can read PCC file $lpcc_path"
357 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$lpcc_path bs=1024 \
358 count=1 && error "non-root user can write PCC file $lpcc_path"
360 local perm=$(do_facet $SINGLEAGT stat -c %a $lpcc_path)
362 [[ $perm == "0" ]] || error "PCC file permission ($perm) is not zero"
364 do_facet $SINGLEAGT $RUNAS $LFS pcc attach -i $HSM_ARCHIVE_NUMBER \
365 $file || error "failed to attach file $file"
366 check_lpcc_state $file "readwrite"
368 do_facet $SINGLEAGT $RUNAS $LFS pcc detach $file ||
369 error "failed to detach file $file"
370 check_lpcc_state $file "none"
371 wait_request_state $(path2fid $file) REMOVE SUCCEED
373 run_test 1e "Test RW-PCC with non-root user"
377 local agt_facet=$SINGLEAGT
378 local loopfile="$TMP/$tfile"
379 local mntpt="/mnt/pcc.$tdir"
380 local hsm_root="$mntpt/$tdir"
381 local file=$DIR/$tdir/$tfile
383 ! is_project_quota_supported &&
384 skip "project quota is not supported"
387 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
388 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
389 setup_pcc_mapping $SINGLEAGT \
390 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ open_attach=0\ stat_attach=0"
392 do_facet $SINGLEAGT mkdir -p $DIR/$tdir
393 chmod 777 $DIR/$tdir || error "chmod 0777 $DIR/$tdir failed"
394 $LFS project -sp $project_id $DIR/$tdir ||
395 error "failed to set project for $DIR/$tdir"
397 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
398 error "failed to dd write to $file"
400 check_lpcc_state $file "readwrite"
401 do_facet $SINGLEAGT $RUNAS dd if=$file of=/dev/null bs=1024 count=1 ||
402 error "failed to dd read from $file"
403 do_facet $SINGLEAGT $RUNAS $TRUNCATE $file 256 ||
404 error "failed to truncate $file"
405 do_facet $SINGLEAGT $RUNAS $TRUNCATE $file 2048 ||
406 error "failed to truncate $file"
407 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=256 count=1 ||
408 error "failed to dd write from $file"
409 check_lpcc_state $file "readwrite"
411 # non-root user is forbidden to access PCC file directly
412 lpcc_path=$(lpcc_fid2path $hsm_root $file)
413 do_facet $SINGLEAGT $RUNAS touch $lpcc_path &&
414 error "non-root user can touch access PCC file $lpcc_path"
415 do_facet $SINGLEAGT $RUNAS dd if=$lpcc_path of=/dev/null bs=1024 \
416 count=1 && error "non-root user can read PCC file $lpcc_path"
417 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$lpcc_path bs=1024 \
418 count=1 && error "non-root user can write PCC file $lpcc_path"
420 do_facet $SINGLEAGT $RUNAS $LFS pcc detach $file ||
421 error "failed to detach file $file"
422 wait_request_state $(path2fid $file) REMOVE SUCCEED
423 check_lpcc_state $file "none"
425 run_test 1f "Test auto RW-PCC cache with non-root user"
428 local loopfile="$TMP/$tfile"
429 local mntpt="/mnt/pcc.$tdir"
430 local hsm_root="$mntpt/$tdir"
431 local file=$DIR/$tfile
433 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
434 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
437 dd if=/dev/zero of=$file bs=1024 count=1 ||
438 error "failed to dd write to $file"
439 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 &&
440 error "non-root user can dd write to $file"
441 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
442 error "failed to attach file $file"
443 check_lpcc_state $file "readwrite"
444 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 &&
445 error "non-root user can dd write to $file"
446 chmod 777 $file || error "chmod 777 $file failed"
447 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
448 error "non-root user cannot write $file with permission (777)"
450 do_facet $SINGLEAGT $RUNAS $LFS pcc detach $file &&
451 error "non-root user or non owner can detach $file"
452 chown $RUNAS_ID $file || error "chown $RUNAS_ID $file failed"
453 do_facet $SINGLEAGT $RUNAS $LFS pcc detach $file ||
454 error "failed to detach file $file"
455 check_lpcc_state $file "none"
456 wait_request_state $(path2fid $file) REMOVE SUCCEED
457 do_facet $SINGLEAGT $RUNAS dd if=$file of=/dev/null bs=1024 count=1 ||
458 error "non-root user cannot read to $file with permisson (777)"
460 run_test 1g "General permission test for RW-PCC"
463 # When a process created a LPCC file and holding the open,
464 # another process on the same client should be able to open the file.
468 local agt_facet=$SINGLEAGT
469 local loopfile="$TMP/$tfile"
470 local mntpt="/mnt/pcc.$tdir"
471 local hsm_root="$mntpt/$tdir"
472 local agt_host=$(facet_active_host $SINGLEAGT)
474 ! is_project_quota_supported &&
475 skip "project quota is not supported" && return
478 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
479 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
481 file=$DIR/$tdir/multiop
485 do_facet $SINGLEAGT $LFS project -sp $project_id $DIR/$tdir ||
486 error "failed to set project quota"
487 rmultiop_start $agt_host $file O_c || error "open $file failed"
488 # HSM released exists archived status
489 check_hsm_flags $file "0x0000000d"
490 do_facet $SINGLEAGT "echo -n multiopen_data > $file" ||
491 error "failed to echo multiopen_data to $file"
493 lpcc_path=$(lpcc_fid2path $hsm_root $file)
494 do_facet $SINGLEAGT ls -l $lpcc_path ||
495 error "failed to ls $lpcc_path"
496 check_lpcc_data $SINGLEAGT $lpcc_path $file "multiopen_data"
497 # HSM released exists archived status
498 check_hsm_flags $file "0x0000000d"
500 do_facet $SINGLEAGT $LFS pcc detach $file ||
501 error "failed to detach $file"
502 rmultiop_stop $agt_host || error "close $file failed"
504 run_test 2a "Test multi open when creating"
506 get_remote_client() {
507 current_id=$(do_facet $SINGLEAGT hostname)
508 for client in ${CLIENTS//,/ }
510 r_id=$(do_node $client hostname)
511 if [ $r_id != $current_id ]; then
519 # When a process created a LPCC file and holding the open, another
520 # process on the different client should be able to open the file
521 # and perform IO on the file.
524 local agt_facet=$SINGLEAGT
525 local agt_host=$(facet_active_host $SINGLEAGT)
526 local loopfile="$TMP/$tfile"
527 local mntpt="/mnt/pcc.$tdir"
528 local hsm_root="$mntpt/$tdir"
530 needclients 2 || return 0
532 remote_client=$(get_remote_client)
535 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
536 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
538 file=$DIR/$tdir/multiop
542 do_facet $SINGLEAGT "echo -n file_data > $file"
543 do_facet $SINGLEAGT lfs pcc attach -i $HSM_ARCHIVE_NUMBER \
544 $file || error "PCC attach $file failed"
545 check_lpcc_state $file "readwrite"
547 rmultiop_start $agt_host $file O_c || error "open $file failed"
549 do_node $remote_client "echo -n multiopen_data > $file"
551 # PCC cached file should be automatically detached
552 check_lpcc_state $file "none"
554 check_file_data $SINGLEAGT $file "multiopen_data"
555 rmultiop_stop $agt_host || error "close $file failed"
556 check_file_data $SINGLEAGT $file "multiopen_data"
558 do_node $remote_client cat $file || error \
559 "cat $file on remote client failed"
560 do_node $remote_client echo -n "multiopen_data" > $file \
561 || error "write $file on remote client failed"
563 run_test 2b "Test multi remote open when creating"
566 local agt_host=$(facet_active_host $SINGLEAGT)
567 local loopfile="$TMP/$tfile"
568 local mntpt="/mnt/pcc.$tdir"
569 local hsm_root="$mntpt/$tdir"
570 local file=$DIR/$tdir/$tfile
571 local file2=$DIR2/$tdir/$tfile
574 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
575 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
580 do_facet $SINGLEAGT "echo -n file_data > $file"
581 do_facet $SINGLEAGT lfs pcc attach -i $HSM_ARCHIVE_NUMBER \
582 $file || error "PCC attach $file failed"
583 check_lpcc_state $file "readwrite"
585 rmultiop_start $agt_host $file O_c || error "open $file failed"
587 echo -n multiopen_data > $file2
589 # PCC cached file should be automatically detached
590 check_lpcc_state $file "none"
592 check_file_data $SINGLEAGT $file "multiopen_data"
593 rmultiop_stop $agt_host || error "close $file failed"
594 check_file_data $SINGLEAGT $file "multiopen_data"
596 cat $file2 || error "cat $file on mount $MOUNT2 failed"
597 echo -n "multiopen_data" > $file2 ||
598 error "write $file on mount $MOUNT2 failed"
600 run_test 2c "Test multi open on different mount points when creating"
603 local file=$DIR/$tdir/$tfile
605 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
606 setup_pcc_mapping $SINGLEAGT \
607 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0"
609 mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir failed"
610 dd if=/dev/zero of=$file bs=1024 count=1 ||
611 error "failed to dd write to $file"
613 echo "Start to attach/detach the file: $file"
614 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
615 error "failed to attach file $file"
616 check_lpcc_state $file "readwrite"
617 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
618 error "failed to detach file $file"
619 check_lpcc_state $file "none"
621 echo "Repeat to attach/detach the same file: $file"
622 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
623 error "failed to attach file $file"
624 check_lpcc_state $file "readwrite"
625 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
626 error "failed to detach file $file"
627 check_lpcc_state $file "none"
629 run_test 3a "Repeat attach/detach operations"
633 local file=$DIR/$tdir/$tfile
635 needclients 3 || return 0
637 # Start all of the copytools and setup PCC
638 for n in $(seq $AGTCOUNT); do
639 copytool setup -f agt$n -a $n -m $MOUNT
640 setup_pcc_mapping agt$n "projid={100}\ rwid=$n\ auto_attach=0"
643 mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir failed"
644 dd if=/dev/zero of=$file bs=1024 count=1 ||
645 error "failed to dd write to $file"
647 echo "Start to attach/detach $file on $agt1_HOST"
648 do_facet agt1 $LFS pcc attach -i 1 $file ||
649 error "failed to attach file $file"
650 check_lpcc_state $file "readwrite" agt1
651 do_facet agt1 $LFS pcc detach -k $file ||
652 error "failed to detach file $file"
653 check_lpcc_state $file "none" agt1
655 echo "Repeat to attach/detach $file on $agt2_HOST"
656 do_facet agt2 $LFS pcc attach -i 2 $file ||
657 error "failed to attach file $file"
658 check_lpcc_state $file "readwrite" agt2
659 do_facet agt2 $LFS pcc detach -k $file ||
660 error "failed to detach file $file"
661 check_lpcc_state $file "none" agt2
663 echo "Try attach on two agents"
664 do_facet agt1 $LFS pcc attach -i 1 $file ||
665 error "failed to attach file $file"
666 check_lpcc_state $file "readwrite" agt1
667 do_facet agt2 $LFS pcc attach -i 2 $file ||
668 error "failed to attach file $file"
669 check_lpcc_state $file "readwrite" agt2
670 # The later attach PCC agent should succeed,
671 # the former agent should be detached automatically.
672 check_lpcc_state $file "none" agt1
673 do_facet agt2 $LFS pcc detach -k $file ||
674 error "failed to detach file $file"
675 check_lpcc_state $file "none" agt2
677 run_test 3b "Repeat attach/detach operations on multiple clients"
681 local loopfile="$TMP/$tfile"
682 local mntpt="/mnt/pcc.$tdir"
683 local hsm_root="$mntpt/$tdir"
685 ! is_project_quota_supported &&
686 skip "project quota is not supported" && return
689 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
690 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
693 mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir failed"
694 lfs project -sp $project_id $DIR/$tdir ||
695 error "lfs project -sp $project_id $DIR/$tdir failed"
697 # mmap_sanity tst7 failed on the local ext4 filesystem.
698 # It seems that Lustre filesystem does special process for tst 7.
699 # Thus, we exclude tst7 from the PCC testing.
700 # There is a mmap problem for PCC when multiple clients read/write
701 # on a shared mmapped file. Thus, we exclude mmap_sanity tst6 from
703 $LUSTRE/tests/mmap_sanity -d $DIR/$tdir -m $DIR2/$tdir -e 6 -e 7 ||
704 error "mmap_sanity test failed"
707 rm -rf $DIR/$tdir || error "failed to remove $DIR/$tdir"
709 run_test 4 "Auto cache test for mmap"
712 local file=$DIR/$tfile
713 local loopfile="$TMP/$tfile"
714 local mntpt="/mnt/pcc.$tdir"
715 local hsm_root="$mntpt/$tdir"
717 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
718 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
721 do_facet $SINGLEAGT "echo -n attach_mmap_data > $file" ||
722 error "echo $file failed"
724 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
725 error "failed to attach file $file"
726 check_lpcc_state $file "readwrite"
728 local content=$($MMAP_CAT $file)
730 [[ $content == "attach_mmap_data" ]] ||
731 error "mmap cat data mismatch: $content"
733 $LFS hsm_restore $file || error "failed to restore $file"
734 wait_request_state $(path2fid $file) RESTORE SUCCEED
735 check_lpcc_state $file "none"
737 content=$($MMAP_CAT $file)
738 [[ $content == "attach_mmap_data" ]] ||
739 error "mmap cat data mismatch: $content"
741 run_test 5 "Mmap & cat a RW-PCC cached file"
744 local loopfile="$TMP/$tfile"
745 local mntpt="/mnt/pcc.$tdir"
746 local hsm_root="$mntpt/$tdir"
747 local file=$DIR/$tfile
750 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
751 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
754 echo -n mmap_write_data > $file || error "echo write $file failed"
755 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
756 error "failed to attach file $file"
757 check_lpcc_state $file "readwrite"
759 do_facet $SINGLEAGT $MULTIOP $file OSMWUc ||
760 error "could not mmap $file"
761 check_lpcc_state $file "readwrite"
762 content=$(do_facet $SINGLEAGT $MMAP_CAT $file)
763 # After mmap write via multiop, the first character of each page
765 [[ $content == "nmap_write_data" ]] ||
766 error "mmap write data mismatch: $content"
767 check_lpcc_state $file "readwrite"
769 do_facet $SINGLEAGT $LFS pcc detach $file ||
770 error "failed to detach file $file"
771 wait_request_state $(path2fid $file) REMOVE SUCCEED
773 content=$(do_facet $SINGLEAGT $MMAP_CAT $file)
774 [[ $content == "nmap_write_data" ]] ||
775 error "mmap write data mismatch: $content"
777 run_test 6 "Test mmap write on RW-PCC "
780 local loopfile="$TMP/$tfile"
781 local mntpt="/mnt/pcc.$tdir"
782 local hsm_root="$mntpt/$tdir"
783 local file=$DIR/$tfile
786 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
787 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
791 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
792 error "failed to attach file $file"
793 check_lpcc_state $file "readwrite"
794 check_file_data $SINGLEAGT $file "QQQQQ"
795 # define OBD_FAIL_LLITE_PCC_DETACH_MKWRITE 0x1412
796 do_facet $SINGLEAGT $LCTL set_param fail_loc=0x1412
797 # HSM released exists archived status
798 check_hsm_flags $file "0x0000000d"
800 # multiop mmap write increase the first character of each page with 1
801 do_facet $SINGLEAGT $MULTIOP $file OSMWUc ||
802 error "mmap write $file failed"
803 check_lpcc_state $file "none"
804 content=$(do_facet $SINGLEAGT $MMAP_CAT $file)
805 [[ $content == "RQQQQ" ]] || error "data mismatch: $content"
807 run_test 7a "Fake file detached between fault() and page_mkwrite() for RW-PCC"
810 local loopfile="$TMP/$tfile"
811 local mntpt="/mnt/pcc.$tdir"
812 local hsm_root="$mntpt/$tdir"
813 local file=$DIR/$tfile
817 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
818 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
819 setup_pcc_mapping $SINGLEAGT \
820 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0"
823 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
824 error "failed to attach file $file"
825 check_lpcc_state $file "readwrite"
826 check_file_data $SINGLEAGT $file "QQQQQ"
827 # define OBD_FAIL_LLITE_PCC_MKWRITE_PAUSE 0x1413
828 do_facet $SINGLEAGT $LCTL set_param fail_loc=0x1413 fail_val=20
829 # HSM released exists archived status
830 check_hsm_flags $file "0x0000000d"
832 # multiop mmap write increases the first character of each page with 1
833 do_facet $SINGLEAGT $MULTIOP $file OSMWUc &
837 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
838 error "failed to detach file $file"
840 wait $pid || error "multiop mmap write failed"
841 check_lpcc_state $file "none"
842 content=$(do_facet $SINGLEAGT $MMAP_CAT $file)
843 [[ $content == "RQQQQ" ]] || error "data mismatch: $content"
845 run_test 7b "Test the race with concurrent mkwrite and detach"
848 local loopfile="$TMP/$tfile"
849 local mntpt="/mnt/pcc.$tdir"
850 local hsm_root="$mntpt/$tdir"
851 local file=$DIR/$tfile
853 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
854 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
858 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
859 error "failed to attach file $file"
860 check_lpcc_state $file "readwrite"
861 check_file_data $SINGLEAGT $file "QQQQQ"
863 # define OBD_FAIL_LLITE_PCC_FAKE_ERROR 0x1411
864 do_facet $SINGLEAGT $LCTL set_param fail_loc=0x1411
865 do_facet $SINGLEAGT "echo -n ENOSPC_write > $file"
866 # Above write will return -ENOSPC failure and retry the IO on normal
867 # IO path. It will restore the HSM released file.
868 check_lpcc_state $file "none"
869 check_file_data $SINGLEAGT $file "ENOSPC_write"
871 run_test 8 "Test fake -ENOSPC tolerance for RW-PCC"
874 local loopfile="$TMP/$tfile"
875 local mntpt="/mnt/pcc.9a"
876 local hsm_root="$mntpt/$tdir"
877 local file=$DIR/$tfile
879 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
881 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMVER" -h "$hsm_root"
883 do_facet $SINGLEAGT $LCTL pcc list $MOUNT
885 touch $file || error "touch $file failed"
886 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
887 error "fail to attach $file"
888 check_lpcc_state $file "readwrite"
889 # write 60M data, it is larger than the capacity of PCC backend
890 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1M count=60 ||
891 error "fail to dd write $file"
892 check_lpcc_state $file "none"
893 check_file_size $SINGLEAGT $file 62914560
895 run_test 9 "Test -ENOSPC tolerance on loop PCC device for RW-PCC"
897 test_usrgrp_quota() {
898 local loopfile="$TMP/$tfile"
899 local mntpt="/mnt/pcc.$tdir"
900 local hsm_root="$mntpt/$tdir"
904 [[ $ug == "g" ]] && id=$RUNAS_GID
906 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
907 do_facet $SINGLEAGT quotacheck -c$ug $mntpt ||
908 error "quotacheck -c$ug $mntpt failed"
909 do_facet $SINGLEAGT quotaon -$ug $mntpt ||
910 error "quotaon -$ug $mntpt failed"
911 do_facet $SINGLEAGT setquota -$ug $id 0 20480 0 0 $mntpt ||
912 error "setquota -$ug $id on $mntpt failed"
913 do_facet $SINGLEAGT repquota -${ug}vs $mntpt
915 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMVER" -h "$hsm_root"
917 do_facet $SINGLEAGT $LCTL pcc list $MOUNT
919 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
921 local file1=$DIR/$tdir/${ug}quotaA
922 local file2=$DIR/$tdir/${ug}quotaB
924 dd if=/dev/zero of=$file1 bs=1M count=15 ||
925 error "dd write $file1 failed"
926 dd if=/dev/zero of=$file2 bs=1M count=15 ||
927 error "dd write $file2 failed"
928 chown $RUNAS_ID:$RUNAS_GID $file1 ||
929 error "chown $RUNAS_ID:$RUNAS_GID $file1 failed"
930 chown $RUNAS_ID:$RUNAS_GID $file2 ||
931 error "chown $RUNAS_ID:$RUNAS_GID $file2 failed"
932 do_facet $SINGLEAGT $RUNAS $LFS pcc attach -i $HSM_ARCHIVE_NUMBER \
933 $file1 || error "attach $file1 failed"
934 do_facet $SINGLEAGT $RUNAS $LFS pcc attach -i $HSM_ARCHIVE_NUMBER \
935 $file2 && error "attach $file2 should fail due to quota limit"
936 check_lpcc_state $file1 "readwrite"
937 check_lpcc_state $file2 "none"
939 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file1 bs=1M count=30 ||
940 error "dd write $file1 failed"
941 # -EDQUOT error should be tolerated via fallback to normal Lustre path.
942 check_lpcc_state $file1 "none"
943 do_facet $SINGLEAGT $LFS pcc detach -k $file1 ||
944 error "failed to detach file $file"
949 test_usrgrp_quota "u"
951 run_test 10a "Test RW-PCC with user quota on loop PCC device"
954 test_usrgrp_quota "g"
956 run_test 10b "Test RW-PCC with group quota on loop PCC device"
959 local loopfile="$TMP/$tfile"
960 local mntpt="/mnt/pcc.$tdir"
961 local hsm_root="$mntpt/$tdir"
962 local file=$DIR/$tfile
966 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
967 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
970 do_facet $SINGLEAGT "echo -n QQQQQ > $file"
971 lpcc_path=$(lpcc_fid2path $hsm_root $file)
972 lpcc_dir=$(dirname $lpcc_path)
973 echo "Lustre file: $file LPCC dir: $lpcc_dir"
974 do_facet $SINGLEAGT mkdir -p $lpcc_dir ||
975 error "mkdir -p $lpcc_dir failed"
976 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
977 error "failed to attach $file"
978 check_lpcc_state $file "readwrite"
979 check_file_data $SINGLEAGT $file "QQQQQ"
980 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
981 error "failed to detach $file"
982 rm $file || error "rm $file failed"
984 # The parent directory of the PCC file is immutable
985 do_facet $SINGLEAGT "echo -n immutable_dir > $file"
986 lpcc_path=$(lpcc_fid2path $hsm_root $file)
987 lpcc_dir=$(dirname $lpcc_path)
988 echo "Lustre file: $file LPCC dir: $lpcc_dir"
989 do_facet $SINGLEAGT mkdir -p $lpcc_dir ||
990 error "mkdir -p $lpcc_dir failed"
991 do_facet $SINGLEAGT chattr +i $lpcc_dir ||
992 error "chattr +i $lpcc_dir failed"
993 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file &&
994 error "attach $file with immutable directory should be failed"
995 do_facet $SINGLEAGT chattr -i $lpcc_dir ||
996 error "chattr -i $lpcc_dir failed"
997 rm $file || error "rm $file failed"
999 # The PCC file path is set to a directory
1000 do_facet $SINGLEAGT "echo -n pcc_file_path_is_dir > $file"
1001 lpcc_path=$(lpcc_fid2path $hsm_root $file)
1002 do_facet $SINGLEAGT mkdir -p $lpcc_path ||
1003 error "mkdir -p $lpcc_path failed"
1004 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file &&
1005 error "attach $file should fail as PCC path is a directory"
1006 rm $file || error "rm $file failed"
1008 run_test 11 "Test attach fault injection with simulated PCC file path"
1011 local file=$DIR/$tfile
1012 local hsm_root=$(hsm_root)
1016 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1017 setup_pcc_mapping $SINGLEAGT \
1018 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0"
1020 echo -n race_rw_attach_hsmremove > $file
1021 lpcc_path=$(lpcc_fid2path $hsm_root $file)
1022 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
1023 error "attach $file failed"
1024 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1025 error "detach $file failed"
1026 # HSM released exists archived status
1027 check_hsm_flags $file "0x0000000d"
1028 # define OBD_FAIL_LLITE_PCC_ATTACH_PAUSE 0x1414
1029 do_facet $SINGLEAGT $LCTL set_param fail_loc=0x1414 fail_val=20
1030 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file &
1032 $LFS hsm_state $file
1034 wait_request_state $(path2fid $file) RESTORE SUCCEED
1035 $LFS hsm_remove $file || error "hsm remove $file failed"
1036 wait $pid && error "RW-PCC attach $file should fail"
1037 do_facet $SINGLEAGT "[ -f $lpcc_path ]" &&
1038 error "RW-PCC cached file '$lpcc_path' should be removed"
1042 run_test 12 "RW-PCC attach races with concurrent HSM remove"
1045 local idstr="${1}id"
1046 local rule="${idstr}={$2}"
1048 local file=$DIR/$tdir/$tfile
1050 setup_pcc_mapping $SINGLEAGT \
1051 "$rule\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0"
1052 $LCTL pcc list $MOUNT
1054 do_facet $SINGLEAGT mkdir -p $DIR/$tdir
1055 chmod 777 $DIR/$tdir || error "chmod 0777 $DIR/$tdir failed"
1057 rm -f $file || error "rm $file failed"
1058 do_facet $SINGLEAGT $myRUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1059 error "failed to dd write to $file"
1060 check_lpcc_state $file "readwrite"
1061 do_facet $SINGLEAGT $myRUNAS dd if=$file of=/dev/null bs=1024 count=1 ||
1062 error "failed to dd read from $file"
1063 do_facet $SINGLEAGT $myRUNAS $TRUNCATE $file 256 ||
1064 error "failed to truncate $file"
1065 do_facet $SINGLEAGT $myRUNAS $TRUNCATE $file 2048 ||
1066 error "failed to truncate $file"
1067 do_facet $SINGLEAGT $myRUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1068 error "failed to dd write from $file"
1069 check_lpcc_state $file "readwrite"
1071 do_facet $SINGLEAGT $myRUNAS $LFS pcc detach $file ||
1072 error "failed to detach file $file"
1073 wait_request_state $(path2fid $file) REMOVE SUCCEED
1074 check_lpcc_state $file "none"
1080 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1081 test_rule_id "u" "500" "runas -u 500"
1082 test_rule_id "g" "500" "runas -u 500 -g 500"
1084 run_test 13a "Test auto RW-PCC create caching for UID/GID rule"
1089 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1090 setup_pcc_mapping $SINGLEAGT \
1091 "fname={*.h5\ suffix.*\ Mid*dle}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0"
1092 $LCTL pcc list $MOUNT
1094 do_facet $SINGLEAGT mkdir -p $DIR/$tdir
1095 chmod 777 $DIR/$tdir || error "chmod 0777 $DIR/$tdir failed"
1097 file=$DIR/$tdir/prefix.h5
1098 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1024 count=1 ||
1099 error "failed to dd write to $file"
1100 check_lpcc_state $file "readwrite"
1101 do_facet $SINGLEAGT $myRUNAS $LFS pcc detach -k $file ||
1102 error "failed to detach file $file"
1103 check_lpcc_state $file "none"
1104 rm $file || error "rm $file failed"
1106 file=$DIR/$tdir/suffix.doc
1107 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1108 error "failed to dd write to $file"
1109 check_lpcc_state $file "readwrite"
1110 do_facet $SINGLEAGT $myRUNAS $LFS pcc detach -k $file ||
1111 error "failed to detach file $file"
1112 check_lpcc_state $file "none"
1113 rm $file || error "rm $file failed"
1115 file=$DIR/$tdir/MidPADdle
1116 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1117 error "failed to dd write to $file"
1118 check_lpcc_state $file "readwrite"
1119 do_facet $SINGLEAGT $myRUNAS $LFS pcc detach -k $file ||
1120 error "failed to detach file $file"
1121 check_lpcc_state $file "none"
1122 rm $file || error "rm $file failed"
1124 file=$DIR/$tdir/Midpad
1125 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1126 error "failed to dd write to $file"
1127 check_lpcc_state $file "none"
1128 rm $file || error "rm $file failed"
1130 run_test 13b "Test auto RW-PCC create caching for file name with wildcard"
1135 local loopfile="$TMP/$tfile"
1136 local mntpt="/mnt/pcc.$tdir"
1137 local hsm_root="$mntpt/$tdir"
1139 ! is_project_quota_supported &&
1140 echo "Skip project quota is not supported" && return 0
1142 enable_project_quota
1143 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1144 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1145 setup_pcc_mapping $SINGLEAGT \
1146 "projid={100\ 200}\&fname={*.h5},uid={500}\&gid={1000}\ rwid=$HSM_ARCHIVE_NUMBER"
1147 $LCTL pcc list $MOUNT
1148 do_facet $SINGLEAGT mkdir -p $DIR/$tdir
1149 chmod 777 $DIR/$tdir || error "chmod 0777 $DIR/$tdir failed"
1151 mkdir -p $DIR/$tdir/proj || error "mkdir $DIR/$tdir/proj failed"
1152 mkdir -p $DIR/$tdir/proj2 || error "mkdir $DIR/$tdir/proj2 failed"
1153 $LFS project -sp 100 $DIR/$tdir/proj ||
1154 error "failed to set project for $DIR/$tdir/proj"
1155 $LFS project -sp 200 $DIR/$tdir/proj2 ||
1156 error "failed to set project for $DIR/$tdir/proj2"
1158 file=$DIR/$tdir/proj/notcache
1159 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1024 count=1 ||
1160 error "failed to dd write to $file"
1161 check_lpcc_state $file "none"
1162 rm $file || error "rm $file failed"
1164 file=$DIR/$tdir/proj/autocache.h5
1165 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1024 count=1 ||
1166 error "failed to dd write to $file"
1167 check_lpcc_state $file "readwrite"
1168 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1169 error "failed to detach $file"
1170 rm $file || error "rm $file failed"
1172 file=$DIR/$tdir/proj2/notcache
1173 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1024 count=1 ||
1174 error "failed to dd write to $file"
1175 check_lpcc_state $file "none"
1176 rm $file || error "rm $file failed"
1178 file=$DIR/$tdir/proj2/autocache.h5
1179 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1024 count=1 ||
1180 error "failed to dd write to $file"
1181 check_lpcc_state $file "readwrite"
1182 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1183 error "failed to detach $file"
1184 rm $file || error "rm $file failed"
1186 file=$DIR/$tdir/ugidcache
1187 myRUNAS="runas -u 500 -g 1000"
1188 do_facet $SINGLEAGT $myRUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1189 error "failed to dd write to $file"
1190 check_lpcc_state $file "readwrite"
1191 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1192 error "failed to detach $file"
1193 rm $file || error "rm $file failed"
1195 run_test 13c "Check auto RW-PCC create caching for UID/GID/ProjID/fname rule"
1198 local file=$DIR/$tdir/$tfile
1200 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1201 setup_pcc_mapping $SINGLEAGT \
1202 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0"
1204 mkdir -p $DIR/$tdir || error "mkdir -p $DIR/$tdir failed"
1205 do_facet $SINGLEAGT "echo -n autodetach_data > $file"
1206 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER \
1207 $file || error "PCC attach $file failed"
1208 check_lpcc_state $file "readwrite"
1210 # Revoke the layout lock, the PCC-cached file will be
1211 # detached automatically.
1212 do_facet $SINGLEAGT $LCTL \
1213 set_param ldlm.namespaces.*mdc*.lru_size=clear
1214 check_file_data $SINGLEAGT $file "autodetach_data"
1215 check_lpcc_state $file "none"
1217 run_test 14 "Revocation of the layout lock should detach the file automatically"
1220 local loopfile="$TMP/$tfile"
1221 local mntpt="/mnt/pcc.$tdir"
1222 local hsm_root="$mntpt/$tdir"
1223 local file=$DIR/$tdir/$tfile
1225 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1226 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1229 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
1230 chmod 777 $DIR/$tdir || error "chmod 777 $DIR/$tdir failed"
1232 echo "Check open attach for non-root user"
1233 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1234 error "failed to dd write to $file"
1235 do_facet $SINGLEAGT $RUNAS $LFS pcc attach -i $HSM_ARCHIVE_NUMBER \
1236 $file || error "failed to attach file $file"
1237 do_facet $SINGLEAGT $RUNAS $LFS pcc state $file
1238 check_lpcc_state $file "readwrite" $SINGLEAGT "$RUNAS"
1239 # Revoke the layout lock, the PCC-cached file will be
1240 # detached automatically.
1241 do_facet $SINGLEAGT $LCTL \
1242 set_param ldlm.namespaces.*mdc*.lru_size=clear
1243 check_lpcc_state $file "readwrite" $SINGLEAGT "$RUNAS"
1244 # Detach the file but keep the cache , as the file layout generation
1245 # is not changed, so the file is still valid cached in PCC, and can
1246 # be reused from PCC cache directly.
1247 do_facet $SINGLEAGT $RUNAS $LFS pcc detach -k $file ||
1248 error "PCC detach $file failed"
1249 check_lpcc_state $file "readwrite" $SINGLEAGT "$RUNAS"
1250 do_facet $SINGLEAGT $RUNAS $LFS pcc detach $file ||
1251 error "PCC detach $file failed"
1252 rm $file || error "rm $file failed"
1254 echo "check open attach for root user"
1255 do_facet $SINGLEAGT "echo -n autoattach_data > $file"
1256 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER \
1257 $file || error "PCC attach $file failed"
1258 check_lpcc_state $file "readwrite"
1260 # Revoke the layout lock, the PCC-cached file will be
1261 # detached automatically.
1262 do_facet $SINGLEAGT $LCTL \
1263 set_param ldlm.namespaces.*mdc*.lru_size=clear
1264 check_file_data $SINGLEAGT $file "autoattach_data"
1265 check_lpcc_state $file "readwrite"
1267 # Detach the file with -k option, as the file layout generation
1268 # is not changed, so the file is still valid cached in PCC,
1269 # and can be reused from PCC cache directly.
1270 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1271 error "PCC detach $file failed"
1272 check_lpcc_state $file "readwrite"
1273 # HSM released exists archived status
1274 check_hsm_flags $file "0x0000000d"
1275 check_file_data $SINGLEAGT $file "autoattach_data"
1277 # HSM restore the PCC cached file, the layout generation
1278 # was changed, so the file can not be auto attached.
1279 $LFS hsm_restore $file || error "failed to restore $file"
1280 wait_request_state $(path2fid $file) RESTORE SUCCEED
1281 check_lpcc_state $file "none"
1282 # HSM exists archived status
1283 check_hsm_flags $file "0x00000009"
1286 run_test 15 "Test auto attach at open when file is still valid cached"
1289 local loopfile="$TMP/$tfile"
1290 local mntpt="/mnt/pcc.$tdir"
1291 local hsm_root="$mntpt/$tdir"
1292 local file=$DIR/$tfile
1295 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1296 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1299 do_facet $SINGLEAGT "echo -n detach_data > $file"
1300 lpcc_path=$(lpcc_fid2path $hsm_root $file)
1301 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER \
1302 $file || error "PCC attach $file failed"
1303 check_lpcc_state $file "readwrite"
1304 # HSM released exists archived status
1305 check_hsm_flags $file "0x0000000d"
1307 echo "Test for reusing valid PCC cache"
1308 # Valid PCC cache can be reused
1309 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1310 error "PCC detach $file failed"
1311 check_lpcc_state $file "readwrite"
1312 # HSM released exists archived status
1313 check_hsm_flags $file "0x0000000d"
1315 echo "Test for the default detach"
1316 # Permanent detach by default, it will remove the PCC copy
1317 do_facet $SINGLEAGT $LFS pcc detach $file ||
1318 error "PCC detach $file failed"
1319 wait_request_state $(path2fid $file) REMOVE SUCCEED
1320 check_lpcc_state $file "none"
1321 # File is removed from PCC backend
1322 check_hsm_flags $file "0x00000000"
1323 do_facet $SINGLEAGT "[ -f $lpcc_path ]" &&
1324 error "RW-PCC cached file '$lpcc_path' should be removed"
1328 run_test 16 "Test detach with different options"
1331 local agt_host=$(facet_active_host $SINGLEAGT)
1332 local loopfile="$TMP/$tfile"
1333 local mntpt="/mnt/pcc.$tdir"
1334 local hsm_root="$mntpt/$tdir"
1335 local file=$DIR/$tfile
1337 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1338 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1339 setup_pcc_mapping $SINGLEAGT \
1340 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ open_attach=0\ stat_attach=0"
1342 do_facet $SINGLEAGT $LCTL pcc list $MOUNT
1344 do_facet $SINGLEAGT "echo -n layout_refresh_data > $file"
1345 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
1346 error "PCC attach $file failed"
1347 check_lpcc_state $file "readwrite"
1349 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1350 error "PCC detach $file failed"
1351 check_lpcc_state $file "none"
1353 # Truncate should attach the file into PCC automatically
1354 # as the PCC copy is still valid.
1355 echo "Verify auto attach during IO for truncate"
1356 do_facet $SINGLEAGT $TRUNCATE $file 4 || error "truncate $file failed"
1357 check_lpcc_state $file "readwrite"
1359 echo "Verify auto attach during IO for read/write"
1360 rmultiop_start $agt_host $file O_r || error "open $file failed"
1363 # Revoke the layout lock, the PCC-cached file will be
1364 # detached automatically.
1365 do_facet $SINGLEAGT $LCTL \
1366 set_param ldlm.namespaces.*mdc*.lru_size=clear
1368 check_lpcc_state $file "none"
1369 rmultiop_stop $agt_host || error "close $file failed"
1371 check_lpcc_state $file "readwrite"
1373 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1374 error "PCC detach $file failed"
1375 check_lpcc_state $file "none"
1377 run_test 17 "Test auto attach for layout refresh"
1380 local agt_host=$(facet_active_host $SINGLEAGT)
1381 local loopfile="$TMP/$tfile"
1382 local mntpt="/mnt/pcc.$tdir"
1383 local hsm_root="$mntpt/$tdir"
1384 local file=$DIR/$tfile
1388 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1389 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1390 setup_pcc_mapping $SINGLEAGT \
1391 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER"
1393 do_facet $SINGLEAGT $LCTL pcc list $MOUNT
1394 do_facet $SINGLEAGT dd if=/dev/urandom of=$file bs=1M count=4 ||
1395 error "failed to write $file"
1396 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
1397 error "failed to attach $file"
1398 do_facet $SINGLEAGT $LFS pcc state $file
1399 check_lpcc_state $file "readwrite"
1400 do_facet $SINGLEAGT $LFS pcc detach --keep $file ||
1401 error "failed to detach $file"
1402 do_facet $SINGLEAGT $LFS pcc state $file
1403 $CHECKSTAT -s 4194304 $file
1404 dd if=/dev/zero of=$DIR2/$tfile seek=1k bs=1k count=1 ||
1405 error "failed to write $DIR2/$tfile"
1406 oldmd5=$(md5sum $DIR2/$tfile | awk '{print $1}')
1407 $CHECKSTAT -s 1049600 $DIR2/$tfile || error "$DIR2/$tfile size wrong"
1409 local lpcc_path=$(lpcc_fid2path $hsm_root $file)
1411 do_facet $SINGLEAGT $LFS pcc state $file
1412 check_file_size $SINGLEAGT $lpcc_path 4194304
1413 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
1414 error "failed to attach $file"
1415 check_lpcc_sizes $SINGLEAGT $lpcc_path $file 1049600
1416 newmd5=$(do_facet $SINGLEAGT md5sum $file | awk '{print $1}')
1417 [ "$oldmd5" == "$newmd5" ] || error "md5sum differ: $oldmd5 != $newmd5"
1418 do_facet $SINGLEAGT $LFS pcc detach $file ||
1419 error "failed to detach $file"
1421 run_test 18 "Verify size correctness after re-attach the file"
1424 local agt_host=$(facet_active_host $SINGLEAGT)
1425 local loopfile="$TMP/$tfile"
1426 local mntpt="/mnt/pcc.$tdir"
1427 local hsm_root="$mntpt/$tdir"
1428 local file=$DIR/$tfile
1430 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1431 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1432 setup_pcc_mapping $SINGLEAGT \
1433 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0"
1435 do_facet $SINGLEAGT "echo -n QQQQQ > $file" || error "echo $file failed"
1436 lpcc_path=$(lpcc_fid2path $hsm_root $file)
1437 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
1438 error "Failed to attach $file"
1439 check_lpcc_state $file "readwrite"
1440 check_lpcc_sizes $SINGLEAGT $file $lpcc_path 5
1441 do_facet $SINGLEAGT $LFS pcc detach --keep $file ||
1442 error "Failed to detach $file"
1443 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
1444 error "Failed to attach $file"
1445 check_lpcc_sizes $SINGLEAGT $file $lpcc_path 5
1446 do_facet $SINGLEAGT $LFS pcc detach --keep $file ||
1447 error "Failed to detach $file"
1449 run_test 19 "Verify the file re-attach works as expected"
1452 local agt_host=$(facet_active_host $SINGLEAGT)
1453 local loopfile="$TMP/$tfile"
1454 local mntpt="/mnt/pcc.$tdir"
1455 local hsm_root="$mntpt/$tdir"
1456 local file=$DIR/$tfile
1458 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1459 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1460 setup_pcc_mapping $SINGLEAGT \
1461 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER"
1463 do_facet $SINGLEAGT "echo -n QQQQQ > $file" ||
1464 error "echo $file failed"
1465 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
1466 error "Failed to attach $file"
1467 do_facet $SINGLEAGT "echo 3 > /proc/sys/vm/drop_caches"
1468 check_lpcc_state $file "readwrite"
1469 do_facet $SINGLEAGT "echo 3 > /proc/sys/vm/drop_caches"
1470 do_facet $SINGLEAGT "echo 3 > /proc/sys/vm/drop_caches"
1471 check_lpcc_state $file "readwrite"
1472 do_facet $SINGLEAGT $LFS pcc detach $file ||
1473 error "Failed to detach $file"
1475 run_test 20 "Auto attach works after the inode was once evicted from cache"
1478 check_and_cleanup_lustre