Whamcloud - gitweb
LU-847 quota: client retrieve quota usage directly
[fs/lustre-release.git] / lustre / quota / quota_ctl.c
index 3650a67..bce3546 100644 (file)
@@ -26,7 +26,7 @@
  * GPL HEADER END
  */
 /*
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  */
 /*
@@ -143,8 +143,11 @@ int filter_quota_ctl(struct obd_device *unused, struct obd_export *exp,
 
         cfs_gettimeofday(&work_start);
         switch (oqctl->qc_cmd) {
-        case Q_FINVALIDATE:
         case Q_QUOTAON:
+                oqctl->qc_id = obt->obt_qfmt;
+                rc = generic_quota_on(obd, oqctl, 0);
+                break;
+        case Q_FINVALIDATE:
         case Q_QUOTAOFF:
                 cfs_down(&obt->obt_quotachecking);
                 if (oqctl->qc_cmd == Q_FINVALIDATE &&
@@ -172,25 +175,17 @@ int filter_quota_ctl(struct obd_device *unused, struct obd_export *exp,
                 if (oqctl->qc_stat == QUOTA_RECOVERING)
                         quota_unbarrier(handle);
 
-                if (oqctl->qc_cmd == Q_QUOTAON || oqctl->qc_cmd == Q_QUOTAOFF ||
+                if (oqctl->qc_cmd == Q_QUOTAOFF ||
                     oqctl->qc_cmd == Q_FINVALIDATE) {
-                        if (oqctl->qc_cmd == Q_QUOTAON) {
-                                if (!rc) {
-                                        obt->obt_qctxt.lqc_flags |=
-                                                UGQUOTA2LQC(oqctl->qc_type);
-                                        /* when quotaon, create lqs for every
-                                         * quota uid/gid b=18574 */
-                                        build_lqs(obd);
-                                } else if (rc == -EBUSY &&
-                                         quota_is_on(qctxt, oqctl)) {
-                                                rc = -EALREADY;
-                                }
-                        } else if (oqctl->qc_cmd == Q_QUOTAOFF) {
+                        if (oqctl->qc_cmd == Q_QUOTAOFF) {
                                 if (!rc)
                                         obt->obt_qctxt.lqc_flags &=
                                                 ~UGQUOTA2LQC(oqctl->qc_type);
                                 else if (quota_is_off(qctxt, oqctl))
                                                 rc = -EALREADY;
+                                CDEBUG(D_QUOTA, "%s: quotaoff type:flags:rc "
+                                       "%u:%lu:%d\n", obd->obd_name,
+                                       oqctl->qc_type, qctxt->lqc_flags, rc);
                         }
                         cfs_up(&obt->obt_quotachecking);
                 }
@@ -302,7 +297,7 @@ int client_quota_ctl(struct obd_device *unused, struct obd_export *exp,
         struct ptlrpc_request   *req;
         struct obd_quotactl     *oqc;
         const struct req_format *rf;
-        int                      ver, opc, rc, resends = 0;
+        int                      ver, opc, rc;
         ENTRY;
 
         if (!strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_MDC_NAME)) {
@@ -317,8 +312,6 @@ int client_quota_ctl(struct obd_device *unused, struct obd_export *exp,
                 RETURN(-EINVAL);
         }
 
-restart_request:
-
         req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), rf, ver, opc);
         if (req == NULL)
                 RETURN(-ENOMEM);
@@ -331,34 +324,20 @@ restart_request:
         req->rq_no_resend = 1;
 
         rc = ptlrpc_queue_wait(req);
-        if (rc) {
+        if (rc)
                 CERROR("ptlrpc_queue_wait failed, rc: %d\n", rc);
-                GOTO(out, rc);
-        }
-
-        oqc = NULL;
-        if (req->rq_repmsg)
-                oqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
 
-        if (oqc == NULL) {
+        if (req->rq_repmsg &&
+            (oqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL))) {
+                *oqctl = *oqc;
+        } else if (!rc) {
                 CERROR ("Can't unpack obd_quotactl\n");
-                GOTO(out, rc = -EPROTO);
+                rc = -EPROTO;
         }
 
-        *oqctl = *oqc;
         EXIT;
-out:
-        ptlrpc_req_finished(req);
-
-        if (client_quota_recoverable_error(rc)) {
-                resends++;
-                if (!client_quota_should_resend(resends, &exp->exp_obd->u.cli)) {
-                        CERROR("too many resend retries, returning error\n");
-                        RETURN(-EIO);
-                }
 
-                goto restart_request;
-        }
+        ptlrpc_req_finished(req);
 
         return rc;
 }
@@ -373,7 +352,9 @@ int lmv_quota_ctl(struct obd_device *unused, struct obd_export *exp,
         struct obd_device *obd = class_exp2obd(exp);
         struct lmv_obd *lmv = &obd->u.lmv;
         struct lmv_tgt_desc *tgt = &lmv->tgts[0];
-        int rc;
+        int rc = 0, i;
+        __u64 curspace;
+        __u64 curinodes;
         ENTRY;
 
         if (!lmv->desc.ld_tgt_count || !tgt->ltd_active) {
@@ -381,7 +362,36 @@ int lmv_quota_ctl(struct obd_device *unused, struct obd_export *exp,
                 RETURN(-EIO);
         }
 
-        rc = obd_quotactl(tgt->ltd_exp, oqctl);
+        if (oqctl->qc_cmd != Q_GETOQUOTA) {
+                rc = obd_quotactl(tgt->ltd_exp, oqctl);
+                RETURN(rc);
+        }
+
+        curspace = curinodes = 0;
+        for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
+                int err;
+                tgt = &lmv->tgts[i];
+
+                if (tgt->ltd_exp == NULL)
+                        continue;
+                if (!tgt->ltd_active) {
+                        CDEBUG(D_HA, "mdt %d is inactive.\n", i);
+                        continue;
+                }
+
+                err = obd_quotactl(tgt->ltd_exp, oqctl);
+                if (err) {
+                        CERROR("getquota on mdt %d failed. %d\n", i, err);
+                        if (!rc)
+                                rc = err;
+                } else {
+                        curspace += oqctl->qc_dqblk.dqb_curspace;
+                        curinodes += oqctl->qc_dqblk.dqb_curinodes;
+                }
+        }
+        oqctl->qc_dqblk.dqb_curspace = curspace;
+        oqctl->qc_dqblk.dqb_curinodes = curinodes;
+
         RETURN(rc);
 }
 
@@ -412,8 +422,13 @@ int lov_quota_ctl(struct obd_device *unused, struct obd_export *exp,
                 int err;
 
                 tgt = lov->lov_tgts[i];
-                if (!tgt || !tgt->ltd_active || tgt->ltd_reap) {
-                        if (oqctl->qc_cmd == Q_GETOQUOTA) {
+
+                if (!tgt)
+                        continue;
+
+                if (!tgt->ltd_active || tgt->ltd_reap) {
+                        if (oqctl->qc_cmd == Q_GETOQUOTA &&
+                            lov->lov_tgts[i]->ltd_activate) {
                                 rc = -EREMOTEIO;
                                 CERROR("ost %d is inactive\n", i);
                         } else {