summaryrefslogtreecommitdiff
path: root/test/shell/integrity-blocksize.sh
blob: 9fd77086f9cd4d83fed104f7712a632a89fd38b4 (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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#!/usr/bin/env bash

# Copyright (C) 2018 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

SKIP_WITH_LVMPOLLD=1

. lib/inittest

aux have_integrity 1 5 0 || skip

losetup -h | grep sector-size || skip


cleanup_mounted_and_teardown()
{
	umount "$mnt" || true
	vgremove -ff $vg1 $vg2 || true

	test -n "${LOOP1-}" && { losetup -d "$LOOP1" || true ; }
	test -n "${LOOP2-}" && { losetup -d "$LOOP2" || true ; }
	test -n "${LOOP3-}" && { losetup -d "$LOOP3" || true ; }
	test -n "${LOOP4-}" && { losetup -d "$LOOP4" || true ; }

	rm -f loop[abcd]
	aux teardown
}

mnt="mnt"
mkdir -p $mnt

# Tests with fs block sizes require a libblkid version that shows BLOCK_SIZE
aux prepare_devs 1
vgcreate $vg "$dev1"
lvcreate -n $lv1 -l8 $vg
mkfs.ext4 "$DM_DEV_DIR/$vg/$lv1"
blkid -p "$DM_DEV_DIR/$vg/$lv1" | grep BLOCK_SIZE || skip
lvchange -an $vg
vgremove -ff $vg

trap 'cleanup_mounted_and_teardown' EXIT

# Currently (5.9-rc5 hits  'blkdev_issue_discard()' kernel WARNING)
#truncate -s 64M loopa
#truncate -s 64M loopb
#truncate -s 64M loopc
#truncate -s 64M loopd

dd if=/dev/zero of=loopa bs=1M count=64 conv=fdatasync
dd if=/dev/zero of=loopb bs=1M count=64 conv=fdatasync
dd if=/dev/zero of=loopc bs=1M count=64 conv=fdatasync
dd if=/dev/zero of=loopd bs=1M count=64 conv=fdatasync

LOOP1=$(losetup -f loopa --show) || skip "Cannot find free loop device"
LOOP2=$(losetup -f loopb --show) || skip "Cannot find free loop device"
LOOP3=$(losetup -f loopc --sector-size 4096 --show) || skip "Loop cannot handle --sector-size 4096"
LOOP4=$(losetup -f loopd --sector-size 4096 --show) || skip "Loop cannot handle --sector-size 4096"

echo "$LOOP1"
echo "$LOOP2"
echo "$LOOP3"
echo "$LOOP4"

aux extend_filter "a|$LOOP1|" "a|$LOOP2|" "a|$LOOP3|" "a|$LOOP4|"
aux extend_devices "$LOOP1" "$LOOP2" "$LOOP3" "$LOOP4"

aux lvmconf 'devices/scan = "/dev"'

vgcreate $vg1 "$LOOP1" "$LOOP2"
vgcreate $vg2 "$LOOP3" "$LOOP4"

# LOOP1/LOOP2 have LBS 512 and PBS 512
# LOOP3/LOOP4 have LBS 4K and PBS 4K

blockdev --getss "$LOOP1"
blockdev --getpbsz "$LOOP1"
blockdev --getss "$LOOP2"
blockdev --getpbsz "$LOOP2"
blockdev --getss "$LOOP3"
blockdev --getpbsz "$LOOP3"
blockdev --getss "$LOOP4"
blockdev --getpbsz "$LOOP4"

# lvcreate on dev512, result 512
lvcreate --type raid1 -m1 --raidintegrity y -l 8 -n $lv1 $vg1
pvck --dump metadata "$LOOP1" | grep 'block_size = 512'
lvremove -y $vg1/$lv1

# lvcreate on dev4k, result 4k
lvcreate --type raid1 -m1 --raidintegrity y -l 8 -n $lv1 $vg2
pvck --dump metadata "$LOOP3" | grep 'block_size = 4096'
lvremove -y $vg2/$lv1

# lvcreate --bs 512 on dev4k, result fail
not lvcreate --type raid1 -m1 --raidintegrity y --raidintegrityblocksize 512 -l 8 -n $lv1 $vg2

# lvcreate --bs 4096 on dev512, result 4k
lvcreate --type raid1 -m1 --raidintegrity y --raidintegrityblocksize 4096 -l 8 -n $lv1 $vg1
lvs -o raidintegrityblocksize $vg1/$lv1 | grep 4096
pvck --dump metadata "$LOOP1" | grep 'block_size = 4096'
lvremove -y $vg1/$lv1

# Test an unknown fs block size by simply not creating a fs on the lv.

# lvconvert on dev512, fsunknown, result 512
lvcreate --type raid1 -m1 -l 8 -n $lv1 $vg1
# clear any residual fs so that libblkid cannot find an fs block size
aux wipefs_a /dev/$vg1/$lv1
lvconvert --raidintegrity y $vg1/$lv1
pvck --dump metadata "$LOOP1" | grep 'block_size = 512'
lvremove -y $vg1/$lv1

# lvconvert on dev4k, fsunknown, result 4k
lvcreate --type raid1 -m1 -l 8 -n $lv1 $vg2
# clear any residual fs so that libblkid cannot find an fs block size
aux wipefs_a /dev/$vg2/$lv1
lvconvert --raidintegrity y $vg2/$lv1
pvck --dump metadata $LOOP3 | grep 'block_size = 4096'
lvremove -y $vg2/$lv1

# lvconvert --bs 4k on dev512, fsunknown, result fail
lvcreate --type raid1 -m1 -l 8 -n $lv1 $vg1
# clear any residual fs so that libblkid cannot find an fs block size
aux wipefs_a /dev/$vg1/$lv1
not lvconvert --raidintegrity y --raidintegrityblocksize 4096 $vg1/$lv1
lvremove -y $vg1/$lv1

# lvconvert --bs 512 on dev4k, fsunknown, result fail
lvcreate --type raid1 -m1 -l 8 -n $lv1 $vg2
# clear any residual fs so that libblkid cannot find an fs block size
aux wipefs_a /dev/$vg2/$lv1
not lvconvert --raidintegrity y --raidintegrityblocksize 512 $vg2/$lv1
lvremove -y $vg2/$lv1

# lvconvert on dev512, ext4 1024, result 1024
lvcreate --type raid1 -m1 -l 8 -n $lv1 $vg1
aux wipefs_a /dev/$vg1/$lv1
mkfs.ext4 "$DM_DEV_DIR/$vg1/$lv1"
blkid -p "$DM_DEV_DIR/$vg1/$lv1" | tee out
grep BLOCK_SIZE=\"1024\" out
lvconvert --raidintegrity y $vg1/$lv1
blkid -p "$DM_DEV_DIR/$vg1/$lv1" | grep BLOCK_SIZE=\"1024\"
mount "$DM_DEV_DIR/$vg1/$lv1" $mnt
umount $mnt
pvck --dump metadata "$LOOP1" | grep 'block_size = 512'
lvremove -y $vg1/$lv1

# lvconvert on dev4k, ext4 4096, result 4096
lvcreate --type raid1 -m1 -l 8 -n $lv1 $vg2
aux wipefs_a /dev/$vg2/$lv1
mkfs.ext4 "$DM_DEV_DIR/$vg2/$lv1"
blkid -p "$DM_DEV_DIR/$vg2/$lv1" | grep BLOCK_SIZE=\"4096\"
lvconvert --raidintegrity y $vg2/$lv1
blkid -p "$DM_DEV_DIR/$vg2/$lv1" | grep BLOCK_SIZE=\"4096\"
mount "$DM_DEV_DIR/$vg2/$lv1" $mnt
umount $mnt
pvck --dump metadata $LOOP3 | grep 'block_size = 4096'
lvremove -y $vg2/$lv1

# lvconvert on dev512, ext4 1024, result 1024 (LV active when adding)
lvcreate --type raid1 -m1 -l 8 -n $lv1 $vg1
aux wipefs_a /dev/$vg1/$lv1
mkfs.ext4 -b 1024 "$DM_DEV_DIR/$vg1/$lv1"
blkid -p "$DM_DEV_DIR/$vg1/$lv1" | grep BLOCK_SIZE=\"1024\"
lvconvert --raidintegrity y $vg1/$lv1
blkid -p "$DM_DEV_DIR/$vg1/$lv1" | grep BLOCK_SIZE=\"1024\"
mount "$DM_DEV_DIR/$vg1/$lv1" $mnt
umount $mnt
pvck --dump metadata "$LOOP1" | grep 'block_size = 512'
lvremove -y $vg1/$lv1

# lvconvert on dev512, ext4 1024, result 1024 (LV inactive when adding)
lvcreate --type raid1 -m1 -l 8 -n $lv1 $vg1
aux wipefs_a /dev/$vg1/$lv1
mkfs.ext4 -b 1024 "$DM_DEV_DIR/$vg1/$lv1"
blkid -p "$DM_DEV_DIR/$vg1/$lv1" | grep BLOCK_SIZE=\"1024\"
lvchange -an $vg1/$lv1
lvconvert --raidintegrity y $vg1/$lv1
lvchange -ay $vg1/$lv1
blkid -p "$DM_DEV_DIR/$vg1/$lv1" | grep BLOCK_SIZE=\"1024\"
mount "$DM_DEV_DIR/$vg1/$lv1" $mnt
umount $mnt
pvck --dump metadata "$LOOP1" | grep 'block_size = 1024'
lvremove -y $vg1/$lv1

# lvconvert on dev4k, ext4 4096, result 4096
lvcreate --type raid1 -m1 -l 8 -n $lv1 $vg2
aux wipefs_a /dev/$vg2/$lv1
mkfs.ext4 "$DM_DEV_DIR/$vg2/$lv1"
blkid -p "$DM_DEV_DIR/$vg2/$lv1" | grep BLOCK_SIZE=\"4096\"
lvconvert --raidintegrity y $vg2/$lv1
blkid -p "$DM_DEV_DIR/$vg2/$lv1" | grep BLOCK_SIZE=\"4096\"
mount "$DM_DEV_DIR/$vg2/$lv1" $mnt
umount $mnt
pvck --dump metadata "$LOOP3" | grep 'block_size = 4096'
lvremove -y $vg2/$lv1

# lvconvert --bs 512 on dev512, ext4 4096, result 512
lvcreate --type raid1 -m1 -l 8 -n $lv1 $vg1
aux wipefs_a /dev/$vg1/$lv1
mkfs.ext4 -b 4096 "$DM_DEV_DIR/$vg1/$lv1"
blkid -p "$DM_DEV_DIR/$vg1/$lv1" | grep BLOCK_SIZE=\"4096\"
lvconvert --raidintegrity y --raidintegrityblocksize 512 $vg1/$lv1
lvs -o raidintegrityblocksize $vg1/$lv1 | grep 512
blkid -p "$DM_DEV_DIR/$vg1/$lv1" | grep BLOCK_SIZE=\"4096\"
mount "$DM_DEV_DIR/$vg1/$lv1" $mnt
umount $mnt
pvck --dump metadata "$LOOP1" | grep 'block_size = 512'
lvremove -y $vg1/$lv1

# lvconvert --bs 1024 on dev512, ext4 4096, result 1024
lvcreate --type raid1 -m1 -l 8 -n $lv1 $vg1
aux wipefs_a /dev/$vg1/$lv1
mkfs.ext4 -b 4096 "$DM_DEV_DIR/$vg1/$lv1"
blkid -p "$DM_DEV_DIR/$vg1/$lv1" | grep BLOCK_SIZE=\"4096\"
lvchange -an $vg1/$lv1
# lv needs to be inactive to increase LBS from 512
lvconvert --raidintegrity y --raidintegrityblocksize 1024 $vg1/$lv1
lvs -o raidintegrityblocksize $vg1/$lv1 | grep 1024
lvchange -ay $vg1/$lv1
blkid -p "$DM_DEV_DIR/$vg1/$lv1" | grep BLOCK_SIZE=\"4096\"
mount "$DM_DEV_DIR/$vg1/$lv1" $mnt
umount $mnt
pvck --dump metadata "$LOOP1" | grep 'block_size = 1024'
lvremove -y $vg1/$lv1

# lvconvert --bs 512 on dev512, ext4 1024, result 512
lvcreate --type raid1 -m1 -l 8 -n $lv1 $vg1
aux wipefs_a /dev/$vg1/$lv1
mkfs.ext4 -b 1024 "$DM_DEV_DIR/$vg1/$lv1"
blkid -p "$DM_DEV_DIR/$vg1/$lv1" | grep BLOCK_SIZE=\"1024\"
lvconvert --raidintegrity y --raidintegrityblocksize 512 $vg1/$lv1
blkid -p "$DM_DEV_DIR/$vg1/$lv1" | grep BLOCK_SIZE=\"1024\"
mount "$DM_DEV_DIR/$vg1/$lv1" $mnt
umount $mnt
pvck --dump metadata "$LOOP1" | grep 'block_size = 512'
lvremove -y $vg1/$lv1

# lvconvert --bs 512 on dev4k, ext4 4096, result fail
lvcreate --type raid1 -m1 -l 8 -n $lv1 $vg2
aux wipefs_a /dev/$vg2/$lv1
mkfs.ext4 "$DM_DEV_DIR/$vg2/$lv1"
not lvconvert --raidintegrity y --raidintegrityblocksize 512 $vg2/$lv1
lvremove -y $vg2/$lv1

# TODO: need to use scsi_debug to create devs with LBS 512 PBS 4k
# TODO: lvconvert, fsunknown, LBS 512, PBS 4k: result 512
# TODO: lvconvert --bs 512, fsunknown, LBS 512, PBS 4k: result 512
# TODO: lvconvert --bs 4k, fsunknown, LBS 512, PBS 4k: result 4k

# lvconvert on dev512, ext4 1024, result 1024, (detect fs with LV inactive)
lvcreate --type raid1 -m1 -l 8 -n $lv1 $vg1
aux wipefs_a /dev/$vg1/$lv1
mkfs.ext4 "$DM_DEV_DIR/$vg1/$lv1"
mount "$DM_DEV_DIR/$vg1/$lv1" $mnt
echo "test" > $mnt/test
umount $mnt
blkid -p "$DM_DEV_DIR/$vg1/$lv1" | grep BLOCK_SIZE=\"1024\"
lvchange -an $vg1/$lv1
lvconvert --raidintegrity y $vg1/$lv1
lvchange -ay $vg1/$lv1
mount "$DM_DEV_DIR/$vg1/$lv1" $mnt
cat $mnt/test
umount $mnt
blkid -p "$DM_DEV_DIR/$vg1/$lv1" | grep BLOCK_SIZE=\"1024\"
pvck --dump metadata "$LOOP1" | tee out
grep 'block_size = 1024' out
lvchange -an $vg1/$lv1
lvremove -y $vg1/$lv1

# lvconvert on dev4k, ext4 4096, result 4096 (detect fs with LV inactive)
lvcreate --type raid1 -m1 -l 8 -n $lv1 $vg2
aux wipefs_a /dev/$vg2/$lv1
mkfs.ext4 "$DM_DEV_DIR/$vg2/$lv1"
mount "$DM_DEV_DIR/$vg2/$lv1" $mnt
echo "test" > $mnt/test
umount $mnt
blkid -p "$DM_DEV_DIR/$vg2/$lv1" | grep BLOCK_SIZE=\"4096\"
lvchange -an $vg2/$lv1
lvconvert --raidintegrity y $vg2/$lv1
lvchange -ay $vg2/$lv1
mount "$DM_DEV_DIR/$vg2/$lv1" $mnt
cat $mnt/test
umount $mnt
blkid -p "$DM_DEV_DIR/$vg2/$lv1" | grep BLOCK_SIZE=\"4096\"
pvck --dump metadata "$LOOP3" | tee out
grep 'block_size = 4096' out
lvchange -an $vg2/$lv1
lvremove -y $vg2/$lv1

# remove of $vg1, $vg2 and loops in cleanup_mounted_and_teardown()