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 wait_request_state $(path2fid $file) REMOVE SUCCEED
273 check_lpcc_state $file "none"
274 # The file is removed from PCC
275 check_hsm_flags $file "0x00000000"
276 check_file_data $SINGLEAGT $file "attach_detach"
280 lpcc_rw_test true false
282 run_test 1a "Test manual lfs pcc attach with manual HSM restore"
285 lpcc_rw_test false false
287 run_test 1b "Test manual lfs pcc attach with restore on remote access"
290 lpcc_rw_test true true
292 run_test 1c "Test automated attach using Project ID with manual HSM restore"
295 lpcc_rw_test false true
297 run_test 1d "Test Project ID with remote access"
300 local file=$DIR/$tdir/$tfile
301 local hsm_root=$(hsm_root)
304 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
306 $LCTL pcc list $MOUNT
307 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
308 chmod 777 $DIR/$tdir || error "chmod 777 $DIR/$tdir failed"
310 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
311 error "failed to dd write to $file"
312 do_facet $SINGLEAGT $RUNAS $LFS pcc attach -i $HSM_ARCHIVE_NUMBER \
313 $file || error "failed to attach file $file"
314 check_lpcc_state $file "readwrite"
315 do_facet $SINGLEAGT $RUNAS dd if=$file of=/dev/null bs=1024 count=1 ||
316 error "failed to dd read from $file"
317 do_facet $SINGLEAGT $RUNAS $TRUNCATE $file 256 ||
318 error "failed to truncate $file"
319 do_facet $SINGLEAGT $RUNAS $TRUNCATE $file 2048 ||
320 error "failed to truncate $file"
321 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
322 error "failed to dd write to $file"
323 check_lpcc_state $file "readwrite"
325 do_facet $SINGLEAGT $RUNAS $LFS pcc detach -k $file ||
326 error "failed to detach file $file"
327 check_lpcc_state $file "none"
329 # non-root user is forbidden to access PCC file directly
330 lpcc_path=$(lpcc_fid2path $hsm_root $file)
331 do_facet $SINGLEAGT $RUNAS touch $lpcc_path &&
332 error "non-root user can touch access PCC file $lpcc_path"
333 do_facet $SINGLEAGT $RUNAS dd if=$lpcc_path of=/dev/null bs=1024 \
334 count=1 && error "non-root user can read PCC file $lpcc_path"
335 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$lpcc_path bs=1024 \
336 count=1 && error "non-root user can write PCC file $lpcc_path"
338 local perm=$(do_facet $SINGLEAGT stat -c %a $lpcc_path)
340 [[ $perm == "0" ]] || error "PCC file permission ($perm) is not zero"
342 do_facet $SINGLEAGT $RUNAS $LFS pcc attach -i $HSM_ARCHIVE_NUMBER \
343 $file || error "failed to attach file $file"
344 check_lpcc_state $file "readwrite"
346 do_facet $SINGLEAGT $RUNAS $LFS pcc detach $file ||
347 error "failed to detach file $file"
348 check_lpcc_state $file "none"
349 wait_request_state $(path2fid $file) REMOVE SUCCEED
351 run_test 1e "Test RW-PCC with non-root user"
355 local agt_facet=$SINGLEAGT
356 local hsm_root=$(hsm_root)
357 local file=$DIR/$tdir/$tfile
359 ! is_project_quota_supported &&
360 skip "project quota is not supported"
363 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
365 do_facet $SINGLEAGT mkdir -p $DIR/$tdir
366 chmod 777 $DIR/$tdir || error "chmod 0777 $DIR/$tdir failed"
367 $LFS project -sp $project_id $DIR/$tdir ||
368 error "failed to set project for $DIR/$tdir"
370 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
371 error "failed to dd write to $file"
373 check_lpcc_state $file "readwrite"
374 do_facet $SINGLEAGT $RUNAS dd if=$file of=/dev/null bs=1024 count=1 ||
375 error "failed to dd read from $file"
376 do_facet $SINGLEAGT $RUNAS $TRUNCATE $file 256 ||
377 error "failed to truncate $file"
378 do_facet $SINGLEAGT $RUNAS $TRUNCATE $file 2048 ||
379 error "failed to truncate $file"
380 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
381 error "failed to dd write from $file"
382 check_lpcc_state $file "readwrite"
384 # non-root user is forbidden to access PCC file directly
385 lpcc_path=$(lpcc_fid2path $hsm_root $file)
386 do_facet $SINGLEAGT $RUNAS touch $lpcc_path &&
387 error "non-root user can touch access PCC file $lpcc_path"
388 do_facet $SINGLEAGT $RUNAS dd if=$lpcc_path of=/dev/null bs=1024 \
389 count=1 && error "non-root user can read PCC file $lpcc_path"
390 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$lpcc_path bs=1024 \
391 count=1 && error "non-root user can write PCC file $lpcc_path"
393 do_facet $SINGLEAGT $RUNAS $LFS pcc detach $file ||
394 error "failed to detach file $file"
395 check_lpcc_state $file "none"
396 wait_request_state $(path2fid $file) REMOVE SUCCEED
398 run_test 1f "Test auto RW-PCC cache with non-root user"
401 local file=$DIR/$tfile
403 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
406 dd if=/dev/zero of=$file bs=1024 count=1 ||
407 error "failed to dd write to $file"
408 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 &&
409 error "non-root user can dd write to $file"
410 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
411 error "failed to attach file $file"
412 check_lpcc_state $file "readwrite"
413 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 &&
414 error "non-root user can dd write to $file"
415 chmod 777 $file || error "chmod 777 $file failed"
416 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
417 error "non-root user cannot write $file with permission (777)"
419 do_facet $SINGLEAGT $RUNAS $LFS pcc detach $file &&
420 error "non-root user or non owner can detach $file"
421 chown $RUNAS_ID $file || error "chown $RUNAS_ID $file failed"
422 do_facet $SINGLEAGT $RUNAS $LFS pcc detach $file ||
423 error "failed to detach file $file"
424 check_lpcc_state $file "none"
425 wait_request_state $(path2fid $file) REMOVE SUCCEED
426 do_facet $SINGLEAGT $RUNAS dd if=$file of=/dev/null bs=1024 count=1 ||
427 error "non-root user cannot read to $file with permisson (777)"
429 run_test 1g "General permission test for RW-PCC"
432 # When a process created a LPCC file and holding the open,
433 # another process on the same client should be able to open the file.
437 local agt_facet=$SINGLEAGT
438 local hsm_root=$(hsm_root)
439 local agt_host=$(facet_active_host $SINGLEAGT)
441 ! is_project_quota_supported &&
442 skip "project quota is not supported" && return
445 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
447 file=$DIR/$tdir/multiop
451 do_facet $SINGLEAGT $LFS project -sp $project_id $DIR/$tdir ||
452 error "failed to set project quota"
453 rmultiop_start $agt_host $file O_c || error "open $file failed"
454 # HSM released exists archived status
455 check_hsm_flags $file "0x0000000d"
456 do_facet $SINGLEAGT "echo -n multiopen_data > $file" ||
457 error "failed to echo multiopen_data to $file"
459 lpcc_path=$(lpcc_fid2path $hsm_root $file)
460 do_facet $SINGLEAGT ls -l $lpcc_path ||
461 error "failed to ls $lpcc_path"
462 check_lpcc_data $SINGLEAGT $lpcc_path $file "multiopen_data"
463 # HSM released exists archived status
464 check_hsm_flags $file "0x0000000d"
466 rmultiop_stop $agt_host || error "close $file failed"
468 run_test 2a "Test multi open when creating"
470 get_remote_client() {
471 current_id=$(do_facet $SINGLEAGT hostname)
472 for client in ${CLIENTS//,/ }
474 r_id=$(do_node $client hostname)
475 if [ $r_id != $current_id ]; then
483 # When a process created a LPCC file and holding the open, another
484 # process on the different client should be able to open the file
485 # and perform IO on the file.
488 local agt_facet=$SINGLEAGT
489 local hsm_root=$(hsm_root)
490 local agt_host=$(facet_active_host $SINGLEAGT)
492 needclients 2 || return 0
494 remote_client=$(get_remote_client)
497 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
499 file=$DIR/$tdir/multiop
503 do_facet $SINGLEAGT "echo -n file_data > $file"
504 do_facet $SINGLEAGT lfs pcc attach -i $HSM_ARCHIVE_NUMBER \
505 $file || error "PCC attach $file failed"
506 check_lpcc_state $file "readwrite"
508 rmultiop_start $agt_host $file O_c || error "open $file failed"
510 do_node $remote_client "echo -n multiopen_data > $file"
512 # PCC cached file should be automatically detached
513 check_lpcc_state $file "none"
515 check_file_data $SINGLEAGT $file "multiopen_data"
516 rmultiop_stop $agt_host || error "close $file failed"
517 check_file_data $SINGLEAGT $file "multiopen_data"
519 do_node $remote_client cat $file || error \
520 "cat $file on remote client failed"
521 do_node $remote_client echo -n "multiopen_data" > $file \
522 || error "write $file on remote client failed"
524 run_test 2b "Test multi remote open when creating"
527 local agt_host=$(facet_active_host $SINGLEAGT)
528 local file=$DIR/$tdir/$tfile
529 local file2=$DIR2/$tdir/$tfile
532 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
537 do_facet $SINGLEAGT "echo -n file_data > $file"
538 do_facet $SINGLEAGT lfs pcc attach -i $HSM_ARCHIVE_NUMBER \
539 $file || error "PCC attach $file failed"
540 check_lpcc_state $file "readwrite"
542 rmultiop_start $agt_host $file O_c || error "open $file failed"
544 echo -n multiopen_data > $file2
546 # PCC cached file should be automatically detached
547 check_lpcc_state $file "none"
549 check_file_data $SINGLEAGT $file "multiopen_data"
550 rmultiop_stop $agt_host || error "close $file failed"
551 check_file_data $SINGLEAGT $file "multiopen_data"
553 cat $file2 || error "cat $file on mount $MOUNT2 failed"
554 echo -n "multiopen_data" > $file2 ||
555 error "write $file on mount $MOUNT2 failed"
557 run_test 2c "Test multi open on different mount points when creating"
560 local file=$DIR/$tdir/$tfile
562 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
565 mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir failed"
566 dd if=/dev/zero of=$file bs=1024 count=1 ||
567 error "failed to dd write to $file"
569 echo "Start to attach/detach the file: $file"
570 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
571 error "failed to attach file $file"
572 check_lpcc_state $file "readwrite"
573 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
574 error "failed to detach file $file"
575 check_lpcc_state $file "none"
577 echo "Repeat to attach/detach the same file: $file"
578 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
579 error "failed to attach file $file"
580 check_lpcc_state $file "readwrite"
581 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
582 error "failed to detach file $file"
583 check_lpcc_state $file "none"
585 run_test 3a "Repeat attach/detach operations"
589 local file=$DIR/$tdir/$tfile
591 needclients 3 || return 0
593 # Start all of the copytools and setup PCC
594 for n in $(seq $AGTCOUNT); do
595 copytool setup -f agt$n -a $n -m $MOUNT
596 setup_pcc_mapping agt$n "projid={100}\ rwid=$n"
599 mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir failed"
600 dd if=/dev/zero of=$file bs=1024 count=1 ||
601 error "failed to dd write to $file"
603 echo "Start to attach/detach $file on $agt1_HOST"
604 do_facet agt1 $LFS pcc attach -i 1 $file ||
605 error "failed to attach file $file"
606 check_lpcc_state $file "readwrite" agt1
607 do_facet agt1 $LFS pcc detach -k $file ||
608 error "failed to detach file $file"
609 check_lpcc_state $file "none" agt1
611 echo "Repeat to attach/detach $file on $agt2_HOST"
612 do_facet agt2 $LFS pcc attach -i 2 $file ||
613 error "failed to attach file $file"
614 check_lpcc_state $file "readwrite" agt2
615 do_facet agt2 $LFS pcc detach -k $file ||
616 error "failed to detach file $file"
617 check_lpcc_state $file "none" agt2
619 echo "Try attach on two agents"
620 do_facet agt1 $LFS pcc attach -i 1 $file ||
621 error "failed to attach file $file"
622 check_lpcc_state $file "readwrite" agt1
623 do_facet agt2 $LFS pcc attach -i 2 $file ||
624 error "failed to attach file $file"
625 check_lpcc_state $file "readwrite" agt2
626 # The later attach PCC agent should succeed,
627 # the former agent should be detached automatically.
628 check_lpcc_state $file "none" agt1
629 do_facet agt2 $LFS pcc detach -k $file ||
630 error "failed to detach file $file"
631 check_lpcc_state $file "none" agt2
633 run_test 3b "Repeat attach/detach operations on multiple clients"
638 ! is_project_quota_supported &&
639 skip "project quota is not supported" && return
642 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
645 mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir failed"
646 lfs project -sp $project_id $DIR/$tdir ||
647 error "lfs project -sp $project_id $DIR/$tdir failed"
649 # mmap_sanity tst7 failed on the local ext4 filesystem.
650 # It seems that Lustre filesystem does special process for tst 7.
651 # Thus, we exclude tst7 from the PCC testing.
652 $LUSTRE/tests/mmap_sanity -d $DIR/$tdir -m $DIR2/$tdir -e 7 ||
653 error "mmap_sanity test failed"
656 run_test 4 "Auto cache test for mmap"
659 local file=$DIR/$tfile
661 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
664 do_facet $SINGLEAGT "echo -n attach_mmap_data > $file" ||
665 error "echo $file failed"
667 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
668 error "failed to attach file $file"
669 check_lpcc_state $file "readwrite"
671 local content=$($MMAP_CAT $file)
673 [[ $content == "attach_mmap_data" ]] ||
674 error "mmap cat data mismatch: $content"
676 $LFS hsm_restore $file || error "failed to restore $file"
677 wait_request_state $(path2fid $file) RESTORE SUCCEED
678 check_lpcc_state $file "none"
680 content=$($MMAP_CAT $file)
681 [[ $content == "attach_mmap_data" ]] ||
682 error "mmap cat data mismatch: $content"
684 run_test 5 "Mmap & cat a RW-PCC cached file"
692 do_facet $facet mkdir -p $mntpt || error "mkdir -p $hsm_root failed"
693 stack_trap "do_facet $facet rm -rf $mntpt" EXIT
694 do_facet $facet dd if=/dev/zero of=$file bs=1M count=$size
695 stack_trap "do_facet $facet rm -f $file" EXIT
696 do_facet $facet mkfs.ext4 $file ||
697 error "mkfs.ext4 $file failed"
698 do_facet $facet file $file
699 do_facet $facet mount -t ext4 -o loop,usrquota,grpquota $file $mntpt ||
700 error "mount -o loop,usrquota,grpquota $file $mntpt failed"
701 stack_trap "do_facet $facet $UMOUNT $mntpt" EXIT
705 local loopfile="$TMP/$tfile"
706 local mntpt="/mnt/pcc.$tdir"
707 local hsm_root="$mntpt/$tdir"
708 local file=$DIR/$tfile
711 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
712 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
715 echo -n mmap_write_data > $file || error "echo write $file failed"
716 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
717 error "failed to attach file $file"
718 check_lpcc_state $file "readwrite"
720 do_facet $SINGLEAGT $MULTIOP $file OSMWUc ||
721 error "could not mmap $file"
722 check_lpcc_state $file "readwrite"
723 content=$(do_facet $SINGLEAGT $MMAP_CAT $file)
724 # After mmap write via multiop, the first character of each page
726 [[ $content == "nmap_write_data" ]] ||
727 error "mmap write data mismatch: $content"
728 check_lpcc_state $file "readwrite"
730 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
731 error "failed to detach file $file"
733 content=$(do_facet $SINGLEAGT $MMAP_CAT $file)
734 [[ $content == "nmap_write_data" ]] ||
735 error "mmap write data mismatch: $content"
737 run_test 6 "Test mmap write on RW-PCC "
740 local loopfile="$TMP/$tfile"
741 local mntpt="/mnt/pcc.$tdir"
742 local hsm_root="$mntpt/$tdir"
743 local file=$DIR/$tfile
746 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
747 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
751 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
752 error "failed to attach file $file"
753 check_lpcc_state $file "readwrite"
754 check_file_data $SINGLEAGT $file "QQQQQ"
755 # define OBD_FAIL_LLITE_PCC_DETACH_MKWRITE 0x1412
756 do_facet $SINGLEAGT $LCTL set_param fail_loc=0x1412
757 # HSM released exists archived status
758 check_hsm_flags $file "0x0000000d"
760 # multiop mmap write increase the first character of each page with 1
761 do_facet $SINGLEAGT $MULTIOP $file OSMWUc ||
762 error "mmap write $file failed"
763 check_lpcc_state $file "none"
764 content=$(do_facet $SINGLEAGT $MMAP_CAT $file)
765 [[ $content == "RQQQQ" ]] || error "data mismatch: $content"
767 run_test 7a "Fake file detached between fault() and page_mkwrite() for RW-PCC"
770 local loopfile="$TMP/$tfile"
771 local mntpt="/mnt/pcc.$tdir"
772 local hsm_root="$mntpt/$tdir"
773 local file=$DIR/$tfile
777 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
778 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
782 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
783 error "failed to attach file $file"
784 check_lpcc_state $file "readwrite"
785 check_file_data $SINGLEAGT $file "QQQQQ"
786 # define OBD_FAIL_LLITE_PCC_MKWRITE_PAUSE 0x1413
787 do_facet $SINGLEAGT $LCTL set_param fail_loc=0x1413 fail_val=20
788 # HSM released exists archived status
789 check_hsm_flags $file "0x0000000d"
791 # multiop mmap write increases the first character of each page with 1
792 do_facet $SINGLEAGT $MULTIOP $file OSMWUc &
795 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
796 error "failed to detach file $file"
798 wait $pid || error "multiop mmap write failed"
799 check_lpcc_state $file "none"
800 content=$(do_facet $SINGLEAGT $MMAP_CAT $file)
801 [[ $content == "RQQQQ" ]] || error "data mismatch: $content"
803 run_test 7b "Test the race with concurrent mkwrite and detach"
806 local file=$DIR/$tfile
808 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
812 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
813 error "failed to attach file $file"
814 check_lpcc_state $file "readwrite"
815 check_file_data $SINGLEAGT $file "QQQQQ"
817 # define OBD_FAIL_LLITE_PCC_FAKE_ERROR 0x1411
818 do_facet $SINGLEAGT $LCTL set_param fail_loc=0x1411
819 do_facet $SINGLEAGT "echo -n ENOSPC_write > $file"
820 # Above write will return -ENOSPC failure and retry the IO on normal
821 # IO path. It will restore the HSM released file.
822 check_lpcc_state $file "none"
823 check_file_data $SINGLEAGT $file "ENOSPC_write"
825 run_test 8 "Test fake -ENOSPC tolerance for RW-PCC"
828 local loopfile="$TMP/$tfile"
829 local mntpt="/mnt/pcc.9a"
830 local hsm_root="$mntpt/$tdir"
831 local file=$DIR/$tfile
833 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
835 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMVER" -h "$hsm_root"
837 do_facet $SINGLEAGT $LCTL pcc list $MOUNT
839 touch $file || error "touch $file failed"
840 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
841 error "fail to attach $file"
842 check_lpcc_state $file "readwrite"
843 # write 60M data, it is larger than the capacity of PCC backend
844 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1M count=60 ||
845 error "fail to dd write $file"
846 check_lpcc_state $file "none"
847 check_file_size $SINGLEAGT $file 62914560
849 run_test 9 "Test -ENOSPC tolerance on loop PCC device for RW-PCC"
851 test_usrgrp_quota() {
852 local loopfile="$TMP/$tfile"
853 local mntpt="/mnt/pcc.$tdir"
854 local hsm_root="$mntpt/$tdir"
858 [[ $ug == "g" ]] && id=$RUNAS_GID
860 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
861 do_facet $SINGLEAGT quotacheck -c$ug $mntpt ||
862 error "quotacheck -c$ug $mntpt failed"
863 do_facet $SINGLEAGT quotaon -$ug $mntpt ||
864 error "quotaon -$ug $mntpt failed"
865 do_facet $SINGLEAGT setquota -$ug $id 0 20480 0 0 $mntpt ||
866 error "setquota -$ug $id on $mntpt failed"
867 do_facet $SINGLEAGT repquota -${ug}vs $mntpt
869 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMVER" -h "$hsm_root"
871 do_facet $SINGLEAGT $LCTL pcc list $MOUNT
873 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
875 local file1=$DIR/$tdir/${ug}quotaA
876 local file2=$DIR/$tdir/${ug}quotaB
878 dd if=/dev/zero of=$file1 bs=1M count=15 ||
879 error "dd write $file1 failed"
880 dd if=/dev/zero of=$file2 bs=1M count=15 ||
881 error "dd write $file2 failed"
882 chown $RUNAS_ID:$RUNAS_GID $file1 ||
883 error "chown $RUNAS_ID:$RUNAS_GID $file1 failed"
884 chown $RUNAS_ID:$RUNAS_GID $file2 ||
885 error "chown $RUNAS_ID:$RUNAS_GID $file2 failed"
886 do_facet $SINGLEAGT $RUNAS $LFS pcc attach -i $HSM_ARCHIVE_NUMBER \
887 $file1 || error "attach $file1 failed"
888 do_facet $SINGLEAGT $RUNAS $LFS pcc attach -i $HSM_ARCHIVE_NUMBER \
889 $file2 && error "attach $file2 should fail due to quota limit"
890 check_lpcc_state $file1 "readwrite"
891 check_lpcc_state $file2 "none"
893 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file1 bs=1M count=30 ||
894 error "dd write $file1 failed"
895 # -EDQUOT error should be tolerated via fallback to normal Lustre path.
896 check_lpcc_state $file1 "none"
897 do_facet $SINGLEAGT $LFS pcc detach -k $file1 ||
898 error "failed to detach file $file"
903 test_usrgrp_quota "u"
905 run_test 10a "Test RW-PCC with user quota on loop PCC device"
908 test_usrgrp_quota "g"
910 run_test 10b "Test RW-PCC with group quota on loop PCC device"
913 local loopfile="$TMP/$tfile"
914 local mntpt="/mnt/pcc.$tdir"
915 local hsm_root="$mntpt/$tdir"
916 local file=$DIR/$tfile
920 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
921 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
924 do_facet $SINGLEAGT "echo -n QQQQQ > $file"
925 lpcc_path=$(lpcc_fid2path $hsm_root $file)
926 lpcc_dir=$(dirname $lpcc_path)
927 echo "Lustre file: $file LPCC dir: $lpcc_dir"
928 do_facet $SINGLEAGT mkdir -p $lpcc_dir ||
929 error "mkdir -p $lpcc_dir failed"
930 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
931 error "failed to attach $file"
932 check_lpcc_state $file "readwrite"
933 check_file_data $SINGLEAGT $file "QQQQQ"
934 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
935 error "failed to detach $file"
936 rm $file || error "rm $file failed"
938 # The parent directory of the PCC file is immutable
939 do_facet $SINGLEAGT "echo -n immutable_dir > $file"
940 lpcc_path=$(lpcc_fid2path $hsm_root $file)
941 lpcc_dir=$(dirname $lpcc_path)
942 echo "Lustre file: $file LPCC dir: $lpcc_dir"
943 do_facet $SINGLEAGT mkdir -p $lpcc_dir ||
944 error "mkdir -p $lpcc_dir failed"
945 do_facet $SINGLEAGT chattr +i $lpcc_dir ||
946 error "chattr +i $lpcc_dir failed"
947 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file &&
948 error "attach $file with immutable directory should be failed"
949 do_facet $SINGLEAGT chattr -i $lpcc_dir ||
950 error "chattr -i $lpcc_dir failed"
951 rm $file || error "rm $file failed"
953 # The PCC file path is set to a directory
954 do_facet $SINGLEAGT "echo -n pcc_file_path_is_dir > $file"
955 lpcc_path=$(lpcc_fid2path $hsm_root $file)
956 do_facet $SINGLEAGT mkdir -p $lpcc_path ||
957 error "mkdir -p $lpcc_path failed"
958 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file &&
959 error "attach $file should fail as PCC path is a directory"
960 rm $file || error "rm $file failed"
962 run_test 11 "Test attach fault injection with simulated PCC file path"
965 local file=$DIR/$tfile
966 local hsm_root=$(hsm_root)
970 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
973 echo -n race_rw_attach_hsmremove > $file
974 lpcc_path=$(lpcc_fid2path $hsm_root $file)
975 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
976 error "attach $file failed"
977 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
978 error "detach $file failed"
979 # HSM released exists archived status
980 check_hsm_flags $file "0x0000000d"
981 # define OBD_FAIL_LLITE_PCC_ATTACH_PAUSE 0x1414
982 do_facet $SINGLEAGT $LCTL set_param fail_loc=0x1414 fail_val=20
983 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file &
987 wait_request_state $(path2fid $file) RESTORE SUCCEED
988 $LFS hsm_remove $file || error "hsm remove $file failed"
989 wait $pid && error "RW-PCC attach $file should fail"
990 do_facet $SINGLEAGT "[ -f $lpcc_path ]" &&
991 error "RW-PCC cached file '$lpcc_path' should be removed"
995 run_test 12 "RW-PCC attach races with concurrent HSM remove"
999 local rule="${idstr}={$2}"
1001 local file=$DIR/$tdir/$tfile
1003 setup_pcc_mapping $SINGLEAGT "$rule\ rwid=$HSM_ARCHIVE_NUMBER"
1004 $LCTL pcc list $MOUNT
1006 do_facet $SINGLEAGT mkdir -p $DIR/$tdir
1007 chmod 777 $DIR/$tdir || error "chmod 0777 $DIR/$tdir failed"
1009 rm -f $file || error "rm $file failed"
1010 do_facet $SINGLEAGT $myRUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1011 error "failed to dd write to $file"
1012 check_lpcc_state $file "readwrite"
1013 do_facet $SINGLEAGT $myRUNAS dd if=$file of=/dev/null bs=1024 count=1 ||
1014 error "failed to dd read from $file"
1015 do_facet $SINGLEAGT $myRUNAS $TRUNCATE $file 256 ||
1016 error "failed to truncate $file"
1017 do_facet $SINGLEAGT $myRUNAS $TRUNCATE $file 2048 ||
1018 error "failed to truncate $file"
1019 do_facet $SINGLEAGT $myRUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1020 error "failed to dd write from $file"
1021 check_lpcc_state $file "readwrite"
1023 do_facet $SINGLEAGT $myRUNAS $LFS pcc detach -k $file ||
1024 error "failed to detach file $file"
1025 check_lpcc_state $file "none"
1029 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1030 test_rule_id "u" "500" "runas -u 500"
1031 test_rule_id "g" "500" "runas -u 500 -g 500"
1033 run_test 13a "Test auto RW-PCC create caching for UID/GID rule"
1038 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1039 setup_pcc_mapping $SINGLEAGT \
1040 "fname={*.h5\ suffix.*\ Mid*dle}\ rwid=$HSM_ARCHIVE_NUMBER"
1041 $LCTL pcc list $MOUNT
1043 do_facet $SINGLEAGT mkdir -p $DIR/$tdir
1044 chmod 777 $DIR/$tdir || error "chmod 0777 $DIR/$tdir failed"
1046 file=$DIR/$tdir/prefix.h5
1047 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1024 count=1 ||
1048 error "failed to dd write to $file"
1049 check_lpcc_state $file "readwrite"
1050 do_facet $SINGLEAGT $myRUNAS $LFS pcc detach -k $file ||
1051 error "failed to detach file $file"
1052 check_lpcc_state $file "none"
1053 rm $file || error "rm $file failed"
1055 file=$DIR/$tdir/suffix.doc
1056 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1057 error "failed to dd write to $file"
1058 check_lpcc_state $file "readwrite"
1059 do_facet $SINGLEAGT $myRUNAS $LFS pcc detach -k $file ||
1060 error "failed to detach file $file"
1061 check_lpcc_state $file "none"
1062 rm $file || error "rm $file failed"
1064 file=$DIR/$tdir/MidPADdle
1065 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1066 error "failed to dd write to $file"
1067 check_lpcc_state $file "readwrite"
1068 do_facet $SINGLEAGT $myRUNAS $LFS pcc detach -k $file ||
1069 error "failed to detach file $file"
1070 check_lpcc_state $file "none"
1071 rm $file || error "rm $file failed"
1073 file=$DIR/$tdir/Midpad
1074 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1075 error "failed to dd write to $file"
1076 check_lpcc_state $file "none"
1077 rm $file || error "rm $file failed"
1079 run_test 13b "Test auto RW-PCC create caching for file name with wildcard"
1085 ! is_project_quota_supported &&
1086 echo "Skip project quota is not supported" && return 0
1088 enable_project_quota
1089 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1090 setup_pcc_mapping $SINGLEAGT \
1091 "projid={100\ 200}\&fname={*.h5},uid={500}\&gid={1000}\ rwid=$HSM_ARCHIVE_NUMBER"
1092 $LCTL pcc list $MOUNT
1093 do_facet $SINGLEAGT mkdir -p $DIR/$tdir
1094 chmod 777 $DIR/$tdir || error "chmod 0777 $DIR/$tdir failed"
1096 mkdir -p $DIR/$tdir/proj || error "mkdir $DIR/$tdir/proj failed"
1097 mkdir -p $DIR/$tdir/proj2 || error "mkdir $DIR/$tdir/proj2 failed"
1098 $LFS project -sp 100 $DIR/$tdir/proj ||
1099 error "failed to set project for $DIR/$tdir/proj"
1100 $LFS project -sp 200 $DIR/$tdir/proj2 ||
1101 error "failed to set project for $DIR/$tdir/proj2"
1103 file=$DIR/$tdir/proj/notcache
1104 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1024 count=1 ||
1105 error "failed to dd write to $file"
1106 check_lpcc_state $file "none"
1107 rm $file || error "rm $file failed"
1109 file=$DIR/$tdir/proj/autocache.h5
1110 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1024 count=1 ||
1111 error "failed to dd write to $file"
1112 check_lpcc_state $file "readwrite"
1113 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1114 error "failed to detach $file"
1115 rm $file || error "rm $file failed"
1117 file=$DIR/$tdir/proj2/notcache
1118 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1024 count=1 ||
1119 error "failed to dd write to $file"
1120 check_lpcc_state $file "none"
1121 rm $file || error "rm $file failed"
1123 file=$DIR/$tdir/proj2/autocache.h5
1124 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1024 count=1 ||
1125 error "failed to dd write to $file"
1126 check_lpcc_state $file "readwrite"
1127 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1128 error "failed to detach $file"
1129 rm $file || error "rm $file failed"
1131 file=$DIR/$tdir/ugidcache
1132 myRUNAS="runas -u 500 -g 1000"
1133 do_facet $SINGLEAGT $myRUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1134 error "failed to dd write to $file"
1135 check_lpcc_state $file "readwrite"
1136 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1137 error "failed to detach $file"
1138 rm $file || error "rm $file failed"
1140 run_test 13c "Check auto RW-PCC create caching for UID/GID/ProjID/fname rule"
1143 local file=$DIR/$tdir/$tfile
1145 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1148 mkdir -p $DIR/$tdir || error "mkdir -p $DIR/$tdir failed"
1149 do_facet $SINGLEAGT "echo -n autodetach_data > $file"
1150 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER \
1151 $file || error "PCC attach $file failed"
1152 check_lpcc_state $file "readwrite"
1154 # Revoke the layout lock, the PCC-cached file will be
1155 # detached automatically.
1156 do_facet $SINGLEAGT $LCTL \
1157 set_param ldlm.namespaces.*mdc*.lru_size=clear
1158 check_file_data $SINGLEAGT $file "autodetach_data"
1159 check_lpcc_state $file "none"
1161 run_test 14 "Revocation of the layout lock should detach the file automatically"
1164 local loopfile="$TMP/$tfile"
1165 local mntpt="/mnt/pcc.$tdir"
1166 local hsm_root="$mntpt/$tdir"
1167 local file=$DIR/$tdir/$tfile
1169 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1170 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1171 setup_pcc_mapping $SINGLEAGT \
1172 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ open_attach=1"
1174 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
1175 chmod 777 $DIR/$tdir || error "chmod 777 $DIR/$tdir failed"
1177 echo "Check open attach for non-root user"
1178 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1179 error "failed to dd write to $file"
1180 do_facet $SINGLEAGT $RUNAS $LFS pcc attach -i $HSM_ARCHIVE_NUMBER \
1181 $file || error "failed to attach file $file"
1182 do_facet $SINGLEAGT $RUNAS $LFS pcc state $file
1183 check_lpcc_state $file "readwrite" $SINGLEAGT "$RUNAS"
1184 # Revoke the layout lock, the PCC-cached file will be
1185 # detached automatically.
1186 do_facet $SINGLEAGT $LCTL \
1187 set_param ldlm.namespaces.*mdc*.lru_size=clear
1188 check_lpcc_state $file "readwrite" $SINGLEAGT "$RUNAS"
1189 # Detach the file but keep the cache , as the file layout generation
1190 # is not changed, so the file is still valid cached in PCC, and can
1191 # be reused from PCC cache directly.
1192 do_facet $SINGLEAGT $RUNAS $LFS pcc detach -k $file ||
1193 error "PCC detach $file failed"
1194 check_lpcc_state $file "readwrite" $SINGLEAGT "$RUNAS"
1195 do_facet $SINGLEAGT $RUNAS $LFS pcc detach $file ||
1196 error "PCC detach $file failed"
1197 rm $file || error "rm $file failed"
1199 echo "check open attach for root user"
1200 do_facet $SINGLEAGT "echo -n autoattach_data > $file"
1201 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER \
1202 $file || error "PCC attach $file failed"
1203 check_lpcc_state $file "readwrite"
1205 # Revoke the layout lock, the PCC-cached file will be
1206 # detached automatically.
1207 do_facet $SINGLEAGT $LCTL \
1208 set_param ldlm.namespaces.*mdc*.lru_size=clear
1209 check_file_data $SINGLEAGT $file "autoattach_data"
1210 check_lpcc_state $file "readwrite"
1212 # Detach the file with -k option, as the file layout generation
1213 # is not changed, so the file is still valid cached in PCC,
1214 # and can be reused from PCC cache directly.
1215 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1216 error "PCC detach $file failed"
1217 check_lpcc_state $file "readwrite"
1218 # HSM released exists archived status
1219 check_hsm_flags $file "0x0000000d"
1220 check_file_data $SINGLEAGT $file "autoattach_data"
1222 # HSM restore the PCC cached file, the layout generation
1223 # was changed, so the file can not be auto attached.
1224 $LFS hsm_restore $file || error "failed to restore $file"
1225 wait_request_state $(path2fid $file) RESTORE SUCCEED
1226 check_lpcc_state $file "none"
1227 # HSM exists archived status
1228 check_hsm_flags $file "0x00000009"
1231 run_test 15 "Test auto attach at open when file is still valid cached"
1234 local loopfile="$TMP/$tfile"
1235 local mntpt="/mnt/pcc.$tdir"
1236 local hsm_root="$mntpt/$tdir"
1237 local file=$DIR/$tfile
1240 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1241 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1242 setup_pcc_mapping $SINGLEAGT \
1243 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ open_attach=1"
1245 do_facet $SINGLEAGT "echo -n detach_data > $file"
1246 lpcc_path=$(lpcc_fid2path $hsm_root $file)
1247 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER \
1248 $file || error "PCC attach $file failed"
1249 check_lpcc_state $file "readwrite"
1250 # HSM released exists archived status
1251 check_hsm_flags $file "0x0000000d"
1253 echo "Test for reusing valid PCC cache"
1254 # Valid PCC cache can be reused
1255 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1256 error "PCC detach $file failed"
1257 check_lpcc_state $file "readwrite"
1258 # HSM released exists archived status
1259 check_hsm_flags $file "0x0000000d"
1261 echo "Test for the default detach"
1262 # Permanent detach by default, it will remove the PCC copy
1263 do_facet $SINGLEAGT $LFS pcc detach $file ||
1264 error "PCC detach $file failed"
1265 wait_request_state $(path2fid $file) REMOVE SUCCEED
1266 check_lpcc_state $file "none"
1267 # File is removed from PCC backend
1268 check_hsm_flags $file "0x00000000"
1269 do_facet $SINGLEAGT "[ -f $lpcc_path ]" &&
1270 error "RW-PCC cached file '$lpcc_path' should be removed"
1274 run_test 16 "Test detach with different options"
1277 check_and_cleanup_lustre