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 proc_dir_entry *
63 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
64 void *data, const struct file_operations *fops)
66 struct proc_dir_entry *proc;
69 if (root == NULL || name == NULL || fops == NULL)
70 return ERR_PTR(-EINVAL);
76 proc = proc_create_data(name, mode, root, fops, data);
78 CERROR("LprocFS: No memory to create /proc entry %s\n",
80 return ERR_PTR(-ENOMEM);
84 EXPORT_SYMBOL(lprocfs_add_simple);
86 struct proc_dir_entry *lprocfs_add_symlink(const char *name,
87 struct proc_dir_entry *parent, const char *format, ...)
89 struct proc_dir_entry *entry;
93 if (parent == NULL || format == NULL)
96 OBD_ALLOC_WAIT(dest, MAX_STRING_SIZE + 1);
100 va_start(ap, format);
101 vsnprintf(dest, MAX_STRING_SIZE, format, ap);
104 entry = proc_symlink(name, parent, dest);
106 CERROR("LprocFS: Could not create symbolic link from "
107 "%s to %s\n", name, dest);
109 OBD_FREE(dest, MAX_STRING_SIZE + 1);
112 EXPORT_SYMBOL(lprocfs_add_symlink);
114 static const struct file_operations lprocfs_generic_fops = { };
116 int ldebugfs_add_vars(struct dentry *parent, struct lprocfs_vars *list,
119 if (IS_ERR_OR_NULL(parent) || IS_ERR_OR_NULL(list))
123 struct dentry *entry;
126 if (list->proc_mode != 0000) {
127 mode = list->proc_mode;
128 } else if (list->fops) {
129 if (list->fops->read)
131 if (list->fops->write)
134 entry = debugfs_create_file(list->name, mode, parent,
136 list->fops ? : &lprocfs_generic_fops);
137 if (IS_ERR_OR_NULL(entry))
138 return entry ? PTR_ERR(entry) : -ENOMEM;
143 EXPORT_SYMBOL_GPL(ldebugfs_add_vars);
148 * \param root [in] The parent proc entry on which new entry will be added.
149 * \param list [in] Array of proc entries to be added.
150 * \param data [in] The argument to be passed when entries read/write routines
151 * are called through /proc file.
153 * \retval 0 on success
157 lprocfs_add_vars(struct proc_dir_entry *root, struct lprocfs_vars *list,
160 if (root == NULL || list == NULL)
163 while (list->name != NULL) {
164 struct proc_dir_entry *proc;
167 if (list->proc_mode != 0000) {
168 mode = list->proc_mode;
169 } else if (list->fops) {
170 if (list->fops->read)
172 if (list->fops->write)
175 proc = proc_create_data(list->name, mode, root,
176 list->fops ?: &lprocfs_generic_fops,
184 EXPORT_SYMBOL(lprocfs_add_vars);
186 void ldebugfs_remove(struct dentry **entryp)
188 debugfs_remove_recursive(*entryp);
191 EXPORT_SYMBOL_GPL(ldebugfs_remove);
193 #ifndef HAVE_REMOVE_PROC_SUBTREE
194 /* for b=10866, global variable */
195 DECLARE_RWSEM(_lprocfs_lock);
196 EXPORT_SYMBOL(_lprocfs_lock);
198 static void lprocfs_remove_nolock(struct proc_dir_entry **proot)
200 struct proc_dir_entry *root = *proot;
201 struct proc_dir_entry *temp = root;
202 struct proc_dir_entry *rm_entry;
203 struct proc_dir_entry *parent;
206 if (root == NULL || IS_ERR(root))
209 parent = root->parent;
210 LASSERT(parent != NULL);
213 while (temp->subdir != NULL)
219 /* Memory corruption once caused this to fail, and
220 without this LASSERT we would loop here forever. */
221 LASSERTF(strlen(rm_entry->name) == rm_entry->namelen,
222 "0x%p %s/%s len %d\n", rm_entry, temp->name,
223 rm_entry->name, (int)strlen(rm_entry->name));
225 remove_proc_entry(rm_entry->name, temp);
231 int remove_proc_subtree(const char *name, struct proc_dir_entry *parent)
233 struct proc_dir_entry *t = NULL;
234 struct proc_dir_entry **p;
237 LASSERT(parent != NULL);
240 down_write(&_lprocfs_lock);
241 /* lookup target name */
242 for (p = &parent->subdir; *p; p = &(*p)->next) {
243 if ((*p)->namelen != len)
245 if (memcmp(name, (*p)->name, len))
252 /* verify it's empty: do not count "num_refs" */
253 for (p = &t->subdir; *p; p = &(*p)->next) {
254 if ((*p)->namelen != strlen("num_refs")) {
258 if (memcmp("num_refs", (*p)->name,
259 strlen("num_refs"))) {
267 lprocfs_remove_nolock(&t);
269 up_write(&_lprocfs_lock);
272 #endif /* !HAVE_REMOVE_PROC_SUBTREE */
274 #ifndef HAVE_PROC_REMOVE
275 void proc_remove(struct proc_dir_entry *de)
277 #ifndef HAVE_REMOVE_PROC_SUBTREE
278 down_write(&_lprocfs_lock); /* search vs remove race */
279 lprocfs_remove_nolock(&de);
280 up_write(&_lprocfs_lock);
283 remove_proc_subtree(de->name, de->parent);
288 void lprocfs_remove(struct proc_dir_entry **rooth)
293 EXPORT_SYMBOL(lprocfs_remove);
295 void lprocfs_remove_proc_entry(const char *name, struct proc_dir_entry *parent)
297 LASSERT(parent != NULL);
298 remove_proc_entry(name, parent);
300 EXPORT_SYMBOL(lprocfs_remove_proc_entry);
302 struct dentry *ldebugfs_register(const char *name, struct dentry *parent,
303 struct lprocfs_vars *list, void *data)
305 struct dentry *entry;
307 entry = debugfs_create_dir(name, parent);
308 if (IS_ERR_OR_NULL(entry)) {
309 entry = entry ?: ERR_PTR(-ENOMEM);
313 if (!IS_ERR_OR_NULL(list)) {
316 rc = ldebugfs_add_vars(entry, list, data);
318 debugfs_remove(entry);
325 EXPORT_SYMBOL_GPL(ldebugfs_register);
327 struct proc_dir_entry *
328 lprocfs_register(const char *name, struct proc_dir_entry *parent,
329 struct lprocfs_vars *list, void *data)
331 struct proc_dir_entry *newchild;
333 newchild = proc_mkdir(name, parent);
334 if (newchild == NULL)
335 return ERR_PTR(-ENOMEM);
338 int rc = lprocfs_add_vars(newchild, list, data);
340 lprocfs_remove(&newchild);
346 EXPORT_SYMBOL(lprocfs_register);
348 /* Generic callbacks */
349 int lprocfs_uint_seq_show(struct seq_file *m, void *data)
351 seq_printf(m, "%u\n", *(unsigned int *)data);
354 EXPORT_SYMBOL(lprocfs_uint_seq_show);
356 int lprocfs_wr_uint(struct file *file, const char __user *buffer,
357 unsigned long count, void *data)
360 char dummy[MAX_STRING_SIZE + 1];
364 if (count >= sizeof(dummy))
370 if (copy_from_user(dummy, buffer, count))
375 tmp = simple_strtoul(dummy, &end, 0);
379 *p = (unsigned int)tmp;
382 EXPORT_SYMBOL(lprocfs_wr_uint);
384 ssize_t lprocfs_uint_seq_write(struct file *file, const char __user *buffer,
385 size_t count, loff_t *off)
387 int *data = ((struct seq_file *)file->private_data)->private;
391 rc = lprocfs_str_to_s64(buffer, count, &val);
395 return lprocfs_wr_uint(file, buffer, count, data);
397 EXPORT_SYMBOL(lprocfs_uint_seq_write);
399 int lprocfs_u64_seq_show(struct seq_file *m, void *data)
401 LASSERT(data != NULL);
402 seq_printf(m, "%llu\n", *(__u64 *)data);
405 EXPORT_SYMBOL(lprocfs_u64_seq_show);
407 int lprocfs_atomic_seq_show(struct seq_file *m, void *data)
409 atomic_t *atom = data;
410 LASSERT(atom != NULL);
411 seq_printf(m, "%d\n", atomic_read(atom));
414 EXPORT_SYMBOL(lprocfs_atomic_seq_show);
417 lprocfs_atomic_seq_write(struct file *file, const char __user *buffer,
418 size_t count, loff_t *off)
420 atomic_t *atm = ((struct seq_file *)file->private_data)->private;
424 rc = lprocfs_str_to_s64(buffer, count, &val);
428 if (val <= 0 || val > INT_MAX)
431 atomic_set(atm, val);
434 EXPORT_SYMBOL(lprocfs_atomic_seq_write);
436 int lprocfs_uuid_seq_show(struct seq_file *m, void *data)
438 struct obd_device *obd = data;
440 LASSERT(obd != NULL);
441 seq_printf(m, "%s\n", obd->obd_uuid.uuid);
444 EXPORT_SYMBOL(lprocfs_uuid_seq_show);
446 static ssize_t uuid_show(struct kobject *kobj, struct attribute *attr,
449 struct obd_device *obd = container_of(kobj, struct obd_device,
452 return sprintf(buf, "%s\n", obd->obd_uuid.uuid);
454 LUSTRE_RO_ATTR(uuid);
456 int lprocfs_name_seq_show(struct seq_file *m, void *data)
458 struct obd_device *dev = data;
460 LASSERT(dev != NULL);
461 seq_printf(m, "%s\n", dev->obd_name);
464 EXPORT_SYMBOL(lprocfs_name_seq_show);
466 static ssize_t blocksize_show(struct kobject *kobj, struct attribute *attr,
469 struct obd_device *obd = container_of(kobj, struct obd_device,
471 struct obd_statfs osfs;
474 rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
475 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
478 return sprintf(buf, "%u\n", osfs.os_bsize);
482 LUSTRE_RO_ATTR(blocksize);
484 static ssize_t kbytestotal_show(struct kobject *kobj, struct attribute *attr,
487 struct obd_device *obd = container_of(kobj, struct obd_device,
489 struct obd_statfs osfs;
492 rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
493 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
496 u32 blk_size = osfs.os_bsize >> 10;
497 u64 result = osfs.os_blocks;
499 while (blk_size >>= 1)
502 return sprintf(buf, "%llu\n", result);
507 LUSTRE_RO_ATTR(kbytestotal);
509 static ssize_t kbytesfree_show(struct kobject *kobj, struct attribute *attr,
512 struct obd_device *obd = container_of(kobj, struct obd_device,
514 struct obd_statfs osfs;
517 rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
518 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
521 u32 blk_size = osfs.os_bsize >> 10;
522 u64 result = osfs.os_bfree;
524 while (blk_size >>= 1)
527 return sprintf(buf, "%llu\n", result);
532 LUSTRE_RO_ATTR(kbytesfree);
534 static ssize_t kbytesavail_show(struct kobject *kobj, struct attribute *attr,
537 struct obd_device *obd = container_of(kobj, struct obd_device,
539 struct obd_statfs osfs;
542 rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
543 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
546 u32 blk_size = osfs.os_bsize >> 10;
547 u64 result = osfs.os_bavail;
549 while (blk_size >>= 1)
552 return sprintf(buf, "%llu\n", result);
557 LUSTRE_RO_ATTR(kbytesavail);
559 static ssize_t filestotal_show(struct kobject *kobj, struct attribute *attr,
562 struct obd_device *obd = container_of(kobj, struct obd_device,
564 struct obd_statfs osfs;
567 rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
568 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
571 return sprintf(buf, "%llu\n", osfs.os_files);
575 LUSTRE_RO_ATTR(filestotal);
577 static ssize_t filesfree_show(struct kobject *kobj, struct attribute *attr,
580 struct obd_device *obd = container_of(kobj, struct obd_device,
582 struct obd_statfs osfs;
585 rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
586 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
589 return sprintf(buf, "%llu\n", osfs.os_ffree);
593 LUSTRE_RO_ATTR(filesfree);
595 int lprocfs_server_uuid_seq_show(struct seq_file *m, void *data)
597 struct obd_device *obd = data;
598 struct obd_import *imp;
599 char *imp_state_name = NULL;
602 LASSERT(obd != NULL);
603 LPROCFS_CLIMP_CHECK(obd);
604 imp = obd->u.cli.cl_import;
605 imp_state_name = ptlrpc_import_state_name(imp->imp_state);
606 seq_printf(m, "%s\t%s%s\n", obd2cli_tgt(obd), imp_state_name,
607 imp->imp_deactive ? "\tDEACTIVATED" : "");
609 LPROCFS_CLIMP_EXIT(obd);
612 EXPORT_SYMBOL(lprocfs_server_uuid_seq_show);
614 int lprocfs_conn_uuid_seq_show(struct seq_file *m, void *data)
616 struct obd_device *obd = data;
617 struct ptlrpc_connection *conn;
620 LASSERT(obd != NULL);
622 LPROCFS_CLIMP_CHECK(obd);
623 conn = obd->u.cli.cl_import->imp_connection;
624 if (conn && obd->u.cli.cl_import)
625 seq_printf(m, "%s\n", conn->c_remote_uuid.uuid);
627 seq_printf(m, "%s\n", "<none>");
629 LPROCFS_CLIMP_EXIT(obd);
632 EXPORT_SYMBOL(lprocfs_conn_uuid_seq_show);
634 /** add up per-cpu counters */
637 * Lock statistics structure for access, possibly only on this CPU.
639 * The statistics struct may be allocated with per-CPU structures for
640 * efficient concurrent update (usually only on server-wide stats), or
641 * as a single global struct (e.g. for per-client or per-job statistics),
642 * so the required locking depends on the type of structure allocated.
644 * For per-CPU statistics, pin the thread to the current cpuid so that
645 * will only access the statistics for that CPU. If the stats structure
646 * for the current CPU has not been allocated (or previously freed),
647 * allocate it now. The per-CPU statistics do not need locking since
648 * the thread is pinned to the CPU during update.
650 * For global statistics, lock the stats structure to prevent concurrent update.
652 * \param[in] stats statistics structure to lock
653 * \param[in] opc type of operation:
654 * LPROCFS_GET_SMP_ID: "lock" and return current CPU index
655 * for incrementing statistics for that CPU
656 * LPROCFS_GET_NUM_CPU: "lock" and return number of used
657 * CPU indices to iterate over all indices
658 * \param[out] flags CPU interrupt saved state for IRQ-safe locking
660 * \retval cpuid of current thread or number of allocated structs
661 * \retval negative on error (only for opc LPROCFS_GET_SMP_ID + per-CPU stats)
663 int lprocfs_stats_lock(struct lprocfs_stats *stats,
664 enum lprocfs_stats_lock_ops opc,
665 unsigned long *flags)
667 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
668 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
669 spin_lock_irqsave(&stats->ls_lock, *flags);
671 spin_lock(&stats->ls_lock);
672 return opc == LPROCFS_GET_NUM_CPU ? 1 : 0;
676 case LPROCFS_GET_SMP_ID: {
677 unsigned int cpuid = get_cpu();
679 if (unlikely(!stats->ls_percpu[cpuid])) {
680 int rc = lprocfs_stats_alloc_one(stats, cpuid);
689 case LPROCFS_GET_NUM_CPU:
690 return stats->ls_biggest_alloc_num;
697 * Unlock statistics structure after access.
699 * Unlock the lock acquired via lprocfs_stats_lock() for global statistics,
700 * or unpin this thread from the current cpuid for per-CPU statistics.
702 * This function must be called using the same arguments as used when calling
703 * lprocfs_stats_lock() so that the correct operation can be performed.
705 * \param[in] stats statistics structure to unlock
706 * \param[in] opc type of operation (current cpuid or number of structs)
707 * \param[in] flags CPU interrupt saved state for IRQ-safe locking
709 void lprocfs_stats_unlock(struct lprocfs_stats *stats,
710 enum lprocfs_stats_lock_ops opc,
711 unsigned long *flags)
713 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
714 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
715 spin_unlock_irqrestore(&stats->ls_lock, *flags);
717 spin_unlock(&stats->ls_lock);
718 } else if (opc == LPROCFS_GET_SMP_ID) {
723 /** add up per-cpu counters */
724 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
725 struct lprocfs_counter *cnt)
727 unsigned int num_entry;
728 struct lprocfs_counter *percpu_cntr;
730 unsigned long flags = 0;
732 memset(cnt, 0, sizeof(*cnt));
735 /* set count to 1 to avoid divide-by-zero errs in callers */
740 cnt->lc_min = LC_MIN_INIT;
742 num_entry = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
744 for (i = 0; i < num_entry; i++) {
745 if (stats->ls_percpu[i] == NULL)
747 percpu_cntr = lprocfs_stats_counter_get(stats, i, idx);
749 cnt->lc_count += percpu_cntr->lc_count;
750 cnt->lc_sum += percpu_cntr->lc_sum;
751 if (percpu_cntr->lc_min < cnt->lc_min)
752 cnt->lc_min = percpu_cntr->lc_min;
753 if (percpu_cntr->lc_max > cnt->lc_max)
754 cnt->lc_max = percpu_cntr->lc_max;
755 cnt->lc_sumsquare += percpu_cntr->lc_sumsquare;
758 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
761 static void obd_import_flags2str(struct obd_import *imp, struct seq_file *m)
765 if (imp->imp_obd->obd_no_recov) {
766 seq_printf(m, "no_recov");
770 flag2str(imp, invalid);
771 flag2str(imp, deactive);
772 flag2str(imp, replayable);
773 flag2str(imp, delayed_recovery);
774 flag2str(imp, vbr_failed);
775 flag2str(imp, pingable);
776 flag2str(imp, resend_replay);
777 flag2str(imp, no_pinger_recover);
778 flag2str(imp, need_mne_swab);
779 flag2str(imp, connect_tried);
782 static const char *obd_connect_names[] = {
801 "remote_client_by_force",
810 "mds_mds_connection",
813 "alt_checksum_algorithm",
854 void obd_connect_seq_flags2str(struct seq_file *m, __u64 flags, __u64 flags2,
861 for (i = 0, mask = 1; i < 64; i++, mask <<= 1) {
863 seq_printf(m, "%s%s",
864 first ? "" : sep, obd_connect_names[i]);
869 if (flags & ~(mask - 1)) {
870 seq_printf(m, "%sunknown_%#llx",
871 first ? "" : sep, flags & ~(mask - 1));
875 if (!(flags & OBD_CONNECT_FLAGS2) || flags2 == 0)
878 for (i = 64, mask = 1; obd_connect_names[i] != NULL; i++, mask <<= 1) {
880 seq_printf(m, "%s%s",
881 first ? "" : sep, obd_connect_names[i]);
886 if (flags2 & ~(mask - 1)) {
887 seq_printf(m, "%sunknown2_%#llx",
888 first ? "" : sep, flags2 & ~(mask - 1));
892 EXPORT_SYMBOL(obd_connect_seq_flags2str);
894 int obd_connect_flags2str(char *page, int count, __u64 flags, __u64 flags2,
900 for (i = 0, mask = 1; i < 64; i++, mask <<= 1) {
902 ret += snprintf(page + ret, count - ret, "%s%s",
903 ret ? sep : "", obd_connect_names[i]);
906 if (flags & ~(mask - 1))
907 ret += snprintf(page + ret, count - ret,
909 ret ? sep : "", flags & ~(mask - 1));
911 if (!(flags & OBD_CONNECT_FLAGS2) || flags2 == 0)
914 for (i = 64, mask = 1; obd_connect_names[i] != NULL; i++, mask <<= 1) {
916 ret += snprintf(page + ret, count - ret, "%s%s",
917 ret ? sep : "", obd_connect_names[i]);
920 if (flags2 & ~(mask - 1))
921 ret += snprintf(page + ret, count - ret,
923 ret ? sep : "", flags2 & ~(mask - 1));
927 EXPORT_SYMBOL(obd_connect_flags2str);
930 obd_connect_data_seqprint(struct seq_file *m, struct obd_connect_data *ocd)
934 LASSERT(ocd != NULL);
935 flags = ocd->ocd_connect_flags;
937 seq_printf(m, " connect_data:\n"
940 ocd->ocd_connect_flags,
942 if (flags & OBD_CONNECT_VERSION)
943 seq_printf(m, " target_version: %u.%u.%u.%u\n",
944 OBD_OCD_VERSION_MAJOR(ocd->ocd_version),
945 OBD_OCD_VERSION_MINOR(ocd->ocd_version),
946 OBD_OCD_VERSION_PATCH(ocd->ocd_version),
947 OBD_OCD_VERSION_FIX(ocd->ocd_version));
948 if (flags & OBD_CONNECT_MDS)
949 seq_printf(m, " mdt_index: %d\n", ocd->ocd_group);
950 if (flags & OBD_CONNECT_GRANT)
951 seq_printf(m, " initial_grant: %d\n", ocd->ocd_grant);
952 if (flags & OBD_CONNECT_INDEX)
953 seq_printf(m, " target_index: %u\n", ocd->ocd_index);
954 if (flags & OBD_CONNECT_BRW_SIZE)
955 seq_printf(m, " max_brw_size: %d\n", ocd->ocd_brw_size);
956 if (flags & OBD_CONNECT_IBITS)
957 seq_printf(m, " ibits_known: %#llx\n",
958 ocd->ocd_ibits_known);
959 if (flags & OBD_CONNECT_GRANT_PARAM)
960 seq_printf(m, " grant_block_size: %d\n"
961 " grant_inode_size: %d\n"
962 " grant_max_extent_size: %d\n"
963 " grant_extent_tax: %d\n",
964 1 << ocd->ocd_grant_blkbits,
965 1 << ocd->ocd_grant_inobits,
966 ocd->ocd_grant_max_blks << ocd->ocd_grant_blkbits,
967 ocd->ocd_grant_tax_kb << 10);
968 if (flags & OBD_CONNECT_TRANSNO)
969 seq_printf(m, " first_transno: %#llx\n",
971 if (flags & OBD_CONNECT_CKSUM)
972 seq_printf(m, " cksum_types: %#x\n",
973 ocd->ocd_cksum_types);
974 if (flags & OBD_CONNECT_MAX_EASIZE)
975 seq_printf(m, " max_easize: %d\n", ocd->ocd_max_easize);
976 if (flags & OBD_CONNECT_MAXBYTES)
977 seq_printf(m, " max_object_bytes: %llu\n",
979 if (flags & OBD_CONNECT_MULTIMODRPCS)
980 seq_printf(m, " max_mod_rpcs: %hu\n",
981 ocd->ocd_maxmodrpcs);
984 int lprocfs_import_seq_show(struct seq_file *m, void *data)
986 char nidstr[LNET_NIDSTR_SIZE];
987 struct lprocfs_counter ret;
988 struct lprocfs_counter_header *header;
989 struct obd_device *obd = (struct obd_device *)data;
990 struct obd_import *imp;
991 struct obd_import_conn *conn;
992 struct obd_connect_data *ocd;
997 LASSERT(obd != NULL);
998 LPROCFS_CLIMP_CHECK(obd);
999 imp = obd->u.cli.cl_import;
1000 ocd = &imp->imp_connect_data;
1002 seq_printf(m, "import:\n"
1006 " connect_flags: [ ",
1009 ptlrpc_import_state_name(imp->imp_state));
1010 obd_connect_seq_flags2str(m, imp->imp_connect_data.ocd_connect_flags,
1011 imp->imp_connect_data.ocd_connect_flags2,
1013 seq_printf(m, " ]\n");
1014 obd_connect_data_seqprint(m, ocd);
1015 seq_printf(m, " import_flags: [ ");
1016 obd_import_flags2str(imp, m);
1018 seq_printf(m, " ]\n"
1020 " failover_nids: [ ");
1021 spin_lock(&imp->imp_lock);
1023 list_for_each_entry(conn, &imp->imp_conn_list, oic_item) {
1024 libcfs_nid2str_r(conn->oic_conn->c_peer.nid,
1025 nidstr, sizeof(nidstr));
1026 seq_printf(m, "%s%s", j ? ", " : "", nidstr);
1029 if (imp->imp_connection != NULL)
1030 libcfs_nid2str_r(imp->imp_connection->c_peer.nid,
1031 nidstr, sizeof(nidstr));
1033 strncpy(nidstr, "<none>", sizeof(nidstr));
1034 seq_printf(m, " ]\n"
1035 " current_connection: %s\n"
1036 " connection_attempts: %u\n"
1038 " in-progress_invalidations: %u\n",
1041 imp->imp_generation,
1042 atomic_read(&imp->imp_inval_count));
1043 spin_unlock(&imp->imp_lock);
1045 if (obd->obd_svc_stats == NULL)
1048 header = &obd->obd_svc_stats->ls_cnt_header[PTLRPC_REQWAIT_CNTR];
1049 lprocfs_stats_collect(obd->obd_svc_stats, PTLRPC_REQWAIT_CNTR, &ret);
1050 if (ret.lc_count != 0) {
1051 /* first argument to do_div MUST be __u64 */
1052 __u64 sum = ret.lc_sum;
1053 do_div(sum, ret.lc_count);
1057 seq_printf(m, " rpcs:\n"
1059 " unregistering: %u\n"
1061 " avg_waittime: %llu %s\n",
1062 atomic_read(&imp->imp_inflight),
1063 atomic_read(&imp->imp_unregistering),
1064 atomic_read(&imp->imp_timeouts),
1065 ret.lc_sum, header->lc_units);
1068 for(j = 0; j < IMP_AT_MAX_PORTALS; j++) {
1069 if (imp->imp_at.iat_portal[j] == 0)
1071 k = max_t(unsigned int, k,
1072 at_get(&imp->imp_at.iat_service_estimate[j]));
1074 seq_printf(m, " service_estimates:\n"
1075 " services: %u sec\n"
1076 " network: %u sec\n",
1078 at_get(&imp->imp_at.iat_net_latency));
1080 seq_printf(m, " transactions:\n"
1081 " last_replay: %llu\n"
1082 " peer_committed: %llu\n"
1083 " last_checked: %llu\n",
1084 imp->imp_last_replay_transno,
1085 imp->imp_peer_committed_transno,
1086 imp->imp_last_transno_checked);
1088 /* avg data rates */
1089 for (rw = 0; rw <= 1; rw++) {
1090 lprocfs_stats_collect(obd->obd_svc_stats,
1091 PTLRPC_LAST_CNTR + BRW_READ_BYTES + rw,
1093 if (ret.lc_sum > 0 && ret.lc_count > 0) {
1094 /* first argument to do_div MUST be __u64 */
1095 __u64 sum = ret.lc_sum;
1096 do_div(sum, ret.lc_count);
1098 seq_printf(m, " %s_data_averages:\n"
1099 " bytes_per_rpc: %llu\n",
1100 rw ? "write" : "read",
1103 k = (int)ret.lc_sum;
1104 j = opcode_offset(OST_READ + rw) + EXTRA_MAX_OPCODES;
1105 header = &obd->obd_svc_stats->ls_cnt_header[j];
1106 lprocfs_stats_collect(obd->obd_svc_stats, j, &ret);
1107 if (ret.lc_sum > 0 && ret.lc_count != 0) {
1108 /* first argument to do_div MUST be __u64 */
1109 __u64 sum = ret.lc_sum;
1110 do_div(sum, ret.lc_count);
1112 seq_printf(m, " %s_per_rpc: %llu\n",
1113 header->lc_units, ret.lc_sum);
1114 j = (int)ret.lc_sum;
1116 seq_printf(m, " MB_per_sec: %u.%.02u\n",
1117 k / j, (100 * k / j) % 100);
1122 LPROCFS_CLIMP_EXIT(obd);
1125 EXPORT_SYMBOL(lprocfs_import_seq_show);
1127 int lprocfs_state_seq_show(struct seq_file *m, void *data)
1129 struct obd_device *obd = (struct obd_device *)data;
1130 struct obd_import *imp;
1133 LASSERT(obd != NULL);
1134 LPROCFS_CLIMP_CHECK(obd);
1135 imp = obd->u.cli.cl_import;
1137 seq_printf(m, "current_state: %s\n",
1138 ptlrpc_import_state_name(imp->imp_state));
1139 seq_printf(m, "state_history:\n");
1140 k = imp->imp_state_hist_idx;
1141 for (j = 0; j < IMP_STATE_HIST_LEN; j++) {
1142 struct import_state_hist *ish =
1143 &imp->imp_state_hist[(k + j) % IMP_STATE_HIST_LEN];
1144 if (ish->ish_state == 0)
1146 seq_printf(m, " - [ %lld, %s ]\n", (s64)ish->ish_time,
1147 ptlrpc_import_state_name(ish->ish_state));
1150 LPROCFS_CLIMP_EXIT(obd);
1153 EXPORT_SYMBOL(lprocfs_state_seq_show);
1155 int lprocfs_at_hist_helper(struct seq_file *m, struct adaptive_timeout *at)
1158 for (i = 0; i < AT_BINS; i++)
1159 seq_printf(m, "%3u ", at->at_hist[i]);
1160 seq_printf(m, "\n");
1163 EXPORT_SYMBOL(lprocfs_at_hist_helper);
1165 /* See also ptlrpc_lprocfs_timeouts_show_seq */
1166 int lprocfs_timeouts_seq_show(struct seq_file *m, void *data)
1168 struct obd_device *obd = (struct obd_device *)data;
1169 struct obd_import *imp;
1170 unsigned int cur, worst;
1171 time64_t now, worstt;
1174 LASSERT(obd != NULL);
1175 LPROCFS_CLIMP_CHECK(obd);
1176 imp = obd->u.cli.cl_import;
1178 now = ktime_get_real_seconds();
1180 /* Some network health info for kicks */
1181 seq_printf(m, "%-10s : %lld, %llds ago\n",
1182 "last reply", (s64)imp->imp_last_reply_time,
1183 (s64)(now - imp->imp_last_reply_time));
1185 cur = at_get(&imp->imp_at.iat_net_latency);
1186 worst = imp->imp_at.iat_net_latency.at_worst_ever;
1187 worstt = imp->imp_at.iat_net_latency.at_worst_time;
1188 seq_printf(m, "%-10s : cur %3u worst %3u (at %lld, %llds ago) ",
1189 "network", cur, worst, (s64)worstt, (s64)(now - worstt));
1190 lprocfs_at_hist_helper(m, &imp->imp_at.iat_net_latency);
1192 for(i = 0; i < IMP_AT_MAX_PORTALS; i++) {
1193 if (imp->imp_at.iat_portal[i] == 0)
1195 cur = at_get(&imp->imp_at.iat_service_estimate[i]);
1196 worst = imp->imp_at.iat_service_estimate[i].at_worst_ever;
1197 worstt = imp->imp_at.iat_service_estimate[i].at_worst_time;
1198 seq_printf(m, "portal %-2d : cur %3u worst %3u (at %lld, %llds ago) ",
1199 imp->imp_at.iat_portal[i], cur, worst, (s64)worstt,
1200 (s64)(now - worstt));
1201 lprocfs_at_hist_helper(m, &imp->imp_at.iat_service_estimate[i]);
1204 LPROCFS_CLIMP_EXIT(obd);
1207 EXPORT_SYMBOL(lprocfs_timeouts_seq_show);
1209 int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data)
1211 struct obd_device *obd = data;
1215 LPROCFS_CLIMP_CHECK(obd);
1216 flags = obd->u.cli.cl_import->imp_connect_data.ocd_connect_flags;
1217 flags2 = obd->u.cli.cl_import->imp_connect_data.ocd_connect_flags2;
1218 seq_printf(m, "flags=%#llx\n", flags);
1219 seq_printf(m, "flags2=%#llx\n", flags2);
1220 obd_connect_seq_flags2str(m, flags, flags2, "\n");
1221 seq_printf(m, "\n");
1222 LPROCFS_CLIMP_EXIT(obd);
1225 EXPORT_SYMBOL(lprocfs_connect_flags_seq_show);
1227 static struct attribute *obd_def_uuid_attrs[] = {
1228 &lustre_attr_uuid.attr,
1232 static struct attribute *obd_def_attrs[] = {
1233 &lustre_attr_blocksize.attr,
1234 &lustre_attr_kbytestotal.attr,
1235 &lustre_attr_kbytesfree.attr,
1236 &lustre_attr_kbytesavail.attr,
1237 &lustre_attr_filestotal.attr,
1238 &lustre_attr_filesfree.attr,
1239 &lustre_attr_uuid.attr,
1243 static void obd_sysfs_release(struct kobject *kobj)
1245 struct obd_device *obd = container_of(kobj, struct obd_device,
1248 complete(&obd->obd_kobj_unregister);
1251 int lprocfs_obd_setup(struct obd_device *obd, bool uuid_only)
1255 if (!obd || obd->obd_magic != OBD_DEVICE_MAGIC)
1258 rc = kobject_set_name(&obd->obd_kset.kobj, "%s", obd->obd_name);
1262 obd->obd_ktype.sysfs_ops = &lustre_sysfs_ops;
1263 obd->obd_ktype.release = obd_sysfs_release;
1265 obd->obd_ktype.default_attrs = obd->obd_attrs;
1267 obd->obd_kset.kobj.parent = &obd->obd_type->typ_kobj;
1268 obd->obd_kset.kobj.ktype = &obd->obd_ktype;
1269 init_completion(&obd->obd_kobj_unregister);
1270 rc = kset_register(&obd->obd_kset);
1275 obd->obd_attrs_group.attrs = obd_def_uuid_attrs;
1277 obd->obd_attrs_group.attrs = obd_def_attrs;
1279 rc = sysfs_create_group(&obd->obd_kset.kobj, &obd->obd_attrs_group);
1281 kset_unregister(&obd->obd_kset);
1285 if (obd->obd_proc_entry)
1286 GOTO(already_registered, rc);
1288 LASSERT(obd->obd_type->typ_procroot != NULL);
1290 obd->obd_proc_entry = lprocfs_register(obd->obd_name,
1291 obd->obd_type->typ_procroot,
1292 obd->obd_vars, obd);
1293 if (IS_ERR(obd->obd_proc_entry)) {
1294 rc = PTR_ERR(obd->obd_proc_entry);
1295 CERROR("error %d setting up lprocfs for %s\n",rc,obd->obd_name);
1296 obd->obd_proc_entry = NULL;
1297 lprocfs_obd_cleanup(obd);
1302 EXPORT_SYMBOL(lprocfs_obd_setup);
1304 int lprocfs_obd_cleanup(struct obd_device *obd)
1309 if (obd->obd_proc_exports_entry) {
1310 /* Should be no exports left */
1311 lprocfs_remove(&obd->obd_proc_exports_entry);
1312 obd->obd_proc_exports_entry = NULL;
1315 if (obd->obd_proc_entry) {
1316 lprocfs_remove(&obd->obd_proc_entry);
1317 obd->obd_proc_entry = NULL;
1320 sysfs_remove_group(&obd->obd_kset.kobj, &obd->obd_attrs_group);
1321 kset_unregister(&obd->obd_kset);
1322 wait_for_completion(&obd->obd_kobj_unregister);
1326 EXPORT_SYMBOL(lprocfs_obd_cleanup);
1328 int lprocfs_stats_alloc_one(struct lprocfs_stats *stats, unsigned int cpuid)
1330 struct lprocfs_counter *cntr;
1331 unsigned int percpusize;
1333 unsigned long flags = 0;
1336 LASSERT(stats->ls_percpu[cpuid] == NULL);
1337 LASSERT((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0);
1339 percpusize = lprocfs_stats_counter_size(stats);
1340 LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[cpuid], percpusize);
1341 if (stats->ls_percpu[cpuid] != NULL) {
1343 if (unlikely(stats->ls_biggest_alloc_num <= cpuid)) {
1344 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
1345 spin_lock_irqsave(&stats->ls_lock, flags);
1347 spin_lock(&stats->ls_lock);
1348 if (stats->ls_biggest_alloc_num <= cpuid)
1349 stats->ls_biggest_alloc_num = cpuid + 1;
1350 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) {
1351 spin_unlock_irqrestore(&stats->ls_lock, flags);
1353 spin_unlock(&stats->ls_lock);
1356 /* initialize the ls_percpu[cpuid] non-zero counter */
1357 for (i = 0; i < stats->ls_num; ++i) {
1358 cntr = lprocfs_stats_counter_get(stats, cpuid, i);
1359 cntr->lc_min = LC_MIN_INIT;
1365 struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num,
1366 enum lprocfs_stats_flags flags)
1368 struct lprocfs_stats *stats;
1369 unsigned int num_entry;
1370 unsigned int percpusize = 0;
1376 if (lprocfs_no_percpu_stats != 0)
1377 flags |= LPROCFS_STATS_FLAG_NOPERCPU;
1379 if (flags & LPROCFS_STATS_FLAG_NOPERCPU)
1382 num_entry = num_possible_cpus();
1384 /* alloc percpu pointers for all possible cpu slots */
1385 LIBCFS_ALLOC(stats, offsetof(typeof(*stats), ls_percpu[num_entry]));
1389 stats->ls_num = num;
1390 stats->ls_flags = flags;
1391 spin_lock_init(&stats->ls_lock);
1393 /* alloc num of counter headers */
1394 LIBCFS_ALLOC(stats->ls_cnt_header,
1395 stats->ls_num * sizeof(struct lprocfs_counter_header));
1396 if (stats->ls_cnt_header == NULL)
1399 if ((flags & LPROCFS_STATS_FLAG_NOPERCPU) != 0) {
1400 /* contains only one set counters */
1401 percpusize = lprocfs_stats_counter_size(stats);
1402 LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[0], percpusize);
1403 if (stats->ls_percpu[0] == NULL)
1405 stats->ls_biggest_alloc_num = 1;
1406 } else if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0) {
1407 /* alloc all percpu data, currently only obd_memory use this */
1408 for (i = 0; i < num_entry; ++i)
1409 if (lprocfs_stats_alloc_one(stats, i) < 0)
1416 lprocfs_free_stats(&stats);
1419 EXPORT_SYMBOL(lprocfs_alloc_stats);
1421 void lprocfs_free_stats(struct lprocfs_stats **statsh)
1423 struct lprocfs_stats *stats = *statsh;
1424 unsigned int num_entry;
1425 unsigned int percpusize;
1428 if (stats == NULL || stats->ls_num == 0)
1432 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU)
1435 num_entry = num_possible_cpus();
1437 percpusize = lprocfs_stats_counter_size(stats);
1438 for (i = 0; i < num_entry; i++)
1439 if (stats->ls_percpu[i] != NULL)
1440 LIBCFS_FREE(stats->ls_percpu[i], percpusize);
1441 if (stats->ls_cnt_header != NULL)
1442 LIBCFS_FREE(stats->ls_cnt_header, stats->ls_num *
1443 sizeof(struct lprocfs_counter_header));
1444 LIBCFS_FREE(stats, offsetof(typeof(*stats), ls_percpu[num_entry]));
1446 EXPORT_SYMBOL(lprocfs_free_stats);
1448 u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
1449 enum lprocfs_fields_flags field)
1451 unsigned long flags = 0;
1452 unsigned int num_cpu;
1458 num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1459 for (i = 0; i < num_cpu; i++) {
1460 struct lprocfs_counter *cntr;
1462 if (!stats->ls_percpu[i])
1465 cntr = lprocfs_stats_counter_get(stats, i, idx);
1466 ret += lprocfs_read_helper(cntr, &stats->ls_cnt_header[idx],
1467 stats->ls_flags, field);
1469 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1472 EXPORT_SYMBOL(lprocfs_stats_collector);
1474 void lprocfs_clear_stats(struct lprocfs_stats *stats)
1476 struct lprocfs_counter *percpu_cntr;
1479 unsigned int num_entry;
1480 unsigned long flags = 0;
1482 num_entry = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1484 for (i = 0; i < num_entry; i++) {
1485 if (stats->ls_percpu[i] == NULL)
1487 for (j = 0; j < stats->ls_num; j++) {
1488 percpu_cntr = lprocfs_stats_counter_get(stats, i, j);
1489 percpu_cntr->lc_count = 0;
1490 percpu_cntr->lc_min = LC_MIN_INIT;
1491 percpu_cntr->lc_max = 0;
1492 percpu_cntr->lc_sumsquare = 0;
1493 percpu_cntr->lc_sum = 0;
1494 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
1495 percpu_cntr->lc_sum_irq = 0;
1499 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1501 EXPORT_SYMBOL(lprocfs_clear_stats);
1503 static ssize_t lprocfs_stats_seq_write(struct file *file,
1504 const char __user *buf,
1505 size_t len, loff_t *off)
1507 struct seq_file *seq = file->private_data;
1508 struct lprocfs_stats *stats = seq->private;
1510 lprocfs_clear_stats(stats);
1515 static void *lprocfs_stats_seq_start(struct seq_file *p, loff_t *pos)
1517 struct lprocfs_stats *stats = p->private;
1519 return (*pos < stats->ls_num) ? pos : NULL;
1522 static void lprocfs_stats_seq_stop(struct seq_file *p, void *v)
1526 static void *lprocfs_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
1530 return lprocfs_stats_seq_start(p, pos);
1533 /* seq file export of one lprocfs counter */
1534 static int lprocfs_stats_seq_show(struct seq_file *p, void *v)
1536 struct lprocfs_stats *stats = p->private;
1537 struct lprocfs_counter_header *hdr;
1538 struct lprocfs_counter ctr;
1539 int idx = *(loff_t *)v;
1542 struct timespec64 now;
1544 ktime_get_real_ts64(&now);
1545 seq_printf(p, "%-25s %llu.%09lu secs.nsecs\n",
1546 "snapshot_time", (s64)now.tv_sec, now.tv_nsec);
1549 hdr = &stats->ls_cnt_header[idx];
1550 lprocfs_stats_collect(stats, idx, &ctr);
1552 if (ctr.lc_count == 0)
1555 seq_printf(p, "%-25s %lld samples [%s]", hdr->lc_name,
1556 ctr.lc_count, hdr->lc_units);
1558 if ((hdr->lc_config & LPROCFS_CNTR_AVGMINMAX) && ctr.lc_count > 0) {
1559 seq_printf(p, " %lld %lld %lld",
1560 ctr.lc_min, ctr.lc_max, ctr.lc_sum);
1561 if (hdr->lc_config & LPROCFS_CNTR_STDDEV)
1562 seq_printf(p, " %llu", ctr.lc_sumsquare);
1568 static const struct seq_operations lprocfs_stats_seq_sops = {
1569 .start = lprocfs_stats_seq_start,
1570 .stop = lprocfs_stats_seq_stop,
1571 .next = lprocfs_stats_seq_next,
1572 .show = lprocfs_stats_seq_show,
1575 static int lprocfs_stats_seq_open(struct inode *inode, struct file *file)
1577 struct seq_file *seq;
1580 rc = LPROCFS_ENTRY_CHECK(inode);
1584 rc = seq_open(file, &lprocfs_stats_seq_sops);
1587 seq = file->private_data;
1588 seq->private = inode->i_private ? : PDE_DATA(inode);
1592 static const struct file_operations lprocfs_stats_seq_fops = {
1593 .owner = THIS_MODULE,
1594 .open = lprocfs_stats_seq_open,
1596 .write = lprocfs_stats_seq_write,
1597 .llseek = seq_lseek,
1598 .release = lprocfs_seq_release,
1601 int ldebugfs_register_stats(struct dentry *parent, const char *name,
1602 struct lprocfs_stats *stats)
1604 struct dentry *entry;
1606 LASSERT(!IS_ERR_OR_NULL(parent));
1608 entry = debugfs_create_file(name, 0644, parent, stats,
1609 &lprocfs_stats_seq_fops);
1610 if (IS_ERR_OR_NULL(entry))
1611 return entry ? PTR_ERR(entry) : -ENOMEM;
1615 EXPORT_SYMBOL_GPL(ldebugfs_register_stats);
1617 int lprocfs_register_stats(struct proc_dir_entry *root, const char *name,
1618 struct lprocfs_stats *stats)
1620 struct proc_dir_entry *entry;
1621 LASSERT(root != NULL);
1623 entry = proc_create_data(name, 0644, root,
1624 &lprocfs_stats_seq_fops, stats);
1629 EXPORT_SYMBOL(lprocfs_register_stats);
1631 void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
1632 unsigned conf, const char *name, const char *units)
1634 struct lprocfs_counter_header *header;
1635 struct lprocfs_counter *percpu_cntr;
1636 unsigned long flags = 0;
1638 unsigned int num_cpu;
1640 LASSERT(stats != NULL);
1642 header = &stats->ls_cnt_header[index];
1643 LASSERTF(header != NULL, "Failed to allocate stats header:[%d]%s/%s\n",
1644 index, name, units);
1646 header->lc_config = conf;
1647 header->lc_name = name;
1648 header->lc_units = units;
1650 num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1651 for (i = 0; i < num_cpu; ++i) {
1652 if (stats->ls_percpu[i] == NULL)
1654 percpu_cntr = lprocfs_stats_counter_get(stats, i, index);
1655 percpu_cntr->lc_count = 0;
1656 percpu_cntr->lc_min = LC_MIN_INIT;
1657 percpu_cntr->lc_max = 0;
1658 percpu_cntr->lc_sumsquare = 0;
1659 percpu_cntr->lc_sum = 0;
1660 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
1661 percpu_cntr->lc_sum_irq = 0;
1663 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1665 EXPORT_SYMBOL(lprocfs_counter_init);
1667 /* Note that we only init md counters for ops whose offset is less
1668 * than NUM_MD_STATS. This is explained in a comment in the definition
1669 * of struct md_ops. */
1670 #define LPROCFS_MD_OP_INIT(base, stats, op) \
1672 unsigned int _idx = base + MD_COUNTER_OFFSET(op); \
1674 if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS) { \
1675 LASSERT(_idx < stats->ls_num); \
1676 lprocfs_counter_init(stats, _idx, 0, #op, "reqs"); \
1680 void lprocfs_init_mps_stats(int num_private_stats, struct lprocfs_stats *stats)
1682 LPROCFS_MD_OP_INIT(num_private_stats, stats, get_root);
1683 LPROCFS_MD_OP_INIT(num_private_stats, stats, null_inode);
1684 LPROCFS_MD_OP_INIT(num_private_stats, stats, close);
1685 LPROCFS_MD_OP_INIT(num_private_stats, stats, create);
1686 LPROCFS_MD_OP_INIT(num_private_stats, stats, enqueue);
1687 LPROCFS_MD_OP_INIT(num_private_stats, stats, getattr);
1688 LPROCFS_MD_OP_INIT(num_private_stats, stats, getattr_name);
1689 LPROCFS_MD_OP_INIT(num_private_stats, stats, intent_lock);
1690 LPROCFS_MD_OP_INIT(num_private_stats, stats, link);
1691 LPROCFS_MD_OP_INIT(num_private_stats, stats, rename);
1692 LPROCFS_MD_OP_INIT(num_private_stats, stats, setattr);
1693 LPROCFS_MD_OP_INIT(num_private_stats, stats, fsync);
1694 LPROCFS_MD_OP_INIT(num_private_stats, stats, read_page);
1695 LPROCFS_MD_OP_INIT(num_private_stats, stats, unlink);
1696 LPROCFS_MD_OP_INIT(num_private_stats, stats, setxattr);
1697 LPROCFS_MD_OP_INIT(num_private_stats, stats, getxattr);
1698 LPROCFS_MD_OP_INIT(num_private_stats, stats, init_ea_size);
1699 LPROCFS_MD_OP_INIT(num_private_stats, stats, get_lustre_md);
1700 LPROCFS_MD_OP_INIT(num_private_stats, stats, free_lustre_md);
1701 LPROCFS_MD_OP_INIT(num_private_stats, stats, merge_attr);
1702 LPROCFS_MD_OP_INIT(num_private_stats, stats, set_open_replay_data);
1703 LPROCFS_MD_OP_INIT(num_private_stats, stats, clear_open_replay_data);
1704 LPROCFS_MD_OP_INIT(num_private_stats, stats, set_lock_data);
1705 LPROCFS_MD_OP_INIT(num_private_stats, stats, lock_match);
1706 LPROCFS_MD_OP_INIT(num_private_stats, stats, cancel_unused);
1707 LPROCFS_MD_OP_INIT(num_private_stats, stats, intent_getattr_async);
1708 LPROCFS_MD_OP_INIT(num_private_stats, stats, revalidate_lock);
1711 int lprocfs_alloc_md_stats(struct obd_device *obd,
1712 unsigned int num_private_stats)
1714 struct lprocfs_stats *stats;
1715 unsigned int num_stats;
1718 CLASSERT(offsetof(struct md_ops, MD_STATS_FIRST_OP) == 0);
1719 CLASSERT(_MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) == 0);
1720 CLASSERT(_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) > 0);
1722 /* TODO Ensure that this function is only used where
1723 * appropriate by adding an assertion to the effect that
1724 * obd->obd_type->typ_md_ops is not NULL. We can't do this now
1725 * because mdt_procfs_init() uses this function to allocate
1726 * the stats backing /proc/fs/lustre/mdt/.../md_stats but the
1727 * mdt layer does not use the md_ops interface. This is
1728 * confusing and a waste of memory. See LU-2484.
1730 LASSERT(obd->obd_proc_entry != NULL);
1731 LASSERT(obd->obd_md_stats == NULL);
1732 LASSERT(obd->obd_md_cntr_base == 0);
1734 num_stats = NUM_MD_STATS + num_private_stats;
1735 stats = lprocfs_alloc_stats(num_stats, 0);
1739 lprocfs_init_mps_stats(num_private_stats, stats);
1741 for (i = num_private_stats; i < num_stats; i++) {
1742 if (stats->ls_cnt_header[i].lc_name == NULL) {
1743 CERROR("Missing md_stat initializer md_op "
1744 "operation at offset %d. Aborting.\n",
1745 i - num_private_stats);
1750 rc = lprocfs_register_stats(obd->obd_proc_entry, "md_stats", stats);
1752 lprocfs_free_stats(&stats);
1754 obd->obd_md_stats = stats;
1755 obd->obd_md_cntr_base = num_private_stats;
1760 EXPORT_SYMBOL(lprocfs_alloc_md_stats);
1762 void lprocfs_free_md_stats(struct obd_device *obd)
1764 struct lprocfs_stats *stats = obd->obd_md_stats;
1766 if (stats != NULL) {
1767 obd->obd_md_stats = NULL;
1768 obd->obd_md_cntr_base = 0;
1769 lprocfs_free_stats(&stats);
1772 EXPORT_SYMBOL(lprocfs_free_md_stats);
1774 void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
1776 lprocfs_counter_init(ldlm_stats,
1777 LDLM_ENQUEUE - LDLM_FIRST_OPC,
1778 0, "ldlm_enqueue", "reqs");
1779 lprocfs_counter_init(ldlm_stats,
1780 LDLM_CONVERT - LDLM_FIRST_OPC,
1781 0, "ldlm_convert", "reqs");
1782 lprocfs_counter_init(ldlm_stats,
1783 LDLM_CANCEL - LDLM_FIRST_OPC,
1784 0, "ldlm_cancel", "reqs");
1785 lprocfs_counter_init(ldlm_stats,
1786 LDLM_BL_CALLBACK - LDLM_FIRST_OPC,
1787 0, "ldlm_bl_callback", "reqs");
1788 lprocfs_counter_init(ldlm_stats,
1789 LDLM_CP_CALLBACK - LDLM_FIRST_OPC,
1790 0, "ldlm_cp_callback", "reqs");
1791 lprocfs_counter_init(ldlm_stats,
1792 LDLM_GL_CALLBACK - LDLM_FIRST_OPC,
1793 0, "ldlm_gl_callback", "reqs");
1795 EXPORT_SYMBOL(lprocfs_init_ldlm_stats);
1797 __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
1798 struct lprocfs_counter_header *header,
1799 enum lprocfs_stats_flags flags,
1800 enum lprocfs_fields_flags field)
1804 if (lc == NULL || header == NULL)
1808 case LPROCFS_FIELDS_FLAGS_CONFIG:
1809 ret = header->lc_config;
1811 case LPROCFS_FIELDS_FLAGS_SUM:
1813 if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
1814 ret += lc->lc_sum_irq;
1816 case LPROCFS_FIELDS_FLAGS_MIN:
1819 case LPROCFS_FIELDS_FLAGS_MAX:
1822 case LPROCFS_FIELDS_FLAGS_AVG:
1823 ret = (lc->lc_max - lc->lc_min) / 2;
1825 case LPROCFS_FIELDS_FLAGS_SUMSQUARE:
1826 ret = lc->lc_sumsquare;
1828 case LPROCFS_FIELDS_FLAGS_COUNT:
1836 EXPORT_SYMBOL(lprocfs_read_helper);
1838 int lprocfs_read_frac_helper(char *buffer, unsigned long count, long val,
1841 long decimal_val, frac_val;
1847 decimal_val = val / mult;
1848 prtn = snprintf(buffer, count, "%ld", decimal_val);
1849 frac_val = val % mult;
1851 if (prtn < (count - 4) && frac_val > 0) {
1853 int i, temp_mult = 1, frac_bits = 0;
1855 temp_frac = frac_val * 10;
1856 buffer[prtn++] = '.';
1857 while (frac_bits < 2 && (temp_frac / mult) < 1 ) {
1858 /* only reserved 2 bits fraction */
1859 buffer[prtn++] ='0';
1864 * Need to think these cases :
1865 * 1. #echo x.00 > /proc/xxx output result : x
1866 * 2. #echo x.0x > /proc/xxx output result : x.0x
1867 * 3. #echo x.x0 > /proc/xxx output result : x.x
1868 * 4. #echo x.xx > /proc/xxx output result : x.xx
1869 * Only reserved 2 bits fraction.
1871 for (i = 0; i < (5 - prtn); i++)
1874 frac_bits = min((int)count - prtn, 3 - frac_bits);
1875 prtn += snprintf(buffer + prtn, frac_bits, "%ld",
1876 frac_val * temp_mult / mult);
1879 while(buffer[prtn] < '1' || buffer[prtn] > '9') {
1881 if (buffer[prtn] == '.') {
1888 buffer[prtn++] ='\n';
1891 EXPORT_SYMBOL(lprocfs_read_frac_helper);
1893 int lprocfs_seq_read_frac_helper(struct seq_file *m, long val, int mult)
1895 long decimal_val, frac_val;
1897 decimal_val = val / mult;
1898 seq_printf(m, "%ld", decimal_val);
1899 frac_val = val % mult;
1906 /* Three cases: x0, xx, 0x */
1907 if ((frac_val % 10) != 0)
1908 seq_printf(m, ".%ld", frac_val);
1910 seq_printf(m, ".%ld", frac_val / 10);
1913 seq_printf(m, "\n");
1916 EXPORT_SYMBOL(lprocfs_seq_read_frac_helper);
1918 /* Obtains the conversion factor for the unit specified */
1919 static int get_mult(char unit, __u64 *mult)
1924 /* peta, tera, giga, mega, and kilo */
1941 /* some tests expect % to be accepted */
1955 * Ensures the numeric string is valid. The function provides the final
1956 * multiplier in the case a unit exists at the end of the string. It also
1957 * locates the start of the whole and fractional parts (if any). This
1958 * function modifies the string so kstrtoull can be used to parse both
1959 * the whole and fraction portions. This function also figures out
1960 * the base of the number.
1962 static int preprocess_numeric_str(char *buffer, __u64 *mult, __u64 def_mult,
1963 bool allow_units, char **whole, char **frac,
1966 bool hit_decimal = false;
1967 bool hit_unit = false;
1975 /* a hex string if it starts with "0x" */
1976 if (buffer[0] == '0' && tolower(buffer[1]) == 'x') {
1984 /* allow for a single new line before the null terminator */
1985 if (*buffer == '\n') {
1995 /* any chars after our unit indicates a malformed string */
1999 /* ensure we only hit one decimal */
2000 if (*buffer == '.') {
2004 /* if past start, there's a whole part */
2005 if (start != buffer)
2011 } else if (!isdigit(*buffer) &&
2012 !(*base == 16 && isxdigit(*buffer))) {
2014 /* if we allow units, attempt to get mult */
2016 rc = get_mult(*buffer, mult);
2020 /* string stops here, but keep processing */
2032 /* hit a decimal, make sure there's a fractional part */
2038 /* didn't hit a decimal, but may have a whole part */
2039 if (start != buffer && *start)
2043 /* malformed string if we didn't get anything */
2044 if (!*frac && !*whole)
2051 * Parses a numeric string which can contain a whole and fraction portion
2052 * into a __u64. Accepts a multiplier to apply to the value parsed. Also
2053 * allows the string to have a unit at the end. The function handles
2054 * wrapping of the final unsigned value.
2056 static int str_to_u64_parse(char *buffer, unsigned long count,
2057 __u64 *val, __u64 def_mult, bool allow_units)
2061 unsigned int frac_d = 1;
2062 __u64 wrap_indicator = ULLONG_MAX;
2067 unsigned int base = 10;
2069 rc = preprocess_numeric_str(buffer, &mult, def_mult, allow_units,
2070 &strwhole, &strfrac, &base);
2080 /* the multiplier limits how large the value can be */
2081 wrap_indicator /= mult;
2084 rc = kstrtoull(strwhole, base, &whole);
2088 if (whole > wrap_indicator)
2095 if (strlen(strfrac) > 10)
2098 rc = kstrtoull(strfrac, base, &frac);
2102 /* determine power of fractional portion */
2108 /* fractional portion is too large to perform calculation */
2109 if (frac > wrap_indicator)
2113 do_div(frac, frac_d);
2116 /* check that the sum of whole and fraction fits in u64 */
2117 if (whole > (ULLONG_MAX - frac))
2120 *val = whole + frac;
2126 * This function parses numeric/hex strings into __s64. It accepts a multiplier
2127 * which will apply to the value parsed. It also can allow the string to
2128 * have a unit as the last character. The function handles overflow/underflow
2129 * of the signed integer.
2131 static int str_to_s64_internal(const char __user *buffer, unsigned long count,
2132 __s64 *val, __u64 def_mult, bool allow_units)
2136 unsigned int offset = 0;
2137 int signed sign = 1;
2138 __u64 max = LLONG_MAX;
2141 if (count > (sizeof(kernbuf) - 1))
2144 if (copy_from_user(kernbuf, buffer, count))
2147 kernbuf[count] = '\0';
2149 /* keep track of our sign */
2150 if (*kernbuf == '-') {
2153 /* equivalent to max = -LLONG_MIN, avoids overflow */
2157 rc = str_to_u64_parse(kernbuf + offset, count - offset,
2158 &tmp, def_mult, allow_units);
2162 /* check for overflow/underflow */
2166 *val = (__s64)tmp * sign;
2172 * Convert a user string into a signed 64 bit number. This function produces
2173 * an error when the value parsed from the string underflows or
2174 * overflows. This function accepts strings which contain digits and
2175 * optionally a decimal or hex strings which are prefixed with "0x".
2177 * \param[in] buffer string consisting of numbers and optionally a decimal
2178 * \param[in] count buffer length
2179 * \param[in] val if successful, the value represented by the string
2181 * \retval 0 on success
2182 * \retval negative number on error
2184 int lprocfs_str_to_s64(const char __user *buffer, unsigned long count,
2187 return str_to_s64_internal(buffer, count, val, 1, false);
2189 EXPORT_SYMBOL(lprocfs_str_to_s64);
2192 * Convert a user string into a signed 64 bit number. This function produces
2193 * an error when the value parsed from the string times multiplier underflows or
2194 * overflows. This function only accepts strings that contains digits, an
2195 * optional decimal, and a char representing a unit at the end. If a unit is
2196 * specified in the string, the multiplier provided by the caller is ignored.
2197 * This function can also accept hexadecimal strings which are prefixed with
2200 * \param[in] buffer string consisting of numbers, a decimal, and a unit
2201 * \param[in] count buffer length
2202 * \param[in] val if successful, the value represented by the string
2203 * \param[in] defunit default unit if string doesn't contain one
2205 * \retval 0 on success
2206 * \retval negative number on error
2208 int lprocfs_str_with_units_to_s64(const char __user *buffer,
2209 unsigned long count, __s64 *val, char defunit)
2214 if (defunit != '1') {
2215 rc = get_mult(defunit, &mult);
2220 return str_to_s64_internal(buffer, count, val, mult, true);
2222 EXPORT_SYMBOL(lprocfs_str_with_units_to_s64);
2224 static char *lprocfs_strnstr(const char *s1, const char *s2, size_t len)
2233 if (!memcmp(s1, s2, l2))
2241 * Find the string \a name in the input \a buffer, and return a pointer to the
2242 * value immediately following \a name, reducing \a count appropriately.
2243 * If \a name is not found the original \a buffer is returned.
2245 char *lprocfs_find_named_value(const char *buffer, const char *name,
2249 size_t buflen = *count;
2251 /* there is no strnstr() in rhel5 and ubuntu kernels */
2252 val = lprocfs_strnstr(buffer, name, buflen);
2254 return (char *)buffer;
2256 val += strlen(name); /* skip prefix */
2257 while (val < buffer + buflen && isspace(*val)) /* skip separator */
2261 while (val < buffer + buflen && isalnum(*val)) {
2266 return val - *count;
2268 EXPORT_SYMBOL(lprocfs_find_named_value);
2270 int ldebugfs_seq_create(struct dentry *parent, const char *name, umode_t mode,
2271 const struct file_operations *seq_fops, void *data)
2273 struct dentry *entry;
2275 /* Disallow secretly (un)writable entries. */
2276 LASSERT((!seq_fops->write) == (!(mode & 0222)));
2278 entry = debugfs_create_file(name, mode, parent, data, seq_fops);
2279 if (IS_ERR_OR_NULL(entry))
2280 return entry ? PTR_ERR(entry) : -ENOMEM;
2284 EXPORT_SYMBOL_GPL(ldebugfs_seq_create);
2286 int lprocfs_seq_create(struct proc_dir_entry *parent,
2289 const struct file_operations *seq_fops,
2292 struct proc_dir_entry *entry;
2295 /* Disallow secretly (un)writable entries. */
2296 LASSERT((seq_fops->write == NULL) == ((mode & 0222) == 0));
2298 entry = proc_create_data(name, mode, parent, seq_fops, data);
2305 EXPORT_SYMBOL(lprocfs_seq_create);
2307 int lprocfs_obd_seq_create(struct obd_device *dev,
2310 const struct file_operations *seq_fops,
2313 return (lprocfs_seq_create(dev->obd_proc_entry, name,
2314 mode, seq_fops, data));
2316 EXPORT_SYMBOL(lprocfs_obd_seq_create);
2318 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
2320 if (value >= OBD_HIST_MAX)
2321 value = OBD_HIST_MAX - 1;
2323 spin_lock(&oh->oh_lock);
2324 oh->oh_buckets[value]++;
2325 spin_unlock(&oh->oh_lock);
2327 EXPORT_SYMBOL(lprocfs_oh_tally);
2329 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
2331 unsigned int val = 0;
2333 if (likely(value != 0))
2334 val = min(fls(value - 1), OBD_HIST_MAX);
2336 lprocfs_oh_tally(oh, val);
2338 EXPORT_SYMBOL(lprocfs_oh_tally_log2);
2340 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
2342 unsigned long ret = 0;
2345 for (i = 0; i < OBD_HIST_MAX; i++)
2346 ret += oh->oh_buckets[i];
2349 EXPORT_SYMBOL(lprocfs_oh_sum);
2351 void lprocfs_oh_clear(struct obd_histogram *oh)
2353 spin_lock(&oh->oh_lock);
2354 memset(oh->oh_buckets, 0, sizeof(oh->oh_buckets));
2355 spin_unlock(&oh->oh_lock);
2357 EXPORT_SYMBOL(lprocfs_oh_clear);
2359 ssize_t lustre_attr_show(struct kobject *kobj,
2360 struct attribute *attr, char *buf)
2362 struct lustre_attr *a = container_of(attr, struct lustre_attr, attr);
2364 return a->show ? a->show(kobj, attr, buf) : 0;
2366 EXPORT_SYMBOL_GPL(lustre_attr_show);
2368 ssize_t lustre_attr_store(struct kobject *kobj, struct attribute *attr,
2369 const char *buf, size_t len)
2371 struct lustre_attr *a = container_of(attr, struct lustre_attr, attr);
2373 return a->store ? a->store(kobj, attr, buf, len) : len;
2375 EXPORT_SYMBOL_GPL(lustre_attr_store);
2377 const struct sysfs_ops lustre_sysfs_ops = {
2378 .show = lustre_attr_show,
2379 .store = lustre_attr_store,
2381 EXPORT_SYMBOL_GPL(lustre_sysfs_ops);
2383 int lprocfs_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *data)
2385 struct obd_device *dev = data;
2386 struct client_obd *cli = &dev->u.cli;
2388 spin_lock(&cli->cl_loi_list_lock);
2389 seq_printf(m, "%d\n", cli->cl_max_pages_per_rpc);
2390 spin_unlock(&cli->cl_loi_list_lock);
2393 EXPORT_SYMBOL(lprocfs_obd_max_pages_per_rpc_seq_show);
2395 ssize_t lprocfs_obd_max_pages_per_rpc_seq_write(struct file *file,
2396 const char __user *buffer,
2397 size_t count, loff_t *off)
2399 struct obd_device *dev =
2400 ((struct seq_file *)file->private_data)->private;
2401 struct client_obd *cli = &dev->u.cli;
2402 struct obd_connect_data *ocd = &cli->cl_import->imp_connect_data;
2406 rc = lprocfs_str_with_units_to_s64(buffer, count, &val, '1');
2412 /* if the max_pages is specified in bytes, convert to pages */
2413 if (val >= ONE_MB_BRW_SIZE)
2416 LPROCFS_CLIMP_CHECK(dev);
2418 chunk_mask = ~((1 << (cli->cl_chunkbits - PAGE_SHIFT)) - 1);
2419 /* max_pages_per_rpc must be chunk aligned */
2420 val = (val + ~chunk_mask) & chunk_mask;
2421 if (val == 0 || (ocd->ocd_brw_size != 0 &&
2422 val > ocd->ocd_brw_size >> PAGE_SHIFT)) {
2423 LPROCFS_CLIMP_EXIT(dev);
2426 spin_lock(&cli->cl_loi_list_lock);
2427 cli->cl_max_pages_per_rpc = val;
2428 client_adjust_max_dirty(cli);
2429 spin_unlock(&cli->cl_loi_list_lock);
2431 LPROCFS_CLIMP_EXIT(dev);
2434 EXPORT_SYMBOL(lprocfs_obd_max_pages_per_rpc_seq_write);
2436 int lprocfs_obd_short_io_bytes_seq_show(struct seq_file *m, void *data)
2438 struct obd_device *dev = data;
2439 struct client_obd *cli = &dev->u.cli;
2441 spin_lock(&cli->cl_loi_list_lock);
2442 seq_printf(m, "%d\n", cli->cl_short_io_bytes);
2443 spin_unlock(&cli->cl_loi_list_lock);
2446 EXPORT_SYMBOL(lprocfs_obd_short_io_bytes_seq_show);
2449 /* Used to catch people who think they're specifying pages. */
2450 #define MIN_SHORT_IO_BYTES 64
2452 ssize_t lprocfs_obd_short_io_bytes_seq_write(struct file *file,
2453 const char __user *buffer,
2454 size_t count, loff_t *off)
2456 struct obd_device *dev = ((struct seq_file *)
2457 file->private_data)->private;
2458 struct client_obd *cli = &dev->u.cli;
2462 LPROCFS_CLIMP_CHECK(dev);
2464 rc = lprocfs_str_to_s64(buffer, count, &val);
2468 if (val > OBD_MAX_SHORT_IO_BYTES || val < MIN_SHORT_IO_BYTES)
2469 GOTO(out, rc = -ERANGE);
2473 spin_lock(&cli->cl_loi_list_lock);
2474 if (val > (cli->cl_max_pages_per_rpc << PAGE_SHIFT))
2477 cli->cl_short_io_bytes = val;
2478 spin_unlock(&cli->cl_loi_list_lock);
2481 LPROCFS_CLIMP_EXIT(dev);
2484 EXPORT_SYMBOL(lprocfs_obd_short_io_bytes_seq_write);
2486 int lprocfs_wr_root_squash(const char __user *buffer, unsigned long count,
2487 struct root_squash_info *squash, char *name)
2490 char kernbuf[64], *tmp, *errmsg;
2491 unsigned long uid, gid;
2494 if (count >= sizeof(kernbuf)) {
2495 errmsg = "string too long";
2496 GOTO(failed_noprint, rc = -EINVAL);
2498 if (copy_from_user(kernbuf, buffer, count)) {
2499 errmsg = "bad address";
2500 GOTO(failed_noprint, rc = -EFAULT);
2502 kernbuf[count] = '\0';
2504 /* look for uid gid separator */
2505 tmp = strchr(kernbuf, ':');
2507 errmsg = "needs uid:gid format";
2508 GOTO(failed, rc = -EINVAL);
2514 if (kstrtoul(kernbuf, 0, &uid) != 0) {
2516 GOTO(failed, rc = -EINVAL);
2520 if (kstrtoul(tmp, 0, &gid) != 0) {
2522 GOTO(failed, rc = -EINVAL);
2525 squash->rsi_uid = uid;
2526 squash->rsi_gid = gid;
2528 LCONSOLE_INFO("%s: root_squash is set to %u:%u\n",
2529 name, squash->rsi_uid, squash->rsi_gid);
2537 CWARN("%s: failed to set root_squash to \"%s\", %s, rc = %d\n",
2538 name, kernbuf, errmsg, rc);
2541 CWARN("%s: failed to set root_squash due to %s, rc = %d\n",
2545 EXPORT_SYMBOL(lprocfs_wr_root_squash);
2548 int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count,
2549 struct root_squash_info *squash, char *name)
2552 char *kernbuf = NULL;
2554 struct list_head tmp;
2559 errmsg = "string too long";
2560 GOTO(failed, rc = -EINVAL);
2563 OBD_ALLOC(kernbuf, count + 1);
2564 if (kernbuf == NULL) {
2565 errmsg = "no memory";
2566 GOTO(failed, rc = -ENOMEM);
2568 if (copy_from_user(kernbuf, buffer, count)) {
2569 errmsg = "bad address";
2570 GOTO(failed, rc = -EFAULT);
2572 kernbuf[count] = '\0';
2574 if (count > 0 && kernbuf[count - 1] == '\n')
2577 if ((len == 4 && strncmp(kernbuf, "NONE", len) == 0) ||
2578 (len == 5 && strncmp(kernbuf, "clear", len) == 0)) {
2579 /* empty string is special case */
2580 down_write(&squash->rsi_sem);
2581 if (!list_empty(&squash->rsi_nosquash_nids))
2582 cfs_free_nidlist(&squash->rsi_nosquash_nids);
2583 up_write(&squash->rsi_sem);
2584 LCONSOLE_INFO("%s: nosquash_nids is cleared\n", name);
2585 OBD_FREE(kernbuf, count + 1);
2589 INIT_LIST_HEAD(&tmp);
2590 if (cfs_parse_nidlist(kernbuf, count, &tmp) <= 0) {
2591 errmsg = "can't parse";
2592 GOTO(failed, rc = -EINVAL);
2594 LCONSOLE_INFO("%s: nosquash_nids set to %s\n",
2596 OBD_FREE(kernbuf, count + 1);
2599 down_write(&squash->rsi_sem);
2600 if (!list_empty(&squash->rsi_nosquash_nids))
2601 cfs_free_nidlist(&squash->rsi_nosquash_nids);
2602 list_splice(&tmp, &squash->rsi_nosquash_nids);
2603 up_write(&squash->rsi_sem);
2609 CWARN("%s: failed to set nosquash_nids to \"%s\", %s rc = %d\n",
2610 name, kernbuf, errmsg, rc);
2611 OBD_FREE(kernbuf, count + 1);
2613 CWARN("%s: failed to set nosquash_nids due to %s rc = %d\n",
2618 EXPORT_SYMBOL(lprocfs_wr_nosquash_nids);
2620 #endif /* CONFIG_PROC_FS*/