From df29d5f15bd1d4c27b722035d2ccc4d54f5fcfad Mon Sep 17 00:00:00 2001
From: grev <grev>
Date: Wed, 20 Aug 2008 16:43:18 +0000
Subject: [PATCH] b=15637 i=Adilger fix test_18 to check the available space

---
 lustre/tests/conf-sanity.sh | 40 +++++++++++++++++++++++++++++++++----
 1 file changed, 36 insertions(+), 4 deletions(-)

diff --git a/lustre/tests/conf-sanity.sh b/lustre/tests/conf-sanity.sh
index 481e4ee8ab..be8f0da27e 100644
--- a/lustre/tests/conf-sanity.sh
+++ b/lustre/tests/conf-sanity.sh
@@ -33,6 +33,10 @@ HOSTNAME=`hostname`
 
 . $LUSTRE/tests/test-framework.sh
 init_test_env $@
+# STORED_MDSSIZE is used in test_18
+if [ -n "$MDSSIZE" ]; then
+    STORED_MDSSIZE=$MDSSIZE
+fi
 # use small MDS + OST size to speed formatting time
 MDSSIZE=40000
 OSTSIZE=40000
@@ -687,10 +691,38 @@ test_17() {
 run_test 17 "Verify failed mds_postsetup won't fail assertion (2936) (should return errs)"
 
 test_18() {
-        [ -f $MDSDEV ] && echo "remove $MDSDEV" && rm -f $MDSDEV
+        [ "$FSTYPE" != "ldiskfs" ] && skip "not needed for FSTYPE=$FSTYPE" && return
+
+        local MIN=2000000
+
+        local OK=
+        # check if current MDSSIZE is large enough
+        [ $MDSSIZE -ge $MIN ] && OK=1 && myMDSSIZE=$MDSSIZE && \
+                log "use MDSSIZE=$MDSSIZE"
+
+        # check if the global config has a large enough MDSSIZE
+        [ -z "$OK" -a ! -z "$STORED_MDSSIZE" ] && [ $STORED_MDSSIZE -ge $MIN ] && \
+                OK=1 && myMDSSIZE=$STORED_MDSSIZE && \
+                log "use STORED_MDSSIZE=$STORED_MDSSIZE"
+
+        # check if the block device is large enough
+        [ -z "$OK" -a -b $MDSDEV ] && \
+                [ "$(dd if=$MDSDEV of=/dev/null bs=1k count=1 skip=$MIN 2>&1 |
+                     awk '($3 == "in") { print $1 }')" = "1+0" ] && OK=1 && \
+                myMDSSIZE=$MIN && log "use device $MDSDEV with MIN=$MIN"
+
+        # check if a loopback device has enough space for fs metadata (5%)
+        [ -z "$OK" ] && [ -f $MDSDEV -o ! -e $MDSDEV ] &&
+                SPACE=$(df -P $(dirname $MDSDEV) |
+                        awk '($1 != "Filesystem") {print $4}') &&
+                [ $SPACE -gt $((MIN / 20)) ] && OK=1 && myMDSSIZE=$MIN && \
+                        log "use file $MDSDEV with MIN=$MIN"
+
+        [ -z "$OK" ] && skip "$MDSDEV too small for ${MIN}kB MDS" && return
+
+
         echo "mount mds with large journal..."
-        local myMDSSIZE=2000000
-        OLD_MDS_MKFS_OPTS=$MDS_MKFS_OPTS
+        local OLD_MDS_MKFS_OPTS=$MDS_MKFS_OPTS
 
         MDS_MKFS_OPTS="--mgs --mdt --fsname=$FSNAME --device-size=$myMDSSIZE --param sys.timeout=$TIMEOUT $MDSOPT"
 
@@ -700,7 +732,7 @@ test_18() {
         check_mount || return 41
 
         echo "check journal size..."
-        FOUNDSIZE=`do_facet mds "debugfs -c -R 'stat <8>' $MDSDEV" | awk '/Size: / { print $NF; exit;}'`
+        local FOUNDSIZE=`do_facet mds "debugfs -c -R 'stat <8>' $MDSDEV" | awk '/Size: / { print $NF; exit;}'`
         if [ $FOUNDSIZE -gt $((32 * 1024 * 1024)) ]; then
                 log "Success: mkfs creates large journals. Size: $((FOUNDSIZE >> 20))M"
         else
-- 
GitLab