+ local fid
+ fid=$(make_large_for_progress $f)
+ [ $? != 0 ] && skip "not enough free space" && return
+
+ local mdtidx=0
+ local mdt=${MDT_PREFIX}${mdtidx}
+ local mds=mds$((mdtidx + 1))
+
+ # Wait for copytool to register
+ wait_update_facet $mds \
+ "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
+ uuid 100 || error "coyptool failed to register with $mdt"
+
+ local start_at=$(date +%s)
+ $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
+ error "could not archive file"
+
+ local agent=$(facet_active_host $SINGLEAGT)
+ local prefix=$TESTLOG_PREFIX
+ [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
+ local copytool_log=$prefix.copytool_log.$agent.log
+
+
+ wait_update $agent \
+ "grep -o start.copy $copytool_log" "start copy" 100 ||
+ error "copytool failed to start"
+
+ local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
+ cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
+
+ local RESULT
+ local WAIT=0
+ local sleep=1
+
+ echo -n "Expecting a progress update within $progress_timeout seconds... "
+ while [ true ]; do
+ RESULT=$(do_node $(facet_active_host $mds) "$cmd")
+ if [ $RESULT -gt 0 ]; then
+ echo "$RESULT bytes copied in $WAIT seconds."
+ break
+ elif [ $WAIT -ge $progress_timeout ]; then
+ error "Timed out waiting for progress update!"
+ break
+ fi
+ WAIT=$((WAIT + sleep))
+ sleep $sleep
+ done
+
+ local finish_at=$(date +%s)
+ local elapsed=$((finish_at - start_at))
+
+ # Ensure that the progress update occurred within the expected window.
+ if [ $elapsed -lt $interval ]; then
+ error "Expected progress update after at least $interval seconds"
+ fi
+
+ cdt_clear_no_retry
+ copytool_cleanup
+}
+run_test 60 "Changing progress update interval from default"
+
+test_70() {
+ # test needs a new running copytool
+ copytool_cleanup
+ copytool_monitor_setup
+ HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
+
+ # Just start and stop the copytool to generate events.
+ cdt_clear_no_retry
+
+ # Wait for the copytool to register.
+ wait_update --verbose $(facet_active_host mds1) \
+ "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
+ uuid 100 ||
+ error "copytool failed to register with MDT0000"
+
+ copytool_cleanup
+
+ local REGISTER_EVENT
+ local UNREGISTER_EVENT
+ while read event; do
+ local parsed=$(parse_json_event "$event")
+ if [ -z "$parsed" ]; then
+ error "Copytool sent malformed event: $event"
+ fi
+ eval $parsed
+
+ if [ $event_type == "REGISTER" ]; then
+ REGISTER_EVENT=$event
+ elif [ $event_type == "UNREGISTER" ]; then
+ UNREGISTER_EVENT=$event
+ fi
+ done < <(echo $"$(get_copytool_event_log)")
+
+ if [ -z "$REGISTER_EVENT" ]; then
+ error "Copytool failed to send register event to FIFO"
+ fi
+
+ if [ -z "$UNREGISTER_EVENT" ]; then
+ error "Copytool failed to send unregister event to FIFO"
+ fi
+
+ copytool_monitor_cleanup
+ echo "Register/Unregister events look OK."
+}
+run_test 70 "Copytool logs JSON register/unregister events to FIFO"
+
+test_71() {
+ # Bump progress interval for livelier events.
+ local interval=5
+
+ # test needs a new running copytool
+ copytool_cleanup
+ copytool_monitor_setup
+ HSMTOOL_UPDATE_INTERVAL=$interval \
+ HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
+
+ mkdir -p $DIR/$tdir
+ local f=$DIR/$tdir/$tfile
+ local fid
+ fid=$(make_large_for_progress $f)
+ [ $? != 0 ] && skip "not enough free space" && return
+
+ $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
+ error "could not archive file"
+ wait_request_state $fid ARCHIVE SUCCEED
+
+ local expected_fields="event_time data_fid source_fid"
+ expected_fields+=" total_bytes current_bytes"
+
+ local START_EVENT
+ local FINISH_EVENT
+ while read event; do
+ # Make sure we're not getting anything from previous events.
+ for field in $expected_fields; do
+ unset $field
+ done
+
+ local parsed=$(parse_json_event "$event")
+ if [ -z "$parsed" ]; then
+ error "Copytool sent malformed event: $event"
+ fi
+ eval $parsed
+
+ if [ $event_type == "ARCHIVE_START" ]; then
+ START_EVENT=$event
+ continue
+ elif [ $event_type == "ARCHIVE_FINISH" ]; then
+ FINISH_EVENT=$event
+ continue
+ elif [ $event_type != "ARCHIVE_RUNNING" ]; then
+ continue
+ fi
+
+ # Do some simple checking of the progress update events.
+ for expected_field in $expected_fields; do
+ if [ -z ${!expected_field+x} ]; then
+ error "Missing $expected_field field in event"
+ fi
+ done
+
+ if [ $total_bytes -eq 0 ]; then
+ error "Expected total_bytes to be > 0"
+ fi
+
+ # These should be identical throughout an archive
+ # operation.
+ if [ $source_fid != $data_fid ]; then
+ error "Expected source_fid to equal data_fid"
+ fi
+ done < <(echo $"$(get_copytool_event_log)")
+
+ if [ -z "$START_EVENT" ]; then
+ error "Copytool failed to send archive start event to FIFO"
+ fi
+
+ if [ -z "$FINISH_EVENT" ]; then
+ error "Copytool failed to send archive finish event to FIFO"
+ fi
+
+ echo "Archive events look OK."
+
+ cdt_clear_no_retry
+ copytool_cleanup
+ copytool_monitor_cleanup
+}
+run_test 71 "Copytool logs JSON archive events to FIFO"
+
+test_72() {
+ # Bump progress interval for livelier events.
+ local interval=5
+
+ # test needs a new running copytool
+ copytool_cleanup
+ copytool_monitor_setup
+ HSMTOOL_UPDATE_INTERVAL=$interval \
+ HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
+ local test_file=$HSMTOOL_MONITOR_DIR/file
+
+ local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
+ cmd+="conv=fsync"
+ do_facet $SINGLEAGT "$cmd" ||
+ error "cannot create $test_file on $SINGLEAGT"
+ copy2archive $test_file $tdir/$tfile
+
+ mkdir -p $DIR/$tdir
+ local f=$DIR/$tdir/$tfile
+ import_file $tdir/$tfile $f
+ f=$DIR2/$tdir/$tfile
+ echo "Verifying released state: "
+ check_hsm_flags $f "0x0000000d"
+
+ local fid=$(path2fid $f)
+ $LFS hsm_restore $f
+ wait_request_state $fid RESTORE SUCCEED
+
+ local expected_fields="event_time data_fid source_fid"
+ expected_fields+=" total_bytes current_bytes"
+
+ local START_EVENT
+ local FINISH_EVENT
+ while read event; do
+ # Make sure we're not getting anything from previous events.
+ for field in $expected_fields; do
+ unset $field
+ done
+
+ local parsed=$(parse_json_event "$event")
+ if [ -z "$parsed" ]; then
+ error "Copytool sent malformed event: $event"
+ fi
+ eval $parsed
+
+ if [ $event_type == "RESTORE_START" ]; then
+ START_EVENT=$event
+ if [ $source_fid != $data_fid ]; then
+ error "source_fid should == data_fid at start"
+ fi
+ continue
+ elif [ $event_type == "RESTORE_FINISH" ]; then
+ FINISH_EVENT=$event
+ if [ $source_fid != $data_fid ]; then
+ error "source_fid should == data_fid at finish"
+ fi
+ continue
+ elif [ $event_type != "RESTORE_RUNNING" ]; then
+ continue
+ fi
+
+ # Do some simple checking of the progress update events.
+ for expected_field in $expected_fields; do
+ if [ -z ${!expected_field+x} ]; then
+ error "Missing $expected_field field in event"
+ fi
+ done
+
+ if [ $total_bytes -eq 0 ]; then
+ error "Expected total_bytes to be > 0"
+ fi
+
+ # When a restore starts out, the data fid is the same as the
+ # source fid. After the restore has gotten going, we learn
+ # the new data fid. Once the restore has finished, the source
+ # fid is set to the new data fid.
+ #
+ # We test this because some monitoring software may depend on
+ # this behavior. If it changes, then the consumers of these
+ # events may need to be modified.
+ if [ $source_fid == $data_fid ]; then
+ error "source_fid should != data_fid during restore"
+ fi
+ done < <(echo $"$(get_copytool_event_log)")
+
+ if [ -z "$START_EVENT" ]; then
+ error "Copytool failed to send restore start event to FIFO"
+ fi
+
+ if [ -z "$FINISH_EVENT" ]; then
+ error "Copytool failed to send restore finish event to FIFO"
+ fi
+
+ echo "Restore events look OK."
+
+ cdt_clear_no_retry
+ copytool_cleanup
+ copytool_monitor_cleanup
+
+ rm -rf $test_dir
+}
+run_test 72 "Copytool logs JSON restore events to FIFO"
+
+test_90() {
+ file_count=51 # Max number of files constrained by LNET message size
+ mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
+ local f=$DIR/$tdir/$tfile