Whamcloud - gitweb
LU-11186 ofd: fix for a final oid at sequence
[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 int ofd_seqs_seq_show(struct seq_file *m, void *data)
63 {
64         struct obd_device *obd = m->private;
65         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
66
67         seq_printf(m, "%u\n", ofd->ofd_seq_count);
68         return 0;
69 }
70 LPROC_SEQ_FOPS_RO(ofd_seqs);
71
72 /**
73  * Show total number of grants for precreate.
74  *
75  * \param[in] m         seq_file handle
76  * \param[in] data      unused for single entry
77  *
78  * \retval              0 on success
79  * \retval              negative value on error
80  */
81 static int ofd_grant_precreate_seq_show(struct seq_file *m, void *data)
82 {
83         struct obd_device *obd = m->private;
84
85         LASSERT(obd != NULL);
86         seq_printf(m, "%ld\n",
87                    obd->obd_self_export->exp_target_data.ted_grant);
88         return 0;
89 }
90 LPROC_SEQ_FOPS_RO(ofd_grant_precreate);
91
92 /**
93  * Show number of precreates allowed in a single transaction.
94  *
95  * \param[in] m         seq_file handle
96  * \param[in] data      unused for single entry
97  *
98  * \retval              0 on success
99  * \retval              negative value on error
100  */
101 static int ofd_precreate_batch_seq_show(struct seq_file *m, void *data)
102 {
103         struct obd_device *obd = m->private;
104         struct ofd_device *ofd;
105
106         LASSERT(obd != NULL);
107         ofd = ofd_dev(obd->obd_lu_dev);
108         seq_printf(m, "%d\n", ofd->ofd_precreate_batch);
109         return 0;
110 }
111
112 /**
113  * Change number of precreates allowed in a single transaction.
114  *
115  * \param[in] file      proc file
116  * \param[in] buffer    string which represents maximum number
117  * \param[in] count     \a buffer length
118  * \param[in] off       unused for single entry
119  *
120  * \retval              \a count on success
121  * \retval              negative number on error
122  */
123 static ssize_t
124 ofd_precreate_batch_seq_write(struct file *file, const char __user *buffer,
125                               size_t count, loff_t *off)
126 {
127         struct seq_file *m = file->private_data;
128         struct obd_device *obd = m->private;
129         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
130         unsigned int val;
131         int rc;
132
133         rc = kstrtouint_from_user(buffer, count, 0, &val);
134         if (rc)
135                 return rc;
136
137         if (val < 1 || val > 65536)
138                 return -EINVAL;
139
140         spin_lock(&ofd->ofd_batch_lock);
141         ofd->ofd_precreate_batch = val;
142         spin_unlock(&ofd->ofd_batch_lock);
143         return count;
144 }
145 LPROC_SEQ_FOPS(ofd_precreate_batch);
146
147 /**
148  * Show the last used ID for each FID sequence used by OFD.
149  *
150  * \param[in] m         seq_file handle
151  * \param[in] data      unused for single entry
152  *
153  * \retval              0 on success
154  * \retval              negative value on error
155  */
156 static int ofd_last_id_seq_show(struct seq_file *m, void *data)
157 {
158         struct obd_device       *obd = m->private;
159         struct ofd_device       *ofd;
160         struct ofd_seq          *oseq = NULL;
161
162         if (obd == NULL)
163                 return 0;
164
165         ofd = ofd_dev(obd->obd_lu_dev);
166
167         read_lock(&ofd->ofd_seq_list_lock);
168         list_for_each_entry(oseq, &ofd->ofd_seq_list, os_list) {
169                 __u64 seq;
170
171                 seq = ostid_seq(&oseq->os_oi) == 0 ?
172                       fid_idif_seq(ostid_id(&oseq->os_oi),
173                                    ofd->ofd_lut.lut_lsd.lsd_osd_index) :
174                       ostid_seq(&oseq->os_oi);
175                 seq_printf(m, DOSTID"\n", seq, ostid_id(&oseq->os_oi));
176         }
177         read_unlock(&ofd->ofd_seq_list_lock);
178         return 0;
179 }
180 LPROC_SEQ_FOPS_RO(ofd_last_id);
181
182 /**
183  * Show maximum number of Filter Modification Data (FMD) maintained by OFD.
184  *
185  * \param[in] m         seq_file handle
186  * \param[in] data      unused for single entry
187  *
188  * \retval              0 on success
189  * \retval              negative value on error
190  */
191 static int ofd_fmd_max_num_seq_show(struct seq_file *m, void *data)
192 {
193         struct obd_device *obd = m->private;
194         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
195
196         seq_printf(m, "%u\n", ofd->ofd_fmd_max_num);
197         return 0;
198 }
199
200 /**
201  * Change number of FMDs maintained by OFD.
202  *
203  * This defines how large the list of FMDs can be.
204  *
205  * \param[in] file      proc file
206  * \param[in] buffer    string which represents maximum number
207  * \param[in] count     \a buffer length
208  * \param[in] off       unused for single entry
209  *
210  * \retval              \a count on success
211  * \retval              negative number on error
212  */
213 static ssize_t
214 ofd_fmd_max_num_seq_write(struct file *file, const char __user *buffer,
215                           size_t count, loff_t *off)
216 {
217         struct seq_file *m = file->private_data;
218         struct obd_device *obd = m->private;
219         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
220         int val;
221         int rc;
222
223         rc = kstrtoint_from_user(buffer, count, 0, &val);
224         if (rc)
225                 return rc;
226
227         if (val < 1 || val > 65536)
228                 return -EINVAL;
229
230         ofd->ofd_fmd_max_num = val;
231         return count;
232 }
233 LPROC_SEQ_FOPS(ofd_fmd_max_num);
234
235 /**
236  * Show the maximum age of FMD data in seconds.
237  *
238  * \param[in] m         seq_file handle
239  * \param[in] data      unused for single entry
240  *
241  * \retval              0 on success
242  * \retval              negative value on error
243  */
244 static int ofd_fmd_max_age_seq_show(struct seq_file *m, void *data)
245 {
246         struct obd_device *obd = m->private;
247         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
248
249         seq_printf(m, "%lld\n", ofd->ofd_fmd_max_age);
250         return 0;
251 }
252
253 /**
254  * Set the maximum age of FMD data in seconds.
255  *
256  * This defines how long FMD data stays in the FMD list.
257  *
258  * \param[in] file      proc file
259  * \param[in] buffer    string which represents maximum number
260  * \param[in] count     \a buffer length
261  * \param[in] off       unused for single entry
262  *
263  * \retval              \a count on success
264  * \retval              negative number on error
265  */
266 static ssize_t
267 ofd_fmd_max_age_seq_write(struct file *file, const char __user *buffer,
268                           size_t count, loff_t *off)
269 {
270         struct seq_file         *m = file->private_data;
271         struct obd_device       *obd = m->private;
272         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
273         time64_t val;
274         int rc;
275
276         rc = kstrtoll_from_user(buffer, count, 0, &val);
277         if (rc)
278                 return rc;
279
280         if (val < 1 || val > 65536) /* ~ 18 hour max */
281                 return -EINVAL;
282
283         ofd->ofd_fmd_max_age = val;
284         return count;
285 }
286 LPROC_SEQ_FOPS(ofd_fmd_max_age);
287
288 /**
289  * Show if the OFD is in degraded mode.
290  *
291  * Degraded means OFD has a failed drive or is undergoing RAID rebuild.
292  * The MDS will try to avoid using this OST for new object allocations
293  * to reduce the impact to global IO performance when clients writing to
294  * this OST are slowed down.  It also reduces the contention on the OST
295  * RAID device, allowing it to rebuild more quickly.
296  *
297  * \param[in] m         seq_file handle
298  * \param[in] data      unused for single entry
299  *
300  * \retval              0 on success
301  * \retval              negative value on error
302  */
303 static int ofd_degraded_seq_show(struct seq_file *m, void *data)
304 {
305         struct obd_device *obd = m->private;
306         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
307
308         seq_printf(m, "%u\n", ofd->ofd_raid_degraded);
309         return 0;
310 }
311
312 /**
313  * Set OFD to degraded mode.
314  *
315  * This is used to interface to userspace administrative tools for
316  * the underlying RAID storage, so that they can mark an OST
317  * as having degraded performance.
318  *
319  * \param[in] file      proc file
320  * \param[in] buffer    string which represents mode
321  *                      1: set degraded mode
322  *                      0: unset degraded mode
323  * \param[in] count     \a buffer length
324  * \param[in] off       unused for single entry
325  *
326  * \retval              \a count on success
327  * \retval              negative number on error
328  */
329 static ssize_t
330 ofd_degraded_seq_write(struct file *file, const char __user *buffer,
331                        size_t count, loff_t *off)
332 {
333         struct seq_file *m = file->private_data;
334         struct obd_device *obd = m->private;
335         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
336         bool val;
337         int rc;
338
339         rc = kstrtobool_from_user(buffer, count, &val);
340         if (rc)
341                 return rc;
342
343         spin_lock(&ofd->ofd_flags_lock);
344         ofd->ofd_raid_degraded = val;
345         spin_unlock(&ofd->ofd_flags_lock);
346         return count;
347 }
348 LPROC_SEQ_FOPS(ofd_degraded);
349
350 /**
351  * Show OFD filesystem type.
352  *
353  * \param[in] m         seq_file handle
354  * \param[in] data      unused for single entry
355  *
356  * \retval              0 on success
357  * \retval              negative value on error
358  */
359 static int ofd_fstype_seq_show(struct seq_file *m, void *data)
360 {
361         struct obd_device *obd = m->private;
362         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
363         struct lu_device  *d;
364
365         LASSERT(ofd->ofd_osd);
366         d = &ofd->ofd_osd->dd_lu_dev;
367         LASSERT(d->ld_type);
368         seq_printf(m, "%s\n", d->ld_type->ldt_name);
369         return 0;
370 }
371 LPROC_SEQ_FOPS_RO(ofd_fstype);
372
373 /**
374  * Show journal handling mode: synchronous or asynchronous.
375  *
376  * When running in asynchronous mode the journal transactions are not
377  * committed to disk before the RPC is replied back to the client.
378  * This will typically improve client performance when only a small number
379  * of clients are writing, since the client(s) can have more write RPCs
380  * in flight. However, it also means that the client has to handle recovery
381  * on bulk RPCs, and will have to keep more dirty pages in cache before they
382  * are committed on the OST.
383  *
384  * \param[in] m         seq_file handle
385  * \param[in] data      unused for single entry
386  *
387  * \retval              0 on success
388  * \retval              negative value on error
389  */
390 static int ofd_syncjournal_seq_show(struct seq_file *m, void *data)
391 {
392         struct obd_device       *obd = m->private;
393         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
394
395         seq_printf(m, "%u\n", ofd->ofd_syncjournal);
396         return 0;
397 }
398
399 /**
400  * Set journal mode to synchronous or asynchronous.
401  *
402  * \param[in] file      proc file
403  * \param[in] buffer    string which represents mode
404  *                      1: synchronous mode
405  *                      0: asynchronous mode
406  * \param[in] count     \a buffer length
407  * \param[in] off       unused for single entry
408  *
409  * \retval              \a count on success
410  * \retval              negative number on error
411  */
412 static ssize_t
413 ofd_syncjournal_seq_write(struct file *file, const char __user *buffer,
414                           size_t count, loff_t *off)
415 {
416         struct seq_file *m = file->private_data;
417         struct obd_device *obd = m->private;
418         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
419         bool val;
420         int rc;
421
422         rc = kstrtobool_from_user(buffer, count, &val);
423         if (rc)
424                 return rc;
425
426         spin_lock(&ofd->ofd_flags_lock);
427         ofd->ofd_syncjournal = val;
428         ofd_slc_set(ofd);
429         spin_unlock(&ofd->ofd_flags_lock);
430
431         return count;
432 }
433 LPROC_SEQ_FOPS(ofd_syncjournal);
434
435 /* This must be longer than the longest string below */
436 #define SYNC_STATES_MAXLEN 16
437
438 static int ofd_brw_size_seq_show(struct seq_file *m, void *data)
439 {
440         struct obd_device       *obd = m->private;
441         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
442
443         seq_printf(m, "%u\n", ofd->ofd_brw_size / ONE_MB_BRW_SIZE);
444         return 0;
445 }
446
447 static ssize_t
448 ofd_brw_size_seq_write(struct file *file, const char __user *buffer,
449                        size_t count, loff_t *off)
450 {
451         struct seq_file *m = file->private_data;
452         struct obd_device *obd = m->private;
453         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
454         __s64 val;
455         int rc;
456
457         rc = lprocfs_str_with_units_to_s64(buffer, count, &val, 'M');
458         if (rc)
459                 return rc;
460
461         if (val <= 0)
462                 return -EINVAL;
463
464         if (val > DT_MAX_BRW_SIZE ||
465             val < (1 << ofd->ofd_lut.lut_tgd.tgd_blockbits))
466                 return -ERANGE;
467
468         spin_lock(&ofd->ofd_flags_lock);
469         ofd->ofd_brw_size = val;
470         spin_unlock(&ofd->ofd_flags_lock);
471
472         return count;
473 }
474 LPROC_SEQ_FOPS(ofd_brw_size);
475
476 static char *sync_on_cancel_states[] = {"never",
477                                         "blocking",
478                                         "always" };
479
480 /**
481  * Show OFD policy for handling dirty data under a lock being cancelled.
482  *
483  * \param[in] m         seq_file handle
484  * \param[in] data      unused for single entry
485  *
486  * \retval              0 on success
487  * \retval              negative value on error
488  */
489 static int ofd_sync_lock_cancel_seq_show(struct seq_file *m, void *data)
490 {
491         struct obd_device       *obd = m->private;
492         struct lu_target        *tgt = obd->u.obt.obt_lut;
493
494         seq_printf(m, "%s\n",
495                    sync_on_cancel_states[tgt->lut_sync_lock_cancel]);
496         return 0;
497 }
498
499 /**
500  * Change OFD policy for handling dirty data under a lock being cancelled.
501  *
502  * This variable defines what action OFD takes upon lock cancel
503  * There are three possible modes:
504  * 1) never - never do sync upon lock cancel. This can lead to data
505  *    inconsistencies if both the OST and client crash while writing a file
506  *    that is also concurrently being read by another client. In these cases,
507  *    this may allow the file data to "rewind" to an earlier state.
508  * 2) blocking - do sync only if there is blocking lock, e.g. if another
509  *    client is trying to access this same object
510  * 3) always - do sync always
511  *
512  * \param[in] file      proc file
513  * \param[in] buffer    string which represents policy
514  * \param[in] count     \a buffer length
515  * \param[in] off       unused for single entry
516  *
517  * \retval              \a count on success
518  * \retval              negative number on error
519  */
520 static ssize_t
521 ofd_sync_lock_cancel_seq_write(struct file *file, const char __user *buffer,
522                                size_t count, loff_t *off)
523 {
524         struct seq_file *m = file->private_data;
525         struct obd_device *obd = m->private;
526         struct lu_target *tgt = obd->u.obt.obt_lut;
527         char kernbuf[SYNC_STATES_MAXLEN];
528         int val = -1;
529         int i;
530
531         if (count == 0 || count >= sizeof(kernbuf))
532                 return -EINVAL;
533
534         if (copy_from_user(kernbuf, buffer, count))
535                 return -EFAULT;
536         kernbuf[count] = 0;
537
538         if (kernbuf[count - 1] == '\n')
539                 kernbuf[count - 1] = 0;
540
541         for (i = 0 ; i < NUM_SYNC_ON_CANCEL_STATES; i++) {
542                 if (strcmp(kernbuf, sync_on_cancel_states[i]) == 0) {
543                         val = i;
544                         break;
545                 }
546         }
547
548         /* Legacy numeric codes */
549         if (val == -1) {
550                 int rc = kstrtoint_from_user(buffer, count, 0, &val);
551                 if (rc)
552                         return rc;
553         }
554
555         if (val < 0 || val > 2)
556                 return -EINVAL;
557
558         spin_lock(&tgt->lut_flags_lock);
559         tgt->lut_sync_lock_cancel = val;
560         spin_unlock(&tgt->lut_flags_lock);
561         return count;
562 }
563 LPROC_SEQ_FOPS(ofd_sync_lock_cancel);
564
565 /**
566  * Show the limit of soft sync RPCs.
567  *
568  * This value defines how many IO RPCs with OBD_BRW_SOFT_SYNC flag
569  * are allowed before sync update will be triggered.
570  *
571  * \param[in] m         seq_file handle
572  * \param[in] data      unused for single entry
573  *
574  * \retval              0 on success
575  * \retval              negative value on error
576  */
577 static int ofd_soft_sync_limit_seq_show(struct seq_file *m, void *data)
578 {
579         struct obd_device       *obd = m->private;
580         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
581
582         seq_printf(m, "%u\n", ofd->ofd_soft_sync_limit);
583         return 0;
584 }
585
586 /**
587  * Change the limit of soft sync RPCs.
588  *
589  * Define how many IO RPCs with OBD_BRW_SOFT_SYNC flag
590  * allowed before sync update will be done.
591  *
592  * This limit is global across all exports.
593  *
594  * \param[in] file      proc file
595  * \param[in] buffer    string which represents limit
596  * \param[in] count     \a buffer length
597  * \param[in] off       unused for single entry
598  *
599  * \retval              \a count on success
600  * \retval              negative number on error
601  */
602 static ssize_t
603 ofd_soft_sync_limit_seq_write(struct file *file, const char __user *buffer,
604                               size_t count, loff_t *off)
605 {
606         struct seq_file *m = file->private_data;
607         struct obd_device *obd = m->private;
608         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
609         unsigned int val;
610         int rc;
611
612         rc = kstrtouint_from_user(buffer, count, 0, &val);
613         if (rc < 0)
614                 return rc;
615
616         ofd->ofd_soft_sync_limit = val;
617         return 0;
618 }
619 LPROC_SEQ_FOPS(ofd_soft_sync_limit);
620
621 /**
622  * Show the LFSCK speed limit.
623  *
624  * The maximum number of items scanned per second.
625  *
626  * \param[in] m         seq_file handle
627  * \param[in] data      unused for single entry
628  *
629  * \retval              0 on success
630  * \retval              negative value on error
631  */
632 static int ofd_lfsck_speed_limit_seq_show(struct seq_file *m, void *data)
633 {
634         struct obd_device       *obd = m->private;
635         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
636
637         return lfsck_get_speed(m, ofd->ofd_osd);
638 }
639
640 /**
641  * Change the LFSCK speed limit.
642  *
643  * Limit number of items that may be scanned per second.
644  *
645  * \param[in] file      proc file
646  * \param[in] buffer    string which represents limit
647  * \param[in] count     \a buffer length
648  * \param[in] off       unused for single entry
649  *
650  * \retval              \a count on success
651  * \retval              negative number on error
652  */
653 static ssize_t
654 ofd_lfsck_speed_limit_seq_write(struct file *file, const char __user *buffer,
655                                 size_t count, loff_t *off)
656 {
657         struct seq_file *m = file->private_data;
658         struct obd_device *obd = m->private;
659         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
660         unsigned long long val;
661         int rc;
662
663         rc = kstrtoull_from_user(buffer, count, 0, &val);
664         if (rc != 0)
665                 return rc;
666
667         rc = lfsck_set_speed(ofd->ofd_osd, val);
668
669         return rc != 0 ? rc : count;
670 }
671 LPROC_SEQ_FOPS(ofd_lfsck_speed_limit);
672
673 /**
674  * Show LFSCK layout verification stats from the most recent LFSCK run.
675  *
676  * \param[in] m         seq_file handle
677  * \param[in] data      unused for single entry
678  *
679  * \retval              0 on success
680  * \retval              negative value on error
681  */
682 static int ofd_lfsck_layout_seq_show(struct seq_file *m, void *data)
683 {
684         struct obd_device *obd = m->private;
685         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
686
687         return lfsck_dump(m, ofd->ofd_osd, LFSCK_TYPE_LAYOUT);
688 }
689 LPROC_SEQ_FOPS_RO(ofd_lfsck_layout);
690
691 /**
692  * Show if LFSCK performed parent FID verification.
693  *
694  * \param[in] m         seq_file handle
695  * \param[in] data      unused for single entry
696  *
697  * \retval              0 on success
698  * \retval              negative value on error
699  */
700 static int ofd_lfsck_verify_pfid_seq_show(struct seq_file *m, void *data)
701 {
702         struct obd_device *obd = m->private;
703         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
704
705         seq_printf(m, "switch: %s\ndetected: %llu\nrepaired: %llu\n",
706                    ofd->ofd_lfsck_verify_pfid ? "on" : "off",
707                    ofd->ofd_inconsistency_self_detected,
708                    ofd->ofd_inconsistency_self_repaired);
709         return 0;
710 }
711
712 /**
713  * Set the LFSCK behavior to verify parent FID correctness.
714  *
715  * If flag ofd_lfsck_verify_pfid is set then LFSCK does parent FID
716  * verification during read/write operations.
717  *
718  * \param[in] file      proc file
719  * \param[in] buffer    string which represents behavior
720  *                      1: verify parent FID
721  *                      0: don't verify parent FID
722  * \param[in] count     \a buffer length
723  * \param[in] off       unused for single entry
724  *
725  * \retval              \a count on success
726  * \retval              negative number on error
727  */
728 static ssize_t
729 ofd_lfsck_verify_pfid_seq_write(struct file *file, const char __user *buffer,
730                                 size_t count, loff_t *off)
731 {
732         struct seq_file *m = file->private_data;
733         struct obd_device *obd = m->private;
734         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
735         bool val;
736         int rc;
737
738         rc = kstrtobool_from_user(buffer, count, &val);
739         if (rc)
740                 return rc;
741
742         ofd->ofd_lfsck_verify_pfid = val;
743         if (!ofd->ofd_lfsck_verify_pfid) {
744                 ofd->ofd_inconsistency_self_detected = 0;
745                 ofd->ofd_inconsistency_self_repaired = 0;
746         }
747
748         return count;
749 }
750 LPROC_SEQ_FOPS(ofd_lfsck_verify_pfid);
751
752 static int ofd_site_stats_seq_show(struct seq_file *m, void *data)
753 {
754         struct obd_device *obd = m->private;
755
756         return lu_site_stats_seq_print(obd->obd_lu_dev->ld_site, m);
757 }
758 LPROC_SEQ_FOPS_RO(ofd_site_stats);
759
760 /**
761  * Show if the OFD enforces T10PI checksum.
762  *
763  * \param[in] m         seq_file handle
764  * \param[in] data      unused for single entry
765  *
766  * \retval              0 on success
767  * \retval              negative value on error
768  */
769 static int ofd_checksum_t10pi_enforce_seq_show(struct seq_file *m, void *data)
770 {
771         struct obd_device *obd = m->private;
772         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
773
774         seq_printf(m, "%u\n", ofd->ofd_checksum_t10pi_enforce);
775         return 0;
776 }
777
778 /**
779  * Force specific T10PI checksum modes to be enabled
780  *
781  * If T10PI *is* supported in hardware, allow only the supported T10PI type
782  * to be used. If T10PI is *not* supported by the OSD, setting the enforce
783  * parameter forces all T10PI types to be enabled (even if slower) for
784  * testing.
785  *
786  * The final determination of which algorithm to be used depends whether
787  * the client supports T10PI or not, and is handled at client connect time.
788  *
789  * \param[in] file      proc file
790  * \param[in] buffer    string which represents mode
791  *                      1: set T10PI checksums enforced
792  *                      0: unset T10PI checksums enforced
793  * \param[in] count     \a buffer length
794  * \param[in] off       unused for single entry
795  *
796  * \retval              \a count on success
797  * \retval              negative number on error
798  */
799 static ssize_t
800 ofd_checksum_t10pi_enforce_seq_write(struct file *file,
801                                      const char __user *buffer,
802                                      size_t count, loff_t *off)
803 {
804         struct seq_file *m = file->private_data;
805         struct obd_device *obd = m->private;
806         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
807         bool enforce;
808         int rc;
809
810         rc = kstrtobool_from_user(buffer, count, &enforce);
811         if (rc)
812                 return rc;
813
814         spin_lock(&ofd->ofd_flags_lock);
815         ofd->ofd_checksum_t10pi_enforce = enforce;
816         spin_unlock(&ofd->ofd_flags_lock);
817         return count;
818 }
819 LPROC_SEQ_FOPS(ofd_checksum_t10pi_enforce);
820
821 LPROC_SEQ_FOPS_RO_TYPE(ofd, recovery_status);
822 LPROC_SEQ_FOPS_RW_TYPE(ofd, recovery_time_soft);
823 LPROC_SEQ_FOPS_RW_TYPE(ofd, recovery_time_hard);
824 LPROC_SEQ_FOPS_WR_ONLY(ofd, evict_client);
825 LPROC_SEQ_FOPS_RO_TYPE(ofd, num_exports);
826 LPROC_SEQ_FOPS_RO_TYPE(ofd, target_instance);
827 LPROC_SEQ_FOPS_RW_TYPE(ofd, ir_factor);
828 LPROC_SEQ_FOPS_RW_TYPE(ofd, checksum_dump);
829 LPROC_SEQ_FOPS_RW_TYPE(ofd, job_interval);
830
831 LPROC_SEQ_FOPS_RO(tgt_tot_dirty);
832 LPROC_SEQ_FOPS_RO(tgt_tot_granted);
833 LPROC_SEQ_FOPS_RO(tgt_tot_pending);
834 LPROC_SEQ_FOPS(tgt_grant_compat_disable);
835
836 struct lprocfs_vars lprocfs_ofd_obd_vars[] = {
837         { .name =       "seqs_allocated",
838           .fops =       &ofd_seqs_fops                  },
839         { .name =       "fstype",
840           .fops =       &ofd_fstype_fops                },
841         { .name =       "last_id",
842           .fops =       &ofd_last_id_fops               },
843         { .name =       "tot_dirty",
844           .fops =       &tgt_tot_dirty_fops             },
845         { .name =       "tot_pending",
846           .fops =       &tgt_tot_pending_fops           },
847         { .name =       "tot_granted",
848           .fops =       &tgt_tot_granted_fops           },
849         { .name =       "grant_precreate",
850           .fops =       &ofd_grant_precreate_fops       },
851         { .name =       "precreate_batch",
852           .fops =       &ofd_precreate_batch_fops       },
853         { .name =       "recovery_status",
854           .fops =       &ofd_recovery_status_fops       },
855         { .name =       "recovery_time_soft",
856           .fops =       &ofd_recovery_time_soft_fops    },
857         { .name =       "recovery_time_hard",
858           .fops =       &ofd_recovery_time_hard_fops    },
859         { .name =       "evict_client",
860           .fops =       &ofd_evict_client_fops          },
861         { .name =       "num_exports",
862           .fops =       &ofd_num_exports_fops           },
863         { .name =       "degraded",
864           .fops =       &ofd_degraded_fops              },
865         { .name =       "sync_journal",
866           .fops =       &ofd_syncjournal_fops           },
867         { .name =       "brw_size",
868           .fops =       &ofd_brw_size_fops              },
869         { .name =       "sync_on_lock_cancel",
870           .fops =       &ofd_sync_lock_cancel_fops      },
871         { .name =       "instance",
872           .fops =       &ofd_target_instance_fops       },
873         { .name =       "ir_factor",
874           .fops =       &ofd_ir_factor_fops             },
875         { .name =       "checksum_dump",
876           .fops =       &ofd_checksum_dump_fops         },
877         { .name =       "grant_compat_disable",
878           .fops =       &tgt_grant_compat_disable_fops  },
879         { .name =       "client_cache_count",
880           .fops =       &ofd_fmd_max_num_fops           },
881         { .name =       "client_cache_seconds",
882           .fops =       &ofd_fmd_max_age_fops           },
883         { .name =       "job_cleanup_interval",
884           .fops =       &ofd_job_interval_fops          },
885         { .name =       "soft_sync_limit",
886           .fops =       &ofd_soft_sync_limit_fops       },
887         { .name =       "lfsck_speed_limit",
888           .fops =       &ofd_lfsck_speed_limit_fops     },
889         { .name =       "lfsck_layout",
890           .fops =       &ofd_lfsck_layout_fops          },
891         { .name =       "lfsck_verify_pfid",
892           .fops =       &ofd_lfsck_verify_pfid_fops     },
893         { .name =       "site_stats",
894           .fops =       &ofd_site_stats_fops            },
895         { .name =       "checksum_t10pi_enforce",
896           .fops =       &ofd_checksum_t10pi_enforce_fops        },
897         { NULL }
898 };
899
900 /**
901  * Initialize OFD statistics counters
902  *
903  * param[in] stats      statistics counters
904  */
905 void ofd_stats_counter_init(struct lprocfs_stats *stats)
906 {
907         LASSERT(stats && stats->ls_num >= LPROC_OFD_STATS_LAST);
908
909         lprocfs_counter_init(stats, LPROC_OFD_STATS_READ,
910                              LPROCFS_CNTR_AVGMINMAX, "read_bytes", "bytes");
911         lprocfs_counter_init(stats, LPROC_OFD_STATS_WRITE,
912                              LPROCFS_CNTR_AVGMINMAX, "write_bytes", "bytes");
913         lprocfs_counter_init(stats, LPROC_OFD_STATS_GETATTR,
914                              0, "getattr", "reqs");
915         lprocfs_counter_init(stats, LPROC_OFD_STATS_SETATTR,
916                              0, "setattr", "reqs");
917         lprocfs_counter_init(stats, LPROC_OFD_STATS_PUNCH,
918                              0, "punch", "reqs");
919         lprocfs_counter_init(stats, LPROC_OFD_STATS_SYNC,
920                              0, "sync", "reqs");
921         lprocfs_counter_init(stats, LPROC_OFD_STATS_DESTROY,
922                              0, "destroy", "reqs");
923         lprocfs_counter_init(stats, LPROC_OFD_STATS_CREATE,
924                              0, "create", "reqs");
925         lprocfs_counter_init(stats, LPROC_OFD_STATS_STATFS,
926                              0, "statfs", "reqs");
927         lprocfs_counter_init(stats, LPROC_OFD_STATS_GET_INFO,
928                              0, "get_info", "reqs");
929         lprocfs_counter_init(stats, LPROC_OFD_STATS_SET_INFO,
930                              0, "set_info", "reqs");
931         lprocfs_counter_init(stats, LPROC_OFD_STATS_QUOTACTL,
932                              0, "quotactl", "reqs");
933 }
934
935 #endif /* CONFIG_PROC_FS */