1 # Put lvm-related utilities here.
2 # This file is sourced from test infrastructure.
4 # Copyright (C) 2007, 2008, 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 || error "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" 2>/dev/null) \
47 || { warn "loop_setup_ failed: Unable to create loopback device"; return 1; }
53 # set up private /dev and /etc
56 test -z "$test_dir_" \
57 && skip_ "Internal error: called lvm_init_root_dir_ before" \
58 "defining \$test_dir_"
60 # Define these two globals.
61 G_root_=$test_dir_/root
64 export LVM_SYSTEM_DIR=$G_root_/etc
65 export DM_DEV_DIR=$G_dev_
67 # Only the first caller does anything.
68 mkdir -p $G_root_/etc $G_dev_ $G_dev_/mapper $G_root_/lib
69 for i in 0 1 2 3 4 5 6 7; do
70 mknod $G_root_/dev/loop$i b 7 $i
72 for i in $abs_top_builddir/dmeventd/mirror/*.so \
73 $abs_top_builddir/dmeventd/snapshot/*.so
75 # NOTE: This check is necessary because the loop above will give us the
76 # value "$abs_top_builddir/dmeventd/mirror/*.so" if no files ending in
77 # 'so' exist. This is the best way I could quickly determine to skip
78 # over this bogus value.
80 echo Setting up symlink from $i to $G_root_/lib
84 cat > $G_root_/etc/lvm.conf <<-EOF
88 filter = [ "a/loop/", "a/mirror/", "a/mapper/", "r/.*/" ]
89 cache_dir = "$G_root_/etc"
93 verbose = $verboselevel
102 library_dir = "$G_root_/lib"