3 # Copyright (C) 2010 Red Hat, Inc. All rights reserved.
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 # check.sh: assert various things about volumes
17 # check lv_on VG LV PV
19 # check mirror VG LV [LOGDEV|core]
20 # check mirror_nonredundant VG LV
21 # check mirror_legs VG LV N
22 # check mirror_images_on VG LV DEV [DEV...]
29 lvs -a --noheadings "$@"
33 lvl -odevices "$@" | sed 's/([^)]*)//g; s/,/ /g'
36 mirror_images_redundant()
42 for i in `lvdevices $lv`; do
44 lvdevices $vg/$i | sort | uniq
47 (grep -v ^# check.tmp.all || true) | sort | uniq -d > check.tmp
49 test "`cat check.tmp | wc -l`" -eq 0 || {
50 echo "mirror images of $lv expected redundant, but are not:"
62 for i in `lvdevices $lv`; do
71 lvdevices $lv | grep -F "$3" || {
72 echo "LV $lv expected on $3 but is not:" >&2
76 test `lvdevices $lv | grep -vF "$3" | wc -l` -eq 0 || {
77 echo "LV $lv contains unexpected devices:" >&2
88 if test "$where" = "core"; then
89 lvl -omirror_log "$vg/$lv" | not grep mlog
91 lv_on $vg "${lv}_mlog" "$where"
97 test `lvl --segments $1 | wc -l` -eq 1 || {
98 echo "LV $1 expected to be contiguous, but is not:"
106 test `lvdevices $1 | sort | uniq | wc -l` -eq 1 || {
107 echo "LV $1 expected to be clung, but is not:"
108 lvdevices $! | sort | uniq
113 mirror_images_contiguous()
115 for i in `lvdevices $1/$2`; do
116 lv_is_contiguous $1/$i
120 mirror_images_clung()
122 for i in `lvdevices $1/$2`; do
128 mirror_nonredundant "$@"
129 mirror_images_redundant "$1" "$2"
132 mirror_nonredundant() {
134 lvs -oattr "$lv" | grep -q "^ *m.....$" || {
135 echo "$lv expected a mirror, but is not:"
139 if test -n "$3"; then mirror_log_on "$1" "$2" "$3"; fi
146 real=`lvdevices "$lv" | wc -w`
147 test "$expect" = "$real"
150 mirror_no_temporaries()
154 lvl -oname $vg | grep $lv | not grep "tmp" || {
155 echo "$lv has temporary mirror images unexpectedly:"
163 lvl -ostripes "$lv" | grep -q "1" || {
164 echo "$lv expected linear, but is not:"
172 lvl -oattr "$lv" 2> /dev/null | grep -q "^ *....a.$" || {
173 echo "$lv expected active, but lvs says it's not:"
174 lvl "$lv" -o+devices 2>/dev/null
177 dmsetup table | egrep -q "$1-$2: *[^ ]+" || {
178 echo "$lv expected active, lvs thinks it is but there are no mappings!"
179 dmsetup table | grep $1-$2:
186 lvl -oattr "$lv" 2> /dev/null | grep -q '^ *....[-isd].$' || {
187 echo "$lv expected inactive, but lvs says it's not:"
188 lvl "$lv" -o+devices 2>/dev/null
191 dmsetup table | not egrep -q "$1-$2: *[^ ]+" || {
192 echo "$lv expected inactive, lvs thinks it is but there are mappings!"
193 dmsetup table | grep $1-$2: