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, 2016, 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;
472 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
473 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
476 return sprintf(buf, "%u\n", osfs.os_bsize);
480 LUSTRE_RO_ATTR(blocksize);
482 static ssize_t kbytestotal_show(struct kobject *kobj, struct attribute *attr,
485 struct obd_device *obd = container_of(kobj, struct obd_device,
487 struct obd_statfs osfs;
488 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
489 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
492 u32 blk_size = osfs.os_bsize >> 10;
493 u64 result = osfs.os_blocks;
495 while (blk_size >>= 1)
498 return sprintf(buf, "%llu\n", result);
503 LUSTRE_RO_ATTR(kbytestotal);
505 static ssize_t kbytesfree_show(struct kobject *kobj, struct attribute *attr,
508 struct obd_device *obd = container_of(kobj, struct obd_device,
510 struct obd_statfs osfs;
511 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
512 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
515 u32 blk_size = osfs.os_bsize >> 10;
516 u64 result = osfs.os_bfree;
518 while (blk_size >>= 1)
521 return sprintf(buf, "%llu\n", result);
526 LUSTRE_RO_ATTR(kbytesfree);
528 static ssize_t kbytesavail_show(struct kobject *kobj, struct attribute *attr,
531 struct obd_device *obd = container_of(kobj, struct obd_device,
533 struct obd_statfs osfs;
534 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
535 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
538 u32 blk_size = osfs.os_bsize >> 10;
539 u64 result = osfs.os_bavail;
541 while (blk_size >>= 1)
544 return sprintf(buf, "%llu\n", result);
549 LUSTRE_RO_ATTR(kbytesavail);
551 static ssize_t filestotal_show(struct kobject *kobj, struct attribute *attr,
554 struct obd_device *obd = container_of(kobj, struct obd_device,
556 struct obd_statfs osfs;
557 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
558 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
561 return sprintf(buf, "%llu\n", osfs.os_files);
565 LUSTRE_RO_ATTR(filestotal);
567 static ssize_t filesfree_show(struct kobject *kobj, struct attribute *attr,
570 struct obd_device *obd = container_of(kobj, struct obd_device,
572 struct obd_statfs osfs;
573 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
574 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
577 return sprintf(buf, "%llu\n", osfs.os_ffree);
581 LUSTRE_RO_ATTR(filesfree);
583 int lprocfs_server_uuid_seq_show(struct seq_file *m, void *data)
585 struct obd_device *obd = data;
586 struct obd_import *imp;
587 char *imp_state_name = NULL;
590 LASSERT(obd != NULL);
591 LPROCFS_CLIMP_CHECK(obd);
592 imp = obd->u.cli.cl_import;
593 imp_state_name = ptlrpc_import_state_name(imp->imp_state);
594 seq_printf(m, "%s\t%s%s\n", obd2cli_tgt(obd), imp_state_name,
595 imp->imp_deactive ? "\tDEACTIVATED" : "");
597 LPROCFS_CLIMP_EXIT(obd);
600 EXPORT_SYMBOL(lprocfs_server_uuid_seq_show);
602 int lprocfs_conn_uuid_seq_show(struct seq_file *m, void *data)
604 struct obd_device *obd = data;
605 struct ptlrpc_connection *conn;
608 LASSERT(obd != NULL);
610 LPROCFS_CLIMP_CHECK(obd);
611 conn = obd->u.cli.cl_import->imp_connection;
612 if (conn && obd->u.cli.cl_import)
613 seq_printf(m, "%s\n", conn->c_remote_uuid.uuid);
615 seq_printf(m, "%s\n", "<none>");
617 LPROCFS_CLIMP_EXIT(obd);
620 EXPORT_SYMBOL(lprocfs_conn_uuid_seq_show);
622 /** add up per-cpu counters */
625 * Lock statistics structure for access, possibly only on this CPU.
627 * The statistics struct may be allocated with per-CPU structures for
628 * efficient concurrent update (usually only on server-wide stats), or
629 * as a single global struct (e.g. for per-client or per-job statistics),
630 * so the required locking depends on the type of structure allocated.
632 * For per-CPU statistics, pin the thread to the current cpuid so that
633 * will only access the statistics for that CPU. If the stats structure
634 * for the current CPU has not been allocated (or previously freed),
635 * allocate it now. The per-CPU statistics do not need locking since
636 * the thread is pinned to the CPU during update.
638 * For global statistics, lock the stats structure to prevent concurrent update.
640 * \param[in] stats statistics structure to lock
641 * \param[in] opc type of operation:
642 * LPROCFS_GET_SMP_ID: "lock" and return current CPU index
643 * for incrementing statistics for that CPU
644 * LPROCFS_GET_NUM_CPU: "lock" and return number of used
645 * CPU indices to iterate over all indices
646 * \param[out] flags CPU interrupt saved state for IRQ-safe locking
648 * \retval cpuid of current thread or number of allocated structs
649 * \retval negative on error (only for opc LPROCFS_GET_SMP_ID + per-CPU stats)
651 int lprocfs_stats_lock(struct lprocfs_stats *stats,
652 enum lprocfs_stats_lock_ops opc,
653 unsigned long *flags)
655 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
656 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
657 spin_lock_irqsave(&stats->ls_lock, *flags);
659 spin_lock(&stats->ls_lock);
660 return opc == LPROCFS_GET_NUM_CPU ? 1 : 0;
664 case LPROCFS_GET_SMP_ID: {
665 unsigned int cpuid = get_cpu();
667 if (unlikely(!stats->ls_percpu[cpuid])) {
668 int rc = lprocfs_stats_alloc_one(stats, cpuid);
677 case LPROCFS_GET_NUM_CPU:
678 return stats->ls_biggest_alloc_num;
685 * Unlock statistics structure after access.
687 * Unlock the lock acquired via lprocfs_stats_lock() for global statistics,
688 * or unpin this thread from the current cpuid for per-CPU statistics.
690 * This function must be called using the same arguments as used when calling
691 * lprocfs_stats_lock() so that the correct operation can be performed.
693 * \param[in] stats statistics structure to unlock
694 * \param[in] opc type of operation (current cpuid or number of structs)
695 * \param[in] flags CPU interrupt saved state for IRQ-safe locking
697 void lprocfs_stats_unlock(struct lprocfs_stats *stats,
698 enum lprocfs_stats_lock_ops opc,
699 unsigned long *flags)
701 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
702 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
703 spin_unlock_irqrestore(&stats->ls_lock, *flags);
705 spin_unlock(&stats->ls_lock);
706 } else if (opc == LPROCFS_GET_SMP_ID) {
711 /** add up per-cpu counters */
712 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
713 struct lprocfs_counter *cnt)
715 unsigned int num_entry;
716 struct lprocfs_counter *percpu_cntr;
718 unsigned long flags = 0;
720 memset(cnt, 0, sizeof(*cnt));
723 /* set count to 1 to avoid divide-by-zero errs in callers */
728 cnt->lc_min = LC_MIN_INIT;
730 num_entry = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
732 for (i = 0; i < num_entry; i++) {
733 if (stats->ls_percpu[i] == NULL)
735 percpu_cntr = lprocfs_stats_counter_get(stats, i, idx);
737 cnt->lc_count += percpu_cntr->lc_count;
738 cnt->lc_sum += percpu_cntr->lc_sum;
739 if (percpu_cntr->lc_min < cnt->lc_min)
740 cnt->lc_min = percpu_cntr->lc_min;
741 if (percpu_cntr->lc_max > cnt->lc_max)
742 cnt->lc_max = percpu_cntr->lc_max;
743 cnt->lc_sumsquare += percpu_cntr->lc_sumsquare;
746 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
750 * Append a space separated list of current set flags to str.
752 #define flag2str(flag) \
754 if (imp->imp_##flag) { \
755 seq_printf(m, "%s" #flag, first ? "" : ", "); \
759 static void obd_import_flags2str(struct obd_import *imp, struct seq_file *m)
763 if (imp->imp_obd->obd_no_recov) {
764 seq_printf(m, "no_recov");
770 flag2str(replayable);
771 flag2str(delayed_recovery);
772 flag2str(no_lock_replay);
773 flag2str(vbr_failed);
775 flag2str(resend_replay);
776 flag2str(no_pinger_recover);
777 flag2str(need_mne_swab);
778 flag2str(connect_tried);
782 static const char *obd_connect_names[] = {
801 "remote_client_by_force",
810 "mds_mds_connection",
813 "alt_checksum_algorithm",
854 static void obd_connect_seq_flags2str(struct seq_file *m, __u64 flags,
855 __u64 flags2, const char *sep)
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));
893 int obd_connect_flags2str(char *page, int count, __u64 flags, __u64 flags2,
899 for (i = 0, mask = 1; i < 64; i++, mask <<= 1) {
901 ret += snprintf(page + ret, count - ret, "%s%s",
902 ret ? sep : "", obd_connect_names[i]);
905 if (flags & ~(mask - 1))
906 ret += snprintf(page + ret, count - ret,
908 ret ? sep : "", flags & ~(mask - 1));
910 if (!(flags & OBD_CONNECT_FLAGS2) || flags2 == 0)
913 for (i = 64, mask = 1; obd_connect_names[i] != NULL; i++, mask <<= 1) {
915 ret += snprintf(page + ret, count - ret, "%s%s",
916 ret ? sep : "", obd_connect_names[i]);
919 if (flags2 & ~(mask - 1))
920 ret += snprintf(page + ret, count - ret,
922 ret ? sep : "", flags2 & ~(mask - 1));
926 EXPORT_SYMBOL(obd_connect_flags2str);
928 static void obd_connect_data_seqprint(struct seq_file *m,
929 struct obd_connect_data *ocd)
933 LASSERT(ocd != NULL);
934 flags = ocd->ocd_connect_flags;
936 seq_printf(m, " connect_data:\n"
939 ocd->ocd_connect_flags,
941 if (flags & OBD_CONNECT_VERSION)
942 seq_printf(m, " target_version: %u.%u.%u.%u\n",
943 OBD_OCD_VERSION_MAJOR(ocd->ocd_version),
944 OBD_OCD_VERSION_MINOR(ocd->ocd_version),
945 OBD_OCD_VERSION_PATCH(ocd->ocd_version),
946 OBD_OCD_VERSION_FIX(ocd->ocd_version));
947 if (flags & OBD_CONNECT_MDS)
948 seq_printf(m, " mdt_index: %d\n", ocd->ocd_group);
949 if (flags & OBD_CONNECT_GRANT)
950 seq_printf(m, " initial_grant: %d\n", ocd->ocd_grant);
951 if (flags & OBD_CONNECT_INDEX)
952 seq_printf(m, " target_index: %u\n", ocd->ocd_index);
953 if (flags & OBD_CONNECT_BRW_SIZE)
954 seq_printf(m, " max_brw_size: %d\n", ocd->ocd_brw_size);
955 if (flags & OBD_CONNECT_IBITS)
956 seq_printf(m, " ibits_known: %#llx\n",
957 ocd->ocd_ibits_known);
958 if (flags & OBD_CONNECT_GRANT_PARAM)
959 seq_printf(m, " grant_block_size: %d\n"
960 " grant_inode_size: %d\n"
961 " grant_max_extent_size: %d\n"
962 " grant_extent_tax: %d\n",
963 1 << ocd->ocd_grant_blkbits,
964 1 << ocd->ocd_grant_inobits,
965 ocd->ocd_grant_max_blks << ocd->ocd_grant_blkbits,
966 ocd->ocd_grant_tax_kb << 10);
967 if (flags & OBD_CONNECT_TRANSNO)
968 seq_printf(m, " first_transno: %#llx\n",
970 if (flags & OBD_CONNECT_CKSUM)
971 seq_printf(m, " cksum_types: %#x\n",
972 ocd->ocd_cksum_types);
973 if (flags & OBD_CONNECT_MAX_EASIZE)
974 seq_printf(m, " max_easize: %d\n", ocd->ocd_max_easize);
975 if (flags & OBD_CONNECT_MAXBYTES)
976 seq_printf(m, " max_object_bytes: %llu\n",
978 if (flags & OBD_CONNECT_MULTIMODRPCS)
979 seq_printf(m, " max_mod_rpcs: %hu\n",
980 ocd->ocd_maxmodrpcs);
983 int lprocfs_import_seq_show(struct seq_file *m, void *data)
985 char nidstr[LNET_NIDSTR_SIZE];
986 struct lprocfs_counter ret;
987 struct lprocfs_counter_header *header;
988 struct obd_device *obd = (struct obd_device *)data;
989 struct obd_import *imp;
990 struct obd_import_conn *conn;
991 struct obd_connect_data *ocd;
996 LASSERT(obd != NULL);
997 LPROCFS_CLIMP_CHECK(obd);
998 imp = obd->u.cli.cl_import;
999 ocd = &imp->imp_connect_data;
1001 seq_printf(m, "import:\n"
1005 " connect_flags: [ ",
1008 ptlrpc_import_state_name(imp->imp_state));
1009 obd_connect_seq_flags2str(m, imp->imp_connect_data.ocd_connect_flags,
1010 imp->imp_connect_data.ocd_connect_flags2,
1012 seq_printf(m, " ]\n");
1013 obd_connect_data_seqprint(m, ocd);
1014 seq_printf(m, " import_flags: [ ");
1015 obd_import_flags2str(imp, m);
1017 seq_printf(m, " ]\n"
1019 " failover_nids: [ ");
1020 spin_lock(&imp->imp_lock);
1022 list_for_each_entry(conn, &imp->imp_conn_list, oic_item) {
1023 libcfs_nid2str_r(conn->oic_conn->c_peer.nid,
1024 nidstr, sizeof(nidstr));
1025 seq_printf(m, "%s%s", j ? ", " : "", nidstr);
1028 if (imp->imp_connection != NULL)
1029 libcfs_nid2str_r(imp->imp_connection->c_peer.nid,
1030 nidstr, sizeof(nidstr));
1032 strncpy(nidstr, "<none>", sizeof(nidstr));
1033 seq_printf(m, " ]\n"
1034 " current_connection: %s\n"
1035 " connection_attempts: %u\n"
1037 " in-progress_invalidations: %u\n",
1040 imp->imp_generation,
1041 atomic_read(&imp->imp_inval_count));
1042 spin_unlock(&imp->imp_lock);
1044 if (obd->obd_svc_stats == NULL)
1047 header = &obd->obd_svc_stats->ls_cnt_header[PTLRPC_REQWAIT_CNTR];
1048 lprocfs_stats_collect(obd->obd_svc_stats, PTLRPC_REQWAIT_CNTR, &ret);
1049 if (ret.lc_count != 0) {
1050 /* first argument to do_div MUST be __u64 */
1051 __u64 sum = ret.lc_sum;
1052 do_div(sum, ret.lc_count);
1056 seq_printf(m, " rpcs:\n"
1058 " unregistering: %u\n"
1060 " avg_waittime: %llu %s\n",
1061 atomic_read(&imp->imp_inflight),
1062 atomic_read(&imp->imp_unregistering),
1063 atomic_read(&imp->imp_timeouts),
1064 ret.lc_sum, header->lc_units);
1067 for(j = 0; j < IMP_AT_MAX_PORTALS; j++) {
1068 if (imp->imp_at.iat_portal[j] == 0)
1070 k = max_t(unsigned int, k,
1071 at_get(&imp->imp_at.iat_service_estimate[j]));
1073 seq_printf(m, " service_estimates:\n"
1074 " services: %u sec\n"
1075 " network: %u sec\n",
1077 at_get(&imp->imp_at.iat_net_latency));
1079 seq_printf(m, " transactions:\n"
1080 " last_replay: %llu\n"
1081 " peer_committed: %llu\n"
1082 " last_checked: %llu\n",
1083 imp->imp_last_replay_transno,
1084 imp->imp_peer_committed_transno,
1085 imp->imp_last_transno_checked);
1087 /* avg data rates */
1088 for (rw = 0; rw <= 1; rw++) {
1089 lprocfs_stats_collect(obd->obd_svc_stats,
1090 PTLRPC_LAST_CNTR + BRW_READ_BYTES + rw,
1092 if (ret.lc_sum > 0 && ret.lc_count > 0) {
1093 /* first argument to do_div MUST be __u64 */
1094 __u64 sum = ret.lc_sum;
1095 do_div(sum, ret.lc_count);
1097 seq_printf(m, " %s_data_averages:\n"
1098 " bytes_per_rpc: %llu\n",
1099 rw ? "write" : "read",
1102 k = (int)ret.lc_sum;
1103 j = opcode_offset(OST_READ + rw) + EXTRA_MAX_OPCODES;
1104 header = &obd->obd_svc_stats->ls_cnt_header[j];
1105 lprocfs_stats_collect(obd->obd_svc_stats, j, &ret);
1106 if (ret.lc_sum > 0 && ret.lc_count != 0) {
1107 /* first argument to do_div MUST be __u64 */
1108 __u64 sum = ret.lc_sum;
1109 do_div(sum, ret.lc_count);
1111 seq_printf(m, " %s_per_rpc: %llu\n",
1112 header->lc_units, ret.lc_sum);
1113 j = (int)ret.lc_sum;
1115 seq_printf(m, " MB_per_sec: %u.%.02u\n",
1116 k / j, (100 * k / j) % 100);
1121 LPROCFS_CLIMP_EXIT(obd);
1124 EXPORT_SYMBOL(lprocfs_import_seq_show);
1126 int lprocfs_state_seq_show(struct seq_file *m, void *data)
1128 struct obd_device *obd = (struct obd_device *)data;
1129 struct obd_import *imp;
1132 LASSERT(obd != NULL);
1133 LPROCFS_CLIMP_CHECK(obd);
1134 imp = obd->u.cli.cl_import;
1136 seq_printf(m, "current_state: %s\n",
1137 ptlrpc_import_state_name(imp->imp_state));
1138 seq_printf(m, "state_history:\n");
1139 k = imp->imp_state_hist_idx;
1140 for (j = 0; j < IMP_STATE_HIST_LEN; j++) {
1141 struct import_state_hist *ish =
1142 &imp->imp_state_hist[(k + j) % IMP_STATE_HIST_LEN];
1143 if (ish->ish_state == 0)
1145 seq_printf(m, " - [ %lld, %s ]\n", (s64)ish->ish_time,
1146 ptlrpc_import_state_name(ish->ish_state));
1149 LPROCFS_CLIMP_EXIT(obd);
1152 EXPORT_SYMBOL(lprocfs_state_seq_show);
1154 int lprocfs_at_hist_helper(struct seq_file *m, struct adaptive_timeout *at)
1157 for (i = 0; i < AT_BINS; i++)
1158 seq_printf(m, "%3u ", at->at_hist[i]);
1159 seq_printf(m, "\n");
1162 EXPORT_SYMBOL(lprocfs_at_hist_helper);
1164 /* See also ptlrpc_lprocfs_timeouts_show_seq */
1165 int lprocfs_timeouts_seq_show(struct seq_file *m, void *data)
1167 struct obd_device *obd = (struct obd_device *)data;
1168 struct obd_import *imp;
1169 unsigned int cur, worst;
1170 time64_t now, worstt;
1173 LASSERT(obd != NULL);
1174 LPROCFS_CLIMP_CHECK(obd);
1175 imp = obd->u.cli.cl_import;
1177 now = ktime_get_real_seconds();
1179 /* Some network health info for kicks */
1180 seq_printf(m, "%-10s : %lld, %llds ago\n",
1181 "last reply", (s64)imp->imp_last_reply_time,
1182 (s64)(now - imp->imp_last_reply_time));
1184 cur = at_get(&imp->imp_at.iat_net_latency);
1185 worst = imp->imp_at.iat_net_latency.at_worst_ever;
1186 worstt = imp->imp_at.iat_net_latency.at_worst_time;
1187 seq_printf(m, "%-10s : cur %3u worst %3u (at %lld, %llds ago) ",
1188 "network", cur, worst, (s64)worstt, (s64)(now - worstt));
1189 lprocfs_at_hist_helper(m, &imp->imp_at.iat_net_latency);
1191 for(i = 0; i < IMP_AT_MAX_PORTALS; i++) {
1192 if (imp->imp_at.iat_portal[i] == 0)
1194 cur = at_get(&imp->imp_at.iat_service_estimate[i]);
1195 worst = imp->imp_at.iat_service_estimate[i].at_worst_ever;
1196 worstt = imp->imp_at.iat_service_estimate[i].at_worst_time;
1197 seq_printf(m, "portal %-2d : cur %3u worst %3u (at %lld, %llds ago) ",
1198 imp->imp_at.iat_portal[i], cur, worst, (s64)worstt,
1199 (s64)(now - worstt));
1200 lprocfs_at_hist_helper(m, &imp->imp_at.iat_service_estimate[i]);
1203 LPROCFS_CLIMP_EXIT(obd);
1206 EXPORT_SYMBOL(lprocfs_timeouts_seq_show);
1208 int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data)
1210 struct obd_device *obd = data;
1214 LPROCFS_CLIMP_CHECK(obd);
1215 flags = obd->u.cli.cl_import->imp_connect_data.ocd_connect_flags;
1216 flags2 = obd->u.cli.cl_import->imp_connect_data.ocd_connect_flags2;
1217 seq_printf(m, "flags=%#llx\n", flags);
1218 seq_printf(m, "flags2=%#llx\n", flags2);
1219 obd_connect_seq_flags2str(m, flags, flags2, "\n");
1220 seq_printf(m, "\n");
1221 LPROCFS_CLIMP_EXIT(obd);
1224 EXPORT_SYMBOL(lprocfs_connect_flags_seq_show);
1226 static struct attribute *obd_def_uuid_attrs[] = {
1227 &lustre_attr_uuid.attr,
1231 static struct attribute *obd_def_attrs[] = {
1232 &lustre_attr_blocksize.attr,
1233 &lustre_attr_kbytestotal.attr,
1234 &lustre_attr_kbytesfree.attr,
1235 &lustre_attr_kbytesavail.attr,
1236 &lustre_attr_filestotal.attr,
1237 &lustre_attr_filesfree.attr,
1238 &lustre_attr_uuid.attr,
1242 static void obd_sysfs_release(struct kobject *kobj)
1244 struct obd_device *obd = container_of(kobj, struct obd_device,
1247 complete(&obd->obd_kobj_unregister);
1250 static struct kobj_type obd_ktype = {
1251 .sysfs_ops = &lustre_sysfs_ops,
1252 .release = obd_sysfs_release,
1256 lprocfs_obd_setup(struct obd_device *obd, bool uuid_only)
1260 LASSERT(obd != NULL);
1261 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1264 obd_ktype.default_attrs = obd_def_uuid_attrs;
1266 obd_ktype.default_attrs = obd_def_attrs;
1268 init_completion(&obd->obd_kobj_unregister);
1269 rc = kobject_init_and_add(&obd->obd_kobj, &obd_ktype,
1270 obd->obd_type->typ_kobj,
1271 "%s", obd->obd_name);
1275 if (obd->obd_attrs) {
1276 rc = sysfs_create_group(&obd->obd_kobj, obd->obd_attrs);
1278 kobject_put(&obd->obd_kobj);
1283 if (obd->obd_proc_entry)
1284 GOTO(already_registered, rc);
1286 LASSERT(obd->obd_type->typ_procroot != NULL);
1288 obd->obd_proc_entry = lprocfs_register(obd->obd_name,
1289 obd->obd_type->typ_procroot,
1290 obd->obd_vars, obd);
1291 if (IS_ERR(obd->obd_proc_entry)) {
1292 kobject_put(&obd->obd_kobj);
1293 rc = PTR_ERR(obd->obd_proc_entry);
1294 CERROR("error %d setting up lprocfs for %s\n",rc,obd->obd_name);
1295 obd->obd_proc_entry = NULL;
1300 EXPORT_SYMBOL(lprocfs_obd_setup);
1302 int lprocfs_obd_cleanup(struct obd_device *obd)
1307 if (obd->obd_proc_exports_entry) {
1308 /* Should be no exports left */
1309 lprocfs_remove(&obd->obd_proc_exports_entry);
1310 obd->obd_proc_exports_entry = NULL;
1313 if (obd->obd_proc_entry) {
1314 lprocfs_remove(&obd->obd_proc_entry);
1315 obd->obd_proc_entry = NULL;
1318 kobject_put(&obd->obd_kobj);
1319 wait_for_completion(&obd->obd_kobj_unregister);
1322 EXPORT_SYMBOL(lprocfs_obd_cleanup);
1324 int lprocfs_stats_alloc_one(struct lprocfs_stats *stats, unsigned int cpuid)
1326 struct lprocfs_counter *cntr;
1327 unsigned int percpusize;
1329 unsigned long flags = 0;
1332 LASSERT(stats->ls_percpu[cpuid] == NULL);
1333 LASSERT((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0);
1335 percpusize = lprocfs_stats_counter_size(stats);
1336 LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[cpuid], percpusize);
1337 if (stats->ls_percpu[cpuid] != NULL) {
1339 if (unlikely(stats->ls_biggest_alloc_num <= cpuid)) {
1340 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
1341 spin_lock_irqsave(&stats->ls_lock, flags);
1343 spin_lock(&stats->ls_lock);
1344 if (stats->ls_biggest_alloc_num <= cpuid)
1345 stats->ls_biggest_alloc_num = cpuid + 1;
1346 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) {
1347 spin_unlock_irqrestore(&stats->ls_lock, flags);
1349 spin_unlock(&stats->ls_lock);
1352 /* initialize the ls_percpu[cpuid] non-zero counter */
1353 for (i = 0; i < stats->ls_num; ++i) {
1354 cntr = lprocfs_stats_counter_get(stats, cpuid, i);
1355 cntr->lc_min = LC_MIN_INIT;
1361 struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num,
1362 enum lprocfs_stats_flags flags)
1364 struct lprocfs_stats *stats;
1365 unsigned int num_entry;
1366 unsigned int percpusize = 0;
1372 if (lprocfs_no_percpu_stats != 0)
1373 flags |= LPROCFS_STATS_FLAG_NOPERCPU;
1375 if (flags & LPROCFS_STATS_FLAG_NOPERCPU)
1378 num_entry = num_possible_cpus();
1380 /* alloc percpu pointers for all possible cpu slots */
1381 LIBCFS_ALLOC(stats, offsetof(typeof(*stats), ls_percpu[num_entry]));
1385 stats->ls_num = num;
1386 stats->ls_flags = flags;
1387 spin_lock_init(&stats->ls_lock);
1389 /* alloc num of counter headers */
1390 LIBCFS_ALLOC(stats->ls_cnt_header,
1391 stats->ls_num * sizeof(struct lprocfs_counter_header));
1392 if (stats->ls_cnt_header == NULL)
1395 if ((flags & LPROCFS_STATS_FLAG_NOPERCPU) != 0) {
1396 /* contains only one set counters */
1397 percpusize = lprocfs_stats_counter_size(stats);
1398 LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[0], percpusize);
1399 if (stats->ls_percpu[0] == NULL)
1401 stats->ls_biggest_alloc_num = 1;
1402 } else if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0) {
1403 /* alloc all percpu data, currently only obd_memory use this */
1404 for (i = 0; i < num_entry; ++i)
1405 if (lprocfs_stats_alloc_one(stats, i) < 0)
1412 lprocfs_free_stats(&stats);
1415 EXPORT_SYMBOL(lprocfs_alloc_stats);
1417 void lprocfs_free_stats(struct lprocfs_stats **statsh)
1419 struct lprocfs_stats *stats = *statsh;
1420 unsigned int num_entry;
1421 unsigned int percpusize;
1424 if (stats == NULL || stats->ls_num == 0)
1428 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU)
1431 num_entry = num_possible_cpus();
1433 percpusize = lprocfs_stats_counter_size(stats);
1434 for (i = 0; i < num_entry; i++)
1435 if (stats->ls_percpu[i] != NULL)
1436 LIBCFS_FREE(stats->ls_percpu[i], percpusize);
1437 if (stats->ls_cnt_header != NULL)
1438 LIBCFS_FREE(stats->ls_cnt_header, stats->ls_num *
1439 sizeof(struct lprocfs_counter_header));
1440 LIBCFS_FREE(stats, offsetof(typeof(*stats), ls_percpu[num_entry]));
1442 EXPORT_SYMBOL(lprocfs_free_stats);
1444 u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
1445 enum lprocfs_fields_flags field)
1447 unsigned long flags = 0;
1448 unsigned int num_cpu;
1454 num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1455 for (i = 0; i < num_cpu; i++) {
1456 struct lprocfs_counter *cntr;
1458 if (!stats->ls_percpu[i])
1461 cntr = lprocfs_stats_counter_get(stats, i, idx);
1462 ret += lprocfs_read_helper(cntr, &stats->ls_cnt_header[idx],
1463 stats->ls_flags, field);
1465 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1468 EXPORT_SYMBOL(lprocfs_stats_collector);
1470 void lprocfs_clear_stats(struct lprocfs_stats *stats)
1472 struct lprocfs_counter *percpu_cntr;
1475 unsigned int num_entry;
1476 unsigned long flags = 0;
1478 num_entry = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1480 for (i = 0; i < num_entry; i++) {
1481 if (stats->ls_percpu[i] == NULL)
1483 for (j = 0; j < stats->ls_num; j++) {
1484 percpu_cntr = lprocfs_stats_counter_get(stats, i, j);
1485 percpu_cntr->lc_count = 0;
1486 percpu_cntr->lc_min = LC_MIN_INIT;
1487 percpu_cntr->lc_max = 0;
1488 percpu_cntr->lc_sumsquare = 0;
1489 percpu_cntr->lc_sum = 0;
1490 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
1491 percpu_cntr->lc_sum_irq = 0;
1495 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1497 EXPORT_SYMBOL(lprocfs_clear_stats);
1499 static ssize_t lprocfs_stats_seq_write(struct file *file,
1500 const char __user *buf,
1501 size_t len, loff_t *off)
1503 struct seq_file *seq = file->private_data;
1504 struct lprocfs_stats *stats = seq->private;
1506 lprocfs_clear_stats(stats);
1511 static void *lprocfs_stats_seq_start(struct seq_file *p, loff_t *pos)
1513 struct lprocfs_stats *stats = p->private;
1515 return (*pos < stats->ls_num) ? pos : NULL;
1518 static void lprocfs_stats_seq_stop(struct seq_file *p, void *v)
1522 static void *lprocfs_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
1526 return lprocfs_stats_seq_start(p, pos);
1529 /* seq file export of one lprocfs counter */
1530 static int lprocfs_stats_seq_show(struct seq_file *p, void *v)
1532 struct lprocfs_stats *stats = p->private;
1533 struct lprocfs_counter_header *hdr;
1534 struct lprocfs_counter ctr;
1535 int idx = *(loff_t *)v;
1538 struct timespec64 now;
1540 ktime_get_real_ts64(&now);
1541 seq_printf(p, "%-25s %llu.%09lu secs.nsecs\n",
1542 "snapshot_time", (s64)now.tv_sec, now.tv_nsec);
1545 hdr = &stats->ls_cnt_header[idx];
1546 lprocfs_stats_collect(stats, idx, &ctr);
1548 if (ctr.lc_count == 0)
1551 seq_printf(p, "%-25s %lld samples [%s]", hdr->lc_name,
1552 ctr.lc_count, hdr->lc_units);
1554 if ((hdr->lc_config & LPROCFS_CNTR_AVGMINMAX) && ctr.lc_count > 0) {
1555 seq_printf(p, " %lld %lld %lld",
1556 ctr.lc_min, ctr.lc_max, ctr.lc_sum);
1557 if (hdr->lc_config & LPROCFS_CNTR_STDDEV)
1558 seq_printf(p, " %llu", ctr.lc_sumsquare);
1564 static const struct seq_operations lprocfs_stats_seq_sops = {
1565 .start = lprocfs_stats_seq_start,
1566 .stop = lprocfs_stats_seq_stop,
1567 .next = lprocfs_stats_seq_next,
1568 .show = lprocfs_stats_seq_show,
1571 static int lprocfs_stats_seq_open(struct inode *inode, struct file *file)
1573 struct seq_file *seq;
1576 rc = LPROCFS_ENTRY_CHECK(inode);
1580 rc = seq_open(file, &lprocfs_stats_seq_sops);
1583 seq = file->private_data;
1584 seq->private = inode->i_private ? : PDE_DATA(inode);
1588 static const struct file_operations lprocfs_stats_seq_fops = {
1589 .owner = THIS_MODULE,
1590 .open = lprocfs_stats_seq_open,
1592 .write = lprocfs_stats_seq_write,
1593 .llseek = seq_lseek,
1594 .release = lprocfs_seq_release,
1597 int ldebugfs_register_stats(struct dentry *parent, const char *name,
1598 struct lprocfs_stats *stats)
1600 struct dentry *entry;
1602 LASSERT(!IS_ERR_OR_NULL(parent));
1604 entry = debugfs_create_file(name, 0644, parent, stats,
1605 &lprocfs_stats_seq_fops);
1606 if (IS_ERR_OR_NULL(entry))
1607 return entry ? PTR_ERR(entry) : -ENOMEM;
1611 EXPORT_SYMBOL_GPL(ldebugfs_register_stats);
1613 int lprocfs_register_stats(struct proc_dir_entry *root, const char *name,
1614 struct lprocfs_stats *stats)
1616 struct proc_dir_entry *entry;
1617 LASSERT(root != NULL);
1619 entry = proc_create_data(name, 0644, root,
1620 &lprocfs_stats_seq_fops, stats);
1625 EXPORT_SYMBOL(lprocfs_register_stats);
1627 void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
1628 unsigned conf, const char *name, const char *units)
1630 struct lprocfs_counter_header *header;
1631 struct lprocfs_counter *percpu_cntr;
1632 unsigned long flags = 0;
1634 unsigned int num_cpu;
1636 LASSERT(stats != NULL);
1638 header = &stats->ls_cnt_header[index];
1639 LASSERTF(header != NULL, "Failed to allocate stats header:[%d]%s/%s\n",
1640 index, name, units);
1642 header->lc_config = conf;
1643 header->lc_name = name;
1644 header->lc_units = units;
1646 num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1647 for (i = 0; i < num_cpu; ++i) {
1648 if (stats->ls_percpu[i] == NULL)
1650 percpu_cntr = lprocfs_stats_counter_get(stats, i, index);
1651 percpu_cntr->lc_count = 0;
1652 percpu_cntr->lc_min = LC_MIN_INIT;
1653 percpu_cntr->lc_max = 0;
1654 percpu_cntr->lc_sumsquare = 0;
1655 percpu_cntr->lc_sum = 0;
1656 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
1657 percpu_cntr->lc_sum_irq = 0;
1659 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1661 EXPORT_SYMBOL(lprocfs_counter_init);
1663 /* Note that we only init md counters for ops whose offset is less
1664 * than NUM_MD_STATS. This is explained in a comment in the definition
1665 * of struct md_ops. */
1666 #define LPROCFS_MD_OP_INIT(base, stats, op) \
1668 unsigned int _idx = base + MD_COUNTER_OFFSET(op); \
1670 if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS) { \
1671 LASSERT(_idx < stats->ls_num); \
1672 lprocfs_counter_init(stats, _idx, 0, #op, "reqs"); \
1676 void lprocfs_init_mps_stats(int num_private_stats, struct lprocfs_stats *stats)
1678 LPROCFS_MD_OP_INIT(num_private_stats, stats, get_root);
1679 LPROCFS_MD_OP_INIT(num_private_stats, stats, null_inode);
1680 LPROCFS_MD_OP_INIT(num_private_stats, stats, close);
1681 LPROCFS_MD_OP_INIT(num_private_stats, stats, create);
1682 LPROCFS_MD_OP_INIT(num_private_stats, stats, enqueue);
1683 LPROCFS_MD_OP_INIT(num_private_stats, stats, getattr);
1684 LPROCFS_MD_OP_INIT(num_private_stats, stats, getattr_name);
1685 LPROCFS_MD_OP_INIT(num_private_stats, stats, intent_lock);
1686 LPROCFS_MD_OP_INIT(num_private_stats, stats, link);
1687 LPROCFS_MD_OP_INIT(num_private_stats, stats, rename);
1688 LPROCFS_MD_OP_INIT(num_private_stats, stats, setattr);
1689 LPROCFS_MD_OP_INIT(num_private_stats, stats, fsync);
1690 LPROCFS_MD_OP_INIT(num_private_stats, stats, read_page);
1691 LPROCFS_MD_OP_INIT(num_private_stats, stats, unlink);
1692 LPROCFS_MD_OP_INIT(num_private_stats, stats, setxattr);
1693 LPROCFS_MD_OP_INIT(num_private_stats, stats, getxattr);
1694 LPROCFS_MD_OP_INIT(num_private_stats, stats, init_ea_size);
1695 LPROCFS_MD_OP_INIT(num_private_stats, stats, get_lustre_md);
1696 LPROCFS_MD_OP_INIT(num_private_stats, stats, free_lustre_md);
1697 LPROCFS_MD_OP_INIT(num_private_stats, stats, merge_attr);
1698 LPROCFS_MD_OP_INIT(num_private_stats, stats, set_open_replay_data);
1699 LPROCFS_MD_OP_INIT(num_private_stats, stats, clear_open_replay_data);
1700 LPROCFS_MD_OP_INIT(num_private_stats, stats, set_lock_data);
1701 LPROCFS_MD_OP_INIT(num_private_stats, stats, lock_match);
1702 LPROCFS_MD_OP_INIT(num_private_stats, stats, cancel_unused);
1703 LPROCFS_MD_OP_INIT(num_private_stats, stats, intent_getattr_async);
1704 LPROCFS_MD_OP_INIT(num_private_stats, stats, revalidate_lock);
1707 int lprocfs_alloc_md_stats(struct obd_device *obd,
1708 unsigned int num_private_stats)
1710 struct lprocfs_stats *stats;
1711 unsigned int num_stats;
1714 CLASSERT(offsetof(struct md_ops, MD_STATS_FIRST_OP) == 0);
1715 CLASSERT(_MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) == 0);
1716 CLASSERT(_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) > 0);
1718 /* TODO Ensure that this function is only used where
1719 * appropriate by adding an assertion to the effect that
1720 * obd->obd_type->typ_md_ops is not NULL. We can't do this now
1721 * because mdt_procfs_init() uses this function to allocate
1722 * the stats backing /proc/fs/lustre/mdt/.../md_stats but the
1723 * mdt layer does not use the md_ops interface. This is
1724 * confusing and a waste of memory. See LU-2484.
1726 LASSERT(obd->obd_proc_entry != NULL);
1727 LASSERT(obd->obd_md_stats == NULL);
1728 LASSERT(obd->obd_md_cntr_base == 0);
1730 num_stats = NUM_MD_STATS + num_private_stats;
1731 stats = lprocfs_alloc_stats(num_stats, 0);
1735 lprocfs_init_mps_stats(num_private_stats, stats);
1737 for (i = num_private_stats; i < num_stats; i++) {
1738 if (stats->ls_cnt_header[i].lc_name == NULL) {
1739 CERROR("Missing md_stat initializer md_op "
1740 "operation at offset %d. Aborting.\n",
1741 i - num_private_stats);
1746 rc = lprocfs_register_stats(obd->obd_proc_entry, "md_stats", stats);
1748 lprocfs_free_stats(&stats);
1750 obd->obd_md_stats = stats;
1751 obd->obd_md_cntr_base = num_private_stats;
1756 EXPORT_SYMBOL(lprocfs_alloc_md_stats);
1758 void lprocfs_free_md_stats(struct obd_device *obd)
1760 struct lprocfs_stats *stats = obd->obd_md_stats;
1762 if (stats != NULL) {
1763 obd->obd_md_stats = NULL;
1764 obd->obd_md_cntr_base = 0;
1765 lprocfs_free_stats(&stats);
1768 EXPORT_SYMBOL(lprocfs_free_md_stats);
1770 void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
1772 lprocfs_counter_init(ldlm_stats,
1773 LDLM_ENQUEUE - LDLM_FIRST_OPC,
1774 0, "ldlm_enqueue", "reqs");
1775 lprocfs_counter_init(ldlm_stats,
1776 LDLM_CONVERT - LDLM_FIRST_OPC,
1777 0, "ldlm_convert", "reqs");
1778 lprocfs_counter_init(ldlm_stats,
1779 LDLM_CANCEL - LDLM_FIRST_OPC,
1780 0, "ldlm_cancel", "reqs");
1781 lprocfs_counter_init(ldlm_stats,
1782 LDLM_BL_CALLBACK - LDLM_FIRST_OPC,
1783 0, "ldlm_bl_callback", "reqs");
1784 lprocfs_counter_init(ldlm_stats,
1785 LDLM_CP_CALLBACK - LDLM_FIRST_OPC,
1786 0, "ldlm_cp_callback", "reqs");
1787 lprocfs_counter_init(ldlm_stats,
1788 LDLM_GL_CALLBACK - LDLM_FIRST_OPC,
1789 0, "ldlm_gl_callback", "reqs");
1791 EXPORT_SYMBOL(lprocfs_init_ldlm_stats);
1793 __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
1794 struct lprocfs_counter_header *header,
1795 enum lprocfs_stats_flags flags,
1796 enum lprocfs_fields_flags field)
1800 if (lc == NULL || header == NULL)
1804 case LPROCFS_FIELDS_FLAGS_CONFIG:
1805 ret = header->lc_config;
1807 case LPROCFS_FIELDS_FLAGS_SUM:
1809 if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
1810 ret += lc->lc_sum_irq;
1812 case LPROCFS_FIELDS_FLAGS_MIN:
1815 case LPROCFS_FIELDS_FLAGS_MAX:
1818 case LPROCFS_FIELDS_FLAGS_AVG:
1819 ret = (lc->lc_max - lc->lc_min) / 2;
1821 case LPROCFS_FIELDS_FLAGS_SUMSQUARE:
1822 ret = lc->lc_sumsquare;
1824 case LPROCFS_FIELDS_FLAGS_COUNT:
1832 EXPORT_SYMBOL(lprocfs_read_helper);
1834 int lprocfs_read_frac_helper(char *buffer, unsigned long count, long val,
1837 long decimal_val, frac_val;
1843 decimal_val = val / mult;
1844 prtn = snprintf(buffer, count, "%ld", decimal_val);
1845 frac_val = val % mult;
1847 if (prtn < (count - 4) && frac_val > 0) {
1849 int i, temp_mult = 1, frac_bits = 0;
1851 temp_frac = frac_val * 10;
1852 buffer[prtn++] = '.';
1853 while (frac_bits < 2 && (temp_frac / mult) < 1 ) {
1854 /* only reserved 2 bits fraction */
1855 buffer[prtn++] ='0';
1860 * Need to think these cases :
1861 * 1. #echo x.00 > /proc/xxx output result : x
1862 * 2. #echo x.0x > /proc/xxx output result : x.0x
1863 * 3. #echo x.x0 > /proc/xxx output result : x.x
1864 * 4. #echo x.xx > /proc/xxx output result : x.xx
1865 * Only reserved 2 bits fraction.
1867 for (i = 0; i < (5 - prtn); i++)
1870 frac_bits = min((int)count - prtn, 3 - frac_bits);
1871 prtn += snprintf(buffer + prtn, frac_bits, "%ld",
1872 frac_val * temp_mult / mult);
1875 while(buffer[prtn] < '1' || buffer[prtn] > '9') {
1877 if (buffer[prtn] == '.') {
1884 buffer[prtn++] ='\n';
1887 EXPORT_SYMBOL(lprocfs_read_frac_helper);
1889 int lprocfs_seq_read_frac_helper(struct seq_file *m, long val, int mult)
1891 long decimal_val, frac_val;
1893 decimal_val = val / mult;
1894 seq_printf(m, "%ld", decimal_val);
1895 frac_val = val % mult;
1902 /* Three cases: x0, xx, 0x */
1903 if ((frac_val % 10) != 0)
1904 seq_printf(m, ".%ld", frac_val);
1906 seq_printf(m, ".%ld", frac_val / 10);
1909 seq_printf(m, "\n");
1912 EXPORT_SYMBOL(lprocfs_seq_read_frac_helper);
1914 /* Obtains the conversion factor for the unit specified */
1915 static int get_mult(char unit, __u64 *mult)
1920 /* peta, tera, giga, mega, and kilo */
1937 /* some tests expect % to be accepted */
1951 * Ensures the numeric string is valid. The function provides the final
1952 * multiplier in the case a unit exists at the end of the string. It also
1953 * locates the start of the whole and fractional parts (if any). This
1954 * function modifies the string so kstrtoull can be used to parse both
1955 * the whole and fraction portions. This function also figures out
1956 * the base of the number.
1958 static int preprocess_numeric_str(char *buffer, __u64 *mult, __u64 def_mult,
1959 bool allow_units, char **whole, char **frac,
1962 bool hit_decimal = false;
1963 bool hit_unit = false;
1971 /* a hex string if it starts with "0x" */
1972 if (buffer[0] == '0' && tolower(buffer[1]) == 'x') {
1980 /* allow for a single new line before the null terminator */
1981 if (*buffer == '\n') {
1991 /* any chars after our unit indicates a malformed string */
1995 /* ensure we only hit one decimal */
1996 if (*buffer == '.') {
2000 /* if past start, there's a whole part */
2001 if (start != buffer)
2007 } else if (!isdigit(*buffer) &&
2008 !(*base == 16 && isxdigit(*buffer))) {
2010 /* if we allow units, attempt to get mult */
2012 rc = get_mult(*buffer, mult);
2016 /* string stops here, but keep processing */
2028 /* hit a decimal, make sure there's a fractional part */
2034 /* didn't hit a decimal, but may have a whole part */
2035 if (start != buffer && *start)
2039 /* malformed string if we didn't get anything */
2040 if (!*frac && !*whole)
2047 * Parses a numeric string which can contain a whole and fraction portion
2048 * into a __u64. Accepts a multiplier to apply to the value parsed. Also
2049 * allows the string to have a unit at the end. The function handles
2050 * wrapping of the final unsigned value.
2052 static int str_to_u64_parse(char *buffer, unsigned long count,
2053 __u64 *val, __u64 def_mult, bool allow_units)
2057 unsigned int frac_d = 1;
2058 __u64 wrap_indicator = ULLONG_MAX;
2063 unsigned int base = 10;
2065 rc = preprocess_numeric_str(buffer, &mult, def_mult, allow_units,
2066 &strwhole, &strfrac, &base);
2076 /* the multiplier limits how large the value can be */
2077 wrap_indicator /= mult;
2080 rc = kstrtoull(strwhole, base, &whole);
2084 if (whole > wrap_indicator)
2091 if (strlen(strfrac) > 10)
2094 rc = kstrtoull(strfrac, base, &frac);
2098 /* determine power of fractional portion */
2104 /* fractional portion is too large to perform calculation */
2105 if (frac > wrap_indicator)
2109 do_div(frac, frac_d);
2112 /* check that the sum of whole and fraction fits in u64 */
2113 if (whole > (ULLONG_MAX - frac))
2116 *val = whole + frac;
2122 * This function parses numeric/hex strings into __s64. It accepts a multiplier
2123 * which will apply to the value parsed. It also can allow the string to
2124 * have a unit as the last character. The function handles overflow/underflow
2125 * of the signed integer.
2127 static int str_to_s64_internal(const char __user *buffer, unsigned long count,
2128 __s64 *val, __u64 def_mult, bool allow_units)
2132 unsigned int offset = 0;
2133 int signed sign = 1;
2134 __u64 max = LLONG_MAX;
2137 if (count > (sizeof(kernbuf) - 1))
2140 if (copy_from_user(kernbuf, buffer, count))
2143 kernbuf[count] = '\0';
2145 /* keep track of our sign */
2146 if (*kernbuf == '-') {
2149 /* equivalent to max = -LLONG_MIN, avoids overflow */
2153 rc = str_to_u64_parse(kernbuf + offset, count - offset,
2154 &tmp, def_mult, allow_units);
2158 /* check for overflow/underflow */
2162 *val = (__s64)tmp * sign;
2168 * Convert a user string into a signed 64 bit number. This function produces
2169 * an error when the value parsed from the string underflows or
2170 * overflows. This function accepts strings which contain digits and
2171 * optionally a decimal or hex strings which are prefixed with "0x".
2173 * \param[in] buffer string consisting of numbers and optionally a decimal
2174 * \param[in] count buffer length
2175 * \param[in] val if successful, the value represented by the string
2177 * \retval 0 on success
2178 * \retval negative number on error
2180 int lprocfs_str_to_s64(const char __user *buffer, unsigned long count,
2183 return str_to_s64_internal(buffer, count, val, 1, false);
2185 EXPORT_SYMBOL(lprocfs_str_to_s64);
2188 * Convert a user string into a signed 64 bit number. This function produces
2189 * an error when the value parsed from the string times multiplier underflows or
2190 * overflows. This function only accepts strings that contains digits, an
2191 * optional decimal, and a char representing a unit at the end. If a unit is
2192 * specified in the string, the multiplier provided by the caller is ignored.
2193 * This function can also accept hexadecimal strings which are prefixed with
2196 * \param[in] buffer string consisting of numbers, a decimal, and a unit
2197 * \param[in] count buffer length
2198 * \param[in] val if successful, the value represented by the string
2199 * \param[in] defunit default unit if string doesn't contain one
2201 * \retval 0 on success
2202 * \retval negative number on error
2204 int lprocfs_str_with_units_to_s64(const char __user *buffer,
2205 unsigned long count, __s64 *val, char defunit)
2210 if (defunit != '1') {
2211 rc = get_mult(defunit, &mult);
2216 return str_to_s64_internal(buffer, count, val, mult, true);
2218 EXPORT_SYMBOL(lprocfs_str_with_units_to_s64);
2220 static char *lprocfs_strnstr(const char *s1, const char *s2, size_t len)
2229 if (!memcmp(s1, s2, l2))
2237 * Find the string \a name in the input \a buffer, and return a pointer to the
2238 * value immediately following \a name, reducing \a count appropriately.
2239 * If \a name is not found the original \a buffer is returned.
2241 char *lprocfs_find_named_value(const char *buffer, const char *name,
2245 size_t buflen = *count;
2247 /* there is no strnstr() in rhel5 and ubuntu kernels */
2248 val = lprocfs_strnstr(buffer, name, buflen);
2250 return (char *)buffer;
2252 val += strlen(name); /* skip prefix */
2253 while (val < buffer + buflen && isspace(*val)) /* skip separator */
2257 while (val < buffer + buflen && isalnum(*val)) {
2262 return val - *count;
2264 EXPORT_SYMBOL(lprocfs_find_named_value);
2266 int ldebugfs_seq_create(struct dentry *parent, const char *name, umode_t mode,
2267 const struct file_operations *seq_fops, void *data)
2269 struct dentry *entry;
2271 /* Disallow secretly (un)writable entries. */
2272 LASSERT((!seq_fops->write) == (!(mode & 0222)));
2274 entry = debugfs_create_file(name, mode, parent, data, seq_fops);
2275 if (IS_ERR_OR_NULL(entry))
2276 return entry ? PTR_ERR(entry) : -ENOMEM;
2280 EXPORT_SYMBOL_GPL(ldebugfs_seq_create);
2282 int lprocfs_seq_create(struct proc_dir_entry *parent,
2285 const struct file_operations *seq_fops,
2288 struct proc_dir_entry *entry;
2291 /* Disallow secretly (un)writable entries. */
2292 LASSERT((seq_fops->write == NULL) == ((mode & 0222) == 0));
2294 entry = proc_create_data(name, mode, parent, seq_fops, data);
2301 EXPORT_SYMBOL(lprocfs_seq_create);
2303 int lprocfs_obd_seq_create(struct obd_device *dev,
2306 const struct file_operations *seq_fops,
2309 return (lprocfs_seq_create(dev->obd_proc_entry, name,
2310 mode, seq_fops, data));
2312 EXPORT_SYMBOL(lprocfs_obd_seq_create);
2314 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
2316 if (value >= OBD_HIST_MAX)
2317 value = OBD_HIST_MAX - 1;
2319 spin_lock(&oh->oh_lock);
2320 oh->oh_buckets[value]++;
2321 spin_unlock(&oh->oh_lock);
2323 EXPORT_SYMBOL(lprocfs_oh_tally);
2325 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
2327 unsigned int val = 0;
2329 if (likely(value != 0))
2330 val = min(fls(value - 1), OBD_HIST_MAX);
2332 lprocfs_oh_tally(oh, val);
2334 EXPORT_SYMBOL(lprocfs_oh_tally_log2);
2336 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
2338 unsigned long ret = 0;
2341 for (i = 0; i < OBD_HIST_MAX; i++)
2342 ret += oh->oh_buckets[i];
2345 EXPORT_SYMBOL(lprocfs_oh_sum);
2347 void lprocfs_oh_clear(struct obd_histogram *oh)
2349 spin_lock(&oh->oh_lock);
2350 memset(oh->oh_buckets, 0, sizeof(oh->oh_buckets));
2351 spin_unlock(&oh->oh_lock);
2353 EXPORT_SYMBOL(lprocfs_oh_clear);
2355 ssize_t lustre_attr_show(struct kobject *kobj,
2356 struct attribute *attr, char *buf)
2358 struct lustre_attr *a = container_of(attr, struct lustre_attr, attr);
2360 return a->show ? a->show(kobj, attr, buf) : 0;
2362 EXPORT_SYMBOL_GPL(lustre_attr_show);
2364 ssize_t lustre_attr_store(struct kobject *kobj, struct attribute *attr,
2365 const char *buf, size_t len)
2367 struct lustre_attr *a = container_of(attr, struct lustre_attr, attr);
2369 return a->store ? a->store(kobj, attr, buf, len) : len;
2371 EXPORT_SYMBOL_GPL(lustre_attr_store);
2373 const struct sysfs_ops lustre_sysfs_ops = {
2374 .show = lustre_attr_show,
2375 .store = lustre_attr_store,
2377 EXPORT_SYMBOL_GPL(lustre_sysfs_ops);
2379 int lprocfs_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *data)
2381 struct obd_device *dev = data;
2382 struct client_obd *cli = &dev->u.cli;
2384 spin_lock(&cli->cl_loi_list_lock);
2385 seq_printf(m, "%d\n", cli->cl_max_pages_per_rpc);
2386 spin_unlock(&cli->cl_loi_list_lock);
2389 EXPORT_SYMBOL(lprocfs_obd_max_pages_per_rpc_seq_show);
2391 ssize_t lprocfs_obd_max_pages_per_rpc_seq_write(struct file *file,
2392 const char __user *buffer,
2393 size_t count, loff_t *off)
2395 struct obd_device *dev =
2396 ((struct seq_file *)file->private_data)->private;
2397 struct client_obd *cli = &dev->u.cli;
2398 struct obd_connect_data *ocd = &cli->cl_import->imp_connect_data;
2402 rc = lprocfs_str_with_units_to_s64(buffer, count, &val, '1');
2408 /* if the max_pages is specified in bytes, convert to pages */
2409 if (val >= ONE_MB_BRW_SIZE)
2412 LPROCFS_CLIMP_CHECK(dev);
2414 chunk_mask = ~((1 << (cli->cl_chunkbits - PAGE_SHIFT)) - 1);
2415 /* max_pages_per_rpc must be chunk aligned */
2416 val = (val + ~chunk_mask) & chunk_mask;
2417 if (val == 0 || (ocd->ocd_brw_size != 0 &&
2418 val > ocd->ocd_brw_size >> PAGE_SHIFT)) {
2419 LPROCFS_CLIMP_EXIT(dev);
2422 spin_lock(&cli->cl_loi_list_lock);
2423 cli->cl_max_pages_per_rpc = val;
2424 client_adjust_max_dirty(cli);
2425 spin_unlock(&cli->cl_loi_list_lock);
2427 LPROCFS_CLIMP_EXIT(dev);
2430 EXPORT_SYMBOL(lprocfs_obd_max_pages_per_rpc_seq_write);
2432 int lprocfs_wr_root_squash(const char __user *buffer, unsigned long count,
2433 struct root_squash_info *squash, char *name)
2436 char kernbuf[64], *tmp, *errmsg;
2437 unsigned long uid, gid;
2440 if (count >= sizeof(kernbuf)) {
2441 errmsg = "string too long";
2442 GOTO(failed_noprint, rc = -EINVAL);
2444 if (copy_from_user(kernbuf, buffer, count)) {
2445 errmsg = "bad address";
2446 GOTO(failed_noprint, rc = -EFAULT);
2448 kernbuf[count] = '\0';
2450 /* look for uid gid separator */
2451 tmp = strchr(kernbuf, ':');
2453 errmsg = "needs uid:gid format";
2454 GOTO(failed, rc = -EINVAL);
2460 if (kstrtoul(kernbuf, 0, &uid) != 0) {
2462 GOTO(failed, rc = -EINVAL);
2466 if (kstrtoul(tmp, 0, &gid) != 0) {
2468 GOTO(failed, rc = -EINVAL);
2471 squash->rsi_uid = uid;
2472 squash->rsi_gid = gid;
2474 LCONSOLE_INFO("%s: root_squash is set to %u:%u\n",
2475 name, squash->rsi_uid, squash->rsi_gid);
2483 CWARN("%s: failed to set root_squash to \"%s\", %s, rc = %d\n",
2484 name, kernbuf, errmsg, rc);
2487 CWARN("%s: failed to set root_squash due to %s, rc = %d\n",
2491 EXPORT_SYMBOL(lprocfs_wr_root_squash);
2494 int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count,
2495 struct root_squash_info *squash, char *name)
2498 char *kernbuf = NULL;
2500 struct list_head tmp;
2505 errmsg = "string too long";
2506 GOTO(failed, rc = -EINVAL);
2509 OBD_ALLOC(kernbuf, count + 1);
2510 if (kernbuf == NULL) {
2511 errmsg = "no memory";
2512 GOTO(failed, rc = -ENOMEM);
2514 if (copy_from_user(kernbuf, buffer, count)) {
2515 errmsg = "bad address";
2516 GOTO(failed, rc = -EFAULT);
2518 kernbuf[count] = '\0';
2520 if (count > 0 && kernbuf[count - 1] == '\n')
2523 if ((len == 4 && strncmp(kernbuf, "NONE", len) == 0) ||
2524 (len == 5 && strncmp(kernbuf, "clear", len) == 0)) {
2525 /* empty string is special case */
2526 down_write(&squash->rsi_sem);
2527 if (!list_empty(&squash->rsi_nosquash_nids))
2528 cfs_free_nidlist(&squash->rsi_nosquash_nids);
2529 up_write(&squash->rsi_sem);
2530 LCONSOLE_INFO("%s: nosquash_nids is cleared\n", name);
2531 OBD_FREE(kernbuf, count + 1);
2535 INIT_LIST_HEAD(&tmp);
2536 if (cfs_parse_nidlist(kernbuf, count, &tmp) <= 0) {
2537 errmsg = "can't parse";
2538 GOTO(failed, rc = -EINVAL);
2540 LCONSOLE_INFO("%s: nosquash_nids set to %s\n",
2542 OBD_FREE(kernbuf, count + 1);
2545 down_write(&squash->rsi_sem);
2546 if (!list_empty(&squash->rsi_nosquash_nids))
2547 cfs_free_nidlist(&squash->rsi_nosquash_nids);
2548 list_splice(&tmp, &squash->rsi_nosquash_nids);
2549 up_write(&squash->rsi_sem);
2555 CWARN("%s: failed to set nosquash_nids to \"%s\", %s rc = %d\n",
2556 name, kernbuf, errmsg, rc);
2557 OBD_FREE(kernbuf, count + 1);
2559 CWARN("%s: failed to set nosquash_nids due to %s rc = %d\n",
2564 EXPORT_SYMBOL(lprocfs_wr_nosquash_nids);
2566 #endif /* CONFIG_PROC_FS*/