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, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 #define DEBUG_SUBSYSTEM S_LLITE
38 #include <linux/version.h>
39 #include <lustre_lite.h>
40 #include <lustre_param.h>
41 #include <lprocfs_status.h>
42 #include <obd_support.h>
44 #include "llite_internal.h"
45 #include "vvp_internal.h"
47 struct proc_dir_entry *proc_lustre_fs_root;
50 /* /proc/lustre/llite mount point registration */
51 struct file_operations ll_rw_extents_stats_fops;
52 struct file_operations ll_rw_extents_stats_pp_fops;
53 struct file_operations ll_rw_offset_stats_fops;
55 static int ll_blksize_seq_show(struct seq_file *m, void *v)
57 struct super_block *sb = m->private;
58 struct obd_statfs osfs;
62 rc = ll_statfs_internal(sb, &osfs,
63 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
66 rc = seq_printf(m, "%u\n", osfs.os_bsize);
69 LPROC_SEQ_FOPS_RO(ll_blksize);
71 static int ll_kbytestotal_seq_show(struct seq_file *m, void *v)
73 struct super_block *sb = m->private;
74 struct obd_statfs osfs;
78 rc = ll_statfs_internal(sb, &osfs,
79 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
82 __u32 blk_size = osfs.os_bsize >> 10;
83 __u64 result = osfs.os_blocks;
85 while (blk_size >>= 1)
88 rc = seq_printf(m, LPU64"\n", result);
92 LPROC_SEQ_FOPS_RO(ll_kbytestotal);
94 static int ll_kbytesfree_seq_show(struct seq_file *m, void *v)
96 struct super_block *sb = m->private;
97 struct obd_statfs osfs;
101 rc = ll_statfs_internal(sb, &osfs,
102 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
105 __u32 blk_size = osfs.os_bsize >> 10;
106 __u64 result = osfs.os_bfree;
108 while (blk_size >>= 1)
111 rc = seq_printf(m, LPU64"\n", result);
115 LPROC_SEQ_FOPS_RO(ll_kbytesfree);
117 static int ll_kbytesavail_seq_show(struct seq_file *m, void *v)
119 struct super_block *sb = m->private;
120 struct obd_statfs osfs;
124 rc = ll_statfs_internal(sb, &osfs,
125 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
128 __u32 blk_size = osfs.os_bsize >> 10;
129 __u64 result = osfs.os_bavail;
131 while (blk_size >>= 1)
134 rc = seq_printf(m, LPU64"\n", result);
138 LPROC_SEQ_FOPS_RO(ll_kbytesavail);
140 static int ll_filestotal_seq_show(struct seq_file *m, void *v)
142 struct super_block *sb = m->private;
143 struct obd_statfs osfs;
147 rc = ll_statfs_internal(sb, &osfs,
148 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
151 rc = seq_printf(m, LPU64"\n", osfs.os_files);
154 LPROC_SEQ_FOPS_RO(ll_filestotal);
156 static int ll_filesfree_seq_show(struct seq_file *m, void *v)
158 struct super_block *sb = m->private;
159 struct obd_statfs osfs;
163 rc = ll_statfs_internal(sb, &osfs,
164 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
167 rc = seq_printf(m, LPU64"\n", osfs.os_ffree);
170 LPROC_SEQ_FOPS_RO(ll_filesfree);
172 static int ll_client_type_seq_show(struct seq_file *m, void *v)
174 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
177 LASSERT(sbi != NULL);
179 if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
180 rc = seq_printf(m, "remote client\n");
182 rc = seq_printf(m, "local client\n");
185 LPROC_SEQ_FOPS_RO(ll_client_type);
187 static int ll_fstype_seq_show(struct seq_file *m, void *v)
189 struct super_block *sb = m->private;
192 return 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 return seq_printf(m, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
203 LPROC_SEQ_FOPS_RO(ll_sb_uuid);
205 static int ll_xattr_cache_seq_show(struct seq_file *m, void *v)
207 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
209 return seq_printf(m, "%u\n", sbi->ll_xattr_cache_enabled);
212 static ssize_t ll_xattr_cache_seq_write(struct file *file, const char *buffer,
213 size_t count, loff_t *off)
215 struct seq_file *m = file->private_data;
216 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
219 rc = lprocfs_write_helper(buffer, count, &val);
223 if (val != 0 && val != 1)
226 if (val == 1 && !(sbi->ll_flags & LL_SBI_XATTR_CACHE))
229 sbi->ll_xattr_cache_enabled = val;
233 LPROC_SEQ_FOPS(ll_xattr_cache);
235 static int ll_site_stats_seq_show(struct seq_file *m, void *v)
237 struct super_block *sb = m->private;
240 * See description of statistical counters in struct cl_site, and
243 return cl_site_stats_print(lu2cl_site(ll_s2sbi(sb)->ll_site), m);
245 LPROC_SEQ_FOPS_RO(ll_site_stats);
247 static int ll_max_readahead_mb_seq_show(struct seq_file *m, void *v)
249 struct super_block *sb = m->private;
250 struct ll_sb_info *sbi = ll_s2sbi(sb);
254 spin_lock(&sbi->ll_lock);
255 pages_number = sbi->ll_ra_info.ra_max_pages;
256 spin_unlock(&sbi->ll_lock);
258 mult = 1 << (20 - PAGE_CACHE_SHIFT);
259 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
263 ll_max_readahead_mb_seq_write(struct file *file, const char *buffer,
264 size_t count, loff_t *off)
266 struct seq_file *m = file->private_data;
267 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
268 int mult, rc, pages_number;
270 mult = 1 << (20 - PAGE_CACHE_SHIFT);
271 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
275 if (pages_number < 0 || pages_number > totalram_pages / 2) {
277 CERROR("can't set file readahead more than %lu MB\n",
278 totalram_pages >> (20 - PAGE_CACHE_SHIFT + 1));
282 spin_lock(&sbi->ll_lock);
283 sbi->ll_ra_info.ra_max_pages = pages_number;
284 spin_unlock(&sbi->ll_lock);
287 LPROC_SEQ_FOPS(ll_max_readahead_mb);
289 static int ll_max_readahead_per_file_mb_seq_show(struct seq_file *m, void *v)
291 struct super_block *sb = m->private;
292 struct ll_sb_info *sbi = ll_s2sbi(sb);
296 spin_lock(&sbi->ll_lock);
297 pages_number = sbi->ll_ra_info.ra_max_pages_per_file;
298 spin_unlock(&sbi->ll_lock);
300 mult = 1 << (20 - PAGE_CACHE_SHIFT);
301 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
305 ll_max_readahead_per_file_mb_seq_write(struct file *file, const char *buffer,
306 size_t count, loff_t *off)
308 struct seq_file *m = file->private_data;
309 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
310 int mult, rc, pages_number;
312 mult = 1 << (20 - PAGE_CACHE_SHIFT);
313 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
317 if (pages_number < 0 ||
318 pages_number > sbi->ll_ra_info.ra_max_pages) {
319 CERROR("can't set file readahead more than"
320 "max_read_ahead_mb %lu MB\n",
321 sbi->ll_ra_info.ra_max_pages);
325 spin_lock(&sbi->ll_lock);
326 sbi->ll_ra_info.ra_max_pages_per_file = pages_number;
327 spin_unlock(&sbi->ll_lock);
330 LPROC_SEQ_FOPS(ll_max_readahead_per_file_mb);
332 static int ll_max_read_ahead_whole_mb_seq_show(struct seq_file *m, void *v)
334 struct super_block *sb = m->private;
335 struct ll_sb_info *sbi = ll_s2sbi(sb);
339 spin_lock(&sbi->ll_lock);
340 pages_number = sbi->ll_ra_info.ra_max_read_ahead_whole_pages;
341 spin_unlock(&sbi->ll_lock);
343 mult = 1 << (20 - PAGE_CACHE_SHIFT);
344 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
348 ll_max_read_ahead_whole_mb_seq_write(struct file *file, const char *buffer,
349 size_t count, loff_t *off)
351 struct seq_file *m = file->private_data;
352 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
353 int mult, rc, pages_number;
355 mult = 1 << (20 - PAGE_CACHE_SHIFT);
356 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
360 /* Cap this at the current max readahead window size, the readahead
361 * algorithm does this anyway so it's pointless to set it larger. */
362 if (pages_number < 0 ||
363 pages_number > sbi->ll_ra_info.ra_max_pages_per_file) {
364 CERROR("can't set max_read_ahead_whole_mb more than "
365 "max_read_ahead_per_file_mb: %lu\n",
366 sbi->ll_ra_info.ra_max_pages_per_file >>
367 (20 - PAGE_CACHE_SHIFT));
371 spin_lock(&sbi->ll_lock);
372 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = pages_number;
373 spin_unlock(&sbi->ll_lock);
376 LPROC_SEQ_FOPS(ll_max_read_ahead_whole_mb);
378 static int ll_max_cached_mb_seq_show(struct seq_file *m, void *v)
380 struct super_block *sb = m->private;
381 struct ll_sb_info *sbi = ll_s2sbi(sb);
382 struct cl_client_cache *cache = &sbi->ll_cache;
383 int shift = 20 - PAGE_CACHE_SHIFT;
387 max_cached_mb = cache->ccc_lru_max >> shift;
388 unused_mb = atomic_read(&cache->ccc_lru_left) >> shift;
391 "max_cached_mb: %d\n"
394 "reclaim_count: %u\n",
395 atomic_read(&cache->ccc_users),
397 max_cached_mb - unused_mb,
399 cache->ccc_lru_shrinkers);
403 ll_max_cached_mb_seq_write(struct file *file, const char __user *buffer,
404 size_t count, loff_t *off)
406 struct seq_file *m = file->private_data;
407 struct super_block *sb = m->private;
408 struct ll_sb_info *sbi = ll_s2sbi(sb);
409 struct cl_client_cache *cache = &sbi->ll_cache;
412 int mult, rc, pages_number;
418 if (count >= sizeof(kernbuf))
421 if (copy_from_user(kernbuf, buffer, count))
425 mult = 1 << (20 - PAGE_CACHE_SHIFT);
426 buffer += lprocfs_find_named_value(kernbuf, "max_cached_mb:", &count) -
428 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
432 if (pages_number < 0 || pages_number > totalram_pages) {
433 CERROR("%s: can't set max cache more than %lu MB\n",
434 ll_get_fsname(sb, NULL, 0),
435 totalram_pages >> (20 - PAGE_CACHE_SHIFT));
439 if (sbi->ll_dt_exp == NULL) /* being initialized */
442 spin_lock(&sbi->ll_lock);
443 diff = pages_number - cache->ccc_lru_max;
444 spin_unlock(&sbi->ll_lock);
446 /* easy - add more LRU slots. */
448 atomic_add(diff, &cache->ccc_lru_left);
452 env = cl_env_get(&refcheck);
460 /* reduce LRU budget from free slots. */
464 ov = atomic_read(&cache->ccc_lru_left);
468 nv = ov > diff ? ov - diff : 0;
469 rc = atomic_cmpxchg(&cache->ccc_lru_left, ov, nv);
470 if (likely(ov == rc)) {
480 /* difficult - have to ask OSCs to drop LRU slots. */
482 rc = obd_set_info_async(env, sbi->ll_dt_exp,
483 sizeof(KEY_CACHE_LRU_SHRINK),
484 KEY_CACHE_LRU_SHRINK,
485 sizeof(tmp), &tmp, NULL);
489 cl_env_put(env, &refcheck);
493 spin_lock(&sbi->ll_lock);
494 cache->ccc_lru_max = pages_number;
495 spin_unlock(&sbi->ll_lock);
498 atomic_add(nrpages, &cache->ccc_lru_left);
502 LPROC_SEQ_FOPS(ll_max_cached_mb);
504 static int ll_checksum_seq_show(struct seq_file *m, void *v)
506 struct super_block *sb = m->private;
507 struct ll_sb_info *sbi = ll_s2sbi(sb);
509 return seq_printf(m, "%u\n", (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0);
512 static ssize_t ll_checksum_seq_write(struct file *file, const char *buffer,
513 size_t count, loff_t *off)
515 struct seq_file *m = file->private_data;
516 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
523 rc = lprocfs_write_helper(buffer, count, &val);
527 sbi->ll_flags |= LL_SBI_CHECKSUM;
529 sbi->ll_flags &= ~LL_SBI_CHECKSUM;
531 rc = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
532 KEY_CHECKSUM, sizeof(val), &val, NULL);
534 CWARN("Failed to set OSC checksum flags: %d\n", rc);
538 LPROC_SEQ_FOPS(ll_checksum);
540 static int ll_max_rw_chunk_seq_show(struct seq_file *m, void *v)
542 struct super_block *sb = m->private;
544 return seq_printf(m, "%lu\n", ll_s2sbi(sb)->ll_max_rw_chunk);
547 static ssize_t ll_max_rw_chunk_seq_write(struct file *file, const char *buffer,
548 size_t count, loff_t *off)
550 struct seq_file *m = file->private_data;
551 struct super_block *sb = m->private;
554 rc = lprocfs_write_helper(buffer, count, &val);
557 ll_s2sbi(sb)->ll_max_rw_chunk = val;
560 LPROC_SEQ_FOPS(ll_max_rw_chunk);
562 static int ll_rd_track_id(struct seq_file *m, enum stats_track_type type)
564 struct super_block *sb = m->private;
566 if (ll_s2sbi(sb)->ll_stats_track_type == type) {
567 return seq_printf(m, "%d\n",
568 ll_s2sbi(sb)->ll_stats_track_id);
569 } else if (ll_s2sbi(sb)->ll_stats_track_type == STATS_TRACK_ALL) {
570 return seq_printf(m, "0 (all)\n");
572 return seq_printf(m, "untracked\n");
576 static int ll_wr_track_id(const char *buffer, unsigned long count, void *data,
577 enum stats_track_type type)
579 struct super_block *sb = data;
582 rc = lprocfs_write_helper(buffer, count, &pid);
585 ll_s2sbi(sb)->ll_stats_track_id = pid;
587 ll_s2sbi(sb)->ll_stats_track_type = STATS_TRACK_ALL;
589 ll_s2sbi(sb)->ll_stats_track_type = type;
590 lprocfs_clear_stats(ll_s2sbi(sb)->ll_stats);
594 static int ll_track_pid_seq_show(struct seq_file *m, void *v)
596 return ll_rd_track_id(m, STATS_TRACK_PID);
599 static ssize_t ll_track_pid_seq_write(struct file *file, const char *buffer,
600 size_t count, loff_t *off)
602 struct seq_file *seq = file->private_data;
603 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PID);
605 LPROC_SEQ_FOPS(ll_track_pid);
607 static int ll_track_ppid_seq_show(struct seq_file *m, void *v)
609 return ll_rd_track_id(m, STATS_TRACK_PPID);
612 static ssize_t ll_track_ppid_seq_write(struct file *file, const char *buffer,
613 size_t count, loff_t *off)
615 struct seq_file *seq = file->private_data;
616 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PPID);
618 LPROC_SEQ_FOPS(ll_track_ppid);
620 static int ll_track_gid_seq_show(struct seq_file *m, void *v)
622 return ll_rd_track_id(m, STATS_TRACK_GID);
625 static ssize_t ll_track_gid_seq_write(struct file *file, const char *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_GID);
631 LPROC_SEQ_FOPS(ll_track_gid);
633 static int ll_statahead_max_seq_show(struct seq_file *m, void *v)
635 struct super_block *sb = m->private;
636 struct ll_sb_info *sbi = ll_s2sbi(sb);
638 return seq_printf(m, "%u\n", sbi->ll_sa_max);
641 static ssize_t ll_statahead_max_seq_write(struct file *file, const char *buffer,
642 size_t count, loff_t *off)
644 struct seq_file *m = file->private_data;
645 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
648 rc = lprocfs_write_helper(buffer, count, &val);
652 if (val >= 0 && val <= LL_SA_RPC_MAX)
653 sbi->ll_sa_max = val;
655 CERROR("Bad statahead_max value %d. Valid values are in the "
656 "range [0, %d]\n", val, LL_SA_RPC_MAX);
660 LPROC_SEQ_FOPS(ll_statahead_max);
662 static int ll_statahead_agl_seq_show(struct seq_file *m, void *v)
664 struct super_block *sb = m->private;
665 struct ll_sb_info *sbi = ll_s2sbi(sb);
667 return seq_printf(m, "%u\n",
668 sbi->ll_flags & LL_SBI_AGL_ENABLED ? 1 : 0);
671 static ssize_t ll_statahead_agl_seq_write(struct file *file, const char *buffer,
672 size_t count, loff_t *off)
674 struct seq_file *m = file->private_data;
675 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
678 rc = lprocfs_write_helper(buffer, count, &val);
683 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
685 sbi->ll_flags &= ~LL_SBI_AGL_ENABLED;
689 LPROC_SEQ_FOPS(ll_statahead_agl);
691 static int ll_statahead_stats_seq_show(struct seq_file *m, void *v)
693 struct super_block *sb = m->private;
694 struct ll_sb_info *sbi = ll_s2sbi(sb);
697 "statahead total: %u\n"
698 "statahead wrong: %u\n"
700 atomic_read(&sbi->ll_sa_total),
701 atomic_read(&sbi->ll_sa_wrong),
702 atomic_read(&sbi->ll_agl_total));
704 LPROC_SEQ_FOPS_RO(ll_statahead_stats);
706 static int ll_lazystatfs_seq_show(struct seq_file *m, void *v)
708 struct super_block *sb = m->private;
709 struct ll_sb_info *sbi = ll_s2sbi(sb);
711 return seq_printf(m, "%u\n",
712 (sbi->ll_flags & LL_SBI_LAZYSTATFS) ? 1 : 0);
715 static ssize_t ll_lazystatfs_seq_write(struct file *file, const char *buffer,
716 size_t count, loff_t *off)
718 struct seq_file *m = file->private_data;
719 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
722 rc = lprocfs_write_helper(buffer, count, &val);
727 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
729 sbi->ll_flags &= ~LL_SBI_LAZYSTATFS;
733 LPROC_SEQ_FOPS(ll_lazystatfs);
735 static int ll_max_easize_seq_show(struct seq_file *m, void *v)
737 struct super_block *sb = m->private;
738 struct ll_sb_info *sbi = ll_s2sbi(sb);
742 rc = ll_get_max_mdsize(sbi, &ealen);
746 return seq_printf(m, "%u\n", ealen);
748 LPROC_SEQ_FOPS_RO(ll_max_easize);
750 static int ll_defult_easize_seq_show(struct seq_file *m, void *v)
752 struct super_block *sb = m->private;
753 struct ll_sb_info *sbi = ll_s2sbi(sb);
757 rc = ll_get_default_mdsize(sbi, &ealen);
761 return seq_printf(m, "%u\n", ealen);
763 LPROC_SEQ_FOPS_RO(ll_defult_easize);
765 static int ll_max_cookiesize_seq_show(struct seq_file *m, void *v)
767 struct super_block *sb = m->private;
768 struct ll_sb_info *sbi = ll_s2sbi(sb);
769 unsigned int cookielen;
772 rc = ll_get_max_cookiesize(sbi, &cookielen);
776 return seq_printf(m, "%u\n", cookielen);
778 LPROC_SEQ_FOPS_RO(ll_max_cookiesize);
780 static int ll_defult_cookiesize_seq_show(struct seq_file *m, void *v)
782 struct super_block *sb = m->private;
783 struct ll_sb_info *sbi = ll_s2sbi(sb);
784 unsigned int cookielen;
787 rc = ll_get_default_cookiesize(sbi, &cookielen);
791 return seq_printf(m, "%u\n", cookielen);
793 LPROC_SEQ_FOPS_RO(ll_defult_cookiesize);
795 static int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
797 const char *str[] = LL_SBI_FLAGS;
798 struct super_block *sb = m->private;
799 int flags = ll_s2sbi(sb)->ll_flags;
803 if (ARRAY_SIZE(str) <= i) {
804 CERROR("%s: Revise array LL_SBI_FLAGS to match sbi "
805 "flags please.\n", ll_get_fsname(sb, NULL, 0));
810 seq_printf(m, "%s ", str[i]);
814 seq_printf(m, "\b\n");
817 LPROC_SEQ_FOPS_RO(ll_sbi_flags);
819 static int ll_unstable_stats_seq_show(struct seq_file *m, void *v)
821 struct super_block *sb = m->private;
822 struct ll_sb_info *sbi = ll_s2sbi(sb);
823 struct cl_client_cache *cache = &sbi->ll_cache;
826 pages = atomic_read(&cache->ccc_unstable_nr);
827 mb = (pages * PAGE_CACHE_SIZE) >> 20;
829 return seq_printf(m, "unstable_check: %8d\n"
830 "unstable_pages: %8d\n"
831 "unstable_mb: %8d\n",
832 cache->ccc_unstable_check, pages, mb);
835 static ssize_t ll_unstable_stats_seq_write(struct file *file,
836 const char __user *buffer,
837 size_t count, loff_t *unused)
839 struct seq_file *seq = file->private_data;
840 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)seq->private);
846 if (count < 0 || count >= sizeof(kernbuf))
849 if (copy_from_user(kernbuf, buffer, count))
853 buffer += lprocfs_find_named_value(kernbuf, "unstable_check:", &count) -
855 rc = lprocfs_write_helper(buffer, count, &val);
859 /* borrow lru lock to set the value */
860 spin_lock(&sbi->ll_cache.ccc_lru_lock);
861 sbi->ll_cache.ccc_unstable_check = !!val;
862 spin_unlock(&sbi->ll_cache.ccc_lru_lock);
866 LPROC_SEQ_FOPS(ll_unstable_stats);
868 static int ll_root_squash_seq_show(struct seq_file *m, void *v)
870 struct super_block *sb = m->private;
871 struct ll_sb_info *sbi = ll_s2sbi(sb);
872 struct root_squash_info *squash = &sbi->ll_squash;
874 return seq_printf(m, "%u:%u\n", squash->rsi_uid, squash->rsi_gid);
877 static ssize_t ll_root_squash_seq_write(struct file *file,
878 const char __user *buffer,
879 size_t count, loff_t *off)
881 struct seq_file *m = file->private_data;
882 struct super_block *sb = m->private;
883 struct ll_sb_info *sbi = ll_s2sbi(sb);
884 struct root_squash_info *squash = &sbi->ll_squash;
886 return lprocfs_wr_root_squash(buffer, count, squash,
887 ll_get_fsname(sb, NULL, 0));
889 LPROC_SEQ_FOPS(ll_root_squash);
891 static int ll_nosquash_nids_seq_show(struct seq_file *m, void *v)
893 struct super_block *sb = m->private;
894 struct ll_sb_info *sbi = ll_s2sbi(sb);
895 struct root_squash_info *squash = &sbi->ll_squash;
898 down_read(&squash->rsi_sem);
899 if (!list_empty(&squash->rsi_nosquash_nids)) {
900 len = cfs_print_nidlist(m->buf + m->count, m->size - m->count,
901 &squash->rsi_nosquash_nids);
903 rc = seq_printf(m, "\n");
905 rc = seq_printf(m, "NONE\n");
907 up_read(&squash->rsi_sem);
912 static ssize_t ll_nosquash_nids_seq_write(struct file *file,
913 const char __user *buffer,
914 size_t count, loff_t *off)
916 struct seq_file *m = file->private_data;
917 struct super_block *sb = m->private;
918 struct ll_sb_info *sbi = ll_s2sbi(sb);
919 struct root_squash_info *squash = &sbi->ll_squash;
922 rc = lprocfs_wr_nosquash_nids(buffer, count, squash,
923 ll_get_fsname(sb, NULL, 0));
927 ll_compute_rootsquash_state(sbi);
931 LPROC_SEQ_FOPS(ll_nosquash_nids);
933 struct lprocfs_seq_vars lprocfs_llite_obd_vars[] = {
935 .fops = &ll_sb_uuid_fops },
937 .fops = &ll_fstype_fops },
939 .fops = &ll_site_stats_fops },
940 { .name = "blocksize",
941 .fops = &ll_blksize_fops },
942 { .name = "kbytestotal",
943 .fops = &ll_kbytestotal_fops },
944 { .name = "kbytesfree",
945 .fops = &ll_kbytesfree_fops },
946 { .name = "kbytesavail",
947 .fops = &ll_kbytesavail_fops },
948 { .name = "filestotal",
949 .fops = &ll_filestotal_fops },
950 { .name = "filesfree",
951 .fops = &ll_filesfree_fops },
952 { .name = "client_type",
953 .fops = &ll_client_type_fops },
954 { .name = "max_read_ahead_mb",
955 .fops = &ll_max_readahead_mb_fops },
956 { .name = "max_read_ahead_per_file_mb",
957 .fops = &ll_max_readahead_per_file_mb_fops },
958 { .name = "max_read_ahead_whole_mb",
959 .fops = &ll_max_read_ahead_whole_mb_fops },
960 { .name = "max_cached_mb",
961 .fops = &ll_max_cached_mb_fops },
962 { .name = "checksum_pages",
963 .fops = &ll_checksum_fops },
964 { .name = "max_rw_chunk",
965 .fops = &ll_max_rw_chunk_fops },
966 { .name = "stats_track_pid",
967 .fops = &ll_track_pid_fops },
968 { .name = "stats_track_ppid",
969 .fops = &ll_track_ppid_fops },
970 { .name = "stats_track_gid",
971 .fops = &ll_track_gid_fops },
972 { .name = "statahead_max",
973 .fops = &ll_statahead_max_fops },
974 { .name = "statahead_agl",
975 .fops = &ll_statahead_agl_fops },
976 { .name = "statahead_stats",
977 .fops = &ll_statahead_stats_fops },
978 { .name = "lazystatfs",
979 .fops = &ll_lazystatfs_fops },
980 { .name = "max_easize",
981 .fops = &ll_max_easize_fops },
982 { .name = "default_easize",
983 .fops = &ll_defult_easize_fops },
984 { .name = "max_cookiesize",
985 .fops = &ll_max_cookiesize_fops },
986 { .name = "default_cookiesize",
987 .fops = &ll_defult_cookiesize_fops },
988 { .name = "sbi_flags",
989 .fops = &ll_sbi_flags_fops },
990 { .name = "xattr_cache",
991 .fops = &ll_xattr_cache_fops },
992 { .name = "unstable_stats",
993 .fops = &ll_unstable_stats_fops },
994 { .name = "root_squash",
995 .fops = &ll_root_squash_fops },
996 { .name = "nosquash_nids",
997 .fops = &ll_nosquash_nids_fops },
1001 #define MAX_STRING_SIZE 128
1003 static const struct llite_file_opcode {
1007 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
1008 /* file operation */
1009 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
1010 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
1011 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1013 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1015 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
1017 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
1019 { LPROC_LL_OSC_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1021 { LPROC_LL_OSC_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1023 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
1024 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
1025 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
1026 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
1027 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
1028 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
1029 { LPROC_LL_READDIR, LPROCFS_TYPE_REGS, "readdir" },
1030 /* inode operation */
1031 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
1032 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "truncate" },
1033 { LPROC_LL_FLOCK, LPROCFS_TYPE_REGS, "flock" },
1034 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
1035 /* dir inode operation */
1036 { LPROC_LL_CREATE, LPROCFS_TYPE_REGS, "create" },
1037 { LPROC_LL_LINK, LPROCFS_TYPE_REGS, "link" },
1038 { LPROC_LL_UNLINK, LPROCFS_TYPE_REGS, "unlink" },
1039 { LPROC_LL_SYMLINK, LPROCFS_TYPE_REGS, "symlink" },
1040 { LPROC_LL_MKDIR, LPROCFS_TYPE_REGS, "mkdir" },
1041 { LPROC_LL_RMDIR, LPROCFS_TYPE_REGS, "rmdir" },
1042 { LPROC_LL_MKNOD, LPROCFS_TYPE_REGS, "mknod" },
1043 { LPROC_LL_RENAME, LPROCFS_TYPE_REGS, "rename" },
1044 /* special inode operation */
1045 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
1046 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
1047 { LPROC_LL_SETXATTR, LPROCFS_TYPE_REGS, "setxattr" },
1048 { LPROC_LL_GETXATTR, LPROCFS_TYPE_REGS, "getxattr" },
1049 { LPROC_LL_GETXATTR_HITS, LPROCFS_TYPE_REGS, "getxattr_hits" },
1050 { LPROC_LL_LISTXATTR, LPROCFS_TYPE_REGS, "listxattr" },
1051 { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_REGS, "removexattr" },
1052 { LPROC_LL_INODE_PERM, LPROCFS_TYPE_REGS, "inode_permission" },
1055 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
1059 if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
1060 lprocfs_counter_add(sbi->ll_stats, op, count);
1061 else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
1062 sbi->ll_stats_track_id == current->pid)
1063 lprocfs_counter_add(sbi->ll_stats, op, count);
1064 else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
1065 sbi->ll_stats_track_id == current->parent->pid)
1066 lprocfs_counter_add(sbi->ll_stats, op, count);
1067 else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
1068 sbi->ll_stats_track_id ==
1069 from_kgid(&init_user_ns, current_gid()))
1070 lprocfs_counter_add(sbi->ll_stats, op, count);
1072 EXPORT_SYMBOL(ll_stats_ops_tally);
1074 static const char *ra_stat_string[] = {
1075 [RA_STAT_HIT] = "hits",
1076 [RA_STAT_MISS] = "misses",
1077 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
1078 [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
1079 [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page",
1080 [RA_STAT_FAILED_MATCH] = "failed lock match",
1081 [RA_STAT_DISCARDED] = "read but discarded",
1082 [RA_STAT_ZERO_LEN] = "zero length file",
1083 [RA_STAT_ZERO_WINDOW] = "zero size window",
1084 [RA_STAT_EOF] = "read-ahead to EOF",
1085 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
1086 [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",
1087 [RA_STAT_FAILED_REACH_END] = "failed to reach end"
1090 LPROC_SEQ_FOPS_RO_TYPE(llite, name);
1091 LPROC_SEQ_FOPS_RO_TYPE(llite, uuid);
1093 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
1094 struct super_block *sb, char *osc, char *mdc)
1096 struct lprocfs_seq_vars lvars[2];
1097 struct lustre_sb_info *lsi = s2lsi(sb);
1098 struct ll_sb_info *sbi = ll_s2sbi(sb);
1099 struct obd_device *obd;
1100 struct proc_dir_entry *dir;
1101 char name[MAX_STRING_SIZE + 1], *ptr;
1102 int err, id, len, rc;
1105 memset(lvars, 0, sizeof(lvars));
1107 name[MAX_STRING_SIZE] = '\0';
1108 lvars[0].name = name;
1110 LASSERT(sbi != NULL);
1111 LASSERT(mdc != NULL);
1112 LASSERT(osc != NULL);
1115 len = strlen(lsi->lsi_lmd->lmd_profile);
1116 ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
1117 if (ptr && (strcmp(ptr, "-client") == 0))
1121 snprintf(name, MAX_STRING_SIZE, "%.*s-%p", len,
1122 lsi->lsi_lmd->lmd_profile, sb);
1124 sbi->ll_proc_root = lprocfs_seq_register(name, parent, NULL, NULL);
1125 if (IS_ERR(sbi->ll_proc_root)) {
1126 err = PTR_ERR(sbi->ll_proc_root);
1127 sbi->ll_proc_root = NULL;
1131 rc = lprocfs_seq_create(sbi->ll_proc_root, "dump_page_cache", 0444,
1132 &vvp_dump_pgcache_file_ops, sbi);
1134 CWARN("Error adding the dump_page_cache file\n");
1136 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats", 0644,
1137 &ll_rw_extents_stats_fops, sbi);
1139 CWARN("Error adding the extent_stats file\n");
1141 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats_per_process",
1142 0644, &ll_rw_extents_stats_pp_fops, sbi);
1144 CWARN("Error adding the extents_stats_per_process file\n");
1146 rc = lprocfs_seq_create(sbi->ll_proc_root, "offset_stats", 0644,
1147 &ll_rw_offset_stats_fops, sbi);
1149 CWARN("Error adding the offset_stats file\n");
1151 /* File operations stats */
1152 sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
1153 LPROCFS_STATS_FLAG_NONE);
1154 if (sbi->ll_stats == NULL)
1155 GOTO(out, err = -ENOMEM);
1156 /* do counter init */
1157 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
1158 __u32 type = llite_opcode_table[id].type;
1160 if (type & LPROCFS_TYPE_REGS)
1162 else if (type & LPROCFS_TYPE_BYTES)
1164 else if (type & LPROCFS_TYPE_PAGES)
1166 lprocfs_counter_init(sbi->ll_stats,
1167 llite_opcode_table[id].opcode,
1168 (type & LPROCFS_CNTR_AVGMINMAX),
1169 llite_opcode_table[id].opname, ptr);
1171 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats);
1175 sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
1176 LPROCFS_STATS_FLAG_NONE);
1177 if (sbi->ll_ra_stats == NULL)
1178 GOTO(out, err = -ENOMEM);
1180 for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
1181 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
1182 ra_stat_string[id], "pages");
1183 err = lprocfs_register_stats(sbi->ll_proc_root, "read_ahead_stats",
1189 err = lprocfs_seq_add_vars(sbi->ll_proc_root, lprocfs_llite_obd_vars, sb);
1194 obd = class_name2obd(mdc);
1196 LASSERT(obd != NULL);
1197 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1198 LASSERT(obd->obd_type->typ_name != NULL);
1200 dir = proc_mkdir(obd->obd_type->typ_name, sbi->ll_proc_root);
1202 GOTO(out, err = -ENOMEM);
1204 snprintf(name, MAX_STRING_SIZE, "common_name");
1205 lvars[0].fops = &llite_name_fops;
1206 err = lprocfs_seq_add_vars(dir, lvars, obd);
1210 snprintf(name, MAX_STRING_SIZE, "uuid");
1211 lvars[0].fops = &llite_uuid_fops;
1212 err = lprocfs_seq_add_vars(dir, lvars, obd);
1217 obd = class_name2obd(osc);
1219 LASSERT(obd != NULL);
1220 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1221 LASSERT(obd->obd_type->typ_name != NULL);
1223 dir = proc_mkdir(obd->obd_type->typ_name, sbi->ll_proc_root);
1225 GOTO(out, err = -ENOMEM);
1227 snprintf(name, MAX_STRING_SIZE, "common_name");
1228 lvars[0].fops = &llite_name_fops;
1229 err = lprocfs_seq_add_vars(dir, lvars, obd);
1233 snprintf(name, MAX_STRING_SIZE, "uuid");
1234 lvars[0].fops = &llite_uuid_fops;
1235 err = lprocfs_seq_add_vars(dir, lvars, obd);
1238 lprocfs_remove(&sbi->ll_proc_root);
1239 lprocfs_free_stats(&sbi->ll_ra_stats);
1240 lprocfs_free_stats(&sbi->ll_stats);
1245 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
1247 if (sbi->ll_proc_root) {
1248 lprocfs_remove(&sbi->ll_proc_root);
1249 lprocfs_free_stats(&sbi->ll_ra_stats);
1250 lprocfs_free_stats(&sbi->ll_stats);
1253 #undef MAX_STRING_SIZE
1255 #define pct(a,b) (b ? a * 100 / b : 0)
1257 static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
1258 struct seq_file *seq, int which)
1260 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
1261 unsigned long start, end, r, w;
1262 char *unitp = "KMGTPEZY";
1264 struct per_process_info *pp_info = &io_extents->pp_extents[which];
1270 for(i = 0; i < LL_HIST_MAX; i++) {
1271 read_tot += pp_info->pp_r_hist.oh_buckets[i];
1272 write_tot += pp_info->pp_w_hist.oh_buckets[i];
1275 for(i = 0; i < LL_HIST_MAX; i++) {
1276 r = pp_info->pp_r_hist.oh_buckets[i];
1277 w = pp_info->pp_w_hist.oh_buckets[i];
1280 end = 1 << (i + LL_HIST_START - units);
1281 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu | "
1282 "%14lu %4lu %4lu\n", start, *unitp, end, *unitp,
1283 (i == LL_HIST_MAX - 1) ? '+' : ' ',
1284 r, pct(r, read_tot), pct(read_cum, read_tot),
1285 w, pct(w, write_tot), pct(write_cum, write_tot));
1287 if (start == 1<<10) {
1292 if (read_cum == read_tot && write_cum == write_tot)
1297 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
1300 struct ll_sb_info *sbi = seq->private;
1301 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1304 do_gettimeofday(&now);
1306 if (!sbi->ll_rw_stats_on) {
1307 seq_printf(seq, "disabled\n"
1308 "write anything in this file to activate, "
1309 "then 0 or \"[D/d]isabled\" to deactivate\n");
1312 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1313 now.tv_sec, now.tv_usec);
1314 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1315 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1316 "extents", "calls", "%", "cum%",
1317 "calls", "%", "cum%");
1318 spin_lock(&sbi->ll_pp_extent_lock);
1319 for (k = 0; k < LL_PROCESS_HIST_MAX; k++) {
1320 if (io_extents->pp_extents[k].pid != 0) {
1321 seq_printf(seq, "\nPID: %d\n",
1322 io_extents->pp_extents[k].pid);
1323 ll_display_extents_info(io_extents, seq, k);
1326 spin_unlock(&sbi->ll_pp_extent_lock);
1330 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
1331 const char __user *buf,
1335 struct seq_file *seq = file->private_data;
1336 struct ll_sb_info *sbi = seq->private;
1337 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1339 int value = 1, rc = 0;
1344 rc = lprocfs_write_helper(buf, len, &value);
1345 if (rc < 0 && len < 16) {
1348 if (copy_from_user(kernbuf, buf, len))
1352 if (kernbuf[len - 1] == '\n')
1353 kernbuf[len - 1] = 0;
1355 if (strcmp(kernbuf, "disabled") == 0 ||
1356 strcmp(kernbuf, "Disabled") == 0)
1361 sbi->ll_rw_stats_on = 0;
1363 sbi->ll_rw_stats_on = 1;
1365 spin_lock(&sbi->ll_pp_extent_lock);
1366 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1367 io_extents->pp_extents[i].pid = 0;
1368 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1369 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1371 spin_unlock(&sbi->ll_pp_extent_lock);
1375 LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
1377 static int ll_rw_extents_stats_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;
1383 do_gettimeofday(&now);
1385 if (!sbi->ll_rw_stats_on) {
1386 seq_printf(seq, "disabled\n"
1387 "write anything in this file to activate, "
1388 "then 0 or \"[D/d]isabled\" to deactivate\n");
1391 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1392 now.tv_sec, now.tv_usec);
1394 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1395 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1396 "extents", "calls", "%", "cum%",
1397 "calls", "%", "cum%");
1398 spin_lock(&sbi->ll_lock);
1399 ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
1400 spin_unlock(&sbi->ll_lock);
1405 static ssize_t ll_rw_extents_stats_seq_write(struct file *file,
1406 const char __user *buf,
1407 size_t len, loff_t *off)
1409 struct seq_file *seq = file->private_data;
1410 struct ll_sb_info *sbi = seq->private;
1411 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1413 int value = 1, rc = 0;
1418 rc = lprocfs_write_helper(buf, len, &value);
1419 if (rc < 0 && len < 16) {
1422 if (copy_from_user(kernbuf, buf, len))
1426 if (kernbuf[len - 1] == '\n')
1427 kernbuf[len - 1] = 0;
1429 if (strcmp(kernbuf, "disabled") == 0 ||
1430 strcmp(kernbuf, "Disabled") == 0)
1435 sbi->ll_rw_stats_on = 0;
1437 sbi->ll_rw_stats_on = 1;
1439 spin_lock(&sbi->ll_pp_extent_lock);
1440 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
1441 io_extents->pp_extents[i].pid = 0;
1442 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1443 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1445 spin_unlock(&sbi->ll_pp_extent_lock);
1449 LPROC_SEQ_FOPS(ll_rw_extents_stats);
1451 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
1452 struct ll_file_data *file, loff_t pos,
1453 size_t count, int rw)
1456 struct ll_rw_process_info *process;
1457 struct ll_rw_process_info *offset;
1458 int *off_count = &sbi->ll_rw_offset_entry_count;
1459 int *process_count = &sbi->ll_offset_process_count;
1460 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1462 if(!sbi->ll_rw_stats_on)
1464 process = sbi->ll_rw_process_info;
1465 offset = sbi->ll_rw_offset_info;
1467 spin_lock(&sbi->ll_pp_extent_lock);
1468 /* Extent statistics */
1469 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1470 if(io_extents->pp_extents[i].pid == pid) {
1478 sbi->ll_extent_process_count =
1479 (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1480 cur = sbi->ll_extent_process_count;
1481 io_extents->pp_extents[cur].pid = pid;
1482 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1483 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1486 for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
1487 (i < (LL_HIST_MAX - 1)); i++);
1489 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1490 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1492 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1493 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1495 spin_unlock(&sbi->ll_pp_extent_lock);
1497 spin_lock(&sbi->ll_process_lock);
1498 /* Offset statistics */
1499 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1500 if (process[i].rw_pid == pid) {
1501 if (process[i].rw_last_file != file) {
1502 process[i].rw_range_start = pos;
1503 process[i].rw_last_file_pos = pos + count;
1504 process[i].rw_smallest_extent = count;
1505 process[i].rw_largest_extent = count;
1506 process[i].rw_offset = 0;
1507 process[i].rw_last_file = file;
1508 spin_unlock(&sbi->ll_process_lock);
1511 if (process[i].rw_last_file_pos != pos) {
1513 (*off_count + 1) % LL_OFFSET_HIST_MAX;
1514 offset[*off_count].rw_op = process[i].rw_op;
1515 offset[*off_count].rw_pid = pid;
1516 offset[*off_count].rw_range_start =
1517 process[i].rw_range_start;
1518 offset[*off_count].rw_range_end =
1519 process[i].rw_last_file_pos;
1520 offset[*off_count].rw_smallest_extent =
1521 process[i].rw_smallest_extent;
1522 offset[*off_count].rw_largest_extent =
1523 process[i].rw_largest_extent;
1524 offset[*off_count].rw_offset =
1525 process[i].rw_offset;
1526 process[i].rw_op = rw;
1527 process[i].rw_range_start = pos;
1528 process[i].rw_smallest_extent = count;
1529 process[i].rw_largest_extent = count;
1530 process[i].rw_offset = pos -
1531 process[i].rw_last_file_pos;
1533 if(process[i].rw_smallest_extent > count)
1534 process[i].rw_smallest_extent = count;
1535 if(process[i].rw_largest_extent < count)
1536 process[i].rw_largest_extent = count;
1537 process[i].rw_last_file_pos = pos + count;
1538 spin_unlock(&sbi->ll_process_lock);
1542 *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
1543 process[*process_count].rw_pid = pid;
1544 process[*process_count].rw_op = rw;
1545 process[*process_count].rw_range_start = pos;
1546 process[*process_count].rw_last_file_pos = pos + count;
1547 process[*process_count].rw_smallest_extent = count;
1548 process[*process_count].rw_largest_extent = count;
1549 process[*process_count].rw_offset = 0;
1550 process[*process_count].rw_last_file = file;
1551 spin_unlock(&sbi->ll_process_lock);
1554 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1557 struct ll_sb_info *sbi = seq->private;
1558 struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
1559 struct ll_rw_process_info *process = sbi->ll_rw_process_info;
1562 do_gettimeofday(&now);
1564 if (!sbi->ll_rw_stats_on) {
1565 seq_printf(seq, "disabled\n"
1566 "write anything in this file to activate, "
1567 "then 0 or \"[D/d]isabled\" to deactivate\n");
1570 spin_lock(&sbi->ll_process_lock);
1572 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1573 now.tv_sec, now.tv_usec);
1574 seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
1575 "R/W", "PID", "RANGE START", "RANGE END",
1576 "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
1578 /* We stored the discontiguous offsets here; print them first */
1579 for (i = 0; i < LL_OFFSET_HIST_MAX; i++) {
1580 if (offset[i].rw_pid != 0)
1582 "%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1583 offset[i].rw_op == READ ? 'R' : 'W',
1585 offset[i].rw_range_start,
1586 offset[i].rw_range_end,
1587 (unsigned long)offset[i].rw_smallest_extent,
1588 (unsigned long)offset[i].rw_largest_extent,
1589 offset[i].rw_offset);
1592 /* Then print the current offsets for each process */
1593 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1594 if (process[i].rw_pid != 0)
1596 "%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1597 process[i].rw_op == READ ? 'R' : 'W',
1599 process[i].rw_range_start,
1600 process[i].rw_last_file_pos,
1601 (unsigned long)process[i].rw_smallest_extent,
1602 (unsigned long)process[i].rw_largest_extent,
1603 process[i].rw_offset);
1605 spin_unlock(&sbi->ll_process_lock);
1610 static ssize_t ll_rw_offset_stats_seq_write(struct file *file,
1611 const char __user *buf,
1612 size_t len, loff_t *off)
1614 struct seq_file *seq = file->private_data;
1615 struct ll_sb_info *sbi = seq->private;
1616 struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
1617 struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
1618 int value = 1, rc = 0;
1623 rc = lprocfs_write_helper(buf, len, &value);
1625 if (rc < 0 && len < 16) {
1628 if (copy_from_user(kernbuf, buf, len))
1632 if (kernbuf[len - 1] == '\n')
1633 kernbuf[len - 1] = 0;
1635 if (strcmp(kernbuf, "disabled") == 0 ||
1636 strcmp(kernbuf, "Disabled") == 0)
1641 sbi->ll_rw_stats_on = 0;
1643 sbi->ll_rw_stats_on = 1;
1645 spin_lock(&sbi->ll_process_lock);
1646 sbi->ll_offset_process_count = 0;
1647 sbi->ll_rw_offset_entry_count = 0;
1648 memset(process_info, 0, sizeof(struct ll_rw_process_info) *
1649 LL_PROCESS_HIST_MAX);
1650 memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
1651 LL_OFFSET_HIST_MAX);
1652 spin_unlock(&sbi->ll_process_lock);
1657 LPROC_SEQ_FOPS(ll_rw_offset_stats);
1658 #endif /* LPROCFS */