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/
31 * lustre/ofd/lproc_ofd.c
33 * This file provides functions of procfs interface for OBD Filter Device (OFD).
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>
41 #define DEBUG_SUBSYSTEM S_CLASS
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>
50 #include "ofd_internal.h"
55 * Show number of FID allocation sequences.
57 * \param[in] m seq_file handle
58 * \param[in] data unused for single entry
60 * \retval 0 on success
61 * \retval negative value on error
63 static ssize_t seqs_allocated_show(struct kobject *kobj, struct attribute *attr,
66 struct obd_device *obd = container_of(kobj, struct obd_device,
68 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
70 return sprintf(buf, "%u\n", ofd->ofd_seq_count);
72 LUSTRE_RO_ATTR(seqs_allocated);
75 * Show total number of grants for precreate.
77 * \param[in] m seq_file handle
78 * \param[in] data unused for single entry
80 * \retval 0 on success
81 * \retval negative value on error
83 static ssize_t grant_precreate_show(struct kobject *kobj,
84 struct attribute *attr,
87 struct obd_device *obd = container_of(kobj, struct obd_device,
90 return sprintf(buf, "%ld\n",
91 obd->obd_self_export->exp_target_data.ted_grant);
93 LUSTRE_RO_ATTR(grant_precreate);
96 * Show number of precreates allowed in a single transaction.
98 * \param[in] m seq_file handle
99 * \param[in] data unused for single entry
101 * \retval 0 on success
102 * \retval negative value on error
104 static ssize_t precreate_batch_show(struct kobject *kobj,
105 struct attribute *attr,
108 struct obd_device *obd = container_of(kobj, struct obd_device,
110 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
112 return sprintf(buf, "%d\n", ofd->ofd_precreate_batch);
116 * Change number of precreates allowed in a single transaction.
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
123 * \retval \a count on success
124 * \retval negative number on error
126 static ssize_t precreate_batch_store(struct kobject *kobj,
127 struct attribute *attr,
128 const char *buffer, size_t count)
130 struct obd_device *obd = container_of(kobj, struct obd_device,
132 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
136 rc = kstrtouint(buffer, 0, &val);
140 if (val < 1 || val > 65536)
143 spin_lock(&ofd->ofd_batch_lock);
144 ofd->ofd_precreate_batch = val;
145 spin_unlock(&ofd->ofd_batch_lock);
148 LUSTRE_RW_ATTR(precreate_batch);
151 * Show number of seconds to delay atime
153 * \param[in] m seq_file handle
154 * \param[in] data unused for single entry
156 * \retval 0 on success
157 * \retval negative value on error
159 static ssize_t atime_diff_show(struct kobject *kobj, struct attribute *attr,
162 struct obd_device *obd = container_of(kobj, struct obd_device,
164 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
166 return scnprintf(buf, PAGE_SIZE, "%lld\n", ofd->ofd_atime_diff);
170 * Change number of seconds to delay atime
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
177 * \retval \a count on success
178 * \retval negative number on error
180 static ssize_t atime_diff_store(struct kobject *kobj, struct attribute *attr,
181 const char *buffer, size_t count)
183 struct obd_device *obd = container_of(kobj, struct obd_device,
185 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
189 rc = kstrtouint(buffer, 0, &val);
196 ofd->ofd_atime_diff = val;
199 LUSTRE_RW_ATTR(atime_diff);
202 * Show the last used ID for each FID sequence used by OFD.
204 * \param[in] m seq_file handle
205 * \param[in] data unused for single entry
207 * \retval 0 on success
208 * \retval negative value on error
210 static int ofd_last_id_seq_show(struct seq_file *m, void *data)
212 struct obd_device *obd = m->private;
213 struct ofd_device *ofd;
214 struct ofd_seq *oseq = NULL;
219 ofd = ofd_dev(obd->obd_lu_dev);
221 read_lock(&ofd->ofd_seq_list_lock);
222 list_for_each_entry(oseq, &ofd->ofd_seq_list, os_list) {
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));
231 read_unlock(&ofd->ofd_seq_list_lock);
235 LPROC_SEQ_FOPS_RO(ofd_last_id);
238 * Show if the OFD is in degraded mode.
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.
246 * \retval count of bytes written
248 static ssize_t degraded_show(struct kobject *kobj, struct attribute *attr,
251 struct obd_device *obd = container_of(kobj, struct obd_device,
253 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
255 return sprintf(buf, "%u\n", ofd->ofd_raid_degraded);
259 * Set OFD to degraded mode.
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.
265 * \param[in] count \a buffer length
266 * \param[in] off unused for single entry
268 * \retval \a count on success
269 * \retval negative number on error
271 static ssize_t degraded_store(struct kobject *kobj, struct attribute *attr,
272 const char *buffer, size_t count)
274 struct obd_device *obd = container_of(kobj, struct obd_device,
276 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
280 rc = kstrtobool(buffer, &val);
284 spin_lock(&ofd->ofd_flags_lock);
285 ofd->ofd_raid_degraded = val;
286 spin_unlock(&ofd->ofd_flags_lock);
289 LUSTRE_RW_ATTR(degraded);
292 * Show if the OFD is in no precreate mode.
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.
298 * \retval number of bytes written
300 static ssize_t no_precreate_show(struct kobject *kobj, struct attribute *attr,
303 struct obd_device *obd = container_of(kobj, struct obd_device,
305 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
307 return scnprintf(buf, PAGE_SIZE, "%u\n", ofd->ofd_no_precreate);
311 * Set OFD to no precreate mode.
313 * This is used to interface to userspace administrative tools to
314 * disable new object creation on the OST.
316 * \param[in] count \a buffer length
318 * \retval \a count on success
319 * \retval negative number on error
321 static ssize_t no_precreate_store(struct kobject *kobj, struct attribute *attr,
322 const char *buffer, size_t count)
324 struct obd_device *obd = container_of(kobj, struct obd_device,
326 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
330 rc = kstrtobool(buffer, &val);
334 spin_lock(&ofd->ofd_flags_lock);
335 ofd->ofd_no_precreate = val;
336 spin_unlock(&ofd->ofd_flags_lock);
340 LUSTRE_RW_ATTR(no_precreate);
343 * Show OFD filesystem type.
345 * \param[in] m seq_file handle
346 * \param[in] data unused for single entry
348 * \retval 0 on success
349 * \retval negative value on error
351 static ssize_t fstype_show(struct kobject *kobj, struct attribute *attr,
354 struct obd_device *obd = container_of(kobj, struct obd_device,
356 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
359 LASSERT(ofd->ofd_osd);
360 d = &ofd->ofd_osd->dd_lu_dev;
362 return sprintf(buf, "%s\n", d->ld_type->ldt_name);
364 LUSTRE_RO_ATTR(fstype);
367 * Show journal handling mode: synchronous or asynchronous.
369 * When running in asynchronous mode the journal transactions are not
370 * committed to disk before the RPC is replied back to the client.
371 * This will typically improve client performance when only a small number
372 * of clients are writing, since the client(s) can have more write RPCs
373 * in flight. However, it also means that the client has to handle recovery
374 * on bulk RPCs, and will have to keep more dirty pages in cache before they
375 * are committed on the OST.
377 * \param[in] m seq_file handle
378 * \param[in] data unused for single entry
380 * \retval 0 on success
381 * \retval negative value on error
383 static ssize_t sync_journal_show(struct kobject *kobj, struct attribute *attr,
386 struct obd_device *obd = container_of(kobj, struct obd_device,
388 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
390 return sprintf(buf, "%u\n", ofd->ofd_sync_journal);
394 * Set journal mode to synchronous or asynchronous.
396 * \param[in] file proc file
397 * \param[in] buffer string which represents mode
398 * 1: synchronous mode
399 * 0: asynchronous mode
400 * \param[in] count \a buffer length
401 * \param[in] off unused for single entry
403 * \retval \a count on success
404 * \retval negative number on error
406 static ssize_t sync_journal_store(struct kobject *kobj, struct attribute *attr,
407 const char *buffer, size_t count)
409 struct obd_device *obd = container_of(kobj, struct obd_device,
411 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
415 rc = kstrtobool(buffer, &val);
419 spin_lock(&ofd->ofd_flags_lock);
420 ofd->ofd_sync_journal = val;
422 spin_unlock(&ofd->ofd_flags_lock);
426 LUSTRE_RW_ATTR(sync_journal);
428 static int ofd_brw_size_seq_show(struct seq_file *m, void *data)
430 struct obd_device *obd = m->private;
431 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
433 seq_printf(m, "%u\n", ofd->ofd_brw_size / ONE_MB_BRW_SIZE);
438 ofd_brw_size_seq_write(struct file *file, const char __user *buffer,
439 size_t count, loff_t *off)
441 struct seq_file *m = file->private_data;
442 struct obd_device *obd = m->private;
443 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
444 char kernbuf[22] = "";
448 if (count >= sizeof(kernbuf))
451 if (copy_from_user(kernbuf, buffer, count))
455 rc = sysfs_memparse(kernbuf, count, &val, "MiB");
462 if (val > DT_MAX_BRW_SIZE ||
463 val < (1 << ofd->ofd_lut.lut_tgd.tgd_blockbits))
466 spin_lock(&ofd->ofd_flags_lock);
467 ofd->ofd_brw_size = val;
468 spin_unlock(&ofd->ofd_flags_lock);
472 LPROC_SEQ_FOPS(ofd_brw_size);
475 * ofd_checksum_type(server) proc handling
479 static int ofd_checksum_type_seq_show(struct seq_file *m, void *data)
481 struct obd_device *obd = m->private;
482 struct lu_target *lut;
483 enum cksum_types pref;
489 lut = obd->u.obt.obt_lut;
491 /* select fastest checksum type on the server */
492 pref = obd_cksum_type_select(obd->obd_name,
493 lut->lut_cksum_types_supported, 0);
495 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
496 if ((BIT(i) & lut->lut_cksum_types_supported) == 0)
500 seq_printf(m, "[%s] ", cksum_name[i]);
502 seq_printf(m, "%s ", cksum_name[i]);
509 LPROC_SEQ_FOPS_RO(ofd_checksum_type);
512 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 16, 53, 0)
513 static bool sync_on_lock_cancel_warned;
514 static ssize_t sync_on_lock_cancel_show(struct kobject *kobj,
515 struct attribute *attr, char *buf)
517 if (!sync_on_lock_cancel_warned) {
518 sync_on_lock_cancel_warned = true;
519 pr_info("ofd: 'obdfilter.*.sync_on_lock_cancel' is deprecated, use 'obdfilter.*.sync_lock_cancel' instead\n");
521 return sync_lock_cancel_show(kobj, attr, buf);
524 static ssize_t sync_on_lock_cancel_store(struct kobject *kobj,
525 struct attribute *attr,
526 const char *buffer, size_t count)
528 if (!sync_on_lock_cancel_warned) {
529 sync_on_lock_cancel_warned = true;
530 pr_info("ofd: 'obdfilter.*.sync_on_lock_cancel' is deprecated, use 'obdfilter.*.sync_lock_cancel' instead\n");
532 return sync_lock_cancel_store(kobj, attr, buffer, count);
534 LUSTRE_RW_ATTR(sync_on_lock_cancel);
538 * Show the limit of soft sync RPCs.
540 * This value defines how many IO RPCs with OBD_BRW_SOFT_SYNC flag
541 * are allowed before sync update will be triggered.
543 * \param[in] m seq_file handle
544 * \param[in] data unused for single entry
546 * \retval 0 on success
547 * \retval negative value on error
549 static ssize_t soft_sync_limit_show(struct kobject *kobj,
550 struct attribute *attr, char *buf)
552 struct obd_device *obd = container_of(kobj, struct obd_device,
554 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
556 return sprintf(buf, "%u\n", ofd->ofd_soft_sync_limit);
560 * Change the limit of soft sync RPCs.
562 * Define how many IO RPCs with OBD_BRW_SOFT_SYNC flag
563 * allowed before sync update will be done.
565 * This limit is global across all exports.
567 * \param[in] file proc file
568 * \param[in] buffer string which represents limit
569 * \param[in] count \a buffer length
570 * \param[in] off unused for single entry
572 * \retval \a count on success
573 * \retval negative number on error
575 static ssize_t soft_sync_limit_store(struct kobject *kobj,
576 struct attribute *attr,
577 const char *buffer, size_t count)
579 struct obd_device *obd = container_of(kobj, struct obd_device,
581 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
585 rc = kstrtouint(buffer, 0, &val);
589 ofd->ofd_soft_sync_limit = val;
592 LUSTRE_RW_ATTR(soft_sync_limit);
595 * Show the LFSCK speed limit.
597 * The maximum number of items scanned per second.
599 * \param[in] m seq_file handle
600 * \param[in] data unused for single entry
602 * \retval 0 on success
603 * \retval negative value on error
605 static ssize_t lfsck_speed_limit_show(struct kobject *kobj,
606 struct attribute *attr, char *buf)
608 struct obd_device *obd = container_of(kobj, struct obd_device,
610 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
612 return lfsck_get_speed(buf, ofd->ofd_osd);
616 * Change the LFSCK speed limit.
618 * Limit number of items that may be scanned per second.
620 * \param[in] file proc file
621 * \param[in] buffer string which represents limit
622 * \param[in] count \a buffer length
623 * \param[in] off unused for single entry
625 * \retval \a count on success
626 * \retval negative number on error
628 static ssize_t lfsck_speed_limit_store(struct kobject *kobj,
629 struct attribute *attr,
630 const char *buffer, size_t count)
632 struct obd_device *obd = container_of(kobj, struct obd_device,
634 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
638 rc = kstrtouint(buffer, 0, &val);
642 rc = lfsck_set_speed(ofd->ofd_osd, val);
644 return rc != 0 ? rc : count;
646 LUSTRE_RW_ATTR(lfsck_speed_limit);
649 * Show LFSCK layout verification stats from the most recent LFSCK run.
651 * \param[in] m seq_file handle
652 * \param[in] data unused for single entry
654 * \retval 0 on success
655 * \retval negative value on error
657 static int ofd_lfsck_layout_seq_show(struct seq_file *m, void *data)
659 struct obd_device *obd = m->private;
660 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
662 return lfsck_dump(m, ofd->ofd_osd, LFSCK_TYPE_LAYOUT);
665 LPROC_SEQ_FOPS_RO(ofd_lfsck_layout);
668 * Show if LFSCK performed parent FID verification.
670 * \param[in] m seq_file handle
671 * \param[in] data unused for single entry
673 * \retval 0 on success
674 * \retval negative value on error
676 static int ofd_lfsck_verify_pfid_seq_show(struct seq_file *m, void *data)
678 struct obd_device *obd = m->private;
679 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
681 seq_printf(m, "switch: %s\ndetected: %llu\nrepaired: %llu\n",
682 ofd->ofd_lfsck_verify_pfid ? "on" : "off",
683 ofd->ofd_inconsistency_self_detected,
684 ofd->ofd_inconsistency_self_repaired);
689 * Set the LFSCK behavior to verify parent FID correctness.
691 * If flag ofd_lfsck_verify_pfid is set then LFSCK does parent FID
692 * verification during read/write operations.
694 * \param[in] file proc file
695 * \param[in] buffer string which represents behavior
696 * 1: verify parent FID
697 * 0: don't verify parent FID
698 * \param[in] count \a buffer length
699 * \param[in] off unused for single entry
701 * \retval \a count on success
702 * \retval negative number on error
705 ofd_lfsck_verify_pfid_seq_write(struct file *file, const char __user *buffer,
706 size_t count, loff_t *off)
708 struct seq_file *m = file->private_data;
709 struct obd_device *obd = m->private;
710 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
714 rc = kstrtobool_from_user(buffer, count, &val);
718 ofd->ofd_lfsck_verify_pfid = val;
719 if (!ofd->ofd_lfsck_verify_pfid) {
720 ofd->ofd_inconsistency_self_detected = 0;
721 ofd->ofd_inconsistency_self_repaired = 0;
727 LPROC_SEQ_FOPS(ofd_lfsck_verify_pfid);
729 static ssize_t access_log_mask_show(struct kobject *kobj,
730 struct attribute *attr, char *buf)
732 struct obd_device *obd = container_of(kobj, struct obd_device,
734 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
736 return scnprintf(buf, PAGE_SIZE, "%s%s%s\n",
737 (ofd->ofd_access_log_mask == 0) ? "0" : "",
738 (ofd->ofd_access_log_mask & OFD_ACCESS_READ) ? "r" : "",
739 (ofd->ofd_access_log_mask & OFD_ACCESS_WRITE) ? "w" : "");
742 static ssize_t access_log_mask_store(struct kobject *kobj,
743 struct attribute *attr,
744 const char *buffer, size_t count)
746 struct obd_device *obd = container_of(kobj, struct obd_device,
748 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
749 unsigned int mask = 0;
752 for (i = 0; i < count; i++) {
753 switch (tolower(buffer[i])) {
757 mask |= OFD_ACCESS_READ;
760 mask |= OFD_ACCESS_WRITE;
767 ofd->ofd_access_log_mask = mask;
771 LUSTRE_RW_ATTR(access_log_mask);
773 static ssize_t access_log_size_show(struct kobject *kobj,
774 struct attribute *attr, char *buf)
776 struct obd_device *obd = container_of(kobj, struct obd_device,
778 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
780 return scnprintf(buf, PAGE_SIZE, "%u\n", ofd->ofd_access_log_size);
783 static ssize_t access_log_size_store(struct kobject *kobj,
784 struct attribute *attr,
785 const char *buffer, size_t count)
787 struct obd_device *obd = container_of(kobj, struct obd_device,
789 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
790 struct ofd_access_log *oal;
794 rc = kstrtouint(buffer, 0, &size);
798 if (!ofd_access_log_size_is_valid(size))
801 /* The size of the ofd_access_log cannot be changed after it
804 if (ofd->ofd_access_log_size == size)
807 oal = ofd_access_log_create(obd->obd_name, size);
811 spin_lock(&ofd->ofd_flags_lock);
812 if (ofd->ofd_access_log != NULL) {
815 ofd->ofd_access_log = oal;
816 ofd->ofd_access_log_size = size;
820 spin_unlock(&ofd->ofd_flags_lock);
822 ofd_access_log_delete(oal);
826 LUSTRE_RW_ATTR(access_log_size);
828 static int ofd_site_stats_seq_show(struct seq_file *m, void *data)
830 struct obd_device *obd = m->private;
832 return lu_site_stats_seq_print(obd->obd_lu_dev->ld_site, m);
835 LPROC_SEQ_FOPS_RO(ofd_site_stats);
838 * Show if the OFD enforces T10PI checksum.
840 * \param[in] m seq_file handle
841 * \param[in] data unused for single entry
843 * \retval 0 on success
844 * \retval negative value on error
846 static ssize_t checksum_t10pi_enforce_show(struct kobject *kobj,
847 struct attribute *attr,
850 struct obd_device *obd = container_of(kobj, struct obd_device,
852 struct lu_target *lut = obd->u.obt.obt_lut;
854 return scnprintf(buf, PAGE_SIZE, "%u\n", lut->lut_cksum_t10pi_enforce);
858 * Force specific T10PI checksum modes to be enabled
860 * If T10PI *is* supported in hardware, allow only the supported T10PI type
861 * to be used. If T10PI is *not* supported by the OSD, setting the enforce
862 * parameter forces all T10PI types to be enabled (even if slower) for
865 * The final determination of which algorithm to be used depends whether
866 * the client supports T10PI or not, and is handled at client connect time.
868 * \param[in] file proc file
869 * \param[in] buffer string which represents mode
870 * 1: set T10PI checksums enforced
871 * 0: unset T10PI checksums enforced
872 * \param[in] count \a buffer length
873 * \param[in] off unused for single entry
875 * \retval \a count on success
876 * \retval negative number on error
878 static ssize_t checksum_t10pi_enforce_store(struct kobject *kobj,
879 struct attribute *attr,
880 const char *buffer, size_t count)
882 struct obd_device *obd = container_of(kobj, struct obd_device,
884 struct lu_target *lut = obd->u.obt.obt_lut;
888 rc = kstrtobool(buffer, &enforce);
892 spin_lock(&lut->lut_flags_lock);
893 lut->lut_cksum_t10pi_enforce = enforce;
894 spin_unlock(&lut->lut_flags_lock);
897 LUSTRE_RW_ATTR(checksum_t10pi_enforce);
899 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 14, 53, 0)
900 static bool max_file_warned;
901 static bool rd_cache_warned;
902 static bool wr_cache_warned;
904 static ssize_t read_cache_enable_show(struct kobject *kobj,
905 struct attribute *attr,
908 struct obd_device *obd = container_of(kobj, struct obd_device,
910 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
912 if (!rd_cache_warned) {
913 rd_cache_warned = true;
914 pr_info("ofd: 'obdfilter.*.read_cache_enabled' is deprecated, use 'osd-*.read_cache_enabled' instead\n");
917 if (!ofd->ofd_read_cache_enable)
920 return lustre_attr_show(&ofd->ofd_osd->dd_kobj,
921 ofd->ofd_read_cache_enable, buf);
924 static ssize_t read_cache_enable_store(struct kobject *kobj,
925 struct attribute *attr,
926 const char *buffer, size_t count)
928 struct obd_device *obd = container_of(kobj, struct obd_device,
930 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
932 if (!rd_cache_warned) {
933 rd_cache_warned = true;
934 pr_info("ofd: 'obdfilter.*.read_cache_enabled' is deprecated, use 'osd-*.read_cache_enabled' instead\n");
937 if (!ofd->ofd_read_cache_enable)
940 return lustre_attr_store(&ofd->ofd_osd->dd_kobj,
941 ofd->ofd_read_cache_enable, buffer, count);
943 LUSTRE_RW_ATTR(read_cache_enable);
945 static ssize_t readcache_max_filesize_show(struct kobject *kobj,
946 struct attribute *attr,
949 struct obd_device *obd = container_of(kobj, struct obd_device,
951 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
953 if (!max_file_warned) {
954 max_file_warned = true;
955 pr_info("ofd: 'obdfilter.*.readcache_max_filesize' is deprecated, use 'osd-*.readcache_max_filesize' instead\n");
958 if (!ofd->ofd_read_cache_max_filesize)
961 return lustre_attr_show(&ofd->ofd_osd->dd_kobj,
962 ofd->ofd_read_cache_max_filesize, buf);
965 static ssize_t readcache_max_filesize_store(struct kobject *kobj,
966 struct attribute *attr,
967 const char *buffer, size_t count)
969 struct obd_device *obd = container_of(kobj, struct obd_device,
971 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
973 if (!max_file_warned) {
974 max_file_warned = true;
975 pr_info("ofd: 'obdfilter.*.readcache_max_filesize' is deprecated, use 'osd-*.readcache_max_filesize' instead\n");
978 if (!ofd->ofd_read_cache_max_filesize)
981 return lustre_attr_store(&ofd->ofd_osd->dd_kobj,
982 ofd->ofd_read_cache_max_filesize,
985 LUSTRE_RW_ATTR(readcache_max_filesize);
987 static ssize_t writethrough_cache_enable_show(struct kobject *kobj,
988 struct attribute *attr,
991 struct obd_device *obd = container_of(kobj, struct obd_device,
993 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
995 if (!wr_cache_warned) {
996 wr_cache_warned = true;
997 pr_info("ofd: 'obdfilter.*.writethrough_cache_enabled' is deprecated, use 'osd-*.writethrough_cache_enabled' instead\n");
1000 if (!ofd->ofd_write_cache_enable)
1003 return lustre_attr_show(&ofd->ofd_osd->dd_kobj,
1004 ofd->ofd_write_cache_enable, buf);
1007 static ssize_t writethrough_cache_enable_store(struct kobject *kobj,
1008 struct attribute *attr,
1009 const char *buffer, size_t count)
1011 struct obd_device *obd = container_of(kobj, struct obd_device,
1013 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
1015 if (!ofd->ofd_write_cache_enable)
1018 return lustre_attr_store(&ofd->ofd_osd->dd_kobj,
1019 ofd->ofd_write_cache_enable,
1022 LUSTRE_RW_ATTR(writethrough_cache_enable);
1025 LPROC_SEQ_FOPS_RO_TYPE(ofd, recovery_status);
1026 LUSTRE_RW_ATTR(recovery_time_hard);
1027 LUSTRE_RW_ATTR(recovery_time_soft);
1028 LUSTRE_RW_ATTR(ir_factor);
1030 LPROC_SEQ_FOPS_WR_ONLY(ofd, evict_client);
1031 LPROC_SEQ_FOPS_RW_TYPE(ofd, checksum_dump);
1032 LUSTRE_RW_ATTR(job_cleanup_interval);
1034 LUSTRE_RO_ATTR(tot_dirty);
1035 LUSTRE_RO_ATTR(tot_granted);
1036 LUSTRE_RO_ATTR(tot_pending);
1037 LUSTRE_RW_ATTR(grant_compat_disable);
1038 LUSTRE_RW_ATTR(lbug_on_grant_miscount);
1039 LUSTRE_RO_ATTR(instance);
1041 LUSTRE_RO_ATTR(num_exports);
1043 struct lprocfs_vars lprocfs_ofd_obd_vars[] = {
1044 { .name = "last_id",
1045 .fops = &ofd_last_id_fops },
1046 { .name = "recovery_status",
1047 .fops = &ofd_recovery_status_fops },
1048 { .name = "evict_client",
1049 .fops = &ofd_evict_client_fops },
1050 { .name = "brw_size",
1051 .fops = &ofd_brw_size_fops },
1052 { .name = "checksum_dump",
1053 .fops = &ofd_checksum_dump_fops },
1054 { .name = "lfsck_layout",
1055 .fops = &ofd_lfsck_layout_fops },
1056 { .name = "lfsck_verify_pfid",
1057 .fops = &ofd_lfsck_verify_pfid_fops },
1058 { .name = "site_stats",
1059 .fops = &ofd_site_stats_fops },
1060 { .name = "checksum_type",
1061 .fops = &ofd_checksum_type_fops },
1066 * Initialize OFD statistics counters
1068 * param[in] stats statistics counters
1070 void ofd_stats_counter_init(struct lprocfs_stats *stats, unsigned int offset)
1072 LASSERT(stats && stats->ls_num >= LPROC_OFD_STATS_LAST);
1074 lprocfs_counter_init(stats, LPROC_OFD_STATS_READ_BYTES,
1075 LPROCFS_TYPE_BYTES_FULL, "read_bytes", "bytes");
1076 lprocfs_counter_init(stats, LPROC_OFD_STATS_WRITE_BYTES,
1077 LPROCFS_TYPE_BYTES_FULL, "write_bytes", "bytes");
1078 lprocfs_counter_init(stats, LPROC_OFD_STATS_READ,
1079 LPROCFS_TYPE_LATENCY, "read", "usecs");
1080 lprocfs_counter_init(stats, LPROC_OFD_STATS_WRITE,
1081 LPROCFS_TYPE_LATENCY, "write", "usecs");
1082 lprocfs_counter_init(stats, LPROC_OFD_STATS_GETATTR,
1083 LPROCFS_TYPE_LATENCY, "getattr", "usecs");
1084 lprocfs_counter_init(stats, LPROC_OFD_STATS_SETATTR,
1085 LPROCFS_TYPE_LATENCY, "setattr", "usecs");
1086 lprocfs_counter_init(stats, LPROC_OFD_STATS_PUNCH,
1087 LPROCFS_TYPE_LATENCY, "punch", "usecs");
1088 lprocfs_counter_init(stats, LPROC_OFD_STATS_SYNC,
1089 LPROCFS_TYPE_LATENCY, "sync", "usecs");
1090 lprocfs_counter_init(stats, LPROC_OFD_STATS_DESTROY,
1091 LPROCFS_TYPE_LATENCY, "destroy", "usecs");
1092 lprocfs_counter_init(stats, LPROC_OFD_STATS_CREATE,
1093 LPROCFS_TYPE_LATENCY, "create", "usecs");
1094 lprocfs_counter_init(stats, LPROC_OFD_STATS_STATFS,
1095 LPROCFS_TYPE_LATENCY, "statfs", "usecs");
1096 lprocfs_counter_init(stats, LPROC_OFD_STATS_GET_INFO,
1097 LPROCFS_TYPE_LATENCY, "get_info", "usecs");
1098 lprocfs_counter_init(stats, LPROC_OFD_STATS_SET_INFO,
1099 LPROCFS_TYPE_LATENCY, "set_info", "usecs");
1100 lprocfs_counter_init(stats, LPROC_OFD_STATS_QUOTACTL,
1101 LPROCFS_TYPE_LATENCY, "quotactl", "usecs");
1102 lprocfs_counter_init(stats, LPROC_OFD_STATS_PREALLOC,
1103 LPROCFS_TYPE_LATENCY, "prealloc", "usecs");
1106 LPROC_SEQ_FOPS(lprocfs_nid_stats_clear);
1108 static struct attribute *ofd_attrs[] = {
1109 &lustre_attr_tot_dirty.attr,
1110 &lustre_attr_tot_granted.attr,
1111 &lustre_attr_tot_pending.attr,
1112 &lustre_attr_grant_compat_disable.attr,
1113 &lustre_attr_lbug_on_grant_miscount.attr,
1114 &lustre_attr_instance.attr,
1115 &lustre_attr_recovery_time_hard.attr,
1116 &lustre_attr_recovery_time_soft.attr,
1117 &lustre_attr_ir_factor.attr,
1118 &lustre_attr_num_exports.attr,
1119 &lustre_attr_seqs_allocated.attr,
1120 &lustre_attr_grant_precreate.attr,
1121 &lustre_attr_precreate_batch.attr,
1122 &lustre_attr_atime_diff.attr,
1123 &lustre_attr_degraded.attr,
1124 &lustre_attr_fstype.attr,
1125 &lustre_attr_no_precreate.attr,
1126 &lustre_attr_sync_journal.attr,
1127 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 16, 53, 0)
1128 &lustre_attr_sync_on_lock_cancel.attr,
1130 &lustre_attr_soft_sync_limit.attr,
1131 &lustre_attr_lfsck_speed_limit.attr,
1132 &lustre_attr_access_log_mask.attr,
1133 &lustre_attr_access_log_size.attr,
1134 &lustre_attr_job_cleanup_interval.attr,
1135 &lustre_attr_checksum_t10pi_enforce.attr,
1136 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 14, 53, 0)
1137 &lustre_attr_read_cache_enable.attr,
1138 &lustre_attr_readcache_max_filesize.attr,
1139 &lustre_attr_writethrough_cache_enable.attr,
1145 * Initialize all needed procfs entries for OFD device.
1147 * \param[in] ofd OFD device
1149 * \retval 0 if successful
1150 * \retval negative value on error
1152 int ofd_tunables_init(struct ofd_device *ofd)
1154 struct obd_device *obd = ofd_obd(ofd);
1155 struct proc_dir_entry *entry;
1159 /* lprocfs must be setup before the ofd so state can be safely added
1160 * to /proc incrementally as the ofd is setup
1162 obd->obd_ktype.default_attrs = ofd_attrs;
1163 obd->obd_vars = lprocfs_ofd_obd_vars;
1164 rc = lprocfs_obd_setup(obd, false);
1166 CERROR("%s: lprocfs_obd_setup failed: %d.\n",
1171 rc = tgt_tunables_init(&ofd->ofd_lut);
1173 CERROR("%s: tgt_tunables_init failed: rc = %d\n",
1175 GOTO(obd_cleanup, rc);
1178 rc = lprocfs_alloc_obd_stats(obd, LPROC_OFD_STATS_LAST);
1180 CERROR("%s: lprocfs_alloc_obd_stats failed: %d.\n",
1182 GOTO(tgt_cleanup, rc);
1185 entry = lprocfs_register("exports", obd->obd_proc_entry, NULL, NULL);
1186 if (IS_ERR(entry)) {
1187 rc = PTR_ERR(entry);
1188 CERROR("%s: error %d setting up lprocfs for %s\n",
1189 obd->obd_name, rc, "exports");
1190 GOTO(obd_free_stats, rc);
1192 obd->obd_proc_exports_entry = entry;
1194 entry = lprocfs_add_simple(obd->obd_proc_exports_entry, "clear",
1195 obd, &lprocfs_nid_stats_clear_fops);
1196 if (IS_ERR(entry)) {
1197 rc = PTR_ERR(entry);
1198 CERROR("%s: add proc entry 'clear' failed: %d.\n",
1200 GOTO(obd_free_stats, rc);
1203 ofd_stats_counter_init(obd->obd_stats, 0);
1205 rc = lprocfs_job_stats_init(obd, LPROC_OFD_STATS_LAST,
1206 ofd_stats_counter_init);
1208 GOTO(obd_free_stats, rc);
1213 lprocfs_free_obd_stats(obd);
1215 tgt_tunables_fini(&ofd->ofd_lut);
1217 lprocfs_obd_cleanup(obd);
1221 #endif /* CONFIG_PROC_FS */