2017-07-02 22:38:32 +03:00
#!/usr/bin/env bash
2017-05-22 15:43:30 +03:00
# Copyright (C) 2017 Red Hat, Inc. All rights reserved.
#
# 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,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
test_description = 'Exercise fsadm operation on renamed device'
2018-05-24 17:49:48 +03:00
2017-05-22 15:43:30 +03:00
SKIP_WITH_LVMPOLLD = 1
. lib/inittest
2022-08-31 13:22:59 +03:00
aux prepare_vg 1 700
2017-05-22 15:43:30 +03:00
vg_lv = $vg /$lv1
vg_lv_ren = ${ vg_lv } _renamed
dev_vg_lv = " $DM_DEV_DIR / $vg_lv "
dev_vg_lv_ren = " $DM_DEV_DIR / $vg_lv_ren "
mount_dir = "mnt"
mount_space_dir = "mnt space dir"
mount_dolar_dir = "mnt \$SPACE dir"
test ! -d " $mount_dir " && mkdir " $mount_dir "
test ! -d " $mount_space_dir " && mkdir " $mount_space_dir "
test ! -d " $mount_dolar_dir " && mkdir " $mount_dolar_dir "
cleanup_mounted_and_teardown( )
{
umount " $mount_dir " || true
umount " $mount_space_dir " || true
umount " $mount_dolar_dir " || true
aux teardown
}
2017-11-08 01:59:04 +03:00
check_mounted( )
{
mount | tee out
grep $vg out || {
# older versions of systemd sometimes umount volume by mistake
# skip further test when this case happens
systemctl --version | grep "systemd 222" && \
skip "System is running old racy systemd version."
}
}
2017-05-22 15:43:30 +03:00
# Test for block sizes != 1024 (rhbz #480022)
trap 'cleanup_mounted_and_teardown' EXIT
# Iterate over supported filesystems
for i in mkfs.ext3 mkfs.xfs mkfs.reiserfs
do
if not which " $i " ; then
echo " Skipping tests for missing $i "
continue
fi
2022-08-31 13:22:59 +03:00
lvcreate -n $lv1 -L300M $vg
2017-05-22 15:43:30 +03:00
case " $i " in
*ext3) MKFS_ARGS = "-b1024 -j" ; ;
2022-08-31 13:22:59 +03:00
*xfs) MKFS_ARGS = "-l internal,size=64m -f" ; ;
2017-05-22 15:43:30 +03:00
*reiserfs) MKFS_ARGS = "-s 513 -f" ; ;
esac
echo " $i "
" $i " $MKFS_ARGS " $dev_vg_lv "
2017-05-31 14:23:34 +03:00
# Adding couple udev wait ops as some older systemd
# might get confused and was 'randomly/racy' umounting
# devices just mounted.
2023-10-05 00:54:07 +03:00
#
# See for explanation:
2017-05-31 14:23:34 +03:00
# https://github.com/systemd/systemd/commit/628c89cc68ab96fce2de7ebba5933725d147aecc
# https://github.com/systemd/systemd/pull/2017
aux udev_wait
2022-10-11 19:28:19 +03:00
# mount /dev/test/lv1 on /mnt
2017-05-22 15:43:30 +03:00
mount " $dev_vg_lv " " $mount_dir "
2017-05-31 14:23:34 +03:00
aux udev_wait
2022-10-11 19:28:19 +03:00
# rename lv1 to lv1_renamed, now /dev/test/lv1_renamed is mounted on /mnt,
# but "df" and "mount" commands will still show /dev/test/lv1 mounted on /mnt.
2017-05-22 15:43:30 +03:00
lvrename $vg_lv $vg_lv_ren
2017-11-08 01:59:04 +03:00
check_mounted
2017-05-22 15:43:30 +03:00
# fails on renamed LV
2022-10-11 19:28:19 +03:00
# lvextend -r test/lv1_renamed succeeds in extending the LV (as lv1_renamed),
# but xfs_growfs /dev/test/lv1_renamed fails because it doesn't recognize
# that device is mounted, because the old lv name reported as being mounted.
2017-11-08 01:59:04 +03:00
fail lvresize -y -L+10M -r $vg_lv_ren
2017-05-22 15:43:30 +03:00
2017-05-23 14:59:29 +03:00
# fails on unknown mountpoint (FIXME: umount)
2017-05-22 15:43:30 +03:00
not umount " $dev_vg_lv "
2022-10-11 19:28:19 +03:00
# create a new LV with the previous name of the renamed lv
2022-08-31 13:22:59 +03:00
lvcreate -L300 -n $lv1 $vg
2017-05-22 15:43:30 +03:00
" $i " $MKFS_ARGS " $dev_vg_lv "
2017-05-31 14:23:34 +03:00
aux udev_wait
2022-10-11 19:28:19 +03:00
# mount the new lv on a dir with a similar name as the other
# now df will show
# /dev/mapper/test-lv1 ... /mnt
# /dev/mapper/test-lv1 ... /mnt $SPACE dir
2017-05-22 15:43:30 +03:00
mount " $dev_vg_lv " " $mount_dolar_dir "
2017-11-08 01:59:04 +03:00
check_mounted
2017-05-22 15:43:30 +03:00
2022-10-11 19:28:19 +03:00
# try to resize the LV that was renamed: lvextend -r test/lv1_renamed
# this succeeds in extending the LV (lv1_renamed), but xfs_growfs fails
# for the same reason as above, i.e. mount doesn't show the lv1_renamed
# device is mounted anywhere.
2017-05-22 15:43:30 +03:00
not lvresize -L+10M -r $vg_lv_ren
umount " $mount_dir "
2023-10-05 00:54:07 +03:00
USE_NOT =
# TODO: this is somewhat suprising for users
# Detect if the 'lvresize' was compiled with HAVE_BLKID_SUBLKS_FSINFO
# In such case --fs checksize is a supported parameter
# otherwise command automatically fallbacks to fsadm and resize reiserfs
not lvresize --fs checksize -L+1 $vg /XXX 2>err
if not grep "Unknown --fs value" err ; then
2023-10-02 15:08:33 +03:00
case " $i " in
2023-10-05 00:54:07 +03:00
# ATM fsadm is required instead of '-r' option with reiserfs
2023-10-02 15:08:33 +03:00
*reiserfs) USE_NOT = "not" ; ;
esac
2023-10-05 00:54:07 +03:00
fi
2023-10-02 15:08:33 +03:00
$USE_NOT lvresize -y -L+10M -r $vg_lv
2017-05-22 15:43:30 +03:00
2017-05-31 14:23:34 +03:00
aux udev_wait
2017-05-22 15:43:30 +03:00
umount " $mount_dolar_dir "
lvremove -ff $vg
done
vgremove -ff $vg