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