Lines 19-37
Link Here
|
19 |
return ${retval} |
19 |
return ${retval} |
20 |
} |
20 |
} |
21 |
|
21 |
|
|
|
22 |
# char **build_dmsetup_command(volume) |
23 |
# |
24 |
# Returns complete dmsetup command given single volume name |
25 |
build_dmsetup_command() { |
26 |
local count dmsetup_cmd |
27 |
|
28 |
# Number of lines mentioning volume name |
29 |
count=$(grep -v -e '^[[:space:]]*\(#\|$\)' /etc/dmtab | grep -c ${1}) |
30 |
|
31 |
# If there's just one line: |
32 |
if [ ${count} -eq 1 ] ; then |
33 |
echo "echo $(grep -v -e '^[[:space:]]*\(#\|$\)' /etc/dmtab | \ |
34 |
grep ${1} | awk '{$1=""; print $0}') | /sbin/dmsetup create ${1}" |
35 |
|
36 |
# For all cases with more lines: |
37 |
elif [ ${count} -gt 1 ] ; then |
38 |
for c in $( seq 1 ${count} ) ; do |
39 |
if [ ${c} -eq 1 ] ; then |
40 |
# Heavy escaping in awk-statement because we cannot use apostrophes |
41 |
dmsetup_cmd="echo -e $(grep -v -e '^[[:space:]]*\(#\|$\)' /etc/dmtab | \ |
42 |
grep ${1} | awk NR==${c}\ \{\$1=\"\"\;\ print\ \$0\})" |
43 |
else |
44 |
# Append starting with newline |
45 |
dmsetup_cmd="${dmsetup_cmd}\\\\n \ |
46 |
$(grep -v -e '^[[:space:]]*\(#\|$\)' /etc/dmtab | \ |
47 |
grep ${1} | awk NR==${c}\ \{\$1=\"\"\;\ print\ \$0\})" |
48 |
fi |
49 |
done |
50 |
echo "${dmsetup_cmd} | /sbin/dmsetup create ${1}" |
51 |
fi |
52 |
|
53 |
return 0 |
54 |
} |
55 |
|
22 |
# char **get_new_dm_volumes(void) |
56 |
# char **get_new_dm_volumes(void) |
23 |
# |
57 |
# |
24 |
# Return dmsetup commands to setup volumes |
58 |
# Return unique volumes from /etc/dmtab |
25 |
get_new_dm_volumes() { |
59 |
get_new_dm_volumes() { |
26 |
local volume params |
60 |
local volume |
27 |
|
61 |
|
28 |
# Filter comments and blank lines |
62 |
# Filter comments and blank lines |
29 |
grep -v -e '^[[:space:]]*\(#\|$\)' /etc/dmtab | \ |
63 |
grep -v -e '^[[:space:]]*\(#\|$\)' /etc/dmtab | \ |
30 |
while read volume params ; do |
64 |
awk '{ print $1 }' | \ |
|
|
65 |
uniq | \ |
66 |
while read volume ; do |
31 |
# If it exists, skip it |
67 |
# If it exists, skip it |
32 |
dmvolume_exists "${volume%:}" && continue |
68 |
dmvolume_exists "${volume%:}" && continue |
33 |
# Assemble the command to run to create volume |
69 |
|
34 |
echo "echo ${params} | /sbin/dmsetup create ${volume%:}" |
70 |
echo "${volume%:}" |
35 |
done |
71 |
done |
36 |
|
72 |
|
37 |
return 0 |
73 |
return 0 |
Lines 88-102
Link Here
|
88 |
if [ -x /sbin/dmsetup -a -c /dev/mapper/control -a -f /etc/dmtab ] ; then |
124 |
if [ -x /sbin/dmsetup -a -c /dev/mapper/control -a -f /etc/dmtab ] ; then |
89 |
[ -n "$(get_new_dm_volumes)" ] && \ |
125 |
[ -n "$(get_new_dm_volumes)" ] && \ |
90 |
einfo " Setting up device-mapper volumes:" |
126 |
einfo " Setting up device-mapper volumes:" |
91 |
|
127 |
|
92 |
get_new_dm_volumes | \ |
128 |
get_new_dm_volumes | \ |
93 |
while read x ; do |
129 |
while read x ; do |
94 |
[ -n "${x}" ] || continue |
130 |
[ -n "${x}" ] || continue |
95 |
|
131 |
|
96 |
volume="${x##* }" |
132 |
volume="${x##* }" |
97 |
|
133 |
|
98 |
ebegin " Creating volume: ${volume}" |
134 |
ebegin " Creating volume: ${volume}" |
99 |
if ! eval "${x}" >/dev/null 2>/dev/null ; then |
135 |
if ! eval $(build_dmsetup_command ${volume}) >/dev/null 2>/dev/null ; then |
100 |
eend 1 " Error creating volume: ${volume}" |
136 |
eend 1 " Error creating volume: ${volume}" |
101 |
# dmsetup still adds an empty volume in some cases, |
137 |
# dmsetup still adds an empty volume in some cases, |
102 |
# so lets remove it |
138 |
# so lets remove it |