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 || !name || !fops)
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,
111 const char *format, ...)
113 struct proc_dir_entry *entry;
117 if (!parent || !format)
120 OBD_ALLOC_WAIT(dest, MAX_STRING_SIZE + 1);
124 va_start(ap, format);
125 vsnprintf(dest, MAX_STRING_SIZE, format, ap);
128 entry = proc_symlink(name, parent, dest);
130 CERROR("LprocFS: Could not create symbolic link from "
131 "%s to %s\n", name, dest);
133 OBD_FREE(dest, MAX_STRING_SIZE + 1);
136 EXPORT_SYMBOL(lprocfs_add_symlink);
138 static const struct file_operations lprocfs_generic_fops = { };
140 int ldebugfs_add_vars(struct dentry *parent, struct lprocfs_vars *list,
143 if (IS_ERR_OR_NULL(parent) || IS_ERR_OR_NULL(list))
147 struct dentry *entry;
150 if (list->proc_mode != 0000) {
151 mode = list->proc_mode;
152 } else if (list->fops) {
153 if (list->fops->read)
155 if (list->fops->write)
158 entry = debugfs_create_file(list->name, mode, parent,
160 list->fops ? : &lprocfs_generic_fops);
161 if (IS_ERR_OR_NULL(entry))
162 return entry ? PTR_ERR(entry) : -ENOMEM;
167 EXPORT_SYMBOL_GPL(ldebugfs_add_vars);
172 * \param root [in] The parent proc entry on which new entry will be added.
173 * \param list [in] Array of proc entries to be added.
174 * \param data [in] The argument to be passed when entries read/write routines
175 * are called through /proc file.
177 * \retval 0 on success
181 lprocfs_add_vars(struct proc_dir_entry *root, struct lprocfs_vars *list,
188 struct proc_dir_entry *proc;
191 if (list->proc_mode != 0000) {
192 mode = list->proc_mode;
193 } else if (list->fops) {
194 if (list->fops->read)
196 if (list->fops->write)
199 proc = proc_create_data(list->name, mode, root,
200 list->fops ?: &lprocfs_generic_fops,
208 EXPORT_SYMBOL(lprocfs_add_vars);
210 #ifndef HAVE_REMOVE_PROC_SUBTREE
211 /* for b=10866, global variable */
212 DECLARE_RWSEM(_lprocfs_lock);
213 EXPORT_SYMBOL(_lprocfs_lock);
215 static void lprocfs_remove_nolock(struct proc_dir_entry **proot)
217 struct proc_dir_entry *root = *proot;
218 struct proc_dir_entry *temp = root;
219 struct proc_dir_entry *rm_entry;
220 struct proc_dir_entry *parent;
223 if (!root || IS_ERR(root))
226 parent = root->parent;
227 LASSERT(parent != NULL);
237 * Memory corruption once caused this to fail, and
238 * without this LASSERT we would loop here forever.
240 LASSERTF(strlen(rm_entry->name) == rm_entry->namelen,
241 "0x%p %s/%s len %d\n", rm_entry, temp->name,
242 rm_entry->name, (int)strlen(rm_entry->name));
244 remove_proc_entry(rm_entry->name, temp);
250 int remove_proc_subtree(const char *name, struct proc_dir_entry *parent)
252 struct proc_dir_entry *t = NULL;
253 struct proc_dir_entry **p;
256 LASSERT(parent != NULL);
259 down_write(&_lprocfs_lock);
260 /* lookup target name */
261 for (p = &parent->subdir; *p; p = &(*p)->next) {
262 if ((*p)->namelen != len)
264 if (memcmp(name, (*p)->name, len))
271 /* verify it's empty: do not count "num_refs" */
272 for (p = &t->subdir; *p; p = &(*p)->next) {
273 if ((*p)->namelen != strlen("num_refs")) {
277 if (memcmp("num_refs", (*p)->name,
278 strlen("num_refs"))) {
286 lprocfs_remove_nolock(&t);
288 up_write(&_lprocfs_lock);
291 #endif /* !HAVE_REMOVE_PROC_SUBTREE */
293 #ifndef HAVE_PROC_REMOVE
294 void proc_remove(struct proc_dir_entry *de)
296 #ifndef HAVE_REMOVE_PROC_SUBTREE
297 down_write(&_lprocfs_lock); /* search vs remove race */
298 lprocfs_remove_nolock(&de);
299 up_write(&_lprocfs_lock);
302 remove_proc_subtree(de->name, de->parent);
307 void lprocfs_remove(struct proc_dir_entry **rooth)
312 EXPORT_SYMBOL(lprocfs_remove);
314 void lprocfs_remove_proc_entry(const char *name, struct proc_dir_entry *parent)
316 LASSERT(parent != NULL);
317 remove_proc_entry(name, parent);
319 EXPORT_SYMBOL(lprocfs_remove_proc_entry);
321 struct dentry *ldebugfs_register(const char *name, struct dentry *parent,
322 struct lprocfs_vars *list, void *data)
324 struct dentry *entry;
326 entry = debugfs_create_dir(name, parent);
327 if (IS_ERR_OR_NULL(entry)) {
328 entry = entry ?: ERR_PTR(-ENOMEM);
332 if (!IS_ERR_OR_NULL(list)) {
335 rc = ldebugfs_add_vars(entry, list, data);
337 debugfs_remove(entry);
344 EXPORT_SYMBOL_GPL(ldebugfs_register);
346 struct proc_dir_entry *
347 lprocfs_register(const char *name, struct proc_dir_entry *parent,
348 struct lprocfs_vars *list, void *data)
350 struct proc_dir_entry *newchild;
352 newchild = proc_mkdir(name, parent);
354 return ERR_PTR(-ENOMEM);
357 int rc = lprocfs_add_vars(newchild, list, data);
359 lprocfs_remove(&newchild);
365 EXPORT_SYMBOL(lprocfs_register);
367 /* Generic callbacks */
368 int lprocfs_uuid_seq_show(struct seq_file *m, void *data)
370 struct obd_device *obd = data;
372 LASSERT(obd != NULL);
373 seq_printf(m, "%s\n", obd->obd_uuid.uuid);
376 EXPORT_SYMBOL(lprocfs_uuid_seq_show);
378 static ssize_t uuid_show(struct kobject *kobj, struct attribute *attr,
381 struct obd_device *obd = container_of(kobj, struct obd_device,
384 return sprintf(buf, "%s\n", obd->obd_uuid.uuid);
386 LUSTRE_RO_ATTR(uuid);
388 static ssize_t blocksize_show(struct kobject *kobj, struct attribute *attr,
391 struct obd_device *obd = container_of(kobj, struct obd_device,
393 struct obd_statfs osfs;
396 rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
397 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
400 return sprintf(buf, "%u\n", osfs.os_bsize);
404 LUSTRE_RO_ATTR(blocksize);
406 static ssize_t kbytestotal_show(struct kobject *kobj, struct attribute *attr,
409 struct obd_device *obd = container_of(kobj, struct obd_device,
411 struct obd_statfs osfs;
414 rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
415 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
418 u32 blk_size = osfs.os_bsize >> 10;
419 u64 result = osfs.os_blocks;
421 result *= rounddown_pow_of_two(blk_size ?: 1);
422 return sprintf(buf, "%llu\n", result);
427 LUSTRE_RO_ATTR(kbytestotal);
429 static ssize_t kbytesfree_show(struct kobject *kobj, struct attribute *attr,
432 struct obd_device *obd = container_of(kobj, struct obd_device,
434 struct obd_statfs osfs;
437 rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
438 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
441 u32 blk_size = osfs.os_bsize >> 10;
442 u64 result = osfs.os_bfree;
444 while (blk_size >>= 1)
447 return sprintf(buf, "%llu\n", result);
452 LUSTRE_RO_ATTR(kbytesfree);
454 static ssize_t kbytesavail_show(struct kobject *kobj, struct attribute *attr,
457 struct obd_device *obd = container_of(kobj, struct obd_device,
459 struct obd_statfs osfs;
462 rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
463 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
466 u32 blk_size = osfs.os_bsize >> 10;
467 u64 result = osfs.os_bavail;
469 while (blk_size >>= 1)
472 return sprintf(buf, "%llu\n", result);
477 LUSTRE_RO_ATTR(kbytesavail);
479 static ssize_t filestotal_show(struct kobject *kobj, struct attribute *attr,
482 struct obd_device *obd = container_of(kobj, struct obd_device,
484 struct obd_statfs osfs;
487 rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
488 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
491 return sprintf(buf, "%llu\n", osfs.os_files);
495 LUSTRE_RO_ATTR(filestotal);
497 static ssize_t filesfree_show(struct kobject *kobj, struct attribute *attr,
500 struct obd_device *obd = container_of(kobj, struct obd_device,
502 struct obd_statfs osfs;
505 rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
506 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
509 return sprintf(buf, "%llu\n", osfs.os_ffree);
513 LUSTRE_RO_ATTR(filesfree);
515 ssize_t conn_uuid_show(struct kobject *kobj, struct attribute *attr, char *buf)
517 struct obd_device *obd = container_of(kobj, struct obd_device,
519 struct ptlrpc_connection *conn;
522 LPROCFS_CLIMP_CHECK(obd);
523 conn = obd->u.cli.cl_import->imp_connection;
524 if (conn && obd->u.cli.cl_import)
525 count = sprintf(buf, "%s\n", conn->c_remote_uuid.uuid);
527 count = sprintf(buf, "%s\n", "<none>");
529 LPROCFS_CLIMP_EXIT(obd);
532 EXPORT_SYMBOL(conn_uuid_show);
534 int lprocfs_server_uuid_seq_show(struct seq_file *m, void *data)
536 struct obd_device *obd = data;
537 struct obd_import *imp;
538 char *imp_state_name = NULL;
541 LASSERT(obd != NULL);
542 LPROCFS_CLIMP_CHECK(obd);
543 imp = obd->u.cli.cl_import;
544 imp_state_name = ptlrpc_import_state_name(imp->imp_state);
545 seq_printf(m, "%s\t%s%s\n", obd2cli_tgt(obd), imp_state_name,
546 imp->imp_deactive ? "\tDEACTIVATED" : "");
548 LPROCFS_CLIMP_EXIT(obd);
551 EXPORT_SYMBOL(lprocfs_server_uuid_seq_show);
553 /** add up per-cpu counters */
556 * Lock statistics structure for access, possibly only on this CPU.
558 * The statistics struct may be allocated with per-CPU structures for
559 * efficient concurrent update (usually only on server-wide stats), or
560 * as a single global struct (e.g. for per-client or per-job statistics),
561 * so the required locking depends on the type of structure allocated.
563 * For per-CPU statistics, pin the thread to the current cpuid so that
564 * will only access the statistics for that CPU. If the stats structure
565 * for the current CPU has not been allocated (or previously freed),
566 * allocate it now. The per-CPU statistics do not need locking since
567 * the thread is pinned to the CPU during update.
569 * For global statistics, lock the stats structure to prevent concurrent update.
571 * \param[in] stats statistics structure to lock
572 * \param[in] opc type of operation:
573 * LPROCFS_GET_SMP_ID: "lock" and return current CPU index
574 * for incrementing statistics for that CPU
575 * LPROCFS_GET_NUM_CPU: "lock" and return number of used
576 * CPU indices to iterate over all indices
577 * \param[out] flags CPU interrupt saved state for IRQ-safe locking
579 * \retval cpuid of current thread or number of allocated structs
580 * \retval negative on error (only for opc LPROCFS_GET_SMP_ID + per-CPU stats)
582 int lprocfs_stats_lock(struct lprocfs_stats *stats,
583 enum lprocfs_stats_lock_ops opc,
584 unsigned long *flags)
586 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
587 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
588 spin_lock_irqsave(&stats->ls_lock, *flags);
590 spin_lock(&stats->ls_lock);
591 return opc == LPROCFS_GET_NUM_CPU ? 1 : 0;
595 case LPROCFS_GET_SMP_ID: {
596 unsigned int cpuid = get_cpu();
598 if (unlikely(!stats->ls_percpu[cpuid])) {
599 int rc = lprocfs_stats_alloc_one(stats, cpuid);
608 case LPROCFS_GET_NUM_CPU:
609 return stats->ls_biggest_alloc_num;
616 * Unlock statistics structure after access.
618 * Unlock the lock acquired via lprocfs_stats_lock() for global statistics,
619 * or unpin this thread from the current cpuid for per-CPU statistics.
621 * This function must be called using the same arguments as used when calling
622 * lprocfs_stats_lock() so that the correct operation can be performed.
624 * \param[in] stats statistics structure to unlock
625 * \param[in] opc type of operation (current cpuid or number of structs)
626 * \param[in] flags CPU interrupt saved state for IRQ-safe locking
628 void lprocfs_stats_unlock(struct lprocfs_stats *stats,
629 enum lprocfs_stats_lock_ops opc,
630 unsigned long *flags)
632 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
633 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
634 spin_unlock_irqrestore(&stats->ls_lock, *flags);
636 spin_unlock(&stats->ls_lock);
637 } else if (opc == LPROCFS_GET_SMP_ID) {
642 /** add up per-cpu counters */
643 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
644 struct lprocfs_counter *cnt)
646 unsigned int num_entry;
647 struct lprocfs_counter *percpu_cntr;
649 unsigned long flags = 0;
651 memset(cnt, 0, sizeof(*cnt));
654 /* set count to 1 to avoid divide-by-zero errs in callers */
659 cnt->lc_min = LC_MIN_INIT;
661 num_entry = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
663 for (i = 0; i < num_entry; i++) {
664 if (!stats->ls_percpu[i])
666 percpu_cntr = lprocfs_stats_counter_get(stats, i, idx);
668 cnt->lc_count += percpu_cntr->lc_count;
669 cnt->lc_sum += percpu_cntr->lc_sum;
670 if (percpu_cntr->lc_min < cnt->lc_min)
671 cnt->lc_min = percpu_cntr->lc_min;
672 if (percpu_cntr->lc_max > cnt->lc_max)
673 cnt->lc_max = percpu_cntr->lc_max;
674 cnt->lc_sumsquare += percpu_cntr->lc_sumsquare;
677 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
680 static void obd_import_flags2str(struct obd_import *imp, struct seq_file *m)
684 if (imp->imp_obd->obd_no_recov) {
685 seq_printf(m, "no_recov");
689 flag2str(imp, invalid);
690 flag2str(imp, deactive);
691 flag2str(imp, replayable);
692 flag2str(imp, delayed_recovery);
693 flag2str(imp, vbr_failed);
694 flag2str(imp, pingable);
695 flag2str(imp, resend_replay);
696 flag2str(imp, no_pinger_recover);
697 flag2str(imp, connect_tried);
700 static const char *obd_connect_names[] = {
719 "remote_client_by_force",
728 "mds_mds_connection",
731 "alt_checksum_algorithm",
767 "file_secctx", /* 0x01 */
768 "lockaheadv2", /* 0x02 */
769 "dir_migrate", /* 0x04 */
770 "sum_statfs", /* 0x08 */
771 "overstriping", /* 0x10 */
774 "lock_convert", /* 0x80 */
775 "archive_id_array", /* 0x100 */
776 "increasing_xid", /* 0x200 */
777 "selinux_policy", /* 0x400 */
780 "crush", /* 0x2000 */
781 "async_discard", /* 0x4000 */
782 "client_encryption", /* 0x8000 */
786 void obd_connect_seq_flags2str(struct seq_file *m, __u64 flags, __u64 flags2,
793 for (i = 0, mask = 1; i < 64; i++, mask <<= 1) {
795 seq_printf(m, "%s%s",
796 first ? "" : sep, obd_connect_names[i]);
801 if (flags & ~(mask - 1)) {
802 seq_printf(m, "%sunknown_%#llx",
803 first ? "" : sep, flags & ~(mask - 1));
807 if (!(flags & OBD_CONNECT_FLAGS2) || flags2 == 0)
810 for (i = 64, mask = 1; obd_connect_names[i] != NULL; i++, mask <<= 1) {
812 seq_printf(m, "%s%s",
813 first ? "" : sep, obd_connect_names[i]);
818 if (flags2 & ~(mask - 1)) {
819 seq_printf(m, "%sunknown2_%#llx",
820 first ? "" : sep, flags2 & ~(mask - 1));
824 EXPORT_SYMBOL(obd_connect_seq_flags2str);
826 int obd_connect_flags2str(char *page, int count, __u64 flags, __u64 flags2,
832 for (i = 0, mask = 1; i < 64; i++, mask <<= 1) {
834 ret += snprintf(page + ret, count - ret, "%s%s",
835 ret ? sep : "", obd_connect_names[i]);
838 if (flags & ~(mask - 1))
839 ret += snprintf(page + ret, count - ret,
841 ret ? sep : "", flags & ~(mask - 1));
843 if (!(flags & OBD_CONNECT_FLAGS2) || flags2 == 0)
846 for (i = 64, mask = 1; obd_connect_names[i] != NULL; i++, mask <<= 1) {
848 ret += snprintf(page + ret, count - ret, "%s%s",
849 ret ? sep : "", obd_connect_names[i]);
852 if (flags2 & ~(mask - 1))
853 ret += snprintf(page + ret, count - ret,
855 ret ? sep : "", flags2 & ~(mask - 1));
859 EXPORT_SYMBOL(obd_connect_flags2str);
862 obd_connect_data_seqprint(struct seq_file *m, struct obd_connect_data *ocd)
866 LASSERT(ocd != NULL);
867 flags = ocd->ocd_connect_flags;
869 seq_printf(m, " connect_data:\n"
872 ocd->ocd_connect_flags,
874 if (flags & OBD_CONNECT_VERSION)
875 seq_printf(m, " target_version: %u.%u.%u.%u\n",
876 OBD_OCD_VERSION_MAJOR(ocd->ocd_version),
877 OBD_OCD_VERSION_MINOR(ocd->ocd_version),
878 OBD_OCD_VERSION_PATCH(ocd->ocd_version),
879 OBD_OCD_VERSION_FIX(ocd->ocd_version));
880 if (flags & OBD_CONNECT_MDS)
881 seq_printf(m, " mdt_index: %d\n", ocd->ocd_group);
882 if (flags & OBD_CONNECT_GRANT)
883 seq_printf(m, " initial_grant: %d\n", ocd->ocd_grant);
884 if (flags & OBD_CONNECT_INDEX)
885 seq_printf(m, " target_index: %u\n", ocd->ocd_index);
886 if (flags & OBD_CONNECT_BRW_SIZE)
887 seq_printf(m, " max_brw_size: %d\n", ocd->ocd_brw_size);
888 if (flags & OBD_CONNECT_IBITS)
889 seq_printf(m, " ibits_known: %#llx\n",
890 ocd->ocd_ibits_known);
891 if (flags & OBD_CONNECT_GRANT_PARAM)
892 seq_printf(m, " grant_block_size: %d\n"
893 " grant_inode_size: %d\n"
894 " grant_max_extent_size: %d\n"
895 " grant_extent_tax: %d\n",
896 1 << ocd->ocd_grant_blkbits,
897 1 << ocd->ocd_grant_inobits,
898 ocd->ocd_grant_max_blks << ocd->ocd_grant_blkbits,
899 ocd->ocd_grant_tax_kb << 10);
900 if (flags & OBD_CONNECT_TRANSNO)
901 seq_printf(m, " first_transno: %#llx\n",
903 if (flags & OBD_CONNECT_CKSUM)
904 seq_printf(m, " cksum_types: %#x\n",
905 ocd->ocd_cksum_types);
906 if (flags & OBD_CONNECT_MAX_EASIZE)
907 seq_printf(m, " max_easize: %d\n", ocd->ocd_max_easize);
908 if (flags & OBD_CONNECT_MAXBYTES)
909 seq_printf(m, " max_object_bytes: %llu\n",
911 if (flags & OBD_CONNECT_MULTIMODRPCS)
912 seq_printf(m, " max_mod_rpcs: %hu\n",
913 ocd->ocd_maxmodrpcs);
916 int lprocfs_import_seq_show(struct seq_file *m, void *data)
918 char nidstr[LNET_NIDSTR_SIZE];
919 struct lprocfs_counter ret;
920 struct lprocfs_counter_header *header;
921 struct obd_device *obd = (struct obd_device *)data;
922 struct obd_import *imp;
923 struct obd_import_conn *conn;
924 struct obd_connect_data *ocd;
929 LASSERT(obd != NULL);
930 LPROCFS_CLIMP_CHECK(obd);
931 imp = obd->u.cli.cl_import;
932 ocd = &imp->imp_connect_data;
934 seq_printf(m, "import:\n"
938 " connect_flags: [ ",
941 ptlrpc_import_state_name(imp->imp_state));
942 obd_connect_seq_flags2str(m, imp->imp_connect_data.ocd_connect_flags,
943 imp->imp_connect_data.ocd_connect_flags2,
945 seq_printf(m, " ]\n");
946 obd_connect_data_seqprint(m, ocd);
947 seq_printf(m, " import_flags: [ ");
948 obd_import_flags2str(imp, m);
952 " failover_nids: [ ");
953 spin_lock(&imp->imp_lock);
955 list_for_each_entry(conn, &imp->imp_conn_list, oic_item) {
956 libcfs_nid2str_r(conn->oic_conn->c_peer.nid,
957 nidstr, sizeof(nidstr));
958 seq_printf(m, "%s%s", j ? ", " : "", nidstr);
961 if (imp->imp_connection)
962 libcfs_nid2str_r(imp->imp_connection->c_peer.nid,
963 nidstr, sizeof(nidstr));
965 strncpy(nidstr, "<none>", sizeof(nidstr));
967 " current_connection: %s\n"
968 " connection_attempts: %u\n"
970 " in-progress_invalidations: %u\n"
975 atomic_read(&imp->imp_inval_count),
976 ktime_get_real_seconds() - imp->imp_last_reply_time);
977 spin_unlock(&imp->imp_lock);
979 if (!obd->obd_svc_stats)
982 header = &obd->obd_svc_stats->ls_cnt_header[PTLRPC_REQWAIT_CNTR];
983 lprocfs_stats_collect(obd->obd_svc_stats, PTLRPC_REQWAIT_CNTR, &ret);
984 if (ret.lc_count != 0)
985 ret.lc_sum = div64_s64(ret.lc_sum, ret.lc_count);
988 seq_printf(m, " rpcs:\n"
990 " unregistering: %u\n"
992 " avg_waittime: %llu %s\n",
993 atomic_read(&imp->imp_inflight),
994 atomic_read(&imp->imp_unregistering),
995 atomic_read(&imp->imp_timeouts),
996 ret.lc_sum, header->lc_units);
999 for(j = 0; j < IMP_AT_MAX_PORTALS; j++) {
1000 if (imp->imp_at.iat_portal[j] == 0)
1002 k = max_t(unsigned int, k,
1003 at_get(&imp->imp_at.iat_service_estimate[j]));
1005 seq_printf(m, " service_estimates:\n"
1006 " services: %u sec\n"
1007 " network: %u sec\n",
1009 at_get(&imp->imp_at.iat_net_latency));
1011 seq_printf(m, " transactions:\n"
1012 " last_replay: %llu\n"
1013 " peer_committed: %llu\n"
1014 " last_checked: %llu\n",
1015 imp->imp_last_replay_transno,
1016 imp->imp_peer_committed_transno,
1017 imp->imp_last_transno_checked);
1019 /* avg data rates */
1020 for (rw = 0; rw <= 1; rw++) {
1021 lprocfs_stats_collect(obd->obd_svc_stats,
1022 PTLRPC_LAST_CNTR + BRW_READ_BYTES + rw,
1024 if (ret.lc_sum > 0 && ret.lc_count > 0) {
1025 ret.lc_sum = div64_s64(ret.lc_sum, ret.lc_count);
1026 seq_printf(m, " %s_data_averages:\n"
1027 " bytes_per_rpc: %llu\n",
1028 rw ? "write" : "read",
1031 k = (int)ret.lc_sum;
1032 j = opcode_offset(OST_READ + rw) + EXTRA_MAX_OPCODES;
1033 header = &obd->obd_svc_stats->ls_cnt_header[j];
1034 lprocfs_stats_collect(obd->obd_svc_stats, j, &ret);
1035 if (ret.lc_sum > 0 && ret.lc_count != 0) {
1036 ret.lc_sum = div64_s64(ret.lc_sum, ret.lc_count);
1037 seq_printf(m, " %s_per_rpc: %llu\n",
1038 header->lc_units, ret.lc_sum);
1039 j = (int)ret.lc_sum;
1041 seq_printf(m, " MB_per_sec: %u.%.02u\n",
1042 k / j, (100 * k / j) % 100);
1047 LPROCFS_CLIMP_EXIT(obd);
1050 EXPORT_SYMBOL(lprocfs_import_seq_show);
1052 int lprocfs_state_seq_show(struct seq_file *m, void *data)
1054 struct obd_device *obd = (struct obd_device *)data;
1055 struct obd_import *imp;
1058 LASSERT(obd != NULL);
1059 LPROCFS_CLIMP_CHECK(obd);
1060 imp = obd->u.cli.cl_import;
1062 seq_printf(m, "current_state: %s\n",
1063 ptlrpc_import_state_name(imp->imp_state));
1064 seq_printf(m, "state_history:\n");
1065 k = imp->imp_state_hist_idx;
1066 for (j = 0; j < IMP_STATE_HIST_LEN; j++) {
1067 struct import_state_hist *ish =
1068 &imp->imp_state_hist[(k + j) % IMP_STATE_HIST_LEN];
1069 if (ish->ish_state == 0)
1071 seq_printf(m, " - [ %lld, %s ]\n", (s64)ish->ish_time,
1072 ptlrpc_import_state_name(ish->ish_state));
1075 LPROCFS_CLIMP_EXIT(obd);
1078 EXPORT_SYMBOL(lprocfs_state_seq_show);
1080 int lprocfs_at_hist_helper(struct seq_file *m, struct adaptive_timeout *at)
1083 for (i = 0; i < AT_BINS; i++)
1084 seq_printf(m, "%3u ", at->at_hist[i]);
1085 seq_printf(m, "\n");
1088 EXPORT_SYMBOL(lprocfs_at_hist_helper);
1090 /* See also ptlrpc_lprocfs_timeouts_show_seq */
1091 int lprocfs_timeouts_seq_show(struct seq_file *m, void *data)
1093 struct obd_device *obd = (struct obd_device *)data;
1094 struct obd_import *imp;
1095 unsigned int cur, worst;
1096 time64_t now, worstt;
1099 LASSERT(obd != NULL);
1100 LPROCFS_CLIMP_CHECK(obd);
1101 imp = obd->u.cli.cl_import;
1103 now = ktime_get_real_seconds();
1105 /* Some network health info for kicks */
1106 seq_printf(m, "%-10s : %lld, %llds ago\n",
1107 "last reply", (s64)imp->imp_last_reply_time,
1108 (s64)(now - imp->imp_last_reply_time));
1110 cur = at_get(&imp->imp_at.iat_net_latency);
1111 worst = imp->imp_at.iat_net_latency.at_worst_ever;
1112 worstt = imp->imp_at.iat_net_latency.at_worst_time;
1113 seq_printf(m, "%-10s : cur %3u worst %3u (at %lld, %llds ago) ",
1114 "network", cur, worst, (s64)worstt, (s64)(now - worstt));
1115 lprocfs_at_hist_helper(m, &imp->imp_at.iat_net_latency);
1117 for(i = 0; i < IMP_AT_MAX_PORTALS; i++) {
1118 if (imp->imp_at.iat_portal[i] == 0)
1120 cur = at_get(&imp->imp_at.iat_service_estimate[i]);
1121 worst = imp->imp_at.iat_service_estimate[i].at_worst_ever;
1122 worstt = imp->imp_at.iat_service_estimate[i].at_worst_time;
1123 seq_printf(m, "portal %-2d : cur %3u worst %3u (at %lld, %llds ago) ",
1124 imp->imp_at.iat_portal[i], cur, worst, (s64)worstt,
1125 (s64)(now - worstt));
1126 lprocfs_at_hist_helper(m, &imp->imp_at.iat_service_estimate[i]);
1129 LPROCFS_CLIMP_EXIT(obd);
1132 EXPORT_SYMBOL(lprocfs_timeouts_seq_show);
1134 int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data)
1136 struct obd_device *obd = data;
1140 LPROCFS_CLIMP_CHECK(obd);
1141 flags = obd->u.cli.cl_import->imp_connect_data.ocd_connect_flags;
1142 flags2 = obd->u.cli.cl_import->imp_connect_data.ocd_connect_flags2;
1143 seq_printf(m, "flags=%#llx\n", flags);
1144 seq_printf(m, "flags2=%#llx\n", flags2);
1145 obd_connect_seq_flags2str(m, flags, flags2, "\n");
1146 seq_printf(m, "\n");
1147 LPROCFS_CLIMP_EXIT(obd);
1150 EXPORT_SYMBOL(lprocfs_connect_flags_seq_show);
1152 static const struct attribute *obd_def_uuid_attrs[] = {
1153 &lustre_attr_uuid.attr,
1157 static const struct attribute *obd_def_attrs[] = {
1158 &lustre_attr_blocksize.attr,
1159 &lustre_attr_kbytestotal.attr,
1160 &lustre_attr_kbytesfree.attr,
1161 &lustre_attr_kbytesavail.attr,
1162 &lustre_attr_filestotal.attr,
1163 &lustre_attr_filesfree.attr,
1164 &lustre_attr_uuid.attr,
1168 static void obd_sysfs_release(struct kobject *kobj)
1170 struct obd_device *obd = container_of(kobj, struct obd_device,
1173 complete(&obd->obd_kobj_unregister);
1176 int lprocfs_obd_setup(struct obd_device *obd, bool uuid_only)
1178 struct lprocfs_vars *debugfs_vars = NULL;
1181 if (!obd || obd->obd_magic != OBD_DEVICE_MAGIC)
1184 rc = kobject_set_name(&obd->obd_kset.kobj, "%s", obd->obd_name);
1188 obd->obd_ktype.sysfs_ops = &lustre_sysfs_ops;
1189 obd->obd_ktype.release = obd_sysfs_release;
1191 obd->obd_kset.kobj.parent = &obd->obd_type->typ_kobj;
1192 obd->obd_kset.kobj.ktype = &obd->obd_ktype;
1193 init_completion(&obd->obd_kobj_unregister);
1194 rc = kset_register(&obd->obd_kset);
1199 obd->obd_attrs = obd_def_uuid_attrs;
1201 obd->obd_attrs = obd_def_attrs;
1203 rc = sysfs_create_files(&obd->obd_kset.kobj, obd->obd_attrs);
1205 kset_unregister(&obd->obd_kset);
1209 if (!obd->obd_type->typ_procroot)
1210 debugfs_vars = obd->obd_vars;
1211 obd->obd_debugfs_entry = ldebugfs_register(obd->obd_name,
1212 obd->obd_type->typ_debugfs_entry,
1214 if (IS_ERR_OR_NULL(obd->obd_debugfs_entry)) {
1215 rc = obd->obd_debugfs_entry ? PTR_ERR(obd->obd_debugfs_entry)
1217 CERROR("error %d setting up debugfs for %s\n",
1219 obd->obd_debugfs_entry = NULL;
1221 sysfs_remove_files(&obd->obd_kset.kobj, obd->obd_attrs);
1222 obd->obd_attrs = NULL;
1223 kset_unregister(&obd->obd_kset);
1227 if (obd->obd_proc_entry || !obd->obd_type->typ_procroot)
1228 GOTO(already_registered, rc);
1230 obd->obd_proc_entry = lprocfs_register(obd->obd_name,
1231 obd->obd_type->typ_procroot,
1232 obd->obd_vars, obd);
1233 if (IS_ERR(obd->obd_proc_entry)) {
1234 rc = PTR_ERR(obd->obd_proc_entry);
1235 CERROR("error %d setting up lprocfs for %s\n",rc,obd->obd_name);
1236 obd->obd_proc_entry = NULL;
1238 debugfs_remove_recursive(obd->obd_debugfs_entry);
1239 obd->obd_debugfs_entry = NULL;
1241 sysfs_remove_files(&obd->obd_kset.kobj, obd->obd_attrs);
1242 obd->obd_attrs = NULL;
1243 kset_unregister(&obd->obd_kset);
1249 EXPORT_SYMBOL(lprocfs_obd_setup);
1251 int lprocfs_obd_cleanup(struct obd_device *obd)
1256 if (obd->obd_proc_exports_entry) {
1257 /* Should be no exports left */
1258 lprocfs_remove(&obd->obd_proc_exports_entry);
1259 obd->obd_proc_exports_entry = NULL;
1262 if (obd->obd_proc_entry) {
1263 lprocfs_remove(&obd->obd_proc_entry);
1264 obd->obd_proc_entry = NULL;
1267 debugfs_remove_recursive(obd->obd_debugfs_entry);
1268 obd->obd_debugfs_entry = NULL;
1270 /* obd device never allocated a kset */
1271 if (!obd->obd_kset.kobj.state_initialized)
1274 if (obd->obd_attrs) {
1275 sysfs_remove_files(&obd->obd_kset.kobj, obd->obd_attrs);
1276 obd->obd_attrs = NULL;
1279 kset_unregister(&obd->obd_kset);
1280 wait_for_completion(&obd->obd_kobj_unregister);
1283 EXPORT_SYMBOL(lprocfs_obd_cleanup);
1285 int lprocfs_stats_alloc_one(struct lprocfs_stats *stats, unsigned int cpuid)
1287 struct lprocfs_counter *cntr;
1288 unsigned int percpusize;
1290 unsigned long flags = 0;
1293 LASSERT(stats->ls_percpu[cpuid] == NULL);
1294 LASSERT((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0);
1296 percpusize = lprocfs_stats_counter_size(stats);
1297 LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[cpuid], percpusize);
1298 if (stats->ls_percpu[cpuid]) {
1300 if (unlikely(stats->ls_biggest_alloc_num <= cpuid)) {
1301 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
1302 spin_lock_irqsave(&stats->ls_lock, flags);
1304 spin_lock(&stats->ls_lock);
1305 if (stats->ls_biggest_alloc_num <= cpuid)
1306 stats->ls_biggest_alloc_num = cpuid + 1;
1307 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) {
1308 spin_unlock_irqrestore(&stats->ls_lock, flags);
1310 spin_unlock(&stats->ls_lock);
1313 /* initialize the ls_percpu[cpuid] non-zero counter */
1314 for (i = 0; i < stats->ls_num; ++i) {
1315 cntr = lprocfs_stats_counter_get(stats, cpuid, i);
1316 cntr->lc_min = LC_MIN_INIT;
1322 struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num,
1323 enum lprocfs_stats_flags flags)
1325 struct lprocfs_stats *stats;
1326 unsigned int num_entry;
1327 unsigned int percpusize = 0;
1333 if (lprocfs_no_percpu_stats != 0)
1334 flags |= LPROCFS_STATS_FLAG_NOPERCPU;
1336 if (flags & LPROCFS_STATS_FLAG_NOPERCPU)
1339 num_entry = num_possible_cpus();
1341 /* alloc percpu pointers for all possible cpu slots */
1342 LIBCFS_ALLOC(stats, offsetof(typeof(*stats), ls_percpu[num_entry]));
1346 stats->ls_num = num;
1347 stats->ls_flags = flags;
1348 spin_lock_init(&stats->ls_lock);
1350 /* alloc num of counter headers */
1351 LIBCFS_ALLOC(stats->ls_cnt_header,
1352 stats->ls_num * sizeof(struct lprocfs_counter_header));
1353 if (!stats->ls_cnt_header)
1356 if ((flags & LPROCFS_STATS_FLAG_NOPERCPU) != 0) {
1357 /* contains only one set counters */
1358 percpusize = lprocfs_stats_counter_size(stats);
1359 LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[0], percpusize);
1360 if (!stats->ls_percpu[0])
1362 stats->ls_biggest_alloc_num = 1;
1363 } else if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0) {
1364 /* alloc all percpu data, currently only obd_memory use this */
1365 for (i = 0; i < num_entry; ++i)
1366 if (lprocfs_stats_alloc_one(stats, i) < 0)
1373 lprocfs_free_stats(&stats);
1376 EXPORT_SYMBOL(lprocfs_alloc_stats);
1378 void lprocfs_free_stats(struct lprocfs_stats **statsh)
1380 struct lprocfs_stats *stats = *statsh;
1381 unsigned int num_entry;
1382 unsigned int percpusize;
1385 if (!stats || stats->ls_num == 0)
1389 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU)
1392 num_entry = num_possible_cpus();
1394 percpusize = lprocfs_stats_counter_size(stats);
1395 for (i = 0; i < num_entry; i++)
1396 if (stats->ls_percpu[i])
1397 LIBCFS_FREE(stats->ls_percpu[i], percpusize);
1398 if (stats->ls_cnt_header)
1399 LIBCFS_FREE(stats->ls_cnt_header, stats->ls_num *
1400 sizeof(struct lprocfs_counter_header));
1401 LIBCFS_FREE(stats, offsetof(typeof(*stats), ls_percpu[num_entry]));
1403 EXPORT_SYMBOL(lprocfs_free_stats);
1405 u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
1406 enum lprocfs_fields_flags field)
1408 unsigned long flags = 0;
1409 unsigned int num_cpu;
1415 num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1416 for (i = 0; i < num_cpu; i++) {
1417 struct lprocfs_counter *cntr;
1419 if (!stats->ls_percpu[i])
1422 cntr = lprocfs_stats_counter_get(stats, i, idx);
1423 ret += lprocfs_read_helper(cntr, &stats->ls_cnt_header[idx],
1424 stats->ls_flags, field);
1426 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1429 EXPORT_SYMBOL(lprocfs_stats_collector);
1431 void lprocfs_clear_stats(struct lprocfs_stats *stats)
1433 struct lprocfs_counter *percpu_cntr;
1436 unsigned int num_entry;
1437 unsigned long flags = 0;
1439 num_entry = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1441 for (i = 0; i < num_entry; i++) {
1442 if (!stats->ls_percpu[i])
1444 for (j = 0; j < stats->ls_num; j++) {
1445 percpu_cntr = lprocfs_stats_counter_get(stats, i, j);
1446 percpu_cntr->lc_count = 0;
1447 percpu_cntr->lc_min = LC_MIN_INIT;
1448 percpu_cntr->lc_max = 0;
1449 percpu_cntr->lc_sumsquare = 0;
1450 percpu_cntr->lc_sum = 0;
1451 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
1452 percpu_cntr->lc_sum_irq = 0;
1456 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1458 EXPORT_SYMBOL(lprocfs_clear_stats);
1460 static ssize_t lprocfs_stats_seq_write(struct file *file,
1461 const char __user *buf,
1462 size_t len, loff_t *off)
1464 struct seq_file *seq = file->private_data;
1465 struct lprocfs_stats *stats = seq->private;
1467 lprocfs_clear_stats(stats);
1472 static void *lprocfs_stats_seq_start(struct seq_file *p, loff_t *pos)
1474 struct lprocfs_stats *stats = p->private;
1476 return (*pos < stats->ls_num) ? pos : NULL;
1479 static void lprocfs_stats_seq_stop(struct seq_file *p, void *v)
1483 static void *lprocfs_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
1487 return lprocfs_stats_seq_start(p, pos);
1490 /* seq file export of one lprocfs counter */
1491 static int lprocfs_stats_seq_show(struct seq_file *p, void *v)
1493 struct lprocfs_stats *stats = p->private;
1494 struct lprocfs_counter_header *hdr;
1495 struct lprocfs_counter ctr;
1496 int idx = *(loff_t *)v;
1499 struct timespec64 now;
1501 ktime_get_real_ts64(&now);
1502 seq_printf(p, "%-25s %llu.%09lu secs.nsecs\n",
1503 "snapshot_time", (s64)now.tv_sec, now.tv_nsec);
1506 hdr = &stats->ls_cnt_header[idx];
1507 lprocfs_stats_collect(stats, idx, &ctr);
1509 if (ctr.lc_count == 0)
1512 seq_printf(p, "%-25s %lld samples [%s]", hdr->lc_name,
1513 ctr.lc_count, hdr->lc_units);
1515 if ((hdr->lc_config & LPROCFS_CNTR_AVGMINMAX) && ctr.lc_count > 0) {
1516 seq_printf(p, " %lld %lld %lld",
1517 ctr.lc_min, ctr.lc_max, ctr.lc_sum);
1518 if (hdr->lc_config & LPROCFS_CNTR_STDDEV)
1519 seq_printf(p, " %llu", ctr.lc_sumsquare);
1525 static const struct seq_operations lprocfs_stats_seq_sops = {
1526 .start = lprocfs_stats_seq_start,
1527 .stop = lprocfs_stats_seq_stop,
1528 .next = lprocfs_stats_seq_next,
1529 .show = lprocfs_stats_seq_show,
1532 static int lprocfs_stats_seq_open(struct inode *inode, struct file *file)
1534 struct seq_file *seq;
1537 rc = LPROCFS_ENTRY_CHECK(inode);
1541 rc = seq_open(file, &lprocfs_stats_seq_sops);
1544 seq = file->private_data;
1545 seq->private = inode->i_private ? inode->i_private : PDE_DATA(inode);
1549 static const struct file_operations lprocfs_stats_seq_fops = {
1550 .owner = THIS_MODULE,
1551 .open = lprocfs_stats_seq_open,
1553 .write = lprocfs_stats_seq_write,
1554 .llseek = seq_lseek,
1555 .release = lprocfs_seq_release,
1558 int ldebugfs_register_stats(struct dentry *parent, const char *name,
1559 struct lprocfs_stats *stats)
1561 struct dentry *entry;
1563 LASSERT(!IS_ERR_OR_NULL(parent));
1565 entry = debugfs_create_file(name, 0644, parent, stats,
1566 &lprocfs_stats_seq_fops);
1567 if (IS_ERR_OR_NULL(entry))
1568 return entry ? PTR_ERR(entry) : -ENOMEM;
1572 EXPORT_SYMBOL_GPL(ldebugfs_register_stats);
1574 int lprocfs_register_stats(struct proc_dir_entry *root, const char *name,
1575 struct lprocfs_stats *stats)
1577 struct proc_dir_entry *entry;
1578 LASSERT(root != NULL);
1580 entry = proc_create_data(name, 0644, root,
1581 &lprocfs_stats_seq_fops, stats);
1586 EXPORT_SYMBOL(lprocfs_register_stats);
1588 void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
1589 unsigned conf, const char *name, const char *units)
1591 struct lprocfs_counter_header *header;
1592 struct lprocfs_counter *percpu_cntr;
1593 unsigned long flags = 0;
1595 unsigned int num_cpu;
1597 LASSERT(stats != NULL);
1599 header = &stats->ls_cnt_header[index];
1600 LASSERTF(header != NULL, "Failed to allocate stats header:[%d]%s/%s\n",
1601 index, name, units);
1603 header->lc_config = conf;
1604 header->lc_name = name;
1605 header->lc_units = units;
1607 num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1608 for (i = 0; i < num_cpu; ++i) {
1609 if (!stats->ls_percpu[i])
1611 percpu_cntr = lprocfs_stats_counter_get(stats, i, index);
1612 percpu_cntr->lc_count = 0;
1613 percpu_cntr->lc_min = LC_MIN_INIT;
1614 percpu_cntr->lc_max = 0;
1615 percpu_cntr->lc_sumsquare = 0;
1616 percpu_cntr->lc_sum = 0;
1617 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
1618 percpu_cntr->lc_sum_irq = 0;
1620 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1622 EXPORT_SYMBOL(lprocfs_counter_init);
1624 static const char * const mps_stats[] = {
1625 [LPROC_MD_CLOSE] = "close",
1626 [LPROC_MD_CREATE] = "create",
1627 [LPROC_MD_ENQUEUE] = "enqueue",
1628 [LPROC_MD_GETATTR] = "getattr",
1629 [LPROC_MD_INTENT_LOCK] = "intent_lock",
1630 [LPROC_MD_LINK] = "link",
1631 [LPROC_MD_RENAME] = "rename",
1632 [LPROC_MD_SETATTR] = "setattr",
1633 [LPROC_MD_FSYNC] = "fsync",
1634 [LPROC_MD_READ_PAGE] = "read_page",
1635 [LPROC_MD_UNLINK] = "unlink",
1636 [LPROC_MD_SETXATTR] = "setxattr",
1637 [LPROC_MD_GETXATTR] = "getxattr",
1638 [LPROC_MD_INTENT_GETATTR_ASYNC] = "intent_getattr_async",
1639 [LPROC_MD_REVALIDATE_LOCK] = "revalidate_lock",
1642 int lprocfs_alloc_md_stats(struct obd_device *obd,
1643 unsigned int num_private_stats)
1645 struct lprocfs_stats *stats;
1646 unsigned int num_stats;
1650 * TODO Ensure that this function is only used where
1651 * appropriate by adding an assertion to the effect that
1652 * obd->obd_type->typ_md_ops is not NULL. We can't do this now
1653 * because mdt_procfs_init() uses this function to allocate
1654 * the stats backing /proc/fs/lustre/mdt/.../md_stats but the
1655 * mdt layer does not use the md_ops interface. This is
1656 * confusing and a waste of memory. See LU-2484.
1658 LASSERT(obd->obd_proc_entry != NULL);
1659 LASSERT(obd->obd_md_stats == NULL);
1661 num_stats = ARRAY_SIZE(mps_stats) + num_private_stats;
1662 stats = lprocfs_alloc_stats(num_stats, 0);
1666 for (i = 0; i < ARRAY_SIZE(mps_stats); i++) {
1667 lprocfs_counter_init(stats, i, 0, mps_stats[i], "reqs");
1668 if (!stats->ls_cnt_header[i].lc_name) {
1669 CERROR("Missing md_stat initializer md_op operation at offset %d. Aborting.\n",
1675 rc = lprocfs_register_stats(obd->obd_proc_entry, "md_stats", stats);
1677 lprocfs_free_stats(&stats);
1679 obd->obd_md_stats = stats;
1684 EXPORT_SYMBOL(lprocfs_alloc_md_stats);
1686 void lprocfs_free_md_stats(struct obd_device *obd)
1688 struct lprocfs_stats *stats = obd->obd_md_stats;
1691 obd->obd_md_stats = NULL;
1692 lprocfs_free_stats(&stats);
1695 EXPORT_SYMBOL(lprocfs_free_md_stats);
1697 void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
1699 lprocfs_counter_init(ldlm_stats,
1700 LDLM_ENQUEUE - LDLM_FIRST_OPC,
1701 0, "ldlm_enqueue", "reqs");
1702 lprocfs_counter_init(ldlm_stats,
1703 LDLM_CONVERT - LDLM_FIRST_OPC,
1704 0, "ldlm_convert", "reqs");
1705 lprocfs_counter_init(ldlm_stats,
1706 LDLM_CANCEL - LDLM_FIRST_OPC,
1707 0, "ldlm_cancel", "reqs");
1708 lprocfs_counter_init(ldlm_stats,
1709 LDLM_BL_CALLBACK - LDLM_FIRST_OPC,
1710 0, "ldlm_bl_callback", "reqs");
1711 lprocfs_counter_init(ldlm_stats,
1712 LDLM_CP_CALLBACK - LDLM_FIRST_OPC,
1713 0, "ldlm_cp_callback", "reqs");
1714 lprocfs_counter_init(ldlm_stats,
1715 LDLM_GL_CALLBACK - LDLM_FIRST_OPC,
1716 0, "ldlm_gl_callback", "reqs");
1718 EXPORT_SYMBOL(lprocfs_init_ldlm_stats);
1720 __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
1721 struct lprocfs_counter_header *header,
1722 enum lprocfs_stats_flags flags,
1723 enum lprocfs_fields_flags field)
1731 case LPROCFS_FIELDS_FLAGS_CONFIG:
1732 ret = header->lc_config;
1734 case LPROCFS_FIELDS_FLAGS_SUM:
1736 if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
1737 ret += lc->lc_sum_irq;
1739 case LPROCFS_FIELDS_FLAGS_MIN:
1742 case LPROCFS_FIELDS_FLAGS_MAX:
1745 case LPROCFS_FIELDS_FLAGS_AVG:
1746 ret = (lc->lc_max - lc->lc_min) / 2;
1748 case LPROCFS_FIELDS_FLAGS_SUMSQUARE:
1749 ret = lc->lc_sumsquare;
1751 case LPROCFS_FIELDS_FLAGS_COUNT:
1759 EXPORT_SYMBOL(lprocfs_read_helper);
1762 * string_to_size - convert ASCII string representing a numerical
1763 * value with optional units to 64-bit binary value
1765 * @size: The numerical value extract out of @buffer
1766 * @buffer: passed in string to parse
1767 * @count: length of the @buffer
1769 * This function returns a 64-bit binary value if @buffer contains a valid
1770 * numerical string. The string is parsed to 3 significant figures after
1771 * the decimal point. Support the string containing an optional units at
1772 * the end which can be base 2 or base 10 in value. If no units are given
1773 * the string is assumed to just a numerical value.
1775 * Returns: @count if the string is successfully parsed,
1776 * -errno on invalid input strings. Error values:
1778 * - ``-EINVAL``: @buffer is not a proper numerical string
1779 * - ``-EOVERFLOW``: results does not fit into 64 bits.
1780 * - ``-E2BIG ``: @buffer is not large
1782 int string_to_size(u64 *size, const char *buffer, size_t count)
1784 /* For string_get_size() it can support values above exabytes,
1785 * (ZiB, YiB) due to breaking the return value into a size and
1786 * bulk size to avoid 64 bit overflow. We don't break the size
1787 * up into block size units so we don't support ZiB or YiB.
1789 static const char *const units_10[] = {
1790 "kB", "MB", "GB", "TB", "PB", "EB"
1792 static const char *const units_2[] = {
1793 "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"
1795 static const char *const *const units_str[] = {
1796 [STRING_UNITS_2] = units_2,
1797 [STRING_UNITS_10] = units_10,
1799 static const unsigned int coeff[] = {
1800 [STRING_UNITS_10] = 1000,
1801 [STRING_UNITS_2] = 1024,
1803 enum string_size_units unit;
1804 u64 whole, blk_size = 1;
1805 char kernbuf[22], *end;
1810 if (count >= sizeof(kernbuf))
1814 /* 'iB' is used for based 2 numbers. If @buffer contains only a 'B'
1815 * or only numbers then we treat it as a direct number which doesn't
1816 * matter if its STRING_UNITS_2 or STRING_UNIT_10.
1818 unit = strstr(buffer, "iB") ? STRING_UNITS_2 : STRING_UNITS_10;
1819 i = unit == STRING_UNITS_2 ? ARRAY_SIZE(units_2) - 1 :
1820 ARRAY_SIZE(units_10) - 1;
1822 end = strstr(buffer, units_str[unit][i]);
1825 blk_size *= coeff[unit];
1831 /* as 'B' is a substring of all units, we need to handle it
1835 /* 'B' is only acceptable letter at this point */
1836 end = strchr(buffer, 'B');
1840 if (count - len > 2 ||
1841 (count - len == 2 && strcmp(end, "B\n") != 0))
1844 /* kstrtoull will error out if it has non digits */
1848 end = strchr(buffer, '.');
1850 /* need to limit 3 decimal places */
1851 char rem[4] = "000";
1858 /* limit to 3 decimal points */
1859 off = min_t(size_t, 3, strspn(end, "0123456789"));
1860 /* need to limit frac_d to a u32 */
1861 memcpy(rem, end, off);
1862 rc = kstrtoull(rem, 10, &frac);
1866 if (fls64(frac) + fls64(blk_size) - 1 > 64)
1874 snprintf(kernbuf, sizeof(kernbuf), "%.*s", (int)len, buffer);
1875 rc = kstrtoull(kernbuf, 10, &whole);
1879 if (whole != 0 && fls64(whole) + fls64(blk_size) - 1 > 64)
1882 *size += whole * blk_size;
1886 EXPORT_SYMBOL(string_to_size);
1889 * sysfs_memparse - parse a ASCII string to 64-bit binary value,
1890 * with optional units
1892 * @buffer: kernel pointer to input string
1893 * @count: number of bytes in the input @buffer
1894 * @val: (output) binary value returned to caller
1895 * @defunit: default unit suffix to use if none is provided
1897 * Parses a string into a number. The number stored at @buffer is
1898 * potentially suffixed with K, M, G, T, P, E. Besides these other
1899 * valid suffix units are shown in the string_to_size() function.
1900 * If the string lacks a suffix then the defunit is used. The defunit
1901 * should be given as a binary unit (e.g. MiB) as that is the standard
1902 * for tunables in Lustre. If no unit suffix is given (e.g. 'G'), then
1903 * it is assumed to be in binary units.
1905 * Returns: 0 on success or -errno on failure.
1907 int sysfs_memparse(const char *buffer, size_t count, u64 *val,
1908 const char *defunit)
1913 if (count >= sizeof(param))
1916 count = strlen(buffer);
1917 if (count && buffer[count - 1] == '\n')
1923 if (isalpha(buffer[count - 1])) {
1924 if (buffer[count - 1] != 'B') {
1925 scnprintf(param, sizeof(param), "%.*siB",
1926 (int)count, buffer);
1928 memcpy(param, buffer, sizeof(param));
1931 scnprintf(param, sizeof(param), "%.*s%s", (int)count,
1935 rc = string_to_size(val, param, strlen(param));
1936 return rc < 0 ? rc : 0;
1938 EXPORT_SYMBOL(sysfs_memparse);
1940 /* Obtains the conversion factor for the unit specified */
1941 static int get_mult(char unit, __u64 *mult)
1946 /* peta, tera, giga, mega, and kilo */
1967 /* some tests expect % to be accepted */
1981 * Ensures the numeric string is valid. The function provides the final
1982 * multiplier in the case a unit exists at the end of the string. It also
1983 * locates the start of the whole and fractional parts (if any). This
1984 * function modifies the string so kstrtoull can be used to parse both
1985 * the whole and fraction portions. This function also figures out
1986 * the base of the number.
1988 static int preprocess_numeric_str(char *buffer, __u64 *mult, __u64 def_mult,
1989 bool allow_units, char **whole, char **frac,
1992 bool hit_decimal = false;
1993 bool hit_unit = false;
2001 /* a hex string if it starts with "0x" */
2002 if (buffer[0] == '0' && tolower(buffer[1]) == 'x') {
2010 /* allow for a single new line before the null terminator */
2011 if (*buffer == '\n') {
2021 /* any chars after our unit indicates a malformed string */
2025 /* ensure we only hit one decimal */
2026 if (*buffer == '.') {
2030 /* if past start, there's a whole part */
2031 if (start != buffer)
2037 } else if (!isdigit(*buffer) &&
2038 !(*base == 16 && isxdigit(*buffer))) {
2040 /* if we allow units, attempt to get mult */
2042 rc = get_mult(*buffer, mult);
2046 /* string stops here, but keep processing */
2058 /* hit a decimal, make sure there's a fractional part */
2064 /* didn't hit a decimal, but may have a whole part */
2065 if (start != buffer && *start)
2069 /* malformed string if we didn't get anything */
2070 if (!*frac && !*whole)
2077 * Parses a numeric string which can contain a whole and fraction portion
2078 * into a __u64. Accepts a multiplier to apply to the value parsed. Also
2079 * allows the string to have a unit at the end. The function handles
2080 * wrapping of the final unsigned value.
2082 static int str_to_u64_parse(char *buffer, unsigned long count,
2083 __u64 *val, __u64 def_mult, bool allow_units)
2087 unsigned int frac_d = 1;
2088 __u64 wrap_indicator = ULLONG_MAX;
2093 unsigned int base = 10;
2095 rc = preprocess_numeric_str(buffer, &mult, def_mult, allow_units,
2096 &strwhole, &strfrac, &base);
2106 /* the multiplier limits how large the value can be */
2107 wrap_indicator = div64_u64(wrap_indicator, mult);
2110 rc = kstrtoull(strwhole, base, &whole);
2114 if (whole > wrap_indicator)
2121 if (strlen(strfrac) > 10)
2124 rc = kstrtoull(strfrac, base, &frac);
2128 /* determine power of fractional portion */
2134 /* fractional portion is too large to perform calculation */
2135 if (frac > wrap_indicator)
2139 do_div(frac, frac_d);
2142 /* check that the sum of whole and fraction fits in u64 */
2143 if (whole > (ULLONG_MAX - frac))
2146 *val = whole + frac;
2152 * This function parses numeric/hex strings into __s64. It accepts a multiplier
2153 * which will apply to the value parsed. It also can allow the string to
2154 * have a unit as the last character. The function handles overflow/underflow
2155 * of the signed integer.
2157 int lu_str_to_s64(char *buffer, unsigned long count, __s64 *val, char defunit)
2161 unsigned int offset = 0;
2162 int signed sign = 1;
2163 __u64 max = LLONG_MAX;
2166 if (defunit != '1') {
2167 rc = get_mult(defunit, &mult);
2172 /* keep track of our sign */
2173 if (*buffer == '-') {
2176 /* equivalent to max = -LLONG_MIN, avoids overflow */
2180 rc = str_to_u64_parse(buffer + offset, count - offset,
2185 /* check for overflow/underflow */
2189 *val = (__s64)tmp * sign;
2193 EXPORT_SYMBOL(lu_str_to_s64);
2195 /* identical to s64 version, but does not handle overflow */
2196 static int str_to_u64_internal(const char __user *buffer, unsigned long count,
2197 __u64 *val, __u64 def_mult, bool allow_units)
2200 unsigned int offset = 0;
2203 if (count > (sizeof(kernbuf) - 1))
2206 if (copy_from_user(kernbuf, buffer, count))
2209 kernbuf[count] = '\0';
2211 rc = str_to_u64_parse(kernbuf + offset, count - offset,
2212 val, def_mult, allow_units);
2219 * Convert a user string into a signed 64 bit number. This function produces
2220 * an error when the value parsed from the string times multiplier underflows or
2221 * overflows. This function only accepts strings that contains digits, an
2222 * optional decimal, and a char representing a unit at the end. If a unit is
2223 * specified in the string, the multiplier provided by the caller is ignored.
2224 * This function can also accept hexadecimal strings which are prefixed with
2227 * \param[in] buffer string consisting of numbers, a decimal, and a unit
2228 * \param[in] count buffer length
2229 * \param[in] val if successful, the value represented by the string
2230 * \param[in] defunit default unit if string doesn't contain one
2232 * \retval 0 on success
2233 * \retval negative number on error
2235 int lprocfs_str_with_units_to_s64(const char __user *buffer,
2236 unsigned long count, __s64 *val, char defunit)
2240 if (count > (sizeof(kernbuf) - 1))
2243 if (copy_from_user(kernbuf, buffer, count))
2246 kernbuf[count] = '\0';
2248 return lu_str_to_s64(kernbuf, count, val, defunit);
2250 EXPORT_SYMBOL(lprocfs_str_with_units_to_s64);
2252 /* identical to s64 version above, but does not handle overflow */
2253 int lprocfs_str_with_units_to_u64(const char __user *buffer,
2254 unsigned long count, __u64 *val, char defunit)
2259 if (defunit != '1') {
2260 rc = get_mult(defunit, &mult);
2265 return str_to_u64_internal(buffer, count, val, mult, true);
2267 EXPORT_SYMBOL(lprocfs_str_with_units_to_u64);
2269 char *lprocfs_strnstr(const char *s1, const char *s2, size_t len)
2278 if (!memcmp(s1, s2, l2))
2284 EXPORT_SYMBOL(lprocfs_strnstr);
2287 * Find the string \a name in the input \a buffer, and return a pointer to the
2288 * value immediately following \a name, reducing \a count appropriately.
2289 * If \a name is not found the original \a buffer is returned.
2291 char *lprocfs_find_named_value(const char *buffer, const char *name,
2295 size_t buflen = *count;
2297 /* there is no strnstr() in rhel5 and ubuntu kernels */
2298 val = lprocfs_strnstr(buffer, name, buflen);
2300 return (char *)buffer;
2302 val += strlen(name); /* skip prefix */
2303 while (val < buffer + buflen && isspace(*val)) /* skip separator */
2307 while (val < buffer + buflen && isalnum(*val)) {
2312 return val - *count;
2314 EXPORT_SYMBOL(lprocfs_find_named_value);
2316 int ldebugfs_seq_create(struct dentry *parent, const char *name, umode_t mode,
2317 const struct file_operations *seq_fops, void *data)
2319 struct dentry *entry;
2321 /* Disallow secretly (un)writable entries. */
2322 LASSERT((!seq_fops->write) == (!(mode & 0222)));
2324 entry = debugfs_create_file(name, mode, parent, data, seq_fops);
2325 if (IS_ERR_OR_NULL(entry))
2326 return entry ? PTR_ERR(entry) : -ENOMEM;
2330 EXPORT_SYMBOL_GPL(ldebugfs_seq_create);
2332 int lprocfs_seq_create(struct proc_dir_entry *parent,
2335 const struct file_operations *seq_fops,
2338 struct proc_dir_entry *entry;
2341 /* Disallow secretly (un)writable entries. */
2342 LASSERT((seq_fops->write == NULL) == ((mode & 0222) == 0));
2344 entry = proc_create_data(name, mode, parent, seq_fops, data);
2351 EXPORT_SYMBOL(lprocfs_seq_create);
2353 int lprocfs_obd_seq_create(struct obd_device *dev,
2356 const struct file_operations *seq_fops,
2359 return (lprocfs_seq_create(dev->obd_proc_entry, name,
2360 mode, seq_fops, data));
2362 EXPORT_SYMBOL(lprocfs_obd_seq_create);
2364 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
2366 if (value >= OBD_HIST_MAX)
2367 value = OBD_HIST_MAX - 1;
2369 spin_lock(&oh->oh_lock);
2370 oh->oh_buckets[value]++;
2371 spin_unlock(&oh->oh_lock);
2373 EXPORT_SYMBOL(lprocfs_oh_tally);
2375 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
2377 unsigned int val = 0;
2379 if (likely(value != 0))
2380 val = min(fls(value - 1), OBD_HIST_MAX);
2382 lprocfs_oh_tally(oh, val);
2384 EXPORT_SYMBOL(lprocfs_oh_tally_log2);
2386 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
2388 unsigned long ret = 0;
2391 for (i = 0; i < OBD_HIST_MAX; i++)
2392 ret += oh->oh_buckets[i];
2395 EXPORT_SYMBOL(lprocfs_oh_sum);
2397 void lprocfs_oh_clear(struct obd_histogram *oh)
2399 spin_lock(&oh->oh_lock);
2400 memset(oh->oh_buckets, 0, sizeof(oh->oh_buckets));
2401 spin_unlock(&oh->oh_lock);
2403 EXPORT_SYMBOL(lprocfs_oh_clear);
2405 ssize_t lustre_attr_show(struct kobject *kobj,
2406 struct attribute *attr, char *buf)
2408 struct lustre_attr *a = container_of(attr, struct lustre_attr, attr);
2410 return a->show ? a->show(kobj, attr, buf) : 0;
2412 EXPORT_SYMBOL_GPL(lustre_attr_show);
2414 ssize_t lustre_attr_store(struct kobject *kobj, struct attribute *attr,
2415 const char *buf, size_t len)
2417 struct lustre_attr *a = container_of(attr, struct lustre_attr, attr);
2419 return a->store ? a->store(kobj, attr, buf, len) : len;
2421 EXPORT_SYMBOL_GPL(lustre_attr_store);
2423 const struct sysfs_ops lustre_sysfs_ops = {
2424 .show = lustre_attr_show,
2425 .store = lustre_attr_store,
2427 EXPORT_SYMBOL_GPL(lustre_sysfs_ops);
2429 int lprocfs_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *data)
2431 struct obd_device *dev = data;
2432 struct client_obd *cli = &dev->u.cli;
2434 spin_lock(&cli->cl_loi_list_lock);
2435 seq_printf(m, "%d\n", cli->cl_max_pages_per_rpc);
2436 spin_unlock(&cli->cl_loi_list_lock);
2439 EXPORT_SYMBOL(lprocfs_obd_max_pages_per_rpc_seq_show);
2441 ssize_t lprocfs_obd_max_pages_per_rpc_seq_write(struct file *file,
2442 const char __user *buffer,
2443 size_t count, loff_t *off)
2445 struct obd_device *dev =
2446 ((struct seq_file *)file->private_data)->private;
2447 struct client_obd *cli = &dev->u.cli;
2448 struct obd_connect_data *ocd = &cli->cl_import->imp_connect_data;
2452 rc = lprocfs_str_with_units_to_s64(buffer, count, &val, '1');
2458 /* if the max_pages is specified in bytes, convert to pages */
2459 if (val >= ONE_MB_BRW_SIZE)
2462 LPROCFS_CLIMP_CHECK(dev);
2464 chunk_mask = ~((1 << (cli->cl_chunkbits - PAGE_SHIFT)) - 1);
2465 /* max_pages_per_rpc must be chunk aligned */
2466 val = (val + ~chunk_mask) & chunk_mask;
2467 if (val == 0 || (ocd->ocd_brw_size != 0 &&
2468 val > ocd->ocd_brw_size >> PAGE_SHIFT)) {
2469 LPROCFS_CLIMP_EXIT(dev);
2472 spin_lock(&cli->cl_loi_list_lock);
2473 cli->cl_max_pages_per_rpc = val;
2474 client_adjust_max_dirty(cli);
2475 spin_unlock(&cli->cl_loi_list_lock);
2477 LPROCFS_CLIMP_EXIT(dev);
2480 EXPORT_SYMBOL(lprocfs_obd_max_pages_per_rpc_seq_write);
2482 ssize_t short_io_bytes_show(struct kobject *kobj, struct attribute *attr,
2485 struct obd_device *dev = container_of(kobj, struct obd_device,
2487 struct client_obd *cli = &dev->u.cli;
2490 spin_lock(&cli->cl_loi_list_lock);
2491 rc = sprintf(buf, "%d\n", cli->cl_max_short_io_bytes);
2492 spin_unlock(&cli->cl_loi_list_lock);
2495 EXPORT_SYMBOL(short_io_bytes_show);
2497 /* Used to catch people who think they're specifying pages. */
2498 #define MIN_SHORT_IO_BYTES 64U
2500 ssize_t short_io_bytes_store(struct kobject *kobj, struct attribute *attr,
2501 const char *buffer, size_t count)
2503 struct obd_device *dev = container_of(kobj, struct obd_device,
2505 struct client_obd *cli = &dev->u.cli;
2510 if (count >= sizeof(kernbuf))
2513 LPROCFS_CLIMP_CHECK(dev);
2515 memcpy(kernbuf, buffer, count);
2516 kernbuf[count] = '\0';
2517 rc = lu_str_to_s64(kernbuf, count, &val, '1');
2522 val = OBD_DEF_SHORT_IO_BYTES;
2524 if (val && (val < MIN_SHORT_IO_BYTES || val > LNET_MTU))
2525 GOTO(out, rc = -ERANGE);
2529 spin_lock(&cli->cl_loi_list_lock);
2530 cli->cl_max_short_io_bytes = min_t(u64, val, OST_MAX_SHORT_IO_BYTES);
2531 spin_unlock(&cli->cl_loi_list_lock);
2534 LPROCFS_CLIMP_EXIT(dev);
2537 EXPORT_SYMBOL(short_io_bytes_store);
2539 int lprocfs_wr_root_squash(const char __user *buffer, unsigned long count,
2540 struct root_squash_info *squash, char *name)
2543 char kernbuf[64], *tmp, *errmsg;
2544 unsigned long uid, gid;
2547 if (count >= sizeof(kernbuf)) {
2548 errmsg = "string too long";
2549 GOTO(failed_noprint, rc = -EINVAL);
2551 if (copy_from_user(kernbuf, buffer, count)) {
2552 errmsg = "bad address";
2553 GOTO(failed_noprint, rc = -EFAULT);
2555 kernbuf[count] = '\0';
2557 /* look for uid gid separator */
2558 tmp = strchr(kernbuf, ':');
2560 errmsg = "needs uid:gid format";
2561 GOTO(failed, rc = -EINVAL);
2567 if (kstrtoul(kernbuf, 0, &uid) != 0) {
2569 GOTO(failed, rc = -EINVAL);
2573 if (kstrtoul(tmp, 0, &gid) != 0) {
2575 GOTO(failed, rc = -EINVAL);
2578 squash->rsi_uid = uid;
2579 squash->rsi_gid = gid;
2581 LCONSOLE_INFO("%s: root_squash is set to %u:%u\n",
2582 name, squash->rsi_uid, squash->rsi_gid);
2590 CWARN("%s: failed to set root_squash to \"%s\", %s, rc = %d\n",
2591 name, kernbuf, errmsg, rc);
2594 CWARN("%s: failed to set root_squash due to %s, rc = %d\n",
2598 EXPORT_SYMBOL(lprocfs_wr_root_squash);
2601 int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count,
2602 struct root_squash_info *squash, char *name)
2605 char *kernbuf = NULL;
2607 struct list_head tmp;
2612 errmsg = "string too long";
2613 GOTO(failed, rc = -EINVAL);
2616 OBD_ALLOC(kernbuf, count + 1);
2618 errmsg = "no memory";
2619 GOTO(failed, rc = -ENOMEM);
2621 if (copy_from_user(kernbuf, buffer, count)) {
2622 errmsg = "bad address";
2623 GOTO(failed, rc = -EFAULT);
2625 kernbuf[count] = '\0';
2627 if (count > 0 && kernbuf[count - 1] == '\n')
2630 if ((len == 4 && strncmp(kernbuf, "NONE", len) == 0) ||
2631 (len == 5 && strncmp(kernbuf, "clear", len) == 0)) {
2632 /* empty string is special case */
2633 spin_lock(&squash->rsi_lock);
2634 if (!list_empty(&squash->rsi_nosquash_nids))
2635 cfs_free_nidlist(&squash->rsi_nosquash_nids);
2636 spin_unlock(&squash->rsi_lock);
2637 LCONSOLE_INFO("%s: nosquash_nids is cleared\n", name);
2638 OBD_FREE(kernbuf, count + 1);
2642 INIT_LIST_HEAD(&tmp);
2643 if (cfs_parse_nidlist(kernbuf, count, &tmp) <= 0) {
2644 errmsg = "can't parse";
2645 GOTO(failed, rc = -EINVAL);
2647 LCONSOLE_INFO("%s: nosquash_nids set to %s\n",
2649 OBD_FREE(kernbuf, count + 1);
2652 spin_lock(&squash->rsi_lock);
2653 if (!list_empty(&squash->rsi_nosquash_nids))
2654 cfs_free_nidlist(&squash->rsi_nosquash_nids);
2655 list_splice(&tmp, &squash->rsi_nosquash_nids);
2656 spin_unlock(&squash->rsi_lock);
2662 CWARN("%s: failed to set nosquash_nids to \"%s\", %s rc = %d\n",
2663 name, kernbuf, errmsg, rc);
2664 OBD_FREE(kernbuf, count + 1);
2666 CWARN("%s: failed to set nosquash_nids due to %s rc = %d\n",
2671 EXPORT_SYMBOL(lprocfs_wr_nosquash_nids);
2673 #endif /* CONFIG_PROC_FS*/