3 # Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
5 # This file is part of the lvm2-cluster package.
7 # This copyrighted material is made available to anyone wishing to use,
8 # modify, copy, or redistribute it subject to the terms and conditions
9 # of the GNU General Public License v.2.
11 # You should have received a copy of the GNU General Public License
12 # along with this program; if not, write to the Free Software Foundation,
13 # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 # Edit an lvm.conf file to adjust various properties
21 echo "usage: $0 <command>"
24 echo "Enable clvm: --enable-cluster [--lockinglibdir <dir>] [--lockinglib <lib>]"
25 echo "Disable clvm: --disable-cluster"
26 echo "Set locking library: --lockinglibdir <dir> [--lockinglib <lib>]"
28 echo "Global options:"
29 echo "Config file location: --file <configfile>"
80 function validate_args
82 [ -z "$CONFIGFILE" ] && CONFIGFILE
="/etc/lvm/lvm.conf"
84 if [ ! -f "$CONFIGFILE" ]
86 echo "$CONFIGFILE does not exist"
90 if [ -z "$LOCKING_TYPE" ] && [ -z "$LOCKINGLIBDIR" ]; then
95 if [ -n "$LOCKINGLIBDIR" ]; then
97 [ -z "$LOCKINGLIB" ] && LOCKINGLIB
="liblvm2clusterlock.so"
99 if [ "${LOCKINGLIBDIR:0:1}" != "/" ]
101 echo "Prefix must be an absolute path name (starting with a /)"
105 if [ ! -f "$LOCKINGLIBDIR/$LOCKINGLIB" ]
107 echo "$LOCKINGLIBDIR/$LOCKINGLIB does not exist, did you do a \"make install\" ?"
113 if [ "$LOCKING_TYPE" = "1" ] && [ -n "$LOCKINGLIBDIR" -o -n "$LOCKINGLIB" ]; then
114 echo "Superfluous locking lib parameter, ignoring"
125 SCRIPTFILE
=/etc
/lvm
/.lvmconf-script.tmp
126 TMPFILE
=/etc
/lvm
/.lvmconf-tmp.tmp
129 # Flags so we know which parts of the file we can replace and which need
130 # adding. These are return codes from grep, so zero means it IS present!
136 grep -q '^[[:blank:]]*locking_type[[:blank:]]*=' $CONFIGFILE
139 grep -q '^[[:blank:]]*library_dir[[:blank:]]*=' $CONFIGFILE
142 grep -q '^[[:blank:]]*locking_library[[:blank:]]*=' $CONFIGFILE
145 # Those options are in section "global {" so we must have one if any are present.
146 if [ "$have_type" = "0" -o "$have_dir" = "0" -o "$have_library" = "0" ]
149 # See if we can find it...
150 grep -q '^[[:blank:]]*global[[:blank:]]*{' $CONFIGFILE
153 if [ "$have_global" = "1" ]
155 echo "global keys but no 'global {' found, can't edit file"
160 if [ "$LOCKING_TYPE" = "2" ] && [ -z "$LOCKINGLIBDIR" ] && [ "$have_dir" = "1" ]; then
161 echo "no library_dir specified in $CONFIGFILE"
165 # So if we don't have "global {" we need to create one and
168 if [ "$have_global" = "1" ]
170 if [ -z "$LOCKING_TYPE" ]; then
173 if [ "$LOCKING_TYPE" = "2" ]; then
174 cat $CONFIGFILE - <<EOF > $TMPFILE
176 # Enable locking for cluster LVM
177 locking_type = $LOCKING_TYPE
178 library_dir = "$LOCKINGLIBDIR"
179 locking_library = "$LOCKINGLIB"
182 fi # if we aren't setting cluster locking, we don't need to create a global section
186 echo "failed to create temporary config file, $CONFIGFILE not updated"
191 # We have a "global {" section, so add or replace the
192 # locking entries as appropriate
195 if [ -n "$LOCKING_TYPE" ]; then
196 if [ "$have_type" = "0" ]
198 SEDCMD
=" s/^[[:blank:]]*locking_type[[:blank:]]*=.*/\ \ \ \ locking_type = $LOCKING_TYPE/g"
200 SEDCMD
=" /global[[:blank:]]*{/a\ \ \ \ locking_type = $LOCKING_TYPE"
204 if [ -n "$LOCKINGLIBDIR" ]; then
205 if [ "$have_dir" = "0" ]
207 SEDCMD
="${SEDCMD}\ns'^[[:blank:]]*library_dir[[:blank:]]*=.*'\ \ \ \ library_dir = \"$LOCKINGLIBDIR\"'g"
209 SEDCMD
="${SEDCMD}\n/global[[:blank:]]*{/a\ \ \ \ library_dir = \"$LOCKINGLIBDIR\""
212 if [ "$have_library" = "0" ]
214 SEDCMD
="${SEDCMD}\ns/^[[:blank:]]*locking_library[[:blank:]]*=.*/\ \ \ \ locking_library = \"$LOCKINGLIB\"/g"
216 SEDCMD
="${SEDCMD}\n/global[[:blank:]]*{/a\ \ \ \ locking_library = \"$LOCKINGLIB\""
220 if [ "$LOCKING_TYPE" = "1" ]; then
221 # if we're not using cluster locking, remove the library dir and locking library name
222 if [ "$have_dir" = "0" ]
224 SEDCMD
="${SEDCMD}\n/^[[:blank:]]*library_dir[[:blank:]]*=.*/d"
227 if [ "$have_library" = "0" ]
229 SEDCMD
="${SEDCMD}\n/^[[:blank:]]*locking_library[[:blank:]]*=.*/d"
233 echo -e $SEDCMD > $SCRIPTFILE
234 sed <$CONFIGFILE >$TMPFILE -f $SCRIPTFILE
237 echo "sed failed, $CONFIGFILE not updated"
242 # Now we have a suitably editted config file in a temp place,
243 # backup the original and copy our new one into place.
245 cp $CONFIGFILE $CONFIGFILE.lvmconfold
248 echo "failed to backup old config file, $CONFIGFILE not updated"
252 cp $TMPFILE $CONFIGFILE
255 echo "failed to copy new config file into place, check $CONFIGFILE is still OK"
259 rm -f $SCRIPTFILE $TMPFILE