From 7cab13d86de57937dbc496842397374098ea17ca Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Thu, 27 Aug 2020 14:02:13 -0400 Subject: fix btrfs-shrink --- src/btrfs-utils/btrfs-shrink | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/btrfs-utils/btrfs-shrink') diff --git a/src/btrfs-utils/btrfs-shrink b/src/btrfs-utils/btrfs-shrink index 229b478..4c4e40d 100755 --- a/src/btrfs-utils/btrfs-shrink +++ b/src/btrfs-utils/btrfs-shrink @@ -6,7 +6,7 @@ die() { printf "%s: Error: %s\n" "$0" "$*" >&2; exit 1; } shrink() { - shrinkmegs=100 + local shrinkmegs=100 mountpoint="$1" while true; do while ! btrfs filesystem resize -${shrinkmegs}M "$mountpoint"/; do shrinkmegs=$((shrinkmegs - 10 )) @@ -30,18 +30,20 @@ btrfs_truncate() main() { if [ -d "$1" ]; then - mountpoint -q "$1" || die "not a mountpoint: $1" - shrink "$1" + mountpoint=$1 + mountpoint -q "$mountpoint" || die "not a mountpoint: $1" + shrink "$mountpoint" elif [ -f "$1" ]; then - mkdir "$1".mnt.tmp - mount -t btrfs "$1" "$1".mnt.tmp + mountpoint="$1".mnt.tmp + mkdir "$mountpoint" + mount -t btrfs "$1" "$mountpoint" result=$? if [ $result = 0 ]; then - shrink "$1".mnt.tmp + shrink "$mountpoint" result=$? + umount "$mountpoint" fi - umount "$1".mnt.tmp - rmdir "$1".mnt.tmp + rmdir "$mountpoint" btrfs_truncate "$1" return $result else -- cgit v1.2.3