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_site_stats_seq_show(struct seq_file *m, void *v)
264 struct super_block *sb = m->private;
267 * See description of statistical counters in struct cl_site, and
270 return cl_site_stats_print(lu2cl_site(ll_s2sbi(sb)->ll_site), m);
272 LPROC_SEQ_FOPS_RO(ll_site_stats);
274 static int ll_max_readahead_mb_seq_show(struct seq_file *m, void *v)
276 struct super_block *sb = m->private;
277 struct ll_sb_info *sbi = ll_s2sbi(sb);
281 spin_lock(&sbi->ll_lock);
282 pages_number = sbi->ll_ra_info.ra_max_pages;
283 spin_unlock(&sbi->ll_lock);
285 mult = 1 << (20 - PAGE_SHIFT);
286 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
290 ll_max_readahead_mb_seq_write(struct file *file, const char __user *buffer,
291 size_t count, loff_t *off)
293 struct seq_file *m = file->private_data;
294 struct super_block *sb = m->private;
295 struct ll_sb_info *sbi = ll_s2sbi(sb);
299 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
303 pages_number >>= PAGE_SHIFT;
305 if (pages_number < 0 || pages_number > totalram_pages / 2) {
307 CERROR("%s: can't set max_readahead_mb=%lu > %luMB\n",
308 ll_get_fsname(sb, NULL, 0),
309 (unsigned long)pages_number >> (20 - PAGE_SHIFT),
310 totalram_pages >> (20 - PAGE_SHIFT + 1));
314 spin_lock(&sbi->ll_lock);
315 sbi->ll_ra_info.ra_max_pages = pages_number;
316 spin_unlock(&sbi->ll_lock);
319 LPROC_SEQ_FOPS(ll_max_readahead_mb);
321 static int ll_max_readahead_per_file_mb_seq_show(struct seq_file *m, void *v)
323 struct super_block *sb = m->private;
324 struct ll_sb_info *sbi = ll_s2sbi(sb);
328 spin_lock(&sbi->ll_lock);
329 pages_number = sbi->ll_ra_info.ra_max_pages_per_file;
330 spin_unlock(&sbi->ll_lock);
332 mult = 1 << (20 - PAGE_SHIFT);
333 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
337 ll_max_readahead_per_file_mb_seq_write(struct file *file,
338 const char __user *buffer,
339 size_t count, loff_t *off)
341 struct seq_file *m = file->private_data;
342 struct super_block *sb = m->private;
343 struct ll_sb_info *sbi = ll_s2sbi(sb);
347 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
351 pages_number >>= PAGE_SHIFT;
353 if (pages_number < 0 || pages_number > sbi->ll_ra_info.ra_max_pages) {
354 CERROR("%s: can't set max_readahead_per_file_mb=%lu > "
355 "max_read_ahead_mb=%lu\n", ll_get_fsname(sb, NULL, 0),
356 (unsigned long)pages_number >> (20 - PAGE_SHIFT),
357 sbi->ll_ra_info.ra_max_pages >> (20 - PAGE_SHIFT));
361 spin_lock(&sbi->ll_lock);
362 sbi->ll_ra_info.ra_max_pages_per_file = pages_number;
363 spin_unlock(&sbi->ll_lock);
366 LPROC_SEQ_FOPS(ll_max_readahead_per_file_mb);
368 static int ll_max_read_ahead_whole_mb_seq_show(struct seq_file *m, void *v)
370 struct super_block *sb = m->private;
371 struct ll_sb_info *sbi = ll_s2sbi(sb);
375 spin_lock(&sbi->ll_lock);
376 pages_number = sbi->ll_ra_info.ra_max_read_ahead_whole_pages;
377 spin_unlock(&sbi->ll_lock);
379 mult = 1 << (20 - PAGE_SHIFT);
380 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
384 ll_max_read_ahead_whole_mb_seq_write(struct file *file,
385 const char __user *buffer,
386 size_t count, loff_t *off)
388 struct seq_file *m = file->private_data;
389 struct super_block *sb = m->private;
390 struct ll_sb_info *sbi = ll_s2sbi(sb);
394 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
398 pages_number >>= PAGE_SHIFT;
400 /* Cap this at the current max readahead window size, the readahead
401 * algorithm does this anyway so it's pointless to set it larger. */
402 if (pages_number < 0 ||
403 pages_number > sbi->ll_ra_info.ra_max_pages_per_file) {
404 int pages_shift = 20 - PAGE_SHIFT;
405 CERROR("%s: can't set max_read_ahead_whole_mb=%lu > "
406 "max_read_ahead_per_file_mb=%lu\n",
407 ll_get_fsname(sb, NULL, 0),
408 (unsigned long)pages_number >> pages_shift,
409 sbi->ll_ra_info.ra_max_pages_per_file >> pages_shift);
413 spin_lock(&sbi->ll_lock);
414 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = pages_number;
415 spin_unlock(&sbi->ll_lock);
418 LPROC_SEQ_FOPS(ll_max_read_ahead_whole_mb);
420 static int ll_max_cached_mb_seq_show(struct seq_file *m, void *v)
422 struct super_block *sb = m->private;
423 struct ll_sb_info *sbi = ll_s2sbi(sb);
424 struct cl_client_cache *cache = sbi->ll_cache;
425 int shift = 20 - PAGE_SHIFT;
429 max_cached_mb = cache->ccc_lru_max >> shift;
430 unused_mb = atomic_long_read(&cache->ccc_lru_left) >> shift;
431 seq_printf(m, "users: %d\n"
432 "max_cached_mb: %ld\n"
435 "reclaim_count: %u\n",
436 atomic_read(&cache->ccc_users),
438 max_cached_mb - unused_mb,
440 cache->ccc_lru_shrinkers);
445 ll_max_cached_mb_seq_write(struct file *file, const char __user *buffer,
446 size_t count, loff_t *off)
448 struct seq_file *m = file->private_data;
449 struct super_block *sb = m->private;
450 struct ll_sb_info *sbi = ll_s2sbi(sb);
451 struct cl_client_cache *cache = sbi->ll_cache;
461 if (count >= sizeof(kernbuf))
464 if (copy_from_user(kernbuf, buffer, count))
468 buffer += lprocfs_find_named_value(kernbuf, "max_cached_mb:", &count) -
470 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
474 pages_number >>= PAGE_SHIFT;
476 if (pages_number < 0 || pages_number > totalram_pages) {
477 CERROR("%s: can't set max cache more than %lu MB\n",
478 ll_get_fsname(sb, NULL, 0),
479 totalram_pages >> (20 - PAGE_SHIFT));
482 /* Allow enough cache so clients can make well-formed RPCs */
483 pages_number = max_t(long, pages_number, PTLRPC_MAX_BRW_PAGES);
485 spin_lock(&sbi->ll_lock);
486 diff = pages_number - cache->ccc_lru_max;
487 spin_unlock(&sbi->ll_lock);
489 /* easy - add more LRU slots. */
491 atomic_long_add(diff, &cache->ccc_lru_left);
495 env = cl_env_get(&refcheck);
503 /* reduce LRU budget from free slots. */
507 ov = atomic_long_read(&cache->ccc_lru_left);
511 nv = ov > diff ? ov - diff : 0;
512 rc = atomic_long_cmpxchg(&cache->ccc_lru_left, ov, nv);
513 if (likely(ov == rc)) {
523 if (sbi->ll_dt_exp == NULL) { /* being initialized */
528 /* difficult - have to ask OSCs to drop LRU slots. */
530 rc = obd_set_info_async(env, sbi->ll_dt_exp,
531 sizeof(KEY_CACHE_LRU_SHRINK),
532 KEY_CACHE_LRU_SHRINK,
533 sizeof(tmp), &tmp, NULL);
537 cl_env_put(env, &refcheck);
541 spin_lock(&sbi->ll_lock);
542 cache->ccc_lru_max = pages_number;
543 spin_unlock(&sbi->ll_lock);
546 atomic_long_add(nrpages, &cache->ccc_lru_left);
550 LPROC_SEQ_FOPS(ll_max_cached_mb);
552 static ssize_t checksums_show(struct kobject *kobj, struct attribute *attr,
555 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
558 return sprintf(buf, "%u\n", (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0);
561 static ssize_t checksums_store(struct kobject *kobj, struct attribute *attr,
562 const char *buffer, size_t count)
564 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
574 rc = kstrtobool(buffer, &val);
578 sbi->ll_flags |= LL_SBI_CHECKSUM;
580 sbi->ll_flags &= ~LL_SBI_CHECKSUM;
583 rc = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
584 KEY_CHECKSUM, sizeof(tmp), &tmp, NULL);
586 CWARN("Failed to set OSC checksum flags: %d\n", rc);
590 LUSTRE_RW_ATTR(checksums);
592 LUSTRE_ATTR(checksum_pages, 0644, checksums_show, checksums_store);
594 static ssize_t ll_rd_track_id(struct kobject *kobj, char *buf,
595 enum stats_track_type type)
597 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
600 if (sbi->ll_stats_track_type == type)
601 return sprintf(buf, "%d\n", sbi->ll_stats_track_id);
602 else if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
603 return sprintf(buf, "0 (all)\n");
605 return sprintf(buf, "untracked\n");
608 static ssize_t ll_wr_track_id(struct kobject *kobj, const char *buffer,
609 size_t count, enum stats_track_type type)
611 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
616 rc = kstrtoul(buffer, 10, &pid);
620 sbi->ll_stats_track_id = pid;
622 sbi->ll_stats_track_type = STATS_TRACK_ALL;
624 sbi->ll_stats_track_type = type;
625 lprocfs_clear_stats(sbi->ll_stats);
629 static ssize_t stats_track_pid_show(struct kobject *kobj,
630 struct attribute *attr,
633 return ll_rd_track_id(kobj, buf, STATS_TRACK_PID);
636 static ssize_t stats_track_pid_store(struct kobject *kobj,
637 struct attribute *attr,
641 return ll_wr_track_id(kobj, buffer, count, STATS_TRACK_PID);
643 LUSTRE_RW_ATTR(stats_track_pid);
645 static ssize_t stats_track_ppid_show(struct kobject *kobj,
646 struct attribute *attr,
649 return ll_rd_track_id(kobj, buf, STATS_TRACK_PPID);
652 static ssize_t stats_track_ppid_store(struct kobject *kobj,
653 struct attribute *attr,
657 return ll_wr_track_id(kobj, buffer, count, STATS_TRACK_PPID);
659 LUSTRE_RW_ATTR(stats_track_ppid);
661 static ssize_t stats_track_gid_show(struct kobject *kobj,
662 struct attribute *attr,
665 return ll_rd_track_id(kobj, buf, STATS_TRACK_GID);
668 static ssize_t stats_track_gid_store(struct kobject *kobj,
669 struct attribute *attr,
673 return ll_wr_track_id(kobj, buffer, count, STATS_TRACK_GID);
675 LUSTRE_RW_ATTR(stats_track_gid);
677 static ssize_t statahead_running_max_show(struct kobject *kobj,
678 struct attribute *attr,
681 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
684 return snprintf(buf, 16, "%u\n", sbi->ll_sa_running_max);
687 static ssize_t statahead_running_max_store(struct kobject *kobj,
688 struct attribute *attr,
692 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
697 rc = kstrtoul(buffer, 0, &val);
701 if (val <= LL_SA_RUNNING_MAX) {
702 sbi->ll_sa_running_max = val;
706 CERROR("Bad statahead_running_max value %lu. Valid values "
707 "are in the range [0, %d]\n", val, LL_SA_RUNNING_MAX);
711 LUSTRE_RW_ATTR(statahead_running_max);
713 static ssize_t statahead_max_show(struct kobject *kobj,
714 struct attribute *attr,
717 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
720 return sprintf(buf, "%u\n", sbi->ll_sa_max);
723 static ssize_t statahead_max_store(struct kobject *kobj,
724 struct attribute *attr,
728 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
733 rc = kstrtoul(buffer, 0, &val);
737 if (val <= LL_SA_RPC_MAX)
738 sbi->ll_sa_max = val;
740 CERROR("Bad statahead_max value %lu. Valid values are in the range [0, %d]\n",
745 LUSTRE_RW_ATTR(statahead_max);
747 static ssize_t statahead_agl_show(struct kobject *kobj,
748 struct attribute *attr,
751 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
754 return sprintf(buf, "%u\n", sbi->ll_flags & LL_SBI_AGL_ENABLED ? 1 : 0);
757 static ssize_t statahead_agl_store(struct kobject *kobj,
758 struct attribute *attr,
762 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
767 rc = kstrtobool(buffer, &val);
772 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
774 sbi->ll_flags &= ~LL_SBI_AGL_ENABLED;
778 LUSTRE_RW_ATTR(statahead_agl);
780 static int ll_statahead_stats_seq_show(struct seq_file *m, void *v)
782 struct super_block *sb = m->private;
783 struct ll_sb_info *sbi = ll_s2sbi(sb);
785 seq_printf(m, "statahead total: %u\n"
786 "statahead wrong: %u\n"
788 atomic_read(&sbi->ll_sa_total),
789 atomic_read(&sbi->ll_sa_wrong),
790 atomic_read(&sbi->ll_agl_total));
793 LPROC_SEQ_FOPS_RO(ll_statahead_stats);
795 static ssize_t lazystatfs_show(struct kobject *kobj,
796 struct attribute *attr,
799 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
802 return sprintf(buf, "%u\n", (sbi->ll_flags & LL_SBI_LAZYSTATFS) ? 1 : 0);
805 static ssize_t lazystatfs_store(struct kobject *kobj,
806 struct attribute *attr,
810 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
815 rc = kstrtobool(buffer, &val);
820 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
822 sbi->ll_flags &= ~LL_SBI_LAZYSTATFS;
826 LUSTRE_RW_ATTR(lazystatfs);
828 static ssize_t max_easize_show(struct kobject *kobj,
829 struct attribute *attr,
832 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
837 rc = ll_get_max_mdsize(sbi, &ealen);
841 return sprintf(buf, "%u\n", ealen);
843 LUSTRE_RO_ATTR(max_easize);
846 * Get default_easize.
848 * \see client_obd::cl_default_mds_easize
850 * \param[in] m seq_file handle
851 * \param[in] v unused for single entry
853 * \retval 0 on success
854 * \retval negative negated errno on failure
856 static ssize_t default_easize_show(struct kobject *kobj,
857 struct attribute *attr,
860 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
865 rc = ll_get_default_mdsize(sbi, &ealen);
869 return sprintf(buf, "%u\n", ealen);
873 * Set default_easize.
875 * Range checking on the passed value is handled by
876 * ll_set_default_mdsize().
878 * \see client_obd::cl_default_mds_easize
880 * \param[in] file proc file
881 * \param[in] buffer string passed from user space
882 * \param[in] count \a buffer length
883 * \param[in] off unused for single entry
885 * \retval positive \a count on success
886 * \retval negative negated errno on failure
888 static ssize_t default_easize_store(struct kobject *kobj,
889 struct attribute *attr,
893 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
901 rc = kstrtouint(buffer, 10, &val);
905 rc = ll_set_default_mdsize(sbi, val);
911 LUSTRE_RW_ATTR(default_easize);
913 static int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
915 const char *str[] = LL_SBI_FLAGS;
916 struct super_block *sb = m->private;
917 int flags = ll_s2sbi(sb)->ll_flags;
921 if (ARRAY_SIZE(str) <= i) {
922 CERROR("%s: Revise array LL_SBI_FLAGS to match sbi "
923 "flags please.\n", ll_get_fsname(sb, NULL, 0));
928 seq_printf(m, "%s ", str[i]);
932 seq_printf(m, "\b\n");
935 LPROC_SEQ_FOPS_RO(ll_sbi_flags);
937 static ssize_t xattr_cache_show(struct kobject *kobj,
938 struct attribute *attr,
941 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
944 return sprintf(buf, "%u\n", sbi->ll_xattr_cache_enabled);
947 static ssize_t xattr_cache_store(struct kobject *kobj,
948 struct attribute *attr,
952 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
957 rc = kstrtobool(buffer, &val);
961 if (val && !(sbi->ll_flags & LL_SBI_XATTR_CACHE))
964 sbi->ll_xattr_cache_enabled = val;
965 sbi->ll_xattr_cache_set = 1;
969 LUSTRE_RW_ATTR(xattr_cache);
971 static int ll_tiny_write_seq_show(struct seq_file *m, void *v)
973 struct super_block *sb = m->private;
974 struct ll_sb_info *sbi = ll_s2sbi(sb);
976 seq_printf(m, "%u\n", !!(sbi->ll_flags & LL_SBI_TINY_WRITE));
980 static ssize_t ll_tiny_write_seq_write(
981 struct file *file, const char __user *buffer, size_t count, loff_t *off)
983 struct seq_file *m = file->private_data;
984 struct super_block *sb = m->private;
985 struct ll_sb_info *sbi = ll_s2sbi(sb);
989 rc = kstrtobool_from_user(buffer, count, &val);
993 spin_lock(&sbi->ll_lock);
995 sbi->ll_flags |= LL_SBI_TINY_WRITE;
997 sbi->ll_flags &= ~LL_SBI_TINY_WRITE;
998 spin_unlock(&sbi->ll_lock);
1002 LPROC_SEQ_FOPS(ll_tiny_write);
1004 static int ll_fast_read_seq_show(struct seq_file *m, void *v)
1006 struct super_block *sb = m->private;
1007 struct ll_sb_info *sbi = ll_s2sbi(sb);
1009 seq_printf(m, "%u\n", !!(sbi->ll_flags & LL_SBI_FAST_READ));
1014 ll_fast_read_seq_write(struct file *file, const char __user *buffer,
1015 size_t count, loff_t *off)
1017 struct seq_file *m = file->private_data;
1018 struct super_block *sb = m->private;
1019 struct ll_sb_info *sbi = ll_s2sbi(sb);
1023 rc = kstrtobool_from_user(buffer, count, &val);
1027 spin_lock(&sbi->ll_lock);
1029 sbi->ll_flags |= LL_SBI_FAST_READ;
1031 sbi->ll_flags &= ~LL_SBI_FAST_READ;
1032 spin_unlock(&sbi->ll_lock);
1036 LPROC_SEQ_FOPS(ll_fast_read);
1038 static int ll_pio_seq_show(struct seq_file *m, void *v)
1040 struct super_block *sb = m->private;
1041 struct ll_sb_info *sbi = ll_s2sbi(sb);
1043 seq_printf(m, "%u\n", !!(sbi->ll_flags & LL_SBI_PIO));
1047 static ssize_t ll_pio_seq_write(struct file *file, const char __user *buffer,
1048 size_t count, loff_t *off)
1050 struct seq_file *m = file->private_data;
1051 struct super_block *sb = m->private;
1052 struct ll_sb_info *sbi = ll_s2sbi(sb);
1056 rc = kstrtobool_from_user(buffer, count, &val);
1060 spin_lock(&sbi->ll_lock);
1062 sbi->ll_flags |= LL_SBI_PIO;
1064 sbi->ll_flags &= ~LL_SBI_PIO;
1065 spin_unlock(&sbi->ll_lock);
1069 LPROC_SEQ_FOPS(ll_pio);
1071 static int ll_unstable_stats_seq_show(struct seq_file *m, void *v)
1073 struct super_block *sb = m->private;
1074 struct ll_sb_info *sbi = ll_s2sbi(sb);
1075 struct cl_client_cache *cache = sbi->ll_cache;
1079 pages = atomic_long_read(&cache->ccc_unstable_nr);
1080 mb = (pages * PAGE_SIZE) >> 20;
1082 seq_printf(m, "unstable_check: %8d\n"
1083 "unstable_pages: %12ld\n"
1084 "unstable_mb: %8d\n",
1085 cache->ccc_unstable_check, pages, mb);
1089 static ssize_t ll_unstable_stats_seq_write(struct file *file,
1090 const char __user *buffer,
1091 size_t count, loff_t *unused)
1093 struct seq_file *seq = file->private_data;
1094 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)seq->private);
1101 if (count >= sizeof(kernbuf))
1104 if (copy_from_user(kernbuf, buffer, count))
1108 buffer += lprocfs_find_named_value(kernbuf, "unstable_check:", &count) -
1110 rc = kstrtobool_from_user(buffer, count, &val);
1114 /* borrow lru lock to set the value */
1115 spin_lock(&sbi->ll_cache->ccc_lru_lock);
1116 sbi->ll_cache->ccc_unstable_check = val;
1117 spin_unlock(&sbi->ll_cache->ccc_lru_lock);
1121 LPROC_SEQ_FOPS(ll_unstable_stats);
1123 static int ll_root_squash_seq_show(struct seq_file *m, void *v)
1125 struct super_block *sb = m->private;
1126 struct ll_sb_info *sbi = ll_s2sbi(sb);
1127 struct root_squash_info *squash = &sbi->ll_squash;
1129 seq_printf(m, "%u:%u\n", squash->rsi_uid, squash->rsi_gid);
1133 static ssize_t ll_root_squash_seq_write(struct file *file,
1134 const char __user *buffer,
1135 size_t count, loff_t *off)
1137 struct seq_file *m = file->private_data;
1138 struct super_block *sb = m->private;
1139 struct ll_sb_info *sbi = ll_s2sbi(sb);
1140 struct root_squash_info *squash = &sbi->ll_squash;
1142 return lprocfs_wr_root_squash(buffer, count, squash,
1143 ll_get_fsname(sb, NULL, 0));
1145 LPROC_SEQ_FOPS(ll_root_squash);
1147 static int ll_nosquash_nids_seq_show(struct seq_file *m, void *v)
1149 struct super_block *sb = m->private;
1150 struct ll_sb_info *sbi = ll_s2sbi(sb);
1151 struct root_squash_info *squash = &sbi->ll_squash;
1154 down_read(&squash->rsi_sem);
1155 if (!list_empty(&squash->rsi_nosquash_nids)) {
1156 len = cfs_print_nidlist(m->buf + m->count, m->size - m->count,
1157 &squash->rsi_nosquash_nids);
1161 seq_puts(m, "NONE\n");
1163 up_read(&squash->rsi_sem);
1168 static ssize_t ll_nosquash_nids_seq_write(struct file *file,
1169 const char __user *buffer,
1170 size_t count, loff_t *off)
1172 struct seq_file *m = file->private_data;
1173 struct super_block *sb = m->private;
1174 struct ll_sb_info *sbi = ll_s2sbi(sb);
1175 struct root_squash_info *squash = &sbi->ll_squash;
1178 rc = lprocfs_wr_nosquash_nids(buffer, count, squash,
1179 ll_get_fsname(sb, NULL, 0));
1183 ll_compute_rootsquash_state(sbi);
1187 LPROC_SEQ_FOPS(ll_nosquash_nids);
1189 struct lprocfs_vars lprocfs_llite_obd_vars[] = {
1191 .fops = &ll_site_stats_fops },
1192 { .name = "stat_blocksize",
1193 .fops = &ll_stat_blksize_fops },
1194 { .name = "max_read_ahead_mb",
1195 .fops = &ll_max_readahead_mb_fops },
1196 { .name = "max_read_ahead_per_file_mb",
1197 .fops = &ll_max_readahead_per_file_mb_fops },
1198 { .name = "max_read_ahead_whole_mb",
1199 .fops = &ll_max_read_ahead_whole_mb_fops },
1200 { .name = "max_cached_mb",
1201 .fops = &ll_max_cached_mb_fops },
1202 { .name = "statahead_stats",
1203 .fops = &ll_statahead_stats_fops },
1204 { .name = "sbi_flags",
1205 .fops = &ll_sbi_flags_fops },
1206 { .name = "unstable_stats",
1207 .fops = &ll_unstable_stats_fops },
1208 { .name = "root_squash",
1209 .fops = &ll_root_squash_fops },
1210 { .name = "nosquash_nids",
1211 .fops = &ll_nosquash_nids_fops },
1212 { .name = "fast_read",
1213 .fops = &ll_fast_read_fops, },
1215 .fops = &ll_pio_fops, },
1216 { .name = "tiny_write",
1217 .fops = &ll_tiny_write_fops, },
1221 #define MAX_STRING_SIZE 128
1223 static struct attribute *llite_attrs[] = {
1224 &lustre_attr_blocksize.attr,
1225 &lustre_attr_kbytestotal.attr,
1226 &lustre_attr_kbytesfree.attr,
1227 &lustre_attr_kbytesavail.attr,
1228 &lustre_attr_filestotal.attr,
1229 &lustre_attr_filesfree.attr,
1230 &lustre_attr_client_type.attr,
1231 &lustre_attr_fstype.attr,
1232 &lustre_attr_uuid.attr,
1233 &lustre_attr_checksums.attr,
1234 &lustre_attr_checksum_pages.attr,
1235 &lustre_attr_stats_track_pid.attr,
1236 &lustre_attr_stats_track_ppid.attr,
1237 &lustre_attr_stats_track_gid.attr,
1238 &lustre_attr_statahead_running_max.attr,
1239 &lustre_attr_statahead_max.attr,
1240 &lustre_attr_statahead_agl.attr,
1241 &lustre_attr_lazystatfs.attr,
1242 &lustre_attr_max_easize.attr,
1243 &lustre_attr_default_easize.attr,
1244 &lustre_attr_xattr_cache.attr,
1248 static void llite_kobj_release(struct kobject *kobj)
1250 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1252 complete(&sbi->ll_kobj_unregister);
1255 static struct kobj_type llite_ktype = {
1256 .default_attrs = llite_attrs,
1257 .sysfs_ops = &lustre_sysfs_ops,
1258 .release = llite_kobj_release,
1261 static const struct llite_file_opcode {
1265 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
1266 /* file operation */
1267 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
1268 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
1269 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1271 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1273 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
1275 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
1277 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
1278 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
1279 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
1280 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
1281 { LPROC_LL_FAULT, LPROCFS_TYPE_REGS, "page_fault" },
1282 { LPROC_LL_MKWRITE, LPROCFS_TYPE_REGS, "page_mkwrite" },
1283 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
1284 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
1285 { LPROC_LL_READDIR, LPROCFS_TYPE_REGS, "readdir" },
1286 /* inode operation */
1287 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
1288 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "truncate" },
1289 { LPROC_LL_FLOCK, LPROCFS_TYPE_REGS, "flock" },
1290 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
1291 /* dir inode operation */
1292 { LPROC_LL_CREATE, LPROCFS_TYPE_REGS, "create" },
1293 { LPROC_LL_LINK, LPROCFS_TYPE_REGS, "link" },
1294 { LPROC_LL_UNLINK, LPROCFS_TYPE_REGS, "unlink" },
1295 { LPROC_LL_SYMLINK, LPROCFS_TYPE_REGS, "symlink" },
1296 { LPROC_LL_MKDIR, LPROCFS_TYPE_REGS, "mkdir" },
1297 { LPROC_LL_RMDIR, LPROCFS_TYPE_REGS, "rmdir" },
1298 { LPROC_LL_MKNOD, LPROCFS_TYPE_REGS, "mknod" },
1299 { LPROC_LL_RENAME, LPROCFS_TYPE_REGS, "rename" },
1300 /* special inode operation */
1301 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
1302 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
1303 { LPROC_LL_SETXATTR, LPROCFS_TYPE_REGS, "setxattr" },
1304 { LPROC_LL_GETXATTR, LPROCFS_TYPE_REGS, "getxattr" },
1305 { LPROC_LL_GETXATTR_HITS, LPROCFS_TYPE_REGS, "getxattr_hits" },
1306 { LPROC_LL_LISTXATTR, LPROCFS_TYPE_REGS, "listxattr" },
1307 { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_REGS, "removexattr" },
1308 { LPROC_LL_INODE_PERM, LPROCFS_TYPE_REGS, "inode_permission" },
1311 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
1315 if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
1316 lprocfs_counter_add(sbi->ll_stats, op, count);
1317 else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
1318 sbi->ll_stats_track_id == current->pid)
1319 lprocfs_counter_add(sbi->ll_stats, op, count);
1320 else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
1321 sbi->ll_stats_track_id == current->parent->pid)
1322 lprocfs_counter_add(sbi->ll_stats, op, count);
1323 else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
1324 sbi->ll_stats_track_id ==
1325 from_kgid(&init_user_ns, current_gid()))
1326 lprocfs_counter_add(sbi->ll_stats, op, count);
1328 EXPORT_SYMBOL(ll_stats_ops_tally);
1330 static const char *ra_stat_string[] = {
1331 [RA_STAT_HIT] = "hits",
1332 [RA_STAT_MISS] = "misses",
1333 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
1334 [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
1335 [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page",
1336 [RA_STAT_FAILED_MATCH] = "failed lock match",
1337 [RA_STAT_DISCARDED] = "read but discarded",
1338 [RA_STAT_ZERO_LEN] = "zero length file",
1339 [RA_STAT_ZERO_WINDOW] = "zero size window",
1340 [RA_STAT_EOF] = "read-ahead to EOF",
1341 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
1342 [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",
1343 [RA_STAT_FAILED_REACH_END] = "failed to reach end"
1346 LPROC_SEQ_FOPS_RO_TYPE(llite, name);
1347 LPROC_SEQ_FOPS_RO_TYPE(llite, uuid);
1349 int ll_debugfs_register_super(struct super_block *sb, const char *name)
1351 struct lustre_sb_info *lsi = s2lsi(sb);
1352 struct ll_sb_info *sbi = ll_s2sbi(sb);
1353 struct lprocfs_vars lvars[2];
1357 memset(lvars, 0, sizeof(lvars));
1358 lvars[0].name = name;
1360 LASSERT(sbi != NULL);
1362 sbi->ll_proc_root = lprocfs_register(name, proc_lustre_fs_root,
1364 if (IS_ERR(sbi->ll_proc_root)) {
1365 err = PTR_ERR(sbi->ll_proc_root);
1366 sbi->ll_proc_root = NULL;
1370 rc = lprocfs_seq_create(sbi->ll_proc_root, "dump_page_cache", 0444,
1371 &vvp_dump_pgcache_file_ops, sbi);
1373 CWARN("Error adding the dump_page_cache file\n");
1375 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats", 0644,
1376 &ll_rw_extents_stats_fops, sbi);
1378 CWARN("Error adding the extent_stats file\n");
1380 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats_per_process",
1381 0644, &ll_rw_extents_stats_pp_fops, sbi);
1383 CWARN("Error adding the extents_stats_per_process file\n");
1385 rc = lprocfs_seq_create(sbi->ll_proc_root, "offset_stats", 0644,
1386 &ll_rw_offset_stats_fops, sbi);
1388 CWARN("Error adding the offset_stats file\n");
1390 /* File operations stats */
1391 sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
1392 LPROCFS_STATS_FLAG_NONE);
1393 if (sbi->ll_stats == NULL)
1394 GOTO(out_proc, err = -ENOMEM);
1396 /* do counter init */
1397 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
1398 __u32 type = llite_opcode_table[id].type;
1400 if (type & LPROCFS_TYPE_REGS)
1402 else if (type & LPROCFS_TYPE_BYTES)
1404 else if (type & LPROCFS_TYPE_PAGES)
1406 lprocfs_counter_init(sbi->ll_stats,
1407 llite_opcode_table[id].opcode,
1408 (type & LPROCFS_CNTR_AVGMINMAX),
1409 llite_opcode_table[id].opname, ptr);
1412 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats);
1414 GOTO(out_stats, err);
1416 sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
1417 LPROCFS_STATS_FLAG_NONE);
1418 if (sbi->ll_ra_stats == NULL)
1419 GOTO(out_stats, err = -ENOMEM);
1421 for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
1422 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
1423 ra_stat_string[id], "pages");
1424 err = lprocfs_register_stats(sbi->ll_proc_root, "read_ahead_stats",
1427 GOTO(out_ra_stats, err);
1429 err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_llite_obd_vars, sb);
1431 GOTO(out_ra_stats, err);
1433 /* Yes we also register sysfs mount kset here as well */
1434 sbi->ll_kset.kobj.parent = llite_kobj;
1435 sbi->ll_kset.kobj.ktype = &llite_ktype;
1436 init_completion(&sbi->ll_kobj_unregister);
1437 err = kobject_set_name(&sbi->ll_kset.kobj, "%s", name);
1439 GOTO(out_ra_stats, err);
1441 err = kset_register(&sbi->ll_kset);
1443 GOTO(out_ra_stats, err);
1445 lsi->lsi_kobj = kobject_get(&sbi->ll_kset.kobj);
1449 lprocfs_free_stats(&sbi->ll_ra_stats);
1451 lprocfs_free_stats(&sbi->ll_stats);
1453 lprocfs_remove(&sbi->ll_proc_root);
1458 int lprocfs_ll_register_obd(struct super_block *sb, const char *obdname)
1460 struct lprocfs_vars lvars[2];
1461 struct ll_sb_info *sbi = ll_s2sbi(sb);
1462 struct obd_device *obd;
1463 struct proc_dir_entry *dir;
1464 char name[MAX_STRING_SIZE + 1];
1468 memset(lvars, 0, sizeof(lvars));
1470 name[MAX_STRING_SIZE] = '\0';
1471 lvars[0].name = name;
1473 LASSERT(sbi != NULL);
1474 LASSERT(obdname != NULL);
1476 obd = class_name2obd(obdname);
1478 LASSERT(obd != NULL);
1479 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1480 LASSERT(obd->obd_type->typ_name != NULL);
1482 dir = proc_mkdir(obd->obd_type->typ_name, sbi->ll_proc_root);
1484 GOTO(out, err = -ENOMEM);
1486 snprintf(name, MAX_STRING_SIZE, "common_name");
1487 lvars[0].fops = &llite_name_fops;
1488 err = lprocfs_add_vars(dir, lvars, obd);
1492 snprintf(name, MAX_STRING_SIZE, "uuid");
1493 lvars[0].fops = &llite_uuid_fops;
1494 err = lprocfs_add_vars(dir, lvars, obd);
1500 lprocfs_remove(&sbi->ll_proc_root);
1501 lprocfs_free_stats(&sbi->ll_ra_stats);
1502 lprocfs_free_stats(&sbi->ll_stats);
1507 void ll_debugfs_unregister_super(struct super_block *sb)
1509 struct lustre_sb_info *lsi = s2lsi(sb);
1510 struct ll_sb_info *sbi = ll_s2sbi(sb);
1512 kobject_put(lsi->lsi_kobj);
1514 kset_unregister(&sbi->ll_kset);
1515 wait_for_completion(&sbi->ll_kobj_unregister);
1517 if (sbi->ll_proc_root) {
1518 lprocfs_remove(&sbi->ll_proc_root);
1519 lprocfs_free_stats(&sbi->ll_ra_stats);
1520 lprocfs_free_stats(&sbi->ll_stats);
1523 #undef MAX_STRING_SIZE
1525 #define pct(a,b) (b ? a * 100 / b : 0)
1527 static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
1528 struct seq_file *seq, int which)
1530 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
1531 unsigned long start, end, r, w;
1532 char *unitp = "KMGTPEZY";
1534 struct per_process_info *pp_info = &io_extents->pp_extents[which];
1540 for(i = 0; i < LL_HIST_MAX; i++) {
1541 read_tot += pp_info->pp_r_hist.oh_buckets[i];
1542 write_tot += pp_info->pp_w_hist.oh_buckets[i];
1545 for(i = 0; i < LL_HIST_MAX; i++) {
1546 r = pp_info->pp_r_hist.oh_buckets[i];
1547 w = pp_info->pp_w_hist.oh_buckets[i];
1550 end = 1 << (i + LL_HIST_START - units);
1551 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu | "
1552 "%14lu %4lu %4lu\n", start, *unitp, end, *unitp,
1553 (i == LL_HIST_MAX - 1) ? '+' : ' ',
1554 r, pct(r, read_tot), pct(read_cum, read_tot),
1555 w, pct(w, write_tot), pct(write_cum, write_tot));
1557 if (start == 1<<10) {
1562 if (read_cum == read_tot && write_cum == write_tot)
1567 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
1569 struct timespec64 now;
1570 struct ll_sb_info *sbi = seq->private;
1571 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1574 ktime_get_real_ts64(&now);
1576 if (!sbi->ll_rw_stats_on) {
1577 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
1580 seq_printf(seq, "snapshot_time: %llu.%09lu (secs.nsecs)\n",
1581 (s64)now.tv_sec, now.tv_nsec);
1582 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1583 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1584 "extents", "calls", "%", "cum%",
1585 "calls", "%", "cum%");
1586 spin_lock(&sbi->ll_pp_extent_lock);
1587 for (k = 0; k < LL_PROCESS_HIST_MAX; k++) {
1588 if (io_extents->pp_extents[k].pid != 0) {
1589 seq_printf(seq, "\nPID: %d\n",
1590 io_extents->pp_extents[k].pid);
1591 ll_display_extents_info(io_extents, seq, k);
1594 spin_unlock(&sbi->ll_pp_extent_lock);
1598 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
1599 const char __user *buf,
1603 struct seq_file *seq = file->private_data;
1604 struct ll_sb_info *sbi = seq->private;
1605 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1612 value = ll_stats_pid_write(buf, len);
1615 sbi->ll_rw_stats_on = 0;
1617 sbi->ll_rw_stats_on = 1;
1619 spin_lock(&sbi->ll_pp_extent_lock);
1620 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1621 io_extents->pp_extents[i].pid = 0;
1622 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1623 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1625 spin_unlock(&sbi->ll_pp_extent_lock);
1629 LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
1631 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
1633 struct timespec64 now;
1634 struct ll_sb_info *sbi = seq->private;
1635 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1637 ktime_get_real_ts64(&now);
1639 if (!sbi->ll_rw_stats_on) {
1640 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
1643 seq_printf(seq, "snapshot_time: %llu.%09lu (secs.nsecs)\n",
1644 (s64)now.tv_sec, now.tv_nsec);
1646 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1647 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1648 "extents", "calls", "%", "cum%",
1649 "calls", "%", "cum%");
1650 spin_lock(&sbi->ll_lock);
1651 ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
1652 spin_unlock(&sbi->ll_lock);
1657 static ssize_t ll_rw_extents_stats_seq_write(struct file *file,
1658 const char __user *buf,
1659 size_t len, loff_t *off)
1661 struct seq_file *seq = file->private_data;
1662 struct ll_sb_info *sbi = seq->private;
1663 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1670 value = ll_stats_pid_write(buf, len);
1673 sbi->ll_rw_stats_on = 0;
1675 sbi->ll_rw_stats_on = 1;
1677 spin_lock(&sbi->ll_pp_extent_lock);
1678 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
1679 io_extents->pp_extents[i].pid = 0;
1680 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1681 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1683 spin_unlock(&sbi->ll_pp_extent_lock);
1687 LPROC_SEQ_FOPS(ll_rw_extents_stats);
1689 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
1690 struct ll_file_data *file, loff_t pos,
1691 size_t count, int rw)
1694 struct ll_rw_process_info *process;
1695 struct ll_rw_process_info *offset;
1696 int *off_count = &sbi->ll_rw_offset_entry_count;
1697 int *process_count = &sbi->ll_offset_process_count;
1698 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1700 if(!sbi->ll_rw_stats_on)
1702 process = sbi->ll_rw_process_info;
1703 offset = sbi->ll_rw_offset_info;
1705 spin_lock(&sbi->ll_pp_extent_lock);
1706 /* Extent statistics */
1707 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1708 if(io_extents->pp_extents[i].pid == pid) {
1716 sbi->ll_extent_process_count =
1717 (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1718 cur = sbi->ll_extent_process_count;
1719 io_extents->pp_extents[cur].pid = pid;
1720 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1721 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1724 for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
1725 (i < (LL_HIST_MAX - 1)); i++);
1727 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1728 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1730 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1731 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1733 spin_unlock(&sbi->ll_pp_extent_lock);
1735 spin_lock(&sbi->ll_process_lock);
1736 /* Offset statistics */
1737 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1738 if (process[i].rw_pid == pid) {
1739 if (process[i].rw_last_file != file) {
1740 process[i].rw_range_start = pos;
1741 process[i].rw_last_file_pos = pos + count;
1742 process[i].rw_smallest_extent = count;
1743 process[i].rw_largest_extent = count;
1744 process[i].rw_offset = 0;
1745 process[i].rw_last_file = file;
1746 spin_unlock(&sbi->ll_process_lock);
1749 if (process[i].rw_last_file_pos != pos) {
1751 (*off_count + 1) % LL_OFFSET_HIST_MAX;
1752 offset[*off_count].rw_op = process[i].rw_op;
1753 offset[*off_count].rw_pid = pid;
1754 offset[*off_count].rw_range_start =
1755 process[i].rw_range_start;
1756 offset[*off_count].rw_range_end =
1757 process[i].rw_last_file_pos;
1758 offset[*off_count].rw_smallest_extent =
1759 process[i].rw_smallest_extent;
1760 offset[*off_count].rw_largest_extent =
1761 process[i].rw_largest_extent;
1762 offset[*off_count].rw_offset =
1763 process[i].rw_offset;
1764 process[i].rw_op = rw;
1765 process[i].rw_range_start = pos;
1766 process[i].rw_smallest_extent = count;
1767 process[i].rw_largest_extent = count;
1768 process[i].rw_offset = pos -
1769 process[i].rw_last_file_pos;
1771 if(process[i].rw_smallest_extent > count)
1772 process[i].rw_smallest_extent = count;
1773 if(process[i].rw_largest_extent < count)
1774 process[i].rw_largest_extent = count;
1775 process[i].rw_last_file_pos = pos + count;
1776 spin_unlock(&sbi->ll_process_lock);
1780 *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
1781 process[*process_count].rw_pid = pid;
1782 process[*process_count].rw_op = rw;
1783 process[*process_count].rw_range_start = pos;
1784 process[*process_count].rw_last_file_pos = pos + count;
1785 process[*process_count].rw_smallest_extent = count;
1786 process[*process_count].rw_largest_extent = count;
1787 process[*process_count].rw_offset = 0;
1788 process[*process_count].rw_last_file = file;
1789 spin_unlock(&sbi->ll_process_lock);
1792 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1794 struct timespec64 now;
1795 struct ll_sb_info *sbi = seq->private;
1796 struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
1797 struct ll_rw_process_info *process = sbi->ll_rw_process_info;
1800 ktime_get_real_ts64(&now);
1802 if (!sbi->ll_rw_stats_on) {
1803 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
1806 spin_lock(&sbi->ll_process_lock);
1808 seq_printf(seq, "snapshot_time: %llu.%09lu (secs.nsecs)\n",
1809 (s64)now.tv_sec, now.tv_nsec);
1810 seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
1811 "R/W", "PID", "RANGE START", "RANGE END",
1812 "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
1814 /* We stored the discontiguous offsets here; print them first */
1815 for (i = 0; i < LL_OFFSET_HIST_MAX; i++) {
1816 if (offset[i].rw_pid != 0)
1818 "%3c %10d %14llu %14llu %17lu %17lu %14llu\n",
1819 offset[i].rw_op == READ ? 'R' : 'W',
1821 offset[i].rw_range_start,
1822 offset[i].rw_range_end,
1823 (unsigned long)offset[i].rw_smallest_extent,
1824 (unsigned long)offset[i].rw_largest_extent,
1825 offset[i].rw_offset);
1828 /* Then print the current offsets for each process */
1829 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1830 if (process[i].rw_pid != 0)
1832 "%3c %10d %14llu %14llu %17lu %17lu %14llu\n",
1833 process[i].rw_op == READ ? 'R' : 'W',
1835 process[i].rw_range_start,
1836 process[i].rw_last_file_pos,
1837 (unsigned long)process[i].rw_smallest_extent,
1838 (unsigned long)process[i].rw_largest_extent,
1839 process[i].rw_offset);
1841 spin_unlock(&sbi->ll_process_lock);
1846 static ssize_t ll_rw_offset_stats_seq_write(struct file *file,
1847 const char __user *buf,
1848 size_t len, loff_t *off)
1850 struct seq_file *seq = file->private_data;
1851 struct ll_sb_info *sbi = seq->private;
1852 struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
1853 struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
1859 value = ll_stats_pid_write(buf, len);
1862 sbi->ll_rw_stats_on = 0;
1864 sbi->ll_rw_stats_on = 1;
1866 spin_lock(&sbi->ll_process_lock);
1867 sbi->ll_offset_process_count = 0;
1868 sbi->ll_rw_offset_entry_count = 0;
1869 memset(process_info, 0, sizeof(struct ll_rw_process_info) *
1870 LL_PROCESS_HIST_MAX);
1871 memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
1872 LL_OFFSET_HIST_MAX);
1873 spin_unlock(&sbi->ll_process_lock);
1879 * ll_stats_pid_write() - Determine if stats collection should be enabled
1880 * @buf: Buffer containing the data written
1881 * @len: Number of bytes in the buffer
1883 * Several proc files begin collecting stats when a value is written, and stop
1884 * collecting when either '0' or 'disable' is written. This function checks the
1885 * written value to see if collection should be enabled or disabled.
1887 * Return: If '0' or 'disable' is provided, 0 is returned. If the text
1888 * equivalent of a number is written, that number is returned. Otherwise,
1889 * 1 is returned. Non-zero return values indicate collection should be enabled.
1891 static __s64 ll_stats_pid_write(const char __user *buf, size_t len)
1893 unsigned long long value = 1;
1897 rc = kstrtoull_from_user(buf, len, 0, &value);
1898 if (rc < 0 && len < sizeof(kernbuf)) {
1900 if (copy_from_user(kernbuf, buf, len))
1904 if (kernbuf[len - 1] == '\n')
1905 kernbuf[len - 1] = 0;
1907 if (strncasecmp(kernbuf, "disable", 7) == 0)
1914 LPROC_SEQ_FOPS(ll_rw_offset_stats);
1915 #endif /* CONFIG_PROC_FS */