Whamcloud - gitweb
b=1028 drop SOM dependency on quota
[fs/lustre-release.git] / lustre / quota / lproc_quota.c
index a76807a..d911365 100644 (file)
@@ -207,65 +207,79 @@ static int auto_quota_on(struct obd_device *obd, int type,
 {
         struct obd_quotactl *oqctl;
         struct lvfs_run_ctxt saved;
-        int rc = 0, id;
-        struct obd_device_target *obt;
+        int rc = 0, rc1 = 0, id;
+        struct obd_device_target *obt = &obd->u.obt;
+        struct lustre_quota_ctxt *qctxt = &obt->obt_qctxt;
+        struct mds_obd *mds = NULL;
         ENTRY;
 
         LASSERT(type == USRQUOTA || type == GRPQUOTA || type == UGQUOTA);
 
-        obt = &obd->u.obt;
-
         OBD_ALLOC_PTR(oqctl);
         if (!oqctl)
                 RETURN(-ENOMEM);
 
-        if (!atomic_dec_and_test(&obt->obt_quotachecking)) {
-                CDEBUG(D_INFO, "other people are doing quotacheck\n");
-                atomic_inc(&obt->obt_quotachecking);
-                RETURN(-EBUSY);
-        }
-
+        cfs_down(&obt->obt_quotachecking);
         id = UGQUOTA2LQC(type);
         /* quota already turned on */
-        if ((obt->obt_qctxt.lqc_flags & id) == id) {
-                rc = 0;
-                goto out;
-        }
+        if ((obt->obt_qctxt.lqc_flags & id) == id)
+                GOTO(out, rc);
 
         oqctl->qc_type = type;
         oqctl->qc_cmd = Q_QUOTAON;
         oqctl->qc_id = obt->obt_qfmt;
 
         push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
-        if (is_master) {
-                struct mds_obd *mds = &obd->u.mds;
 
-                down(&mds->mds_qonoff_sem);
+        if (is_master) {
+                mds = &obd->u.mds;
+                cfs_down(&mds->mds_qonoff_sem);
                 /* turn on cluster wide quota */
-                rc = mds_admin_quota_on(obd, oqctl);
-                if (rc)
-                        CDEBUG(rc == -ENOENT ? D_QUOTA : D_ERROR,
-                               "auto-enable admin quota failed. rc=%d\n", rc);
-                up(&mds->mds_qonoff_sem);
-
+                rc1 = mds_admin_quota_on(obd, oqctl);
+                if (rc1 && rc1 != -EALREADY) {
+                        CDEBUG_LIMIT(rc1 == -ENOENT ? D_QUOTA : D_ERROR,
+                                     "%s: auto-enable admin quota failed with "
+                                     "rc=%d\n", obd->obd_name, rc1);
+                        GOTO(out_ctxt, rc1);
+                }
         }
+
+        /* turn on local quota */
+        rc = fsfilt_quotactl(obd, sb, oqctl);
         if (!rc) {
-                /* turn on local quota */
-                rc = fsfilt_quotactl(obd, sb, oqctl);
-                if (rc)
-                        CDEBUG(rc == -ENOENT ? D_QUOTA : D_ERROR,
-                               "auto-enable local quota failed. rc=%d\n", rc);
-                else
-                        obt->obt_qctxt.lqc_flags |= UGQUOTA2LQC(type);
+                obt->obt_qctxt.lqc_flags |= UGQUOTA2LQC(type);
+                build_lqs(obd);
+        } else if (rc == -EBUSY && quota_is_on(qctxt, oqctl)) {
+                CWARN("%s: mds local quota[%d] is on already\n",
+                      obd->obd_name, oqctl->qc_type);
+                rc = -EALREADY;
+        } else {
+                CDEBUG_LIMIT(rc == -ENOENT ? D_QUOTA : D_ERROR,
+                             "%s: auto-enable local quota failed with rc=%d\n",
+                             obd->obd_name, rc);
+                if (rc1 == -EALREADY) {
+                        oqctl->qc_cmd = Q_QUOTAOFF;
+                        mds_admin_quota_off(obd, oqctl);
+                }
+                if (rc == -ENOENT)
+                        CWARN("%s: quotaon failed because quota files don't "
+                              "exist, please run quotacheck firstly\n",
+                              obd->obd_name);
+
+                GOTO(out_ctxt, rc);
         }
 
+        EXIT;
+
+out_ctxt:
+        if (mds != NULL)
+                cfs_up(&mds->mds_qonoff_sem);
         pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
 
 out:
-        atomic_inc(&obt->obt_quotachecking);
-
+        cfs_up(&obt->obt_quotachecking);
         OBD_FREE_PTR(oqctl);
-        RETURN(rc);
+        return rc;
 }
 
 int lprocfs_quota_wr_type(struct file *file, const char *buffer,
@@ -286,7 +300,7 @@ int lprocfs_quota_wr_type(struct file *file, const char *buffer,
         if (count > MAX_STYPE_SIZE)
                 return -EINVAL;
 
-        if (copy_from_user(stype, buffer, count))
+        if (cfs_copy_from_user(stype, buffer, count))
                 return -EFAULT;
 
         for (i = 0 ; i < count ; i++) {
@@ -308,8 +322,12 @@ int lprocfs_quota_wr_type(struct file *file, const char *buffer,
                 }
         }
 
-        if (type != 0)
-                auto_quota_on(obd, type - 1, obt->obt_sb, is_mds);
+        if (type != 0) {
+                int rc = auto_quota_on(obd, type - 1, obt->obt_sb, is_mds);
+
+                if (rc && rc != -EALREADY && rc != -ENOENT)
+                        return rc;
+        }
 
         return count;
 }
@@ -547,6 +565,7 @@ struct lprocfs_vars lprocfs_quota_common_vars[] = {
                                    lprocfs_quota_wr_switch_seconds, 0 },
         { "quota_sync_blk", lprocfs_quota_rd_sync_blk,
                             lprocfs_quota_wr_sync_blk, 0},
+        { NULL }
 };
 
 struct lprocfs_vars lprocfs_quota_master_vars[] = {
@@ -560,6 +579,7 @@ struct lprocfs_vars lprocfs_quota_master_vars[] = {
                                lprocfs_quota_wr_least_iunit, 0 },
         { "quota_qs_factor",   lprocfs_quota_rd_qs_factor,
                                lprocfs_quota_wr_qs_factor, 0 },
+        { NULL }
 };
 
 int lquota_proc_setup(struct obd_device *obd, int is_master)
@@ -574,8 +594,8 @@ int lquota_proc_setup(struct obd_device *obd, int is_master)
                                                lprocfs_quota_common_vars, obd);
         if (IS_ERR(qctxt->lqc_proc_dir)) {
                 rc = PTR_ERR(qctxt->lqc_proc_dir);
-                CERROR("error %d setting up lprocfs for %s\n", rc,
-                       obd->obd_name);
+                CERROR("%s: error %d setting up lprocfs\n",
+                       obd->obd_name, rc);
                 qctxt->lqc_proc_dir = NULL;
                 GOTO(out, rc);
         }
@@ -584,8 +604,8 @@ int lquota_proc_setup(struct obd_device *obd, int is_master)
                 rc = lprocfs_add_vars(qctxt->lqc_proc_dir,
                                       lprocfs_quota_master_vars, obd);
                 if (rc) {
-                        CERROR("error %d setting up lprocfs for %s"
-                               "(quota master)\n", rc, obd->obd_name);
+                        CERROR("%s: error %d setting up lprocfs for "
+                               "quota master\n", obd->obd_name, rc);
                         GOTO(out_free_proc, rc);
                 }
         }