[kexec-tools] add check_size function for fs dump

Dave Young yangrr at fedoraproject.org
Thu Jul 5 09:01:23 UTC 2012


commit a71cead537904058526f0588f995cb914169df2f
Author: dyoung at redhat.com <dyoung at redhat.com>
Date:   Tue Jun 26 17:21:54 2012 +0800

    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 at redhat.com>
    Acked-by: Vivek Goyal <vgoyal at redhat.com>

 mkdumprd |   78 ++++++++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 51 insertions(+), 27 deletions(-)
---
diff --git a/mkdumprd b/mkdumprd
index c4785ca..d1f7e15 100644
--- a/mkdumprd
+++ b/mkdumprd
@@ -35,6 +35,37 @@ add_dracut_sshkey() {
     add_dracut_arg "--sshkey" "$1"
 }
 
+# Generic substring function.  If $2 is in $1, return 0.
+strstr() { [[ $1 =~ $2 ]]; }
+
+to_dev_name() {
+    local dev="$1"
+
+    case "$dev" in
+    UUID=*)
+        dev=`blkid -U "${dev#UUID=}"`
+        ;;
+    LABEL=*)
+        dev=`blkid -L "${dev#LABEL=}"`
+        ;;
+    esac
+    echo $dev
+}
+
+get_rootdev() {
+    mount | grep 'on / ' | grep -v rootfs | awk '{print $1}'
+}
+
+to_mount() {
+    local _dev=$(to_dev_name $1)
+    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() {
@@ -50,6 +81,20 @@ get_ssh_size() {
     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() {
@@ -57,7 +102,7 @@ get_raw_size() {
 }
 
 #Function: check_size
-#$1: dump type string ('raw', 'local', 'ssh', 'nfs')
+#$1: dump type string ('raw', 'fs', 'ssh')
 #$2: dump target
 check_size() {
     local avail memtotal
@@ -70,6 +115,9 @@ check_size() {
         ssh)
             avail=$(get_ssh_size "$2")
             ;;
+        fs)
+            avail=$(get_fs_size "$2")
+            ;;
         *)
             return
     esac
@@ -80,32 +128,6 @@ check_size() {
     fi
 }
 
-# Generic substring function.  If $2 is in $1, return 0.
-strstr() { [[ $1 =~ $2 ]]; }
-
-to_dev_name() {
-    local dev="$1"
-
-    case "$dev" in
-    UUID=*)
-        dev=`blkid -U "${dev#UUID=}"`
-        ;;
-    LABEL=*)
-        dev=`blkid -L "${dev#LABEL=}"`
-        ;;
-    esac
-    echo $dev
-}
-
-get_rootdev() {
-    mount | grep 'on / ' | grep -v rootfs | awk '{print $1}'
-}
-
-to_mount() {
-    local _dev=$(to_dev_name $1)
-    echo "$(grep "$_dev" /proc/mounts | cut -d' ' -f1-4)"
-}
-
 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)


More information about the scm-commits mailing list