list_tomb_binds: simplify function

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.
This commit is contained in:
Narrat 2024-08-06 15:43:15 +02:00 committed by Jaromil
parent 6df1cdeab9
commit 42e233d2b0

19
tomb
View File

@ -2730,7 +2730,7 @@ awk "/mapper/"' { print $2 ";" $3 ";" $4 ";" $5 }'`
} }
# Now check hooks # Now check hooks
mounted_hooks=(`list_tomb_binds $tombname "$tombmount"`) mounted_hooks=(`list_tomb_binds "$mapper"`)
for h in ${mounted_hooks}; do for h in ${mounted_hooks}; do
_message "::1 tombname:: hooks ::2 hookdest::" \ _message "::1 tombname:: hooks ::2 hookdest::" \
$tombname ${h[(ws:;:)2]} $tombname ${h[(ws:;:)2]}
@ -2776,23 +2776,16 @@ BEGIN { main="" }
# needs two arguments: name of tomb whose hooks belong # needs two arguments: name of tomb whose hooks belong
# mount tomb # mount tomb
list_tomb_binds() { list_tomb_binds() {
[[ -z "$2" ]] && { [[ -z "$1" ]] && {
_failure "Internal error: list_tomb_binds called without argument." } _failure "Internal error: list_tomb_binds called without argument." }
# much simpler than the crazy from before # much simpler than the crazy from before
# in fact, the second parameter is now redundant # in fact, the second parameter is now redundant
# as we only need the tomb name # as we only need the tomb mapper name
findmnt --source=/dev/mapper/"$1" -rno SOURCE,TARGET,FSTYPE,OPTIONS,LABEL \
# note that this code assumes that the tomb name is provided in square brackets | awk '
_sudo findmnt -ro SOURCE,TARGET,FSTYPE,OPTIONS,LABEL \
| grep -F "/dev/mapper/tomb" \
| awk -vpattern="$1" '
BEGIN { }
{ {
if("["$5"]"!=pattern) next;
if(index($1,"[")==0) next; if(index($1,"[")==0) next;
gsub("[[][^]]*[]]","",$1);
print $1 ";" $2 ";" $3 ";(" $4 ");[" $5 "]" print $1 ";" $2 ";" $3 ";(" $4 ");[" $5 "]"
} }
' '
@ -3064,7 +3057,7 @@ umount_tomb() {
$tombname "$tombmount" $tombname "$tombmount"
# check if there are bind mounted dirs and close them # 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 for b in ${bind_tombs}; do
bind_mapper="${b[(ws:;:)1]}" bind_mapper="${b[(ws:;:)1]}"
bind_mount="${b[(ws:;:)2]}" bind_mount="${b[(ws:;:)2]}"