Skip to content

Commit

Permalink
Trim excess shellcheck annotations. Widen to all non-Korn scripts
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes openzfs#12042
  • Loading branch information
nabijaczleweli authored and behlendorf committed May 20, 2021
1 parent 2ca7798 commit 6fc3099
Show file tree
Hide file tree
Showing 18 changed files with 75 additions and 89 deletions.
6 changes: 3 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ filter_executable = -exec test -x '{}' \; -print
PHONY += shellcheck
shellcheck:
@if type shellcheck > /dev/null 2>&1; then \
shellcheck --exclude=SC1090 --exclude=SC1117 --format=gcc \
$$(find ${top_srcdir}/scripts/*.sh -type f) \
$$(find ${top_srcdir}/cmd/zed/zed.d/*.sh -type f) \
shellcheck --exclude=SC1090,SC1117,SC1091 --format=gcc \
$$(find ${top_srcdir} -name "config*" -prune -name tests -prune \
-o -name "*.sh" -o -name "*.sh.in" -type f) \
$$(find ${top_srcdir}/cmd/zpool/zpool.d/* \
-type f ${filter_executable}); \
else \
Expand Down
6 changes: 3 additions & 3 deletions cmd/fsck_zfs/fsck.zfs.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ for dataset in "$@"; do

case "$(@sbindir@/zpool list -Ho health "$pool")" in
DEGRADED)
ret=$(( $ret | 4 ))
ret=$(( ret | 4 ))
;;
FAULTED)
awk '!/^([[:space:]]*#.*)?$/ && $1 == "'"$dataset"'" && $3 == "zfs" {exit 1}' /etc/fstab || \
ret=$(( $ret | 8 ))
ret=$(( ret | 8 ))
;;
"")
# Pool not found, error printed by zpool(8)
ret=$(( $ret | 8 ))
ret=$(( ret | 8 ))
;;
*)
;;
Expand Down
2 changes: 1 addition & 1 deletion cmd/zed/zed.d/zed-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ zed_notify_email()
-e "s/@SUBJECT@/${subject}/g")"

# 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=$?
if [ "${rv}" -ne 0 ]; then
zed_log_err "$(basename "${ZED_EMAIL_PROG}") exit=${rv}"
Expand Down
1 change: 1 addition & 0 deletions cmd/zvol_wait/zvol_wait
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ filter_out_deleted_zvols() {
OIFS="$IFS"
IFS="
"
# shellcheck disable=SC2086
zfs list -H -o name $zvols 2>/dev/null
IFS="$OIFS"
}
Expand Down
47 changes: 19 additions & 28 deletions contrib/dracut/02zfsexpandknowledge/module-setup.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,16 @@ get_pool_devices() {
local poolconfigtemp
local poolconfigoutput
local pooldev
local prefix
local resolved
poolconfigtemp=`mktemp`
poolconfigtemp="$(mktemp)"
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"
else
cat "$poolconfigtemp" | awk -F '\t' '/\t\/dev/ { print $2 }' | \
while read pooldev ; do
if [ -n "$pooldev" -a -e "$pooldev" ] ; then
if [ -h "$pooldev" ] ; then
resolved=`readlink -f "$pooldev"`
else
resolved="$pooldev"
fi
awk -F '\t' '/\t\/dev/ { print $2 }' "$poolconfigtemp" | \
while read -r pooldev ; do
if [ -e "$pooldev" ] ; then
resolved="$(readlink -f "$pooldev")"
dinfo "zfsexpandknowledge: pool $1 has device $pooldev (which resolves to $resolved)"
echo "$resolved"
fi
Expand All @@ -39,22 +34,20 @@ get_pool_devices() {

find_zfs_block_devices() {
local dev
local blockdev
local mp
local fstype
local pool
local key
local n
local poolconfigoutput
numfields=`head -1 /proc/self/mountinfo | awk '{print NF}'`
if [ "$numfields" == "10" ] ; then
fields="n n n n mp n n fstype dev n"
local _
numfields="$(awk '{print NF; exit}' /proc/self/mountinfo)"
if [ "$numfields" = "10" ] ; then
fields="_ _ _ _ mp _ _ fstype dev _"
else
fields="n n n n mp n n n fstype dev n"
fields="_ _ _ _ mp _ _ _ fstype dev _"
fi
while read $fields ; do
if [ "$fstype" != "zfs" ]; then continue ; fi
if [ "$mp" == "$1" ]; then
# shellcheck disable=SC2086
while read -r ${fields?} ; do
[ "$fstype" = "zfs" ] || continue
if [ "$mp" = "$1" ]; then
pool=$(echo "$dev" | cut -d / -f 1)
get_pool_devices "$pool"
fi
Expand All @@ -76,10 +69,9 @@ check() {
local _depdev
local _depdevname
local _depdevtype
local _depmajmin
local _dev

if [[ $hostonly ]]; then
# shellcheck disable=SC2154
if [ -n "$hostonly" ]; then

for mp in \
"/" \
Expand All @@ -106,13 +98,12 @@ if [[ $hostonly ]]; then
fstype=$(get_devtype "$dev")
host_fs_types["$dev"]="$fstype"
majmin=$(get_maj_min "$dev")
if [[ -d /sys/dev/block/$majmin/slaves ]] ; then
for _depdev in /sys/dev/block/$majmin/slaves/*; do
if [ -d "/sys/dev/block/$majmin/slaves" ] ; then
for _depdev in "/sys/dev/block/$majmin/slaves"/*; do
[[ -f $_depdev/dev ]] || continue
_depdev=/dev/$(basename "$_depdev")
_depdevname=$(udevadm info --query=property --name="$_depdev" | grep "^DEVNAME=" | sed 's|^DEVNAME=||')
_depdevtype=$(get_devtype "$_depdevname")
_depmajmin=$(get_maj_min "$_depdevname")
dinfo "zfsexpandknowledge: underlying block device backing ZFS dataset $mp: ${_depdevname//$'\n'/ }"
array_contains "$_depdevname" "${host_devs[@]}" || host_devs+=("$_depdevname")
host_fs_types["$_depdevname"]="$_depdevtype"
Expand Down
2 changes: 2 additions & 0 deletions contrib/dracut/90zfs/module-setup.sh.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
# shellcheck disable=SC2154

check() {
# We depend on udev-rules being loaded
Expand Down Expand Up @@ -56,6 +57,7 @@ install() {
# Fallback: Guess the path and include all matches
dracut_install /usr/lib/gcc/*/*/libgcc_s.so*
fi
# shellcheck disable=SC2050
if [ @LIBFETCH_DYNAMIC@ != 0 ]; then
for d in $libdirs; do
[ -e "$d"/@LIBFETCH_SONAME@ ] && dracut_install "$d"/@LIBFETCH_SONAME@
Expand Down
2 changes: 2 additions & 0 deletions contrib/dracut/90zfs/mount-zfs.sh.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
# shellcheck disable=SC2034,SC2154

. /lib/dracut-zfs-lib.sh

Expand Down Expand Up @@ -39,6 +40,7 @@ udevadm settle

if [ "${root}" = "zfs:AUTO" ] ; then
if ! ZFS_DATASET="$(find_bootfs)" ; then
# shellcheck disable=SC2086
zpool import -N -a ${ZPOOL_IMPORT_OPTS}
if ! ZFS_DATASET="$(find_bootfs)" ; then
warn "ZFS: No bootfs attribute found in importable pools."
Expand Down
3 changes: 2 additions & 1 deletion contrib/dracut/90zfs/parse-zfs.sh.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
# shellcheck disable=SC2034,SC2154

. /lib/dracut-lib.sh

Expand Down Expand Up @@ -28,7 +29,7 @@ case "${root}" in
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
# a root=... param in any of the following formats:
# root=ZFS=rpool/ROOT
Expand Down
1 change: 1 addition & 0 deletions contrib/dracut/90zfs/zfs-generator.sh.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
# shellcheck disable=SC2016,SC1004

grep -wq debug /proc/cmdline && debug=1
[ -n "$debug" ] && echo "zfs-generator: starting" >> /dev/kmsg
Expand Down
4 changes: 2 additions & 2 deletions contrib/dracut/90zfs/zfs-lib.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import_pool() {

if ! zpool list -H "${pool}" > /dev/null 2>&1; then
info "ZFS: Importing pool ${pool}..."
# shellcheck disable=SC2086
if ! zpool import -N ${ZPOOL_IMPORT_OPTS} "${pool}" ; then
warn "ZFS: Unable to import pool ${pool}"
return 1
Expand Down Expand Up @@ -123,13 +124,12 @@ for_relevant_root_children() {
# export_all OPTS
# exports all imported zfs pools.
export_all() {
opts="${@}"
ret=0

IFS="${NEWLINE}"
for pool in $(zpool list -H -o name) ; do
if zpool list -H "${pool}" > /dev/null 2>&1; then
zpool export "${pool}" ${opts} || ret=$?
zpool export "${pool}" "$@" || ret=$?
fi
done
IFS="${OLDIFS}"
Expand Down
1 change: 1 addition & 0 deletions contrib/dracut/90zfs/zfs-load-key.sh.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
# shellcheck disable=SC2154

# 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
Expand Down
5 changes: 3 additions & 2 deletions contrib/initramfs/hooks/zfs.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ fi

# We use pthreads, but i-t from buster doesn't automatically
# 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"
done

# shellcheck disable=SC2050
if [ @LIBFETCH_DYNAMIC@ != 0 ]; then
for libfetch in $(find /lib/ -name @LIBFETCH_SONAME@); do
find /lib/ -name @LIBFETCH_SONAME@ | while read -r libfetch; do
copy_exec "$libfetch"
done
fi
Expand Down
21 changes: 7 additions & 14 deletions contrib/initramfs/scripts/local-top/zfs
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
#!/bin/sh
PREREQ="mdadm mdrun multipath"
# shellcheck disable=SC2154

prereqs()
{
echo "$PREREQ"
}

case $1 in
# get pre-requisites
prereqs)
prereqs
if [ "$1" = "prereqs" ]; then
echo mdadm mdrun multipath
exit 0
;;
esac
fi


#
# Helper functions
#
message()
{
if [ -x /bin/plymouth ] && plymouth --ping; then
plymouth message --text="$@"
if plymouth --ping 2>/dev/null; then
plymouth message --text="$*"
else
echo "$@" >&2
echo "$*" >&2
fi
return 0
}
Expand Down
1 change: 0 additions & 1 deletion scripts/zfs-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ while getopts 'hvqxkfScn:d:s:r:?t:T:u:I:' OPTION; do
exit 1
;;
v)
# shellcheck disable=SC2034
VERBOSE="yes"
;;
q)
Expand Down
11 changes: 4 additions & 7 deletions scripts/zimport.sh
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,13 @@ populate() {
local MAX_DIR_SIZE=$2
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")

for DIR in $DIRS; do
COUNT=$((RANDOM % MAX_DIR_SIZE))

# shellcheck disable=SC2034
for i in $(seq $COUNT); do
for _ in $(seq $COUNT); do
FILE=$(mktemp -p "$DIR")
SIZE=$((RANDOM % MAX_FILE_SIZE))
dd if=/dev/urandom of="$FILE" bs=1k \
Expand Down Expand Up @@ -334,9 +332,8 @@ fi
for TAG in $POOL_TAGS; do

if [ "$TAG" = "all" ]; then
# shellcheck disable=SC2010
ALL_TAGS=$(ls "$IMAGES_DIR" | grep "tar.bz2" | \
sed 's/.tar.bz2//' | tr '\n' ' ')
ALL_TAGS=$(echo "$IMAGES_DIR"/*.tar.bz2 | \
sed "s|$IMAGES_DIR/||g;s|.tar.bz2||g")
NEW_TAGS="$NEW_TAGS $ALL_TAGS"
else
NEW_TAGS="$NEW_TAGS $TAG"
Expand Down
10 changes: 4 additions & 6 deletions scripts/zloop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,16 @@ esac

function core_file
{
# shellcheck disable=SC2012 disable=2086
printf "%s" "$(ls -tr1 $coreglob 2> /dev/null | head -1)"
# shellcheck disable=SC2012,SC2086
ls -tr1 $coreglob 2>/dev/null | head -1
}

function core_prog
{
prog=$ZTEST
core_id=$($GDB --batch -c "$1" | grep "Core was generated by" | \
tr \' ' ')
# shellcheck disable=SC2076
if [[ "$core_id" =~ "zdb " ]]; then
if [[ "$core_id" == *"zdb "* ]]; then
prog=$ZDB
fi
printf "%s" "$prog"
Expand Down Expand Up @@ -303,8 +302,7 @@ while [[ $timeout -eq 0 ]] || [[ $curtime -le $((starttime + timeout)) ]]; do
zopt="$zopt -s $size"
zopt="$zopt -f $workdir"

# shellcheck disable=SC2124
cmd="$ZTEST $zopt $@"
cmd="$ZTEST $zopt $*"
desc="$(date '+%m/%d %T') $cmd"
echo "$desc" | tee -a ztest.history
echo "$desc" >>ztest.out
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ function do_dup_test

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

0 comments on commit 6fc3099

Please sign in to comment.