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