changeset 628:17209ce80536

Use the newly implemented "_get_zfs_mounts_for_dataset_tree()" where appropriate. It is in sbin/ftjail and sbin/fzfs.
author Franz Glasner <fzglas.hg@dom66.de>
date Tue, 24 Sep 2024 18:46:15 +0200
parents b1e26b956041
children f7eda6256ae8
files sbin/ftjail sbin/fzfs
diffstat 2 files changed, 10 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/sbin/ftjail	Tue Sep 24 18:20:30 2024 +0200
+++ b/sbin/ftjail	Tue Sep 24 18:46:15 2024 +0200
@@ -535,18 +535,11 @@
     [ -z "${_dsname}" ] && { echo "ERROR: no dataset given" >&2; return 2; }
 
     # Just determine whether the given dataset name exists
-    _rootds_mountpoint="$(zfs list -H -o mountpoint -t filesystem "${_dsname}")" || \
-        { echo "ERROR: dataset not found" >&2; return 1; }
+    _rootds_mountpoint="$(zfs list -H -o mountpoint -t filesystem "${_dsname}" 2>/dev/null)" || { err "dataset not found"; return 1; }
 
-    # Check for unexpected spaces
-    if ! check_for_proper_fstab; then
-        fatal 1 "Unexpected spaces in fstab. Please install \`${JQ}'."
-    fi
-    /sbin/mount -t zfs -p \
-    | LC_ALL=C /usr/bin/grep -E "^${_dsname}(/|\s)" \
-    | LC_ALL=C /usr/bin/sort -n -r \
+    _get_zfs_mounts_for_dataset_tree -r "${_dsname}" \
     | {
-        while IFS=' '$'\t' read -r _name _mp _rest ; do
+        while IFS=$'\t' read -r _name _mp _rest ; do
             echo "Umounting ${_name} on ${_mp}"
             /sbin/umount "${_mp}" || return 1
         done
--- a/sbin/fzfs	Tue Sep 24 18:20:30 2024 +0200
+++ b/sbin/fzfs	Tue Sep 24 18:46:15 2024 +0200
@@ -307,39 +307,20 @@
     [ -z "${_dsname}" ] && { err "no dataset given"; return 2; }
 
     # Just determine whether the given dataset name exists
-    _rootds_mountpoint="$(zfs list -H -o mountpoint -t filesystem "${_dsname}" 1>/dev/null 2>/dev/null)" || { err "dataset not found"; return 1; }
+    _rootds_mountpoint="$(zfs list -H -o mountpoint -t filesystem "${_dsname}" 2>/dev/null)" || { err "dataset not found"; return 1; }
 
-    if [ -x "${JQ}" ]; then
-        /sbin/mount -t zfs -p --libxo=json,no-locale \
-        | LC_ALL=C "${JQ}" -r $'.mount.fstab[] | [.device, .mntpoint, .fstype, .opts, .dump, .pass] | @tsv ' \
-        | LC_ALL=C /usr/bin/awk -F $'\\t+' -v OFS=$'\t' -v ds1="${_dsname}" -v ds2="${_dsname}/" $'{ if (($1 == ds1) || (index($1, ds2) == 1)) { print $1, $2; } }' \
-        | LC_ALL=C /usr/bin/sort -t $'\t' -k 1 -r \
-        | while IFS=$'\t' read -r _name _mp ; do
+    _get_zfs_mounts_for_dataset_tree -r "${_dsname}" \
+    | {
+        while IFS=$'\t' read -r _name _mp ; do
             if checkyes _opt_dry_run ; then
                 echo "Would umount ${_name} from ${_mp}"
             else
                 echo "Umounting ${_name} on ${_mp}"
                 /sbin/umount "${_mp}" || return 1
             fi
-          done
-    else
-        # Check for unexpected spaces
-        if ! check_for_proper_fstab; then
-            fatal 1 "Unexpected spaces in fstab. Please install \`${JQ}'."
-        fi
-        /sbin/mount -t zfs -p \
-        | LC_ALL=C /usr/bin/grep -E "^${_dsname}(/|\s)" \
-        | LC_ALL=C /usr/bin/sort -r \
-        | while IFS=' '$'\t' read -r _name _mp _rest ; do
-            if checkyes _opt_dry_run ; then
-                echo "Would umount ${_name} from ${_mp}"
-            else
-                echo "Umounting ${_name} on ${_mp}"
-                /sbin/umount "${_mp}" || return 1
-            fi
-          done
-    fi
-    return 0
+        done
+        return 0
+      }
 }