Whamcloud - gitweb
LU-2558 test: recovery-small 19a FAIL no eviction
[fs/lustre-release.git] / lustre / ofd / lproc_ofd.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/ofd/lproc_ofd.c
37  */
38
39 #define DEBUG_SUBSYSTEM S_CLASS
40
41 #include <obd.h>
42 #include <lprocfs_status.h>
43 #include <linux/seq_file.h>
44
45 #include "ofd_internal.h"
46
47 #ifdef LPROCFS
48
49 static int lprocfs_ofd_rd_seqs(char *page, char **start, off_t off,
50                                 int count, int *eof, void *data)
51 {
52         struct obd_device *obd = (struct obd_device *)data;
53         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
54
55         *eof = 1;
56         return snprintf(page, count, "%u\n", ofd->ofd_seq_count);
57 }
58
59 static int lprocfs_ofd_rd_tot_dirty(char *page, char **start, off_t off,
60                                     int count, int *eof, void *data)
61 {
62         struct obd_device *obd = (struct obd_device *)data;
63         struct ofd_device *ofd;
64
65         LASSERT(obd != NULL);
66         ofd = ofd_dev(obd->obd_lu_dev);
67         *eof = 1;
68         return snprintf(page, count, LPU64"\n", ofd->ofd_tot_dirty);
69 }
70
71 static int lprocfs_ofd_rd_tot_granted(char *page, char **start, off_t off,
72                                       int count, int *eof, void *data)
73 {
74         struct obd_device *obd = (struct obd_device *)data;
75         struct ofd_device *ofd;
76
77         LASSERT(obd != NULL);
78         ofd = ofd_dev(obd->obd_lu_dev);
79         *eof = 1;
80         return snprintf(page, count, LPU64"\n", ofd->ofd_tot_granted);
81 }
82
83 static int lprocfs_ofd_rd_tot_pending(char *page, char **start, off_t off,
84                                       int count, int *eof, void *data)
85 {
86         struct obd_device *obd = (struct obd_device *)data;
87         struct ofd_device *ofd;
88
89         LASSERT(obd != NULL);
90         ofd = ofd_dev(obd->obd_lu_dev);
91         *eof = 1;
92         return snprintf(page, count, LPU64"\n", ofd->ofd_tot_pending);
93 }
94
95 static int lprocfs_ofd_rd_grant_precreate(char *page, char **start, off_t off,
96                                           int count, int *eof, void *data)
97 {
98         struct obd_device *obd = (struct obd_device *)data;
99
100         LASSERT(obd != NULL);
101         *eof = 1;
102         return snprintf(page, count, "%ld\n",
103                         obd->obd_self_export->exp_filter_data.fed_grant);
104 }
105
106 static int lprocfs_ofd_rd_grant_ratio(char *page, char **start, off_t off,
107                                       int count, int *eof, void *data)
108 {
109         struct obd_device *obd = (struct obd_device *)data;
110         struct ofd_device *ofd;
111
112         LASSERT(obd != NULL);
113         ofd = ofd_dev(obd->obd_lu_dev);
114         *eof = 1;
115         return snprintf(page, count, "%d%%\n",
116                         (int) ofd_grant_reserved(ofd, 100));
117 }
118
119 static int lprocfs_ofd_wr_grant_ratio(struct file *file, const char *buffer,
120                                       unsigned long count, void *data)
121 {
122         struct obd_device       *obd = (struct obd_device *)data;
123         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
124         int                      val;
125         int                      rc;
126
127         rc = lprocfs_write_helper(buffer, count, &val);
128         if (rc)
129                 return rc;
130
131         if (val > 100 || val < 0)
132                 return -EINVAL;
133
134         if (val == 0)
135                 CWARN("%s: disabling grant error margin\n", obd->obd_name);
136         if (val > 50)
137                 CWARN("%s: setting grant error margin >50%%, be warned that "
138                       "a huge part of the free space is now reserved for "
139                       "grants\n", obd->obd_name);
140
141         spin_lock(&ofd->ofd_grant_lock);
142         ofd->ofd_grant_ratio = ofd_grant_ratio_conv(val);
143         spin_unlock(&ofd->ofd_grant_lock);
144         return count;
145 }
146
147 static int lprocfs_ofd_rd_precreate_batch(char *page, char **start, off_t off,
148                                           int count, int *eof, void *data)
149 {
150         struct obd_device *obd = (struct obd_device *)data;
151         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
152
153         LASSERT(obd != NULL);
154         *eof = 1;
155         return snprintf(page, count, "%d\n", ofd->ofd_precreate_batch);
156 }
157
158 static int lprocfs_ofd_wr_precreate_batch(struct file *file, const char *buffer,
159                                           unsigned long count, void *data)
160 {
161         struct obd_device *obd = (struct obd_device *)data;
162         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
163         int val;
164         int rc;
165
166         rc = lprocfs_write_helper(buffer, count, &val);
167         if (rc)
168                 return rc;
169
170         if (val < 1)
171                 return -EINVAL;
172
173         spin_lock(&ofd->ofd_batch_lock);
174         ofd->ofd_precreate_batch = val;
175         spin_unlock(&ofd->ofd_batch_lock);
176         return count;
177 }
178
179 static int lprocfs_ofd_rd_last_id(char *page, char **start, off_t off,
180                                   int count, int *eof, void *data)
181 {
182         struct obd_device       *obd = data;
183         struct ofd_device       *ofd;
184         struct ofd_seq          *oseq = NULL;
185         int                     retval = 0, rc;
186
187         if (obd == NULL)
188                 return 0;
189
190         ofd = ofd_dev(obd->obd_lu_dev);
191
192         read_lock(&ofd->ofd_seq_list_lock);
193         cfs_list_for_each_entry(oseq, &ofd->ofd_seq_list, os_list) {
194                 rc = snprintf(page, count, LPX64": "LPX64"\n",
195                               oseq->os_seq, ofd_seq_last_oid(oseq));
196                 if (rc < 0) {
197                         retval = rc;
198                         break;
199                 }
200                 page += rc;
201                 count -= rc;
202                 retval += rc;
203         }
204         read_unlock(&ofd->ofd_seq_list_lock);
205         return retval;
206 }
207
208 int lprocfs_ofd_rd_fmd_max_num(char *page, char **start, off_t off,
209                                int count, int *eof, void *data)
210 {
211         struct obd_device       *obd = data;
212         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
213         int                      rc;
214
215         rc = snprintf(page, count, "%u\n", ofd->ofd_fmd_max_num);
216         return rc;
217 }
218
219 int lprocfs_ofd_wr_fmd_max_num(struct file *file, const char *buffer,
220                                unsigned long count, void *data)
221 {
222         struct obd_device       *obd = data;
223         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
224         int                      val;
225         int                      rc;
226
227         rc = lprocfs_write_helper(buffer, count, &val);
228         if (rc)
229                 return rc;
230
231         if (val > 65536 || val < 1)
232                 return -EINVAL;
233
234         ofd->ofd_fmd_max_num = val;
235         return count;
236 }
237
238 int lprocfs_ofd_rd_fmd_max_age(char *page, char **start, off_t off,
239                                int count, int *eof, void *data)
240 {
241         struct obd_device       *obd = data;
242         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
243         int                      rc;
244
245         rc = snprintf(page, count, "%ld\n", ofd->ofd_fmd_max_age / CFS_HZ);
246         return rc;
247 }
248
249 int lprocfs_ofd_wr_fmd_max_age(struct file *file, const char *buffer,
250                                unsigned long count, void *data)
251 {
252         struct obd_device       *obd = data;
253         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
254         int                      val;
255         int                      rc;
256
257         rc = lprocfs_write_helper(buffer, count, &val);
258         if (rc)
259                 return rc;
260
261         if (val > 65536 || val < 1)
262                 return -EINVAL;
263
264         ofd->ofd_fmd_max_age = val * CFS_HZ;
265         return count;
266 }
267
268 static int lprocfs_ofd_rd_capa(char *page, char **start, off_t off,
269                                int count, int *eof, void *data)
270 {
271         struct obd_device       *obd = data;
272         int                      rc;
273
274         rc = snprintf(page, count, "capability on: %s\n",
275                       obd->u.filter.fo_fl_oss_capa ? "oss" : "");
276         return rc;
277 }
278
279 static int lprocfs_ofd_wr_capa(struct file *file, const char *buffer,
280                                unsigned long count, void *data)
281 {
282         struct obd_device       *obd = data;
283         int                      val, rc;
284
285         rc = lprocfs_write_helper(buffer, count, &val);
286         if (rc)
287                 return rc;
288
289         if (val & ~0x1) {
290                 CERROR("invalid capability mode, only 0/1 are accepted.\n"
291                        " 1: enable oss fid capability\n"
292                        " 0: disable oss fid capability\n");
293                 return -EINVAL;
294         }
295
296         obd->u.filter.fo_fl_oss_capa = val;
297         LCONSOLE_INFO("OSS %s %s fid capability.\n", obd->obd_name,
298                       val ? "enabled" : "disabled");
299         return count;
300 }
301
302 static int lprocfs_ofd_rd_capa_count(char *page, char **start, off_t off,
303                                      int count, int *eof, void *data)
304 {
305         return snprintf(page, count, "%d %d\n",
306                         capa_count[CAPA_SITE_CLIENT],
307                         capa_count[CAPA_SITE_SERVER]);
308 }
309
310 int lprocfs_ofd_rd_degraded(char *page, char **start, off_t off,
311                             int count, int *eof, void *data)
312 {
313         struct obd_device *obd = data;
314         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
315
316         return snprintf(page, count, "%u\n", ofd->ofd_raid_degraded);
317 }
318
319 int lprocfs_ofd_wr_degraded(struct file *file, const char *buffer,
320                             unsigned long count, void *data)
321 {
322         struct obd_device       *obd = data;
323         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
324         int                      val, rc;
325
326         rc = lprocfs_write_helper(buffer, count, &val);
327         if (rc)
328                 return rc;
329
330         spin_lock(&ofd->ofd_flags_lock);
331         ofd->ofd_raid_degraded = !!val;
332         spin_unlock(&ofd->ofd_flags_lock);
333
334         return count;
335 }
336
337 int lprocfs_ofd_rd_fstype(char *page, char **start, off_t off, int count,
338                           int *eof, void *data)
339 {
340         struct obd_device *obd = data;
341         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
342         struct lu_device  *d;
343
344         LASSERT(ofd->ofd_osd);
345         d = &ofd->ofd_osd->dd_lu_dev;
346         LASSERT(d->ld_type);
347         return snprintf(page, count, "%s\n", d->ld_type->ldt_name);
348 }
349
350 int lprocfs_ofd_rd_syncjournal(char *page, char **start, off_t off,
351                                int count, int *eof, void *data)
352 {
353         struct obd_device       *obd = data;
354         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
355         int                      rc;
356
357         rc = snprintf(page, count, "%u\n", ofd->ofd_syncjournal);
358         return rc;
359 }
360
361 int lprocfs_ofd_wr_syncjournal(struct file *file, const char *buffer,
362                                unsigned long count, void *data)
363 {
364         struct obd_device       *obd = data;
365         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
366         int                      val;
367         int                      rc;
368
369         rc = lprocfs_write_helper(buffer, count, &val);
370         if (rc)
371                 return rc;
372
373         if (val < 0)
374                 return -EINVAL;
375
376         spin_lock(&ofd->ofd_flags_lock);
377         ofd->ofd_syncjournal = !!val;
378         ofd_slc_set(ofd);
379         spin_unlock(&ofd->ofd_flags_lock);
380
381         return count;
382 }
383
384 static char *sync_on_cancel_states[] = {"never",
385                                         "blocking",
386                                         "always" };
387
388 int lprocfs_ofd_rd_sync_lock_cancel(char *page, char **start, off_t off,
389                                     int count, int *eof, void *data)
390 {
391         struct obd_device       *obd = data;
392         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
393         int                      rc;
394
395         rc = snprintf(page, count, "%s\n",
396                       sync_on_cancel_states[ofd->ofd_sync_lock_cancel]);
397         return rc;
398 }
399
400 int lprocfs_ofd_wr_sync_lock_cancel(struct file *file, const char *buffer,
401                                     unsigned long count, void *data)
402 {
403         struct obd_device       *obd = data;
404         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
405         int                      val = -1;
406         int                      i;
407
408         for (i = 0 ; i < NUM_SYNC_ON_CANCEL_STATES; i++) {
409                 if (memcmp(buffer, sync_on_cancel_states[i],
410                            strlen(sync_on_cancel_states[i])) == 0) {
411                         val = i;
412                         break;
413                 }
414         }
415         if (val == -1) {
416                 int rc;
417
418                 rc = lprocfs_write_helper(buffer, count, &val);
419                 if (rc)
420                         return rc;
421         }
422
423         if (val < 0 || val > 2)
424                 return -EINVAL;
425
426         spin_lock(&ofd->ofd_flags_lock);
427         ofd->ofd_sync_lock_cancel = val;
428         spin_unlock(&ofd->ofd_flags_lock);
429         return count;
430 }
431
432 int lprocfs_ofd_rd_grant_compat_disable(char *page, char **start, off_t off,
433                                         int count, int *eof, void *data)
434 {
435         struct obd_device       *obd = data;
436         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
437         int                      rc;
438
439         rc = snprintf(page, count, "%u\n", ofd->ofd_grant_compat_disable);
440         return rc;
441 }
442
443 int lprocfs_ofd_wr_grant_compat_disable(struct file *file, const char *buffer,
444                                         unsigned long count, void *data)
445 {
446         struct obd_device       *obd = data;
447         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
448         int                      val;
449         int                      rc;
450
451         rc = lprocfs_write_helper(buffer, count, &val);
452         if (rc)
453                 return rc;
454
455         if (val < 0)
456                 return -EINVAL;
457
458         spin_lock(&ofd->ofd_flags_lock);
459         ofd->ofd_grant_compat_disable = !!val;
460         spin_unlock(&ofd->ofd_flags_lock);
461
462         return count;
463 }
464
465 static struct lprocfs_vars lprocfs_ofd_obd_vars[] = {
466         { "uuid",                lprocfs_rd_uuid, 0, 0 },
467         { "blocksize",           lprocfs_rd_blksize, 0, 0 },
468         { "kbytestotal",         lprocfs_rd_kbytestotal, 0, 0 },
469         { "kbytesfree",          lprocfs_rd_kbytesfree, 0, 0 },
470         { "kbytesavail",         lprocfs_rd_kbytesavail, 0, 0 },
471         { "filestotal",          lprocfs_rd_filestotal, 0, 0 },
472         { "filesfree",           lprocfs_rd_filesfree, 0, 0 },
473         { "seqs_allocated",      lprocfs_ofd_rd_seqs, 0, 0 },
474         { "fstype",              lprocfs_ofd_rd_fstype, 0, 0 },
475         { "last_id",             lprocfs_ofd_rd_last_id, 0, 0 },
476         { "tot_dirty",           lprocfs_ofd_rd_tot_dirty,   0, 0 },
477         { "tot_pending",         lprocfs_ofd_rd_tot_pending, 0, 0 },
478         { "tot_granted",         lprocfs_ofd_rd_tot_granted, 0, 0 },
479         { "grant_precreate",     lprocfs_ofd_rd_grant_precreate, 0, 0 },
480         { "grant_ratio",         lprocfs_ofd_rd_grant_ratio,
481                                  lprocfs_ofd_wr_grant_ratio, 0, 0 },
482         { "precreate_batch",     lprocfs_ofd_rd_precreate_batch,
483                                  lprocfs_ofd_wr_precreate_batch, 0 },
484         { "recovery_status",     lprocfs_obd_rd_recovery_status, 0, 0 },
485         { "recovery_time_soft",  lprocfs_obd_rd_recovery_time_soft,
486                                  lprocfs_obd_wr_recovery_time_soft, 0},
487         { "recovery_time_hard",  lprocfs_obd_rd_recovery_time_hard,
488                                  lprocfs_obd_wr_recovery_time_hard, 0},
489         { "evict_client",        0, lprocfs_wr_evict_client, 0,
490                                  &lprocfs_evict_client_fops},
491         { "num_exports",         lprocfs_rd_num_exports,   0, 0 },
492         { "degraded",            lprocfs_ofd_rd_degraded,
493                                  lprocfs_ofd_wr_degraded, 0},
494         { "sync_journal",        lprocfs_ofd_rd_syncjournal,
495                                  lprocfs_ofd_wr_syncjournal, 0 },
496         { "sync_on_lock_cancel", lprocfs_ofd_rd_sync_lock_cancel,
497                                  lprocfs_ofd_wr_sync_lock_cancel, 0 },
498         { "instance",            lprocfs_target_rd_instance, 0 },
499         { "ir_factor",           lprocfs_obd_rd_ir_factor,
500                                  lprocfs_obd_wr_ir_factor, 0},
501         { "grant_compat_disable", lprocfs_ofd_rd_grant_compat_disable,
502                                   lprocfs_ofd_wr_grant_compat_disable, 0 },
503         { "client_cache_count",  lprocfs_ofd_rd_fmd_max_num,
504                                  lprocfs_ofd_wr_fmd_max_num, 0 },
505         { "client_cache_seconds", lprocfs_ofd_rd_fmd_max_age,
506                                   lprocfs_ofd_wr_fmd_max_age, 0 },
507         { "capa",                lprocfs_ofd_rd_capa,
508                                  lprocfs_ofd_wr_capa, 0 },
509         { "capa_count",          lprocfs_ofd_rd_capa_count, 0, 0 },
510         { "job_cleanup_interval", lprocfs_rd_job_interval,
511                                   lprocfs_wr_job_interval, 0},
512         { 0 }
513 };
514
515 static struct lprocfs_vars lprocfs_ofd_module_vars[] = {
516         { "num_refs",     lprocfs_rd_numrefs,   0, 0 },
517         { 0 }
518 };
519
520 #define pct(a,b) (b ? a * 100 / b : 0)
521
522 static void display_brw_stats(struct seq_file *seq, char *name, char *units,
523                               struct obd_histogram *read,
524                               struct obd_histogram *write, int log2)
525 {
526         unsigned long   read_tot, write_tot, r, w, read_cum = 0, write_cum = 0;
527         int             i;
528
529         seq_printf(seq, "\n%26s read      |     write\n", " ");
530         seq_printf(seq, "%-22s %-5s %% cum %% |  %-5s %% cum %%\n",
531                    name, units, units);
532
533         read_tot = lprocfs_oh_sum(read);
534         write_tot = lprocfs_oh_sum(write);
535         for (i = 0; i < OBD_HIST_MAX; i++) {
536                 r = read->oh_buckets[i];
537                 w = write->oh_buckets[i];
538                 read_cum += r;
539                 write_cum += w;
540                 if (read_cum == 0 && write_cum == 0)
541                         continue;
542
543                 if (!log2)
544                         seq_printf(seq, "%u", i);
545                 else if (i < 10)
546                         seq_printf(seq, "%u", 1 << i);
547                 else if (i < 20)
548                         seq_printf(seq, "%uK", 1 << (i - 10));
549                 else
550                         seq_printf(seq, "%uM", 1 << (i - 20));
551
552                 seq_printf(seq, ":\t\t%10lu %3lu %3lu   | %4lu %3lu %3lu\n",
553                            r, pct(r, read_tot), pct(read_cum, read_tot),
554                            w, pct(w, write_tot), pct(write_cum, write_tot));
555
556                 if (read_cum == read_tot && write_cum == write_tot)
557                         break;
558         }
559 }
560
561 static void brw_stats_show(struct seq_file *seq, struct brw_stats *brw_stats)
562 {
563         struct timeval  now;
564         char            title[24];
565
566         /* this sampling races with updates */
567         cfs_gettimeofday(&now);
568         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
569                    now.tv_sec, now.tv_usec);
570
571         display_brw_stats(seq, "pages per bulk r/w", "rpcs",
572                           &brw_stats->hist[BRW_R_PAGES],
573                           &brw_stats->hist[BRW_W_PAGES], 1);
574
575         display_brw_stats(seq, "discontiguous pages", "rpcs",
576                           &brw_stats->hist[BRW_R_DISCONT_PAGES],
577                           &brw_stats->hist[BRW_W_DISCONT_PAGES], 0);
578
579         display_brw_stats(seq, "discontiguous blocks", "rpcs",
580                           &brw_stats->hist[BRW_R_DISCONT_BLOCKS],
581                           &brw_stats->hist[BRW_W_DISCONT_BLOCKS], 0);
582
583         display_brw_stats(seq, "disk fragmented I/Os", "ios",
584                           &brw_stats->hist[BRW_R_DIO_FRAGS],
585                           &brw_stats->hist[BRW_W_DIO_FRAGS], 0);
586
587         display_brw_stats(seq, "disk I/Os in flight", "ios",
588                           &brw_stats->hist[BRW_R_RPC_HIST],
589                           &brw_stats->hist[BRW_W_RPC_HIST], 0);
590
591         sprintf(title, "I/O time (1/%ds)", CFS_HZ);
592         display_brw_stats(seq, title, "ios",
593                           &brw_stats->hist[BRW_R_IO_TIME],
594                           &brw_stats->hist[BRW_W_IO_TIME], 1);
595
596         display_brw_stats(seq, "disk I/O size", "ios",
597                           &brw_stats->hist[BRW_R_DISK_IOSIZE],
598                           &brw_stats->hist[BRW_W_DISK_IOSIZE], 1);
599 }
600
601 #undef pct
602
603 static int ofd_brw_stats_seq_show(struct seq_file *seq, void *v)
604 {
605         struct obd_device *dev = seq->private;
606         struct filter_obd *ofd = &dev->u.filter;
607
608         brw_stats_show(seq, &ofd->fo_filter_stats);
609
610         return 0;
611 }
612
613 static ssize_t ofd_brw_stats_seq_write(struct file *file, const char *buf,
614                                        size_t len, loff_t *off)
615 {
616         struct seq_file         *seq = file->private_data;
617         struct obd_device       *dev = seq->private;
618         struct filter_obd       *ofd = &dev->u.filter;
619         int                      i;
620
621         for (i = 0; i < BRW_LAST; i++)
622                 lprocfs_oh_clear(&ofd->fo_filter_stats.hist[i]);
623
624         return len;
625 }
626
627 LPROC_SEQ_FOPS(ofd_brw_stats);
628
629 int lproc_ofd_attach_seqstat(struct obd_device *dev)
630 {
631         return lprocfs_obd_seq_create(dev, "brw_stats", 0644,
632                                       &ofd_brw_stats_fops, dev);
633 }
634
635 void lprocfs_ofd_init_vars(struct lprocfs_static_vars *lvars)
636 {
637         lvars->module_vars  = lprocfs_ofd_module_vars;
638         lvars->obd_vars     = lprocfs_ofd_obd_vars;
639 }
640
641 static int ofd_per_nid_stats_seq_show(struct seq_file *seq, void *v)
642 {
643         nid_stat_t *stat = seq->private;
644
645         if (stat->nid_brw_stats)
646                 brw_stats_show(seq, stat->nid_brw_stats);
647
648         return 0;
649 }
650
651 static ssize_t ofd_per_nid_stats_seq_write(struct file *file, const char *buf,
652                                            size_t len, loff_t *off)
653 {
654         struct seq_file *seq = file->private_data;
655         nid_stat_t      *stat = seq->private;
656         int              i;
657
658         if (stat->nid_brw_stats)
659                 for (i = 0; i < BRW_LAST; i++)
660                         lprocfs_oh_clear(&stat->nid_brw_stats->hist[i]);
661
662         return len;
663 }
664
665 LPROC_SEQ_FOPS(ofd_per_nid_stats);
666
667 void ofd_stats_counter_init(struct lprocfs_stats *stats)
668 {
669         LASSERT(stats && stats->ls_num == LPROC_OFD_STATS_LAST);
670         lprocfs_counter_init(stats, LPROC_OFD_STATS_READ,
671                              LPROCFS_CNTR_AVGMINMAX, "read", "bytes");
672         lprocfs_counter_init(stats, LPROC_OFD_STATS_WRITE,
673                              LPROCFS_CNTR_AVGMINMAX, "write", "bytes");
674         lprocfs_counter_init(stats, LPROC_OFD_STATS_SETATTR,
675                              0, "setattr", "reqs");
676         lprocfs_counter_init(stats, LPROC_OFD_STATS_PUNCH,
677                              0, "punch", "reqs");
678         lprocfs_counter_init(stats, LPROC_OFD_STATS_SYNC,
679                              0, "sync", "reqs");
680 }
681 #endif /* LPROCFS */