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