1
# Put lvm-related utilities here.
2
# This file is sourced from test infrastructure.
4
# Copyright (C) 2007-2010 Red Hat, Inc. All rights reserved.
6
# This copyrighted material is made available to anyone wishing to use,
7
# modify, copy, or redistribute it subject to the terms and conditions
8
# of the GNU General Public License v.2.
10
# You should have received a copy of the GNU General Public License
11
# along with this program; if not, write to the Free Software Foundation,
12
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14
export LVM_SUPPRESS_FD_WARNINGS=1
17
warn() { echo >&2 "$ME: $@"; }
24
|| fail_ "Internal error: unsafe_losetup_ called before init_root_dir_"
26
# Iterate through $G_dev_/loop{,/}{0,1,2,3,4,5,6,7,8,9}
28
for i in 0 1 2 3 4 5 6 7 8 9; do
29
dev=$G_dev_/loop$slash$i
30
losetup $dev > /dev/null 2>&1 && continue;
31
losetup "$dev" "$f" > /dev/null && { echo "$dev"; return 0; }
42
dd if=/dev/zero of="$file" bs=1M count=1 seek=1000 > /dev/null 2>&1 \
43
|| { warn "loop_setup_ failed: Unable to create tmp file $file"; return 1; }
45
# NOTE: this requires a new enough version of losetup
46
dev=$(unsafe_losetup_ "$file") \
47
|| { warn "loop_setup_ failed: Unable to create loopback device"; return 1; }
64
val1=$($cmd1 --noheadings -o $field1 $obj1)
65
val2=$($cmd2 --noheadings -o $field2 $obj2)
66
if test "$verbose" = "t"
68
echo "compare_two_fields_ $obj1($field1): $val1 $obj2($field2): $val2"
81
val1=$(vgs --noheadings -o $field $vg1)
82
val2=$(vgs --noheadings -o $field $vg2)
83
if test "$verbose" = "t"
85
echo "compare_vg_field_ VG1: $val1 VG2: $val2"
97
actual=$(vgs --noheadings -o $field $vg)
98
if test "$verbose" = "t"
100
echo "check_vg_field_ VG=$vg, field=$field, actual=$actual, expected=$expected"
102
test $actual = $expected
112
actual=$(pvs --noheadings -o $field $pv)
113
if test "$verbose" = "t"
115
echo "check_pv_field_ PV=$pv, field=$field, actual=$actual, expected=$expected"
117
test $actual = $expected
127
actual=$(lvs --noheadings -o $field $lv)
128
if test "$verbose" = "t"
130
echo "check_lv_field_ LV=$lv, field=$field, actual=$actual, expected=$expected"
132
test $actual = $expected
135
vg_validate_pvlv_counts_()
142
check_vg_field_ $local_vg pv_count $num_pvs &&
143
check_vg_field_ $local_vg lv_count $num_lvs &&
144
check_vg_field_ $local_vg snap_count $num_snaps
147
dmsetup_has_dm_devdir_support_()
149
# Detect support for the envvar. If it's supported, the
150
# following command will fail with the expected diagnostic.
151
out=$(DM_DEV_DIR=j dmsetup version 2>&1)
152
test "$?:$out" = "1:Invalid DM_DEV_DIR envvar value." ||
153
test "$?:$out" = "1:Invalid DM_DEV_DIR environment variable value."
156
# set up private /dev and /etc
159
test -n "$test_dir_" \
160
|| fail_ "Internal error: called init_root_dir_ before" \
161
"defining \$test_dir_"
163
# Define these two globals.
164
G_root_=$test_dir_/root
167
export LVM_SYSTEM_DIR=$G_root_/etc
168
export DM_DEV_DIR=$G_dev_
170
# Only the first caller does anything.
171
mkdir -p $G_root_/etc $G_dev_ $G_dev_/mapper $G_root_/lib
172
for i in 0 1 2 3 4 5 6 7; do
173
mknod $G_root_/dev/loop$i b 7 $i
175
for i in $abs_top_builddir/dmeventd/mirror/*.so $abs_top_builddir/dmeventd/snapshot/*.so
177
# NOTE: This check is necessary because the loop above will give us the value
178
# "$abs_top_builddir/dmeventd/mirror/*.so" if no files ending in 'so' exist.
179
# This is the best way I could quickly determine to skip over this bogus value.
181
echo Setting up symlink from $i to $G_root_/lib
182
ln -s $i $G_root_/lib
185
cat > $G_root_/etc/lvm.conf <<-EOF
189
filter = [ "a/loop/", "a/mirror/", "a/mapper/", "r/.*/" ]
190
cache_dir = "$G_root_/etc"
194
verbose = $verboselevel
203
library_dir = "$G_root_/lib"