summaryrefslogtreecommitdiff
path: root/test/shell/fsadm-renamed.sh
blob: 698b143cfbd4d443dce63aa2eb1291afd5aa55b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env bash

# 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'

SKIP_WITH_LVMPOLLD=1

. lib/inittest

aux prepare_vg 1 700

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
}

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."
	}
}

# 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

lvcreate -n $lv1 -L300M $vg

case "$i" in
*ext3)		MKFS_ARGS="-b1024 -j" ;;
*xfs)		MKFS_ARGS="-l internal,size=64m -f" ;;
*reiserfs)	MKFS_ARGS="-s 513 -f" ;;
esac

echo "$i"
"$i" $MKFS_ARGS "$dev_vg_lv"

# Adding couple udev wait ops as some older systemd
# might get confused and was 'randomly/racy' umounting
# devices  just mounted.
# 
# See for explanation: 
#   https://github.com/systemd/systemd/commit/628c89cc68ab96fce2de7ebba5933725d147aecc
#   https://github.com/systemd/systemd/pull/2017
aux udev_wait

# mount /dev/test/lv1 on /mnt
mount "$dev_vg_lv" "$mount_dir"

aux udev_wait

# 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.
lvrename $vg_lv $vg_lv_ren

check_mounted

# fails on renamed LV
# 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.
fail lvresize -y -L+10M -r $vg_lv_ren

# fails on unknown mountpoint  (FIXME: umount)
not umount "$dev_vg_lv"

# create a new LV with the previous name of the renamed lv
lvcreate -L300 -n $lv1 $vg
"$i" $MKFS_ARGS "$dev_vg_lv"

aux udev_wait

# 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
mount "$dev_vg_lv" "$mount_dolar_dir"

check_mounted

# 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.
not lvresize -L+10M -r $vg_lv_ren

umount "$mount_dir"

lvresize -y -L+10M -r $vg_lv

aux udev_wait

umount "$mount_dolar_dir"

lvremove -ff $vg

done

vgremove -ff $vg