4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2016, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 #define DEBUG_SUBSYSTEM S_LLITE
34 #include <linux/version.h>
35 #include <linux/user_namespace.h>
36 #ifdef HAVE_UIDGID_HEADER
37 # include <linux/uidgid.h>
39 #include <lustre_param.h>
40 #include <lprocfs_status.h>
41 #include <obd_support.h>
43 #include "llite_internal.h"
44 #include "vvp_internal.h"
46 struct proc_dir_entry *proc_lustre_fs_root;
49 /* /proc/lustre/llite mount point registration */
50 static const struct file_operations ll_rw_extents_stats_fops;
51 static const struct file_operations ll_rw_extents_stats_pp_fops;
52 static const struct file_operations ll_rw_offset_stats_fops;
53 static __s64 ll_stats_pid_write(const char __user *buf, size_t len);
55 static int ll_blksize_seq_show(struct seq_file *m, void *v)
57 struct super_block *sb = m->private;
58 struct obd_statfs osfs;
62 rc = ll_statfs_internal(sb, &osfs,
63 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
66 seq_printf(m, "%u\n", osfs.os_bsize);
69 LPROC_SEQ_FOPS_RO(ll_blksize);
71 static int ll_kbytestotal_seq_show(struct seq_file *m, void *v)
73 struct super_block *sb = m->private;
74 struct obd_statfs osfs;
78 rc = ll_statfs_internal(sb, &osfs,
79 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
82 __u32 blk_size = osfs.os_bsize >> 10;
83 __u64 result = osfs.os_blocks;
85 while (blk_size >>= 1)
88 seq_printf(m, "%llu\n", result);
92 LPROC_SEQ_FOPS_RO(ll_kbytestotal);
94 static int ll_kbytesfree_seq_show(struct seq_file *m, void *v)
96 struct super_block *sb = m->private;
97 struct obd_statfs osfs;
101 rc = ll_statfs_internal(sb, &osfs,
102 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
105 __u32 blk_size = osfs.os_bsize >> 10;
106 __u64 result = osfs.os_bfree;
108 while (blk_size >>= 1)
111 seq_printf(m, "%llu\n", result);
115 LPROC_SEQ_FOPS_RO(ll_kbytesfree);
117 static int ll_kbytesavail_seq_show(struct seq_file *m, void *v)
119 struct super_block *sb = m->private;
120 struct obd_statfs osfs;
124 rc = ll_statfs_internal(sb, &osfs,
125 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
128 __u32 blk_size = osfs.os_bsize >> 10;
129 __u64 result = osfs.os_bavail;
131 while (blk_size >>= 1)
134 seq_printf(m, "%llu\n", result);
138 LPROC_SEQ_FOPS_RO(ll_kbytesavail);
140 static int ll_filestotal_seq_show(struct seq_file *m, void *v)
142 struct super_block *sb = m->private;
143 struct obd_statfs osfs;
147 rc = ll_statfs_internal(sb, &osfs,
148 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
151 seq_printf(m, "%llu\n", osfs.os_files);
154 LPROC_SEQ_FOPS_RO(ll_filestotal);
156 static int ll_filesfree_seq_show(struct seq_file *m, void *v)
158 struct super_block *sb = m->private;
159 struct obd_statfs osfs;
163 rc = ll_statfs_internal(sb, &osfs,
164 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
167 seq_printf(m, "%llu\n", osfs.os_ffree);
170 LPROC_SEQ_FOPS_RO(ll_filesfree);
172 static int ll_client_type_seq_show(struct seq_file *m, void *v)
174 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
176 LASSERT(sbi != NULL);
178 seq_puts(m, "local client\n");
181 LPROC_SEQ_FOPS_RO(ll_client_type);
183 static int ll_fstype_seq_show(struct seq_file *m, void *v)
185 struct super_block *sb = m->private;
188 seq_printf(m, "%s\n", sb->s_type->name);
191 LPROC_SEQ_FOPS_RO(ll_fstype);
193 static int ll_sb_uuid_seq_show(struct seq_file *m, void *v)
195 struct super_block *sb = m->private;
198 seq_printf(m, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
201 LPROC_SEQ_FOPS_RO(ll_sb_uuid);
203 static int ll_xattr_cache_seq_show(struct seq_file *m, void *v)
205 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
207 seq_printf(m, "%u\n", sbi->ll_xattr_cache_enabled);
211 static ssize_t ll_xattr_cache_seq_write(struct file *file,
212 const char __user *buffer,
213 size_t count, loff_t *off)
215 struct seq_file *m = file->private_data;
216 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
220 rc = lprocfs_str_to_s64(buffer, count, &val);
224 if (val != 0 && val != 1)
227 if (val == 1 && !(sbi->ll_flags & LL_SBI_XATTR_CACHE))
230 sbi->ll_xattr_cache_enabled = val;
234 LPROC_SEQ_FOPS(ll_xattr_cache);
236 static int ll_site_stats_seq_show(struct seq_file *m, void *v)
238 struct super_block *sb = m->private;
241 * See description of statistical counters in struct cl_site, and
244 return cl_site_stats_print(lu2cl_site(ll_s2sbi(sb)->ll_site), m);
246 LPROC_SEQ_FOPS_RO(ll_site_stats);
248 static int ll_max_readahead_mb_seq_show(struct seq_file *m, void *v)
250 struct super_block *sb = m->private;
251 struct ll_sb_info *sbi = ll_s2sbi(sb);
255 spin_lock(&sbi->ll_lock);
256 pages_number = sbi->ll_ra_info.ra_max_pages;
257 spin_unlock(&sbi->ll_lock);
259 mult = 1 << (20 - PAGE_SHIFT);
260 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
264 ll_max_readahead_mb_seq_write(struct file *file, const char __user *buffer,
265 size_t count, loff_t *off)
267 struct seq_file *m = file->private_data;
268 struct super_block *sb = m->private;
269 struct ll_sb_info *sbi = ll_s2sbi(sb);
273 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
277 pages_number >>= PAGE_SHIFT;
279 if (pages_number < 0 || pages_number > totalram_pages / 2) {
281 CERROR("%s: can't set max_readahead_mb=%lu > %luMB\n",
282 ll_get_fsname(sb, NULL, 0),
283 (unsigned long)pages_number >> (20 - PAGE_SHIFT),
284 totalram_pages >> (20 - PAGE_SHIFT + 1));
288 spin_lock(&sbi->ll_lock);
289 sbi->ll_ra_info.ra_max_pages = pages_number;
290 spin_unlock(&sbi->ll_lock);
293 LPROC_SEQ_FOPS(ll_max_readahead_mb);
295 static int ll_max_readahead_per_file_mb_seq_show(struct seq_file *m, void *v)
297 struct super_block *sb = m->private;
298 struct ll_sb_info *sbi = ll_s2sbi(sb);
302 spin_lock(&sbi->ll_lock);
303 pages_number = sbi->ll_ra_info.ra_max_pages_per_file;
304 spin_unlock(&sbi->ll_lock);
306 mult = 1 << (20 - PAGE_SHIFT);
307 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
311 ll_max_readahead_per_file_mb_seq_write(struct file *file,
312 const char __user *buffer,
313 size_t count, loff_t *off)
315 struct seq_file *m = file->private_data;
316 struct super_block *sb = m->private;
317 struct ll_sb_info *sbi = ll_s2sbi(sb);
321 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
325 pages_number >>= PAGE_SHIFT;
327 if (pages_number < 0 || pages_number > sbi->ll_ra_info.ra_max_pages) {
328 CERROR("%s: can't set max_readahead_per_file_mb=%lu > "
329 "max_read_ahead_mb=%lu\n", ll_get_fsname(sb, NULL, 0),
330 (unsigned long)pages_number >> (20 - PAGE_SHIFT),
331 sbi->ll_ra_info.ra_max_pages >> (20 - PAGE_SHIFT));
335 spin_lock(&sbi->ll_lock);
336 sbi->ll_ra_info.ra_max_pages_per_file = pages_number;
337 spin_unlock(&sbi->ll_lock);
340 LPROC_SEQ_FOPS(ll_max_readahead_per_file_mb);
342 static int ll_max_read_ahead_whole_mb_seq_show(struct seq_file *m, void *v)
344 struct super_block *sb = m->private;
345 struct ll_sb_info *sbi = ll_s2sbi(sb);
349 spin_lock(&sbi->ll_lock);
350 pages_number = sbi->ll_ra_info.ra_max_read_ahead_whole_pages;
351 spin_unlock(&sbi->ll_lock);
353 mult = 1 << (20 - PAGE_SHIFT);
354 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
358 ll_max_read_ahead_whole_mb_seq_write(struct file *file,
359 const char __user *buffer,
360 size_t count, loff_t *off)
362 struct seq_file *m = file->private_data;
363 struct super_block *sb = m->private;
364 struct ll_sb_info *sbi = ll_s2sbi(sb);
368 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
372 pages_number >>= PAGE_SHIFT;
374 /* Cap this at the current max readahead window size, the readahead
375 * algorithm does this anyway so it's pointless to set it larger. */
376 if (pages_number < 0 ||
377 pages_number > sbi->ll_ra_info.ra_max_pages_per_file) {
378 int pages_shift = 20 - PAGE_SHIFT;
379 CERROR("%s: can't set max_read_ahead_whole_mb=%lu > "
380 "max_read_ahead_per_file_mb=%lu\n",
381 ll_get_fsname(sb, NULL, 0),
382 (unsigned long)pages_number >> pages_shift,
383 sbi->ll_ra_info.ra_max_pages_per_file >> pages_shift);
387 spin_lock(&sbi->ll_lock);
388 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = pages_number;
389 spin_unlock(&sbi->ll_lock);
392 LPROC_SEQ_FOPS(ll_max_read_ahead_whole_mb);
394 static int ll_max_cached_mb_seq_show(struct seq_file *m, void *v)
396 struct super_block *sb = m->private;
397 struct ll_sb_info *sbi = ll_s2sbi(sb);
398 struct cl_client_cache *cache = sbi->ll_cache;
399 int shift = 20 - PAGE_SHIFT;
403 max_cached_mb = cache->ccc_lru_max >> shift;
404 unused_mb = atomic_long_read(&cache->ccc_lru_left) >> shift;
405 seq_printf(m, "users: %d\n"
406 "max_cached_mb: %ld\n"
409 "reclaim_count: %u\n",
410 atomic_read(&cache->ccc_users),
412 max_cached_mb - unused_mb,
414 cache->ccc_lru_shrinkers);
419 ll_max_cached_mb_seq_write(struct file *file, const char __user *buffer,
420 size_t count, loff_t *off)
422 struct seq_file *m = file->private_data;
423 struct super_block *sb = m->private;
424 struct ll_sb_info *sbi = ll_s2sbi(sb);
425 struct cl_client_cache *cache = sbi->ll_cache;
435 if (count >= sizeof(kernbuf))
438 if (copy_from_user(kernbuf, buffer, count))
442 buffer += lprocfs_find_named_value(kernbuf, "max_cached_mb:", &count) -
444 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
448 pages_number >>= PAGE_SHIFT;
450 if (pages_number < 0 || pages_number > totalram_pages) {
451 CERROR("%s: can't set max cache more than %lu MB\n",
452 ll_get_fsname(sb, NULL, 0),
453 totalram_pages >> (20 - PAGE_SHIFT));
456 /* Allow enough cache so clients can make well-formed RPCs */
457 pages_number = max_t(long, pages_number, PTLRPC_MAX_BRW_PAGES);
459 spin_lock(&sbi->ll_lock);
460 diff = pages_number - cache->ccc_lru_max;
461 spin_unlock(&sbi->ll_lock);
463 /* easy - add more LRU slots. */
465 atomic_long_add(diff, &cache->ccc_lru_left);
469 env = cl_env_get(&refcheck);
477 /* reduce LRU budget from free slots. */
481 ov = atomic_long_read(&cache->ccc_lru_left);
485 nv = ov > diff ? ov - diff : 0;
486 rc = atomic_long_cmpxchg(&cache->ccc_lru_left, ov, nv);
487 if (likely(ov == rc)) {
497 if (sbi->ll_dt_exp == NULL) { /* being initialized */
502 /* difficult - have to ask OSCs to drop LRU slots. */
504 rc = obd_set_info_async(env, sbi->ll_dt_exp,
505 sizeof(KEY_CACHE_LRU_SHRINK),
506 KEY_CACHE_LRU_SHRINK,
507 sizeof(tmp), &tmp, NULL);
511 cl_env_put(env, &refcheck);
515 spin_lock(&sbi->ll_lock);
516 cache->ccc_lru_max = pages_number;
517 spin_unlock(&sbi->ll_lock);
520 atomic_long_add(nrpages, &cache->ccc_lru_left);
524 LPROC_SEQ_FOPS(ll_max_cached_mb);
526 static int ll_checksum_seq_show(struct seq_file *m, void *v)
528 struct super_block *sb = m->private;
529 struct ll_sb_info *sbi = ll_s2sbi(sb);
531 seq_printf(m, "%u\n", (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0);
535 static ssize_t ll_checksum_seq_write(struct file *file,
536 const char __user *buffer,
537 size_t count, loff_t *off)
539 struct seq_file *m = file->private_data;
540 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
548 rc = lprocfs_str_to_s64(buffer, count, &val);
552 sbi->ll_flags |= LL_SBI_CHECKSUM;
554 sbi->ll_flags &= ~LL_SBI_CHECKSUM;
556 rc = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
557 KEY_CHECKSUM, sizeof(val), &val, NULL);
559 CWARN("Failed to set OSC checksum flags: %d\n", rc);
563 LPROC_SEQ_FOPS(ll_checksum);
565 static int ll_rd_track_id(struct seq_file *m, enum stats_track_type type)
567 struct super_block *sb = m->private;
569 if (ll_s2sbi(sb)->ll_stats_track_type == type) {
570 seq_printf(m, "%d\n",
571 ll_s2sbi(sb)->ll_stats_track_id);
572 } else if (ll_s2sbi(sb)->ll_stats_track_type == STATS_TRACK_ALL) {
573 seq_puts(m, "0 (all)\n");
575 seq_puts(m, "untracked\n");
580 static int ll_wr_track_id(const char __user *buffer, unsigned long count,
581 void *data, enum stats_track_type type)
583 struct super_block *sb = data;
587 rc = lprocfs_str_to_s64(buffer, count, &pid);
590 if (pid > INT_MAX || pid < 0)
593 ll_s2sbi(sb)->ll_stats_track_id = pid;
595 ll_s2sbi(sb)->ll_stats_track_type = STATS_TRACK_ALL;
597 ll_s2sbi(sb)->ll_stats_track_type = type;
598 lprocfs_clear_stats(ll_s2sbi(sb)->ll_stats);
602 static int ll_track_pid_seq_show(struct seq_file *m, void *v)
604 return ll_rd_track_id(m, STATS_TRACK_PID);
607 static ssize_t ll_track_pid_seq_write(struct file *file,
608 const char __user *buffer,
609 size_t count, loff_t *off)
611 struct seq_file *seq = file->private_data;
612 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PID);
614 LPROC_SEQ_FOPS(ll_track_pid);
616 static int ll_track_ppid_seq_show(struct seq_file *m, void *v)
618 return ll_rd_track_id(m, STATS_TRACK_PPID);
621 static ssize_t ll_track_ppid_seq_write(struct file *file,
622 const char __user *buffer,
623 size_t count, loff_t *off)
625 struct seq_file *seq = file->private_data;
626 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PPID);
628 LPROC_SEQ_FOPS(ll_track_ppid);
630 static int ll_track_gid_seq_show(struct seq_file *m, void *v)
632 return ll_rd_track_id(m, STATS_TRACK_GID);
635 static ssize_t ll_track_gid_seq_write(struct file *file,
636 const char __user *buffer,
637 size_t count, loff_t *off)
639 struct seq_file *seq = file->private_data;
640 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_GID);
642 LPROC_SEQ_FOPS(ll_track_gid);
644 static int ll_statahead_max_seq_show(struct seq_file *m, void *v)
646 struct super_block *sb = m->private;
647 struct ll_sb_info *sbi = ll_s2sbi(sb);
649 seq_printf(m, "%u\n", sbi->ll_sa_max);
653 static ssize_t ll_statahead_max_seq_write(struct file *file,
654 const char __user *buffer,
655 size_t count, loff_t *off)
657 struct seq_file *m = file->private_data;
658 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
662 rc = lprocfs_str_to_s64(buffer, count, &val);
666 if (val >= 0 && val <= LL_SA_RPC_MAX)
667 sbi->ll_sa_max = val;
669 CERROR("Bad statahead_max value %lld. Valid values are in "
670 "the range [0, %d]\n", val, LL_SA_RPC_MAX);
674 LPROC_SEQ_FOPS(ll_statahead_max);
676 static int ll_statahead_agl_seq_show(struct seq_file *m, void *v)
678 struct super_block *sb = m->private;
679 struct ll_sb_info *sbi = ll_s2sbi(sb);
681 seq_printf(m, "%u\n",
682 sbi->ll_flags & LL_SBI_AGL_ENABLED ? 1 : 0);
686 static ssize_t ll_statahead_agl_seq_write(struct file *file,
687 const char __user *buffer,
688 size_t count, loff_t *off)
690 struct seq_file *m = file->private_data;
691 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
695 rc = lprocfs_str_to_s64(buffer, count, &val);
700 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
702 sbi->ll_flags &= ~LL_SBI_AGL_ENABLED;
706 LPROC_SEQ_FOPS(ll_statahead_agl);
708 static int ll_statahead_stats_seq_show(struct seq_file *m, void *v)
710 struct super_block *sb = m->private;
711 struct ll_sb_info *sbi = ll_s2sbi(sb);
713 seq_printf(m, "statahead total: %u\n"
714 "statahead wrong: %u\n"
716 atomic_read(&sbi->ll_sa_total),
717 atomic_read(&sbi->ll_sa_wrong),
718 atomic_read(&sbi->ll_agl_total));
721 LPROC_SEQ_FOPS_RO(ll_statahead_stats);
723 static int ll_lazystatfs_seq_show(struct seq_file *m, void *v)
725 struct super_block *sb = m->private;
726 struct ll_sb_info *sbi = ll_s2sbi(sb);
728 seq_printf(m, "%u\n",
729 (sbi->ll_flags & LL_SBI_LAZYSTATFS) ? 1 : 0);
733 static ssize_t ll_lazystatfs_seq_write(struct file *file,
734 const char __user *buffer,
735 size_t count, loff_t *off)
737 struct seq_file *m = file->private_data;
738 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
742 rc = lprocfs_str_to_s64(buffer, count, &val);
747 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
749 sbi->ll_flags &= ~LL_SBI_LAZYSTATFS;
753 LPROC_SEQ_FOPS(ll_lazystatfs);
755 static int ll_max_easize_seq_show(struct seq_file *m, void *v)
757 struct super_block *sb = m->private;
758 struct ll_sb_info *sbi = ll_s2sbi(sb);
762 rc = ll_get_max_mdsize(sbi, &ealen);
766 seq_printf(m, "%u\n", ealen);
769 LPROC_SEQ_FOPS_RO(ll_max_easize);
772 * Get default_easize.
774 * \see client_obd::cl_default_mds_easize
776 * \param[in] m seq_file handle
777 * \param[in] v unused for single entry
779 * \retval 0 on success
780 * \retval negative negated errno on failure
782 static int ll_default_easize_seq_show(struct seq_file *m, void *v)
784 struct super_block *sb = m->private;
785 struct ll_sb_info *sbi = ll_s2sbi(sb);
789 rc = ll_get_default_mdsize(sbi, &ealen);
793 seq_printf(m, "%u\n", ealen);
798 * Set default_easize.
800 * Range checking on the passed value is handled by
801 * ll_set_default_mdsize().
803 * \see client_obd::cl_default_mds_easize
805 * \param[in] file proc file
806 * \param[in] buffer string passed from user space
807 * \param[in] count \a buffer length
808 * \param[in] off unused for single entry
810 * \retval positive \a count on success
811 * \retval negative negated errno on failure
813 static ssize_t ll_default_easize_seq_write(struct file *file,
814 const char __user *buffer,
815 size_t count, loff_t *unused)
817 struct seq_file *seq = file->private_data;
818 struct super_block *sb = (struct super_block *)seq->private;
819 struct ll_sb_info *sbi = ll_s2sbi(sb);
826 rc = lprocfs_str_to_s64(buffer, count, &val);
829 if (val < 0 || val > INT_MAX)
832 rc = ll_set_default_mdsize(sbi, val);
838 LPROC_SEQ_FOPS(ll_default_easize);
840 static int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
842 const char *str[] = LL_SBI_FLAGS;
843 struct super_block *sb = m->private;
844 int flags = ll_s2sbi(sb)->ll_flags;
848 if (ARRAY_SIZE(str) <= i) {
849 CERROR("%s: Revise array LL_SBI_FLAGS to match sbi "
850 "flags please.\n", ll_get_fsname(sb, NULL, 0));
855 seq_printf(m, "%s ", str[i]);
859 seq_printf(m, "\b\n");
862 LPROC_SEQ_FOPS_RO(ll_sbi_flags);
864 static int ll_fast_read_seq_show(struct seq_file *m, void *v)
866 struct super_block *sb = m->private;
867 struct ll_sb_info *sbi = ll_s2sbi(sb);
869 seq_printf(m, "%u\n", !!(sbi->ll_flags & LL_SBI_FAST_READ));
874 ll_fast_read_seq_write(struct file *file, const char __user *buffer,
875 size_t count, loff_t *off)
877 struct seq_file *m = file->private_data;
878 struct super_block *sb = m->private;
879 struct ll_sb_info *sbi = ll_s2sbi(sb);
883 rc = lprocfs_str_to_s64(buffer, count, &val);
887 spin_lock(&sbi->ll_lock);
889 sbi->ll_flags |= LL_SBI_FAST_READ;
891 sbi->ll_flags &= ~LL_SBI_FAST_READ;
892 spin_unlock(&sbi->ll_lock);
896 LPROC_SEQ_FOPS(ll_fast_read);
898 static int ll_unstable_stats_seq_show(struct seq_file *m, void *v)
900 struct super_block *sb = m->private;
901 struct ll_sb_info *sbi = ll_s2sbi(sb);
902 struct cl_client_cache *cache = sbi->ll_cache;
906 pages = atomic_long_read(&cache->ccc_unstable_nr);
907 mb = (pages * PAGE_SIZE) >> 20;
909 seq_printf(m, "unstable_check: %8d\n"
910 "unstable_pages: %12ld\n"
911 "unstable_mb: %8d\n",
912 cache->ccc_unstable_check, pages, mb);
916 static ssize_t ll_unstable_stats_seq_write(struct file *file,
917 const char __user *buffer,
918 size_t count, loff_t *unused)
920 struct seq_file *seq = file->private_data;
921 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)seq->private);
928 if (count >= sizeof(kernbuf))
931 if (copy_from_user(kernbuf, buffer, count))
935 buffer += lprocfs_find_named_value(kernbuf, "unstable_check:", &count) -
937 rc = lprocfs_str_to_s64(buffer, count, &val);
941 /* borrow lru lock to set the value */
942 spin_lock(&sbi->ll_cache->ccc_lru_lock);
943 sbi->ll_cache->ccc_unstable_check = !!val;
944 spin_unlock(&sbi->ll_cache->ccc_lru_lock);
948 LPROC_SEQ_FOPS(ll_unstable_stats);
950 static int ll_root_squash_seq_show(struct seq_file *m, void *v)
952 struct super_block *sb = m->private;
953 struct ll_sb_info *sbi = ll_s2sbi(sb);
954 struct root_squash_info *squash = &sbi->ll_squash;
956 seq_printf(m, "%u:%u\n", squash->rsi_uid, squash->rsi_gid);
960 static ssize_t ll_root_squash_seq_write(struct file *file,
961 const char __user *buffer,
962 size_t count, loff_t *off)
964 struct seq_file *m = file->private_data;
965 struct super_block *sb = m->private;
966 struct ll_sb_info *sbi = ll_s2sbi(sb);
967 struct root_squash_info *squash = &sbi->ll_squash;
969 return lprocfs_wr_root_squash(buffer, count, squash,
970 ll_get_fsname(sb, NULL, 0));
972 LPROC_SEQ_FOPS(ll_root_squash);
974 static int ll_nosquash_nids_seq_show(struct seq_file *m, void *v)
976 struct super_block *sb = m->private;
977 struct ll_sb_info *sbi = ll_s2sbi(sb);
978 struct root_squash_info *squash = &sbi->ll_squash;
981 down_read(&squash->rsi_sem);
982 if (!list_empty(&squash->rsi_nosquash_nids)) {
983 len = cfs_print_nidlist(m->buf + m->count, m->size - m->count,
984 &squash->rsi_nosquash_nids);
988 seq_puts(m, "NONE\n");
990 up_read(&squash->rsi_sem);
995 static ssize_t ll_nosquash_nids_seq_write(struct file *file,
996 const char __user *buffer,
997 size_t count, loff_t *off)
999 struct seq_file *m = file->private_data;
1000 struct super_block *sb = m->private;
1001 struct ll_sb_info *sbi = ll_s2sbi(sb);
1002 struct root_squash_info *squash = &sbi->ll_squash;
1005 rc = lprocfs_wr_nosquash_nids(buffer, count, squash,
1006 ll_get_fsname(sb, NULL, 0));
1010 ll_compute_rootsquash_state(sbi);
1014 LPROC_SEQ_FOPS(ll_nosquash_nids);
1016 struct lprocfs_vars lprocfs_llite_obd_vars[] = {
1018 .fops = &ll_sb_uuid_fops },
1020 .fops = &ll_fstype_fops },
1022 .fops = &ll_site_stats_fops },
1023 { .name = "blocksize",
1024 .fops = &ll_blksize_fops },
1025 { .name = "kbytestotal",
1026 .fops = &ll_kbytestotal_fops },
1027 { .name = "kbytesfree",
1028 .fops = &ll_kbytesfree_fops },
1029 { .name = "kbytesavail",
1030 .fops = &ll_kbytesavail_fops },
1031 { .name = "filestotal",
1032 .fops = &ll_filestotal_fops },
1033 { .name = "filesfree",
1034 .fops = &ll_filesfree_fops },
1035 { .name = "client_type",
1036 .fops = &ll_client_type_fops },
1037 { .name = "max_read_ahead_mb",
1038 .fops = &ll_max_readahead_mb_fops },
1039 { .name = "max_read_ahead_per_file_mb",
1040 .fops = &ll_max_readahead_per_file_mb_fops },
1041 { .name = "max_read_ahead_whole_mb",
1042 .fops = &ll_max_read_ahead_whole_mb_fops },
1043 { .name = "max_cached_mb",
1044 .fops = &ll_max_cached_mb_fops },
1045 { .name = "checksum_pages",
1046 .fops = &ll_checksum_fops },
1047 { .name = "stats_track_pid",
1048 .fops = &ll_track_pid_fops },
1049 { .name = "stats_track_ppid",
1050 .fops = &ll_track_ppid_fops },
1051 { .name = "stats_track_gid",
1052 .fops = &ll_track_gid_fops },
1053 { .name = "statahead_max",
1054 .fops = &ll_statahead_max_fops },
1055 { .name = "statahead_agl",
1056 .fops = &ll_statahead_agl_fops },
1057 { .name = "statahead_stats",
1058 .fops = &ll_statahead_stats_fops },
1059 { .name = "lazystatfs",
1060 .fops = &ll_lazystatfs_fops },
1061 { .name = "max_easize",
1062 .fops = &ll_max_easize_fops },
1063 { .name = "default_easize",
1064 .fops = &ll_default_easize_fops },
1065 { .name = "sbi_flags",
1066 .fops = &ll_sbi_flags_fops },
1067 { .name = "xattr_cache",
1068 .fops = &ll_xattr_cache_fops },
1069 { .name = "unstable_stats",
1070 .fops = &ll_unstable_stats_fops },
1071 { .name = "root_squash",
1072 .fops = &ll_root_squash_fops },
1073 { .name = "nosquash_nids",
1074 .fops = &ll_nosquash_nids_fops },
1075 { .name = "fast_read",
1076 .fops = &ll_fast_read_fops, },
1080 #define MAX_STRING_SIZE 128
1082 static const struct llite_file_opcode {
1086 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
1087 /* file operation */
1088 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
1089 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
1090 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1092 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1094 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
1096 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
1098 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
1099 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
1100 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
1101 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
1102 { LPROC_LL_FAULT, LPROCFS_TYPE_REGS, "page_fault" },
1103 { LPROC_LL_MKWRITE, LPROCFS_TYPE_REGS, "page_mkwrite" },
1104 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
1105 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
1106 { LPROC_LL_READDIR, LPROCFS_TYPE_REGS, "readdir" },
1107 /* inode operation */
1108 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
1109 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "truncate" },
1110 { LPROC_LL_FLOCK, LPROCFS_TYPE_REGS, "flock" },
1111 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
1112 /* dir inode operation */
1113 { LPROC_LL_CREATE, LPROCFS_TYPE_REGS, "create" },
1114 { LPROC_LL_LINK, LPROCFS_TYPE_REGS, "link" },
1115 { LPROC_LL_UNLINK, LPROCFS_TYPE_REGS, "unlink" },
1116 { LPROC_LL_SYMLINK, LPROCFS_TYPE_REGS, "symlink" },
1117 { LPROC_LL_MKDIR, LPROCFS_TYPE_REGS, "mkdir" },
1118 { LPROC_LL_RMDIR, LPROCFS_TYPE_REGS, "rmdir" },
1119 { LPROC_LL_MKNOD, LPROCFS_TYPE_REGS, "mknod" },
1120 { LPROC_LL_RENAME, LPROCFS_TYPE_REGS, "rename" },
1121 /* special inode operation */
1122 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
1123 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
1124 { LPROC_LL_SETXATTR, LPROCFS_TYPE_REGS, "setxattr" },
1125 { LPROC_LL_GETXATTR, LPROCFS_TYPE_REGS, "getxattr" },
1126 { LPROC_LL_GETXATTR_HITS, LPROCFS_TYPE_REGS, "getxattr_hits" },
1127 { LPROC_LL_LISTXATTR, LPROCFS_TYPE_REGS, "listxattr" },
1128 { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_REGS, "removexattr" },
1129 { LPROC_LL_INODE_PERM, LPROCFS_TYPE_REGS, "inode_permission" },
1132 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
1136 if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
1137 lprocfs_counter_add(sbi->ll_stats, op, count);
1138 else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
1139 sbi->ll_stats_track_id == current->pid)
1140 lprocfs_counter_add(sbi->ll_stats, op, count);
1141 else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
1142 sbi->ll_stats_track_id == current->parent->pid)
1143 lprocfs_counter_add(sbi->ll_stats, op, count);
1144 else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
1145 sbi->ll_stats_track_id ==
1146 from_kgid(&init_user_ns, current_gid()))
1147 lprocfs_counter_add(sbi->ll_stats, op, count);
1149 EXPORT_SYMBOL(ll_stats_ops_tally);
1151 static const char *ra_stat_string[] = {
1152 [RA_STAT_HIT] = "hits",
1153 [RA_STAT_MISS] = "misses",
1154 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
1155 [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
1156 [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page",
1157 [RA_STAT_FAILED_MATCH] = "failed lock match",
1158 [RA_STAT_DISCARDED] = "read but discarded",
1159 [RA_STAT_ZERO_LEN] = "zero length file",
1160 [RA_STAT_ZERO_WINDOW] = "zero size window",
1161 [RA_STAT_EOF] = "read-ahead to EOF",
1162 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
1163 [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",
1164 [RA_STAT_FAILED_REACH_END] = "failed to reach end"
1167 LPROC_SEQ_FOPS_RO_TYPE(llite, name);
1168 LPROC_SEQ_FOPS_RO_TYPE(llite, uuid);
1170 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
1171 struct super_block *sb, char *osc, char *mdc)
1173 struct lprocfs_vars lvars[2];
1174 struct lustre_sb_info *lsi = s2lsi(sb);
1175 struct ll_sb_info *sbi = ll_s2sbi(sb);
1176 struct obd_device *obd;
1177 struct proc_dir_entry *dir;
1178 char name[MAX_STRING_SIZE + 1], *ptr;
1179 int err, id, len, rc;
1182 memset(lvars, 0, sizeof(lvars));
1184 name[MAX_STRING_SIZE] = '\0';
1185 lvars[0].name = name;
1187 LASSERT(sbi != NULL);
1188 LASSERT(mdc != NULL);
1189 LASSERT(osc != NULL);
1192 len = strlen(lsi->lsi_lmd->lmd_profile);
1193 ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
1194 if (ptr && (strcmp(ptr, "-client") == 0))
1198 snprintf(name, MAX_STRING_SIZE, "%.*s-%p", len,
1199 lsi->lsi_lmd->lmd_profile, sb);
1201 sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
1202 if (IS_ERR(sbi->ll_proc_root)) {
1203 err = PTR_ERR(sbi->ll_proc_root);
1204 sbi->ll_proc_root = NULL;
1208 rc = lprocfs_seq_create(sbi->ll_proc_root, "dump_page_cache", 0444,
1209 &vvp_dump_pgcache_file_ops, sbi);
1211 CWARN("Error adding the dump_page_cache file\n");
1213 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats", 0644,
1214 &ll_rw_extents_stats_fops, sbi);
1216 CWARN("Error adding the extent_stats file\n");
1218 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats_per_process",
1219 0644, &ll_rw_extents_stats_pp_fops, sbi);
1221 CWARN("Error adding the extents_stats_per_process file\n");
1223 rc = lprocfs_seq_create(sbi->ll_proc_root, "offset_stats", 0644,
1224 &ll_rw_offset_stats_fops, sbi);
1226 CWARN("Error adding the offset_stats file\n");
1228 /* File operations stats */
1229 sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
1230 LPROCFS_STATS_FLAG_NONE);
1231 if (sbi->ll_stats == NULL)
1232 GOTO(out, err = -ENOMEM);
1233 /* do counter init */
1234 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
1235 __u32 type = llite_opcode_table[id].type;
1237 if (type & LPROCFS_TYPE_REGS)
1239 else if (type & LPROCFS_TYPE_BYTES)
1241 else if (type & LPROCFS_TYPE_PAGES)
1243 lprocfs_counter_init(sbi->ll_stats,
1244 llite_opcode_table[id].opcode,
1245 (type & LPROCFS_CNTR_AVGMINMAX),
1246 llite_opcode_table[id].opname, ptr);
1248 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats);
1252 sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
1253 LPROCFS_STATS_FLAG_NONE);
1254 if (sbi->ll_ra_stats == NULL)
1255 GOTO(out, err = -ENOMEM);
1257 for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
1258 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
1259 ra_stat_string[id], "pages");
1260 err = lprocfs_register_stats(sbi->ll_proc_root, "read_ahead_stats",
1266 err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_llite_obd_vars, sb);
1271 obd = class_name2obd(mdc);
1273 LASSERT(obd != NULL);
1274 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1275 LASSERT(obd->obd_type->typ_name != NULL);
1277 dir = proc_mkdir(obd->obd_type->typ_name, sbi->ll_proc_root);
1279 GOTO(out, err = -ENOMEM);
1281 snprintf(name, MAX_STRING_SIZE, "common_name");
1282 lvars[0].fops = &llite_name_fops;
1283 err = lprocfs_add_vars(dir, lvars, obd);
1287 snprintf(name, MAX_STRING_SIZE, "uuid");
1288 lvars[0].fops = &llite_uuid_fops;
1289 err = lprocfs_add_vars(dir, lvars, obd);
1294 obd = class_name2obd(osc);
1296 LASSERT(obd != NULL);
1297 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1298 LASSERT(obd->obd_type->typ_name != NULL);
1300 dir = proc_mkdir(obd->obd_type->typ_name, sbi->ll_proc_root);
1302 GOTO(out, err = -ENOMEM);
1304 snprintf(name, MAX_STRING_SIZE, "common_name");
1305 lvars[0].fops = &llite_name_fops;
1306 err = lprocfs_add_vars(dir, lvars, obd);
1310 snprintf(name, MAX_STRING_SIZE, "uuid");
1311 lvars[0].fops = &llite_uuid_fops;
1312 err = lprocfs_add_vars(dir, lvars, obd);
1315 lprocfs_remove(&sbi->ll_proc_root);
1316 lprocfs_free_stats(&sbi->ll_ra_stats);
1317 lprocfs_free_stats(&sbi->ll_stats);
1322 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
1324 if (sbi->ll_proc_root) {
1325 lprocfs_remove(&sbi->ll_proc_root);
1326 lprocfs_free_stats(&sbi->ll_ra_stats);
1327 lprocfs_free_stats(&sbi->ll_stats);
1330 #undef MAX_STRING_SIZE
1332 #define pct(a,b) (b ? a * 100 / b : 0)
1334 static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
1335 struct seq_file *seq, int which)
1337 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
1338 unsigned long start, end, r, w;
1339 char *unitp = "KMGTPEZY";
1341 struct per_process_info *pp_info = &io_extents->pp_extents[which];
1347 for(i = 0; i < LL_HIST_MAX; i++) {
1348 read_tot += pp_info->pp_r_hist.oh_buckets[i];
1349 write_tot += pp_info->pp_w_hist.oh_buckets[i];
1352 for(i = 0; i < LL_HIST_MAX; i++) {
1353 r = pp_info->pp_r_hist.oh_buckets[i];
1354 w = pp_info->pp_w_hist.oh_buckets[i];
1357 end = 1 << (i + LL_HIST_START - units);
1358 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu | "
1359 "%14lu %4lu %4lu\n", start, *unitp, end, *unitp,
1360 (i == LL_HIST_MAX - 1) ? '+' : ' ',
1361 r, pct(r, read_tot), pct(read_cum, read_tot),
1362 w, pct(w, write_tot), pct(write_cum, write_tot));
1364 if (start == 1<<10) {
1369 if (read_cum == read_tot && write_cum == write_tot)
1374 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
1376 struct timespec64 now;
1377 struct ll_sb_info *sbi = seq->private;
1378 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1381 ktime_get_real_ts64(&now);
1383 if (!sbi->ll_rw_stats_on) {
1384 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
1387 seq_printf(seq, "snapshot_time: %llu.%09lu (secs.nsecs)\n",
1388 (s64)now.tv_sec, now.tv_nsec);
1389 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1390 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1391 "extents", "calls", "%", "cum%",
1392 "calls", "%", "cum%");
1393 spin_lock(&sbi->ll_pp_extent_lock);
1394 for (k = 0; k < LL_PROCESS_HIST_MAX; k++) {
1395 if (io_extents->pp_extents[k].pid != 0) {
1396 seq_printf(seq, "\nPID: %d\n",
1397 io_extents->pp_extents[k].pid);
1398 ll_display_extents_info(io_extents, seq, k);
1401 spin_unlock(&sbi->ll_pp_extent_lock);
1405 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
1406 const char __user *buf,
1410 struct seq_file *seq = file->private_data;
1411 struct ll_sb_info *sbi = seq->private;
1412 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1419 value = ll_stats_pid_write(buf, len);
1422 sbi->ll_rw_stats_on = 0;
1424 sbi->ll_rw_stats_on = 1;
1426 spin_lock(&sbi->ll_pp_extent_lock);
1427 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1428 io_extents->pp_extents[i].pid = 0;
1429 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1430 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1432 spin_unlock(&sbi->ll_pp_extent_lock);
1436 LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
1438 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
1440 struct timespec64 now;
1441 struct ll_sb_info *sbi = seq->private;
1442 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1444 ktime_get_real_ts64(&now);
1446 if (!sbi->ll_rw_stats_on) {
1447 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
1450 seq_printf(seq, "snapshot_time: %llu.%09lu (secs.nsecs)\n",
1451 (s64)now.tv_sec, now.tv_nsec);
1453 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1454 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1455 "extents", "calls", "%", "cum%",
1456 "calls", "%", "cum%");
1457 spin_lock(&sbi->ll_lock);
1458 ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
1459 spin_unlock(&sbi->ll_lock);
1464 static ssize_t ll_rw_extents_stats_seq_write(struct file *file,
1465 const char __user *buf,
1466 size_t len, loff_t *off)
1468 struct seq_file *seq = file->private_data;
1469 struct ll_sb_info *sbi = seq->private;
1470 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1477 value = ll_stats_pid_write(buf, len);
1480 sbi->ll_rw_stats_on = 0;
1482 sbi->ll_rw_stats_on = 1;
1484 spin_lock(&sbi->ll_pp_extent_lock);
1485 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
1486 io_extents->pp_extents[i].pid = 0;
1487 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1488 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1490 spin_unlock(&sbi->ll_pp_extent_lock);
1494 LPROC_SEQ_FOPS(ll_rw_extents_stats);
1496 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
1497 struct ll_file_data *file, loff_t pos,
1498 size_t count, int rw)
1501 struct ll_rw_process_info *process;
1502 struct ll_rw_process_info *offset;
1503 int *off_count = &sbi->ll_rw_offset_entry_count;
1504 int *process_count = &sbi->ll_offset_process_count;
1505 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1507 if(!sbi->ll_rw_stats_on)
1509 process = sbi->ll_rw_process_info;
1510 offset = sbi->ll_rw_offset_info;
1512 spin_lock(&sbi->ll_pp_extent_lock);
1513 /* Extent statistics */
1514 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1515 if(io_extents->pp_extents[i].pid == pid) {
1523 sbi->ll_extent_process_count =
1524 (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1525 cur = sbi->ll_extent_process_count;
1526 io_extents->pp_extents[cur].pid = pid;
1527 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1528 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1531 for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
1532 (i < (LL_HIST_MAX - 1)); i++);
1534 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1535 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1537 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1538 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1540 spin_unlock(&sbi->ll_pp_extent_lock);
1542 spin_lock(&sbi->ll_process_lock);
1543 /* Offset statistics */
1544 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1545 if (process[i].rw_pid == pid) {
1546 if (process[i].rw_last_file != file) {
1547 process[i].rw_range_start = pos;
1548 process[i].rw_last_file_pos = pos + count;
1549 process[i].rw_smallest_extent = count;
1550 process[i].rw_largest_extent = count;
1551 process[i].rw_offset = 0;
1552 process[i].rw_last_file = file;
1553 spin_unlock(&sbi->ll_process_lock);
1556 if (process[i].rw_last_file_pos != pos) {
1558 (*off_count + 1) % LL_OFFSET_HIST_MAX;
1559 offset[*off_count].rw_op = process[i].rw_op;
1560 offset[*off_count].rw_pid = pid;
1561 offset[*off_count].rw_range_start =
1562 process[i].rw_range_start;
1563 offset[*off_count].rw_range_end =
1564 process[i].rw_last_file_pos;
1565 offset[*off_count].rw_smallest_extent =
1566 process[i].rw_smallest_extent;
1567 offset[*off_count].rw_largest_extent =
1568 process[i].rw_largest_extent;
1569 offset[*off_count].rw_offset =
1570 process[i].rw_offset;
1571 process[i].rw_op = rw;
1572 process[i].rw_range_start = pos;
1573 process[i].rw_smallest_extent = count;
1574 process[i].rw_largest_extent = count;
1575 process[i].rw_offset = pos -
1576 process[i].rw_last_file_pos;
1578 if(process[i].rw_smallest_extent > count)
1579 process[i].rw_smallest_extent = count;
1580 if(process[i].rw_largest_extent < count)
1581 process[i].rw_largest_extent = count;
1582 process[i].rw_last_file_pos = pos + count;
1583 spin_unlock(&sbi->ll_process_lock);
1587 *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
1588 process[*process_count].rw_pid = pid;
1589 process[*process_count].rw_op = rw;
1590 process[*process_count].rw_range_start = pos;
1591 process[*process_count].rw_last_file_pos = pos + count;
1592 process[*process_count].rw_smallest_extent = count;
1593 process[*process_count].rw_largest_extent = count;
1594 process[*process_count].rw_offset = 0;
1595 process[*process_count].rw_last_file = file;
1596 spin_unlock(&sbi->ll_process_lock);
1599 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1601 struct timespec64 now;
1602 struct ll_sb_info *sbi = seq->private;
1603 struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
1604 struct ll_rw_process_info *process = sbi->ll_rw_process_info;
1607 ktime_get_real_ts64(&now);
1609 if (!sbi->ll_rw_stats_on) {
1610 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
1613 spin_lock(&sbi->ll_process_lock);
1615 seq_printf(seq, "snapshot_time: %llu.%09lu (secs.nsecs)\n",
1616 (s64)now.tv_sec, now.tv_nsec);
1617 seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
1618 "R/W", "PID", "RANGE START", "RANGE END",
1619 "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
1621 /* We stored the discontiguous offsets here; print them first */
1622 for (i = 0; i < LL_OFFSET_HIST_MAX; i++) {
1623 if (offset[i].rw_pid != 0)
1625 "%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1626 offset[i].rw_op == READ ? 'R' : 'W',
1628 offset[i].rw_range_start,
1629 offset[i].rw_range_end,
1630 (unsigned long)offset[i].rw_smallest_extent,
1631 (unsigned long)offset[i].rw_largest_extent,
1632 offset[i].rw_offset);
1635 /* Then print the current offsets for each process */
1636 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1637 if (process[i].rw_pid != 0)
1639 "%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1640 process[i].rw_op == READ ? 'R' : 'W',
1642 process[i].rw_range_start,
1643 process[i].rw_last_file_pos,
1644 (unsigned long)process[i].rw_smallest_extent,
1645 (unsigned long)process[i].rw_largest_extent,
1646 process[i].rw_offset);
1648 spin_unlock(&sbi->ll_process_lock);
1653 static ssize_t ll_rw_offset_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_process_info *process_info = sbi->ll_rw_process_info;
1660 struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_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_process_lock);
1674 sbi->ll_offset_process_count = 0;
1675 sbi->ll_rw_offset_entry_count = 0;
1676 memset(process_info, 0, sizeof(struct ll_rw_process_info) *
1677 LL_PROCESS_HIST_MAX);
1678 memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
1679 LL_OFFSET_HIST_MAX);
1680 spin_unlock(&sbi->ll_process_lock);
1686 * ll_stats_pid_write() - Determine if stats collection should be enabled
1687 * @buf: Buffer containing the data written
1688 * @len: Number of bytes in the buffer
1690 * Several proc files begin collecting stats when a value is written, and stop
1691 * collecting when either '0' or 'disable' is written. This function checks the
1692 * written value to see if collection should be enabled or disabled.
1694 * Return: If '0' or 'disable' is provided, 0 is returned. If the text
1695 * equivalent of a number is written, that number is returned. Otherwise,
1696 * 1 is returned. Non-zero return values indicate collection should be enabled.
1698 static __s64 ll_stats_pid_write(const char __user *buf, size_t len)
1704 rc = lprocfs_str_to_s64(buf, len, &value);
1706 if (rc < 0 && len < sizeof(kernbuf)) {
1708 if (copy_from_user(kernbuf, buf, len))
1712 if (kernbuf[len - 1] == '\n')
1713 kernbuf[len - 1] = 0;
1715 if (strncasecmp(kernbuf, "disable", 7) == 0)
1722 LPROC_SEQ_FOPS(ll_rw_offset_stats);
1723 #endif /* CONFIG_PROC_FS */