Whamcloud - gitweb
LU-15055 lod: run qmt_pool_* only from the MDT0000 config
[fs/lustre-release.git] / lustre / tests / sanity-quota.sh
index 89ba55e..d36cefe 100755 (executable)
@@ -128,17 +128,20 @@ resetquota() {
 quota_scan() {
        local local_ugp=$1
        local local_id=$2
+       local count
 
        if [ "$local_ugp" == "a" -o "$local_ugp" == "u" ]; then
                $LFS quota -v -u $local_id $DIR
-               log "Files for user ($local_id):"
+               count=$($LFS find --user $local_id $DIR | wc -l)
+               log "Files for user ($local_id), count=$count:"
                ($LFS find --user $local_id $DIR | head -n 4 |
                        xargs stat 2>/dev/null)
        fi
 
        if [ "$local_ugp" == "a" -o "$local_ugp" == "g" ]; then
                $LFS quota -v -g $local_id $DIR
-               log "Files for group ($local_id):"
+               count=$($LFS find --group $local_id $DIR | wc -l)
+               log "Files for group ($local_id), count=$count:"
                ($LFS find --group $local_id $DIR | head -n 4 |
                        xargs stat 2>/dev/null)
        fi
@@ -146,7 +149,8 @@ quota_scan() {
        is_project_quota_supported || return 0
        if [ "$local_ugp" == "a" -o "$local_ugp" == "p" ]; then
                $LFS quota -v -p $TSTPRJID $DIR
-               log "Files for project ($TSTPRJID):"
+               count=$($LFS find --projid $TSTPRJID $DIR | wc -l)
+               log "Files for project ($TSTPRJID), count=$count:"
                ($LFS find --projid $TSTPRJID $DIR | head -n 4 |
                        xargs stat 2>/dev/null)
        fi
@@ -704,6 +708,12 @@ test_1b() {
        pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
                error "pool_add_targets failed"
 
+       # check qmt_pool_add dmesg error
+       local msg_rgx="QMT0000: can't add to $FSNAME-OST0000.*pool.*$qpool"
+       local dmesg_err
+       dmesg_err=$(do_facet mds1 dmesg | grep "$msg_rgx" | tail -1)
+       [[ -z "$dmesg_err" ]] || error "found qmt_pool_add error: $dmesg_err"
+
        $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
                error "set user quota failed"
 
@@ -1183,11 +1193,13 @@ test_2() {
        local testfile="$DIR/$tdir/$tfile-0"
        local least_qunit=$(do_facet mds1 $LCTL get_param -n \
                qmt.$FSNAME-QMT0000.md-0x0.info |
-               awk '/least qunit/{ print $3 }')
+               sed -e 's/least qunit/least_qunit/' |
+               awk '/least_qunit/{ print $2 }')
        local limit
 
        [ "$SLOW" = "no" ] && limit=$((least_qunit * 2)) ||
                limit=$((least_qunit * 1024))
+       echo "least_qunit: '$least_qunit', limit: '$limit'"
 
        local free_inodes=$(mdt_free_inodes 0)
        echo "$free_inodes free inodes on master MDT"
@@ -3590,6 +3602,68 @@ test_41() {
 }
 run_test 41 "df should return projid-specific values"
 
+test_delete_qid()
+{
+       local qslv_file=$1
+       local qtype_file=$2
+       local qtype=$3
+       local qid=$4
+       local osd="osd-ldiskfs"
+
+       [ "$ost1_FSTYPE" = zfs ] && osd="osd-zfs"
+
+       rm -f $DIR/$tdir/$tfile
+       $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile
+       chmod a+rw $DIR/$tdir/$tfile
+
+       $LFS setquota $qtype $qid -B 300M $MOUNT
+       $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 ||
+               error "failed to dd"
+
+       do_facet $SINGLEMDS \
+               "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
+                grep -E 'id: *$qid'" || error "QMT: no qid $qid is found"
+       echo $osd
+       do_facet ost1 \
+               "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
+                grep -E 'id: *$qid'" || error "QSD: no qid $qid is found"
+
+       $LFS setquota $qtype $qid --delete $MOUNT
+       do_facet $SINGLEMDS \
+               "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
+                grep -E 'id: *$qid'" && error "QMT: qid $qid is not deleted"
+       sleep 5
+       do_facet ost1 \
+               "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
+                grep -E 'id: *$qid'" && error "QSD: qid $qid is not deleted"
+
+       $LFS setquota $qtype $qid -B 500M $MOUNT
+       $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 ||
+               error "failed to dd"
+       do_facet $SINGLEMDS \
+               "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
+                grep -E 'id: *$qid'" || error "QMT: qid $pid is not recreated"
+       cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file
+       do_facet ost1 \
+               "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
+                grep -E 'id: *$qid'" || error "QSD: qid $qid is not recreated"
+}
+
+test_48()
+{
+       setup_quota_test || error "setup quota failed with $?"
+       set_ost_qtype $QTYPE || error "enable ost quota failed"
+       quota_init
+
+       test_delete_qid "quota_slave/limit_user" "glb-usr" "-u" $TSTID
+       test_delete_qid "quota_slave/limit_group" "glb-grp" "-g" $TSTID
+       is_project_quota_supported &&
+           test_delete_qid "quota_slave/limit_project" "glb-prj" "-p" "10000"
+
+       cleanup_quota_test
+}
+run_test 48 "lfs quota --delete should delete quota project ID"
+
 test_50() {
        ! is_project_quota_supported &&
                skip "Project quota is not supported"
@@ -4470,6 +4544,11 @@ get_slave_nr() {
        local qtype=$2
        local nr
 
+       wait_update_facet mds1 \
+               "$LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info \
+                       >/dev/null 2>&1 || echo foo" "" ||
+       error "mds1: failed to create quota pool $pool"
+
        do_facet mds1 $LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info |
                awk '/usr/ {getline; print $2}'
 }
@@ -5182,6 +5261,53 @@ test_78()
 }
 run_test 78 "Check fallocate increase quota usage"
 
+test_78a()
+{
+       (( $CLIENT_VERSION >= $(version_code 2.15.0) )) ||
+               skip "need client at least 2.15.0"
+       (( $OST1_VERSION >= $(version_code 2.15.0) )) ||
+               skip "need OST at least 2.15.0"
+       check_set_fallocate_or_skip
+
+       setup_quota_test || error "setup quota failed with $?"
+
+       # enable ost quota
+       set_ost_qtype $QTYPE || error "enable ost quota failed"
+
+       mkdir -p $DIR/$tdir || error "failed to create $tdir"
+
+       local projectid=5200 # Random project id to test
+
+       change_project -sp $projectid $DIR/$tdir
+
+       # setup quota limit
+       $LFS setquota -p $projectid -b25M -B25M $DIR/$tdir ||
+               error "lfs setquota project failed"
+
+       # call fallocate
+       fallocate -l 204800 $DIR/$tdir/$tfile
+
+       # Get curspace (kbytes) for $projectid
+       local kbytes=$(getquota -p $projectid global curspace)
+
+       echo "kbytes returned:$kbytes"
+
+       # For file size of 204800. We should be having roughly 200 kbytes
+       # returned. Anything alarmingly low (50 taken as arbitrary value)
+       # would bail out this TC. Also this also avoids $kbytes of 0
+       # to be used in calculation below.
+       (( $kbytes > 50 )) ||
+               error "fallocate did not use projectid. kbytes returned:$kbytes"
+
+       local expect_lo=$(($kbytes * 95 / 100)) # 5% below
+       local expect_hi=$(($kbytes * 105 / 100)) # 5% above
+
+       # Verify kbytes is 200 (204800/1024). With a permited  5% drift
+       (( $kbytes >= $expect_lo && $kbytes <= $expect_hi )) ||
+               error "fallocate did not use quota projectid correctly"
+}
+run_test 78a "Check fallocate increase projectid usage"
+
 test_79()
 {
        local qpool="qpool1"
@@ -5298,6 +5424,37 @@ test_81() {
 }
 run_test 81 "Race qmt_start_pool_recalc with qmt_pool_free"
 
+test_82()
+{
+       (( $MDS1_VERSION >= $(version_code 2.14.55) )) ||
+               skip "need MDS 2.14.55 or later"
+       is_project_quota_supported ||
+               skip "skip project quota unsupported"
+
+       setup_quota_test || error "setup quota failed with $?"
+       stack_trap cleanup_quota_test
+       quota_init
+
+       local parent_dir="$DIR/$tdir.parent"
+       local child_dir="$parent_dir/child"
+
+       mkdir -p $child_dir
+       stack_trap "chown -R 0:0 $parent_dir"
+
+       chown $TSTUSR:$TSTUSR $parent_dir ||
+               error "failed to chown on $parent_dir"
+       chown $TSTUSR2:$TSTUSRS2 $child_dir ||
+               error "failed to chown on $parent_dir"
+
+       $LFS project -p 1000 $parent_dir ||
+               error "failed to set project id on $parent_dir"
+       $LFS project -p 1001 $child_dir ||
+               error "failed to set project id on $child_dir"
+
+       rmdir $child_dir || error "cannot remove child dir, test failed"
+}
+run_test 82 "verify more than 8 qids for single operation"
+
 quota_fini()
 {
        do_nodes $(comma_list $(nodes_list)) \