kfan / rpms / kexec-tools

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