Home | History | Annotate | Line # | Download | only in test
t-pvcreate-operation-md.sh revision 1.1.1.1
      1  1.1  haad # Copyright (C) 2009 Red Hat, Inc. All rights reserved.
      2  1.1  haad #
      3  1.1  haad # This copyrighted material is made available to anyone wishing to use,
      4  1.1  haad # modify, copy, or redistribute it subject to the terms and conditions
      5  1.1  haad # of the GNU General Public License v.2.
      6  1.1  haad #
      7  1.1  haad # You should have received a copy of the GNU General Public License
      8  1.1  haad # along with this program; if not, write to the Free Software Foundation,
      9  1.1  haad # Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     10  1.1  haad 
     11  1.1  haad # skip this test if mdadm or sfdisk (or others) aren't available
     12  1.1  haad which mdadm || exit 200
     13  1.1  haad which sfdisk || exit 200
     14  1.1  haad which perl || exit 200
     15  1.1  haad which awk || exit 200
     16  1.1  haad which cut || exit 200
     17  1.1  haad test -f /proc/mdstat || exit 200
     18  1.1  haad 
     19  1.1  haad . ./test-utils.sh
     20  1.1  haad 
     21  1.1  haad prepare_lvmconf '[ "a|/dev/md.*|", "a/dev\/mapper\/.*$/", "r/.*/" ]'
     22  1.1  haad aux prepare_devs 2
     23  1.1  haad 
     24  1.1  haad # Have MD use a non-standard name to avoid colliding with an existing MD device
     25  1.1  haad # - mdadm >= 3.0 requires that non-standard device names be in /dev/md/
     26  1.1  haad # - newer mdadm _completely_ defers to udev to create the associated device node
     27  1.1  haad mdadm_maj=$(mdadm --version 2>&1 | perl -pi -e 's|.* v(\d+).*|\1|')
     28  1.1  haad [ $mdadm_maj -ge 3 ] && \
     29  1.1  haad     mddev=/dev/md/md_lvm_test0 || \
     30  1.1  haad     mddev=/dev/md_lvm_test0
     31  1.1  haad 
     32  1.1  haad cleanup_md() {
     33  1.1  haad     # sleeps offer hack to defeat: 'md: md127 still in use'
     34  1.1  haad     # see: https://bugzilla.redhat.com/show_bug.cgi?id=509908#c25
     35  1.1  haad     sleep 2
     36  1.1  haad     mdadm --stop $mddev
     37  1.1  haad     if [ -b "$mddev" ]; then
     38  1.1  haad         # mdadm doesn't always cleanup the device node
     39  1.1  haad 	sleep 2
     40  1.1  haad 	rm -f $mddev
     41  1.1  haad     fi
     42  1.1  haad     teardown_
     43  1.1  haad }
     44  1.1  haad 
     45  1.1  haad # create 2 disk MD raid0 array (stripe_width=128K)
     46  1.1  haad [ -b "$mddev" ] && exit 200
     47  1.1  haad mdadm --create $mddev --auto=md --level 0 --raid-devices=2 --chunk 64 $dev1 $dev2
     48  1.1  haad trap 'aux cleanup_md' EXIT # cleanup this MD device at the end of the test
     49  1.1  haad 
     50  1.1  haad # Test alignment of PV on MD without any MD-aware or topology-aware detection
     51  1.1  haad # - should treat $mddev just like any other block device
     52  1.1  haad pv_align="192.00k"
     53  1.1  haad pvcreate --metadatasize 128k \
     54  1.1  haad     --config 'devices {md_chunk_alignment=0 data_alignment_detection=0 data_alignment_offset_detection=0}' \
     55  1.1  haad     $mddev
     56  1.1  haad check_pv_field_ $mddev pe_start $pv_align
     57  1.1  haad 
     58  1.1  haad # Test md_chunk_alignment independent of topology-aware detection
     59  1.1  haad pv_align="256.00k"
     60  1.1  haad pvcreate --metadatasize 128k \
     61  1.1  haad     --config 'devices {data_alignment_detection=0 data_alignment_offset_detection=0}' \
     62  1.1  haad     $mddev
     63  1.1  haad check_pv_field_ $mddev pe_start $pv_align
     64  1.1  haad 
     65  1.1  haad # Get linux minor version
     66  1.1  haad linux_minor=$(echo `uname -r` | cut -d'.' -f3 | cut -d'-' -f1)
     67  1.1  haad 
     68  1.1  haad # Test newer topology-aware alignment detection
     69  1.1  haad if [ $linux_minor -gt 31 ]; then
     70  1.1  haad     pv_align="256.00k"
     71  1.1  haad     pvcreate --metadatasize 128k \
     72  1.1  haad 	--config 'devices { md_chunk_alignment=0 }' $mddev
     73  1.1  haad     check_pv_field_ $mddev pe_start $pv_align
     74  1.1  haad fi
     75  1.1  haad 
     76  1.1  haad # partition MD array directly, depends on blkext in Linux >= 2.6.28
     77  1.1  haad if [ $linux_minor -gt 27 ]; then
     78  1.1  haad     # create one partition
     79  1.1  haad     sfdisk $mddev <<EOF
     80  1.1  haad ,,83
     81  1.1  haad EOF
     82  1.1  haad     # make sure partition on MD is _not_ removed
     83  1.1  haad     # - tests partition -> parent lookup via sysfs paths
     84  1.1  haad     not pvcreate --metadatasize 128k $mddev
     85  1.1  haad 
     86  1.1  haad     # verify alignment_offset is accounted for in pe_start
     87  1.1  haad     # - topology infrastructure is available in Linux >= 2.6.31
     88  1.1  haad     # - also tests partition -> parent lookup via sysfs paths
     89  1.1  haad 
     90  1.1  haad     # Oh joy: need to lookup /sys/block/md127 rather than /sys/block/md_lvm_test0
     91  1.1  haad     mddev_maj_min=$(ls -lL $mddev | awk '{ print $5 $6 }' | perl -pi -e 's|,|:|')
     92  1.1  haad     mddev_p_sysfs_name=$(echo /sys/dev/block/${mddev_maj_min}/*p1)
     93  1.1  haad     base_mddev_p=`basename $mddev_p_sysfs_name`
     94  1.1  haad     mddev_p=/dev/${base_mddev_p}
     95  1.1  haad 
     96  1.1  haad     # Checking for 'alignment_offset' in sysfs implies Linux >= 2.6.31
     97  1.1  haad     sysfs_alignment_offset=/sys/dev/block/${mddev_maj_min}/${base_mddev_p}/alignment_offset
     98  1.1  haad     [ -f $sysfs_alignment_offset ] && \
     99  1.1  haad 	alignment_offset=`cat $sysfs_alignment_offset` || \
    100  1.1  haad 	alignment_offset=0
    101  1.1  haad 
    102  1.1  haad     if [ "$alignment_offset" = "512" ]; then
    103  1.1  haad 	pv_align="256.50k"
    104  1.1  haad 	pvcreate --metadatasize 128k $mddev_p
    105  1.1  haad 	check_pv_field_ $mddev_p pe_start $pv_align
    106  1.1  haad 	pvremove $mddev_p
    107  1.1  haad     elif [ "$alignment_offset" = "2048" ]; then
    108  1.1  haad 	pv_align="258.00k"
    109  1.1  haad 	pvcreate --metadatasize 128k $mddev_p
    110  1.1  haad 	check_pv_field_ $mddev_p pe_start $pv_align
    111  1.1  haad 	pvremove $mddev_p
    112  1.1  haad     fi
    113  1.1  haad fi
    114