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