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\n",
97 return ERR_PTR(-ENOMEM);
99 proc->read_proc = read_proc;
100 proc->write_proc = write_proc;
102 LPROCFS_WRITE_EXIT();
104 return ERR_PTR(-EINVAL);
111 proc = proc_create_data(name, mode, root, fops, data);
113 CERROR("LprocFS: No memory to create /proc entry %s\n",
115 return ERR_PTR(-ENOMEM);
120 EXPORT_SYMBOL(lprocfs_add_simple);
122 struct proc_dir_entry *lprocfs_add_symlink(const char *name,
123 struct proc_dir_entry *parent, const char *format, ...)
125 struct proc_dir_entry *entry;
129 if (parent == NULL || format == NULL)
132 OBD_ALLOC_WAIT(dest, MAX_STRING_SIZE + 1);
136 va_start(ap, format);
137 vsnprintf(dest, MAX_STRING_SIZE, format, ap);
140 entry = proc_symlink(name, parent, dest);
142 CERROR("LprocFS: Could not create symbolic link from "
143 "%s to %s\n", name, dest);
145 OBD_FREE(dest, MAX_STRING_SIZE + 1);
148 EXPORT_SYMBOL(lprocfs_add_symlink);
150 #ifdef HAVE_ONLY_PROCFS_SEQ
151 static const struct file_operations lprocfs_generic_fops = { };
155 lprocfs_fops_read(struct file *f, char __user *buf, size_t size, loff_t *ppos)
157 struct proc_dir_entry *dp = PDE(f->f_dentry->d_inode);
158 char *page, *start = NULL;
159 int rc = 0, eof = 1, count;
161 if (*ppos >= PAGE_CACHE_SIZE)
164 page = (char *)__get_free_page(GFP_KERNEL);
168 if (LPROCFS_ENTRY_CHECK(dp)) {
173 OBD_FAIL_TIMEOUT(OBD_FAIL_LPROC_REMOVE, 10);
175 rc = dp->read_proc(page, &start, *ppos, PAGE_CACHE_SIZE,
180 /* for lustre proc read, the read count must be less than PAGE_SIZE */
189 start = page + *ppos;
190 } else if (start < page) {
194 count = (rc < size) ? rc : size;
195 if (copy_to_user(buf, start, count)) {
202 free_page((unsigned long)page);
207 lprocfs_fops_write(struct file *f, const char __user *buf, size_t size,
210 struct proc_dir_entry *dp = PDE(f->f_dentry->d_inode);
213 if (LPROCFS_ENTRY_CHECK(dp))
216 rc = dp->write_proc(f, buf, size, dp->data);
220 static struct file_operations lprocfs_generic_fops = {
221 .owner = THIS_MODULE,
222 .read = lprocfs_fops_read,
223 .write = lprocfs_fops_write,
226 /* for b=10866, global variable */
227 DECLARE_RWSEM(_lprocfs_lock);
228 EXPORT_SYMBOL(_lprocfs_lock);
230 static struct proc_dir_entry *__lprocfs_srch(struct proc_dir_entry *head,
233 struct proc_dir_entry *temp;
239 while (temp != NULL) {
240 if (strcmp(temp->name, name) == 0)
247 struct proc_dir_entry *lprocfs_srch(struct proc_dir_entry *head,
250 struct proc_dir_entry *temp;
252 LPROCFS_SRCH_ENTRY();
253 temp = __lprocfs_srch(head, name);
257 EXPORT_SYMBOL(lprocfs_srch);
259 static int __lprocfs_add_vars(struct proc_dir_entry *root,
260 struct lprocfs_vars *list,
265 if (root == NULL || list == NULL)
268 while (list->name != NULL) {
269 struct proc_dir_entry *cur_root, *proc;
270 char *pathcopy, *cur, *next, pathbuf[64];
271 int pathsize = strlen(list->name) + 1;
276 /* need copy of path for strsep */
277 if (strlen(list->name) > sizeof(pathbuf) - 1) {
278 OBD_ALLOC(pathcopy, pathsize);
279 if (pathcopy == NULL)
280 GOTO(out, rc = -ENOMEM);
286 strcpy(pathcopy, list->name);
288 while (cur_root != NULL && (cur = strsep(&next, "/"))) {
289 if (*cur =='\0') /* skip double/trailing "/" */
292 proc = __lprocfs_srch(cur_root, cur);
293 CDEBUG(D_OTHER, "cur_root=%s, cur=%s, next=%s, (%s)\n",
294 cur_root->name, cur, next,
295 (proc ? "exists" : "new"));
297 cur_root = (proc ? proc :
298 proc_mkdir(cur, cur_root));
299 } else if (proc == NULL) {
301 if (list->proc_mode != 0000) {
302 mode = list->proc_mode;
306 if (list->write_fptr)
309 proc = create_proc_entry(cur, mode, cur_root);
313 if (pathcopy != pathbuf)
314 OBD_FREE(pathcopy, pathsize);
316 if (cur_root == NULL || proc == NULL) {
317 CERROR("LprocFS: No memory to create /proc entry %s\n",
319 GOTO(out, rc = -ENOMEM);
323 proc->proc_fops = list->fops;
325 proc->proc_fops = &lprocfs_generic_fops;
326 proc->read_proc = list->read_fptr;
327 proc->write_proc = list->write_fptr;
328 proc->data = (list->data ? list->data : data);
335 int lprocfs_add_vars(struct proc_dir_entry *root, struct lprocfs_vars *list,
340 LPROCFS_WRITE_ENTRY();
341 rc = __lprocfs_add_vars(root, list, data);
342 LPROCFS_WRITE_EXIT();
346 EXPORT_SYMBOL(lprocfs_add_vars);
352 * \param root [in] The parent proc entry on which new entry will be added.
353 * \param list [in] Array of proc entries to be added.
354 * \param data [in] The argument to be passed when entries read/write routines
355 * are called through /proc file.
357 * \retval 0 on success
361 lprocfs_seq_add_vars(struct proc_dir_entry *root, struct lprocfs_seq_vars *list,
364 if (root == NULL || list == NULL)
367 while (list->name != NULL) {
368 struct proc_dir_entry *proc;
371 if (list->proc_mode != 0000) {
372 mode = list->proc_mode;
373 } else if (list->fops) {
374 if (list->fops->read)
376 if (list->fops->write)
379 proc = proc_create_data(list->name, mode, root,
380 list->fops ?: &lprocfs_generic_fops,
388 EXPORT_SYMBOL(lprocfs_seq_add_vars);
390 #ifndef HAVE_ONLY_PROCFS_SEQ
391 void lprocfs_remove_nolock(struct proc_dir_entry **proot)
393 struct proc_dir_entry *root = *proot;
394 struct proc_dir_entry *temp = root;
395 struct proc_dir_entry *rm_entry;
396 struct proc_dir_entry *parent;
399 if (root == NULL || IS_ERR(root))
402 parent = root->parent;
403 LASSERT(parent != NULL);
406 while (temp->subdir != NULL)
412 /* Memory corruption once caused this to fail, and
413 without this LASSERT we would loop here forever. */
414 LASSERTF(strlen(rm_entry->name) == rm_entry->namelen,
415 "0x%p %s/%s len %d\n", rm_entry, temp->name,
416 rm_entry->name, (int)strlen(rm_entry->name));
418 remove_proc_entry(rm_entry->name, temp);
425 void lprocfs_remove(struct proc_dir_entry **rooth)
427 #ifndef HAVE_ONLY_PROCFS_SEQ
428 LPROCFS_WRITE_ENTRY(); /* search vs remove race */
429 lprocfs_remove_nolock(rooth);
430 LPROCFS_WRITE_EXIT();
436 EXPORT_SYMBOL(lprocfs_remove);
438 void lprocfs_remove_proc_entry(const char *name, struct proc_dir_entry *parent)
440 LASSERT(parent != NULL);
441 remove_proc_entry(name, parent);
443 EXPORT_SYMBOL(lprocfs_remove_proc_entry);
445 #ifndef HAVE_ONLY_PROCFS_SEQ
446 void lprocfs_try_remove_proc_entry(const char *name,
447 struct proc_dir_entry *parent)
449 struct proc_dir_entry *t = NULL;
450 struct proc_dir_entry **p;
453 LASSERT(parent != NULL);
456 LPROCFS_WRITE_ENTRY();
458 /* lookup target name */
459 for (p = &parent->subdir; *p; p = &(*p)->next) {
460 if ((*p)->namelen != len)
462 if (memcmp(name, (*p)->name, len))
469 /* verify it's empty: do not count "num_refs" */
470 for (p = &t->subdir; *p; p = &(*p)->next) {
471 if ((*p)->namelen != strlen("num_refs")) {
475 if (memcmp("num_refs", (*p)->name,
476 strlen("num_refs"))) {
484 lprocfs_remove_nolock(&t);
486 LPROCFS_WRITE_EXIT();
490 EXPORT_SYMBOL(lprocfs_try_remove_proc_entry);
492 struct proc_dir_entry *lprocfs_register(const char *name,
493 struct proc_dir_entry *parent,
494 struct lprocfs_vars *list, void *data)
496 struct proc_dir_entry *entry;
499 LPROCFS_WRITE_ENTRY();
500 entry = __lprocfs_srch(parent, name);
502 CERROR("entry '%s' already registered\n", name);
503 GOTO(out, entry = ERR_PTR(-EALREADY));
506 entry = proc_mkdir(name, parent);
508 GOTO(out, entry = ERR_PTR(-ENOMEM));
511 rc = __lprocfs_add_vars(entry, list, data);
513 lprocfs_remove_nolock(&entry);
514 GOTO(out, entry = ERR_PTR(rc));
518 LPROCFS_WRITE_EXIT();
521 EXPORT_SYMBOL(lprocfs_register);
524 struct proc_dir_entry *
525 lprocfs_seq_register(const char *name, struct proc_dir_entry *parent,
526 struct lprocfs_seq_vars *list, void *data)
528 struct proc_dir_entry *newchild;
530 newchild = proc_mkdir(name, parent);
531 if (newchild != NULL && list != NULL) {
532 int rc = lprocfs_seq_add_vars(newchild, list, data);
534 lprocfs_remove(&newchild);
540 EXPORT_SYMBOL(lprocfs_seq_register);
542 /* Generic callbacks */
543 int lprocfs_uint_seq_show(struct seq_file *m, void *data)
545 return seq_printf(m, "%u\n", *(unsigned int *)data);
547 EXPORT_SYMBOL(lprocfs_uint_seq_show);
549 int lprocfs_wr_uint(struct file *file, const char *buffer,
550 unsigned long count, void *data)
553 char dummy[MAX_STRING_SIZE + 1], *end;
556 dummy[MAX_STRING_SIZE] = '\0';
557 if (copy_from_user(dummy, buffer, MAX_STRING_SIZE))
560 tmp = simple_strtoul(dummy, &end, 0);
564 *p = (unsigned int)tmp;
567 EXPORT_SYMBOL(lprocfs_wr_uint);
569 ssize_t lprocfs_uint_seq_write(struct file *file, const char *buffer,
570 size_t count, loff_t *off)
572 int *data = ((struct seq_file *)file->private_data)->private;
575 rc = lprocfs_write_helper(buffer, count, &val);
579 return lprocfs_wr_uint(file, buffer, count, data);
581 EXPORT_SYMBOL(lprocfs_uint_seq_write);
583 int lprocfs_u64_seq_show(struct seq_file *m, void *data)
585 LASSERT(data != NULL);
586 return seq_printf(m, LPU64"\n", *(__u64 *)data);
588 EXPORT_SYMBOL(lprocfs_u64_seq_show);
590 int lprocfs_atomic_seq_show(struct seq_file *m, void *data)
592 atomic_t *atom = data;
593 LASSERT(atom != NULL);
594 return seq_printf(m, "%d\n", atomic_read(atom));
596 EXPORT_SYMBOL(lprocfs_atomic_seq_show);
599 lprocfs_atomic_seq_write(struct file *file, const char *buffer,
600 size_t count, loff_t *off)
602 atomic_t *atm = ((struct seq_file *)file->private_data)->private;
606 rc = lprocfs_write_helper(buffer, count, &val);
613 atomic_set(atm, val);
616 EXPORT_SYMBOL(lprocfs_atomic_seq_write);
618 int lprocfs_uuid_seq_show(struct seq_file *m, void *data)
620 struct obd_device *obd = data;
622 LASSERT(obd != NULL);
623 return seq_printf(m, "%s\n", obd->obd_uuid.uuid);
625 EXPORT_SYMBOL(lprocfs_uuid_seq_show);
627 int lprocfs_name_seq_show(struct seq_file *m, void *data)
629 struct obd_device *dev = data;
631 LASSERT(dev != NULL);
632 return seq_printf(m, "%s\n", dev->obd_name);
634 EXPORT_SYMBOL(lprocfs_name_seq_show);
636 int lprocfs_blksize_seq_show(struct seq_file *m, void *data)
638 struct obd_device *obd = data;
639 struct obd_statfs osfs;
640 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
641 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
644 rc = seq_printf(m, "%u\n", osfs.os_bsize);
647 EXPORT_SYMBOL(lprocfs_blksize_seq_show);
649 int lprocfs_kbytestotal_seq_show(struct seq_file *m, void *data)
651 struct obd_device *obd = data;
652 struct obd_statfs osfs;
653 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
654 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
657 __u32 blk_size = osfs.os_bsize >> 10;
658 __u64 result = osfs.os_blocks;
660 while (blk_size >>= 1)
663 rc = seq_printf(m, LPU64"\n", result);
667 EXPORT_SYMBOL(lprocfs_kbytestotal_seq_show);
669 int lprocfs_kbytesfree_seq_show(struct seq_file *m, void *data)
671 struct obd_device *obd = data;
672 struct obd_statfs osfs;
673 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
674 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
677 __u32 blk_size = osfs.os_bsize >> 10;
678 __u64 result = osfs.os_bfree;
680 while (blk_size >>= 1)
683 rc = seq_printf(m, LPU64"\n", result);
687 EXPORT_SYMBOL(lprocfs_kbytesfree_seq_show);
689 int lprocfs_kbytesavail_seq_show(struct seq_file *m, void *data)
691 struct obd_device *obd = data;
692 struct obd_statfs osfs;
693 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
694 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
697 __u32 blk_size = osfs.os_bsize >> 10;
698 __u64 result = osfs.os_bavail;
700 while (blk_size >>= 1)
703 rc = seq_printf(m, LPU64"\n", result);
707 EXPORT_SYMBOL(lprocfs_kbytesavail_seq_show);
709 int lprocfs_filestotal_seq_show(struct seq_file *m, void *data)
711 struct obd_device *obd = data;
712 struct obd_statfs osfs;
713 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
714 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
717 rc = seq_printf(m, LPU64"\n", osfs.os_files);
720 EXPORT_SYMBOL(lprocfs_filestotal_seq_show);
722 int lprocfs_filesfree_seq_show(struct seq_file *m, void *data)
724 struct obd_device *obd = data;
725 struct obd_statfs osfs;
726 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
727 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
730 rc = seq_printf(m, LPU64"\n", osfs.os_ffree);
733 EXPORT_SYMBOL(lprocfs_filesfree_seq_show);
735 int lprocfs_server_uuid_seq_show(struct seq_file *m, void *data)
737 struct obd_device *obd = data;
738 struct obd_import *imp;
739 char *imp_state_name = NULL;
742 LASSERT(obd != NULL);
743 LPROCFS_CLIMP_CHECK(obd);
744 imp = obd->u.cli.cl_import;
745 imp_state_name = ptlrpc_import_state_name(imp->imp_state);
746 rc = seq_printf(m, "%s\t%s%s\n", obd2cli_tgt(obd), imp_state_name,
747 imp->imp_deactive ? "\tDEACTIVATED" : "");
749 LPROCFS_CLIMP_EXIT(obd);
752 EXPORT_SYMBOL(lprocfs_server_uuid_seq_show);
754 int lprocfs_conn_uuid_seq_show(struct seq_file *m, void *data)
756 struct obd_device *obd = data;
757 struct ptlrpc_connection *conn;
760 LASSERT(obd != NULL);
762 LPROCFS_CLIMP_CHECK(obd);
763 conn = obd->u.cli.cl_import->imp_connection;
764 if (conn && obd->u.cli.cl_import)
765 rc = seq_printf(m, "%s\n", conn->c_remote_uuid.uuid);
767 rc = seq_printf(m, "%s\n", "<none>");
769 LPROCFS_CLIMP_EXIT(obd);
772 EXPORT_SYMBOL(lprocfs_conn_uuid_seq_show);
774 /** add up per-cpu counters */
775 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
776 struct lprocfs_counter *cnt)
778 unsigned int num_entry;
779 struct lprocfs_counter *percpu_cntr;
781 unsigned long flags = 0;
783 memset(cnt, 0, sizeof(*cnt));
786 /* set count to 1 to avoid divide-by-zero errs in callers */
791 cnt->lc_min = LC_MIN_INIT;
793 num_entry = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
795 for (i = 0; i < num_entry; i++) {
796 if (stats->ls_percpu[i] == NULL)
798 percpu_cntr = lprocfs_stats_counter_get(stats, i, idx);
800 cnt->lc_count += percpu_cntr->lc_count;
801 cnt->lc_sum += percpu_cntr->lc_sum;
802 if (percpu_cntr->lc_min < cnt->lc_min)
803 cnt->lc_min = percpu_cntr->lc_min;
804 if (percpu_cntr->lc_max > cnt->lc_max)
805 cnt->lc_max = percpu_cntr->lc_max;
806 cnt->lc_sumsquare += percpu_cntr->lc_sumsquare;
809 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
811 EXPORT_SYMBOL(lprocfs_stats_collect);
814 * Append a space separated list of current set flags to str.
816 #define flag2seqstr(flag) \
818 if (imp->imp_##flag) { \
819 seq_printf(m, "%s" #flag, first ? "" : ", "); \
823 static void obd_import_flags2seqstr(struct obd_import *imp, struct seq_file *m)
827 if (imp->imp_obd->obd_no_recov) {
828 seq_printf(m, "no_recov");
832 flag2seqstr(invalid);
833 flag2seqstr(deactive);
834 flag2seqstr(replayable);
835 flag2seqstr(delayed_recovery);
836 flag2seqstr(no_lock_replay);
837 flag2seqstr(vbr_failed);
838 flag2seqstr(pingable);
839 flag2seqstr(resend_replay);
840 flag2seqstr(no_pinger_recover);
841 flag2seqstr(need_mne_swab);
842 flag2seqstr(connect_tried);
846 static const char *obd_connect_names[] = {
860 "join_file(obsolete)",
864 "remote_client_by_force",
873 "mds_mds_connection",
876 "alt_checksum_algorithm",
910 static void obd_connect_seq_flags2str(struct seq_file *m, __u64 flags, char *sep)
916 for (i = 0; obd_connect_names[i] != NULL; i++, mask <<= 1) {
918 seq_printf(m, "%s%s",
919 first ? "" : sep, obd_connect_names[i]);
923 if (flags & ~(mask - 1))
924 seq_printf(m, "%sunknown_"LPX64,
925 first ? "" : sep, flags & ~(mask - 1));
928 int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep)
933 for (i = 0; obd_connect_names[i] != NULL; i++, mask <<= 1) {
935 ret += snprintf(page + ret, count - ret, "%s%s",
936 ret ? sep : "", obd_connect_names[i]);
938 if (flags & ~(mask - 1))
939 ret += snprintf(page + ret, count - ret,
941 ret ? sep : "", flags & ~(mask - 1));
944 EXPORT_SYMBOL(obd_connect_flags2str);
946 static void obd_connect_data_seqprint(struct seq_file *m,
947 struct obd_connect_data *ocd)
951 LASSERT(ocd != NULL);
952 flags = ocd->ocd_connect_flags;
954 seq_printf(m, " connect_data:\n"
957 ocd->ocd_connect_flags,
959 if (flags & OBD_CONNECT_VERSION)
960 seq_printf(m, " target_version: %u.%u.%u.%u\n",
961 OBD_OCD_VERSION_MAJOR(ocd->ocd_version),
962 OBD_OCD_VERSION_MINOR(ocd->ocd_version),
963 OBD_OCD_VERSION_PATCH(ocd->ocd_version),
964 OBD_OCD_VERSION_FIX(ocd->ocd_version));
965 if (flags & OBD_CONNECT_MDS)
966 seq_printf(m, " mdt_index: %d\n", ocd->ocd_group);
967 if (flags & OBD_CONNECT_GRANT)
968 seq_printf(m, " initial_grant: %d\n", ocd->ocd_grant);
969 if (flags & OBD_CONNECT_INDEX)
970 seq_printf(m, " target_index: %u\n", ocd->ocd_index);
971 if (flags & OBD_CONNECT_BRW_SIZE)
972 seq_printf(m, " max_brw_size: %d\n", ocd->ocd_brw_size);
973 if (flags & OBD_CONNECT_IBITS)
974 seq_printf(m, " ibits_known: "LPX64"\n",
975 ocd->ocd_ibits_known);
976 if (flags & OBD_CONNECT_GRANT_PARAM)
977 seq_printf(m, " grant_block_size: %d\n"
978 " grant_inode_size: %d\n"
979 " grant_extent_overhead: %d\n",
982 ocd->ocd_grant_extent);
983 if (flags & OBD_CONNECT_TRANSNO)
984 seq_printf(m, " first_transno: "LPX64"\n",
986 if (flags & OBD_CONNECT_CKSUM)
987 seq_printf(m, " cksum_types: %#x\n",
988 ocd->ocd_cksum_types);
989 if (flags & OBD_CONNECT_MAX_EASIZE)
990 seq_printf(m, " max_easize: %d\n", ocd->ocd_max_easize);
991 if (flags & OBD_CONNECT_MAXBYTES)
992 seq_printf(m, " max_object_bytes: "LPU64"\n",
996 int lprocfs_import_seq_show(struct seq_file *m, void *data)
998 struct lprocfs_counter ret;
999 struct lprocfs_counter_header *header;
1000 struct obd_device *obd = (struct obd_device *)data;
1001 struct obd_import *imp;
1002 struct obd_import_conn *conn;
1003 struct obd_connect_data *ocd;
1008 LASSERT(obd != NULL);
1009 LPROCFS_CLIMP_CHECK(obd);
1010 imp = obd->u.cli.cl_import;
1011 ocd = &imp->imp_connect_data;
1013 seq_printf(m, "import:\n"
1017 " connect_flags: [ ",
1020 ptlrpc_import_state_name(imp->imp_state));
1021 obd_connect_seq_flags2str(m, imp->imp_connect_data.ocd_connect_flags,
1023 seq_printf(m, " ]\n");
1024 obd_connect_data_seqprint(m, ocd);
1025 seq_printf(m, " import_flags: [ ");
1026 obd_import_flags2seqstr(imp, m);
1028 seq_printf(m, " ]\n"
1030 " failover_nids: [ ");
1031 spin_lock(&imp->imp_lock);
1033 list_for_each_entry(conn, &imp->imp_conn_list, oic_item) {
1034 seq_printf(m, "%s%s", j ? ", " : "",
1035 libcfs_nid2str(conn->oic_conn->c_peer.nid));
1038 seq_printf(m, " ]\n"
1039 " current_connection: %s\n"
1040 " connection_attempts: %u\n"
1042 " in-progress_invalidations: %u\n",
1043 imp->imp_connection == NULL ? "<none>" :
1044 libcfs_nid2str(imp->imp_connection->c_peer.nid),
1046 imp->imp_generation,
1047 atomic_read(&imp->imp_inval_count));
1048 spin_unlock(&imp->imp_lock);
1050 if (obd->obd_svc_stats == NULL)
1053 header = &obd->obd_svc_stats->ls_cnt_header[PTLRPC_REQWAIT_CNTR];
1054 lprocfs_stats_collect(obd->obd_svc_stats, PTLRPC_REQWAIT_CNTR, &ret);
1055 if (ret.lc_count != 0) {
1056 /* first argument to do_div MUST be __u64 */
1057 __u64 sum = ret.lc_sum;
1058 do_div(sum, ret.lc_count);
1062 seq_printf(m, " rpcs:\n"
1064 " unregistering: %u\n"
1066 " avg_waittime: "LPU64" %s\n",
1067 atomic_read(&imp->imp_inflight),
1068 atomic_read(&imp->imp_unregistering),
1069 atomic_read(&imp->imp_timeouts),
1070 ret.lc_sum, header->lc_units);
1073 for(j = 0; j < IMP_AT_MAX_PORTALS; j++) {
1074 if (imp->imp_at.iat_portal[j] == 0)
1076 k = max_t(unsigned int, k,
1077 at_get(&imp->imp_at.iat_service_estimate[j]));
1079 seq_printf(m, " service_estimates:\n"
1080 " services: %u sec\n"
1081 " network: %u sec\n",
1083 at_get(&imp->imp_at.iat_net_latency));
1085 seq_printf(m, " transactions:\n"
1086 " last_replay: "LPU64"\n"
1087 " peer_committed: "LPU64"\n"
1088 " last_checked: "LPU64"\n",
1089 imp->imp_last_replay_transno,
1090 imp->imp_peer_committed_transno,
1091 imp->imp_last_transno_checked);
1093 /* avg data rates */
1094 for (rw = 0; rw <= 1; rw++) {
1095 lprocfs_stats_collect(obd->obd_svc_stats,
1096 PTLRPC_LAST_CNTR + BRW_READ_BYTES + rw,
1098 if (ret.lc_sum > 0 && ret.lc_count > 0) {
1099 /* first argument to do_div MUST be __u64 */
1100 __u64 sum = ret.lc_sum;
1101 do_div(sum, ret.lc_count);
1103 seq_printf(m, " %s_data_averages:\n"
1104 " bytes_per_rpc: "LPU64"\n",
1105 rw ? "write" : "read",
1108 k = (int)ret.lc_sum;
1109 j = opcode_offset(OST_READ + rw) + EXTRA_MAX_OPCODES;
1110 header = &obd->obd_svc_stats->ls_cnt_header[j];
1111 lprocfs_stats_collect(obd->obd_svc_stats, j, &ret);
1112 if (ret.lc_sum > 0 && ret.lc_count != 0) {
1113 /* first argument to do_div MUST be __u64 */
1114 __u64 sum = ret.lc_sum;
1115 do_div(sum, ret.lc_count);
1117 seq_printf(m, " %s_per_rpc: "LPU64"\n",
1118 header->lc_units, ret.lc_sum);
1119 j = (int)ret.lc_sum;
1121 seq_printf(m, " MB_per_sec: %u.%.02u\n",
1122 k / j, (100 * k / j) % 100);
1127 LPROCFS_CLIMP_EXIT(obd);
1130 EXPORT_SYMBOL(lprocfs_import_seq_show);
1132 int lprocfs_state_seq_show(struct seq_file *m, void *data)
1134 struct obd_device *obd = (struct obd_device *)data;
1135 struct obd_import *imp;
1138 LASSERT(obd != NULL);
1139 LPROCFS_CLIMP_CHECK(obd);
1140 imp = obd->u.cli.cl_import;
1142 seq_printf(m, "current_state: %s\n",
1143 ptlrpc_import_state_name(imp->imp_state));
1144 seq_printf(m, "state_history:\n");
1145 k = imp->imp_state_hist_idx;
1146 for (j = 0; j < IMP_STATE_HIST_LEN; j++) {
1147 struct import_state_hist *ish =
1148 &imp->imp_state_hist[(k + j) % IMP_STATE_HIST_LEN];
1149 if (ish->ish_state == 0)
1151 seq_printf(m, " - [ "CFS_TIME_T", %s ]\n",
1153 ptlrpc_import_state_name(ish->ish_state));
1156 LPROCFS_CLIMP_EXIT(obd);
1159 EXPORT_SYMBOL(lprocfs_state_seq_show);
1161 int lprocfs_seq_at_hist_helper(struct seq_file *m, struct adaptive_timeout *at)
1164 for (i = 0; i < AT_BINS; i++)
1165 seq_printf(m, "%3u ", at->at_hist[i]);
1166 seq_printf(m, "\n");
1169 EXPORT_SYMBOL(lprocfs_seq_at_hist_helper);
1171 /* See also ptlrpc_lprocfs_timeouts_show_seq */
1172 int lprocfs_timeouts_seq_show(struct seq_file *m, void *data)
1174 struct obd_device *obd = (struct obd_device *)data;
1175 struct obd_import *imp;
1176 unsigned int cur, worst;
1181 LASSERT(obd != NULL);
1182 LPROCFS_CLIMP_CHECK(obd);
1183 imp = obd->u.cli.cl_import;
1185 now = cfs_time_current_sec();
1187 /* Some network health info for kicks */
1188 s2dhms(&ts, now - imp->imp_last_reply_time);
1189 seq_printf(m, "%-10s : %ld, "DHMS_FMT" ago\n",
1190 "last reply", imp->imp_last_reply_time, DHMS_VARS(&ts));
1192 cur = at_get(&imp->imp_at.iat_net_latency);
1193 worst = imp->imp_at.iat_net_latency.at_worst_ever;
1194 worstt = imp->imp_at.iat_net_latency.at_worst_time;
1195 s2dhms(&ts, now - worstt);
1196 seq_printf(m, "%-10s : cur %3u worst %3u (at %ld, "DHMS_FMT" ago) ",
1197 "network", cur, worst, worstt, DHMS_VARS(&ts));
1198 lprocfs_seq_at_hist_helper(m, &imp->imp_at.iat_net_latency);
1200 for(i = 0; i < IMP_AT_MAX_PORTALS; i++) {
1201 if (imp->imp_at.iat_portal[i] == 0)
1203 cur = at_get(&imp->imp_at.iat_service_estimate[i]);
1204 worst = imp->imp_at.iat_service_estimate[i].at_worst_ever;
1205 worstt = imp->imp_at.iat_service_estimate[i].at_worst_time;
1206 s2dhms(&ts, now - worstt);
1207 seq_printf(m, "portal %-2d : cur %3u worst %3u (at %ld, "
1208 DHMS_FMT" ago) ", imp->imp_at.iat_portal[i],
1209 cur, worst, worstt, DHMS_VARS(&ts));
1210 lprocfs_seq_at_hist_helper(m, &imp->imp_at.iat_service_estimate[i]);
1213 LPROCFS_CLIMP_EXIT(obd);
1216 EXPORT_SYMBOL(lprocfs_timeouts_seq_show);
1218 int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data)
1220 struct obd_device *obd = data;
1223 LPROCFS_CLIMP_CHECK(obd);
1224 flags = obd->u.cli.cl_import->imp_connect_data.ocd_connect_flags;
1225 seq_printf(m, "flags="LPX64"\n", flags);
1226 obd_connect_seq_flags2str(m, flags, "\n");
1227 seq_printf(m, "\n");
1228 LPROCFS_CLIMP_EXIT(obd);
1231 EXPORT_SYMBOL(lprocfs_connect_flags_seq_show);
1233 #ifndef HAVE_ONLY_PROCFS_SEQ
1235 int lprocfs_rd_uint(char *page, char **start, off_t off,
1236 int count, int *eof, void *data)
1238 unsigned int *temp = data;
1239 return snprintf(page, count, "%u\n", *temp);
1241 EXPORT_SYMBOL(lprocfs_rd_uint);
1243 int lprocfs_rd_u64(char *page, char **start, off_t off,
1244 int count, int *eof, void *data)
1246 LASSERT(data != NULL);
1248 return snprintf(page, count, LPU64"\n", *(__u64 *)data);
1250 EXPORT_SYMBOL(lprocfs_rd_u64);
1252 int lprocfs_rd_atomic(char *page, char **start, off_t off,
1253 int count, int *eof, void *data)
1255 atomic_t *atom = data;
1256 LASSERT(atom != NULL);
1258 return snprintf(page, count, "%d\n", atomic_read(atom));
1260 EXPORT_SYMBOL(lprocfs_rd_atomic);
1262 int lprocfs_wr_atomic(struct file *file, const char *buffer,
1263 unsigned long count, void *data)
1265 atomic_t *atm = data;
1269 rc = lprocfs_write_helper(buffer, count, &val);
1276 atomic_set(atm, val);
1279 EXPORT_SYMBOL(lprocfs_wr_atomic);
1281 int lprocfs_rd_uuid(char *page, char **start, off_t off, int count,
1282 int *eof, void *data)
1284 struct obd_device *obd = data;
1286 LASSERT(obd != NULL);
1288 return snprintf(page, count, "%s\n", obd->obd_uuid.uuid);
1290 EXPORT_SYMBOL(lprocfs_rd_uuid);
1292 int lprocfs_rd_name(char *page, char **start, off_t off, int count,
1293 int *eof, void *data)
1295 struct obd_device *dev = data;
1297 LASSERT(dev != NULL);
1299 return snprintf(page, count, "%s\n", dev->obd_name);
1301 EXPORT_SYMBOL(lprocfs_rd_name);
1303 int lprocfs_rd_blksize(char *page, char **start, off_t off, int count,
1304 int *eof, void *data)
1306 struct obd_device *obd = data;
1307 struct obd_statfs osfs;
1308 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
1309 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1310 OBD_STATFS_NODELAY);
1313 rc = snprintf(page, count, "%u\n", osfs.os_bsize);
1317 EXPORT_SYMBOL(lprocfs_rd_blksize);
1319 int lprocfs_rd_kbytestotal(char *page, char **start, off_t off, int count,
1320 int *eof, void *data)
1322 struct obd_device *obd = data;
1323 struct obd_statfs osfs;
1324 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
1325 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1326 OBD_STATFS_NODELAY);
1328 __u32 blk_size = osfs.os_bsize >> 10;
1329 __u64 result = osfs.os_blocks;
1331 while (blk_size >>= 1)
1335 rc = snprintf(page, count, LPU64"\n", result);
1339 EXPORT_SYMBOL(lprocfs_rd_kbytestotal);
1341 int lprocfs_rd_kbytesfree(char *page, char **start, off_t off, int count,
1342 int *eof, void *data)
1344 struct obd_device *obd = data;
1345 struct obd_statfs osfs;
1346 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
1347 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1348 OBD_STATFS_NODELAY);
1350 __u32 blk_size = osfs.os_bsize >> 10;
1351 __u64 result = osfs.os_bfree;
1353 while (blk_size >>= 1)
1357 rc = snprintf(page, count, LPU64"\n", result);
1361 EXPORT_SYMBOL(lprocfs_rd_kbytesfree);
1363 int lprocfs_rd_kbytesavail(char *page, char **start, off_t off, int count,
1364 int *eof, void *data)
1366 struct obd_device *obd = data;
1367 struct obd_statfs osfs;
1368 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
1369 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1370 OBD_STATFS_NODELAY);
1372 __u32 blk_size = osfs.os_bsize >> 10;
1373 __u64 result = osfs.os_bavail;
1375 while (blk_size >>= 1)
1379 rc = snprintf(page, count, LPU64"\n", result);
1383 EXPORT_SYMBOL(lprocfs_rd_kbytesavail);
1385 int lprocfs_rd_filestotal(char *page, char **start, off_t off, int count,
1386 int *eof, void *data)
1388 struct obd_device *obd = data;
1389 struct obd_statfs osfs;
1390 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
1391 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1392 OBD_STATFS_NODELAY);
1395 rc = snprintf(page, count, LPU64"\n", osfs.os_files);
1400 EXPORT_SYMBOL(lprocfs_rd_filestotal);
1402 int lprocfs_rd_filesfree(char *page, char **start, off_t off, int count,
1403 int *eof, void *data)
1405 struct obd_device *obd = data;
1406 struct obd_statfs osfs;
1407 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
1408 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1409 OBD_STATFS_NODELAY);
1412 rc = snprintf(page, count, LPU64"\n", osfs.os_ffree);
1416 EXPORT_SYMBOL(lprocfs_rd_filesfree);
1418 int lprocfs_rd_server_uuid(char *page, char **start, off_t off, int count,
1419 int *eof, void *data)
1421 struct obd_device *obd = data;
1422 struct obd_import *imp;
1423 char *imp_state_name = NULL;
1426 LASSERT(obd != NULL);
1427 LPROCFS_CLIMP_CHECK(obd);
1428 imp = obd->u.cli.cl_import;
1429 imp_state_name = ptlrpc_import_state_name(imp->imp_state);
1431 rc = snprintf(page, count, "%s\t%s%s\n",
1432 obd2cli_tgt(obd), imp_state_name,
1433 imp->imp_deactive ? "\tDEACTIVATED" : "");
1435 LPROCFS_CLIMP_EXIT(obd);
1438 EXPORT_SYMBOL(lprocfs_rd_server_uuid);
1440 int lprocfs_rd_conn_uuid(char *page, char **start, off_t off, int count,
1441 int *eof, void *data)
1443 struct obd_device *obd = data;
1444 struct ptlrpc_connection *conn;
1447 LASSERT(obd != NULL);
1449 LPROCFS_CLIMP_CHECK(obd);
1450 conn = obd->u.cli.cl_import->imp_connection;
1452 if (conn && obd->u.cli.cl_import) {
1453 rc = snprintf(page, count, "%s\n",
1454 conn->c_remote_uuid.uuid);
1456 rc = snprintf(page, count, "%s\n", "<none>");
1459 LPROCFS_CLIMP_EXIT(obd);
1462 EXPORT_SYMBOL(lprocfs_rd_conn_uuid);
1465 * Append a space separated list of current set flags to str.
1467 #define flag2str(flag) \
1468 if (imp->imp_##flag && max - len > 0) \
1469 len += snprintf(str + len, max - len, "%s" #flag, len ? ", " : "");
1470 static int obd_import_flags2str(struct obd_import *imp, char *str, int max)
1474 if (imp->imp_obd->obd_no_recov)
1475 len += snprintf(str, max - len, "no_recov");
1479 flag2str(replayable);
1485 int lprocfs_rd_import(char *page, char **start, off_t off, int count,
1486 int *eof, void *data)
1488 struct lprocfs_counter ret;
1489 struct lprocfs_counter_header *header;
1490 struct obd_device *obd = (struct obd_device *)data;
1491 struct obd_import *imp;
1492 struct obd_import_conn *conn;
1498 LASSERT(obd != NULL);
1499 LPROCFS_CLIMP_CHECK(obd);
1500 imp = obd->u.cli.cl_import;
1503 i = snprintf(page, count,
1509 " connect_flags: [",
1512 ptlrpc_import_state_name(imp->imp_state),
1513 imp->imp_connect_data.ocd_instance);
1514 i += obd_connect_flags2str(page + i, count - i,
1515 imp->imp_connect_data.ocd_connect_flags,
1517 i += snprintf(page + i, count - i,
1519 " import_flags: [");
1520 i += obd_import_flags2str(imp, page + i, count - i);
1522 i += snprintf(page + i, count - i,
1525 " failover_nids: [");
1526 spin_lock(&imp->imp_lock);
1528 list_for_each_entry(conn, &imp->imp_conn_list, oic_item) {
1529 i += snprintf(page + i, count - i, "%s%s", j ? ", " : "",
1530 libcfs_nid2str(conn->oic_conn->c_peer.nid));
1533 i += snprintf(page + i, count - i,
1535 " current_connection: %s\n"
1536 " connection_attempts: %u\n"
1538 " in-progress_invalidations: %u\n",
1539 imp->imp_connection == NULL ? "<none>" :
1540 libcfs_nid2str(imp->imp_connection->c_peer.nid),
1542 imp->imp_generation,
1543 atomic_read(&imp->imp_inval_count));
1544 spin_unlock(&imp->imp_lock);
1546 if (obd->obd_svc_stats == NULL)
1549 header = &obd->obd_svc_stats->ls_cnt_header[PTLRPC_REQWAIT_CNTR];
1550 lprocfs_stats_collect(obd->obd_svc_stats, PTLRPC_REQWAIT_CNTR, &ret);
1551 if (ret.lc_count != 0) {
1552 /* first argument to do_div MUST be __u64 */
1553 __u64 sum = ret.lc_sum;
1554 do_div(sum, ret.lc_count);
1558 i += snprintf(page + i, count - i,
1561 " unregistering: %u\n"
1563 " avg_waittime: "LPU64" %s\n",
1564 atomic_read(&imp->imp_inflight),
1565 atomic_read(&imp->imp_unregistering),
1566 atomic_read(&imp->imp_timeouts),
1567 ret.lc_sum, header->lc_units);
1570 for(j = 0; j < IMP_AT_MAX_PORTALS; j++) {
1571 if (imp->imp_at.iat_portal[j] == 0)
1573 k = max_t(unsigned int, k,
1574 at_get(&imp->imp_at.iat_service_estimate[j]));
1576 i += snprintf(page + i, count - i,
1577 " service_estimates:\n"
1578 " services: %u sec\n"
1579 " network: %u sec\n",
1581 at_get(&imp->imp_at.iat_net_latency));
1583 i += snprintf(page + i, count - i,
1585 " last_replay: "LPU64"\n"
1586 " peer_committed: "LPU64"\n"
1587 " last_checked: "LPU64"\n",
1588 imp->imp_last_replay_transno,
1589 imp->imp_peer_committed_transno,
1590 imp->imp_last_transno_checked);
1592 /* avg data rates */
1593 for (rw = 0; rw <= 1; rw++) {
1594 lprocfs_stats_collect(obd->obd_svc_stats,
1595 PTLRPC_LAST_CNTR + BRW_READ_BYTES + rw,
1597 if (ret.lc_sum > 0 && ret.lc_count > 0) {
1598 /* first argument to do_div MUST be __u64 */
1599 __u64 sum = ret.lc_sum;
1600 do_div(sum, ret.lc_count);
1602 i += snprintf(page + i, count - i,
1603 " %s_data_averages:\n"
1604 " bytes_per_rpc: "LPU64"\n",
1605 rw ? "write" : "read",
1608 k = (int)ret.lc_sum;
1609 j = opcode_offset(OST_READ + rw) + EXTRA_MAX_OPCODES;
1610 header = &obd->obd_svc_stats->ls_cnt_header[j];
1611 lprocfs_stats_collect(obd->obd_svc_stats, j, &ret);
1612 if (ret.lc_sum > 0 && ret.lc_count != 0) {
1613 /* first argument to do_div MUST be __u64 */
1614 __u64 sum = ret.lc_sum;
1615 do_div(sum, ret.lc_count);
1617 i += snprintf(page + i, count - i,
1618 " %s_per_rpc: "LPU64"\n",
1619 header->lc_units, ret.lc_sum);
1620 j = (int)ret.lc_sum;
1622 i += snprintf(page + i, count - i,
1623 " MB_per_sec: %u.%.02u\n",
1624 k / j, (100 * k / j) % 100);
1629 LPROCFS_CLIMP_EXIT(obd);
1632 EXPORT_SYMBOL(lprocfs_rd_import);
1634 int lprocfs_rd_state(char *page, char **start, off_t off, int count,
1635 int *eof, void *data)
1637 struct obd_device *obd = (struct obd_device *)data;
1638 struct obd_import *imp;
1641 LASSERT(obd != NULL);
1642 LPROCFS_CLIMP_CHECK(obd);
1643 imp = obd->u.cli.cl_import;
1646 i = snprintf(page, count, "current_state: %s\n",
1647 ptlrpc_import_state_name(imp->imp_state));
1648 i += snprintf(page + i, count - i,
1649 "state_history:\n");
1650 k = imp->imp_state_hist_idx;
1651 for (j = 0; j < IMP_STATE_HIST_LEN; j++) {
1652 struct import_state_hist *ish =
1653 &imp->imp_state_hist[(k + j) % IMP_STATE_HIST_LEN];
1654 if (ish->ish_state == 0)
1656 i += snprintf(page + i, count - i, " - ["CFS_TIME_T", %s]\n",
1658 ptlrpc_import_state_name(ish->ish_state));
1661 LPROCFS_CLIMP_EXIT(obd);
1664 EXPORT_SYMBOL(lprocfs_rd_state);
1666 int lprocfs_at_hist_helper(char *page, int count, int rc,
1667 struct adaptive_timeout *at)
1670 for (i = 0; i < AT_BINS; i++)
1671 rc += snprintf(page + rc, count - rc, "%3u ", at->at_hist[i]);
1672 rc += snprintf(page + rc, count - rc, "\n");
1675 EXPORT_SYMBOL(lprocfs_at_hist_helper);
1677 /* See also ptlrpc_lprocfs_rd_timeouts */
1678 int lprocfs_rd_timeouts(char *page, char **start, off_t off, int count,
1679 int *eof, void *data)
1681 struct obd_device *obd = (struct obd_device *)data;
1682 struct obd_import *imp;
1683 unsigned int cur, worst;
1688 LASSERT(obd != NULL);
1689 LPROCFS_CLIMP_CHECK(obd);
1690 imp = obd->u.cli.cl_import;
1693 now = cfs_time_current_sec();
1695 /* Some network health info for kicks */
1696 s2dhms(&ts, now - imp->imp_last_reply_time);
1697 rc += snprintf(page + rc, count - rc,
1698 "%-10s : %ld, "DHMS_FMT" ago\n",
1699 "last reply", imp->imp_last_reply_time, DHMS_VARS(&ts));
1701 cur = at_get(&imp->imp_at.iat_net_latency);
1702 worst = imp->imp_at.iat_net_latency.at_worst_ever;
1703 worstt = imp->imp_at.iat_net_latency.at_worst_time;
1704 s2dhms(&ts, now - worstt);
1705 rc += snprintf(page + rc, count - rc,
1706 "%-10s : cur %3u worst %3u (at %ld, "DHMS_FMT" ago) ",
1707 "network", cur, worst, worstt, DHMS_VARS(&ts));
1708 rc = lprocfs_at_hist_helper(page, count, rc,
1709 &imp->imp_at.iat_net_latency);
1711 for(i = 0; i < IMP_AT_MAX_PORTALS; i++) {
1712 if (imp->imp_at.iat_portal[i] == 0)
1714 cur = at_get(&imp->imp_at.iat_service_estimate[i]);
1715 worst = imp->imp_at.iat_service_estimate[i].at_worst_ever;
1716 worstt = imp->imp_at.iat_service_estimate[i].at_worst_time;
1717 s2dhms(&ts, now - worstt);
1718 rc += snprintf(page + rc, count - rc,
1719 "portal %-2d : cur %3u worst %3u (at %ld, "
1720 DHMS_FMT" ago) ", imp->imp_at.iat_portal[i],
1721 cur, worst, worstt, DHMS_VARS(&ts));
1722 rc = lprocfs_at_hist_helper(page, count, rc,
1723 &imp->imp_at.iat_service_estimate[i]);
1726 LPROCFS_CLIMP_EXIT(obd);
1729 EXPORT_SYMBOL(lprocfs_rd_timeouts);
1731 int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
1732 int count, int *eof, void *data)
1734 struct obd_device *obd = data;
1738 LPROCFS_CLIMP_CHECK(obd);
1739 flags = obd->u.cli.cl_import->imp_connect_data.ocd_connect_flags;
1740 ret = snprintf(page, count, "flags="LPX64"\n", flags);
1741 ret += obd_connect_flags2str(page + ret, count - ret, flags, "\n");
1742 ret += snprintf(page + ret, count - ret, "\n");
1743 LPROCFS_CLIMP_EXIT(obd);
1746 EXPORT_SYMBOL(lprocfs_rd_connect_flags);
1748 int lprocfs_rd_numrefs(char *page, char **start, off_t off, int count,
1749 int *eof, void *data)
1751 struct obd_type *class = (struct obd_type*) data;
1753 LASSERT(class != NULL);
1755 return snprintf(page, count, "%d\n", class->typ_refcnt);
1757 EXPORT_SYMBOL(lprocfs_rd_numrefs);
1759 int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list)
1763 LASSERT(obd != NULL);
1764 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1765 LASSERT(obd->obd_type->typ_procroot != NULL);
1767 obd->obd_proc_entry = lprocfs_register(obd->obd_name,
1768 obd->obd_type->typ_procroot,
1770 if (IS_ERR(obd->obd_proc_entry)) {
1771 rc = PTR_ERR(obd->obd_proc_entry);
1772 CERROR("error %d setting up lprocfs for %s\n",rc,obd->obd_name);
1773 obd->obd_proc_entry = NULL;
1777 EXPORT_SYMBOL(lprocfs_obd_setup);
1781 lprocfs_seq_obd_setup(struct obd_device *obd)
1785 LASSERT(obd != NULL);
1786 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1787 LASSERT(obd->obd_type->typ_procroot != NULL);
1789 obd->obd_proc_entry = lprocfs_seq_register(obd->obd_name,
1790 obd->obd_type->typ_procroot,
1791 obd->obd_vars, obd);
1792 if (IS_ERR(obd->obd_proc_entry)) {
1793 rc = PTR_ERR(obd->obd_proc_entry);
1794 CERROR("error %d setting up lprocfs for %s\n",rc,obd->obd_name);
1795 obd->obd_proc_entry = NULL;
1799 EXPORT_SYMBOL(lprocfs_seq_obd_setup);
1801 int lprocfs_obd_cleanup(struct obd_device *obd)
1805 if (obd->obd_proc_exports_entry) {
1806 /* Should be no exports left */
1807 lprocfs_remove(&obd->obd_proc_exports_entry);
1808 obd->obd_proc_exports_entry = NULL;
1810 if (obd->obd_proc_entry) {
1811 lprocfs_remove(&obd->obd_proc_entry);
1812 obd->obd_proc_entry = NULL;
1816 EXPORT_SYMBOL(lprocfs_obd_cleanup);
1818 int lprocfs_stats_alloc_one(struct lprocfs_stats *stats, unsigned int cpuid)
1820 struct lprocfs_counter *cntr;
1821 unsigned int percpusize;
1823 unsigned long flags = 0;
1826 LASSERT(stats->ls_percpu[cpuid] == NULL);
1827 LASSERT((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0);
1829 percpusize = lprocfs_stats_counter_size(stats);
1830 LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[cpuid], percpusize);
1831 if (stats->ls_percpu[cpuid] != NULL) {
1833 if (unlikely(stats->ls_biggest_alloc_num <= cpuid)) {
1834 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
1835 spin_lock_irqsave(&stats->ls_lock, flags);
1837 spin_lock(&stats->ls_lock);
1838 if (stats->ls_biggest_alloc_num <= cpuid)
1839 stats->ls_biggest_alloc_num = cpuid + 1;
1840 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) {
1841 spin_unlock_irqrestore(&stats->ls_lock, flags);
1843 spin_unlock(&stats->ls_lock);
1846 /* initialize the ls_percpu[cpuid] non-zero counter */
1847 for (i = 0; i < stats->ls_num; ++i) {
1848 cntr = lprocfs_stats_counter_get(stats, cpuid, i);
1849 cntr->lc_min = LC_MIN_INIT;
1854 EXPORT_SYMBOL(lprocfs_stats_alloc_one);
1856 struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num,
1857 enum lprocfs_stats_flags flags)
1859 struct lprocfs_stats *stats;
1860 unsigned int num_entry;
1861 unsigned int percpusize = 0;
1867 if (lprocfs_no_percpu_stats != 0)
1868 flags |= LPROCFS_STATS_FLAG_NOPERCPU;
1870 if (flags & LPROCFS_STATS_FLAG_NOPERCPU)
1873 num_entry = num_possible_cpus();
1875 /* alloc percpu pointers for all possible cpu slots */
1876 LIBCFS_ALLOC(stats, offsetof(typeof(*stats), ls_percpu[num_entry]));
1880 stats->ls_num = num;
1881 stats->ls_flags = flags;
1882 spin_lock_init(&stats->ls_lock);
1884 /* alloc num of counter headers */
1885 LIBCFS_ALLOC(stats->ls_cnt_header,
1886 stats->ls_num * sizeof(struct lprocfs_counter_header));
1887 if (stats->ls_cnt_header == NULL)
1890 if ((flags & LPROCFS_STATS_FLAG_NOPERCPU) != 0) {
1891 /* contains only one set counters */
1892 percpusize = lprocfs_stats_counter_size(stats);
1893 LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[0], percpusize);
1894 if (stats->ls_percpu[0] == NULL)
1896 stats->ls_biggest_alloc_num = 1;
1897 } else if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0) {
1898 /* alloc all percpu data, currently only obd_memory use this */
1899 for (i = 0; i < num_entry; ++i)
1900 if (lprocfs_stats_alloc_one(stats, i) < 0)
1907 lprocfs_free_stats(&stats);
1910 EXPORT_SYMBOL(lprocfs_alloc_stats);
1912 void lprocfs_free_stats(struct lprocfs_stats **statsh)
1914 struct lprocfs_stats *stats = *statsh;
1915 unsigned int num_entry;
1916 unsigned int percpusize;
1919 if (stats == NULL || stats->ls_num == 0)
1923 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU)
1926 num_entry = num_possible_cpus();
1928 percpusize = lprocfs_stats_counter_size(stats);
1929 for (i = 0; i < num_entry; i++)
1930 if (stats->ls_percpu[i] != NULL)
1931 LIBCFS_FREE(stats->ls_percpu[i], percpusize);
1932 if (stats->ls_cnt_header != NULL)
1933 LIBCFS_FREE(stats->ls_cnt_header, stats->ls_num *
1934 sizeof(struct lprocfs_counter_header));
1935 LIBCFS_FREE(stats, offsetof(typeof(*stats), ls_percpu[num_entry]));
1937 EXPORT_SYMBOL(lprocfs_free_stats);
1939 void lprocfs_clear_stats(struct lprocfs_stats *stats)
1941 struct lprocfs_counter *percpu_cntr;
1944 unsigned int num_entry;
1945 unsigned long flags = 0;
1947 num_entry = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1949 for (i = 0; i < num_entry; i++) {
1950 if (stats->ls_percpu[i] == NULL)
1952 for (j = 0; j < stats->ls_num; j++) {
1953 percpu_cntr = lprocfs_stats_counter_get(stats, i, j);
1954 percpu_cntr->lc_count = 0;
1955 percpu_cntr->lc_min = LC_MIN_INIT;
1956 percpu_cntr->lc_max = 0;
1957 percpu_cntr->lc_sumsquare = 0;
1958 percpu_cntr->lc_sum = 0;
1959 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
1960 percpu_cntr->lc_sum_irq = 0;
1964 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1966 EXPORT_SYMBOL(lprocfs_clear_stats);
1968 static ssize_t lprocfs_stats_seq_write(struct file *file, const char *buf,
1969 size_t len, loff_t *off)
1971 struct seq_file *seq = file->private_data;
1972 struct lprocfs_stats *stats = seq->private;
1974 lprocfs_clear_stats(stats);
1979 static void *lprocfs_stats_seq_start(struct seq_file *p, loff_t *pos)
1981 struct lprocfs_stats *stats = p->private;
1983 return (*pos < stats->ls_num) ? pos : NULL;
1986 static void lprocfs_stats_seq_stop(struct seq_file *p, void *v)
1990 static void *lprocfs_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
1994 return lprocfs_stats_seq_start(p, pos);
1997 /* seq file export of one lprocfs counter */
1998 static int lprocfs_stats_seq_show(struct seq_file *p, void *v)
2000 struct lprocfs_stats *stats = p->private;
2001 struct lprocfs_counter_header *hdr;
2002 struct lprocfs_counter ctr;
2003 int idx = *(loff_t *)v;
2009 do_gettimeofday(&now);
2010 rc = seq_printf(p, "%-25s %lu.%lu secs.usecs\n",
2011 "snapshot_time", now.tv_sec, now.tv_usec);
2016 hdr = &stats->ls_cnt_header[idx];
2017 lprocfs_stats_collect(stats, idx, &ctr);
2019 if (ctr.lc_count == 0)
2022 rc = seq_printf(p, "%-25s "LPD64" samples [%s]", hdr->lc_name,
2023 ctr.lc_count, hdr->lc_units);
2027 if ((hdr->lc_config & LPROCFS_CNTR_AVGMINMAX) && ctr.lc_count > 0) {
2028 rc = seq_printf(p, " "LPD64" "LPD64" "LPD64,
2029 ctr.lc_min, ctr.lc_max, ctr.lc_sum);
2032 if (hdr->lc_config & LPROCFS_CNTR_STDDEV)
2033 rc = seq_printf(p, " "LPD64, ctr.lc_sumsquare);
2037 rc = seq_printf(p, "\n");
2039 return (rc < 0) ? rc : 0;
2042 struct seq_operations lprocfs_stats_seq_sops = {
2043 .start = lprocfs_stats_seq_start,
2044 .stop = lprocfs_stats_seq_stop,
2045 .next = lprocfs_stats_seq_next,
2046 .show = lprocfs_stats_seq_show,
2049 static int lprocfs_stats_seq_open(struct inode *inode, struct file *file)
2051 struct seq_file *seq;
2054 #ifndef HAVE_ONLY_PROCFS_SEQ
2055 if (LPROCFS_ENTRY_CHECK(PDE(inode)))
2058 rc = seq_open(file, &lprocfs_stats_seq_sops);
2061 seq = file->private_data;
2062 seq->private = PDE_DATA(inode);
2066 struct file_operations lprocfs_stats_seq_fops = {
2067 .owner = THIS_MODULE,
2068 .open = lprocfs_stats_seq_open,
2070 .write = lprocfs_stats_seq_write,
2071 .llseek = seq_lseek,
2072 .release = lprocfs_seq_release,
2075 int lprocfs_register_stats(struct proc_dir_entry *root, const char *name,
2076 struct lprocfs_stats *stats)
2078 struct proc_dir_entry *entry;
2079 LASSERT(root != NULL);
2081 entry = proc_create_data(name, 0644, root,
2082 &lprocfs_stats_seq_fops, stats);
2087 EXPORT_SYMBOL(lprocfs_register_stats);
2089 void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
2090 unsigned conf, const char *name, const char *units)
2092 struct lprocfs_counter_header *header;
2093 struct lprocfs_counter *percpu_cntr;
2094 unsigned long flags = 0;
2096 unsigned int num_cpu;
2098 LASSERT(stats != NULL);
2100 header = &stats->ls_cnt_header[index];
2101 LASSERTF(header != NULL, "Failed to allocate stats header:[%d]%s/%s\n",
2102 index, name, units);
2104 header->lc_config = conf;
2105 header->lc_name = name;
2106 header->lc_units = units;
2108 num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
2109 for (i = 0; i < num_cpu; ++i) {
2110 if (stats->ls_percpu[i] == NULL)
2112 percpu_cntr = lprocfs_stats_counter_get(stats, i, index);
2113 percpu_cntr->lc_count = 0;
2114 percpu_cntr->lc_min = LC_MIN_INIT;
2115 percpu_cntr->lc_max = 0;
2116 percpu_cntr->lc_sumsquare = 0;
2117 percpu_cntr->lc_sum = 0;
2118 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
2119 percpu_cntr->lc_sum_irq = 0;
2121 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
2123 EXPORT_SYMBOL(lprocfs_counter_init);
2125 /* Note that we only init md counters for ops whose offset is less
2126 * than NUM_MD_STATS. This is explained in a comment in the definition
2127 * of struct md_ops. */
2128 #define LPROCFS_MD_OP_INIT(base, stats, op) \
2130 unsigned int _idx = base + MD_COUNTER_OFFSET(op); \
2132 if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS) { \
2133 LASSERT(_idx < stats->ls_num); \
2134 lprocfs_counter_init(stats, _idx, 0, #op, "reqs"); \
2138 void lprocfs_init_mps_stats(int num_private_stats, struct lprocfs_stats *stats)
2140 LPROCFS_MD_OP_INIT(num_private_stats, stats, getstatus);
2141 LPROCFS_MD_OP_INIT(num_private_stats, stats, null_inode);
2142 LPROCFS_MD_OP_INIT(num_private_stats, stats, find_cbdata);
2143 LPROCFS_MD_OP_INIT(num_private_stats, stats, close);
2144 LPROCFS_MD_OP_INIT(num_private_stats, stats, create);
2145 LPROCFS_MD_OP_INIT(num_private_stats, stats, done_writing);
2146 LPROCFS_MD_OP_INIT(num_private_stats, stats, enqueue);
2147 LPROCFS_MD_OP_INIT(num_private_stats, stats, getattr);
2148 LPROCFS_MD_OP_INIT(num_private_stats, stats, getattr_name);
2149 LPROCFS_MD_OP_INIT(num_private_stats, stats, intent_lock);
2150 LPROCFS_MD_OP_INIT(num_private_stats, stats, link);
2151 LPROCFS_MD_OP_INIT(num_private_stats, stats, rename);
2152 LPROCFS_MD_OP_INIT(num_private_stats, stats, setattr);
2153 LPROCFS_MD_OP_INIT(num_private_stats, stats, fsync);
2154 LPROCFS_MD_OP_INIT(num_private_stats, stats, read_page);
2155 LPROCFS_MD_OP_INIT(num_private_stats, stats, unlink);
2156 LPROCFS_MD_OP_INIT(num_private_stats, stats, setxattr);
2157 LPROCFS_MD_OP_INIT(num_private_stats, stats, getxattr);
2158 LPROCFS_MD_OP_INIT(num_private_stats, stats, init_ea_size);
2159 LPROCFS_MD_OP_INIT(num_private_stats, stats, get_lustre_md);
2160 LPROCFS_MD_OP_INIT(num_private_stats, stats, free_lustre_md);
2161 LPROCFS_MD_OP_INIT(num_private_stats, stats, update_lsm_md);
2162 LPROCFS_MD_OP_INIT(num_private_stats, stats, merge_attr);
2163 LPROCFS_MD_OP_INIT(num_private_stats, stats, set_open_replay_data);
2164 LPROCFS_MD_OP_INIT(num_private_stats, stats, clear_open_replay_data);
2165 LPROCFS_MD_OP_INIT(num_private_stats, stats, set_lock_data);
2166 LPROCFS_MD_OP_INIT(num_private_stats, stats, lock_match);
2167 LPROCFS_MD_OP_INIT(num_private_stats, stats, cancel_unused);
2168 LPROCFS_MD_OP_INIT(num_private_stats, stats, renew_capa);
2169 LPROCFS_MD_OP_INIT(num_private_stats, stats, unpack_capa);
2170 LPROCFS_MD_OP_INIT(num_private_stats, stats, get_remote_perm);
2171 LPROCFS_MD_OP_INIT(num_private_stats, stats, intent_getattr_async);
2172 LPROCFS_MD_OP_INIT(num_private_stats, stats, revalidate_lock);
2174 EXPORT_SYMBOL(lprocfs_init_mps_stats);
2176 int lprocfs_alloc_md_stats(struct obd_device *obd,
2177 unsigned int num_private_stats)
2179 struct lprocfs_stats *stats;
2180 unsigned int num_stats;
2183 CLASSERT(offsetof(struct md_ops, MD_STATS_FIRST_OP) == 0);
2184 CLASSERT(_MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) == 0);
2185 CLASSERT(_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) > 0);
2187 /* TODO Ensure that this function is only used where
2188 * appropriate by adding an assertion to the effect that
2189 * obd->obd_type->typ_md_ops is not NULL. We can't do this now
2190 * because mdt_procfs_init() uses this function to allocate
2191 * the stats backing /proc/fs/lustre/mdt/.../md_stats but the
2192 * mdt layer does not use the md_ops interface. This is
2193 * confusing and a waste of memory. See LU-2484.
2195 LASSERT(obd->obd_proc_entry != NULL);
2196 LASSERT(obd->obd_md_stats == NULL);
2197 LASSERT(obd->obd_md_cntr_base == 0);
2199 num_stats = NUM_MD_STATS + num_private_stats;
2200 stats = lprocfs_alloc_stats(num_stats, 0);
2204 lprocfs_init_mps_stats(num_private_stats, stats);
2206 for (i = num_private_stats; i < num_stats; i++) {
2207 if (stats->ls_cnt_header[i].lc_name == NULL) {
2208 CERROR("Missing md_stat initializer md_op "
2209 "operation at offset %d. Aborting.\n",
2210 i - num_private_stats);
2215 rc = lprocfs_register_stats(obd->obd_proc_entry, "md_stats", stats);
2217 lprocfs_free_stats(&stats);
2219 obd->obd_md_stats = stats;
2220 obd->obd_md_cntr_base = num_private_stats;
2225 EXPORT_SYMBOL(lprocfs_alloc_md_stats);
2227 void lprocfs_free_md_stats(struct obd_device *obd)
2229 struct lprocfs_stats *stats = obd->obd_md_stats;
2231 if (stats != NULL) {
2232 obd->obd_md_stats = NULL;
2233 obd->obd_md_cntr_base = 0;
2234 lprocfs_free_stats(&stats);
2237 EXPORT_SYMBOL(lprocfs_free_md_stats);
2239 void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
2241 lprocfs_counter_init(ldlm_stats,
2242 LDLM_ENQUEUE - LDLM_FIRST_OPC,
2243 0, "ldlm_enqueue", "reqs");
2244 lprocfs_counter_init(ldlm_stats,
2245 LDLM_CONVERT - LDLM_FIRST_OPC,
2246 0, "ldlm_convert", "reqs");
2247 lprocfs_counter_init(ldlm_stats,
2248 LDLM_CANCEL - LDLM_FIRST_OPC,
2249 0, "ldlm_cancel", "reqs");
2250 lprocfs_counter_init(ldlm_stats,
2251 LDLM_BL_CALLBACK - LDLM_FIRST_OPC,
2252 0, "ldlm_bl_callback", "reqs");
2253 lprocfs_counter_init(ldlm_stats,
2254 LDLM_CP_CALLBACK - LDLM_FIRST_OPC,
2255 0, "ldlm_cp_callback", "reqs");
2256 lprocfs_counter_init(ldlm_stats,
2257 LDLM_GL_CALLBACK - LDLM_FIRST_OPC,
2258 0, "ldlm_gl_callback", "reqs");
2260 EXPORT_SYMBOL(lprocfs_init_ldlm_stats);
2262 __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
2263 struct lprocfs_counter_header *header,
2264 enum lprocfs_stats_flags flags,
2265 enum lprocfs_fields_flags field)
2269 if (lc == NULL || header == NULL)
2273 case LPROCFS_FIELDS_FLAGS_CONFIG:
2274 ret = header->lc_config;
2276 case LPROCFS_FIELDS_FLAGS_SUM:
2278 if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
2279 ret += lc->lc_sum_irq;
2281 case LPROCFS_FIELDS_FLAGS_MIN:
2284 case LPROCFS_FIELDS_FLAGS_MAX:
2287 case LPROCFS_FIELDS_FLAGS_AVG:
2288 ret = (lc->lc_max - lc->lc_min) / 2;
2290 case LPROCFS_FIELDS_FLAGS_SUMSQUARE:
2291 ret = lc->lc_sumsquare;
2293 case LPROCFS_FIELDS_FLAGS_COUNT:
2301 EXPORT_SYMBOL(lprocfs_read_helper);
2303 int lprocfs_write_helper(const char *buffer, unsigned long count,
2306 return lprocfs_write_frac_helper(buffer, count, val, 1);
2308 EXPORT_SYMBOL(lprocfs_write_helper);
2310 int lprocfs_write_frac_helper(const char *buffer, unsigned long count,
2313 char kernbuf[20], *end, *pbuf;
2315 if (count > (sizeof(kernbuf) - 1))
2318 if (copy_from_user(kernbuf, buffer, count))
2321 kernbuf[count] = '\0';
2328 *val = (int)simple_strtoul(pbuf, &end, 10) * mult;
2332 if (end != NULL && *end == '.') {
2333 int temp_val, pow = 1;
2337 if (strlen(pbuf) > 5)
2338 pbuf[5] = '\0'; /*only allow 5bits fractional*/
2340 temp_val = (int)simple_strtoul(pbuf, &end, 10) * mult;
2343 for (i = 0; i < (end - pbuf); i++)
2346 *val += temp_val / pow;
2351 EXPORT_SYMBOL(lprocfs_write_frac_helper);
2353 int lprocfs_read_frac_helper(char *buffer, unsigned long count, long val,
2356 long decimal_val, frac_val;
2362 decimal_val = val / mult;
2363 prtn = snprintf(buffer, count, "%ld", decimal_val);
2364 frac_val = val % mult;
2366 if (prtn < (count - 4) && frac_val > 0) {
2368 int i, temp_mult = 1, frac_bits = 0;
2370 temp_frac = frac_val * 10;
2371 buffer[prtn++] = '.';
2372 while (frac_bits < 2 && (temp_frac / mult) < 1 ) {
2373 /* only reserved 2 bits fraction */
2374 buffer[prtn++] ='0';
2379 * Need to think these cases :
2380 * 1. #echo x.00 > /proc/xxx output result : x
2381 * 2. #echo x.0x > /proc/xxx output result : x.0x
2382 * 3. #echo x.x0 > /proc/xxx output result : x.x
2383 * 4. #echo x.xx > /proc/xxx output result : x.xx
2384 * Only reserved 2 bits fraction.
2386 for (i = 0; i < (5 - prtn); i++)
2389 frac_bits = min((int)count - prtn, 3 - frac_bits);
2390 prtn += snprintf(buffer + prtn, frac_bits, "%ld",
2391 frac_val * temp_mult / mult);
2394 while(buffer[prtn] < '1' || buffer[prtn] > '9') {
2396 if (buffer[prtn] == '.') {
2403 buffer[prtn++] ='\n';
2406 EXPORT_SYMBOL(lprocfs_read_frac_helper);
2408 int lprocfs_seq_read_frac_helper(struct seq_file *m, long val, int mult)
2410 long decimal_val, frac_val;
2412 decimal_val = val / mult;
2413 seq_printf(m, "%ld", decimal_val);
2414 frac_val = val % mult;
2421 /* Three cases: x0, xx, 0x */
2422 if ((frac_val % 10) != 0)
2423 seq_printf(m, ".%ld", frac_val);
2425 seq_printf(m, ".%ld", frac_val / 10);
2428 seq_printf(m, "\n");
2431 EXPORT_SYMBOL(lprocfs_seq_read_frac_helper);
2433 int lprocfs_write_u64_helper(const char *buffer, unsigned long count,__u64 *val)
2435 return lprocfs_write_frac_u64_helper(buffer, count, val, 1);
2437 EXPORT_SYMBOL(lprocfs_write_u64_helper);
2439 int lprocfs_write_frac_u64_helper(const char *buffer, unsigned long count,
2440 __u64 *val, int mult)
2442 char kernbuf[22], *end, *pbuf;
2443 __u64 whole, frac = 0, units;
2444 unsigned frac_d = 1;
2446 if (count > (sizeof(kernbuf) - 1))
2449 if (copy_from_user(kernbuf, buffer, count))
2452 kernbuf[count] = '\0';
2459 whole = simple_strtoull(pbuf, &end, 10);
2463 if (end != NULL && *end == '.') {
2467 /* need to limit frac_d to a __u32 */
2468 if (strlen(pbuf) > 10)
2471 frac = simple_strtoull(pbuf, &end, 10);
2472 /* count decimal places */
2473 for (i = 0; i < (end - pbuf); i++)
2492 /* Specified units override the multiplier */
2494 mult = mult < 0 ? -units : units;
2497 do_div(frac, frac_d);
2498 *val = whole * mult + frac;
2501 EXPORT_SYMBOL(lprocfs_write_frac_u64_helper);
2503 static char *lprocfs_strnstr(const char *s1, const char *s2, size_t len)
2512 if (!memcmp(s1, s2, l2))
2520 * Find the string \a name in the input \a buffer, and return a pointer to the
2521 * value immediately following \a name, reducing \a count appropriately.
2522 * If \a name is not found the original \a buffer is returned.
2524 char *lprocfs_find_named_value(const char *buffer, const char *name,
2528 size_t buflen = *count;
2530 /* there is no strnstr() in rhel5 and ubuntu kernels */
2531 val = lprocfs_strnstr(buffer, name, buflen);
2533 return (char *)buffer;
2535 val += strlen(name); /* skip prefix */
2536 while (val < buffer + buflen && isspace(*val)) /* skip separator */
2540 while (val < buffer + buflen && isalnum(*val)) {
2545 return val - *count;
2547 EXPORT_SYMBOL(lprocfs_find_named_value);
2549 int lprocfs_seq_create(struct proc_dir_entry *parent,
2552 const struct file_operations *seq_fops,
2555 struct proc_dir_entry *entry;
2558 /* Disallow secretly (un)writable entries. */
2559 LASSERT((seq_fops->write == NULL) == ((mode & 0222) == 0));
2561 entry = proc_create_data(name, mode, parent, seq_fops, data);
2568 EXPORT_SYMBOL(lprocfs_seq_create);
2570 int lprocfs_obd_seq_create(struct obd_device *dev,
2573 const struct file_operations *seq_fops,
2576 return (lprocfs_seq_create(dev->obd_proc_entry, name,
2577 mode, seq_fops, data));
2579 EXPORT_SYMBOL(lprocfs_obd_seq_create);
2581 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
2583 if (value >= OBD_HIST_MAX)
2584 value = OBD_HIST_MAX - 1;
2586 spin_lock(&oh->oh_lock);
2587 oh->oh_buckets[value]++;
2588 spin_unlock(&oh->oh_lock);
2590 EXPORT_SYMBOL(lprocfs_oh_tally);
2592 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
2594 unsigned int val = 0;
2596 if (likely(value != 0))
2597 val = min(fls(value - 1), OBD_HIST_MAX);
2599 lprocfs_oh_tally(oh, val);
2601 EXPORT_SYMBOL(lprocfs_oh_tally_log2);
2603 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
2605 unsigned long ret = 0;
2608 for (i = 0; i < OBD_HIST_MAX; i++)
2609 ret += oh->oh_buckets[i];
2612 EXPORT_SYMBOL(lprocfs_oh_sum);
2614 void lprocfs_oh_clear(struct obd_histogram *oh)
2616 spin_lock(&oh->oh_lock);
2617 memset(oh->oh_buckets, 0, sizeof(oh->oh_buckets));
2618 spin_unlock(&oh->oh_lock);
2620 EXPORT_SYMBOL(lprocfs_oh_clear);
2622 int lprocfs_obd_rd_max_pages_per_rpc(char *page, char **start, off_t off,
2623 int count, int *eof, void *data)
2625 struct obd_device *dev = data;
2626 struct client_obd *cli = &dev->u.cli;
2629 client_obd_list_lock(&cli->cl_loi_list_lock);
2630 rc = snprintf(page, count, "%d\n", cli->cl_max_pages_per_rpc);
2631 client_obd_list_unlock(&cli->cl_loi_list_lock);
2634 EXPORT_SYMBOL(lprocfs_obd_rd_max_pages_per_rpc);
2636 int lprocfs_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *data)
2638 struct obd_device *dev = data;
2639 struct client_obd *cli = &dev->u.cli;
2642 client_obd_list_lock(&cli->cl_loi_list_lock);
2643 rc = seq_printf(m, "%d\n", cli->cl_max_pages_per_rpc);
2644 client_obd_list_unlock(&cli->cl_loi_list_lock);
2647 EXPORT_SYMBOL(lprocfs_obd_max_pages_per_rpc_seq_show);
2649 int lprocfs_wr_root_squash(const char __user *buffer, unsigned long count,
2650 struct root_squash_info *squash, char *name)
2653 char kernbuf[64], *tmp, *errmsg;
2654 unsigned long uid, gid;
2657 if (count >= sizeof(kernbuf)) {
2658 errmsg = "string too long";
2659 GOTO(failed_noprint, rc = -EINVAL);
2661 if (copy_from_user(kernbuf, buffer, count)) {
2662 errmsg = "bad address";
2663 GOTO(failed_noprint, rc = -EFAULT);
2665 kernbuf[count] = '\0';
2667 /* look for uid gid separator */
2668 tmp = strchr(kernbuf, ':');
2670 errmsg = "needs uid:gid format";
2671 GOTO(failed, rc = -EINVAL);
2677 if (kstrtoul(kernbuf, 0, &uid) != 0) {
2679 GOTO(failed, rc = -EINVAL);
2683 if (kstrtoul(tmp, 0, &gid) != 0) {
2685 GOTO(failed, rc = -EINVAL);
2688 squash->rsi_uid = uid;
2689 squash->rsi_gid = gid;
2691 LCONSOLE_INFO("%s: root_squash is set to %u:%u\n",
2692 name, squash->rsi_uid, squash->rsi_gid);
2700 CWARN("%s: failed to set root_squash to \"%s\", %s, rc = %d\n",
2701 name, kernbuf, errmsg, rc);
2704 CWARN("%s: failed to set root_squash due to %s, rc = %d\n",
2708 EXPORT_SYMBOL(lprocfs_wr_root_squash);
2711 int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count,
2712 struct root_squash_info *squash, char *name)
2715 char *kernbuf = NULL;
2717 struct list_head tmp;
2721 errmsg = "string too long";
2722 GOTO(failed, rc = -EINVAL);
2725 OBD_ALLOC(kernbuf, count + 1);
2726 if (kernbuf == NULL) {
2727 errmsg = "no memory";
2728 GOTO(failed, rc = -ENOMEM);
2730 if (copy_from_user(kernbuf, buffer, count)) {
2731 errmsg = "bad address";
2732 GOTO(failed, rc = -EFAULT);
2734 kernbuf[count] = '\0';
2736 if (count > 0 && kernbuf[count - 1] == '\n')
2737 kernbuf[count - 1] = '\0';
2739 if (strcmp(kernbuf, "NONE") == 0 || strcmp(kernbuf, "clear") == 0) {
2740 /* empty string is special case */
2741 down_write(&squash->rsi_sem);
2742 if (!list_empty(&squash->rsi_nosquash_nids))
2743 cfs_free_nidlist(&squash->rsi_nosquash_nids);
2744 up_write(&squash->rsi_sem);
2745 LCONSOLE_INFO("%s: nosquash_nids is cleared\n", name);
2746 OBD_FREE(kernbuf, count + 1);
2750 INIT_LIST_HEAD(&tmp);
2751 if (cfs_parse_nidlist(kernbuf, count, &tmp) <= 0) {
2752 errmsg = "can't parse";
2753 GOTO(failed, rc = -EINVAL);
2755 LCONSOLE_INFO("%s: nosquash_nids set to %s\n",
2757 OBD_FREE(kernbuf, count + 1);
2760 down_write(&squash->rsi_sem);
2761 if (!list_empty(&squash->rsi_nosquash_nids))
2762 cfs_free_nidlist(&squash->rsi_nosquash_nids);
2763 list_splice(&tmp, &squash->rsi_nosquash_nids);
2764 up_write(&squash->rsi_sem);
2770 CWARN("%s: failed to set nosquash_nids to \"%s\", %s rc = %d\n",
2771 name, kernbuf, errmsg, rc);
2772 OBD_FREE(kernbuf, count + 1);
2774 CWARN("%s: failed to set nosquash_nids due to %s rc = %d\n",
2779 EXPORT_SYMBOL(lprocfs_wr_nosquash_nids);