Whamcloud - gitweb
LU-12967 ofd: restore sync_on_lock_cancel tunable
[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 LPROC_SEQ_FOPS(ofd_brw_size);
413
414 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 16, 53, 0)
415 static bool sync_on_lock_cancel_warned;
416 static ssize_t sync_on_lock_cancel_show(struct kobject *kobj,
417                                         struct attribute *attr, char *buf)
418 {
419         if (!sync_on_lock_cancel_warned) {
420                 sync_on_lock_cancel_warned = true;
421                 pr_info("ofd: 'obdfilter.*.sync_on_lock_cancel' is deprecated, use 'obdfilter.*.sync_lock_cancel' instead\n");
422         }
423         return sync_lock_cancel_show(kobj, attr, buf);
424 }
425
426 static ssize_t sync_on_lock_cancel_store(struct kobject *kobj,
427                                          struct attribute *attr,
428                                          const char *buffer, size_t count)
429 {
430         if (!sync_on_lock_cancel_warned) {
431                 sync_on_lock_cancel_warned = true;
432                 pr_info("ofd: 'obdfilter.*.sync_on_lock_cancel' is deprecated, use 'obdfilter.*.sync_lock_cancel' instead\n");
433         }
434         return sync_lock_cancel_store(kobj, attr, buffer, count);
435 }
436 LUSTRE_RW_ATTR(sync_on_lock_cancel);
437 #endif
438
439 /**
440  * Show the limit of soft sync RPCs.
441  *
442  * This value defines how many IO RPCs with OBD_BRW_SOFT_SYNC flag
443  * are allowed before sync update will be triggered.
444  *
445  * \param[in] m         seq_file handle
446  * \param[in] data      unused for single entry
447  *
448  * \retval              0 on success
449  * \retval              negative value on error
450  */
451 static ssize_t soft_sync_limit_show(struct kobject *kobj,
452                                     struct attribute *attr, char *buf)
453 {
454         struct obd_device *obd = container_of(kobj, struct obd_device,
455                                               obd_kset.kobj);
456         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
457
458         return sprintf(buf, "%u\n", ofd->ofd_soft_sync_limit);
459 }
460
461 /**
462  * Change the limit of soft sync RPCs.
463  *
464  * Define how many IO RPCs with OBD_BRW_SOFT_SYNC flag
465  * allowed before sync update will be done.
466  *
467  * This limit is global across all exports.
468  *
469  * \param[in] file      proc file
470  * \param[in] buffer    string which represents limit
471  * \param[in] count     \a buffer length
472  * \param[in] off       unused for single entry
473  *
474  * \retval              \a count on success
475  * \retval              negative number on error
476  */
477 static ssize_t soft_sync_limit_store(struct kobject *kobj,
478                                      struct attribute *attr,
479                                      const char *buffer, size_t count)
480 {
481         struct obd_device *obd = container_of(kobj, struct obd_device,
482                                               obd_kset.kobj);
483         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
484         unsigned int val;
485         int rc;
486
487         rc = kstrtouint(buffer, 0, &val);
488         if (rc < 0)
489                 return rc;
490
491         ofd->ofd_soft_sync_limit = val;
492         return 0;
493 }
494 LUSTRE_RW_ATTR(soft_sync_limit);
495
496 /**
497  * Show the LFSCK speed limit.
498  *
499  * The maximum number of items scanned per second.
500  *
501  * \param[in] m         seq_file handle
502  * \param[in] data      unused for single entry
503  *
504  * \retval              0 on success
505  * \retval              negative value on error
506  */
507 static ssize_t lfsck_speed_limit_show(struct kobject *kobj,
508                                       struct attribute *attr, char *buf)
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
514         return lfsck_get_speed(buf, ofd->ofd_osd);
515 }
516
517 /**
518  * Change the LFSCK speed limit.
519  *
520  * Limit number of items that may be scanned per second.
521  *
522  * \param[in] file      proc file
523  * \param[in] buffer    string which represents limit
524  * \param[in] count     \a buffer length
525  * \param[in] off       unused for single entry
526  *
527  * \retval              \a count on success
528  * \retval              negative number on error
529  */
530 static ssize_t lfsck_speed_limit_store(struct kobject *kobj,
531                                        struct attribute *attr,
532                                        const char *buffer, size_t count)
533 {
534         struct obd_device *obd = container_of(kobj, struct obd_device,
535                                               obd_kset.kobj);
536         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
537         unsigned int val;
538         int rc;
539
540         rc = kstrtouint(buffer, 0, &val);
541         if (rc != 0)
542                 return rc;
543
544         rc = lfsck_set_speed(ofd->ofd_osd, val);
545
546         return rc != 0 ? rc : count;
547 }
548 LUSTRE_RW_ATTR(lfsck_speed_limit);
549
550 /**
551  * Show LFSCK layout verification stats from the most recent LFSCK run.
552  *
553  * \param[in] m         seq_file handle
554  * \param[in] data      unused for single entry
555  *
556  * \retval              0 on success
557  * \retval              negative value on error
558  */
559 static int ofd_lfsck_layout_seq_show(struct seq_file *m, void *data)
560 {
561         struct obd_device *obd = m->private;
562         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
563
564         return lfsck_dump(m, ofd->ofd_osd, LFSCK_TYPE_LAYOUT);
565 }
566
567 LPROC_SEQ_FOPS_RO(ofd_lfsck_layout);
568
569 /**
570  * Show if LFSCK performed parent FID verification.
571  *
572  * \param[in] m         seq_file handle
573  * \param[in] data      unused for single entry
574  *
575  * \retval              0 on success
576  * \retval              negative value on error
577  */
578 static int ofd_lfsck_verify_pfid_seq_show(struct seq_file *m, void *data)
579 {
580         struct obd_device *obd = m->private;
581         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
582
583         seq_printf(m, "switch: %s\ndetected: %llu\nrepaired: %llu\n",
584                    ofd->ofd_lfsck_verify_pfid ? "on" : "off",
585                    ofd->ofd_inconsistency_self_detected,
586                    ofd->ofd_inconsistency_self_repaired);
587         return 0;
588 }
589
590 /**
591  * Set the LFSCK behavior to verify parent FID correctness.
592  *
593  * If flag ofd_lfsck_verify_pfid is set then LFSCK does parent FID
594  * verification during read/write operations.
595  *
596  * \param[in] file      proc file
597  * \param[in] buffer    string which represents behavior
598  *                      1: verify parent FID
599  *                      0: don't verify parent FID
600  * \param[in] count     \a buffer length
601  * \param[in] off       unused for single entry
602  *
603  * \retval              \a count on success
604  * \retval              negative number on error
605  */
606 static ssize_t
607 ofd_lfsck_verify_pfid_seq_write(struct file *file, const char __user *buffer,
608                                 size_t count, loff_t *off)
609 {
610         struct seq_file *m = file->private_data;
611         struct obd_device *obd = m->private;
612         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
613         bool val;
614         int rc;
615
616         rc = kstrtobool_from_user(buffer, count, &val);
617         if (rc)
618                 return rc;
619
620         ofd->ofd_lfsck_verify_pfid = val;
621         if (!ofd->ofd_lfsck_verify_pfid) {
622                 ofd->ofd_inconsistency_self_detected = 0;
623                 ofd->ofd_inconsistency_self_repaired = 0;
624         }
625
626         return count;
627 }
628
629 LPROC_SEQ_FOPS(ofd_lfsck_verify_pfid);
630
631 static int ofd_site_stats_seq_show(struct seq_file *m, void *data)
632 {
633         struct obd_device *obd = m->private;
634
635         return lu_site_stats_seq_print(obd->obd_lu_dev->ld_site, m);
636 }
637
638 LPROC_SEQ_FOPS_RO(ofd_site_stats);
639
640 /**
641  * Show if the OFD enforces T10PI checksum.
642  *
643  * \param[in] m         seq_file handle
644  * \param[in] data      unused for single entry
645  *
646  * \retval              0 on success
647  * \retval              negative value on error
648  */
649 static ssize_t checksum_t10pi_enforce_show(struct kobject *kobj,
650                                            struct attribute *attr,
651                                            char *buf)
652 {
653         struct obd_device *obd = container_of(kobj, struct obd_device,
654                                               obd_kset.kobj);
655         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
656
657         return sprintf(buf, "%u\n", ofd->ofd_checksum_t10pi_enforce);
658 }
659
660 /**
661  * Force specific T10PI checksum modes to be enabled
662  *
663  * If T10PI *is* supported in hardware, allow only the supported T10PI type
664  * to be used. If T10PI is *not* supported by the OSD, setting the enforce
665  * parameter forces all T10PI types to be enabled (even if slower) for
666  * testing.
667  *
668  * The final determination of which algorithm to be used depends whether
669  * the client supports T10PI or not, and is handled at client connect time.
670  *
671  * \param[in] file      proc file
672  * \param[in] buffer    string which represents mode
673  *                      1: set T10PI checksums enforced
674  *                      0: unset T10PI checksums enforced
675  * \param[in] count     \a buffer length
676  * \param[in] off       unused for single entry
677  *
678  * \retval              \a count on success
679  * \retval              negative number on error
680  */
681 static ssize_t checksum_t10pi_enforce_store(struct kobject *kobj,
682                                             struct attribute *attr,
683                                             const char *buffer, size_t count)
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         bool enforce;
689         int rc;
690
691         rc = kstrtobool(buffer, &enforce);
692         if (rc)
693                 return rc;
694
695         spin_lock(&ofd->ofd_flags_lock);
696         ofd->ofd_checksum_t10pi_enforce = enforce;
697         spin_unlock(&ofd->ofd_flags_lock);
698         return count;
699 }
700 LUSTRE_RW_ATTR(checksum_t10pi_enforce);
701
702 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 14, 53, 0)
703 static bool max_file_warned;
704 static bool rd_cache_warned;
705 static bool wr_cache_warned;
706
707 static ssize_t read_cache_enable_show(struct kobject *kobj,
708                                       struct attribute *attr,
709                                       char *buf)
710 {
711         struct obd_device *obd = container_of(kobj, struct obd_device,
712                                               obd_kset.kobj);
713         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
714
715         if (!rd_cache_warned) {
716                 rd_cache_warned = true;
717                 pr_info("ofd: 'obdfilter.*.read_cache_enabled' is deprecated, use 'osd-*.read_cache_enabled' instead\n");
718         }
719
720         if (!ofd->ofd_read_cache_enable)
721                 return -EOPNOTSUPP;
722
723         return lustre_attr_show(&ofd->ofd_osd->dd_kobj,
724                                 ofd->ofd_read_cache_enable, buf);
725 }
726
727 static ssize_t read_cache_enable_store(struct kobject *kobj,
728                                        struct attribute *attr,
729                                        const char *buffer, size_t count)
730 {
731         struct obd_device *obd = container_of(kobj, struct obd_device,
732                                               obd_kset.kobj);
733         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
734
735         if (!rd_cache_warned) {
736                 rd_cache_warned = true;
737                 pr_info("ofd: 'obdfilter.*.read_cache_enabled' is deprecated, use 'osd-*.read_cache_enabled' instead\n");
738         }
739
740         if (!ofd->ofd_read_cache_enable)
741                 return -EOPNOTSUPP;
742
743         return lustre_attr_store(&ofd->ofd_osd->dd_kobj,
744                                  ofd->ofd_read_cache_enable, buffer, count);
745 }
746 LUSTRE_RW_ATTR(read_cache_enable);
747
748 static ssize_t readcache_max_filesize_show(struct kobject *kobj,
749                                            struct attribute *attr,
750                                            char *buf)
751 {
752         struct obd_device *obd = container_of(kobj, struct obd_device,
753                                               obd_kset.kobj);
754         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
755
756         if (!max_file_warned) {
757                 max_file_warned = true;
758                 pr_info("ofd: 'obdfilter.*.readcache_max_filesize' is deprecated, use 'osd-*.readcache_max_filesize' instead\n");
759         }
760
761         if (!ofd->ofd_read_cache_max_filesize)
762                 return -EOPNOTSUPP;
763
764         return lustre_attr_show(&ofd->ofd_osd->dd_kobj,
765                                 ofd->ofd_read_cache_max_filesize, buf);
766 }
767
768 static ssize_t readcache_max_filesize_store(struct kobject *kobj,
769                                             struct attribute *attr,
770                                             const char *buffer, size_t count)
771 {
772         struct obd_device *obd = container_of(kobj, struct obd_device,
773                                               obd_kset.kobj);
774         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
775
776         if (!max_file_warned) {
777                 max_file_warned = true;
778                 pr_info("ofd: 'obdfilter.*.readcache_max_filesize' is deprecated, use 'osd-*.readcache_max_filesize' instead\n");
779         }
780
781         if (!ofd->ofd_read_cache_max_filesize)
782                 return -EOPNOTSUPP;
783
784         return lustre_attr_store(&ofd->ofd_osd->dd_kobj,
785                                  ofd->ofd_read_cache_max_filesize,
786                                  buffer, count);
787 }
788 LUSTRE_RW_ATTR(readcache_max_filesize);
789
790 static ssize_t writethrough_cache_enable_show(struct kobject *kobj,
791                                               struct attribute *attr,
792                                               char *buf)
793 {
794         struct obd_device *obd = container_of(kobj, struct obd_device,
795                                               obd_kset.kobj);
796         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
797
798         if (!wr_cache_warned) {
799                 wr_cache_warned = true;
800                 pr_info("ofd: 'obdfilter.*.writethrough_cache_enabled' is deprecated, use 'osd-*.writethrough_cache_enabled' instead\n");
801         }
802
803         if (!ofd->ofd_write_cache_enable)
804                 return -EOPNOTSUPP;
805
806         return lustre_attr_show(&ofd->ofd_osd->dd_kobj,
807                                 ofd->ofd_write_cache_enable, buf);
808 }
809
810 static ssize_t writethrough_cache_enable_store(struct kobject *kobj,
811                                                struct attribute *attr,
812                                                const char *buffer, size_t count)
813 {
814         struct obd_device *obd = container_of(kobj, struct obd_device,
815                                               obd_kset.kobj);
816         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
817
818         if (!ofd->ofd_write_cache_enable)
819                 return -EOPNOTSUPP;
820
821         return lustre_attr_store(&ofd->ofd_osd->dd_kobj,
822                                  ofd->ofd_write_cache_enable,
823                                  buffer, count);
824 }
825 LUSTRE_RW_ATTR(writethrough_cache_enable);
826 #endif
827
828 LPROC_SEQ_FOPS_RO_TYPE(ofd, recovery_status);
829 LUSTRE_RW_ATTR(recovery_time_hard);
830 LUSTRE_RW_ATTR(recovery_time_soft);
831 LUSTRE_RW_ATTR(ir_factor);
832
833 LPROC_SEQ_FOPS_WR_ONLY(ofd, evict_client);
834 LPROC_SEQ_FOPS_RW_TYPE(ofd, checksum_dump);
835 LUSTRE_RW_ATTR(job_cleanup_interval);
836
837 LUSTRE_RO_ATTR(tot_dirty);
838 LUSTRE_RO_ATTR(tot_granted);
839 LUSTRE_RO_ATTR(tot_pending);
840 LUSTRE_RW_ATTR(grant_compat_disable);
841 LUSTRE_RO_ATTR(instance);
842
843 LUSTRE_RO_ATTR(num_exports);
844
845 struct lprocfs_vars lprocfs_ofd_obd_vars[] = {
846         { .name =       "last_id",
847           .fops =       &ofd_last_id_fops               },
848         { .name =       "recovery_status",
849           .fops =       &ofd_recovery_status_fops       },
850         { .name =       "evict_client",
851           .fops =       &ofd_evict_client_fops          },
852         { .name =       "brw_size",
853           .fops =       &ofd_brw_size_fops              },
854         { .name =       "checksum_dump",
855           .fops =       &ofd_checksum_dump_fops         },
856         { .name =       "lfsck_layout",
857           .fops =       &ofd_lfsck_layout_fops          },
858         { .name =       "lfsck_verify_pfid",
859           .fops =       &ofd_lfsck_verify_pfid_fops     },
860         { .name =       "site_stats",
861           .fops =       &ofd_site_stats_fops            },
862         { NULL }
863 };
864
865 /**
866  * Initialize OFD statistics counters
867  *
868  * param[in] stats      statistics counters
869  */
870 void ofd_stats_counter_init(struct lprocfs_stats *stats)
871 {
872         LASSERT(stats && stats->ls_num >= LPROC_OFD_STATS_LAST);
873
874         lprocfs_counter_init(stats, LPROC_OFD_STATS_READ,
875                              LPROCFS_CNTR_AVGMINMAX, "read_bytes", "bytes");
876         lprocfs_counter_init(stats, LPROC_OFD_STATS_WRITE,
877                              LPROCFS_CNTR_AVGMINMAX, "write_bytes", "bytes");
878         lprocfs_counter_init(stats, LPROC_OFD_STATS_GETATTR,
879                              0, "getattr", "reqs");
880         lprocfs_counter_init(stats, LPROC_OFD_STATS_SETATTR,
881                              0, "setattr", "reqs");
882         lprocfs_counter_init(stats, LPROC_OFD_STATS_PUNCH,
883                              0, "punch", "reqs");
884         lprocfs_counter_init(stats, LPROC_OFD_STATS_SYNC,
885                              0, "sync", "reqs");
886         lprocfs_counter_init(stats, LPROC_OFD_STATS_DESTROY,
887                              0, "destroy", "reqs");
888         lprocfs_counter_init(stats, LPROC_OFD_STATS_CREATE,
889                              0, "create", "reqs");
890         lprocfs_counter_init(stats, LPROC_OFD_STATS_STATFS,
891                              0, "statfs", "reqs");
892         lprocfs_counter_init(stats, LPROC_OFD_STATS_GET_INFO,
893                              0, "get_info", "reqs");
894         lprocfs_counter_init(stats, LPROC_OFD_STATS_SET_INFO,
895                              0, "set_info", "reqs");
896         lprocfs_counter_init(stats, LPROC_OFD_STATS_QUOTACTL,
897                              0, "quotactl", "reqs");
898 }
899
900 LPROC_SEQ_FOPS(lprocfs_nid_stats_clear);
901
902 static struct attribute *ofd_attrs[] = {
903         &lustre_attr_tot_dirty.attr,
904         &lustre_attr_tot_granted.attr,
905         &lustre_attr_tot_pending.attr,
906         &lustre_attr_grant_compat_disable.attr,
907         &lustre_attr_instance.attr,
908         &lustre_attr_recovery_time_hard.attr,
909         &lustre_attr_recovery_time_soft.attr,
910         &lustre_attr_ir_factor.attr,
911         &lustre_attr_num_exports.attr,
912         &lustre_attr_seqs_allocated.attr,
913         &lustre_attr_grant_precreate.attr,
914         &lustre_attr_precreate_batch.attr,
915         &lustre_attr_degraded.attr,
916         &lustre_attr_fstype.attr,
917         &lustre_attr_no_precreate.attr,
918         &lustre_attr_sync_journal.attr,
919 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 16, 53, 0)
920         &lustre_attr_sync_on_lock_cancel.attr,
921 #endif
922         &lustre_attr_soft_sync_limit.attr,
923         &lustre_attr_lfsck_speed_limit.attr,
924         &lustre_attr_job_cleanup_interval.attr,
925         &lustre_attr_checksum_t10pi_enforce.attr,
926 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 14, 53, 0)
927         &lustre_attr_read_cache_enable.attr,
928         &lustre_attr_readcache_max_filesize.attr,
929         &lustre_attr_writethrough_cache_enable.attr,
930 #endif
931         NULL,
932 };
933
934 /**
935  * Initialize all needed procfs entries for OFD device.
936  *
937  * \param[in] ofd       OFD device
938  *
939  * \retval              0 if successful
940  * \retval              negative value on error
941  */
942 int ofd_tunables_init(struct ofd_device *ofd)
943 {
944         struct obd_device *obd = ofd_obd(ofd);
945         struct proc_dir_entry *entry;
946         int rc = 0;
947
948         ENTRY;
949         /* lprocfs must be setup before the ofd so state can be safely added
950          * to /proc incrementally as the ofd is setup
951          */
952         obd->obd_ktype.default_attrs = ofd_attrs;
953         obd->obd_vars = lprocfs_ofd_obd_vars;
954         rc = lprocfs_obd_setup(obd, false);
955         if (rc) {
956                 CERROR("%s: lprocfs_obd_setup failed: %d.\n",
957                        obd->obd_name, rc);
958                 RETURN(rc);
959         }
960
961         rc = tgt_tunables_init(&ofd->ofd_lut);
962         if (rc) {
963                 CERROR("%s: tgt_tunables_init failed: rc = %d\n",
964                        obd->obd_name, rc);
965                 GOTO(obd_cleanup, rc);
966         }
967
968         rc = lprocfs_alloc_obd_stats(obd, LPROC_OFD_STATS_LAST);
969         if (rc) {
970                 CERROR("%s: lprocfs_alloc_obd_stats failed: %d.\n",
971                        obd->obd_name, rc);
972                 GOTO(tgt_cleanup, rc);
973         }
974
975         entry = lprocfs_register("exports", obd->obd_proc_entry, NULL, NULL);
976         if (IS_ERR(entry)) {
977                 rc = PTR_ERR(entry);
978                 CERROR("%s: error %d setting up lprocfs for %s\n",
979                        obd->obd_name, rc, "exports");
980                 GOTO(obd_free_stats, rc);
981         }
982         obd->obd_proc_exports_entry = entry;
983
984         entry = lprocfs_add_simple(obd->obd_proc_exports_entry, "clear",
985                                    obd, &lprocfs_nid_stats_clear_fops);
986         if (IS_ERR(entry)) {
987                 rc = PTR_ERR(entry);
988                 CERROR("%s: add proc entry 'clear' failed: %d.\n",
989                        obd->obd_name, rc);
990                 GOTO(obd_free_stats, rc);
991         }
992
993         ofd_stats_counter_init(obd->obd_stats);
994
995         rc = lprocfs_job_stats_init(obd, LPROC_OFD_STATS_LAST,
996                                     ofd_stats_counter_init);
997         if (rc)
998                 GOTO(obd_free_stats, rc);
999
1000         RETURN(0);
1001
1002 obd_free_stats:
1003         lprocfs_free_obd_stats(obd);
1004 tgt_cleanup:
1005         tgt_tunables_fini(&ofd->ofd_lut);
1006 obd_cleanup:
1007         lprocfs_obd_cleanup(obd);
1008
1009         return rc;
1010 }
1011 #endif /* CONFIG_PROC_FS */