Whamcloud - gitweb
50fd29d5d1178ae840a9731c3149a28259bcf208
[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  */
31 #define DEBUG_SUBSYSTEM S_LLITE
32
33 #include <linux/version.h>
34 #include <linux/user_namespace.h>
35 #include <linux/uidgid.h>
36
37 #include <uapi/linux/lustre/lustre_param.h>
38 #include <lprocfs_status.h>
39 #include <obd_support.h>
40
41 #include "llite_internal.h"
42 #include "vvp_internal.h"
43
44 static struct kobject *llite_kobj;
45 static struct dentry *llite_root;
46
47 static void llite_kobj_release(struct kobject *kobj)
48 {
49         if (!IS_ERR_OR_NULL(llite_root)) {
50                 debugfs_remove(llite_root);
51                 llite_root = NULL;
52         }
53
54         kfree(kobj);
55 }
56
57 static struct kobj_type llite_kobj_ktype = {
58         .release        = llite_kobj_release,
59         .sysfs_ops      = &lustre_sysfs_ops,
60 };
61
62 int llite_tunables_register(void)
63 {
64         int rc;
65
66         llite_kobj = kzalloc(sizeof(*llite_kobj), GFP_KERNEL);
67         if (!llite_kobj)
68                 return -ENOMEM;
69
70         llite_kobj->kset = lustre_kset;
71         rc = kobject_init_and_add(llite_kobj, &llite_kobj_ktype,
72                                   &lustre_kset->kobj, "%s", "llite");
73         if (rc)
74                 goto free_kobj;
75
76         llite_root = debugfs_create_dir("llite", debugfs_lustre_root);
77         return 0;
78
79 free_kobj:
80         kobject_put(llite_kobj);
81         llite_kobj = NULL;
82
83         return rc;
84 }
85
86 void llite_tunables_unregister(void)
87 {
88         kobject_put(llite_kobj);
89         llite_kobj = NULL;
90 }
91
92 /* <debugfs>/lustre/llite mount point registration */
93 static const struct file_operations ll_rw_extents_stats_fops;
94 static const struct file_operations ll_rw_extents_stats_pp_fops;
95 static const struct file_operations ll_rw_offset_stats_fops;
96
97 /**
98  * ll_stats_pid_write() - Determine if stats collection should be enabled
99  * @buf: Buffer containing the data written
100  * @len: Number of bytes in the buffer
101  *
102  * Several proc files begin collecting stats when a value is written, and stop
103  * collecting when either '0' or 'disable' is written. This function checks the
104  * written value to see if collection should be enabled or disabled.
105  *
106  * Return: If '0' or 'disable' is provided, 0 is returned. If the text
107  * equivalent of a number is written, that number is returned. Otherwise,
108  * 1 is returned. Non-zero return values indicate collection should be enabled.
109  */
110 static s64 ll_stats_pid_write(const char __user *buf, size_t len)
111 {
112         unsigned long long value = 1;
113         char kernbuf[16];
114         int rc;
115
116         rc = kstrtoull_from_user(buf, len, 0, &value);
117         if (rc < 0 && len < sizeof(kernbuf)) {
118                 if (copy_from_user(kernbuf, buf, len))
119                         return -EFAULT;
120                 kernbuf[len] = 0;
121
122                 if (kernbuf[len - 1] == '\n')
123                         kernbuf[len - 1] = 0;
124
125                 if (strncasecmp(kernbuf, "disable", 7) == 0)
126                         value = 0;
127         }
128
129         return value;
130 }
131
132 static ssize_t blocksize_show(struct kobject *kobj, struct attribute *attr,
133                               char *buf)
134 {
135         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
136                                               ll_kset.kobj);
137         struct obd_statfs osfs;
138         int rc;
139
140         rc = ll_statfs_internal(sbi, &osfs, OBD_STATFS_NODELAY);
141         if (rc)
142                 return rc;
143
144         return sprintf(buf, "%u\n", osfs.os_bsize);
145 }
146 LUSTRE_RO_ATTR(blocksize);
147
148 static ssize_t stat_blocksize_show(struct kobject *kobj, struct attribute *attr,
149                                    char *buf)
150 {
151         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
152                                               ll_kset.kobj);
153
154         return sprintf(buf, "%u\n", sbi->ll_stat_blksize);
155 }
156
157 static ssize_t stat_blocksize_store(struct kobject *kobj,
158                                     struct attribute *attr,
159                                     const char *buffer,
160                                     size_t count)
161 {
162         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
163                                               ll_kset.kobj);
164         unsigned int val;
165         int rc;
166
167         rc = kstrtouint(buffer, 10, &val);
168         if (rc)
169                 return rc;
170
171         if (val != 0 && (val < PAGE_SIZE || (val & (val - 1))) != 0)
172                 return -ERANGE;
173
174         sbi->ll_stat_blksize = val;
175
176         return count;
177 }
178 LUSTRE_RW_ATTR(stat_blocksize);
179
180 static ssize_t kbytestotal_show(struct kobject *kobj, struct attribute *attr,
181                                 char *buf)
182 {
183         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
184                                               ll_kset.kobj);
185         struct obd_statfs osfs;
186         u32 blk_size;
187         u64 result;
188         int rc;
189
190         rc = ll_statfs_internal(sbi, &osfs, OBD_STATFS_NODELAY);
191         if (rc)
192                 return rc;
193
194         blk_size = osfs.os_bsize >> 10;
195         result = osfs.os_blocks;
196
197         while (blk_size >>= 1)
198                 result <<= 1;
199
200         return sprintf(buf, "%llu\n", result);
201 }
202 LUSTRE_RO_ATTR(kbytestotal);
203
204 static ssize_t kbytesfree_show(struct kobject *kobj, struct attribute *attr,
205                                char *buf)
206 {
207         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
208                                               ll_kset.kobj);
209         struct obd_statfs osfs;
210         u32 blk_size;
211         u64 result;
212         int rc;
213
214         rc = ll_statfs_internal(sbi, &osfs, OBD_STATFS_NODELAY);
215         if (rc)
216                 return rc;
217
218         blk_size = osfs.os_bsize >> 10;
219         result = osfs.os_bfree;
220
221         while (blk_size >>= 1)
222                 result <<= 1;
223
224         return sprintf(buf, "%llu\n", result);
225 }
226 LUSTRE_RO_ATTR(kbytesfree);
227
228 static ssize_t kbytesavail_show(struct kobject *kobj, struct attribute *attr,
229                                 char *buf)
230 {
231         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
232                                               ll_kset.kobj);
233         struct obd_statfs osfs;
234         u32 blk_size;
235         u64 result;
236         int rc;
237
238         rc = ll_statfs_internal(sbi, &osfs, OBD_STATFS_NODELAY);
239         if (rc)
240                 return rc;
241
242         blk_size = osfs.os_bsize >> 10;
243         result = osfs.os_bavail;
244
245         while (blk_size >>= 1)
246                 result <<= 1;
247
248         return sprintf(buf, "%llu\n", result);
249 }
250 LUSTRE_RO_ATTR(kbytesavail);
251
252 static ssize_t filestotal_show(struct kobject *kobj, struct attribute *attr,
253                                char *buf)
254 {
255         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
256                                               ll_kset.kobj);
257         struct obd_statfs osfs;
258         int rc;
259
260         rc = ll_statfs_internal(sbi, &osfs, OBD_STATFS_NODELAY);
261         if (rc)
262                 return rc;
263
264         return sprintf(buf, "%llu\n", osfs.os_files);
265 }
266 LUSTRE_RO_ATTR(filestotal);
267
268 static ssize_t filesfree_show(struct kobject *kobj, struct attribute *attr,
269                               char *buf)
270 {
271         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
272                                               ll_kset.kobj);
273         struct obd_statfs osfs;
274         int rc;
275
276         rc = ll_statfs_internal(sbi, &osfs, OBD_STATFS_NODELAY);
277         if (rc)
278                 return rc;
279
280         return sprintf(buf, "%llu\n", osfs.os_ffree);
281 }
282 LUSTRE_RO_ATTR(filesfree);
283
284 static ssize_t client_type_show(struct kobject *kobj, struct attribute *attr,
285                                 char *buf)
286 {
287         return sprintf(buf, "local client\n");
288 }
289 LUSTRE_RO_ATTR(client_type);
290
291 LUSTRE_RW_ATTR(foreign_symlink_enable);
292
293 LUSTRE_RW_ATTR(foreign_symlink_prefix);
294
295 LUSTRE_RW_ATTR(foreign_symlink_upcall);
296
297 LUSTRE_WO_ATTR(foreign_symlink_upcall_info);
298
299 static ssize_t fstype_show(struct kobject *kobj, struct attribute *attr,
300                            char *buf)
301 {
302         return sprintf(buf, "lustre\n");
303 }
304 LUSTRE_RO_ATTR(fstype);
305
306 static ssize_t uuid_show(struct kobject *kobj, struct attribute *attr,
307                          char *buf)
308 {
309         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
310                                               ll_kset.kobj);
311
312         return sprintf(buf, "%s\n", sbi->ll_sb_uuid.uuid);
313 }
314 LUSTRE_RO_ATTR(uuid);
315
316 static int ll_site_stats_seq_show(struct seq_file *m, void *v)
317 {
318         struct super_block *sb = m->private;
319
320         /*
321          * See description of statistical counters in struct cl_site, and
322          * struct lu_site.
323          */
324         return cl_site_stats_print(lu2cl_site(ll_s2sbi(sb)->ll_site), m);
325 }
326
327 LDEBUGFS_SEQ_FOPS_RO(ll_site_stats);
328
329 static ssize_t max_read_ahead_mb_show(struct kobject *kobj,
330                                       struct attribute *attr, char *buf)
331 {
332         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
333                                               ll_kset.kobj);
334
335         return scnprintf(buf, PAGE_SIZE, "%lu\n",
336                         PAGES_TO_MiB(sbi->ll_ra_info.ra_max_pages));
337 }
338
339 static ssize_t max_read_ahead_mb_store(struct kobject *kobj,
340                                        struct attribute *attr,
341                                        const char *buffer, size_t count)
342 {
343         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
344                                               ll_kset.kobj);
345         u64 ra_max_mb, pages_number;
346         int rc;
347
348         rc = sysfs_memparse(buffer, count, &ra_max_mb, "MiB");
349         if (rc)
350                 return rc;
351
352         pages_number = round_up(ra_max_mb, 1024 * 1024) >> PAGE_SHIFT;
353         CDEBUG(D_INFO, "%s: set max_read_ahead_mb=%llu (%llu pages)\n",
354                sbi->ll_fsname, PAGES_TO_MiB(pages_number), pages_number);
355         if (pages_number > cfs_totalram_pages() / 2) {
356                 /* 1/2 of RAM */
357                 CERROR("%s: cannot set max_read_ahead_mb=%llu > totalram/2=%luMB\n",
358                        sbi->ll_fsname, PAGES_TO_MiB(pages_number),
359                        PAGES_TO_MiB(cfs_totalram_pages() / 2));
360                 return -ERANGE;
361         }
362
363         spin_lock(&sbi->ll_lock);
364         sbi->ll_ra_info.ra_max_pages = pages_number;
365         spin_unlock(&sbi->ll_lock);
366
367         return count;
368 }
369 LUSTRE_RW_ATTR(max_read_ahead_mb);
370
371 static ssize_t max_read_ahead_per_file_mb_show(struct kobject *kobj,
372                                                struct attribute *attr,
373                                                char *buf)
374 {
375         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
376                                               ll_kset.kobj);
377
378         return scnprintf(buf, PAGE_SIZE, "%lu\n",
379                          PAGES_TO_MiB(sbi->ll_ra_info.ra_max_pages_per_file));
380 }
381
382 static ssize_t max_read_ahead_per_file_mb_store(struct kobject *kobj,
383                                                 struct attribute *attr,
384                                                 const char *buffer,
385                                                 size_t count)
386 {
387         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
388                                               ll_kset.kobj);
389         u64 ra_max_file_mb, pages_number;
390         int rc;
391
392         rc = sysfs_memparse(buffer, count, &ra_max_file_mb, "MiB");
393         if (rc)
394                 return rc;
395
396         pages_number = round_up(ra_max_file_mb, 1024 * 1024) >> PAGE_SHIFT;
397         if (pages_number > sbi->ll_ra_info.ra_max_pages) {
398                 CERROR("%s: cannot set max_read_ahead_per_file_mb=%llu > max_read_ahead_mb=%lu\n",
399                        sbi->ll_fsname, PAGES_TO_MiB(pages_number),
400                        PAGES_TO_MiB(sbi->ll_ra_info.ra_max_pages));
401                 return -ERANGE;
402         }
403
404         spin_lock(&sbi->ll_lock);
405         sbi->ll_ra_info.ra_max_pages_per_file = pages_number;
406         spin_unlock(&sbi->ll_lock);
407
408         return count;
409 }
410 LUSTRE_RW_ATTR(max_read_ahead_per_file_mb);
411
412 static ssize_t max_read_ahead_whole_mb_show(struct kobject *kobj,
413                                             struct attribute *attr, char *buf)
414 {
415         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
416                                               ll_kset.kobj);
417
418         return scnprintf(buf, PAGE_SIZE, "%lu\n",
419                          PAGES_TO_MiB(sbi->ll_ra_info.ra_max_read_ahead_whole_pages));
420 }
421
422 static ssize_t max_read_ahead_whole_mb_store(struct kobject *kobj,
423                                              struct attribute *attr,
424                                              const char *buffer, size_t count)
425 {
426         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
427                                               ll_kset.kobj);
428         u64 ra_max_whole_mb, pages_number;
429         int rc;
430
431         rc = sysfs_memparse(buffer, count, &ra_max_whole_mb, "MiB");
432         if (rc)
433                 return rc;
434
435         pages_number = round_up(ra_max_whole_mb, 1024 * 1024) >> PAGE_SHIFT;
436         /* Cap this at the current max readahead window size, the readahead
437          * algorithm does this anyway so it's pointless to set it larger.
438          */
439         if (pages_number > sbi->ll_ra_info.ra_max_pages_per_file) {
440                 CERROR("%s: cannot set max_read_ahead_whole_mb=%llu > max_read_ahead_per_file_mb=%lu\n",
441                        sbi->ll_fsname, PAGES_TO_MiB(pages_number),
442                        PAGES_TO_MiB(sbi->ll_ra_info.ra_max_pages_per_file));
443
444                 return -ERANGE;
445         }
446
447         spin_lock(&sbi->ll_lock);
448         sbi->ll_ra_info.ra_max_read_ahead_whole_pages = pages_number;
449         spin_unlock(&sbi->ll_lock);
450
451         return count;
452 }
453 LUSTRE_RW_ATTR(max_read_ahead_whole_mb);
454
455 static int ll_max_cached_mb_seq_show(struct seq_file *m, void *v)
456 {
457         struct super_block     *sb    = m->private;
458         struct ll_sb_info      *sbi   = ll_s2sbi(sb);
459         struct cl_client_cache *cache = sbi->ll_cache;
460         struct ll_ra_info *ra = &sbi->ll_ra_info;
461         long max_cached_mb;
462         long unused_mb;
463
464         mutex_lock(&cache->ccc_max_cache_mb_lock);
465         max_cached_mb = PAGES_TO_MiB(cache->ccc_lru_max);
466         unused_mb = PAGES_TO_MiB(atomic_long_read(&cache->ccc_lru_left));
467         mutex_unlock(&cache->ccc_max_cache_mb_lock);
468
469         seq_printf(m, "users: %d\n"
470                       "max_cached_mb: %ld\n"
471                       "used_mb: %ld\n"
472                       "unused_mb: %ld\n"
473                       "reclaim_count: %u\n"
474                       "max_read_ahead_mb: %lu\n"
475                       "used_read_ahead_mb: %d\n",
476                    atomic_read(&cache->ccc_users),
477                    max_cached_mb,
478                    max_cached_mb - unused_mb,
479                    unused_mb,
480                    cache->ccc_lru_shrinkers,
481                    PAGES_TO_MiB(ra->ra_max_pages),
482                    PAGES_TO_MiB(atomic_read(&ra->ra_cur_pages)));
483         return 0;
484 }
485
486 static ssize_t ll_max_cached_mb_seq_write(struct file *file,
487                                           const char __user *buffer,
488                                           size_t count, loff_t *off)
489 {
490         struct seq_file *m = file->private_data;
491         struct super_block *sb = m->private;
492         struct ll_sb_info *sbi = ll_s2sbi(sb);
493         struct cl_client_cache *cache = sbi->ll_cache;
494         struct lu_env *env;
495         long diff = 0;
496         long nrpages = 0;
497         __u16 refcheck;
498         u64 pages_number;
499         int rc;
500         char kernbuf[128], *ptr;
501
502         ENTRY;
503         if (count >= sizeof(kernbuf))
504                 RETURN(-EINVAL);
505
506         if (copy_from_user(kernbuf, buffer, count))
507                 RETURN(-EFAULT);
508         kernbuf[count] = '\0';
509
510         ptr = lprocfs_find_named_value(kernbuf, "max_cached_mb:", &count);
511         rc = sysfs_memparse(ptr, count, &pages_number, "MiB");
512         if (rc)
513                 RETURN(rc);
514
515         pages_number >>= PAGE_SHIFT;
516
517         if (pages_number < 0 || pages_number > cfs_totalram_pages()) {
518                 CERROR("%s: can't set max cache more than %lu MB\n",
519                        sbi->ll_fsname,
520                        PAGES_TO_MiB(cfs_totalram_pages()));
521                 RETURN(-ERANGE);
522         }
523         /* Allow enough cache so clients can make well-formed RPCs */
524         pages_number = max_t(long, pages_number, PTLRPC_MAX_BRW_PAGES);
525
526         mutex_lock(&cache->ccc_max_cache_mb_lock);
527         diff = pages_number - cache->ccc_lru_max;
528
529         /* easy - add more LRU slots. */
530         if (diff >= 0) {
531                 atomic_long_add(diff, &cache->ccc_lru_left);
532                 GOTO(out, rc = 0);
533         }
534
535         env = cl_env_get(&refcheck);
536         if (IS_ERR(env))
537                 GOTO(out_unlock, rc = PTR_ERR(env));
538
539         diff = -diff;
540         while (diff > 0) {
541                 long tmp;
542
543                 /* reduce LRU budget from free slots. */
544                 do {
545                         long lru_left_old, lru_left_new, lru_left_ret;
546
547                         lru_left_old = atomic_long_read(&cache->ccc_lru_left);
548                         if (lru_left_old == 0)
549                                 break;
550
551                         lru_left_new = lru_left_old > diff ?
552                                         lru_left_old - diff : 0;
553                         lru_left_ret =
554                                 atomic_long_cmpxchg(&cache->ccc_lru_left,
555                                                     lru_left_old,
556                                                     lru_left_new);
557                         if (likely(lru_left_old == lru_left_ret)) {
558                                 diff -= lru_left_old - lru_left_new;
559                                 nrpages += lru_left_old - lru_left_new;
560                                 break;
561                         }
562                 } while (1);
563
564                 if (diff <= 0)
565                         break;
566
567                 if (sbi->ll_dt_exp == NULL) { /* being initialized */
568                         rc = -ENODEV;
569                         break;
570                 }
571
572                 /* Request extra free slots to avoid them all being used
573                  * by other processes before this can continue shrinking.
574                  */
575                 tmp = diff + min_t(long, diff, MiB_TO_PAGES(1024));
576                 /* difficult - have to ask OSCs to drop LRU slots. */
577                 rc = obd_set_info_async(env, sbi->ll_dt_exp,
578                                 sizeof(KEY_CACHE_LRU_SHRINK),
579                                 KEY_CACHE_LRU_SHRINK,
580                                 sizeof(tmp), &tmp, NULL);
581                 if (rc < 0)
582                         break;
583         }
584         cl_env_put(env, &refcheck);
585
586 out:
587         if (rc >= 0) {
588                 cache->ccc_lru_max = pages_number;
589                 rc = count;
590         } else {
591                 atomic_long_add(nrpages, &cache->ccc_lru_left);
592         }
593 out_unlock:
594         mutex_unlock(&cache->ccc_max_cache_mb_lock);
595         return rc;
596 }
597 LDEBUGFS_SEQ_FOPS(ll_max_cached_mb);
598
599 static ssize_t checksums_show(struct kobject *kobj, struct attribute *attr,
600                               char *buf)
601 {
602         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
603                                               ll_kset.kobj);
604
605         return scnprintf(buf, PAGE_SIZE, "%u\n",
606                          test_bit(LL_SBI_CHECKSUM, sbi->ll_flags));
607 }
608
609 static ssize_t checksums_store(struct kobject *kobj, struct attribute *attr,
610                                const char *buffer, size_t count)
611 {
612         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
613                                               ll_kset.kobj);
614         bool val;
615         int tmp;
616         int rc;
617
618         if (!sbi->ll_dt_exp)
619                 /* Not set up yet */
620                 return -EAGAIN;
621
622         rc = kstrtobool(buffer, &val);
623         if (rc)
624                 return rc;
625         if (val)
626                 set_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
627         else
628                 clear_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
629         tmp = val;
630
631         rc = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
632                                 KEY_CHECKSUM, sizeof(tmp), &tmp, NULL);
633         if (rc)
634                 CWARN("Failed to set OSC checksum flags: %d\n", rc);
635
636         return count;
637 }
638 LUSTRE_RW_ATTR(checksums);
639
640 LUSTRE_ATTR(checksum_pages, 0644, checksums_show, checksums_store);
641
642 static ssize_t ll_rd_track_id(struct kobject *kobj, char *buf,
643                               enum stats_track_type type)
644 {
645         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
646                                               ll_kset.kobj);
647
648         if (sbi->ll_stats_track_type == type)
649                 return sprintf(buf, "%d\n", sbi->ll_stats_track_id);
650         else if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
651                 return sprintf(buf, "0 (all)\n");
652
653         return sprintf(buf, "untracked\n");
654 }
655
656 static ssize_t ll_wr_track_id(struct kobject *kobj, const char *buffer,
657                               size_t count, enum stats_track_type type)
658 {
659         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
660                                               ll_kset.kobj);
661         unsigned long pid;
662         int rc;
663
664         rc = kstrtoul(buffer, 10, &pid);
665         if (rc)
666                 return rc;
667
668         sbi->ll_stats_track_id = pid;
669         if (pid == 0)
670                 sbi->ll_stats_track_type = STATS_TRACK_ALL;
671         else
672                 sbi->ll_stats_track_type = type;
673         lprocfs_clear_stats(sbi->ll_stats);
674         return count;
675 }
676
677 static ssize_t stats_track_pid_show(struct kobject *kobj,
678                                     struct attribute *attr,
679                                     char *buf)
680 {
681         return ll_rd_track_id(kobj, buf, STATS_TRACK_PID);
682 }
683
684 static ssize_t stats_track_pid_store(struct kobject *kobj,
685                                      struct attribute *attr,
686                                      const char *buffer,
687                                      size_t count)
688 {
689         return ll_wr_track_id(kobj, buffer, count, STATS_TRACK_PID);
690 }
691 LUSTRE_RW_ATTR(stats_track_pid);
692
693 static ssize_t stats_track_ppid_show(struct kobject *kobj,
694                                      struct attribute *attr,
695                                      char *buf)
696 {
697         return ll_rd_track_id(kobj, buf, STATS_TRACK_PPID);
698 }
699
700 static ssize_t stats_track_ppid_store(struct kobject *kobj,
701                                       struct attribute *attr,
702                                       const char *buffer,
703                                       size_t count)
704 {
705         return ll_wr_track_id(kobj, buffer, count, STATS_TRACK_PPID);
706 }
707 LUSTRE_RW_ATTR(stats_track_ppid);
708
709 static ssize_t stats_track_gid_show(struct kobject *kobj,
710                                     struct attribute *attr,
711                                     char *buf)
712 {
713         return ll_rd_track_id(kobj, buf, STATS_TRACK_GID);
714 }
715
716 static ssize_t stats_track_gid_store(struct kobject *kobj,
717                                      struct attribute *attr,
718                                      const char *buffer,
719                                      size_t count)
720 {
721         return ll_wr_track_id(kobj, buffer, count, STATS_TRACK_GID);
722 }
723 LUSTRE_RW_ATTR(stats_track_gid);
724
725 static ssize_t statahead_running_max_show(struct kobject *kobj,
726                                           struct attribute *attr,
727                                           char *buf)
728 {
729         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
730                                               ll_kset.kobj);
731
732         return scnprintf(buf, PAGE_SIZE, "%u\n", sbi->ll_sa_running_max);
733 }
734
735 static ssize_t statahead_running_max_store(struct kobject *kobj,
736                                            struct attribute *attr,
737                                            const char *buffer,
738                                            size_t count)
739 {
740         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
741                                               ll_kset.kobj);
742         unsigned long val;
743         int rc;
744
745         rc = kstrtoul(buffer, 0, &val);
746         if (rc)
747                 return rc;
748
749         if (val <= LL_SA_RUNNING_MAX) {
750                 sbi->ll_sa_running_max = val;
751                 return count;
752         }
753
754         CERROR("Bad statahead_running_max value %lu. Valid values "
755                "are in the range [0, %d]\n", val, LL_SA_RUNNING_MAX);
756
757         return -ERANGE;
758 }
759 LUSTRE_RW_ATTR(statahead_running_max);
760
761 static ssize_t statahead_max_show(struct kobject *kobj,
762                                   struct attribute *attr,
763                                   char *buf)
764 {
765         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
766                                               ll_kset.kobj);
767
768         return sprintf(buf, "%u\n", sbi->ll_sa_max);
769 }
770
771 static ssize_t statahead_max_store(struct kobject *kobj,
772                                    struct attribute *attr,
773                                    const char *buffer,
774                                    size_t count)
775 {
776         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
777                                               ll_kset.kobj);
778         unsigned long val;
779         int rc;
780
781         rc = kstrtoul(buffer, 0, &val);
782         if (rc)
783                 return rc;
784
785         if (val <= LL_SA_RPC_MAX)
786                 sbi->ll_sa_max = val;
787         else
788                 CERROR("Bad statahead_max value %lu. Valid values are in the range [0, %d]\n",
789                        val, LL_SA_RPC_MAX);
790
791         return count;
792 }
793 LUSTRE_RW_ATTR(statahead_max);
794
795 static ssize_t statahead_agl_show(struct kobject *kobj,
796                                   struct attribute *attr,
797                                   char *buf)
798 {
799         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
800                                               ll_kset.kobj);
801
802         return scnprintf(buf, PAGE_SIZE, "%u\n",
803                          test_bit(LL_SBI_AGL_ENABLED, sbi->ll_flags));
804 }
805
806 static ssize_t statahead_agl_store(struct kobject *kobj,
807                                    struct attribute *attr,
808                                    const char *buffer,
809                                    size_t count)
810 {
811         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
812                                               ll_kset.kobj);
813         bool val;
814         int rc;
815
816         rc = kstrtobool(buffer, &val);
817         if (rc)
818                 return rc;
819
820         if (val)
821                 set_bit(LL_SBI_AGL_ENABLED, sbi->ll_flags);
822         else
823                 clear_bit(LL_SBI_AGL_ENABLED, sbi->ll_flags);
824
825         return count;
826 }
827 LUSTRE_RW_ATTR(statahead_agl);
828
829 static int ll_statahead_stats_seq_show(struct seq_file *m, void *v)
830 {
831         struct super_block *sb = m->private;
832         struct ll_sb_info *sbi = ll_s2sbi(sb);
833
834         seq_printf(m, "statahead total: %u\n"
835                       "statahead wrong: %u\n"
836                       "agl total: %u\n"
837                       "hit_total: %u\n"
838                       "miss_total: %u\n",
839                    atomic_read(&sbi->ll_sa_total),
840                    atomic_read(&sbi->ll_sa_wrong),
841                    atomic_read(&sbi->ll_agl_total),
842                    atomic_read(&sbi->ll_sa_hit_total),
843                    atomic_read(&sbi->ll_sa_miss_total));
844         return 0;
845 }
846
847 static ssize_t ll_statahead_stats_seq_write(struct file *file,
848                                             const char __user *buffer,
849                                             size_t count, loff_t *off)
850 {
851         struct seq_file *m = file->private_data;
852         struct super_block *sb = m->private;
853         struct ll_sb_info *sbi = ll_s2sbi(sb);
854
855         atomic_set(&sbi->ll_sa_total, 0);
856         atomic_set(&sbi->ll_sa_wrong, 0);
857         atomic_set(&sbi->ll_agl_total, 0);
858         atomic_set(&sbi->ll_sa_hit_total, 0);
859         atomic_set(&sbi->ll_sa_miss_total, 0);
860
861         return count;
862 }
863 LDEBUGFS_SEQ_FOPS(ll_statahead_stats);
864
865 static ssize_t lazystatfs_show(struct kobject *kobj,
866                                struct attribute *attr,
867                                char *buf)
868 {
869         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
870                                               ll_kset.kobj);
871
872         return scnprintf(buf, PAGE_SIZE, "%u\n",
873                          test_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags));
874 }
875
876 static ssize_t lazystatfs_store(struct kobject *kobj,
877                                 struct attribute *attr,
878                                 const char *buffer,
879                                 size_t count)
880 {
881         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
882                                               ll_kset.kobj);
883         bool val;
884         int rc;
885
886         rc = kstrtobool(buffer, &val);
887         if (rc)
888                 return rc;
889
890         if (val)
891                 set_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags);
892         else
893                 clear_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags);
894
895         return count;
896 }
897 LUSTRE_RW_ATTR(lazystatfs);
898
899 static ssize_t statfs_max_age_show(struct kobject *kobj, struct attribute *attr,
900                                    char *buf)
901 {
902         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
903                                               ll_kset.kobj);
904
905         return scnprintf(buf, PAGE_SIZE, "%u\n", sbi->ll_statfs_max_age);
906 }
907
908 static ssize_t statfs_max_age_store(struct kobject *kobj,
909                                     struct attribute *attr, const char *buffer,
910                                     size_t count)
911 {
912         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
913                                               ll_kset.kobj);
914         unsigned int val;
915         int rc;
916
917         rc = kstrtouint(buffer, 10, &val);
918         if (rc)
919                 return rc;
920         if (val > OBD_STATFS_CACHE_MAX_AGE)
921                 return -EINVAL;
922
923         sbi->ll_statfs_max_age = val;
924
925         return count;
926 }
927 LUSTRE_RW_ATTR(statfs_max_age);
928
929 static ssize_t max_easize_show(struct kobject *kobj,
930                                struct attribute *attr,
931                                char *buf)
932 {
933         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
934                                               ll_kset.kobj);
935         unsigned int ealen;
936         int rc;
937
938         rc = ll_get_max_mdsize(sbi, &ealen);
939         if (rc)
940                 return rc;
941
942         /* Limit xattr size returned to userspace based on kernel maximum */
943         return scnprintf(buf, PAGE_SIZE, "%u\n",
944                          ealen > XATTR_SIZE_MAX ? XATTR_SIZE_MAX : ealen);
945 }
946 LUSTRE_RO_ATTR(max_easize);
947
948 /**
949  * Get default_easize.
950  *
951  * \see client_obd::cl_default_mds_easize
952  *
953  * \param[in] m         seq_file handle
954  * \param[in] v         unused for single entry
955  *
956  * \retval 0            on success
957  * \retval negative     negated errno on failure
958  */
959 static ssize_t default_easize_show(struct kobject *kobj,
960                                    struct attribute *attr,
961                                    char *buf)
962 {
963         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
964                                               ll_kset.kobj);
965         unsigned int ealen;
966         int rc;
967
968         rc = ll_get_default_mdsize(sbi, &ealen);
969         if (rc)
970                 return rc;
971
972         /* Limit xattr size returned to userspace based on kernel maximum */
973         return scnprintf(buf, PAGE_SIZE, "%u\n",
974                          ealen > XATTR_SIZE_MAX ? XATTR_SIZE_MAX : ealen);
975 }
976
977 /**
978  * Set default_easize.
979  *
980  * Range checking on the passed value is handled by
981  * ll_set_default_mdsize().
982  *
983  * \see client_obd::cl_default_mds_easize
984  *
985  * \param[in] file      proc file
986  * \param[in] buffer    string passed from user space
987  * \param[in] count     \a buffer length
988  * \param[in] off       unused for single entry
989  *
990  * \retval positive     \a count on success
991  * \retval negative     negated errno on failure
992  */
993 static ssize_t default_easize_store(struct kobject *kobj,
994                                     struct attribute *attr,
995                                     const char *buffer,
996                                     size_t count)
997 {
998         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
999                                               ll_kset.kobj);
1000         unsigned int val;
1001         int rc;
1002
1003         if (count == 0)
1004                 return 0;
1005
1006         rc = kstrtouint(buffer, 10, &val);
1007         if (rc)
1008                 return rc;
1009
1010         rc = ll_set_default_mdsize(sbi, val);
1011         if (rc)
1012                 return rc;
1013
1014         return count;
1015 }
1016 LUSTRE_RW_ATTR(default_easize);
1017
1018 LDEBUGFS_SEQ_FOPS_RO(ll_sbi_flags);
1019
1020 static ssize_t xattr_cache_show(struct kobject *kobj,
1021                                 struct attribute *attr,
1022                                 char *buf)
1023 {
1024         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1025                                               ll_kset.kobj);
1026
1027         return sprintf(buf, "%u\n", sbi->ll_xattr_cache_enabled);
1028 }
1029
1030 static ssize_t xattr_cache_store(struct kobject *kobj,
1031                                  struct attribute *attr,
1032                                  const char *buffer,
1033                                  size_t count)
1034 {
1035         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1036                                               ll_kset.kobj);
1037         bool val;
1038         int rc;
1039
1040         rc = kstrtobool(buffer, &val);
1041         if (rc)
1042                 return rc;
1043
1044         if (val && !test_bit(LL_SBI_XATTR_CACHE, sbi->ll_flags))
1045                 return -ENOTSUPP;
1046
1047         sbi->ll_xattr_cache_enabled = val;
1048         sbi->ll_xattr_cache_set = 1;
1049
1050         return count;
1051 }
1052 LUSTRE_RW_ATTR(xattr_cache);
1053
1054 static ssize_t tiny_write_show(struct kobject *kobj,
1055                                struct attribute *attr,
1056                                char *buf)
1057 {
1058         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1059                                               ll_kset.kobj);
1060
1061         return scnprintf(buf, PAGE_SIZE, "%u\n",
1062                          test_bit(LL_SBI_TINY_WRITE, sbi->ll_flags));
1063 }
1064
1065 static ssize_t tiny_write_store(struct kobject *kobj,
1066                                 struct attribute *attr,
1067                                 const char *buffer,
1068                                 size_t count)
1069 {
1070         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1071                                               ll_kset.kobj);
1072         bool val;
1073         int rc;
1074
1075         rc = kstrtobool(buffer, &val);
1076         if (rc)
1077                 return rc;
1078
1079         spin_lock(&sbi->ll_lock);
1080         if (val)
1081                 set_bit(LL_SBI_TINY_WRITE, sbi->ll_flags);
1082         else
1083                 clear_bit(LL_SBI_TINY_WRITE, sbi->ll_flags);
1084         spin_unlock(&sbi->ll_lock);
1085
1086         return count;
1087 }
1088 LUSTRE_RW_ATTR(tiny_write);
1089
1090 static ssize_t parallel_dio_show(struct kobject *kobj,
1091                                  struct attribute *attr,
1092                                  char *buf)
1093 {
1094         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1095                                               ll_kset.kobj);
1096
1097         return snprintf(buf, PAGE_SIZE, "%u\n",
1098                         test_bit(LL_SBI_PARALLEL_DIO, sbi->ll_flags));
1099 }
1100
1101 static ssize_t parallel_dio_store(struct kobject *kobj,
1102                                   struct attribute *attr,
1103                                   const char *buffer,
1104                                   size_t count)
1105 {
1106         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1107                                               ll_kset.kobj);
1108         bool val;
1109         int rc;
1110
1111         rc = kstrtobool(buffer, &val);
1112         if (rc)
1113                 return rc;
1114
1115         spin_lock(&sbi->ll_lock);
1116         if (val)
1117                 set_bit(LL_SBI_PARALLEL_DIO, sbi->ll_flags);
1118         else
1119                 clear_bit(LL_SBI_PARALLEL_DIO, sbi->ll_flags);
1120         spin_unlock(&sbi->ll_lock);
1121
1122         return count;
1123 }
1124 LUSTRE_RW_ATTR(parallel_dio);
1125
1126 static ssize_t max_read_ahead_async_active_show(struct kobject *kobj,
1127                                                struct attribute *attr,
1128                                                char *buf)
1129 {
1130         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1131                                               ll_kset.kobj);
1132
1133         return scnprintf(buf, PAGE_SIZE, "%u\n",
1134                          sbi->ll_ra_info.ra_async_max_active);
1135 }
1136
1137 static ssize_t max_read_ahead_async_active_store(struct kobject *kobj,
1138                                                  struct attribute *attr,
1139                                                  const char *buffer,
1140                                                  size_t count)
1141 {
1142         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1143                                               ll_kset.kobj);
1144         unsigned int val;
1145         int rc;
1146
1147         rc = kstrtouint(buffer, 10, &val);
1148         if (rc)
1149                 return rc;
1150
1151         /**
1152          * It doesn't make any sense to make it exceed what
1153          * workqueue could acutally support. This can easily
1154          * over subscripe the cores but Lustre internally
1155          * throttles to avoid those impacts.
1156          */
1157         if (val > WQ_UNBOUND_MAX_ACTIVE) {
1158                 CERROR("%s: cannot set max_read_ahead_async_active=%u larger than %u\n",
1159                        sbi->ll_fsname, val, WQ_UNBOUND_MAX_ACTIVE);
1160                 return -ERANGE;
1161         }
1162
1163         spin_lock(&sbi->ll_lock);
1164         sbi->ll_ra_info.ra_async_max_active = val;
1165         spin_unlock(&sbi->ll_lock);
1166
1167         return count;
1168 }
1169 LUSTRE_RW_ATTR(max_read_ahead_async_active);
1170
1171 static ssize_t read_ahead_async_file_threshold_mb_show(struct kobject *kobj,
1172                                                        struct attribute *attr,
1173                                                        char *buf)
1174 {
1175         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1176                                               ll_kset.kobj);
1177
1178         return scnprintf(buf, PAGE_SIZE, "%lu\n", PAGES_TO_MiB(
1179                          sbi->ll_ra_info.ra_async_pages_per_file_threshold));
1180 }
1181
1182 static ssize_t
1183 read_ahead_async_file_threshold_mb_store(struct kobject *kobj,
1184                                          struct attribute *attr,
1185                                          const char *buffer, size_t count)
1186 {
1187         unsigned long pages_number;
1188         unsigned long max_ra_per_file;
1189         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1190                                               ll_kset.kobj);
1191         int rc;
1192
1193         rc = kstrtoul(buffer, 10, &pages_number);
1194         if (rc)
1195                 return rc;
1196
1197         pages_number = MiB_TO_PAGES(pages_number);
1198         max_ra_per_file = sbi->ll_ra_info.ra_max_pages_per_file;
1199         if (pages_number < 0 || pages_number > max_ra_per_file) {
1200                 CERROR("%s: can't set read_ahead_async_file_threshold_mb=%lu > "
1201                        "max_read_readahead_per_file_mb=%lu\n", sbi->ll_fsname,
1202                        PAGES_TO_MiB(pages_number),
1203                        PAGES_TO_MiB(max_ra_per_file));
1204                 return -ERANGE;
1205         }
1206         sbi->ll_ra_info.ra_async_pages_per_file_threshold = pages_number;
1207
1208         return count;
1209 }
1210 LUSTRE_RW_ATTR(read_ahead_async_file_threshold_mb);
1211
1212 static ssize_t read_ahead_range_kb_show(struct kobject *kobj,
1213                                         struct attribute *attr,char *buf)
1214 {
1215         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1216                                               ll_kset.kobj);
1217
1218         return snprintf(buf, PAGE_SIZE, "%lu\n",
1219                         sbi->ll_ra_info.ra_range_pages << (PAGE_SHIFT - 10));
1220 }
1221
1222 static ssize_t
1223 read_ahead_range_kb_store(struct kobject *kobj,
1224                                struct attribute *attr,
1225                                const char *buffer, size_t count)
1226 {
1227         unsigned long pages_number;
1228         unsigned long max_ra_per_file;
1229         u64 val;
1230         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1231                                               ll_kset.kobj);
1232         int rc;
1233
1234         rc = sysfs_memparse(buffer, count, &val, "KiB");
1235         if (rc < 0)
1236                 return rc;
1237
1238         pages_number = val >> PAGE_SHIFT;
1239         /* Disable mmap range read */
1240         if (pages_number == 0)
1241                 goto out;
1242
1243         max_ra_per_file = sbi->ll_ra_info.ra_max_pages_per_file;
1244         if (pages_number > max_ra_per_file ||
1245             pages_number < RA_MIN_MMAP_RANGE_PAGES)
1246                 return -ERANGE;
1247
1248 out:
1249         spin_lock(&sbi->ll_lock);
1250         sbi->ll_ra_info.ra_range_pages = pages_number;
1251         spin_unlock(&sbi->ll_lock);
1252
1253         return count;
1254 }
1255 LUSTRE_RW_ATTR(read_ahead_range_kb);
1256
1257 static ssize_t fast_read_show(struct kobject *kobj,
1258                               struct attribute *attr,
1259                               char *buf)
1260 {
1261         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1262                                               ll_kset.kobj);
1263
1264         return scnprintf(buf, PAGE_SIZE, "%u\n",
1265                          test_bit(LL_SBI_FAST_READ, sbi->ll_flags));
1266 }
1267
1268 static ssize_t fast_read_store(struct kobject *kobj,
1269                                struct attribute *attr,
1270                                const char *buffer,
1271                                size_t count)
1272 {
1273         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1274                                               ll_kset.kobj);
1275         bool val;
1276         int rc;
1277
1278         rc = kstrtobool(buffer, &val);
1279         if (rc)
1280                 return rc;
1281
1282         spin_lock(&sbi->ll_lock);
1283         if (val)
1284                 set_bit(LL_SBI_FAST_READ, sbi->ll_flags);
1285         else
1286                 clear_bit(LL_SBI_FAST_READ, sbi->ll_flags);
1287         spin_unlock(&sbi->ll_lock);
1288
1289         return count;
1290 }
1291 LUSTRE_RW_ATTR(fast_read);
1292
1293 static ssize_t file_heat_show(struct kobject *kobj,
1294                               struct attribute *attr,
1295                               char *buf)
1296 {
1297         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1298                                               ll_kset.kobj);
1299
1300         return scnprintf(buf, PAGE_SIZE, "%u\n",
1301                          test_bit(LL_SBI_FILE_HEAT, sbi->ll_flags));
1302 }
1303
1304 static ssize_t file_heat_store(struct kobject *kobj,
1305                                struct attribute *attr,
1306                                const char *buffer,
1307                                size_t count)
1308 {
1309         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1310                                               ll_kset.kobj);
1311         bool val;
1312         int rc;
1313
1314         rc = kstrtobool(buffer, &val);
1315         if (rc)
1316                 return rc;
1317
1318         spin_lock(&sbi->ll_lock);
1319         if (val)
1320                 set_bit(LL_SBI_FILE_HEAT, sbi->ll_flags);
1321         else
1322                 clear_bit(LL_SBI_FILE_HEAT, sbi->ll_flags);
1323         spin_unlock(&sbi->ll_lock);
1324
1325         return count;
1326 }
1327 LUSTRE_RW_ATTR(file_heat);
1328
1329 static ssize_t heat_decay_percentage_show(struct kobject *kobj,
1330                                           struct attribute *attr,
1331                                           char *buf)
1332 {
1333         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1334                                               ll_kset.kobj);
1335
1336         return scnprintf(buf, PAGE_SIZE, "%u\n",
1337                          (sbi->ll_heat_decay_weight * 100 + 128) / 256);
1338 }
1339
1340 static ssize_t heat_decay_percentage_store(struct kobject *kobj,
1341                                            struct attribute *attr,
1342                                            const char *buffer,
1343                                            size_t count)
1344 {
1345         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1346                                               ll_kset.kobj);
1347         unsigned long val;
1348         int rc;
1349
1350         rc = kstrtoul(buffer, 10, &val);
1351         if (rc)
1352                 return rc;
1353
1354         if (val < 0 || val > 100)
1355                 return -ERANGE;
1356
1357         sbi->ll_heat_decay_weight = (val * 256 + 50) / 100;
1358
1359         return count;
1360 }
1361 LUSTRE_RW_ATTR(heat_decay_percentage);
1362
1363 static ssize_t heat_period_second_show(struct kobject *kobj,
1364                                        struct attribute *attr,
1365                                        char *buf)
1366 {
1367         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1368                                               ll_kset.kobj);
1369
1370         return scnprintf(buf, PAGE_SIZE, "%u\n", sbi->ll_heat_period_second);
1371 }
1372
1373 static ssize_t heat_period_second_store(struct kobject *kobj,
1374                                         struct attribute *attr,
1375                                         const char *buffer,
1376                                         size_t count)
1377 {
1378         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1379                                               ll_kset.kobj);
1380         unsigned long val;
1381         int rc;
1382
1383         rc = kstrtoul(buffer, 10, &val);
1384         if (rc)
1385                 return rc;
1386
1387         if (val <= 0)
1388                 return -ERANGE;
1389
1390         sbi->ll_heat_period_second = val;
1391
1392         return count;
1393 }
1394 LUSTRE_RW_ATTR(heat_period_second);
1395
1396 static ssize_t opencache_threshold_count_show(struct kobject *kobj,
1397                                               struct attribute *attr,
1398                                               char *buf)
1399 {
1400         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1401                                               ll_kset.kobj);
1402
1403         if (sbi->ll_oc_thrsh_count)
1404                 return snprintf(buf, PAGE_SIZE, "%u\n",
1405                                 sbi->ll_oc_thrsh_count);
1406         else
1407                 return snprintf(buf, PAGE_SIZE, "off\n");
1408 }
1409
1410 static ssize_t opencache_threshold_count_store(struct kobject *kobj,
1411                                                struct attribute *attr,
1412                                                const char *buffer,
1413                                                size_t count)
1414 {
1415         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1416                                               ll_kset.kobj);
1417         unsigned int val;
1418         int rc;
1419
1420         rc = kstrtouint(buffer, 10, &val);
1421         if (rc) {
1422                 bool enable;
1423                 /* also accept "off" to disable and "on" to always cache */
1424                 rc = kstrtobool(buffer, &enable);
1425                 if (rc)
1426                         return rc;
1427                 val = enable;
1428         }
1429         sbi->ll_oc_thrsh_count = val;
1430
1431         return count;
1432 }
1433 LUSTRE_RW_ATTR(opencache_threshold_count);
1434
1435 static ssize_t opencache_threshold_ms_show(struct kobject *kobj,
1436                                            struct attribute *attr,
1437                                            char *buf)
1438 {
1439         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1440                                               ll_kset.kobj);
1441
1442         return snprintf(buf, PAGE_SIZE, "%u\n", sbi->ll_oc_thrsh_ms);
1443 }
1444
1445 static ssize_t opencache_threshold_ms_store(struct kobject *kobj,
1446                                             struct attribute *attr,
1447                                             const char *buffer,
1448                                             size_t count)
1449 {
1450         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1451                                               ll_kset.kobj);
1452         unsigned int val;
1453         int rc;
1454
1455         rc = kstrtouint(buffer, 10, &val);
1456         if (rc)
1457                 return rc;
1458
1459         sbi->ll_oc_thrsh_ms = val;
1460
1461         return count;
1462 }
1463 LUSTRE_RW_ATTR(opencache_threshold_ms);
1464
1465 static ssize_t opencache_max_ms_show(struct kobject *kobj,
1466                                      struct attribute *attr,
1467                                      char *buf)
1468 {
1469         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1470                                               ll_kset.kobj);
1471
1472         return snprintf(buf, PAGE_SIZE, "%u\n", sbi->ll_oc_max_ms);
1473 }
1474
1475 static ssize_t opencache_max_ms_store(struct kobject *kobj,
1476                                       struct attribute *attr,
1477                                       const char *buffer,
1478                                       size_t count)
1479 {
1480         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1481                                               ll_kset.kobj);
1482         unsigned int val;
1483         int rc;
1484
1485         rc = kstrtouint(buffer, 10, &val);
1486         if (rc)
1487                 return rc;
1488
1489         sbi->ll_oc_max_ms = val;
1490
1491         return count;
1492 }
1493 LUSTRE_RW_ATTR(opencache_max_ms);
1494
1495 static ssize_t inode_cache_show(struct kobject *kobj,
1496                                 struct attribute *attr,
1497                                 char *buf)
1498 {
1499         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1500                                               ll_kset.kobj);
1501
1502         return snprintf(buf, PAGE_SIZE, "%u\n", sbi->ll_inode_cache_enabled);
1503 }
1504
1505 static ssize_t inode_cache_store(struct kobject *kobj,
1506                                  struct attribute *attr,
1507                                  const char *buffer,
1508                                  size_t count)
1509 {
1510         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1511                                               ll_kset.kobj);
1512         bool val;
1513         int rc;
1514
1515         rc = kstrtobool(buffer, &val);
1516         if (rc)
1517                 return rc;
1518
1519         sbi->ll_inode_cache_enabled = val;
1520
1521         return count;
1522 }
1523 LUSTRE_RW_ATTR(inode_cache);
1524
1525 static int ll_unstable_stats_seq_show(struct seq_file *m, void *v)
1526 {
1527         struct super_block      *sb    = m->private;
1528         struct ll_sb_info       *sbi   = ll_s2sbi(sb);
1529         struct cl_client_cache  *cache = sbi->ll_cache;
1530         long pages;
1531         int mb;
1532
1533         pages = atomic_long_read(&cache->ccc_unstable_nr);
1534         mb    = (pages * PAGE_SIZE) >> 20;
1535
1536         seq_printf(m, "unstable_check:     %8d\n"
1537                       "unstable_pages: %12ld\n"
1538                       "unstable_mb:        %8d\n",
1539                    cache->ccc_unstable_check, pages, mb);
1540         return 0;
1541 }
1542
1543 static ssize_t ll_unstable_stats_seq_write(struct file *file,
1544                                            const char __user *buffer,
1545                                            size_t count, loff_t *unused)
1546 {
1547         struct seq_file *seq = file->private_data;
1548         struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)seq->private);
1549         char kernbuf[128];
1550         bool val;
1551         int rc;
1552
1553         if (count == 0)
1554                 return 0;
1555         if (count >= sizeof(kernbuf))
1556                 return -EINVAL;
1557
1558         if (copy_from_user(kernbuf, buffer, count))
1559                 return -EFAULT;
1560         kernbuf[count] = 0;
1561
1562         buffer += lprocfs_find_named_value(kernbuf, "unstable_check:", &count) -
1563                   kernbuf;
1564         rc = kstrtobool_from_user(buffer, count, &val);
1565         if (rc < 0)
1566                 return rc;
1567
1568         /* borrow lru lock to set the value */
1569         spin_lock(&sbi->ll_cache->ccc_lru_lock);
1570         sbi->ll_cache->ccc_unstable_check = val;
1571         spin_unlock(&sbi->ll_cache->ccc_lru_lock);
1572
1573         return count;
1574 }
1575
1576 LDEBUGFS_SEQ_FOPS(ll_unstable_stats);
1577
1578 static int ll_root_squash_seq_show(struct seq_file *m, void *v)
1579 {
1580         struct super_block *sb = m->private;
1581         struct ll_sb_info *sbi = ll_s2sbi(sb);
1582         struct root_squash_info *squash = &sbi->ll_squash;
1583
1584         seq_printf(m, "%u:%u\n", squash->rsi_uid, squash->rsi_gid);
1585         return 0;
1586 }
1587
1588 static ssize_t ll_root_squash_seq_write(struct file *file,
1589                                         const char __user *buffer,
1590                                         size_t count, loff_t *off)
1591 {
1592         struct seq_file *m = file->private_data;
1593         struct super_block *sb = m->private;
1594         struct ll_sb_info *sbi = ll_s2sbi(sb);
1595         struct root_squash_info *squash = &sbi->ll_squash;
1596
1597         return lprocfs_wr_root_squash(buffer, count, squash, sbi->ll_fsname);
1598 }
1599
1600 LDEBUGFS_SEQ_FOPS(ll_root_squash);
1601
1602 static int ll_nosquash_nids_seq_show(struct seq_file *m, void *v)
1603 {
1604         struct super_block *sb = m->private;
1605         struct ll_sb_info *sbi = ll_s2sbi(sb);
1606         struct root_squash_info *squash = &sbi->ll_squash;
1607         int len;
1608
1609         spin_lock(&squash->rsi_lock);
1610         if (!list_empty(&squash->rsi_nosquash_nids)) {
1611                 len = cfs_print_nidlist(m->buf + m->count, m->size - m->count,
1612                                         &squash->rsi_nosquash_nids);
1613                 m->count += len;
1614                 seq_putc(m, '\n');
1615         } else {
1616                 seq_puts(m, "NONE\n");
1617         }
1618         spin_unlock(&squash->rsi_lock);
1619
1620         return 0;
1621 }
1622
1623 static ssize_t ll_nosquash_nids_seq_write(struct file *file,
1624                                           const char __user *buffer,
1625                                           size_t count, loff_t *off)
1626 {
1627         struct seq_file *m = file->private_data;
1628         struct super_block *sb = m->private;
1629         struct ll_sb_info *sbi = ll_s2sbi(sb);
1630         struct root_squash_info *squash = &sbi->ll_squash;
1631         int rc;
1632
1633         rc = lprocfs_wr_nosquash_nids(buffer, count, squash, sbi->ll_fsname);
1634         if (rc < 0)
1635                 return rc;
1636
1637         ll_compute_rootsquash_state(sbi);
1638
1639         return rc;
1640 }
1641
1642 LDEBUGFS_SEQ_FOPS(ll_nosquash_nids);
1643
1644 static int ll_filename_enc_seq_show(struct seq_file *m, void *v)
1645 {
1646         struct super_block *sb = m->private;
1647         struct lustre_sb_info *lsi = s2lsi(sb);
1648
1649         seq_printf(m, "%u\n", lsi->lsi_flags & LSI_FILENAME_ENC ? 1 : 0);
1650         return 0;
1651 }
1652
1653 static ssize_t ll_filename_enc_seq_write(struct file *file,
1654                                          const char __user *buffer,
1655                                          size_t count, loff_t *off)
1656 {
1657         struct seq_file *m = file->private_data;
1658         struct super_block *sb = m->private;
1659         struct lustre_sb_info *lsi = s2lsi(sb);
1660         struct ll_sb_info *sbi = ll_s2sbi(sb);
1661         bool val;
1662         int rc;
1663
1664         rc = kstrtobool_from_user(buffer, count, &val);
1665         if (rc)
1666                 return rc;
1667
1668         if (val) {
1669                 if (!ll_sbi_has_name_encrypt(sbi)) {
1670                         /* server does not support name encryption,
1671                          * so force it to NULL on client
1672                          */
1673                         CDEBUG(D_SEC, "%s: server does not support name encryption\n",
1674                                sbi->ll_fsname);
1675                         lsi->lsi_flags &= ~LSI_FILENAME_ENC;
1676                         return -EOPNOTSUPP;
1677                 }
1678
1679                 lsi->lsi_flags |= LSI_FILENAME_ENC;
1680         } else {
1681                 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
1682         }
1683
1684         return count;
1685 }
1686
1687 LDEBUGFS_SEQ_FOPS(ll_filename_enc);
1688
1689 static int ll_pcc_seq_show(struct seq_file *m, void *v)
1690 {
1691         struct super_block *sb = m->private;
1692         struct ll_sb_info *sbi = ll_s2sbi(sb);
1693
1694         return pcc_super_dump(&sbi->ll_pcc_super, m);
1695 }
1696
1697 static ssize_t ll_pcc_seq_write(struct file *file, const char __user *buffer,
1698                                 size_t count, loff_t *off)
1699 {
1700         struct seq_file *m = file->private_data;
1701         struct super_block *sb = m->private;
1702         struct ll_sb_info *sbi = ll_s2sbi(sb);
1703         int rc;
1704         char *kernbuf;
1705
1706         if (count >= LPROCFS_WR_PCC_MAX_CMD)
1707                 return -EINVAL;
1708
1709         if (!(exp_connect_flags2(sbi->ll_md_exp) & OBD_CONNECT2_PCC))
1710                 return -EOPNOTSUPP;
1711
1712         OBD_ALLOC(kernbuf, count + 1);
1713         if (kernbuf == NULL)
1714                 return -ENOMEM;
1715
1716         if (copy_from_user(kernbuf, buffer, count))
1717                 GOTO(out_free_kernbuff, rc = -EFAULT);
1718
1719         rc = pcc_cmd_handle(kernbuf, count, &sbi->ll_pcc_super);
1720 out_free_kernbuff:
1721         OBD_FREE(kernbuf, count + 1);
1722         return rc ? rc : count;
1723 }
1724 LDEBUGFS_SEQ_FOPS(ll_pcc);
1725
1726 struct ldebugfs_vars lprocfs_llite_obd_vars[] = {
1727         { .name =       "site",
1728           .fops =       &ll_site_stats_fops                     },
1729         { .name =       "max_cached_mb",
1730           .fops =       &ll_max_cached_mb_fops                  },
1731         { .name =       "statahead_stats",
1732           .fops =       &ll_statahead_stats_fops                },
1733         { .name =       "unstable_stats",
1734           .fops =       &ll_unstable_stats_fops                 },
1735         { .name =       "sbi_flags",
1736           .fops =       &ll_sbi_flags_fops                      },
1737         { .name =       "root_squash",
1738           .fops =       &ll_root_squash_fops                    },
1739         { .name =       "nosquash_nids",
1740           .fops =       &ll_nosquash_nids_fops                  },
1741         { .name =       "pcc",
1742           .fops =       &ll_pcc_fops,                           },
1743         { .name =       "enable_filename_encryption",
1744           .fops =       &ll_filename_enc_fops,                  },
1745         { NULL }
1746 };
1747
1748 #define MAX_STRING_SIZE 128
1749
1750 static struct attribute *llite_attrs[] = {
1751         &lustre_attr_blocksize.attr,
1752         &lustre_attr_stat_blocksize.attr,
1753         &lustre_attr_kbytestotal.attr,
1754         &lustre_attr_kbytesfree.attr,
1755         &lustre_attr_kbytesavail.attr,
1756         &lustre_attr_filestotal.attr,
1757         &lustre_attr_filesfree.attr,
1758         &lustre_attr_client_type.attr,
1759         &lustre_attr_foreign_symlink_enable.attr,
1760         &lustre_attr_foreign_symlink_prefix.attr,
1761         &lustre_attr_foreign_symlink_upcall.attr,
1762         &lustre_attr_foreign_symlink_upcall_info.attr,
1763         &lustre_attr_fstype.attr,
1764         &lustre_attr_uuid.attr,
1765         &lustre_attr_checksums.attr,
1766         &lustre_attr_checksum_pages.attr,
1767         &lustre_attr_max_read_ahead_mb.attr,
1768         &lustre_attr_max_read_ahead_per_file_mb.attr,
1769         &lustre_attr_max_read_ahead_whole_mb.attr,
1770         &lustre_attr_max_read_ahead_async_active.attr,
1771         &lustre_attr_read_ahead_async_file_threshold_mb.attr,
1772         &lustre_attr_read_ahead_range_kb.attr,
1773         &lustre_attr_stats_track_pid.attr,
1774         &lustre_attr_stats_track_ppid.attr,
1775         &lustre_attr_stats_track_gid.attr,
1776         &lustre_attr_statahead_running_max.attr,
1777         &lustre_attr_statahead_max.attr,
1778         &lustre_attr_statahead_agl.attr,
1779         &lustre_attr_lazystatfs.attr,
1780         &lustre_attr_statfs_max_age.attr,
1781         &lustre_attr_max_easize.attr,
1782         &lustre_attr_default_easize.attr,
1783         &lustre_attr_xattr_cache.attr,
1784         &lustre_attr_fast_read.attr,
1785         &lustre_attr_tiny_write.attr,
1786         &lustre_attr_parallel_dio.attr,
1787         &lustre_attr_file_heat.attr,
1788         &lustre_attr_heat_decay_percentage.attr,
1789         &lustre_attr_heat_period_second.attr,
1790         &lustre_attr_opencache_threshold_count.attr,
1791         &lustre_attr_opencache_threshold_ms.attr,
1792         &lustre_attr_opencache_max_ms.attr,
1793         &lustre_attr_inode_cache.attr,
1794         NULL,
1795 };
1796
1797 static void sbi_kobj_release(struct kobject *kobj)
1798 {
1799         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1800                                               ll_kset.kobj);
1801         complete(&sbi->ll_kobj_unregister);
1802 }
1803
1804 static struct kobj_type sbi_ktype = {
1805         .default_attrs  = llite_attrs,
1806         .sysfs_ops      = &lustre_sysfs_ops,
1807         .release        = sbi_kobj_release,
1808 };
1809
1810 static const struct llite_file_opcode {
1811         __u32           opcode;
1812         __u32           type;
1813         const char      *opname;
1814 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
1815         /* file operation */
1816         { LPROC_LL_READ_BYTES,  LPROCFS_TYPE_BYTES_FULL, "read_bytes" },
1817         { LPROC_LL_WRITE_BYTES, LPROCFS_TYPE_BYTES_FULL, "write_bytes" },
1818         { LPROC_LL_READ,        LPROCFS_TYPE_LATENCY,   "read" },
1819         { LPROC_LL_WRITE,       LPROCFS_TYPE_LATENCY,   "write" },
1820         { LPROC_LL_IOCTL,       LPROCFS_TYPE_REQS,      "ioctl" },
1821         { LPROC_LL_OPEN,        LPROCFS_TYPE_LATENCY,   "open" },
1822         { LPROC_LL_RELEASE,     LPROCFS_TYPE_LATENCY,   "close" },
1823         { LPROC_LL_MMAP,        LPROCFS_TYPE_LATENCY,   "mmap" },
1824         { LPROC_LL_FAULT,       LPROCFS_TYPE_LATENCY,   "page_fault" },
1825         { LPROC_LL_MKWRITE,     LPROCFS_TYPE_LATENCY,   "page_mkwrite" },
1826         { LPROC_LL_LLSEEK,      LPROCFS_TYPE_LATENCY,   "seek" },
1827         { LPROC_LL_FSYNC,       LPROCFS_TYPE_LATENCY,   "fsync" },
1828         { LPROC_LL_READDIR,     LPROCFS_TYPE_LATENCY,   "readdir" },
1829         { LPROC_LL_INODE_OCOUNT,LPROCFS_TYPE_REQS |
1830                                 LPROCFS_CNTR_AVGMINMAX |
1831                                 LPROCFS_CNTR_STDDEV,    "opencount" },
1832         { LPROC_LL_INODE_OPCLTM,LPROCFS_TYPE_LATENCY,   "openclosetime" },
1833         /* inode operation */
1834         { LPROC_LL_SETATTR,     LPROCFS_TYPE_LATENCY,   "setattr" },
1835         { LPROC_LL_TRUNC,       LPROCFS_TYPE_LATENCY,   "truncate" },
1836         { LPROC_LL_FLOCK,       LPROCFS_TYPE_LATENCY,   "flock" },
1837         { LPROC_LL_GETATTR,     LPROCFS_TYPE_LATENCY,   "getattr" },
1838         { LPROC_LL_FALLOCATE,   LPROCFS_TYPE_LATENCY, "fallocate"},
1839         /* dir inode operation */
1840         { LPROC_LL_CREATE,      LPROCFS_TYPE_LATENCY,   "create" },
1841         { LPROC_LL_LINK,        LPROCFS_TYPE_LATENCY,   "link" },
1842         { LPROC_LL_UNLINK,      LPROCFS_TYPE_LATENCY,   "unlink" },
1843         { LPROC_LL_SYMLINK,     LPROCFS_TYPE_LATENCY,   "symlink" },
1844         { LPROC_LL_MKDIR,       LPROCFS_TYPE_LATENCY,   "mkdir" },
1845         { LPROC_LL_RMDIR,       LPROCFS_TYPE_LATENCY,   "rmdir" },
1846         { LPROC_LL_MKNOD,       LPROCFS_TYPE_LATENCY,   "mknod" },
1847         { LPROC_LL_RENAME,      LPROCFS_TYPE_LATENCY,   "rename" },
1848         /* special inode operation */
1849         { LPROC_LL_STATFS,      LPROCFS_TYPE_LATENCY,   "statfs" },
1850         { LPROC_LL_SETXATTR,    LPROCFS_TYPE_LATENCY,   "setxattr" },
1851         { LPROC_LL_GETXATTR,    LPROCFS_TYPE_LATENCY,   "getxattr" },
1852         { LPROC_LL_GETXATTR_HITS, LPROCFS_TYPE_REQS,    "getxattr_hits" },
1853         { LPROC_LL_LISTXATTR,   LPROCFS_TYPE_LATENCY,   "listxattr" },
1854         { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_LATENCY,   "removexattr" },
1855         { LPROC_LL_INODE_PERM,  LPROCFS_TYPE_LATENCY,   "inode_permission" },
1856 };
1857
1858 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, long count)
1859 {
1860         if (!sbi->ll_stats)
1861                 return;
1862
1863         if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
1864                 lprocfs_counter_add(sbi->ll_stats, op, count);
1865         else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
1866                  sbi->ll_stats_track_id == current->pid)
1867                 lprocfs_counter_add(sbi->ll_stats, op, count);
1868         else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
1869                  sbi->ll_stats_track_id == current->real_parent->pid)
1870                 lprocfs_counter_add(sbi->ll_stats, op, count);
1871         else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
1872                  sbi->ll_stats_track_id ==
1873                         from_kgid(&init_user_ns, current_gid()))
1874                 lprocfs_counter_add(sbi->ll_stats, op, count);
1875 }
1876 EXPORT_SYMBOL(ll_stats_ops_tally);
1877
1878 static const char *const ra_stat_string[] = {
1879         [RA_STAT_HIT]                   = "hits",
1880         [RA_STAT_MISS]                  = "misses",
1881         [RA_STAT_DISTANT_READPAGE]      = "readpage_not_consecutive",
1882         [RA_STAT_MISS_IN_WINDOW]        = "miss_inside_window",
1883         [RA_STAT_FAILED_GRAB_PAGE]      = "failed_grab_cache_page",
1884         [RA_STAT_FAILED_MATCH]          = "failed_lock_match",
1885         [RA_STAT_DISCARDED]             = "read_but_discarded",
1886         [RA_STAT_ZERO_LEN]              = "zero_length_file",
1887         [RA_STAT_ZERO_WINDOW]           = "zero_size_window",
1888         [RA_STAT_EOF]                   = "readahead_to_eof",
1889         [RA_STAT_MAX_IN_FLIGHT]         = "hit_max_readahead_issue",
1890         [RA_STAT_WRONG_GRAB_PAGE]       = "wrong_page_from_grab_cache_page",
1891         [RA_STAT_FAILED_REACH_END]      = "failed_to_reach_end",
1892         [RA_STAT_ASYNC]                 = "async_readahead",
1893         [RA_STAT_FAILED_FAST_READ]      = "failed_to_fast_read",
1894         [RA_STAT_MMAP_RANGE_READ]       = "mmap_range_read",
1895 };
1896
1897 int ll_debugfs_register_super(struct super_block *sb, const char *name)
1898 {
1899         struct lustre_sb_info *lsi = s2lsi(sb);
1900         struct ll_sb_info *sbi = ll_s2sbi(sb);
1901         int err, id;
1902
1903         ENTRY;
1904         LASSERT(sbi);
1905
1906         if (IS_ERR_OR_NULL(llite_root))
1907                 goto out_ll_kset;
1908
1909         sbi->ll_debugfs_entry = debugfs_create_dir(name, llite_root);
1910         ldebugfs_add_vars(sbi->ll_debugfs_entry, lprocfs_llite_obd_vars, sb);
1911
1912         debugfs_create_file("dump_page_cache", 0444, sbi->ll_debugfs_entry, sbi,
1913                             &vvp_dump_pgcache_file_ops);
1914
1915         debugfs_create_file("extents_stats", 0644, sbi->ll_debugfs_entry, sbi,
1916                                  &ll_rw_extents_stats_fops);
1917
1918         debugfs_create_file("extents_stats_per_process", 0644,
1919                             sbi->ll_debugfs_entry, sbi,
1920                             &ll_rw_extents_stats_pp_fops);
1921
1922         debugfs_create_file("offset_stats", 0644, sbi->ll_debugfs_entry, sbi,
1923                             &ll_rw_offset_stats_fops);
1924
1925         /* File operations stats */
1926         sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
1927                                             LPROCFS_STATS_FLAG_NONE);
1928         if (sbi->ll_stats == NULL)
1929                 GOTO(out_debugfs, err = -ENOMEM);
1930
1931         /* do counter init */
1932         for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
1933                 u32 type = llite_opcode_table[id].type;
1934                 void *ptr = "unknown";
1935
1936                 if (type & LPROCFS_TYPE_REQS)
1937                         ptr = "reqs";
1938                 else if (type & LPROCFS_TYPE_BYTES)
1939                         ptr = "bytes";
1940                 else if (type & LPROCFS_TYPE_USEC)
1941                         ptr = "usec";
1942                 lprocfs_counter_init(sbi->ll_stats,
1943                                      llite_opcode_table[id].opcode, type,
1944                                      llite_opcode_table[id].opname, ptr);
1945         }
1946
1947         debugfs_create_file("stats", 0644, sbi->ll_debugfs_entry,
1948                             sbi->ll_stats, &ldebugfs_stats_seq_fops);
1949
1950         sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
1951                                                LPROCFS_STATS_FLAG_NONE);
1952         if (sbi->ll_ra_stats == NULL)
1953                 GOTO(out_stats, err = -ENOMEM);
1954
1955         for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
1956                 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
1957                                      ra_stat_string[id], "pages");
1958
1959         debugfs_create_file("read_ahead_stats", 0644, sbi->ll_debugfs_entry,
1960                             sbi->ll_ra_stats, &ldebugfs_stats_seq_fops);
1961
1962 out_ll_kset:
1963         /* Yes we also register sysfs mount kset here as well */
1964         sbi->ll_kset.kobj.parent = llite_kobj;
1965         sbi->ll_kset.kobj.ktype = &sbi_ktype;
1966         init_completion(&sbi->ll_kobj_unregister);
1967         err = kobject_set_name(&sbi->ll_kset.kobj, "%s", name);
1968         if (err)
1969                 GOTO(out_ra_stats, err);
1970
1971         err = kset_register(&sbi->ll_kset);
1972         if (err)
1973                 GOTO(out_ra_stats, err);
1974
1975         lsi->lsi_kobj = kobject_get(&sbi->ll_kset.kobj);
1976
1977         RETURN(0);
1978 out_ra_stats:
1979         lprocfs_free_stats(&sbi->ll_ra_stats);
1980 out_stats:
1981         lprocfs_free_stats(&sbi->ll_stats);
1982 out_debugfs:
1983         debugfs_remove_recursive(sbi->ll_debugfs_entry);
1984
1985         RETURN(err);
1986 }
1987
1988 void ll_debugfs_unregister_super(struct super_block *sb)
1989 {
1990         struct lustre_sb_info *lsi = s2lsi(sb);
1991         struct ll_sb_info *sbi = ll_s2sbi(sb);
1992
1993         debugfs_remove_recursive(sbi->ll_debugfs_entry);
1994
1995         if (sbi->ll_dt_obd)
1996                 sysfs_remove_link(&sbi->ll_kset.kobj,
1997                                   sbi->ll_dt_obd->obd_type->typ_name);
1998
1999         if (sbi->ll_md_obd)
2000                 sysfs_remove_link(&sbi->ll_kset.kobj,
2001                                   sbi->ll_md_obd->obd_type->typ_name);
2002
2003         kobject_put(lsi->lsi_kobj);
2004
2005         kset_unregister(&sbi->ll_kset);
2006         wait_for_completion(&sbi->ll_kobj_unregister);
2007
2008         lprocfs_free_stats(&sbi->ll_ra_stats);
2009         lprocfs_free_stats(&sbi->ll_stats);
2010 }
2011 #undef MAX_STRING_SIZE
2012
2013 static void ll_display_extents_info(struct ll_rw_extents_info *rw_extents,
2014                                     struct seq_file *seq, int which)
2015 {
2016         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
2017         unsigned long start, end, r, w;
2018         char *unitp = "KMGTPEZY";
2019         int i, units = 10;
2020         struct per_process_info *pp_info;
2021
2022         pp_info = &rw_extents->pp_extents[which];
2023         read_cum = 0;
2024         write_cum = 0;
2025         start = 0;
2026
2027         for (i = 0; i < LL_HIST_MAX; i++) {
2028                 read_tot += pp_info->pp_r_hist.oh_buckets[i];
2029                 write_tot += pp_info->pp_w_hist.oh_buckets[i];
2030         }
2031
2032         for (i = 0; i < LL_HIST_MAX; i++) {
2033                 r = pp_info->pp_r_hist.oh_buckets[i];
2034                 w = pp_info->pp_w_hist.oh_buckets[i];
2035                 read_cum += r;
2036                 write_cum += w;
2037                 end = 1 << (i + LL_HIST_START - units);
2038                 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4u %4u  | "
2039                            "%14lu %4u %4u\n", start, *unitp, end, *unitp,
2040                            (i == LL_HIST_MAX - 1) ? '+' : ' ',
2041                            r, pct(r, read_tot), pct(read_cum, read_tot),
2042                            w, pct(w, write_tot), pct(write_cum, write_tot));
2043                 start = end;
2044                 if (start == (1 << 10)) {
2045                         start = 1;
2046                         units += 10;
2047                         unitp++;
2048                 }
2049                 if (read_cum == read_tot && write_cum == write_tot)
2050                         break;
2051         }
2052 }
2053
2054 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
2055 {
2056         struct ll_sb_info *sbi = seq->private;
2057         struct ll_rw_extents_info *rw_extents = sbi->ll_rw_extents_info;
2058         int k;
2059
2060         if (!sbi->ll_rw_stats_on || !rw_extents) {
2061                 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
2062                 return 0;
2063         }
2064
2065         spin_lock(&sbi->ll_pp_extent_lock);
2066         lprocfs_stats_header(seq, ktime_get(), rw_extents->pp_init, 25, ":", 1);
2067         seq_printf(seq, "%15s %19s       | %20s\n", " ", "read", "write");
2068         seq_printf(seq, "%13s   %14s %4s %4s  | %14s %4s %4s\n",
2069                    "extents", "calls", "%", "cum%", "calls", "%", "cum%");
2070
2071         for (k = 0; k < LL_PROCESS_HIST_MAX; k++) {
2072                 if (rw_extents->pp_extents[k].pid != 0) {
2073                         seq_printf(seq, "\nPID: %d\n",
2074                                    rw_extents->pp_extents[k].pid);
2075                         ll_display_extents_info(rw_extents, seq, k);
2076                 }
2077         }
2078         spin_unlock(&sbi->ll_pp_extent_lock);
2079         return 0;
2080 }
2081
2082 static int alloc_rw_stats_info(struct ll_sb_info *sbi)
2083 {
2084         struct ll_rw_extents_info *rw_extents;
2085         struct ll_rw_process_info *offset;
2086         struct ll_rw_process_info *process;
2087         int i, rc = 0;
2088
2089         OBD_ALLOC(rw_extents, sizeof(*rw_extents));
2090         if (!rw_extents)
2091                 return -ENOMEM;
2092
2093         for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
2094                 spin_lock_init(&rw_extents->pp_extents[i].pp_r_hist.oh_lock);
2095                 spin_lock_init(&rw_extents->pp_extents[i].pp_w_hist.oh_lock);
2096         }
2097
2098         spin_lock(&sbi->ll_pp_extent_lock);
2099         if (!sbi->ll_rw_extents_info)
2100                 sbi->ll_rw_extents_info = rw_extents;
2101         spin_unlock(&sbi->ll_pp_extent_lock);
2102         /* another writer allocated the struct before we got the lock */
2103         if (sbi->ll_rw_extents_info != rw_extents)
2104                 OBD_FREE(rw_extents, sizeof(*rw_extents));
2105
2106         OBD_ALLOC(process, sizeof(*process) * LL_PROCESS_HIST_MAX);
2107         if (!process)
2108                 GOTO(out, rc = -ENOMEM);
2109         OBD_ALLOC(offset, sizeof(*offset) * LL_OFFSET_HIST_MAX);
2110         if (!offset)
2111                 GOTO(out_free, rc = -ENOMEM);
2112
2113         spin_lock(&sbi->ll_process_lock);
2114         if (!sbi->ll_rw_process_info)
2115                 sbi->ll_rw_process_info = process;
2116         if (!sbi->ll_rw_offset_info)
2117                 sbi->ll_rw_offset_info = offset;
2118         spin_unlock(&sbi->ll_process_lock);
2119
2120         /* another writer allocated the structs before we got the lock */
2121         if (sbi->ll_rw_offset_info != offset)
2122                 OBD_FREE(offset, sizeof(*offset) * LL_OFFSET_HIST_MAX);
2123         if (sbi->ll_rw_process_info != process) {
2124 out_free:
2125                 OBD_FREE(process, sizeof(*process) * LL_PROCESS_HIST_MAX);
2126         }
2127
2128 out:
2129         return rc;
2130 }
2131
2132 void ll_free_rw_stats_info(struct ll_sb_info *sbi)
2133 {
2134         if (sbi->ll_rw_extents_info) {
2135                 OBD_FREE(sbi->ll_rw_extents_info,
2136                          sizeof(*sbi->ll_rw_extents_info));
2137                 sbi->ll_rw_extents_info = NULL;
2138         }
2139         if (sbi->ll_rw_offset_info) {
2140                 OBD_FREE(sbi->ll_rw_offset_info,
2141                          sizeof(*sbi->ll_rw_offset_info) * LL_OFFSET_HIST_MAX);
2142                 sbi->ll_rw_offset_info = NULL;
2143         }
2144         if (sbi->ll_rw_process_info) {
2145                 OBD_FREE(sbi->ll_rw_process_info,
2146                         sizeof(*sbi->ll_rw_process_info) * LL_PROCESS_HIST_MAX);
2147                 sbi->ll_rw_process_info = NULL;
2148         }
2149 }
2150
2151 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
2152                                                 const char __user *buf,
2153                                                 size_t len, loff_t *off)
2154 {
2155         struct seq_file *seq = file->private_data;
2156         struct ll_sb_info *sbi = seq->private;
2157         struct ll_rw_extents_info *rw_extents;
2158         int i;
2159         __s64 value;
2160
2161         if (len == 0)
2162                 return -EINVAL;
2163
2164         value = ll_stats_pid_write(buf, len);
2165
2166         if (value == 0) {
2167                 sbi->ll_rw_stats_on = 0;
2168         } else {
2169                 if (!sbi->ll_rw_extents_info) {
2170                         int rc = alloc_rw_stats_info(sbi);
2171
2172                         if (rc)
2173                                 return rc;
2174                 }
2175                 sbi->ll_rw_stats_on = 1;
2176         }
2177
2178
2179         spin_lock(&sbi->ll_pp_extent_lock);
2180         rw_extents = sbi->ll_rw_extents_info;
2181         if (rw_extents) {
2182                 rw_extents->pp_init = ktime_get();
2183                 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
2184                         rw_extents->pp_extents[i].pid = 0;
2185                         lprocfs_oh_clear(&rw_extents->pp_extents[i].pp_r_hist);
2186                         lprocfs_oh_clear(&rw_extents->pp_extents[i].pp_w_hist);
2187                 }
2188         }
2189         spin_unlock(&sbi->ll_pp_extent_lock);
2190
2191         return len;
2192 }
2193
2194 LDEBUGFS_SEQ_FOPS(ll_rw_extents_stats_pp);
2195
2196 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
2197 {
2198         struct ll_sb_info *sbi = seq->private;
2199         struct ll_rw_extents_info *rw_extents = sbi->ll_rw_extents_info;
2200
2201         if (!sbi->ll_rw_stats_on || !rw_extents) {
2202                 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
2203                 return 0;
2204         }
2205
2206         spin_lock(&sbi->ll_lock);
2207         lprocfs_stats_header(seq, ktime_get(), rw_extents->pp_init, 25, ":", 1);
2208
2209         seq_printf(seq, "%15s %19s       | %20s\n", " ", "read", "write");
2210         seq_printf(seq, "%13s   %14s %4s %4s  | %14s %4s %4s\n",
2211                    "extents", "calls", "%", "cum%",
2212                    "calls", "%", "cum%");
2213
2214         ll_display_extents_info(rw_extents, seq, LL_PROCESS_HIST_MAX);
2215         spin_unlock(&sbi->ll_lock);
2216
2217         return 0;
2218 }
2219
2220 static ssize_t ll_rw_extents_stats_seq_write(struct file *file,
2221                                              const char __user *buf,
2222                                              size_t len, loff_t *off)
2223 {
2224         struct seq_file *seq = file->private_data;
2225         struct ll_sb_info *sbi = seq->private;
2226         struct ll_rw_extents_info *rw_extents;
2227         int i;
2228         __s64 value;
2229
2230         if (len == 0)
2231                 return -EINVAL;
2232
2233         value = ll_stats_pid_write(buf, len);
2234
2235         if (value == 0) {
2236                 sbi->ll_rw_stats_on = 0;
2237         } else {
2238                 if (!sbi->ll_rw_extents_info) {
2239                         int rc = alloc_rw_stats_info(sbi);
2240
2241                         if (rc)
2242                                 return rc;
2243                 }
2244                 sbi->ll_rw_stats_on = 1;
2245         }
2246
2247         spin_lock(&sbi->ll_pp_extent_lock);
2248         rw_extents = sbi->ll_rw_extents_info;
2249         if (rw_extents) {
2250                 rw_extents->pp_init = ktime_get();
2251                 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
2252                         rw_extents->pp_extents[i].pid = 0;
2253                         lprocfs_oh_clear(&rw_extents->pp_extents[i].pp_r_hist);
2254                         lprocfs_oh_clear(&rw_extents->pp_extents[i].pp_w_hist);
2255                 }
2256         }
2257         spin_unlock(&sbi->ll_pp_extent_lock);
2258
2259         return len;
2260 }
2261
2262 LDEBUGFS_SEQ_FOPS(ll_rw_extents_stats);
2263
2264 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
2265                        struct ll_file_data *file, loff_t pos,
2266                        size_t count, int rw)
2267 {
2268         int i, cur = -1;
2269         struct ll_rw_process_info *process;
2270         struct ll_rw_process_info *offset;
2271         int *off_count = &sbi->ll_rw_offset_entry_count;
2272         int *process_count = &sbi->ll_offset_process_count;
2273         struct ll_rw_extents_info *rw_extents;
2274
2275         if (!sbi->ll_rw_stats_on)
2276                 return;
2277
2278         spin_lock(&sbi->ll_pp_extent_lock);
2279         rw_extents = sbi->ll_rw_extents_info;
2280         if (!rw_extents) {
2281                 spin_unlock(&sbi->ll_pp_extent_lock);
2282                 return;
2283         }
2284
2285         /* Extent statistics */
2286         for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
2287                 if (rw_extents->pp_extents[i].pid == pid) {
2288                         cur = i;
2289                         break;
2290                 }
2291         }
2292
2293         if (cur == -1) {
2294                 /* new process */
2295                 sbi->ll_extent_process_count =
2296                         (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
2297                 cur = sbi->ll_extent_process_count;
2298                 rw_extents->pp_extents[cur].pid = pid;
2299                 lprocfs_oh_clear(&rw_extents->pp_extents[cur].pp_r_hist);
2300                 lprocfs_oh_clear(&rw_extents->pp_extents[cur].pp_w_hist);
2301         }
2302
2303         for (i = 0; (count >= 1 << (LL_HIST_START + i)) &&
2304              (i < (LL_HIST_MAX - 1)); i++);
2305         if (rw == 0) {
2306                 rw_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
2307                 rw_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
2308         } else {
2309                 rw_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
2310                 rw_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
2311         }
2312         spin_unlock(&sbi->ll_pp_extent_lock);
2313
2314         spin_lock(&sbi->ll_process_lock);
2315         process = sbi->ll_rw_process_info;
2316         offset = sbi->ll_rw_offset_info;
2317         if (!process || !offset)
2318                 goto out_unlock;
2319
2320         /* Offset statistics */
2321         for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
2322                 if (process[i].rw_pid == pid) {
2323                         if (process[i].rw_last_file != file) {
2324                                 process[i].rw_range_start = pos;
2325                                 process[i].rw_last_file_pos = pos + count;
2326                                 process[i].rw_smallest_extent = count;
2327                                 process[i].rw_largest_extent = count;
2328                                 process[i].rw_offset = 0;
2329                                 process[i].rw_last_file = file;
2330                                 goto out_unlock;
2331                         }
2332                         if (process[i].rw_last_file_pos != pos) {
2333                                 *off_count =
2334                                     (*off_count + 1) % LL_OFFSET_HIST_MAX;
2335                                 offset[*off_count].rw_op = process[i].rw_op;
2336                                 offset[*off_count].rw_pid = pid;
2337                                 offset[*off_count].rw_range_start =
2338                                         process[i].rw_range_start;
2339                                 offset[*off_count].rw_range_end =
2340                                         process[i].rw_last_file_pos;
2341                                 offset[*off_count].rw_smallest_extent =
2342                                         process[i].rw_smallest_extent;
2343                                 offset[*off_count].rw_largest_extent =
2344                                         process[i].rw_largest_extent;
2345                                 offset[*off_count].rw_offset =
2346                                         process[i].rw_offset;
2347                                 process[i].rw_op = rw;
2348                                 process[i].rw_range_start = pos;
2349                                 process[i].rw_smallest_extent = count;
2350                                 process[i].rw_largest_extent = count;
2351                                 process[i].rw_offset = pos -
2352                                         process[i].rw_last_file_pos;
2353                         }
2354                         if (process[i].rw_smallest_extent > count)
2355                                 process[i].rw_smallest_extent = count;
2356                         if (process[i].rw_largest_extent < count)
2357                                 process[i].rw_largest_extent = count;
2358                         process[i].rw_last_file_pos = pos + count;
2359                         goto out_unlock;
2360                 }
2361         }
2362         *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
2363         process[*process_count].rw_pid = pid;
2364         process[*process_count].rw_op = rw;
2365         process[*process_count].rw_range_start = pos;
2366         process[*process_count].rw_last_file_pos = pos + count;
2367         process[*process_count].rw_smallest_extent = count;
2368         process[*process_count].rw_largest_extent = count;
2369         process[*process_count].rw_offset = 0;
2370         process[*process_count].rw_last_file = file;
2371
2372 out_unlock:
2373         spin_unlock(&sbi->ll_process_lock);
2374 }
2375
2376 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
2377 {
2378         struct ll_sb_info *sbi = seq->private;
2379         struct ll_rw_process_info *offset;
2380         struct ll_rw_process_info *process;
2381         int i;
2382
2383         if (!sbi->ll_rw_stats_on) {
2384                 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
2385                 return 0;
2386         }
2387
2388         spin_lock(&sbi->ll_process_lock);
2389         lprocfs_stats_header(seq, ktime_get(), sbi->ll_process_stats_init, 25,
2390                              ":", true);
2391         seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
2392                    "R/W", "PID", "RANGE START", "RANGE END",
2393                    "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
2394
2395         /* We stored the discontiguous offsets here; print them first */
2396         offset = sbi->ll_rw_offset_info;
2397         for (i = 0; offset && i < LL_OFFSET_HIST_MAX; i++) {
2398                 if (offset[i].rw_pid != 0)
2399                         seq_printf(seq,
2400                                   "%3c %10d %14llu %14llu %17lu %17lu %14lld\n",
2401                                    offset[i].rw_op == READ ? 'R' : 'W',
2402                                    offset[i].rw_pid,
2403                                    offset[i].rw_range_start,
2404                                    offset[i].rw_range_end,
2405                                    (unsigned long)offset[i].rw_smallest_extent,
2406                                    (unsigned long)offset[i].rw_largest_extent,
2407                                    offset[i].rw_offset);
2408         }
2409
2410         /* Then print the current offsets for each process */
2411         process = sbi->ll_rw_process_info;
2412         for (i = 0; process && i < LL_PROCESS_HIST_MAX; i++) {
2413                 if (process[i].rw_pid != 0)
2414                         seq_printf(seq,
2415                                   "%3c %10d %14llu %14llu %17lu %17lu %14lld\n",
2416                                    process[i].rw_op == READ ? 'R' : 'W',
2417                                    process[i].rw_pid,
2418                                    process[i].rw_range_start,
2419                                    process[i].rw_last_file_pos,
2420                                    (unsigned long)process[i].rw_smallest_extent,
2421                                    (unsigned long)process[i].rw_largest_extent,
2422                                    process[i].rw_offset);
2423         }
2424         spin_unlock(&sbi->ll_process_lock);
2425
2426         return 0;
2427 }
2428
2429 static ssize_t ll_rw_offset_stats_seq_write(struct file *file,
2430                                             const char __user *buf,
2431                                             size_t len, loff_t *off)
2432 {
2433         struct seq_file *seq = file->private_data;
2434         struct ll_sb_info *sbi = seq->private;
2435         __s64 value;
2436
2437         if (len == 0)
2438                 return -EINVAL;
2439
2440         value = ll_stats_pid_write(buf, len);
2441
2442         if (value == 0) {
2443                 sbi->ll_rw_stats_on = 0;
2444         } else {
2445                 if (!sbi->ll_rw_process_info || !sbi->ll_rw_offset_info) {
2446                         int rc = alloc_rw_stats_info(sbi);
2447
2448                         if (rc)
2449                                 return rc;
2450                 }
2451                 sbi->ll_rw_stats_on = 1;
2452         }
2453
2454         spin_lock(&sbi->ll_process_lock);
2455         sbi->ll_offset_process_count = 0;
2456         sbi->ll_rw_offset_entry_count = 0;
2457         sbi->ll_process_stats_init = ktime_get();
2458         if (sbi->ll_rw_process_info)
2459                 memset(sbi->ll_rw_process_info, 0,
2460                        sizeof(struct ll_rw_process_info) * LL_PROCESS_HIST_MAX);
2461         if (sbi->ll_rw_offset_info)
2462                 memset(sbi->ll_rw_offset_info, 0,
2463                        sizeof(struct ll_rw_process_info) * LL_OFFSET_HIST_MAX);
2464         spin_unlock(&sbi->ll_process_lock);
2465
2466         return len;
2467 }
2468
2469 LDEBUGFS_SEQ_FOPS(ll_rw_offset_stats);