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"
46 struct proc_dir_entry *proc_lustre_fs_root;
49 /* /proc/lustre/llite mount point registration */
50 extern struct file_operations vvp_dump_pgcache_file_ops;
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 = cfs_atomic_read(&cache->ccc_lru_left) >> shift;
391 "max_cached_mb: %d\n"
394 "reclaim_count: %u\n",
395 cfs_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 *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;
417 mult = 1 << (20 - PAGE_CACHE_SHIFT);
418 buffer = lprocfs_find_named_value(buffer, "max_cached_mb:", &count);
419 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
423 if (pages_number < 0 || pages_number > totalram_pages) {
424 CERROR("%s: can't set max cache more than %lu MB\n",
425 ll_get_fsname(sb, NULL, 0),
426 totalram_pages >> (20 - PAGE_CACHE_SHIFT));
430 if (sbi->ll_dt_exp == NULL) /* being initialized */
433 spin_lock(&sbi->ll_lock);
434 diff = pages_number - cache->ccc_lru_max;
435 spin_unlock(&sbi->ll_lock);
437 /* easy - add more LRU slots. */
439 cfs_atomic_add(diff, &cache->ccc_lru_left);
443 env = cl_env_get(&refcheck);
451 /* reduce LRU budget from free slots. */
455 ov = cfs_atomic_read(&cache->ccc_lru_left);
459 nv = ov > diff ? ov - diff : 0;
460 rc = cfs_atomic_cmpxchg(&cache->ccc_lru_left, ov, nv);
461 if (likely(ov == rc)) {
471 /* difficult - have to ask OSCs to drop LRU slots. */
473 rc = obd_set_info_async(env, sbi->ll_dt_exp,
474 sizeof(KEY_CACHE_LRU_SHRINK),
475 KEY_CACHE_LRU_SHRINK,
476 sizeof(tmp), &tmp, NULL);
480 cl_env_put(env, &refcheck);
484 spin_lock(&sbi->ll_lock);
485 cache->ccc_lru_max = pages_number;
486 spin_unlock(&sbi->ll_lock);
489 cfs_atomic_add(nrpages, &cache->ccc_lru_left);
493 LPROC_SEQ_FOPS(ll_max_cached_mb);
495 static int ll_checksum_seq_show(struct seq_file *m, void *v)
497 struct super_block *sb = m->private;
498 struct ll_sb_info *sbi = ll_s2sbi(sb);
500 return seq_printf(m, "%u\n", (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0);
503 static ssize_t ll_checksum_seq_write(struct file *file, const char *buffer,
504 size_t count, loff_t *off)
506 struct seq_file *m = file->private_data;
507 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
514 rc = lprocfs_write_helper(buffer, count, &val);
518 sbi->ll_flags |= LL_SBI_CHECKSUM;
520 sbi->ll_flags &= ~LL_SBI_CHECKSUM;
522 rc = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
523 KEY_CHECKSUM, sizeof(val), &val, NULL);
525 CWARN("Failed to set OSC checksum flags: %d\n", rc);
529 LPROC_SEQ_FOPS(ll_checksum);
531 static int ll_max_rw_chunk_seq_show(struct seq_file *m, void *v)
533 struct super_block *sb = m->private;
535 return seq_printf(m, "%lu\n", ll_s2sbi(sb)->ll_max_rw_chunk);
538 static ssize_t ll_max_rw_chunk_seq_write(struct file *file, const char *buffer,
539 size_t count, loff_t *off)
541 struct seq_file *m = file->private_data;
542 struct super_block *sb = m->private;
545 rc = lprocfs_write_helper(buffer, count, &val);
548 ll_s2sbi(sb)->ll_max_rw_chunk = val;
551 LPROC_SEQ_FOPS(ll_max_rw_chunk);
553 static int ll_rd_track_id(struct seq_file *m, enum stats_track_type type)
555 struct super_block *sb = m->private;
557 if (ll_s2sbi(sb)->ll_stats_track_type == type) {
558 return seq_printf(m, "%d\n",
559 ll_s2sbi(sb)->ll_stats_track_id);
560 } else if (ll_s2sbi(sb)->ll_stats_track_type == STATS_TRACK_ALL) {
561 return seq_printf(m, "0 (all)\n");
563 return seq_printf(m, "untracked\n");
567 static int ll_wr_track_id(const char *buffer, unsigned long count, void *data,
568 enum stats_track_type type)
570 struct super_block *sb = data;
573 rc = lprocfs_write_helper(buffer, count, &pid);
576 ll_s2sbi(sb)->ll_stats_track_id = pid;
578 ll_s2sbi(sb)->ll_stats_track_type = STATS_TRACK_ALL;
580 ll_s2sbi(sb)->ll_stats_track_type = type;
581 lprocfs_clear_stats(ll_s2sbi(sb)->ll_stats);
585 static int ll_track_pid_seq_show(struct seq_file *m, void *v)
587 return ll_rd_track_id(m, STATS_TRACK_PID);
590 static ssize_t ll_track_pid_seq_write(struct file *file, const char *buffer,
591 size_t count, loff_t *off)
593 struct seq_file *seq = file->private_data;
594 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PID);
596 LPROC_SEQ_FOPS(ll_track_pid);
598 static int ll_track_ppid_seq_show(struct seq_file *m, void *v)
600 return ll_rd_track_id(m, STATS_TRACK_PPID);
603 static ssize_t ll_track_ppid_seq_write(struct file *file, const char *buffer,
604 size_t count, loff_t *off)
606 struct seq_file *seq = file->private_data;
607 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PPID);
609 LPROC_SEQ_FOPS(ll_track_ppid);
611 static int ll_track_gid_seq_show(struct seq_file *m, void *v)
613 return ll_rd_track_id(m, STATS_TRACK_GID);
616 static ssize_t ll_track_gid_seq_write(struct file *file, const char *buffer,
617 size_t count, loff_t *off)
619 struct seq_file *seq = file->private_data;
620 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_GID);
622 LPROC_SEQ_FOPS(ll_track_gid);
624 static int ll_statahead_max_seq_show(struct seq_file *m, void *v)
626 struct super_block *sb = m->private;
627 struct ll_sb_info *sbi = ll_s2sbi(sb);
629 return seq_printf(m, "%u\n", sbi->ll_sa_max);
632 static ssize_t ll_statahead_max_seq_write(struct file *file, const char *buffer,
633 size_t count, loff_t *off)
635 struct seq_file *m = file->private_data;
636 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
639 rc = lprocfs_write_helper(buffer, count, &val);
643 if (val >= 0 && val <= LL_SA_RPC_MAX)
644 sbi->ll_sa_max = val;
646 CERROR("Bad statahead_max value %d. Valid values are in the "
647 "range [0, %d]\n", val, LL_SA_RPC_MAX);
651 LPROC_SEQ_FOPS(ll_statahead_max);
653 static int ll_statahead_agl_seq_show(struct seq_file *m, void *v)
655 struct super_block *sb = m->private;
656 struct ll_sb_info *sbi = ll_s2sbi(sb);
658 return seq_printf(m, "%u\n",
659 sbi->ll_flags & LL_SBI_AGL_ENABLED ? 1 : 0);
662 static ssize_t ll_statahead_agl_seq_write(struct file *file, const char *buffer,
663 size_t count, loff_t *off)
665 struct seq_file *m = file->private_data;
666 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
669 rc = lprocfs_write_helper(buffer, count, &val);
674 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
676 sbi->ll_flags &= ~LL_SBI_AGL_ENABLED;
680 LPROC_SEQ_FOPS(ll_statahead_agl);
682 static int ll_statahead_stats_seq_show(struct seq_file *m, void *v)
684 struct super_block *sb = m->private;
685 struct ll_sb_info *sbi = ll_s2sbi(sb);
688 "statahead total: %u\n"
689 "statahead wrong: %u\n"
691 atomic_read(&sbi->ll_sa_total),
692 atomic_read(&sbi->ll_sa_wrong),
693 atomic_read(&sbi->ll_agl_total));
695 LPROC_SEQ_FOPS_RO(ll_statahead_stats);
697 static int ll_lazystatfs_seq_show(struct seq_file *m, void *v)
699 struct super_block *sb = m->private;
700 struct ll_sb_info *sbi = ll_s2sbi(sb);
702 return seq_printf(m, "%u\n",
703 (sbi->ll_flags & LL_SBI_LAZYSTATFS) ? 1 : 0);
706 static ssize_t ll_lazystatfs_seq_write(struct file *file, const char *buffer,
707 size_t count, loff_t *off)
709 struct seq_file *m = file->private_data;
710 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
713 rc = lprocfs_write_helper(buffer, count, &val);
718 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
720 sbi->ll_flags &= ~LL_SBI_LAZYSTATFS;
724 LPROC_SEQ_FOPS(ll_lazystatfs);
726 static int ll_max_easize_seq_show(struct seq_file *m, void *v)
728 struct super_block *sb = m->private;
729 struct ll_sb_info *sbi = ll_s2sbi(sb);
733 rc = ll_get_max_mdsize(sbi, &ealen);
737 return seq_printf(m, "%u\n", ealen);
739 LPROC_SEQ_FOPS_RO(ll_max_easize);
741 static int ll_defult_easize_seq_show(struct seq_file *m, void *v)
743 struct super_block *sb = m->private;
744 struct ll_sb_info *sbi = ll_s2sbi(sb);
748 rc = ll_get_default_mdsize(sbi, &ealen);
752 return seq_printf(m, "%u\n", ealen);
754 LPROC_SEQ_FOPS_RO(ll_defult_easize);
756 static int ll_max_cookiesize_seq_show(struct seq_file *m, void *v)
758 struct super_block *sb = m->private;
759 struct ll_sb_info *sbi = ll_s2sbi(sb);
760 unsigned int cookielen;
763 rc = ll_get_max_cookiesize(sbi, &cookielen);
767 return seq_printf(m, "%u\n", cookielen);
769 LPROC_SEQ_FOPS_RO(ll_max_cookiesize);
771 static int ll_defult_cookiesize_seq_show(struct seq_file *m, void *v)
773 struct super_block *sb = m->private;
774 struct ll_sb_info *sbi = ll_s2sbi(sb);
775 unsigned int cookielen;
778 rc = ll_get_default_cookiesize(sbi, &cookielen);
782 return seq_printf(m, "%u\n", cookielen);
784 LPROC_SEQ_FOPS_RO(ll_defult_cookiesize);
786 static int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
788 const char *str[] = LL_SBI_FLAGS;
789 struct super_block *sb = m->private;
790 int flags = ll_s2sbi(sb)->ll_flags;
794 if (ARRAY_SIZE(str) <= i) {
795 CERROR("%s: Revise array LL_SBI_FLAGS to match sbi "
796 "flags please.\n", ll_get_fsname(sb, NULL, 0));
801 seq_printf(m, "%s ", str[i]);
805 seq_printf(m, "\b\n");
808 LPROC_SEQ_FOPS_RO(ll_sbi_flags);
810 static int ll_unstable_stats_seq_show(struct seq_file *m, void *v)
812 struct super_block *sb = m->private;
813 struct ll_sb_info *sbi = ll_s2sbi(sb);
814 struct cl_client_cache *cache = &sbi->ll_cache;
817 pages = cfs_atomic_read(&cache->ccc_unstable_nr);
818 mb = (pages * PAGE_CACHE_SIZE) >> 20;
820 return seq_printf(m, "unstable_pages: %8d\n"
821 "unstable_mb: %8d\n", pages, mb);
823 LPROC_SEQ_FOPS_RO(ll_unstable_stats);
825 struct lprocfs_seq_vars lprocfs_llite_obd_vars[] = {
827 .fops = &ll_sb_uuid_fops },
829 .fops = &ll_fstype_fops },
831 .fops = &ll_site_stats_fops },
832 { .name = "blocksize",
833 .fops = &ll_blksize_fops },
834 { .name = "kbytestotal",
835 .fops = &ll_kbytestotal_fops },
836 { .name = "kbytesfree",
837 .fops = &ll_kbytesfree_fops },
838 { .name = "kbytesavail",
839 .fops = &ll_kbytesavail_fops },
840 { .name = "filestotal",
841 .fops = &ll_filestotal_fops },
842 { .name = "filesfree",
843 .fops = &ll_filesfree_fops },
844 { .name = "client_type",
845 .fops = &ll_client_type_fops },
846 { .name = "max_read_ahead_mb",
847 .fops = &ll_max_readahead_mb_fops },
848 { .name = "max_read_ahead_per_file_mb",
849 .fops = &ll_max_readahead_per_file_mb_fops },
850 { .name = "max_read_ahead_whole_mb",
851 .fops = &ll_max_read_ahead_whole_mb_fops },
852 { .name = "max_cached_mb",
853 .fops = &ll_max_cached_mb_fops },
854 { .name = "checksum_pages",
855 .fops = &ll_checksum_fops },
856 { .name = "max_rw_chunk",
857 .fops = &ll_max_rw_chunk_fops },
858 { .name = "stats_track_pid",
859 .fops = &ll_track_pid_fops },
860 { .name = "stats_track_ppid",
861 .fops = &ll_track_ppid_fops },
862 { .name = "stats_track_gid",
863 .fops = &ll_track_gid_fops },
864 { .name = "statahead_max",
865 .fops = &ll_statahead_max_fops },
866 { .name = "statahead_agl",
867 .fops = &ll_statahead_agl_fops },
868 { .name = "statahead_stats",
869 .fops = &ll_statahead_stats_fops },
870 { .name = "lazystatfs",
871 .fops = &ll_lazystatfs_fops },
872 { .name = "max_easize",
873 .fops = &ll_max_easize_fops },
874 { .name = "default_easize",
875 .fops = &ll_defult_easize_fops },
876 { .name = "max_cookiesize",
877 .fops = &ll_max_cookiesize_fops },
878 { .name = "default_cookiesize",
879 .fops = &ll_defult_cookiesize_fops },
880 { .name = "sbi_flags",
881 .fops = &ll_sbi_flags_fops },
882 { .name = "xattr_cache",
883 .fops = &ll_xattr_cache_fops },
884 { .name = "unstable_stats",
885 .fops = &ll_unstable_stats_fops },
889 #define MAX_STRING_SIZE 128
891 struct llite_file_opcode {
895 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
897 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
898 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
899 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
901 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
903 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
905 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
907 { LPROC_LL_OSC_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
909 { LPROC_LL_OSC_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
911 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
912 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
913 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
914 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
915 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
916 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
917 { LPROC_LL_READDIR, LPROCFS_TYPE_REGS, "readdir" },
918 /* inode operation */
919 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
920 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "truncate" },
921 { LPROC_LL_FLOCK, LPROCFS_TYPE_REGS, "flock" },
922 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
923 /* dir inode operation */
924 { LPROC_LL_CREATE, LPROCFS_TYPE_REGS, "create" },
925 { LPROC_LL_LINK, LPROCFS_TYPE_REGS, "link" },
926 { LPROC_LL_UNLINK, LPROCFS_TYPE_REGS, "unlink" },
927 { LPROC_LL_SYMLINK, LPROCFS_TYPE_REGS, "symlink" },
928 { LPROC_LL_MKDIR, LPROCFS_TYPE_REGS, "mkdir" },
929 { LPROC_LL_RMDIR, LPROCFS_TYPE_REGS, "rmdir" },
930 { LPROC_LL_MKNOD, LPROCFS_TYPE_REGS, "mknod" },
931 { LPROC_LL_RENAME, LPROCFS_TYPE_REGS, "rename" },
932 /* special inode operation */
933 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
934 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
935 { LPROC_LL_SETXATTR, LPROCFS_TYPE_REGS, "setxattr" },
936 { LPROC_LL_GETXATTR, LPROCFS_TYPE_REGS, "getxattr" },
937 { LPROC_LL_GETXATTR_HITS, LPROCFS_TYPE_REGS, "getxattr_hits" },
938 { LPROC_LL_LISTXATTR, LPROCFS_TYPE_REGS, "listxattr" },
939 { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_REGS, "removexattr" },
940 { LPROC_LL_INODE_PERM, LPROCFS_TYPE_REGS, "inode_permission" },
943 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
947 if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
948 lprocfs_counter_add(sbi->ll_stats, op, count);
949 else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
950 sbi->ll_stats_track_id == current->pid)
951 lprocfs_counter_add(sbi->ll_stats, op, count);
952 else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
953 sbi->ll_stats_track_id == current->parent->pid)
954 lprocfs_counter_add(sbi->ll_stats, op, count);
955 else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
956 sbi->ll_stats_track_id ==
957 from_kgid(&init_user_ns, current_gid()))
958 lprocfs_counter_add(sbi->ll_stats, op, count);
960 EXPORT_SYMBOL(ll_stats_ops_tally);
962 static const char *ra_stat_string[] = {
963 [RA_STAT_HIT] = "hits",
964 [RA_STAT_MISS] = "misses",
965 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
966 [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
967 [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page",
968 [RA_STAT_FAILED_MATCH] = "failed lock match",
969 [RA_STAT_DISCARDED] = "read but discarded",
970 [RA_STAT_ZERO_LEN] = "zero length file",
971 [RA_STAT_ZERO_WINDOW] = "zero size window",
972 [RA_STAT_EOF] = "read-ahead to EOF",
973 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
974 [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",
975 [RA_STAT_FAILED_REACH_END] = "failed to reach end"
978 LPROC_SEQ_FOPS_RO_TYPE(llite, name);
979 LPROC_SEQ_FOPS_RO_TYPE(llite, uuid);
981 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
982 struct super_block *sb, char *osc, char *mdc)
984 struct lprocfs_seq_vars lvars[2];
985 struct lustre_sb_info *lsi = s2lsi(sb);
986 struct ll_sb_info *sbi = ll_s2sbi(sb);
987 struct obd_device *obd;
988 struct proc_dir_entry *dir;
989 char name[MAX_STRING_SIZE + 1], *ptr;
990 int err, id, len, rc;
993 memset(lvars, 0, sizeof(lvars));
995 name[MAX_STRING_SIZE] = '\0';
996 lvars[0].name = name;
998 LASSERT(sbi != NULL);
999 LASSERT(mdc != NULL);
1000 LASSERT(osc != NULL);
1003 len = strlen(lsi->lsi_lmd->lmd_profile);
1004 ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
1005 if (ptr && (strcmp(ptr, "-client") == 0))
1009 snprintf(name, MAX_STRING_SIZE, "%.*s-%p", len,
1010 lsi->lsi_lmd->lmd_profile, sb);
1012 sbi->ll_proc_root = lprocfs_seq_register(name, parent, NULL, NULL);
1013 if (IS_ERR(sbi->ll_proc_root)) {
1014 err = PTR_ERR(sbi->ll_proc_root);
1015 sbi->ll_proc_root = NULL;
1019 rc = lprocfs_seq_create(sbi->ll_proc_root, "dump_page_cache", 0444,
1020 &vvp_dump_pgcache_file_ops, sbi);
1022 CWARN("Error adding the dump_page_cache file\n");
1024 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats", 0644,
1025 &ll_rw_extents_stats_fops, sbi);
1027 CWARN("Error adding the extent_stats file\n");
1029 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats_per_process",
1030 0644, &ll_rw_extents_stats_pp_fops, sbi);
1032 CWARN("Error adding the extents_stats_per_process file\n");
1034 rc = lprocfs_seq_create(sbi->ll_proc_root, "offset_stats", 0644,
1035 &ll_rw_offset_stats_fops, sbi);
1037 CWARN("Error adding the offset_stats file\n");
1039 /* File operations stats */
1040 sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
1041 LPROCFS_STATS_FLAG_NONE);
1042 if (sbi->ll_stats == NULL)
1043 GOTO(out, err = -ENOMEM);
1044 /* do counter init */
1045 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
1046 __u32 type = llite_opcode_table[id].type;
1048 if (type & LPROCFS_TYPE_REGS)
1050 else if (type & LPROCFS_TYPE_BYTES)
1052 else if (type & LPROCFS_TYPE_PAGES)
1054 lprocfs_counter_init(sbi->ll_stats,
1055 llite_opcode_table[id].opcode,
1056 (type & LPROCFS_CNTR_AVGMINMAX),
1057 llite_opcode_table[id].opname, ptr);
1059 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats);
1063 sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
1064 LPROCFS_STATS_FLAG_NONE);
1065 if (sbi->ll_ra_stats == NULL)
1066 GOTO(out, err = -ENOMEM);
1068 for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
1069 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
1070 ra_stat_string[id], "pages");
1071 err = lprocfs_register_stats(sbi->ll_proc_root, "read_ahead_stats",
1077 err = lprocfs_seq_add_vars(sbi->ll_proc_root, lprocfs_llite_obd_vars, sb);
1082 obd = class_name2obd(mdc);
1084 LASSERT(obd != NULL);
1085 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1086 LASSERT(obd->obd_type->typ_name != NULL);
1088 dir = proc_mkdir(obd->obd_type->typ_name, sbi->ll_proc_root);
1090 GOTO(out, err = -ENOMEM);
1092 snprintf(name, MAX_STRING_SIZE, "common_name");
1093 lvars[0].fops = &llite_name_fops;
1094 err = lprocfs_seq_add_vars(dir, lvars, obd);
1098 snprintf(name, MAX_STRING_SIZE, "uuid");
1099 lvars[0].fops = &llite_uuid_fops;
1100 err = lprocfs_seq_add_vars(dir, lvars, obd);
1105 obd = class_name2obd(osc);
1107 LASSERT(obd != NULL);
1108 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1109 LASSERT(obd->obd_type->typ_name != NULL);
1111 dir = proc_mkdir(obd->obd_type->typ_name, sbi->ll_proc_root);
1113 GOTO(out, err = -ENOMEM);
1115 snprintf(name, MAX_STRING_SIZE, "common_name");
1116 lvars[0].fops = &llite_name_fops;
1117 err = lprocfs_seq_add_vars(dir, lvars, obd);
1121 snprintf(name, MAX_STRING_SIZE, "uuid");
1122 lvars[0].fops = &llite_uuid_fops;
1123 err = lprocfs_seq_add_vars(dir, lvars, obd);
1126 lprocfs_remove(&sbi->ll_proc_root);
1127 lprocfs_free_stats(&sbi->ll_ra_stats);
1128 lprocfs_free_stats(&sbi->ll_stats);
1133 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
1135 if (sbi->ll_proc_root) {
1136 lprocfs_remove(&sbi->ll_proc_root);
1137 lprocfs_free_stats(&sbi->ll_ra_stats);
1138 lprocfs_free_stats(&sbi->ll_stats);
1141 #undef MAX_STRING_SIZE
1143 #define pct(a,b) (b ? a * 100 / b : 0)
1145 static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
1146 struct seq_file *seq, int which)
1148 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
1149 unsigned long start, end, r, w;
1150 char *unitp = "KMGTPEZY";
1152 struct per_process_info *pp_info = &io_extents->pp_extents[which];
1158 for(i = 0; i < LL_HIST_MAX; i++) {
1159 read_tot += pp_info->pp_r_hist.oh_buckets[i];
1160 write_tot += pp_info->pp_w_hist.oh_buckets[i];
1163 for(i = 0; i < LL_HIST_MAX; i++) {
1164 r = pp_info->pp_r_hist.oh_buckets[i];
1165 w = pp_info->pp_w_hist.oh_buckets[i];
1168 end = 1 << (i + LL_HIST_START - units);
1169 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu | "
1170 "%14lu %4lu %4lu\n", start, *unitp, end, *unitp,
1171 (i == LL_HIST_MAX - 1) ? '+' : ' ',
1172 r, pct(r, read_tot), pct(read_cum, read_tot),
1173 w, pct(w, write_tot), pct(write_cum, write_tot));
1175 if (start == 1<<10) {
1180 if (read_cum == read_tot && write_cum == write_tot)
1185 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
1188 struct ll_sb_info *sbi = seq->private;
1189 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1192 do_gettimeofday(&now);
1194 if (!sbi->ll_rw_stats_on) {
1195 seq_printf(seq, "disabled\n"
1196 "write anything in this file to activate, "
1197 "then 0 or \"[D/d]isabled\" to deactivate\n");
1200 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1201 now.tv_sec, now.tv_usec);
1202 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1203 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1204 "extents", "calls", "%", "cum%",
1205 "calls", "%", "cum%");
1206 spin_lock(&sbi->ll_pp_extent_lock);
1207 for (k = 0; k < LL_PROCESS_HIST_MAX; k++) {
1208 if (io_extents->pp_extents[k].pid != 0) {
1209 seq_printf(seq, "\nPID: %d\n",
1210 io_extents->pp_extents[k].pid);
1211 ll_display_extents_info(io_extents, seq, k);
1214 spin_unlock(&sbi->ll_pp_extent_lock);
1218 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
1219 const char *buf, size_t len,
1222 struct seq_file *seq = file->private_data;
1223 struct ll_sb_info *sbi = seq->private;
1224 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1226 int value = 1, rc = 0;
1228 rc = lprocfs_write_helper(buf, len, &value);
1229 if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
1230 strcmp(buf, "Disabled") == 0))
1234 sbi->ll_rw_stats_on = 0;
1236 sbi->ll_rw_stats_on = 1;
1238 spin_lock(&sbi->ll_pp_extent_lock);
1239 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1240 io_extents->pp_extents[i].pid = 0;
1241 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1242 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1244 spin_unlock(&sbi->ll_pp_extent_lock);
1248 LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
1250 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
1253 struct ll_sb_info *sbi = seq->private;
1254 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1256 do_gettimeofday(&now);
1258 if (!sbi->ll_rw_stats_on) {
1259 seq_printf(seq, "disabled\n"
1260 "write anything in this file to activate, "
1261 "then 0 or \"[D/d]isabled\" to deactivate\n");
1264 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1265 now.tv_sec, now.tv_usec);
1267 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1268 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1269 "extents", "calls", "%", "cum%",
1270 "calls", "%", "cum%");
1271 spin_lock(&sbi->ll_lock);
1272 ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
1273 spin_unlock(&sbi->ll_lock);
1278 static ssize_t ll_rw_extents_stats_seq_write(struct file *file, const char *buf,
1279 size_t len, loff_t *off)
1281 struct seq_file *seq = file->private_data;
1282 struct ll_sb_info *sbi = seq->private;
1283 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1285 int value = 1, rc = 0;
1287 rc = lprocfs_write_helper(buf, len, &value);
1288 if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
1289 strcmp(buf, "Disabled") == 0))
1293 sbi->ll_rw_stats_on = 0;
1295 sbi->ll_rw_stats_on = 1;
1296 spin_lock(&sbi->ll_pp_extent_lock);
1297 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
1298 io_extents->pp_extents[i].pid = 0;
1299 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1300 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1302 spin_unlock(&sbi->ll_pp_extent_lock);
1307 LPROC_SEQ_FOPS(ll_rw_extents_stats);
1309 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
1310 struct ll_file_data *file, loff_t pos,
1311 size_t count, int rw)
1314 struct ll_rw_process_info *process;
1315 struct ll_rw_process_info *offset;
1316 int *off_count = &sbi->ll_rw_offset_entry_count;
1317 int *process_count = &sbi->ll_offset_process_count;
1318 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1320 if(!sbi->ll_rw_stats_on)
1322 process = sbi->ll_rw_process_info;
1323 offset = sbi->ll_rw_offset_info;
1325 spin_lock(&sbi->ll_pp_extent_lock);
1326 /* Extent statistics */
1327 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1328 if(io_extents->pp_extents[i].pid == pid) {
1336 sbi->ll_extent_process_count =
1337 (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1338 cur = sbi->ll_extent_process_count;
1339 io_extents->pp_extents[cur].pid = pid;
1340 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1341 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1344 for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
1345 (i < (LL_HIST_MAX - 1)); i++);
1347 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1348 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1350 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1351 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1353 spin_unlock(&sbi->ll_pp_extent_lock);
1355 spin_lock(&sbi->ll_process_lock);
1356 /* Offset statistics */
1357 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1358 if (process[i].rw_pid == pid) {
1359 if (process[i].rw_last_file != file) {
1360 process[i].rw_range_start = pos;
1361 process[i].rw_last_file_pos = pos + count;
1362 process[i].rw_smallest_extent = count;
1363 process[i].rw_largest_extent = count;
1364 process[i].rw_offset = 0;
1365 process[i].rw_last_file = file;
1366 spin_unlock(&sbi->ll_process_lock);
1369 if (process[i].rw_last_file_pos != pos) {
1371 (*off_count + 1) % LL_OFFSET_HIST_MAX;
1372 offset[*off_count].rw_op = process[i].rw_op;
1373 offset[*off_count].rw_pid = pid;
1374 offset[*off_count].rw_range_start =
1375 process[i].rw_range_start;
1376 offset[*off_count].rw_range_end =
1377 process[i].rw_last_file_pos;
1378 offset[*off_count].rw_smallest_extent =
1379 process[i].rw_smallest_extent;
1380 offset[*off_count].rw_largest_extent =
1381 process[i].rw_largest_extent;
1382 offset[*off_count].rw_offset =
1383 process[i].rw_offset;
1384 process[i].rw_op = rw;
1385 process[i].rw_range_start = pos;
1386 process[i].rw_smallest_extent = count;
1387 process[i].rw_largest_extent = count;
1388 process[i].rw_offset = pos -
1389 process[i].rw_last_file_pos;
1391 if(process[i].rw_smallest_extent > count)
1392 process[i].rw_smallest_extent = count;
1393 if(process[i].rw_largest_extent < count)
1394 process[i].rw_largest_extent = count;
1395 process[i].rw_last_file_pos = pos + count;
1396 spin_unlock(&sbi->ll_process_lock);
1400 *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
1401 process[*process_count].rw_pid = pid;
1402 process[*process_count].rw_op = rw;
1403 process[*process_count].rw_range_start = pos;
1404 process[*process_count].rw_last_file_pos = pos + count;
1405 process[*process_count].rw_smallest_extent = count;
1406 process[*process_count].rw_largest_extent = count;
1407 process[*process_count].rw_offset = 0;
1408 process[*process_count].rw_last_file = file;
1409 spin_unlock(&sbi->ll_process_lock);
1412 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1415 struct ll_sb_info *sbi = seq->private;
1416 struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
1417 struct ll_rw_process_info *process = sbi->ll_rw_process_info;
1420 do_gettimeofday(&now);
1422 if (!sbi->ll_rw_stats_on) {
1423 seq_printf(seq, "disabled\n"
1424 "write anything in this file to activate, "
1425 "then 0 or \"[D/d]isabled\" to deactivate\n");
1428 spin_lock(&sbi->ll_process_lock);
1430 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1431 now.tv_sec, now.tv_usec);
1432 seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
1433 "R/W", "PID", "RANGE START", "RANGE END",
1434 "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
1436 /* We stored the discontiguous offsets here; print them first */
1437 for (i = 0; i < LL_OFFSET_HIST_MAX; i++) {
1438 if (offset[i].rw_pid != 0)
1440 "%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1441 offset[i].rw_op == READ ? 'R' : 'W',
1443 offset[i].rw_range_start,
1444 offset[i].rw_range_end,
1445 (unsigned long)offset[i].rw_smallest_extent,
1446 (unsigned long)offset[i].rw_largest_extent,
1447 offset[i].rw_offset);
1450 /* Then print the current offsets for each process */
1451 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1452 if (process[i].rw_pid != 0)
1454 "%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1455 process[i].rw_op == READ ? 'R' : 'W',
1457 process[i].rw_range_start,
1458 process[i].rw_last_file_pos,
1459 (unsigned long)process[i].rw_smallest_extent,
1460 (unsigned long)process[i].rw_largest_extent,
1461 process[i].rw_offset);
1463 spin_unlock(&sbi->ll_process_lock);
1468 static ssize_t ll_rw_offset_stats_seq_write(struct file *file, const char *buf,
1469 size_t len, loff_t *off)
1471 struct seq_file *seq = file->private_data;
1472 struct ll_sb_info *sbi = seq->private;
1473 struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
1474 struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
1475 int value = 1, rc = 0;
1477 rc = lprocfs_write_helper(buf, len, &value);
1479 if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
1480 strcmp(buf, "Disabled") == 0))
1484 sbi->ll_rw_stats_on = 0;
1486 sbi->ll_rw_stats_on = 1;
1488 spin_lock(&sbi->ll_process_lock);
1489 sbi->ll_offset_process_count = 0;
1490 sbi->ll_rw_offset_entry_count = 0;
1491 memset(process_info, 0, sizeof(struct ll_rw_process_info) *
1492 LL_PROCESS_HIST_MAX);
1493 memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
1494 LL_OFFSET_HIST_MAX);
1495 spin_unlock(&sbi->ll_process_lock);
1500 LPROC_SEQ_FOPS(ll_rw_offset_stats);
1501 #endif /* LPROCFS */