+ 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