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