2017-07-02 22:38:32 +03:00
#!/usr/bin/env bash
2015-04-25 01:38:06 +03:00
# Copyright (C) 2009-2015 Red Hat, Inc. All rights reserved.
2009-08-04 20:02:39 +04:00
#
# 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,
2016-01-21 13:49:46 +03:00
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2009-08-04 20:02:39 +04:00
2018-06-01 00:18:53 +03:00
2015-10-27 17:10:06 +03:00
SKIP_WITH_LVMPOLLD = 1
2012-03-16 17:00:05 +04:00
2015-10-27 17:10:06 +03:00
. lib/inittest
2015-05-09 02:59:18 +03:00
2009-08-04 20:02:39 +04:00
# skip this test if mdadm or sfdisk (or others) aren't available
2012-03-16 17:00:05 +04:00
which sfdisk || skip
2010-01-19 18:59:34 +03:00
test -f /proc/mdstat && grep -q raid0 /proc/mdstat || \
2012-03-16 17:00:05 +04:00
modprobe raid0 || skip
2009-08-04 20:02:39 +04:00
2012-03-16 17:00:05 +04:00
aux lvmconf 'devices/md_component_detection = 1'
2019-06-20 01:03:18 +03:00
aux extend_filter_LVMTEST "a|/dev/md|"
2013-05-27 04:03:00 +04:00
2009-08-04 20:02:39 +04:00
aux prepare_devs 2
# create 2 disk MD raid0 array (stripe_width=128K)
2015-04-25 01:38:06 +03:00
aux prepare_md_dev 0 64 2 " $dev1 " " $dev2 "
mddev = $( < MD_DEV)
pvdev = $( < MD_DEV_PV)
2009-08-04 20:02:39 +04:00
# Test alignment of PV on MD without any MD-aware or topology-aware detection
# - should treat $mddev just like any other block device
pvcreate --metadatasize 128k \
--config 'devices {md_chunk_alignment=0 data_alignment_detection=0 data_alignment_offset_detection=0}' \
2015-04-25 01:38:06 +03:00
" $pvdev "
2013-02-19 04:56:51 +04:00
2015-04-25 01:38:06 +03:00
check pv_field " $pvdev " pe_start "1.00m"
2009-08-04 20:02:39 +04:00
# Test md_chunk_alignment independent of topology-aware detection
pvcreate --metadatasize 128k \
--config 'devices {data_alignment_detection=0 data_alignment_offset_detection=0}' \
2015-04-25 01:38:06 +03:00
" $pvdev "
check pv_field " $pvdev " pe_start "1.00m"
2009-08-04 20:02:39 +04:00
# Test newer topology-aware alignment detection
2010-01-19 18:59:34 +03:00
# - first added to 2.6.31 but not "reliable" until 2.6.33
2015-04-30 14:23:56 +03:00
if aux kernel_at_least 2 6 33 ; then
2010-08-12 08:11:48 +04:00
# optimal_io_size=131072, minimum_io_size=65536
2009-08-04 20:02:39 +04:00
pvcreate --metadatasize 128k \
2015-04-25 01:38:06 +03:00
--config 'devices { md_chunk_alignment=0 }' " $pvdev "
check pv_field " $pvdev " pe_start "1.00m"
2015-05-04 14:07:33 +03:00
pvremove " $pvdev "
2009-08-04 20:02:39 +04:00
fi
# partition MD array directly, depends on blkext in Linux >= 2.6.28
2015-04-30 14:23:56 +03:00
if aux kernel_at_least 2 6 28 ; then
2009-08-04 20:02:39 +04:00
# create one partition
2012-03-20 14:48:59 +04:00
sfdisk " $mddev " <<EOF
2009-08-04 20:02:39 +04:00
,,83
EOF
2015-05-04 14:07:33 +03:00
# Wait till all partition links in udev are created
aux udev_wait
# Skip test if udev rule has not created proper links for partitions
test -b " ${ mddev } p1 " || { ls -laR /dev ; skip "Missing partition link" ; }
2013-02-19 04:56:51 +04:00
pvscan
2009-08-04 20:02:39 +04:00
# make sure partition on MD is _not_ removed
# - tests partition -> parent lookup via sysfs paths
2015-04-25 01:38:06 +03:00
not pvcreate --metadatasize 128k " $pvdev "
2009-08-04 20:02:39 +04:00
# verify alignment_offset is accounted for in pe_start
# - topology infrastructure is available in Linux >= 2.6.31
# - also tests partition -> parent lookup via sysfs paths
# Checking for 'alignment_offset' in sysfs implies Linux >= 2.6.31
2010-08-12 08:56:05 +04:00
# but reliable alignment_offset support requires kernel.org Linux >= 2.6.33
2015-04-30 14:23:56 +03:00
if aux kernel_at_least 2 6 33 ; then
2015-04-25 01:38:06 +03:00
# in case the system is running without devtmpfs /dev
# wait here for created device node on tmpfs
2018-05-24 12:04:38 +03:00
test " $DM_DEV_DIR " = "/dev" || cp -LR " ${ mddev } p1 " " ${ pvdev %/* } "
2015-04-25 01:38:06 +03:00
pvcreate --metadatasize 128k " ${ pvdev } p1 "
maj = $(( $( stat -L --printf= 0x%t " ${ mddev } p1 " ) ))
min = $(( $( stat -L --printf= 0x%T " ${ mddev } p1 " ) ))
2018-05-25 19:14:12 +03:00
ls /sys/dev/block/$maj :$min /
ls /sys/dev/block/$maj :$min /holders/
cat /sys/dev/block/$maj :$min /dev
cat /sys/dev/block/$maj :$min /stat
cat /sys/dev/block/$maj :$min /size
2015-04-25 01:38:06 +03:00
sysfs_alignment_offset = " /sys/dev/block/ $maj : $min /alignment_offset "
[ -f " $sysfs_alignment_offset " ] && \
alignment_offset = $( < " $sysfs_alignment_offset " ) || \
alignment_offset = 0
# default alignment is 1M, add alignment_offset
2017-07-06 20:27:04 +03:00
pv_align = $(( 1048576 + alignment_offset ))
2015-04-25 01:38:06 +03:00
check pv_field " ${ pvdev } p1 " pe_start $pv_align --units b --nosuffix
pvremove " ${ pvdev } p1 "
2018-05-24 12:04:38 +03:00
test " $DM_DEV_DIR " = "/dev" || rm -f " ${ pvdev } p1 "
2010-08-12 08:56:05 +04:00
fi
2009-08-04 20:02:39 +04:00
fi
2010-08-21 19:43:45 +04:00
# Test newer topology-aware alignment detection w/ --dataalignment override
2015-04-30 14:23:56 +03:00
if aux kernel_at_least 2 6 33 ; then
2015-04-23 21:26:19 +03:00
# make sure we're clean for another test
2018-05-24 12:04:38 +03:00
dd if = /dev/zero of = " $mddev " bs = 512 count = 4 conv = fdatasync
partprobe -s " $mddev "
2015-04-25 01:38:06 +03:00
aux prepare_md_dev 0 1024 2 " $dev1 " " $dev2 "
pvdev = $( < MD_DEV_PV)
2010-08-21 19:43:45 +04:00
# optimal_io_size=2097152, minimum_io_size=1048576
pvcreate --metadatasize 128k \
2015-04-25 01:38:06 +03:00
--config 'devices { md_chunk_alignment=0 }' " $pvdev "
2018-05-24 12:04:38 +03:00
# to see the processing of scanning
pvs -vvvv
2015-04-25 01:38:06 +03:00
check pv_field " $pvdev " pe_start "2.00m"
2010-08-21 19:43:45 +04:00
# now verify pe_start alignment override using --dataalignment
pvcreate --dataalignment 64k --metadatasize 128k \
2015-04-25 01:38:06 +03:00
--config 'devices { md_chunk_alignment=0 }' " $pvdev "
check pv_field " $pvdev " pe_start "192.00k"
2010-08-21 19:43:45 +04:00
fi