Whamcloud - gitweb
Land b_head_interop_disk on HEAD (20081119_1314)
[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         rc = snprintf(page, count, LPU64"\n",filter_last_id(filter, 0));
107         if (rc < 0)
108                 return rc;
109         page += rc;
110         count -= rc;
111         retval += rc;
112
113         for (i = FILTER_GROUP_MDS1_N_BASE + 1; i < filter->fo_group_count; i++) {
114                 rc = snprintf(page, count, LPU64"\n",filter_last_id(filter, i));
115                 if (rc < 0) {
116                         retval = rc;
117                         break;
118                 }
119                 page += rc;
120                 count -= rc;
121                 retval += rc;
122         }
123         return retval;
124 }
125
126 int lprocfs_filter_rd_readcache(char *page, char **start, off_t off, int count,
127                                 int *eof, void *data)
128 {
129         struct obd_device *obd = data;
130         int rc;
131
132         rc = snprintf(page, count, LPU64"\n",
133                       obd->u.filter.fo_readcache_max_filesize);
134         return rc;
135 }
136
137 int lprocfs_filter_wr_readcache(struct file *file, const char *buffer,
138                                 unsigned long count, void *data)
139 {
140         struct obd_device *obd = data;
141         __u64 val;
142         int rc;
143
144         rc = lprocfs_write_u64_helper(buffer, count, &val);
145         if (rc)
146                 return rc;
147
148         obd->u.filter.fo_readcache_max_filesize = val;
149         return count;
150 }
151
152 int lprocfs_filter_rd_fmd_max_num(char *page, char **start, off_t off,
153                                   int count, int *eof, void *data)
154 {
155         struct obd_device *obd = data;
156         int rc;
157
158         rc = snprintf(page, count, "%u\n", obd->u.filter.fo_fmd_max_num);
159         return rc;
160 }
161
162 int lprocfs_filter_wr_fmd_max_num(struct file *file, const char *buffer,
163                                   unsigned long count, void *data)
164 {
165         struct obd_device *obd = data;
166         int val;
167         int rc;
168
169         rc = lprocfs_write_helper(buffer, count, &val);
170         if (rc)
171                 return rc;
172
173         if (val > 65536 || val < 1)
174                 return -EINVAL;
175
176         obd->u.filter.fo_fmd_max_num = val;
177         return count;
178 }
179
180 int lprocfs_filter_rd_fmd_max_age(char *page, char **start, off_t off,
181                                   int count, int *eof, void *data)
182 {
183         struct obd_device *obd = data;
184         int rc;
185
186         rc = snprintf(page, count, "%u\n", obd->u.filter.fo_fmd_max_age / HZ);
187         return rc;
188 }
189
190 int lprocfs_filter_wr_fmd_max_age(struct file *file, const char *buffer,
191                                   unsigned long count, void *data)
192 {
193         struct obd_device *obd = data;
194         int val;
195         int rc;
196
197         rc = lprocfs_write_helper(buffer, count, &val);
198         if (rc)
199                 return rc;
200
201         if (val > 65536 || val < 1)
202                 return -EINVAL;
203
204         obd->u.filter.fo_fmd_max_age = val * HZ;
205         return count;
206 }
207
208 static int lprocfs_filter_rd_capa(char *page, char **start, off_t off,
209                                   int count, int *eof, void *data)
210 {
211         struct obd_device *obd = data;
212         int rc;
213
214         rc = snprintf(page, count, "capability on: %s\n",
215                       obd->u.filter.fo_fl_oss_capa ? "oss" : "");
216         return rc;
217 }
218
219 static int lprocfs_filter_wr_capa(struct file *file, const char *buffer,
220                                   unsigned long count, void *data)
221 {
222         struct obd_device *obd = data;
223         int val, rc;
224
225         rc = lprocfs_write_helper(buffer, count, &val);
226         if (rc)
227                 return rc;
228
229         if (val & ~0x1) {
230                 CERROR("invalid capability mode, only 0/1 are accepted.\n"
231                        " 1: enable oss fid capability\n"
232                        " 0: disable oss fid capability\n");
233                 return -EINVAL;
234         }
235
236         obd->u.filter.fo_fl_oss_capa = val;
237         LCONSOLE_INFO("OSS %s %s fid capability.\n", obd->obd_name,
238                       val ? "enabled" : "disabled");
239         return count;
240 }
241
242 static int lprocfs_filter_rd_capa_count(char *page, char **start, off_t off,
243                                         int count, int *eof, void *data)
244 {
245         return snprintf(page, count, "%d %d\n",
246                         capa_count[CAPA_SITE_CLIENT],
247                         capa_count[CAPA_SITE_SERVER]);
248 }
249
250 static int lprocfs_rd_sec_level(char *page, char **start, off_t off,
251                                 int count, int *eof, void *data)
252 {
253         struct obd_device *obd = data;
254
255         return snprintf(page, count, "%d\n", obd->u.filter.fo_sec_level);
256 }
257
258 static int lprocfs_wr_sec_level(struct file *file, const char *buffer,
259                                 unsigned long count, void *data)
260 {
261         struct obd_device *obd = data;
262         int val, rc;
263
264         rc = lprocfs_write_helper(buffer, count, &val);
265         if (rc)
266                 return rc;
267
268         if (val > LUSTRE_SEC_ALL || val < LUSTRE_SEC_NONE)
269                 return -EINVAL;
270
271         if (val == LUSTRE_SEC_SPECIFY) {
272                 CWARN("security level %d will be supported in future.\n",
273                       LUSTRE_SEC_SPECIFY);
274                 return -EINVAL;
275         }
276
277         obd->u.filter.fo_sec_level = val;
278         return count;
279 }
280
281 static int lprocfs_filter_rd_cache(char *page, char **start, off_t off,
282                                    int count, int *eof, void *data)
283 {
284         struct obd_device *obd = (struct obd_device *)data;
285         LASSERT(obd != NULL);
286
287         return snprintf(page, count, "%u\n", obd->u.filter.fo_read_cache);
288 }
289
290 static int lprocfs_filter_wr_cache(struct file *file, const char *buffer,
291                      unsigned long count, void *data)
292 {
293         struct obd_device *obd = (struct obd_device *)data;
294         int val, rc;
295         LASSERT(obd != NULL);
296
297         rc = lprocfs_write_helper(buffer, count, &val);
298
299         if (rc)
300                 return rc;
301
302         obd->u.filter.fo_read_cache = val;
303         return count;
304 }
305
306 static int lprocfs_filter_rd_wcache(char *page, char **start, off_t off,
307                                    int count, int *eof, void *data)
308 {
309         struct obd_device *obd = (struct obd_device *)data;
310         LASSERT(obd != NULL);
311
312         return snprintf(page, count, "%u\n", obd->u.filter.fo_writethrough_cache);
313 }
314
315 static int lprocfs_filter_wr_wcache(struct file *file, const char *buffer,
316                      unsigned long count, void *data)
317 {
318         struct obd_device *obd = (struct obd_device *)data;
319         int val, rc;
320         LASSERT(obd != NULL);
321
322         rc = lprocfs_write_helper(buffer, count, &val);
323
324         if (rc)
325                 return rc;
326
327         obd->u.filter.fo_writethrough_cache = val;
328         return count;
329 }
330
331 static struct lprocfs_vars lprocfs_filter_obd_vars[] = {
332         { "uuid",         lprocfs_rd_uuid,          0, 0 },
333         { "blocksize",    lprocfs_rd_blksize,       0, 0 },
334         { "kbytestotal",  lprocfs_rd_kbytestotal,   0, 0 },
335         { "kbytesfree",   lprocfs_rd_kbytesfree,    0, 0 },
336         { "kbytesavail",  lprocfs_rd_kbytesavail,   0, 0 },
337         { "filestotal",   lprocfs_rd_filestotal,    0, 0 },
338         { "filesfree",    lprocfs_rd_filesfree,     0, 0 },
339         { "filegroups",   lprocfs_filter_rd_groups, 0, 0 },
340         { "fstype",       lprocfs_rd_fstype,        0, 0 },
341         { "mntdev",       lprocfs_filter_rd_mntdev, 0, 0 },
342         { "last_id",      lprocfs_filter_rd_last_id,0, 0 },
343         { "tot_dirty",    lprocfs_filter_rd_tot_dirty,   0, 0 },
344         { "tot_pending",  lprocfs_filter_rd_tot_pending, 0, 0 },
345         { "tot_granted",  lprocfs_filter_rd_tot_granted, 0, 0 },
346         { "hash_stats",   lprocfs_obd_rd_hash,      0, 0 },
347         { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
348         { "recovery_maxtime", lprocfs_obd_rd_recovery_maxtime,
349                               lprocfs_obd_wr_recovery_maxtime, 0},
350         { "evict_client", 0, lprocfs_wr_evict_client, 0,
351                                 &lprocfs_evict_client_fops},
352         { "num_exports",  lprocfs_rd_num_exports,   0, 0 },
353         { "readcache_max_filesize",
354                           lprocfs_filter_rd_readcache,
355                           lprocfs_filter_wr_readcache, 0 },
356 #ifdef HAVE_QUOTA_SUPPORT
357         { "quota_type",     lprocfs_quota_rd_type,
358                             lprocfs_quota_wr_type, 0},
359 #endif
360         { "client_cache_count", lprocfs_filter_rd_fmd_max_num,
361                           lprocfs_filter_wr_fmd_max_num, 0 },
362         { "client_cache_seconds", lprocfs_filter_rd_fmd_max_age,
363                           lprocfs_filter_wr_fmd_max_age, 0 },
364         { "capa",         lprocfs_filter_rd_capa,
365                           lprocfs_filter_wr_capa, 0 },
366         { "capa_count",   lprocfs_filter_rd_capa_count, 0, 0 },
367         { "sec_level",    lprocfs_rd_sec_level,
368                           lprocfs_wr_sec_level,            0 },
369         { "read_cache_enable", lprocfs_filter_rd_cache, lprocfs_filter_wr_cache, 0},
370         { "writethrough_cache_enable", lprocfs_filter_rd_wcache,
371                           lprocfs_filter_wr_wcache, 0},
372         { 0 }
373 };
374
375 static struct lprocfs_vars lprocfs_filter_module_vars[] = {
376         { "num_refs",     lprocfs_rd_numrefs,       0, 0 },
377         { 0 }
378 };
379
380 void filter_tally(struct obd_export *exp, struct page **pages, int nr_pages,
381                   unsigned long *blocks, int blocks_per_page, int wr)
382 {
383         struct filter_obd *filter = &exp->exp_obd->u.filter;
384         struct filter_export_data *fed = &exp->exp_filter_data;
385         struct page *last_page = NULL;
386         unsigned long *last_block = NULL;
387         unsigned long discont_pages = 0;
388         unsigned long discont_blocks = 0;
389         int i;
390
391         if (nr_pages == 0)
392                 return;
393
394         lprocfs_oh_tally_log2(&filter->fo_filter_stats.hist[BRW_R_PAGES + wr],
395                               nr_pages);
396         lprocfs_oh_tally_log2(&fed->fed_brw_stats.hist[BRW_R_PAGES + wr],
397                               nr_pages);
398         if (exp->exp_nid_stats && exp->exp_nid_stats->nid_brw_stats)
399                 lprocfs_oh_tally_log2(&exp->exp_nid_stats->nid_brw_stats->
400                                         hist[BRW_R_PAGES + wr], nr_pages);
401
402         while (nr_pages-- > 0) {
403                 if (last_page && (*pages)->index != (last_page->index + 1))
404                         discont_pages++;
405                 last_page = *pages;
406                 pages++;
407                 for (i = 0; i < blocks_per_page; i++) {
408                         if (last_block && *blocks != (*last_block + 1))
409                                 discont_blocks++;
410                         last_block = blocks++;
411                 }
412         }
413
414         lprocfs_oh_tally(&filter->fo_filter_stats.hist[BRW_R_DISCONT_PAGES +wr],
415                          discont_pages);
416         lprocfs_oh_tally(&fed->fed_brw_stats.hist[BRW_R_DISCONT_PAGES + wr],
417                          discont_pages);
418         lprocfs_oh_tally(&filter->fo_filter_stats.hist[BRW_R_DISCONT_BLOCKS+wr],
419                          discont_blocks);
420         lprocfs_oh_tally(&fed->fed_brw_stats.hist[BRW_R_DISCONT_BLOCKS + wr],
421                          discont_blocks);
422
423         if (exp->exp_nid_stats && exp->exp_nid_stats->nid_brw_stats) {
424                 lprocfs_oh_tally_log2(&exp->exp_nid_stats->nid_brw_stats->
425                                         hist[BRW_R_DISCONT_PAGES + wr],
426                                       discont_pages);
427                 lprocfs_oh_tally_log2(&exp->exp_nid_stats->nid_brw_stats->
428                                         hist[BRW_R_DISCONT_BLOCKS + wr],
429                                       discont_blocks);
430         }
431 }
432
433 #define pct(a,b) (b ? a * 100 / b : 0)
434
435 static void display_brw_stats(struct seq_file *seq, char *name, char *units,
436         struct obd_histogram *read, struct obd_histogram *write, int log2)
437 {
438         unsigned long read_tot, write_tot, r, w, read_cum = 0, write_cum = 0;
439         int i;
440
441         seq_printf(seq, "\n%26s read      |     write\n", " ");
442         seq_printf(seq, "%-22s %-5s %% cum %% |  %-5s %% cum %%\n",
443                    name, units, units);
444
445         read_tot = lprocfs_oh_sum(read);
446         write_tot = lprocfs_oh_sum(write);
447         for (i = 0; i < OBD_HIST_MAX; i++) {
448                 r = read->oh_buckets[i];
449                 w = write->oh_buckets[i];
450                 read_cum += r;
451                 write_cum += w;
452                 if (read_cum == 0 && write_cum == 0)
453                         continue;
454
455                 if (!log2)
456                         seq_printf(seq, "%u", i);
457                 else if (i < 10)
458                         seq_printf(seq, "%u", 1<<i);
459                 else if (i < 20)
460                         seq_printf(seq, "%uK", 1<<(i-10));
461                 else
462                         seq_printf(seq, "%uM", 1<<(i-20));
463
464                 seq_printf(seq, ":\t\t%10lu %3lu %3lu   | %4lu %3lu %3lu\n",
465                            r, pct(r, read_tot), pct(read_cum, read_tot),
466                            w, pct(w, write_tot), pct(write_cum, write_tot));
467
468                 if (read_cum == read_tot && write_cum == write_tot)
469                         break;
470         }
471 }
472
473 static void brw_stats_show(struct seq_file *seq, struct brw_stats *brw_stats)
474 {
475         struct timeval now;
476
477         /* this sampling races with updates */
478         do_gettimeofday(&now);
479         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
480                    now.tv_sec, now.tv_usec);
481
482         display_brw_stats(seq, "pages per bulk r/w", "rpcs",
483                           &brw_stats->hist[BRW_R_PAGES],
484                           &brw_stats->hist[BRW_W_PAGES], 1);
485
486         display_brw_stats(seq, "discontiguous pages", "rpcs",
487                           &brw_stats->hist[BRW_R_DISCONT_PAGES],
488                           &brw_stats->hist[BRW_W_DISCONT_PAGES], 0);
489
490         display_brw_stats(seq, "discontiguous blocks", "rpcs",
491                           &brw_stats->hist[BRW_R_DISCONT_BLOCKS],
492                           &brw_stats->hist[BRW_W_DISCONT_BLOCKS], 0);
493
494         display_brw_stats(seq, "disk fragmented I/Os", "ios",
495                           &brw_stats->hist[BRW_R_DIO_FRAGS],
496                           &brw_stats->hist[BRW_W_DIO_FRAGS], 0);
497
498         display_brw_stats(seq, "disk I/Os in flight", "ios",
499                           &brw_stats->hist[BRW_R_RPC_HIST],
500                           &brw_stats->hist[BRW_W_RPC_HIST], 0);
501
502         {
503                 char title[24];
504                 sprintf(title, "I/O time (1/%ds)", HZ);
505                 display_brw_stats(seq, title, "ios",
506                                   &brw_stats->hist[BRW_R_IO_TIME],
507                                   &brw_stats->hist[BRW_W_IO_TIME], 1);
508         }
509
510         display_brw_stats(seq, "disk I/O size", "ios",
511                           &brw_stats->hist[BRW_R_DISK_IOSIZE],
512                           &brw_stats->hist[BRW_W_DISK_IOSIZE], 1);
513 }
514
515 #undef pct
516
517 static int filter_brw_stats_seq_show(struct seq_file *seq, void *v)
518 {
519         struct obd_device *dev = seq->private;
520         struct filter_obd *filter = &dev->u.filter;
521
522         brw_stats_show(seq, &filter->fo_filter_stats);
523
524         return 0;
525 }
526
527 static ssize_t filter_brw_stats_seq_write(struct file *file, const char *buf,
528                                        size_t len, loff_t *off)
529 {
530         struct seq_file *seq = file->private_data;
531         struct obd_device *dev = seq->private;
532         struct filter_obd *filter = &dev->u.filter;
533         int i;
534
535         for (i = 0; i < BRW_LAST; i++)
536                 lprocfs_oh_clear(&filter->fo_filter_stats.hist[i]);
537
538         return len;
539 }
540
541 LPROC_SEQ_FOPS(filter_brw_stats);
542
543 int lproc_filter_attach_seqstat(struct obd_device *dev)
544 {
545         return lprocfs_obd_seq_create(dev, "brw_stats", 0444,
546                                       &filter_brw_stats_fops, dev);
547 }
548
549 static int filter_per_export_stats_seq_show(struct seq_file *seq, void *v)
550 {
551         struct filter_export_data *fed = seq->private;
552
553         brw_stats_show(seq, &fed->fed_brw_stats);
554
555         return 0;
556 }
557
558 static ssize_t filter_per_export_stats_seq_write(struct file *file,
559                                        const char *buf, size_t len, loff_t *off)
560 {
561         struct seq_file *seq = file->private_data;
562         struct filter_export_data *fed = seq->private;
563         int i;
564
565         for (i = 0; i < BRW_LAST; i++)
566                 lprocfs_oh_clear(&fed->fed_brw_stats.hist[i]);
567
568         return len;
569 }
570
571 LPROC_SEQ_FOPS(filter_per_export_stats);
572
573 void lprocfs_filter_init_vars(struct lprocfs_static_vars *lvars)
574 {
575     lvars->module_vars  = lprocfs_filter_module_vars;
576     lvars->obd_vars     = lprocfs_filter_obd_vars;
577 }
578
579 static int filter_per_nid_stats_seq_show(struct seq_file *seq, void *v)
580 {
581         nid_stat_t *tmp = seq->private;
582
583         if (tmp->nid_brw_stats)
584                 brw_stats_show(seq, tmp->nid_brw_stats);
585
586         return 0;
587 }
588
589 static ssize_t filter_per_nid_stats_seq_write(struct file *file,
590                                               const char *buf, size_t len,
591                                               loff_t *off)
592 {
593         struct seq_file *seq = file->private_data;
594         nid_stat_t *tmp = seq->private;
595         int i;
596
597         if (tmp->nid_brw_stats)
598                 for (i = 0; i < BRW_LAST; i++)
599                         lprocfs_oh_clear(&tmp->nid_brw_stats->hist[i]);
600
601         return len;
602 }
603
604 LPROC_SEQ_FOPS(filter_per_nid_stats);
605 #endif /* LPROCFS */