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, 2015, 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 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 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 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 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 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 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);
179 LASSERT(sbi != NULL);
181 seq_puts(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 seq_printf(m, "%s\n", sb->s_type->name);
194 LPROC_SEQ_FOPS_RO(ll_fstype);
196 static int ll_sb_uuid_seq_show(struct seq_file *m, void *v)
198 struct super_block *sb = m->private;
201 seq_printf(m, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
204 LPROC_SEQ_FOPS_RO(ll_sb_uuid);
206 static int ll_xattr_cache_seq_show(struct seq_file *m, void *v)
208 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
210 seq_printf(m, "%u\n", sbi->ll_xattr_cache_enabled);
214 static ssize_t ll_xattr_cache_seq_write(struct file *file,
215 const char __user *buffer,
216 size_t count, loff_t *off)
218 struct seq_file *m = file->private_data;
219 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
223 rc = lprocfs_str_to_s64(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);
276 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
280 pages_number >>= PAGE_CACHE_SHIFT;
282 if (pages_number < 0 || pages_number > totalram_pages / 2) {
284 CERROR("%s: can't set max_readahead_mb=%lu > %luMB\n",
285 ll_get_fsname(sb, NULL, 0),
286 (unsigned long)pages_number >> (20 - PAGE_CACHE_SHIFT),
287 totalram_pages >> (20 - PAGE_CACHE_SHIFT + 1));
291 spin_lock(&sbi->ll_lock);
292 sbi->ll_ra_info.ra_max_pages = pages_number;
293 spin_unlock(&sbi->ll_lock);
296 LPROC_SEQ_FOPS(ll_max_readahead_mb);
298 static int ll_max_readahead_per_file_mb_seq_show(struct seq_file *m, void *v)
300 struct super_block *sb = m->private;
301 struct ll_sb_info *sbi = ll_s2sbi(sb);
305 spin_lock(&sbi->ll_lock);
306 pages_number = sbi->ll_ra_info.ra_max_pages_per_file;
307 spin_unlock(&sbi->ll_lock);
309 mult = 1 << (20 - PAGE_CACHE_SHIFT);
310 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
314 ll_max_readahead_per_file_mb_seq_write(struct file *file,
315 const char __user *buffer,
316 size_t count, loff_t *off)
318 struct seq_file *m = file->private_data;
319 struct super_block *sb = m->private;
320 struct ll_sb_info *sbi = ll_s2sbi(sb);
324 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
328 pages_number >>= PAGE_CACHE_SHIFT;
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=%lu > "
332 "max_read_ahead_mb=%lu\n", ll_get_fsname(sb, NULL, 0),
333 (unsigned long)pages_number >> (20 - PAGE_CACHE_SHIFT),
334 sbi->ll_ra_info.ra_max_pages >> (20 - PAGE_CACHE_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);
371 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
375 pages_number >>= PAGE_CACHE_SHIFT;
377 /* Cap this at the current max readahead window size, the readahead
378 * algorithm does this anyway so it's pointless to set it larger. */
379 if (pages_number < 0 ||
380 pages_number > sbi->ll_ra_info.ra_max_pages_per_file) {
381 int pages_shift = 20 - PAGE_CACHE_SHIFT;
382 CERROR("%s: can't set max_read_ahead_whole_mb=%lu > "
383 "max_read_ahead_per_file_mb=%lu\n",
384 ll_get_fsname(sb, NULL, 0),
385 (unsigned long)pages_number >> pages_shift,
386 sbi->ll_ra_info.ra_max_pages_per_file >> pages_shift);
390 spin_lock(&sbi->ll_lock);
391 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = pages_number;
392 spin_unlock(&sbi->ll_lock);
395 LPROC_SEQ_FOPS(ll_max_read_ahead_whole_mb);
397 static int ll_max_cached_mb_seq_show(struct seq_file *m, void *v)
399 struct super_block *sb = m->private;
400 struct ll_sb_info *sbi = ll_s2sbi(sb);
401 struct cl_client_cache *cache = sbi->ll_cache;
402 int shift = 20 - PAGE_CACHE_SHIFT;
406 max_cached_mb = cache->ccc_lru_max >> shift;
407 unused_mb = atomic_long_read(&cache->ccc_lru_left) >> shift;
408 seq_printf(m, "users: %d\n"
409 "max_cached_mb: %ld\n"
412 "reclaim_count: %u\n",
413 atomic_read(&cache->ccc_users),
415 max_cached_mb - unused_mb,
417 cache->ccc_lru_shrinkers);
422 ll_max_cached_mb_seq_write(struct file *file, const char __user *buffer,
423 size_t count, loff_t *off)
425 struct seq_file *m = file->private_data;
426 struct super_block *sb = m->private;
427 struct ll_sb_info *sbi = ll_s2sbi(sb);
428 struct cl_client_cache *cache = sbi->ll_cache;
438 if (count >= sizeof(kernbuf))
441 if (copy_from_user(kernbuf, buffer, count))
445 buffer += lprocfs_find_named_value(kernbuf, "max_cached_mb:", &count) -
447 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
451 pages_number >>= PAGE_CACHE_SHIFT;
453 if (pages_number < 0 || pages_number > totalram_pages) {
454 CERROR("%s: can't set max cache more than %lu MB\n",
455 ll_get_fsname(sb, NULL, 0),
456 totalram_pages >> (20 - PAGE_CACHE_SHIFT));
459 /* Allow enough cache so clients can make well-formed RPCs */
460 pages_number = max_t(long, pages_number, PTLRPC_MAX_BRW_PAGES);
462 spin_lock(&sbi->ll_lock);
463 diff = pages_number - cache->ccc_lru_max;
464 spin_unlock(&sbi->ll_lock);
466 /* easy - add more LRU slots. */
468 atomic_long_add(diff, &cache->ccc_lru_left);
472 env = cl_env_get(&refcheck);
480 /* reduce LRU budget from free slots. */
484 ov = atomic_long_read(&cache->ccc_lru_left);
488 nv = ov > diff ? ov - diff : 0;
489 rc = atomic_long_cmpxchg(&cache->ccc_lru_left, ov, nv);
490 if (likely(ov == rc)) {
500 if (sbi->ll_dt_exp == NULL) { /* being initialized */
505 /* difficult - have to ask OSCs to drop LRU slots. */
507 rc = obd_set_info_async(env, sbi->ll_dt_exp,
508 sizeof(KEY_CACHE_LRU_SHRINK),
509 KEY_CACHE_LRU_SHRINK,
510 sizeof(tmp), &tmp, NULL);
514 cl_env_put(env, &refcheck);
518 spin_lock(&sbi->ll_lock);
519 cache->ccc_lru_max = pages_number;
520 spin_unlock(&sbi->ll_lock);
523 atomic_long_add(nrpages, &cache->ccc_lru_left);
527 LPROC_SEQ_FOPS(ll_max_cached_mb);
529 static int ll_checksum_seq_show(struct seq_file *m, void *v)
531 struct super_block *sb = m->private;
532 struct ll_sb_info *sbi = ll_s2sbi(sb);
534 seq_printf(m, "%u\n", (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0);
538 static ssize_t ll_checksum_seq_write(struct file *file,
539 const char __user *buffer,
540 size_t count, loff_t *off)
542 struct seq_file *m = file->private_data;
543 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
551 rc = lprocfs_str_to_s64(buffer, count, &val);
555 sbi->ll_flags |= LL_SBI_CHECKSUM;
557 sbi->ll_flags &= ~LL_SBI_CHECKSUM;
559 rc = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
560 KEY_CHECKSUM, sizeof(val), &val, NULL);
562 CWARN("Failed to set OSC checksum flags: %d\n", rc);
566 LPROC_SEQ_FOPS(ll_checksum);
568 static int ll_rd_track_id(struct seq_file *m, enum stats_track_type type)
570 struct super_block *sb = m->private;
572 if (ll_s2sbi(sb)->ll_stats_track_type == type) {
573 seq_printf(m, "%d\n",
574 ll_s2sbi(sb)->ll_stats_track_id);
575 } else if (ll_s2sbi(sb)->ll_stats_track_type == STATS_TRACK_ALL) {
576 seq_puts(m, "0 (all)\n");
578 seq_puts(m, "untracked\n");
583 static int ll_wr_track_id(const char __user *buffer, unsigned long count,
584 void *data, enum stats_track_type type)
586 struct super_block *sb = data;
590 rc = lprocfs_str_to_s64(buffer, count, &pid);
593 if (pid > INT_MAX || pid < 0)
596 ll_s2sbi(sb)->ll_stats_track_id = pid;
598 ll_s2sbi(sb)->ll_stats_track_type = STATS_TRACK_ALL;
600 ll_s2sbi(sb)->ll_stats_track_type = type;
601 lprocfs_clear_stats(ll_s2sbi(sb)->ll_stats);
605 static int ll_track_pid_seq_show(struct seq_file *m, void *v)
607 return ll_rd_track_id(m, STATS_TRACK_PID);
610 static ssize_t ll_track_pid_seq_write(struct file *file,
611 const char __user *buffer,
612 size_t count, loff_t *off)
614 struct seq_file *seq = file->private_data;
615 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PID);
617 LPROC_SEQ_FOPS(ll_track_pid);
619 static int ll_track_ppid_seq_show(struct seq_file *m, void *v)
621 return ll_rd_track_id(m, STATS_TRACK_PPID);
624 static ssize_t ll_track_ppid_seq_write(struct file *file,
625 const char __user *buffer,
626 size_t count, loff_t *off)
628 struct seq_file *seq = file->private_data;
629 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PPID);
631 LPROC_SEQ_FOPS(ll_track_ppid);
633 static int ll_track_gid_seq_show(struct seq_file *m, void *v)
635 return ll_rd_track_id(m, STATS_TRACK_GID);
638 static ssize_t ll_track_gid_seq_write(struct file *file,
639 const char __user *buffer,
640 size_t count, loff_t *off)
642 struct seq_file *seq = file->private_data;
643 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_GID);
645 LPROC_SEQ_FOPS(ll_track_gid);
647 static int ll_statahead_max_seq_show(struct seq_file *m, void *v)
649 struct super_block *sb = m->private;
650 struct ll_sb_info *sbi = ll_s2sbi(sb);
652 seq_printf(m, "%u\n", sbi->ll_sa_max);
656 static ssize_t ll_statahead_max_seq_write(struct file *file,
657 const char __user *buffer,
658 size_t count, loff_t *off)
660 struct seq_file *m = file->private_data;
661 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
665 rc = lprocfs_str_to_s64(buffer, count, &val);
669 if (val >= 0 && val <= LL_SA_RPC_MAX)
670 sbi->ll_sa_max = val;
672 CERROR("Bad statahead_max value "LPD64". Valid values are in "
673 "the range [0, %d]\n", val, LL_SA_RPC_MAX);
677 LPROC_SEQ_FOPS(ll_statahead_max);
679 static int ll_statahead_agl_seq_show(struct seq_file *m, void *v)
681 struct super_block *sb = m->private;
682 struct ll_sb_info *sbi = ll_s2sbi(sb);
684 seq_printf(m, "%u\n",
685 sbi->ll_flags & LL_SBI_AGL_ENABLED ? 1 : 0);
689 static ssize_t ll_statahead_agl_seq_write(struct file *file,
690 const char __user *buffer,
691 size_t count, loff_t *off)
693 struct seq_file *m = file->private_data;
694 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
698 rc = lprocfs_str_to_s64(buffer, count, &val);
703 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
705 sbi->ll_flags &= ~LL_SBI_AGL_ENABLED;
709 LPROC_SEQ_FOPS(ll_statahead_agl);
711 static int ll_statahead_stats_seq_show(struct seq_file *m, void *v)
713 struct super_block *sb = m->private;
714 struct ll_sb_info *sbi = ll_s2sbi(sb);
716 seq_printf(m, "statahead total: %u\n"
717 "statahead wrong: %u\n"
719 atomic_read(&sbi->ll_sa_total),
720 atomic_read(&sbi->ll_sa_wrong),
721 atomic_read(&sbi->ll_agl_total));
724 LPROC_SEQ_FOPS_RO(ll_statahead_stats);
726 static int ll_lazystatfs_seq_show(struct seq_file *m, void *v)
728 struct super_block *sb = m->private;
729 struct ll_sb_info *sbi = ll_s2sbi(sb);
731 seq_printf(m, "%u\n",
732 (sbi->ll_flags & LL_SBI_LAZYSTATFS) ? 1 : 0);
736 static ssize_t ll_lazystatfs_seq_write(struct file *file,
737 const char __user *buffer,
738 size_t count, loff_t *off)
740 struct seq_file *m = file->private_data;
741 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
745 rc = lprocfs_str_to_s64(buffer, count, &val);
750 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
752 sbi->ll_flags &= ~LL_SBI_LAZYSTATFS;
756 LPROC_SEQ_FOPS(ll_lazystatfs);
758 static int ll_max_easize_seq_show(struct seq_file *m, void *v)
760 struct super_block *sb = m->private;
761 struct ll_sb_info *sbi = ll_s2sbi(sb);
765 rc = ll_get_max_mdsize(sbi, &ealen);
769 seq_printf(m, "%u\n", ealen);
772 LPROC_SEQ_FOPS_RO(ll_max_easize);
775 * Get default_easize.
777 * \see client_obd::cl_default_mds_easize
779 * \param[in] m seq_file handle
780 * \param[in] v unused for single entry
782 * \retval 0 on success
783 * \retval negative negated errno on failure
785 static int ll_default_easize_seq_show(struct seq_file *m, void *v)
787 struct super_block *sb = m->private;
788 struct ll_sb_info *sbi = ll_s2sbi(sb);
792 rc = ll_get_default_mdsize(sbi, &ealen);
796 seq_printf(m, "%u\n", ealen);
801 * Set default_easize.
803 * Range checking on the passed value is handled by
804 * ll_set_default_mdsize().
806 * \see client_obd::cl_default_mds_easize
808 * \param[in] file proc file
809 * \param[in] buffer string passed from user space
810 * \param[in] count \a buffer length
811 * \param[in] off unused for single entry
813 * \retval positive \a count on success
814 * \retval negative negated errno on failure
816 static ssize_t ll_default_easize_seq_write(struct file *file,
817 const char __user *buffer,
818 size_t count, loff_t *unused)
820 struct seq_file *seq = file->private_data;
821 struct super_block *sb = (struct super_block *)seq->private;
822 struct ll_sb_info *sbi = ll_s2sbi(sb);
829 rc = lprocfs_str_to_s64(buffer, count, &val);
832 if (val < 0 || val > INT_MAX)
835 rc = ll_set_default_mdsize(sbi, val);
841 LPROC_SEQ_FOPS(ll_default_easize);
843 static int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
845 const char *str[] = LL_SBI_FLAGS;
846 struct super_block *sb = m->private;
847 int flags = ll_s2sbi(sb)->ll_flags;
851 if (ARRAY_SIZE(str) <= i) {
852 CERROR("%s: Revise array LL_SBI_FLAGS to match sbi "
853 "flags please.\n", ll_get_fsname(sb, NULL, 0));
858 seq_printf(m, "%s ", str[i]);
862 seq_printf(m, "\b\n");
865 LPROC_SEQ_FOPS_RO(ll_sbi_flags);
867 static int ll_fast_read_seq_show(struct seq_file *m, void *v)
869 struct super_block *sb = m->private;
870 struct ll_sb_info *sbi = ll_s2sbi(sb);
872 seq_printf(m, "%u\n", !!(sbi->ll_flags & LL_SBI_FAST_READ));
877 ll_fast_read_seq_write(struct file *file, const char __user *buffer,
878 size_t count, loff_t *off)
880 struct seq_file *m = file->private_data;
881 struct super_block *sb = m->private;
882 struct ll_sb_info *sbi = ll_s2sbi(sb);
886 rc = lprocfs_str_to_s64(buffer, count, &val);
890 spin_lock(&sbi->ll_lock);
892 sbi->ll_flags |= LL_SBI_FAST_READ;
894 sbi->ll_flags &= ~LL_SBI_FAST_READ;
895 spin_unlock(&sbi->ll_lock);
899 LPROC_SEQ_FOPS(ll_fast_read);
901 static int ll_unstable_stats_seq_show(struct seq_file *m, void *v)
903 struct super_block *sb = m->private;
904 struct ll_sb_info *sbi = ll_s2sbi(sb);
905 struct cl_client_cache *cache = sbi->ll_cache;
909 pages = atomic_long_read(&cache->ccc_unstable_nr);
910 mb = (pages * PAGE_CACHE_SIZE) >> 20;
912 seq_printf(m, "unstable_check: %8d\n"
913 "unstable_pages: %12ld\n"
914 "unstable_mb: %8d\n",
915 cache->ccc_unstable_check, pages, mb);
919 static ssize_t ll_unstable_stats_seq_write(struct file *file,
920 const char __user *buffer,
921 size_t count, loff_t *unused)
923 struct seq_file *seq = file->private_data;
924 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)seq->private);
931 if (count >= sizeof(kernbuf))
934 if (copy_from_user(kernbuf, buffer, count))
938 buffer += lprocfs_find_named_value(kernbuf, "unstable_check:", &count) -
940 rc = lprocfs_str_to_s64(buffer, count, &val);
944 /* borrow lru lock to set the value */
945 spin_lock(&sbi->ll_cache->ccc_lru_lock);
946 sbi->ll_cache->ccc_unstable_check = !!val;
947 spin_unlock(&sbi->ll_cache->ccc_lru_lock);
951 LPROC_SEQ_FOPS(ll_unstable_stats);
953 static int ll_root_squash_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;
959 seq_printf(m, "%u:%u\n", squash->rsi_uid, squash->rsi_gid);
963 static ssize_t ll_root_squash_seq_write(struct file *file,
964 const char __user *buffer,
965 size_t count, loff_t *off)
967 struct seq_file *m = file->private_data;
968 struct super_block *sb = m->private;
969 struct ll_sb_info *sbi = ll_s2sbi(sb);
970 struct root_squash_info *squash = &sbi->ll_squash;
972 return lprocfs_wr_root_squash(buffer, count, squash,
973 ll_get_fsname(sb, NULL, 0));
975 LPROC_SEQ_FOPS(ll_root_squash);
977 static int ll_nosquash_nids_seq_show(struct seq_file *m, void *v)
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 down_read(&squash->rsi_sem);
985 if (!list_empty(&squash->rsi_nosquash_nids)) {
986 len = cfs_print_nidlist(m->buf + m->count, m->size - m->count,
987 &squash->rsi_nosquash_nids);
991 seq_puts(m, "NONE\n");
993 up_read(&squash->rsi_sem);
998 static ssize_t ll_nosquash_nids_seq_write(struct file *file,
999 const char __user *buffer,
1000 size_t count, loff_t *off)
1002 struct seq_file *m = file->private_data;
1003 struct super_block *sb = m->private;
1004 struct ll_sb_info *sbi = ll_s2sbi(sb);
1005 struct root_squash_info *squash = &sbi->ll_squash;
1008 rc = lprocfs_wr_nosquash_nids(buffer, count, squash,
1009 ll_get_fsname(sb, NULL, 0));
1013 ll_compute_rootsquash_state(sbi);
1017 LPROC_SEQ_FOPS(ll_nosquash_nids);
1019 struct lprocfs_vars lprocfs_llite_obd_vars[] = {
1021 .fops = &ll_sb_uuid_fops },
1023 .fops = &ll_fstype_fops },
1025 .fops = &ll_site_stats_fops },
1026 { .name = "blocksize",
1027 .fops = &ll_blksize_fops },
1028 { .name = "kbytestotal",
1029 .fops = &ll_kbytestotal_fops },
1030 { .name = "kbytesfree",
1031 .fops = &ll_kbytesfree_fops },
1032 { .name = "kbytesavail",
1033 .fops = &ll_kbytesavail_fops },
1034 { .name = "filestotal",
1035 .fops = &ll_filestotal_fops },
1036 { .name = "filesfree",
1037 .fops = &ll_filesfree_fops },
1038 { .name = "client_type",
1039 .fops = &ll_client_type_fops },
1040 { .name = "max_read_ahead_mb",
1041 .fops = &ll_max_readahead_mb_fops },
1042 { .name = "max_read_ahead_per_file_mb",
1043 .fops = &ll_max_readahead_per_file_mb_fops },
1044 { .name = "max_read_ahead_whole_mb",
1045 .fops = &ll_max_read_ahead_whole_mb_fops },
1046 { .name = "max_cached_mb",
1047 .fops = &ll_max_cached_mb_fops },
1048 { .name = "checksum_pages",
1049 .fops = &ll_checksum_fops },
1050 { .name = "stats_track_pid",
1051 .fops = &ll_track_pid_fops },
1052 { .name = "stats_track_ppid",
1053 .fops = &ll_track_ppid_fops },
1054 { .name = "stats_track_gid",
1055 .fops = &ll_track_gid_fops },
1056 { .name = "statahead_max",
1057 .fops = &ll_statahead_max_fops },
1058 { .name = "statahead_agl",
1059 .fops = &ll_statahead_agl_fops },
1060 { .name = "statahead_stats",
1061 .fops = &ll_statahead_stats_fops },
1062 { .name = "lazystatfs",
1063 .fops = &ll_lazystatfs_fops },
1064 { .name = "max_easize",
1065 .fops = &ll_max_easize_fops },
1066 { .name = "default_easize",
1067 .fops = &ll_default_easize_fops },
1068 { .name = "sbi_flags",
1069 .fops = &ll_sbi_flags_fops },
1070 { .name = "xattr_cache",
1071 .fops = &ll_xattr_cache_fops },
1072 { .name = "unstable_stats",
1073 .fops = &ll_unstable_stats_fops },
1074 { .name = "root_squash",
1075 .fops = &ll_root_squash_fops },
1076 { .name = "nosquash_nids",
1077 .fops = &ll_nosquash_nids_fops },
1078 { .name = "fast_read",
1079 .fops = &ll_fast_read_fops, },
1083 #define MAX_STRING_SIZE 128
1085 static const struct llite_file_opcode {
1089 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
1090 /* file operation */
1091 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
1092 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
1093 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1095 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1097 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
1099 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
1101 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
1102 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
1103 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
1104 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
1105 { LPROC_LL_FAULT, LPROCFS_TYPE_REGS, "page_fault" },
1106 { LPROC_LL_MKWRITE, LPROCFS_TYPE_REGS, "page_mkwrite" },
1107 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
1108 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
1109 { LPROC_LL_READDIR, LPROCFS_TYPE_REGS, "readdir" },
1110 /* inode operation */
1111 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
1112 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "truncate" },
1113 { LPROC_LL_FLOCK, LPROCFS_TYPE_REGS, "flock" },
1114 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
1115 /* dir inode operation */
1116 { LPROC_LL_CREATE, LPROCFS_TYPE_REGS, "create" },
1117 { LPROC_LL_LINK, LPROCFS_TYPE_REGS, "link" },
1118 { LPROC_LL_UNLINK, LPROCFS_TYPE_REGS, "unlink" },
1119 { LPROC_LL_SYMLINK, LPROCFS_TYPE_REGS, "symlink" },
1120 { LPROC_LL_MKDIR, LPROCFS_TYPE_REGS, "mkdir" },
1121 { LPROC_LL_RMDIR, LPROCFS_TYPE_REGS, "rmdir" },
1122 { LPROC_LL_MKNOD, LPROCFS_TYPE_REGS, "mknod" },
1123 { LPROC_LL_RENAME, LPROCFS_TYPE_REGS, "rename" },
1124 /* special inode operation */
1125 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
1126 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
1127 { LPROC_LL_SETXATTR, LPROCFS_TYPE_REGS, "setxattr" },
1128 { LPROC_LL_GETXATTR, LPROCFS_TYPE_REGS, "getxattr" },
1129 { LPROC_LL_GETXATTR_HITS, LPROCFS_TYPE_REGS, "getxattr_hits" },
1130 { LPROC_LL_LISTXATTR, LPROCFS_TYPE_REGS, "listxattr" },
1131 { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_REGS, "removexattr" },
1132 { LPROC_LL_INODE_PERM, LPROCFS_TYPE_REGS, "inode_permission" },
1135 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
1139 if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
1140 lprocfs_counter_add(sbi->ll_stats, op, count);
1141 else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
1142 sbi->ll_stats_track_id == current->pid)
1143 lprocfs_counter_add(sbi->ll_stats, op, count);
1144 else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
1145 sbi->ll_stats_track_id == current->parent->pid)
1146 lprocfs_counter_add(sbi->ll_stats, op, count);
1147 else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
1148 sbi->ll_stats_track_id ==
1149 from_kgid(&init_user_ns, current_gid()))
1150 lprocfs_counter_add(sbi->ll_stats, op, count);
1152 EXPORT_SYMBOL(ll_stats_ops_tally);
1154 static const char *ra_stat_string[] = {
1155 [RA_STAT_HIT] = "hits",
1156 [RA_STAT_MISS] = "misses",
1157 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
1158 [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
1159 [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page",
1160 [RA_STAT_FAILED_MATCH] = "failed lock match",
1161 [RA_STAT_DISCARDED] = "read but discarded",
1162 [RA_STAT_ZERO_LEN] = "zero length file",
1163 [RA_STAT_ZERO_WINDOW] = "zero size window",
1164 [RA_STAT_EOF] = "read-ahead to EOF",
1165 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
1166 [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",
1167 [RA_STAT_FAILED_REACH_END] = "failed to reach end"
1170 LPROC_SEQ_FOPS_RO_TYPE(llite, name);
1171 LPROC_SEQ_FOPS_RO_TYPE(llite, uuid);
1173 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
1174 struct super_block *sb, char *osc, char *mdc)
1176 struct lprocfs_vars lvars[2];
1177 struct lustre_sb_info *lsi = s2lsi(sb);
1178 struct ll_sb_info *sbi = ll_s2sbi(sb);
1179 struct obd_device *obd;
1180 struct proc_dir_entry *dir;
1181 char name[MAX_STRING_SIZE + 1], *ptr;
1182 int err, id, len, rc;
1185 memset(lvars, 0, sizeof(lvars));
1187 name[MAX_STRING_SIZE] = '\0';
1188 lvars[0].name = name;
1190 LASSERT(sbi != NULL);
1191 LASSERT(mdc != NULL);
1192 LASSERT(osc != NULL);
1195 len = strlen(lsi->lsi_lmd->lmd_profile);
1196 ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
1197 if (ptr && (strcmp(ptr, "-client") == 0))
1201 snprintf(name, MAX_STRING_SIZE, "%.*s-%p", len,
1202 lsi->lsi_lmd->lmd_profile, sb);
1204 sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
1205 if (IS_ERR(sbi->ll_proc_root)) {
1206 err = PTR_ERR(sbi->ll_proc_root);
1207 sbi->ll_proc_root = NULL;
1211 rc = lprocfs_seq_create(sbi->ll_proc_root, "dump_page_cache", 0444,
1212 &vvp_dump_pgcache_file_ops, sbi);
1214 CWARN("Error adding the dump_page_cache file\n");
1216 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats", 0644,
1217 &ll_rw_extents_stats_fops, sbi);
1219 CWARN("Error adding the extent_stats file\n");
1221 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats_per_process",
1222 0644, &ll_rw_extents_stats_pp_fops, sbi);
1224 CWARN("Error adding the extents_stats_per_process file\n");
1226 rc = lprocfs_seq_create(sbi->ll_proc_root, "offset_stats", 0644,
1227 &ll_rw_offset_stats_fops, sbi);
1229 CWARN("Error adding the offset_stats file\n");
1231 /* File operations stats */
1232 sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
1233 LPROCFS_STATS_FLAG_NONE);
1234 if (sbi->ll_stats == NULL)
1235 GOTO(out, err = -ENOMEM);
1236 /* do counter init */
1237 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
1238 __u32 type = llite_opcode_table[id].type;
1240 if (type & LPROCFS_TYPE_REGS)
1242 else if (type & LPROCFS_TYPE_BYTES)
1244 else if (type & LPROCFS_TYPE_PAGES)
1246 lprocfs_counter_init(sbi->ll_stats,
1247 llite_opcode_table[id].opcode,
1248 (type & LPROCFS_CNTR_AVGMINMAX),
1249 llite_opcode_table[id].opname, ptr);
1251 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats);
1255 sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
1256 LPROCFS_STATS_FLAG_NONE);
1257 if (sbi->ll_ra_stats == NULL)
1258 GOTO(out, err = -ENOMEM);
1260 for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
1261 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
1262 ra_stat_string[id], "pages");
1263 err = lprocfs_register_stats(sbi->ll_proc_root, "read_ahead_stats",
1269 err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_llite_obd_vars, sb);
1274 obd = class_name2obd(mdc);
1276 LASSERT(obd != NULL);
1277 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1278 LASSERT(obd->obd_type->typ_name != NULL);
1280 dir = proc_mkdir(obd->obd_type->typ_name, sbi->ll_proc_root);
1282 GOTO(out, err = -ENOMEM);
1284 snprintf(name, MAX_STRING_SIZE, "common_name");
1285 lvars[0].fops = &llite_name_fops;
1286 err = lprocfs_add_vars(dir, lvars, obd);
1290 snprintf(name, MAX_STRING_SIZE, "uuid");
1291 lvars[0].fops = &llite_uuid_fops;
1292 err = lprocfs_add_vars(dir, lvars, obd);
1297 obd = class_name2obd(osc);
1299 LASSERT(obd != NULL);
1300 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1301 LASSERT(obd->obd_type->typ_name != NULL);
1303 dir = proc_mkdir(obd->obd_type->typ_name, sbi->ll_proc_root);
1305 GOTO(out, err = -ENOMEM);
1307 snprintf(name, MAX_STRING_SIZE, "common_name");
1308 lvars[0].fops = &llite_name_fops;
1309 err = lprocfs_add_vars(dir, lvars, obd);
1313 snprintf(name, MAX_STRING_SIZE, "uuid");
1314 lvars[0].fops = &llite_uuid_fops;
1315 err = lprocfs_add_vars(dir, lvars, obd);
1318 lprocfs_remove(&sbi->ll_proc_root);
1319 lprocfs_free_stats(&sbi->ll_ra_stats);
1320 lprocfs_free_stats(&sbi->ll_stats);
1325 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
1327 if (sbi->ll_proc_root) {
1328 lprocfs_remove(&sbi->ll_proc_root);
1329 lprocfs_free_stats(&sbi->ll_ra_stats);
1330 lprocfs_free_stats(&sbi->ll_stats);
1333 #undef MAX_STRING_SIZE
1335 #define pct(a,b) (b ? a * 100 / b : 0)
1337 static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
1338 struct seq_file *seq, int which)
1340 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
1341 unsigned long start, end, r, w;
1342 char *unitp = "KMGTPEZY";
1344 struct per_process_info *pp_info = &io_extents->pp_extents[which];
1350 for(i = 0; i < LL_HIST_MAX; i++) {
1351 read_tot += pp_info->pp_r_hist.oh_buckets[i];
1352 write_tot += pp_info->pp_w_hist.oh_buckets[i];
1355 for(i = 0; i < LL_HIST_MAX; i++) {
1356 r = pp_info->pp_r_hist.oh_buckets[i];
1357 w = pp_info->pp_w_hist.oh_buckets[i];
1360 end = 1 << (i + LL_HIST_START - units);
1361 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu | "
1362 "%14lu %4lu %4lu\n", start, *unitp, end, *unitp,
1363 (i == LL_HIST_MAX - 1) ? '+' : ' ',
1364 r, pct(r, read_tot), pct(read_cum, read_tot),
1365 w, pct(w, write_tot), pct(write_cum, write_tot));
1367 if (start == 1<<10) {
1372 if (read_cum == read_tot && write_cum == write_tot)
1377 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
1380 struct ll_sb_info *sbi = seq->private;
1381 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1384 do_gettimeofday(&now);
1386 if (!sbi->ll_rw_stats_on) {
1387 seq_puts(seq, "disabled\n write anything in this file to activate, then 0 or \[D/d]isabled\" to deactivate\n");
1390 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1391 now.tv_sec, now.tv_usec);
1392 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1393 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1394 "extents", "calls", "%", "cum%",
1395 "calls", "%", "cum%");
1396 spin_lock(&sbi->ll_pp_extent_lock);
1397 for (k = 0; k < LL_PROCESS_HIST_MAX; k++) {
1398 if (io_extents->pp_extents[k].pid != 0) {
1399 seq_printf(seq, "\nPID: %d\n",
1400 io_extents->pp_extents[k].pid);
1401 ll_display_extents_info(io_extents, seq, k);
1404 spin_unlock(&sbi->ll_pp_extent_lock);
1408 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
1409 const char __user *buf,
1413 struct seq_file *seq = file->private_data;
1414 struct ll_sb_info *sbi = seq->private;
1415 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1423 rc = lprocfs_str_to_s64(buf, len, &value);
1424 if (rc < 0 && len < 16) {
1427 if (copy_from_user(kernbuf, buf, len))
1431 if (kernbuf[len - 1] == '\n')
1432 kernbuf[len - 1] = 0;
1434 if (strcmp(kernbuf, "disabled") == 0 ||
1435 strcmp(kernbuf, "Disabled") == 0)
1440 sbi->ll_rw_stats_on = 0;
1442 sbi->ll_rw_stats_on = 1;
1444 spin_lock(&sbi->ll_pp_extent_lock);
1445 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1446 io_extents->pp_extents[i].pid = 0;
1447 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1448 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1450 spin_unlock(&sbi->ll_pp_extent_lock);
1454 LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
1456 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
1459 struct ll_sb_info *sbi = seq->private;
1460 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1462 do_gettimeofday(&now);
1464 if (!sbi->ll_rw_stats_on) {
1465 seq_puts(seq, "disabled\n write anything in this file to activate, then 0 or \"[D/d]isabled\" to deactivate\n");
1468 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1469 now.tv_sec, now.tv_usec);
1471 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1472 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1473 "extents", "calls", "%", "cum%",
1474 "calls", "%", "cum%");
1475 spin_lock(&sbi->ll_lock);
1476 ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
1477 spin_unlock(&sbi->ll_lock);
1482 static ssize_t ll_rw_extents_stats_seq_write(struct file *file,
1483 const char __user *buf,
1484 size_t len, loff_t *off)
1486 struct seq_file *seq = file->private_data;
1487 struct ll_sb_info *sbi = seq->private;
1488 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1496 rc = lprocfs_str_to_s64(buf, len, &value);
1497 if (rc < 0 && len < 16) {
1500 if (copy_from_user(kernbuf, buf, len))
1504 if (kernbuf[len - 1] == '\n')
1505 kernbuf[len - 1] = 0;
1507 if (strcmp(kernbuf, "disabled") == 0 ||
1508 strcmp(kernbuf, "Disabled") == 0)
1513 sbi->ll_rw_stats_on = 0;
1515 sbi->ll_rw_stats_on = 1;
1517 spin_lock(&sbi->ll_pp_extent_lock);
1518 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
1519 io_extents->pp_extents[i].pid = 0;
1520 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1521 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1523 spin_unlock(&sbi->ll_pp_extent_lock);
1527 LPROC_SEQ_FOPS(ll_rw_extents_stats);
1529 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
1530 struct ll_file_data *file, loff_t pos,
1531 size_t count, int rw)
1534 struct ll_rw_process_info *process;
1535 struct ll_rw_process_info *offset;
1536 int *off_count = &sbi->ll_rw_offset_entry_count;
1537 int *process_count = &sbi->ll_offset_process_count;
1538 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1540 if(!sbi->ll_rw_stats_on)
1542 process = sbi->ll_rw_process_info;
1543 offset = sbi->ll_rw_offset_info;
1545 spin_lock(&sbi->ll_pp_extent_lock);
1546 /* Extent statistics */
1547 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1548 if(io_extents->pp_extents[i].pid == pid) {
1556 sbi->ll_extent_process_count =
1557 (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1558 cur = sbi->ll_extent_process_count;
1559 io_extents->pp_extents[cur].pid = pid;
1560 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1561 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1564 for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
1565 (i < (LL_HIST_MAX - 1)); i++);
1567 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1568 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1570 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1571 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1573 spin_unlock(&sbi->ll_pp_extent_lock);
1575 spin_lock(&sbi->ll_process_lock);
1576 /* Offset statistics */
1577 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1578 if (process[i].rw_pid == pid) {
1579 if (process[i].rw_last_file != file) {
1580 process[i].rw_range_start = pos;
1581 process[i].rw_last_file_pos = pos + count;
1582 process[i].rw_smallest_extent = count;
1583 process[i].rw_largest_extent = count;
1584 process[i].rw_offset = 0;
1585 process[i].rw_last_file = file;
1586 spin_unlock(&sbi->ll_process_lock);
1589 if (process[i].rw_last_file_pos != pos) {
1591 (*off_count + 1) % LL_OFFSET_HIST_MAX;
1592 offset[*off_count].rw_op = process[i].rw_op;
1593 offset[*off_count].rw_pid = pid;
1594 offset[*off_count].rw_range_start =
1595 process[i].rw_range_start;
1596 offset[*off_count].rw_range_end =
1597 process[i].rw_last_file_pos;
1598 offset[*off_count].rw_smallest_extent =
1599 process[i].rw_smallest_extent;
1600 offset[*off_count].rw_largest_extent =
1601 process[i].rw_largest_extent;
1602 offset[*off_count].rw_offset =
1603 process[i].rw_offset;
1604 process[i].rw_op = rw;
1605 process[i].rw_range_start = pos;
1606 process[i].rw_smallest_extent = count;
1607 process[i].rw_largest_extent = count;
1608 process[i].rw_offset = pos -
1609 process[i].rw_last_file_pos;
1611 if(process[i].rw_smallest_extent > count)
1612 process[i].rw_smallest_extent = count;
1613 if(process[i].rw_largest_extent < count)
1614 process[i].rw_largest_extent = count;
1615 process[i].rw_last_file_pos = pos + count;
1616 spin_unlock(&sbi->ll_process_lock);
1620 *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
1621 process[*process_count].rw_pid = pid;
1622 process[*process_count].rw_op = rw;
1623 process[*process_count].rw_range_start = pos;
1624 process[*process_count].rw_last_file_pos = pos + count;
1625 process[*process_count].rw_smallest_extent = count;
1626 process[*process_count].rw_largest_extent = count;
1627 process[*process_count].rw_offset = 0;
1628 process[*process_count].rw_last_file = file;
1629 spin_unlock(&sbi->ll_process_lock);
1632 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1635 struct ll_sb_info *sbi = seq->private;
1636 struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
1637 struct ll_rw_process_info *process = sbi->ll_rw_process_info;
1640 do_gettimeofday(&now);
1642 if (!sbi->ll_rw_stats_on) {
1643 seq_puts(seq, "disabled\n write anything in this file to activate, then 0 or \"[D/d]isabled\" to deactivate\n");
1646 spin_lock(&sbi->ll_process_lock);
1648 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1649 now.tv_sec, now.tv_usec);
1650 seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
1651 "R/W", "PID", "RANGE START", "RANGE END",
1652 "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
1654 /* We stored the discontiguous offsets here; print them first */
1655 for (i = 0; i < LL_OFFSET_HIST_MAX; i++) {
1656 if (offset[i].rw_pid != 0)
1658 "%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1659 offset[i].rw_op == READ ? 'R' : 'W',
1661 offset[i].rw_range_start,
1662 offset[i].rw_range_end,
1663 (unsigned long)offset[i].rw_smallest_extent,
1664 (unsigned long)offset[i].rw_largest_extent,
1665 offset[i].rw_offset);
1668 /* Then print the current offsets for each process */
1669 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1670 if (process[i].rw_pid != 0)
1672 "%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1673 process[i].rw_op == READ ? 'R' : 'W',
1675 process[i].rw_range_start,
1676 process[i].rw_last_file_pos,
1677 (unsigned long)process[i].rw_smallest_extent,
1678 (unsigned long)process[i].rw_largest_extent,
1679 process[i].rw_offset);
1681 spin_unlock(&sbi->ll_process_lock);
1686 static ssize_t ll_rw_offset_stats_seq_write(struct file *file,
1687 const char __user *buf,
1688 size_t len, loff_t *off)
1690 struct seq_file *seq = file->private_data;
1691 struct ll_sb_info *sbi = seq->private;
1692 struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
1693 struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
1700 rc = lprocfs_str_to_s64(buf, len, &value);
1702 if (rc < 0 && len < 16) {
1705 if (copy_from_user(kernbuf, buf, len))
1709 if (kernbuf[len - 1] == '\n')
1710 kernbuf[len - 1] = 0;
1712 if (strcmp(kernbuf, "disabled") == 0 ||
1713 strcmp(kernbuf, "Disabled") == 0)
1718 sbi->ll_rw_stats_on = 0;
1720 sbi->ll_rw_stats_on = 1;
1722 spin_lock(&sbi->ll_process_lock);
1723 sbi->ll_offset_process_count = 0;
1724 sbi->ll_rw_offset_entry_count = 0;
1725 memset(process_info, 0, sizeof(struct ll_rw_process_info) *
1726 LL_PROCESS_HIST_MAX);
1727 memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
1728 LL_OFFSET_HIST_MAX);
1729 spin_unlock(&sbi->ll_process_lock);
1734 LPROC_SEQ_FOPS(ll_rw_offset_stats);
1735 #endif /* CONFIG_PROC_FS */