+test_17() {
+ local agt_host=$(facet_active_host $SINGLEAGT)
+ local loopfile="$TMP/$tfile"
+ local mntpt="/mnt/pcc.$tdir"
+ local hsm_root="$mntpt/$tdir"
+ local file=$DIR/$tfile
+
+ setup_loopdev $SINGLEAGT $loopfile $mntpt 50
+ copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
+ setup_pcc_mapping $SINGLEAGT \
+ "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ open_attach=0\ stat_attach=0"
+
+ do_facet $SINGLEAGT $LCTL pcc list $MOUNT
+
+ do_facet $SINGLEAGT "echo -n layout_refresh_data > $file"
+ do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
+ error "PCC attach $file failed"
+ check_lpcc_state $file "readwrite"
+
+ do_facet $SINGLEAGT $LFS pcc detach -k $file ||
+ error "PCC detach $file failed"
+ check_lpcc_state $file "none"
+
+ # Truncate should attach the file into PCC automatically
+ # as the PCC copy is still valid.
+ echo "Verify auto attach during IO for truncate"
+ do_facet $SINGLEAGT $TRUNCATE $file 4 || error "truncate $file failed"
+ check_lpcc_state $file "readwrite"
+
+ echo "Verify auto attach during IO for read/write"
+ rmultiop_start $agt_host $file O_r || error "open $file failed"
+ sleep 3
+
+ # Revoke the layout lock, the PCC-cached file will be
+ # detached automatically.
+ do_facet $SINGLEAGT $LCTL \
+ set_param ldlm.namespaces.*mdc*.lru_size=clear
+
+ check_lpcc_state $file "none"
+ rmultiop_stop $agt_host || error "close $file failed"
+ sleep 3
+ check_lpcc_state $file "readwrite"
+
+ do_facet $SINGLEAGT $LFS pcc detach -k $file ||
+ error "PCC detach $file failed"
+ check_lpcc_state $file "none"
+}
+run_test 17 "Test auto attach for layout refresh"
+