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 ssize_t filestotal_show(struct kobject *kobj, struct attribute *attr,
209 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
211 struct obd_statfs osfs;
214 rc = ll_statfs_internal(sbi, &osfs, OBD_STATFS_NODELAY);
218 return sprintf(buf, "%llu\n", osfs.os_files);
220 LUSTRE_RO_ATTR(filestotal);
222 static ssize_t filesfree_show(struct kobject *kobj, struct attribute *attr,
225 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
227 struct obd_statfs osfs;
230 rc = ll_statfs_internal(sbi, &osfs, OBD_STATFS_NODELAY);
234 return sprintf(buf, "%llu\n", osfs.os_ffree);
236 LUSTRE_RO_ATTR(filesfree);
238 static ssize_t client_type_show(struct kobject *kobj, struct attribute *attr,
241 return sprintf(buf, "local client\n");
243 LUSTRE_RO_ATTR(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 = "max_read_ahead_mb",
1187 .fops = &ll_max_readahead_mb_fops },
1188 { .name = "max_read_ahead_per_file_mb",
1189 .fops = &ll_max_readahead_per_file_mb_fops },
1190 { .name = "max_read_ahead_whole_mb",
1191 .fops = &ll_max_read_ahead_whole_mb_fops },
1192 { .name = "max_cached_mb",
1193 .fops = &ll_max_cached_mb_fops },
1194 { .name = "checksum_pages",
1195 .fops = &ll_checksum_fops },
1196 { .name = "stats_track_pid",
1197 .fops = &ll_track_pid_fops },
1198 { .name = "stats_track_ppid",
1199 .fops = &ll_track_ppid_fops },
1200 { .name = "stats_track_gid",
1201 .fops = &ll_track_gid_fops },
1202 { .name = "statahead_max",
1203 .fops = &ll_statahead_max_fops },
1204 { .name = "statahead_agl",
1205 .fops = &ll_statahead_agl_fops },
1206 { .name = "statahead_stats",
1207 .fops = &ll_statahead_stats_fops },
1208 { .name = "lazystatfs",
1209 .fops = &ll_lazystatfs_fops },
1210 { .name = "max_easize",
1211 .fops = &ll_max_easize_fops },
1212 { .name = "default_easize",
1213 .fops = &ll_default_easize_fops },
1214 { .name = "sbi_flags",
1215 .fops = &ll_sbi_flags_fops },
1216 { .name = "xattr_cache",
1217 .fops = &ll_xattr_cache_fops },
1218 { .name = "unstable_stats",
1219 .fops = &ll_unstable_stats_fops },
1220 { .name = "root_squash",
1221 .fops = &ll_root_squash_fops },
1222 { .name = "nosquash_nids",
1223 .fops = &ll_nosquash_nids_fops },
1224 { .name = "fast_read",
1225 .fops = &ll_fast_read_fops, },
1227 .fops = &ll_pio_fops, },
1228 { .name = "tiny_write",
1229 .fops = &ll_tiny_write_fops, },
1233 #define MAX_STRING_SIZE 128
1235 static struct attribute *llite_attrs[] = {
1236 &lustre_attr_blocksize.attr,
1237 &lustre_attr_kbytestotal.attr,
1238 &lustre_attr_kbytesfree.attr,
1239 &lustre_attr_kbytesavail.attr,
1240 &lustre_attr_filestotal.attr,
1241 &lustre_attr_filesfree.attr,
1242 &lustre_attr_client_type.attr,
1243 &lustre_attr_statahead_running_max.attr,
1247 static void llite_kobj_release(struct kobject *kobj)
1249 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1251 complete(&sbi->ll_kobj_unregister);
1254 static struct kobj_type llite_ktype = {
1255 .default_attrs = llite_attrs,
1256 .sysfs_ops = &lustre_sysfs_ops,
1257 .release = llite_kobj_release,
1260 static const struct llite_file_opcode {
1264 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
1265 /* file operation */
1266 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
1267 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
1268 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1270 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1272 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
1274 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
1276 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
1277 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
1278 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
1279 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
1280 { LPROC_LL_FAULT, LPROCFS_TYPE_REGS, "page_fault" },
1281 { LPROC_LL_MKWRITE, LPROCFS_TYPE_REGS, "page_mkwrite" },
1282 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
1283 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
1284 { LPROC_LL_READDIR, LPROCFS_TYPE_REGS, "readdir" },
1285 /* inode operation */
1286 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
1287 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "truncate" },
1288 { LPROC_LL_FLOCK, LPROCFS_TYPE_REGS, "flock" },
1289 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
1290 /* dir inode operation */
1291 { LPROC_LL_CREATE, LPROCFS_TYPE_REGS, "create" },
1292 { LPROC_LL_LINK, LPROCFS_TYPE_REGS, "link" },
1293 { LPROC_LL_UNLINK, LPROCFS_TYPE_REGS, "unlink" },
1294 { LPROC_LL_SYMLINK, LPROCFS_TYPE_REGS, "symlink" },
1295 { LPROC_LL_MKDIR, LPROCFS_TYPE_REGS, "mkdir" },
1296 { LPROC_LL_RMDIR, LPROCFS_TYPE_REGS, "rmdir" },
1297 { LPROC_LL_MKNOD, LPROCFS_TYPE_REGS, "mknod" },
1298 { LPROC_LL_RENAME, LPROCFS_TYPE_REGS, "rename" },
1299 /* special inode operation */
1300 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
1301 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
1302 { LPROC_LL_SETXATTR, LPROCFS_TYPE_REGS, "setxattr" },
1303 { LPROC_LL_GETXATTR, LPROCFS_TYPE_REGS, "getxattr" },
1304 { LPROC_LL_GETXATTR_HITS, LPROCFS_TYPE_REGS, "getxattr_hits" },
1305 { LPROC_LL_LISTXATTR, LPROCFS_TYPE_REGS, "listxattr" },
1306 { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_REGS, "removexattr" },
1307 { LPROC_LL_INODE_PERM, LPROCFS_TYPE_REGS, "inode_permission" },
1310 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
1314 if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
1315 lprocfs_counter_add(sbi->ll_stats, op, count);
1316 else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
1317 sbi->ll_stats_track_id == current->pid)
1318 lprocfs_counter_add(sbi->ll_stats, op, count);
1319 else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
1320 sbi->ll_stats_track_id == current->parent->pid)
1321 lprocfs_counter_add(sbi->ll_stats, op, count);
1322 else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
1323 sbi->ll_stats_track_id ==
1324 from_kgid(&init_user_ns, current_gid()))
1325 lprocfs_counter_add(sbi->ll_stats, op, count);
1327 EXPORT_SYMBOL(ll_stats_ops_tally);
1329 static const char *ra_stat_string[] = {
1330 [RA_STAT_HIT] = "hits",
1331 [RA_STAT_MISS] = "misses",
1332 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
1333 [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
1334 [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page",
1335 [RA_STAT_FAILED_MATCH] = "failed lock match",
1336 [RA_STAT_DISCARDED] = "read but discarded",
1337 [RA_STAT_ZERO_LEN] = "zero length file",
1338 [RA_STAT_ZERO_WINDOW] = "zero size window",
1339 [RA_STAT_EOF] = "read-ahead to EOF",
1340 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
1341 [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",
1342 [RA_STAT_FAILED_REACH_END] = "failed to reach end"
1345 LPROC_SEQ_FOPS_RO_TYPE(llite, name);
1346 LPROC_SEQ_FOPS_RO_TYPE(llite, uuid);
1348 int ll_debugfs_register_super(struct super_block *sb, const char *name)
1350 struct lustre_sb_info *lsi = s2lsi(sb);
1351 struct ll_sb_info *sbi = ll_s2sbi(sb);
1352 struct lprocfs_vars lvars[2];
1356 memset(lvars, 0, sizeof(lvars));
1357 lvars[0].name = name;
1359 LASSERT(sbi != NULL);
1361 sbi->ll_proc_root = lprocfs_register(name, proc_lustre_fs_root,
1363 if (IS_ERR(sbi->ll_proc_root)) {
1364 err = PTR_ERR(sbi->ll_proc_root);
1365 sbi->ll_proc_root = NULL;
1369 rc = lprocfs_seq_create(sbi->ll_proc_root, "dump_page_cache", 0444,
1370 &vvp_dump_pgcache_file_ops, sbi);
1372 CWARN("Error adding the dump_page_cache file\n");
1374 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats", 0644,
1375 &ll_rw_extents_stats_fops, sbi);
1377 CWARN("Error adding the extent_stats file\n");
1379 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats_per_process",
1380 0644, &ll_rw_extents_stats_pp_fops, sbi);
1382 CWARN("Error adding the extents_stats_per_process file\n");
1384 rc = lprocfs_seq_create(sbi->ll_proc_root, "offset_stats", 0644,
1385 &ll_rw_offset_stats_fops, sbi);
1387 CWARN("Error adding the offset_stats file\n");
1389 /* File operations stats */
1390 sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
1391 LPROCFS_STATS_FLAG_NONE);
1392 if (sbi->ll_stats == NULL)
1393 GOTO(out_proc, err = -ENOMEM);
1395 /* do counter init */
1396 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
1397 __u32 type = llite_opcode_table[id].type;
1399 if (type & LPROCFS_TYPE_REGS)
1401 else if (type & LPROCFS_TYPE_BYTES)
1403 else if (type & LPROCFS_TYPE_PAGES)
1405 lprocfs_counter_init(sbi->ll_stats,
1406 llite_opcode_table[id].opcode,
1407 (type & LPROCFS_CNTR_AVGMINMAX),
1408 llite_opcode_table[id].opname, ptr);
1411 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats);
1413 GOTO(out_stats, err);
1415 sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
1416 LPROCFS_STATS_FLAG_NONE);
1417 if (sbi->ll_ra_stats == NULL)
1418 GOTO(out_stats, err = -ENOMEM);
1420 for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
1421 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
1422 ra_stat_string[id], "pages");
1423 err = lprocfs_register_stats(sbi->ll_proc_root, "read_ahead_stats",
1426 GOTO(out_ra_stats, err);
1428 err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_llite_obd_vars, sb);
1430 GOTO(out_ra_stats, err);
1432 /* Yes we also register sysfs mount kset here as well */
1433 sbi->ll_kset.kobj.parent = llite_kobj;
1434 sbi->ll_kset.kobj.ktype = &llite_ktype;
1435 init_completion(&sbi->ll_kobj_unregister);
1436 err = kobject_set_name(&sbi->ll_kset.kobj, "%s", name);
1438 GOTO(out_ra_stats, err);
1440 err = kset_register(&sbi->ll_kset);
1442 GOTO(out_ra_stats, err);
1444 lsi->lsi_kobj = kobject_get(&sbi->ll_kset.kobj);
1448 lprocfs_free_stats(&sbi->ll_ra_stats);
1450 lprocfs_free_stats(&sbi->ll_stats);
1452 lprocfs_remove(&sbi->ll_proc_root);
1457 int lprocfs_ll_register_obd(struct super_block *sb, const char *obdname)
1459 struct lprocfs_vars lvars[2];
1460 struct ll_sb_info *sbi = ll_s2sbi(sb);
1461 struct obd_device *obd;
1462 struct proc_dir_entry *dir;
1463 char name[MAX_STRING_SIZE + 1];
1467 memset(lvars, 0, sizeof(lvars));
1469 name[MAX_STRING_SIZE] = '\0';
1470 lvars[0].name = name;
1472 LASSERT(sbi != NULL);
1473 LASSERT(obdname != NULL);
1475 obd = class_name2obd(obdname);
1477 LASSERT(obd != NULL);
1478 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1479 LASSERT(obd->obd_type->typ_name != NULL);
1481 dir = proc_mkdir(obd->obd_type->typ_name, sbi->ll_proc_root);
1483 GOTO(out, err = -ENOMEM);
1485 snprintf(name, MAX_STRING_SIZE, "common_name");
1486 lvars[0].fops = &llite_name_fops;
1487 err = lprocfs_add_vars(dir, lvars, obd);
1491 snprintf(name, MAX_STRING_SIZE, "uuid");
1492 lvars[0].fops = &llite_uuid_fops;
1493 err = lprocfs_add_vars(dir, lvars, obd);
1499 lprocfs_remove(&sbi->ll_proc_root);
1500 lprocfs_free_stats(&sbi->ll_ra_stats);
1501 lprocfs_free_stats(&sbi->ll_stats);
1506 void ll_debugfs_unregister_super(struct super_block *sb)
1508 struct lustre_sb_info *lsi = s2lsi(sb);
1509 struct ll_sb_info *sbi = ll_s2sbi(sb);
1511 kobject_put(lsi->lsi_kobj);
1513 kset_unregister(&sbi->ll_kset);
1514 wait_for_completion(&sbi->ll_kobj_unregister);
1516 if (sbi->ll_proc_root) {
1517 lprocfs_remove(&sbi->ll_proc_root);
1518 lprocfs_free_stats(&sbi->ll_ra_stats);
1519 lprocfs_free_stats(&sbi->ll_stats);
1522 #undef MAX_STRING_SIZE
1524 #define pct(a,b) (b ? a * 100 / b : 0)
1526 static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
1527 struct seq_file *seq, int which)
1529 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
1530 unsigned long start, end, r, w;
1531 char *unitp = "KMGTPEZY";
1533 struct per_process_info *pp_info = &io_extents->pp_extents[which];
1539 for(i = 0; i < LL_HIST_MAX; i++) {
1540 read_tot += pp_info->pp_r_hist.oh_buckets[i];
1541 write_tot += pp_info->pp_w_hist.oh_buckets[i];
1544 for(i = 0; i < LL_HIST_MAX; i++) {
1545 r = pp_info->pp_r_hist.oh_buckets[i];
1546 w = pp_info->pp_w_hist.oh_buckets[i];
1549 end = 1 << (i + LL_HIST_START - units);
1550 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu | "
1551 "%14lu %4lu %4lu\n", start, *unitp, end, *unitp,
1552 (i == LL_HIST_MAX - 1) ? '+' : ' ',
1553 r, pct(r, read_tot), pct(read_cum, read_tot),
1554 w, pct(w, write_tot), pct(write_cum, write_tot));
1556 if (start == 1<<10) {
1561 if (read_cum == read_tot && write_cum == write_tot)
1566 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
1568 struct timespec64 now;
1569 struct ll_sb_info *sbi = seq->private;
1570 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1573 ktime_get_real_ts64(&now);
1575 if (!sbi->ll_rw_stats_on) {
1576 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
1579 seq_printf(seq, "snapshot_time: %llu.%09lu (secs.nsecs)\n",
1580 (s64)now.tv_sec, now.tv_nsec);
1581 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1582 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1583 "extents", "calls", "%", "cum%",
1584 "calls", "%", "cum%");
1585 spin_lock(&sbi->ll_pp_extent_lock);
1586 for (k = 0; k < LL_PROCESS_HIST_MAX; k++) {
1587 if (io_extents->pp_extents[k].pid != 0) {
1588 seq_printf(seq, "\nPID: %d\n",
1589 io_extents->pp_extents[k].pid);
1590 ll_display_extents_info(io_extents, seq, k);
1593 spin_unlock(&sbi->ll_pp_extent_lock);
1597 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
1598 const char __user *buf,
1602 struct seq_file *seq = file->private_data;
1603 struct ll_sb_info *sbi = seq->private;
1604 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1611 value = ll_stats_pid_write(buf, len);
1614 sbi->ll_rw_stats_on = 0;
1616 sbi->ll_rw_stats_on = 1;
1618 spin_lock(&sbi->ll_pp_extent_lock);
1619 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1620 io_extents->pp_extents[i].pid = 0;
1621 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1622 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1624 spin_unlock(&sbi->ll_pp_extent_lock);
1628 LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
1630 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
1632 struct timespec64 now;
1633 struct ll_sb_info *sbi = seq->private;
1634 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1636 ktime_get_real_ts64(&now);
1638 if (!sbi->ll_rw_stats_on) {
1639 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
1642 seq_printf(seq, "snapshot_time: %llu.%09lu (secs.nsecs)\n",
1643 (s64)now.tv_sec, now.tv_nsec);
1645 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1646 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1647 "extents", "calls", "%", "cum%",
1648 "calls", "%", "cum%");
1649 spin_lock(&sbi->ll_lock);
1650 ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
1651 spin_unlock(&sbi->ll_lock);
1656 static ssize_t ll_rw_extents_stats_seq_write(struct file *file,
1657 const char __user *buf,
1658 size_t len, loff_t *off)
1660 struct seq_file *seq = file->private_data;
1661 struct ll_sb_info *sbi = seq->private;
1662 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1669 value = ll_stats_pid_write(buf, len);
1672 sbi->ll_rw_stats_on = 0;
1674 sbi->ll_rw_stats_on = 1;
1676 spin_lock(&sbi->ll_pp_extent_lock);
1677 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
1678 io_extents->pp_extents[i].pid = 0;
1679 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1680 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1682 spin_unlock(&sbi->ll_pp_extent_lock);
1686 LPROC_SEQ_FOPS(ll_rw_extents_stats);
1688 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
1689 struct ll_file_data *file, loff_t pos,
1690 size_t count, int rw)
1693 struct ll_rw_process_info *process;
1694 struct ll_rw_process_info *offset;
1695 int *off_count = &sbi->ll_rw_offset_entry_count;
1696 int *process_count = &sbi->ll_offset_process_count;
1697 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1699 if(!sbi->ll_rw_stats_on)
1701 process = sbi->ll_rw_process_info;
1702 offset = sbi->ll_rw_offset_info;
1704 spin_lock(&sbi->ll_pp_extent_lock);
1705 /* Extent statistics */
1706 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1707 if(io_extents->pp_extents[i].pid == pid) {
1715 sbi->ll_extent_process_count =
1716 (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1717 cur = sbi->ll_extent_process_count;
1718 io_extents->pp_extents[cur].pid = pid;
1719 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1720 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1723 for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
1724 (i < (LL_HIST_MAX - 1)); i++);
1726 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1727 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1729 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1730 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1732 spin_unlock(&sbi->ll_pp_extent_lock);
1734 spin_lock(&sbi->ll_process_lock);
1735 /* Offset statistics */
1736 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1737 if (process[i].rw_pid == pid) {
1738 if (process[i].rw_last_file != file) {
1739 process[i].rw_range_start = pos;
1740 process[i].rw_last_file_pos = pos + count;
1741 process[i].rw_smallest_extent = count;
1742 process[i].rw_largest_extent = count;
1743 process[i].rw_offset = 0;
1744 process[i].rw_last_file = file;
1745 spin_unlock(&sbi->ll_process_lock);
1748 if (process[i].rw_last_file_pos != pos) {
1750 (*off_count + 1) % LL_OFFSET_HIST_MAX;
1751 offset[*off_count].rw_op = process[i].rw_op;
1752 offset[*off_count].rw_pid = pid;
1753 offset[*off_count].rw_range_start =
1754 process[i].rw_range_start;
1755 offset[*off_count].rw_range_end =
1756 process[i].rw_last_file_pos;
1757 offset[*off_count].rw_smallest_extent =
1758 process[i].rw_smallest_extent;
1759 offset[*off_count].rw_largest_extent =
1760 process[i].rw_largest_extent;
1761 offset[*off_count].rw_offset =
1762 process[i].rw_offset;
1763 process[i].rw_op = rw;
1764 process[i].rw_range_start = pos;
1765 process[i].rw_smallest_extent = count;
1766 process[i].rw_largest_extent = count;
1767 process[i].rw_offset = pos -
1768 process[i].rw_last_file_pos;
1770 if(process[i].rw_smallest_extent > count)
1771 process[i].rw_smallest_extent = count;
1772 if(process[i].rw_largest_extent < count)
1773 process[i].rw_largest_extent = count;
1774 process[i].rw_last_file_pos = pos + count;
1775 spin_unlock(&sbi->ll_process_lock);
1779 *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
1780 process[*process_count].rw_pid = pid;
1781 process[*process_count].rw_op = rw;
1782 process[*process_count].rw_range_start = pos;
1783 process[*process_count].rw_last_file_pos = pos + count;
1784 process[*process_count].rw_smallest_extent = count;
1785 process[*process_count].rw_largest_extent = count;
1786 process[*process_count].rw_offset = 0;
1787 process[*process_count].rw_last_file = file;
1788 spin_unlock(&sbi->ll_process_lock);
1791 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1793 struct timespec64 now;
1794 struct ll_sb_info *sbi = seq->private;
1795 struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
1796 struct ll_rw_process_info *process = sbi->ll_rw_process_info;
1799 ktime_get_real_ts64(&now);
1801 if (!sbi->ll_rw_stats_on) {
1802 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
1805 spin_lock(&sbi->ll_process_lock);
1807 seq_printf(seq, "snapshot_time: %llu.%09lu (secs.nsecs)\n",
1808 (s64)now.tv_sec, now.tv_nsec);
1809 seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
1810 "R/W", "PID", "RANGE START", "RANGE END",
1811 "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
1813 /* We stored the discontiguous offsets here; print them first */
1814 for (i = 0; i < LL_OFFSET_HIST_MAX; i++) {
1815 if (offset[i].rw_pid != 0)
1817 "%3c %10d %14llu %14llu %17lu %17lu %14llu\n",
1818 offset[i].rw_op == READ ? 'R' : 'W',
1820 offset[i].rw_range_start,
1821 offset[i].rw_range_end,
1822 (unsigned long)offset[i].rw_smallest_extent,
1823 (unsigned long)offset[i].rw_largest_extent,
1824 offset[i].rw_offset);
1827 /* Then print the current offsets for each process */
1828 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1829 if (process[i].rw_pid != 0)
1831 "%3c %10d %14llu %14llu %17lu %17lu %14llu\n",
1832 process[i].rw_op == READ ? 'R' : 'W',
1834 process[i].rw_range_start,
1835 process[i].rw_last_file_pos,
1836 (unsigned long)process[i].rw_smallest_extent,
1837 (unsigned long)process[i].rw_largest_extent,
1838 process[i].rw_offset);
1840 spin_unlock(&sbi->ll_process_lock);
1845 static ssize_t ll_rw_offset_stats_seq_write(struct file *file,
1846 const char __user *buf,
1847 size_t len, loff_t *off)
1849 struct seq_file *seq = file->private_data;
1850 struct ll_sb_info *sbi = seq->private;
1851 struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
1852 struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
1858 value = ll_stats_pid_write(buf, len);
1861 sbi->ll_rw_stats_on = 0;
1863 sbi->ll_rw_stats_on = 1;
1865 spin_lock(&sbi->ll_process_lock);
1866 sbi->ll_offset_process_count = 0;
1867 sbi->ll_rw_offset_entry_count = 0;
1868 memset(process_info, 0, sizeof(struct ll_rw_process_info) *
1869 LL_PROCESS_HIST_MAX);
1870 memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
1871 LL_OFFSET_HIST_MAX);
1872 spin_unlock(&sbi->ll_process_lock);
1878 * ll_stats_pid_write() - Determine if stats collection should be enabled
1879 * @buf: Buffer containing the data written
1880 * @len: Number of bytes in the buffer
1882 * Several proc files begin collecting stats when a value is written, and stop
1883 * collecting when either '0' or 'disable' is written. This function checks the
1884 * written value to see if collection should be enabled or disabled.
1886 * Return: If '0' or 'disable' is provided, 0 is returned. If the text
1887 * equivalent of a number is written, that number is returned. Otherwise,
1888 * 1 is returned. Non-zero return values indicate collection should be enabled.
1890 static __s64 ll_stats_pid_write(const char __user *buf, size_t len)
1892 unsigned long long value = 1;
1896 rc = kstrtoull_from_user(buf, len, 0, &value);
1897 if (rc < 0 && len < sizeof(kernbuf)) {
1899 if (copy_from_user(kernbuf, buf, len))
1903 if (kernbuf[len - 1] == '\n')
1904 kernbuf[len - 1] = 0;
1906 if (strncasecmp(kernbuf, "disable", 7) == 0)
1913 LPROC_SEQ_FOPS(ll_rw_offset_stats);
1914 #endif /* CONFIG_PROC_FS */