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