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, 2017, 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;
47 static struct kobject *llite_kobj;
49 int llite_tunables_register(void)
53 proc_lustre_fs_root = lprocfs_register("llite", proc_lustre_root,
55 if (IS_ERR(proc_lustre_fs_root)) {
56 rc = PTR_ERR(proc_lustre_fs_root);
57 CERROR("cannot register '/proc/fs/lustre/llite': rc = %d\n",
59 proc_lustre_fs_root = NULL;
63 llite_kobj = class_setup_tunables("llite");
64 if (IS_ERR(llite_kobj)) {
65 rc = PTR_ERR(llite_kobj);
72 void llite_tunables_unregister(void)
75 kobject_put(llite_kobj);
77 lprocfs_remove(&proc_lustre_fs_root);
81 /* /proc/lustre/llite mount point registration */
82 static const struct file_operations ll_rw_extents_stats_fops;
83 static const struct file_operations ll_rw_extents_stats_pp_fops;
84 static const struct file_operations ll_rw_offset_stats_fops;
85 static __s64 ll_stats_pid_write(const char __user *buf, size_t len);
87 static ssize_t blocksize_show(struct kobject *kobj, struct attribute *attr,
90 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
92 struct obd_statfs osfs;
95 rc = ll_statfs_internal(sbi, &osfs, OBD_STATFS_NODELAY);
99 return sprintf(buf, "%u\n", osfs.os_bsize);
101 LUSTRE_RO_ATTR(blocksize);
103 static int ll_stat_blksize_seq_show(struct seq_file *m, void *v)
105 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
107 seq_printf(m, "%u\n", sbi->ll_stat_blksize);
112 static ssize_t ll_stat_blksize_seq_write(struct file *file,
113 const char __user *buffer,
114 size_t count, loff_t *off)
116 struct seq_file *m = file->private_data;
117 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
121 rc = kstrtouint_from_user(buffer, count, 0, &val);
125 if (val != 0 && (val < PAGE_SIZE || (val & (val - 1))) != 0)
128 sbi->ll_stat_blksize = val;
132 LPROC_SEQ_FOPS(ll_stat_blksize);
134 static ssize_t kbytestotal_show(struct kobject *kobj, struct attribute *attr,
137 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
139 struct obd_statfs osfs;
144 rc = ll_statfs_internal(sbi, &osfs, OBD_STATFS_NODELAY);
148 blk_size = osfs.os_bsize >> 10;
149 result = osfs.os_blocks;
151 while (blk_size >>= 1)
154 return sprintf(buf, "%llu\n", result);
156 LUSTRE_RO_ATTR(kbytestotal);
158 static ssize_t kbytesfree_show(struct kobject *kobj, struct attribute *attr,
161 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
163 struct obd_statfs osfs;
168 rc = ll_statfs_internal(sbi, &osfs, OBD_STATFS_NODELAY);
172 blk_size = osfs.os_bsize >> 10;
173 result = osfs.os_bfree;
175 while (blk_size >>= 1)
178 return sprintf(buf, "%llu\n", result);
180 LUSTRE_RO_ATTR(kbytesfree);
182 static ssize_t kbytesavail_show(struct kobject *kobj, struct attribute *attr,
185 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
187 struct obd_statfs osfs;
192 rc = ll_statfs_internal(sbi, &osfs, OBD_STATFS_NODELAY);
196 blk_size = osfs.os_bsize >> 10;
197 result = osfs.os_bavail;
199 while (blk_size >>= 1)
202 return sprintf(buf, "%llu\n", result);
204 LUSTRE_RO_ATTR(kbytesavail);
206 static int ll_filestotal_seq_show(struct seq_file *m, void *v)
208 struct super_block *sb = m->private;
209 struct obd_statfs osfs;
213 rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_NODELAY);
215 seq_printf(m, "%llu\n", osfs.os_files);
218 LPROC_SEQ_FOPS_RO(ll_filestotal);
220 static int ll_filesfree_seq_show(struct seq_file *m, void *v)
222 struct super_block *sb = m->private;
223 struct obd_statfs osfs;
227 rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_NODELAY);
229 seq_printf(m, "%llu\n", osfs.os_ffree);
232 LPROC_SEQ_FOPS_RO(ll_filesfree);
234 static int ll_client_type_seq_show(struct seq_file *m, void *v)
236 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
238 LASSERT(sbi != NULL);
240 seq_puts(m, "local client\n");
243 LPROC_SEQ_FOPS_RO(ll_client_type);
245 static int ll_fstype_seq_show(struct seq_file *m, void *v)
247 struct super_block *sb = m->private;
248 struct ll_sb_info *sbi = ll_s2sbi(sb);
251 seq_printf(m, "%s\n", sbi->ll_mnt.mnt->mnt_sb->s_type->name);
254 LPROC_SEQ_FOPS_RO(ll_fstype);
256 static int ll_sb_uuid_seq_show(struct seq_file *m, void *v)
258 struct super_block *sb = m->private;
261 seq_printf(m, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
264 LPROC_SEQ_FOPS_RO(ll_sb_uuid);
266 static int ll_xattr_cache_seq_show(struct seq_file *m, void *v)
268 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
270 seq_printf(m, "%u\n", sbi->ll_xattr_cache_enabled);
274 static ssize_t ll_xattr_cache_seq_write(struct file *file,
275 const char __user *buffer,
276 size_t count, loff_t *off)
278 struct seq_file *m = file->private_data;
279 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
283 rc = kstrtobool_from_user(buffer, count, &val);
287 if (val && !(sbi->ll_flags & LL_SBI_XATTR_CACHE))
290 sbi->ll_xattr_cache_enabled = val;
291 sbi->ll_xattr_cache_set = 1;
295 LPROC_SEQ_FOPS(ll_xattr_cache);
297 static int ll_site_stats_seq_show(struct seq_file *m, void *v)
299 struct super_block *sb = m->private;
302 * See description of statistical counters in struct cl_site, and
305 return cl_site_stats_print(lu2cl_site(ll_s2sbi(sb)->ll_site), m);
307 LPROC_SEQ_FOPS_RO(ll_site_stats);
309 static int ll_max_readahead_mb_seq_show(struct seq_file *m, void *v)
311 struct super_block *sb = m->private;
312 struct ll_sb_info *sbi = ll_s2sbi(sb);
316 spin_lock(&sbi->ll_lock);
317 pages_number = sbi->ll_ra_info.ra_max_pages;
318 spin_unlock(&sbi->ll_lock);
320 mult = 1 << (20 - PAGE_SHIFT);
321 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
325 ll_max_readahead_mb_seq_write(struct file *file, const char __user *buffer,
326 size_t count, loff_t *off)
328 struct seq_file *m = file->private_data;
329 struct super_block *sb = m->private;
330 struct ll_sb_info *sbi = ll_s2sbi(sb);
334 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
338 pages_number >>= PAGE_SHIFT;
340 if (pages_number < 0 || pages_number > totalram_pages / 2) {
342 CERROR("%s: can't set max_readahead_mb=%lu > %luMB\n",
343 ll_get_fsname(sb, NULL, 0),
344 (unsigned long)pages_number >> (20 - PAGE_SHIFT),
345 totalram_pages >> (20 - PAGE_SHIFT + 1));
349 spin_lock(&sbi->ll_lock);
350 sbi->ll_ra_info.ra_max_pages = pages_number;
351 spin_unlock(&sbi->ll_lock);
354 LPROC_SEQ_FOPS(ll_max_readahead_mb);
356 static int ll_max_readahead_per_file_mb_seq_show(struct seq_file *m, void *v)
358 struct super_block *sb = m->private;
359 struct ll_sb_info *sbi = ll_s2sbi(sb);
363 spin_lock(&sbi->ll_lock);
364 pages_number = sbi->ll_ra_info.ra_max_pages_per_file;
365 spin_unlock(&sbi->ll_lock);
367 mult = 1 << (20 - PAGE_SHIFT);
368 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
372 ll_max_readahead_per_file_mb_seq_write(struct file *file,
373 const char __user *buffer,
374 size_t count, loff_t *off)
376 struct seq_file *m = file->private_data;
377 struct super_block *sb = m->private;
378 struct ll_sb_info *sbi = ll_s2sbi(sb);
382 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
386 pages_number >>= PAGE_SHIFT;
388 if (pages_number < 0 || pages_number > sbi->ll_ra_info.ra_max_pages) {
389 CERROR("%s: can't set max_readahead_per_file_mb=%lu > "
390 "max_read_ahead_mb=%lu\n", ll_get_fsname(sb, NULL, 0),
391 (unsigned long)pages_number >> (20 - PAGE_SHIFT),
392 sbi->ll_ra_info.ra_max_pages >> (20 - PAGE_SHIFT));
396 spin_lock(&sbi->ll_lock);
397 sbi->ll_ra_info.ra_max_pages_per_file = pages_number;
398 spin_unlock(&sbi->ll_lock);
401 LPROC_SEQ_FOPS(ll_max_readahead_per_file_mb);
403 static int ll_max_read_ahead_whole_mb_seq_show(struct seq_file *m, void *v)
405 struct super_block *sb = m->private;
406 struct ll_sb_info *sbi = ll_s2sbi(sb);
410 spin_lock(&sbi->ll_lock);
411 pages_number = sbi->ll_ra_info.ra_max_read_ahead_whole_pages;
412 spin_unlock(&sbi->ll_lock);
414 mult = 1 << (20 - PAGE_SHIFT);
415 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
419 ll_max_read_ahead_whole_mb_seq_write(struct file *file,
420 const char __user *buffer,
421 size_t count, loff_t *off)
423 struct seq_file *m = file->private_data;
424 struct super_block *sb = m->private;
425 struct ll_sb_info *sbi = ll_s2sbi(sb);
429 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
433 pages_number >>= PAGE_SHIFT;
435 /* Cap this at the current max readahead window size, the readahead
436 * algorithm does this anyway so it's pointless to set it larger. */
437 if (pages_number < 0 ||
438 pages_number > sbi->ll_ra_info.ra_max_pages_per_file) {
439 int pages_shift = 20 - PAGE_SHIFT;
440 CERROR("%s: can't set max_read_ahead_whole_mb=%lu > "
441 "max_read_ahead_per_file_mb=%lu\n",
442 ll_get_fsname(sb, NULL, 0),
443 (unsigned long)pages_number >> pages_shift,
444 sbi->ll_ra_info.ra_max_pages_per_file >> pages_shift);
448 spin_lock(&sbi->ll_lock);
449 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = pages_number;
450 spin_unlock(&sbi->ll_lock);
453 LPROC_SEQ_FOPS(ll_max_read_ahead_whole_mb);
455 static int ll_max_cached_mb_seq_show(struct seq_file *m, void *v)
457 struct super_block *sb = m->private;
458 struct ll_sb_info *sbi = ll_s2sbi(sb);
459 struct cl_client_cache *cache = sbi->ll_cache;
460 int shift = 20 - PAGE_SHIFT;
464 max_cached_mb = cache->ccc_lru_max >> shift;
465 unused_mb = atomic_long_read(&cache->ccc_lru_left) >> shift;
466 seq_printf(m, "users: %d\n"
467 "max_cached_mb: %ld\n"
470 "reclaim_count: %u\n",
471 atomic_read(&cache->ccc_users),
473 max_cached_mb - unused_mb,
475 cache->ccc_lru_shrinkers);
480 ll_max_cached_mb_seq_write(struct file *file, const char __user *buffer,
481 size_t count, loff_t *off)
483 struct seq_file *m = file->private_data;
484 struct super_block *sb = m->private;
485 struct ll_sb_info *sbi = ll_s2sbi(sb);
486 struct cl_client_cache *cache = sbi->ll_cache;
496 if (count >= sizeof(kernbuf))
499 if (copy_from_user(kernbuf, buffer, count))
503 buffer += lprocfs_find_named_value(kernbuf, "max_cached_mb:", &count) -
505 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
509 pages_number >>= PAGE_SHIFT;
511 if (pages_number < 0 || pages_number > totalram_pages) {
512 CERROR("%s: can't set max cache more than %lu MB\n",
513 ll_get_fsname(sb, NULL, 0),
514 totalram_pages >> (20 - PAGE_SHIFT));
517 /* Allow enough cache so clients can make well-formed RPCs */
518 pages_number = max_t(long, pages_number, PTLRPC_MAX_BRW_PAGES);
520 spin_lock(&sbi->ll_lock);
521 diff = pages_number - cache->ccc_lru_max;
522 spin_unlock(&sbi->ll_lock);
524 /* easy - add more LRU slots. */
526 atomic_long_add(diff, &cache->ccc_lru_left);
530 env = cl_env_get(&refcheck);
538 /* reduce LRU budget from free slots. */
542 ov = atomic_long_read(&cache->ccc_lru_left);
546 nv = ov > diff ? ov - diff : 0;
547 rc = atomic_long_cmpxchg(&cache->ccc_lru_left, ov, nv);
548 if (likely(ov == rc)) {
558 if (sbi->ll_dt_exp == NULL) { /* being initialized */
563 /* difficult - have to ask OSCs to drop LRU slots. */
565 rc = obd_set_info_async(env, sbi->ll_dt_exp,
566 sizeof(KEY_CACHE_LRU_SHRINK),
567 KEY_CACHE_LRU_SHRINK,
568 sizeof(tmp), &tmp, NULL);
572 cl_env_put(env, &refcheck);
576 spin_lock(&sbi->ll_lock);
577 cache->ccc_lru_max = pages_number;
578 spin_unlock(&sbi->ll_lock);
581 atomic_long_add(nrpages, &cache->ccc_lru_left);
585 LPROC_SEQ_FOPS(ll_max_cached_mb);
587 static int ll_checksum_seq_show(struct seq_file *m, void *v)
589 struct super_block *sb = m->private;
590 struct ll_sb_info *sbi = ll_s2sbi(sb);
592 seq_printf(m, "%u\n", (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0);
596 static ssize_t ll_checksum_seq_write(struct file *file,
597 const char __user *buffer,
598 size_t count, loff_t *off)
600 struct seq_file *m = file->private_data;
601 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
610 rc = kstrtobool_from_user(buffer, count, &val);
614 sbi->ll_flags |= LL_SBI_CHECKSUM;
616 sbi->ll_flags &= ~LL_SBI_CHECKSUM;
619 rc = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
620 KEY_CHECKSUM, sizeof(tmp), &tmp, NULL);
622 CWARN("Failed to set OSC checksum flags: %d\n", rc);
626 LPROC_SEQ_FOPS(ll_checksum);
628 static int ll_rd_track_id(struct seq_file *m, enum stats_track_type type)
630 struct super_block *sb = m->private;
632 if (ll_s2sbi(sb)->ll_stats_track_type == type) {
633 seq_printf(m, "%d\n",
634 ll_s2sbi(sb)->ll_stats_track_id);
635 } else if (ll_s2sbi(sb)->ll_stats_track_type == STATS_TRACK_ALL) {
636 seq_puts(m, "0 (all)\n");
638 seq_puts(m, "untracked\n");
643 static int ll_wr_track_id(const char __user *buffer, unsigned long count,
644 void *data, enum stats_track_type type)
646 struct super_block *sb = data;
650 rc = kstrtouint_from_user(buffer, count, 0, &pid);
654 ll_s2sbi(sb)->ll_stats_track_id = pid;
656 ll_s2sbi(sb)->ll_stats_track_type = STATS_TRACK_ALL;
658 ll_s2sbi(sb)->ll_stats_track_type = type;
659 lprocfs_clear_stats(ll_s2sbi(sb)->ll_stats);
663 static int ll_track_pid_seq_show(struct seq_file *m, void *v)
665 return ll_rd_track_id(m, STATS_TRACK_PID);
668 static ssize_t ll_track_pid_seq_write(struct file *file,
669 const char __user *buffer,
670 size_t count, loff_t *off)
672 struct seq_file *seq = file->private_data;
673 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PID);
675 LPROC_SEQ_FOPS(ll_track_pid);
677 static int ll_track_ppid_seq_show(struct seq_file *m, void *v)
679 return ll_rd_track_id(m, STATS_TRACK_PPID);
682 static ssize_t ll_track_ppid_seq_write(struct file *file,
683 const char __user *buffer,
684 size_t count, loff_t *off)
686 struct seq_file *seq = file->private_data;
687 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PPID);
689 LPROC_SEQ_FOPS(ll_track_ppid);
691 static int ll_track_gid_seq_show(struct seq_file *m, void *v)
693 return ll_rd_track_id(m, STATS_TRACK_GID);
696 static ssize_t ll_track_gid_seq_write(struct file *file,
697 const char __user *buffer,
698 size_t count, loff_t *off)
700 struct seq_file *seq = file->private_data;
701 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_GID);
703 LPROC_SEQ_FOPS(ll_track_gid);
705 static ssize_t statahead_running_max_show(struct kobject *kobj,
706 struct attribute *attr,
709 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
712 return snprintf(buf, 16, "%u\n", sbi->ll_sa_running_max);
715 static ssize_t statahead_running_max_store(struct kobject *kobj,
716 struct attribute *attr,
720 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
725 rc = kstrtoul(buffer, 0, &val);
729 if (val <= LL_SA_RUNNING_MAX) {
730 sbi->ll_sa_running_max = val;
734 CERROR("Bad statahead_running_max value %lu. Valid values "
735 "are in the range [0, %d]\n", val, LL_SA_RUNNING_MAX);
739 LUSTRE_RW_ATTR(statahead_running_max);
741 static int ll_statahead_max_seq_show(struct seq_file *m, void *v)
743 struct super_block *sb = m->private;
744 struct ll_sb_info *sbi = ll_s2sbi(sb);
746 seq_printf(m, "%u\n", sbi->ll_sa_max);
750 static ssize_t ll_statahead_max_seq_write(struct file *file,
751 const char __user *buffer,
752 size_t count, loff_t *off)
754 struct seq_file *m = file->private_data;
755 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
759 rc = kstrtouint_from_user(buffer, count, 0, &val);
763 if (val <= LL_SA_RPC_MAX)
764 sbi->ll_sa_max = val;
766 CERROR("Bad statahead_max value %u. Valid values are in "
767 "the range [0, %d]\n", val, LL_SA_RPC_MAX);
771 LPROC_SEQ_FOPS(ll_statahead_max);
773 static int ll_statahead_agl_seq_show(struct seq_file *m, void *v)
775 struct super_block *sb = m->private;
776 struct ll_sb_info *sbi = ll_s2sbi(sb);
778 seq_printf(m, "%u\n",
779 sbi->ll_flags & LL_SBI_AGL_ENABLED ? 1 : 0);
783 static ssize_t ll_statahead_agl_seq_write(struct file *file,
784 const char __user *buffer,
785 size_t count, loff_t *off)
787 struct seq_file *m = file->private_data;
788 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
792 rc = kstrtobool_from_user(buffer, count, &val);
797 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
799 sbi->ll_flags &= ~LL_SBI_AGL_ENABLED;
803 LPROC_SEQ_FOPS(ll_statahead_agl);
805 static int ll_statahead_stats_seq_show(struct seq_file *m, void *v)
807 struct super_block *sb = m->private;
808 struct ll_sb_info *sbi = ll_s2sbi(sb);
810 seq_printf(m, "statahead total: %u\n"
811 "statahead wrong: %u\n"
813 atomic_read(&sbi->ll_sa_total),
814 atomic_read(&sbi->ll_sa_wrong),
815 atomic_read(&sbi->ll_agl_total));
818 LPROC_SEQ_FOPS_RO(ll_statahead_stats);
820 static int ll_lazystatfs_seq_show(struct seq_file *m, void *v)
822 struct super_block *sb = m->private;
823 struct ll_sb_info *sbi = ll_s2sbi(sb);
825 seq_printf(m, "%u\n",
826 (sbi->ll_flags & LL_SBI_LAZYSTATFS) ? 1 : 0);
830 static ssize_t ll_lazystatfs_seq_write(struct file *file,
831 const char __user *buffer,
832 size_t count, loff_t *off)
834 struct seq_file *m = file->private_data;
835 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
839 rc = kstrtobool_from_user(buffer, count, &val);
844 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
846 sbi->ll_flags &= ~LL_SBI_LAZYSTATFS;
850 LPROC_SEQ_FOPS(ll_lazystatfs);
852 static int ll_max_easize_seq_show(struct seq_file *m, void *v)
854 struct super_block *sb = m->private;
855 struct ll_sb_info *sbi = ll_s2sbi(sb);
859 rc = ll_get_max_mdsize(sbi, &ealen);
863 seq_printf(m, "%u\n", ealen);
866 LPROC_SEQ_FOPS_RO(ll_max_easize);
869 * Get default_easize.
871 * \see client_obd::cl_default_mds_easize
873 * \param[in] m seq_file handle
874 * \param[in] v unused for single entry
876 * \retval 0 on success
877 * \retval negative negated errno on failure
879 static int ll_default_easize_seq_show(struct seq_file *m, void *v)
881 struct super_block *sb = m->private;
882 struct ll_sb_info *sbi = ll_s2sbi(sb);
886 rc = ll_get_default_mdsize(sbi, &ealen);
890 seq_printf(m, "%u\n", ealen);
895 * Set default_easize.
897 * Range checking on the passed value is handled by
898 * ll_set_default_mdsize().
900 * \see client_obd::cl_default_mds_easize
902 * \param[in] file proc file
903 * \param[in] buffer string passed from user space
904 * \param[in] count \a buffer length
905 * \param[in] off unused for single entry
907 * \retval positive \a count on success
908 * \retval negative negated errno on failure
910 static ssize_t ll_default_easize_seq_write(struct file *file,
911 const char __user *buffer,
912 size_t count, loff_t *unused)
914 struct seq_file *seq = file->private_data;
915 struct super_block *sb = (struct super_block *)seq->private;
916 struct ll_sb_info *sbi = ll_s2sbi(sb);
923 rc = kstrtouint_from_user(buffer, count, 0, &val);
927 rc = ll_set_default_mdsize(sbi, val);
933 LPROC_SEQ_FOPS(ll_default_easize);
935 static int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
937 const char *str[] = LL_SBI_FLAGS;
938 struct super_block *sb = m->private;
939 int flags = ll_s2sbi(sb)->ll_flags;
943 if (ARRAY_SIZE(str) <= i) {
944 CERROR("%s: Revise array LL_SBI_FLAGS to match sbi "
945 "flags please.\n", ll_get_fsname(sb, NULL, 0));
950 seq_printf(m, "%s ", str[i]);
954 seq_printf(m, "\b\n");
957 LPROC_SEQ_FOPS_RO(ll_sbi_flags);
959 static int ll_tiny_write_seq_show(struct seq_file *m, void *v)
961 struct super_block *sb = m->private;
962 struct ll_sb_info *sbi = ll_s2sbi(sb);
964 seq_printf(m, "%u\n", !!(sbi->ll_flags & LL_SBI_TINY_WRITE));
968 static ssize_t ll_tiny_write_seq_write(
969 struct file *file, const char __user *buffer, size_t count, loff_t *off)
971 struct seq_file *m = file->private_data;
972 struct super_block *sb = m->private;
973 struct ll_sb_info *sbi = ll_s2sbi(sb);
977 rc = kstrtobool_from_user(buffer, count, &val);
981 spin_lock(&sbi->ll_lock);
983 sbi->ll_flags |= LL_SBI_TINY_WRITE;
985 sbi->ll_flags &= ~LL_SBI_TINY_WRITE;
986 spin_unlock(&sbi->ll_lock);
990 LPROC_SEQ_FOPS(ll_tiny_write);
992 static int ll_fast_read_seq_show(struct seq_file *m, void *v)
994 struct super_block *sb = m->private;
995 struct ll_sb_info *sbi = ll_s2sbi(sb);
997 seq_printf(m, "%u\n", !!(sbi->ll_flags & LL_SBI_FAST_READ));
1002 ll_fast_read_seq_write(struct file *file, const char __user *buffer,
1003 size_t count, loff_t *off)
1005 struct seq_file *m = file->private_data;
1006 struct super_block *sb = m->private;
1007 struct ll_sb_info *sbi = ll_s2sbi(sb);
1011 rc = kstrtobool_from_user(buffer, count, &val);
1015 spin_lock(&sbi->ll_lock);
1017 sbi->ll_flags |= LL_SBI_FAST_READ;
1019 sbi->ll_flags &= ~LL_SBI_FAST_READ;
1020 spin_unlock(&sbi->ll_lock);
1024 LPROC_SEQ_FOPS(ll_fast_read);
1026 static int ll_pio_seq_show(struct seq_file *m, void *v)
1028 struct super_block *sb = m->private;
1029 struct ll_sb_info *sbi = ll_s2sbi(sb);
1031 seq_printf(m, "%u\n", !!(sbi->ll_flags & LL_SBI_PIO));
1035 static ssize_t ll_pio_seq_write(struct file *file, const char __user *buffer,
1036 size_t count, loff_t *off)
1038 struct seq_file *m = file->private_data;
1039 struct super_block *sb = m->private;
1040 struct ll_sb_info *sbi = ll_s2sbi(sb);
1044 rc = kstrtobool_from_user(buffer, count, &val);
1048 spin_lock(&sbi->ll_lock);
1050 sbi->ll_flags |= LL_SBI_PIO;
1052 sbi->ll_flags &= ~LL_SBI_PIO;
1053 spin_unlock(&sbi->ll_lock);
1057 LPROC_SEQ_FOPS(ll_pio);
1059 static int ll_unstable_stats_seq_show(struct seq_file *m, void *v)
1061 struct super_block *sb = m->private;
1062 struct ll_sb_info *sbi = ll_s2sbi(sb);
1063 struct cl_client_cache *cache = sbi->ll_cache;
1067 pages = atomic_long_read(&cache->ccc_unstable_nr);
1068 mb = (pages * PAGE_SIZE) >> 20;
1070 seq_printf(m, "unstable_check: %8d\n"
1071 "unstable_pages: %12ld\n"
1072 "unstable_mb: %8d\n",
1073 cache->ccc_unstable_check, pages, mb);
1077 static ssize_t ll_unstable_stats_seq_write(struct file *file,
1078 const char __user *buffer,
1079 size_t count, loff_t *unused)
1081 struct seq_file *seq = file->private_data;
1082 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)seq->private);
1089 if (count >= sizeof(kernbuf))
1092 if (copy_from_user(kernbuf, buffer, count))
1096 buffer += lprocfs_find_named_value(kernbuf, "unstable_check:", &count) -
1098 rc = kstrtobool_from_user(buffer, count, &val);
1102 /* borrow lru lock to set the value */
1103 spin_lock(&sbi->ll_cache->ccc_lru_lock);
1104 sbi->ll_cache->ccc_unstable_check = val;
1105 spin_unlock(&sbi->ll_cache->ccc_lru_lock);
1109 LPROC_SEQ_FOPS(ll_unstable_stats);
1111 static int ll_root_squash_seq_show(struct seq_file *m, void *v)
1113 struct super_block *sb = m->private;
1114 struct ll_sb_info *sbi = ll_s2sbi(sb);
1115 struct root_squash_info *squash = &sbi->ll_squash;
1117 seq_printf(m, "%u:%u\n", squash->rsi_uid, squash->rsi_gid);
1121 static ssize_t ll_root_squash_seq_write(struct file *file,
1122 const char __user *buffer,
1123 size_t count, loff_t *off)
1125 struct seq_file *m = file->private_data;
1126 struct super_block *sb = m->private;
1127 struct ll_sb_info *sbi = ll_s2sbi(sb);
1128 struct root_squash_info *squash = &sbi->ll_squash;
1130 return lprocfs_wr_root_squash(buffer, count, squash,
1131 ll_get_fsname(sb, NULL, 0));
1133 LPROC_SEQ_FOPS(ll_root_squash);
1135 static int ll_nosquash_nids_seq_show(struct seq_file *m, void *v)
1137 struct super_block *sb = m->private;
1138 struct ll_sb_info *sbi = ll_s2sbi(sb);
1139 struct root_squash_info *squash = &sbi->ll_squash;
1142 down_read(&squash->rsi_sem);
1143 if (!list_empty(&squash->rsi_nosquash_nids)) {
1144 len = cfs_print_nidlist(m->buf + m->count, m->size - m->count,
1145 &squash->rsi_nosquash_nids);
1149 seq_puts(m, "NONE\n");
1151 up_read(&squash->rsi_sem);
1156 static ssize_t ll_nosquash_nids_seq_write(struct file *file,
1157 const char __user *buffer,
1158 size_t count, loff_t *off)
1160 struct seq_file *m = file->private_data;
1161 struct super_block *sb = m->private;
1162 struct ll_sb_info *sbi = ll_s2sbi(sb);
1163 struct root_squash_info *squash = &sbi->ll_squash;
1166 rc = lprocfs_wr_nosquash_nids(buffer, count, squash,
1167 ll_get_fsname(sb, NULL, 0));
1171 ll_compute_rootsquash_state(sbi);
1175 LPROC_SEQ_FOPS(ll_nosquash_nids);
1177 struct lprocfs_vars lprocfs_llite_obd_vars[] = {
1179 .fops = &ll_sb_uuid_fops },
1181 .fops = &ll_fstype_fops },
1183 .fops = &ll_site_stats_fops },
1184 { .name = "stat_blocksize",
1185 .fops = &ll_stat_blksize_fops },
1186 { .name = "filestotal",
1187 .fops = &ll_filestotal_fops },
1188 { .name = "filesfree",
1189 .fops = &ll_filesfree_fops },
1190 { .name = "client_type",
1191 .fops = &ll_client_type_fops },
1192 { .name = "max_read_ahead_mb",
1193 .fops = &ll_max_readahead_mb_fops },
1194 { .name = "max_read_ahead_per_file_mb",
1195 .fops = &ll_max_readahead_per_file_mb_fops },
1196 { .name = "max_read_ahead_whole_mb",
1197 .fops = &ll_max_read_ahead_whole_mb_fops },
1198 { .name = "max_cached_mb",
1199 .fops = &ll_max_cached_mb_fops },
1200 { .name = "checksum_pages",
1201 .fops = &ll_checksum_fops },
1202 { .name = "stats_track_pid",
1203 .fops = &ll_track_pid_fops },
1204 { .name = "stats_track_ppid",
1205 .fops = &ll_track_ppid_fops },
1206 { .name = "stats_track_gid",
1207 .fops = &ll_track_gid_fops },
1208 { .name = "statahead_max",
1209 .fops = &ll_statahead_max_fops },
1210 { .name = "statahead_agl",
1211 .fops = &ll_statahead_agl_fops },
1212 { .name = "statahead_stats",
1213 .fops = &ll_statahead_stats_fops },
1214 { .name = "lazystatfs",
1215 .fops = &ll_lazystatfs_fops },
1216 { .name = "max_easize",
1217 .fops = &ll_max_easize_fops },
1218 { .name = "default_easize",
1219 .fops = &ll_default_easize_fops },
1220 { .name = "sbi_flags",
1221 .fops = &ll_sbi_flags_fops },
1222 { .name = "xattr_cache",
1223 .fops = &ll_xattr_cache_fops },
1224 { .name = "unstable_stats",
1225 .fops = &ll_unstable_stats_fops },
1226 { .name = "root_squash",
1227 .fops = &ll_root_squash_fops },
1228 { .name = "nosquash_nids",
1229 .fops = &ll_nosquash_nids_fops },
1230 { .name = "fast_read",
1231 .fops = &ll_fast_read_fops, },
1233 .fops = &ll_pio_fops, },
1234 { .name = "tiny_write",
1235 .fops = &ll_tiny_write_fops, },
1239 #define MAX_STRING_SIZE 128
1241 static struct attribute *llite_attrs[] = {
1242 &lustre_attr_blocksize.attr,
1243 &lustre_attr_kbytestotal.attr,
1244 &lustre_attr_kbytesfree.attr,
1245 &lustre_attr_kbytesavail.attr,
1246 &lustre_attr_statahead_running_max.attr,
1250 static void llite_kobj_release(struct kobject *kobj)
1252 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1254 complete(&sbi->ll_kobj_unregister);
1257 static struct kobj_type llite_ktype = {
1258 .default_attrs = llite_attrs,
1259 .sysfs_ops = &lustre_sysfs_ops,
1260 .release = llite_kobj_release,
1263 static const struct llite_file_opcode {
1267 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
1268 /* file operation */
1269 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
1270 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
1271 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1273 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1275 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
1277 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
1279 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
1280 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
1281 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
1282 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
1283 { LPROC_LL_FAULT, LPROCFS_TYPE_REGS, "page_fault" },
1284 { LPROC_LL_MKWRITE, LPROCFS_TYPE_REGS, "page_mkwrite" },
1285 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
1286 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
1287 { LPROC_LL_READDIR, LPROCFS_TYPE_REGS, "readdir" },
1288 /* inode operation */
1289 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
1290 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "truncate" },
1291 { LPROC_LL_FLOCK, LPROCFS_TYPE_REGS, "flock" },
1292 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
1293 /* dir inode operation */
1294 { LPROC_LL_CREATE, LPROCFS_TYPE_REGS, "create" },
1295 { LPROC_LL_LINK, LPROCFS_TYPE_REGS, "link" },
1296 { LPROC_LL_UNLINK, LPROCFS_TYPE_REGS, "unlink" },
1297 { LPROC_LL_SYMLINK, LPROCFS_TYPE_REGS, "symlink" },
1298 { LPROC_LL_MKDIR, LPROCFS_TYPE_REGS, "mkdir" },
1299 { LPROC_LL_RMDIR, LPROCFS_TYPE_REGS, "rmdir" },
1300 { LPROC_LL_MKNOD, LPROCFS_TYPE_REGS, "mknod" },
1301 { LPROC_LL_RENAME, LPROCFS_TYPE_REGS, "rename" },
1302 /* special inode operation */
1303 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
1304 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
1305 { LPROC_LL_SETXATTR, LPROCFS_TYPE_REGS, "setxattr" },
1306 { LPROC_LL_GETXATTR, LPROCFS_TYPE_REGS, "getxattr" },
1307 { LPROC_LL_GETXATTR_HITS, LPROCFS_TYPE_REGS, "getxattr_hits" },
1308 { LPROC_LL_LISTXATTR, LPROCFS_TYPE_REGS, "listxattr" },
1309 { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_REGS, "removexattr" },
1310 { LPROC_LL_INODE_PERM, LPROCFS_TYPE_REGS, "inode_permission" },
1313 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
1317 if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
1318 lprocfs_counter_add(sbi->ll_stats, op, count);
1319 else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
1320 sbi->ll_stats_track_id == current->pid)
1321 lprocfs_counter_add(sbi->ll_stats, op, count);
1322 else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
1323 sbi->ll_stats_track_id == current->parent->pid)
1324 lprocfs_counter_add(sbi->ll_stats, op, count);
1325 else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
1326 sbi->ll_stats_track_id ==
1327 from_kgid(&init_user_ns, current_gid()))
1328 lprocfs_counter_add(sbi->ll_stats, op, count);
1330 EXPORT_SYMBOL(ll_stats_ops_tally);
1332 static const char *ra_stat_string[] = {
1333 [RA_STAT_HIT] = "hits",
1334 [RA_STAT_MISS] = "misses",
1335 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
1336 [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
1337 [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page",
1338 [RA_STAT_FAILED_MATCH] = "failed lock match",
1339 [RA_STAT_DISCARDED] = "read but discarded",
1340 [RA_STAT_ZERO_LEN] = "zero length file",
1341 [RA_STAT_ZERO_WINDOW] = "zero size window",
1342 [RA_STAT_EOF] = "read-ahead to EOF",
1343 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
1344 [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",
1345 [RA_STAT_FAILED_REACH_END] = "failed to reach end"
1348 LPROC_SEQ_FOPS_RO_TYPE(llite, name);
1349 LPROC_SEQ_FOPS_RO_TYPE(llite, uuid);
1351 int ll_debugfs_register_super(struct super_block *sb, const char *name)
1353 struct lustre_sb_info *lsi = s2lsi(sb);
1354 struct ll_sb_info *sbi = ll_s2sbi(sb);
1355 struct lprocfs_vars lvars[2];
1359 memset(lvars, 0, sizeof(lvars));
1360 lvars[0].name = name;
1362 LASSERT(sbi != NULL);
1364 sbi->ll_proc_root = lprocfs_register(name, proc_lustre_fs_root,
1366 if (IS_ERR(sbi->ll_proc_root)) {
1367 err = PTR_ERR(sbi->ll_proc_root);
1368 sbi->ll_proc_root = NULL;
1372 rc = lprocfs_seq_create(sbi->ll_proc_root, "dump_page_cache", 0444,
1373 &vvp_dump_pgcache_file_ops, sbi);
1375 CWARN("Error adding the dump_page_cache file\n");
1377 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats", 0644,
1378 &ll_rw_extents_stats_fops, sbi);
1380 CWARN("Error adding the extent_stats file\n");
1382 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats_per_process",
1383 0644, &ll_rw_extents_stats_pp_fops, sbi);
1385 CWARN("Error adding the extents_stats_per_process file\n");
1387 rc = lprocfs_seq_create(sbi->ll_proc_root, "offset_stats", 0644,
1388 &ll_rw_offset_stats_fops, sbi);
1390 CWARN("Error adding the offset_stats file\n");
1392 /* File operations stats */
1393 sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
1394 LPROCFS_STATS_FLAG_NONE);
1395 if (sbi->ll_stats == NULL)
1396 GOTO(out_proc, err = -ENOMEM);
1398 /* do counter init */
1399 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
1400 __u32 type = llite_opcode_table[id].type;
1402 if (type & LPROCFS_TYPE_REGS)
1404 else if (type & LPROCFS_TYPE_BYTES)
1406 else if (type & LPROCFS_TYPE_PAGES)
1408 lprocfs_counter_init(sbi->ll_stats,
1409 llite_opcode_table[id].opcode,
1410 (type & LPROCFS_CNTR_AVGMINMAX),
1411 llite_opcode_table[id].opname, ptr);
1414 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats);
1416 GOTO(out_stats, err);
1418 sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
1419 LPROCFS_STATS_FLAG_NONE);
1420 if (sbi->ll_ra_stats == NULL)
1421 GOTO(out_stats, err = -ENOMEM);
1423 for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
1424 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
1425 ra_stat_string[id], "pages");
1426 err = lprocfs_register_stats(sbi->ll_proc_root, "read_ahead_stats",
1429 GOTO(out_ra_stats, err);
1431 err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_llite_obd_vars, sb);
1433 GOTO(out_ra_stats, err);
1435 /* Yes we also register sysfs mount kset here as well */
1436 sbi->ll_kset.kobj.parent = llite_kobj;
1437 sbi->ll_kset.kobj.ktype = &llite_ktype;
1438 init_completion(&sbi->ll_kobj_unregister);
1439 err = kobject_set_name(&sbi->ll_kset.kobj, "%s", name);
1441 GOTO(out_ra_stats, err);
1443 err = kset_register(&sbi->ll_kset);
1445 GOTO(out_ra_stats, err);
1447 lsi->lsi_kobj = kobject_get(&sbi->ll_kset.kobj);
1451 lprocfs_free_stats(&sbi->ll_ra_stats);
1453 lprocfs_free_stats(&sbi->ll_stats);
1455 lprocfs_remove(&sbi->ll_proc_root);
1460 int lprocfs_ll_register_obd(struct super_block *sb, const char *obdname)
1462 struct lprocfs_vars lvars[2];
1463 struct ll_sb_info *sbi = ll_s2sbi(sb);
1464 struct obd_device *obd;
1465 struct proc_dir_entry *dir;
1466 char name[MAX_STRING_SIZE + 1];
1470 memset(lvars, 0, sizeof(lvars));
1472 name[MAX_STRING_SIZE] = '\0';
1473 lvars[0].name = name;
1475 LASSERT(sbi != NULL);
1476 LASSERT(obdname != NULL);
1478 obd = class_name2obd(obdname);
1480 LASSERT(obd != NULL);
1481 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1482 LASSERT(obd->obd_type->typ_name != NULL);
1484 dir = proc_mkdir(obd->obd_type->typ_name, sbi->ll_proc_root);
1486 GOTO(out, err = -ENOMEM);
1488 snprintf(name, MAX_STRING_SIZE, "common_name");
1489 lvars[0].fops = &llite_name_fops;
1490 err = lprocfs_add_vars(dir, lvars, obd);
1494 snprintf(name, MAX_STRING_SIZE, "uuid");
1495 lvars[0].fops = &llite_uuid_fops;
1496 err = lprocfs_add_vars(dir, lvars, obd);
1502 lprocfs_remove(&sbi->ll_proc_root);
1503 lprocfs_free_stats(&sbi->ll_ra_stats);
1504 lprocfs_free_stats(&sbi->ll_stats);
1509 void ll_debugfs_unregister_super(struct super_block *sb)
1511 struct lustre_sb_info *lsi = s2lsi(sb);
1512 struct ll_sb_info *sbi = ll_s2sbi(sb);
1514 kobject_put(lsi->lsi_kobj);
1516 kset_unregister(&sbi->ll_kset);
1517 wait_for_completion(&sbi->ll_kobj_unregister);
1519 if (sbi->ll_proc_root) {
1520 lprocfs_remove(&sbi->ll_proc_root);
1521 lprocfs_free_stats(&sbi->ll_ra_stats);
1522 lprocfs_free_stats(&sbi->ll_stats);
1525 #undef MAX_STRING_SIZE
1527 #define pct(a,b) (b ? a * 100 / b : 0)
1529 static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
1530 struct seq_file *seq, int which)
1532 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
1533 unsigned long start, end, r, w;
1534 char *unitp = "KMGTPEZY";
1536 struct per_process_info *pp_info = &io_extents->pp_extents[which];
1542 for(i = 0; i < LL_HIST_MAX; i++) {
1543 read_tot += pp_info->pp_r_hist.oh_buckets[i];
1544 write_tot += pp_info->pp_w_hist.oh_buckets[i];
1547 for(i = 0; i < LL_HIST_MAX; i++) {
1548 r = pp_info->pp_r_hist.oh_buckets[i];
1549 w = pp_info->pp_w_hist.oh_buckets[i];
1552 end = 1 << (i + LL_HIST_START - units);
1553 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu | "
1554 "%14lu %4lu %4lu\n", start, *unitp, end, *unitp,
1555 (i == LL_HIST_MAX - 1) ? '+' : ' ',
1556 r, pct(r, read_tot), pct(read_cum, read_tot),
1557 w, pct(w, write_tot), pct(write_cum, write_tot));
1559 if (start == 1<<10) {
1564 if (read_cum == read_tot && write_cum == write_tot)
1569 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
1571 struct timespec64 now;
1572 struct ll_sb_info *sbi = seq->private;
1573 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1576 ktime_get_real_ts64(&now);
1578 if (!sbi->ll_rw_stats_on) {
1579 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
1582 seq_printf(seq, "snapshot_time: %llu.%09lu (secs.nsecs)\n",
1583 (s64)now.tv_sec, now.tv_nsec);
1584 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1585 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1586 "extents", "calls", "%", "cum%",
1587 "calls", "%", "cum%");
1588 spin_lock(&sbi->ll_pp_extent_lock);
1589 for (k = 0; k < LL_PROCESS_HIST_MAX; k++) {
1590 if (io_extents->pp_extents[k].pid != 0) {
1591 seq_printf(seq, "\nPID: %d\n",
1592 io_extents->pp_extents[k].pid);
1593 ll_display_extents_info(io_extents, seq, k);
1596 spin_unlock(&sbi->ll_pp_extent_lock);
1600 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
1601 const char __user *buf,
1605 struct seq_file *seq = file->private_data;
1606 struct ll_sb_info *sbi = seq->private;
1607 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1614 value = ll_stats_pid_write(buf, len);
1617 sbi->ll_rw_stats_on = 0;
1619 sbi->ll_rw_stats_on = 1;
1621 spin_lock(&sbi->ll_pp_extent_lock);
1622 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1623 io_extents->pp_extents[i].pid = 0;
1624 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1625 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1627 spin_unlock(&sbi->ll_pp_extent_lock);
1631 LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
1633 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
1635 struct timespec64 now;
1636 struct ll_sb_info *sbi = seq->private;
1637 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1639 ktime_get_real_ts64(&now);
1641 if (!sbi->ll_rw_stats_on) {
1642 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
1645 seq_printf(seq, "snapshot_time: %llu.%09lu (secs.nsecs)\n",
1646 (s64)now.tv_sec, now.tv_nsec);
1648 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1649 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1650 "extents", "calls", "%", "cum%",
1651 "calls", "%", "cum%");
1652 spin_lock(&sbi->ll_lock);
1653 ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
1654 spin_unlock(&sbi->ll_lock);
1659 static ssize_t ll_rw_extents_stats_seq_write(struct file *file,
1660 const char __user *buf,
1661 size_t len, loff_t *off)
1663 struct seq_file *seq = file->private_data;
1664 struct ll_sb_info *sbi = seq->private;
1665 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1672 value = ll_stats_pid_write(buf, len);
1675 sbi->ll_rw_stats_on = 0;
1677 sbi->ll_rw_stats_on = 1;
1679 spin_lock(&sbi->ll_pp_extent_lock);
1680 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
1681 io_extents->pp_extents[i].pid = 0;
1682 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1683 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1685 spin_unlock(&sbi->ll_pp_extent_lock);
1689 LPROC_SEQ_FOPS(ll_rw_extents_stats);
1691 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
1692 struct ll_file_data *file, loff_t pos,
1693 size_t count, int rw)
1696 struct ll_rw_process_info *process;
1697 struct ll_rw_process_info *offset;
1698 int *off_count = &sbi->ll_rw_offset_entry_count;
1699 int *process_count = &sbi->ll_offset_process_count;
1700 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1702 if(!sbi->ll_rw_stats_on)
1704 process = sbi->ll_rw_process_info;
1705 offset = sbi->ll_rw_offset_info;
1707 spin_lock(&sbi->ll_pp_extent_lock);
1708 /* Extent statistics */
1709 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1710 if(io_extents->pp_extents[i].pid == pid) {
1718 sbi->ll_extent_process_count =
1719 (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1720 cur = sbi->ll_extent_process_count;
1721 io_extents->pp_extents[cur].pid = pid;
1722 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1723 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1726 for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
1727 (i < (LL_HIST_MAX - 1)); i++);
1729 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1730 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1732 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1733 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1735 spin_unlock(&sbi->ll_pp_extent_lock);
1737 spin_lock(&sbi->ll_process_lock);
1738 /* Offset statistics */
1739 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1740 if (process[i].rw_pid == pid) {
1741 if (process[i].rw_last_file != file) {
1742 process[i].rw_range_start = pos;
1743 process[i].rw_last_file_pos = pos + count;
1744 process[i].rw_smallest_extent = count;
1745 process[i].rw_largest_extent = count;
1746 process[i].rw_offset = 0;
1747 process[i].rw_last_file = file;
1748 spin_unlock(&sbi->ll_process_lock);
1751 if (process[i].rw_last_file_pos != pos) {
1753 (*off_count + 1) % LL_OFFSET_HIST_MAX;
1754 offset[*off_count].rw_op = process[i].rw_op;
1755 offset[*off_count].rw_pid = pid;
1756 offset[*off_count].rw_range_start =
1757 process[i].rw_range_start;
1758 offset[*off_count].rw_range_end =
1759 process[i].rw_last_file_pos;
1760 offset[*off_count].rw_smallest_extent =
1761 process[i].rw_smallest_extent;
1762 offset[*off_count].rw_largest_extent =
1763 process[i].rw_largest_extent;
1764 offset[*off_count].rw_offset =
1765 process[i].rw_offset;
1766 process[i].rw_op = rw;
1767 process[i].rw_range_start = pos;
1768 process[i].rw_smallest_extent = count;
1769 process[i].rw_largest_extent = count;
1770 process[i].rw_offset = pos -
1771 process[i].rw_last_file_pos;
1773 if(process[i].rw_smallest_extent > count)
1774 process[i].rw_smallest_extent = count;
1775 if(process[i].rw_largest_extent < count)
1776 process[i].rw_largest_extent = count;
1777 process[i].rw_last_file_pos = pos + count;
1778 spin_unlock(&sbi->ll_process_lock);
1782 *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
1783 process[*process_count].rw_pid = pid;
1784 process[*process_count].rw_op = rw;
1785 process[*process_count].rw_range_start = pos;
1786 process[*process_count].rw_last_file_pos = pos + count;
1787 process[*process_count].rw_smallest_extent = count;
1788 process[*process_count].rw_largest_extent = count;
1789 process[*process_count].rw_offset = 0;
1790 process[*process_count].rw_last_file = file;
1791 spin_unlock(&sbi->ll_process_lock);
1794 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1796 struct timespec64 now;
1797 struct ll_sb_info *sbi = seq->private;
1798 struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
1799 struct ll_rw_process_info *process = sbi->ll_rw_process_info;
1802 ktime_get_real_ts64(&now);
1804 if (!sbi->ll_rw_stats_on) {
1805 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
1808 spin_lock(&sbi->ll_process_lock);
1810 seq_printf(seq, "snapshot_time: %llu.%09lu (secs.nsecs)\n",
1811 (s64)now.tv_sec, now.tv_nsec);
1812 seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
1813 "R/W", "PID", "RANGE START", "RANGE END",
1814 "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
1816 /* We stored the discontiguous offsets here; print them first */
1817 for (i = 0; i < LL_OFFSET_HIST_MAX; i++) {
1818 if (offset[i].rw_pid != 0)
1820 "%3c %10d %14llu %14llu %17lu %17lu %14llu\n",
1821 offset[i].rw_op == READ ? 'R' : 'W',
1823 offset[i].rw_range_start,
1824 offset[i].rw_range_end,
1825 (unsigned long)offset[i].rw_smallest_extent,
1826 (unsigned long)offset[i].rw_largest_extent,
1827 offset[i].rw_offset);
1830 /* Then print the current offsets for each process */
1831 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1832 if (process[i].rw_pid != 0)
1834 "%3c %10d %14llu %14llu %17lu %17lu %14llu\n",
1835 process[i].rw_op == READ ? 'R' : 'W',
1837 process[i].rw_range_start,
1838 process[i].rw_last_file_pos,
1839 (unsigned long)process[i].rw_smallest_extent,
1840 (unsigned long)process[i].rw_largest_extent,
1841 process[i].rw_offset);
1843 spin_unlock(&sbi->ll_process_lock);
1848 static ssize_t ll_rw_offset_stats_seq_write(struct file *file,
1849 const char __user *buf,
1850 size_t len, loff_t *off)
1852 struct seq_file *seq = file->private_data;
1853 struct ll_sb_info *sbi = seq->private;
1854 struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
1855 struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
1861 value = ll_stats_pid_write(buf, len);
1864 sbi->ll_rw_stats_on = 0;
1866 sbi->ll_rw_stats_on = 1;
1868 spin_lock(&sbi->ll_process_lock);
1869 sbi->ll_offset_process_count = 0;
1870 sbi->ll_rw_offset_entry_count = 0;
1871 memset(process_info, 0, sizeof(struct ll_rw_process_info) *
1872 LL_PROCESS_HIST_MAX);
1873 memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
1874 LL_OFFSET_HIST_MAX);
1875 spin_unlock(&sbi->ll_process_lock);
1881 * ll_stats_pid_write() - Determine if stats collection should be enabled
1882 * @buf: Buffer containing the data written
1883 * @len: Number of bytes in the buffer
1885 * Several proc files begin collecting stats when a value is written, and stop
1886 * collecting when either '0' or 'disable' is written. This function checks the
1887 * written value to see if collection should be enabled or disabled.
1889 * Return: If '0' or 'disable' is provided, 0 is returned. If the text
1890 * equivalent of a number is written, that number is returned. Otherwise,
1891 * 1 is returned. Non-zero return values indicate collection should be enabled.
1893 static __s64 ll_stats_pid_write(const char __user *buf, size_t len)
1895 unsigned long long value = 1;
1899 rc = kstrtoull_from_user(buf, len, 0, &value);
1900 if (rc < 0 && len < sizeof(kernbuf)) {
1902 if (copy_from_user(kernbuf, buf, len))
1906 if (kernbuf[len - 1] == '\n')
1907 kernbuf[len - 1] = 0;
1909 if (strncasecmp(kernbuf, "disable", 7) == 0)
1916 LPROC_SEQ_FOPS(ll_rw_offset_stats);
1917 #endif /* CONFIG_PROC_FS */