4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/obdclass/lprocfs_status.c
38 * Author: Hariharan Thantry <thantry@users.sourceforge.net>
41 #define DEBUG_SUBSYSTEM S_CLASS
44 #include <liblustre.h>
47 #include <obd_class.h>
48 #include <lprocfs_status.h>
49 #include <lustre/lustre_idl.h>
53 static int lprocfs_no_percpu_stats = 0;
54 CFS_MODULE_PARM(lprocfs_no_percpu_stats, "i", int, 0644,
55 "Do not alloc percpu data for lprocfs stats");
57 #define MAX_STRING_SIZE 128
59 int lprocfs_single_release(struct inode *inode, struct file *file)
61 return single_release(inode, file);
63 EXPORT_SYMBOL(lprocfs_single_release);
65 int lprocfs_seq_release(struct inode *inode, struct file *file)
67 return seq_release(inode, file);
69 EXPORT_SYMBOL(lprocfs_seq_release);
71 struct proc_dir_entry *
72 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
73 #ifndef HAVE_ONLY_PROCFS_SEQ
74 read_proc_t *read_proc, write_proc_t *write_proc,
76 void *data, const struct file_operations *fops)
78 struct proc_dir_entry *proc;
81 if (root == NULL || name == NULL)
82 return ERR_PTR(-EINVAL);
85 #ifndef HAVE_ONLY_PROCFS_SEQ
91 LPROCFS_WRITE_ENTRY();
92 proc = create_proc_entry(name, mode, root);
94 CERROR("LprocFS: No memory to create /proc entry %s", name);
96 return ERR_PTR(-ENOMEM);
98 proc->read_proc = read_proc;
99 proc->write_proc = write_proc;
101 LPROCFS_WRITE_EXIT();
103 return ERR_PTR(-EINVAL);
110 proc = proc_create_data(name, mode, root, fops, data);
112 CERROR("LprocFS: No memory to create /proc entry %s",
114 return ERR_PTR(-ENOMEM);
119 EXPORT_SYMBOL(lprocfs_add_simple);
121 struct proc_dir_entry *lprocfs_add_symlink(const char *name,
122 struct proc_dir_entry *parent, const char *format, ...)
124 struct proc_dir_entry *entry;
128 if (parent == NULL || format == NULL)
131 OBD_ALLOC_WAIT(dest, MAX_STRING_SIZE + 1);
135 va_start(ap, format);
136 vsnprintf(dest, MAX_STRING_SIZE, format, ap);
139 entry = proc_symlink(name, parent, dest);
141 CERROR("LprocFS: Could not create symbolic link from %s to %s",
144 OBD_FREE(dest, MAX_STRING_SIZE + 1);
147 EXPORT_SYMBOL(lprocfs_add_symlink);
149 #ifdef HAVE_ONLY_PROCFS_SEQ
150 static const struct file_operations lprocfs_generic_fops = { };
154 lprocfs_fops_read(struct file *f, char __user *buf, size_t size, loff_t *ppos)
156 struct proc_dir_entry *dp = PDE(f->f_dentry->d_inode);
157 char *page, *start = NULL;
158 int rc = 0, eof = 1, count;
160 if (*ppos >= PAGE_CACHE_SIZE)
163 page = (char *)__get_free_page(GFP_KERNEL);
167 if (LPROCFS_ENTRY_CHECK(dp)) {
172 OBD_FAIL_TIMEOUT(OBD_FAIL_LPROC_REMOVE, 10);
174 rc = dp->read_proc(page, &start, *ppos, PAGE_CACHE_SIZE,
179 /* for lustre proc read, the read count must be less than PAGE_SIZE */
188 start = page + *ppos;
189 } else if (start < page) {
193 count = (rc < size) ? rc : size;
194 if (copy_to_user(buf, start, count)) {
201 free_page((unsigned long)page);
206 lprocfs_fops_write(struct file *f, const char __user *buf, size_t size,
209 struct proc_dir_entry *dp = PDE(f->f_dentry->d_inode);
212 if (LPROCFS_ENTRY_CHECK(dp))
215 rc = dp->write_proc(f, buf, size, dp->data);
219 static struct file_operations lprocfs_generic_fops = {
220 .owner = THIS_MODULE,
221 .read = lprocfs_fops_read,
222 .write = lprocfs_fops_write,
225 /* for b=10866, global variable */
226 DECLARE_RWSEM(_lprocfs_lock);
227 EXPORT_SYMBOL(_lprocfs_lock);
229 static struct proc_dir_entry *__lprocfs_srch(struct proc_dir_entry *head,
232 struct proc_dir_entry *temp;
238 while (temp != NULL) {
239 if (strcmp(temp->name, name) == 0)
246 struct proc_dir_entry *lprocfs_srch(struct proc_dir_entry *head,
249 struct proc_dir_entry *temp;
251 LPROCFS_SRCH_ENTRY();
252 temp = __lprocfs_srch(head, name);
256 EXPORT_SYMBOL(lprocfs_srch);
258 static int __lprocfs_add_vars(struct proc_dir_entry *root,
259 struct lprocfs_vars *list,
264 if (root == NULL || list == NULL)
267 while (list->name != NULL) {
268 struct proc_dir_entry *cur_root, *proc;
269 char *pathcopy, *cur, *next, pathbuf[64];
270 int pathsize = strlen(list->name) + 1;
275 /* need copy of path for strsep */
276 if (strlen(list->name) > sizeof(pathbuf) - 1) {
277 OBD_ALLOC(pathcopy, pathsize);
278 if (pathcopy == NULL)
279 GOTO(out, rc = -ENOMEM);
285 strcpy(pathcopy, list->name);
287 while (cur_root != NULL && (cur = strsep(&next, "/"))) {
288 if (*cur =='\0') /* skip double/trailing "/" */
291 proc = __lprocfs_srch(cur_root, cur);
292 CDEBUG(D_OTHER, "cur_root=%s, cur=%s, next=%s, (%s)\n",
293 cur_root->name, cur, next,
294 (proc ? "exists" : "new"));
296 cur_root = (proc ? proc :
297 proc_mkdir(cur, cur_root));
298 } else if (proc == NULL) {
300 if (list->proc_mode != 0000) {
301 mode = list->proc_mode;
305 if (list->write_fptr)
308 proc = create_proc_entry(cur, mode, cur_root);
312 if (pathcopy != pathbuf)
313 OBD_FREE(pathcopy, pathsize);
315 if (cur_root == NULL || proc == NULL) {
316 CERROR("LprocFS: No memory to create /proc entry %s",
318 GOTO(out, rc = -ENOMEM);
322 proc->proc_fops = list->fops;
324 proc->proc_fops = &lprocfs_generic_fops;
325 proc->read_proc = list->read_fptr;
326 proc->write_proc = list->write_fptr;
327 proc->data = (list->data ? list->data : data);
334 int lprocfs_add_vars(struct proc_dir_entry *root, struct lprocfs_vars *list,
339 LPROCFS_WRITE_ENTRY();
340 rc = __lprocfs_add_vars(root, list, data);
341 LPROCFS_WRITE_EXIT();
345 EXPORT_SYMBOL(lprocfs_add_vars);
351 * \param root [in] The parent proc entry on which new entry will be added.
352 * \param list [in] Array of proc entries to be added.
353 * \param data [in] The argument to be passed when entries read/write routines
354 * are called through /proc file.
356 * \retval 0 on success
360 lprocfs_seq_add_vars(struct proc_dir_entry *root, struct lprocfs_seq_vars *list,
363 if (root == NULL || list == NULL)
366 while (list->name != NULL) {
367 struct proc_dir_entry *proc;
370 if (list->proc_mode != 0000) {
371 mode = list->proc_mode;
372 } else if (list->fops) {
373 if (list->fops->read)
375 if (list->fops->write)
378 proc = proc_create_data(list->name, mode, root,
379 list->fops ?: &lprocfs_generic_fops,
387 EXPORT_SYMBOL(lprocfs_seq_add_vars);
389 #ifndef HAVE_ONLY_PROCFS_SEQ
390 void lprocfs_remove_nolock(struct proc_dir_entry **proot)
392 struct proc_dir_entry *root = *proot;
393 struct proc_dir_entry *temp = root;
394 struct proc_dir_entry *rm_entry;
395 struct proc_dir_entry *parent;
398 if (root == NULL || IS_ERR(root))
401 parent = root->parent;
402 LASSERT(parent != NULL);
405 while (temp->subdir != NULL)
411 /* Memory corruption once caused this to fail, and
412 without this LASSERT we would loop here forever. */
413 LASSERTF(strlen(rm_entry->name) == rm_entry->namelen,
414 "0x%p %s/%s len %d\n", rm_entry, temp->name,
415 rm_entry->name, (int)strlen(rm_entry->name));
417 remove_proc_entry(rm_entry->name, temp);
424 void lprocfs_remove(struct proc_dir_entry **rooth)
426 #ifndef HAVE_ONLY_PROCFS_SEQ
427 LPROCFS_WRITE_ENTRY(); /* search vs remove race */
428 lprocfs_remove_nolock(rooth);
429 LPROCFS_WRITE_EXIT();
435 EXPORT_SYMBOL(lprocfs_remove);
437 void lprocfs_remove_proc_entry(const char *name, struct proc_dir_entry *parent)
439 LASSERT(parent != NULL);
440 remove_proc_entry(name, parent);
442 EXPORT_SYMBOL(lprocfs_remove_proc_entry);
444 #ifndef HAVE_ONLY_PROCFS_SEQ
445 void lprocfs_try_remove_proc_entry(const char *name,
446 struct proc_dir_entry *parent)
448 struct proc_dir_entry *t = NULL;
449 struct proc_dir_entry **p;
452 LASSERT(parent != NULL);
455 LPROCFS_WRITE_ENTRY();
457 /* lookup target name */
458 for (p = &parent->subdir; *p; p = &(*p)->next) {
459 if ((*p)->namelen != len)
461 if (memcmp(name, (*p)->name, len))
468 /* verify it's empty: do not count "num_refs" */
469 for (p = &t->subdir; *p; p = &(*p)->next) {
470 if ((*p)->namelen != strlen("num_refs")) {
474 if (memcmp("num_refs", (*p)->name,
475 strlen("num_refs"))) {
483 lprocfs_remove_nolock(&t);
485 LPROCFS_WRITE_EXIT();
489 EXPORT_SYMBOL(lprocfs_try_remove_proc_entry);
491 struct proc_dir_entry *lprocfs_register(const char *name,
492 struct proc_dir_entry *parent,
493 struct lprocfs_vars *list, void *data)
495 struct proc_dir_entry *entry;
498 LPROCFS_WRITE_ENTRY();
499 entry = __lprocfs_srch(parent, name);
501 CERROR("entry '%s' already registered\n", name);
502 GOTO(out, entry = ERR_PTR(-EALREADY));
505 entry = proc_mkdir(name, parent);
507 GOTO(out, entry = ERR_PTR(-ENOMEM));
510 rc = __lprocfs_add_vars(entry, list, data);
512 lprocfs_remove_nolock(&entry);
513 GOTO(out, entry = ERR_PTR(rc));
517 LPROCFS_WRITE_EXIT();
520 EXPORT_SYMBOL(lprocfs_register);
523 struct proc_dir_entry *
524 lprocfs_seq_register(const char *name, struct proc_dir_entry *parent,
525 struct lprocfs_seq_vars *list, void *data)
527 struct proc_dir_entry *newchild;
529 newchild = proc_mkdir(name, parent);
530 if (newchild != NULL && list != NULL) {
531 int rc = lprocfs_seq_add_vars(newchild, list, data);
533 lprocfs_remove(&newchild);
539 EXPORT_SYMBOL(lprocfs_seq_register);
541 /* Generic callbacks */
542 int lprocfs_uint_seq_show(struct seq_file *m, void *data)
544 return seq_printf(m, "%u\n", *(unsigned int *)data);
546 EXPORT_SYMBOL(lprocfs_uint_seq_show);
548 int lprocfs_wr_uint(struct file *file, const char *buffer,
549 unsigned long count, void *data)
552 char dummy[MAX_STRING_SIZE + 1], *end;
555 dummy[MAX_STRING_SIZE] = '\0';
556 if (copy_from_user(dummy, buffer, MAX_STRING_SIZE))
559 tmp = simple_strtoul(dummy, &end, 0);
563 *p = (unsigned int)tmp;
566 EXPORT_SYMBOL(lprocfs_wr_uint);
568 ssize_t lprocfs_uint_seq_write(struct file *file, const char *buffer,
569 size_t count, loff_t *off)
571 int *data = ((struct seq_file *)file->private_data)->private;
574 rc = lprocfs_write_helper(buffer, count, &val);
578 return lprocfs_wr_uint(file, buffer, count, data);
580 EXPORT_SYMBOL(lprocfs_uint_seq_write);
582 int lprocfs_u64_seq_show(struct seq_file *m, void *data)
584 LASSERT(data != NULL);
585 return seq_printf(m, LPU64"\n", *(__u64 *)data);
587 EXPORT_SYMBOL(lprocfs_u64_seq_show);
589 int lprocfs_atomic_seq_show(struct seq_file *m, void *data)
591 atomic_t *atom = data;
592 LASSERT(atom != NULL);
593 return seq_printf(m, "%d\n", atomic_read(atom));
595 EXPORT_SYMBOL(lprocfs_atomic_seq_show);
598 lprocfs_atomic_seq_write(struct file *file, const char *buffer,
599 size_t count, loff_t *off)
601 atomic_t *atm = ((struct seq_file *)file->private_data)->private;
605 rc = lprocfs_write_helper(buffer, count, &val);
612 atomic_set(atm, val);
615 EXPORT_SYMBOL(lprocfs_atomic_seq_write);
617 int lprocfs_uuid_seq_show(struct seq_file *m, void *data)
619 struct obd_device *obd = data;
621 LASSERT(obd != NULL);
622 return seq_printf(m, "%s\n", obd->obd_uuid.uuid);
624 EXPORT_SYMBOL(lprocfs_uuid_seq_show);
626 int lprocfs_name_seq_show(struct seq_file *m, void *data)
628 struct obd_device *dev = data;
630 LASSERT(dev != NULL);
631 return seq_printf(m, "%s\n", dev->obd_name);
633 EXPORT_SYMBOL(lprocfs_name_seq_show);
635 int lprocfs_blksize_seq_show(struct seq_file *m, void *data)
637 struct obd_device *obd = data;
638 struct obd_statfs osfs;
639 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
640 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
643 rc = seq_printf(m, "%u\n", osfs.os_bsize);
646 EXPORT_SYMBOL(lprocfs_blksize_seq_show);
648 int lprocfs_kbytestotal_seq_show(struct seq_file *m, void *data)
650 struct obd_device *obd = data;
651 struct obd_statfs osfs;
652 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
653 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
656 __u32 blk_size = osfs.os_bsize >> 10;
657 __u64 result = osfs.os_blocks;
659 while (blk_size >>= 1)
662 rc = seq_printf(m, LPU64"\n", result);
666 EXPORT_SYMBOL(lprocfs_kbytestotal_seq_show);
668 int lprocfs_kbytesfree_seq_show(struct seq_file *m, void *data)
670 struct obd_device *obd = data;
671 struct obd_statfs osfs;
672 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
673 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
676 __u32 blk_size = osfs.os_bsize >> 10;
677 __u64 result = osfs.os_bfree;
679 while (blk_size >>= 1)
682 rc = seq_printf(m, LPU64"\n", result);
686 EXPORT_SYMBOL(lprocfs_kbytesfree_seq_show);
688 int lprocfs_kbytesavail_seq_show(struct seq_file *m, void *data)
690 struct obd_device *obd = data;
691 struct obd_statfs osfs;
692 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
693 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
696 __u32 blk_size = osfs.os_bsize >> 10;
697 __u64 result = osfs.os_bavail;
699 while (blk_size >>= 1)
702 rc = seq_printf(m, LPU64"\n", result);
706 EXPORT_SYMBOL(lprocfs_kbytesavail_seq_show);
708 int lprocfs_filestotal_seq_show(struct seq_file *m, void *data)
710 struct obd_device *obd = data;
711 struct obd_statfs osfs;
712 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
713 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
716 rc = seq_printf(m, LPU64"\n", osfs.os_files);
719 EXPORT_SYMBOL(lprocfs_filestotal_seq_show);
721 int lprocfs_filesfree_seq_show(struct seq_file *m, void *data)
723 struct obd_device *obd = data;
724 struct obd_statfs osfs;
725 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
726 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
729 rc = seq_printf(m, LPU64"\n", osfs.os_ffree);
732 EXPORT_SYMBOL(lprocfs_filesfree_seq_show);
734 int lprocfs_server_uuid_seq_show(struct seq_file *m, void *data)
736 struct obd_device *obd = data;
737 struct obd_import *imp;
738 char *imp_state_name = NULL;
741 LASSERT(obd != NULL);
742 LPROCFS_CLIMP_CHECK(obd);
743 imp = obd->u.cli.cl_import;
744 imp_state_name = ptlrpc_import_state_name(imp->imp_state);
745 rc = seq_printf(m, "%s\t%s%s\n", obd2cli_tgt(obd), imp_state_name,
746 imp->imp_deactive ? "\tDEACTIVATED" : "");
748 LPROCFS_CLIMP_EXIT(obd);
751 EXPORT_SYMBOL(lprocfs_server_uuid_seq_show);
753 int lprocfs_conn_uuid_seq_show(struct seq_file *m, void *data)
755 struct obd_device *obd = data;
756 struct ptlrpc_connection *conn;
759 LASSERT(obd != NULL);
761 LPROCFS_CLIMP_CHECK(obd);
762 conn = obd->u.cli.cl_import->imp_connection;
763 if (conn && obd->u.cli.cl_import)
764 rc = seq_printf(m, "%s\n", conn->c_remote_uuid.uuid);
766 rc = seq_printf(m, "%s\n", "<none>");
768 LPROCFS_CLIMP_EXIT(obd);
771 EXPORT_SYMBOL(lprocfs_conn_uuid_seq_show);
773 /** add up per-cpu counters */
774 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
775 struct lprocfs_counter *cnt)
777 unsigned int num_entry;
778 struct lprocfs_counter *percpu_cntr;
780 unsigned long flags = 0;
782 memset(cnt, 0, sizeof(*cnt));
785 /* set count to 1 to avoid divide-by-zero errs in callers */
790 cnt->lc_min = LC_MIN_INIT;
792 num_entry = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
794 for (i = 0; i < num_entry; i++) {
795 if (stats->ls_percpu[i] == NULL)
797 percpu_cntr = lprocfs_stats_counter_get(stats, i, idx);
799 cnt->lc_count += percpu_cntr->lc_count;
800 cnt->lc_sum += percpu_cntr->lc_sum;
801 if (percpu_cntr->lc_min < cnt->lc_min)
802 cnt->lc_min = percpu_cntr->lc_min;
803 if (percpu_cntr->lc_max > cnt->lc_max)
804 cnt->lc_max = percpu_cntr->lc_max;
805 cnt->lc_sumsquare += percpu_cntr->lc_sumsquare;
808 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
810 EXPORT_SYMBOL(lprocfs_stats_collect);
813 * Append a space separated list of current set flags to str.
815 #define flag2seqstr(flag) \
817 if (imp->imp_##flag) \
818 seq_printf(m, "%s" #flag, first ? "" : ", "); \
820 static int obd_import_flags2seqstr(struct obd_import *imp, struct seq_file *m)
824 if (imp->imp_obd->obd_no_recov) {
825 seq_printf(m, "no_recov");
829 flag2seqstr(invalid);
830 flag2seqstr(deactive);
831 flag2seqstr(replayable);
832 flag2seqstr(pingable);
837 static const char *obd_connect_names[] = {
851 "join_file(obsolete)",
855 "remote_client_by_force",
864 "mds_mds_connection",
867 "alt_checksum_algorithm",
895 static void obd_connect_seq_flags2str(struct seq_file *m, __u64 flags, char *sep)
901 for (i = 0; obd_connect_names[i] != NULL; i++, mask <<= 1) {
903 seq_printf(m, "%s%s",
904 first ? "" : sep, obd_connect_names[i]);
908 if (flags & ~(mask - 1))
909 seq_printf(m, "%sunknown flags "LPX64,
910 first ? "" : sep, flags & ~(mask - 1));
913 int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep)
918 for (i = 0; obd_connect_names[i] != NULL; i++, mask <<= 1) {
920 ret += snprintf(page + ret, count - ret, "%s%s",
921 ret ? sep : "", obd_connect_names[i]);
923 if (flags & ~(mask - 1))
924 ret += snprintf(page + ret, count - ret,
925 "%sunknown flags "LPX64,
926 ret ? sep : "", flags & ~(mask - 1));
929 EXPORT_SYMBOL(obd_connect_flags2str);
931 static void obd_connect_data_seqprint(struct seq_file *m,
932 struct obd_connect_data *ocd)
936 LASSERT(ocd != NULL);
937 flags = ocd->ocd_connect_flags;
939 seq_printf(m, " connect_data:\n"
942 ocd->ocd_connect_flags,
944 if (flags & OBD_CONNECT_VERSION)
945 seq_printf(m, " target_version: %u.%u.%u.%u\n",
946 OBD_OCD_VERSION_MAJOR(ocd->ocd_version),
947 OBD_OCD_VERSION_MINOR(ocd->ocd_version),
948 OBD_OCD_VERSION_PATCH(ocd->ocd_version),
949 OBD_OCD_VERSION_FIX(ocd->ocd_version));
950 if (flags & OBD_CONNECT_MDS)
951 seq_printf(m, " mdt_index: %d\n", ocd->ocd_group);
952 if (flags & OBD_CONNECT_GRANT)
953 seq_printf(m, " initial_grant: %d\n", ocd->ocd_grant);
954 if (flags & OBD_CONNECT_INDEX)
955 seq_printf(m, " target_index: %u\n", ocd->ocd_index);
956 if (flags & OBD_CONNECT_BRW_SIZE)
957 seq_printf(m, " max_brw_size: %d\n", ocd->ocd_brw_size);
958 if (flags & OBD_CONNECT_IBITS)
959 seq_printf(m, " ibits_known: "LPX64"\n",
960 ocd->ocd_ibits_known);
961 if (flags & OBD_CONNECT_GRANT_PARAM)
962 seq_printf(m, " grant_block_size: %d\n"
963 " grant_inode_size: %d\n"
964 " grant_extent_overhead: %d\n",
967 ocd->ocd_grant_extent);
968 if (flags & OBD_CONNECT_TRANSNO)
969 seq_printf(m, " first_transno: "LPX64"\n",
971 if (flags & OBD_CONNECT_CKSUM)
972 seq_printf(m, " cksum_types: %#x\n",
973 ocd->ocd_cksum_types);
974 if (flags & OBD_CONNECT_MAX_EASIZE)
975 seq_printf(m, " max_easize: %d\n", ocd->ocd_max_easize);
976 if (flags & OBD_CONNECT_MAXBYTES)
977 seq_printf(m, " max_object_bytes: "LPU64"\n",
981 int lprocfs_import_seq_show(struct seq_file *m, void *data)
983 struct lprocfs_counter ret;
984 struct lprocfs_counter_header *header;
985 struct obd_device *obd = (struct obd_device *)data;
986 struct obd_import *imp;
987 struct obd_import_conn *conn;
988 struct obd_connect_data *ocd;
993 LASSERT(obd != NULL);
994 LPROCFS_CLIMP_CHECK(obd);
995 imp = obd->u.cli.cl_import;
996 ocd = &imp->imp_connect_data;
998 seq_printf(m, "import:\n"
1002 " connect_flags: [",
1005 ptlrpc_import_state_name(imp->imp_state));
1006 obd_connect_seq_flags2str(m, imp->imp_connect_data.ocd_connect_flags,
1008 seq_printf(m, "]\n");
1009 obd_connect_data_seqprint(m, ocd);
1010 seq_printf(m, " import_flags: [");
1011 obd_import_flags2seqstr(imp, m);
1015 " failover_nids: [");
1016 spin_lock(&imp->imp_lock);
1018 list_for_each_entry(conn, &imp->imp_conn_list, oic_item) {
1019 seq_printf(m, "%s%s", j ? ", " : "",
1020 libcfs_nid2str(conn->oic_conn->c_peer.nid));
1024 " current_connection: %s\n"
1025 " connection_attempts: %u\n"
1027 " in-progress_invalidations: %u\n",
1028 imp->imp_connection == NULL ? "<none>" :
1029 libcfs_nid2str(imp->imp_connection->c_peer.nid),
1031 imp->imp_generation,
1032 atomic_read(&imp->imp_inval_count));
1033 spin_unlock(&imp->imp_lock);
1035 if (obd->obd_svc_stats == NULL)
1038 header = &obd->obd_svc_stats->ls_cnt_header[PTLRPC_REQWAIT_CNTR];
1039 lprocfs_stats_collect(obd->obd_svc_stats, PTLRPC_REQWAIT_CNTR, &ret);
1040 if (ret.lc_count != 0) {
1041 /* first argument to do_div MUST be __u64 */
1042 __u64 sum = ret.lc_sum;
1043 do_div(sum, ret.lc_count);
1047 seq_printf(m, " rpcs:\n"
1049 " unregistering: %u\n"
1051 " avg_waittime: "LPU64" %s\n",
1052 atomic_read(&imp->imp_inflight),
1053 atomic_read(&imp->imp_unregistering),
1054 atomic_read(&imp->imp_timeouts),
1055 ret.lc_sum, header->lc_units);
1058 for(j = 0; j < IMP_AT_MAX_PORTALS; j++) {
1059 if (imp->imp_at.iat_portal[j] == 0)
1061 k = max_t(unsigned int, k,
1062 at_get(&imp->imp_at.iat_service_estimate[j]));
1064 seq_printf(m, " service_estimates:\n"
1065 " services: %u sec\n"
1066 " network: %u sec\n",
1068 at_get(&imp->imp_at.iat_net_latency));
1070 seq_printf(m, " transactions:\n"
1071 " last_replay: "LPU64"\n"
1072 " peer_committed: "LPU64"\n"
1073 " last_checked: "LPU64"\n",
1074 imp->imp_last_replay_transno,
1075 imp->imp_peer_committed_transno,
1076 imp->imp_last_transno_checked);
1078 /* avg data rates */
1079 for (rw = 0; rw <= 1; rw++) {
1080 lprocfs_stats_collect(obd->obd_svc_stats,
1081 PTLRPC_LAST_CNTR + BRW_READ_BYTES + rw,
1083 if (ret.lc_sum > 0 && ret.lc_count > 0) {
1084 /* first argument to do_div MUST be __u64 */
1085 __u64 sum = ret.lc_sum;
1086 do_div(sum, ret.lc_count);
1088 seq_printf(m, " %s_data_averages:\n"
1089 " bytes_per_rpc: "LPU64"\n",
1090 rw ? "write" : "read",
1093 k = (int)ret.lc_sum;
1094 j = opcode_offset(OST_READ + rw) + EXTRA_MAX_OPCODES;
1095 header = &obd->obd_svc_stats->ls_cnt_header[j];
1096 lprocfs_stats_collect(obd->obd_svc_stats, j, &ret);
1097 if (ret.lc_sum > 0 && ret.lc_count != 0) {
1098 /* first argument to do_div MUST be __u64 */
1099 __u64 sum = ret.lc_sum;
1100 do_div(sum, ret.lc_count);
1102 seq_printf(m, " %s_per_rpc: "LPU64"\n",
1103 header->lc_units, ret.lc_sum);
1104 j = (int)ret.lc_sum;
1106 seq_printf(m, " MB_per_sec: %u.%.02u\n",
1107 k / j, (100 * k / j) % 100);
1112 LPROCFS_CLIMP_EXIT(obd);
1115 EXPORT_SYMBOL(lprocfs_import_seq_show);
1117 int lprocfs_state_seq_show(struct seq_file *m, void *data)
1119 struct obd_device *obd = (struct obd_device *)data;
1120 struct obd_import *imp;
1123 LASSERT(obd != NULL);
1124 LPROCFS_CLIMP_CHECK(obd);
1125 imp = obd->u.cli.cl_import;
1127 seq_printf(m, "current_state: %s\n",
1128 ptlrpc_import_state_name(imp->imp_state));
1129 seq_printf(m, "state_history:\n");
1130 k = imp->imp_state_hist_idx;
1131 for (j = 0; j < IMP_STATE_HIST_LEN; j++) {
1132 struct import_state_hist *ish =
1133 &imp->imp_state_hist[(k + j) % IMP_STATE_HIST_LEN];
1134 if (ish->ish_state == 0)
1136 seq_printf(m, " - ["CFS_TIME_T", %s]\n",
1138 ptlrpc_import_state_name(ish->ish_state));
1141 LPROCFS_CLIMP_EXIT(obd);
1144 EXPORT_SYMBOL(lprocfs_state_seq_show);
1146 int lprocfs_seq_at_hist_helper(struct seq_file *m, struct adaptive_timeout *at)
1149 for (i = 0; i < AT_BINS; i++)
1150 seq_printf(m, "%3u ", at->at_hist[i]);
1151 seq_printf(m, "\n");
1154 EXPORT_SYMBOL(lprocfs_seq_at_hist_helper);
1156 /* See also ptlrpc_lprocfs_timeouts_show_seq */
1157 int lprocfs_timeouts_seq_show(struct seq_file *m, void *data)
1159 struct obd_device *obd = (struct obd_device *)data;
1160 struct obd_import *imp;
1161 unsigned int cur, worst;
1166 LASSERT(obd != NULL);
1167 LPROCFS_CLIMP_CHECK(obd);
1168 imp = obd->u.cli.cl_import;
1170 now = cfs_time_current_sec();
1172 /* Some network health info for kicks */
1173 s2dhms(&ts, now - imp->imp_last_reply_time);
1174 seq_printf(m, "%-10s : %ld, "DHMS_FMT" ago\n",
1175 "last reply", imp->imp_last_reply_time, DHMS_VARS(&ts));
1177 cur = at_get(&imp->imp_at.iat_net_latency);
1178 worst = imp->imp_at.iat_net_latency.at_worst_ever;
1179 worstt = imp->imp_at.iat_net_latency.at_worst_time;
1180 s2dhms(&ts, now - worstt);
1181 seq_printf(m, "%-10s : cur %3u worst %3u (at %ld, "DHMS_FMT" ago) ",
1182 "network", cur, worst, worstt, DHMS_VARS(&ts));
1183 lprocfs_seq_at_hist_helper(m, &imp->imp_at.iat_net_latency);
1185 for(i = 0; i < IMP_AT_MAX_PORTALS; i++) {
1186 if (imp->imp_at.iat_portal[i] == 0)
1188 cur = at_get(&imp->imp_at.iat_service_estimate[i]);
1189 worst = imp->imp_at.iat_service_estimate[i].at_worst_ever;
1190 worstt = imp->imp_at.iat_service_estimate[i].at_worst_time;
1191 s2dhms(&ts, now - worstt);
1192 seq_printf(m, "portal %-2d : cur %3u worst %3u (at %ld, "
1193 DHMS_FMT" ago) ", imp->imp_at.iat_portal[i],
1194 cur, worst, worstt, DHMS_VARS(&ts));
1195 lprocfs_seq_at_hist_helper(m, &imp->imp_at.iat_service_estimate[i]);
1198 LPROCFS_CLIMP_EXIT(obd);
1201 EXPORT_SYMBOL(lprocfs_timeouts_seq_show);
1203 int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data)
1205 struct obd_device *obd = data;
1208 LPROCFS_CLIMP_CHECK(obd);
1209 flags = obd->u.cli.cl_import->imp_connect_data.ocd_connect_flags;
1210 seq_printf(m, "flags="LPX64"\n", flags);
1211 obd_connect_seq_flags2str(m, flags, "\n");
1212 seq_printf(m, "\n");
1213 LPROCFS_CLIMP_EXIT(obd);
1216 EXPORT_SYMBOL(lprocfs_connect_flags_seq_show);
1218 #ifndef HAVE_ONLY_PROCFS_SEQ
1220 int lprocfs_rd_uint(char *page, char **start, off_t off,
1221 int count, int *eof, void *data)
1223 unsigned int *temp = data;
1224 return snprintf(page, count, "%u\n", *temp);
1226 EXPORT_SYMBOL(lprocfs_rd_uint);
1228 int lprocfs_rd_u64(char *page, char **start, off_t off,
1229 int count, int *eof, void *data)
1231 LASSERT(data != NULL);
1233 return snprintf(page, count, LPU64"\n", *(__u64 *)data);
1235 EXPORT_SYMBOL(lprocfs_rd_u64);
1237 int lprocfs_rd_atomic(char *page, char **start, off_t off,
1238 int count, int *eof, void *data)
1240 atomic_t *atom = data;
1241 LASSERT(atom != NULL);
1243 return snprintf(page, count, "%d\n", atomic_read(atom));
1245 EXPORT_SYMBOL(lprocfs_rd_atomic);
1247 int lprocfs_wr_atomic(struct file *file, const char *buffer,
1248 unsigned long count, void *data)
1250 atomic_t *atm = data;
1254 rc = lprocfs_write_helper(buffer, count, &val);
1261 atomic_set(atm, val);
1264 EXPORT_SYMBOL(lprocfs_wr_atomic);
1266 int lprocfs_rd_uuid(char *page, char **start, off_t off, int count,
1267 int *eof, void *data)
1269 struct obd_device *obd = data;
1271 LASSERT(obd != NULL);
1273 return snprintf(page, count, "%s\n", obd->obd_uuid.uuid);
1275 EXPORT_SYMBOL(lprocfs_rd_uuid);
1277 int lprocfs_rd_name(char *page, char **start, off_t off, int count,
1278 int *eof, void *data)
1280 struct obd_device *dev = data;
1282 LASSERT(dev != NULL);
1284 return snprintf(page, count, "%s\n", dev->obd_name);
1286 EXPORT_SYMBOL(lprocfs_rd_name);
1288 int lprocfs_rd_blksize(char *page, char **start, off_t off, int count,
1289 int *eof, void *data)
1291 struct obd_device *obd = data;
1292 struct obd_statfs osfs;
1293 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
1294 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1295 OBD_STATFS_NODELAY);
1298 rc = snprintf(page, count, "%u\n", osfs.os_bsize);
1302 EXPORT_SYMBOL(lprocfs_rd_blksize);
1304 int lprocfs_rd_kbytestotal(char *page, char **start, off_t off, int count,
1305 int *eof, void *data)
1307 struct obd_device *obd = data;
1308 struct obd_statfs osfs;
1309 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
1310 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1311 OBD_STATFS_NODELAY);
1313 __u32 blk_size = osfs.os_bsize >> 10;
1314 __u64 result = osfs.os_blocks;
1316 while (blk_size >>= 1)
1320 rc = snprintf(page, count, LPU64"\n", result);
1324 EXPORT_SYMBOL(lprocfs_rd_kbytestotal);
1326 int lprocfs_rd_kbytesfree(char *page, char **start, off_t off, int count,
1327 int *eof, void *data)
1329 struct obd_device *obd = data;
1330 struct obd_statfs osfs;
1331 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
1332 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1333 OBD_STATFS_NODELAY);
1335 __u32 blk_size = osfs.os_bsize >> 10;
1336 __u64 result = osfs.os_bfree;
1338 while (blk_size >>= 1)
1342 rc = snprintf(page, count, LPU64"\n", result);
1346 EXPORT_SYMBOL(lprocfs_rd_kbytesfree);
1348 int lprocfs_rd_kbytesavail(char *page, char **start, off_t off, int count,
1349 int *eof, void *data)
1351 struct obd_device *obd = data;
1352 struct obd_statfs osfs;
1353 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
1354 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1355 OBD_STATFS_NODELAY);
1357 __u32 blk_size = osfs.os_bsize >> 10;
1358 __u64 result = osfs.os_bavail;
1360 while (blk_size >>= 1)
1364 rc = snprintf(page, count, LPU64"\n", result);
1368 EXPORT_SYMBOL(lprocfs_rd_kbytesavail);
1370 int lprocfs_rd_filestotal(char *page, char **start, off_t off, int count,
1371 int *eof, void *data)
1373 struct obd_device *obd = data;
1374 struct obd_statfs osfs;
1375 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
1376 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1377 OBD_STATFS_NODELAY);
1380 rc = snprintf(page, count, LPU64"\n", osfs.os_files);
1385 EXPORT_SYMBOL(lprocfs_rd_filestotal);
1387 int lprocfs_rd_filesfree(char *page, char **start, off_t off, int count,
1388 int *eof, void *data)
1390 struct obd_device *obd = data;
1391 struct obd_statfs osfs;
1392 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
1393 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1394 OBD_STATFS_NODELAY);
1397 rc = snprintf(page, count, LPU64"\n", osfs.os_ffree);
1401 EXPORT_SYMBOL(lprocfs_rd_filesfree);
1403 int lprocfs_rd_server_uuid(char *page, char **start, off_t off, int count,
1404 int *eof, void *data)
1406 struct obd_device *obd = data;
1407 struct obd_import *imp;
1408 char *imp_state_name = NULL;
1411 LASSERT(obd != NULL);
1412 LPROCFS_CLIMP_CHECK(obd);
1413 imp = obd->u.cli.cl_import;
1414 imp_state_name = ptlrpc_import_state_name(imp->imp_state);
1416 rc = snprintf(page, count, "%s\t%s%s\n",
1417 obd2cli_tgt(obd), imp_state_name,
1418 imp->imp_deactive ? "\tDEACTIVATED" : "");
1420 LPROCFS_CLIMP_EXIT(obd);
1423 EXPORT_SYMBOL(lprocfs_rd_server_uuid);
1425 int lprocfs_rd_conn_uuid(char *page, char **start, off_t off, int count,
1426 int *eof, void *data)
1428 struct obd_device *obd = data;
1429 struct ptlrpc_connection *conn;
1432 LASSERT(obd != NULL);
1434 LPROCFS_CLIMP_CHECK(obd);
1435 conn = obd->u.cli.cl_import->imp_connection;
1437 if (conn && obd->u.cli.cl_import) {
1438 rc = snprintf(page, count, "%s\n",
1439 conn->c_remote_uuid.uuid);
1441 rc = snprintf(page, count, "%s\n", "<none>");
1444 LPROCFS_CLIMP_EXIT(obd);
1447 EXPORT_SYMBOL(lprocfs_rd_conn_uuid);
1450 * Append a space separated list of current set flags to str.
1452 #define flag2str(flag) \
1453 if (imp->imp_##flag && max - len > 0) \
1454 len += snprintf(str + len, max - len, "%s" #flag, len ? ", " : "");
1455 static int obd_import_flags2str(struct obd_import *imp, char *str, int max)
1459 if (imp->imp_obd->obd_no_recov)
1460 len += snprintf(str, max - len, "no_recov");
1464 flag2str(replayable);
1470 int lprocfs_rd_import(char *page, char **start, off_t off, int count,
1471 int *eof, void *data)
1473 struct lprocfs_counter ret;
1474 struct lprocfs_counter_header *header;
1475 struct obd_device *obd = (struct obd_device *)data;
1476 struct obd_import *imp;
1477 struct obd_import_conn *conn;
1483 LASSERT(obd != NULL);
1484 LPROCFS_CLIMP_CHECK(obd);
1485 imp = obd->u.cli.cl_import;
1488 i = snprintf(page, count,
1494 " connect_flags: [",
1497 ptlrpc_import_state_name(imp->imp_state),
1498 imp->imp_connect_data.ocd_instance);
1499 i += obd_connect_flags2str(page + i, count - i,
1500 imp->imp_connect_data.ocd_connect_flags,
1502 i += snprintf(page + i, count - i,
1504 " import_flags: [");
1505 i += obd_import_flags2str(imp, page + i, count - i);
1507 i += snprintf(page + i, count - i,
1510 " failover_nids: [");
1511 spin_lock(&imp->imp_lock);
1513 list_for_each_entry(conn, &imp->imp_conn_list, oic_item) {
1514 i += snprintf(page + i, count - i, "%s%s", j ? ", " : "",
1515 libcfs_nid2str(conn->oic_conn->c_peer.nid));
1518 i += snprintf(page + i, count - i,
1520 " current_connection: %s\n"
1521 " connection_attempts: %u\n"
1523 " in-progress_invalidations: %u\n",
1524 imp->imp_connection == NULL ? "<none>" :
1525 libcfs_nid2str(imp->imp_connection->c_peer.nid),
1527 imp->imp_generation,
1528 atomic_read(&imp->imp_inval_count));
1529 spin_unlock(&imp->imp_lock);
1531 if (obd->obd_svc_stats == NULL)
1534 header = &obd->obd_svc_stats->ls_cnt_header[PTLRPC_REQWAIT_CNTR];
1535 lprocfs_stats_collect(obd->obd_svc_stats, PTLRPC_REQWAIT_CNTR, &ret);
1536 if (ret.lc_count != 0) {
1537 /* first argument to do_div MUST be __u64 */
1538 __u64 sum = ret.lc_sum;
1539 do_div(sum, ret.lc_count);
1543 i += snprintf(page + i, count - i,
1546 " unregistering: %u\n"
1548 " avg_waittime: "LPU64" %s\n",
1549 atomic_read(&imp->imp_inflight),
1550 atomic_read(&imp->imp_unregistering),
1551 atomic_read(&imp->imp_timeouts),
1552 ret.lc_sum, header->lc_units);
1555 for(j = 0; j < IMP_AT_MAX_PORTALS; j++) {
1556 if (imp->imp_at.iat_portal[j] == 0)
1558 k = max_t(unsigned int, k,
1559 at_get(&imp->imp_at.iat_service_estimate[j]));
1561 i += snprintf(page + i, count - i,
1562 " service_estimates:\n"
1563 " services: %u sec\n"
1564 " network: %u sec\n",
1566 at_get(&imp->imp_at.iat_net_latency));
1568 i += snprintf(page + i, count - i,
1570 " last_replay: "LPU64"\n"
1571 " peer_committed: "LPU64"\n"
1572 " last_checked: "LPU64"\n",
1573 imp->imp_last_replay_transno,
1574 imp->imp_peer_committed_transno,
1575 imp->imp_last_transno_checked);
1577 /* avg data rates */
1578 for (rw = 0; rw <= 1; rw++) {
1579 lprocfs_stats_collect(obd->obd_svc_stats,
1580 PTLRPC_LAST_CNTR + BRW_READ_BYTES + rw,
1582 if (ret.lc_sum > 0 && ret.lc_count > 0) {
1583 /* first argument to do_div MUST be __u64 */
1584 __u64 sum = ret.lc_sum;
1585 do_div(sum, ret.lc_count);
1587 i += snprintf(page + i, count - i,
1588 " %s_data_averages:\n"
1589 " bytes_per_rpc: "LPU64"\n",
1590 rw ? "write" : "read",
1593 k = (int)ret.lc_sum;
1594 j = opcode_offset(OST_READ + rw) + EXTRA_MAX_OPCODES;
1595 header = &obd->obd_svc_stats->ls_cnt_header[j];
1596 lprocfs_stats_collect(obd->obd_svc_stats, j, &ret);
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_per_rpc: "LPU64"\n",
1604 header->lc_units, ret.lc_sum);
1605 j = (int)ret.lc_sum;
1607 i += snprintf(page + i, count - i,
1608 " MB_per_sec: %u.%.02u\n",
1609 k / j, (100 * k / j) % 100);
1614 LPROCFS_CLIMP_EXIT(obd);
1617 EXPORT_SYMBOL(lprocfs_rd_import);
1619 int lprocfs_rd_state(char *page, char **start, off_t off, int count,
1620 int *eof, void *data)
1622 struct obd_device *obd = (struct obd_device *)data;
1623 struct obd_import *imp;
1626 LASSERT(obd != NULL);
1627 LPROCFS_CLIMP_CHECK(obd);
1628 imp = obd->u.cli.cl_import;
1631 i = snprintf(page, count, "current_state: %s\n",
1632 ptlrpc_import_state_name(imp->imp_state));
1633 i += snprintf(page + i, count - i,
1634 "state_history:\n");
1635 k = imp->imp_state_hist_idx;
1636 for (j = 0; j < IMP_STATE_HIST_LEN; j++) {
1637 struct import_state_hist *ish =
1638 &imp->imp_state_hist[(k + j) % IMP_STATE_HIST_LEN];
1639 if (ish->ish_state == 0)
1641 i += snprintf(page + i, count - i, " - ["CFS_TIME_T", %s]\n",
1643 ptlrpc_import_state_name(ish->ish_state));
1646 LPROCFS_CLIMP_EXIT(obd);
1649 EXPORT_SYMBOL(lprocfs_rd_state);
1651 int lprocfs_at_hist_helper(char *page, int count, int rc,
1652 struct adaptive_timeout *at)
1655 for (i = 0; i < AT_BINS; i++)
1656 rc += snprintf(page + rc, count - rc, "%3u ", at->at_hist[i]);
1657 rc += snprintf(page + rc, count - rc, "\n");
1660 EXPORT_SYMBOL(lprocfs_at_hist_helper);
1662 /* See also ptlrpc_lprocfs_rd_timeouts */
1663 int lprocfs_rd_timeouts(char *page, char **start, off_t off, int count,
1664 int *eof, void *data)
1666 struct obd_device *obd = (struct obd_device *)data;
1667 struct obd_import *imp;
1668 unsigned int cur, worst;
1673 LASSERT(obd != NULL);
1674 LPROCFS_CLIMP_CHECK(obd);
1675 imp = obd->u.cli.cl_import;
1678 now = cfs_time_current_sec();
1680 /* Some network health info for kicks */
1681 s2dhms(&ts, now - imp->imp_last_reply_time);
1682 rc += snprintf(page + rc, count - rc,
1683 "%-10s : %ld, "DHMS_FMT" ago\n",
1684 "last reply", imp->imp_last_reply_time, DHMS_VARS(&ts));
1686 cur = at_get(&imp->imp_at.iat_net_latency);
1687 worst = imp->imp_at.iat_net_latency.at_worst_ever;
1688 worstt = imp->imp_at.iat_net_latency.at_worst_time;
1689 s2dhms(&ts, now - worstt);
1690 rc += snprintf(page + rc, count - rc,
1691 "%-10s : cur %3u worst %3u (at %ld, "DHMS_FMT" ago) ",
1692 "network", cur, worst, worstt, DHMS_VARS(&ts));
1693 rc = lprocfs_at_hist_helper(page, count, rc,
1694 &imp->imp_at.iat_net_latency);
1696 for(i = 0; i < IMP_AT_MAX_PORTALS; i++) {
1697 if (imp->imp_at.iat_portal[i] == 0)
1699 cur = at_get(&imp->imp_at.iat_service_estimate[i]);
1700 worst = imp->imp_at.iat_service_estimate[i].at_worst_ever;
1701 worstt = imp->imp_at.iat_service_estimate[i].at_worst_time;
1702 s2dhms(&ts, now - worstt);
1703 rc += snprintf(page + rc, count - rc,
1704 "portal %-2d : cur %3u worst %3u (at %ld, "
1705 DHMS_FMT" ago) ", imp->imp_at.iat_portal[i],
1706 cur, worst, worstt, DHMS_VARS(&ts));
1707 rc = lprocfs_at_hist_helper(page, count, rc,
1708 &imp->imp_at.iat_service_estimate[i]);
1711 LPROCFS_CLIMP_EXIT(obd);
1714 EXPORT_SYMBOL(lprocfs_rd_timeouts);
1716 int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
1717 int count, int *eof, void *data)
1719 struct obd_device *obd = data;
1723 LPROCFS_CLIMP_CHECK(obd);
1724 flags = obd->u.cli.cl_import->imp_connect_data.ocd_connect_flags;
1725 ret = snprintf(page, count, "flags="LPX64"\n", flags);
1726 ret += obd_connect_flags2str(page + ret, count - ret, flags, "\n");
1727 ret += snprintf(page + ret, count - ret, "\n");
1728 LPROCFS_CLIMP_EXIT(obd);
1731 EXPORT_SYMBOL(lprocfs_rd_connect_flags);
1733 int lprocfs_rd_numrefs(char *page, char **start, off_t off, int count,
1734 int *eof, void *data)
1736 struct obd_type *class = (struct obd_type*) data;
1738 LASSERT(class != NULL);
1740 return snprintf(page, count, "%d\n", class->typ_refcnt);
1742 EXPORT_SYMBOL(lprocfs_rd_numrefs);
1744 int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list)
1748 LASSERT(obd != NULL);
1749 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1750 LASSERT(obd->obd_type->typ_procroot != NULL);
1752 obd->obd_proc_entry = lprocfs_register(obd->obd_name,
1753 obd->obd_type->typ_procroot,
1755 if (IS_ERR(obd->obd_proc_entry)) {
1756 rc = PTR_ERR(obd->obd_proc_entry);
1757 CERROR("error %d setting up lprocfs for %s\n",rc,obd->obd_name);
1758 obd->obd_proc_entry = NULL;
1762 EXPORT_SYMBOL(lprocfs_obd_setup);
1766 lprocfs_seq_obd_setup(struct obd_device *obd)
1770 LASSERT(obd != NULL);
1771 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1772 LASSERT(obd->obd_type->typ_procroot != NULL);
1774 obd->obd_proc_entry = lprocfs_seq_register(obd->obd_name,
1775 obd->obd_type->typ_procroot,
1776 obd->obd_vars, obd);
1777 if (IS_ERR(obd->obd_proc_entry)) {
1778 rc = PTR_ERR(obd->obd_proc_entry);
1779 CERROR("error %d setting up lprocfs for %s\n",rc,obd->obd_name);
1780 obd->obd_proc_entry = NULL;
1784 EXPORT_SYMBOL(lprocfs_seq_obd_setup);
1786 int lprocfs_obd_cleanup(struct obd_device *obd)
1790 if (obd->obd_proc_exports_entry) {
1791 /* Should be no exports left */
1792 lprocfs_remove(&obd->obd_proc_exports_entry);
1793 obd->obd_proc_exports_entry = NULL;
1795 if (obd->obd_proc_entry) {
1796 lprocfs_remove(&obd->obd_proc_entry);
1797 obd->obd_proc_entry = NULL;
1801 EXPORT_SYMBOL(lprocfs_obd_cleanup);
1803 int lprocfs_stats_alloc_one(struct lprocfs_stats *stats, unsigned int cpuid)
1805 struct lprocfs_counter *cntr;
1806 unsigned int percpusize;
1808 unsigned long flags = 0;
1811 LASSERT(stats->ls_percpu[cpuid] == NULL);
1812 LASSERT((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0);
1814 percpusize = lprocfs_stats_counter_size(stats);
1815 LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[cpuid], percpusize);
1816 if (stats->ls_percpu[cpuid] != NULL) {
1818 if (unlikely(stats->ls_biggest_alloc_num <= cpuid)) {
1819 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
1820 spin_lock_irqsave(&stats->ls_lock, flags);
1822 spin_lock(&stats->ls_lock);
1823 if (stats->ls_biggest_alloc_num <= cpuid)
1824 stats->ls_biggest_alloc_num = cpuid + 1;
1825 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) {
1826 spin_unlock_irqrestore(&stats->ls_lock, flags);
1828 spin_unlock(&stats->ls_lock);
1831 /* initialize the ls_percpu[cpuid] non-zero counter */
1832 for (i = 0; i < stats->ls_num; ++i) {
1833 cntr = lprocfs_stats_counter_get(stats, cpuid, i);
1834 cntr->lc_min = LC_MIN_INIT;
1839 EXPORT_SYMBOL(lprocfs_stats_alloc_one);
1841 struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num,
1842 enum lprocfs_stats_flags flags)
1844 struct lprocfs_stats *stats;
1845 unsigned int num_entry;
1846 unsigned int percpusize = 0;
1852 if (lprocfs_no_percpu_stats != 0)
1853 flags |= LPROCFS_STATS_FLAG_NOPERCPU;
1855 if (flags & LPROCFS_STATS_FLAG_NOPERCPU)
1858 num_entry = num_possible_cpus();
1860 /* alloc percpu pointers for all possible cpu slots */
1861 LIBCFS_ALLOC(stats, offsetof(typeof(*stats), ls_percpu[num_entry]));
1865 stats->ls_num = num;
1866 stats->ls_flags = flags;
1867 spin_lock_init(&stats->ls_lock);
1869 /* alloc num of counter headers */
1870 LIBCFS_ALLOC(stats->ls_cnt_header,
1871 stats->ls_num * sizeof(struct lprocfs_counter_header));
1872 if (stats->ls_cnt_header == NULL)
1875 if ((flags & LPROCFS_STATS_FLAG_NOPERCPU) != 0) {
1876 /* contains only one set counters */
1877 percpusize = lprocfs_stats_counter_size(stats);
1878 LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[0], percpusize);
1879 if (stats->ls_percpu[0] == NULL)
1881 stats->ls_biggest_alloc_num = 1;
1882 } else if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0) {
1883 /* alloc all percpu data, currently only obd_memory use this */
1884 for (i = 0; i < num_entry; ++i)
1885 if (lprocfs_stats_alloc_one(stats, i) < 0)
1892 lprocfs_free_stats(&stats);
1895 EXPORT_SYMBOL(lprocfs_alloc_stats);
1897 void lprocfs_free_stats(struct lprocfs_stats **statsh)
1899 struct lprocfs_stats *stats = *statsh;
1900 unsigned int num_entry;
1901 unsigned int percpusize;
1904 if (stats == NULL || stats->ls_num == 0)
1908 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU)
1911 num_entry = num_possible_cpus();
1913 percpusize = lprocfs_stats_counter_size(stats);
1914 for (i = 0; i < num_entry; i++)
1915 if (stats->ls_percpu[i] != NULL)
1916 LIBCFS_FREE(stats->ls_percpu[i], percpusize);
1917 if (stats->ls_cnt_header != NULL)
1918 LIBCFS_FREE(stats->ls_cnt_header, stats->ls_num *
1919 sizeof(struct lprocfs_counter_header));
1920 LIBCFS_FREE(stats, offsetof(typeof(*stats), ls_percpu[num_entry]));
1922 EXPORT_SYMBOL(lprocfs_free_stats);
1924 void lprocfs_clear_stats(struct lprocfs_stats *stats)
1926 struct lprocfs_counter *percpu_cntr;
1929 unsigned int num_entry;
1930 unsigned long flags = 0;
1932 num_entry = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1934 for (i = 0; i < num_entry; i++) {
1935 if (stats->ls_percpu[i] == NULL)
1937 for (j = 0; j < stats->ls_num; j++) {
1938 percpu_cntr = lprocfs_stats_counter_get(stats, i, j);
1939 percpu_cntr->lc_count = 0;
1940 percpu_cntr->lc_min = LC_MIN_INIT;
1941 percpu_cntr->lc_max = 0;
1942 percpu_cntr->lc_sumsquare = 0;
1943 percpu_cntr->lc_sum = 0;
1944 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
1945 percpu_cntr->lc_sum_irq = 0;
1949 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1951 EXPORT_SYMBOL(lprocfs_clear_stats);
1953 static ssize_t lprocfs_stats_seq_write(struct file *file, const char *buf,
1954 size_t len, loff_t *off)
1956 struct seq_file *seq = file->private_data;
1957 struct lprocfs_stats *stats = seq->private;
1959 lprocfs_clear_stats(stats);
1964 static void *lprocfs_stats_seq_start(struct seq_file *p, loff_t *pos)
1966 struct lprocfs_stats *stats = p->private;
1968 return (*pos < stats->ls_num) ? pos : NULL;
1971 static void lprocfs_stats_seq_stop(struct seq_file *p, void *v)
1975 static void *lprocfs_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
1979 return lprocfs_stats_seq_start(p, pos);
1982 /* seq file export of one lprocfs counter */
1983 static int lprocfs_stats_seq_show(struct seq_file *p, void *v)
1985 struct lprocfs_stats *stats = p->private;
1986 struct lprocfs_counter_header *hdr;
1987 struct lprocfs_counter ctr;
1988 int idx = *(loff_t *)v;
1994 do_gettimeofday(&now);
1995 rc = seq_printf(p, "%-25s %lu.%lu secs.usecs\n",
1996 "snapshot_time", now.tv_sec, now.tv_usec);
2001 hdr = &stats->ls_cnt_header[idx];
2002 lprocfs_stats_collect(stats, idx, &ctr);
2004 if (ctr.lc_count == 0)
2007 rc = seq_printf(p, "%-25s "LPD64" samples [%s]", hdr->lc_name,
2008 ctr.lc_count, hdr->lc_units);
2012 if ((hdr->lc_config & LPROCFS_CNTR_AVGMINMAX) && ctr.lc_count > 0) {
2013 rc = seq_printf(p, " "LPD64" "LPD64" "LPD64,
2014 ctr.lc_min, ctr.lc_max, ctr.lc_sum);
2017 if (hdr->lc_config & LPROCFS_CNTR_STDDEV)
2018 rc = seq_printf(p, " "LPD64, ctr.lc_sumsquare);
2022 rc = seq_printf(p, "\n");
2024 return (rc < 0) ? rc : 0;
2027 struct seq_operations lprocfs_stats_seq_sops = {
2028 .start = lprocfs_stats_seq_start,
2029 .stop = lprocfs_stats_seq_stop,
2030 .next = lprocfs_stats_seq_next,
2031 .show = lprocfs_stats_seq_show,
2034 static int lprocfs_stats_seq_open(struct inode *inode, struct file *file)
2036 struct seq_file *seq;
2039 #ifndef HAVE_ONLY_PROCFS_SEQ
2040 if (LPROCFS_ENTRY_CHECK(PDE(inode)))
2043 rc = seq_open(file, &lprocfs_stats_seq_sops);
2046 seq = file->private_data;
2047 seq->private = PDE_DATA(inode);
2051 struct file_operations lprocfs_stats_seq_fops = {
2052 .owner = THIS_MODULE,
2053 .open = lprocfs_stats_seq_open,
2055 .write = lprocfs_stats_seq_write,
2056 .llseek = seq_lseek,
2057 .release = lprocfs_seq_release,
2060 int lprocfs_register_stats(struct proc_dir_entry *root, const char *name,
2061 struct lprocfs_stats *stats)
2063 struct proc_dir_entry *entry;
2064 LASSERT(root != NULL);
2066 entry = proc_create_data(name, 0644, root,
2067 &lprocfs_stats_seq_fops, stats);
2072 EXPORT_SYMBOL(lprocfs_register_stats);
2074 void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
2075 unsigned conf, const char *name, const char *units)
2077 struct lprocfs_counter_header *header;
2078 struct lprocfs_counter *percpu_cntr;
2079 unsigned long flags = 0;
2081 unsigned int num_cpu;
2083 LASSERT(stats != NULL);
2085 header = &stats->ls_cnt_header[index];
2086 LASSERTF(header != NULL, "Failed to allocate stats header:[%d]%s/%s\n",
2087 index, name, units);
2089 header->lc_config = conf;
2090 header->lc_name = name;
2091 header->lc_units = units;
2093 num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
2094 for (i = 0; i < num_cpu; ++i) {
2095 if (stats->ls_percpu[i] == NULL)
2097 percpu_cntr = lprocfs_stats_counter_get(stats, i, index);
2098 percpu_cntr->lc_count = 0;
2099 percpu_cntr->lc_min = LC_MIN_INIT;
2100 percpu_cntr->lc_max = 0;
2101 percpu_cntr->lc_sumsquare = 0;
2102 percpu_cntr->lc_sum = 0;
2103 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
2104 percpu_cntr->lc_sum_irq = 0;
2106 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
2108 EXPORT_SYMBOL(lprocfs_counter_init);
2110 /* Note that we only init md counters for ops whose offset is less
2111 * than NUM_MD_STATS. This is explained in a comment in the definition
2112 * of struct md_ops. */
2113 #define LPROCFS_MD_OP_INIT(base, stats, op) \
2115 unsigned int _idx = base + MD_COUNTER_OFFSET(op); \
2117 if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS) { \
2118 LASSERT(_idx < stats->ls_num); \
2119 lprocfs_counter_init(stats, _idx, 0, #op, "reqs"); \
2123 void lprocfs_init_mps_stats(int num_private_stats, struct lprocfs_stats *stats)
2125 LPROCFS_MD_OP_INIT(num_private_stats, stats, getstatus);
2126 LPROCFS_MD_OP_INIT(num_private_stats, stats, null_inode);
2127 LPROCFS_MD_OP_INIT(num_private_stats, stats, find_cbdata);
2128 LPROCFS_MD_OP_INIT(num_private_stats, stats, close);
2129 LPROCFS_MD_OP_INIT(num_private_stats, stats, create);
2130 LPROCFS_MD_OP_INIT(num_private_stats, stats, done_writing);
2131 LPROCFS_MD_OP_INIT(num_private_stats, stats, enqueue);
2132 LPROCFS_MD_OP_INIT(num_private_stats, stats, getattr);
2133 LPROCFS_MD_OP_INIT(num_private_stats, stats, getattr_name);
2134 LPROCFS_MD_OP_INIT(num_private_stats, stats, intent_lock);
2135 LPROCFS_MD_OP_INIT(num_private_stats, stats, link);
2136 LPROCFS_MD_OP_INIT(num_private_stats, stats, rename);
2137 LPROCFS_MD_OP_INIT(num_private_stats, stats, is_subdir);
2138 LPROCFS_MD_OP_INIT(num_private_stats, stats, setattr);
2139 LPROCFS_MD_OP_INIT(num_private_stats, stats, fsync);
2140 LPROCFS_MD_OP_INIT(num_private_stats, stats, readpage);
2141 LPROCFS_MD_OP_INIT(num_private_stats, stats, read_entry);
2142 LPROCFS_MD_OP_INIT(num_private_stats, stats, unlink);
2143 LPROCFS_MD_OP_INIT(num_private_stats, stats, setxattr);
2144 LPROCFS_MD_OP_INIT(num_private_stats, stats, getxattr);
2145 LPROCFS_MD_OP_INIT(num_private_stats, stats, init_ea_size);
2146 LPROCFS_MD_OP_INIT(num_private_stats, stats, get_lustre_md);
2147 LPROCFS_MD_OP_INIT(num_private_stats, stats, free_lustre_md);
2148 LPROCFS_MD_OP_INIT(num_private_stats, stats, update_lsm_md);
2149 LPROCFS_MD_OP_INIT(num_private_stats, stats, merge_attr);
2150 LPROCFS_MD_OP_INIT(num_private_stats, stats, set_open_replay_data);
2151 LPROCFS_MD_OP_INIT(num_private_stats, stats, clear_open_replay_data);
2152 LPROCFS_MD_OP_INIT(num_private_stats, stats, set_lock_data);
2153 LPROCFS_MD_OP_INIT(num_private_stats, stats, lock_match);
2154 LPROCFS_MD_OP_INIT(num_private_stats, stats, cancel_unused);
2155 LPROCFS_MD_OP_INIT(num_private_stats, stats, renew_capa);
2156 LPROCFS_MD_OP_INIT(num_private_stats, stats, unpack_capa);
2157 LPROCFS_MD_OP_INIT(num_private_stats, stats, get_remote_perm);
2158 LPROCFS_MD_OP_INIT(num_private_stats, stats, intent_getattr_async);
2159 LPROCFS_MD_OP_INIT(num_private_stats, stats, revalidate_lock);
2161 EXPORT_SYMBOL(lprocfs_init_mps_stats);
2163 int lprocfs_alloc_md_stats(struct obd_device *obd,
2164 unsigned int num_private_stats)
2166 struct lprocfs_stats *stats;
2167 unsigned int num_stats;
2170 CLASSERT(offsetof(struct md_ops, MD_STATS_FIRST_OP) == 0);
2171 CLASSERT(_MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) == 0);
2172 CLASSERT(_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) > 0);
2174 /* TODO Ensure that this function is only used where
2175 * appropriate by adding an assertion to the effect that
2176 * obd->obd_type->typ_md_ops is not NULL. We can't do this now
2177 * because mdt_procfs_init() uses this function to allocate
2178 * the stats backing /proc/fs/lustre/mdt/.../md_stats but the
2179 * mdt layer does not use the md_ops interface. This is
2180 * confusing and a waste of memory. See LU-2484.
2182 LASSERT(obd->obd_proc_entry != NULL);
2183 LASSERT(obd->obd_md_stats == NULL);
2184 LASSERT(obd->obd_md_cntr_base == 0);
2186 num_stats = NUM_MD_STATS + num_private_stats;
2187 stats = lprocfs_alloc_stats(num_stats, 0);
2191 lprocfs_init_mps_stats(num_private_stats, stats);
2193 for (i = num_private_stats; i < num_stats; i++) {
2194 if (stats->ls_cnt_header[i].lc_name == NULL) {
2195 CERROR("Missing md_stat initializer md_op "
2196 "operation at offset %d. Aborting.\n",
2197 i - num_private_stats);
2202 rc = lprocfs_register_stats(obd->obd_proc_entry, "md_stats", stats);
2204 lprocfs_free_stats(&stats);
2206 obd->obd_md_stats = stats;
2207 obd->obd_md_cntr_base = num_private_stats;
2212 EXPORT_SYMBOL(lprocfs_alloc_md_stats);
2214 void lprocfs_free_md_stats(struct obd_device *obd)
2216 struct lprocfs_stats *stats = obd->obd_md_stats;
2218 if (stats != NULL) {
2219 obd->obd_md_stats = NULL;
2220 obd->obd_md_cntr_base = 0;
2221 lprocfs_free_stats(&stats);
2224 EXPORT_SYMBOL(lprocfs_free_md_stats);
2226 void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
2228 lprocfs_counter_init(ldlm_stats,
2229 LDLM_ENQUEUE - LDLM_FIRST_OPC,
2230 0, "ldlm_enqueue", "reqs");
2231 lprocfs_counter_init(ldlm_stats,
2232 LDLM_CONVERT - LDLM_FIRST_OPC,
2233 0, "ldlm_convert", "reqs");
2234 lprocfs_counter_init(ldlm_stats,
2235 LDLM_CANCEL - LDLM_FIRST_OPC,
2236 0, "ldlm_cancel", "reqs");
2237 lprocfs_counter_init(ldlm_stats,
2238 LDLM_BL_CALLBACK - LDLM_FIRST_OPC,
2239 0, "ldlm_bl_callback", "reqs");
2240 lprocfs_counter_init(ldlm_stats,
2241 LDLM_CP_CALLBACK - LDLM_FIRST_OPC,
2242 0, "ldlm_cp_callback", "reqs");
2243 lprocfs_counter_init(ldlm_stats,
2244 LDLM_GL_CALLBACK - LDLM_FIRST_OPC,
2245 0, "ldlm_gl_callback", "reqs");
2247 EXPORT_SYMBOL(lprocfs_init_ldlm_stats);
2249 __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
2250 struct lprocfs_counter_header *header,
2251 enum lprocfs_stats_flags flags,
2252 enum lprocfs_fields_flags field)
2256 if (lc == NULL || header == NULL)
2260 case LPROCFS_FIELDS_FLAGS_CONFIG:
2261 ret = header->lc_config;
2263 case LPROCFS_FIELDS_FLAGS_SUM:
2265 if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
2266 ret += lc->lc_sum_irq;
2268 case LPROCFS_FIELDS_FLAGS_MIN:
2271 case LPROCFS_FIELDS_FLAGS_MAX:
2274 case LPROCFS_FIELDS_FLAGS_AVG:
2275 ret = (lc->lc_max - lc->lc_min) / 2;
2277 case LPROCFS_FIELDS_FLAGS_SUMSQUARE:
2278 ret = lc->lc_sumsquare;
2280 case LPROCFS_FIELDS_FLAGS_COUNT:
2288 EXPORT_SYMBOL(lprocfs_read_helper);
2290 int lprocfs_write_helper(const char *buffer, unsigned long count,
2293 return lprocfs_write_frac_helper(buffer, count, val, 1);
2295 EXPORT_SYMBOL(lprocfs_write_helper);
2297 int lprocfs_write_frac_helper(const char *buffer, unsigned long count,
2300 char kernbuf[20], *end, *pbuf;
2302 if (count > (sizeof(kernbuf) - 1))
2305 if (copy_from_user(kernbuf, buffer, count))
2308 kernbuf[count] = '\0';
2315 *val = (int)simple_strtoul(pbuf, &end, 10) * mult;
2319 if (end != NULL && *end == '.') {
2320 int temp_val, pow = 1;
2324 if (strlen(pbuf) > 5)
2325 pbuf[5] = '\0'; /*only allow 5bits fractional*/
2327 temp_val = (int)simple_strtoul(pbuf, &end, 10) * mult;
2330 for (i = 0; i < (end - pbuf); i++)
2333 *val += temp_val / pow;
2338 EXPORT_SYMBOL(lprocfs_write_frac_helper);
2340 int lprocfs_read_frac_helper(char *buffer, unsigned long count, long val,
2343 long decimal_val, frac_val;
2349 decimal_val = val / mult;
2350 prtn = snprintf(buffer, count, "%ld", decimal_val);
2351 frac_val = val % mult;
2353 if (prtn < (count - 4) && frac_val > 0) {
2355 int i, temp_mult = 1, frac_bits = 0;
2357 temp_frac = frac_val * 10;
2358 buffer[prtn++] = '.';
2359 while (frac_bits < 2 && (temp_frac / mult) < 1 ) {
2360 /* only reserved 2 bits fraction */
2361 buffer[prtn++] ='0';
2366 * Need to think these cases :
2367 * 1. #echo x.00 > /proc/xxx output result : x
2368 * 2. #echo x.0x > /proc/xxx output result : x.0x
2369 * 3. #echo x.x0 > /proc/xxx output result : x.x
2370 * 4. #echo x.xx > /proc/xxx output result : x.xx
2371 * Only reserved 2 bits fraction.
2373 for (i = 0; i < (5 - prtn); i++)
2376 frac_bits = min((int)count - prtn, 3 - frac_bits);
2377 prtn += snprintf(buffer + prtn, frac_bits, "%ld",
2378 frac_val * temp_mult / mult);
2381 while(buffer[prtn] < '1' || buffer[prtn] > '9') {
2383 if (buffer[prtn] == '.') {
2390 buffer[prtn++] ='\n';
2393 EXPORT_SYMBOL(lprocfs_read_frac_helper);
2395 int lprocfs_seq_read_frac_helper(struct seq_file *m, long val, int mult)
2397 long decimal_val, frac_val;
2399 decimal_val = val / mult;
2400 seq_printf(m, "%ld", decimal_val);
2401 frac_val = val % mult;
2408 /* Three cases: x0, xx, 0x */
2409 if ((frac_val % 10) != 0)
2410 seq_printf(m, ".%ld", frac_val);
2412 seq_printf(m, ".%ld", frac_val / 10);
2415 seq_printf(m, "\n");
2418 EXPORT_SYMBOL(lprocfs_seq_read_frac_helper);
2420 int lprocfs_write_u64_helper(const char *buffer, unsigned long count,__u64 *val)
2422 return lprocfs_write_frac_u64_helper(buffer, count, val, 1);
2424 EXPORT_SYMBOL(lprocfs_write_u64_helper);
2426 int lprocfs_write_frac_u64_helper(const char *buffer, unsigned long count,
2427 __u64 *val, int mult)
2429 char kernbuf[22], *end, *pbuf;
2430 __u64 whole, frac = 0, units;
2431 unsigned frac_d = 1;
2433 if (count > (sizeof(kernbuf) - 1))
2436 if (copy_from_user(kernbuf, buffer, count))
2439 kernbuf[count] = '\0';
2446 whole = simple_strtoull(pbuf, &end, 10);
2450 if (end != NULL && *end == '.') {
2454 /* need to limit frac_d to a __u32 */
2455 if (strlen(pbuf) > 10)
2458 frac = simple_strtoull(pbuf, &end, 10);
2459 /* count decimal places */
2460 for (i = 0; i < (end - pbuf); i++)
2479 /* Specified units override the multiplier */
2481 mult = mult < 0 ? -units : units;
2484 do_div(frac, frac_d);
2485 *val = whole * mult + frac;
2488 EXPORT_SYMBOL(lprocfs_write_frac_u64_helper);
2490 static char *lprocfs_strnstr(const char *s1, const char *s2, size_t len)
2499 if (!memcmp(s1, s2, l2))
2507 * Find the string \a name in the input \a buffer, and return a pointer to the
2508 * value immediately following \a name, reducing \a count appropriately.
2509 * If \a name is not found the original \a buffer is returned.
2511 char *lprocfs_find_named_value(const char *buffer, const char *name,
2515 size_t buflen = *count;
2517 /* there is no strnstr() in rhel5 and ubuntu kernels */
2518 val = lprocfs_strnstr(buffer, name, buflen);
2520 return (char *)buffer;
2522 val += strlen(name); /* skip prefix */
2523 while (val < buffer + buflen && isspace(*val)) /* skip separator */
2527 while (val < buffer + buflen && isalnum(*val)) {
2532 return val - *count;
2534 EXPORT_SYMBOL(lprocfs_find_named_value);
2536 int lprocfs_seq_create(struct proc_dir_entry *parent,
2539 const struct file_operations *seq_fops,
2542 struct proc_dir_entry *entry;
2545 /* Disallow secretly (un)writable entries. */
2546 LASSERT((seq_fops->write == NULL) == ((mode & 0222) == 0));
2548 entry = proc_create_data(name, mode, parent, seq_fops, data);
2555 EXPORT_SYMBOL(lprocfs_seq_create);
2557 int lprocfs_obd_seq_create(struct obd_device *dev,
2560 const struct file_operations *seq_fops,
2563 return (lprocfs_seq_create(dev->obd_proc_entry, name,
2564 mode, seq_fops, data));
2566 EXPORT_SYMBOL(lprocfs_obd_seq_create);
2568 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
2570 if (value >= OBD_HIST_MAX)
2571 value = OBD_HIST_MAX - 1;
2573 spin_lock(&oh->oh_lock);
2574 oh->oh_buckets[value]++;
2575 spin_unlock(&oh->oh_lock);
2577 EXPORT_SYMBOL(lprocfs_oh_tally);
2579 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
2581 unsigned int val = 0;
2583 if (likely(value != 0))
2584 val = min(fls(value - 1), OBD_HIST_MAX);
2586 lprocfs_oh_tally(oh, val);
2588 EXPORT_SYMBOL(lprocfs_oh_tally_log2);
2590 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
2592 unsigned long ret = 0;
2595 for (i = 0; i < OBD_HIST_MAX; i++)
2596 ret += oh->oh_buckets[i];
2599 EXPORT_SYMBOL(lprocfs_oh_sum);
2601 void lprocfs_oh_clear(struct obd_histogram *oh)
2603 spin_lock(&oh->oh_lock);
2604 memset(oh->oh_buckets, 0, sizeof(oh->oh_buckets));
2605 spin_unlock(&oh->oh_lock);
2607 EXPORT_SYMBOL(lprocfs_oh_clear);
2609 int lprocfs_obd_rd_max_pages_per_rpc(char *page, char **start, off_t off,
2610 int count, int *eof, void *data)
2612 struct obd_device *dev = data;
2613 struct client_obd *cli = &dev->u.cli;
2616 client_obd_list_lock(&cli->cl_loi_list_lock);
2617 rc = snprintf(page, count, "%d\n", cli->cl_max_pages_per_rpc);
2618 client_obd_list_unlock(&cli->cl_loi_list_lock);
2621 EXPORT_SYMBOL(lprocfs_obd_rd_max_pages_per_rpc);
2623 int lprocfs_obd_max_pages_per_rpc_seq_show(struct seq_file *m, 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 = seq_printf(m, "%d\n", cli->cl_max_pages_per_rpc);
2631 client_obd_list_unlock(&cli->cl_loi_list_lock);
2634 EXPORT_SYMBOL(lprocfs_obd_max_pages_per_rpc_seq_show);
2636 int lprocfs_wr_root_squash(const char __user *buffer, unsigned long count,
2637 struct root_squash_info *squash, char *name)
2640 char kernbuf[64], *tmp, *errmsg;
2641 unsigned long uid, gid;
2644 if (count >= sizeof(kernbuf)) {
2645 errmsg = "string too long";
2646 GOTO(failed_noprint, rc = -EINVAL);
2648 if (copy_from_user(kernbuf, buffer, count)) {
2649 errmsg = "bad address";
2650 GOTO(failed_noprint, rc = -EFAULT);
2652 kernbuf[count] = '\0';
2654 /* look for uid gid separator */
2655 tmp = strchr(kernbuf, ':');
2657 errmsg = "needs uid:gid format";
2658 GOTO(failed, rc = -EINVAL);
2664 if (kstrtoul(kernbuf, 0, &uid) != 0) {
2666 GOTO(failed, rc = -EINVAL);
2670 if (kstrtoul(tmp, 0, &gid) != 0) {
2672 GOTO(failed, rc = -EINVAL);
2675 squash->rsi_uid = uid;
2676 squash->rsi_gid = gid;
2678 LCONSOLE_INFO("%s: root_squash is set to %u:%u\n",
2679 name, squash->rsi_uid, squash->rsi_gid);
2687 CWARN("%s: failed to set root_squash to \"%s\", %s, rc = %d\n",
2688 name, kernbuf, errmsg, rc);
2691 CWARN("%s: failed to set root_squash due to %s, rc = %d\n",
2695 EXPORT_SYMBOL(lprocfs_wr_root_squash);
2698 int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count,
2699 struct root_squash_info *squash, char *name)
2702 char *kernbuf = NULL;
2704 struct list_head tmp;
2708 errmsg = "string too long";
2709 GOTO(failed, rc = -EINVAL);
2712 OBD_ALLOC(kernbuf, count + 1);
2713 if (kernbuf == NULL) {
2714 errmsg = "no memory";
2715 GOTO(failed, rc = -ENOMEM);
2717 if (copy_from_user(kernbuf, buffer, count)) {
2718 errmsg = "bad address";
2719 GOTO(failed, rc = -EFAULT);
2721 kernbuf[count] = '\0';
2723 if (count > 0 && kernbuf[count - 1] == '\n')
2724 kernbuf[count - 1] = '\0';
2726 if (strcmp(kernbuf, "NONE") == 0 || strcmp(kernbuf, "clear") == 0) {
2727 /* empty string is special case */
2728 down_write(&squash->rsi_sem);
2729 if (!list_empty(&squash->rsi_nosquash_nids))
2730 cfs_free_nidlist(&squash->rsi_nosquash_nids);
2731 up_write(&squash->rsi_sem);
2732 LCONSOLE_INFO("%s: nosquash_nids is cleared\n", name);
2733 OBD_FREE(kernbuf, count + 1);
2737 INIT_LIST_HEAD(&tmp);
2738 if (cfs_parse_nidlist(kernbuf, count, &tmp) <= 0) {
2739 errmsg = "can't parse";
2740 GOTO(failed, rc = -EINVAL);
2742 LCONSOLE_INFO("%s: nosquash_nids set to %s\n",
2744 OBD_FREE(kernbuf, count + 1);
2747 down_write(&squash->rsi_sem);
2748 if (!list_empty(&squash->rsi_nosquash_nids))
2749 cfs_free_nidlist(&squash->rsi_nosquash_nids);
2750 list_splice(&tmp, &squash->rsi_nosquash_nids);
2751 up_write(&squash->rsi_sem);
2757 CWARN("%s: failed to set nosquash_nids to \"%s\", %s rc = %d\n",
2758 name, kernbuf, errmsg, rc);
2759 OBD_FREE(kernbuf, count + 1);
2761 CWARN("%s: failed to set nosquash_nids due to %s rc = %d\n",
2766 EXPORT_SYMBOL(lprocfs_wr_nosquash_nids);