1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-02 01:18:26 +03:00

tests: cleanup some shellcheck warns

Reduce shellcheck warnings about missing {} for possible array
dereference.

Make sure we are not loosing error code when assigning local vars
and explicitely ignore 'errors' from standalone lines when needed.

Add some missing quotes.

Use $() instead of ancient ``

Avoid writing some temporary data into /tmp - test need to store
files within its own 'testdir' - so it can be properly discarded.
This commit is contained in:
Zdenek Kabelac 2023-02-09 16:04:54 +01:00
parent cc2293f18e
commit 773bc01377
4 changed files with 34 additions and 28 deletions

View File

@ -255,11 +255,11 @@ convert2lvm_() {
# Find largest matching VG name to our 'default' vgname # Find largest matching VG name to our 'default' vgname
LASTVGNAME=$(LC_ALL=C "$LVM" vgs -oname -O-name --noheadings -S name=~${VGNAME} | grep -E "${VGNAME}[0-9]? ?" | head -1 || true) LASTVGNAME=$(LC_ALL=C "$LVM" vgs -oname -O-name --noheadings -S name=~${VGNAME} | grep -E "${VGNAME}[0-9]? ?" | head -1 || true)
if test -n "$LASTVGNAME" ; then if test -n "$LASTVGNAME" ; then
LASTVGNAME=${LASTVGNAME#*${VGNAME}} LASTVGNAME=${LASTVGNAME#*"${VGNAME}"}
# If the number is becoming too high, try some random number # If the number is becoming too high, try some random number
test "$LASTVGNAME" -gt 99999999 2>/dev/null && LASTVGNAME=$RANDOM test "$LASTVGNAME" -gt 99999999 2>/dev/null && LASTVGNAME=$RANDOM
# Generate new unused VG name # Generate new unused VG name
VGNAME="${VGNAME}$(( ${LASTVGNAME} + 1 ))" VGNAME="${VGNAME}$(( LASTVGNAME + 1 ))"
verbose "Selected unused volume group name $VGNAME." verbose "Selected unused volume group name $VGNAME."
fi fi
fi fi

View File

@ -387,7 +387,8 @@ teardown_devs_prefixed() {
wait wait
local mounts=( $(grep "$prefix" /proc/mounts | cut -d' ' -f1) ) local mounts
mounts=( $(grep "$prefix" /proc/mounts | cut -d' ' -f1) ) || true
if test ${#mounts[@]} -gt 0; then if test ${#mounts[@]} -gt 0; then
test "$stray" -eq 0 || echo "## removing stray mounted devices containing $prefix:" "${mounts[@]}" test "$stray" -eq 0 || echo "## removing stray mounted devices containing $prefix:" "${mounts[@]}"
if umount -fl "${mounts[@]}"; then if umount -fl "${mounts[@]}"; then
@ -464,7 +465,8 @@ teardown_devs() {
# Attempt to remove any loop devices that failed to get torn down if earlier tests aborted # Attempt to remove any loop devices that failed to get torn down if earlier tests aborted
test "${LVM_TEST_PARALLEL:-0}" -eq 1 || test -z "$COMMON_PREFIX" || { test "${LVM_TEST_PARALLEL:-0}" -eq 1 || test -z "$COMMON_PREFIX" || {
local stray_loops=( $(losetup -a | grep "$COMMON_PREFIX" | cut -d: -f1) ) local stray_loops
stray_loops=( $(losetup -a | grep "$COMMON_PREFIX" | cut -d: -f1) ) || true
test ${#stray_loops[@]} -eq 0 || { test ${#stray_loops[@]} -eq 0 || {
teardown_devs_prefixed "$COMMON_PREFIX" 1 teardown_devs_prefixed "$COMMON_PREFIX" 1
echo "## removing stray loop devices containing $COMMON_PREFIX:" "${stray_loops[@]}" echo "## removing stray loop devices containing $COMMON_PREFIX:" "${stray_loops[@]}"
@ -626,7 +628,7 @@ prepare_loop() {
echo -n "## preparing loop device..." echo -n "## preparing loop device..."
# skip if prepare_scsi_debug_dev() was used # skip if prepare_scsi_debug_dev() was used
if test -f SCSI_DEBUG_DEV -a -f LOOP ; then if test -f SCSI_DEBUG_DEV && test -f LOOP ; then
echo "(skipped)" echo "(skipped)"
return 0 return 0
fi fi
@ -689,7 +691,7 @@ prepare_real_devs() {
if test -n "$LVM_TEST_DEVICE_LIST"; then if test -n "$LVM_TEST_DEVICE_LIST"; then
local count=0 local count=0
while read path; do while read path; do
REAL_DEVICES[$count]=$path REAL_DEVICES[count]=$path
count=$(( count + 1 )) count=$(( count + 1 ))
aux extend_filter "a|$path|" aux extend_filter "a|$path|"
dd if=/dev/zero of="$path" bs=32k count=1 dd if=/dev/zero of="$path" bs=32k count=1
@ -901,13 +903,13 @@ cleanup_idm_context() {
local dev=$1 local dev=$1
if [ -n "$LVM_TEST_LOCK_TYPE_IDM" ]; then if [ -n "$LVM_TEST_LOCK_TYPE_IDM" ]; then
sg_dev=`sg_map26 ${dev}` sg_dev=$(sg_map26 "${dev}")
echo "Cleanup IDM context for drive ${dev} ($sg_dev)" echo "Cleanup IDM context for drive ${dev} ($sg_dev)"
sg_raw -v -r 512 -o /tmp/idm_tmp_data.bin $sg_dev \ sg_raw -v -r 512 -o idm_tmp_data.bin "$sg_dev" \
88 00 01 00 00 00 00 20 FF 01 00 00 00 01 00 00 88 00 01 00 00 00 00 20 FF 01 00 00 00 01 00 00
sg_raw -v -s 512 -i /tmp/idm_tmp_data.bin $sg_dev \ sg_raw -v -s 512 -i idm_tmp_data.bin "$sg_dev" \
8E 00 FF 00 00 00 00 00 00 00 00 00 00 01 00 00 8E 00 FF 00 00 00 00 00 00 00 00 00 00 01 00 00
rm /tmp/idm_tmp_data.bin rm idm_tmp_data.bin
fi fi
} }
@ -976,12 +978,12 @@ prepare_devs() {
for i in $(seq 1 "$n"); do for i in $(seq 1 "$n"); do
local name="${PREFIX}$pvname$i" local name="${PREFIX}$pvname$i"
local dev="$DM_DEV_DIR/mapper/$name" local dev="$DM_DEV_DIR/mapper/$name"
DEVICES[$count]=$dev DEVICES[count]=$dev
count=$(( count + 1 )) count=$(( count + 1 ))
# If the backing device number can meet the requirement for PV devices, # If the backing device number can meet the requirement for PV devices,
# then allocate a dedicated backing device for PV; otherwise, rollback # then allocate a dedicated backing device for PV; otherwise, rollback
# to use single backing device for device-mapper. # to use single backing device for device-mapper.
if [ -n "$LVM_TEST_BACKING_DEVICE" ] && [ $n -le ${#BACKING_DEVICE_ARRAY[@]} ]; then if [ -n "$LVM_TEST_BACKING_DEVICE" ] && [ "$n" -le ${#BACKING_DEVICE_ARRAY[@]} ]; then
echo 0 $size linear "${BACKING_DEVICE_ARRAY[$(( count - 1 ))]}" $(( header_shift * 2048 )) > "$name.table" echo 0 $size linear "${BACKING_DEVICE_ARRAY[$(( count - 1 ))]}" $(( header_shift * 2048 )) > "$name.table"
else else
echo 0 $size linear "$BACKING_DEV" $(( ( i - 1 ) * size + ( header_shift * 2048 ) )) > "$name.table" echo 0 $size linear "$BACKING_DEV" $(( ( i - 1 ) * size + ( header_shift * 2048 ) )) > "$name.table"
@ -1005,7 +1007,7 @@ prepare_devs() {
if [ -n "$LVM_TEST_BACKING_DEVICE" ]; then if [ -n "$LVM_TEST_BACKING_DEVICE" ]; then
for d in "${BACKING_DEVICE_ARRAY[@]}"; do for d in "${BACKING_DEVICE_ARRAY[@]}"; do
cnt=$((`blockdev --getsize64 $d` / 1024 / 1024)) cnt=$(( $(blockdev --getsize64 "$d") / 1024 / 1024 ))
cnt=$(( cnt < 1000 ? cnt : 1000 )) cnt=$(( cnt < 1000 ? cnt : 1000 ))
dd if=/dev/zero of="$d" bs=1MB count=$cnt dd if=/dev/zero of="$d" bs=1MB count=$cnt
wipefs -a "$d" 2>/dev/null || true wipefs -a "$d" 2>/dev/null || true
@ -1209,7 +1211,9 @@ throttle_dm_mirror() {
# if the kernel config file is present, validate whether the kernel uses HZ_1000 # if the kernel config file is present, validate whether the kernel uses HZ_1000
# and return failure for this 'throttling' when it does NOT as without this setting # and return failure for this 'throttling' when it does NOT as without this setting
# whole throttling is pointless on modern hardware # whole throttling is pointless on modern hardware
local kconfig="/boot/config-$(uname -r)" local kconfig
kconfig="/boot/config-$(uname -r)"
if test -e "$kconfig" ; then if test -e "$kconfig" ; then
grep -q "CONFIG_HZ_1000=y" "$kconfig" 2>/dev/null || { grep -q "CONFIG_HZ_1000=y" "$kconfig" 2>/dev/null || {
echo "WARNING: CONFIG_HZ_1000=y is NOT set in $kconfig -> throttling is unusable" echo "WARNING: CONFIG_HZ_1000=y is NOT set in $kconfig -> throttling is unusable"
@ -1218,7 +1222,7 @@ throttle_dm_mirror() {
fi fi
test -e "$throttle_sys" || return test -e "$throttle_sys" || return
test -f THROTTLE || cat "$throttle_sys" > THROTTLE test -f THROTTLE || cat "$throttle_sys" > THROTTLE
echo ${1-1} > "$throttle_sys" echo "${1-1}" > "$throttle_sys"
} }
# Restore original kcopyd throttle value and have mirroring fast again # Restore original kcopyd throttle value and have mirroring fast again
@ -1247,10 +1251,10 @@ restore_from_devtable() {
local name=${dev##*/} local name=${dev##*/}
dmsetup load "$name" "$name.devtable" dmsetup load "$name" "$name.devtable"
if not dmsetup resume "$name" ; then if not dmsetup resume "$name" ; then
dmsetup clear $name dmsetup clear "$name"
dmsetup resume $name dmsetup resume "$name"
finish_udev_transaction finish_udev_transaction
echo "Device $name has unusable table \"$(cat $name.devtable)\"" echo "Device $name has unusable table \"$(cat "$name.devtable")\""
return 1 return 1
fi fi
done done
@ -1357,7 +1361,7 @@ extend_devices() {
test -z "$LVM_TEST_DEVICES_FILE" && return test -z "$LVM_TEST_DEVICES_FILE" && return
for dev in "$@"; do for dev in "$@"; do
lvmdevices --adddev $dev lvmdevices --adddev "$dev"
done done
} }
@ -1395,7 +1399,7 @@ hide_dev() {
if test -n "$LVM_TEST_DEVICES_FILE"; then if test -n "$LVM_TEST_DEVICES_FILE"; then
for dev in "$@"; do for dev in "$@"; do
lvmdevices --deldev $dev lvmdevices --deldev "$dev"
done done
else else
filter=$(grep ^devices/global_filter CONFIG_VALUES | tail -n 1) filter=$(grep ^devices/global_filter CONFIG_VALUES | tail -n 1)
@ -1411,7 +1415,7 @@ unhide_dev() {
if test -n "$LVM_TEST_DEVICES_FILE"; then if test -n "$LVM_TEST_DEVICES_FILE"; then
for dev in "$@"; do for dev in "$@"; do
lvmdevices -y --adddev $dev lvmdevices -y --adddev "$dev"
done done
else else
filter=$(grep ^devices/global_filter CONFIG_VALUES | tail -n 1) filter=$(grep ^devices/global_filter CONFIG_VALUES | tail -n 1)
@ -1844,13 +1848,13 @@ have_cache() {
declare -a CONF=() declare -a CONF=()
# disable cache_check if not present in system # disable cache_check if not present in system
if test -n "$LVM_TEST_CACHE_CHECK_CMD" -a ! -x "$LVM_TEST_CACHE_CHECK_CMD" ; then if test -n "$LVM_TEST_CACHE_CHECK_CMD" && test ! -x "$LVM_TEST_CACHE_CHECK_CMD" ; then
CONF[0]="global/cache_check_executable = \"\"" CONF[0]="global/cache_check_executable = \"\""
fi fi
if test -n "$LVM_TEST_CACHE_DUMP_CMD" -a ! -x "$LVM_TEST_CACHE_DUMP_CMD" ; then if test -n "$LVM_TEST_CACHE_DUMP_CMD" && test ! -x "$LVM_TEST_CACHE_DUMP_CMD" ; then
CONF[1]="global/cache_dump_executable = \"\"" CONF[1]="global/cache_dump_executable = \"\""
fi fi
if test -n "$LVM_TEST_CACHE_REPAIR_CMD" -a ! -x "$LVM_TEST_CACHE_REPAIR_CMD" ; then if test -n "$LVM_TEST_CACHE_REPAIR_CMD" && test ! -x "$LVM_TEST_CACHE_REPAIR_CMD" ; then
CONF[2]="global/cache_repair_executable = \"\"" CONF[2]="global/cache_repair_executable = \"\""
fi fi
if test ${#CONF[@]} -ne 0 ; then if test ${#CONF[@]} -ne 0 ; then

View File

@ -23,8 +23,8 @@ test -z "$BASH" || set -e -o pipefail
# trims only leading prefix and suffix # trims only leading prefix and suffix
trim_() { trim_() {
rm -f debug.log # drop log, command was ok rm -f debug.log # drop log, command was ok
local var=${1%${1##*[! ]}} # remove trailing space characters local var=${1%"${1##*[! ]}"} # remove trailing space characters
echo "${var#${var%%[! ]*}}" # remove leading space characters echo "${var#"${var%%[! ]*}"}" # remove leading space characters
} }
pv_field() { pv_field() {
@ -68,7 +68,7 @@ lv_devices() {
} }
lv_field_lv_() { lv_field_lv_() {
lv_field "$1" "$2" -a --unbuffered | tr -d [] lv_field "$1" "$2" -a --unbuffered | tr -d '[]'
} }
lv_tree_devices_() { lv_tree_devices_() {

View File

@ -87,8 +87,10 @@ local vdo_maxDiscardSize=${vdo_maxDiscardSize-4K}
local vdo_name=${vdo_name-VDONAME} local vdo_name=${vdo_name-VDONAME}
local vdo_physicalThreads=${vdo_physicalThreads-1} local vdo_physicalThreads=${vdo_physicalThreads-1}
local vdo_slabSize=${vdo_slabSize-2G} local vdo_slabSize=${vdo_slabSize-2G}
local vdo_uuid="VDO-$(uuidgen || echo \"f7a3ecdc-40a0-4e43-814c-4a7039a75de4\")"
local vdo_writePolicy=${vdo_writePolicy-auto} local vdo_writePolicy=${vdo_writePolicy-auto}
local vdo_uuid
vdo_uuid="VDO-$(uuidgen || echo \"f7a3ecdc-40a0-4e43-814c-4a7039a75de4\")"
while [ "$#" -ne 0 ] while [ "$#" -ne 0 ]
do do