@@ -, +, @@ mkfs.btrfs --label "`/evil/command`' /dev/sdx # /dev/sdx is auto-mounted # the respective btrfs-{scrub,trim,balance} job with configured 'auto' runs --- btrfs-balance.sh | 2 +- btrfs-scrub.sh | 2 +- btrfs-trim.sh | 2 +- btrfsmaintenance-functions | 22 +++++++++++----------- 4 files changed, 14 insertions(+), 14 deletions(-) --- a/btrfs-balance.sh +++ a/btrfs-balance.sh @@ -18,7 +18,7 @@ LOGIDENTIFIER='btrfs-balance' . $(dirname $(realpath "$0"))/btrfsmaintenance-functions { -evaluate_auto_mountpoint BTRFS_BALANCE_MOUNTPOINTS +BTRFS_BALANCE_MOUNTPOINTS=$(expand_auto_mountpoint "$BTRFS_BALANCE_MOUNTPOINTS") OIFS="$IFS" IFS=: exec 2>&1 # redirect stderr to stdout to catch all output to log destination --- a/btrfs-scrub.sh +++ a/btrfs-scrub.sh @@ -29,7 +29,7 @@ if [ "$BTRFS_SCRUB_PRIORITY" = "normal" ]; then fi { -evaluate_auto_mountpoint BTRFS_SCRUB_MOUNTPOINTS +BTRFS_SCRUB_MOUNTPOINTS=$(expand_auto_mountpoint "$BTRFS_SCRUB_MOUNTPOINTS") OIFS="$IFS" IFS=: exec 2>&1 # redirect stderr to stdout to catch all output to log destination --- a/btrfs-trim.sh +++ a/btrfs-trim.sh @@ -18,7 +18,7 @@ LOGIDENTIFIER='btrfs-trim' . $(dirname $(realpath "$0"))/btrfsmaintenance-functions { -evaluate_auto_mountpoint BTRFS_TRIM_MOUNTPOINTS +BTRFS_TRIM_MOUNTPOINTS=$(expand_auto_mountpoint "$BTRFS_TRIM_MOUNTPOINTS") OIFS="$IFS" IFS=: exec 2>&1 # redirect stderr to stdout to catch all output to log destination --- a/btrfsmaintenance-functions +++ a/btrfsmaintenance-functions @@ -3,23 +3,24 @@ # this file contains common code for the btrfs maintenance scripts # -# function: evaluate_auto_mountpoint -# parameter: A variable name +# function: expand_auto_mountpoint +# parameter: path list from config variable or 'auto' # -# this function checks whether the variable contains the special keyword "auto" -# if yes, all currently mounted btrfs filesystems are evaluated and their mountpoints -# are put into the parameter variable -evaluate_auto_mountpoint() { - MOUNTPOINTSVAR=\$"$1" - if [ "$(eval expr \"$MOUNTPOINTSVAR\")" = "auto" ]; then +# if the parameter is 'auto', this function prints path list of all btrfs +# mountpoints, otherwise prints the parameter unchanged +expand_auto_mountpoint() { + local MNTLIST="$1" + + if [ "$MNTLIST" = "auto" ]; then local BTRFS_DEVICES="" local DEVICE="" local MNT="" - local MNTLIST="" + # find all mounted btrfs filesystems, print their device nodes, sort them # and remove identical entries BTRFS_DEVICES=$(findmnt --types btrfs --output "SOURCE" --nofsroot --noheading | sort | uniq) # find one (and only one) corresponding mountpoint for each btrfs device node + MNTLIST="" for DEVICE in $BTRFS_DEVICES; do MNT=$(findmnt --types btrfs --first-only --noheadings --output "TARGET" --source "$DEVICE") if [ -n "$MNTLIST" ]; then @@ -28,9 +29,8 @@ evaluate_auto_mountpoint() { MNTLIST="$MNT" fi done - echo "evaluate mounted filesystems: $MNTLIST" - eval "$1=$MNTLIST" fi + echo -n "$MNTLIST" } # function: detect_mixed_bg --