+ echo "Start mds..."
+ start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
+ quota_init
+
+ # wait longer than usual to make sure the reintegration
+ # is triggered by quota wb thread.
+ wait_ost_reint $QTYPE 200 || error "reintegration failed"
+
+ # hardlimit should have been fetched by slave during global
+ # reintegration, write will exceed quota
+ $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
+ quota_error u $TSTUSR "write success, but expect EDQUOT"
+
+ cleanup_quota_test
+}
+run_test 7c "Quota reintegration (restart mds during reintegration)"
+
+# Quota reintegration (Transfer index in multiple bulks)
+test_7d(){
+ local TESTFILE=$DIR/$tdir/$tfile
+ local TESTFILE1="$DIR/$tdir/$tfile"-1
+ local limit=20 #20M
+
+ setup_quota_test || error "setup quota failed with $?"
+ trap cleanup_quota_test EXIT
+
+ set_ost_qtype "none" || error "disable ost quota failed"
+ $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
+ error "set quota for $TSTUSR failed"
+ $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
+ error "set quota for $TSTUSR2 failed"
+
+ #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
+ lustre_fail mds 0x608 0
+
+ # enable quota to tirgger reintegration
+ set_ost_qtype "u" || error "enable ost quota failed"
+ wait_ost_reint "u" || error "reintegration failed"
+
+ lustre_fail mds 0
+
+ # hardlimit should have been fetched by slave during global
+ # reintegration, write will exceed quota
+ $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
+ quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
+
+ $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
+ quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
+
+ cleanup_quota_test
+}
+run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
+
+# quota reintegration (inode limits)
+test_7e() {
+ [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
+
+ # LU-2435: skip this quota test if underlying zfs version has not
+ # supported native dnode accounting
+ [ "$mds1_FSTYPE" == zfs ] && {
+ local F="feature@userobj_accounting"
+ local pool=$(zpool_name mds1)
+ local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
+
+ [[ "$feature" != *" active "* ]] &&
+ skip "requires zpool with active userobj_accounting"
+ }
+
+ local ilimit=$((1024 * 2)) # 2k inodes
+ local TESTFILE=$DIR/${tdir}-1/$tfile
+
+ setup_quota_test || error "setup quota failed with $?"
+ trap cleanup_quota_test EXIT
+
+ # make sure the system is clean
+ local USED=$(getquota -u $TSTUSR global curinodes)
+ [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
+
+ # make sure no granted quota on mdt1
+ set_mdt_qtype $QTYPE || error "enable mdt quota failed"
+ resetquota -u $TSTUSR
+ set_mdt_qtype "none" || error "disable mdt quota failed"
+
+ local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
+ USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
+ [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
+ "$TSTUSR isn't 0."
+
+ echo "Stop mds${MDSCOUNT}..."
+ stop mds${MDSCOUNT}
+
+ echo "Enable quota & set quota limit for $TSTUSR"
+ set_mdt_qtype $QTYPE || error "enable mdt quota failed"
+ $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
+ error "set quota failed"
+
+ echo "Start mds${MDSCOUNT}..."
+ start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
+ quota_init
+
+ wait_mdt_reint $QTYPE || error "reintegration failed"
+
+ echo "create remote dir"
+ $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
+ error "create remote dir failed"
+ chmod 0777 $DIR/${tdir}-1
+
+ # hardlimit should have been fetched by slave during global
+ # reintegration, create will exceed quota
+ $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
+ quota_error u $TSTUSR "create succeeded, expect EDQUOT"
+
+ $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
+ wait_delete_completed
+ sync_all_data || true
+
+ echo "Stop mds${MDSCOUNT}..."
+ stop mds${MDSCOUNT}
+
+ $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
+ error "clear quota failed"
+
+ echo "Start mds${MDSCOUNT}..."
+ start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
+ quota_init
+
+ wait_mdt_reint $QTYPE || error "reintegration failed"
+
+ # hardlimit should be cleared on slave during reintegration
+ $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
+ quota_error u $TSTUSR "create failed, expect success"
+
+ $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
+ rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
+
+ cleanup_quota_test
+}
+run_test 7e "Quota reintegration (inode limits)"
+
+# run dbench with quota enabled
+test_8() {
+ local BLK_LIMIT="100g" #100G
+ local FILE_LIMIT=1000000
+
+ setup_quota_test || error "setup quota failed with $?"
+ trap cleanup_quota_test EXIT
+
+ set_mdt_qtype $QTYPE || error "enable mdt quota failed"
+ set_ost_qtype $QTYPE || error "enable ost quota failed"
+
+ echo "Set enough high limit for user: $TSTUSR"
+ $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
+ error "set user quota failed"
+ echo "Set enough high limit for group: $TSTUSR"
+ $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
+ error "set group quota failed"
+ if is_project_quota_supported; then
+ change_project -sp $TSTPRJID $DIR/$tdir
+ echo "Set enough high limit for project: $TSTPRJID"
+ $LFS setquota -p $TSTPRJID -b 0 \
+ -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
+ error "set project quota failed"
+ fi
+
+ local duration=""
+ [ "$SLOW" = "no" ] && duration=" -t 120"
+ $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
+ quota_error a $TSTUSR "dbench failed!"
+
+ is_project_quota_supported && change_project -C $DIR/$tdir
+ cleanup_quota_test
+}
+run_test 8 "Run dbench with quota enabled"
+
+# this check is just for test_9
+OST0_MIN=4900000 #4.67G
+
+check_whether_skip () {
+ local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
+ log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
+ if [ $OST0_SIZE -lt $OST0_MIN ]; then
+ echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
+ return 0
+ else
+ return 1
+ fi
+}
+
+# run for fixing bug10707, it needs a big room. test for 64bit
+test_9() {
+ local filesize=$((1024 * 9 / 2)) # 4.5G
+
+ check_whether_skip && return 0
+
+ setup_quota_test || error "setup quota failed with $?"
+ trap cleanup_quota_test EXIT
+
+ set_ost_qtype "ug" || error "enable ost quota failed"
+
+ local TESTFILE="$DIR/$tdir/$tfile-0"
+ local BLK_LIMIT=100G #100G
+ local FILE_LIMIT=1000000
+
+ echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
+
+ log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
+ "for user: $TSTUSR"
+ $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
+ error "set user quota failed"
+
+ log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
+ "for group: $TSTUSR"
+ $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
+ error "set group quota failed"
+
+ quota_show_check a u $TSTUSR
+ quota_show_check a g $TSTUSR
+
+ echo "Create test file"
+ $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
+ chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
+
+ log "Write the big file of 4.5G ..."
+ $RUNAS $DD of=$TESTFILE count=$filesize ||
+ quota_error a $TSTUSR "write 4.5G file failure, expect success"
+
+ $SHOW_QUOTA_USER
+ $SHOW_QUOTA_GROUP
+
+ cleanup_quota_test
+
+ $SHOW_QUOTA_USER
+ $SHOW_QUOTA_GROUP
+}
+run_test 9 "Block limit larger than 4GB (b10707)"
+
+test_10() {
+ local TESTFILE=$DIR/$tdir/$tfile
+
+ setup_quota_test || error "setup quota failed with $?"
+ trap cleanup_quota_test EXIT
+
+ # set limit to root user should fail
+ $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
+ error "set limit for root user successfully, expect failure"
+ $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
+ error "set limit for root group successfully, expect failure"
+ $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
+ error "set limit for project 0 successfully, expect failure"
+
+ # root user can overrun quota
+ set_ost_qtype "ug" || error "enable ost quota failed"
+
+ $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
+ error "set quota failed"
+ quota_show_check b u $TSTUSR
+
+ $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
+ chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
+
+ runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
+ error "write failure, expect success"
+
+ cleanup_quota_test
+}
+run_test 10 "Test quota for root user"
+
+test_11() {
+ local TESTFILE=$DIR/$tdir/$tfile
+ setup_quota_test || error "setup quota failed with $?"
+ trap cleanup_quota_test EXIT
+
+ set_mdt_qtype "ug" || error "enable mdt quota failed"
+ $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
+ error "set quota failed"
+
+ touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
+ touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
+
+ chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
+ chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
+
+ $SHOW_QUOTA_USER
+ local USED=$(getquota -u $TSTUSR global curinodes)
+ [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
+
+ cleanup_quota_test
+}
+run_test 11 "Chown/chgrp ignores quota"
+
+test_12a() {
+ [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
+
+ local blimit=22 # 22M
+ local blk_cnt=$((blimit - 5))
+ local TESTFILE0="$DIR/$tdir/$tfile"-0
+ local TESTFILE1="$DIR/$tdir/$tfile"-1
+
+ setup_quota_test || error "setup quota failed with $?"
+ trap cleanup_quota_test EXIT
+
+ set_ost_qtype "u" || error "enable ost quota failed"
+ quota_show_check b u $TSTUSR
+
+ $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
+ error "set quota failed"
+
+ $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
+ $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
+ chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
+ chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
+
+ echo "Write to ost0..."
+ $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
+ quota_error a $TSTUSR "dd failed"
+
+ echo "Write to ost1..."
+ $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
+ quota_error a $TSTUSR "dd succeed, expect EDQUOT"
+
+ echo "Free space from ost0..."
+ rm -f $TESTFILE0
+ wait_delete_completed
+ sync_all_data || true
+
+ echo "Write to ost1 after space freed from ost0..."
+ $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
+ quota_error a $TSTUSR "rebalancing failed"
+
+ cleanup_quota_test
+}
+run_test 12a "Block quota rebalancing"
+
+test_12b() {
+ [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
+
+ local ilimit=$((1024 * 2)) # 2k inodes
+ local TESTFILE0=$DIR/$tdir/$tfile
+ local TESTFILE1=$DIR/${tdir}-1/$tfile
+
+ setup_quota_test || error "setup quota failed with $?"
+ trap cleanup_quota_test EXIT
+
+ $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
+ chmod 0777 $DIR/${tdir}-1
+
+ set_mdt_qtype "u" || error "enable mdt quota failed"
+ quota_show_check f u $TSTUSR
+
+ $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
+ error "set quota failed"
+
+ echo "Create $ilimit files on mdt0..."
+ $RUNAS createmany -m $TESTFILE0 $ilimit ||
+ quota_error u $TSTUSR "create failed, but expect success"
+
+ echo "Create files on mdt1..."
+ $RUNAS createmany -m $TESTFILE1 1 &&
+ quota_error a $TSTUSR "create succeeded, expect EDQUOT"
+
+ echo "Free space from mdt0..."
+ $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
+ wait_delete_completed
+ sync_all_data || true
+
+ echo "Create files on mdt1 after space freed from mdt0..."
+ $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
+ quota_error a $TSTUSR "rebalancing failed"
+
+ $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
+ error "unlink mdt1 files failed"
+ rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
+
+ cleanup_quota_test
+}
+run_test 12b "Inode quota rebalancing"
+
+test_13(){
+ local TESTFILE=$DIR/$tdir/$tfile
+ # the name of lwp on ost1 name is MDT0000-lwp-OST0000
+ local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
+
+ setup_quota_test || error "setup quota failed with $?"
+ trap cleanup_quota_test EXIT
+
+ set_ost_qtype "u" || error "enable ost quota failed"
+ quota_show_check b u $TSTUSR
+
+ $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
+ error "set quota failed"
+ $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
+ chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
+
+ # clear the locks in cache first
+ do_facet ost1 $LCTL set_param -n $procf=clear
+ local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
+ [ $nlock -eq 0 ] || error "$nlock cached locks"
+
+ # write to acquire the per-ID lock
+ $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
+ quota_error a $TSTUSR "dd failed"
+
+ nlock=$(do_facet ost1 $LCTL get_param -n $procf)
+ [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
+
+ # clear quota doesn't trigger per-ID lock cancellation
+ resetquota -u $TSTUSR
+ nlock=$(do_facet ost1 $LCTL get_param -n $procf)
+ [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
+
+ # clear the per-ID lock
+ do_facet ost1 $LCTL set_param -n $procf=clear
+ nlock=$(do_facet ost1 $LCTL get_param -n $procf)
+ [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
+
+ # spare quota should be released
+ local OSTUUID=$(ostuuid_from_index 0)
+ local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
+ local space=$(getquota -u $TSTUSR $OSTUUID curspace)
+ [ $limit -le $space ] ||
+ error "spare quota isn't released, limit:$limit, space:$space"
+
+ cleanup_quota_test
+}
+run_test 13 "Cancel per-ID lock in the LRU list"
+
+test_15(){
+ local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
+
+ wait_delete_completed
+ sync_all_data || true
+
+ # test for user
+ $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
+ error "set user quota failed"
+ local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
+ [ $TOTAL_LIMIT -eq $LIMIT ] ||
+ error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
+ resetquota -u $TSTUSR
+
+ # test for group
+ $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
+ error "set group quota failed"
+ TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
+ [ $TOTAL_LIMIT -eq $LIMIT ] ||
+ error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
+ resetquota -g $TSTUSR
+}
+run_test 15 "Set over 4T block quota"
+
+test_17sub() {
+ local err_code=$1
+ local BLKS=1 # 1M less than limit
+ local TESTFILE=$DIR/$tdir/$tfile
+
+ setup_quota_test || error "setup quota failed with $?"
+ trap cleanup_quota_test EXIT
+
+ # make sure the system is clean
+ local USED=$(getquota -u $TSTUSR global curspace)
+ [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
+
+ set_ost_qtype "ug" || error "enable ost quota failed"
+ # make sure no granted quota on ost
+ resetquota -u $TSTUSR
+ $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
+ error "set quota failed"
+
+ quota_show_check b u $TSTUSR
+
+ #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
+ lustre_fail mds 0xa04 $err_code
+
+ # write in background
+ $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
+ local DDPID=$!
+
+ sleep 2
+ # write should be blocked and never finished
+ if ! ps -p $DDPID > /dev/null 2>&1; then
+ lustre_fail mds 0 0
+ quota_error u $TSTUSR "write finished incorrectly!"
+ fi
+
+ lustre_fail mds 0 0
+
+ local count=0
+ local timeout=30
+ while [ true ]; do
+ if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
+ count=$((count+1))
+ if [ $count -gt $timeout ]; then
+ quota_error u $TSTUSR "dd is not finished!"
+ fi
+ sleep 1
+ done
+
+ sync; sync_all_data || true
+
+ USED=$(getquota -u $TSTUSR global curspace)
+ [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
+ "Used space(${USED}K) is less than ${BLKS}M"
+
+ cleanup_quota_test
+}
+
+# DQACQ return recoverable error
+test_17() {
+ echo "DQACQ return -ENOLCK"
+ #define ENOLCK 37
+ test_17sub 37 || error "Handle -ENOLCK failed"
+
+ echo "DQACQ return -EAGAIN"
+ #define EAGAIN 11
+ test_17sub 11 || error "Handle -EAGAIN failed"
+
+ echo "DQACQ return -ETIMEDOUT"
+ #define ETIMEDOUT 110
+ test_17sub 110 || error "Handle -ETIMEDOUT failed"
+
+ echo "DQACQ return -ENOTCONN"
+ #define ENOTCONN 107
+ test_17sub 107 || error "Handle -ENOTCONN failed"
+}
+
+run_test 17 "DQACQ return recoverable error"
+
+test_18_sub () {
+ local io_type=$1
+ local blimit="200m" # 200M
+ local TESTFILE="$DIR/$tdir/$tfile"
+
+ setup_quota_test || error "setup quota failed with $?"
+ trap cleanup_quota_test EXIT
+
+ set_ost_qtype "u" || error "enable ost quota failed"
+ log "User quota (limit: $blimit)"
+ $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
+ error "set quota failed"
+ quota_show_check b u $TSTUSR
+
+ $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
+ chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
+
+ local timeout=$(sysctl -n lustre.timeout)
+
+ if [ $io_type = "directio" ]; then
+ log "Write 100M (directio) ..."
+ $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
+ else
+ log "Write 100M (buffered) ..."
+ $RUNAS $DD of=$TESTFILE count=100 &
+ fi
+ local DDPID=$!
+
+ replay_barrier $SINGLEMDS
+ log "Fail mds for $((2 * timeout)) seconds"
+ fail $SINGLEMDS $((2 * timeout))
+
+ local count=0
+ if at_is_enabled; then
+ timeout=$(at_max_get mds)
+ else
+ timeout=$(lctl get_param -n timeout)
+ fi
+
+ while [ true ]; do
+ if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
+ if [ $((++count % (2 * timeout) )) -eq 0 ]; then
+ log "it took $count second"
+ fi
+ sleep 1
+ done
+
+ log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
+ sync
+ cancel_lru_locks mdc
+ cancel_lru_locks osc
+ $SHOW_QUOTA_USER
+
+ local testfile_size=$(stat -c %s $TESTFILE)
+ if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
+ quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
+ "got ${testfile_size}. Verifying file failed!"
+ fi
+ cleanup_quota_test
+}
+
+# test when mds does failover, the ost still could work well
+# this test shouldn't trigger watchdog b=14840
+test_18() {
+ # Clear dmesg so watchdog is not triggered by previous
+ # test output
+ do_facet ost1 dmesg -c > /dev/null
+
+ test_18_sub normal
+ test_18_sub directio
+
+ # check if watchdog is triggered
+ do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
+ local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
+ { print; }' $TMP/lustre-log-${TESTNAME}.log)
+ [ -z "$watchdog" ] || error "$watchdog"
+ rm -f $TMP/lustre-log-${TESTNAME}.log
+}
+run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
+
+test_19() {
+ local blimit=5 # 5M
+ local TESTFILE=$DIR/$tdir/$tfile
+
+ setup_quota_test || error "setup quota failed with $?"
+ trap cleanup_quota_test EXIT
+
+ set_ost_qtype $QTYPE || error "enable ost quota failed"
+
+ # bind file to a single OST
+ $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
+ chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
+
+ echo "Set user quota (limit: ${blimit}M)"
+ $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
+ error "set user quota failed"
+ quota_show_check b u $TSTUSR
+ echo "Update quota limits"
+ $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
+ error "set group quota failed"
+ quota_show_check b u $TSTUSR
+
+ # first wirte might be cached
+ $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
+ cancel_lru_locks osc
+ $SHOW_QUOTA_USER
+ $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
+ quota_error u $TSTUSR "Write success, expect failure"
+ $SHOW_QUOTA_USER
+
+ cleanup_quota_test
+}
+run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
+
+test_20() { # b15754
+ local LSTR=(2g 1t 4k 3m) # limits strings
+ # limits values
+ local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
+ $((3*1024*1024)))
+
+ resetquota -u $TSTUSR
+
+ $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
+ $MOUNT || error "could not set quota limits"
+ $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
+ --inode-softlimit ${LSTR[2]} \
+ --inode-hardlimit ${LSTR[3]} \
+ $MOUNT || error "could not set quota limits"
+
+ [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
+ error "bsoftlimit was not set properly"
+ [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
+ error "bhardlimit was not set properly"
+ [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
+ error "isoftlimit was not set properly"
+ [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
+ error "ihardlimit was not set properly"
+
+ resetquota -u $TSTUSR
+}
+run_test 20 "Test if setquota specifiers work properly (b15754)"
+
+test_21_sub() {
+ local testfile=$1
+ local blk_number=$2
+ local seconds=$3
+
+ local time=$(($(date +%s) + seconds))
+ while [ $(date +%s) -lt $time ]; do
+ $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
+ done
+}
+
+# run for fixing bug16053, setquota shouldn't fail when writing and
+# deleting are happening
+test_21() {
+ local TESTFILE="$DIR/$tdir/$tfile"
+ local BLIMIT=10 # 10G
+ local ILIMIT=1000000
+
+ setup_quota_test || error "setup quota failed with $?"
+ trap cleanup_quota_test EXIT
+
+ set_ost_qtype $QTYPE || error "Enable ost quota failed"
+
+ log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
+ $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
+ error "set user quota failed"
+ log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
+ $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
+ error "set group quota failed"
+ if is_project_quota_supported; then
+ log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
+ "project: $TSTPRJID"
+ $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
+ $MOUNT || error "set project quota failed"
+ fi
+
+ # repeat writing on a 1M file
+ test_21_sub ${TESTFILE}_1 1 30 &
+ local DDPID1=$!
+ # repeat writing on a 128M file
+ test_21_sub ${TESTFILE}_2 128 30 &
+ local DDPID2=$!
+
+ local time=$(($(date +%s) + 30))
+ local i=1
+ while [ $(date +%s) -lt $time ]; do
+ log "Set quota for $i times"
+ $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
+ -I $((ILIMIT + i)) $MOUNT ||
+ error "Set user quota failed"
+ $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
+ -I $((ILIMIT + i)) $MOUNT ||
+ error "Set group quota failed"
+ if is_project_quota_supported; then
+ $LFS setquota -p $TSTPRJID -b 0 -B \
+ "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
+ error "Set project quota failed"
+ fi
+ i=$((i+1))
+ sleep 1
+ done
+
+ local count=0
+ while [ true ]; do
+ if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
+ count=$((count+1))
+ if [ $count -gt 60 ]; then
+ quota_error a $TSTUSR "dd should be finished!"
+ fi
+ sleep 1
+ done
+ echo "(dd_pid=$DDPID1, time=$count)successful"
+
+ count=0
+ while [ true ]; do
+ if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
+ count=$((count+1))
+ if [ $count -gt 60 ]; then
+ quota_error a $TSTUSR "dd should be finished!"
+ fi
+ sleep 1
+ done
+ echo "(dd_pid=$DDPID2, time=$count)successful"
+
+ cleanup_quota_test
+}
+run_test 21 "Setquota while writing & deleting (b16053)"
+
+# enable/disable quota enforcement permanently
+test_22() {
+ echo "Set both mdt & ost quota type as ug"
+ local qtype="ug"
+ is_project_quota_supported && qtype=$QTYPE
+ set_mdt_qtype $qtype || error "enable mdt quota failed"
+ set_ost_qtype $qtype || error "enable ost quota failed"
+
+ echo "Restart..."
+ stopall || error "failed to stopall (1)"
+ mount
+ setupall
+
+ echo "Verify if quota is enabled"
+ local qtype1=$(mdt_quota_type)
+ [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
+ qtype=$(ost_quota_type)
+ [ $qtype1 != $qtype ] && error "ost quota setting is lost"
+
+ echo "Set both mdt & ost quota type as none"
+ set_mdt_qtype "none" || error "disable mdt quota failed"
+ set_ost_qtype "none" || error "disable ost quota failed"
+
+ echo "Restart..."
+ stopall || error "failed to stopall (2)"
+ mount
+ setupall
+ quota_init
+
+ echo "Verify if quota is disabled"
+ qtype=$(mdt_quota_type)
+ [ $qtype != "none" ] && error "mdt quota setting is lost"
+ qtype=$(ost_quota_type)
+ [ $qtype != "none" ] && error "ost quota setting is lost"
+
+ return 0
+}
+run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
+
+test_23_sub() {
+ local TESTFILE="$DIR/$tdir/$tfile"
+ local LIMIT=$1
+
+ setup_quota_test || error "setup quota failed with $?"
+ trap cleanup_quota_test EXIT
+
+ set_ost_qtype $QTYPE || error "Enable ost quota failed"
+
+ # test for user
+ log "User quota (limit: $LIMIT MB)"
+ $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
+ error "set quota failed"
+ quota_show_check b u $TSTUSR
+
+ $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
+ chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
+
+ log "Step1: trigger EDQUOT with O_DIRECT"
+ log "Write half of file"
+ $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
+ quota_error u $TSTUSR "(1) Write failure, expect success." \
+ "limit=$LIMIT"
+ log "Write out of block quota ..."
+ $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
+ oflag=direct conv=notrunc &&
+ quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
+ "limit=$LIMIT"
+ log "Step1: done"
+
+ log "Step2: rewrite should succeed"
+ $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
+ quota_error u $TSTUSR "(3) Write failure, expect success." \
+ "limit=$LIMIT"
+ log "Step2: done"
+
+ cleanup_quota_test
+
+ local OST0_UUID=$(ostuuid_from_index 0)
+ local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
+ [ $OST0_QUOTA_USED -ne 0 ] &&
+ ($SHOW_QUOTA_USER; \
+ quota_error u $TSTUSR "quota isn't released")
+ $SHOW_QUOTA_USER
+}
+
+test_23() {
+ [ "$ost1_FSTYPE" == zfs ] &&
+ skip "Overwrite in place is not guaranteed to be " \
+ "space neutral on ZFS"
+
+ local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
+ check_whether_skip && return 0
+ log "run for 4MB test file"
+ test_23_sub 4
+
+ OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
+ check_whether_skip && return 0
+ log "run for 40MB test file"
+ test_23_sub 40
+}
+run_test 23 "Quota should be honored with directIO (b16125)"
+
+test_24() {
+ local blimit=5 # 5M
+ local TESTFILE="$DIR/$tdir/$tfile"
+
+ setup_quota_test || error "setup quota failed with $?"
+ trap cleanup_quota_test EXIT
+
+ set_ost_qtype $QTYPE || error "enable ost quota failed"
+
+ # bind file to a single OST
+ $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
+ chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
+
+ echo "Set user quota (limit: ${blimit}M)"
+ $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
+ error "set quota failed"
+
+ # overrun quota by root user
+ runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
+ error "write failure, expect success"
+ cancel_lru_locks osc
+ sync_all_data || true
+
+ $SHOW_QUOTA_USER | grep '*' || error "no matching *"
+
+ cleanup_quota_test
+}
+run_test 24 "lfs draws an asterix when limit is reached (b16646)"
+
+test_27a() { # b19612
+ $LFS quota $TSTUSR $DIR &&
+ error "lfs succeeded with no type, but should have failed"
+ $LFS setquota $TSTUSR $DIR &&
+ error "lfs succeeded with no type, but should have failed"
+ return 0
+}
+run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
+
+test_27b() { # b20200
+ $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
+ error "lfs setquota failed with uid argument"
+ $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
+ error "lfs stequota failed with gid argument"
+ if is_project_quota_supported; then
+ $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
+ 1000 $DIR || error \
+ "lfs stequota failed with projid argument"
+ fi
+ $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
+ $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
+ if is_project_quota_supported; then
+ $SHOW_QUOTA_PROJID ||
+ error "lfs quota failed with projid argument"
+ fi
+ resetquota -u $TSTID
+ resetquota -g $TSTID
+ resetquota -p $TSTPRJID
+ return 0
+}
+run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
+
+test_27c() {
+ local limit
+
+ $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
+ error "lfs setquota failed"
+
+ limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
+ [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
+ limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
+ [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
+
+ $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
+ error "lfs setquota for $TSTID failed"
+
+ limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
+ [ $limit != "1.465G" ] && error "wrong softlimit $limit"
+ limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
+ [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
+
+ $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
+ error "total allocated inode/block limit not printed"
+
+ resetquota -u $TSTUSR
+}
+run_test 27c "lfs quota should support human-readable output"
+
+test_27d() {
+ local softlimit=1.5
+ local hardlimit=2.3
+ local limit
+
+ $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
+ error "set fraction block limit failed"
+ limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
+ [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
+ limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
+ [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
+
+ resetquota -u $TSTUSR
+}
+run_test 27d "lfs setquota should support fraction block limit"
+
+test_30() {
+ local LIMIT=4 # 4MB
+ local TESTFILE="$DIR/$tdir/$tfile"
+ local GRACE=10
+
+ setup_quota_test || error "setup quota failed with $?"
+ trap cleanup_quota_test EXIT
+
+ set_ost_qtype "u" || error "enable ost quota failed"
+
+ $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
+ chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
+
+ $LFS setquota -t -u --block-grace $GRACE --inode-grace \
+ $MAX_IQ_TIME $DIR || error "set grace time failed"
+ $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
+ error "set quota failed"
+ $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
+ cancel_lru_locks osc
+ sleep $GRACE
+ $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
+ # over-quota flag has not yet settled since we do not trigger async
+ # events based on grace time period expiration
+ $SHOW_QUOTA_USER
+ $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
+ cancel_lru_locks osc
+ # now over-quota flag should be settled and further writes should fail
+ $SHOW_QUOTA_USER
+ $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
+ error "grace times were reset"
+ # cleanup
+ cleanup_quota_test
+ $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
+ $MAX_IQ_TIME $DIR || error "restore grace time failed"
+}
+run_test 30 "Hard limit updates should not reset grace times"
+
+# basic usage tracking for user & group
+test_33() {
+ local INODES=10 # 10 files
+ local BLK_CNT=2 # of 2M each
+ local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
+
+ setup_quota_test || error "setup quota failed with $?"
+ trap cleanup_quota_test EXIT
+
+ # make sure the system is clean
+ local USED=$(getquota -u $TSTID global curspace)
+ [ $USED -ne 0 ] &&
+ error "Used space ($USED) for user $TSTID isn't 0."
+ USED=$(getquota -g $TSTID global curspace)
+ [ $USED -ne 0 ] &&
+ error "Used space ($USED) for group $TSTID isn't 0."
+ if is_project_quota_supported; then
+ USED=$(getquota -p $TSTPRJID global curspace)
+ [ $USED -ne 0 ] && error \
+ "Used space ($USED) for project $TSTPRJID isn't 0."
+ fi
+
+ echo "Write files..."
+ for i in $(seq 0 $INODES); do
+ $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
+ error "write failed"
+ is_project_quota_supported &&
+ change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
+ echo "Iteration $i/$INODES completed"
+ done
+ cancel_lru_locks osc
+
+ echo "Wait for setattr on objects finished..."
+ wait_delete_completed
+
+ sync; sync_all_data || true
+
+ echo "Verify disk usage after write"
+ USED=$(getquota -u $TSTID global curspace)
+ [ $USED -lt $TOTAL_BLKS ] &&
+ error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
+ USED=$(getquota -g $TSTID global curspace)
+ [ $USED -lt $TOTAL_BLKS ] &&
+ error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
+ if is_project_quota_supported; then
+ USED=$(getquota -p $TSTPRJID global curspace)
+ [ $USED -lt $TOTAL_BLKS ] && error \
+ "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
+ fi
+
+ echo "Verify inode usage after write"
+ USED=$(getquota -u $TSTID global curinodes)
+ [ $USED -lt $INODES ] &&
+ error "Used inode for user $TSTID is $USED, expected $INODES"
+ USED=$(getquota -g $TSTID global curinodes)
+ [ $USED -lt $INODES ] &&
+ error "Used inode for group $TSTID is $USED, expected $INODES"
+ if is_project_quota_supported; then
+ USED=$(getquota -p $TSTPRJID global curinodes)
+ [ $USED -lt $INODES ] && error \
+ "Used inode for project $TSTPRJID is $USED, expected $INODES"
+ fi
+
+ cleanup_quota_test
+
+ echo "Verify disk usage after delete"
+ USED=$(getquota -u $TSTID global curspace)
+ [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
+ USED=$(getquota -u $TSTID global curinodes)
+ [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
+ USED=$(getquota -g $TSTID global curspace)
+ [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
+ USED=$(getquota -g $TSTID global curinodes)
+ [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
+ if is_project_quota_supported; then
+ USED=$(getquota -p $TSTPRJID global curspace)
+ [ $USED -eq 0 ] ||
+ error "Used space for project $TSTPRJID isn't 0. $USED"
+ USED=$(getquota -p $TSTPRJID global curinodes)
+ [ $USED -eq 0 ] ||
+ error "Used inodes for project $TSTPRJID isn't 0. $USED"
+ fi
+}
+run_test 33 "Basic usage tracking for user & group & project"
+
+# usage transfer test for user & group & project
+test_34() {
+ local BLK_CNT=2 # 2MB
+ local project_supported="no"
+
+ is_project_quota_supported && project_supported="yes"
+ setup_quota_test || error "setup quota failed with $?"
+ trap cleanup_quota_test EXIT
+
+ # make sure the system is clean
+ local USED=$(getquota -u $TSTID global curspace)
+ [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
+ USED=$(getquota -g $TSTID global curspace)
+ [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
+
+ local USED=$(getquota -u $TSTID2 global curspace)
+ [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
+ if [ $project_supported == "yes" ]; then
+ USED=$(getquota -p $TSTPRJID global curspace)
+ [ $USED -ne 0 ] && error \
+ "Used space ($USED) for Project $TSTPRJID isn't 0."
+ fi
+
+ echo "Write file..."
+ $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
+ error "write failed"
+ cancel_lru_locks osc
+ sync; sync_all_data || true
+
+ echo "chown the file to user $TSTID"
+ chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
+
+ echo "Wait for setattr on objects finished..."
+ wait_delete_completed
+
+ BLK_CNT=$((BLK_CNT * 1024))
+
+ echo "Verify disk usage for user $TSTID"
+ USED=$(getquota -u $TSTID global curspace)
+ [ $USED -lt $BLK_CNT ] &&
+ error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
+ USED=$(getquota -u $TSTID global curinodes)
+ [ $USED -ne 1 ] &&
+ error "Used inodes for user $TSTID is $USED, expected 1"
+
+ echo "chgrp the file to group $TSTID"
+ chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
+
+ echo "Wait for setattr on objects finished..."
+ wait_delete_completed
+
+ echo "Verify disk usage for group $TSTID"
+ USED=$(getquota -g $TSTID global curspace)
+ [ $USED -ge $BLK_CNT ] ||
+ error "Used space for group $TSTID is $USED, expected $BLK_CNT"
+ USED=$(getquota -g $TSTID global curinodes)
+ [ $USED -eq 1 ] ||
+ error "Used inodes for group $TSTID is $USED, expected 1"
+
+ # chown won't change the ost object group. LU-4345 */
+ echo "chown the file to user $TSTID2"
+ chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
+
+ echo "Wait for setattr on objects finished..."
+ wait_delete_completed
+
+ echo "change_project project id to $TSTPRJID"
+ [ $project_supported == "yes" ] &&
+ change_project -p $TSTPRJID $DIR/$tdir/$tfile
+ echo "Wait for setattr on objects finished..."
+ wait_delete_completed
+
+ echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
+ USED=$(getquota -u $TSTID2 global curspace)
+ [ $USED -lt $BLK_CNT ] &&
+ error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
+ USED=$(getquota -u $TSTID global curspace)
+ [ $USED -ne 0 ] &&
+ error "Used space for user $TSTID is $USED, expected 0"
+ USED=$(getquota -g $TSTID global curspace)
+ [ $USED -lt $BLK_CNT ] &&
+ error "Used space for group $TSTID is $USED, expected $BLK_CNT"
+ if [ $project_supported == "yes" ]; then
+ USED=$(getquota -p $TSTPRJID global curspace)
+ [ $USED -lt $BLK_CNT ] && error \
+ "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
+ fi
+
+ cleanup_quota_test
+}
+run_test 34 "Usage transfer for user & group & project"
+
+# usage is still accessible across restart
+test_35() {
+ local BLK_CNT=2 # 2 MB
+
+ setup_quota_test || error "setup quota failed with $?"
+ trap cleanup_quota_test EXIT
+
+ echo "Write file..."
+ $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
+ error "write failed"
+ is_project_quota_supported &&
+ change_project -p $TSTPRJID $DIR/$tdir/$tfile
+ cancel_lru_locks osc
+
+ echo "Wait for setattr on objects finished..."
+ wait_delete_completed
+
+ sync; sync_all_data || true
+
+ echo "Save disk usage before restart"
+ local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
+ [ $ORIG_USR_SPACE -eq 0 ] &&
+ error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
+ local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
+ [ $ORIG_USR_INODES -eq 0 ] &&
+ error "Used inodes for user $TSTID is 0, expected 1"
+ echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
+ local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
+ [ $ORIG_GRP_SPACE -eq 0 ] &&
+ error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
+ local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
+ [ $ORIG_GRP_INODES -eq 0 ] &&
+ error "Used inodes for group $TSTID is 0, expected 1"
+ echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
+
+ if is_project_quota_supported; then
+ local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
+ [ $ORIG_PRJ_SPACE -eq 0 ] && error \
+ "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
+ local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
+ [ $ORIG_PRJ_INODES -eq 0 ] && error \
+ "Used inodes for project $TSTPRJID is 0, expected 1"
+ echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
+ fi
+
+ log "Restart..."
+ stopall
+ setupall
+ quota_init
+
+ echo "Verify disk usage after restart"
+ local USED=$(getquota -u $TSTID global curspace)
+ [ $USED -eq $ORIG_USR_SPACE ] ||
+ error "Used space for user $TSTID changed from " \
+ "$ORIG_USR_SPACE to $USED"
+ USED=$(getquota -u $TSTID global curinodes)
+ [ $USED -eq $ORIG_USR_INODES ] ||
+ error "Used inodes for user $TSTID changed from " \
+ "$ORIG_USR_INODES to $USED"
+ USED=$(getquota -g $TSTID global curspace)
+ [ $USED -eq $ORIG_GRP_SPACE ] ||
+ error "Used space for group $TSTID changed from " \
+ "$ORIG_GRP_SPACE to $USED"
+ USED=$(getquota -g $TSTID global curinodes)
+ [ $USED -eq $ORIG_GRP_INODES ] ||
+ error "Used inodes for group $TSTID changed from " \
+ "$ORIG_GRP_INODES to $USED"
+ if [ $project_supported == "yes" ]; then
+ USED=$(getquota -p $TSTPRJID global curinodes)
+ [ $USED -eq $ORIG_PRJ_INODES ] ||
+ error "Used inodes for project $TSTPRJID " \
+ "changed from $ORIG_PRJ_INODES to $USED"
+ USED=$(getquota -p $TSTPRJID global curspace)
+ [ $USED -eq $ORIG_PRJ_SPACE ] ||
+ error "Used space for project $TSTPRJID "\
+ "changed from $ORIG_PRJ_SPACE to $USED"
+ fi
+
+ # check if the vfs_dq_init() is called before writing
+ echo "Append to the same file..."
+ $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
+ error "write failed"
+ cancel_lru_locks osc
+ sync; sync_all_data || true
+
+ echo "Verify space usage is increased"
+ USED=$(getquota -u $TSTID global curspace)
+ [ $USED -gt $ORIG_USR_SPACE ] ||
+ error "Used space for user $TSTID isn't increased" \
+ "orig:$ORIG_USR_SPACE, now:$USED"
+ USED=$(getquota -g $TSTID global curspace)
+ [ $USED -gt $ORIG_GRP_SPACE ] ||
+ error "Used space for group $TSTID isn't increased" \
+ "orig:$ORIG_GRP_SPACE, now:$USED"
+ if [ $project_supported == "yes" ]; then
+ USED=$(getquota -p $TSTPRJID global curspace)
+ [ $USED -gt $ORIG_PRJ_SPACE ] ||
+ error "Used space for project $TSTPRJID isn't " \
+ "increased orig:$ORIG_PRJ_SPACE, now:$USED"
+ fi