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