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 ALWAYS_EXCEPT="$SANITY_PCC_EXCEPT "
15 # bug number for skipped test:
17 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
19 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
20 HSMTOOL_ARCHIVE_FORMAT=v1
22 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
24 . $LUSTRE/tests/test-framework.sh
26 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
29 MULTIOP=${MULTIOP:-multiop}
30 OPENFILE=${OPENFILE:-openfile}
31 MOUNT_2=${MOUNT_2:-"yes"}
34 # script only handles up to 10 MDTs (because of MDT_PREFIX)
35 [ $MDSCOUNT -gt 9 ] &&
36 error "script cannot handle more than 9 MDTs, please fix" && exit
38 check_and_setup_lustre
40 if [[ "$MDS1_VERSION" -lt $(version_code 2.12.52) ]]; then
41 skip "Need MDS version at least 2.12.52"
44 # $RUNAS_ID may get set incorrectly somewhere else
45 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
46 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
48 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
49 if getent group nobody; then
51 elif getent group nogroup; then
54 error "No generic nobody group"
59 # if there is no CLIENT1 defined, some tests can be ran on localhost
60 CLIENT1=${CLIENT1:-$HOSTNAME}
61 # if CLIENT2 doesn't exist then use CLIENT1 instead
62 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
64 # Exception is the test which need two separate nodes
65 CLIENT2=${CLIENT2:-$CLIENT1}
71 local expected_size="$3"
73 size=$(do_facet $client stat "--printf=%s" $fpath)
74 [[ $size == "$expected_size" ]] || error \
75 "expected $fpath size: $expected_size got: $size"
82 local lustre_fpath="$3"
83 local expected_size="$4"
85 check_file_size $client $lpcc_fpath $expected_size
86 check_file_size $client $lustre_fpath $expected_size
93 local expected_data="$3"
95 path_data=$(do_facet $client cat $path)
96 [[ "x$path_data" == "x$expected_data" ]] || error \
97 "expected $path: $expected_data, got: $path_data"
103 local lpcc_fpath="$2"
104 local lustre_fpath="$3"
105 local expected_data="$4"
107 check_file_data "$client" "$lpcc_fpath" "$expected_data"
108 check_file_data "$client" "$lustre_fpath" "$expected_data"
114 local lustre_path="$2"
115 local fid=$(path2fid $lustre_path)
117 local seq=$(echo $fid | awk -F ':' '{print $1}')
118 local oid=$(echo $fid | awk -F ':' '{print $2}')
119 local ver=$(echo $fid | awk -F ':' '{print $3}')
121 case "$HSMTOOL_ARCHIVE_FORMAT" in
123 printf "%s/%04x/%04x/%04x/%04x/%04x/%04x/%s" \
124 $hsm_root $((oid & 0xFFFF)) \
125 $((oid >> 16 & 0xFFFF)) \
127 $((seq >> 16 & 0xFFFF)) \
128 $((seq >> 32 & 0xFFFF)) \
129 $((seq >> 48 & 0xFFFF)) $fid
132 printf "%s/%04x/%s" $hsm_root $(((oid ^ seq) & 0xFFFF)) $fid
139 local lustre_path="$1"
140 local expected_state="$2"
141 local facet=${3:-$SINGLEAGT}
143 local state=$(do_facet $facet $myRUNAS $LFS pcc state $lustre_path |
144 awk -F 'type: ' '{print $2}' | awk -F ',' '{print $1}')
146 [[ "x$state" == "x$expected_state" ]] || error \
147 "$lustre_path expected pcc state: $expected_state, but got: $state"
153 # populate MDT device array
156 # cleanup from previous bad setup
159 # for recovery tests, coordinator needs to be started at mount
161 # the lustre conf must be without hsm on (like for sanity.sh)
162 echo "Set HSM on and start"
163 cdt_set_mount_state enabled
164 cdt_check_state enabled
166 echo "Set sanity-hsm HSM policy"
167 cdt_set_sanity_policy
169 # finished requests are quickly removed from list
170 set_hsm_param grace_delay 10
172 cleanup_pcc_mapping() {
173 local facet=${1:-$SINGLEAGT}
175 do_facet $facet $LCTL pcc clear $MOUNT
178 setup_pcc_mapping() {
179 local facet=${1:-$SINGLEAGT}
180 local hsm_root=${hsm_root:-$(hsm_root "$facet")}
183 [ -z "$param" ] && param="projid={100}\ rwid=$HSM_ARCHIVE_NUMBER"
184 stack_trap "cleanup_pcc_mapping $facet" EXIT
185 do_facet $facet $LCTL pcc add $MOUNT $hsm_root -p $param
194 do_facet $facet mkdir -p $mntpt || error "mkdir -p $hsm_root failed"
195 stack_trap "do_facet $facet rm -rf $mntpt" EXIT
196 do_facet $facet dd if=/dev/zero of=$file bs=1M count=$size
197 stack_trap "do_facet $facet rm -f $file" EXIT
198 do_facet $facet mkfs.ext4 $file ||
199 error "mkfs.ext4 $file failed"
200 do_facet $facet file $file
201 do_facet $facet mount -t ext4 -o loop,usrquota,grpquota $file $mntpt ||
202 error "mount -o loop,usrquota,grpquota $file $mntpt failed"
203 stack_trap "do_facet $facet $UMOUNT $mntpt" EXIT
210 local agt_facet=$SINGLEAGT
211 local loopfile="$TMP/$tfile"
212 local mntpt="/mnt/pcc.$tdir"
213 local hsm_root="$mntpt/$tdir"
214 local file=$DIR/$tdir/$tfile
219 $project && enable_project_quota
221 do_facet $SINGLEAGT rm -rf $hsm_root
222 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
223 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
225 is_project_quota_supported || project=false
227 do_facet $SINGLEAGT $LFS mkdir -i0 -c1 $DIR/$tdir
229 $project && lfs project -sp $project_id $DIR/$tdir
231 do_facet $SINGLEAGT "echo -n attach_origin > $file"
233 check_lpcc_state $file "none"
234 do_facet $SINGLEAGT $LFS pcc attach -i \
235 $HSM_ARCHIVE_NUMBER $file ||
236 error "pcc attach $file failed"
239 check_lpcc_state $file "readwrite"
240 # HSM released exists archived status
241 check_hsm_flags $file "0x0000000d"
242 lpcc_path=$(lpcc_fid2path $hsm_root $file)
243 check_lpcc_data $SINGLEAGT $lpcc_path $file "attach_origin"
245 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=7654321 count=1
246 check_lpcc_sizes $SINGLEAGT $lpcc_path $file 7654321
248 do_facet $SINGLEAGT $TRUNCATE $file 1234567 ||
249 error "truncate failed"
250 check_lpcc_sizes $SINGLEAGT $lpcc_path $file 1234567
251 check_lpcc_state $file "readwrite"
253 do_facet $SINGLEAGT "echo -n file_data > $file"
254 check_lpcc_state $file "readwrite"
255 # HSM released exists archived status
256 check_hsm_flags $file "0x0000000d"
257 check_lpcc_data $SINGLEAGT $lpcc_path $file "file_data"
259 echo "Restore testing..."
260 if [ $CLIENTCOUNT -lt 2 -o $restore ]; then
261 $LFS hsm_restore $file || error \
262 "failed to restore $file"
263 wait_request_state $(path2fid $file) RESTORE SUCCEED
265 path_data=$(do_node $CLIENT2 cat $file)
266 [[ "x$path_data" == "xfile_data" ]] || error \
267 "expected file_data, got: $path_data"
270 check_lpcc_state $file "none"
271 # HSM exists archived status
272 check_hsm_flags $file "0x00000009"
274 echo -n "new_data" > $file
275 check_lpcc_state $file "none"
276 # HSM exists dirty archived status
277 check_hsm_flags $file "0x0000000b"
278 check_file_data $SINGLEAGT $file "new_data"
280 echo "Attach and detach testing"
282 do_facet $SINGLEAGT "echo -n new_data2 > $file"
284 check_lpcc_state $file "none"
285 do_facet $SINGLEAGT $LFS pcc attach -i \
286 $HSM_ARCHIVE_NUMBER $file ||
287 error "PCC attach $file failed"
289 check_lpcc_state $file "readwrite"
290 # HSM released exists archived status
291 check_hsm_flags $file "0x0000000d"
292 do_facet $SINGLEAGT "echo -n attach_detach > $file"
293 echo "Start to detach the $file"
294 do_facet $SINGLEAGT $LFS pcc detach $file ||
295 error "PCC detach $file failed"
296 wait_request_state $(path2fid $file) REMOVE SUCCEED
298 check_lpcc_state $file "none"
299 # The file is removed from PCC
300 check_hsm_flags $file "0x00000000"
301 check_file_data $SINGLEAGT $file "attach_detach"
305 lpcc_rw_test true false
307 run_test 1a "Test manual lfs pcc attach with manual HSM restore"
310 lpcc_rw_test false false
312 run_test 1b "Test manual lfs pcc attach with restore on remote access"
315 lpcc_rw_test true true
317 run_test 1c "Test automated attach using Project ID with manual HSM restore"
320 lpcc_rw_test false true
322 run_test 1d "Test Project ID with remote access"
325 local file=$DIR/$tdir/$tfile
326 local hsm_root=$(hsm_root)
329 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
330 setup_pcc_mapping $SINGLEAGT \
331 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0"
332 $LCTL pcc list $MOUNT
333 mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
334 chmod 777 $DIR/$tdir || error "chmod 777 $DIR/$tdir failed"
336 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
337 error "failed to dd write to $file"
338 do_facet $SINGLEAGT $RUNAS $LFS pcc attach -i $HSM_ARCHIVE_NUMBER \
339 $file || error "failed to attach file $file"
340 check_lpcc_state $file "readwrite"
341 do_facet $SINGLEAGT $RUNAS dd if=$file of=/dev/null bs=1024 count=1 ||
342 error "failed to dd read from $file"
343 do_facet $SINGLEAGT $RUNAS $TRUNCATE $file 256 ||
344 error "failed to truncate $file"
345 do_facet $SINGLEAGT $RUNAS $TRUNCATE $file 2048 ||
346 error "failed to truncate $file"
347 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
348 error "failed to dd write to $file"
349 check_lpcc_state $file "readwrite"
351 do_facet $SINGLEAGT $RUNAS $LFS pcc detach -k $file ||
352 error "failed to detach file $file"
353 check_lpcc_state $file "none"
355 # non-root user is forbidden to access PCC file directly
356 lpcc_path=$(lpcc_fid2path $hsm_root $file)
357 do_facet $SINGLEAGT $RUNAS touch $lpcc_path &&
358 error "non-root user can touch access PCC file $lpcc_path"
359 do_facet $SINGLEAGT $RUNAS dd if=$lpcc_path of=/dev/null bs=1024 \
360 count=1 && error "non-root user can read PCC file $lpcc_path"
361 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$lpcc_path bs=1024 \
362 count=1 && error "non-root user can write PCC file $lpcc_path"
364 local perm=$(do_facet $SINGLEAGT stat -c %a $lpcc_path)
366 [[ $perm == "0" ]] || error "PCC file permission ($perm) is not zero"
368 do_facet $SINGLEAGT $RUNAS $LFS pcc attach -i $HSM_ARCHIVE_NUMBER \
369 $file || error "failed to attach file $file"
370 check_lpcc_state $file "readwrite"
372 do_facet $SINGLEAGT $RUNAS $LFS pcc detach $file ||
373 error "failed to detach file $file"
374 check_lpcc_state $file "none"
375 wait_request_state $(path2fid $file) REMOVE SUCCEED
377 run_test 1e "Test RW-PCC with non-root user"
381 local agt_facet=$SINGLEAGT
382 local loopfile="$TMP/$tfile"
383 local mntpt="/mnt/pcc.$tdir"
384 local hsm_root="$mntpt/$tdir"
385 local file=$DIR/$tdir/$tfile
387 ! is_project_quota_supported &&
388 skip "project quota is not supported"
391 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
392 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
393 setup_pcc_mapping $SINGLEAGT \
394 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ open_attach=0\ stat_attach=0"
396 do_facet $SINGLEAGT $LFS mkdir -i0 -c1 $DIR/$tdir
397 chmod 777 $DIR/$tdir || error "chmod 0777 $DIR/$tdir failed"
398 $LFS project -sp $project_id $DIR/$tdir ||
399 error "failed to set project for $DIR/$tdir"
401 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
402 error "failed to dd write to $file"
404 check_lpcc_state $file "readwrite"
405 do_facet $SINGLEAGT $RUNAS dd if=$file of=/dev/null bs=1024 count=1 ||
406 error "failed to dd read from $file"
407 do_facet $SINGLEAGT $RUNAS $TRUNCATE $file 256 ||
408 error "failed to truncate $file"
409 do_facet $SINGLEAGT $RUNAS $TRUNCATE $file 2048 ||
410 error "failed to truncate $file"
411 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=256 count=1 ||
412 error "failed to dd write from $file"
413 check_lpcc_state $file "readwrite"
415 # non-root user is forbidden to access PCC file directly
416 lpcc_path=$(lpcc_fid2path $hsm_root $file)
417 do_facet $SINGLEAGT $RUNAS touch $lpcc_path &&
418 error "non-root user can touch access PCC file $lpcc_path"
419 do_facet $SINGLEAGT $RUNAS dd if=$lpcc_path of=/dev/null bs=1024 \
420 count=1 && error "non-root user can read PCC file $lpcc_path"
421 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$lpcc_path bs=1024 \
422 count=1 && error "non-root user can write PCC file $lpcc_path"
424 do_facet $SINGLEAGT $RUNAS $LFS pcc detach $file ||
425 error "failed to detach file $file"
426 wait_request_state $(path2fid $file) REMOVE SUCCEED
427 check_lpcc_state $file "none"
429 run_test 1f "Test auto RW-PCC cache with non-root user"
432 local loopfile="$TMP/$tfile"
433 local mntpt="/mnt/pcc.$tdir"
434 local hsm_root="$mntpt/$tdir"
435 local file=$DIR/$tfile
437 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
438 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
441 dd if=/dev/zero of=$file bs=1024 count=1 ||
442 error "failed to dd write to $file"
443 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 &&
444 error "non-root user can dd write to $file"
445 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
446 error "failed to attach file $file"
447 check_lpcc_state $file "readwrite"
448 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 &&
449 error "non-root user can dd write to $file"
450 chmod 777 $file || error "chmod 777 $file failed"
451 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
452 error "non-root user cannot write $file with permission (777)"
454 do_facet $SINGLEAGT $RUNAS $LFS pcc detach $file &&
455 error "non-root user or non owner can detach $file"
456 chown $RUNAS_ID $file || error "chown $RUNAS_ID $file failed"
457 do_facet $SINGLEAGT $RUNAS $LFS pcc detach $file ||
458 error "failed to detach file $file"
459 check_lpcc_state $file "none"
460 wait_request_state $(path2fid $file) REMOVE SUCCEED
461 do_facet $SINGLEAGT $RUNAS dd if=$file of=/dev/null bs=1024 count=1 ||
462 error "non-root user cannot read to $file with permisson (777)"
464 run_test 1g "General permission test for RW-PCC"
467 # When a process created a LPCC file and holding the open,
468 # another process on the same client should be able to open the file.
472 local agt_facet=$SINGLEAGT
473 local loopfile="$TMP/$tfile"
474 local mntpt="/mnt/pcc.$tdir"
475 local hsm_root="$mntpt/$tdir"
476 local agt_host=$(facet_active_host $SINGLEAGT)
478 ! is_project_quota_supported &&
479 skip "project quota is not supported" && return
482 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
483 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
485 file=$DIR/$tdir/multiop
486 $LFS mkdir -i -1 -c $MDSCOUNT $DIR/$tdir
489 do_facet $SINGLEAGT $LFS project -sp $project_id $DIR/$tdir ||
490 error "failed to set project quota"
491 rmultiop_start $agt_host $file O_c || error "open $file failed"
492 # HSM released exists archived status
493 check_hsm_flags $file "0x0000000d"
494 do_facet $SINGLEAGT "echo -n multiopen_data > $file" ||
495 error "failed to echo multiopen_data to $file"
497 lpcc_path=$(lpcc_fid2path $hsm_root $file)
498 do_facet $SINGLEAGT ls -l $lpcc_path ||
499 error "failed to ls $lpcc_path"
500 check_lpcc_data $SINGLEAGT $lpcc_path $file "multiopen_data"
501 # HSM released exists archived status
502 check_hsm_flags $file "0x0000000d"
504 do_facet $SINGLEAGT $LFS pcc detach $file ||
505 error "failed to detach $file"
506 rmultiop_stop $agt_host || error "close $file failed"
508 run_test 2a "Test multi open when creating"
510 get_remote_client() {
511 current_id=$(do_facet $SINGLEAGT hostname)
512 for client in ${CLIENTS//,/ }
514 r_id=$(do_node $client hostname)
515 if [ $r_id != $current_id ]; then
523 # When a process created a LPCC file and holding the open, another
524 # process on the different client should be able to open the file
525 # and perform IO on the file.
528 local agt_facet=$SINGLEAGT
529 local agt_host=$(facet_active_host $SINGLEAGT)
530 local loopfile="$TMP/$tfile"
531 local mntpt="/mnt/pcc.$tdir"
532 local hsm_root="$mntpt/$tdir"
534 needclients 2 || return 0
536 remote_client=$(get_remote_client)
539 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
540 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
542 file=$DIR/$tdir/multiop
546 do_facet $SINGLEAGT "echo -n file_data > $file"
547 do_facet $SINGLEAGT lfs pcc attach -i $HSM_ARCHIVE_NUMBER \
548 $file || error "PCC attach $file failed"
549 check_lpcc_state $file "readwrite"
551 rmultiop_start $agt_host $file O_c || error "open $file failed"
553 do_node $remote_client "echo -n multiopen_data > $file"
555 # PCC cached file should be automatically detached
556 check_lpcc_state $file "none"
558 check_file_data $SINGLEAGT $file "multiopen_data"
559 rmultiop_stop $agt_host || error "close $file failed"
560 check_file_data $SINGLEAGT $file "multiopen_data"
562 do_node $remote_client cat $file || error \
563 "cat $file on remote client failed"
564 do_node $remote_client echo -n "multiopen_data" > $file \
565 || error "write $file on remote client failed"
567 run_test 2b "Test multi remote open when creating"
570 local agt_host=$(facet_active_host $SINGLEAGT)
571 local loopfile="$TMP/$tfile"
572 local mntpt="/mnt/pcc.$tdir"
573 local hsm_root="$mntpt/$tdir"
574 local file=$DIR/$tdir/$tfile
575 local file2=$DIR2/$tdir/$tfile
578 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
579 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
584 do_facet $SINGLEAGT "echo -n file_data > $file"
585 do_facet $SINGLEAGT lfs pcc attach -i $HSM_ARCHIVE_NUMBER \
586 $file || error "PCC attach $file failed"
587 check_lpcc_state $file "readwrite"
589 rmultiop_start $agt_host $file O_c || error "open $file failed"
591 echo -n multiopen_data > $file2
593 # PCC cached file should be automatically detached
594 check_lpcc_state $file "none"
596 check_file_data $SINGLEAGT $file "multiopen_data"
597 rmultiop_stop $agt_host || error "close $file failed"
598 check_file_data $SINGLEAGT $file "multiopen_data"
600 cat $file2 || error "cat $file on mount $MOUNT2 failed"
601 echo -n "multiopen_data" > $file2 ||
602 error "write $file on mount $MOUNT2 failed"
604 run_test 2c "Test multi open on different mount points when creating"
607 local file=$DIR/$tdir/$tfile
609 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
610 setup_pcc_mapping $SINGLEAGT \
611 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0"
613 mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir failed"
614 dd if=/dev/zero of=$file bs=1024 count=1 ||
615 error "failed to dd write to $file"
617 echo "Start to attach/detach the file: $file"
618 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
619 error "failed to attach file $file"
620 check_lpcc_state $file "readwrite"
621 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
622 error "failed to detach file $file"
623 check_lpcc_state $file "none"
625 echo "Repeat to attach/detach the same file: $file"
626 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
627 error "failed to attach file $file"
628 check_lpcc_state $file "readwrite"
629 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
630 error "failed to detach file $file"
631 check_lpcc_state $file "none"
633 run_test 3a "Repeat attach/detach operations"
637 local file=$DIR/$tdir/$tfile
639 needclients 3 || return 0
641 # Start all of the copytools and setup PCC
642 for n in $(seq $AGTCOUNT); do
643 copytool setup -f agt$n -a $n -m $MOUNT
644 setup_pcc_mapping agt$n "projid={100}\ rwid=$n\ auto_attach=0"
647 mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir failed"
648 dd if=/dev/zero of=$file bs=1024 count=1 ||
649 error "failed to dd write to $file"
651 echo "Start to attach/detach $file on $agt1_HOST"
652 do_facet agt1 $LFS pcc attach -i 1 $file ||
653 error "failed to attach file $file"
654 check_lpcc_state $file "readwrite" agt1
655 do_facet agt1 $LFS pcc detach -k $file ||
656 error "failed to detach file $file"
657 check_lpcc_state $file "none" agt1
659 echo "Repeat to attach/detach $file on $agt2_HOST"
660 do_facet agt2 $LFS pcc attach -i 2 $file ||
661 error "failed to attach file $file"
662 check_lpcc_state $file "readwrite" agt2
663 do_facet agt2 $LFS pcc detach -k $file ||
664 error "failed to detach file $file"
665 check_lpcc_state $file "none" agt2
667 echo "Try attach on two agents"
668 do_facet agt1 $LFS pcc attach -i 1 $file ||
669 error "failed to attach file $file"
670 check_lpcc_state $file "readwrite" agt1
671 do_facet agt2 $LFS pcc attach -i 2 $file ||
672 error "failed to attach file $file"
673 check_lpcc_state $file "readwrite" agt2
674 # The later attach PCC agent should succeed,
675 # the former agent should be detached automatically.
676 check_lpcc_state $file "none" agt1
677 do_facet agt2 $LFS pcc detach -k $file ||
678 error "failed to detach file $file"
679 check_lpcc_state $file "none" agt2
681 run_test 3b "Repeat attach/detach operations on multiple clients"
685 local loopfile="$TMP/$tfile"
686 local mntpt="/mnt/pcc.$tdir"
687 local hsm_root="$mntpt/$tdir"
688 local excepts="-e 6 -e 7 -e 8 -e 9"
690 ! is_project_quota_supported &&
691 skip "project quota is not supported" && return
694 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
695 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
698 mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir failed"
699 lfs project -sp $project_id $DIR/$tdir ||
700 error "lfs project -sp $project_id $DIR/$tdir failed"
702 # 1. mmap_sanity tst7 failed on the local ext4 filesystem.
703 # It seems that Lustre filesystem does special process for tst 7.
704 # 2. There is a mmap problem for PCC when multiple clients read/write
705 # on a shared mmapped file for mmap_sanity tst 6.
706 # 3. Current CentOS8 kernel does not strictly obey POSIX syntax for
707 # mmap() within the maping but beyond current end of the underlying
708 # files: It does not send SIGBUS signals to the process.
709 # 4. For negative file offset, sanity_mmap also failed on 48 bits
710 # ldiksfs backend due to too large offset: "Value too large for
711 # defined data type".
712 # mmap_sanity tst7/tst8/tst9 all failed on Lustre and local ext4.
713 # Thus, we exclude sanity tst6/tst7/tst8/tst9 from the PCC testing.
714 $LUSTRE/tests/mmap_sanity -d $DIR/$tdir -m $DIR2/$tdir $excepts ||
715 error "mmap_sanity test failed"
718 # Revoke the layout lock, the PCC-cached file will be
719 # detached automatically.
720 do_facet $SINGLEAGT $LCTL \
721 set_param ldlm.namespaces.*mdc*.lru_size=clear
722 rm -rf $DIR/$tdir || error "failed to remove $DIR/$tdir"
724 run_test 4 "Auto cache test for mmap"
727 local file=$DIR/$tfile
728 local loopfile="$TMP/$tfile"
729 local mntpt="/mnt/pcc.$tdir"
730 local hsm_root="$mntpt/$tdir"
732 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
733 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
736 do_facet $SINGLEAGT "echo -n attach_mmap_data > $file" ||
737 error "echo $file failed"
739 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
740 error "failed to attach file $file"
741 check_lpcc_state $file "readwrite"
743 local content=$($MMAP_CAT $file)
745 [[ $content == "attach_mmap_data" ]] ||
746 error "mmap cat data mismatch: $content"
748 $LFS hsm_restore $file || error "failed to restore $file"
749 wait_request_state $(path2fid $file) RESTORE SUCCEED
750 check_lpcc_state $file "none"
752 content=$($MMAP_CAT $file)
753 [[ $content == "attach_mmap_data" ]] ||
754 error "mmap cat data mismatch: $content"
756 run_test 5 "Mmap & cat a RW-PCC cached file"
759 local loopfile="$TMP/$tfile"
760 local mntpt="/mnt/pcc.$tdir"
761 local hsm_root="$mntpt/$tdir"
762 local file=$DIR/$tfile
765 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
766 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
769 echo -n mmap_write_data > $file || error "echo write $file failed"
770 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
771 error "failed to attach file $file"
772 check_lpcc_state $file "readwrite"
774 do_facet $SINGLEAGT $MULTIOP $file OSMWUc ||
775 error "could not mmap $file"
776 check_lpcc_state $file "readwrite"
777 content=$(do_facet $SINGLEAGT $MMAP_CAT $file)
778 # After mmap write via multiop, the first character of each page
780 [[ $content == "nmap_write_data" ]] ||
781 error "mmap write data mismatch: $content"
782 check_lpcc_state $file "readwrite"
784 do_facet $SINGLEAGT $LFS pcc detach $file ||
785 error "failed to detach file $file"
786 wait_request_state $(path2fid $file) REMOVE SUCCEED
788 content=$(do_facet $SINGLEAGT $MMAP_CAT $file)
789 [[ $content == "nmap_write_data" ]] ||
790 error "mmap write data mismatch: $content"
792 run_test 6 "Test mmap write on RW-PCC "
795 local loopfile="$TMP/$tfile"
796 local mntpt="/mnt/pcc.$tdir"
797 local hsm_root="$mntpt/$tdir"
798 local file=$DIR/$tfile
801 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
802 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
806 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
807 error "failed to attach file $file"
808 check_lpcc_state $file "readwrite"
809 check_file_data $SINGLEAGT $file "QQQQQ"
810 # define OBD_FAIL_LLITE_PCC_DETACH_MKWRITE 0x1412
811 do_facet $SINGLEAGT $LCTL set_param fail_loc=0x1412
812 # HSM released exists archived status
813 check_hsm_flags $file "0x0000000d"
815 # multiop mmap write increase the first character of each page with 1
816 do_facet $SINGLEAGT $MULTIOP $file OSMWUc ||
817 error "mmap write $file failed"
818 check_lpcc_state $file "none"
819 content=$(do_facet $SINGLEAGT $MMAP_CAT $file)
820 [[ $content == "RQQQQ" ]] || error "data mismatch: $content"
822 run_test 7a "Fake file detached between fault() and page_mkwrite() for RW-PCC"
825 local loopfile="$TMP/$tfile"
826 local mntpt="/mnt/pcc.$tdir"
827 local hsm_root="$mntpt/$tdir"
828 local file=$DIR/$tfile
832 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
833 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
834 setup_pcc_mapping $SINGLEAGT \
835 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0"
838 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
839 error "failed to attach file $file"
840 check_lpcc_state $file "readwrite"
841 check_file_data $SINGLEAGT $file "QQQQQ"
842 # define OBD_FAIL_LLITE_PCC_MKWRITE_PAUSE 0x1413
843 do_facet $SINGLEAGT $LCTL set_param fail_loc=0x1413 fail_val=20
844 # HSM released exists archived status
845 check_hsm_flags $file "0x0000000d"
847 # multiop mmap write increases the first character of each page with 1
848 do_facet $SINGLEAGT $MULTIOP $file OSMWUc &
852 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
853 error "failed to detach file $file"
855 wait $pid || error "multiop mmap write failed"
856 check_lpcc_state $file "none"
857 content=$(do_facet $SINGLEAGT $MMAP_CAT $file)
858 [[ $content == "RQQQQ" ]] || error "data mismatch: $content"
860 run_test 7b "Test the race with concurrent mkwrite and detach"
863 local loopfile="$TMP/$tfile"
864 local mntpt="/mnt/pcc.$tdir"
865 local hsm_root="$mntpt/$tdir"
866 local file=$DIR/$tfile
868 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
869 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
873 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
874 error "failed to attach file $file"
875 check_lpcc_state $file "readwrite"
876 check_file_data $SINGLEAGT $file "QQQQQ"
878 # define OBD_FAIL_LLITE_PCC_FAKE_ERROR 0x1411
879 do_facet $SINGLEAGT $LCTL set_param fail_loc=0x1411
880 do_facet $SINGLEAGT "echo -n ENOSPC_write > $file"
881 # Above write will return -ENOSPC failure and retry the IO on normal
882 # IO path. It will restore the HSM released file.
883 check_lpcc_state $file "none"
884 check_file_data $SINGLEAGT $file "ENOSPC_write"
886 run_test 8 "Test fake -ENOSPC tolerance for RW-PCC"
889 local loopfile="$TMP/$tfile"
890 local mntpt="/mnt/pcc.9a"
891 local hsm_root="$mntpt/$tdir"
892 local file=$DIR/$tfile
894 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
896 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMVER" -h "$hsm_root"
898 do_facet $SINGLEAGT $LCTL pcc list $MOUNT
900 touch $file || error "touch $file failed"
901 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
902 error "fail to attach $file"
903 check_lpcc_state $file "readwrite"
904 # write 60M data, it is larger than the capacity of PCC backend
905 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1M count=60 ||
906 error "fail to dd write $file"
907 check_lpcc_state $file "none"
908 check_file_size $SINGLEAGT $file 62914560
910 run_test 9 "Test -ENOSPC tolerance on loop PCC device for RW-PCC"
912 test_usrgrp_quota() {
913 local loopfile="$TMP/$tfile"
914 local mntpt="/mnt/pcc.$tdir"
915 local hsm_root="$mntpt/$tdir"
919 [[ $ug == "g" ]] && id=$RUNAS_GID
921 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
922 do_facet $SINGLEAGT quotacheck -c$ug $mntpt ||
923 error "quotacheck -c$ug $mntpt failed"
924 do_facet $SINGLEAGT quotaon -$ug $mntpt ||
925 error "quotaon -$ug $mntpt failed"
926 do_facet $SINGLEAGT setquota -$ug $id 0 20480 0 0 $mntpt ||
927 error "setquota -$ug $id on $mntpt failed"
928 do_facet $SINGLEAGT repquota -${ug}vs $mntpt
930 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMVER" -h "$hsm_root"
932 do_facet $SINGLEAGT $LCTL pcc list $MOUNT
934 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
936 local file1=$DIR/$tdir/${ug}quotaA
937 local file2=$DIR/$tdir/${ug}quotaB
939 dd if=/dev/zero of=$file1 bs=1M count=15 ||
940 error "dd write $file1 failed"
941 dd if=/dev/zero of=$file2 bs=1M count=15 ||
942 error "dd write $file2 failed"
943 chown $RUNAS_ID:$RUNAS_GID $file1 ||
944 error "chown $RUNAS_ID:$RUNAS_GID $file1 failed"
945 chown $RUNAS_ID:$RUNAS_GID $file2 ||
946 error "chown $RUNAS_ID:$RUNAS_GID $file2 failed"
947 do_facet $SINGLEAGT $RUNAS $LFS pcc attach -i $HSM_ARCHIVE_NUMBER \
948 $file1 || error "attach $file1 failed"
949 do_facet $SINGLEAGT $RUNAS $LFS pcc attach -i $HSM_ARCHIVE_NUMBER \
950 $file2 && error "attach $file2 should fail due to quota limit"
951 check_lpcc_state $file1 "readwrite"
952 check_lpcc_state $file2 "none"
954 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file1 bs=1M count=30 ||
955 error "dd write $file1 failed"
956 # -EDQUOT error should be tolerated via fallback to normal Lustre path.
957 check_lpcc_state $file1 "none"
958 do_facet $SINGLEAGT $LFS pcc detach -k $file1 ||
959 error "failed to detach file $file"
964 test_usrgrp_quota "u"
966 run_test 10a "Test RW-PCC with user quota on loop PCC device"
969 test_usrgrp_quota "g"
971 run_test 10b "Test RW-PCC with group quota on loop PCC device"
974 local loopfile="$TMP/$tfile"
975 local mntpt="/mnt/pcc.$tdir"
976 local hsm_root="$mntpt/$tdir"
977 local file=$DIR/$tfile
981 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
982 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
985 do_facet $SINGLEAGT "echo -n QQQQQ > $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 $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
992 error "failed to attach $file"
993 check_lpcc_state $file "readwrite"
994 check_file_data $SINGLEAGT $file "QQQQQ"
995 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
996 error "failed to detach $file"
997 rm $file || error "rm $file failed"
999 # The parent directory of the PCC file is immutable
1000 do_facet $SINGLEAGT "echo -n immutable_dir > $file"
1001 lpcc_path=$(lpcc_fid2path $hsm_root $file)
1002 lpcc_dir=$(dirname $lpcc_path)
1003 echo "Lustre file: $file LPCC dir: $lpcc_dir"
1004 do_facet $SINGLEAGT mkdir -p $lpcc_dir ||
1005 error "mkdir -p $lpcc_dir failed"
1006 do_facet $SINGLEAGT chattr +i $lpcc_dir ||
1007 error "chattr +i $lpcc_dir failed"
1008 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file &&
1009 error "attach $file with immutable directory should be failed"
1010 do_facet $SINGLEAGT chattr -i $lpcc_dir ||
1011 error "chattr -i $lpcc_dir failed"
1012 rm $file || error "rm $file failed"
1014 # The PCC file path is set to a directory
1015 do_facet $SINGLEAGT "echo -n pcc_file_path_is_dir > $file"
1016 lpcc_path=$(lpcc_fid2path $hsm_root $file)
1017 do_facet $SINGLEAGT mkdir -p $lpcc_path ||
1018 error "mkdir -p $lpcc_path failed"
1019 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file &&
1020 error "attach $file should fail as PCC path is a directory"
1021 rm $file || error "rm $file failed"
1023 run_test 11 "Test attach fault injection with simulated PCC file path"
1026 local file=$DIR/$tfile
1027 local hsm_root=$(hsm_root)
1031 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1032 setup_pcc_mapping $SINGLEAGT \
1033 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0"
1035 echo -n race_rw_attach_hsmremove > $file
1036 lpcc_path=$(lpcc_fid2path $hsm_root $file)
1037 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
1038 error "attach $file failed"
1039 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1040 error "detach $file failed"
1041 # HSM released exists archived status
1042 check_hsm_flags $file "0x0000000d"
1043 # define OBD_FAIL_LLITE_PCC_ATTACH_PAUSE 0x1414
1044 do_facet $SINGLEAGT $LCTL set_param fail_loc=0x1414 fail_val=20
1045 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file &
1047 $LFS hsm_state $file
1049 wait_request_state $(path2fid $file) RESTORE SUCCEED
1050 $LFS hsm_remove $file || error "hsm remove $file failed"
1052 do_facet $SINGLEAGT "[ -f $lpcc_path ]" &&
1053 error "RW-PCC cached file '$lpcc_path' should be removed"
1057 run_test 12 "RW-PCC attach races with concurrent HSM remove"
1060 local idstr="${1}id"
1061 local rule="${idstr}={$2}"
1063 local file=$DIR/$tdir/$tfile
1065 setup_pcc_mapping $SINGLEAGT \
1066 "$rule\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0"
1067 $LCTL pcc list $MOUNT
1069 do_facet $SINGLEAGT $LFS mkdir -i 0 $DIR/$tdir
1070 chmod 777 $DIR/$tdir || error "chmod 0777 $DIR/$tdir failed"
1072 rm -f $file || error "rm $file failed"
1073 do_facet $SINGLEAGT $myRUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1074 error "failed to dd write to $file"
1075 check_lpcc_state $file "readwrite"
1076 do_facet $SINGLEAGT $myRUNAS dd if=$file of=/dev/null bs=1024 count=1 ||
1077 error "failed to dd read from $file"
1078 do_facet $SINGLEAGT $myRUNAS $TRUNCATE $file 256 ||
1079 error "failed to truncate $file"
1080 do_facet $SINGLEAGT $myRUNAS $TRUNCATE $file 2048 ||
1081 error "failed to truncate $file"
1082 do_facet $SINGLEAGT $myRUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1083 error "failed to dd write from $file"
1084 check_lpcc_state $file "readwrite"
1086 do_facet $SINGLEAGT $myRUNAS $LFS pcc detach $file ||
1087 error "failed to detach file $file"
1088 wait_request_state $(path2fid $file) REMOVE SUCCEED
1089 check_lpcc_state $file "none"
1095 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1096 test_rule_id "u" "500" "runas -u 500"
1097 test_rule_id "g" "500" "runas -u 500 -g 500"
1099 run_test 13a "Test auto RW-PCC create caching for UID/GID rule"
1104 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1105 setup_pcc_mapping $SINGLEAGT \
1106 "fname={*.h5\ suffix.*\ Mid*dle}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0"
1107 $LCTL pcc list $MOUNT
1109 do_facet $SINGLEAGT mkdir -p $DIR/$tdir
1110 chmod 777 $DIR/$tdir || error "chmod 0777 $DIR/$tdir failed"
1112 file=$DIR/$tdir/prefix.h5
1113 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1024 count=1 ||
1114 error "failed to dd write to $file"
1115 check_lpcc_state $file "readwrite"
1116 do_facet $SINGLEAGT $myRUNAS $LFS pcc detach -k $file ||
1117 error "failed to detach file $file"
1118 check_lpcc_state $file "none"
1119 rm $file || error "rm $file failed"
1121 file=$DIR/$tdir/suffix.doc
1122 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1123 error "failed to dd write to $file"
1124 check_lpcc_state $file "readwrite"
1125 do_facet $SINGLEAGT $myRUNAS $LFS pcc detach -k $file ||
1126 error "failed to detach file $file"
1127 check_lpcc_state $file "none"
1128 rm $file || error "rm $file failed"
1130 file=$DIR/$tdir/MidPADdle
1131 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1132 error "failed to dd write to $file"
1133 check_lpcc_state $file "readwrite"
1134 do_facet $SINGLEAGT $myRUNAS $LFS pcc detach -k $file ||
1135 error "failed to detach file $file"
1136 check_lpcc_state $file "none"
1137 rm $file || error "rm $file failed"
1139 file=$DIR/$tdir/Midpad
1140 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1141 error "failed to dd write to $file"
1142 check_lpcc_state $file "none"
1143 rm $file || error "rm $file failed"
1145 run_test 13b "Test auto RW-PCC create caching for file name with wildcard"
1150 local loopfile="$TMP/$tfile"
1151 local mntpt="/mnt/pcc.$tdir"
1152 local hsm_root="$mntpt/$tdir"
1154 ! is_project_quota_supported &&
1155 echo "Skip project quota is not supported" && return 0
1157 enable_project_quota
1158 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1159 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1160 setup_pcc_mapping $SINGLEAGT \
1161 "projid={100\ 200}\&fname={*.h5},uid={500}\&gid={1000}\ rwid=$HSM_ARCHIVE_NUMBER"
1162 $LCTL pcc list $MOUNT
1163 do_facet $SINGLEAGT mkdir -p $DIR/$tdir
1164 chmod 777 $DIR/$tdir || error "chmod 0777 $DIR/$tdir failed"
1166 mkdir -p $DIR/$tdir/proj || error "mkdir $DIR/$tdir/proj failed"
1167 mkdir -p $DIR/$tdir/proj2 || error "mkdir $DIR/$tdir/proj2 failed"
1168 $LFS project -sp 100 $DIR/$tdir/proj ||
1169 error "failed to set project for $DIR/$tdir/proj"
1170 $LFS project -sp 200 $DIR/$tdir/proj2 ||
1171 error "failed to set project for $DIR/$tdir/proj2"
1173 file=$DIR/$tdir/proj/notcache
1174 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1024 count=1 ||
1175 error "failed to dd write to $file"
1176 check_lpcc_state $file "none"
1177 rm $file || error "rm $file failed"
1179 file=$DIR/$tdir/proj/autocache.h5
1180 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1024 count=1 ||
1181 error "failed to dd write to $file"
1182 check_lpcc_state $file "readwrite"
1183 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1184 error "failed to detach $file"
1185 rm $file || error "rm $file failed"
1187 file=$DIR/$tdir/proj2/notcache
1188 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1024 count=1 ||
1189 error "failed to dd write to $file"
1190 check_lpcc_state $file "none"
1191 rm $file || error "rm $file failed"
1193 file=$DIR/$tdir/proj2/autocache.h5
1194 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1024 count=1 ||
1195 error "failed to dd write to $file"
1196 check_lpcc_state $file "readwrite"
1197 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1198 error "failed to detach $file"
1199 rm $file || error "rm $file failed"
1201 file=$DIR/$tdir/ugidcache
1202 myRUNAS="runas -u 500 -g 1000"
1203 do_facet $SINGLEAGT $myRUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1204 error "failed to dd write to $file"
1205 check_lpcc_state $file "readwrite"
1206 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1207 error "failed to detach $file"
1208 rm $file || error "rm $file failed"
1210 run_test 13c "Check auto RW-PCC create caching for UID/GID/ProjID/fname rule"
1213 local file=$DIR/$tdir/$tfile
1215 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1216 setup_pcc_mapping $SINGLEAGT \
1217 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0"
1219 mkdir -p $DIR/$tdir || error "mkdir -p $DIR/$tdir failed"
1220 do_facet $SINGLEAGT "echo -n autodetach_data > $file"
1221 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER \
1222 $file || error "PCC attach $file failed"
1223 check_lpcc_state $file "readwrite"
1225 # Revoke the layout lock, the PCC-cached file will be
1226 # detached automatically.
1227 do_facet $SINGLEAGT $LCTL \
1228 set_param ldlm.namespaces.*mdc*.lru_size=clear
1229 check_file_data $SINGLEAGT $file "autodetach_data"
1230 check_lpcc_state $file "none"
1232 run_test 14 "Revocation of the layout lock should detach the file automatically"
1235 local loopfile="$TMP/$tfile"
1236 local mntpt="/mnt/pcc.$tdir"
1237 local hsm_root="$mntpt/$tdir"
1238 local file=$DIR/$tdir/$tfile
1240 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1241 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1244 mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
1245 chmod 777 $DIR/$tdir || error "chmod 777 $DIR/$tdir failed"
1247 echo "Check open attach for non-root user"
1248 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1249 error "failed to dd write to $file"
1250 do_facet $SINGLEAGT $RUNAS $LFS pcc attach -i $HSM_ARCHIVE_NUMBER \
1251 $file || error "failed to attach file $file"
1252 do_facet $SINGLEAGT $RUNAS $LFS pcc state $file
1253 check_lpcc_state $file "readwrite" $SINGLEAGT "$RUNAS"
1254 # Revoke the layout lock, the PCC-cached file will be
1255 # detached automatically.
1256 do_facet $SINGLEAGT $LCTL \
1257 set_param ldlm.namespaces.*mdc*.lru_size=clear
1258 check_lpcc_state $file "readwrite" $SINGLEAGT "$RUNAS"
1259 # Detach the file but keep the cache , as the file layout generation
1260 # is not changed, so the file is still valid cached in PCC, and can
1261 # be reused from PCC cache directly.
1262 do_facet $SINGLEAGT $RUNAS $LFS pcc detach -k $file ||
1263 error "PCC detach $file failed"
1264 check_lpcc_state $file "readwrite" $SINGLEAGT "$RUNAS"
1265 do_facet $SINGLEAGT $RUNAS $LFS pcc detach $file ||
1266 error "PCC detach $file failed"
1267 rm $file || error "rm $file failed"
1269 echo "check open attach for root user"
1270 do_facet $SINGLEAGT "echo -n autoattach_data > $file"
1271 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER \
1272 $file || error "PCC attach $file failed"
1273 check_lpcc_state $file "readwrite"
1275 # Revoke the layout lock, the PCC-cached file will be
1276 # detached automatically.
1277 do_facet $SINGLEAGT $LCTL \
1278 set_param ldlm.namespaces.*mdc*.lru_size=clear
1279 check_file_data $SINGLEAGT $file "autoattach_data"
1280 check_lpcc_state $file "readwrite"
1282 # Detach the file with -k option, as the file layout generation
1283 # is not changed, so the file is still valid cached in PCC,
1284 # and can be reused from PCC cache directly.
1285 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1286 error "PCC detach $file failed"
1287 check_lpcc_state $file "readwrite"
1288 # HSM released exists archived status
1289 check_hsm_flags $file "0x0000000d"
1290 check_file_data $SINGLEAGT $file "autoattach_data"
1292 # HSM restore the PCC cached file, the layout generation
1293 # was changed, so the file can not be auto attached.
1294 $LFS hsm_restore $file || error "failed to restore $file"
1295 wait_request_state $(path2fid $file) RESTORE SUCCEED
1296 check_lpcc_state $file "none"
1297 # HSM exists archived status
1298 check_hsm_flags $file "0x00000009"
1301 run_test 15 "Test auto attach at open when file is still valid cached"
1304 local loopfile="$TMP/$tfile"
1305 local mntpt="/mnt/pcc.$tdir"
1306 local hsm_root="$mntpt/$tdir"
1307 local file=$DIR/$tfile
1310 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1311 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1314 do_facet $SINGLEAGT "echo -n detach_data > $file"
1315 lpcc_path=$(lpcc_fid2path $hsm_root $file)
1316 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER \
1317 $file || error "PCC attach $file failed"
1318 check_lpcc_state $file "readwrite"
1319 # HSM released exists archived status
1320 check_hsm_flags $file "0x0000000d"
1322 echo "Test for reusing valid PCC cache"
1323 # Valid PCC cache can be reused
1324 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1325 error "PCC detach $file failed"
1326 check_lpcc_state $file "readwrite"
1327 # HSM released exists archived status
1328 check_hsm_flags $file "0x0000000d"
1330 echo "Test for the default detach"
1331 # Permanent detach by default, it will remove the PCC copy
1332 do_facet $SINGLEAGT $LFS pcc detach $file ||
1333 error "PCC detach $file failed"
1334 wait_request_state $(path2fid $file) REMOVE SUCCEED
1335 check_lpcc_state $file "none"
1336 # File is removed from PCC backend
1337 check_hsm_flags $file "0x00000000"
1338 do_facet $SINGLEAGT "[ -f $lpcc_path ]" &&
1339 error "RW-PCC cached file '$lpcc_path' should be removed"
1343 run_test 16 "Test detach with different options"
1346 local agt_host=$(facet_active_host $SINGLEAGT)
1347 local loopfile="$TMP/$tfile"
1348 local mntpt="/mnt/pcc.$tdir"
1349 local hsm_root="$mntpt/$tdir"
1350 local file=$DIR/$tfile
1352 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1353 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1354 setup_pcc_mapping $SINGLEAGT \
1355 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ open_attach=0\ stat_attach=0"
1357 do_facet $SINGLEAGT $LCTL pcc list $MOUNT
1359 do_facet $SINGLEAGT "echo -n layout_refresh_data > $file"
1360 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
1361 error "PCC attach $file failed"
1362 check_lpcc_state $file "readwrite"
1364 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1365 error "PCC detach $file failed"
1366 check_lpcc_state $file "none"
1368 # Truncate should attach the file into PCC automatically
1369 # as the PCC copy is still valid.
1370 echo "Verify auto attach during IO for truncate"
1371 do_facet $SINGLEAGT $TRUNCATE $file 4 || error "truncate $file failed"
1372 check_lpcc_state $file "readwrite"
1374 echo "Verify auto attach during IO for read/write"
1375 rmultiop_start $agt_host $file O_r || error "open $file failed"
1378 # Revoke the layout lock, the PCC-cached file will be
1379 # detached automatically.
1380 do_facet $SINGLEAGT $LCTL \
1381 set_param ldlm.namespaces.*mdc*.lru_size=clear
1383 check_lpcc_state $file "none"
1384 rmultiop_stop $agt_host || error "close $file failed"
1386 check_lpcc_state $file "readwrite"
1388 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1389 error "PCC detach $file failed"
1390 check_lpcc_state $file "none"
1392 run_test 17 "Test auto attach for layout refresh"
1395 local agt_host=$(facet_active_host $SINGLEAGT)
1396 local loopfile="$TMP/$tfile"
1397 local mntpt="/mnt/pcc.$tdir"
1398 local hsm_root="$mntpt/$tdir"
1399 local file=$DIR/$tfile
1403 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1404 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1405 setup_pcc_mapping $SINGLEAGT \
1406 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER"
1408 do_facet $SINGLEAGT $LCTL pcc list $MOUNT
1409 do_facet $SINGLEAGT dd if=/dev/urandom of=$file bs=1M count=4 ||
1410 error "failed to write $file"
1411 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
1412 error "failed to attach $file"
1413 do_facet $SINGLEAGT $LFS pcc state $file
1414 check_lpcc_state $file "readwrite"
1415 do_facet $SINGLEAGT $LFS pcc detach --keep $file ||
1416 error "failed to detach $file"
1417 do_facet $SINGLEAGT $LFS pcc state $file
1418 $CHECKSTAT -s 4194304 $file
1419 dd if=/dev/zero of=$DIR2/$tfile seek=1k bs=1k count=1 ||
1420 error "failed to write $DIR2/$tfile"
1421 oldmd5=$(md5sum $DIR2/$tfile | awk '{print $1}')
1422 $CHECKSTAT -s 1049600 $DIR2/$tfile || error "$DIR2/$tfile size wrong"
1424 local lpcc_path=$(lpcc_fid2path $hsm_root $file)
1426 do_facet $SINGLEAGT $LFS pcc state $file
1427 check_file_size $SINGLEAGT $lpcc_path 4194304
1428 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
1429 error "failed to attach $file"
1430 check_lpcc_sizes $SINGLEAGT $lpcc_path $file 1049600
1431 newmd5=$(do_facet $SINGLEAGT md5sum $file | awk '{print $1}')
1432 [ "$oldmd5" == "$newmd5" ] || error "md5sum differ: $oldmd5 != $newmd5"
1433 do_facet $SINGLEAGT $LFS pcc detach $file ||
1434 error "failed to detach $file"
1436 run_test 18 "Verify size correctness after re-attach the file"
1439 local agt_host=$(facet_active_host $SINGLEAGT)
1440 local loopfile="$TMP/$tfile"
1441 local mntpt="/mnt/pcc.$tdir"
1442 local hsm_root="$mntpt/$tdir"
1443 local file=$DIR/$tfile
1445 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1446 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1447 setup_pcc_mapping $SINGLEAGT \
1448 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0"
1450 do_facet $SINGLEAGT "echo -n QQQQQ > $file" || error "echo $file failed"
1451 lpcc_path=$(lpcc_fid2path $hsm_root $file)
1452 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
1453 error "Failed to attach $file"
1454 check_lpcc_state $file "readwrite"
1455 check_lpcc_sizes $SINGLEAGT $file $lpcc_path 5
1456 do_facet $SINGLEAGT $LFS pcc detach --keep $file ||
1457 error "Failed to detach $file"
1458 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
1459 error "Failed to attach $file"
1460 check_lpcc_sizes $SINGLEAGT $file $lpcc_path 5
1461 do_facet $SINGLEAGT $LFS pcc detach --keep $file ||
1462 error "Failed to detach $file"
1464 run_test 19 "Verify the file re-attach works as expected"
1467 local agt_host=$(facet_active_host $SINGLEAGT)
1468 local loopfile="$TMP/$tfile"
1469 local mntpt="/mnt/pcc.$tdir"
1470 local hsm_root="$mntpt/$tdir"
1471 local file=$DIR/$tfile
1473 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1474 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1475 setup_pcc_mapping $SINGLEAGT \
1476 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER"
1478 do_facet $SINGLEAGT "echo -n QQQQQ > $file" ||
1479 error "echo $file failed"
1480 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
1481 error "Failed to attach $file"
1482 do_facet $SINGLEAGT "echo 3 > /proc/sys/vm/drop_caches"
1483 check_lpcc_state $file "readwrite"
1484 do_facet $SINGLEAGT "echo 3 > /proc/sys/vm/drop_caches"
1485 do_facet $SINGLEAGT "echo 3 > /proc/sys/vm/drop_caches"
1486 check_lpcc_state $file "readwrite"
1487 do_facet $SINGLEAGT $LFS pcc detach $file ||
1488 error "Failed to detach $file"
1490 run_test 20 "Auto attach works after the inode was once evicted from cache"
1493 check_and_cleanup_lustre