2010-01-20 10:27:08 +11:00
|
|
|
#! /bin/bash
|
2018-06-09 11:35:42 +10:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
# Copyright (c) 2009 Christoph Hellwig.
|
|
|
|
|
#
|
2015-02-12 14:20:27 +11:00
|
|
|
# FS QA Test No. 050
|
2009-01-10 21:38:24 +01:00
|
|
|
#
|
|
|
|
|
# Check out various mount/remount/unmount scenarious on a read-only blockdev.
|
|
|
|
|
#
|
2019-11-05 14:19:21 +01:00
|
|
|
seqfull=$0
|
2009-01-10 21:38:24 +01:00
|
|
|
seq=`basename $0`
|
2013-03-15 12:28:02 +00:00
|
|
|
seqres=$RESULT_DIR/$seq
|
2009-01-10 21:38:24 +01:00
|
|
|
echo "QA output created by $seq"
|
|
|
|
|
|
|
|
|
|
here=`pwd`
|
|
|
|
|
tmp=/tmp/$$
|
|
|
|
|
status=1 # failure is the default!
|
|
|
|
|
|
|
|
|
|
_cleanup()
|
|
|
|
|
{
|
|
|
|
|
cd /
|
|
|
|
|
blockdev --setrw $SCRATCH_DEV
|
|
|
|
|
}
|
|
|
|
|
trap "_cleanup; exit \$status" 0 1 2 3 15
|
|
|
|
|
|
|
|
|
|
# get standard environment, filters and checks
|
2013-03-15 12:28:04 +00:00
|
|
|
. ./common/rc
|
|
|
|
|
. ./common/filter
|
2009-01-10 21:38:24 +01:00
|
|
|
|
|
|
|
|
# real QA test starts here
|
2015-02-12 14:20:27 +11:00
|
|
|
_supported_fs generic
|
2009-01-10 21:38:24 +01:00
|
|
|
|
2014-09-29 12:56:28 +10:00
|
|
|
_require_scratch_nocheck
|
2015-02-12 14:14:52 +11:00
|
|
|
_require_scratch_shutdown
|
2018-01-02 17:17:05 +00:00
|
|
|
_require_local_device $SCRATCH_DEV
|
2015-02-12 14:19:37 +11:00
|
|
|
_require_norecovery
|
2009-01-10 21:38:24 +01:00
|
|
|
|
2019-11-05 14:19:21 +01:00
|
|
|
# Select appropriate output file
|
|
|
|
|
features=""
|
|
|
|
|
if ! _has_metadata_journaling $SCRATCH_DEV >/dev/null; then
|
|
|
|
|
features="nojournal"
|
2019-11-11 15:49:52 +01:00
|
|
|
elif [ "$FSTYP" = "xfs" ] && echo "$MOUNT_OPTIONS" | grep -q quota ; then
|
|
|
|
|
# Mounting with quota on XFS requires a writable fs, which means
|
|
|
|
|
# we expect to fail the ro blockdev test with with EPERM.
|
|
|
|
|
features="xfsquota"
|
2019-11-05 14:19:21 +01:00
|
|
|
fi
|
|
|
|
|
_link_out_file "$features"
|
|
|
|
|
|
2015-02-12 14:20:27 +11:00
|
|
|
_scratch_mkfs >/dev/null 2>&1
|
2009-01-10 21:38:24 +01:00
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Mark the device read-only
|
|
|
|
|
#
|
|
|
|
|
echo "setting device read-only"
|
|
|
|
|
blockdev --setro $SCRATCH_DEV
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Mount it, and make sure we can't write to it, and we can unmount it again
|
|
|
|
|
#
|
|
|
|
|
echo "mounting read-only block device:"
|
2019-11-27 08:34:57 -08:00
|
|
|
_try_scratch_mount 2>&1 | _filter_ro_mount | _filter_scratch
|
|
|
|
|
if [ "${PIPESTATUS[0]}" -eq 0 ]; then
|
|
|
|
|
echo "touching file on read-only filesystem (should fail)"
|
|
|
|
|
touch $SCRATCH_MNT/foo 2>&1 | _filter_scratch
|
|
|
|
|
fi
|
2009-01-10 21:38:24 +01:00
|
|
|
|
2019-11-11 15:49:52 +01:00
|
|
|
#
|
|
|
|
|
# Apparently this used to be broken at some point:
|
|
|
|
|
# http://oss.sgi.com/bugzilla/show_bug.cgi?id=807
|
|
|
|
|
#
|
|
|
|
|
echo "unmounting read-only filesystem"
|
2019-11-11 15:49:53 +01:00
|
|
|
_scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
|
2009-01-10 21:38:24 +01:00
|
|
|
|
|
|
|
|
echo "setting device read-write"
|
|
|
|
|
blockdev --setrw $SCRATCH_DEV
|
|
|
|
|
|
|
|
|
|
echo "mounting read-write block device:"
|
2018-02-07 17:31:36 +08:00
|
|
|
_try_scratch_mount 2>&1 | _filter_scratch
|
2009-01-10 21:38:24 +01:00
|
|
|
|
|
|
|
|
echo "touch files"
|
|
|
|
|
touch $SCRATCH_MNT/{0,1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}
|
|
|
|
|
|
|
|
|
|
echo "going down:"
|
2019-05-20 15:31:10 -07:00
|
|
|
_scratch_shutdown -f
|
2009-01-10 21:38:24 +01:00
|
|
|
|
|
|
|
|
echo "unmounting shutdown filesystem:"
|
2015-12-21 18:07:43 +11:00
|
|
|
_scratch_unmount 2>&1 | _filter_scratch
|
2009-01-10 21:38:24 +01:00
|
|
|
|
|
|
|
|
echo "setting device read-only"
|
|
|
|
|
blockdev --setro $SCRATCH_DEV
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Mounting a filesystem that requires log-recovery fails unless
|
|
|
|
|
# -o norecovery is used.
|
|
|
|
|
#
|
|
|
|
|
echo "mounting filesystem that needs recovery on a read-only device:"
|
2019-11-27 08:34:57 -08:00
|
|
|
_try_scratch_mount 2>&1 | _filter_ro_mount | _filter_scratch
|
2009-01-10 21:38:24 +01:00
|
|
|
|
|
|
|
|
echo "unmounting read-only filesystem"
|
2017-11-14 18:26:45 +08:00
|
|
|
_scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
|
2009-01-10 21:38:24 +01:00
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# This is the way out if the underlying device really is read-only.
|
2018-12-18 12:36:03 -08:00
|
|
|
# Doesn't mean it's a good idea in practice, more a last resort
|
2009-01-10 21:38:24 +01:00
|
|
|
# data recovery hack.
|
|
|
|
|
#
|
|
|
|
|
echo "mounting filesystem with -o norecovery on a read-only device:"
|
2019-11-27 08:34:57 -08:00
|
|
|
_try_scratch_mount -o norecovery 2>&1 | _filter_ro_mount | _filter_scratch
|
2019-11-11 15:49:52 +01:00
|
|
|
echo "unmounting read-only filesystem"
|
2019-11-11 15:49:53 +01:00
|
|
|
_scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
|
2009-01-10 21:38:24 +01:00
|
|
|
|
|
|
|
|
echo "setting device read-write"
|
|
|
|
|
blockdev --setrw $SCRATCH_DEV
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# But log recovery is performed when mount with -o ro as long as
|
|
|
|
|
# the underlying device is not write protected.
|
|
|
|
|
#
|
|
|
|
|
echo "mounting filesystem that needs recovery with -o ro:"
|
2018-02-07 17:31:36 +08:00
|
|
|
_try_scratch_mount -o ro 2>&1 | _filter_scratch
|
2009-01-10 21:38:24 +01:00
|
|
|
|
|
|
|
|
# success, all done
|
|
|
|
|
echo "*** done"
|
2013-03-15 12:28:02 +00:00
|
|
|
rm -f $seqres.full
|
2009-01-10 21:38:24 +01:00
|
|
|
status=0
|