+test_255()
+{
+ [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
+ skip "Need MDS version at least 2.12.0"
+
+ local file="$DIR/$tdir/$tfile"
+ local fid=$(create_empty_file "$file")
+
+ # How do you make sure the coordinator has consumed any outstanding
+ # event, without triggering an event yourself?
+ #
+ # You wait for a request to disappear from the coordinator's llog.
+
+ # Warning: the setup represents 90% of this test
+
+ # Create and process an HSM request
+ copytool setup
+ "$LFS" hsm_archive "$file"
+ wait_request_state $fid ARCHIVE SUCCEED
+
+ kill_copytools
+ wait_copytools || error "failed to stop copytools"
+
+ # Launch a new HSM request
+ rm "$file"
+ create_empty_file "$file"
+ "$LFS" hsm_archive "$file"
+
+ cdt_shutdown
+
+ # Have the completed request be removed as soon as the cdt wakes up
+ stack_trap "set_hsm_param grace_delay $(get_hsm_param grace_delay)" EXIT
+ set_hsm_param grace_delay 1
+ # (Hopefully, time on the MDS will behave nicely)
+ do_facet $SINGLEMDS sleep 2 &
+
+ # Increase `loop_period' as a mean to prevent the coordinator from
+ # waking itself up to do some housekeeping.
+ stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
+ set_hsm_param loop_period 1000
+
+ wait $! || error "waiting failed"
+ cdt_enable
+ wait_request_state $fid ARCHIVE ""
+ # The coordinator will not wake up on its own for ~`loop_period' secs...
+
+ # ... Unless a copytool registers. Now the real test begins
+ copytool setup
+ wait_request_state $(path2fid "$file") ARCHIVE SUCCEED
+}
+run_test 255 "Copytool registration wakes the coordinator up"
+
+# tests 260[a-c] rely on the parsing of the copytool's log file, they might
+# break in the future because of that.
+test_260a()
+{
+ [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
+ skip "need MDS version 2.11.56 or later"
+
+ local -a files=("$DIR/$tdir/$tfile".{0..15})
+ local file
+
+ for file in "${files[@]}"; do
+ create_small_file "$file"
+ done
+
+ # Set a few hsm parameters
+ stack_trap \
+ "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
+ set_hsm_param loop_period 1
+ stack_trap \
+ "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
+ set_hsm_param max_requests 3
+
+ # Release one file
+ copytool setup
+ "$LFS" hsm_archive "${files[0]}"
+ wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
+ "$LFS" hsm_release "${files[0]}"
+
+ # Stop the copytool
+ kill_copytools
+ wait_copytools || error "copytools failed to stop"
+
+ # Send several archive requests
+ for file in "${files[@]:1}"; do
+ "$LFS" hsm_archive "$file"
+ done
+
+ # Send one restore request
+ "$LFS" hsm_restore "${files[0]}"
+
+ # Launch a copytool
+ copytool setup
+
+ # Wait for all the requests to complete
+ wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
+ for file in "${files[@]:1}"; do
+ wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
+ done
+
+ # Collect the actions in the order in which the copytool processed them
+ local -a actions=(
+ $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
+ "$(copytool_logfile "$SINGLEAGT")")
+ )
+
+ printf '%s\n' "${actions[@]}"
+
+ local action
+ for action in "${actions[@]:0:3}"; do
+ [ "$action" == RESTORE ] && return
+ done
+
+ error "Too many ARCHIVE requests were run before the RESTORE request"
+}
+run_test 260a "Restore request have priority over other requests"
+
+# This test is very much tied to the implementation of the current priorisation
+# mechanism in the coordinator. It might not make sense to keep it in the future
+test_260b()
+{
+ [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
+ skip "need MDS version 2.11.56 or later"
+
+ local -a files=("$DIR/$tdir/$tfile".{0..15})
+ local file
+
+ for file in "${files[@]}"; do
+ create_small_file "$file"
+ done
+
+ # Set a few hsm parameters
+ stack_trap \
+ "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
+ set_hsm_param loop_period 1
+ stack_trap \
+ "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
+ set_hsm_param max_requests 3
+
+ # Release one file
+ copytool setup --archive-id 2
+ "$LFS" hsm_archive --archive 2 "${files[0]}"
+ wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
+ "$LFS" hsm_release "${files[0]}"
+
+ # Stop the copytool
+ kill_copytools
+ wait_copytools || error "copytools failed to stop"
+
+ # Send several archive requests
+ for file in "${files[@]:1}"; do
+ "$LFS" hsm_archive "$file"
+ done
+
+ # Send one restore request
+ "$LFS" hsm_restore "${files[0]}"
+
+ # Launch a copytool
+ copytool setup
+ copytool setup --archive-id 2
+
+ # Wait for all the requests to complete
+ wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
+ for file in "${files[@]:1}"; do
+ wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
+ done
+
+ # Collect the actions in the order in which the copytool processed them
+ local -a actions=(
+ $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
+ "$(copytool_logfile "$SINGLEAGT")")
+ )
+
+ printf '%s\n' "${actions[@]}"
+
+ local action
+ for action in "${actions[@]:0:3}"; do
+ [ "$action" == RESTORE ] && return
+ done
+
+ error "Too many ARCHIVE requests were run before the RESTORE request"
+}
+run_test 260b "Restore request have priority over other requests"
+
+# This test is very much tied to the implementation of the current priorisation
+# mechanism in the coordinator. It might not make sense to keep it in the future
+test_260c()
+{
+ [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
+ skip "Need MDS version at least 2.12.0"
+
+ local -a files=("$DIR/$tdir/$tfile".{0..15})
+ local file
+
+ for file in "${files[@]}"; do
+ create_small_file "$file"
+ done
+
+ # Set a few hsm parameters
+ stack_trap \
+ "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
+ set_hsm_param loop_period 1000
+ stack_trap \
+ "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
+ set_hsm_param max_requests 3
+
+ # Release one file
+ copytool setup --archive-id 2
+ "$LFS" hsm_archive --archive 2 "${files[0]}"
+ wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
+ "$LFS" hsm_release "${files[0]}"
+
+ # Stop the copytool
+ kill_copytools
+ wait_copytools || error "copytools failed to stop"
+
+ # Force the next coordinator run to do housekeeping
+ cdt_shutdown
+ cdt_enable
+
+ "$LFS" hsm_archive "${files[1]}"
+
+ # Launch a copytool
+ copytool setup
+ copytool setup --archive-id 2
+
+ wait_request_state "$(path2fid "${files[1]}")" ARCHIVE SUCCEED
+ # The coordinator just did a housekeeping run it won't do another one
+ # for around `loop_period' seconds => requests will not be reordered
+ # if it costs too much (ie. when the coordinator has to discard a whole
+ # hal)
+
+ # Send several archive requests
+ for file in "${files[@]:2}"; do
+ "$LFS" hsm_archive "$file"
+ done
+
+ # Send one restore request
+ "$LFS" hsm_restore "${files[0]}"
+
+ # Wait for all the requests to complete
+ wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
+ for file in "${files[@]:2}"; do
+ wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
+ done
+
+ # Collect the actions in the order in which the copytool processed them
+ local -a actions=(
+ $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
+ "$(copytool_logfile "$SINGLEAGT")")
+ )
+
+ printf '%s\n' "${actions[@]}"
+
+ local action
+ for action in "${actions[@]:0:3}"; do
+ [ "$action" == RESTORE ] &&
+ error "Restore requests should not be prioritised" \
+ "unless the coordinator is doing housekeeping"
+ done
+ return 0
+}
+run_test 260c "Requests are not reordered on the 'hot' path of the coordinator"
+