Whamcloud - gitweb
merge b_devel into HEAD (20030703)
[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 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
26 #include <asm/statfs.h>
27 #endif
28 #include <linux/lustre_lite.h>
29 #include <linux/lprocfs_status.h>
30
31 #include "llite_internal.h"
32
33 /* /proc/lustre/llite mount point registration */
34
35 #ifndef LPROCFS
36 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
37                                 struct super_block *sb, char *osc, char *mdc)
38 {
39         return 0;
40 }
41 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi){}
42 #else
43
44 #define LPROC_LLITE_STAT_FCT(fct_name, get_statfs_fct)                    \
45 int fct_name(char *page, char **start, off_t off,                         \
46              int count, int *eof, void *data)                             \
47 {                                                                         \
48         struct statfs sfs;                                                \
49         int rc;                                                           \
50         LASSERT(data != NULL);                                            \
51         rc = get_statfs_fct((struct super_block*)data, &sfs);             \
52         return (rc==0                                                     \
53                 ? lprocfs_##fct_name (page, start, off, count, eof, &sfs) \
54                 : rc);                                                    \
55 }
56
57 long long mnt_instance;
58
59 LPROC_LLITE_STAT_FCT(rd_blksize,     vfs_statfs);
60 LPROC_LLITE_STAT_FCT(rd_kbytestotal, vfs_statfs);
61 LPROC_LLITE_STAT_FCT(rd_kbytesfree,  vfs_statfs);
62 LPROC_LLITE_STAT_FCT(rd_filestotal,  vfs_statfs);
63 LPROC_LLITE_STAT_FCT(rd_filesfree,   vfs_statfs);
64 LPROC_LLITE_STAT_FCT(rd_filegroups,  vfs_statfs);
65
66 int rd_path(char *page, char **start, off_t off, int count, int *eof,
67             void *data)
68 {
69         return 0;
70 }
71
72 int rd_fstype(char *page, char **start, off_t off, int count, int *eof,
73               void *data)
74 {
75         struct super_block *sb = (struct super_block*)data;
76
77         LASSERT(sb != NULL);
78         *eof = 1;
79         return snprintf(page, count, "%s\n", sb->s_type->name);
80 }
81
82 int rd_sb_uuid(char *page, char **start, off_t off, int count, int *eof,
83                void *data)
84 {
85         struct super_block *sb = (struct super_block *)data;
86
87         LASSERT(sb != NULL);
88         *eof = 1;
89         return snprintf(page, count, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
90 }
91
92 struct lprocfs_vars lprocfs_obd_vars[] = {
93         { "uuid",        rd_sb_uuid,     0, 0 },
94         { "mntpt_path",  rd_path,        0, 0 },
95         { "fstype",      rd_fstype,      0, 0 },
96         { "blocksize",   rd_blksize,     0, 0 },
97         { "kbytestotal", rd_kbytestotal, 0, 0 },
98         { "kbytesfree",  rd_kbytesfree,  0, 0 },
99         { "filestotal",  rd_filestotal,  0, 0 },
100         { "filesfree",   rd_filesfree,   0, 0 },
101         { "filegroups",  rd_filegroups,  0, 0 },
102         { "dirty_pages", ll_rd_dirty_pages, 0, 0},
103         { "max_dirty_pages", ll_rd_max_dirty_pages, ll_wr_max_dirty_pages, 0},
104         { 0 }
105 };
106
107 #define MAX_STRING_SIZE 128
108
109 struct llite_file_opcode {
110         __u32       opcode;
111         __u32       type;
112         const char *opname;
113 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
114         /* file operation */
115         { LPROC_LL_DIRTY_HITS,     LPROCFS_TYPE_REGS, "dirty_pages_hits" },
116         { LPROC_LL_DIRTY_MISSES,   LPROCFS_TYPE_REGS, "dirty_pages_misses" },
117         { LPROC_LL_WB_WRITEPAGE,   LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
118                                    "writeback_from_writepage" },
119         { LPROC_LL_WB_PRESSURE,    LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
120                                    "writeback_from_pressure" },
121         { LPROC_LL_WB_OK,          LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
122                                    "writeback_ok_pages" },
123         { LPROC_LL_WB_FAIL,        LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
124                                    "writeback_failed_pages" },
125         { LPROC_LL_READ_BYTES,     LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
126                                    "read_bytes" },
127         { LPROC_LL_WRITE_BYTES,    LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
128                                    "write_bytes" },
129         { LPROC_LL_BRW_READ,       LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
130                                    "brw_read" },
131         { LPROC_LL_BRW_WRITE,      LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
132                                    "brw_write" },
133
134         { LPROC_LL_IOCTL,          LPROCFS_TYPE_REGS, "ioctl" },
135         { LPROC_LL_OPEN,           LPROCFS_TYPE_REGS, "open" },
136         { LPROC_LL_RELEASE,        LPROCFS_TYPE_REGS, "close" },
137         { LPROC_LL_MAP,            LPROCFS_TYPE_REGS, "mmap" },
138         { LPROC_LL_LLSEEK,         LPROCFS_TYPE_REGS, "seek" },
139         { LPROC_LL_FSYNC,          LPROCFS_TYPE_REGS, "fsync" },
140         /* inode operation */
141         { LPROC_LL_SETATTR_RAW,    LPROCFS_TYPE_REGS, "setattr_raw" },
142         { LPROC_LL_SETATTR,        LPROCFS_TYPE_REGS, "setattr" },
143         { LPROC_LL_TRUNC,          LPROCFS_TYPE_REGS, "punch" },
144 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
145         { LPROC_LL_GETATTR,        LPROCFS_TYPE_REGS, "getattr" },
146 #else
147         { LPROC_LL_REVALIDATE,     LPROCFS_TYPE_REGS, "getattr" },
148 #endif
149         /* special inode operation */
150         { LPROC_LL_STAFS,          LPROCFS_TYPE_REGS, "statfs" },
151         { LPROC_LL_ALLOC_INODE,    LPROCFS_TYPE_REGS, "alloc_inode" },
152         { LPROC_LL_DIRECT_READ,    LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
153                                    "direct_read" },
154         { LPROC_LL_DIRECT_WRITE,   LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
155                                    "direct_write" },
156
157 };
158
159 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
160                                 struct super_block *sb, char *osc, char *mdc)
161 {
162         struct lprocfs_vars lvars[2];
163         struct ll_sb_info *sbi = ll_s2sbi(sb);
164         struct obd_device *obd;
165         char name[MAX_STRING_SIZE + 1];
166         int err, id;
167         struct lprocfs_stats *svc_stats = NULL;
168         ENTRY;
169
170         memset(lvars, 0, sizeof(lvars));
171
172         name[MAX_STRING_SIZE] = '\0';
173         lvars[0].name = name;
174
175         LASSERT(sbi != NULL);
176         LASSERT(mdc != NULL);
177         LASSERT(osc != NULL);
178
179         /* Mount info */
180         snprintf(name, MAX_STRING_SIZE, "fs%llu", mnt_instance);
181
182         mnt_instance++;
183         sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
184         if (IS_ERR(sbi->ll_proc_root)) {
185                 err = PTR_ERR(sbi->ll_proc_root);
186                 sbi->ll_proc_root = NULL;
187                 RETURN(err);
188         }
189
190         svc_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES);
191         if (svc_stats == NULL) {
192                 err = -ENOMEM;
193                 goto out;
194         }
195         /* do counter init */
196         for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
197                 __u32 type = llite_opcode_table[id].type;
198                 void *ptr = NULL;
199                 if (type & LPROCFS_TYPE_REGS)
200                         ptr = "regs";
201                 else {
202                         if (type & LPROCFS_TYPE_BYTES)
203                                 ptr = "bytes";
204                         else {
205                                 if (type & LPROCFS_TYPE_PAGES)
206                                         ptr = "pages";
207                         }
208                 }
209                 lprocfs_counter_init(svc_stats, llite_opcode_table[id].opcode,
210                                      (type & LPROCFS_CNTR_AVGMINMAX),
211                                      llite_opcode_table[id].opname, ptr);
212         }
213         err = lprocfs_register_stats(sbi->ll_proc_root, "stats", svc_stats);
214         if (err)
215                 goto out;
216         else
217                 sbi->ll_stats = svc_stats;
218         /* need place to keep svc_stats */
219
220         /* Static configuration info */
221         err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_obd_vars, sb);
222         if (err)
223                 goto out;
224
225         /* MDC info */
226         obd = class_name2obd(mdc);
227
228         LASSERT(obd != NULL);
229         LASSERT(obd->obd_type != NULL);
230         LASSERT(obd->obd_type->typ_name != NULL);
231
232         snprintf(name, MAX_STRING_SIZE, "%s/common_name",
233                  obd->obd_type->typ_name);
234         lvars[0].read_fptr = lprocfs_rd_name;
235         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
236         if (err)
237                 goto out;
238
239         snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
240         lvars[0].read_fptr = lprocfs_rd_uuid;
241         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
242         if (err)
243                 goto out;
244
245         /* OSC */
246         obd = class_name2obd(osc);
247
248         LASSERT(obd != NULL);
249         LASSERT(obd->obd_type != NULL);
250         LASSERT(obd->obd_type->typ_name != NULL);
251
252         snprintf(name, MAX_STRING_SIZE, "%s/common_name",
253                  obd->obd_type->typ_name);
254         lvars[0].read_fptr = lprocfs_rd_name;
255         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
256         if (err)
257                 goto out;
258
259         snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
260         lvars[0].read_fptr = lprocfs_rd_uuid;
261         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
262 out:
263         if (err) {
264                 if (svc_stats)
265                         lprocfs_free_stats(svc_stats);
266                 if (sbi->ll_proc_root)
267                         lprocfs_remove(sbi->ll_proc_root);
268         }
269         RETURN(err);
270 }
271
272 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
273 {
274         if (sbi->ll_proc_root) {
275                 struct proc_dir_entry *file_stats =
276                         lprocfs_srch(sbi->ll_proc_root, "stats");
277
278                 if (file_stats) {
279                         lprocfs_free_stats(sbi->ll_stats);
280                         lprocfs_remove(file_stats);
281                 }
282         }
283 }
284 #undef MAX_STRING_SIZE
285 #endif /* LPROCFS */