Whamcloud - gitweb
Branch head
[fs/lustre-release.git] / lustre / tests / sanity-quota.sh
index 1f2ca61..92a0080 100644 (file)
@@ -155,25 +155,25 @@ mounted_lustre_filesystems() {
 
 # Remember where our caller has hinted that we should mount lustre
 MOUNT_HINT=$MOUNT
-MOUNT_HINT2=$MOUNT2
+MOUNT_HINT2=$MOUNT_2
 MOUNT="`mounted_lustre_filesystems 1`"
-MOUNT2="`mounted_lustre_filesystems 2`"
+MOUNT_2="`mounted_lustre_filesystems 2`"
 if [ $TEST_9_10 -eq 1 -a "$MOUNT" ]; then
         echo "test9 and test10 will run on $MOUNT"
-elif [ "$MOUNT" -a "$MOUNT2" ]; then
-       echo "testing on $MOUNT and $MOUNT2"
-elif [ "$MOUNT" -o "$MOUNT2" ]; then
-        error "test needs two mounts, only found $MOUNT $MOUNT2!"
+elif [ "$MOUNT" -a "$MOUNT_2" ]; then
+       echo "testing on $MOUNT and $MOUNT_2"
+elif [ "$MOUNT" -o "$MOUNT_2" ]; then
+        error "test needs two mounts, only found $MOUNT $MOUNT_2!"
 else
        export QUOTA_OPTS="quotaon=ug"
        export MOUNT=$MOUNT_HINT 
-       export MOUNT2=$MOUNT_HINT2
-       MOUNT2=${MOUNT2:-/mnt/lustre2}
+       export MOUNT_2=$MOUNT_HINT2
+       MOUNT_2=${MOUNT_2:-/mnt/lustre_2}
        sh llmount.sh 
        MOUNT="`mounted_lustre_filesystems 1`"
-       MOUNT2="`mounted_lustre_filesystems 2`"
+       MOUNT_2="`mounted_lustre_filesystems 2`"
        [ -z "$MOUNT" ] && error "NAME=$MOUNT not mounted"
-       [ -z "$MOUNT2" ] && error "NAME=$MOUNT2 not mounted"
+       [ -z "$MOUNT_2" ] && error "NAME=$MOUNT_2 not mounted"
        I_MOUNTED=yes
 fi
 
@@ -181,7 +181,7 @@ fi
 
 DIR=${DIR:-$MOUNT}
 [ -z "`echo $DIR | grep $MOUNT`" ] && echo "$DIR not in $MOUNT" && exit 99
-DIR2=${DIR2:-$MOUNT2}
+DIR2=${DIR2:-$MOUNT_2}
 
 LPROC=/proc/fs/lustre
 LOVNAME=`cat $LPROC/llite/*/lov/common_name | tail -n 1`
@@ -194,7 +194,7 @@ STRIPECOUNT=`cat $LPROC/lov/$LOVNAME/stripecount`
 STRIPESIZE=`cat $LPROC/lov/$LOVNAME/stripesize`
 ORIGFREE=`cat $LPROC/lov/$LOVNAME/kbytesavail`
 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
-MDS=$(\ls $LPROC/mds 2> /dev/null | grep -v num_refs | tail -n 1)
+MDS=$(\ls $LPROC/mdt 2> /dev/null | grep -v num_refs | tail -n 1)
 TSTDIR=$DIR/quota_test_dir
 TSTDIR2=$DIR2/quota_test_dir
 SHOW_QUOTA_USER="$LFS quota -u $TSTUSR $MOUNT"
@@ -280,27 +280,27 @@ post_test() {
 
 setup() {
        # create local test group
-       GRP="`cat /etc/group | grep "$TSTUSR" | awk -F: '{print $1}'`"
+       GRP="`cat /etc/group | grep "^${TSTUSR}:" | awk -F: '{print $1}'`"
        if [ -z "$GRP" ]; then
                groupadd -g $TSTID "$TSTUSR"
        fi
-       TSTID="`cat /etc/group | grep "$TSTUSR" | awk -F: '{print $3}'`"
+       TSTID="`cat /etc/group | grep "^${TSTUSR}:" | awk -F: '{print $3}'`"
 
-        GRP2="`cat /etc/group | grep "$TSTUSR2" | awk -F: '{print $1}'`"
+        GRP2="`cat /etc/group | grep "^${TSTUSR2}:" | awk -F: '{print $1}'`"
         if [ -z "$GRP2" ]; then
                 groupadd -g $TSTID2 "$TSTUSR2"
         fi
-        TSTID2="`cat /etc/group | grep "$TSTUSR2" | awk -F: '{print $3}'`"
+        TSTID2="`cat /etc/group | grep "^${TSTUSR2}:" | awk -F: '{print $3}'`"
 
        # create test user
-       USR="`cat /etc/passwd | grep "$TSTUSR" | awk -F: '{print $1}'`"
+       USR="`cat /etc/passwd | grep "^${TSTUSR}:" | awk -F: '{print $1}'`"
        if [ -z "$USR" ]; then
                useradd -u $TSTID -g $TSTID -d /tmp "$TSTUSR"
        fi
        
        RUNAS="runas -u $TSTID"
 
-       USR2="`cat /etc/passwd | grep "$TSTUSR2" | awk -F: '{print $1}'`"
+       USR2="`cat /etc/passwd | grep "^${TSTUSR2}:" | awk -F: '{print $1}'`"
         if [ -z "$USR2" ]; then
                 useradd -u $TSTID2 -g $TSTID2 -d /tmp "$TSTUSR2"
         fi
@@ -617,7 +617,7 @@ test_6() {
                return 0;
        fi
 
-       LIMIT=$((BUNIT_SZ * (OSTCOUNT + 1) * 5)) # 5 bunits per server
+       LIMIT=$(($BUNIT_SZ * $(($OSTCOUNT + 1)) * 5)) # 5 bunits per server
        FILEA="$TSTDIR/quota_tst60_a"
        FILEB="$TSTDIR/quota_tst60_b"
        
@@ -712,8 +712,8 @@ test_7()
        [ $TOTAL_LIMIT -eq $LIMIT ] || error "total limits not recovery!"
        echo "  total limits = $TOTAL_LIMIT"
        
-       OST0_UUID=`$LCTL dl | awk '$3 ~ /obdfilter/ { print $5 }'| head -n1`
-       [ -z "$OST0_UUID" ] && OST0_UUID=`$LCTL dl | awk '$3 ~ /obdfilter/ { print $5 }'|head -n1`
+        OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
+        [ -z "$OST0_UUID" ] && OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
        OST0_LIMIT="`$LFS quota -o $OST0_UUID -u $TSTUSR $MOUNT | awk '/^.*[[:digit:]+][[:space:]+]/ { print $3 }'`"
        [ $OST0_LIMIT -eq $BUNIT_SZ ] || error "high limits not released!"
        echo "  limits on $OST0_UUID = $OST0_LIMIT"
@@ -1043,8 +1043,6 @@ test_13() {
        $SHOW_QUOTA_USER
        [ $((fz + fz2)) -lt $((BUNIT_SZ * BLK_SZ * 10)) ] && \
                error "files too small $fz + $fz < $((BUNIT_SZ * BLK_SZ * 10))"
-       [ $((fz + fz2)) -gt $((BUNIT_SZ * BLK_SZ * 11)) ] && \
-               error "files too large $fz + $fz > $((BUNIT_SZ * BLK_SZ * 11))"
 
        rm -f $TESTFILE $TESTFILE.2
        
@@ -1052,6 +1050,56 @@ test_13() {
 }
 run_test 13 "test multiple clients write block quota ==="
 
+check_if_quota_zero(){
+        line=`$LFS quota -$1 $2 $MOUNT | wc -l`
+       for i in `seq 3 $line`; do
+           for j in 3 4 6 7; do
+               tmp=`$LFS quota -$1 $2 $MOUNT | sed -n ${i}p | 
+                     awk  '{print $'"$j"'}'`
+               [ -n "$tmp" ] && [ $tmp -ne 0 ] && $LFS quota -$1 $2 $MOUNT && \
+                   error "quota on $1 isn't clean"
+           done
+       done
+       echo "pass check_if_quota_zero"
+}
+
+# test setting quota on root, b=12223
+test_13(){
+        TESTFILE="$TSTDIR/quota_tst13"
+
+       # reboot the lustre
+       cd $T_PWD; sh llmountcleanup.sh || error "llmountcleanup failed"
+       sh llmount.sh 
+       pre_test
+       setup
+       run_test 0 "reboot lustre"
+
+       # out of root's file and block quota
+        $LFS setquota -u root 10 10 10 10 $MOUNT
+       createmany -m ${TESTFILE} 20 || \
+           error "unexpected: user(root) create files failly!"
+       dd if=/dev/zero of=$TESTFILE bs=4k count=4096 || \
+           error "unexpected: user(root) write files failly!"
+       chmod 666 $TESTFILE
+       $RUNAS dd if=/dev/zero of=${TESTFILE} seek=4096 bs=4k count=4096 && \
+           error "unexpected: user(quota_usr) write a file successfully!"      
+
+       # trigger the llog
+       chmod 777 $MOUNT
+       for i in `seq 1 10`; do $RUNAS touch ${TESTFILE}a_$i; done 
+       for i in `seq 1 10`; do $RUNAS rm -f ${TESTFILE}a_$i; done 
+
+       # do the check
+       dmesg | tail | grep "\-122" |grep llog_obd_origin_add && error "test_13 failed."
+       $LFS setquota -u root 0 0 0 0 $MOUNT
+       #check_if_quota_zero u root
+
+       # clean 
+       unlinkmany ${TESTFILE} 15
+       rm -f $TESTFILE
+}
+run_test 13 "test setting quota on root ==="
+
 # turn off quota
 test_99()
 {