Whamcloud - gitweb
71ee75a5d501c16233bc88e735d9613fa3155da4
[fs/lustre-release.git] / lustre / ofd / lproc_ofd.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) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2012, 2017, 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/ofd/lproc_ofd.c
33  *
34  * This file provides functions of procfs interface for OBD Filter Device (OFD).
35  *
36  * Author: Andreas Dilger <andreas.dilger@intel.com>
37  * Author: Mikhail Pershin <mike.pershin@intel.com>
38  * Author: Johann Lombardi <johann.lombardi@intel.com>
39  * Author: Fan Yong <fan.yong@intel.com>
40  */
41
42 #define DEBUG_SUBSYSTEM S_CLASS
43
44 #include <obd.h>
45 #include <lprocfs_status.h>
46 #include <linux/seq_file.h>
47 #include <lustre_lfsck.h>
48
49 #include "ofd_internal.h"
50
51 #ifdef CONFIG_PROC_FS
52
53 /**
54  * Show number of FID allocation sequences.
55  *
56  * \param[in] m         seq_file handle
57  * \param[in] data      unused for single entry
58  *
59  * \retval              0 on success
60  * \retval              negative value on error
61  */
62 static ssize_t seqs_allocated_show(struct kobject *kobj, struct attribute *attr,
63                                    char *buf)
64 {
65         struct obd_device *obd = container_of(kobj, struct obd_device,
66                                               obd_kset.kobj);
67         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
68
69         return sprintf(buf, "%u\n", ofd->ofd_seq_count);
70 }
71 LUSTRE_RO_ATTR(seqs_allocated);
72
73 /**
74  * Show total number of grants for precreate.
75  *
76  * \param[in] m         seq_file handle
77  * \param[in] data      unused for single entry
78  *
79  * \retval              0 on success
80  * \retval              negative value on error
81  */
82 static ssize_t grant_precreate_show(struct kobject *kobj,
83                                     struct attribute *attr,
84                                     char *buf)
85 {
86         struct obd_device *obd = container_of(kobj, struct obd_device,
87                                               obd_kset.kobj);
88
89         return sprintf(buf, "%ld\n",
90                        obd->obd_self_export->exp_target_data.ted_grant);
91 }
92 LUSTRE_RO_ATTR(grant_precreate);
93
94 /**
95  * Show number of precreates allowed in a single transaction.
96  *
97  * \param[in] m         seq_file handle
98  * \param[in] data      unused for single entry
99  *
100  * \retval              0 on success
101  * \retval              negative value on error
102  */
103 static ssize_t precreate_batch_show(struct kobject *kobj,
104                                     struct attribute *attr,
105                                     char *buf)
106 {
107         struct obd_device *obd = container_of(kobj, struct obd_device,
108                                               obd_kset.kobj);
109         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
110
111         return sprintf(buf, "%d\n", ofd->ofd_precreate_batch);
112 }
113
114 /**
115  * Change number of precreates allowed in a single transaction.
116  *
117  * \param[in] file      proc file
118  * \param[in] buffer    string which represents maximum number
119  * \param[in] count     \a buffer length
120  * \param[in] off       unused for single entry
121  *
122  * \retval              \a count on success
123  * \retval              negative number on error
124  */
125 static ssize_t precreate_batch_store(struct kobject *kobj,
126                                      struct attribute *attr,
127                                      const char *buffer, size_t count)
128 {
129         struct obd_device *obd = container_of(kobj, struct obd_device,
130                                               obd_kset.kobj);
131         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
132         unsigned int val;
133         int rc;
134
135         rc = kstrtouint(buffer, 0, &val);
136         if (rc)
137                 return rc;
138
139         if (val < 1 || val > 65536)
140                 return -EINVAL;
141
142         spin_lock(&ofd->ofd_batch_lock);
143         ofd->ofd_precreate_batch = val;
144         spin_unlock(&ofd->ofd_batch_lock);
145         return count;
146 }
147 LUSTRE_RW_ATTR(precreate_batch);
148
149 /**
150  * Show the last used ID for each FID sequence used by OFD.
151  *
152  * \param[in] m         seq_file handle
153  * \param[in] data      unused for single entry
154  *
155  * \retval              0 on success
156  * \retval              negative value on error
157  */
158 static int ofd_last_id_seq_show(struct seq_file *m, void *data)
159 {
160         struct obd_device       *obd = m->private;
161         struct ofd_device       *ofd;
162         struct ofd_seq          *oseq = NULL;
163
164         if (obd == NULL)
165                 return 0;
166
167         ofd = ofd_dev(obd->obd_lu_dev);
168
169         read_lock(&ofd->ofd_seq_list_lock);
170         list_for_each_entry(oseq, &ofd->ofd_seq_list, os_list) {
171                 __u64 seq;
172
173                 seq = ostid_seq(&oseq->os_oi) == 0 ?
174                       fid_idif_seq(ostid_id(&oseq->os_oi),
175                                    ofd->ofd_lut.lut_lsd.lsd_osd_index) :
176                       ostid_seq(&oseq->os_oi);
177                 seq_printf(m, DOSTID"\n", seq, ostid_id(&oseq->os_oi));
178         }
179         read_unlock(&ofd->ofd_seq_list_lock);
180         return 0;
181 }
182
183 LPROC_SEQ_FOPS_RO(ofd_last_id);
184
185 /**
186  * Show if the OFD is in degraded mode.
187  *
188  * Degraded means OFD has a failed drive or is undergoing RAID rebuild.
189  * The MDS will try to avoid using this OST for new object allocations
190  * to reduce the impact to global IO performance when clients writing to
191  * this OST are slowed down.  It also reduces the contention on the OST
192  * RAID device, allowing it to rebuild more quickly.
193  *
194  * \retval              count of bytes written
195  */
196 static ssize_t degraded_show(struct kobject *kobj, struct attribute *attr,
197                              char *buf)
198 {
199         struct obd_device *obd = container_of(kobj, struct obd_device,
200                                               obd_kset.kobj);
201         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
202
203         return sprintf(buf, "%u\n", ofd->ofd_raid_degraded);
204 }
205
206 /**
207  * Set OFD to degraded mode.
208  *
209  * This is used to interface to userspace administrative tools for
210  * the underlying RAID storage, so that they can mark an OST
211  * as having degraded performance.
212  *
213  * \param[in] count     \a buffer length
214  * \param[in] off       unused for single entry
215  *
216  * \retval              \a count on success
217  * \retval              negative number on error
218  */
219 static ssize_t degraded_store(struct kobject *kobj, struct attribute *attr,
220                               const char *buffer, size_t count)
221 {
222         struct obd_device *obd = container_of(kobj, struct obd_device,
223                                               obd_kset.kobj);
224         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
225         bool val;
226         int rc;
227
228         rc = kstrtobool(buffer, &val);
229         if (rc)
230                 return rc;
231
232         spin_lock(&ofd->ofd_flags_lock);
233         ofd->ofd_raid_degraded = val;
234         spin_unlock(&ofd->ofd_flags_lock);
235         return count;
236 }
237 LUSTRE_RW_ATTR(degraded);
238
239 /**
240  * Show if the OFD is in no precreate mode.
241  *
242  * This means OFD has been adminstratively disabled at the OST to prevent
243  * the MDS from creating any new files on the OST, though existing files
244  * can still be read, written, and unlinked.
245  *
246  * \retval              number of bytes written
247  */
248 static ssize_t no_precreate_show(struct kobject *kobj, struct attribute *attr,
249                                  char *buf)
250 {
251         struct obd_device *obd = container_of(kobj, struct obd_device,
252                                               obd_kset.kobj);
253         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
254
255         return snprintf(buf, PAGE_SIZE, "%u\n", ofd->ofd_no_precreate);
256 }
257
258 /**
259  * Set OFD to no precreate mode.
260  *
261  * This is used to interface to userspace administrative tools to
262  * disable new object creation on the OST.
263  *
264  * \param[in] count     \a buffer length
265  *
266  * \retval              \a count on success
267  * \retval              negative number on error
268  */
269 static ssize_t no_precreate_store(struct kobject *kobj, struct attribute *attr,
270                                   const char *buffer, size_t count)
271 {
272         struct obd_device *obd = container_of(kobj, struct obd_device,
273                                               obd_kset.kobj);
274         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
275         bool val;
276         int rc;
277
278         rc = kstrtobool(buffer, &val);
279         if (rc)
280                 return rc;
281
282         spin_lock(&ofd->ofd_flags_lock);
283         ofd->ofd_no_precreate = val;
284         spin_unlock(&ofd->ofd_flags_lock);
285
286         return count;
287 }
288 LUSTRE_RW_ATTR(no_precreate);
289
290 /**
291  * Show OFD filesystem type.
292  *
293  * \param[in] m         seq_file handle
294  * \param[in] data      unused for single entry
295  *
296  * \retval              0 on success
297  * \retval              negative value on error
298  */
299 static ssize_t fstype_show(struct kobject *kobj, struct attribute *attr,
300                            char *buf)
301 {
302         struct obd_device *obd = container_of(kobj, struct obd_device,
303                                               obd_kset.kobj);
304         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
305         struct lu_device  *d;
306
307         LASSERT(ofd->ofd_osd);
308         d = &ofd->ofd_osd->dd_lu_dev;
309         LASSERT(d->ld_type);
310         return sprintf(buf, "%s\n", d->ld_type->ldt_name);
311 }
312 LUSTRE_RO_ATTR(fstype);
313
314 /**
315  * Show journal handling mode: synchronous or asynchronous.
316  *
317  * When running in asynchronous mode the journal transactions are not
318  * committed to disk before the RPC is replied back to the client.
319  * This will typically improve client performance when only a small number
320  * of clients are writing, since the client(s) can have more write RPCs
321  * in flight. However, it also means that the client has to handle recovery
322  * on bulk RPCs, and will have to keep more dirty pages in cache before they
323  * are committed on the OST.
324  *
325  * \param[in] m         seq_file handle
326  * \param[in] data      unused for single entry
327  *
328  * \retval              0 on success
329  * \retval              negative value on error
330  */
331 static ssize_t sync_journal_show(struct kobject *kobj, struct attribute *attr,
332                                 char *buf)
333 {
334         struct obd_device *obd = container_of(kobj, struct obd_device,
335                                               obd_kset.kobj);
336         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
337
338         return sprintf(buf, "%u\n", ofd->ofd_sync_journal);
339 }
340
341 /**
342  * Set journal mode to synchronous or asynchronous.
343  *
344  * \param[in] file      proc file
345  * \param[in] buffer    string which represents mode
346  *                      1: synchronous mode
347  *                      0: asynchronous mode
348  * \param[in] count     \a buffer length
349  * \param[in] off       unused for single entry
350  *
351  * \retval              \a count on success
352  * \retval              negative number on error
353  */
354 static ssize_t sync_journal_store(struct kobject *kobj, struct attribute *attr,
355                                  const char *buffer, size_t count)
356 {
357         struct obd_device *obd = container_of(kobj, struct obd_device,
358                                               obd_kset.kobj);
359         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
360         bool val;
361         int rc;
362
363         rc = kstrtobool(buffer, &val);
364         if (rc)
365                 return rc;
366
367         spin_lock(&ofd->ofd_flags_lock);
368         ofd->ofd_sync_journal = val;
369         ofd_slc_set(ofd);
370         spin_unlock(&ofd->ofd_flags_lock);
371
372         return count;
373 }
374 LUSTRE_RW_ATTR(sync_journal);
375
376 static int ofd_brw_size_seq_show(struct seq_file *m, void *data)
377 {
378         struct obd_device       *obd = m->private;
379         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
380
381         seq_printf(m, "%u\n", ofd->ofd_brw_size / ONE_MB_BRW_SIZE);
382         return 0;
383 }
384
385 static ssize_t
386 ofd_brw_size_seq_write(struct file *file, const char __user *buffer,
387                        size_t count, loff_t *off)
388 {
389         struct seq_file *m = file->private_data;
390         struct obd_device *obd = m->private;
391         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
392         __s64 val;
393         int rc;
394
395         rc = lprocfs_str_with_units_to_s64(buffer, count, &val, 'M');
396         if (rc)
397                 return rc;
398
399         if (val <= 0)
400                 return -EINVAL;
401
402         if (val > DT_MAX_BRW_SIZE ||
403             val < (1 << ofd->ofd_lut.lut_tgd.tgd_blockbits))
404                 return -ERANGE;
405
406         spin_lock(&ofd->ofd_flags_lock);
407         ofd->ofd_brw_size = val;
408         spin_unlock(&ofd->ofd_flags_lock);
409
410         return count;
411 }
412
413 LPROC_SEQ_FOPS(ofd_brw_size);
414
415 /**
416  * Show the limit of soft sync RPCs.
417  *
418  * This value defines how many IO RPCs with OBD_BRW_SOFT_SYNC flag
419  * are allowed before sync update will be triggered.
420  *
421  * \param[in] m         seq_file handle
422  * \param[in] data      unused for single entry
423  *
424  * \retval              0 on success
425  * \retval              negative value on error
426  */
427 static ssize_t soft_sync_limit_show(struct kobject *kobj,
428                                     struct attribute *attr, char *buf)
429 {
430         struct obd_device *obd = container_of(kobj, struct obd_device,
431                                               obd_kset.kobj);
432         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
433
434         return sprintf(buf, "%u\n", ofd->ofd_soft_sync_limit);
435 }
436
437 /**
438  * Change the limit of soft sync RPCs.
439  *
440  * Define how many IO RPCs with OBD_BRW_SOFT_SYNC flag
441  * allowed before sync update will be done.
442  *
443  * This limit is global across all exports.
444  *
445  * \param[in] file      proc file
446  * \param[in] buffer    string which represents limit
447  * \param[in] count     \a buffer length
448  * \param[in] off       unused for single entry
449  *
450  * \retval              \a count on success
451  * \retval              negative number on error
452  */
453 static ssize_t soft_sync_limit_store(struct kobject *kobj,
454                                      struct attribute *attr,
455                                      const char *buffer, size_t count)
456 {
457         struct obd_device *obd = container_of(kobj, struct obd_device,
458                                               obd_kset.kobj);
459         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
460         unsigned int val;
461         int rc;
462
463         rc = kstrtouint(buffer, 0, &val);
464         if (rc < 0)
465                 return rc;
466
467         ofd->ofd_soft_sync_limit = val;
468         return 0;
469 }
470 LUSTRE_RW_ATTR(soft_sync_limit);
471
472 /**
473  * Show the LFSCK speed limit.
474  *
475  * The maximum number of items scanned per second.
476  *
477  * \param[in] m         seq_file handle
478  * \param[in] data      unused for single entry
479  *
480  * \retval              0 on success
481  * \retval              negative value on error
482  */
483 static ssize_t lfsck_speed_limit_show(struct kobject *kobj,
484                                       struct attribute *attr, char *buf)
485 {
486         struct obd_device *obd = container_of(kobj, struct obd_device,
487                                               obd_kset.kobj);
488         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
489
490         return lfsck_get_speed(buf, ofd->ofd_osd);
491 }
492
493 /**
494  * Change the LFSCK speed limit.
495  *
496  * Limit number of items that may be scanned per second.
497  *
498  * \param[in] file      proc file
499  * \param[in] buffer    string which represents limit
500  * \param[in] count     \a buffer length
501  * \param[in] off       unused for single entry
502  *
503  * \retval              \a count on success
504  * \retval              negative number on error
505  */
506 static ssize_t lfsck_speed_limit_store(struct kobject *kobj,
507                                        struct attribute *attr,
508                                        const char *buffer, size_t count)
509 {
510         struct obd_device *obd = container_of(kobj, struct obd_device,
511                                               obd_kset.kobj);
512         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
513         unsigned int val;
514         int rc;
515
516         rc = kstrtouint(buffer, 0, &val);
517         if (rc != 0)
518                 return rc;
519
520         rc = lfsck_set_speed(ofd->ofd_osd, val);
521
522         return rc != 0 ? rc : count;
523 }
524 LUSTRE_RW_ATTR(lfsck_speed_limit);
525
526 /**
527  * Show LFSCK layout verification stats from the most recent LFSCK run.
528  *
529  * \param[in] m         seq_file handle
530  * \param[in] data      unused for single entry
531  *
532  * \retval              0 on success
533  * \retval              negative value on error
534  */
535 static int ofd_lfsck_layout_seq_show(struct seq_file *m, void *data)
536 {
537         struct obd_device *obd = m->private;
538         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
539
540         return lfsck_dump(m, ofd->ofd_osd, LFSCK_TYPE_LAYOUT);
541 }
542
543 LPROC_SEQ_FOPS_RO(ofd_lfsck_layout);
544
545 /**
546  * Show if LFSCK performed parent FID verification.
547  *
548  * \param[in] m         seq_file handle
549  * \param[in] data      unused for single entry
550  *
551  * \retval              0 on success
552  * \retval              negative value on error
553  */
554 static int ofd_lfsck_verify_pfid_seq_show(struct seq_file *m, void *data)
555 {
556         struct obd_device *obd = m->private;
557         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
558
559         seq_printf(m, "switch: %s\ndetected: %llu\nrepaired: %llu\n",
560                    ofd->ofd_lfsck_verify_pfid ? "on" : "off",
561                    ofd->ofd_inconsistency_self_detected,
562                    ofd->ofd_inconsistency_self_repaired);
563         return 0;
564 }
565
566 /**
567  * Set the LFSCK behavior to verify parent FID correctness.
568  *
569  * If flag ofd_lfsck_verify_pfid is set then LFSCK does parent FID
570  * verification during read/write operations.
571  *
572  * \param[in] file      proc file
573  * \param[in] buffer    string which represents behavior
574  *                      1: verify parent FID
575  *                      0: don't verify parent FID
576  * \param[in] count     \a buffer length
577  * \param[in] off       unused for single entry
578  *
579  * \retval              \a count on success
580  * \retval              negative number on error
581  */
582 static ssize_t
583 ofd_lfsck_verify_pfid_seq_write(struct file *file, const char __user *buffer,
584                                 size_t count, loff_t *off)
585 {
586         struct seq_file *m = file->private_data;
587         struct obd_device *obd = m->private;
588         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
589         bool val;
590         int rc;
591
592         rc = kstrtobool_from_user(buffer, count, &val);
593         if (rc)
594                 return rc;
595
596         ofd->ofd_lfsck_verify_pfid = val;
597         if (!ofd->ofd_lfsck_verify_pfid) {
598                 ofd->ofd_inconsistency_self_detected = 0;
599                 ofd->ofd_inconsistency_self_repaired = 0;
600         }
601
602         return count;
603 }
604
605 LPROC_SEQ_FOPS(ofd_lfsck_verify_pfid);
606
607 static int ofd_site_stats_seq_show(struct seq_file *m, void *data)
608 {
609         struct obd_device *obd = m->private;
610
611         return lu_site_stats_seq_print(obd->obd_lu_dev->ld_site, m);
612 }
613
614 LPROC_SEQ_FOPS_RO(ofd_site_stats);
615
616 /**
617  * Show if the OFD enforces T10PI checksum.
618  *
619  * \param[in] m         seq_file handle
620  * \param[in] data      unused for single entry
621  *
622  * \retval              0 on success
623  * \retval              negative value on error
624  */
625 static ssize_t checksum_t10pi_enforce_show(struct kobject *kobj,
626                                            struct attribute *attr,
627                                            char *buf)
628 {
629         struct obd_device *obd = container_of(kobj, struct obd_device,
630                                               obd_kset.kobj);
631         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
632
633         return sprintf(buf, "%u\n", ofd->ofd_checksum_t10pi_enforce);
634 }
635
636 /**
637  * Force specific T10PI checksum modes to be enabled
638  *
639  * If T10PI *is* supported in hardware, allow only the supported T10PI type
640  * to be used. If T10PI is *not* supported by the OSD, setting the enforce
641  * parameter forces all T10PI types to be enabled (even if slower) for
642  * testing.
643  *
644  * The final determination of which algorithm to be used depends whether
645  * the client supports T10PI or not, and is handled at client connect time.
646  *
647  * \param[in] file      proc file
648  * \param[in] buffer    string which represents mode
649  *                      1: set T10PI checksums enforced
650  *                      0: unset T10PI checksums enforced
651  * \param[in] count     \a buffer length
652  * \param[in] off       unused for single entry
653  *
654  * \retval              \a count on success
655  * \retval              negative number on error
656  */
657 static ssize_t checksum_t10pi_enforce_store(struct kobject *kobj,
658                                             struct attribute *attr,
659                                             const char *buffer, size_t count)
660 {
661         struct obd_device *obd = container_of(kobj, struct obd_device,
662                                               obd_kset.kobj);
663         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
664         bool enforce;
665         int rc;
666
667         rc = kstrtobool(buffer, &enforce);
668         if (rc)
669                 return rc;
670
671         spin_lock(&ofd->ofd_flags_lock);
672         ofd->ofd_checksum_t10pi_enforce = enforce;
673         spin_unlock(&ofd->ofd_flags_lock);
674         return count;
675 }
676 LUSTRE_RW_ATTR(checksum_t10pi_enforce);
677
678 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 14, 53, 0)
679 static bool max_file_warned;
680 static bool rd_cache_warned;
681 static bool wr_cache_warned;
682
683 static ssize_t read_cache_enable_show(struct kobject *kobj,
684                                       struct attribute *attr,
685                                       char *buf)
686 {
687         struct obd_device *obd = container_of(kobj, struct obd_device,
688                                               obd_kset.kobj);
689         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
690
691         if (!rd_cache_warned) {
692                 rd_cache_warned = true;
693                 pr_info("ofd: 'obdfilter.*.read_cache_enabled' is deprecated, use 'osd-*.read_cache_enabled' instead\n");
694         }
695
696         if (!ofd->ofd_read_cache_enable)
697                 return -EOPNOTSUPP;
698
699         return lustre_attr_show(&ofd->ofd_osd->dd_kobj,
700                                 ofd->ofd_read_cache_enable, buf);
701 }
702
703 static ssize_t read_cache_enable_store(struct kobject *kobj,
704                                        struct attribute *attr,
705                                        const char *buffer, size_t count)
706 {
707         struct obd_device *obd = container_of(kobj, struct obd_device,
708                                               obd_kset.kobj);
709         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
710
711         if (!rd_cache_warned) {
712                 rd_cache_warned = true;
713                 pr_info("ofd: 'obdfilter.*.read_cache_enabled' is deprecated, use 'osd-*.read_cache_enabled' instead\n");
714         }
715
716         if (!ofd->ofd_read_cache_enable)
717                 return -EOPNOTSUPP;
718
719         return lustre_attr_store(&ofd->ofd_osd->dd_kobj,
720                                  ofd->ofd_read_cache_enable, buffer, count);
721 }
722 LUSTRE_RW_ATTR(read_cache_enable);
723
724 static ssize_t readcache_max_filesize_show(struct kobject *kobj,
725                                            struct attribute *attr,
726                                            char *buf)
727 {
728         struct obd_device *obd = container_of(kobj, struct obd_device,
729                                               obd_kset.kobj);
730         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
731
732         if (!max_file_warned) {
733                 max_file_warned = true;
734                 pr_info("ofd: 'obdfilter.*.readcache_max_filesize' is deprecated, use 'osd-*.readcache_max_filesize' instead\n");
735         }
736
737         if (!ofd->ofd_read_cache_max_filesize)
738                 return -EOPNOTSUPP;
739
740         return lustre_attr_show(&ofd->ofd_osd->dd_kobj,
741                                 ofd->ofd_read_cache_max_filesize, buf);
742 }
743
744 static ssize_t readcache_max_filesize_store(struct kobject *kobj,
745                                             struct attribute *attr,
746                                             const char *buffer, size_t count)
747 {
748         struct obd_device *obd = container_of(kobj, struct obd_device,
749                                               obd_kset.kobj);
750         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
751
752         if (!max_file_warned) {
753                 max_file_warned = true;
754                 pr_info("ofd: 'obdfilter.*.readcache_max_filesize' is deprecated, use 'osd-*.readcache_max_filesize' instead\n");
755         }
756
757         if (!ofd->ofd_read_cache_max_filesize)
758                 return -EOPNOTSUPP;
759
760         return lustre_attr_store(&ofd->ofd_osd->dd_kobj,
761                                  ofd->ofd_read_cache_max_filesize,
762                                  buffer, count);
763 }
764 LUSTRE_RW_ATTR(readcache_max_filesize);
765
766 static ssize_t writethrough_cache_enable_show(struct kobject *kobj,
767                                               struct attribute *attr,
768                                               char *buf)
769 {
770         struct obd_device *obd = container_of(kobj, struct obd_device,
771                                               obd_kset.kobj);
772         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
773
774         if (!wr_cache_warned) {
775                 wr_cache_warned = true;
776                 pr_info("ofd: 'obdfilter.*.writethrough_cache_enabled' is deprecated, use 'osd-*.writethrough_cache_enabled' instead\n");
777         }
778
779         if (!ofd->ofd_write_cache_enable)
780                 return -EOPNOTSUPP;
781
782         return lustre_attr_show(&ofd->ofd_osd->dd_kobj,
783                                 ofd->ofd_write_cache_enable, buf);
784 }
785
786 static ssize_t writethrough_cache_enable_store(struct kobject *kobj,
787                                                struct attribute *attr,
788                                                const char *buffer, size_t count)
789 {
790         struct obd_device *obd = container_of(kobj, struct obd_device,
791                                               obd_kset.kobj);
792         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
793
794         if (!ofd->ofd_write_cache_enable)
795                 return -EOPNOTSUPP;
796
797         return lustre_attr_store(&ofd->ofd_osd->dd_kobj,
798                                  ofd->ofd_write_cache_enable,
799                                  buffer, count);
800 }
801 LUSTRE_RW_ATTR(writethrough_cache_enable);
802 #endif
803
804 LPROC_SEQ_FOPS_RO_TYPE(ofd, recovery_status);
805 LUSTRE_RW_ATTR(recovery_time_hard);
806 LUSTRE_RW_ATTR(recovery_time_soft);
807 LUSTRE_RW_ATTR(ir_factor);
808
809 LPROC_SEQ_FOPS_WR_ONLY(ofd, evict_client);
810 LPROC_SEQ_FOPS_RW_TYPE(ofd, checksum_dump);
811 LUSTRE_RW_ATTR(job_cleanup_interval);
812
813 LUSTRE_RO_ATTR(tot_dirty);
814 LUSTRE_RO_ATTR(tot_granted);
815 LUSTRE_RO_ATTR(tot_pending);
816 LUSTRE_RW_ATTR(grant_compat_disable);
817 LUSTRE_RO_ATTR(instance);
818
819 LUSTRE_RO_ATTR(num_exports);
820
821 struct lprocfs_vars lprocfs_ofd_obd_vars[] = {
822         { .name =       "last_id",
823           .fops =       &ofd_last_id_fops               },
824         { .name =       "recovery_status",
825           .fops =       &ofd_recovery_status_fops       },
826         { .name =       "evict_client",
827           .fops =       &ofd_evict_client_fops          },
828         { .name =       "brw_size",
829           .fops =       &ofd_brw_size_fops              },
830         { .name =       "checksum_dump",
831           .fops =       &ofd_checksum_dump_fops         },
832         { .name =       "lfsck_layout",
833           .fops =       &ofd_lfsck_layout_fops          },
834         { .name =       "lfsck_verify_pfid",
835           .fops =       &ofd_lfsck_verify_pfid_fops     },
836         { .name =       "site_stats",
837           .fops =       &ofd_site_stats_fops            },
838         { NULL }
839 };
840
841 /**
842  * Initialize OFD statistics counters
843  *
844  * param[in] stats      statistics counters
845  */
846 void ofd_stats_counter_init(struct lprocfs_stats *stats)
847 {
848         LASSERT(stats && stats->ls_num >= LPROC_OFD_STATS_LAST);
849
850         lprocfs_counter_init(stats, LPROC_OFD_STATS_READ,
851                              LPROCFS_CNTR_AVGMINMAX, "read_bytes", "bytes");
852         lprocfs_counter_init(stats, LPROC_OFD_STATS_WRITE,
853                              LPROCFS_CNTR_AVGMINMAX, "write_bytes", "bytes");
854         lprocfs_counter_init(stats, LPROC_OFD_STATS_GETATTR,
855                              0, "getattr", "reqs");
856         lprocfs_counter_init(stats, LPROC_OFD_STATS_SETATTR,
857                              0, "setattr", "reqs");
858         lprocfs_counter_init(stats, LPROC_OFD_STATS_PUNCH,
859                              0, "punch", "reqs");
860         lprocfs_counter_init(stats, LPROC_OFD_STATS_SYNC,
861                              0, "sync", "reqs");
862         lprocfs_counter_init(stats, LPROC_OFD_STATS_DESTROY,
863                              0, "destroy", "reqs");
864         lprocfs_counter_init(stats, LPROC_OFD_STATS_CREATE,
865                              0, "create", "reqs");
866         lprocfs_counter_init(stats, LPROC_OFD_STATS_STATFS,
867                              0, "statfs", "reqs");
868         lprocfs_counter_init(stats, LPROC_OFD_STATS_GET_INFO,
869                              0, "get_info", "reqs");
870         lprocfs_counter_init(stats, LPROC_OFD_STATS_SET_INFO,
871                              0, "set_info", "reqs");
872         lprocfs_counter_init(stats, LPROC_OFD_STATS_QUOTACTL,
873                              0, "quotactl", "reqs");
874 }
875
876 LPROC_SEQ_FOPS(lprocfs_nid_stats_clear);
877
878 static struct attribute *ofd_attrs[] = {
879         &lustre_attr_tot_dirty.attr,
880         &lustre_attr_tot_granted.attr,
881         &lustre_attr_tot_pending.attr,
882         &lustre_attr_grant_compat_disable.attr,
883         &lustre_attr_instance.attr,
884         &lustre_attr_recovery_time_hard.attr,
885         &lustre_attr_recovery_time_soft.attr,
886         &lustre_attr_ir_factor.attr,
887         &lustre_attr_num_exports.attr,
888         &lustre_attr_seqs_allocated.attr,
889         &lustre_attr_grant_precreate.attr,
890         &lustre_attr_precreate_batch.attr,
891         &lustre_attr_degraded.attr,
892         &lustre_attr_fstype.attr,
893         &lustre_attr_no_precreate.attr,
894         &lustre_attr_sync_journal.attr,
895         &lustre_attr_soft_sync_limit.attr,
896         &lustre_attr_lfsck_speed_limit.attr,
897         &lustre_attr_job_cleanup_interval.attr,
898         &lustre_attr_checksum_t10pi_enforce.attr,
899 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 14, 53, 0)
900         &lustre_attr_read_cache_enable.attr,
901         &lustre_attr_readcache_max_filesize.attr,
902         &lustre_attr_writethrough_cache_enable.attr,
903 #endif
904         NULL,
905 };
906
907 /**
908  * Initialize all needed procfs entries for OFD device.
909  *
910  * \param[in] ofd       OFD device
911  *
912  * \retval              0 if successful
913  * \retval              negative value on error
914  */
915 int ofd_tunables_init(struct ofd_device *ofd)
916 {
917         struct obd_device *obd = ofd_obd(ofd);
918         struct proc_dir_entry *entry;
919         int rc = 0;
920
921         ENTRY;
922         /* lprocfs must be setup before the ofd so state can be safely added
923          * to /proc incrementally as the ofd is setup
924          */
925         obd->obd_ktype.default_attrs = ofd_attrs;
926         obd->obd_vars = lprocfs_ofd_obd_vars;
927         rc = lprocfs_obd_setup(obd, false);
928         if (rc) {
929                 CERROR("%s: lprocfs_obd_setup failed: %d.\n",
930                        obd->obd_name, rc);
931                 RETURN(rc);
932         }
933
934         rc = tgt_tunables_init(&ofd->ofd_lut);
935         if (rc) {
936                 CERROR("%s: tgt_tunables_init failed: rc = %d\n",
937                        obd->obd_name, rc);
938                 GOTO(obd_cleanup, rc);
939         }
940
941         rc = lprocfs_alloc_obd_stats(obd, LPROC_OFD_STATS_LAST);
942         if (rc) {
943                 CERROR("%s: lprocfs_alloc_obd_stats failed: %d.\n",
944                        obd->obd_name, rc);
945                 GOTO(tgt_cleanup, rc);
946         }
947
948         entry = lprocfs_register("exports", obd->obd_proc_entry, NULL, NULL);
949         if (IS_ERR(entry)) {
950                 rc = PTR_ERR(entry);
951                 CERROR("%s: error %d setting up lprocfs for %s\n",
952                        obd->obd_name, rc, "exports");
953                 GOTO(obd_free_stats, rc);
954         }
955         obd->obd_proc_exports_entry = entry;
956
957         entry = lprocfs_add_simple(obd->obd_proc_exports_entry, "clear",
958                                    obd, &lprocfs_nid_stats_clear_fops);
959         if (IS_ERR(entry)) {
960                 rc = PTR_ERR(entry);
961                 CERROR("%s: add proc entry 'clear' failed: %d.\n",
962                        obd->obd_name, rc);
963                 GOTO(obd_free_stats, rc);
964         }
965
966         ofd_stats_counter_init(obd->obd_stats);
967
968         rc = lprocfs_job_stats_init(obd, LPROC_OFD_STATS_LAST,
969                                     ofd_stats_counter_init);
970         if (rc)
971                 GOTO(obd_free_stats, rc);
972
973         RETURN(0);
974
975 obd_free_stats:
976         lprocfs_free_obd_stats(obd);
977 tgt_cleanup:
978         tgt_tunables_fini(&ofd->ofd_lut);
979 obd_cleanup:
980         lprocfs_obd_cleanup(obd);
981
982         return rc;
983 }
984 #endif /* CONFIG_PROC_FS */