Whamcloud - gitweb
b=19390 Remove unneeded spinlock
[fs/lustre-release.git] / lustre / quota / quota_check.c
index 62fc1f0..4368db4 100644 (file)
 # include <linux/version.h>
 # include <linux/module.h>
 # include <linux/init.h>
-# include <linux/fs.h>
-# include <linux/jbd.h>
-# include <linux/ext3_fs.h>
-# include <linux/smp_lock.h>
-# include <linux/buffer_head.h>
-# include <linux/workqueue.h>
-# include <linux/mount.h>
+#  include <linux/smp_lock.h>
+#  include <linux/buffer_head.h>
+#  include <linux/workqueue.h>
+#  include <linux/mount.h>
 #else /* __KERNEL__ */
 # include <liblustre.h>
 #endif
@@ -70,19 +67,19 @@ static int target_quotacheck_callback(struct obd_export *exp,
                                       struct obd_quotactl *oqctl)
 {
         struct ptlrpc_request *req;
-        struct obd_quotactl   *body;
-        int                    rc;
+        struct obd_quotactl *body;
+        int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*oqctl) };
         ENTRY;
 
-        req = ptlrpc_request_alloc_pack(exp->exp_imp_reverse, &RQF_QC_CALLBACK,
-                                        LUSTRE_OBD_VERSION, OBD_QC_CALLBACK);
-        if (req == NULL)
+        req = ptlrpc_prep_req(exp->exp_imp_reverse, LUSTRE_OBD_VERSION,
+                              OBD_QC_CALLBACK, 2, size, NULL);
+        if (!req)
                 RETURN(-ENOMEM);
 
-        body = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
+        body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
         *body = *oqctl;
 
-        ptlrpc_request_set_replen(req);
+        ptlrpc_req_set_repsize(req, 1, NULL);
 
         rc = ptlrpc_queue_wait(req);
         ptlrpc_req_finished(req);
@@ -99,10 +96,10 @@ static int target_quotacheck_thread(void *data)
         struct lvfs_run_ctxt saved;
         int rc;
 
-        ptlrpc_daemonize("quotacheck");
+        cfs_daemonize_ctxt("quotacheck");
 
         exp = qta->qta_exp;
-        obd = qta->qta_obd;
+        obd = exp->exp_obd;
         oqctl = &qta->qta_oqctl;
 
         push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
@@ -114,6 +111,7 @@ static int target_quotacheck_thread(void *data)
         pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
 
         rc = target_quotacheck_callback(exp, oqctl);
+        class_export_put(exp);
 
         atomic_inc(qta->qta_sem);
 
@@ -121,9 +119,9 @@ static int target_quotacheck_thread(void *data)
         return rc;
 }
 
-int target_quota_check(struct obd_device *obd, struct obd_export *exp,
-                       struct obd_quotactl *oqctl)
+int target_quota_check(struct obd_export *exp, struct obd_quotactl *oqctl)
 {
+        struct obd_device *obd = exp->exp_obd;
         struct obd_device_target *obt = &obd->u.obt;
         struct quotacheck_thread_args *qta;
         int rc = 0;
@@ -139,7 +137,6 @@ int target_quota_check(struct obd_device *obd, struct obd_export *exp,
                 GOTO(out, rc = -ENOMEM);
 
         qta->qta_exp = exp;
-        qta->qta_obd = obd;
         qta->qta_oqctl = *oqctl;
         qta->qta_oqctl.qc_id = obt->obt_qfmt; /* override qfmt version */
         qta->qta_sb = obt->obt_sb;
@@ -155,6 +152,9 @@ int target_quota_check(struct obd_device *obd, struct obd_export *exp,
                 }
         }
 
+        /* we get ref for exp because target_quotacheck_callback() will use this
+         * export later b=18126 */
+        class_export_get(exp);
         rc = kernel_thread(target_quotacheck_thread, qta, CLONE_VM|CLONE_FILES);
         if (rc >= 0) {
                 CDEBUG(D_INFO, "%s: target_quotacheck_thread: %d\n",
@@ -162,6 +162,7 @@ int target_quota_check(struct obd_device *obd, struct obd_export *exp,
                 RETURN(0);
         }
 
+        class_export_put(exp);
         CERROR("%s: error starting quotacheck_thread: %d\n",
                obd->obd_name, rc);
         OBD_FREE_PTR(qta);
@@ -173,36 +174,33 @@ out:
 #endif /* __KERNEL__ */
 #endif /* HAVE_QUOTA_SUPPORT */
 
-int client_quota_check(struct obd_device *unused, struct obd_export *exp,
-                       struct obd_quotactl *oqctl)
+int client_quota_check(struct obd_export *exp, struct obd_quotactl *oqctl)
 {
-        struct client_obd       *cli = &exp->exp_obd->u.cli;
-        struct ptlrpc_request   *req;
-        struct obd_quotactl     *body;
-        const struct req_format *rf;
-        int                      ver, opc, rc;
+        struct client_obd *cli = &exp->exp_obd->u.cli;
+        struct ptlrpc_request *req;
+        struct obd_quotactl *body;
+        __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
+        int ver, opc, rc;
         ENTRY;
 
         if (!strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_MDC_NAME)) {
-                rf  = &RQF_MDS_QUOTACHECK;
                 ver = LUSTRE_MDS_VERSION;
                 opc = MDS_QUOTACHECK;
         } else if (!strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_OSC_NAME)) {
-                rf  = &RQF_OST_QUOTACHECK;
                 ver = LUSTRE_OST_VERSION;
                 opc = OST_QUOTACHECK;
         } else {
                 RETURN(-EINVAL);
         }
 
-        req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), rf, ver, opc);
-        if (req == NULL)
-                RETURN(-ENOMEM);
+        req = ptlrpc_prep_req(class_exp2cliimp(exp), ver, opc, 2, size, NULL);
+        if (!req)
+                GOTO(out, rc = -ENOMEM);
 
-        body = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
+        body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
         *body = *oqctl;
 
-        ptlrpc_request_set_replen(req);
+        ptlrpc_req_set_repsize(req, 1, NULL);
 
         /* the next poll will find -ENODATA, that means quotacheck is
          * going on */
@@ -210,6 +208,7 @@ int client_quota_check(struct obd_device *unused, struct obd_export *exp,
         rc = ptlrpc_queue_wait(req);
         if (rc)
                 cli->cl_qchk_stat = rc;
+out:
         ptlrpc_req_finished(req);
         RETURN(rc);
 }
@@ -240,33 +239,7 @@ int client_quota_poll_check(struct obd_export *exp, struct if_quotacheck *qchk)
         RETURN(rc);
 }
 
-int lmv_quota_check(struct obd_device *unused, struct obd_export *exp,
-                    struct obd_quotactl *oqctl)
-{
-        struct obd_device *obd = class_exp2obd(exp);
-        struct lmv_obd *lmv = &obd->u.lmv;
-        struct lmv_tgt_desc *tgt;
-        int i, rc = 0;
-        ENTRY;
-
-        for (i = 0, tgt = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgt++) {
-                int err;
-
-                if (!tgt->ltd_active) {
-                        CERROR("lmv idx %d inactive\n", i);
-                        RETURN(-EIO);
-                }
-
-                err = obd_quotacheck(tgt->ltd_exp, oqctl);
-                if (err && !rc)
-                        rc = err;
-        }
-
-        RETURN(rc);
-}
-
-int lov_quota_check(struct obd_device *unused, struct obd_export *exp,
-                    struct obd_quotactl *oqctl)
+int lov_quota_check(struct obd_export *exp, struct obd_quotactl *oqctl)
 {
         struct obd_device *obd = class_exp2obd(exp);
         struct lov_obd *lov = &obd->u.lov;
@@ -274,12 +247,14 @@ int lov_quota_check(struct obd_device *unused, struct obd_export *exp,
         ENTRY;
 
         for (i = 0; i < lov->desc.ld_tgt_count; i++) {
-                int err;
-
                 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active) {
                         CERROR("lov idx %d inactive\n", i);
                         RETURN(-EIO);
                 }
+        }
+
+        for (i = 0; i < lov->desc.ld_tgt_count; i++) {
+                int err;
 
                 err = obd_quotacheck(lov->lov_tgts[i]->ltd_exp, oqctl);
                 if (err && !rc)