ZTS: change `$(cat)` to `$(<)` for speedup

It's better to use ksh/bash built in methods,
rather than spawn new processes every time.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: John Wren Kennedy <john.kennedy@delphix.com>
Signed-off-by: George Melikov <mail@gmelikov.ru>
Closes #8071
This commit is contained in:
George Melikov 2018-10-31 20:00:06 +03:00 committed by Brian Behlendorf
parent 9553c533a6
commit 58aeb87a8f
15 changed files with 40 additions and 40 deletions

View File

@ -18,7 +18,7 @@
# $1: number of lines to output (default: 40) # $1: number of lines to output (default: 40)
typeset lines=${1:-40} typeset lines=${1:-40}
typeset history=$(cat /sys/module/zfs/parameters/zfs_multihost_history) typeset history=$(</sys/module/zfs/parameters/zfs_multihost_history)
if [ $history -eq 0 ]; then if [ $history -eq 0 ]; then
exit exit

View File

@ -3332,7 +3332,7 @@ function zed_stop
log_note "Stopping ZED" log_note "Stopping ZED"
if [[ -f ${ZEDLET_DIR}/zed.pid ]]; then if [[ -f ${ZEDLET_DIR}/zed.pid ]]; then
zedpid=$(cat ${ZEDLET_DIR}/zed.pid) zedpid=$(<${ZEDLET_DIR}/zed.pid)
kill $zedpid kill $zedpid
while ps -p $zedpid > /dev/null; do while ps -p $zedpid > /dev/null; do
sleep 1 sleep 1

View File

@ -67,10 +67,10 @@ function log_program
outdiff=$(diff "$basename.out" "$tmpout") outdiff=$(diff "$basename.out" "$tmpout")
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
output=$(cat $tmpout) output=$(<$tmpout)
rm $tmpout $tmperr $tmpin rm $tmpout $tmperr $tmpin
log_fail "Output mismatch. Expected:\n" \ log_fail "Output mismatch. Expected:\n" \
"$(cat $basename.out)\nBut got:\n$output\n" \ "$(<$basename.out)\nBut got:\n$output\n" \
"Diff:\n$outdiff" "Diff:\n$outdiff"
fi fi
@ -78,10 +78,10 @@ function log_program
outdiff=$(diff "$basename.err" "$tmperr") outdiff=$(diff "$basename.err" "$tmperr")
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
outputerror=$(cat $tmperr) outputerror=$(<$tmperr)
rm $tmpout $tmperr $tmpin rm $tmpout $tmperr $tmpin
log_fail "Error mismatch. Expected:\n" \ log_fail "Error mismatch. Expected:\n" \
"$(cat $basename.err)\nBut got:\n$outputerror\n" \ "$(<$basename.err)\nBut got:\n$outputerror\n" \
"Diff:\n$outdiff" "Diff:\n$outdiff"
fi fi
@ -89,7 +89,7 @@ function log_program
grep -q "$expecterror" $tmperr grep -q "$expecterror" $tmperr
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
outputerror=$(cat $tmperr) outputerror=$(<$tmperr)
rm $tmpout $tmperr $tmpin rm $tmpout $tmperr $tmpin
log_fail "Error mismatch. Expected to contain:\n" \ log_fail "Error mismatch. Expected to contain:\n" \
"$expecterror\nBut got:\n$outputerror\n" "$expecterror\nBut got:\n$outputerror\n"
@ -100,7 +100,7 @@ function log_program
# If there's no expected output, error reporting is allowed to # If there's no expected output, error reporting is allowed to
# vary, but ensure that we didn't fail silently. # vary, but ensure that we didn't fail silently.
# #
if [[ -z "$(cat $tmperr)" ]]; then if [[ -z "$(<$tmperr)" ]]; then
rm $tmpout $tmperr $tmpin rm $tmpout $tmperr $tmpin
log_fail "error with no stderr output" log_fail "error with no stderr output"
fi fi

View File

@ -220,8 +220,8 @@ function test_verify_pre_checkpoint_state
{ {
log_must zfs list $FS0 log_must zfs list $FS0
log_must zfs list $FS1 log_must zfs list $FS1
log_must [ "$(cat $FS0FILE)" = "$FILECONTENTS0" ] log_must [ "$(<$FS0FILE)" = "$FILECONTENTS0" ]
log_must [ "$(cat $FS1FILE)" = "$FILECONTENTS1" ] log_must [ "$(<$FS1FILE)" = "$FILECONTENTS1" ]
# #
# If we've opened the checkpointed state of the # If we've opened the checkpointed state of the
@ -236,15 +236,15 @@ function test_verify_pre_checkpoint_state
# Ensure post-checkpoint state is not present # Ensure post-checkpoint state is not present
# #
log_mustnot zfs list $FS2 log_mustnot zfs list $FS2
log_mustnot [ "$(cat $FS0FILE)" = "$NEWFILECONTENTS0" ] log_mustnot [ "$(<$FS0FILE)" = "$NEWFILECONTENTS0" ]
} }
function nested_verify_pre_checkpoint_state function nested_verify_pre_checkpoint_state
{ {
log_must zfs list $NESTEDFS0 log_must zfs list $NESTEDFS0
log_must zfs list $NESTEDFS1 log_must zfs list $NESTEDFS1
log_must [ "$(cat $NESTEDFS0FILE)" = "$FILECONTENTS0" ] log_must [ "$(<$NESTEDFS0FILE)" = "$FILECONTENTS0" ]
log_must [ "$(cat $NESTEDFS1FILE)" = "$FILECONTENTS1" ] log_must [ "$(<$NESTEDFS1FILE)" = "$FILECONTENTS1" ]
# #
# If we've opened the checkpointed state of the # If we've opened the checkpointed state of the
@ -259,7 +259,7 @@ function nested_verify_pre_checkpoint_state
# Ensure post-checkpoint state is not present # Ensure post-checkpoint state is not present
# #
log_mustnot zfs list $NESTEDFS2 log_mustnot zfs list $NESTEDFS2
log_mustnot [ "$(cat $NESTEDFS0FILE)" = "$NEWFILECONTENTS0" ] log_mustnot [ "$(<$NESTEDFS0FILE)" = "$NEWFILECONTENTS0" ]
} }
function test_change_state_after_checkpoint function test_change_state_after_checkpoint
@ -284,8 +284,8 @@ function test_verify_post_checkpoint_state
{ {
log_must zfs list $FS0 log_must zfs list $FS0
log_must zfs list $FS2 log_must zfs list $FS2
log_must [ "$(cat $FS0FILE)" = "$NEWFILECONTENTS0" ] log_must [ "$(<$FS0FILE)" = "$NEWFILECONTENTS0" ]
log_must [ "$(cat $FS2FILE)" = "$NEWFILECONTENTS2" ] log_must [ "$(<$FS2FILE)" = "$NEWFILECONTENTS2" ]
log_must zdb $TESTPOOL log_must zdb $TESTPOOL
@ -294,7 +294,7 @@ function test_verify_post_checkpoint_state
# is not present # is not present
# #
log_mustnot zfs list $FS1 log_mustnot zfs list $FS1
log_mustnot [ "$(cat $FS0FILE)" = "$FILECONTENTS0" ] log_mustnot [ "$(<$FS0FILE)" = "$FILECONTENTS0" ]
} }
function fragment_before_checkpoint function fragment_before_checkpoint

View File

@ -37,10 +37,10 @@ fi
verify_runnable "global" verify_runnable "global"
ZFS_USER=$(cat $TEST_BASE_DIR/zfs-privs-test-user.txt) ZFS_USER=$(<$TEST_BASE_DIR/zfs-privs-test-user.txt)
[[ -z $ZFS_USER ]] && log_fail "no ZFS_USER found" [[ -z $ZFS_USER ]] && log_fail "no ZFS_USER found"
USES_NIS=$(cat $TEST_BASE_DIR/zfs-privs-test-nis.txt) USES_NIS=$(<$TEST_BASE_DIR/zfs-privs-test-nis.txt)
if [ "${USES_NIS}" == "true" ] if [ "${USES_NIS}" == "true" ]
then then

View File

@ -63,7 +63,7 @@ fi
log_assert "The RBAC profile \"ZFS Storage Management\" works" log_assert "The RBAC profile \"ZFS Storage Management\" works"
ZFS_USER=$(cat $TEST_BASE_DIR/zfs-privs-test-user.txt) ZFS_USER=$(<$TEST_BASE_DIR/zfs-privs-test-user.txt)
# the user shouldn't be able to do anything initially # the user shouldn't be able to do anything initially
log_mustnot user_run $ZFS_USER "zpool create $TESTPOOL $DISKS" log_mustnot user_run $ZFS_USER "zpool create $TESTPOOL $DISKS"

View File

@ -66,7 +66,7 @@ fi
log_assert "The RBAC profile \"ZFS File System Management\" works" log_assert "The RBAC profile \"ZFS File System Management\" works"
ZFS_USER=$(cat $TEST_BASE_DIR/zfs-privs-test-user.txt) ZFS_USER=$(<$TEST_BASE_DIR/zfs-privs-test-user.txt)
# Set a $DATASET where we can create child files systems # Set a $DATASET where we can create child files systems
if is_global_zone; then if is_global_zone; then

View File

@ -86,7 +86,7 @@ function check_all
state1=$(zpool status $pool | awk '/state: /{print $2}'); state1=$(zpool status $pool | awk '/state: /{print $2}');
state2=$(zpool list -H -o health $pool) state2=$(zpool list -H -o health $pool)
state3=$(cat /proc/spl/kstat/zfs/$pool/state) state3=$(</proc/spl/kstat/zfs/$pool/state)
log_note "Checking $expected = $state1 = $state2 = $state3" log_note "Checking $expected = $state1 = $state2 = $state3"
if [[ "$expected" == "$state1" && "$expected" == "$state2" && \ if [[ "$expected" == "$state1" && "$expected" == "$state2" && \
"$expected" == "$state3" ]] ; then "$expected" == "$state3" ]] ; then

View File

@ -86,7 +86,7 @@ typeset default_max_entries
log_onexit cleanup log_onexit cleanup
default_max_entries=$(cat $MAX_ENTRIES_PARAM) || log_fail default_max_entries=$(<$MAX_ENTRIES_PARAM) || log_fail
echo 50 >$MAX_ENTRIES_PARAM || log_fail echo 50 >$MAX_ENTRIES_PARAM || log_fail
# Clear all of the existing entries. # Clear all of the existing entries.

View File

@ -67,8 +67,8 @@ log_onexit cleanup
log_must set_tunable32 zfs_remove_max_segment 32768 log_must set_tunable32 zfs_remove_max_segment 32768
log_must dd if=/dev/urandom of=$TESTDIR/$TESTFILE0 bs=128k count=1 log_must dd if=/dev/urandom of=$TESTDIR/$TESTFILE0 bs=128k count=1
FILE_CONTENTS=`cat $TESTDIR/$TESTFILE0` FILE_CONTENTS=$(<$TESTDIR/$TESTFILE0)
log_must [ "x$(cat $TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ] log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
for i in {1..10}; do for i in {1..10}; do
log_must zpool remove $TESTPOOL $TMPDIR/dsk1 log_must zpool remove $TESTPOOL $TMPDIR/dsk1
@ -78,7 +78,7 @@ for i in {1..10}; do
log_must zinject -a log_must zinject -a
log_must dd if=$TESTDIR/$TESTFILE0 of=/dev/null log_must dd if=$TESTDIR/$TESTFILE0 of=/dev/null
log_must [ "x$(cat $TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ] log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
log_must zpool remove $TESTPOOL $TMPDIR/dsk2 log_must zpool remove $TESTPOOL $TMPDIR/dsk2
log_must wait_for_removal $TESTPOOL log_must wait_for_removal $TESTPOOL
@ -87,7 +87,7 @@ for i in {1..10}; do
log_must zinject -a log_must zinject -a
log_must dd if=$TESTDIR/$TESTFILE0 of=/dev/null log_must dd if=$TESTDIR/$TESTFILE0 of=/dev/null
log_must [ "x$(cat $TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ] log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
done done
log_pass "File contents transferred completely from one disk to another." log_pass "File contents transferred completely from one disk to another."

View File

@ -27,13 +27,13 @@ log_onexit default_cleanup_noexit
FILE_CONTENTS="Leeloo Dallas mul-ti-pass." FILE_CONTENTS="Leeloo Dallas mul-ti-pass."
echo $FILE_CONTENTS >$TESTDIR/$TESTFILE0 echo $FILE_CONTENTS >$TESTDIR/$TESTFILE0
log_must [ "x$(cat $TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ] log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
log_must zpool remove $TESTPOOL $REMOVEDISK log_must zpool remove $TESTPOOL $REMOVEDISK
log_must wait_for_removal $TESTPOOL log_must wait_for_removal $TESTPOOL
log_mustnot vdevs_in_pool $TESTPOOL $REMOVEDISK log_mustnot vdevs_in_pool $TESTPOOL $REMOVEDISK
log_must dd if=/$TESTDIR/$TESTFILE0 of=/dev/null log_must dd if=/$TESTDIR/$TESTFILE0 of=/dev/null
log_must [ "x$(cat $TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ] log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
log_pass "Removed device not in use after removal." log_pass "Removed device not in use after removal."

View File

@ -31,9 +31,9 @@ FILE_CONTENTS="Leeloo Dallas mul-ti-pass."
echo $FILE_CONTENTS >$TESTDIR/$TESTFILE0 echo $FILE_CONTENTS >$TESTDIR/$TESTFILE0
echo $FILE_CONTENTS >$TESTDIR/$TESTFILE1 echo $FILE_CONTENTS >$TESTDIR/$TESTFILE1
echo $FILE_CONTENTS >$TESTDIR/$TESTFILE2 echo $FILE_CONTENTS >$TESTDIR/$TESTFILE2
log_must [ "x$(cat $TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ] log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
log_must [ "x$(cat $TESTDIR/$TESTFILE1)" = "x$FILE_CONTENTS" ] log_must [ "x$(<$TESTDIR/$TESTFILE1)" = "x$FILE_CONTENTS" ]
log_must [ "x$(cat $TESTDIR/$TESTFILE2)" = "x$FILE_CONTENTS" ] log_must [ "x$(<$TESTDIR/$TESTFILE2)" = "x$FILE_CONTENTS" ]
log_must zpool remove $TESTPOOL $REMOVEDISK log_must zpool remove $TESTPOOL $REMOVEDISK
log_must wait_for_removal $TESTPOOL log_must wait_for_removal $TESTPOOL
@ -42,8 +42,8 @@ log_mustnot vdevs_in_pool $TESTPOOL $REMOVEDISK
log_must dd if=/$TESTDIR/$TESTFILE0 of=/dev/null log_must dd if=/$TESTDIR/$TESTFILE0 of=/dev/null
log_must dd if=/$TESTDIR/$TESTFILE1 of=/dev/null log_must dd if=/$TESTDIR/$TESTFILE1 of=/dev/null
log_must dd if=/$TESTDIR/$TESTFILE2 of=/dev/null log_must dd if=/$TESTDIR/$TESTFILE2 of=/dev/null
log_must [ "x$(cat $TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ] log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
log_must [ "x$(cat $TESTDIR/$TESTFILE1)" = "x$FILE_CONTENTS" ] log_must [ "x$(<$TESTDIR/$TESTFILE1)" = "x$FILE_CONTENTS" ]
log_must [ "x$(cat $TESTDIR/$TESTFILE2)" = "x$FILE_CONTENTS" ] log_must [ "x$(<$TESTDIR/$TESTFILE2)" = "x$FILE_CONTENTS" ]
log_pass "Removed device not in use after removal." log_pass "Removed device not in use after removal."

View File

@ -34,7 +34,7 @@ log_onexit cleanup
FILE_CONTENTS="Leeloo Dallas mul-ti-pass." FILE_CONTENTS="Leeloo Dallas mul-ti-pass."
echo $FILE_CONTENTS >$TESTDIR/$TESTFILE0 echo $FILE_CONTENTS >$TESTDIR/$TESTFILE0
log_must [ "x$(cat $TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ] log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
log_must file_write -o create -f $TESTDIR/$TESTFILE1 -b $((2**20)) -c $((2**7)) log_must file_write -o create -f $TESTDIR/$TESTFILE1 -b $((2**20)) -c $((2**7))
log_must zpool remove $TESTPOOL $REMOVEDISK log_must zpool remove $TESTPOOL $REMOVEDISK
@ -42,6 +42,6 @@ log_must wait_for_removal $TESTPOOL
log_mustnot vdevs_in_pool $TESTPOOL $REMOVEDISK log_mustnot vdevs_in_pool $TESTPOOL $REMOVEDISK
log_must dd if=/$TESTDIR/$TESTFILE0 of=/dev/null log_must dd if=/$TESTDIR/$TESTFILE0 of=/dev/null
log_must [ "x$(cat $TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ] log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
log_pass "Removed device not in use after removal." log_pass "Removed device not in use after removal."

View File

@ -39,7 +39,7 @@ elif [[ -f $WORDS_FILE2 ]]; then
log_must cp $WORDS_FILE2 $TESTDIR log_must cp $WORDS_FILE2 $TESTDIR
else else
echo $FILE_CONTENTS >$TESTDIR/$TESTFILE0 echo $FILE_CONTENTS >$TESTDIR/$TESTFILE0
log_must [ "x$(cat $TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ] log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
fi fi
log_must zpool remove $TESTPOOL mirror-1 log_must zpool remove $TESTPOOL mirror-1
@ -52,7 +52,7 @@ elif [[ -f $WORDS_FILE2 ]]; then
log_must diff $WORDS_FILE2 $TESTDIR/words log_must diff $WORDS_FILE2 $TESTDIR/words
else else
log_must dd if=/$TESTDIR/$TESTFILE0 of=/dev/null log_must dd if=/$TESTDIR/$TESTFILE0 of=/dev/null
log_must [ "x$(cat $TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ] log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
fi fi
log_pass "Removed top-level mirror device not in use after removal." log_pass "Removed top-level mirror device not in use after removal."

View File

@ -416,7 +416,7 @@ function get_system_config
then then
printf ",\n" >>$config printf ",\n" >>$config
fi fi
printf " \"$tunable\": \"$(cat $zfs_tunables/$tunable)\"" \ printf " \"$tunable\": \"$(<$zfs_tunables/$tunable)\"" \
>>$config >>$config
done done
printf "\n }\n" >>$config printf "\n }\n" >>$config