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