add check_size function for fs dump

Resolves: bz806196

Adding check_size function for filesystem dump, also move common code to
top of the file because get_fs_size need know the mount point.

Signed-off-by: Dave Young <dyoung@redhat.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
This commit is contained in:
dyoung@redhat.com 2012-06-26 17:21:54 +08:00 committed by Dave Young
parent 2cb3c1cbc4
commit a71cead537

114
mkdumprd
View File

@ -35,51 +35,6 @@ add_dracut_sshkey() {
add_dracut_arg "--sshkey" "$1"
}
#Function: get_ssh_size
#$1=dump target
get_ssh_size() {
local _opt _out _size
_opt="-i $SSH_KEY_LOCATION -o BatchMode=yes -o StrictHostKeyChecking=yes"
_out=$(ssh -q $_opt $1 "df -P $SAVE_PATH")
if [ $? -ne 0 ]; then
echo "checking remote ssh server available size failed."
exit 1
fi
#ssh output removed the line break, so print $11 instead of $4
_size=$(echo -n $_out|tail -1 | awk '{print $11}')
echo -n $_size
}
#Function: get_raw_size
#$1=dump target
get_raw_size() {
echo -n $(fdisk -s "$1")
}
#Function: check_size
#$1: dump type string ('raw', 'local', 'ssh', 'nfs')
#$2: dump target
check_size() {
local avail memtotal
memtotal=$(awk '/MemTotal/{print $2}' /proc/meminfo)
case "$1" in
raw)
avail=$(get_raw_size "$2")
;;
ssh)
avail=$(get_ssh_size "$2")
;;
*)
return
esac
if [ $avail -lt $memtotal ]; then
echo "Warning: There is not enough space to save a vmcore."
echo " The size of $2 should be much greater than $memtotal kilo bytes."
fi
}
# Generic substring function. If $2 is in $1, return 0.
strstr() { [[ $1 =~ $2 ]]; }
@ -106,6 +61,73 @@ to_mount() {
echo "$(grep "$_dev" /proc/mounts | cut -d' ' -f1-4)"
}
to_mount_point() {
local _dev=$(to_dev_name $1)
echo "$(grep "$_dev" /proc/mounts | cut -d' ' -f2)"
}
#Function: get_ssh_size
#$1=dump target
get_ssh_size() {
local _opt _out _size
_opt="-i $SSH_KEY_LOCATION -o BatchMode=yes -o StrictHostKeyChecking=yes"
_out=$(ssh -q $_opt $1 "df -P $SAVE_PATH")
if [ $? -ne 0 ]; then
echo "checking remote ssh server available size failed."
exit 1
fi
#ssh output removed the line break, so print $11 instead of $4
_size=$(echo -n $_out|tail -1 | awk '{print $11}')
echo -n $_size
}
#Function: get_fs_size
#$1=dump target
get_fs_size() {
local _mnt=$(to_mount_point $1)
[ ! -d ${_mnt}/$SAVE_PATH ] && {
mkdir -p ${_mnt}/$SAVE_PATH
[ $? -ne 0 ] && {
echo "Creating ${_mnt}/$SAVE_PATH failed."
exit 1
}
}
echo -n $(df -P "${_mnt}/$SAVE_PATH"|tail -1|awk '{print $4}')
}
#Function: get_raw_size
#$1=dump target
get_raw_size() {
echo -n $(fdisk -s "$1")
}
#Function: check_size
#$1: dump type string ('raw', 'fs', 'ssh')
#$2: dump target
check_size() {
local avail memtotal
memtotal=$(awk '/MemTotal/{print $2}' /proc/meminfo)
case "$1" in
raw)
avail=$(get_raw_size "$2")
;;
ssh)
avail=$(get_ssh_size "$2")
;;
fs)
avail=$(get_fs_size "$2")
;;
*)
return
esac
if [ $avail -lt $memtotal ]; then
echo "Warning: There is not enough space to save a vmcore."
echo " The size of $2 should be much greater than $memtotal kilo bytes."
fi
}
is_ssh_dump_target()
{
grep -q "^net.*@" $conf_file
@ -165,6 +187,7 @@ do
echo "Dump target $config_val is probably not mounted."
exit 1
fi
check_size fs $config_val
;;
raw)
#checking raw disk writable
@ -187,6 +210,7 @@ do
echo "Dump target $config_val is probably not mounted."
exit 1
fi
check_size fs $config_val
fi
;;
core_collector)