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"
57 if [[ -r /etc/redhat-release ]]; then
58 rhel_version=$(sed -e 's/[^0-9.]*//g' /etc/redhat-release)
59 if (( $(version_code $rhel_version) >= $(version_code 9.3.0) )); then
60 always_except EX-8739 6 7a 7b 23 # PCC-RW
61 always_except LU-17289 102 # fio io_uring
67 # if there is no CLIENT1 defined, some tests can be ran on localhost
68 CLIENT1=${CLIENT1:-$HOSTNAME}
69 # if CLIENT2 doesn't exist then use CLIENT1 instead
70 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
72 # Exception is the test which need two separate nodes
73 CLIENT2=${CLIENT2:-$CLIENT1}
79 local expected_size="$3"
81 size=$(do_facet $client stat "--printf=%s" $fpath)
82 [[ $size == "$expected_size" ]] || error \
83 "expected $fpath size: $expected_size got: $size"
90 local lustre_fpath="$3"
91 local expected_size="$4"
93 check_file_size $client $lpcc_fpath $expected_size
94 check_file_size $client $lustre_fpath $expected_size
101 local expected_data="$3"
104 # if $pid is set, then run command within namespace for that process
105 path_data=$(do_facet $client ${pid:+nsenter -t $pid -U -m} cat $path)
106 [[ "x$path_data" == "x$expected_data" ]] ||
107 error "expected $path: $expected_data, got: $path_data"
113 local lpcc_fpath="$2"
114 local lustre_fpath="$3"
115 local expected_data="$4"
117 check_file_data "$client" "$lpcc_fpath" "$expected_data"
118 check_file_data "$client" "$lustre_fpath" "$expected_data"
124 local lustre_path="$2"
125 local fid=$(path2fid $lustre_path)
127 local seq=$(echo $fid | awk -F ':' '{print $1}')
128 local oid=$(echo $fid | awk -F ':' '{print $2}')
129 local ver=$(echo $fid | awk -F ':' '{print $3}')
131 case "$HSMTOOL_ARCHIVE_FORMAT" in
133 printf "%s/%04x/%04x/%04x/%04x/%04x/%04x/%s" \
134 $hsm_root $((oid & 0xFFFF)) \
135 $((oid >> 16 & 0xFFFF)) \
137 $((seq >> 16 & 0xFFFF)) \
138 $((seq >> 32 & 0xFFFF)) \
139 $((seq >> 48 & 0xFFFF)) $fid
142 printf "%s/%04x/%s" $hsm_root $(((oid ^ seq) & 0xFFFF)) $fid
149 local lustre_path="$1"
150 local expected_state="$2"
151 local facet=${3:-$SINGLEAGT}
153 local state=$(do_facet $facet $myRUNAS $LFS pcc state $lustre_path |
154 awk -F 'type: ' '{print $2}' | awk -F ',' '{print $1}')
156 [[ "x$state" == "x$expected_state" ]] || error \
157 "$lustre_path expected pcc state: $expected_state, but got: $state"
163 # populate MDT device array
166 # cleanup from previous bad setup
169 # for recovery tests, coordinator needs to be started at mount
171 # the lustre conf must be without hsm on (like for sanity.sh)
172 echo "Set HSM on and start"
173 cdt_set_mount_state enabled
174 cdt_check_state enabled
176 echo "Set sanity-hsm HSM policy"
177 cdt_set_sanity_policy
179 # finished requests are quickly removed from list
180 set_hsm_param grace_delay 10
182 cleanup_pcc_mapping() {
183 local facet=${1:-$SINGLEAGT}
185 do_facet $facet $LCTL pcc clear $MOUNT
188 setup_pcc_mapping() {
189 local facet=${1:-$SINGLEAGT}
190 local hsm_root=${hsm_root:-$(hsm_root "$facet")}
193 [ -z "$param" ] && param="projid={100}\ rwid=$HSM_ARCHIVE_NUMBER"
194 stack_trap "cleanup_pcc_mapping $facet" EXIT
195 do_facet $facet $LCTL pcc add $MOUNT $hsm_root -p $param ||
196 error "Setup PCC backend $hsm_root on $MOUNT failed"
204 do_facet $facet lsof $mntpt || true
205 do_facet $facet $UMOUNT $mntpt
216 do_facet $facet mkdir -p $mntpt || error "mkdir -p $mntpt failed"
217 stack_trap "do_facet $facet rm -rf $mntpt" EXIT
218 do_facet $facet dd if=/dev/zero of=$file bs=1M count=$size
219 stack_trap "do_facet $facet rm -f $file" EXIT
220 do_facet $facet mkfs.ext4 $file ||
221 error "mkfs.ext4 $file failed"
222 do_facet $facet file $file
223 do_facet $facet mount -t ext4 -o loop,usrquota,grpquota $file $mntpt ||
224 error "mount -o loop,usrquota,grpquota $file $mntpt failed"
225 stack_trap "umount_loopdev $facet $mntpt" EXIT
232 local agt_facet=$SINGLEAGT
233 local loopfile="$TMP/$tfile"
234 local mntpt="/mnt/pcc.$tdir"
235 local hsm_root="$mntpt/$tdir"
236 local file=$DIR/$tdir/$tfile
241 $project && enable_project_quota
243 do_facet $SINGLEAGT rm -rf $hsm_root
244 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
245 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
247 is_project_quota_supported || project=false
249 do_facet $SINGLEAGT $LFS mkdir -i0 -c1 $DIR/$tdir
250 setup_pcc_mapping $SINGLEAGT "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ pccrw=1"
251 $project && lfs project -sp $project_id $DIR2/$tdir
253 do_facet $SINGLEAGT "echo -n attach_origin > $file"
255 check_lpcc_state $file "none"
256 do_facet $SINGLEAGT $LFS pcc attach -w \
257 -i $HSM_ARCHIVE_NUMBER $file ||
258 error "pcc attach $file failed"
261 check_lpcc_state $file "readwrite"
262 # HSM released exists archived status
263 check_hsm_flags $file "0x0000000d"
264 lpcc_path=$(lpcc_fid2path $hsm_root $file)
265 check_lpcc_data $SINGLEAGT $lpcc_path $file "attach_origin"
267 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=7654321 count=1
268 check_lpcc_sizes $SINGLEAGT $lpcc_path $file 7654321
270 do_facet $SINGLEAGT $TRUNCATE $file 1234567 ||
271 error "truncate failed"
272 check_lpcc_sizes $SINGLEAGT $lpcc_path $file 1234567
273 check_lpcc_state $file "readwrite"
275 do_facet $SINGLEAGT "echo -n file_data > $file"
276 check_lpcc_state $file "readwrite"
277 # HSM released exists archived status
278 check_hsm_flags $file "0x0000000d"
279 check_lpcc_data $SINGLEAGT $lpcc_path $file "file_data"
281 echo "Restore testing..."
282 if [ $CLIENTCOUNT -lt 2 -o $restore ]; then
283 $LFS hsm_restore $file || error \
284 "failed to restore $file"
285 wait_request_state $(path2fid $file) RESTORE SUCCEED
287 path_data=$(do_node $CLIENT2 cat $file)
288 [[ "x$path_data" == "xfile_data" ]] || error \
289 "expected file_data, got: $path_data"
292 check_lpcc_state $file "none"
293 # HSM exists archived status
294 check_hsm_flags $file "0x00000009"
296 echo -n "new_data" > $file
297 check_lpcc_state $file "none"
298 # HSM exists dirty archived status
299 check_hsm_flags $file "0x0000000b"
300 check_file_data $SINGLEAGT $file "new_data"
302 echo "Attach and detach testing"
304 do_facet $SINGLEAGT "echo -n new_data2 > $file"
306 check_lpcc_state $file "none"
307 do_facet $SINGLEAGT $LFS pcc attach -w \
308 -i $HSM_ARCHIVE_NUMBER $file ||
309 error "PCC attach $file failed"
311 check_lpcc_state $file "readwrite"
312 # HSM released exists archived status
313 check_hsm_flags $file "0x0000000d"
314 do_facet $SINGLEAGT "echo -n attach_detach > $file"
315 echo "Start to detach the $file"
316 do_facet $SINGLEAGT $LFS pcc detach $file ||
317 error "PCC detach $file failed"
318 wait_request_state $(path2fid $file) REMOVE SUCCEED
320 check_lpcc_state $file "none"
321 # The file is removed from PCC
322 check_hsm_flags $file "0x00000000"
323 check_file_data $SINGLEAGT $file "attach_detach"
327 lpcc_rw_test true false
329 run_test 1a "Test manual lfs pcc attach with manual HSM restore"
332 lpcc_rw_test false false
334 run_test 1b "Test manual lfs pcc attach with restore on remote access"
337 lpcc_rw_test true true
339 run_test 1c "Test automated attach using Project ID with manual HSM restore"
342 lpcc_rw_test false true
344 run_test 1d "Test Project ID with remote access"
347 local file=$DIR/$tdir/$tfile
348 local hsm_root=$(hsm_root)
351 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
352 setup_pcc_mapping $SINGLEAGT \
353 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0\ pccrw=1"
354 $LCTL pcc list $MOUNT
355 mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
356 chmod 777 $DIR/$tdir || error "chmod 777 $DIR/$tdir failed"
358 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
359 error "failed to dd write to $file"
360 do_facet $SINGLEAGT $RUNAS $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER \
361 $file || error "failed to attach file $file"
362 check_lpcc_state $file "readwrite"
363 do_facet $SINGLEAGT $RUNAS dd if=$file of=/dev/null bs=1024 count=1 ||
364 error "failed to dd read from $file"
365 do_facet $SINGLEAGT $RUNAS $TRUNCATE $file 256 ||
366 error "failed to truncate $file"
367 do_facet $SINGLEAGT $RUNAS $TRUNCATE $file 2048 ||
368 error "failed to truncate $file"
369 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
370 error "failed to dd write to $file"
371 check_lpcc_state $file "readwrite"
373 do_facet $SINGLEAGT $RUNAS $LFS pcc detach -k $file ||
374 error "failed to detach file $file"
375 check_lpcc_state $file "none"
377 # non-root user is forbidden to access PCC file directly
378 lpcc_path=$(lpcc_fid2path $hsm_root $file)
379 do_facet $SINGLEAGT $RUNAS touch $lpcc_path &&
380 error "non-root user can touch access PCC file $lpcc_path"
381 do_facet $SINGLEAGT $RUNAS dd if=$lpcc_path of=/dev/null bs=1024 \
382 count=1 && error "non-root user can read PCC file $lpcc_path"
383 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$lpcc_path bs=1024 \
384 count=1 && error "non-root user can write PCC file $lpcc_path"
386 local perm=$(do_facet $SINGLEAGT stat -c %a $lpcc_path)
388 [[ $perm == "0" ]] || error "PCC file permission ($perm) is not zero"
390 do_facet $SINGLEAGT $RUNAS $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER \
391 $file || error "failed to attach file $file"
392 check_lpcc_state $file "readwrite"
394 do_facet $SINGLEAGT $RUNAS $LFS pcc detach $file ||
395 error "failed to detach file $file"
396 wait_request_state $(path2fid $file) REMOVE SUCCEED
397 check_lpcc_state $file "none"
399 run_test 1e "Test RW-PCC with non-root user"
403 local agt_facet=$SINGLEAGT
404 local loopfile="$TMP/$tfile"
405 local mntpt="/mnt/pcc.$tdir"
406 local hsm_root="$mntpt/$tdir"
407 local file=$DIR/$tdir/$tfile
409 ! is_project_quota_supported &&
410 skip "project quota is not supported"
413 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
414 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
415 setup_pcc_mapping $SINGLEAGT \
416 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ open_attach=0\ stat_attach=0\ pccrw=1"
418 do_facet $SINGLEAGT $LFS mkdir -i0 -c1 $DIR/$tdir
419 chmod 777 $DIR/$tdir || error "chmod 0777 $DIR/$tdir failed"
420 $LFS project -sp $project_id $DIR/$tdir ||
421 error "failed to set project for $DIR/$tdir"
423 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
424 error "failed to dd write to $file"
426 check_lpcc_state $file "readwrite"
427 do_facet $SINGLEAGT $RUNAS dd if=$file of=/dev/null bs=1024 count=1 ||
428 error "failed to dd read from $file"
429 do_facet $SINGLEAGT $RUNAS $TRUNCATE $file 256 ||
430 error "failed to truncate $file"
431 do_facet $SINGLEAGT $RUNAS $TRUNCATE $file 2048 ||
432 error "failed to truncate $file"
433 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=256 count=1 ||
434 error "failed to dd write from $file"
435 check_lpcc_state $file "readwrite"
437 # non-root user is forbidden to access PCC file directly
438 lpcc_path=$(lpcc_fid2path $hsm_root $file)
439 do_facet $SINGLEAGT $RUNAS touch $lpcc_path &&
440 error "non-root user can touch access PCC file $lpcc_path"
441 do_facet $SINGLEAGT $RUNAS dd if=$lpcc_path of=/dev/null bs=1024 \
442 count=1 && error "non-root user can read PCC file $lpcc_path"
443 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$lpcc_path bs=1024 \
444 count=1 && error "non-root user can write PCC file $lpcc_path"
446 do_facet $SINGLEAGT $RUNAS $LFS pcc detach $file ||
447 error "failed to detach file $file"
448 wait_request_state $(path2fid $file) REMOVE SUCCEED
449 check_lpcc_state $file "none"
451 run_test 1f "Test auto RW-PCC cache with non-root user"
454 local loopfile="$TMP/$tfile"
455 local mntpt="/mnt/pcc.$tdir"
456 local hsm_root="$mntpt/$tdir"
457 local file=$DIR/$tfile
459 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
460 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
461 setup_pcc_mapping $SINGLEAGT "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ pccrw=1"
463 dd if=/dev/zero of=$file bs=1024 count=1 ||
464 error "failed to dd write to $file"
465 chmod 600 $file || error "chmod 600 $file failed"
466 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 &&
467 error "non-root user can dd write $file"
468 do_facet $SINGLEAGT $RUNAS dd if=$file of=/dev/null bs=1024 count=1 &&
469 error "non-root user can dd read $file"
470 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER $file ||
471 error "failed to attach file $file"
472 check_lpcc_state $file "readwrite"
473 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 &&
474 error "non-root user can dd write to $file"
475 do_facet $SINGLEAGT $RUNAS dd if=$file of=/dev/null bs=1024 count=1 &&
476 error "non-root user can dd read $file"
477 chmod 777 $DIR2/$tfile || error "chmod 777 $DIR2/$tfile failed"
478 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
479 error "non-root user cannot write $file with permission (777)"
481 do_facet $SINGLEAGT $RUNAS $LFS pcc detach $file &&
482 error "non-root user or non owner can detach $file"
483 chown $RUNAS_ID $file || error "chown $RUNAS_ID $file failed"
484 do_facet $SINGLEAGT $RUNAS $LFS pcc detach $file ||
485 error "failed to detach file $file"
486 wait_request_state $(path2fid $file) REMOVE SUCCEED
487 check_lpcc_state $file "none"
488 do_facet $SINGLEAGT $RUNAS dd if=$file of=/dev/null bs=1024 count=1 ||
489 error "non-root user cannot read to $file with permisson (777)"
491 run_test 1g "General permission test for RW-PCC"
494 # When a process created a LPCC file and holding the open,
495 # another process on the same client should be able to open the file.
499 local agt_facet=$SINGLEAGT
500 local loopfile="$TMP/$tfile"
501 local mntpt="/mnt/pcc.$tdir"
502 local hsm_root="$mntpt/$tdir"
503 local agt_host=$(facet_active_host $SINGLEAGT)
505 ! is_project_quota_supported &&
506 skip "project quota is not supported" && return
509 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
510 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
511 setup_pcc_mapping $SINGLEAGT "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ pccrw=1"
512 file=$DIR/$tdir/multiop
513 $LFS mkdir -i -1 -c $MDSCOUNT $DIR/$tdir
516 do_facet $SINGLEAGT $LFS project -sp $project_id $DIR/$tdir ||
517 error "failed to set project quota"
518 rmultiop_start $agt_host $file O_c || error "open $file failed"
519 # HSM released exists archived status
520 check_hsm_flags $file "0x0000000d"
521 do_facet $SINGLEAGT "echo -n multiopen_data > $file" ||
522 error "failed to echo multiopen_data to $file"
524 lpcc_path=$(lpcc_fid2path $hsm_root $file)
525 do_facet $SINGLEAGT ls -l $lpcc_path ||
526 error "failed to ls $lpcc_path"
527 check_lpcc_data $SINGLEAGT $lpcc_path $file "multiopen_data"
528 # HSM released exists archived status
529 check_hsm_flags $file "0x0000000d"
531 do_facet $SINGLEAGT $LFS pcc detach $file ||
532 error "failed to detach $file"
533 rmultiop_stop $agt_host || error "close $file failed"
535 run_test 2a "Test multi open when creating"
537 get_remote_client() {
538 current_id=$(do_facet $SINGLEAGT hostname)
539 for client in ${CLIENTS//,/ }
541 r_id=$(do_node $client hostname)
542 if [ $r_id != $current_id ]; then
550 # When a process created a LPCC file and holding the open, another
551 # process on the different client should be able to open the file
552 # and perform IO on the file.
555 local agt_facet=$SINGLEAGT
556 local agt_host=$(facet_active_host $SINGLEAGT)
557 local loopfile="$TMP/$tfile"
558 local mntpt="/mnt/pcc.$tdir"
559 local hsm_root="$mntpt/$tdir"
561 needclients 2 || return 0
563 remote_client=$(get_remote_client)
566 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
567 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
568 setup_pcc_mapping $SINGLEAGT "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ pccrw=1"
569 file=$DIR/$tdir/multiop
573 do_facet $SINGLEAGT "echo -n file_data > $file"
574 do_facet $SINGLEAGT lfs pcc attach -w -i $HSM_ARCHIVE_NUMBER \
575 $file || error "PCC attach $file failed"
576 check_lpcc_state $file "readwrite"
578 rmultiop_start $agt_host $file O_c || error "open $file failed"
580 do_node $remote_client "echo -n multiopen_data > $file"
582 # PCC cached file should be automatically detached
583 check_lpcc_state $file "none"
585 check_file_data $SINGLEAGT $file "multiopen_data"
586 rmultiop_stop $agt_host || error "close $file failed"
587 check_file_data $SINGLEAGT $file "multiopen_data"
589 do_node $remote_client cat $file || error \
590 "cat $file on remote client failed"
591 do_node $remote_client echo -n "multiopen_data" > $file \
592 || error "write $file on remote client failed"
594 run_test 2b "Test multi remote open when creating"
597 local agt_host=$(facet_active_host $SINGLEAGT)
598 local loopfile="$TMP/$tfile"
599 local mntpt="/mnt/pcc.$tdir"
600 local hsm_root="$mntpt/$tdir"
601 local file=$DIR/$tdir/$tfile
602 local file2=$DIR2/$tdir/$tfile
605 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
606 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
607 setup_pcc_mapping $SINGLEAGT "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ pccrw=1"
611 do_facet $SINGLEAGT "echo -n file_data > $file"
612 do_facet $SINGLEAGT lfs pcc attach -w -i $HSM_ARCHIVE_NUMBER \
613 $file || error "PCC attach $file failed"
614 check_lpcc_state $file "readwrite"
616 rmultiop_start $agt_host $file O_c || error "open $file failed"
618 echo -n multiopen_data > $file2
620 # PCC cached file should be automatically detached
621 check_lpcc_state $file "none"
623 check_file_data $SINGLEAGT $file "multiopen_data"
624 rmultiop_stop $agt_host || error "close $file failed"
625 check_file_data $SINGLEAGT $file "multiopen_data"
627 cat $file2 || error "cat $file on mount $MOUNT2 failed"
628 echo -n "multiopen_data" > $file2 ||
629 error "write $file on mount $MOUNT2 failed"
631 run_test 2c "Test multi open on different mount points when creating"
634 local file=$DIR/$tdir/$tfile
635 local file2=$DIR2/$tdir/$tfile
637 $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
638 skip "Server does not support PCC-RO"
640 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
641 setup_pcc_mapping $SINGLEAGT \
642 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0\ pccrw=1\ pccro=1"
644 mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir failed"
645 dd if=/dev/zero of=$file2 bs=1024 count=1 ||
646 error "failed to dd write to $file"
648 echo "Start to RW-PCC attach/detach the file: $file"
649 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER $file ||
650 error "failed to attach file $file"
651 check_lpcc_state $file "readwrite"
652 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
653 error "failed to detach file $file"
654 check_lpcc_state $file "none"
656 echo "Repeat to RW-PCC attach/detach the same file: $file"
657 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER $file ||
658 error "failed to attach file $file"
659 check_lpcc_state $file "readwrite"
660 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
661 error "failed to detach file $file"
662 check_lpcc_state $file "none"
664 rm -f $file || error "failed to remove $file"
665 echo "pccro_data" > $file
667 echo "Start to RO-PCC attach/detach the file: $file"
668 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
669 error "failed to attach file $file"
670 check_lpcc_state $file "readonly"
671 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
672 error "failed to detach file $file"
673 check_lpcc_state $file "none"
675 echo "Repeat to RO-PCC attach/detach the same file: $file"
676 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
677 error "failed to attach file $file"
678 check_lpcc_state $file "readonly"
679 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
680 error "failed to detach file $file"
681 check_lpcc_state $file "none"
683 run_test 3a "Repeat attach/detach operations"
687 local file=$DIR/$tdir/$tfile
689 needclients 3 || return 0
691 # Start all of the copytools and setup PCC
692 for n in $(seq $AGTCOUNT); do
693 copytool setup -f agt$n -a $n -m $MOUNT -h $(hsm_root agt$n)
694 setup_pcc_mapping agt$n "projid={100}\ rwid=$n\ auto_attach=0\ pccrw=1\ pccro=1"
697 mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir failed"
698 dd if=/dev/zero of=$file bs=1024 count=1 ||
699 error "failed to dd write to $file"
701 echo "Start to RW-PCC attach/detach $file on $agt1_HOST"
702 do_facet agt1 $LFS pcc attach -w -i 1 $file ||
703 error "failed to attach file $file"
704 check_lpcc_state $file "readwrite" agt1
705 do_facet agt1 $LFS pcc detach -k $file ||
706 error "failed to detach file $file"
707 check_lpcc_state $file "none" agt1
709 echo "Repeat to RW-PCC attach/detach $file on $agt2_HOST"
710 do_facet agt2 $LFS pcc attach -w -i 2 $file ||
711 error "failed to attach file $file"
712 check_lpcc_state $file "readwrite" agt2
713 do_facet agt2 $LFS pcc detach -k $file ||
714 error "failed to detach file $file"
715 check_lpcc_state $file "none" agt2
717 echo "Try RW-PCC attach on two agents"
718 do_facet agt1 $LFS pcc attach -w -i 1 $file ||
719 error "failed to attach file $file"
720 check_lpcc_state $file "readwrite" agt1
721 do_facet agt2 $LFS pcc attach -w -i 2 $file ||
722 error "failed to attach file $file"
723 check_lpcc_state $file "readwrite" agt2
724 # The later attach PCC agent should succeed,
725 # the former agent should be detached automatically.
726 check_lpcc_state $file "none" agt1
727 do_facet agt2 $LFS pcc detach -k $file ||
728 error "failed to detach file $file"
729 check_lpcc_state $file "none" agt2
731 echo "Start to RO-PCC attach/detach $file on $agt1_HOST"
732 do_facet agt1 $LFS pcc attach -r -i 1 $file ||
733 error "failed to attach file $file"
734 check_lpcc_state $file "readonly" agt1
735 do_facet agt1 $LFS pcc detach -k $file ||
736 error "failed to detach file $file"
737 check_lpcc_state $file "none" agt1
739 echo "Repeat to RO-PCC attach/detach $file on $agt2_HOST"
740 do_facet agt2 $LFS pcc attach -r -i 2 $file ||
741 error "failed to attach file $file"
742 check_lpcc_state $file "readonly" agt2
743 do_facet agt2 $LFS pcc detach -k $file ||
744 error "failed to detach file $file"
745 check_lpcc_state $file "none" agt2
747 echo "Try RO-PCC attach on two agents"
748 do_facet agt1 $LFS pcc attach -r -i 1 $file ||
749 error "failed to attach file $file"
750 check_lpcc_state $file "readonly" agt1
751 do_facet agt2 $LFS pcc attach -r -i 2 $file ||
752 error "failed to attach file $file"
753 check_lpcc_state $file "readonly" agt2
754 check_lpcc_state $file "readonly" agt1
755 do_facet agt2 $LFS pcc detach -k $file ||
756 error "failed to detach file $file"
757 check_lpcc_state $file "none" agt2
758 do_facet agt1 $LFS pcc detach -k $file ||
759 error "failed to detach file $file"
760 check_lpcc_state $file "none" agt1
762 run_test 3b "Repeat attach/detach operations on multiple clients"
766 local loopfile="$TMP/$tfile"
767 local mntpt="/mnt/pcc.$tdir"
768 local hsm_root="$mntpt/$tdir"
769 local excepts="-e 6 -e 7 -e 8 -e 9"
771 ! is_project_quota_supported &&
772 skip "project quota is not supported" && return
775 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
776 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
777 setup_pcc_mapping $SINGLEAGT "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ pccrw=1"
779 mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir failed"
780 lfs project -sp $project_id $DIR/$tdir ||
781 error "lfs project -sp $project_id $DIR/$tdir failed"
783 # 1. mmap_sanity tst7 failed on the local ext4 filesystem.
784 # It seems that Lustre filesystem does special process for tst 7.
785 # 2. There is a mmap problem for PCC when multiple clients read/write
786 # on a shared mmapped file for mmap_sanity tst 6.
787 # 3. Current CentOS8 kernel does not strictly obey POSIX syntax for
788 # mmap() within the maping but beyond current end of the underlying
789 # files: It does not send SIGBUS signals to the process.
790 # 4. For negative file offset, sanity_mmap also failed on 48 bits
791 # ldiksfs backend due to too large offset: "Value too large for
792 # defined data type".
793 # mmap_sanity tst7/tst8/tst9 all failed on Lustre and local ext4.
794 # Thus, we exclude sanity tst6/tst7/tst8/tst9 from the PCC testing.
795 $LUSTRE/tests/mmap_sanity -d $DIR/$tdir -m $DIR2/$tdir $excepts ||
796 error "mmap_sanity test failed"
799 # Revoke the layout lock, the PCC-cached file will be
800 # detached automatically.
801 do_facet $SINGLEAGT $LCTL \
802 set_param ldlm.namespaces.*mdc*.lru_size=clear
803 rm -rf $DIR/$tdir || error "failed to remove $DIR/$tdir"
805 run_test 4 "Auto cache test for mmap"
808 local file=$DIR/$tfile
809 local loopfile="$TMP/$tfile"
810 local mntpt="/mnt/pcc.$tdir"
811 local hsm_root="$mntpt/$tdir"
813 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
814 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
815 setup_pcc_mapping $SINGLEAGT "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ pccrw=1"
817 do_facet $SINGLEAGT "echo -n attach_mmap_data > $file" ||
818 error "echo $file failed"
820 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER $file ||
821 error "failed to attach file $file"
822 check_lpcc_state $file "readwrite"
824 local content=$($MMAP_CAT $file)
826 [[ $content == "attach_mmap_data" ]] ||
827 error "mmap cat data mismatch: $content"
829 $LFS hsm_restore $file || error "failed to restore $file"
830 wait_request_state $(path2fid $file) RESTORE SUCCEED
831 check_lpcc_state $file "none"
833 content=$($MMAP_CAT $file)
834 [[ $content == "attach_mmap_data" ]] ||
835 error "mmap cat data mismatch: $content"
837 run_test 5 "Mmap & cat a RW-PCC cached file"
840 local loopfile="$TMP/$tfile"
841 local mntpt="/mnt/pcc.$tdir"
842 local hsm_root="$mntpt/$tdir"
843 local file=$DIR/$tfile
846 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
847 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
848 setup_pcc_mapping $SINGLEAGT "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ pccrw=1"
850 echo -n mmap_write_data > $file || error "echo write $file failed"
851 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER $file ||
852 error "failed to attach file $file"
853 check_lpcc_state $file "readwrite"
855 do_facet $SINGLEAGT $MULTIOP $file OSMWUc ||
856 error "could not mmap $file"
857 check_lpcc_state $file "readwrite"
858 content=$(do_facet $SINGLEAGT $MMAP_CAT $file)
859 # After mmap write via multiop, the first character of each page
861 [[ $content == "nmap_write_data" ]] ||
862 error "mmap write data mismatch: $content"
863 check_lpcc_state $file "readwrite"
865 do_facet $SINGLEAGT $LFS pcc detach $file ||
866 error "failed to detach file $file"
867 wait_request_state $(path2fid $file) REMOVE SUCCEED
869 content=$(do_facet $SINGLEAGT $MMAP_CAT $file)
870 [[ $content == "nmap_write_data" ]] ||
871 error "mmap write data mismatch: $content"
873 run_test 6 "Test mmap write on RW-PCC "
876 local loopfile="$TMP/$tfile"
877 local mntpt="/mnt/pcc.$tdir"
878 local hsm_root="$mntpt/$tdir"
879 local file=$DIR/$tfile
882 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
883 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
884 setup_pcc_mapping $SINGLEAGT "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ pccrw=1"
887 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER $file ||
888 error "failed to attach file $file"
889 check_lpcc_state $file "readwrite"
890 check_file_data $SINGLEAGT $file "QQQQQ"
891 # define OBD_FAIL_LLITE_PCC_DETACH_MKWRITE 0x1412
892 do_facet $SINGLEAGT $LCTL set_param fail_loc=0x1412
893 # HSM released exists archived status
894 check_hsm_flags $file "0x0000000d"
896 # multiop mmap write increase the first character of each page with 1
897 do_facet $SINGLEAGT $MULTIOP $file OSMWUc ||
898 error "mmap write $file failed"
899 check_lpcc_state $file "none"
900 content=$(do_facet $SINGLEAGT $MMAP_CAT $file)
901 [[ $content == "RQQQQ" ]] || error "data mismatch: $content"
903 run_test 7a "Fake file detached between fault() and page_mkwrite() for RW-PCC"
906 local loopfile="$TMP/$tfile"
907 local mntpt="/mnt/pcc.$tdir"
908 local hsm_root="$mntpt/$tdir"
909 local file=$DIR/$tfile
913 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
914 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
915 setup_pcc_mapping $SINGLEAGT \
916 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0\ pccrw=1"
919 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER $file ||
920 error "failed to attach file $file"
921 check_lpcc_state $file "readwrite"
922 check_file_data $SINGLEAGT $file "QQQQQ"
923 # define OBD_FAIL_LLITE_PCC_MKWRITE_PAUSE 0x1413
924 do_facet $SINGLEAGT $LCTL set_param fail_loc=0x1413 fail_val=20
925 # HSM released exists archived status
926 check_hsm_flags $file "0x0000000d"
928 # multiop mmap write increases the first character of each page with 1
929 do_facet $SINGLEAGT $MULTIOP $file OSMWUc &
933 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
934 error "failed to detach file $file"
936 wait $pid || error "multiop mmap write failed"
937 check_lpcc_state $file "none"
938 content=$(do_facet $SINGLEAGT $MMAP_CAT $file)
939 [[ $content == "RQQQQ" ]] || error "data mismatch: $content"
941 run_test 7b "Test the race with concurrent mkwrite and detach"
944 local loopfile="$TMP/$tfile"
945 local mntpt="/mnt/pcc.$tdir"
946 local hsm_root="$mntpt/$tdir"
947 local file=$DIR/$tfile
949 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
950 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
951 setup_pcc_mapping $SINGLEAGT "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ pccrw=1"
954 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER $file ||
955 error "failed to attach file $file"
956 check_lpcc_state $file "readwrite"
957 check_file_data $SINGLEAGT $file "QQQQQ"
959 # define OBD_FAIL_LLITE_PCC_FAKE_ERROR 0x1411
960 do_facet $SINGLEAGT $LCTL set_param fail_loc=0x1411
961 do_facet $SINGLEAGT "echo -n ENOSPC_write > $file"
962 # Above write will return -ENOSPC failure and retry the IO on normal
963 # IO path. It will restore the HSM released file.
964 check_lpcc_state $file "none"
965 check_file_data $SINGLEAGT $file "ENOSPC_write"
967 run_test 8 "Test fake -ENOSPC tolerance for RW-PCC"
970 local loopfile="$TMP/$tfile"
971 local mntpt="/mnt/pcc.9a"
972 local hsm_root="$mntpt/$tdir"
973 local file=$DIR/$tfile
975 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
977 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMVER" -h "$hsm_root"
978 setup_pcc_mapping $SINGLEAGT "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ pccrw=1"
979 do_facet $SINGLEAGT $LCTL pcc list $MOUNT
981 touch $file || error "touch $file failed"
982 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER $file ||
983 error "fail to attach $file"
984 check_lpcc_state $file "readwrite"
985 # write 60M data, it is larger than the capacity of PCC backend
986 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1M count=60 ||
987 error "fail to dd write $file"
988 check_lpcc_state $file "none"
989 check_file_size $SINGLEAGT $file 62914560
991 run_test 9 "Test -ENOSPC tolerance on loop PCC device for RW-PCC"
993 test_usrgrp_quota() {
994 local loopfile="$TMP/$tfile"
995 local mntpt="/mnt/pcc.$tdir"
996 local hsm_root="$mntpt/$tdir"
997 local state="readonly"
1003 [[ $ug == "g" ]] && id=$RUNAS_GID
1009 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1010 do_facet $SINGLEAGT quotacheck -c$ug $mntpt ||
1011 error "quotacheck -c$ug $mntpt failed"
1012 do_facet $SINGLEAGT quotaon -$ug $mntpt ||
1013 error "quotaon -$ug $mntpt failed"
1014 do_facet $SINGLEAGT setquota -$ug $id 0 20480 0 0 $mntpt ||
1015 error "setquota -$ug $id on $mntpt failed"
1016 do_facet $SINGLEAGT repquota -${ug}vs $mntpt
1018 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMVER" -h "$hsm_root"
1019 setup_pcc_mapping $SINGLEAGT "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ $mode=1"
1020 do_facet $SINGLEAGT $LCTL pcc list $MOUNT
1022 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
1024 local file1=$DIR/$tdir/${ug}quotaA
1025 local file2=$DIR/$tdir/${ug}quotaB
1027 dd if=/dev/zero of=$file1 bs=1M count=15 ||
1028 error "dd write $file1 failed"
1029 dd if=/dev/zero of=$file2 bs=1M count=15 ||
1030 error "dd write $file2 failed"
1031 chown $RUNAS_ID:$RUNAS_GID $file1 ||
1032 error "chown $RUNAS_ID:$RUNAS_GID $file1 failed"
1033 chown $RUNAS_ID:$RUNAS_GID $file2 ||
1034 error "chown $RUNAS_ID:$RUNAS_GID $file2 failed"
1035 do_facet $SINGLEAGT $RUNAS $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $rw \
1036 $file1 || error "attach $file1 failed"
1037 do_facet $SINGLEAGT $RUNAS $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $rw \
1038 $file2 && error "attach $file2 should fail due to quota limit"
1039 check_lpcc_state $file1 $state
1040 check_lpcc_state $file2 "none"
1042 if [[ -z $rw ]]; then
1043 do_facet $SINGLEAGT $LFS pcc detach $file1 ||
1044 error "detach $file1 failed"
1048 echo "Test -EDQUOT error tolerance for RW-PCC"
1049 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file1 bs=1M count=30 ||
1050 error "dd write $file1 failed"
1051 # -EDQUOT error should be tolerated via fallback to normal Lustre path.
1052 check_lpcc_state $file1 "none"
1056 test_usrgrp_quota "u" "-w"
1058 run_test 10a "Test RW-PCC with user quota on loop PCC device"
1061 test_usrgrp_quota "g" "-w"
1063 run_test 10b "Test RW-PCC with group quota on loop PCC device"
1066 $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
1067 skip "Server does not support PCC-RO"
1069 test_usrgrp_quota "u"
1071 run_test 10c "Test RO-PCC with user quota on loop PCC device"
1074 $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
1075 skip "Server does not support PCC-RO"
1077 test_usrgrp_quota "g"
1079 run_test 10d "Test RO-PCC with group quota on loop PCC device"
1081 test_usrgrp_edquot() {
1082 local loopfile="$TMP/$tfile"
1083 local mntpt="/mnt/pcc.$tdir"
1084 local hsm_root="$mntpt/$tdir"
1085 local file=$DIR/$tfile
1089 $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
1090 skip "Server does not support PCC-RO"
1092 [[ $ug == "g" ]] && id=$RUNAS_GID
1093 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1094 do_facet $SINGLEAGT quotacheck -c$ug $mntpt ||
1095 error "quotacheck -c$ug $mntpt failed"
1096 do_facet $SINGLEAGT quotaon -$ug $mntpt ||
1097 error "quotaon -$ug $mntpt failed"
1098 do_facet $SINGLEAGT setquota -$ug $id 0 4096 0 0 $mntpt ||
1099 error "setquota -$ug $id on $mntpt failed"
1100 do_facet $SINGLEAGT repquota -${ug}vs $mntpt
1101 do_facet $SINGLEAGT mkdir $hsm_root || error "mkdir $hsm_root failed"
1102 setup_pcc_mapping $SINGLEAGT \
1103 "${ug}id={$id}\ roid=$HSM_ARCHIVE_NUMBER\ pccro=1"
1104 do_facet $SINGLEAGT $LCTL pcc list $MOUNT
1106 dd if=/dev/zero of=$file bs=1M count=2 ||
1107 error "dd write $file failed"
1108 chown $RUNAS_ID:$RUNAS_GID $file ||
1109 error "chown $RUNAS_ID:$RUNAS_GID $file failed"
1110 do_facet $SINGLEAGT $RUNAS dd if=$file of=/dev/null bs=1M count=2 ||
1111 error "dd read $file failed"
1112 check_lpcc_state $file "readonly"
1113 $LFS getstripe -v $file
1114 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1M count=5 ||
1115 error "dd write $file failed"
1116 check_lpcc_state $file "none"
1117 do_facet $SINGLEAGT $RUNAS dd if=$file of=/dev/null bs=1M count=5 ||
1118 error "dd read $file failed"
1119 do_facet $SINGLEAGT $LFS pcc state $file
1120 $LFS getstripe -v $file
1121 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
1122 error "PCC-RO attach $file failed"
1124 do_facet $SINGLEAGT $LFS pcc detach $file || error "detach $file failed"
1128 test_usrgrp_edquot "u"
1130 run_test 10e "Tolerate -EDQUOT failure when auto PCC-RO attach with user quota"
1133 test_usrgrp_edquot "g"
1135 run_test 10f "Tolerate -EDQUOT failure when auto PCC-RO attach with group quota"
1138 local loopfile="$TMP/$tfile"
1139 local mntpt="/mnt/pcc.$tdir"
1140 local hsm_root="$mntpt/$tdir"
1141 local file=$DIR/$tfile
1145 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1146 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1147 setup_pcc_mapping $SINGLEAGT "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ pccrw=1"
1149 do_facet $SINGLEAGT "echo -n QQQQQ > $file"
1150 lpcc_path=$(lpcc_fid2path $hsm_root $file)
1151 lpcc_dir=$(dirname $lpcc_path)
1152 echo "Lustre file: $file LPCC dir: $lpcc_dir"
1153 do_facet $SINGLEAGT mkdir -p $lpcc_dir ||
1154 error "mkdir -p $lpcc_dir failed"
1155 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER $file ||
1156 error "failed to attach $file"
1157 check_lpcc_state $file "readwrite"
1158 check_file_data $SINGLEAGT $file "QQQQQ"
1159 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1160 error "failed to detach $file"
1161 rm $file || error "rm $file failed"
1163 # The parent directory of the PCC file is immutable
1164 do_facet $SINGLEAGT "echo -n immutable_dir > $file"
1165 lpcc_path=$(lpcc_fid2path $hsm_root $file)
1166 lpcc_dir=$(dirname $lpcc_path)
1167 echo "Lustre file: $file LPCC dir: $lpcc_dir"
1168 do_facet $SINGLEAGT mkdir -p $lpcc_dir ||
1169 error "mkdir -p $lpcc_dir failed"
1170 do_facet $SINGLEAGT chattr +i $lpcc_dir ||
1171 error "chattr +i $lpcc_dir failed"
1172 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER $file &&
1173 error "attach $file with immutable directory should be failed"
1174 do_facet $SINGLEAGT chattr -i $lpcc_dir ||
1175 error "chattr -i $lpcc_dir failed"
1176 rm $file || error "rm $file failed"
1178 # The PCC file path is set to a directory
1179 do_facet $SINGLEAGT "echo -n pcc_file_path_is_dir > $file"
1180 lpcc_path=$(lpcc_fid2path $hsm_root $file)
1181 do_facet $SINGLEAGT mkdir -p $lpcc_path ||
1182 error "mkdir -p $lpcc_path failed"
1183 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER $file &&
1184 error "attach $file should fail as PCC path is a directory"
1185 rm $file || error "rm $file failed"
1187 run_test 11 "Test attach fault injection with simulated PCC file path"
1190 local file=$DIR/$tfile
1191 local hsm_root=$(hsm_root)
1195 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1196 setup_pcc_mapping $SINGLEAGT \
1197 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0\ pccrw=1"
1199 echo -n race_rw_attach_hsmremove > $file
1200 lpcc_path=$(lpcc_fid2path $hsm_root $file)
1201 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER $file ||
1202 error "attach $file failed"
1203 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1204 error "detach $file failed"
1205 # HSM released exists archived status
1206 check_hsm_flags $file "0x0000000d"
1207 # define OBD_FAIL_LLITE_PCC_ATTACH_PAUSE 0x1414
1208 do_facet $SINGLEAGT $LCTL set_param fail_loc=0x1414 fail_val=20
1209 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER $file &
1211 $LFS hsm_state $file
1213 wait_request_state $(path2fid $file) RESTORE SUCCEED
1214 $LFS hsm_remove $file || error "hsm remove $file failed"
1216 do_facet $SINGLEAGT "[ -f $lpcc_path ]" &&
1217 error "RW-PCC cached file '$lpcc_path' should be removed"
1221 run_test 12 "RW-PCC attach races with concurrent HSM remove"
1224 local idstr="${1}id"
1225 local rule="${idstr}={$2}"
1227 local file=$DIR/$tdir/$tfile
1229 setup_pcc_mapping $SINGLEAGT \
1230 "$rule\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0\ pccrw=1"
1231 $LCTL pcc list $MOUNT
1233 do_facet $SINGLEAGT $LFS mkdir -i 0 $DIR/$tdir
1234 chmod 777 $DIR/$tdir || error "chmod 0777 $DIR/$tdir failed"
1236 rm -f $file || error "rm $file failed"
1237 do_facet $SINGLEAGT $myRUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1238 error "failed to dd write to $file"
1239 check_lpcc_state $file "readwrite"
1240 do_facet $SINGLEAGT $myRUNAS dd if=$file of=/dev/null bs=1024 count=1 ||
1241 error "failed to dd read from $file"
1242 do_facet $SINGLEAGT $myRUNAS $TRUNCATE $file 256 ||
1243 error "failed to truncate $file"
1244 do_facet $SINGLEAGT $myRUNAS $TRUNCATE $file 2048 ||
1245 error "failed to truncate $file"
1246 do_facet $SINGLEAGT $myRUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1247 error "failed to dd write from $file"
1248 check_lpcc_state $file "readwrite"
1250 do_facet $SINGLEAGT $myRUNAS $LFS pcc detach $file ||
1251 error "failed to detach file $file"
1252 wait_request_state $(path2fid $file) REMOVE SUCCEED
1253 check_lpcc_state $file "none"
1259 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1260 test_rule_id "u" "$RUNAS_ID" "runas -u $RUNAS_ID"
1261 test_rule_id "g" "$RUNAS_GID" "runas -u $RUNAS_ID -g $RUNAS_GID"
1263 run_test 13a "Test auto RW-PCC create caching for UID/GID rule"
1268 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1269 setup_pcc_mapping $SINGLEAGT \
1270 "fname={*.h5\ suffix.*\ Mid*dle}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0\ pccrw=1"
1271 $LCTL pcc list $MOUNT
1273 do_facet $SINGLEAGT mkdir -p $DIR/$tdir
1274 chmod 777 $DIR/$tdir || error "chmod 0777 $DIR/$tdir failed"
1276 file=$DIR/$tdir/prefix.h5
1277 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1024 count=1 ||
1278 error "failed to dd write to $file"
1279 check_lpcc_state $file "readwrite"
1280 do_facet $SINGLEAGT $myRUNAS $LFS pcc detach -k $file ||
1281 error "failed to detach file $file"
1282 check_lpcc_state $file "none"
1283 rm $file || error "rm $file failed"
1285 file=$DIR/$tdir/suffix.doc
1286 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1287 error "failed to dd write to $file"
1288 check_lpcc_state $file "readwrite"
1289 do_facet $SINGLEAGT $myRUNAS $LFS pcc detach -k $file ||
1290 error "failed to detach file $file"
1291 check_lpcc_state $file "none"
1292 rm $file || error "rm $file failed"
1294 file=$DIR/$tdir/MidPADdle
1295 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1296 error "failed to dd write to $file"
1297 check_lpcc_state $file "readwrite"
1298 do_facet $SINGLEAGT $myRUNAS $LFS pcc detach -k $file ||
1299 error "failed to detach file $file"
1300 check_lpcc_state $file "none"
1301 rm $file || error "rm $file failed"
1303 file=$DIR/$tdir/Midpad
1304 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1305 error "failed to dd write to $file"
1306 check_lpcc_state $file "none"
1307 rm $file || error "rm $file failed"
1309 run_test 13b "Test auto RW-PCC create caching for file name with wildcard"
1314 local loopfile="$TMP/$tfile"
1315 local mntpt="/mnt/pcc.$tdir"
1316 local hsm_root="$mntpt/$tdir"
1318 ! is_project_quota_supported &&
1319 echo "Skip project quota is not supported" && return 0
1321 enable_project_quota
1322 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1323 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1324 setup_pcc_mapping $SINGLEAGT \
1325 "projid={100\ 200}\&fname={*.h5},uid={$RUNAS_ID}\&gid={$RUNAS_GID}\ rwid=$HSM_ARCHIVE_NUMBER\ pccrw=1"
1326 $LCTL pcc list $MOUNT
1327 do_facet $SINGLEAGT mkdir -p $DIR/$tdir
1328 chmod 777 $DIR/$tdir || error "chmod 0777 $DIR/$tdir failed"
1330 mkdir -p $DIR/$tdir/proj || error "mkdir $DIR/$tdir/proj failed"
1331 mkdir -p $DIR/$tdir/proj2 || error "mkdir $DIR/$tdir/proj2 failed"
1332 $LFS project -sp 100 $DIR/$tdir/proj ||
1333 error "failed to set project for $DIR/$tdir/proj"
1334 $LFS project -sp 200 $DIR/$tdir/proj2 ||
1335 error "failed to set project for $DIR/$tdir/proj2"
1337 file=$DIR/$tdir/proj/notcache
1338 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1024 count=1 ||
1339 error "failed to dd write to $file"
1340 check_lpcc_state $file "none"
1341 rm $file || error "rm $file failed"
1343 file=$DIR/$tdir/proj/autocache.h5
1344 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1024 count=1 ||
1345 error "failed to dd write to $file"
1346 check_lpcc_state $file "readwrite"
1347 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1348 error "failed to detach $file"
1349 rm $file || error "rm $file failed"
1351 file=$DIR/$tdir/proj2/notcache
1352 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1024 count=1 ||
1353 error "failed to dd write to $file"
1354 check_lpcc_state $file "none"
1355 rm $file || error "rm $file failed"
1357 file=$DIR/$tdir/proj2/autocache.h5
1358 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=1024 count=1 ||
1359 error "failed to dd write to $file"
1360 check_lpcc_state $file "readwrite"
1361 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1362 error "failed to detach $file"
1363 rm $file || error "rm $file failed"
1365 file=$DIR/$tdir/ugidcache
1366 myRUNAS="runas -u $RUNAS_ID -g $RUNAS_GID"
1367 do_facet $SINGLEAGT $myRUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1368 error "failed to dd write to $file"
1369 check_lpcc_state $file "readwrite"
1370 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1371 error "failed to detach $file"
1372 rm $file || error "rm $file failed"
1374 run_test 13c "Check auto RW-PCC create caching for UID/GID/ProjID/fname rule"
1377 local file=$DIR/$tdir/$tfile
1379 $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
1380 skip "Server does not support PCC-RO"
1382 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1383 setup_pcc_mapping $SINGLEAGT \
1384 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0\ pccrw=1\ pccro=1"
1386 mkdir -p $DIR/$tdir || error "mkdir -p $DIR/$tdir failed"
1387 do_facet $SINGLEAGT "echo -n autodetach_data > $file"
1388 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER \
1389 $file || error "PCC attach $file failed"
1390 check_lpcc_state $file "readwrite"
1392 # Revoke the layout lock, the PCC-cached file will be
1393 # detached automatically.
1394 do_facet $SINGLEAGT $LCTL \
1395 set_param ldlm.namespaces.*mdc*.lru_size=clear
1396 check_file_data $SINGLEAGT $file "autodetach_data"
1397 check_lpcc_state $file "none"
1399 rm $file || error "rm $file failed"
1400 do_facet $SINGLEAGT "echo -n ro_autodetach_data > $file"
1401 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
1402 error "PCC attach $file failed"
1403 check_lpcc_state $file "readonly"
1405 # Revoke the layout lock, the PCC-cached file will be
1406 # detached automatically.
1407 do_facet $SINGLEAGT $LCTL \
1408 set_param ldlm.namespaces.*mdc*.lru_size=clear
1409 check_file_data $SINGLEAGT $file "ro_autodetach_data"
1410 check_lpcc_state $file "none"
1412 run_test 14 "Revocation of the layout lock should detach the file automatically"
1415 local loopfile="$TMP/$tfile"
1416 local mntpt="/mnt/pcc.$tdir"
1417 local hsm_root="$mntpt/$tdir"
1418 local file=$DIR/$tdir/$tfile
1420 $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
1421 skip "Server does not support PCC-RO"
1423 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1424 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1425 setup_pcc_mapping $SINGLEAGT "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ pccrw=1\ pccro=1"
1427 mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
1428 chmod 777 $DIR/$tdir || error "chmod 777 $DIR/$tdir failed"
1430 echo "Verify open attach for non-root user"
1431 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
1432 error "failed to dd write to $file"
1433 do_facet $SINGLEAGT $RUNAS $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER \
1434 $file || error "failed to attach file $file"
1435 do_facet $SINGLEAGT $RUNAS $LFS pcc state $file
1436 check_lpcc_state $file "readwrite" $SINGLEAGT "$RUNAS"
1437 # Revoke the layout lock, the PCC-cached file will be
1438 # detached automatically.
1439 do_facet $SINGLEAGT $LCTL \
1440 set_param ldlm.namespaces.*mdc*.lru_size=clear
1441 check_lpcc_state $file "readwrite" $SINGLEAGT "$RUNAS"
1442 # Detach the file but keep the cache , as the file layout generation
1443 # is not changed, so the file is still valid cached in PCC, and can
1444 # be reused from PCC cache directly.
1445 do_facet $SINGLEAGT $RUNAS $LFS pcc detach -k $file ||
1446 error "PCC detach $file failed"
1447 check_lpcc_state $file "readwrite" $SINGLEAGT "$RUNAS"
1448 do_facet $SINGLEAGT $RUNAS $LFS pcc detach $file ||
1449 error "PCC detach $file failed"
1450 rm $file || error "rm $file failed"
1452 echo "Verify auto attach at open for RW-PCC"
1453 do_facet $SINGLEAGT "echo -n autoattach_data > $file"
1454 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER \
1455 $file || error "RW-PCC attach $file failed"
1456 check_lpcc_state $file "readwrite"
1458 # Revoke the layout lock, the PCC-cached file will be
1459 # detached automatically.
1460 do_facet $SINGLEAGT $LCTL \
1461 set_param ldlm.namespaces.*mdc*.lru_size=clear
1462 check_file_data $SINGLEAGT $file "autoattach_data"
1463 check_lpcc_state $file "readwrite"
1465 # Detach the file with -k option, as the file layout generation
1466 # is not changed, so the file is still valid cached in PCC,
1467 # and can be reused from PCC cache directly.
1468 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1469 error "RW-PCC detach $file failed"
1470 check_lpcc_state $file "readwrite"
1471 # HSM released exists archived status
1472 check_hsm_flags $file "0x0000000d"
1473 check_file_data $SINGLEAGT $file "autoattach_data"
1475 # HSM restore the PCC cached file, the layout generation
1476 # was changed, so the file can not be auto attached.
1477 $LFS hsm_restore $file || error "failed to restore $file"
1478 wait_request_state $(path2fid $file) RESTORE SUCCEED
1479 check_lpcc_state $file "none"
1480 # HSM exists archived status
1481 check_hsm_flags $file "0x00000009"
1483 echo "Verify auto attach at open for RO-PCC"
1484 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER -r $file ||
1485 error "RO-PCC attach $file failed"
1486 check_lpcc_state $file "readonly"
1488 # Revoke the layout lock, the PCC-cached file will be
1489 # detached automatically.
1490 do_facet $SINGLEAGT $LCTL \
1491 set_param ldlm.namespaces.*mdc*.lru_size=clear
1492 check_file_data $SINGLEAGT $file "autoattach_data"
1493 check_lpcc_state $file "readonly"
1495 # Detach the file with "-k" option, as the file layout generation
1496 # is not changed, so the file is still valid cached in PCC,
1497 # and can be reused from PCC cache directly.
1498 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1499 error "RO-PCC detach $file failed"
1500 check_lpcc_state $file "readonly"
1501 check_file_data $SINGLEAGT $file "autoattach_data"
1502 do_facet $SINGLEAGT $LFS pcc detach $file ||
1503 error "RO-PCC detach $file failed"
1505 run_test 15 "Test auto attach at open when file is still valid cached"
1508 local loopfile="$TMP/$tfile"
1509 local mntpt="/mnt/pcc.$tdir"
1510 local hsm_root="$mntpt/$tdir"
1511 local file=$DIR/$tfile
1514 $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
1515 skip "Server does not support PCC-RO"
1517 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1518 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1519 setup_pcc_mapping $SINGLEAGT "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ pccrw=1\ pccro=1"
1521 echo "Test detach for RW-PCC"
1522 do_facet $SINGLEAGT "echo -n detach_data > $file"
1523 lpcc_path=$(lpcc_fid2path $hsm_root $file)
1524 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER \
1525 $file || error "RW-PCC attach $file failed"
1526 check_lpcc_state $file "readwrite"
1527 # HSM released exists archived status
1528 check_hsm_flags $file "0x0000000d"
1530 echo "Test for reusing valid PCC cache"
1531 # Valid PCC cache can be reused
1532 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1533 error "PCC detach $file failed"
1534 check_lpcc_state $file "readwrite"
1535 # HSM released exists archived status
1536 check_hsm_flags $file "0x0000000d"
1538 echo "Test for the default detach"
1539 # Permanent detach by default, it will remove the PCC copy
1540 do_facet $SINGLEAGT $LFS pcc detach $file ||
1541 error "RW-PCC detach $file failed"
1542 wait_request_state $(path2fid $file) REMOVE SUCCEED
1543 check_lpcc_state $file "none"
1544 # File is removed from PCC backend
1545 check_hsm_flags $file "0x00000000"
1546 do_facet $SINGLEAGT "[ -f $lpcc_path ]" &&
1547 error "RW-PCC cached file '$lpcc_path' should be removed"
1549 echo "Test detach for RO-PCC"
1550 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER -r $file ||
1551 error "RO-PCC attach $file failed"
1552 check_lpcc_state $file "readonly"
1554 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1555 error "RO-PCC detach $file failed"
1556 check_lpcc_state $file "readonly"
1558 do_facet $SINGLEAGT $LFS pcc detach $file ||
1559 error "RO-PCC detach $file failed"
1560 check_lpcc_state $file "none"
1561 do_facet $SINGLEAGT "[ -f $lpcc_path ]" &&
1562 error "RO-PCC cached file '$lpcc_path' should be removed"
1566 run_test 16 "Test detach with different options"
1569 local agt_host=$(facet_active_host $SINGLEAGT)
1570 local loopfile="$TMP/$tfile"
1571 local mntpt="/mnt/pcc.$tdir"
1572 local hsm_root="$mntpt/$tdir"
1573 local file=$DIR/$tfile
1575 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1576 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1577 setup_pcc_mapping $SINGLEAGT \
1578 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ open_attach=0\ stat_attach=0\ pccrw=1"
1580 do_facet $SINGLEAGT $LCTL pcc list $MOUNT
1582 do_facet $SINGLEAGT "echo -n layout_refresh_data > $file"
1583 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER $file ||
1584 error "PCC attach $file failed"
1585 check_lpcc_state $file "readwrite"
1587 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1588 error "PCC detach $file failed"
1589 check_lpcc_state $file "none"
1591 # Truncate should attach the file into PCC automatically
1592 # as the PCC copy is still valid.
1593 echo "Verify auto attach during IO for truncate"
1594 do_facet $SINGLEAGT $TRUNCATE $file 4 || error "truncate $file failed"
1595 check_lpcc_state $file "readwrite"
1597 echo "Verify auto attach during IO for read/write"
1598 rmultiop_start $agt_host $file O_r || error "open $file failed"
1601 # Revoke the layout lock, the PCC-cached file will be
1602 # detached automatically.
1603 do_facet $SINGLEAGT $LCTL \
1604 set_param ldlm.namespaces.*mdc*.lru_size=clear
1606 check_lpcc_state $file "none"
1607 rmultiop_stop $agt_host || error "close $file failed"
1609 check_lpcc_state $file "readwrite"
1611 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1612 error "PCC detach $file failed"
1613 check_lpcc_state $file "none"
1615 run_test 17 "Test auto attach for layout refresh"
1618 local agt_host=$(facet_active_host $SINGLEAGT)
1619 local loopfile="$TMP/$tfile"
1620 local mntpt="/mnt/pcc.$tdir"
1621 local hsm_root="$mntpt/$tdir"
1622 local file=$DIR/$tfile
1626 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1627 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1628 setup_pcc_mapping $SINGLEAGT \
1629 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ pccrw=1"
1631 do_facet $SINGLEAGT $LCTL pcc list $MOUNT
1632 do_facet $SINGLEAGT dd if=/dev/urandom of=$file bs=1M count=4 ||
1633 error "failed to write $file"
1634 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER $file ||
1635 error "failed to attach $file"
1636 do_facet $SINGLEAGT $LFS pcc state $file
1637 check_lpcc_state $file "readwrite"
1638 do_facet $SINGLEAGT $LFS pcc detach --keep $file ||
1639 error "failed to detach $file"
1640 do_facet $SINGLEAGT $LFS pcc state $file
1641 $CHECKSTAT -s 4194304 $file
1642 dd if=/dev/zero of=$DIR2/$tfile seek=1k bs=1k count=1 ||
1643 error "failed to write $DIR2/$tfile"
1644 oldmd5=$(md5sum $DIR2/$tfile | awk '{print $1}')
1645 $CHECKSTAT -s 1049600 $DIR2/$tfile || error "$DIR2/$tfile size wrong"
1647 local lpcc_path=$(lpcc_fid2path $hsm_root $file)
1649 do_facet $SINGLEAGT $LFS pcc state $file
1650 check_file_size $SINGLEAGT $lpcc_path 4194304
1651 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER $file ||
1652 error "failed to attach $file"
1653 check_lpcc_sizes $SINGLEAGT $lpcc_path $file 1049600
1654 newmd5=$(do_facet $SINGLEAGT md5sum $file | awk '{print $1}')
1655 [ "$oldmd5" == "$newmd5" ] || error "md5sum differ: $oldmd5 != $newmd5"
1656 do_facet $SINGLEAGT $LFS pcc detach $file ||
1657 error "failed to detach $file"
1659 run_test 18 "Verify size correctness after re-attach the file"
1662 local agt_host=$(facet_active_host $SINGLEAGT)
1663 local loopfile="$TMP/$tfile"
1664 local mntpt="/mnt/pcc.$tdir"
1665 local hsm_root="$mntpt/$tdir"
1666 local file=$DIR/$tfile
1668 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1669 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1670 setup_pcc_mapping $SINGLEAGT \
1671 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0\ pccrw=1"
1673 do_facet $SINGLEAGT "echo -n QQQQQ > $file" || error "echo $file failed"
1674 lpcc_path=$(lpcc_fid2path $hsm_root $file)
1675 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER $file ||
1676 error "Failed to attach $file"
1677 check_lpcc_state $file "readwrite"
1678 check_lpcc_sizes $SINGLEAGT $file $lpcc_path 5
1679 do_facet $SINGLEAGT $LFS pcc detach --keep $file ||
1680 error "Failed to detach $file"
1681 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER $file ||
1682 error "Failed to attach $file"
1683 check_lpcc_sizes $SINGLEAGT $file $lpcc_path 5
1684 do_facet $SINGLEAGT $LFS pcc detach --keep $file ||
1685 error "Failed to detach $file"
1687 run_test 19 "Verify the file re-attach works as expected"
1690 local agt_host=$(facet_active_host $SINGLEAGT)
1691 local loopfile="$TMP/$tfile"
1692 local mntpt="/mnt/pcc.$tdir"
1693 local hsm_root="$mntpt/$tdir"
1694 local file=$DIR/$tfile
1696 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1697 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1698 setup_pcc_mapping $SINGLEAGT \
1699 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ pccrw=1"
1701 do_facet $SINGLEAGT "echo -n QQQQQ > $file" ||
1702 error "echo $file failed"
1703 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER $file ||
1704 error "Failed to attach $file"
1705 do_facet $SINGLEAGT "echo 3 > /proc/sys/vm/drop_caches"
1706 check_lpcc_state $file "readwrite"
1707 do_facet $SINGLEAGT "echo 3 > /proc/sys/vm/drop_caches"
1708 do_facet $SINGLEAGT "echo 3 > /proc/sys/vm/drop_caches"
1709 check_lpcc_state $file "readwrite"
1710 do_facet $SINGLEAGT $LFS pcc detach $file ||
1711 error "Failed to detach $file"
1713 run_test 20 "Auto attach works after the inode was once evicted from cache"
1716 local loopfile="$TMP/$tfile"
1717 local mntpt="/mnt/pcc.$tdir"
1718 local hsm_root="$mntpt/$tdir"
1719 local file=$DIR/$tfile
1721 $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
1722 skip "Server does not support PCC-RO"
1724 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1725 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1726 setup_pcc_mapping $SINGLEAGT \
1727 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0"
1729 do_facet $SINGLEAGT "echo -n pccro_as_mirror_layout > $file"
1730 echo "Plain layout info before PCC-RO attach '$file':"
1731 $LFS getstripe -v $file
1732 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
1733 error "RW-PCC attach $file failed"
1734 check_lpcc_state $file "readonly"
1735 echo -e "\nFLR layout info after PCC-RO attach '$file':"
1736 $LFS getstripe -v $file
1737 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1738 error "failed to detach file $file"
1739 check_lpcc_state $file "none"
1740 echo -e "\nFLR layout info after PCC-RO detach '$file':"
1741 $LFS getstripe -v $file
1743 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
1744 error "failed to attach file $file"
1745 check_lpcc_state $file "readonly"
1746 echo -e "\nFLR layout info after RO-PCC attach $file again:"
1747 $LFS getstripe -v $file
1748 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1749 error "failed to detach file $file"
1750 check_lpcc_state $file "none"
1751 echo -e "\nFLR layout info after RO-PCC detach '$file' again:"
1752 $LFS getstripe -v $file
1754 run_test 21a "PCC-RO storing as a plain HSM mirror component for plain layout"
1757 local loopfile="$TMP/$tfile"
1758 local mntpt="/mnt/pcc.$tdir"
1759 local hsm_root="$mntpt/$tdir"
1760 local file=$DIR/$tfile
1762 $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
1763 skip "Server does not support PCC-RO"
1765 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1766 do_facet $SINGLEAGT mkdir -p $hsm_root ||
1767 error "failed to mkdir $hsm_root"
1768 setup_pcc_mapping $SINGLEAGT \
1769 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0"
1771 $LFS mirror create -N -S 4M -c 2 -N -S 1M -c -1 $file ||
1772 error "create mirrored file $file failed"
1773 #do_facet $SINGLEAGT "echo -n pccro_as_mirror_layout > $file"
1774 echo "FLR layout before PCC-RO attach '$file':"
1775 $LFS getstripe -v $file
1776 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
1777 error "failed to attach file $file"
1778 check_lpcc_state $file "readonly"
1779 echo -e "\nFLR layout after PCC-RO attach '$file':"
1780 $LFS getstripe -v $file
1781 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1782 error "failed to detach file $file"
1783 check_lpcc_state $file "none"
1784 echo -e "\nFLR layout info after PCC-RO detach '$file':"
1785 $LFS getstripe -v $file
1787 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
1788 error "failed to attach file $file"
1789 check_lpcc_state $file "readonly"
1790 echo -e "\nFLR layout after PCC-RO attach '$file' again:"
1791 $LFS getstripe -v $file
1792 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1793 error "failed to detach file $file"
1794 check_lpcc_state $file "none"
1795 echo -e "\nFLR layout info after PCC-RO detach '$file':"
1796 $LFS getstripe -v $file
1798 run_test 21b "PCC-RO stroing as a plain HSM mirror component for FLR layouts"
1801 local loopfile="$TMP/$tfile"
1802 local mntpt="/mnt/pcc.$tdir"
1803 local hsm_root="$mntpt/$tdir"
1804 local file=$DIR/$tfile
1805 local file2=$DIR2/$tfile
1808 $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
1809 skip "Server does not support PCC-RO"
1811 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1812 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1813 setup_pcc_mapping $SINGLEAGT \
1814 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0"
1816 do_facet $SINGLEAGT "echo -n pccro_hsm_release > $file"
1817 fid=$(path2fid $file)
1818 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $file ||
1819 error "Archive $file failed"
1820 wait_request_state $fid ARCHIVE SUCCEED
1821 $LFS hsm_state $file
1823 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER -r $file ||
1824 error "RO-PCC attach $file failed"
1825 # HSM exists archived status
1826 check_hsm_flags $file "0x00000009"
1827 check_lpcc_state $file "readonly"
1828 check_file_data $SINGLEAGT $file "pccro_hsm_release"
1830 $LFS hsm_release $file || error "HSM released $file failed"
1831 $LFS getstripe $file
1832 $LFS hsm_state $file
1833 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
1834 error "failed to detach $file"
1835 check_lpcc_state $file "none"
1836 unlink $file || error "unlink $file failed"
1838 run_test 21c "Verify HSM release works storing PCC-RO as HSM mirror component"
1841 local loopfile="$TMP/$tfile"
1842 local mntpt="/mnt/pcc.$tdir"
1843 local hsm_root="$mntpt/$tdir"
1844 local file=$DIR/$tfile
1846 $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
1847 skip "Server does not support PCC-RO"
1849 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1850 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1853 echo "pccro_init_data" > $file
1854 $LFS getstripe $file
1855 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
1856 error "failed to PCC-RO attach file $file"
1857 check_lpcc_state $file "readonly"
1858 echo "PCC-RO attach '$file':"
1859 $LFS getstripe -v $file
1861 echo "Write invalidated PCC-RO cache:"
1862 echo -n "write_mod_data" > $file
1863 check_lpcc_state $file "none"
1864 $LFS getstripe -v $file
1865 check_file_data $SINGLEAGT $file "write_mod_data"
1867 run_test 21d "Write should invalidate PCC-RO caching"
1870 local loopfile="$TMP/$tfile"
1871 local mntpt="/mnt/pcc.$tdir"
1872 local hsm_root="$mntpt/$tdir"
1873 local file=$DIR/$tfile
1875 $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
1876 skip "Server does not support PCC-RO"
1878 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1879 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1882 echo "pccro_init_data" > $file
1883 $LFS getstripe $file
1884 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
1885 error "failed to PCC-RO attach file $file"
1886 check_lpcc_state $file "readonly"
1887 echo "PCC-RO attach '$file':"
1888 $LFS getstripe -v $file
1890 echo "Trucate invalidate PCC-RO file '$file':"
1891 $TRUNCATE $file 256 || error "failed to truncate $file"
1892 $LFS getstripe -v $file
1893 check_lpcc_state $file "none"
1894 check_file_size $SINGLEAGT $file 256
1896 run_test 21e "Truncate should invalidate PCC-RO caching"
1899 local loopfile="$TMP/$tfile"
1900 local mntpt="/mnt/pcc.$tdir"
1901 local hsm_root="$mntpt/$tdir"
1902 local file=$DIR/$tfile
1904 $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
1905 skip "Server does not support PCC-RO"
1907 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1908 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1911 echo "pccro_mmap_data" > $file
1912 $LFS getstripe $file
1913 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
1914 error "failed to PCC-RO attach file $file"
1915 check_lpcc_state $file "readonly"
1916 echo "PCC-RO attach '$file':"
1917 $LFS getstripe -v $file
1919 echo "Mmap write invalidate PCC-RO caching:"
1920 # Mmap write will invalidate the RO-PCC cache
1921 do_facet $SINGLEAGT $MULTIOP $file OSMWUc ||
1922 error "mmap write $file failed"
1923 check_lpcc_state $file "none"
1924 $LFS getstripe -v $file
1925 # After mmap-write by MULTIOP, the first character of the content
1926 # will be increased with 1.
1927 content=$(do_facet $SINGLEAGT $MMAP_CAT $file)
1928 [[ $content == "qccro_mmap_data" ]] ||
1929 error "mmap_cat data mismatch: $content"
1931 run_test 21f "mmap write should invalidate PCC-RO caching"
1934 local loopfile="$TMP/$tfile"
1935 local mntpt="/mnt/pcc.$tdir"
1936 local hsm_root="$mntpt/$tdir"
1937 local file=$DIR/$tfile
1939 $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
1940 skip "Server does not support PCC-RO"
1942 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1943 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1944 setup_pcc_mapping $SINGLEAGT \
1945 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0"
1947 $LFS mirror create -N -S 4M -c 2 -N -S 1M -c -1 $file ||
1948 error "create mirrored file '$file' failed"
1949 do_facet $SINGLEAGT "echo -n pccro_as_mirror_layout > $file"
1950 echo "FLR layout before PCC-RO attach '$file':"
1951 $LFS getstripe -v $file
1952 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
1953 error "failed to PCC-RO attach '$file'"
1954 echo "FLR layout after PCC-RO attach '$file':"
1955 $LFS getstripe -v $file
1956 echo "Layout after Write invalidate '$file':"
1957 echo -n pccro_write_invalidate_mirror > $file
1958 $LFS getstripe -v $file
1960 run_test 21g "PCC-RO for file under FLR write pending state"
1963 local loopfile="$TMP/$tfile"
1964 local mntpt="/mnt/pcc.$tdir"
1965 local hsm_root="$mntpt/$tdir"
1966 local file=$DIR/$tfile
1968 $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
1969 skip "Server does not support PCC-RO"
1971 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
1972 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
1973 setup_pcc_mapping $SINGLEAGT \
1974 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0"
1976 $LFS mirror create -N -S 4M -c 2 -N -S 1M -c -1 $file ||
1977 error "create mirrored file $file failed"
1978 #do_facet $SINGLEAGT "echo -n pccro_as_mirror_layout > $file"
1979 echo "FLR layout before PCC-RO attach '$file':"
1980 $LFS getstripe -v $file
1981 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
1982 error "failed to attach file $file"
1983 check_lpcc_state $file "readonly"
1984 echo -e "\nFLR layout after PCC-RO attach '$file':"
1985 $LFS getstripe -v $file
1987 $LFS mirror extend -N -S 8M -c -1 $file ||
1988 error "mirror extend $file failed"
1989 echo -e "\nFLR layout after extend a mirror:"
1990 $LFS getstripe -v $file
1991 $LFS pcc state $file
1992 check_lpcc_state $file "none"
1994 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
1995 error "failed to attach file $file"
1996 check_lpcc_state $file "readonly"
1997 echo -e "\nFLR layout after PCC-RO attach '$file' again:"
1998 $LFS getstripe -v $file
1999 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
2000 error "failed to detach file $file"
2001 check_lpcc_state $file "none"
2003 run_test 21h "Extend mirror once file was PCC-RO cached"
2006 local loopfile="$TMP/$tfile"
2007 local mntpt="/mnt/pcc.$tdir"
2008 local hsm_root="$mntpt/$tdir"
2009 local file=$DIR/$tfile
2010 local file2=$DIR2/$tfile
2013 $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
2014 skip "Server does not support PCC-RO"
2016 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
2017 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
2018 setup_pcc_mapping $SINGLEAGT \
2019 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0\ pccro=1\ pccrw=1"
2021 do_facet $SINGLEAGT "echo -n hsm_release_pcc_file > $file"
2022 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER $file ||
2023 error "RW-PCC attach $file failed"
2024 check_lpcc_state $file "readwrite"
2025 # HSM released exists archived status
2026 check_hsm_flags $file "0x0000000d"
2028 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
2029 error "RW-PCC detach $file failed"
2030 check_lpcc_state $file "none"
2031 # HSM released exists archived status
2032 check_hsm_flags $file "0x0000000d"
2034 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
2035 error "failed to PCC-RO attach $file"
2037 $LFS hsm_state $file
2038 $LFS hsm_release $file || error "HSM released $file failed"
2039 echo "Layout after HSM release $file:"
2040 $LFS getstripe -v $file
2041 echo "PCC state $file:"
2042 $LFS pcc state $file
2043 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER -r $file ||
2044 error "RO-PCC attach $file failed"
2045 echo "Layout after PCC-RO attach $file again:"
2046 $LFS getstripe -v $file
2048 $LFS pcc state $file
2050 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
2051 error "RW-PCC detach $file failed"
2052 check_lpcc_state $file "none"
2054 run_test 21i "HSM release increase layout gen, should invalidate PCC-RO cache"
2057 local loopfile="$TMP/$tfile"
2058 local mntpt="/mnt/pcc.$tdir"
2059 local hsm_root="$mntpt/$tdir"
2060 local file=$DIR/$tfile
2061 local file2=$DIR2/$tfile
2064 $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
2065 skip "Server does not support PCC-RO"
2067 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
2068 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
2069 setup_pcc_mapping $SINGLEAGT \
2070 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0\ pccrw=1\ pccro=1"
2072 do_facet $SINGLEAGT "echo -n roattach_data > $file"
2074 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER $file ||
2075 error "RW-PCC attach $file failed"
2076 check_lpcc_state $file "readwrite"
2077 # HSM released exists archived status
2078 check_hsm_flags $file "0x0000000d"
2080 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
2081 error "RW-PCC detach $file failed"
2082 check_lpcc_state $file "none"
2083 # HSM released exists archived status
2084 check_hsm_flags $file "0x0000000d"
2086 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER -r $file ||
2087 error "RO-PCC attach $file failed"
2088 echo "Layout after PCC-RO attach $file:"
2089 $LFS getstripe -v $file
2090 # HSM exists archived status
2091 check_hsm_flags $file "0x00000009"
2092 check_lpcc_state $file "readonly"
2093 check_file_data $SINGLEAGT $file "roattach_data"
2095 $LFS hsm_release $file || error "HSM released $file failed"
2096 echo "Layout after HSM release $file:"
2097 $LFS getstripe -v $file
2098 # HSM released exists archived status
2099 check_hsm_flags $file "0x0000000d"
2100 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER -r $file ||
2101 error "RO-PCC attach $file failed"
2102 echo "Layout after PCC-RO attach $file again:"
2103 $LFS getstripe -v $file
2104 check_lpcc_state $file "readonly"
2105 check_file_data $SINGLEAGT $file "roattach_data"
2106 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
2107 error "failed to detach $file"
2108 echo "Layout after PCC-RO detach $file:"
2109 $LFS getstripe -v $file
2110 rm -f $file2 || error "rm -f $file failed"
2111 do_facet $SINGLEAGT "echo -n roattach_data2 > $file"
2112 fid=$(path2fid $file)
2113 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $file ||
2114 error "Archive $file failed"
2115 wait_request_state $fid ARCHIVE SUCCEED
2116 $LFS hsm_release $file || error "HSM released $file failed"
2117 # HSM released exists archived status
2118 check_hsm_flags $file "0x0000000d"
2119 do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER -r $file ||
2120 error "RO-PCC attach $file failed"
2121 check_lpcc_state $file "readonly"
2122 check_file_data $SINGLEAGT $file "roattach_data2"
2123 do_facet $SINGLEAGT $LFS pcc detach $file ||
2124 error "RO-PCC detach $file failed"
2126 run_test 22 "Test RO-PCC attach for the HSM released file"
2129 local loopfile="$TMP/$tfile"
2130 local mntpt="/mnt/pcc.$tdir"
2131 local hsm_root="$mntpt/$tdir"
2132 local file=$DIR/$tfile
2135 $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
2136 skip "Server does not support PCC-RO"
2138 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
2139 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
2142 echo "pccro_data" > $file
2143 lpcc_path=$(lpcc_fid2path $hsm_root $file)
2145 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
2146 error "failed to RO-PCC attach file $file"
2147 check_lpcc_state $file "readonly"
2148 check_lpcc_data $SINGLEAGT $lpcc_path $file "pccro_data"
2150 local content=$(do_facet $SINGLEAGT $MMAP_CAT $file)
2152 [[ $content == "pccro_data" ]] ||
2153 error "mmap_cat data mismatch: $content"
2154 check_lpcc_state $file "readonly"
2156 echo -n "write_mod_data" > $file
2157 echo "Write should invalidate the RO-PCC cache:"
2158 $LFS getstripe -v $file
2159 check_lpcc_state $file "none"
2160 check_file_data $SINGLEAGT $file "write_mod_data"
2162 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
2163 error "failed to RO-PCC attach file $file"
2164 check_lpcc_state $file "readonly"
2165 echo "PCC-RO attach '$file' again:"
2166 $LFS getstripe -v $file
2168 echo "Truncate invalidate the RO-PCC cache:"
2169 $TRUNCATE $file 256 || error "failed to truncate $file"
2170 $LFS getstripe -v $file
2171 echo "Finish trucate operation"
2172 check_lpcc_state $file "none"
2173 check_file_size $SINGLEAGT $file 256
2175 echo "Mmap write invalidates RO-PCC caching"
2176 echo -n mmap_write_data > $file || error "echo write $file failed"
2177 $LFS getstripe -v $file
2178 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
2179 error "failed to RO-PCC attach file $file"
2180 check_lpcc_state $file "readonly"
2181 echo "PCC-RO attach '$file' again:"
2182 $LFS getstripe -v $file
2183 echo "Mmap write $file via multiop"
2184 # Mmap write will invalidate the RO-PCC cache
2185 do_facet $SINGLEAGT $MULTIOP $file OSMWUc ||
2186 error "mmap write $file failed"
2187 check_lpcc_state $file "none"
2188 $LFS getstripe -v $file
2189 # After mmap-write by MULTIOP, the first character of the content
2191 content=$(do_facet $SINGLEAGT $MMAP_CAT $file)
2192 [[ $content == "nmap_write_data" ]] ||
2193 error "mmap_cat data mismatch: $content"
2195 run_test 23 "Test write/truncate/mmap-write invalidating RO-PCC caching"
2198 local loopfile="$TMP/$tfile"
2199 local mntpt="/mnt/pcc.$tdir"
2200 local hsm_root="$mntpt/$tdir"
2201 local file=$DIR/$tdir/$tfile
2204 $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
2205 skip "Server does not support PCC-RO"
2207 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
2208 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
2209 setup_pcc_mapping $SINGLEAGT \
2210 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0"
2211 $LCTL pcc list $MOUNT
2213 chmod 777 $DIR/$tdir
2215 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 ||
2216 error "failed to dd write to $file"
2217 do_facet $SINGLEAGT $RUNAS $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER \
2218 $file || error "failed to attach file $file"
2219 check_lpcc_state $file "readonly"
2220 do_facet $SINGLEAGT $RUNAS dd if=$file of=/dev/null bs=1024 count=1 ||
2221 error "failed to dd read from $file"
2222 check_lpcc_state $file "readonly"
2224 do_facet $SINGLEAGT $RUNAS $LFS pcc detach -k $file ||
2225 error "failed to detach file $file"
2226 check_lpcc_state $file "none"
2228 # non-root user is forbidden to access PCC file directly
2229 lpcc_path=$(lpcc_fid2path $hsm_root $file)
2230 do_facet $SINGLEAGT $RUNAS touch $lpcc_path &&
2231 error "non-root user can touch access PCC file $lpcc_path"
2232 do_facet $SINGLEAGT $RUNAS dd if=$lpcc_path of=/dev/null bs=1024 \
2233 count=1 && error "non-root user can read PCC file $lpcc_path"
2234 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$lpcc_path bs=1024 \
2235 count=1 && error "non-root user can write PCC file $lpcc_path"
2237 do_facet $SINGLEAGT $RUNAS $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER \
2238 $file || error "failed to attach file $file"
2239 check_lpcc_state $file "readonly"
2241 # Test RO-PCC detach as non-root user
2242 do_facet $SINGLEAGT $RUNAS $LFS pcc detach $file ||
2243 error "failed to detach file $file"
2244 check_lpcc_state $file "none"
2245 do_facet $SINGLEAGT "[ -f $lpcc_path ]" &&
2246 error "RO-PCC cached file '$lpcc_path' should be removed"
2250 run_test 24a "Test RO-PCC with non-root user"
2253 local loopfile="$TMP/$tfile"
2254 local mntpt="/mnt/pcc.$tdir"
2255 local hsm_root="$mntpt/$tdir"
2256 local file=$DIR/$tdir/$tfile
2258 $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
2259 skip "Server does not support PCC-RO"
2261 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
2262 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
2265 mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2266 dd if=/dev/zero of=$file bs=1024 count=1 ||
2267 error "failed to dd write $file"
2268 chmod 600 $file || error "chmod 600 $file failed"
2269 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 &&
2270 error "non-root user can dd write $file"
2271 do_facet $SINGLEAGT $RUNAS dd if=$file of=/dev/null bs=1024 count=1 &&
2272 error "non-root user can dd read $file"
2273 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
2274 error "failed to attach file $file"
2275 check_lpcc_state $file "readonly"
2276 do_facet $SINGLEAGT $RUNAS dd if=/dev/zero of=$file bs=1024 count=1 &&
2277 error "non-root user can dd write $file"
2278 do_facet $SINGLEAGT $RUNAS dd if=$file of=/dev/null bs=1024 count=1 &&
2279 error "non-root user can dd read $file"
2280 chmod 777 $file || error "chmod 777 $file failed"
2281 do_facet $SINGLEAGT $RUNAS dd if=$file of=/dev/null bs=1024 count=1 ||
2282 error "non-root user cannot read $file with permission (777)"
2283 check_lpcc_state $file "readonly"
2285 do_facet $SINGLEAGT $RUNAS $LFS pcc detach $file &&
2286 error "non-root user or non owner can detach $file"
2287 chown $RUNAS_ID $file || error "chown $RUNAS_ID $file failed"
2288 do_facet $SINGLEAGT $RUNAS $LFS pcc detach $file ||
2289 error "failed to detach file $file"
2290 check_lpcc_state $file "none"
2291 do_facet $SINGLEAGT $RUNAS dd if=$file of=/dev/null bs=1024 count=1 ||
2292 error "non-root user cannot read $file with permission (777)"
2294 run_test 24b "General permission test for RO-PCC"
2297 local loopfile="$TMP/$tfile"
2298 local mntpt="/mnt/pcc.$tdir"
2299 local hsm_root="$mntpt/$tdir"
2300 local file=$DIR/$tdir/$tfile
2303 $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
2304 skip "Server does not support PCC-RO"
2306 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
2307 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
2310 mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2312 echo "ro_fake_mmap_cat_err" > $file
2313 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
2314 error "failed to attach RO-PCC file $file"
2315 check_lpcc_state $file "readonly"
2316 check_file_data $SINGLEAGT $file "ro_fake_mmap_cat_err"
2318 # define OBD_FAIL_LLITE_PCC_FAKE_ERROR 0x1411
2319 do_facet $SINGLEAGT $LCTL set_param fail_loc=0x1411
2320 content=$(do_facet $SINGLEAGT $MMAP_CAT $file)
2321 [[ $content == "ro_fake_mmap_cat_err" ]] ||
2322 error "failed to fall back to Lustre I/O path for mmap-read"
2323 # Above mmap read will return VM_FAULT_SIGBUS failure and
2324 # retry the IO on normal IO path.
2325 check_lpcc_state $file "readonly"
2326 check_file_data $SINGLEAGT $file "ro_fake_mmap_cat_err"
2328 do_facet $SINGLEAGT $LFS pcc detach $file ||
2329 error "failed to detach RO-PCC file $file"
2330 check_lpcc_state $file "none"
2332 do_facet $SINGLEAGT $LCTL set_param fail_loc=0
2333 echo "ro_fake_cat_err" > $file
2334 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
2335 error "failed to attach RO-PCC file $file"
2336 check_lpcc_state $file "readonly"
2337 check_file_data $SINGLEAGT $file "ro_fake_cat_err"
2339 # define OBD_FAIL_LLITE_PCC_FAKE_ERROR 0x1411
2340 do_facet $SINGLEAGT $LCTL set_param fail_loc=0x1411
2341 # Fake read I/O will return -EIO failure and
2342 # retry the IO on normal IO path.
2343 check_file_data $SINGLEAGT $file "ro_fake_cat_err"
2344 check_lpcc_state $file "readonly"
2346 do_facet $SINGLEAGT $LFS pcc detach $file ||
2347 error "failed to detach RO-PCC file $file"
2348 check_lpcc_state $file "none"
2350 run_test 25 "Tolerate fake read failure for RO-PCC"
2353 local agt_host=$(facet_active_host $SINGLEAGT)
2354 local loopfile="$TMP/$tfile"
2355 local mntpt="/mnt/pcc.$tdir"
2356 local hsm_root="$mntpt/$tdir"
2357 local file=$DIR/$tfile
2359 $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
2360 skip "Server does not support PCC-RO"
2362 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
2363 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER" -h "$hsm_root"
2364 setup_pcc_mapping $SINGLEAGT \
2365 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0\ pccrw=1\ pccro=1"
2367 echo -n attach_keep_open > $file
2368 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
2369 error "attach $file failed"
2370 check_lpcc_state $file "readonly"
2371 rmultiop_start $agt_host $file O_c || error "multiop $file failed"
2372 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
2373 error "detach $file failed"
2374 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
2375 error "attach $file failed"
2376 check_lpcc_state $file "readonly"
2377 check_file_data $SINGLEAGT $file "attach_keep_open"
2378 check_lpcc_state $file "readonly"
2379 do_facet $SINGLEAGT $LFS pcc detach $file ||
2380 error "detach $file failed"
2381 rmultiop_stop $agt_host || error "multiop $file close failed"
2383 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
2384 error "attach $file failed"
2385 check_lpcc_state $file "readonly"
2386 rmultiop_start $agt_host $file O_c || error "multiop $file failed"
2387 do_facet $SINGLEAGT $LFS pcc detach $file ||
2388 error "detach $file failed"
2389 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
2390 error "attach $file failed"
2391 check_lpcc_state $file "readonly"
2392 check_file_data $SINGLEAGT $file "attach_keep_open"
2393 check_lpcc_state $file "readonly"
2394 do_facet $SINGLEAGT $LFS pcc detach $file ||
2395 error "detach $file failed"
2396 rmultiop_stop $agt_host || error "multiop $file close failed"
2398 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
2399 error "attach $file failed"
2400 check_lpcc_state $file "readonly"
2401 rmultiop_start $agt_host $file O_c || error "multiop $file failed"
2402 do_facet $SINGLEAGT $LFS pcc detach $file ||
2403 error "detach $file failed"
2404 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
2405 error "attach $file failed"
2406 check_lpcc_state $file "readonly"
2407 check_file_data $SINGLEAGT $file "attach_keep_open"
2408 check_lpcc_state $file "readonly"
2409 rmultiop_stop $agt_host || error "multiop $file close failed"
2410 do_facet $SINGLEAGT $LFS pcc detach $file ||
2411 error "detach $file failed"
2413 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER $file ||
2414 error "attach $file failed"
2415 check_lpcc_state $file "readwrite"
2416 rmultiop_start $agt_host $file O_c || error "multiop $file failed"
2417 do_facet $SINGLEAGT $LFS pcc detach $file ||
2418 error "detach $file failed"
2419 wait_request_state $(path2fid $file) REMOVE SUCCEED
2420 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
2421 error "attach $file failed"
2422 check_lpcc_state $file "readonly"
2423 check_file_data $SINGLEAGT $file "attach_keep_open"
2424 check_lpcc_state $file "readonly"
2425 rmultiop_stop $agt_host || error "multiop $file close failed"
2426 check_lpcc_state $file "readonly"
2427 do_facet $SINGLEAGT $LFS pcc detach $file ||
2428 error "detach $file failed"
2430 rm $file || error "rm $file failed"
2431 echo -n attach_keep_open > $file
2432 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER $file ||
2433 error "attach $file failed"
2434 check_lpcc_state $file "readwrite"
2435 rmultiop_start $agt_host $file O_c || error "multiop $file failed"
2436 do_facet $SINGLEAGT $LFS pcc detach $file ||
2437 error "detach $file failed"
2438 wait_request_state $(path2fid $file) REMOVE SUCCEED
2439 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
2440 error "attach $file failed"
2441 check_lpcc_state $file "readonly"
2442 check_file_data $SINGLEAGT $file "attach_keep_open"
2443 check_lpcc_state $file "readonly"
2444 do_facet $SINGLEAGT $LFS pcc detach $file ||
2445 error "detach $file failed"
2446 rmultiop_stop $agt_host || error "multiop $file close failed"
2447 check_lpcc_state $file "none"
2449 run_test 26 "Repeat the attach/detach when the file has multiple openers"
2452 local agt_host=$(facet_active_host $SINGLEAGT)
2453 local loopfile="$TMP/$tfile"
2454 local mntpt="/mnt/pcc.$tdir"
2455 local hsm_root="$mntpt/$tdir"
2456 local file=$DIR/$tfile
2458 $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
2459 skip "Server does not support PCC-RO"
2461 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
2462 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER" -h "$hsm_root"
2463 setup_pcc_mapping $SINGLEAGT \
2464 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ open_attach=1\ pccrw=1\ pccro=1"
2466 echo -n auto_attach_multi_open > $file
2467 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER $file ||
2468 error "attach $file failed"
2469 check_lpcc_state $file "readwrite"
2470 rmultiop_start $agt_host $file O_c || error "multiop $file failed"
2471 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
2472 error "detach $file failed"
2473 check_lpcc_state $file "readwrite"
2474 check_file_data $SINGLEAGT $file "auto_attach_multi_open"
2475 check_lpcc_state $file "readwrite"
2476 do_facet $SINGLEAGT $LFS pcc detach $file ||
2477 error "detach $file failed"
2478 wait_request_state $(path2fid $file) REMOVE SUCCEED
2479 check_lpcc_state $file "none"
2480 rmultiop_stop $agt_host || error "multiop $file close failed"
2482 rm $file || error "rm $file failed"
2483 echo -n auto_attach_multi_open > $file
2484 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER $file ||
2485 error "attach $file failed"
2486 check_lpcc_state $file "readwrite"
2487 rmultiop_start $agt_host $file O_c || error "multiop $file failed"
2488 do_facet $SINGLEAGT $LCTL \
2489 set_param ldlm.namespaces.*mdc*.lru_size=clear
2490 check_lpcc_state $file "readwrite"
2491 check_file_data $SINGLEAGT $file "auto_attach_multi_open"
2492 check_lpcc_state $file "readwrite"
2493 do_facet $SINGLEAGT $LFS pcc detach $file ||
2494 error "detach $file failed"
2495 wait_request_state $(path2fid $file) REMOVE SUCCEED
2496 check_lpcc_state $file "none"
2497 rmultiop_stop $agt_host || error "multiop $file close failed"
2499 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
2500 error "attach $file failed"
2501 check_lpcc_state $file "readonly"
2502 rmultiop_start $agt_host $file O_c || error "multiop $file failed"
2503 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
2504 error "detach $file failed"
2505 check_lpcc_state $file "readonly"
2506 check_file_data $SINGLEAGT $file "auto_attach_multi_open"
2507 check_lpcc_state $file "readonly"
2508 do_facet $SINGLEAGT $LFS pcc detach $file ||
2509 error "detach $file failed"
2510 check_lpcc_state $file "none"
2511 rmultiop_stop $agt_host || error "multiop $file close failed"
2513 do_facet $SINGLEAGT $LFS pcc attach -r -i $HSM_ARCHIVE_NUMBER $file ||
2514 error "attach $file failed"
2515 check_lpcc_state $file "readonly"
2516 rmultiop_start $agt_host $file O_c || error "multiop $file failed"
2517 do_facet $SINGLEAGT $LCTL \
2518 set_param ldlm.namespaces.*mdc*.lru_size=clear
2519 check_lpcc_state $file "readonly"
2520 check_file_data $SINGLEAGT $file "auto_attach_multi_open"
2521 check_lpcc_state $file "readonly"
2522 do_facet $SINGLEAGT $LFS pcc detach $file ||
2523 error "detach $file failed"
2524 check_lpcc_state $file "none"
2525 rmultiop_stop $agt_host || error "multiop $file close failed"
2527 run_test 27 "Auto attach at open when the file has multiple openers"
2530 local agt_host=$(facet_active_host $SINGLEAGT)
2531 local loopfile="$TMP/$tfile"
2532 local mntpt="/mnt/pcc.$tdir"
2533 local hsm_root="$mntpt/$tdir"
2534 local file=$DIR/$tfile
2535 local file2=$DIR2/$tfile
2538 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
2539 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER" -h "$hsm_root"
2540 setup_pcc_mapping $SINGLEAGT \
2541 "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0\ pccrw=1"
2543 echo -n rw_attach_hasopen_fail > $file
2544 rmultiop_start $agt_host $file O_c || error "multiop $file failed"
2545 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER $file &&
2546 error "attach $file should fail"
2547 rmultiop_stop $agt_host || error "multiop $file close failed"
2548 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER $file ||
2549 error "attach $file should fail"
2550 check_lpcc_state $file "readwrite"
2551 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
2552 error "detach $file failed"
2553 check_lpcc_state $file "none"
2555 multiop_bg_pause $file2 O_c || error "multiop $file2 failed"
2557 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER $file &&
2558 error "attach $file should fail"
2559 kill -USR1 $multipid
2560 wait $multipid || error "multiop $file2 close failed"
2561 do_facet $SINGLEAGT $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER $file ||
2562 error "failed to attach $file"
2563 check_lpcc_state $file "readwrite"
2564 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
2565 error "detach $file failed"
2566 check_lpcc_state $file "none"
2568 run_test 28 "RW-PCC attach should fail when the file has cluster-wide openers"
2571 local project_id=100
2572 local agt_facet=$SINGLEAGT
2573 local loopfile="$TMP/$tfile"
2574 local mntpt="/mnt/pcc.$tdir"
2575 local hsm_root="$mntpt/$tdir"
2576 local file=$DIR/$tdir/$tfile
2577 local file2=$DIR2/$tdir/$tfile
2579 $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
2580 skip "Server does not support PCC-RO"
2582 is_project_quota_supported || skip "project quota is not supported"
2584 enable_project_quota
2585 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
2586 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
2587 setup_pcc_mapping $SINGLEAGT \
2588 "projid={$project_id}\ rwid=$HSM_ARCHIVE_NUMBER\ pccro=1"
2589 $LCTL pcc list $MOUNT
2591 do_facet $SINGLEAGT mkdir -p $DIR/$tdir ||
2592 error "mkdir $DIR/$tdir failed"
2593 do_facet $SINGLEAGT "echo -n ro_uptodate > $file" ||
2594 error "failed to write $file"
2595 check_lpcc_state $file "none"
2596 $LFS project -sp $project_id $file ||
2597 error "failed to set project for $file"
2598 $LFS project -d $file
2599 check_lpcc_state $file "readonly"
2600 check_file_data $SINGLEAGT $file "ro_uptodate"
2602 echo -n Update_ro_data > $file2
2603 check_lpcc_state $file "readonly"
2604 check_file_data $SINGLEAGT $file "Update_ro_data"
2606 do_facet $SINGLEAGT $LFS pcc detach $file ||
2607 error "failed to detach $file"
2609 run_test 29a "Auto readonly caching on RO-PCC backend for O_RDONLY open"
2612 local loopfile="$TMP/$tfile"
2613 local mntpt="/mnt/pcc.$tdir"
2614 local hsm_root="$mntpt/$tdir"
2615 local file=$DIR/myfile.dat
2617 $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
2618 skip "Server does not support PCC-RO"
2620 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
2621 do_facet $SINGLEAGT mkdir $hsm_root || error "mkdir $hsm_root failed"
2622 setup_pcc_mapping $SINGLEAGT \
2623 "fname={*.dat}\ roid=$HSM_ARCHIVE_NUMBER\ pccro=1"
2624 do_facet $SINGLEAGT $LCTL pcc list $MOUNT
2626 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=4k count=1 ||
2627 error "Write $file failed"
2628 do_facet $SINGLEAGT dd if=$file of=/dev/null bs=4k count=1 ||
2629 error "Read $file failed"
2630 do_facet $SINGLEAGT $LFS pcc state $file
2631 check_lpcc_state $file "readonly"
2632 do_facet $SINGLEAGT dd if=/dev/zero of=$file bs=4k count=1 ||
2633 error "Write $file failed"
2634 sysctl vm.drop_caches=3
2635 do_facet $SINGLEAGT dd if=$file of=/dev/null bs=4k count=1 ||
2636 error "Read $file failed"
2637 do_facet $SINGLEAGT $LFS pcc state $file
2638 check_lpcc_state $file "readonly"
2640 do_facet $SINGLEAGT $LFS pcc detach $file || error "detach $file failed"
2642 run_test 29b "Auto PCC-RO attach in atomic_open"
2644 #test 101: containers and PCC
2645 #LU-15170: Test mount namespaces with PCC
2646 #This tests the cases where the PCC mount is not present in the container by
2647 #creating a mount namespace without the PCC mount in it (this is probably the
2648 #standard config for most containers)
2650 local loopfile="$TMP/$tfile"
2651 local mntpt="/mnt/pcc.$tdir"
2652 local hsm_root="$mntpt/$tdir"
2653 local file=$DIR/$tdir/$tfile
2655 # Some kernels such as RHEL7 default to 0 user namespaces
2656 local maxuserns=$(do_facet $SINGLEAGT cat /proc/sys/user/max_user_namespaces)
2657 do_facet $SINGLEAGT "echo 10 > /proc/sys/user/max_user_namespaces"
2658 stack_trap "do_facet $SINGLEAGT 'echo $maxuserns > /proc/sys/user/max_user_namespaces'"
2660 echo "creating user namespace for $RUNAS_ID"
2661 # Create a mount and user namespace with this command, and leave the
2662 # process running so we can do the rest of our steps
2663 local start=$SECONDS
2664 local PID=$(do_facet $SINGLEAGT \
2665 "$RUNAS unshare -Um sleep 600 &>/dev/null & echo \\\$!")
2666 local elapsed=$((SECONDS - start))
2669 do_facet $SINGLEAGT ps auxww | grep sleep
2670 echo "Created NS: child (sleep) pid=$PID in $elapsed seconds"
2671 [[ -n "$PID" ]] || error "remote sleep start failed"
2672 stack_trap "do_facet $SINGLEAGT kill -9 $PID" EXIT
2673 (( elapsed < 300 )) || error "remote sleep took $elapsed sec to start"
2675 # Map 'RUNAS' to root in the namespace, so it has rights to do whatever
2676 # This is handled by '-r' in unshare in newer versions
2677 do_facet $SINGLEAGT $RUNAS newuidmap $PID 0 $RUNAS_ID 1 ||
2678 error "could not map uid $RUNAS_ID to root in namespace"
2679 do_facet $SINGLEAGT $RUNAS newgidmap $PID 0 $RUNAS_GID 1 ||
2680 error "could not map gid $RUNAS_GID to root in namespace"
2682 # Create PCC after creating namespace; namespace will not have PCC
2684 setup_loopdev $SINGLEAGT $loopfile $mntpt 50
2686 # Create a temp file inside the PCC mount to verify mount namespace
2687 do_facet $SINGLEAGT touch $mntpt/$tfile.tmp
2688 stack_trap "do_facet $SINGLEAGT rm -f $mntpt/$tfile.tmp" EXIT
2689 echo "Check for temp file in PCC mount"
2690 do_facet $SINGLEAGT test -f $mntpt/$tfile.tmp ||
2691 error "Should see $mntpt/$tfile.tmp"
2692 echo "Check for temp file in PCC mount from inside namespace"
2693 do_facet $SINGLEAGT nsenter -t $PID -U -m test -f $mntpt/$tfile.tmp &&
2694 error "Should not see $mntpt/$tfile.tmp from namespace"
2695 rm -f $mntpt/$tfile.tmp
2698 copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
2699 setup_pcc_mapping $SINGLEAGT "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ pccrw=1"
2701 mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2702 chmod 777 $DIR/$tdir || error "chmod 777 $DIR/$tdir failed"
2704 echo "Verify open attach from inside mount namespace"
2705 do_facet $SINGLEAGT nsenter -t $PID -U -m dd if=/dev/zero of=$file bs=1024 count=1 ||
2706 error "failed to dd write to $file"
2707 do_facet $SINGLEAGT nsenter -t $PID -U -m $LFS pcc attach -w \
2708 -i $HSM_ARCHIVE_NUMBER $file || error "cannot attach $file"
2709 do_facet $SINGLEAGT nsenter -t $PID -U -m $LFS pcc state $file
2711 check_lpcc_state $file "readwrite" $SINGLEAGT "$RUNAS"
2712 # Revoke the layout lock, the PCC-cached file will be
2713 # detached automatically.
2714 do_facet $SINGLEAGT $LCTL set_param ldlm.namespaces.*mdc*.lru_size=clear
2715 check_lpcc_state $file "readwrite" $SINGLEAGT "$RUNAS"
2716 # Detach the file but keep the cache, as the file layout generation
2717 # is not changed, so the file is still valid cached in PCC, and can
2718 # be reused from PCC cache directly.
2719 do_facet $SINGLEAGT nsenter -t $PID -U -m $LFS pcc detach -k $file ||
2720 error "PCC detach $file failed"
2721 check_lpcc_state $file "readwrite" $SINGLEAGT "$RUNAS"
2722 do_facet $SINGLEAGT nsenter -t $PID -U -m $LFS pcc detach $file ||
2723 error "PCC detach $file failed"
2724 do_facet $SINGLEAGT nsenter -t $PID -U -m dd if=/dev/zero of=$file bs=1024 count=1 ||
2725 error "failed to dd write to $file"
2726 rm -f $file || error "rm $file failed"
2728 echo "Verify auto attach at open from inside NS for RW-PCC"
2729 # nsenter has strange behavior with echo, which means we have to place
2730 # this in a script so we can use sh, otherwise it doesn't execute echo
2732 # NB: using /bin/echo instead of the shell built in does not help
2733 echo "echo -n autoattach_data > $file" > $DIR/$tdir/$tfile.shell
2734 # File is owned by root, make it accessible to RUNAS user
2735 chmod a+rw $DIR/$tdir/$tfile.shell
2736 stack_trap 'rm -f $DIR/$tdir/$tfile.shell' EXIT
2737 do_facet $SINGLEAGT nsenter -t $PID -U -m "bash $DIR/$tdir/$tfile.shell"
2738 do_facet $SINGLEAGT nsenter -t $PID -U -m $LFS pcc attach -w -i $HSM_ARCHIVE_NUMBER \
2739 $file || error "RW-PCC attach $file failed"
2740 check_lpcc_state $file "readwrite"
2742 # Revoke the layout lock, the PCC-cached file will be
2743 # detached automatically.
2744 do_facet $SINGLEAGT $LCTL set_param ldlm.namespaces.*mdc*.lru_size=clear
2745 check_file_data $SINGLEAGT $file "autoattach_data" $PID
2746 check_lpcc_state $file "readwrite"
2748 # Detach the file with -k option, as the file layout generation
2749 # is not changed, so the file is still valid cached in PCC,
2750 # and can be reused from PCC cache directly.
2751 do_facet $SINGLEAGT $LFS pcc detach -k $file ||
2752 error "RW-PCC detach $file failed"
2753 check_lpcc_state $file "readwrite"
2754 # HSM released exists archived status
2755 check_hsm_flags $file "0x0000000d"
2756 check_file_data $SINGLEAGT $file "autoattach_data" $PID
2758 # HSM restore the PCC cached file, the layout generation
2759 # was changed, so the file can not be auto attached.
2760 $LFS hsm_restore $file || error "failed to restore $file"
2761 wait_request_state $(path2fid $file) RESTORE SUCCEED
2762 check_lpcc_state $file "none"
2763 # HSM exists archived status
2764 check_hsm_flags $file "0x00000009"
2766 run_test 101a "Test auto attach in mount namespace (simulated container)"
2769 grep -q io_uring_setup /proc/kallsyms ||
2770 skip "Client OS does not support io_uring I/O engine"
2771 io_uring_probe || skip "kernel does not support io_uring fully"
2773 $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
2774 skip "Server does not support PCC-RO"
2776 which fio || skip_env "no fio installed"
2777 fio --enghelp | grep -q io_uring ||
2778 skip_env "fio does not support io_uring I/O engine"
2780 local loopfile="$TMP/$tfile"
2781 local mntpt="/mnt/pcc.$tdir"
2782 local hsm_root="$mntpt/$tdir"
2783 local file=$DIR/$tfile
2785 setup_loopdev client $loopfile $mntpt 60
2786 mkdir $hsm_root || error "mkdir $hsm_root failed"
2787 setup_pcc_mapping client \
2788 "projid={0}\ roid=$HSM_ARCHIVE_NUMBER\ pccro=1"
2789 do_facet $SINGLEAGT $LCTL set_param llite.*.pcc_async_threshold=0
2791 local ioengine="io_uring"
2795 do_facet $SINGLEAGT fio --name=seqwrite --ioengine=$ioengine \
2796 --bs=$PAGE_SIZE --direct=1 --numjobs=$numjobs \
2797 --iodepth=64 --size=$size --filename=$file --rw=write ||
2798 error "fio seqwrite $file failed"
2800 # Read the file will trigger the buffered read from Lustre OSTs and
2801 # write to PCC copy as @pcc_async_threshold is set with 0.
2802 do_facet $SINGLEAGT fio --name=seqread --ioengine=$ioengine \
2803 --bs=$PAGE_SIZE --direct=1 --numjobs=$numjobs \
2804 --iodepth=64 --size=$size --filename=$file --rw=read ||
2805 error "fio seqread $file failed"
2807 run_test 102 "PCC-RO should not hange for io_uring I/O engine"
2809 complete_test $SECONDS
2810 check_and_cleanup_lustre