de80c6
#!/bin/sh
de80c6
#
de80c6
# Kdump common variables and functions
de80c6
#
de80c6
de80c6
DEFAULT_PATH="/var/crash/"
de80c6
FENCE_KDUMP_CONFIG_FILE="/etc/sysconfig/fence_kdump"
de80c6
FENCE_KDUMP_SEND="/usr/libexec/fence_kdump_send"
de80c6
de80c6
is_ssh_dump_target()
de80c6
{
de80c6
    grep -q "^ssh[[:blank:]].*@" /etc/kdump.conf
de80c6
}
de80c6
de80c6
is_nfs_dump_target()
de80c6
{
de80c6
    grep -q "^nfs" /etc/kdump.conf
de80c6
}
de80c6
de80c6
is_raw_dump_target()
de80c6
{
de80c6
    grep -q "^raw" /etc/kdump.conf
de80c6
}
de80c6
de80c6
is_fs_type_nfs()
de80c6
{
de80c6
    local _fstype=$1
de80c6
    [ $_fstype = "nfs" ] || [ $_fstype = "nfs4" ] && return 0
de80c6
    return 1
de80c6
}
de80c6
de80c6
is_fs_dump_target()
de80c6
{
de80c6
    egrep -q "^ext[234]|^xfs|^btrfs|^minix" /etc/kdump.conf
de80c6
}
de80c6
de80c6
is_user_configured_dump_target()
de80c6
{
de80c6
    return $(is_ssh_dump_target || is_nfs_dump_target || is_raw_dump_target || is_fs_dump_target)
de80c6
}
de80c6
de80c6
strip_comments()
de80c6
{
de80c6
    echo $@ | sed -e 's/\(.*\)#.*/\1/'
de80c6
}
de80c6
de80c6
# Check if fence kdump is configured in Pacemaker cluster
de80c6
is_pcs_fence_kdump()
de80c6
{
de80c6
    # no pcs or fence_kdump_send executables installed?
de80c6
    type -P pcs > /dev/null || return 1
de80c6
    [ -x $FENCE_KDUMP_SEND ] || return 1
de80c6
de80c6
    # fence kdump not configured?
de80c6
    (pcs cluster cib | grep -q 'type="fence_kdump"') &> /dev/null || return 1
de80c6
}
de80c6
de80c6
# Check if fence_kdump is configured using kdump options
de80c6
is_generic_fence_kdump()
de80c6
{
de80c6
    [ -x $FENCE_KDUMP_SEND ] || return 1
de80c6
de80c6
    grep -q "^fence_kdump_nodes" /etc/kdump.conf
de80c6
}
de80c6
de80c6
get_user_configured_dump_disk()
de80c6
{
de80c6
    local _target
de80c6
de80c6
    if is_ssh_dump_target || is_nfs_dump_target; then
de80c6
        return
de80c6
    fi
de80c6
de80c6
    _target=$(egrep "^ext[234]|^xfs|^btrfs|^minix|^raw" /etc/kdump.conf 2>/dev/null |awk '{print $2}')
de80c6
    [ -n "$_target" ] && echo $_target
de80c6
de80c6
    return
de80c6
}
de80c6
de80c6
get_root_fs_device()
de80c6
{
de80c6
    local _target
de80c6
    _target=$(findmnt -k -f -n -o SOURCE /)
de80c6
    [ -n "$_target" ] && echo $_target
de80c6
de80c6
    return
de80c6
}
de80c6
de80c6
get_mntpoint_from_path() 
de80c6
{
de80c6
    echo $(df $1 | tail -1 |  awk '{print $NF}')
de80c6
}
de80c6
de80c6
get_target_from_path()
de80c6
{
de80c6
    echo $(df $1 | tail -1 |  awk '{print $1}')
de80c6
}
de80c6
de80c6
get_fs_type_from_target() 
de80c6
{
de80c6
    echo $(findmnt -k -f -n -r -o FSTYPE $1)
de80c6
}
de80c6
de80c6
get_mntpoint_from_target()
de80c6
{
de80c6
    echo $(findmnt -k -f -n -r -o TARGET $1)
de80c6
}
de80c6
de80c6
# get_option_value <option_name>
de80c6
# retrieves value of option defined in kdump.conf
de80c6
get_option_value() {
de80c6
    echo $(strip_comments `grep ^$1 /etc/kdump.conf | tail -1 | cut -d\  -f2-`)
de80c6
}
de80c6
de80c6
#This function compose a absolute path with the mount
de80c6
#point and the relative $SAVE_PATH.
de80c6
#target is passed in as argument, could be UUID, LABEL,
de80c6
#block device or even nfs server export of the form of
de80c6
#"my.server.com:/tmp/export"?
de80c6
#And possibly this could be used for both default case
de80c6
#as well as when dump taret is specified. When dump
de80c6
#target is not specified, then $target would be null.
de80c6
make_absolute_save_path()
de80c6
{
de80c6
    local _target=$1
de80c6
    local _mnt
de80c6
de80c6
    [ -n $_target ] && _mnt=$(get_mntpoint_from_target $1)
de80c6
    echo "${_mnt}/$SAVE_PATH"
de80c6
}
de80c6
de80c6
check_save_path_fs()
de80c6
{
de80c6
    local _path=$1
de80c6
de80c6
    if [ ! -d $_path ]; then
de80c6
        perror_exit "Dump path $_path does not exist."
de80c6
    fi
de80c6
}
de80c6