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 if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
182 seq_puts(m, "remote client\n");
184 seq_puts(m, "local client\n");
187 LPROC_SEQ_FOPS_RO(ll_client_type);
189 static int ll_fstype_seq_show(struct seq_file *m, void *v)
191 struct super_block *sb = m->private;
194 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 seq_printf(m, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
207 LPROC_SEQ_FOPS_RO(ll_sb_uuid);
209 static int ll_xattr_cache_seq_show(struct seq_file *m, void *v)
211 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
213 seq_printf(m, "%u\n", sbi->ll_xattr_cache_enabled);
217 static ssize_t ll_xattr_cache_seq_write(struct file *file,
218 const char __user *buffer,
219 size_t count, loff_t *off)
221 struct seq_file *m = file->private_data;
222 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
226 rc = lprocfs_str_to_s64(buffer, count, &val);
230 if (val != 0 && val != 1)
233 if (val == 1 && !(sbi->ll_flags & LL_SBI_XATTR_CACHE))
236 sbi->ll_xattr_cache_enabled = val;
240 LPROC_SEQ_FOPS(ll_xattr_cache);
242 static int ll_site_stats_seq_show(struct seq_file *m, void *v)
244 struct super_block *sb = m->private;
247 * See description of statistical counters in struct cl_site, and
250 return cl_site_stats_print(lu2cl_site(ll_s2sbi(sb)->ll_site), m);
252 LPROC_SEQ_FOPS_RO(ll_site_stats);
254 static int ll_max_readahead_mb_seq_show(struct seq_file *m, void *v)
256 struct super_block *sb = m->private;
257 struct ll_sb_info *sbi = ll_s2sbi(sb);
261 spin_lock(&sbi->ll_lock);
262 pages_number = sbi->ll_ra_info.ra_max_pages;
263 spin_unlock(&sbi->ll_lock);
265 mult = 1 << (20 - PAGE_CACHE_SHIFT);
266 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
270 ll_max_readahead_mb_seq_write(struct file *file, const char __user *buffer,
271 size_t count, loff_t *off)
273 struct seq_file *m = file->private_data;
274 struct super_block *sb = m->private;
275 struct ll_sb_info *sbi = ll_s2sbi(sb);
279 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
283 pages_number >>= PAGE_CACHE_SHIFT;
285 if (pages_number < 0 || pages_number > totalram_pages / 2) {
287 CERROR("%s: can't set max_readahead_mb=%lu > %luMB\n",
288 ll_get_fsname(sb, NULL, 0),
289 (unsigned long)pages_number >> (20 - PAGE_CACHE_SHIFT),
290 totalram_pages >> (20 - PAGE_CACHE_SHIFT + 1));
294 spin_lock(&sbi->ll_lock);
295 sbi->ll_ra_info.ra_max_pages = pages_number;
296 spin_unlock(&sbi->ll_lock);
299 LPROC_SEQ_FOPS(ll_max_readahead_mb);
301 static int ll_max_readahead_per_file_mb_seq_show(struct seq_file *m, void *v)
303 struct super_block *sb = m->private;
304 struct ll_sb_info *sbi = ll_s2sbi(sb);
308 spin_lock(&sbi->ll_lock);
309 pages_number = sbi->ll_ra_info.ra_max_pages_per_file;
310 spin_unlock(&sbi->ll_lock);
312 mult = 1 << (20 - PAGE_CACHE_SHIFT);
313 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
317 ll_max_readahead_per_file_mb_seq_write(struct file *file,
318 const char __user *buffer,
319 size_t count, loff_t *off)
321 struct seq_file *m = file->private_data;
322 struct super_block *sb = m->private;
323 struct ll_sb_info *sbi = ll_s2sbi(sb);
327 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
331 pages_number >>= PAGE_CACHE_SHIFT;
333 if (pages_number < 0 || pages_number > sbi->ll_ra_info.ra_max_pages) {
334 CERROR("%s: can't set max_readahead_per_file_mb=%lu > "
335 "max_read_ahead_mb=%lu\n", ll_get_fsname(sb, NULL, 0),
336 (unsigned long)pages_number >> (20 - PAGE_CACHE_SHIFT),
337 sbi->ll_ra_info.ra_max_pages >> (20 - PAGE_CACHE_SHIFT));
341 spin_lock(&sbi->ll_lock);
342 sbi->ll_ra_info.ra_max_pages_per_file = pages_number;
343 spin_unlock(&sbi->ll_lock);
346 LPROC_SEQ_FOPS(ll_max_readahead_per_file_mb);
348 static int ll_max_read_ahead_whole_mb_seq_show(struct seq_file *m, void *v)
350 struct super_block *sb = m->private;
351 struct ll_sb_info *sbi = ll_s2sbi(sb);
355 spin_lock(&sbi->ll_lock);
356 pages_number = sbi->ll_ra_info.ra_max_read_ahead_whole_pages;
357 spin_unlock(&sbi->ll_lock);
359 mult = 1 << (20 - PAGE_CACHE_SHIFT);
360 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
364 ll_max_read_ahead_whole_mb_seq_write(struct file *file,
365 const char __user *buffer,
366 size_t count, loff_t *off)
368 struct seq_file *m = file->private_data;
369 struct super_block *sb = m->private;
370 struct ll_sb_info *sbi = ll_s2sbi(sb);
374 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
378 pages_number >>= PAGE_CACHE_SHIFT;
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 int pages_shift = 20 - PAGE_CACHE_SHIFT;
385 CERROR("%s: can't set max_read_ahead_whole_mb=%lu > "
386 "max_read_ahead_per_file_mb=%lu\n",
387 ll_get_fsname(sb, NULL, 0),
388 (unsigned long)pages_number >> pages_shift,
389 sbi->ll_ra_info.ra_max_pages_per_file >> pages_shift);
393 spin_lock(&sbi->ll_lock);
394 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = pages_number;
395 spin_unlock(&sbi->ll_lock);
398 LPROC_SEQ_FOPS(ll_max_read_ahead_whole_mb);
400 static int ll_max_cached_mb_seq_show(struct seq_file *m, void *v)
402 struct super_block *sb = m->private;
403 struct ll_sb_info *sbi = ll_s2sbi(sb);
404 struct cl_client_cache *cache = sbi->ll_cache;
405 int shift = 20 - PAGE_CACHE_SHIFT;
409 max_cached_mb = cache->ccc_lru_max >> shift;
410 unused_mb = atomic_long_read(&cache->ccc_lru_left) >> shift;
411 seq_printf(m, "users: %d\n"
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);
425 ll_max_cached_mb_seq_write(struct file *file, const char __user *buffer,
426 size_t count, loff_t *off)
428 struct seq_file *m = file->private_data;
429 struct super_block *sb = m->private;
430 struct ll_sb_info *sbi = ll_s2sbi(sb);
431 struct cl_client_cache *cache = sbi->ll_cache;
441 if (count >= sizeof(kernbuf))
444 if (copy_from_user(kernbuf, buffer, count))
448 buffer += lprocfs_find_named_value(kernbuf, "max_cached_mb:", &count) -
450 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
454 pages_number >>= PAGE_CACHE_SHIFT;
456 if (pages_number < 0 || pages_number > totalram_pages) {
457 CERROR("%s: can't set max cache more than %lu MB\n",
458 ll_get_fsname(sb, NULL, 0),
459 totalram_pages >> (20 - PAGE_CACHE_SHIFT));
462 /* Allow enough cache so clients can make well-formed RPCs */
463 pages_number = max_t(long, pages_number, PTLRPC_MAX_BRW_PAGES);
465 spin_lock(&sbi->ll_lock);
466 diff = pages_number - cache->ccc_lru_max;
467 spin_unlock(&sbi->ll_lock);
469 /* easy - add more LRU slots. */
471 atomic_long_add(diff, &cache->ccc_lru_left);
475 env = cl_env_get(&refcheck);
483 /* reduce LRU budget from free slots. */
487 ov = atomic_long_read(&cache->ccc_lru_left);
491 nv = ov > diff ? ov - diff : 0;
492 rc = atomic_long_cmpxchg(&cache->ccc_lru_left, ov, nv);
493 if (likely(ov == rc)) {
503 if (sbi->ll_dt_exp == NULL) { /* being initialized */
508 /* difficult - have to ask OSCs to drop LRU slots. */
510 rc = obd_set_info_async(env, sbi->ll_dt_exp,
511 sizeof(KEY_CACHE_LRU_SHRINK),
512 KEY_CACHE_LRU_SHRINK,
513 sizeof(tmp), &tmp, NULL);
517 cl_env_put(env, &refcheck);
521 spin_lock(&sbi->ll_lock);
522 cache->ccc_lru_max = pages_number;
523 spin_unlock(&sbi->ll_lock);
526 atomic_long_add(nrpages, &cache->ccc_lru_left);
530 LPROC_SEQ_FOPS(ll_max_cached_mb);
532 static int ll_checksum_seq_show(struct seq_file *m, void *v)
534 struct super_block *sb = m->private;
535 struct ll_sb_info *sbi = ll_s2sbi(sb);
537 seq_printf(m, "%u\n", (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0);
541 static ssize_t ll_checksum_seq_write(struct file *file,
542 const char __user *buffer,
543 size_t count, loff_t *off)
545 struct seq_file *m = file->private_data;
546 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
554 rc = lprocfs_str_to_s64(buffer, count, &val);
558 sbi->ll_flags |= LL_SBI_CHECKSUM;
560 sbi->ll_flags &= ~LL_SBI_CHECKSUM;
562 rc = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
563 KEY_CHECKSUM, sizeof(val), &val, NULL);
565 CWARN("Failed to set OSC checksum flags: %d\n", rc);
569 LPROC_SEQ_FOPS(ll_checksum);
571 static int ll_rd_track_id(struct seq_file *m, enum stats_track_type type)
573 struct super_block *sb = m->private;
575 if (ll_s2sbi(sb)->ll_stats_track_type == type) {
576 seq_printf(m, "%d\n",
577 ll_s2sbi(sb)->ll_stats_track_id);
578 } else if (ll_s2sbi(sb)->ll_stats_track_type == STATS_TRACK_ALL) {
579 seq_puts(m, "0 (all)\n");
581 seq_puts(m, "untracked\n");
586 static int ll_wr_track_id(const char __user *buffer, unsigned long count,
587 void *data, enum stats_track_type type)
589 struct super_block *sb = data;
593 rc = lprocfs_str_to_s64(buffer, count, &pid);
596 if (pid > INT_MAX || pid < 0)
599 ll_s2sbi(sb)->ll_stats_track_id = pid;
601 ll_s2sbi(sb)->ll_stats_track_type = STATS_TRACK_ALL;
603 ll_s2sbi(sb)->ll_stats_track_type = type;
604 lprocfs_clear_stats(ll_s2sbi(sb)->ll_stats);
608 static int ll_track_pid_seq_show(struct seq_file *m, void *v)
610 return ll_rd_track_id(m, STATS_TRACK_PID);
613 static ssize_t ll_track_pid_seq_write(struct file *file,
614 const char __user *buffer,
615 size_t count, loff_t *off)
617 struct seq_file *seq = file->private_data;
618 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PID);
620 LPROC_SEQ_FOPS(ll_track_pid);
622 static int ll_track_ppid_seq_show(struct seq_file *m, void *v)
624 return ll_rd_track_id(m, STATS_TRACK_PPID);
627 static ssize_t ll_track_ppid_seq_write(struct file *file,
628 const char __user *buffer,
629 size_t count, loff_t *off)
631 struct seq_file *seq = file->private_data;
632 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PPID);
634 LPROC_SEQ_FOPS(ll_track_ppid);
636 static int ll_track_gid_seq_show(struct seq_file *m, void *v)
638 return ll_rd_track_id(m, STATS_TRACK_GID);
641 static ssize_t ll_track_gid_seq_write(struct file *file,
642 const char __user *buffer,
643 size_t count, loff_t *off)
645 struct seq_file *seq = file->private_data;
646 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_GID);
648 LPROC_SEQ_FOPS(ll_track_gid);
650 static int ll_statahead_max_seq_show(struct seq_file *m, void *v)
652 struct super_block *sb = m->private;
653 struct ll_sb_info *sbi = ll_s2sbi(sb);
655 seq_printf(m, "%u\n", sbi->ll_sa_max);
659 static ssize_t ll_statahead_max_seq_write(struct file *file,
660 const char __user *buffer,
661 size_t count, loff_t *off)
663 struct seq_file *m = file->private_data;
664 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
668 rc = lprocfs_str_to_s64(buffer, count, &val);
672 if (val >= 0 && val <= LL_SA_RPC_MAX)
673 sbi->ll_sa_max = val;
675 CERROR("Bad statahead_max value "LPD64". Valid values are in "
676 "the range [0, %d]\n", val, LL_SA_RPC_MAX);
680 LPROC_SEQ_FOPS(ll_statahead_max);
682 static int ll_statahead_agl_seq_show(struct seq_file *m, void *v)
684 struct super_block *sb = m->private;
685 struct ll_sb_info *sbi = ll_s2sbi(sb);
687 seq_printf(m, "%u\n",
688 sbi->ll_flags & LL_SBI_AGL_ENABLED ? 1 : 0);
692 static ssize_t ll_statahead_agl_seq_write(struct file *file,
693 const char __user *buffer,
694 size_t count, loff_t *off)
696 struct seq_file *m = file->private_data;
697 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
701 rc = lprocfs_str_to_s64(buffer, count, &val);
706 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
708 sbi->ll_flags &= ~LL_SBI_AGL_ENABLED;
712 LPROC_SEQ_FOPS(ll_statahead_agl);
714 static int ll_statahead_stats_seq_show(struct seq_file *m, void *v)
716 struct super_block *sb = m->private;
717 struct ll_sb_info *sbi = ll_s2sbi(sb);
719 seq_printf(m, "statahead total: %u\n"
720 "statahead wrong: %u\n"
722 atomic_read(&sbi->ll_sa_total),
723 atomic_read(&sbi->ll_sa_wrong),
724 atomic_read(&sbi->ll_agl_total));
727 LPROC_SEQ_FOPS_RO(ll_statahead_stats);
729 static int ll_lazystatfs_seq_show(struct seq_file *m, void *v)
731 struct super_block *sb = m->private;
732 struct ll_sb_info *sbi = ll_s2sbi(sb);
734 seq_printf(m, "%u\n",
735 (sbi->ll_flags & LL_SBI_LAZYSTATFS) ? 1 : 0);
739 static ssize_t ll_lazystatfs_seq_write(struct file *file,
740 const char __user *buffer,
741 size_t count, loff_t *off)
743 struct seq_file *m = file->private_data;
744 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
748 rc = lprocfs_str_to_s64(buffer, count, &val);
753 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
755 sbi->ll_flags &= ~LL_SBI_LAZYSTATFS;
759 LPROC_SEQ_FOPS(ll_lazystatfs);
761 static int ll_max_easize_seq_show(struct seq_file *m, void *v)
763 struct super_block *sb = m->private;
764 struct ll_sb_info *sbi = ll_s2sbi(sb);
768 rc = ll_get_max_mdsize(sbi, &ealen);
772 seq_printf(m, "%u\n", ealen);
775 LPROC_SEQ_FOPS_RO(ll_max_easize);
778 * Get default_easize.
780 * \see client_obd::cl_default_mds_easize
782 * \param[in] m seq_file handle
783 * \param[in] v unused for single entry
785 * \retval 0 on success
786 * \retval negative negated errno on failure
788 static int ll_default_easize_seq_show(struct seq_file *m, void *v)
790 struct super_block *sb = m->private;
791 struct ll_sb_info *sbi = ll_s2sbi(sb);
795 rc = ll_get_default_mdsize(sbi, &ealen);
799 seq_printf(m, "%u\n", ealen);
804 * Set default_easize.
806 * Range checking on the passed value is handled by
807 * ll_set_default_mdsize().
809 * \see client_obd::cl_default_mds_easize
811 * \param[in] file proc file
812 * \param[in] buffer string passed from user space
813 * \param[in] count \a buffer length
814 * \param[in] off unused for single entry
816 * \retval positive \a count on success
817 * \retval negative negated errno on failure
819 static ssize_t ll_default_easize_seq_write(struct file *file,
820 const char __user *buffer,
821 size_t count, loff_t *unused)
823 struct seq_file *seq = file->private_data;
824 struct super_block *sb = (struct super_block *)seq->private;
825 struct ll_sb_info *sbi = ll_s2sbi(sb);
832 rc = lprocfs_str_to_s64(buffer, count, &val);
835 if (val < 0 || val > INT_MAX)
838 rc = ll_set_default_mdsize(sbi, val);
844 LPROC_SEQ_FOPS(ll_default_easize);
846 static int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
848 const char *str[] = LL_SBI_FLAGS;
849 struct super_block *sb = m->private;
850 int flags = ll_s2sbi(sb)->ll_flags;
854 if (ARRAY_SIZE(str) <= i) {
855 CERROR("%s: Revise array LL_SBI_FLAGS to match sbi "
856 "flags please.\n", ll_get_fsname(sb, NULL, 0));
861 seq_printf(m, "%s ", str[i]);
865 seq_printf(m, "\b\n");
868 LPROC_SEQ_FOPS_RO(ll_sbi_flags);
870 static int ll_fast_read_seq_show(struct seq_file *m, void *v)
872 struct super_block *sb = m->private;
873 struct ll_sb_info *sbi = ll_s2sbi(sb);
875 seq_printf(m, "%u\n", !!(sbi->ll_flags & LL_SBI_FAST_READ));
880 ll_fast_read_seq_write(struct file *file, const char __user *buffer,
881 size_t count, loff_t *off)
883 struct seq_file *m = file->private_data;
884 struct super_block *sb = m->private;
885 struct ll_sb_info *sbi = ll_s2sbi(sb);
889 rc = lprocfs_str_to_s64(buffer, count, &val);
893 spin_lock(&sbi->ll_lock);
895 sbi->ll_flags |= LL_SBI_FAST_READ;
897 sbi->ll_flags &= ~LL_SBI_FAST_READ;
898 spin_unlock(&sbi->ll_lock);
902 LPROC_SEQ_FOPS(ll_fast_read);
904 static int ll_unstable_stats_seq_show(struct seq_file *m, void *v)
906 struct super_block *sb = m->private;
907 struct ll_sb_info *sbi = ll_s2sbi(sb);
908 struct cl_client_cache *cache = sbi->ll_cache;
912 pages = atomic_long_read(&cache->ccc_unstable_nr);
913 mb = (pages * PAGE_CACHE_SIZE) >> 20;
915 seq_printf(m, "unstable_check: %8d\n"
916 "unstable_pages: %12ld\n"
917 "unstable_mb: %8d\n",
918 cache->ccc_unstable_check, pages, mb);
922 static ssize_t ll_unstable_stats_seq_write(struct file *file,
923 const char __user *buffer,
924 size_t count, loff_t *unused)
926 struct seq_file *seq = file->private_data;
927 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)seq->private);
934 if (count >= sizeof(kernbuf))
937 if (copy_from_user(kernbuf, buffer, count))
941 buffer += lprocfs_find_named_value(kernbuf, "unstable_check:", &count) -
943 rc = lprocfs_str_to_s64(buffer, count, &val);
947 /* borrow lru lock to set the value */
948 spin_lock(&sbi->ll_cache->ccc_lru_lock);
949 sbi->ll_cache->ccc_unstable_check = !!val;
950 spin_unlock(&sbi->ll_cache->ccc_lru_lock);
954 LPROC_SEQ_FOPS(ll_unstable_stats);
956 static int ll_root_squash_seq_show(struct seq_file *m, void *v)
958 struct super_block *sb = m->private;
959 struct ll_sb_info *sbi = ll_s2sbi(sb);
960 struct root_squash_info *squash = &sbi->ll_squash;
962 seq_printf(m, "%u:%u\n", squash->rsi_uid, squash->rsi_gid);
966 static ssize_t ll_root_squash_seq_write(struct file *file,
967 const char __user *buffer,
968 size_t count, loff_t *off)
970 struct seq_file *m = file->private_data;
971 struct super_block *sb = m->private;
972 struct ll_sb_info *sbi = ll_s2sbi(sb);
973 struct root_squash_info *squash = &sbi->ll_squash;
975 return lprocfs_wr_root_squash(buffer, count, squash,
976 ll_get_fsname(sb, NULL, 0));
978 LPROC_SEQ_FOPS(ll_root_squash);
980 static int ll_nosquash_nids_seq_show(struct seq_file *m, void *v)
982 struct super_block *sb = m->private;
983 struct ll_sb_info *sbi = ll_s2sbi(sb);
984 struct root_squash_info *squash = &sbi->ll_squash;
987 down_read(&squash->rsi_sem);
988 if (!list_empty(&squash->rsi_nosquash_nids)) {
989 len = cfs_print_nidlist(m->buf + m->count, m->size - m->count,
990 &squash->rsi_nosquash_nids);
994 seq_puts(m, "NONE\n");
996 up_read(&squash->rsi_sem);
1001 static ssize_t ll_nosquash_nids_seq_write(struct file *file,
1002 const char __user *buffer,
1003 size_t count, loff_t *off)
1005 struct seq_file *m = file->private_data;
1006 struct super_block *sb = m->private;
1007 struct ll_sb_info *sbi = ll_s2sbi(sb);
1008 struct root_squash_info *squash = &sbi->ll_squash;
1011 rc = lprocfs_wr_nosquash_nids(buffer, count, squash,
1012 ll_get_fsname(sb, NULL, 0));
1016 ll_compute_rootsquash_state(sbi);
1020 LPROC_SEQ_FOPS(ll_nosquash_nids);
1022 struct lprocfs_vars lprocfs_llite_obd_vars[] = {
1024 .fops = &ll_sb_uuid_fops },
1026 .fops = &ll_fstype_fops },
1028 .fops = &ll_site_stats_fops },
1029 { .name = "blocksize",
1030 .fops = &ll_blksize_fops },
1031 { .name = "kbytestotal",
1032 .fops = &ll_kbytestotal_fops },
1033 { .name = "kbytesfree",
1034 .fops = &ll_kbytesfree_fops },
1035 { .name = "kbytesavail",
1036 .fops = &ll_kbytesavail_fops },
1037 { .name = "filestotal",
1038 .fops = &ll_filestotal_fops },
1039 { .name = "filesfree",
1040 .fops = &ll_filesfree_fops },
1041 { .name = "client_type",
1042 .fops = &ll_client_type_fops },
1043 { .name = "max_read_ahead_mb",
1044 .fops = &ll_max_readahead_mb_fops },
1045 { .name = "max_read_ahead_per_file_mb",
1046 .fops = &ll_max_readahead_per_file_mb_fops },
1047 { .name = "max_read_ahead_whole_mb",
1048 .fops = &ll_max_read_ahead_whole_mb_fops },
1049 { .name = "max_cached_mb",
1050 .fops = &ll_max_cached_mb_fops },
1051 { .name = "checksum_pages",
1052 .fops = &ll_checksum_fops },
1053 { .name = "stats_track_pid",
1054 .fops = &ll_track_pid_fops },
1055 { .name = "stats_track_ppid",
1056 .fops = &ll_track_ppid_fops },
1057 { .name = "stats_track_gid",
1058 .fops = &ll_track_gid_fops },
1059 { .name = "statahead_max",
1060 .fops = &ll_statahead_max_fops },
1061 { .name = "statahead_agl",
1062 .fops = &ll_statahead_agl_fops },
1063 { .name = "statahead_stats",
1064 .fops = &ll_statahead_stats_fops },
1065 { .name = "lazystatfs",
1066 .fops = &ll_lazystatfs_fops },
1067 { .name = "max_easize",
1068 .fops = &ll_max_easize_fops },
1069 { .name = "default_easize",
1070 .fops = &ll_default_easize_fops },
1071 { .name = "sbi_flags",
1072 .fops = &ll_sbi_flags_fops },
1073 { .name = "xattr_cache",
1074 .fops = &ll_xattr_cache_fops },
1075 { .name = "unstable_stats",
1076 .fops = &ll_unstable_stats_fops },
1077 { .name = "root_squash",
1078 .fops = &ll_root_squash_fops },
1079 { .name = "nosquash_nids",
1080 .fops = &ll_nosquash_nids_fops },
1081 { .name = "fast_read",
1082 .fops = &ll_fast_read_fops, },
1086 #define MAX_STRING_SIZE 128
1088 static const struct llite_file_opcode {
1092 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
1093 /* file operation */
1094 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
1095 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
1096 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1098 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1100 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
1102 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
1104 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
1105 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
1106 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
1107 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
1108 { LPROC_LL_FAULT, LPROCFS_TYPE_REGS, "page_fault" },
1109 { LPROC_LL_MKWRITE, LPROCFS_TYPE_REGS, "page_mkwrite" },
1110 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
1111 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
1112 { LPROC_LL_READDIR, LPROCFS_TYPE_REGS, "readdir" },
1113 /* inode operation */
1114 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
1115 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "truncate" },
1116 { LPROC_LL_FLOCK, LPROCFS_TYPE_REGS, "flock" },
1117 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
1118 /* dir inode operation */
1119 { LPROC_LL_CREATE, LPROCFS_TYPE_REGS, "create" },
1120 { LPROC_LL_LINK, LPROCFS_TYPE_REGS, "link" },
1121 { LPROC_LL_UNLINK, LPROCFS_TYPE_REGS, "unlink" },
1122 { LPROC_LL_SYMLINK, LPROCFS_TYPE_REGS, "symlink" },
1123 { LPROC_LL_MKDIR, LPROCFS_TYPE_REGS, "mkdir" },
1124 { LPROC_LL_RMDIR, LPROCFS_TYPE_REGS, "rmdir" },
1125 { LPROC_LL_MKNOD, LPROCFS_TYPE_REGS, "mknod" },
1126 { LPROC_LL_RENAME, LPROCFS_TYPE_REGS, "rename" },
1127 /* special inode operation */
1128 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
1129 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
1130 { LPROC_LL_SETXATTR, LPROCFS_TYPE_REGS, "setxattr" },
1131 { LPROC_LL_GETXATTR, LPROCFS_TYPE_REGS, "getxattr" },
1132 { LPROC_LL_GETXATTR_HITS, LPROCFS_TYPE_REGS, "getxattr_hits" },
1133 { LPROC_LL_LISTXATTR, LPROCFS_TYPE_REGS, "listxattr" },
1134 { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_REGS, "removexattr" },
1135 { LPROC_LL_INODE_PERM, LPROCFS_TYPE_REGS, "inode_permission" },
1138 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
1142 if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
1143 lprocfs_counter_add(sbi->ll_stats, op, count);
1144 else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
1145 sbi->ll_stats_track_id == current->pid)
1146 lprocfs_counter_add(sbi->ll_stats, op, count);
1147 else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
1148 sbi->ll_stats_track_id == current->parent->pid)
1149 lprocfs_counter_add(sbi->ll_stats, op, count);
1150 else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
1151 sbi->ll_stats_track_id ==
1152 from_kgid(&init_user_ns, current_gid()))
1153 lprocfs_counter_add(sbi->ll_stats, op, count);
1155 EXPORT_SYMBOL(ll_stats_ops_tally);
1157 static const char *ra_stat_string[] = {
1158 [RA_STAT_HIT] = "hits",
1159 [RA_STAT_MISS] = "misses",
1160 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
1161 [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
1162 [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page",
1163 [RA_STAT_FAILED_MATCH] = "failed lock match",
1164 [RA_STAT_DISCARDED] = "read but discarded",
1165 [RA_STAT_ZERO_LEN] = "zero length file",
1166 [RA_STAT_ZERO_WINDOW] = "zero size window",
1167 [RA_STAT_EOF] = "read-ahead to EOF",
1168 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
1169 [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",
1170 [RA_STAT_FAILED_REACH_END] = "failed to reach end"
1173 LPROC_SEQ_FOPS_RO_TYPE(llite, name);
1174 LPROC_SEQ_FOPS_RO_TYPE(llite, uuid);
1176 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
1177 struct super_block *sb, char *osc, char *mdc)
1179 struct lprocfs_vars lvars[2];
1180 struct lustre_sb_info *lsi = s2lsi(sb);
1181 struct ll_sb_info *sbi = ll_s2sbi(sb);
1182 struct obd_device *obd;
1183 struct proc_dir_entry *dir;
1184 char name[MAX_STRING_SIZE + 1], *ptr;
1185 int err, id, len, rc;
1188 memset(lvars, 0, sizeof(lvars));
1190 name[MAX_STRING_SIZE] = '\0';
1191 lvars[0].name = name;
1193 LASSERT(sbi != NULL);
1194 LASSERT(mdc != NULL);
1195 LASSERT(osc != NULL);
1198 len = strlen(lsi->lsi_lmd->lmd_profile);
1199 ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
1200 if (ptr && (strcmp(ptr, "-client") == 0))
1204 snprintf(name, MAX_STRING_SIZE, "%.*s-%p", len,
1205 lsi->lsi_lmd->lmd_profile, sb);
1207 sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
1208 if (IS_ERR(sbi->ll_proc_root)) {
1209 err = PTR_ERR(sbi->ll_proc_root);
1210 sbi->ll_proc_root = NULL;
1214 rc = lprocfs_seq_create(sbi->ll_proc_root, "dump_page_cache", 0444,
1215 &vvp_dump_pgcache_file_ops, sbi);
1217 CWARN("Error adding the dump_page_cache file\n");
1219 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats", 0644,
1220 &ll_rw_extents_stats_fops, sbi);
1222 CWARN("Error adding the extent_stats file\n");
1224 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats_per_process",
1225 0644, &ll_rw_extents_stats_pp_fops, sbi);
1227 CWARN("Error adding the extents_stats_per_process file\n");
1229 rc = lprocfs_seq_create(sbi->ll_proc_root, "offset_stats", 0644,
1230 &ll_rw_offset_stats_fops, sbi);
1232 CWARN("Error adding the offset_stats file\n");
1234 /* File operations stats */
1235 sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
1236 LPROCFS_STATS_FLAG_NONE);
1237 if (sbi->ll_stats == NULL)
1238 GOTO(out, err = -ENOMEM);
1239 /* do counter init */
1240 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
1241 __u32 type = llite_opcode_table[id].type;
1243 if (type & LPROCFS_TYPE_REGS)
1245 else if (type & LPROCFS_TYPE_BYTES)
1247 else if (type & LPROCFS_TYPE_PAGES)
1249 lprocfs_counter_init(sbi->ll_stats,
1250 llite_opcode_table[id].opcode,
1251 (type & LPROCFS_CNTR_AVGMINMAX),
1252 llite_opcode_table[id].opname, ptr);
1254 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats);
1258 sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
1259 LPROCFS_STATS_FLAG_NONE);
1260 if (sbi->ll_ra_stats == NULL)
1261 GOTO(out, err = -ENOMEM);
1263 for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
1264 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
1265 ra_stat_string[id], "pages");
1266 err = lprocfs_register_stats(sbi->ll_proc_root, "read_ahead_stats",
1272 err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_llite_obd_vars, sb);
1277 obd = class_name2obd(mdc);
1279 LASSERT(obd != NULL);
1280 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1281 LASSERT(obd->obd_type->typ_name != NULL);
1283 dir = proc_mkdir(obd->obd_type->typ_name, sbi->ll_proc_root);
1285 GOTO(out, err = -ENOMEM);
1287 snprintf(name, MAX_STRING_SIZE, "common_name");
1288 lvars[0].fops = &llite_name_fops;
1289 err = lprocfs_add_vars(dir, lvars, obd);
1293 snprintf(name, MAX_STRING_SIZE, "uuid");
1294 lvars[0].fops = &llite_uuid_fops;
1295 err = lprocfs_add_vars(dir, lvars, obd);
1300 obd = class_name2obd(osc);
1302 LASSERT(obd != NULL);
1303 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1304 LASSERT(obd->obd_type->typ_name != NULL);
1306 dir = proc_mkdir(obd->obd_type->typ_name, sbi->ll_proc_root);
1308 GOTO(out, err = -ENOMEM);
1310 snprintf(name, MAX_STRING_SIZE, "common_name");
1311 lvars[0].fops = &llite_name_fops;
1312 err = lprocfs_add_vars(dir, lvars, obd);
1316 snprintf(name, MAX_STRING_SIZE, "uuid");
1317 lvars[0].fops = &llite_uuid_fops;
1318 err = lprocfs_add_vars(dir, lvars, obd);
1321 lprocfs_remove(&sbi->ll_proc_root);
1322 lprocfs_free_stats(&sbi->ll_ra_stats);
1323 lprocfs_free_stats(&sbi->ll_stats);
1328 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
1330 if (sbi->ll_proc_root) {
1331 lprocfs_remove(&sbi->ll_proc_root);
1332 lprocfs_free_stats(&sbi->ll_ra_stats);
1333 lprocfs_free_stats(&sbi->ll_stats);
1336 #undef MAX_STRING_SIZE
1338 #define pct(a,b) (b ? a * 100 / b : 0)
1340 static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
1341 struct seq_file *seq, int which)
1343 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
1344 unsigned long start, end, r, w;
1345 char *unitp = "KMGTPEZY";
1347 struct per_process_info *pp_info = &io_extents->pp_extents[which];
1353 for(i = 0; i < LL_HIST_MAX; i++) {
1354 read_tot += pp_info->pp_r_hist.oh_buckets[i];
1355 write_tot += pp_info->pp_w_hist.oh_buckets[i];
1358 for(i = 0; i < LL_HIST_MAX; i++) {
1359 r = pp_info->pp_r_hist.oh_buckets[i];
1360 w = pp_info->pp_w_hist.oh_buckets[i];
1363 end = 1 << (i + LL_HIST_START - units);
1364 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu | "
1365 "%14lu %4lu %4lu\n", start, *unitp, end, *unitp,
1366 (i == LL_HIST_MAX - 1) ? '+' : ' ',
1367 r, pct(r, read_tot), pct(read_cum, read_tot),
1368 w, pct(w, write_tot), pct(write_cum, write_tot));
1370 if (start == 1<<10) {
1375 if (read_cum == read_tot && write_cum == write_tot)
1380 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
1383 struct ll_sb_info *sbi = seq->private;
1384 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1387 do_gettimeofday(&now);
1389 if (!sbi->ll_rw_stats_on) {
1390 seq_puts(seq, "disabled\n write anything in this file to activate, then 0 or \[D/d]isabled\" to deactivate\n");
1393 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1394 now.tv_sec, now.tv_usec);
1395 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1396 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1397 "extents", "calls", "%", "cum%",
1398 "calls", "%", "cum%");
1399 spin_lock(&sbi->ll_pp_extent_lock);
1400 for (k = 0; k < LL_PROCESS_HIST_MAX; k++) {
1401 if (io_extents->pp_extents[k].pid != 0) {
1402 seq_printf(seq, "\nPID: %d\n",
1403 io_extents->pp_extents[k].pid);
1404 ll_display_extents_info(io_extents, seq, k);
1407 spin_unlock(&sbi->ll_pp_extent_lock);
1411 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
1412 const char __user *buf,
1416 struct seq_file *seq = file->private_data;
1417 struct ll_sb_info *sbi = seq->private;
1418 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1426 rc = lprocfs_str_to_s64(buf, len, &value);
1427 if (rc < 0 && len < 16) {
1430 if (copy_from_user(kernbuf, buf, len))
1434 if (kernbuf[len - 1] == '\n')
1435 kernbuf[len - 1] = 0;
1437 if (strcmp(kernbuf, "disabled") == 0 ||
1438 strcmp(kernbuf, "Disabled") == 0)
1443 sbi->ll_rw_stats_on = 0;
1445 sbi->ll_rw_stats_on = 1;
1447 spin_lock(&sbi->ll_pp_extent_lock);
1448 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1449 io_extents->pp_extents[i].pid = 0;
1450 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1451 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1453 spin_unlock(&sbi->ll_pp_extent_lock);
1457 LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
1459 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
1462 struct ll_sb_info *sbi = seq->private;
1463 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1465 do_gettimeofday(&now);
1467 if (!sbi->ll_rw_stats_on) {
1468 seq_puts(seq, "disabled\n write anything in this file to activate, then 0 or \"[D/d]isabled\" to deactivate\n");
1471 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1472 now.tv_sec, now.tv_usec);
1474 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1475 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1476 "extents", "calls", "%", "cum%",
1477 "calls", "%", "cum%");
1478 spin_lock(&sbi->ll_lock);
1479 ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
1480 spin_unlock(&sbi->ll_lock);
1485 static ssize_t ll_rw_extents_stats_seq_write(struct file *file,
1486 const char __user *buf,
1487 size_t len, loff_t *off)
1489 struct seq_file *seq = file->private_data;
1490 struct ll_sb_info *sbi = seq->private;
1491 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1499 rc = lprocfs_str_to_s64(buf, len, &value);
1500 if (rc < 0 && len < 16) {
1503 if (copy_from_user(kernbuf, buf, len))
1507 if (kernbuf[len - 1] == '\n')
1508 kernbuf[len - 1] = 0;
1510 if (strcmp(kernbuf, "disabled") == 0 ||
1511 strcmp(kernbuf, "Disabled") == 0)
1516 sbi->ll_rw_stats_on = 0;
1518 sbi->ll_rw_stats_on = 1;
1520 spin_lock(&sbi->ll_pp_extent_lock);
1521 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
1522 io_extents->pp_extents[i].pid = 0;
1523 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1524 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1526 spin_unlock(&sbi->ll_pp_extent_lock);
1530 LPROC_SEQ_FOPS(ll_rw_extents_stats);
1532 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
1533 struct ll_file_data *file, loff_t pos,
1534 size_t count, int rw)
1537 struct ll_rw_process_info *process;
1538 struct ll_rw_process_info *offset;
1539 int *off_count = &sbi->ll_rw_offset_entry_count;
1540 int *process_count = &sbi->ll_offset_process_count;
1541 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1543 if(!sbi->ll_rw_stats_on)
1545 process = sbi->ll_rw_process_info;
1546 offset = sbi->ll_rw_offset_info;
1548 spin_lock(&sbi->ll_pp_extent_lock);
1549 /* Extent statistics */
1550 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1551 if(io_extents->pp_extents[i].pid == pid) {
1559 sbi->ll_extent_process_count =
1560 (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1561 cur = sbi->ll_extent_process_count;
1562 io_extents->pp_extents[cur].pid = pid;
1563 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1564 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1567 for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
1568 (i < (LL_HIST_MAX - 1)); i++);
1570 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1571 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1573 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1574 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1576 spin_unlock(&sbi->ll_pp_extent_lock);
1578 spin_lock(&sbi->ll_process_lock);
1579 /* Offset statistics */
1580 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1581 if (process[i].rw_pid == pid) {
1582 if (process[i].rw_last_file != file) {
1583 process[i].rw_range_start = pos;
1584 process[i].rw_last_file_pos = pos + count;
1585 process[i].rw_smallest_extent = count;
1586 process[i].rw_largest_extent = count;
1587 process[i].rw_offset = 0;
1588 process[i].rw_last_file = file;
1589 spin_unlock(&sbi->ll_process_lock);
1592 if (process[i].rw_last_file_pos != pos) {
1594 (*off_count + 1) % LL_OFFSET_HIST_MAX;
1595 offset[*off_count].rw_op = process[i].rw_op;
1596 offset[*off_count].rw_pid = pid;
1597 offset[*off_count].rw_range_start =
1598 process[i].rw_range_start;
1599 offset[*off_count].rw_range_end =
1600 process[i].rw_last_file_pos;
1601 offset[*off_count].rw_smallest_extent =
1602 process[i].rw_smallest_extent;
1603 offset[*off_count].rw_largest_extent =
1604 process[i].rw_largest_extent;
1605 offset[*off_count].rw_offset =
1606 process[i].rw_offset;
1607 process[i].rw_op = rw;
1608 process[i].rw_range_start = pos;
1609 process[i].rw_smallest_extent = count;
1610 process[i].rw_largest_extent = count;
1611 process[i].rw_offset = pos -
1612 process[i].rw_last_file_pos;
1614 if(process[i].rw_smallest_extent > count)
1615 process[i].rw_smallest_extent = count;
1616 if(process[i].rw_largest_extent < count)
1617 process[i].rw_largest_extent = count;
1618 process[i].rw_last_file_pos = pos + count;
1619 spin_unlock(&sbi->ll_process_lock);
1623 *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
1624 process[*process_count].rw_pid = pid;
1625 process[*process_count].rw_op = rw;
1626 process[*process_count].rw_range_start = pos;
1627 process[*process_count].rw_last_file_pos = pos + count;
1628 process[*process_count].rw_smallest_extent = count;
1629 process[*process_count].rw_largest_extent = count;
1630 process[*process_count].rw_offset = 0;
1631 process[*process_count].rw_last_file = file;
1632 spin_unlock(&sbi->ll_process_lock);
1635 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1638 struct ll_sb_info *sbi = seq->private;
1639 struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
1640 struct ll_rw_process_info *process = sbi->ll_rw_process_info;
1643 do_gettimeofday(&now);
1645 if (!sbi->ll_rw_stats_on) {
1646 seq_puts(seq, "disabled\n write anything in this file to activate, then 0 or \"[D/d]isabled\" to deactivate\n");
1649 spin_lock(&sbi->ll_process_lock);
1651 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1652 now.tv_sec, now.tv_usec);
1653 seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
1654 "R/W", "PID", "RANGE START", "RANGE END",
1655 "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
1657 /* We stored the discontiguous offsets here; print them first */
1658 for (i = 0; i < LL_OFFSET_HIST_MAX; i++) {
1659 if (offset[i].rw_pid != 0)
1661 "%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1662 offset[i].rw_op == READ ? 'R' : 'W',
1664 offset[i].rw_range_start,
1665 offset[i].rw_range_end,
1666 (unsigned long)offset[i].rw_smallest_extent,
1667 (unsigned long)offset[i].rw_largest_extent,
1668 offset[i].rw_offset);
1671 /* Then print the current offsets for each process */
1672 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1673 if (process[i].rw_pid != 0)
1675 "%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1676 process[i].rw_op == READ ? 'R' : 'W',
1678 process[i].rw_range_start,
1679 process[i].rw_last_file_pos,
1680 (unsigned long)process[i].rw_smallest_extent,
1681 (unsigned long)process[i].rw_largest_extent,
1682 process[i].rw_offset);
1684 spin_unlock(&sbi->ll_process_lock);
1689 static ssize_t ll_rw_offset_stats_seq_write(struct file *file,
1690 const char __user *buf,
1691 size_t len, loff_t *off)
1693 struct seq_file *seq = file->private_data;
1694 struct ll_sb_info *sbi = seq->private;
1695 struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
1696 struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
1703 rc = lprocfs_str_to_s64(buf, len, &value);
1705 if (rc < 0 && len < 16) {
1708 if (copy_from_user(kernbuf, buf, len))
1712 if (kernbuf[len - 1] == '\n')
1713 kernbuf[len - 1] = 0;
1715 if (strcmp(kernbuf, "disabled") == 0 ||
1716 strcmp(kernbuf, "Disabled") == 0)
1721 sbi->ll_rw_stats_on = 0;
1723 sbi->ll_rw_stats_on = 1;
1725 spin_lock(&sbi->ll_process_lock);
1726 sbi->ll_offset_process_count = 0;
1727 sbi->ll_rw_offset_entry_count = 0;
1728 memset(process_info, 0, sizeof(struct ll_rw_process_info) *
1729 LL_PROCESS_HIST_MAX);
1730 memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
1731 LL_OFFSET_HIST_MAX);
1732 spin_unlock(&sbi->ll_process_lock);
1737 LPROC_SEQ_FOPS(ll_rw_offset_stats);
1738 #endif /* CONFIG_PROC_FS */