Sync usage with man page.
[netbsd-mini2440.git] / external / gpl2 / lvm2 / dist / test / t-mirror-names.sh
blobb73fd2530d396b4cdebb2f18afc3e4ad09adcf52
1 #!/bin/sh
2 # Copyright (C) 2007-2008 Red Hat, Inc. All rights reserved.
3 # Copyright (C) 2007-2008 NEC Corporation
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.
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
13 test_description="check namings of mirrored LV"
15 . ./test-utils.sh
17 dmsetup_has_dm_devdir_support_ || exit 200
19 # ---------------------------------------------------------------------
20 # Utilities
22 lv_devices_() {
23 local d
24 local lv=$1
25 shift
26 local devices=$*
28 local devs=$(lvs -a -odevices --noheadings $lv | sed 's/([0-9]*)//g' |
29 sed 's/ //g' | sed 's/,/ /g')
31 for d in $devs; do
32 (echo $devices | grep -q $d) || return 1
33 devices=$(echo $devices | sed "s/$d//")
34 done
36 [ "$(echo $devices | sed 's/ //g')" = "" ]
39 lv_mirror_log_() {
40 local lv=$1
42 echo $(lvs -a -omirror_log --noheadings $lv | sed 's/ //g')
45 lv_convert_lv_() {
46 local lv=$1
48 echo $(lvs -a -oconvert_lv --noheadings $lv | sed 's/ //g')
51 # ---------------------------------------------------------------------
52 # Initialize PVs and VGs
54 aux prepare_vg 5 80
56 # ---------------------------------------------------------------------
57 # Common environment setup/cleanup for each sub testcases
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
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
77 prepare_lvs_
78 check_and_cleanup_lvs_
80 # ---------------------------------------------------------------------
81 # basic
83 #COMM "init: lvcreate"
84 prepare_lvs_
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
90 #COMM "mirror log is ${lv1}_mlog"
91 lv_mirror_log_ $vg/$lv1 "$lv1"_mlog
93 # "cleanup"
94 check_and_cleanup_lvs_
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_
102 # ---------------------------------------------------------------------
103 # lvrename
105 #COMM "init: lvrename"
106 prepare_lvs_
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
114 #COMM "cleanup"
115 check_and_cleanup_lvs_
117 # ---------------------------------------------------------------------
118 # lvconvert
120 #COMM "init: lvconvert"
121 prepare_lvs_
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
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
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
150 #COMM "cleanup"
151 check_and_cleanup_lvs_
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.
158 # ---------------------------------------------------------------------