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
2012-03-16 17:00:05 +04:00
aux lvmconf 'devices/md_component_detection = 1'
2019-09-11 21:26:41 +03:00
aux extend_filter_md "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)
2021-03-22 23:45:39 +03:00
aux mdadm_create --metadata= 1.0 --level= 0 --chunk= 64 --raid-devices= 2 " $dev1 " " $dev2 "
mddev = $( < MD_DEV)
2015-04-25 01:38:06 +03:00
2019-09-11 21:26:41 +03:00
pvdev = " $mddev "
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
2019-09-11 21:26:41 +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 "
2019-09-11 21:26:41 +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
2021-03-22 23:45:39 +03:00
aux cleanup_md_dev
2019-10-02 22:11:08 +03:00
aux wipefs_a " $dev1 "
aux wipefs_a " $dev2 "
2019-09-11 21:26:41 +03:00
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
2019-09-11 21:26:41 +03:00
2021-03-22 23:45:39 +03:00
aux mdadm_create --metadata= 1.0 --level 0 --chunk= 1024 --raid-devices= 2 " $dev1 " " $dev2 "
mddev = $( < MD_DEV)
2019-09-11 21:26:41 +03:00
pvdev = " $mddev "
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"
2019-09-11 21:26:41 +03:00
2021-03-22 23:45:39 +03:00
aux cleanup_md_dev
2019-10-02 22:11:08 +03:00
aux wipefs_a " $dev1 "
aux wipefs_a " $dev2 "
2010-08-21 19:43:45 +04:00
fi