Whamcloud - gitweb
LU-694 ptlrpc: Job Stats
[fs/lustre-release.git] / lustre / llite / lproc_llite.c
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) 2012, Whamcloud, Inc.
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
46 struct proc_dir_entry *proc_lustre_fs_root;
47
48 #ifdef LPROCFS
49 /* /proc/lustre/llite mount point registration */
50 extern struct file_operations vvp_dump_pgcache_file_ops;
51 struct file_operations ll_rw_extents_stats_fops;
52 struct file_operations ll_rw_extents_stats_pp_fops;
53 struct file_operations ll_rw_offset_stats_fops;
54
55 static 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
74 static 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
99 static 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
123 static 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
147 static 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
165 static 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
184 static 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
201 static 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
211 static 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
221 static 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
234 static 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         cfs_spin_lock(&sbi->ll_lock);
243         pages_number = sbi->ll_ra_info.ra_max_pages;
244         cfs_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
250 static 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 - CFS_PAGE_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 > cfs_num_physpages / 2) {
263                 CERROR("can't set file readahead more than %lu MB\n",
264                        cfs_num_physpages >> (20 - CFS_PAGE_SHIFT + 1)); /*1/2 of RAM*/
265                 return -ERANGE;
266         }
267
268         cfs_spin_lock(&sbi->ll_lock);
269         sbi->ll_ra_info.ra_max_pages = pages_number;
270         cfs_spin_unlock(&sbi->ll_lock);
271
272         return count;
273 }
274
275 static 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         cfs_spin_lock(&sbi->ll_lock);
284         pages_number = sbi->ll_ra_info.ra_max_pages_per_file;
285         cfs_spin_unlock(&sbi->ll_lock);
286
287         mult = 1 << (20 - CFS_PAGE_SHIFT);
288         return lprocfs_read_frac_helper(page, count, pages_number, mult);
289 }
290
291 static 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 - CFS_PAGE_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         cfs_spin_lock(&sbi->ll_lock);
312         sbi->ll_ra_info.ra_max_pages_per_file = pages_number;
313         cfs_spin_unlock(&sbi->ll_lock);
314
315         return count;
316 }
317
318 static 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         cfs_spin_lock(&sbi->ll_lock);
327         pages_number = sbi->ll_ra_info.ra_max_read_ahead_whole_pages;
328         cfs_spin_unlock(&sbi->ll_lock);
329
330         mult = 1 << (20 - CFS_PAGE_SHIFT);
331         return lprocfs_read_frac_helper(page, count, pages_number, mult);
332 }
333
334 static 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 - CFS_PAGE_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 - CFS_PAGE_SHIFT));
353                 return -ERANGE;
354         }
355
356         cfs_spin_lock(&sbi->ll_lock);
357         sbi->ll_ra_info.ra_max_read_ahead_whole_pages = pages_number;
358         cfs_spin_unlock(&sbi->ll_lock);
359
360         return count;
361 }
362
363 static 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         long pages_number;
369         int mult;
370
371         cfs_spin_lock(&sbi->ll_lock);
372         pages_number = sbi->ll_async_page_max;
373         cfs_spin_unlock(&sbi->ll_lock);
374
375         mult = 1 << (20 - CFS_PAGE_SHIFT);
376         return lprocfs_read_frac_helper(page, count, pages_number, mult);;
377 }
378
379 static int ll_wr_max_cached_mb(struct file *file, const char *buffer,
380                                unsigned long count, void *data)
381 {
382         struct super_block *sb = data;
383         struct ll_sb_info *sbi = ll_s2sbi(sb);
384         int mult, rc, pages_number;
385
386         mult = 1 << (20 - CFS_PAGE_SHIFT);
387         rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
388         if (rc)
389                 return rc;
390
391         if (pages_number < 0 || pages_number > cfs_num_physpages) {
392                 CERROR("can't set max cache more than %lu MB\n",
393                         cfs_num_physpages >> (20 - CFS_PAGE_SHIFT));
394                 return -ERANGE;
395         }
396
397         cfs_spin_lock(&sbi->ll_lock);
398         sbi->ll_async_page_max = pages_number ;
399         cfs_spin_unlock(&sbi->ll_lock);
400
401         if (!sbi->ll_dt_exp)
402                 /* Not set up yet, don't call llap_shrink_cache */
403                 return count;
404
405         return count;
406 }
407
408 static int ll_rd_checksum(char *page, char **start, off_t off,
409                           int count, int *eof, void *data)
410 {
411         struct super_block *sb = data;
412         struct ll_sb_info *sbi = ll_s2sbi(sb);
413
414         return snprintf(page, count, "%u\n",
415                         (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0);
416 }
417
418 static int ll_wr_checksum(struct file *file, const char *buffer,
419                           unsigned long count, void *data)
420 {
421         struct super_block *sb = data;
422         struct ll_sb_info *sbi = ll_s2sbi(sb);
423         int val, rc;
424
425         if (!sbi->ll_dt_exp)
426                 /* Not set up yet */
427                 return -EAGAIN;
428
429         rc = lprocfs_write_helper(buffer, count, &val);
430         if (rc)
431                 return rc;
432         if (val)
433                 sbi->ll_flags |= LL_SBI_CHECKSUM;
434         else
435                 sbi->ll_flags &= ~LL_SBI_CHECKSUM;
436
437         rc = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
438                                 KEY_CHECKSUM, sizeof(val), &val, NULL);
439         if (rc)
440                 CWARN("Failed to set OSC checksum flags: %d\n", rc);
441
442         return count;
443 }
444
445 static int ll_rd_max_rw_chunk(char *page, char **start, off_t off,
446                           int count, int *eof, void *data)
447 {
448         struct super_block *sb = data;
449
450         return snprintf(page, count, "%lu\n", ll_s2sbi(sb)->ll_max_rw_chunk);
451 }
452
453 static int ll_wr_max_rw_chunk(struct file *file, const char *buffer,
454                           unsigned long count, void *data)
455 {
456         struct super_block *sb = data;
457         int rc, val;
458
459         rc = lprocfs_write_helper(buffer, count, &val);
460         if (rc)
461                 return rc;
462         ll_s2sbi(sb)->ll_max_rw_chunk = val;
463         return count;
464 }
465
466 static int ll_rd_track_id(char *page, int count, void *data,
467                           enum stats_track_type type)
468 {
469         struct super_block *sb = data;
470
471         if (ll_s2sbi(sb)->ll_stats_track_type == type) {
472                 return snprintf(page, count, "%d\n",
473                                 ll_s2sbi(sb)->ll_stats_track_id);
474
475         } else if (ll_s2sbi(sb)->ll_stats_track_type == STATS_TRACK_ALL) {
476                 return snprintf(page, count, "0 (all)\n");
477         } else {
478                 return snprintf(page, count, "untracked\n");
479         }
480 }
481
482 static int ll_wr_track_id(const char *buffer, unsigned long count, void *data,
483                           enum stats_track_type type)
484 {
485         struct super_block *sb = data;
486         int rc, pid;
487
488         rc = lprocfs_write_helper(buffer, count, &pid);
489         if (rc)
490                 return rc;
491         ll_s2sbi(sb)->ll_stats_track_id = pid;
492         if (pid == 0)
493                 ll_s2sbi(sb)->ll_stats_track_type = STATS_TRACK_ALL;
494         else
495                 ll_s2sbi(sb)->ll_stats_track_type = type;
496         lprocfs_clear_stats(ll_s2sbi(sb)->ll_stats);
497         return count;
498 }
499
500 static int ll_rd_track_pid(char *page, char **start, off_t off,
501                           int count, int *eof, void *data)
502 {
503         return (ll_rd_track_id(page, count, data, STATS_TRACK_PID));
504 }
505
506 static int ll_wr_track_pid(struct file *file, const char *buffer,
507                           unsigned long count, void *data)
508 {
509         return (ll_wr_track_id(buffer, count, data, STATS_TRACK_PID));
510 }
511
512 static int ll_rd_track_ppid(char *page, char **start, off_t off,
513                           int count, int *eof, void *data)
514 {
515         return (ll_rd_track_id(page, count, data, STATS_TRACK_PPID));
516 }
517
518 static int ll_wr_track_ppid(struct file *file, const char *buffer,
519                           unsigned long count, void *data)
520 {
521         return (ll_wr_track_id(buffer, count, data, STATS_TRACK_PPID));
522 }
523
524 static int ll_rd_track_gid(char *page, char **start, off_t off,
525                           int count, int *eof, void *data)
526 {
527         return (ll_rd_track_id(page, count, data, STATS_TRACK_GID));
528 }
529
530 static int ll_wr_track_gid(struct file *file, const char *buffer,
531                           unsigned long count, void *data)
532 {
533         return (ll_wr_track_id(buffer, count, data, STATS_TRACK_GID));
534 }
535
536 static int ll_rd_statahead_max(char *page, char **start, off_t off,
537                                int count, int *eof, void *data)
538 {
539         struct super_block *sb = data;
540         struct ll_sb_info *sbi = ll_s2sbi(sb);
541
542         return snprintf(page, count, "%u\n", sbi->ll_sa_max);
543 }
544
545 static int ll_wr_statahead_max(struct file *file, const char *buffer,
546                                unsigned long count, void *data)
547 {
548         struct super_block *sb = data;
549         struct ll_sb_info *sbi = ll_s2sbi(sb);
550         int val, rc;
551
552         rc = lprocfs_write_helper(buffer, count, &val);
553         if (rc)
554                 return rc;
555
556         if (val >= 0 && val <= LL_SA_RPC_MAX)
557                 sbi->ll_sa_max = val;
558         else
559                 CERROR("Bad statahead_max value %d. Valid values are in the "
560                        "range [0, %d]\n", val, LL_SA_RPC_MAX);
561
562         return count;
563 }
564
565 static int ll_rd_statahead_agl(char *page, char **start, off_t off,
566                                int count, int *eof, void *data)
567 {
568         struct super_block *sb = data;
569         struct ll_sb_info *sbi = ll_s2sbi(sb);
570
571         return snprintf(page, count, "%u\n",
572                         sbi->ll_flags & LL_SBI_AGL_ENABLED ? 1 : 0);
573 }
574
575 static int ll_wr_statahead_agl(struct file *file, const char *buffer,
576                                unsigned long count, void *data)
577 {
578         struct super_block *sb = data;
579         struct ll_sb_info *sbi = ll_s2sbi(sb);
580         int val, rc;
581
582         rc = lprocfs_write_helper(buffer, count, &val);
583         if (rc)
584                 return rc;
585
586         if (val)
587                 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
588         else
589                 sbi->ll_flags &= ~LL_SBI_AGL_ENABLED;
590
591         return count;
592 }
593
594 static int ll_rd_statahead_stats(char *page, char **start, off_t off,
595                                  int count, int *eof, void *data)
596 {
597         struct super_block *sb = data;
598         struct ll_sb_info *sbi = ll_s2sbi(sb);
599
600         return snprintf(page, count,
601                         "statahead total: %u\n"
602                         "statahead wrong: %u\n"
603                         "agl total: %u\n",
604                         atomic_read(&sbi->ll_sa_total),
605                         atomic_read(&sbi->ll_sa_wrong),
606                         atomic_read(&sbi->ll_agl_total));
607 }
608
609 static int ll_rd_lazystatfs(char *page, char **start, off_t off,
610                             int count, int *eof, void *data)
611 {
612         struct super_block *sb = data;
613         struct ll_sb_info *sbi = ll_s2sbi(sb);
614
615         return snprintf(page, count, "%u\n",
616                         (sbi->ll_flags & LL_SBI_LAZYSTATFS) ? 1 : 0);
617 }
618
619 static int ll_wr_lazystatfs(struct file *file, const char *buffer,
620                             unsigned long count, void *data)
621 {
622         struct super_block *sb = data;
623         struct ll_sb_info *sbi = ll_s2sbi(sb);
624         int val, rc;
625
626         rc = lprocfs_write_helper(buffer, count, &val);
627         if (rc)
628                 return rc;
629
630         if (val)
631                 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
632         else
633                 sbi->ll_flags &= ~LL_SBI_LAZYSTATFS;
634
635         return count;
636 }
637
638 static int ll_rd_maxea_size(char *page, char **start, off_t off,
639                             int count, int *eof, void *data)
640 {
641         struct super_block *sb = data;
642         struct ll_sb_info *sbi = ll_s2sbi(sb);
643         unsigned int ealen;
644         int rc;
645
646         rc = ll_get_max_mdsize(sbi, &ealen);
647         if (rc)
648                 return rc;
649
650         return snprintf(page, count, "%u\n", ealen);
651 }
652
653 static int ll_rd_jobidvar(char *page, char **start, off_t off,
654                           int count, int *eof, void *data)
655 {
656         return snprintf(page, count, "%s\n", obd_jobid_var);
657 }
658
659 static int ll_wr_jobidvar(struct file *file, const char *buffer,
660                           unsigned long count, void *data)
661 {
662         if (!count || count > JOBSTATS_JOBID_VAR_MAX_LEN)
663                 return -EINVAL;
664
665         memset(obd_jobid_var, 0, JOBSTATS_JOBID_VAR_MAX_LEN + 1);
666         /* Trim the trailing '\n' if any */
667         memcpy(obd_jobid_var, buffer, count - (buffer[count - 1] == '\n'));
668         return count;
669 }
670
671 static struct lprocfs_vars lprocfs_llite_obd_vars[] = {
672         { "uuid",         ll_rd_sb_uuid,          0, 0 },
673         //{ "mntpt_path",   ll_rd_path,             0, 0 },
674         { "fstype",       ll_rd_fstype,           0, 0 },
675         { "site",         ll_rd_site_stats,       0, 0 },
676         { "blocksize",    ll_rd_blksize,          0, 0 },
677         { "kbytestotal",  ll_rd_kbytestotal,      0, 0 },
678         { "kbytesfree",   ll_rd_kbytesfree,       0, 0 },
679         { "kbytesavail",  ll_rd_kbytesavail,      0, 0 },
680         { "filestotal",   ll_rd_filestotal,       0, 0 },
681         { "filesfree",    ll_rd_filesfree,        0, 0 },
682         { "client_type",  ll_rd_client_type,      0, 0 },
683         //{ "filegroups",   lprocfs_rd_filegroups,  0, 0 },
684         { "max_read_ahead_mb", ll_rd_max_readahead_mb,
685                                ll_wr_max_readahead_mb, 0 },
686         { "max_read_ahead_per_file_mb", ll_rd_max_readahead_per_file_mb,
687                                         ll_wr_max_readahead_per_file_mb, 0 },
688         { "max_read_ahead_whole_mb", ll_rd_max_read_ahead_whole_mb,
689                                      ll_wr_max_read_ahead_whole_mb, 0 },
690         { "max_cached_mb",    ll_rd_max_cached_mb, ll_wr_max_cached_mb, 0 },
691         { "checksum_pages",   ll_rd_checksum, ll_wr_checksum, 0 },
692         { "max_rw_chunk",     ll_rd_max_rw_chunk, ll_wr_max_rw_chunk, 0 },
693         { "stats_track_pid",  ll_rd_track_pid, ll_wr_track_pid, 0 },
694         { "stats_track_ppid", ll_rd_track_ppid, ll_wr_track_ppid, 0 },
695         { "stats_track_gid",  ll_rd_track_gid, ll_wr_track_gid, 0 },
696         { "statahead_max",    ll_rd_statahead_max, ll_wr_statahead_max, 0 },
697         { "statahead_agl",    ll_rd_statahead_agl, ll_wr_statahead_agl, 0 },
698         { "statahead_stats",  ll_rd_statahead_stats, 0, 0 },
699         { "lazystatfs",       ll_rd_lazystatfs, ll_wr_lazystatfs, 0 },
700         { "max_easize",       ll_rd_maxea_size, 0, 0 },
701         { "jobid_var",  ll_rd_jobidvar, ll_wr_jobidvar, 0 },
702         { 0 }
703 };
704
705 #define MAX_STRING_SIZE 128
706
707 struct llite_file_opcode {
708         __u32       opcode;
709         __u32       type;
710         const char *opname;
711 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
712         /* file operation */
713         { LPROC_LL_DIRTY_HITS,     LPROCFS_TYPE_REGS, "dirty_pages_hits" },
714         { LPROC_LL_DIRTY_MISSES,   LPROCFS_TYPE_REGS, "dirty_pages_misses" },
715         { LPROC_LL_READ_BYTES,     LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
716                                    "read_bytes" },
717         { LPROC_LL_WRITE_BYTES,    LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
718                                    "write_bytes" },
719         { LPROC_LL_BRW_READ,       LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
720                                    "brw_read" },
721         { LPROC_LL_BRW_WRITE,      LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
722                                    "brw_write" },
723         { LPROC_LL_OSC_READ,       LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
724                                    "osc_read" },
725         { LPROC_LL_OSC_WRITE,      LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
726                                    "osc_write" },
727         { LPROC_LL_IOCTL,          LPROCFS_TYPE_REGS, "ioctl" },
728         { LPROC_LL_OPEN,           LPROCFS_TYPE_REGS, "open" },
729         { LPROC_LL_RELEASE,        LPROCFS_TYPE_REGS, "close" },
730         { LPROC_LL_MAP,            LPROCFS_TYPE_REGS, "mmap" },
731         { LPROC_LL_LLSEEK,         LPROCFS_TYPE_REGS, "seek" },
732         { LPROC_LL_FSYNC,          LPROCFS_TYPE_REGS, "fsync" },
733         { LPROC_LL_READDIR,        LPROCFS_TYPE_REGS, "readdir" },
734         /* inode operation */
735         { LPROC_LL_SETATTR,        LPROCFS_TYPE_REGS, "setattr" },
736         { LPROC_LL_TRUNC,          LPROCFS_TYPE_REGS, "truncate" },
737         { LPROC_LL_FLOCK,          LPROCFS_TYPE_REGS, "flock" },
738         { LPROC_LL_GETATTR,        LPROCFS_TYPE_REGS, "getattr" },
739         /* dir inode operation */
740         { LPROC_LL_CREATE,         LPROCFS_TYPE_REGS, "create" },
741         { LPROC_LL_LINK,           LPROCFS_TYPE_REGS, "link" },
742         { LPROC_LL_UNLINK,         LPROCFS_TYPE_REGS, "unlink" },
743         { LPROC_LL_SYMLINK,        LPROCFS_TYPE_REGS, "symlink" },
744         { LPROC_LL_MKDIR,          LPROCFS_TYPE_REGS, "mkdir" },
745         { LPROC_LL_RMDIR,          LPROCFS_TYPE_REGS, "rmdir" },
746         { LPROC_LL_MKNOD,          LPROCFS_TYPE_REGS, "mknod" },
747         { LPROC_LL_RENAME,         LPROCFS_TYPE_REGS, "rename" },
748         /* special inode operation */
749         { LPROC_LL_STAFS,          LPROCFS_TYPE_REGS, "statfs" },
750         { LPROC_LL_ALLOC_INODE,    LPROCFS_TYPE_REGS, "alloc_inode" },
751         { LPROC_LL_SETXATTR,       LPROCFS_TYPE_REGS, "setxattr" },
752         { LPROC_LL_GETXATTR,       LPROCFS_TYPE_REGS, "getxattr" },
753         { LPROC_LL_LISTXATTR,      LPROCFS_TYPE_REGS, "listxattr" },
754         { LPROC_LL_REMOVEXATTR,    LPROCFS_TYPE_REGS, "removexattr" },
755         { LPROC_LL_INODE_PERM,     LPROCFS_TYPE_REGS, "inode_permission" },
756 };
757
758 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
759 {
760         if (!sbi->ll_stats)
761                 return;
762         if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
763                 lprocfs_counter_add(sbi->ll_stats, op, count);
764         else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
765                  sbi->ll_stats_track_id == current->pid)
766                 lprocfs_counter_add(sbi->ll_stats, op, count);
767         else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
768                  sbi->ll_stats_track_id == current->parent->pid)
769                 lprocfs_counter_add(sbi->ll_stats, op, count);
770         else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
771                  sbi->ll_stats_track_id == cfs_curproc_gid())
772                 lprocfs_counter_add(sbi->ll_stats, op, count);
773 }
774 EXPORT_SYMBOL(ll_stats_ops_tally);
775
776 static const char *ra_stat_string[] = {
777         [RA_STAT_HIT] = "hits",
778         [RA_STAT_MISS] = "misses",
779         [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
780         [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
781         [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page",
782         [RA_STAT_FAILED_MATCH] = "failed lock match",
783         [RA_STAT_DISCARDED] = "read but discarded",
784         [RA_STAT_ZERO_LEN] = "zero length file",
785         [RA_STAT_ZERO_WINDOW] = "zero size window",
786         [RA_STAT_EOF] = "read-ahead to EOF",
787         [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
788         [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",
789 };
790
791
792 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
793                                 struct super_block *sb, char *osc, char *mdc)
794 {
795         struct lprocfs_vars lvars[2];
796         struct lustre_sb_info *lsi = s2lsi(sb);
797         struct ll_sb_info *sbi = ll_s2sbi(sb);
798         struct obd_device *obd;
799         char name[MAX_STRING_SIZE + 1], *ptr;
800         int err, id, len, rc;
801         ENTRY;
802
803         memset(lvars, 0, sizeof(lvars));
804
805         name[MAX_STRING_SIZE] = '\0';
806         lvars[0].name = name;
807
808         LASSERT(sbi != NULL);
809         LASSERT(mdc != NULL);
810         LASSERT(osc != NULL);
811
812         /* Get fsname */
813         len = strlen(lsi->lsi_lmd->lmd_profile);
814         ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
815         if (ptr && (strcmp(ptr, "-client") == 0))
816                 len -= 7;
817
818         /* Mount info */
819         snprintf(name, MAX_STRING_SIZE, "%.*s-%p", len,
820                  lsi->lsi_lmd->lmd_profile, sb);
821
822         sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
823         if (IS_ERR(sbi->ll_proc_root)) {
824                 err = PTR_ERR(sbi->ll_proc_root);
825                 sbi->ll_proc_root = NULL;
826                 RETURN(err);
827         }
828
829         rc = lprocfs_seq_create(sbi->ll_proc_root, "dump_page_cache", 0444,
830                                 &vvp_dump_pgcache_file_ops, sbi);
831         if (rc)
832                 CWARN("Error adding the dump_page_cache file\n");
833
834         rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats", 0644,
835                                 &ll_rw_extents_stats_fops, sbi);
836         if (rc)
837                 CWARN("Error adding the extent_stats file\n");
838
839         rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats_per_process",
840                                 0644, &ll_rw_extents_stats_pp_fops, sbi);
841         if (rc)
842                 CWARN("Error adding the extents_stats_per_process file\n");
843
844         rc = lprocfs_seq_create(sbi->ll_proc_root, "offset_stats", 0644,
845                                 &ll_rw_offset_stats_fops, sbi);
846         if (rc)
847                 CWARN("Error adding the offset_stats file\n");
848
849         /* File operations stats */
850         sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
851                                             LPROCFS_STATS_FLAG_NONE);
852         if (sbi->ll_stats == NULL)
853                 GOTO(out, err = -ENOMEM);
854         /* do counter init */
855         for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
856                 __u32 type = llite_opcode_table[id].type;
857                 void *ptr = NULL;
858                 if (type & LPROCFS_TYPE_REGS)
859                         ptr = "regs";
860                 else if (type & LPROCFS_TYPE_BYTES)
861                         ptr = "bytes";
862                 else if (type & LPROCFS_TYPE_PAGES)
863                         ptr = "pages";
864                 lprocfs_counter_init(sbi->ll_stats,
865                                      llite_opcode_table[id].opcode,
866                                      (type & LPROCFS_CNTR_AVGMINMAX),
867                                      llite_opcode_table[id].opname, ptr);
868         }
869         err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats);
870         if (err)
871                 GOTO(out, err);
872
873         sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
874                                                LPROCFS_STATS_FLAG_NONE);
875         if (sbi->ll_ra_stats == NULL)
876                 GOTO(out, err = -ENOMEM);
877
878         for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
879                 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
880                                      ra_stat_string[id], "pages");
881         err = lprocfs_register_stats(sbi->ll_proc_root, "read_ahead_stats",
882                                      sbi->ll_ra_stats);
883         if (err)
884                 GOTO(out, err);
885
886
887         err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_llite_obd_vars, sb);
888         if (err)
889                 GOTO(out, err);
890
891         /* MDC info */
892         obd = class_name2obd(mdc);
893
894         LASSERT(obd != NULL);
895         LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
896         LASSERT(obd->obd_type->typ_name != NULL);
897
898         snprintf(name, MAX_STRING_SIZE, "%s/common_name",
899                  obd->obd_type->typ_name);
900         lvars[0].read_fptr = lprocfs_rd_name;
901         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
902         if (err)
903                 GOTO(out, err);
904
905         snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
906         lvars[0].read_fptr = lprocfs_rd_uuid;
907         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
908         if (err)
909                 GOTO(out, err);
910
911         /* OSC */
912         obd = class_name2obd(osc);
913
914         LASSERT(obd != NULL);
915         LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
916         LASSERT(obd->obd_type->typ_name != NULL);
917
918         snprintf(name, MAX_STRING_SIZE, "%s/common_name",
919                  obd->obd_type->typ_name);
920         lvars[0].read_fptr = lprocfs_rd_name;
921         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
922         if (err)
923                 GOTO(out, err);
924
925         snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
926         lvars[0].read_fptr = lprocfs_rd_uuid;
927         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
928 out:
929         if (err) {
930                 lprocfs_remove(&sbi->ll_proc_root);
931                 lprocfs_free_stats(&sbi->ll_ra_stats);
932                 lprocfs_free_stats(&sbi->ll_stats);
933         }
934         RETURN(err);
935 }
936
937 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
938 {
939         if (sbi->ll_proc_root) {
940                 lprocfs_remove(&sbi->ll_proc_root);
941                 lprocfs_free_stats(&sbi->ll_ra_stats);
942                 lprocfs_free_stats(&sbi->ll_stats);
943         }
944 }
945 #undef MAX_STRING_SIZE
946
947 #define pct(a,b) (b ? a * 100 / b : 0)
948
949 static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
950                                    struct seq_file *seq, int which)
951 {
952         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
953         unsigned long start, end, r, w;
954         char *unitp = "KMGTPEZY";
955         int i, units = 10;
956         struct per_process_info *pp_info = &io_extents->pp_extents[which];
957
958         read_cum = 0;
959         write_cum = 0;
960         start = 0;
961
962         for(i = 0; i < LL_HIST_MAX; i++) {
963                 read_tot += pp_info->pp_r_hist.oh_buckets[i];
964                 write_tot += pp_info->pp_w_hist.oh_buckets[i];
965         }
966
967         for(i = 0; i < LL_HIST_MAX; i++) {
968                 r = pp_info->pp_r_hist.oh_buckets[i];
969                 w = pp_info->pp_w_hist.oh_buckets[i];
970                 read_cum += r;
971                 write_cum += w;
972                 end = 1 << (i + LL_HIST_START - units);
973                 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu  | "
974                            "%14lu %4lu %4lu\n", start, *unitp, end, *unitp,
975                            (i == LL_HIST_MAX - 1) ? '+' : ' ',
976                            r, pct(r, read_tot), pct(read_cum, read_tot),
977                            w, pct(w, write_tot), pct(write_cum, write_tot));
978                 start = end;
979                 if (start == 1<<10) {
980                         start = 1;
981                         units += 10;
982                         unitp++;
983                 }
984                 if (read_cum == read_tot && write_cum == write_tot)
985                         break;
986         }
987 }
988
989 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
990 {
991         struct timeval now;
992         struct ll_sb_info *sbi = seq->private;
993         struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
994         int k;
995
996         cfs_gettimeofday(&now);
997
998         if (!sbi->ll_rw_stats_on) {
999                 seq_printf(seq, "disabled\n"
1000                                 "write anything in this file to activate, "
1001                                 "then 0 or \"[D/d]isabled\" to deactivate\n");
1002                 return 0;
1003         }
1004         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
1005                    now.tv_sec, now.tv_usec);
1006         seq_printf(seq, "%15s %19s       | %20s\n", " ", "read", "write");
1007         seq_printf(seq, "%13s   %14s %4s %4s  | %14s %4s %4s\n",
1008                    "extents", "calls", "%", "cum%",
1009                    "calls", "%", "cum%");
1010         cfs_spin_lock(&sbi->ll_pp_extent_lock);
1011         for(k = 0; k < LL_PROCESS_HIST_MAX; k++) {
1012                 if(io_extents->pp_extents[k].pid != 0) {
1013                         seq_printf(seq, "\nPID: %d\n",
1014                                    io_extents->pp_extents[k].pid);
1015                         ll_display_extents_info(io_extents, seq, k);
1016                 }
1017         }
1018         cfs_spin_unlock(&sbi->ll_pp_extent_lock);
1019         return 0;
1020 }
1021
1022 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
1023                                                 const char *buf, size_t len,
1024                                                 loff_t *off)
1025 {
1026         struct seq_file *seq = file->private_data;
1027         struct ll_sb_info *sbi = seq->private;
1028         struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1029         int i;
1030         int value = 1, rc = 0;
1031
1032         rc = lprocfs_write_helper(buf, len, &value);
1033         if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
1034                        strcmp(buf, "Disabled") == 0))
1035                 value = 0;
1036
1037         if (value == 0)
1038                 sbi->ll_rw_stats_on = 0;
1039         else
1040                 sbi->ll_rw_stats_on = 1;
1041
1042         cfs_spin_lock(&sbi->ll_pp_extent_lock);
1043         for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1044                 io_extents->pp_extents[i].pid = 0;
1045                 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1046                 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1047         }
1048         cfs_spin_unlock(&sbi->ll_pp_extent_lock);
1049         return len;
1050 }
1051
1052 LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
1053
1054 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
1055 {
1056         struct timeval now;
1057         struct ll_sb_info *sbi = seq->private;
1058         struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1059
1060         cfs_gettimeofday(&now);
1061
1062         if (!sbi->ll_rw_stats_on) {
1063                 seq_printf(seq, "disabled\n"
1064                                 "write anything in this file to activate, "
1065                                 "then 0 or \"[D/d]isabled\" to deactivate\n");
1066                 return 0;
1067         }
1068         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
1069                    now.tv_sec, now.tv_usec);
1070
1071         seq_printf(seq, "%15s %19s       | %20s\n", " ", "read", "write");
1072         seq_printf(seq, "%13s   %14s %4s %4s  | %14s %4s %4s\n",
1073                    "extents", "calls", "%", "cum%",
1074                    "calls", "%", "cum%");
1075         cfs_spin_lock(&sbi->ll_lock);
1076         ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
1077         cfs_spin_unlock(&sbi->ll_lock);
1078
1079         return 0;
1080 }
1081
1082 static ssize_t ll_rw_extents_stats_seq_write(struct file *file, const char *buf,
1083                                         size_t len, loff_t *off)
1084 {
1085         struct seq_file *seq = file->private_data;
1086         struct ll_sb_info *sbi = seq->private;
1087         struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1088         int i;
1089         int value = 1, rc = 0;
1090
1091         rc = lprocfs_write_helper(buf, len, &value);
1092         if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
1093                        strcmp(buf, "Disabled") == 0))
1094                 value = 0;
1095
1096         if (value == 0)
1097                 sbi->ll_rw_stats_on = 0;
1098         else
1099                 sbi->ll_rw_stats_on = 1;
1100         cfs_spin_lock(&sbi->ll_pp_extent_lock);
1101         for(i = 0; i <= LL_PROCESS_HIST_MAX; i++)
1102         {
1103                 io_extents->pp_extents[i].pid = 0;
1104                 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1105                 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1106         }
1107         cfs_spin_unlock(&sbi->ll_pp_extent_lock);
1108
1109         return len;
1110 }
1111
1112 LPROC_SEQ_FOPS(ll_rw_extents_stats);
1113
1114 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
1115                        struct ll_file_data *file, loff_t pos,
1116                        size_t count, int rw)
1117 {
1118         int i, cur = -1;
1119         struct ll_rw_process_info *process;
1120         struct ll_rw_process_info *offset;
1121         int *off_count = &sbi->ll_rw_offset_entry_count;
1122         int *process_count = &sbi->ll_offset_process_count;
1123         struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1124
1125         if(!sbi->ll_rw_stats_on)
1126                 return;
1127         process = sbi->ll_rw_process_info;
1128         offset = sbi->ll_rw_offset_info;
1129
1130         cfs_spin_lock(&sbi->ll_pp_extent_lock);
1131         /* Extent statistics */
1132         for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1133                 if(io_extents->pp_extents[i].pid == pid) {
1134                         cur = i;
1135                         break;
1136                 }
1137         }
1138
1139         if (cur == -1) {
1140                 /* new process */
1141                 sbi->ll_extent_process_count =
1142                         (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1143                 cur = sbi->ll_extent_process_count;
1144                 io_extents->pp_extents[cur].pid = pid;
1145                 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1146                 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1147         }
1148
1149         for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
1150              (i < (LL_HIST_MAX - 1)); i++);
1151         if (rw == 0) {
1152                 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1153                 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1154         } else {
1155                 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1156                 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1157         }
1158         cfs_spin_unlock(&sbi->ll_pp_extent_lock);
1159
1160         cfs_spin_lock(&sbi->ll_process_lock);
1161         /* Offset statistics */
1162         for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1163                 if (process[i].rw_pid == pid) {
1164                         if (process[i].rw_last_file != file) {
1165                                 process[i].rw_range_start = pos;
1166                                 process[i].rw_last_file_pos = pos + count;
1167                                 process[i].rw_smallest_extent = count;
1168                                 process[i].rw_largest_extent = count;
1169                                 process[i].rw_offset = 0;
1170                                 process[i].rw_last_file = file;
1171                                 cfs_spin_unlock(&sbi->ll_process_lock);
1172                                 return;
1173                         }
1174                         if (process[i].rw_last_file_pos != pos) {
1175                                 *off_count =
1176                                     (*off_count + 1) % LL_OFFSET_HIST_MAX;
1177                                 offset[*off_count].rw_op = process[i].rw_op;
1178                                 offset[*off_count].rw_pid = pid;
1179                                 offset[*off_count].rw_range_start =
1180                                         process[i].rw_range_start;
1181                                 offset[*off_count].rw_range_end =
1182                                         process[i].rw_last_file_pos;
1183                                 offset[*off_count].rw_smallest_extent =
1184                                         process[i].rw_smallest_extent;
1185                                 offset[*off_count].rw_largest_extent =
1186                                         process[i].rw_largest_extent;
1187                                 offset[*off_count].rw_offset =
1188                                         process[i].rw_offset;
1189                                 process[i].rw_op = rw;
1190                                 process[i].rw_range_start = pos;
1191                                 process[i].rw_smallest_extent = count;
1192                                 process[i].rw_largest_extent = count;
1193                                 process[i].rw_offset = pos -
1194                                         process[i].rw_last_file_pos;
1195                         }
1196                         if(process[i].rw_smallest_extent > count)
1197                                 process[i].rw_smallest_extent = count;
1198                         if(process[i].rw_largest_extent < count)
1199                                 process[i].rw_largest_extent = count;
1200                         process[i].rw_last_file_pos = pos + count;
1201                         cfs_spin_unlock(&sbi->ll_process_lock);
1202                         return;
1203                 }
1204         }
1205         *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
1206         process[*process_count].rw_pid = pid;
1207         process[*process_count].rw_op = rw;
1208         process[*process_count].rw_range_start = pos;
1209         process[*process_count].rw_last_file_pos = pos + count;
1210         process[*process_count].rw_smallest_extent = count;
1211         process[*process_count].rw_largest_extent = count;
1212         process[*process_count].rw_offset = 0;
1213         process[*process_count].rw_last_file = file;
1214         cfs_spin_unlock(&sbi->ll_process_lock);
1215 }
1216
1217 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1218 {
1219         struct timeval now;
1220         struct ll_sb_info *sbi = seq->private;
1221         struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
1222         struct ll_rw_process_info *process = sbi->ll_rw_process_info;
1223         int i;
1224
1225         cfs_gettimeofday(&now);
1226
1227         if (!sbi->ll_rw_stats_on) {
1228                 seq_printf(seq, "disabled\n"
1229                                 "write anything in this file to activate, "
1230                                 "then 0 or \"[D/d]isabled\" to deactivate\n");
1231                 return 0;
1232         }
1233         cfs_spin_lock(&sbi->ll_process_lock);
1234
1235         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
1236                    now.tv_sec, now.tv_usec);
1237         seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
1238                    "R/W", "PID", "RANGE START", "RANGE END",
1239                    "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
1240         /* We stored the discontiguous offsets here; print them first */
1241         for(i = 0; i < LL_OFFSET_HIST_MAX; i++) {
1242                 if (offset[i].rw_pid != 0)
1243                         seq_printf(seq,"%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1244                                    offset[i].rw_op ? 'W' : 'R',
1245                                    offset[i].rw_pid,
1246                                    offset[i].rw_range_start,
1247                                    offset[i].rw_range_end,
1248                                    (unsigned long)offset[i].rw_smallest_extent,
1249                                    (unsigned long)offset[i].rw_largest_extent,
1250                                    offset[i].rw_offset);
1251         }
1252         /* Then print the current offsets for each process */
1253         for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1254                 if (process[i].rw_pid != 0)
1255                         seq_printf(seq,"%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1256                                    process[i].rw_op ? 'W' : 'R',
1257                                    process[i].rw_pid,
1258                                    process[i].rw_range_start,
1259                                    process[i].rw_last_file_pos,
1260                                    (unsigned long)process[i].rw_smallest_extent,
1261                                    (unsigned long)process[i].rw_largest_extent,
1262                                    process[i].rw_offset);
1263         }
1264         cfs_spin_unlock(&sbi->ll_process_lock);
1265
1266         return 0;
1267 }
1268
1269 static ssize_t ll_rw_offset_stats_seq_write(struct file *file, const char *buf,
1270                                        size_t len, loff_t *off)
1271 {
1272         struct seq_file *seq = file->private_data;
1273         struct ll_sb_info *sbi = seq->private;
1274         struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
1275         struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
1276         int value = 1, rc = 0;
1277
1278         rc = lprocfs_write_helper(buf, len, &value);
1279
1280         if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
1281                            strcmp(buf, "Disabled") == 0))
1282                 value = 0;
1283
1284         if (value == 0)
1285                 sbi->ll_rw_stats_on = 0;
1286         else
1287                 sbi->ll_rw_stats_on = 1;
1288
1289         cfs_spin_lock(&sbi->ll_process_lock);
1290         sbi->ll_offset_process_count = 0;
1291         sbi->ll_rw_offset_entry_count = 0;
1292         memset(process_info, 0, sizeof(struct ll_rw_process_info) *
1293                LL_PROCESS_HIST_MAX);
1294         memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
1295                LL_OFFSET_HIST_MAX);
1296         cfs_spin_unlock(&sbi->ll_process_lock);
1297
1298         return len;
1299 }
1300
1301 LPROC_SEQ_FOPS(ll_rw_offset_stats);
1302
1303 void lprocfs_llite_init_vars(struct lprocfs_static_vars *lvars)
1304 {
1305     lvars->module_vars  = NULL;
1306     lvars->obd_vars     = lprocfs_llite_obd_vars;
1307 }
1308 #endif /* LPROCFS */