Tizen 2.1 base
[external/device-mapper.git] / test / t-mirror-names.sh
1 #!/bin/sh
2 # Copyright (C) 2007-2008 Red Hat, Inc. All rights reserved.
3 # Copyright (C) 2007-2008 NEC Corporation
4 #
5 # This copyrighted material is made available to anyone wishing to use,
6 # modify, copy, or redistribute it subject to the terms and conditions
7 # of the GNU General Public License v.2.
8 #
9 # You should have received a copy of the GNU General Public License
10 # along with this program; if not, write to the Free Software Foundation,
11 # Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
12
13 test_description="check namings of mirrored LV"
14
15 . ./test-utils.sh
16
17 # ---------------------------------------------------------------------
18 # Utilities
19
20 lv_devices_() {
21   local d
22   local lv=$1
23   shift
24   local devices=$*
25
26   local devs=$(lvs -a -odevices --noheadings $lv | sed 's/([0-9]*)//g' |
27                sed 's/ //g' | sed 's/,/ /g')
28
29   for d in $devs; do
30     (echo $devices | grep -q $d)  || return 1
31     devices=$(echo $devices | sed "s/$d//")
32   done
33
34   [ "$(echo $devices | sed 's/ //g')" = "" ]
35 }
36
37 lv_mirror_log_() {
38   local lv=$1
39
40   echo $(lvs -a -omirror_log --noheadings $lv | sed 's/ //g')
41 }
42
43 lv_convert_lv_() {
44   local lv=$1
45
46   echo $(lvs -a -oconvert_lv --noheadings $lv | sed 's/ //g')
47 }
48
49 # ---------------------------------------------------------------------
50 # Initialize PVs and VGs
51
52 aux prepare_vg 5 80
53
54 # ---------------------------------------------------------------------
55 # Common environment setup/cleanup for each sub testcases
56
57 prepare_lvs_() {
58         lvremove -ff $vg
59         if dmsetup table|grep $vg; then
60                 echo "ERROR: lvremove did leave some some mappings in DM behind!"
61                 return 1
62         fi
63   :
64 }
65
66 check_and_cleanup_lvs_() {
67   lvs -a -o+devices $vg 
68   lvremove -ff $vg
69         if dmsetup table|grep $vg; then
70                 echo "ERROR: lvremove did leave some some mappings in DM behind!"
71                 return 1
72         fi
73 }
74
75 prepare_lvs_ 
76 check_and_cleanup_lvs_
77
78 # ---------------------------------------------------------------------
79 # basic
80
81 #COMM "init: lvcreate" 
82 prepare_lvs_
83
84 #COMM "mirror images are ${lv1}_mimage_x"
85 lvcreate -l2 -m1 -n $lv1 $vg 
86 lv_devices_ $vg/$lv1 "$lv1"_mimage_0 "$lv1"_mimage_1
87
88 #COMM "mirror log is ${lv1}_mlog"
89 lv_mirror_log_ $vg/$lv1 "$lv1"_mlog
90
91 # "cleanup" 
92 check_and_cleanup_lvs_
93
94 #COMM "mirror with name longer than 22 characters (bz221322)"
95 name="LVwithanamelogerthan22characters_butidontwonttocounthem"
96 lvcreate -m1 -l2 -n"$name" $vg
97 lvs $vg/"$name"
98 check_and_cleanup_lvs_
99
100 # ---------------------------------------------------------------------
101 # lvrename
102
103 #COMM "init: lvrename" 
104 prepare_lvs_
105
106 #COMM "renamed mirror names: $lv1 to $lv2" 
107 lvcreate -l2 -m1 -n $lv1 $vg 
108 lvrename $vg/$lv1 $vg/$lv2 
109 lv_devices_ $vg/$lv2 "$lv2"_mimage_0 "$lv2"_mimage_1 
110 lv_mirror_log_ $vg/$lv2 "$lv2"_mlog
111
112 #COMM "cleanup" 
113 check_and_cleanup_lvs_
114
115 # ---------------------------------------------------------------------
116 # lvconvert
117
118 #COMM "init: lvconvert" 
119 prepare_lvs_
120
121 #COMM "converting mirror names is ${lv1}_mimagetmp_2"
122 lvcreate -l2 -m1 -n $lv1 $vg 
123 lvconvert -m+1 -i+10 -b $vg/$lv1
124 convlv=$(lv_convert_lv_ "$vg/$lv1") 
125 test "$convlv" = "$lv1"_mimagetmp_2 
126 lv_devices_ $vg/$lv1 "$convlv" "$lv1"_mimage_2 
127 lv_devices_ "$vg/$convlv" "$lv1"_mimage_0 "$lv1"_mimage_1 
128 loglv=$(lv_mirror_log_ "$vg/$convlv") 
129 test "$loglv" = "$lv1"_mlog
130
131 #COMM "mirror log name after re-adding is ${lv1}_mlog" \
132 lvconvert --mirrorlog core $vg/$lv1 
133 lvconvert --mirrorlog disk $vg/$lv1 
134 convlv=$(lv_convert_lv_ "$vg/$lv1") 
135 lv_devices_ $vg/$lv1 "$convlv" "$lv1"_mimage_2 
136 lv_devices_ "$vg/$convlv" "$lv1"_mimage_0 "$lv1"_mimage_1 
137 loglv=$(lv_mirror_log_ "$vg/$convlv") 
138 test "$loglv" = "$lv1"_mlog
139
140 #COMM "renamed converting mirror names: $lv1 to $lv2" \
141 lvrename $vg/$lv1 $vg/$lv2 
142 convlv=$(lv_convert_lv_ "$vg/$lv2") 
143 lv_devices_ $vg/$lv2 "$convlv" "$lv2"_mimage_2 
144 lv_devices_ "$vg/$convlv" "$lv2"_mimage_0 "$lv2"_mimage_1 
145 loglv=$(lv_mirror_log_ "$vg/$convlv") 
146 test "$loglv" = "$lv2"_mlog
147
148 #COMM "cleanup" 
149 check_and_cleanup_lvs_
150
151 # Temporary mirror log should have "_mlogtmp_<n>" suffix
152 # but currently lvconvert doesn't have an option to add the log.
153 # If such feature is added in future, a test for that should
154 # be added.
155
156 # ---------------------------------------------------------------------