import source from lvm2 2.02.79
[external/device-mapper.git] / test / t-topology-support.sh
1 # Copyright (C) 2010 Red Hat, Inc. All rights reserved.
2 #
3 # This copyrighted material is made available to anyone wishing to use,
4 # modify, copy, or redistribute it subject to the terms and conditions
5 # of the GNU General Public License v.2.
6 #
7 # You should have received a copy of the GNU General Public License
8 # along with this program; if not, write to the Free Software Foundation,
9 # Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
10
11 which mkfs.ext3 || exit 200
12
13 # Get linux minor version
14 linux_minor=$(echo `uname -r` | cut -d'.' -f3 | cut -d'-' -f1)
15
16 test $linux_minor -ge 31 || exit 200
17
18 . ./test-utils.sh
19
20 check_logical_block_size()
21 {
22     local DEV_=$1
23     local LOGICAL_BS=$2
24     # Verify logical_block_size - requires Linux >= 2.6.31
25     SYSFS_LOGICAL_BLOCK_SIZE=`echo /sys/block/$(basename $DEV_)/queue/logical_block_size`
26     if [ -f "$SYSFS_LOGICAL_BLOCK_SIZE" ] ; then
27         ACTUAL_LOGICAL_BLOCK_SIZE=`cat $SYSFS_LOGICAL_BLOCK_SIZE`
28         test $ACTUAL_LOGICAL_BLOCK_SIZE = $LOGICAL_BS
29     fi
30 }
31
32 lvdev_()
33 {
34     echo "$DM_DEV_DIR/$1/$2"
35 }
36
37 test_snapshot_mount()
38 {
39     lvcreate -L 16M -n $lv1 $vg $dev1
40     mkfs.ext3 $(lvdev_ $vg $lv1)
41     mkdir test_mnt
42     mount $(lvdev_ $vg $lv1) test_mnt
43     lvcreate -L 16M -n $lv2 -s $vg/$lv1
44     umount test_mnt
45     # mount the origin
46     mount $(lvdev_ $vg $lv1) test_mnt
47     umount test_mnt
48     # mount the snapshot
49     mount $(lvdev_ $vg $lv2) test_mnt
50     umount test_mnt
51     rm -r test_mnt
52     vgchange -an $vg
53     lvremove -f $vg/$lv2
54     lvremove -f $vg/$lv1
55 }
56
57 # FIXME add more topology-specific tests and validation (striped LVs, etc)
58
59 NUM_DEVS=1
60 PER_DEV_SIZE=34
61 DEV_SIZE=$(($NUM_DEVS*$PER_DEV_SIZE))
62
63 # ---------------------------------------------
64 # Create "desktop-class" 4K drive
65 # (logical_block_size=512, physical_block_size=4096, alignment_offset=0):
66 LOGICAL_BLOCK_SIZE=512
67 prepare_scsi_debug_dev $DEV_SIZE \
68     sector_size=$LOGICAL_BLOCK_SIZE physblk_exp=3
69 check_logical_block_size $SCSI_DEBUG_DEV $LOGICAL_BLOCK_SIZE
70
71 aux prepare_pvs $NUM_DEVS $PER_DEV_SIZE
72 vgcreate -c n $vg $devs
73 test_snapshot_mount
74 vgremove $vg
75
76 cleanup_scsi_debug_dev
77
78 # ---------------------------------------------
79 # Create "desktop-class" 4K drive w/ 63-sector DOS partition compensation
80 # (logical_block_size=512, physical_block_size=4096, alignment_offset=3584):
81 LOGICAL_BLOCK_SIZE=512
82 prepare_scsi_debug_dev $DEV_SIZE \
83     sector_size=$LOGICAL_BLOCK_SIZE physblk_exp=3 lowest_aligned=7
84 check_logical_block_size $SCSI_DEBUG_DEV $LOGICAL_BLOCK_SIZE
85
86 aux prepare_pvs $NUM_DEVS $PER_DEV_SIZE
87 vgcreate -c n $vg $devs
88 test_snapshot_mount
89 vgremove $vg
90
91 cleanup_scsi_debug_dev
92
93 # ---------------------------------------------
94 # Create "enterprise-class" 4K drive
95 # (logical_block_size=4096, physical_block_size=4096, alignment_offset=0):
96 LOGICAL_BLOCK_SIZE=4096
97 prepare_scsi_debug_dev $DEV_SIZE \
98     sector_size=$LOGICAL_BLOCK_SIZE
99 check_logical_block_size $SCSI_DEBUG_DEV $LOGICAL_BLOCK_SIZE
100
101 aux prepare_pvs $NUM_DEVS $PER_DEV_SIZE
102 vgcreate -c n $vg $devs
103 test_snapshot_mount
104 vgremove $vg