Whamcloud - gitweb
b=19860
[fs/lustre-release.git] / lustre / quota / quota_check.c
index 7c5d749..4368db4 100644 (file)
@@ -1,66 +1,85 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- *  lustre/quota/quota_check.c
+ * GPL HEADER START
  *
- *  Copyright (c) 2005 Cluster File Systems, Inc.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- *   This file is part of Lustre, http://www.lustre.org.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
  *
- *   No redistribution or use is permitted outside of Cluster File Systems, Inc.
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
  *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Use is subject to license terms.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
  */
+
+
 #ifndef EXPORT_SYMTAB
 # define EXPORT_SYMTAB
 #endif
-#define DEBUG_SUBSYSTEM S_MDS
+#define DEBUG_SUBSYSTEM S_LQUOTA
 
 #ifdef __KERNEL__
 # 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>
-# if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
 #  include <linux/smp_lock.h>
 #  include <linux/buffer_head.h>
 #  include <linux/workqueue.h>
 #  include <linux/mount.h>
-# else
-#  include <linux/locks.h>
-# endif
 #else /* __KERNEL__ */
 # include <liblustre.h>
 #endif
 
-#include <linux/obd_class.h>
-#include <linux/lustre_mds.h>
-#include <linux/lustre_dlm.h>
-#include <linux/lustre_cfg.h>
-#include <linux/obd_ost.h>
-#include <linux/lustre_fsfilt.h>
-#include <linux/lustre_quota.h>
+#include <obd_class.h>
+#include <lustre_mds.h>
+#include <lustre_dlm.h>
+#include <lustre_cfg.h>
+#include <obd_ost.h>
+#include <lustre_fsfilt.h>
+#include <lustre_quota.h>
 #include "quota_internal.h"
 
+#ifdef HAVE_QUOTA_SUPPORT
 #ifdef __KERNEL__
 static int target_quotacheck_callback(struct obd_export *exp,
                                       struct obd_quotactl *oqctl)
 {
         struct ptlrpc_request *req;
         struct obd_quotactl *body;
-        int rc, size = sizeof(*oqctl);
+        int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*oqctl) };
         ENTRY;
 
         req = ptlrpc_prep_req(exp->exp_imp_reverse, LUSTRE_OBD_VERSION,
-                              OBD_QC_CALLBACK, 1, &size, NULL);
+                              OBD_QC_CALLBACK, 2, size, NULL);
         if (!req)
                 RETURN(-ENOMEM);
 
-        body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
+        body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
         *body = *oqctl;
 
-        req->rq_replen = lustre_msg_size(0, NULL);
+        ptlrpc_req_set_repsize(req, 1, NULL);
 
         rc = ptlrpc_queue_wait(req);
         ptlrpc_req_finished(req);
@@ -70,7 +89,6 @@ static int target_quotacheck_callback(struct obd_export *exp,
 
 static int target_quotacheck_thread(void *data)
 {
-        unsigned long flags;
         struct quotacheck_thread_args *qta = data;
         struct obd_export *exp;
         struct obd_device *obd;
@@ -78,17 +96,7 @@ static int target_quotacheck_thread(void *data)
         struct lvfs_run_ctxt saved;
         int rc;
 
-        lock_kernel();
-        ptlrpc_daemonize();
-
-        SIGNAL_MASK_LOCK(current, flags);
-        sigfillset(&current->blocked);
-        RECALC_SIGPENDING;
-        SIGNAL_MASK_UNLOCK(current, flags);
-
-        THREAD_NAME(cfs_curproc_comm(), CFS_CURPROC_COMM_MAX, "%s",
-                    "quotacheck");
-        unlock_kernel();
+        cfs_daemonize_ctxt("quotacheck");
 
         exp = qta->qta_exp;
         obd = exp->exp_obd;
@@ -103,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);
 
@@ -129,6 +138,7 @@ int target_quota_check(struct obd_export *exp, struct obd_quotactl *oqctl)
 
         qta->qta_exp = exp;
         qta->qta_oqctl = *oqctl;
+        qta->qta_oqctl.qc_id = obt->obt_qfmt; /* override qfmt version */
         qta->qta_sb = obt->obt_sb;
         qta->qta_sem = &obt->obt_quotachecking;
 
@@ -142,6 +152,9 @@ int target_quota_check(struct obd_export *exp, struct obd_quotactl *oqctl)
                 }
         }
 
+        /* 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",
@@ -149,6 +162,7 @@ int target_quota_check(struct obd_export *exp, struct obd_quotactl *oqctl)
                 RETURN(0);
         }
 
+        class_export_put(exp);
         CERROR("%s: error starting quotacheck_thread: %d\n",
                obd->obd_name, rc);
         OBD_FREE_PTR(qta);
@@ -158,35 +172,35 @@ out:
 }
 
 #endif /* __KERNEL__ */
+#endif /* HAVE_QUOTA_SUPPORT */
 
 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;
-        int size = sizeof(*body), opc, version;
-        int rc;
+        __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)) {
-                version = LUSTRE_MDS_VERSION;
+                ver = LUSTRE_MDS_VERSION;
                 opc = MDS_QUOTACHECK;
         } else if (!strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_OSC_NAME)) {
-                version = LUSTRE_OST_VERSION;
+                ver = LUSTRE_OST_VERSION;
                 opc = OST_QUOTACHECK;
         } else {
                 RETURN(-EINVAL);
         }
 
-        req = ptlrpc_prep_req(class_exp2cliimp(exp), version, opc, 1, &size,
-                              NULL);
+        req = ptlrpc_prep_req(class_exp2cliimp(exp), ver, opc, 2, size, NULL);
         if (!req)
                 GOTO(out, rc = -ENOMEM);
 
-        body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
+        body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
         *body = *oqctl;
 
-        req->rq_replen = lustre_msg_size(0, NULL);
+        ptlrpc_req_set_repsize(req, 1, NULL);
 
         /* the next poll will find -ENODATA, that means quotacheck is
          * going on */
@@ -211,13 +225,14 @@ int client_quota_poll_check(struct obd_export *exp, struct if_quotacheck *qchk)
         if (rc == CL_NOT_QUOTACHECKED)
                 rc = -EINTR;
 
-        qchk->obd_uuid = cli->cl_import->imp_target_uuid;
+        qchk->obd_uuid = cli->cl_target_uuid;
+        /* FIXME change strncmp to strcmp and save the strlen op */
         if (strncmp(exp->exp_obd->obd_type->typ_name, LUSTRE_OSC_NAME,
-            strlen(LUSTRE_OSC_NAME)))
-                memcpy(qchk->obd_type, LUSTRE_FILTER_NAME,
-                       strlen(LUSTRE_FILTER_NAME));
+                    strlen(LUSTRE_OSC_NAME)) == 0)
+                memcpy(qchk->obd_type, LUSTRE_OST_NAME,
+                       strlen(LUSTRE_OST_NAME));
         else if (strncmp(exp->exp_obd->obd_type->typ_name, LUSTRE_MDC_NAME,
-                 strlen(LUSTRE_MDC_NAME)))
+                         strlen(LUSTRE_MDC_NAME)) == 0)
                 memcpy(qchk->obd_type, LUSTRE_MDS_NAME,
                        strlen(LUSTRE_MDS_NAME));
 
@@ -232,15 +247,17 @@ int lov_quota_check(struct obd_export *exp, struct obd_quotactl *oqctl)
         ENTRY;
 
         for (i = 0; i < lov->desc.ld_tgt_count; i++) {
-                int err;
-
-                if (!lov->tgts[i].active) {
+                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->tgts[i].ltd_exp, oqctl);
-                if (err && lov->tgts[i].active && !rc)
+                err = obd_quotacheck(lov->lov_tgts[i]->ltd_exp, oqctl);
+                if (err && !rc)
                         rc = err;
         }