Trim excess shellcheck annotations. Widen to all non-Korn scripts

Before, make shellcheck checked
  scripts/{commitcheck,make_gitrev,man-dates,paxcheck,zfs-helpers,zfs,
           zfs-tests,zimport,zloop}.sh
  cmd/zed/zed.d/{{all-debug,all-syslog,data-notify,generic-notify,
                 resilver_finish-start-scrub,scrub_finish-notify,
                 statechange-led,statechange-notify,trim_finish-notify,
                 zed-functions}.sh,history_event-zfs-list-cacher.sh.in}
  cmd/zpool/zpool.d/{dm-deps,iostat,lsblk,media,ses,smart,upath}
now it also checks
  contrib/dracut/{02zfsexpandknowledge/module-setup,
                  90zfs/{export-zfs,parse-zfs,zfs-needshutdown,
                         zfs-load-key,zfs-lib,module-setup,
                         mount-zfs,zfs-generator}}.sh.in
  cmd/zed/zed.d/{pool_import-led,vdev_attach-led,
                 resilver_finish-notify,vdev_clear-led}.sh
  contrib/initramfs/{zfsunlock,hooks/zfs.in,scripts/local-top/zfs}
  tests/zfs-tests/tests/perf/scripts/prefetch_io.sh
  scripts/common.sh.in
  contrib/bpftrace/zfs-trace.sh
  autogen.sh

Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #12042
This commit is contained in:
наб 2021-05-14 14:02:11 +02:00 committed by Brian Behlendorf
parent 59d91b4d10
commit e40ffed021
18 changed files with 72 additions and 88 deletions

View File

@ -126,9 +126,9 @@ filter_executable = -exec test -x '{}' \; -print
PHONY += shellcheck PHONY += shellcheck
shellcheck: shellcheck:
@if type shellcheck > /dev/null 2>&1; then \ @if type shellcheck > /dev/null 2>&1; then \
shellcheck --exclude=SC1090 --exclude=SC1117 --format=gcc \ shellcheck --exclude=SC1090,SC1117,SC1091 --format=gcc \
$$(find ${top_srcdir}/scripts/*.sh -type f) \ $$(find ${top_srcdir} -name "config*" -prune -name tests -prune \
$$(find ${top_srcdir}/cmd/zed/zed.d/*.sh -type f) \ -o -name "*.sh" -o -name "*.sh.in" -type f) \
$$(find ${top_srcdir}/cmd/zpool/zpool.d/* \ $$(find ${top_srcdir}/cmd/zpool/zpool.d/* \
-type f ${filter_executable}); \ -type f ${filter_executable}); \
else \ else \

View File

@ -26,15 +26,15 @@ for dataset in "$@"; do
case "$(@sbindir@/zpool list -Ho health "$pool")" in case "$(@sbindir@/zpool list -Ho health "$pool")" in
DEGRADED) DEGRADED)
ret=$(( $ret | 4 )) ret=$(( ret | 4 ))
;; ;;
FAULTED) FAULTED)
awk '!/^([[:space:]]*#.*)?$/ && $1 == "'"$dataset"'" && $3 == "zfs" {exit 1}' /etc/fstab || \ awk '!/^([[:space:]]*#.*)?$/ && $1 == "'"$dataset"'" && $3 == "zfs" {exit 1}' /etc/fstab || \
ret=$(( $ret | 8 )) ret=$(( ret | 8 ))
;; ;;
"") "")
# Pool not found, error printed by zpool(8) # Pool not found, error printed by zpool(8)
ret=$(( $ret | 8 )) ret=$(( ret | 8 ))
;; ;;
*) *)
;; ;;

View File

@ -263,7 +263,7 @@ zed_notify_email()
-e "s/@SUBJECT@/${subject}/g")" -e "s/@SUBJECT@/${subject}/g")"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
eval "${ZED_EMAIL_PROG}" ${ZED_EMAIL_OPTS} < "${pathname}" >/dev/null 2>&1 ${ZED_EMAIL_PROG} ${ZED_EMAIL_OPTS} < "${pathname}" >/dev/null 2>&1
rv=$? rv=$?
if [ "${rv}" -ne 0 ]; then if [ "${rv}" -ne 0 ]; then
zed_log_err "$(basename "${ZED_EMAIL_PROG}") exit=${rv}" zed_log_err "$(basename "${ZED_EMAIL_PROG}") exit=${rv}"

View File

@ -20,6 +20,7 @@ filter_out_deleted_zvols() {
OIFS="$IFS" OIFS="$IFS"
IFS=" IFS="
" "
# shellcheck disable=SC2086
zfs list -H -o name $zvols 2>/dev/null zfs list -H -o name $zvols 2>/dev/null
IFS="$OIFS" IFS="$OIFS"
} }

View File

@ -14,21 +14,16 @@ get_pool_devices() {
local poolconfigtemp local poolconfigtemp
local poolconfigoutput local poolconfigoutput
local pooldev local pooldev
local prefix
local resolved local resolved
poolconfigtemp=`mktemp` poolconfigtemp="$(mktemp)"
if ! @sbindir@/zpool list -v -H -P "$1" > "$poolconfigtemp" 2>&1 ; then if ! @sbindir@/zpool list -v -H -P "$1" > "$poolconfigtemp" 2>&1 ; then
poolconfigoutput=$(cat "$poolconfigtemp") poolconfigoutput="$(cat "$poolconfigtemp")"
dinfo "zfsexpandknowledge: pool $1 cannot be listed: $poolconfigoutput" dinfo "zfsexpandknowledge: pool $1 cannot be listed: $poolconfigoutput"
else else
cat "$poolconfigtemp" | awk -F '\t' '/\t\/dev/ { print $2 }' | \ awk -F '\t' '/\t\/dev/ { print $2 }' "$poolconfigtemp" | \
while read pooldev ; do while read -r pooldev ; do
if [ -n "$pooldev" -a -e "$pooldev" ] ; then if [ -e "$pooldev" ] ; then
if [ -h "$pooldev" ] ; then resolved="$(readlink -f "$pooldev")"
resolved=`readlink -f "$pooldev"`
else
resolved="$pooldev"
fi
dinfo "zfsexpandknowledge: pool $1 has device $pooldev (which resolves to $resolved)" dinfo "zfsexpandknowledge: pool $1 has device $pooldev (which resolves to $resolved)"
echo "$resolved" echo "$resolved"
fi fi
@ -39,22 +34,20 @@ get_pool_devices() {
find_zfs_block_devices() { find_zfs_block_devices() {
local dev local dev
local blockdev
local mp local mp
local fstype local fstype
local pool local pool
local key local _
local n numfields="$(awk '{print NF; exit}' /proc/self/mountinfo)"
local poolconfigoutput if [ "$numfields" = "10" ] ; then
numfields=`head -1 /proc/self/mountinfo | awk '{print NF}'` fields="_ _ _ _ mp _ _ fstype dev _"
if [ "$numfields" == "10" ] ; then
fields="n n n n mp n n fstype dev n"
else else
fields="n n n n mp n n n fstype dev n" fields="_ _ _ _ mp _ _ _ fstype dev _"
fi fi
while read $fields ; do # shellcheck disable=SC2086
if [ "$fstype" != "zfs" ]; then continue ; fi while read -r ${fields?} ; do
if [ "$mp" == "$1" ]; then [ "$fstype" = "zfs" ] || continue
if [ "$mp" = "$1" ]; then
pool=$(echo "$dev" | cut -d / -f 1) pool=$(echo "$dev" | cut -d / -f 1)
get_pool_devices "$pool" get_pool_devices "$pool"
fi fi
@ -76,10 +69,9 @@ check() {
local _depdev local _depdev
local _depdevname local _depdevname
local _depdevtype local _depdevtype
local _depmajmin
local _dev
if [[ $hostonly ]]; then # shellcheck disable=SC2154
if [ -n "$hostonly" ]; then
for mp in \ for mp in \
"/" \ "/" \
@ -106,13 +98,12 @@ if [[ $hostonly ]]; then
fstype=$(get_devtype "$dev") fstype=$(get_devtype "$dev")
host_fs_types["$dev"]="$fstype" host_fs_types["$dev"]="$fstype"
majmin=$(get_maj_min "$dev") majmin=$(get_maj_min "$dev")
if [[ -d /sys/dev/block/$majmin/slaves ]] ; then if [ -d "/sys/dev/block/$majmin/slaves" ] ; then
for _depdev in /sys/dev/block/$majmin/slaves/*; do for _depdev in "/sys/dev/block/$majmin/slaves"/*; do
[[ -f $_depdev/dev ]] || continue [[ -f $_depdev/dev ]] || continue
_depdev=/dev/$(basename "$_depdev") _depdev=/dev/$(basename "$_depdev")
_depdevname=$(udevadm info --query=property --name="$_depdev" | grep "^DEVNAME=" | sed 's|^DEVNAME=||') _depdevname=$(udevadm info --query=property --name="$_depdev" | grep "^DEVNAME=" | sed 's|^DEVNAME=||')
_depdevtype=$(get_devtype "$_depdevname") _depdevtype=$(get_devtype "$_depdevname")
_depmajmin=$(get_maj_min "$_depdevname")
dinfo "zfsexpandknowledge: underlying block device backing ZFS dataset $mp: ${_depdevname//$'\n'/ }" dinfo "zfsexpandknowledge: underlying block device backing ZFS dataset $mp: ${_depdevname//$'\n'/ }"
array_contains "$_depdevname" "${host_devs[@]}" || host_devs+=("$_depdevname") array_contains "$_depdevname" "${host_devs[@]}" || host_devs+=("$_depdevname")
host_fs_types["$_depdevname"]="$_depdevtype" host_fs_types["$_depdevname"]="$_depdevtype"

View File

@ -1,4 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2154
check() { check() {
# We depend on udev-rules being loaded # We depend on udev-rules being loaded

View File

@ -1,4 +1,5 @@
#!/bin/sh #!/bin/sh
# shellcheck disable=SC2034,SC2154
. /lib/dracut-zfs-lib.sh . /lib/dracut-zfs-lib.sh
@ -39,6 +40,7 @@ udevadm settle
if [ "${root}" = "zfs:AUTO" ] ; then if [ "${root}" = "zfs:AUTO" ] ; then
if ! ZFS_DATASET="$(find_bootfs)" ; then if ! ZFS_DATASET="$(find_bootfs)" ; then
# shellcheck disable=SC2086
zpool import -N -a ${ZPOOL_IMPORT_OPTS} zpool import -N -a ${ZPOOL_IMPORT_OPTS}
if ! ZFS_DATASET="$(find_bootfs)" ; then if ! ZFS_DATASET="$(find_bootfs)" ; then
warn "ZFS: No bootfs attribute found in importable pools." warn "ZFS: No bootfs attribute found in importable pools."

View File

@ -1,4 +1,5 @@
#!/bin/sh #!/bin/sh
# shellcheck disable=SC2034,SC2154
. /lib/dracut-lib.sh . /lib/dracut-lib.sh
@ -28,7 +29,7 @@ case "${root}" in
info "ZFS: Enabling autodetection of bootfs after udev settles." info "ZFS: Enabling autodetection of bootfs after udev settles."
;; ;;
ZFS\=*|zfs:*|zfs:FILESYSTEM\=*|FILESYSTEM\=*) ZFS=*|zfs:*|FILESYSTEM=*)
# root is explicit ZFS root. Parse it now. We can handle # root is explicit ZFS root. Parse it now. We can handle
# a root=... param in any of the following formats: # a root=... param in any of the following formats:
# root=ZFS=rpool/ROOT # root=ZFS=rpool/ROOT

View File

@ -1,4 +1,5 @@
#!/bin/sh #!/bin/sh
# shellcheck disable=SC2016,SC1004
grep -wq debug /proc/cmdline && debug=1 grep -wq debug /proc/cmdline && debug=1
[ -n "$debug" ] && echo "zfs-generator: starting" >> /dev/kmsg [ -n "$debug" ] && echo "zfs-generator: starting" >> /dev/kmsg

View File

@ -59,6 +59,7 @@ import_pool() {
if ! zpool list -H "${pool}" > /dev/null 2>&1; then if ! zpool list -H "${pool}" > /dev/null 2>&1; then
info "ZFS: Importing pool ${pool}..." info "ZFS: Importing pool ${pool}..."
# shellcheck disable=SC2086
if ! zpool import -N ${ZPOOL_IMPORT_OPTS} "${pool}" ; then if ! zpool import -N ${ZPOOL_IMPORT_OPTS} "${pool}" ; then
warn "ZFS: Unable to import pool ${pool}" warn "ZFS: Unable to import pool ${pool}"
return 1 return 1
@ -123,13 +124,12 @@ for_relevant_root_children() {
# export_all OPTS # export_all OPTS
# exports all imported zfs pools. # exports all imported zfs pools.
export_all() { export_all() {
opts="${@}"
ret=0 ret=0
IFS="${NEWLINE}" IFS="${NEWLINE}"
for pool in $(zpool list -H -o name) ; do for pool in $(zpool list -H -o name) ; do
if zpool list -H "${pool}" > /dev/null 2>&1; then if zpool list -H "${pool}" > /dev/null 2>&1; then
zpool export "${pool}" ${opts} || ret=$? zpool export "${pool}" "$@" || ret=$?
fi fi
done done
IFS="${OLDIFS}" IFS="${OLDIFS}"

View File

@ -1,4 +1,5 @@
#!/bin/sh #!/bin/sh
# shellcheck disable=SC2154
# only run this on systemd systems, we handle the decrypt in mount-zfs.sh in the mount hook otherwise # only run this on systemd systems, we handle the decrypt in mount-zfs.sh in the mount hook otherwise
[ -e /bin/systemctl ] || [ -e /usr/bin/systemctl ] || return 0 [ -e /bin/systemctl ] || [ -e /usr/bin/systemctl ] || return 0

View File

@ -26,7 +26,7 @@ fi
# We use pthreads, but i-t from buster doesn't automatically # We use pthreads, but i-t from buster doesn't automatically
# copy this indirect dependency: this can be removed when buster finally dies. # copy this indirect dependency: this can be removed when buster finally dies.
for libgcc in $(find /lib/ -type f -name libgcc_s.so.[1-9]); do find /lib/ -type f -name "libgcc_s.so.[1-9]" | while read -r libgcc; do
copy_exec "$libgcc" copy_exec "$libgcc"
done done

View File

@ -1,18 +1,11 @@
#!/bin/sh #!/bin/sh
PREREQ="mdadm mdrun multipath" # shellcheck disable=SC2154
prereqs()
{
echo "$PREREQ"
}
case $1 in if [ "$1" = "prereqs" ]; then
# get pre-requisites echo mdadm mdrun multipath
prereqs)
prereqs
exit 0 exit 0
;; fi
esac
# #
@ -20,10 +13,10 @@ esac
# #
message() message()
{ {
if [ -x /bin/plymouth ] && plymouth --ping; then if plymouth --ping 2>/dev/null; then
plymouth message --text="$@" plymouth message --text="$*"
else else
echo "$@" >&2 echo "$*" >&2
fi fi
return 0 return 0
} }

View File

@ -355,7 +355,6 @@ while getopts 'hvqxkfScn:d:s:r:?t:T:u:I:' OPTION; do
exit 1 exit 1
;; ;;
v) v)
# shellcheck disable=SC2034
VERBOSE="yes" VERBOSE="yes"
;; ;;
q) q)

View File

@ -164,15 +164,13 @@ populate() {
local MAX_DIR_SIZE=$2 local MAX_DIR_SIZE=$2
local MAX_FILE_SIZE=$3 local MAX_FILE_SIZE=$3
# shellcheck disable=SC2086 mkdir -p "$ROOT"/{a,b,c,d,e,f,g}/{h,i}
mkdir -p $ROOT/{a,b,c,d,e,f,g}/{h,i}
DIRS=$(find "$ROOT") DIRS=$(find "$ROOT")
for DIR in $DIRS; do for DIR in $DIRS; do
COUNT=$((RANDOM % MAX_DIR_SIZE)) COUNT=$((RANDOM % MAX_DIR_SIZE))
# shellcheck disable=SC2034 for _ in $(seq $COUNT); do
for i in $(seq $COUNT); do
FILE=$(mktemp -p "$DIR") FILE=$(mktemp -p "$DIR")
SIZE=$((RANDOM % MAX_FILE_SIZE)) SIZE=$((RANDOM % MAX_FILE_SIZE))
dd if=/dev/urandom of="$FILE" bs=1k \ dd if=/dev/urandom of="$FILE" bs=1k \
@ -334,9 +332,8 @@ fi
for TAG in $POOL_TAGS; do for TAG in $POOL_TAGS; do
if [ "$TAG" = "all" ]; then if [ "$TAG" = "all" ]; then
# shellcheck disable=SC2010 ALL_TAGS=$(echo "$IMAGES_DIR"/*.tar.bz2 | \
ALL_TAGS=$(ls "$IMAGES_DIR" | grep "tar.bz2" | \ sed "s|$IMAGES_DIR/||g;s|.tar.bz2||g")
sed 's/.tar.bz2//' | tr '\n' ' ')
NEW_TAGS="$NEW_TAGS $ALL_TAGS" NEW_TAGS="$NEW_TAGS $ALL_TAGS"
else else
NEW_TAGS="$NEW_TAGS $TAG" NEW_TAGS="$NEW_TAGS $TAG"

View File

@ -91,8 +91,8 @@ esac
function core_file function core_file
{ {
# shellcheck disable=SC2012 disable=2086 # shellcheck disable=SC2012,SC2086
printf "%s" "$(ls -tr1 $coreglob 2> /dev/null | head -1)" ls -tr1 $coreglob 2>/dev/null | head -1
} }
function core_prog function core_prog
@ -100,8 +100,7 @@ function core_prog
prog=$ZTEST prog=$ZTEST
core_id=$($GDB --batch -c "$1" | grep "Core was generated by" | \ core_id=$($GDB --batch -c "$1" | grep "Core was generated by" | \
tr \' ' ') tr \' ' ')
# shellcheck disable=SC2076 if [[ "$core_id" == *"zdb "* ]]; then
if [[ "$core_id" =~ "zdb " ]]; then
prog=$ZDB prog=$ZDB
fi fi
printf "%s" "$prog" printf "%s" "$prog"
@ -303,8 +302,7 @@ while [[ $timeout -eq 0 ]] || [[ $curtime -le $((starttime + timeout)) ]]; do
zopt="$zopt -s $size" zopt="$zopt -s $size"
zopt="$zopt -f $workdir" zopt="$zopt -f $workdir"
# shellcheck disable=SC2124 cmd="$ZTEST $zopt $*"
cmd="$ZTEST $zopt $@"
desc="$(date '+%m/%d %T') $cmd" desc="$(date '+%m/%d %T') $cmd"
echo "$desc" | tee -a ztest.history echo "$desc" | tee -a ztest.history
echo "$desc" >>ztest.out echo "$desc" >>ztest.out

View File

@ -102,8 +102,7 @@ function do_dup_test
# Read the file a few times to generate some # Read the file a few times to generate some
# duplicate errors of the same blocks # duplicate errors of the same blocks
# shellcheck disable=SC2034 for _ in {1..15}; do
for i in {1..15}; do
dd if=$FILEPATH of=/dev/null bs=128K > /dev/null 2>&1 dd if=$FILEPATH of=/dev/null bs=128K > /dev/null 2>&1
done done
log_must zinject -c all log_must zinject -c all

View File

@ -1,4 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC1004
# #
# This file and its contents are supplied under the terms of the # This file and its contents are supplied under the terms of the
@ -24,38 +25,37 @@ zfs_kstats="/proc/spl/kstat/zfs"
function get_prefetch_ios function get_prefetch_ios
{ {
typeset -l data_misses=`awk '$1 == "prefetch_data_misses" \ typeset -l data_misses="$(awk '$1 == "prefetch_data_misses" \
{ print $3 }' $zfs_kstats/arcstats` { print $3; exit }' "$zfs_kstats/arcstats")"
typeset -l metadata_misses=`awk '$1 == "prefetch_metadata_misses" \ typeset -l metadata_misses="$(awk '$1 == "prefetch_metadata_misses" \
{ print $3 }' $zfs_kstats/arcstats` { print $3; exit }' "$zfs_kstats/arcstats")"
typeset -l total_misses=$(( $data_misses + $metadata_misses )) typeset -l total_misses=$(( data_misses + metadata_misses ))
echo $total_misses echo "$total_misses"
} }
function get_prefetched_demand_reads function get_prefetched_demand_reads
{ {
typeset -l demand_reads=`awk '$1 == "demand_hit_predictive_prefetch" \ typeset -l demand_reads="$(awk '$1 == "demand_hit_predictive_prefetch" \
{ print $3 }' $zfs_kstats/arcstats` { print $3; exit }' "$zfs_kstats/arcstats")"
echo $demand_reads echo "$demand_reads"
} }
function get_async_upgrade_sync function get_async_upgrade_sync
{ {
typeset -l sync_wait=`awk '$1 == "async_upgrade_sync" \ typeset -l sync_wait="$(awk '$1 == "async_upgrade_sync" \
{ print $3 }' $zfs_kstats/arcstats` { print $3; exit }' "$zfs_kstats/arcstats")"
echo $sync_wait echo "$sync_wait"
} }
if [ $# -ne 2 ] if [ $# -ne 2 ]
then then
echo "Usage: `basename $0` <poolname> interval" >&2 echo "Usage: ${0##*/} poolname interval" >&2
exit 1 exit 1
fi fi
poolname=$1
interval=$2 interval=$2
prefetch_ios=$(get_prefetch_ios) prefetch_ios=$(get_prefetch_ios)
prefetched_demand_reads=$(get_prefetched_demand_reads) prefetched_demand_reads=$(get_prefetched_demand_reads)
@ -64,19 +64,19 @@ async_upgrade_sync=$(get_async_upgrade_sync)
while true while true
do do
new_prefetch_ios=$(get_prefetch_ios) new_prefetch_ios=$(get_prefetch_ios)
printf "%u\n%-24s\t%u\n" $(date +%s) "prefetch_ios" \ printf "%u\n%-24s\t%u\n" "$(date +%s)" "prefetch_ios" \
$(( $new_prefetch_ios - $prefetch_ios )) $(( new_prefetch_ios - prefetch_ios ))
prefetch_ios=$new_prefetch_ios prefetch_ios=$new_prefetch_ios
new_prefetched_demand_reads=$(get_prefetched_demand_reads) new_prefetched_demand_reads=$(get_prefetched_demand_reads)
printf "%-24s\t%u\n" "prefetched_demand_reads" \ printf "%-24s\t%u\n" "prefetched_demand_reads" \
$(( $new_prefetched_demand_reads - $prefetched_demand_reads )) $(( new_prefetched_demand_reads - prefetched_demand_reads ))
prefetched_demand_reads=$new_prefetched_demand_reads prefetched_demand_reads=$new_prefetched_demand_reads
new_async_upgrade_sync=$(get_async_upgrade_sync) new_async_upgrade_sync=$(get_async_upgrade_sync)
printf "%-24s\t%u\n" "async_upgrade_sync" \ printf "%-24s\t%u\n" "async_upgrade_sync" \
$(( $new_async_upgrade_sync - $async_upgrade_sync )) $(( new_async_upgrade_sync - async_upgrade_sync ))
async_upgrade_sync=$new_async_upgrade_sync async_upgrade_sync=$new_async_upgrade_sync
sleep $interval sleep "$interval"
done done