1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/quota/quotacheck_test.c
38 * Author: Lai Siyao <lsy@clusterfs.com>
42 # define EXPORT_SYMTAB
44 #define DEBUG_SUBSYSTEM S_CLASS
46 #include <linux/module.h>
47 #include <linux/init.h>
49 #include <linux/jbd.h>
50 #include <linux/slab.h>
51 #include <linux/pagemap.h>
52 #include <linux/quotaops.h>
53 #include <linux/ext3_fs.h>
54 #include <linux/ext3_jbd.h>
55 #include <linux/version.h>
56 #include <linux/bitops.h>
58 #include <obd_class.h>
59 #include <lustre_fsfilt.h>
60 #include <lustre_mds.h>
63 char *test_quotafile[] = {"aquotacheck.user", "aquotacheck.group"};
65 static inline struct ext3_group_desc *
66 get_group_desc(struct super_block *sb, int group)
68 unsigned long desc_block, desc;
69 struct ext3_group_desc *gdp;
71 desc_block = group / EXT3_DESC_PER_BLOCK(sb);
72 desc = group % EXT3_DESC_PER_BLOCK(sb);
73 gdp = (struct ext3_group_desc *)
74 EXT3_SB(sb)->s_group_desc[desc_block]->b_data;
79 static inline struct buffer_head *
80 read_inode_bitmap(struct super_block *sb, unsigned long group)
82 struct ext3_group_desc *desc;
83 struct buffer_head *bh;
85 desc = get_group_desc(sb, group);
86 bh = sb_bread(sb, le32_to_cpu(desc->bg_inode_bitmap));
91 static inline struct inode *ext3_iget_inuse(struct super_block *sb,
92 struct buffer_head *bitmap_bh,
93 int index, unsigned long ino)
95 struct inode *inode = NULL;
97 if (ext3_test_bit(index, bitmap_bh->b_data)) {
98 CERROR("i: %d, ino: %lu\n", index, ino);
100 inode = iget(sb, ino);
106 static void print_inode(struct inode *inode)
110 if (S_ISDIR(inode->i_mode) ||
111 S_ISREG(inode->i_mode) ||
112 S_ISLNK(inode->i_mode))
113 size = inode_get_bytes(inode);
115 CERROR("%lu: uid: %u, size: %llu, blocks: %llu, real size: %llu\n",
116 inode->i_ino, inode->i_uid, i_size_read(inode),
117 (unsigned long long)inode->i_blocks, size);
121 static int quotacheck_test_1(struct obd_device *obd, struct super_block *sb)
123 struct ext3_sb_info *sbi = EXT3_SB(sb);
124 struct buffer_head *bitmap_bh = NULL;
130 for (group = 0; group < sbi->s_groups_count; group++) {
131 ino = group * sbi->s_inodes_per_group + 1;
133 bitmap_bh = read_inode_bitmap(sb, group);
136 CERROR("groups_count: %lu, inodes_per_group: %lu, first_ino: %u, inodes_count: %u\n",
137 sbi->s_groups_count, sbi->s_inodes_per_group,
138 sbi->s_first_ino, le32_to_cpu(sbi->s_es->s_inodes_count));
140 for (i = 0; i < sbi->s_inodes_per_group; i++, ino++) {
141 if (ino < sbi->s_first_ino)
143 if (ino > le32_to_cpu(sbi->s_es->s_inodes_count)) {
144 CERROR("bad inode number: %lu > s_inodes_count\n", ino);
148 inode = ext3_iget_inuse(sb, bitmap_bh, i, ino);
159 /* -------------------------------------------------------------------------
160 * Tests above, boring obd functions below
161 * ------------------------------------------------------------------------- */
162 static int quotacheck_run_tests(struct obd_device *obd, struct obd_device *tgt)
167 if (strcmp(tgt->obd_type->typ_name, LUSTRE_MDS_NAME) &&
168 !strcmp(tgt->obd_type->typ_name, "obdfilter")) {
169 CERROR("TARGET OBD should be mds or ost\n");
173 rc = quotacheck_test_1(tgt, tgt->u.obt.obt_sb);
179 static struct lprocfs_vars lprocfs_quotacheck_test_obd_vars[] = { {0} };
180 static struct lprocfs_vars lprocfs_quotacheck_test_module_vars[] = { {0} };
182 void lprocfs_quotacheck_test_init_vars(struct lprocfs_static_vars *lvars)
184 lvars->module_vars = lprocfs_quotacheck_test_module_vars;
185 lvars->obd_vars = lprocfs_quotacheck_test_obd_vars;
189 static int quotacheck_test_cleanup(struct obd_device *obd)
191 lprocfs_obd_cleanup(obd);
195 static int quotacheck_test_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
197 struct lprocfs_static_vars lvars = { 0 };
198 struct obd_device *tgt;
202 if (lcfg->lcfg_bufcount < 1) {
203 CERROR("requires a mds OBD name\n");
207 tgt = class_name2obd(lustre_cfg_string(lcfg, 1));
208 if (!tgt || !tgt->obd_attached || !tgt->obd_set_up) {
209 CERROR("target device not attached or not set up (%s)\n",
210 lustre_cfg_string(lcfg, 1));
214 rc = quotacheck_run_tests(obd, tgt);
216 quotacheck_test_cleanup(obd);
218 lprocfs_quotacheck_test_init_vars(&lvars);
219 lprocfs_obd_setup(obd, lvars.obd_vars);
224 static struct obd_ops quotacheck_obd_ops = {
225 .o_owner = THIS_MODULE,
226 .o_setup = quotacheck_test_setup,
227 .o_cleanup = quotacheck_test_cleanup,
230 static int __init quotacheck_test_init(void)
232 struct lprocfs_static_vars lvars = { 0 };
234 lprocfs_quotacheck_test_init_vars(&lvars);
235 return class_register_type("acheck_obd_ops, NULL, lvars.module_vars,
236 "quotacheck_test", NULL);
239 static void __exit quotacheck_test_exit(void)
241 class_unregister_type("quotacheck_test");
244 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
245 MODULE_DESCRIPTION("quotacheck test module");
246 MODULE_LICENSE("GPL");
248 module_init(quotacheck_test_init);
249 module_exit(quotacheck_test_exit);