#!/bin/bash
#
-# Copyright (C) 2007-2012 Red Hat, Inc. All rights reserved.
+# Copyright (C) 2007-2017 Red Hat, Inc. All rights reserved.
#
# This file is part of LVM2.
#
TOOL=fsadm
_SAVEPATH=$PATH
-PATH=/sbin:/usr/sbin:/bin:/usr/sbin:$PATH
+PATH="/sbin:/usr/sbin:/bin:/usr/sbin:$PATH"
# utilities
TUNE_EXT=tune2fs
export _FSADM_YES _FSADM_EXTOFF
unset FSADM_RUNNING
test -n "$LVM_BINARY" && PATH=$_SAVEPATH
- dry exec "$LVM" lvresize $VERB $FORCE -r -L${NEWSIZE}b "$VOLUME_ORIG"
+ dry exec "$LVM" lvresize $VERB $FORCE -r -L"${NEWSIZE}b" "$VOLUME_ORIG"
fi
# error exit status for break
- exit ${1:-1}
+ exit "${1:-1}"
}
# convert parameter from Exa/Peta/Tera/Giga/Mega/Kilo/Bytes and blocks
*) NEWSIZE=$(( $1 * $2 )) ;;
esac
#NEWBLOCKCOUNT=$(round_block_size $NEWSIZE $2)
- NEWBLOCKCOUNT=$(( $NEWSIZE / $2 ))
+ NEWBLOCKCOUNT=$(( NEWSIZE / $2 ))
- if [ $DO_LVRESIZE -eq 1 ]; then
+ if [ "$DO_LVRESIZE" -eq 1 ]; then
# start lvresize, but first cleanup mounted dirs
DO_LVRESIZE=2
cleanup 0
case "$RVOLUME" in
# hardcoded /dev since udev does not create these entries elsewhere
/dev/dm-[0-9]*)
- read </sys/block/${RVOLUME#/dev/}/dm/name SYSVOLUME 2>&1 && VOLUME="$DM_DEV_DIR/mapper/$SYSVOLUME"
- read </sys/block/${RVOLUME#/dev/}/dev MAJORMINOR 2>&1 || error "Cannot get major:minor for \"$VOLUME\"."
+ read <"/sys/block/${RVOLUME#/dev/}/dm/name" SYSVOLUME 2>&1 && VOLUME="$DM_DEV_DIR/mapper/$SYSVOLUME"
+ read <"/sys/block/${RVOLUME#/dev/}/dev" MAJORMINOR 2>&1 || error "Cannot get major:minor for \"$VOLUME\"."
MAJOR=${MAJORMINOR%%:*}
MINOR=${MAJORMINOR##*:}
;;
*)
- STAT=$(stat --format "MAJOR=\$((0x%t)) MINOR=\$((0x%T))" ${RVOLUME})
+ STAT=$(stat --format "MAJOR=\$((0x%t)) MINOR=\$((0x%T))" "$RVOLUME")
test -n "$STAT" || error "Cannot get major:minor for \"$VOLUME\"."
eval "$STAT"
MAJORMINOR="${MAJOR}:${MINOR}"
case "$VOL" in
# hardcoded /dev since udev does not create these entries elsewhere
/dev/dm-[0-9]*)
- read </sys/block/${VOL#/dev/}/dev MOUNTEDMAJORMINOR 2>&1 || error "Cannot get major:minor for \"$VOLUME\"."
+ read <"/sys/block/${VOL#/dev/}/dev" MOUNTEDMAJORMINOR 2>&1 || error "Cannot get major:minor for \"$VOLUME\"."
;;
*)
STAT=$(stat --format "MOUNTEDMAJORMINOR=\$((0x%t)):\$((0x%T))" "$VOL")
# Use 'find' to not fail on to long list of args with too many pids
# only 1st. line is needed
test -z "$MOUNTED" &&
- test $(dmsetup info -c --noheading -o open -j "$MAJOR" -m "$MINOR") -gt 0 &&
+ test "$(dmsetup info -c --noheading -o open -j "$MAJOR" -m "$MINOR")" -gt 0 &&
MOUNTED=$(find "$PROCDIR" -maxdepth 2 -name mountinfo -print0 | xargs -0 "$GREP" "^[0-9]* [0-9]* $MAJORMINOR " 2>/dev/null | head -1 2>/dev/null)
# TODO: for performance compare with sed and stop with 1st. match:
# sed -n "/$MAJORMINOR/ {;p;q;}"
# extract 2nd field after ' - ' separator as mouted device
- MOUNTDEV=$(echo ${MOUNTED##* - } | cut -d ' ' -f 2)
- MOUNTDEV=$(echo -n -e ${MOUNTDEV})
+ MOUNTDEV=$(echo "${MOUNTED##* - }" | cut -d ' ' -f 2)
+ MOUNTDEV=$(echo -n -e "$MOUNTDEV")
# extract 5th field as mount point
# echo -e translates \040 to spaces
- MOUNTED=$(echo ${MOUNTED} | cut -d ' ' -f 5)
- MOUNTED=$(echo -n -e ${MOUNTED})
+ MOUNTED=$(echo "$MOUNTED" | cut -d ' ' -f 5)
+ MOUNTED=$(echo -n -e "$MOUNTED")
test -n "$MOUNTED" || return 1 # Not seen mounted anywhere
# for empty string try again with real volume name
test -z "$MOUNTED" && MOUNTED=$("$GREP" "^$RVOLUME[ \t]" "$PROCMOUNTS")
- MOUNTDEV=$(echo -n -e ${MOUNTED%% *})
+ MOUNTDEV=$(echo -n -e "${MOUNTED%% *}")
# cut device name prefix and trim everything past mountpoint
# echo translates \040 to spaces
MOUNTED=${MOUNTED#* }
- MOUNTED=$(echo -n -e ${MOUNTED%% *})
+ MOUNTED=$(echo -n -e "${MOUNTED%% *}")
# for systems with different device names - check also mount output
if test -z "$MOUNTED" ; then
# If still nothing found and volume is in use
# check every known mount point against MAJOR:MINOR
- if test $(dmsetup info -c --noheading -o open -j "$MAJOR" -m "$MINOR") -gt 0 ; then
+ if test "$(dmsetup info -c --noheading -o open -j "$MAJOR" -m "$MINOR")" -gt 0 ; then
while IFS=$'\n' read -r i ; do
- MOUNTDEV=$(echo -n -e ${i%% *})
+ MOUNTDEV=$(echo -n -e "${i%% *}")
MOUNTED=${i#* }
- MOUNTED=$(echo -n -e ${MOUNTED%% *})
- STAT=$(stat --format "%d" $MOUNTED)
- validate_mounted_major_minor $(decode_major_minor "$STAT")
+ MOUNTED=$(echo -n -e "${MOUNTED%% *}")
+ STAT=$(stat --format "%d" "$MOUNTED")
+ validate_mounted_major_minor "$(decode_major_minor "$STAT")"
done < "$PROCMOUNTS"
fi
test -n "$DEVSIZE" || error "Cannot read size of device \"$VOLUME\"."
SSSIZE=$("$BLOCKDEV" --getss "$VOLUME")
test -n "$SSSIZE" || error "Cannot read sector size of device \"$VOLUME\"."
- DEVSIZE=$(($DEVSIZE * $SSSIZE))
+ DEVSIZE=$(("$DEVSIZE" * "$SSSIZE"))
fi
}
esac
done
validate_parsing "$TUNE_EXT"
- decode_size $1 $BLOCKSIZE
+ decode_size "$1" "$BLOCKSIZE"
FSFORCE=$FORCE
if [ "$NEWBLOCKCOUNT" -lt "$BLOCKCOUNT" -o "$EXTOFF" -eq 1 ]; then
- test $IS_MOUNTED -eq 1 && verbose "$RESIZE_EXT needs unmounted filesystem" && try_umount
+ test "$IS_MOUNTED" -eq 1 && verbose "$RESIZE_EXT needs unmounted filesystem" && try_umount
REMOUNT=$MOUNTED
if test -n "$MOUNTED" ; then
# Forced fsck -f for umounted extX filesystem.
fi
verbose "Resizing filesystem on device \"$VOLUME\" to $NEWSIZE bytes ($BLOCKCOUNT -> $NEWBLOCKCOUNT blocks of $BLOCKSIZE bytes)"
- dry "$RESIZE_EXT" $FSFORCE "$VOLUME" $NEWBLOCKCOUNT
+ dry "$RESIZE_EXT" $FSFORCE "$VOLUME" "$NEWBLOCKCOUNT"
}
#############################
esac
done
validate_parsing "$TUNE_REISER"
- decode_size $1 $BLOCKSIZE
+ decode_size "$1" "$BLOCKSIZE"
verbose "Resizing \"$VOLUME\" $BLOCKCOUNT -> $NEWBLOCKCOUNT blocks ($NEWSIZE bytes, bs: $NEWBLOCKCOUNT)"
if [ -n "$YES" ]; then
- echo y | dry "$RESIZE_REISER" -s $NEWSIZE "$VOLUME"
+ echo y | dry "$RESIZE_REISER" -s "$NEWSIZE" "$VOLUME"
else
- dry "$RESIZE_REISER" -s $NEWSIZE "$VOLUME"
+ dry "$RESIZE_REISER" -s "$NEWSIZE" "$VOLUME"
fi
}
BLOCKSIZE=${BLOCKSIZE%%[^0-9]*}
BLOCKCOUNT=${BLOCKCOUNT%%[^0-9]*}
validate_parsing "$TUNE_XFS"
- decode_size $1 $BLOCKSIZE
- if [ $NEWBLOCKCOUNT -gt $BLOCKCOUNT ]; then
+ decode_size "$1" "$BLOCKSIZE"
+ if [ "$NEWBLOCKCOUNT" -gt "$BLOCKCOUNT" ]; then
verbose "Resizing Xfs mounted on \"$MOUNTPOINT\" to fill device \"$VOLUME\""
- dry "$RESIZE_XFS" $MOUNTPOINT
- elif [ $NEWBLOCKCOUNT -eq $BLOCKCOUNT ]; then
+ dry "$RESIZE_XFS" "$MOUNTPOINT"
+ elif [ "$NEWBLOCKCOUNT" -eq "$BLOCKCOUNT" ]; then
verbose "Xfs filesystem already has the right size"
else
error "Xfs filesystem shrinking is unsupported."
case "$LASTMOUNT" in
*"n/a") ;; # nothing to do - system was not mounted yet
*)
- LASTDIFF=$(diff_dates $LASTMOUNT $LASTCHECKED)
+ LASTDIFF=$(diff_dates "$LASTMOUNT" "$LASTCHECKED")
if test "$LASTDIFF" -gt 0 ; then
verbose "Filesystem has not been checked after the last mount, using fsck -f"
FORCE="-f"
TEST64BIT=$(( 1000 * 1000000000000 ))
test "$TEST64BIT" -eq 1000000000000000 || error "Shell does not handle 64bit arithmetic."
$(echo Y | "$GREP" Y >"$NULL") || error "Grep does not work properly."
-test $("$DATE" -u -d"Jan 01 00:00:01 1970" +%s) -eq 1 || error "Date translation does not work."
+test "$("$DATE" -u -d"Jan 01 00:00:01 1970" +%s)" -eq 1 || error "Date translation does not work."
if [ "$#" -eq 0 ] ; then