Whamcloud - gitweb
b=21571 stacksize and locking fixes for loadgen patch from umka
[fs/lustre-release.git] / lustre / quota / quota_master.c
index 9edffbe..f0ccb99 100644 (file)
@@ -255,9 +255,7 @@ int dqacq_adjust_qunit_sz(struct obd_device *obd, qid_t id, int type,
 {
         struct mds_obd *mds = &obd->u.mds;
         struct lustre_quota_ctxt *qctxt = &mds->mds_obt.obt_qctxt;
-        struct obd_device *lov_mds_obd = class_exp2obd(mds->mds_osc_exp);
-        struct lov_obd *lov = &lov_mds_obd->u.lov;
-        __u32 ost_num = lov->desc.ld_tgt_count, mdt_num = 1;
+        __u32 ost_num = mds->mds_lov_objid_count, mdt_num = 1;
         struct quota_adjust_qunit *oqaq = NULL;
         unsigned int qid[MAXQUOTAS] = { 0, 0 };
         struct lustre_quota_info *info = &mds->mds_quota_info;
@@ -283,7 +281,7 @@ int dqacq_adjust_qunit_sz(struct obd_device *obd, qid_t id, int type,
                                LQUOTA_FLAGS_ADJINO, oqaq);
 
         if (rc < 0) {
-                CDEBUG(D_ERROR, "create oqaq failed! (rc:%d)\n", rc);
+                CERROR("create oqaq failed! (rc:%d)\n", rc);
                 GOTO(out_sem, rc);
         }
         QAQ_DEBUG(oqaq, "show oqaq.\n")
@@ -296,8 +294,8 @@ int dqacq_adjust_qunit_sz(struct obd_device *obd, qid_t id, int type,
         if (adjust_res <= 0) {
                 if (adjust_res < 0) {
                         rc = adjust_res;
-                        CDEBUG(D_ERROR, "adjust mds slave's qunit size failed! \
-                               (rc:%d)\n", rc);
+                        CERROR("adjust mds slave's qunit size failed! "
+                               "(rc:%d)\n", rc);
                 } else {
                         CDEBUG(D_QUOTA, "qunit doesn't need to be adjusted.\n");
                 }
@@ -317,8 +315,8 @@ int dqacq_adjust_qunit_sz(struct obd_device *obd, qid_t id, int type,
                 rc = 0;
         }
         if (rc) {
-                CDEBUG(D_ERROR, "mds fail to adjust file quota! \
-                               (rc:%d)\n", rc);
+                CERROR("%s: mds fail to adjust file quota! (rc:%d)\n",
+                       obd->obd_name, rc);
                 GOTO(out, rc);
         }
 
@@ -533,7 +531,7 @@ int mds_quota_adjust(struct obd_device *obd, const unsigned int qcids[],
         }
 
         if (rc2)
-                CDEBUG(rc2 == QUOTA_REQ_RETURNED ? D_QUOTA: D_ERROR,
+                CDEBUG(D_QUOTA,
                        "mds adjust qunit %ssuccessfully! (opc:%d rc:%d)\n",
                        rc2 == QUOTA_REQ_RETURNED ? "" : "un", opc, rc2);
         RETURN(0);
@@ -569,9 +567,9 @@ int filter_quota_adjust(struct obd_device *obd, const unsigned int qcids[],
         if (rc || rc2) {
                 if (!rc)
                         rc = rc2;
-                CDEBUG(rc == QUOTA_REQ_RETURNED ? D_QUOTA: D_ERROR,
+                CDEBUG(D_QUOTA,
                        "filter adjust qunit %ssuccessfully! (opc:%d rc%d)\n",
-                       QUOTA_REQ_RETURNED ? "" : "un", opc, rc);
+                       rc == QUOTA_REQ_RETURNED ? "" : "un", opc, rc);
         }
 
         RETURN(0);
@@ -620,8 +618,8 @@ int mds_quota_invalidate(struct obd_device *obd, struct obd_quotactl *oqctl)
                 fp = filp_open(name, O_CREAT | O_TRUNC | O_RDWR, 0644);
                 if (IS_ERR(fp)) {
                         rc = PTR_ERR(fp);
-                        CERROR("error invalidating admin quotafile %s (rc:%d)\n",
-                               name, rc);
+                        CERROR("%s: error invalidating admin quotafile %s (rc:%d)\n",
+                               obd->obd_name, name, rc);
                 }
                 else
                         filp_close(fp, 0);
@@ -717,8 +715,8 @@ int init_admin_quotafiles(struct obd_device *obd, struct obd_quotactl *oqctl)
 
                 /* -EINVAL may be returned by quotainfo for bad quota file */
                 if (rc != -ENOENT && rc != -EINVAL) {
-                        CERROR("error opening old quota file %s (%d)\n",
-                               name, rc);
+                        CERROR("%s: error opening old quota file %s (%d)\n",
+                               obd->obd_name, name, rc);
                         break;
                 }
 
@@ -729,8 +727,8 @@ int init_admin_quotafiles(struct obd_device *obd, struct obd_quotactl *oqctl)
                 fp = filp_open(name, O_CREAT | O_TRUNC | O_RDWR, 0644);
                 if (IS_ERR(fp)) {
                         rc = PTR_ERR(fp);
-                        CERROR("error creating admin quotafile %s (rc:%d)\n",
-                               name, rc);
+                        CERROR("%s: error creating admin quotafile %s (rc:%d)\n",
+                               obd->obd_name, name, rc);
                         break;
                 }
 
@@ -854,7 +852,13 @@ int mds_quota_on(struct obd_device *obd, struct obd_quotactl *oqctl)
                 RETURN(-EINVAL);
 
         down(&obt->obt_quotachecking);
-        LASSERT(!obt->obt_qctxt.lqc_immutable);
+        if (obt->obt_qctxt.lqc_immutable) {
+                LCONSOLE_ERROR("Failed to turn Quota on, immutable mode "
+                               "(is SOM enabled?)\n");
+                up(&obt->obt_quotachecking);
+                RETURN(-ECANCELED);
+        }
+
         push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
         down(&mds->mds_qonoff_sem);
         rc2 = mds_admin_quota_on(obd, oqctl);
@@ -866,6 +870,8 @@ int mds_quota_on(struct obd_device *obd, struct obd_quotactl *oqctl)
         rc1 = fsfilt_quotactl(obd, obd->u.obt.obt_sb, oqctl);
         if (!rc1) {
                 qctxt->lqc_flags |= UGQUOTA2LQC(oqctl->qc_type);
+                /* when quotaon, create lqs for every quota uid/gid b=18574 */
+                build_lqs(obd);
         } else if (rc1 == -EBUSY && quota_is_on(qctxt, oqctl)) {
                 CWARN("mds local quota[%d] is on already\n", oqctl->qc_type);
                 rc1 = -EALREADY;
@@ -893,6 +899,7 @@ int mds_quota_on(struct obd_device *obd, struct obd_quotactl *oqctl)
                 }
                 oqctl->qc_cmd = Q_QUOTAON;
         }
+
         EXIT;
 
 out:
@@ -902,7 +909,8 @@ out:
         return rc ? : (rc1 ? : rc2);
 }
 
-int mds_quota_off(struct obd_device *obd, struct obd_quotactl *oqctl)
+/* with obt->obt_quotachecking held */
+int do_mds_quota_off(struct obd_device *obd, struct obd_quotactl *oqctl)
 {
         struct mds_obd *mds = &obd->u.mds;
         struct obd_device_target *obt = &obd->u.obt;
@@ -911,6 +919,8 @@ int mds_quota_off(struct obd_device *obd, struct obd_quotactl *oqctl)
         int rc = 0, rc1 = 0, rc2 = 0, imm;
         ENTRY;
 
+        LASSERT_SEM_LOCKED(&obt->obt_quotachecking);
+
         imm = oqctl->qc_type & IMMQUOTA;
         oqctl->qc_type &= ~IMMQUOTA;
 
@@ -919,7 +929,6 @@ int mds_quota_off(struct obd_device *obd, struct obd_quotactl *oqctl)
             oqctl->qc_type != UGQUOTA)
                 RETURN(-EINVAL);
 
-        down(&obt->obt_quotachecking);
         push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
         down(&mds->mds_qonoff_sem);
         /* close admin quota files */
@@ -968,10 +977,21 @@ int mds_quota_off(struct obd_device *obd, struct obd_quotactl *oqctl)
 out:
         up(&mds->mds_qonoff_sem);
         pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
-        up(&obt->obt_quotachecking);
         return rc ? : (rc1 ? : rc2);
 }
 
+int mds_quota_off(struct obd_device *obd, struct obd_quotactl *oqctl)
+{
+        struct obd_device_target *obt = &obd->u.obt;
+        int rc;
+        ENTRY;
+
+        down(&obt->obt_quotachecking);
+        rc = do_mds_quota_off(obd, oqctl);
+        up(&obt->obt_quotachecking);
+        RETURN(rc);
+}
+
 int mds_set_dqinfo(struct obd_device *obd, struct obd_quotactl *oqctl)
 {
         struct mds_obd *mds = &obd->u.mds;
@@ -1554,13 +1574,14 @@ int mds_get_dqblk(struct obd_device *obd, struct obd_quotactl *oqctl)
         up(&dquot->dq_sem);
 
         lustre_dqput(dquot);
+        up(&mds->mds_qonoff_sem);
 
         /* the usages in admin quota file is inaccurate */
         dqblk->dqb_curinodes = 0;
         dqblk->dqb_curspace = 0;
         rc = mds_get_space(obd, oqctl);
         EXIT;
-
+        return rc;
 out:
         up(&mds->mds_qonoff_sem);
         return rc;
@@ -1669,7 +1690,7 @@ static int qmaster_recovery_main(void *arg)
         unsigned short type;
         ENTRY;
 
-        ptlrpc_daemonize("qmaster_recovd");
+        cfs_daemonize_ctxt("qmaster_recovd");
 
         /* for mds */
         class_incref(obd, "qmaster_recovd_mds", obd);
@@ -1702,8 +1723,9 @@ static int qmaster_recovery_main(void *arg)
 
                         rc = dquot_recovery(obd, dqid->di_id, type);
                         if (rc)
-                                CERROR("qmaster recovery failed! (id:%d type:%d"
-                                       " rc:%d)\n", dqid->di_id, type, rc);
+                                CERROR("%s: qmaster recovery failed for %sid %d"
+                                       " rc:%d)\n", obd->obd_name,
+                                       type ? "g" : "u", dqid->di_id, rc);
 free:
                         OBD_FREE_PTR(dqid);
                 }
@@ -1738,7 +1760,8 @@ int mds_quota_recovery(struct obd_device *obd)
 
         rc = kernel_thread(qmaster_recovery_main, &data, CLONE_VM|CLONE_FILES);
         if (rc < 0)
-                CERROR("Cannot start quota recovery thread: rc %d\n", rc);
+                CERROR("%s: cannot start quota recovery thread: rc %d\n",
+                       obd->obd_name, rc);
 
         wait_for_completion(&data.comp);
         RETURN(rc);