+ atime1=$(stat -c "%X" $file)
+ mtime1=$(stat -c "%Y" $file)
+ ctime1=$(stat -c "%Z" $file)
+
+ [ $atime0 -eq $atime1 ] ||
+ error "archive changed atime from $atime0 to $atime1"
+
+ [ $mtime0 -eq $mtime1 ] ||
+ error "archive changed mtime from $mtime0 to $mtime1"
+
+ [ $ctime0 -eq $ctime1 ] ||
+ error "archive changed ctime from $ctime0 to $ctime1"
+
+ # Release should not change any timestamps.
+ $LFS hsm_release $file || error "cannot release '$file'"
+ check_hsm_flags $file "0x0000000d"
+
+ atime1=$(stat -c "%X" $file)
+ mtime1=$(stat -c "%Y" $file)
+ ctime1=$(stat -c "%Z" $file)
+
+ [ $atime0 -eq $atime1 ] ||
+ error "release changed atime from $atime0 to $atime1"
+
+ [ $mtime0 -eq $mtime1 ] ||
+ error "release changed mtime from $mtime0 to $mtime1"
+
+ [ $ctime0 -eq $ctime1 ] ||
+ error "release changed ctime from $ctime0 to $ctime1"
+
+ # Restore should not change atime or mtime and should not
+ # decrease ctime.
+ $LFS hsm_restore $file
+ wait_request_state $fid RESTORE SUCCEED
+
+ atime1=$(stat -c "%X" $file)
+ mtime1=$(stat -c "%Y" $file)
+ ctime1=$(stat -c "%Z" $file)
+
+ [ $atime0 -eq $atime1 ] ||
+ error "restore changed atime from $atime0 to $atime1"
+
+ [ $mtime0 -eq $mtime1 ] ||
+ error "restore changed mtime from $mtime0 to $mtime1"
+
+ [ $ctime0 -le $ctime1 ] ||
+ error "restore changed ctime from $ctime0 to $ctime1"
+
+ copytool_cleanup
+
+ # Once more, after unmount and mount.
+ umount_client $MOUNT || error "cannot unmount '$MOUNT'"
+ mount_client $MOUNT || error "cannot mount '$MOUNT'"
+
+ atime1=$(stat -c "%X" $file)
+ mtime1=$(stat -c "%Y" $file)
+ ctime1=$(stat -c "%Z" $file)
+
+ [ $atime0 -eq $atime1 ] ||
+ error "remount changed atime from $atime0 to $atime1"
+
+ [ $mtime0 -eq $mtime1 ] ||
+ error "remount changed mtime from $mtime0 to $mtime1"
+
+ [ $ctime0 -le $ctime1 ] ||
+ error "remount changed ctime from $ctime0 to $ctime1"
+}
+run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
+
+test_24b() {
+ local file=$DIR/$tdir/$tfile
+ local fid
+ local sum0
+ local sum1
+ # LU-3811
+
+ # Test needs a running copytool.
+ copytool_setup
+ mkdir -p $DIR/$tdir
+
+ # Check that root can do HSM actions on a ordinary user's file.
+ rm -f $file
+ fid=$(make_small $file)
+ sum0=$(md5sum $file)
+
+ chown $RUNAS_ID:$RUNAS_GID $file ||
+ error "cannot chown '$file' to '$RUNAS_ID'"
+
+ chmod ugo-w $DIR/$tdir ||
+ error "cannot chmod '$DIR/$tdir'"
+
+ $LFS hsm_archive $file
+ wait_request_state $fid ARCHIVE SUCCEED
+
+ $LFS hsm_release $file
+ check_hsm_flags $file "0x0000000d"
+
+ $LFS hsm_restore $file
+ wait_request_state $fid RESTORE SUCCEED
+
+ # Check that ordinary user can get HSM state.
+ $RUNAS $LFS hsm_state $file ||
+ error "user '$RUNAS_ID' cannot get HSM state of '$file'"
+
+ $LFS hsm_release $file
+ check_hsm_flags $file "0x0000000d"
+
+ # Check that ordinary user can accessed released file.
+ sum1=$($RUNAS md5sum $file) ||
+ error "user '$RUNAS_ID' cannot read '$file'"
+
+ [ "$sum0" == "$sum1" ] ||
+ error "md5sum mismatch for '$file'"
+
+ copytool_cleanup
+}
+run_test 24b "root can archive, release, and restore user files"
+
+cleanup_test_24c() {
+ trap 0
+ set_hsm_param user_request_mask RESTORE
+ set_hsm_param group_request_mask RESTORE
+ set_hsm_param other_request_mask RESTORE
+}
+
+test_24c() {
+ local file=$DIR/$tdir/$tfile
+ local action=archive
+ local user_save
+ local group_save
+ local other_save
+
+ # test needs a running copytool
+ copytool_setup
+
+ mkdir -p $DIR/$tdir
+
+ # Save the default masks and check that cleanup_24c will
+ # restore the request masks correctly.
+ user_save=$(get_hsm_param user_request_mask)
+ group_save=$(get_hsm_param group_request_mask)
+ other_save=$(get_hsm_param other_request_mask)
+
+ [ "$user_save" == RESTORE ] ||
+ error "user_request_mask is '$user_save' expected 'RESTORE'"
+ [ "$group_save" == RESTORE ] ||
+ error "group_request_mask is '$group_save' expected 'RESTORE'"
+ [ "$other_save" == RESTORE ] ||
+ error "other_request_mask is '$other_save' expected 'RESTORE'"
+
+ trap cleanup_test_24c EXIT
+
+ # User.
+ rm -f $file
+ make_small $file
+ chown $RUNAS_ID:nobody $file ||
+ error "cannot chown '$file' to '$RUNAS_ID:nobody'"
+
+ set_hsm_param user_request_mask ""
+ $RUNAS $LFS hsm_$action $file &&
+ error "$action by user should fail"
+
+ set_hsm_param user_request_mask $action
+ $RUNAS $LFS hsm_$action $file ||
+ error "$action by user should succeed"
+
+ # Group.
+ rm -f $file
+ make_small $file
+ chown nobody:$RUNAS_GID $file ||
+ error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
+
+ set_hsm_param group_request_mask ""
+ $RUNAS $LFS hsm_$action $file &&
+ error "$action by group should fail"
+
+ set_hsm_param group_request_mask $action
+ $RUNAS $LFS hsm_$action $file ||
+ error "$action by group should succeed"
+
+ # Other.
+ rm -f $file
+ make_small $file
+ chown nobody:nobody $file ||
+ error "cannot chown '$file' to 'nobody:nobody'"
+
+ set_hsm_param other_request_mask ""
+ $RUNAS $LFS hsm_$action $file &&
+ error "$action by other should fail"
+
+ set_hsm_param other_request_mask $action
+ $RUNAS $LFS hsm_$action $file ||
+ error "$action by other should succeed"
+
+ copytool_cleanup
+ cleanup_test_24c
+}
+run_test 24c "check that user,group,other request masks work"
+
+cleanup_test_24d() {
+ trap 0
+ mount -o remount,rw $MOUNT2
+}
+
+test_24d() {
+ local file1=$DIR/$tdir/$tfile
+ local file2=$DIR2/$tdir/$tfile
+ local fid1
+ local fid2
+
+ copytool_setup
+
+ mkdir -p $DIR/$tdir
+ rm -f $file1
+ fid1=$(make_small $file1)
+
+ trap cleanup_test_24d EXIT
+
+ mount -o remount,ro $MOUNT2