Import lvm2 from NetBSD
[dragonfly.git] / contrib / lvm2 / dist / 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 dmsetup_has_dm_devdir_support_ || exit 200
18
19 # ---------------------------------------------------------------------
20 # Utilities
21
22 lv_devices_() {
23   local d
24   local lv=$1
25   shift
26   local devices=$*
27
28   local devs=$(lvs -a -odevices --noheadings $lv | sed 's/([0-9]*)//g' |
29                sed 's/ //g' | sed 's/,/ /g')
30
31   for d in $devs; do
32     (echo $devices | grep -q $d)  || return 1
33     devices=$(echo $devices | sed "s/$d//")
34   done
35
36   [ "$(echo $devices | sed 's/ //g')" = "" ]
37 }
38
39 lv_mirror_log_() {
40   local lv=$1
41
42   echo $(lvs -a -omirror_log --noheadings $lv | sed 's/ //g')
43 }
44
45 lv_convert_lv_() {
46   local lv=$1
47
48   echo $(lvs -a -oconvert_lv --noheadings $lv | sed 's/ //g')
49 }
50
51 # ---------------------------------------------------------------------
52 # Initialize PVs and VGs
53
54 aux prepare_vg 5 80
55
56 # ---------------------------------------------------------------------
57 # Common environment setup/cleanup for each sub testcases
58
59 prepare_lvs_() {
60         lvremove -ff $vg
61         if dmsetup table|grep $vg; then
62                 echo "ERROR: lvremove did leave some some mappings in DM behind!"
63                 return 1
64         fi
65   :
66 }
67
68 check_and_cleanup_lvs_() {
69   lvs -a -o+devices $vg 
70   lvremove -ff $vg
71         if dmsetup table|grep $vg; then
72                 echo "ERROR: lvremove did leave some some mappings in DM behind!"
73                 return 1
74         fi
75 }
76
77 prepare_lvs_ 
78 check_and_cleanup_lvs_
79
80 # ---------------------------------------------------------------------
81 # basic
82
83 #COMM "init: lvcreate" 
84 prepare_lvs_
85
86 #COMM "mirror images are ${lv1}_mimage_x"
87 lvcreate -l2 -m1 -n $lv1 $vg 
88 lv_devices_ $vg/$lv1 "$lv1"_mimage_0 "$lv1"_mimage_1
89
90 #COMM "mirror log is ${lv1}_mlog"
91 lv_mirror_log_ $vg/$lv1 "$lv1"_mlog
92
93 # "cleanup" 
94 check_and_cleanup_lvs_
95
96 #COMM "mirror with name longer than 22 characters (bz221322)"
97 name="LVwithanamelogerthan22characters_butidontwonttocounthem"
98 lvcreate -m1 -l2 -n"$name" $vg
99 lvs $vg/"$name"
100 check_and_cleanup_lvs_
101
102 # ---------------------------------------------------------------------
103 # lvrename
104
105 #COMM "init: lvrename" 
106 prepare_lvs_
107
108 #COMM "renamed mirror names: $lv1 to $lv2" 
109 lvcreate -l2 -m1 -n $lv1 $vg 
110 lvrename $vg/$lv1 $vg/$lv2 
111 lv_devices_ $vg/$lv2 "$lv2"_mimage_0 "$lv2"_mimage_1 
112 lv_mirror_log_ $vg/$lv2 "$lv2"_mlog
113
114 #COMM "cleanup" 
115 check_and_cleanup_lvs_
116
117 # ---------------------------------------------------------------------
118 # lvconvert
119
120 #COMM "init: lvconvert" 
121 prepare_lvs_
122
123 #COMM "converting mirror names is ${lv1}_mimagetmp_2"
124 lvcreate -l2 -m1 -n $lv1 $vg 
125 lvconvert -m+1 -i1000 -b $vg/$lv1 
126 convlv=$(lv_convert_lv_ "$vg/$lv1") 
127 test "$convlv" = "$lv1"_mimagetmp_2 
128 lv_devices_ $vg/$lv1 "$convlv" "$lv1"_mimage_2 
129 lv_devices_ "$vg/$convlv" "$lv1"_mimage_0 "$lv1"_mimage_1 
130 loglv=$(lv_mirror_log_ "$vg/$convlv") 
131 test "$loglv" = "$lv1"_mlog
132
133 #COMM "mirror log name after re-adding is ${lv1}_mlog" \
134 lvconvert --mirrorlog core $vg/$lv1 
135 lvconvert --mirrorlog disk $vg/$lv1 
136 convlv=$(lv_convert_lv_ "$vg/$lv1") 
137 lv_devices_ $vg/$lv1 "$convlv" "$lv1"_mimage_2 
138 lv_devices_ "$vg/$convlv" "$lv1"_mimage_0 "$lv1"_mimage_1 
139 loglv=$(lv_mirror_log_ "$vg/$convlv") 
140 test "$loglv" = "$lv1"_mlog
141
142 #COMM "renamed converting mirror names: $lv1 to $lv2" \
143 lvrename $vg/$lv1 $vg/$lv2 
144 convlv=$(lv_convert_lv_ "$vg/$lv2") 
145 lv_devices_ $vg/$lv2 "$convlv" "$lv2"_mimage_2 
146 lv_devices_ "$vg/$convlv" "$lv2"_mimage_0 "$lv2"_mimage_1 
147 loglv=$(lv_mirror_log_ "$vg/$convlv") 
148 test "$loglv" = "$lv2"_mlog
149
150 #COMM "cleanup" 
151 check_and_cleanup_lvs_
152
153 # Temporary mirror log should have "_mlogtmp_<n>" suffix
154 # but currently lvconvert doesn't have an option to add the log.
155 # If such feature is added in future, a test for that should
156 # be added.
157
158 # ---------------------------------------------------------------------