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