2017-07-02 22:38:32 +03:00
#!/usr/bin/env bash
2014-01-20 15:02:33 +04:00
# Copyright (C) 2008-2014 Red Hat, Inc. All rights reserved.
2009-01-15 20:14:38 +03:00
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions
# of the GNU General Public License v.2.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
2016-01-21 13:49:46 +03:00
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2009-01-15 20:14:38 +03:00
2010-10-08 19:03:21 +04:00
test_description = 'Exercise fsadm filesystem resize'
2018-05-24 17:49:48 +03:00
2015-10-27 17:10:06 +03:00
SKIP_WITH_LVMPOLLD = 1
2010-10-08 19:03:21 +04:00
2014-06-06 19:40:04 +04:00
. lib/inittest
2009-01-15 20:14:38 +03:00
2010-10-08 19:03:21 +04:00
aux prepare_vg 1 100
# set to "skip" to avoid testing given fs and test warning result
# i.e. check_reiserfs=skip
2014-02-27 02:25:30 +04:00
check_ext2 =
2010-10-08 19:03:21 +04:00
check_ext3 =
check_xfs =
check_reiserfs =
2014-02-27 02:25:30 +04:00
which mkfs.ext2 || check_ext2 = ${ check_ext2 :- mkfs .ext2 }
2012-03-16 17:00:05 +04:00
which mkfs.ext3 || check_ext3 = ${ check_ext3 :- mkfs .ext3 }
which fsck.ext3 || check_ext3 = ${ check_ext3 :- fsck .ext3 }
which mkfs.xfs || check_xfs = ${ check_xfs :- mkfs .xfs }
2014-01-20 15:02:33 +04:00
which xfs_check || {
which xfs_repair || check_xfs = ${ check_xfs :- xfs_repair }
}
2014-03-01 02:05:58 +04:00
grep xfs /proc/filesystems || check_xfs = ${ check_xfs :- no_xfs }
2012-03-16 17:00:05 +04:00
which mkfs.reiserfs || check_reiserfs = ${ check_reiserfs :- mkfs .reiserfs }
which reiserfsck || check_reiserfs = ${ check_reiserfs :- reiserfsck }
2017-10-30 15:28:08 +03:00
modprobe reiserfs || true
2014-03-01 02:05:58 +04:00
grep reiserfs /proc/filesystems || check_reiserfs = ${ check_reiserfs :- no_reiserfs }
2010-10-08 19:03:21 +04:00
2012-03-16 17:00:05 +04:00
vg_lv = $vg /$lv1
vg_lv2 = $vg /${ lv1 } bar
2010-10-08 19:03:21 +04:00
dev_vg_lv = " $DM_DEV_DIR / $vg_lv "
2012-03-16 17:00:05 +04:00
dev_vg_lv2 = " $DM_DEV_DIR / $vg_lv2 "
mount_dir = "mnt"
mount_space_dir = "mnt space dir"
2011-09-19 17:52:22 +04:00
# for recursive call
2017-07-06 20:30:19 +03:00
LVM_BINARY = $( which lvm)
export LVM_BINARY
2010-10-08 19:03:21 +04:00
2012-03-16 17:00:05 +04:00
test ! -d " $mount_dir " && mkdir " $mount_dir "
test ! -d " $mount_space_dir " && mkdir " $mount_space_dir "
2010-10-08 19:03:21 +04:00
cleanup_mounted_and_teardown( )
{
2012-03-16 17:00:05 +04:00
umount " $mount_dir " || true
umount " $mount_space_dir " || true
2011-02-01 01:05:30 +03:00
aux teardown
2010-10-08 19:03:21 +04:00
}
fscheck_ext3( )
{
2012-03-16 17:00:05 +04:00
fsck.ext3 -p -F -f " $dev_vg_lv "
2010-10-08 19:03:21 +04:00
}
fscheck_xfs( )
{
2014-01-20 15:02:33 +04:00
if which xfs_repair ; then
xfs_repair -n " $dev_vg_lv "
else
xfs_check " $dev_vg_lv "
fi
2010-10-08 19:03:21 +04:00
}
fscheck_reiserfs( )
{
2012-03-16 17:00:05 +04:00
reiserfsck --check -p -f " $dev_vg_lv " </dev/null
2010-10-08 19:03:21 +04:00
}
check_missing( )
{
2014-06-30 22:04:24 +04:00
local t
2017-07-07 22:24:57 +03:00
eval " t=\$check_ $1 "
2010-10-08 19:03:21 +04:00
test -z " $t " && return 0
test " $t " = skip && return 1
2014-01-20 15:02:33 +04:00
echo " WARNING: fsadm test skipped $1 tests, $t tool is missing. "
2014-03-01 02:05:58 +04:00
# trick to get test listed with warning
# should false;
2010-10-08 19:03:21 +04:00
return 1
}
2009-01-15 20:14:38 +03:00
# Test for block sizes != 1024 (rhbz #480022)
2010-10-08 19:03:21 +04:00
lvcreate -n $lv1 -L20M $vg
2012-03-16 17:00:05 +04:00
lvcreate -n ${ lv1 } bar -L10M $vg
2011-02-01 01:05:30 +03:00
trap 'cleanup_mounted_and_teardown' EXIT
2010-10-08 19:03:21 +04:00
2012-03-16 17:00:05 +04:00
if check_missing ext2; then
mkfs.ext2 -b4096 -j " $dev_vg_lv "
fsadm --lvresize resize $vg_lv 30M
# Fails - not enough space for 4M fs
not fsadm -y --lvresize resize " $dev_vg_lv " 4M
lvresize -L+10M -r $vg_lv
lvreduce -L10M -r $vg_lv
fscheck_ext3
mount " $dev_vg_lv " " $mount_dir "
not fsadm -y --lvresize resize $vg_lv 4M
echo n | not lvresize -L4M -r -n $vg_lv
lvresize -L+20M -r -n $vg_lv
umount " $mount_dir "
fscheck_ext3
lvresize -f -L20M $vg_lv
fi
2010-10-08 19:03:21 +04:00
if check_missing ext3; then
2012-03-16 17:00:05 +04:00
mkfs.ext3 -b4096 -j " $dev_vg_lv "
mkfs.ext3 -b4096 -j " $dev_vg_lv2 "
2010-10-08 19:03:21 +04:00
fsadm --lvresize resize $vg_lv 30M
# Fails - not enough space for 4M fs
2012-03-16 17:00:05 +04:00
not fsadm -y --lvresize resize " $dev_vg_lv " 4M
2010-10-08 19:03:21 +04:00
lvresize -L+10M -r $vg_lv
lvreduce -L10M -r $vg_lv
fscheck_ext3
2012-03-16 17:00:05 +04:00
mount " $dev_vg_lv " " $mount_dir "
lvresize -L+10M -r $vg_lv
mount " $dev_vg_lv2 " " $mount_space_dir "
fsadm --lvresize -e -y resize $vg_lv2 25M
2011-09-19 17:52:22 +04:00
not fsadm -y --lvresize resize $vg_lv 4M
2011-09-21 14:39:47 +04:00
echo n | not lvresize -L4M -r -n $vg_lv
2010-10-08 19:03:21 +04:00
lvresize -L+20M -r -n $vg_lv
2017-06-21 14:58:55 +03:00
lvresize -L-10M -r -y $vg_lv
2012-03-16 17:00:05 +04:00
umount " $mount_dir "
umount " $mount_space_dir "
2010-10-08 19:03:21 +04:00
fscheck_ext3
lvresize -f -L20M $vg_lv
fi
if check_missing xfs; then
2012-03-16 17:00:05 +04:00
mkfs.xfs -l internal,size= 1000b -f " $dev_vg_lv "
2010-10-08 19:03:21 +04:00
fsadm --lvresize resize $vg_lv 30M
# Fails - not enough space for 4M fs
lvresize -L+10M -r $vg_lv
not lvreduce -L10M -r $vg_lv
fscheck_xfs
2012-03-16 17:00:05 +04:00
mount " $dev_vg_lv " " $mount_dir "
2010-10-08 19:03:21 +04:00
lvresize -L+10M -r -n $vg_lv
2012-03-16 17:00:05 +04:00
umount " $mount_dir "
2010-10-08 19:03:21 +04:00
fscheck_xfs
lvresize -f -L20M $vg_lv
fi
if check_missing reiserfs; then
2012-03-16 17:00:05 +04:00
mkfs.reiserfs -s 513 -f " $dev_vg_lv "
2010-10-08 19:03:21 +04:00
fsadm --lvresize resize $vg_lv 30M
lvresize -L+10M -r $vg_lv
fsadm --lvresize -y resize $vg_lv 10M
fscheck_reiserfs
2012-03-16 17:00:05 +04:00
mount " $dev_vg_lv " " $mount_dir "
2010-10-08 19:03:21 +04:00
2011-09-19 23:37:26 +04:00
fsadm -y --lvresize resize $vg_lv 30M
2012-03-16 17:00:05 +04:00
umount " $mount_dir "
2011-09-19 23:37:26 +04:00
fscheck_reiserfs
2010-10-08 19:03:21 +04:00
lvresize -f -L20M $vg_lv
fi
2011-09-19 17:52:22 +04:00
vgremove -ff $vg