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_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;
265 LPROC_SEQ_FOPS(ll_xattr_cache);
267 static int ll_site_stats_seq_show(struct seq_file *m, void *v)
269 struct super_block *sb = m->private;
272 * See description of statistical counters in struct cl_site, and
275 return cl_site_stats_print(lu2cl_site(ll_s2sbi(sb)->ll_site), m);
277 LPROC_SEQ_FOPS_RO(ll_site_stats);
279 static int ll_max_readahead_mb_seq_show(struct seq_file *m, void *v)
281 struct super_block *sb = m->private;
282 struct ll_sb_info *sbi = ll_s2sbi(sb);
286 spin_lock(&sbi->ll_lock);
287 pages_number = sbi->ll_ra_info.ra_max_pages;
288 spin_unlock(&sbi->ll_lock);
290 mult = 1 << (20 - PAGE_SHIFT);
291 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
295 ll_max_readahead_mb_seq_write(struct file *file, const char __user *buffer,
296 size_t count, loff_t *off)
298 struct seq_file *m = file->private_data;
299 struct super_block *sb = m->private;
300 struct ll_sb_info *sbi = ll_s2sbi(sb);
304 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
308 pages_number >>= PAGE_SHIFT;
310 if (pages_number < 0 || pages_number > totalram_pages / 2) {
312 CERROR("%s: can't set max_readahead_mb=%lu > %luMB\n",
313 ll_get_fsname(sb, NULL, 0),
314 (unsigned long)pages_number >> (20 - PAGE_SHIFT),
315 totalram_pages >> (20 - PAGE_SHIFT + 1));
319 spin_lock(&sbi->ll_lock);
320 sbi->ll_ra_info.ra_max_pages = pages_number;
321 spin_unlock(&sbi->ll_lock);
324 LPROC_SEQ_FOPS(ll_max_readahead_mb);
326 static int ll_max_readahead_per_file_mb_seq_show(struct seq_file *m, void *v)
328 struct super_block *sb = m->private;
329 struct ll_sb_info *sbi = ll_s2sbi(sb);
333 spin_lock(&sbi->ll_lock);
334 pages_number = sbi->ll_ra_info.ra_max_pages_per_file;
335 spin_unlock(&sbi->ll_lock);
337 mult = 1 << (20 - PAGE_SHIFT);
338 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
342 ll_max_readahead_per_file_mb_seq_write(struct file *file,
343 const char __user *buffer,
344 size_t count, loff_t *off)
346 struct seq_file *m = file->private_data;
347 struct super_block *sb = m->private;
348 struct ll_sb_info *sbi = ll_s2sbi(sb);
352 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
356 pages_number >>= PAGE_SHIFT;
358 if (pages_number < 0 || pages_number > sbi->ll_ra_info.ra_max_pages) {
359 CERROR("%s: can't set max_readahead_per_file_mb=%lu > "
360 "max_read_ahead_mb=%lu\n", ll_get_fsname(sb, NULL, 0),
361 (unsigned long)pages_number >> (20 - PAGE_SHIFT),
362 sbi->ll_ra_info.ra_max_pages >> (20 - PAGE_SHIFT));
366 spin_lock(&sbi->ll_lock);
367 sbi->ll_ra_info.ra_max_pages_per_file = pages_number;
368 spin_unlock(&sbi->ll_lock);
371 LPROC_SEQ_FOPS(ll_max_readahead_per_file_mb);
373 static int ll_max_read_ahead_whole_mb_seq_show(struct seq_file *m, void *v)
375 struct super_block *sb = m->private;
376 struct ll_sb_info *sbi = ll_s2sbi(sb);
380 spin_lock(&sbi->ll_lock);
381 pages_number = sbi->ll_ra_info.ra_max_read_ahead_whole_pages;
382 spin_unlock(&sbi->ll_lock);
384 mult = 1 << (20 - PAGE_SHIFT);
385 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
389 ll_max_read_ahead_whole_mb_seq_write(struct file *file,
390 const char __user *buffer,
391 size_t count, loff_t *off)
393 struct seq_file *m = file->private_data;
394 struct super_block *sb = m->private;
395 struct ll_sb_info *sbi = ll_s2sbi(sb);
399 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
403 pages_number >>= PAGE_SHIFT;
405 /* Cap this at the current max readahead window size, the readahead
406 * algorithm does this anyway so it's pointless to set it larger. */
407 if (pages_number < 0 ||
408 pages_number > sbi->ll_ra_info.ra_max_pages_per_file) {
409 int pages_shift = 20 - PAGE_SHIFT;
410 CERROR("%s: can't set max_read_ahead_whole_mb=%lu > "
411 "max_read_ahead_per_file_mb=%lu\n",
412 ll_get_fsname(sb, NULL, 0),
413 (unsigned long)pages_number >> pages_shift,
414 sbi->ll_ra_info.ra_max_pages_per_file >> pages_shift);
418 spin_lock(&sbi->ll_lock);
419 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = pages_number;
420 spin_unlock(&sbi->ll_lock);
423 LPROC_SEQ_FOPS(ll_max_read_ahead_whole_mb);
425 static int ll_max_cached_mb_seq_show(struct seq_file *m, void *v)
427 struct super_block *sb = m->private;
428 struct ll_sb_info *sbi = ll_s2sbi(sb);
429 struct cl_client_cache *cache = sbi->ll_cache;
430 int shift = 20 - PAGE_SHIFT;
434 max_cached_mb = cache->ccc_lru_max >> shift;
435 unused_mb = atomic_long_read(&cache->ccc_lru_left) >> shift;
436 seq_printf(m, "users: %d\n"
437 "max_cached_mb: %ld\n"
440 "reclaim_count: %u\n",
441 atomic_read(&cache->ccc_users),
443 max_cached_mb - unused_mb,
445 cache->ccc_lru_shrinkers);
450 ll_max_cached_mb_seq_write(struct file *file, const char __user *buffer,
451 size_t count, loff_t *off)
453 struct seq_file *m = file->private_data;
454 struct super_block *sb = m->private;
455 struct ll_sb_info *sbi = ll_s2sbi(sb);
456 struct cl_client_cache *cache = sbi->ll_cache;
466 if (count >= sizeof(kernbuf))
469 if (copy_from_user(kernbuf, buffer, count))
473 buffer += lprocfs_find_named_value(kernbuf, "max_cached_mb:", &count) -
475 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
479 pages_number >>= PAGE_SHIFT;
481 if (pages_number < 0 || pages_number > totalram_pages) {
482 CERROR("%s: can't set max cache more than %lu MB\n",
483 ll_get_fsname(sb, NULL, 0),
484 totalram_pages >> (20 - PAGE_SHIFT));
487 /* Allow enough cache so clients can make well-formed RPCs */
488 pages_number = max_t(long, pages_number, PTLRPC_MAX_BRW_PAGES);
490 spin_lock(&sbi->ll_lock);
491 diff = pages_number - cache->ccc_lru_max;
492 spin_unlock(&sbi->ll_lock);
494 /* easy - add more LRU slots. */
496 atomic_long_add(diff, &cache->ccc_lru_left);
500 env = cl_env_get(&refcheck);
508 /* reduce LRU budget from free slots. */
512 ov = atomic_long_read(&cache->ccc_lru_left);
516 nv = ov > diff ? ov - diff : 0;
517 rc = atomic_long_cmpxchg(&cache->ccc_lru_left, ov, nv);
518 if (likely(ov == rc)) {
528 if (sbi->ll_dt_exp == NULL) { /* being initialized */
533 /* difficult - have to ask OSCs to drop LRU slots. */
535 rc = obd_set_info_async(env, sbi->ll_dt_exp,
536 sizeof(KEY_CACHE_LRU_SHRINK),
537 KEY_CACHE_LRU_SHRINK,
538 sizeof(tmp), &tmp, NULL);
542 cl_env_put(env, &refcheck);
546 spin_lock(&sbi->ll_lock);
547 cache->ccc_lru_max = pages_number;
548 spin_unlock(&sbi->ll_lock);
551 atomic_long_add(nrpages, &cache->ccc_lru_left);
555 LPROC_SEQ_FOPS(ll_max_cached_mb);
557 static int ll_checksum_seq_show(struct seq_file *m, void *v)
559 struct super_block *sb = m->private;
560 struct ll_sb_info *sbi = ll_s2sbi(sb);
562 seq_printf(m, "%u\n", (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0);
566 static ssize_t ll_checksum_seq_write(struct file *file,
567 const char __user *buffer,
568 size_t count, loff_t *off)
570 struct seq_file *m = file->private_data;
571 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
579 rc = lprocfs_str_to_s64(buffer, count, &val);
583 sbi->ll_flags |= LL_SBI_CHECKSUM;
585 sbi->ll_flags &= ~LL_SBI_CHECKSUM;
587 rc = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
588 KEY_CHECKSUM, sizeof(val), &val, NULL);
590 CWARN("Failed to set OSC checksum flags: %d\n", rc);
594 LPROC_SEQ_FOPS(ll_checksum);
596 static int ll_rd_track_id(struct seq_file *m, enum stats_track_type type)
598 struct super_block *sb = m->private;
600 if (ll_s2sbi(sb)->ll_stats_track_type == type) {
601 seq_printf(m, "%d\n",
602 ll_s2sbi(sb)->ll_stats_track_id);
603 } else if (ll_s2sbi(sb)->ll_stats_track_type == STATS_TRACK_ALL) {
604 seq_puts(m, "0 (all)\n");
606 seq_puts(m, "untracked\n");
611 static int ll_wr_track_id(const char __user *buffer, unsigned long count,
612 void *data, enum stats_track_type type)
614 struct super_block *sb = data;
618 rc = lprocfs_str_to_s64(buffer, count, &pid);
621 if (pid > INT_MAX || pid < 0)
624 ll_s2sbi(sb)->ll_stats_track_id = pid;
626 ll_s2sbi(sb)->ll_stats_track_type = STATS_TRACK_ALL;
628 ll_s2sbi(sb)->ll_stats_track_type = type;
629 lprocfs_clear_stats(ll_s2sbi(sb)->ll_stats);
633 static int ll_track_pid_seq_show(struct seq_file *m, void *v)
635 return ll_rd_track_id(m, STATS_TRACK_PID);
638 static ssize_t ll_track_pid_seq_write(struct file *file,
639 const char __user *buffer,
640 size_t count, loff_t *off)
642 struct seq_file *seq = file->private_data;
643 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PID);
645 LPROC_SEQ_FOPS(ll_track_pid);
647 static int ll_track_ppid_seq_show(struct seq_file *m, void *v)
649 return ll_rd_track_id(m, STATS_TRACK_PPID);
652 static ssize_t ll_track_ppid_seq_write(struct file *file,
653 const char __user *buffer,
654 size_t count, loff_t *off)
656 struct seq_file *seq = file->private_data;
657 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PPID);
659 LPROC_SEQ_FOPS(ll_track_ppid);
661 static int ll_track_gid_seq_show(struct seq_file *m, void *v)
663 return ll_rd_track_id(m, STATS_TRACK_GID);
666 static ssize_t ll_track_gid_seq_write(struct file *file,
667 const char __user *buffer,
668 size_t count, loff_t *off)
670 struct seq_file *seq = file->private_data;
671 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_GID);
673 LPROC_SEQ_FOPS(ll_track_gid);
675 static int ll_statahead_max_seq_show(struct seq_file *m, void *v)
677 struct super_block *sb = m->private;
678 struct ll_sb_info *sbi = ll_s2sbi(sb);
680 seq_printf(m, "%u\n", sbi->ll_sa_max);
684 static ssize_t ll_statahead_max_seq_write(struct file *file,
685 const char __user *buffer,
686 size_t count, loff_t *off)
688 struct seq_file *m = file->private_data;
689 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
693 rc = lprocfs_str_to_s64(buffer, count, &val);
697 if (val >= 0 && val <= LL_SA_RPC_MAX)
698 sbi->ll_sa_max = val;
700 CERROR("Bad statahead_max value %lld. Valid values are in "
701 "the range [0, %d]\n", val, LL_SA_RPC_MAX);
705 LPROC_SEQ_FOPS(ll_statahead_max);
707 static int ll_statahead_agl_seq_show(struct seq_file *m, void *v)
709 struct super_block *sb = m->private;
710 struct ll_sb_info *sbi = ll_s2sbi(sb);
712 seq_printf(m, "%u\n",
713 sbi->ll_flags & LL_SBI_AGL_ENABLED ? 1 : 0);
717 static ssize_t ll_statahead_agl_seq_write(struct file *file,
718 const char __user *buffer,
719 size_t count, loff_t *off)
721 struct seq_file *m = file->private_data;
722 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
726 rc = lprocfs_str_to_s64(buffer, count, &val);
731 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
733 sbi->ll_flags &= ~LL_SBI_AGL_ENABLED;
737 LPROC_SEQ_FOPS(ll_statahead_agl);
739 static int ll_statahead_stats_seq_show(struct seq_file *m, void *v)
741 struct super_block *sb = m->private;
742 struct ll_sb_info *sbi = ll_s2sbi(sb);
744 seq_printf(m, "statahead total: %u\n"
745 "statahead wrong: %u\n"
747 atomic_read(&sbi->ll_sa_total),
748 atomic_read(&sbi->ll_sa_wrong),
749 atomic_read(&sbi->ll_agl_total));
752 LPROC_SEQ_FOPS_RO(ll_statahead_stats);
754 static int ll_lazystatfs_seq_show(struct seq_file *m, void *v)
756 struct super_block *sb = m->private;
757 struct ll_sb_info *sbi = ll_s2sbi(sb);
759 seq_printf(m, "%u\n",
760 (sbi->ll_flags & LL_SBI_LAZYSTATFS) ? 1 : 0);
764 static ssize_t ll_lazystatfs_seq_write(struct file *file,
765 const char __user *buffer,
766 size_t count, loff_t *off)
768 struct seq_file *m = file->private_data;
769 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
773 rc = lprocfs_str_to_s64(buffer, count, &val);
778 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
780 sbi->ll_flags &= ~LL_SBI_LAZYSTATFS;
784 LPROC_SEQ_FOPS(ll_lazystatfs);
786 static int ll_max_easize_seq_show(struct seq_file *m, void *v)
788 struct super_block *sb = m->private;
789 struct ll_sb_info *sbi = ll_s2sbi(sb);
793 rc = ll_get_max_mdsize(sbi, &ealen);
797 seq_printf(m, "%u\n", ealen);
800 LPROC_SEQ_FOPS_RO(ll_max_easize);
803 * Get default_easize.
805 * \see client_obd::cl_default_mds_easize
807 * \param[in] m seq_file handle
808 * \param[in] v unused for single entry
810 * \retval 0 on success
811 * \retval negative negated errno on failure
813 static int ll_default_easize_seq_show(struct seq_file *m, void *v)
815 struct super_block *sb = m->private;
816 struct ll_sb_info *sbi = ll_s2sbi(sb);
820 rc = ll_get_default_mdsize(sbi, &ealen);
824 seq_printf(m, "%u\n", ealen);
829 * Set default_easize.
831 * Range checking on the passed value is handled by
832 * ll_set_default_mdsize().
834 * \see client_obd::cl_default_mds_easize
836 * \param[in] file proc file
837 * \param[in] buffer string passed from user space
838 * \param[in] count \a buffer length
839 * \param[in] off unused for single entry
841 * \retval positive \a count on success
842 * \retval negative negated errno on failure
844 static ssize_t ll_default_easize_seq_write(struct file *file,
845 const char __user *buffer,
846 size_t count, loff_t *unused)
848 struct seq_file *seq = file->private_data;
849 struct super_block *sb = (struct super_block *)seq->private;
850 struct ll_sb_info *sbi = ll_s2sbi(sb);
857 rc = lprocfs_str_to_s64(buffer, count, &val);
860 if (val < 0 || val > INT_MAX)
863 rc = ll_set_default_mdsize(sbi, val);
869 LPROC_SEQ_FOPS(ll_default_easize);
871 static int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
873 const char *str[] = LL_SBI_FLAGS;
874 struct super_block *sb = m->private;
875 int flags = ll_s2sbi(sb)->ll_flags;
879 if (ARRAY_SIZE(str) <= i) {
880 CERROR("%s: Revise array LL_SBI_FLAGS to match sbi "
881 "flags please.\n", ll_get_fsname(sb, NULL, 0));
886 seq_printf(m, "%s ", str[i]);
890 seq_printf(m, "\b\n");
893 LPROC_SEQ_FOPS_RO(ll_sbi_flags);
895 static int ll_fast_read_seq_show(struct seq_file *m, void *v)
897 struct super_block *sb = m->private;
898 struct ll_sb_info *sbi = ll_s2sbi(sb);
900 seq_printf(m, "%u\n", !!(sbi->ll_flags & LL_SBI_FAST_READ));
905 ll_fast_read_seq_write(struct file *file, const char __user *buffer,
906 size_t count, loff_t *off)
908 struct seq_file *m = file->private_data;
909 struct super_block *sb = m->private;
910 struct ll_sb_info *sbi = ll_s2sbi(sb);
914 rc = lprocfs_str_to_s64(buffer, count, &val);
918 spin_lock(&sbi->ll_lock);
920 sbi->ll_flags |= LL_SBI_FAST_READ;
922 sbi->ll_flags &= ~LL_SBI_FAST_READ;
923 spin_unlock(&sbi->ll_lock);
927 LPROC_SEQ_FOPS(ll_fast_read);
929 static int ll_pio_seq_show(struct seq_file *m, void *v)
931 struct super_block *sb = m->private;
932 struct ll_sb_info *sbi = ll_s2sbi(sb);
934 seq_printf(m, "%u\n", !!(sbi->ll_flags & LL_SBI_PIO));
938 static ssize_t ll_pio_seq_write(struct file *file, const char __user *buffer,
939 size_t count, loff_t *off)
941 struct seq_file *m = file->private_data;
942 struct super_block *sb = m->private;
943 struct ll_sb_info *sbi = ll_s2sbi(sb);
947 rc = lprocfs_str_to_s64(buffer, count, &val);
951 spin_lock(&sbi->ll_lock);
953 sbi->ll_flags |= LL_SBI_PIO;
955 sbi->ll_flags &= ~LL_SBI_PIO;
956 spin_unlock(&sbi->ll_lock);
960 LPROC_SEQ_FOPS(ll_pio);
962 static int ll_unstable_stats_seq_show(struct seq_file *m, void *v)
964 struct super_block *sb = m->private;
965 struct ll_sb_info *sbi = ll_s2sbi(sb);
966 struct cl_client_cache *cache = sbi->ll_cache;
970 pages = atomic_long_read(&cache->ccc_unstable_nr);
971 mb = (pages * PAGE_SIZE) >> 20;
973 seq_printf(m, "unstable_check: %8d\n"
974 "unstable_pages: %12ld\n"
975 "unstable_mb: %8d\n",
976 cache->ccc_unstable_check, pages, mb);
980 static ssize_t ll_unstable_stats_seq_write(struct file *file,
981 const char __user *buffer,
982 size_t count, loff_t *unused)
984 struct seq_file *seq = file->private_data;
985 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)seq->private);
992 if (count >= sizeof(kernbuf))
995 if (copy_from_user(kernbuf, buffer, count))
999 buffer += lprocfs_find_named_value(kernbuf, "unstable_check:", &count) -
1001 rc = lprocfs_str_to_s64(buffer, count, &val);
1005 /* borrow lru lock to set the value */
1006 spin_lock(&sbi->ll_cache->ccc_lru_lock);
1007 sbi->ll_cache->ccc_unstable_check = !!val;
1008 spin_unlock(&sbi->ll_cache->ccc_lru_lock);
1012 LPROC_SEQ_FOPS(ll_unstable_stats);
1014 static int ll_root_squash_seq_show(struct seq_file *m, void *v)
1016 struct super_block *sb = m->private;
1017 struct ll_sb_info *sbi = ll_s2sbi(sb);
1018 struct root_squash_info *squash = &sbi->ll_squash;
1020 seq_printf(m, "%u:%u\n", squash->rsi_uid, squash->rsi_gid);
1024 static ssize_t ll_root_squash_seq_write(struct file *file,
1025 const char __user *buffer,
1026 size_t count, loff_t *off)
1028 struct seq_file *m = file->private_data;
1029 struct super_block *sb = m->private;
1030 struct ll_sb_info *sbi = ll_s2sbi(sb);
1031 struct root_squash_info *squash = &sbi->ll_squash;
1033 return lprocfs_wr_root_squash(buffer, count, squash,
1034 ll_get_fsname(sb, NULL, 0));
1036 LPROC_SEQ_FOPS(ll_root_squash);
1038 static int ll_nosquash_nids_seq_show(struct seq_file *m, void *v)
1040 struct super_block *sb = m->private;
1041 struct ll_sb_info *sbi = ll_s2sbi(sb);
1042 struct root_squash_info *squash = &sbi->ll_squash;
1045 down_read(&squash->rsi_sem);
1046 if (!list_empty(&squash->rsi_nosquash_nids)) {
1047 len = cfs_print_nidlist(m->buf + m->count, m->size - m->count,
1048 &squash->rsi_nosquash_nids);
1052 seq_puts(m, "NONE\n");
1054 up_read(&squash->rsi_sem);
1059 static ssize_t ll_nosquash_nids_seq_write(struct file *file,
1060 const char __user *buffer,
1061 size_t count, loff_t *off)
1063 struct seq_file *m = file->private_data;
1064 struct super_block *sb = m->private;
1065 struct ll_sb_info *sbi = ll_s2sbi(sb);
1066 struct root_squash_info *squash = &sbi->ll_squash;
1069 rc = lprocfs_wr_nosquash_nids(buffer, count, squash,
1070 ll_get_fsname(sb, NULL, 0));
1074 ll_compute_rootsquash_state(sbi);
1078 LPROC_SEQ_FOPS(ll_nosquash_nids);
1080 struct lprocfs_vars lprocfs_llite_obd_vars[] = {
1082 .fops = &ll_sb_uuid_fops },
1084 .fops = &ll_fstype_fops },
1086 .fops = &ll_site_stats_fops },
1087 { .name = "blocksize",
1088 .fops = &ll_blksize_fops },
1089 { .name = "stat_blocksize",
1090 .fops = &ll_stat_blksize_fops },
1091 { .name = "kbytestotal",
1092 .fops = &ll_kbytestotal_fops },
1093 { .name = "kbytesfree",
1094 .fops = &ll_kbytesfree_fops },
1095 { .name = "kbytesavail",
1096 .fops = &ll_kbytesavail_fops },
1097 { .name = "filestotal",
1098 .fops = &ll_filestotal_fops },
1099 { .name = "filesfree",
1100 .fops = &ll_filesfree_fops },
1101 { .name = "client_type",
1102 .fops = &ll_client_type_fops },
1103 { .name = "max_read_ahead_mb",
1104 .fops = &ll_max_readahead_mb_fops },
1105 { .name = "max_read_ahead_per_file_mb",
1106 .fops = &ll_max_readahead_per_file_mb_fops },
1107 { .name = "max_read_ahead_whole_mb",
1108 .fops = &ll_max_read_ahead_whole_mb_fops },
1109 { .name = "max_cached_mb",
1110 .fops = &ll_max_cached_mb_fops },
1111 { .name = "checksum_pages",
1112 .fops = &ll_checksum_fops },
1113 { .name = "stats_track_pid",
1114 .fops = &ll_track_pid_fops },
1115 { .name = "stats_track_ppid",
1116 .fops = &ll_track_ppid_fops },
1117 { .name = "stats_track_gid",
1118 .fops = &ll_track_gid_fops },
1119 { .name = "statahead_max",
1120 .fops = &ll_statahead_max_fops },
1121 { .name = "statahead_agl",
1122 .fops = &ll_statahead_agl_fops },
1123 { .name = "statahead_stats",
1124 .fops = &ll_statahead_stats_fops },
1125 { .name = "lazystatfs",
1126 .fops = &ll_lazystatfs_fops },
1127 { .name = "max_easize",
1128 .fops = &ll_max_easize_fops },
1129 { .name = "default_easize",
1130 .fops = &ll_default_easize_fops },
1131 { .name = "sbi_flags",
1132 .fops = &ll_sbi_flags_fops },
1133 { .name = "xattr_cache",
1134 .fops = &ll_xattr_cache_fops },
1135 { .name = "unstable_stats",
1136 .fops = &ll_unstable_stats_fops },
1137 { .name = "root_squash",
1138 .fops = &ll_root_squash_fops },
1139 { .name = "nosquash_nids",
1140 .fops = &ll_nosquash_nids_fops },
1141 { .name = "fast_read",
1142 .fops = &ll_fast_read_fops, },
1144 .fops = &ll_pio_fops, },
1148 #define MAX_STRING_SIZE 128
1150 static const struct llite_file_opcode {
1154 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
1155 /* file operation */
1156 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
1157 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
1158 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1160 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1162 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
1164 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
1166 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
1167 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
1168 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
1169 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
1170 { LPROC_LL_FAULT, LPROCFS_TYPE_REGS, "page_fault" },
1171 { LPROC_LL_MKWRITE, LPROCFS_TYPE_REGS, "page_mkwrite" },
1172 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
1173 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
1174 { LPROC_LL_READDIR, LPROCFS_TYPE_REGS, "readdir" },
1175 /* inode operation */
1176 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
1177 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "truncate" },
1178 { LPROC_LL_FLOCK, LPROCFS_TYPE_REGS, "flock" },
1179 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
1180 /* dir inode operation */
1181 { LPROC_LL_CREATE, LPROCFS_TYPE_REGS, "create" },
1182 { LPROC_LL_LINK, LPROCFS_TYPE_REGS, "link" },
1183 { LPROC_LL_UNLINK, LPROCFS_TYPE_REGS, "unlink" },
1184 { LPROC_LL_SYMLINK, LPROCFS_TYPE_REGS, "symlink" },
1185 { LPROC_LL_MKDIR, LPROCFS_TYPE_REGS, "mkdir" },
1186 { LPROC_LL_RMDIR, LPROCFS_TYPE_REGS, "rmdir" },
1187 { LPROC_LL_MKNOD, LPROCFS_TYPE_REGS, "mknod" },
1188 { LPROC_LL_RENAME, LPROCFS_TYPE_REGS, "rename" },
1189 /* special inode operation */
1190 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
1191 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
1192 { LPROC_LL_SETXATTR, LPROCFS_TYPE_REGS, "setxattr" },
1193 { LPROC_LL_GETXATTR, LPROCFS_TYPE_REGS, "getxattr" },
1194 { LPROC_LL_GETXATTR_HITS, LPROCFS_TYPE_REGS, "getxattr_hits" },
1195 { LPROC_LL_LISTXATTR, LPROCFS_TYPE_REGS, "listxattr" },
1196 { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_REGS, "removexattr" },
1197 { LPROC_LL_INODE_PERM, LPROCFS_TYPE_REGS, "inode_permission" },
1200 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
1204 if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
1205 lprocfs_counter_add(sbi->ll_stats, op, count);
1206 else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
1207 sbi->ll_stats_track_id == current->pid)
1208 lprocfs_counter_add(sbi->ll_stats, op, count);
1209 else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
1210 sbi->ll_stats_track_id == current->parent->pid)
1211 lprocfs_counter_add(sbi->ll_stats, op, count);
1212 else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
1213 sbi->ll_stats_track_id ==
1214 from_kgid(&init_user_ns, current_gid()))
1215 lprocfs_counter_add(sbi->ll_stats, op, count);
1217 EXPORT_SYMBOL(ll_stats_ops_tally);
1219 static const char *ra_stat_string[] = {
1220 [RA_STAT_HIT] = "hits",
1221 [RA_STAT_MISS] = "misses",
1222 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
1223 [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
1224 [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page",
1225 [RA_STAT_FAILED_MATCH] = "failed lock match",
1226 [RA_STAT_DISCARDED] = "read but discarded",
1227 [RA_STAT_ZERO_LEN] = "zero length file",
1228 [RA_STAT_ZERO_WINDOW] = "zero size window",
1229 [RA_STAT_EOF] = "read-ahead to EOF",
1230 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
1231 [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",
1232 [RA_STAT_FAILED_REACH_END] = "failed to reach end"
1235 LPROC_SEQ_FOPS_RO_TYPE(llite, name);
1236 LPROC_SEQ_FOPS_RO_TYPE(llite, uuid);
1238 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
1239 struct super_block *sb, char *osc, char *mdc)
1241 struct lprocfs_vars lvars[2];
1242 struct lustre_sb_info *lsi = s2lsi(sb);
1243 struct ll_sb_info *sbi = ll_s2sbi(sb);
1244 struct obd_device *obd;
1245 struct proc_dir_entry *dir;
1246 char name[MAX_STRING_SIZE + 1], *ptr;
1247 int err, id, len, rc;
1250 memset(lvars, 0, sizeof(lvars));
1252 name[MAX_STRING_SIZE] = '\0';
1253 lvars[0].name = name;
1255 LASSERT(sbi != NULL);
1256 LASSERT(mdc != NULL);
1257 LASSERT(osc != NULL);
1260 len = strlen(lsi->lsi_lmd->lmd_profile);
1261 ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
1262 if (ptr && (strcmp(ptr, "-client") == 0))
1266 snprintf(name, MAX_STRING_SIZE, "%.*s-%p", len,
1267 lsi->lsi_lmd->lmd_profile, sb);
1269 sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
1270 if (IS_ERR(sbi->ll_proc_root)) {
1271 err = PTR_ERR(sbi->ll_proc_root);
1272 sbi->ll_proc_root = NULL;
1276 rc = lprocfs_seq_create(sbi->ll_proc_root, "dump_page_cache", 0444,
1277 &vvp_dump_pgcache_file_ops, sbi);
1279 CWARN("Error adding the dump_page_cache file\n");
1281 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats", 0644,
1282 &ll_rw_extents_stats_fops, sbi);
1284 CWARN("Error adding the extent_stats file\n");
1286 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats_per_process",
1287 0644, &ll_rw_extents_stats_pp_fops, sbi);
1289 CWARN("Error adding the extents_stats_per_process file\n");
1291 rc = lprocfs_seq_create(sbi->ll_proc_root, "offset_stats", 0644,
1292 &ll_rw_offset_stats_fops, sbi);
1294 CWARN("Error adding the offset_stats file\n");
1296 /* File operations stats */
1297 sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
1298 LPROCFS_STATS_FLAG_NONE);
1299 if (sbi->ll_stats == NULL)
1300 GOTO(out, err = -ENOMEM);
1301 /* do counter init */
1302 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
1303 __u32 type = llite_opcode_table[id].type;
1305 if (type & LPROCFS_TYPE_REGS)
1307 else if (type & LPROCFS_TYPE_BYTES)
1309 else if (type & LPROCFS_TYPE_PAGES)
1311 lprocfs_counter_init(sbi->ll_stats,
1312 llite_opcode_table[id].opcode,
1313 (type & LPROCFS_CNTR_AVGMINMAX),
1314 llite_opcode_table[id].opname, ptr);
1316 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats);
1320 sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
1321 LPROCFS_STATS_FLAG_NONE);
1322 if (sbi->ll_ra_stats == NULL)
1323 GOTO(out, err = -ENOMEM);
1325 for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
1326 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
1327 ra_stat_string[id], "pages");
1328 err = lprocfs_register_stats(sbi->ll_proc_root, "read_ahead_stats",
1334 err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_llite_obd_vars, sb);
1339 obd = class_name2obd(mdc);
1341 LASSERT(obd != NULL);
1342 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1343 LASSERT(obd->obd_type->typ_name != NULL);
1345 dir = proc_mkdir(obd->obd_type->typ_name, sbi->ll_proc_root);
1347 GOTO(out, err = -ENOMEM);
1349 snprintf(name, MAX_STRING_SIZE, "common_name");
1350 lvars[0].fops = &llite_name_fops;
1351 err = lprocfs_add_vars(dir, lvars, obd);
1355 snprintf(name, MAX_STRING_SIZE, "uuid");
1356 lvars[0].fops = &llite_uuid_fops;
1357 err = lprocfs_add_vars(dir, lvars, obd);
1362 obd = class_name2obd(osc);
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);
1383 lprocfs_remove(&sbi->ll_proc_root);
1384 lprocfs_free_stats(&sbi->ll_ra_stats);
1385 lprocfs_free_stats(&sbi->ll_stats);
1390 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
1392 if (sbi->ll_proc_root) {
1393 lprocfs_remove(&sbi->ll_proc_root);
1394 lprocfs_free_stats(&sbi->ll_ra_stats);
1395 lprocfs_free_stats(&sbi->ll_stats);
1398 #undef MAX_STRING_SIZE
1400 #define pct(a,b) (b ? a * 100 / b : 0)
1402 static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
1403 struct seq_file *seq, int which)
1405 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
1406 unsigned long start, end, r, w;
1407 char *unitp = "KMGTPEZY";
1409 struct per_process_info *pp_info = &io_extents->pp_extents[which];
1415 for(i = 0; i < LL_HIST_MAX; i++) {
1416 read_tot += pp_info->pp_r_hist.oh_buckets[i];
1417 write_tot += pp_info->pp_w_hist.oh_buckets[i];
1420 for(i = 0; i < LL_HIST_MAX; i++) {
1421 r = pp_info->pp_r_hist.oh_buckets[i];
1422 w = pp_info->pp_w_hist.oh_buckets[i];
1425 end = 1 << (i + LL_HIST_START - units);
1426 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu | "
1427 "%14lu %4lu %4lu\n", start, *unitp, end, *unitp,
1428 (i == LL_HIST_MAX - 1) ? '+' : ' ',
1429 r, pct(r, read_tot), pct(read_cum, read_tot),
1430 w, pct(w, write_tot), pct(write_cum, write_tot));
1432 if (start == 1<<10) {
1437 if (read_cum == read_tot && write_cum == write_tot)
1442 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
1444 struct timespec64 now;
1445 struct ll_sb_info *sbi = seq->private;
1446 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1449 ktime_get_real_ts64(&now);
1451 if (!sbi->ll_rw_stats_on) {
1452 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
1455 seq_printf(seq, "snapshot_time: %llu.%09lu (secs.nsecs)\n",
1456 (s64)now.tv_sec, now.tv_nsec);
1457 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1458 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1459 "extents", "calls", "%", "cum%",
1460 "calls", "%", "cum%");
1461 spin_lock(&sbi->ll_pp_extent_lock);
1462 for (k = 0; k < LL_PROCESS_HIST_MAX; k++) {
1463 if (io_extents->pp_extents[k].pid != 0) {
1464 seq_printf(seq, "\nPID: %d\n",
1465 io_extents->pp_extents[k].pid);
1466 ll_display_extents_info(io_extents, seq, k);
1469 spin_unlock(&sbi->ll_pp_extent_lock);
1473 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
1474 const char __user *buf,
1478 struct seq_file *seq = file->private_data;
1479 struct ll_sb_info *sbi = seq->private;
1480 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1487 value = ll_stats_pid_write(buf, len);
1490 sbi->ll_rw_stats_on = 0;
1492 sbi->ll_rw_stats_on = 1;
1494 spin_lock(&sbi->ll_pp_extent_lock);
1495 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1496 io_extents->pp_extents[i].pid = 0;
1497 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1498 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1500 spin_unlock(&sbi->ll_pp_extent_lock);
1504 LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
1506 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
1508 struct timespec64 now;
1509 struct ll_sb_info *sbi = seq->private;
1510 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1512 ktime_get_real_ts64(&now);
1514 if (!sbi->ll_rw_stats_on) {
1515 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
1518 seq_printf(seq, "snapshot_time: %llu.%09lu (secs.nsecs)\n",
1519 (s64)now.tv_sec, now.tv_nsec);
1521 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1522 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1523 "extents", "calls", "%", "cum%",
1524 "calls", "%", "cum%");
1525 spin_lock(&sbi->ll_lock);
1526 ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
1527 spin_unlock(&sbi->ll_lock);
1532 static ssize_t ll_rw_extents_stats_seq_write(struct file *file,
1533 const char __user *buf,
1534 size_t len, loff_t *off)
1536 struct seq_file *seq = file->private_data;
1537 struct ll_sb_info *sbi = seq->private;
1538 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1545 value = ll_stats_pid_write(buf, len);
1548 sbi->ll_rw_stats_on = 0;
1550 sbi->ll_rw_stats_on = 1;
1552 spin_lock(&sbi->ll_pp_extent_lock);
1553 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
1554 io_extents->pp_extents[i].pid = 0;
1555 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1556 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1558 spin_unlock(&sbi->ll_pp_extent_lock);
1562 LPROC_SEQ_FOPS(ll_rw_extents_stats);
1564 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
1565 struct ll_file_data *file, loff_t pos,
1566 size_t count, int rw)
1569 struct ll_rw_process_info *process;
1570 struct ll_rw_process_info *offset;
1571 int *off_count = &sbi->ll_rw_offset_entry_count;
1572 int *process_count = &sbi->ll_offset_process_count;
1573 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1575 if(!sbi->ll_rw_stats_on)
1577 process = sbi->ll_rw_process_info;
1578 offset = sbi->ll_rw_offset_info;
1580 spin_lock(&sbi->ll_pp_extent_lock);
1581 /* Extent statistics */
1582 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1583 if(io_extents->pp_extents[i].pid == pid) {
1591 sbi->ll_extent_process_count =
1592 (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1593 cur = sbi->ll_extent_process_count;
1594 io_extents->pp_extents[cur].pid = pid;
1595 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1596 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1599 for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
1600 (i < (LL_HIST_MAX - 1)); i++);
1602 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1603 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1605 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1606 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1608 spin_unlock(&sbi->ll_pp_extent_lock);
1610 spin_lock(&sbi->ll_process_lock);
1611 /* Offset statistics */
1612 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1613 if (process[i].rw_pid == pid) {
1614 if (process[i].rw_last_file != file) {
1615 process[i].rw_range_start = pos;
1616 process[i].rw_last_file_pos = pos + count;
1617 process[i].rw_smallest_extent = count;
1618 process[i].rw_largest_extent = count;
1619 process[i].rw_offset = 0;
1620 process[i].rw_last_file = file;
1621 spin_unlock(&sbi->ll_process_lock);
1624 if (process[i].rw_last_file_pos != pos) {
1626 (*off_count + 1) % LL_OFFSET_HIST_MAX;
1627 offset[*off_count].rw_op = process[i].rw_op;
1628 offset[*off_count].rw_pid = pid;
1629 offset[*off_count].rw_range_start =
1630 process[i].rw_range_start;
1631 offset[*off_count].rw_range_end =
1632 process[i].rw_last_file_pos;
1633 offset[*off_count].rw_smallest_extent =
1634 process[i].rw_smallest_extent;
1635 offset[*off_count].rw_largest_extent =
1636 process[i].rw_largest_extent;
1637 offset[*off_count].rw_offset =
1638 process[i].rw_offset;
1639 process[i].rw_op = rw;
1640 process[i].rw_range_start = pos;
1641 process[i].rw_smallest_extent = count;
1642 process[i].rw_largest_extent = count;
1643 process[i].rw_offset = pos -
1644 process[i].rw_last_file_pos;
1646 if(process[i].rw_smallest_extent > count)
1647 process[i].rw_smallest_extent = count;
1648 if(process[i].rw_largest_extent < count)
1649 process[i].rw_largest_extent = count;
1650 process[i].rw_last_file_pos = pos + count;
1651 spin_unlock(&sbi->ll_process_lock);
1655 *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
1656 process[*process_count].rw_pid = pid;
1657 process[*process_count].rw_op = rw;
1658 process[*process_count].rw_range_start = pos;
1659 process[*process_count].rw_last_file_pos = pos + count;
1660 process[*process_count].rw_smallest_extent = count;
1661 process[*process_count].rw_largest_extent = count;
1662 process[*process_count].rw_offset = 0;
1663 process[*process_count].rw_last_file = file;
1664 spin_unlock(&sbi->ll_process_lock);
1667 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1669 struct timespec64 now;
1670 struct ll_sb_info *sbi = seq->private;
1671 struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
1672 struct ll_rw_process_info *process = sbi->ll_rw_process_info;
1675 ktime_get_real_ts64(&now);
1677 if (!sbi->ll_rw_stats_on) {
1678 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
1681 spin_lock(&sbi->ll_process_lock);
1683 seq_printf(seq, "snapshot_time: %llu.%09lu (secs.nsecs)\n",
1684 (s64)now.tv_sec, now.tv_nsec);
1685 seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
1686 "R/W", "PID", "RANGE START", "RANGE END",
1687 "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
1689 /* We stored the discontiguous offsets here; print them first */
1690 for (i = 0; i < LL_OFFSET_HIST_MAX; i++) {
1691 if (offset[i].rw_pid != 0)
1693 "%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1694 offset[i].rw_op == READ ? 'R' : 'W',
1696 offset[i].rw_range_start,
1697 offset[i].rw_range_end,
1698 (unsigned long)offset[i].rw_smallest_extent,
1699 (unsigned long)offset[i].rw_largest_extent,
1700 offset[i].rw_offset);
1703 /* Then print the current offsets for each process */
1704 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1705 if (process[i].rw_pid != 0)
1707 "%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1708 process[i].rw_op == READ ? 'R' : 'W',
1710 process[i].rw_range_start,
1711 process[i].rw_last_file_pos,
1712 (unsigned long)process[i].rw_smallest_extent,
1713 (unsigned long)process[i].rw_largest_extent,
1714 process[i].rw_offset);
1716 spin_unlock(&sbi->ll_process_lock);
1721 static ssize_t ll_rw_offset_stats_seq_write(struct file *file,
1722 const char __user *buf,
1723 size_t len, loff_t *off)
1725 struct seq_file *seq = file->private_data;
1726 struct ll_sb_info *sbi = seq->private;
1727 struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
1728 struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
1734 value = ll_stats_pid_write(buf, len);
1737 sbi->ll_rw_stats_on = 0;
1739 sbi->ll_rw_stats_on = 1;
1741 spin_lock(&sbi->ll_process_lock);
1742 sbi->ll_offset_process_count = 0;
1743 sbi->ll_rw_offset_entry_count = 0;
1744 memset(process_info, 0, sizeof(struct ll_rw_process_info) *
1745 LL_PROCESS_HIST_MAX);
1746 memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
1747 LL_OFFSET_HIST_MAX);
1748 spin_unlock(&sbi->ll_process_lock);
1754 * ll_stats_pid_write() - Determine if stats collection should be enabled
1755 * @buf: Buffer containing the data written
1756 * @len: Number of bytes in the buffer
1758 * Several proc files begin collecting stats when a value is written, and stop
1759 * collecting when either '0' or 'disable' is written. This function checks the
1760 * written value to see if collection should be enabled or disabled.
1762 * Return: If '0' or 'disable' is provided, 0 is returned. If the text
1763 * equivalent of a number is written, that number is returned. Otherwise,
1764 * 1 is returned. Non-zero return values indicate collection should be enabled.
1766 static __s64 ll_stats_pid_write(const char __user *buf, size_t len)
1772 rc = lprocfs_str_to_s64(buf, len, &value);
1774 if (rc < 0 && len < sizeof(kernbuf)) {
1776 if (copy_from_user(kernbuf, buf, len))
1780 if (kernbuf[len - 1] == '\n')
1781 kernbuf[len - 1] = 0;
1783 if (strncasecmp(kernbuf, "disable", 7) == 0)
1790 LPROC_SEQ_FOPS(ll_rw_offset_stats);
1791 #endif /* CONFIG_PROC_FS */