1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002, 2003 Cluster File Systems, Inc.
5 * Author: Hariharan Thantry <thantry@users.sourceforge.net>
7 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
24 # define EXPORT_SYMTAB
26 #define DEBUG_SUBSYSTEM S_CLASS
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>
37 # include <linux/seq_file.h>
38 # include <asm/div64.h>
39 #else /* __KERNEL__ */
40 # include <liblustre.h>
43 #include <linux/obd_class.h>
44 #include <linux/lprocfs_status.h>
45 #include <linux/lustre_fsfilt.h>
47 #if defined(LPROCFS) && defined(__KERNEL__)
48 struct proc_dir_entry *lprocfs_srch(struct proc_dir_entry *head,
51 struct proc_dir_entry *temp;
57 while (temp != NULL) {
58 if (strcmp(temp->name, name) == 0)
66 /* lprocfs API calls */
67 int lprocfs_add_vars(struct proc_dir_entry *root, struct lprocfs_vars *list,
70 if (root == NULL || list == NULL)
73 while (list->name != NULL) {
74 struct proc_dir_entry *cur_root, *proc;
75 char *pathcopy, *cur, *next, pathbuf[64];
76 int pathsize = strlen(list->name) + 1;
81 /* need copy of path for strsep */
82 if (strlen(list->name) > sizeof(pathbuf) - 1) {
83 OBD_ALLOC(pathcopy, pathsize);
91 strcpy(pathcopy, list->name);
93 while (cur_root != NULL && (cur = strsep(&next, "/"))) {
94 if (*cur =='\0') /* skip double/trailing "/" */
97 proc = lprocfs_srch(cur_root, cur);
98 CDEBUG(D_OTHER, "cur_root=%s, cur=%s, next=%s, (%s)\n",
99 cur_root->name, cur, next,
100 (proc ? "exists" : "new"));
102 cur_root = (proc ? proc :
103 proc_mkdir(cur, cur_root));
104 } else if (proc == NULL) {
108 if (list->write_fptr)
110 proc = create_proc_entry(cur, mode, cur_root);
114 if (pathcopy != pathbuf)
115 OBD_FREE(pathcopy, pathsize);
117 if (cur_root == NULL || proc == NULL) {
118 CERROR("LprocFS: No memory to create /proc entry %s",
123 proc->read_proc = list->read_fptr;
124 proc->write_proc = list->write_fptr;
125 proc->data = (list->data ? list->data : data);
131 void lprocfs_remove(struct proc_dir_entry *root)
133 struct proc_dir_entry *temp = root;
134 struct proc_dir_entry *rm_entry;
135 struct proc_dir_entry *parent;
137 LASSERT(root != NULL);
138 parent = root->parent;
139 LASSERT(parent != NULL);
142 while (temp->subdir != NULL)
148 /* Memory corruption once caused this to fail, and
149 without this LASSERT we would loop here forever. */
150 LASSERTF(strlen(rm_entry->name) == rm_entry->namelen,
151 "0x%p %s/%s len %d\n", rm_entry, temp->name,
152 rm_entry->name, (int)strlen(rm_entry->name));
154 remove_proc_entry(rm_entry->name, rm_entry->parent);
160 struct proc_dir_entry *lprocfs_register(const char *name,
161 struct proc_dir_entry *parent,
162 struct lprocfs_vars *list, void *data)
164 struct proc_dir_entry *newchild;
166 newchild = lprocfs_srch(parent, name);
167 if (newchild != NULL) {
168 CERROR(" Lproc: Attempting to register %s more than once \n",
170 return ERR_PTR(-EALREADY);
173 newchild = proc_mkdir(name, parent);
174 if (newchild != NULL && list != NULL) {
175 int rc = lprocfs_add_vars(newchild, list, data);
177 lprocfs_remove(newchild);
184 /* Generic callbacks */
186 int lprocfs_rd_u64(char *page, char **start, off_t off,
187 int count, int *eof, void *data)
189 LASSERT(data != NULL);
191 return snprintf(page, count, LPU64"\n", *(__u64 *)data);
194 int lprocfs_rd_uuid(char *page, char **start, off_t off, int count,
195 int *eof, void *data)
197 struct obd_device *dev = (struct obd_device*)data;
199 LASSERT(dev != NULL);
201 return snprintf(page, count, "%s\n", dev->obd_uuid.uuid);
204 int lprocfs_rd_name(char *page, char **start, off_t off, int count,
205 int *eof, void* data)
207 struct obd_device *dev = (struct obd_device *)data;
209 LASSERT(dev != NULL);
210 LASSERT(dev->obd_name != NULL);
212 return snprintf(page, count, "%s\n", dev->obd_name);
215 int lprocfs_rd_fstype(char *page, char **start, off_t off, int count, int *eof,
218 struct obd_device *obd = (struct obd_device *)data;
220 LASSERT(obd != NULL);
221 LASSERT(obd->obd_fsops != NULL);
222 LASSERT(obd->obd_fsops->fs_type != NULL);
223 return snprintf(page, count, "%s\n", obd->obd_fsops->fs_type);
226 int lprocfs_rd_blksize(char *page, char **start, off_t off, int count,
227 int *eof, void *data)
229 struct obd_statfs osfs;
230 int rc = obd_statfs(data, &osfs, jiffies - HZ);
233 rc = snprintf(page, count, "%u\n", osfs.os_bsize);
238 int lprocfs_rd_kbytestotal(char *page, char **start, off_t off, int count,
239 int *eof, void *data)
241 struct obd_statfs osfs;
242 int rc = obd_statfs(data, &osfs, jiffies - HZ);
244 __u32 blk_size = osfs.os_bsize >> 10;
245 __u64 result = osfs.os_blocks;
247 while (blk_size >>= 1)
251 rc = snprintf(page, count, LPU64"\n", result);
256 int lprocfs_rd_kbytesfree(char *page, char **start, off_t off, int count,
257 int *eof, void *data)
259 struct obd_statfs osfs;
260 int rc = obd_statfs(data, &osfs, jiffies - HZ);
262 __u32 blk_size = osfs.os_bsize >> 10;
263 __u64 result = osfs.os_bfree;
265 while (blk_size >>= 1)
269 rc = snprintf(page, count, LPU64"\n", result);
274 int lprocfs_rd_kbytesavail(char *page, char **start, off_t off, int count,
275 int *eof, void *data)
277 struct obd_statfs osfs;
278 int rc = obd_statfs(data, &osfs, jiffies - HZ);
280 __u32 blk_size = osfs.os_bsize >> 10;
281 __u64 result = osfs.os_bavail;
283 while (blk_size >>= 1)
287 rc = snprintf(page, count, LPU64"\n", result);
292 int lprocfs_rd_filestotal(char *page, char **start, off_t off, int count,
293 int *eof, void *data)
295 struct obd_statfs osfs;
296 int rc = obd_statfs(data, &osfs, jiffies - HZ);
299 rc = snprintf(page, count, LPU64"\n", osfs.os_files);
305 int lprocfs_rd_filesfree(char *page, char **start, off_t off, int count,
306 int *eof, void *data)
308 struct obd_statfs osfs;
309 int rc = obd_statfs(data, &osfs, jiffies - HZ);
312 rc = snprintf(page, count, LPU64"\n", osfs.os_ffree);
317 int lprocfs_rd_server_uuid(char *page, char **start, off_t off, int count,
318 int *eof, void *data)
320 struct obd_device *obd = (struct obd_device *)data;
321 struct obd_import *imp;
322 char *imp_state_name = NULL;
324 LASSERT(obd != NULL);
325 imp = obd->u.cli.cl_import;
326 imp_state_name = ptlrpc_import_state_name(imp->imp_state);
328 return snprintf(page, count, "%s\t%s\n",
329 imp->imp_target_uuid.uuid, imp_state_name);
332 int lprocfs_rd_conn_uuid(char *page, char **start, off_t off, int count,
333 int *eof, void *data)
335 struct obd_device *obd = (struct obd_device*)data;
336 struct ptlrpc_connection *conn;
338 LASSERT(obd != NULL);
339 conn = obd->u.cli.cl_import->imp_connection;
340 LASSERT(conn != NULL);
342 return snprintf(page, count, "%s\n", conn->c_remote_uuid.uuid);
345 int lprocfs_rd_num_exports(char *page, char **start, off_t off, int count,
346 int *eof, void *data)
348 struct obd_device *obd = (struct obd_device*)data;
350 LASSERT(obd != NULL);
352 return snprintf(page, count, "%u\n", obd->obd_num_exports);
355 int lprocfs_rd_numrefs(char *page, char **start, off_t off, int count,
356 int *eof, void *data)
358 struct obd_type *class = (struct obd_type*) data;
360 LASSERT(class != NULL);
362 return snprintf(page, count, "%d\n", class->typ_refcnt);
365 int lprocfs_obd_attach(struct obd_device *dev, struct lprocfs_vars *list)
369 LASSERT(dev != NULL);
370 LASSERT(dev->obd_type != NULL);
371 LASSERT(dev->obd_type->typ_procroot != NULL);
373 dev->obd_proc_entry = lprocfs_register(dev->obd_name,
374 dev->obd_type->typ_procroot,
376 if (IS_ERR(dev->obd_proc_entry)) {
377 rc = PTR_ERR(dev->obd_proc_entry);
378 dev->obd_proc_entry = NULL;
383 int lprocfs_obd_detach(struct obd_device *dev)
385 if (dev && dev->obd_proc_entry) {
386 lprocfs_remove(dev->obd_proc_entry);
387 dev->obd_proc_entry = NULL;
392 struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num)
394 struct lprocfs_stats *stats;
395 struct lprocfs_percpu *percpu;
396 unsigned int percpusize;
402 OBD_ALLOC(stats, offsetof(typeof(*stats), ls_percpu[num_online_cpus()]));
406 percpusize = L1_CACHE_ALIGN(offsetof(typeof(*percpu), lp_cntr[num]));
407 stats->ls_percpu_size = num_online_cpus() * percpusize;
408 OBD_ALLOC(stats->ls_percpu[0], stats->ls_percpu_size);
409 if (stats->ls_percpu[0] == NULL) {
410 OBD_FREE(stats, offsetof(typeof(*stats),
411 ls_percpu[num_online_cpus()]));
416 for (i = 1; i < num_online_cpus(); i++)
417 stats->ls_percpu[i] = (void *)(stats->ls_percpu[i - 1]) +
423 void lprocfs_free_stats(struct lprocfs_stats *stats)
425 if (stats->ls_num == 0)
428 OBD_FREE(stats->ls_percpu[0], stats->ls_percpu_size);
429 OBD_FREE(stats, offsetof(typeof(*stats), ls_percpu[num_online_cpus()]));
432 /* Reset counter under lock */
433 int lprocfs_counter_write(struct file *file, const char *buffer,
434 unsigned long count, void *data)
440 static void *lprocfs_stats_seq_start(struct seq_file *p, loff_t *pos)
442 struct lprocfs_stats *stats = p->private;
443 /* return 1st cpu location */
444 return (*pos >= stats->ls_num) ? NULL :
445 &(stats->ls_percpu[0]->lp_cntr[*pos]);
448 static void lprocfs_stats_seq_stop(struct seq_file *p, void *v)
452 static void *lprocfs_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
454 struct lprocfs_stats *stats = p->private;
456 return (*pos >= stats->ls_num) ? NULL :
457 &(stats->ls_percpu[0]->lp_cntr[*pos]);
460 /* seq file export of one lprocfs counter */
461 static int lprocfs_stats_seq_show(struct seq_file *p, void *v)
463 struct lprocfs_stats *stats = p->private;
464 struct lprocfs_counter *cntr = v;
465 struct lprocfs_counter t, ret = { .lc_min = ~(__u64)0 };
468 if (cntr == &(stats->ls_percpu[0])->lp_cntr[0]) {
470 do_gettimeofday(&now);
471 rc = seq_printf(p, "%-25s %lu.%lu secs.usecs\n",
472 "snapshot_time", now.tv_sec, now.tv_usec);
476 idx = cntr - &(stats->ls_percpu[0])->lp_cntr[0];
478 for (i = 0; i < num_online_cpus(); i++) {
479 struct lprocfs_counter *percpu_cntr =
480 &(stats->ls_percpu[i])->lp_cntr[idx];
484 centry = atomic_read(&percpu_cntr->lc_cntl.la_entry);
485 t.lc_count = percpu_cntr->lc_count;
486 t.lc_sum = percpu_cntr->lc_sum;
487 t.lc_min = percpu_cntr->lc_min;
488 t.lc_max = percpu_cntr->lc_max;
489 t.lc_sumsquare = percpu_cntr->lc_sumsquare;
490 } while (centry != atomic_read(&percpu_cntr->lc_cntl.la_entry) &&
491 centry != atomic_read(&percpu_cntr->lc_cntl.la_exit));
492 ret.lc_count += t.lc_count;
493 ret.lc_sum += t.lc_sum;
494 if (t.lc_min < ret.lc_min)
495 ret.lc_min = t.lc_min;
496 if (t.lc_max > ret.lc_max)
497 ret.lc_max = t.lc_max;
498 ret.lc_sumsquare += t.lc_sumsquare;
501 rc = seq_printf(p, "%-25s "LPU64" samples [%s]", cntr->lc_name,
502 ret.lc_count, cntr->lc_units);
506 if ((cntr->lc_config & LPROCFS_CNTR_AVGMINMAX) && (ret.lc_count > 0)) {
507 rc = seq_printf(p, " "LPU64" "LPU64" "LPU64,
508 ret.lc_min, ret.lc_max, ret.lc_sum);
511 if (cntr->lc_config & LPROCFS_CNTR_STDDEV)
512 rc = seq_printf(p, " "LPU64, ret.lc_sumsquare);
516 rc = seq_printf(p, "\n");
518 return (rc < 0) ? rc : 0;
521 struct seq_operations lprocfs_stats_seq_sops = {
522 start: lprocfs_stats_seq_start,
523 stop: lprocfs_stats_seq_stop,
524 next: lprocfs_stats_seq_next,
525 show: lprocfs_stats_seq_show,
528 static int lprocfs_stats_seq_open(struct inode *inode, struct file *file)
530 struct proc_dir_entry *dp = PDE(inode);
531 struct seq_file *seq;
534 rc = seq_open(file, &lprocfs_stats_seq_sops);
537 seq = file->private_data;
538 seq->private = dp->data;
542 struct file_operations lprocfs_stats_seq_fops = {
543 .owner = THIS_MODULE,
544 .open = lprocfs_stats_seq_open,
547 .release = seq_release,
550 int lprocfs_register_stats(struct proc_dir_entry *root,
552 struct lprocfs_stats *stats)
554 struct proc_dir_entry *entry;
555 LASSERT(root != NULL);
557 entry = create_proc_entry(name, 0444, root);
560 entry->proc_fops = &lprocfs_stats_seq_fops;
561 entry->data = (void *)stats;
562 entry->write_proc = lprocfs_counter_write;
566 void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
567 unsigned conf, const char *name,
570 struct lprocfs_counter *c;
573 LASSERT(stats != NULL);
574 for (i = 0; i < num_online_cpus(); i++) {
575 c = &(stats->ls_percpu[i]->lp_cntr[index]);
577 c->lc_min = ~(__u64)0;
582 EXPORT_SYMBOL(lprocfs_counter_init);
584 #define LPROCFS_OBD_OP_INIT(base, stats, op) \
586 unsigned int coffset = base + OBD_COUNTER_OFFSET(op); \
587 LASSERT(coffset < stats->ls_num); \
588 lprocfs_counter_init(stats, coffset, 0, #op, "reqs"); \
591 int lprocfs_alloc_obd_stats(struct obd_device *obd,
592 unsigned num_private_stats)
594 struct lprocfs_stats *stats;
595 unsigned int num_stats;
598 LASSERT(obd->obd_stats == NULL);
599 LASSERT(obd->obd_proc_entry != NULL);
600 LASSERT(obd->obd_cntr_base == 0);
602 num_stats = 1 + OBD_COUNTER_OFFSET(init_ea_size) +
604 stats = lprocfs_alloc_stats(num_stats);
608 LPROCFS_OBD_OP_INIT(num_private_stats, stats, iocontrol);
609 LPROCFS_OBD_OP_INIT(num_private_stats, stats, get_info);
610 LPROCFS_OBD_OP_INIT(num_private_stats, stats, set_info);
611 LPROCFS_OBD_OP_INIT(num_private_stats, stats, attach);
612 LPROCFS_OBD_OP_INIT(num_private_stats, stats, detach);
613 LPROCFS_OBD_OP_INIT(num_private_stats, stats, setup);
614 LPROCFS_OBD_OP_INIT(num_private_stats, stats, precleanup);
615 LPROCFS_OBD_OP_INIT(num_private_stats, stats, cleanup);
616 LPROCFS_OBD_OP_INIT(num_private_stats, stats, process_config);
617 LPROCFS_OBD_OP_INIT(num_private_stats, stats, postrecov);
618 LPROCFS_OBD_OP_INIT(num_private_stats, stats, add_conn);
619 LPROCFS_OBD_OP_INIT(num_private_stats, stats, del_conn);
620 LPROCFS_OBD_OP_INIT(num_private_stats, stats, connect);
621 LPROCFS_OBD_OP_INIT(num_private_stats, stats, connect_post);
622 LPROCFS_OBD_OP_INIT(num_private_stats, stats, disconnect);
623 LPROCFS_OBD_OP_INIT(num_private_stats, stats, statfs);
624 LPROCFS_OBD_OP_INIT(num_private_stats, stats, packmd);
625 LPROCFS_OBD_OP_INIT(num_private_stats, stats, unpackmd);
626 LPROCFS_OBD_OP_INIT(num_private_stats, stats, revalidate_md);
627 LPROCFS_OBD_OP_INIT(num_private_stats, stats, preallocate);
628 LPROCFS_OBD_OP_INIT(num_private_stats, stats, create);
629 LPROCFS_OBD_OP_INIT(num_private_stats, stats, destroy);
630 LPROCFS_OBD_OP_INIT(num_private_stats, stats, setattr);
631 LPROCFS_OBD_OP_INIT(num_private_stats, stats, getattr);
632 LPROCFS_OBD_OP_INIT(num_private_stats, stats, getattr_async);
633 LPROCFS_OBD_OP_INIT(num_private_stats, stats, brw);
634 LPROCFS_OBD_OP_INIT(num_private_stats, stats, brw_async);
635 LPROCFS_OBD_OP_INIT(num_private_stats, stats, prep_async_page);
636 LPROCFS_OBD_OP_INIT(num_private_stats, stats, queue_async_io);
637 LPROCFS_OBD_OP_INIT(num_private_stats, stats, set_async_flags);
638 LPROCFS_OBD_OP_INIT(num_private_stats, stats, queue_group_io);
639 LPROCFS_OBD_OP_INIT(num_private_stats, stats, trigger_group_io);
640 LPROCFS_OBD_OP_INIT(num_private_stats, stats, teardown_async_page);
641 LPROCFS_OBD_OP_INIT(num_private_stats, stats, adjust_kms);
642 LPROCFS_OBD_OP_INIT(num_private_stats, stats, punch);
643 LPROCFS_OBD_OP_INIT(num_private_stats, stats, sync);
644 LPROCFS_OBD_OP_INIT(num_private_stats, stats, migrate);
645 LPROCFS_OBD_OP_INIT(num_private_stats, stats, copy);
646 LPROCFS_OBD_OP_INIT(num_private_stats, stats, iterate);
647 LPROCFS_OBD_OP_INIT(num_private_stats, stats, preprw);
648 LPROCFS_OBD_OP_INIT(num_private_stats, stats, commitrw);
649 LPROCFS_OBD_OP_INIT(num_private_stats, stats, do_cow);
650 LPROCFS_OBD_OP_INIT(num_private_stats, stats, write_extents);
651 LPROCFS_OBD_OP_INIT(num_private_stats, stats, enqueue);
652 LPROCFS_OBD_OP_INIT(num_private_stats, stats, match);
653 LPROCFS_OBD_OP_INIT(num_private_stats, stats, change_cbdata);
654 LPROCFS_OBD_OP_INIT(num_private_stats, stats, cancel);
655 LPROCFS_OBD_OP_INIT(num_private_stats, stats, cancel_unused);
656 LPROCFS_OBD_OP_INIT(num_private_stats, stats, san_preprw);
657 LPROCFS_OBD_OP_INIT(num_private_stats, stats, init_export);
658 LPROCFS_OBD_OP_INIT(num_private_stats, stats, destroy_export);
659 LPROCFS_OBD_OP_INIT(num_private_stats, stats, llog_init);
660 LPROCFS_OBD_OP_INIT(num_private_stats, stats, llog_finish);
661 LPROCFS_OBD_OP_INIT(num_private_stats, stats, llog_connect);
662 LPROCFS_OBD_OP_INIT(num_private_stats, stats, pin);
663 LPROCFS_OBD_OP_INIT(num_private_stats, stats, unpin);
664 LPROCFS_OBD_OP_INIT(num_private_stats, stats, import_event);
665 LPROCFS_OBD_OP_INIT(num_private_stats, stats, notify);
666 LPROCFS_OBD_OP_INIT(num_private_stats, stats, getready);
667 LPROCFS_OBD_OP_INIT(num_private_stats, stats, init_ea_size);
669 for (i = num_private_stats; i < num_stats; i++) {
670 /* if this LBUGs, it is likely that an obd operation was added
671 * to struct obd_ops in <linux/obd.h>, and that the
672 * corresponding line item LPROCFS_OBD_OP_INIT(.., .., opname)
673 * is missing from the list above. */
674 if (stats->ls_percpu[0]->lp_cntr[i].lc_name == NULL) {
675 CERROR("Missing obd_stat initializer obd_op "
676 "operation at offset %d. Aborting.\n",
677 i - num_private_stats);
681 rc = lprocfs_register_stats(obd->obd_proc_entry, "stats", stats);
683 lprocfs_free_stats(stats);
685 obd->obd_stats = stats;
686 obd->obd_cntr_base = num_private_stats;
691 void lprocfs_free_obd_stats(struct obd_device *obd)
693 struct lprocfs_stats *stats = obd->obd_stats;
696 obd->obd_stats = NULL;
697 lprocfs_free_stats(stats);
701 #define LPROCFS_MD_OP_INIT(base, stats, op) \
703 unsigned int coffset = base + MD_COUNTER_OFFSET(op); \
704 LASSERT(coffset < stats->ls_num); \
705 lprocfs_counter_init(stats, coffset, 0, #op, "reqs"); \
708 int lprocfs_alloc_md_stats(struct obd_device *obd,
709 unsigned num_private_stats)
711 struct lprocfs_stats *stats;
712 unsigned int num_stats;
715 LASSERT(obd->md_stats == NULL);
716 LASSERT(obd->obd_proc_entry != NULL);
717 LASSERT(obd->md_cntr_base == 0);
719 num_stats = 1 + MD_COUNTER_OFFSET(delete_inode) +
721 stats = lprocfs_alloc_stats(num_stats);
725 LPROCFS_MD_OP_INIT(num_private_stats, stats, getstatus);
726 LPROCFS_MD_OP_INIT(num_private_stats, stats, change_cbdata);
727 LPROCFS_MD_OP_INIT(num_private_stats, stats, change_cbdata_name);
728 LPROCFS_MD_OP_INIT(num_private_stats, stats, close);
729 LPROCFS_MD_OP_INIT(num_private_stats, stats, create);
730 LPROCFS_MD_OP_INIT(num_private_stats, stats, done_writing);
731 LPROCFS_MD_OP_INIT(num_private_stats, stats, enqueue);
732 LPROCFS_MD_OP_INIT(num_private_stats, stats, getattr);
733 LPROCFS_MD_OP_INIT(num_private_stats, stats, getattr_lock);
734 LPROCFS_MD_OP_INIT(num_private_stats, stats, intent_lock);
735 LPROCFS_MD_OP_INIT(num_private_stats, stats, link);
736 LPROCFS_MD_OP_INIT(num_private_stats, stats, rename);
737 LPROCFS_MD_OP_INIT(num_private_stats, stats, setattr);
738 LPROCFS_MD_OP_INIT(num_private_stats, stats, sync);
739 LPROCFS_MD_OP_INIT(num_private_stats, stats, readpage);
740 LPROCFS_MD_OP_INIT(num_private_stats, stats, unlink);
741 LPROCFS_MD_OP_INIT(num_private_stats, stats, valid_attrs);
742 LPROCFS_MD_OP_INIT(num_private_stats, stats, get_real_obd);
743 LPROCFS_MD_OP_INIT(num_private_stats, stats, req2lustre_md);
744 LPROCFS_MD_OP_INIT(num_private_stats, stats, set_open_replay_data);
745 LPROCFS_MD_OP_INIT(num_private_stats, stats, clear_open_replay_data);
746 LPROCFS_MD_OP_INIT(num_private_stats, stats, store_inode_generation);
747 LPROCFS_MD_OP_INIT(num_private_stats, stats, set_lock_data);
748 LPROCFS_MD_OP_INIT(num_private_stats, stats, delete_inode);
750 for (i = num_private_stats; i < num_stats; i++) {
751 if (stats->ls_percpu[0]->lp_cntr[i].lc_name == NULL) {
752 CERROR("Missing md_stat initializer md_op "
753 "operation at offset %d. Aborting.\n",
754 i - num_private_stats);
758 rc = lprocfs_register_stats(obd->obd_proc_entry, "stats", stats);
760 lprocfs_free_stats(stats);
762 obd->md_stats = stats;
763 obd->md_cntr_base = num_private_stats;
768 void lprocfs_free_md_stats(struct obd_device *obd)
770 struct lprocfs_stats *stats = obd->md_stats;
773 obd->md_stats = NULL;
774 lprocfs_free_stats(stats);
778 int lprocfs_write_helper(const char *buffer, unsigned long count,
781 char kernbuf[20], *end;
783 if (count > (sizeof(kernbuf) - 1))
786 if (copy_from_user(kernbuf, buffer, count))
789 kernbuf[count] = '\0';
791 *val = simple_strtol(kernbuf, &end, 0);
798 int lprocfs_write_u64_helper(const char *buffer, unsigned long count,
801 char kernbuf[22], *end;
803 if (count > (sizeof(kernbuf) - 1))
806 if (copy_from_user(kernbuf, buffer, count))
809 kernbuf[count] = '\0';
811 if (kernbuf[0] == '-')
812 *val = -simple_strtoull(kernbuf + 1, &end, 0);
814 *val = simple_strtoull(kernbuf, &end, 0);
821 int lprocfs_obd_seq_create(struct obd_device *dev, char *name, mode_t mode,
822 struct file_operations *seq_fops, void *data)
824 struct proc_dir_entry *entry;
827 entry = create_proc_entry(name, mode, dev->obd_proc_entry);
830 entry->proc_fops = seq_fops;
835 EXPORT_SYMBOL(lprocfs_obd_seq_create);
837 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
841 if (value >= OBD_HIST_MAX)
842 value = OBD_HIST_MAX - 1;
844 spin_lock_irqsave(&oh->oh_lock, flags);
845 oh->oh_buckets[value]++;
846 spin_unlock_irqrestore(&oh->oh_lock, flags);
848 EXPORT_SYMBOL(lprocfs_oh_tally);
850 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
854 for (val = 0; ((1 << val) < value) && (val <= OBD_HIST_MAX); val++)
857 lprocfs_oh_tally(oh, val);
859 EXPORT_SYMBOL(lprocfs_oh_tally_log2);
861 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
863 unsigned long ret = 0;
866 for (i = 0; i < OBD_HIST_MAX; i++)
867 ret += oh->oh_buckets[i];
870 EXPORT_SYMBOL(lprocfs_oh_sum);
872 void lprocfs_oh_clear(struct obd_histogram *oh)
875 spin_lock_irqsave(&oh->oh_lock, flags);
876 memset(oh->oh_buckets, 0, sizeof(oh->oh_buckets));
877 spin_unlock_irqrestore(&oh->oh_lock, flags);
879 EXPORT_SYMBOL(lprocfs_oh_clear);
881 /* XXX copied from ldlm/ldlm_lockd.c, copied from ptlrpc/service.c */
882 static long timeval_sub(struct timeval *large, struct timeval *small)
884 return ((large->tv_sec - small->tv_sec) * 1000000) +
885 (large->tv_usec - small->tv_usec);
888 void lprocfs_stime_record(struct obd_service_time *stime, struct timeval *large,
889 struct timeval *small)
891 long diff = timeval_sub(large, small);
897 stime->st_total_us += diff;
899 EXPORT_SYMBOL(lprocfs_stime_record);
901 unsigned long lprocfs_stime_avg_ms(struct obd_service_time *stime)
903 struct obd_service_time copy;
905 memcpy(©, stime, sizeof(copy));
906 if (copy.st_num > 0) {
907 do_div(copy.st_total_us, copy.st_num * 1000);
908 return (unsigned long)copy.st_total_us;
912 EXPORT_SYMBOL(lprocfs_stime_avg_ms);
914 unsigned long lprocfs_stime_avg_us(struct obd_service_time *stime)
916 struct obd_service_time copy;
919 memcpy(©, stime, sizeof(copy));
920 if (copy.st_num > 0) {
921 do_div(copy.st_total_us, copy.st_num);
922 remainder = do_div(copy.st_total_us, 1000);
923 return (unsigned long)remainder;
927 EXPORT_SYMBOL(lprocfs_stime_avg_us);
929 int lprocfs_obd_rd_recovery_status(char *page, char **start, off_t off,
930 int count, int *eof, void *data)
932 struct obd_device *obd = data;
934 connected = obd->obd_connected_clients,
935 max_recoverable = obd->obd_max_recoverable_clients,
936 recoverable = obd->obd_recoverable_clients,
937 completed = max_recoverable - recoverable,
938 queue_len = obd->obd_requests_queued_for_recovery,
939 replayed = obd->obd_replayed_requests;
940 __u64 next_transno = obd->obd_next_recovery_transno;
942 LASSERT(obd != NULL);
945 n = snprintf(page, count, "status: ");
946 page += n; len += n; count -= n;
947 if (obd->obd_max_recoverable_clients == 0) {
948 n = snprintf(page, count, "INACTIVE\n");
952 /* sampled unlocked, but really... */
953 if (obd->obd_recovering == 0) {
954 n = snprintf(page, count, "COMPLETE\n");
955 page += n; len += n; count -= n;
957 n = snprintf(page, count, "recovery_start: %lu\n",
958 obd->obd_recovery_start);
959 page += n; len += n; count -= n;
960 n = snprintf(page, count, "recovery_end: %lu\n",
961 obd->obd_recovery_end);
962 page += n; len += n; count -= n;
963 n = snprintf(page, count, "recovered_clients: %d\n",
965 page += n; len += n; count -= n;
966 n = snprintf(page, count, "unrecovered_clients: %d\n",
967 obd->obd_recoverable_clients);
968 page += n; len += n; count -= n;
969 n = snprintf(page, count, "last_transno: "LPD64"\n",
971 page += n; len += n; count -= n;
972 n = snprintf(page, count, "replayed_requests: %d\n", replayed);
976 n = snprintf(page, count, "RECOVERING\n");
977 page += n; len += n; count -= n;
978 n = snprintf(page, count, "recovery_start: %lu\n",
979 obd->obd_recovery_start);
980 page += n; len += n; count -= n;
981 n = snprintf(page, count, "connected_clients: %d/%d\n",
982 connected, max_recoverable);
983 page += n; len += n; count -= n;
984 n = snprintf(page, count, "completed_clients: %d/%d\n",
985 completed, max_recoverable);
986 page += n; len += n; count -= n;
987 n = snprintf(page, count, "replayed_requests: %d/??\n", replayed);
988 page += n; len += n; count -= n;
989 n = snprintf(page, count, "queued_requests: %d\n", queue_len);
990 page += n; len += n; count -= n;
991 n = snprintf(page, count, "next_transno: "LPD64"\n", next_transno);
994 EXPORT_SYMBOL(lprocfs_obd_rd_recovery_status);
997 EXPORT_SYMBOL(lprocfs_register);
998 EXPORT_SYMBOL(lprocfs_srch);
999 EXPORT_SYMBOL(lprocfs_remove);
1000 EXPORT_SYMBOL(lprocfs_add_vars);
1001 EXPORT_SYMBOL(lprocfs_obd_attach);
1002 EXPORT_SYMBOL(lprocfs_obd_detach);
1003 EXPORT_SYMBOL(lprocfs_alloc_stats);
1004 EXPORT_SYMBOL(lprocfs_free_stats);
1005 EXPORT_SYMBOL(lprocfs_register_stats);
1006 EXPORT_SYMBOL(lprocfs_alloc_obd_stats);
1007 EXPORT_SYMBOL(lprocfs_free_obd_stats);
1008 EXPORT_SYMBOL(lprocfs_alloc_md_stats);
1009 EXPORT_SYMBOL(lprocfs_free_md_stats);
1011 EXPORT_SYMBOL(lprocfs_rd_u64);
1012 EXPORT_SYMBOL(lprocfs_rd_uuid);
1013 EXPORT_SYMBOL(lprocfs_rd_name);
1014 EXPORT_SYMBOL(lprocfs_rd_fstype);
1015 EXPORT_SYMBOL(lprocfs_rd_server_uuid);
1016 EXPORT_SYMBOL(lprocfs_rd_conn_uuid);
1017 EXPORT_SYMBOL(lprocfs_rd_num_exports);
1018 EXPORT_SYMBOL(lprocfs_rd_numrefs);
1020 EXPORT_SYMBOL(lprocfs_rd_blksize);
1021 EXPORT_SYMBOL(lprocfs_rd_kbytestotal);
1022 EXPORT_SYMBOL(lprocfs_rd_kbytesfree);
1023 EXPORT_SYMBOL(lprocfs_rd_kbytesavail);
1024 EXPORT_SYMBOL(lprocfs_rd_filestotal);
1025 EXPORT_SYMBOL(lprocfs_rd_filesfree);
1027 EXPORT_SYMBOL(lprocfs_write_helper);
1028 EXPORT_SYMBOL(lprocfs_write_u64_helper);