Mercurial > hgrepos > FreeBSD > ports > sysutils > local-bsdtools
comparison sbin/fzfs @ 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 | 69d557d67842 |
| children | 4f2257ea7d0a |
comparison
equal
deleted
inserted
replaced
| 627:b1e26b956041 | 628:17209ce80536 |
|---|---|
| 305 | 305 |
| 306 _dsname="${1-}" | 306 _dsname="${1-}" |
| 307 [ -z "${_dsname}" ] && { err "no dataset given"; return 2; } | 307 [ -z "${_dsname}" ] && { err "no dataset given"; return 2; } |
| 308 | 308 |
| 309 # Just determine whether the given dataset name exists | 309 # Just determine whether the given dataset name exists |
| 310 _rootds_mountpoint="$(zfs list -H -o mountpoint -t filesystem "${_dsname}" 1>/dev/null 2>/dev/null)" || { err "dataset not found"; return 1; } | 310 _rootds_mountpoint="$(zfs list -H -o mountpoint -t filesystem "${_dsname}" 2>/dev/null)" || { err "dataset not found"; return 1; } |
| 311 | 311 |
| 312 if [ -x "${JQ}" ]; then | 312 _get_zfs_mounts_for_dataset_tree -r "${_dsname}" \ |
| 313 /sbin/mount -t zfs -p --libxo=json,no-locale \ | 313 | { |
| 314 | LC_ALL=C "${JQ}" -r $'.mount.fstab[] | [.device, .mntpoint, .fstype, .opts, .dump, .pass] | @tsv ' \ | 314 while IFS=$'\t' read -r _name _mp ; do |
| 315 | 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; } }' \ | |
| 316 | LC_ALL=C /usr/bin/sort -t $'\t' -k 1 -r \ | |
| 317 | while IFS=$'\t' read -r _name _mp ; do | |
| 318 if checkyes _opt_dry_run ; then | 315 if checkyes _opt_dry_run ; then |
| 319 echo "Would umount ${_name} from ${_mp}" | 316 echo "Would umount ${_name} from ${_mp}" |
| 320 else | 317 else |
| 321 echo "Umounting ${_name} on ${_mp}" | 318 echo "Umounting ${_name} on ${_mp}" |
| 322 /sbin/umount "${_mp}" || return 1 | 319 /sbin/umount "${_mp}" || return 1 |
| 323 fi | 320 fi |
| 324 done | 321 done |
| 325 else | 322 return 0 |
| 326 # Check for unexpected spaces | 323 } |
| 327 if ! check_for_proper_fstab; then | |
| 328 fatal 1 "Unexpected spaces in fstab. Please install \`${JQ}'." | |
| 329 fi | |
| 330 /sbin/mount -t zfs -p \ | |
| 331 | LC_ALL=C /usr/bin/grep -E "^${_dsname}(/|\s)" \ | |
| 332 | LC_ALL=C /usr/bin/sort -r \ | |
| 333 | while IFS=' '$'\t' read -r _name _mp _rest ; do | |
| 334 if checkyes _opt_dry_run ; then | |
| 335 echo "Would umount ${_name} from ${_mp}" | |
| 336 else | |
| 337 echo "Umounting ${_name} on ${_mp}" | |
| 338 /sbin/umount "${_mp}" || return 1 | |
| 339 fi | |
| 340 done | |
| 341 fi | |
| 342 return 0 | |
| 343 } | 324 } |
| 344 | 325 |
| 345 | 326 |
| 346 #: | 327 #: |
| 347 #: Implementation of "copy-tree" | 328 #: Implementation of "copy-tree" |
