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 /* enable start/elapsed_time in stats headers by default */
44 unsigned int obd_enable_stats_header = 1;
46 static int lprocfs_no_percpu_stats = 0;
47 module_param(lprocfs_no_percpu_stats, int, 0644);
48 MODULE_PARM_DESC(lprocfs_no_percpu_stats, "Do not alloc percpu data for lprocfs stats");
50 #define MAX_STRING_SIZE 128
52 int lprocfs_single_release(struct inode *inode, struct file *file)
54 return single_release(inode, file);
56 EXPORT_SYMBOL(lprocfs_single_release);
58 int lprocfs_seq_release(struct inode *inode, struct file *file)
60 return seq_release(inode, file);
62 EXPORT_SYMBOL(lprocfs_seq_release);
64 static umode_t default_mode(const struct proc_ops *ops)
76 struct proc_dir_entry *
77 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
78 void *data, const struct proc_ops *fops)
80 struct proc_dir_entry *proc;
83 if (!root || !name || !fops)
84 return ERR_PTR(-EINVAL);
86 mode = default_mode(fops);
87 proc = proc_create_data(name, mode, root, fops, data);
89 CERROR("LprocFS: No memory to create /proc entry %s\n",
91 return ERR_PTR(-ENOMEM);
95 EXPORT_SYMBOL(lprocfs_add_simple);
97 struct proc_dir_entry *lprocfs_add_symlink(const char *name,
98 struct proc_dir_entry *parent,
99 const char *format, ...)
101 struct proc_dir_entry *entry;
105 if (!parent || !format)
108 OBD_ALLOC_WAIT(dest, MAX_STRING_SIZE + 1);
112 va_start(ap, format);
113 vsnprintf(dest, MAX_STRING_SIZE, format, ap);
116 entry = proc_symlink(name, parent, dest);
118 CERROR("LprocFS: Could not create symbolic link from "
119 "%s to %s\n", name, dest);
121 OBD_FREE(dest, MAX_STRING_SIZE + 1);
124 EXPORT_SYMBOL(lprocfs_add_symlink);
126 static const struct file_operations ldebugfs_empty_ops = { };
128 void ldebugfs_add_vars(struct dentry *parent, struct ldebugfs_vars *list,
131 if (IS_ERR_OR_NULL(parent) || IS_ERR_OR_NULL(list))
137 if (list->proc_mode != 0000) {
138 mode = list->proc_mode;
139 } else if (list->fops) {
140 if (list->fops->read)
142 if (list->fops->write)
145 debugfs_create_file(list->name, mode, parent,
147 list->fops ? : &ldebugfs_empty_ops);
151 EXPORT_SYMBOL_GPL(ldebugfs_add_vars);
153 static const struct proc_ops lprocfs_empty_ops = { };
158 * \param root [in] The parent proc entry on which new entry will be added.
159 * \param list [in] Array of proc entries to be added.
160 * \param data [in] The argument to be passed when entries read/write routines
161 * are called through /proc file.
163 * \retval 0 on success
167 lprocfs_add_vars(struct proc_dir_entry *root, struct lprocfs_vars *list,
174 struct proc_dir_entry *proc;
178 mode = list->proc_mode;
180 mode = default_mode(list->fops);
181 proc = proc_create_data(list->name, mode, root,
182 list->fops ?: &lprocfs_empty_ops,
190 EXPORT_SYMBOL(lprocfs_add_vars);
192 void lprocfs_remove(struct proc_dir_entry **rooth)
197 EXPORT_SYMBOL(lprocfs_remove);
199 void lprocfs_remove_proc_entry(const char *name, struct proc_dir_entry *parent)
201 LASSERT(parent != NULL);
202 remove_proc_entry(name, parent);
204 EXPORT_SYMBOL(lprocfs_remove_proc_entry);
206 struct proc_dir_entry *
207 lprocfs_register(const char *name, struct proc_dir_entry *parent,
208 struct lprocfs_vars *list, void *data)
210 struct proc_dir_entry *newchild;
212 newchild = proc_mkdir(name, parent);
214 return ERR_PTR(-ENOMEM);
217 int rc = lprocfs_add_vars(newchild, list, data);
219 lprocfs_remove(&newchild);
225 EXPORT_SYMBOL(lprocfs_register);
227 /* Generic callbacks */
228 int lprocfs_uuid_seq_show(struct seq_file *m, void *data)
230 struct obd_device *obd = data;
232 LASSERT(obd != NULL);
233 seq_printf(m, "%s\n", obd->obd_uuid.uuid);
236 EXPORT_SYMBOL(lprocfs_uuid_seq_show);
238 static ssize_t uuid_show(struct kobject *kobj, struct attribute *attr,
241 struct obd_device *obd = container_of(kobj, struct obd_device,
244 return sprintf(buf, "%s\n", obd->obd_uuid.uuid);
246 LUSTRE_RO_ATTR(uuid);
248 static ssize_t blocksize_show(struct kobject *kobj, struct attribute *attr,
251 struct obd_device *obd = container_of(kobj, struct obd_device,
253 struct obd_statfs osfs;
256 rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
257 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
260 return sprintf(buf, "%u\n", osfs.os_bsize);
264 LUSTRE_RO_ATTR(blocksize);
266 static ssize_t kbytestotal_show(struct kobject *kobj, struct attribute *attr,
269 struct obd_device *obd = container_of(kobj, struct obd_device,
271 struct obd_statfs osfs;
274 rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
275 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
278 u32 blk_size = osfs.os_bsize >> 10;
279 u64 result = osfs.os_blocks;
281 result *= rounddown_pow_of_two(blk_size ?: 1);
282 return sprintf(buf, "%llu\n", result);
287 LUSTRE_RO_ATTR(kbytestotal);
289 static ssize_t kbytesfree_show(struct kobject *kobj, struct attribute *attr,
292 struct obd_device *obd = container_of(kobj, struct obd_device,
294 struct obd_statfs osfs;
297 rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
298 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
301 u32 blk_size = osfs.os_bsize >> 10;
302 u64 result = osfs.os_bfree;
304 while (blk_size >>= 1)
307 return sprintf(buf, "%llu\n", result);
312 LUSTRE_RO_ATTR(kbytesfree);
314 static ssize_t kbytesavail_show(struct kobject *kobj, struct attribute *attr,
317 struct obd_device *obd = container_of(kobj, struct obd_device,
319 struct obd_statfs osfs;
322 rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
323 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
326 u32 blk_size = osfs.os_bsize >> 10;
327 u64 result = osfs.os_bavail;
329 while (blk_size >>= 1)
332 return sprintf(buf, "%llu\n", result);
337 LUSTRE_RO_ATTR(kbytesavail);
339 static ssize_t filestotal_show(struct kobject *kobj, struct attribute *attr,
342 struct obd_device *obd = container_of(kobj, struct obd_device,
344 struct obd_statfs osfs;
347 rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
348 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
351 return sprintf(buf, "%llu\n", osfs.os_files);
355 LUSTRE_RO_ATTR(filestotal);
357 static ssize_t filesfree_show(struct kobject *kobj, struct attribute *attr,
360 struct obd_device *obd = container_of(kobj, struct obd_device,
362 struct obd_statfs osfs;
365 rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
366 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
369 return sprintf(buf, "%llu\n", osfs.os_ffree);
373 LUSTRE_RO_ATTR(filesfree);
375 ssize_t conn_uuid_show(struct kobject *kobj, struct attribute *attr, char *buf)
377 struct obd_device *obd = container_of(kobj, struct obd_device,
379 struct obd_import *imp;
380 struct ptlrpc_connection *conn;
383 with_imp_locked(obd, imp, count) {
384 conn = imp->imp_connection;
386 count = sprintf(buf, "%s\n", conn->c_remote_uuid.uuid);
388 count = sprintf(buf, "%s\n", "<none>");
393 EXPORT_SYMBOL(conn_uuid_show);
395 int lprocfs_server_uuid_seq_show(struct seq_file *m, void *data)
397 struct obd_device *obd = data;
398 struct obd_import *imp;
399 const char *imp_state_name = NULL;
402 LASSERT(obd != NULL);
403 with_imp_locked(obd, imp, rc) {
404 imp_state_name = ptlrpc_import_state_name(imp->imp_state);
405 seq_printf(m, "%s\t%s%s\n", obd2cli_tgt(obd), imp_state_name,
406 imp->imp_deactive ? "\tDEACTIVATED" : "");
411 EXPORT_SYMBOL(lprocfs_server_uuid_seq_show);
413 /** add up per-cpu counters */
416 * Lock statistics structure for access, possibly only on this CPU.
418 * The statistics struct may be allocated with per-CPU structures for
419 * efficient concurrent update (usually only on server-wide stats), or
420 * as a single global struct (e.g. for per-client or per-job statistics),
421 * so the required locking depends on the type of structure allocated.
423 * For per-CPU statistics, pin the thread to the current cpuid so that
424 * will only access the statistics for that CPU. If the stats structure
425 * for the current CPU has not been allocated (or previously freed),
426 * allocate it now. The per-CPU statistics do not need locking since
427 * the thread is pinned to the CPU during update.
429 * For global statistics, lock the stats structure to prevent concurrent update.
431 * \param[in] stats statistics structure to lock
432 * \param[in] opc type of operation:
433 * LPROCFS_GET_SMP_ID: "lock" and return current CPU index
434 * for incrementing statistics for that CPU
435 * LPROCFS_GET_NUM_CPU: "lock" and return number of used
436 * CPU indices to iterate over all indices
437 * \param[out] flags CPU interrupt saved state for IRQ-safe locking
439 * \retval cpuid of current thread or number of allocated structs
440 * \retval negative on error (only for opc LPROCFS_GET_SMP_ID + per-CPU stats)
442 int lprocfs_stats_lock(struct lprocfs_stats *stats,
443 enum lprocfs_stats_lock_ops opc,
444 unsigned long *flags)
446 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
447 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
448 spin_lock_irqsave(&stats->ls_lock, *flags);
450 spin_lock(&stats->ls_lock);
451 return opc == LPROCFS_GET_NUM_CPU ? 1 : 0;
455 case LPROCFS_GET_SMP_ID: {
456 unsigned int cpuid = get_cpu();
458 if (unlikely(!stats->ls_percpu[cpuid])) {
459 int rc = lprocfs_stats_alloc_one(stats, cpuid);
468 case LPROCFS_GET_NUM_CPU:
469 return stats->ls_biggest_alloc_num;
476 * Unlock statistics structure after access.
478 * Unlock the lock acquired via lprocfs_stats_lock() for global statistics,
479 * or unpin this thread from the current cpuid for per-CPU statistics.
481 * This function must be called using the same arguments as used when calling
482 * lprocfs_stats_lock() so that the correct operation can be performed.
484 * \param[in] stats statistics structure to unlock
485 * \param[in] opc type of operation (current cpuid or number of structs)
486 * \param[in] flags CPU interrupt saved state for IRQ-safe locking
488 void lprocfs_stats_unlock(struct lprocfs_stats *stats,
489 enum lprocfs_stats_lock_ops opc,
490 unsigned long *flags)
492 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
493 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
494 spin_unlock_irqrestore(&stats->ls_lock, *flags);
496 spin_unlock(&stats->ls_lock);
497 } else if (opc == LPROCFS_GET_SMP_ID) {
502 /** add up per-cpu counters */
503 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
504 struct lprocfs_counter *cnt)
506 unsigned int num_entry;
507 struct lprocfs_counter *percpu_cntr;
509 unsigned long flags = 0;
511 memset(cnt, 0, sizeof(*cnt));
514 /* set count to 1 to avoid divide-by-zero errs in callers */
519 cnt->lc_min = LC_MIN_INIT;
521 num_entry = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
523 for (i = 0; i < num_entry; i++) {
524 if (!stats->ls_percpu[i])
526 percpu_cntr = lprocfs_stats_counter_get(stats, i, idx);
528 cnt->lc_count += percpu_cntr->lc_count;
529 cnt->lc_sum += percpu_cntr->lc_sum;
530 if (percpu_cntr->lc_min < cnt->lc_min)
531 cnt->lc_min = percpu_cntr->lc_min;
532 if (percpu_cntr->lc_max > cnt->lc_max)
533 cnt->lc_max = percpu_cntr->lc_max;
534 cnt->lc_sumsquare += percpu_cntr->lc_sumsquare;
537 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
540 static void obd_import_flags2str(struct obd_import *imp, struct seq_file *m)
544 if (imp->imp_obd->obd_no_recov) {
545 seq_printf(m, "no_recov");
549 flag2str(imp, invalid);
550 flag2str(imp, deactive);
551 flag2str(imp, replayable);
552 flag2str(imp, delayed_recovery);
553 flag2str(imp, vbr_failed);
554 flag2str(imp, pingable);
555 flag2str(imp, resend_replay);
556 flag2str(imp, no_pinger_recover);
557 flag2str(imp, connect_tried);
560 static const char *const obd_connect_names[] = {
561 "read_only", /* 0x01 */
562 "lov_index", /* 0x02 */
563 "connect_from_mds", /* 0x03 */
564 "write_grant", /* 0x04 */
565 "server_lock", /* 0x10 */
566 "version", /* 0x20 */
567 "request_portal", /* 0x40 */
570 "create_on_write", /* 0x200 */
571 "truncate_lock", /* 0x400 */
572 "initial_transno", /* 0x800 */
573 "inode_bit_locks", /* 0x1000 */
574 "barrier", /* 0x2000 */
575 "getattr_by_fid", /* 0x4000 */
576 "no_oh_for_devices", /* 0x8000 */
577 "remote_client", /* 0x10000 */
578 "remote_client_by_force", /* 0x20000 */
579 "max_byte_per_rpc", /* 0x40000 */
580 "64bit_qdata", /* 0x80000 */
581 "mds_capability", /* 0x100000 */
582 "oss_capability", /* 0x200000 */
583 "early_lock_cancel", /* 0x400000 */
584 "som", /* 0x800000 */
585 "adaptive_timeouts", /* 0x1000000 */
586 "lru_resize", /* 0x2000000 */
587 "mds_mds_connection", /* 0x4000000 */
588 "real_conn", /* 0x8000000 */
589 "change_qunit_size", /* 0x10000000 */
590 "alt_checksum_algorithm", /* 0x20000000 */
591 "fid_is_enabled", /* 0x40000000 */
592 "version_recovery", /* 0x80000000 */
593 "pools", /* 0x100000000 */
594 "grant_shrink", /* 0x200000000 */
595 "skip_orphan", /* 0x400000000 */
596 "large_ea", /* 0x800000000 */
597 "full20", /* 0x1000000000 */
598 "layout_lock", /* 0x2000000000 */
599 "64bithash", /* 0x4000000000 */
600 "object_max_bytes", /* 0x8000000000 */
601 "imp_recov", /* 0x10000000000 */
602 "jobstats", /* 0x20000000000 */
603 "umask", /* 0x40000000000 */
604 "einprogress", /* 0x80000000000 */
605 "grant_param", /* 0x100000000000 */
606 "flock_owner", /* 0x200000000000 */
607 "lvb_type", /* 0x400000000000 */
608 "nanoseconds_times", /* 0x800000000000 */
609 "lightweight_conn", /* 0x1000000000000 */
610 "short_io", /* 0x2000000000000 */
611 "pingless", /* 0x4000000000000 */
612 "flock_deadlock", /* 0x8000000000000 */
613 "disp_stripe", /* 0x10000000000000 */
614 "open_by_fid", /* 0x20000000000000 */
615 "lfsck", /* 0x40000000000000 */
616 "unknown", /* 0x80000000000000 */
617 "unlink_close", /* 0x100000000000000 */
618 "multi_mod_rpcs", /* 0x200000000000000 */
619 "dir_stripe", /* 0x400000000000000 */
620 "subtree", /* 0x800000000000000 */
621 "lockahead", /* 0x1000000000000000 */
622 "bulk_mbits", /* 0x2000000000000000 */
623 "compact_obdo", /* 0x4000000000000000 */
624 "second_flags", /* 0x8000000000000000 */
625 /* ocd_connect_flags2 names */
626 "file_secctx", /* 0x01 */
627 "lockaheadv2", /* 0x02 */
628 "dir_migrate", /* 0x04 */
629 "sum_statfs", /* 0x08 */
630 "overstriping", /* 0x10 */
633 "lock_convert", /* 0x80 */
634 "archive_id_array", /* 0x100 */
635 "increasing_xid", /* 0x200 */
636 "selinux_policy", /* 0x400 */
639 "crush", /* 0x2000 */
640 "async_discard", /* 0x4000 */
641 "client_encryption", /* 0x8000 */
642 "fidmap", /* 0x10000 */
643 "getattr_pfid", /* 0x20000 */
644 "lseek", /* 0x40000 */
645 "dom_lvb", /* 0x80000 */
646 "reply_mbits", /* 0x100000 */
647 "mode_convert", /* 0x200000 */
648 "batch_rpc", /* 0x400000 */
649 "pcc_ro", /* 0x800000 */
650 "mne_nid_type", /* 0x1000000 */
651 "lock_contend", /* 0x2000000 */
652 "atomic_open_lock", /* 0x4000000 */
653 "name_encryption", /* 0x8000000 */
654 "mkdir_replay", /* 0x10000000 */
655 "dmv_imp_inherit", /* 0x20000000 */
656 "encryption_fid2path", /* 0x40000000 */
657 "replay_create", /* 0x80000000 */
658 "large_nid", /* 0x100000000 */
659 "compressed_file", /* 0x200000000 */
660 "unaligned_dio", /* 0x400000000 */
661 "conn_policy", /* 0x800000000 */
665 void obd_connect_seq_flags2str(struct seq_file *m, __u64 flags, __u64 flags2,
672 for (i = 0, mask = 1; i < 64; i++, mask <<= 1) {
674 seq_printf(m, "%s%s",
675 first ? "" : sep, obd_connect_names[i]);
680 if (flags & ~(mask - 1)) {
681 seq_printf(m, "%sunknown_%#llx",
682 first ? "" : sep, flags & ~(mask - 1));
686 if (!(flags & OBD_CONNECT_FLAGS2) || flags2 == 0)
689 for (i = 64, mask = 1; obd_connect_names[i] != NULL; i++, mask <<= 1) {
691 seq_printf(m, "%s%s",
692 first ? "" : sep, obd_connect_names[i]);
697 if (flags2 & ~(mask - 1)) {
698 seq_printf(m, "%sunknown2_%#llx",
699 first ? "" : sep, flags2 & ~(mask - 1));
703 EXPORT_SYMBOL(obd_connect_seq_flags2str);
705 int obd_connect_flags2str(char *page, int count, __u64 flags, __u64 flags2,
711 for (i = 0, mask = 1; i < 64; i++, mask <<= 1) {
713 ret += snprintf(page + ret, count - ret, "%s%s",
714 ret ? sep : "", obd_connect_names[i]);
717 if (flags & ~(mask - 1))
718 ret += snprintf(page + ret, count - ret,
720 ret ? sep : "", flags & ~(mask - 1));
722 if (!(flags & OBD_CONNECT_FLAGS2) || flags2 == 0)
725 for (i = 64, mask = 1; obd_connect_names[i] != NULL; i++, mask <<= 1) {
727 ret += snprintf(page + ret, count - ret, "%s%s",
728 ret ? sep : "", obd_connect_names[i]);
731 if (flags2 & ~(mask - 1))
732 ret += snprintf(page + ret, count - ret,
734 ret ? sep : "", flags2 & ~(mask - 1));
738 EXPORT_SYMBOL(obd_connect_flags2str);
741 obd_connect_data_seqprint(struct seq_file *m, struct obd_connect_data *ocd)
745 LASSERT(ocd != NULL);
746 flags = ocd->ocd_connect_flags;
748 seq_printf(m, " connect_data:\n"
751 ocd->ocd_connect_flags,
753 if (flags & OBD_CONNECT_VERSION)
754 seq_printf(m, " target_version: %u.%u.%u.%u\n",
755 OBD_OCD_VERSION_MAJOR(ocd->ocd_version),
756 OBD_OCD_VERSION_MINOR(ocd->ocd_version),
757 OBD_OCD_VERSION_PATCH(ocd->ocd_version),
758 OBD_OCD_VERSION_FIX(ocd->ocd_version));
759 if (flags & OBD_CONNECT_MDS)
760 seq_printf(m, " mdt_index: %d\n", ocd->ocd_group);
761 if (flags & OBD_CONNECT_GRANT)
762 seq_printf(m, " initial_grant: %d\n", ocd->ocd_grant);
763 if (flags & OBD_CONNECT_INDEX)
764 seq_printf(m, " target_index: %u\n", ocd->ocd_index);
765 if (flags & OBD_CONNECT_BRW_SIZE)
766 seq_printf(m, " max_brw_size: %d\n", ocd->ocd_brw_size);
767 if (flags & OBD_CONNECT_IBITS)
768 seq_printf(m, " ibits_known: %#llx\n",
769 ocd->ocd_ibits_known);
770 if (flags & OBD_CONNECT_GRANT_PARAM)
771 seq_printf(m, " grant_block_size: %d\n"
772 " grant_inode_size: %d\n"
773 " grant_max_extent_size: %d\n"
774 " grant_extent_tax: %d\n",
775 1 << ocd->ocd_grant_blkbits,
776 1 << ocd->ocd_grant_inobits,
777 ocd->ocd_grant_max_blks << ocd->ocd_grant_blkbits,
778 ocd->ocd_grant_tax_kb << 10);
779 if (flags & OBD_CONNECT_TRANSNO)
780 seq_printf(m, " first_transno: %#llx\n",
782 if (flags & OBD_CONNECT_CKSUM)
783 seq_printf(m, " cksum_types: %#x\n",
784 ocd->ocd_cksum_types);
785 if (flags & OBD_CONNECT_MAX_EASIZE)
786 seq_printf(m, " max_easize: %d\n", ocd->ocd_max_easize);
787 if (flags & OBD_CONNECT_MAXBYTES)
788 seq_printf(m, " max_object_bytes: %llu\n",
790 if (flags & OBD_CONNECT_MULTIMODRPCS)
791 seq_printf(m, " max_mod_rpcs: %hu\n",
792 ocd->ocd_maxmodrpcs);
795 static void lprocfs_import_seq_show_locked(struct seq_file *m,
796 struct obd_device *obd,
797 struct obd_import *imp)
799 char nidstr[LNET_NIDSTR_SIZE];
800 struct lprocfs_counter ret;
801 struct lprocfs_counter_header *header;
802 struct obd_import_conn *conn;
803 struct obd_connect_data *ocd;
808 ocd = &imp->imp_connect_data;
810 seq_printf(m, "import:\n"
814 " connect_flags: [ ",
817 ptlrpc_import_state_name(imp->imp_state));
818 obd_connect_seq_flags2str(m, imp->imp_connect_data.ocd_connect_flags,
819 imp->imp_connect_data.ocd_connect_flags2,
821 seq_printf(m, " ]\n");
822 obd_connect_data_seqprint(m, ocd);
823 seq_printf(m, " import_flags: [ ");
824 obd_import_flags2str(imp, m);
828 " failover_nids: [ ");
829 spin_lock(&imp->imp_lock);
831 list_for_each_entry(conn, &imp->imp_conn_list, oic_item) {
832 libcfs_nidstr_r(&conn->oic_conn->c_peer.nid,
833 nidstr, sizeof(nidstr));
836 /* Place nidstr in quotes */
837 seq_printf(m, "\"%s\"", nidstr);
840 if (imp->imp_connection)
841 libcfs_nidstr_r(&imp->imp_connection->c_peer.nid,
842 nidstr, sizeof(nidstr));
844 strncpy(nidstr, "<none>", sizeof(nidstr));
846 " current_connection: \"%s\"\n"
847 " connection_attempts: %u\n"
849 " in-progress_invalidations: %u\n"
854 atomic_read(&imp->imp_inval_count),
855 ktime_get_real_seconds() - imp->imp_last_reply_time);
856 spin_unlock(&imp->imp_lock);
858 if (!obd->obd_svc_stats)
861 header = &obd->obd_svc_stats->ls_cnt_header[PTLRPC_REQWAIT_CNTR];
862 lprocfs_stats_collect(obd->obd_svc_stats, PTLRPC_REQWAIT_CNTR, &ret);
863 if (ret.lc_count != 0)
864 ret.lc_sum = div64_s64(ret.lc_sum, ret.lc_count);
867 seq_printf(m, " rpcs:\n"
869 " unregistering: %u\n"
871 " avg_waittime: %llu %s\n",
872 atomic_read(&imp->imp_inflight),
873 atomic_read(&imp->imp_unregistering),
874 atomic_read(&imp->imp_timeouts),
875 ret.lc_sum, header->lc_units);
878 for(j = 0; j < IMP_AT_MAX_PORTALS; j++) {
879 if (imp->imp_at.iat_portal[j] == 0)
881 k = max_t(unsigned int, k,
882 obd_at_get(imp->imp_obd,
883 &imp->imp_at.iat_service_estimate[j]));
885 seq_printf(m, " service_estimates:\n"
886 " services: %u sec\n"
887 " network: %d sec\n",
889 obd_at_get(imp->imp_obd, &imp->imp_at.iat_net_latency));
891 seq_printf(m, " transactions:\n"
892 " last_replay: %llu\n"
893 " peer_committed: %llu\n"
894 " last_checked: %llu\n",
895 imp->imp_last_replay_transno,
896 imp->imp_peer_committed_transno,
897 imp->imp_last_transno_checked);
900 for (rw = 0; rw <= 1; rw++) {
901 lprocfs_stats_collect(obd->obd_svc_stats,
902 PTLRPC_LAST_CNTR + BRW_READ_BYTES + rw,
904 if (ret.lc_sum > 0 && ret.lc_count > 0) {
905 ret.lc_sum = div64_s64(ret.lc_sum, ret.lc_count);
906 seq_printf(m, " %s_data_averages:\n"
907 " bytes_per_rpc: %llu\n",
908 rw ? "write" : "read",
912 j = opcode_offset(OST_READ + rw) + EXTRA_MAX_OPCODES;
913 header = &obd->obd_svc_stats->ls_cnt_header[j];
914 lprocfs_stats_collect(obd->obd_svc_stats, j, &ret);
915 if (ret.lc_sum > 0 && ret.lc_count != 0) {
916 ret.lc_sum = div64_s64(ret.lc_sum, ret.lc_count);
917 seq_printf(m, " %s_per_rpc: %llu\n",
918 header->lc_units, ret.lc_sum);
921 seq_printf(m, " MB_per_sec: %u.%.02u\n",
922 k / j, (100 * k / j) % 100);
927 int lprocfs_import_seq_show(struct seq_file *m, void *data)
929 struct obd_device *obd = (struct obd_device *)data;
930 struct obd_import *imp;
933 LASSERT(obd != NULL);
934 with_imp_locked(obd, imp, rv)
935 lprocfs_import_seq_show_locked(m, obd, imp);
938 EXPORT_SYMBOL(lprocfs_import_seq_show);
940 int lprocfs_state_seq_show(struct seq_file *m, void *data)
942 struct obd_device *obd = (struct obd_device *)data;
943 struct obd_import *imp;
947 LASSERT(obd != NULL);
948 with_imp_locked(obd, imp, rc) {
949 seq_printf(m, "current_state: %s\n",
950 ptlrpc_import_state_name(imp->imp_state));
951 seq_printf(m, "state_history:\n");
952 k = imp->imp_state_hist_idx;
953 for (j = 0; j < IMP_STATE_HIST_LEN; j++) {
954 struct import_state_hist *ish =
955 &imp->imp_state_hist[(k + j) % IMP_STATE_HIST_LEN];
956 if (ish->ish_state == 0)
958 seq_printf(m, " - [ %lld, %s ]\n", (s64)ish->ish_time,
959 ptlrpc_import_state_name(ish->ish_state));
965 EXPORT_SYMBOL(lprocfs_state_seq_show);
967 int lprocfs_at_hist_helper(struct seq_file *m, struct adaptive_timeout *at)
970 for (i = 0; i < AT_BINS; i++)
971 seq_printf(m, "%3u ", at->at_hist[i]);
975 EXPORT_SYMBOL(lprocfs_at_hist_helper);
977 /* See also ptlrpc_lprocfs_timeouts_show_seq */
978 static void lprocfs_timeouts_seq_show_locked(struct seq_file *m,
979 struct obd_device *obd,
980 struct obd_import *imp)
982 timeout_t cur_timeout, worst_timeout;
983 time64_t now, worst_timestamp;
986 LASSERT(obd != NULL);
988 now = ktime_get_real_seconds();
990 /* Some network health info for kicks */
991 seq_printf(m, "%-10s : %lld, %llds ago\n",
992 "last reply", (s64)imp->imp_last_reply_time,
993 (s64)(now - imp->imp_last_reply_time));
995 cur_timeout = obd_at_get(imp->imp_obd, &imp->imp_at.iat_net_latency);
996 worst_timeout = imp->imp_at.iat_net_latency.at_worst_timeout_ever;
997 worst_timestamp = imp->imp_at.iat_net_latency.at_worst_timestamp;
998 seq_printf(m, "%-10s : cur %3u worst %3u (at %lld, %llds ago) ",
999 "network", cur_timeout, worst_timeout, worst_timestamp,
1000 now - worst_timestamp);
1001 lprocfs_at_hist_helper(m, &imp->imp_at.iat_net_latency);
1003 for(i = 0; i < IMP_AT_MAX_PORTALS; i++) {
1004 struct adaptive_timeout *service_est;
1006 if (imp->imp_at.iat_portal[i] == 0)
1009 service_est = &imp->imp_at.iat_service_estimate[i];
1010 cur_timeout = obd_at_get(imp->imp_obd, service_est);
1011 worst_timeout = service_est->at_worst_timeout_ever;
1012 worst_timestamp = service_est->at_worst_timestamp;
1013 seq_printf(m, "portal %-2d : cur %3u worst %3u (at %lld, %llds ago) ",
1014 imp->imp_at.iat_portal[i], cur_timeout,
1015 worst_timeout, worst_timestamp,
1016 now - worst_timestamp);
1017 lprocfs_at_hist_helper(m, service_est);
1021 int lprocfs_timeouts_seq_show(struct seq_file *m, void *data)
1023 struct obd_device *obd = (struct obd_device *)data;
1024 struct obd_import *imp;
1027 with_imp_locked(obd, imp, rc)
1028 lprocfs_timeouts_seq_show_locked(m, obd, imp);
1031 EXPORT_SYMBOL(lprocfs_timeouts_seq_show);
1033 int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data)
1035 struct obd_device *obd = data;
1038 struct obd_import *imp;
1041 with_imp_locked(obd, imp, rc) {
1042 flags = imp->imp_connect_data.ocd_connect_flags;
1043 flags2 = imp->imp_connect_data.ocd_connect_flags2;
1044 seq_printf(m, "flags=%#llx\n", flags);
1045 seq_printf(m, "flags2=%#llx\n", flags2);
1046 obd_connect_seq_flags2str(m, flags, flags2, "\n");
1047 seq_printf(m, "\n");
1052 EXPORT_SYMBOL(lprocfs_connect_flags_seq_show);
1054 static const struct attribute *obd_def_uuid_attrs[] = {
1055 &lustre_attr_uuid.attr,
1059 static const struct attribute *obd_def_attrs[] = {
1060 &lustre_attr_blocksize.attr,
1061 &lustre_attr_kbytestotal.attr,
1062 &lustre_attr_kbytesfree.attr,
1063 &lustre_attr_kbytesavail.attr,
1064 &lustre_attr_filestotal.attr,
1065 &lustre_attr_filesfree.attr,
1066 &lustre_attr_uuid.attr,
1070 static void obd_sysfs_release(struct kobject *kobj)
1072 struct obd_device *obd = container_of(kobj, struct obd_device,
1075 complete(&obd->obd_kobj_unregister);
1078 int lprocfs_obd_setup(struct obd_device *obd, bool uuid_only)
1080 struct ldebugfs_vars *debugfs_vars = NULL;
1083 if (!obd || obd->obd_magic != OBD_DEVICE_MAGIC)
1086 rc = kobject_set_name(&obd->obd_kset.kobj, "%s", obd->obd_name);
1090 obd->obd_ktype.sysfs_ops = &lustre_sysfs_ops;
1091 obd->obd_ktype.release = obd_sysfs_release;
1093 obd->obd_kset.kobj.parent = &obd->obd_type->typ_kobj;
1094 obd->obd_kset.kobj.ktype = &obd->obd_ktype;
1095 init_completion(&obd->obd_kobj_unregister);
1096 rc = kset_register(&obd->obd_kset);
1101 obd->obd_attrs = obd_def_uuid_attrs;
1103 obd->obd_attrs = obd_def_attrs;
1105 rc = sysfs_create_files(&obd->obd_kset.kobj, obd->obd_attrs);
1107 kset_unregister(&obd->obd_kset);
1111 if (!obd->obd_type->typ_procroot)
1112 debugfs_vars = obd->obd_debugfs_vars;
1113 obd->obd_debugfs_entry = debugfs_create_dir(
1114 obd->obd_name, obd->obd_type->typ_debugfs_entry);
1115 ldebugfs_add_vars(obd->obd_debugfs_entry, debugfs_vars, obd);
1117 if (obd->obd_proc_entry || !obd->obd_type->typ_procroot)
1118 GOTO(already_registered, rc);
1120 obd->obd_proc_entry = lprocfs_register(obd->obd_name,
1121 obd->obd_type->typ_procroot,
1122 obd->obd_vars, obd);
1123 if (IS_ERR(obd->obd_proc_entry)) {
1124 rc = PTR_ERR(obd->obd_proc_entry);
1125 CERROR("error %d setting up lprocfs for %s\n",rc,obd->obd_name);
1126 obd->obd_proc_entry = NULL;
1128 debugfs_remove_recursive(obd->obd_debugfs_entry);
1129 obd->obd_debugfs_entry = NULL;
1131 sysfs_remove_files(&obd->obd_kset.kobj, obd->obd_attrs);
1132 obd->obd_attrs = NULL;
1133 kset_unregister(&obd->obd_kset);
1139 EXPORT_SYMBOL(lprocfs_obd_setup);
1141 int lprocfs_obd_cleanup(struct obd_device *obd)
1146 debugfs_remove_recursive(obd->obd_debugfs_gss_dir);
1147 obd->obd_debugfs_gss_dir = NULL;
1149 if (obd->obd_proc_exports_entry) {
1150 /* Should be no exports left */
1151 lprocfs_remove(&obd->obd_proc_exports_entry);
1152 obd->obd_proc_exports_entry = NULL;
1155 if (obd->obd_proc_entry) {
1156 lprocfs_remove(&obd->obd_proc_entry);
1157 obd->obd_proc_entry = NULL;
1160 debugfs_remove_recursive(obd->obd_debugfs_entry);
1161 obd->obd_debugfs_entry = NULL;
1163 /* obd device never allocated a kset */
1164 if (!obd->obd_kset.kobj.state_initialized)
1167 if (obd->obd_attrs) {
1168 sysfs_remove_files(&obd->obd_kset.kobj, obd->obd_attrs);
1169 obd->obd_attrs = NULL;
1172 kset_unregister(&obd->obd_kset);
1173 wait_for_completion(&obd->obd_kobj_unregister);
1176 EXPORT_SYMBOL(lprocfs_obd_cleanup);
1178 int lprocfs_stats_alloc_one(struct lprocfs_stats *stats, unsigned int cpuid)
1180 struct lprocfs_counter *cntr;
1181 unsigned int percpusize;
1183 unsigned long flags = 0;
1186 LASSERT(stats->ls_percpu[cpuid] == NULL);
1187 LASSERT((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0);
1189 percpusize = lprocfs_stats_counter_size(stats);
1190 LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[cpuid], percpusize);
1191 if (stats->ls_percpu[cpuid]) {
1193 if (unlikely(stats->ls_biggest_alloc_num <= cpuid)) {
1194 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
1195 spin_lock_irqsave(&stats->ls_lock, flags);
1197 spin_lock(&stats->ls_lock);
1198 if (stats->ls_biggest_alloc_num <= cpuid)
1199 stats->ls_biggest_alloc_num = cpuid + 1;
1200 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) {
1201 spin_unlock_irqrestore(&stats->ls_lock, flags);
1203 spin_unlock(&stats->ls_lock);
1206 /* initialize the ls_percpu[cpuid] non-zero counter */
1207 for (i = 0; i < stats->ls_num; ++i) {
1208 cntr = lprocfs_stats_counter_get(stats, cpuid, i);
1209 cntr->lc_min = LC_MIN_INIT;
1215 struct lprocfs_stats *lprocfs_stats_alloc(unsigned int num,
1216 enum lprocfs_stats_flags flags)
1218 struct lprocfs_stats *stats;
1219 unsigned int num_entry;
1220 unsigned int percpusize = 0;
1226 if (lprocfs_no_percpu_stats != 0)
1227 flags |= LPROCFS_STATS_FLAG_NOPERCPU;
1229 if (flags & LPROCFS_STATS_FLAG_NOPERCPU)
1232 num_entry = num_possible_cpus();
1234 /* alloc percpu pointers for all possible cpu slots */
1235 LIBCFS_ALLOC(stats, offsetof(typeof(*stats), ls_percpu[num_entry]));
1239 stats->ls_num = num;
1240 stats->ls_flags = flags;
1241 stats->ls_init = ktime_get_real();
1242 spin_lock_init(&stats->ls_lock);
1244 /* alloc num of counter headers */
1245 CFS_ALLOC_PTR_ARRAY(stats->ls_cnt_header, stats->ls_num);
1246 if (!stats->ls_cnt_header)
1249 if ((flags & LPROCFS_STATS_FLAG_NOPERCPU) != 0) {
1250 /* contains only one set counters */
1251 percpusize = lprocfs_stats_counter_size(stats);
1252 LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[0], percpusize);
1253 if (!stats->ls_percpu[0])
1255 stats->ls_biggest_alloc_num = 1;
1256 } else if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0) {
1257 /* alloc all percpu data, currently only obd_memory use this */
1258 for (i = 0; i < num_entry; ++i)
1259 if (lprocfs_stats_alloc_one(stats, i) < 0)
1266 lprocfs_stats_free(&stats);
1269 EXPORT_SYMBOL(lprocfs_stats_alloc);
1271 void lprocfs_stats_free(struct lprocfs_stats **statsh)
1273 struct lprocfs_stats *stats = *statsh;
1274 unsigned int num_entry;
1275 unsigned int percpusize;
1278 if (!stats || stats->ls_num == 0)
1282 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU)
1285 num_entry = num_possible_cpus();
1287 percpusize = lprocfs_stats_counter_size(stats);
1288 for (i = 0; i < num_entry; i++)
1289 if (stats->ls_percpu[i])
1290 LIBCFS_FREE(stats->ls_percpu[i], percpusize);
1292 if (stats->ls_cnt_header) {
1293 for (i = 0; i < stats->ls_num; i++)
1294 if (stats->ls_cnt_header[i].lc_hist != NULL)
1295 CFS_FREE_PTR(stats->ls_cnt_header[i].lc_hist);
1296 CFS_FREE_PTR_ARRAY(stats->ls_cnt_header, stats->ls_num);
1299 LIBCFS_FREE(stats, offsetof(typeof(*stats), ls_percpu[num_entry]));
1301 EXPORT_SYMBOL(lprocfs_stats_free);
1303 u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
1304 enum lprocfs_fields_flags field)
1306 unsigned long flags = 0;
1307 unsigned int num_cpu;
1313 num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1314 for (i = 0; i < num_cpu; i++) {
1315 struct lprocfs_counter *cntr;
1317 if (!stats->ls_percpu[i])
1320 cntr = lprocfs_stats_counter_get(stats, i, idx);
1321 ret += lprocfs_read_helper(cntr, &stats->ls_cnt_header[idx],
1322 stats->ls_flags, field);
1324 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1327 EXPORT_SYMBOL(lprocfs_stats_collector);
1329 void lprocfs_stats_clear(struct lprocfs_stats *stats)
1331 struct lprocfs_counter *percpu_cntr;
1332 unsigned int num_entry;
1333 unsigned long flags = 0;
1336 num_entry = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1338 /* clear histogram if exists */
1339 for (j = 0; j < stats->ls_num; j++) {
1340 struct obd_histogram *hist = stats->ls_cnt_header[j].lc_hist;
1343 lprocfs_oh_clear(hist);
1346 for (i = 0; i < num_entry; i++) {
1347 if (!stats->ls_percpu[i])
1349 for (j = 0; j < stats->ls_num; j++) {
1350 percpu_cntr = lprocfs_stats_counter_get(stats, i, j);
1351 percpu_cntr->lc_count = 0;
1352 percpu_cntr->lc_min = LC_MIN_INIT;
1353 percpu_cntr->lc_max = 0;
1354 percpu_cntr->lc_sumsquare = 0;
1355 percpu_cntr->lc_sum = 0;
1356 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
1357 percpu_cntr->lc_sum_irq = 0;
1360 stats->ls_init = ktime_get_real();
1362 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1364 EXPORT_SYMBOL(lprocfs_stats_clear);
1366 static ssize_t lprocfs_stats_seq_write(struct file *file,
1367 const char __user *buf,
1368 size_t len, loff_t *off)
1370 struct seq_file *seq = file->private_data;
1371 struct lprocfs_stats *stats = seq->private;
1373 lprocfs_stats_clear(stats);
1378 static void *lprocfs_stats_seq_start(struct seq_file *p, loff_t *pos)
1380 struct lprocfs_stats *stats = p->private;
1382 return (*pos < stats->ls_num) ? pos : NULL;
1385 static void lprocfs_stats_seq_stop(struct seq_file *p, void *v)
1389 static void *lprocfs_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
1393 return lprocfs_stats_seq_start(p, pos);
1397 * print header of stats including snapshot_time, start_time and elapsed_time.
1399 * \param seq the file to print content to
1400 * \param now end time to calculate elapsed_time
1401 * \param ts_init start time to calculate elapsed_time
1402 * \param width the width of key to align them well
1403 * \param colon "" or ":"
1404 * \param show_units show units or not
1405 * \param prefix prefix (indent) before printing each line of header
1406 * to align them with other content
1408 void lprocfs_stats_header(struct seq_file *seq, ktime_t now, ktime_t ts_init,
1409 int width, const char *colon, bool show_units,
1412 const char *units = show_units ? " secs.nsecs" : "";
1413 struct timespec64 ts;
1416 field = (colon && colon[0]) ? "snapshot_time:" : "snapshot_time";
1417 ts = ktime_to_timespec64(now);
1418 seq_printf(seq, "%s%-*s %llu.%09lu%s\n", prefix, width, field,
1419 (s64)ts.tv_sec, ts.tv_nsec, units);
1421 if (!obd_enable_stats_header)
1424 field = (colon && colon[0]) ? "start_time:" : "start_time";
1425 ts = ktime_to_timespec64(ts_init);
1426 seq_printf(seq, "%s%-*s %llu.%09lu%s\n", prefix, width, field,
1427 (s64)ts.tv_sec, ts.tv_nsec, units);
1429 field = (colon && colon[0]) ? "elapsed_time:" : "elapsed_time";
1430 ts = ktime_to_timespec64(ktime_sub(now, ts_init));
1431 seq_printf(seq, "%s%-*s %llu.%09lu%s\n", prefix, width, field,
1432 (s64)ts.tv_sec, ts.tv_nsec, units);
1434 EXPORT_SYMBOL(lprocfs_stats_header);
1436 /* seq file export of one lprocfs counter */
1437 static int lprocfs_stats_seq_show(struct seq_file *p, void *v)
1439 struct lprocfs_stats *stats = p->private;
1440 struct lprocfs_counter_header *hdr;
1441 struct lprocfs_counter ctr;
1442 int idx = *(loff_t *)v;
1445 lprocfs_stats_header(p, ktime_get_real(), stats->ls_init, 25,
1448 hdr = &stats->ls_cnt_header[idx];
1449 lprocfs_stats_collect(stats, idx, &ctr);
1451 if (ctr.lc_count == 0)
1454 seq_printf(p, "%-25s %lld samples [%s]", hdr->lc_name,
1455 ctr.lc_count, hdr->lc_units);
1457 if ((hdr->lc_config & LPROCFS_CNTR_AVGMINMAX) && ctr.lc_count > 0) {
1458 seq_printf(p, " %lld %lld %lld",
1459 ctr.lc_min, ctr.lc_max, ctr.lc_sum);
1460 if (hdr->lc_config & LPROCFS_CNTR_STDDEV)
1461 seq_printf(p, " %llu", ctr.lc_sumsquare);
1467 static const struct seq_operations lprocfs_stats_seq_sops = {
1468 .start = lprocfs_stats_seq_start,
1469 .stop = lprocfs_stats_seq_stop,
1470 .next = lprocfs_stats_seq_next,
1471 .show = lprocfs_stats_seq_show,
1474 static int lprocfs_stats_seq_open(struct inode *inode, struct file *file)
1476 struct seq_file *seq;
1479 rc = seq_open(file, &lprocfs_stats_seq_sops);
1482 seq = file->private_data;
1483 seq->private = inode->i_private ? inode->i_private : pde_data(inode);
1487 const struct file_operations ldebugfs_stats_seq_fops = {
1488 .owner = THIS_MODULE,
1489 .open = lprocfs_stats_seq_open,
1491 .write = lprocfs_stats_seq_write,
1492 .llseek = seq_lseek,
1493 .release = lprocfs_seq_release,
1495 EXPORT_SYMBOL(ldebugfs_stats_seq_fops);
1497 static const struct proc_ops lprocfs_stats_seq_fops = {
1498 PROC_OWNER(THIS_MODULE)
1499 .proc_open = lprocfs_stats_seq_open,
1500 .proc_read = seq_read,
1501 .proc_write = lprocfs_stats_seq_write,
1502 .proc_lseek = seq_lseek,
1503 .proc_release = lprocfs_seq_release,
1506 int lprocfs_stats_register(struct proc_dir_entry *root, const char *name,
1507 struct lprocfs_stats *stats)
1509 struct proc_dir_entry *entry;
1511 LASSERT(root != NULL);
1512 entry = proc_create_data(name, 0644, root,
1513 &lprocfs_stats_seq_fops, stats);
1519 EXPORT_SYMBOL(lprocfs_stats_register);
1521 static const char *lprocfs_counter_config_units(const char *name,
1522 enum lprocfs_counter_config config)
1526 switch (config & LPROCFS_TYPE_MASK) {
1528 units = "reqs"; break;
1529 case LPROCFS_TYPE_BYTES:
1530 units = "bytes"; break;
1531 case LPROCFS_TYPE_PAGES:
1532 units = "pages"; break;
1533 case LPROCFS_TYPE_LOCKS:
1534 units = "locks"; break;
1535 case LPROCFS_TYPE_LOCKSPS:
1536 units = "locks/s"; break;
1537 case LPROCFS_TYPE_SECS:
1538 units = "secs"; break;
1539 case LPROCFS_TYPE_USECS:
1540 units = "usecs"; break;
1546 void lprocfs_counter_init_units(struct lprocfs_stats *stats, int index,
1547 enum lprocfs_counter_config config,
1548 const char *name, const char *units)
1550 struct lprocfs_counter_header *header;
1551 struct lprocfs_counter *percpu_cntr;
1552 unsigned long flags = 0;
1554 unsigned int num_cpu;
1556 LASSERT(stats != NULL);
1558 header = &stats->ls_cnt_header[index];
1559 LASSERTF(header != NULL, "Failed to allocate stats header:[%d]%s/%s\n",
1560 index, name, units);
1562 header->lc_config = config;
1563 header->lc_name = name;
1564 header->lc_units = units;
1566 if (config & LPROCFS_CNTR_HISTOGRAM) {
1567 CFS_ALLOC_PTR(stats->ls_cnt_header[index].lc_hist);
1568 if (stats->ls_cnt_header[index].lc_hist == NULL)
1569 CERROR("LprocFS: Failed to allocate histogram:[%d]%s/%s\n",
1570 index, name, units);
1572 spin_lock_init(&stats->ls_cnt_header[index].lc_hist->oh_lock);
1574 num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1575 for (i = 0; i < num_cpu; ++i) {
1576 if (!stats->ls_percpu[i])
1578 percpu_cntr = lprocfs_stats_counter_get(stats, i, index);
1579 percpu_cntr->lc_count = 0;
1580 percpu_cntr->lc_min = LC_MIN_INIT;
1581 percpu_cntr->lc_max = 0;
1582 percpu_cntr->lc_sumsquare = 0;
1583 percpu_cntr->lc_sum = 0;
1584 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
1585 percpu_cntr->lc_sum_irq = 0;
1587 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1589 EXPORT_SYMBOL(lprocfs_counter_init_units);
1591 void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
1592 enum lprocfs_counter_config config,
1595 lprocfs_counter_init_units(stats, index, config, name,
1596 lprocfs_counter_config_units(name, config));
1598 EXPORT_SYMBOL(lprocfs_counter_init);
1600 static const char * const mps_stats[] = {
1601 [LPROC_MD_CLOSE] = "close",
1602 [LPROC_MD_CREATE] = "create",
1603 [LPROC_MD_ENQUEUE] = "enqueue",
1604 [LPROC_MD_GETATTR] = "getattr",
1605 [LPROC_MD_INTENT_LOCK] = "intent_lock",
1606 [LPROC_MD_LINK] = "link",
1607 [LPROC_MD_RENAME] = "rename",
1608 [LPROC_MD_SETATTR] = "setattr",
1609 [LPROC_MD_FSYNC] = "fsync",
1610 [LPROC_MD_READ_PAGE] = "read_page",
1611 [LPROC_MD_UNLINK] = "unlink",
1612 [LPROC_MD_SETXATTR] = "setxattr",
1613 [LPROC_MD_GETXATTR] = "getxattr",
1614 [LPROC_MD_INTENT_GETATTR_ASYNC] = "intent_getattr_async",
1615 [LPROC_MD_REVALIDATE_LOCK] = "revalidate_lock",
1618 int lprocfs_alloc_md_stats(struct obd_device *obd,
1619 unsigned int num_private_stats)
1621 struct lprocfs_stats *stats;
1622 unsigned int num_stats;
1626 * TODO Ensure that this function is only used where
1627 * appropriate by adding an assertion to the effect that
1628 * obd->obd_type->typ_md_ops is not NULL. We can't do this now
1629 * because mdt_procfs_init() uses this function to allocate
1630 * the stats backing /proc/fs/lustre/mdt/.../md_stats but the
1631 * mdt layer does not use the md_ops interface. This is
1632 * confusing and a waste of memory. See LU-2484.
1634 LASSERT(obd->obd_proc_entry != NULL);
1635 LASSERT(obd->obd_md_stats == NULL);
1637 num_stats = ARRAY_SIZE(mps_stats) + num_private_stats;
1638 stats = lprocfs_stats_alloc(num_stats, 0);
1642 for (i = 0; i < ARRAY_SIZE(mps_stats); i++) {
1643 lprocfs_counter_init(stats, i, LPROCFS_TYPE_REQS,
1645 if (!stats->ls_cnt_header[i].lc_name) {
1646 CERROR("Missing md_stat initializer md_op operation at offset %d. Aborting.\n",
1652 rc = lprocfs_stats_register(obd->obd_proc_entry, "md_stats", stats);
1654 lprocfs_stats_free(&stats);
1656 obd->obd_md_stats = stats;
1661 EXPORT_SYMBOL(lprocfs_alloc_md_stats);
1663 void lprocfs_free_md_stats(struct obd_device *obd)
1665 struct lprocfs_stats *stats = obd->obd_md_stats;
1668 obd->obd_md_stats = NULL;
1669 lprocfs_stats_free(&stats);
1672 EXPORT_SYMBOL(lprocfs_free_md_stats);
1674 void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
1676 lprocfs_counter_init(ldlm_stats, LDLM_ENQUEUE - LDLM_FIRST_OPC,
1677 LPROCFS_TYPE_REQS, "ldlm_enqueue");
1678 lprocfs_counter_init(ldlm_stats, LDLM_CONVERT - LDLM_FIRST_OPC,
1679 LPROCFS_TYPE_REQS, "ldlm_convert");
1680 lprocfs_counter_init(ldlm_stats, LDLM_CANCEL - LDLM_FIRST_OPC,
1681 LPROCFS_TYPE_REQS, "ldlm_cancel");
1682 lprocfs_counter_init(ldlm_stats, LDLM_BL_CALLBACK - LDLM_FIRST_OPC,
1683 LPROCFS_TYPE_REQS, "ldlm_bl_callback");
1684 lprocfs_counter_init(ldlm_stats, LDLM_CP_CALLBACK - LDLM_FIRST_OPC,
1685 LPROCFS_TYPE_REQS, "ldlm_cp_callback");
1686 lprocfs_counter_init(ldlm_stats, LDLM_GL_CALLBACK - LDLM_FIRST_OPC,
1687 LPROCFS_TYPE_REQS, "ldlm_gl_callback");
1689 EXPORT_SYMBOL(lprocfs_init_ldlm_stats);
1691 __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
1692 struct lprocfs_counter_header *header,
1693 enum lprocfs_stats_flags flags,
1694 enum lprocfs_fields_flags field)
1702 case LPROCFS_FIELDS_FLAGS_CONFIG:
1703 ret = header->lc_config;
1705 case LPROCFS_FIELDS_FLAGS_SUM:
1707 if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
1708 ret += lc->lc_sum_irq;
1710 case LPROCFS_FIELDS_FLAGS_MIN:
1713 case LPROCFS_FIELDS_FLAGS_MAX:
1716 case LPROCFS_FIELDS_FLAGS_AVG:
1717 ret = div64_u64((flags & LPROCFS_STATS_FLAG_IRQ_SAFE ?
1718 lc->lc_sum_irq : 0) + lc->lc_sum,
1721 case LPROCFS_FIELDS_FLAGS_SUMSQUARE:
1722 ret = lc->lc_sumsquare;
1724 case LPROCFS_FIELDS_FLAGS_COUNT:
1732 EXPORT_SYMBOL(lprocfs_read_helper);
1735 * string_to_size - convert ASCII string representing a numerical
1736 * value with optional units to 64-bit binary value
1738 * @size: The numerical value extract out of @buffer
1739 * @buffer: passed in string to parse
1740 * @count: length of the @buffer
1742 * This function returns a 64-bit binary value if @buffer contains a valid
1743 * numerical string. The string is parsed to 3 significant figures after
1744 * the decimal point. Support the string containing an optional units at
1745 * the end which can be base 2 or base 10 in value. If no units are given
1746 * the string is assumed to just a numerical value.
1748 * Returns: @count if the string is successfully parsed,
1749 * -errno on invalid input strings. Error values:
1751 * - ``-EINVAL``: @buffer is not a proper numerical string
1752 * - ``-EOVERFLOW``: results does not fit into 64 bits.
1753 * - ``-E2BIG ``: @buffer is too large (not a valid number)
1755 int string_to_size(u64 *size, const char *buffer, size_t count)
1757 /* For string_get_size() it can support values above exabytes,
1758 * (ZiB, YiB) due to breaking the return value into a size and
1759 * bulk size to avoid 64 bit overflow. We don't break the size
1760 * up into block size units so we don't support ZiB or YiB.
1762 static const char *const units_10[] = {
1763 "kB", "MB", "GB", "TB", "PB", "EB",
1765 static const char *const units_2[] = {
1766 "K", "M", "G", "T", "P", "E",
1768 static const char *const *const units_str[] = {
1769 [STRING_UNITS_2] = units_2,
1770 [STRING_UNITS_10] = units_10,
1772 static const unsigned int coeff[] = {
1773 [STRING_UNITS_10] = 1000,
1774 [STRING_UNITS_2] = 1024,
1776 enum string_size_units unit = STRING_UNITS_2;
1777 u64 whole, blk_size = 1;
1778 char kernbuf[22], *end;
1783 if (count >= sizeof(kernbuf)) {
1784 CERROR("count %zd > buffer %zd\n", count, sizeof(kernbuf));
1789 /* The "iB" suffix is optionally allowed for indicating base-2 numbers.
1790 * If suffix is only "B" and not "iB" then we treat it as base-10.
1792 end = strstr(buffer, "B");
1793 if (end && *(end - 1) != 'i')
1794 unit = STRING_UNITS_10;
1796 i = unit == STRING_UNITS_2 ? ARRAY_SIZE(units_2) - 1 :
1797 ARRAY_SIZE(units_10) - 1;
1799 end = strnstr(buffer, units_str[unit][i], count);
1802 blk_size *= coeff[unit];
1808 /* as 'B' is a substring of all units, we need to handle it
1812 /* 'B' is only acceptable letter at this point */
1813 end = strnchr(buffer, count, 'B');
1817 if (count - len > 2 ||
1818 (count - len == 2 && strcmp(end, "B\n") != 0)) {
1819 CDEBUG(D_INFO, "unknown suffix '%s'\n", buffer);
1823 /* kstrtoull will error out if it has non digits */
1827 end = strnchr(buffer, count, '.');
1829 /* need to limit 3 decimal places */
1830 char rem[4] = "000";
1837 /* limit to 3 decimal points */
1838 off = min_t(size_t, 3, strspn(end, "0123456789"));
1839 /* need to limit frac_d to a u32 */
1840 memcpy(rem, end, off);
1841 rc = kstrtoull(rem, 10, &frac);
1845 if (fls64(frac) + fls64(blk_size) - 1 > 64)
1853 snprintf(kernbuf, sizeof(kernbuf), "%.*s", (int)len, buffer);
1854 rc = kstrtoull(kernbuf, 10, &whole);
1858 if (whole != 0 && fls64(whole) + fls64(blk_size) - 1 > 64)
1861 *size += whole * blk_size;
1865 EXPORT_SYMBOL(string_to_size);
1868 * sysfs_memparse - parse a ASCII string to 64-bit binary value,
1869 * with optional units
1871 * @buffer: kernel pointer to input string
1872 * @count: number of bytes in the input @buffer
1873 * @val: (output) binary value returned to caller
1874 * @defunit: default unit suffix to use if none is provided
1876 * Parses a string into a number. The number stored at @buffer is
1877 * potentially suffixed with K, M, G, T, P, E. Besides these other
1878 * valid suffix units are shown in the string_to_size() function.
1879 * If the string lacks a suffix then the defunit is used. The defunit
1880 * should be given as a binary unit (e.g. MiB) as that is the standard
1881 * for tunables in Lustre. If no unit suffix is given (e.g. 'G'), then
1882 * it is assumed to be in binary units.
1884 * Returns: 0 on success or -errno on failure.
1886 int sysfs_memparse(const char *buffer, size_t count, u64 *val,
1887 const char *defunit)
1889 const char *param = buffer;
1893 count = strlen(buffer);
1894 while (count > 0 && isspace(buffer[count - 1]))
1900 /* If there isn't already a unit on this value, append @defunit.
1901 * Units of 'B' don't affect the value, so don't bother adding.
1903 if (!isalpha(buffer[count - 1]) && defunit[0] != 'B') {
1904 if (count + 3 >= sizeof(tmp_buf)) {
1905 CERROR("count %zd > size %zd\n", count, sizeof(param));
1909 scnprintf(tmp_buf, sizeof(tmp_buf), "%.*s%s", (int)count,
1912 count = strlen(param);
1915 rc = string_to_size(val, param, count);
1917 return rc < 0 ? rc : 0;
1919 EXPORT_SYMBOL(sysfs_memparse);
1921 char *lprocfs_strnstr(const char *s1, const char *s2, size_t len)
1930 if (!memcmp(s1, s2, l2))
1936 EXPORT_SYMBOL(lprocfs_strnstr);
1939 * Find the string \a name in the input \a buffer, and return a pointer to the
1940 * value immediately following \a name, reducing \a count appropriately.
1941 * If \a name is not found the original \a buffer is returned.
1943 char *lprocfs_find_named_value(const char *buffer, const char *name,
1947 size_t buflen = *count;
1949 /* there is no strnstr() in rhel5 and ubuntu kernels */
1950 val = lprocfs_strnstr(buffer, name, buflen);
1952 return (char *)buffer;
1954 val += strlen(name); /* skip prefix */
1955 while (val < buffer + buflen && isspace(*val)) /* skip separator */
1959 while (val < buffer + buflen && isalnum(*val)) {
1964 return val - *count;
1966 EXPORT_SYMBOL(lprocfs_find_named_value);
1968 int lprocfs_seq_create(struct proc_dir_entry *parent,
1971 const struct proc_ops *seq_fops,
1974 struct proc_dir_entry *entry;
1977 /* Disallow secretly (un)writable entries. */
1978 LASSERT(!seq_fops->proc_write == !(mode & 0222));
1980 entry = proc_create_data(name, mode, parent, seq_fops, data);
1987 EXPORT_SYMBOL(lprocfs_seq_create);
1989 int lprocfs_obd_seq_create(struct obd_device *obd,
1992 const struct proc_ops *seq_fops,
1995 return lprocfs_seq_create(obd->obd_proc_entry, name,
1996 mode, seq_fops, data);
1998 EXPORT_SYMBOL(lprocfs_obd_seq_create);
2000 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
2002 if (value >= OBD_HIST_MAX)
2003 value = OBD_HIST_MAX - 1;
2005 spin_lock(&oh->oh_lock);
2006 oh->oh_buckets[value]++;
2007 spin_unlock(&oh->oh_lock);
2009 EXPORT_SYMBOL(lprocfs_oh_tally);
2011 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
2013 unsigned int val = 0;
2015 if (likely(value != 0))
2016 val = min(fls(value - 1), OBD_HIST_MAX);
2018 lprocfs_oh_tally(oh, val);
2020 EXPORT_SYMBOL(lprocfs_oh_tally_log2);
2022 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
2024 unsigned long ret = 0;
2027 for (i = 0; i < OBD_HIST_MAX; i++)
2028 ret += oh->oh_buckets[i];
2031 EXPORT_SYMBOL(lprocfs_oh_sum);
2033 void lprocfs_oh_clear(struct obd_histogram *oh)
2035 spin_lock(&oh->oh_lock);
2036 memset(oh->oh_buckets, 0, sizeof(oh->oh_buckets));
2037 spin_unlock(&oh->oh_lock);
2039 EXPORT_SYMBOL(lprocfs_oh_clear);
2041 void lprocfs_oh_tally_pcpu(struct obd_hist_pcpu *oh,
2044 if (value >= OBD_HIST_MAX)
2045 value = OBD_HIST_MAX - 1;
2047 percpu_counter_inc(&oh->oh_pc_buckets[value]);
2049 EXPORT_SYMBOL(lprocfs_oh_tally_pcpu);
2051 void lprocfs_oh_tally_log2_pcpu(struct obd_hist_pcpu *oh,
2054 unsigned int val = 0;
2056 if (likely(value != 0))
2057 val = min(fls(value - 1), OBD_HIST_MAX);
2059 lprocfs_oh_tally_pcpu(oh, val);
2061 EXPORT_SYMBOL(lprocfs_oh_tally_log2_pcpu);
2063 unsigned long lprocfs_oh_counter_pcpu(struct obd_hist_pcpu *oh,
2066 return percpu_counter_sum(&oh->oh_pc_buckets[value]);
2068 EXPORT_SYMBOL(lprocfs_oh_counter_pcpu);
2070 unsigned long lprocfs_oh_sum_pcpu(struct obd_hist_pcpu *oh)
2072 unsigned long ret = 0;
2075 for (i = 0; i < OBD_HIST_MAX; i++)
2076 ret += percpu_counter_sum(&oh->oh_pc_buckets[i]);
2080 EXPORT_SYMBOL(lprocfs_oh_sum_pcpu);
2082 int lprocfs_oh_alloc_pcpu(struct obd_hist_pcpu *oh)
2086 if (oh->oh_initialized)
2089 for (i = 0; i < OBD_HIST_MAX; i++) {
2090 rc = percpu_counter_init(&oh->oh_pc_buckets[i], 0, GFP_KERNEL);
2095 oh->oh_initialized = true;
2100 for (i--; i >= 0; i--)
2101 percpu_counter_destroy(&oh->oh_pc_buckets[i]);
2105 EXPORT_SYMBOL(lprocfs_oh_alloc_pcpu);
2107 void lprocfs_oh_clear_pcpu(struct obd_hist_pcpu *oh)
2111 for (i = 0; i < OBD_HIST_MAX; i++)
2112 percpu_counter_set(&oh->oh_pc_buckets[i], 0);
2114 EXPORT_SYMBOL(lprocfs_oh_clear_pcpu);
2116 void lprocfs_oh_release_pcpu(struct obd_hist_pcpu *oh)
2120 if (!oh->oh_initialized)
2123 for (i = 0; i < OBD_HIST_MAX; i++)
2124 percpu_counter_destroy(&oh->oh_pc_buckets[i]);
2126 oh->oh_initialized = false;
2128 EXPORT_SYMBOL(lprocfs_oh_release_pcpu);
2130 ssize_t lustre_attr_show(struct kobject *kobj,
2131 struct attribute *attr, char *buf)
2133 struct lustre_attr *a = container_of(attr, struct lustre_attr, attr);
2135 return a->show ? a->show(kobj, attr, buf) : 0;
2137 EXPORT_SYMBOL_GPL(lustre_attr_show);
2139 ssize_t lustre_attr_store(struct kobject *kobj, struct attribute *attr,
2140 const char *buf, size_t len)
2142 struct lustre_attr *a = container_of(attr, struct lustre_attr, attr);
2144 return a->store ? a->store(kobj, attr, buf, len) : len;
2146 EXPORT_SYMBOL_GPL(lustre_attr_store);
2148 const struct sysfs_ops lustre_sysfs_ops = {
2149 .show = lustre_attr_show,
2150 .store = lustre_attr_store,
2152 EXPORT_SYMBOL_GPL(lustre_sysfs_ops);
2154 int lprocfs_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *data)
2156 struct obd_device *obd = data;
2157 struct client_obd *cli = &obd->u.cli;
2159 spin_lock(&cli->cl_loi_list_lock);
2160 seq_printf(m, "%d\n", cli->cl_max_pages_per_rpc);
2161 spin_unlock(&cli->cl_loi_list_lock);
2164 EXPORT_SYMBOL(lprocfs_obd_max_pages_per_rpc_seq_show);
2166 ssize_t lprocfs_obd_max_pages_per_rpc_seq_write(struct file *file,
2167 const char __user *buffer,
2168 size_t count, loff_t *off)
2170 struct seq_file *m = file->private_data;
2171 struct obd_device *obd = m->private;
2172 struct client_obd *cli = &obd->u.cli;
2173 struct obd_import *imp;
2174 struct obd_connect_data *ocd;
2179 if (count > sizeof(kernbuf) - 1)
2182 if (copy_from_user(kernbuf, buffer, count))
2185 kernbuf[count] = '\0';
2187 rc = sysfs_memparse(kernbuf, count, &val, "B");
2191 /* if the max_pages is specified in bytes, convert to pages */
2192 if (val >= ONE_MB_BRW_SIZE)
2195 with_imp_locked(obd, imp, rc) {
2196 ocd = &imp->imp_connect_data;
2197 chunk_mask = ~((1 << (cli->cl_chunkbits - PAGE_SHIFT)) - 1);
2198 /* max_pages_per_rpc must be chunk aligned */
2199 val = (val + ~chunk_mask) & chunk_mask;
2200 if (val == 0 || (ocd->ocd_brw_size != 0 &&
2201 val > ocd->ocd_brw_size >> PAGE_SHIFT)) {
2204 spin_lock(&cli->cl_loi_list_lock);
2205 cli->cl_max_pages_per_rpc = val;
2206 client_adjust_max_dirty(cli);
2207 spin_unlock(&cli->cl_loi_list_lock);
2213 EXPORT_SYMBOL(lprocfs_obd_max_pages_per_rpc_seq_write);
2215 ssize_t short_io_bytes_show(struct kobject *kobj, struct attribute *attr,
2218 struct obd_device *obd = container_of(kobj, struct obd_device,
2220 struct client_obd *cli = &obd->u.cli;
2223 spin_lock(&cli->cl_loi_list_lock);
2224 rc = sprintf(buf, "%d\n", cli->cl_max_short_io_bytes);
2225 spin_unlock(&cli->cl_loi_list_lock);
2228 EXPORT_SYMBOL(short_io_bytes_show);
2230 /* Used to catch people who think they're specifying pages. */
2231 #define MIN_SHORT_IO_BYTES 64U
2233 ssize_t short_io_bytes_store(struct kobject *kobj, struct attribute *attr,
2234 const char *buffer, size_t count)
2236 struct obd_device *obd = container_of(kobj, struct obd_device,
2238 struct client_obd *cli = &obd->u.cli;
2242 if (strcmp(buffer, "-1") == 0) {
2243 val = OBD_DEF_SHORT_IO_BYTES;
2245 rc = sysfs_memparse(buffer, count, &val, "B");
2250 if (val && (val < MIN_SHORT_IO_BYTES || val > LNET_MTU))
2251 GOTO(out, rc = -ERANGE);
2255 spin_lock(&cli->cl_loi_list_lock);
2256 cli->cl_max_short_io_bytes = min_t(u64, val, OST_MAX_SHORT_IO_BYTES);
2257 spin_unlock(&cli->cl_loi_list_lock);
2262 EXPORT_SYMBOL(short_io_bytes_store);
2264 int lprocfs_wr_root_squash(const char __user *buffer, unsigned long count,
2265 struct root_squash_info *squash, char *name)
2268 char kernbuf[64], *tmp, *errmsg;
2269 unsigned long uid, gid;
2272 if (count >= sizeof(kernbuf)) {
2273 errmsg = "string too long";
2274 GOTO(failed_noprint, rc = -EINVAL);
2276 if (copy_from_user(kernbuf, buffer, count)) {
2277 errmsg = "bad address";
2278 GOTO(failed_noprint, rc = -EFAULT);
2280 kernbuf[count] = '\0';
2282 /* look for uid gid separator */
2283 tmp = strchr(kernbuf, ':');
2285 errmsg = "needs uid:gid format";
2286 GOTO(failed, rc = -EINVAL);
2292 if (kstrtoul(kernbuf, 0, &uid) != 0) {
2294 GOTO(failed, rc = -EINVAL);
2298 if (kstrtoul(tmp, 0, &gid) != 0) {
2300 GOTO(failed, rc = -EINVAL);
2303 squash->rsi_uid = uid;
2304 squash->rsi_gid = gid;
2306 LCONSOLE_INFO("%s: root_squash is set to %u:%u\n",
2307 name, squash->rsi_uid, squash->rsi_gid);
2315 CWARN("%s: failed to set root_squash to \"%s\", %s, rc = %d\n",
2316 name, kernbuf, errmsg, rc);
2319 CWARN("%s: failed to set root_squash due to %s, rc = %d\n",
2323 EXPORT_SYMBOL(lprocfs_wr_root_squash);
2326 int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count,
2327 struct root_squash_info *squash, char *name)
2330 char *kernbuf = NULL;
2337 errmsg = "string too long";
2338 GOTO(failed, rc = -EINVAL);
2341 OBD_ALLOC(kernbuf, count + 1);
2343 errmsg = "no memory";
2344 GOTO(failed, rc = -ENOMEM);
2346 if (copy_from_user(kernbuf, buffer, count)) {
2347 errmsg = "bad address";
2348 GOTO(failed, rc = -EFAULT);
2350 kernbuf[count] = '\0';
2352 if (count > 0 && kernbuf[count - 1] == '\n')
2355 if ((len == 4 && strncmp(kernbuf, "NONE", len) == 0) ||
2356 (len == 5 && strncmp(kernbuf, "clear", len) == 0)) {
2357 /* empty string is special case */
2358 spin_lock(&squash->rsi_lock);
2359 if (!list_empty(&squash->rsi_nosquash_nids))
2360 cfs_free_nidlist(&squash->rsi_nosquash_nids);
2361 spin_unlock(&squash->rsi_lock);
2362 LCONSOLE_INFO("%s: nosquash_nids is cleared\n", name);
2363 OBD_FREE(kernbuf, count + 1);
2367 if (cfs_parse_nidlist(kernbuf, &tmp) < 0) {
2368 errmsg = "can't parse";
2369 GOTO(failed, rc = -EINVAL);
2371 LCONSOLE_INFO("%s: nosquash_nids set to %s\n",
2373 OBD_FREE(kernbuf, count + 1);
2376 spin_lock(&squash->rsi_lock);
2377 if (!list_empty(&squash->rsi_nosquash_nids))
2378 cfs_free_nidlist(&squash->rsi_nosquash_nids);
2379 list_splice(&tmp, &squash->rsi_nosquash_nids);
2380 spin_unlock(&squash->rsi_lock);
2386 CWARN("%s: failed to set nosquash_nids to \"%s\", %s rc = %d\n",
2387 name, kernbuf, errmsg, rc);
2388 OBD_FREE(kernbuf, count + 1);
2390 CWARN("%s: failed to set nosquash_nids due to %s rc = %d\n",
2395 EXPORT_SYMBOL(lprocfs_wr_nosquash_nids);
2397 #endif /* CONFIG_PROC_FS*/