4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
23 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/ofd/lproc_ofd.c
34 * This file provides functions of procfs interface for OBD Filter Device (OFD).
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>
42 #define DEBUG_SUBSYSTEM S_CLASS
45 #include <lprocfs_status.h>
46 #include <linux/seq_file.h>
47 #include <lustre_lfsck.h>
49 #include "ofd_internal.h"
54 * Show number of FID allocation sequences.
56 * \param[in] m seq_file handle
57 * \param[in] data unused for single entry
59 * \retval 0 on success
60 * \retval negative value on error
62 static ssize_t seqs_allocated_show(struct kobject *kobj, struct attribute *attr,
65 struct obd_device *obd = container_of(kobj, struct obd_device,
67 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
69 return sprintf(buf, "%u\n", ofd->ofd_seq_count);
71 LUSTRE_RO_ATTR(seqs_allocated);
74 * Show total number of grants for precreate.
76 * \param[in] m seq_file handle
77 * \param[in] data unused for single entry
79 * \retval 0 on success
80 * \retval negative value on error
82 static ssize_t grant_precreate_show(struct kobject *kobj,
83 struct attribute *attr,
86 struct obd_device *obd = container_of(kobj, struct obd_device,
89 return sprintf(buf, "%ld\n",
90 obd->obd_self_export->exp_target_data.ted_grant);
92 LUSTRE_RO_ATTR(grant_precreate);
95 * Show number of precreates allowed in a single transaction.
97 * \param[in] m seq_file handle
98 * \param[in] data unused for single entry
100 * \retval 0 on success
101 * \retval negative value on error
103 static ssize_t precreate_batch_show(struct kobject *kobj,
104 struct attribute *attr,
107 struct obd_device *obd = container_of(kobj, struct obd_device,
109 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
111 return sprintf(buf, "%d\n", ofd->ofd_precreate_batch);
115 * Change number of precreates allowed in a single transaction.
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
122 * \retval \a count on success
123 * \retval negative number on error
125 static ssize_t precreate_batch_store(struct kobject *kobj,
126 struct attribute *attr,
127 const char *buffer, size_t count)
129 struct obd_device *obd = container_of(kobj, struct obd_device,
131 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
135 rc = kstrtouint(buffer, 0, &val);
139 if (val < 1 || val > 65536)
142 spin_lock(&ofd->ofd_batch_lock);
143 ofd->ofd_precreate_batch = val;
144 spin_unlock(&ofd->ofd_batch_lock);
147 LUSTRE_RW_ATTR(precreate_batch);
150 * Show the last used ID for each FID sequence used by OFD.
152 * \param[in] m seq_file handle
153 * \param[in] data unused for single entry
155 * \retval 0 on success
156 * \retval negative value on error
158 static int ofd_last_id_seq_show(struct seq_file *m, void *data)
160 struct obd_device *obd = m->private;
161 struct ofd_device *ofd;
162 struct ofd_seq *oseq = NULL;
167 ofd = ofd_dev(obd->obd_lu_dev);
169 read_lock(&ofd->ofd_seq_list_lock);
170 list_for_each_entry(oseq, &ofd->ofd_seq_list, os_list) {
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));
179 read_unlock(&ofd->ofd_seq_list_lock);
183 LPROC_SEQ_FOPS_RO(ofd_last_id);
186 * Show maximum number of Filter Modification Data (FMD) maintained by OFD.
188 * \param[in] m seq_file handle
189 * \param[in] data unused for single entry
191 * \retval 0 on success
192 * \retval negative value on error
194 static ssize_t client_cache_count_show(struct kobject *kobj,
195 struct attribute *attr,
198 struct obd_device *obd = container_of(kobj, struct obd_device,
200 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
202 return sprintf(buf, "%u\n", ofd->ofd_fmd_max_num);
206 * Change number of FMDs maintained by OFD.
208 * This defines how large the list of FMDs can be.
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
215 * \retval \a count on success
216 * \retval negative number on error
218 static ssize_t client_cache_count_store(struct kobject *kobj,
219 struct attribute *attr,
220 const char *buffer, size_t count)
222 struct obd_device *obd = container_of(kobj, struct obd_device,
224 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
228 rc = kstrtoint(buffer, 0, &val);
232 if (val < 1 || val > 65536)
235 ofd->ofd_fmd_max_num = val;
238 LUSTRE_RW_ATTR(client_cache_count);
241 * Show the maximum age of FMD data in seconds.
243 * \param[in] m seq_file handle
244 * \param[in] data unused for single entry
246 * \retval 0 on success
247 * \retval negative value on error
249 static ssize_t client_cache_seconds_show(struct kobject *kobj,
250 struct attribute *attr,
253 struct obd_device *obd = container_of(kobj, struct obd_device,
255 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
257 return sprintf(buf, "%lld\n", ofd->ofd_fmd_max_age);
261 * Set the maximum age of FMD data in seconds.
263 * This defines how long FMD data stays in the FMD list.
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
270 * \retval \a count on success
271 * \retval negative number on error
273 static ssize_t client_cache_seconds_store(struct kobject *kobj,
274 struct attribute *attr,
275 const char *buffer, size_t count)
277 struct obd_device *obd = container_of(kobj, struct obd_device,
279 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
283 rc = kstrtoll(buffer, 0, &val);
287 if (val < 1 || val > 65536) /* ~ 18 hour max */
290 ofd->ofd_fmd_max_age = val;
293 LUSTRE_RW_ATTR(client_cache_seconds);
296 * Show if the OFD is in degraded mode.
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.
304 * \param[in] m seq_file handle
305 * \param[in] data unused for single entry
307 * \retval 0 on success
308 * \retval negative value on error
310 static ssize_t degraded_show(struct kobject *kobj, struct attribute *attr,
313 struct obd_device *obd = container_of(kobj, struct obd_device,
315 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
317 return sprintf(buf, "%u\n", ofd->ofd_raid_degraded);
321 * Set OFD to degraded mode.
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.
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
334 * \retval \a count on success
335 * \retval negative number on error
337 static ssize_t degraded_store(struct kobject *kobj, struct attribute *attr,
338 const char *buffer, size_t count)
340 struct obd_device *obd = container_of(kobj, struct obd_device,
342 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
346 rc = kstrtobool(buffer, &val);
350 spin_lock(&ofd->ofd_flags_lock);
351 ofd->ofd_raid_degraded = val;
352 spin_unlock(&ofd->ofd_flags_lock);
355 LUSTRE_RW_ATTR(degraded);
358 * Show OFD filesystem type.
360 * \param[in] m seq_file handle
361 * \param[in] data unused for single entry
363 * \retval 0 on success
364 * \retval negative value on error
366 static ssize_t fstype_show(struct kobject *kobj, struct attribute *attr,
369 struct obd_device *obd = container_of(kobj, struct obd_device,
371 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
374 LASSERT(ofd->ofd_osd);
375 d = &ofd->ofd_osd->dd_lu_dev;
377 return sprintf(buf, "%s\n", d->ld_type->ldt_name);
379 LUSTRE_RO_ATTR(fstype);
382 * Show journal handling mode: synchronous or asynchronous.
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.
392 * \param[in] m seq_file handle
393 * \param[in] data unused for single entry
395 * \retval 0 on success
396 * \retval negative value on error
398 static ssize_t sync_journal_show(struct kobject *kobj, struct attribute *attr,
401 struct obd_device *obd = container_of(kobj, struct obd_device,
403 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
405 return sprintf(buf, "%u\n", ofd->ofd_sync_journal);
409 * Set journal mode to synchronous or asynchronous.
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
418 * \retval \a count on success
419 * \retval negative number on error
421 static ssize_t sync_journal_store(struct kobject *kobj, struct attribute *attr,
422 const char *buffer, size_t count)
424 struct obd_device *obd = container_of(kobj, struct obd_device,
426 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
430 rc = kstrtobool(buffer, &val);
434 spin_lock(&ofd->ofd_flags_lock);
435 ofd->ofd_sync_journal = val;
437 spin_unlock(&ofd->ofd_flags_lock);
441 LUSTRE_RW_ATTR(sync_journal);
443 /* This must be longer than the longest string below */
444 #define SYNC_STATES_MAXLEN 16
446 static int ofd_brw_size_seq_show(struct seq_file *m, void *data)
448 struct obd_device *obd = m->private;
449 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
451 seq_printf(m, "%u\n", ofd->ofd_brw_size / ONE_MB_BRW_SIZE);
456 ofd_brw_size_seq_write(struct file *file, const char __user *buffer,
457 size_t count, loff_t *off)
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);
465 rc = lprocfs_str_with_units_to_s64(buffer, count, &val, 'M');
472 if (val > DT_MAX_BRW_SIZE ||
473 val < (1 << ofd->ofd_lut.lut_tgd.tgd_blockbits))
476 spin_lock(&ofd->ofd_flags_lock);
477 ofd->ofd_brw_size = val;
478 spin_unlock(&ofd->ofd_flags_lock);
483 LPROC_SEQ_FOPS(ofd_brw_size);
485 static char *sync_on_cancel_states[] = {"never",
490 * Show OFD policy for handling dirty data under a lock being cancelled.
492 * \param[in] m seq_file handle
493 * \param[in] data unused for single entry
495 * \retval 0 on success
496 * \retval negative value on error
498 static ssize_t sync_lock_cancel_show(struct kobject *kobj,
499 struct attribute *attr, char *buf)
501 struct obd_device *obd = container_of(kobj, struct obd_device,
503 struct lu_target *tgt = obd->u.obt.obt_lut;
505 return sprintf(buf, "%s\n",
506 sync_on_cancel_states[tgt->lut_sync_lock_cancel]);
510 * Change OFD policy for handling dirty data under a lock being cancelled.
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
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
527 * \retval \a count on success
528 * \retval negative number on error
530 static ssize_t sync_lock_cancel_store(struct kobject *kobj,
531 struct attribute *attr,
532 const char *buffer, size_t count)
534 struct obd_device *obd = container_of(kobj, struct obd_device,
536 struct lu_target *tgt = obd->u.obt.obt_lut;
540 if (count == 0 || count >= SYNC_STATES_MAXLEN)
543 for (i = 0 ; i < NUM_SYNC_ON_CANCEL_STATES; i++) {
544 if (strcmp(buffer, sync_on_cancel_states[i]) == 0) {
550 /* Legacy numeric codes */
552 int rc = kstrtoint(buffer, 0, &val);
557 if (val < 0 || val > 2)
560 spin_lock(&tgt->lut_flags_lock);
561 tgt->lut_sync_lock_cancel = val;
562 spin_unlock(&tgt->lut_flags_lock);
565 LUSTRE_RW_ATTR(sync_lock_cancel);
568 * Show the limit of soft sync RPCs.
570 * This value defines how many IO RPCs with OBD_BRW_SOFT_SYNC flag
571 * are allowed before sync update will be triggered.
573 * \param[in] m seq_file handle
574 * \param[in] data unused for single entry
576 * \retval 0 on success
577 * \retval negative value on error
579 static ssize_t soft_sync_limit_show(struct kobject *kobj,
580 struct attribute *attr, char *buf)
582 struct obd_device *obd = container_of(kobj, struct obd_device,
584 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
586 return sprintf(buf, "%u\n", ofd->ofd_soft_sync_limit);
590 * Change the limit of soft sync RPCs.
592 * Define how many IO RPCs with OBD_BRW_SOFT_SYNC flag
593 * allowed before sync update will be done.
595 * This limit is global across all exports.
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
602 * \retval \a count on success
603 * \retval negative number on error
605 static ssize_t soft_sync_limit_store(struct kobject *kobj,
606 struct attribute *attr,
607 const char *buffer, size_t count)
609 struct obd_device *obd = container_of(kobj, struct obd_device,
611 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
615 rc = kstrtouint(buffer, 0, &val);
619 ofd->ofd_soft_sync_limit = val;
622 LUSTRE_RW_ATTR(soft_sync_limit);
625 * Show the LFSCK speed limit.
627 * The maximum number of items scanned per second.
629 * \param[in] m seq_file handle
630 * \param[in] data unused for single entry
632 * \retval 0 on success
633 * \retval negative value on error
635 static ssize_t lfsck_speed_limit_show(struct kobject *kobj,
636 struct attribute *attr, char *buf)
638 struct obd_device *obd = container_of(kobj, struct obd_device,
640 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
642 return lfsck_get_speed(buf, ofd->ofd_osd);
646 * Change the LFSCK speed limit.
648 * Limit number of items that may be scanned per second.
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
655 * \retval \a count on success
656 * \retval negative number on error
658 static ssize_t lfsck_speed_limit_store(struct kobject *kobj,
659 struct attribute *attr,
660 const char *buffer, size_t count)
662 struct obd_device *obd = container_of(kobj, struct obd_device,
664 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
668 rc = kstrtouint(buffer, 0, &val);
672 rc = lfsck_set_speed(ofd->ofd_osd, val);
674 return rc != 0 ? rc : count;
676 LUSTRE_RW_ATTR(lfsck_speed_limit);
679 * Show LFSCK layout verification stats from the most recent LFSCK run.
681 * \param[in] m seq_file handle
682 * \param[in] data unused for single entry
684 * \retval 0 on success
685 * \retval negative value on error
687 static int ofd_lfsck_layout_seq_show(struct seq_file *m, void *data)
689 struct obd_device *obd = m->private;
690 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
692 return lfsck_dump(m, ofd->ofd_osd, LFSCK_TYPE_LAYOUT);
695 LPROC_SEQ_FOPS_RO(ofd_lfsck_layout);
698 * Show if LFSCK performed parent FID verification.
700 * \param[in] m seq_file handle
701 * \param[in] data unused for single entry
703 * \retval 0 on success
704 * \retval negative value on error
706 static int ofd_lfsck_verify_pfid_seq_show(struct seq_file *m, void *data)
708 struct obd_device *obd = m->private;
709 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
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);
719 * Set the LFSCK behavior to verify parent FID correctness.
721 * If flag ofd_lfsck_verify_pfid is set then LFSCK does parent FID
722 * verification during read/write operations.
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
731 * \retval \a count on success
732 * \retval negative number on error
735 ofd_lfsck_verify_pfid_seq_write(struct file *file, const char __user *buffer,
736 size_t count, loff_t *off)
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);
744 rc = kstrtobool_from_user(buffer, count, &val);
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;
757 LPROC_SEQ_FOPS(ofd_lfsck_verify_pfid);
759 static int ofd_site_stats_seq_show(struct seq_file *m, void *data)
761 struct obd_device *obd = m->private;
763 return lu_site_stats_seq_print(obd->obd_lu_dev->ld_site, m);
766 LPROC_SEQ_FOPS_RO(ofd_site_stats);
769 * Show if the OFD enforces T10PI checksum.
771 * \param[in] m seq_file handle
772 * \param[in] data unused for single entry
774 * \retval 0 on success
775 * \retval negative value on error
777 static ssize_t checksum_t10pi_enforce_show(struct kobject *kobj,
778 struct attribute *attr,
781 struct obd_device *obd = container_of(kobj, struct obd_device,
783 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
785 return sprintf(buf, "%u\n", ofd->ofd_checksum_t10pi_enforce);
789 * Force specific T10PI checksum modes to be enabled
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
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.
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
806 * \retval \a count on success
807 * \retval negative number on error
809 static ssize_t checksum_t10pi_enforce_store(struct kobject *kobj,
810 struct attribute *attr,
811 const char *buffer, size_t count)
813 struct obd_device *obd = container_of(kobj, struct obd_device,
815 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
819 rc = kstrtobool(buffer, &enforce);
823 spin_lock(&ofd->ofd_flags_lock);
824 ofd->ofd_checksum_t10pi_enforce = enforce;
825 spin_unlock(&ofd->ofd_flags_lock);
828 LUSTRE_RW_ATTR(checksum_t10pi_enforce);
830 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 14, 53, 0)
831 static bool max_file_warned;
832 static bool rd_cache_warned;
833 static bool wr_cache_warned;
835 static ssize_t read_cache_enable_show(struct kobject *kobj,
836 struct attribute *attr,
839 struct obd_device *obd = container_of(kobj, struct obd_device,
841 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
843 if (!rd_cache_warned) {
844 rd_cache_warned = true;
845 pr_info("ofd: 'obdfilter.*.read_cache_enabled' is deprecated, use 'osd-*.read_cache_enabled' instead\n");
848 if (!ofd->ofd_read_cache_enable)
851 return lustre_attr_show(&ofd->ofd_osd->dd_kobj,
852 ofd->ofd_read_cache_enable, buf);
855 static ssize_t read_cache_enable_store(struct kobject *kobj,
856 struct attribute *attr,
857 const char *buffer, size_t count)
859 struct obd_device *obd = container_of(kobj, struct obd_device,
861 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
863 if (!rd_cache_warned) {
864 rd_cache_warned = true;
865 pr_info("ofd: 'obdfilter.*.read_cache_enabled' is deprecated, use 'osd-*.read_cache_enabled' instead\n");
868 if (!ofd->ofd_read_cache_enable)
871 return lustre_attr_store(&ofd->ofd_osd->dd_kobj,
872 ofd->ofd_read_cache_enable, buffer, count);
874 LUSTRE_RW_ATTR(read_cache_enable);
876 static ssize_t readcache_max_filesize_show(struct kobject *kobj,
877 struct attribute *attr,
880 struct obd_device *obd = container_of(kobj, struct obd_device,
882 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
884 if (!max_file_warned) {
885 max_file_warned = true;
886 pr_info("ofd: 'obdfilter.*.readcache_max_filesize' is deprecated, use 'osd-*.readcache_max_filesize' instead\n");
889 if (!ofd->ofd_read_cache_max_filesize)
892 return lustre_attr_show(&ofd->ofd_osd->dd_kobj,
893 ofd->ofd_read_cache_max_filesize, buf);
896 static ssize_t readcache_max_filesize_store(struct kobject *kobj,
897 struct attribute *attr,
898 const char *buffer, size_t count)
900 struct obd_device *obd = container_of(kobj, struct obd_device,
902 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
904 if (!max_file_warned) {
905 max_file_warned = true;
906 pr_info("ofd: 'obdfilter.*.readcache_max_filesize' is deprecated, use 'osd-*.readcache_max_filesize' instead\n");
909 if (!ofd->ofd_read_cache_max_filesize)
912 return lustre_attr_store(&ofd->ofd_osd->dd_kobj,
913 ofd->ofd_read_cache_max_filesize,
916 LUSTRE_RW_ATTR(readcache_max_filesize);
918 static ssize_t writethrough_cache_enable_show(struct kobject *kobj,
919 struct attribute *attr,
922 struct obd_device *obd = container_of(kobj, struct obd_device,
924 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
926 if (!wr_cache_warned) {
927 wr_cache_warned = true;
928 pr_info("ofd: 'obdfilter.*.writethrough_cache_enabled' is deprecated, use 'osd-*.writethrough_cache_enabled' instead\n");
931 if (!ofd->ofd_write_cache_enable)
934 return lustre_attr_show(&ofd->ofd_osd->dd_kobj,
935 ofd->ofd_write_cache_enable, buf);
938 static ssize_t writethrough_cache_enable_store(struct kobject *kobj,
939 struct attribute *attr,
940 const char *buffer, size_t count)
942 struct obd_device *obd = container_of(kobj, struct obd_device,
944 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
946 if (!ofd->ofd_write_cache_enable)
949 return lustre_attr_store(&ofd->ofd_osd->dd_kobj,
950 ofd->ofd_write_cache_enable,
953 LUSTRE_RW_ATTR(writethrough_cache_enable);
956 LPROC_SEQ_FOPS_RO_TYPE(ofd, recovery_status);
957 LPROC_SEQ_FOPS_RW_TYPE(ofd, recovery_time_soft);
958 LPROC_SEQ_FOPS_RW_TYPE(ofd, recovery_time_hard);
959 LPROC_SEQ_FOPS_WR_ONLY(ofd, evict_client);
960 LPROC_SEQ_FOPS_RO_TYPE(ofd, num_exports);
961 LPROC_SEQ_FOPS_RO_TYPE(ofd, target_instance);
962 LPROC_SEQ_FOPS_RW_TYPE(ofd, ir_factor);
963 LPROC_SEQ_FOPS_RW_TYPE(ofd, checksum_dump);
964 LPROC_SEQ_FOPS_RW_TYPE(ofd, job_interval);
966 LPROC_SEQ_FOPS_RO(tgt_tot_dirty);
967 LPROC_SEQ_FOPS_RO(tgt_tot_granted);
968 LPROC_SEQ_FOPS_RO(tgt_tot_pending);
969 LPROC_SEQ_FOPS(tgt_grant_compat_disable);
971 struct lprocfs_vars lprocfs_ofd_obd_vars[] = {
973 .fops = &ofd_last_id_fops },
974 { .name = "tot_dirty",
975 .fops = &tgt_tot_dirty_fops },
976 { .name = "tot_pending",
977 .fops = &tgt_tot_pending_fops },
978 { .name = "tot_granted",
979 .fops = &tgt_tot_granted_fops },
980 { .name = "recovery_status",
981 .fops = &ofd_recovery_status_fops },
982 { .name = "recovery_time_soft",
983 .fops = &ofd_recovery_time_soft_fops },
984 { .name = "recovery_time_hard",
985 .fops = &ofd_recovery_time_hard_fops },
986 { .name = "evict_client",
987 .fops = &ofd_evict_client_fops },
988 { .name = "num_exports",
989 .fops = &ofd_num_exports_fops },
990 { .name = "brw_size",
991 .fops = &ofd_brw_size_fops },
992 { .name = "instance",
993 .fops = &ofd_target_instance_fops },
994 { .name = "ir_factor",
995 .fops = &ofd_ir_factor_fops },
996 { .name = "checksum_dump",
997 .fops = &ofd_checksum_dump_fops },
998 { .name = "grant_compat_disable",
999 .fops = &tgt_grant_compat_disable_fops },
1000 { .name = "job_cleanup_interval",
1001 .fops = &ofd_job_interval_fops },
1002 { .name = "lfsck_layout",
1003 .fops = &ofd_lfsck_layout_fops },
1004 { .name = "lfsck_verify_pfid",
1005 .fops = &ofd_lfsck_verify_pfid_fops },
1006 { .name = "site_stats",
1007 .fops = &ofd_site_stats_fops },
1012 * Initialize OFD statistics counters
1014 * param[in] stats statistics counters
1016 void ofd_stats_counter_init(struct lprocfs_stats *stats)
1018 LASSERT(stats && stats->ls_num >= LPROC_OFD_STATS_LAST);
1020 lprocfs_counter_init(stats, LPROC_OFD_STATS_READ,
1021 LPROCFS_CNTR_AVGMINMAX, "read_bytes", "bytes");
1022 lprocfs_counter_init(stats, LPROC_OFD_STATS_WRITE,
1023 LPROCFS_CNTR_AVGMINMAX, "write_bytes", "bytes");
1024 lprocfs_counter_init(stats, LPROC_OFD_STATS_GETATTR,
1025 0, "getattr", "reqs");
1026 lprocfs_counter_init(stats, LPROC_OFD_STATS_SETATTR,
1027 0, "setattr", "reqs");
1028 lprocfs_counter_init(stats, LPROC_OFD_STATS_PUNCH,
1029 0, "punch", "reqs");
1030 lprocfs_counter_init(stats, LPROC_OFD_STATS_SYNC,
1032 lprocfs_counter_init(stats, LPROC_OFD_STATS_DESTROY,
1033 0, "destroy", "reqs");
1034 lprocfs_counter_init(stats, LPROC_OFD_STATS_CREATE,
1035 0, "create", "reqs");
1036 lprocfs_counter_init(stats, LPROC_OFD_STATS_STATFS,
1037 0, "statfs", "reqs");
1038 lprocfs_counter_init(stats, LPROC_OFD_STATS_GET_INFO,
1039 0, "get_info", "reqs");
1040 lprocfs_counter_init(stats, LPROC_OFD_STATS_SET_INFO,
1041 0, "set_info", "reqs");
1042 lprocfs_counter_init(stats, LPROC_OFD_STATS_QUOTACTL,
1043 0, "quotactl", "reqs");
1046 LPROC_SEQ_FOPS(lprocfs_nid_stats_clear);
1048 static struct attribute *ofd_attrs[] = {
1049 &lustre_attr_seqs_allocated.attr,
1050 &lustre_attr_grant_precreate.attr,
1051 &lustre_attr_precreate_batch.attr,
1052 &lustre_attr_client_cache_count.attr,
1053 &lustre_attr_client_cache_seconds.attr,
1054 &lustre_attr_degraded.attr,
1055 &lustre_attr_fstype.attr,
1056 &lustre_attr_sync_journal.attr,
1057 &lustre_attr_sync_lock_cancel.attr,
1058 &lustre_attr_soft_sync_limit.attr,
1059 &lustre_attr_lfsck_speed_limit.attr,
1060 &lustre_attr_checksum_t10pi_enforce.attr,
1061 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 14, 53, 0)
1062 &lustre_attr_read_cache_enable.attr,
1063 &lustre_attr_readcache_max_filesize.attr,
1064 &lustre_attr_writethrough_cache_enable.attr,
1070 * Initialize all needed procfs entries for OFD device.
1072 * \param[in] ofd OFD device
1074 * \retval 0 if successful
1075 * \retval negative value on error
1077 int ofd_tunables_init(struct ofd_device *ofd)
1079 struct obd_device *obd = ofd_obd(ofd);
1080 struct proc_dir_entry *entry;
1084 /* lprocfs must be setup before the ofd so state can be safely added
1085 * to /proc incrementally as the ofd is setup
1087 obd->obd_ktype.default_attrs = ofd_attrs;
1088 obd->obd_vars = lprocfs_ofd_obd_vars;
1089 rc = lprocfs_obd_setup(obd, false);
1091 CERROR("%s: lprocfs_obd_setup failed: %d.\n",
1096 rc = lprocfs_alloc_obd_stats(obd, LPROC_OFD_STATS_LAST);
1098 CERROR("%s: lprocfs_alloc_obd_stats failed: %d.\n",
1100 GOTO(obd_cleanup, rc);
1103 entry = lprocfs_register("exports", obd->obd_proc_entry, NULL, NULL);
1104 if (IS_ERR(entry)) {
1105 rc = PTR_ERR(entry);
1106 CERROR("%s: error %d setting up lprocfs for %s\n",
1107 obd->obd_name, rc, "exports");
1108 GOTO(obd_free_stats, rc);
1110 obd->obd_proc_exports_entry = entry;
1112 entry = lprocfs_add_simple(obd->obd_proc_exports_entry, "clear",
1113 obd, &lprocfs_nid_stats_clear_fops);
1114 if (IS_ERR(entry)) {
1115 rc = PTR_ERR(entry);
1116 CERROR("%s: add proc entry 'clear' failed: %d.\n",
1118 GOTO(obd_free_stats, rc);
1121 ofd_stats_counter_init(obd->obd_stats);
1123 rc = lprocfs_job_stats_init(obd, LPROC_OFD_STATS_LAST,
1124 ofd_stats_counter_init);
1126 GOTO(obd_free_stats, rc);
1131 lprocfs_free_obd_stats(obd);
1133 lprocfs_obd_cleanup(obd);
1137 #endif /* CONFIG_PROC_FS */