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/
31 * lustre/obdclass/lprocfs_status.c
33 * Author: Hariharan Thantry <thantry@users.sourceforge.net>
36 #define DEBUG_SUBSYSTEM S_CLASS
38 #include <obd_class.h>
39 #include <lprocfs_status.h>
43 static int lprocfs_no_percpu_stats = 0;
44 module_param(lprocfs_no_percpu_stats, int, 0644);
45 MODULE_PARM_DESC(lprocfs_no_percpu_stats, "Do not alloc percpu data for lprocfs stats");
47 #define MAX_STRING_SIZE 128
49 int lprocfs_single_release(struct inode *inode, struct file *file)
51 return single_release(inode, file);
53 EXPORT_SYMBOL(lprocfs_single_release);
55 int lprocfs_seq_release(struct inode *inode, struct file *file)
57 return seq_release(inode, file);
59 EXPORT_SYMBOL(lprocfs_seq_release);
61 static umode_t default_mode(const struct proc_ops *ops)
73 struct proc_dir_entry *
74 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
75 void *data, const struct proc_ops *fops)
77 struct proc_dir_entry *proc;
80 if (!root || !name || !fops)
81 return ERR_PTR(-EINVAL);
83 mode = default_mode(fops);
84 proc = proc_create_data(name, mode, root, fops, data);
86 CERROR("LprocFS: No memory to create /proc entry %s\n",
88 return ERR_PTR(-ENOMEM);
92 EXPORT_SYMBOL(lprocfs_add_simple);
94 struct proc_dir_entry *lprocfs_add_symlink(const char *name,
95 struct proc_dir_entry *parent,
96 const char *format, ...)
98 struct proc_dir_entry *entry;
102 if (!parent || !format)
105 OBD_ALLOC_WAIT(dest, MAX_STRING_SIZE + 1);
109 va_start(ap, format);
110 vsnprintf(dest, MAX_STRING_SIZE, format, ap);
113 entry = proc_symlink(name, parent, dest);
115 CERROR("LprocFS: Could not create symbolic link from "
116 "%s to %s\n", name, dest);
118 OBD_FREE(dest, MAX_STRING_SIZE + 1);
121 EXPORT_SYMBOL(lprocfs_add_symlink);
123 static const struct file_operations ldebugfs_empty_ops = { };
125 void ldebugfs_add_vars(struct dentry *parent, struct ldebugfs_vars *list,
128 if (IS_ERR_OR_NULL(parent) || IS_ERR_OR_NULL(list))
134 if (list->proc_mode != 0000) {
135 mode = list->proc_mode;
136 } else if (list->fops) {
137 if (list->fops->read)
139 if (list->fops->write)
142 debugfs_create_file(list->name, mode, parent,
144 list->fops ? : &ldebugfs_empty_ops);
148 EXPORT_SYMBOL_GPL(ldebugfs_add_vars);
150 static const struct proc_ops lprocfs_empty_ops = { };
155 * \param root [in] The parent proc entry on which new entry will be added.
156 * \param list [in] Array of proc entries to be added.
157 * \param data [in] The argument to be passed when entries read/write routines
158 * are called through /proc file.
160 * \retval 0 on success
164 lprocfs_add_vars(struct proc_dir_entry *root, struct lprocfs_vars *list,
171 struct proc_dir_entry *proc;
175 mode = list->proc_mode;
177 mode = default_mode(list->fops);
178 proc = proc_create_data(list->name, mode, root,
179 list->fops ?: &lprocfs_empty_ops,
187 EXPORT_SYMBOL(lprocfs_add_vars);
189 void lprocfs_remove(struct proc_dir_entry **rooth)
194 EXPORT_SYMBOL(lprocfs_remove);
196 void lprocfs_remove_proc_entry(const char *name, struct proc_dir_entry *parent)
198 LASSERT(parent != NULL);
199 remove_proc_entry(name, parent);
201 EXPORT_SYMBOL(lprocfs_remove_proc_entry);
203 struct proc_dir_entry *
204 lprocfs_register(const char *name, struct proc_dir_entry *parent,
205 struct lprocfs_vars *list, void *data)
207 struct proc_dir_entry *newchild;
209 newchild = proc_mkdir(name, parent);
211 return ERR_PTR(-ENOMEM);
214 int rc = lprocfs_add_vars(newchild, list, data);
216 lprocfs_remove(&newchild);
222 EXPORT_SYMBOL(lprocfs_register);
224 /* Generic callbacks */
225 int lprocfs_uuid_seq_show(struct seq_file *m, void *data)
227 struct obd_device *obd = data;
229 LASSERT(obd != NULL);
230 seq_printf(m, "%s\n", obd->obd_uuid.uuid);
233 EXPORT_SYMBOL(lprocfs_uuid_seq_show);
235 static ssize_t uuid_show(struct kobject *kobj, struct attribute *attr,
238 struct obd_device *obd = container_of(kobj, struct obd_device,
241 return sprintf(buf, "%s\n", obd->obd_uuid.uuid);
243 LUSTRE_RO_ATTR(uuid);
245 static ssize_t blocksize_show(struct kobject *kobj, struct attribute *attr,
248 struct obd_device *obd = container_of(kobj, struct obd_device,
250 struct obd_statfs osfs;
253 rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
254 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
257 return sprintf(buf, "%u\n", osfs.os_bsize);
261 LUSTRE_RO_ATTR(blocksize);
263 static ssize_t kbytestotal_show(struct kobject *kobj, struct attribute *attr,
266 struct obd_device *obd = container_of(kobj, struct obd_device,
268 struct obd_statfs osfs;
271 rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
272 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
275 u32 blk_size = osfs.os_bsize >> 10;
276 u64 result = osfs.os_blocks;
278 result *= rounddown_pow_of_two(blk_size ?: 1);
279 return sprintf(buf, "%llu\n", result);
284 LUSTRE_RO_ATTR(kbytestotal);
286 static ssize_t kbytesfree_show(struct kobject *kobj, struct attribute *attr,
289 struct obd_device *obd = container_of(kobj, struct obd_device,
291 struct obd_statfs osfs;
294 rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
295 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
298 u32 blk_size = osfs.os_bsize >> 10;
299 u64 result = osfs.os_bfree;
301 while (blk_size >>= 1)
304 return sprintf(buf, "%llu\n", result);
309 LUSTRE_RO_ATTR(kbytesfree);
311 static ssize_t kbytesavail_show(struct kobject *kobj, struct attribute *attr,
314 struct obd_device *obd = container_of(kobj, struct obd_device,
316 struct obd_statfs osfs;
319 rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
320 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
323 u32 blk_size = osfs.os_bsize >> 10;
324 u64 result = osfs.os_bavail;
326 while (blk_size >>= 1)
329 return sprintf(buf, "%llu\n", result);
334 LUSTRE_RO_ATTR(kbytesavail);
336 static ssize_t filestotal_show(struct kobject *kobj, struct attribute *attr,
339 struct obd_device *obd = container_of(kobj, struct obd_device,
341 struct obd_statfs osfs;
344 rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
345 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
348 return sprintf(buf, "%llu\n", osfs.os_files);
352 LUSTRE_RO_ATTR(filestotal);
354 static ssize_t filesfree_show(struct kobject *kobj, struct attribute *attr,
357 struct obd_device *obd = container_of(kobj, struct obd_device,
359 struct obd_statfs osfs;
362 rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
363 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
366 return sprintf(buf, "%llu\n", osfs.os_ffree);
370 LUSTRE_RO_ATTR(filesfree);
372 ssize_t conn_uuid_show(struct kobject *kobj, struct attribute *attr, char *buf)
374 struct obd_device *obd = container_of(kobj, struct obd_device,
376 struct obd_import *imp;
377 struct ptlrpc_connection *conn;
380 with_imp_locked(obd, imp, count) {
381 conn = imp->imp_connection;
383 count = sprintf(buf, "%s\n", conn->c_remote_uuid.uuid);
385 count = sprintf(buf, "%s\n", "<none>");
390 EXPORT_SYMBOL(conn_uuid_show);
392 int lprocfs_server_uuid_seq_show(struct seq_file *m, void *data)
394 struct obd_device *obd = data;
395 struct obd_import *imp;
396 const char *imp_state_name = NULL;
399 LASSERT(obd != NULL);
400 with_imp_locked(obd, imp, rc) {
401 imp_state_name = ptlrpc_import_state_name(imp->imp_state);
402 seq_printf(m, "%s\t%s%s\n", obd2cli_tgt(obd), imp_state_name,
403 imp->imp_deactive ? "\tDEACTIVATED" : "");
408 EXPORT_SYMBOL(lprocfs_server_uuid_seq_show);
410 /** add up per-cpu counters */
413 * Lock statistics structure for access, possibly only on this CPU.
415 * The statistics struct may be allocated with per-CPU structures for
416 * efficient concurrent update (usually only on server-wide stats), or
417 * as a single global struct (e.g. for per-client or per-job statistics),
418 * so the required locking depends on the type of structure allocated.
420 * For per-CPU statistics, pin the thread to the current cpuid so that
421 * will only access the statistics for that CPU. If the stats structure
422 * for the current CPU has not been allocated (or previously freed),
423 * allocate it now. The per-CPU statistics do not need locking since
424 * the thread is pinned to the CPU during update.
426 * For global statistics, lock the stats structure to prevent concurrent update.
428 * \param[in] stats statistics structure to lock
429 * \param[in] opc type of operation:
430 * LPROCFS_GET_SMP_ID: "lock" and return current CPU index
431 * for incrementing statistics for that CPU
432 * LPROCFS_GET_NUM_CPU: "lock" and return number of used
433 * CPU indices to iterate over all indices
434 * \param[out] flags CPU interrupt saved state for IRQ-safe locking
436 * \retval cpuid of current thread or number of allocated structs
437 * \retval negative on error (only for opc LPROCFS_GET_SMP_ID + per-CPU stats)
439 int lprocfs_stats_lock(struct lprocfs_stats *stats,
440 enum lprocfs_stats_lock_ops opc,
441 unsigned long *flags)
443 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
444 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
445 spin_lock_irqsave(&stats->ls_lock, *flags);
447 spin_lock(&stats->ls_lock);
448 return opc == LPROCFS_GET_NUM_CPU ? 1 : 0;
452 case LPROCFS_GET_SMP_ID: {
453 unsigned int cpuid = get_cpu();
455 if (unlikely(!stats->ls_percpu[cpuid])) {
456 int rc = lprocfs_stats_alloc_one(stats, cpuid);
465 case LPROCFS_GET_NUM_CPU:
466 return stats->ls_biggest_alloc_num;
473 * Unlock statistics structure after access.
475 * Unlock the lock acquired via lprocfs_stats_lock() for global statistics,
476 * or unpin this thread from the current cpuid for per-CPU statistics.
478 * This function must be called using the same arguments as used when calling
479 * lprocfs_stats_lock() so that the correct operation can be performed.
481 * \param[in] stats statistics structure to unlock
482 * \param[in] opc type of operation (current cpuid or number of structs)
483 * \param[in] flags CPU interrupt saved state for IRQ-safe locking
485 void lprocfs_stats_unlock(struct lprocfs_stats *stats,
486 enum lprocfs_stats_lock_ops opc,
487 unsigned long *flags)
489 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
490 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
491 spin_unlock_irqrestore(&stats->ls_lock, *flags);
493 spin_unlock(&stats->ls_lock);
494 } else if (opc == LPROCFS_GET_SMP_ID) {
499 /** add up per-cpu counters */
500 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
501 struct lprocfs_counter *cnt)
503 unsigned int num_entry;
504 struct lprocfs_counter *percpu_cntr;
506 unsigned long flags = 0;
508 memset(cnt, 0, sizeof(*cnt));
511 /* set count to 1 to avoid divide-by-zero errs in callers */
516 cnt->lc_min = LC_MIN_INIT;
518 num_entry = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
520 for (i = 0; i < num_entry; i++) {
521 if (!stats->ls_percpu[i])
523 percpu_cntr = lprocfs_stats_counter_get(stats, i, idx);
525 cnt->lc_count += percpu_cntr->lc_count;
526 cnt->lc_sum += percpu_cntr->lc_sum;
527 if (percpu_cntr->lc_min < cnt->lc_min)
528 cnt->lc_min = percpu_cntr->lc_min;
529 if (percpu_cntr->lc_max > cnt->lc_max)
530 cnt->lc_max = percpu_cntr->lc_max;
531 cnt->lc_sumsquare += percpu_cntr->lc_sumsquare;
534 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
537 static void obd_import_flags2str(struct obd_import *imp, struct seq_file *m)
541 if (imp->imp_obd->obd_no_recov) {
542 seq_printf(m, "no_recov");
546 flag2str(imp, invalid);
547 flag2str(imp, deactive);
548 flag2str(imp, replayable);
549 flag2str(imp, delayed_recovery);
550 flag2str(imp, vbr_failed);
551 flag2str(imp, pingable);
552 flag2str(imp, resend_replay);
553 flag2str(imp, no_pinger_recover);
554 flag2str(imp, connect_tried);
557 static const char *const obd_connect_names[] = {
558 "read_only", /* 0x01 */
559 "lov_index", /* 0x02 */
560 "connect_from_mds", /* 0x03 */
561 "write_grant", /* 0x04 */
562 "server_lock", /* 0x10 */
563 "version", /* 0x20 */
564 "request_portal", /* 0x40 */
567 "create_on_write", /* 0x200 */
568 "truncate_lock", /* 0x400 */
569 "initial_transno", /* 0x800 */
570 "inode_bit_locks", /* 0x1000 */
571 "barrier", /* 0x2000 */
572 "getattr_by_fid", /* 0x4000 */
573 "no_oh_for_devices", /* 0x8000 */
574 "remote_client", /* 0x10000 */
575 "remote_client_by_force", /* 0x20000 */
576 "max_byte_per_rpc", /* 0x40000 */
577 "64bit_qdata", /* 0x80000 */
578 "mds_capability", /* 0x100000 */
579 "oss_capability", /* 0x200000 */
580 "early_lock_cancel", /* 0x400000 */
581 "som", /* 0x800000 */
582 "adaptive_timeouts", /* 0x1000000 */
583 "lru_resize", /* 0x2000000 */
584 "mds_mds_connection", /* 0x4000000 */
585 "real_conn", /* 0x8000000 */
586 "change_qunit_size", /* 0x10000000 */
587 "alt_checksum_algorithm", /* 0x20000000 */
588 "fid_is_enabled", /* 0x40000000 */
589 "version_recovery", /* 0x80000000 */
590 "pools", /* 0x100000000 */
591 "grant_shrink", /* 0x200000000 */
592 "skip_orphan", /* 0x400000000 */
593 "large_ea", /* 0x800000000 */
594 "full20", /* 0x1000000000 */
595 "layout_lock", /* 0x2000000000 */
596 "64bithash", /* 0x4000000000 */
597 "object_max_bytes", /* 0x8000000000 */
598 "imp_recov", /* 0x10000000000 */
599 "jobstats", /* 0x20000000000 */
600 "umask", /* 0x40000000000 */
601 "einprogress", /* 0x80000000000 */
602 "grant_param", /* 0x100000000000 */
603 "flock_owner", /* 0x200000000000 */
604 "lvb_type", /* 0x400000000000 */
605 "nanoseconds_times", /* 0x800000000000 */
606 "lightweight_conn", /* 0x1000000000000 */
607 "short_io", /* 0x2000000000000 */
608 "pingless", /* 0x4000000000000 */
609 "flock_deadlock", /* 0x8000000000000 */
610 "disp_stripe", /* 0x10000000000000 */
611 "open_by_fid", /* 0x20000000000000 */
612 "lfsck", /* 0x40000000000000 */
613 "unknown", /* 0x80000000000000 */
614 "unlink_close", /* 0x100000000000000 */
615 "multi_mod_rpcs", /* 0x200000000000000 */
616 "dir_stripe", /* 0x400000000000000 */
617 "subtree", /* 0x800000000000000 */
618 "lockahead", /* 0x1000000000000000 */
619 "bulk_mbits", /* 0x2000000000000000 */
620 "compact_obdo", /* 0x4000000000000000 */
621 "second_flags", /* 0x8000000000000000 */
622 /* ocd_connect_flags2 names */
623 "file_secctx", /* 0x01 */
624 "lockaheadv2", /* 0x02 */
625 "dir_migrate", /* 0x04 */
626 "sum_statfs", /* 0x08 */
627 "overstriping", /* 0x10 */
630 "lock_convert", /* 0x80 */
631 "archive_id_array", /* 0x100 */
632 "increasing_xid", /* 0x200 */
633 "selinux_policy", /* 0x400 */
636 "crush", /* 0x2000 */
637 "async_discard", /* 0x4000 */
638 "client_encryption", /* 0x8000 */
639 "fidmap", /* 0x10000 */
640 "getattr_pfid", /* 0x20000 */
641 "lseek", /* 0x40000 */
642 "dom_lvb", /* 0x80000 */
643 "reply_mbits", /* 0x100000 */
644 "mode_convert", /* 0x200000 */
645 "batch_rpc", /* 0x400000 */
646 "pcc_ro", /* 0x800000 */
647 "mne_nid_type", /* 0x1000000 */
648 "lock_contend", /* 0x2000000 */
649 "atomic_open_lock", /* 0x4000000 */
650 "name_encryption", /* 0x8000000 */
654 void obd_connect_seq_flags2str(struct seq_file *m, __u64 flags, __u64 flags2,
661 for (i = 0, mask = 1; i < 64; i++, mask <<= 1) {
663 seq_printf(m, "%s%s",
664 first ? "" : sep, obd_connect_names[i]);
669 if (flags & ~(mask - 1)) {
670 seq_printf(m, "%sunknown_%#llx",
671 first ? "" : sep, flags & ~(mask - 1));
675 if (!(flags & OBD_CONNECT_FLAGS2) || flags2 == 0)
678 for (i = 64, mask = 1; obd_connect_names[i] != NULL; i++, mask <<= 1) {
680 seq_printf(m, "%s%s",
681 first ? "" : sep, obd_connect_names[i]);
686 if (flags2 & ~(mask - 1)) {
687 seq_printf(m, "%sunknown2_%#llx",
688 first ? "" : sep, flags2 & ~(mask - 1));
692 EXPORT_SYMBOL(obd_connect_seq_flags2str);
694 int obd_connect_flags2str(char *page, int count, __u64 flags, __u64 flags2,
700 for (i = 0, mask = 1; i < 64; i++, mask <<= 1) {
702 ret += snprintf(page + ret, count - ret, "%s%s",
703 ret ? sep : "", obd_connect_names[i]);
706 if (flags & ~(mask - 1))
707 ret += snprintf(page + ret, count - ret,
709 ret ? sep : "", flags & ~(mask - 1));
711 if (!(flags & OBD_CONNECT_FLAGS2) || flags2 == 0)
714 for (i = 64, mask = 1; obd_connect_names[i] != NULL; i++, mask <<= 1) {
716 ret += snprintf(page + ret, count - ret, "%s%s",
717 ret ? sep : "", obd_connect_names[i]);
720 if (flags2 & ~(mask - 1))
721 ret += snprintf(page + ret, count - ret,
723 ret ? sep : "", flags2 & ~(mask - 1));
727 EXPORT_SYMBOL(obd_connect_flags2str);
730 obd_connect_data_seqprint(struct seq_file *m, struct obd_connect_data *ocd)
734 LASSERT(ocd != NULL);
735 flags = ocd->ocd_connect_flags;
737 seq_printf(m, " connect_data:\n"
740 ocd->ocd_connect_flags,
742 if (flags & OBD_CONNECT_VERSION)
743 seq_printf(m, " target_version: %u.%u.%u.%u\n",
744 OBD_OCD_VERSION_MAJOR(ocd->ocd_version),
745 OBD_OCD_VERSION_MINOR(ocd->ocd_version),
746 OBD_OCD_VERSION_PATCH(ocd->ocd_version),
747 OBD_OCD_VERSION_FIX(ocd->ocd_version));
748 if (flags & OBD_CONNECT_MDS)
749 seq_printf(m, " mdt_index: %d\n", ocd->ocd_group);
750 if (flags & OBD_CONNECT_GRANT)
751 seq_printf(m, " initial_grant: %d\n", ocd->ocd_grant);
752 if (flags & OBD_CONNECT_INDEX)
753 seq_printf(m, " target_index: %u\n", ocd->ocd_index);
754 if (flags & OBD_CONNECT_BRW_SIZE)
755 seq_printf(m, " max_brw_size: %d\n", ocd->ocd_brw_size);
756 if (flags & OBD_CONNECT_IBITS)
757 seq_printf(m, " ibits_known: %#llx\n",
758 ocd->ocd_ibits_known);
759 if (flags & OBD_CONNECT_GRANT_PARAM)
760 seq_printf(m, " grant_block_size: %d\n"
761 " grant_inode_size: %d\n"
762 " grant_max_extent_size: %d\n"
763 " grant_extent_tax: %d\n",
764 1 << ocd->ocd_grant_blkbits,
765 1 << ocd->ocd_grant_inobits,
766 ocd->ocd_grant_max_blks << ocd->ocd_grant_blkbits,
767 ocd->ocd_grant_tax_kb << 10);
768 if (flags & OBD_CONNECT_TRANSNO)
769 seq_printf(m, " first_transno: %#llx\n",
771 if (flags & OBD_CONNECT_CKSUM)
772 seq_printf(m, " cksum_types: %#x\n",
773 ocd->ocd_cksum_types);
774 if (flags & OBD_CONNECT_MAX_EASIZE)
775 seq_printf(m, " max_easize: %d\n", ocd->ocd_max_easize);
776 if (flags & OBD_CONNECT_MAXBYTES)
777 seq_printf(m, " max_object_bytes: %llu\n",
779 if (flags & OBD_CONNECT_MULTIMODRPCS)
780 seq_printf(m, " max_mod_rpcs: %hu\n",
781 ocd->ocd_maxmodrpcs);
784 static void lprocfs_import_seq_show_locked(struct seq_file *m,
785 struct obd_device *obd,
786 struct obd_import *imp)
788 char nidstr[LNET_NIDSTR_SIZE];
789 struct lprocfs_counter ret;
790 struct lprocfs_counter_header *header;
791 struct obd_import_conn *conn;
792 struct obd_connect_data *ocd;
797 ocd = &imp->imp_connect_data;
799 seq_printf(m, "import:\n"
803 " connect_flags: [ ",
806 ptlrpc_import_state_name(imp->imp_state));
807 obd_connect_seq_flags2str(m, imp->imp_connect_data.ocd_connect_flags,
808 imp->imp_connect_data.ocd_connect_flags2,
810 seq_printf(m, " ]\n");
811 obd_connect_data_seqprint(m, ocd);
812 seq_printf(m, " import_flags: [ ");
813 obd_import_flags2str(imp, m);
817 " failover_nids: [ ");
818 spin_lock(&imp->imp_lock);
820 list_for_each_entry(conn, &imp->imp_conn_list, oic_item) {
821 libcfs_nidstr_r(&conn->oic_conn->c_peer.nid,
822 nidstr, sizeof(nidstr));
823 seq_printf(m, "%s%s", j ? ", " : "", nidstr);
826 if (imp->imp_connection)
827 libcfs_nidstr_r(&imp->imp_connection->c_peer.nid,
828 nidstr, sizeof(nidstr));
830 strncpy(nidstr, "<none>", sizeof(nidstr));
832 " current_connection: %s\n"
833 " connection_attempts: %u\n"
835 " in-progress_invalidations: %u\n"
840 atomic_read(&imp->imp_inval_count),
841 ktime_get_real_seconds() - imp->imp_last_reply_time);
842 spin_unlock(&imp->imp_lock);
844 if (!obd->obd_svc_stats)
847 header = &obd->obd_svc_stats->ls_cnt_header[PTLRPC_REQWAIT_CNTR];
848 lprocfs_stats_collect(obd->obd_svc_stats, PTLRPC_REQWAIT_CNTR, &ret);
849 if (ret.lc_count != 0)
850 ret.lc_sum = div64_s64(ret.lc_sum, ret.lc_count);
853 seq_printf(m, " rpcs:\n"
855 " unregistering: %u\n"
857 " avg_waittime: %llu %s\n",
858 atomic_read(&imp->imp_inflight),
859 atomic_read(&imp->imp_unregistering),
860 atomic_read(&imp->imp_timeouts),
861 ret.lc_sum, header->lc_units);
864 for(j = 0; j < IMP_AT_MAX_PORTALS; j++) {
865 if (imp->imp_at.iat_portal[j] == 0)
867 k = max_t(unsigned int, k,
868 at_get(&imp->imp_at.iat_service_estimate[j]));
870 seq_printf(m, " service_estimates:\n"
871 " services: %u sec\n"
872 " network: %d sec\n",
874 at_get(&imp->imp_at.iat_net_latency));
876 seq_printf(m, " transactions:\n"
877 " last_replay: %llu\n"
878 " peer_committed: %llu\n"
879 " last_checked: %llu\n",
880 imp->imp_last_replay_transno,
881 imp->imp_peer_committed_transno,
882 imp->imp_last_transno_checked);
885 for (rw = 0; rw <= 1; rw++) {
886 lprocfs_stats_collect(obd->obd_svc_stats,
887 PTLRPC_LAST_CNTR + BRW_READ_BYTES + rw,
889 if (ret.lc_sum > 0 && ret.lc_count > 0) {
890 ret.lc_sum = div64_s64(ret.lc_sum, ret.lc_count);
891 seq_printf(m, " %s_data_averages:\n"
892 " bytes_per_rpc: %llu\n",
893 rw ? "write" : "read",
897 j = opcode_offset(OST_READ + rw) + EXTRA_MAX_OPCODES;
898 header = &obd->obd_svc_stats->ls_cnt_header[j];
899 lprocfs_stats_collect(obd->obd_svc_stats, j, &ret);
900 if (ret.lc_sum > 0 && ret.lc_count != 0) {
901 ret.lc_sum = div64_s64(ret.lc_sum, ret.lc_count);
902 seq_printf(m, " %s_per_rpc: %llu\n",
903 header->lc_units, ret.lc_sum);
906 seq_printf(m, " MB_per_sec: %u.%.02u\n",
907 k / j, (100 * k / j) % 100);
912 int lprocfs_import_seq_show(struct seq_file *m, void *data)
914 struct obd_device *obd = (struct obd_device *)data;
915 struct obd_import *imp;
918 LASSERT(obd != NULL);
919 with_imp_locked(obd, imp, rv)
920 lprocfs_import_seq_show_locked(m, obd, imp);
923 EXPORT_SYMBOL(lprocfs_import_seq_show);
925 int lprocfs_state_seq_show(struct seq_file *m, void *data)
927 struct obd_device *obd = (struct obd_device *)data;
928 struct obd_import *imp;
932 LASSERT(obd != NULL);
933 with_imp_locked(obd, imp, rc) {
934 seq_printf(m, "current_state: %s\n",
935 ptlrpc_import_state_name(imp->imp_state));
936 seq_printf(m, "state_history:\n");
937 k = imp->imp_state_hist_idx;
938 for (j = 0; j < IMP_STATE_HIST_LEN; j++) {
939 struct import_state_hist *ish =
940 &imp->imp_state_hist[(k + j) % IMP_STATE_HIST_LEN];
941 if (ish->ish_state == 0)
943 seq_printf(m, " - [ %lld, %s ]\n", (s64)ish->ish_time,
944 ptlrpc_import_state_name(ish->ish_state));
950 EXPORT_SYMBOL(lprocfs_state_seq_show);
952 int lprocfs_at_hist_helper(struct seq_file *m, struct adaptive_timeout *at)
955 for (i = 0; i < AT_BINS; i++)
956 seq_printf(m, "%3u ", at->at_hist[i]);
960 EXPORT_SYMBOL(lprocfs_at_hist_helper);
962 /* See also ptlrpc_lprocfs_timeouts_show_seq */
963 static void lprocfs_timeouts_seq_show_locked(struct seq_file *m,
964 struct obd_device *obd,
965 struct obd_import *imp)
967 timeout_t cur_timeout, worst_timeout;
968 time64_t now, worst_timestamp;
971 LASSERT(obd != NULL);
973 now = ktime_get_real_seconds();
975 /* Some network health info for kicks */
976 seq_printf(m, "%-10s : %lld, %llds ago\n",
977 "last reply", (s64)imp->imp_last_reply_time,
978 (s64)(now - imp->imp_last_reply_time));
980 cur_timeout = at_get(&imp->imp_at.iat_net_latency);
981 worst_timeout = imp->imp_at.iat_net_latency.at_worst_timeout_ever;
982 worst_timestamp = imp->imp_at.iat_net_latency.at_worst_timestamp;
983 seq_printf(m, "%-10s : cur %3u worst %3u (at %lld, %llds ago) ",
984 "network", cur_timeout, worst_timeout, worst_timestamp,
985 now - worst_timestamp);
986 lprocfs_at_hist_helper(m, &imp->imp_at.iat_net_latency);
988 for(i = 0; i < IMP_AT_MAX_PORTALS; i++) {
989 struct adaptive_timeout *service_est;
991 if (imp->imp_at.iat_portal[i] == 0)
994 service_est = &imp->imp_at.iat_service_estimate[i];
995 cur_timeout = at_get(service_est);
996 worst_timeout = service_est->at_worst_timeout_ever;
997 worst_timestamp = service_est->at_worst_timestamp;
998 seq_printf(m, "portal %-2d : cur %3u worst %3u (at %lld, %llds ago) ",
999 imp->imp_at.iat_portal[i], cur_timeout,
1000 worst_timeout, worst_timestamp,
1001 now - worst_timestamp);
1002 lprocfs_at_hist_helper(m, service_est);
1006 int lprocfs_timeouts_seq_show(struct seq_file *m, void *data)
1008 struct obd_device *obd = (struct obd_device *)data;
1009 struct obd_import *imp;
1012 with_imp_locked(obd, imp, rc)
1013 lprocfs_timeouts_seq_show_locked(m, obd, imp);
1016 EXPORT_SYMBOL(lprocfs_timeouts_seq_show);
1018 int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data)
1020 struct obd_device *obd = data;
1023 struct obd_import *imp;
1026 with_imp_locked(obd, imp, rc) {
1027 flags = imp->imp_connect_data.ocd_connect_flags;
1028 flags2 = imp->imp_connect_data.ocd_connect_flags2;
1029 seq_printf(m, "flags=%#llx\n", flags);
1030 seq_printf(m, "flags2=%#llx\n", flags2);
1031 obd_connect_seq_flags2str(m, flags, flags2, "\n");
1032 seq_printf(m, "\n");
1037 EXPORT_SYMBOL(lprocfs_connect_flags_seq_show);
1039 static const struct attribute *obd_def_uuid_attrs[] = {
1040 &lustre_attr_uuid.attr,
1044 static const struct attribute *obd_def_attrs[] = {
1045 &lustre_attr_blocksize.attr,
1046 &lustre_attr_kbytestotal.attr,
1047 &lustre_attr_kbytesfree.attr,
1048 &lustre_attr_kbytesavail.attr,
1049 &lustre_attr_filestotal.attr,
1050 &lustre_attr_filesfree.attr,
1051 &lustre_attr_uuid.attr,
1055 static void obd_sysfs_release(struct kobject *kobj)
1057 struct obd_device *obd = container_of(kobj, struct obd_device,
1060 complete(&obd->obd_kobj_unregister);
1063 int lprocfs_obd_setup(struct obd_device *obd, bool uuid_only)
1065 struct ldebugfs_vars *debugfs_vars = NULL;
1068 if (!obd || obd->obd_magic != OBD_DEVICE_MAGIC)
1071 rc = kobject_set_name(&obd->obd_kset.kobj, "%s", obd->obd_name);
1075 obd->obd_ktype.sysfs_ops = &lustre_sysfs_ops;
1076 obd->obd_ktype.release = obd_sysfs_release;
1078 obd->obd_kset.kobj.parent = &obd->obd_type->typ_kobj;
1079 obd->obd_kset.kobj.ktype = &obd->obd_ktype;
1080 init_completion(&obd->obd_kobj_unregister);
1081 rc = kset_register(&obd->obd_kset);
1086 obd->obd_attrs = obd_def_uuid_attrs;
1088 obd->obd_attrs = obd_def_attrs;
1090 rc = sysfs_create_files(&obd->obd_kset.kobj, obd->obd_attrs);
1092 kset_unregister(&obd->obd_kset);
1096 if (!obd->obd_type->typ_procroot)
1097 debugfs_vars = obd->obd_debugfs_vars;
1098 obd->obd_debugfs_entry = debugfs_create_dir(
1099 obd->obd_name, obd->obd_type->typ_debugfs_entry);
1100 ldebugfs_add_vars(obd->obd_debugfs_entry, debugfs_vars, obd);
1102 if (obd->obd_proc_entry || !obd->obd_type->typ_procroot)
1103 GOTO(already_registered, rc);
1105 obd->obd_proc_entry = lprocfs_register(obd->obd_name,
1106 obd->obd_type->typ_procroot,
1107 obd->obd_vars, obd);
1108 if (IS_ERR(obd->obd_proc_entry)) {
1109 rc = PTR_ERR(obd->obd_proc_entry);
1110 CERROR("error %d setting up lprocfs for %s\n",rc,obd->obd_name);
1111 obd->obd_proc_entry = NULL;
1113 debugfs_remove_recursive(obd->obd_debugfs_entry);
1114 obd->obd_debugfs_entry = NULL;
1116 sysfs_remove_files(&obd->obd_kset.kobj, obd->obd_attrs);
1117 obd->obd_attrs = NULL;
1118 kset_unregister(&obd->obd_kset);
1124 EXPORT_SYMBOL(lprocfs_obd_setup);
1126 int lprocfs_obd_cleanup(struct obd_device *obd)
1131 if (obd->obd_proc_exports_entry) {
1132 /* Should be no exports left */
1133 lprocfs_remove(&obd->obd_proc_exports_entry);
1134 obd->obd_proc_exports_entry = NULL;
1137 if (obd->obd_proc_entry) {
1138 lprocfs_remove(&obd->obd_proc_entry);
1139 obd->obd_proc_entry = NULL;
1142 debugfs_remove_recursive(obd->obd_debugfs_entry);
1143 obd->obd_debugfs_entry = NULL;
1145 /* obd device never allocated a kset */
1146 if (!obd->obd_kset.kobj.state_initialized)
1149 if (obd->obd_attrs) {
1150 sysfs_remove_files(&obd->obd_kset.kobj, obd->obd_attrs);
1151 obd->obd_attrs = NULL;
1154 kset_unregister(&obd->obd_kset);
1155 wait_for_completion(&obd->obd_kobj_unregister);
1158 EXPORT_SYMBOL(lprocfs_obd_cleanup);
1160 int lprocfs_stats_alloc_one(struct lprocfs_stats *stats, unsigned int cpuid)
1162 struct lprocfs_counter *cntr;
1163 unsigned int percpusize;
1165 unsigned long flags = 0;
1168 LASSERT(stats->ls_percpu[cpuid] == NULL);
1169 LASSERT((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0);
1171 percpusize = lprocfs_stats_counter_size(stats);
1172 LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[cpuid], percpusize);
1173 if (stats->ls_percpu[cpuid]) {
1175 if (unlikely(stats->ls_biggest_alloc_num <= cpuid)) {
1176 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
1177 spin_lock_irqsave(&stats->ls_lock, flags);
1179 spin_lock(&stats->ls_lock);
1180 if (stats->ls_biggest_alloc_num <= cpuid)
1181 stats->ls_biggest_alloc_num = cpuid + 1;
1182 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) {
1183 spin_unlock_irqrestore(&stats->ls_lock, flags);
1185 spin_unlock(&stats->ls_lock);
1188 /* initialize the ls_percpu[cpuid] non-zero counter */
1189 for (i = 0; i < stats->ls_num; ++i) {
1190 cntr = lprocfs_stats_counter_get(stats, cpuid, i);
1191 cntr->lc_min = LC_MIN_INIT;
1197 struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num,
1198 enum lprocfs_stats_flags flags)
1200 struct lprocfs_stats *stats;
1201 unsigned int num_entry;
1202 unsigned int percpusize = 0;
1208 if (lprocfs_no_percpu_stats != 0)
1209 flags |= LPROCFS_STATS_FLAG_NOPERCPU;
1211 if (flags & LPROCFS_STATS_FLAG_NOPERCPU)
1214 num_entry = num_possible_cpus();
1216 /* alloc percpu pointers for all possible cpu slots */
1217 LIBCFS_ALLOC(stats, offsetof(typeof(*stats), ls_percpu[num_entry]));
1221 stats->ls_num = num;
1222 stats->ls_flags = flags;
1223 spin_lock_init(&stats->ls_lock);
1225 /* alloc num of counter headers */
1226 CFS_ALLOC_PTR_ARRAY(stats->ls_cnt_header, stats->ls_num);
1227 if (!stats->ls_cnt_header)
1230 if ((flags & LPROCFS_STATS_FLAG_NOPERCPU) != 0) {
1231 /* contains only one set counters */
1232 percpusize = lprocfs_stats_counter_size(stats);
1233 LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[0], percpusize);
1234 if (!stats->ls_percpu[0])
1236 stats->ls_biggest_alloc_num = 1;
1237 } else if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0) {
1238 /* alloc all percpu data, currently only obd_memory use this */
1239 for (i = 0; i < num_entry; ++i)
1240 if (lprocfs_stats_alloc_one(stats, i) < 0)
1247 lprocfs_free_stats(&stats);
1250 EXPORT_SYMBOL(lprocfs_alloc_stats);
1252 void lprocfs_free_stats(struct lprocfs_stats **statsh)
1254 struct lprocfs_stats *stats = *statsh;
1255 unsigned int num_entry;
1256 unsigned int percpusize;
1259 if (!stats || stats->ls_num == 0)
1263 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU)
1266 num_entry = num_possible_cpus();
1268 percpusize = lprocfs_stats_counter_size(stats);
1269 for (i = 0; i < num_entry; i++)
1270 if (stats->ls_percpu[i])
1271 LIBCFS_FREE(stats->ls_percpu[i], percpusize);
1272 if (stats->ls_cnt_header)
1273 CFS_FREE_PTR_ARRAY(stats->ls_cnt_header, stats->ls_num);
1274 LIBCFS_FREE(stats, offsetof(typeof(*stats), ls_percpu[num_entry]));
1276 EXPORT_SYMBOL(lprocfs_free_stats);
1278 u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
1279 enum lprocfs_fields_flags field)
1281 unsigned long flags = 0;
1282 unsigned int num_cpu;
1288 num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1289 for (i = 0; i < num_cpu; i++) {
1290 struct lprocfs_counter *cntr;
1292 if (!stats->ls_percpu[i])
1295 cntr = lprocfs_stats_counter_get(stats, i, idx);
1296 ret += lprocfs_read_helper(cntr, &stats->ls_cnt_header[idx],
1297 stats->ls_flags, field);
1299 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1302 EXPORT_SYMBOL(lprocfs_stats_collector);
1304 void lprocfs_clear_stats(struct lprocfs_stats *stats)
1306 struct lprocfs_counter *percpu_cntr;
1309 unsigned int num_entry;
1310 unsigned long flags = 0;
1312 num_entry = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1314 for (i = 0; i < num_entry; i++) {
1315 if (!stats->ls_percpu[i])
1317 for (j = 0; j < stats->ls_num; j++) {
1318 percpu_cntr = lprocfs_stats_counter_get(stats, i, j);
1319 percpu_cntr->lc_count = 0;
1320 percpu_cntr->lc_min = LC_MIN_INIT;
1321 percpu_cntr->lc_max = 0;
1322 percpu_cntr->lc_sumsquare = 0;
1323 percpu_cntr->lc_sum = 0;
1324 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
1325 percpu_cntr->lc_sum_irq = 0;
1329 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1331 EXPORT_SYMBOL(lprocfs_clear_stats);
1333 static ssize_t lprocfs_stats_seq_write(struct file *file,
1334 const char __user *buf,
1335 size_t len, loff_t *off)
1337 struct seq_file *seq = file->private_data;
1338 struct lprocfs_stats *stats = seq->private;
1340 lprocfs_clear_stats(stats);
1345 static void *lprocfs_stats_seq_start(struct seq_file *p, loff_t *pos)
1347 struct lprocfs_stats *stats = p->private;
1349 return (*pos < stats->ls_num) ? pos : NULL;
1352 static void lprocfs_stats_seq_stop(struct seq_file *p, void *v)
1356 static void *lprocfs_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
1360 return lprocfs_stats_seq_start(p, pos);
1363 void lprocfs_stats_header(struct seq_file *seq, ktime_t now, ktime_t ts_init,
1364 int width, const char *colon, bool show_units)
1366 const char *units = show_units ? " secs.nsecs" : "";
1367 struct timespec64 ts;
1369 ts = ktime_to_timespec64(now);
1370 seq_printf(seq, "%-*s%s %llu.%09lu%s\n", width,
1371 "snapshot_time", colon, (s64)ts.tv_sec, ts.tv_nsec, units);
1372 ts = ktime_to_timespec64(ts_init);
1373 seq_printf(seq, "%-*s%s %llu.%09lu%s\n", width,
1374 "start_time", colon, (s64)ts.tv_sec, ts.tv_nsec, units);
1375 ts = ktime_to_timespec64(ktime_sub(now, ts_init));
1376 seq_printf(seq, "%-*s%s %llu.%09lu%s\n", width,
1377 "elapsed_time", colon, (s64)ts.tv_sec, ts.tv_nsec, units);
1379 EXPORT_SYMBOL(lprocfs_stats_header);
1381 /* seq file export of one lprocfs counter */
1382 static int lprocfs_stats_seq_show(struct seq_file *p, void *v)
1384 struct lprocfs_stats *stats = p->private;
1385 struct lprocfs_counter_header *hdr;
1386 struct lprocfs_counter ctr;
1387 int idx = *(loff_t *)v;
1390 lprocfs_stats_header(p, ktime_get(), stats->ls_init, 25, "", 1);
1392 hdr = &stats->ls_cnt_header[idx];
1393 lprocfs_stats_collect(stats, idx, &ctr);
1395 if (ctr.lc_count == 0)
1398 seq_printf(p, "%-25s %lld samples [%s]", hdr->lc_name,
1399 ctr.lc_count, hdr->lc_units);
1401 if ((hdr->lc_config & LPROCFS_CNTR_AVGMINMAX) && ctr.lc_count > 0) {
1402 seq_printf(p, " %lld %lld %lld",
1403 ctr.lc_min, ctr.lc_max, ctr.lc_sum);
1404 if (hdr->lc_config & LPROCFS_CNTR_STDDEV)
1405 seq_printf(p, " %llu", ctr.lc_sumsquare);
1411 static const struct seq_operations lprocfs_stats_seq_sops = {
1412 .start = lprocfs_stats_seq_start,
1413 .stop = lprocfs_stats_seq_stop,
1414 .next = lprocfs_stats_seq_next,
1415 .show = lprocfs_stats_seq_show,
1418 static int lprocfs_stats_seq_open(struct inode *inode, struct file *file)
1420 struct seq_file *seq;
1423 rc = seq_open(file, &lprocfs_stats_seq_sops);
1426 seq = file->private_data;
1427 seq->private = inode->i_private ? inode->i_private : PDE_DATA(inode);
1431 const struct file_operations ldebugfs_stats_seq_fops = {
1432 .owner = THIS_MODULE,
1433 .open = lprocfs_stats_seq_open,
1435 .write = lprocfs_stats_seq_write,
1436 .llseek = seq_lseek,
1437 .release = lprocfs_seq_release,
1439 EXPORT_SYMBOL(ldebugfs_stats_seq_fops);
1441 static const struct proc_ops lprocfs_stats_seq_fops = {
1442 PROC_OWNER(THIS_MODULE)
1443 .proc_open = lprocfs_stats_seq_open,
1444 .proc_read = seq_read,
1445 .proc_write = lprocfs_stats_seq_write,
1446 .proc_lseek = seq_lseek,
1447 .proc_release = lprocfs_seq_release,
1450 int lprocfs_register_stats(struct proc_dir_entry *root, const char *name,
1451 struct lprocfs_stats *stats)
1453 struct proc_dir_entry *entry;
1454 LASSERT(root != NULL);
1456 entry = proc_create_data(name, 0644, root,
1457 &lprocfs_stats_seq_fops, stats);
1462 EXPORT_SYMBOL(lprocfs_register_stats);
1464 static const char *lprocfs_counter_config_units(const char *name,
1465 enum lprocfs_counter_config config)
1469 switch (config & LPROCFS_TYPE_MASK) {
1471 units = "reqs"; break;
1472 case LPROCFS_TYPE_BYTES:
1473 units = "bytes"; break;
1474 case LPROCFS_TYPE_PAGES:
1475 units = "pages"; break;
1476 case LPROCFS_TYPE_LOCKS:
1477 units = "locks"; break;
1478 case LPROCFS_TYPE_LOCKSPS:
1479 units = "locks/s"; break;
1480 case LPROCFS_TYPE_SECS:
1481 units = "secs"; break;
1482 case LPROCFS_TYPE_USECS:
1483 units = "usecs"; break;
1489 void lprocfs_counter_init_units(struct lprocfs_stats *stats, int index,
1490 enum lprocfs_counter_config config,
1491 const char *name, const char *units)
1493 struct lprocfs_counter_header *header;
1494 struct lprocfs_counter *percpu_cntr;
1495 unsigned long flags = 0;
1497 unsigned int num_cpu;
1499 LASSERT(stats != NULL);
1501 header = &stats->ls_cnt_header[index];
1502 LASSERTF(header != NULL, "Failed to allocate stats header:[%d]%s/%s\n",
1503 index, name, units);
1505 header->lc_config = config;
1506 header->lc_name = name;
1507 header->lc_units = units;
1509 num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1510 for (i = 0; i < num_cpu; ++i) {
1511 if (!stats->ls_percpu[i])
1513 percpu_cntr = lprocfs_stats_counter_get(stats, i, index);
1514 percpu_cntr->lc_count = 0;
1515 percpu_cntr->lc_min = LC_MIN_INIT;
1516 percpu_cntr->lc_max = 0;
1517 percpu_cntr->lc_sumsquare = 0;
1518 percpu_cntr->lc_sum = 0;
1519 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
1520 percpu_cntr->lc_sum_irq = 0;
1522 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1524 EXPORT_SYMBOL(lprocfs_counter_init_units);
1526 void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
1527 enum lprocfs_counter_config config,
1530 lprocfs_counter_init_units(stats, index, config, name,
1531 lprocfs_counter_config_units(name, config));
1533 EXPORT_SYMBOL(lprocfs_counter_init);
1535 static const char * const mps_stats[] = {
1536 [LPROC_MD_CLOSE] = "close",
1537 [LPROC_MD_CREATE] = "create",
1538 [LPROC_MD_ENQUEUE] = "enqueue",
1539 [LPROC_MD_GETATTR] = "getattr",
1540 [LPROC_MD_INTENT_LOCK] = "intent_lock",
1541 [LPROC_MD_LINK] = "link",
1542 [LPROC_MD_RENAME] = "rename",
1543 [LPROC_MD_SETATTR] = "setattr",
1544 [LPROC_MD_FSYNC] = "fsync",
1545 [LPROC_MD_READ_PAGE] = "read_page",
1546 [LPROC_MD_UNLINK] = "unlink",
1547 [LPROC_MD_SETXATTR] = "setxattr",
1548 [LPROC_MD_GETXATTR] = "getxattr",
1549 [LPROC_MD_INTENT_GETATTR_ASYNC] = "intent_getattr_async",
1550 [LPROC_MD_REVALIDATE_LOCK] = "revalidate_lock",
1553 int lprocfs_alloc_md_stats(struct obd_device *obd,
1554 unsigned int num_private_stats)
1556 struct lprocfs_stats *stats;
1557 unsigned int num_stats;
1561 * TODO Ensure that this function is only used where
1562 * appropriate by adding an assertion to the effect that
1563 * obd->obd_type->typ_md_ops is not NULL. We can't do this now
1564 * because mdt_procfs_init() uses this function to allocate
1565 * the stats backing /proc/fs/lustre/mdt/.../md_stats but the
1566 * mdt layer does not use the md_ops interface. This is
1567 * confusing and a waste of memory. See LU-2484.
1569 LASSERT(obd->obd_proc_entry != NULL);
1570 LASSERT(obd->obd_md_stats == NULL);
1572 num_stats = ARRAY_SIZE(mps_stats) + num_private_stats;
1573 stats = lprocfs_alloc_stats(num_stats, 0);
1577 for (i = 0; i < ARRAY_SIZE(mps_stats); i++) {
1578 lprocfs_counter_init(stats, i, LPROCFS_TYPE_REQS,
1580 if (!stats->ls_cnt_header[i].lc_name) {
1581 CERROR("Missing md_stat initializer md_op operation at offset %d. Aborting.\n",
1587 rc = lprocfs_register_stats(obd->obd_proc_entry, "md_stats", stats);
1589 lprocfs_free_stats(&stats);
1591 obd->obd_md_stats = stats;
1596 EXPORT_SYMBOL(lprocfs_alloc_md_stats);
1598 void lprocfs_free_md_stats(struct obd_device *obd)
1600 struct lprocfs_stats *stats = obd->obd_md_stats;
1603 obd->obd_md_stats = NULL;
1604 lprocfs_free_stats(&stats);
1607 EXPORT_SYMBOL(lprocfs_free_md_stats);
1609 void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
1611 lprocfs_counter_init(ldlm_stats, LDLM_ENQUEUE - LDLM_FIRST_OPC,
1612 LPROCFS_TYPE_REQS, "ldlm_enqueue");
1613 lprocfs_counter_init(ldlm_stats, LDLM_CONVERT - LDLM_FIRST_OPC,
1614 LPROCFS_TYPE_REQS, "ldlm_convert");
1615 lprocfs_counter_init(ldlm_stats, LDLM_CANCEL - LDLM_FIRST_OPC,
1616 LPROCFS_TYPE_REQS, "ldlm_cancel");
1617 lprocfs_counter_init(ldlm_stats, LDLM_BL_CALLBACK - LDLM_FIRST_OPC,
1618 LPROCFS_TYPE_REQS, "ldlm_bl_callback");
1619 lprocfs_counter_init(ldlm_stats, LDLM_CP_CALLBACK - LDLM_FIRST_OPC,
1620 LPROCFS_TYPE_REQS, "ldlm_cp_callback");
1621 lprocfs_counter_init(ldlm_stats, LDLM_GL_CALLBACK - LDLM_FIRST_OPC,
1622 LPROCFS_TYPE_REQS, "ldlm_gl_callback");
1624 EXPORT_SYMBOL(lprocfs_init_ldlm_stats);
1626 __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
1627 struct lprocfs_counter_header *header,
1628 enum lprocfs_stats_flags flags,
1629 enum lprocfs_fields_flags field)
1637 case LPROCFS_FIELDS_FLAGS_CONFIG:
1638 ret = header->lc_config;
1640 case LPROCFS_FIELDS_FLAGS_SUM:
1642 if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
1643 ret += lc->lc_sum_irq;
1645 case LPROCFS_FIELDS_FLAGS_MIN:
1648 case LPROCFS_FIELDS_FLAGS_MAX:
1651 case LPROCFS_FIELDS_FLAGS_AVG:
1652 ret = div64_u64((flags & LPROCFS_STATS_FLAG_IRQ_SAFE ?
1653 lc->lc_sum_irq : 0) + lc->lc_sum,
1656 case LPROCFS_FIELDS_FLAGS_SUMSQUARE:
1657 ret = lc->lc_sumsquare;
1659 case LPROCFS_FIELDS_FLAGS_COUNT:
1667 EXPORT_SYMBOL(lprocfs_read_helper);
1670 * string_to_size - convert ASCII string representing a numerical
1671 * value with optional units to 64-bit binary value
1673 * @size: The numerical value extract out of @buffer
1674 * @buffer: passed in string to parse
1675 * @count: length of the @buffer
1677 * This function returns a 64-bit binary value if @buffer contains a valid
1678 * numerical string. The string is parsed to 3 significant figures after
1679 * the decimal point. Support the string containing an optional units at
1680 * the end which can be base 2 or base 10 in value. If no units are given
1681 * the string is assumed to just a numerical value.
1683 * Returns: @count if the string is successfully parsed,
1684 * -errno on invalid input strings. Error values:
1686 * - ``-EINVAL``: @buffer is not a proper numerical string
1687 * - ``-EOVERFLOW``: results does not fit into 64 bits.
1688 * - ``-E2BIG ``: @buffer is too large (not a valid number)
1690 int string_to_size(u64 *size, const char *buffer, size_t count)
1692 /* For string_get_size() it can support values above exabytes,
1693 * (ZiB, YiB) due to breaking the return value into a size and
1694 * bulk size to avoid 64 bit overflow. We don't break the size
1695 * up into block size units so we don't support ZiB or YiB.
1697 static const char *const units_10[] = {
1698 "kB", "MB", "GB", "TB", "PB", "EB",
1700 static const char *const units_2[] = {
1701 "K", "M", "G", "T", "P", "E",
1703 static const char *const *const units_str[] = {
1704 [STRING_UNITS_2] = units_2,
1705 [STRING_UNITS_10] = units_10,
1707 static const unsigned int coeff[] = {
1708 [STRING_UNITS_10] = 1000,
1709 [STRING_UNITS_2] = 1024,
1711 enum string_size_units unit = STRING_UNITS_2;
1712 u64 whole, blk_size = 1;
1713 char kernbuf[22], *end;
1718 if (count >= sizeof(kernbuf)) {
1719 CERROR("count %zd > buffer %zd\n", count, sizeof(kernbuf));
1724 /* The "iB" suffix is optionally allowed for indicating base-2 numbers.
1725 * If suffix is only "B" and not "iB" then we treat it as base-10.
1727 end = strstr(buffer, "B");
1728 if (end && *(end - 1) != 'i')
1729 unit = STRING_UNITS_10;
1731 i = unit == STRING_UNITS_2 ? ARRAY_SIZE(units_2) - 1 :
1732 ARRAY_SIZE(units_10) - 1;
1734 end = strnstr(buffer, units_str[unit][i], count);
1737 blk_size *= coeff[unit];
1743 /* as 'B' is a substring of all units, we need to handle it
1747 /* 'B' is only acceptable letter at this point */
1748 end = strnchr(buffer, count, 'B');
1752 if (count - len > 2 ||
1753 (count - len == 2 && strcmp(end, "B\n") != 0)) {
1754 CDEBUG(D_INFO, "unknown suffix '%s'\n", buffer);
1758 /* kstrtoull will error out if it has non digits */
1762 end = strnchr(buffer, count, '.');
1764 /* need to limit 3 decimal places */
1765 char rem[4] = "000";
1772 /* limit to 3 decimal points */
1773 off = min_t(size_t, 3, strspn(end, "0123456789"));
1774 /* need to limit frac_d to a u32 */
1775 memcpy(rem, end, off);
1776 rc = kstrtoull(rem, 10, &frac);
1780 if (fls64(frac) + fls64(blk_size) - 1 > 64)
1788 snprintf(kernbuf, sizeof(kernbuf), "%.*s", (int)len, buffer);
1789 rc = kstrtoull(kernbuf, 10, &whole);
1793 if (whole != 0 && fls64(whole) + fls64(blk_size) - 1 > 64)
1796 *size += whole * blk_size;
1800 EXPORT_SYMBOL(string_to_size);
1803 * sysfs_memparse - parse a ASCII string to 64-bit binary value,
1804 * with optional units
1806 * @buffer: kernel pointer to input string
1807 * @count: number of bytes in the input @buffer
1808 * @val: (output) binary value returned to caller
1809 * @defunit: default unit suffix to use if none is provided
1811 * Parses a string into a number. The number stored at @buffer is
1812 * potentially suffixed with K, M, G, T, P, E. Besides these other
1813 * valid suffix units are shown in the string_to_size() function.
1814 * If the string lacks a suffix then the defunit is used. The defunit
1815 * should be given as a binary unit (e.g. MiB) as that is the standard
1816 * for tunables in Lustre. If no unit suffix is given (e.g. 'G'), then
1817 * it is assumed to be in binary units.
1819 * Returns: 0 on success or -errno on failure.
1821 int sysfs_memparse(const char *buffer, size_t count, u64 *val,
1822 const char *defunit)
1824 const char *param = buffer;
1828 count = strlen(buffer);
1829 while (count > 0 && isspace(buffer[count - 1]))
1835 /* If there isn't already a unit on this value, append @defunit.
1836 * Units of 'B' don't affect the value, so don't bother adding.
1838 if (!isalpha(buffer[count - 1]) && defunit[0] != 'B') {
1839 if (count + 3 >= sizeof(tmp_buf)) {
1840 CERROR("count %zd > size %zd\n", count, sizeof(param));
1844 scnprintf(tmp_buf, sizeof(tmp_buf), "%.*s%s", (int)count,
1847 count = strlen(param);
1850 rc = string_to_size(val, param, count);
1852 return rc < 0 ? rc : 0;
1854 EXPORT_SYMBOL(sysfs_memparse);
1856 char *lprocfs_strnstr(const char *s1, const char *s2, size_t len)
1865 if (!memcmp(s1, s2, l2))
1871 EXPORT_SYMBOL(lprocfs_strnstr);
1874 * Find the string \a name in the input \a buffer, and return a pointer to the
1875 * value immediately following \a name, reducing \a count appropriately.
1876 * If \a name is not found the original \a buffer is returned.
1878 char *lprocfs_find_named_value(const char *buffer, const char *name,
1882 size_t buflen = *count;
1884 /* there is no strnstr() in rhel5 and ubuntu kernels */
1885 val = lprocfs_strnstr(buffer, name, buflen);
1887 return (char *)buffer;
1889 val += strlen(name); /* skip prefix */
1890 while (val < buffer + buflen && isspace(*val)) /* skip separator */
1894 while (val < buffer + buflen && isalnum(*val)) {
1899 return val - *count;
1901 EXPORT_SYMBOL(lprocfs_find_named_value);
1903 int lprocfs_seq_create(struct proc_dir_entry *parent,
1906 const struct proc_ops *seq_fops,
1909 struct proc_dir_entry *entry;
1912 /* Disallow secretly (un)writable entries. */
1913 LASSERT(!seq_fops->proc_write == !(mode & 0222));
1915 entry = proc_create_data(name, mode, parent, seq_fops, data);
1922 EXPORT_SYMBOL(lprocfs_seq_create);
1924 int lprocfs_obd_seq_create(struct obd_device *obd,
1927 const struct proc_ops *seq_fops,
1930 return lprocfs_seq_create(obd->obd_proc_entry, name,
1931 mode, seq_fops, data);
1933 EXPORT_SYMBOL(lprocfs_obd_seq_create);
1935 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
1937 if (value >= OBD_HIST_MAX)
1938 value = OBD_HIST_MAX - 1;
1940 spin_lock(&oh->oh_lock);
1941 oh->oh_buckets[value]++;
1942 spin_unlock(&oh->oh_lock);
1944 EXPORT_SYMBOL(lprocfs_oh_tally);
1946 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
1948 unsigned int val = 0;
1950 if (likely(value != 0))
1951 val = min(fls(value - 1), OBD_HIST_MAX);
1953 lprocfs_oh_tally(oh, val);
1955 EXPORT_SYMBOL(lprocfs_oh_tally_log2);
1957 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
1959 unsigned long ret = 0;
1962 for (i = 0; i < OBD_HIST_MAX; i++)
1963 ret += oh->oh_buckets[i];
1966 EXPORT_SYMBOL(lprocfs_oh_sum);
1968 void lprocfs_oh_clear(struct obd_histogram *oh)
1970 spin_lock(&oh->oh_lock);
1971 memset(oh->oh_buckets, 0, sizeof(oh->oh_buckets));
1972 spin_unlock(&oh->oh_lock);
1974 EXPORT_SYMBOL(lprocfs_oh_clear);
1976 void lprocfs_oh_tally_pcpu(struct obd_hist_pcpu *oh,
1979 if (value >= OBD_HIST_MAX)
1980 value = OBD_HIST_MAX - 1;
1982 percpu_counter_inc(&oh->oh_pc_buckets[value]);
1984 EXPORT_SYMBOL(lprocfs_oh_tally_pcpu);
1986 void lprocfs_oh_tally_log2_pcpu(struct obd_hist_pcpu *oh,
1989 unsigned int val = 0;
1991 if (likely(value != 0))
1992 val = min(fls(value - 1), OBD_HIST_MAX);
1994 lprocfs_oh_tally_pcpu(oh, val);
1996 EXPORT_SYMBOL(lprocfs_oh_tally_log2_pcpu);
1998 unsigned long lprocfs_oh_counter_pcpu(struct obd_hist_pcpu *oh,
2001 return percpu_counter_sum(&oh->oh_pc_buckets[value]);
2003 EXPORT_SYMBOL(lprocfs_oh_counter_pcpu);
2005 unsigned long lprocfs_oh_sum_pcpu(struct obd_hist_pcpu *oh)
2007 unsigned long ret = 0;
2010 for (i = 0; i < OBD_HIST_MAX; i++)
2011 ret += percpu_counter_sum(&oh->oh_pc_buckets[i]);
2015 EXPORT_SYMBOL(lprocfs_oh_sum_pcpu);
2017 int lprocfs_oh_alloc_pcpu(struct obd_hist_pcpu *oh)
2021 if (oh->oh_initialized)
2024 for (i = 0; i < OBD_HIST_MAX; i++) {
2025 rc = percpu_counter_init(&oh->oh_pc_buckets[i], 0, GFP_KERNEL);
2030 oh->oh_initialized = true;
2035 for (i--; i >= 0; i--)
2036 percpu_counter_destroy(&oh->oh_pc_buckets[i]);
2040 EXPORT_SYMBOL(lprocfs_oh_alloc_pcpu);
2042 void lprocfs_oh_clear_pcpu(struct obd_hist_pcpu *oh)
2046 for (i = 0; i < OBD_HIST_MAX; i++)
2047 percpu_counter_set(&oh->oh_pc_buckets[i], 0);
2049 EXPORT_SYMBOL(lprocfs_oh_clear_pcpu);
2051 void lprocfs_oh_release_pcpu(struct obd_hist_pcpu *oh)
2055 if (!oh->oh_initialized)
2058 for (i = 0; i < OBD_HIST_MAX; i++)
2059 percpu_counter_destroy(&oh->oh_pc_buckets[i]);
2061 oh->oh_initialized = false;
2063 EXPORT_SYMBOL(lprocfs_oh_release_pcpu);
2065 ssize_t lustre_attr_show(struct kobject *kobj,
2066 struct attribute *attr, char *buf)
2068 struct lustre_attr *a = container_of(attr, struct lustre_attr, attr);
2070 return a->show ? a->show(kobj, attr, buf) : 0;
2072 EXPORT_SYMBOL_GPL(lustre_attr_show);
2074 ssize_t lustre_attr_store(struct kobject *kobj, struct attribute *attr,
2075 const char *buf, size_t len)
2077 struct lustre_attr *a = container_of(attr, struct lustre_attr, attr);
2079 return a->store ? a->store(kobj, attr, buf, len) : len;
2081 EXPORT_SYMBOL_GPL(lustre_attr_store);
2083 const struct sysfs_ops lustre_sysfs_ops = {
2084 .show = lustre_attr_show,
2085 .store = lustre_attr_store,
2087 EXPORT_SYMBOL_GPL(lustre_sysfs_ops);
2089 int lprocfs_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *data)
2091 struct obd_device *obd = data;
2092 struct client_obd *cli = &obd->u.cli;
2094 spin_lock(&cli->cl_loi_list_lock);
2095 seq_printf(m, "%d\n", cli->cl_max_pages_per_rpc);
2096 spin_unlock(&cli->cl_loi_list_lock);
2099 EXPORT_SYMBOL(lprocfs_obd_max_pages_per_rpc_seq_show);
2101 ssize_t lprocfs_obd_max_pages_per_rpc_seq_write(struct file *file,
2102 const char __user *buffer,
2103 size_t count, loff_t *off)
2105 struct seq_file *m = file->private_data;
2106 struct obd_device *obd = m->private;
2107 struct client_obd *cli = &obd->u.cli;
2108 struct obd_import *imp;
2109 struct obd_connect_data *ocd;
2114 if (count > sizeof(kernbuf) - 1)
2117 if (copy_from_user(kernbuf, buffer, count))
2120 kernbuf[count] = '\0';
2122 rc = sysfs_memparse(kernbuf, count, &val, "B");
2126 /* if the max_pages is specified in bytes, convert to pages */
2127 if (val >= ONE_MB_BRW_SIZE)
2130 with_imp_locked(obd, imp, rc) {
2131 ocd = &imp->imp_connect_data;
2132 chunk_mask = ~((1 << (cli->cl_chunkbits - PAGE_SHIFT)) - 1);
2133 /* max_pages_per_rpc must be chunk aligned */
2134 val = (val + ~chunk_mask) & chunk_mask;
2135 if (val == 0 || (ocd->ocd_brw_size != 0 &&
2136 val > ocd->ocd_brw_size >> PAGE_SHIFT)) {
2139 spin_lock(&cli->cl_loi_list_lock);
2140 cli->cl_max_pages_per_rpc = val;
2141 client_adjust_max_dirty(cli);
2142 spin_unlock(&cli->cl_loi_list_lock);
2148 EXPORT_SYMBOL(lprocfs_obd_max_pages_per_rpc_seq_write);
2150 ssize_t short_io_bytes_show(struct kobject *kobj, struct attribute *attr,
2153 struct obd_device *obd = container_of(kobj, struct obd_device,
2155 struct client_obd *cli = &obd->u.cli;
2158 spin_lock(&cli->cl_loi_list_lock);
2159 rc = sprintf(buf, "%d\n", cli->cl_max_short_io_bytes);
2160 spin_unlock(&cli->cl_loi_list_lock);
2163 EXPORT_SYMBOL(short_io_bytes_show);
2165 /* Used to catch people who think they're specifying pages. */
2166 #define MIN_SHORT_IO_BYTES 64U
2168 ssize_t short_io_bytes_store(struct kobject *kobj, struct attribute *attr,
2169 const char *buffer, size_t count)
2171 struct obd_device *obd = container_of(kobj, struct obd_device,
2173 struct client_obd *cli = &obd->u.cli;
2177 if (strcmp(buffer, "-1") == 0) {
2178 val = OBD_DEF_SHORT_IO_BYTES;
2180 rc = sysfs_memparse(buffer, count, &val, "B");
2185 if (val && (val < MIN_SHORT_IO_BYTES || val > LNET_MTU))
2186 GOTO(out, rc = -ERANGE);
2190 spin_lock(&cli->cl_loi_list_lock);
2191 cli->cl_max_short_io_bytes = min_t(u64, val, OST_MAX_SHORT_IO_BYTES);
2192 spin_unlock(&cli->cl_loi_list_lock);
2197 EXPORT_SYMBOL(short_io_bytes_store);
2199 int lprocfs_wr_root_squash(const char __user *buffer, unsigned long count,
2200 struct root_squash_info *squash, char *name)
2203 char kernbuf[64], *tmp, *errmsg;
2204 unsigned long uid, gid;
2207 if (count >= sizeof(kernbuf)) {
2208 errmsg = "string too long";
2209 GOTO(failed_noprint, rc = -EINVAL);
2211 if (copy_from_user(kernbuf, buffer, count)) {
2212 errmsg = "bad address";
2213 GOTO(failed_noprint, rc = -EFAULT);
2215 kernbuf[count] = '\0';
2217 /* look for uid gid separator */
2218 tmp = strchr(kernbuf, ':');
2220 errmsg = "needs uid:gid format";
2221 GOTO(failed, rc = -EINVAL);
2227 if (kstrtoul(kernbuf, 0, &uid) != 0) {
2229 GOTO(failed, rc = -EINVAL);
2233 if (kstrtoul(tmp, 0, &gid) != 0) {
2235 GOTO(failed, rc = -EINVAL);
2238 squash->rsi_uid = uid;
2239 squash->rsi_gid = gid;
2241 LCONSOLE_INFO("%s: root_squash is set to %u:%u\n",
2242 name, squash->rsi_uid, squash->rsi_gid);
2250 CWARN("%s: failed to set root_squash to \"%s\", %s, rc = %d\n",
2251 name, kernbuf, errmsg, rc);
2254 CWARN("%s: failed to set root_squash due to %s, rc = %d\n",
2258 EXPORT_SYMBOL(lprocfs_wr_root_squash);
2261 int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count,
2262 struct root_squash_info *squash, char *name)
2265 char *kernbuf = NULL;
2272 errmsg = "string too long";
2273 GOTO(failed, rc = -EINVAL);
2276 OBD_ALLOC(kernbuf, count + 1);
2278 errmsg = "no memory";
2279 GOTO(failed, rc = -ENOMEM);
2281 if (copy_from_user(kernbuf, buffer, count)) {
2282 errmsg = "bad address";
2283 GOTO(failed, rc = -EFAULT);
2285 kernbuf[count] = '\0';
2287 if (count > 0 && kernbuf[count - 1] == '\n')
2290 if ((len == 4 && strncmp(kernbuf, "NONE", len) == 0) ||
2291 (len == 5 && strncmp(kernbuf, "clear", len) == 0)) {
2292 /* empty string is special case */
2293 spin_lock(&squash->rsi_lock);
2294 if (!list_empty(&squash->rsi_nosquash_nids))
2295 cfs_free_nidlist(&squash->rsi_nosquash_nids);
2296 spin_unlock(&squash->rsi_lock);
2297 LCONSOLE_INFO("%s: nosquash_nids is cleared\n", name);
2298 OBD_FREE(kernbuf, count + 1);
2302 if (cfs_parse_nidlist(kernbuf, count, &tmp) <= 0) {
2303 errmsg = "can't parse";
2304 GOTO(failed, rc = -EINVAL);
2306 LCONSOLE_INFO("%s: nosquash_nids set to %s\n",
2308 OBD_FREE(kernbuf, count + 1);
2311 spin_lock(&squash->rsi_lock);
2312 if (!list_empty(&squash->rsi_nosquash_nids))
2313 cfs_free_nidlist(&squash->rsi_nosquash_nids);
2314 list_splice(&tmp, &squash->rsi_nosquash_nids);
2315 spin_unlock(&squash->rsi_lock);
2321 CWARN("%s: failed to set nosquash_nids to \"%s\", %s rc = %d\n",
2322 name, kernbuf, errmsg, rc);
2323 OBD_FREE(kernbuf, count + 1);
2325 CWARN("%s: failed to set nosquash_nids due to %s rc = %d\n",
2330 EXPORT_SYMBOL(lprocfs_wr_nosquash_nids);
2332 #endif /* CONFIG_PROC_FS*/