Whamcloud - gitweb
LU-14793 hsm: record index for further HSM action scanning
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_lproc.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) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2015, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  *
31  * lustre/osd/osd_lproc.c
32  *
33  * Author: Mikhail Pershin <tappro@sun.com>
34  */
35
36 #define DEBUG_SUBSYSTEM S_OSD
37
38 #include <lprocfs_status.h>
39
40 #include "osd_internal.h"
41
42 #ifdef CONFIG_PROC_FS
43
44 void osd_brw_stats_update(struct osd_device *osd, struct osd_iobuf *iobuf)
45 {
46         struct brw_stats *bs = &osd->od_brw_stats;
47         sector_t         *last_block = NULL;
48         struct page     **pages = iobuf->dr_pages;
49         struct page      *last_page = NULL;
50         unsigned long     discont_pages = 0;
51         unsigned long     discont_blocks = 0;
52         sector_t         *blocks = iobuf->dr_blocks;
53         int               i, nr_pages = iobuf->dr_npages;
54         int               blocks_per_page;
55         int               rw = iobuf->dr_rw;
56
57         if (unlikely(nr_pages == 0))
58                 return;
59
60         blocks_per_page = PAGE_SIZE >> osd_sb(osd)->s_blocksize_bits;
61
62         lprocfs_oh_tally_log2(&bs->bs_hist[BRW_R_PAGES + rw], nr_pages);
63
64         while (nr_pages-- > 0) {
65                 if (last_page && (*pages)->index != (last_page->index + 1))
66                         discont_pages++;
67                 last_page = *pages;
68                 pages++;
69                 for (i = 0; i < blocks_per_page; i++) {
70                         if (last_block && *blocks != (*last_block + 1))
71                                 discont_blocks++;
72                         last_block = blocks++;
73                 }
74         }
75
76         lprocfs_oh_tally(&bs->bs_hist[BRW_R_DISCONT_PAGES+rw], discont_pages);
77         lprocfs_oh_tally(&bs->bs_hist[BRW_R_DISCONT_BLOCKS+rw], discont_blocks);
78 }
79
80 static void display_brw_stats(struct seq_file *seq, char *name, char *units,
81         struct obd_histogram *read, struct obd_histogram *write, int scale)
82 {
83         unsigned long read_tot, write_tot, r, w, read_cum = 0, write_cum = 0;
84         int i;
85
86         seq_printf(seq, "\n%26s read      |     write\n", " ");
87         seq_printf(seq, "%-22s %-5s %% cum %% |  %-11s %% cum %%\n",
88                    name, units, units);
89
90         read_tot = lprocfs_oh_sum(read);
91         write_tot = lprocfs_oh_sum(write);
92         for (i = 0; i < OBD_HIST_MAX; i++) {
93                 r = read->oh_buckets[i];
94                 w = write->oh_buckets[i];
95                 read_cum += r;
96                 write_cum += w;
97                 if (read_cum == 0 && write_cum == 0)
98                         continue;
99
100                 if (!scale)
101                         seq_printf(seq, "%u", i);
102                 else if (i < 10)
103                         seq_printf(seq, "%u", scale << i);
104                 else if (i < 20)
105                         seq_printf(seq, "%uK", scale << (i-10));
106                 else
107                         seq_printf(seq, "%uM", scale << (i-20));
108
109                 seq_printf(seq, ":\t\t%10lu %3u %3u   | %4lu %3u %3u\n",
110                            r, pct(r, read_tot), pct(read_cum, read_tot),
111                            w, pct(w, write_tot), pct(write_cum, write_tot));
112
113                 if (read_cum == read_tot && write_cum == write_tot)
114                         break;
115         }
116 }
117
118 static void brw_stats_show(struct seq_file *seq, struct brw_stats *brw_stats)
119 {
120         /* this sampling races with updates */
121         lprocfs_stats_header(seq, ktime_get(), brw_stats->bs_init, 25, ":", 1);
122
123         display_brw_stats(seq, "pages per bulk r/w", "rpcs",
124                           &brw_stats->bs_hist[BRW_R_PAGES],
125                           &brw_stats->bs_hist[BRW_W_PAGES], 1);
126
127         display_brw_stats(seq, "discontiguous pages", "rpcs",
128                           &brw_stats->bs_hist[BRW_R_DISCONT_PAGES],
129                           &brw_stats->bs_hist[BRW_W_DISCONT_PAGES], 0);
130
131         display_brw_stats(seq, "discontiguous blocks", "rpcs",
132                           &brw_stats->bs_hist[BRW_R_DISCONT_BLOCKS],
133                           &brw_stats->bs_hist[BRW_W_DISCONT_BLOCKS], 0);
134
135         display_brw_stats(seq, "disk fragmented I/Os", "ios",
136                           &brw_stats->bs_hist[BRW_R_DIO_FRAGS],
137                           &brw_stats->bs_hist[BRW_W_DIO_FRAGS], 0);
138
139         display_brw_stats(seq, "disk I/Os in flight", "ios",
140                           &brw_stats->bs_hist[BRW_R_RPC_HIST],
141                           &brw_stats->bs_hist[BRW_W_RPC_HIST], 0);
142
143         display_brw_stats(seq, "I/O time (1/1000s)", "ios",
144                           &brw_stats->bs_hist[BRW_R_IO_TIME],
145                           &brw_stats->bs_hist[BRW_W_IO_TIME], 1);
146
147         display_brw_stats(seq, "disk I/O size", "ios",
148                           &brw_stats->bs_hist[BRW_R_DISK_IOSIZE],
149                           &brw_stats->bs_hist[BRW_W_DISK_IOSIZE], 1);
150 }
151
152 static int osd_brw_stats_seq_show(struct seq_file *seq, void *v)
153 {
154         struct osd_device *osd = seq->private;
155
156         brw_stats_show(seq, &osd->od_brw_stats);
157
158         return 0;
159 }
160
161 static ssize_t osd_brw_stats_seq_write(struct file *file,
162                                        const char __user *buf,
163                                        size_t len, loff_t *off)
164 {
165         struct seq_file *seq = file->private_data;
166         struct osd_device *osd = seq->private;
167         int i;
168
169         for (i = 0; i < BRW_LAST; i++)
170                 lprocfs_oh_clear(&osd->od_brw_stats.bs_hist[i]);
171         osd->od_brw_stats.bs_init = ktime_get();
172
173         return len;
174 }
175
176 LPROC_SEQ_FOPS(osd_brw_stats);
177
178 static int osd_stats_init(struct osd_device *osd)
179 {
180         int i, result;
181
182         ENTRY;
183         osd->od_brw_stats.bs_init = ktime_get();
184
185         for (i = 0; i < BRW_LAST; i++)
186                 spin_lock_init(&osd->od_brw_stats.bs_hist[i].oh_lock);
187
188         osd->od_stats = lprocfs_alloc_stats(LPROC_OSD_LAST, 0);
189         if (osd->od_stats != NULL) {
190                 result = lprocfs_register_stats(osd->od_proc_entry, "stats",
191                                                 osd->od_stats);
192                 if (result)
193                         GOTO(out, result);
194
195                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_GET_PAGE,
196                                      LPROCFS_CNTR_AVGMINMAX|LPROCFS_CNTR_STDDEV,
197                                      "get_page", "usec");
198                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_NO_PAGE,
199                                      LPROCFS_CNTR_AVGMINMAX,
200                                      "get_page_failures", "num");
201                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_ACCESS,
202                                      LPROCFS_CNTR_AVGMINMAX,
203                                      "cache_access", "pages");
204                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_HIT,
205                                      LPROCFS_CNTR_AVGMINMAX,
206                                      "cache_hit", "pages");
207                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_MISS,
208                                      LPROCFS_CNTR_AVGMINMAX,
209                                      "cache_miss", "pages");
210 #if OSD_THANDLE_STATS
211                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_STARTING,
212                                      LPROCFS_CNTR_AVGMINMAX,
213                                      "thandle starting", "usec");
214                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_OPEN,
215                                      LPROCFS_CNTR_AVGMINMAX,
216                                      "thandle open", "usec");
217                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_CLOSING,
218                                      LPROCFS_CNTR_AVGMINMAX,
219                                      "thandle closing", "usec");
220 #endif
221                 result = lprocfs_seq_create(osd->od_proc_entry, "brw_stats",
222                                             0644, &osd_brw_stats_fops, osd);
223         } else
224                 result = -ENOMEM;
225
226 out:
227         RETURN(result);
228 }
229
230 static ssize_t fstype_show(struct kobject *kobj, struct attribute *attr,
231                            char *buf)
232 {
233         return sprintf(buf, "ldiskfs\n");
234 }
235 LUSTRE_RO_ATTR(fstype);
236
237 static ssize_t mntdev_show(struct kobject *kobj, struct attribute *attr,
238                            char *buf)
239 {
240         struct dt_device *dt = container_of(kobj, struct dt_device,
241                                             dd_kobj);
242         struct osd_device *osd = osd_dt_dev(dt);
243
244         LASSERT(osd);
245         if (unlikely(!osd->od_mnt))
246                 return -EINPROGRESS;
247
248         return sprintf(buf, "%s\n", osd->od_mntdev);
249 }
250 LUSTRE_RO_ATTR(mntdev);
251
252 static ssize_t read_cache_enable_show(struct kobject *kobj,
253                                       struct attribute *attr,
254                                       char *buf)
255 {
256         struct dt_device *dt = container_of(kobj, struct dt_device,
257                                             dd_kobj);
258         struct osd_device *osd = osd_dt_dev(dt);
259
260         LASSERT(osd);
261         if (unlikely(!osd->od_mnt))
262                 return -EINPROGRESS;
263
264         return sprintf(buf, "%u\n", osd->od_read_cache);
265 }
266
267 static ssize_t read_cache_enable_store(struct kobject *kobj,
268                                        struct attribute *attr,
269                                        const char *buffer, size_t count)
270 {
271         struct dt_device *dt = container_of(kobj, struct dt_device,
272                                             dd_kobj);
273         struct osd_device *osd = osd_dt_dev(dt);
274         bool val;
275         int rc;
276
277         LASSERT(osd);
278         if (unlikely(!osd->od_mnt))
279                 return -EINPROGRESS;
280
281         rc = kstrtobool(buffer, &val);
282         if (rc)
283                 return rc;
284
285         osd->od_read_cache = !!val;
286         return count;
287 }
288 LUSTRE_RW_ATTR(read_cache_enable);
289
290 static ssize_t writethrough_cache_enable_show(struct kobject *kobj,
291                                               struct attribute *attr,
292                                               char *buf)
293 {
294         struct dt_device *dt = container_of(kobj, struct dt_device,
295                                             dd_kobj);
296         struct osd_device *osd = osd_dt_dev(dt);
297
298         LASSERT(osd);
299         if (unlikely(!osd->od_mnt))
300                 return -EINPROGRESS;
301
302         return sprintf(buf, "%u\n", osd->od_writethrough_cache);
303 }
304
305 static ssize_t writethrough_cache_enable_store(struct kobject *kobj,
306                                                struct attribute *attr,
307                                                const char *buffer,
308                                                size_t count)
309 {
310         struct dt_device *dt = container_of(kobj, struct dt_device,
311                                             dd_kobj);
312         struct osd_device *osd = osd_dt_dev(dt);
313         bool val;
314         int rc;
315
316         LASSERT(osd);
317         if (unlikely(!osd->od_mnt))
318                 return -EINPROGRESS;
319
320         rc = kstrtobool(buffer, &val);
321         if (rc)
322                 return rc;
323
324         osd->od_writethrough_cache = !!val;
325         return count;
326 }
327 LUSTRE_RW_ATTR(writethrough_cache_enable);
328
329 static ssize_t fallocate_zero_blocks_show(struct kobject *kobj,
330                                           struct attribute *attr,
331                                           char *buf)
332 {
333         struct dt_device *dt = container_of(kobj, struct dt_device,
334                                             dd_kobj);
335         struct osd_device *osd = osd_dt_dev(dt);
336
337         LASSERT(osd);
338         if (unlikely(!osd->od_mnt))
339                 return -EINPROGRESS;
340
341         return scnprintf(buf, PAGE_SIZE, "%d\n", osd->od_fallocate_zero_blocks);
342 }
343
344 /*
345  * Set how fallocate() interacts with the backing filesystem:
346  * -1: fallocate is disabled and returns -EOPNOTSUPP
347  *  0: fallocate allocates unwritten extents (like ext4)
348  *  1: fallocate zeroes allocated extents on disk
349  */
350 static ssize_t fallocate_zero_blocks_store(struct kobject *kobj,
351                                            struct attribute *attr,
352                                            const char *buffer, size_t count)
353 {
354         struct dt_device *dt = container_of(kobj, struct dt_device,
355                                             dd_kobj);
356         struct osd_device *osd = osd_dt_dev(dt);
357         long val;
358         int rc;
359
360         LASSERT(osd);
361         if (unlikely(!osd->od_mnt))
362                 return -EINPROGRESS;
363
364         rc = kstrtol(buffer, 0, &val);
365         if (rc)
366                 return rc;
367
368         if (val < -1 || val > 1)
369                 return -EINVAL;
370
371         osd->od_fallocate_zero_blocks = val;
372         return count;
373 }
374 LUSTRE_RW_ATTR(fallocate_zero_blocks);
375
376 ssize_t force_sync_store(struct kobject *kobj, struct attribute *attr,
377                          const char *buffer, size_t count)
378 {
379         struct dt_device *dt = container_of(kobj, struct dt_device,
380                                             dd_kobj);
381         struct osd_device *osd = osd_dt_dev(dt);
382         struct lu_env env;
383         int rc;
384
385         LASSERT(osd);
386         if (unlikely(!osd->od_mnt))
387                 return -EINPROGRESS;
388
389         rc = lu_env_init(&env, LCT_LOCAL);
390         if (rc)
391                 return rc;
392
393         rc = dt_sync(&env, dt);
394         lu_env_fini(&env);
395
396         return rc == 0 ? count : rc;
397 }
398 LUSTRE_WO_ATTR(force_sync);
399
400 static ssize_t nonrotational_show(struct kobject *kobj, struct attribute *attr,
401                                   char *buf)
402 {
403         struct dt_device *dt = container_of(kobj, struct dt_device,
404                                             dd_kobj);
405         struct osd_device *osd = osd_dt_dev(dt);
406
407         LASSERT(osd);
408         if (unlikely(!osd->od_mnt))
409                 return -EINPROGRESS;
410
411         return sprintf(buf, "%u\n", osd->od_nonrotational);
412 }
413
414 static ssize_t nonrotational_store(struct kobject *kobj,
415                                    struct attribute *attr, const char *buffer,
416                                    size_t count)
417 {
418         struct dt_device *dt = container_of(kobj, struct dt_device,
419                                             dd_kobj);
420         struct osd_device *osd = osd_dt_dev(dt);
421         bool val;
422         int rc;
423
424         LASSERT(osd);
425         if (unlikely(!osd->od_mnt))
426                 return -EINPROGRESS;
427
428         rc = kstrtobool(buffer, &val);
429         if (rc)
430                 return rc;
431
432         osd->od_nonrotational = val;
433         return count;
434 }
435 LUSTRE_RW_ATTR(nonrotational);
436
437 static ssize_t pdo_show(struct kobject *kobj, struct attribute *attr,
438                         char *buf)
439 {
440         return sprintf(buf, "%s\n", ldiskfs_pdo ? "ON" : "OFF");
441 }
442
443 static ssize_t pdo_store(struct kobject *kobj, struct attribute *attr,
444                          const char *buffer, size_t count)
445 {
446         bool pdo;
447         int rc;
448
449         rc = kstrtobool(buffer, &pdo);
450         if (rc != 0)
451                 return rc;
452
453         ldiskfs_pdo = pdo;
454
455         return count;
456 }
457 LUSTRE_RW_ATTR(pdo);
458
459 static ssize_t auto_scrub_show(struct kobject *kobj, struct attribute *attr,
460                                char *buf)
461 {
462         struct dt_device *dt = container_of(kobj, struct dt_device,
463                                             dd_kobj);
464         struct osd_device *dev = osd_dt_dev(dt);
465
466         LASSERT(dev);
467         if (unlikely(!dev->od_mnt))
468                 return -EINPROGRESS;
469
470         return scnprintf(buf, PAGE_SIZE, "%lld\n",
471                          dev->od_scrub.os_scrub.os_auto_scrub_interval);
472 }
473
474 static ssize_t auto_scrub_store(struct kobject *kobj, struct attribute *attr,
475                                 const char *buffer, size_t count)
476 {
477         struct dt_device *dt = container_of(kobj, struct dt_device,
478                                             dd_kobj);
479         struct osd_device *dev = osd_dt_dev(dt);
480         s64 val;
481         int rc;
482
483         LASSERT(dev);
484         if (unlikely(!dev->od_mnt))
485                 return -EINPROGRESS;
486
487         rc = kstrtoll(buffer, 0, &val);
488         if (rc)
489                 return rc;
490
491         dev->od_scrub.os_scrub.os_auto_scrub_interval = val;
492         return count;
493 }
494 LUSTRE_RW_ATTR(auto_scrub);
495
496 static ssize_t full_scrub_ratio_show(struct kobject *kobj,
497                                      struct attribute *attr,
498                                      char *buf)
499 {
500         struct dt_device *dt = container_of(kobj, struct dt_device,
501                                             dd_kobj);
502         struct osd_device *dev = osd_dt_dev(dt);
503
504         LASSERT(dev);
505         if (unlikely(!dev->od_mnt))
506                 return -EINPROGRESS;
507
508         return sprintf(buf, "%llu\n", dev->od_full_scrub_ratio);
509 }
510
511 static ssize_t full_scrub_ratio_store(struct kobject *kobj,
512                                       struct attribute *attr,
513                                       const char *buffer, size_t count)
514 {
515         struct dt_device *dt = container_of(kobj, struct dt_device,
516                                             dd_kobj);
517         struct osd_device *dev = osd_dt_dev(dt);
518         s64 val;
519         int rc;
520
521         LASSERT(dev);
522         if (unlikely(!dev->od_mnt))
523                 return -EINPROGRESS;
524
525         rc = kstrtoll(buffer, 0, &val);
526         if (rc)
527                 return rc;
528
529         if (val < 0)
530                 return -EINVAL;
531
532         dev->od_full_scrub_ratio = val;
533         return count;
534 }
535 LUSTRE_RW_ATTR(full_scrub_ratio);
536
537 static ssize_t full_scrub_threshold_rate_show(struct kobject *kobj,
538                                               struct attribute *attr,
539                                               char *buf)
540 {
541         struct dt_device *dt = container_of(kobj, struct dt_device,
542                                             dd_kobj);
543         struct osd_device *dev = osd_dt_dev(dt);
544
545         LASSERT(dev);
546         if (unlikely(!dev->od_mnt))
547                 return -EINPROGRESS;
548
549         return sprintf(buf, "%llu (bad OI mappings/minute)\n",
550                        dev->od_full_scrub_threshold_rate);
551 }
552
553 static ssize_t full_scrub_threshold_rate_store(struct kobject *kobj,
554                                                struct attribute *attr,
555                                                const char *buffer, size_t count)
556 {
557         struct dt_device *dt = container_of(kobj, struct dt_device,
558                                             dd_kobj);
559         struct osd_device *dev = osd_dt_dev(dt);
560         u64 val;
561         int rc;
562
563         LASSERT(dev);
564         if (unlikely(!dev->od_mnt))
565                 return -EINPROGRESS;
566
567         rc = kstrtoull(buffer, 0, &val);
568         if (rc != 0)
569                 return rc;
570
571         dev->od_full_scrub_threshold_rate = val;
572         return count;
573 }
574 LUSTRE_RW_ATTR(full_scrub_threshold_rate);
575
576 static ssize_t extent_bytes_allocation_show(struct kobject *kobj,
577                                             struct attribute *attr, char *buf)
578 {
579         struct dt_device *dt = container_of(kobj, struct dt_device,
580                                             dd_kobj);
581         struct osd_device *dev = osd_dt_dev(dt);
582         int i;
583         unsigned int min = (unsigned int)(~0), cur;
584
585         for_each_online_cpu(i) {
586                 cur = *per_cpu_ptr(dev->od_extent_bytes_percpu, i);
587                 if (cur < min)
588                         min = cur;
589         }
590         return snprintf(buf, PAGE_SIZE, "%u\n", min);
591 }
592 LUSTRE_RO_ATTR(extent_bytes_allocation);
593
594 static int ldiskfs_osd_oi_scrub_seq_show(struct seq_file *m, void *data)
595 {
596         struct osd_device *dev = osd_dt_dev((struct dt_device *)m->private);
597
598         LASSERT(dev != NULL);
599         if (unlikely(dev->od_mnt == NULL))
600                 return -EINPROGRESS;
601
602         osd_scrub_dump(m, dev);
603         return 0;
604 }
605
606 LDEBUGFS_SEQ_FOPS_RO(ldiskfs_osd_oi_scrub);
607
608 static int ldiskfs_osd_readcache_seq_show(struct seq_file *m, void *data)
609 {
610         struct osd_device *osd = osd_dt_dev((struct dt_device *)m->private);
611
612         LASSERT(osd != NULL);
613         if (unlikely(osd->od_mnt == NULL))
614                 return -EINPROGRESS;
615
616         seq_printf(m, "%llu\n", osd->od_readcache_max_filesize);
617         return 0;
618 }
619
620 static ssize_t
621 ldiskfs_osd_readcache_seq_write(struct file *file, const char __user *buffer,
622                                 size_t count, loff_t *off)
623 {
624         struct seq_file *m = file->private_data;
625         struct dt_device *dt = m->private;
626         struct osd_device *osd = osd_dt_dev(dt);
627         char kernbuf[22] = "";
628         u64 val;
629         int rc;
630
631         LASSERT(osd != NULL);
632         if (unlikely(osd->od_mnt == NULL))
633                 return -EINPROGRESS;
634
635         if (count >= sizeof(kernbuf))
636                 return -EINVAL;
637
638         if (copy_from_user(kernbuf, buffer, count))
639                 return -EFAULT;
640         kernbuf[count] = 0;
641
642         rc = sysfs_memparse(kernbuf, count, &val, "B");
643         if (rc < 0)
644                 return rc;
645
646         osd->od_readcache_max_filesize = val > OSD_MAX_CACHE_SIZE ?
647                                          OSD_MAX_CACHE_SIZE : val;
648         return count;
649 }
650
651 LDEBUGFS_SEQ_FOPS(ldiskfs_osd_readcache);
652
653 static int ldiskfs_osd_readcache_max_io_seq_show(struct seq_file *m, void *data)
654 {
655         struct osd_device *osd = osd_dt_dev((struct dt_device *)m->private);
656
657         LASSERT(osd != NULL);
658         if (unlikely(osd->od_mnt == NULL))
659                 return -EINPROGRESS;
660
661         seq_printf(m, "%lu\n", osd->od_readcache_max_iosize >> 20);
662         return 0;
663 }
664
665 static ssize_t
666 ldiskfs_osd_readcache_max_io_seq_write(struct file *file,
667                                        const char __user *buffer,
668                                        size_t count, loff_t *off)
669 {
670         struct seq_file *m = file->private_data;
671         struct dt_device *dt = m->private;
672         struct osd_device *osd = osd_dt_dev(dt);
673         char kernbuf[22] = "";
674         u64 val;
675         int rc;
676
677         LASSERT(osd != NULL);
678         if (unlikely(osd->od_mnt == NULL))
679                 return -EINPROGRESS;
680
681         if (count >= sizeof(kernbuf))
682                 return -EINVAL;
683
684         if (copy_from_user(kernbuf, buffer, count))
685                 return -EFAULT;
686         kernbuf[count] = 0;
687
688         rc = sysfs_memparse(kernbuf, count, &val, "MiB");
689         if (rc < 0)
690                 return rc;
691
692         if (val > PTLRPC_MAX_BRW_SIZE)
693                 return -ERANGE;
694         osd->od_readcache_max_iosize = val;
695         return count;
696 }
697
698 LDEBUGFS_SEQ_FOPS(ldiskfs_osd_readcache_max_io);
699
700 static int ldiskfs_osd_writethrough_max_io_seq_show(struct seq_file *m,
701                                                     void *data)
702 {
703         struct osd_device *osd = osd_dt_dev((struct dt_device *)m->private);
704
705         LASSERT(osd != NULL);
706         if (unlikely(osd->od_mnt == NULL))
707                 return -EINPROGRESS;
708
709         seq_printf(m, "%lu\n", osd->od_writethrough_max_iosize >> 20);
710         return 0;
711 }
712
713 static ssize_t
714 ldiskfs_osd_writethrough_max_io_seq_write(struct file *file,
715                                        const char __user *buffer,
716                                        size_t count, loff_t *off)
717 {
718         struct seq_file *m = file->private_data;
719         struct dt_device *dt = m->private;
720         struct osd_device *osd = osd_dt_dev(dt);
721         char kernbuf[22] = "";
722         u64 val;
723         int rc;
724
725         LASSERT(osd != NULL);
726         if (unlikely(osd->od_mnt == NULL))
727                 return -EINPROGRESS;
728
729         if (count >= sizeof(kernbuf))
730                 return -EINVAL;
731
732         if (copy_from_user(kernbuf, buffer, count))
733                 return -EFAULT;
734         kernbuf[count] = 0;
735
736         rc = sysfs_memparse(kernbuf, count, &val, "MiB");
737         if (rc < 0)
738                 return rc;
739
740         if (val > PTLRPC_MAX_BRW_SIZE)
741                 return -ERANGE;
742         osd->od_writethrough_max_iosize = val;
743         return count;
744 }
745
746 LDEBUGFS_SEQ_FOPS(ldiskfs_osd_writethrough_max_io);
747
748 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 52, 0)
749 static ssize_t index_in_idif_show(struct kobject *kobj, struct attribute *attr,
750                                   char *buf)
751 {
752         struct dt_device *dt = container_of(kobj, struct dt_device,
753                                             dd_kobj);
754         struct osd_device *dev = osd_dt_dev(dt);
755
756         LASSERT(dev);
757         if (unlikely(!dev->od_mnt))
758                 return -EINPROGRESS;
759
760         return sprintf(buf, "%d\n", (int)(dev->od_index_in_idif));
761 }
762
763 static ssize_t index_in_idif_store(struct kobject *kobj,
764                                    struct attribute *attr,
765                                    const char *buffer, size_t count)
766 {
767         struct dt_device *dt = container_of(kobj, struct dt_device,
768                                             dd_kobj);
769         struct osd_device *dev = osd_dt_dev(dt);
770         struct lu_target *tgt;
771         struct lu_env env;
772         bool val;
773         int rc;
774
775         LASSERT(dev);
776         if (unlikely(!dev->od_mnt))
777                 return -EINPROGRESS;
778
779         rc = kstrtobool(buffer, &val);
780         if (rc)
781                 return rc;
782
783         if (dev->od_index_in_idif) {
784                 if (val)
785                         return count;
786
787                 LCONSOLE_WARN("%s: OST-index in IDIF has been enabled, "
788                               "it cannot be reverted back.\n", osd_name(dev));
789                 return -EPERM;
790         }
791
792         if (!val)
793                 return count;
794
795         rc = lu_env_init(&env, LCT_DT_THREAD);
796         if (rc)
797                 return rc;
798
799         tgt = dev->od_dt_dev.dd_lu_dev.ld_site->ls_tgt;
800         tgt->lut_lsd.lsd_feature_rocompat |= OBD_ROCOMPAT_IDX_IN_IDIF;
801         rc = tgt_server_data_update(&env, tgt, 1);
802         lu_env_fini(&env);
803         if (rc < 0)
804                 return rc;
805
806         LCONSOLE_INFO("%s: enable OST-index in IDIF successfully, "
807                       "it cannot be reverted back.\n", osd_name(dev));
808
809         dev->od_index_in_idif = 1;
810         return count;
811 }
812 LUSTRE_RW_ATTR(index_in_idif);
813
814 int osd_register_proc_index_in_idif(struct osd_device *osd)
815 {
816         struct dt_device *dt = &osd->od_dt_dev;
817
818         return sysfs_create_file(&dt->dd_kobj, &lustre_attr_index_in_idif.attr);
819 }
820 #endif
821
822 static ssize_t index_backup_show(struct kobject *kobj, struct attribute *attr,
823                                  char *buf)
824 {
825         struct dt_device *dt = container_of(kobj, struct dt_device,
826                                             dd_kobj);
827         struct osd_device *dev = osd_dt_dev(dt);
828
829         LASSERT(dev);
830         if (unlikely(!dev->od_mnt))
831                 return -EINPROGRESS;
832
833         return sprintf(buf, "%d\n", dev->od_index_backup_policy);
834 }
835
836 ssize_t index_backup_store(struct kobject *kobj, struct attribute *attr,
837                            const char *buffer, size_t count)
838 {
839         struct dt_device *dt = container_of(kobj, struct dt_device,
840                                            dd_kobj);
841         struct osd_device *dev = osd_dt_dev(dt);
842         int val;
843         int rc;
844
845         LASSERT(dev);
846         if (unlikely(!dev->od_mnt))
847                 return -EINPROGRESS;
848
849         rc = kstrtoint(buffer, 0, &val);
850         if (rc)
851                 return rc;
852
853         dev->od_index_backup_policy = val;
854         return count;
855 }
856 LUSTRE_RW_ATTR(index_backup);
857
858 struct ldebugfs_vars ldebugfs_osd_obd_vars[] = {
859         { .name =       "oi_scrub",
860           .fops =       &ldiskfs_osd_oi_scrub_fops      },
861         { .name =       "readcache_max_filesize",
862           .fops =       &ldiskfs_osd_readcache_fops     },
863         { .name =       "readcache_max_io_mb",
864           .fops =       &ldiskfs_osd_readcache_max_io_fops      },
865         { .name =       "writethrough_max_io_mb",
866           .fops =       &ldiskfs_osd_writethrough_max_io_fops   },
867         { NULL }
868 };
869
870 static struct attribute *ldiskfs_attrs[] = {
871         &lustre_attr_read_cache_enable.attr,
872         &lustre_attr_writethrough_cache_enable.attr,
873         &lustre_attr_fstype.attr,
874         &lustre_attr_mntdev.attr,
875         &lustre_attr_fallocate_zero_blocks.attr,
876         &lustre_attr_force_sync.attr,
877         &lustre_attr_nonrotational.attr,
878         &lustre_attr_index_backup.attr,
879         &lustre_attr_auto_scrub.attr,
880         &lustre_attr_pdo.attr,
881         &lustre_attr_full_scrub_ratio.attr,
882         &lustre_attr_full_scrub_threshold_rate.attr,
883         &lustre_attr_extent_bytes_allocation.attr,
884         NULL,
885 };
886
887 int osd_procfs_init(struct osd_device *osd, const char *name)
888 {
889         struct obd_type *type;
890         int rc;
891
892         ENTRY;
893
894         /* at the moment there is no linkage between lu_type
895          * and obd_type, so we lookup obd_type this way
896          */
897         type = class_search_type(LUSTRE_OSD_LDISKFS_NAME);
898
899         LASSERT(name);
900         LASSERT(type);
901
902         CDEBUG(D_CONFIG, "%s: register osd-ldiskfs tunable parameters\n", name);
903
904         /* put reference taken by class_search_type */
905         kobject_put(&type->typ_kobj);
906
907         osd->od_dt_dev.dd_ktype.default_attrs = ldiskfs_attrs;
908         rc = dt_tunables_init(&osd->od_dt_dev, type, name,
909                               ldebugfs_osd_obd_vars);
910         if (rc) {
911                 CERROR("%s: cannot setup sysfs / debugfs entry: %d\n",
912                        name, rc);
913                 GOTO(out, rc);
914         }
915
916         if (osd->od_proc_entry)
917                 RETURN(0);
918
919         /* Find the type procroot and add the proc entry for this device */
920         osd->od_proc_entry = lprocfs_register(name, type->typ_procroot,
921                                               NULL, &osd->od_dt_dev);
922         if (IS_ERR(osd->od_proc_entry)) {
923                 rc = PTR_ERR(osd->od_proc_entry);
924                 CERROR("Error %d setting up lprocfs for %s\n",
925                        rc, name);
926                 osd->od_proc_entry = NULL;
927                 GOTO(out, rc);
928         }
929
930         rc = osd_stats_init(osd);
931
932         EXIT;
933 out:
934         if (rc)
935                 osd_procfs_fini(osd);
936         return rc;
937 }
938
939 int osd_procfs_fini(struct osd_device *osd)
940 {
941         if (osd->od_stats)
942                 lprocfs_free_stats(&osd->od_stats);
943
944         if (osd->od_proc_entry)
945                 lprocfs_remove(&osd->od_proc_entry);
946
947         return dt_tunables_fini(&osd->od_dt_dev);
948 }
949 #endif