Whamcloud - gitweb
LU-6875 update: set st to NULL in error handler
[fs/lustre-release.git] / lustre / tests / ost-pools.sh
index bdb0e09..a53fa90 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/bash
 # -*- mode: Bash; tab-width: 4; indent-tabs-mode: t; -*-
-# vim:autoindent:shiftwidth=4:tabstop=4:
+# vim:shiftwidth=4:softtabstop=4:tabstop=4:
 #
 # Run select tests by setting ONLY, or as arguments to the script.
 # Skip specific tests by setting EXCEPT.
@@ -29,7 +29,7 @@ init_logging
 
 check_and_setup_lustre
 
-[ "$SLOW" = "no" ] && EXCEPT_SLOW="23b"
+[ "$SLOW" = "no" ] && EXCEPT_SLOW="5b 18 22 23b 25"
 
 DIR=${DIR:-$MOUNT}
 assert_DIR
@@ -155,15 +155,15 @@ check_file_not_in_pool() {
 }
 
 check_dir_not_in_pool() {
-    local dir=$1
-    local pool=$2
-    local res=$($GETSTRIPE -v $dir | grep "^stripe_count" | head -1 |
-                cut -f 8 -d ' ')
-    if [[ "$res" == "$pool" ]]; then
-        error "File $dir is in pool: $res"
-        return 1
-    fi
-    return 0
+       local dir=$1
+       local pool=$2
+       local res=$($GETSTRIPE -v $dir | grep "^stripe_count" | head -n1 |
+               cut -f 8 -d ' ')
+       if [[ "$res" == "$pool" ]]; then
+               error "File $dir is in pool: $res"
+               return 1
+       fi
+       return 0
 }
 
 drain_pool() {
@@ -237,20 +237,20 @@ test_1b() {
     create_pool_nofail ${POOL}12
     destroy_pool ${POOL}12
 }
-run_test 1b "Create a pool with a 10 character pool name"
+run_test 1b "Create a pool with a 10 char pool name"
 
 test_1c() {
     set_cleanup_trap
-    create_pool_nofail ${POOL}12345678
-    destroy_pool ${POOL}12345678
+    create_pool_nofail ${POOL}1234567
+    destroy_pool ${POOL}1234567
 }
-run_test 1c "Create a pool with a 16 character pool name"
+run_test 1c "Create a pool with a 15 char pool name"
 
 test_1d() {
     set_cleanup_trap
-    create_pool_fail ${POOL}123456789
+    create_pool_fail ${POOL}12345678
 }
-run_test 1d "Create a pool with a 17 char pool name; should fail"
+run_test 1d "Create a pool with a 16 char pool name; should fail"
 
 test_1e() {
     set_cleanup_trap
@@ -318,6 +318,23 @@ test_1m() {
 }
 run_test 1m "pool_new did not fail even though $POOL2 existed"
 
+test_1n() {
+    set_cleanup_trap
+    create_pool_nofail ${POOL}1234567
+
+    add_pool ${POOL}1234567 "OST0000" "$FSNAME-OST0000_UUID "
+    local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
+    create_dir $POOL_ROOT ${POOL}1234567
+    dd if=/dev/zero of=$POOL_ROOT/file bs=1M count=100
+    RC=$?; [[ $RC -eq 0 ]] ||
+        error "failed to write to $POOL_ROOT/file: $RC"
+    do_facet $SINGLEMDS lctl pool_remove $FSNAME.${POOL}1234567 OST0000
+    drain_pool ${POOL}1234567
+
+    destroy_pool ${POOL}1234567
+}
+run_test 1n "Pool with a 15 char pool name works well"
+
 test_2a() {
     set_cleanup_trap
     destroy_pool $POOL
@@ -576,18 +593,18 @@ sub_test_5() {
     destroy_pool $POOL2
 }
 
-test_5() {
+test_5a() {
     set_cleanup_trap
     # Issue commands from client
-    sub_test_5 $LCTL
     sub_test_5 $LFS
+}
+run_test 5a "lfs pool_list from client"
 
-    # Issue commands from MDS
+test_5b() {
+    set_cleanup_trap
     sub_test_5 "do_facet $SINGLEMDS lctl"
-    sub_test_5 "do_facet $SINGLEMDS lfs"
-
 }
-run_test 5 "lfs/lctl pool_list"
+run_test 5b "lctl pool_list from MDS"
 
 test_6() {
     set_cleanup_trap
@@ -632,6 +649,95 @@ test_6() {
 }
 run_test 6 "getstripe/setstripe"
 
+helper_test_7a()
+{
+       # Create a pool, stripe a directory and file with it
+       local pool=$1
+
+       pool_add $pool || error "pool_add failed"
+       pool_add_targets $pool 0 1 || error "pool_add_targets failed"
+
+       $SETSTRIPE -c 1 $DIR/$tdir/testfile1 --pool "$pool" || \
+               error "setstripe failed"
+       $SETSTRIPE -c 1 $DIR/$tdir/testfile2 --pool "$FSNAME.$pool" || \
+               error "setstripe failed"
+
+       mkdir $DIR/$tdir/testdir
+       $SETSTRIPE -c 1 $DIR/$tdir/testdir  -p "$pool" || \
+               error "setstripe failed"
+       $SETSTRIPE -c 1 $DIR/$tdir/testdir  -p "$FSNAME.$pool" || \
+               error "setstripe failed"
+
+       rm -f $DIR/$tdir/testfile1
+       rm -f $DIR/$tdir/testfile2
+       rmdir $DIR/$tdir/testdir
+
+       destroy_pool_int $FSNAME.$pool
+}
+
+test_7a()
+{
+       [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
+
+       mkdir -p $DIR/$tdir
+
+       # Generate pool with random name from 1 to 15 characters
+       for i in 1 9 15 ; do
+               POOLNAME=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w $i |
+                          head -n 1)
+               echo set poolname to $POOLNAME
+               helper_test_7a $POOLNAME
+       done
+}
+run_test 7a "create various pool name"
+
+test_7b()
+{
+       # No fsname
+       do_facet mgs lctl pool_new qwerty
+       [ $? -ne 22 ] && error "can create a pool with no fsname"
+
+       # No pool name
+       do_facet mgs lctl pool_new $FSNAME.
+       [ $? -ne 22 ] && error "can create a pool with no name"
+
+       # Invalid character
+       do_facet mgs lctl pool_new $FSNAME.0123456789^bdef
+       [ $? -ne 22 ] && error "can create a pool with an invalid name"
+
+       # Too long
+       do_facet mgs lctl pool_new $FSNAME.0123456789abdefg
+       [ $? -ne 36 ] && error "can create a pool with a name too long"
+
+       return 0
+}
+run_test 7b "try to create pool name with invalid lengths or names"
+
+test_7c()
+{
+       [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
+
+       mkdir -p $DIR/$tdir
+
+       # Create a pool with 15 letters
+       local pool=0123456789abcde
+       pool_add $pool || error "pool_add failed"
+       pool_add_targets $pool 0 1 || error "pool_add_targets failed"
+
+       # setstripe with the same pool name plus 1 letter
+       $SETSTRIPE -c 1 $DIR/$tdir/testfile1 --pool "${pool}X" && \
+               error "setstripe succedeed"
+
+       # setstripe with the same pool name minus 1 letter
+       $SETSTRIPE -c 1 $DIR/$tdir/testfile1 --pool "${pool%?}" && \
+               error "setstripe succedeed"
+
+       rm -f $DIR/$tdir/testfile1
+
+       destroy_pool_int $FSNAME.$pool
+}
+run_test 7c "create a valid pool name and setstripe with a bad one"
+
 test_11() {
     set_cleanup_trap
     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
@@ -998,17 +1104,17 @@ test_18() {
     # is / should be
     max=30
     diff=$((($files1 - $files2) * 100 / $files1))
-    echo  "No pool / wide pool: $diff %."
-    [ $diff -gt $max ] &&
-        error_ignore 23408 "Degradation with wide pool is $diff% > $max%"
+       echo  "No pool / wide pool: $diff %."
+       [ $diff -gt $max ] &&
+               error_ignore bz23408 "Degradation with wide pool is $diff% > $max%"
 
-    max=30
-    diff=$((($files1 - $files3) * 100 / $files1))
-    echo  "No pool / missing pool: $diff %."
-    [ $diff -gt $max ] &&
-        error_ignore 23408 "Degradation with wide pool is $diff% > $max%"
+       max=30
+       diff=$((($files1 - $files3) * 100 / $files1))
+       echo  "No pool / missing pool: $diff %."
+       [ $diff -gt $max ] &&
+               error_ignore bz23408 "Degradation with wide pool is $diff% > $max%"
 
-    return 0
+       return 0
 }
 run_test 18 "File create in a directory which references a deleted pool"
 
@@ -1183,8 +1289,16 @@ test_23a() {
     add_pool $POOL "$FSNAME-OST[$TGT_FIRST-$TGT_MAX/3]" "$TGT"
     create_dir $dir $POOL
 
-    $LFS quotaoff -ug $MOUNT
-    $LFS quotacheck -ug $MOUNT
+       # XXX remove the interoperability code once we drop the old server
+       #     ( < 2.3.50) support.
+       if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
+               $LFS quotaoff -ug $MOUNT
+               $LFS quotacheck -ug $MOUNT
+       else
+               do_facet mgs $LCTL conf_param $FSNAME.quota.ost=ug
+               sleep 5
+       fi
+
     $LFS setquota -u $RUNAS_ID -b $LIMIT -B $LIMIT $dir
     sleep 3
     $LFS quota -v -u $RUNAS_ID $dir
@@ -1229,8 +1343,6 @@ test_23b() {
 
     local i=0
     local TGT
-    local BUNIT_SZ=1024  # min block quota unit(kB)
-    local LIMIT=$((BUNIT_SZ * (OSTCOUNT + 1)))
     local dir=$POOL_ROOT/dir
     local file="$dir/$tfile-quota"
 
@@ -1241,36 +1353,65 @@ test_23b() {
     add_pool $POOL "$FSNAME-OST[$TGT_FIRST-$TGT_MAX/3]" "$TGT"
     create_dir $dir $POOL
 
-    AVAIL=$($LFS df -p $POOL $dir | awk '/summary/ { print $4 }')
-    [ $AVAIL -gt $MAXFREE ] &&
-        skip_env "Filesystem space $AVAIL is larger than $MAXFREE limit" &&
-            return 0
-    log "OSTCOUNT=$OSTCOUNT, OSTSIZE=$OSTSIZE"
-    log "MAXFREE=$MAXFREE, AVAIL=$AVAIL, SLOW=$SLOW"
-
-    $LFS quotaoff -ug $MOUNT
-    chown $RUNAS_ID.$RUNAS_ID $dir
-    i=0
-    RC=0
-    while [ $RC -eq 0 ]; do
-        i=$((i + 1))
-        stat=$(LOCALE=C $RUNAS2 dd if=/dev/zero of=${file}$i bs=1M \
-               count=$((LIMIT * 4)) 2>&1)
-        RC=$?
-               echo "$i: $stat"
-        if [ $RC -eq 1 ]; then
-            echo $stat | grep -q "Disk quota exceeded"
-            [[ $? -eq 0 ]] && error "dd failed with EDQUOT with quota off"
-
-            echo $stat | grep -q "No space left on device"
-            [[ $? -ne 0 ]] &&
-                error "dd did not fail with ENOSPC"
-        fi
-    done
-
-    df -h
-
-    rm -rf $POOL_ROOT
+       local maxfree=$((1024 * 1024 * 30)) # 30G
+       local AVAIL=$(lfs_df -p $POOL $dir | awk '/summary/ { print $4 }')
+       [ $AVAIL -gt $maxfree ] &&
+               skip_env "Filesystem space $AVAIL is larger than " \
+                       "$maxfree limit" && return 0
+
+       echo "OSTCOUNT=$OSTCOUNT, OSTSIZE=$OSTSIZE, AVAIL=$AVAIL"
+       echo "MAXFREE=$maxfree, SLOW=$SLOW"
+
+       # XXX remove the interoperability code once we drop the old server
+       #     ( < 2.3.50) support.
+       if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
+               $LFS quotaoff -ug $MOUNT
+       else
+               do_facet mgs $LCTL conf_param $FSNAME.quota.ost=none
+               sleep 5
+       fi
+
+       chown $RUNAS_ID.$RUNAS_ID $dir
+       i=0
+       local RC=0
+       local TOTAL=0 # KB
+       local stime=$(date +%s)
+       local stat
+       local etime
+       local elapsed
+       local maxtime=300 # minimum speed: 5GB / 300sec ~= 17MB/s
+       while [ $RC -eq 0 ]; do
+               i=$((i + 1))
+               stat=$(LOCALE=C $RUNAS2 dd if=/dev/zero of=${file}$i bs=1M \
+                       count=$((5 * 1024)) 2>&1)
+               RC=$?
+               TOTAL=$((TOTAL + 1024 * 1024 * 5))
+               echo "[$i iteration] $stat"
+               echo "total written: $TOTAL"
+
+               etime=$(date +%s)
+               elapsed=$((etime - stime))
+               echo "stime=$stime, etime=$etime, elapsed=$elapsed"
+
+               if [ $RC -eq 1 ]; then
+                       echo $stat | grep -q "Disk quota exceeded"
+                       [[ $? -eq 0 ]] &&
+                               error "dd failed with EDQUOT with quota off"
+
+                       echo $stat | grep -q "No space left on device"
+                       [[ $? -ne 0 ]] &&
+                               error "dd did not fail with ENOSPC"
+               elif [ $TOTAL -gt $AVAIL ]; then
+                       error "dd didn't fail with ENOSPC ($TOTAL > $AVAIL)"
+               elif [ $i -eq 1 -a $elapsed -gt $maxtime ]; then
+                       log "The first 5G write used $elapsed (> $maxtime) " \
+                               "seconds, terminated"
+                       RC=1
+               fi
+       done
+
+       df -h
+       rm -rf $POOL_ROOT
 }
 run_test 23b "OST pools and OOS"
 
@@ -1353,7 +1494,6 @@ run_test 24 "Independence of pool from other setstripe parameters"
 
 test_25() {
     set_cleanup_trap
-    local dev=$(mdsdevname ${SINGLEMDS//mds/})
     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
 
     mkdir -p $POOL_ROOT
@@ -1365,11 +1505,9 @@ test_25() {
             sort -u | tr '\n' ' ' " "$FSNAME-OST0000_UUID " >/dev/null ||
                 error "pool_add failed: $1; $2"
 
-        stop $SINGLEMDS || return 1
-        start $SINGLEMDS ${dev} $MDS_MOUNT_OPTS ||
-            { error "Failed to start $SINGLEMDS after stopping" && break; }
-        wait_osc_import_state mds ost FULL
-        clients_up
+       facet_failover $SINGLEMDS || error "failed to failover $SINGLEMDS"
+       wait_osc_import_state $SINGLEMDS ost FULL
+       clients_up
 
         wait_mds_ost_sync
         # Veriy that the pool got created and is usable
@@ -1431,7 +1569,7 @@ run_test 26 "Choose other OSTs in the pool first in the creation remedy"
 
 cd $ORIG_PWD
 
-complete $(basename $0) $SECONDS
+complete $SECONDS
 cleanup_pools $FSNAME
 check_and_cleanup_lustre
 exit_status