diff sbin/fzfs @ 662:bc418b122fc9

fzfs: Implement option "-f" for the "umount" command: try to forcefully umount a dataset tree
author Franz Glasner <fzglas.hg@dom66.de>
date Sun, 29 Sep 2024 16:27:22 +0200
parents 1e6c86f0a850
children 6e7c118e7d47
line wrap: on
line diff
--- a/sbin/fzfs	Sun Sep 29 16:22:45 2024 +0200
+++ b/sbin/fzfs	Sun Sep 29 16:27:22 2024 +0200
@@ -37,9 +37,9 @@
 
   mount [-O] [-N] [-P] [-k] [-u] [-n] DATASET [MOUNTPOINT]
 
-  umount [-k] DATASET
+  umount [-f] [-k] DATASET
 
-  unmount
+  unmount [-f] [-k] DATASET
 
 '
 
@@ -285,14 +285,18 @@
 #:
 command_umount() {
     local _dsname
-    local _opt_dry_run
+    local _opt_force _opt_dry_run
 
     local _opt _name _mp _rest _rootds_mountpoint
 
+    _opt_force=""
     _opt_dry_run=""
 
-    while getopts "k" _opt ; do
+    while getopts "fk" _opt ; do
         case ${_opt} in
+            f)
+                _opt_force="-f"
+                ;;
             k)
                 _opt_dry_run="yes"
                 ;;
@@ -314,10 +318,15 @@
     | {
         while IFS=$'\t' read -r _name _mp ; do
             if checkyes _opt_dry_run ; then
-                echo "Would umount ${_name} from ${_mp}"
+                if [ -z "${_opt_force}" ]; then
+                    echo "Would umount ${_name} from ${_mp}"
+                else
+
+                    echo "Would forcefully umount ${_name} from ${_mp}"
+                fi
             else
                 echo "Umounting ${_name} on ${_mp}"
-                /sbin/umount "${_mp}" || return 1
+                /sbin/umount ${_opt_force} "${_mp}" || return 1
             fi
         done
         return 0