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, 2014, 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 <obd_class.h>
45 #include <lprocfs_status.h>
46 #include <lustre/lustre_idl.h>
50 static int lprocfs_no_percpu_stats = 0;
51 CFS_MODULE_PARM(lprocfs_no_percpu_stats, "i", int, 0644,
52 "Do not alloc percpu data for lprocfs stats");
54 #define MAX_STRING_SIZE 128
56 int lprocfs_single_release(struct inode *inode, struct file *file)
58 return single_release(inode, file);
60 EXPORT_SYMBOL(lprocfs_single_release);
62 int lprocfs_seq_release(struct inode *inode, struct file *file)
64 return seq_release(inode, file);
66 EXPORT_SYMBOL(lprocfs_seq_release);
68 struct proc_dir_entry *
69 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
70 void *data, const struct file_operations *fops)
72 struct proc_dir_entry *proc;
75 if (root == NULL || name == NULL || fops == NULL)
76 return ERR_PTR(-EINVAL);
82 proc = proc_create_data(name, mode, root, fops, data);
84 CERROR("LprocFS: No memory to create /proc entry %s\n",
86 return ERR_PTR(-ENOMEM);
90 EXPORT_SYMBOL(lprocfs_add_simple);
92 struct proc_dir_entry *lprocfs_add_symlink(const char *name,
93 struct proc_dir_entry *parent, const char *format, ...)
95 struct proc_dir_entry *entry;
99 if (parent == NULL || format == NULL)
102 OBD_ALLOC_WAIT(dest, MAX_STRING_SIZE + 1);
106 va_start(ap, format);
107 vsnprintf(dest, MAX_STRING_SIZE, format, ap);
110 entry = proc_symlink(name, parent, dest);
112 CERROR("LprocFS: Could not create symbolic link from "
113 "%s to %s\n", name, dest);
115 OBD_FREE(dest, MAX_STRING_SIZE + 1);
118 EXPORT_SYMBOL(lprocfs_add_symlink);
120 #ifdef HAVE_ONLY_PROCFS_SEQ
121 static const struct file_operations lprocfs_generic_fops = { };
125 lprocfs_fops_read(struct file *f, char __user *buf, size_t size, loff_t *ppos)
127 struct inode *inode = f->f_dentry->d_inode;
128 struct proc_dir_entry *dp = PDE(inode);
129 char *page, *start = NULL;
130 int rc, eof = 1, count;
132 if (*ppos >= PAGE_CACHE_SIZE)
135 page = (char *)__get_free_page(GFP_KERNEL);
139 rc = LPROCFS_ENTRY_CHECK(inode);
143 OBD_FAIL_TIMEOUT(OBD_FAIL_LPROC_REMOVE, 10);
144 if (dp->read_proc != NULL)
145 rc = dp->read_proc(page, &start, *ppos, PAGE_CACHE_SIZE,
153 /* for lustre proc read, the read count must be less than PAGE_SIZE */
162 start = page + *ppos;
163 } else if (start < page) {
167 count = (rc < size) ? rc : size;
168 if (copy_to_user(buf, start, count)) {
175 free_page((unsigned long)page);
180 lprocfs_fops_write(struct file *f, const char __user *buf, size_t size,
183 struct inode *inode = f->f_dentry->d_inode;
184 struct proc_dir_entry *dp = PDE(inode);
187 rc = LPROCFS_ENTRY_CHECK(inode);
191 if (dp->write_proc != NULL)
192 rc = dp->write_proc(f, buf, size, dp->data);
199 static struct file_operations lprocfs_generic_fops = {
200 .owner = THIS_MODULE,
201 .read = lprocfs_fops_read,
202 .write = lprocfs_fops_write,
205 /* for b=10866, global variable */
206 DECLARE_RWSEM(_lprocfs_lock);
207 EXPORT_SYMBOL(_lprocfs_lock);
209 static struct proc_dir_entry *__lprocfs_srch(struct proc_dir_entry *head,
212 struct proc_dir_entry *temp;
218 while (temp != NULL) {
219 if (strcmp(temp->name, name) == 0)
226 struct proc_dir_entry *lprocfs_srch(struct proc_dir_entry *head,
229 struct proc_dir_entry *temp;
231 LPROCFS_SRCH_ENTRY();
232 temp = __lprocfs_srch(head, name);
236 EXPORT_SYMBOL(lprocfs_srch);
238 static int __lprocfs_add_vars(struct proc_dir_entry *root,
239 struct lprocfs_vars *list,
244 if (root == NULL || list == NULL)
247 while (list->name != NULL) {
248 struct proc_dir_entry *cur_root, *proc;
249 char *pathcopy, *cur, *next, pathbuf[64];
250 int pathsize = strlen(list->name) + 1;
255 /* need copy of path for strsep */
256 if (strlen(list->name) > sizeof(pathbuf) - 1) {
257 OBD_ALLOC(pathcopy, pathsize);
258 if (pathcopy == NULL)
259 GOTO(out, rc = -ENOMEM);
265 strcpy(pathcopy, list->name);
267 while (cur_root != NULL && (cur = strsep(&next, "/"))) {
268 if (*cur =='\0') /* skip double/trailing "/" */
271 proc = __lprocfs_srch(cur_root, cur);
272 CDEBUG(D_OTHER, "cur_root=%s, cur=%s, next=%s, (%s)\n",
273 cur_root->name, cur, next,
274 (proc ? "exists" : "new"));
276 cur_root = (proc ? proc :
277 proc_mkdir(cur, cur_root));
278 } else if (proc == NULL) {
280 if (list->proc_mode != 0000) {
281 mode = list->proc_mode;
285 if (list->write_fptr)
288 proc = create_proc_entry(cur, mode, cur_root);
292 if (pathcopy != pathbuf)
293 OBD_FREE(pathcopy, pathsize);
295 if (cur_root == NULL || proc == NULL) {
296 CERROR("LprocFS: No memory to create /proc entry %s\n",
298 GOTO(out, rc = -ENOMEM);
302 proc->proc_fops = list->fops;
304 proc->proc_fops = &lprocfs_generic_fops;
305 proc->read_proc = list->read_fptr;
306 proc->write_proc = list->write_fptr;
307 proc->data = (list->data ? list->data : data);
314 int lprocfs_add_vars(struct proc_dir_entry *root, struct lprocfs_vars *list,
319 LPROCFS_WRITE_ENTRY();
320 rc = __lprocfs_add_vars(root, list, data);
321 LPROCFS_WRITE_EXIT();
325 EXPORT_SYMBOL(lprocfs_add_vars);
331 * \param root [in] The parent proc entry on which new entry will be added.
332 * \param list [in] Array of proc entries to be added.
333 * \param data [in] The argument to be passed when entries read/write routines
334 * are called through /proc file.
336 * \retval 0 on success
340 lprocfs_seq_add_vars(struct proc_dir_entry *root, struct lprocfs_seq_vars *list,
343 if (root == NULL || list == NULL)
346 while (list->name != NULL) {
347 struct proc_dir_entry *proc;
350 if (list->proc_mode != 0000) {
351 mode = list->proc_mode;
352 } else if (list->fops) {
353 if (list->fops->read)
355 if (list->fops->write)
358 proc = proc_create_data(list->name, mode, root,
359 list->fops ?: &lprocfs_generic_fops,
367 EXPORT_SYMBOL(lprocfs_seq_add_vars);
369 #ifndef HAVE_ONLY_PROCFS_SEQ
370 static void lprocfs_remove_nolock(struct proc_dir_entry **proot)
372 struct proc_dir_entry *root = *proot;
373 struct proc_dir_entry *temp = root;
374 struct proc_dir_entry *rm_entry;
375 struct proc_dir_entry *parent;
378 if (root == NULL || IS_ERR(root))
381 parent = root->parent;
382 LASSERT(parent != NULL);
385 while (temp->subdir != NULL)
391 /* Memory corruption once caused this to fail, and
392 without this LASSERT we would loop here forever. */
393 LASSERTF(strlen(rm_entry->name) == rm_entry->namelen,
394 "0x%p %s/%s len %d\n", rm_entry, temp->name,
395 rm_entry->name, (int)strlen(rm_entry->name));
397 remove_proc_entry(rm_entry->name, temp);
404 void lprocfs_remove(struct proc_dir_entry **rooth)
406 #ifndef HAVE_ONLY_PROCFS_SEQ
407 LPROCFS_WRITE_ENTRY(); /* search vs remove race */
408 lprocfs_remove_nolock(rooth);
409 LPROCFS_WRITE_EXIT();
415 EXPORT_SYMBOL(lprocfs_remove);
417 void lprocfs_remove_proc_entry(const char *name, struct proc_dir_entry *parent)
419 LASSERT(parent != NULL);
420 remove_proc_entry(name, parent);
422 EXPORT_SYMBOL(lprocfs_remove_proc_entry);
424 #ifndef HAVE_ONLY_PROCFS_SEQ
425 void lprocfs_try_remove_proc_entry(const char *name,
426 struct proc_dir_entry *parent)
428 struct proc_dir_entry *t = NULL;
429 struct proc_dir_entry **p;
432 LASSERT(parent != NULL);
435 LPROCFS_WRITE_ENTRY();
437 /* lookup target name */
438 for (p = &parent->subdir; *p; p = &(*p)->next) {
439 if ((*p)->namelen != len)
441 if (memcmp(name, (*p)->name, len))
448 /* verify it's empty: do not count "num_refs" */
449 for (p = &t->subdir; *p; p = &(*p)->next) {
450 if ((*p)->namelen != strlen("num_refs")) {
454 if (memcmp("num_refs", (*p)->name,
455 strlen("num_refs"))) {
463 lprocfs_remove_nolock(&t);
465 LPROCFS_WRITE_EXIT();
469 EXPORT_SYMBOL(lprocfs_try_remove_proc_entry);
471 struct proc_dir_entry *lprocfs_register(const char *name,
472 struct proc_dir_entry *parent,
473 struct lprocfs_vars *list, void *data)
475 struct proc_dir_entry *entry;
478 LPROCFS_WRITE_ENTRY();
479 entry = __lprocfs_srch(parent, name);
481 CERROR("entry '%s' already registered\n", name);
482 GOTO(out, entry = ERR_PTR(-EALREADY));
485 entry = proc_mkdir(name, parent);
487 GOTO(out, entry = ERR_PTR(-ENOMEM));
490 rc = __lprocfs_add_vars(entry, list, data);
492 lprocfs_remove_nolock(&entry);
493 GOTO(out, entry = ERR_PTR(rc));
497 LPROCFS_WRITE_EXIT();
500 EXPORT_SYMBOL(lprocfs_register);
503 struct proc_dir_entry *
504 lprocfs_seq_register(const char *name, struct proc_dir_entry *parent,
505 struct lprocfs_seq_vars *list, void *data)
507 struct proc_dir_entry *newchild;
509 newchild = proc_mkdir(name, parent);
510 if (newchild == NULL)
511 return ERR_PTR(-ENOMEM);
514 int rc = lprocfs_seq_add_vars(newchild, list, data);
516 lprocfs_remove(&newchild);
522 EXPORT_SYMBOL(lprocfs_seq_register);
524 /* Generic callbacks */
525 int lprocfs_uint_seq_show(struct seq_file *m, void *data)
527 return seq_printf(m, "%u\n", *(unsigned int *)data);
529 EXPORT_SYMBOL(lprocfs_uint_seq_show);
531 int lprocfs_wr_uint(struct file *file, const char __user *buffer,
532 unsigned long count, void *data)
535 char dummy[MAX_STRING_SIZE + 1], *end;
538 dummy[MAX_STRING_SIZE] = '\0';
539 if (copy_from_user(dummy, buffer, MAX_STRING_SIZE))
542 tmp = simple_strtoul(dummy, &end, 0);
546 *p = (unsigned int)tmp;
549 EXPORT_SYMBOL(lprocfs_wr_uint);
551 ssize_t lprocfs_uint_seq_write(struct file *file, const char __user *buffer,
552 size_t count, loff_t *off)
554 int *data = ((struct seq_file *)file->private_data)->private;
557 rc = lprocfs_write_helper(buffer, count, &val);
561 return lprocfs_wr_uint(file, buffer, count, data);
563 EXPORT_SYMBOL(lprocfs_uint_seq_write);
565 int lprocfs_u64_seq_show(struct seq_file *m, void *data)
567 LASSERT(data != NULL);
568 return seq_printf(m, LPU64"\n", *(__u64 *)data);
570 EXPORT_SYMBOL(lprocfs_u64_seq_show);
572 int lprocfs_atomic_seq_show(struct seq_file *m, void *data)
574 atomic_t *atom = data;
575 LASSERT(atom != NULL);
576 return seq_printf(m, "%d\n", atomic_read(atom));
578 EXPORT_SYMBOL(lprocfs_atomic_seq_show);
581 lprocfs_atomic_seq_write(struct file *file, const char __user *buffer,
582 size_t count, loff_t *off)
584 atomic_t *atm = ((struct seq_file *)file->private_data)->private;
588 rc = lprocfs_write_helper(buffer, count, &val);
595 atomic_set(atm, val);
598 EXPORT_SYMBOL(lprocfs_atomic_seq_write);
600 int lprocfs_uuid_seq_show(struct seq_file *m, void *data)
602 struct obd_device *obd = data;
604 LASSERT(obd != NULL);
605 return seq_printf(m, "%s\n", obd->obd_uuid.uuid);
607 EXPORT_SYMBOL(lprocfs_uuid_seq_show);
609 int lprocfs_name_seq_show(struct seq_file *m, void *data)
611 struct obd_device *dev = data;
613 LASSERT(dev != NULL);
614 return seq_printf(m, "%s\n", dev->obd_name);
616 EXPORT_SYMBOL(lprocfs_name_seq_show);
618 int lprocfs_blksize_seq_show(struct seq_file *m, void *data)
620 struct obd_device *obd = data;
621 struct obd_statfs osfs;
622 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
623 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
626 rc = seq_printf(m, "%u\n", osfs.os_bsize);
629 EXPORT_SYMBOL(lprocfs_blksize_seq_show);
631 int lprocfs_kbytestotal_seq_show(struct seq_file *m, void *data)
633 struct obd_device *obd = data;
634 struct obd_statfs osfs;
635 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
636 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
639 __u32 blk_size = osfs.os_bsize >> 10;
640 __u64 result = osfs.os_blocks;
642 while (blk_size >>= 1)
645 rc = seq_printf(m, LPU64"\n", result);
649 EXPORT_SYMBOL(lprocfs_kbytestotal_seq_show);
651 int lprocfs_kbytesfree_seq_show(struct seq_file *m, void *data)
653 struct obd_device *obd = data;
654 struct obd_statfs osfs;
655 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
656 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
659 __u32 blk_size = osfs.os_bsize >> 10;
660 __u64 result = osfs.os_bfree;
662 while (blk_size >>= 1)
665 rc = seq_printf(m, LPU64"\n", result);
669 EXPORT_SYMBOL(lprocfs_kbytesfree_seq_show);
671 int lprocfs_kbytesavail_seq_show(struct seq_file *m, void *data)
673 struct obd_device *obd = data;
674 struct obd_statfs osfs;
675 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
676 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
679 __u32 blk_size = osfs.os_bsize >> 10;
680 __u64 result = osfs.os_bavail;
682 while (blk_size >>= 1)
685 rc = seq_printf(m, LPU64"\n", result);
689 EXPORT_SYMBOL(lprocfs_kbytesavail_seq_show);
691 int lprocfs_filestotal_seq_show(struct seq_file *m, void *data)
693 struct obd_device *obd = data;
694 struct obd_statfs osfs;
695 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
696 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
699 rc = seq_printf(m, LPU64"\n", osfs.os_files);
702 EXPORT_SYMBOL(lprocfs_filestotal_seq_show);
704 int lprocfs_filesfree_seq_show(struct seq_file *m, void *data)
706 struct obd_device *obd = data;
707 struct obd_statfs osfs;
708 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
709 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
712 rc = seq_printf(m, LPU64"\n", osfs.os_ffree);
715 EXPORT_SYMBOL(lprocfs_filesfree_seq_show);
717 int lprocfs_server_uuid_seq_show(struct seq_file *m, void *data)
719 struct obd_device *obd = data;
720 struct obd_import *imp;
721 char *imp_state_name = NULL;
724 LASSERT(obd != NULL);
725 LPROCFS_CLIMP_CHECK(obd);
726 imp = obd->u.cli.cl_import;
727 imp_state_name = ptlrpc_import_state_name(imp->imp_state);
728 rc = seq_printf(m, "%s\t%s%s\n", obd2cli_tgt(obd), imp_state_name,
729 imp->imp_deactive ? "\tDEACTIVATED" : "");
731 LPROCFS_CLIMP_EXIT(obd);
734 EXPORT_SYMBOL(lprocfs_server_uuid_seq_show);
736 int lprocfs_conn_uuid_seq_show(struct seq_file *m, void *data)
738 struct obd_device *obd = data;
739 struct ptlrpc_connection *conn;
742 LASSERT(obd != NULL);
744 LPROCFS_CLIMP_CHECK(obd);
745 conn = obd->u.cli.cl_import->imp_connection;
746 if (conn && obd->u.cli.cl_import)
747 rc = seq_printf(m, "%s\n", conn->c_remote_uuid.uuid);
749 rc = seq_printf(m, "%s\n", "<none>");
751 LPROCFS_CLIMP_EXIT(obd);
754 EXPORT_SYMBOL(lprocfs_conn_uuid_seq_show);
756 /** add up per-cpu counters */
757 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
758 struct lprocfs_counter *cnt)
760 unsigned int num_entry;
761 struct lprocfs_counter *percpu_cntr;
763 unsigned long flags = 0;
765 memset(cnt, 0, sizeof(*cnt));
768 /* set count to 1 to avoid divide-by-zero errs in callers */
773 cnt->lc_min = LC_MIN_INIT;
775 num_entry = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
777 for (i = 0; i < num_entry; i++) {
778 if (stats->ls_percpu[i] == NULL)
780 percpu_cntr = lprocfs_stats_counter_get(stats, i, idx);
782 cnt->lc_count += percpu_cntr->lc_count;
783 cnt->lc_sum += percpu_cntr->lc_sum;
784 if (percpu_cntr->lc_min < cnt->lc_min)
785 cnt->lc_min = percpu_cntr->lc_min;
786 if (percpu_cntr->lc_max > cnt->lc_max)
787 cnt->lc_max = percpu_cntr->lc_max;
788 cnt->lc_sumsquare += percpu_cntr->lc_sumsquare;
791 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
793 EXPORT_SYMBOL(lprocfs_stats_collect);
796 * Append a space separated list of current set flags to str.
798 #define flag2str(flag) \
800 if (imp->imp_##flag) { \
801 seq_printf(m, "%s" #flag, first ? "" : ", "); \
805 static void obd_import_flags2str(struct obd_import *imp, struct seq_file *m)
809 if (imp->imp_obd->obd_no_recov) {
810 seq_printf(m, "no_recov");
816 flag2str(replayable);
817 flag2str(delayed_recovery);
818 flag2str(no_lock_replay);
819 flag2str(vbr_failed);
821 flag2str(resend_replay);
822 flag2str(no_pinger_recover);
823 flag2str(need_mne_swab);
824 flag2str(connect_tried);
828 static const char *obd_connect_names[] = {
842 "join_file(obsolete)",
846 "remote_client_by_force",
855 "mds_mds_connection",
858 "alt_checksum_algorithm",
892 static void obd_connect_seq_flags2str(struct seq_file *m, __u64 flags, char *sep)
898 for (i = 0; obd_connect_names[i] != NULL; i++, mask <<= 1) {
900 seq_printf(m, "%s%s",
901 first ? "" : sep, obd_connect_names[i]);
905 if (flags & ~(mask - 1))
906 seq_printf(m, "%sunknown_"LPX64,
907 first ? "" : sep, flags & ~(mask - 1));
910 int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep)
915 for (i = 0; obd_connect_names[i] != NULL; i++, mask <<= 1) {
917 ret += snprintf(page + ret, count - ret, "%s%s",
918 ret ? sep : "", obd_connect_names[i]);
920 if (flags & ~(mask - 1))
921 ret += snprintf(page + ret, count - ret,
923 ret ? sep : "", flags & ~(mask - 1));
926 EXPORT_SYMBOL(obd_connect_flags2str);
928 static void obd_connect_data_seqprint(struct seq_file *m,
929 struct obd_connect_data *ocd)
933 LASSERT(ocd != NULL);
934 flags = ocd->ocd_connect_flags;
936 seq_printf(m, " connect_data:\n"
939 ocd->ocd_connect_flags,
941 if (flags & OBD_CONNECT_VERSION)
942 seq_printf(m, " target_version: %u.%u.%u.%u\n",
943 OBD_OCD_VERSION_MAJOR(ocd->ocd_version),
944 OBD_OCD_VERSION_MINOR(ocd->ocd_version),
945 OBD_OCD_VERSION_PATCH(ocd->ocd_version),
946 OBD_OCD_VERSION_FIX(ocd->ocd_version));
947 if (flags & OBD_CONNECT_MDS)
948 seq_printf(m, " mdt_index: %d\n", ocd->ocd_group);
949 if (flags & OBD_CONNECT_GRANT)
950 seq_printf(m, " initial_grant: %d\n", ocd->ocd_grant);
951 if (flags & OBD_CONNECT_INDEX)
952 seq_printf(m, " target_index: %u\n", ocd->ocd_index);
953 if (flags & OBD_CONNECT_BRW_SIZE)
954 seq_printf(m, " max_brw_size: %d\n", ocd->ocd_brw_size);
955 if (flags & OBD_CONNECT_IBITS)
956 seq_printf(m, " ibits_known: "LPX64"\n",
957 ocd->ocd_ibits_known);
958 if (flags & OBD_CONNECT_GRANT_PARAM)
959 seq_printf(m, " grant_block_size: %d\n"
960 " grant_inode_size: %d\n"
961 " grant_extent_overhead: %d\n",
964 ocd->ocd_grant_extent);
965 if (flags & OBD_CONNECT_TRANSNO)
966 seq_printf(m, " first_transno: "LPX64"\n",
968 if (flags & OBD_CONNECT_CKSUM)
969 seq_printf(m, " cksum_types: %#x\n",
970 ocd->ocd_cksum_types);
971 if (flags & OBD_CONNECT_MAX_EASIZE)
972 seq_printf(m, " max_easize: %d\n", ocd->ocd_max_easize);
973 if (flags & OBD_CONNECT_MAXBYTES)
974 seq_printf(m, " max_object_bytes: "LPU64"\n",
978 int lprocfs_import_seq_show(struct seq_file *m, void *data)
980 struct lprocfs_counter ret;
981 struct lprocfs_counter_header *header;
982 struct obd_device *obd = (struct obd_device *)data;
983 struct obd_import *imp;
984 struct obd_import_conn *conn;
985 struct obd_connect_data *ocd;
990 LASSERT(obd != NULL);
991 LPROCFS_CLIMP_CHECK(obd);
992 imp = obd->u.cli.cl_import;
993 ocd = &imp->imp_connect_data;
995 seq_printf(m, "import:\n"
999 " connect_flags: [ ",
1002 ptlrpc_import_state_name(imp->imp_state));
1003 obd_connect_seq_flags2str(m, imp->imp_connect_data.ocd_connect_flags,
1005 seq_printf(m, " ]\n");
1006 obd_connect_data_seqprint(m, ocd);
1007 seq_printf(m, " import_flags: [ ");
1008 obd_import_flags2str(imp, m);
1010 seq_printf(m, " ]\n"
1012 " failover_nids: [ ");
1013 spin_lock(&imp->imp_lock);
1015 list_for_each_entry(conn, &imp->imp_conn_list, oic_item) {
1016 seq_printf(m, "%s%s", j ? ", " : "",
1017 libcfs_nid2str(conn->oic_conn->c_peer.nid));
1020 seq_printf(m, " ]\n"
1021 " current_connection: %s\n"
1022 " connection_attempts: %u\n"
1024 " in-progress_invalidations: %u\n",
1025 imp->imp_connection == NULL ? "<none>" :
1026 libcfs_nid2str(imp->imp_connection->c_peer.nid),
1028 imp->imp_generation,
1029 atomic_read(&imp->imp_inval_count));
1030 spin_unlock(&imp->imp_lock);
1032 if (obd->obd_svc_stats == NULL)
1035 header = &obd->obd_svc_stats->ls_cnt_header[PTLRPC_REQWAIT_CNTR];
1036 lprocfs_stats_collect(obd->obd_svc_stats, PTLRPC_REQWAIT_CNTR, &ret);
1037 if (ret.lc_count != 0) {
1038 /* first argument to do_div MUST be __u64 */
1039 __u64 sum = ret.lc_sum;
1040 do_div(sum, ret.lc_count);
1044 seq_printf(m, " rpcs:\n"
1046 " unregistering: %u\n"
1048 " avg_waittime: "LPU64" %s\n",
1049 atomic_read(&imp->imp_inflight),
1050 atomic_read(&imp->imp_unregistering),
1051 atomic_read(&imp->imp_timeouts),
1052 ret.lc_sum, header->lc_units);
1055 for(j = 0; j < IMP_AT_MAX_PORTALS; j++) {
1056 if (imp->imp_at.iat_portal[j] == 0)
1058 k = max_t(unsigned int, k,
1059 at_get(&imp->imp_at.iat_service_estimate[j]));
1061 seq_printf(m, " service_estimates:\n"
1062 " services: %u sec\n"
1063 " network: %u sec\n",
1065 at_get(&imp->imp_at.iat_net_latency));
1067 seq_printf(m, " transactions:\n"
1068 " last_replay: "LPU64"\n"
1069 " peer_committed: "LPU64"\n"
1070 " last_checked: "LPU64"\n",
1071 imp->imp_last_replay_transno,
1072 imp->imp_peer_committed_transno,
1073 imp->imp_last_transno_checked);
1075 /* avg data rates */
1076 for (rw = 0; rw <= 1; rw++) {
1077 lprocfs_stats_collect(obd->obd_svc_stats,
1078 PTLRPC_LAST_CNTR + BRW_READ_BYTES + rw,
1080 if (ret.lc_sum > 0 && ret.lc_count > 0) {
1081 /* first argument to do_div MUST be __u64 */
1082 __u64 sum = ret.lc_sum;
1083 do_div(sum, ret.lc_count);
1085 seq_printf(m, " %s_data_averages:\n"
1086 " bytes_per_rpc: "LPU64"\n",
1087 rw ? "write" : "read",
1090 k = (int)ret.lc_sum;
1091 j = opcode_offset(OST_READ + rw) + EXTRA_MAX_OPCODES;
1092 header = &obd->obd_svc_stats->ls_cnt_header[j];
1093 lprocfs_stats_collect(obd->obd_svc_stats, j, &ret);
1094 if (ret.lc_sum > 0 && ret.lc_count != 0) {
1095 /* first argument to do_div MUST be __u64 */
1096 __u64 sum = ret.lc_sum;
1097 do_div(sum, ret.lc_count);
1099 seq_printf(m, " %s_per_rpc: "LPU64"\n",
1100 header->lc_units, ret.lc_sum);
1101 j = (int)ret.lc_sum;
1103 seq_printf(m, " MB_per_sec: %u.%.02u\n",
1104 k / j, (100 * k / j) % 100);
1109 LPROCFS_CLIMP_EXIT(obd);
1112 EXPORT_SYMBOL(lprocfs_import_seq_show);
1114 int lprocfs_state_seq_show(struct seq_file *m, void *data)
1116 struct obd_device *obd = (struct obd_device *)data;
1117 struct obd_import *imp;
1120 LASSERT(obd != NULL);
1121 LPROCFS_CLIMP_CHECK(obd);
1122 imp = obd->u.cli.cl_import;
1124 seq_printf(m, "current_state: %s\n",
1125 ptlrpc_import_state_name(imp->imp_state));
1126 seq_printf(m, "state_history:\n");
1127 k = imp->imp_state_hist_idx;
1128 for (j = 0; j < IMP_STATE_HIST_LEN; j++) {
1129 struct import_state_hist *ish =
1130 &imp->imp_state_hist[(k + j) % IMP_STATE_HIST_LEN];
1131 if (ish->ish_state == 0)
1133 seq_printf(m, " - [ "CFS_TIME_T", %s ]\n",
1135 ptlrpc_import_state_name(ish->ish_state));
1138 LPROCFS_CLIMP_EXIT(obd);
1141 EXPORT_SYMBOL(lprocfs_state_seq_show);
1143 int lprocfs_seq_at_hist_helper(struct seq_file *m, struct adaptive_timeout *at)
1146 for (i = 0; i < AT_BINS; i++)
1147 seq_printf(m, "%3u ", at->at_hist[i]);
1148 seq_printf(m, "\n");
1151 EXPORT_SYMBOL(lprocfs_seq_at_hist_helper);
1153 /* See also ptlrpc_lprocfs_timeouts_show_seq */
1154 int lprocfs_timeouts_seq_show(struct seq_file *m, void *data)
1156 struct obd_device *obd = (struct obd_device *)data;
1157 struct obd_import *imp;
1158 unsigned int cur, worst;
1163 LASSERT(obd != NULL);
1164 LPROCFS_CLIMP_CHECK(obd);
1165 imp = obd->u.cli.cl_import;
1167 now = cfs_time_current_sec();
1169 /* Some network health info for kicks */
1170 s2dhms(&ts, now - imp->imp_last_reply_time);
1171 seq_printf(m, "%-10s : %ld, "DHMS_FMT" ago\n",
1172 "last reply", imp->imp_last_reply_time, DHMS_VARS(&ts));
1174 cur = at_get(&imp->imp_at.iat_net_latency);
1175 worst = imp->imp_at.iat_net_latency.at_worst_ever;
1176 worstt = imp->imp_at.iat_net_latency.at_worst_time;
1177 s2dhms(&ts, now - worstt);
1178 seq_printf(m, "%-10s : cur %3u worst %3u (at %ld, "DHMS_FMT" ago) ",
1179 "network", cur, worst, worstt, DHMS_VARS(&ts));
1180 lprocfs_seq_at_hist_helper(m, &imp->imp_at.iat_net_latency);
1182 for(i = 0; i < IMP_AT_MAX_PORTALS; i++) {
1183 if (imp->imp_at.iat_portal[i] == 0)
1185 cur = at_get(&imp->imp_at.iat_service_estimate[i]);
1186 worst = imp->imp_at.iat_service_estimate[i].at_worst_ever;
1187 worstt = imp->imp_at.iat_service_estimate[i].at_worst_time;
1188 s2dhms(&ts, now - worstt);
1189 seq_printf(m, "portal %-2d : cur %3u worst %3u (at %ld, "
1190 DHMS_FMT" ago) ", imp->imp_at.iat_portal[i],
1191 cur, worst, worstt, DHMS_VARS(&ts));
1192 lprocfs_seq_at_hist_helper(m, &imp->imp_at.iat_service_estimate[i]);
1195 LPROCFS_CLIMP_EXIT(obd);
1198 EXPORT_SYMBOL(lprocfs_timeouts_seq_show);
1200 int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data)
1202 struct obd_device *obd = data;
1205 LPROCFS_CLIMP_CHECK(obd);
1206 flags = obd->u.cli.cl_import->imp_connect_data.ocd_connect_flags;
1207 seq_printf(m, "flags="LPX64"\n", flags);
1208 obd_connect_seq_flags2str(m, flags, "\n");
1209 seq_printf(m, "\n");
1210 LPROCFS_CLIMP_EXIT(obd);
1213 EXPORT_SYMBOL(lprocfs_connect_flags_seq_show);
1216 lprocfs_obd_setup(struct obd_device *obd)
1220 LASSERT(obd != NULL);
1221 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1222 LASSERT(obd->obd_type->typ_procroot != NULL);
1224 obd->obd_proc_entry = lprocfs_seq_register(obd->obd_name,
1225 obd->obd_type->typ_procroot,
1226 obd->obd_vars, obd);
1227 if (IS_ERR(obd->obd_proc_entry)) {
1228 rc = PTR_ERR(obd->obd_proc_entry);
1229 CERROR("error %d setting up lprocfs for %s\n",rc,obd->obd_name);
1230 obd->obd_proc_entry = NULL;
1234 EXPORT_SYMBOL(lprocfs_obd_setup);
1236 int lprocfs_obd_cleanup(struct obd_device *obd)
1240 if (obd->obd_proc_exports_entry) {
1241 /* Should be no exports left */
1242 lprocfs_remove(&obd->obd_proc_exports_entry);
1243 obd->obd_proc_exports_entry = NULL;
1245 if (obd->obd_proc_entry) {
1246 lprocfs_remove(&obd->obd_proc_entry);
1247 obd->obd_proc_entry = NULL;
1251 EXPORT_SYMBOL(lprocfs_obd_cleanup);
1253 int lprocfs_stats_alloc_one(struct lprocfs_stats *stats, unsigned int cpuid)
1255 struct lprocfs_counter *cntr;
1256 unsigned int percpusize;
1258 unsigned long flags = 0;
1261 LASSERT(stats->ls_percpu[cpuid] == NULL);
1262 LASSERT((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0);
1264 percpusize = lprocfs_stats_counter_size(stats);
1265 LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[cpuid], percpusize);
1266 if (stats->ls_percpu[cpuid] != NULL) {
1268 if (unlikely(stats->ls_biggest_alloc_num <= cpuid)) {
1269 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
1270 spin_lock_irqsave(&stats->ls_lock, flags);
1272 spin_lock(&stats->ls_lock);
1273 if (stats->ls_biggest_alloc_num <= cpuid)
1274 stats->ls_biggest_alloc_num = cpuid + 1;
1275 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) {
1276 spin_unlock_irqrestore(&stats->ls_lock, flags);
1278 spin_unlock(&stats->ls_lock);
1281 /* initialize the ls_percpu[cpuid] non-zero counter */
1282 for (i = 0; i < stats->ls_num; ++i) {
1283 cntr = lprocfs_stats_counter_get(stats, cpuid, i);
1284 cntr->lc_min = LC_MIN_INIT;
1289 EXPORT_SYMBOL(lprocfs_stats_alloc_one);
1291 struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num,
1292 enum lprocfs_stats_flags flags)
1294 struct lprocfs_stats *stats;
1295 unsigned int num_entry;
1296 unsigned int percpusize = 0;
1302 if (lprocfs_no_percpu_stats != 0)
1303 flags |= LPROCFS_STATS_FLAG_NOPERCPU;
1305 if (flags & LPROCFS_STATS_FLAG_NOPERCPU)
1308 num_entry = num_possible_cpus();
1310 /* alloc percpu pointers for all possible cpu slots */
1311 LIBCFS_ALLOC(stats, offsetof(typeof(*stats), ls_percpu[num_entry]));
1315 stats->ls_num = num;
1316 stats->ls_flags = flags;
1317 spin_lock_init(&stats->ls_lock);
1319 /* alloc num of counter headers */
1320 LIBCFS_ALLOC(stats->ls_cnt_header,
1321 stats->ls_num * sizeof(struct lprocfs_counter_header));
1322 if (stats->ls_cnt_header == NULL)
1325 if ((flags & LPROCFS_STATS_FLAG_NOPERCPU) != 0) {
1326 /* contains only one set counters */
1327 percpusize = lprocfs_stats_counter_size(stats);
1328 LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[0], percpusize);
1329 if (stats->ls_percpu[0] == NULL)
1331 stats->ls_biggest_alloc_num = 1;
1332 } else if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0) {
1333 /* alloc all percpu data, currently only obd_memory use this */
1334 for (i = 0; i < num_entry; ++i)
1335 if (lprocfs_stats_alloc_one(stats, i) < 0)
1342 lprocfs_free_stats(&stats);
1345 EXPORT_SYMBOL(lprocfs_alloc_stats);
1347 void lprocfs_free_stats(struct lprocfs_stats **statsh)
1349 struct lprocfs_stats *stats = *statsh;
1350 unsigned int num_entry;
1351 unsigned int percpusize;
1354 if (stats == NULL || stats->ls_num == 0)
1358 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU)
1361 num_entry = num_possible_cpus();
1363 percpusize = lprocfs_stats_counter_size(stats);
1364 for (i = 0; i < num_entry; i++)
1365 if (stats->ls_percpu[i] != NULL)
1366 LIBCFS_FREE(stats->ls_percpu[i], percpusize);
1367 if (stats->ls_cnt_header != NULL)
1368 LIBCFS_FREE(stats->ls_cnt_header, stats->ls_num *
1369 sizeof(struct lprocfs_counter_header));
1370 LIBCFS_FREE(stats, offsetof(typeof(*stats), ls_percpu[num_entry]));
1372 EXPORT_SYMBOL(lprocfs_free_stats);
1374 void lprocfs_clear_stats(struct lprocfs_stats *stats)
1376 struct lprocfs_counter *percpu_cntr;
1379 unsigned int num_entry;
1380 unsigned long flags = 0;
1382 num_entry = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1384 for (i = 0; i < num_entry; i++) {
1385 if (stats->ls_percpu[i] == NULL)
1387 for (j = 0; j < stats->ls_num; j++) {
1388 percpu_cntr = lprocfs_stats_counter_get(stats, i, j);
1389 percpu_cntr->lc_count = 0;
1390 percpu_cntr->lc_min = LC_MIN_INIT;
1391 percpu_cntr->lc_max = 0;
1392 percpu_cntr->lc_sumsquare = 0;
1393 percpu_cntr->lc_sum = 0;
1394 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
1395 percpu_cntr->lc_sum_irq = 0;
1399 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1401 EXPORT_SYMBOL(lprocfs_clear_stats);
1403 static ssize_t lprocfs_stats_seq_write(struct file *file,
1404 const char __user *buf,
1405 size_t len, loff_t *off)
1407 struct seq_file *seq = file->private_data;
1408 struct lprocfs_stats *stats = seq->private;
1410 lprocfs_clear_stats(stats);
1415 static void *lprocfs_stats_seq_start(struct seq_file *p, loff_t *pos)
1417 struct lprocfs_stats *stats = p->private;
1419 return (*pos < stats->ls_num) ? pos : NULL;
1422 static void lprocfs_stats_seq_stop(struct seq_file *p, void *v)
1426 static void *lprocfs_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
1430 return lprocfs_stats_seq_start(p, pos);
1433 /* seq file export of one lprocfs counter */
1434 static int lprocfs_stats_seq_show(struct seq_file *p, void *v)
1436 struct lprocfs_stats *stats = p->private;
1437 struct lprocfs_counter_header *hdr;
1438 struct lprocfs_counter ctr;
1439 int idx = *(loff_t *)v;
1445 do_gettimeofday(&now);
1446 rc = seq_printf(p, "%-25s %lu.%lu secs.usecs\n",
1447 "snapshot_time", now.tv_sec, now.tv_usec);
1452 hdr = &stats->ls_cnt_header[idx];
1453 lprocfs_stats_collect(stats, idx, &ctr);
1455 if (ctr.lc_count == 0)
1458 rc = seq_printf(p, "%-25s "LPD64" samples [%s]", hdr->lc_name,
1459 ctr.lc_count, hdr->lc_units);
1463 if ((hdr->lc_config & LPROCFS_CNTR_AVGMINMAX) && ctr.lc_count > 0) {
1464 rc = seq_printf(p, " "LPD64" "LPD64" "LPD64,
1465 ctr.lc_min, ctr.lc_max, ctr.lc_sum);
1468 if (hdr->lc_config & LPROCFS_CNTR_STDDEV)
1469 rc = seq_printf(p, " "LPD64, ctr.lc_sumsquare);
1473 rc = seq_printf(p, "\n");
1475 return (rc < 0) ? rc : 0;
1478 static const struct seq_operations lprocfs_stats_seq_sops = {
1479 .start = lprocfs_stats_seq_start,
1480 .stop = lprocfs_stats_seq_stop,
1481 .next = lprocfs_stats_seq_next,
1482 .show = lprocfs_stats_seq_show,
1485 static int lprocfs_stats_seq_open(struct inode *inode, struct file *file)
1487 struct seq_file *seq;
1490 rc = LPROCFS_ENTRY_CHECK(inode);
1494 rc = seq_open(file, &lprocfs_stats_seq_sops);
1497 seq = file->private_data;
1498 seq->private = PDE_DATA(inode);
1502 static const struct file_operations lprocfs_stats_seq_fops = {
1503 .owner = THIS_MODULE,
1504 .open = lprocfs_stats_seq_open,
1506 .write = lprocfs_stats_seq_write,
1507 .llseek = seq_lseek,
1508 .release = lprocfs_seq_release,
1511 int lprocfs_register_stats(struct proc_dir_entry *root, const char *name,
1512 struct lprocfs_stats *stats)
1514 struct proc_dir_entry *entry;
1515 LASSERT(root != NULL);
1517 entry = proc_create_data(name, 0644, root,
1518 &lprocfs_stats_seq_fops, stats);
1523 EXPORT_SYMBOL(lprocfs_register_stats);
1525 void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
1526 unsigned conf, const char *name, const char *units)
1528 struct lprocfs_counter_header *header;
1529 struct lprocfs_counter *percpu_cntr;
1530 unsigned long flags = 0;
1532 unsigned int num_cpu;
1534 LASSERT(stats != NULL);
1536 header = &stats->ls_cnt_header[index];
1537 LASSERTF(header != NULL, "Failed to allocate stats header:[%d]%s/%s\n",
1538 index, name, units);
1540 header->lc_config = conf;
1541 header->lc_name = name;
1542 header->lc_units = units;
1544 num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1545 for (i = 0; i < num_cpu; ++i) {
1546 if (stats->ls_percpu[i] == NULL)
1548 percpu_cntr = lprocfs_stats_counter_get(stats, i, index);
1549 percpu_cntr->lc_count = 0;
1550 percpu_cntr->lc_min = LC_MIN_INIT;
1551 percpu_cntr->lc_max = 0;
1552 percpu_cntr->lc_sumsquare = 0;
1553 percpu_cntr->lc_sum = 0;
1554 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
1555 percpu_cntr->lc_sum_irq = 0;
1557 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1559 EXPORT_SYMBOL(lprocfs_counter_init);
1561 /* Note that we only init md counters for ops whose offset is less
1562 * than NUM_MD_STATS. This is explained in a comment in the definition
1563 * of struct md_ops. */
1564 #define LPROCFS_MD_OP_INIT(base, stats, op) \
1566 unsigned int _idx = base + MD_COUNTER_OFFSET(op); \
1568 if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS) { \
1569 LASSERT(_idx < stats->ls_num); \
1570 lprocfs_counter_init(stats, _idx, 0, #op, "reqs"); \
1574 void lprocfs_init_mps_stats(int num_private_stats, struct lprocfs_stats *stats)
1576 LPROCFS_MD_OP_INIT(num_private_stats, stats, getstatus);
1577 LPROCFS_MD_OP_INIT(num_private_stats, stats, null_inode);
1578 LPROCFS_MD_OP_INIT(num_private_stats, stats, find_cbdata);
1579 LPROCFS_MD_OP_INIT(num_private_stats, stats, close);
1580 LPROCFS_MD_OP_INIT(num_private_stats, stats, create);
1581 LPROCFS_MD_OP_INIT(num_private_stats, stats, done_writing);
1582 LPROCFS_MD_OP_INIT(num_private_stats, stats, enqueue);
1583 LPROCFS_MD_OP_INIT(num_private_stats, stats, getattr);
1584 LPROCFS_MD_OP_INIT(num_private_stats, stats, getattr_name);
1585 LPROCFS_MD_OP_INIT(num_private_stats, stats, intent_lock);
1586 LPROCFS_MD_OP_INIT(num_private_stats, stats, link);
1587 LPROCFS_MD_OP_INIT(num_private_stats, stats, rename);
1588 LPROCFS_MD_OP_INIT(num_private_stats, stats, setattr);
1589 LPROCFS_MD_OP_INIT(num_private_stats, stats, fsync);
1590 LPROCFS_MD_OP_INIT(num_private_stats, stats, read_page);
1591 LPROCFS_MD_OP_INIT(num_private_stats, stats, unlink);
1592 LPROCFS_MD_OP_INIT(num_private_stats, stats, setxattr);
1593 LPROCFS_MD_OP_INIT(num_private_stats, stats, getxattr);
1594 LPROCFS_MD_OP_INIT(num_private_stats, stats, init_ea_size);
1595 LPROCFS_MD_OP_INIT(num_private_stats, stats, get_lustre_md);
1596 LPROCFS_MD_OP_INIT(num_private_stats, stats, free_lustre_md);
1597 LPROCFS_MD_OP_INIT(num_private_stats, stats, update_lsm_md);
1598 LPROCFS_MD_OP_INIT(num_private_stats, stats, merge_attr);
1599 LPROCFS_MD_OP_INIT(num_private_stats, stats, set_open_replay_data);
1600 LPROCFS_MD_OP_INIT(num_private_stats, stats, clear_open_replay_data);
1601 LPROCFS_MD_OP_INIT(num_private_stats, stats, set_lock_data);
1602 LPROCFS_MD_OP_INIT(num_private_stats, stats, lock_match);
1603 LPROCFS_MD_OP_INIT(num_private_stats, stats, cancel_unused);
1604 LPROCFS_MD_OP_INIT(num_private_stats, stats, renew_capa);
1605 LPROCFS_MD_OP_INIT(num_private_stats, stats, unpack_capa);
1606 LPROCFS_MD_OP_INIT(num_private_stats, stats, get_remote_perm);
1607 LPROCFS_MD_OP_INIT(num_private_stats, stats, intent_getattr_async);
1608 LPROCFS_MD_OP_INIT(num_private_stats, stats, revalidate_lock);
1610 EXPORT_SYMBOL(lprocfs_init_mps_stats);
1612 int lprocfs_alloc_md_stats(struct obd_device *obd,
1613 unsigned int num_private_stats)
1615 struct lprocfs_stats *stats;
1616 unsigned int num_stats;
1619 CLASSERT(offsetof(struct md_ops, MD_STATS_FIRST_OP) == 0);
1620 CLASSERT(_MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) == 0);
1621 CLASSERT(_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) > 0);
1623 /* TODO Ensure that this function is only used where
1624 * appropriate by adding an assertion to the effect that
1625 * obd->obd_type->typ_md_ops is not NULL. We can't do this now
1626 * because mdt_procfs_init() uses this function to allocate
1627 * the stats backing /proc/fs/lustre/mdt/.../md_stats but the
1628 * mdt layer does not use the md_ops interface. This is
1629 * confusing and a waste of memory. See LU-2484.
1631 LASSERT(obd->obd_proc_entry != NULL);
1632 LASSERT(obd->obd_md_stats == NULL);
1633 LASSERT(obd->obd_md_cntr_base == 0);
1635 num_stats = NUM_MD_STATS + num_private_stats;
1636 stats = lprocfs_alloc_stats(num_stats, 0);
1640 lprocfs_init_mps_stats(num_private_stats, stats);
1642 for (i = num_private_stats; i < num_stats; i++) {
1643 if (stats->ls_cnt_header[i].lc_name == NULL) {
1644 CERROR("Missing md_stat initializer md_op "
1645 "operation at offset %d. Aborting.\n",
1646 i - num_private_stats);
1651 rc = lprocfs_register_stats(obd->obd_proc_entry, "md_stats", stats);
1653 lprocfs_free_stats(&stats);
1655 obd->obd_md_stats = stats;
1656 obd->obd_md_cntr_base = num_private_stats;
1661 EXPORT_SYMBOL(lprocfs_alloc_md_stats);
1663 void lprocfs_free_md_stats(struct obd_device *obd)
1665 struct lprocfs_stats *stats = obd->obd_md_stats;
1667 if (stats != NULL) {
1668 obd->obd_md_stats = NULL;
1669 obd->obd_md_cntr_base = 0;
1670 lprocfs_free_stats(&stats);
1673 EXPORT_SYMBOL(lprocfs_free_md_stats);
1675 void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
1677 lprocfs_counter_init(ldlm_stats,
1678 LDLM_ENQUEUE - LDLM_FIRST_OPC,
1679 0, "ldlm_enqueue", "reqs");
1680 lprocfs_counter_init(ldlm_stats,
1681 LDLM_CONVERT - LDLM_FIRST_OPC,
1682 0, "ldlm_convert", "reqs");
1683 lprocfs_counter_init(ldlm_stats,
1684 LDLM_CANCEL - LDLM_FIRST_OPC,
1685 0, "ldlm_cancel", "reqs");
1686 lprocfs_counter_init(ldlm_stats,
1687 LDLM_BL_CALLBACK - LDLM_FIRST_OPC,
1688 0, "ldlm_bl_callback", "reqs");
1689 lprocfs_counter_init(ldlm_stats,
1690 LDLM_CP_CALLBACK - LDLM_FIRST_OPC,
1691 0, "ldlm_cp_callback", "reqs");
1692 lprocfs_counter_init(ldlm_stats,
1693 LDLM_GL_CALLBACK - LDLM_FIRST_OPC,
1694 0, "ldlm_gl_callback", "reqs");
1696 EXPORT_SYMBOL(lprocfs_init_ldlm_stats);
1698 __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
1699 struct lprocfs_counter_header *header,
1700 enum lprocfs_stats_flags flags,
1701 enum lprocfs_fields_flags field)
1705 if (lc == NULL || header == NULL)
1709 case LPROCFS_FIELDS_FLAGS_CONFIG:
1710 ret = header->lc_config;
1712 case LPROCFS_FIELDS_FLAGS_SUM:
1714 if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
1715 ret += lc->lc_sum_irq;
1717 case LPROCFS_FIELDS_FLAGS_MIN:
1720 case LPROCFS_FIELDS_FLAGS_MAX:
1723 case LPROCFS_FIELDS_FLAGS_AVG:
1724 ret = (lc->lc_max - lc->lc_min) / 2;
1726 case LPROCFS_FIELDS_FLAGS_SUMSQUARE:
1727 ret = lc->lc_sumsquare;
1729 case LPROCFS_FIELDS_FLAGS_COUNT:
1737 EXPORT_SYMBOL(lprocfs_read_helper);
1739 int lprocfs_write_helper(const char __user *buffer, unsigned long count,
1742 return lprocfs_write_frac_helper(buffer, count, val, 1);
1744 EXPORT_SYMBOL(lprocfs_write_helper);
1746 int lprocfs_write_frac_helper(const char __user *buffer, unsigned long count,
1749 char kernbuf[20], *end, *pbuf;
1751 if (count > (sizeof(kernbuf) - 1))
1754 if (copy_from_user(kernbuf, buffer, count))
1757 kernbuf[count] = '\0';
1764 *val = (int)simple_strtoul(pbuf, &end, 10) * mult;
1768 if (end != NULL && *end == '.') {
1769 int temp_val, pow = 1;
1773 if (strlen(pbuf) > 5)
1774 pbuf[5] = '\0'; /*only allow 5bits fractional*/
1776 temp_val = (int)simple_strtoul(pbuf, &end, 10) * mult;
1779 for (i = 0; i < (end - pbuf); i++)
1782 *val += temp_val / pow;
1787 EXPORT_SYMBOL(lprocfs_write_frac_helper);
1789 int lprocfs_read_frac_helper(char *buffer, unsigned long count, long val,
1792 long decimal_val, frac_val;
1798 decimal_val = val / mult;
1799 prtn = snprintf(buffer, count, "%ld", decimal_val);
1800 frac_val = val % mult;
1802 if (prtn < (count - 4) && frac_val > 0) {
1804 int i, temp_mult = 1, frac_bits = 0;
1806 temp_frac = frac_val * 10;
1807 buffer[prtn++] = '.';
1808 while (frac_bits < 2 && (temp_frac / mult) < 1 ) {
1809 /* only reserved 2 bits fraction */
1810 buffer[prtn++] ='0';
1815 * Need to think these cases :
1816 * 1. #echo x.00 > /proc/xxx output result : x
1817 * 2. #echo x.0x > /proc/xxx output result : x.0x
1818 * 3. #echo x.x0 > /proc/xxx output result : x.x
1819 * 4. #echo x.xx > /proc/xxx output result : x.xx
1820 * Only reserved 2 bits fraction.
1822 for (i = 0; i < (5 - prtn); i++)
1825 frac_bits = min((int)count - prtn, 3 - frac_bits);
1826 prtn += snprintf(buffer + prtn, frac_bits, "%ld",
1827 frac_val * temp_mult / mult);
1830 while(buffer[prtn] < '1' || buffer[prtn] > '9') {
1832 if (buffer[prtn] == '.') {
1839 buffer[prtn++] ='\n';
1842 EXPORT_SYMBOL(lprocfs_read_frac_helper);
1844 int lprocfs_seq_read_frac_helper(struct seq_file *m, long val, int mult)
1846 long decimal_val, frac_val;
1848 decimal_val = val / mult;
1849 seq_printf(m, "%ld", decimal_val);
1850 frac_val = val % mult;
1857 /* Three cases: x0, xx, 0x */
1858 if ((frac_val % 10) != 0)
1859 seq_printf(m, ".%ld", frac_val);
1861 seq_printf(m, ".%ld", frac_val / 10);
1864 seq_printf(m, "\n");
1867 EXPORT_SYMBOL(lprocfs_seq_read_frac_helper);
1869 int lprocfs_write_u64_helper(const char __user *buffer, unsigned long count,
1872 return lprocfs_write_frac_u64_helper(buffer, count, val, 1);
1874 EXPORT_SYMBOL(lprocfs_write_u64_helper);
1876 int lprocfs_write_frac_u64_helper(const char __user *buffer,
1877 unsigned long count,
1878 __u64 *val, int mult)
1880 char kernbuf[22], *end, *pbuf;
1881 __u64 whole, frac = 0, units;
1882 unsigned frac_d = 1;
1884 if (count > (sizeof(kernbuf) - 1))
1887 if (copy_from_user(kernbuf, buffer, count))
1890 kernbuf[count] = '\0';
1897 whole = simple_strtoull(pbuf, &end, 10);
1901 if (end != NULL && *end == '.') {
1905 /* need to limit frac_d to a __u32 */
1906 if (strlen(pbuf) > 10)
1909 frac = simple_strtoull(pbuf, &end, 10);
1910 /* count decimal places */
1911 for (i = 0; i < (end - pbuf); i++)
1930 /* Specified units override the multiplier */
1932 mult = mult < 0 ? -units : units;
1935 do_div(frac, frac_d);
1936 *val = whole * mult + frac;
1939 EXPORT_SYMBOL(lprocfs_write_frac_u64_helper);
1941 static char *lprocfs_strnstr(const char *s1, const char *s2, size_t len)
1950 if (!memcmp(s1, s2, l2))
1958 * Find the string \a name in the input \a buffer, and return a pointer to the
1959 * value immediately following \a name, reducing \a count appropriately.
1960 * If \a name is not found the original \a buffer is returned.
1962 char *lprocfs_find_named_value(const char *buffer, const char *name,
1966 size_t buflen = *count;
1968 /* there is no strnstr() in rhel5 and ubuntu kernels */
1969 val = lprocfs_strnstr(buffer, name, buflen);
1971 return (char *)buffer;
1973 val += strlen(name); /* skip prefix */
1974 while (val < buffer + buflen && isspace(*val)) /* skip separator */
1978 while (val < buffer + buflen && isalnum(*val)) {
1983 return val - *count;
1985 EXPORT_SYMBOL(lprocfs_find_named_value);
1987 int lprocfs_seq_create(struct proc_dir_entry *parent,
1990 const struct file_operations *seq_fops,
1993 struct proc_dir_entry *entry;
1996 /* Disallow secretly (un)writable entries. */
1997 LASSERT((seq_fops->write == NULL) == ((mode & 0222) == 0));
1999 entry = proc_create_data(name, mode, parent, seq_fops, data);
2006 EXPORT_SYMBOL(lprocfs_seq_create);
2008 int lprocfs_obd_seq_create(struct obd_device *dev,
2011 const struct file_operations *seq_fops,
2014 return (lprocfs_seq_create(dev->obd_proc_entry, name,
2015 mode, seq_fops, data));
2017 EXPORT_SYMBOL(lprocfs_obd_seq_create);
2019 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
2021 if (value >= OBD_HIST_MAX)
2022 value = OBD_HIST_MAX - 1;
2024 spin_lock(&oh->oh_lock);
2025 oh->oh_buckets[value]++;
2026 spin_unlock(&oh->oh_lock);
2028 EXPORT_SYMBOL(lprocfs_oh_tally);
2030 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
2032 unsigned int val = 0;
2034 if (likely(value != 0))
2035 val = min(fls(value - 1), OBD_HIST_MAX);
2037 lprocfs_oh_tally(oh, val);
2039 EXPORT_SYMBOL(lprocfs_oh_tally_log2);
2041 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
2043 unsigned long ret = 0;
2046 for (i = 0; i < OBD_HIST_MAX; i++)
2047 ret += oh->oh_buckets[i];
2050 EXPORT_SYMBOL(lprocfs_oh_sum);
2052 void lprocfs_oh_clear(struct obd_histogram *oh)
2054 spin_lock(&oh->oh_lock);
2055 memset(oh->oh_buckets, 0, sizeof(oh->oh_buckets));
2056 spin_unlock(&oh->oh_lock);
2058 EXPORT_SYMBOL(lprocfs_oh_clear);
2060 int lprocfs_obd_rd_max_pages_per_rpc(char *page, char **start, off_t off,
2061 int count, int *eof, void *data)
2063 struct obd_device *dev = data;
2064 struct client_obd *cli = &dev->u.cli;
2067 spin_lock(&cli->cl_loi_list_lock);
2068 rc = snprintf(page, count, "%d\n", cli->cl_max_pages_per_rpc);
2069 spin_unlock(&cli->cl_loi_list_lock);
2073 EXPORT_SYMBOL(lprocfs_obd_rd_max_pages_per_rpc);
2075 int lprocfs_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *data)
2077 struct obd_device *dev = data;
2078 struct client_obd *cli = &dev->u.cli;
2081 spin_lock(&cli->cl_loi_list_lock);
2082 rc = seq_printf(m, "%d\n", cli->cl_max_pages_per_rpc);
2083 spin_unlock(&cli->cl_loi_list_lock);
2086 EXPORT_SYMBOL(lprocfs_obd_max_pages_per_rpc_seq_show);
2088 int lprocfs_wr_root_squash(const char __user *buffer, unsigned long count,
2089 struct root_squash_info *squash, char *name)
2092 char kernbuf[64], *tmp, *errmsg;
2093 unsigned long uid, gid;
2096 if (count >= sizeof(kernbuf)) {
2097 errmsg = "string too long";
2098 GOTO(failed_noprint, rc = -EINVAL);
2100 if (copy_from_user(kernbuf, buffer, count)) {
2101 errmsg = "bad address";
2102 GOTO(failed_noprint, rc = -EFAULT);
2104 kernbuf[count] = '\0';
2106 /* look for uid gid separator */
2107 tmp = strchr(kernbuf, ':');
2109 errmsg = "needs uid:gid format";
2110 GOTO(failed, rc = -EINVAL);
2116 if (kstrtoul(kernbuf, 0, &uid) != 0) {
2118 GOTO(failed, rc = -EINVAL);
2122 if (kstrtoul(tmp, 0, &gid) != 0) {
2124 GOTO(failed, rc = -EINVAL);
2127 squash->rsi_uid = uid;
2128 squash->rsi_gid = gid;
2130 LCONSOLE_INFO("%s: root_squash is set to %u:%u\n",
2131 name, squash->rsi_uid, squash->rsi_gid);
2139 CWARN("%s: failed to set root_squash to \"%s\", %s, rc = %d\n",
2140 name, kernbuf, errmsg, rc);
2143 CWARN("%s: failed to set root_squash due to %s, rc = %d\n",
2147 EXPORT_SYMBOL(lprocfs_wr_root_squash);
2150 int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count,
2151 struct root_squash_info *squash, char *name)
2154 char *kernbuf = NULL;
2156 struct list_head tmp;
2160 errmsg = "string too long";
2161 GOTO(failed, rc = -EINVAL);
2164 OBD_ALLOC(kernbuf, count + 1);
2165 if (kernbuf == NULL) {
2166 errmsg = "no memory";
2167 GOTO(failed, rc = -ENOMEM);
2169 if (copy_from_user(kernbuf, buffer, count)) {
2170 errmsg = "bad address";
2171 GOTO(failed, rc = -EFAULT);
2173 kernbuf[count] = '\0';
2175 if (count > 0 && kernbuf[count - 1] == '\n')
2176 kernbuf[count - 1] = '\0';
2178 if (strcmp(kernbuf, "NONE") == 0 || strcmp(kernbuf, "clear") == 0) {
2179 /* empty string is special case */
2180 down_write(&squash->rsi_sem);
2181 if (!list_empty(&squash->rsi_nosquash_nids))
2182 cfs_free_nidlist(&squash->rsi_nosquash_nids);
2183 up_write(&squash->rsi_sem);
2184 LCONSOLE_INFO("%s: nosquash_nids is cleared\n", name);
2185 OBD_FREE(kernbuf, count + 1);
2189 INIT_LIST_HEAD(&tmp);
2190 if (cfs_parse_nidlist(kernbuf, count, &tmp) <= 0) {
2191 errmsg = "can't parse";
2192 GOTO(failed, rc = -EINVAL);
2194 LCONSOLE_INFO("%s: nosquash_nids set to %s\n",
2196 OBD_FREE(kernbuf, count + 1);
2199 down_write(&squash->rsi_sem);
2200 if (!list_empty(&squash->rsi_nosquash_nids))
2201 cfs_free_nidlist(&squash->rsi_nosquash_nids);
2202 list_splice(&tmp, &squash->rsi_nosquash_nids);
2203 up_write(&squash->rsi_sem);
2209 CWARN("%s: failed to set nosquash_nids to \"%s\", %s rc = %d\n",
2210 name, kernbuf, errmsg, rc);
2211 OBD_FREE(kernbuf, count + 1);
2213 CWARN("%s: failed to set nosquash_nids due to %s rc = %d\n",
2218 EXPORT_SYMBOL(lprocfs_wr_nosquash_nids);
2220 #endif /* CONFIG_PROC_FS*/