SHA256
1
0
forked from pool/lvm2
lvm2/collect_lvm

54 lines
1.3 KiB
Bash

#!/bin/sh
PVNAME=$1
/sbin/lvm pvs --config "devices {filter = [ \"a|$PVNAME|\", \"r/.*/\" ]}" --partial -o vg_name,vg_attr,pv_uuid,vg_uuid --ignorelockingfailure --noheadings $PVNAME 2>/dev/null | while read vgname vgattr pvuuid vguuid; do
if [[ $vgattr =~ mode. ]]; then
continue
fi
if [[ $vgattr =~ .....c ]]; then
exit 1
fi
lvlist=$(/sbin/lvm lvs --config "devices {filter = [ \"a|$PVNAME|\", \"r/.*/\" ]}" --partial -o lv_name,lv_attr --ignorelockingfailure --noheadings $vgname 2>/dev/null | while read lvname lvattr; do
if [[ $lvattr =~ mode. ]] ; then
continue
fi
if [[ $lvattr =~ ....-. ]]; then
echo -n $lvname
fi
done)
if [ -z "$lvlist" ] ; then
exit 1
fi
pvlist=$(/sbin/lvm vgdisplay --config "devices {filter = [ \"a|$PVNAME|\", \"r/.*/\" ]}" --partial -v $vgname 2>/dev/null | while read str1 str2 val; do
if [[ $str1 =~ PV && $str2 =~ UUID ]]; then
echo $val
fi
done)
echo PVUUID=$pvuuid
echo VGUUID=$vguuid
echo VGNAME=$vgname
collected=0
for pv in $pvlist; do
if [[ x$pv = x$pvuuid ]]; then
continue
fi
if [[ ! -h /dev/disk/by-id/lvm2-pvuuid-$pv ]]; then
echo COLLECT=1
collected=1
break
fi
done
if [[ $collected = 0 ]]; then
echo COLLECT=0
fi
# /lib/udev/collect $vguuid $pvuuid $pvlist
# echo COLLECT=$?
done