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