+# save quota version (both administrative and operational quotas)
+# add an additional parameter if mountpoint is ever different from $MOUNT
+quota_save_version() {
+ local fsname=${2:-$FSNAME}
+ local spec=$1
+ local ver=$(tr -c -d "123" <<< $spec)
+ local type=$(tr -c -d "ug" <<< $spec)
+
+ [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
+
+ $LFS quotaoff -ug $MOUNT # just in case
+ [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
+
+ do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
+ local varsvc
+ local osts=$(get_facets OST)
+ for ost in ${osts//,/ }; do
+ varsvc=${ost}_svc
+ do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
+ done
+}
+
+# client could mount several lustre
+quota_type () {
+ local fsname=${1:-$FSNAME}
+ local rc=0
+ do_facet mgs lctl get_param mdd.${fsname}-MDT*.quota_type || rc=$?
+ do_nodes $(comma_list $(osts_nodes)) \
+ lctl get_param obdfilter.${fsname}-OST*.quota_type || 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
+}
+
+setup_quota(){
+ local mntpt=$1
+
+ # We need:
+ # 1. run quotacheck only if quota is off
+ # 2. save the original quota_type params, restore them after testing
+
+ # Suppose that quota type the same on mds and ost
+ local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
+ [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
+ echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
+ if [ "$quota_type" != "$QUOTA_TYPE" ]; then
+ export old_QUOTA_TYPE=$quota_type
+ quota_save_version $QUOTA_TYPE
+ fi
+
+ 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 -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
+}
+