changeset 206:92e5db34eb2b

Implent a "-O" flag for mounts that allows to mount also datasets with configured mountpoints outside their "natural" mountpoints within the dataset hierarchy
author Franz Glasner <fzglas.hg@dom66.de>
date Sun, 21 Aug 2022 14:38:05 +0200
parents fcfa674c8444
children a19acddb4662
files sbin/fjail
diffstat 1 files changed, 19 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/sbin/fjail	Sun Aug 21 14:22:40 2022 +0200
+++ b/sbin/fjail	Sun Aug 21 14:38:05 2022 +0200
@@ -40,11 +40,13 @@
     -T        Create only an extra tiny set of datasets
     -u        Do not automatically mount newly created datasets
 
-  mount [-u] [-n] DATASET MOUNTPOINT
+  mount [-O] [-u] [-n] DATASET MOUNTPOINT
 
     Mount the ZFS dataset DATASET and all its children to mountpoint
     MOUNTPOINT
 
+    -O        Also mount datasets at mountpoints outside of their natural
+              and inherited mountpoints
     -n        Do not really mount but show what would be mounted where
     -u        Alias of -n
 
@@ -364,11 +366,15 @@
     local _dsname _mountpoint
     local _name _mp _canmount _mounted
     local _rootds_mountpoint _relative_mp _real_mp
-    local _dry_run
+    local _dry_run _mount_outside
 
     _dry_run=""
-    while getopts "nu" _opt ; do
+    _mount_outside=""
+    while getopts "Onu" _opt ; do
         case ${_opt} in
+            O)
+                _mount_outside="yes"
+                ;;
             n|u)
                 _dry_run="yes"
                 ;;
@@ -433,8 +439,16 @@
                     fi
                     ;;
                 *)
-                    # XXX FIXME Option to do a zfs mount $_name ???
-                    echo "Skipping ${_name} because its configured mountpoint is not relative to given root dataset" 2>&1
+                    if [ "${_mount_outside}" = "yes" ]; then
+                        if [ "${_dry_run}" = "yes" ]; then
+                            echo "Would mount ${_name} on configured dataset mountpoint ${_mp}"
+                        else
+                            echo "Mounting ${_name} on configured dataset mountpoint ${_mp}"
+                            zfs mount "${_name}" || return 1
+                        fi
+                    else
+                        echo "Skipping ${_name} because its configured mountpoint is not relative to given root dataset" 2>&1
+                    fi
                     ;;
             esac
         done