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
13test_description="check namings of mirrored LV"
14
15. ./test-utils.sh
16
17dmsetup_has_dm_devdir_support_ || exit 200
18
19# ---------------------------------------------------------------------
20# Utilities
21
22lv_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
39lv_mirror_log_() {
40  local lv=$1
41
42  echo $(lvs -a -omirror_log --noheadings $lv | sed 's/ //g')
43}
44
45lv_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
54aux prepare_vg 5 80
55
56# ---------------------------------------------------------------------
57# Common environment setup/cleanup for each sub testcases
58
59prepare_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
68check_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
77prepare_lvs_
78check_and_cleanup_lvs_
79
80# ---------------------------------------------------------------------
81# basic
82
83#COMM "init: lvcreate"
84prepare_lvs_
85
86#COMM "mirror images are ${lv1}_mimage_x"
87lvcreate -l2 -m1 -n $lv1 $vg
88lv_devices_ $vg/$lv1 "$lv1"_mimage_0 "$lv1"_mimage_1
89
90#COMM "mirror log is ${lv1}_mlog"
91lv_mirror_log_ $vg/$lv1 "$lv1"_mlog
92
93# "cleanup"
94check_and_cleanup_lvs_
95
96#COMM "mirror with name longer than 22 characters (bz221322)"
97name="LVwithanamelogerthan22characters_butidontwonttocounthem"
98lvcreate -m1 -l2 -n"$name" $vg
99lvs $vg/"$name"
100check_and_cleanup_lvs_
101
102# ---------------------------------------------------------------------
103# lvrename
104
105#COMM "init: lvrename"
106prepare_lvs_
107
108#COMM "renamed mirror names: $lv1 to $lv2"
109lvcreate -l2 -m1 -n $lv1 $vg
110lvrename $vg/$lv1 $vg/$lv2
111lv_devices_ $vg/$lv2 "$lv2"_mimage_0 "$lv2"_mimage_1
112lv_mirror_log_ $vg/$lv2 "$lv2"_mlog
113
114#COMM "cleanup"
115check_and_cleanup_lvs_
116
117# ---------------------------------------------------------------------
118# lvconvert
119
120#COMM "init: lvconvert"
121prepare_lvs_
122
123#COMM "converting mirror names is ${lv1}_mimagetmp_2"
124lvcreate -l2 -m1 -n $lv1 $vg
125lvconvert -m+1 -i1000 -b $vg/$lv1
126convlv=$(lv_convert_lv_ "$vg/$lv1")
127test "$convlv" = "$lv1"_mimagetmp_2
128lv_devices_ $vg/$lv1 "$convlv" "$lv1"_mimage_2
129lv_devices_ "$vg/$convlv" "$lv1"_mimage_0 "$lv1"_mimage_1
130loglv=$(lv_mirror_log_ "$vg/$convlv")
131test "$loglv" = "$lv1"_mlog
132
133#COMM "mirror log name after re-adding is ${lv1}_mlog" \
134lvconvert --mirrorlog core $vg/$lv1
135lvconvert --mirrorlog disk $vg/$lv1
136convlv=$(lv_convert_lv_ "$vg/$lv1")
137lv_devices_ $vg/$lv1 "$convlv" "$lv1"_mimage_2
138lv_devices_ "$vg/$convlv" "$lv1"_mimage_0 "$lv1"_mimage_1
139loglv=$(lv_mirror_log_ "$vg/$convlv")
140test "$loglv" = "$lv1"_mlog
141
142#COMM "renamed converting mirror names: $lv1 to $lv2" \
143lvrename $vg/$lv1 $vg/$lv2
144convlv=$(lv_convert_lv_ "$vg/$lv2")
145lv_devices_ $vg/$lv2 "$convlv" "$lv2"_mimage_2
146lv_devices_ "$vg/$convlv" "$lv2"_mimage_0 "$lv2"_mimage_1
147loglv=$(lv_mirror_log_ "$vg/$convlv")
148test "$loglv" = "$lv2"_mlog
149
150#COMM "cleanup"
151check_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# ---------------------------------------------------------------------
159