summaryrefslogtreecommitdiff
path: root/test/shell/lvcreate-usage.sh
blob: 6d469398fdff20fc57973852b84303c327a7e946 (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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/usr/bin/env bash

# Copyright (C) 2008-2013 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

# 'Exercise some lvcreate diagnostics'

. lib/inittest

aux prepare_pvs 4
get_devs

aux pvcreate --metadatacopies 0 "$dev1"
aux vgcreate $SHARED "$vg" "${DEVICES[@]}"

invalid lvcreate --type free -l1 -n $lv1 $vg 2>err
grep "Invalid argument for --type" err
invalid lvcreate --type $RANDOM -l1 -n $lv1 $vg
invalid lvcreate --type unknown -l1 -n $lv1 $vg

invalid lvcreate -L10000000000000000000 -n $lv $vg 2>&1 | tee err
grep "Size is too big" err
invalid lvcreate -L+-10 -n $lv $vg 2>&1 | tee err
grep "Multiple sign" err
invalid lvcreate -L-.1 -n $lv $vg  2>&1 | tee err
grep "Size may not be negative" err
invalid lvcreate -L..1 -n $lv $vg  2>&1 | tee err
grep "Can't parse size" err

lvcreate --type linear -aey -m0 -l1 -n $lv1 $vg
lvcreate --type snapshot -l1 -n $lv2 $vg/$lv1
# Supporting decimal point with size
lvcreate -L.1 -n $lv3 $vg

# Reject repeated invocation (run 2 times) (bz178216)
lvcreate -n $lv -l 4 $vg
not lvcreate -n $lv -l 4 $vg
lvremove -ff $vg/$lv
# Try to remove it again - should fail (but not segfault)
not lvremove -ff $vg/$lv

# Reject a negative stripe_size
invalid lvcreate -L 64m -n $lv -i2 --stripesize -4 $vg 2>err;
grep "may not be negative" err

# Reject a too-large stripesize
invalid lvcreate -L 64m -n $lv -i2 --stripesize 4294967291 $vg 2>err
grep "Stripe size cannot be larger than" err

# w/single stripe succeeds with diagnostics to stdout
lvcreate -L 64m -n $lv -i1 --stripesize 4 $vg 2> err | tee out
grep "Ignoring stripesize argument with single stripe" out
lvdisplay $vg
lvremove -ff $vg

# w/default (64KB) stripe size succeeds with diagnostics to stdout
lvcreate -L 64m -n $lv -i2 $vg > out
grep "Using default stripesize" out
lvdisplay $vg
check lv_field $vg/$lv stripesize "64.00k"
lvremove -ff $vg

# Reject an invalid number of stripes
invalid lvcreate -L 64m -n $lv -i129 $vg 2>err
grep "Number of stripes (129) must be between 1 and 128" err

# Reject an invalid stripe size
invalid lvcreate -L 64m -n $lv -i2 --stripesize 3 $vg 2>err
grep "Invalid stripe size" err
# Verify that the LV was not created via lvdisplay empty output
test -z "$(lvdisplay $vg)"

# Setting max_lv works. (bz490298)
check vg_field $vg max_lv "0"
vgchange -l 3 $vg
check vg_field $vg max_lv "3"
lvcreate -aey -l1 -n $lv1 $vg
lvcreate -l1 -s -n $lv2 $vg/$lv1
lvcreate -l1 -n $lv3 $vg
fail lvcreate -l1 -n $lv4 $vg
lvremove -ff $vg/$lv3

# Check snapshot of inactive origin
lvchange -an $vg/$lv1
lvcreate -l1 -s -n $lv3 $vg/$lv1
fail lvcreate -l1 -n $lv4 $vg
fail lvcreate -l1 --type mirror -m1 -n $lv4 $vg

lvremove -ff $vg/$lv3
lvcreate -aey -l1 --type mirror -m1 -n $lv3 $vg
not lvcreate -l1 -n $lv4 $vg
not lvcreate -l1 --type mirror -m1 -n $lv4 $vg

lvconvert -m0 $vg/$lv3
lvconvert -m2 --type mirror -i 1 $vg/$lv3
lvconvert -m1 $vg/$lv3

fail vgchange -l 2
check vg_field $vg max_lv "3"
vgchange -l 4
check vg_field $vg max_lv "4"

lvremove -ff $vg
vgchange -l 0 $vg
check vg_field $vg max_lv "0"

# Rejects invalid chunksize, accepts between 4K and 512K
# and validate origin_size
lvcreate -aey -L 32m -n $lv1 $vg
not lvcreate -L 8m -n $lv2 -s --chunksize 3k $vg/$lv1
not lvcreate -L 8m -n $lv2 -s --chunksize 1024k $vg/$lv1
lvcreate -L 8m -n $lv2 -s --chunksize 4k $vg/$lv1
check lv_field $vg/$lv2 chunk_size "4.00k"
check lv_field $vg/$lv2 origin_size "32.00m"
lvcreate -L 8m -n $lv3 -s --chunksize 512k $vg/$lv1
check lv_field $vg/$lv3 chunk_size "512.00k"
check lv_field $vg/$lv3 origin_size "32.00m"
lvremove -f $vg

# Mirror regionsize must be
# - nonzero (bz186013)
# - a power of 2 and a multiple of page size
# - <= size of LV
invalid lvcreate --type mirror -m 1 -L 32m -n $lv -R 0 $vg 2>err
grep "may not be zero" err
invalid lvcreate --type mirror -m 1 -L 32m -n $lv -R 11k $vg
invalid lvcreate --type mirror -m 1 -L 32m -n $lv -R 1k $vg
lvcreate -aey -L 32m -n $lv --regionsize 128m  --type mirror -m 1 $vg
check lv_field $vg/$lv regionsize "32.00m"
lvremove -f $vg
lvcreate -aey -L 32m -n $lv --regionsize 4m --type mirror -m 1 $vg
check lv_field $vg/$lv regionsize "4.00m"

# -m0 is creating non-mirrored segment and give info about redundant option
lvcreate -m 0 -l1 -n $lv1 $vg 2>&1 | tee err
grep "Redundant" err
check lv_field $vg/$lv1 segtype "linear"
lvremove -ff $vg

if test -n "$LVM_TEST_LVMLOCKD"; then
echo "skip snapshot without origin"
else

# Old --type snapshot works with -s
lvcreate --type snapshot -s -V64 -L32 -n $lv1 $vg
check lv_field $vg/$lv1 segtype "linear"
lvcreate --type snapshot -V64 -L32 -n $lv2 $vg
check lv_field $vg/$lv2 segtype "linear"
lvremove -ff $vg

# --virtualoriginsize  always makes old snapshot
lvcreate -s --virtualoriginsize 64m -L 32m -n $lv1 $vg
check lv_field $vg/$lv1 segtype "linear"
lvrename $vg/$lv1 $vg/$lv2
lvcreate -s --virtualoriginsize 64m -L 32m -n $lv1 $vg
lvchange -a n $vg/$lv1
lvremove -ff $vg/$lv1
lvremove -ff $vg

fi

# readahead default (auto), none, #, auto
lvcreate -L 8 -n $lv1 $vg
check lv_field $vg/$lv1 lv_read_ahead "auto"
lvcreate -L 8 -n $lv2 --readahead none $vg
check lv_field $vg/$lv2 lv_read_ahead "0"
check lv_field $vg/$lv2 lv_kernel_read_ahead "0"
lvcreate -L 8 -n $lv3 --readahead 8k $vg
check lv_field $vg/$lv3 lv_read_ahead "8.00k"
check lv_field $vg/$lv3 lv_kernel_read_ahead "8.00k"
lvcreate -L 8 -n $lv4 --readahead auto $vg "$dev1"
check lv_field $vg/$lv4 lv_read_ahead "auto"
# figure RA value of a PV origin device
DEVICE=$(dmsetup deps -o blkdevname "$dev1" | sed -e "s,.*:\ (\(.*\)),/dev/\1,")
RASZ=$(( $(blockdev --getra "$DEVICE" ) / 2 ))
test "$RASZ" -ge 128 || RASZ="128"
check lv_field $vg/$lv4 lv_kernel_read_ahead "${RASZ}.00k" --units k
lvcreate -vvvvv -L 8 -n $lv5 -i2 --stripesize 16k --readahead auto $vg
check lv_field $vg/$lv5 lv_read_ahead "auto"
# For 16k stripe we set '128k' as the is the minimum size we get when creating DM device
check lv_field $vg/$lv5 lv_kernel_read_ahead "128.00k" --units k
lvcreate -L 8 -n $lv6 -i2 --stripesize 128k --readahead auto $vg
check lv_field $vg/$lv6 lv_read_ahead "auto"
# For striped device we set double of strip size unrelated to underlaying dev RA size
check lv_field $vg/$lv6 lv_kernel_read_ahead "512.00k" --units k
lvremove -ff $vg

#
# Validate --major --minor,  we need to know VG, thus failing
#
fail lvcreate -My --major 234 -l1 $vg
# cannot specify --major or --minor with -Mn
fail lvcreate -Mn --major 234 -l1 $vg
fail lvcreate --persistent n --minor 234 -l1 $vg
# out-of-range minor value
fail lvcreate --minor 9999999 -l1 $vg
if aux kernel_at_least 2 4 0; then
# On >2.4 we ignore --major
lvcreate --major 234 -l1 $vg 2>&1 | tee err;
grep "Ignoring" err
# Try some bigger possibly unused minor
if test ! -d /sys/block/dm-2345; then
	lvcreate --minor 2345 -l1 -n $lv1 $vg
	check lv_field $vg/$lv1 lv_kernel_minor "2345"
fi
if test ! -d /sys/block/dm-23456; then
	lvcreate -My --minor 23456 -j 122 -l1 -n $lv2 $vg
	check lv_field $vg/$lv2 lv_kernel_minor "23456"
fi
fi # 2.4
lvremove -f $vg

# prohibited names
for i in pvmove snapshot ; do
	invalid lvcreate -l1 -n ${i}1 $vg
done
for i in _cdata _cmeta _cpool _cvol _mimage _mlog _pmspare _tdata _tmeta _vorigin ; do
	invalid lvcreate -l1 -n s_${i}_1 $vg
done

# Check invalid error for pool-only options
invalid lvcreate --poolmetadataspare y -l1 $vg
invalid lvcreate --poolmetadatasize 10 -l1 $vg
invalid lvcreate --discards passdown -l1 $vg