}
-# Input vars: $d, eg: /a
+# Input vars: $vol, eg:a
#
-# Output vars: $root_dir, eg: /mnt/root
+# Output vars: $root_dirs[$vol], eg: root_dir[a]=/mnt/root
#
# Note: code-organizational only function.
get-btrfs-root-mountpoint() {
local dev devx
### this is duplicated in check-subvol-stale
- dev=$(sed -rn "s,^\s*([^#]\S*)\s+$d\s.*,\1,p" /etc/fstab /etc/mtab|head -n1)
+ dev=$(sed -rn "s,^\s*([^#]\S*)\s+/$vol\s.*,\1,p" /etc/fstab /etc/mtab|head -n1)
# example dev: /dev/mapper/crypt-vgDISK_BY_ID_NAME-root
d dev=$dev
# $devx are the devices of the btrfs filesystem. they include $dev.
echo "$0: error could not find root subvol mount for $dev" >&2
exit 1
fi
+ root_dirs[$vol]=$root_dir
}
-# Input vars: $vol, $root_dir (from get-btrfs-root-mountpoint)
+# Input vars: $vol, $root_dir
# Note: we cd $root_dir.
expire-leaf-vols() {
local leaf_vols count leaf_limit_time leaf_new_limit_time leaf
#
# Silently give up if $1 is not a child of a btrbk subvol.
#
-# Input vars: $vol $root_dir (from get-btrfs-root-mounts)
+# Input vars: $vol $root_dir
dedupe-btrbk() {
local parentid subvol parent_sub i lines tmpstr
local -a bsubs
# Maybe move volume to leaf.
#
-# Input vars: $vol, $root_dir (from get-btrfs-root-mountpoint)
+# Input vars: $vol, $root_dir
#
# Note: we cd $root_dir.
mv-vol-to-leaf() {
##### end #####
pruned_vols+=("$vol")
+ get-btrfs-root-mountpoint
done
}
# Find and fix the case where a bind mount's original source directory
# got remounted with a different filesystem.
#
-# Input vars: ${pruned_vols[@]}
+# Input vars: ${pruned_vols[@]} ${root_dirs[@]}
#
-# Set leftover vars: $root_dir
+# Leftover vars: $root_dir
mount-mismatch-fix() {
local vol vol_id mp mp_id found_mismatch
local -a to_umount
for vol in ${pruned_vols[@]}; do
set-d-binds
- get-btrfs-root-mountpoint
+ root_dir=${root_dirs[$vol]}
found_mismatch=false
vol_id=$(stat -c%d $root_dir/$vol)
for mp in $d ${binds[@]}; do
umount-kill ${to_umount[@]}
for vol in ${umount_vols[@]}; do
set-d-binds
+ root_dir=${root_dirs[$vol]}
if $umount_ret; then
fresh_snap=$(cat /nocow/btrfs-stale/$vol 2>/dev/null)
- get-btrfs-root-mountpoint
mv-vol-to-leaf
expire-leaf-vols
b btrfs sub snapshot $fresh_snap $vol
ret=0
mkdir -p /var/log/btrbk
+declare -A root_dirs
+
setup-fstab
prune-vols
w mount-mismatch-fix ||: