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 <linux/user_namespace.h>
40 #ifdef HAVE_UIDGID_HEADER
41 # include <linux/uidgid.h>
43 #include <lustre_param.h>
44 #include <lprocfs_status.h>
45 #include <obd_support.h>
47 #include "llite_internal.h"
48 #include "vvp_internal.h"
50 struct proc_dir_entry *proc_lustre_fs_root;
53 /* /proc/lustre/llite mount point registration */
54 static const struct file_operations ll_rw_extents_stats_fops;
55 static const struct file_operations ll_rw_extents_stats_pp_fops;
56 static const struct file_operations ll_rw_offset_stats_fops;
58 static int ll_blksize_seq_show(struct seq_file *m, void *v)
60 struct super_block *sb = m->private;
61 struct obd_statfs osfs;
65 rc = ll_statfs_internal(sb, &osfs,
66 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
69 rc = seq_printf(m, "%u\n", osfs.os_bsize);
72 LPROC_SEQ_FOPS_RO(ll_blksize);
74 static int ll_kbytestotal_seq_show(struct seq_file *m, void *v)
76 struct super_block *sb = m->private;
77 struct obd_statfs osfs;
81 rc = ll_statfs_internal(sb, &osfs,
82 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
85 __u32 blk_size = osfs.os_bsize >> 10;
86 __u64 result = osfs.os_blocks;
88 while (blk_size >>= 1)
91 rc = seq_printf(m, LPU64"\n", result);
95 LPROC_SEQ_FOPS_RO(ll_kbytestotal);
97 static int ll_kbytesfree_seq_show(struct seq_file *m, void *v)
99 struct super_block *sb = m->private;
100 struct obd_statfs osfs;
104 rc = ll_statfs_internal(sb, &osfs,
105 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
108 __u32 blk_size = osfs.os_bsize >> 10;
109 __u64 result = osfs.os_bfree;
111 while (blk_size >>= 1)
114 rc = seq_printf(m, LPU64"\n", result);
118 LPROC_SEQ_FOPS_RO(ll_kbytesfree);
120 static int ll_kbytesavail_seq_show(struct seq_file *m, void *v)
122 struct super_block *sb = m->private;
123 struct obd_statfs osfs;
127 rc = ll_statfs_internal(sb, &osfs,
128 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
131 __u32 blk_size = osfs.os_bsize >> 10;
132 __u64 result = osfs.os_bavail;
134 while (blk_size >>= 1)
137 rc = seq_printf(m, LPU64"\n", result);
141 LPROC_SEQ_FOPS_RO(ll_kbytesavail);
143 static int ll_filestotal_seq_show(struct seq_file *m, void *v)
145 struct super_block *sb = m->private;
146 struct obd_statfs osfs;
150 rc = ll_statfs_internal(sb, &osfs,
151 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
154 rc = seq_printf(m, LPU64"\n", osfs.os_files);
157 LPROC_SEQ_FOPS_RO(ll_filestotal);
159 static int ll_filesfree_seq_show(struct seq_file *m, void *v)
161 struct super_block *sb = m->private;
162 struct obd_statfs osfs;
166 rc = ll_statfs_internal(sb, &osfs,
167 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
170 rc = seq_printf(m, LPU64"\n", osfs.os_ffree);
173 LPROC_SEQ_FOPS_RO(ll_filesfree);
175 static int ll_client_type_seq_show(struct seq_file *m, void *v)
177 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
180 LASSERT(sbi != NULL);
182 if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
183 rc = seq_printf(m, "remote client\n");
185 rc = seq_printf(m, "local client\n");
188 LPROC_SEQ_FOPS_RO(ll_client_type);
190 static int ll_fstype_seq_show(struct seq_file *m, void *v)
192 struct super_block *sb = m->private;
195 return seq_printf(m, "%s\n", sb->s_type->name);
197 LPROC_SEQ_FOPS_RO(ll_fstype);
199 static int ll_sb_uuid_seq_show(struct seq_file *m, void *v)
201 struct super_block *sb = m->private;
204 return seq_printf(m, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
206 LPROC_SEQ_FOPS_RO(ll_sb_uuid);
208 static int ll_xattr_cache_seq_show(struct seq_file *m, void *v)
210 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
212 return seq_printf(m, "%u\n", sbi->ll_xattr_cache_enabled);
215 static ssize_t ll_xattr_cache_seq_write(struct file *file,
216 const char __user *buffer,
217 size_t count, loff_t *off)
219 struct seq_file *m = file->private_data;
220 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
223 rc = lprocfs_write_helper(buffer, count, &val);
227 if (val != 0 && val != 1)
230 if (val == 1 && !(sbi->ll_flags & LL_SBI_XATTR_CACHE))
233 sbi->ll_xattr_cache_enabled = val;
237 LPROC_SEQ_FOPS(ll_xattr_cache);
239 static int ll_site_stats_seq_show(struct seq_file *m, void *v)
241 struct super_block *sb = m->private;
244 * See description of statistical counters in struct cl_site, and
247 return cl_site_stats_print(lu2cl_site(ll_s2sbi(sb)->ll_site), m);
249 LPROC_SEQ_FOPS_RO(ll_site_stats);
251 static int ll_max_readahead_mb_seq_show(struct seq_file *m, void *v)
253 struct super_block *sb = m->private;
254 struct ll_sb_info *sbi = ll_s2sbi(sb);
258 spin_lock(&sbi->ll_lock);
259 pages_number = sbi->ll_ra_info.ra_max_pages;
260 spin_unlock(&sbi->ll_lock);
262 mult = 1 << (20 - PAGE_CACHE_SHIFT);
263 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
267 ll_max_readahead_mb_seq_write(struct file *file, const char __user *buffer,
268 size_t count, loff_t *off)
270 struct seq_file *m = file->private_data;
271 struct super_block *sb = m->private;
272 struct ll_sb_info *sbi = ll_s2sbi(sb);
278 pages_shift = 20 - PAGE_CACHE_SHIFT;
279 rc = lprocfs_write_frac_u64_helper(buffer, count, &val,
286 pages_number = (long)val;
288 if (pages_number < 0 || pages_number > totalram_pages / 2) {
290 CERROR("%s: can't set max_readahead_mb=%lu > %luMB\n",
291 ll_get_fsname(sb, NULL, 0), pages_number >> pages_shift,
292 totalram_pages >> (pages_shift + 1));
296 spin_lock(&sbi->ll_lock);
297 sbi->ll_ra_info.ra_max_pages = pages_number;
298 spin_unlock(&sbi->ll_lock);
301 LPROC_SEQ_FOPS(ll_max_readahead_mb);
303 static int ll_max_readahead_per_file_mb_seq_show(struct seq_file *m, void *v)
305 struct super_block *sb = m->private;
306 struct ll_sb_info *sbi = ll_s2sbi(sb);
310 spin_lock(&sbi->ll_lock);
311 pages_number = sbi->ll_ra_info.ra_max_pages_per_file;
312 spin_unlock(&sbi->ll_lock);
314 mult = 1 << (20 - PAGE_CACHE_SHIFT);
315 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
319 ll_max_readahead_per_file_mb_seq_write(struct file *file,
320 const char __user *buffer,
321 size_t count, loff_t *off)
323 struct seq_file *m = file->private_data;
324 struct super_block *sb = m->private;
325 struct ll_sb_info *sbi = ll_s2sbi(sb);
326 int pages_shift, rc, pages_number;
328 pages_shift = 20 - PAGE_CACHE_SHIFT;
329 rc = lprocfs_write_frac_helper(buffer, count, &pages_number,
334 if (pages_number < 0 || pages_number > sbi->ll_ra_info.ra_max_pages) {
335 CERROR("%s: can't set max_readahead_per_file_mb=%u > "
336 "max_read_ahead_mb=%lu\n", ll_get_fsname(sb, NULL, 0),
337 pages_number >> pages_shift,
338 sbi->ll_ra_info.ra_max_pages >> pages_shift);
342 spin_lock(&sbi->ll_lock);
343 sbi->ll_ra_info.ra_max_pages_per_file = pages_number;
344 spin_unlock(&sbi->ll_lock);
347 LPROC_SEQ_FOPS(ll_max_readahead_per_file_mb);
349 static int ll_max_read_ahead_whole_mb_seq_show(struct seq_file *m, void *v)
351 struct super_block *sb = m->private;
352 struct ll_sb_info *sbi = ll_s2sbi(sb);
356 spin_lock(&sbi->ll_lock);
357 pages_number = sbi->ll_ra_info.ra_max_read_ahead_whole_pages;
358 spin_unlock(&sbi->ll_lock);
360 mult = 1 << (20 - PAGE_CACHE_SHIFT);
361 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
365 ll_max_read_ahead_whole_mb_seq_write(struct file *file,
366 const char __user *buffer,
367 size_t count, loff_t *off)
369 struct seq_file *m = file->private_data;
370 struct super_block *sb = m->private;
371 struct ll_sb_info *sbi = ll_s2sbi(sb);
372 int pages_shift, rc, pages_number;
374 pages_shift = 20 - PAGE_CACHE_SHIFT;
375 rc = lprocfs_write_frac_helper(buffer, count, &pages_number,
380 /* Cap this at the current max readahead window size, the readahead
381 * algorithm does this anyway so it's pointless to set it larger. */
382 if (pages_number < 0 ||
383 pages_number > sbi->ll_ra_info.ra_max_pages_per_file) {
384 CERROR("%s: can't set max_read_ahead_whole_mb=%u > "
385 "max_read_ahead_per_file_mb=%lu\n",
386 ll_get_fsname(sb, NULL, 0),
387 pages_number >> pages_shift,
388 sbi->ll_ra_info.ra_max_pages_per_file >> pages_shift);
392 spin_lock(&sbi->ll_lock);
393 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = pages_number;
394 spin_unlock(&sbi->ll_lock);
397 LPROC_SEQ_FOPS(ll_max_read_ahead_whole_mb);
399 static int ll_max_cached_mb_seq_show(struct seq_file *m, void *v)
401 struct super_block *sb = m->private;
402 struct ll_sb_info *sbi = ll_s2sbi(sb);
403 struct cl_client_cache *cache = sbi->ll_cache;
404 int shift = 20 - PAGE_CACHE_SHIFT;
408 max_cached_mb = cache->ccc_lru_max >> shift;
409 unused_mb = atomic_long_read(&cache->ccc_lru_left) >> shift;
412 "max_cached_mb: %ld\n"
415 "reclaim_count: %u\n",
416 atomic_read(&cache->ccc_users),
418 max_cached_mb - unused_mb,
420 cache->ccc_lru_shrinkers);
424 ll_max_cached_mb_seq_write(struct file *file, const char __user *buffer,
425 size_t count, loff_t *off)
427 struct seq_file *m = file->private_data;
428 struct super_block *sb = m->private;
429 struct ll_sb_info *sbi = ll_s2sbi(sb);
430 struct cl_client_cache *cache = sbi->ll_cache;
442 if (count >= sizeof(kernbuf))
445 if (copy_from_user(kernbuf, buffer, count))
449 mult = 1 << (20 - PAGE_CACHE_SHIFT);
450 buffer += lprocfs_find_named_value(kernbuf, "max_cached_mb:", &count) -
452 rc = lprocfs_write_frac_u64_helper(buffer, count, &val, mult);
458 pages_number = (long)val;
460 if (pages_number < 0 || pages_number > totalram_pages) {
461 CERROR("%s: can't set max cache more than %lu MB\n",
462 ll_get_fsname(sb, NULL, 0),
463 totalram_pages >> (20 - PAGE_CACHE_SHIFT));
466 /* Allow enough cache so clients can make well-formed RPCs */
467 pages_number = max_t(long, pages_number, PTLRPC_MAX_BRW_PAGES);
469 spin_lock(&sbi->ll_lock);
470 diff = pages_number - cache->ccc_lru_max;
471 spin_unlock(&sbi->ll_lock);
473 /* easy - add more LRU slots. */
475 atomic_long_add(diff, &cache->ccc_lru_left);
479 env = cl_env_get(&refcheck);
487 /* reduce LRU budget from free slots. */
491 ov = atomic_long_read(&cache->ccc_lru_left);
495 nv = ov > diff ? ov - diff : 0;
496 rc = atomic_long_cmpxchg(&cache->ccc_lru_left, ov, nv);
497 if (likely(ov == rc)) {
507 if (sbi->ll_dt_exp == NULL) { /* being initialized */
512 /* difficult - have to ask OSCs to drop LRU slots. */
514 rc = obd_set_info_async(env, sbi->ll_dt_exp,
515 sizeof(KEY_CACHE_LRU_SHRINK),
516 KEY_CACHE_LRU_SHRINK,
517 sizeof(tmp), &tmp, NULL);
521 cl_env_put(env, &refcheck);
525 spin_lock(&sbi->ll_lock);
526 cache->ccc_lru_max = pages_number;
527 spin_unlock(&sbi->ll_lock);
530 atomic_long_add(nrpages, &cache->ccc_lru_left);
534 LPROC_SEQ_FOPS(ll_max_cached_mb);
536 static int ll_checksum_seq_show(struct seq_file *m, void *v)
538 struct super_block *sb = m->private;
539 struct ll_sb_info *sbi = ll_s2sbi(sb);
541 return seq_printf(m, "%u\n", (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0);
544 static ssize_t ll_checksum_seq_write(struct file *file,
545 const char __user *buffer,
546 size_t count, loff_t *off)
548 struct seq_file *m = file->private_data;
549 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
556 rc = lprocfs_write_helper(buffer, count, &val);
560 sbi->ll_flags |= LL_SBI_CHECKSUM;
562 sbi->ll_flags &= ~LL_SBI_CHECKSUM;
564 rc = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
565 KEY_CHECKSUM, sizeof(val), &val, NULL);
567 CWARN("Failed to set OSC checksum flags: %d\n", rc);
571 LPROC_SEQ_FOPS(ll_checksum);
573 static int ll_max_rw_chunk_seq_show(struct seq_file *m, void *v)
575 struct super_block *sb = m->private;
577 return seq_printf(m, "%lu\n", ll_s2sbi(sb)->ll_max_rw_chunk);
580 static ssize_t ll_max_rw_chunk_seq_write(struct file *file,
581 const char __user *buffer,
582 size_t count, loff_t *off)
584 struct seq_file *m = file->private_data;
585 struct super_block *sb = m->private;
588 rc = lprocfs_write_helper(buffer, count, &val);
591 ll_s2sbi(sb)->ll_max_rw_chunk = val;
594 LPROC_SEQ_FOPS(ll_max_rw_chunk);
596 static int ll_rd_track_id(struct seq_file *m, enum stats_track_type type)
598 struct super_block *sb = m->private;
600 if (ll_s2sbi(sb)->ll_stats_track_type == type) {
601 return seq_printf(m, "%d\n",
602 ll_s2sbi(sb)->ll_stats_track_id);
603 } else if (ll_s2sbi(sb)->ll_stats_track_type == STATS_TRACK_ALL) {
604 return seq_printf(m, "0 (all)\n");
606 return seq_printf(m, "untracked\n");
610 static int ll_wr_track_id(const char __user *buffer, unsigned long count,
611 void *data, enum stats_track_type type)
613 struct super_block *sb = data;
616 rc = lprocfs_write_helper(buffer, count, &pid);
619 ll_s2sbi(sb)->ll_stats_track_id = pid;
621 ll_s2sbi(sb)->ll_stats_track_type = STATS_TRACK_ALL;
623 ll_s2sbi(sb)->ll_stats_track_type = type;
624 lprocfs_clear_stats(ll_s2sbi(sb)->ll_stats);
628 static int ll_track_pid_seq_show(struct seq_file *m, void *v)
630 return ll_rd_track_id(m, STATS_TRACK_PID);
633 static ssize_t ll_track_pid_seq_write(struct file *file,
634 const char __user *buffer,
635 size_t count, loff_t *off)
637 struct seq_file *seq = file->private_data;
638 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PID);
640 LPROC_SEQ_FOPS(ll_track_pid);
642 static int ll_track_ppid_seq_show(struct seq_file *m, void *v)
644 return ll_rd_track_id(m, STATS_TRACK_PPID);
647 static ssize_t ll_track_ppid_seq_write(struct file *file,
648 const char __user *buffer,
649 size_t count, loff_t *off)
651 struct seq_file *seq = file->private_data;
652 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PPID);
654 LPROC_SEQ_FOPS(ll_track_ppid);
656 static int ll_track_gid_seq_show(struct seq_file *m, void *v)
658 return ll_rd_track_id(m, STATS_TRACK_GID);
661 static ssize_t ll_track_gid_seq_write(struct file *file,
662 const char __user *buffer,
663 size_t count, loff_t *off)
665 struct seq_file *seq = file->private_data;
666 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_GID);
668 LPROC_SEQ_FOPS(ll_track_gid);
670 static int ll_statahead_max_seq_show(struct seq_file *m, void *v)
672 struct super_block *sb = m->private;
673 struct ll_sb_info *sbi = ll_s2sbi(sb);
675 return seq_printf(m, "%u\n", sbi->ll_sa_max);
678 static ssize_t ll_statahead_max_seq_write(struct file *file,
679 const char __user *buffer,
680 size_t count, loff_t *off)
682 struct seq_file *m = file->private_data;
683 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
686 rc = lprocfs_write_helper(buffer, count, &val);
690 if (val >= 0 && val <= LL_SA_RPC_MAX)
691 sbi->ll_sa_max = val;
693 CERROR("Bad statahead_max value %d. Valid values are in the "
694 "range [0, %d]\n", val, LL_SA_RPC_MAX);
698 LPROC_SEQ_FOPS(ll_statahead_max);
700 static int ll_statahead_agl_seq_show(struct seq_file *m, void *v)
702 struct super_block *sb = m->private;
703 struct ll_sb_info *sbi = ll_s2sbi(sb);
705 return seq_printf(m, "%u\n",
706 sbi->ll_flags & LL_SBI_AGL_ENABLED ? 1 : 0);
709 static ssize_t ll_statahead_agl_seq_write(struct file *file,
710 const char __user *buffer,
711 size_t count, loff_t *off)
713 struct seq_file *m = file->private_data;
714 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
717 rc = lprocfs_write_helper(buffer, count, &val);
722 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
724 sbi->ll_flags &= ~LL_SBI_AGL_ENABLED;
728 LPROC_SEQ_FOPS(ll_statahead_agl);
730 static int ll_statahead_stats_seq_show(struct seq_file *m, void *v)
732 struct super_block *sb = m->private;
733 struct ll_sb_info *sbi = ll_s2sbi(sb);
736 "statahead total: %u\n"
737 "statahead wrong: %u\n"
739 atomic_read(&sbi->ll_sa_total),
740 atomic_read(&sbi->ll_sa_wrong),
741 atomic_read(&sbi->ll_agl_total));
743 LPROC_SEQ_FOPS_RO(ll_statahead_stats);
745 static int ll_lazystatfs_seq_show(struct seq_file *m, void *v)
747 struct super_block *sb = m->private;
748 struct ll_sb_info *sbi = ll_s2sbi(sb);
750 return seq_printf(m, "%u\n",
751 (sbi->ll_flags & LL_SBI_LAZYSTATFS) ? 1 : 0);
754 static ssize_t ll_lazystatfs_seq_write(struct file *file,
755 const char __user *buffer,
756 size_t count, loff_t *off)
758 struct seq_file *m = file->private_data;
759 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
762 rc = lprocfs_write_helper(buffer, count, &val);
767 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
769 sbi->ll_flags &= ~LL_SBI_LAZYSTATFS;
773 LPROC_SEQ_FOPS(ll_lazystatfs);
775 static int ll_max_easize_seq_show(struct seq_file *m, void *v)
777 struct super_block *sb = m->private;
778 struct ll_sb_info *sbi = ll_s2sbi(sb);
782 rc = ll_get_max_mdsize(sbi, &ealen);
786 return seq_printf(m, "%u\n", ealen);
788 LPROC_SEQ_FOPS_RO(ll_max_easize);
791 * Get default_easize.
793 * \see client_obd::cl_default_mds_easize
795 * \param[in] m seq_file handle
796 * \param[in] v unused for single entry
798 * \retval 0 on success
799 * \retval negative negated errno on failure
801 static int ll_default_easize_seq_show(struct seq_file *m, void *v)
803 struct super_block *sb = m->private;
804 struct ll_sb_info *sbi = ll_s2sbi(sb);
808 rc = ll_get_default_mdsize(sbi, &ealen);
812 return seq_printf(m, "%u\n", ealen);
816 * Set default_easize.
818 * Range checking on the passed value is handled by
819 * ll_set_default_mdsize().
821 * \see client_obd::cl_default_mds_easize
823 * \param[in] file proc file
824 * \param[in] buffer string passed from user space
825 * \param[in] count \a buffer length
826 * \param[in] off unused for single entry
828 * \retval positive \a count on success
829 * \retval negative negated errno on failure
831 static ssize_t ll_default_easize_seq_write(struct file *file,
832 const char __user *buffer,
833 size_t count, loff_t *unused)
835 struct seq_file *seq = file->private_data;
836 struct super_block *sb = (struct super_block *)seq->private;
837 struct ll_sb_info *sbi = ll_s2sbi(sb);
844 rc = lprocfs_write_helper(buffer, count, &val);
848 rc = ll_set_default_mdsize(sbi, val);
854 LPROC_SEQ_FOPS(ll_default_easize);
856 static int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
858 const char *str[] = LL_SBI_FLAGS;
859 struct super_block *sb = m->private;
860 int flags = ll_s2sbi(sb)->ll_flags;
864 if (ARRAY_SIZE(str) <= i) {
865 CERROR("%s: Revise array LL_SBI_FLAGS to match sbi "
866 "flags please.\n", ll_get_fsname(sb, NULL, 0));
871 seq_printf(m, "%s ", str[i]);
875 seq_printf(m, "\b\n");
878 LPROC_SEQ_FOPS_RO(ll_sbi_flags);
880 static int ll_unstable_stats_seq_show(struct seq_file *m, void *v)
882 struct super_block *sb = m->private;
883 struct ll_sb_info *sbi = ll_s2sbi(sb);
884 struct cl_client_cache *cache = sbi->ll_cache;
888 pages = atomic_long_read(&cache->ccc_unstable_nr);
889 mb = (pages * PAGE_CACHE_SIZE) >> 20;
891 return seq_printf(m, "unstable_check: %8d\n"
892 "unstable_pages: %12ld\n"
893 "unstable_mb: %8d\n",
894 cache->ccc_unstable_check, pages, mb);
897 static ssize_t ll_unstable_stats_seq_write(struct file *file,
898 const char __user *buffer,
899 size_t count, loff_t *unused)
901 struct seq_file *seq = file->private_data;
902 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)seq->private);
908 if (count >= sizeof(kernbuf))
911 if (copy_from_user(kernbuf, buffer, count))
915 buffer += lprocfs_find_named_value(kernbuf, "unstable_check:", &count) -
917 rc = lprocfs_write_helper(buffer, count, &val);
921 /* borrow lru lock to set the value */
922 spin_lock(&sbi->ll_cache->ccc_lru_lock);
923 sbi->ll_cache->ccc_unstable_check = !!val;
924 spin_unlock(&sbi->ll_cache->ccc_lru_lock);
928 LPROC_SEQ_FOPS(ll_unstable_stats);
930 static int ll_root_squash_seq_show(struct seq_file *m, void *v)
932 struct super_block *sb = m->private;
933 struct ll_sb_info *sbi = ll_s2sbi(sb);
934 struct root_squash_info *squash = &sbi->ll_squash;
936 return seq_printf(m, "%u:%u\n", squash->rsi_uid, squash->rsi_gid);
939 static ssize_t ll_root_squash_seq_write(struct file *file,
940 const char __user *buffer,
941 size_t count, loff_t *off)
943 struct seq_file *m = file->private_data;
944 struct super_block *sb = m->private;
945 struct ll_sb_info *sbi = ll_s2sbi(sb);
946 struct root_squash_info *squash = &sbi->ll_squash;
948 return lprocfs_wr_root_squash(buffer, count, squash,
949 ll_get_fsname(sb, NULL, 0));
951 LPROC_SEQ_FOPS(ll_root_squash);
953 static int ll_nosquash_nids_seq_show(struct seq_file *m, void *v)
955 struct super_block *sb = m->private;
956 struct ll_sb_info *sbi = ll_s2sbi(sb);
957 struct root_squash_info *squash = &sbi->ll_squash;
960 down_read(&squash->rsi_sem);
961 if (!list_empty(&squash->rsi_nosquash_nids)) {
962 len = cfs_print_nidlist(m->buf + m->count, m->size - m->count,
963 &squash->rsi_nosquash_nids);
965 rc = seq_printf(m, "\n");
967 rc = seq_printf(m, "NONE\n");
969 up_read(&squash->rsi_sem);
974 static ssize_t ll_nosquash_nids_seq_write(struct file *file,
975 const char __user *buffer,
976 size_t count, loff_t *off)
978 struct seq_file *m = file->private_data;
979 struct super_block *sb = m->private;
980 struct ll_sb_info *sbi = ll_s2sbi(sb);
981 struct root_squash_info *squash = &sbi->ll_squash;
984 rc = lprocfs_wr_nosquash_nids(buffer, count, squash,
985 ll_get_fsname(sb, NULL, 0));
989 ll_compute_rootsquash_state(sbi);
993 LPROC_SEQ_FOPS(ll_nosquash_nids);
995 struct lprocfs_vars lprocfs_llite_obd_vars[] = {
997 .fops = &ll_sb_uuid_fops },
999 .fops = &ll_fstype_fops },
1001 .fops = &ll_site_stats_fops },
1002 { .name = "blocksize",
1003 .fops = &ll_blksize_fops },
1004 { .name = "kbytestotal",
1005 .fops = &ll_kbytestotal_fops },
1006 { .name = "kbytesfree",
1007 .fops = &ll_kbytesfree_fops },
1008 { .name = "kbytesavail",
1009 .fops = &ll_kbytesavail_fops },
1010 { .name = "filestotal",
1011 .fops = &ll_filestotal_fops },
1012 { .name = "filesfree",
1013 .fops = &ll_filesfree_fops },
1014 { .name = "client_type",
1015 .fops = &ll_client_type_fops },
1016 { .name = "max_read_ahead_mb",
1017 .fops = &ll_max_readahead_mb_fops },
1018 { .name = "max_read_ahead_per_file_mb",
1019 .fops = &ll_max_readahead_per_file_mb_fops },
1020 { .name = "max_read_ahead_whole_mb",
1021 .fops = &ll_max_read_ahead_whole_mb_fops },
1022 { .name = "max_cached_mb",
1023 .fops = &ll_max_cached_mb_fops },
1024 { .name = "checksum_pages",
1025 .fops = &ll_checksum_fops },
1026 { .name = "max_rw_chunk",
1027 .fops = &ll_max_rw_chunk_fops },
1028 { .name = "stats_track_pid",
1029 .fops = &ll_track_pid_fops },
1030 { .name = "stats_track_ppid",
1031 .fops = &ll_track_ppid_fops },
1032 { .name = "stats_track_gid",
1033 .fops = &ll_track_gid_fops },
1034 { .name = "statahead_max",
1035 .fops = &ll_statahead_max_fops },
1036 { .name = "statahead_agl",
1037 .fops = &ll_statahead_agl_fops },
1038 { .name = "statahead_stats",
1039 .fops = &ll_statahead_stats_fops },
1040 { .name = "lazystatfs",
1041 .fops = &ll_lazystatfs_fops },
1042 { .name = "max_easize",
1043 .fops = &ll_max_easize_fops },
1044 { .name = "default_easize",
1045 .fops = &ll_default_easize_fops },
1046 { .name = "sbi_flags",
1047 .fops = &ll_sbi_flags_fops },
1048 { .name = "xattr_cache",
1049 .fops = &ll_xattr_cache_fops },
1050 { .name = "unstable_stats",
1051 .fops = &ll_unstable_stats_fops },
1052 { .name = "root_squash",
1053 .fops = &ll_root_squash_fops },
1054 { .name = "nosquash_nids",
1055 .fops = &ll_nosquash_nids_fops },
1059 #define MAX_STRING_SIZE 128
1061 static const struct llite_file_opcode {
1065 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
1066 /* file operation */
1067 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
1068 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
1069 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1071 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1073 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
1075 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
1077 { LPROC_LL_OSC_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1079 { LPROC_LL_OSC_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1081 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
1082 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
1083 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
1084 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
1085 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
1086 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
1087 { LPROC_LL_READDIR, LPROCFS_TYPE_REGS, "readdir" },
1088 /* inode operation */
1089 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
1090 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "truncate" },
1091 { LPROC_LL_FLOCK, LPROCFS_TYPE_REGS, "flock" },
1092 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
1093 /* dir inode operation */
1094 { LPROC_LL_CREATE, LPROCFS_TYPE_REGS, "create" },
1095 { LPROC_LL_LINK, LPROCFS_TYPE_REGS, "link" },
1096 { LPROC_LL_UNLINK, LPROCFS_TYPE_REGS, "unlink" },
1097 { LPROC_LL_SYMLINK, LPROCFS_TYPE_REGS, "symlink" },
1098 { LPROC_LL_MKDIR, LPROCFS_TYPE_REGS, "mkdir" },
1099 { LPROC_LL_RMDIR, LPROCFS_TYPE_REGS, "rmdir" },
1100 { LPROC_LL_MKNOD, LPROCFS_TYPE_REGS, "mknod" },
1101 { LPROC_LL_RENAME, LPROCFS_TYPE_REGS, "rename" },
1102 /* special inode operation */
1103 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
1104 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
1105 { LPROC_LL_SETXATTR, LPROCFS_TYPE_REGS, "setxattr" },
1106 { LPROC_LL_GETXATTR, LPROCFS_TYPE_REGS, "getxattr" },
1107 { LPROC_LL_GETXATTR_HITS, LPROCFS_TYPE_REGS, "getxattr_hits" },
1108 { LPROC_LL_LISTXATTR, LPROCFS_TYPE_REGS, "listxattr" },
1109 { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_REGS, "removexattr" },
1110 { LPROC_LL_INODE_PERM, LPROCFS_TYPE_REGS, "inode_permission" },
1113 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
1117 if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
1118 lprocfs_counter_add(sbi->ll_stats, op, count);
1119 else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
1120 sbi->ll_stats_track_id == current->pid)
1121 lprocfs_counter_add(sbi->ll_stats, op, count);
1122 else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
1123 sbi->ll_stats_track_id == current->parent->pid)
1124 lprocfs_counter_add(sbi->ll_stats, op, count);
1125 else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
1126 sbi->ll_stats_track_id ==
1127 from_kgid(&init_user_ns, current_gid()))
1128 lprocfs_counter_add(sbi->ll_stats, op, count);
1130 EXPORT_SYMBOL(ll_stats_ops_tally);
1132 static const char *ra_stat_string[] = {
1133 [RA_STAT_HIT] = "hits",
1134 [RA_STAT_MISS] = "misses",
1135 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
1136 [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
1137 [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page",
1138 [RA_STAT_FAILED_MATCH] = "failed lock match",
1139 [RA_STAT_DISCARDED] = "read but discarded",
1140 [RA_STAT_ZERO_LEN] = "zero length file",
1141 [RA_STAT_ZERO_WINDOW] = "zero size window",
1142 [RA_STAT_EOF] = "read-ahead to EOF",
1143 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
1144 [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",
1145 [RA_STAT_FAILED_REACH_END] = "failed to reach end"
1148 LPROC_SEQ_FOPS_RO_TYPE(llite, name);
1149 LPROC_SEQ_FOPS_RO_TYPE(llite, uuid);
1151 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
1152 struct super_block *sb, char *osc, char *mdc)
1154 struct lprocfs_vars lvars[2];
1155 struct lustre_sb_info *lsi = s2lsi(sb);
1156 struct ll_sb_info *sbi = ll_s2sbi(sb);
1157 struct obd_device *obd;
1158 struct proc_dir_entry *dir;
1159 char name[MAX_STRING_SIZE + 1], *ptr;
1160 int err, id, len, rc;
1163 memset(lvars, 0, sizeof(lvars));
1165 name[MAX_STRING_SIZE] = '\0';
1166 lvars[0].name = name;
1168 LASSERT(sbi != NULL);
1169 LASSERT(mdc != NULL);
1170 LASSERT(osc != NULL);
1173 len = strlen(lsi->lsi_lmd->lmd_profile);
1174 ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
1175 if (ptr && (strcmp(ptr, "-client") == 0))
1179 snprintf(name, MAX_STRING_SIZE, "%.*s-%p", len,
1180 lsi->lsi_lmd->lmd_profile, sb);
1182 sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
1183 if (IS_ERR(sbi->ll_proc_root)) {
1184 err = PTR_ERR(sbi->ll_proc_root);
1185 sbi->ll_proc_root = NULL;
1189 rc = lprocfs_seq_create(sbi->ll_proc_root, "dump_page_cache", 0444,
1190 &vvp_dump_pgcache_file_ops, sbi);
1192 CWARN("Error adding the dump_page_cache file\n");
1194 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats", 0644,
1195 &ll_rw_extents_stats_fops, sbi);
1197 CWARN("Error adding the extent_stats file\n");
1199 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats_per_process",
1200 0644, &ll_rw_extents_stats_pp_fops, sbi);
1202 CWARN("Error adding the extents_stats_per_process file\n");
1204 rc = lprocfs_seq_create(sbi->ll_proc_root, "offset_stats", 0644,
1205 &ll_rw_offset_stats_fops, sbi);
1207 CWARN("Error adding the offset_stats file\n");
1209 /* File operations stats */
1210 sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
1211 LPROCFS_STATS_FLAG_NONE);
1212 if (sbi->ll_stats == NULL)
1213 GOTO(out, err = -ENOMEM);
1214 /* do counter init */
1215 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
1216 __u32 type = llite_opcode_table[id].type;
1218 if (type & LPROCFS_TYPE_REGS)
1220 else if (type & LPROCFS_TYPE_BYTES)
1222 else if (type & LPROCFS_TYPE_PAGES)
1224 lprocfs_counter_init(sbi->ll_stats,
1225 llite_opcode_table[id].opcode,
1226 (type & LPROCFS_CNTR_AVGMINMAX),
1227 llite_opcode_table[id].opname, ptr);
1229 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats);
1233 sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
1234 LPROCFS_STATS_FLAG_NONE);
1235 if (sbi->ll_ra_stats == NULL)
1236 GOTO(out, err = -ENOMEM);
1238 for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
1239 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
1240 ra_stat_string[id], "pages");
1241 err = lprocfs_register_stats(sbi->ll_proc_root, "read_ahead_stats",
1247 err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_llite_obd_vars, sb);
1252 obd = class_name2obd(mdc);
1254 LASSERT(obd != NULL);
1255 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1256 LASSERT(obd->obd_type->typ_name != NULL);
1258 dir = proc_mkdir(obd->obd_type->typ_name, sbi->ll_proc_root);
1260 GOTO(out, err = -ENOMEM);
1262 snprintf(name, MAX_STRING_SIZE, "common_name");
1263 lvars[0].fops = &llite_name_fops;
1264 err = lprocfs_add_vars(dir, lvars, obd);
1268 snprintf(name, MAX_STRING_SIZE, "uuid");
1269 lvars[0].fops = &llite_uuid_fops;
1270 err = lprocfs_add_vars(dir, lvars, obd);
1275 obd = class_name2obd(osc);
1277 LASSERT(obd != NULL);
1278 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1279 LASSERT(obd->obd_type->typ_name != NULL);
1281 dir = proc_mkdir(obd->obd_type->typ_name, sbi->ll_proc_root);
1283 GOTO(out, err = -ENOMEM);
1285 snprintf(name, MAX_STRING_SIZE, "common_name");
1286 lvars[0].fops = &llite_name_fops;
1287 err = lprocfs_add_vars(dir, lvars, obd);
1291 snprintf(name, MAX_STRING_SIZE, "uuid");
1292 lvars[0].fops = &llite_uuid_fops;
1293 err = lprocfs_add_vars(dir, lvars, obd);
1296 lprocfs_remove(&sbi->ll_proc_root);
1297 lprocfs_free_stats(&sbi->ll_ra_stats);
1298 lprocfs_free_stats(&sbi->ll_stats);
1303 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
1305 if (sbi->ll_proc_root) {
1306 lprocfs_remove(&sbi->ll_proc_root);
1307 lprocfs_free_stats(&sbi->ll_ra_stats);
1308 lprocfs_free_stats(&sbi->ll_stats);
1311 #undef MAX_STRING_SIZE
1313 #define pct(a,b) (b ? a * 100 / b : 0)
1315 static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
1316 struct seq_file *seq, int which)
1318 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
1319 unsigned long start, end, r, w;
1320 char *unitp = "KMGTPEZY";
1322 struct per_process_info *pp_info = &io_extents->pp_extents[which];
1328 for(i = 0; i < LL_HIST_MAX; i++) {
1329 read_tot += pp_info->pp_r_hist.oh_buckets[i];
1330 write_tot += pp_info->pp_w_hist.oh_buckets[i];
1333 for(i = 0; i < LL_HIST_MAX; i++) {
1334 r = pp_info->pp_r_hist.oh_buckets[i];
1335 w = pp_info->pp_w_hist.oh_buckets[i];
1338 end = 1 << (i + LL_HIST_START - units);
1339 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu | "
1340 "%14lu %4lu %4lu\n", start, *unitp, end, *unitp,
1341 (i == LL_HIST_MAX - 1) ? '+' : ' ',
1342 r, pct(r, read_tot), pct(read_cum, read_tot),
1343 w, pct(w, write_tot), pct(write_cum, write_tot));
1345 if (start == 1<<10) {
1350 if (read_cum == read_tot && write_cum == write_tot)
1355 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
1358 struct ll_sb_info *sbi = seq->private;
1359 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1362 do_gettimeofday(&now);
1364 if (!sbi->ll_rw_stats_on) {
1365 seq_printf(seq, "disabled\n"
1366 "write anything in this file to activate, "
1367 "then 0 or \"[D/d]isabled\" to deactivate\n");
1370 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1371 now.tv_sec, now.tv_usec);
1372 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1373 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1374 "extents", "calls", "%", "cum%",
1375 "calls", "%", "cum%");
1376 spin_lock(&sbi->ll_pp_extent_lock);
1377 for (k = 0; k < LL_PROCESS_HIST_MAX; k++) {
1378 if (io_extents->pp_extents[k].pid != 0) {
1379 seq_printf(seq, "\nPID: %d\n",
1380 io_extents->pp_extents[k].pid);
1381 ll_display_extents_info(io_extents, seq, k);
1384 spin_unlock(&sbi->ll_pp_extent_lock);
1388 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
1389 const char __user *buf,
1393 struct seq_file *seq = file->private_data;
1394 struct ll_sb_info *sbi = seq->private;
1395 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1397 int value = 1, rc = 0;
1402 rc = lprocfs_write_helper(buf, len, &value);
1403 if (rc < 0 && len < 16) {
1406 if (copy_from_user(kernbuf, buf, len))
1410 if (kernbuf[len - 1] == '\n')
1411 kernbuf[len - 1] = 0;
1413 if (strcmp(kernbuf, "disabled") == 0 ||
1414 strcmp(kernbuf, "Disabled") == 0)
1419 sbi->ll_rw_stats_on = 0;
1421 sbi->ll_rw_stats_on = 1;
1423 spin_lock(&sbi->ll_pp_extent_lock);
1424 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1425 io_extents->pp_extents[i].pid = 0;
1426 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1427 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1429 spin_unlock(&sbi->ll_pp_extent_lock);
1433 LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
1435 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
1438 struct ll_sb_info *sbi = seq->private;
1439 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1441 do_gettimeofday(&now);
1443 if (!sbi->ll_rw_stats_on) {
1444 seq_printf(seq, "disabled\n"
1445 "write anything in this file to activate, "
1446 "then 0 or \"[D/d]isabled\" to deactivate\n");
1449 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1450 now.tv_sec, now.tv_usec);
1452 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1453 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1454 "extents", "calls", "%", "cum%",
1455 "calls", "%", "cum%");
1456 spin_lock(&sbi->ll_lock);
1457 ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
1458 spin_unlock(&sbi->ll_lock);
1463 static ssize_t ll_rw_extents_stats_seq_write(struct file *file,
1464 const char __user *buf,
1465 size_t len, loff_t *off)
1467 struct seq_file *seq = file->private_data;
1468 struct ll_sb_info *sbi = seq->private;
1469 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1471 int value = 1, rc = 0;
1476 rc = lprocfs_write_helper(buf, len, &value);
1477 if (rc < 0 && len < 16) {
1480 if (copy_from_user(kernbuf, buf, len))
1484 if (kernbuf[len - 1] == '\n')
1485 kernbuf[len - 1] = 0;
1487 if (strcmp(kernbuf, "disabled") == 0 ||
1488 strcmp(kernbuf, "Disabled") == 0)
1493 sbi->ll_rw_stats_on = 0;
1495 sbi->ll_rw_stats_on = 1;
1497 spin_lock(&sbi->ll_pp_extent_lock);
1498 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
1499 io_extents->pp_extents[i].pid = 0;
1500 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1501 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1503 spin_unlock(&sbi->ll_pp_extent_lock);
1507 LPROC_SEQ_FOPS(ll_rw_extents_stats);
1509 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
1510 struct ll_file_data *file, loff_t pos,
1511 size_t count, int rw)
1514 struct ll_rw_process_info *process;
1515 struct ll_rw_process_info *offset;
1516 int *off_count = &sbi->ll_rw_offset_entry_count;
1517 int *process_count = &sbi->ll_offset_process_count;
1518 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1520 if(!sbi->ll_rw_stats_on)
1522 process = sbi->ll_rw_process_info;
1523 offset = sbi->ll_rw_offset_info;
1525 spin_lock(&sbi->ll_pp_extent_lock);
1526 /* Extent statistics */
1527 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1528 if(io_extents->pp_extents[i].pid == pid) {
1536 sbi->ll_extent_process_count =
1537 (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1538 cur = sbi->ll_extent_process_count;
1539 io_extents->pp_extents[cur].pid = pid;
1540 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1541 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1544 for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
1545 (i < (LL_HIST_MAX - 1)); i++);
1547 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1548 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1550 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1551 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1553 spin_unlock(&sbi->ll_pp_extent_lock);
1555 spin_lock(&sbi->ll_process_lock);
1556 /* Offset statistics */
1557 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1558 if (process[i].rw_pid == pid) {
1559 if (process[i].rw_last_file != file) {
1560 process[i].rw_range_start = pos;
1561 process[i].rw_last_file_pos = pos + count;
1562 process[i].rw_smallest_extent = count;
1563 process[i].rw_largest_extent = count;
1564 process[i].rw_offset = 0;
1565 process[i].rw_last_file = file;
1566 spin_unlock(&sbi->ll_process_lock);
1569 if (process[i].rw_last_file_pos != pos) {
1571 (*off_count + 1) % LL_OFFSET_HIST_MAX;
1572 offset[*off_count].rw_op = process[i].rw_op;
1573 offset[*off_count].rw_pid = pid;
1574 offset[*off_count].rw_range_start =
1575 process[i].rw_range_start;
1576 offset[*off_count].rw_range_end =
1577 process[i].rw_last_file_pos;
1578 offset[*off_count].rw_smallest_extent =
1579 process[i].rw_smallest_extent;
1580 offset[*off_count].rw_largest_extent =
1581 process[i].rw_largest_extent;
1582 offset[*off_count].rw_offset =
1583 process[i].rw_offset;
1584 process[i].rw_op = rw;
1585 process[i].rw_range_start = pos;
1586 process[i].rw_smallest_extent = count;
1587 process[i].rw_largest_extent = count;
1588 process[i].rw_offset = pos -
1589 process[i].rw_last_file_pos;
1591 if(process[i].rw_smallest_extent > count)
1592 process[i].rw_smallest_extent = count;
1593 if(process[i].rw_largest_extent < count)
1594 process[i].rw_largest_extent = count;
1595 process[i].rw_last_file_pos = pos + count;
1596 spin_unlock(&sbi->ll_process_lock);
1600 *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
1601 process[*process_count].rw_pid = pid;
1602 process[*process_count].rw_op = rw;
1603 process[*process_count].rw_range_start = pos;
1604 process[*process_count].rw_last_file_pos = pos + count;
1605 process[*process_count].rw_smallest_extent = count;
1606 process[*process_count].rw_largest_extent = count;
1607 process[*process_count].rw_offset = 0;
1608 process[*process_count].rw_last_file = file;
1609 spin_unlock(&sbi->ll_process_lock);
1612 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1615 struct ll_sb_info *sbi = seq->private;
1616 struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
1617 struct ll_rw_process_info *process = sbi->ll_rw_process_info;
1620 do_gettimeofday(&now);
1622 if (!sbi->ll_rw_stats_on) {
1623 seq_printf(seq, "disabled\n"
1624 "write anything in this file to activate, "
1625 "then 0 or \"[D/d]isabled\" to deactivate\n");
1628 spin_lock(&sbi->ll_process_lock);
1630 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1631 now.tv_sec, now.tv_usec);
1632 seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
1633 "R/W", "PID", "RANGE START", "RANGE END",
1634 "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
1636 /* We stored the discontiguous offsets here; print them first */
1637 for (i = 0; i < LL_OFFSET_HIST_MAX; i++) {
1638 if (offset[i].rw_pid != 0)
1640 "%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1641 offset[i].rw_op == READ ? 'R' : 'W',
1643 offset[i].rw_range_start,
1644 offset[i].rw_range_end,
1645 (unsigned long)offset[i].rw_smallest_extent,
1646 (unsigned long)offset[i].rw_largest_extent,
1647 offset[i].rw_offset);
1650 /* Then print the current offsets for each process */
1651 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1652 if (process[i].rw_pid != 0)
1654 "%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1655 process[i].rw_op == READ ? 'R' : 'W',
1657 process[i].rw_range_start,
1658 process[i].rw_last_file_pos,
1659 (unsigned long)process[i].rw_smallest_extent,
1660 (unsigned long)process[i].rw_largest_extent,
1661 process[i].rw_offset);
1663 spin_unlock(&sbi->ll_process_lock);
1668 static ssize_t ll_rw_offset_stats_seq_write(struct file *file,
1669 const char __user *buf,
1670 size_t len, loff_t *off)
1672 struct seq_file *seq = file->private_data;
1673 struct ll_sb_info *sbi = seq->private;
1674 struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
1675 struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
1676 int value = 1, rc = 0;
1681 rc = lprocfs_write_helper(buf, len, &value);
1683 if (rc < 0 && len < 16) {
1686 if (copy_from_user(kernbuf, buf, len))
1690 if (kernbuf[len - 1] == '\n')
1691 kernbuf[len - 1] = 0;
1693 if (strcmp(kernbuf, "disabled") == 0 ||
1694 strcmp(kernbuf, "Disabled") == 0)
1699 sbi->ll_rw_stats_on = 0;
1701 sbi->ll_rw_stats_on = 1;
1703 spin_lock(&sbi->ll_process_lock);
1704 sbi->ll_offset_process_count = 0;
1705 sbi->ll_rw_offset_entry_count = 0;
1706 memset(process_info, 0, sizeof(struct ll_rw_process_info) *
1707 LL_PROCESS_HIST_MAX);
1708 memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
1709 LL_OFFSET_HIST_MAX);
1710 spin_unlock(&sbi->ll_process_lock);
1715 LPROC_SEQ_FOPS(ll_rw_offset_stats);
1716 #endif /* CONFIG_PROC_FS */