Whamcloud - gitweb
LU-11963 osd: Add nonrotational flag to statfs
[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         s64 val;
565         int rc;
566
567         LASSERT(osd != NULL);
568         if (unlikely(osd->od_mnt == NULL))
569                 return -EINPROGRESS;
570
571         rc = lprocfs_str_with_units_to_s64(buffer, count, &val, '1');
572         if (rc)
573                 return rc;
574         if (val < 0)
575                 return -ERANGE;
576
577         osd->od_readcache_max_filesize = val > OSD_MAX_CACHE_SIZE ?
578                                          OSD_MAX_CACHE_SIZE : val;
579         return count;
580 }
581
582 LDEBUGFS_SEQ_FOPS(ldiskfs_osd_readcache);
583
584 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 52, 0)
585 static ssize_t index_in_idif_show(struct kobject *kobj, struct attribute *attr,
586                                   char *buf)
587 {
588         struct dt_device *dt = container_of(kobj, struct dt_device,
589                                             dd_kobj);
590         struct osd_device *dev = osd_dt_dev(dt);
591
592         LASSERT(dev);
593         if (unlikely(!dev->od_mnt))
594                 return -EINPROGRESS;
595
596         return sprintf(buf, "%d\n", (int)(dev->od_index_in_idif));
597 }
598
599 static ssize_t index_in_idif_store(struct kobject *kobj,
600                                    struct attribute *attr,
601                                    const char *buffer, size_t count)
602 {
603         struct dt_device *dt = container_of(kobj, struct dt_device,
604                                             dd_kobj);
605         struct osd_device *dev = osd_dt_dev(dt);
606         struct lu_target *tgt;
607         struct lu_env env;
608         bool val;
609         int rc;
610
611         LASSERT(dev);
612         if (unlikely(!dev->od_mnt))
613                 return -EINPROGRESS;
614
615         rc = kstrtobool(buffer, &val);
616         if (rc)
617                 return rc;
618
619         if (dev->od_index_in_idif) {
620                 if (val)
621                         return count;
622
623                 LCONSOLE_WARN("%s: OST-index in IDIF has been enabled, "
624                               "it cannot be reverted back.\n", osd_name(dev));
625                 return -EPERM;
626         }
627
628         if (!val)
629                 return count;
630
631         rc = lu_env_init(&env, LCT_DT_THREAD);
632         if (rc)
633                 return rc;
634
635         tgt = dev->od_dt_dev.dd_lu_dev.ld_site->ls_tgt;
636         tgt->lut_lsd.lsd_feature_rocompat |= OBD_ROCOMPAT_IDX_IN_IDIF;
637         rc = tgt_server_data_update(&env, tgt, 1);
638         lu_env_fini(&env);
639         if (rc < 0)
640                 return rc;
641
642         LCONSOLE_INFO("%s: enable OST-index in IDIF successfully, "
643                       "it cannot be reverted back.\n", osd_name(dev));
644
645         dev->od_index_in_idif = 1;
646         return count;
647 }
648 LUSTRE_RW_ATTR(index_in_idif);
649
650 int osd_register_proc_index_in_idif(struct osd_device *osd)
651 {
652         struct dt_device *dt = &osd->od_dt_dev;
653
654         return sysfs_create_file(&dt->dd_kobj, &lustre_attr_index_in_idif.attr);
655 }
656 #endif
657
658 static ssize_t index_backup_show(struct kobject *kobj, struct attribute *attr,
659                                  char *buf)
660 {
661         struct dt_device *dt = container_of(kobj, struct dt_device,
662                                             dd_kobj);
663         struct osd_device *dev = osd_dt_dev(dt);
664
665         LASSERT(dev);
666         if (unlikely(!dev->od_mnt))
667                 return -EINPROGRESS;
668
669         return sprintf(buf, "%d\n", dev->od_index_backup_policy);
670 }
671
672 ssize_t index_backup_store(struct kobject *kobj, struct attribute *attr,
673                            const char *buffer, size_t count)
674 {
675         struct dt_device *dt = container_of(kobj, struct dt_device,
676                                            dd_kobj);
677         struct osd_device *dev = osd_dt_dev(dt);
678         int val;
679         int rc;
680
681         LASSERT(dev);
682         if (unlikely(!dev->od_mnt))
683                 return -EINPROGRESS;
684
685         rc = kstrtoint(buffer, 0, &val);
686         if (rc)
687                 return rc;
688
689         dev->od_index_backup_policy = val;
690         return count;
691 }
692 LUSTRE_RW_ATTR(index_backup);
693
694 struct lprocfs_vars lprocfs_osd_obd_vars[] = {
695         { .name =       "oi_scrub",
696           .fops =       &ldiskfs_osd_oi_scrub_fops      },
697         { .name =       "readcache_max_filesize",
698           .fops =       &ldiskfs_osd_readcache_fops     },
699         { NULL }
700 };
701
702 static struct attribute *ldiskfs_attrs[] = {
703         &lustre_attr_read_cache_enable.attr,
704         &lustre_attr_writethrough_cache_enable.attr,
705         &lustre_attr_fstype.attr,
706         &lustre_attr_mntdev.attr,
707         &lustre_attr_force_sync.attr,
708         &lustre_attr_nonrotational.attr,
709         &lustre_attr_index_backup.attr,
710         &lustre_attr_auto_scrub.attr,
711         &lustre_attr_pdo.attr,
712         &lustre_attr_full_scrub_ratio.attr,
713         &lustre_attr_full_scrub_threshold_rate.attr,
714         NULL,
715 };
716
717 int osd_procfs_init(struct osd_device *osd, const char *name)
718 {
719         struct obd_type *type;
720         int rc;
721
722         ENTRY;
723
724         /* at the moment there is no linkage between lu_type
725          * and obd_type, so we lookup obd_type this way
726          */
727         type = class_search_type(LUSTRE_OSD_LDISKFS_NAME);
728
729         LASSERT(name);
730         LASSERT(type);
731
732         LCONSOLE_INFO("osd-ldiskfs create tunables for %s\n", name);
733
734         osd->od_dt_dev.dd_ktype.default_attrs = ldiskfs_attrs;
735         rc = dt_tunables_init(&osd->od_dt_dev, type, name,
736                               lprocfs_osd_obd_vars);
737         if (rc) {
738                 CERROR("%s: cannot setup sysfs / debugfs entry: %d\n",
739                        name, rc);
740                 GOTO(out, rc);
741         }
742
743         if (osd->od_proc_entry)
744                 RETURN(0);
745
746         /* Find the type procroot and add the proc entry for this device */
747         osd->od_proc_entry = lprocfs_register(name, type->typ_procroot,
748                                               NULL, &osd->od_dt_dev);
749         if (IS_ERR(osd->od_proc_entry)) {
750                 rc = PTR_ERR(osd->od_proc_entry);
751                 CERROR("Error %d setting up lprocfs for %s\n",
752                        rc, name);
753                 osd->od_proc_entry = NULL;
754                 GOTO(out, rc);
755         }
756
757         rc = osd_stats_init(osd);
758
759         EXIT;
760 out:
761         if (rc)
762                 osd_procfs_fini(osd);
763         return rc;
764 }
765
766 int osd_procfs_fini(struct osd_device *osd)
767 {
768         if (osd->od_stats)
769                 lprocfs_free_stats(&osd->od_stats);
770
771         if (osd->od_proc_entry)
772                 lprocfs_remove(&osd->od_proc_entry);
773
774         return dt_tunables_fini(&osd->od_dt_dev);
775 }
776 #endif