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, const char *name,
551 struct lprocfs_stats *stats)
553 struct proc_dir_entry *entry;
554 LASSERT(root != NULL);
556 entry = create_proc_entry(name, 0444, root);
559 entry->proc_fops = &lprocfs_stats_seq_fops;
560 entry->data = (void *)stats;
561 entry->write_proc = lprocfs_counter_write;
565 void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
566 unsigned conf, const char *name, const char *units)
568 struct lprocfs_counter *c;
571 LASSERT(stats != NULL);
572 for (i = 0; i < num_online_cpus(); i++) {
573 c = &(stats->ls_percpu[i]->lp_cntr[index]);
575 c->lc_min = ~(__u64)0;
580 EXPORT_SYMBOL(lprocfs_counter_init);
582 #define LPROCFS_OBD_OP_INIT(base, stats, op) \
584 unsigned int coffset = base + OBD_COUNTER_OFFSET(op); \
585 LASSERT(coffset < stats->ls_num); \
586 lprocfs_counter_init(stats, coffset, 0, #op, "reqs"); \
589 int lprocfs_alloc_obd_stats(struct obd_device *obd, unsigned num_private_stats)
591 struct lprocfs_stats *stats;
592 unsigned int num_stats;
595 LASSERT(obd->obd_stats == NULL);
596 LASSERT(obd->obd_proc_entry != NULL);
597 LASSERT(obd->obd_cntr_base == 0);
599 num_stats = 1 + OBD_COUNTER_OFFSET(init_ea_size) +
601 stats = lprocfs_alloc_stats(num_stats);
605 LPROCFS_OBD_OP_INIT(num_private_stats, stats, iocontrol);
606 LPROCFS_OBD_OP_INIT(num_private_stats, stats, get_info);
607 LPROCFS_OBD_OP_INIT(num_private_stats, stats, set_info);
608 LPROCFS_OBD_OP_INIT(num_private_stats, stats, attach);
609 LPROCFS_OBD_OP_INIT(num_private_stats, stats, detach);
610 LPROCFS_OBD_OP_INIT(num_private_stats, stats, setup);
611 LPROCFS_OBD_OP_INIT(num_private_stats, stats, precleanup);
612 LPROCFS_OBD_OP_INIT(num_private_stats, stats, cleanup);
613 LPROCFS_OBD_OP_INIT(num_private_stats, stats, process_config);
614 LPROCFS_OBD_OP_INIT(num_private_stats, stats, postrecov);
615 LPROCFS_OBD_OP_INIT(num_private_stats, stats, add_conn);
616 LPROCFS_OBD_OP_INIT(num_private_stats, stats, del_conn);
617 LPROCFS_OBD_OP_INIT(num_private_stats, stats, connect);
618 LPROCFS_OBD_OP_INIT(num_private_stats, stats, connect_post);
619 LPROCFS_OBD_OP_INIT(num_private_stats, stats, disconnect);
620 LPROCFS_OBD_OP_INIT(num_private_stats, stats, statfs);
621 LPROCFS_OBD_OP_INIT(num_private_stats, stats, packmd);
622 LPROCFS_OBD_OP_INIT(num_private_stats, stats, unpackmd);
623 LPROCFS_OBD_OP_INIT(num_private_stats, stats, revalidate_md);
624 LPROCFS_OBD_OP_INIT(num_private_stats, stats, preallocate);
625 LPROCFS_OBD_OP_INIT(num_private_stats, stats, create);
626 LPROCFS_OBD_OP_INIT(num_private_stats, stats, destroy);
627 LPROCFS_OBD_OP_INIT(num_private_stats, stats, setattr);
628 LPROCFS_OBD_OP_INIT(num_private_stats, stats, getattr);
629 LPROCFS_OBD_OP_INIT(num_private_stats, stats, getattr_async);
630 LPROCFS_OBD_OP_INIT(num_private_stats, stats, brw);
631 LPROCFS_OBD_OP_INIT(num_private_stats, stats, brw_async);
632 LPROCFS_OBD_OP_INIT(num_private_stats, stats, prep_async_page);
633 LPROCFS_OBD_OP_INIT(num_private_stats, stats, queue_async_io);
634 LPROCFS_OBD_OP_INIT(num_private_stats, stats, set_async_flags);
635 LPROCFS_OBD_OP_INIT(num_private_stats, stats, queue_group_io);
636 LPROCFS_OBD_OP_INIT(num_private_stats, stats, trigger_group_io);
637 LPROCFS_OBD_OP_INIT(num_private_stats, stats, teardown_async_page);
638 LPROCFS_OBD_OP_INIT(num_private_stats, stats, punch);
639 LPROCFS_OBD_OP_INIT(num_private_stats, stats, sync);
640 LPROCFS_OBD_OP_INIT(num_private_stats, stats, migrate);
641 LPROCFS_OBD_OP_INIT(num_private_stats, stats, copy);
642 LPROCFS_OBD_OP_INIT(num_private_stats, stats, iterate);
643 LPROCFS_OBD_OP_INIT(num_private_stats, stats, preprw);
644 LPROCFS_OBD_OP_INIT(num_private_stats, stats, commitrw);
645 LPROCFS_OBD_OP_INIT(num_private_stats, stats, do_cow);
646 LPROCFS_OBD_OP_INIT(num_private_stats, stats, write_extents);
647 LPROCFS_OBD_OP_INIT(num_private_stats, stats, enqueue);
648 LPROCFS_OBD_OP_INIT(num_private_stats, stats, match);
649 LPROCFS_OBD_OP_INIT(num_private_stats, stats, change_cbdata);
650 LPROCFS_OBD_OP_INIT(num_private_stats, stats, cancel);
651 LPROCFS_OBD_OP_INIT(num_private_stats, stats, cancel_unused);
652 LPROCFS_OBD_OP_INIT(num_private_stats, stats, san_preprw);
653 LPROCFS_OBD_OP_INIT(num_private_stats, stats, init_export);
654 LPROCFS_OBD_OP_INIT(num_private_stats, stats, destroy_export);
655 LPROCFS_OBD_OP_INIT(num_private_stats, stats, llog_init);
656 LPROCFS_OBD_OP_INIT(num_private_stats, stats, llog_finish);
657 LPROCFS_OBD_OP_INIT(num_private_stats, stats, llog_connect);
658 LPROCFS_OBD_OP_INIT(num_private_stats, stats, pin);
659 LPROCFS_OBD_OP_INIT(num_private_stats, stats, unpin);
660 LPROCFS_OBD_OP_INIT(num_private_stats, stats, import_event);
661 LPROCFS_OBD_OP_INIT(num_private_stats, stats, notify);
662 LPROCFS_OBD_OP_INIT(num_private_stats, stats, getready);
663 LPROCFS_OBD_OP_INIT(num_private_stats, stats, init_ea_size);
665 for (i = num_private_stats; i < num_stats; i++) {
666 /* if this LBUGs, it is likely that an obd operation was added
667 * to struct obd_ops in <linux/obd.h>, and that the
668 * corresponding line item LPROCFS_OBD_OP_INIT(.., .., opname)
669 * is missing from the list above. */
670 if (stats->ls_percpu[0]->lp_cntr[i].lc_name == NULL) {
671 CERROR("Missing obd_stat initializer obd_op "
672 "operation at offset %d. Aborting.\n",
673 i - num_private_stats);
677 rc = lprocfs_register_stats(obd->obd_proc_entry, "stats", stats);
679 lprocfs_free_stats(stats);
681 obd->obd_stats = stats;
682 obd->obd_cntr_base = num_private_stats;
687 void lprocfs_free_obd_stats(struct obd_device *obd)
689 struct lprocfs_stats *stats = obd->obd_stats;
692 obd->obd_stats = NULL;
693 lprocfs_free_stats(stats);
697 int lprocfs_write_helper(const char *buffer, unsigned long count,
700 char kernbuf[20], *end;
702 if (count > (sizeof(kernbuf) - 1))
705 if (copy_from_user(kernbuf, buffer, count))
708 kernbuf[count] = '\0';
710 *val = simple_strtol(kernbuf, &end, 0);
717 int lprocfs_write_u64_helper(const char *buffer, unsigned long count,
720 char kernbuf[22], *end;
722 if (count > (sizeof(kernbuf) - 1))
725 if (copy_from_user(kernbuf, buffer, count))
728 kernbuf[count] = '\0';
730 *val = simple_strtoull(kernbuf, &end, 0);
737 int lprocfs_obd_seq_create(struct obd_device *dev, char *name, mode_t mode,
738 struct file_operations *seq_fops, void *data)
740 struct proc_dir_entry *entry;
743 entry = create_proc_entry(name, mode, dev->obd_proc_entry);
746 entry->proc_fops = seq_fops;
751 EXPORT_SYMBOL(lprocfs_obd_seq_create);
753 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
757 if (value >= OBD_HIST_MAX)
758 value = OBD_HIST_MAX - 1;
760 spin_lock_irqsave(&oh->oh_lock, flags);
761 oh->oh_buckets[value]++;
762 spin_unlock_irqrestore(&oh->oh_lock, flags);
764 EXPORT_SYMBOL(lprocfs_oh_tally);
766 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
770 for (val = 0; ((1 << val) < value) && (val <= OBD_HIST_MAX); val++)
773 lprocfs_oh_tally(oh, val);
775 EXPORT_SYMBOL(lprocfs_oh_tally_log2);
777 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
779 unsigned long ret = 0;
782 for (i = 0; i < OBD_HIST_MAX; i++)
783 ret += oh->oh_buckets[i];
786 EXPORT_SYMBOL(lprocfs_oh_sum);
788 void lprocfs_oh_clear(struct obd_histogram *oh)
791 spin_lock_irqsave(&oh->oh_lock, flags);
792 memset(oh->oh_buckets, 0, sizeof(oh->oh_buckets));
793 spin_unlock_irqrestore(&oh->oh_lock, flags);
795 EXPORT_SYMBOL(lprocfs_oh_clear);
797 /* XXX copied from ldlm/ldlm_lockd.c, copied from ptlrpc/service.c */
798 static long timeval_sub(struct timeval *large, struct timeval *small)
800 return ((large->tv_sec - small->tv_sec) * 1000000) +
801 (large->tv_usec - small->tv_usec);
803 void lprocfs_stime_record(struct obd_service_time *stime, struct timeval *large,
804 struct timeval *small)
806 long diff = timeval_sub(large, small);
812 stime->st_total_us += diff;
814 EXPORT_SYMBOL(lprocfs_stime_record);
816 unsigned long lprocfs_stime_avg_ms(struct obd_service_time *stime)
818 struct obd_service_time copy;
820 memcpy(©, stime, sizeof(copy));
821 if (copy.st_num > 0) {
822 do_div(copy.st_total_us, copy.st_num * 1000);
823 return (unsigned long)copy.st_total_us;
827 EXPORT_SYMBOL(lprocfs_stime_avg_ms);
829 unsigned long lprocfs_stime_avg_us(struct obd_service_time *stime)
831 struct obd_service_time copy;
834 memcpy(©, stime, sizeof(copy));
835 if (copy.st_num > 0) {
836 do_div(copy.st_total_us, copy.st_num);
837 remainder = do_div(copy.st_total_us, 1000);
838 return (unsigned long)remainder;
842 EXPORT_SYMBOL(lprocfs_stime_avg_us);
844 int lprocfs_obd_rd_recovery_status(char *page, char **start, off_t off,
845 int count, int *eof, void *data)
847 struct obd_device *obd = data;
849 connected = obd->obd_connected_clients,
850 max_recoverable = obd->obd_max_recoverable_clients,
851 recoverable = obd->obd_recoverable_clients,
852 completed = max_recoverable - recoverable,
853 queue_len = obd->obd_requests_queued_for_recovery,
854 replayed = obd->obd_replayed_requests;
855 __u64 next_transno = obd->obd_next_recovery_transno;
857 LASSERT(obd != NULL);
860 n = snprintf(page, count, "status: ");
861 page += n; len += n; count -= n;
862 if (obd->obd_max_recoverable_clients == 0) {
863 n = snprintf(page, count, "INACTIVE\n");
867 /* sampled unlocked, but really... */
868 if (obd->obd_recovering == 0) {
869 n = snprintf(page, count, "COMPLETE\n");
870 page += n; len += n; count -= n;
872 n = snprintf(page, count, "recovery_start: %lu\n",
873 obd->obd_recovery_start);
874 page += n; len += n; count -= n;
875 n = snprintf(page, count, "recovery_end: %lu\n",
876 obd->obd_recovery_end);
877 page += n; len += n; count -= n;
878 n = snprintf(page, count, "recovered_clients: %d\n",
880 page += n; len += n; count -= n;
881 n = snprintf(page, count, "unrecovered_clients: %d\n",
882 obd->obd_recoverable_clients);
883 page += n; len += n; count -= n;
884 n = snprintf(page, count, "last_transno: "LPD64"\n",
886 page += n; len += n; count -= n;
887 n = snprintf(page, count, "replayed_requests: %d\n", replayed);
891 n = snprintf(page, count, "RECOVERING\n");
892 page += n; len += n; count -= n;
893 n = snprintf(page, count, "recovery_start: %lu\n",
894 obd->obd_recovery_start);
895 page += n; len += n; count -= n;
896 n = snprintf(page, count, "connected_clients: %d/%d\n",
897 connected, max_recoverable);
898 page += n; len += n; count -= n;
899 n = snprintf(page, count, "completed_clients: %d/%d\n",
900 completed, max_recoverable);
901 page += n; len += n; count -= n;
902 n = snprintf(page, count, "replayed_requests: %d/??\n", replayed);
903 page += n; len += n; count -= n;
904 n = snprintf(page, count, "queued_requests: %d\n", queue_len);
905 page += n; len += n; count -= n;
906 n = snprintf(page, count, "next_transno: "LPD64"\n", next_transno);
909 EXPORT_SYMBOL(lprocfs_obd_rd_recovery_status);
912 EXPORT_SYMBOL(lprocfs_register);
913 EXPORT_SYMBOL(lprocfs_srch);
914 EXPORT_SYMBOL(lprocfs_remove);
915 EXPORT_SYMBOL(lprocfs_add_vars);
916 EXPORT_SYMBOL(lprocfs_obd_attach);
917 EXPORT_SYMBOL(lprocfs_obd_detach);
918 EXPORT_SYMBOL(lprocfs_alloc_stats);
919 EXPORT_SYMBOL(lprocfs_free_stats);
920 EXPORT_SYMBOL(lprocfs_register_stats);
921 EXPORT_SYMBOL(lprocfs_alloc_obd_stats);
922 EXPORT_SYMBOL(lprocfs_free_obd_stats);
924 EXPORT_SYMBOL(lprocfs_rd_u64);
925 EXPORT_SYMBOL(lprocfs_rd_uuid);
926 EXPORT_SYMBOL(lprocfs_rd_name);
927 EXPORT_SYMBOL(lprocfs_rd_fstype);
928 EXPORT_SYMBOL(lprocfs_rd_server_uuid);
929 EXPORT_SYMBOL(lprocfs_rd_conn_uuid);
930 EXPORT_SYMBOL(lprocfs_rd_num_exports);
931 EXPORT_SYMBOL(lprocfs_rd_numrefs);
933 EXPORT_SYMBOL(lprocfs_rd_blksize);
934 EXPORT_SYMBOL(lprocfs_rd_kbytestotal);
935 EXPORT_SYMBOL(lprocfs_rd_kbytesfree);
936 EXPORT_SYMBOL(lprocfs_rd_kbytesavail);
937 EXPORT_SYMBOL(lprocfs_rd_filestotal);
938 EXPORT_SYMBOL(lprocfs_rd_filesfree);
940 EXPORT_SYMBOL(lprocfs_write_helper);
941 EXPORT_SYMBOL(lprocfs_write_u64_helper);