Whamcloud - gitweb
merge b_devel into HEAD, which will become 0.7.3
[fs/lustre-release.git] / lustre / llite / lproc_llite.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2002 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  */
22 #define DEBUG_SUBSYSTEM S_LLITE
23
24 #include <linux/version.h>
25 #include <linux/lustre_lite.h>
26 #include <linux/lprocfs_status.h>
27
28 #include "llite_internal.h"
29
30 /* /proc/lustre/llite mount point registration */
31 struct proc_dir_entry *proc_lustre_fs_root;
32
33 #ifndef LPROCFS
34 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
35                                 struct super_block *sb, char *osc, char *mdc)
36 {
37         return 0;
38 }
39 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi){}
40 #else
41
42 long long mnt_instance;
43
44 static int ll_rd_blksize(char *page, char **start, off_t off, int count,
45                          int *eof, void *data)
46 {
47         struct super_block *sb = (struct super_block *)data;
48         struct obd_statfs osfs;
49         int rc;
50
51         LASSERT(sb != NULL);
52         rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
53         if (!rc) {
54               *eof = 1;
55               rc = snprintf(page, count, "%u\n", osfs.os_bsize);
56         }
57
58         return rc;
59 }
60
61 static int ll_rd_kbytestotal(char *page, char **start, off_t off, int count,
62                              int *eof, void *data)
63 {
64         struct super_block *sb = (struct super_block *)data;
65         struct obd_statfs osfs;
66         int rc;
67
68         LASSERT(sb != NULL);
69         rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
70         if (!rc) {
71                 __u32 blk_size = osfs.os_bsize >> 10;
72                 __u64 result = osfs.os_blocks;
73
74                 while (blk_size >>= 1)
75                         result <<= 1;
76
77                 *eof = 1;
78                 rc = snprintf(page, count, LPU64"\n", result);
79         }
80         return rc;
81
82 }
83
84 static int ll_rd_kbytesfree(char *page, char **start, off_t off, int count,
85                             int *eof, void *data)
86 {
87         struct super_block *sb = (struct super_block *)data;
88         struct obd_statfs osfs;
89         int rc;
90
91         LASSERT(sb != NULL);
92         rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
93         if (!rc) {
94                 __u32 blk_size = osfs.os_bsize >> 10;
95                 __u64 result = osfs.os_bfree;
96
97                 while (blk_size >>= 1)
98                         result <<= 1;
99
100                 *eof = 1;
101                 rc = snprintf(page, count, LPU64"\n", result);
102         }
103         return rc;
104 }
105
106 static int ll_rd_filestotal(char *page, char **start, off_t off, int count,
107                             int *eof, void *data)
108 {
109         struct super_block *sb = (struct super_block *)data;
110         struct obd_statfs osfs;
111         int rc;
112
113         LASSERT(sb != NULL);
114         rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
115         if (!rc) {
116                  *eof = 1;
117                  rc = snprintf(page, count, LPU64"\n", osfs.os_files);
118         }
119         return rc;
120 }
121
122 static int ll_rd_filesfree(char *page, char **start, off_t off, int count,
123                            int *eof, void *data)
124 {
125         struct super_block *sb = (struct super_block *)data;
126         struct obd_statfs osfs;
127         int rc;
128
129         LASSERT(sb != NULL);
130         rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
131         if (!rc) {
132                  *eof = 1;
133                  rc = snprintf(page, count, LPU64"\n", osfs.os_ffree);
134         }
135         return rc;
136
137 }
138
139 #if 0
140 static int ll_rd_path(char *page, char **start, off_t off, int count, int *eof,
141                       void *data)
142 {
143         return 0;
144 }
145 #endif
146
147 static int ll_rd_fstype(char *page, char **start, off_t off, int count,
148                         int *eof, void *data)
149 {
150         struct super_block *sb = (struct super_block*)data;
151
152         LASSERT(sb != NULL);
153         *eof = 1;
154         return snprintf(page, count, "%s\n", sb->s_type->name);
155 }
156
157 static int ll_rd_sb_uuid(char *page, char **start, off_t off, int count,
158                          int *eof, void *data)
159 {
160         struct super_block *sb = (struct super_block *)data;
161
162         LASSERT(sb != NULL);
163         *eof = 1;
164         return snprintf(page, count, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
165 }
166
167 static struct lprocfs_vars lprocfs_obd_vars[] = {
168         { "uuid",         ll_rd_sb_uuid,          0, 0 },
169         //{ "mntpt_path",   ll_rd_path,             0, 0 },
170         { "fstype",       ll_rd_fstype,           0, 0 },
171         { "blocksize",    ll_rd_blksize,          0, 0 },
172         { "kbytestotal",  ll_rd_kbytestotal,      0, 0 },
173         { "kbytesfree",   ll_rd_kbytesfree,       0, 0 },
174         { "filestotal",   ll_rd_filestotal,       0, 0 },
175         { "filesfree",    ll_rd_filesfree,        0, 0 },
176         //{ "filegroups",   lprocfs_rd_filegroups,  0, 0 },
177 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
178         { "dirty_pages",  ll_rd_dirty_pages,      0, 0},
179         { "max_dirty_pages", ll_rd_max_dirty_pages, ll_wr_max_dirty_pages, 0},
180 #endif
181         { 0 }
182 };
183
184 #define MAX_STRING_SIZE 128
185
186 struct llite_file_opcode {
187         __u32       opcode;
188         __u32       type;
189         const char *opname;
190 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
191         /* file operation */
192         { LPROC_LL_DIRTY_HITS,     LPROCFS_TYPE_REGS, "dirty_pages_hits" },
193         { LPROC_LL_DIRTY_MISSES,   LPROCFS_TYPE_REGS, "dirty_pages_misses" },
194         { LPROC_LL_WB_WRITEPAGE,   LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
195                                    "writeback_from_writepage" },
196         { LPROC_LL_WB_PRESSURE,    LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
197                                    "writeback_from_pressure" },
198         { LPROC_LL_WB_OK,          LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
199                                    "writeback_ok_pages" },
200         { LPROC_LL_WB_FAIL,        LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
201                                    "writeback_failed_pages" },
202         { LPROC_LL_READ_BYTES,     LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
203                                    "read_bytes" },
204         { LPROC_LL_WRITE_BYTES,    LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
205                                    "write_bytes" },
206         { LPROC_LL_BRW_READ,       LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
207                                    "brw_read" },
208         { LPROC_LL_BRW_WRITE,      LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
209                                    "brw_write" },
210
211         { LPROC_LL_IOCTL,          LPROCFS_TYPE_REGS, "ioctl" },
212         { LPROC_LL_OPEN,           LPROCFS_TYPE_REGS, "open" },
213         { LPROC_LL_RELEASE,        LPROCFS_TYPE_REGS, "close" },
214         { LPROC_LL_MAP,            LPROCFS_TYPE_REGS, "mmap" },
215         { LPROC_LL_LLSEEK,         LPROCFS_TYPE_REGS, "seek" },
216         { LPROC_LL_FSYNC,          LPROCFS_TYPE_REGS, "fsync" },
217         /* inode operation */
218         { LPROC_LL_SETATTR_RAW,    LPROCFS_TYPE_REGS, "setattr_raw" },
219         { LPROC_LL_SETATTR,        LPROCFS_TYPE_REGS, "setattr" },
220         { LPROC_LL_TRUNC,          LPROCFS_TYPE_REGS, "punch" },
221 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
222         { LPROC_LL_GETATTR,        LPROCFS_TYPE_REGS, "getattr" },
223 #else
224         { LPROC_LL_REVALIDATE,     LPROCFS_TYPE_REGS, "getattr" },
225 #endif
226         /* special inode operation */
227         { LPROC_LL_STAFS,          LPROCFS_TYPE_REGS, "statfs" },
228         { LPROC_LL_ALLOC_INODE,    LPROCFS_TYPE_REGS, "alloc_inode" },
229         { LPROC_LL_DIRECT_READ,    LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
230                                    "direct_read" },
231         { LPROC_LL_DIRECT_WRITE,   LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
232                                    "direct_write" },
233
234 };
235
236 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
237                                 struct super_block *sb, char *osc, char *mdc)
238 {
239         struct lprocfs_vars lvars[2];
240         struct ll_sb_info *sbi = ll_s2sbi(sb);
241         struct obd_device *obd;
242         char name[MAX_STRING_SIZE + 1];
243         int err, id;
244         struct lprocfs_stats *svc_stats = NULL;
245         ENTRY;
246
247         memset(lvars, 0, sizeof(lvars));
248
249         name[MAX_STRING_SIZE] = '\0';
250         lvars[0].name = name;
251
252         LASSERT(sbi != NULL);
253         LASSERT(mdc != NULL);
254         LASSERT(osc != NULL);
255
256         /* Mount info */
257         snprintf(name, MAX_STRING_SIZE, "fs%llu", mnt_instance);
258
259         mnt_instance++;
260         sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
261         if (IS_ERR(sbi->ll_proc_root)) {
262                 err = PTR_ERR(sbi->ll_proc_root);
263                 sbi->ll_proc_root = NULL;
264                 RETURN(err);
265         }
266
267         svc_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES);
268         if (svc_stats == NULL) {
269                 err = -ENOMEM;
270                 goto out;
271         }
272         /* do counter init */
273         for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
274                 __u32 type = llite_opcode_table[id].type;
275                 void *ptr = NULL;
276                 if (type & LPROCFS_TYPE_REGS)
277                         ptr = "regs";
278                 else {
279                         if (type & LPROCFS_TYPE_BYTES)
280                                 ptr = "bytes";
281                         else {
282                                 if (type & LPROCFS_TYPE_PAGES)
283                                         ptr = "pages";
284                         }
285                 }
286                 lprocfs_counter_init(svc_stats, llite_opcode_table[id].opcode,
287                                      (type & LPROCFS_CNTR_AVGMINMAX),
288                                      llite_opcode_table[id].opname, ptr);
289         }
290         err = lprocfs_register_stats(sbi->ll_proc_root, "stats", svc_stats);
291         if (err)
292                 goto out;
293         else
294                 sbi->ll_stats = svc_stats;
295         /* need place to keep svc_stats */
296
297         /* Static configuration info */
298         err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_obd_vars, sb);
299         if (err)
300                 goto out;
301
302         /* MDC info */
303         obd = class_name2obd(mdc);
304
305         LASSERT(obd != NULL);
306         LASSERT(obd->obd_type != NULL);
307         LASSERT(obd->obd_type->typ_name != NULL);
308
309         snprintf(name, MAX_STRING_SIZE, "%s/common_name",
310                  obd->obd_type->typ_name);
311         lvars[0].read_fptr = lprocfs_rd_name;
312         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
313         if (err)
314                 goto out;
315
316         snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
317         lvars[0].read_fptr = lprocfs_rd_uuid;
318         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
319         if (err)
320                 goto out;
321
322         /* OSC */
323         obd = class_name2obd(osc);
324
325         LASSERT(obd != NULL);
326         LASSERT(obd->obd_type != NULL);
327         LASSERT(obd->obd_type->typ_name != NULL);
328
329         snprintf(name, MAX_STRING_SIZE, "%s/common_name",
330                  obd->obd_type->typ_name);
331         lvars[0].read_fptr = lprocfs_rd_name;
332         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
333         if (err)
334                 goto out;
335
336         snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
337         lvars[0].read_fptr = lprocfs_rd_uuid;
338         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
339 out:
340         if (err) {
341                 if (svc_stats)
342                         lprocfs_free_stats(svc_stats);
343                 if (sbi->ll_proc_root)
344                         lprocfs_remove(sbi->ll_proc_root);
345         }
346         RETURN(err);
347 }
348
349 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
350 {
351         if (sbi->ll_proc_root) {
352                 struct proc_dir_entry *file_stats =
353                         lprocfs_srch(sbi->ll_proc_root, "stats");
354
355                 if (file_stats) {
356                         lprocfs_free_stats(sbi->ll_stats);
357                         lprocfs_remove(file_stats);
358                 }
359         }
360 }
361 #undef MAX_STRING_SIZE
362 #endif /* LPROCFS */