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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, 2014, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 #define DEBUG_SUBSYSTEM S_LLITE
38 #include <linux/version.h>
39 #include <lustre_param.h>
40 #include <lprocfs_status.h>
41 #include <obd_support.h>
43 #include "llite_internal.h"
44 #include "vvp_internal.h"
46 struct proc_dir_entry *proc_lustre_fs_root;
49 /* /proc/lustre/llite mount point registration */
50 static const struct file_operations ll_rw_extents_stats_fops;
51 static const struct file_operations ll_rw_extents_stats_pp_fops;
52 static const struct file_operations ll_rw_offset_stats_fops;
54 static int ll_blksize_seq_show(struct seq_file *m, void *v)
56 struct super_block *sb = m->private;
57 struct obd_statfs osfs;
61 rc = ll_statfs_internal(sb, &osfs,
62 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
65 rc = seq_printf(m, "%u\n", osfs.os_bsize);
68 LPROC_SEQ_FOPS_RO(ll_blksize);
70 static int ll_kbytestotal_seq_show(struct seq_file *m, void *v)
72 struct super_block *sb = m->private;
73 struct obd_statfs osfs;
77 rc = ll_statfs_internal(sb, &osfs,
78 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
81 __u32 blk_size = osfs.os_bsize >> 10;
82 __u64 result = osfs.os_blocks;
84 while (blk_size >>= 1)
87 rc = seq_printf(m, LPU64"\n", result);
91 LPROC_SEQ_FOPS_RO(ll_kbytestotal);
93 static int ll_kbytesfree_seq_show(struct seq_file *m, void *v)
95 struct super_block *sb = m->private;
96 struct obd_statfs osfs;
100 rc = ll_statfs_internal(sb, &osfs,
101 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
104 __u32 blk_size = osfs.os_bsize >> 10;
105 __u64 result = osfs.os_bfree;
107 while (blk_size >>= 1)
110 rc = seq_printf(m, LPU64"\n", result);
114 LPROC_SEQ_FOPS_RO(ll_kbytesfree);
116 static int ll_kbytesavail_seq_show(struct seq_file *m, void *v)
118 struct super_block *sb = m->private;
119 struct obd_statfs osfs;
123 rc = ll_statfs_internal(sb, &osfs,
124 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
127 __u32 blk_size = osfs.os_bsize >> 10;
128 __u64 result = osfs.os_bavail;
130 while (blk_size >>= 1)
133 rc = seq_printf(m, LPU64"\n", result);
137 LPROC_SEQ_FOPS_RO(ll_kbytesavail);
139 static int ll_filestotal_seq_show(struct seq_file *m, void *v)
141 struct super_block *sb = m->private;
142 struct obd_statfs osfs;
146 rc = ll_statfs_internal(sb, &osfs,
147 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
150 rc = seq_printf(m, LPU64"\n", osfs.os_files);
153 LPROC_SEQ_FOPS_RO(ll_filestotal);
155 static int ll_filesfree_seq_show(struct seq_file *m, void *v)
157 struct super_block *sb = m->private;
158 struct obd_statfs osfs;
162 rc = ll_statfs_internal(sb, &osfs,
163 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
166 rc = seq_printf(m, LPU64"\n", osfs.os_ffree);
169 LPROC_SEQ_FOPS_RO(ll_filesfree);
171 static int ll_client_type_seq_show(struct seq_file *m, void *v)
173 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
176 LASSERT(sbi != NULL);
178 if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
179 rc = seq_printf(m, "remote client\n");
181 rc = seq_printf(m, "local client\n");
184 LPROC_SEQ_FOPS_RO(ll_client_type);
186 static int ll_fstype_seq_show(struct seq_file *m, void *v)
188 struct super_block *sb = m->private;
191 return seq_printf(m, "%s\n", sb->s_type->name);
193 LPROC_SEQ_FOPS_RO(ll_fstype);
195 static int ll_sb_uuid_seq_show(struct seq_file *m, void *v)
197 struct super_block *sb = m->private;
200 return seq_printf(m, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
202 LPROC_SEQ_FOPS_RO(ll_sb_uuid);
204 static int ll_xattr_cache_seq_show(struct seq_file *m, void *v)
206 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
208 return seq_printf(m, "%u\n", sbi->ll_xattr_cache_enabled);
211 static ssize_t ll_xattr_cache_seq_write(struct file *file,
212 const char __user *buffer,
213 size_t count, loff_t *off)
215 struct seq_file *m = file->private_data;
216 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
219 rc = lprocfs_write_helper(buffer, count, &val);
223 if (val != 0 && val != 1)
226 if (val == 1 && !(sbi->ll_flags & LL_SBI_XATTR_CACHE))
229 sbi->ll_xattr_cache_enabled = val;
233 LPROC_SEQ_FOPS(ll_xattr_cache);
235 static int ll_site_stats_seq_show(struct seq_file *m, void *v)
237 struct super_block *sb = m->private;
240 * See description of statistical counters in struct cl_site, and
243 return cl_site_stats_print(lu2cl_site(ll_s2sbi(sb)->ll_site), m);
245 LPROC_SEQ_FOPS_RO(ll_site_stats);
247 static int ll_max_readahead_mb_seq_show(struct seq_file *m, void *v)
249 struct super_block *sb = m->private;
250 struct ll_sb_info *sbi = ll_s2sbi(sb);
254 spin_lock(&sbi->ll_lock);
255 pages_number = sbi->ll_ra_info.ra_max_pages;
256 spin_unlock(&sbi->ll_lock);
258 mult = 1 << (20 - PAGE_CACHE_SHIFT);
259 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
263 ll_max_readahead_mb_seq_write(struct file *file, const char __user *buffer,
264 size_t count, loff_t *off)
266 struct seq_file *m = file->private_data;
267 struct super_block *sb = m->private;
268 struct ll_sb_info *sbi = ll_s2sbi(sb);
274 pages_shift = 20 - PAGE_CACHE_SHIFT;
275 rc = lprocfs_write_frac_u64_helper(buffer, count, &val,
282 pages_number = (long)val;
284 if (pages_number < 0 || pages_number > totalram_pages / 2) {
286 CERROR("%s: can't set max_readahead_mb=%lu > %luMB\n",
287 ll_get_fsname(sb, NULL, 0), pages_number >> pages_shift,
288 totalram_pages >> (pages_shift + 1));
292 spin_lock(&sbi->ll_lock);
293 sbi->ll_ra_info.ra_max_pages = pages_number;
294 spin_unlock(&sbi->ll_lock);
297 LPROC_SEQ_FOPS(ll_max_readahead_mb);
299 static int ll_max_readahead_per_file_mb_seq_show(struct seq_file *m, void *v)
301 struct super_block *sb = m->private;
302 struct ll_sb_info *sbi = ll_s2sbi(sb);
306 spin_lock(&sbi->ll_lock);
307 pages_number = sbi->ll_ra_info.ra_max_pages_per_file;
308 spin_unlock(&sbi->ll_lock);
310 mult = 1 << (20 - PAGE_CACHE_SHIFT);
311 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
315 ll_max_readahead_per_file_mb_seq_write(struct file *file,
316 const char __user *buffer,
317 size_t count, loff_t *off)
319 struct seq_file *m = file->private_data;
320 struct super_block *sb = m->private;
321 struct ll_sb_info *sbi = ll_s2sbi(sb);
322 int pages_shift, rc, pages_number;
324 pages_shift = 20 - PAGE_CACHE_SHIFT;
325 rc = lprocfs_write_frac_helper(buffer, count, &pages_number,
330 if (pages_number < 0 || pages_number > sbi->ll_ra_info.ra_max_pages) {
331 CERROR("%s: can't set max_readahead_per_file_mb=%u > "
332 "max_read_ahead_mb=%lu\n", ll_get_fsname(sb, NULL, 0),
333 pages_number >> pages_shift,
334 sbi->ll_ra_info.ra_max_pages >> pages_shift);
338 spin_lock(&sbi->ll_lock);
339 sbi->ll_ra_info.ra_max_pages_per_file = pages_number;
340 spin_unlock(&sbi->ll_lock);
343 LPROC_SEQ_FOPS(ll_max_readahead_per_file_mb);
345 static int ll_max_read_ahead_whole_mb_seq_show(struct seq_file *m, void *v)
347 struct super_block *sb = m->private;
348 struct ll_sb_info *sbi = ll_s2sbi(sb);
352 spin_lock(&sbi->ll_lock);
353 pages_number = sbi->ll_ra_info.ra_max_read_ahead_whole_pages;
354 spin_unlock(&sbi->ll_lock);
356 mult = 1 << (20 - PAGE_CACHE_SHIFT);
357 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
361 ll_max_read_ahead_whole_mb_seq_write(struct file *file,
362 const char __user *buffer,
363 size_t count, loff_t *off)
365 struct seq_file *m = file->private_data;
366 struct super_block *sb = m->private;
367 struct ll_sb_info *sbi = ll_s2sbi(sb);
368 int pages_shift, rc, pages_number;
370 pages_shift = 20 - PAGE_CACHE_SHIFT;
371 rc = lprocfs_write_frac_helper(buffer, count, &pages_number,
376 /* Cap this at the current max readahead window size, the readahead
377 * algorithm does this anyway so it's pointless to set it larger. */
378 if (pages_number < 0 ||
379 pages_number > sbi->ll_ra_info.ra_max_pages_per_file) {
380 CERROR("%s: can't set max_read_ahead_whole_mb=%u > "
381 "max_read_ahead_per_file_mb=%lu\n",
382 ll_get_fsname(sb, NULL, 0),
383 pages_number >> pages_shift,
384 sbi->ll_ra_info.ra_max_pages_per_file >> pages_shift);
388 spin_lock(&sbi->ll_lock);
389 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = pages_number;
390 spin_unlock(&sbi->ll_lock);
393 LPROC_SEQ_FOPS(ll_max_read_ahead_whole_mb);
395 static int ll_max_cached_mb_seq_show(struct seq_file *m, void *v)
397 struct super_block *sb = m->private;
398 struct ll_sb_info *sbi = ll_s2sbi(sb);
399 struct cl_client_cache *cache = sbi->ll_cache;
400 int shift = 20 - PAGE_CACHE_SHIFT;
404 max_cached_mb = cache->ccc_lru_max >> shift;
405 unused_mb = atomic_long_read(&cache->ccc_lru_left) >> shift;
408 "max_cached_mb: %ld\n"
411 "reclaim_count: %u\n",
412 atomic_read(&cache->ccc_users),
414 max_cached_mb - unused_mb,
416 cache->ccc_lru_shrinkers);
420 ll_max_cached_mb_seq_write(struct file *file, const char __user *buffer,
421 size_t count, loff_t *off)
423 struct seq_file *m = file->private_data;
424 struct super_block *sb = m->private;
425 struct ll_sb_info *sbi = ll_s2sbi(sb);
426 struct cl_client_cache *cache = sbi->ll_cache;
438 if (count >= sizeof(kernbuf))
441 if (copy_from_user(kernbuf, buffer, count))
445 mult = 1 << (20 - PAGE_CACHE_SHIFT);
446 buffer += lprocfs_find_named_value(kernbuf, "max_cached_mb:", &count) -
448 rc = lprocfs_write_frac_u64_helper(buffer, count, &val, mult);
454 pages_number = (long)val;
456 if (pages_number < 0 || pages_number > totalram_pages) {
457 CERROR("%s: can't set max cache more than %lu MB\n",
458 ll_get_fsname(sb, NULL, 0),
459 totalram_pages >> (20 - PAGE_CACHE_SHIFT));
462 /* Allow enough cache so clients can make well-formed RPCs */
463 pages_number = max_t(long, pages_number, PTLRPC_MAX_BRW_PAGES);
465 spin_lock(&sbi->ll_lock);
466 diff = pages_number - cache->ccc_lru_max;
467 spin_unlock(&sbi->ll_lock);
469 /* easy - add more LRU slots. */
471 atomic_long_add(diff, &cache->ccc_lru_left);
475 env = cl_env_get(&refcheck);
483 /* reduce LRU budget from free slots. */
487 ov = atomic_long_read(&cache->ccc_lru_left);
491 nv = ov > diff ? ov - diff : 0;
492 rc = atomic_long_cmpxchg(&cache->ccc_lru_left, ov, nv);
493 if (likely(ov == rc)) {
503 if (sbi->ll_dt_exp == NULL) { /* being initialized */
508 /* difficult - have to ask OSCs to drop LRU slots. */
510 rc = obd_set_info_async(env, sbi->ll_dt_exp,
511 sizeof(KEY_CACHE_LRU_SHRINK),
512 KEY_CACHE_LRU_SHRINK,
513 sizeof(tmp), &tmp, NULL);
517 cl_env_put(env, &refcheck);
521 spin_lock(&sbi->ll_lock);
522 cache->ccc_lru_max = pages_number;
523 spin_unlock(&sbi->ll_lock);
526 atomic_long_add(nrpages, &cache->ccc_lru_left);
530 LPROC_SEQ_FOPS(ll_max_cached_mb);
532 static int ll_checksum_seq_show(struct seq_file *m, void *v)
534 struct super_block *sb = m->private;
535 struct ll_sb_info *sbi = ll_s2sbi(sb);
537 return seq_printf(m, "%u\n", (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0);
540 static ssize_t ll_checksum_seq_write(struct file *file,
541 const char __user *buffer,
542 size_t count, loff_t *off)
544 struct seq_file *m = file->private_data;
545 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
552 rc = lprocfs_write_helper(buffer, count, &val);
556 sbi->ll_flags |= LL_SBI_CHECKSUM;
558 sbi->ll_flags &= ~LL_SBI_CHECKSUM;
560 rc = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
561 KEY_CHECKSUM, sizeof(val), &val, NULL);
563 CWARN("Failed to set OSC checksum flags: %d\n", rc);
567 LPROC_SEQ_FOPS(ll_checksum);
569 static int ll_max_rw_chunk_seq_show(struct seq_file *m, void *v)
571 struct super_block *sb = m->private;
573 return seq_printf(m, "%lu\n", ll_s2sbi(sb)->ll_max_rw_chunk);
576 static ssize_t ll_max_rw_chunk_seq_write(struct file *file,
577 const char __user *buffer,
578 size_t count, loff_t *off)
580 struct seq_file *m = file->private_data;
581 struct super_block *sb = m->private;
584 rc = lprocfs_write_helper(buffer, count, &val);
587 ll_s2sbi(sb)->ll_max_rw_chunk = val;
590 LPROC_SEQ_FOPS(ll_max_rw_chunk);
592 static int ll_rd_track_id(struct seq_file *m, enum stats_track_type type)
594 struct super_block *sb = m->private;
596 if (ll_s2sbi(sb)->ll_stats_track_type == type) {
597 return seq_printf(m, "%d\n",
598 ll_s2sbi(sb)->ll_stats_track_id);
599 } else if (ll_s2sbi(sb)->ll_stats_track_type == STATS_TRACK_ALL) {
600 return seq_printf(m, "0 (all)\n");
602 return seq_printf(m, "untracked\n");
606 static int ll_wr_track_id(const char __user *buffer, unsigned long count,
607 void *data, enum stats_track_type type)
609 struct super_block *sb = data;
612 rc = lprocfs_write_helper(buffer, count, &pid);
615 ll_s2sbi(sb)->ll_stats_track_id = pid;
617 ll_s2sbi(sb)->ll_stats_track_type = STATS_TRACK_ALL;
619 ll_s2sbi(sb)->ll_stats_track_type = type;
620 lprocfs_clear_stats(ll_s2sbi(sb)->ll_stats);
624 static int ll_track_pid_seq_show(struct seq_file *m, void *v)
626 return ll_rd_track_id(m, STATS_TRACK_PID);
629 static ssize_t ll_track_pid_seq_write(struct file *file,
630 const char __user *buffer,
631 size_t count, loff_t *off)
633 struct seq_file *seq = file->private_data;
634 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PID);
636 LPROC_SEQ_FOPS(ll_track_pid);
638 static int ll_track_ppid_seq_show(struct seq_file *m, void *v)
640 return ll_rd_track_id(m, STATS_TRACK_PPID);
643 static ssize_t ll_track_ppid_seq_write(struct file *file,
644 const char __user *buffer,
645 size_t count, loff_t *off)
647 struct seq_file *seq = file->private_data;
648 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PPID);
650 LPROC_SEQ_FOPS(ll_track_ppid);
652 static int ll_track_gid_seq_show(struct seq_file *m, void *v)
654 return ll_rd_track_id(m, STATS_TRACK_GID);
657 static ssize_t ll_track_gid_seq_write(struct file *file,
658 const char __user *buffer,
659 size_t count, loff_t *off)
661 struct seq_file *seq = file->private_data;
662 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_GID);
664 LPROC_SEQ_FOPS(ll_track_gid);
666 static int ll_statahead_max_seq_show(struct seq_file *m, void *v)
668 struct super_block *sb = m->private;
669 struct ll_sb_info *sbi = ll_s2sbi(sb);
671 return seq_printf(m, "%u\n", sbi->ll_sa_max);
674 static ssize_t ll_statahead_max_seq_write(struct file *file,
675 const char __user *buffer,
676 size_t count, loff_t *off)
678 struct seq_file *m = file->private_data;
679 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
682 rc = lprocfs_write_helper(buffer, count, &val);
686 if (val >= 0 && val <= LL_SA_RPC_MAX)
687 sbi->ll_sa_max = val;
689 CERROR("Bad statahead_max value %d. Valid values are in the "
690 "range [0, %d]\n", val, LL_SA_RPC_MAX);
694 LPROC_SEQ_FOPS(ll_statahead_max);
696 static int ll_statahead_agl_seq_show(struct seq_file *m, void *v)
698 struct super_block *sb = m->private;
699 struct ll_sb_info *sbi = ll_s2sbi(sb);
701 return seq_printf(m, "%u\n",
702 sbi->ll_flags & LL_SBI_AGL_ENABLED ? 1 : 0);
705 static ssize_t ll_statahead_agl_seq_write(struct file *file,
706 const char __user *buffer,
707 size_t count, loff_t *off)
709 struct seq_file *m = file->private_data;
710 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
713 rc = lprocfs_write_helper(buffer, count, &val);
718 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
720 sbi->ll_flags &= ~LL_SBI_AGL_ENABLED;
724 LPROC_SEQ_FOPS(ll_statahead_agl);
726 static int ll_statahead_stats_seq_show(struct seq_file *m, void *v)
728 struct super_block *sb = m->private;
729 struct ll_sb_info *sbi = ll_s2sbi(sb);
732 "statahead total: %u\n"
733 "statahead wrong: %u\n"
735 atomic_read(&sbi->ll_sa_total),
736 atomic_read(&sbi->ll_sa_wrong),
737 atomic_read(&sbi->ll_agl_total));
739 LPROC_SEQ_FOPS_RO(ll_statahead_stats);
741 static int ll_lazystatfs_seq_show(struct seq_file *m, void *v)
743 struct super_block *sb = m->private;
744 struct ll_sb_info *sbi = ll_s2sbi(sb);
746 return seq_printf(m, "%u\n",
747 (sbi->ll_flags & LL_SBI_LAZYSTATFS) ? 1 : 0);
750 static ssize_t ll_lazystatfs_seq_write(struct file *file,
751 const char __user *buffer,
752 size_t count, loff_t *off)
754 struct seq_file *m = file->private_data;
755 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
758 rc = lprocfs_write_helper(buffer, count, &val);
763 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
765 sbi->ll_flags &= ~LL_SBI_LAZYSTATFS;
769 LPROC_SEQ_FOPS(ll_lazystatfs);
771 static int ll_max_easize_seq_show(struct seq_file *m, void *v)
773 struct super_block *sb = m->private;
774 struct ll_sb_info *sbi = ll_s2sbi(sb);
778 rc = ll_get_max_mdsize(sbi, &ealen);
782 return seq_printf(m, "%u\n", ealen);
784 LPROC_SEQ_FOPS_RO(ll_max_easize);
787 * Get default_easize.
789 * \see client_obd::cl_default_mds_easize
791 * \param[in] m seq_file handle
792 * \param[in] v unused for single entry
794 * \retval 0 on success
795 * \retval negative negated errno on failure
797 static int ll_default_easize_seq_show(struct seq_file *m, void *v)
799 struct super_block *sb = m->private;
800 struct ll_sb_info *sbi = ll_s2sbi(sb);
804 rc = ll_get_default_mdsize(sbi, &ealen);
808 return seq_printf(m, "%u\n", ealen);
812 * Set default_easize.
814 * Range checking on the passed value is handled by
815 * ll_set_default_mdsize().
817 * \see client_obd::cl_default_mds_easize
819 * \param[in] file proc file
820 * \param[in] buffer string passed from user space
821 * \param[in] count \a buffer length
822 * \param[in] off unused for single entry
824 * \retval positive \a count on success
825 * \retval negative negated errno on failure
827 static ssize_t ll_default_easize_seq_write(struct file *file,
828 const char __user *buffer,
829 size_t count, loff_t *unused)
831 struct seq_file *seq = file->private_data;
832 struct super_block *sb = (struct super_block *)seq->private;
833 struct ll_sb_info *sbi = ll_s2sbi(sb);
840 rc = lprocfs_write_helper(buffer, count, &val);
844 rc = ll_set_default_mdsize(sbi, val);
850 LPROC_SEQ_FOPS(ll_default_easize);
852 static int ll_max_cookiesize_seq_show(struct seq_file *m, void *v)
854 struct super_block *sb = m->private;
855 struct ll_sb_info *sbi = ll_s2sbi(sb);
856 unsigned int cookielen;
859 rc = ll_get_max_cookiesize(sbi, &cookielen);
863 return seq_printf(m, "%u\n", cookielen);
865 LPROC_SEQ_FOPS_RO(ll_max_cookiesize);
867 static int ll_default_cookiesize_seq_show(struct seq_file *m, void *v)
869 struct super_block *sb = m->private;
870 struct ll_sb_info *sbi = ll_s2sbi(sb);
871 unsigned int cookielen;
874 rc = ll_get_default_cookiesize(sbi, &cookielen);
878 return seq_printf(m, "%u\n", cookielen);
880 LPROC_SEQ_FOPS_RO(ll_default_cookiesize);
882 static int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
884 const char *str[] = LL_SBI_FLAGS;
885 struct super_block *sb = m->private;
886 int flags = ll_s2sbi(sb)->ll_flags;
890 if (ARRAY_SIZE(str) <= i) {
891 CERROR("%s: Revise array LL_SBI_FLAGS to match sbi "
892 "flags please.\n", ll_get_fsname(sb, NULL, 0));
897 seq_printf(m, "%s ", str[i]);
901 seq_printf(m, "\b\n");
904 LPROC_SEQ_FOPS_RO(ll_sbi_flags);
906 static int ll_unstable_stats_seq_show(struct seq_file *m, void *v)
908 struct super_block *sb = m->private;
909 struct ll_sb_info *sbi = ll_s2sbi(sb);
910 struct cl_client_cache *cache = sbi->ll_cache;
914 pages = atomic_long_read(&cache->ccc_unstable_nr);
915 mb = (pages * PAGE_CACHE_SIZE) >> 20;
917 return seq_printf(m, "unstable_check: %8d\n"
918 "unstable_pages: %12ld\n"
919 "unstable_mb: %8d\n",
920 cache->ccc_unstable_check, pages, mb);
923 static ssize_t ll_unstable_stats_seq_write(struct file *file,
924 const char __user *buffer,
925 size_t count, loff_t *unused)
927 struct seq_file *seq = file->private_data;
928 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)seq->private);
934 if (count >= sizeof(kernbuf))
937 if (copy_from_user(kernbuf, buffer, count))
941 buffer += lprocfs_find_named_value(kernbuf, "unstable_check:", &count) -
943 rc = lprocfs_write_helper(buffer, count, &val);
947 /* borrow lru lock to set the value */
948 spin_lock(&sbi->ll_cache->ccc_lru_lock);
949 sbi->ll_cache->ccc_unstable_check = !!val;
950 spin_unlock(&sbi->ll_cache->ccc_lru_lock);
954 LPROC_SEQ_FOPS(ll_unstable_stats);
956 static int ll_root_squash_seq_show(struct seq_file *m, void *v)
958 struct super_block *sb = m->private;
959 struct ll_sb_info *sbi = ll_s2sbi(sb);
960 struct root_squash_info *squash = &sbi->ll_squash;
962 return seq_printf(m, "%u:%u\n", squash->rsi_uid, squash->rsi_gid);
965 static ssize_t ll_root_squash_seq_write(struct file *file,
966 const char __user *buffer,
967 size_t count, loff_t *off)
969 struct seq_file *m = file->private_data;
970 struct super_block *sb = m->private;
971 struct ll_sb_info *sbi = ll_s2sbi(sb);
972 struct root_squash_info *squash = &sbi->ll_squash;
974 return lprocfs_wr_root_squash(buffer, count, squash,
975 ll_get_fsname(sb, NULL, 0));
977 LPROC_SEQ_FOPS(ll_root_squash);
979 static int ll_nosquash_nids_seq_show(struct seq_file *m, void *v)
981 struct super_block *sb = m->private;
982 struct ll_sb_info *sbi = ll_s2sbi(sb);
983 struct root_squash_info *squash = &sbi->ll_squash;
986 down_read(&squash->rsi_sem);
987 if (!list_empty(&squash->rsi_nosquash_nids)) {
988 len = cfs_print_nidlist(m->buf + m->count, m->size - m->count,
989 &squash->rsi_nosquash_nids);
991 rc = seq_printf(m, "\n");
993 rc = seq_printf(m, "NONE\n");
995 up_read(&squash->rsi_sem);
1000 static ssize_t ll_nosquash_nids_seq_write(struct file *file,
1001 const char __user *buffer,
1002 size_t count, loff_t *off)
1004 struct seq_file *m = file->private_data;
1005 struct super_block *sb = m->private;
1006 struct ll_sb_info *sbi = ll_s2sbi(sb);
1007 struct root_squash_info *squash = &sbi->ll_squash;
1010 rc = lprocfs_wr_nosquash_nids(buffer, count, squash,
1011 ll_get_fsname(sb, NULL, 0));
1015 ll_compute_rootsquash_state(sbi);
1019 LPROC_SEQ_FOPS(ll_nosquash_nids);
1021 struct lprocfs_vars lprocfs_llite_obd_vars[] = {
1023 .fops = &ll_sb_uuid_fops },
1025 .fops = &ll_fstype_fops },
1027 .fops = &ll_site_stats_fops },
1028 { .name = "blocksize",
1029 .fops = &ll_blksize_fops },
1030 { .name = "kbytestotal",
1031 .fops = &ll_kbytestotal_fops },
1032 { .name = "kbytesfree",
1033 .fops = &ll_kbytesfree_fops },
1034 { .name = "kbytesavail",
1035 .fops = &ll_kbytesavail_fops },
1036 { .name = "filestotal",
1037 .fops = &ll_filestotal_fops },
1038 { .name = "filesfree",
1039 .fops = &ll_filesfree_fops },
1040 { .name = "client_type",
1041 .fops = &ll_client_type_fops },
1042 { .name = "max_read_ahead_mb",
1043 .fops = &ll_max_readahead_mb_fops },
1044 { .name = "max_read_ahead_per_file_mb",
1045 .fops = &ll_max_readahead_per_file_mb_fops },
1046 { .name = "max_read_ahead_whole_mb",
1047 .fops = &ll_max_read_ahead_whole_mb_fops },
1048 { .name = "max_cached_mb",
1049 .fops = &ll_max_cached_mb_fops },
1050 { .name = "checksum_pages",
1051 .fops = &ll_checksum_fops },
1052 { .name = "max_rw_chunk",
1053 .fops = &ll_max_rw_chunk_fops },
1054 { .name = "stats_track_pid",
1055 .fops = &ll_track_pid_fops },
1056 { .name = "stats_track_ppid",
1057 .fops = &ll_track_ppid_fops },
1058 { .name = "stats_track_gid",
1059 .fops = &ll_track_gid_fops },
1060 { .name = "statahead_max",
1061 .fops = &ll_statahead_max_fops },
1062 { .name = "statahead_agl",
1063 .fops = &ll_statahead_agl_fops },
1064 { .name = "statahead_stats",
1065 .fops = &ll_statahead_stats_fops },
1066 { .name = "lazystatfs",
1067 .fops = &ll_lazystatfs_fops },
1068 { .name = "max_easize",
1069 .fops = &ll_max_easize_fops },
1070 { .name = "default_easize",
1071 .fops = &ll_default_easize_fops },
1072 { .name = "max_cookiesize",
1073 .fops = &ll_max_cookiesize_fops },
1074 { .name = "default_cookiesize",
1075 .fops = &ll_default_cookiesize_fops },
1076 { .name = "sbi_flags",
1077 .fops = &ll_sbi_flags_fops },
1078 { .name = "xattr_cache",
1079 .fops = &ll_xattr_cache_fops },
1080 { .name = "unstable_stats",
1081 .fops = &ll_unstable_stats_fops },
1082 { .name = "root_squash",
1083 .fops = &ll_root_squash_fops },
1084 { .name = "nosquash_nids",
1085 .fops = &ll_nosquash_nids_fops },
1089 #define MAX_STRING_SIZE 128
1091 static const struct llite_file_opcode {
1095 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
1096 /* file operation */
1097 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
1098 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
1099 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1101 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1103 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
1105 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
1107 { LPROC_LL_OSC_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1109 { LPROC_LL_OSC_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1111 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
1112 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
1113 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
1114 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
1115 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
1116 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
1117 { LPROC_LL_READDIR, LPROCFS_TYPE_REGS, "readdir" },
1118 /* inode operation */
1119 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
1120 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "truncate" },
1121 { LPROC_LL_FLOCK, LPROCFS_TYPE_REGS, "flock" },
1122 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
1123 /* dir inode operation */
1124 { LPROC_LL_CREATE, LPROCFS_TYPE_REGS, "create" },
1125 { LPROC_LL_LINK, LPROCFS_TYPE_REGS, "link" },
1126 { LPROC_LL_UNLINK, LPROCFS_TYPE_REGS, "unlink" },
1127 { LPROC_LL_SYMLINK, LPROCFS_TYPE_REGS, "symlink" },
1128 { LPROC_LL_MKDIR, LPROCFS_TYPE_REGS, "mkdir" },
1129 { LPROC_LL_RMDIR, LPROCFS_TYPE_REGS, "rmdir" },
1130 { LPROC_LL_MKNOD, LPROCFS_TYPE_REGS, "mknod" },
1131 { LPROC_LL_RENAME, LPROCFS_TYPE_REGS, "rename" },
1132 /* special inode operation */
1133 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
1134 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
1135 { LPROC_LL_SETXATTR, LPROCFS_TYPE_REGS, "setxattr" },
1136 { LPROC_LL_GETXATTR, LPROCFS_TYPE_REGS, "getxattr" },
1137 { LPROC_LL_GETXATTR_HITS, LPROCFS_TYPE_REGS, "getxattr_hits" },
1138 { LPROC_LL_LISTXATTR, LPROCFS_TYPE_REGS, "listxattr" },
1139 { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_REGS, "removexattr" },
1140 { LPROC_LL_INODE_PERM, LPROCFS_TYPE_REGS, "inode_permission" },
1143 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
1147 if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
1148 lprocfs_counter_add(sbi->ll_stats, op, count);
1149 else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
1150 sbi->ll_stats_track_id == current->pid)
1151 lprocfs_counter_add(sbi->ll_stats, op, count);
1152 else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
1153 sbi->ll_stats_track_id == current->parent->pid)
1154 lprocfs_counter_add(sbi->ll_stats, op, count);
1155 else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
1156 sbi->ll_stats_track_id ==
1157 from_kgid(&init_user_ns, current_gid()))
1158 lprocfs_counter_add(sbi->ll_stats, op, count);
1160 EXPORT_SYMBOL(ll_stats_ops_tally);
1162 static const char *ra_stat_string[] = {
1163 [RA_STAT_HIT] = "hits",
1164 [RA_STAT_MISS] = "misses",
1165 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
1166 [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
1167 [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page",
1168 [RA_STAT_FAILED_MATCH] = "failed lock match",
1169 [RA_STAT_DISCARDED] = "read but discarded",
1170 [RA_STAT_ZERO_LEN] = "zero length file",
1171 [RA_STAT_ZERO_WINDOW] = "zero size window",
1172 [RA_STAT_EOF] = "read-ahead to EOF",
1173 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
1174 [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",
1175 [RA_STAT_FAILED_REACH_END] = "failed to reach end"
1178 LPROC_SEQ_FOPS_RO_TYPE(llite, name);
1179 LPROC_SEQ_FOPS_RO_TYPE(llite, uuid);
1181 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
1182 struct super_block *sb, char *osc, char *mdc)
1184 struct lprocfs_vars lvars[2];
1185 struct lustre_sb_info *lsi = s2lsi(sb);
1186 struct ll_sb_info *sbi = ll_s2sbi(sb);
1187 struct obd_device *obd;
1188 struct proc_dir_entry *dir;
1189 char name[MAX_STRING_SIZE + 1], *ptr;
1190 int err, id, len, rc;
1193 memset(lvars, 0, sizeof(lvars));
1195 name[MAX_STRING_SIZE] = '\0';
1196 lvars[0].name = name;
1198 LASSERT(sbi != NULL);
1199 LASSERT(mdc != NULL);
1200 LASSERT(osc != NULL);
1203 len = strlen(lsi->lsi_lmd->lmd_profile);
1204 ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
1205 if (ptr && (strcmp(ptr, "-client") == 0))
1209 snprintf(name, MAX_STRING_SIZE, "%.*s-%p", len,
1210 lsi->lsi_lmd->lmd_profile, sb);
1212 sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
1213 if (IS_ERR(sbi->ll_proc_root)) {
1214 err = PTR_ERR(sbi->ll_proc_root);
1215 sbi->ll_proc_root = NULL;
1219 rc = lprocfs_seq_create(sbi->ll_proc_root, "dump_page_cache", 0444,
1220 &vvp_dump_pgcache_file_ops, sbi);
1222 CWARN("Error adding the dump_page_cache file\n");
1224 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats", 0644,
1225 &ll_rw_extents_stats_fops, sbi);
1227 CWARN("Error adding the extent_stats file\n");
1229 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats_per_process",
1230 0644, &ll_rw_extents_stats_pp_fops, sbi);
1232 CWARN("Error adding the extents_stats_per_process file\n");
1234 rc = lprocfs_seq_create(sbi->ll_proc_root, "offset_stats", 0644,
1235 &ll_rw_offset_stats_fops, sbi);
1237 CWARN("Error adding the offset_stats file\n");
1239 /* File operations stats */
1240 sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
1241 LPROCFS_STATS_FLAG_NONE);
1242 if (sbi->ll_stats == NULL)
1243 GOTO(out, err = -ENOMEM);
1244 /* do counter init */
1245 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
1246 __u32 type = llite_opcode_table[id].type;
1248 if (type & LPROCFS_TYPE_REGS)
1250 else if (type & LPROCFS_TYPE_BYTES)
1252 else if (type & LPROCFS_TYPE_PAGES)
1254 lprocfs_counter_init(sbi->ll_stats,
1255 llite_opcode_table[id].opcode,
1256 (type & LPROCFS_CNTR_AVGMINMAX),
1257 llite_opcode_table[id].opname, ptr);
1259 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats);
1263 sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
1264 LPROCFS_STATS_FLAG_NONE);
1265 if (sbi->ll_ra_stats == NULL)
1266 GOTO(out, err = -ENOMEM);
1268 for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
1269 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
1270 ra_stat_string[id], "pages");
1271 err = lprocfs_register_stats(sbi->ll_proc_root, "read_ahead_stats",
1277 err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_llite_obd_vars, sb);
1282 obd = class_name2obd(mdc);
1284 LASSERT(obd != NULL);
1285 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1286 LASSERT(obd->obd_type->typ_name != NULL);
1288 dir = proc_mkdir(obd->obd_type->typ_name, sbi->ll_proc_root);
1290 GOTO(out, err = -ENOMEM);
1292 snprintf(name, MAX_STRING_SIZE, "common_name");
1293 lvars[0].fops = &llite_name_fops;
1294 err = lprocfs_add_vars(dir, lvars, obd);
1298 snprintf(name, MAX_STRING_SIZE, "uuid");
1299 lvars[0].fops = &llite_uuid_fops;
1300 err = lprocfs_add_vars(dir, lvars, obd);
1305 obd = class_name2obd(osc);
1307 LASSERT(obd != NULL);
1308 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1309 LASSERT(obd->obd_type->typ_name != NULL);
1311 dir = proc_mkdir(obd->obd_type->typ_name, sbi->ll_proc_root);
1313 GOTO(out, err = -ENOMEM);
1315 snprintf(name, MAX_STRING_SIZE, "common_name");
1316 lvars[0].fops = &llite_name_fops;
1317 err = lprocfs_add_vars(dir, lvars, obd);
1321 snprintf(name, MAX_STRING_SIZE, "uuid");
1322 lvars[0].fops = &llite_uuid_fops;
1323 err = lprocfs_add_vars(dir, lvars, obd);
1326 lprocfs_remove(&sbi->ll_proc_root);
1327 lprocfs_free_stats(&sbi->ll_ra_stats);
1328 lprocfs_free_stats(&sbi->ll_stats);
1333 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
1335 if (sbi->ll_proc_root) {
1336 lprocfs_remove(&sbi->ll_proc_root);
1337 lprocfs_free_stats(&sbi->ll_ra_stats);
1338 lprocfs_free_stats(&sbi->ll_stats);
1341 #undef MAX_STRING_SIZE
1343 #define pct(a,b) (b ? a * 100 / b : 0)
1345 static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
1346 struct seq_file *seq, int which)
1348 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
1349 unsigned long start, end, r, w;
1350 char *unitp = "KMGTPEZY";
1352 struct per_process_info *pp_info = &io_extents->pp_extents[which];
1358 for(i = 0; i < LL_HIST_MAX; i++) {
1359 read_tot += pp_info->pp_r_hist.oh_buckets[i];
1360 write_tot += pp_info->pp_w_hist.oh_buckets[i];
1363 for(i = 0; i < LL_HIST_MAX; i++) {
1364 r = pp_info->pp_r_hist.oh_buckets[i];
1365 w = pp_info->pp_w_hist.oh_buckets[i];
1368 end = 1 << (i + LL_HIST_START - units);
1369 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu | "
1370 "%14lu %4lu %4lu\n", start, *unitp, end, *unitp,
1371 (i == LL_HIST_MAX - 1) ? '+' : ' ',
1372 r, pct(r, read_tot), pct(read_cum, read_tot),
1373 w, pct(w, write_tot), pct(write_cum, write_tot));
1375 if (start == 1<<10) {
1380 if (read_cum == read_tot && write_cum == write_tot)
1385 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
1388 struct ll_sb_info *sbi = seq->private;
1389 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1392 do_gettimeofday(&now);
1394 if (!sbi->ll_rw_stats_on) {
1395 seq_printf(seq, "disabled\n"
1396 "write anything in this file to activate, "
1397 "then 0 or \"[D/d]isabled\" to deactivate\n");
1400 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1401 now.tv_sec, now.tv_usec);
1402 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1403 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1404 "extents", "calls", "%", "cum%",
1405 "calls", "%", "cum%");
1406 spin_lock(&sbi->ll_pp_extent_lock);
1407 for (k = 0; k < LL_PROCESS_HIST_MAX; k++) {
1408 if (io_extents->pp_extents[k].pid != 0) {
1409 seq_printf(seq, "\nPID: %d\n",
1410 io_extents->pp_extents[k].pid);
1411 ll_display_extents_info(io_extents, seq, k);
1414 spin_unlock(&sbi->ll_pp_extent_lock);
1418 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
1419 const char __user *buf,
1423 struct seq_file *seq = file->private_data;
1424 struct ll_sb_info *sbi = seq->private;
1425 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1427 int value = 1, rc = 0;
1432 rc = lprocfs_write_helper(buf, len, &value);
1433 if (rc < 0 && len < 16) {
1436 if (copy_from_user(kernbuf, buf, len))
1440 if (kernbuf[len - 1] == '\n')
1441 kernbuf[len - 1] = 0;
1443 if (strcmp(kernbuf, "disabled") == 0 ||
1444 strcmp(kernbuf, "Disabled") == 0)
1449 sbi->ll_rw_stats_on = 0;
1451 sbi->ll_rw_stats_on = 1;
1453 spin_lock(&sbi->ll_pp_extent_lock);
1454 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1455 io_extents->pp_extents[i].pid = 0;
1456 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1457 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1459 spin_unlock(&sbi->ll_pp_extent_lock);
1463 LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
1465 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
1468 struct ll_sb_info *sbi = seq->private;
1469 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1471 do_gettimeofday(&now);
1473 if (!sbi->ll_rw_stats_on) {
1474 seq_printf(seq, "disabled\n"
1475 "write anything in this file to activate, "
1476 "then 0 or \"[D/d]isabled\" to deactivate\n");
1479 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1480 now.tv_sec, now.tv_usec);
1482 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1483 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1484 "extents", "calls", "%", "cum%",
1485 "calls", "%", "cum%");
1486 spin_lock(&sbi->ll_lock);
1487 ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
1488 spin_unlock(&sbi->ll_lock);
1493 static ssize_t ll_rw_extents_stats_seq_write(struct file *file,
1494 const char __user *buf,
1495 size_t len, loff_t *off)
1497 struct seq_file *seq = file->private_data;
1498 struct ll_sb_info *sbi = seq->private;
1499 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1501 int value = 1, rc = 0;
1506 rc = lprocfs_write_helper(buf, len, &value);
1507 if (rc < 0 && len < 16) {
1510 if (copy_from_user(kernbuf, buf, len))
1514 if (kernbuf[len - 1] == '\n')
1515 kernbuf[len - 1] = 0;
1517 if (strcmp(kernbuf, "disabled") == 0 ||
1518 strcmp(kernbuf, "Disabled") == 0)
1523 sbi->ll_rw_stats_on = 0;
1525 sbi->ll_rw_stats_on = 1;
1527 spin_lock(&sbi->ll_pp_extent_lock);
1528 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
1529 io_extents->pp_extents[i].pid = 0;
1530 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1531 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1533 spin_unlock(&sbi->ll_pp_extent_lock);
1537 LPROC_SEQ_FOPS(ll_rw_extents_stats);
1539 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
1540 struct ll_file_data *file, loff_t pos,
1541 size_t count, int rw)
1544 struct ll_rw_process_info *process;
1545 struct ll_rw_process_info *offset;
1546 int *off_count = &sbi->ll_rw_offset_entry_count;
1547 int *process_count = &sbi->ll_offset_process_count;
1548 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1550 if(!sbi->ll_rw_stats_on)
1552 process = sbi->ll_rw_process_info;
1553 offset = sbi->ll_rw_offset_info;
1555 spin_lock(&sbi->ll_pp_extent_lock);
1556 /* Extent statistics */
1557 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1558 if(io_extents->pp_extents[i].pid == pid) {
1566 sbi->ll_extent_process_count =
1567 (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1568 cur = sbi->ll_extent_process_count;
1569 io_extents->pp_extents[cur].pid = pid;
1570 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1571 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1574 for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
1575 (i < (LL_HIST_MAX - 1)); i++);
1577 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1578 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1580 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1581 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1583 spin_unlock(&sbi->ll_pp_extent_lock);
1585 spin_lock(&sbi->ll_process_lock);
1586 /* Offset statistics */
1587 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1588 if (process[i].rw_pid == pid) {
1589 if (process[i].rw_last_file != file) {
1590 process[i].rw_range_start = pos;
1591 process[i].rw_last_file_pos = pos + count;
1592 process[i].rw_smallest_extent = count;
1593 process[i].rw_largest_extent = count;
1594 process[i].rw_offset = 0;
1595 process[i].rw_last_file = file;
1596 spin_unlock(&sbi->ll_process_lock);
1599 if (process[i].rw_last_file_pos != pos) {
1601 (*off_count + 1) % LL_OFFSET_HIST_MAX;
1602 offset[*off_count].rw_op = process[i].rw_op;
1603 offset[*off_count].rw_pid = pid;
1604 offset[*off_count].rw_range_start =
1605 process[i].rw_range_start;
1606 offset[*off_count].rw_range_end =
1607 process[i].rw_last_file_pos;
1608 offset[*off_count].rw_smallest_extent =
1609 process[i].rw_smallest_extent;
1610 offset[*off_count].rw_largest_extent =
1611 process[i].rw_largest_extent;
1612 offset[*off_count].rw_offset =
1613 process[i].rw_offset;
1614 process[i].rw_op = rw;
1615 process[i].rw_range_start = pos;
1616 process[i].rw_smallest_extent = count;
1617 process[i].rw_largest_extent = count;
1618 process[i].rw_offset = pos -
1619 process[i].rw_last_file_pos;
1621 if(process[i].rw_smallest_extent > count)
1622 process[i].rw_smallest_extent = count;
1623 if(process[i].rw_largest_extent < count)
1624 process[i].rw_largest_extent = count;
1625 process[i].rw_last_file_pos = pos + count;
1626 spin_unlock(&sbi->ll_process_lock);
1630 *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
1631 process[*process_count].rw_pid = pid;
1632 process[*process_count].rw_op = rw;
1633 process[*process_count].rw_range_start = pos;
1634 process[*process_count].rw_last_file_pos = pos + count;
1635 process[*process_count].rw_smallest_extent = count;
1636 process[*process_count].rw_largest_extent = count;
1637 process[*process_count].rw_offset = 0;
1638 process[*process_count].rw_last_file = file;
1639 spin_unlock(&sbi->ll_process_lock);
1642 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1645 struct ll_sb_info *sbi = seq->private;
1646 struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
1647 struct ll_rw_process_info *process = sbi->ll_rw_process_info;
1650 do_gettimeofday(&now);
1652 if (!sbi->ll_rw_stats_on) {
1653 seq_printf(seq, "disabled\n"
1654 "write anything in this file to activate, "
1655 "then 0 or \"[D/d]isabled\" to deactivate\n");
1658 spin_lock(&sbi->ll_process_lock);
1660 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1661 now.tv_sec, now.tv_usec);
1662 seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
1663 "R/W", "PID", "RANGE START", "RANGE END",
1664 "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
1666 /* We stored the discontiguous offsets here; print them first */
1667 for (i = 0; i < LL_OFFSET_HIST_MAX; i++) {
1668 if (offset[i].rw_pid != 0)
1670 "%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1671 offset[i].rw_op == READ ? 'R' : 'W',
1673 offset[i].rw_range_start,
1674 offset[i].rw_range_end,
1675 (unsigned long)offset[i].rw_smallest_extent,
1676 (unsigned long)offset[i].rw_largest_extent,
1677 offset[i].rw_offset);
1680 /* Then print the current offsets for each process */
1681 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1682 if (process[i].rw_pid != 0)
1684 "%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1685 process[i].rw_op == READ ? 'R' : 'W',
1687 process[i].rw_range_start,
1688 process[i].rw_last_file_pos,
1689 (unsigned long)process[i].rw_smallest_extent,
1690 (unsigned long)process[i].rw_largest_extent,
1691 process[i].rw_offset);
1693 spin_unlock(&sbi->ll_process_lock);
1698 static ssize_t ll_rw_offset_stats_seq_write(struct file *file,
1699 const char __user *buf,
1700 size_t len, loff_t *off)
1702 struct seq_file *seq = file->private_data;
1703 struct ll_sb_info *sbi = seq->private;
1704 struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
1705 struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
1706 int value = 1, rc = 0;
1711 rc = lprocfs_write_helper(buf, len, &value);
1713 if (rc < 0 && len < 16) {
1716 if (copy_from_user(kernbuf, buf, len))
1720 if (kernbuf[len - 1] == '\n')
1721 kernbuf[len - 1] = 0;
1723 if (strcmp(kernbuf, "disabled") == 0 ||
1724 strcmp(kernbuf, "Disabled") == 0)
1729 sbi->ll_rw_stats_on = 0;
1731 sbi->ll_rw_stats_on = 1;
1733 spin_lock(&sbi->ll_process_lock);
1734 sbi->ll_offset_process_count = 0;
1735 sbi->ll_rw_offset_entry_count = 0;
1736 memset(process_info, 0, sizeof(struct ll_rw_process_info) *
1737 LL_PROCESS_HIST_MAX);
1738 memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
1739 LL_OFFSET_HIST_MAX);
1740 spin_unlock(&sbi->ll_process_lock);
1745 LPROC_SEQ_FOPS(ll_rw_offset_stats);
1746 #endif /* CONFIG_PROC_FS */