tests: remove unused functions

As found by
  git -C tests/ grep ^function | grep -vFe '.lua:' -e '.zcp:' | while IFS=":$IFS" read -r _ _ fn _; do [ $(git -C tests/ grep -wF $fn | head -2 | wc -l) -eq 1 ] && echo $fn; done
after all rounds this comes out to, sorted:
  check_slog_state
  chgusr_exec
  cksum_files
  cleanup_pools
  compare_modes
  count_ACE
  dataset_set_defaultproperties
  ds_is_snapshot
  get_ACE
  get_group
  get_min
  get_mode
  get_owner
  get_rand_checksum
  get_rand_checksum_any
  get_rand_large_recsize
  get_rand_recsize
  get_user_group
  getitem
  indirect_vdev_mapping_size
  is_dilos
  log_noresult
  log_notinuse
  log_other
  log_timed_out
  log_uninitiated
  log_warning
  num_jobs_by_cpu
  plus_sign_check_l
  plus_sign_check_v
  record_cksum
  rwx_node
  seconds_mmp_waits_for_activity
  set_cur_usr
  setup_mirrors
  setup_raidzs
  showshares_smb
  zfs_zones_setup

This, of course, doesn't catch recursive ones, or ones that log with
their own function name as a prefix, but

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #13259
This commit is contained in:
наб
2022-03-24 13:15:00 +01:00
committed by Brian Behlendorf
parent 5c9f744b1a
commit fbe811b054
10 changed files with 6 additions and 809 deletions
@@ -31,21 +31,6 @@
. $STF_SUITE/tests/functional/acl/acl.cfg
. $STF_SUITE/include/libtest.shlib
#
# Get the given file/directory access mode
#
# $1 object -- file or directory
#
function get_mode #<obj>
{
typeset obj=$1
if (( ${#obj} == 0 )); then
return 1
fi
ls -ld $obj | awk '{print $1}'
}
#
# Get the given file/directory ACL
#
@@ -115,36 +100,6 @@ function compare_acls #<src> <tgt>
return $ret
}
#
# Check that the given two objects have the same modes.
# Return 0, if their modes are equal with each other. Otherwise, return 1.
#
# $1 source object
# $2 target object
#
function compare_modes #<src> <tgt>
{
typeset src=$1
typeset tgt=$2
typeset -i i=0
set -A mode
(( ${#src} == 0 || ${#tgt} == 0 )) && return 1
[[ $src == $tgt ]] && return 0
typeset obj
for obj in $src $tgt
do
mode[i]=$(get_mode $obj)
(( i = i + 1 ))
done
[[ ${mode[0]} != ${mode[1]} ]] && return 1
return 0
}
#
# Check that the given two objects have the same xattrs.
# Return 0, if their xattrs are equal with each other. Otherwise, return 1.
@@ -173,57 +128,6 @@ function compare_xattrs #<src> <tgt>
return $ret
}
#
# Check '+' is set for a given file/directory with 'ls [-l]' command
#
# $1 object -- file or directory.
#
function plus_sign_check_l #<obj>
{
typeset obj=$1
if (( ${#obj} == 0 )); then
return 1
fi
! ls -ld $obj | awk '$1 ~ /\+$/ {exit 1}'
}
#
# Check '+' is set for a given file/directory with 'ls [-v]' command
#
# $1 object -- file or directory.
#
function plus_sign_check_v #<obj>
{
typeset obj=$1
if (( ${#obj} == 0 )); then
return 1
fi
! ls -vd $obj | awk 'NR == 1 && $1 ~ /\+$ {exit 1}'
}
#
# A wrapper function of c program
#
# $1 legal login name
# $2-n commands and options
#
function chgusr_exec #<login_name> <commands> [...]
{
chg_usr_exec $@
}
#
# Export the current user for the following usr_exec operating.
#
# $1 legal login name
#
function set_cur_usr #<login_name>
{
export ZFS_ACL_CUR_USER=$1
}
#
# Run commands by $ZFS_ACL_CUR_USER
#
@@ -234,80 +138,6 @@ function usr_exec #<commands> [...]
chg_usr_exec "$ZFS_ACL_CUR_USER" $@
}
#
# Count how many ACEs for the specified file or directory.
#
# $1 file or directory name
#
function count_ACE #<file or dir name>
{
if [[ ! -e $1 ]]; then
log_note "Need input file or directory name."
return 1
fi
ls -vd $1 | awk 'BEGIN {count=0}
(NR != 1)&&(/[0-9]:/) {count++}
END {print count}'
return 0
}
#
# Get specified number ACE content of specified file or directory.
#
# $1 file or directory name
# $2 specified number
#
function get_ACE #<file or dir name> <specified number> <verbose|compact>
{
if [[ ! -e $1 || $2 -ge $(count_ACE $1) ]]; then
return 1
fi
typeset file=$1
typeset -i num=$2
typeset format=${3:-verbose}
typeset -i next_num=-1
typeset tmpfile=$TEST_BASE_DIR/tmp_get_ACE.$$
typeset line=""
typeset args
case $format in
verbose) args="-vd"
;;
compact) args="-Vd"
;;
*) log_fail "Invalid parameter as ($format), " \
"only verbose|compact is supported."
;;
esac
log_must eval "ls $args $file > $tmpfile"
while read line; do
[[ -z $line ]] && continue
if [[ $args == -vd ]]; then
if [[ $line == "$num":* ]]; then
(( next_num = num + 1 ))
fi
if [[ $line == "$next_num":* ]]; then
break
fi
if (( next_num != -1 )); then
print -n $line
fi
else
if (( next_num == num )); then
print -n $line
fi
(( next_num += 1 ))
fi
done < $tmpfile
log_must rm -f $tmpfile
}
#
# Cleanup exist user/group.
#
@@ -337,57 +167,6 @@ function cleanup
fi
}
#
# According to specified access or acl_spec, do relevant operating by using the
# specified user.
#
# $1 specified user
# $2 node
# $3 acl_spec or access
#
function rwx_node #user node acl_spec|access
{
typeset user=$1
typeset node=$2
typeset acl_spec=$3
if [[ $user == "" || $node == "" || $acl_spec == "" ]]; then
log_note "node or acl_spec are not defined."
return 1
fi
if [[ -d $node ]]; then
case $acl_spec in
*:read_data:*|read_data)
chgusr_exec $user ls -l $node > /dev/null 2>&1
;;
*:write_data:*|write_data)
if [[ -f ${node}/tmpfile ]]; then
log_must rm -f ${node}/tmpfile
fi
chgusr_exec $user touch ${node}/tmpfile > \
/dev/null 2>&1
;;
*"execute:"*|execute)
chgusr_exec $user find $node > /dev/null 2>&1
;;
esac
else
case $acl_spec in
*:read_data:*|read_data)
chgusr_exec $user cat $node > /dev/null 2>&1
;;
*:write_data:*|write_data)
chgusr_exec $user dd if=/usr/bin/ls of=$node > \
/dev/null 2>&1
;;
*"execute:"*|execute)
ZFS_ACL_ERR_STR=$(chgusr_exec $user $node 2>&1)
;;
esac
fi
}
#
# Get the given file/directory xattr
#
@@ -406,121 +185,6 @@ function get_xattr #<obj>
done
}
#
# Get the owner of a file/directory
#
function get_owner #node
{
typeset node=$1
typeset value
if [[ -z $node ]]; then
log_fail "node is not defined."
fi
if [[ -d $node ]]; then
ls -dl $node
elif [[ -e $node ]]; then
ls -l $node
fi | awk '{print $3}'
}
#
# Get the group of a file/directory
#
function get_group #node
{
typeset node=$1
typeset value
if [[ -z $node ]]; then
log_fail "node are not defined."
fi
if [[ -d $node ]]; then
ls -dl $node
elif [[ -e $node ]]; then
ls -l $node
fi | awk '{print $4}'
}
#
# Get the group name that a UID belongs to
#
function get_user_group #uid
{
typeset uid=$1
typeset value
if [[ -z $uid ]]; then
log_fail "UID not defined."
fi
if value=$(id $uid); then
value=${value##*\(}
value=${value%%\)*}
echo $value
else
log_fail "Invalid UID (uid)."
fi
}
#
# Get the specified item of the specified string
#
# $1: Item number, count from 0.
# $2-n: strings
#
function getitem
{
typeset -i n=$1
shift
(( n += 1 ))
eval echo \${$n}
}
#
# This function calculate the specified directory files checksum and write
# to the specified array.
#
# $1 directory in which the files will be cksum.
# $2 file array name which was used to store file cksum information.
# $3 attribute array name which was used to store attribute information.
#
function cksum_files #<dir> <file_array_name> <attribute_array_name>
{
typeset dir=$1
typeset farr_name=$2
typeset aarr_name=$3
[[ ! -d $dir ]] && return
typeset oldpwd=$PWD
cd $dir
typeset files=$(ls file*)
typeset -i i=0
typeset -i n=0
while (( i < NUM_FILE )); do
typeset f=$(getitem $i $files)
eval $farr_name[$i]=\$\(\cksum $f\)
typeset -i j=0
while (( j < NUM_ATTR )); do
eval $aarr_name[$n]=\$\(\runat \$f \cksum \
attribute.$j\)
(( j += 1 ))
(( n += 1 ))
done
(( i += 1 ))
done
cd $oldpwd
}
#
# This function compare two cksum results array.
#
@@ -548,26 +212,6 @@ function compare_cksum #<array1> <array2>
return 0
}
#
# This function calculate all the files cksum information in current directory
# and output them to the specified file.
#
# $1 directory from which the files will be cksum.
# $2 cksum output file
#
function record_cksum #<outfile>
{
typeset dir=$1
typeset outfile=$2
[[ ! -d ${outfile%/*} ]] && usr_exec mkdir -p ${outfile%/*}
usr_exec cd $dir ; find . -depth -type f -exec cksum {} \\\; | \
sort > $outfile
usr_exec cd $dir ; find . -depth -type f -xattr -exec runat {} \
cksum attribute* \\\; | sort >> $outfile
}
#
# The function create_files creates the directories and files that the script
# will operate on to test extended attribute functionality.
@@ -151,43 +151,6 @@ function mmp_pool_set_hostid # pool hostid
return 0
}
# Return the number of seconds the activity check portion of the import process
# will take. Does not include the time to find devices and assemble a config.
# Note that the activity check may be skipped, e.g. if the pool and host
# hostid's match, but this will return non-zero because mmp_* are populated.
function seconds_mmp_waits_for_activity
{
typeset pool=$1
typeset devpath=$2
typeset seconds=0
typeset devices=${#DISK[@]}
typeset import_intervals=$(get_tunable MULTIHOST_IMPORT_INTERVALS)
typeset import_interval=$(get_tunable MULTIHOST_INTERVAL)
typeset tmpfile=$(mktemp)
typeset mmp_fail
typeset mmp_write
typeset mmp_delay
log_must eval "zdb -e -p $devpath $pool >$tmpfile 2>/dev/null"
mmp_fail=$(awk '/mmp_fail/ {print $NF}' $tmpfile)
mmp_write=$(awk '/mmp_write/ {print $NF}' $tmpfile)
mmp_delay=$(awk '/mmp_delay/ {print $NF}' $tmpfile)
rm $tmpfile
# In order of preference:
if [ -n $mmp_fail -a -n $mmp_write ]; then
seconds=$((2*mmp_fail*mmp_write/1000))
elif [ -n $mmp_delay ]; then
# MMP V0: Based on mmp_delay from the best Uberblock
seconds=$((import_intervals*devices*mmp_delay/1000000000))
else
# Non-MMP aware: Based on zfs_multihost_interval and import_intervals
seconds=$((import_intervals*import_interval/1000))
fi
echo $seconds
}
function import_no_activity_check # pool opts
{
@@ -88,13 +88,6 @@ function attempt_during_removal # pool disk callback [args]
return 0
}
function indirect_vdev_mapping_size # pool
{
typeset pool=$1
zdb -P $pool | grep 'indirect vdev' | \
sed -E 's/.*\(([0-9]+) in memory\).*/\1/g'
}
function random_write # file write_size
{
typeset file=$1
@@ -155,12 +155,6 @@ function cleanup_pool
fi
}
function cleanup_pools
{
cleanup_pool $POOL2
destroy_pool $POOL3
}
function cmp_md5s {
typeset file1=$1
typeset file2=$2
-14
View File
@@ -524,20 +524,6 @@ function get_system_config
echo "}" >>$config
}
function num_jobs_by_cpu
{
if is_linux; then
typeset ncpu=$($NPROC --all)
else
typeset ncpu=$(psrinfo | $WC -l)
fi
typeset num_jobs=$ncpu
[[ $ncpu -gt 8 ]] && num_jobs=$(echo "$ncpu * 3 / 4" | bc)
echo $num_jobs
}
#
# On illumos this looks like: ":sd3:sd4:sd1:sd2:"
#