4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/obdclass/lprocfs_status.c
38 * Author: Hariharan Thantry <thantry@users.sourceforge.net>
41 #define DEBUG_SUBSYSTEM S_CLASS
44 #include <liblustre.h>
47 #include <obd_class.h>
48 #include <lprocfs_status.h>
49 #include <lustre/lustre_idl.h>
53 static int lprocfs_no_percpu_stats = 0;
54 CFS_MODULE_PARM(lprocfs_no_percpu_stats, "i", int, 0644,
55 "Do not alloc percpu data for lprocfs stats");
57 #define MAX_STRING_SIZE 128
59 int lprocfs_single_release(struct inode *inode, struct file *file)
61 return single_release(inode, file);
63 EXPORT_SYMBOL(lprocfs_single_release);
65 int lprocfs_seq_release(struct inode *inode, struct file *file)
67 return seq_release(inode, file);
69 EXPORT_SYMBOL(lprocfs_seq_release);
71 struct proc_dir_entry *
72 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
73 #ifndef HAVE_ONLY_PROCFS_SEQ
74 read_proc_t *read_proc, write_proc_t *write_proc,
76 void *data, const struct file_operations *fops)
78 struct proc_dir_entry *proc;
81 if (root == NULL || name == NULL)
82 return ERR_PTR(-EINVAL);
85 #ifndef HAVE_ONLY_PROCFS_SEQ
91 LPROCFS_WRITE_ENTRY();
92 proc = create_proc_entry(name, mode, root);
94 CERROR("LprocFS: No memory to create /proc entry %s", name);
96 return ERR_PTR(-ENOMEM);
98 proc->read_proc = read_proc;
99 proc->write_proc = write_proc;
101 LPROCFS_WRITE_EXIT();
103 return ERR_PTR(-EINVAL);
110 proc = proc_create_data(name, mode, root, fops, data);
112 CERROR("LprocFS: No memory to create /proc entry %s",
114 return ERR_PTR(-ENOMEM);
119 EXPORT_SYMBOL(lprocfs_add_simple);
121 struct proc_dir_entry *lprocfs_add_symlink(const char *name,
122 struct proc_dir_entry *parent, const char *format, ...)
124 struct proc_dir_entry *entry;
128 if (parent == NULL || format == NULL)
131 OBD_ALLOC_WAIT(dest, MAX_STRING_SIZE + 1);
135 va_start(ap, format);
136 vsnprintf(dest, MAX_STRING_SIZE, format, ap);
139 entry = proc_symlink(name, parent, dest);
141 CERROR("LprocFS: Could not create symbolic link from %s to %s",
144 OBD_FREE(dest, MAX_STRING_SIZE + 1);
147 EXPORT_SYMBOL(lprocfs_add_symlink);
149 #ifdef HAVE_ONLY_PROCFS_SEQ
150 static const struct file_operations lprocfs_generic_fops = { };
154 lprocfs_fops_read(struct file *f, char __user *buf, size_t size, loff_t *ppos)
156 struct proc_dir_entry *dp = PDE(f->f_dentry->d_inode);
157 char *page, *start = NULL;
158 int rc = 0, eof = 1, count;
160 if (*ppos >= PAGE_CACHE_SIZE)
163 page = (char *)__get_free_page(GFP_KERNEL);
167 if (LPROCFS_ENTRY_CHECK(dp)) {
172 OBD_FAIL_TIMEOUT(OBD_FAIL_LPROC_REMOVE, 10);
174 rc = dp->read_proc(page, &start, *ppos, PAGE_CACHE_SIZE,
179 /* for lustre proc read, the read count must be less than PAGE_SIZE */
188 start = page + *ppos;
189 } else if (start < page) {
193 count = (rc < size) ? rc : size;
194 if (copy_to_user(buf, start, count)) {
201 free_page((unsigned long)page);
206 lprocfs_fops_write(struct file *f, const char __user *buf, size_t size,
209 struct proc_dir_entry *dp = PDE(f->f_dentry->d_inode);
212 if (LPROCFS_ENTRY_CHECK(dp))
215 rc = dp->write_proc(f, buf, size, dp->data);
219 static struct file_operations lprocfs_generic_fops = {
220 .owner = THIS_MODULE,
221 .read = lprocfs_fops_read,
222 .write = lprocfs_fops_write,
225 /* for b=10866, global variable */
226 DECLARE_RWSEM(_lprocfs_lock);
227 EXPORT_SYMBOL(_lprocfs_lock);
229 static struct proc_dir_entry *__lprocfs_srch(struct proc_dir_entry *head,
232 struct proc_dir_entry *temp;
238 while (temp != NULL) {
239 if (strcmp(temp->name, name) == 0)
246 struct proc_dir_entry *lprocfs_srch(struct proc_dir_entry *head,
249 struct proc_dir_entry *temp;
251 LPROCFS_SRCH_ENTRY();
252 temp = __lprocfs_srch(head, name);
256 EXPORT_SYMBOL(lprocfs_srch);
258 static int __lprocfs_add_vars(struct proc_dir_entry *root,
259 struct lprocfs_vars *list,
264 if (root == NULL || list == NULL)
267 while (list->name != NULL) {
268 struct proc_dir_entry *cur_root, *proc;
269 char *pathcopy, *cur, *next, pathbuf[64];
270 int pathsize = strlen(list->name) + 1;
275 /* need copy of path for strsep */
276 if (strlen(list->name) > sizeof(pathbuf) - 1) {
277 OBD_ALLOC(pathcopy, pathsize);
278 if (pathcopy == NULL)
279 GOTO(out, rc = -ENOMEM);
285 strcpy(pathcopy, list->name);
287 while (cur_root != NULL && (cur = strsep(&next, "/"))) {
288 if (*cur =='\0') /* skip double/trailing "/" */
291 proc = __lprocfs_srch(cur_root, cur);
292 CDEBUG(D_OTHER, "cur_root=%s, cur=%s, next=%s, (%s)\n",
293 cur_root->name, cur, next,
294 (proc ? "exists" : "new"));
296 cur_root = (proc ? proc :
297 proc_mkdir(cur, cur_root));
298 } else if (proc == NULL) {
300 if (list->proc_mode != 0000) {
301 mode = list->proc_mode;
305 if (list->write_fptr)
308 proc = create_proc_entry(cur, mode, cur_root);
312 if (pathcopy != pathbuf)
313 OBD_FREE(pathcopy, pathsize);
315 if (cur_root == NULL || proc == NULL) {
316 CERROR("LprocFS: No memory to create /proc entry %s",
318 GOTO(out, rc = -ENOMEM);
322 proc->proc_fops = list->fops;
324 proc->proc_fops = &lprocfs_generic_fops;
325 proc->read_proc = list->read_fptr;
326 proc->write_proc = list->write_fptr;
327 proc->data = (list->data ? list->data : data);
334 int lprocfs_add_vars(struct proc_dir_entry *root, struct lprocfs_vars *list,
339 LPROCFS_WRITE_ENTRY();
340 rc = __lprocfs_add_vars(root, list, data);
341 LPROCFS_WRITE_EXIT();
345 EXPORT_SYMBOL(lprocfs_add_vars);
351 * \param root [in] The parent proc entry on which new entry will be added.
352 * \param list [in] Array of proc entries to be added.
353 * \param data [in] The argument to be passed when entries read/write routines
354 * are called through /proc file.
356 * \retval 0 on success
360 lprocfs_seq_add_vars(struct proc_dir_entry *root, struct lprocfs_seq_vars *list,
363 if (root == NULL || list == NULL)
366 while (list->name != NULL) {
367 struct proc_dir_entry *proc;
370 if (list->proc_mode != 0000) {
371 mode = list->proc_mode;
372 } else if (list->fops) {
373 if (list->fops->read)
375 if (list->fops->write)
378 proc = proc_create_data(list->name, mode, root,
379 list->fops ?: &lprocfs_generic_fops,
387 EXPORT_SYMBOL(lprocfs_seq_add_vars);
389 #ifndef HAVE_ONLY_PROCFS_SEQ
390 void lprocfs_remove_nolock(struct proc_dir_entry **proot)
392 struct proc_dir_entry *root = *proot;
393 struct proc_dir_entry *temp = root;
394 struct proc_dir_entry *rm_entry;
395 struct proc_dir_entry *parent;
398 if (root == NULL || IS_ERR(root))
401 parent = root->parent;
402 LASSERT(parent != NULL);
405 while (temp->subdir != NULL)
411 /* Memory corruption once caused this to fail, and
412 without this LASSERT we would loop here forever. */
413 LASSERTF(strlen(rm_entry->name) == rm_entry->namelen,
414 "0x%p %s/%s len %d\n", rm_entry, temp->name,
415 rm_entry->name, (int)strlen(rm_entry->name));
417 remove_proc_entry(rm_entry->name, temp);
424 void lprocfs_remove(struct proc_dir_entry **rooth)
426 #ifndef HAVE_ONLY_PROCFS_SEQ
427 LPROCFS_WRITE_ENTRY(); /* search vs remove race */
428 lprocfs_remove_nolock(rooth);
429 LPROCFS_WRITE_EXIT();
435 EXPORT_SYMBOL(lprocfs_remove);
437 void lprocfs_remove_proc_entry(const char *name, struct proc_dir_entry *parent)
439 LASSERT(parent != NULL);
440 remove_proc_entry(name, parent);
442 EXPORT_SYMBOL(lprocfs_remove_proc_entry);
444 #ifndef HAVE_ONLY_PROCFS_SEQ
445 void lprocfs_try_remove_proc_entry(const char *name,
446 struct proc_dir_entry *parent)
448 struct proc_dir_entry *t = NULL;
449 struct proc_dir_entry **p;
452 LASSERT(parent != NULL);
455 LPROCFS_WRITE_ENTRY();
457 /* lookup target name */
458 for (p = &parent->subdir; *p; p = &(*p)->next) {
459 if ((*p)->namelen != len)
461 if (memcmp(name, (*p)->name, len))
468 /* verify it's empty: do not count "num_refs" */
469 for (p = &t->subdir; *p; p = &(*p)->next) {
470 if ((*p)->namelen != strlen("num_refs")) {
474 if (memcmp("num_refs", (*p)->name,
475 strlen("num_refs"))) {
483 lprocfs_remove_nolock(&t);
485 LPROCFS_WRITE_EXIT();
489 EXPORT_SYMBOL(lprocfs_try_remove_proc_entry);
491 struct proc_dir_entry *lprocfs_register(const char *name,
492 struct proc_dir_entry *parent,
493 struct lprocfs_vars *list, void *data)
495 struct proc_dir_entry *entry;
498 LPROCFS_WRITE_ENTRY();
499 entry = __lprocfs_srch(parent, name);
501 CERROR("entry '%s' already registered\n", name);
502 GOTO(out, entry = ERR_PTR(-EALREADY));
505 entry = proc_mkdir(name, parent);
507 GOTO(out, entry = ERR_PTR(-ENOMEM));
510 rc = __lprocfs_add_vars(entry, list, data);
512 lprocfs_remove_nolock(&entry);
513 GOTO(out, entry = ERR_PTR(rc));
517 LPROCFS_WRITE_EXIT();
520 EXPORT_SYMBOL(lprocfs_register);
523 struct proc_dir_entry *
524 lprocfs_seq_register(const char *name, struct proc_dir_entry *parent,
525 struct lprocfs_seq_vars *list, void *data)
527 struct proc_dir_entry *newchild;
529 newchild = proc_mkdir(name, parent);
530 if (newchild != NULL && list != NULL) {
531 int rc = lprocfs_seq_add_vars(newchild, list, data);
533 lprocfs_remove(&newchild);
539 EXPORT_SYMBOL(lprocfs_seq_register);
541 /* Generic callbacks */
542 int lprocfs_uint_seq_show(struct seq_file *m, void *data)
544 return seq_printf(m, "%u\n", *(unsigned int *)data);
546 EXPORT_SYMBOL(lprocfs_uint_seq_show);
548 int lprocfs_wr_uint(struct file *file, const char *buffer,
549 unsigned long count, void *data)
552 char dummy[MAX_STRING_SIZE + 1], *end;
555 dummy[MAX_STRING_SIZE] = '\0';
556 if (copy_from_user(dummy, buffer, MAX_STRING_SIZE))
559 tmp = simple_strtoul(dummy, &end, 0);
563 *p = (unsigned int)tmp;
566 EXPORT_SYMBOL(lprocfs_wr_uint);
568 ssize_t lprocfs_uint_seq_write(struct file *file, const char *buffer,
569 size_t count, loff_t *off)
571 int *data = ((struct seq_file *)file->private_data)->private;
574 rc = lprocfs_write_helper(buffer, count, &val);
578 return lprocfs_wr_uint(file, buffer, count, data);
580 EXPORT_SYMBOL(lprocfs_uint_seq_write);
582 int lprocfs_u64_seq_show(struct seq_file *m, void *data)
584 LASSERT(data != NULL);
585 return seq_printf(m, LPU64"\n", *(__u64 *)data);
587 EXPORT_SYMBOL(lprocfs_u64_seq_show);
589 int lprocfs_atomic_seq_show(struct seq_file *m, void *data)
591 atomic_t *atom = data;
592 LASSERT(atom != NULL);
593 return seq_printf(m, "%d\n", atomic_read(atom));
595 EXPORT_SYMBOL(lprocfs_atomic_seq_show);
598 lprocfs_atomic_seq_write(struct file *file, const char *buffer,
599 size_t count, loff_t *off)
601 atomic_t *atm = ((struct seq_file *)file->private_data)->private;
605 rc = lprocfs_write_helper(buffer, count, &val);
612 atomic_set(atm, val);
615 EXPORT_SYMBOL(lprocfs_atomic_seq_write);
617 int lprocfs_uuid_seq_show(struct seq_file *m, void *data)
619 struct obd_device *obd = data;
621 LASSERT(obd != NULL);
622 return seq_printf(m, "%s\n", obd->obd_uuid.uuid);
624 EXPORT_SYMBOL(lprocfs_uuid_seq_show);
626 int lprocfs_name_seq_show(struct seq_file *m, void *data)
628 struct obd_device *dev = data;
630 LASSERT(dev != NULL);
631 return seq_printf(m, "%s\n", dev->obd_name);
633 EXPORT_SYMBOL(lprocfs_name_seq_show);
635 int lprocfs_blksize_seq_show(struct seq_file *m, void *data)
637 struct obd_device *obd = data;
638 struct obd_statfs osfs;
639 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
640 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
643 rc = seq_printf(m, "%u\n", osfs.os_bsize);
646 EXPORT_SYMBOL(lprocfs_blksize_seq_show);
648 int lprocfs_kbytestotal_seq_show(struct seq_file *m, void *data)
650 struct obd_device *obd = data;
651 struct obd_statfs osfs;
652 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
653 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
656 __u32 blk_size = osfs.os_bsize >> 10;
657 __u64 result = osfs.os_blocks;
659 while (blk_size >>= 1)
662 rc = seq_printf(m, LPU64"\n", result);
666 EXPORT_SYMBOL(lprocfs_kbytestotal_seq_show);
668 int lprocfs_kbytesfree_seq_show(struct seq_file *m, void *data)
670 struct obd_device *obd = data;
671 struct obd_statfs osfs;
672 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
673 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
676 __u32 blk_size = osfs.os_bsize >> 10;
677 __u64 result = osfs.os_bfree;
679 while (blk_size >>= 1)
682 rc = seq_printf(m, LPU64"\n", result);
686 EXPORT_SYMBOL(lprocfs_kbytesfree_seq_show);
688 int lprocfs_kbytesavail_seq_show(struct seq_file *m, void *data)
690 struct obd_device *obd = data;
691 struct obd_statfs osfs;
692 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
693 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
696 __u32 blk_size = osfs.os_bsize >> 10;
697 __u64 result = osfs.os_bavail;
699 while (blk_size >>= 1)
702 rc = seq_printf(m, LPU64"\n", result);
706 EXPORT_SYMBOL(lprocfs_kbytesavail_seq_show);
708 int lprocfs_filestotal_seq_show(struct seq_file *m, void *data)
710 struct obd_device *obd = data;
711 struct obd_statfs osfs;
712 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
713 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
716 rc = seq_printf(m, LPU64"\n", osfs.os_files);
719 EXPORT_SYMBOL(lprocfs_filestotal_seq_show);
721 int lprocfs_filesfree_seq_show(struct seq_file *m, void *data)
723 struct obd_device *obd = data;
724 struct obd_statfs osfs;
725 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
726 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
729 rc = seq_printf(m, LPU64"\n", osfs.os_ffree);
732 EXPORT_SYMBOL(lprocfs_filesfree_seq_show);
734 int lprocfs_server_uuid_seq_show(struct seq_file *m, void *data)
736 struct obd_device *obd = data;
737 struct obd_import *imp;
738 char *imp_state_name = NULL;
741 LASSERT(obd != NULL);
742 LPROCFS_CLIMP_CHECK(obd);
743 imp = obd->u.cli.cl_import;
744 imp_state_name = ptlrpc_import_state_name(imp->imp_state);
745 rc = seq_printf(m, "%s\t%s%s\n", obd2cli_tgt(obd), imp_state_name,
746 imp->imp_deactive ? "\tDEACTIVATED" : "");
748 LPROCFS_CLIMP_EXIT(obd);
751 EXPORT_SYMBOL(lprocfs_server_uuid_seq_show);
753 int lprocfs_conn_uuid_seq_show(struct seq_file *m, void *data)
755 struct obd_device *obd = data;
756 struct ptlrpc_connection *conn;
759 LASSERT(obd != NULL);
761 LPROCFS_CLIMP_CHECK(obd);
762 conn = obd->u.cli.cl_import->imp_connection;
763 if (conn && obd->u.cli.cl_import)
764 rc = seq_printf(m, "%s\n", conn->c_remote_uuid.uuid);
766 rc = seq_printf(m, "%s\n", "<none>");
768 LPROCFS_CLIMP_EXIT(obd);
771 EXPORT_SYMBOL(lprocfs_conn_uuid_seq_show);
773 /** add up per-cpu counters */
774 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
775 struct lprocfs_counter *cnt)
777 unsigned int num_entry;
778 struct lprocfs_counter *percpu_cntr;
780 unsigned long flags = 0;
782 memset(cnt, 0, sizeof(*cnt));
785 /* set count to 1 to avoid divide-by-zero errs in callers */
790 cnt->lc_min = LC_MIN_INIT;
792 num_entry = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
794 for (i = 0; i < num_entry; i++) {
795 if (stats->ls_percpu[i] == NULL)
797 percpu_cntr = lprocfs_stats_counter_get(stats, i, idx);
799 cnt->lc_count += percpu_cntr->lc_count;
800 cnt->lc_sum += percpu_cntr->lc_sum;
801 if (percpu_cntr->lc_min < cnt->lc_min)
802 cnt->lc_min = percpu_cntr->lc_min;
803 if (percpu_cntr->lc_max > cnt->lc_max)
804 cnt->lc_max = percpu_cntr->lc_max;
805 cnt->lc_sumsquare += percpu_cntr->lc_sumsquare;
808 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
810 EXPORT_SYMBOL(lprocfs_stats_collect);
813 * Append a space separated list of current set flags to str.
815 #define flag2seqstr(flag) \
817 if (imp->imp_##flag) \
818 seq_printf(m, "%s" #flag, first ? "" : ", "); \
820 static int obd_import_flags2seqstr(struct obd_import *imp, struct seq_file *m)
824 if (imp->imp_obd->obd_no_recov) {
825 seq_printf(m, "no_recov");
829 flag2seqstr(invalid);
830 flag2seqstr(deactive);
831 flag2seqstr(replayable);
832 flag2seqstr(pingable);
837 static const char *obd_connect_names[] = {
851 "join_file(obsolete)",
855 "remote_client_by_force",
864 "mds_mds_connection",
867 "alt_checksum_algorithm",
899 static void obd_connect_seq_flags2str(struct seq_file *m, __u64 flags, char *sep)
905 for (i = 0; obd_connect_names[i] != NULL; i++, mask <<= 1) {
907 seq_printf(m, "%s%s",
908 first ? "" : sep, obd_connect_names[i]);
912 if (flags & ~(mask - 1))
913 seq_printf(m, "%sunknown flags "LPX64,
914 first ? "" : sep, flags & ~(mask - 1));
917 int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep)
922 for (i = 0; obd_connect_names[i] != NULL; i++, mask <<= 1) {
924 ret += snprintf(page + ret, count - ret, "%s%s",
925 ret ? sep : "", obd_connect_names[i]);
927 if (flags & ~(mask - 1))
928 ret += snprintf(page + ret, count - ret,
929 "%sunknown flags "LPX64,
930 ret ? sep : "", flags & ~(mask - 1));
933 EXPORT_SYMBOL(obd_connect_flags2str);
935 static void obd_connect_data_seqprint(struct seq_file *m,
936 struct obd_connect_data *ocd)
940 LASSERT(ocd != NULL);
941 flags = ocd->ocd_connect_flags;
943 seq_printf(m, " connect_data:\n"
946 ocd->ocd_connect_flags,
948 if (flags & OBD_CONNECT_VERSION)
949 seq_printf(m, " target_version: %u.%u.%u.%u\n",
950 OBD_OCD_VERSION_MAJOR(ocd->ocd_version),
951 OBD_OCD_VERSION_MINOR(ocd->ocd_version),
952 OBD_OCD_VERSION_PATCH(ocd->ocd_version),
953 OBD_OCD_VERSION_FIX(ocd->ocd_version));
954 if (flags & OBD_CONNECT_MDS)
955 seq_printf(m, " mdt_index: %d\n", ocd->ocd_group);
956 if (flags & OBD_CONNECT_GRANT)
957 seq_printf(m, " initial_grant: %d\n", ocd->ocd_grant);
958 if (flags & OBD_CONNECT_INDEX)
959 seq_printf(m, " target_index: %u\n", ocd->ocd_index);
960 if (flags & OBD_CONNECT_BRW_SIZE)
961 seq_printf(m, " max_brw_size: %d\n", ocd->ocd_brw_size);
962 if (flags & OBD_CONNECT_IBITS)
963 seq_printf(m, " ibits_known: "LPX64"\n",
964 ocd->ocd_ibits_known);
965 if (flags & OBD_CONNECT_GRANT_PARAM)
966 seq_printf(m, " grant_block_size: %d\n"
967 " grant_inode_size: %d\n"
968 " grant_extent_overhead: %d\n",
971 ocd->ocd_grant_extent);
972 if (flags & OBD_CONNECT_TRANSNO)
973 seq_printf(m, " first_transno: "LPX64"\n",
975 if (flags & OBD_CONNECT_CKSUM)
976 seq_printf(m, " cksum_types: %#x\n",
977 ocd->ocd_cksum_types);
978 if (flags & OBD_CONNECT_MAX_EASIZE)
979 seq_printf(m, " max_easize: %d\n", ocd->ocd_max_easize);
980 if (flags & OBD_CONNECT_MAXBYTES)
981 seq_printf(m, " max_object_bytes: "LPU64"\n",
985 int lprocfs_import_seq_show(struct seq_file *m, void *data)
987 struct lprocfs_counter ret;
988 struct lprocfs_counter_header *header;
989 struct obd_device *obd = (struct obd_device *)data;
990 struct obd_import *imp;
991 struct obd_import_conn *conn;
992 struct obd_connect_data *ocd;
997 LASSERT(obd != NULL);
998 LPROCFS_CLIMP_CHECK(obd);
999 imp = obd->u.cli.cl_import;
1000 ocd = &imp->imp_connect_data;
1002 seq_printf(m, "import:\n"
1006 " connect_flags: [",
1009 ptlrpc_import_state_name(imp->imp_state));
1010 obd_connect_seq_flags2str(m, imp->imp_connect_data.ocd_connect_flags,
1012 seq_printf(m, "]\n");
1013 obd_connect_data_seqprint(m, ocd);
1014 seq_printf(m, " import_flags: [");
1015 obd_import_flags2seqstr(imp, m);
1019 " failover_nids: [");
1020 spin_lock(&imp->imp_lock);
1022 list_for_each_entry(conn, &imp->imp_conn_list, oic_item) {
1023 seq_printf(m, "%s%s", j ? ", " : "",
1024 libcfs_nid2str(conn->oic_conn->c_peer.nid));
1028 " current_connection: %s\n"
1029 " connection_attempts: %u\n"
1031 " in-progress_invalidations: %u\n",
1032 imp->imp_connection == NULL ? "<none>" :
1033 libcfs_nid2str(imp->imp_connection->c_peer.nid),
1035 imp->imp_generation,
1036 atomic_read(&imp->imp_inval_count));
1037 spin_unlock(&imp->imp_lock);
1039 if (obd->obd_svc_stats == NULL)
1042 header = &obd->obd_svc_stats->ls_cnt_header[PTLRPC_REQWAIT_CNTR];
1043 lprocfs_stats_collect(obd->obd_svc_stats, PTLRPC_REQWAIT_CNTR, &ret);
1044 if (ret.lc_count != 0) {
1045 /* first argument to do_div MUST be __u64 */
1046 __u64 sum = ret.lc_sum;
1047 do_div(sum, ret.lc_count);
1051 seq_printf(m, " rpcs:\n"
1053 " unregistering: %u\n"
1055 " avg_waittime: "LPU64" %s\n",
1056 atomic_read(&imp->imp_inflight),
1057 atomic_read(&imp->imp_unregistering),
1058 atomic_read(&imp->imp_timeouts),
1059 ret.lc_sum, header->lc_units);
1062 for(j = 0; j < IMP_AT_MAX_PORTALS; j++) {
1063 if (imp->imp_at.iat_portal[j] == 0)
1065 k = max_t(unsigned int, k,
1066 at_get(&imp->imp_at.iat_service_estimate[j]));
1068 seq_printf(m, " service_estimates:\n"
1069 " services: %u sec\n"
1070 " network: %u sec\n",
1072 at_get(&imp->imp_at.iat_net_latency));
1074 seq_printf(m, " transactions:\n"
1075 " last_replay: "LPU64"\n"
1076 " peer_committed: "LPU64"\n"
1077 " last_checked: "LPU64"\n",
1078 imp->imp_last_replay_transno,
1079 imp->imp_peer_committed_transno,
1080 imp->imp_last_transno_checked);
1082 /* avg data rates */
1083 for (rw = 0; rw <= 1; rw++) {
1084 lprocfs_stats_collect(obd->obd_svc_stats,
1085 PTLRPC_LAST_CNTR + BRW_READ_BYTES + rw,
1087 if (ret.lc_sum > 0 && ret.lc_count > 0) {
1088 /* first argument to do_div MUST be __u64 */
1089 __u64 sum = ret.lc_sum;
1090 do_div(sum, ret.lc_count);
1092 seq_printf(m, " %s_data_averages:\n"
1093 " bytes_per_rpc: "LPU64"\n",
1094 rw ? "write" : "read",
1097 k = (int)ret.lc_sum;
1098 j = opcode_offset(OST_READ + rw) + EXTRA_MAX_OPCODES;
1099 header = &obd->obd_svc_stats->ls_cnt_header[j];
1100 lprocfs_stats_collect(obd->obd_svc_stats, j, &ret);
1101 if (ret.lc_sum > 0 && ret.lc_count != 0) {
1102 /* first argument to do_div MUST be __u64 */
1103 __u64 sum = ret.lc_sum;
1104 do_div(sum, ret.lc_count);
1106 seq_printf(m, " %s_per_rpc: "LPU64"\n",
1107 header->lc_units, ret.lc_sum);
1108 j = (int)ret.lc_sum;
1110 seq_printf(m, " MB_per_sec: %u.%.02u\n",
1111 k / j, (100 * k / j) % 100);
1116 LPROCFS_CLIMP_EXIT(obd);
1119 EXPORT_SYMBOL(lprocfs_import_seq_show);
1121 int lprocfs_state_seq_show(struct seq_file *m, void *data)
1123 struct obd_device *obd = (struct obd_device *)data;
1124 struct obd_import *imp;
1127 LASSERT(obd != NULL);
1128 LPROCFS_CLIMP_CHECK(obd);
1129 imp = obd->u.cli.cl_import;
1131 seq_printf(m, "current_state: %s\n",
1132 ptlrpc_import_state_name(imp->imp_state));
1133 seq_printf(m, "state_history:\n");
1134 k = imp->imp_state_hist_idx;
1135 for (j = 0; j < IMP_STATE_HIST_LEN; j++) {
1136 struct import_state_hist *ish =
1137 &imp->imp_state_hist[(k + j) % IMP_STATE_HIST_LEN];
1138 if (ish->ish_state == 0)
1140 seq_printf(m, " - ["CFS_TIME_T", %s]\n",
1142 ptlrpc_import_state_name(ish->ish_state));
1145 LPROCFS_CLIMP_EXIT(obd);
1148 EXPORT_SYMBOL(lprocfs_state_seq_show);
1150 int lprocfs_seq_at_hist_helper(struct seq_file *m, struct adaptive_timeout *at)
1153 for (i = 0; i < AT_BINS; i++)
1154 seq_printf(m, "%3u ", at->at_hist[i]);
1155 seq_printf(m, "\n");
1158 EXPORT_SYMBOL(lprocfs_seq_at_hist_helper);
1160 /* See also ptlrpc_lprocfs_timeouts_show_seq */
1161 int lprocfs_timeouts_seq_show(struct seq_file *m, void *data)
1163 struct obd_device *obd = (struct obd_device *)data;
1164 struct obd_import *imp;
1165 unsigned int cur, worst;
1170 LASSERT(obd != NULL);
1171 LPROCFS_CLIMP_CHECK(obd);
1172 imp = obd->u.cli.cl_import;
1174 now = cfs_time_current_sec();
1176 /* Some network health info for kicks */
1177 s2dhms(&ts, now - imp->imp_last_reply_time);
1178 seq_printf(m, "%-10s : %ld, "DHMS_FMT" ago\n",
1179 "last reply", imp->imp_last_reply_time, DHMS_VARS(&ts));
1181 cur = at_get(&imp->imp_at.iat_net_latency);
1182 worst = imp->imp_at.iat_net_latency.at_worst_ever;
1183 worstt = imp->imp_at.iat_net_latency.at_worst_time;
1184 s2dhms(&ts, now - worstt);
1185 seq_printf(m, "%-10s : cur %3u worst %3u (at %ld, "DHMS_FMT" ago) ",
1186 "network", cur, worst, worstt, DHMS_VARS(&ts));
1187 lprocfs_seq_at_hist_helper(m, &imp->imp_at.iat_net_latency);
1189 for(i = 0; i < IMP_AT_MAX_PORTALS; i++) {
1190 if (imp->imp_at.iat_portal[i] == 0)
1192 cur = at_get(&imp->imp_at.iat_service_estimate[i]);
1193 worst = imp->imp_at.iat_service_estimate[i].at_worst_ever;
1194 worstt = imp->imp_at.iat_service_estimate[i].at_worst_time;
1195 s2dhms(&ts, now - worstt);
1196 seq_printf(m, "portal %-2d : cur %3u worst %3u (at %ld, "
1197 DHMS_FMT" ago) ", imp->imp_at.iat_portal[i],
1198 cur, worst, worstt, DHMS_VARS(&ts));
1199 lprocfs_seq_at_hist_helper(m, &imp->imp_at.iat_service_estimate[i]);
1202 LPROCFS_CLIMP_EXIT(obd);
1205 EXPORT_SYMBOL(lprocfs_timeouts_seq_show);
1207 int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data)
1209 struct obd_device *obd = data;
1212 LPROCFS_CLIMP_CHECK(obd);
1213 flags = obd->u.cli.cl_import->imp_connect_data.ocd_connect_flags;
1214 seq_printf(m, "flags="LPX64"\n", flags);
1215 obd_connect_seq_flags2str(m, flags, "\n");
1216 seq_printf(m, "\n");
1217 LPROCFS_CLIMP_EXIT(obd);
1220 EXPORT_SYMBOL(lprocfs_connect_flags_seq_show);
1222 #ifndef HAVE_ONLY_PROCFS_SEQ
1224 int lprocfs_rd_uint(char *page, char **start, off_t off,
1225 int count, int *eof, void *data)
1227 unsigned int *temp = data;
1228 return snprintf(page, count, "%u\n", *temp);
1230 EXPORT_SYMBOL(lprocfs_rd_uint);
1232 int lprocfs_rd_u64(char *page, char **start, off_t off,
1233 int count, int *eof, void *data)
1235 LASSERT(data != NULL);
1237 return snprintf(page, count, LPU64"\n", *(__u64 *)data);
1239 EXPORT_SYMBOL(lprocfs_rd_u64);
1241 int lprocfs_rd_atomic(char *page, char **start, off_t off,
1242 int count, int *eof, void *data)
1244 atomic_t *atom = data;
1245 LASSERT(atom != NULL);
1247 return snprintf(page, count, "%d\n", atomic_read(atom));
1249 EXPORT_SYMBOL(lprocfs_rd_atomic);
1251 int lprocfs_wr_atomic(struct file *file, const char *buffer,
1252 unsigned long count, void *data)
1254 atomic_t *atm = data;
1258 rc = lprocfs_write_helper(buffer, count, &val);
1265 atomic_set(atm, val);
1268 EXPORT_SYMBOL(lprocfs_wr_atomic);
1270 int lprocfs_rd_uuid(char *page, char **start, off_t off, int count,
1271 int *eof, void *data)
1273 struct obd_device *obd = data;
1275 LASSERT(obd != NULL);
1277 return snprintf(page, count, "%s\n", obd->obd_uuid.uuid);
1279 EXPORT_SYMBOL(lprocfs_rd_uuid);
1281 int lprocfs_rd_name(char *page, char **start, off_t off, int count,
1282 int *eof, void *data)
1284 struct obd_device *dev = data;
1286 LASSERT(dev != NULL);
1288 return snprintf(page, count, "%s\n", dev->obd_name);
1290 EXPORT_SYMBOL(lprocfs_rd_name);
1292 int lprocfs_rd_blksize(char *page, char **start, off_t off, int count,
1293 int *eof, void *data)
1295 struct obd_device *obd = data;
1296 struct obd_statfs osfs;
1297 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
1298 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1299 OBD_STATFS_NODELAY);
1302 rc = snprintf(page, count, "%u\n", osfs.os_bsize);
1306 EXPORT_SYMBOL(lprocfs_rd_blksize);
1308 int lprocfs_rd_kbytestotal(char *page, char **start, off_t off, int count,
1309 int *eof, void *data)
1311 struct obd_device *obd = data;
1312 struct obd_statfs osfs;
1313 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
1314 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1315 OBD_STATFS_NODELAY);
1317 __u32 blk_size = osfs.os_bsize >> 10;
1318 __u64 result = osfs.os_blocks;
1320 while (blk_size >>= 1)
1324 rc = snprintf(page, count, LPU64"\n", result);
1328 EXPORT_SYMBOL(lprocfs_rd_kbytestotal);
1330 int lprocfs_rd_kbytesfree(char *page, char **start, off_t off, int count,
1331 int *eof, void *data)
1333 struct obd_device *obd = data;
1334 struct obd_statfs osfs;
1335 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
1336 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1337 OBD_STATFS_NODELAY);
1339 __u32 blk_size = osfs.os_bsize >> 10;
1340 __u64 result = osfs.os_bfree;
1342 while (blk_size >>= 1)
1346 rc = snprintf(page, count, LPU64"\n", result);
1350 EXPORT_SYMBOL(lprocfs_rd_kbytesfree);
1352 int lprocfs_rd_kbytesavail(char *page, char **start, off_t off, int count,
1353 int *eof, void *data)
1355 struct obd_device *obd = data;
1356 struct obd_statfs osfs;
1357 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
1358 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1359 OBD_STATFS_NODELAY);
1361 __u32 blk_size = osfs.os_bsize >> 10;
1362 __u64 result = osfs.os_bavail;
1364 while (blk_size >>= 1)
1368 rc = snprintf(page, count, LPU64"\n", result);
1372 EXPORT_SYMBOL(lprocfs_rd_kbytesavail);
1374 int lprocfs_rd_filestotal(char *page, char **start, off_t off, int count,
1375 int *eof, void *data)
1377 struct obd_device *obd = data;
1378 struct obd_statfs osfs;
1379 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
1380 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1381 OBD_STATFS_NODELAY);
1384 rc = snprintf(page, count, LPU64"\n", osfs.os_files);
1389 EXPORT_SYMBOL(lprocfs_rd_filestotal);
1391 int lprocfs_rd_filesfree(char *page, char **start, off_t off, int count,
1392 int *eof, void *data)
1394 struct obd_device *obd = data;
1395 struct obd_statfs osfs;
1396 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
1397 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1398 OBD_STATFS_NODELAY);
1401 rc = snprintf(page, count, LPU64"\n", osfs.os_ffree);
1405 EXPORT_SYMBOL(lprocfs_rd_filesfree);
1407 int lprocfs_rd_server_uuid(char *page, char **start, off_t off, int count,
1408 int *eof, void *data)
1410 struct obd_device *obd = data;
1411 struct obd_import *imp;
1412 char *imp_state_name = NULL;
1415 LASSERT(obd != NULL);
1416 LPROCFS_CLIMP_CHECK(obd);
1417 imp = obd->u.cli.cl_import;
1418 imp_state_name = ptlrpc_import_state_name(imp->imp_state);
1420 rc = snprintf(page, count, "%s\t%s%s\n",
1421 obd2cli_tgt(obd), imp_state_name,
1422 imp->imp_deactive ? "\tDEACTIVATED" : "");
1424 LPROCFS_CLIMP_EXIT(obd);
1427 EXPORT_SYMBOL(lprocfs_rd_server_uuid);
1429 int lprocfs_rd_conn_uuid(char *page, char **start, off_t off, int count,
1430 int *eof, void *data)
1432 struct obd_device *obd = data;
1433 struct ptlrpc_connection *conn;
1436 LASSERT(obd != NULL);
1438 LPROCFS_CLIMP_CHECK(obd);
1439 conn = obd->u.cli.cl_import->imp_connection;
1441 if (conn && obd->u.cli.cl_import) {
1442 rc = snprintf(page, count, "%s\n",
1443 conn->c_remote_uuid.uuid);
1445 rc = snprintf(page, count, "%s\n", "<none>");
1448 LPROCFS_CLIMP_EXIT(obd);
1451 EXPORT_SYMBOL(lprocfs_rd_conn_uuid);
1454 * Append a space separated list of current set flags to str.
1456 #define flag2str(flag) \
1457 if (imp->imp_##flag && max - len > 0) \
1458 len += snprintf(str + len, max - len, "%s" #flag, len ? ", " : "");
1459 static int obd_import_flags2str(struct obd_import *imp, char *str, int max)
1463 if (imp->imp_obd->obd_no_recov)
1464 len += snprintf(str, max - len, "no_recov");
1468 flag2str(replayable);
1474 int lprocfs_rd_import(char *page, char **start, off_t off, int count,
1475 int *eof, void *data)
1477 struct lprocfs_counter ret;
1478 struct lprocfs_counter_header *header;
1479 struct obd_device *obd = (struct obd_device *)data;
1480 struct obd_import *imp;
1481 struct obd_import_conn *conn;
1487 LASSERT(obd != NULL);
1488 LPROCFS_CLIMP_CHECK(obd);
1489 imp = obd->u.cli.cl_import;
1492 i = snprintf(page, count,
1498 " connect_flags: [",
1501 ptlrpc_import_state_name(imp->imp_state),
1502 imp->imp_connect_data.ocd_instance);
1503 i += obd_connect_flags2str(page + i, count - i,
1504 imp->imp_connect_data.ocd_connect_flags,
1506 i += snprintf(page + i, count - i,
1508 " import_flags: [");
1509 i += obd_import_flags2str(imp, page + i, count - i);
1511 i += snprintf(page + i, count - i,
1514 " failover_nids: [");
1515 spin_lock(&imp->imp_lock);
1517 list_for_each_entry(conn, &imp->imp_conn_list, oic_item) {
1518 i += snprintf(page + i, count - i, "%s%s", j ? ", " : "",
1519 libcfs_nid2str(conn->oic_conn->c_peer.nid));
1522 i += snprintf(page + i, count - i,
1524 " current_connection: %s\n"
1525 " connection_attempts: %u\n"
1527 " in-progress_invalidations: %u\n",
1528 imp->imp_connection == NULL ? "<none>" :
1529 libcfs_nid2str(imp->imp_connection->c_peer.nid),
1531 imp->imp_generation,
1532 atomic_read(&imp->imp_inval_count));
1533 spin_unlock(&imp->imp_lock);
1535 if (obd->obd_svc_stats == NULL)
1538 header = &obd->obd_svc_stats->ls_cnt_header[PTLRPC_REQWAIT_CNTR];
1539 lprocfs_stats_collect(obd->obd_svc_stats, PTLRPC_REQWAIT_CNTR, &ret);
1540 if (ret.lc_count != 0) {
1541 /* first argument to do_div MUST be __u64 */
1542 __u64 sum = ret.lc_sum;
1543 do_div(sum, ret.lc_count);
1547 i += snprintf(page + i, count - i,
1550 " unregistering: %u\n"
1552 " avg_waittime: "LPU64" %s\n",
1553 atomic_read(&imp->imp_inflight),
1554 atomic_read(&imp->imp_unregistering),
1555 atomic_read(&imp->imp_timeouts),
1556 ret.lc_sum, header->lc_units);
1559 for(j = 0; j < IMP_AT_MAX_PORTALS; j++) {
1560 if (imp->imp_at.iat_portal[j] == 0)
1562 k = max_t(unsigned int, k,
1563 at_get(&imp->imp_at.iat_service_estimate[j]));
1565 i += snprintf(page + i, count - i,
1566 " service_estimates:\n"
1567 " services: %u sec\n"
1568 " network: %u sec\n",
1570 at_get(&imp->imp_at.iat_net_latency));
1572 i += snprintf(page + i, count - i,
1574 " last_replay: "LPU64"\n"
1575 " peer_committed: "LPU64"\n"
1576 " last_checked: "LPU64"\n",
1577 imp->imp_last_replay_transno,
1578 imp->imp_peer_committed_transno,
1579 imp->imp_last_transno_checked);
1581 /* avg data rates */
1582 for (rw = 0; rw <= 1; rw++) {
1583 lprocfs_stats_collect(obd->obd_svc_stats,
1584 PTLRPC_LAST_CNTR + BRW_READ_BYTES + rw,
1586 if (ret.lc_sum > 0 && ret.lc_count > 0) {
1587 /* first argument to do_div MUST be __u64 */
1588 __u64 sum = ret.lc_sum;
1589 do_div(sum, ret.lc_count);
1591 i += snprintf(page + i, count - i,
1592 " %s_data_averages:\n"
1593 " bytes_per_rpc: "LPU64"\n",
1594 rw ? "write" : "read",
1597 k = (int)ret.lc_sum;
1598 j = opcode_offset(OST_READ + rw) + EXTRA_MAX_OPCODES;
1599 header = &obd->obd_svc_stats->ls_cnt_header[j];
1600 lprocfs_stats_collect(obd->obd_svc_stats, j, &ret);
1601 if (ret.lc_sum > 0 && ret.lc_count != 0) {
1602 /* first argument to do_div MUST be __u64 */
1603 __u64 sum = ret.lc_sum;
1604 do_div(sum, ret.lc_count);
1606 i += snprintf(page + i, count - i,
1607 " %s_per_rpc: "LPU64"\n",
1608 header->lc_units, ret.lc_sum);
1609 j = (int)ret.lc_sum;
1611 i += snprintf(page + i, count - i,
1612 " MB_per_sec: %u.%.02u\n",
1613 k / j, (100 * k / j) % 100);
1618 LPROCFS_CLIMP_EXIT(obd);
1621 EXPORT_SYMBOL(lprocfs_rd_import);
1623 int lprocfs_rd_state(char *page, char **start, off_t off, int count,
1624 int *eof, void *data)
1626 struct obd_device *obd = (struct obd_device *)data;
1627 struct obd_import *imp;
1630 LASSERT(obd != NULL);
1631 LPROCFS_CLIMP_CHECK(obd);
1632 imp = obd->u.cli.cl_import;
1635 i = snprintf(page, count, "current_state: %s\n",
1636 ptlrpc_import_state_name(imp->imp_state));
1637 i += snprintf(page + i, count - i,
1638 "state_history:\n");
1639 k = imp->imp_state_hist_idx;
1640 for (j = 0; j < IMP_STATE_HIST_LEN; j++) {
1641 struct import_state_hist *ish =
1642 &imp->imp_state_hist[(k + j) % IMP_STATE_HIST_LEN];
1643 if (ish->ish_state == 0)
1645 i += snprintf(page + i, count - i, " - ["CFS_TIME_T", %s]\n",
1647 ptlrpc_import_state_name(ish->ish_state));
1650 LPROCFS_CLIMP_EXIT(obd);
1653 EXPORT_SYMBOL(lprocfs_rd_state);
1655 int lprocfs_at_hist_helper(char *page, int count, int rc,
1656 struct adaptive_timeout *at)
1659 for (i = 0; i < AT_BINS; i++)
1660 rc += snprintf(page + rc, count - rc, "%3u ", at->at_hist[i]);
1661 rc += snprintf(page + rc, count - rc, "\n");
1664 EXPORT_SYMBOL(lprocfs_at_hist_helper);
1666 /* See also ptlrpc_lprocfs_rd_timeouts */
1667 int lprocfs_rd_timeouts(char *page, char **start, off_t off, int count,
1668 int *eof, void *data)
1670 struct obd_device *obd = (struct obd_device *)data;
1671 struct obd_import *imp;
1672 unsigned int cur, worst;
1677 LASSERT(obd != NULL);
1678 LPROCFS_CLIMP_CHECK(obd);
1679 imp = obd->u.cli.cl_import;
1682 now = cfs_time_current_sec();
1684 /* Some network health info for kicks */
1685 s2dhms(&ts, now - imp->imp_last_reply_time);
1686 rc += snprintf(page + rc, count - rc,
1687 "%-10s : %ld, "DHMS_FMT" ago\n",
1688 "last reply", imp->imp_last_reply_time, DHMS_VARS(&ts));
1690 cur = at_get(&imp->imp_at.iat_net_latency);
1691 worst = imp->imp_at.iat_net_latency.at_worst_ever;
1692 worstt = imp->imp_at.iat_net_latency.at_worst_time;
1693 s2dhms(&ts, now - worstt);
1694 rc += snprintf(page + rc, count - rc,
1695 "%-10s : cur %3u worst %3u (at %ld, "DHMS_FMT" ago) ",
1696 "network", cur, worst, worstt, DHMS_VARS(&ts));
1697 rc = lprocfs_at_hist_helper(page, count, rc,
1698 &imp->imp_at.iat_net_latency);
1700 for(i = 0; i < IMP_AT_MAX_PORTALS; i++) {
1701 if (imp->imp_at.iat_portal[i] == 0)
1703 cur = at_get(&imp->imp_at.iat_service_estimate[i]);
1704 worst = imp->imp_at.iat_service_estimate[i].at_worst_ever;
1705 worstt = imp->imp_at.iat_service_estimate[i].at_worst_time;
1706 s2dhms(&ts, now - worstt);
1707 rc += snprintf(page + rc, count - rc,
1708 "portal %-2d : cur %3u worst %3u (at %ld, "
1709 DHMS_FMT" ago) ", imp->imp_at.iat_portal[i],
1710 cur, worst, worstt, DHMS_VARS(&ts));
1711 rc = lprocfs_at_hist_helper(page, count, rc,
1712 &imp->imp_at.iat_service_estimate[i]);
1715 LPROCFS_CLIMP_EXIT(obd);
1718 EXPORT_SYMBOL(lprocfs_rd_timeouts);
1720 int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
1721 int count, int *eof, void *data)
1723 struct obd_device *obd = data;
1727 LPROCFS_CLIMP_CHECK(obd);
1728 flags = obd->u.cli.cl_import->imp_connect_data.ocd_connect_flags;
1729 ret = snprintf(page, count, "flags="LPX64"\n", flags);
1730 ret += obd_connect_flags2str(page + ret, count - ret, flags, "\n");
1731 ret += snprintf(page + ret, count - ret, "\n");
1732 LPROCFS_CLIMP_EXIT(obd);
1735 EXPORT_SYMBOL(lprocfs_rd_connect_flags);
1737 int lprocfs_rd_numrefs(char *page, char **start, off_t off, int count,
1738 int *eof, void *data)
1740 struct obd_type *class = (struct obd_type*) data;
1742 LASSERT(class != NULL);
1744 return snprintf(page, count, "%d\n", class->typ_refcnt);
1746 EXPORT_SYMBOL(lprocfs_rd_numrefs);
1748 int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list)
1752 LASSERT(obd != NULL);
1753 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1754 LASSERT(obd->obd_type->typ_procroot != NULL);
1756 obd->obd_proc_entry = lprocfs_register(obd->obd_name,
1757 obd->obd_type->typ_procroot,
1759 if (IS_ERR(obd->obd_proc_entry)) {
1760 rc = PTR_ERR(obd->obd_proc_entry);
1761 CERROR("error %d setting up lprocfs for %s\n",rc,obd->obd_name);
1762 obd->obd_proc_entry = NULL;
1766 EXPORT_SYMBOL(lprocfs_obd_setup);
1770 lprocfs_seq_obd_setup(struct obd_device *obd)
1774 LASSERT(obd != NULL);
1775 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1776 LASSERT(obd->obd_type->typ_procroot != NULL);
1778 obd->obd_proc_entry = lprocfs_seq_register(obd->obd_name,
1779 obd->obd_type->typ_procroot,
1780 obd->obd_vars, obd);
1781 if (IS_ERR(obd->obd_proc_entry)) {
1782 rc = PTR_ERR(obd->obd_proc_entry);
1783 CERROR("error %d setting up lprocfs for %s\n",rc,obd->obd_name);
1784 obd->obd_proc_entry = NULL;
1788 EXPORT_SYMBOL(lprocfs_seq_obd_setup);
1790 int lprocfs_obd_cleanup(struct obd_device *obd)
1794 if (obd->obd_proc_exports_entry) {
1795 /* Should be no exports left */
1796 lprocfs_remove(&obd->obd_proc_exports_entry);
1797 obd->obd_proc_exports_entry = NULL;
1799 if (obd->obd_proc_entry) {
1800 lprocfs_remove(&obd->obd_proc_entry);
1801 obd->obd_proc_entry = NULL;
1805 EXPORT_SYMBOL(lprocfs_obd_cleanup);
1807 int lprocfs_stats_alloc_one(struct lprocfs_stats *stats, unsigned int cpuid)
1809 struct lprocfs_counter *cntr;
1810 unsigned int percpusize;
1812 unsigned long flags = 0;
1815 LASSERT(stats->ls_percpu[cpuid] == NULL);
1816 LASSERT((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0);
1818 percpusize = lprocfs_stats_counter_size(stats);
1819 LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[cpuid], percpusize);
1820 if (stats->ls_percpu[cpuid] != NULL) {
1822 if (unlikely(stats->ls_biggest_alloc_num <= cpuid)) {
1823 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
1824 spin_lock_irqsave(&stats->ls_lock, flags);
1826 spin_lock(&stats->ls_lock);
1827 if (stats->ls_biggest_alloc_num <= cpuid)
1828 stats->ls_biggest_alloc_num = cpuid + 1;
1829 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) {
1830 spin_unlock_irqrestore(&stats->ls_lock, flags);
1832 spin_unlock(&stats->ls_lock);
1835 /* initialize the ls_percpu[cpuid] non-zero counter */
1836 for (i = 0; i < stats->ls_num; ++i) {
1837 cntr = lprocfs_stats_counter_get(stats, cpuid, i);
1838 cntr->lc_min = LC_MIN_INIT;
1843 EXPORT_SYMBOL(lprocfs_stats_alloc_one);
1845 struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num,
1846 enum lprocfs_stats_flags flags)
1848 struct lprocfs_stats *stats;
1849 unsigned int num_entry;
1850 unsigned int percpusize = 0;
1856 if (lprocfs_no_percpu_stats != 0)
1857 flags |= LPROCFS_STATS_FLAG_NOPERCPU;
1859 if (flags & LPROCFS_STATS_FLAG_NOPERCPU)
1862 num_entry = num_possible_cpus();
1864 /* alloc percpu pointers for all possible cpu slots */
1865 LIBCFS_ALLOC(stats, offsetof(typeof(*stats), ls_percpu[num_entry]));
1869 stats->ls_num = num;
1870 stats->ls_flags = flags;
1871 spin_lock_init(&stats->ls_lock);
1873 /* alloc num of counter headers */
1874 LIBCFS_ALLOC(stats->ls_cnt_header,
1875 stats->ls_num * sizeof(struct lprocfs_counter_header));
1876 if (stats->ls_cnt_header == NULL)
1879 if ((flags & LPROCFS_STATS_FLAG_NOPERCPU) != 0) {
1880 /* contains only one set counters */
1881 percpusize = lprocfs_stats_counter_size(stats);
1882 LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[0], percpusize);
1883 if (stats->ls_percpu[0] == NULL)
1885 stats->ls_biggest_alloc_num = 1;
1886 } else if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0) {
1887 /* alloc all percpu data, currently only obd_memory use this */
1888 for (i = 0; i < num_entry; ++i)
1889 if (lprocfs_stats_alloc_one(stats, i) < 0)
1896 lprocfs_free_stats(&stats);
1899 EXPORT_SYMBOL(lprocfs_alloc_stats);
1901 void lprocfs_free_stats(struct lprocfs_stats **statsh)
1903 struct lprocfs_stats *stats = *statsh;
1904 unsigned int num_entry;
1905 unsigned int percpusize;
1908 if (stats == NULL || stats->ls_num == 0)
1912 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU)
1915 num_entry = num_possible_cpus();
1917 percpusize = lprocfs_stats_counter_size(stats);
1918 for (i = 0; i < num_entry; i++)
1919 if (stats->ls_percpu[i] != NULL)
1920 LIBCFS_FREE(stats->ls_percpu[i], percpusize);
1921 if (stats->ls_cnt_header != NULL)
1922 LIBCFS_FREE(stats->ls_cnt_header, stats->ls_num *
1923 sizeof(struct lprocfs_counter_header));
1924 LIBCFS_FREE(stats, offsetof(typeof(*stats), ls_percpu[num_entry]));
1926 EXPORT_SYMBOL(lprocfs_free_stats);
1928 void lprocfs_clear_stats(struct lprocfs_stats *stats)
1930 struct lprocfs_counter *percpu_cntr;
1933 unsigned int num_entry;
1934 unsigned long flags = 0;
1936 num_entry = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1938 for (i = 0; i < num_entry; i++) {
1939 if (stats->ls_percpu[i] == NULL)
1941 for (j = 0; j < stats->ls_num; j++) {
1942 percpu_cntr = lprocfs_stats_counter_get(stats, i, j);
1943 percpu_cntr->lc_count = 0;
1944 percpu_cntr->lc_min = LC_MIN_INIT;
1945 percpu_cntr->lc_max = 0;
1946 percpu_cntr->lc_sumsquare = 0;
1947 percpu_cntr->lc_sum = 0;
1948 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
1949 percpu_cntr->lc_sum_irq = 0;
1953 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1955 EXPORT_SYMBOL(lprocfs_clear_stats);
1957 static ssize_t lprocfs_stats_seq_write(struct file *file, const char *buf,
1958 size_t len, loff_t *off)
1960 struct seq_file *seq = file->private_data;
1961 struct lprocfs_stats *stats = seq->private;
1963 lprocfs_clear_stats(stats);
1968 static void *lprocfs_stats_seq_start(struct seq_file *p, loff_t *pos)
1970 struct lprocfs_stats *stats = p->private;
1972 return (*pos < stats->ls_num) ? pos : NULL;
1975 static void lprocfs_stats_seq_stop(struct seq_file *p, void *v)
1979 static void *lprocfs_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
1983 return lprocfs_stats_seq_start(p, pos);
1986 /* seq file export of one lprocfs counter */
1987 static int lprocfs_stats_seq_show(struct seq_file *p, void *v)
1989 struct lprocfs_stats *stats = p->private;
1990 struct lprocfs_counter_header *hdr;
1991 struct lprocfs_counter ctr;
1992 int idx = *(loff_t *)v;
1998 do_gettimeofday(&now);
1999 rc = seq_printf(p, "%-25s %lu.%lu secs.usecs\n",
2000 "snapshot_time", now.tv_sec, now.tv_usec);
2005 hdr = &stats->ls_cnt_header[idx];
2006 lprocfs_stats_collect(stats, idx, &ctr);
2008 if (ctr.lc_count == 0)
2011 rc = seq_printf(p, "%-25s "LPD64" samples [%s]", hdr->lc_name,
2012 ctr.lc_count, hdr->lc_units);
2016 if ((hdr->lc_config & LPROCFS_CNTR_AVGMINMAX) && ctr.lc_count > 0) {
2017 rc = seq_printf(p, " "LPD64" "LPD64" "LPD64,
2018 ctr.lc_min, ctr.lc_max, ctr.lc_sum);
2021 if (hdr->lc_config & LPROCFS_CNTR_STDDEV)
2022 rc = seq_printf(p, " "LPD64, ctr.lc_sumsquare);
2026 rc = seq_printf(p, "\n");
2028 return (rc < 0) ? rc : 0;
2031 struct seq_operations lprocfs_stats_seq_sops = {
2032 .start = lprocfs_stats_seq_start,
2033 .stop = lprocfs_stats_seq_stop,
2034 .next = lprocfs_stats_seq_next,
2035 .show = lprocfs_stats_seq_show,
2038 static int lprocfs_stats_seq_open(struct inode *inode, struct file *file)
2040 struct seq_file *seq;
2043 #ifndef HAVE_ONLY_PROCFS_SEQ
2044 if (LPROCFS_ENTRY_CHECK(PDE(inode)))
2047 rc = seq_open(file, &lprocfs_stats_seq_sops);
2050 seq = file->private_data;
2051 seq->private = PDE_DATA(inode);
2055 struct file_operations lprocfs_stats_seq_fops = {
2056 .owner = THIS_MODULE,
2057 .open = lprocfs_stats_seq_open,
2059 .write = lprocfs_stats_seq_write,
2060 .llseek = seq_lseek,
2061 .release = lprocfs_seq_release,
2064 int lprocfs_register_stats(struct proc_dir_entry *root, const char *name,
2065 struct lprocfs_stats *stats)
2067 struct proc_dir_entry *entry;
2068 LASSERT(root != NULL);
2070 entry = proc_create_data(name, 0644, root,
2071 &lprocfs_stats_seq_fops, stats);
2076 EXPORT_SYMBOL(lprocfs_register_stats);
2078 void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
2079 unsigned conf, const char *name, const char *units)
2081 struct lprocfs_counter_header *header;
2082 struct lprocfs_counter *percpu_cntr;
2083 unsigned long flags = 0;
2085 unsigned int num_cpu;
2087 LASSERT(stats != NULL);
2089 header = &stats->ls_cnt_header[index];
2090 LASSERTF(header != NULL, "Failed to allocate stats header:[%d]%s/%s\n",
2091 index, name, units);
2093 header->lc_config = conf;
2094 header->lc_name = name;
2095 header->lc_units = units;
2097 num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
2098 for (i = 0; i < num_cpu; ++i) {
2099 if (stats->ls_percpu[i] == NULL)
2101 percpu_cntr = lprocfs_stats_counter_get(stats, i, index);
2102 percpu_cntr->lc_count = 0;
2103 percpu_cntr->lc_min = LC_MIN_INIT;
2104 percpu_cntr->lc_max = 0;
2105 percpu_cntr->lc_sumsquare = 0;
2106 percpu_cntr->lc_sum = 0;
2107 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
2108 percpu_cntr->lc_sum_irq = 0;
2110 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
2112 EXPORT_SYMBOL(lprocfs_counter_init);
2114 /* Note that we only init md counters for ops whose offset is less
2115 * than NUM_MD_STATS. This is explained in a comment in the definition
2116 * of struct md_ops. */
2117 #define LPROCFS_MD_OP_INIT(base, stats, op) \
2119 unsigned int _idx = base + MD_COUNTER_OFFSET(op); \
2121 if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS) { \
2122 LASSERT(_idx < stats->ls_num); \
2123 lprocfs_counter_init(stats, _idx, 0, #op, "reqs"); \
2127 void lprocfs_init_mps_stats(int num_private_stats, struct lprocfs_stats *stats)
2129 LPROCFS_MD_OP_INIT(num_private_stats, stats, getstatus);
2130 LPROCFS_MD_OP_INIT(num_private_stats, stats, null_inode);
2131 LPROCFS_MD_OP_INIT(num_private_stats, stats, find_cbdata);
2132 LPROCFS_MD_OP_INIT(num_private_stats, stats, close);
2133 LPROCFS_MD_OP_INIT(num_private_stats, stats, create);
2134 LPROCFS_MD_OP_INIT(num_private_stats, stats, done_writing);
2135 LPROCFS_MD_OP_INIT(num_private_stats, stats, enqueue);
2136 LPROCFS_MD_OP_INIT(num_private_stats, stats, getattr);
2137 LPROCFS_MD_OP_INIT(num_private_stats, stats, getattr_name);
2138 LPROCFS_MD_OP_INIT(num_private_stats, stats, intent_lock);
2139 LPROCFS_MD_OP_INIT(num_private_stats, stats, link);
2140 LPROCFS_MD_OP_INIT(num_private_stats, stats, rename);
2141 LPROCFS_MD_OP_INIT(num_private_stats, stats, setattr);
2142 LPROCFS_MD_OP_INIT(num_private_stats, stats, fsync);
2143 LPROCFS_MD_OP_INIT(num_private_stats, stats, read_page);
2144 LPROCFS_MD_OP_INIT(num_private_stats, stats, unlink);
2145 LPROCFS_MD_OP_INIT(num_private_stats, stats, setxattr);
2146 LPROCFS_MD_OP_INIT(num_private_stats, stats, getxattr);
2147 LPROCFS_MD_OP_INIT(num_private_stats, stats, init_ea_size);
2148 LPROCFS_MD_OP_INIT(num_private_stats, stats, get_lustre_md);
2149 LPROCFS_MD_OP_INIT(num_private_stats, stats, free_lustre_md);
2150 LPROCFS_MD_OP_INIT(num_private_stats, stats, update_lsm_md);
2151 LPROCFS_MD_OP_INIT(num_private_stats, stats, merge_attr);
2152 LPROCFS_MD_OP_INIT(num_private_stats, stats, set_open_replay_data);
2153 LPROCFS_MD_OP_INIT(num_private_stats, stats, clear_open_replay_data);
2154 LPROCFS_MD_OP_INIT(num_private_stats, stats, set_lock_data);
2155 LPROCFS_MD_OP_INIT(num_private_stats, stats, lock_match);
2156 LPROCFS_MD_OP_INIT(num_private_stats, stats, cancel_unused);
2157 LPROCFS_MD_OP_INIT(num_private_stats, stats, renew_capa);
2158 LPROCFS_MD_OP_INIT(num_private_stats, stats, unpack_capa);
2159 LPROCFS_MD_OP_INIT(num_private_stats, stats, get_remote_perm);
2160 LPROCFS_MD_OP_INIT(num_private_stats, stats, intent_getattr_async);
2161 LPROCFS_MD_OP_INIT(num_private_stats, stats, revalidate_lock);
2163 EXPORT_SYMBOL(lprocfs_init_mps_stats);
2165 int lprocfs_alloc_md_stats(struct obd_device *obd,
2166 unsigned int num_private_stats)
2168 struct lprocfs_stats *stats;
2169 unsigned int num_stats;
2172 CLASSERT(offsetof(struct md_ops, MD_STATS_FIRST_OP) == 0);
2173 CLASSERT(_MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) == 0);
2174 CLASSERT(_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) > 0);
2176 /* TODO Ensure that this function is only used where
2177 * appropriate by adding an assertion to the effect that
2178 * obd->obd_type->typ_md_ops is not NULL. We can't do this now
2179 * because mdt_procfs_init() uses this function to allocate
2180 * the stats backing /proc/fs/lustre/mdt/.../md_stats but the
2181 * mdt layer does not use the md_ops interface. This is
2182 * confusing and a waste of memory. See LU-2484.
2184 LASSERT(obd->obd_proc_entry != NULL);
2185 LASSERT(obd->obd_md_stats == NULL);
2186 LASSERT(obd->obd_md_cntr_base == 0);
2188 num_stats = NUM_MD_STATS + num_private_stats;
2189 stats = lprocfs_alloc_stats(num_stats, 0);
2193 lprocfs_init_mps_stats(num_private_stats, stats);
2195 for (i = num_private_stats; i < num_stats; i++) {
2196 if (stats->ls_cnt_header[i].lc_name == NULL) {
2197 CERROR("Missing md_stat initializer md_op "
2198 "operation at offset %d. Aborting.\n",
2199 i - num_private_stats);
2204 rc = lprocfs_register_stats(obd->obd_proc_entry, "md_stats", stats);
2206 lprocfs_free_stats(&stats);
2208 obd->obd_md_stats = stats;
2209 obd->obd_md_cntr_base = num_private_stats;
2214 EXPORT_SYMBOL(lprocfs_alloc_md_stats);
2216 void lprocfs_free_md_stats(struct obd_device *obd)
2218 struct lprocfs_stats *stats = obd->obd_md_stats;
2220 if (stats != NULL) {
2221 obd->obd_md_stats = NULL;
2222 obd->obd_md_cntr_base = 0;
2223 lprocfs_free_stats(&stats);
2226 EXPORT_SYMBOL(lprocfs_free_md_stats);
2228 void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
2230 lprocfs_counter_init(ldlm_stats,
2231 LDLM_ENQUEUE - LDLM_FIRST_OPC,
2232 0, "ldlm_enqueue", "reqs");
2233 lprocfs_counter_init(ldlm_stats,
2234 LDLM_CONVERT - LDLM_FIRST_OPC,
2235 0, "ldlm_convert", "reqs");
2236 lprocfs_counter_init(ldlm_stats,
2237 LDLM_CANCEL - LDLM_FIRST_OPC,
2238 0, "ldlm_cancel", "reqs");
2239 lprocfs_counter_init(ldlm_stats,
2240 LDLM_BL_CALLBACK - LDLM_FIRST_OPC,
2241 0, "ldlm_bl_callback", "reqs");
2242 lprocfs_counter_init(ldlm_stats,
2243 LDLM_CP_CALLBACK - LDLM_FIRST_OPC,
2244 0, "ldlm_cp_callback", "reqs");
2245 lprocfs_counter_init(ldlm_stats,
2246 LDLM_GL_CALLBACK - LDLM_FIRST_OPC,
2247 0, "ldlm_gl_callback", "reqs");
2249 EXPORT_SYMBOL(lprocfs_init_ldlm_stats);
2251 __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
2252 struct lprocfs_counter_header *header,
2253 enum lprocfs_stats_flags flags,
2254 enum lprocfs_fields_flags field)
2258 if (lc == NULL || header == NULL)
2262 case LPROCFS_FIELDS_FLAGS_CONFIG:
2263 ret = header->lc_config;
2265 case LPROCFS_FIELDS_FLAGS_SUM:
2267 if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
2268 ret += lc->lc_sum_irq;
2270 case LPROCFS_FIELDS_FLAGS_MIN:
2273 case LPROCFS_FIELDS_FLAGS_MAX:
2276 case LPROCFS_FIELDS_FLAGS_AVG:
2277 ret = (lc->lc_max - lc->lc_min) / 2;
2279 case LPROCFS_FIELDS_FLAGS_SUMSQUARE:
2280 ret = lc->lc_sumsquare;
2282 case LPROCFS_FIELDS_FLAGS_COUNT:
2290 EXPORT_SYMBOL(lprocfs_read_helper);
2292 int lprocfs_write_helper(const char *buffer, unsigned long count,
2295 return lprocfs_write_frac_helper(buffer, count, val, 1);
2297 EXPORT_SYMBOL(lprocfs_write_helper);
2299 int lprocfs_write_frac_helper(const char *buffer, unsigned long count,
2302 char kernbuf[20], *end, *pbuf;
2304 if (count > (sizeof(kernbuf) - 1))
2307 if (copy_from_user(kernbuf, buffer, count))
2310 kernbuf[count] = '\0';
2317 *val = (int)simple_strtoul(pbuf, &end, 10) * mult;
2321 if (end != NULL && *end == '.') {
2322 int temp_val, pow = 1;
2326 if (strlen(pbuf) > 5)
2327 pbuf[5] = '\0'; /*only allow 5bits fractional*/
2329 temp_val = (int)simple_strtoul(pbuf, &end, 10) * mult;
2332 for (i = 0; i < (end - pbuf); i++)
2335 *val += temp_val / pow;
2340 EXPORT_SYMBOL(lprocfs_write_frac_helper);
2342 int lprocfs_read_frac_helper(char *buffer, unsigned long count, long val,
2345 long decimal_val, frac_val;
2351 decimal_val = val / mult;
2352 prtn = snprintf(buffer, count, "%ld", decimal_val);
2353 frac_val = val % mult;
2355 if (prtn < (count - 4) && frac_val > 0) {
2357 int i, temp_mult = 1, frac_bits = 0;
2359 temp_frac = frac_val * 10;
2360 buffer[prtn++] = '.';
2361 while (frac_bits < 2 && (temp_frac / mult) < 1 ) {
2362 /* only reserved 2 bits fraction */
2363 buffer[prtn++] ='0';
2368 * Need to think these cases :
2369 * 1. #echo x.00 > /proc/xxx output result : x
2370 * 2. #echo x.0x > /proc/xxx output result : x.0x
2371 * 3. #echo x.x0 > /proc/xxx output result : x.x
2372 * 4. #echo x.xx > /proc/xxx output result : x.xx
2373 * Only reserved 2 bits fraction.
2375 for (i = 0; i < (5 - prtn); i++)
2378 frac_bits = min((int)count - prtn, 3 - frac_bits);
2379 prtn += snprintf(buffer + prtn, frac_bits, "%ld",
2380 frac_val * temp_mult / mult);
2383 while(buffer[prtn] < '1' || buffer[prtn] > '9') {
2385 if (buffer[prtn] == '.') {
2392 buffer[prtn++] ='\n';
2395 EXPORT_SYMBOL(lprocfs_read_frac_helper);
2397 int lprocfs_seq_read_frac_helper(struct seq_file *m, long val, int mult)
2399 long decimal_val, frac_val;
2401 decimal_val = val / mult;
2402 seq_printf(m, "%ld", decimal_val);
2403 frac_val = val % mult;
2410 /* Three cases: x0, xx, 0x */
2411 if ((frac_val % 10) != 0)
2412 seq_printf(m, ".%ld", frac_val);
2414 seq_printf(m, ".%ld", frac_val / 10);
2417 seq_printf(m, "\n");
2420 EXPORT_SYMBOL(lprocfs_seq_read_frac_helper);
2422 int lprocfs_write_u64_helper(const char *buffer, unsigned long count,__u64 *val)
2424 return lprocfs_write_frac_u64_helper(buffer, count, val, 1);
2426 EXPORT_SYMBOL(lprocfs_write_u64_helper);
2428 int lprocfs_write_frac_u64_helper(const char *buffer, unsigned long count,
2429 __u64 *val, int mult)
2431 char kernbuf[22], *end, *pbuf;
2432 __u64 whole, frac = 0, units;
2433 unsigned frac_d = 1;
2435 if (count > (sizeof(kernbuf) - 1))
2438 if (copy_from_user(kernbuf, buffer, count))
2441 kernbuf[count] = '\0';
2448 whole = simple_strtoull(pbuf, &end, 10);
2452 if (end != NULL && *end == '.') {
2456 /* need to limit frac_d to a __u32 */
2457 if (strlen(pbuf) > 10)
2460 frac = simple_strtoull(pbuf, &end, 10);
2461 /* count decimal places */
2462 for (i = 0; i < (end - pbuf); i++)
2481 /* Specified units override the multiplier */
2483 mult = mult < 0 ? -units : units;
2486 do_div(frac, frac_d);
2487 *val = whole * mult + frac;
2490 EXPORT_SYMBOL(lprocfs_write_frac_u64_helper);
2492 static char *lprocfs_strnstr(const char *s1, const char *s2, size_t len)
2501 if (!memcmp(s1, s2, l2))
2509 * Find the string \a name in the input \a buffer, and return a pointer to the
2510 * value immediately following \a name, reducing \a count appropriately.
2511 * If \a name is not found the original \a buffer is returned.
2513 char *lprocfs_find_named_value(const char *buffer, const char *name,
2517 size_t buflen = *count;
2519 /* there is no strnstr() in rhel5 and ubuntu kernels */
2520 val = lprocfs_strnstr(buffer, name, buflen);
2522 return (char *)buffer;
2524 val += strlen(name); /* skip prefix */
2525 while (val < buffer + buflen && isspace(*val)) /* skip separator */
2529 while (val < buffer + buflen && isalnum(*val)) {
2534 return val - *count;
2536 EXPORT_SYMBOL(lprocfs_find_named_value);
2538 int lprocfs_seq_create(struct proc_dir_entry *parent,
2541 const struct file_operations *seq_fops,
2544 struct proc_dir_entry *entry;
2547 /* Disallow secretly (un)writable entries. */
2548 LASSERT((seq_fops->write == NULL) == ((mode & 0222) == 0));
2550 entry = proc_create_data(name, mode, parent, seq_fops, data);
2557 EXPORT_SYMBOL(lprocfs_seq_create);
2559 int lprocfs_obd_seq_create(struct obd_device *dev,
2562 const struct file_operations *seq_fops,
2565 return (lprocfs_seq_create(dev->obd_proc_entry, name,
2566 mode, seq_fops, data));
2568 EXPORT_SYMBOL(lprocfs_obd_seq_create);
2570 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
2572 if (value >= OBD_HIST_MAX)
2573 value = OBD_HIST_MAX - 1;
2575 spin_lock(&oh->oh_lock);
2576 oh->oh_buckets[value]++;
2577 spin_unlock(&oh->oh_lock);
2579 EXPORT_SYMBOL(lprocfs_oh_tally);
2581 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
2583 unsigned int val = 0;
2585 if (likely(value != 0))
2586 val = min(fls(value - 1), OBD_HIST_MAX);
2588 lprocfs_oh_tally(oh, val);
2590 EXPORT_SYMBOL(lprocfs_oh_tally_log2);
2592 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
2594 unsigned long ret = 0;
2597 for (i = 0; i < OBD_HIST_MAX; i++)
2598 ret += oh->oh_buckets[i];
2601 EXPORT_SYMBOL(lprocfs_oh_sum);
2603 void lprocfs_oh_clear(struct obd_histogram *oh)
2605 spin_lock(&oh->oh_lock);
2606 memset(oh->oh_buckets, 0, sizeof(oh->oh_buckets));
2607 spin_unlock(&oh->oh_lock);
2609 EXPORT_SYMBOL(lprocfs_oh_clear);
2611 int lprocfs_obd_rd_max_pages_per_rpc(char *page, char **start, off_t off,
2612 int count, int *eof, void *data)
2614 struct obd_device *dev = data;
2615 struct client_obd *cli = &dev->u.cli;
2618 client_obd_list_lock(&cli->cl_loi_list_lock);
2619 rc = snprintf(page, count, "%d\n", cli->cl_max_pages_per_rpc);
2620 client_obd_list_unlock(&cli->cl_loi_list_lock);
2623 EXPORT_SYMBOL(lprocfs_obd_rd_max_pages_per_rpc);
2625 int lprocfs_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *data)
2627 struct obd_device *dev = data;
2628 struct client_obd *cli = &dev->u.cli;
2631 client_obd_list_lock(&cli->cl_loi_list_lock);
2632 rc = seq_printf(m, "%d\n", cli->cl_max_pages_per_rpc);
2633 client_obd_list_unlock(&cli->cl_loi_list_lock);
2636 EXPORT_SYMBOL(lprocfs_obd_max_pages_per_rpc_seq_show);
2638 int lprocfs_wr_root_squash(const char __user *buffer, unsigned long count,
2639 struct root_squash_info *squash, char *name)
2642 char kernbuf[64], *tmp, *errmsg;
2643 unsigned long uid, gid;
2646 if (count >= sizeof(kernbuf)) {
2647 errmsg = "string too long";
2648 GOTO(failed_noprint, rc = -EINVAL);
2650 if (copy_from_user(kernbuf, buffer, count)) {
2651 errmsg = "bad address";
2652 GOTO(failed_noprint, rc = -EFAULT);
2654 kernbuf[count] = '\0';
2656 /* look for uid gid separator */
2657 tmp = strchr(kernbuf, ':');
2659 errmsg = "needs uid:gid format";
2660 GOTO(failed, rc = -EINVAL);
2666 if (kstrtoul(kernbuf, 0, &uid) != 0) {
2668 GOTO(failed, rc = -EINVAL);
2672 if (kstrtoul(tmp, 0, &gid) != 0) {
2674 GOTO(failed, rc = -EINVAL);
2677 squash->rsi_uid = uid;
2678 squash->rsi_gid = gid;
2680 LCONSOLE_INFO("%s: root_squash is set to %u:%u\n",
2681 name, squash->rsi_uid, squash->rsi_gid);
2689 CWARN("%s: failed to set root_squash to \"%s\", %s, rc = %d\n",
2690 name, kernbuf, errmsg, rc);
2693 CWARN("%s: failed to set root_squash due to %s, rc = %d\n",
2697 EXPORT_SYMBOL(lprocfs_wr_root_squash);
2700 int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count,
2701 struct root_squash_info *squash, char *name)
2704 char *kernbuf = NULL;
2706 struct list_head tmp;
2710 errmsg = "string too long";
2711 GOTO(failed, rc = -EINVAL);
2714 OBD_ALLOC(kernbuf, count + 1);
2715 if (kernbuf == NULL) {
2716 errmsg = "no memory";
2717 GOTO(failed, rc = -ENOMEM);
2719 if (copy_from_user(kernbuf, buffer, count)) {
2720 errmsg = "bad address";
2721 GOTO(failed, rc = -EFAULT);
2723 kernbuf[count] = '\0';
2725 if (count > 0 && kernbuf[count - 1] == '\n')
2726 kernbuf[count - 1] = '\0';
2728 if (strcmp(kernbuf, "NONE") == 0 || strcmp(kernbuf, "clear") == 0) {
2729 /* empty string is special case */
2730 down_write(&squash->rsi_sem);
2731 if (!list_empty(&squash->rsi_nosquash_nids))
2732 cfs_free_nidlist(&squash->rsi_nosquash_nids);
2733 up_write(&squash->rsi_sem);
2734 LCONSOLE_INFO("%s: nosquash_nids is cleared\n", name);
2735 OBD_FREE(kernbuf, count + 1);
2739 INIT_LIST_HEAD(&tmp);
2740 if (cfs_parse_nidlist(kernbuf, count, &tmp) <= 0) {
2741 errmsg = "can't parse";
2742 GOTO(failed, rc = -EINVAL);
2744 LCONSOLE_INFO("%s: nosquash_nids set to %s\n",
2746 OBD_FREE(kernbuf, count + 1);
2749 down_write(&squash->rsi_sem);
2750 if (!list_empty(&squash->rsi_nosquash_nids))
2751 cfs_free_nidlist(&squash->rsi_nosquash_nids);
2752 list_splice(&tmp, &squash->rsi_nosquash_nids);
2753 up_write(&squash->rsi_sem);
2759 CWARN("%s: failed to set nosquash_nids to \"%s\", %s rc = %d\n",
2760 name, kernbuf, errmsg, rc);
2761 OBD_FREE(kernbuf, count + 1);
2763 CWARN("%s: failed to set nosquash_nids due to %s rc = %d\n",
2768 EXPORT_SYMBOL(lprocfs_wr_nosquash_nids);