Whamcloud - gitweb
land v0.9.1 on HEAD, in preparation for a 1.0.x branch
[fs/lustre-release.git] / lustre / obdclass / lprocfs_status.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2002, 2003 Cluster File Systems, Inc.
5  *   Author: Hariharan Thantry <thantry@users.sourceforge.net>
6  *
7  *   This file is part of Lustre, http://www.lustre.org.
8  *
9  *   Lustre is free software; you can redistribute it and/or
10  *   modify it under the terms of version 2 of the GNU General Public
11  *   License as published by the Free Software Foundation.
12  *
13  *   Lustre is distributed in the hope that it will be useful,
14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *   GNU General Public License for more details.
17  *
18  *   You should have received a copy of the GNU General Public License
19  *   along with Lustre; if not, write to the Free Software
20  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22
23 #ifndef EXPORT_SYMTAB
24 # define EXPORT_SYMTAB
25 #endif
26 #define DEBUG_SUBSYSTEM S_CLASS
27
28 #ifdef __KERNEL__
29 # include <linux/config.h>
30 # include <linux/module.h>
31 # include <linux/version.h>
32 # include <linux/slab.h>
33 # include <linux/types.h>
34 # if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
35 #  include <asm/statfs.h>
36 # endif
37 # include <linux/seq_file.h>
38 #else /* __KERNEL__ */
39 # include <liblustre.h>
40 #endif
41
42 #include <linux/obd_class.h>
43 #include <linux/lprocfs_status.h>
44 #include <linux/lustre_fsfilt.h>
45
46 #if defined(LPROCFS) && defined(__KERNEL__)
47
48 struct proc_dir_entry *lprocfs_srch(struct proc_dir_entry *head,
49                                     const char *name)
50 {
51         struct proc_dir_entry *temp;
52
53         if (head == NULL)
54                 return NULL;
55
56         temp = head->subdir;
57         while (temp != NULL) {
58                 if (strcmp(temp->name, name) == 0)
59                         return temp;
60
61                 temp = temp->next;
62         }
63         return NULL;
64 }
65
66 /* lprocfs API calls */
67
68 int lprocfs_add_vars(struct proc_dir_entry *root, struct lprocfs_vars *list,
69                      void *data)
70 {
71         if (root == NULL || list == NULL)
72                 return -EINVAL;
73
74         while (list->name != NULL) {
75                 struct proc_dir_entry *cur_root, *proc;
76                 char *pathcopy, *cur, *next, pathbuf[64];
77                 int pathsize = strlen(list->name) + 1;
78
79                 proc = NULL;
80                 cur_root = root;
81
82                 /* need copy of path for strsep */
83                 if (strlen(list->name) > sizeof(pathbuf) - 1) {
84                         OBD_ALLOC(pathcopy, pathsize);
85                         if (pathcopy == NULL)
86                                 return -ENOMEM;
87                 } else {
88                         pathcopy = pathbuf;
89                 }
90
91                 next = pathcopy;
92                 strcpy(pathcopy, list->name);
93
94                 while (cur_root != NULL && (cur = strsep(&next, "/"))) {
95                         if (*cur =='\0') /* skip double/trailing "/" */
96                                 continue;
97
98                         proc = lprocfs_srch(cur_root, cur);
99                         CDEBUG(D_OTHER, "cur_root=%s, cur=%s, next=%s, (%s)\n",
100                                cur_root->name, cur, next,
101                                (proc ? "exists" : "new"));
102                         if (next != NULL) {
103                                 cur_root = (proc ? proc :
104                                             proc_mkdir(cur, cur_root));
105                         } else if (proc == NULL) {
106                                 mode_t mode = 0;
107                                 if (list->read_fptr)
108                                         mode = 0444;
109                                 if (list->write_fptr)
110                                         mode |= 0200;
111                                 proc = create_proc_entry(cur, mode, cur_root);
112                         }
113                 }
114
115                 if (pathcopy != pathbuf)
116                 OBD_FREE(pathcopy, pathsize);
117
118                 if (cur_root == NULL || proc == NULL) {
119                         CERROR("LprocFS: No memory to create /proc entry %s",
120                                list->name);
121                         return -ENOMEM;
122                 }
123
124                 proc->read_proc = list->read_fptr;
125                 proc->write_proc = list->write_fptr;
126                 proc->data = (list->data ? list->data : data);
127                 list++;
128         }
129         return 0;
130 }
131
132 void lprocfs_remove(struct proc_dir_entry *root)
133 {
134         struct proc_dir_entry *temp = root;
135         struct proc_dir_entry *rm_entry;
136         struct proc_dir_entry *parent;
137
138         LASSERT(root != NULL);
139         parent = root->parent;
140         LASSERT(parent != NULL);
141
142         while (1) {
143                 while (temp->subdir != NULL)
144                         temp = temp->subdir;
145
146                 rm_entry = temp;
147                 temp = temp->parent;
148                 remove_proc_entry(rm_entry->name, rm_entry->parent);
149                 if (temp == parent)
150                         break;
151         }
152 }
153
154 struct proc_dir_entry *lprocfs_register(const char *name,
155                                         struct proc_dir_entry *parent,
156                                         struct lprocfs_vars *list, void *data)
157 {
158         struct proc_dir_entry *newchild;
159
160         newchild = lprocfs_srch(parent, name);
161         if (newchild != NULL) {
162                 CERROR(" Lproc: Attempting to register %s more than once \n",
163                        name);
164                 return ERR_PTR(-EALREADY);
165         }
166
167         newchild = proc_mkdir(name, parent);
168         if (newchild != NULL && list != NULL) {
169                 int rc = lprocfs_add_vars(newchild, list, data);
170                 if (rc) {
171                         lprocfs_remove(newchild);
172                         return ERR_PTR(rc);
173                 }
174         }
175         return newchild;
176 }
177
178 /* Generic callbacks */
179
180 int lprocfs_rd_u64(char *page, char **start, off_t off,
181                    int count, int *eof, void *data)
182 {
183         LASSERT(data != NULL);
184         *eof = 1;
185         return snprintf(page, count, LPU64"\n", *(__u64 *)data);
186 }
187
188 int lprocfs_rd_uuid(char *page, char **start, off_t off, int count,
189                     int *eof, void *data)
190 {
191         struct obd_device *dev = (struct obd_device*)data;
192
193         LASSERT(dev != NULL);
194         *eof = 1;
195         return snprintf(page, count, "%s\n", dev->obd_uuid.uuid);
196 }
197
198 int lprocfs_rd_name(char *page, char **start, off_t off, int count,
199                     int *eof, void* data)
200 {
201         struct obd_device *dev = (struct obd_device *)data;
202
203         LASSERT(dev != NULL);
204         LASSERT(dev->obd_name != NULL);
205         *eof = 1;
206         return snprintf(page, count, "%s\n", dev->obd_name);
207 }
208
209 int lprocfs_rd_fstype(char *page, char **start, off_t off, int count, int *eof,
210                       void *data)
211 {
212         struct obd_device *obd = (struct obd_device *)data;
213
214         LASSERT(obd != NULL);
215         LASSERT(obd->obd_fsops != NULL);
216         LASSERT(obd->obd_fsops->fs_type != NULL);
217         return snprintf(page, count, "%s\n", obd->obd_fsops->fs_type);
218 }
219
220 int lprocfs_rd_blksize(char *page, char **start, off_t off, int count,
221                        int *eof, void *data)
222 {
223         struct obd_statfs osfs;
224         int rc = obd_statfs(data, &osfs, jiffies - HZ);
225         if (!rc) {
226                 *eof = 1;
227                 rc = snprintf(page, count, "%u\n", osfs.os_bsize);
228         }
229         return rc;
230 }
231
232 int lprocfs_rd_kbytestotal(char *page, char **start, off_t off, int count,
233                            int *eof, void *data)
234 {
235         struct obd_statfs osfs;
236         int rc = obd_statfs(data, &osfs, jiffies - HZ);
237         if (!rc) {
238                 __u32 blk_size = osfs.os_bsize >> 10;
239                 __u64 result = osfs.os_blocks;
240
241                 while (blk_size >>= 1)
242                         result <<= 1;
243
244                 *eof = 1;
245                 rc = snprintf(page, count, LPU64"\n", result);
246         }
247         return rc;
248 }
249
250 int lprocfs_rd_kbytesfree(char *page, char **start, off_t off, int count,
251                           int *eof, void *data)
252 {
253         struct obd_statfs osfs;
254         int rc = obd_statfs(data, &osfs, jiffies - HZ);
255         if (!rc) {
256                 __u32 blk_size = osfs.os_bsize >> 10;
257                 __u64 result = osfs.os_bfree;
258
259                 while (blk_size >>= 1)
260                         result <<= 1;
261
262                 *eof = 1;
263                 rc = snprintf(page, count, LPU64"\n", result);
264         }
265         return rc;
266 }
267
268 int lprocfs_rd_filestotal(char *page, char **start, off_t off, int count,
269                           int *eof, void *data)
270 {
271         struct obd_statfs osfs;
272         int rc = obd_statfs(data, &osfs, jiffies - HZ);
273         if (!rc) {
274                 *eof = 1;
275                 rc = snprintf(page, count, LPU64"\n", osfs.os_files);
276         }
277
278         return rc;
279 }
280
281 int lprocfs_rd_filesfree(char *page, char **start, off_t off, int count,
282                          int *eof, void *data)
283 {
284         struct obd_statfs osfs;
285         int rc = obd_statfs(data, &osfs, jiffies - HZ);
286         if (!rc) {
287                 *eof = 1;
288                 rc = snprintf(page, count, LPU64"\n", osfs.os_ffree);
289         }
290         return rc;
291 }
292
293 int lprocfs_rd_filegroups(char *page, char **start, off_t off, int count,
294                           int *eof, void *data)
295 {
296         *eof = 1;
297         return snprintf(page, count, "unimplemented\n");
298 }
299
300 int lprocfs_rd_server_uuid(char *page, char **start, off_t off, int count,
301                            int *eof, void *data)
302 {
303         struct obd_device *obd = (struct obd_device *)data;
304         struct obd_import *imp;
305         static char* import_state_names[] = {
306                 "<UNKNOWN 0>", "INVALID", "NEW", "DISCONN", "CONNECTING",
307                 "REPLAY", "RECOVER", "FULL", "EVICTED",
308         };
309         char *imp_state_name = NULL;
310         
311         LASSERT(obd != NULL);
312         imp = obd->u.cli.cl_import;
313         LASSERT(imp->imp_state <= LUSTRE_IMP_EVICTED);
314         imp_state_name = import_state_names[imp->imp_state];
315         *eof = 1;
316         return snprintf(page, count, "%s\t%s\n",
317                         imp->imp_target_uuid.uuid, imp_state_name);
318 }
319
320 int lprocfs_rd_conn_uuid(char *page, char **start, off_t off, int count,
321                          int *eof,  void *data)
322 {
323         struct obd_device *obd = (struct obd_device*)data;
324         struct ptlrpc_connection *conn;
325
326         LASSERT(obd != NULL);
327         conn = obd->u.cli.cl_import->imp_connection;
328         LASSERT(conn != NULL);
329         *eof = 1;
330         return snprintf(page, count, "%s\n", conn->c_remote_uuid.uuid);
331 }
332
333 int lprocfs_rd_numrefs(char *page, char **start, off_t off, int count,
334                        int *eof, void *data)
335 {
336         struct obd_type *class = (struct obd_type*) data;
337
338         LASSERT(class != NULL);
339         *eof = 1;
340         return snprintf(page, count, "%d\n", class->typ_refcnt);
341 }
342
343 int lprocfs_obd_attach(struct obd_device *dev, struct lprocfs_vars *list)
344 {
345         int rc = 0;
346
347         LASSERT(dev != NULL);
348         LASSERT(dev->obd_type != NULL);
349         LASSERT(dev->obd_type->typ_procroot != NULL);
350
351         dev->obd_proc_entry = lprocfs_register(dev->obd_name,
352                                                dev->obd_type->typ_procroot,
353                                                list, dev);
354         if (IS_ERR(dev->obd_proc_entry)) {
355                 rc = PTR_ERR(dev->obd_proc_entry);
356                 dev->obd_proc_entry = NULL;
357         }
358         return rc;
359 }
360
361 int lprocfs_obd_detach(struct obd_device *dev)
362 {
363         if (dev && dev->obd_proc_entry) {
364                 lprocfs_remove(dev->obd_proc_entry);
365                 dev->obd_proc_entry = NULL;
366         }
367         return 0;
368 }
369
370 struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num)
371 {
372         struct lprocfs_stats *stats;
373         struct lprocfs_percpu *percpu;
374         unsigned int percpusize;
375         unsigned int i;
376
377         if (num == 0)
378                 return NULL;
379
380         OBD_ALLOC(stats, offsetof(typeof(*stats), ls_percpu[num_online_cpus()]));
381         if (stats == NULL)
382                 return NULL;
383
384         percpusize = L1_CACHE_ALIGN(offsetof(typeof(*percpu), lp_cntr[num]));
385         stats->ls_percpu_size = num_online_cpus() * percpusize;
386         OBD_ALLOC(stats->ls_percpu[0], stats->ls_percpu_size);
387         if (stats->ls_percpu[0] == NULL) {
388                 OBD_FREE(stats, offsetof(typeof(*stats),
389                                          ls_percpu[num_online_cpus()]));
390                 return NULL;
391         }
392
393         stats->ls_num = num;
394         for (i = 1; i < num_online_cpus(); i++)
395                 stats->ls_percpu[i] = (void *)(stats->ls_percpu[i - 1]) +
396                         percpusize;
397
398         return stats;
399 }
400
401 void lprocfs_free_stats(struct lprocfs_stats *stats)
402 {
403         if (stats->ls_num == 0)
404                 return;
405
406         OBD_FREE(stats->ls_percpu[0], stats->ls_percpu_size);
407         OBD_FREE(stats, offsetof(typeof(*stats), ls_percpu[num_online_cpus()]));
408 }
409
410 /* Reset counter under lock */
411 int lprocfs_counter_write(struct file *file, const char *buffer,
412                           unsigned long count, void *data)
413 {
414         /* not supported */
415         return 0;
416 }
417
418 static void *lprocfs_stats_seq_start(struct seq_file *p, loff_t *pos)
419 {
420         struct lprocfs_stats *stats = p->private;
421         /* return 1st cpu location */
422         return (*pos >= stats->ls_num) ? NULL :
423                 &(stats->ls_percpu[0]->lp_cntr[*pos]);
424 }
425
426 static void lprocfs_stats_seq_stop(struct seq_file *p, void *v)
427 {
428 }
429
430 static void *lprocfs_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
431 {
432         struct lprocfs_stats *stats = p->private;
433         ++*pos;
434         return (*pos >= stats->ls_num) ? NULL :
435                 &(stats->ls_percpu[0]->lp_cntr[*pos]);
436 }
437
438 /* seq file export of one lprocfs counter */
439 static int lprocfs_stats_seq_show(struct seq_file *p, void *v)
440 {
441        struct lprocfs_stats *stats = p->private;
442        struct lprocfs_counter  *cntr = v;
443        struct lprocfs_counter  t, ret = { .lc_min = ~(__u64)0 };
444        int i, idx, rc;
445
446        if (cntr == &(stats->ls_percpu[0])->lp_cntr[0]) {
447                struct timeval now;
448                do_gettimeofday(&now);
449                rc = seq_printf(p, "%-25s %lu.%lu secs.usecs\n",
450                                "snapshot_time", now.tv_sec, now.tv_usec);
451                if (rc < 0)
452                        return rc;
453        }
454        idx = cntr - &(stats->ls_percpu[0])->lp_cntr[0];
455
456        for (i = 0; i < num_online_cpus(); i++) {
457                struct lprocfs_counter *percpu_cntr =
458                        &(stats->ls_percpu[i])->lp_cntr[idx];
459                int centry;
460
461                do {
462                        centry = atomic_read(&percpu_cntr->lc_cntl.la_entry);
463                        t.lc_count = percpu_cntr->lc_count;
464                        t.lc_sum = percpu_cntr->lc_sum;
465                        t.lc_min = percpu_cntr->lc_min;
466                        t.lc_max = percpu_cntr->lc_max;
467                        t.lc_sumsquare = percpu_cntr->lc_sumsquare;
468                } while (centry != atomic_read(&percpu_cntr->lc_cntl.la_entry) &&
469                         centry != atomic_read(&percpu_cntr->lc_cntl.la_exit));
470                ret.lc_count += t.lc_count;
471                ret.lc_sum += t.lc_sum;
472                if (t.lc_min < ret.lc_min)
473                        ret.lc_min = t.lc_min;
474                if (t.lc_max > ret.lc_max)
475                        ret.lc_max = t.lc_max;
476                ret.lc_sumsquare += t.lc_sumsquare;
477        }
478
479        rc = seq_printf(p, "%-25s "LPU64" samples [%s]", cntr->lc_name,
480                        ret.lc_count, cntr->lc_units);
481        if (rc < 0)
482                goto out;
483
484        if ((cntr->lc_config & LPROCFS_CNTR_AVGMINMAX) && (ret.lc_count > 0)) {
485                rc = seq_printf(p, " "LPU64" "LPU64" "LPU64,
486                                ret.lc_min, ret.lc_max, ret.lc_sum);
487                if (rc < 0)
488                        goto out;
489                if (cntr->lc_config & LPROCFS_CNTR_STDDEV)
490                        rc = seq_printf(p, " "LPU64, ret.lc_sumsquare);
491                if (rc < 0)
492                        goto out;
493        }
494        rc = seq_printf(p, "\n");
495  out:
496        return (rc < 0) ? rc : 0;
497 }
498
499 struct seq_operations lprocfs_stats_seq_sops = {
500         start: lprocfs_stats_seq_start,
501         stop:  lprocfs_stats_seq_stop,
502         next:  lprocfs_stats_seq_next,
503         show:  lprocfs_stats_seq_show,
504 };
505
506 static int lprocfs_stats_seq_open(struct inode *inode, struct file *file)
507 {
508         struct proc_dir_entry *dp = inode->u.generic_ip;
509         struct seq_file *seq;
510         int rc;
511
512         rc = seq_open(file, &lprocfs_stats_seq_sops);
513         if (rc)
514                 return rc;
515         seq = file->private_data;
516         seq->private = dp->data;
517         return 0;
518 }
519
520 struct file_operations lprocfs_stats_seq_fops = {
521         open:    lprocfs_stats_seq_open,
522         read:    seq_read,
523         llseek:  seq_lseek,
524         release: seq_release,
525 };
526
527 int lprocfs_register_stats(struct proc_dir_entry *root, const char *name,
528                            struct lprocfs_stats *stats)
529 {
530         struct proc_dir_entry *entry;
531         LASSERT(root != NULL);
532
533         entry = create_proc_entry(name, 0444, root);
534         if (entry == NULL)
535                 return -ENOMEM;
536         entry->proc_fops = &lprocfs_stats_seq_fops;
537         entry->data = (void *)stats;
538         entry->write_proc = lprocfs_counter_write;
539         return 0;
540 }
541
542 void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
543                           unsigned conf, const char *name, const char *units)
544 {
545         struct lprocfs_counter *c;
546         int i;
547
548         LASSERT(stats != NULL);
549         for (i = 0; i < num_online_cpus(); i++) {
550                 c = &(stats->ls_percpu[i]->lp_cntr[index]);
551                 c->lc_config = conf;
552                 c->lc_min = ~(__u64)0;
553                 c->lc_name = name;
554                 c->lc_units = units;
555         }
556 }
557 EXPORT_SYMBOL(lprocfs_counter_init);
558
559 #define LPROCFS_OBD_OP_INIT(base, stats, op)                               \
560 do {                                                                       \
561         unsigned int coffset = base + OBD_COUNTER_OFFSET(op);              \
562         LASSERT(coffset < stats->ls_num);                                  \
563         lprocfs_counter_init(stats, coffset, 0, #op, "reqs");              \
564 } while (0)
565
566 int lprocfs_alloc_obd_stats(struct obd_device *obd, unsigned num_private_stats)
567 {
568         struct lprocfs_stats *stats;
569         unsigned int num_stats;
570         int rc, i;
571
572         LASSERT(obd->obd_stats == NULL);
573         LASSERT(obd->obd_proc_entry != NULL);
574         LASSERT(obd->obd_cntr_base == 0);
575
576         num_stats = 1 + OBD_COUNTER_OFFSET(notify) +
577                 num_private_stats;
578         stats = lprocfs_alloc_stats(num_stats);
579         if (stats == NULL)
580                 return -ENOMEM;
581
582         LPROCFS_OBD_OP_INIT(num_private_stats, stats, iocontrol);
583         LPROCFS_OBD_OP_INIT(num_private_stats, stats, get_info);
584         LPROCFS_OBD_OP_INIT(num_private_stats, stats, set_info);
585         LPROCFS_OBD_OP_INIT(num_private_stats, stats, attach);
586         LPROCFS_OBD_OP_INIT(num_private_stats, stats, detach);
587         LPROCFS_OBD_OP_INIT(num_private_stats, stats, setup);
588         LPROCFS_OBD_OP_INIT(num_private_stats, stats, postsetup);
589         LPROCFS_OBD_OP_INIT(num_private_stats, stats, precleanup);
590         LPROCFS_OBD_OP_INIT(num_private_stats, stats, cleanup);
591         LPROCFS_OBD_OP_INIT(num_private_stats, stats, postrecov);
592         LPROCFS_OBD_OP_INIT(num_private_stats, stats, connect);
593         LPROCFS_OBD_OP_INIT(num_private_stats, stats, disconnect);
594         LPROCFS_OBD_OP_INIT(num_private_stats, stats, statfs);
595         LPROCFS_OBD_OP_INIT(num_private_stats, stats, packmd);
596         LPROCFS_OBD_OP_INIT(num_private_stats, stats, unpackmd);
597         LPROCFS_OBD_OP_INIT(num_private_stats, stats, preallocate);
598         LPROCFS_OBD_OP_INIT(num_private_stats, stats, create);
599         LPROCFS_OBD_OP_INIT(num_private_stats, stats, destroy);
600         LPROCFS_OBD_OP_INIT(num_private_stats, stats, setattr);
601         LPROCFS_OBD_OP_INIT(num_private_stats, stats, getattr);
602         LPROCFS_OBD_OP_INIT(num_private_stats, stats, getattr_async);
603         LPROCFS_OBD_OP_INIT(num_private_stats, stats, brw);
604         LPROCFS_OBD_OP_INIT(num_private_stats, stats, brw_async);
605         LPROCFS_OBD_OP_INIT(num_private_stats, stats, prep_async_page);
606         LPROCFS_OBD_OP_INIT(num_private_stats, stats, queue_async_io);
607         LPROCFS_OBD_OP_INIT(num_private_stats, stats, set_async_flags);
608         LPROCFS_OBD_OP_INIT(num_private_stats, stats, queue_sync_io);
609         LPROCFS_OBD_OP_INIT(num_private_stats, stats, trigger_sync_io);
610         LPROCFS_OBD_OP_INIT(num_private_stats, stats, teardown_async_page);
611         LPROCFS_OBD_OP_INIT(num_private_stats, stats, punch);
612         LPROCFS_OBD_OP_INIT(num_private_stats, stats, sync);
613         LPROCFS_OBD_OP_INIT(num_private_stats, stats, migrate);
614         LPROCFS_OBD_OP_INIT(num_private_stats, stats, copy);
615         LPROCFS_OBD_OP_INIT(num_private_stats, stats, iterate);
616         LPROCFS_OBD_OP_INIT(num_private_stats, stats, preprw);
617         LPROCFS_OBD_OP_INIT(num_private_stats, stats, commitrw);
618         LPROCFS_OBD_OP_INIT(num_private_stats, stats, enqueue);
619         LPROCFS_OBD_OP_INIT(num_private_stats, stats, match);
620         LPROCFS_OBD_OP_INIT(num_private_stats, stats, change_cbdata);
621         LPROCFS_OBD_OP_INIT(num_private_stats, stats, cancel);
622         LPROCFS_OBD_OP_INIT(num_private_stats, stats, cancel_unused);
623         LPROCFS_OBD_OP_INIT(num_private_stats, stats, san_preprw);
624         LPROCFS_OBD_OP_INIT(num_private_stats, stats, init_export);
625         LPROCFS_OBD_OP_INIT(num_private_stats, stats, destroy_export);
626         LPROCFS_OBD_OP_INIT(num_private_stats, stats, lock_contains);
627         LPROCFS_OBD_OP_INIT(num_private_stats, stats, llog_init); 
628         LPROCFS_OBD_OP_INIT(num_private_stats, stats, llog_finish); 
629         LPROCFS_OBD_OP_INIT(num_private_stats, stats, pin); 
630         LPROCFS_OBD_OP_INIT(num_private_stats, stats, unpin);
631         LPROCFS_OBD_OP_INIT(num_private_stats, stats, invalidate_import);
632         LPROCFS_OBD_OP_INIT(num_private_stats, stats, notify);
633         
634         for (i = num_private_stats; i < num_stats; i++) {
635                 /* If this LBUGs, it is likely that an obd
636                  * operation was added to struct obd_ops in
637                  * <linux/obd.h>, and that the corresponding line item
638                  * LPROCFS_OBD_OP_INIT(.., .., opname)
639                  * is missing from the list above. */
640                 if (stats->ls_percpu[0]->lp_cntr[i].lc_name == NULL) {
641                         CERROR("Missing obd_stat initializer obd_op "
642                                "operation at offset %d. Aborting.\n",
643                                i - num_private_stats);
644                         LBUG();
645                 }
646         }
647         rc = lprocfs_register_stats(obd->obd_proc_entry, "stats", stats);
648         if (rc < 0) {
649                 lprocfs_free_stats(stats);
650         } else {
651                 obd->obd_stats  = stats;
652                 obd->obd_cntr_base = num_private_stats;
653         }
654         return rc;
655 }
656
657 void lprocfs_free_obd_stats(struct obd_device *obd)
658 {
659         struct lprocfs_stats *stats = obd->obd_stats;
660
661         if (stats != NULL) {
662                 obd->obd_stats = NULL;
663                 lprocfs_free_stats(stats);
664         }
665 }
666
667 int lprocfs_write_helper(const char *buffer, unsigned long count,
668                          int *val)
669 {
670         char kernbuf[20], *end;
671         
672         if (count > (sizeof(kernbuf) - 1))
673                 return -EINVAL;
674
675         if (copy_from_user(kernbuf, buffer, count))
676                 return -EFAULT;
677
678         kernbuf[count] = '\0';
679
680         *val = simple_strtol(kernbuf, &end, 0);
681         if (kernbuf == end)
682                 return -EINVAL;
683
684         return 0;
685 }
686
687
688 #endif /* LPROCFS*/
689
690 EXPORT_SYMBOL(lprocfs_register);
691 EXPORT_SYMBOL(lprocfs_srch);
692 EXPORT_SYMBOL(lprocfs_remove);
693 EXPORT_SYMBOL(lprocfs_add_vars);
694 EXPORT_SYMBOL(lprocfs_obd_attach);
695 EXPORT_SYMBOL(lprocfs_obd_detach);
696 EXPORT_SYMBOL(lprocfs_alloc_stats);
697 EXPORT_SYMBOL(lprocfs_free_stats);
698 EXPORT_SYMBOL(lprocfs_register_stats);
699 EXPORT_SYMBOL(lprocfs_alloc_obd_stats);
700 EXPORT_SYMBOL(lprocfs_free_obd_stats);
701
702 EXPORT_SYMBOL(lprocfs_rd_u64);
703 EXPORT_SYMBOL(lprocfs_rd_uuid);
704 EXPORT_SYMBOL(lprocfs_rd_name);
705 EXPORT_SYMBOL(lprocfs_rd_fstype);
706 EXPORT_SYMBOL(lprocfs_rd_server_uuid);
707 EXPORT_SYMBOL(lprocfs_rd_conn_uuid);
708 EXPORT_SYMBOL(lprocfs_rd_numrefs);
709
710 EXPORT_SYMBOL(lprocfs_rd_blksize);
711 EXPORT_SYMBOL(lprocfs_rd_kbytestotal);
712 EXPORT_SYMBOL(lprocfs_rd_kbytesfree);
713 EXPORT_SYMBOL(lprocfs_rd_filestotal);
714 EXPORT_SYMBOL(lprocfs_rd_filesfree);
715 EXPORT_SYMBOL(lprocfs_rd_filegroups);
716
717 EXPORT_SYMBOL(lprocfs_write_helper);