2012-03-16 17:00:05 +04:00
#!/bin/sh
2009-08-04 20:02:39 +04:00
# Copyright (C) 2009 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2014-06-06 19:40:04 +04:00
. lib/inittest
2012-03-16 17:00:05 +04: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 mdadm || skip
which sfdisk || skip
which perl || skip
which awk || skip
which cut || 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'
2013-05-27 04:03:00 +04:00
aux extend_filter_LVMTEST
aux extend_filter "a|/dev/md.*|"
2009-08-04 20:02:39 +04:00
aux prepare_devs 2
# Have MD use a non-standard name to avoid colliding with an existing MD device
# - mdadm >= 3.0 requires that non-standard device names be in /dev/md/
# - newer mdadm _completely_ defers to udev to create the associated device node
mdadm_maj = $( mdadm --version 2>& 1 | perl -pi -e 's|.* v(\d+).*|\1|' )
[ $mdadm_maj -ge 3 ] && \
mddev = /dev/md/md_lvm_test0 || \
mddev = /dev/md_lvm_test0
cleanup_md( ) {
# sleeps offer hack to defeat: 'md: md127 still in use'
# see: https://bugzilla.redhat.com/show_bug.cgi?id=509908#c25
2011-01-28 19:12:45 +03:00
aux udev_wait
2012-03-20 14:48:59 +04:00
mdadm --stop " $mddev " || true
2011-01-28 19:12:45 +03:00
aux udev_wait
2009-08-04 20:02:39 +04:00
if [ -b " $mddev " ] ; then
# mdadm doesn't always cleanup the device node
sleep 2
2012-03-20 14:48:59 +04:00
rm -f " $mddev "
2009-08-04 20:02:39 +04:00
fi
2010-08-21 19:43:45 +04:00
}
cleanup_md_and_teardown( ) {
cleanup_md
2011-01-05 04:04:47 +03:00
aux teardown
2009-08-04 20:02:39 +04:00
}
# create 2 disk MD raid0 array (stripe_width=128K)
2012-03-16 17:00:05 +04:00
test -b " $mddev " && skip
2012-03-20 14:48:59 +04:00
mdadm --create --metadata= 1.0 " $mddev " --auto= md --level 0 --raid-devices= 2 --chunk 64 " $dev1 " " $dev2 "
2011-01-05 04:04:47 +03:00
trap 'cleanup_md_and_teardown' EXIT # cleanup this MD device at the end of the test
2012-03-16 17:00:05 +04:00
test -b " $mddev " || skip
2013-02-19 04:56:51 +04:00
cp -LR " $mddev " " $DM_DEV_DIR " # so that LVM/DM can see the device
lvmdev = " $DM_DEV_DIR /md_lvm_test0 "
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
2010-08-12 08:11:48 +04:00
pv_align = "1.00m"
2009-08-04 20:02:39 +04:00
pvcreate --metadatasize 128k \
--config 'devices {md_chunk_alignment=0 data_alignment_detection=0 data_alignment_offset_detection=0}' \
2013-02-19 04:56:51 +04:00
" $lvmdev "
check pv_field " $lvmdev " pe_start $pv_align
2009-08-04 20:02:39 +04:00
# Test md_chunk_alignment independent of topology-aware detection
2010-08-12 08:11:48 +04:00
pv_align = "1.00m"
2009-08-04 20:02:39 +04:00
pvcreate --metadatasize 128k \
--config 'devices {data_alignment_detection=0 data_alignment_offset_detection=0}' \
2013-02-19 04:56:51 +04:00
" $lvmdev "
check pv_field " $lvmdev " pe_start $pv_align
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
2011-06-09 22:58:00 +04:00
if kernel_at_least 2 6 33 ; then
2010-08-12 08:11:48 +04:00
pv_align = "1.00m"
# optimal_io_size=131072, minimum_io_size=65536
2009-08-04 20:02:39 +04:00
pvcreate --metadatasize 128k \
2013-02-19 04:56:51 +04:00
--config 'devices { md_chunk_alignment=0 }' " $lvmdev "
check pv_field " $lvmdev " pe_start $pv_align
2009-08-04 20:02:39 +04:00
fi
# partition MD array directly, depends on blkext in Linux >= 2.6.28
2011-06-09 22:58:00 +04:00
if 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
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
2013-02-19 04:56:51 +04:00
not pvcreate --metadatasize 128k " $lvmdev "
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
# Oh joy: need to lookup /sys/block/md127 rather than /sys/block/md_lvm_test0
2012-03-20 14:48:59 +04:00
mddev_maj_min = $( ls -lL " $mddev " | awk '{ print $5 $6 }' | perl -pi -e 's|,|:|' )
2009-08-04 20:02:39 +04:00
mddev_p_sysfs_name = $( echo /sys/dev/block/${ mddev_maj_min } /*p1)
base_mddev_p = ` basename $mddev_p_sysfs_name `
mddev_p = /dev/${ base_mddev_p }
2011-01-28 19:12:45 +03:00
# in case the system is running without devtmpfs /dev
# wait here for created device node on tmpfs
2012-03-20 14:48:59 +04:00
aux udev_wait " $mddev_p "
test -b " $mddev_p " || skip
2013-02-19 04:56:51 +04:00
cp -LR " $mddev_p " " $DM_DEV_DIR "
lvmdev_p = " $DM_DEV_DIR / $base_mddev_p "
2011-01-28 19:12:45 +03:00
2009-08-04 20:02:39 +04:00
# 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
2009-08-04 20:02:39 +04:00
sysfs_alignment_offset = /sys/dev/block/${ mddev_maj_min } /${ base_mddev_p } /alignment_offset
2011-06-09 22:58:00 +04:00
[ -f $sysfs_alignment_offset ] && kernel_at_least 2 6 33 && \
2009-08-04 20:02:39 +04:00
alignment_offset = ` cat $sysfs_alignment_offset ` || \
alignment_offset = 0
2011-06-09 22:58:00 +04:00
if [ $alignment_offset -gt 0 ] ; then
2010-08-12 08:56:05 +04:00
# default alignment is 1M, add alignment_offset
pv_align = $(( 1048576 + $alignment_offset )) B
2013-02-19 04:56:51 +04:00
pvcreate --metadatasize 128k " $lvmdev_p "
check pv_field " $lvmdev_p " pe_start $pv_align --units b
pvremove " $lvmdev_p "
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
2015-02-13 16:53:26 +03:00
# make sure we're clean for another test
test -b " $mddev " && cleanup_md
dd if = /dev/zero of = " $dev1 " bs = 512 count = 1
dd if = /dev/zero of = " $dev2 " bs = 512 count = 1
2010-08-21 19:43:45 +04:00
# Test newer topology-aware alignment detection w/ --dataalignment override
2011-06-09 22:58:00 +04:00
if kernel_at_least 2 6 33 ; then
2012-03-16 17:00:05 +04:00
pvcreate -f " $dev1 "
pvcreate -f " $dev2 "
2010-08-21 19:43:45 +04:00
# create 2 disk MD raid0 array (stripe_width=2M)
2012-03-16 17:00:05 +04:00
test -b " $mddev " && skip
2012-03-20 14:48:59 +04:00
mdadm --create --metadata= 1.0 " $mddev " --auto= md --level 0 --raid-devices= 2 --chunk 1024 " $dev1 " " $dev2 "
2012-03-16 17:00:05 +04:00
test -b " $mddev " || skip
2010-08-21 19:43:45 +04:00
# optimal_io_size=2097152, minimum_io_size=1048576
pv_align = "2.00m"
pvcreate --metadatasize 128k \
2013-02-19 04:56:51 +04:00
--config 'devices { md_chunk_alignment=0 }' " $lvmdev "
pvscan # Something is seriously broken.
check pv_field " $lvmdev " pe_start $pv_align
2010-08-21 19:43:45 +04:00
# now verify pe_start alignment override using --dataalignment
pv_align = "192.00k"
pvcreate --dataalignment 64k --metadatasize 128k \
2013-02-19 04:56:51 +04:00
--config 'devices { md_chunk_alignment=0 }' " $lvmdev "
check pv_field " $lvmdev " pe_start $pv_align
2010-08-21 19:43:45 +04:00
fi