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 ssize_t fstype_show(struct kobject *kobj, struct attribute *attr,
248 return sprintf(buf, "lustre\n");
250 LUSTRE_RO_ATTR(fstype);
252 static ssize_t uuid_show(struct kobject *kobj, struct attribute *attr,
255 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
258 return sprintf(buf, "%s\n", sbi->ll_sb_uuid.uuid);
260 LUSTRE_RO_ATTR(uuid);
262 static int ll_xattr_cache_seq_show(struct seq_file *m, void *v)
264 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
266 seq_printf(m, "%u\n", sbi->ll_xattr_cache_enabled);
270 static ssize_t ll_xattr_cache_seq_write(struct file *file,
271 const char __user *buffer,
272 size_t count, loff_t *off)
274 struct seq_file *m = file->private_data;
275 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
279 rc = kstrtobool_from_user(buffer, count, &val);
283 if (val && !(sbi->ll_flags & LL_SBI_XATTR_CACHE))
286 sbi->ll_xattr_cache_enabled = val;
287 sbi->ll_xattr_cache_set = 1;
291 LPROC_SEQ_FOPS(ll_xattr_cache);
293 static int ll_site_stats_seq_show(struct seq_file *m, void *v)
295 struct super_block *sb = m->private;
298 * See description of statistical counters in struct cl_site, and
301 return cl_site_stats_print(lu2cl_site(ll_s2sbi(sb)->ll_site), m);
303 LPROC_SEQ_FOPS_RO(ll_site_stats);
305 static int ll_max_readahead_mb_seq_show(struct seq_file *m, void *v)
307 struct super_block *sb = m->private;
308 struct ll_sb_info *sbi = ll_s2sbi(sb);
312 spin_lock(&sbi->ll_lock);
313 pages_number = sbi->ll_ra_info.ra_max_pages;
314 spin_unlock(&sbi->ll_lock);
316 mult = 1 << (20 - PAGE_SHIFT);
317 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
321 ll_max_readahead_mb_seq_write(struct file *file, const char __user *buffer,
322 size_t count, loff_t *off)
324 struct seq_file *m = file->private_data;
325 struct super_block *sb = m->private;
326 struct ll_sb_info *sbi = ll_s2sbi(sb);
330 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
334 pages_number >>= PAGE_SHIFT;
336 if (pages_number < 0 || pages_number > totalram_pages / 2) {
338 CERROR("%s: can't set max_readahead_mb=%lu > %luMB\n",
339 ll_get_fsname(sb, NULL, 0),
340 (unsigned long)pages_number >> (20 - PAGE_SHIFT),
341 totalram_pages >> (20 - PAGE_SHIFT + 1));
345 spin_lock(&sbi->ll_lock);
346 sbi->ll_ra_info.ra_max_pages = pages_number;
347 spin_unlock(&sbi->ll_lock);
350 LPROC_SEQ_FOPS(ll_max_readahead_mb);
352 static int ll_max_readahead_per_file_mb_seq_show(struct seq_file *m, void *v)
354 struct super_block *sb = m->private;
355 struct ll_sb_info *sbi = ll_s2sbi(sb);
359 spin_lock(&sbi->ll_lock);
360 pages_number = sbi->ll_ra_info.ra_max_pages_per_file;
361 spin_unlock(&sbi->ll_lock);
363 mult = 1 << (20 - PAGE_SHIFT);
364 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
368 ll_max_readahead_per_file_mb_seq_write(struct file *file,
369 const char __user *buffer,
370 size_t count, loff_t *off)
372 struct seq_file *m = file->private_data;
373 struct super_block *sb = m->private;
374 struct ll_sb_info *sbi = ll_s2sbi(sb);
378 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
382 pages_number >>= PAGE_SHIFT;
384 if (pages_number < 0 || pages_number > sbi->ll_ra_info.ra_max_pages) {
385 CERROR("%s: can't set max_readahead_per_file_mb=%lu > "
386 "max_read_ahead_mb=%lu\n", ll_get_fsname(sb, NULL, 0),
387 (unsigned long)pages_number >> (20 - PAGE_SHIFT),
388 sbi->ll_ra_info.ra_max_pages >> (20 - PAGE_SHIFT));
392 spin_lock(&sbi->ll_lock);
393 sbi->ll_ra_info.ra_max_pages_per_file = pages_number;
394 spin_unlock(&sbi->ll_lock);
397 LPROC_SEQ_FOPS(ll_max_readahead_per_file_mb);
399 static int ll_max_read_ahead_whole_mb_seq_show(struct seq_file *m, void *v)
401 struct super_block *sb = m->private;
402 struct ll_sb_info *sbi = ll_s2sbi(sb);
406 spin_lock(&sbi->ll_lock);
407 pages_number = sbi->ll_ra_info.ra_max_read_ahead_whole_pages;
408 spin_unlock(&sbi->ll_lock);
410 mult = 1 << (20 - PAGE_SHIFT);
411 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
415 ll_max_read_ahead_whole_mb_seq_write(struct file *file,
416 const char __user *buffer,
417 size_t count, loff_t *off)
419 struct seq_file *m = file->private_data;
420 struct super_block *sb = m->private;
421 struct ll_sb_info *sbi = ll_s2sbi(sb);
425 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
429 pages_number >>= PAGE_SHIFT;
431 /* Cap this at the current max readahead window size, the readahead
432 * algorithm does this anyway so it's pointless to set it larger. */
433 if (pages_number < 0 ||
434 pages_number > sbi->ll_ra_info.ra_max_pages_per_file) {
435 int pages_shift = 20 - PAGE_SHIFT;
436 CERROR("%s: can't set max_read_ahead_whole_mb=%lu > "
437 "max_read_ahead_per_file_mb=%lu\n",
438 ll_get_fsname(sb, NULL, 0),
439 (unsigned long)pages_number >> pages_shift,
440 sbi->ll_ra_info.ra_max_pages_per_file >> pages_shift);
444 spin_lock(&sbi->ll_lock);
445 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = pages_number;
446 spin_unlock(&sbi->ll_lock);
449 LPROC_SEQ_FOPS(ll_max_read_ahead_whole_mb);
451 static int ll_max_cached_mb_seq_show(struct seq_file *m, void *v)
453 struct super_block *sb = m->private;
454 struct ll_sb_info *sbi = ll_s2sbi(sb);
455 struct cl_client_cache *cache = sbi->ll_cache;
456 int shift = 20 - PAGE_SHIFT;
460 max_cached_mb = cache->ccc_lru_max >> shift;
461 unused_mb = atomic_long_read(&cache->ccc_lru_left) >> shift;
462 seq_printf(m, "users: %d\n"
463 "max_cached_mb: %ld\n"
466 "reclaim_count: %u\n",
467 atomic_read(&cache->ccc_users),
469 max_cached_mb - unused_mb,
471 cache->ccc_lru_shrinkers);
476 ll_max_cached_mb_seq_write(struct file *file, const char __user *buffer,
477 size_t count, loff_t *off)
479 struct seq_file *m = file->private_data;
480 struct super_block *sb = m->private;
481 struct ll_sb_info *sbi = ll_s2sbi(sb);
482 struct cl_client_cache *cache = sbi->ll_cache;
492 if (count >= sizeof(kernbuf))
495 if (copy_from_user(kernbuf, buffer, count))
499 buffer += lprocfs_find_named_value(kernbuf, "max_cached_mb:", &count) -
501 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
505 pages_number >>= PAGE_SHIFT;
507 if (pages_number < 0 || pages_number > totalram_pages) {
508 CERROR("%s: can't set max cache more than %lu MB\n",
509 ll_get_fsname(sb, NULL, 0),
510 totalram_pages >> (20 - PAGE_SHIFT));
513 /* Allow enough cache so clients can make well-formed RPCs */
514 pages_number = max_t(long, pages_number, PTLRPC_MAX_BRW_PAGES);
516 spin_lock(&sbi->ll_lock);
517 diff = pages_number - cache->ccc_lru_max;
518 spin_unlock(&sbi->ll_lock);
520 /* easy - add more LRU slots. */
522 atomic_long_add(diff, &cache->ccc_lru_left);
526 env = cl_env_get(&refcheck);
534 /* reduce LRU budget from free slots. */
538 ov = atomic_long_read(&cache->ccc_lru_left);
542 nv = ov > diff ? ov - diff : 0;
543 rc = atomic_long_cmpxchg(&cache->ccc_lru_left, ov, nv);
544 if (likely(ov == rc)) {
554 if (sbi->ll_dt_exp == NULL) { /* being initialized */
559 /* difficult - have to ask OSCs to drop LRU slots. */
561 rc = obd_set_info_async(env, sbi->ll_dt_exp,
562 sizeof(KEY_CACHE_LRU_SHRINK),
563 KEY_CACHE_LRU_SHRINK,
564 sizeof(tmp), &tmp, NULL);
568 cl_env_put(env, &refcheck);
572 spin_lock(&sbi->ll_lock);
573 cache->ccc_lru_max = pages_number;
574 spin_unlock(&sbi->ll_lock);
577 atomic_long_add(nrpages, &cache->ccc_lru_left);
581 LPROC_SEQ_FOPS(ll_max_cached_mb);
583 static ssize_t checksum_pages_show(struct kobject *kobj, struct attribute *attr,
586 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
589 return sprintf(buf, "%u\n", (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0);
592 static ssize_t checksum_pages_store(struct kobject *kobj,
593 struct attribute *attr,
597 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
607 rc = kstrtobool(buffer, &val);
611 sbi->ll_flags |= LL_SBI_CHECKSUM;
613 sbi->ll_flags &= ~LL_SBI_CHECKSUM;
616 rc = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
617 KEY_CHECKSUM, sizeof(tmp), &tmp, NULL);
619 CWARN("Failed to set OSC checksum flags: %d\n", rc);
623 LUSTRE_RW_ATTR(checksum_pages);
625 static ssize_t ll_rd_track_id(struct kobject *kobj, char *buf,
626 enum stats_track_type type)
628 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
631 if (sbi->ll_stats_track_type == type)
632 return sprintf(buf, "%d\n", sbi->ll_stats_track_id);
633 else if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
634 return sprintf(buf, "0 (all)\n");
636 return sprintf(buf, "untracked\n");
639 static ssize_t ll_wr_track_id(struct kobject *kobj, const char *buffer,
640 size_t count, enum stats_track_type type)
642 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
647 rc = kstrtoul(buffer, 10, &pid);
651 sbi->ll_stats_track_id = pid;
653 sbi->ll_stats_track_type = STATS_TRACK_ALL;
655 sbi->ll_stats_track_type = type;
656 lprocfs_clear_stats(sbi->ll_stats);
660 static ssize_t stats_track_pid_show(struct kobject *kobj,
661 struct attribute *attr,
664 return ll_rd_track_id(kobj, buf, STATS_TRACK_PID);
667 static ssize_t stats_track_pid_store(struct kobject *kobj,
668 struct attribute *attr,
672 return ll_wr_track_id(kobj, buffer, count, STATS_TRACK_PID);
674 LUSTRE_RW_ATTR(stats_track_pid);
676 static ssize_t stats_track_ppid_show(struct kobject *kobj,
677 struct attribute *attr,
680 return ll_rd_track_id(kobj, buf, STATS_TRACK_PPID);
683 static ssize_t stats_track_ppid_store(struct kobject *kobj,
684 struct attribute *attr,
688 return ll_wr_track_id(kobj, buffer, count, STATS_TRACK_PPID);
690 LUSTRE_RW_ATTR(stats_track_ppid);
692 static ssize_t stats_track_gid_show(struct kobject *kobj,
693 struct attribute *attr,
696 return ll_rd_track_id(kobj, buf, STATS_TRACK_GID);
699 static ssize_t stats_track_gid_store(struct kobject *kobj,
700 struct attribute *attr,
704 return ll_wr_track_id(kobj, buffer, count, STATS_TRACK_GID);
706 LUSTRE_RW_ATTR(stats_track_gid);
708 static ssize_t statahead_running_max_show(struct kobject *kobj,
709 struct attribute *attr,
712 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
715 return snprintf(buf, 16, "%u\n", sbi->ll_sa_running_max);
718 static ssize_t statahead_running_max_store(struct kobject *kobj,
719 struct attribute *attr,
723 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
728 rc = kstrtoul(buffer, 0, &val);
732 if (val <= LL_SA_RUNNING_MAX) {
733 sbi->ll_sa_running_max = val;
737 CERROR("Bad statahead_running_max value %lu. Valid values "
738 "are in the range [0, %d]\n", val, LL_SA_RUNNING_MAX);
742 LUSTRE_RW_ATTR(statahead_running_max);
744 static int ll_statahead_max_seq_show(struct seq_file *m, void *v)
746 struct super_block *sb = m->private;
747 struct ll_sb_info *sbi = ll_s2sbi(sb);
749 seq_printf(m, "%u\n", sbi->ll_sa_max);
753 static ssize_t ll_statahead_max_seq_write(struct file *file,
754 const char __user *buffer,
755 size_t count, loff_t *off)
757 struct seq_file *m = file->private_data;
758 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
762 rc = kstrtouint_from_user(buffer, count, 0, &val);
766 if (val <= LL_SA_RPC_MAX)
767 sbi->ll_sa_max = val;
769 CERROR("Bad statahead_max value %u. Valid values are in "
770 "the range [0, %d]\n", val, LL_SA_RPC_MAX);
774 LPROC_SEQ_FOPS(ll_statahead_max);
776 static int ll_statahead_agl_seq_show(struct seq_file *m, void *v)
778 struct super_block *sb = m->private;
779 struct ll_sb_info *sbi = ll_s2sbi(sb);
781 seq_printf(m, "%u\n",
782 sbi->ll_flags & LL_SBI_AGL_ENABLED ? 1 : 0);
786 static ssize_t ll_statahead_agl_seq_write(struct file *file,
787 const char __user *buffer,
788 size_t count, loff_t *off)
790 struct seq_file *m = file->private_data;
791 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
795 rc = kstrtobool_from_user(buffer, count, &val);
800 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
802 sbi->ll_flags &= ~LL_SBI_AGL_ENABLED;
806 LPROC_SEQ_FOPS(ll_statahead_agl);
808 static int ll_statahead_stats_seq_show(struct seq_file *m, void *v)
810 struct super_block *sb = m->private;
811 struct ll_sb_info *sbi = ll_s2sbi(sb);
813 seq_printf(m, "statahead total: %u\n"
814 "statahead wrong: %u\n"
816 atomic_read(&sbi->ll_sa_total),
817 atomic_read(&sbi->ll_sa_wrong),
818 atomic_read(&sbi->ll_agl_total));
821 LPROC_SEQ_FOPS_RO(ll_statahead_stats);
823 static int ll_lazystatfs_seq_show(struct seq_file *m, void *v)
825 struct super_block *sb = m->private;
826 struct ll_sb_info *sbi = ll_s2sbi(sb);
828 seq_printf(m, "%u\n",
829 (sbi->ll_flags & LL_SBI_LAZYSTATFS) ? 1 : 0);
833 static ssize_t ll_lazystatfs_seq_write(struct file *file,
834 const char __user *buffer,
835 size_t count, loff_t *off)
837 struct seq_file *m = file->private_data;
838 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
842 rc = kstrtobool_from_user(buffer, count, &val);
847 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
849 sbi->ll_flags &= ~LL_SBI_LAZYSTATFS;
853 LPROC_SEQ_FOPS(ll_lazystatfs);
855 static int ll_max_easize_seq_show(struct seq_file *m, void *v)
857 struct super_block *sb = m->private;
858 struct ll_sb_info *sbi = ll_s2sbi(sb);
862 rc = ll_get_max_mdsize(sbi, &ealen);
866 seq_printf(m, "%u\n", ealen);
869 LPROC_SEQ_FOPS_RO(ll_max_easize);
872 * Get default_easize.
874 * \see client_obd::cl_default_mds_easize
876 * \param[in] m seq_file handle
877 * \param[in] v unused for single entry
879 * \retval 0 on success
880 * \retval negative negated errno on failure
882 static int ll_default_easize_seq_show(struct seq_file *m, void *v)
884 struct super_block *sb = m->private;
885 struct ll_sb_info *sbi = ll_s2sbi(sb);
889 rc = ll_get_default_mdsize(sbi, &ealen);
893 seq_printf(m, "%u\n", ealen);
898 * Set default_easize.
900 * Range checking on the passed value is handled by
901 * ll_set_default_mdsize().
903 * \see client_obd::cl_default_mds_easize
905 * \param[in] file proc file
906 * \param[in] buffer string passed from user space
907 * \param[in] count \a buffer length
908 * \param[in] off unused for single entry
910 * \retval positive \a count on success
911 * \retval negative negated errno on failure
913 static ssize_t ll_default_easize_seq_write(struct file *file,
914 const char __user *buffer,
915 size_t count, loff_t *unused)
917 struct seq_file *seq = file->private_data;
918 struct super_block *sb = (struct super_block *)seq->private;
919 struct ll_sb_info *sbi = ll_s2sbi(sb);
926 rc = kstrtouint_from_user(buffer, count, 0, &val);
930 rc = ll_set_default_mdsize(sbi, val);
936 LPROC_SEQ_FOPS(ll_default_easize);
938 static int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
940 const char *str[] = LL_SBI_FLAGS;
941 struct super_block *sb = m->private;
942 int flags = ll_s2sbi(sb)->ll_flags;
946 if (ARRAY_SIZE(str) <= i) {
947 CERROR("%s: Revise array LL_SBI_FLAGS to match sbi "
948 "flags please.\n", ll_get_fsname(sb, NULL, 0));
953 seq_printf(m, "%s ", str[i]);
957 seq_printf(m, "\b\n");
960 LPROC_SEQ_FOPS_RO(ll_sbi_flags);
962 static int ll_tiny_write_seq_show(struct seq_file *m, void *v)
964 struct super_block *sb = m->private;
965 struct ll_sb_info *sbi = ll_s2sbi(sb);
967 seq_printf(m, "%u\n", !!(sbi->ll_flags & LL_SBI_TINY_WRITE));
971 static ssize_t ll_tiny_write_seq_write(
972 struct file *file, const char __user *buffer, size_t count, loff_t *off)
974 struct seq_file *m = file->private_data;
975 struct super_block *sb = m->private;
976 struct ll_sb_info *sbi = ll_s2sbi(sb);
980 rc = kstrtobool_from_user(buffer, count, &val);
984 spin_lock(&sbi->ll_lock);
986 sbi->ll_flags |= LL_SBI_TINY_WRITE;
988 sbi->ll_flags &= ~LL_SBI_TINY_WRITE;
989 spin_unlock(&sbi->ll_lock);
993 LPROC_SEQ_FOPS(ll_tiny_write);
995 static int ll_fast_read_seq_show(struct seq_file *m, void *v)
997 struct super_block *sb = m->private;
998 struct ll_sb_info *sbi = ll_s2sbi(sb);
1000 seq_printf(m, "%u\n", !!(sbi->ll_flags & LL_SBI_FAST_READ));
1005 ll_fast_read_seq_write(struct file *file, const char __user *buffer,
1006 size_t count, loff_t *off)
1008 struct seq_file *m = file->private_data;
1009 struct super_block *sb = m->private;
1010 struct ll_sb_info *sbi = ll_s2sbi(sb);
1014 rc = kstrtobool_from_user(buffer, count, &val);
1018 spin_lock(&sbi->ll_lock);
1020 sbi->ll_flags |= LL_SBI_FAST_READ;
1022 sbi->ll_flags &= ~LL_SBI_FAST_READ;
1023 spin_unlock(&sbi->ll_lock);
1027 LPROC_SEQ_FOPS(ll_fast_read);
1029 static int ll_pio_seq_show(struct seq_file *m, void *v)
1031 struct super_block *sb = m->private;
1032 struct ll_sb_info *sbi = ll_s2sbi(sb);
1034 seq_printf(m, "%u\n", !!(sbi->ll_flags & LL_SBI_PIO));
1038 static ssize_t ll_pio_seq_write(struct file *file, const char __user *buffer,
1039 size_t count, loff_t *off)
1041 struct seq_file *m = file->private_data;
1042 struct super_block *sb = m->private;
1043 struct ll_sb_info *sbi = ll_s2sbi(sb);
1047 rc = kstrtobool_from_user(buffer, count, &val);
1051 spin_lock(&sbi->ll_lock);
1053 sbi->ll_flags |= LL_SBI_PIO;
1055 sbi->ll_flags &= ~LL_SBI_PIO;
1056 spin_unlock(&sbi->ll_lock);
1060 LPROC_SEQ_FOPS(ll_pio);
1062 static int ll_unstable_stats_seq_show(struct seq_file *m, void *v)
1064 struct super_block *sb = m->private;
1065 struct ll_sb_info *sbi = ll_s2sbi(sb);
1066 struct cl_client_cache *cache = sbi->ll_cache;
1070 pages = atomic_long_read(&cache->ccc_unstable_nr);
1071 mb = (pages * PAGE_SIZE) >> 20;
1073 seq_printf(m, "unstable_check: %8d\n"
1074 "unstable_pages: %12ld\n"
1075 "unstable_mb: %8d\n",
1076 cache->ccc_unstable_check, pages, mb);
1080 static ssize_t ll_unstable_stats_seq_write(struct file *file,
1081 const char __user *buffer,
1082 size_t count, loff_t *unused)
1084 struct seq_file *seq = file->private_data;
1085 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)seq->private);
1092 if (count >= sizeof(kernbuf))
1095 if (copy_from_user(kernbuf, buffer, count))
1099 buffer += lprocfs_find_named_value(kernbuf, "unstable_check:", &count) -
1101 rc = kstrtobool_from_user(buffer, count, &val);
1105 /* borrow lru lock to set the value */
1106 spin_lock(&sbi->ll_cache->ccc_lru_lock);
1107 sbi->ll_cache->ccc_unstable_check = val;
1108 spin_unlock(&sbi->ll_cache->ccc_lru_lock);
1112 LPROC_SEQ_FOPS(ll_unstable_stats);
1114 static int ll_root_squash_seq_show(struct seq_file *m, void *v)
1116 struct super_block *sb = m->private;
1117 struct ll_sb_info *sbi = ll_s2sbi(sb);
1118 struct root_squash_info *squash = &sbi->ll_squash;
1120 seq_printf(m, "%u:%u\n", squash->rsi_uid, squash->rsi_gid);
1124 static ssize_t ll_root_squash_seq_write(struct file *file,
1125 const char __user *buffer,
1126 size_t count, loff_t *off)
1128 struct seq_file *m = file->private_data;
1129 struct super_block *sb = m->private;
1130 struct ll_sb_info *sbi = ll_s2sbi(sb);
1131 struct root_squash_info *squash = &sbi->ll_squash;
1133 return lprocfs_wr_root_squash(buffer, count, squash,
1134 ll_get_fsname(sb, NULL, 0));
1136 LPROC_SEQ_FOPS(ll_root_squash);
1138 static int ll_nosquash_nids_seq_show(struct seq_file *m, void *v)
1140 struct super_block *sb = m->private;
1141 struct ll_sb_info *sbi = ll_s2sbi(sb);
1142 struct root_squash_info *squash = &sbi->ll_squash;
1145 down_read(&squash->rsi_sem);
1146 if (!list_empty(&squash->rsi_nosquash_nids)) {
1147 len = cfs_print_nidlist(m->buf + m->count, m->size - m->count,
1148 &squash->rsi_nosquash_nids);
1152 seq_puts(m, "NONE\n");
1154 up_read(&squash->rsi_sem);
1159 static ssize_t ll_nosquash_nids_seq_write(struct file *file,
1160 const char __user *buffer,
1161 size_t count, loff_t *off)
1163 struct seq_file *m = file->private_data;
1164 struct super_block *sb = m->private;
1165 struct ll_sb_info *sbi = ll_s2sbi(sb);
1166 struct root_squash_info *squash = &sbi->ll_squash;
1169 rc = lprocfs_wr_nosquash_nids(buffer, count, squash,
1170 ll_get_fsname(sb, NULL, 0));
1174 ll_compute_rootsquash_state(sbi);
1178 LPROC_SEQ_FOPS(ll_nosquash_nids);
1180 struct lprocfs_vars lprocfs_llite_obd_vars[] = {
1182 .fops = &ll_site_stats_fops },
1183 { .name = "stat_blocksize",
1184 .fops = &ll_stat_blksize_fops },
1185 { .name = "max_read_ahead_mb",
1186 .fops = &ll_max_readahead_mb_fops },
1187 { .name = "max_read_ahead_per_file_mb",
1188 .fops = &ll_max_readahead_per_file_mb_fops },
1189 { .name = "max_read_ahead_whole_mb",
1190 .fops = &ll_max_read_ahead_whole_mb_fops },
1191 { .name = "max_cached_mb",
1192 .fops = &ll_max_cached_mb_fops },
1193 { .name = "statahead_max",
1194 .fops = &ll_statahead_max_fops },
1195 { .name = "statahead_agl",
1196 .fops = &ll_statahead_agl_fops },
1197 { .name = "statahead_stats",
1198 .fops = &ll_statahead_stats_fops },
1199 { .name = "lazystatfs",
1200 .fops = &ll_lazystatfs_fops },
1201 { .name = "max_easize",
1202 .fops = &ll_max_easize_fops },
1203 { .name = "default_easize",
1204 .fops = &ll_default_easize_fops },
1205 { .name = "sbi_flags",
1206 .fops = &ll_sbi_flags_fops },
1207 { .name = "xattr_cache",
1208 .fops = &ll_xattr_cache_fops },
1209 { .name = "unstable_stats",
1210 .fops = &ll_unstable_stats_fops },
1211 { .name = "root_squash",
1212 .fops = &ll_root_squash_fops },
1213 { .name = "nosquash_nids",
1214 .fops = &ll_nosquash_nids_fops },
1215 { .name = "fast_read",
1216 .fops = &ll_fast_read_fops, },
1218 .fops = &ll_pio_fops, },
1219 { .name = "tiny_write",
1220 .fops = &ll_tiny_write_fops, },
1224 #define MAX_STRING_SIZE 128
1226 static struct attribute *llite_attrs[] = {
1227 &lustre_attr_blocksize.attr,
1228 &lustre_attr_kbytestotal.attr,
1229 &lustre_attr_kbytesfree.attr,
1230 &lustre_attr_kbytesavail.attr,
1231 &lustre_attr_filestotal.attr,
1232 &lustre_attr_filesfree.attr,
1233 &lustre_attr_client_type.attr,
1234 &lustre_attr_fstype.attr,
1235 &lustre_attr_uuid.attr,
1236 &lustre_attr_checksum_pages.attr,
1237 &lustre_attr_stats_track_pid.attr,
1238 &lustre_attr_stats_track_ppid.attr,
1239 &lustre_attr_stats_track_gid.attr,
1240 &lustre_attr_statahead_running_max.attr,
1244 static void llite_kobj_release(struct kobject *kobj)
1246 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1248 complete(&sbi->ll_kobj_unregister);
1251 static struct kobj_type llite_ktype = {
1252 .default_attrs = llite_attrs,
1253 .sysfs_ops = &lustre_sysfs_ops,
1254 .release = llite_kobj_release,
1257 static const struct llite_file_opcode {
1261 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
1262 /* file operation */
1263 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
1264 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
1265 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1267 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1269 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
1271 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
1273 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
1274 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
1275 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
1276 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
1277 { LPROC_LL_FAULT, LPROCFS_TYPE_REGS, "page_fault" },
1278 { LPROC_LL_MKWRITE, LPROCFS_TYPE_REGS, "page_mkwrite" },
1279 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
1280 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
1281 { LPROC_LL_READDIR, LPROCFS_TYPE_REGS, "readdir" },
1282 /* inode operation */
1283 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
1284 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "truncate" },
1285 { LPROC_LL_FLOCK, LPROCFS_TYPE_REGS, "flock" },
1286 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
1287 /* dir inode operation */
1288 { LPROC_LL_CREATE, LPROCFS_TYPE_REGS, "create" },
1289 { LPROC_LL_LINK, LPROCFS_TYPE_REGS, "link" },
1290 { LPROC_LL_UNLINK, LPROCFS_TYPE_REGS, "unlink" },
1291 { LPROC_LL_SYMLINK, LPROCFS_TYPE_REGS, "symlink" },
1292 { LPROC_LL_MKDIR, LPROCFS_TYPE_REGS, "mkdir" },
1293 { LPROC_LL_RMDIR, LPROCFS_TYPE_REGS, "rmdir" },
1294 { LPROC_LL_MKNOD, LPROCFS_TYPE_REGS, "mknod" },
1295 { LPROC_LL_RENAME, LPROCFS_TYPE_REGS, "rename" },
1296 /* special inode operation */
1297 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
1298 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
1299 { LPROC_LL_SETXATTR, LPROCFS_TYPE_REGS, "setxattr" },
1300 { LPROC_LL_GETXATTR, LPROCFS_TYPE_REGS, "getxattr" },
1301 { LPROC_LL_GETXATTR_HITS, LPROCFS_TYPE_REGS, "getxattr_hits" },
1302 { LPROC_LL_LISTXATTR, LPROCFS_TYPE_REGS, "listxattr" },
1303 { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_REGS, "removexattr" },
1304 { LPROC_LL_INODE_PERM, LPROCFS_TYPE_REGS, "inode_permission" },
1307 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
1311 if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
1312 lprocfs_counter_add(sbi->ll_stats, op, count);
1313 else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
1314 sbi->ll_stats_track_id == current->pid)
1315 lprocfs_counter_add(sbi->ll_stats, op, count);
1316 else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
1317 sbi->ll_stats_track_id == current->parent->pid)
1318 lprocfs_counter_add(sbi->ll_stats, op, count);
1319 else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
1320 sbi->ll_stats_track_id ==
1321 from_kgid(&init_user_ns, current_gid()))
1322 lprocfs_counter_add(sbi->ll_stats, op, count);
1324 EXPORT_SYMBOL(ll_stats_ops_tally);
1326 static const char *ra_stat_string[] = {
1327 [RA_STAT_HIT] = "hits",
1328 [RA_STAT_MISS] = "misses",
1329 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
1330 [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
1331 [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page",
1332 [RA_STAT_FAILED_MATCH] = "failed lock match",
1333 [RA_STAT_DISCARDED] = "read but discarded",
1334 [RA_STAT_ZERO_LEN] = "zero length file",
1335 [RA_STAT_ZERO_WINDOW] = "zero size window",
1336 [RA_STAT_EOF] = "read-ahead to EOF",
1337 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
1338 [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",
1339 [RA_STAT_FAILED_REACH_END] = "failed to reach end"
1342 LPROC_SEQ_FOPS_RO_TYPE(llite, name);
1343 LPROC_SEQ_FOPS_RO_TYPE(llite, uuid);
1345 int ll_debugfs_register_super(struct super_block *sb, const char *name)
1347 struct lustre_sb_info *lsi = s2lsi(sb);
1348 struct ll_sb_info *sbi = ll_s2sbi(sb);
1349 struct lprocfs_vars lvars[2];
1353 memset(lvars, 0, sizeof(lvars));
1354 lvars[0].name = name;
1356 LASSERT(sbi != NULL);
1358 sbi->ll_proc_root = lprocfs_register(name, proc_lustre_fs_root,
1360 if (IS_ERR(sbi->ll_proc_root)) {
1361 err = PTR_ERR(sbi->ll_proc_root);
1362 sbi->ll_proc_root = NULL;
1366 rc = lprocfs_seq_create(sbi->ll_proc_root, "dump_page_cache", 0444,
1367 &vvp_dump_pgcache_file_ops, sbi);
1369 CWARN("Error adding the dump_page_cache file\n");
1371 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats", 0644,
1372 &ll_rw_extents_stats_fops, sbi);
1374 CWARN("Error adding the extent_stats file\n");
1376 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats_per_process",
1377 0644, &ll_rw_extents_stats_pp_fops, sbi);
1379 CWARN("Error adding the extents_stats_per_process file\n");
1381 rc = lprocfs_seq_create(sbi->ll_proc_root, "offset_stats", 0644,
1382 &ll_rw_offset_stats_fops, sbi);
1384 CWARN("Error adding the offset_stats file\n");
1386 /* File operations stats */
1387 sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
1388 LPROCFS_STATS_FLAG_NONE);
1389 if (sbi->ll_stats == NULL)
1390 GOTO(out_proc, err = -ENOMEM);
1392 /* do counter init */
1393 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
1394 __u32 type = llite_opcode_table[id].type;
1396 if (type & LPROCFS_TYPE_REGS)
1398 else if (type & LPROCFS_TYPE_BYTES)
1400 else if (type & LPROCFS_TYPE_PAGES)
1402 lprocfs_counter_init(sbi->ll_stats,
1403 llite_opcode_table[id].opcode,
1404 (type & LPROCFS_CNTR_AVGMINMAX),
1405 llite_opcode_table[id].opname, ptr);
1408 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats);
1410 GOTO(out_stats, err);
1412 sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
1413 LPROCFS_STATS_FLAG_NONE);
1414 if (sbi->ll_ra_stats == NULL)
1415 GOTO(out_stats, err = -ENOMEM);
1417 for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
1418 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
1419 ra_stat_string[id], "pages");
1420 err = lprocfs_register_stats(sbi->ll_proc_root, "read_ahead_stats",
1423 GOTO(out_ra_stats, err);
1425 err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_llite_obd_vars, sb);
1427 GOTO(out_ra_stats, err);
1429 /* Yes we also register sysfs mount kset here as well */
1430 sbi->ll_kset.kobj.parent = llite_kobj;
1431 sbi->ll_kset.kobj.ktype = &llite_ktype;
1432 init_completion(&sbi->ll_kobj_unregister);
1433 err = kobject_set_name(&sbi->ll_kset.kobj, "%s", name);
1435 GOTO(out_ra_stats, err);
1437 err = kset_register(&sbi->ll_kset);
1439 GOTO(out_ra_stats, err);
1441 lsi->lsi_kobj = kobject_get(&sbi->ll_kset.kobj);
1445 lprocfs_free_stats(&sbi->ll_ra_stats);
1447 lprocfs_free_stats(&sbi->ll_stats);
1449 lprocfs_remove(&sbi->ll_proc_root);
1454 int lprocfs_ll_register_obd(struct super_block *sb, const char *obdname)
1456 struct lprocfs_vars lvars[2];
1457 struct ll_sb_info *sbi = ll_s2sbi(sb);
1458 struct obd_device *obd;
1459 struct proc_dir_entry *dir;
1460 char name[MAX_STRING_SIZE + 1];
1464 memset(lvars, 0, sizeof(lvars));
1466 name[MAX_STRING_SIZE] = '\0';
1467 lvars[0].name = name;
1469 LASSERT(sbi != NULL);
1470 LASSERT(obdname != NULL);
1472 obd = class_name2obd(obdname);
1474 LASSERT(obd != NULL);
1475 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1476 LASSERT(obd->obd_type->typ_name != NULL);
1478 dir = proc_mkdir(obd->obd_type->typ_name, sbi->ll_proc_root);
1480 GOTO(out, err = -ENOMEM);
1482 snprintf(name, MAX_STRING_SIZE, "common_name");
1483 lvars[0].fops = &llite_name_fops;
1484 err = lprocfs_add_vars(dir, lvars, obd);
1488 snprintf(name, MAX_STRING_SIZE, "uuid");
1489 lvars[0].fops = &llite_uuid_fops;
1490 err = lprocfs_add_vars(dir, lvars, obd);
1496 lprocfs_remove(&sbi->ll_proc_root);
1497 lprocfs_free_stats(&sbi->ll_ra_stats);
1498 lprocfs_free_stats(&sbi->ll_stats);
1503 void ll_debugfs_unregister_super(struct super_block *sb)
1505 struct lustre_sb_info *lsi = s2lsi(sb);
1506 struct ll_sb_info *sbi = ll_s2sbi(sb);
1508 kobject_put(lsi->lsi_kobj);
1510 kset_unregister(&sbi->ll_kset);
1511 wait_for_completion(&sbi->ll_kobj_unregister);
1513 if (sbi->ll_proc_root) {
1514 lprocfs_remove(&sbi->ll_proc_root);
1515 lprocfs_free_stats(&sbi->ll_ra_stats);
1516 lprocfs_free_stats(&sbi->ll_stats);
1519 #undef MAX_STRING_SIZE
1521 #define pct(a,b) (b ? a * 100 / b : 0)
1523 static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
1524 struct seq_file *seq, int which)
1526 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
1527 unsigned long start, end, r, w;
1528 char *unitp = "KMGTPEZY";
1530 struct per_process_info *pp_info = &io_extents->pp_extents[which];
1536 for(i = 0; i < LL_HIST_MAX; i++) {
1537 read_tot += pp_info->pp_r_hist.oh_buckets[i];
1538 write_tot += pp_info->pp_w_hist.oh_buckets[i];
1541 for(i = 0; i < LL_HIST_MAX; i++) {
1542 r = pp_info->pp_r_hist.oh_buckets[i];
1543 w = pp_info->pp_w_hist.oh_buckets[i];
1546 end = 1 << (i + LL_HIST_START - units);
1547 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu | "
1548 "%14lu %4lu %4lu\n", start, *unitp, end, *unitp,
1549 (i == LL_HIST_MAX - 1) ? '+' : ' ',
1550 r, pct(r, read_tot), pct(read_cum, read_tot),
1551 w, pct(w, write_tot), pct(write_cum, write_tot));
1553 if (start == 1<<10) {
1558 if (read_cum == read_tot && write_cum == write_tot)
1563 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
1565 struct timespec64 now;
1566 struct ll_sb_info *sbi = seq->private;
1567 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1570 ktime_get_real_ts64(&now);
1572 if (!sbi->ll_rw_stats_on) {
1573 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
1576 seq_printf(seq, "snapshot_time: %llu.%09lu (secs.nsecs)\n",
1577 (s64)now.tv_sec, now.tv_nsec);
1578 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1579 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1580 "extents", "calls", "%", "cum%",
1581 "calls", "%", "cum%");
1582 spin_lock(&sbi->ll_pp_extent_lock);
1583 for (k = 0; k < LL_PROCESS_HIST_MAX; k++) {
1584 if (io_extents->pp_extents[k].pid != 0) {
1585 seq_printf(seq, "\nPID: %d\n",
1586 io_extents->pp_extents[k].pid);
1587 ll_display_extents_info(io_extents, seq, k);
1590 spin_unlock(&sbi->ll_pp_extent_lock);
1594 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
1595 const char __user *buf,
1599 struct seq_file *seq = file->private_data;
1600 struct ll_sb_info *sbi = seq->private;
1601 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1608 value = ll_stats_pid_write(buf, len);
1611 sbi->ll_rw_stats_on = 0;
1613 sbi->ll_rw_stats_on = 1;
1615 spin_lock(&sbi->ll_pp_extent_lock);
1616 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1617 io_extents->pp_extents[i].pid = 0;
1618 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1619 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1621 spin_unlock(&sbi->ll_pp_extent_lock);
1625 LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
1627 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
1629 struct timespec64 now;
1630 struct ll_sb_info *sbi = seq->private;
1631 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1633 ktime_get_real_ts64(&now);
1635 if (!sbi->ll_rw_stats_on) {
1636 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
1639 seq_printf(seq, "snapshot_time: %llu.%09lu (secs.nsecs)\n",
1640 (s64)now.tv_sec, now.tv_nsec);
1642 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1643 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1644 "extents", "calls", "%", "cum%",
1645 "calls", "%", "cum%");
1646 spin_lock(&sbi->ll_lock);
1647 ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
1648 spin_unlock(&sbi->ll_lock);
1653 static ssize_t ll_rw_extents_stats_seq_write(struct file *file,
1654 const char __user *buf,
1655 size_t len, loff_t *off)
1657 struct seq_file *seq = file->private_data;
1658 struct ll_sb_info *sbi = seq->private;
1659 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1666 value = ll_stats_pid_write(buf, len);
1669 sbi->ll_rw_stats_on = 0;
1671 sbi->ll_rw_stats_on = 1;
1673 spin_lock(&sbi->ll_pp_extent_lock);
1674 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
1675 io_extents->pp_extents[i].pid = 0;
1676 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1677 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1679 spin_unlock(&sbi->ll_pp_extent_lock);
1683 LPROC_SEQ_FOPS(ll_rw_extents_stats);
1685 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
1686 struct ll_file_data *file, loff_t pos,
1687 size_t count, int rw)
1690 struct ll_rw_process_info *process;
1691 struct ll_rw_process_info *offset;
1692 int *off_count = &sbi->ll_rw_offset_entry_count;
1693 int *process_count = &sbi->ll_offset_process_count;
1694 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1696 if(!sbi->ll_rw_stats_on)
1698 process = sbi->ll_rw_process_info;
1699 offset = sbi->ll_rw_offset_info;
1701 spin_lock(&sbi->ll_pp_extent_lock);
1702 /* Extent statistics */
1703 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1704 if(io_extents->pp_extents[i].pid == pid) {
1712 sbi->ll_extent_process_count =
1713 (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1714 cur = sbi->ll_extent_process_count;
1715 io_extents->pp_extents[cur].pid = pid;
1716 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1717 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1720 for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
1721 (i < (LL_HIST_MAX - 1)); i++);
1723 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1724 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1726 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1727 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1729 spin_unlock(&sbi->ll_pp_extent_lock);
1731 spin_lock(&sbi->ll_process_lock);
1732 /* Offset statistics */
1733 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1734 if (process[i].rw_pid == pid) {
1735 if (process[i].rw_last_file != file) {
1736 process[i].rw_range_start = pos;
1737 process[i].rw_last_file_pos = pos + count;
1738 process[i].rw_smallest_extent = count;
1739 process[i].rw_largest_extent = count;
1740 process[i].rw_offset = 0;
1741 process[i].rw_last_file = file;
1742 spin_unlock(&sbi->ll_process_lock);
1745 if (process[i].rw_last_file_pos != pos) {
1747 (*off_count + 1) % LL_OFFSET_HIST_MAX;
1748 offset[*off_count].rw_op = process[i].rw_op;
1749 offset[*off_count].rw_pid = pid;
1750 offset[*off_count].rw_range_start =
1751 process[i].rw_range_start;
1752 offset[*off_count].rw_range_end =
1753 process[i].rw_last_file_pos;
1754 offset[*off_count].rw_smallest_extent =
1755 process[i].rw_smallest_extent;
1756 offset[*off_count].rw_largest_extent =
1757 process[i].rw_largest_extent;
1758 offset[*off_count].rw_offset =
1759 process[i].rw_offset;
1760 process[i].rw_op = rw;
1761 process[i].rw_range_start = pos;
1762 process[i].rw_smallest_extent = count;
1763 process[i].rw_largest_extent = count;
1764 process[i].rw_offset = pos -
1765 process[i].rw_last_file_pos;
1767 if(process[i].rw_smallest_extent > count)
1768 process[i].rw_smallest_extent = count;
1769 if(process[i].rw_largest_extent < count)
1770 process[i].rw_largest_extent = count;
1771 process[i].rw_last_file_pos = pos + count;
1772 spin_unlock(&sbi->ll_process_lock);
1776 *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
1777 process[*process_count].rw_pid = pid;
1778 process[*process_count].rw_op = rw;
1779 process[*process_count].rw_range_start = pos;
1780 process[*process_count].rw_last_file_pos = pos + count;
1781 process[*process_count].rw_smallest_extent = count;
1782 process[*process_count].rw_largest_extent = count;
1783 process[*process_count].rw_offset = 0;
1784 process[*process_count].rw_last_file = file;
1785 spin_unlock(&sbi->ll_process_lock);
1788 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1790 struct timespec64 now;
1791 struct ll_sb_info *sbi = seq->private;
1792 struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
1793 struct ll_rw_process_info *process = sbi->ll_rw_process_info;
1796 ktime_get_real_ts64(&now);
1798 if (!sbi->ll_rw_stats_on) {
1799 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
1802 spin_lock(&sbi->ll_process_lock);
1804 seq_printf(seq, "snapshot_time: %llu.%09lu (secs.nsecs)\n",
1805 (s64)now.tv_sec, now.tv_nsec);
1806 seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
1807 "R/W", "PID", "RANGE START", "RANGE END",
1808 "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
1810 /* We stored the discontiguous offsets here; print them first */
1811 for (i = 0; i < LL_OFFSET_HIST_MAX; i++) {
1812 if (offset[i].rw_pid != 0)
1814 "%3c %10d %14llu %14llu %17lu %17lu %14llu\n",
1815 offset[i].rw_op == READ ? 'R' : 'W',
1817 offset[i].rw_range_start,
1818 offset[i].rw_range_end,
1819 (unsigned long)offset[i].rw_smallest_extent,
1820 (unsigned long)offset[i].rw_largest_extent,
1821 offset[i].rw_offset);
1824 /* Then print the current offsets for each process */
1825 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1826 if (process[i].rw_pid != 0)
1828 "%3c %10d %14llu %14llu %17lu %17lu %14llu\n",
1829 process[i].rw_op == READ ? 'R' : 'W',
1831 process[i].rw_range_start,
1832 process[i].rw_last_file_pos,
1833 (unsigned long)process[i].rw_smallest_extent,
1834 (unsigned long)process[i].rw_largest_extent,
1835 process[i].rw_offset);
1837 spin_unlock(&sbi->ll_process_lock);
1842 static ssize_t ll_rw_offset_stats_seq_write(struct file *file,
1843 const char __user *buf,
1844 size_t len, loff_t *off)
1846 struct seq_file *seq = file->private_data;
1847 struct ll_sb_info *sbi = seq->private;
1848 struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
1849 struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
1855 value = ll_stats_pid_write(buf, len);
1858 sbi->ll_rw_stats_on = 0;
1860 sbi->ll_rw_stats_on = 1;
1862 spin_lock(&sbi->ll_process_lock);
1863 sbi->ll_offset_process_count = 0;
1864 sbi->ll_rw_offset_entry_count = 0;
1865 memset(process_info, 0, sizeof(struct ll_rw_process_info) *
1866 LL_PROCESS_HIST_MAX);
1867 memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
1868 LL_OFFSET_HIST_MAX);
1869 spin_unlock(&sbi->ll_process_lock);
1875 * ll_stats_pid_write() - Determine if stats collection should be enabled
1876 * @buf: Buffer containing the data written
1877 * @len: Number of bytes in the buffer
1879 * Several proc files begin collecting stats when a value is written, and stop
1880 * collecting when either '0' or 'disable' is written. This function checks the
1881 * written value to see if collection should be enabled or disabled.
1883 * Return: If '0' or 'disable' is provided, 0 is returned. If the text
1884 * equivalent of a number is written, that number is returned. Otherwise,
1885 * 1 is returned. Non-zero return values indicate collection should be enabled.
1887 static __s64 ll_stats_pid_write(const char __user *buf, size_t len)
1889 unsigned long long value = 1;
1893 rc = kstrtoull_from_user(buf, len, 0, &value);
1894 if (rc < 0 && len < sizeof(kernbuf)) {
1896 if (copy_from_user(kernbuf, buf, len))
1900 if (kernbuf[len - 1] == '\n')
1901 kernbuf[len - 1] = 0;
1903 if (strncasecmp(kernbuf, "disable", 7) == 0)
1910 LPROC_SEQ_FOPS(ll_rw_offset_stats);
1911 #endif /* CONFIG_PROC_FS */