Whamcloud - gitweb
LU-10496 tgt: move FMD handling from OFD to target
[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  * \param[in] m         seq_file handle
195  * \param[in] data      unused for single entry
196  *
197  * \retval              0 on success
198  * \retval              negative value on error
199  */
200 static ssize_t degraded_show(struct kobject *kobj, struct attribute *attr,
201                              char *buf)
202 {
203         struct obd_device *obd = container_of(kobj, struct obd_device,
204                                               obd_kset.kobj);
205         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
206
207         return sprintf(buf, "%u\n", ofd->ofd_raid_degraded);
208 }
209
210 /**
211  * Set OFD to degraded mode.
212  *
213  * This is used to interface to userspace administrative tools for
214  * the underlying RAID storage, so that they can mark an OST
215  * as having degraded performance.
216  *
217  * \param[in] file      proc file
218  * \param[in] buffer    string which represents mode
219  *                      1: set degraded mode
220  *                      0: unset degraded mode
221  * \param[in] count     \a buffer length
222  * \param[in] off       unused for single entry
223  *
224  * \retval              \a count on success
225  * \retval              negative number on error
226  */
227 static ssize_t degraded_store(struct kobject *kobj, struct attribute *attr,
228                               const char *buffer, size_t count)
229 {
230         struct obd_device *obd = container_of(kobj, struct obd_device,
231                                               obd_kset.kobj);
232         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
233         bool val;
234         int rc;
235
236         rc = kstrtobool(buffer, &val);
237         if (rc)
238                 return rc;
239
240         spin_lock(&ofd->ofd_flags_lock);
241         ofd->ofd_raid_degraded = val;
242         spin_unlock(&ofd->ofd_flags_lock);
243         return count;
244 }
245 LUSTRE_RW_ATTR(degraded);
246
247 /**
248  * Show OFD filesystem type.
249  *
250  * \param[in] m         seq_file handle
251  * \param[in] data      unused for single entry
252  *
253  * \retval              0 on success
254  * \retval              negative value on error
255  */
256 static ssize_t fstype_show(struct kobject *kobj, struct attribute *attr,
257                            char *buf)
258 {
259         struct obd_device *obd = container_of(kobj, struct obd_device,
260                                               obd_kset.kobj);
261         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
262         struct lu_device  *d;
263
264         LASSERT(ofd->ofd_osd);
265         d = &ofd->ofd_osd->dd_lu_dev;
266         LASSERT(d->ld_type);
267         return sprintf(buf, "%s\n", d->ld_type->ldt_name);
268 }
269 LUSTRE_RO_ATTR(fstype);
270
271 /**
272  * Show journal handling mode: synchronous or asynchronous.
273  *
274  * When running in asynchronous mode the journal transactions are not
275  * committed to disk before the RPC is replied back to the client.
276  * This will typically improve client performance when only a small number
277  * of clients are writing, since the client(s) can have more write RPCs
278  * in flight. However, it also means that the client has to handle recovery
279  * on bulk RPCs, and will have to keep more dirty pages in cache before they
280  * are committed on the OST.
281  *
282  * \param[in] m         seq_file handle
283  * \param[in] data      unused for single entry
284  *
285  * \retval              0 on success
286  * \retval              negative value on error
287  */
288 static ssize_t sync_journal_show(struct kobject *kobj, struct attribute *attr,
289                                 char *buf)
290 {
291         struct obd_device *obd = container_of(kobj, struct obd_device,
292                                               obd_kset.kobj);
293         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
294
295         return sprintf(buf, "%u\n", ofd->ofd_sync_journal);
296 }
297
298 /**
299  * Set journal mode to synchronous or asynchronous.
300  *
301  * \param[in] file      proc file
302  * \param[in] buffer    string which represents mode
303  *                      1: synchronous mode
304  *                      0: asynchronous mode
305  * \param[in] count     \a buffer length
306  * \param[in] off       unused for single entry
307  *
308  * \retval              \a count on success
309  * \retval              negative number on error
310  */
311 static ssize_t sync_journal_store(struct kobject *kobj, struct attribute *attr,
312                                  const char *buffer, size_t count)
313 {
314         struct obd_device *obd = container_of(kobj, struct obd_device,
315                                               obd_kset.kobj);
316         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
317         bool val;
318         int rc;
319
320         rc = kstrtobool(buffer, &val);
321         if (rc)
322                 return rc;
323
324         spin_lock(&ofd->ofd_flags_lock);
325         ofd->ofd_sync_journal = val;
326         ofd_slc_set(ofd);
327         spin_unlock(&ofd->ofd_flags_lock);
328
329         return count;
330 }
331 LUSTRE_RW_ATTR(sync_journal);
332
333 static int ofd_brw_size_seq_show(struct seq_file *m, void *data)
334 {
335         struct obd_device       *obd = m->private;
336         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
337
338         seq_printf(m, "%u\n", ofd->ofd_brw_size / ONE_MB_BRW_SIZE);
339         return 0;
340 }
341
342 static ssize_t
343 ofd_brw_size_seq_write(struct file *file, const char __user *buffer,
344                        size_t count, loff_t *off)
345 {
346         struct seq_file *m = file->private_data;
347         struct obd_device *obd = m->private;
348         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
349         __s64 val;
350         int rc;
351
352         rc = lprocfs_str_with_units_to_s64(buffer, count, &val, 'M');
353         if (rc)
354                 return rc;
355
356         if (val <= 0)
357                 return -EINVAL;
358
359         if (val > DT_MAX_BRW_SIZE ||
360             val < (1 << ofd->ofd_lut.lut_tgd.tgd_blockbits))
361                 return -ERANGE;
362
363         spin_lock(&ofd->ofd_flags_lock);
364         ofd->ofd_brw_size = val;
365         spin_unlock(&ofd->ofd_flags_lock);
366
367         return count;
368 }
369
370 LPROC_SEQ_FOPS(ofd_brw_size);
371
372 /**
373  * Show the limit of soft sync RPCs.
374  *
375  * This value defines how many IO RPCs with OBD_BRW_SOFT_SYNC flag
376  * are allowed before sync update will be triggered.
377  *
378  * \param[in] m         seq_file handle
379  * \param[in] data      unused for single entry
380  *
381  * \retval              0 on success
382  * \retval              negative value on error
383  */
384 static ssize_t soft_sync_limit_show(struct kobject *kobj,
385                                     struct attribute *attr, char *buf)
386 {
387         struct obd_device *obd = container_of(kobj, struct obd_device,
388                                               obd_kset.kobj);
389         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
390
391         return sprintf(buf, "%u\n", ofd->ofd_soft_sync_limit);
392 }
393
394 /**
395  * Change the limit of soft sync RPCs.
396  *
397  * Define how many IO RPCs with OBD_BRW_SOFT_SYNC flag
398  * allowed before sync update will be done.
399  *
400  * This limit is global across all exports.
401  *
402  * \param[in] file      proc file
403  * \param[in] buffer    string which represents limit
404  * \param[in] count     \a buffer length
405  * \param[in] off       unused for single entry
406  *
407  * \retval              \a count on success
408  * \retval              negative number on error
409  */
410 static ssize_t soft_sync_limit_store(struct kobject *kobj,
411                                      struct attribute *attr,
412                                      const char *buffer, size_t count)
413 {
414         struct obd_device *obd = container_of(kobj, struct obd_device,
415                                               obd_kset.kobj);
416         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
417         unsigned int val;
418         int rc;
419
420         rc = kstrtouint(buffer, 0, &val);
421         if (rc < 0)
422                 return rc;
423
424         ofd->ofd_soft_sync_limit = val;
425         return 0;
426 }
427 LUSTRE_RW_ATTR(soft_sync_limit);
428
429 /**
430  * Show the LFSCK speed limit.
431  *
432  * The maximum number of items scanned per second.
433  *
434  * \param[in] m         seq_file handle
435  * \param[in] data      unused for single entry
436  *
437  * \retval              0 on success
438  * \retval              negative value on error
439  */
440 static ssize_t lfsck_speed_limit_show(struct kobject *kobj,
441                                       struct attribute *attr, char *buf)
442 {
443         struct obd_device *obd = container_of(kobj, struct obd_device,
444                                               obd_kset.kobj);
445         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
446
447         return lfsck_get_speed(buf, ofd->ofd_osd);
448 }
449
450 /**
451  * Change the LFSCK speed limit.
452  *
453  * Limit number of items that may be scanned per second.
454  *
455  * \param[in] file      proc file
456  * \param[in] buffer    string which represents limit
457  * \param[in] count     \a buffer length
458  * \param[in] off       unused for single entry
459  *
460  * \retval              \a count on success
461  * \retval              negative number on error
462  */
463 static ssize_t lfsck_speed_limit_store(struct kobject *kobj,
464                                        struct attribute *attr,
465                                        const char *buffer, size_t count)
466 {
467         struct obd_device *obd = container_of(kobj, struct obd_device,
468                                               obd_kset.kobj);
469         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
470         unsigned int val;
471         int rc;
472
473         rc = kstrtouint(buffer, 0, &val);
474         if (rc != 0)
475                 return rc;
476
477         rc = lfsck_set_speed(ofd->ofd_osd, val);
478
479         return rc != 0 ? rc : count;
480 }
481 LUSTRE_RW_ATTR(lfsck_speed_limit);
482
483 /**
484  * Show LFSCK layout verification stats from the most recent LFSCK run.
485  *
486  * \param[in] m         seq_file handle
487  * \param[in] data      unused for single entry
488  *
489  * \retval              0 on success
490  * \retval              negative value on error
491  */
492 static int ofd_lfsck_layout_seq_show(struct seq_file *m, void *data)
493 {
494         struct obd_device *obd = m->private;
495         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
496
497         return lfsck_dump(m, ofd->ofd_osd, LFSCK_TYPE_LAYOUT);
498 }
499
500 LPROC_SEQ_FOPS_RO(ofd_lfsck_layout);
501
502 /**
503  * Show if LFSCK performed parent FID verification.
504  *
505  * \param[in] m         seq_file handle
506  * \param[in] data      unused for single entry
507  *
508  * \retval              0 on success
509  * \retval              negative value on error
510  */
511 static int ofd_lfsck_verify_pfid_seq_show(struct seq_file *m, void *data)
512 {
513         struct obd_device *obd = m->private;
514         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
515
516         seq_printf(m, "switch: %s\ndetected: %llu\nrepaired: %llu\n",
517                    ofd->ofd_lfsck_verify_pfid ? "on" : "off",
518                    ofd->ofd_inconsistency_self_detected,
519                    ofd->ofd_inconsistency_self_repaired);
520         return 0;
521 }
522
523 /**
524  * Set the LFSCK behavior to verify parent FID correctness.
525  *
526  * If flag ofd_lfsck_verify_pfid is set then LFSCK does parent FID
527  * verification during read/write operations.
528  *
529  * \param[in] file      proc file
530  * \param[in] buffer    string which represents behavior
531  *                      1: verify parent FID
532  *                      0: don't verify parent FID
533  * \param[in] count     \a buffer length
534  * \param[in] off       unused for single entry
535  *
536  * \retval              \a count on success
537  * \retval              negative number on error
538  */
539 static ssize_t
540 ofd_lfsck_verify_pfid_seq_write(struct file *file, const char __user *buffer,
541                                 size_t count, loff_t *off)
542 {
543         struct seq_file *m = file->private_data;
544         struct obd_device *obd = m->private;
545         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
546         bool val;
547         int rc;
548
549         rc = kstrtobool_from_user(buffer, count, &val);
550         if (rc)
551                 return rc;
552
553         ofd->ofd_lfsck_verify_pfid = val;
554         if (!ofd->ofd_lfsck_verify_pfid) {
555                 ofd->ofd_inconsistency_self_detected = 0;
556                 ofd->ofd_inconsistency_self_repaired = 0;
557         }
558
559         return count;
560 }
561
562 LPROC_SEQ_FOPS(ofd_lfsck_verify_pfid);
563
564 static int ofd_site_stats_seq_show(struct seq_file *m, void *data)
565 {
566         struct obd_device *obd = m->private;
567
568         return lu_site_stats_seq_print(obd->obd_lu_dev->ld_site, m);
569 }
570
571 LPROC_SEQ_FOPS_RO(ofd_site_stats);
572
573 /**
574  * Show if the OFD enforces T10PI checksum.
575  *
576  * \param[in] m         seq_file handle
577  * \param[in] data      unused for single entry
578  *
579  * \retval              0 on success
580  * \retval              negative value on error
581  */
582 static ssize_t checksum_t10pi_enforce_show(struct kobject *kobj,
583                                            struct attribute *attr,
584                                            char *buf)
585 {
586         struct obd_device *obd = container_of(kobj, struct obd_device,
587                                               obd_kset.kobj);
588         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
589
590         return sprintf(buf, "%u\n", ofd->ofd_checksum_t10pi_enforce);
591 }
592
593 /**
594  * Force specific T10PI checksum modes to be enabled
595  *
596  * If T10PI *is* supported in hardware, allow only the supported T10PI type
597  * to be used. If T10PI is *not* supported by the OSD, setting the enforce
598  * parameter forces all T10PI types to be enabled (even if slower) for
599  * testing.
600  *
601  * The final determination of which algorithm to be used depends whether
602  * the client supports T10PI or not, and is handled at client connect time.
603  *
604  * \param[in] file      proc file
605  * \param[in] buffer    string which represents mode
606  *                      1: set T10PI checksums enforced
607  *                      0: unset T10PI checksums enforced
608  * \param[in] count     \a buffer length
609  * \param[in] off       unused for single entry
610  *
611  * \retval              \a count on success
612  * \retval              negative number on error
613  */
614 static ssize_t checksum_t10pi_enforce_store(struct kobject *kobj,
615                                             struct attribute *attr,
616                                             const char *buffer, size_t count)
617 {
618         struct obd_device *obd = container_of(kobj, struct obd_device,
619                                               obd_kset.kobj);
620         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
621         bool enforce;
622         int rc;
623
624         rc = kstrtobool(buffer, &enforce);
625         if (rc)
626                 return rc;
627
628         spin_lock(&ofd->ofd_flags_lock);
629         ofd->ofd_checksum_t10pi_enforce = enforce;
630         spin_unlock(&ofd->ofd_flags_lock);
631         return count;
632 }
633 LUSTRE_RW_ATTR(checksum_t10pi_enforce);
634
635 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 14, 53, 0)
636 static bool max_file_warned;
637 static bool rd_cache_warned;
638 static bool wr_cache_warned;
639
640 static ssize_t read_cache_enable_show(struct kobject *kobj,
641                                       struct attribute *attr,
642                                       char *buf)
643 {
644         struct obd_device *obd = container_of(kobj, struct obd_device,
645                                               obd_kset.kobj);
646         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
647
648         if (!rd_cache_warned) {
649                 rd_cache_warned = true;
650                 pr_info("ofd: 'obdfilter.*.read_cache_enabled' is deprecated, use 'osd-*.read_cache_enabled' instead\n");
651         }
652
653         if (!ofd->ofd_read_cache_enable)
654                 return -EOPNOTSUPP;
655
656         return lustre_attr_show(&ofd->ofd_osd->dd_kobj,
657                                 ofd->ofd_read_cache_enable, buf);
658 }
659
660 static ssize_t read_cache_enable_store(struct kobject *kobj,
661                                        struct attribute *attr,
662                                        const char *buffer, size_t count)
663 {
664         struct obd_device *obd = container_of(kobj, struct obd_device,
665                                               obd_kset.kobj);
666         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
667
668         if (!rd_cache_warned) {
669                 rd_cache_warned = true;
670                 pr_info("ofd: 'obdfilter.*.read_cache_enabled' is deprecated, use 'osd-*.read_cache_enabled' instead\n");
671         }
672
673         if (!ofd->ofd_read_cache_enable)
674                 return -EOPNOTSUPP;
675
676         return lustre_attr_store(&ofd->ofd_osd->dd_kobj,
677                                  ofd->ofd_read_cache_enable, buffer, count);
678 }
679 LUSTRE_RW_ATTR(read_cache_enable);
680
681 static ssize_t readcache_max_filesize_show(struct kobject *kobj,
682                                            struct attribute *attr,
683                                            char *buf)
684 {
685         struct obd_device *obd = container_of(kobj, struct obd_device,
686                                               obd_kset.kobj);
687         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
688
689         if (!max_file_warned) {
690                 max_file_warned = true;
691                 pr_info("ofd: 'obdfilter.*.readcache_max_filesize' is deprecated, use 'osd-*.readcache_max_filesize' instead\n");
692         }
693
694         if (!ofd->ofd_read_cache_max_filesize)
695                 return -EOPNOTSUPP;
696
697         return lustre_attr_show(&ofd->ofd_osd->dd_kobj,
698                                 ofd->ofd_read_cache_max_filesize, buf);
699 }
700
701 static ssize_t readcache_max_filesize_store(struct kobject *kobj,
702                                             struct attribute *attr,
703                                             const char *buffer, size_t count)
704 {
705         struct obd_device *obd = container_of(kobj, struct obd_device,
706                                               obd_kset.kobj);
707         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
708
709         if (!max_file_warned) {
710                 max_file_warned = true;
711                 pr_info("ofd: 'obdfilter.*.readcache_max_filesize' is deprecated, use 'osd-*.readcache_max_filesize' instead\n");
712         }
713
714         if (!ofd->ofd_read_cache_max_filesize)
715                 return -EOPNOTSUPP;
716
717         return lustre_attr_store(&ofd->ofd_osd->dd_kobj,
718                                  ofd->ofd_read_cache_max_filesize,
719                                  buffer, count);
720 }
721 LUSTRE_RW_ATTR(readcache_max_filesize);
722
723 static ssize_t writethrough_cache_enable_show(struct kobject *kobj,
724                                               struct attribute *attr,
725                                               char *buf)
726 {
727         struct obd_device *obd = container_of(kobj, struct obd_device,
728                                               obd_kset.kobj);
729         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
730
731         if (!wr_cache_warned) {
732                 wr_cache_warned = true;
733                 pr_info("ofd: 'obdfilter.*.writethrough_cache_enabled' is deprecated, use 'osd-*.writethrough_cache_enabled' instead\n");
734         }
735
736         if (!ofd->ofd_write_cache_enable)
737                 return -EOPNOTSUPP;
738
739         return lustre_attr_show(&ofd->ofd_osd->dd_kobj,
740                                 ofd->ofd_write_cache_enable, buf);
741 }
742
743 static ssize_t writethrough_cache_enable_store(struct kobject *kobj,
744                                                struct attribute *attr,
745                                                const char *buffer, size_t count)
746 {
747         struct obd_device *obd = container_of(kobj, struct obd_device,
748                                               obd_kset.kobj);
749         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
750
751         if (!ofd->ofd_write_cache_enable)
752                 return -EOPNOTSUPP;
753
754         return lustre_attr_store(&ofd->ofd_osd->dd_kobj,
755                                  ofd->ofd_write_cache_enable,
756                                  buffer, count);
757 }
758 LUSTRE_RW_ATTR(writethrough_cache_enable);
759 #endif
760
761 LPROC_SEQ_FOPS_RO_TYPE(ofd, recovery_status);
762 LPROC_SEQ_FOPS_RW_TYPE(ofd, recovery_time_soft);
763 LPROC_SEQ_FOPS_RW_TYPE(ofd, recovery_time_hard);
764 LPROC_SEQ_FOPS_WR_ONLY(ofd, evict_client);
765 LPROC_SEQ_FOPS_RO_TYPE(ofd, num_exports);
766 LPROC_SEQ_FOPS_RO_TYPE(ofd, target_instance);
767 LPROC_SEQ_FOPS_RW_TYPE(ofd, ir_factor);
768 LPROC_SEQ_FOPS_RW_TYPE(ofd, checksum_dump);
769 LPROC_SEQ_FOPS_RW_TYPE(ofd, job_interval);
770
771 LPROC_SEQ_FOPS_RO(tgt_tot_dirty);
772 LPROC_SEQ_FOPS_RO(tgt_tot_granted);
773 LPROC_SEQ_FOPS_RO(tgt_tot_pending);
774 LPROC_SEQ_FOPS(tgt_grant_compat_disable);
775
776 struct lprocfs_vars lprocfs_ofd_obd_vars[] = {
777         { .name =       "last_id",
778           .fops =       &ofd_last_id_fops               },
779         { .name =       "tot_dirty",
780           .fops =       &tgt_tot_dirty_fops             },
781         { .name =       "tot_pending",
782           .fops =       &tgt_tot_pending_fops           },
783         { .name =       "tot_granted",
784           .fops =       &tgt_tot_granted_fops           },
785         { .name =       "recovery_status",
786           .fops =       &ofd_recovery_status_fops       },
787         { .name =       "recovery_time_soft",
788           .fops =       &ofd_recovery_time_soft_fops    },
789         { .name =       "recovery_time_hard",
790           .fops =       &ofd_recovery_time_hard_fops    },
791         { .name =       "evict_client",
792           .fops =       &ofd_evict_client_fops          },
793         { .name =       "num_exports",
794           .fops =       &ofd_num_exports_fops           },
795         { .name =       "brw_size",
796           .fops =       &ofd_brw_size_fops              },
797         { .name =       "instance",
798           .fops =       &ofd_target_instance_fops       },
799         { .name =       "ir_factor",
800           .fops =       &ofd_ir_factor_fops             },
801         { .name =       "checksum_dump",
802           .fops =       &ofd_checksum_dump_fops         },
803         { .name =       "grant_compat_disable",
804           .fops =       &tgt_grant_compat_disable_fops  },
805         { .name =       "job_cleanup_interval",
806           .fops =       &ofd_job_interval_fops          },
807         { .name =       "lfsck_layout",
808           .fops =       &ofd_lfsck_layout_fops          },
809         { .name =       "lfsck_verify_pfid",
810           .fops =       &ofd_lfsck_verify_pfid_fops     },
811         { .name =       "site_stats",
812           .fops =       &ofd_site_stats_fops            },
813         { NULL }
814 };
815
816 /**
817  * Initialize OFD statistics counters
818  *
819  * param[in] stats      statistics counters
820  */
821 void ofd_stats_counter_init(struct lprocfs_stats *stats)
822 {
823         LASSERT(stats && stats->ls_num >= LPROC_OFD_STATS_LAST);
824
825         lprocfs_counter_init(stats, LPROC_OFD_STATS_READ,
826                              LPROCFS_CNTR_AVGMINMAX, "read_bytes", "bytes");
827         lprocfs_counter_init(stats, LPROC_OFD_STATS_WRITE,
828                              LPROCFS_CNTR_AVGMINMAX, "write_bytes", "bytes");
829         lprocfs_counter_init(stats, LPROC_OFD_STATS_GETATTR,
830                              0, "getattr", "reqs");
831         lprocfs_counter_init(stats, LPROC_OFD_STATS_SETATTR,
832                              0, "setattr", "reqs");
833         lprocfs_counter_init(stats, LPROC_OFD_STATS_PUNCH,
834                              0, "punch", "reqs");
835         lprocfs_counter_init(stats, LPROC_OFD_STATS_SYNC,
836                              0, "sync", "reqs");
837         lprocfs_counter_init(stats, LPROC_OFD_STATS_DESTROY,
838                              0, "destroy", "reqs");
839         lprocfs_counter_init(stats, LPROC_OFD_STATS_CREATE,
840                              0, "create", "reqs");
841         lprocfs_counter_init(stats, LPROC_OFD_STATS_STATFS,
842                              0, "statfs", "reqs");
843         lprocfs_counter_init(stats, LPROC_OFD_STATS_GET_INFO,
844                              0, "get_info", "reqs");
845         lprocfs_counter_init(stats, LPROC_OFD_STATS_SET_INFO,
846                              0, "set_info", "reqs");
847         lprocfs_counter_init(stats, LPROC_OFD_STATS_QUOTACTL,
848                              0, "quotactl", "reqs");
849 }
850
851 LPROC_SEQ_FOPS(lprocfs_nid_stats_clear);
852
853 static struct attribute *ofd_attrs[] = {
854         &lustre_attr_seqs_allocated.attr,
855         &lustre_attr_grant_precreate.attr,
856         &lustre_attr_precreate_batch.attr,
857         &lustre_attr_degraded.attr,
858         &lustre_attr_fstype.attr,
859         &lustre_attr_sync_journal.attr,
860         &lustre_attr_soft_sync_limit.attr,
861         &lustre_attr_lfsck_speed_limit.attr,
862         &lustre_attr_checksum_t10pi_enforce.attr,
863 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 14, 53, 0)
864         &lustre_attr_read_cache_enable.attr,
865         &lustre_attr_readcache_max_filesize.attr,
866         &lustre_attr_writethrough_cache_enable.attr,
867 #endif
868         NULL,
869 };
870
871 /**
872  * Initialize all needed procfs entries for OFD device.
873  *
874  * \param[in] ofd       OFD device
875  *
876  * \retval              0 if successful
877  * \retval              negative value on error
878  */
879 int ofd_tunables_init(struct ofd_device *ofd)
880 {
881         struct obd_device *obd = ofd_obd(ofd);
882         struct proc_dir_entry *entry;
883         int rc = 0;
884
885         ENTRY;
886         /* lprocfs must be setup before the ofd so state can be safely added
887          * to /proc incrementally as the ofd is setup
888          */
889         obd->obd_ktype.default_attrs = ofd_attrs;
890         obd->obd_vars = lprocfs_ofd_obd_vars;
891         rc = lprocfs_obd_setup(obd, false);
892         if (rc) {
893                 CERROR("%s: lprocfs_obd_setup failed: %d.\n",
894                        obd->obd_name, rc);
895                 RETURN(rc);
896         }
897
898         rc = tgt_tunables_init(&ofd->ofd_lut);
899         if (rc) {
900                 CERROR("%s: tgt_tunables_init failed: rc = %d\n",
901                        obd->obd_name, rc);
902                 GOTO(obd_cleanup, rc);
903         }
904
905         rc = lprocfs_alloc_obd_stats(obd, LPROC_OFD_STATS_LAST);
906         if (rc) {
907                 CERROR("%s: lprocfs_alloc_obd_stats failed: %d.\n",
908                        obd->obd_name, rc);
909                 GOTO(tgt_cleanup, rc);
910         }
911
912         entry = lprocfs_register("exports", obd->obd_proc_entry, NULL, NULL);
913         if (IS_ERR(entry)) {
914                 rc = PTR_ERR(entry);
915                 CERROR("%s: error %d setting up lprocfs for %s\n",
916                        obd->obd_name, rc, "exports");
917                 GOTO(obd_free_stats, rc);
918         }
919         obd->obd_proc_exports_entry = entry;
920
921         entry = lprocfs_add_simple(obd->obd_proc_exports_entry, "clear",
922                                    obd, &lprocfs_nid_stats_clear_fops);
923         if (IS_ERR(entry)) {
924                 rc = PTR_ERR(entry);
925                 CERROR("%s: add proc entry 'clear' failed: %d.\n",
926                        obd->obd_name, rc);
927                 GOTO(obd_free_stats, rc);
928         }
929
930         ofd_stats_counter_init(obd->obd_stats);
931
932         rc = lprocfs_job_stats_init(obd, LPROC_OFD_STATS_LAST,
933                                     ofd_stats_counter_init);
934         if (rc)
935                 GOTO(obd_free_stats, rc);
936
937         RETURN(0);
938
939 obd_free_stats:
940         lprocfs_free_obd_stats(obd);
941 tgt_cleanup:
942         tgt_tunables_fini(&ofd->ofd_lut);
943 obd_cleanup:
944         lprocfs_obd_cleanup(obd);
945
946         return rc;
947 }
948 #endif /* CONFIG_PROC_FS */