+test_29a() {
+ # Tests --mntpath and --archive options
+
+ local archive_id=7
+ copytool_setup $SINGLEAGT $MOUNT $archive_id
+
+ # Bad archive number
+ $LFS hsm_remove -m $MOUNT -a 33 0x857765760:0x8:0x2 2>&1 |
+ grep "Invalid argument" ||
+ error "unexpected hsm_remove failure (1)"
+
+ # mntpath is present but file is given
+ $LFS hsm_remove --mntpath $MOUNT --archive 30 /qwerty/uyt 2>&1 |
+ grep "hsm: '/qwerty/uyt' is not a valid FID" ||
+ error "unexpected hsm_remove failure (2)"
+
+ copytool_cleanup
+}
+run_test 29a "Tests --mntpath and --archive options"
+
+test_29b() {
+ # test needs a running copytool
+ copytool_setup
+
+ mkdir -p $DIR/$tdir
+ local f=$DIR/$tdir/$tfile
+ local fid=$(make_small $f)
+
+ $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
+ wait_request_state $fid ARCHIVE SUCCEED
+
+ rm -f $f
+
+ $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
+ wait_request_state $fid REMOVE SUCCEED
+
+ copytool_cleanup
+}
+run_test 29b "Archive/delete/remove by FID from the archive."
+
+test_29c() {
+ # test needs a running copytool
+ copytool_setup
+
+ mkdir -p $DIR/$tdir
+ local fid1=$(make_small $DIR/$tdir/$tfile-1)
+ local fid2=$(make_small $DIR/$tdir/$tfile-2)
+ local fid3=$(make_small $DIR/$tdir/$tfile-3)
+
+ $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
+ wait_request_state $fid1 ARCHIVE SUCCEED
+ wait_request_state $fid2 ARCHIVE SUCCEED
+ wait_request_state $fid3 ARCHIVE SUCCEED
+
+ rm -f $DIR/$tdir/$tfile-[1-3]
+
+ echo $fid1 > $DIR/$tdir/list
+ echo $fid2 >> $DIR/$tdir/list
+ echo $fid3 >> $DIR/$tdir/list
+
+ $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
+ --filelist $DIR/$tdir/list
+ wait_request_state $fid1 REMOVE SUCCEED
+ wait_request_state $fid2 REMOVE SUCCEED
+ wait_request_state $fid3 REMOVE SUCCEED
+
+ copytool_cleanup
+}
+run_test 29c "Archive/delete/remove by FID, using a file list."
+
+test_29d() {
+ # test needs more than one CT
+ needclients 3 || return 0
+
+ local n
+ local file
+ local fid
+
+ copytool_cleanup $(comma_list $(agts_nodes))
+
+ # start all of the copytools
+ for n in $(seq $AGTCOUNT); do
+ copytool_setup agt$n $MOUNT2 $n
+ done
+
+ trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
+ # archive files
+ mkdir -p $DIR/$tdir
+ file=$DIR/$tdir/$tfile
+ fid=$(make_small $file)
+
+ $LFS hsm_archive $file
+ wait_request_state $fid ARCHIVE SUCCEED
+ check_hsm_flags $file "0x00000009"
+
+ rm -f $file
+
+ $LFS hsm_remove -a 0 $fid
+
+ # give time for CDT to handle remove request and create broadcasted
+ sleep 2
+
+ # remove request has been broadcasted ?
+ local cnt=$(get_request_count $fid REMOVE)
+ # broadcasted requests + original
+ [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
+ error "remove not broadcasted to all CTs"
+
+ # give time for CDT and CTs to handle broadcasted
+ wait_for_loop_period
+
+ # each agent serves one different archive_id, so broadcasted
+ # hsm_remove request should only succeed once and fail at all others
+ local res
+ local scnt=0
+ local fcnt=0
+ for n in $(seq $AGTCOUNT); do
+ res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
+ $HSM_PARAM.actions | awk \
+ '/'$fid'.*action=REMOVE archive#='$n'/ \
+ {print \\\$13}' | cut -f2 -d=")
+ if [[ "$res" == "SUCCEED" ]]; then
+ scnt=$((scnt + 1))
+ elif [[ "$res" == "FAILED" ]]; then
+ fcnt=$((fcnt + 1))
+ fi
+ done
+
+ [[ $scnt -ne 1 ]] &&
+ error "one and only CT should have removed successfully"
+
+ [[ $AGTCOUNT -ne $((scnt + fcnt)) ]] &&
+ error "all but one CT should have failed to remove"
+
+ trap - EXIT
+ copytool_cleanup $(comma_list $(agts_nodes))
+
+}
+run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
+ "request to be sent once for each registered archive_id"
+