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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/obdclass/lprocfs_status.c
34 * Author: Hariharan Thantry <thantry@users.sourceforge.net>
37 #define DEBUG_SUBSYSTEM S_CLASS
39 #include <obd_class.h>
40 #include <lprocfs_status.h>
44 static int lprocfs_no_percpu_stats = 0;
45 module_param(lprocfs_no_percpu_stats, int, 0644);
46 MODULE_PARM_DESC(lprocfs_no_percpu_stats, "Do not alloc percpu data for lprocfs stats");
48 #define MAX_STRING_SIZE 128
50 int lprocfs_single_release(struct inode *inode, struct file *file)
52 return single_release(inode, file);
54 EXPORT_SYMBOL(lprocfs_single_release);
56 int lprocfs_seq_release(struct inode *inode, struct file *file)
58 return seq_release(inode, file);
60 EXPORT_SYMBOL(lprocfs_seq_release);
62 struct dentry *ldebugfs_add_simple(struct dentry *root,
63 char *name, void *data,
64 const struct file_operations *fops)
69 if (!root || !name || !fops)
70 return ERR_PTR(-EINVAL);
76 entry = debugfs_create_file(name, mode, root, data, fops);
77 if (IS_ERR_OR_NULL(entry)) {
78 CERROR("LprocFS: No memory to create <debugfs> entry %s", name);
79 return entry ?: ERR_PTR(-ENOMEM);
83 EXPORT_SYMBOL(ldebugfs_add_simple);
85 struct proc_dir_entry *
86 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
87 void *data, const struct file_operations *fops)
89 struct proc_dir_entry *proc;
92 if (root == NULL || name == NULL || fops == NULL)
93 return ERR_PTR(-EINVAL);
99 proc = proc_create_data(name, mode, root, fops, data);
101 CERROR("LprocFS: No memory to create /proc entry %s\n",
103 return ERR_PTR(-ENOMEM);
107 EXPORT_SYMBOL(lprocfs_add_simple);
109 struct proc_dir_entry *lprocfs_add_symlink(const char *name,
110 struct proc_dir_entry *parent, const char *format, ...)
112 struct proc_dir_entry *entry;
116 if (parent == NULL || format == NULL)
119 OBD_ALLOC_WAIT(dest, MAX_STRING_SIZE + 1);
123 va_start(ap, format);
124 vsnprintf(dest, MAX_STRING_SIZE, format, ap);
127 entry = proc_symlink(name, parent, dest);
129 CERROR("LprocFS: Could not create symbolic link from "
130 "%s to %s\n", name, dest);
132 OBD_FREE(dest, MAX_STRING_SIZE + 1);
135 EXPORT_SYMBOL(lprocfs_add_symlink);
137 static const struct file_operations lprocfs_generic_fops = { };
139 int ldebugfs_add_vars(struct dentry *parent, struct lprocfs_vars *list,
142 if (IS_ERR_OR_NULL(parent) || IS_ERR_OR_NULL(list))
146 struct dentry *entry;
149 if (list->proc_mode != 0000) {
150 mode = list->proc_mode;
151 } else if (list->fops) {
152 if (list->fops->read)
154 if (list->fops->write)
157 entry = debugfs_create_file(list->name, mode, parent,
159 list->fops ? : &lprocfs_generic_fops);
160 if (IS_ERR_OR_NULL(entry))
161 return entry ? PTR_ERR(entry) : -ENOMEM;
166 EXPORT_SYMBOL_GPL(ldebugfs_add_vars);
171 * \param root [in] The parent proc entry on which new entry will be added.
172 * \param list [in] Array of proc entries to be added.
173 * \param data [in] The argument to be passed when entries read/write routines
174 * are called through /proc file.
176 * \retval 0 on success
180 lprocfs_add_vars(struct proc_dir_entry *root, struct lprocfs_vars *list,
183 if (root == NULL || list == NULL)
186 while (list->name != NULL) {
187 struct proc_dir_entry *proc;
190 if (list->proc_mode != 0000) {
191 mode = list->proc_mode;
192 } else if (list->fops) {
193 if (list->fops->read)
195 if (list->fops->write)
198 proc = proc_create_data(list->name, mode, root,
199 list->fops ?: &lprocfs_generic_fops,
207 EXPORT_SYMBOL(lprocfs_add_vars);
209 void ldebugfs_remove(struct dentry **entryp)
211 debugfs_remove_recursive(*entryp);
214 EXPORT_SYMBOL_GPL(ldebugfs_remove);
216 #ifndef HAVE_REMOVE_PROC_SUBTREE
217 /* for b=10866, global variable */
218 DECLARE_RWSEM(_lprocfs_lock);
219 EXPORT_SYMBOL(_lprocfs_lock);
221 static void lprocfs_remove_nolock(struct proc_dir_entry **proot)
223 struct proc_dir_entry *root = *proot;
224 struct proc_dir_entry *temp = root;
225 struct proc_dir_entry *rm_entry;
226 struct proc_dir_entry *parent;
229 if (root == NULL || IS_ERR(root))
232 parent = root->parent;
233 LASSERT(parent != NULL);
236 while (temp->subdir != NULL)
242 /* Memory corruption once caused this to fail, and
243 without this LASSERT we would loop here forever. */
244 LASSERTF(strlen(rm_entry->name) == rm_entry->namelen,
245 "0x%p %s/%s len %d\n", rm_entry, temp->name,
246 rm_entry->name, (int)strlen(rm_entry->name));
248 remove_proc_entry(rm_entry->name, temp);
254 int remove_proc_subtree(const char *name, struct proc_dir_entry *parent)
256 struct proc_dir_entry *t = NULL;
257 struct proc_dir_entry **p;
260 LASSERT(parent != NULL);
263 down_write(&_lprocfs_lock);
264 /* lookup target name */
265 for (p = &parent->subdir; *p; p = &(*p)->next) {
266 if ((*p)->namelen != len)
268 if (memcmp(name, (*p)->name, len))
275 /* verify it's empty: do not count "num_refs" */
276 for (p = &t->subdir; *p; p = &(*p)->next) {
277 if ((*p)->namelen != strlen("num_refs")) {
281 if (memcmp("num_refs", (*p)->name,
282 strlen("num_refs"))) {
290 lprocfs_remove_nolock(&t);
292 up_write(&_lprocfs_lock);
295 #endif /* !HAVE_REMOVE_PROC_SUBTREE */
297 #ifndef HAVE_PROC_REMOVE
298 void proc_remove(struct proc_dir_entry *de)
300 #ifndef HAVE_REMOVE_PROC_SUBTREE
301 down_write(&_lprocfs_lock); /* search vs remove race */
302 lprocfs_remove_nolock(&de);
303 up_write(&_lprocfs_lock);
306 remove_proc_subtree(de->name, de->parent);
311 void lprocfs_remove(struct proc_dir_entry **rooth)
316 EXPORT_SYMBOL(lprocfs_remove);
318 void lprocfs_remove_proc_entry(const char *name, struct proc_dir_entry *parent)
320 LASSERT(parent != NULL);
321 remove_proc_entry(name, parent);
323 EXPORT_SYMBOL(lprocfs_remove_proc_entry);
325 struct dentry *ldebugfs_register(const char *name, struct dentry *parent,
326 struct lprocfs_vars *list, void *data)
328 struct dentry *entry;
330 entry = debugfs_create_dir(name, parent);
331 if (IS_ERR_OR_NULL(entry)) {
332 entry = entry ?: ERR_PTR(-ENOMEM);
336 if (!IS_ERR_OR_NULL(list)) {
339 rc = ldebugfs_add_vars(entry, list, data);
341 debugfs_remove(entry);
348 EXPORT_SYMBOL_GPL(ldebugfs_register);
350 struct proc_dir_entry *
351 lprocfs_register(const char *name, struct proc_dir_entry *parent,
352 struct lprocfs_vars *list, void *data)
354 struct proc_dir_entry *newchild;
356 newchild = proc_mkdir(name, parent);
357 if (newchild == NULL)
358 return ERR_PTR(-ENOMEM);
361 int rc = lprocfs_add_vars(newchild, list, data);
363 lprocfs_remove(&newchild);
369 EXPORT_SYMBOL(lprocfs_register);
371 /* Generic callbacks */
372 int lprocfs_uuid_seq_show(struct seq_file *m, void *data)
374 struct obd_device *obd = data;
376 LASSERT(obd != NULL);
377 seq_printf(m, "%s\n", obd->obd_uuid.uuid);
380 EXPORT_SYMBOL(lprocfs_uuid_seq_show);
382 static ssize_t uuid_show(struct kobject *kobj, struct attribute *attr,
385 struct obd_device *obd = container_of(kobj, struct obd_device,
388 return sprintf(buf, "%s\n", obd->obd_uuid.uuid);
390 LUSTRE_RO_ATTR(uuid);
392 int lprocfs_name_seq_show(struct seq_file *m, void *data)
394 struct obd_device *dev = data;
396 LASSERT(dev != NULL);
397 seq_printf(m, "%s\n", dev->obd_name);
400 EXPORT_SYMBOL(lprocfs_name_seq_show);
402 static ssize_t blocksize_show(struct kobject *kobj, struct attribute *attr,
405 struct obd_device *obd = container_of(kobj, struct obd_device,
407 struct obd_statfs osfs;
410 rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
411 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
414 return sprintf(buf, "%u\n", osfs.os_bsize);
418 LUSTRE_RO_ATTR(blocksize);
420 static ssize_t kbytestotal_show(struct kobject *kobj, struct attribute *attr,
423 struct obd_device *obd = container_of(kobj, struct obd_device,
425 struct obd_statfs osfs;
428 rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
429 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
432 u32 blk_size = osfs.os_bsize >> 10;
433 u64 result = osfs.os_blocks;
435 while (blk_size >>= 1)
438 return sprintf(buf, "%llu\n", result);
443 LUSTRE_RO_ATTR(kbytestotal);
445 static ssize_t kbytesfree_show(struct kobject *kobj, struct attribute *attr,
448 struct obd_device *obd = container_of(kobj, struct obd_device,
450 struct obd_statfs osfs;
453 rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
454 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
457 u32 blk_size = osfs.os_bsize >> 10;
458 u64 result = osfs.os_bfree;
460 while (blk_size >>= 1)
463 return sprintf(buf, "%llu\n", result);
468 LUSTRE_RO_ATTR(kbytesfree);
470 static ssize_t kbytesavail_show(struct kobject *kobj, struct attribute *attr,
473 struct obd_device *obd = container_of(kobj, struct obd_device,
475 struct obd_statfs osfs;
478 rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
479 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
482 u32 blk_size = osfs.os_bsize >> 10;
483 u64 result = osfs.os_bavail;
485 while (blk_size >>= 1)
488 return sprintf(buf, "%llu\n", result);
493 LUSTRE_RO_ATTR(kbytesavail);
495 static ssize_t filestotal_show(struct kobject *kobj, struct attribute *attr,
498 struct obd_device *obd = container_of(kobj, struct obd_device,
500 struct obd_statfs osfs;
503 rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
504 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
507 return sprintf(buf, "%llu\n", osfs.os_files);
511 LUSTRE_RO_ATTR(filestotal);
513 static ssize_t filesfree_show(struct kobject *kobj, struct attribute *attr,
516 struct obd_device *obd = container_of(kobj, struct obd_device,
518 struct obd_statfs osfs;
521 rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
522 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
525 return sprintf(buf, "%llu\n", osfs.os_ffree);
529 LUSTRE_RO_ATTR(filesfree);
531 ssize_t conn_uuid_show(struct kobject *kobj, struct attribute *attr, char *buf)
533 struct obd_device *obd = container_of(kobj, struct obd_device,
535 struct ptlrpc_connection *conn;
538 LPROCFS_CLIMP_CHECK(obd);
539 conn = obd->u.cli.cl_import->imp_connection;
540 if (conn && obd->u.cli.cl_import)
541 count = sprintf(buf, "%s\n", conn->c_remote_uuid.uuid);
543 count = sprintf(buf, "%s\n", "<none>");
545 LPROCFS_CLIMP_EXIT(obd);
548 EXPORT_SYMBOL(conn_uuid_show);
550 int lprocfs_server_uuid_seq_show(struct seq_file *m, void *data)
552 struct obd_device *obd = data;
553 struct obd_import *imp;
554 char *imp_state_name = NULL;
557 LASSERT(obd != NULL);
558 LPROCFS_CLIMP_CHECK(obd);
559 imp = obd->u.cli.cl_import;
560 imp_state_name = ptlrpc_import_state_name(imp->imp_state);
561 seq_printf(m, "%s\t%s%s\n", obd2cli_tgt(obd), imp_state_name,
562 imp->imp_deactive ? "\tDEACTIVATED" : "");
564 LPROCFS_CLIMP_EXIT(obd);
567 EXPORT_SYMBOL(lprocfs_server_uuid_seq_show);
569 int lprocfs_conn_uuid_seq_show(struct seq_file *m, void *data)
571 struct obd_device *obd = data;
572 struct ptlrpc_connection *conn;
575 LASSERT(obd != NULL);
577 LPROCFS_CLIMP_CHECK(obd);
578 conn = obd->u.cli.cl_import->imp_connection;
579 if (conn && obd->u.cli.cl_import)
580 seq_printf(m, "%s\n", conn->c_remote_uuid.uuid);
582 seq_printf(m, "%s\n", "<none>");
584 LPROCFS_CLIMP_EXIT(obd);
587 EXPORT_SYMBOL(lprocfs_conn_uuid_seq_show);
589 /** add up per-cpu counters */
592 * Lock statistics structure for access, possibly only on this CPU.
594 * The statistics struct may be allocated with per-CPU structures for
595 * efficient concurrent update (usually only on server-wide stats), or
596 * as a single global struct (e.g. for per-client or per-job statistics),
597 * so the required locking depends on the type of structure allocated.
599 * For per-CPU statistics, pin the thread to the current cpuid so that
600 * will only access the statistics for that CPU. If the stats structure
601 * for the current CPU has not been allocated (or previously freed),
602 * allocate it now. The per-CPU statistics do not need locking since
603 * the thread is pinned to the CPU during update.
605 * For global statistics, lock the stats structure to prevent concurrent update.
607 * \param[in] stats statistics structure to lock
608 * \param[in] opc type of operation:
609 * LPROCFS_GET_SMP_ID: "lock" and return current CPU index
610 * for incrementing statistics for that CPU
611 * LPROCFS_GET_NUM_CPU: "lock" and return number of used
612 * CPU indices to iterate over all indices
613 * \param[out] flags CPU interrupt saved state for IRQ-safe locking
615 * \retval cpuid of current thread or number of allocated structs
616 * \retval negative on error (only for opc LPROCFS_GET_SMP_ID + per-CPU stats)
618 int lprocfs_stats_lock(struct lprocfs_stats *stats,
619 enum lprocfs_stats_lock_ops opc,
620 unsigned long *flags)
622 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
623 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
624 spin_lock_irqsave(&stats->ls_lock, *flags);
626 spin_lock(&stats->ls_lock);
627 return opc == LPROCFS_GET_NUM_CPU ? 1 : 0;
631 case LPROCFS_GET_SMP_ID: {
632 unsigned int cpuid = get_cpu();
634 if (unlikely(!stats->ls_percpu[cpuid])) {
635 int rc = lprocfs_stats_alloc_one(stats, cpuid);
644 case LPROCFS_GET_NUM_CPU:
645 return stats->ls_biggest_alloc_num;
652 * Unlock statistics structure after access.
654 * Unlock the lock acquired via lprocfs_stats_lock() for global statistics,
655 * or unpin this thread from the current cpuid for per-CPU statistics.
657 * This function must be called using the same arguments as used when calling
658 * lprocfs_stats_lock() so that the correct operation can be performed.
660 * \param[in] stats statistics structure to unlock
661 * \param[in] opc type of operation (current cpuid or number of structs)
662 * \param[in] flags CPU interrupt saved state for IRQ-safe locking
664 void lprocfs_stats_unlock(struct lprocfs_stats *stats,
665 enum lprocfs_stats_lock_ops opc,
666 unsigned long *flags)
668 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
669 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
670 spin_unlock_irqrestore(&stats->ls_lock, *flags);
672 spin_unlock(&stats->ls_lock);
673 } else if (opc == LPROCFS_GET_SMP_ID) {
678 /** add up per-cpu counters */
679 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
680 struct lprocfs_counter *cnt)
682 unsigned int num_entry;
683 struct lprocfs_counter *percpu_cntr;
685 unsigned long flags = 0;
687 memset(cnt, 0, sizeof(*cnt));
690 /* set count to 1 to avoid divide-by-zero errs in callers */
695 cnt->lc_min = LC_MIN_INIT;
697 num_entry = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
699 for (i = 0; i < num_entry; i++) {
700 if (stats->ls_percpu[i] == NULL)
702 percpu_cntr = lprocfs_stats_counter_get(stats, i, idx);
704 cnt->lc_count += percpu_cntr->lc_count;
705 cnt->lc_sum += percpu_cntr->lc_sum;
706 if (percpu_cntr->lc_min < cnt->lc_min)
707 cnt->lc_min = percpu_cntr->lc_min;
708 if (percpu_cntr->lc_max > cnt->lc_max)
709 cnt->lc_max = percpu_cntr->lc_max;
710 cnt->lc_sumsquare += percpu_cntr->lc_sumsquare;
713 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
716 static void obd_import_flags2str(struct obd_import *imp, struct seq_file *m)
720 if (imp->imp_obd->obd_no_recov) {
721 seq_printf(m, "no_recov");
725 flag2str(imp, invalid);
726 flag2str(imp, deactive);
727 flag2str(imp, replayable);
728 flag2str(imp, delayed_recovery);
729 flag2str(imp, vbr_failed);
730 flag2str(imp, pingable);
731 flag2str(imp, resend_replay);
732 flag2str(imp, no_pinger_recover);
733 flag2str(imp, connect_tried);
736 static const char *obd_connect_names[] = {
755 "remote_client_by_force",
764 "mds_mds_connection",
767 "alt_checksum_algorithm",
803 "file_secctx", /* 0x01 */
804 "lockaheadv2", /* 0x02 */
805 "dir_migrate", /* 0x04 */
806 "unknown", /* 0x08 */
807 "unknown", /* 0x10 */
810 "lock_convert", /* 0x80 */
811 "archive_id_array", /* 0x100 */
815 void obd_connect_seq_flags2str(struct seq_file *m, __u64 flags, __u64 flags2,
822 for (i = 0, mask = 1; i < 64; i++, mask <<= 1) {
824 seq_printf(m, "%s%s",
825 first ? "" : sep, obd_connect_names[i]);
830 if (flags & ~(mask - 1)) {
831 seq_printf(m, "%sunknown_%#llx",
832 first ? "" : sep, flags & ~(mask - 1));
836 if (!(flags & OBD_CONNECT_FLAGS2) || flags2 == 0)
839 for (i = 64, mask = 1; obd_connect_names[i] != NULL; i++, mask <<= 1) {
841 seq_printf(m, "%s%s",
842 first ? "" : sep, obd_connect_names[i]);
847 if (flags2 & ~(mask - 1)) {
848 seq_printf(m, "%sunknown2_%#llx",
849 first ? "" : sep, flags2 & ~(mask - 1));
853 EXPORT_SYMBOL(obd_connect_seq_flags2str);
855 int obd_connect_flags2str(char *page, int count, __u64 flags, __u64 flags2,
861 for (i = 0, mask = 1; i < 64; i++, mask <<= 1) {
863 ret += snprintf(page + ret, count - ret, "%s%s",
864 ret ? sep : "", obd_connect_names[i]);
867 if (flags & ~(mask - 1))
868 ret += snprintf(page + ret, count - ret,
870 ret ? sep : "", flags & ~(mask - 1));
872 if (!(flags & OBD_CONNECT_FLAGS2) || flags2 == 0)
875 for (i = 64, mask = 1; obd_connect_names[i] != NULL; i++, mask <<= 1) {
877 ret += snprintf(page + ret, count - ret, "%s%s",
878 ret ? sep : "", obd_connect_names[i]);
881 if (flags2 & ~(mask - 1))
882 ret += snprintf(page + ret, count - ret,
884 ret ? sep : "", flags2 & ~(mask - 1));
888 EXPORT_SYMBOL(obd_connect_flags2str);
891 obd_connect_data_seqprint(struct seq_file *m, struct obd_connect_data *ocd)
895 LASSERT(ocd != NULL);
896 flags = ocd->ocd_connect_flags;
898 seq_printf(m, " connect_data:\n"
901 ocd->ocd_connect_flags,
903 if (flags & OBD_CONNECT_VERSION)
904 seq_printf(m, " target_version: %u.%u.%u.%u\n",
905 OBD_OCD_VERSION_MAJOR(ocd->ocd_version),
906 OBD_OCD_VERSION_MINOR(ocd->ocd_version),
907 OBD_OCD_VERSION_PATCH(ocd->ocd_version),
908 OBD_OCD_VERSION_FIX(ocd->ocd_version));
909 if (flags & OBD_CONNECT_MDS)
910 seq_printf(m, " mdt_index: %d\n", ocd->ocd_group);
911 if (flags & OBD_CONNECT_GRANT)
912 seq_printf(m, " initial_grant: %d\n", ocd->ocd_grant);
913 if (flags & OBD_CONNECT_INDEX)
914 seq_printf(m, " target_index: %u\n", ocd->ocd_index);
915 if (flags & OBD_CONNECT_BRW_SIZE)
916 seq_printf(m, " max_brw_size: %d\n", ocd->ocd_brw_size);
917 if (flags & OBD_CONNECT_IBITS)
918 seq_printf(m, " ibits_known: %#llx\n",
919 ocd->ocd_ibits_known);
920 if (flags & OBD_CONNECT_GRANT_PARAM)
921 seq_printf(m, " grant_block_size: %d\n"
922 " grant_inode_size: %d\n"
923 " grant_max_extent_size: %d\n"
924 " grant_extent_tax: %d\n",
925 1 << ocd->ocd_grant_blkbits,
926 1 << ocd->ocd_grant_inobits,
927 ocd->ocd_grant_max_blks << ocd->ocd_grant_blkbits,
928 ocd->ocd_grant_tax_kb << 10);
929 if (flags & OBD_CONNECT_TRANSNO)
930 seq_printf(m, " first_transno: %#llx\n",
932 if (flags & OBD_CONNECT_CKSUM)
933 seq_printf(m, " cksum_types: %#x\n",
934 ocd->ocd_cksum_types);
935 if (flags & OBD_CONNECT_MAX_EASIZE)
936 seq_printf(m, " max_easize: %d\n", ocd->ocd_max_easize);
937 if (flags & OBD_CONNECT_MAXBYTES)
938 seq_printf(m, " max_object_bytes: %llu\n",
940 if (flags & OBD_CONNECT_MULTIMODRPCS)
941 seq_printf(m, " max_mod_rpcs: %hu\n",
942 ocd->ocd_maxmodrpcs);
945 int lprocfs_import_seq_show(struct seq_file *m, void *data)
947 char nidstr[LNET_NIDSTR_SIZE];
948 struct lprocfs_counter ret;
949 struct lprocfs_counter_header *header;
950 struct obd_device *obd = (struct obd_device *)data;
951 struct obd_import *imp;
952 struct obd_import_conn *conn;
953 struct obd_connect_data *ocd;
958 LASSERT(obd != NULL);
959 LPROCFS_CLIMP_CHECK(obd);
960 imp = obd->u.cli.cl_import;
961 ocd = &imp->imp_connect_data;
963 seq_printf(m, "import:\n"
967 " connect_flags: [ ",
970 ptlrpc_import_state_name(imp->imp_state));
971 obd_connect_seq_flags2str(m, imp->imp_connect_data.ocd_connect_flags,
972 imp->imp_connect_data.ocd_connect_flags2,
974 seq_printf(m, " ]\n");
975 obd_connect_data_seqprint(m, ocd);
976 seq_printf(m, " import_flags: [ ");
977 obd_import_flags2str(imp, m);
981 " failover_nids: [ ");
982 spin_lock(&imp->imp_lock);
984 list_for_each_entry(conn, &imp->imp_conn_list, oic_item) {
985 libcfs_nid2str_r(conn->oic_conn->c_peer.nid,
986 nidstr, sizeof(nidstr));
987 seq_printf(m, "%s%s", j ? ", " : "", nidstr);
990 if (imp->imp_connection != NULL)
991 libcfs_nid2str_r(imp->imp_connection->c_peer.nid,
992 nidstr, sizeof(nidstr));
994 strncpy(nidstr, "<none>", sizeof(nidstr));
996 " current_connection: %s\n"
997 " connection_attempts: %u\n"
999 " in-progress_invalidations: %u\n"
1000 " idle: %lld sec\n",
1003 imp->imp_generation,
1004 atomic_read(&imp->imp_inval_count),
1005 ktime_get_real_seconds() - imp->imp_last_reply_time);
1006 spin_unlock(&imp->imp_lock);
1008 if (obd->obd_svc_stats == NULL)
1011 header = &obd->obd_svc_stats->ls_cnt_header[PTLRPC_REQWAIT_CNTR];
1012 lprocfs_stats_collect(obd->obd_svc_stats, PTLRPC_REQWAIT_CNTR, &ret);
1013 if (ret.lc_count != 0) {
1014 /* first argument to do_div MUST be __u64 */
1015 __u64 sum = ret.lc_sum;
1016 do_div(sum, ret.lc_count);
1020 seq_printf(m, " rpcs:\n"
1022 " unregistering: %u\n"
1024 " avg_waittime: %llu %s\n",
1025 atomic_read(&imp->imp_inflight),
1026 atomic_read(&imp->imp_unregistering),
1027 atomic_read(&imp->imp_timeouts),
1028 ret.lc_sum, header->lc_units);
1031 for(j = 0; j < IMP_AT_MAX_PORTALS; j++) {
1032 if (imp->imp_at.iat_portal[j] == 0)
1034 k = max_t(unsigned int, k,
1035 at_get(&imp->imp_at.iat_service_estimate[j]));
1037 seq_printf(m, " service_estimates:\n"
1038 " services: %u sec\n"
1039 " network: %u sec\n",
1041 at_get(&imp->imp_at.iat_net_latency));
1043 seq_printf(m, " transactions:\n"
1044 " last_replay: %llu\n"
1045 " peer_committed: %llu\n"
1046 " last_checked: %llu\n",
1047 imp->imp_last_replay_transno,
1048 imp->imp_peer_committed_transno,
1049 imp->imp_last_transno_checked);
1051 /* avg data rates */
1052 for (rw = 0; rw <= 1; rw++) {
1053 lprocfs_stats_collect(obd->obd_svc_stats,
1054 PTLRPC_LAST_CNTR + BRW_READ_BYTES + rw,
1056 if (ret.lc_sum > 0 && ret.lc_count > 0) {
1057 /* first argument to do_div MUST be __u64 */
1058 __u64 sum = ret.lc_sum;
1059 do_div(sum, ret.lc_count);
1061 seq_printf(m, " %s_data_averages:\n"
1062 " bytes_per_rpc: %llu\n",
1063 rw ? "write" : "read",
1066 k = (int)ret.lc_sum;
1067 j = opcode_offset(OST_READ + rw) + EXTRA_MAX_OPCODES;
1068 header = &obd->obd_svc_stats->ls_cnt_header[j];
1069 lprocfs_stats_collect(obd->obd_svc_stats, j, &ret);
1070 if (ret.lc_sum > 0 && ret.lc_count != 0) {
1071 /* first argument to do_div MUST be __u64 */
1072 __u64 sum = ret.lc_sum;
1073 do_div(sum, ret.lc_count);
1075 seq_printf(m, " %s_per_rpc: %llu\n",
1076 header->lc_units, ret.lc_sum);
1077 j = (int)ret.lc_sum;
1079 seq_printf(m, " MB_per_sec: %u.%.02u\n",
1080 k / j, (100 * k / j) % 100);
1085 LPROCFS_CLIMP_EXIT(obd);
1088 EXPORT_SYMBOL(lprocfs_import_seq_show);
1090 int lprocfs_state_seq_show(struct seq_file *m, void *data)
1092 struct obd_device *obd = (struct obd_device *)data;
1093 struct obd_import *imp;
1096 LASSERT(obd != NULL);
1097 LPROCFS_CLIMP_CHECK(obd);
1098 imp = obd->u.cli.cl_import;
1100 seq_printf(m, "current_state: %s\n",
1101 ptlrpc_import_state_name(imp->imp_state));
1102 seq_printf(m, "state_history:\n");
1103 k = imp->imp_state_hist_idx;
1104 for (j = 0; j < IMP_STATE_HIST_LEN; j++) {
1105 struct import_state_hist *ish =
1106 &imp->imp_state_hist[(k + j) % IMP_STATE_HIST_LEN];
1107 if (ish->ish_state == 0)
1109 seq_printf(m, " - [ %lld, %s ]\n", (s64)ish->ish_time,
1110 ptlrpc_import_state_name(ish->ish_state));
1113 LPROCFS_CLIMP_EXIT(obd);
1116 EXPORT_SYMBOL(lprocfs_state_seq_show);
1118 int lprocfs_at_hist_helper(struct seq_file *m, struct adaptive_timeout *at)
1121 for (i = 0; i < AT_BINS; i++)
1122 seq_printf(m, "%3u ", at->at_hist[i]);
1123 seq_printf(m, "\n");
1126 EXPORT_SYMBOL(lprocfs_at_hist_helper);
1128 /* See also ptlrpc_lprocfs_timeouts_show_seq */
1129 int lprocfs_timeouts_seq_show(struct seq_file *m, void *data)
1131 struct obd_device *obd = (struct obd_device *)data;
1132 struct obd_import *imp;
1133 unsigned int cur, worst;
1134 time64_t now, worstt;
1137 LASSERT(obd != NULL);
1138 LPROCFS_CLIMP_CHECK(obd);
1139 imp = obd->u.cli.cl_import;
1141 now = ktime_get_real_seconds();
1143 /* Some network health info for kicks */
1144 seq_printf(m, "%-10s : %lld, %llds ago\n",
1145 "last reply", (s64)imp->imp_last_reply_time,
1146 (s64)(now - imp->imp_last_reply_time));
1148 cur = at_get(&imp->imp_at.iat_net_latency);
1149 worst = imp->imp_at.iat_net_latency.at_worst_ever;
1150 worstt = imp->imp_at.iat_net_latency.at_worst_time;
1151 seq_printf(m, "%-10s : cur %3u worst %3u (at %lld, %llds ago) ",
1152 "network", cur, worst, (s64)worstt, (s64)(now - worstt));
1153 lprocfs_at_hist_helper(m, &imp->imp_at.iat_net_latency);
1155 for(i = 0; i < IMP_AT_MAX_PORTALS; i++) {
1156 if (imp->imp_at.iat_portal[i] == 0)
1158 cur = at_get(&imp->imp_at.iat_service_estimate[i]);
1159 worst = imp->imp_at.iat_service_estimate[i].at_worst_ever;
1160 worstt = imp->imp_at.iat_service_estimate[i].at_worst_time;
1161 seq_printf(m, "portal %-2d : cur %3u worst %3u (at %lld, %llds ago) ",
1162 imp->imp_at.iat_portal[i], cur, worst, (s64)worstt,
1163 (s64)(now - worstt));
1164 lprocfs_at_hist_helper(m, &imp->imp_at.iat_service_estimate[i]);
1167 LPROCFS_CLIMP_EXIT(obd);
1170 EXPORT_SYMBOL(lprocfs_timeouts_seq_show);
1172 int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data)
1174 struct obd_device *obd = data;
1178 LPROCFS_CLIMP_CHECK(obd);
1179 flags = obd->u.cli.cl_import->imp_connect_data.ocd_connect_flags;
1180 flags2 = obd->u.cli.cl_import->imp_connect_data.ocd_connect_flags2;
1181 seq_printf(m, "flags=%#llx\n", flags);
1182 seq_printf(m, "flags2=%#llx\n", flags2);
1183 obd_connect_seq_flags2str(m, flags, flags2, "\n");
1184 seq_printf(m, "\n");
1185 LPROCFS_CLIMP_EXIT(obd);
1188 EXPORT_SYMBOL(lprocfs_connect_flags_seq_show);
1190 static const struct attribute *obd_def_uuid_attrs[] = {
1191 &lustre_attr_uuid.attr,
1195 static const struct attribute *obd_def_attrs[] = {
1196 &lustre_attr_blocksize.attr,
1197 &lustre_attr_kbytestotal.attr,
1198 &lustre_attr_kbytesfree.attr,
1199 &lustre_attr_kbytesavail.attr,
1200 &lustre_attr_filestotal.attr,
1201 &lustre_attr_filesfree.attr,
1202 &lustre_attr_uuid.attr,
1206 static void obd_sysfs_release(struct kobject *kobj)
1208 struct obd_device *obd = container_of(kobj, struct obd_device,
1211 complete(&obd->obd_kobj_unregister);
1214 int lprocfs_obd_setup(struct obd_device *obd, bool uuid_only)
1216 struct lprocfs_vars *debugfs_vars = NULL;
1219 if (!obd || obd->obd_magic != OBD_DEVICE_MAGIC)
1222 rc = kobject_set_name(&obd->obd_kset.kobj, "%s", obd->obd_name);
1226 obd->obd_ktype.sysfs_ops = &lustre_sysfs_ops;
1227 obd->obd_ktype.release = obd_sysfs_release;
1229 obd->obd_kset.kobj.parent = obd->obd_type->typ_kobj;
1230 obd->obd_kset.kobj.ktype = &obd->obd_ktype;
1231 init_completion(&obd->obd_kobj_unregister);
1232 rc = kset_register(&obd->obd_kset);
1237 obd->obd_attrs = obd_def_uuid_attrs;
1239 obd->obd_attrs = obd_def_attrs;
1241 rc = sysfs_create_files(&obd->obd_kset.kobj, obd->obd_attrs);
1243 kset_unregister(&obd->obd_kset);
1247 if (!obd->obd_type->typ_procroot)
1248 debugfs_vars = obd->obd_vars;
1249 obd->obd_debugfs_entry = ldebugfs_register(obd->obd_name,
1250 obd->obd_type->typ_debugfs_entry,
1252 if (IS_ERR_OR_NULL(obd->obd_debugfs_entry)) {
1253 rc = obd->obd_debugfs_entry ? PTR_ERR(obd->obd_debugfs_entry)
1255 CERROR("error %d setting up debugfs for %s\n",
1257 obd->obd_debugfs_entry = NULL;
1259 sysfs_remove_files(&obd->obd_kset.kobj, obd->obd_attrs);
1260 obd->obd_attrs = NULL;
1261 kset_unregister(&obd->obd_kset);
1265 if (obd->obd_proc_entry || !obd->obd_type->typ_procroot)
1266 GOTO(already_registered, rc);
1268 obd->obd_proc_entry = lprocfs_register(obd->obd_name,
1269 obd->obd_type->typ_procroot,
1270 obd->obd_vars, obd);
1271 if (IS_ERR(obd->obd_proc_entry)) {
1272 rc = PTR_ERR(obd->obd_proc_entry);
1273 CERROR("error %d setting up lprocfs for %s\n",rc,obd->obd_name);
1274 obd->obd_proc_entry = NULL;
1276 ldebugfs_remove(&obd->obd_debugfs_entry);
1277 sysfs_remove_files(&obd->obd_kset.kobj, obd->obd_attrs);
1278 obd->obd_attrs = NULL;
1279 kset_unregister(&obd->obd_kset);
1285 EXPORT_SYMBOL(lprocfs_obd_setup);
1287 int lprocfs_obd_cleanup(struct obd_device *obd)
1292 if (obd->obd_proc_exports_entry) {
1293 /* Should be no exports left */
1294 lprocfs_remove(&obd->obd_proc_exports_entry);
1295 obd->obd_proc_exports_entry = NULL;
1298 if (obd->obd_proc_entry) {
1299 lprocfs_remove(&obd->obd_proc_entry);
1300 obd->obd_proc_entry = NULL;
1303 if (!IS_ERR_OR_NULL(obd->obd_debugfs_entry))
1304 ldebugfs_remove(&obd->obd_debugfs_entry);
1306 /* obd device never allocated a kset */
1307 if (!obd->obd_kset.kobj.state_initialized)
1310 if (obd->obd_attrs) {
1311 sysfs_remove_files(&obd->obd_kset.kobj, obd->obd_attrs);
1312 obd->obd_attrs = NULL;
1315 kset_unregister(&obd->obd_kset);
1316 wait_for_completion(&obd->obd_kobj_unregister);
1319 EXPORT_SYMBOL(lprocfs_obd_cleanup);
1321 int lprocfs_stats_alloc_one(struct lprocfs_stats *stats, unsigned int cpuid)
1323 struct lprocfs_counter *cntr;
1324 unsigned int percpusize;
1326 unsigned long flags = 0;
1329 LASSERT(stats->ls_percpu[cpuid] == NULL);
1330 LASSERT((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0);
1332 percpusize = lprocfs_stats_counter_size(stats);
1333 LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[cpuid], percpusize);
1334 if (stats->ls_percpu[cpuid] != NULL) {
1336 if (unlikely(stats->ls_biggest_alloc_num <= cpuid)) {
1337 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
1338 spin_lock_irqsave(&stats->ls_lock, flags);
1340 spin_lock(&stats->ls_lock);
1341 if (stats->ls_biggest_alloc_num <= cpuid)
1342 stats->ls_biggest_alloc_num = cpuid + 1;
1343 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) {
1344 spin_unlock_irqrestore(&stats->ls_lock, flags);
1346 spin_unlock(&stats->ls_lock);
1349 /* initialize the ls_percpu[cpuid] non-zero counter */
1350 for (i = 0; i < stats->ls_num; ++i) {
1351 cntr = lprocfs_stats_counter_get(stats, cpuid, i);
1352 cntr->lc_min = LC_MIN_INIT;
1358 struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num,
1359 enum lprocfs_stats_flags flags)
1361 struct lprocfs_stats *stats;
1362 unsigned int num_entry;
1363 unsigned int percpusize = 0;
1369 if (lprocfs_no_percpu_stats != 0)
1370 flags |= LPROCFS_STATS_FLAG_NOPERCPU;
1372 if (flags & LPROCFS_STATS_FLAG_NOPERCPU)
1375 num_entry = num_possible_cpus();
1377 /* alloc percpu pointers for all possible cpu slots */
1378 LIBCFS_ALLOC(stats, offsetof(typeof(*stats), ls_percpu[num_entry]));
1382 stats->ls_num = num;
1383 stats->ls_flags = flags;
1384 spin_lock_init(&stats->ls_lock);
1386 /* alloc num of counter headers */
1387 LIBCFS_ALLOC(stats->ls_cnt_header,
1388 stats->ls_num * sizeof(struct lprocfs_counter_header));
1389 if (stats->ls_cnt_header == NULL)
1392 if ((flags & LPROCFS_STATS_FLAG_NOPERCPU) != 0) {
1393 /* contains only one set counters */
1394 percpusize = lprocfs_stats_counter_size(stats);
1395 LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[0], percpusize);
1396 if (stats->ls_percpu[0] == NULL)
1398 stats->ls_biggest_alloc_num = 1;
1399 } else if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0) {
1400 /* alloc all percpu data, currently only obd_memory use this */
1401 for (i = 0; i < num_entry; ++i)
1402 if (lprocfs_stats_alloc_one(stats, i) < 0)
1409 lprocfs_free_stats(&stats);
1412 EXPORT_SYMBOL(lprocfs_alloc_stats);
1414 void lprocfs_free_stats(struct lprocfs_stats **statsh)
1416 struct lprocfs_stats *stats = *statsh;
1417 unsigned int num_entry;
1418 unsigned int percpusize;
1421 if (stats == NULL || stats->ls_num == 0)
1425 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU)
1428 num_entry = num_possible_cpus();
1430 percpusize = lprocfs_stats_counter_size(stats);
1431 for (i = 0; i < num_entry; i++)
1432 if (stats->ls_percpu[i] != NULL)
1433 LIBCFS_FREE(stats->ls_percpu[i], percpusize);
1434 if (stats->ls_cnt_header != NULL)
1435 LIBCFS_FREE(stats->ls_cnt_header, stats->ls_num *
1436 sizeof(struct lprocfs_counter_header));
1437 LIBCFS_FREE(stats, offsetof(typeof(*stats), ls_percpu[num_entry]));
1439 EXPORT_SYMBOL(lprocfs_free_stats);
1441 u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
1442 enum lprocfs_fields_flags field)
1444 unsigned long flags = 0;
1445 unsigned int num_cpu;
1451 num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1452 for (i = 0; i < num_cpu; i++) {
1453 struct lprocfs_counter *cntr;
1455 if (!stats->ls_percpu[i])
1458 cntr = lprocfs_stats_counter_get(stats, i, idx);
1459 ret += lprocfs_read_helper(cntr, &stats->ls_cnt_header[idx],
1460 stats->ls_flags, field);
1462 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1465 EXPORT_SYMBOL(lprocfs_stats_collector);
1467 void lprocfs_clear_stats(struct lprocfs_stats *stats)
1469 struct lprocfs_counter *percpu_cntr;
1472 unsigned int num_entry;
1473 unsigned long flags = 0;
1475 num_entry = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1477 for (i = 0; i < num_entry; i++) {
1478 if (stats->ls_percpu[i] == NULL)
1480 for (j = 0; j < stats->ls_num; j++) {
1481 percpu_cntr = lprocfs_stats_counter_get(stats, i, j);
1482 percpu_cntr->lc_count = 0;
1483 percpu_cntr->lc_min = LC_MIN_INIT;
1484 percpu_cntr->lc_max = 0;
1485 percpu_cntr->lc_sumsquare = 0;
1486 percpu_cntr->lc_sum = 0;
1487 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
1488 percpu_cntr->lc_sum_irq = 0;
1492 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1494 EXPORT_SYMBOL(lprocfs_clear_stats);
1496 static ssize_t lprocfs_stats_seq_write(struct file *file,
1497 const char __user *buf,
1498 size_t len, loff_t *off)
1500 struct seq_file *seq = file->private_data;
1501 struct lprocfs_stats *stats = seq->private;
1503 lprocfs_clear_stats(stats);
1508 static void *lprocfs_stats_seq_start(struct seq_file *p, loff_t *pos)
1510 struct lprocfs_stats *stats = p->private;
1512 return (*pos < stats->ls_num) ? pos : NULL;
1515 static void lprocfs_stats_seq_stop(struct seq_file *p, void *v)
1519 static void *lprocfs_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
1523 return lprocfs_stats_seq_start(p, pos);
1526 /* seq file export of one lprocfs counter */
1527 static int lprocfs_stats_seq_show(struct seq_file *p, void *v)
1529 struct lprocfs_stats *stats = p->private;
1530 struct lprocfs_counter_header *hdr;
1531 struct lprocfs_counter ctr;
1532 int idx = *(loff_t *)v;
1535 struct timespec64 now;
1537 ktime_get_real_ts64(&now);
1538 seq_printf(p, "%-25s %llu.%09lu secs.nsecs\n",
1539 "snapshot_time", (s64)now.tv_sec, now.tv_nsec);
1542 hdr = &stats->ls_cnt_header[idx];
1543 lprocfs_stats_collect(stats, idx, &ctr);
1545 if (ctr.lc_count == 0)
1548 seq_printf(p, "%-25s %lld samples [%s]", hdr->lc_name,
1549 ctr.lc_count, hdr->lc_units);
1551 if ((hdr->lc_config & LPROCFS_CNTR_AVGMINMAX) && ctr.lc_count > 0) {
1552 seq_printf(p, " %lld %lld %lld",
1553 ctr.lc_min, ctr.lc_max, ctr.lc_sum);
1554 if (hdr->lc_config & LPROCFS_CNTR_STDDEV)
1555 seq_printf(p, " %llu", ctr.lc_sumsquare);
1561 static const struct seq_operations lprocfs_stats_seq_sops = {
1562 .start = lprocfs_stats_seq_start,
1563 .stop = lprocfs_stats_seq_stop,
1564 .next = lprocfs_stats_seq_next,
1565 .show = lprocfs_stats_seq_show,
1568 static int lprocfs_stats_seq_open(struct inode *inode, struct file *file)
1570 struct seq_file *seq;
1573 rc = LPROCFS_ENTRY_CHECK(inode);
1577 rc = seq_open(file, &lprocfs_stats_seq_sops);
1580 seq = file->private_data;
1581 seq->private = inode->i_private ? inode->i_private : PDE_DATA(inode);
1585 static const struct file_operations lprocfs_stats_seq_fops = {
1586 .owner = THIS_MODULE,
1587 .open = lprocfs_stats_seq_open,
1589 .write = lprocfs_stats_seq_write,
1590 .llseek = seq_lseek,
1591 .release = lprocfs_seq_release,
1594 int ldebugfs_register_stats(struct dentry *parent, const char *name,
1595 struct lprocfs_stats *stats)
1597 struct dentry *entry;
1599 LASSERT(!IS_ERR_OR_NULL(parent));
1601 entry = debugfs_create_file(name, 0644, parent, stats,
1602 &lprocfs_stats_seq_fops);
1603 if (IS_ERR_OR_NULL(entry))
1604 return entry ? PTR_ERR(entry) : -ENOMEM;
1608 EXPORT_SYMBOL_GPL(ldebugfs_register_stats);
1610 int lprocfs_register_stats(struct proc_dir_entry *root, const char *name,
1611 struct lprocfs_stats *stats)
1613 struct proc_dir_entry *entry;
1614 LASSERT(root != NULL);
1616 entry = proc_create_data(name, 0644, root,
1617 &lprocfs_stats_seq_fops, stats);
1622 EXPORT_SYMBOL(lprocfs_register_stats);
1624 void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
1625 unsigned conf, const char *name, const char *units)
1627 struct lprocfs_counter_header *header;
1628 struct lprocfs_counter *percpu_cntr;
1629 unsigned long flags = 0;
1631 unsigned int num_cpu;
1633 LASSERT(stats != NULL);
1635 header = &stats->ls_cnt_header[index];
1636 LASSERTF(header != NULL, "Failed to allocate stats header:[%d]%s/%s\n",
1637 index, name, units);
1639 header->lc_config = conf;
1640 header->lc_name = name;
1641 header->lc_units = units;
1643 num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1644 for (i = 0; i < num_cpu; ++i) {
1645 if (stats->ls_percpu[i] == NULL)
1647 percpu_cntr = lprocfs_stats_counter_get(stats, i, index);
1648 percpu_cntr->lc_count = 0;
1649 percpu_cntr->lc_min = LC_MIN_INIT;
1650 percpu_cntr->lc_max = 0;
1651 percpu_cntr->lc_sumsquare = 0;
1652 percpu_cntr->lc_sum = 0;
1653 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
1654 percpu_cntr->lc_sum_irq = 0;
1656 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1658 EXPORT_SYMBOL(lprocfs_counter_init);
1660 static const char * const mps_stats[] = {
1661 [LPROC_MD_CLOSE] = "close",
1662 [LPROC_MD_CREATE] = "create",
1663 [LPROC_MD_ENQUEUE] = "enqueue",
1664 [LPROC_MD_GETATTR] = "getattr",
1665 [LPROC_MD_INTENT_LOCK] = "intent_lock",
1666 [LPROC_MD_LINK] = "link",
1667 [LPROC_MD_RENAME] = "rename",
1668 [LPROC_MD_SETATTR] = "setattr",
1669 [LPROC_MD_FSYNC] = "fsync",
1670 [LPROC_MD_READ_PAGE] = "read_page",
1671 [LPROC_MD_UNLINK] = "unlink",
1672 [LPROC_MD_SETXATTR] = "setxattr",
1673 [LPROC_MD_GETXATTR] = "getxattr",
1674 [LPROC_MD_INTENT_GETATTR_ASYNC] = "intent_getattr_async",
1675 [LPROC_MD_REVALIDATE_LOCK] = "revalidate_lock",
1678 int lprocfs_alloc_md_stats(struct obd_device *obd,
1679 unsigned int num_private_stats)
1681 struct lprocfs_stats *stats;
1682 unsigned int num_stats;
1685 /* TODO Ensure that this function is only used where
1686 * appropriate by adding an assertion to the effect that
1687 * obd->obd_type->typ_md_ops is not NULL. We can't do this now
1688 * because mdt_procfs_init() uses this function to allocate
1689 * the stats backing /proc/fs/lustre/mdt/.../md_stats but the
1690 * mdt layer does not use the md_ops interface. This is
1691 * confusing and a waste of memory. See LU-2484.
1693 LASSERT(obd->obd_proc_entry != NULL);
1694 LASSERT(obd->obd_md_stats == NULL);
1696 num_stats = ARRAY_SIZE(mps_stats) + num_private_stats;
1697 stats = lprocfs_alloc_stats(num_stats, 0);
1701 for (i = 0; i < ARRAY_SIZE(mps_stats); i++) {
1702 lprocfs_counter_init(stats, i, 0, mps_stats[i], "reqs");
1703 if (!stats->ls_cnt_header[i].lc_name) {
1704 CERROR("Missing md_stat initializer md_op operation at offset %d. Aborting.\n",
1710 rc = lprocfs_register_stats(obd->obd_proc_entry, "md_stats", stats);
1712 lprocfs_free_stats(&stats);
1714 obd->obd_md_stats = stats;
1719 EXPORT_SYMBOL(lprocfs_alloc_md_stats);
1721 void lprocfs_free_md_stats(struct obd_device *obd)
1723 struct lprocfs_stats *stats = obd->obd_md_stats;
1725 if (stats != NULL) {
1726 obd->obd_md_stats = NULL;
1727 lprocfs_free_stats(&stats);
1730 EXPORT_SYMBOL(lprocfs_free_md_stats);
1732 void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
1734 lprocfs_counter_init(ldlm_stats,
1735 LDLM_ENQUEUE - LDLM_FIRST_OPC,
1736 0, "ldlm_enqueue", "reqs");
1737 lprocfs_counter_init(ldlm_stats,
1738 LDLM_CONVERT - LDLM_FIRST_OPC,
1739 0, "ldlm_convert", "reqs");
1740 lprocfs_counter_init(ldlm_stats,
1741 LDLM_CANCEL - LDLM_FIRST_OPC,
1742 0, "ldlm_cancel", "reqs");
1743 lprocfs_counter_init(ldlm_stats,
1744 LDLM_BL_CALLBACK - LDLM_FIRST_OPC,
1745 0, "ldlm_bl_callback", "reqs");
1746 lprocfs_counter_init(ldlm_stats,
1747 LDLM_CP_CALLBACK - LDLM_FIRST_OPC,
1748 0, "ldlm_cp_callback", "reqs");
1749 lprocfs_counter_init(ldlm_stats,
1750 LDLM_GL_CALLBACK - LDLM_FIRST_OPC,
1751 0, "ldlm_gl_callback", "reqs");
1753 EXPORT_SYMBOL(lprocfs_init_ldlm_stats);
1755 __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
1756 struct lprocfs_counter_header *header,
1757 enum lprocfs_stats_flags flags,
1758 enum lprocfs_fields_flags field)
1762 if (lc == NULL || header == NULL)
1766 case LPROCFS_FIELDS_FLAGS_CONFIG:
1767 ret = header->lc_config;
1769 case LPROCFS_FIELDS_FLAGS_SUM:
1771 if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
1772 ret += lc->lc_sum_irq;
1774 case LPROCFS_FIELDS_FLAGS_MIN:
1777 case LPROCFS_FIELDS_FLAGS_MAX:
1780 case LPROCFS_FIELDS_FLAGS_AVG:
1781 ret = (lc->lc_max - lc->lc_min) / 2;
1783 case LPROCFS_FIELDS_FLAGS_SUMSQUARE:
1784 ret = lc->lc_sumsquare;
1786 case LPROCFS_FIELDS_FLAGS_COUNT:
1794 EXPORT_SYMBOL(lprocfs_read_helper);
1796 int lprocfs_read_frac_helper(char *buffer, unsigned long count, long val,
1799 long decimal_val, frac_val;
1805 decimal_val = val / mult;
1806 prtn = snprintf(buffer, count, "%ld", decimal_val);
1807 frac_val = val % mult;
1809 if (prtn < (count - 4) && frac_val > 0) {
1811 int i, temp_mult = 1, frac_bits = 0;
1813 temp_frac = frac_val * 10;
1814 buffer[prtn++] = '.';
1815 while (frac_bits < 2 && (temp_frac / mult) < 1 ) {
1816 /* only reserved 2 bits fraction */
1817 buffer[prtn++] ='0';
1822 * Need to think these cases :
1823 * 1. #echo x.00 > /proc/xxx output result : x
1824 * 2. #echo x.0x > /proc/xxx output result : x.0x
1825 * 3. #echo x.x0 > /proc/xxx output result : x.x
1826 * 4. #echo x.xx > /proc/xxx output result : x.xx
1827 * Only reserved 2 bits fraction.
1829 for (i = 0; i < (5 - prtn); i++)
1832 frac_bits = min((int)count - prtn, 3 - frac_bits);
1833 prtn += snprintf(buffer + prtn, frac_bits, "%ld",
1834 frac_val * temp_mult / mult);
1837 while(buffer[prtn] < '1' || buffer[prtn] > '9') {
1839 if (buffer[prtn] == '.') {
1846 buffer[prtn++] ='\n';
1849 EXPORT_SYMBOL(lprocfs_read_frac_helper);
1851 int lprocfs_seq_read_frac_helper(struct seq_file *m, long val, int mult)
1853 long decimal_val, frac_val;
1855 decimal_val = val / mult;
1856 seq_printf(m, "%ld", decimal_val);
1857 frac_val = val % mult;
1864 /* Three cases: x0, xx, 0x */
1865 if ((frac_val % 10) != 0)
1866 seq_printf(m, ".%ld", frac_val);
1868 seq_printf(m, ".%ld", frac_val / 10);
1871 seq_printf(m, "\n");
1874 EXPORT_SYMBOL(lprocfs_seq_read_frac_helper);
1876 /* Obtains the conversion factor for the unit specified */
1877 static int get_mult(char unit, __u64 *mult)
1882 /* peta, tera, giga, mega, and kilo */
1899 /* some tests expect % to be accepted */
1913 * Ensures the numeric string is valid. The function provides the final
1914 * multiplier in the case a unit exists at the end of the string. It also
1915 * locates the start of the whole and fractional parts (if any). This
1916 * function modifies the string so kstrtoull can be used to parse both
1917 * the whole and fraction portions. This function also figures out
1918 * the base of the number.
1920 static int preprocess_numeric_str(char *buffer, __u64 *mult, __u64 def_mult,
1921 bool allow_units, char **whole, char **frac,
1924 bool hit_decimal = false;
1925 bool hit_unit = false;
1933 /* a hex string if it starts with "0x" */
1934 if (buffer[0] == '0' && tolower(buffer[1]) == 'x') {
1942 /* allow for a single new line before the null terminator */
1943 if (*buffer == '\n') {
1953 /* any chars after our unit indicates a malformed string */
1957 /* ensure we only hit one decimal */
1958 if (*buffer == '.') {
1962 /* if past start, there's a whole part */
1963 if (start != buffer)
1969 } else if (!isdigit(*buffer) &&
1970 !(*base == 16 && isxdigit(*buffer))) {
1972 /* if we allow units, attempt to get mult */
1974 rc = get_mult(*buffer, mult);
1978 /* string stops here, but keep processing */
1990 /* hit a decimal, make sure there's a fractional part */
1996 /* didn't hit a decimal, but may have a whole part */
1997 if (start != buffer && *start)
2001 /* malformed string if we didn't get anything */
2002 if (!*frac && !*whole)
2009 * Parses a numeric string which can contain a whole and fraction portion
2010 * into a __u64. Accepts a multiplier to apply to the value parsed. Also
2011 * allows the string to have a unit at the end. The function handles
2012 * wrapping of the final unsigned value.
2014 static int str_to_u64_parse(char *buffer, unsigned long count,
2015 __u64 *val, __u64 def_mult, bool allow_units)
2019 unsigned int frac_d = 1;
2020 __u64 wrap_indicator = ULLONG_MAX;
2025 unsigned int base = 10;
2027 rc = preprocess_numeric_str(buffer, &mult, def_mult, allow_units,
2028 &strwhole, &strfrac, &base);
2038 /* the multiplier limits how large the value can be */
2039 wrap_indicator = div64_u64(wrap_indicator, mult);
2042 rc = kstrtoull(strwhole, base, &whole);
2046 if (whole > wrap_indicator)
2053 if (strlen(strfrac) > 10)
2056 rc = kstrtoull(strfrac, base, &frac);
2060 /* determine power of fractional portion */
2066 /* fractional portion is too large to perform calculation */
2067 if (frac > wrap_indicator)
2071 do_div(frac, frac_d);
2074 /* check that the sum of whole and fraction fits in u64 */
2075 if (whole > (ULLONG_MAX - frac))
2078 *val = whole + frac;
2084 * This function parses numeric/hex strings into __s64. It accepts a multiplier
2085 * which will apply to the value parsed. It also can allow the string to
2086 * have a unit as the last character. The function handles overflow/underflow
2087 * of the signed integer.
2089 static int str_to_s64_internal(const char __user *buffer, unsigned long count,
2090 __s64 *val, __u64 def_mult, bool allow_units)
2094 unsigned int offset = 0;
2095 int signed sign = 1;
2096 __u64 max = LLONG_MAX;
2099 if (count > (sizeof(kernbuf) - 1))
2102 if (copy_from_user(kernbuf, buffer, count))
2105 kernbuf[count] = '\0';
2107 /* keep track of our sign */
2108 if (*kernbuf == '-') {
2111 /* equivalent to max = -LLONG_MIN, avoids overflow */
2115 rc = str_to_u64_parse(kernbuf + offset, count - offset,
2116 &tmp, def_mult, allow_units);
2120 /* check for overflow/underflow */
2124 *val = (__s64)tmp * sign;
2130 * Convert a user string into a signed 64 bit number. This function produces
2131 * an error when the value parsed from the string times multiplier underflows or
2132 * overflows. This function only accepts strings that contains digits, an
2133 * optional decimal, and a char representing a unit at the end. If a unit is
2134 * specified in the string, the multiplier provided by the caller is ignored.
2135 * This function can also accept hexadecimal strings which are prefixed with
2138 * \param[in] buffer string consisting of numbers, a decimal, and a unit
2139 * \param[in] count buffer length
2140 * \param[in] val if successful, the value represented by the string
2141 * \param[in] defunit default unit if string doesn't contain one
2143 * \retval 0 on success
2144 * \retval negative number on error
2146 int lprocfs_str_with_units_to_s64(const char __user *buffer,
2147 unsigned long count, __s64 *val, char defunit)
2152 if (defunit != '1') {
2153 rc = get_mult(defunit, &mult);
2158 return str_to_s64_internal(buffer, count, val, mult, true);
2160 EXPORT_SYMBOL(lprocfs_str_with_units_to_s64);
2162 char *lprocfs_strnstr(const char *s1, const char *s2, size_t len)
2171 if (!memcmp(s1, s2, l2))
2177 EXPORT_SYMBOL(lprocfs_strnstr);
2180 * Find the string \a name in the input \a buffer, and return a pointer to the
2181 * value immediately following \a name, reducing \a count appropriately.
2182 * If \a name is not found the original \a buffer is returned.
2184 char *lprocfs_find_named_value(const char *buffer, const char *name,
2188 size_t buflen = *count;
2190 /* there is no strnstr() in rhel5 and ubuntu kernels */
2191 val = lprocfs_strnstr(buffer, name, buflen);
2193 return (char *)buffer;
2195 val += strlen(name); /* skip prefix */
2196 while (val < buffer + buflen && isspace(*val)) /* skip separator */
2200 while (val < buffer + buflen && isalnum(*val)) {
2205 return val - *count;
2207 EXPORT_SYMBOL(lprocfs_find_named_value);
2209 int ldebugfs_seq_create(struct dentry *parent, const char *name, umode_t mode,
2210 const struct file_operations *seq_fops, void *data)
2212 struct dentry *entry;
2214 /* Disallow secretly (un)writable entries. */
2215 LASSERT((!seq_fops->write) == (!(mode & 0222)));
2217 entry = debugfs_create_file(name, mode, parent, data, seq_fops);
2218 if (IS_ERR_OR_NULL(entry))
2219 return entry ? PTR_ERR(entry) : -ENOMEM;
2223 EXPORT_SYMBOL_GPL(ldebugfs_seq_create);
2225 int lprocfs_seq_create(struct proc_dir_entry *parent,
2228 const struct file_operations *seq_fops,
2231 struct proc_dir_entry *entry;
2234 /* Disallow secretly (un)writable entries. */
2235 LASSERT((seq_fops->write == NULL) == ((mode & 0222) == 0));
2237 entry = proc_create_data(name, mode, parent, seq_fops, data);
2244 EXPORT_SYMBOL(lprocfs_seq_create);
2246 int lprocfs_obd_seq_create(struct obd_device *dev,
2249 const struct file_operations *seq_fops,
2252 return (lprocfs_seq_create(dev->obd_proc_entry, name,
2253 mode, seq_fops, data));
2255 EXPORT_SYMBOL(lprocfs_obd_seq_create);
2257 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
2259 if (value >= OBD_HIST_MAX)
2260 value = OBD_HIST_MAX - 1;
2262 spin_lock(&oh->oh_lock);
2263 oh->oh_buckets[value]++;
2264 spin_unlock(&oh->oh_lock);
2266 EXPORT_SYMBOL(lprocfs_oh_tally);
2268 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
2270 unsigned int val = 0;
2272 if (likely(value != 0))
2273 val = min(fls(value - 1), OBD_HIST_MAX);
2275 lprocfs_oh_tally(oh, val);
2277 EXPORT_SYMBOL(lprocfs_oh_tally_log2);
2279 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
2281 unsigned long ret = 0;
2284 for (i = 0; i < OBD_HIST_MAX; i++)
2285 ret += oh->oh_buckets[i];
2288 EXPORT_SYMBOL(lprocfs_oh_sum);
2290 void lprocfs_oh_clear(struct obd_histogram *oh)
2292 spin_lock(&oh->oh_lock);
2293 memset(oh->oh_buckets, 0, sizeof(oh->oh_buckets));
2294 spin_unlock(&oh->oh_lock);
2296 EXPORT_SYMBOL(lprocfs_oh_clear);
2298 ssize_t lustre_attr_show(struct kobject *kobj,
2299 struct attribute *attr, char *buf)
2301 struct lustre_attr *a = container_of(attr, struct lustre_attr, attr);
2303 return a->show ? a->show(kobj, attr, buf) : 0;
2305 EXPORT_SYMBOL_GPL(lustre_attr_show);
2307 ssize_t lustre_attr_store(struct kobject *kobj, struct attribute *attr,
2308 const char *buf, size_t len)
2310 struct lustre_attr *a = container_of(attr, struct lustre_attr, attr);
2312 return a->store ? a->store(kobj, attr, buf, len) : len;
2314 EXPORT_SYMBOL_GPL(lustre_attr_store);
2316 const struct sysfs_ops lustre_sysfs_ops = {
2317 .show = lustre_attr_show,
2318 .store = lustre_attr_store,
2320 EXPORT_SYMBOL_GPL(lustre_sysfs_ops);
2322 int lprocfs_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *data)
2324 struct obd_device *dev = data;
2325 struct client_obd *cli = &dev->u.cli;
2327 spin_lock(&cli->cl_loi_list_lock);
2328 seq_printf(m, "%d\n", cli->cl_max_pages_per_rpc);
2329 spin_unlock(&cli->cl_loi_list_lock);
2332 EXPORT_SYMBOL(lprocfs_obd_max_pages_per_rpc_seq_show);
2334 ssize_t lprocfs_obd_max_pages_per_rpc_seq_write(struct file *file,
2335 const char __user *buffer,
2336 size_t count, loff_t *off)
2338 struct obd_device *dev =
2339 ((struct seq_file *)file->private_data)->private;
2340 struct client_obd *cli = &dev->u.cli;
2341 struct obd_connect_data *ocd = &cli->cl_import->imp_connect_data;
2345 rc = lprocfs_str_with_units_to_s64(buffer, count, &val, '1');
2351 /* if the max_pages is specified in bytes, convert to pages */
2352 if (val >= ONE_MB_BRW_SIZE)
2355 LPROCFS_CLIMP_CHECK(dev);
2357 chunk_mask = ~((1 << (cli->cl_chunkbits - PAGE_SHIFT)) - 1);
2358 /* max_pages_per_rpc must be chunk aligned */
2359 val = (val + ~chunk_mask) & chunk_mask;
2360 if (val == 0 || (ocd->ocd_brw_size != 0 &&
2361 val > ocd->ocd_brw_size >> PAGE_SHIFT)) {
2362 LPROCFS_CLIMP_EXIT(dev);
2365 spin_lock(&cli->cl_loi_list_lock);
2366 cli->cl_max_pages_per_rpc = val;
2367 client_adjust_max_dirty(cli);
2368 spin_unlock(&cli->cl_loi_list_lock);
2370 LPROCFS_CLIMP_EXIT(dev);
2373 EXPORT_SYMBOL(lprocfs_obd_max_pages_per_rpc_seq_write);
2375 ssize_t short_io_bytes_show(struct kobject *kobj, struct attribute *attr,
2378 struct obd_device *dev = container_of(kobj, struct obd_device,
2380 struct client_obd *cli = &dev->u.cli;
2383 spin_lock(&cli->cl_loi_list_lock);
2384 rc = sprintf(buf, "%d\n", cli->cl_short_io_bytes);
2385 spin_unlock(&cli->cl_loi_list_lock);
2388 EXPORT_SYMBOL(short_io_bytes_show);
2390 /* Used to catch people who think they're specifying pages. */
2391 #define MIN_SHORT_IO_BYTES 64
2393 ssize_t short_io_bytes_store(struct kobject *kobj, struct attribute *attr,
2394 const char *buffer, size_t count)
2396 struct obd_device *dev = container_of(kobj, struct obd_device,
2398 struct client_obd *cli = &dev->u.cli;
2402 LPROCFS_CLIMP_CHECK(dev);
2404 rc = kstrtouint(buffer, 0, &val);
2408 if (val < MIN_SHORT_IO_BYTES || val > OBD_MAX_SHORT_IO_BYTES)
2409 GOTO(out, rc = -ERANGE);
2413 spin_lock(&cli->cl_loi_list_lock);
2414 if (val > (cli->cl_max_pages_per_rpc << PAGE_SHIFT))
2417 cli->cl_short_io_bytes = val;
2418 spin_unlock(&cli->cl_loi_list_lock);
2421 LPROCFS_CLIMP_EXIT(dev);
2424 EXPORT_SYMBOL(short_io_bytes_store);
2426 int lprocfs_wr_root_squash(const char __user *buffer, unsigned long count,
2427 struct root_squash_info *squash, char *name)
2430 char kernbuf[64], *tmp, *errmsg;
2431 unsigned long uid, gid;
2434 if (count >= sizeof(kernbuf)) {
2435 errmsg = "string too long";
2436 GOTO(failed_noprint, rc = -EINVAL);
2438 if (copy_from_user(kernbuf, buffer, count)) {
2439 errmsg = "bad address";
2440 GOTO(failed_noprint, rc = -EFAULT);
2442 kernbuf[count] = '\0';
2444 /* look for uid gid separator */
2445 tmp = strchr(kernbuf, ':');
2447 errmsg = "needs uid:gid format";
2448 GOTO(failed, rc = -EINVAL);
2454 if (kstrtoul(kernbuf, 0, &uid) != 0) {
2456 GOTO(failed, rc = -EINVAL);
2460 if (kstrtoul(tmp, 0, &gid) != 0) {
2462 GOTO(failed, rc = -EINVAL);
2465 squash->rsi_uid = uid;
2466 squash->rsi_gid = gid;
2468 LCONSOLE_INFO("%s: root_squash is set to %u:%u\n",
2469 name, squash->rsi_uid, squash->rsi_gid);
2477 CWARN("%s: failed to set root_squash to \"%s\", %s, rc = %d\n",
2478 name, kernbuf, errmsg, rc);
2481 CWARN("%s: failed to set root_squash due to %s, rc = %d\n",
2485 EXPORT_SYMBOL(lprocfs_wr_root_squash);
2488 int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count,
2489 struct root_squash_info *squash, char *name)
2492 char *kernbuf = NULL;
2494 struct list_head tmp;
2499 errmsg = "string too long";
2500 GOTO(failed, rc = -EINVAL);
2503 OBD_ALLOC(kernbuf, count + 1);
2504 if (kernbuf == NULL) {
2505 errmsg = "no memory";
2506 GOTO(failed, rc = -ENOMEM);
2508 if (copy_from_user(kernbuf, buffer, count)) {
2509 errmsg = "bad address";
2510 GOTO(failed, rc = -EFAULT);
2512 kernbuf[count] = '\0';
2514 if (count > 0 && kernbuf[count - 1] == '\n')
2517 if ((len == 4 && strncmp(kernbuf, "NONE", len) == 0) ||
2518 (len == 5 && strncmp(kernbuf, "clear", len) == 0)) {
2519 /* empty string is special case */
2520 down_write(&squash->rsi_sem);
2521 if (!list_empty(&squash->rsi_nosquash_nids))
2522 cfs_free_nidlist(&squash->rsi_nosquash_nids);
2523 up_write(&squash->rsi_sem);
2524 LCONSOLE_INFO("%s: nosquash_nids is cleared\n", name);
2525 OBD_FREE(kernbuf, count + 1);
2529 INIT_LIST_HEAD(&tmp);
2530 if (cfs_parse_nidlist(kernbuf, count, &tmp) <= 0) {
2531 errmsg = "can't parse";
2532 GOTO(failed, rc = -EINVAL);
2534 LCONSOLE_INFO("%s: nosquash_nids set to %s\n",
2536 OBD_FREE(kernbuf, count + 1);
2539 down_write(&squash->rsi_sem);
2540 if (!list_empty(&squash->rsi_nosquash_nids))
2541 cfs_free_nidlist(&squash->rsi_nosquash_nids);
2542 list_splice(&tmp, &squash->rsi_nosquash_nids);
2543 up_write(&squash->rsi_sem);
2549 CWARN("%s: failed to set nosquash_nids to \"%s\", %s rc = %d\n",
2550 name, kernbuf, errmsg, rc);
2551 OBD_FREE(kernbuf, count + 1);
2553 CWARN("%s: failed to set nosquash_nids due to %s rc = %d\n",
2558 EXPORT_SYMBOL(lprocfs_wr_nosquash_nids);
2560 #endif /* CONFIG_PROC_FS*/