Whamcloud - gitweb
land b1_5 onto HEAD
[fs/lustre-release.git] / lustre / obdfilter / lproc_obdfilter.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2002, 2003 Cluster File Systems, Inc.
5  *
6  *   This file is part of the Lustre file system, http://www.lustre.org
7  *   Lustre is a trademark of Cluster File Systems, Inc.
8  *
9  *   You may have signed or agreed to another license before downloading
10  *   this software.  If so, you are bound by the terms and conditions
11  *   of that agreement, and the following does not apply to you.  See the
12  *   LICENSE file included with this distribution for more information.
13  *
14  *   If you did not agree to a different license, then this copy of Lustre
15  *   is open source software; you can redistribute it and/or modify it
16  *   under the terms of version 2 of the GNU General Public License as
17  *   published by the Free Software Foundation.
18  *
19  *   In either case, Lustre is distributed in the hope that it will be
20  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
21  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  *   license text for more details.
23  *
24  */
25 #define DEBUG_SUBSYSTEM S_CLASS
26
27 #include <linux/version.h>
28 #include <lprocfs_status.h>
29 #include <obd.h>
30 #include <linux/seq_file.h>
31 #include <linux/version.h>
32
33 #include "filter_internal.h"
34
35 #ifdef LPROCFS
36 static int lprocfs_filter_rd_groups(char *page, char **start, off_t off,
37                                     int count, int *eof, void *data)
38 {
39         *eof = 1;
40         return snprintf(page, count, "%u\n", FILTER_GROUPS);
41 }
42
43 static int lprocfs_filter_rd_tot_dirty(char *page, char **start, off_t off,
44                                        int count, int *eof, void *data)
45 {
46         struct obd_device *obd = (struct obd_device *)data;
47
48         LASSERT(obd != NULL);
49         *eof = 1;
50         return snprintf(page, count, LPU64"\n", obd->u.filter.fo_tot_dirty);
51 }
52
53 static int lprocfs_filter_rd_tot_granted(char *page, char **start, off_t off,
54                                          int count, int *eof, void *data)
55 {
56         struct obd_device *obd = (struct obd_device *)data;
57
58         LASSERT(obd != NULL);
59         *eof = 1;
60         return snprintf(page, count, LPU64"\n", obd->u.filter.fo_tot_granted);
61 }
62
63 static int lprocfs_filter_rd_tot_pending(char *page, char **start, off_t off,
64                                          int count, int *eof, void *data)
65 {
66         struct obd_device *obd = (struct obd_device *)data;
67
68         LASSERT(obd != NULL);
69         *eof = 1;
70         return snprintf(page, count, LPU64"\n", obd->u.filter.fo_tot_pending);
71 }
72
73 static int lprocfs_filter_rd_mntdev(char *page, char **start, off_t off,
74                                     int count, int *eof, void *data)
75 {
76         struct obd_device *obd = (struct obd_device *)data;
77
78         LASSERT(obd != NULL);
79         LASSERT(obd->u.filter.fo_vfsmnt->mnt_devname);
80         *eof = 1;
81         return snprintf(page, count, "%s\n",
82                         obd->u.filter.fo_vfsmnt->mnt_devname);
83 }
84
85 static int lprocfs_filter_rd_last_id(char *page, char **start, off_t off,
86                                      int count, int *eof, void *data)
87 {
88         struct obd_device *obd = data;
89
90         if (obd == NULL)
91                 return 0;
92
93         return snprintf(page, count, LPU64"\n",
94                         filter_last_id(&obd->u.filter, 0));
95 }
96
97 int lprocfs_filter_rd_readcache(char *page, char **start, off_t off, int count,
98                                 int *eof, void *data)
99 {
100         struct obd_device *obd = data;
101         int rc;
102
103         rc = snprintf(page, count, LPU64"\n",
104                       obd->u.filter.fo_readcache_max_filesize);
105         return rc;
106 }
107
108 int lprocfs_filter_wr_readcache(struct file *file, const char *buffer,
109                                 unsigned long count, void *data)
110 {
111         struct obd_device *obd = data;
112         __u64 val;
113         int rc;
114
115         rc = lprocfs_write_u64_helper(buffer, count, &val);
116         if (rc)
117                 return rc;
118
119         obd->u.filter.fo_readcache_max_filesize = val;
120         return count;
121 }
122
123 int lprocfs_filter_rd_fmd_max_num(char *page, char **start, off_t off,
124                                   int count, int *eof, void *data)
125 {
126         struct obd_device *obd = data;
127         int rc;
128
129         rc = snprintf(page, count, "%u\n", obd->u.filter.fo_fmd_max_num);
130         return rc;
131 }
132
133 int lprocfs_filter_wr_fmd_max_num(struct file *file, const char *buffer,
134                                   unsigned long count, void *data)
135 {
136         struct obd_device *obd = data;
137         int val;
138         int rc;
139
140         rc = lprocfs_write_helper(buffer, count, &val);
141         if (rc)
142                 return rc;
143
144         if (val > 65536 || val < 1)
145                 return -EINVAL;
146
147         obd->u.filter.fo_fmd_max_num = val;
148         return count;
149 }
150
151 int lprocfs_filter_rd_fmd_max_age(char *page, char **start, off_t off,
152                                   int count, int *eof, void *data)
153 {
154         struct obd_device *obd = data;
155         int rc;
156
157         rc = snprintf(page, count, "%u\n", obd->u.filter.fo_fmd_max_age / HZ);
158         return rc;
159 }
160
161 int lprocfs_filter_wr_fmd_max_age(struct file *file, const char *buffer,
162                                   unsigned long count, void *data)
163 {
164         struct obd_device *obd = data;
165         int val;
166         int rc;
167
168         rc = lprocfs_write_helper(buffer, count, &val);
169         if (rc)
170                 return rc;
171
172         if (val > 65536 || val < 1)
173                 return -EINVAL;
174
175         obd->u.filter.fo_fmd_max_age = val * HZ;
176         return count;
177 }
178
179 static struct lprocfs_vars lprocfs_obd_vars[] = {
180         { "uuid",         lprocfs_rd_uuid,          0, 0 },
181         { "blocksize",    lprocfs_rd_blksize,       0, 0 },
182         { "kbytestotal",  lprocfs_rd_kbytestotal,   0, 0 },
183         { "kbytesfree",   lprocfs_rd_kbytesfree,    0, 0 },
184         { "kbytesavail",  lprocfs_rd_kbytesavail,   0, 0 },
185         { "filestotal",   lprocfs_rd_filestotal,    0, 0 },
186         { "filesfree",    lprocfs_rd_filesfree,     0, 0 },
187         { "filegroups",   lprocfs_filter_rd_groups, 0, 0 },
188         { "fstype",       lprocfs_rd_fstype,        0, 0 },
189         { "mntdev",       lprocfs_filter_rd_mntdev, 0, 0 },
190         { "last_id",      lprocfs_filter_rd_last_id,0, 0 },
191         { "tot_dirty",    lprocfs_filter_rd_tot_dirty,   0, 0 },
192         { "tot_pending",  lprocfs_filter_rd_tot_pending, 0, 0 },
193         { "tot_granted",  lprocfs_filter_rd_tot_granted, 0, 0 },
194         { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
195         { "evict_client", 0, lprocfs_wr_evict_client, 0 },
196         { "num_exports",  lprocfs_rd_num_exports,   0, 0 },
197         { "readcache_max_filesize",
198                           lprocfs_filter_rd_readcache,
199                           lprocfs_filter_wr_readcache, 0 },
200 #ifdef HAVE_QUOTA_SUPPORT
201         { "quota_bunit_sz", lprocfs_rd_bunit, lprocfs_wr_bunit, 0},
202         { "quota_btune_sz", lprocfs_rd_btune, lprocfs_wr_btune, 0},
203         { "quota_iunit_sz", lprocfs_rd_iunit, lprocfs_wr_iunit, 0},
204         { "quota_itune_sz", lprocfs_rd_itune, lprocfs_wr_itune, 0},
205         { "quota_type",     lprocfs_rd_type, lprocfs_wr_type, 0},
206 #endif
207         { "client_cache_count", lprocfs_filter_rd_fmd_max_num,
208                           lprocfs_filter_wr_fmd_max_num, 0 },
209         { "client_cache_seconds", lprocfs_filter_rd_fmd_max_age,
210                           lprocfs_filter_wr_fmd_max_age, 0 },
211         { 0 }
212 };
213
214 static struct lprocfs_vars lprocfs_module_vars[] = {
215         { "num_refs",     lprocfs_rd_numrefs,       0, 0 },
216         { 0 }
217 };
218
219 void filter_tally_write(struct obd_export *exp, struct page **pages,
220                         int nr_pages, unsigned long *blocks,int blocks_per_page)
221 {
222         struct filter_obd *filter = &exp->exp_obd->u.filter;
223         struct filter_export_data *fed = &exp->exp_filter_data;
224         struct page *last_page = NULL;
225         unsigned long *last_block = NULL;
226         unsigned long discont_pages = 0;
227         unsigned long discont_blocks = 0;
228         int i;
229
230         if (nr_pages == 0)
231                 return;
232
233         lprocfs_oh_tally_log2(&filter->fo_filter_stats.hist[BRW_W_PAGES],
234                               nr_pages);
235         lprocfs_oh_tally_log2(&fed->fed_brw_stats.hist[BRW_W_PAGES],
236                               nr_pages);
237
238         while (nr_pages-- > 0) {
239                 if (last_page && (*pages)->index != (last_page->index + 1))
240                         discont_pages++;
241                 last_page = *pages;
242                 pages++;
243                 for (i = 0; i < blocks_per_page; i++) {
244                         if (last_block && *blocks != (*last_block + 1))
245                                 discont_blocks++;
246                         last_block = blocks++;
247                 }
248         }
249
250         lprocfs_oh_tally(&filter->fo_filter_stats.hist[BRW_W_DISCONT_PAGES],
251                          discont_pages);
252         lprocfs_oh_tally(&filter->fo_filter_stats.hist[BRW_W_DISCONT_BLOCKS],
253                          discont_blocks);
254
255         lprocfs_oh_tally(&fed->fed_brw_stats.hist[BRW_W_DISCONT_PAGES],
256                          discont_pages);
257         lprocfs_oh_tally(&fed->fed_brw_stats.hist[BRW_W_DISCONT_BLOCKS],
258                          discont_blocks);
259 }
260
261 void filter_tally_read(struct obd_export *exp, struct page **pages,
262                        int nr_pages, unsigned long *blocks, int blocks_per_page)
263 {
264         struct filter_obd *filter = &exp->exp_obd->u.filter;
265         struct page *last_page = NULL;
266         unsigned long *last_block = NULL;
267         unsigned long discont_pages = 0;
268         unsigned long discont_blocks = 0;
269         int i;
270
271         if (nr_pages == 0)
272                 return;
273
274         lprocfs_oh_tally_log2(&filter->fo_filter_stats.hist[BRW_R_PAGES], nr_pages);
275
276         while (nr_pages-- > 0) {
277                 if (last_page && (*pages)->index != (last_page->index + 1))
278                         discont_pages++;
279                 last_page = *pages;
280                 pages++;
281                 for (i = 0; i < blocks_per_page; i++) {
282                         if (last_block && *blocks != (*last_block + 1))
283                                 discont_blocks++;
284                         last_block = blocks++;
285                 }
286         }
287
288         lprocfs_oh_tally_log2(&filter->fo_filter_stats.hist[BRW_R_PAGES], nr_pages);
289         lprocfs_oh_tally(&filter->fo_filter_stats.hist[BRW_R_DISCONT_PAGES], discont_pages);
290         lprocfs_oh_tally(&filter->fo_filter_stats.hist[BRW_R_DISCONT_BLOCKS], discont_blocks);
291
292         lprocfs_oh_tally_log2(&exp->exp_filter_data.fed_brw_stats.hist[BRW_R_PAGES],
293                               nr_pages);
294         lprocfs_oh_tally(&exp->exp_filter_data.fed_brw_stats.hist[BRW_R_DISCONT_PAGES],
295                          discont_pages);
296         lprocfs_oh_tally(&exp->exp_filter_data.fed_brw_stats.hist[BRW_R_DISCONT_BLOCKS],
297                          discont_blocks);
298 }
299
300 #define pct(a,b) (b ? a * 100 / b : 0)
301
302 static void display_brw_stats(struct seq_file *seq, struct obd_histogram *read,
303                               struct obd_histogram *write)
304 {
305         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
306         int i;
307
308         read_tot = lprocfs_oh_sum(read);
309         write_tot = lprocfs_oh_sum(write);
310
311         read_cum = 0;
312         write_cum = 0;
313         for (i = 0; i < OBD_HIST_MAX; i++) {
314                 unsigned long r = read->oh_buckets[i];
315                 unsigned long w = write->oh_buckets[i];
316                 read_cum += r;
317                 write_cum += w;
318                 seq_printf(seq, "%u:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
319                                  1 << i, r, pct(r, read_tot),
320                                  pct(read_cum, read_tot), w,
321                                  pct(w, write_tot),
322                                  pct(write_cum, write_tot));
323                 if (read_cum == read_tot && write_cum == write_tot)
324                         break;
325         }
326 }
327
328 static void brw_stats_show(struct seq_file *seq, struct brw_stats *brw_stats)
329 {
330         struct timeval now;
331 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
332         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
333         int i;
334 #endif
335
336         do_gettimeofday(&now);
337
338         /* this sampling races with updates */
339
340         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
341                    now.tv_sec, now.tv_usec);
342
343         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
344         seq_printf(seq, "pages per brw         brws   %% cum %% |");
345         seq_printf(seq, "       rpcs   %% cum %%\n");
346
347         display_brw_stats(seq, &brw_stats->hist[BRW_R_PAGES], &brw_stats->hist[BRW_W_PAGES]);
348
349         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
350         seq_printf(seq, "discont pages         rpcs   %% cum %% |");
351         seq_printf(seq, "       rpcs   %% cum %%\n");
352
353         display_brw_stats(seq, &brw_stats->hist[BRW_R_DISCONT_PAGES],
354                           &brw_stats->hist[BRW_W_DISCONT_PAGES]);
355
356         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
357         seq_printf(seq, "discont blocks        rpcs   %% cum %% |");
358         seq_printf(seq, "       rpcs   %% cum %%\n");
359
360         display_brw_stats(seq, &brw_stats->hist[BRW_R_DISCONT_BLOCKS],
361                           &brw_stats->hist[BRW_W_DISCONT_BLOCKS]);
362
363         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
364         seq_printf(seq, "dio frags             rpcs   %% cum %% |");
365         seq_printf(seq, "       rpcs   %% cum %%\n");
366
367         display_brw_stats(seq, &brw_stats->hist[BRW_R_DIO_FRAGS],
368                           &brw_stats->hist[BRW_W_DIO_FRAGS]);
369
370 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
371         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
372         seq_printf(seq, "disk ios in flight     ios   %% cum %% |");
373         seq_printf(seq, "       rpcs   %% cum %%\n");
374
375         display_brw_stats(seq, &brw_stats->hist[BRW_R_RPC_HIST],
376                           &brw_stats->hist[BRW_W_RPC_HIST]);
377
378         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
379         seq_printf(seq, "io time (1/%ds)     rpcs   %% cum %% |", HZ);
380         seq_printf(seq, "       rpcs   %% cum %%\n");
381
382         display_brw_stats(seq, &brw_stats->hist[BRW_R_IO_TIME],
383                           &brw_stats->hist[BRW_W_IO_TIME]);
384
385         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
386         seq_printf(seq, "disk I/O size         count  %% cum %% |");
387         seq_printf(seq, "       count  %% cum %%\n");
388
389         read_tot = lprocfs_oh_sum(&brw_stats->hist[BRW_R_DISK_IOSIZE]);
390         write_tot = lprocfs_oh_sum(&brw_stats->hist[BRW_W_DISK_IOSIZE]);
391
392         read_cum = 0;
393         write_cum = 0;
394         for (i = 0; i < OBD_HIST_MAX; i++) {
395                 unsigned long r = brw_stats->hist[BRW_R_DISK_IOSIZE].oh_buckets[i];
396                 unsigned long w = brw_stats->hist[BRW_W_DISK_IOSIZE].oh_buckets[i];
397
398                 read_cum += r;
399                 write_cum += w;
400                 if (read_cum == 0 && write_cum == 0)
401                         continue;
402
403                 if (i < 10)
404                         seq_printf(seq, "%u", 1<<i);
405                 else if (i < 20)
406                         seq_printf(seq, "%uK", 1<<(i-10));
407                 else
408                         seq_printf(seq, "%uM", 1<<(i-20));
409
410                 seq_printf(seq, ":\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
411                            r, pct(r, read_tot), pct(read_cum, read_tot),
412                            w, pct(w, write_tot), pct(write_cum, write_tot));
413                 if (read_cum == read_tot && write_cum == write_tot)
414                         break;
415         }
416 #endif
417 }
418
419 static int filter_brw_stats_seq_show(struct seq_file *seq, void *v)
420 {
421         struct obd_device *dev = seq->private;
422         struct filter_obd *filter = &dev->u.filter;
423
424         brw_stats_show(seq, &filter->fo_filter_stats);
425
426         return 0;
427 }
428
429 static ssize_t filter_brw_stats_seq_write(struct file *file, const char *buf,
430                                        size_t len, loff_t *off)
431 {
432         struct seq_file *seq = file->private_data;
433         struct obd_device *dev = seq->private;
434         struct filter_obd *filter = &dev->u.filter;
435         int i;
436
437         for (i = 0; i < BRW_LAST; i++)
438                 lprocfs_oh_clear(&filter->fo_filter_stats.hist[i]);
439
440         return len;
441 }
442
443 LPROC_SEQ_FOPS(filter_brw_stats);
444
445 int lproc_filter_attach_seqstat(struct obd_device *dev)
446 {
447         return lprocfs_obd_seq_create(dev, "brw_stats", 0444,
448                                       &filter_brw_stats_fops, dev);
449 }
450
451 static int filter_per_export_stats_seq_show(struct seq_file *seq, void *v)
452 {
453         struct filter_export_data *fed = seq->private;
454
455         brw_stats_show(seq, &fed->fed_brw_stats);
456
457         return 0;
458 }
459
460 static ssize_t filter_per_export_stats_seq_write(struct file *file,
461                                        const char *buf, size_t len, loff_t *off)
462 {
463         struct seq_file *seq = file->private_data;
464         struct filter_export_data *fed = seq->private;
465         int i;
466
467         for (i = 0; i < BRW_LAST; i++)
468                 lprocfs_oh_clear(&fed->fed_brw_stats.hist[i]);
469
470         return len;
471 }
472
473 LPROC_SEQ_FOPS(filter_per_export_stats);
474
475 LPROCFS_INIT_VARS(filter, lprocfs_module_vars, lprocfs_obd_vars)
476 #endif /* LPROCFS */