]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - drivers/staging/lustre/lustre/llite/lproc_llite.c
staging: add Lustre file system client support
[mirror_ubuntu-hirsute-kernel.git] / drivers / staging / lustre / lustre / llite / lproc_llite.c
CommitLineData
d7e09d03
PT
1/*
2 * GPL HEADER START
3 *
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
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.
9 *
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).
15 *
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.sun.com/software/products/lustre/docs/GPLv2.pdf
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 *
24 * GPL HEADER END
25 */
26/*
27 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
29 *
30 * Copyright (c) 2011, 2012, Intel Corporation.
31 */
32/*
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
35 */
36#define DEBUG_SUBSYSTEM S_LLITE
37
38#include <linux/version.h>
39#include <lustre_lite.h>
40#include <lprocfs_status.h>
41#include <linux/seq_file.h>
42#include <obd_support.h>
43
44#include "llite_internal.h"
45
46struct proc_dir_entry *proc_lustre_fs_root;
47
48#ifdef LPROCFS
49/* /proc/lustre/llite mount point registration */
50extern struct file_operations vvp_dump_pgcache_file_ops;
51struct file_operations ll_rw_extents_stats_fops;
52struct file_operations ll_rw_extents_stats_pp_fops;
53struct file_operations ll_rw_offset_stats_fops;
54
55static int ll_rd_blksize(char *page, char **start, off_t off, int count,
56 int *eof, void *data)
57{
58 struct super_block *sb = (struct super_block *)data;
59 struct obd_statfs osfs;
60 int rc;
61
62 LASSERT(sb != NULL);
63 rc = ll_statfs_internal(sb, &osfs,
64 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
65 OBD_STATFS_NODELAY);
66 if (!rc) {
67 *eof = 1;
68 rc = snprintf(page, count, "%u\n", osfs.os_bsize);
69 }
70
71 return rc;
72}
73
74static int ll_rd_kbytestotal(char *page, char **start, off_t off, int count,
75 int *eof, void *data)
76{
77 struct super_block *sb = (struct super_block *)data;
78 struct obd_statfs osfs;
79 int rc;
80
81 LASSERT(sb != NULL);
82 rc = ll_statfs_internal(sb, &osfs,
83 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
84 OBD_STATFS_NODELAY);
85 if (!rc) {
86 __u32 blk_size = osfs.os_bsize >> 10;
87 __u64 result = osfs.os_blocks;
88
89 while (blk_size >>= 1)
90 result <<= 1;
91
92 *eof = 1;
93 rc = snprintf(page, count, LPU64"\n", result);
94 }
95 return rc;
96
97}
98
99static int ll_rd_kbytesfree(char *page, char **start, off_t off, int count,
100 int *eof, void *data)
101{
102 struct super_block *sb = (struct super_block *)data;
103 struct obd_statfs osfs;
104 int rc;
105
106 LASSERT(sb != NULL);
107 rc = ll_statfs_internal(sb, &osfs,
108 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
109 OBD_STATFS_NODELAY);
110 if (!rc) {
111 __u32 blk_size = osfs.os_bsize >> 10;
112 __u64 result = osfs.os_bfree;
113
114 while (blk_size >>= 1)
115 result <<= 1;
116
117 *eof = 1;
118 rc = snprintf(page, count, LPU64"\n", result);
119 }
120 return rc;
121}
122
123static int ll_rd_kbytesavail(char *page, char **start, off_t off, int count,
124 int *eof, void *data)
125{
126 struct super_block *sb = (struct super_block *)data;
127 struct obd_statfs osfs;
128 int rc;
129
130 LASSERT(sb != NULL);
131 rc = ll_statfs_internal(sb, &osfs,
132 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
133 OBD_STATFS_NODELAY);
134 if (!rc) {
135 __u32 blk_size = osfs.os_bsize >> 10;
136 __u64 result = osfs.os_bavail;
137
138 while (blk_size >>= 1)
139 result <<= 1;
140
141 *eof = 1;
142 rc = snprintf(page, count, LPU64"\n", result);
143 }
144 return rc;
145}
146
147static int ll_rd_filestotal(char *page, char **start, off_t off, int count,
148 int *eof, void *data)
149{
150 struct super_block *sb = (struct super_block *)data;
151 struct obd_statfs osfs;
152 int rc;
153
154 LASSERT(sb != NULL);
155 rc = ll_statfs_internal(sb, &osfs,
156 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
157 OBD_STATFS_NODELAY);
158 if (!rc) {
159 *eof = 1;
160 rc = snprintf(page, count, LPU64"\n", osfs.os_files);
161 }
162 return rc;
163}
164
165static int ll_rd_filesfree(char *page, char **start, off_t off, int count,
166 int *eof, void *data)
167{
168 struct super_block *sb = (struct super_block *)data;
169 struct obd_statfs osfs;
170 int rc;
171
172 LASSERT(sb != NULL);
173 rc = ll_statfs_internal(sb, &osfs,
174 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
175 OBD_STATFS_NODELAY);
176 if (!rc) {
177 *eof = 1;
178 rc = snprintf(page, count, LPU64"\n", osfs.os_ffree);
179 }
180 return rc;
181
182}
183
184static int ll_rd_client_type(char *page, char **start, off_t off, int count,
185 int *eof, void *data)
186{
187 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)data);
188 int rc;
189
190 LASSERT(sbi != NULL);
191
192 *eof = 1;
193 if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
194 rc = snprintf(page, count, "remote client\n");
195 else
196 rc = snprintf(page, count, "local client\n");
197
198 return rc;
199}
200
201static int ll_rd_fstype(char *page, char **start, off_t off, int count,
202 int *eof, void *data)
203{
204 struct super_block *sb = (struct super_block*)data;
205
206 LASSERT(sb != NULL);
207 *eof = 1;
208 return snprintf(page, count, "%s\n", sb->s_type->name);
209}
210
211static int ll_rd_sb_uuid(char *page, char **start, off_t off, int count,
212 int *eof, void *data)
213{
214 struct super_block *sb = (struct super_block *)data;
215
216 LASSERT(sb != NULL);
217 *eof = 1;
218 return snprintf(page, count, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
219}
220
221static int ll_rd_site_stats(char *page, char **start, off_t off,
222 int count, int *eof, void *data)
223{
224 struct super_block *sb = data;
225
226 /*
227 * See description of statistical counters in struct cl_site, and
228 * struct lu_site.
229 */
230 return cl_site_stats_print(lu2cl_site(ll_s2sbi(sb)->ll_site),
231 page, count);
232}
233
234static int ll_rd_max_readahead_mb(char *page, char **start, off_t off,
235 int count, int *eof, void *data)
236{
237 struct super_block *sb = data;
238 struct ll_sb_info *sbi = ll_s2sbi(sb);
239 long pages_number;
240 int mult;
241
242 spin_lock(&sbi->ll_lock);
243 pages_number = sbi->ll_ra_info.ra_max_pages;
244 spin_unlock(&sbi->ll_lock);
245
246 mult = 1 << (20 - PAGE_CACHE_SHIFT);
247 return lprocfs_read_frac_helper(page, count, pages_number, mult);
248}
249
250static int ll_wr_max_readahead_mb(struct file *file, const char *buffer,
251 unsigned long count, void *data)
252{
253 struct super_block *sb = data;
254 struct ll_sb_info *sbi = ll_s2sbi(sb);
255 int mult, rc, pages_number;
256
257 mult = 1 << (20 - PAGE_CACHE_SHIFT);
258 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
259 if (rc)
260 return rc;
261
262 if (pages_number < 0 || pages_number > num_physpages / 2) {
263 CERROR("can't set file readahead more than %lu MB\n",
264 num_physpages >> (20 - PAGE_CACHE_SHIFT + 1)); /*1/2 of RAM*/
265 return -ERANGE;
266 }
267
268 spin_lock(&sbi->ll_lock);
269 sbi->ll_ra_info.ra_max_pages = pages_number;
270 spin_unlock(&sbi->ll_lock);
271
272 return count;
273}
274
275static int ll_rd_max_readahead_per_file_mb(char *page, char **start, off_t off,
276 int count, int *eof, void *data)
277{
278 struct super_block *sb = data;
279 struct ll_sb_info *sbi = ll_s2sbi(sb);
280 long pages_number;
281 int mult;
282
283 spin_lock(&sbi->ll_lock);
284 pages_number = sbi->ll_ra_info.ra_max_pages_per_file;
285 spin_unlock(&sbi->ll_lock);
286
287 mult = 1 << (20 - PAGE_CACHE_SHIFT);
288 return lprocfs_read_frac_helper(page, count, pages_number, mult);
289}
290
291static int ll_wr_max_readahead_per_file_mb(struct file *file, const char *buffer,
292 unsigned long count, void *data)
293{
294 struct super_block *sb = data;
295 struct ll_sb_info *sbi = ll_s2sbi(sb);
296 int mult, rc, pages_number;
297
298 mult = 1 << (20 - PAGE_CACHE_SHIFT);
299 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
300 if (rc)
301 return rc;
302
303 if (pages_number < 0 ||
304 pages_number > sbi->ll_ra_info.ra_max_pages) {
305 CERROR("can't set file readahead more than"
306 "max_read_ahead_mb %lu MB\n",
307 sbi->ll_ra_info.ra_max_pages);
308 return -ERANGE;
309 }
310
311 spin_lock(&sbi->ll_lock);
312 sbi->ll_ra_info.ra_max_pages_per_file = pages_number;
313 spin_unlock(&sbi->ll_lock);
314
315 return count;
316}
317
318static int ll_rd_max_read_ahead_whole_mb(char *page, char **start, off_t off,
319 int count, int *eof, void *data)
320{
321 struct super_block *sb = data;
322 struct ll_sb_info *sbi = ll_s2sbi(sb);
323 long pages_number;
324 int mult;
325
326 spin_lock(&sbi->ll_lock);
327 pages_number = sbi->ll_ra_info.ra_max_read_ahead_whole_pages;
328 spin_unlock(&sbi->ll_lock);
329
330 mult = 1 << (20 - PAGE_CACHE_SHIFT);
331 return lprocfs_read_frac_helper(page, count, pages_number, mult);
332}
333
334static int ll_wr_max_read_ahead_whole_mb(struct file *file, const char *buffer,
335 unsigned long count, void *data)
336{
337 struct super_block *sb = data;
338 struct ll_sb_info *sbi = ll_s2sbi(sb);
339 int mult, rc, pages_number;
340
341 mult = 1 << (20 - PAGE_CACHE_SHIFT);
342 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
343 if (rc)
344 return rc;
345
346 /* Cap this at the current max readahead window size, the readahead
347 * algorithm does this anyway so it's pointless to set it larger. */
348 if (pages_number < 0 ||
349 pages_number > sbi->ll_ra_info.ra_max_pages_per_file) {
350 CERROR("can't set max_read_ahead_whole_mb more than "
351 "max_read_ahead_per_file_mb: %lu\n",
352 sbi->ll_ra_info.ra_max_pages_per_file >> (20 - PAGE_CACHE_SHIFT));
353 return -ERANGE;
354 }
355
356 spin_lock(&sbi->ll_lock);
357 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = pages_number;
358 spin_unlock(&sbi->ll_lock);
359
360 return count;
361}
362
363static int ll_rd_max_cached_mb(char *page, char **start, off_t off,
364 int count, int *eof, void *data)
365{
366 struct super_block *sb = data;
367 struct ll_sb_info *sbi = ll_s2sbi(sb);
368 struct cl_client_cache *cache = &sbi->ll_cache;
369 int shift = 20 - PAGE_CACHE_SHIFT;
370 int max_cached_mb;
371 int unused_mb;
372
373 *eof = 1;
374 max_cached_mb = cache->ccc_lru_max >> shift;
375 unused_mb = atomic_read(&cache->ccc_lru_left) >> shift;
376 return snprintf(page, count,
377 "users: %d\n"
378 "max_cached_mb: %d\n"
379 "used_mb: %d\n"
380 "unused_mb: %d\n"
381 "reclaim_count: %u\n",
382 atomic_read(&cache->ccc_users),
383 max_cached_mb,
384 max_cached_mb - unused_mb,
385 unused_mb,
386 cache->ccc_lru_shrinkers);
387}
388
389static int ll_wr_max_cached_mb(struct file *file, const char *buffer,
390 unsigned long count, void *data)
391{
392 struct super_block *sb = data;
393 struct ll_sb_info *sbi = ll_s2sbi(sb);
394 struct cl_client_cache *cache = &sbi->ll_cache;
395 int mult, rc, pages_number;
396 int diff = 0;
397 int nrpages = 0;
398 ENTRY;
399
400 mult = 1 << (20 - PAGE_CACHE_SHIFT);
401 buffer = lprocfs_find_named_value(buffer, "max_cached_mb:", &count);
402 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
403 if (rc)
404 RETURN(rc);
405
406 if (pages_number < 0 || pages_number > num_physpages) {
407 CERROR("%s: can't set max cache more than %lu MB\n",
408 ll_get_fsname(sb, NULL, 0),
409 num_physpages >> (20 - PAGE_CACHE_SHIFT));
410 RETURN(-ERANGE);
411 }
412
413 if (sbi->ll_dt_exp == NULL)
414 RETURN(-ENODEV);
415
416 spin_lock(&sbi->ll_lock);
417 diff = pages_number - cache->ccc_lru_max;
418 spin_unlock(&sbi->ll_lock);
419
420 /* easy - add more LRU slots. */
421 if (diff >= 0) {
422 atomic_add(diff, &cache->ccc_lru_left);
423 GOTO(out, rc = 0);
424 }
425
426 diff = -diff;
427 while (diff > 0) {
428 int tmp;
429
430 /* reduce LRU budget from free slots. */
431 do {
432 int ov, nv;
433
434 ov = atomic_read(&cache->ccc_lru_left);
435 if (ov == 0)
436 break;
437
438 nv = ov > diff ? ov - diff : 0;
439 rc = cfs_atomic_cmpxchg(&cache->ccc_lru_left, ov, nv);
440 if (likely(ov == rc)) {
441 diff -= ov - nv;
442 nrpages += ov - nv;
443 break;
444 }
445 } while (1);
446
447 if (diff <= 0)
448 break;
449
450 /* difficult - have to ask OSCs to drop LRU slots. */
451 tmp = diff << 1;
452 rc = obd_set_info_async(NULL, sbi->ll_dt_exp,
453 sizeof(KEY_CACHE_LRU_SHRINK),
454 KEY_CACHE_LRU_SHRINK,
455 sizeof(tmp), &tmp, NULL);
456 if (rc < 0)
457 break;
458 }
459
460out:
461 if (rc >= 0) {
462 spin_lock(&sbi->ll_lock);
463 cache->ccc_lru_max = pages_number;
464 spin_unlock(&sbi->ll_lock);
465 rc = count;
466 } else {
467 atomic_add(nrpages, &cache->ccc_lru_left);
468 }
469 return rc;
470}
471
472static int ll_rd_checksum(char *page, char **start, off_t off,
473 int count, int *eof, void *data)
474{
475 struct super_block *sb = data;
476 struct ll_sb_info *sbi = ll_s2sbi(sb);
477
478 return snprintf(page, count, "%u\n",
479 (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0);
480}
481
482static int ll_wr_checksum(struct file *file, const char *buffer,
483 unsigned long count, void *data)
484{
485 struct super_block *sb = data;
486 struct ll_sb_info *sbi = ll_s2sbi(sb);
487 int val, rc;
488
489 if (!sbi->ll_dt_exp)
490 /* Not set up yet */
491 return -EAGAIN;
492
493 rc = lprocfs_write_helper(buffer, count, &val);
494 if (rc)
495 return rc;
496 if (val)
497 sbi->ll_flags |= LL_SBI_CHECKSUM;
498 else
499 sbi->ll_flags &= ~LL_SBI_CHECKSUM;
500
501 rc = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
502 KEY_CHECKSUM, sizeof(val), &val, NULL);
503 if (rc)
504 CWARN("Failed to set OSC checksum flags: %d\n", rc);
505
506 return count;
507}
508
509static int ll_rd_max_rw_chunk(char *page, char **start, off_t off,
510 int count, int *eof, void *data)
511{
512 struct super_block *sb = data;
513
514 return snprintf(page, count, "%lu\n", ll_s2sbi(sb)->ll_max_rw_chunk);
515}
516
517static int ll_wr_max_rw_chunk(struct file *file, const char *buffer,
518 unsigned long count, void *data)
519{
520 struct super_block *sb = data;
521 int rc, val;
522
523 rc = lprocfs_write_helper(buffer, count, &val);
524 if (rc)
525 return rc;
526 ll_s2sbi(sb)->ll_max_rw_chunk = val;
527 return count;
528}
529
530static int ll_rd_track_id(char *page, int count, void *data,
531 enum stats_track_type type)
532{
533 struct super_block *sb = data;
534
535 if (ll_s2sbi(sb)->ll_stats_track_type == type) {
536 return snprintf(page, count, "%d\n",
537 ll_s2sbi(sb)->ll_stats_track_id);
538
539 } else if (ll_s2sbi(sb)->ll_stats_track_type == STATS_TRACK_ALL) {
540 return snprintf(page, count, "0 (all)\n");
541 } else {
542 return snprintf(page, count, "untracked\n");
543 }
544}
545
546static int ll_wr_track_id(const char *buffer, unsigned long count, void *data,
547 enum stats_track_type type)
548{
549 struct super_block *sb = data;
550 int rc, pid;
551
552 rc = lprocfs_write_helper(buffer, count, &pid);
553 if (rc)
554 return rc;
555 ll_s2sbi(sb)->ll_stats_track_id = pid;
556 if (pid == 0)
557 ll_s2sbi(sb)->ll_stats_track_type = STATS_TRACK_ALL;
558 else
559 ll_s2sbi(sb)->ll_stats_track_type = type;
560 lprocfs_clear_stats(ll_s2sbi(sb)->ll_stats);
561 return count;
562}
563
564static int ll_rd_track_pid(char *page, char **start, off_t off,
565 int count, int *eof, void *data)
566{
567 return (ll_rd_track_id(page, count, data, STATS_TRACK_PID));
568}
569
570static int ll_wr_track_pid(struct file *file, const char *buffer,
571 unsigned long count, void *data)
572{
573 return (ll_wr_track_id(buffer, count, data, STATS_TRACK_PID));
574}
575
576static int ll_rd_track_ppid(char *page, char **start, off_t off,
577 int count, int *eof, void *data)
578{
579 return (ll_rd_track_id(page, count, data, STATS_TRACK_PPID));
580}
581
582static int ll_wr_track_ppid(struct file *file, const char *buffer,
583 unsigned long count, void *data)
584{
585 return (ll_wr_track_id(buffer, count, data, STATS_TRACK_PPID));
586}
587
588static int ll_rd_track_gid(char *page, char **start, off_t off,
589 int count, int *eof, void *data)
590{
591 return (ll_rd_track_id(page, count, data, STATS_TRACK_GID));
592}
593
594static int ll_wr_track_gid(struct file *file, const char *buffer,
595 unsigned long count, void *data)
596{
597 return (ll_wr_track_id(buffer, count, data, STATS_TRACK_GID));
598}
599
600static int ll_rd_statahead_max(char *page, char **start, off_t off,
601 int count, int *eof, void *data)
602{
603 struct super_block *sb = data;
604 struct ll_sb_info *sbi = ll_s2sbi(sb);
605
606 return snprintf(page, count, "%u\n", sbi->ll_sa_max);
607}
608
609static int ll_wr_statahead_max(struct file *file, const char *buffer,
610 unsigned long count, void *data)
611{
612 struct super_block *sb = data;
613 struct ll_sb_info *sbi = ll_s2sbi(sb);
614 int val, rc;
615
616 rc = lprocfs_write_helper(buffer, count, &val);
617 if (rc)
618 return rc;
619
620 if (val >= 0 && val <= LL_SA_RPC_MAX)
621 sbi->ll_sa_max = val;
622 else
623 CERROR("Bad statahead_max value %d. Valid values are in the "
624 "range [0, %d]\n", val, LL_SA_RPC_MAX);
625
626 return count;
627}
628
629static int ll_rd_statahead_agl(char *page, char **start, off_t off,
630 int count, int *eof, void *data)
631{
632 struct super_block *sb = data;
633 struct ll_sb_info *sbi = ll_s2sbi(sb);
634
635 return snprintf(page, count, "%u\n",
636 sbi->ll_flags & LL_SBI_AGL_ENABLED ? 1 : 0);
637}
638
639static int ll_wr_statahead_agl(struct file *file, const char *buffer,
640 unsigned long count, void *data)
641{
642 struct super_block *sb = data;
643 struct ll_sb_info *sbi = ll_s2sbi(sb);
644 int val, rc;
645
646 rc = lprocfs_write_helper(buffer, count, &val);
647 if (rc)
648 return rc;
649
650 if (val)
651 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
652 else
653 sbi->ll_flags &= ~LL_SBI_AGL_ENABLED;
654
655 return count;
656}
657
658static int ll_rd_statahead_stats(char *page, char **start, off_t off,
659 int count, int *eof, void *data)
660{
661 struct super_block *sb = data;
662 struct ll_sb_info *sbi = ll_s2sbi(sb);
663
664 return snprintf(page, count,
665 "statahead total: %u\n"
666 "statahead wrong: %u\n"
667 "agl total: %u\n",
668 atomic_read(&sbi->ll_sa_total),
669 atomic_read(&sbi->ll_sa_wrong),
670 atomic_read(&sbi->ll_agl_total));
671}
672
673static int ll_rd_lazystatfs(char *page, char **start, off_t off,
674 int count, int *eof, void *data)
675{
676 struct super_block *sb = data;
677 struct ll_sb_info *sbi = ll_s2sbi(sb);
678
679 return snprintf(page, count, "%u\n",
680 (sbi->ll_flags & LL_SBI_LAZYSTATFS) ? 1 : 0);
681}
682
683static int ll_wr_lazystatfs(struct file *file, const char *buffer,
684 unsigned long count, void *data)
685{
686 struct super_block *sb = data;
687 struct ll_sb_info *sbi = ll_s2sbi(sb);
688 int val, rc;
689
690 rc = lprocfs_write_helper(buffer, count, &val);
691 if (rc)
692 return rc;
693
694 if (val)
695 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
696 else
697 sbi->ll_flags &= ~LL_SBI_LAZYSTATFS;
698
699 return count;
700}
701
702static int ll_rd_maxea_size(char *page, char **start, off_t off,
703 int count, int *eof, void *data)
704{
705 struct super_block *sb = data;
706 struct ll_sb_info *sbi = ll_s2sbi(sb);
707 unsigned int ealen;
708 int rc;
709
710 rc = ll_get_max_mdsize(sbi, &ealen);
711 if (rc)
712 return rc;
713
714 return snprintf(page, count, "%u\n", ealen);
715}
716
717static int ll_rd_sbi_flags(char *page, char **start, off_t off,
718 int count, int *eof, void *data)
719{
720 const char *str[] = LL_SBI_FLAGS;
721 struct super_block *sb = data;
722 int flags = ll_s2sbi(sb)->ll_flags;
723 int i = 0;
724 int rc = 0;
725
726 while (flags != 0) {
727 if (ARRAY_SIZE(str) <= i) {
728 CERROR("%s: Revise array LL_SBI_FLAGS to match sbi "
729 "flags please.\n", ll_get_fsname(sb, NULL, 0));
730 return -EINVAL;
731 }
732
733 if (flags & 0x1)
734 rc += snprintf(page + rc, count - rc, "%s ", str[i]);
735 flags >>= 1;
736 ++i;
737 }
738 if (rc > 0)
739 rc += snprintf(page + rc, count - rc, "\b\n");
740 return rc;
741}
742
743static int ll_rd_unstable_stats(char *page, char **start, off_t off,
744 int count, int *eof, void *data)
745{
746 struct super_block *sb = data;
747 struct ll_sb_info *sbi = ll_s2sbi(sb);
748 struct cl_client_cache *cache = &sbi->ll_cache;
749 int pages, mb, rc;
750
751 pages = atomic_read(&cache->ccc_unstable_nr);
752 mb = (pages * PAGE_CACHE_SIZE) >> 20;
753
754 rc = snprintf(page, count, "unstable_pages: %8d\n"
755 "unstable_mb: %8d\n", pages, mb);
756
757 return rc;
758}
759
760static struct lprocfs_vars lprocfs_llite_obd_vars[] = {
761 { "uuid", ll_rd_sb_uuid, 0, 0 },
762 //{ "mntpt_path", ll_rd_path, 0, 0 },
763 { "fstype", ll_rd_fstype, 0, 0 },
764 { "site", ll_rd_site_stats, 0, 0 },
765 { "blocksize", ll_rd_blksize, 0, 0 },
766 { "kbytestotal", ll_rd_kbytestotal, 0, 0 },
767 { "kbytesfree", ll_rd_kbytesfree, 0, 0 },
768 { "kbytesavail", ll_rd_kbytesavail, 0, 0 },
769 { "filestotal", ll_rd_filestotal, 0, 0 },
770 { "filesfree", ll_rd_filesfree, 0, 0 },
771 { "client_type", ll_rd_client_type, 0, 0 },
772 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 },
773 { "max_read_ahead_mb", ll_rd_max_readahead_mb,
774 ll_wr_max_readahead_mb, 0 },
775 { "max_read_ahead_per_file_mb", ll_rd_max_readahead_per_file_mb,
776 ll_wr_max_readahead_per_file_mb, 0 },
777 { "max_read_ahead_whole_mb", ll_rd_max_read_ahead_whole_mb,
778 ll_wr_max_read_ahead_whole_mb, 0 },
779 { "max_cached_mb", ll_rd_max_cached_mb, ll_wr_max_cached_mb, 0 },
780 { "checksum_pages", ll_rd_checksum, ll_wr_checksum, 0 },
781 { "max_rw_chunk", ll_rd_max_rw_chunk, ll_wr_max_rw_chunk, 0 },
782 { "stats_track_pid", ll_rd_track_pid, ll_wr_track_pid, 0 },
783 { "stats_track_ppid", ll_rd_track_ppid, ll_wr_track_ppid, 0 },
784 { "stats_track_gid", ll_rd_track_gid, ll_wr_track_gid, 0 },
785 { "statahead_max", ll_rd_statahead_max, ll_wr_statahead_max, 0 },
786 { "statahead_agl", ll_rd_statahead_agl, ll_wr_statahead_agl, 0 },
787 { "statahead_stats", ll_rd_statahead_stats, 0, 0 },
788 { "lazystatfs", ll_rd_lazystatfs, ll_wr_lazystatfs, 0 },
789 { "max_easize", ll_rd_maxea_size, 0, 0 },
790 { "sbi_flags", ll_rd_sbi_flags, 0, 0 },
791 { "unstable_stats", ll_rd_unstable_stats, 0, 0},
792 { 0 }
793};
794
795#define MAX_STRING_SIZE 128
796
797struct llite_file_opcode {
798 __u32 opcode;
799 __u32 type;
800 const char *opname;
801} llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
802 /* file operation */
803 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
804 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
805 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
806 "read_bytes" },
807 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
808 "write_bytes" },
809 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
810 "brw_read" },
811 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
812 "brw_write" },
813 { LPROC_LL_OSC_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
814 "osc_read" },
815 { LPROC_LL_OSC_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
816 "osc_write" },
817 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
818 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
819 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
820 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
821 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
822 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
823 { LPROC_LL_READDIR, LPROCFS_TYPE_REGS, "readdir" },
824 /* inode operation */
825 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
826 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "truncate" },
827 { LPROC_LL_FLOCK, LPROCFS_TYPE_REGS, "flock" },
828 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
829 /* dir inode operation */
830 { LPROC_LL_CREATE, LPROCFS_TYPE_REGS, "create" },
831 { LPROC_LL_LINK, LPROCFS_TYPE_REGS, "link" },
832 { LPROC_LL_UNLINK, LPROCFS_TYPE_REGS, "unlink" },
833 { LPROC_LL_SYMLINK, LPROCFS_TYPE_REGS, "symlink" },
834 { LPROC_LL_MKDIR, LPROCFS_TYPE_REGS, "mkdir" },
835 { LPROC_LL_RMDIR, LPROCFS_TYPE_REGS, "rmdir" },
836 { LPROC_LL_MKNOD, LPROCFS_TYPE_REGS, "mknod" },
837 { LPROC_LL_RENAME, LPROCFS_TYPE_REGS, "rename" },
838 /* special inode operation */
839 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
840 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
841 { LPROC_LL_SETXATTR, LPROCFS_TYPE_REGS, "setxattr" },
842 { LPROC_LL_GETXATTR, LPROCFS_TYPE_REGS, "getxattr" },
843 { LPROC_LL_LISTXATTR, LPROCFS_TYPE_REGS, "listxattr" },
844 { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_REGS, "removexattr" },
845 { LPROC_LL_INODE_PERM, LPROCFS_TYPE_REGS, "inode_permission" },
846};
847
848void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
849{
850 if (!sbi->ll_stats)
851 return;
852 if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
853 lprocfs_counter_add(sbi->ll_stats, op, count);
854 else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
855 sbi->ll_stats_track_id == current->pid)
856 lprocfs_counter_add(sbi->ll_stats, op, count);
857 else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
858 sbi->ll_stats_track_id == current->parent->pid)
859 lprocfs_counter_add(sbi->ll_stats, op, count);
860 else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
861 sbi->ll_stats_track_id == current_gid())
862 lprocfs_counter_add(sbi->ll_stats, op, count);
863}
864EXPORT_SYMBOL(ll_stats_ops_tally);
865
866static const char *ra_stat_string[] = {
867 [RA_STAT_HIT] = "hits",
868 [RA_STAT_MISS] = "misses",
869 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
870 [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
871 [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page",
872 [RA_STAT_FAILED_MATCH] = "failed lock match",
873 [RA_STAT_DISCARDED] = "read but discarded",
874 [RA_STAT_ZERO_LEN] = "zero length file",
875 [RA_STAT_ZERO_WINDOW] = "zero size window",
876 [RA_STAT_EOF] = "read-ahead to EOF",
877 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
878 [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",
879};
880
881
882int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
883 struct super_block *sb, char *osc, char *mdc)
884{
885 struct lprocfs_vars lvars[2];
886 struct lustre_sb_info *lsi = s2lsi(sb);
887 struct ll_sb_info *sbi = ll_s2sbi(sb);
888 struct obd_device *obd;
889 char name[MAX_STRING_SIZE + 1], *ptr;
890 int err, id, len, rc;
891 ENTRY;
892
893 memset(lvars, 0, sizeof(lvars));
894
895 name[MAX_STRING_SIZE] = '\0';
896 lvars[0].name = name;
897
898 LASSERT(sbi != NULL);
899 LASSERT(mdc != NULL);
900 LASSERT(osc != NULL);
901
902 /* Get fsname */
903 len = strlen(lsi->lsi_lmd->lmd_profile);
904 ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
905 if (ptr && (strcmp(ptr, "-client") == 0))
906 len -= 7;
907
908 /* Mount info */
909 snprintf(name, MAX_STRING_SIZE, "%.*s-%p", len,
910 lsi->lsi_lmd->lmd_profile, sb);
911
912 sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
913 if (IS_ERR(sbi->ll_proc_root)) {
914 err = PTR_ERR(sbi->ll_proc_root);
915 sbi->ll_proc_root = NULL;
916 RETURN(err);
917 }
918
919 rc = lprocfs_seq_create(sbi->ll_proc_root, "dump_page_cache", 0444,
920 &vvp_dump_pgcache_file_ops, sbi);
921 if (rc)
922 CWARN("Error adding the dump_page_cache file\n");
923
924 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats", 0644,
925 &ll_rw_extents_stats_fops, sbi);
926 if (rc)
927 CWARN("Error adding the extent_stats file\n");
928
929 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats_per_process",
930 0644, &ll_rw_extents_stats_pp_fops, sbi);
931 if (rc)
932 CWARN("Error adding the extents_stats_per_process file\n");
933
934 rc = lprocfs_seq_create(sbi->ll_proc_root, "offset_stats", 0644,
935 &ll_rw_offset_stats_fops, sbi);
936 if (rc)
937 CWARN("Error adding the offset_stats file\n");
938
939 /* File operations stats */
940 sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
941 LPROCFS_STATS_FLAG_NONE);
942 if (sbi->ll_stats == NULL)
943 GOTO(out, err = -ENOMEM);
944 /* do counter init */
945 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
946 __u32 type = llite_opcode_table[id].type;
947 void *ptr = NULL;
948 if (type & LPROCFS_TYPE_REGS)
949 ptr = "regs";
950 else if (type & LPROCFS_TYPE_BYTES)
951 ptr = "bytes";
952 else if (type & LPROCFS_TYPE_PAGES)
953 ptr = "pages";
954 lprocfs_counter_init(sbi->ll_stats,
955 llite_opcode_table[id].opcode,
956 (type & LPROCFS_CNTR_AVGMINMAX),
957 llite_opcode_table[id].opname, ptr);
958 }
959 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats);
960 if (err)
961 GOTO(out, err);
962
963 sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
964 LPROCFS_STATS_FLAG_NONE);
965 if (sbi->ll_ra_stats == NULL)
966 GOTO(out, err = -ENOMEM);
967
968 for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
969 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
970 ra_stat_string[id], "pages");
971 err = lprocfs_register_stats(sbi->ll_proc_root, "read_ahead_stats",
972 sbi->ll_ra_stats);
973 if (err)
974 GOTO(out, err);
975
976
977 err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_llite_obd_vars, sb);
978 if (err)
979 GOTO(out, err);
980
981 /* MDC info */
982 obd = class_name2obd(mdc);
983
984 LASSERT(obd != NULL);
985 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
986 LASSERT(obd->obd_type->typ_name != NULL);
987
988 snprintf(name, MAX_STRING_SIZE, "%s/common_name",
989 obd->obd_type->typ_name);
990 lvars[0].read_fptr = lprocfs_rd_name;
991 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
992 if (err)
993 GOTO(out, err);
994
995 snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
996 lvars[0].read_fptr = lprocfs_rd_uuid;
997 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
998 if (err)
999 GOTO(out, err);
1000
1001 /* OSC */
1002 obd = class_name2obd(osc);
1003
1004 LASSERT(obd != NULL);
1005 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1006 LASSERT(obd->obd_type->typ_name != NULL);
1007
1008 snprintf(name, MAX_STRING_SIZE, "%s/common_name",
1009 obd->obd_type->typ_name);
1010 lvars[0].read_fptr = lprocfs_rd_name;
1011 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
1012 if (err)
1013 GOTO(out, err);
1014
1015 snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
1016 lvars[0].read_fptr = lprocfs_rd_uuid;
1017 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
1018out:
1019 if (err) {
1020 lprocfs_remove(&sbi->ll_proc_root);
1021 lprocfs_free_stats(&sbi->ll_ra_stats);
1022 lprocfs_free_stats(&sbi->ll_stats);
1023 }
1024 RETURN(err);
1025}
1026
1027void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
1028{
1029 if (sbi->ll_proc_root) {
1030 lprocfs_remove(&sbi->ll_proc_root);
1031 lprocfs_free_stats(&sbi->ll_ra_stats);
1032 lprocfs_free_stats(&sbi->ll_stats);
1033 }
1034}
1035#undef MAX_STRING_SIZE
1036
1037#define pct(a,b) (b ? a * 100 / b : 0)
1038
1039static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
1040 struct seq_file *seq, int which)
1041{
1042 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
1043 unsigned long start, end, r, w;
1044 char *unitp = "KMGTPEZY";
1045 int i, units = 10;
1046 struct per_process_info *pp_info = &io_extents->pp_extents[which];
1047
1048 read_cum = 0;
1049 write_cum = 0;
1050 start = 0;
1051
1052 for(i = 0; i < LL_HIST_MAX; i++) {
1053 read_tot += pp_info->pp_r_hist.oh_buckets[i];
1054 write_tot += pp_info->pp_w_hist.oh_buckets[i];
1055 }
1056
1057 for(i = 0; i < LL_HIST_MAX; i++) {
1058 r = pp_info->pp_r_hist.oh_buckets[i];
1059 w = pp_info->pp_w_hist.oh_buckets[i];
1060 read_cum += r;
1061 write_cum += w;
1062 end = 1 << (i + LL_HIST_START - units);
1063 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu | "
1064 "%14lu %4lu %4lu\n", start, *unitp, end, *unitp,
1065 (i == LL_HIST_MAX - 1) ? '+' : ' ',
1066 r, pct(r, read_tot), pct(read_cum, read_tot),
1067 w, pct(w, write_tot), pct(write_cum, write_tot));
1068 start = end;
1069 if (start == 1<<10) {
1070 start = 1;
1071 units += 10;
1072 unitp++;
1073 }
1074 if (read_cum == read_tot && write_cum == write_tot)
1075 break;
1076 }
1077}
1078
1079static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
1080{
1081 struct timeval now;
1082 struct ll_sb_info *sbi = seq->private;
1083 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1084 int k;
1085
1086 do_gettimeofday(&now);
1087
1088 if (!sbi->ll_rw_stats_on) {
1089 seq_printf(seq, "disabled\n"
1090 "write anything in this file to activate, "
1091 "then 0 or \"[D/d]isabled\" to deactivate\n");
1092 return 0;
1093 }
1094 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1095 now.tv_sec, now.tv_usec);
1096 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1097 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1098 "extents", "calls", "%", "cum%",
1099 "calls", "%", "cum%");
1100 spin_lock(&sbi->ll_pp_extent_lock);
1101 for (k = 0; k < LL_PROCESS_HIST_MAX; k++) {
1102 if (io_extents->pp_extents[k].pid != 0) {
1103 seq_printf(seq, "\nPID: %d\n",
1104 io_extents->pp_extents[k].pid);
1105 ll_display_extents_info(io_extents, seq, k);
1106 }
1107 }
1108 spin_unlock(&sbi->ll_pp_extent_lock);
1109 return 0;
1110}
1111
1112static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
1113 const char *buf, size_t len,
1114 loff_t *off)
1115{
1116 struct seq_file *seq = file->private_data;
1117 struct ll_sb_info *sbi = seq->private;
1118 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1119 int i;
1120 int value = 1, rc = 0;
1121
1122 rc = lprocfs_write_helper(buf, len, &value);
1123 if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
1124 strcmp(buf, "Disabled") == 0))
1125 value = 0;
1126
1127 if (value == 0)
1128 sbi->ll_rw_stats_on = 0;
1129 else
1130 sbi->ll_rw_stats_on = 1;
1131
1132 spin_lock(&sbi->ll_pp_extent_lock);
1133 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1134 io_extents->pp_extents[i].pid = 0;
1135 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1136 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1137 }
1138 spin_unlock(&sbi->ll_pp_extent_lock);
1139 return len;
1140}
1141
1142LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
1143
1144static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
1145{
1146 struct timeval now;
1147 struct ll_sb_info *sbi = seq->private;
1148 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1149
1150 do_gettimeofday(&now);
1151
1152 if (!sbi->ll_rw_stats_on) {
1153 seq_printf(seq, "disabled\n"
1154 "write anything in this file to activate, "
1155 "then 0 or \"[D/d]isabled\" to deactivate\n");
1156 return 0;
1157 }
1158 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1159 now.tv_sec, now.tv_usec);
1160
1161 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
1162 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
1163 "extents", "calls", "%", "cum%",
1164 "calls", "%", "cum%");
1165 spin_lock(&sbi->ll_lock);
1166 ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
1167 spin_unlock(&sbi->ll_lock);
1168
1169 return 0;
1170}
1171
1172static ssize_t ll_rw_extents_stats_seq_write(struct file *file, const char *buf,
1173 size_t len, loff_t *off)
1174{
1175 struct seq_file *seq = file->private_data;
1176 struct ll_sb_info *sbi = seq->private;
1177 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1178 int i;
1179 int value = 1, rc = 0;
1180
1181 rc = lprocfs_write_helper(buf, len, &value);
1182 if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
1183 strcmp(buf, "Disabled") == 0))
1184 value = 0;
1185
1186 if (value == 0)
1187 sbi->ll_rw_stats_on = 0;
1188 else
1189 sbi->ll_rw_stats_on = 1;
1190 spin_lock(&sbi->ll_pp_extent_lock);
1191 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
1192 io_extents->pp_extents[i].pid = 0;
1193 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1194 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1195 }
1196 spin_unlock(&sbi->ll_pp_extent_lock);
1197
1198 return len;
1199}
1200
1201LPROC_SEQ_FOPS(ll_rw_extents_stats);
1202
1203void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
1204 struct ll_file_data *file, loff_t pos,
1205 size_t count, int rw)
1206{
1207 int i, cur = -1;
1208 struct ll_rw_process_info *process;
1209 struct ll_rw_process_info *offset;
1210 int *off_count = &sbi->ll_rw_offset_entry_count;
1211 int *process_count = &sbi->ll_offset_process_count;
1212 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1213
1214 if(!sbi->ll_rw_stats_on)
1215 return;
1216 process = sbi->ll_rw_process_info;
1217 offset = sbi->ll_rw_offset_info;
1218
1219 spin_lock(&sbi->ll_pp_extent_lock);
1220 /* Extent statistics */
1221 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1222 if(io_extents->pp_extents[i].pid == pid) {
1223 cur = i;
1224 break;
1225 }
1226 }
1227
1228 if (cur == -1) {
1229 /* new process */
1230 sbi->ll_extent_process_count =
1231 (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1232 cur = sbi->ll_extent_process_count;
1233 io_extents->pp_extents[cur].pid = pid;
1234 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1235 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1236 }
1237
1238 for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
1239 (i < (LL_HIST_MAX - 1)); i++);
1240 if (rw == 0) {
1241 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1242 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1243 } else {
1244 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1245 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1246 }
1247 spin_unlock(&sbi->ll_pp_extent_lock);
1248
1249 spin_lock(&sbi->ll_process_lock);
1250 /* Offset statistics */
1251 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1252 if (process[i].rw_pid == pid) {
1253 if (process[i].rw_last_file != file) {
1254 process[i].rw_range_start = pos;
1255 process[i].rw_last_file_pos = pos + count;
1256 process[i].rw_smallest_extent = count;
1257 process[i].rw_largest_extent = count;
1258 process[i].rw_offset = 0;
1259 process[i].rw_last_file = file;
1260 spin_unlock(&sbi->ll_process_lock);
1261 return;
1262 }
1263 if (process[i].rw_last_file_pos != pos) {
1264 *off_count =
1265 (*off_count + 1) % LL_OFFSET_HIST_MAX;
1266 offset[*off_count].rw_op = process[i].rw_op;
1267 offset[*off_count].rw_pid = pid;
1268 offset[*off_count].rw_range_start =
1269 process[i].rw_range_start;
1270 offset[*off_count].rw_range_end =
1271 process[i].rw_last_file_pos;
1272 offset[*off_count].rw_smallest_extent =
1273 process[i].rw_smallest_extent;
1274 offset[*off_count].rw_largest_extent =
1275 process[i].rw_largest_extent;
1276 offset[*off_count].rw_offset =
1277 process[i].rw_offset;
1278 process[i].rw_op = rw;
1279 process[i].rw_range_start = pos;
1280 process[i].rw_smallest_extent = count;
1281 process[i].rw_largest_extent = count;
1282 process[i].rw_offset = pos -
1283 process[i].rw_last_file_pos;
1284 }
1285 if(process[i].rw_smallest_extent > count)
1286 process[i].rw_smallest_extent = count;
1287 if(process[i].rw_largest_extent < count)
1288 process[i].rw_largest_extent = count;
1289 process[i].rw_last_file_pos = pos + count;
1290 spin_unlock(&sbi->ll_process_lock);
1291 return;
1292 }
1293 }
1294 *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
1295 process[*process_count].rw_pid = pid;
1296 process[*process_count].rw_op = rw;
1297 process[*process_count].rw_range_start = pos;
1298 process[*process_count].rw_last_file_pos = pos + count;
1299 process[*process_count].rw_smallest_extent = count;
1300 process[*process_count].rw_largest_extent = count;
1301 process[*process_count].rw_offset = 0;
1302 process[*process_count].rw_last_file = file;
1303 spin_unlock(&sbi->ll_process_lock);
1304}
1305
1306static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1307{
1308 struct timeval now;
1309 struct ll_sb_info *sbi = seq->private;
1310 struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
1311 struct ll_rw_process_info *process = sbi->ll_rw_process_info;
1312 int i;
1313
1314 do_gettimeofday(&now);
1315
1316 if (!sbi->ll_rw_stats_on) {
1317 seq_printf(seq, "disabled\n"
1318 "write anything in this file to activate, "
1319 "then 0 or \"[D/d]isabled\" to deactivate\n");
1320 return 0;
1321 }
1322 spin_lock(&sbi->ll_process_lock);
1323
1324 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1325 now.tv_sec, now.tv_usec);
1326 seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
1327 "R/W", "PID", "RANGE START", "RANGE END",
1328 "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
1329 /* We stored the discontiguous offsets here; print them first */
1330 for(i = 0; i < LL_OFFSET_HIST_MAX; i++) {
1331 if (offset[i].rw_pid != 0)
1332 seq_printf(seq,"%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1333 offset[i].rw_op ? 'W' : 'R',
1334 offset[i].rw_pid,
1335 offset[i].rw_range_start,
1336 offset[i].rw_range_end,
1337 (unsigned long)offset[i].rw_smallest_extent,
1338 (unsigned long)offset[i].rw_largest_extent,
1339 offset[i].rw_offset);
1340 }
1341 /* Then print the current offsets for each process */
1342 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1343 if (process[i].rw_pid != 0)
1344 seq_printf(seq,"%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1345 process[i].rw_op ? 'W' : 'R',
1346 process[i].rw_pid,
1347 process[i].rw_range_start,
1348 process[i].rw_last_file_pos,
1349 (unsigned long)process[i].rw_smallest_extent,
1350 (unsigned long)process[i].rw_largest_extent,
1351 process[i].rw_offset);
1352 }
1353 spin_unlock(&sbi->ll_process_lock);
1354
1355 return 0;
1356}
1357
1358static ssize_t ll_rw_offset_stats_seq_write(struct file *file, const char *buf,
1359 size_t len, loff_t *off)
1360{
1361 struct seq_file *seq = file->private_data;
1362 struct ll_sb_info *sbi = seq->private;
1363 struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
1364 struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
1365 int value = 1, rc = 0;
1366
1367 rc = lprocfs_write_helper(buf, len, &value);
1368
1369 if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
1370 strcmp(buf, "Disabled") == 0))
1371 value = 0;
1372
1373 if (value == 0)
1374 sbi->ll_rw_stats_on = 0;
1375 else
1376 sbi->ll_rw_stats_on = 1;
1377
1378 spin_lock(&sbi->ll_process_lock);
1379 sbi->ll_offset_process_count = 0;
1380 sbi->ll_rw_offset_entry_count = 0;
1381 memset(process_info, 0, sizeof(struct ll_rw_process_info) *
1382 LL_PROCESS_HIST_MAX);
1383 memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
1384 LL_OFFSET_HIST_MAX);
1385 spin_unlock(&sbi->ll_process_lock);
1386
1387 return len;
1388}
1389
1390LPROC_SEQ_FOPS(ll_rw_offset_stats);
1391
1392void lprocfs_llite_init_vars(struct lprocfs_static_vars *lvars)
1393{
1394 lvars->module_vars = NULL;
1395 lvars->obd_vars = lprocfs_llite_obd_vars;
1396}
1397#endif /* LPROCFS */