Whamcloud - gitweb
LU-15922 sec: new connect flag for name encryption
[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                    atomic_read(&sbi->ll_sa_total),
838                    atomic_read(&sbi->ll_sa_wrong),
839                    atomic_read(&sbi->ll_agl_total));
840         return 0;
841 }
842
843 LDEBUGFS_SEQ_FOPS_RO(ll_statahead_stats);
844
845 static ssize_t lazystatfs_show(struct kobject *kobj,
846                                struct attribute *attr,
847                                char *buf)
848 {
849         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
850                                               ll_kset.kobj);
851
852         return scnprintf(buf, PAGE_SIZE, "%u\n",
853                          test_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags));
854 }
855
856 static ssize_t lazystatfs_store(struct kobject *kobj,
857                                 struct attribute *attr,
858                                 const char *buffer,
859                                 size_t count)
860 {
861         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
862                                               ll_kset.kobj);
863         bool val;
864         int rc;
865
866         rc = kstrtobool(buffer, &val);
867         if (rc)
868                 return rc;
869
870         if (val)
871                 set_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags);
872         else
873                 clear_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags);
874
875         return count;
876 }
877 LUSTRE_RW_ATTR(lazystatfs);
878
879 static ssize_t statfs_max_age_show(struct kobject *kobj, struct attribute *attr,
880                                    char *buf)
881 {
882         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
883                                               ll_kset.kobj);
884
885         return scnprintf(buf, PAGE_SIZE, "%u\n", sbi->ll_statfs_max_age);
886 }
887
888 static ssize_t statfs_max_age_store(struct kobject *kobj,
889                                     struct attribute *attr, const char *buffer,
890                                     size_t count)
891 {
892         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
893                                               ll_kset.kobj);
894         unsigned int val;
895         int rc;
896
897         rc = kstrtouint(buffer, 10, &val);
898         if (rc)
899                 return rc;
900         if (val > OBD_STATFS_CACHE_MAX_AGE)
901                 return -EINVAL;
902
903         sbi->ll_statfs_max_age = val;
904
905         return count;
906 }
907 LUSTRE_RW_ATTR(statfs_max_age);
908
909 static ssize_t max_easize_show(struct kobject *kobj,
910                                struct attribute *attr,
911                                char *buf)
912 {
913         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
914                                               ll_kset.kobj);
915         unsigned int ealen;
916         int rc;
917
918         rc = ll_get_max_mdsize(sbi, &ealen);
919         if (rc)
920                 return rc;
921
922         /* Limit xattr size returned to userspace based on kernel maximum */
923         return scnprintf(buf, PAGE_SIZE, "%u\n",
924                          ealen > XATTR_SIZE_MAX ? XATTR_SIZE_MAX : ealen);
925 }
926 LUSTRE_RO_ATTR(max_easize);
927
928 /**
929  * Get default_easize.
930  *
931  * \see client_obd::cl_default_mds_easize
932  *
933  * \param[in] m         seq_file handle
934  * \param[in] v         unused for single entry
935  *
936  * \retval 0            on success
937  * \retval negative     negated errno on failure
938  */
939 static ssize_t default_easize_show(struct kobject *kobj,
940                                    struct attribute *attr,
941                                    char *buf)
942 {
943         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
944                                               ll_kset.kobj);
945         unsigned int ealen;
946         int rc;
947
948         rc = ll_get_default_mdsize(sbi, &ealen);
949         if (rc)
950                 return rc;
951
952         /* Limit xattr size returned to userspace based on kernel maximum */
953         return scnprintf(buf, PAGE_SIZE, "%u\n",
954                          ealen > XATTR_SIZE_MAX ? XATTR_SIZE_MAX : ealen);
955 }
956
957 /**
958  * Set default_easize.
959  *
960  * Range checking on the passed value is handled by
961  * ll_set_default_mdsize().
962  *
963  * \see client_obd::cl_default_mds_easize
964  *
965  * \param[in] file      proc file
966  * \param[in] buffer    string passed from user space
967  * \param[in] count     \a buffer length
968  * \param[in] off       unused for single entry
969  *
970  * \retval positive     \a count on success
971  * \retval negative     negated errno on failure
972  */
973 static ssize_t default_easize_store(struct kobject *kobj,
974                                     struct attribute *attr,
975                                     const char *buffer,
976                                     size_t count)
977 {
978         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
979                                               ll_kset.kobj);
980         unsigned int val;
981         int rc;
982
983         if (count == 0)
984                 return 0;
985
986         rc = kstrtouint(buffer, 10, &val);
987         if (rc)
988                 return rc;
989
990         rc = ll_set_default_mdsize(sbi, val);
991         if (rc)
992                 return rc;
993
994         return count;
995 }
996 LUSTRE_RW_ATTR(default_easize);
997
998 LDEBUGFS_SEQ_FOPS_RO(ll_sbi_flags);
999
1000 static ssize_t xattr_cache_show(struct kobject *kobj,
1001                                 struct attribute *attr,
1002                                 char *buf)
1003 {
1004         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1005                                               ll_kset.kobj);
1006
1007         return sprintf(buf, "%u\n", sbi->ll_xattr_cache_enabled);
1008 }
1009
1010 static ssize_t xattr_cache_store(struct kobject *kobj,
1011                                  struct attribute *attr,
1012                                  const char *buffer,
1013                                  size_t count)
1014 {
1015         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1016                                               ll_kset.kobj);
1017         bool val;
1018         int rc;
1019
1020         rc = kstrtobool(buffer, &val);
1021         if (rc)
1022                 return rc;
1023
1024         if (val && !test_bit(LL_SBI_XATTR_CACHE, sbi->ll_flags))
1025                 return -ENOTSUPP;
1026
1027         sbi->ll_xattr_cache_enabled = val;
1028         sbi->ll_xattr_cache_set = 1;
1029
1030         return count;
1031 }
1032 LUSTRE_RW_ATTR(xattr_cache);
1033
1034 static ssize_t tiny_write_show(struct kobject *kobj,
1035                                struct attribute *attr,
1036                                char *buf)
1037 {
1038         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1039                                               ll_kset.kobj);
1040
1041         return scnprintf(buf, PAGE_SIZE, "%u\n",
1042                          test_bit(LL_SBI_TINY_WRITE, sbi->ll_flags));
1043 }
1044
1045 static ssize_t tiny_write_store(struct kobject *kobj,
1046                                 struct attribute *attr,
1047                                 const char *buffer,
1048                                 size_t count)
1049 {
1050         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1051                                               ll_kset.kobj);
1052         bool val;
1053         int rc;
1054
1055         rc = kstrtobool(buffer, &val);
1056         if (rc)
1057                 return rc;
1058
1059         spin_lock(&sbi->ll_lock);
1060         if (val)
1061                 set_bit(LL_SBI_TINY_WRITE, sbi->ll_flags);
1062         else
1063                 clear_bit(LL_SBI_TINY_WRITE, sbi->ll_flags);
1064         spin_unlock(&sbi->ll_lock);
1065
1066         return count;
1067 }
1068 LUSTRE_RW_ATTR(tiny_write);
1069
1070 static ssize_t parallel_dio_show(struct kobject *kobj,
1071                                  struct attribute *attr,
1072                                  char *buf)
1073 {
1074         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1075                                               ll_kset.kobj);
1076
1077         return snprintf(buf, PAGE_SIZE, "%u\n",
1078                         test_bit(LL_SBI_PARALLEL_DIO, sbi->ll_flags));
1079 }
1080
1081 static ssize_t parallel_dio_store(struct kobject *kobj,
1082                                   struct attribute *attr,
1083                                   const char *buffer,
1084                                   size_t count)
1085 {
1086         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1087                                               ll_kset.kobj);
1088         bool val;
1089         int rc;
1090
1091         rc = kstrtobool(buffer, &val);
1092         if (rc)
1093                 return rc;
1094
1095         spin_lock(&sbi->ll_lock);
1096         if (val)
1097                 set_bit(LL_SBI_PARALLEL_DIO, sbi->ll_flags);
1098         else
1099                 clear_bit(LL_SBI_PARALLEL_DIO, sbi->ll_flags);
1100         spin_unlock(&sbi->ll_lock);
1101
1102         return count;
1103 }
1104 LUSTRE_RW_ATTR(parallel_dio);
1105
1106 static ssize_t max_read_ahead_async_active_show(struct kobject *kobj,
1107                                                struct attribute *attr,
1108                                                char *buf)
1109 {
1110         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1111                                               ll_kset.kobj);
1112
1113         return scnprintf(buf, PAGE_SIZE, "%u\n",
1114                          sbi->ll_ra_info.ra_async_max_active);
1115 }
1116
1117 static ssize_t max_read_ahead_async_active_store(struct kobject *kobj,
1118                                                  struct attribute *attr,
1119                                                  const char *buffer,
1120                                                  size_t count)
1121 {
1122         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1123                                               ll_kset.kobj);
1124         unsigned int val;
1125         int rc;
1126
1127         rc = kstrtouint(buffer, 10, &val);
1128         if (rc)
1129                 return rc;
1130
1131         /**
1132          * It doesn't make any sense to make it exceed what
1133          * workqueue could acutally support. This can easily
1134          * over subscripe the cores but Lustre internally
1135          * throttles to avoid those impacts.
1136          */
1137         if (val > WQ_UNBOUND_MAX_ACTIVE) {
1138                 CERROR("%s: cannot set max_read_ahead_async_active=%u larger than %u\n",
1139                        sbi->ll_fsname, val, WQ_UNBOUND_MAX_ACTIVE);
1140                 return -ERANGE;
1141         }
1142
1143         spin_lock(&sbi->ll_lock);
1144         sbi->ll_ra_info.ra_async_max_active = val;
1145         spin_unlock(&sbi->ll_lock);
1146
1147         return count;
1148 }
1149 LUSTRE_RW_ATTR(max_read_ahead_async_active);
1150
1151 static ssize_t read_ahead_async_file_threshold_mb_show(struct kobject *kobj,
1152                                                        struct attribute *attr,
1153                                                        char *buf)
1154 {
1155         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1156                                               ll_kset.kobj);
1157
1158         return scnprintf(buf, PAGE_SIZE, "%lu\n", PAGES_TO_MiB(
1159                          sbi->ll_ra_info.ra_async_pages_per_file_threshold));
1160 }
1161
1162 static ssize_t
1163 read_ahead_async_file_threshold_mb_store(struct kobject *kobj,
1164                                          struct attribute *attr,
1165                                          const char *buffer, size_t count)
1166 {
1167         unsigned long pages_number;
1168         unsigned long max_ra_per_file;
1169         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1170                                               ll_kset.kobj);
1171         int rc;
1172
1173         rc = kstrtoul(buffer, 10, &pages_number);
1174         if (rc)
1175                 return rc;
1176
1177         pages_number = MiB_TO_PAGES(pages_number);
1178         max_ra_per_file = sbi->ll_ra_info.ra_max_pages_per_file;
1179         if (pages_number < 0 || pages_number > max_ra_per_file) {
1180                 CERROR("%s: can't set read_ahead_async_file_threshold_mb=%lu > "
1181                        "max_read_readahead_per_file_mb=%lu\n", sbi->ll_fsname,
1182                        PAGES_TO_MiB(pages_number),
1183                        PAGES_TO_MiB(max_ra_per_file));
1184                 return -ERANGE;
1185         }
1186         sbi->ll_ra_info.ra_async_pages_per_file_threshold = pages_number;
1187
1188         return count;
1189 }
1190 LUSTRE_RW_ATTR(read_ahead_async_file_threshold_mb);
1191
1192 static ssize_t read_ahead_range_kb_show(struct kobject *kobj,
1193                                         struct attribute *attr,char *buf)
1194 {
1195         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1196                                               ll_kset.kobj);
1197
1198         return snprintf(buf, PAGE_SIZE, "%lu\n",
1199                         sbi->ll_ra_info.ra_range_pages << (PAGE_SHIFT - 10));
1200 }
1201
1202 static ssize_t
1203 read_ahead_range_kb_store(struct kobject *kobj,
1204                                struct attribute *attr,
1205                                const char *buffer, size_t count)
1206 {
1207         unsigned long pages_number;
1208         unsigned long max_ra_per_file;
1209         u64 val;
1210         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1211                                               ll_kset.kobj);
1212         int rc;
1213
1214         rc = sysfs_memparse(buffer, count, &val, "KiB");
1215         if (rc < 0)
1216                 return rc;
1217
1218         pages_number = val >> PAGE_SHIFT;
1219         /* Disable mmap range read */
1220         if (pages_number == 0)
1221                 goto out;
1222
1223         max_ra_per_file = sbi->ll_ra_info.ra_max_pages_per_file;
1224         if (pages_number > max_ra_per_file ||
1225             pages_number < RA_MIN_MMAP_RANGE_PAGES)
1226                 return -ERANGE;
1227
1228 out:
1229         spin_lock(&sbi->ll_lock);
1230         sbi->ll_ra_info.ra_range_pages = pages_number;
1231         spin_unlock(&sbi->ll_lock);
1232
1233         return count;
1234 }
1235 LUSTRE_RW_ATTR(read_ahead_range_kb);
1236
1237 static ssize_t fast_read_show(struct kobject *kobj,
1238                               struct attribute *attr,
1239                               char *buf)
1240 {
1241         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1242                                               ll_kset.kobj);
1243
1244         return scnprintf(buf, PAGE_SIZE, "%u\n",
1245                          test_bit(LL_SBI_FAST_READ, sbi->ll_flags));
1246 }
1247
1248 static ssize_t fast_read_store(struct kobject *kobj,
1249                                struct attribute *attr,
1250                                const char *buffer,
1251                                size_t count)
1252 {
1253         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1254                                               ll_kset.kobj);
1255         bool val;
1256         int rc;
1257
1258         rc = kstrtobool(buffer, &val);
1259         if (rc)
1260                 return rc;
1261
1262         spin_lock(&sbi->ll_lock);
1263         if (val)
1264                 set_bit(LL_SBI_FAST_READ, sbi->ll_flags);
1265         else
1266                 clear_bit(LL_SBI_FAST_READ, sbi->ll_flags);
1267         spin_unlock(&sbi->ll_lock);
1268
1269         return count;
1270 }
1271 LUSTRE_RW_ATTR(fast_read);
1272
1273 static ssize_t file_heat_show(struct kobject *kobj,
1274                               struct attribute *attr,
1275                               char *buf)
1276 {
1277         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1278                                               ll_kset.kobj);
1279
1280         return scnprintf(buf, PAGE_SIZE, "%u\n",
1281                          test_bit(LL_SBI_FILE_HEAT, sbi->ll_flags));
1282 }
1283
1284 static ssize_t file_heat_store(struct kobject *kobj,
1285                                struct attribute *attr,
1286                                const char *buffer,
1287                                size_t count)
1288 {
1289         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1290                                               ll_kset.kobj);
1291         bool val;
1292         int rc;
1293
1294         rc = kstrtobool(buffer, &val);
1295         if (rc)
1296                 return rc;
1297
1298         spin_lock(&sbi->ll_lock);
1299         if (val)
1300                 set_bit(LL_SBI_FILE_HEAT, sbi->ll_flags);
1301         else
1302                 clear_bit(LL_SBI_FILE_HEAT, sbi->ll_flags);
1303         spin_unlock(&sbi->ll_lock);
1304
1305         return count;
1306 }
1307 LUSTRE_RW_ATTR(file_heat);
1308
1309 static ssize_t heat_decay_percentage_show(struct kobject *kobj,
1310                                           struct attribute *attr,
1311                                           char *buf)
1312 {
1313         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1314                                               ll_kset.kobj);
1315
1316         return scnprintf(buf, PAGE_SIZE, "%u\n",
1317                          (sbi->ll_heat_decay_weight * 100 + 128) / 256);
1318 }
1319
1320 static ssize_t heat_decay_percentage_store(struct kobject *kobj,
1321                                            struct attribute *attr,
1322                                            const char *buffer,
1323                                            size_t count)
1324 {
1325         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1326                                               ll_kset.kobj);
1327         unsigned long val;
1328         int rc;
1329
1330         rc = kstrtoul(buffer, 10, &val);
1331         if (rc)
1332                 return rc;
1333
1334         if (val < 0 || val > 100)
1335                 return -ERANGE;
1336
1337         sbi->ll_heat_decay_weight = (val * 256 + 50) / 100;
1338
1339         return count;
1340 }
1341 LUSTRE_RW_ATTR(heat_decay_percentage);
1342
1343 static ssize_t heat_period_second_show(struct kobject *kobj,
1344                                        struct attribute *attr,
1345                                        char *buf)
1346 {
1347         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1348                                               ll_kset.kobj);
1349
1350         return scnprintf(buf, PAGE_SIZE, "%u\n", sbi->ll_heat_period_second);
1351 }
1352
1353 static ssize_t heat_period_second_store(struct kobject *kobj,
1354                                         struct attribute *attr,
1355                                         const char *buffer,
1356                                         size_t count)
1357 {
1358         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1359                                               ll_kset.kobj);
1360         unsigned long val;
1361         int rc;
1362
1363         rc = kstrtoul(buffer, 10, &val);
1364         if (rc)
1365                 return rc;
1366
1367         if (val <= 0)
1368                 return -ERANGE;
1369
1370         sbi->ll_heat_period_second = val;
1371
1372         return count;
1373 }
1374 LUSTRE_RW_ATTR(heat_period_second);
1375
1376 static ssize_t opencache_threshold_count_show(struct kobject *kobj,
1377                                               struct attribute *attr,
1378                                               char *buf)
1379 {
1380         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1381                                               ll_kset.kobj);
1382
1383         if (sbi->ll_oc_thrsh_count)
1384                 return snprintf(buf, PAGE_SIZE, "%u\n",
1385                                 sbi->ll_oc_thrsh_count);
1386         else
1387                 return snprintf(buf, PAGE_SIZE, "off\n");
1388 }
1389
1390 static ssize_t opencache_threshold_count_store(struct kobject *kobj,
1391                                                struct attribute *attr,
1392                                                const char *buffer,
1393                                                size_t count)
1394 {
1395         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1396                                               ll_kset.kobj);
1397         unsigned int val;
1398         int rc;
1399
1400         rc = kstrtouint(buffer, 10, &val);
1401         if (rc) {
1402                 bool enable;
1403                 /* also accept "off" to disable and "on" to always cache */
1404                 rc = kstrtobool(buffer, &enable);
1405                 if (rc)
1406                         return rc;
1407                 val = enable;
1408         }
1409         sbi->ll_oc_thrsh_count = val;
1410
1411         return count;
1412 }
1413 LUSTRE_RW_ATTR(opencache_threshold_count);
1414
1415 static ssize_t opencache_threshold_ms_show(struct kobject *kobj,
1416                                            struct attribute *attr,
1417                                            char *buf)
1418 {
1419         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1420                                               ll_kset.kobj);
1421
1422         return snprintf(buf, PAGE_SIZE, "%u\n", sbi->ll_oc_thrsh_ms);
1423 }
1424
1425 static ssize_t opencache_threshold_ms_store(struct kobject *kobj,
1426                                             struct attribute *attr,
1427                                             const char *buffer,
1428                                             size_t count)
1429 {
1430         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1431                                               ll_kset.kobj);
1432         unsigned int val;
1433         int rc;
1434
1435         rc = kstrtouint(buffer, 10, &val);
1436         if (rc)
1437                 return rc;
1438
1439         sbi->ll_oc_thrsh_ms = val;
1440
1441         return count;
1442 }
1443 LUSTRE_RW_ATTR(opencache_threshold_ms);
1444
1445 static ssize_t opencache_max_ms_show(struct kobject *kobj,
1446                                      struct attribute *attr,
1447                                      char *buf)
1448 {
1449         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1450                                               ll_kset.kobj);
1451
1452         return snprintf(buf, PAGE_SIZE, "%u\n", sbi->ll_oc_max_ms);
1453 }
1454
1455 static ssize_t opencache_max_ms_store(struct kobject *kobj,
1456                                       struct attribute *attr,
1457                                       const char *buffer,
1458                                       size_t count)
1459 {
1460         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1461                                               ll_kset.kobj);
1462         unsigned int val;
1463         int rc;
1464
1465         rc = kstrtouint(buffer, 10, &val);
1466         if (rc)
1467                 return rc;
1468
1469         sbi->ll_oc_max_ms = val;
1470
1471         return count;
1472 }
1473 LUSTRE_RW_ATTR(opencache_max_ms);
1474
1475 static ssize_t inode_cache_show(struct kobject *kobj,
1476                                 struct attribute *attr,
1477                                 char *buf)
1478 {
1479         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1480                                               ll_kset.kobj);
1481
1482         return snprintf(buf, PAGE_SIZE, "%u\n", sbi->ll_inode_cache_enabled);
1483 }
1484
1485 static ssize_t inode_cache_store(struct kobject *kobj,
1486                                  struct attribute *attr,
1487                                  const char *buffer,
1488                                  size_t count)
1489 {
1490         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1491                                               ll_kset.kobj);
1492         bool val;
1493         int rc;
1494
1495         rc = kstrtobool(buffer, &val);
1496         if (rc)
1497                 return rc;
1498
1499         sbi->ll_inode_cache_enabled = val;
1500
1501         return count;
1502 }
1503 LUSTRE_RW_ATTR(inode_cache);
1504
1505 static int ll_unstable_stats_seq_show(struct seq_file *m, void *v)
1506 {
1507         struct super_block      *sb    = m->private;
1508         struct ll_sb_info       *sbi   = ll_s2sbi(sb);
1509         struct cl_client_cache  *cache = sbi->ll_cache;
1510         long pages;
1511         int mb;
1512
1513         pages = atomic_long_read(&cache->ccc_unstable_nr);
1514         mb    = (pages * PAGE_SIZE) >> 20;
1515
1516         seq_printf(m, "unstable_check:     %8d\n"
1517                       "unstable_pages: %12ld\n"
1518                       "unstable_mb:        %8d\n",
1519                    cache->ccc_unstable_check, pages, mb);
1520         return 0;
1521 }
1522
1523 static ssize_t ll_unstable_stats_seq_write(struct file *file,
1524                                            const char __user *buffer,
1525                                            size_t count, loff_t *unused)
1526 {
1527         struct seq_file *seq = file->private_data;
1528         struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)seq->private);
1529         char kernbuf[128];
1530         bool val;
1531         int rc;
1532
1533         if (count == 0)
1534                 return 0;
1535         if (count >= sizeof(kernbuf))
1536                 return -EINVAL;
1537
1538         if (copy_from_user(kernbuf, buffer, count))
1539                 return -EFAULT;
1540         kernbuf[count] = 0;
1541
1542         buffer += lprocfs_find_named_value(kernbuf, "unstable_check:", &count) -
1543                   kernbuf;
1544         rc = kstrtobool_from_user(buffer, count, &val);
1545         if (rc < 0)
1546                 return rc;
1547
1548         /* borrow lru lock to set the value */
1549         spin_lock(&sbi->ll_cache->ccc_lru_lock);
1550         sbi->ll_cache->ccc_unstable_check = val;
1551         spin_unlock(&sbi->ll_cache->ccc_lru_lock);
1552
1553         return count;
1554 }
1555
1556 LDEBUGFS_SEQ_FOPS(ll_unstable_stats);
1557
1558 static int ll_root_squash_seq_show(struct seq_file *m, void *v)
1559 {
1560         struct super_block *sb = m->private;
1561         struct ll_sb_info *sbi = ll_s2sbi(sb);
1562         struct root_squash_info *squash = &sbi->ll_squash;
1563
1564         seq_printf(m, "%u:%u\n", squash->rsi_uid, squash->rsi_gid);
1565         return 0;
1566 }
1567
1568 static ssize_t ll_root_squash_seq_write(struct file *file,
1569                                         const char __user *buffer,
1570                                         size_t count, loff_t *off)
1571 {
1572         struct seq_file *m = file->private_data;
1573         struct super_block *sb = m->private;
1574         struct ll_sb_info *sbi = ll_s2sbi(sb);
1575         struct root_squash_info *squash = &sbi->ll_squash;
1576
1577         return lprocfs_wr_root_squash(buffer, count, squash, sbi->ll_fsname);
1578 }
1579
1580 LDEBUGFS_SEQ_FOPS(ll_root_squash);
1581
1582 static int ll_nosquash_nids_seq_show(struct seq_file *m, void *v)
1583 {
1584         struct super_block *sb = m->private;
1585         struct ll_sb_info *sbi = ll_s2sbi(sb);
1586         struct root_squash_info *squash = &sbi->ll_squash;
1587         int len;
1588
1589         spin_lock(&squash->rsi_lock);
1590         if (!list_empty(&squash->rsi_nosquash_nids)) {
1591                 len = cfs_print_nidlist(m->buf + m->count, m->size - m->count,
1592                                         &squash->rsi_nosquash_nids);
1593                 m->count += len;
1594                 seq_putc(m, '\n');
1595         } else {
1596                 seq_puts(m, "NONE\n");
1597         }
1598         spin_unlock(&squash->rsi_lock);
1599
1600         return 0;
1601 }
1602
1603 static ssize_t ll_nosquash_nids_seq_write(struct file *file,
1604                                           const char __user *buffer,
1605                                           size_t count, loff_t *off)
1606 {
1607         struct seq_file *m = file->private_data;
1608         struct super_block *sb = m->private;
1609         struct ll_sb_info *sbi = ll_s2sbi(sb);
1610         struct root_squash_info *squash = &sbi->ll_squash;
1611         int rc;
1612
1613         rc = lprocfs_wr_nosquash_nids(buffer, count, squash, sbi->ll_fsname);
1614         if (rc < 0)
1615                 return rc;
1616
1617         ll_compute_rootsquash_state(sbi);
1618
1619         return rc;
1620 }
1621
1622 LDEBUGFS_SEQ_FOPS(ll_nosquash_nids);
1623
1624 static int ll_filename_enc_seq_show(struct seq_file *m, void *v)
1625 {
1626         struct super_block *sb = m->private;
1627         struct lustre_sb_info *lsi = s2lsi(sb);
1628
1629         seq_printf(m, "%u\n", lsi->lsi_flags & LSI_FILENAME_ENC ? 1 : 0);
1630         return 0;
1631 }
1632
1633 static ssize_t ll_filename_enc_seq_write(struct file *file,
1634                                          const char __user *buffer,
1635                                          size_t count, loff_t *off)
1636 {
1637         struct seq_file *m = file->private_data;
1638         struct super_block *sb = m->private;
1639         struct lustre_sb_info *lsi = s2lsi(sb);
1640         struct ll_sb_info *sbi = ll_s2sbi(sb);
1641         bool val;
1642         int rc;
1643
1644         rc = kstrtobool_from_user(buffer, count, &val);
1645         if (rc)
1646                 return rc;
1647
1648         if (val) {
1649                 if (!ll_sbi_has_name_encrypt(sbi)) {
1650                         /* server does not support name encryption,
1651                          * so force it to NULL on client
1652                          */
1653                         CDEBUG(D_SEC, "%s: server does not support name encryption\n",
1654                                sbi->ll_fsname);
1655                         lsi->lsi_flags &= ~LSI_FILENAME_ENC;
1656                         return -EOPNOTSUPP;
1657                 }
1658
1659                 lsi->lsi_flags |= LSI_FILENAME_ENC;
1660         } else {
1661                 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
1662         }
1663
1664         return count;
1665 }
1666
1667 LDEBUGFS_SEQ_FOPS(ll_filename_enc);
1668
1669 static int ll_pcc_seq_show(struct seq_file *m, void *v)
1670 {
1671         struct super_block *sb = m->private;
1672         struct ll_sb_info *sbi = ll_s2sbi(sb);
1673
1674         return pcc_super_dump(&sbi->ll_pcc_super, m);
1675 }
1676
1677 static ssize_t ll_pcc_seq_write(struct file *file, const char __user *buffer,
1678                                 size_t count, loff_t *off)
1679 {
1680         struct seq_file *m = file->private_data;
1681         struct super_block *sb = m->private;
1682         struct ll_sb_info *sbi = ll_s2sbi(sb);
1683         int rc;
1684         char *kernbuf;
1685
1686         if (count >= LPROCFS_WR_PCC_MAX_CMD)
1687                 return -EINVAL;
1688
1689         if (!(exp_connect_flags2(sbi->ll_md_exp) & OBD_CONNECT2_PCC))
1690                 return -EOPNOTSUPP;
1691
1692         OBD_ALLOC(kernbuf, count + 1);
1693         if (kernbuf == NULL)
1694                 return -ENOMEM;
1695
1696         if (copy_from_user(kernbuf, buffer, count))
1697                 GOTO(out_free_kernbuff, rc = -EFAULT);
1698
1699         rc = pcc_cmd_handle(kernbuf, count, &sbi->ll_pcc_super);
1700 out_free_kernbuff:
1701         OBD_FREE(kernbuf, count + 1);
1702         return rc ? rc : count;
1703 }
1704 LDEBUGFS_SEQ_FOPS(ll_pcc);
1705
1706 struct ldebugfs_vars lprocfs_llite_obd_vars[] = {
1707         { .name =       "site",
1708           .fops =       &ll_site_stats_fops                     },
1709         { .name =       "max_cached_mb",
1710           .fops =       &ll_max_cached_mb_fops                  },
1711         { .name =       "statahead_stats",
1712           .fops =       &ll_statahead_stats_fops                },
1713         { .name =       "unstable_stats",
1714           .fops =       &ll_unstable_stats_fops                 },
1715         { .name =       "sbi_flags",
1716           .fops =       &ll_sbi_flags_fops                      },
1717         { .name =       "root_squash",
1718           .fops =       &ll_root_squash_fops                    },
1719         { .name =       "nosquash_nids",
1720           .fops =       &ll_nosquash_nids_fops                  },
1721         { .name =       "pcc",
1722           .fops =       &ll_pcc_fops,                           },
1723         { .name =       "enable_filename_encryption",
1724           .fops =       &ll_filename_enc_fops,                  },
1725         { NULL }
1726 };
1727
1728 #define MAX_STRING_SIZE 128
1729
1730 static struct attribute *llite_attrs[] = {
1731         &lustre_attr_blocksize.attr,
1732         &lustre_attr_stat_blocksize.attr,
1733         &lustre_attr_kbytestotal.attr,
1734         &lustre_attr_kbytesfree.attr,
1735         &lustre_attr_kbytesavail.attr,
1736         &lustre_attr_filestotal.attr,
1737         &lustre_attr_filesfree.attr,
1738         &lustre_attr_client_type.attr,
1739         &lustre_attr_foreign_symlink_enable.attr,
1740         &lustre_attr_foreign_symlink_prefix.attr,
1741         &lustre_attr_foreign_symlink_upcall.attr,
1742         &lustre_attr_foreign_symlink_upcall_info.attr,
1743         &lustre_attr_fstype.attr,
1744         &lustre_attr_uuid.attr,
1745         &lustre_attr_checksums.attr,
1746         &lustre_attr_checksum_pages.attr,
1747         &lustre_attr_max_read_ahead_mb.attr,
1748         &lustre_attr_max_read_ahead_per_file_mb.attr,
1749         &lustre_attr_max_read_ahead_whole_mb.attr,
1750         &lustre_attr_max_read_ahead_async_active.attr,
1751         &lustre_attr_read_ahead_async_file_threshold_mb.attr,
1752         &lustre_attr_read_ahead_range_kb.attr,
1753         &lustre_attr_stats_track_pid.attr,
1754         &lustre_attr_stats_track_ppid.attr,
1755         &lustre_attr_stats_track_gid.attr,
1756         &lustre_attr_statahead_running_max.attr,
1757         &lustre_attr_statahead_max.attr,
1758         &lustre_attr_statahead_agl.attr,
1759         &lustre_attr_lazystatfs.attr,
1760         &lustre_attr_statfs_max_age.attr,
1761         &lustre_attr_max_easize.attr,
1762         &lustre_attr_default_easize.attr,
1763         &lustre_attr_xattr_cache.attr,
1764         &lustre_attr_fast_read.attr,
1765         &lustre_attr_tiny_write.attr,
1766         &lustre_attr_parallel_dio.attr,
1767         &lustre_attr_file_heat.attr,
1768         &lustre_attr_heat_decay_percentage.attr,
1769         &lustre_attr_heat_period_second.attr,
1770         &lustre_attr_opencache_threshold_count.attr,
1771         &lustre_attr_opencache_threshold_ms.attr,
1772         &lustre_attr_opencache_max_ms.attr,
1773         &lustre_attr_inode_cache.attr,
1774         NULL,
1775 };
1776
1777 static void sbi_kobj_release(struct kobject *kobj)
1778 {
1779         struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
1780                                               ll_kset.kobj);
1781         complete(&sbi->ll_kobj_unregister);
1782 }
1783
1784 static struct kobj_type sbi_ktype = {
1785         .default_attrs  = llite_attrs,
1786         .sysfs_ops      = &lustre_sysfs_ops,
1787         .release        = sbi_kobj_release,
1788 };
1789
1790 static const struct llite_file_opcode {
1791         __u32           opcode;
1792         __u32           type;
1793         const char      *opname;
1794 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
1795         /* file operation */
1796         { LPROC_LL_READ_BYTES,  LPROCFS_TYPE_BYTES_FULL, "read_bytes" },
1797         { LPROC_LL_WRITE_BYTES, LPROCFS_TYPE_BYTES_FULL, "write_bytes" },
1798         { LPROC_LL_READ,        LPROCFS_TYPE_LATENCY,   "read" },
1799         { LPROC_LL_WRITE,       LPROCFS_TYPE_LATENCY,   "write" },
1800         { LPROC_LL_IOCTL,       LPROCFS_TYPE_REQS,      "ioctl" },
1801         { LPROC_LL_OPEN,        LPROCFS_TYPE_LATENCY,   "open" },
1802         { LPROC_LL_RELEASE,     LPROCFS_TYPE_LATENCY,   "close" },
1803         { LPROC_LL_MMAP,        LPROCFS_TYPE_LATENCY,   "mmap" },
1804         { LPROC_LL_FAULT,       LPROCFS_TYPE_LATENCY,   "page_fault" },
1805         { LPROC_LL_MKWRITE,     LPROCFS_TYPE_LATENCY,   "page_mkwrite" },
1806         { LPROC_LL_LLSEEK,      LPROCFS_TYPE_LATENCY,   "seek" },
1807         { LPROC_LL_FSYNC,       LPROCFS_TYPE_LATENCY,   "fsync" },
1808         { LPROC_LL_READDIR,     LPROCFS_TYPE_LATENCY,   "readdir" },
1809         { LPROC_LL_INODE_OCOUNT,LPROCFS_TYPE_REQS |
1810                                 LPROCFS_CNTR_AVGMINMAX |
1811                                 LPROCFS_CNTR_STDDEV,    "opencount" },
1812         { LPROC_LL_INODE_OPCLTM,LPROCFS_TYPE_LATENCY,   "openclosetime" },
1813         /* inode operation */
1814         { LPROC_LL_SETATTR,     LPROCFS_TYPE_LATENCY,   "setattr" },
1815         { LPROC_LL_TRUNC,       LPROCFS_TYPE_LATENCY,   "truncate" },
1816         { LPROC_LL_FLOCK,       LPROCFS_TYPE_LATENCY,   "flock" },
1817         { LPROC_LL_GETATTR,     LPROCFS_TYPE_LATENCY,   "getattr" },
1818         { LPROC_LL_FALLOCATE,   LPROCFS_TYPE_LATENCY, "fallocate"},
1819         /* dir inode operation */
1820         { LPROC_LL_CREATE,      LPROCFS_TYPE_LATENCY,   "create" },
1821         { LPROC_LL_LINK,        LPROCFS_TYPE_LATENCY,   "link" },
1822         { LPROC_LL_UNLINK,      LPROCFS_TYPE_LATENCY,   "unlink" },
1823         { LPROC_LL_SYMLINK,     LPROCFS_TYPE_LATENCY,   "symlink" },
1824         { LPROC_LL_MKDIR,       LPROCFS_TYPE_LATENCY,   "mkdir" },
1825         { LPROC_LL_RMDIR,       LPROCFS_TYPE_LATENCY,   "rmdir" },
1826         { LPROC_LL_MKNOD,       LPROCFS_TYPE_LATENCY,   "mknod" },
1827         { LPROC_LL_RENAME,      LPROCFS_TYPE_LATENCY,   "rename" },
1828         /* special inode operation */
1829         { LPROC_LL_STATFS,      LPROCFS_TYPE_LATENCY,   "statfs" },
1830         { LPROC_LL_SETXATTR,    LPROCFS_TYPE_LATENCY,   "setxattr" },
1831         { LPROC_LL_GETXATTR,    LPROCFS_TYPE_LATENCY,   "getxattr" },
1832         { LPROC_LL_GETXATTR_HITS, LPROCFS_TYPE_REQS,    "getxattr_hits" },
1833         { LPROC_LL_LISTXATTR,   LPROCFS_TYPE_LATENCY,   "listxattr" },
1834         { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_LATENCY,   "removexattr" },
1835         { LPROC_LL_INODE_PERM,  LPROCFS_TYPE_LATENCY,   "inode_permission" },
1836 };
1837
1838 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, long count)
1839 {
1840         if (!sbi->ll_stats)
1841                 return;
1842
1843         if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
1844                 lprocfs_counter_add(sbi->ll_stats, op, count);
1845         else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
1846                  sbi->ll_stats_track_id == current->pid)
1847                 lprocfs_counter_add(sbi->ll_stats, op, count);
1848         else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
1849                  sbi->ll_stats_track_id == current->real_parent->pid)
1850                 lprocfs_counter_add(sbi->ll_stats, op, count);
1851         else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
1852                  sbi->ll_stats_track_id ==
1853                         from_kgid(&init_user_ns, current_gid()))
1854                 lprocfs_counter_add(sbi->ll_stats, op, count);
1855 }
1856 EXPORT_SYMBOL(ll_stats_ops_tally);
1857
1858 static const char *const ra_stat_string[] = {
1859         [RA_STAT_HIT]                   = "hits",
1860         [RA_STAT_MISS]                  = "misses",
1861         [RA_STAT_DISTANT_READPAGE]      = "readpage_not_consecutive",
1862         [RA_STAT_MISS_IN_WINDOW]        = "miss_inside_window",
1863         [RA_STAT_FAILED_GRAB_PAGE]      = "failed_grab_cache_page",
1864         [RA_STAT_FAILED_MATCH]          = "failed_lock_match",
1865         [RA_STAT_DISCARDED]             = "read_but_discarded",
1866         [RA_STAT_ZERO_LEN]              = "zero_length_file",
1867         [RA_STAT_ZERO_WINDOW]           = "zero_size_window",
1868         [RA_STAT_EOF]                   = "readahead_to_eof",
1869         [RA_STAT_MAX_IN_FLIGHT]         = "hit_max_readahead_issue",
1870         [RA_STAT_WRONG_GRAB_PAGE]       = "wrong_page_from_grab_cache_page",
1871         [RA_STAT_FAILED_REACH_END]      = "failed_to_reach_end",
1872         [RA_STAT_ASYNC]                 = "async_readahead",
1873         [RA_STAT_FAILED_FAST_READ]      = "failed_to_fast_read",
1874         [RA_STAT_MMAP_RANGE_READ]       = "mmap_range_read",
1875 };
1876
1877 int ll_debugfs_register_super(struct super_block *sb, const char *name)
1878 {
1879         struct lustre_sb_info *lsi = s2lsi(sb);
1880         struct ll_sb_info *sbi = ll_s2sbi(sb);
1881         int err, id;
1882
1883         ENTRY;
1884         LASSERT(sbi);
1885
1886         if (IS_ERR_OR_NULL(llite_root))
1887                 goto out_ll_kset;
1888
1889         sbi->ll_debugfs_entry = debugfs_create_dir(name, llite_root);
1890         ldebugfs_add_vars(sbi->ll_debugfs_entry, lprocfs_llite_obd_vars, sb);
1891
1892         debugfs_create_file("dump_page_cache", 0444, sbi->ll_debugfs_entry, sbi,
1893                             &vvp_dump_pgcache_file_ops);
1894
1895         debugfs_create_file("extents_stats", 0644, sbi->ll_debugfs_entry, sbi,
1896                                  &ll_rw_extents_stats_fops);
1897
1898         debugfs_create_file("extents_stats_per_process", 0644,
1899                             sbi->ll_debugfs_entry, sbi,
1900                             &ll_rw_extents_stats_pp_fops);
1901
1902         debugfs_create_file("offset_stats", 0644, sbi->ll_debugfs_entry, sbi,
1903                             &ll_rw_offset_stats_fops);
1904
1905         /* File operations stats */
1906         sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
1907                                             LPROCFS_STATS_FLAG_NONE);
1908         if (sbi->ll_stats == NULL)
1909                 GOTO(out_debugfs, err = -ENOMEM);
1910
1911         /* do counter init */
1912         for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
1913                 u32 type = llite_opcode_table[id].type;
1914                 void *ptr = "unknown";
1915
1916                 if (type & LPROCFS_TYPE_REQS)
1917                         ptr = "reqs";
1918                 else if (type & LPROCFS_TYPE_BYTES)
1919                         ptr = "bytes";
1920                 else if (type & LPROCFS_TYPE_USEC)
1921                         ptr = "usec";
1922                 lprocfs_counter_init(sbi->ll_stats,
1923                                      llite_opcode_table[id].opcode, type,
1924                                      llite_opcode_table[id].opname, ptr);
1925         }
1926
1927         debugfs_create_file("stats", 0644, sbi->ll_debugfs_entry,
1928                             sbi->ll_stats, &ldebugfs_stats_seq_fops);
1929
1930         sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
1931                                                LPROCFS_STATS_FLAG_NONE);
1932         if (sbi->ll_ra_stats == NULL)
1933                 GOTO(out_stats, err = -ENOMEM);
1934
1935         for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
1936                 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
1937                                      ra_stat_string[id], "pages");
1938
1939         debugfs_create_file("read_ahead_stats", 0644, sbi->ll_debugfs_entry,
1940                             sbi->ll_ra_stats, &ldebugfs_stats_seq_fops);
1941
1942 out_ll_kset:
1943         /* Yes we also register sysfs mount kset here as well */
1944         sbi->ll_kset.kobj.parent = llite_kobj;
1945         sbi->ll_kset.kobj.ktype = &sbi_ktype;
1946         init_completion(&sbi->ll_kobj_unregister);
1947         err = kobject_set_name(&sbi->ll_kset.kobj, "%s", name);
1948         if (err)
1949                 GOTO(out_ra_stats, err);
1950
1951         err = kset_register(&sbi->ll_kset);
1952         if (err)
1953                 GOTO(out_ra_stats, err);
1954
1955         lsi->lsi_kobj = kobject_get(&sbi->ll_kset.kobj);
1956
1957         RETURN(0);
1958 out_ra_stats:
1959         lprocfs_free_stats(&sbi->ll_ra_stats);
1960 out_stats:
1961         lprocfs_free_stats(&sbi->ll_stats);
1962 out_debugfs:
1963         debugfs_remove_recursive(sbi->ll_debugfs_entry);
1964
1965         RETURN(err);
1966 }
1967
1968 void ll_debugfs_unregister_super(struct super_block *sb)
1969 {
1970         struct lustre_sb_info *lsi = s2lsi(sb);
1971         struct ll_sb_info *sbi = ll_s2sbi(sb);
1972
1973         debugfs_remove_recursive(sbi->ll_debugfs_entry);
1974
1975         if (sbi->ll_dt_obd)
1976                 sysfs_remove_link(&sbi->ll_kset.kobj,
1977                                   sbi->ll_dt_obd->obd_type->typ_name);
1978
1979         if (sbi->ll_md_obd)
1980                 sysfs_remove_link(&sbi->ll_kset.kobj,
1981                                   sbi->ll_md_obd->obd_type->typ_name);
1982
1983         kobject_put(lsi->lsi_kobj);
1984
1985         kset_unregister(&sbi->ll_kset);
1986         wait_for_completion(&sbi->ll_kobj_unregister);
1987
1988         lprocfs_free_stats(&sbi->ll_ra_stats);
1989         lprocfs_free_stats(&sbi->ll_stats);
1990 }
1991 #undef MAX_STRING_SIZE
1992
1993 static void ll_display_extents_info(struct ll_rw_extents_info *rw_extents,
1994                                     struct seq_file *seq, int which)
1995 {
1996         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
1997         unsigned long start, end, r, w;
1998         char *unitp = "KMGTPEZY";
1999         int i, units = 10;
2000         struct per_process_info *pp_info;
2001
2002         pp_info = &rw_extents->pp_extents[which];
2003         read_cum = 0;
2004         write_cum = 0;
2005         start = 0;
2006
2007         for (i = 0; i < LL_HIST_MAX; i++) {
2008                 read_tot += pp_info->pp_r_hist.oh_buckets[i];
2009                 write_tot += pp_info->pp_w_hist.oh_buckets[i];
2010         }
2011
2012         for (i = 0; i < LL_HIST_MAX; i++) {
2013                 r = pp_info->pp_r_hist.oh_buckets[i];
2014                 w = pp_info->pp_w_hist.oh_buckets[i];
2015                 read_cum += r;
2016                 write_cum += w;
2017                 end = 1 << (i + LL_HIST_START - units);
2018                 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4u %4u  | "
2019                            "%14lu %4u %4u\n", start, *unitp, end, *unitp,
2020                            (i == LL_HIST_MAX - 1) ? '+' : ' ',
2021                            r, pct(r, read_tot), pct(read_cum, read_tot),
2022                            w, pct(w, write_tot), pct(write_cum, write_tot));
2023                 start = end;
2024                 if (start == (1 << 10)) {
2025                         start = 1;
2026                         units += 10;
2027                         unitp++;
2028                 }
2029                 if (read_cum == read_tot && write_cum == write_tot)
2030                         break;
2031         }
2032 }
2033
2034 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
2035 {
2036         struct ll_sb_info *sbi = seq->private;
2037         struct ll_rw_extents_info *rw_extents = sbi->ll_rw_extents_info;
2038         int k;
2039
2040         if (!sbi->ll_rw_stats_on || !rw_extents) {
2041                 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
2042                 return 0;
2043         }
2044
2045         spin_lock(&sbi->ll_pp_extent_lock);
2046         lprocfs_stats_header(seq, ktime_get(), rw_extents->pp_init, 25, ":", 1);
2047         seq_printf(seq, "%15s %19s       | %20s\n", " ", "read", "write");
2048         seq_printf(seq, "%13s   %14s %4s %4s  | %14s %4s %4s\n",
2049                    "extents", "calls", "%", "cum%", "calls", "%", "cum%");
2050
2051         for (k = 0; k < LL_PROCESS_HIST_MAX; k++) {
2052                 if (rw_extents->pp_extents[k].pid != 0) {
2053                         seq_printf(seq, "\nPID: %d\n",
2054                                    rw_extents->pp_extents[k].pid);
2055                         ll_display_extents_info(rw_extents, seq, k);
2056                 }
2057         }
2058         spin_unlock(&sbi->ll_pp_extent_lock);
2059         return 0;
2060 }
2061
2062 static int alloc_rw_stats_info(struct ll_sb_info *sbi)
2063 {
2064         struct ll_rw_extents_info *rw_extents;
2065         struct ll_rw_process_info *offset;
2066         struct ll_rw_process_info *process;
2067         int i, rc = 0;
2068
2069         OBD_ALLOC(rw_extents, sizeof(*rw_extents));
2070         if (!rw_extents)
2071                 return -ENOMEM;
2072
2073         for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
2074                 spin_lock_init(&rw_extents->pp_extents[i].pp_r_hist.oh_lock);
2075                 spin_lock_init(&rw_extents->pp_extents[i].pp_w_hist.oh_lock);
2076         }
2077
2078         spin_lock(&sbi->ll_pp_extent_lock);
2079         if (!sbi->ll_rw_extents_info)
2080                 sbi->ll_rw_extents_info = rw_extents;
2081         spin_unlock(&sbi->ll_pp_extent_lock);
2082         /* another writer allocated the struct before we got the lock */
2083         if (sbi->ll_rw_extents_info != rw_extents)
2084                 OBD_FREE(rw_extents, sizeof(*rw_extents));
2085
2086         OBD_ALLOC(process, sizeof(*process) * LL_PROCESS_HIST_MAX);
2087         if (!process)
2088                 GOTO(out, rc = -ENOMEM);
2089         OBD_ALLOC(offset, sizeof(*offset) * LL_OFFSET_HIST_MAX);
2090         if (!offset)
2091                 GOTO(out_free, rc = -ENOMEM);
2092
2093         spin_lock(&sbi->ll_process_lock);
2094         if (!sbi->ll_rw_process_info)
2095                 sbi->ll_rw_process_info = process;
2096         if (!sbi->ll_rw_offset_info)
2097                 sbi->ll_rw_offset_info = offset;
2098         spin_unlock(&sbi->ll_process_lock);
2099
2100         /* another writer allocated the structs before we got the lock */
2101         if (sbi->ll_rw_offset_info != offset)
2102                 OBD_FREE(offset, sizeof(*offset) * LL_OFFSET_HIST_MAX);
2103         if (sbi->ll_rw_process_info != process) {
2104 out_free:
2105                 OBD_FREE(process, sizeof(*process) * LL_PROCESS_HIST_MAX);
2106         }
2107
2108 out:
2109         return rc;
2110 }
2111
2112 void ll_free_rw_stats_info(struct ll_sb_info *sbi)
2113 {
2114         if (sbi->ll_rw_extents_info) {
2115                 OBD_FREE(sbi->ll_rw_extents_info,
2116                          sizeof(*sbi->ll_rw_extents_info));
2117                 sbi->ll_rw_extents_info = NULL;
2118         }
2119         if (sbi->ll_rw_offset_info) {
2120                 OBD_FREE(sbi->ll_rw_offset_info,
2121                          sizeof(*sbi->ll_rw_offset_info) * LL_OFFSET_HIST_MAX);
2122                 sbi->ll_rw_offset_info = NULL;
2123         }
2124         if (sbi->ll_rw_process_info) {
2125                 OBD_FREE(sbi->ll_rw_process_info,
2126                         sizeof(*sbi->ll_rw_process_info) * LL_PROCESS_HIST_MAX);
2127                 sbi->ll_rw_process_info = NULL;
2128         }
2129 }
2130
2131 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
2132                                                 const char __user *buf,
2133                                                 size_t len, loff_t *off)
2134 {
2135         struct seq_file *seq = file->private_data;
2136         struct ll_sb_info *sbi = seq->private;
2137         struct ll_rw_extents_info *rw_extents;
2138         int i;
2139         __s64 value;
2140
2141         if (len == 0)
2142                 return -EINVAL;
2143
2144         value = ll_stats_pid_write(buf, len);
2145
2146         if (value == 0) {
2147                 sbi->ll_rw_stats_on = 0;
2148         } else {
2149                 if (!sbi->ll_rw_extents_info) {
2150                         int rc = alloc_rw_stats_info(sbi);
2151
2152                         if (rc)
2153                                 return rc;
2154                 }
2155                 sbi->ll_rw_stats_on = 1;
2156         }
2157
2158
2159         spin_lock(&sbi->ll_pp_extent_lock);
2160         rw_extents = sbi->ll_rw_extents_info;
2161         if (rw_extents) {
2162                 rw_extents->pp_init = ktime_get();
2163                 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
2164                         rw_extents->pp_extents[i].pid = 0;
2165                         lprocfs_oh_clear(&rw_extents->pp_extents[i].pp_r_hist);
2166                         lprocfs_oh_clear(&rw_extents->pp_extents[i].pp_w_hist);
2167                 }
2168         }
2169         spin_unlock(&sbi->ll_pp_extent_lock);
2170
2171         return len;
2172 }
2173
2174 LDEBUGFS_SEQ_FOPS(ll_rw_extents_stats_pp);
2175
2176 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
2177 {
2178         struct ll_sb_info *sbi = seq->private;
2179         struct ll_rw_extents_info *rw_extents = sbi->ll_rw_extents_info;
2180
2181         if (!sbi->ll_rw_stats_on || !rw_extents) {
2182                 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
2183                 return 0;
2184         }
2185
2186         spin_lock(&sbi->ll_lock);
2187         lprocfs_stats_header(seq, ktime_get(), rw_extents->pp_init, 25, ":", 1);
2188
2189         seq_printf(seq, "%15s %19s       | %20s\n", " ", "read", "write");
2190         seq_printf(seq, "%13s   %14s %4s %4s  | %14s %4s %4s\n",
2191                    "extents", "calls", "%", "cum%",
2192                    "calls", "%", "cum%");
2193
2194         ll_display_extents_info(rw_extents, seq, LL_PROCESS_HIST_MAX);
2195         spin_unlock(&sbi->ll_lock);
2196
2197         return 0;
2198 }
2199
2200 static ssize_t ll_rw_extents_stats_seq_write(struct file *file,
2201                                              const char __user *buf,
2202                                              size_t len, loff_t *off)
2203 {
2204         struct seq_file *seq = file->private_data;
2205         struct ll_sb_info *sbi = seq->private;
2206         struct ll_rw_extents_info *rw_extents;
2207         int i;
2208         __s64 value;
2209
2210         if (len == 0)
2211                 return -EINVAL;
2212
2213         value = ll_stats_pid_write(buf, len);
2214
2215         if (value == 0) {
2216                 sbi->ll_rw_stats_on = 0;
2217         } else {
2218                 if (!sbi->ll_rw_extents_info) {
2219                         int rc = alloc_rw_stats_info(sbi);
2220
2221                         if (rc)
2222                                 return rc;
2223                 }
2224                 sbi->ll_rw_stats_on = 1;
2225         }
2226
2227         spin_lock(&sbi->ll_pp_extent_lock);
2228         rw_extents = sbi->ll_rw_extents_info;
2229         if (rw_extents) {
2230                 rw_extents->pp_init = ktime_get();
2231                 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
2232                         rw_extents->pp_extents[i].pid = 0;
2233                         lprocfs_oh_clear(&rw_extents->pp_extents[i].pp_r_hist);
2234                         lprocfs_oh_clear(&rw_extents->pp_extents[i].pp_w_hist);
2235                 }
2236         }
2237         spin_unlock(&sbi->ll_pp_extent_lock);
2238
2239         return len;
2240 }
2241
2242 LDEBUGFS_SEQ_FOPS(ll_rw_extents_stats);
2243
2244 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
2245                        struct ll_file_data *file, loff_t pos,
2246                        size_t count, int rw)
2247 {
2248         int i, cur = -1;
2249         struct ll_rw_process_info *process;
2250         struct ll_rw_process_info *offset;
2251         int *off_count = &sbi->ll_rw_offset_entry_count;
2252         int *process_count = &sbi->ll_offset_process_count;
2253         struct ll_rw_extents_info *rw_extents;
2254
2255         if (!sbi->ll_rw_stats_on)
2256                 return;
2257
2258         spin_lock(&sbi->ll_pp_extent_lock);
2259         rw_extents = sbi->ll_rw_extents_info;
2260         if (!rw_extents) {
2261                 spin_unlock(&sbi->ll_pp_extent_lock);
2262                 return;
2263         }
2264
2265         /* Extent statistics */
2266         for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
2267                 if (rw_extents->pp_extents[i].pid == pid) {
2268                         cur = i;
2269                         break;
2270                 }
2271         }
2272
2273         if (cur == -1) {
2274                 /* new process */
2275                 sbi->ll_extent_process_count =
2276                         (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
2277                 cur = sbi->ll_extent_process_count;
2278                 rw_extents->pp_extents[cur].pid = pid;
2279                 lprocfs_oh_clear(&rw_extents->pp_extents[cur].pp_r_hist);
2280                 lprocfs_oh_clear(&rw_extents->pp_extents[cur].pp_w_hist);
2281         }
2282
2283         for (i = 0; (count >= 1 << (LL_HIST_START + i)) &&
2284              (i < (LL_HIST_MAX - 1)); i++);
2285         if (rw == 0) {
2286                 rw_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
2287                 rw_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
2288         } else {
2289                 rw_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
2290                 rw_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
2291         }
2292         spin_unlock(&sbi->ll_pp_extent_lock);
2293
2294         spin_lock(&sbi->ll_process_lock);
2295         process = sbi->ll_rw_process_info;
2296         offset = sbi->ll_rw_offset_info;
2297         if (!process || !offset)
2298                 goto out_unlock;
2299
2300         /* Offset statistics */
2301         for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
2302                 if (process[i].rw_pid == pid) {
2303                         if (process[i].rw_last_file != file) {
2304                                 process[i].rw_range_start = pos;
2305                                 process[i].rw_last_file_pos = pos + count;
2306                                 process[i].rw_smallest_extent = count;
2307                                 process[i].rw_largest_extent = count;
2308                                 process[i].rw_offset = 0;
2309                                 process[i].rw_last_file = file;
2310                                 goto out_unlock;
2311                         }
2312                         if (process[i].rw_last_file_pos != pos) {
2313                                 *off_count =
2314                                     (*off_count + 1) % LL_OFFSET_HIST_MAX;
2315                                 offset[*off_count].rw_op = process[i].rw_op;
2316                                 offset[*off_count].rw_pid = pid;
2317                                 offset[*off_count].rw_range_start =
2318                                         process[i].rw_range_start;
2319                                 offset[*off_count].rw_range_end =
2320                                         process[i].rw_last_file_pos;
2321                                 offset[*off_count].rw_smallest_extent =
2322                                         process[i].rw_smallest_extent;
2323                                 offset[*off_count].rw_largest_extent =
2324                                         process[i].rw_largest_extent;
2325                                 offset[*off_count].rw_offset =
2326                                         process[i].rw_offset;
2327                                 process[i].rw_op = rw;
2328                                 process[i].rw_range_start = pos;
2329                                 process[i].rw_smallest_extent = count;
2330                                 process[i].rw_largest_extent = count;
2331                                 process[i].rw_offset = pos -
2332                                         process[i].rw_last_file_pos;
2333                         }
2334                         if (process[i].rw_smallest_extent > count)
2335                                 process[i].rw_smallest_extent = count;
2336                         if (process[i].rw_largest_extent < count)
2337                                 process[i].rw_largest_extent = count;
2338                         process[i].rw_last_file_pos = pos + count;
2339                         goto out_unlock;
2340                 }
2341         }
2342         *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
2343         process[*process_count].rw_pid = pid;
2344         process[*process_count].rw_op = rw;
2345         process[*process_count].rw_range_start = pos;
2346         process[*process_count].rw_last_file_pos = pos + count;
2347         process[*process_count].rw_smallest_extent = count;
2348         process[*process_count].rw_largest_extent = count;
2349         process[*process_count].rw_offset = 0;
2350         process[*process_count].rw_last_file = file;
2351
2352 out_unlock:
2353         spin_unlock(&sbi->ll_process_lock);
2354 }
2355
2356 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
2357 {
2358         struct ll_sb_info *sbi = seq->private;
2359         struct ll_rw_process_info *offset;
2360         struct ll_rw_process_info *process;
2361         int i;
2362
2363         if (!sbi->ll_rw_stats_on) {
2364                 seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
2365                 return 0;
2366         }
2367
2368         spin_lock(&sbi->ll_process_lock);
2369         lprocfs_stats_header(seq, ktime_get(), sbi->ll_process_stats_init, 25,
2370                              ":", true);
2371         seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
2372                    "R/W", "PID", "RANGE START", "RANGE END",
2373                    "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
2374
2375         /* We stored the discontiguous offsets here; print them first */
2376         offset = sbi->ll_rw_offset_info;
2377         for (i = 0; offset && i < LL_OFFSET_HIST_MAX; i++) {
2378                 if (offset[i].rw_pid != 0)
2379                         seq_printf(seq,
2380                                   "%3c %10d %14llu %14llu %17lu %17lu %14lld\n",
2381                                    offset[i].rw_op == READ ? 'R' : 'W',
2382                                    offset[i].rw_pid,
2383                                    offset[i].rw_range_start,
2384                                    offset[i].rw_range_end,
2385                                    (unsigned long)offset[i].rw_smallest_extent,
2386                                    (unsigned long)offset[i].rw_largest_extent,
2387                                    offset[i].rw_offset);
2388         }
2389
2390         /* Then print the current offsets for each process */
2391         process = sbi->ll_rw_process_info;
2392         for (i = 0; process && i < LL_PROCESS_HIST_MAX; i++) {
2393                 if (process[i].rw_pid != 0)
2394                         seq_printf(seq,
2395                                   "%3c %10d %14llu %14llu %17lu %17lu %14lld\n",
2396                                    process[i].rw_op == READ ? 'R' : 'W',
2397                                    process[i].rw_pid,
2398                                    process[i].rw_range_start,
2399                                    process[i].rw_last_file_pos,
2400                                    (unsigned long)process[i].rw_smallest_extent,
2401                                    (unsigned long)process[i].rw_largest_extent,
2402                                    process[i].rw_offset);
2403         }
2404         spin_unlock(&sbi->ll_process_lock);
2405
2406         return 0;
2407 }
2408
2409 static ssize_t ll_rw_offset_stats_seq_write(struct file *file,
2410                                             const char __user *buf,
2411                                             size_t len, loff_t *off)
2412 {
2413         struct seq_file *seq = file->private_data;
2414         struct ll_sb_info *sbi = seq->private;
2415         __s64 value;
2416
2417         if (len == 0)
2418                 return -EINVAL;
2419
2420         value = ll_stats_pid_write(buf, len);
2421
2422         if (value == 0) {
2423                 sbi->ll_rw_stats_on = 0;
2424         } else {
2425                 if (!sbi->ll_rw_process_info || !sbi->ll_rw_offset_info) {
2426                         int rc = alloc_rw_stats_info(sbi);
2427
2428                         if (rc)
2429                                 return rc;
2430                 }
2431                 sbi->ll_rw_stats_on = 1;
2432         }
2433
2434         spin_lock(&sbi->ll_process_lock);
2435         sbi->ll_offset_process_count = 0;
2436         sbi->ll_rw_offset_entry_count = 0;
2437         sbi->ll_process_stats_init = ktime_get();
2438         if (sbi->ll_rw_process_info)
2439                 memset(sbi->ll_rw_process_info, 0,
2440                        sizeof(struct ll_rw_process_info) * LL_PROCESS_HIST_MAX);
2441         if (sbi->ll_rw_offset_info)
2442                 memset(sbi->ll_rw_offset_info, 0,
2443                        sizeof(struct ll_rw_process_info) * LL_OFFSET_HIST_MAX);
2444         spin_unlock(&sbi->ll_process_lock);
2445
2446         return len;
2447 }
2448
2449 LDEBUGFS_SEQ_FOPS(ll_rw_offset_stats);