Skip to content

Commit

Permalink
list_tomb_binds: simplify function
Browse files Browse the repository at this point in the history
similar to list_tomb_mounts, rework the findmnt usage to usage of the
actual tomb mapper device.
Simplifies the awk usage and just only one argument needed for the
mapper function.
  • Loading branch information
Narrat committed Aug 6, 2024
1 parent 252cb30 commit 68970ef
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions tomb
Original file line number Diff line number Diff line change
Expand Up @@ -2730,7 +2730,7 @@ awk "/mapper/"' { print $2 ";" $3 ";" $4 ";" $5 }'`
}

# Now check hooks
mounted_hooks=(`list_tomb_binds $tombname "$tombmount"`)
mounted_hooks=(`list_tomb_binds "$mapper"`)
for h in ${mounted_hooks}; do
_message "::1 tombname:: hooks ::2 hookdest::" \
$tombname ${h[(ws:;:)2]}
Expand Down Expand Up @@ -2776,23 +2776,16 @@ BEGIN { main="" }
# needs two arguments: name of tomb whose hooks belong
# mount tomb
list_tomb_binds() {
[[ -z "$2" ]] && {
[[ -z "$1" ]] && {
_failure "Internal error: list_tomb_binds called without argument." }

# much simpler than the crazy from before
# in fact, the second parameter is now redundant
# as we only need the tomb name

# note that this code assumes that the tomb name is provided in square brackets

_sudo findmnt -ro SOURCE,TARGET,FSTYPE,OPTIONS,LABEL \
| grep -F "/dev/mapper/tomb" \
| awk -vpattern="$1" '
BEGIN { }
# as we only need the tomb mapper name
findmnt --source=/dev/mapper/"$1" -rno SOURCE,TARGET,FSTYPE,OPTIONS,LABEL \
| awk '
{
if("["$5"]"!=pattern) next;
if(index($1,"[")==0) next;
gsub("[[][^]]*[]]","",$1);
print $1 ";" $2 ";" $3 ";(" $4 ");[" $5 "]"
}
'
Expand Down Expand Up @@ -3064,7 +3057,7 @@ umount_tomb() {
$tombname "$tombmount"

# check if there are bind mounted dirs and close them
bind_tombs=(`list_tomb_binds $tombname "$tombmount"`)
bind_tombs=(`list_tomb_binds "$mapper"`)
for b in ${bind_tombs}; do
bind_mapper="${b[(ws:;:)1]}"
bind_mount="${b[(ws:;:)2]}"
Expand Down

0 comments on commit 68970ef

Please sign in to comment.