Whamcloud - gitweb
A couple of trivial spelling fixes.
[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  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36 #define DEBUG_SUBSYSTEM S_CLASS
37
38 #include <linux/version.h>
39 #include <lprocfs_status.h>
40 #include <obd.h>
41 #include <linux/seq_file.h>
42 #include <linux/version.h>
43
44 #include "filter_internal.h"
45
46 #ifdef LPROCFS
47 static int lprocfs_filter_rd_groups(char *page, char **start, off_t off,
48                                     int count, int *eof, void *data)
49 {
50         struct obd_device *obd = (struct obd_device *)data;
51         *eof = 1;
52         return snprintf(page, count, "%u\n", obd->u.filter.fo_group_count);
53 }
54
55 static int lprocfs_filter_rd_tot_dirty(char *page, char **start, off_t off,
56                                        int count, int *eof, void *data)
57 {
58         struct obd_device *obd = (struct obd_device *)data;
59
60         LASSERT(obd != NULL);
61         *eof = 1;
62         return snprintf(page, count, LPU64"\n", obd->u.filter.fo_tot_dirty);
63 }
64
65 static int lprocfs_filter_rd_tot_granted(char *page, char **start, off_t off,
66                                          int count, int *eof, void *data)
67 {
68         struct obd_device *obd = (struct obd_device *)data;
69
70         LASSERT(obd != NULL);
71         *eof = 1;
72         return snprintf(page, count, LPU64"\n", obd->u.filter.fo_tot_granted);
73 }
74
75 static int lprocfs_filter_rd_tot_pending(char *page, char **start, off_t off,
76                                          int count, int *eof, void *data)
77 {
78         struct obd_device *obd = (struct obd_device *)data;
79
80         LASSERT(obd != NULL);
81         *eof = 1;
82         return snprintf(page, count, LPU64"\n", obd->u.filter.fo_tot_pending);
83 }
84
85 static int lprocfs_filter_rd_mntdev(char *page, char **start, off_t off,
86                                     int count, int *eof, void *data)
87 {
88         struct obd_device *obd = (struct obd_device *)data;
89
90         LASSERT(obd != NULL);
91         LASSERT(obd->u.filter.fo_vfsmnt->mnt_devname);
92         *eof = 1;
93         return snprintf(page, count, "%s\n",
94                         obd->u.filter.fo_vfsmnt->mnt_devname);
95 }
96
97 static int lprocfs_filter_rd_last_id(char *page, char **start, off_t off,
98                                      int count, int *eof, void *data)
99 {
100         struct obd_device *obd = data;
101         struct filter_obd *filter = &obd->u.filter;
102         int retval = 0, rc, i;
103
104         if (obd == NULL)
105                 return 0;
106
107         for (i = FILTER_GROUP_MDS0; i < filter->fo_group_count; i++) {
108                 rc = snprintf(page, count, LPU64"\n",filter_last_id(filter, i));
109                 if (rc < 0) {
110                         retval = rc;
111                         break;
112                 }
113                 page += rc;
114                 count -= rc;
115                 retval += rc;
116         }
117         return retval;
118 }
119
120 int lprocfs_filter_rd_readcache(char *page, char **start, off_t off, int count,
121                                 int *eof, void *data)
122 {
123         struct obd_device *obd = data;
124         int rc;
125
126         rc = snprintf(page, count, LPU64"\n",
127                       obd->u.filter.fo_readcache_max_filesize);
128         return rc;
129 }
130
131 int lprocfs_filter_wr_readcache(struct file *file, const char *buffer,
132                                 unsigned long count, void *data)
133 {
134         struct obd_device *obd = data;
135         __u64 val;
136         int rc;
137
138         rc = lprocfs_write_u64_helper(buffer, count, &val);
139         if (rc)
140                 return rc;
141
142         obd->u.filter.fo_readcache_max_filesize = val;
143         return count;
144 }
145
146
147 int lprocfs_filter_rd_fmd_max_num(char *page, char **start, off_t off,
148                                   int count, int *eof, void *data)
149 {
150         struct obd_device *obd = data;
151         int rc;
152
153         rc = snprintf(page, count, "%u\n", obd->u.filter.fo_fmd_max_num);
154         return rc;
155 }
156
157 int lprocfs_filter_wr_fmd_max_num(struct file *file, const char *buffer,
158                                   unsigned long count, void *data)
159 {
160         struct obd_device *obd = data;
161         int val;
162         int rc;
163
164         rc = lprocfs_write_helper(buffer, count, &val);
165         if (rc)
166                 return rc;
167
168         if (val > 65536 || val < 1)
169                 return -EINVAL;
170
171         obd->u.filter.fo_fmd_max_num = val;
172         return count;
173 }
174
175 int lprocfs_filter_rd_fmd_max_age(char *page, char **start, off_t off,
176                                   int count, int *eof, void *data)
177 {
178         struct obd_device *obd = data;
179         int rc;
180
181         rc = snprintf(page, count, "%u\n", obd->u.filter.fo_fmd_max_age / HZ);
182         return rc;
183 }
184
185 int lprocfs_filter_wr_fmd_max_age(struct file *file, const char *buffer,
186                                   unsigned long count, void *data)
187 {
188         struct obd_device *obd = data;
189         int val;
190         int rc;
191
192         rc = lprocfs_write_helper(buffer, count, &val);
193         if (rc)
194                 return rc;
195
196         if (val > 65536 || val < 1)
197                 return -EINVAL;
198
199         obd->u.filter.fo_fmd_max_age = val * HZ;
200         return count;
201 }
202
203 static int lprocfs_filter_rd_capa(char *page, char **start, off_t off,
204                                   int count, int *eof, void *data)
205 {
206         struct obd_device *obd = data;
207         int rc;
208
209         rc = snprintf(page, count, "capability on: %s\n",
210                       obd->u.filter.fo_fl_oss_capa ? "oss" : "");
211         return rc;
212 }
213
214 static int lprocfs_filter_wr_capa(struct file *file, const char *buffer,
215                                   unsigned long count, void *data)
216 {
217         struct obd_device *obd = data;
218         int val, rc;
219
220         rc = lprocfs_write_helper(buffer, count, &val);
221         if (rc)
222                 return rc;
223
224         if (val & ~0x1) {
225                 CERROR("invalid capability mode, only 0/1 are accepted.\n"
226                        " 1: enable oss fid capability\n"
227                        " 0: disable oss fid capability\n");
228                 return -EINVAL;
229         }
230
231         obd->u.filter.fo_fl_oss_capa = val;
232         LCONSOLE_INFO("OSS %s %s fid capability.\n", obd->obd_name,
233                       val ? "enabled" : "disabled");
234         return count;
235 }
236
237 static int lprocfs_filter_rd_capa_count(char *page, char **start, off_t off,
238                                         int count, int *eof, void *data)
239 {
240         return snprintf(page, count, "%d %d\n",
241                         capa_count[CAPA_SITE_CLIENT],
242                         capa_count[CAPA_SITE_SERVER]);
243 }
244
245 static int lprocfs_filter_rd_cache(char *page, char **start, off_t off,
246                                    int count, int *eof, void *data)
247 {
248         struct obd_device *obd = (struct obd_device *)data;
249         LASSERT(obd != NULL);
250
251         return snprintf(page, count, "%u\n", obd->u.filter.fo_read_cache);
252 }
253
254 static int lprocfs_filter_wr_cache(struct file *file, const char *buffer,
255                      unsigned long count, void *data)
256 {
257         struct obd_device *obd = (struct obd_device *)data;
258         int val, rc;
259         LASSERT(obd != NULL);
260
261         rc = lprocfs_write_helper(buffer, count, &val);
262
263         if (rc)
264                 return rc;
265
266         obd->u.filter.fo_read_cache = val;
267         return count;
268 }
269
270 static int lprocfs_filter_rd_wcache(char *page, char **start, off_t off,
271                                    int count, int *eof, void *data)
272 {
273         struct obd_device *obd = (struct obd_device *)data;
274         LASSERT(obd != NULL);
275
276         return snprintf(page, count, "%u\n", obd->u.filter.fo_writethrough_cache);
277 }
278
279 static int lprocfs_filter_wr_wcache(struct file *file, const char *buffer,
280                      unsigned long count, void *data)
281 {
282         struct obd_device *obd = (struct obd_device *)data;
283         int val, rc;
284         LASSERT(obd != NULL);
285
286         rc = lprocfs_write_helper(buffer, count, &val);
287
288         if (rc)
289                 return rc;
290
291         obd->u.filter.fo_writethrough_cache = val;
292         return count;
293 }
294
295 static struct lprocfs_vars lprocfs_filter_obd_vars[] = {
296         { "uuid",         lprocfs_rd_uuid,          0, 0 },
297         { "blocksize",    lprocfs_rd_blksize,       0, 0 },
298         { "kbytestotal",  lprocfs_rd_kbytestotal,   0, 0 },
299         { "kbytesfree",   lprocfs_rd_kbytesfree,    0, 0 },
300         { "kbytesavail",  lprocfs_rd_kbytesavail,   0, 0 },
301         { "filestotal",   lprocfs_rd_filestotal,    0, 0 },
302         { "filesfree",    lprocfs_rd_filesfree,     0, 0 },
303         { "filegroups",   lprocfs_filter_rd_groups, 0, 0 },
304         { "fstype",       lprocfs_rd_fstype,        0, 0 },
305         { "mntdev",       lprocfs_filter_rd_mntdev, 0, 0 },
306         { "last_id",      lprocfs_filter_rd_last_id,0, 0 },
307         { "tot_dirty",    lprocfs_filter_rd_tot_dirty,   0, 0 },
308         { "tot_pending",  lprocfs_filter_rd_tot_pending, 0, 0 },
309         { "tot_granted",  lprocfs_filter_rd_tot_granted, 0, 0 },
310         { "hash_stats",   lprocfs_obd_rd_hash,      0, 0 },
311         { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
312         { "recovery_maxtime", lprocfs_obd_rd_recovery_maxtime,
313                               lprocfs_obd_wr_recovery_maxtime, 0},
314         { "evict_client", 0, lprocfs_wr_evict_client, 0,
315                                 &lprocfs_evict_client_fops},
316         { "num_exports",  lprocfs_rd_num_exports,   0, 0 },
317         { "readcache_max_filesize",
318                           lprocfs_filter_rd_readcache,
319                           lprocfs_filter_wr_readcache, 0 },
320 #ifdef HAVE_QUOTA_SUPPORT
321         { "quota_bunit_sz", lprocfs_rd_bunit, lprocfs_wr_bunit, 0},
322         { "quota_btune_sz", lprocfs_rd_btune, lprocfs_wr_btune, 0},
323         { "quota_iunit_sz", lprocfs_rd_iunit, lprocfs_wr_iunit, 0},
324         { "quota_itune_sz", lprocfs_rd_itune, lprocfs_wr_itune, 0},
325         { "quota_type",     lprocfs_rd_type, lprocfs_wr_type, 0},
326 #endif
327         { "client_cache_count", lprocfs_filter_rd_fmd_max_num,
328                           lprocfs_filter_wr_fmd_max_num, 0 },
329         { "client_cache_seconds", lprocfs_filter_rd_fmd_max_age,
330                           lprocfs_filter_wr_fmd_max_age, 0 },
331         { "capa",         lprocfs_filter_rd_capa,
332                           lprocfs_filter_wr_capa, 0 },
333         { "capa_count",   lprocfs_filter_rd_capa_count, 0, 0 },
334         { "read_cache_enable", lprocfs_filter_rd_cache, lprocfs_filter_wr_cache, 0},
335         { "writethrough_cache_enable", lprocfs_filter_rd_wcache,
336                           lprocfs_filter_wr_wcache, 0},
337         { 0 }
338 };
339
340 static struct lprocfs_vars lprocfs_filter_module_vars[] = {
341         { "num_refs",     lprocfs_rd_numrefs,       0, 0 },
342         { 0 }
343 };
344
345 void filter_tally(struct obd_export *exp, struct page **pages, int nr_pages,
346                   unsigned long *blocks, int blocks_per_page, int wr)
347 {
348         struct filter_obd *filter = &exp->exp_obd->u.filter;
349         struct filter_export_data *fed = &exp->exp_filter_data;
350         struct page *last_page = NULL;
351         unsigned long *last_block = NULL;
352         unsigned long discont_pages = 0;
353         unsigned long discont_blocks = 0;
354         int i;
355
356         if (nr_pages == 0)
357                 return;
358
359         lprocfs_oh_tally_log2(&filter->fo_filter_stats.hist[BRW_R_PAGES + wr],
360                               nr_pages);
361         lprocfs_oh_tally_log2(&fed->fed_brw_stats.hist[BRW_R_PAGES + wr],
362                               nr_pages);
363         if (exp->exp_nid_stats && exp->exp_nid_stats->nid_brw_stats)
364                 lprocfs_oh_tally_log2(&exp->exp_nid_stats->nid_brw_stats->
365                                         hist[BRW_R_PAGES + wr], nr_pages);
366
367         while (nr_pages-- > 0) {
368                 if (last_page && (*pages)->index != (last_page->index + 1))
369                         discont_pages++;
370                 last_page = *pages;
371                 pages++;
372                 for (i = 0; i < blocks_per_page; i++) {
373                         if (last_block && *blocks != (*last_block + 1))
374                                 discont_blocks++;
375                         last_block = blocks++;
376                 }
377         }
378
379         lprocfs_oh_tally(&filter->fo_filter_stats.hist[BRW_R_DISCONT_PAGES +wr],
380                          discont_pages);
381         lprocfs_oh_tally(&fed->fed_brw_stats.hist[BRW_R_DISCONT_PAGES + wr],
382                          discont_pages);
383         lprocfs_oh_tally(&filter->fo_filter_stats.hist[BRW_R_DISCONT_BLOCKS+wr],
384                          discont_blocks);
385         lprocfs_oh_tally(&fed->fed_brw_stats.hist[BRW_R_DISCONT_BLOCKS + wr],
386                          discont_blocks);
387
388         if (exp->exp_nid_stats && exp->exp_nid_stats->nid_brw_stats) {
389                 lprocfs_oh_tally_log2(&exp->exp_nid_stats->nid_brw_stats->
390                                         hist[BRW_R_DISCONT_PAGES + wr],
391                                       discont_pages);
392                 lprocfs_oh_tally_log2(&exp->exp_nid_stats->nid_brw_stats->
393                                         hist[BRW_R_DISCONT_BLOCKS + wr],
394                                       discont_blocks);
395         }
396 }
397
398 #define pct(a,b) (b ? a * 100 / b : 0)
399
400 static void display_brw_stats(struct seq_file *seq, char *name, char *units,
401         struct obd_histogram *read, struct obd_histogram *write, int log2)
402 {
403         unsigned long read_tot, write_tot, r, w, read_cum = 0, write_cum = 0;
404         int i;
405
406         seq_printf(seq, "\n%26s read      |     write\n", " ");
407         seq_printf(seq, "%-22s %-5s %% cum %% |  %-5s %% cum %%\n",
408                    name, units, units);
409
410         read_tot = lprocfs_oh_sum(read);
411         write_tot = lprocfs_oh_sum(write);
412         for (i = 0; i < OBD_HIST_MAX; i++) {
413                 r = read->oh_buckets[i];
414                 w = write->oh_buckets[i];
415                 read_cum += r;
416                 write_cum += w;
417                 if (read_cum == 0 && write_cum == 0)
418                         continue;
419
420                 if (!log2)
421                         seq_printf(seq, "%u", i);
422                 else if (i < 10)
423                         seq_printf(seq, "%u", 1<<i);
424                 else if (i < 20)
425                         seq_printf(seq, "%uK", 1<<(i-10));
426                 else
427                         seq_printf(seq, "%uM", 1<<(i-20));
428
429                 seq_printf(seq, ":\t\t%10lu %3lu %3lu   | %4lu %3lu %3lu\n",
430                            r, pct(r, read_tot), pct(read_cum, read_tot),
431                            w, pct(w, write_tot), pct(write_cum, write_tot));
432
433                 if (read_cum == read_tot && write_cum == write_tot)
434                         break;
435         }
436 }
437
438 static void brw_stats_show(struct seq_file *seq, struct brw_stats *brw_stats)
439 {
440         struct timeval now;
441
442         /* this sampling races with updates */
443         do_gettimeofday(&now);
444         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
445                    now.tv_sec, now.tv_usec);
446
447         display_brw_stats(seq, "pages per bulk r/w", "rpcs",
448                           &brw_stats->hist[BRW_R_PAGES],
449                           &brw_stats->hist[BRW_W_PAGES], 1);
450
451         display_brw_stats(seq, "discontiguous pages", "rpcs",
452                           &brw_stats->hist[BRW_R_DISCONT_PAGES],
453                           &brw_stats->hist[BRW_W_DISCONT_PAGES], 0);
454
455         display_brw_stats(seq, "discontiguous blocks", "rpcs",
456                           &brw_stats->hist[BRW_R_DISCONT_BLOCKS],
457                           &brw_stats->hist[BRW_W_DISCONT_BLOCKS], 0);
458
459         display_brw_stats(seq, "disk fragmented I/Os", "ios",
460                           &brw_stats->hist[BRW_R_DIO_FRAGS],
461                           &brw_stats->hist[BRW_W_DIO_FRAGS], 0);
462
463         display_brw_stats(seq, "disk I/Os in flight", "ios",
464                           &brw_stats->hist[BRW_R_RPC_HIST],
465                           &brw_stats->hist[BRW_W_RPC_HIST], 0);
466
467         {
468                 char title[24];
469                 sprintf(title, "I/O time (1/%ds)", HZ);
470                 display_brw_stats(seq, title, "ios",
471                                   &brw_stats->hist[BRW_R_IO_TIME],
472                                   &brw_stats->hist[BRW_W_IO_TIME], 1);
473         }
474
475         display_brw_stats(seq, "disk I/O size", "ios",
476                           &brw_stats->hist[BRW_R_DISK_IOSIZE],
477                           &brw_stats->hist[BRW_W_DISK_IOSIZE], 1);
478 }
479
480 #undef pct
481
482 static int filter_brw_stats_seq_show(struct seq_file *seq, void *v)
483 {
484         struct obd_device *dev = seq->private;
485         struct filter_obd *filter = &dev->u.filter;
486
487         brw_stats_show(seq, &filter->fo_filter_stats);
488
489         return 0;
490 }
491
492 static ssize_t filter_brw_stats_seq_write(struct file *file, const char *buf,
493                                        size_t len, loff_t *off)
494 {
495         struct seq_file *seq = file->private_data;
496         struct obd_device *dev = seq->private;
497         struct filter_obd *filter = &dev->u.filter;
498         int i;
499
500         for (i = 0; i < BRW_LAST; i++)
501                 lprocfs_oh_clear(&filter->fo_filter_stats.hist[i]);
502
503         return len;
504 }
505
506 LPROC_SEQ_FOPS(filter_brw_stats);
507
508 int lproc_filter_attach_seqstat(struct obd_device *dev)
509 {
510         return lprocfs_obd_seq_create(dev, "brw_stats", 0444,
511                                       &filter_brw_stats_fops, dev);
512 }
513
514 static int filter_per_export_stats_seq_show(struct seq_file *seq, void *v)
515 {
516         struct filter_export_data *fed = seq->private;
517
518         brw_stats_show(seq, &fed->fed_brw_stats);
519
520         return 0;
521 }
522
523 static ssize_t filter_per_export_stats_seq_write(struct file *file,
524                                        const char *buf, size_t len, loff_t *off)
525 {
526         struct seq_file *seq = file->private_data;
527         struct filter_export_data *fed = seq->private;
528         int i;
529
530         for (i = 0; i < BRW_LAST; i++)
531                 lprocfs_oh_clear(&fed->fed_brw_stats.hist[i]);
532
533         return len;
534 }
535
536 LPROC_SEQ_FOPS(filter_per_export_stats);
537
538 void lprocfs_filter_init_vars(struct lprocfs_static_vars *lvars)
539 {
540     lvars->module_vars  = lprocfs_filter_module_vars;
541     lvars->obd_vars     = lprocfs_filter_obd_vars;
542 }
543
544 static int filter_per_nid_stats_seq_show(struct seq_file *seq, void *v)
545 {
546         nid_stat_t *tmp = seq->private;
547
548         if (tmp->nid_brw_stats)
549                 brw_stats_show(seq, tmp->nid_brw_stats);
550
551         return 0;
552 }
553
554 static ssize_t filter_per_nid_stats_seq_write(struct file *file,
555                                               const char *buf, size_t len,
556                                               loff_t *off)
557 {
558         struct seq_file *seq = file->private_data;
559         nid_stat_t *tmp = seq->private;
560         int i;
561
562         if (tmp->nid_brw_stats)
563                 for (i = 0; i < BRW_LAST; i++)
564                         lprocfs_oh_clear(&tmp->nid_brw_stats->hist[i]);
565
566         return len;
567 }
568
569 LPROC_SEQ_FOPS(filter_per_nid_stats);
570 #endif /* LPROCFS */