2019-11-21 01:07:27 +03:00
#!/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
2020-09-18 01:31:11 +03:00
cleanup_mounted_and_teardown( )
{
umount " $mnt " || true
vgremove -ff $vg1 $vg2 || true
2020-09-20 01:32:26 +03:00
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]
2020-09-18 01:31:11 +03:00
aux teardown
}
2020-09-18 22:59:24 +03:00
mnt = "mnt"
mkdir -p $mnt
2020-09-18 01:31:11 +03:00
2019-11-21 01:07:27 +03:00
# 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
2023-04-21 23:28:32 +03:00
mkfs.ext4 " $DM_DEV_DIR / $vg / $lv1 "
2022-09-09 23:16:56 +03:00
blkid -p " $DM_DEV_DIR / $vg / $lv1 " | grep BLOCK_SIZE || skip
2019-11-21 01:07:27 +03:00
lvchange -an $vg
vgremove -ff $vg
2020-09-18 01:31:11 +03:00
trap 'cleanup_mounted_and_teardown' EXIT
2020-09-20 00:25:11 +03:00
# 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
2022-09-06 19:47:03 +03:00
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
2020-09-20 00:25:11 +03:00
2020-09-20 01:32:26 +03:00
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"
2019-11-21 01:07:27 +03:00
2023-04-21 23:28:32 +03:00
echo " $LOOP1 "
echo " $LOOP2 "
echo " $LOOP3 "
echo " $LOOP4 "
2019-11-21 01:07:27 +03:00
2023-04-21 23:28:32 +03:00
aux extend_filter " a| $LOOP1 | " " a| $LOOP2 | " " a| $LOOP3 | " " a| $LOOP4 | "
aux extend_devices " $LOOP1 " " $LOOP2 " " $LOOP3 " " $LOOP4 "
2019-11-21 01:07:27 +03:00
aux lvmconf 'devices/scan = "/dev"'
2023-04-21 23:28:32 +03:00
vgcreate $vg1 " $LOOP1 " " $LOOP2 "
vgcreate $vg2 " $LOOP3 " " $LOOP4 "
2019-11-21 01:07:27 +03:00
2020-06-15 22:08:28 +03:00
# LOOP1/LOOP2 have LBS 512 and PBS 512
# LOOP3/LOOP4 have LBS 4K and PBS 4K
2023-04-21 23:28:32 +03:00
blockdev --getss " $LOOP1 "
blockdev --getpbsz " $LOOP1 "
blockdev --getss " $LOOP2 "
blockdev --getpbsz " $LOOP2 "
blockdev --getss " $LOOP3 "
blockdev --getpbsz " $LOOP3 "
blockdev --getss " $LOOP4 "
blockdev --getpbsz " $LOOP4 "
2020-06-15 22:08:28 +03:00
2019-11-21 01:07:27 +03:00
# lvcreate on dev512, result 512
lvcreate --type raid1 -m1 --raidintegrity y -l 8 -n $lv1 $vg1
2023-04-21 23:28:32 +03:00
pvck --dump metadata " $LOOP1 " | grep 'block_size = 512'
2019-11-21 01:07:27 +03:00
lvremove -y $vg1 /$lv1
# lvcreate on dev4k, result 4k
lvcreate --type raid1 -m1 --raidintegrity y -l 8 -n $lv1 $vg2
2023-04-21 23:28:32 +03:00
pvck --dump metadata " $LOOP3 " | grep 'block_size = 4096'
2019-11-21 01:07:27 +03:00
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
2020-09-02 01:07:36 +03:00
lvs -o raidintegrityblocksize $vg1 /$lv1 | grep 4096
2023-04-21 23:28:32 +03:00
pvck --dump metadata " $LOOP1 " | grep 'block_size = 4096'
2019-11-21 01:07:27 +03:00
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
2023-06-20 22:19:43 +03:00
aux wipefs_a " $DM_DEV_DIR / $vg1 / $lv1 "
2019-11-21 01:07:27 +03:00
lvconvert --raidintegrity y $vg1 /$lv1
2023-04-21 23:28:32 +03:00
pvck --dump metadata " $LOOP1 " | grep 'block_size = 512'
2019-11-21 01:07:27 +03:00
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
2023-06-20 22:19:43 +03:00
aux wipefs_a " $DM_DEV_DIR // $vg2 / $lv1 "
2019-11-21 01:07:27 +03:00
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
2023-06-20 22:19:43 +03:00
aux wipefs_a " $DM_DEV_DIR // $vg1 / $lv1 "
2019-11-21 01:07:27 +03:00
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
2023-06-20 22:19:43 +03:00
aux wipefs_a " $DM_DEV_DIR // $vg2 / $lv1 "
2019-11-21 01:07:27 +03:00
not lvconvert --raidintegrity y --raidintegrityblocksize 512 $vg2 /$lv1
lvremove -y $vg2 /$lv1
2023-04-21 23:28:32 +03:00
# lvconvert on dev512, ext4 1024, result 1024
2019-11-21 01:07:27 +03:00
lvcreate --type raid1 -m1 -l 8 -n $lv1 $vg1
2023-06-20 22:19:43 +03:00
aux wipefs_a " $DM_DEV_DIR // $vg1 / $lv1 "
2023-04-21 23:28:32 +03:00
mkfs.ext4 " $DM_DEV_DIR / $vg1 / $lv1 "
blkid -p " $DM_DEV_DIR / $vg1 / $lv1 " | tee out
grep BLOCK_SIZE = \" 1024\" out
2019-11-21 01:07:27 +03:00
lvconvert --raidintegrity y $vg1 /$lv1
2023-04-21 23:28:32 +03:00
blkid -p " $DM_DEV_DIR / $vg1 / $lv1 " | grep BLOCK_SIZE = \" 1024\"
2020-06-11 20:46:47 +03:00
mount " $DM_DEV_DIR / $vg1 / $lv1 " $mnt
umount $mnt
2023-04-21 23:28:32 +03:00
pvck --dump metadata " $LOOP1 " | grep 'block_size = 512'
2019-11-21 01:07:27 +03:00
lvremove -y $vg1 /$lv1
2023-04-21 23:28:32 +03:00
# lvconvert on dev4k, ext4 4096, result 4096
2019-11-21 01:07:27 +03:00
lvcreate --type raid1 -m1 -l 8 -n $lv1 $vg2
2023-06-20 22:19:43 +03:00
aux wipefs_a " $DM_DEV_DIR / $vg2 / $lv1 "
2023-04-21 23:28:32 +03:00
mkfs.ext4 " $DM_DEV_DIR / $vg2 / $lv1 "
2022-09-09 23:16:56 +03:00
blkid -p " $DM_DEV_DIR / $vg2 / $lv1 " | grep BLOCK_SIZE = \" 4096\"
2019-11-21 01:07:27 +03:00
lvconvert --raidintegrity y $vg2 /$lv1
2022-09-09 23:16:56 +03:00
blkid -p " $DM_DEV_DIR / $vg2 / $lv1 " | grep BLOCK_SIZE = \" 4096\"
2020-06-11 20:46:47 +03:00
mount " $DM_DEV_DIR / $vg2 / $lv1 " $mnt
umount $mnt
2019-11-21 01:07:27 +03:00
pvck --dump metadata $LOOP3 | grep 'block_size = 4096'
lvremove -y $vg2 /$lv1
2020-06-16 19:59:59 +03:00
# lvconvert on dev512, ext4 1024, result 1024 (LV active when adding)
2019-11-21 01:07:27 +03:00
lvcreate --type raid1 -m1 -l 8 -n $lv1 $vg1
2023-06-20 22:19:43 +03:00
aux wipefs_a " $DM_DEV_DIR // $vg1 / $lv1 "
2019-11-21 01:07:27 +03:00
mkfs.ext4 -b 1024 " $DM_DEV_DIR / $vg1 / $lv1 "
2022-09-09 23:16:56 +03:00
blkid -p " $DM_DEV_DIR / $vg1 / $lv1 " | grep BLOCK_SIZE = \" 1024\"
2019-11-21 01:07:27 +03:00
lvconvert --raidintegrity y $vg1 /$lv1
2022-09-09 23:16:56 +03:00
blkid -p " $DM_DEV_DIR / $vg1 / $lv1 " | grep BLOCK_SIZE = \" 1024\"
2020-06-11 20:46:47 +03:00
mount " $DM_DEV_DIR / $vg1 / $lv1 " $mnt
umount $mnt
2023-04-21 23:28:32 +03:00
pvck --dump metadata " $LOOP1 " | grep 'block_size = 512'
2020-06-16 19:59:59 +03:00
lvremove -y $vg1 /$lv1
# lvconvert on dev512, ext4 1024, result 1024 (LV inactive when adding)
lvcreate --type raid1 -m1 -l 8 -n $lv1 $vg1
2023-06-20 22:19:43 +03:00
aux wipefs_a " $DM_DEV_DIR // $vg1 / $lv1 "
2020-06-16 19:59:59 +03:00
mkfs.ext4 -b 1024 " $DM_DEV_DIR / $vg1 / $lv1 "
2022-09-09 23:16:56 +03:00
blkid -p " $DM_DEV_DIR / $vg1 / $lv1 " | grep BLOCK_SIZE = \" 1024\"
2020-06-16 19:59:59 +03:00
lvchange -an $vg1 /$lv1
lvconvert --raidintegrity y $vg1 /$lv1
lvchange -ay $vg1 /$lv1
2022-09-09 23:16:56 +03:00
blkid -p " $DM_DEV_DIR / $vg1 / $lv1 " | grep BLOCK_SIZE = \" 1024\"
2020-06-16 19:59:59 +03:00
mount " $DM_DEV_DIR / $vg1 / $lv1 " $mnt
umount $mnt
2023-04-21 23:28:32 +03:00
pvck --dump metadata " $LOOP1 " | grep 'block_size = 1024'
2019-11-21 01:07:27 +03:00
lvremove -y $vg1 /$lv1
# lvconvert on dev4k, ext4 4096, result 4096
lvcreate --type raid1 -m1 -l 8 -n $lv1 $vg2
2023-06-20 22:19:43 +03:00
aux wipefs_a " $DM_DEV_DIR // $vg2 / $lv1 "
2019-11-21 01:07:27 +03:00
mkfs.ext4 " $DM_DEV_DIR / $vg2 / $lv1 "
2022-09-09 23:16:56 +03:00
blkid -p " $DM_DEV_DIR / $vg2 / $lv1 " | grep BLOCK_SIZE = \" 4096\"
2019-11-21 01:07:27 +03:00
lvconvert --raidintegrity y $vg2 /$lv1
2022-09-09 23:16:56 +03:00
blkid -p " $DM_DEV_DIR / $vg2 / $lv1 " | grep BLOCK_SIZE = \" 4096\"
2020-06-11 20:46:47 +03:00
mount " $DM_DEV_DIR / $vg2 / $lv1 " $mnt
umount $mnt
2023-04-21 23:28:32 +03:00
pvck --dump metadata " $LOOP3 " | grep 'block_size = 4096'
2019-11-21 01:07:27 +03:00
lvremove -y $vg2 /$lv1
2024-04-16 22:14:26 +03:00
dm_table | grep ${ PREFIX }
2023-04-21 23:28:32 +03:00
# lvconvert --bs 512 on dev512, ext4 4096, result 512
2019-11-21 01:07:27 +03:00
lvcreate --type raid1 -m1 -l 8 -n $lv1 $vg1
2023-06-20 22:19:43 +03:00
aux wipefs_a " $DM_DEV_DIR // $vg1 / $lv1 "
2023-04-21 23:28:32 +03:00
mkfs.ext4 -b 4096 " $DM_DEV_DIR / $vg1 / $lv1 "
2022-09-09 23:16:56 +03:00
blkid -p " $DM_DEV_DIR / $vg1 / $lv1 " | grep BLOCK_SIZE = \" 4096\"
2019-11-21 01:07:27 +03:00
lvconvert --raidintegrity y --raidintegrityblocksize 512 $vg1 /$lv1
2020-09-02 01:07:36 +03:00
lvs -o raidintegrityblocksize $vg1 /$lv1 | grep 512
2022-09-09 23:16:56 +03:00
blkid -p " $DM_DEV_DIR / $vg1 / $lv1 " | grep BLOCK_SIZE = \" 4096\"
2020-06-11 20:46:47 +03:00
mount " $DM_DEV_DIR / $vg1 / $lv1 " $mnt
umount $mnt
2023-04-21 23:28:32 +03:00
pvck --dump metadata " $LOOP1 " | grep 'block_size = 512'
2019-11-21 01:07:27 +03:00
lvremove -y $vg1 /$lv1
2023-04-21 23:28:32 +03:00
# lvconvert --bs 1024 on dev512, ext4 4096, result 1024
2020-06-15 22:08:28 +03:00
lvcreate --type raid1 -m1 -l 8 -n $lv1 $vg1
2023-06-20 22:19:43 +03:00
aux wipefs_a " $DM_DEV_DIR // $vg1 / $lv1 "
2023-04-21 23:28:32 +03:00
mkfs.ext4 -b 4096 " $DM_DEV_DIR / $vg1 / $lv1 "
2022-09-09 23:16:56 +03:00
blkid -p " $DM_DEV_DIR / $vg1 / $lv1 " | grep BLOCK_SIZE = \" 4096\"
2020-06-15 22:08:28 +03:00
lvchange -an $vg1 /$lv1
2020-06-16 19:59:59 +03:00
# lv needs to be inactive to increase LBS from 512
2020-06-15 22:08:28 +03:00
lvconvert --raidintegrity y --raidintegrityblocksize 1024 $vg1 /$lv1
2020-09-02 01:07:36 +03:00
lvs -o raidintegrityblocksize $vg1 /$lv1 | grep 1024
2020-06-15 22:08:28 +03:00
lvchange -ay $vg1 /$lv1
2022-09-09 23:16:56 +03:00
blkid -p " $DM_DEV_DIR / $vg1 / $lv1 " | grep BLOCK_SIZE = \" 4096\"
2020-06-15 22:08:28 +03:00
mount " $DM_DEV_DIR / $vg1 / $lv1 " $mnt
umount $mnt
2023-04-21 23:28:32 +03:00
pvck --dump metadata " $LOOP1 " | grep 'block_size = 1024'
2020-06-15 22:08:28 +03:00
lvremove -y $vg1 /$lv1
2019-11-21 01:07:27 +03:00
# lvconvert --bs 512 on dev512, ext4 1024, result 512
lvcreate --type raid1 -m1 -l 8 -n $lv1 $vg1
2023-06-20 22:19:43 +03:00
aux wipefs_a " $DM_DEV_DIR // $vg1 / $lv1 "
2019-11-21 01:07:27 +03:00
mkfs.ext4 -b 1024 " $DM_DEV_DIR / $vg1 / $lv1 "
2022-09-09 23:16:56 +03:00
blkid -p " $DM_DEV_DIR / $vg1 / $lv1 " | grep BLOCK_SIZE = \" 1024\"
2019-11-21 01:07:27 +03:00
lvconvert --raidintegrity y --raidintegrityblocksize 512 $vg1 /$lv1
2022-09-09 23:16:56 +03:00
blkid -p " $DM_DEV_DIR / $vg1 / $lv1 " | grep BLOCK_SIZE = \" 1024\"
2020-06-11 20:46:47 +03:00
mount " $DM_DEV_DIR / $vg1 / $lv1 " $mnt
umount $mnt
2023-04-21 23:28:32 +03:00
pvck --dump metadata " $LOOP1 " | grep 'block_size = 512'
2019-11-21 01:07:27 +03:00
lvremove -y $vg1 /$lv1
# lvconvert --bs 512 on dev4k, ext4 4096, result fail
lvcreate --type raid1 -m1 -l 8 -n $lv1 $vg2
2023-06-20 22:19:43 +03:00
aux wipefs_a " $DM_DEV_DIR // $vg2 / $lv1 "
2019-11-21 01:07:27 +03:00
mkfs.ext4 " $DM_DEV_DIR / $vg2 / $lv1 "
not lvconvert --raidintegrity y --raidintegrityblocksize 512 $vg2 /$lv1
lvremove -y $vg2 /$lv1
2020-06-15 22:08:28 +03:00
# 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
2019-11-21 01:07:27 +03:00
2023-04-21 23:28:32 +03:00
# lvconvert on dev512, ext4 1024, result 1024, (detect fs with LV inactive)
2020-06-11 20:46:47 +03:00
lvcreate --type raid1 -m1 -l 8 -n $lv1 $vg1
2023-06-20 22:19:43 +03:00
aux wipefs_a " $DM_DEV_DIR // $vg1 / $lv1 "
2023-04-21 23:28:32 +03:00
mkfs.ext4 " $DM_DEV_DIR / $vg1 / $lv1 "
2020-06-11 20:46:47 +03:00
mount " $DM_DEV_DIR / $vg1 / $lv1 " $mnt
echo "test" > $mnt /test
umount $mnt
2023-04-21 23:28:32 +03:00
blkid -p " $DM_DEV_DIR / $vg1 / $lv1 " | grep BLOCK_SIZE = \" 1024\"
2020-06-11 20:46:47 +03:00
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
2023-04-21 23:28:32 +03:00
blkid -p " $DM_DEV_DIR / $vg1 / $lv1 " | grep BLOCK_SIZE = \" 1024\"
pvck --dump metadata " $LOOP1 " | tee out
grep 'block_size = 1024' out
2020-06-11 20:46:47 +03:00
lvchange -an $vg1 /$lv1
lvremove -y $vg1 /$lv1
2023-04-21 23:28:32 +03:00
# lvconvert on dev4k, ext4 4096, result 4096 (detect fs with LV inactive)
2020-06-11 20:46:47 +03:00
lvcreate --type raid1 -m1 -l 8 -n $lv1 $vg2
2023-06-20 22:19:43 +03:00
aux wipefs_a " $DM_DEV_DIR // $vg2 / $lv1 "
2023-04-21 23:28:32 +03:00
mkfs.ext4 " $DM_DEV_DIR / $vg2 / $lv1 "
2020-06-11 20:46:47 +03:00
mount " $DM_DEV_DIR / $vg2 / $lv1 " $mnt
echo "test" > $mnt /test
umount $mnt
2022-09-09 23:16:56 +03:00
blkid -p " $DM_DEV_DIR / $vg2 / $lv1 " | grep BLOCK_SIZE = \" 4096\"
2020-06-11 20:46:47 +03:00
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
2022-09-09 23:16:56 +03:00
blkid -p " $DM_DEV_DIR / $vg2 / $lv1 " | grep BLOCK_SIZE = \" 4096\"
2023-04-21 23:28:32 +03:00
pvck --dump metadata " $LOOP3 " | tee out
grep 'block_size = 4096' out
2020-06-11 20:46:47 +03:00
lvchange -an $vg2 /$lv1
lvremove -y $vg2 /$lv1
2020-09-18 01:31:11 +03:00
# remove of $vg1, $vg2 and loops in cleanup_mounted_and_teardown()