X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Fquota%2Fquota_context.c;h=f6340b3bb8bbff2a106287fa501ee98398698833;hp=e601840d25e9875afa0251a889aa27b624c5cce6;hb=78377ff4718213ffaa609ce150afda31e3756b38;hpb=fddc386818cc1358e6c4212a7aaf6b89e5c8099a diff --git a/lustre/quota/quota_context.c b/lustre/quota/quota_context.c index e601840..f6340b3 100644 --- a/lustre/quota/quota_context.c +++ b/lustre/quota/quota_context.c @@ -221,6 +221,59 @@ out: return ret; } +/* compute the remaining quota for certain gid or uid b=11693 */ +int compute_remquota(struct obd_device *obd, + struct lustre_quota_ctxt *qctxt, struct qunit_data *qdata) +{ + struct super_block *sb = qctxt->lqc_sb; + __u64 usage, limit; + struct obd_quotactl *qctl; + int ret = QUOTA_RET_OK; + __u32 qdata_type = qdata->qd_flags & QUOTA_IS_GRP; + ENTRY; + + if (!sb_any_quota_enabled(sb)) + RETURN(QUOTA_RET_NOQUOTA); + + /* ignore root user */ + if (qdata->qd_id == 0 && qdata_type == USRQUOTA) + RETURN(QUOTA_RET_NOLIMIT); + + OBD_ALLOC_PTR(qctl); + if (qctl == NULL) + RETURN(-ENOMEM); + + /* get fs quota usage & limit */ + qctl->qc_cmd = Q_GETQUOTA; + qctl->qc_id = qdata->qd_id; + qctl->qc_type = qdata_type; + ret = fsfilt_quotactl(obd, sb, qctl); + if (ret) { + if (ret == -ESRCH) /* no limit */ + ret = QUOTA_RET_NOLIMIT; + else + CDEBUG(D_QUOTA, "can't get fs quota usage! (rc:%d)", + ret); + GOTO(out, ret); + } + + usage = qctl->qc_dqblk.dqb_curspace; + limit = qctl->qc_dqblk.dqb_bhardlimit << QUOTABLOCK_BITS; + if (!limit){ /* no limit */ + ret = QUOTA_RET_NOLIMIT; + GOTO(out, ret); + } + + if (limit >= usage) + qdata->qd_count = limit - usage; + else + qdata->qd_count = 0; + EXIT; +out: + OBD_FREE_PTR(qctl); + return ret; +} + /* caller must hold qunit_hash_lock */ static struct lustre_qunit *dqacq_in_flight(struct lustre_quota_ctxt *qctxt, struct qunit_data *qdata)