Rework lvm rc.d script. Check active flag for selected LV not for the first

one. Remove dmtest function.

Most changes are based on feedback from salo@.
This commit is contained in:
haad 2009-01-20 00:40:59 +00:00
parent 0d3e94c475
commit 94a80e6646

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# $NetBSD: lvm,v 1.1 2009/01/14 22:07:55 haad Exp $
# $NetBSD: lvm,v 1.2 2009/01/20 00:40:59 haad Exp $
#
# PROVIDE: disks
@ -12,76 +12,77 @@ rcvar=$name
start_cmd="lvm_start"
stop_cmd="lvm_stop"
dm_test()
{
if [ -x /sbin/dmsetup ]; then
/sbin/dmsetup version >/dev/null
if [ $? -ne 0 ]; then
echo "Device-mapper not present in kernel"
exit;
fi
fi
}
ifs_restore="$IFS";
lvm_start()
{
dm_test;
if [ -x /sbin/dmsetup ]; then
/sbin/dmsetup version >/dev/null
if [ $? -ne 0 ]; then
warn "Device-mapper not present in kernel"
return 1;
fi
fi
if [ -x /sbin/lvm ]; then
echo "Configuring lvm devices."
if [ -x /sbin/lvm ]; then
echo "Configuring lvm devices."
# Scan for all available VG's
/sbin/lvm vgscan --mknodes --ignorelockingfailure >/dev/null
/sbin/lvm vgscan --mknodes --ignorelockingfailure >/dev/null
# Activate all LV's and create apropriate nodes in /dev
/sbin/lvm vgchange --ignorelockingfailure -a y >/dev/null
echo " Activated Volume Groups:"`/sbin/lvm vgdisplay -C -o vg_name --noheadings 2>/dev/null`
fi
$LV_LIST = $(/sbin/lvm vgdisplay -C -o vg_name --noheadings 2>/dev/null)
echo " Activated Volume Groups:" $LV_LIST
fi
}
lvm_stop()
{
dm_test;
if [ -x /sbin/dmsetup ]; then
/sbin/dmsetup version >/dev/null
if [ $? -ne 0 ]; then
warn "Device-mapper not present in kernel"
return 1;
fi
fi
if [ -x /sbin/lvm ]; then
echo "Deconfiguring lvm devices."
if [ -x /sbin/lvm ]; then
echo "Unconfiguring lvm devices."
LOGICAL_VOLUMES=$(/sbin/lvm lvdisplay -C -o vg_name,lv_name \
-O vg_name --separator \/ --noheadings 2>/dev/null)
VOLUME_GROUPS=$(/sbin/lvm vgdisplay -C -o vg_name \
--separator " " --noheadings 2>/dev/null)
LOGICAL_VOLUMES=`/sbin/lvm lvdisplay -C -o vg_name,lv_name -O vg_name --separator \/ --noheadings 2>/dev/null`
VOLUME_GROUPS=`/sbin/lvm vgdisplay -C -o vg_name --separator " " --noheadings 2>/dev/null`
for x in ${LOGICAL_VOLUMES}; do
IFS=":"
set -- `/sbin/lvm lvdisplay -c`
# The fourth argument in the column LV display is inkernel flag
LV_IS_ACTIVE=$4;
unset IFS
if [ ${LV_IS_ACTIVE} -eq 1 ]; then
echo " Shutting Down logical volume: ${x} "
/sbin/lvm lvchange -an --ignorelockingfailure -P ${x} >/dev/null
fi
for lv in ${LOGICAL_VOLUMES}; do
LV_IS_ACTIVE=$(/sbin/lvm lvdisplay -C --noheadings \
-o lv_attr $lv)
case $LV_IS_ACTIVE in
*a*)
echo " Shutting Down logical volume: ${lv}"
/sbin/lvm lvchange -an --ignorelockingfailure \
-P ${lv} >/dev/null
;;
esac
done
for x in ${VOLUME_GROUPS}; do
echo "VG -> |${x}|"
# Set IFS to field separator
IFS=":"
set -- `/sbin/lvm vgdisplay -cA ${x} 2>/dev/null`
# The seventh parameter is number of opened LVs in a Volume Group
VG_HAS_ACTIVE_LV=$7
unset IFS
if [ "${VG_HAS_ACTIVE_LV}" = 0 ]
then
echo " Shutting Down volume group: ${x}"
/sbin/lvm vgchange -an --ignorelockingfailure -P ${x} >/dev/null
fi
for vg in ${VOLUME_GROUPS}; do
# Set IFS to field separator
IFS=":"
set -- $(/sbin/lvm vgdisplay -cA ${vg} 2>/dev/null)
# The seventh parameter is number of opened LVs in a Volume Group
VG_HAS_ACTIVE_LV=$7
IFS="$ifs_restore";
if [ "${VG_HAS_ACTIVE_LV}" = 0 ]; then
echo " Shutting Down volume group: ${vg}"
/sbin/lvm vgchange -an --ignorelockingfailure \
-P ${vg} >/dev/null
fi
done
fi
fi
}
load_rc_config $name
run_rc_command "$1"