comparison 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
comparison
equal deleted inserted replaced
661:1e6c86f0a850 662:bc418b122fc9
35 35
36 create-tree [-A] [-M MOUNTPOINT] [-n] [-p] [-u] SOURCE-DATASET DEST-DATASET 36 create-tree [-A] [-M MOUNTPOINT] [-n] [-p] [-u] SOURCE-DATASET DEST-DATASET
37 37
38 mount [-O] [-N] [-P] [-k] [-u] [-n] DATASET [MOUNTPOINT] 38 mount [-O] [-N] [-P] [-k] [-u] [-n] DATASET [MOUNTPOINT]
39 39
40 umount [-k] DATASET 40 umount [-f] [-k] DATASET
41 41
42 unmount 42 unmount [-f] [-k] DATASET
43 43
44 ' 44 '
45 45
46 46
47 _p_datadir='@@DATADIR@@' 47 _p_datadir='@@DATADIR@@'
283 #: 283 #:
284 #: Umount a datasets and recursively all its children datasets. 284 #: Umount a datasets and recursively all its children datasets.
285 #: 285 #:
286 command_umount() { 286 command_umount() {
287 local _dsname 287 local _dsname
288 local _opt_dry_run 288 local _opt_force _opt_dry_run
289 289
290 local _opt _name _mp _rest _rootds_mountpoint 290 local _opt _name _mp _rest _rootds_mountpoint
291 291
292 _opt_force=""
292 _opt_dry_run="" 293 _opt_dry_run=""
293 294
294 while getopts "k" _opt ; do 295 while getopts "fk" _opt ; do
295 case ${_opt} in 296 case ${_opt} in
297 f)
298 _opt_force="-f"
299 ;;
296 k) 300 k)
297 _opt_dry_run="yes" 301 _opt_dry_run="yes"
298 ;; 302 ;;
299 \?) 303 \?)
300 return 2; 304 return 2;
312 316
313 _get_zfs_mounts_for_dataset_tree -r "${_dsname}" \ 317 _get_zfs_mounts_for_dataset_tree -r "${_dsname}" \
314 | { 318 | {
315 while IFS=$'\t' read -r _name _mp ; do 319 while IFS=$'\t' read -r _name _mp ; do
316 if checkyes _opt_dry_run ; then 320 if checkyes _opt_dry_run ; then
317 echo "Would umount ${_name} from ${_mp}" 321 if [ -z "${_opt_force}" ]; then
322 echo "Would umount ${_name} from ${_mp}"
323 else
324
325 echo "Would forcefully umount ${_name} from ${_mp}"
326 fi
318 else 327 else
319 echo "Umounting ${_name} on ${_mp}" 328 echo "Umounting ${_name} on ${_mp}"
320 /sbin/umount "${_mp}" || return 1 329 /sbin/umount ${_opt_force} "${_mp}" || return 1
321 fi 330 fi
322 done 331 done
323 return 0 332 return 0
324 } 333 }
325 } 334 }