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 ? "" : ", "); \
822 static void obd_import_flags2seqstr(struct obd_import *imp, struct seq_file *m)
826 if (imp->imp_obd->obd_no_recov) {
827 seq_printf(m, "no_recov");
831 flag2seqstr(invalid);
832 flag2seqstr(deactive);
833 flag2seqstr(replayable);
834 flag2seqstr(delayed_recovery);
835 flag2seqstr(no_lock_replay);
836 flag2seqstr(vbr_failed);
837 flag2seqstr(pingable);
838 flag2seqstr(resend_replay);
839 flag2seqstr(no_pinger_recover);
840 flag2seqstr(need_mne_swab);
841 flag2seqstr(connect_tried);
845 static const char *obd_connect_names[] = {
859 "join_file(obsolete)",
863 "remote_client_by_force",
872 "mds_mds_connection",
875 "alt_checksum_algorithm",
907 static void obd_connect_seq_flags2str(struct seq_file *m, __u64 flags, char *sep)
913 for (i = 0; obd_connect_names[i] != NULL; i++, mask <<= 1) {
915 seq_printf(m, "%s%s",
916 first ? "" : sep, obd_connect_names[i]);
920 if (flags & ~(mask - 1))
921 seq_printf(m, "%sunknown_"LPX64,
922 first ? "" : sep, flags & ~(mask - 1));
925 int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep)
930 for (i = 0; obd_connect_names[i] != NULL; i++, mask <<= 1) {
932 ret += snprintf(page + ret, count - ret, "%s%s",
933 ret ? sep : "", obd_connect_names[i]);
935 if (flags & ~(mask - 1))
936 ret += snprintf(page + ret, count - ret,
938 ret ? sep : "", flags & ~(mask - 1));
941 EXPORT_SYMBOL(obd_connect_flags2str);
943 static void obd_connect_data_seqprint(struct seq_file *m,
944 struct obd_connect_data *ocd)
948 LASSERT(ocd != NULL);
949 flags = ocd->ocd_connect_flags;
951 seq_printf(m, " connect_data:\n"
954 ocd->ocd_connect_flags,
956 if (flags & OBD_CONNECT_VERSION)
957 seq_printf(m, " target_version: %u.%u.%u.%u\n",
958 OBD_OCD_VERSION_MAJOR(ocd->ocd_version),
959 OBD_OCD_VERSION_MINOR(ocd->ocd_version),
960 OBD_OCD_VERSION_PATCH(ocd->ocd_version),
961 OBD_OCD_VERSION_FIX(ocd->ocd_version));
962 if (flags & OBD_CONNECT_MDS)
963 seq_printf(m, " mdt_index: %d\n", ocd->ocd_group);
964 if (flags & OBD_CONNECT_GRANT)
965 seq_printf(m, " initial_grant: %d\n", ocd->ocd_grant);
966 if (flags & OBD_CONNECT_INDEX)
967 seq_printf(m, " target_index: %u\n", ocd->ocd_index);
968 if (flags & OBD_CONNECT_BRW_SIZE)
969 seq_printf(m, " max_brw_size: %d\n", ocd->ocd_brw_size);
970 if (flags & OBD_CONNECT_IBITS)
971 seq_printf(m, " ibits_known: "LPX64"\n",
972 ocd->ocd_ibits_known);
973 if (flags & OBD_CONNECT_GRANT_PARAM)
974 seq_printf(m, " grant_block_size: %d\n"
975 " grant_inode_size: %d\n"
976 " grant_extent_overhead: %d\n",
979 ocd->ocd_grant_extent);
980 if (flags & OBD_CONNECT_TRANSNO)
981 seq_printf(m, " first_transno: "LPX64"\n",
983 if (flags & OBD_CONNECT_CKSUM)
984 seq_printf(m, " cksum_types: %#x\n",
985 ocd->ocd_cksum_types);
986 if (flags & OBD_CONNECT_MAX_EASIZE)
987 seq_printf(m, " max_easize: %d\n", ocd->ocd_max_easize);
988 if (flags & OBD_CONNECT_MAXBYTES)
989 seq_printf(m, " max_object_bytes: "LPU64"\n",
993 int lprocfs_import_seq_show(struct seq_file *m, void *data)
995 struct lprocfs_counter ret;
996 struct lprocfs_counter_header *header;
997 struct obd_device *obd = (struct obd_device *)data;
998 struct obd_import *imp;
999 struct obd_import_conn *conn;
1000 struct obd_connect_data *ocd;
1005 LASSERT(obd != NULL);
1006 LPROCFS_CLIMP_CHECK(obd);
1007 imp = obd->u.cli.cl_import;
1008 ocd = &imp->imp_connect_data;
1010 seq_printf(m, "import:\n"
1014 " connect_flags: [ ",
1017 ptlrpc_import_state_name(imp->imp_state));
1018 obd_connect_seq_flags2str(m, imp->imp_connect_data.ocd_connect_flags,
1020 seq_printf(m, " ]\n");
1021 obd_connect_data_seqprint(m, ocd);
1022 seq_printf(m, " import_flags: [ ");
1023 obd_import_flags2seqstr(imp, m);
1025 seq_printf(m, " ]\n"
1027 " failover_nids: [ ");
1028 spin_lock(&imp->imp_lock);
1030 list_for_each_entry(conn, &imp->imp_conn_list, oic_item) {
1031 seq_printf(m, "%s%s", j ? ", " : "",
1032 libcfs_nid2str(conn->oic_conn->c_peer.nid));
1035 seq_printf(m, " ]\n"
1036 " current_connection: %s\n"
1037 " connection_attempts: %u\n"
1039 " in-progress_invalidations: %u\n",
1040 imp->imp_connection == NULL ? "<none>" :
1041 libcfs_nid2str(imp->imp_connection->c_peer.nid),
1043 imp->imp_generation,
1044 atomic_read(&imp->imp_inval_count));
1045 spin_unlock(&imp->imp_lock);
1047 if (obd->obd_svc_stats == NULL)
1050 header = &obd->obd_svc_stats->ls_cnt_header[PTLRPC_REQWAIT_CNTR];
1051 lprocfs_stats_collect(obd->obd_svc_stats, PTLRPC_REQWAIT_CNTR, &ret);
1052 if (ret.lc_count != 0) {
1053 /* first argument to do_div MUST be __u64 */
1054 __u64 sum = ret.lc_sum;
1055 do_div(sum, ret.lc_count);
1059 seq_printf(m, " rpcs:\n"
1061 " unregistering: %u\n"
1063 " avg_waittime: "LPU64" %s\n",
1064 atomic_read(&imp->imp_inflight),
1065 atomic_read(&imp->imp_unregistering),
1066 atomic_read(&imp->imp_timeouts),
1067 ret.lc_sum, header->lc_units);
1070 for(j = 0; j < IMP_AT_MAX_PORTALS; j++) {
1071 if (imp->imp_at.iat_portal[j] == 0)
1073 k = max_t(unsigned int, k,
1074 at_get(&imp->imp_at.iat_service_estimate[j]));
1076 seq_printf(m, " service_estimates:\n"
1077 " services: %u sec\n"
1078 " network: %u sec\n",
1080 at_get(&imp->imp_at.iat_net_latency));
1082 seq_printf(m, " transactions:\n"
1083 " last_replay: "LPU64"\n"
1084 " peer_committed: "LPU64"\n"
1085 " last_checked: "LPU64"\n",
1086 imp->imp_last_replay_transno,
1087 imp->imp_peer_committed_transno,
1088 imp->imp_last_transno_checked);
1090 /* avg data rates */
1091 for (rw = 0; rw <= 1; rw++) {
1092 lprocfs_stats_collect(obd->obd_svc_stats,
1093 PTLRPC_LAST_CNTR + BRW_READ_BYTES + rw,
1095 if (ret.lc_sum > 0 && ret.lc_count > 0) {
1096 /* first argument to do_div MUST be __u64 */
1097 __u64 sum = ret.lc_sum;
1098 do_div(sum, ret.lc_count);
1100 seq_printf(m, " %s_data_averages:\n"
1101 " bytes_per_rpc: "LPU64"\n",
1102 rw ? "write" : "read",
1105 k = (int)ret.lc_sum;
1106 j = opcode_offset(OST_READ + rw) + EXTRA_MAX_OPCODES;
1107 header = &obd->obd_svc_stats->ls_cnt_header[j];
1108 lprocfs_stats_collect(obd->obd_svc_stats, j, &ret);
1109 if (ret.lc_sum > 0 && ret.lc_count != 0) {
1110 /* first argument to do_div MUST be __u64 */
1111 __u64 sum = ret.lc_sum;
1112 do_div(sum, ret.lc_count);
1114 seq_printf(m, " %s_per_rpc: "LPU64"\n",
1115 header->lc_units, ret.lc_sum);
1116 j = (int)ret.lc_sum;
1118 seq_printf(m, " MB_per_sec: %u.%.02u\n",
1119 k / j, (100 * k / j) % 100);
1124 LPROCFS_CLIMP_EXIT(obd);
1127 EXPORT_SYMBOL(lprocfs_import_seq_show);
1129 int lprocfs_state_seq_show(struct seq_file *m, void *data)
1131 struct obd_device *obd = (struct obd_device *)data;
1132 struct obd_import *imp;
1135 LASSERT(obd != NULL);
1136 LPROCFS_CLIMP_CHECK(obd);
1137 imp = obd->u.cli.cl_import;
1139 seq_printf(m, "current_state: %s\n",
1140 ptlrpc_import_state_name(imp->imp_state));
1141 seq_printf(m, "state_history:\n");
1142 k = imp->imp_state_hist_idx;
1143 for (j = 0; j < IMP_STATE_HIST_LEN; j++) {
1144 struct import_state_hist *ish =
1145 &imp->imp_state_hist[(k + j) % IMP_STATE_HIST_LEN];
1146 if (ish->ish_state == 0)
1148 seq_printf(m, " - [ "CFS_TIME_T", %s ]\n",
1150 ptlrpc_import_state_name(ish->ish_state));
1153 LPROCFS_CLIMP_EXIT(obd);
1156 EXPORT_SYMBOL(lprocfs_state_seq_show);
1158 int lprocfs_seq_at_hist_helper(struct seq_file *m, struct adaptive_timeout *at)
1161 for (i = 0; i < AT_BINS; i++)
1162 seq_printf(m, "%3u ", at->at_hist[i]);
1163 seq_printf(m, "\n");
1166 EXPORT_SYMBOL(lprocfs_seq_at_hist_helper);
1168 /* See also ptlrpc_lprocfs_timeouts_show_seq */
1169 int lprocfs_timeouts_seq_show(struct seq_file *m, void *data)
1171 struct obd_device *obd = (struct obd_device *)data;
1172 struct obd_import *imp;
1173 unsigned int cur, worst;
1178 LASSERT(obd != NULL);
1179 LPROCFS_CLIMP_CHECK(obd);
1180 imp = obd->u.cli.cl_import;
1182 now = cfs_time_current_sec();
1184 /* Some network health info for kicks */
1185 s2dhms(&ts, now - imp->imp_last_reply_time);
1186 seq_printf(m, "%-10s : %ld, "DHMS_FMT" ago\n",
1187 "last reply", imp->imp_last_reply_time, DHMS_VARS(&ts));
1189 cur = at_get(&imp->imp_at.iat_net_latency);
1190 worst = imp->imp_at.iat_net_latency.at_worst_ever;
1191 worstt = imp->imp_at.iat_net_latency.at_worst_time;
1192 s2dhms(&ts, now - worstt);
1193 seq_printf(m, "%-10s : cur %3u worst %3u (at %ld, "DHMS_FMT" ago) ",
1194 "network", cur, worst, worstt, DHMS_VARS(&ts));
1195 lprocfs_seq_at_hist_helper(m, &imp->imp_at.iat_net_latency);
1197 for(i = 0; i < IMP_AT_MAX_PORTALS; i++) {
1198 if (imp->imp_at.iat_portal[i] == 0)
1200 cur = at_get(&imp->imp_at.iat_service_estimate[i]);
1201 worst = imp->imp_at.iat_service_estimate[i].at_worst_ever;
1202 worstt = imp->imp_at.iat_service_estimate[i].at_worst_time;
1203 s2dhms(&ts, now - worstt);
1204 seq_printf(m, "portal %-2d : cur %3u worst %3u (at %ld, "
1205 DHMS_FMT" ago) ", imp->imp_at.iat_portal[i],
1206 cur, worst, worstt, DHMS_VARS(&ts));
1207 lprocfs_seq_at_hist_helper(m, &imp->imp_at.iat_service_estimate[i]);
1210 LPROCFS_CLIMP_EXIT(obd);
1213 EXPORT_SYMBOL(lprocfs_timeouts_seq_show);
1215 int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data)
1217 struct obd_device *obd = data;
1220 LPROCFS_CLIMP_CHECK(obd);
1221 flags = obd->u.cli.cl_import->imp_connect_data.ocd_connect_flags;
1222 seq_printf(m, "flags="LPX64"\n", flags);
1223 obd_connect_seq_flags2str(m, flags, "\n");
1224 seq_printf(m, "\n");
1225 LPROCFS_CLIMP_EXIT(obd);
1228 EXPORT_SYMBOL(lprocfs_connect_flags_seq_show);
1230 #ifndef HAVE_ONLY_PROCFS_SEQ
1232 int lprocfs_rd_uint(char *page, char **start, off_t off,
1233 int count, int *eof, void *data)
1235 unsigned int *temp = data;
1236 return snprintf(page, count, "%u\n", *temp);
1238 EXPORT_SYMBOL(lprocfs_rd_uint);
1240 int lprocfs_rd_u64(char *page, char **start, off_t off,
1241 int count, int *eof, void *data)
1243 LASSERT(data != NULL);
1245 return snprintf(page, count, LPU64"\n", *(__u64 *)data);
1247 EXPORT_SYMBOL(lprocfs_rd_u64);
1249 int lprocfs_rd_atomic(char *page, char **start, off_t off,
1250 int count, int *eof, void *data)
1252 atomic_t *atom = data;
1253 LASSERT(atom != NULL);
1255 return snprintf(page, count, "%d\n", atomic_read(atom));
1257 EXPORT_SYMBOL(lprocfs_rd_atomic);
1259 int lprocfs_wr_atomic(struct file *file, const char *buffer,
1260 unsigned long count, void *data)
1262 atomic_t *atm = data;
1266 rc = lprocfs_write_helper(buffer, count, &val);
1273 atomic_set(atm, val);
1276 EXPORT_SYMBOL(lprocfs_wr_atomic);
1278 int lprocfs_rd_uuid(char *page, char **start, off_t off, int count,
1279 int *eof, void *data)
1281 struct obd_device *obd = data;
1283 LASSERT(obd != NULL);
1285 return snprintf(page, count, "%s\n", obd->obd_uuid.uuid);
1287 EXPORT_SYMBOL(lprocfs_rd_uuid);
1289 int lprocfs_rd_name(char *page, char **start, off_t off, int count,
1290 int *eof, void *data)
1292 struct obd_device *dev = data;
1294 LASSERT(dev != NULL);
1296 return snprintf(page, count, "%s\n", dev->obd_name);
1298 EXPORT_SYMBOL(lprocfs_rd_name);
1300 int lprocfs_rd_blksize(char *page, char **start, off_t off, int count,
1301 int *eof, void *data)
1303 struct obd_device *obd = data;
1304 struct obd_statfs osfs;
1305 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
1306 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1307 OBD_STATFS_NODELAY);
1310 rc = snprintf(page, count, "%u\n", osfs.os_bsize);
1314 EXPORT_SYMBOL(lprocfs_rd_blksize);
1316 int lprocfs_rd_kbytestotal(char *page, char **start, off_t off, int count,
1317 int *eof, void *data)
1319 struct obd_device *obd = data;
1320 struct obd_statfs osfs;
1321 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
1322 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1323 OBD_STATFS_NODELAY);
1325 __u32 blk_size = osfs.os_bsize >> 10;
1326 __u64 result = osfs.os_blocks;
1328 while (blk_size >>= 1)
1332 rc = snprintf(page, count, LPU64"\n", result);
1336 EXPORT_SYMBOL(lprocfs_rd_kbytestotal);
1338 int lprocfs_rd_kbytesfree(char *page, char **start, off_t off, int count,
1339 int *eof, void *data)
1341 struct obd_device *obd = data;
1342 struct obd_statfs osfs;
1343 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
1344 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1345 OBD_STATFS_NODELAY);
1347 __u32 blk_size = osfs.os_bsize >> 10;
1348 __u64 result = osfs.os_bfree;
1350 while (blk_size >>= 1)
1354 rc = snprintf(page, count, LPU64"\n", result);
1358 EXPORT_SYMBOL(lprocfs_rd_kbytesfree);
1360 int lprocfs_rd_kbytesavail(char *page, char **start, off_t off, int count,
1361 int *eof, void *data)
1363 struct obd_device *obd = data;
1364 struct obd_statfs osfs;
1365 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
1366 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1367 OBD_STATFS_NODELAY);
1369 __u32 blk_size = osfs.os_bsize >> 10;
1370 __u64 result = osfs.os_bavail;
1372 while (blk_size >>= 1)
1376 rc = snprintf(page, count, LPU64"\n", result);
1380 EXPORT_SYMBOL(lprocfs_rd_kbytesavail);
1382 int lprocfs_rd_filestotal(char *page, char **start, off_t off, int count,
1383 int *eof, void *data)
1385 struct obd_device *obd = data;
1386 struct obd_statfs osfs;
1387 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
1388 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1389 OBD_STATFS_NODELAY);
1392 rc = snprintf(page, count, LPU64"\n", osfs.os_files);
1397 EXPORT_SYMBOL(lprocfs_rd_filestotal);
1399 int lprocfs_rd_filesfree(char *page, char **start, off_t off, int count,
1400 int *eof, void *data)
1402 struct obd_device *obd = data;
1403 struct obd_statfs osfs;
1404 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
1405 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1406 OBD_STATFS_NODELAY);
1409 rc = snprintf(page, count, LPU64"\n", osfs.os_ffree);
1413 EXPORT_SYMBOL(lprocfs_rd_filesfree);
1415 int lprocfs_rd_server_uuid(char *page, char **start, off_t off, int count,
1416 int *eof, void *data)
1418 struct obd_device *obd = data;
1419 struct obd_import *imp;
1420 char *imp_state_name = NULL;
1423 LASSERT(obd != NULL);
1424 LPROCFS_CLIMP_CHECK(obd);
1425 imp = obd->u.cli.cl_import;
1426 imp_state_name = ptlrpc_import_state_name(imp->imp_state);
1428 rc = snprintf(page, count, "%s\t%s%s\n",
1429 obd2cli_tgt(obd), imp_state_name,
1430 imp->imp_deactive ? "\tDEACTIVATED" : "");
1432 LPROCFS_CLIMP_EXIT(obd);
1435 EXPORT_SYMBOL(lprocfs_rd_server_uuid);
1437 int lprocfs_rd_conn_uuid(char *page, char **start, off_t off, int count,
1438 int *eof, void *data)
1440 struct obd_device *obd = data;
1441 struct ptlrpc_connection *conn;
1444 LASSERT(obd != NULL);
1446 LPROCFS_CLIMP_CHECK(obd);
1447 conn = obd->u.cli.cl_import->imp_connection;
1449 if (conn && obd->u.cli.cl_import) {
1450 rc = snprintf(page, count, "%s\n",
1451 conn->c_remote_uuid.uuid);
1453 rc = snprintf(page, count, "%s\n", "<none>");
1456 LPROCFS_CLIMP_EXIT(obd);
1459 EXPORT_SYMBOL(lprocfs_rd_conn_uuid);
1462 * Append a space separated list of current set flags to str.
1464 #define flag2str(flag) \
1465 if (imp->imp_##flag && max - len > 0) \
1466 len += snprintf(str + len, max - len, "%s" #flag, len ? ", " : "");
1467 static int obd_import_flags2str(struct obd_import *imp, char *str, int max)
1471 if (imp->imp_obd->obd_no_recov)
1472 len += snprintf(str, max - len, "no_recov");
1476 flag2str(replayable);
1482 int lprocfs_rd_import(char *page, char **start, off_t off, int count,
1483 int *eof, void *data)
1485 struct lprocfs_counter ret;
1486 struct lprocfs_counter_header *header;
1487 struct obd_device *obd = (struct obd_device *)data;
1488 struct obd_import *imp;
1489 struct obd_import_conn *conn;
1495 LASSERT(obd != NULL);
1496 LPROCFS_CLIMP_CHECK(obd);
1497 imp = obd->u.cli.cl_import;
1500 i = snprintf(page, count,
1506 " connect_flags: [",
1509 ptlrpc_import_state_name(imp->imp_state),
1510 imp->imp_connect_data.ocd_instance);
1511 i += obd_connect_flags2str(page + i, count - i,
1512 imp->imp_connect_data.ocd_connect_flags,
1514 i += snprintf(page + i, count - i,
1516 " import_flags: [");
1517 i += obd_import_flags2str(imp, page + i, count - i);
1519 i += snprintf(page + i, count - i,
1522 " failover_nids: [");
1523 spin_lock(&imp->imp_lock);
1525 list_for_each_entry(conn, &imp->imp_conn_list, oic_item) {
1526 i += snprintf(page + i, count - i, "%s%s", j ? ", " : "",
1527 libcfs_nid2str(conn->oic_conn->c_peer.nid));
1530 i += snprintf(page + i, count - i,
1532 " current_connection: %s\n"
1533 " connection_attempts: %u\n"
1535 " in-progress_invalidations: %u\n",
1536 imp->imp_connection == NULL ? "<none>" :
1537 libcfs_nid2str(imp->imp_connection->c_peer.nid),
1539 imp->imp_generation,
1540 atomic_read(&imp->imp_inval_count));
1541 spin_unlock(&imp->imp_lock);
1543 if (obd->obd_svc_stats == NULL)
1546 header = &obd->obd_svc_stats->ls_cnt_header[PTLRPC_REQWAIT_CNTR];
1547 lprocfs_stats_collect(obd->obd_svc_stats, PTLRPC_REQWAIT_CNTR, &ret);
1548 if (ret.lc_count != 0) {
1549 /* first argument to do_div MUST be __u64 */
1550 __u64 sum = ret.lc_sum;
1551 do_div(sum, ret.lc_count);
1555 i += snprintf(page + i, count - i,
1558 " unregistering: %u\n"
1560 " avg_waittime: "LPU64" %s\n",
1561 atomic_read(&imp->imp_inflight),
1562 atomic_read(&imp->imp_unregistering),
1563 atomic_read(&imp->imp_timeouts),
1564 ret.lc_sum, header->lc_units);
1567 for(j = 0; j < IMP_AT_MAX_PORTALS; j++) {
1568 if (imp->imp_at.iat_portal[j] == 0)
1570 k = max_t(unsigned int, k,
1571 at_get(&imp->imp_at.iat_service_estimate[j]));
1573 i += snprintf(page + i, count - i,
1574 " service_estimates:\n"
1575 " services: %u sec\n"
1576 " network: %u sec\n",
1578 at_get(&imp->imp_at.iat_net_latency));
1580 i += snprintf(page + i, count - i,
1582 " last_replay: "LPU64"\n"
1583 " peer_committed: "LPU64"\n"
1584 " last_checked: "LPU64"\n",
1585 imp->imp_last_replay_transno,
1586 imp->imp_peer_committed_transno,
1587 imp->imp_last_transno_checked);
1589 /* avg data rates */
1590 for (rw = 0; rw <= 1; rw++) {
1591 lprocfs_stats_collect(obd->obd_svc_stats,
1592 PTLRPC_LAST_CNTR + BRW_READ_BYTES + rw,
1594 if (ret.lc_sum > 0 && ret.lc_count > 0) {
1595 /* first argument to do_div MUST be __u64 */
1596 __u64 sum = ret.lc_sum;
1597 do_div(sum, ret.lc_count);
1599 i += snprintf(page + i, count - i,
1600 " %s_data_averages:\n"
1601 " bytes_per_rpc: "LPU64"\n",
1602 rw ? "write" : "read",
1605 k = (int)ret.lc_sum;
1606 j = opcode_offset(OST_READ + rw) + EXTRA_MAX_OPCODES;
1607 header = &obd->obd_svc_stats->ls_cnt_header[j];
1608 lprocfs_stats_collect(obd->obd_svc_stats, j, &ret);
1609 if (ret.lc_sum > 0 && ret.lc_count != 0) {
1610 /* first argument to do_div MUST be __u64 */
1611 __u64 sum = ret.lc_sum;
1612 do_div(sum, ret.lc_count);
1614 i += snprintf(page + i, count - i,
1615 " %s_per_rpc: "LPU64"\n",
1616 header->lc_units, ret.lc_sum);
1617 j = (int)ret.lc_sum;
1619 i += snprintf(page + i, count - i,
1620 " MB_per_sec: %u.%.02u\n",
1621 k / j, (100 * k / j) % 100);
1626 LPROCFS_CLIMP_EXIT(obd);
1629 EXPORT_SYMBOL(lprocfs_rd_import);
1631 int lprocfs_rd_state(char *page, char **start, off_t off, int count,
1632 int *eof, void *data)
1634 struct obd_device *obd = (struct obd_device *)data;
1635 struct obd_import *imp;
1638 LASSERT(obd != NULL);
1639 LPROCFS_CLIMP_CHECK(obd);
1640 imp = obd->u.cli.cl_import;
1643 i = snprintf(page, count, "current_state: %s\n",
1644 ptlrpc_import_state_name(imp->imp_state));
1645 i += snprintf(page + i, count - i,
1646 "state_history:\n");
1647 k = imp->imp_state_hist_idx;
1648 for (j = 0; j < IMP_STATE_HIST_LEN; j++) {
1649 struct import_state_hist *ish =
1650 &imp->imp_state_hist[(k + j) % IMP_STATE_HIST_LEN];
1651 if (ish->ish_state == 0)
1653 i += snprintf(page + i, count - i, " - ["CFS_TIME_T", %s]\n",
1655 ptlrpc_import_state_name(ish->ish_state));
1658 LPROCFS_CLIMP_EXIT(obd);
1661 EXPORT_SYMBOL(lprocfs_rd_state);
1663 int lprocfs_at_hist_helper(char *page, int count, int rc,
1664 struct adaptive_timeout *at)
1667 for (i = 0; i < AT_BINS; i++)
1668 rc += snprintf(page + rc, count - rc, "%3u ", at->at_hist[i]);
1669 rc += snprintf(page + rc, count - rc, "\n");
1672 EXPORT_SYMBOL(lprocfs_at_hist_helper);
1674 /* See also ptlrpc_lprocfs_rd_timeouts */
1675 int lprocfs_rd_timeouts(char *page, char **start, off_t off, int count,
1676 int *eof, void *data)
1678 struct obd_device *obd = (struct obd_device *)data;
1679 struct obd_import *imp;
1680 unsigned int cur, worst;
1685 LASSERT(obd != NULL);
1686 LPROCFS_CLIMP_CHECK(obd);
1687 imp = obd->u.cli.cl_import;
1690 now = cfs_time_current_sec();
1692 /* Some network health info for kicks */
1693 s2dhms(&ts, now - imp->imp_last_reply_time);
1694 rc += snprintf(page + rc, count - rc,
1695 "%-10s : %ld, "DHMS_FMT" ago\n",
1696 "last reply", imp->imp_last_reply_time, DHMS_VARS(&ts));
1698 cur = at_get(&imp->imp_at.iat_net_latency);
1699 worst = imp->imp_at.iat_net_latency.at_worst_ever;
1700 worstt = imp->imp_at.iat_net_latency.at_worst_time;
1701 s2dhms(&ts, now - worstt);
1702 rc += snprintf(page + rc, count - rc,
1703 "%-10s : cur %3u worst %3u (at %ld, "DHMS_FMT" ago) ",
1704 "network", cur, worst, worstt, DHMS_VARS(&ts));
1705 rc = lprocfs_at_hist_helper(page, count, rc,
1706 &imp->imp_at.iat_net_latency);
1708 for(i = 0; i < IMP_AT_MAX_PORTALS; i++) {
1709 if (imp->imp_at.iat_portal[i] == 0)
1711 cur = at_get(&imp->imp_at.iat_service_estimate[i]);
1712 worst = imp->imp_at.iat_service_estimate[i].at_worst_ever;
1713 worstt = imp->imp_at.iat_service_estimate[i].at_worst_time;
1714 s2dhms(&ts, now - worstt);
1715 rc += snprintf(page + rc, count - rc,
1716 "portal %-2d : cur %3u worst %3u (at %ld, "
1717 DHMS_FMT" ago) ", imp->imp_at.iat_portal[i],
1718 cur, worst, worstt, DHMS_VARS(&ts));
1719 rc = lprocfs_at_hist_helper(page, count, rc,
1720 &imp->imp_at.iat_service_estimate[i]);
1723 LPROCFS_CLIMP_EXIT(obd);
1726 EXPORT_SYMBOL(lprocfs_rd_timeouts);
1728 int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
1729 int count, int *eof, void *data)
1731 struct obd_device *obd = data;
1735 LPROCFS_CLIMP_CHECK(obd);
1736 flags = obd->u.cli.cl_import->imp_connect_data.ocd_connect_flags;
1737 ret = snprintf(page, count, "flags="LPX64"\n", flags);
1738 ret += obd_connect_flags2str(page + ret, count - ret, flags, "\n");
1739 ret += snprintf(page + ret, count - ret, "\n");
1740 LPROCFS_CLIMP_EXIT(obd);
1743 EXPORT_SYMBOL(lprocfs_rd_connect_flags);
1745 int lprocfs_rd_numrefs(char *page, char **start, off_t off, int count,
1746 int *eof, void *data)
1748 struct obd_type *class = (struct obd_type*) data;
1750 LASSERT(class != NULL);
1752 return snprintf(page, count, "%d\n", class->typ_refcnt);
1754 EXPORT_SYMBOL(lprocfs_rd_numrefs);
1756 int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list)
1760 LASSERT(obd != NULL);
1761 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1762 LASSERT(obd->obd_type->typ_procroot != NULL);
1764 obd->obd_proc_entry = lprocfs_register(obd->obd_name,
1765 obd->obd_type->typ_procroot,
1767 if (IS_ERR(obd->obd_proc_entry)) {
1768 rc = PTR_ERR(obd->obd_proc_entry);
1769 CERROR("error %d setting up lprocfs for %s\n",rc,obd->obd_name);
1770 obd->obd_proc_entry = NULL;
1774 EXPORT_SYMBOL(lprocfs_obd_setup);
1778 lprocfs_seq_obd_setup(struct obd_device *obd)
1782 LASSERT(obd != NULL);
1783 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1784 LASSERT(obd->obd_type->typ_procroot != NULL);
1786 obd->obd_proc_entry = lprocfs_seq_register(obd->obd_name,
1787 obd->obd_type->typ_procroot,
1788 obd->obd_vars, obd);
1789 if (IS_ERR(obd->obd_proc_entry)) {
1790 rc = PTR_ERR(obd->obd_proc_entry);
1791 CERROR("error %d setting up lprocfs for %s\n",rc,obd->obd_name);
1792 obd->obd_proc_entry = NULL;
1796 EXPORT_SYMBOL(lprocfs_seq_obd_setup);
1798 int lprocfs_obd_cleanup(struct obd_device *obd)
1802 if (obd->obd_proc_exports_entry) {
1803 /* Should be no exports left */
1804 lprocfs_remove(&obd->obd_proc_exports_entry);
1805 obd->obd_proc_exports_entry = NULL;
1807 if (obd->obd_proc_entry) {
1808 lprocfs_remove(&obd->obd_proc_entry);
1809 obd->obd_proc_entry = NULL;
1813 EXPORT_SYMBOL(lprocfs_obd_cleanup);
1815 int lprocfs_stats_alloc_one(struct lprocfs_stats *stats, unsigned int cpuid)
1817 struct lprocfs_counter *cntr;
1818 unsigned int percpusize;
1820 unsigned long flags = 0;
1823 LASSERT(stats->ls_percpu[cpuid] == NULL);
1824 LASSERT((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0);
1826 percpusize = lprocfs_stats_counter_size(stats);
1827 LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[cpuid], percpusize);
1828 if (stats->ls_percpu[cpuid] != NULL) {
1830 if (unlikely(stats->ls_biggest_alloc_num <= cpuid)) {
1831 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
1832 spin_lock_irqsave(&stats->ls_lock, flags);
1834 spin_lock(&stats->ls_lock);
1835 if (stats->ls_biggest_alloc_num <= cpuid)
1836 stats->ls_biggest_alloc_num = cpuid + 1;
1837 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) {
1838 spin_unlock_irqrestore(&stats->ls_lock, flags);
1840 spin_unlock(&stats->ls_lock);
1843 /* initialize the ls_percpu[cpuid] non-zero counter */
1844 for (i = 0; i < stats->ls_num; ++i) {
1845 cntr = lprocfs_stats_counter_get(stats, cpuid, i);
1846 cntr->lc_min = LC_MIN_INIT;
1851 EXPORT_SYMBOL(lprocfs_stats_alloc_one);
1853 struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num,
1854 enum lprocfs_stats_flags flags)
1856 struct lprocfs_stats *stats;
1857 unsigned int num_entry;
1858 unsigned int percpusize = 0;
1864 if (lprocfs_no_percpu_stats != 0)
1865 flags |= LPROCFS_STATS_FLAG_NOPERCPU;
1867 if (flags & LPROCFS_STATS_FLAG_NOPERCPU)
1870 num_entry = num_possible_cpus();
1872 /* alloc percpu pointers for all possible cpu slots */
1873 LIBCFS_ALLOC(stats, offsetof(typeof(*stats), ls_percpu[num_entry]));
1877 stats->ls_num = num;
1878 stats->ls_flags = flags;
1879 spin_lock_init(&stats->ls_lock);
1881 /* alloc num of counter headers */
1882 LIBCFS_ALLOC(stats->ls_cnt_header,
1883 stats->ls_num * sizeof(struct lprocfs_counter_header));
1884 if (stats->ls_cnt_header == NULL)
1887 if ((flags & LPROCFS_STATS_FLAG_NOPERCPU) != 0) {
1888 /* contains only one set counters */
1889 percpusize = lprocfs_stats_counter_size(stats);
1890 LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[0], percpusize);
1891 if (stats->ls_percpu[0] == NULL)
1893 stats->ls_biggest_alloc_num = 1;
1894 } else if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0) {
1895 /* alloc all percpu data, currently only obd_memory use this */
1896 for (i = 0; i < num_entry; ++i)
1897 if (lprocfs_stats_alloc_one(stats, i) < 0)
1904 lprocfs_free_stats(&stats);
1907 EXPORT_SYMBOL(lprocfs_alloc_stats);
1909 void lprocfs_free_stats(struct lprocfs_stats **statsh)
1911 struct lprocfs_stats *stats = *statsh;
1912 unsigned int num_entry;
1913 unsigned int percpusize;
1916 if (stats == NULL || stats->ls_num == 0)
1920 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU)
1923 num_entry = num_possible_cpus();
1925 percpusize = lprocfs_stats_counter_size(stats);
1926 for (i = 0; i < num_entry; i++)
1927 if (stats->ls_percpu[i] != NULL)
1928 LIBCFS_FREE(stats->ls_percpu[i], percpusize);
1929 if (stats->ls_cnt_header != NULL)
1930 LIBCFS_FREE(stats->ls_cnt_header, stats->ls_num *
1931 sizeof(struct lprocfs_counter_header));
1932 LIBCFS_FREE(stats, offsetof(typeof(*stats), ls_percpu[num_entry]));
1934 EXPORT_SYMBOL(lprocfs_free_stats);
1936 void lprocfs_clear_stats(struct lprocfs_stats *stats)
1938 struct lprocfs_counter *percpu_cntr;
1941 unsigned int num_entry;
1942 unsigned long flags = 0;
1944 num_entry = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1946 for (i = 0; i < num_entry; i++) {
1947 if (stats->ls_percpu[i] == NULL)
1949 for (j = 0; j < stats->ls_num; j++) {
1950 percpu_cntr = lprocfs_stats_counter_get(stats, i, j);
1951 percpu_cntr->lc_count = 0;
1952 percpu_cntr->lc_min = LC_MIN_INIT;
1953 percpu_cntr->lc_max = 0;
1954 percpu_cntr->lc_sumsquare = 0;
1955 percpu_cntr->lc_sum = 0;
1956 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
1957 percpu_cntr->lc_sum_irq = 0;
1961 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1963 EXPORT_SYMBOL(lprocfs_clear_stats);
1965 static ssize_t lprocfs_stats_seq_write(struct file *file, const char *buf,
1966 size_t len, loff_t *off)
1968 struct seq_file *seq = file->private_data;
1969 struct lprocfs_stats *stats = seq->private;
1971 lprocfs_clear_stats(stats);
1976 static void *lprocfs_stats_seq_start(struct seq_file *p, loff_t *pos)
1978 struct lprocfs_stats *stats = p->private;
1980 return (*pos < stats->ls_num) ? pos : NULL;
1983 static void lprocfs_stats_seq_stop(struct seq_file *p, void *v)
1987 static void *lprocfs_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
1991 return lprocfs_stats_seq_start(p, pos);
1994 /* seq file export of one lprocfs counter */
1995 static int lprocfs_stats_seq_show(struct seq_file *p, void *v)
1997 struct lprocfs_stats *stats = p->private;
1998 struct lprocfs_counter_header *hdr;
1999 struct lprocfs_counter ctr;
2000 int idx = *(loff_t *)v;
2006 do_gettimeofday(&now);
2007 rc = seq_printf(p, "%-25s %lu.%lu secs.usecs\n",
2008 "snapshot_time", now.tv_sec, now.tv_usec);
2013 hdr = &stats->ls_cnt_header[idx];
2014 lprocfs_stats_collect(stats, idx, &ctr);
2016 if (ctr.lc_count == 0)
2019 rc = seq_printf(p, "%-25s "LPD64" samples [%s]", hdr->lc_name,
2020 ctr.lc_count, hdr->lc_units);
2024 if ((hdr->lc_config & LPROCFS_CNTR_AVGMINMAX) && ctr.lc_count > 0) {
2025 rc = seq_printf(p, " "LPD64" "LPD64" "LPD64,
2026 ctr.lc_min, ctr.lc_max, ctr.lc_sum);
2029 if (hdr->lc_config & LPROCFS_CNTR_STDDEV)
2030 rc = seq_printf(p, " "LPD64, ctr.lc_sumsquare);
2034 rc = seq_printf(p, "\n");
2036 return (rc < 0) ? rc : 0;
2039 struct seq_operations lprocfs_stats_seq_sops = {
2040 .start = lprocfs_stats_seq_start,
2041 .stop = lprocfs_stats_seq_stop,
2042 .next = lprocfs_stats_seq_next,
2043 .show = lprocfs_stats_seq_show,
2046 static int lprocfs_stats_seq_open(struct inode *inode, struct file *file)
2048 struct seq_file *seq;
2051 #ifndef HAVE_ONLY_PROCFS_SEQ
2052 if (LPROCFS_ENTRY_CHECK(PDE(inode)))
2055 rc = seq_open(file, &lprocfs_stats_seq_sops);
2058 seq = file->private_data;
2059 seq->private = PDE_DATA(inode);
2063 struct file_operations lprocfs_stats_seq_fops = {
2064 .owner = THIS_MODULE,
2065 .open = lprocfs_stats_seq_open,
2067 .write = lprocfs_stats_seq_write,
2068 .llseek = seq_lseek,
2069 .release = lprocfs_seq_release,
2072 int lprocfs_register_stats(struct proc_dir_entry *root, const char *name,
2073 struct lprocfs_stats *stats)
2075 struct proc_dir_entry *entry;
2076 LASSERT(root != NULL);
2078 entry = proc_create_data(name, 0644, root,
2079 &lprocfs_stats_seq_fops, stats);
2084 EXPORT_SYMBOL(lprocfs_register_stats);
2086 void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
2087 unsigned conf, const char *name, const char *units)
2089 struct lprocfs_counter_header *header;
2090 struct lprocfs_counter *percpu_cntr;
2091 unsigned long flags = 0;
2093 unsigned int num_cpu;
2095 LASSERT(stats != NULL);
2097 header = &stats->ls_cnt_header[index];
2098 LASSERTF(header != NULL, "Failed to allocate stats header:[%d]%s/%s\n",
2099 index, name, units);
2101 header->lc_config = conf;
2102 header->lc_name = name;
2103 header->lc_units = units;
2105 num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
2106 for (i = 0; i < num_cpu; ++i) {
2107 if (stats->ls_percpu[i] == NULL)
2109 percpu_cntr = lprocfs_stats_counter_get(stats, i, index);
2110 percpu_cntr->lc_count = 0;
2111 percpu_cntr->lc_min = LC_MIN_INIT;
2112 percpu_cntr->lc_max = 0;
2113 percpu_cntr->lc_sumsquare = 0;
2114 percpu_cntr->lc_sum = 0;
2115 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
2116 percpu_cntr->lc_sum_irq = 0;
2118 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
2120 EXPORT_SYMBOL(lprocfs_counter_init);
2122 /* Note that we only init md counters for ops whose offset is less
2123 * than NUM_MD_STATS. This is explained in a comment in the definition
2124 * of struct md_ops. */
2125 #define LPROCFS_MD_OP_INIT(base, stats, op) \
2127 unsigned int _idx = base + MD_COUNTER_OFFSET(op); \
2129 if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS) { \
2130 LASSERT(_idx < stats->ls_num); \
2131 lprocfs_counter_init(stats, _idx, 0, #op, "reqs"); \
2135 void lprocfs_init_mps_stats(int num_private_stats, struct lprocfs_stats *stats)
2137 LPROCFS_MD_OP_INIT(num_private_stats, stats, getstatus);
2138 LPROCFS_MD_OP_INIT(num_private_stats, stats, null_inode);
2139 LPROCFS_MD_OP_INIT(num_private_stats, stats, find_cbdata);
2140 LPROCFS_MD_OP_INIT(num_private_stats, stats, close);
2141 LPROCFS_MD_OP_INIT(num_private_stats, stats, create);
2142 LPROCFS_MD_OP_INIT(num_private_stats, stats, done_writing);
2143 LPROCFS_MD_OP_INIT(num_private_stats, stats, enqueue);
2144 LPROCFS_MD_OP_INIT(num_private_stats, stats, getattr);
2145 LPROCFS_MD_OP_INIT(num_private_stats, stats, getattr_name);
2146 LPROCFS_MD_OP_INIT(num_private_stats, stats, intent_lock);
2147 LPROCFS_MD_OP_INIT(num_private_stats, stats, link);
2148 LPROCFS_MD_OP_INIT(num_private_stats, stats, rename);
2149 LPROCFS_MD_OP_INIT(num_private_stats, stats, setattr);
2150 LPROCFS_MD_OP_INIT(num_private_stats, stats, fsync);
2151 LPROCFS_MD_OP_INIT(num_private_stats, stats, read_page);
2152 LPROCFS_MD_OP_INIT(num_private_stats, stats, unlink);
2153 LPROCFS_MD_OP_INIT(num_private_stats, stats, setxattr);
2154 LPROCFS_MD_OP_INIT(num_private_stats, stats, getxattr);
2155 LPROCFS_MD_OP_INIT(num_private_stats, stats, init_ea_size);
2156 LPROCFS_MD_OP_INIT(num_private_stats, stats, get_lustre_md);
2157 LPROCFS_MD_OP_INIT(num_private_stats, stats, free_lustre_md);
2158 LPROCFS_MD_OP_INIT(num_private_stats, stats, update_lsm_md);
2159 LPROCFS_MD_OP_INIT(num_private_stats, stats, merge_attr);
2160 LPROCFS_MD_OP_INIT(num_private_stats, stats, set_open_replay_data);
2161 LPROCFS_MD_OP_INIT(num_private_stats, stats, clear_open_replay_data);
2162 LPROCFS_MD_OP_INIT(num_private_stats, stats, set_lock_data);
2163 LPROCFS_MD_OP_INIT(num_private_stats, stats, lock_match);
2164 LPROCFS_MD_OP_INIT(num_private_stats, stats, cancel_unused);
2165 LPROCFS_MD_OP_INIT(num_private_stats, stats, renew_capa);
2166 LPROCFS_MD_OP_INIT(num_private_stats, stats, unpack_capa);
2167 LPROCFS_MD_OP_INIT(num_private_stats, stats, get_remote_perm);
2168 LPROCFS_MD_OP_INIT(num_private_stats, stats, intent_getattr_async);
2169 LPROCFS_MD_OP_INIT(num_private_stats, stats, revalidate_lock);
2171 EXPORT_SYMBOL(lprocfs_init_mps_stats);
2173 int lprocfs_alloc_md_stats(struct obd_device *obd,
2174 unsigned int num_private_stats)
2176 struct lprocfs_stats *stats;
2177 unsigned int num_stats;
2180 CLASSERT(offsetof(struct md_ops, MD_STATS_FIRST_OP) == 0);
2181 CLASSERT(_MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) == 0);
2182 CLASSERT(_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) > 0);
2184 /* TODO Ensure that this function is only used where
2185 * appropriate by adding an assertion to the effect that
2186 * obd->obd_type->typ_md_ops is not NULL. We can't do this now
2187 * because mdt_procfs_init() uses this function to allocate
2188 * the stats backing /proc/fs/lustre/mdt/.../md_stats but the
2189 * mdt layer does not use the md_ops interface. This is
2190 * confusing and a waste of memory. See LU-2484.
2192 LASSERT(obd->obd_proc_entry != NULL);
2193 LASSERT(obd->obd_md_stats == NULL);
2194 LASSERT(obd->obd_md_cntr_base == 0);
2196 num_stats = NUM_MD_STATS + num_private_stats;
2197 stats = lprocfs_alloc_stats(num_stats, 0);
2201 lprocfs_init_mps_stats(num_private_stats, stats);
2203 for (i = num_private_stats; i < num_stats; i++) {
2204 if (stats->ls_cnt_header[i].lc_name == NULL) {
2205 CERROR("Missing md_stat initializer md_op "
2206 "operation at offset %d. Aborting.\n",
2207 i - num_private_stats);
2212 rc = lprocfs_register_stats(obd->obd_proc_entry, "md_stats", stats);
2214 lprocfs_free_stats(&stats);
2216 obd->obd_md_stats = stats;
2217 obd->obd_md_cntr_base = num_private_stats;
2222 EXPORT_SYMBOL(lprocfs_alloc_md_stats);
2224 void lprocfs_free_md_stats(struct obd_device *obd)
2226 struct lprocfs_stats *stats = obd->obd_md_stats;
2228 if (stats != NULL) {
2229 obd->obd_md_stats = NULL;
2230 obd->obd_md_cntr_base = 0;
2231 lprocfs_free_stats(&stats);
2234 EXPORT_SYMBOL(lprocfs_free_md_stats);
2236 void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
2238 lprocfs_counter_init(ldlm_stats,
2239 LDLM_ENQUEUE - LDLM_FIRST_OPC,
2240 0, "ldlm_enqueue", "reqs");
2241 lprocfs_counter_init(ldlm_stats,
2242 LDLM_CONVERT - LDLM_FIRST_OPC,
2243 0, "ldlm_convert", "reqs");
2244 lprocfs_counter_init(ldlm_stats,
2245 LDLM_CANCEL - LDLM_FIRST_OPC,
2246 0, "ldlm_cancel", "reqs");
2247 lprocfs_counter_init(ldlm_stats,
2248 LDLM_BL_CALLBACK - LDLM_FIRST_OPC,
2249 0, "ldlm_bl_callback", "reqs");
2250 lprocfs_counter_init(ldlm_stats,
2251 LDLM_CP_CALLBACK - LDLM_FIRST_OPC,
2252 0, "ldlm_cp_callback", "reqs");
2253 lprocfs_counter_init(ldlm_stats,
2254 LDLM_GL_CALLBACK - LDLM_FIRST_OPC,
2255 0, "ldlm_gl_callback", "reqs");
2257 EXPORT_SYMBOL(lprocfs_init_ldlm_stats);
2259 __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
2260 struct lprocfs_counter_header *header,
2261 enum lprocfs_stats_flags flags,
2262 enum lprocfs_fields_flags field)
2266 if (lc == NULL || header == NULL)
2270 case LPROCFS_FIELDS_FLAGS_CONFIG:
2271 ret = header->lc_config;
2273 case LPROCFS_FIELDS_FLAGS_SUM:
2275 if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
2276 ret += lc->lc_sum_irq;
2278 case LPROCFS_FIELDS_FLAGS_MIN:
2281 case LPROCFS_FIELDS_FLAGS_MAX:
2284 case LPROCFS_FIELDS_FLAGS_AVG:
2285 ret = (lc->lc_max - lc->lc_min) / 2;
2287 case LPROCFS_FIELDS_FLAGS_SUMSQUARE:
2288 ret = lc->lc_sumsquare;
2290 case LPROCFS_FIELDS_FLAGS_COUNT:
2298 EXPORT_SYMBOL(lprocfs_read_helper);
2300 int lprocfs_write_helper(const char *buffer, unsigned long count,
2303 return lprocfs_write_frac_helper(buffer, count, val, 1);
2305 EXPORT_SYMBOL(lprocfs_write_helper);
2307 int lprocfs_write_frac_helper(const char *buffer, unsigned long count,
2310 char kernbuf[20], *end, *pbuf;
2312 if (count > (sizeof(kernbuf) - 1))
2315 if (copy_from_user(kernbuf, buffer, count))
2318 kernbuf[count] = '\0';
2325 *val = (int)simple_strtoul(pbuf, &end, 10) * mult;
2329 if (end != NULL && *end == '.') {
2330 int temp_val, pow = 1;
2334 if (strlen(pbuf) > 5)
2335 pbuf[5] = '\0'; /*only allow 5bits fractional*/
2337 temp_val = (int)simple_strtoul(pbuf, &end, 10) * mult;
2340 for (i = 0; i < (end - pbuf); i++)
2343 *val += temp_val / pow;
2348 EXPORT_SYMBOL(lprocfs_write_frac_helper);
2350 int lprocfs_read_frac_helper(char *buffer, unsigned long count, long val,
2353 long decimal_val, frac_val;
2359 decimal_val = val / mult;
2360 prtn = snprintf(buffer, count, "%ld", decimal_val);
2361 frac_val = val % mult;
2363 if (prtn < (count - 4) && frac_val > 0) {
2365 int i, temp_mult = 1, frac_bits = 0;
2367 temp_frac = frac_val * 10;
2368 buffer[prtn++] = '.';
2369 while (frac_bits < 2 && (temp_frac / mult) < 1 ) {
2370 /* only reserved 2 bits fraction */
2371 buffer[prtn++] ='0';
2376 * Need to think these cases :
2377 * 1. #echo x.00 > /proc/xxx output result : x
2378 * 2. #echo x.0x > /proc/xxx output result : x.0x
2379 * 3. #echo x.x0 > /proc/xxx output result : x.x
2380 * 4. #echo x.xx > /proc/xxx output result : x.xx
2381 * Only reserved 2 bits fraction.
2383 for (i = 0; i < (5 - prtn); i++)
2386 frac_bits = min((int)count - prtn, 3 - frac_bits);
2387 prtn += snprintf(buffer + prtn, frac_bits, "%ld",
2388 frac_val * temp_mult / mult);
2391 while(buffer[prtn] < '1' || buffer[prtn] > '9') {
2393 if (buffer[prtn] == '.') {
2400 buffer[prtn++] ='\n';
2403 EXPORT_SYMBOL(lprocfs_read_frac_helper);
2405 int lprocfs_seq_read_frac_helper(struct seq_file *m, long val, int mult)
2407 long decimal_val, frac_val;
2409 decimal_val = val / mult;
2410 seq_printf(m, "%ld", decimal_val);
2411 frac_val = val % mult;
2418 /* Three cases: x0, xx, 0x */
2419 if ((frac_val % 10) != 0)
2420 seq_printf(m, ".%ld", frac_val);
2422 seq_printf(m, ".%ld", frac_val / 10);
2425 seq_printf(m, "\n");
2428 EXPORT_SYMBOL(lprocfs_seq_read_frac_helper);
2430 int lprocfs_write_u64_helper(const char *buffer, unsigned long count,__u64 *val)
2432 return lprocfs_write_frac_u64_helper(buffer, count, val, 1);
2434 EXPORT_SYMBOL(lprocfs_write_u64_helper);
2436 int lprocfs_write_frac_u64_helper(const char *buffer, unsigned long count,
2437 __u64 *val, int mult)
2439 char kernbuf[22], *end, *pbuf;
2440 __u64 whole, frac = 0, units;
2441 unsigned frac_d = 1;
2443 if (count > (sizeof(kernbuf) - 1))
2446 if (copy_from_user(kernbuf, buffer, count))
2449 kernbuf[count] = '\0';
2456 whole = simple_strtoull(pbuf, &end, 10);
2460 if (end != NULL && *end == '.') {
2464 /* need to limit frac_d to a __u32 */
2465 if (strlen(pbuf) > 10)
2468 frac = simple_strtoull(pbuf, &end, 10);
2469 /* count decimal places */
2470 for (i = 0; i < (end - pbuf); i++)
2489 /* Specified units override the multiplier */
2491 mult = mult < 0 ? -units : units;
2494 do_div(frac, frac_d);
2495 *val = whole * mult + frac;
2498 EXPORT_SYMBOL(lprocfs_write_frac_u64_helper);
2500 static char *lprocfs_strnstr(const char *s1, const char *s2, size_t len)
2509 if (!memcmp(s1, s2, l2))
2517 * Find the string \a name in the input \a buffer, and return a pointer to the
2518 * value immediately following \a name, reducing \a count appropriately.
2519 * If \a name is not found the original \a buffer is returned.
2521 char *lprocfs_find_named_value(const char *buffer, const char *name,
2525 size_t buflen = *count;
2527 /* there is no strnstr() in rhel5 and ubuntu kernels */
2528 val = lprocfs_strnstr(buffer, name, buflen);
2530 return (char *)buffer;
2532 val += strlen(name); /* skip prefix */
2533 while (val < buffer + buflen && isspace(*val)) /* skip separator */
2537 while (val < buffer + buflen && isalnum(*val)) {
2542 return val - *count;
2544 EXPORT_SYMBOL(lprocfs_find_named_value);
2546 int lprocfs_seq_create(struct proc_dir_entry *parent,
2549 const struct file_operations *seq_fops,
2552 struct proc_dir_entry *entry;
2555 /* Disallow secretly (un)writable entries. */
2556 LASSERT((seq_fops->write == NULL) == ((mode & 0222) == 0));
2558 entry = proc_create_data(name, mode, parent, seq_fops, data);
2565 EXPORT_SYMBOL(lprocfs_seq_create);
2567 int lprocfs_obd_seq_create(struct obd_device *dev,
2570 const struct file_operations *seq_fops,
2573 return (lprocfs_seq_create(dev->obd_proc_entry, name,
2574 mode, seq_fops, data));
2576 EXPORT_SYMBOL(lprocfs_obd_seq_create);
2578 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
2580 if (value >= OBD_HIST_MAX)
2581 value = OBD_HIST_MAX - 1;
2583 spin_lock(&oh->oh_lock);
2584 oh->oh_buckets[value]++;
2585 spin_unlock(&oh->oh_lock);
2587 EXPORT_SYMBOL(lprocfs_oh_tally);
2589 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
2591 unsigned int val = 0;
2593 if (likely(value != 0))
2594 val = min(fls(value - 1), OBD_HIST_MAX);
2596 lprocfs_oh_tally(oh, val);
2598 EXPORT_SYMBOL(lprocfs_oh_tally_log2);
2600 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
2602 unsigned long ret = 0;
2605 for (i = 0; i < OBD_HIST_MAX; i++)
2606 ret += oh->oh_buckets[i];
2609 EXPORT_SYMBOL(lprocfs_oh_sum);
2611 void lprocfs_oh_clear(struct obd_histogram *oh)
2613 spin_lock(&oh->oh_lock);
2614 memset(oh->oh_buckets, 0, sizeof(oh->oh_buckets));
2615 spin_unlock(&oh->oh_lock);
2617 EXPORT_SYMBOL(lprocfs_oh_clear);
2619 int lprocfs_obd_rd_max_pages_per_rpc(char *page, char **start, off_t off,
2620 int count, int *eof, void *data)
2622 struct obd_device *dev = data;
2623 struct client_obd *cli = &dev->u.cli;
2626 client_obd_list_lock(&cli->cl_loi_list_lock);
2627 rc = snprintf(page, count, "%d\n", cli->cl_max_pages_per_rpc);
2628 client_obd_list_unlock(&cli->cl_loi_list_lock);
2631 EXPORT_SYMBOL(lprocfs_obd_rd_max_pages_per_rpc);
2633 int lprocfs_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *data)
2635 struct obd_device *dev = data;
2636 struct client_obd *cli = &dev->u.cli;
2639 client_obd_list_lock(&cli->cl_loi_list_lock);
2640 rc = seq_printf(m, "%d\n", cli->cl_max_pages_per_rpc);
2641 client_obd_list_unlock(&cli->cl_loi_list_lock);
2644 EXPORT_SYMBOL(lprocfs_obd_max_pages_per_rpc_seq_show);
2646 int lprocfs_wr_root_squash(const char __user *buffer, unsigned long count,
2647 struct root_squash_info *squash, char *name)
2650 char kernbuf[64], *tmp, *errmsg;
2651 unsigned long uid, gid;
2654 if (count >= sizeof(kernbuf)) {
2655 errmsg = "string too long";
2656 GOTO(failed_noprint, rc = -EINVAL);
2658 if (copy_from_user(kernbuf, buffer, count)) {
2659 errmsg = "bad address";
2660 GOTO(failed_noprint, rc = -EFAULT);
2662 kernbuf[count] = '\0';
2664 /* look for uid gid separator */
2665 tmp = strchr(kernbuf, ':');
2667 errmsg = "needs uid:gid format";
2668 GOTO(failed, rc = -EINVAL);
2674 if (kstrtoul(kernbuf, 0, &uid) != 0) {
2676 GOTO(failed, rc = -EINVAL);
2680 if (kstrtoul(tmp, 0, &gid) != 0) {
2682 GOTO(failed, rc = -EINVAL);
2685 squash->rsi_uid = uid;
2686 squash->rsi_gid = gid;
2688 LCONSOLE_INFO("%s: root_squash is set to %u:%u\n",
2689 name, squash->rsi_uid, squash->rsi_gid);
2697 CWARN("%s: failed to set root_squash to \"%s\", %s, rc = %d\n",
2698 name, kernbuf, errmsg, rc);
2701 CWARN("%s: failed to set root_squash due to %s, rc = %d\n",
2705 EXPORT_SYMBOL(lprocfs_wr_root_squash);
2708 int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count,
2709 struct root_squash_info *squash, char *name)
2712 char *kernbuf = NULL;
2714 struct list_head tmp;
2718 errmsg = "string too long";
2719 GOTO(failed, rc = -EINVAL);
2722 OBD_ALLOC(kernbuf, count + 1);
2723 if (kernbuf == NULL) {
2724 errmsg = "no memory";
2725 GOTO(failed, rc = -ENOMEM);
2727 if (copy_from_user(kernbuf, buffer, count)) {
2728 errmsg = "bad address";
2729 GOTO(failed, rc = -EFAULT);
2731 kernbuf[count] = '\0';
2733 if (count > 0 && kernbuf[count - 1] == '\n')
2734 kernbuf[count - 1] = '\0';
2736 if (strcmp(kernbuf, "NONE") == 0 || strcmp(kernbuf, "clear") == 0) {
2737 /* empty string is special case */
2738 down_write(&squash->rsi_sem);
2739 if (!list_empty(&squash->rsi_nosquash_nids))
2740 cfs_free_nidlist(&squash->rsi_nosquash_nids);
2741 up_write(&squash->rsi_sem);
2742 LCONSOLE_INFO("%s: nosquash_nids is cleared\n", name);
2743 OBD_FREE(kernbuf, count + 1);
2747 INIT_LIST_HEAD(&tmp);
2748 if (cfs_parse_nidlist(kernbuf, count, &tmp) <= 0) {
2749 errmsg = "can't parse";
2750 GOTO(failed, rc = -EINVAL);
2752 LCONSOLE_INFO("%s: nosquash_nids set to %s\n",
2754 OBD_FREE(kernbuf, count + 1);
2757 down_write(&squash->rsi_sem);
2758 if (!list_empty(&squash->rsi_nosquash_nids))
2759 cfs_free_nidlist(&squash->rsi_nosquash_nids);
2760 list_splice(&tmp, &squash->rsi_nosquash_nids);
2761 up_write(&squash->rsi_sem);
2767 CWARN("%s: failed to set nosquash_nids to \"%s\", %s rc = %d\n",
2768 name, kernbuf, errmsg, rc);
2769 OBD_FREE(kernbuf, count + 1);
2771 CWARN("%s: failed to set nosquash_nids due to %s rc = %d\n",
2776 EXPORT_SYMBOL(lprocfs_wr_nosquash_nids);