Merge git://git.infradead.org/mtd-2.6
[linux-2.6] / fs / xfs / quota / xfs_qm_stats.c
1 /*
2  * Copyright (c) 2000-2003 Silicon Graphics, Inc.
3  * All Rights Reserved.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it would be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write the Free Software Foundation,
16  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18 #include "xfs.h"
19 #include "xfs_fs.h"
20 #include "xfs_bit.h"
21 #include "xfs_log.h"
22 #include "xfs_inum.h"
23 #include "xfs_trans.h"
24 #include "xfs_sb.h"
25 #include "xfs_ag.h"
26 #include "xfs_dir2.h"
27 #include "xfs_alloc.h"
28 #include "xfs_dmapi.h"
29 #include "xfs_quota.h"
30 #include "xfs_mount.h"
31 #include "xfs_bmap_btree.h"
32 #include "xfs_alloc_btree.h"
33 #include "xfs_ialloc_btree.h"
34 #include "xfs_dir2_sf.h"
35 #include "xfs_attr_sf.h"
36 #include "xfs_dinode.h"
37 #include "xfs_inode.h"
38 #include "xfs_ialloc.h"
39 #include "xfs_itable.h"
40 #include "xfs_bmap.h"
41 #include "xfs_btree.h"
42 #include "xfs_rtalloc.h"
43 #include "xfs_error.h"
44 #include "xfs_rw.h"
45 #include "xfs_attr.h"
46 #include "xfs_buf_item.h"
47 #include "xfs_qm.h"
48
49 struct xqmstats xqmstats;
50
51 STATIC int
52 xfs_qm_read_xfsquota(
53         char            *buffer,
54         char            **start,
55         off_t           offset,
56         int             count,
57         int             *eof,
58         void            *data)
59 {
60         int             len;
61
62         /* maximum; incore; ratio free to inuse; freelist */
63         len = sprintf(buffer, "%d\t%d\t%d\t%u\n",
64                         ndquot,
65                         xfs_Gqm? atomic_read(&xfs_Gqm->qm_totaldquots) : 0,
66                         xfs_Gqm? xfs_Gqm->qm_dqfree_ratio : 0,
67                         xfs_Gqm? xfs_Gqm->qm_dqfreelist.qh_nelems : 0);
68
69         if (offset >= len) {
70                 *start = buffer;
71                 *eof = 1;
72                 return 0;
73         }
74         *start = buffer + offset;
75         if ((len -= offset) > count)
76                 return count;
77         *eof = 1;
78
79         return len;
80 }
81
82 STATIC int
83 xfs_qm_read_stats(
84         char            *buffer,
85         char            **start,
86         off_t           offset,
87         int             count,
88         int             *eof,
89         void            *data)
90 {
91         int             len;
92
93         /* quota performance statistics */
94         len = sprintf(buffer, "qm %u %u %u %u %u %u %u %u\n",
95                         xqmstats.xs_qm_dqreclaims,
96                         xqmstats.xs_qm_dqreclaim_misses,
97                         xqmstats.xs_qm_dquot_dups,
98                         xqmstats.xs_qm_dqcachemisses,
99                         xqmstats.xs_qm_dqcachehits,
100                         xqmstats.xs_qm_dqwants,
101                         xqmstats.xs_qm_dqshake_reclaims,
102                         xqmstats.xs_qm_dqinact_reclaims);
103
104         if (offset >= len) {
105                 *start = buffer;
106                 *eof = 1;
107                 return 0;
108         }
109         *start = buffer + offset;
110         if ((len -= offset) > count)
111                 return count;
112         *eof = 1;
113
114         return len;
115 }
116
117 void
118 xfs_qm_init_procfs(void)
119 {
120         create_proc_read_entry("fs/xfs/xqmstat", 0, NULL, xfs_qm_read_stats, NULL);
121         create_proc_read_entry("fs/xfs/xqm", 0, NULL, xfs_qm_read_xfsquota, NULL);
122 }
123
124 void
125 xfs_qm_cleanup_procfs(void)
126 {
127         remove_proc_entry("fs/xfs/xqm", NULL);
128         remove_proc_entry("fs/xfs/xqmstat", NULL);
129 }