#!/bin/sh

#
# 1. PowerPath is installed and started
# 2. root device is managed by PowerPath
#

# if PowerPath modules are not loaded, stop here.
[ `/sbin/lsmod | grep emcp | wc -l` -gt 0 ] || exit 1

# We only dependent on SCSI and will be loaded by default.
[[ $1 = -d ]] && exit 0

. $dracutfunctions
[[ $debug ]] && set -x

ROOT_VG=`mount 2>/dev/null | grep "on / " | grep mapper | sed -e 's/^\/dev\/mapper\/\(.*\) on.*/\1/'`
if [ "$ROOT_VG" == "" ]
then
    exit 1
fi

# If a snapshot of the root logical volume exists, then dmsetup table will
# give details of the dm device.  Hence add the prefix '-real' to the name
# so that dmsetup table will give the details of the original pseudo device.
if dmsetup table $ROOT_VG | grep -q "snapshot-origin"; then
    ROOT_VG="${ROOT_VG}-real"
fi

DM_TABLE=`dmsetup table $ROOT_VG 2>/dev/null`
DEV_MAJOR=`echo $DM_TABLE | sed -e 's/.* \([0-9]*\):\([0-9]*\).*/\1/'`
DEV_MINOR=`echo $DM_TABLE | sed -e 's/.* \([0-9]*\):\([0-9]*\).*/\2/'`
DEV_NAME_FULL=`grep -e "^ \+$DEV_MAJOR \+ $DEV_MINOR \+" /proc/partitions | sed -e 's/^ *[0-9]* *[0-9]* *[0-9]* *//'`
DEV_NAME=`echo $DEV_NAME_FULL | sed -e 's/[0-9]*//g'`
DEV_NAME_PSEUDO=`powermt display dev=$DEV_NAME 2>/dev/null| grep -e "Pseudo name" | sed -e 's/^Pseudo name=\(.*\)/\1/'`
if [ "$DEV_NAME_PSEUDO" != "" ]
then
    exit 0
fi

exit 1
