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) 2012, 2015, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 #define DEBUG_SUBSYSTEM S_LLITE
34 #include <linux/version.h>
35 #include <linux/user_namespace.h>
36 #ifdef HAVE_UIDGID_HEADER
37 # include <linux/uidgid.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 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 seq_printf(m, "%llu\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 seq_printf(m, "%llu\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 seq_printf(m, "%llu\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 seq_printf(m, "%llu\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 seq_printf(m, "%llu\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);
175 LASSERT(sbi != NULL);
177 seq_puts(m, "local client\n");
180 LPROC_SEQ_FOPS_RO(ll_client_type);
182 static int ll_fstype_seq_show(struct seq_file *m, void *v)
184 struct super_block *sb = m->private;
187 seq_printf(m, "%s\n", sb->s_type->name);
190 LPROC_SEQ_FOPS_RO(ll_fstype);
192 static int ll_sb_uuid_seq_show(struct seq_file *m, void *v)
194 struct super_block *sb = m->private;
197 seq_printf(m, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
200 LPROC_SEQ_FOPS_RO(ll_sb_uuid);
202 static int ll_xattr_cache_seq_show(struct seq_file *m, void *v)
204 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
206 seq_printf(m, "%u\n", sbi->ll_xattr_cache_enabled);
210 static ssize_t ll_xattr_cache_seq_write(struct file *file,
211 const char __user *buffer,
212 size_t count, loff_t *off)
214 struct seq_file *m = file->private_data;
215 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
219 rc = lprocfs_str_to_s64(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_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);
272 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
276 pages_number >>= PAGE_SHIFT;
278 if (pages_number < 0 || pages_number > totalram_pages / 2) {
280 CERROR("%s: can't set max_readahead_mb=%lu > %luMB\n",
281 ll_get_fsname(sb, NULL, 0),
282 (unsigned long)pages_number >> (20 - PAGE_SHIFT),
283 totalram_pages >> (20 - PAGE_SHIFT + 1));
287 spin_lock(&sbi->ll_lock);
288 sbi->ll_ra_info.ra_max_pages = pages_number;
289 spin_unlock(&sbi->ll_lock);
292 LPROC_SEQ_FOPS(ll_max_readahead_mb);
294 static int ll_max_readahead_per_file_mb_seq_show(struct seq_file *m, void *v)
296 struct super_block *sb = m->private;
297 struct ll_sb_info *sbi = ll_s2sbi(sb);
301 spin_lock(&sbi->ll_lock);
302 pages_number = sbi->ll_ra_info.ra_max_pages_per_file;
303 spin_unlock(&sbi->ll_lock);
305 mult = 1 << (20 - PAGE_SHIFT);
306 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
310 ll_max_readahead_per_file_mb_seq_write(struct file *file,
311 const char __user *buffer,
312 size_t count, loff_t *off)
314 struct seq_file *m = file->private_data;
315 struct super_block *sb = m->private;
316 struct ll_sb_info *sbi = ll_s2sbi(sb);
320 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
324 pages_number >>= PAGE_SHIFT;
326 if (pages_number < 0 || pages_number > sbi->ll_ra_info.ra_max_pages) {
327 CERROR("%s: can't set max_readahead_per_file_mb=%lu > "
328 "max_read_ahead_mb=%lu\n", ll_get_fsname(sb, NULL, 0),
329 (unsigned long)pages_number >> (20 - PAGE_SHIFT),
330 sbi->ll_ra_info.ra_max_pages >> (20 - PAGE_SHIFT));
334 spin_lock(&sbi->ll_lock);
335 sbi->ll_ra_info.ra_max_pages_per_file = pages_number;
336 spin_unlock(&sbi->ll_lock);
339 LPROC_SEQ_FOPS(ll_max_readahead_per_file_mb);
341 static int ll_max_read_ahead_whole_mb_seq_show(struct seq_file *m, void *v)
343 struct super_block *sb = m->private;
344 struct ll_sb_info *sbi = ll_s2sbi(sb);
348 spin_lock(&sbi->ll_lock);
349 pages_number = sbi->ll_ra_info.ra_max_read_ahead_whole_pages;
350 spin_unlock(&sbi->ll_lock);
352 mult = 1 << (20 - PAGE_SHIFT);
353 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
357 ll_max_read_ahead_whole_mb_seq_write(struct file *file,
358 const char __user *buffer,
359 size_t count, loff_t *off)
361 struct seq_file *m = file->private_data;
362 struct super_block *sb = m->private;
363 struct ll_sb_info *sbi = ll_s2sbi(sb);
367 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
371 pages_number >>= PAGE_SHIFT;
373 /* Cap this at the current max readahead window size, the readahead
374 * algorithm does this anyway so it's pointless to set it larger. */
375 if (pages_number < 0 ||
376 pages_number > sbi->ll_ra_info.ra_max_pages_per_file) {
377 int pages_shift = 20 - PAGE_SHIFT;
378 CERROR("%s: can't set max_read_ahead_whole_mb=%lu > "
379 "max_read_ahead_per_file_mb=%lu\n",
380 ll_get_fsname(sb, NULL, 0),
381 (unsigned long)pages_number >> pages_shift,
382 sbi->ll_ra_info.ra_max_pages_per_file >> pages_shift);
386 spin_lock(&sbi->ll_lock);
387 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = pages_number;
388 spin_unlock(&sbi->ll_lock);
391 LPROC_SEQ_FOPS(ll_max_read_ahead_whole_mb);
393 static int ll_max_cached_mb_seq_show(struct seq_file *m, void *v)
395 struct super_block *sb = m->private;
396 struct ll_sb_info *sbi = ll_s2sbi(sb);
397 struct cl_client_cache *cache = sbi->ll_cache;
398 int shift = 20 - PAGE_SHIFT;
402 max_cached_mb = cache->ccc_lru_max >> shift;
403 unused_mb = atomic_long_read(&cache->ccc_lru_left) >> shift;
404 seq_printf(m, "users: %d\n"
405 "max_cached_mb: %ld\n"
408 "reclaim_count: %u\n",
409 atomic_read(&cache->ccc_users),
411 max_cached_mb - unused_mb,
413 cache->ccc_lru_shrinkers);
418 ll_max_cached_mb_seq_write(struct file *file, const char __user *buffer,
419 size_t count, loff_t *off)
421 struct seq_file *m = file->private_data;
422 struct super_block *sb = m->private;
423 struct ll_sb_info *sbi = ll_s2sbi(sb);
424 struct cl_client_cache *cache = sbi->ll_cache;
434 if (count >= sizeof(kernbuf))
437 if (copy_from_user(kernbuf, buffer, count))
441 buffer += lprocfs_find_named_value(kernbuf, "max_cached_mb:", &count) -
443 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
447 pages_number >>= PAGE_SHIFT;
449 if (pages_number < 0 || pages_number > totalram_pages) {
450 CERROR("%s: can't set max cache more than %lu MB\n",
451 ll_get_fsname(sb, NULL, 0),
452 totalram_pages >> (20 - PAGE_SHIFT));
455 /* Allow enough cache so clients can make well-formed RPCs */
456 pages_number = max_t(long, pages_number, PTLRPC_MAX_BRW_PAGES);
458 spin_lock(&sbi->ll_lock);
459 diff = pages_number - cache->ccc_lru_max;
460 spin_unlock(&sbi->ll_lock);
462 /* easy - add more LRU slots. */
464 atomic_long_add(diff, &cache->ccc_lru_left);
468 env = cl_env_get(&refcheck);
476 /* reduce LRU budget from free slots. */
480 ov = atomic_long_read(&cache->ccc_lru_left);
484 nv = ov > diff ? ov - diff : 0;
485 rc = atomic_long_cmpxchg(&cache->ccc_lru_left, ov, nv);
486 if (likely(ov == rc)) {
496 if (sbi->ll_dt_exp == NULL) { /* being initialized */
501 /* difficult - have to ask OSCs to drop LRU slots. */
503 rc = obd_set_info_async(env, sbi->ll_dt_exp,
504 sizeof(KEY_CACHE_LRU_SHRINK),
505 KEY_CACHE_LRU_SHRINK,
506 sizeof(tmp), &tmp, NULL);
510 cl_env_put(env, &refcheck);
514 spin_lock(&sbi->ll_lock);
515 cache->ccc_lru_max = pages_number;
516 spin_unlock(&sbi->ll_lock);
519 atomic_long_add(nrpages, &cache->ccc_lru_left);
523 LPROC_SEQ_FOPS(ll_max_cached_mb);
525 static int ll_checksum_seq_show(struct seq_file *m, void *v)
527 struct super_block *sb = m->private;
528 struct ll_sb_info *sbi = ll_s2sbi(sb);
530 seq_printf(m, "%u\n", (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0);
534 static ssize_t ll_checksum_seq_write(struct file *file,
535 const char __user *buffer,
536 size_t count, loff_t *off)
538 struct seq_file *m = file->private_data;
539 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
547 rc = lprocfs_str_to_s64(buffer, count, &val);
551 sbi->ll_flags |= LL_SBI_CHECKSUM;
553 sbi->ll_flags &= ~LL_SBI_CHECKSUM;
555 rc = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
556 KEY_CHECKSUM, sizeof(val), &val, NULL);
558 CWARN("Failed to set OSC checksum flags: %d\n", rc);
562 LPROC_SEQ_FOPS(ll_checksum);
564 static int ll_rd_track_id(struct seq_file *m, enum stats_track_type type)
566 struct super_block *sb = m->private;
568 if (ll_s2sbi(sb)->ll_stats_track_type == type) {
569 seq_printf(m, "%d\n",
570 ll_s2sbi(sb)->ll_stats_track_id);
571 } else if (ll_s2sbi(sb)->ll_stats_track_type == STATS_TRACK_ALL) {
572 seq_puts(m, "0 (all)\n");
574 seq_puts(m, "untracked\n");
579 static int ll_wr_track_id(const char __user *buffer, unsigned long count,
580 void *data, enum stats_track_type type)
582 struct super_block *sb = data;
586 rc = lprocfs_str_to_s64(buffer, count, &pid);
589 if (pid > INT_MAX || pid < 0)
592 ll_s2sbi(sb)->ll_stats_track_id = pid;
594 ll_s2sbi(sb)->ll_stats_track_type = STATS_TRACK_ALL;
596 ll_s2sbi(sb)->ll_stats_track_type = type;
597 lprocfs_clear_stats(ll_s2sbi(sb)->ll_stats);
601 static int ll_track_pid_seq_show(struct seq_file *m, void *v)
603 return ll_rd_track_id(m, STATS_TRACK_PID);
606 static ssize_t ll_track_pid_seq_write(struct file *file,
607 const char __user *buffer,
608 size_t count, loff_t *off)
610 struct seq_file *seq = file->private_data;
611 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PID);
613 LPROC_SEQ_FOPS(ll_track_pid);
615 static int ll_track_ppid_seq_show(struct seq_file *m, void *v)
617 return ll_rd_track_id(m, STATS_TRACK_PPID);
620 static ssize_t ll_track_ppid_seq_write(struct file *file,
621 const char __user *buffer,
622 size_t count, loff_t *off)
624 struct seq_file *seq = file->private_data;
625 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PPID);
627 LPROC_SEQ_FOPS(ll_track_ppid);
629 static int ll_track_gid_seq_show(struct seq_file *m, void *v)
631 return ll_rd_track_id(m, STATS_TRACK_GID);
634 static ssize_t ll_track_gid_seq_write(struct file *file,
635 const char __user *buffer,
636 size_t count, loff_t *off)
638 struct seq_file *seq = file->private_data;
639 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_GID);
641 LPROC_SEQ_FOPS(ll_track_gid);
643 static int ll_statahead_max_seq_show(struct seq_file *m, void *v)
645 struct super_block *sb = m->private;
646 struct ll_sb_info *sbi = ll_s2sbi(sb);
648 seq_printf(m, "%u\n", sbi->ll_sa_max);
652 static ssize_t ll_statahead_max_seq_write(struct file *file,
653 const char __user *buffer,
654 size_t count, loff_t *off)
656 struct seq_file *m = file->private_data;
657 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
661 rc = lprocfs_str_to_s64(buffer, count, &val);
665 if (val >= 0 && val <= LL_SA_RPC_MAX)
666 sbi->ll_sa_max = val;
668 CERROR("Bad statahead_max value %lld. Valid values are in "
669 "the range [0, %d]\n", val, LL_SA_RPC_MAX);
673 LPROC_SEQ_FOPS(ll_statahead_max);
675 static int ll_statahead_agl_seq_show(struct seq_file *m, void *v)
677 struct super_block *sb = m->private;
678 struct ll_sb_info *sbi = ll_s2sbi(sb);
680 seq_printf(m, "%u\n",
681 sbi->ll_flags & LL_SBI_AGL_ENABLED ? 1 : 0);
685 static ssize_t ll_statahead_agl_seq_write(struct file *file,
686 const char __user *buffer,
687 size_t count, loff_t *off)
689 struct seq_file *m = file->private_data;
690 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
694 rc = lprocfs_str_to_s64(buffer, count, &val);
699 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
701 sbi->ll_flags &= ~LL_SBI_AGL_ENABLED;
705 LPROC_SEQ_FOPS(ll_statahead_agl);
707 static int ll_statahead_stats_seq_show(struct seq_file *m, void *v)
709 struct super_block *sb = m->private;
710 struct ll_sb_info *sbi = ll_s2sbi(sb);
712 seq_printf(m, "statahead total: %u\n"
713 "statahead wrong: %u\n"
715 atomic_read(&sbi->ll_sa_total),
716 atomic_read(&sbi->ll_sa_wrong),
717 atomic_read(&sbi->ll_agl_total));
720 LPROC_SEQ_FOPS_RO(ll_statahead_stats);
722 static int ll_lazystatfs_seq_show(struct seq_file *m, void *v)
724 struct super_block *sb = m->private;
725 struct ll_sb_info *sbi = ll_s2sbi(sb);
727 seq_printf(m, "%u\n",
728 (sbi->ll_flags & LL_SBI_LAZYSTATFS) ? 1 : 0);
732 static ssize_t ll_lazystatfs_seq_write(struct file *file,
733 const char __user *buffer,
734 size_t count, loff_t *off)
736 struct seq_file *m = file->private_data;
737 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
741 rc = lprocfs_str_to_s64(buffer, count, &val);
746 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
748 sbi->ll_flags &= ~LL_SBI_LAZYSTATFS;
752 LPROC_SEQ_FOPS(ll_lazystatfs);
754 static int ll_max_easize_seq_show(struct seq_file *m, void *v)
756 struct super_block *sb = m->private;
757 struct ll_sb_info *sbi = ll_s2sbi(sb);
761 rc = ll_get_max_mdsize(sbi, &ealen);
765 seq_printf(m, "%u\n", ealen);
768 LPROC_SEQ_FOPS_RO(ll_max_easize);
771 * Get default_easize.
773 * \see client_obd::cl_default_mds_easize
775 * \param[in] m seq_file handle
776 * \param[in] v unused for single entry
778 * \retval 0 on success
779 * \retval negative negated errno on failure
781 static int ll_default_easize_seq_show(struct seq_file *m, void *v)
783 struct super_block *sb = m->private;
784 struct ll_sb_info *sbi = ll_s2sbi(sb);
788 rc = ll_get_default_mdsize(sbi, &ealen);
792 seq_printf(m, "%u\n", ealen);
797 * Set default_easize.
799 * Range checking on the passed value is handled by
800 * ll_set_default_mdsize().
802 * \see client_obd::cl_default_mds_easize
804 * \param[in] file proc file
805 * \param[in] buffer string passed from user space
806 * \param[in] count \a buffer length
807 * \param[in] off unused for single entry
809 * \retval positive \a count on success
810 * \retval negative negated errno on failure
812 static ssize_t ll_default_easize_seq_write(struct file *file,
813 const char __user *buffer,
814 size_t count, loff_t *unused)
816 struct seq_file *seq = file->private_data;
817 struct super_block *sb = (struct super_block *)seq->private;
818 struct ll_sb_info *sbi = ll_s2sbi(sb);
825 rc = lprocfs_str_to_s64(buffer, count, &val);
828 if (val < 0 || val > INT_MAX)
831 rc = ll_set_default_mdsize(sbi, val);
837 LPROC_SEQ_FOPS(ll_default_easize);
839 static int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
841 const char *str[] = LL_SBI_FLAGS;
842 struct super_block *sb = m->private;
843 int flags = ll_s2sbi(sb)->ll_flags;
847 if (ARRAY_SIZE(str) <= i) {
848 CERROR("%s: Revise array LL_SBI_FLAGS to match sbi "
849 "flags please.\n", ll_get_fsname(sb, NULL, 0));
854 seq_printf(m, "%s ", str[i]);
858 seq_printf(m, "\b\n");
861 LPROC_SEQ_FOPS_RO(ll_sbi_flags);
863 static int ll_fast_read_seq_show(struct seq_file *m, void *v)
865 struct super_block *sb = m->private;
866 struct ll_sb_info *sbi = ll_s2sbi(sb);
868 seq_printf(m, "%u\n", !!(sbi->ll_flags & LL_SBI_FAST_READ));
873 ll_fast_read_seq_write(struct file *file, const char __user *buffer,
874 size_t count, loff_t *off)
876 struct seq_file *m = file->private_data;
877 struct super_block *sb = m->private;
878 struct ll_sb_info *sbi = ll_s2sbi(sb);
882 rc = lprocfs_str_to_s64(buffer, count, &val);
886 spin_lock(&sbi->ll_lock);
888 sbi->ll_flags |= LL_SBI_FAST_READ;
890 sbi->ll_flags &= ~LL_SBI_FAST_READ;
891 spin_unlock(&sbi->ll_lock);
895 LPROC_SEQ_FOPS(ll_fast_read);
897 static int ll_unstable_stats_seq_show(struct seq_file *m, void *v)
899 struct super_block *sb = m->private;
900 struct ll_sb_info *sbi = ll_s2sbi(sb);
901 struct cl_client_cache *cache = sbi->ll_cache;
905 pages = atomic_long_read(&cache->ccc_unstable_nr);
906 mb = (pages * PAGE_SIZE) >> 20;
908 seq_printf(m, "unstable_check: %8d\n"
909 "unstable_pages: %12ld\n"
910 "unstable_mb: %8d\n",
911 cache->ccc_unstable_check, pages, mb);
915 static ssize_t ll_unstable_stats_seq_write(struct file *file,
916 const char __user *buffer,
917 size_t count, loff_t *unused)
919 struct seq_file *seq = file->private_data;
920 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)seq->private);
927 if (count >= sizeof(kernbuf))
930 if (copy_from_user(kernbuf, buffer, count))
934 buffer += lprocfs_find_named_value(kernbuf, "unstable_check:", &count) -
936 rc = lprocfs_str_to_s64(buffer, count, &val);
940 /* borrow lru lock to set the value */
941 spin_lock(&sbi->ll_cache->ccc_lru_lock);
942 sbi->ll_cache->ccc_unstable_check = !!val;
943 spin_unlock(&sbi->ll_cache->ccc_lru_lock);
947 LPROC_SEQ_FOPS(ll_unstable_stats);
949 static int ll_root_squash_seq_show(struct seq_file *m, void *v)
951 struct super_block *sb = m->private;
952 struct ll_sb_info *sbi = ll_s2sbi(sb);
953 struct root_squash_info *squash = &sbi->ll_squash;
955 seq_printf(m, "%u:%u\n", squash->rsi_uid, squash->rsi_gid);
959 static ssize_t ll_root_squash_seq_write(struct file *file,
960 const char __user *buffer,
961 size_t count, loff_t *off)
963 struct seq_file *m = file->private_data;
964 struct super_block *sb = m->private;
965 struct ll_sb_info *sbi = ll_s2sbi(sb);
966 struct root_squash_info *squash = &sbi->ll_squash;
968 return lprocfs_wr_root_squash(buffer, count, squash,
969 ll_get_fsname(sb, NULL, 0));
971 LPROC_SEQ_FOPS(ll_root_squash);
973 static int ll_nosquash_nids_seq_show(struct seq_file *m, void *v)
975 struct super_block *sb = m->private;
976 struct ll_sb_info *sbi = ll_s2sbi(sb);
977 struct root_squash_info *squash = &sbi->ll_squash;
980 down_read(&squash->rsi_sem);
981 if (!list_empty(&squash->rsi_nosquash_nids)) {
982 len = cfs_print_nidlist(m->buf + m->count, m->size - m->count,
983 &squash->rsi_nosquash_nids);
987 seq_puts(m, "NONE\n");
989 up_read(&squash->rsi_sem);
994 static ssize_t ll_nosquash_nids_seq_write(struct file *file,
995 const char __user *buffer,
996 size_t count, loff_t *off)
998 struct seq_file *m = file->private_data;
999 struct super_block *sb = m->private;
1000 struct ll_sb_info *sbi = ll_s2sbi(sb);
1001 struct root_squash_info *squash = &sbi->ll_squash;
1004 rc = lprocfs_wr_nosquash_nids(buffer, count, squash,
1005 ll_get_fsname(sb, NULL, 0));
1009 ll_compute_rootsquash_state(sbi);
1013 LPROC_SEQ_FOPS(ll_nosquash_nids);
1015 struct lprocfs_vars lprocfs_llite_obd_vars[] = {
1017 .fops = &ll_sb_uuid_fops },
1019 .fops = &ll_fstype_fops },
1021 .fops = &ll_site_stats_fops },
1022 { .name = "blocksize",
1023 .fops = &ll_blksize_fops },
1024 { .name = "kbytestotal",
1025 .fops = &ll_kbytestotal_fops },
1026 { .name = "kbytesfree",
1027 .fops = &ll_kbytesfree_fops },
1028 { .name = "kbytesavail",
1029 .fops = &ll_kbytesavail_fops },
1030 { .name = "filestotal",
1031 .fops = &ll_filestotal_fops },
1032 { .name = "filesfree",
1033 .fops = &ll_filesfree_fops },
1034 { .name = "client_type",
1035 .fops = &ll_client_type_fops },
1036 { .name = "max_read_ahead_mb",
1037 .fops = &ll_max_readahead_mb_fops },
1038 { .name = "max_read_ahead_per_file_mb",
1039 .fops = &ll_max_readahead_per_file_mb_fops },
1040 { .name = "max_read_ahead_whole_mb",
1041 .fops = &ll_max_read_ahead_whole_mb_fops },
1042 { .name = "max_cached_mb",
1043 .fops = &ll_max_cached_mb_fops },
1044 { .name = "checksum_pages",
1045 .fops = &ll_checksum_fops },
1046 { .name = "stats_track_pid",
1047 .fops = &ll_track_pid_fops },
1048 { .name = "stats_track_ppid",
1049 .fops = &ll_track_ppid_fops },
1050 { .name = "stats_track_gid",
1051 .fops = &ll_track_gid_fops },
1052 { .name = "statahead_max",
1053 .fops = &ll_statahead_max_fops },
1054 { .name = "statahead_agl",
1055 .fops = &ll_statahead_agl_fops },
1056 { .name = "statahead_stats",
1057 .fops = &ll_statahead_stats_fops },
1058 { .name = "lazystatfs",
1059 .fops = &ll_lazystatfs_fops },
1060 { .name = "max_easize",
1061 .fops = &ll_max_easize_fops },
1062 { .name = "default_easize",
1063 .fops = &ll_default_easize_fops },
1064 { .name = "sbi_flags",
1065 .fops = &ll_sbi_flags_fops },
1066 { .name = "xattr_cache",
1067 .fops = &ll_xattr_cache_fops },
1068 { .name = "unstable_stats",
1069 .fops = &ll_unstable_stats_fops },
1070 { .name = "root_squash",
1071 .fops = &ll_root_squash_fops },
1072 { .name = "nosquash_nids",
1073 .fops = &ll_nosquash_nids_fops },
1074 { .name = "fast_read",
1075 .fops = &ll_fast_read_fops, },
1079 #define MAX_STRING_SIZE 128
1081 static const struct llite_file_opcode {
1085 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
1086 /* file operation */
1087 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
1088 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
1089 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1091 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1093 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
1095 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
1097 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
1098 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
1099 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
1100 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
1101 { LPROC_LL_FAULT, LPROCFS_TYPE_REGS, "page_fault" },
1102 { LPROC_LL_MKWRITE, LPROCFS_TYPE_REGS, "page_mkwrite" },
1103 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
1104 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
1105 { LPROC_LL_READDIR, LPROCFS_TYPE_REGS, "readdir" },
1106 /* inode operation */
1107 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
1108 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "truncate" },
1109 { LPROC_LL_FLOCK, LPROCFS_TYPE_REGS, "flock" },
1110 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
1111 /* dir inode operation */
1112 { LPROC_LL_CREATE, LPROCFS_TYPE_REGS, "create" },
1113 { LPROC_LL_LINK, LPROCFS_TYPE_REGS, "link" },
1114 { LPROC_LL_UNLINK, LPROCFS_TYPE_REGS, "unlink" },
1115 { LPROC_LL_SYMLINK, LPROCFS_TYPE_REGS, "symlink" },
1116 { LPROC_LL_MKDIR, LPROCFS_TYPE_REGS, "mkdir" },
1117 { LPROC_LL_RMDIR, LPROCFS_TYPE_REGS, "rmdir" },
1118 { LPROC_LL_MKNOD, LPROCFS_TYPE_REGS, "mknod" },
1119 { LPROC_LL_RENAME, LPROCFS_TYPE_REGS, "rename" },
1120 /* special inode operation */
1121 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
1122 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
1123 { LPROC_LL_SETXATTR, LPROCFS_TYPE_REGS, "setxattr" },
1124 { LPROC_LL_GETXATTR, LPROCFS_TYPE_REGS, "getxattr" },
1125 { LPROC_LL_GETXATTR_HITS, LPROCFS_TYPE_REGS, "getxattr_hits" },
1126 { LPROC_LL_LISTXATTR, LPROCFS_TYPE_REGS, "listxattr" },
1127 { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_REGS, "removexattr" },
1128 { LPROC_LL_INODE_PERM, LPROCFS_TYPE_REGS, "inode_permission" },
1131 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
1135 if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
1136 lprocfs_counter_add(sbi->ll_stats, op, count);
1137 else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
1138 sbi->ll_stats_track_id == current->pid)
1139 lprocfs_counter_add(sbi->ll_stats, op, count);
1140 else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
1141 sbi->ll_stats_track_id == current->parent->pid)
1142 lprocfs_counter_add(sbi->ll_stats, op, count);
1143 else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
1144 sbi->ll_stats_track_id ==
1145 from_kgid(&init_user_ns, current_gid()))
1146 lprocfs_counter_add(sbi->ll_stats, op, count);
1148 EXPORT_SYMBOL(ll_stats_ops_tally);
1150 static const char *ra_stat_string[] = {
1151 [RA_STAT_HIT] = "hits",
1152 [RA_STAT_MISS] = "misses",
1153 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
1154 [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
1155 [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page",
1156 [RA_STAT_FAILED_MATCH] = "failed lock match",
1157 [RA_STAT_DISCARDED] = "read but discarded",
1158 [RA_STAT_ZERO_LEN] = "zero length file",
1159 [RA_STAT_ZERO_WINDOW] = "zero size window",
1160 [RA_STAT_EOF] = "read-ahead to EOF",
1161 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
1162 [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",
1163 [RA_STAT_FAILED_REACH_END] = "failed to reach end"
1166 LPROC_SEQ_FOPS_RO_TYPE(llite, name);
1167 LPROC_SEQ_FOPS_RO_TYPE(llite, uuid);
1169 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
1170 struct super_block *sb, char *osc, char *mdc)
1172 struct lprocfs_vars lvars[2];
1173 struct lustre_sb_info *lsi = s2lsi(sb);
1174 struct ll_sb_info *sbi = ll_s2sbi(sb);
1175 struct obd_device *obd;
1176 struct proc_dir_entry *dir;
1177 char name[MAX_STRING_SIZE + 1], *ptr;
1178 int err, id, len, rc;
1181 memset(lvars, 0, sizeof(lvars));
1183 name[MAX_STRING_SIZE] = '\0';
1184 lvars[0].name = name;
1186 LASSERT(sbi != NULL);
1187 LASSERT(mdc != NULL);
1188 LASSERT(osc != NULL);
1191 len = strlen(lsi->lsi_lmd->lmd_profile);
1192 ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
1193 if (ptr && (strcmp(ptr, "-client") == 0))
1197 snprintf(name, MAX_STRING_SIZE, "%.*s-%p", len,
1198 lsi->lsi_lmd->lmd_profile, sb);
1200 sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
1201 if (IS_ERR(sbi->ll_proc_root)) {
1202 err = PTR_ERR(sbi->ll_proc_root);
1203 sbi->ll_proc_root = NULL;
1207 rc = lprocfs_seq_create(sbi->ll_proc_root, "dump_page_cache", 0444,
1208 &vvp_dump_pgcache_file_ops, sbi);
1210 CWARN("Error adding the dump_page_cache file\n");
1212 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats", 0644,
1213 &ll_rw_extents_stats_fops, sbi);
1215 CWARN("Error adding the extent_stats file\n");
1217 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats_per_process",
1218 0644, &ll_rw_extents_stats_pp_fops, sbi);
1220 CWARN("Error adding the extents_stats_per_process file\n");
1222 rc = lprocfs_seq_create(sbi->ll_proc_root, "offset_stats", 0644,
1223 &ll_rw_offset_stats_fops, sbi);
1225 CWARN("Error adding the offset_stats file\n");
1227 /* File operations stats */
1228 sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
1229 LPROCFS_STATS_FLAG_NONE);
1230 if (sbi->ll_stats == NULL)
1231 GOTO(out, err = -ENOMEM);
1232 /* do counter init */
1233 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
1234 __u32 type = llite_opcode_table[id].type;
1236 if (type & LPROCFS_TYPE_REGS)
1238 else if (type & LPROCFS_TYPE_BYTES)
1240 else if (type & LPROCFS_TYPE_PAGES)
1242 lprocfs_counter_init(sbi->ll_stats,
1243 llite_opcode_table[id].opcode,
1244 (type & LPROCFS_CNTR_AVGMINMAX),
1245 llite_opcode_table[id].opname, ptr);
1247 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats);
1251 sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
1252 LPROCFS_STATS_FLAG_NONE);
1253 if (sbi->ll_ra_stats == NULL)
1254 GOTO(out, err = -ENOMEM);
1256 for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
1257 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
1258 ra_stat_string[id], "pages");
1259 err = lprocfs_register_stats(sbi->ll_proc_root, "read_ahead_stats",
1265 err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_llite_obd_vars, sb);
1270 obd = class_name2obd(mdc);
1272 LASSERT(obd != NULL);
1273 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1274 LASSERT(obd->obd_type->typ_name != NULL);
1276 dir = proc_mkdir(obd->obd_type->typ_name, sbi->ll_proc_root);
1278 GOTO(out, err = -ENOMEM);
1280 snprintf(name, MAX_STRING_SIZE, "common_name");
1281 lvars[0].fops = &llite_name_fops;
1282 err = lprocfs_add_vars(dir, lvars, obd);
1286 snprintf(name, MAX_STRING_SIZE, "uuid");
1287 lvars[0].fops = &llite_uuid_fops;
1288 err = lprocfs_add_vars(dir, lvars, obd);
1293 obd = class_name2obd(osc);
1295 LASSERT(obd != NULL);
1296 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1297 LASSERT(obd->obd_type->typ_name != NULL);
1299 dir = proc_mkdir(obd->obd_type->typ_name, sbi->ll_proc_root);
1301 GOTO(out, err = -ENOMEM);
1303 snprintf(name, MAX_STRING_SIZE, "common_name");
1304 lvars[0].fops = &llite_name_fops;
1305 err = lprocfs_add_vars(dir, lvars, obd);
1309 snprintf(name, MAX_STRING_SIZE, "uuid");
1310 lvars[0].fops = &llite_uuid_fops;
1311 err = lprocfs_add_vars(dir, lvars, obd);
1314 lprocfs_remove(&sbi->ll_proc_root);
1315 lprocfs_free_stats(&sbi->ll_ra_stats);
1316 lprocfs_free_stats(&sbi->ll_stats);
1321 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
1323 if (sbi->ll_proc_root) {
1324 lprocfs_remove(&sbi->ll_proc_root);
1325 lprocfs_free_stats(&sbi->ll_ra_stats);
1326 lprocfs_free_stats(&sbi->ll_stats);
1329 #undef MAX_STRING_SIZE
1331 #define pct(a,b) (b ? a * 100 / b : 0)
1333 static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
1334 struct seq_file *seq, int which)
1336 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
1337 unsigned long start, end, r, w;
1338 char *unitp = "KMGTPEZY";
1340 struct per_process_info *pp_info = &io_extents->pp_extents[which];
1346 for(i = 0; i < LL_HIST_MAX; i++) {
1347 read_tot += pp_info->pp_r_hist.oh_buckets[i];
1348 write_tot += pp_info->pp_w_hist.oh_buckets[i];
1351 for(i = 0; i < LL_HIST_MAX; i++) {
1352 r = pp_info->pp_r_hist.oh_buckets[i];
1353 w = pp_info->pp_w_hist.oh_buckets[i];
1356 end = 1 << (i + LL_HIST_START - units);
1357 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu | "
1358 "%14lu %4lu %4lu\n", start, *unitp, end, *unitp,
1359 (i == LL_HIST_MAX - 1) ? '+' : ' ',
1360 r, pct(r, read_tot), pct(read_cum, read_tot),
1361 w, pct(w, write_tot), pct(write_cum, write_tot));
1363 if (start == 1<<10) {
1368 if (read_cum == read_tot && write_cum == write_tot)
1373 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
1376 struct ll_sb_info *sbi = seq->private;
1377 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1380 do_gettimeofday(&now);
1382 if (!sbi->ll_rw_stats_on) {
1383 seq_puts(seq, "disabled\n write anything in this file to activate, then 0 or \"[D/d]isabled\" to deactivate\n");
1386 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1387 now.tv_sec, now.tv_usec);
1388 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1389 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1390 "extents", "calls", "%", "cum%",
1391 "calls", "%", "cum%");
1392 spin_lock(&sbi->ll_pp_extent_lock);
1393 for (k = 0; k < LL_PROCESS_HIST_MAX; k++) {
1394 if (io_extents->pp_extents[k].pid != 0) {
1395 seq_printf(seq, "\nPID: %d\n",
1396 io_extents->pp_extents[k].pid);
1397 ll_display_extents_info(io_extents, seq, k);
1400 spin_unlock(&sbi->ll_pp_extent_lock);
1404 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
1405 const char __user *buf,
1409 struct seq_file *seq = file->private_data;
1410 struct ll_sb_info *sbi = seq->private;
1411 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1419 rc = lprocfs_str_to_s64(buf, len, &value);
1420 if (rc < 0 && len < 16) {
1423 if (copy_from_user(kernbuf, buf, len))
1427 if (kernbuf[len - 1] == '\n')
1428 kernbuf[len - 1] = 0;
1430 if (strcmp(kernbuf, "disabled") == 0 ||
1431 strcmp(kernbuf, "Disabled") == 0)
1436 sbi->ll_rw_stats_on = 0;
1438 sbi->ll_rw_stats_on = 1;
1440 spin_lock(&sbi->ll_pp_extent_lock);
1441 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1442 io_extents->pp_extents[i].pid = 0;
1443 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1444 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1446 spin_unlock(&sbi->ll_pp_extent_lock);
1450 LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
1452 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
1455 struct ll_sb_info *sbi = seq->private;
1456 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1458 do_gettimeofday(&now);
1460 if (!sbi->ll_rw_stats_on) {
1461 seq_puts(seq, "disabled\n write anything in this file to activate, then 0 or \"[D/d]isabled\" to deactivate\n");
1464 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1465 now.tv_sec, now.tv_usec);
1467 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1468 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1469 "extents", "calls", "%", "cum%",
1470 "calls", "%", "cum%");
1471 spin_lock(&sbi->ll_lock);
1472 ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
1473 spin_unlock(&sbi->ll_lock);
1478 static ssize_t ll_rw_extents_stats_seq_write(struct file *file,
1479 const char __user *buf,
1480 size_t len, loff_t *off)
1482 struct seq_file *seq = file->private_data;
1483 struct ll_sb_info *sbi = seq->private;
1484 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1492 rc = lprocfs_str_to_s64(buf, len, &value);
1493 if (rc < 0 && len < 16) {
1496 if (copy_from_user(kernbuf, buf, len))
1500 if (kernbuf[len - 1] == '\n')
1501 kernbuf[len - 1] = 0;
1503 if (strcmp(kernbuf, "disabled") == 0 ||
1504 strcmp(kernbuf, "Disabled") == 0)
1509 sbi->ll_rw_stats_on = 0;
1511 sbi->ll_rw_stats_on = 1;
1513 spin_lock(&sbi->ll_pp_extent_lock);
1514 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
1515 io_extents->pp_extents[i].pid = 0;
1516 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1517 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1519 spin_unlock(&sbi->ll_pp_extent_lock);
1523 LPROC_SEQ_FOPS(ll_rw_extents_stats);
1525 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
1526 struct ll_file_data *file, loff_t pos,
1527 size_t count, int rw)
1530 struct ll_rw_process_info *process;
1531 struct ll_rw_process_info *offset;
1532 int *off_count = &sbi->ll_rw_offset_entry_count;
1533 int *process_count = &sbi->ll_offset_process_count;
1534 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1536 if(!sbi->ll_rw_stats_on)
1538 process = sbi->ll_rw_process_info;
1539 offset = sbi->ll_rw_offset_info;
1541 spin_lock(&sbi->ll_pp_extent_lock);
1542 /* Extent statistics */
1543 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1544 if(io_extents->pp_extents[i].pid == pid) {
1552 sbi->ll_extent_process_count =
1553 (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1554 cur = sbi->ll_extent_process_count;
1555 io_extents->pp_extents[cur].pid = pid;
1556 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1557 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1560 for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
1561 (i < (LL_HIST_MAX - 1)); i++);
1563 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1564 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1566 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1567 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1569 spin_unlock(&sbi->ll_pp_extent_lock);
1571 spin_lock(&sbi->ll_process_lock);
1572 /* Offset statistics */
1573 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1574 if (process[i].rw_pid == pid) {
1575 if (process[i].rw_last_file != file) {
1576 process[i].rw_range_start = pos;
1577 process[i].rw_last_file_pos = pos + count;
1578 process[i].rw_smallest_extent = count;
1579 process[i].rw_largest_extent = count;
1580 process[i].rw_offset = 0;
1581 process[i].rw_last_file = file;
1582 spin_unlock(&sbi->ll_process_lock);
1585 if (process[i].rw_last_file_pos != pos) {
1587 (*off_count + 1) % LL_OFFSET_HIST_MAX;
1588 offset[*off_count].rw_op = process[i].rw_op;
1589 offset[*off_count].rw_pid = pid;
1590 offset[*off_count].rw_range_start =
1591 process[i].rw_range_start;
1592 offset[*off_count].rw_range_end =
1593 process[i].rw_last_file_pos;
1594 offset[*off_count].rw_smallest_extent =
1595 process[i].rw_smallest_extent;
1596 offset[*off_count].rw_largest_extent =
1597 process[i].rw_largest_extent;
1598 offset[*off_count].rw_offset =
1599 process[i].rw_offset;
1600 process[i].rw_op = rw;
1601 process[i].rw_range_start = pos;
1602 process[i].rw_smallest_extent = count;
1603 process[i].rw_largest_extent = count;
1604 process[i].rw_offset = pos -
1605 process[i].rw_last_file_pos;
1607 if(process[i].rw_smallest_extent > count)
1608 process[i].rw_smallest_extent = count;
1609 if(process[i].rw_largest_extent < count)
1610 process[i].rw_largest_extent = count;
1611 process[i].rw_last_file_pos = pos + count;
1612 spin_unlock(&sbi->ll_process_lock);
1616 *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
1617 process[*process_count].rw_pid = pid;
1618 process[*process_count].rw_op = rw;
1619 process[*process_count].rw_range_start = pos;
1620 process[*process_count].rw_last_file_pos = pos + count;
1621 process[*process_count].rw_smallest_extent = count;
1622 process[*process_count].rw_largest_extent = count;
1623 process[*process_count].rw_offset = 0;
1624 process[*process_count].rw_last_file = file;
1625 spin_unlock(&sbi->ll_process_lock);
1628 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1631 struct ll_sb_info *sbi = seq->private;
1632 struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
1633 struct ll_rw_process_info *process = sbi->ll_rw_process_info;
1636 do_gettimeofday(&now);
1638 if (!sbi->ll_rw_stats_on) {
1639 seq_puts(seq, "disabled\n write anything in this file to activate, then 0 or \"[D/d]isabled\" to deactivate\n");
1642 spin_lock(&sbi->ll_process_lock);
1644 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1645 now.tv_sec, now.tv_usec);
1646 seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
1647 "R/W", "PID", "RANGE START", "RANGE END",
1648 "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
1650 /* We stored the discontiguous offsets here; print them first */
1651 for (i = 0; i < LL_OFFSET_HIST_MAX; i++) {
1652 if (offset[i].rw_pid != 0)
1654 "%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1655 offset[i].rw_op == READ ? 'R' : 'W',
1657 offset[i].rw_range_start,
1658 offset[i].rw_range_end,
1659 (unsigned long)offset[i].rw_smallest_extent,
1660 (unsigned long)offset[i].rw_largest_extent,
1661 offset[i].rw_offset);
1664 /* Then print the current offsets for each process */
1665 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1666 if (process[i].rw_pid != 0)
1668 "%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1669 process[i].rw_op == READ ? 'R' : 'W',
1671 process[i].rw_range_start,
1672 process[i].rw_last_file_pos,
1673 (unsigned long)process[i].rw_smallest_extent,
1674 (unsigned long)process[i].rw_largest_extent,
1675 process[i].rw_offset);
1677 spin_unlock(&sbi->ll_process_lock);
1682 static ssize_t ll_rw_offset_stats_seq_write(struct file *file,
1683 const char __user *buf,
1684 size_t len, loff_t *off)
1686 struct seq_file *seq = file->private_data;
1687 struct ll_sb_info *sbi = seq->private;
1688 struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
1689 struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
1696 rc = lprocfs_str_to_s64(buf, len, &value);
1698 if (rc < 0 && len < 16) {
1701 if (copy_from_user(kernbuf, buf, len))
1705 if (kernbuf[len - 1] == '\n')
1706 kernbuf[len - 1] = 0;
1708 if (strcmp(kernbuf, "disabled") == 0 ||
1709 strcmp(kernbuf, "Disabled") == 0)
1714 sbi->ll_rw_stats_on = 0;
1716 sbi->ll_rw_stats_on = 1;
1718 spin_lock(&sbi->ll_process_lock);
1719 sbi->ll_offset_process_count = 0;
1720 sbi->ll_rw_offset_entry_count = 0;
1721 memset(process_info, 0, sizeof(struct ll_rw_process_info) *
1722 LL_PROCESS_HIST_MAX);
1723 memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
1724 LL_OFFSET_HIST_MAX);
1725 spin_unlock(&sbi->ll_process_lock);
1730 LPROC_SEQ_FOPS(ll_rw_offset_stats);
1731 #endif /* CONFIG_PROC_FS */