| #!/usr/bin/env bash | |
| # Copyright (C) 2012 Karel Zak <kzak@redhat.com> | |
| TS_TOPDIR="${0%/*}/../.." | |
| TS_DESC="umount-recursive" | |
| . "$TS_TOPDIR"/functions.sh | |
| ts_init "$*" | |
| ts_check_test_command "$TS_CMD_MOUNT" | |
| ts_check_test_command "$TS_CMD_UMOUNT" | |
| ts_check_test_command "$TS_CMD_FDISK" | |
| ts_skip_nonroot | |
| ts_check_prog "mkfs.ext2" | |
| $TS_CMD_UMOUNT --help | grep -q recursive | |
| [ $? -eq 1 ] && ts_skip "recursive unsupported" | |
| ts_log "Init device" | |
| # set global variable TS_DEVICE | |
| ts_scsi_debug_init dev_size_mb=50 | |
| ts_log "Create partitions" | |
| $TS_CMD_FDISK --noauto-pt ${TS_DEVICE} &> /dev/null <<EOF | |
| o | |
| n | |
| p | |
| 1 | |
| +10M | |
| n | |
| p | |
| 2 | |
| +10M | |
| n | |
| p | |
| 3 | |
| +10M | |
| n | |
| p | |
| +10M | |
| w | |
| q | |
| EOF | |
| udevadm settle | |
| ts_log "Create filesystem A" | |
| mkfs.ext2 ${TS_DEVICE}1 &> /dev/null | |
| ts_log "Create filesystem B" | |
| mkfs.ext2 ${TS_DEVICE}2 &> /dev/null | |
| ts_log "Create filesystem C" | |
| mkfs.ext2 ${TS_DEVICE}3 &> /dev/null | |
| ts_log "Create filesystem D" | |
| mkfs.ext2 ${TS_DEVICE}4 &> /dev/null | |
| udevadm settle | |
| ts_log "Do tests..." | |
| [ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT | |
| ts_log "A) Mount root" | |
| $TS_CMD_MOUNT ${TS_DEVICE}1 $TS_MOUNTPOINT >> "$TS_OUTPUT" 2>> "$TS_ERRLOG" | |
| $TS_CMD_MOUNT --make-shared $TS_MOUNTPOINT &> /dev/null | |
| ts_log "B) Mount child" | |
| mkdir -p $TS_MOUNTPOINT/mntB | |
| $TS_CMD_MOUNT ${TS_DEVICE}2 $TS_MOUNTPOINT/mntB >> "$TS_OUTPUT" 2>> "$TS_ERRLOG" | |
| ts_log "B2) Mount child-bind" | |
| mkdir -p $TS_MOUNTPOINT/bindB | |
| $TS_CMD_MOUNT --bind $TS_MOUNTPOINT/mntB $TS_MOUNTPOINT/bindB >> "$TS_OUTPUT" 2>> "$TS_ERRLOG" | |
| ts_log "C) Mount child/child" | |
| mkdir -p $TS_MOUNTPOINT/mntB/mnt{C,D} | |
| $TS_CMD_MOUNT ${TS_DEVICE}3 $TS_MOUNTPOINT/mntB/mntC >> "$TS_OUTPUT" 2>> "$TS_ERRLOG" | |
| ts_log "D) Mount child/child" | |
| $TS_CMD_MOUNT ${TS_DEVICE}4 $TS_MOUNTPOINT/mntB/mntD >> "$TS_OUTPUT" 2>> "$TS_ERRLOG" | |
| ts_log "E) Mount child-bind" | |
| mkdir -p $TS_MOUNTPOINT/bindC | |
| $TS_CMD_MOUNT --bind $TS_MOUNTPOINT/mntB/mntC $TS_MOUNTPOINT/bindC &> /dev/null | |
| ts_log "F) Mount mountpoint-bind" | |
| $TS_CMD_MOUNT --bind $TS_MOUNTPOINT $TS_MOUNTPOINT &> /dev/null | |
| udevadm settle | |
| $TS_CMD_UMOUNT --recursive $TS_MOUNTPOINT >> "$TS_OUTPUT" 2>> "$TS_ERRLOG" \ | |
| || ts_die "umount failed" | |
| # the mountpoint has already been unmounted, so this second call should not fail | |
| $TS_CMD_UMOUNT --graceful $TS_MOUNTPOINT >> "$TS_OUTPUT" 2>> "$TS_ERRLOG" \ | |
| || ts_die "--graceful on unmounted mountpoint failed" | |
| # non-existent path should not fail with --graceful | |
| $TS_CMD_UMOUNT --graceful /non-existent-path-$$ >> "$TS_OUTPUT" 2>> "$TS_ERRLOG" \ | |
| || ts_die "--graceful on non-existent path failed" | |
| # --graceful has to be honoured also for --recursive | |
| $TS_CMD_UMOUNT --recursive --graceful $TS_MOUNTPOINT >> "$TS_OUTPUT" 2>> "$TS_ERRLOG" \ | |
| || ts_die "--recursive --graceful on unmounted mountpoint failed" | |
| $TS_CMD_UMOUNT --recursive --graceful /non-existent-path-$$ >> "$TS_OUTPUT" 2>> "$TS_ERRLOG" \ | |
| || ts_die "--recursive --graceful on non-existent path failed" | |
| # --graceful has to be honoured also for --all-targets | |
| $TS_CMD_UMOUNT --all-targets --graceful /non-existent-path-$$ >> "$TS_OUTPUT" 2>> "$TS_ERRLOG" \ | |
| || ts_die "--all-targets --graceful on non-existent path failed" | |
| ts_log "G) Mount below a non-mountpoint directory" | |
| $TS_CMD_MOUNT ${TS_DEVICE}1 $TS_MOUNTPOINT >> "$TS_OUTPUT" 2>> "$TS_ERRLOG" | |
| mkdir -p $TS_MOUNTPOINT/dir/mnt{A,B} $TS_MOUNTPOINT/dirX | |
| $TS_CMD_MOUNT ${TS_DEVICE}2 $TS_MOUNTPOINT/dir/mntA >> "$TS_OUTPUT" 2>> "$TS_ERRLOG" | |
| $TS_CMD_MOUNT ${TS_DEVICE}3 $TS_MOUNTPOINT/dir/mntB >> "$TS_OUTPUT" 2>> "$TS_ERRLOG" | |
| $TS_CMD_MOUNT ${TS_DEVICE}4 $TS_MOUNTPOINT/dirX >> "$TS_OUTPUT" 2>> "$TS_ERRLOG" | |
| udevadm settle | |
| # dir is not a mountpoint, umount all below it but keep the sibling dirX | |
| $TS_CMD_UMOUNT --recursive $TS_MOUNTPOINT/dir >> "$TS_OUTPUT" 2>> "$TS_ERRLOG" \ | |
| || ts_die "umount of non-mountpoint directory failed" | |
| # trailing and redundant slashes must not break the match | |
| $TS_CMD_MOUNT ${TS_DEVICE}2 $TS_MOUNTPOINT/dir/mntA >> "$TS_OUTPUT" 2>> "$TS_ERRLOG" | |
| udevadm settle | |
| $TS_CMD_UMOUNT --recursive --no-canonicalize $TS_MOUNTPOINT/dir/ >> "$TS_OUTPUT" 2>> "$TS_ERRLOG" \ | |
| || ts_die "umount of non-mountpoint directory with trailing slash failed" | |
| $TS_CMD_MOUNT ${TS_DEVICE}2 $TS_MOUNTPOINT/dir/mntA >> "$TS_OUTPUT" 2>> "$TS_ERRLOG" | |
| udevadm settle | |
| $TS_CMD_UMOUNT --recursive --no-canonicalize $TS_MOUNTPOINT//dir >> "$TS_OUTPUT" 2>> "$TS_ERRLOG" \ | |
| || ts_die "umount of non-mountpoint directory with redundant slash failed" | |
| # an empty target must not be resolved to the current directory | |
| $TS_CMD_UMOUNT --recursive "" >> "$TS_OUTPUT" 2>> "$TS_ERRLOG" \ | |
| && ts_die "umount of an empty target succeeded" | |
| ts_log "H) Sibling and parent mounts untouched" | |
| $TS_CMD_UMOUNT $TS_MOUNTPOINT/dirX >> "$TS_OUTPUT" 2>> "$TS_ERRLOG" \ | |
| || ts_die "prefix-sharing sibling mount has been umounted too" | |
| $TS_CMD_UMOUNT --recursive $TS_MOUNTPOINT >> "$TS_OUTPUT" 2>> "$TS_ERRLOG" \ | |
| || ts_die "parent mountpoint has been umounted too" | |
| ts_log "Success" | |
| ts_finalize | |