Whamcloud - gitweb
LU-709 build: clean up quota_read, follow_link and RCU
[fs/lustre-release.git] / lustre / lvfs / quotafmt_test.c
index 09e10af..98bb156 100644 (file)
@@ -1,26 +1,57 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
+/*
+ * GPL HEADER START
  *
- *   No redistribution or use is permitted outside of Cluster File Systems, Inc.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * 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.
+ *
+ * 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 (c) 2007, 2010, Oracle and/or its affiliates. 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.
+ *
+ * lustre/lvfs/quotafmt_test.c
+ *
+ * No redistribution or use is permitted outside of Sun Microsystems, Inc.
  *
  * Kernel module to test lustre administrative quotafile format APIs
- * from the OBD setup function */
-#ifndef EXPORT_SYMTAB
-# define EXPORT_SYMTAB
-#endif
+ * from the OBD setup function
+ */
 
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/errno.h>
 #include <linux/fs.h>
 #include <linux/kernel.h>
-#include <linux/random.h>
 
 #include <lustre_quota.h>
 #include <obd_class.h>
 
 #include "lustre_quota_fmt.h"
 
+#ifdef HAVE_QUOTA_SUPPORT
+
 char *test_quotafile[2] = { "usrquota_test", "grpquota_test" };
 
 static int quotfmt_initialize(struct lustre_quota_info *lqi,
@@ -29,7 +60,7 @@ static int quotfmt_initialize(struct lustre_quota_info *lqi,
 {
         struct lustre_disk_dqheader dqhead;
         static const uint quota_magics[] = LUSTRE_INITQMAGICS;
-        static const uint quota_versions[] = LUSTRE_INITQVERSIONS;
+        static const uint quota_versions[] = LUSTRE_INITQVERSIONS_V2;
         struct file *fp;
         struct inode *parent_inode = tgt->obd_lvfs_ctxt.pwd->d_inode;
         size_t size;
@@ -45,10 +76,11 @@ static int quotfmt_initialize(struct lustre_quota_info *lqi,
                 int namelen = strlen(name);
 
                 /* remove the stale test quotafile */
-                LOCK_INODE_MUTEX(parent_inode);
+                LOCK_INODE_MUTEX_PARENT(parent_inode);
                 de = lookup_one_len(name, tgt->obd_lvfs_ctxt.pwd, namelen);
                 if (!IS_ERR(de) && de->d_inode)
-                        vfs_unlink(parent_inode, de);
+                        ll_vfs_unlink(parent_inode, de,
+                                      tgt->obd_lvfs_ctxt.pwdmnt);
                 if (!IS_ERR(de))
                         dput(de);
                 UNLOCK_INODE_MUTEX(parent_inode);
@@ -70,7 +102,7 @@ static int quotfmt_initialize(struct lustre_quota_info *lqi,
                                        sizeof(struct lustre_disk_dqheader),
                                        &offset);
                 if (size != sizeof(struct lustre_disk_dqheader)) {
-                        CERROR("error writing quoafile header %s (rc = %d)\n",
+                        CERROR("error writing quotafile header %s (rc = %d)\n",
                                name, rc);
                         rc = size;
                         break;
@@ -99,7 +131,7 @@ static int quotfmt_finalize(struct lustre_quota_info *lqi,
                 filp_close(lqi->qi_files[i], 0);
 
                 /* unlink quota file */
-                LOCK_INODE_MUTEX(parent_inode);
+                LOCK_INODE_MUTEX_PARENT(parent_inode);
 
                 de = lookup_one_len(name, tgt->obd_lvfs_ctxt.pwd, namelen);
                 if (IS_ERR(de) || de->d_inode == NULL) {
@@ -109,7 +141,7 @@ static int quotfmt_finalize(struct lustre_quota_info *lqi,
                         goto dput;
                 }
 
-                rc = vfs_unlink(parent_inode, de);
+                rc = ll_vfs_unlink(parent_inode, de, tgt->obd_lvfs_ctxt.pwdmnt);
                 if (rc)
                         CERROR("error unlink quotafile %s (rc = %d)\n",
                                name, rc);
@@ -129,7 +161,7 @@ static int quotfmt_test_1(struct lustre_quota_info *lqi)
         ENTRY;
 
         for (i = 0; i < MAXQUOTAS; i++) {
-                if (!lustre_check_quota_file(lqi, i))
+                if (lustre_check_quota_file(lqi, i))
                         RETURN(-EINVAL);
         }
         RETURN(0);
@@ -143,13 +175,12 @@ static void print_quota_info(struct lustre_quota_info *lqi)
 
         for (i = 0; i < MAXQUOTAS; i++) {
                 dqinfo = &lqi->qi_info[i];
-                printk("%s quota info:\n", i == USRQUOTA ? "user " : "group");
-                printk
-                    ("dqi_bgrace(%u) dqi_igrace(%u) dqi_flags(%lu) dqi_blocks(%u) "
-                     "dqi_free_blk(%u) dqi_free_entry(%u)\n",
-                     dqinfo->dqi_bgrace, dqinfo->dqi_igrace, dqinfo->dqi_flags,
-                     dqinfo->dqi_blocks, dqinfo->dqi_free_blk,
-                     dqinfo->dqi_free_entry);
+                CDEBUG(D_INFO, "%s quota info:\n", i == USRQUOTA ? "user " : "group");
+                CDEBUG(D_INFO, "dqi_bgrace(%u) dqi_igrace(%u) dqi_flags(%lu) dqi_blocks(%u) "
+                       "dqi_free_blk(%u) dqi_free_entry(%u)\n",
+                       dqinfo->dqi_bgrace, dqinfo->dqi_igrace, dqinfo->dqi_flags,
+                       dqinfo->dqi_blocks, dqinfo->dqi_free_blk,
+                       dqinfo->dqi_free_entry);
         }
 #endif
 }
@@ -192,7 +223,7 @@ static struct lustre_dquot *get_rand_dquot(struct lustre_quota_info *lqi)
         if (dquot == NULL)
                 return NULL;
 
-        get_random_bytes(&rand, sizeof(rand));
+        cfs_get_random_bytes(&rand, sizeof(rand));
         if (!rand)
                 rand = 1000;
 
@@ -220,7 +251,7 @@ static void put_rand_dquot(struct lustre_dquot *dquot)
 static int write_check_dquot(struct lustre_quota_info *lqi)
 {
         struct lustre_dquot *dquot;
-        struct mem_dqblk dqblk;
+        struct lustre_mem_dqblk dqblk;
         int rc = 0;
         ENTRY;
 
@@ -235,7 +266,7 @@ static int write_check_dquot(struct lustre_quota_info *lqi)
                 GOTO(out, rc);
         }
 
-        clear_bit(DQ_FAKE_B, &dquot->dq_flags);
+        cfs_clear_bit(DQ_FAKE_B, &dquot->dq_flags);
         /* for already exists entry, we rewrite it */
         rc = lustre_commit_dquot(dquot);
         if (rc) {
@@ -270,7 +301,7 @@ static int quotfmt_test_3(struct lustre_quota_info *lqi)
         if (dquot == NULL)
                 RETURN(-ENOMEM);
       repeat:
-        clear_bit(DQ_FAKE_B, &dquot->dq_flags);
+        cfs_clear_bit(DQ_FAKE_B, &dquot->dq_flags);
         /* write a new dquot */
         rc = lustre_commit_dquot(dquot);
         if (rc) {
@@ -286,13 +317,13 @@ static int quotfmt_test_3(struct lustre_quota_info *lqi)
                 CERROR("read dquot failed! (rc:%d)\n", rc);
                 GOTO(out, rc);
         }
-        if (!dquot->dq_off || test_bit(DQ_FAKE_B, &dquot->dq_flags)) {
+        if (!dquot->dq_off || cfs_test_bit(DQ_FAKE_B, &dquot->dq_flags)) {
                 CERROR("the dquot isn't committed\n");
                 GOTO(out, rc = -EINVAL);
         }
 
         /* remove this dquot */
-        set_bit(DQ_FAKE_B, &dquot->dq_flags);
+        cfs_set_bit(DQ_FAKE_B, &dquot->dq_flags);
         dquot->dq_dqb.dqb_curspace = 0;
         dquot->dq_dqb.dqb_curinodes = 0;
         rc = lustre_commit_dquot(dquot);
@@ -302,14 +333,14 @@ static int quotfmt_test_3(struct lustre_quota_info *lqi)
         }
 
         /* check if the dquot is really removed */
-        clear_bit(DQ_FAKE_B, &dquot->dq_flags);
+        cfs_clear_bit(DQ_FAKE_B, &dquot->dq_flags);
         dquot->dq_off = 0;
         rc = lustre_read_dquot(dquot);
         if (rc) {
                 CERROR("read dquot failed! (rc:%d)\n", rc);
                 GOTO(out, rc);
         }
-        if (!test_bit(DQ_FAKE_B, &dquot->dq_flags) || dquot->dq_off) {
+        if (!cfs_test_bit(DQ_FAKE_B, &dquot->dq_flags) || dquot->dq_off) {
                 CERROR("the dquot isn't removed!\n");
                 GOTO(out, rc = -EINVAL);
         }
@@ -342,37 +373,6 @@ static int quotfmt_test_4(struct lustre_quota_info *lqi)
         RETURN(rc);
 }
 
-static int quotfmt_test_5(struct lustre_quota_info *lqi)
-{
-#ifndef KERNEL_SUPPORTS_QUOTA_READ 
-        int i, rc = 0;
-
-        for (i = USRQUOTA; i < MAXQUOTAS && !rc; i++) {
-                struct list_head list;
-                struct dquot_id *dqid, *tmp;
-
-                INIT_LIST_HEAD(&list);
-                rc = lustre_get_qids(lqi->qi_files[i], NULL, i, &list);
-                if (rc) {
-                        CERROR("%s get all %ss (rc:%d):\n",
-                               rc ? "error" : "success",
-                               i == USRQUOTA ? "uid" : "gid", rc);
-                }
-                list_for_each_entry_safe(dqid, tmp, &list, di_link) {
-                        list_del_init(&dqid->di_link);
-                        if (rc == 0)
-                                printk("%d ", dqid->di_id);
-                        kfree(dqid);
-                }
-                printk("\n");
-        }
-        return rc;
-#else
-        CWARN("kernel supports quota_read OR kernel version >= 2.6.12, test skipped\n");
-        return 0;
-#endif
-}
-
 static int quotfmt_run_tests(struct obd_device *obd, struct obd_device *tgt)
 {
         struct lvfs_run_ctxt saved;
@@ -419,14 +419,7 @@ static int quotfmt_run_tests(struct obd_device *obd, struct obd_device *tgt)
                 GOTO(out, rc);
         }
 
-        CWARN("=== test 5: walk through quota file to get all ids\n");
-        rc = quotfmt_test_5(lqi);
-        if (rc) {
-                CERROR("walk through quota file failed\n");
-                GOTO(out, rc);
-        }
-
-      out:
+out:
         CWARN("=== Finalize quotafile test\n");
         rc = quotfmt_finalize(lqi, tgt, &saved);
         OBD_FREE(lqi, sizeof(*lqi));
@@ -440,10 +433,9 @@ static int quotfmt_test_cleanup(struct obd_device *obd)
         RETURN(0);
 }
 
-static int quotfmt_test_setup(struct obd_device *obd, obd_count len, void *buf)
+static int quotfmt_test_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
 {
         struct lprocfs_static_vars lvars;
-        struct lustre_cfg *lcfg = buf;
         struct obd_device *tgt;
         int rc;
         ENTRY;
@@ -464,7 +456,7 @@ static int quotfmt_test_setup(struct obd_device *obd, obd_count len, void *buf)
         if (rc)
                 quotfmt_test_cleanup(obd);
 
-        lprocfs_init_vars(quotfmt_test, &lvars);
+        lprocfs_quotfmt_test_init_vars(&lvars);
         lprocfs_obd_setup(obd, lvars.obd_vars);
 
         RETURN(rc);
@@ -477,18 +469,22 @@ static struct obd_ops quotfmt_obd_ops = {
 };
 
 #ifdef LPROCFS
-static struct lprocfs_vars lprocfs_obd_vars[] = { {0} };
-static struct lprocfs_vars lprocfs_module_vars[] = { {0} };
+static struct lprocfs_vars lprocfs_quotfmt_test_obd_vars[] = { {0} };
+static struct lprocfs_vars lprocfs_quotfmt_test_module_vars[] = { {0} };
 
-LPROCFS_INIT_VARS(quotfmt_test, lprocfs_module_vars, lprocfs_obd_vars)
+void lprocfs_quotfmt_test_init_vars(struct lprocfs_static_vars *lvars)
+{
+    lvars->module_vars  = lprocfs_quotfmt_test_module_vars;
+    lvars->obd_vars     = lprocfs_quotfmt_test_obd_vars;
+}
 #endif
 static int __init quotfmt_test_init(void)
 {
         struct lprocfs_static_vars lvars;
 
-        lprocfs_init_vars(quotfmt_test, &lvars);
-        return class_register_type(&quotfmt_obd_ops, lvars.module_vars,
-                                   "quotfmt_test");
+        lprocfs_quotfmt_test_init_vars(&lvars);
+        return class_register_type(&quotfmt_obd_ops, NULL, lvars.module_vars,
+                                   "quotfmt_test", NULL);
 }
 
 static void __exit quotfmt_test_exit(void)
@@ -496,9 +492,11 @@ static void __exit quotfmt_test_exit(void)
         class_unregister_type("quotfmt_test");
 }
 
-MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
+MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
 MODULE_DESCRIPTION("administrative quotafile test module");
 MODULE_LICENSE("GPL");
 
 module_init(quotfmt_test_init);
 module_exit(quotfmt_test_exit);
+
+#endif /* HAVE_QUOTA_SUPPORT */