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) 2011, 2012, 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 <lustre_lite.h>
39 #include <lprocfs_status.h>
40 #include <linux/seq_file.h>
41 #include <obd_support.h>
43 #include "llite_internal.h"
44 #include "vvp_internal.h"
46 /* /proc/lustre/llite mount point registration */
47 static struct file_operations ll_rw_extents_stats_fops;
48 static struct file_operations ll_rw_extents_stats_pp_fops;
49 static struct file_operations ll_rw_offset_stats_fops;
51 static int ll_blksize_seq_show(struct seq_file *m, void *v)
53 struct super_block *sb = (struct super_block *)m->private;
54 struct obd_statfs osfs;
58 rc = ll_statfs_internal(sb, &osfs,
59 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
62 rc = seq_printf(m, "%u\n", osfs.os_bsize);
66 LPROC_SEQ_FOPS_RO(ll_blksize);
68 static int ll_kbytestotal_seq_show(struct seq_file *m, void *v)
70 struct super_block *sb = (struct super_block *)m->private;
71 struct obd_statfs osfs;
75 rc = ll_statfs_internal(sb, &osfs,
76 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
79 __u32 blk_size = osfs.os_bsize >> 10;
80 __u64 result = osfs.os_blocks;
82 while (blk_size >>= 1)
85 rc = seq_printf(m, LPU64"\n", result);
89 LPROC_SEQ_FOPS_RO(ll_kbytestotal);
91 static int ll_kbytesfree_seq_show(struct seq_file *m, void *v)
93 struct super_block *sb = (struct super_block *)m->private;
94 struct obd_statfs osfs;
98 rc = ll_statfs_internal(sb, &osfs,
99 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
102 __u32 blk_size = osfs.os_bsize >> 10;
103 __u64 result = osfs.os_bfree;
105 while (blk_size >>= 1)
108 rc = seq_printf(m, LPU64"\n", result);
112 LPROC_SEQ_FOPS_RO(ll_kbytesfree);
114 static int ll_kbytesavail_seq_show(struct seq_file *m, void *v)
116 struct super_block *sb = (struct super_block *)m->private;
117 struct obd_statfs osfs;
121 rc = ll_statfs_internal(sb, &osfs,
122 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
125 __u32 blk_size = osfs.os_bsize >> 10;
126 __u64 result = osfs.os_bavail;
128 while (blk_size >>= 1)
131 rc = seq_printf(m, LPU64"\n", result);
135 LPROC_SEQ_FOPS_RO(ll_kbytesavail);
137 static int ll_filestotal_seq_show(struct seq_file *m, void *v)
139 struct super_block *sb = (struct super_block *)m->private;
140 struct obd_statfs osfs;
144 rc = ll_statfs_internal(sb, &osfs,
145 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
148 rc = seq_printf(m, LPU64"\n", osfs.os_files);
151 LPROC_SEQ_FOPS_RO(ll_filestotal);
153 static int ll_filesfree_seq_show(struct seq_file *m, void *v)
155 struct super_block *sb = (struct super_block *)m->private;
156 struct obd_statfs osfs;
160 rc = ll_statfs_internal(sb, &osfs,
161 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
164 rc = seq_printf(m, LPU64"\n", osfs.os_ffree);
167 LPROC_SEQ_FOPS_RO(ll_filesfree);
169 static int ll_client_type_seq_show(struct seq_file *m, void *v)
171 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
174 LASSERT(sbi != NULL);
176 if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
177 rc = seq_printf(m, "remote client\n");
179 rc = seq_printf(m, "local client\n");
183 LPROC_SEQ_FOPS_RO(ll_client_type);
185 static int ll_fstype_seq_show(struct seq_file *m, void *v)
187 struct super_block *sb = (struct super_block *)m->private;
190 return seq_printf(m, "%s\n", sb->s_type->name);
192 LPROC_SEQ_FOPS_RO(ll_fstype);
194 static int ll_sb_uuid_seq_show(struct seq_file *m, void *v)
196 struct super_block *sb = (struct super_block *)m->private;
199 return seq_printf(m, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
201 LPROC_SEQ_FOPS_RO(ll_sb_uuid);
203 static int ll_site_stats_seq_show(struct seq_file *m, void *v)
205 struct super_block *sb = m->private;
208 * See description of statistical counters in struct cl_site, and
211 return cl_site_stats_print(lu2cl_site(ll_s2sbi(sb)->ll_site), m);
213 LPROC_SEQ_FOPS_RO(ll_site_stats);
215 static int ll_max_readahead_mb_seq_show(struct seq_file *m, void *v)
217 struct super_block *sb = m->private;
218 struct ll_sb_info *sbi = ll_s2sbi(sb);
222 spin_lock(&sbi->ll_lock);
223 pages_number = sbi->ll_ra_info.ra_max_pages;
224 spin_unlock(&sbi->ll_lock);
226 mult = 1 << (20 - PAGE_CACHE_SHIFT);
227 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
230 static ssize_t ll_max_readahead_mb_seq_write(struct file *file, const char *buffer,
231 size_t count, loff_t *off)
233 struct super_block *sb = ((struct seq_file *)file->private_data)->private;
234 struct ll_sb_info *sbi = ll_s2sbi(sb);
235 int mult, rc, pages_number;
237 mult = 1 << (20 - PAGE_CACHE_SHIFT);
238 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
242 if (pages_number < 0 || pages_number > totalram_pages / 2) {
243 CERROR("can't set file readahead more than %lu MB\n",
244 totalram_pages >> (20 - PAGE_CACHE_SHIFT + 1)); /*1/2 of RAM*/
248 spin_lock(&sbi->ll_lock);
249 sbi->ll_ra_info.ra_max_pages = pages_number;
250 spin_unlock(&sbi->ll_lock);
254 LPROC_SEQ_FOPS(ll_max_readahead_mb);
256 static int ll_max_readahead_per_file_mb_seq_show(struct seq_file *m, void *v)
258 struct super_block *sb = m->private;
259 struct ll_sb_info *sbi = ll_s2sbi(sb);
263 spin_lock(&sbi->ll_lock);
264 pages_number = sbi->ll_ra_info.ra_max_pages_per_file;
265 spin_unlock(&sbi->ll_lock);
267 mult = 1 << (20 - PAGE_CACHE_SHIFT);
268 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
271 static ssize_t ll_max_readahead_per_file_mb_seq_write(struct file *file,
273 size_t count, loff_t *off)
275 struct super_block *sb = ((struct seq_file *)file->private_data)->private;
276 struct ll_sb_info *sbi = ll_s2sbi(sb);
277 int mult, rc, pages_number;
279 mult = 1 << (20 - PAGE_CACHE_SHIFT);
280 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
284 if (pages_number < 0 ||
285 pages_number > sbi->ll_ra_info.ra_max_pages) {
286 CERROR("can't set file readahead more than"
287 "max_read_ahead_mb %lu MB\n",
288 sbi->ll_ra_info.ra_max_pages);
292 spin_lock(&sbi->ll_lock);
293 sbi->ll_ra_info.ra_max_pages_per_file = pages_number;
294 spin_unlock(&sbi->ll_lock);
298 LPROC_SEQ_FOPS(ll_max_readahead_per_file_mb);
300 static int ll_max_read_ahead_whole_mb_seq_show(struct seq_file *m, void *unused)
302 struct super_block *sb = m->private;
303 struct ll_sb_info *sbi = ll_s2sbi(sb);
307 spin_lock(&sbi->ll_lock);
308 pages_number = sbi->ll_ra_info.ra_max_read_ahead_whole_pages;
309 spin_unlock(&sbi->ll_lock);
311 mult = 1 << (20 - PAGE_CACHE_SHIFT);
312 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
315 static ssize_t ll_max_read_ahead_whole_mb_seq_write(struct file *file,
317 size_t count, loff_t *off)
319 struct super_block *sb = ((struct seq_file *)file->private_data)->private;
320 struct ll_sb_info *sbi = ll_s2sbi(sb);
321 int mult, rc, pages_number;
323 mult = 1 << (20 - PAGE_CACHE_SHIFT);
324 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
328 /* Cap this at the current max readahead window size, the readahead
329 * algorithm does this anyway so it's pointless to set it larger. */
330 if (pages_number < 0 ||
331 pages_number > sbi->ll_ra_info.ra_max_pages_per_file) {
332 CERROR("can't set max_read_ahead_whole_mb more than "
333 "max_read_ahead_per_file_mb: %lu\n",
334 sbi->ll_ra_info.ra_max_pages_per_file >> (20 - PAGE_CACHE_SHIFT));
338 spin_lock(&sbi->ll_lock);
339 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = pages_number;
340 spin_unlock(&sbi->ll_lock);
344 LPROC_SEQ_FOPS(ll_max_read_ahead_whole_mb);
346 static int ll_max_cached_mb_seq_show(struct seq_file *m, void *v)
348 struct super_block *sb = m->private;
349 struct ll_sb_info *sbi = ll_s2sbi(sb);
350 struct cl_client_cache *cache = &sbi->ll_cache;
351 int shift = 20 - PAGE_CACHE_SHIFT;
355 max_cached_mb = cache->ccc_lru_max >> shift;
356 unused_mb = atomic_read(&cache->ccc_lru_left) >> shift;
359 "max_cached_mb: %d\n"
362 "reclaim_count: %u\n",
363 atomic_read(&cache->ccc_users),
365 max_cached_mb - unused_mb,
367 cache->ccc_lru_shrinkers);
370 static ssize_t ll_max_cached_mb_seq_write(struct file *file,
371 const char __user *buffer,
372 size_t count, loff_t *off)
374 struct super_block *sb = ((struct seq_file *)file->private_data)->private;
375 struct ll_sb_info *sbi = ll_s2sbi(sb);
376 struct cl_client_cache *cache = &sbi->ll_cache;
377 int mult, rc, pages_number;
382 if (count >= sizeof(kernbuf))
385 if (copy_from_user(kernbuf, buffer, count))
389 mult = 1 << (20 - PAGE_CACHE_SHIFT);
390 buffer += lprocfs_find_named_value(kernbuf, "max_cached_mb:", &count) -
392 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
396 if (pages_number < 0 || pages_number > totalram_pages) {
397 CERROR("%s: can't set max cache more than %lu MB\n",
398 ll_get_fsname(sb, NULL, 0),
399 totalram_pages >> (20 - PAGE_CACHE_SHIFT));
403 if (sbi->ll_dt_exp == NULL)
406 spin_lock(&sbi->ll_lock);
407 diff = pages_number - cache->ccc_lru_max;
408 spin_unlock(&sbi->ll_lock);
410 /* easy - add more LRU slots. */
412 atomic_add(diff, &cache->ccc_lru_left);
420 /* reduce LRU budget from free slots. */
424 ov = atomic_read(&cache->ccc_lru_left);
428 nv = ov > diff ? ov - diff : 0;
429 rc = atomic_cmpxchg(&cache->ccc_lru_left, ov, nv);
430 if (likely(ov == rc)) {
440 /* difficult - have to ask OSCs to drop LRU slots. */
442 rc = obd_set_info_async(NULL, sbi->ll_dt_exp,
443 sizeof(KEY_CACHE_LRU_SHRINK),
444 KEY_CACHE_LRU_SHRINK,
445 sizeof(tmp), &tmp, NULL);
452 spin_lock(&sbi->ll_lock);
453 cache->ccc_lru_max = pages_number;
454 spin_unlock(&sbi->ll_lock);
457 atomic_add(nrpages, &cache->ccc_lru_left);
461 LPROC_SEQ_FOPS(ll_max_cached_mb);
463 static int ll_checksum_seq_show(struct seq_file *m, void *v)
465 struct super_block *sb = m->private;
466 struct ll_sb_info *sbi = ll_s2sbi(sb);
468 return seq_printf(m, "%u\n", (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0);
471 static ssize_t ll_checksum_seq_write(struct file *file, const char *buffer,
472 size_t count, loff_t *off)
474 struct super_block *sb = ((struct seq_file *)file->private_data)->private;
475 struct ll_sb_info *sbi = ll_s2sbi(sb);
482 rc = lprocfs_write_helper(buffer, count, &val);
486 sbi->ll_flags |= LL_SBI_CHECKSUM;
488 sbi->ll_flags &= ~LL_SBI_CHECKSUM;
490 rc = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
491 KEY_CHECKSUM, sizeof(val), &val, NULL);
493 CWARN("Failed to set OSC checksum flags: %d\n", rc);
497 LPROC_SEQ_FOPS(ll_checksum);
499 static int ll_max_rw_chunk_seq_show(struct seq_file *m, void *v)
501 struct super_block *sb = m->private;
503 return seq_printf(m, "%lu\n", ll_s2sbi(sb)->ll_max_rw_chunk);
506 static ssize_t ll_max_rw_chunk_seq_write(struct file *file, const char *buffer,
507 size_t count, loff_t *off)
509 struct super_block *sb = ((struct seq_file *)file->private_data)->private;
512 rc = lprocfs_write_helper(buffer, count, &val);
515 ll_s2sbi(sb)->ll_max_rw_chunk = val;
518 LPROC_SEQ_FOPS(ll_max_rw_chunk);
520 static int ll_rd_track_id(struct seq_file *m, enum stats_track_type type)
522 struct super_block *sb = m->private;
524 if (ll_s2sbi(sb)->ll_stats_track_type == type) {
525 return seq_printf(m, "%d\n",
526 ll_s2sbi(sb)->ll_stats_track_id);
528 } else if (ll_s2sbi(sb)->ll_stats_track_type == STATS_TRACK_ALL) {
529 return seq_printf(m, "0 (all)\n");
531 return seq_printf(m, "untracked\n");
535 static int ll_wr_track_id(const char *buffer, unsigned long count, void *data,
536 enum stats_track_type type)
538 struct super_block *sb = data;
541 rc = lprocfs_write_helper(buffer, count, &pid);
544 ll_s2sbi(sb)->ll_stats_track_id = pid;
546 ll_s2sbi(sb)->ll_stats_track_type = STATS_TRACK_ALL;
548 ll_s2sbi(sb)->ll_stats_track_type = type;
549 lprocfs_clear_stats(ll_s2sbi(sb)->ll_stats);
553 static int ll_track_pid_seq_show(struct seq_file *m, void *v)
555 return ll_rd_track_id(m, STATS_TRACK_PID);
558 static ssize_t ll_track_pid_seq_write(struct file *file, const char *buffer,
559 size_t count, loff_t *off)
561 struct seq_file *seq = file->private_data;
562 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PID);
564 LPROC_SEQ_FOPS(ll_track_pid);
566 static int ll_track_ppid_seq_show(struct seq_file *m, void *v)
568 return ll_rd_track_id(m, STATS_TRACK_PPID);
571 static ssize_t ll_track_ppid_seq_write(struct file *file, const char *buffer,
572 size_t count, loff_t *off)
574 struct seq_file *seq = file->private_data;
575 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PPID);
577 LPROC_SEQ_FOPS(ll_track_ppid);
579 static int ll_track_gid_seq_show(struct seq_file *m, void *v)
581 return ll_rd_track_id(m, STATS_TRACK_GID);
584 static ssize_t ll_track_gid_seq_write(struct file *file, const char *buffer,
585 size_t count, loff_t *off)
587 struct seq_file *seq = file->private_data;
588 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_GID);
590 LPROC_SEQ_FOPS(ll_track_gid);
592 static int ll_statahead_max_seq_show(struct seq_file *m, void *v)
594 struct super_block *sb = m->private;
595 struct ll_sb_info *sbi = ll_s2sbi(sb);
597 return seq_printf(m, "%u\n", sbi->ll_sa_max);
600 static ssize_t ll_statahead_max_seq_write(struct file *file, const char *buffer,
601 size_t count, loff_t *off)
603 struct super_block *sb = ((struct seq_file *)file->private_data)->private;
604 struct ll_sb_info *sbi = ll_s2sbi(sb);
607 rc = lprocfs_write_helper(buffer, count, &val);
611 if (val >= 0 && val <= LL_SA_RPC_MAX)
612 sbi->ll_sa_max = val;
614 CERROR("Bad statahead_max value %d. Valid values are in the "
615 "range [0, %d]\n", val, LL_SA_RPC_MAX);
619 LPROC_SEQ_FOPS(ll_statahead_max);
621 static int ll_statahead_agl_seq_show(struct seq_file *m, void *v)
623 struct super_block *sb = m->private;
624 struct ll_sb_info *sbi = ll_s2sbi(sb);
626 return seq_printf(m, "%u\n",
627 sbi->ll_flags & LL_SBI_AGL_ENABLED ? 1 : 0);
630 static ssize_t ll_statahead_agl_seq_write(struct file *file, const char *buffer,
631 size_t count, loff_t *off)
633 struct super_block *sb = ((struct seq_file *)file->private_data)->private;
634 struct ll_sb_info *sbi = ll_s2sbi(sb);
637 rc = lprocfs_write_helper(buffer, count, &val);
642 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
644 sbi->ll_flags &= ~LL_SBI_AGL_ENABLED;
648 LPROC_SEQ_FOPS(ll_statahead_agl);
650 static int ll_statahead_stats_seq_show(struct seq_file *m, void *v)
652 struct super_block *sb = m->private;
653 struct ll_sb_info *sbi = ll_s2sbi(sb);
656 "statahead total: %u\n"
657 "statahead wrong: %u\n"
659 atomic_read(&sbi->ll_sa_total),
660 atomic_read(&sbi->ll_sa_wrong),
661 atomic_read(&sbi->ll_agl_total));
663 LPROC_SEQ_FOPS_RO(ll_statahead_stats);
665 static int ll_lazystatfs_seq_show(struct seq_file *m, void *v)
667 struct super_block *sb = m->private;
668 struct ll_sb_info *sbi = ll_s2sbi(sb);
670 return seq_printf(m, "%u\n",
671 (sbi->ll_flags & LL_SBI_LAZYSTATFS) ? 1 : 0);
674 static ssize_t ll_lazystatfs_seq_write(struct file *file, const char *buffer,
675 size_t count, loff_t *off)
677 struct super_block *sb = ((struct seq_file *)file->private_data)->private;
678 struct ll_sb_info *sbi = ll_s2sbi(sb);
681 rc = lprocfs_write_helper(buffer, count, &val);
686 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
688 sbi->ll_flags &= ~LL_SBI_LAZYSTATFS;
692 LPROC_SEQ_FOPS(ll_lazystatfs);
694 static int ll_max_easize_seq_show(struct seq_file *m, void *v)
696 struct super_block *sb = m->private;
697 struct ll_sb_info *sbi = ll_s2sbi(sb);
701 rc = ll_get_max_mdsize(sbi, &ealen);
705 return seq_printf(m, "%u\n", ealen);
707 LPROC_SEQ_FOPS_RO(ll_max_easize);
709 static int ll_defult_easize_seq_show(struct seq_file *m, void *v)
711 struct super_block *sb = m->private;
712 struct ll_sb_info *sbi = ll_s2sbi(sb);
716 rc = ll_get_default_mdsize(sbi, &ealen);
720 return seq_printf(m, "%u\n", ealen);
722 LPROC_SEQ_FOPS_RO(ll_defult_easize);
724 static int ll_max_cookiesize_seq_show(struct seq_file *m, void *v)
726 struct super_block *sb = m->private;
727 struct ll_sb_info *sbi = ll_s2sbi(sb);
728 unsigned int cookielen;
731 rc = ll_get_max_cookiesize(sbi, &cookielen);
735 return seq_printf(m, "%u\n", cookielen);
737 LPROC_SEQ_FOPS_RO(ll_max_cookiesize);
739 static int ll_defult_cookiesize_seq_show(struct seq_file *m, void *v)
741 struct super_block *sb = m->private;
742 struct ll_sb_info *sbi = ll_s2sbi(sb);
743 unsigned int cookielen;
746 rc = ll_get_default_cookiesize(sbi, &cookielen);
750 return seq_printf(m, "%u\n", cookielen);
752 LPROC_SEQ_FOPS_RO(ll_defult_cookiesize);
754 static int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
756 const char *str[] = LL_SBI_FLAGS;
757 struct super_block *sb = m->private;
758 int flags = ll_s2sbi(sb)->ll_flags;
762 if (ARRAY_SIZE(str) <= i) {
763 CERROR("%s: Revise array LL_SBI_FLAGS to match sbi "
764 "flags please.\n", ll_get_fsname(sb, NULL, 0));
769 seq_printf(m, "%s ", str[i]);
773 seq_printf(m, "\b\n");
776 LPROC_SEQ_FOPS_RO(ll_sbi_flags);
778 static int ll_xattr_cache_seq_show(struct seq_file *m, void *v)
780 struct super_block *sb = m->private;
781 struct ll_sb_info *sbi = ll_s2sbi(sb);
784 rc = seq_printf(m, "%u\n", sbi->ll_xattr_cache_enabled);
789 static ssize_t ll_xattr_cache_seq_write(struct file *file, const char *buffer,
790 size_t count, loff_t *off)
792 struct seq_file *seq = file->private_data;
793 struct super_block *sb = seq->private;
794 struct ll_sb_info *sbi = ll_s2sbi(sb);
797 rc = lprocfs_write_helper(buffer, count, &val);
801 if (val != 0 && val != 1)
804 if (val == 1 && !(sbi->ll_flags & LL_SBI_XATTR_CACHE))
807 sbi->ll_xattr_cache_enabled = val;
811 LPROC_SEQ_FOPS(ll_xattr_cache);
813 static struct lprocfs_vars lprocfs_llite_obd_vars[] = {
814 { "uuid", &ll_sb_uuid_fops, NULL, 0 },
815 //{ "mntpt_path", ll_rd_path, 0, 0 },
816 { "fstype", &ll_fstype_fops, NULL, 0 },
817 { "site", &ll_site_stats_fops, NULL, 0 },
818 { "blocksize", &ll_blksize_fops, NULL, 0 },
819 { "kbytestotal", &ll_kbytestotal_fops, NULL, 0 },
820 { "kbytesfree", &ll_kbytesfree_fops, NULL, 0 },
821 { "kbytesavail", &ll_kbytesavail_fops, NULL, 0 },
822 { "filestotal", &ll_filestotal_fops, NULL, 0 },
823 { "filesfree", &ll_filesfree_fops, NULL, 0 },
824 { "client_type", &ll_client_type_fops, NULL, 0 },
825 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 },
826 { "max_read_ahead_mb", &ll_max_readahead_mb_fops, NULL },
827 { "max_read_ahead_per_file_mb", &ll_max_readahead_per_file_mb_fops,
829 { "max_read_ahead_whole_mb", &ll_max_read_ahead_whole_mb_fops, NULL },
830 { "max_cached_mb", &ll_max_cached_mb_fops, NULL },
831 { "checksum_pages", &ll_checksum_fops, NULL },
832 { "max_rw_chunk", &ll_max_rw_chunk_fops, NULL },
833 { "stats_track_pid", &ll_track_pid_fops, NULL },
834 { "stats_track_ppid", &ll_track_ppid_fops, NULL },
835 { "stats_track_gid", &ll_track_gid_fops, NULL },
836 { "statahead_max", &ll_statahead_max_fops, NULL },
837 { "statahead_agl", &ll_statahead_agl_fops, NULL },
838 { "statahead_stats", &ll_statahead_stats_fops, NULL, 0 },
839 { "lazystatfs", &ll_lazystatfs_fops, NULL },
840 { "max_easize", &ll_max_easize_fops, NULL, 0 },
841 { "default_easize", &ll_defult_easize_fops, NULL, 0 },
842 { "max_cookiesize", &ll_max_cookiesize_fops, NULL, 0 },
843 { "default_cookiesize", &ll_defult_cookiesize_fops, NULL, 0 },
844 { "sbi_flags", &ll_sbi_flags_fops, NULL, 0 },
845 { "xattr_cache", &ll_xattr_cache_fops, NULL, 0 },
849 #define MAX_STRING_SIZE 128
851 static const struct llite_file_opcode {
855 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
857 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
858 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
859 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
861 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
863 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
865 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
867 { LPROC_LL_OSC_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
869 { LPROC_LL_OSC_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
871 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
872 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
873 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
874 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
875 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
876 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
877 { LPROC_LL_READDIR, LPROCFS_TYPE_REGS, "readdir" },
878 /* inode operation */
879 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
880 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "truncate" },
881 { LPROC_LL_FLOCK, LPROCFS_TYPE_REGS, "flock" },
882 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
883 /* dir inode operation */
884 { LPROC_LL_CREATE, LPROCFS_TYPE_REGS, "create" },
885 { LPROC_LL_LINK, LPROCFS_TYPE_REGS, "link" },
886 { LPROC_LL_UNLINK, LPROCFS_TYPE_REGS, "unlink" },
887 { LPROC_LL_SYMLINK, LPROCFS_TYPE_REGS, "symlink" },
888 { LPROC_LL_MKDIR, LPROCFS_TYPE_REGS, "mkdir" },
889 { LPROC_LL_RMDIR, LPROCFS_TYPE_REGS, "rmdir" },
890 { LPROC_LL_MKNOD, LPROCFS_TYPE_REGS, "mknod" },
891 { LPROC_LL_RENAME, LPROCFS_TYPE_REGS, "rename" },
892 /* special inode operation */
893 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
894 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
895 { LPROC_LL_SETXATTR, LPROCFS_TYPE_REGS, "setxattr" },
896 { LPROC_LL_GETXATTR, LPROCFS_TYPE_REGS, "getxattr" },
897 { LPROC_LL_GETXATTR_HITS, LPROCFS_TYPE_REGS, "getxattr_hits" },
898 { LPROC_LL_LISTXATTR, LPROCFS_TYPE_REGS, "listxattr" },
899 { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_REGS, "removexattr" },
900 { LPROC_LL_INODE_PERM, LPROCFS_TYPE_REGS, "inode_permission" },
903 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
907 if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
908 lprocfs_counter_add(sbi->ll_stats, op, count);
909 else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
910 sbi->ll_stats_track_id == current->pid)
911 lprocfs_counter_add(sbi->ll_stats, op, count);
912 else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
913 sbi->ll_stats_track_id == current->parent->pid)
914 lprocfs_counter_add(sbi->ll_stats, op, count);
915 else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
916 sbi->ll_stats_track_id ==
917 from_kgid(&init_user_ns, current_gid()))
918 lprocfs_counter_add(sbi->ll_stats, op, count);
920 EXPORT_SYMBOL(ll_stats_ops_tally);
922 static const char *ra_stat_string[] = {
923 [RA_STAT_HIT] = "hits",
924 [RA_STAT_MISS] = "misses",
925 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
926 [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
927 [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page",
928 [RA_STAT_FAILED_MATCH] = "failed lock match",
929 [RA_STAT_DISCARDED] = "read but discarded",
930 [RA_STAT_ZERO_LEN] = "zero length file",
931 [RA_STAT_ZERO_WINDOW] = "zero size window",
932 [RA_STAT_EOF] = "read-ahead to EOF",
933 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
934 [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",
937 LPROC_SEQ_FOPS_RO_TYPE(llite, name);
938 LPROC_SEQ_FOPS_RO_TYPE(llite, uuid);
940 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
941 struct super_block *sb, char *osc, char *mdc)
943 struct lprocfs_vars lvars[2];
944 struct lustre_sb_info *lsi = s2lsi(sb);
945 struct ll_sb_info *sbi = ll_s2sbi(sb);
946 struct obd_device *obd;
947 struct proc_dir_entry *dir;
948 char name[MAX_STRING_SIZE + 1], *ptr;
949 int err, id, len, rc;
951 memset(lvars, 0, sizeof(lvars));
953 name[MAX_STRING_SIZE] = '\0';
954 lvars[0].name = name;
956 LASSERT(sbi != NULL);
957 LASSERT(mdc != NULL);
958 LASSERT(osc != NULL);
961 len = strlen(lsi->lsi_lmd->lmd_profile);
962 ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
963 if (ptr && (strcmp(ptr, "-client") == 0))
967 snprintf(name, MAX_STRING_SIZE, "%.*s-%p", len,
968 lsi->lsi_lmd->lmd_profile, sb);
970 sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
971 if (IS_ERR(sbi->ll_proc_root)) {
972 err = PTR_ERR(sbi->ll_proc_root);
973 sbi->ll_proc_root = NULL;
977 rc = lprocfs_seq_create(sbi->ll_proc_root, "dump_page_cache", 0444,
978 &vvp_dump_pgcache_file_ops, sbi);
980 CWARN("Error adding the dump_page_cache file\n");
982 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats", 0644,
983 &ll_rw_extents_stats_fops, sbi);
985 CWARN("Error adding the extent_stats file\n");
987 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats_per_process",
988 0644, &ll_rw_extents_stats_pp_fops, sbi);
990 CWARN("Error adding the extents_stats_per_process file\n");
992 rc = lprocfs_seq_create(sbi->ll_proc_root, "offset_stats", 0644,
993 &ll_rw_offset_stats_fops, sbi);
995 CWARN("Error adding the offset_stats file\n");
997 /* File operations stats */
998 sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
999 LPROCFS_STATS_FLAG_NONE);
1000 if (sbi->ll_stats == NULL)
1001 GOTO(out, err = -ENOMEM);
1002 /* do counter init */
1003 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
1004 __u32 type = llite_opcode_table[id].type;
1006 if (type & LPROCFS_TYPE_REGS)
1008 else if (type & LPROCFS_TYPE_BYTES)
1010 else if (type & LPROCFS_TYPE_PAGES)
1012 lprocfs_counter_init(sbi->ll_stats,
1013 llite_opcode_table[id].opcode,
1014 (type & LPROCFS_CNTR_AVGMINMAX),
1015 llite_opcode_table[id].opname, ptr);
1017 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats);
1021 sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
1022 LPROCFS_STATS_FLAG_NONE);
1023 if (sbi->ll_ra_stats == NULL)
1024 GOTO(out, err = -ENOMEM);
1026 for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
1027 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
1028 ra_stat_string[id], "pages");
1029 err = lprocfs_register_stats(sbi->ll_proc_root, "read_ahead_stats",
1035 err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_llite_obd_vars, sb);
1040 obd = class_name2obd(mdc);
1042 LASSERT(obd != NULL);
1043 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1044 LASSERT(obd->obd_type->typ_name != NULL);
1046 dir = proc_mkdir(obd->obd_type->typ_name, sbi->ll_proc_root);
1048 GOTO(out, err = -ENOMEM);
1050 snprintf(name, MAX_STRING_SIZE, "common_name");
1051 lvars[0].fops = &llite_name_fops;
1052 err = lprocfs_add_vars(dir, lvars, obd);
1056 snprintf(name, MAX_STRING_SIZE, "uuid");
1057 lvars[0].fops = &llite_uuid_fops;
1058 err = lprocfs_add_vars(dir, lvars, obd);
1063 obd = class_name2obd(osc);
1065 LASSERT(obd != NULL);
1066 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1067 LASSERT(obd->obd_type->typ_name != NULL);
1069 dir = proc_mkdir(obd->obd_type->typ_name, sbi->ll_proc_root);
1071 GOTO(out, err = -ENOMEM);
1073 snprintf(name, MAX_STRING_SIZE, "common_name");
1074 lvars[0].fops = &llite_name_fops;
1075 err = lprocfs_add_vars(dir, lvars, obd);
1079 snprintf(name, MAX_STRING_SIZE, "uuid");
1080 lvars[0].fops = &llite_uuid_fops;
1081 err = lprocfs_add_vars(dir, lvars, obd);
1084 lprocfs_remove(&sbi->ll_proc_root);
1085 lprocfs_free_stats(&sbi->ll_ra_stats);
1086 lprocfs_free_stats(&sbi->ll_stats);
1091 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
1093 if (sbi->ll_proc_root) {
1094 lprocfs_remove(&sbi->ll_proc_root);
1095 lprocfs_free_stats(&sbi->ll_ra_stats);
1096 lprocfs_free_stats(&sbi->ll_stats);
1099 #undef MAX_STRING_SIZE
1101 #define pct(a,b) (b ? a * 100 / b : 0)
1103 static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
1104 struct seq_file *seq, int which)
1106 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
1107 unsigned long start, end, r, w;
1108 char *unitp = "KMGTPEZY";
1110 struct per_process_info *pp_info = &io_extents->pp_extents[which];
1116 for(i = 0; i < LL_HIST_MAX; i++) {
1117 read_tot += pp_info->pp_r_hist.oh_buckets[i];
1118 write_tot += pp_info->pp_w_hist.oh_buckets[i];
1121 for(i = 0; i < LL_HIST_MAX; i++) {
1122 r = pp_info->pp_r_hist.oh_buckets[i];
1123 w = pp_info->pp_w_hist.oh_buckets[i];
1126 end = 1 << (i + LL_HIST_START - units);
1127 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu | "
1128 "%14lu %4lu %4lu\n", start, *unitp, end, *unitp,
1129 (i == LL_HIST_MAX - 1) ? '+' : ' ',
1130 r, pct(r, read_tot), pct(read_cum, read_tot),
1131 w, pct(w, write_tot), pct(write_cum, write_tot));
1133 if (start == 1<<10) {
1138 if (read_cum == read_tot && write_cum == write_tot)
1143 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
1146 struct ll_sb_info *sbi = seq->private;
1147 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1150 do_gettimeofday(&now);
1152 if (!sbi->ll_rw_stats_on) {
1153 seq_printf(seq, "disabled\n"
1154 "write anything in this file to activate, "
1155 "then 0 or \"[D/d]isabled\" to deactivate\n");
1158 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1159 now.tv_sec, (unsigned long)now.tv_usec);
1160 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1161 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1162 "extents", "calls", "%", "cum%",
1163 "calls", "%", "cum%");
1164 spin_lock(&sbi->ll_pp_extent_lock);
1165 for (k = 0; k < LL_PROCESS_HIST_MAX; k++) {
1166 if (io_extents->pp_extents[k].pid != 0) {
1167 seq_printf(seq, "\nPID: %d\n",
1168 io_extents->pp_extents[k].pid);
1169 ll_display_extents_info(io_extents, seq, k);
1172 spin_unlock(&sbi->ll_pp_extent_lock);
1176 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
1177 const char __user *buf,
1181 struct seq_file *seq = file->private_data;
1182 struct ll_sb_info *sbi = seq->private;
1183 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1185 int value = 1, rc = 0;
1190 rc = lprocfs_write_helper(buf, len, &value);
1191 if (rc < 0 && len < 16) {
1194 if (copy_from_user(kernbuf, buf, len))
1198 if (kernbuf[len - 1] == '\n')
1199 kernbuf[len - 1] = 0;
1201 if (strcmp(kernbuf, "disabled") == 0 ||
1202 strcmp(kernbuf, "Disabled") == 0)
1207 sbi->ll_rw_stats_on = 0;
1209 sbi->ll_rw_stats_on = 1;
1211 spin_lock(&sbi->ll_pp_extent_lock);
1212 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1213 io_extents->pp_extents[i].pid = 0;
1214 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1215 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1217 spin_unlock(&sbi->ll_pp_extent_lock);
1221 LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
1223 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
1226 struct ll_sb_info *sbi = seq->private;
1227 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1229 do_gettimeofday(&now);
1231 if (!sbi->ll_rw_stats_on) {
1232 seq_printf(seq, "disabled\n"
1233 "write anything in this file to activate, "
1234 "then 0 or \"[D/d]isabled\" to deactivate\n");
1237 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1238 now.tv_sec, (unsigned long)now.tv_usec);
1240 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1241 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1242 "extents", "calls", "%", "cum%",
1243 "calls", "%", "cum%");
1244 spin_lock(&sbi->ll_lock);
1245 ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
1246 spin_unlock(&sbi->ll_lock);
1251 static ssize_t ll_rw_extents_stats_seq_write(struct file *file,
1252 const char __user *buf,
1253 size_t len, loff_t *off)
1255 struct seq_file *seq = file->private_data;
1256 struct ll_sb_info *sbi = seq->private;
1257 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1259 int value = 1, rc = 0;
1264 rc = lprocfs_write_helper(buf, len, &value);
1265 if (rc < 0 && len < 16) {
1268 if (copy_from_user(kernbuf, buf, len))
1272 if (kernbuf[len - 1] == '\n')
1273 kernbuf[len - 1] = 0;
1275 if (strcmp(kernbuf, "disabled") == 0 ||
1276 strcmp(kernbuf, "Disabled") == 0)
1281 sbi->ll_rw_stats_on = 0;
1283 sbi->ll_rw_stats_on = 1;
1285 spin_lock(&sbi->ll_pp_extent_lock);
1286 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
1287 io_extents->pp_extents[i].pid = 0;
1288 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1289 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1291 spin_unlock(&sbi->ll_pp_extent_lock);
1295 LPROC_SEQ_FOPS(ll_rw_extents_stats);
1297 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
1298 struct ll_file_data *file, loff_t pos,
1299 size_t count, int rw)
1302 struct ll_rw_process_info *process;
1303 struct ll_rw_process_info *offset;
1304 int *off_count = &sbi->ll_rw_offset_entry_count;
1305 int *process_count = &sbi->ll_offset_process_count;
1306 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1308 if(!sbi->ll_rw_stats_on)
1310 process = sbi->ll_rw_process_info;
1311 offset = sbi->ll_rw_offset_info;
1313 spin_lock(&sbi->ll_pp_extent_lock);
1314 /* Extent statistics */
1315 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1316 if(io_extents->pp_extents[i].pid == pid) {
1324 sbi->ll_extent_process_count =
1325 (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1326 cur = sbi->ll_extent_process_count;
1327 io_extents->pp_extents[cur].pid = pid;
1328 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1329 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1332 for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
1333 (i < (LL_HIST_MAX - 1)); i++);
1335 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1336 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1338 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1339 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1341 spin_unlock(&sbi->ll_pp_extent_lock);
1343 spin_lock(&sbi->ll_process_lock);
1344 /* Offset statistics */
1345 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1346 if (process[i].rw_pid == pid) {
1347 if (process[i].rw_last_file != file) {
1348 process[i].rw_range_start = pos;
1349 process[i].rw_last_file_pos = pos + count;
1350 process[i].rw_smallest_extent = count;
1351 process[i].rw_largest_extent = count;
1352 process[i].rw_offset = 0;
1353 process[i].rw_last_file = file;
1354 spin_unlock(&sbi->ll_process_lock);
1357 if (process[i].rw_last_file_pos != pos) {
1359 (*off_count + 1) % LL_OFFSET_HIST_MAX;
1360 offset[*off_count].rw_op = process[i].rw_op;
1361 offset[*off_count].rw_pid = pid;
1362 offset[*off_count].rw_range_start =
1363 process[i].rw_range_start;
1364 offset[*off_count].rw_range_end =
1365 process[i].rw_last_file_pos;
1366 offset[*off_count].rw_smallest_extent =
1367 process[i].rw_smallest_extent;
1368 offset[*off_count].rw_largest_extent =
1369 process[i].rw_largest_extent;
1370 offset[*off_count].rw_offset =
1371 process[i].rw_offset;
1372 process[i].rw_op = rw;
1373 process[i].rw_range_start = pos;
1374 process[i].rw_smallest_extent = count;
1375 process[i].rw_largest_extent = count;
1376 process[i].rw_offset = pos -
1377 process[i].rw_last_file_pos;
1379 if(process[i].rw_smallest_extent > count)
1380 process[i].rw_smallest_extent = count;
1381 if(process[i].rw_largest_extent < count)
1382 process[i].rw_largest_extent = count;
1383 process[i].rw_last_file_pos = pos + count;
1384 spin_unlock(&sbi->ll_process_lock);
1388 *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
1389 process[*process_count].rw_pid = pid;
1390 process[*process_count].rw_op = rw;
1391 process[*process_count].rw_range_start = pos;
1392 process[*process_count].rw_last_file_pos = pos + count;
1393 process[*process_count].rw_smallest_extent = count;
1394 process[*process_count].rw_largest_extent = count;
1395 process[*process_count].rw_offset = 0;
1396 process[*process_count].rw_last_file = file;
1397 spin_unlock(&sbi->ll_process_lock);
1400 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1403 struct ll_sb_info *sbi = seq->private;
1404 struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
1405 struct ll_rw_process_info *process = sbi->ll_rw_process_info;
1408 do_gettimeofday(&now);
1410 if (!sbi->ll_rw_stats_on) {
1411 seq_printf(seq, "disabled\n"
1412 "write anything in this file to activate, "
1413 "then 0 or \"[D/d]isabled\" to deactivate\n");
1416 spin_lock(&sbi->ll_process_lock);
1418 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1419 now.tv_sec, (unsigned long)now.tv_usec);
1420 seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
1421 "R/W", "PID", "RANGE START", "RANGE END",
1422 "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
1423 /* We stored the discontiguous offsets here; print them first */
1424 for(i = 0; i < LL_OFFSET_HIST_MAX; i++) {
1425 if (offset[i].rw_pid != 0)
1427 "%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1428 offset[i].rw_op == READ ? 'R' : 'W',
1430 offset[i].rw_range_start,
1431 offset[i].rw_range_end,
1432 (unsigned long)offset[i].rw_smallest_extent,
1433 (unsigned long)offset[i].rw_largest_extent,
1434 offset[i].rw_offset);
1436 /* Then print the current offsets for each process */
1437 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1438 if (process[i].rw_pid != 0)
1440 "%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1441 process[i].rw_op == READ ? 'R' : 'W',
1443 process[i].rw_range_start,
1444 process[i].rw_last_file_pos,
1445 (unsigned long)process[i].rw_smallest_extent,
1446 (unsigned long)process[i].rw_largest_extent,
1447 process[i].rw_offset);
1449 spin_unlock(&sbi->ll_process_lock);
1454 static ssize_t ll_rw_offset_stats_seq_write(struct file *file,
1455 const char __user *buf,
1456 size_t len, loff_t *off)
1458 struct seq_file *seq = file->private_data;
1459 struct ll_sb_info *sbi = seq->private;
1460 struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
1461 struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
1462 int value = 1, rc = 0;
1467 rc = lprocfs_write_helper(buf, len, &value);
1469 if (rc < 0 && len < 16) {
1472 if (copy_from_user(kernbuf, buf, len))
1476 if (kernbuf[len - 1] == '\n')
1477 kernbuf[len - 1] = 0;
1479 if (strcmp(kernbuf, "disabled") == 0 ||
1480 strcmp(kernbuf, "Disabled") == 0)
1485 sbi->ll_rw_stats_on = 0;
1487 sbi->ll_rw_stats_on = 1;
1489 spin_lock(&sbi->ll_process_lock);
1490 sbi->ll_offset_process_count = 0;
1491 sbi->ll_rw_offset_entry_count = 0;
1492 memset(process_info, 0, sizeof(struct ll_rw_process_info) *
1493 LL_PROCESS_HIST_MAX);
1494 memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
1495 LL_OFFSET_HIST_MAX);
1496 spin_unlock(&sbi->ll_process_lock);
1501 LPROC_SEQ_FOPS(ll_rw_offset_stats);
1503 void lprocfs_llite_init_vars(struct lprocfs_static_vars *lvars)
1505 lvars->module_vars = NULL;
1506 lvars->obd_vars = lprocfs_llite_obd_vars;