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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2016, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 #define DEBUG_SUBSYSTEM S_LLITE
34 #include <linux/version.h>
35 #include <linux/user_namespace.h>
36 #ifdef HAVE_UIDGID_HEADER
37 # include <linux/uidgid.h>
39 #include <uapi/linux/lustre/lustre_param.h>
40 #include <lprocfs_status.h>
41 #include <obd_support.h>
43 #include "llite_internal.h"
44 #include "vvp_internal.h"
46 struct proc_dir_entry *proc_lustre_fs_root;
49 /* /proc/lustre/llite mount point registration */
50 static const struct file_operations ll_rw_extents_stats_fops;
51 static const struct file_operations ll_rw_extents_stats_pp_fops;
52 static const struct file_operations ll_rw_offset_stats_fops;
53 static __s64 ll_stats_pid_write(const char __user *buf, size_t len);
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 seq_printf(m, "%u\n", osfs.os_bsize);
69 LPROC_SEQ_FOPS_RO(ll_blksize);
71 static int ll_stat_blksize_seq_show(struct seq_file *m, void *v)
73 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
75 seq_printf(m, "%u\n", sbi->ll_stat_blksize);
80 static ssize_t ll_stat_blksize_seq_write(struct file *file,
81 const char __user *buffer,
82 size_t count, loff_t *off)
84 struct seq_file *m = file->private_data;
85 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
89 rc = lprocfs_str_to_s64(buffer, count, &val);
93 if (val != 0 && (val < PAGE_SIZE || (val & (val - 1))) != 0)
96 sbi->ll_stat_blksize = val;
100 LPROC_SEQ_FOPS(ll_stat_blksize);
102 static int ll_kbytestotal_seq_show(struct seq_file *m, void *v)
104 struct super_block *sb = m->private;
105 struct obd_statfs osfs;
109 rc = ll_statfs_internal(sb, &osfs,
110 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
113 __u32 blk_size = osfs.os_bsize >> 10;
114 __u64 result = osfs.os_blocks;
116 while (blk_size >>= 1)
119 seq_printf(m, "%llu\n", result);
123 LPROC_SEQ_FOPS_RO(ll_kbytestotal);
125 static int ll_kbytesfree_seq_show(struct seq_file *m, void *v)
127 struct super_block *sb = m->private;
128 struct obd_statfs osfs;
132 rc = ll_statfs_internal(sb, &osfs,
133 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
136 __u32 blk_size = osfs.os_bsize >> 10;
137 __u64 result = osfs.os_bfree;
139 while (blk_size >>= 1)
142 seq_printf(m, "%llu\n", result);
146 LPROC_SEQ_FOPS_RO(ll_kbytesfree);
148 static int ll_kbytesavail_seq_show(struct seq_file *m, void *v)
150 struct super_block *sb = m->private;
151 struct obd_statfs osfs;
155 rc = ll_statfs_internal(sb, &osfs,
156 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
159 __u32 blk_size = osfs.os_bsize >> 10;
160 __u64 result = osfs.os_bavail;
162 while (blk_size >>= 1)
165 seq_printf(m, "%llu\n", result);
169 LPROC_SEQ_FOPS_RO(ll_kbytesavail);
171 static int ll_filestotal_seq_show(struct seq_file *m, void *v)
173 struct super_block *sb = m->private;
174 struct obd_statfs osfs;
178 rc = ll_statfs_internal(sb, &osfs,
179 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
182 seq_printf(m, "%llu\n", osfs.os_files);
185 LPROC_SEQ_FOPS_RO(ll_filestotal);
187 static int ll_filesfree_seq_show(struct seq_file *m, void *v)
189 struct super_block *sb = m->private;
190 struct obd_statfs osfs;
194 rc = ll_statfs_internal(sb, &osfs,
195 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
198 seq_printf(m, "%llu\n", osfs.os_ffree);
201 LPROC_SEQ_FOPS_RO(ll_filesfree);
203 static int ll_client_type_seq_show(struct seq_file *m, void *v)
205 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
207 LASSERT(sbi != NULL);
209 seq_puts(m, "local client\n");
212 LPROC_SEQ_FOPS_RO(ll_client_type);
214 static int ll_fstype_seq_show(struct seq_file *m, void *v)
216 struct super_block *sb = m->private;
219 seq_printf(m, "%s\n", sb->s_type->name);
222 LPROC_SEQ_FOPS_RO(ll_fstype);
224 static int ll_sb_uuid_seq_show(struct seq_file *m, void *v)
226 struct super_block *sb = m->private;
229 seq_printf(m, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
232 LPROC_SEQ_FOPS_RO(ll_sb_uuid);
234 static int ll_xattr_cache_seq_show(struct seq_file *m, void *v)
236 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
238 seq_printf(m, "%u\n", sbi->ll_xattr_cache_enabled);
242 static ssize_t ll_xattr_cache_seq_write(struct file *file,
243 const char __user *buffer,
244 size_t count, loff_t *off)
246 struct seq_file *m = file->private_data;
247 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
251 rc = lprocfs_str_to_s64(buffer, count, &val);
255 if (val != 0 && val != 1)
258 if (val == 1 && !(sbi->ll_flags & LL_SBI_XATTR_CACHE))
261 sbi->ll_xattr_cache_enabled = val;
262 sbi->ll_xattr_cache_set = 1;
266 LPROC_SEQ_FOPS(ll_xattr_cache);
268 static int ll_site_stats_seq_show(struct seq_file *m, void *v)
270 struct super_block *sb = m->private;
273 * See description of statistical counters in struct cl_site, and
276 return cl_site_stats_print(lu2cl_site(ll_s2sbi(sb)->ll_site), m);
278 LPROC_SEQ_FOPS_RO(ll_site_stats);
280 static int ll_max_readahead_mb_seq_show(struct seq_file *m, void *v)
282 struct super_block *sb = m->private;
283 struct ll_sb_info *sbi = ll_s2sbi(sb);
287 spin_lock(&sbi->ll_lock);
288 pages_number = sbi->ll_ra_info.ra_max_pages;
289 spin_unlock(&sbi->ll_lock);
291 mult = 1 << (20 - PAGE_SHIFT);
292 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
296 ll_max_readahead_mb_seq_write(struct file *file, const char __user *buffer,
297 size_t count, loff_t *off)
299 struct seq_file *m = file->private_data;
300 struct super_block *sb = m->private;
301 struct ll_sb_info *sbi = ll_s2sbi(sb);
305 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
309 pages_number >>= PAGE_SHIFT;
311 if (pages_number < 0 || pages_number > totalram_pages / 2) {
313 CERROR("%s: can't set max_readahead_mb=%lu > %luMB\n",
314 ll_get_fsname(sb, NULL, 0),
315 (unsigned long)pages_number >> (20 - PAGE_SHIFT),
316 totalram_pages >> (20 - PAGE_SHIFT + 1));
320 spin_lock(&sbi->ll_lock);
321 sbi->ll_ra_info.ra_max_pages = pages_number;
322 spin_unlock(&sbi->ll_lock);
325 LPROC_SEQ_FOPS(ll_max_readahead_mb);
327 static int ll_max_readahead_per_file_mb_seq_show(struct seq_file *m, void *v)
329 struct super_block *sb = m->private;
330 struct ll_sb_info *sbi = ll_s2sbi(sb);
334 spin_lock(&sbi->ll_lock);
335 pages_number = sbi->ll_ra_info.ra_max_pages_per_file;
336 spin_unlock(&sbi->ll_lock);
338 mult = 1 << (20 - PAGE_SHIFT);
339 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
343 ll_max_readahead_per_file_mb_seq_write(struct file *file,
344 const char __user *buffer,
345 size_t count, loff_t *off)
347 struct seq_file *m = file->private_data;
348 struct super_block *sb = m->private;
349 struct ll_sb_info *sbi = ll_s2sbi(sb);
353 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
357 pages_number >>= PAGE_SHIFT;
359 if (pages_number < 0 || pages_number > sbi->ll_ra_info.ra_max_pages) {
360 CERROR("%s: can't set max_readahead_per_file_mb=%lu > "
361 "max_read_ahead_mb=%lu\n", ll_get_fsname(sb, NULL, 0),
362 (unsigned long)pages_number >> (20 - PAGE_SHIFT),
363 sbi->ll_ra_info.ra_max_pages >> (20 - PAGE_SHIFT));
367 spin_lock(&sbi->ll_lock);
368 sbi->ll_ra_info.ra_max_pages_per_file = pages_number;
369 spin_unlock(&sbi->ll_lock);
372 LPROC_SEQ_FOPS(ll_max_readahead_per_file_mb);
374 static int ll_max_read_ahead_whole_mb_seq_show(struct seq_file *m, void *v)
376 struct super_block *sb = m->private;
377 struct ll_sb_info *sbi = ll_s2sbi(sb);
381 spin_lock(&sbi->ll_lock);
382 pages_number = sbi->ll_ra_info.ra_max_read_ahead_whole_pages;
383 spin_unlock(&sbi->ll_lock);
385 mult = 1 << (20 - PAGE_SHIFT);
386 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
390 ll_max_read_ahead_whole_mb_seq_write(struct file *file,
391 const char __user *buffer,
392 size_t count, loff_t *off)
394 struct seq_file *m = file->private_data;
395 struct super_block *sb = m->private;
396 struct ll_sb_info *sbi = ll_s2sbi(sb);
400 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
404 pages_number >>= PAGE_SHIFT;
406 /* Cap this at the current max readahead window size, the readahead
407 * algorithm does this anyway so it's pointless to set it larger. */
408 if (pages_number < 0 ||
409 pages_number > sbi->ll_ra_info.ra_max_pages_per_file) {
410 int pages_shift = 20 - PAGE_SHIFT;
411 CERROR("%s: can't set max_read_ahead_whole_mb=%lu > "
412 "max_read_ahead_per_file_mb=%lu\n",
413 ll_get_fsname(sb, NULL, 0),
414 (unsigned long)pages_number >> pages_shift,
415 sbi->ll_ra_info.ra_max_pages_per_file >> pages_shift);
419 spin_lock(&sbi->ll_lock);
420 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = pages_number;
421 spin_unlock(&sbi->ll_lock);
424 LPROC_SEQ_FOPS(ll_max_read_ahead_whole_mb);
426 static int ll_max_cached_mb_seq_show(struct seq_file *m, void *v)
428 struct super_block *sb = m->private;
429 struct ll_sb_info *sbi = ll_s2sbi(sb);
430 struct cl_client_cache *cache = sbi->ll_cache;
431 int shift = 20 - PAGE_SHIFT;
435 max_cached_mb = cache->ccc_lru_max >> shift;
436 unused_mb = atomic_long_read(&cache->ccc_lru_left) >> shift;
437 seq_printf(m, "users: %d\n"
438 "max_cached_mb: %ld\n"
441 "reclaim_count: %u\n",
442 atomic_read(&cache->ccc_users),
444 max_cached_mb - unused_mb,
446 cache->ccc_lru_shrinkers);
451 ll_max_cached_mb_seq_write(struct file *file, const char __user *buffer,
452 size_t count, loff_t *off)
454 struct seq_file *m = file->private_data;
455 struct super_block *sb = m->private;
456 struct ll_sb_info *sbi = ll_s2sbi(sb);
457 struct cl_client_cache *cache = sbi->ll_cache;
467 if (count >= sizeof(kernbuf))
470 if (copy_from_user(kernbuf, buffer, count))
474 buffer += lprocfs_find_named_value(kernbuf, "max_cached_mb:", &count) -
476 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
480 pages_number >>= PAGE_SHIFT;
482 if (pages_number < 0 || pages_number > totalram_pages) {
483 CERROR("%s: can't set max cache more than %lu MB\n",
484 ll_get_fsname(sb, NULL, 0),
485 totalram_pages >> (20 - PAGE_SHIFT));
488 /* Allow enough cache so clients can make well-formed RPCs */
489 pages_number = max_t(long, pages_number, PTLRPC_MAX_BRW_PAGES);
491 spin_lock(&sbi->ll_lock);
492 diff = pages_number - cache->ccc_lru_max;
493 spin_unlock(&sbi->ll_lock);
495 /* easy - add more LRU slots. */
497 atomic_long_add(diff, &cache->ccc_lru_left);
501 env = cl_env_get(&refcheck);
509 /* reduce LRU budget from free slots. */
513 ov = atomic_long_read(&cache->ccc_lru_left);
517 nv = ov > diff ? ov - diff : 0;
518 rc = atomic_long_cmpxchg(&cache->ccc_lru_left, ov, nv);
519 if (likely(ov == rc)) {
529 if (sbi->ll_dt_exp == NULL) { /* being initialized */
534 /* difficult - have to ask OSCs to drop LRU slots. */
536 rc = obd_set_info_async(env, sbi->ll_dt_exp,
537 sizeof(KEY_CACHE_LRU_SHRINK),
538 KEY_CACHE_LRU_SHRINK,
539 sizeof(tmp), &tmp, NULL);
543 cl_env_put(env, &refcheck);
547 spin_lock(&sbi->ll_lock);
548 cache->ccc_lru_max = pages_number;
549 spin_unlock(&sbi->ll_lock);
552 atomic_long_add(nrpages, &cache->ccc_lru_left);
556 LPROC_SEQ_FOPS(ll_max_cached_mb);
558 static int ll_checksum_seq_show(struct seq_file *m, void *v)
560 struct super_block *sb = m->private;
561 struct ll_sb_info *sbi = ll_s2sbi(sb);
563 seq_printf(m, "%u\n", (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0);
567 static ssize_t ll_checksum_seq_write(struct file *file,
568 const char __user *buffer,
569 size_t count, loff_t *off)
571 struct seq_file *m = file->private_data;
572 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
580 rc = lprocfs_str_to_s64(buffer, count, &val);
584 sbi->ll_flags |= LL_SBI_CHECKSUM;
586 sbi->ll_flags &= ~LL_SBI_CHECKSUM;
588 rc = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
589 KEY_CHECKSUM, sizeof(val), &val, NULL);
591 CWARN("Failed to set OSC checksum flags: %d\n", rc);
595 LPROC_SEQ_FOPS(ll_checksum);
597 static int ll_rd_track_id(struct seq_file *m, enum stats_track_type type)
599 struct super_block *sb = m->private;
601 if (ll_s2sbi(sb)->ll_stats_track_type == type) {
602 seq_printf(m, "%d\n",
603 ll_s2sbi(sb)->ll_stats_track_id);
604 } else if (ll_s2sbi(sb)->ll_stats_track_type == STATS_TRACK_ALL) {
605 seq_puts(m, "0 (all)\n");
607 seq_puts(m, "untracked\n");
612 static int ll_wr_track_id(const char __user *buffer, unsigned long count,
613 void *data, enum stats_track_type type)
615 struct super_block *sb = data;
619 rc = lprocfs_str_to_s64(buffer, count, &pid);
622 if (pid > INT_MAX || pid < 0)
625 ll_s2sbi(sb)->ll_stats_track_id = pid;
627 ll_s2sbi(sb)->ll_stats_track_type = STATS_TRACK_ALL;
629 ll_s2sbi(sb)->ll_stats_track_type = type;
630 lprocfs_clear_stats(ll_s2sbi(sb)->ll_stats);
634 static int ll_track_pid_seq_show(struct seq_file *m, void *v)
636 return ll_rd_track_id(m, STATS_TRACK_PID);
639 static ssize_t ll_track_pid_seq_write(struct file *file,
640 const char __user *buffer,
641 size_t count, loff_t *off)
643 struct seq_file *seq = file->private_data;
644 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PID);
646 LPROC_SEQ_FOPS(ll_track_pid);
648 static int ll_track_ppid_seq_show(struct seq_file *m, void *v)
650 return ll_rd_track_id(m, STATS_TRACK_PPID);
653 static ssize_t ll_track_ppid_seq_write(struct file *file,
654 const char __user *buffer,
655 size_t count, loff_t *off)
657 struct seq_file *seq = file->private_data;
658 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PPID);
660 LPROC_SEQ_FOPS(ll_track_ppid);
662 static int ll_track_gid_seq_show(struct seq_file *m, void *v)
664 return ll_rd_track_id(m, STATS_TRACK_GID);
667 static ssize_t ll_track_gid_seq_write(struct file *file,
668 const char __user *buffer,
669 size_t count, loff_t *off)
671 struct seq_file *seq = file->private_data;
672 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_GID);
674 LPROC_SEQ_FOPS(ll_track_gid);
676 static int ll_statahead_max_seq_show(struct seq_file *m, void *v)
678 struct super_block *sb = m->private;
679 struct ll_sb_info *sbi = ll_s2sbi(sb);
681 seq_printf(m, "%u\n", sbi->ll_sa_max);
685 static ssize_t ll_statahead_max_seq_write(struct file *file,
686 const char __user *buffer,
687 size_t count, loff_t *off)
689 struct seq_file *m = file->private_data;
690 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
694 rc = lprocfs_str_to_s64(buffer, count, &val);
698 if (val >= 0 && val <= LL_SA_RPC_MAX)
699 sbi->ll_sa_max = val;
701 CERROR("Bad statahead_max value %lld. Valid values are in "
702 "the range [0, %d]\n", val, LL_SA_RPC_MAX);
706 LPROC_SEQ_FOPS(ll_statahead_max);
708 static int ll_statahead_agl_seq_show(struct seq_file *m, void *v)
710 struct super_block *sb = m->private;
711 struct ll_sb_info *sbi = ll_s2sbi(sb);
713 seq_printf(m, "%u\n",
714 sbi->ll_flags & LL_SBI_AGL_ENABLED ? 1 : 0);
718 static ssize_t ll_statahead_agl_seq_write(struct file *file,
719 const char __user *buffer,
720 size_t count, loff_t *off)
722 struct seq_file *m = file->private_data;
723 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
727 rc = lprocfs_str_to_s64(buffer, count, &val);
732 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
734 sbi->ll_flags &= ~LL_SBI_AGL_ENABLED;
738 LPROC_SEQ_FOPS(ll_statahead_agl);
740 static int ll_statahead_stats_seq_show(struct seq_file *m, void *v)
742 struct super_block *sb = m->private;
743 struct ll_sb_info *sbi = ll_s2sbi(sb);
745 seq_printf(m, "statahead total: %u\n"
746 "statahead wrong: %u\n"
748 atomic_read(&sbi->ll_sa_total),
749 atomic_read(&sbi->ll_sa_wrong),
750 atomic_read(&sbi->ll_agl_total));
753 LPROC_SEQ_FOPS_RO(ll_statahead_stats);
755 static int ll_lazystatfs_seq_show(struct seq_file *m, void *v)
757 struct super_block *sb = m->private;
758 struct ll_sb_info *sbi = ll_s2sbi(sb);
760 seq_printf(m, "%u\n",
761 (sbi->ll_flags & LL_SBI_LAZYSTATFS) ? 1 : 0);
765 static ssize_t ll_lazystatfs_seq_write(struct file *file,
766 const char __user *buffer,
767 size_t count, loff_t *off)
769 struct seq_file *m = file->private_data;
770 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
774 rc = lprocfs_str_to_s64(buffer, count, &val);
779 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
781 sbi->ll_flags &= ~LL_SBI_LAZYSTATFS;
785 LPROC_SEQ_FOPS(ll_lazystatfs);
787 static int ll_max_easize_seq_show(struct seq_file *m, void *v)
789 struct super_block *sb = m->private;
790 struct ll_sb_info *sbi = ll_s2sbi(sb);
794 rc = ll_get_max_mdsize(sbi, &ealen);
798 seq_printf(m, "%u\n", ealen);
801 LPROC_SEQ_FOPS_RO(ll_max_easize);
804 * Get default_easize.
806 * \see client_obd::cl_default_mds_easize
808 * \param[in] m seq_file handle
809 * \param[in] v unused for single entry
811 * \retval 0 on success
812 * \retval negative negated errno on failure
814 static int ll_default_easize_seq_show(struct seq_file *m, void *v)
816 struct super_block *sb = m->private;
817 struct ll_sb_info *sbi = ll_s2sbi(sb);
821 rc = ll_get_default_mdsize(sbi, &ealen);
825 seq_printf(m, "%u\n", ealen);
830 * Set default_easize.
832 * Range checking on the passed value is handled by
833 * ll_set_default_mdsize().
835 * \see client_obd::cl_default_mds_easize
837 * \param[in] file proc file
838 * \param[in] buffer string passed from user space
839 * \param[in] count \a buffer length
840 * \param[in] off unused for single entry
842 * \retval positive \a count on success
843 * \retval negative negated errno on failure
845 static ssize_t ll_default_easize_seq_write(struct file *file,
846 const char __user *buffer,
847 size_t count, loff_t *unused)
849 struct seq_file *seq = file->private_data;
850 struct super_block *sb = (struct super_block *)seq->private;
851 struct ll_sb_info *sbi = ll_s2sbi(sb);
858 rc = lprocfs_str_to_s64(buffer, count, &val);
861 if (val < 0 || val > INT_MAX)
864 rc = ll_set_default_mdsize(sbi, val);
870 LPROC_SEQ_FOPS(ll_default_easize);
872 static int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
874 const char *str[] = LL_SBI_FLAGS;
875 struct super_block *sb = m->private;
876 int flags = ll_s2sbi(sb)->ll_flags;
880 if (ARRAY_SIZE(str) <= i) {
881 CERROR("%s: Revise array LL_SBI_FLAGS to match sbi "
882 "flags please.\n", ll_get_fsname(sb, NULL, 0));
887 seq_printf(m, "%s ", str[i]);
891 seq_printf(m, "\b\n");
894 LPROC_SEQ_FOPS_RO(ll_sbi_flags);
896 static int ll_fast_read_seq_show(struct seq_file *m, void *v)
898 struct super_block *sb = m->private;
899 struct ll_sb_info *sbi = ll_s2sbi(sb);
901 seq_printf(m, "%u\n", !!(sbi->ll_flags & LL_SBI_FAST_READ));
906 ll_fast_read_seq_write(struct file *file, const char __user *buffer,
907 size_t count, loff_t *off)
909 struct seq_file *m = file->private_data;
910 struct super_block *sb = m->private;
911 struct ll_sb_info *sbi = ll_s2sbi(sb);
915 rc = lprocfs_str_to_s64(buffer, count, &val);
919 spin_lock(&sbi->ll_lock);
921 sbi->ll_flags |= LL_SBI_FAST_READ;
923 sbi->ll_flags &= ~LL_SBI_FAST_READ;
924 spin_unlock(&sbi->ll_lock);
928 LPROC_SEQ_FOPS(ll_fast_read);
930 static int ll_pio_seq_show(struct seq_file *m, void *v)
932 struct super_block *sb = m->private;
933 struct ll_sb_info *sbi = ll_s2sbi(sb);
935 seq_printf(m, "%u\n", !!(sbi->ll_flags & LL_SBI_PIO));
939 static ssize_t ll_pio_seq_write(struct file *file, const char __user *buffer,
940 size_t count, loff_t *off)
942 struct seq_file *m = file->private_data;
943 struct super_block *sb = m->private;
944 struct ll_sb_info *sbi = ll_s2sbi(sb);
948 rc = lprocfs_str_to_s64(buffer, count, &val);
952 spin_lock(&sbi->ll_lock);
954 sbi->ll_flags |= LL_SBI_PIO;
956 sbi->ll_flags &= ~LL_SBI_PIO;
957 spin_unlock(&sbi->ll_lock);
961 LPROC_SEQ_FOPS(ll_pio);
963 static int ll_unstable_stats_seq_show(struct seq_file *m, void *v)
965 struct super_block *sb = m->private;
966 struct ll_sb_info *sbi = ll_s2sbi(sb);
967 struct cl_client_cache *cache = sbi->ll_cache;
971 pages = atomic_long_read(&cache->ccc_unstable_nr);
972 mb = (pages * PAGE_SIZE) >> 20;
974 seq_printf(m, "unstable_check: %8d\n"
975 "unstable_pages: %12ld\n"
976 "unstable_mb: %8d\n",
977 cache->ccc_unstable_check, pages, mb);
981 static ssize_t ll_unstable_stats_seq_write(struct file *file,
982 const char __user *buffer,
983 size_t count, loff_t *unused)
985 struct seq_file *seq = file->private_data;
986 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)seq->private);
993 if (count >= sizeof(kernbuf))
996 if (copy_from_user(kernbuf, buffer, count))
1000 buffer += lprocfs_find_named_value(kernbuf, "unstable_check:", &count) -
1002 rc = lprocfs_str_to_s64(buffer, count, &val);
1006 /* borrow lru lock to set the value */
1007 spin_lock(&sbi->ll_cache->ccc_lru_lock);
1008 sbi->ll_cache->ccc_unstable_check = !!val;
1009 spin_unlock(&sbi->ll_cache->ccc_lru_lock);
1013 LPROC_SEQ_FOPS(ll_unstable_stats);
1015 static int ll_root_squash_seq_show(struct seq_file *m, void *v)
1017 struct super_block *sb = m->private;
1018 struct ll_sb_info *sbi = ll_s2sbi(sb);
1019 struct root_squash_info *squash = &sbi->ll_squash;
1021 seq_printf(m, "%u:%u\n", squash->rsi_uid, squash->rsi_gid);
1025 static ssize_t ll_root_squash_seq_write(struct file *file,
1026 const char __user *buffer,
1027 size_t count, loff_t *off)
1029 struct seq_file *m = file->private_data;
1030 struct super_block *sb = m->private;
1031 struct ll_sb_info *sbi = ll_s2sbi(sb);
1032 struct root_squash_info *squash = &sbi->ll_squash;
1034 return lprocfs_wr_root_squash(buffer, count, squash,
1035 ll_get_fsname(sb, NULL, 0));
1037 LPROC_SEQ_FOPS(ll_root_squash);
1039 static int ll_nosquash_nids_seq_show(struct seq_file *m, void *v)
1041 struct super_block *sb = m->private;
1042 struct ll_sb_info *sbi = ll_s2sbi(sb);
1043 struct root_squash_info *squash = &sbi->ll_squash;
1046 down_read(&squash->rsi_sem);
1047 if (!list_empty(&squash->rsi_nosquash_nids)) {
1048 len = cfs_print_nidlist(m->buf + m->count, m->size - m->count,
1049 &squash->rsi_nosquash_nids);
1053 seq_puts(m, "NONE\n");
1055 up_read(&squash->rsi_sem);
1060 static ssize_t ll_nosquash_nids_seq_write(struct file *file,
1061 const char __user *buffer,
1062 size_t count, loff_t *off)
1064 struct seq_file *m = file->private_data;
1065 struct super_block *sb = m->private;
1066 struct ll_sb_info *sbi = ll_s2sbi(sb);
1067 struct root_squash_info *squash = &sbi->ll_squash;
1070 rc = lprocfs_wr_nosquash_nids(buffer, count, squash,
1071 ll_get_fsname(sb, NULL, 0));
1075 ll_compute_rootsquash_state(sbi);
1079 LPROC_SEQ_FOPS(ll_nosquash_nids);
1081 struct lprocfs_vars lprocfs_llite_obd_vars[] = {
1083 .fops = &ll_sb_uuid_fops },
1085 .fops = &ll_fstype_fops },
1087 .fops = &ll_site_stats_fops },
1088 { .name = "blocksize",
1089 .fops = &ll_blksize_fops },
1090 { .name = "stat_blocksize",
1091 .fops = &ll_stat_blksize_fops },
1092 { .name = "kbytestotal",
1093 .fops = &ll_kbytestotal_fops },
1094 { .name = "kbytesfree",
1095 .fops = &ll_kbytesfree_fops },
1096 { .name = "kbytesavail",
1097 .fops = &ll_kbytesavail_fops },
1098 { .name = "filestotal",
1099 .fops = &ll_filestotal_fops },
1100 { .name = "filesfree",
1101 .fops = &ll_filesfree_fops },
1102 { .name = "client_type",
1103 .fops = &ll_client_type_fops },
1104 { .name = "max_read_ahead_mb",
1105 .fops = &ll_max_readahead_mb_fops },
1106 { .name = "max_read_ahead_per_file_mb",
1107 .fops = &ll_max_readahead_per_file_mb_fops },
1108 { .name = "max_read_ahead_whole_mb",
1109 .fops = &ll_max_read_ahead_whole_mb_fops },
1110 { .name = "max_cached_mb",
1111 .fops = &ll_max_cached_mb_fops },
1112 { .name = "checksum_pages",
1113 .fops = &ll_checksum_fops },
1114 { .name = "stats_track_pid",
1115 .fops = &ll_track_pid_fops },
1116 { .name = "stats_track_ppid",
1117 .fops = &ll_track_ppid_fops },
1118 { .name = "stats_track_gid",
1119 .fops = &ll_track_gid_fops },
1120 { .name = "statahead_max",
1121 .fops = &ll_statahead_max_fops },
1122 { .name = "statahead_agl",
1123 .fops = &ll_statahead_agl_fops },
1124 { .name = "statahead_stats",
1125 .fops = &ll_statahead_stats_fops },
1126 { .name = "lazystatfs",
1127 .fops = &ll_lazystatfs_fops },
1128 { .name = "max_easize",
1129 .fops = &ll_max_easize_fops },
1130 { .name = "default_easize",
1131 .fops = &ll_default_easize_fops },
1132 { .name = "sbi_flags",
1133 .fops = &ll_sbi_flags_fops },
1134 { .name = "xattr_cache",
1135 .fops = &ll_xattr_cache_fops },
1136 { .name = "unstable_stats",
1137 .fops = &ll_unstable_stats_fops },
1138 { .name = "root_squash",
1139 .fops = &ll_root_squash_fops },
1140 { .name = "nosquash_nids",
1141 .fops = &ll_nosquash_nids_fops },
1142 { .name = "fast_read",
1143 .fops = &ll_fast_read_fops, },
1145 .fops = &ll_pio_fops, },
1149 #define MAX_STRING_SIZE 128
1151 static const struct llite_file_opcode {
1155 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
1156 /* file operation */
1157 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
1158 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
1159 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1161 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1163 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
1165 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
1167 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
1168 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
1169 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
1170 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
1171 { LPROC_LL_FAULT, LPROCFS_TYPE_REGS, "page_fault" },
1172 { LPROC_LL_MKWRITE, LPROCFS_TYPE_REGS, "page_mkwrite" },
1173 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
1174 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
1175 { LPROC_LL_READDIR, LPROCFS_TYPE_REGS, "readdir" },
1176 /* inode operation */
1177 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
1178 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "truncate" },
1179 { LPROC_LL_FLOCK, LPROCFS_TYPE_REGS, "flock" },
1180 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
1181 /* dir inode operation */
1182 { LPROC_LL_CREATE, LPROCFS_TYPE_REGS, "create" },
1183 { LPROC_LL_LINK, LPROCFS_TYPE_REGS, "link" },
1184 { LPROC_LL_UNLINK, LPROCFS_TYPE_REGS, "unlink" },
1185 { LPROC_LL_SYMLINK, LPROCFS_TYPE_REGS, "symlink" },
1186 { LPROC_LL_MKDIR, LPROCFS_TYPE_REGS, "mkdir" },
1187 { LPROC_LL_RMDIR, LPROCFS_TYPE_REGS, "rmdir" },
1188 { LPROC_LL_MKNOD, LPROCFS_TYPE_REGS, "mknod" },
1189 { LPROC_LL_RENAME, LPROCFS_TYPE_REGS, "rename" },
1190 /* special inode operation */
1191 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
1192 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
1193 { LPROC_LL_SETXATTR, LPROCFS_TYPE_REGS, "setxattr" },
1194 { LPROC_LL_GETXATTR, LPROCFS_TYPE_REGS, "getxattr" },
1195 { LPROC_LL_GETXATTR_HITS, LPROCFS_TYPE_REGS, "getxattr_hits" },
1196 { LPROC_LL_LISTXATTR, LPROCFS_TYPE_REGS, "listxattr" },
1197 { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_REGS, "removexattr" },
1198 { LPROC_LL_INODE_PERM, LPROCFS_TYPE_REGS, "inode_permission" },
1201 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
1205 if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
1206 lprocfs_counter_add(sbi->ll_stats, op, count);
1207 else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
1208 sbi->ll_stats_track_id == current->pid)
1209 lprocfs_counter_add(sbi->ll_stats, op, count);
1210 else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
1211 sbi->ll_stats_track_id == current->parent->pid)
1212 lprocfs_counter_add(sbi->ll_stats, op, count);
1213 else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
1214 sbi->ll_stats_track_id ==
1215 from_kgid(&init_user_ns, current_gid()))
1216 lprocfs_counter_add(sbi->ll_stats, op, count);
1218 EXPORT_SYMBOL(ll_stats_ops_tally);
1220 static const char *ra_stat_string[] = {
1221 [RA_STAT_HIT] = "hits",
1222 [RA_STAT_MISS] = "misses",
1223 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
1224 [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
1225 [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page",
1226 [RA_STAT_FAILED_MATCH] = "failed lock match",
1227 [RA_STAT_DISCARDED] = "read but discarded",
1228 [RA_STAT_ZERO_LEN] = "zero length file",
1229 [RA_STAT_ZERO_WINDOW] = "zero size window",
1230 [RA_STAT_EOF] = "read-ahead to EOF",
1231 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
1232 [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",
1233 [RA_STAT_FAILED_REACH_END] = "failed to reach end"
1236 LPROC_SEQ_FOPS_RO_TYPE(llite, name);
1237 LPROC_SEQ_FOPS_RO_TYPE(llite, uuid);
1239 int lprocfs_ll_register_mountpoint(struct proc_dir_entry *parent,
1240 struct super_block *sb)
1242 struct lprocfs_vars lvars[2];
1243 struct lustre_sb_info *lsi = s2lsi(sb);
1244 struct ll_sb_info *sbi = ll_s2sbi(sb);
1245 char name[MAX_STRING_SIZE + 1], *ptr;
1246 int err, id, len, rc;
1249 memset(lvars, 0, sizeof(lvars));
1251 name[MAX_STRING_SIZE] = '\0';
1252 lvars[0].name = name;
1254 LASSERT(sbi != NULL);
1257 len = strlen(lsi->lsi_lmd->lmd_profile);
1258 ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
1259 if (ptr && (strcmp(ptr, "-client") == 0))
1263 snprintf(name, MAX_STRING_SIZE, "%.*s-%p", len,
1264 lsi->lsi_lmd->lmd_profile, sb);
1266 sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
1267 if (IS_ERR(sbi->ll_proc_root)) {
1268 err = PTR_ERR(sbi->ll_proc_root);
1269 sbi->ll_proc_root = NULL;
1273 rc = lprocfs_seq_create(sbi->ll_proc_root, "dump_page_cache", 0444,
1274 &vvp_dump_pgcache_file_ops, sbi);
1276 CWARN("Error adding the dump_page_cache file\n");
1278 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats", 0644,
1279 &ll_rw_extents_stats_fops, sbi);
1281 CWARN("Error adding the extent_stats file\n");
1283 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats_per_process",
1284 0644, &ll_rw_extents_stats_pp_fops, sbi);
1286 CWARN("Error adding the extents_stats_per_process file\n");
1288 rc = lprocfs_seq_create(sbi->ll_proc_root, "offset_stats", 0644,
1289 &ll_rw_offset_stats_fops, sbi);
1291 CWARN("Error adding the offset_stats file\n");
1293 /* File operations stats */
1294 sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
1295 LPROCFS_STATS_FLAG_NONE);
1296 if (sbi->ll_stats == NULL)
1297 GOTO(out, err = -ENOMEM);
1298 /* do counter init */
1299 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
1300 __u32 type = llite_opcode_table[id].type;
1302 if (type & LPROCFS_TYPE_REGS)
1304 else if (type & LPROCFS_TYPE_BYTES)
1306 else if (type & LPROCFS_TYPE_PAGES)
1308 lprocfs_counter_init(sbi->ll_stats,
1309 llite_opcode_table[id].opcode,
1310 (type & LPROCFS_CNTR_AVGMINMAX),
1311 llite_opcode_table[id].opname, ptr);
1313 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats);
1317 sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
1318 LPROCFS_STATS_FLAG_NONE);
1319 if (sbi->ll_ra_stats == NULL)
1320 GOTO(out, err = -ENOMEM);
1322 for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
1323 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
1324 ra_stat_string[id], "pages");
1325 err = lprocfs_register_stats(sbi->ll_proc_root, "read_ahead_stats",
1331 err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_llite_obd_vars, sb);
1337 lprocfs_remove(&sbi->ll_proc_root);
1338 lprocfs_free_stats(&sbi->ll_ra_stats);
1339 lprocfs_free_stats(&sbi->ll_stats);
1344 int lprocfs_ll_register_obd(struct super_block *sb, const char *obdname)
1346 struct lprocfs_vars lvars[2];
1347 struct ll_sb_info *sbi = ll_s2sbi(sb);
1348 struct obd_device *obd;
1349 struct proc_dir_entry *dir;
1350 char name[MAX_STRING_SIZE + 1];
1354 memset(lvars, 0, sizeof(lvars));
1356 name[MAX_STRING_SIZE] = '\0';
1357 lvars[0].name = name;
1359 LASSERT(sbi != NULL);
1360 LASSERT(obdname != NULL);
1362 obd = class_name2obd(obdname);
1364 LASSERT(obd != NULL);
1365 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1366 LASSERT(obd->obd_type->typ_name != NULL);
1368 dir = proc_mkdir(obd->obd_type->typ_name, sbi->ll_proc_root);
1370 GOTO(out, err = -ENOMEM);
1372 snprintf(name, MAX_STRING_SIZE, "common_name");
1373 lvars[0].fops = &llite_name_fops;
1374 err = lprocfs_add_vars(dir, lvars, obd);
1378 snprintf(name, MAX_STRING_SIZE, "uuid");
1379 lvars[0].fops = &llite_uuid_fops;
1380 err = lprocfs_add_vars(dir, lvars, obd);
1386 lprocfs_remove(&sbi->ll_proc_root);
1387 lprocfs_free_stats(&sbi->ll_ra_stats);
1388 lprocfs_free_stats(&sbi->ll_stats);
1393 void lprocfs_ll_unregister_mountpoint(struct ll_sb_info *sbi)
1395 if (sbi->ll_proc_root) {
1396 lprocfs_remove(&sbi->ll_proc_root);
1397 lprocfs_free_stats(&sbi->ll_ra_stats);
1398 lprocfs_free_stats(&sbi->ll_stats);
1401 #undef MAX_STRING_SIZE
1403 #define pct(a,b) (b ? a * 100 / b : 0)
1405 static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
1406 struct seq_file *seq, int which)
1408 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
1409 unsigned long start, end, r, w;
1410 char *unitp = "KMGTPEZY";
1412 struct per_process_info *pp_info = &io_extents->pp_extents[which];
1418 for(i = 0; i < LL_HIST_MAX; i++) {
1419 read_tot += pp_info->pp_r_hist.oh_buckets[i];
1420 write_tot += pp_info->pp_w_hist.oh_buckets[i];
1423 for(i = 0; i < LL_HIST_MAX; i++) {
1424 r = pp_info->pp_r_hist.oh_buckets[i];
1425 w = pp_info->pp_w_hist.oh_buckets[i];
1428 end = 1 << (i + LL_HIST_START - units);
1429 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu | "
1430 "%14lu %4lu %4lu\n", start, *unitp, end, *unitp,
1431 (i == LL_HIST_MAX - 1) ? '+' : ' ',
1432 r, pct(r, read_tot), pct(read_cum, read_tot),
1433 w, pct(w, write_tot), pct(write_cum, write_tot));
1435 if (start == 1<<10) {
1440 if (read_cum == read_tot && write_cum == write_tot)
1445 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
1447 struct timespec64 now;
1448 struct ll_sb_info *sbi = seq->private;
1449 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1452 ktime_get_real_ts64(&now);
1454 if (!sbi->ll_rw_stats_on) {
1455 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
1458 seq_printf(seq, "snapshot_time: %llu.%09lu (secs.nsecs)\n",
1459 (s64)now.tv_sec, now.tv_nsec);
1460 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1461 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1462 "extents", "calls", "%", "cum%",
1463 "calls", "%", "cum%");
1464 spin_lock(&sbi->ll_pp_extent_lock);
1465 for (k = 0; k < LL_PROCESS_HIST_MAX; k++) {
1466 if (io_extents->pp_extents[k].pid != 0) {
1467 seq_printf(seq, "\nPID: %d\n",
1468 io_extents->pp_extents[k].pid);
1469 ll_display_extents_info(io_extents, seq, k);
1472 spin_unlock(&sbi->ll_pp_extent_lock);
1476 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
1477 const char __user *buf,
1481 struct seq_file *seq = file->private_data;
1482 struct ll_sb_info *sbi = seq->private;
1483 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1490 value = ll_stats_pid_write(buf, len);
1493 sbi->ll_rw_stats_on = 0;
1495 sbi->ll_rw_stats_on = 1;
1497 spin_lock(&sbi->ll_pp_extent_lock);
1498 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1499 io_extents->pp_extents[i].pid = 0;
1500 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1501 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1503 spin_unlock(&sbi->ll_pp_extent_lock);
1507 LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
1509 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
1511 struct timespec64 now;
1512 struct ll_sb_info *sbi = seq->private;
1513 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1515 ktime_get_real_ts64(&now);
1517 if (!sbi->ll_rw_stats_on) {
1518 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
1521 seq_printf(seq, "snapshot_time: %llu.%09lu (secs.nsecs)\n",
1522 (s64)now.tv_sec, now.tv_nsec);
1524 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1525 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1526 "extents", "calls", "%", "cum%",
1527 "calls", "%", "cum%");
1528 spin_lock(&sbi->ll_lock);
1529 ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
1530 spin_unlock(&sbi->ll_lock);
1535 static ssize_t ll_rw_extents_stats_seq_write(struct file *file,
1536 const char __user *buf,
1537 size_t len, loff_t *off)
1539 struct seq_file *seq = file->private_data;
1540 struct ll_sb_info *sbi = seq->private;
1541 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1548 value = ll_stats_pid_write(buf, len);
1551 sbi->ll_rw_stats_on = 0;
1553 sbi->ll_rw_stats_on = 1;
1555 spin_lock(&sbi->ll_pp_extent_lock);
1556 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
1557 io_extents->pp_extents[i].pid = 0;
1558 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1559 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1561 spin_unlock(&sbi->ll_pp_extent_lock);
1565 LPROC_SEQ_FOPS(ll_rw_extents_stats);
1567 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
1568 struct ll_file_data *file, loff_t pos,
1569 size_t count, int rw)
1572 struct ll_rw_process_info *process;
1573 struct ll_rw_process_info *offset;
1574 int *off_count = &sbi->ll_rw_offset_entry_count;
1575 int *process_count = &sbi->ll_offset_process_count;
1576 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1578 if(!sbi->ll_rw_stats_on)
1580 process = sbi->ll_rw_process_info;
1581 offset = sbi->ll_rw_offset_info;
1583 spin_lock(&sbi->ll_pp_extent_lock);
1584 /* Extent statistics */
1585 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1586 if(io_extents->pp_extents[i].pid == pid) {
1594 sbi->ll_extent_process_count =
1595 (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1596 cur = sbi->ll_extent_process_count;
1597 io_extents->pp_extents[cur].pid = pid;
1598 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1599 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1602 for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
1603 (i < (LL_HIST_MAX - 1)); i++);
1605 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1606 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1608 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1609 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1611 spin_unlock(&sbi->ll_pp_extent_lock);
1613 spin_lock(&sbi->ll_process_lock);
1614 /* Offset statistics */
1615 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1616 if (process[i].rw_pid == pid) {
1617 if (process[i].rw_last_file != file) {
1618 process[i].rw_range_start = pos;
1619 process[i].rw_last_file_pos = pos + count;
1620 process[i].rw_smallest_extent = count;
1621 process[i].rw_largest_extent = count;
1622 process[i].rw_offset = 0;
1623 process[i].rw_last_file = file;
1624 spin_unlock(&sbi->ll_process_lock);
1627 if (process[i].rw_last_file_pos != pos) {
1629 (*off_count + 1) % LL_OFFSET_HIST_MAX;
1630 offset[*off_count].rw_op = process[i].rw_op;
1631 offset[*off_count].rw_pid = pid;
1632 offset[*off_count].rw_range_start =
1633 process[i].rw_range_start;
1634 offset[*off_count].rw_range_end =
1635 process[i].rw_last_file_pos;
1636 offset[*off_count].rw_smallest_extent =
1637 process[i].rw_smallest_extent;
1638 offset[*off_count].rw_largest_extent =
1639 process[i].rw_largest_extent;
1640 offset[*off_count].rw_offset =
1641 process[i].rw_offset;
1642 process[i].rw_op = rw;
1643 process[i].rw_range_start = pos;
1644 process[i].rw_smallest_extent = count;
1645 process[i].rw_largest_extent = count;
1646 process[i].rw_offset = pos -
1647 process[i].rw_last_file_pos;
1649 if(process[i].rw_smallest_extent > count)
1650 process[i].rw_smallest_extent = count;
1651 if(process[i].rw_largest_extent < count)
1652 process[i].rw_largest_extent = count;
1653 process[i].rw_last_file_pos = pos + count;
1654 spin_unlock(&sbi->ll_process_lock);
1658 *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
1659 process[*process_count].rw_pid = pid;
1660 process[*process_count].rw_op = rw;
1661 process[*process_count].rw_range_start = pos;
1662 process[*process_count].rw_last_file_pos = pos + count;
1663 process[*process_count].rw_smallest_extent = count;
1664 process[*process_count].rw_largest_extent = count;
1665 process[*process_count].rw_offset = 0;
1666 process[*process_count].rw_last_file = file;
1667 spin_unlock(&sbi->ll_process_lock);
1670 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1672 struct timespec64 now;
1673 struct ll_sb_info *sbi = seq->private;
1674 struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
1675 struct ll_rw_process_info *process = sbi->ll_rw_process_info;
1678 ktime_get_real_ts64(&now);
1680 if (!sbi->ll_rw_stats_on) {
1681 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
1684 spin_lock(&sbi->ll_process_lock);
1686 seq_printf(seq, "snapshot_time: %llu.%09lu (secs.nsecs)\n",
1687 (s64)now.tv_sec, now.tv_nsec);
1688 seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
1689 "R/W", "PID", "RANGE START", "RANGE END",
1690 "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
1692 /* We stored the discontiguous offsets here; print them first */
1693 for (i = 0; i < LL_OFFSET_HIST_MAX; i++) {
1694 if (offset[i].rw_pid != 0)
1696 "%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1697 offset[i].rw_op == READ ? 'R' : 'W',
1699 offset[i].rw_range_start,
1700 offset[i].rw_range_end,
1701 (unsigned long)offset[i].rw_smallest_extent,
1702 (unsigned long)offset[i].rw_largest_extent,
1703 offset[i].rw_offset);
1706 /* Then print the current offsets for each process */
1707 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1708 if (process[i].rw_pid != 0)
1710 "%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1711 process[i].rw_op == READ ? 'R' : 'W',
1713 process[i].rw_range_start,
1714 process[i].rw_last_file_pos,
1715 (unsigned long)process[i].rw_smallest_extent,
1716 (unsigned long)process[i].rw_largest_extent,
1717 process[i].rw_offset);
1719 spin_unlock(&sbi->ll_process_lock);
1724 static ssize_t ll_rw_offset_stats_seq_write(struct file *file,
1725 const char __user *buf,
1726 size_t len, loff_t *off)
1728 struct seq_file *seq = file->private_data;
1729 struct ll_sb_info *sbi = seq->private;
1730 struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
1731 struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
1737 value = ll_stats_pid_write(buf, len);
1740 sbi->ll_rw_stats_on = 0;
1742 sbi->ll_rw_stats_on = 1;
1744 spin_lock(&sbi->ll_process_lock);
1745 sbi->ll_offset_process_count = 0;
1746 sbi->ll_rw_offset_entry_count = 0;
1747 memset(process_info, 0, sizeof(struct ll_rw_process_info) *
1748 LL_PROCESS_HIST_MAX);
1749 memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
1750 LL_OFFSET_HIST_MAX);
1751 spin_unlock(&sbi->ll_process_lock);
1757 * ll_stats_pid_write() - Determine if stats collection should be enabled
1758 * @buf: Buffer containing the data written
1759 * @len: Number of bytes in the buffer
1761 * Several proc files begin collecting stats when a value is written, and stop
1762 * collecting when either '0' or 'disable' is written. This function checks the
1763 * written value to see if collection should be enabled or disabled.
1765 * Return: If '0' or 'disable' is provided, 0 is returned. If the text
1766 * equivalent of a number is written, that number is returned. Otherwise,
1767 * 1 is returned. Non-zero return values indicate collection should be enabled.
1769 static __s64 ll_stats_pid_write(const char __user *buf, size_t len)
1775 rc = lprocfs_str_to_s64(buf, len, &value);
1777 if (rc < 0 && len < sizeof(kernbuf)) {
1779 if (copy_from_user(kernbuf, buf, len))
1783 if (kernbuf[len - 1] == '\n')
1784 kernbuf[len - 1] = 0;
1786 if (strncasecmp(kernbuf, "disable", 7) == 0)
1793 LPROC_SEQ_FOPS(ll_rw_offset_stats);
1794 #endif /* CONFIG_PROC_FS */