Whamcloud - gitweb
Revert "LU-8066 llite: replace ll_process_config with class_modify_config"
[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.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2012, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  */
32 #define DEBUG_SUBSYSTEM S_LLITE
33
34 #include <linux/version.h>
35 #include <linux/user_namespace.h>
36 #ifdef HAVE_UIDGID_HEADER
37 # include <linux/uidgid.h>
38 #endif
39 #include <uapi/linux/lustre/lustre_param.h>
40 #include <lprocfs_status.h>
41 #include <obd_support.h>
42
43 #include "llite_internal.h"
44 #include "vvp_internal.h"
45
46 struct proc_dir_entry *proc_lustre_fs_root;
47 static struct kobject *llite_kobj;
48
49 int llite_tunables_register(void)
50 {
51         int rc = 0;
52
53         proc_lustre_fs_root = lprocfs_register("llite", proc_lustre_root,
54                                                NULL, NULL);
55         if (IS_ERR(proc_lustre_fs_root)) {
56                 rc = PTR_ERR(proc_lustre_fs_root);
57                 CERROR("cannot register '/proc/fs/lustre/llite': rc = %d\n",
58                        rc);
59                 proc_lustre_fs_root = NULL;
60                 return rc;
61         }
62
63         llite_kobj = class_setup_tunables("llite");
64         if (IS_ERR(llite_kobj)) {
65                 rc = PTR_ERR(llite_kobj);
66                 llite_kobj = NULL;
67         }
68
69         return rc;
70 }
71
72 void llite_tunables_unregister(void)
73 {
74         if (llite_kobj)
75                 kobject_put(llite_kobj);
76
77         lprocfs_remove(&proc_lustre_fs_root);
78 }
79
80 #ifdef CONFIG_PROC_FS
81 /* /proc/lustre/llite mount point registration */
82 static const struct file_operations ll_rw_extents_stats_fops;
83 static const struct file_operations ll_rw_extents_stats_pp_fops;
84 static const struct file_operations ll_rw_offset_stats_fops;
85 static __s64 ll_stats_pid_write(const char __user *buf, size_t len);
86
87 static int ll_blksize_seq_show(struct seq_file *m, void *v)
88 {
89         struct super_block *sb = m->private;
90         struct obd_statfs osfs;
91         int rc;
92
93         LASSERT(sb != NULL);
94         rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_NODELAY);
95         if (!rc)
96                 seq_printf(m, "%u\n", osfs.os_bsize);
97         return rc;
98 }
99 LPROC_SEQ_FOPS_RO(ll_blksize);
100
101 static int ll_stat_blksize_seq_show(struct seq_file *m, void *v)
102 {
103         struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
104
105         seq_printf(m, "%u\n", sbi->ll_stat_blksize);
106
107         return 0;
108 }
109
110 static ssize_t ll_stat_blksize_seq_write(struct file *file,
111                                          const char __user *buffer,
112                                          size_t count, loff_t *off)
113 {
114         struct seq_file *m = file->private_data;
115         struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
116         unsigned int val;
117         int rc;
118
119         rc = kstrtouint_from_user(buffer, count, 0, &val);
120         if (rc)
121                 return rc;
122
123         if (val != 0 && (val < PAGE_SIZE || (val & (val - 1))) != 0)
124                 return -ERANGE;
125
126         sbi->ll_stat_blksize = val;
127
128         return count;
129 }
130 LPROC_SEQ_FOPS(ll_stat_blksize);
131
132 static int ll_kbytestotal_seq_show(struct seq_file *m, void *v)
133 {
134         struct super_block *sb = m->private;
135         struct obd_statfs osfs;
136         int rc;
137
138         LASSERT(sb != NULL);
139         rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_NODELAY);
140         if (!rc) {
141                 __u32 blk_size = osfs.os_bsize >> 10;
142                 __u64 result = osfs.os_blocks;
143
144                 while (blk_size >>= 1)
145                         result <<= 1;
146
147                 seq_printf(m, "%llu\n", result);
148         }
149         return rc;
150 }
151 LPROC_SEQ_FOPS_RO(ll_kbytestotal);
152
153 static int ll_kbytesfree_seq_show(struct seq_file *m, void *v)
154 {
155         struct super_block *sb = m->private;
156         struct obd_statfs osfs;
157         int rc;
158
159         LASSERT(sb != NULL);
160         rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_NODELAY);
161         if (!rc) {
162                 __u32 blk_size = osfs.os_bsize >> 10;
163                 __u64 result = osfs.os_bfree;
164
165                 while (blk_size >>= 1)
166                         result <<= 1;
167
168                 seq_printf(m, "%llu\n", result);
169         }
170         return rc;
171 }
172 LPROC_SEQ_FOPS_RO(ll_kbytesfree);
173
174 static int ll_kbytesavail_seq_show(struct seq_file *m, void *v)
175 {
176         struct super_block *sb = m->private;
177         struct obd_statfs osfs;
178         int rc;
179
180         LASSERT(sb != NULL);
181         rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_NODELAY);
182         if (!rc) {
183                 __u32 blk_size = osfs.os_bsize >> 10;
184                 __u64 result = osfs.os_bavail;
185
186                 while (blk_size >>= 1)
187                         result <<= 1;
188
189                 seq_printf(m, "%llu\n", result);
190         }
191         return rc;
192 }
193 LPROC_SEQ_FOPS_RO(ll_kbytesavail);
194
195 static int ll_filestotal_seq_show(struct seq_file *m, void *v)
196 {
197         struct super_block *sb = m->private;
198         struct obd_statfs osfs;
199         int rc;
200
201         LASSERT(sb != NULL);
202         rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_NODELAY);
203         if (!rc)
204                 seq_printf(m, "%llu\n", osfs.os_files);
205         return rc;
206 }
207 LPROC_SEQ_FOPS_RO(ll_filestotal);
208
209 static int ll_filesfree_seq_show(struct seq_file *m, void *v)
210 {
211         struct super_block *sb = m->private;
212         struct obd_statfs osfs;
213         int rc;
214
215         LASSERT(sb != NULL);
216         rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_NODELAY);
217         if (!rc)
218                 seq_printf(m, "%llu\n", osfs.os_ffree);
219         return rc;
220 }
221 LPROC_SEQ_FOPS_RO(ll_filesfree);
222
223 static int ll_client_type_seq_show(struct seq_file *m, void *v)
224 {
225         struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
226
227         LASSERT(sbi != NULL);
228
229         seq_puts(m, "local client\n");
230         return 0;
231 }
232 LPROC_SEQ_FOPS_RO(ll_client_type);
233
234 static int ll_fstype_seq_show(struct seq_file *m, void *v)
235 {
236         struct super_block *sb = m->private;
237         struct ll_sb_info *sbi = ll_s2sbi(sb);
238
239         LASSERT(sb != NULL);
240         seq_printf(m, "%s\n", sbi->ll_mnt.mnt->mnt_sb->s_type->name);
241         return 0;
242 }
243 LPROC_SEQ_FOPS_RO(ll_fstype);
244
245 static int ll_sb_uuid_seq_show(struct seq_file *m, void *v)
246 {
247         struct super_block *sb = m->private;
248
249         LASSERT(sb != NULL);
250         seq_printf(m, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
251         return 0;
252 }
253 LPROC_SEQ_FOPS_RO(ll_sb_uuid);
254
255 static int ll_xattr_cache_seq_show(struct seq_file *m, void *v)
256 {
257         struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
258
259         seq_printf(m, "%u\n", sbi->ll_xattr_cache_enabled);
260         return 0;
261 }
262
263 static ssize_t ll_xattr_cache_seq_write(struct file *file,
264                                         const char __user *buffer,
265                                         size_t count, loff_t *off)
266 {
267         struct seq_file *m = file->private_data;
268         struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
269         bool val;
270         int rc;
271
272         rc = kstrtobool_from_user(buffer, count, &val);
273         if (rc)
274                 return rc;
275
276         if (val && !(sbi->ll_flags & LL_SBI_XATTR_CACHE))
277                 return -ENOTSUPP;
278
279         sbi->ll_xattr_cache_enabled = val;
280         sbi->ll_xattr_cache_set = 1;
281
282         return count;
283 }
284 LPROC_SEQ_FOPS(ll_xattr_cache);
285
286 static int ll_site_stats_seq_show(struct seq_file *m, void *v)
287 {
288         struct super_block *sb = m->private;
289
290         /*
291          * See description of statistical counters in struct cl_site, and
292          * struct lu_site.
293          */
294         return cl_site_stats_print(lu2cl_site(ll_s2sbi(sb)->ll_site), m);
295 }
296 LPROC_SEQ_FOPS_RO(ll_site_stats);
297
298 static int ll_max_readahead_mb_seq_show(struct seq_file *m, void *v)
299 {
300         struct super_block *sb = m->private;
301         struct ll_sb_info *sbi = ll_s2sbi(sb);
302         long pages_number;
303         int mult;
304
305         spin_lock(&sbi->ll_lock);
306         pages_number = sbi->ll_ra_info.ra_max_pages;
307         spin_unlock(&sbi->ll_lock);
308
309         mult = 1 << (20 - PAGE_SHIFT);
310         return lprocfs_seq_read_frac_helper(m, pages_number, mult);
311 }
312
313 static ssize_t
314 ll_max_readahead_mb_seq_write(struct file *file, const char __user *buffer,
315                               size_t count, loff_t *off)
316 {
317         struct seq_file *m = file->private_data;
318         struct super_block *sb = m->private;
319         struct ll_sb_info *sbi = ll_s2sbi(sb);
320         __s64 pages_number;
321         int rc;
322
323         rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
324         if (rc)
325                 return rc;
326
327         pages_number >>= PAGE_SHIFT;
328
329         if (pages_number < 0 || pages_number > totalram_pages / 2) {
330                 /* 1/2 of RAM */
331                 CERROR("%s: can't set max_readahead_mb=%lu > %luMB\n",
332                        ll_get_fsname(sb, NULL, 0),
333                        (unsigned long)pages_number >> (20 - PAGE_SHIFT),
334                        totalram_pages >> (20 - PAGE_SHIFT + 1));
335                 return -ERANGE;
336         }
337
338         spin_lock(&sbi->ll_lock);
339         sbi->ll_ra_info.ra_max_pages = pages_number;
340         spin_unlock(&sbi->ll_lock);
341         return count;
342 }
343 LPROC_SEQ_FOPS(ll_max_readahead_mb);
344
345 static int ll_max_readahead_per_file_mb_seq_show(struct seq_file *m, void *v)
346 {
347         struct super_block *sb = m->private;
348         struct ll_sb_info *sbi = ll_s2sbi(sb);
349         long pages_number;
350         int mult;
351
352         spin_lock(&sbi->ll_lock);
353         pages_number = sbi->ll_ra_info.ra_max_pages_per_file;
354         spin_unlock(&sbi->ll_lock);
355
356         mult = 1 << (20 - PAGE_SHIFT);
357         return lprocfs_seq_read_frac_helper(m, pages_number, mult);
358 }
359
360 static ssize_t
361 ll_max_readahead_per_file_mb_seq_write(struct file *file,
362                                        const char __user *buffer,
363                                        size_t count, loff_t *off)
364 {
365         struct seq_file *m = file->private_data;
366         struct super_block *sb = m->private;
367         struct ll_sb_info *sbi = ll_s2sbi(sb);
368         int rc;
369         __s64 pages_number;
370
371         rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
372         if (rc)
373                 return rc;
374
375         pages_number >>= PAGE_SHIFT;
376
377         if (pages_number < 0 || pages_number > sbi->ll_ra_info.ra_max_pages) {
378                 CERROR("%s: can't set max_readahead_per_file_mb=%lu > "
379                        "max_read_ahead_mb=%lu\n", ll_get_fsname(sb, NULL, 0),
380                        (unsigned long)pages_number >> (20 - PAGE_SHIFT),
381                        sbi->ll_ra_info.ra_max_pages >> (20 - PAGE_SHIFT));
382                 return -ERANGE;
383         }
384
385         spin_lock(&sbi->ll_lock);
386         sbi->ll_ra_info.ra_max_pages_per_file = pages_number;
387         spin_unlock(&sbi->ll_lock);
388         return count;
389 }
390 LPROC_SEQ_FOPS(ll_max_readahead_per_file_mb);
391
392 static int ll_max_read_ahead_whole_mb_seq_show(struct seq_file *m, void *v)
393 {
394         struct super_block *sb = m->private;
395         struct ll_sb_info *sbi = ll_s2sbi(sb);
396         long pages_number;
397         int mult;
398
399         spin_lock(&sbi->ll_lock);
400         pages_number = sbi->ll_ra_info.ra_max_read_ahead_whole_pages;
401         spin_unlock(&sbi->ll_lock);
402
403         mult = 1 << (20 - PAGE_SHIFT);
404         return lprocfs_seq_read_frac_helper(m, pages_number, mult);
405 }
406
407 static ssize_t
408 ll_max_read_ahead_whole_mb_seq_write(struct file *file,
409                                      const char __user *buffer,
410                                      size_t count, loff_t *off)
411 {
412         struct seq_file *m = file->private_data;
413         struct super_block *sb = m->private;
414         struct ll_sb_info *sbi = ll_s2sbi(sb);
415         int rc;
416         __s64 pages_number;
417
418         rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
419         if (rc)
420                 return rc;
421
422         pages_number >>= PAGE_SHIFT;
423
424         /* Cap this at the current max readahead window size, the readahead
425          * algorithm does this anyway so it's pointless to set it larger. */
426         if (pages_number < 0 ||
427             pages_number > sbi->ll_ra_info.ra_max_pages_per_file) {
428                 int pages_shift = 20 - PAGE_SHIFT;
429                 CERROR("%s: can't set max_read_ahead_whole_mb=%lu > "
430                        "max_read_ahead_per_file_mb=%lu\n",
431                        ll_get_fsname(sb, NULL, 0),
432                        (unsigned long)pages_number >> pages_shift,
433                        sbi->ll_ra_info.ra_max_pages_per_file >> pages_shift);
434                 return -ERANGE;
435         }
436
437         spin_lock(&sbi->ll_lock);
438         sbi->ll_ra_info.ra_max_read_ahead_whole_pages = pages_number;
439         spin_unlock(&sbi->ll_lock);
440         return count;
441 }
442 LPROC_SEQ_FOPS(ll_max_read_ahead_whole_mb);
443
444 static int ll_max_cached_mb_seq_show(struct seq_file *m, void *v)
445 {
446         struct super_block     *sb    = m->private;
447         struct ll_sb_info      *sbi   = ll_s2sbi(sb);
448         struct cl_client_cache *cache = sbi->ll_cache;
449         int shift = 20 - PAGE_SHIFT;
450         long max_cached_mb;
451         long unused_mb;
452
453         max_cached_mb = cache->ccc_lru_max >> shift;
454         unused_mb = atomic_long_read(&cache->ccc_lru_left) >> shift;
455         seq_printf(m, "users: %d\n"
456                    "max_cached_mb: %ld\n"
457                    "used_mb: %ld\n"
458                    "unused_mb: %ld\n"
459                    "reclaim_count: %u\n",
460                    atomic_read(&cache->ccc_users),
461                    max_cached_mb,
462                    max_cached_mb - unused_mb,
463                    unused_mb,
464                    cache->ccc_lru_shrinkers);
465         return 0;
466 }
467
468 static ssize_t
469 ll_max_cached_mb_seq_write(struct file *file, const char __user *buffer,
470                            size_t count, loff_t *off)
471 {
472         struct seq_file *m = file->private_data;
473         struct super_block *sb = m->private;
474         struct ll_sb_info *sbi = ll_s2sbi(sb);
475         struct cl_client_cache *cache = sbi->ll_cache;
476         struct lu_env *env;
477         long diff = 0;
478         long nrpages = 0;
479         __u16 refcheck;
480         __s64 pages_number;
481         long rc;
482         char kernbuf[128];
483         ENTRY;
484
485         if (count >= sizeof(kernbuf))
486                 RETURN(-EINVAL);
487
488         if (copy_from_user(kernbuf, buffer, count))
489                 RETURN(-EFAULT);
490         kernbuf[count] = 0;
491
492         buffer += lprocfs_find_named_value(kernbuf, "max_cached_mb:", &count) -
493                   kernbuf;
494         rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
495         if (rc)
496                 RETURN(rc);
497
498         pages_number >>= PAGE_SHIFT;
499
500         if (pages_number < 0 || pages_number > totalram_pages) {
501                 CERROR("%s: can't set max cache more than %lu MB\n",
502                        ll_get_fsname(sb, NULL, 0),
503                        totalram_pages >> (20 - PAGE_SHIFT));
504                 RETURN(-ERANGE);
505         }
506         /* Allow enough cache so clients can make well-formed RPCs */
507         pages_number = max_t(long, pages_number, PTLRPC_MAX_BRW_PAGES);
508
509         spin_lock(&sbi->ll_lock);
510         diff = pages_number - cache->ccc_lru_max;
511         spin_unlock(&sbi->ll_lock);
512
513         /* easy - add more LRU slots. */
514         if (diff >= 0) {
515                 atomic_long_add(diff, &cache->ccc_lru_left);
516                 GOTO(out, rc = 0);
517         }
518
519         env = cl_env_get(&refcheck);
520         if (IS_ERR(env))
521                 RETURN(rc);
522
523         diff = -diff;
524         while (diff > 0) {
525                 long tmp;
526
527                 /* reduce LRU budget from free slots. */
528                 do {
529                         long ov, nv;
530
531                         ov = atomic_long_read(&cache->ccc_lru_left);
532                         if (ov == 0)
533                                 break;
534
535                         nv = ov > diff ? ov - diff : 0;
536                         rc = atomic_long_cmpxchg(&cache->ccc_lru_left, ov, nv);
537                         if (likely(ov == rc)) {
538                                 diff -= ov - nv;
539                                 nrpages += ov - nv;
540                                 break;
541                         }
542                 } while (1);
543
544                 if (diff <= 0)
545                         break;
546
547                 if (sbi->ll_dt_exp == NULL) { /* being initialized */
548                         rc = -ENODEV;
549                         break;
550                 }
551
552                 /* difficult - have to ask OSCs to drop LRU slots. */
553                 tmp = diff << 1;
554                 rc = obd_set_info_async(env, sbi->ll_dt_exp,
555                                 sizeof(KEY_CACHE_LRU_SHRINK),
556                                 KEY_CACHE_LRU_SHRINK,
557                                 sizeof(tmp), &tmp, NULL);
558                 if (rc < 0)
559                         break;
560         }
561         cl_env_put(env, &refcheck);
562
563 out:
564         if (rc >= 0) {
565                 spin_lock(&sbi->ll_lock);
566                 cache->ccc_lru_max = pages_number;
567                 spin_unlock(&sbi->ll_lock);
568                 rc = count;
569         } else {
570                 atomic_long_add(nrpages, &cache->ccc_lru_left);
571         }
572         return rc;
573 }
574 LPROC_SEQ_FOPS(ll_max_cached_mb);
575
576 static int ll_checksum_seq_show(struct seq_file *m, void *v)
577 {
578         struct super_block *sb = m->private;
579         struct ll_sb_info *sbi = ll_s2sbi(sb);
580
581         seq_printf(m, "%u\n", (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0);
582         return 0;
583 }
584
585 static ssize_t ll_checksum_seq_write(struct file *file,
586                                      const char __user *buffer,
587                                      size_t count, loff_t *off)
588 {
589         struct seq_file *m = file->private_data;
590         struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
591         bool val;
592         int tmp;
593         int rc;
594
595         if (!sbi->ll_dt_exp)
596                 /* Not set up yet */
597                 return -EAGAIN;
598
599         rc = kstrtobool_from_user(buffer, count, &val);
600         if (rc)
601                 return rc;
602         if (val)
603                 sbi->ll_flags |= LL_SBI_CHECKSUM;
604         else
605                 sbi->ll_flags &= ~LL_SBI_CHECKSUM;
606         tmp = val;
607
608         rc = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
609                                 KEY_CHECKSUM, sizeof(tmp), &tmp, NULL);
610         if (rc)
611                 CWARN("Failed to set OSC checksum flags: %d\n", rc);
612
613         return count;
614 }
615 LPROC_SEQ_FOPS(ll_checksum);
616
617 static int ll_rd_track_id(struct seq_file *m, enum stats_track_type type)
618 {
619         struct super_block *sb = m->private;
620
621         if (ll_s2sbi(sb)->ll_stats_track_type == type) {
622                 seq_printf(m, "%d\n",
623                            ll_s2sbi(sb)->ll_stats_track_id);
624         } else if (ll_s2sbi(sb)->ll_stats_track_type == STATS_TRACK_ALL) {
625                 seq_puts(m, "0 (all)\n");
626         } else {
627                 seq_puts(m, "untracked\n");
628         }
629         return 0;
630 }
631
632 static int ll_wr_track_id(const char __user *buffer, unsigned long count,
633                           void *data, enum stats_track_type type)
634 {
635         struct super_block *sb = data;
636         unsigned int pid;
637         int rc;
638
639         rc = kstrtouint_from_user(buffer, count, 0, &pid);
640         if (rc)
641                 return rc;
642
643         ll_s2sbi(sb)->ll_stats_track_id = pid;
644         if (pid == 0)
645                 ll_s2sbi(sb)->ll_stats_track_type = STATS_TRACK_ALL;
646         else
647                 ll_s2sbi(sb)->ll_stats_track_type = type;
648         lprocfs_clear_stats(ll_s2sbi(sb)->ll_stats);
649         return count;
650 }
651
652 static int ll_track_pid_seq_show(struct seq_file *m, void *v)
653 {
654         return ll_rd_track_id(m, STATS_TRACK_PID);
655 }
656
657 static ssize_t ll_track_pid_seq_write(struct file *file,
658                                       const char __user *buffer,
659                                       size_t count, loff_t *off)
660 {
661         struct seq_file *seq = file->private_data;
662         return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PID);
663 }
664 LPROC_SEQ_FOPS(ll_track_pid);
665
666 static int ll_track_ppid_seq_show(struct seq_file *m, void *v)
667 {
668         return ll_rd_track_id(m, STATS_TRACK_PPID);
669 }
670
671 static ssize_t ll_track_ppid_seq_write(struct file *file,
672                                        const char __user *buffer,
673                                        size_t count, loff_t *off)
674 {
675         struct seq_file *seq = file->private_data;
676         return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PPID);
677 }
678 LPROC_SEQ_FOPS(ll_track_ppid);
679
680 static int ll_track_gid_seq_show(struct seq_file *m, void *v)
681 {
682         return ll_rd_track_id(m, STATS_TRACK_GID);
683 }
684
685 static ssize_t ll_track_gid_seq_write(struct file *file,
686                                       const char __user *buffer,
687                                       size_t count, loff_t *off)
688 {
689         struct seq_file *seq = file->private_data;
690         return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_GID);
691 }
692 LPROC_SEQ_FOPS(ll_track_gid);
693
694 static int ll_statahead_max_seq_show(struct seq_file *m, void *v)
695 {
696         struct super_block *sb = m->private;
697         struct ll_sb_info *sbi = ll_s2sbi(sb);
698
699         seq_printf(m, "%u\n", sbi->ll_sa_max);
700         return 0;
701 }
702
703 static ssize_t ll_statahead_max_seq_write(struct file *file,
704                                           const char __user *buffer,
705                                           size_t count, loff_t *off)
706 {
707         struct seq_file *m = file->private_data;
708         struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
709         unsigned int val;
710         int rc;
711
712         rc = kstrtouint_from_user(buffer, count, 0, &val);
713         if (rc)
714                 return rc;
715
716         if (val <= LL_SA_RPC_MAX)
717                 sbi->ll_sa_max = val;
718         else
719                 CERROR("Bad statahead_max value %u. Valid values are in "
720                        "the range [0, %d]\n", val, LL_SA_RPC_MAX);
721
722         return count;
723 }
724 LPROC_SEQ_FOPS(ll_statahead_max);
725
726 static int ll_statahead_agl_seq_show(struct seq_file *m, void *v)
727 {
728         struct super_block *sb = m->private;
729         struct ll_sb_info *sbi = ll_s2sbi(sb);
730
731         seq_printf(m, "%u\n",
732                    sbi->ll_flags & LL_SBI_AGL_ENABLED ? 1 : 0);
733         return 0;
734 }
735
736 static ssize_t ll_statahead_agl_seq_write(struct file *file,
737                                           const char __user *buffer,
738                                           size_t count, loff_t *off)
739 {
740         struct seq_file *m = file->private_data;
741         struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
742         bool val;
743         int rc;
744
745         rc = kstrtobool_from_user(buffer, count, &val);
746         if (rc)
747                 return rc;
748
749         if (val)
750                 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
751         else
752                 sbi->ll_flags &= ~LL_SBI_AGL_ENABLED;
753
754         return count;
755 }
756 LPROC_SEQ_FOPS(ll_statahead_agl);
757
758 static int ll_statahead_stats_seq_show(struct seq_file *m, void *v)
759 {
760         struct super_block *sb = m->private;
761         struct ll_sb_info *sbi = ll_s2sbi(sb);
762
763         seq_printf(m, "statahead total: %u\n"
764                     "statahead wrong: %u\n"
765                     "agl total: %u\n",
766                     atomic_read(&sbi->ll_sa_total),
767                     atomic_read(&sbi->ll_sa_wrong),
768                     atomic_read(&sbi->ll_agl_total));
769         return 0;
770 }
771 LPROC_SEQ_FOPS_RO(ll_statahead_stats);
772
773 static int ll_lazystatfs_seq_show(struct seq_file *m, void *v)
774 {
775         struct super_block *sb = m->private;
776         struct ll_sb_info *sbi = ll_s2sbi(sb);
777
778         seq_printf(m, "%u\n",
779                    (sbi->ll_flags & LL_SBI_LAZYSTATFS) ? 1 : 0);
780         return 0;
781 }
782
783 static ssize_t ll_lazystatfs_seq_write(struct file *file,
784                                        const char __user *buffer,
785                                         size_t count, loff_t *off)
786 {
787         struct seq_file *m = file->private_data;
788         struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
789         bool val;
790         int rc;
791
792         rc = kstrtobool_from_user(buffer, count, &val);
793         if (rc)
794                 return rc;
795
796         if (val)
797                 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
798         else
799                 sbi->ll_flags &= ~LL_SBI_LAZYSTATFS;
800
801         return count;
802 }
803 LPROC_SEQ_FOPS(ll_lazystatfs);
804
805 static int ll_max_easize_seq_show(struct seq_file *m, void *v)
806 {
807         struct super_block *sb = m->private;
808         struct ll_sb_info *sbi = ll_s2sbi(sb);
809         unsigned int ealen;
810         int rc;
811
812         rc = ll_get_max_mdsize(sbi, &ealen);
813         if (rc)
814                 return rc;
815
816         seq_printf(m, "%u\n", ealen);
817         return 0;
818 }
819 LPROC_SEQ_FOPS_RO(ll_max_easize);
820
821 /**
822  * Get default_easize.
823  *
824  * \see client_obd::cl_default_mds_easize
825  *
826  * \param[in] m         seq_file handle
827  * \param[in] v         unused for single entry
828  *
829  * \retval 0            on success
830  * \retval negative     negated errno on failure
831  */
832 static int ll_default_easize_seq_show(struct seq_file *m, void *v)
833 {
834         struct super_block *sb = m->private;
835         struct ll_sb_info *sbi = ll_s2sbi(sb);
836         unsigned int ealen;
837         int rc;
838
839         rc = ll_get_default_mdsize(sbi, &ealen);
840         if (rc)
841                 return rc;
842
843         seq_printf(m, "%u\n", ealen);
844         return 0;
845 }
846
847 /**
848  * Set default_easize.
849  *
850  * Range checking on the passed value is handled by
851  * ll_set_default_mdsize().
852  *
853  * \see client_obd::cl_default_mds_easize
854  *
855  * \param[in] file      proc file
856  * \param[in] buffer    string passed from user space
857  * \param[in] count     \a buffer length
858  * \param[in] off       unused for single entry
859  *
860  * \retval positive     \a count on success
861  * \retval negative     negated errno on failure
862  */
863 static ssize_t ll_default_easize_seq_write(struct file *file,
864                                            const char __user *buffer,
865                                            size_t count, loff_t *unused)
866 {
867         struct seq_file *seq = file->private_data;
868         struct super_block *sb = (struct super_block *)seq->private;
869         struct ll_sb_info *sbi = ll_s2sbi(sb);
870         unsigned int val;
871         int rc;
872
873         if (count == 0)
874                 return 0;
875
876         rc = kstrtouint_from_user(buffer, count, 0, &val);
877         if (rc)
878                 return rc;
879
880         rc = ll_set_default_mdsize(sbi, val);
881         if (rc)
882                 return rc;
883
884         return count;
885 }
886 LPROC_SEQ_FOPS(ll_default_easize);
887
888 static int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
889 {
890         const char *str[] = LL_SBI_FLAGS;
891         struct super_block *sb = m->private;
892         int flags = ll_s2sbi(sb)->ll_flags;
893         int i = 0;
894
895         while (flags != 0) {
896                 if (ARRAY_SIZE(str) <= i) {
897                         CERROR("%s: Revise array LL_SBI_FLAGS to match sbi "
898                                 "flags please.\n", ll_get_fsname(sb, NULL, 0));
899                         return -EINVAL;
900                 }
901
902                 if (flags & 0x1)
903                         seq_printf(m, "%s ", str[i]);
904                 flags >>= 1;
905                 ++i;
906         }
907         seq_printf(m, "\b\n");
908         return 0;
909 }
910 LPROC_SEQ_FOPS_RO(ll_sbi_flags);
911
912 static int ll_tiny_write_seq_show(struct seq_file *m, void *v)
913 {
914         struct super_block *sb = m->private;
915         struct ll_sb_info *sbi = ll_s2sbi(sb);
916
917         seq_printf(m, "%u\n", !!(sbi->ll_flags & LL_SBI_TINY_WRITE));
918         return 0;
919 }
920
921 static ssize_t ll_tiny_write_seq_write(
922         struct file *file, const char __user *buffer, size_t count, loff_t *off)
923 {
924         struct seq_file *m = file->private_data;
925         struct super_block *sb = m->private;
926         struct ll_sb_info *sbi = ll_s2sbi(sb);
927         bool val;
928         int rc;
929
930         rc = kstrtobool_from_user(buffer, count, &val);
931         if (rc)
932                 return rc;
933
934         spin_lock(&sbi->ll_lock);
935         if (val)
936                 sbi->ll_flags |= LL_SBI_TINY_WRITE;
937         else
938                 sbi->ll_flags &= ~LL_SBI_TINY_WRITE;
939         spin_unlock(&sbi->ll_lock);
940
941         return count;
942 }
943 LPROC_SEQ_FOPS(ll_tiny_write);
944
945 static int ll_fast_read_seq_show(struct seq_file *m, void *v)
946 {
947         struct super_block *sb = m->private;
948         struct ll_sb_info *sbi = ll_s2sbi(sb);
949
950         seq_printf(m, "%u\n", !!(sbi->ll_flags & LL_SBI_FAST_READ));
951         return 0;
952 }
953
954 static ssize_t
955 ll_fast_read_seq_write(struct file *file, const char __user *buffer,
956                        size_t count, loff_t *off)
957 {
958         struct seq_file *m = file->private_data;
959         struct super_block *sb = m->private;
960         struct ll_sb_info *sbi = ll_s2sbi(sb);
961         bool val;
962         int rc;
963
964         rc = kstrtobool_from_user(buffer, count, &val);
965         if (rc)
966                 return rc;
967
968         spin_lock(&sbi->ll_lock);
969         if (val)
970                 sbi->ll_flags |= LL_SBI_FAST_READ;
971         else
972                 sbi->ll_flags &= ~LL_SBI_FAST_READ;
973         spin_unlock(&sbi->ll_lock);
974
975         return count;
976 }
977 LPROC_SEQ_FOPS(ll_fast_read);
978
979 static int ll_pio_seq_show(struct seq_file *m, void *v)
980 {
981         struct super_block *sb = m->private;
982         struct ll_sb_info *sbi = ll_s2sbi(sb);
983
984         seq_printf(m, "%u\n", !!(sbi->ll_flags & LL_SBI_PIO));
985         return 0;
986 }
987
988 static ssize_t ll_pio_seq_write(struct file *file, const char __user *buffer,
989                                 size_t count, loff_t *off)
990 {
991         struct seq_file *m = file->private_data;
992         struct super_block *sb = m->private;
993         struct ll_sb_info *sbi = ll_s2sbi(sb);
994         bool val;
995         int rc;
996
997         rc = kstrtobool_from_user(buffer, count, &val);
998         if (rc)
999                 return rc;
1000
1001         spin_lock(&sbi->ll_lock);
1002         if (val)
1003                 sbi->ll_flags |= LL_SBI_PIO;
1004         else
1005                 sbi->ll_flags &= ~LL_SBI_PIO;
1006         spin_unlock(&sbi->ll_lock);
1007
1008         return count;
1009 }
1010 LPROC_SEQ_FOPS(ll_pio);
1011
1012 static int ll_unstable_stats_seq_show(struct seq_file *m, void *v)
1013 {
1014         struct super_block      *sb    = m->private;
1015         struct ll_sb_info       *sbi   = ll_s2sbi(sb);
1016         struct cl_client_cache  *cache = sbi->ll_cache;
1017         long pages;
1018         int mb;
1019
1020         pages = atomic_long_read(&cache->ccc_unstable_nr);
1021         mb    = (pages * PAGE_SIZE) >> 20;
1022
1023         seq_printf(m, "unstable_check:     %8d\n"
1024                    "unstable_pages: %12ld\n"
1025                    "unstable_mb:        %8d\n",
1026                    cache->ccc_unstable_check, pages, mb);
1027         return 0;
1028 }
1029
1030 static ssize_t ll_unstable_stats_seq_write(struct file *file,
1031                                            const char __user *buffer,
1032                                            size_t count, loff_t *unused)
1033 {
1034         struct seq_file *seq = file->private_data;
1035         struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)seq->private);
1036         char kernbuf[128];
1037         bool val;
1038         int rc;
1039
1040         if (count == 0)
1041                 return 0;
1042         if (count >= sizeof(kernbuf))
1043                 return -EINVAL;
1044
1045         if (copy_from_user(kernbuf, buffer, count))
1046                 return -EFAULT;
1047         kernbuf[count] = 0;
1048
1049         buffer += lprocfs_find_named_value(kernbuf, "unstable_check:", &count) -
1050                   kernbuf;
1051         rc = kstrtobool_from_user(buffer, count, &val);
1052         if (rc < 0)
1053                 return rc;
1054
1055         /* borrow lru lock to set the value */
1056         spin_lock(&sbi->ll_cache->ccc_lru_lock);
1057         sbi->ll_cache->ccc_unstable_check = val;
1058         spin_unlock(&sbi->ll_cache->ccc_lru_lock);
1059
1060         return count;
1061 }
1062 LPROC_SEQ_FOPS(ll_unstable_stats);
1063
1064 static int ll_root_squash_seq_show(struct seq_file *m, void *v)
1065 {
1066         struct super_block *sb = m->private;
1067         struct ll_sb_info *sbi = ll_s2sbi(sb);
1068         struct root_squash_info *squash = &sbi->ll_squash;
1069
1070         seq_printf(m, "%u:%u\n", squash->rsi_uid, squash->rsi_gid);
1071         return 0;
1072 }
1073
1074 static ssize_t ll_root_squash_seq_write(struct file *file,
1075                                         const char __user *buffer,
1076                                         size_t count, loff_t *off)
1077 {
1078         struct seq_file *m = file->private_data;
1079         struct super_block *sb = m->private;
1080         struct ll_sb_info *sbi = ll_s2sbi(sb);
1081         struct root_squash_info *squash = &sbi->ll_squash;
1082
1083         return lprocfs_wr_root_squash(buffer, count, squash,
1084                                       ll_get_fsname(sb, NULL, 0));
1085 }
1086 LPROC_SEQ_FOPS(ll_root_squash);
1087
1088 static int ll_nosquash_nids_seq_show(struct seq_file *m, void *v)
1089 {
1090         struct super_block *sb = m->private;
1091         struct ll_sb_info *sbi = ll_s2sbi(sb);
1092         struct root_squash_info *squash = &sbi->ll_squash;
1093         int len;
1094
1095         down_read(&squash->rsi_sem);
1096         if (!list_empty(&squash->rsi_nosquash_nids)) {
1097                 len = cfs_print_nidlist(m->buf + m->count, m->size - m->count,
1098                                         &squash->rsi_nosquash_nids);
1099                 m->count += len;
1100                 seq_putc(m, '\n');
1101         } else {
1102                 seq_puts(m, "NONE\n");
1103         }
1104         up_read(&squash->rsi_sem);
1105
1106         return 0;
1107 }
1108
1109 static ssize_t ll_nosquash_nids_seq_write(struct file *file,
1110                                           const char __user *buffer,
1111                                           size_t count, loff_t *off)
1112 {
1113         struct seq_file *m = file->private_data;
1114         struct super_block *sb = m->private;
1115         struct ll_sb_info *sbi = ll_s2sbi(sb);
1116         struct root_squash_info *squash = &sbi->ll_squash;
1117         int rc;
1118
1119         rc = lprocfs_wr_nosquash_nids(buffer, count, squash,
1120                                       ll_get_fsname(sb, NULL, 0));
1121         if (rc < 0)
1122                 return rc;
1123
1124         ll_compute_rootsquash_state(sbi);
1125
1126         return rc;
1127 }
1128 LPROC_SEQ_FOPS(ll_nosquash_nids);
1129
1130 struct lprocfs_vars lprocfs_llite_obd_vars[] = {
1131         { .name =       "uuid",
1132           .fops =       &ll_sb_uuid_fops                        },
1133         { .name =       "fstype",
1134           .fops =       &ll_fstype_fops                         },
1135         { .name =       "site",
1136           .fops =       &ll_site_stats_fops                     },
1137         { .name =       "blocksize",
1138           .fops =       &ll_blksize_fops                        },
1139         { .name =       "stat_blocksize",
1140           .fops =       &ll_stat_blksize_fops                   },
1141         { .name =       "kbytestotal",
1142           .fops =       &ll_kbytestotal_fops                    },
1143         { .name =       "kbytesfree",
1144           .fops =       &ll_kbytesfree_fops                     },
1145         { .name =       "kbytesavail",
1146           .fops =       &ll_kbytesavail_fops                    },
1147         { .name =       "filestotal",
1148           .fops =       &ll_filestotal_fops                     },
1149         { .name =       "filesfree",
1150           .fops =       &ll_filesfree_fops                      },
1151         { .name =       "client_type",
1152           .fops =       &ll_client_type_fops                    },
1153         { .name =       "max_read_ahead_mb",
1154           .fops =       &ll_max_readahead_mb_fops               },
1155         { .name =       "max_read_ahead_per_file_mb",
1156           .fops =       &ll_max_readahead_per_file_mb_fops      },
1157         { .name =       "max_read_ahead_whole_mb",
1158           .fops =       &ll_max_read_ahead_whole_mb_fops        },
1159         { .name =       "max_cached_mb",
1160           .fops =       &ll_max_cached_mb_fops                  },
1161         { .name =       "checksum_pages",
1162           .fops =       &ll_checksum_fops                       },
1163         { .name =       "stats_track_pid",
1164           .fops =       &ll_track_pid_fops                      },
1165         { .name =       "stats_track_ppid",
1166           .fops =       &ll_track_ppid_fops                     },
1167         { .name =       "stats_track_gid",
1168           .fops =       &ll_track_gid_fops                      },
1169         { .name =       "statahead_max",
1170           .fops =       &ll_statahead_max_fops                  },
1171         { .name =       "statahead_agl",
1172           .fops =       &ll_statahead_agl_fops                  },
1173         { .name =       "statahead_stats",
1174           .fops =       &ll_statahead_stats_fops                },
1175         { .name =       "lazystatfs",
1176           .fops =       &ll_lazystatfs_fops                     },
1177         { .name =       "max_easize",
1178           .fops =       &ll_max_easize_fops                     },
1179         { .name =       "default_easize",
1180           .fops =       &ll_default_easize_fops                 },
1181         { .name =       "sbi_flags",
1182           .fops =       &ll_sbi_flags_fops                      },
1183         { .name =       "xattr_cache",
1184           .fops =       &ll_xattr_cache_fops                    },
1185         { .name =       "unstable_stats",
1186           .fops =       &ll_unstable_stats_fops                 },
1187         { .name =       "root_squash",
1188           .fops =       &ll_root_squash_fops                    },
1189         { .name =       "nosquash_nids",
1190           .fops =       &ll_nosquash_nids_fops                  },
1191         { .name =       "fast_read",
1192           .fops =       &ll_fast_read_fops,                     },
1193         { .name =       "pio",
1194           .fops =       &ll_pio_fops,                           },
1195         { .name =       "tiny_write",
1196           .fops =       &ll_tiny_write_fops,                    },
1197         { NULL }
1198 };
1199
1200 #define MAX_STRING_SIZE 128
1201
1202 static struct attribute *llite_attrs[] = {
1203         NULL,
1204 };
1205
1206 static void llite_kobj_release(struct kobject *kobj)
1207 {
1208         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1209                                               ll_kset.kobj);
1210         complete(&sbi->ll_kobj_unregister);
1211 }
1212
1213 static struct kobj_type llite_ktype = {
1214         .default_attrs  = llite_attrs,
1215         .sysfs_ops      = &lustre_sysfs_ops,
1216         .release        = llite_kobj_release,
1217 };
1218
1219 static const struct llite_file_opcode {
1220         __u32       opcode;
1221         __u32       type;
1222         const char *opname;
1223 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
1224         /* file operation */
1225         { LPROC_LL_DIRTY_HITS,     LPROCFS_TYPE_REGS, "dirty_pages_hits" },
1226         { LPROC_LL_DIRTY_MISSES,   LPROCFS_TYPE_REGS, "dirty_pages_misses" },
1227         { LPROC_LL_READ_BYTES,     LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1228                                    "read_bytes" },
1229         { LPROC_LL_WRITE_BYTES,    LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
1230                                    "write_bytes" },
1231         { LPROC_LL_BRW_READ,       LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
1232                                    "brw_read" },
1233         { LPROC_LL_BRW_WRITE,      LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
1234                                    "brw_write" },
1235         { LPROC_LL_IOCTL,          LPROCFS_TYPE_REGS, "ioctl" },
1236         { LPROC_LL_OPEN,           LPROCFS_TYPE_REGS, "open" },
1237         { LPROC_LL_RELEASE,        LPROCFS_TYPE_REGS, "close" },
1238         { LPROC_LL_MAP,            LPROCFS_TYPE_REGS, "mmap" },
1239         { LPROC_LL_FAULT,          LPROCFS_TYPE_REGS, "page_fault" },
1240         { LPROC_LL_MKWRITE,        LPROCFS_TYPE_REGS, "page_mkwrite" },
1241         { LPROC_LL_LLSEEK,         LPROCFS_TYPE_REGS, "seek" },
1242         { LPROC_LL_FSYNC,          LPROCFS_TYPE_REGS, "fsync" },
1243         { LPROC_LL_READDIR,        LPROCFS_TYPE_REGS, "readdir" },
1244         /* inode operation */
1245         { LPROC_LL_SETATTR,        LPROCFS_TYPE_REGS, "setattr" },
1246         { LPROC_LL_TRUNC,          LPROCFS_TYPE_REGS, "truncate" },
1247         { LPROC_LL_FLOCK,          LPROCFS_TYPE_REGS, "flock" },
1248         { LPROC_LL_GETATTR,        LPROCFS_TYPE_REGS, "getattr" },
1249         /* dir inode operation */
1250         { LPROC_LL_CREATE,         LPROCFS_TYPE_REGS, "create" },
1251         { LPROC_LL_LINK,           LPROCFS_TYPE_REGS, "link" },
1252         { LPROC_LL_UNLINK,         LPROCFS_TYPE_REGS, "unlink" },
1253         { LPROC_LL_SYMLINK,        LPROCFS_TYPE_REGS, "symlink" },
1254         { LPROC_LL_MKDIR,          LPROCFS_TYPE_REGS, "mkdir" },
1255         { LPROC_LL_RMDIR,          LPROCFS_TYPE_REGS, "rmdir" },
1256         { LPROC_LL_MKNOD,          LPROCFS_TYPE_REGS, "mknod" },
1257         { LPROC_LL_RENAME,         LPROCFS_TYPE_REGS, "rename" },
1258         /* special inode operation */
1259         { LPROC_LL_STAFS,          LPROCFS_TYPE_REGS, "statfs" },
1260         { LPROC_LL_ALLOC_INODE,    LPROCFS_TYPE_REGS, "alloc_inode" },
1261         { LPROC_LL_SETXATTR,       LPROCFS_TYPE_REGS, "setxattr" },
1262         { LPROC_LL_GETXATTR,       LPROCFS_TYPE_REGS, "getxattr" },
1263         { LPROC_LL_GETXATTR_HITS,  LPROCFS_TYPE_REGS, "getxattr_hits" },
1264         { LPROC_LL_LISTXATTR,      LPROCFS_TYPE_REGS, "listxattr" },
1265         { LPROC_LL_REMOVEXATTR,    LPROCFS_TYPE_REGS, "removexattr" },
1266         { LPROC_LL_INODE_PERM,     LPROCFS_TYPE_REGS, "inode_permission" },
1267 };
1268
1269 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
1270 {
1271         if (!sbi->ll_stats)
1272                 return;
1273         if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
1274                 lprocfs_counter_add(sbi->ll_stats, op, count);
1275         else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
1276                  sbi->ll_stats_track_id == current->pid)
1277                 lprocfs_counter_add(sbi->ll_stats, op, count);
1278         else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
1279                  sbi->ll_stats_track_id == current->parent->pid)
1280                 lprocfs_counter_add(sbi->ll_stats, op, count);
1281         else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
1282                  sbi->ll_stats_track_id ==
1283                         from_kgid(&init_user_ns, current_gid()))
1284                 lprocfs_counter_add(sbi->ll_stats, op, count);
1285 }
1286 EXPORT_SYMBOL(ll_stats_ops_tally);
1287
1288 static const char *ra_stat_string[] = {
1289         [RA_STAT_HIT] = "hits",
1290         [RA_STAT_MISS] = "misses",
1291         [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
1292         [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
1293         [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page",
1294         [RA_STAT_FAILED_MATCH] = "failed lock match",
1295         [RA_STAT_DISCARDED] = "read but discarded",
1296         [RA_STAT_ZERO_LEN] = "zero length file",
1297         [RA_STAT_ZERO_WINDOW] = "zero size window",
1298         [RA_STAT_EOF] = "read-ahead to EOF",
1299         [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
1300         [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",
1301         [RA_STAT_FAILED_REACH_END] = "failed to reach end"
1302 };
1303
1304 LPROC_SEQ_FOPS_RO_TYPE(llite, name);
1305 LPROC_SEQ_FOPS_RO_TYPE(llite, uuid);
1306
1307 int ll_debugfs_register_super(struct super_block *sb, const char *name)
1308 {
1309         struct ll_sb_info *sbi = ll_s2sbi(sb);
1310         struct lprocfs_vars lvars[2];
1311         int err, id, rc;
1312
1313         ENTRY;
1314         memset(lvars, 0, sizeof(lvars));
1315         lvars[0].name = name;
1316
1317         LASSERT(sbi != NULL);
1318
1319         sbi->ll_proc_root = lprocfs_register(name, proc_lustre_fs_root,
1320                                              NULL, NULL);
1321         if (IS_ERR(sbi->ll_proc_root)) {
1322                 err = PTR_ERR(sbi->ll_proc_root);
1323                 sbi->ll_proc_root = NULL;
1324                 RETURN(err);
1325         }
1326
1327         rc = lprocfs_seq_create(sbi->ll_proc_root, "dump_page_cache", 0444,
1328                                 &vvp_dump_pgcache_file_ops, sbi);
1329         if (rc)
1330                 CWARN("Error adding the dump_page_cache file\n");
1331
1332         rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats", 0644,
1333                                 &ll_rw_extents_stats_fops, sbi);
1334         if (rc)
1335                 CWARN("Error adding the extent_stats file\n");
1336
1337         rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats_per_process",
1338                                 0644, &ll_rw_extents_stats_pp_fops, sbi);
1339         if (rc)
1340                 CWARN("Error adding the extents_stats_per_process file\n");
1341
1342         rc = lprocfs_seq_create(sbi->ll_proc_root, "offset_stats", 0644,
1343                                 &ll_rw_offset_stats_fops, sbi);
1344         if (rc)
1345                 CWARN("Error adding the offset_stats file\n");
1346
1347         /* File operations stats */
1348         sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
1349                                             LPROCFS_STATS_FLAG_NONE);
1350         if (sbi->ll_stats == NULL)
1351                 GOTO(out_proc, err = -ENOMEM);
1352
1353         /* do counter init */
1354         for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
1355                 __u32 type = llite_opcode_table[id].type;
1356                 void *ptr = NULL;
1357                 if (type & LPROCFS_TYPE_REGS)
1358                         ptr = "regs";
1359                 else if (type & LPROCFS_TYPE_BYTES)
1360                         ptr = "bytes";
1361                 else if (type & LPROCFS_TYPE_PAGES)
1362                         ptr = "pages";
1363                 lprocfs_counter_init(sbi->ll_stats,
1364                                      llite_opcode_table[id].opcode,
1365                                      (type & LPROCFS_CNTR_AVGMINMAX),
1366                                      llite_opcode_table[id].opname, ptr);
1367         }
1368
1369         err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats);
1370         if (err)
1371                 GOTO(out_stats, err);
1372
1373         sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
1374                                                LPROCFS_STATS_FLAG_NONE);
1375         if (sbi->ll_ra_stats == NULL)
1376                 GOTO(out_stats, err = -ENOMEM);
1377
1378         for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
1379                 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
1380                                      ra_stat_string[id], "pages");
1381         err = lprocfs_register_stats(sbi->ll_proc_root, "read_ahead_stats",
1382                                      sbi->ll_ra_stats);
1383         if (err)
1384                 GOTO(out_ra_stats, err);
1385
1386         err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_llite_obd_vars, sb);
1387         if (err)
1388                 GOTO(out_ra_stats, err);
1389
1390         /* Yes we also register sysfs mount kset here as well */
1391         sbi->ll_kset.kobj.parent = llite_kobj;
1392         sbi->ll_kset.kobj.ktype = &llite_ktype;
1393         init_completion(&sbi->ll_kobj_unregister);
1394         err = kobject_set_name(&sbi->ll_kset.kobj, "%s", name);
1395         if (err)
1396                 GOTO(out_ra_stats, err);
1397
1398         err = kset_register(&sbi->ll_kset);
1399         if (err)
1400                 GOTO(out_ra_stats, err);
1401         RETURN(0);
1402 out_ra_stats:
1403         lprocfs_free_stats(&sbi->ll_ra_stats);
1404 out_stats:
1405         lprocfs_free_stats(&sbi->ll_stats);
1406 out_proc:
1407         lprocfs_remove(&sbi->ll_proc_root);
1408
1409         RETURN(err);
1410 }
1411
1412 int lprocfs_ll_register_obd(struct super_block *sb, const char *obdname)
1413 {
1414         struct lprocfs_vars lvars[2];
1415         struct ll_sb_info *sbi = ll_s2sbi(sb);
1416         struct obd_device *obd;
1417         struct proc_dir_entry *dir;
1418         char name[MAX_STRING_SIZE + 1];
1419         int err;
1420         ENTRY;
1421
1422         memset(lvars, 0, sizeof(lvars));
1423
1424         name[MAX_STRING_SIZE] = '\0';
1425         lvars[0].name = name;
1426
1427         LASSERT(sbi != NULL);
1428         LASSERT(obdname != NULL);
1429
1430         obd = class_name2obd(obdname);
1431
1432         LASSERT(obd != NULL);
1433         LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
1434         LASSERT(obd->obd_type->typ_name != NULL);
1435
1436         dir = proc_mkdir(obd->obd_type->typ_name, sbi->ll_proc_root);
1437         if (dir == NULL)
1438                 GOTO(out, err = -ENOMEM);
1439
1440         snprintf(name, MAX_STRING_SIZE, "common_name");
1441         lvars[0].fops = &llite_name_fops;
1442         err = lprocfs_add_vars(dir, lvars, obd);
1443         if (err)
1444                 GOTO(out, err);
1445
1446         snprintf(name, MAX_STRING_SIZE, "uuid");
1447         lvars[0].fops = &llite_uuid_fops;
1448         err = lprocfs_add_vars(dir, lvars, obd);
1449         if (err)
1450                 GOTO(out, err);
1451
1452 out:
1453         if (err) {
1454                 lprocfs_remove(&sbi->ll_proc_root);
1455                 lprocfs_free_stats(&sbi->ll_ra_stats);
1456                 lprocfs_free_stats(&sbi->ll_stats);
1457         }
1458         RETURN(err);
1459 }
1460
1461 void ll_debugfs_unregister_super(struct super_block *sb)
1462 {
1463         struct ll_sb_info *sbi = ll_s2sbi(sb);
1464
1465         kset_unregister(&sbi->ll_kset);
1466         wait_for_completion(&sbi->ll_kobj_unregister);
1467
1468         if (sbi->ll_proc_root) {
1469                 lprocfs_remove(&sbi->ll_proc_root);
1470                 lprocfs_free_stats(&sbi->ll_ra_stats);
1471                 lprocfs_free_stats(&sbi->ll_stats);
1472         }
1473 }
1474 #undef MAX_STRING_SIZE
1475
1476 #define pct(a,b) (b ? a * 100 / b : 0)
1477
1478 static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
1479                                    struct seq_file *seq, int which)
1480 {
1481         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
1482         unsigned long start, end, r, w;
1483         char *unitp = "KMGTPEZY";
1484         int i, units = 10;
1485         struct per_process_info *pp_info = &io_extents->pp_extents[which];
1486
1487         read_cum = 0;
1488         write_cum = 0;
1489         start = 0;
1490
1491         for(i = 0; i < LL_HIST_MAX; i++) {
1492                 read_tot += pp_info->pp_r_hist.oh_buckets[i];
1493                 write_tot += pp_info->pp_w_hist.oh_buckets[i];
1494         }
1495
1496         for(i = 0; i < LL_HIST_MAX; i++) {
1497                 r = pp_info->pp_r_hist.oh_buckets[i];
1498                 w = pp_info->pp_w_hist.oh_buckets[i];
1499                 read_cum += r;
1500                 write_cum += w;
1501                 end = 1 << (i + LL_HIST_START - units);
1502                 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu  | "
1503                            "%14lu %4lu %4lu\n", start, *unitp, end, *unitp,
1504                            (i == LL_HIST_MAX - 1) ? '+' : ' ',
1505                            r, pct(r, read_tot), pct(read_cum, read_tot),
1506                            w, pct(w, write_tot), pct(write_cum, write_tot));
1507                 start = end;
1508                 if (start == 1<<10) {
1509                         start = 1;
1510                         units += 10;
1511                         unitp++;
1512                 }
1513                 if (read_cum == read_tot && write_cum == write_tot)
1514                         break;
1515         }
1516 }
1517
1518 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
1519 {
1520         struct timespec64 now;
1521         struct ll_sb_info *sbi = seq->private;
1522         struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1523         int k;
1524
1525         ktime_get_real_ts64(&now);
1526
1527         if (!sbi->ll_rw_stats_on) {
1528                 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
1529                 return 0;
1530         }
1531         seq_printf(seq, "snapshot_time:         %llu.%09lu (secs.nsecs)\n",
1532                    (s64)now.tv_sec, now.tv_nsec);
1533         seq_printf(seq, "%15s %19s       | %20s\n", " ", "read", "write");
1534         seq_printf(seq, "%13s   %14s %4s %4s  | %14s %4s %4s\n",
1535                    "extents", "calls", "%", "cum%",
1536                    "calls", "%", "cum%");
1537         spin_lock(&sbi->ll_pp_extent_lock);
1538         for (k = 0; k < LL_PROCESS_HIST_MAX; k++) {
1539                 if (io_extents->pp_extents[k].pid != 0) {
1540                         seq_printf(seq, "\nPID: %d\n",
1541                                    io_extents->pp_extents[k].pid);
1542                         ll_display_extents_info(io_extents, seq, k);
1543                 }
1544         }
1545         spin_unlock(&sbi->ll_pp_extent_lock);
1546         return 0;
1547 }
1548
1549 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
1550                                                 const char __user *buf,
1551                                                 size_t len,
1552                                                 loff_t *off)
1553 {
1554         struct seq_file *seq = file->private_data;
1555         struct ll_sb_info *sbi = seq->private;
1556         struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1557         int i;
1558         __s64 value;
1559
1560         if (len == 0)
1561                 return -EINVAL;
1562
1563         value = ll_stats_pid_write(buf, len);
1564
1565         if (value == 0)
1566                 sbi->ll_rw_stats_on = 0;
1567         else
1568                 sbi->ll_rw_stats_on = 1;
1569
1570         spin_lock(&sbi->ll_pp_extent_lock);
1571         for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1572                 io_extents->pp_extents[i].pid = 0;
1573                 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1574                 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1575         }
1576         spin_unlock(&sbi->ll_pp_extent_lock);
1577         return len;
1578 }
1579
1580 LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
1581
1582 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
1583 {
1584         struct timespec64 now;
1585         struct ll_sb_info *sbi = seq->private;
1586         struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1587
1588         ktime_get_real_ts64(&now);
1589
1590         if (!sbi->ll_rw_stats_on) {
1591                 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
1592                 return 0;
1593         }
1594         seq_printf(seq, "snapshot_time:         %llu.%09lu (secs.nsecs)\n",
1595                    (s64)now.tv_sec, now.tv_nsec);
1596
1597         seq_printf(seq, "%15s %19s       | %20s\n", " ", "read", "write");
1598         seq_printf(seq, "%13s   %14s %4s %4s  | %14s %4s %4s\n",
1599                    "extents", "calls", "%", "cum%",
1600                    "calls", "%", "cum%");
1601         spin_lock(&sbi->ll_lock);
1602         ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
1603         spin_unlock(&sbi->ll_lock);
1604
1605         return 0;
1606 }
1607
1608 static ssize_t ll_rw_extents_stats_seq_write(struct file *file,
1609                                              const char __user *buf,
1610                                              size_t len, loff_t *off)
1611 {
1612         struct seq_file *seq = file->private_data;
1613         struct ll_sb_info *sbi = seq->private;
1614         struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1615         int i;
1616         __s64 value;
1617
1618         if (len == 0)
1619                 return -EINVAL;
1620
1621         value = ll_stats_pid_write(buf, len);
1622
1623         if (value == 0)
1624                 sbi->ll_rw_stats_on = 0;
1625         else
1626                 sbi->ll_rw_stats_on = 1;
1627
1628         spin_lock(&sbi->ll_pp_extent_lock);
1629         for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
1630                 io_extents->pp_extents[i].pid = 0;
1631                 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1632                 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1633         }
1634         spin_unlock(&sbi->ll_pp_extent_lock);
1635
1636         return len;
1637 }
1638 LPROC_SEQ_FOPS(ll_rw_extents_stats);
1639
1640 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
1641                        struct ll_file_data *file, loff_t pos,
1642                        size_t count, int rw)
1643 {
1644         int i, cur = -1;
1645         struct ll_rw_process_info *process;
1646         struct ll_rw_process_info *offset;
1647         int *off_count = &sbi->ll_rw_offset_entry_count;
1648         int *process_count = &sbi->ll_offset_process_count;
1649         struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1650
1651         if(!sbi->ll_rw_stats_on)
1652                 return;
1653         process = sbi->ll_rw_process_info;
1654         offset = sbi->ll_rw_offset_info;
1655
1656         spin_lock(&sbi->ll_pp_extent_lock);
1657         /* Extent statistics */
1658         for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1659                 if(io_extents->pp_extents[i].pid == pid) {
1660                         cur = i;
1661                         break;
1662                 }
1663         }
1664
1665         if (cur == -1) {
1666                 /* new process */
1667                 sbi->ll_extent_process_count =
1668                         (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1669                 cur = sbi->ll_extent_process_count;
1670                 io_extents->pp_extents[cur].pid = pid;
1671                 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1672                 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1673         }
1674
1675         for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
1676              (i < (LL_HIST_MAX - 1)); i++);
1677         if (rw == 0) {
1678                 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1679                 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1680         } else {
1681                 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1682                 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1683         }
1684         spin_unlock(&sbi->ll_pp_extent_lock);
1685
1686         spin_lock(&sbi->ll_process_lock);
1687         /* Offset statistics */
1688         for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1689                 if (process[i].rw_pid == pid) {
1690                         if (process[i].rw_last_file != file) {
1691                                 process[i].rw_range_start = pos;
1692                                 process[i].rw_last_file_pos = pos + count;
1693                                 process[i].rw_smallest_extent = count;
1694                                 process[i].rw_largest_extent = count;
1695                                 process[i].rw_offset = 0;
1696                                 process[i].rw_last_file = file;
1697                                 spin_unlock(&sbi->ll_process_lock);
1698                                 return;
1699                         }
1700                         if (process[i].rw_last_file_pos != pos) {
1701                                 *off_count =
1702                                     (*off_count + 1) % LL_OFFSET_HIST_MAX;
1703                                 offset[*off_count].rw_op = process[i].rw_op;
1704                                 offset[*off_count].rw_pid = pid;
1705                                 offset[*off_count].rw_range_start =
1706                                         process[i].rw_range_start;
1707                                 offset[*off_count].rw_range_end =
1708                                         process[i].rw_last_file_pos;
1709                                 offset[*off_count].rw_smallest_extent =
1710                                         process[i].rw_smallest_extent;
1711                                 offset[*off_count].rw_largest_extent =
1712                                         process[i].rw_largest_extent;
1713                                 offset[*off_count].rw_offset =
1714                                         process[i].rw_offset;
1715                                 process[i].rw_op = rw;
1716                                 process[i].rw_range_start = pos;
1717                                 process[i].rw_smallest_extent = count;
1718                                 process[i].rw_largest_extent = count;
1719                                 process[i].rw_offset = pos -
1720                                         process[i].rw_last_file_pos;
1721                         }
1722                         if(process[i].rw_smallest_extent > count)
1723                                 process[i].rw_smallest_extent = count;
1724                         if(process[i].rw_largest_extent < count)
1725                                 process[i].rw_largest_extent = count;
1726                         process[i].rw_last_file_pos = pos + count;
1727                         spin_unlock(&sbi->ll_process_lock);
1728                         return;
1729                 }
1730         }
1731         *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
1732         process[*process_count].rw_pid = pid;
1733         process[*process_count].rw_op = rw;
1734         process[*process_count].rw_range_start = pos;
1735         process[*process_count].rw_last_file_pos = pos + count;
1736         process[*process_count].rw_smallest_extent = count;
1737         process[*process_count].rw_largest_extent = count;
1738         process[*process_count].rw_offset = 0;
1739         process[*process_count].rw_last_file = file;
1740         spin_unlock(&sbi->ll_process_lock);
1741 }
1742
1743 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1744 {
1745         struct timespec64 now;
1746         struct ll_sb_info *sbi = seq->private;
1747         struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
1748         struct ll_rw_process_info *process = sbi->ll_rw_process_info;
1749         int i;
1750
1751         ktime_get_real_ts64(&now);
1752
1753         if (!sbi->ll_rw_stats_on) {
1754                 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
1755                 return 0;
1756         }
1757         spin_lock(&sbi->ll_process_lock);
1758
1759         seq_printf(seq, "snapshot_time:         %llu.%09lu (secs.nsecs)\n",
1760                    (s64)now.tv_sec, now.tv_nsec);
1761         seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
1762                    "R/W", "PID", "RANGE START", "RANGE END",
1763                    "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
1764
1765         /* We stored the discontiguous offsets here; print them first */
1766         for (i = 0; i < LL_OFFSET_HIST_MAX; i++) {
1767                 if (offset[i].rw_pid != 0)
1768                         seq_printf(seq,
1769                                    "%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1770                                    offset[i].rw_op == READ ? 'R' : 'W',
1771                                    offset[i].rw_pid,
1772                                    offset[i].rw_range_start,
1773                                    offset[i].rw_range_end,
1774                                    (unsigned long)offset[i].rw_smallest_extent,
1775                                    (unsigned long)offset[i].rw_largest_extent,
1776                                    offset[i].rw_offset);
1777         }
1778
1779         /* Then print the current offsets for each process */
1780         for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1781                 if (process[i].rw_pid != 0)
1782                         seq_printf(seq,
1783                                    "%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1784                                    process[i].rw_op == READ ? 'R' : 'W',
1785                                    process[i].rw_pid,
1786                                    process[i].rw_range_start,
1787                                    process[i].rw_last_file_pos,
1788                                    (unsigned long)process[i].rw_smallest_extent,
1789                                    (unsigned long)process[i].rw_largest_extent,
1790                                    process[i].rw_offset);
1791         }
1792         spin_unlock(&sbi->ll_process_lock);
1793
1794         return 0;
1795 }
1796
1797 static ssize_t ll_rw_offset_stats_seq_write(struct file *file,
1798                                             const char __user *buf,
1799                                             size_t len, loff_t *off)
1800 {
1801         struct seq_file *seq = file->private_data;
1802         struct ll_sb_info *sbi = seq->private;
1803         struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
1804         struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
1805         __s64 value;
1806
1807         if (len == 0)
1808                 return -EINVAL;
1809
1810         value = ll_stats_pid_write(buf, len);
1811
1812         if (value == 0)
1813                 sbi->ll_rw_stats_on = 0;
1814         else
1815                 sbi->ll_rw_stats_on = 1;
1816
1817         spin_lock(&sbi->ll_process_lock);
1818         sbi->ll_offset_process_count = 0;
1819         sbi->ll_rw_offset_entry_count = 0;
1820         memset(process_info, 0, sizeof(struct ll_rw_process_info) *
1821                LL_PROCESS_HIST_MAX);
1822         memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
1823                LL_OFFSET_HIST_MAX);
1824         spin_unlock(&sbi->ll_process_lock);
1825
1826         return len;
1827 }
1828
1829 /**
1830  * ll_stats_pid_write() - Determine if stats collection should be enabled
1831  * @buf: Buffer containing the data written
1832  * @len: Number of bytes in the buffer
1833  *
1834  * Several proc files begin collecting stats when a value is written, and stop
1835  * collecting when either '0' or 'disable' is written. This function checks the
1836  * written value to see if collection should be enabled or disabled.
1837  *
1838  * Return: If '0' or 'disable' is provided, 0 is returned. If the text
1839  * equivalent of a number is written, that number is returned. Otherwise,
1840  * 1 is returned. Non-zero return values indicate collection should be enabled.
1841  */
1842 static __s64 ll_stats_pid_write(const char __user *buf, size_t len)
1843 {
1844         unsigned long long value = 1;
1845         int rc;
1846         char kernbuf[16];
1847
1848         rc = kstrtoull_from_user(buf, len, 0, &value);
1849         if (rc < 0 && len < sizeof(kernbuf)) {
1850
1851                 if (copy_from_user(kernbuf, buf, len))
1852                         return -EFAULT;
1853                 kernbuf[len] = 0;
1854
1855                 if (kernbuf[len - 1] == '\n')
1856                         kernbuf[len - 1] = 0;
1857
1858                 if (strncasecmp(kernbuf, "disable", 7) == 0)
1859                         value = 0;
1860         }
1861
1862         return value;
1863 }
1864
1865 LPROC_SEQ_FOPS(ll_rw_offset_stats);
1866 #endif /* CONFIG_PROC_FS */