Whamcloud - gitweb
LU-1842 quota: t-f changes for new quota
authorNiu Yawei <niu@whamcloud.com>
Tue, 18 Sep 2012 15:00:12 +0000 (11:00 -0400)
committerOleg Drokin <green@whamcloud.com>
Tue, 25 Sep 2012 18:16:35 +0000 (14:16 -0400)
Added new quota functions in the t-f according to new quota
architecutre, at the same time, old functions are kept for
the interoprability with old server.

two minor defects fixed:
- in facet_up(), add '-x' option to grep for exact matching,
  otherwise this function will not work in single node test;
- missing 'shift' in wait_update_facet();

Test-Parameters: envdefinitions=ENABLE_QUOTA=yes

Signed-off-by: Niu Yawei <niu@whamcloud.com>
Change-Id: I86915976f53af8620679ab267e04beea18dd5cf3
Reviewed-on: http://review.whamcloud.com/4031
Reviewed-by: Yu Jian <yujian@whamcloud.com>
Tested-by: Hudson
Reviewed-by: Johann Lombardi <johann@whamcloud.com>
Tested-by: Maloo <whamcloud.maloo@gmail.com>
lustre/tests/test-framework.sh

index 34959ed..1d4c7a0 100644 (file)
@@ -980,6 +980,10 @@ stop() {
 
 # save quota version (both administrative and operational quotas)
 # add an additional parameter if mountpoint is ever different from $MOUNT
 
 # save quota version (both administrative and operational quotas)
 # add an additional parameter if mountpoint is ever different from $MOUNT
+#
+# XXX This function is kept for interoperability with old server (< 2.3.51),
+#     it should be removed whenever we drop the interoperability for such
+#     server.
 quota_save_version() {
     local fsname=${2:-$FSNAME}
     local spec=$1
 quota_save_version() {
     local fsname=${2:-$FSNAME}
     local spec=$1
@@ -999,7 +1003,11 @@ quota_save_version() {
     done
 }
 
     done
 }
 
-# client could mount several lustre 
+# client could mount several lustre
+#
+# XXX This function is kept for interoperability with old server (< 2.3.51),
+#     it should be removed whenever we drop the interoperability for such
+#     server.
 quota_type () {
     local fsname=${1:-$FSNAME}
     local rc=0
 quota_type () {
     local fsname=${1:-$FSNAME}
     local rc=0
@@ -1009,17 +1017,24 @@ quota_type () {
     return $rc 
 }
 
     return $rc 
 }
 
-restore_quota_type () {
-   local mntpt=${1:-$MOUNT}
-   local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
-   if [ ! "$old_QUOTA_TYPE" ] || [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
-        return
-   fi
-   quota_save_version $old_QUOTA_TYPE
+# XXX This function is kept for interoperability with old server (< 2.3.51),
+#     it should be removed whenever we drop the interoperability for such
+#     server.
+restore_quota_old() {
+       local mntpt=${1:-$MOUNT}
+       local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
+       if [ ! "$old_QUOTA_TYPE" ] ||
+               [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
+               return
+       fi
+       quota_save_version $old_QUOTA_TYPE
 }
 
 }
 
-setup_quota(){
-    local mntpt=$1
+# XXX This function is kept for interoperability with old server (< 2.3.51),
+#     it should be removed whenever we drop the interoperability for such
+#     server.
+setup_quota_old(){
+       local mntpt=$1
 
        if [ "$USE_OFD" = "yes" ]; then
                $LFS quotacheck $mntpt || error "quotacheck failed"
 
        if [ "$USE_OFD" = "yes" ]; then
                $LFS quotacheck $mntpt || error "quotacheck failed"
@@ -1068,6 +1083,93 @@ setup_quota(){
     done
 }
 
     done
 }
 
+# get mdt quota type
+mdt_quota_type() {
+       local varsvc=${SINGLEMDS}_svc
+       do_facet $SINGLEMDS $LCTL get_param -n \
+               osd-$FSTYPE.${!varsvc}.quota_slave.enabled
+}
+
+# get ost quota type
+ost_quota_type() {
+       # All OSTs should have same quota type
+       local varsvc=ost1_svc
+       do_facet ost1 $LCTL get_param -n \
+               osd-$FSTYPE.${!varsvc}.quota_slave.enabled
+}
+
+# restore old quota type settings
+restore_quota() {
+       if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.51) ]; then
+               restore_quota_old
+               return
+       fi
+
+       if [ "$old_MDT_QUOTA_TYPE" ]; then
+               do_facet mgs $LCTL conf_param \
+                       $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
+       fi
+       if [ "$old_OST_QUOTA_TYPE" ]; then
+               do_facet mgs $LCTL conf_param \
+                       $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
+       fi
+}
+
+setup_quota(){
+       if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.51) ]; then
+               setup_quota_old $1
+               return
+       fi
+
+       local mntpt=$1
+
+       # save old quota type & set new quota type
+       local mdt_qtype=$(mdt_quota_type)
+       local ost_qtype=$(ost_quota_type)
+
+       echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
+               "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
+
+       export old_MDT_QUOTA_TYPE=$mdt_qtype
+       export old_OST_QUOTA_TYPE=$ost_qtype
+
+       do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
+               error "set mdt quota type failed"
+       do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
+               error "set ost quota type failed"
+
+       local quota_usrs=$QUOTA_USERS
+
+       # get_filesystem_size
+       local disksz=$(lfs df $mntpt | grep "filesystem summary:" |
+                    awk '{print $3}')
+       local blk_soft=$((disksz + 1024))
+       local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
+
+       local inodes=$(lfs df -i $mntpt | grep "filesystem summary:" |
+                    awk '{print $3}')
+       local i_soft=$inodes
+       local i_hard=$((i_soft + i_soft / 20))
+
+       echo "Total disk size: $disksz  block-softlimit: $blk_soft" \
+               "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
+               "inode-hardlimit: $i_hard"
+
+       local cmd
+       for usr in $quota_usrs; do
+               echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
+               for type in u g; do
+                       cmd="$LFS setquota -$type $usr -b $blk_soft"
+                       cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
+                       echo "+ $cmd"
+                       eval $cmd || error "$cmd FAILED!"
+               done
+               # display the quota status
+               echo "Quota settings for $usr : "
+               $LFS quota -v -u $usr $mntpt || true
+       done
+}
+
 zconf_mount() {
     local client=$1
     local mnt=$2
 zconf_mount() {
     local client=$1
     local mnt=$2
@@ -1277,12 +1379,12 @@ facets_on_host () {
     echo $(comma_list $affected)
 }
 
     echo $(comma_list $affected)
 }
 
-facet_up () {
-    local facet=$1
-    local host=${2:-$(facet_host $facet)}
+facet_up() {
+       local facet=$1
+       local host=${2:-$(facet_host $facet)}
 
 
-    local label=$(convert_facet2label $facet)
-    do_node $host lctl dl | awk '{print $4}' | grep -q $label
+       local label=$(convert_facet2label $facet)
+       do_node $host $LCTL dl | awk '{print $4}' | grep -q -x $label
 }
 
 facets_up_on_host () {
 }
 
 facets_up_on_host () {
@@ -1623,9 +1725,10 @@ wait_update () {
         return 3
 }
 
         return 3
 }
 
-wait_update_facet () {
-    local facet=$1
-    wait_update  $(facet_active_host $facet) "$@"
+wait_update_facet() {
+       local facet=$1
+       shift
+       wait_update $(facet_active_host $facet) "$@"
 }
 
 sync_all_data() {
 }
 
 sync_all_data() {
@@ -3261,11 +3364,11 @@ check_and_cleanup_lustre() {
         run_lfsck
     fi
 
         run_lfsck
     fi
 
-    if is_mounted $MOUNT; then
-        [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
-            error "remove sub-test dirs failed"
-        [ "$ENABLE_QUOTA" ] && restore_quota_type || true
-    fi
+       if is_mounted $MOUNT; then
+               [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
+                       error "remove sub-test dirs failed"
+               [ "$ENABLE_QUOTA" ] && restore_quota || true
+       fi
 
     if [ "$I_UMOUNTED2" = "yes" ]; then
         restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
 
     if [ "$I_UMOUNTED2" = "yes" ]; then
         restore_mount $MOUNT2 || error "restore $MOUNT2 failed"