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