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>
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 number of seconds to delay atime
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 ssize_t atime_diff_show(struct kobject *kobj, struct attribute *attr,
161 struct obd_device *obd = container_of(kobj, struct obd_device,
163 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
165 return scnprintf(buf, PAGE_SIZE, "%lld\n", ofd->ofd_atime_diff);
169 * Change number of seconds to delay atime
171 * \param[in] file proc file
172 * \param[in] buffer string which represents maximum number
173 * \param[in] count \a buffer length
174 * \param[in] off unused for single entry
176 * \retval \a count on success
177 * \retval negative number on error
179 static ssize_t atime_diff_store(struct kobject *kobj, struct attribute *attr,
180 const char *buffer, size_t count)
182 struct obd_device *obd = container_of(kobj, struct obd_device,
184 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
188 rc = kstrtouint(buffer, 0, &val);
195 ofd->ofd_atime_diff = val;
198 LUSTRE_RW_ATTR(atime_diff);
201 * Show the last used ID for each FID sequence used by OFD.
203 * \param[in] m seq_file handle
204 * \param[in] data unused for single entry
206 * \retval 0 on success
207 * \retval negative value on error
209 static int ofd_last_id_seq_show(struct seq_file *m, void *data)
211 struct obd_device *obd = m->private;
212 struct ofd_device *ofd;
213 struct ofd_seq *oseq = NULL;
218 ofd = ofd_dev(obd->obd_lu_dev);
220 read_lock(&ofd->ofd_seq_list_lock);
221 list_for_each_entry(oseq, &ofd->ofd_seq_list, os_list) {
224 seq = ostid_seq(&oseq->os_oi) == 0 ?
225 fid_idif_seq(ostid_id(&oseq->os_oi),
226 ofd->ofd_lut.lut_lsd.lsd_osd_index) & ~0xFFFF :
227 ostid_seq(&oseq->os_oi);
228 seq_printf(m, DOSTID"\n", seq, ostid_id(&oseq->os_oi));
230 read_unlock(&ofd->ofd_seq_list_lock);
234 LPROC_SEQ_FOPS_RO(ofd_last_id);
237 * Show if the OFD is in degraded mode.
239 * Degraded means OFD has a failed drive or is undergoing RAID rebuild.
240 * The MDS will try to avoid using this OST for new object allocations
241 * to reduce the impact to global IO performance when clients writing to
242 * this OST are slowed down. It also reduces the contention on the OST
243 * RAID device, allowing it to rebuild more quickly.
245 * \retval count of bytes written
247 static ssize_t degraded_show(struct kobject *kobj, struct attribute *attr,
250 struct obd_device *obd = container_of(kobj, struct obd_device,
252 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
254 return sprintf(buf, "%u\n", ofd->ofd_raid_degraded);
258 * Set OFD to degraded mode.
260 * This is used to interface to userspace administrative tools for
261 * the underlying RAID storage, so that they can mark an OST
262 * as having degraded performance.
264 * \param[in] count \a buffer length
265 * \param[in] off unused for single entry
267 * \retval \a count on success
268 * \retval negative number on error
270 static ssize_t degraded_store(struct kobject *kobj, struct attribute *attr,
271 const char *buffer, size_t count)
273 struct obd_device *obd = container_of(kobj, struct obd_device,
275 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
279 rc = kstrtobool(buffer, &val);
283 spin_lock(&ofd->ofd_flags_lock);
284 ofd->ofd_raid_degraded = val;
285 spin_unlock(&ofd->ofd_flags_lock);
288 LUSTRE_RW_ATTR(degraded);
291 * Show if the OFD is in no precreate mode.
293 * This means OFD has been adminstratively disabled at the OST to prevent
294 * the MDS from creating any new files on the OST, though existing files
295 * can still be read, written, and unlinked.
297 * \retval number of bytes written
299 static ssize_t no_precreate_show(struct kobject *kobj, struct attribute *attr,
302 struct obd_device *obd = container_of(kobj, struct obd_device,
304 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
306 return scnprintf(buf, PAGE_SIZE, "%u\n", ofd->ofd_no_precreate);
310 * Set OFD to no precreate mode.
312 * This is used to interface to userspace administrative tools to
313 * disable new object creation on the OST.
315 * \param[in] count \a buffer length
317 * \retval \a count on success
318 * \retval negative number on error
320 static ssize_t no_precreate_store(struct kobject *kobj, struct attribute *attr,
321 const char *buffer, size_t count)
323 struct obd_device *obd = container_of(kobj, struct obd_device,
325 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
329 rc = kstrtobool(buffer, &val);
333 spin_lock(&ofd->ofd_flags_lock);
334 ofd->ofd_no_precreate = val;
335 spin_unlock(&ofd->ofd_flags_lock);
339 LUSTRE_RW_ATTR(no_precreate);
342 * Show OFD filesystem type.
344 * \param[in] m seq_file handle
345 * \param[in] data unused for single entry
347 * \retval 0 on success
348 * \retval negative value on error
350 static ssize_t fstype_show(struct kobject *kobj, struct attribute *attr,
353 struct obd_device *obd = container_of(kobj, struct obd_device,
355 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
358 LASSERT(ofd->ofd_osd);
359 d = &ofd->ofd_osd->dd_lu_dev;
361 return sprintf(buf, "%s\n", d->ld_type->ldt_name);
363 LUSTRE_RO_ATTR(fstype);
366 * Show journal handling mode: synchronous or asynchronous.
368 * When running in asynchronous mode the journal transactions are not
369 * committed to disk before the RPC is replied back to the client.
370 * This will typically improve client performance when only a small number
371 * of clients are writing, since the client(s) can have more write RPCs
372 * in flight. However, it also means that the client has to handle recovery
373 * on bulk RPCs, and will have to keep more dirty pages in cache before they
374 * are committed on the OST.
376 * \param[in] m seq_file handle
377 * \param[in] data unused for single entry
379 * \retval 0 on success
380 * \retval negative value on error
382 static ssize_t sync_journal_show(struct kobject *kobj, struct attribute *attr,
385 struct obd_device *obd = container_of(kobj, struct obd_device,
387 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
389 return sprintf(buf, "%u\n", ofd->ofd_sync_journal);
393 * Set journal mode to synchronous or asynchronous.
395 * \param[in] file proc file
396 * \param[in] buffer string which represents mode
397 * 1: synchronous mode
398 * 0: asynchronous mode
399 * \param[in] count \a buffer length
400 * \param[in] off unused for single entry
402 * \retval \a count on success
403 * \retval negative number on error
405 static ssize_t sync_journal_store(struct kobject *kobj, struct attribute *attr,
406 const char *buffer, size_t count)
408 struct obd_device *obd = container_of(kobj, struct obd_device,
410 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
414 rc = kstrtobool(buffer, &val);
418 spin_lock(&ofd->ofd_flags_lock);
419 ofd->ofd_sync_journal = val;
421 spin_unlock(&ofd->ofd_flags_lock);
425 LUSTRE_RW_ATTR(sync_journal);
427 static int ofd_brw_size_seq_show(struct seq_file *m, void *data)
429 struct obd_device *obd = m->private;
430 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
432 seq_printf(m, "%u\n", ofd->ofd_brw_size / ONE_MB_BRW_SIZE);
437 ofd_brw_size_seq_write(struct file *file, const char __user *buffer,
438 size_t count, loff_t *off)
440 struct seq_file *m = file->private_data;
441 struct obd_device *obd = m->private;
442 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
443 char kernbuf[22] = "";
447 if (count >= sizeof(kernbuf))
450 if (copy_from_user(kernbuf, buffer, count))
454 rc = sysfs_memparse(kernbuf, count, &val, "MiB");
461 if (val > DT_MAX_BRW_SIZE ||
462 val < (1 << ofd->ofd_lut.lut_tgd.tgd_blockbits))
465 spin_lock(&ofd->ofd_flags_lock);
466 ofd->ofd_brw_size = val;
467 spin_unlock(&ofd->ofd_flags_lock);
471 LPROC_SEQ_FOPS(ofd_brw_size);
473 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 16, 53, 0)
474 static bool sync_on_lock_cancel_warned;
475 static ssize_t sync_on_lock_cancel_show(struct kobject *kobj,
476 struct attribute *attr, char *buf)
478 if (!sync_on_lock_cancel_warned) {
479 sync_on_lock_cancel_warned = true;
480 pr_info("ofd: 'obdfilter.*.sync_on_lock_cancel' is deprecated, use 'obdfilter.*.sync_lock_cancel' instead\n");
482 return sync_lock_cancel_show(kobj, attr, buf);
485 static ssize_t sync_on_lock_cancel_store(struct kobject *kobj,
486 struct attribute *attr,
487 const char *buffer, size_t count)
489 if (!sync_on_lock_cancel_warned) {
490 sync_on_lock_cancel_warned = true;
491 pr_info("ofd: 'obdfilter.*.sync_on_lock_cancel' is deprecated, use 'obdfilter.*.sync_lock_cancel' instead\n");
493 return sync_lock_cancel_store(kobj, attr, buffer, count);
495 LUSTRE_RW_ATTR(sync_on_lock_cancel);
499 * Show the limit of soft sync RPCs.
501 * This value defines how many IO RPCs with OBD_BRW_SOFT_SYNC flag
502 * are allowed before sync update will be triggered.
504 * \param[in] m seq_file handle
505 * \param[in] data unused for single entry
507 * \retval 0 on success
508 * \retval negative value on error
510 static ssize_t soft_sync_limit_show(struct kobject *kobj,
511 struct attribute *attr, char *buf)
513 struct obd_device *obd = container_of(kobj, struct obd_device,
515 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
517 return sprintf(buf, "%u\n", ofd->ofd_soft_sync_limit);
521 * Change the limit of soft sync RPCs.
523 * Define how many IO RPCs with OBD_BRW_SOFT_SYNC flag
524 * allowed before sync update will be done.
526 * This limit is global across all exports.
528 * \param[in] file proc file
529 * \param[in] buffer string which represents limit
530 * \param[in] count \a buffer length
531 * \param[in] off unused for single entry
533 * \retval \a count on success
534 * \retval negative number on error
536 static ssize_t soft_sync_limit_store(struct kobject *kobj,
537 struct attribute *attr,
538 const char *buffer, size_t count)
540 struct obd_device *obd = container_of(kobj, struct obd_device,
542 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
546 rc = kstrtouint(buffer, 0, &val);
550 ofd->ofd_soft_sync_limit = val;
553 LUSTRE_RW_ATTR(soft_sync_limit);
556 * Show the LFSCK speed limit.
558 * The maximum number of items scanned per second.
560 * \param[in] m seq_file handle
561 * \param[in] data unused for single entry
563 * \retval 0 on success
564 * \retval negative value on error
566 static ssize_t lfsck_speed_limit_show(struct kobject *kobj,
567 struct attribute *attr, char *buf)
569 struct obd_device *obd = container_of(kobj, struct obd_device,
571 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
573 return lfsck_get_speed(buf, ofd->ofd_osd);
577 * Change the LFSCK speed limit.
579 * Limit number of items that may be scanned per second.
581 * \param[in] file proc file
582 * \param[in] buffer string which represents limit
583 * \param[in] count \a buffer length
584 * \param[in] off unused for single entry
586 * \retval \a count on success
587 * \retval negative number on error
589 static ssize_t lfsck_speed_limit_store(struct kobject *kobj,
590 struct attribute *attr,
591 const char *buffer, size_t count)
593 struct obd_device *obd = container_of(kobj, struct obd_device,
595 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
599 rc = kstrtouint(buffer, 0, &val);
603 rc = lfsck_set_speed(ofd->ofd_osd, val);
605 return rc != 0 ? rc : count;
607 LUSTRE_RW_ATTR(lfsck_speed_limit);
610 * Show LFSCK layout verification stats from the most recent LFSCK run.
612 * \param[in] m seq_file handle
613 * \param[in] data unused for single entry
615 * \retval 0 on success
616 * \retval negative value on error
618 static int ofd_lfsck_layout_seq_show(struct seq_file *m, void *data)
620 struct obd_device *obd = m->private;
621 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
623 return lfsck_dump(m, ofd->ofd_osd, LFSCK_TYPE_LAYOUT);
626 LPROC_SEQ_FOPS_RO(ofd_lfsck_layout);
629 * Show if LFSCK performed parent FID verification.
631 * \param[in] m seq_file handle
632 * \param[in] data unused for single entry
634 * \retval 0 on success
635 * \retval negative value on error
637 static int ofd_lfsck_verify_pfid_seq_show(struct seq_file *m, void *data)
639 struct obd_device *obd = m->private;
640 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
642 seq_printf(m, "switch: %s\ndetected: %llu\nrepaired: %llu\n",
643 ofd->ofd_lfsck_verify_pfid ? "on" : "off",
644 ofd->ofd_inconsistency_self_detected,
645 ofd->ofd_inconsistency_self_repaired);
650 * Set the LFSCK behavior to verify parent FID correctness.
652 * If flag ofd_lfsck_verify_pfid is set then LFSCK does parent FID
653 * verification during read/write operations.
655 * \param[in] file proc file
656 * \param[in] buffer string which represents behavior
657 * 1: verify parent FID
658 * 0: don't verify parent FID
659 * \param[in] count \a buffer length
660 * \param[in] off unused for single entry
662 * \retval \a count on success
663 * \retval negative number on error
666 ofd_lfsck_verify_pfid_seq_write(struct file *file, const char __user *buffer,
667 size_t count, loff_t *off)
669 struct seq_file *m = file->private_data;
670 struct obd_device *obd = m->private;
671 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
675 rc = kstrtobool_from_user(buffer, count, &val);
679 ofd->ofd_lfsck_verify_pfid = val;
680 if (!ofd->ofd_lfsck_verify_pfid) {
681 ofd->ofd_inconsistency_self_detected = 0;
682 ofd->ofd_inconsistency_self_repaired = 0;
688 LPROC_SEQ_FOPS(ofd_lfsck_verify_pfid);
690 static ssize_t access_log_mask_show(struct kobject *kobj,
691 struct attribute *attr, char *buf)
693 struct obd_device *obd = container_of(kobj, struct obd_device,
695 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
697 return scnprintf(buf, PAGE_SIZE, "%s%s%s\n",
698 (ofd->ofd_access_log_mask == 0) ? "0" : "",
699 (ofd->ofd_access_log_mask & OFD_ACCESS_READ) ? "r" : "",
700 (ofd->ofd_access_log_mask & OFD_ACCESS_WRITE) ? "w" : "");
703 static ssize_t access_log_mask_store(struct kobject *kobj,
704 struct attribute *attr,
705 const char *buffer, size_t count)
707 struct obd_device *obd = container_of(kobj, struct obd_device,
709 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
710 unsigned int mask = 0;
713 for (i = 0; i < count; i++) {
714 switch (tolower(buffer[i])) {
718 mask |= OFD_ACCESS_READ;
721 mask |= OFD_ACCESS_WRITE;
728 ofd->ofd_access_log_mask = mask;
732 LUSTRE_RW_ATTR(access_log_mask);
734 static ssize_t access_log_size_show(struct kobject *kobj,
735 struct attribute *attr, char *buf)
737 struct obd_device *obd = container_of(kobj, struct obd_device,
739 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
741 return scnprintf(buf, PAGE_SIZE, "%u\n", ofd->ofd_access_log_size);
744 static ssize_t access_log_size_store(struct kobject *kobj,
745 struct attribute *attr,
746 const char *buffer, size_t count)
748 struct obd_device *obd = container_of(kobj, struct obd_device,
750 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
751 struct ofd_access_log *oal;
755 rc = kstrtouint(buffer, 0, &size);
759 if (!ofd_access_log_size_is_valid(size))
762 /* The size of the ofd_access_log cannot be changed after it
765 if (ofd->ofd_access_log_size == size)
768 oal = ofd_access_log_create(obd->obd_name, size);
772 spin_lock(&ofd->ofd_flags_lock);
773 if (ofd->ofd_access_log != NULL) {
776 ofd->ofd_access_log = oal;
777 ofd->ofd_access_log_size = size;
781 spin_unlock(&ofd->ofd_flags_lock);
783 ofd_access_log_delete(oal);
787 LUSTRE_RW_ATTR(access_log_size);
789 static int ofd_site_stats_seq_show(struct seq_file *m, void *data)
791 struct obd_device *obd = m->private;
793 return lu_site_stats_seq_print(obd->obd_lu_dev->ld_site, m);
796 LPROC_SEQ_FOPS_RO(ofd_site_stats);
799 * Show if the OFD enforces T10PI checksum.
801 * \param[in] m seq_file handle
802 * \param[in] data unused for single entry
804 * \retval 0 on success
805 * \retval negative value on error
807 static ssize_t checksum_t10pi_enforce_show(struct kobject *kobj,
808 struct attribute *attr,
811 struct obd_device *obd = container_of(kobj, struct obd_device,
813 struct lu_target *lut = obd->u.obt.obt_lut;
815 return scnprintf(buf, PAGE_SIZE, "%u\n", lut->lut_cksum_t10pi_enforce);
819 * Force specific T10PI checksum modes to be enabled
821 * If T10PI *is* supported in hardware, allow only the supported T10PI type
822 * to be used. If T10PI is *not* supported by the OSD, setting the enforce
823 * parameter forces all T10PI types to be enabled (even if slower) for
826 * The final determination of which algorithm to be used depends whether
827 * the client supports T10PI or not, and is handled at client connect time.
829 * \param[in] file proc file
830 * \param[in] buffer string which represents mode
831 * 1: set T10PI checksums enforced
832 * 0: unset T10PI checksums enforced
833 * \param[in] count \a buffer length
834 * \param[in] off unused for single entry
836 * \retval \a count on success
837 * \retval negative number on error
839 static ssize_t checksum_t10pi_enforce_store(struct kobject *kobj,
840 struct attribute *attr,
841 const char *buffer, size_t count)
843 struct obd_device *obd = container_of(kobj, struct obd_device,
845 struct lu_target *lut = obd->u.obt.obt_lut;
849 rc = kstrtobool(buffer, &enforce);
853 spin_lock(&lut->lut_flags_lock);
854 lut->lut_cksum_t10pi_enforce = enforce;
855 spin_unlock(&lut->lut_flags_lock);
858 LUSTRE_RW_ATTR(checksum_t10pi_enforce);
860 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 14, 53, 0)
861 static bool max_file_warned;
862 static bool rd_cache_warned;
863 static bool wr_cache_warned;
865 static ssize_t read_cache_enable_show(struct kobject *kobj,
866 struct attribute *attr,
869 struct obd_device *obd = container_of(kobj, struct obd_device,
871 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
873 if (!rd_cache_warned) {
874 rd_cache_warned = true;
875 pr_info("ofd: 'obdfilter.*.read_cache_enabled' is deprecated, use 'osd-*.read_cache_enabled' instead\n");
878 if (!ofd->ofd_read_cache_enable)
881 return lustre_attr_show(&ofd->ofd_osd->dd_kobj,
882 ofd->ofd_read_cache_enable, buf);
885 static ssize_t read_cache_enable_store(struct kobject *kobj,
886 struct attribute *attr,
887 const char *buffer, size_t count)
889 struct obd_device *obd = container_of(kobj, struct obd_device,
891 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
893 if (!rd_cache_warned) {
894 rd_cache_warned = true;
895 pr_info("ofd: 'obdfilter.*.read_cache_enabled' is deprecated, use 'osd-*.read_cache_enabled' instead\n");
898 if (!ofd->ofd_read_cache_enable)
901 return lustre_attr_store(&ofd->ofd_osd->dd_kobj,
902 ofd->ofd_read_cache_enable, buffer, count);
904 LUSTRE_RW_ATTR(read_cache_enable);
906 static ssize_t readcache_max_filesize_show(struct kobject *kobj,
907 struct attribute *attr,
910 struct obd_device *obd = container_of(kobj, struct obd_device,
912 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
914 if (!max_file_warned) {
915 max_file_warned = true;
916 pr_info("ofd: 'obdfilter.*.readcache_max_filesize' is deprecated, use 'osd-*.readcache_max_filesize' instead\n");
919 if (!ofd->ofd_read_cache_max_filesize)
922 return lustre_attr_show(&ofd->ofd_osd->dd_kobj,
923 ofd->ofd_read_cache_max_filesize, buf);
926 static ssize_t readcache_max_filesize_store(struct kobject *kobj,
927 struct attribute *attr,
928 const char *buffer, size_t count)
930 struct obd_device *obd = container_of(kobj, struct obd_device,
932 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
934 if (!max_file_warned) {
935 max_file_warned = true;
936 pr_info("ofd: 'obdfilter.*.readcache_max_filesize' is deprecated, use 'osd-*.readcache_max_filesize' instead\n");
939 if (!ofd->ofd_read_cache_max_filesize)
942 return lustre_attr_store(&ofd->ofd_osd->dd_kobj,
943 ofd->ofd_read_cache_max_filesize,
946 LUSTRE_RW_ATTR(readcache_max_filesize);
948 static ssize_t writethrough_cache_enable_show(struct kobject *kobj,
949 struct attribute *attr,
952 struct obd_device *obd = container_of(kobj, struct obd_device,
954 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
956 if (!wr_cache_warned) {
957 wr_cache_warned = true;
958 pr_info("ofd: 'obdfilter.*.writethrough_cache_enabled' is deprecated, use 'osd-*.writethrough_cache_enabled' instead\n");
961 if (!ofd->ofd_write_cache_enable)
964 return lustre_attr_show(&ofd->ofd_osd->dd_kobj,
965 ofd->ofd_write_cache_enable, buf);
968 static ssize_t writethrough_cache_enable_store(struct kobject *kobj,
969 struct attribute *attr,
970 const char *buffer, size_t count)
972 struct obd_device *obd = container_of(kobj, struct obd_device,
974 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
976 if (!ofd->ofd_write_cache_enable)
979 return lustre_attr_store(&ofd->ofd_osd->dd_kobj,
980 ofd->ofd_write_cache_enable,
983 LUSTRE_RW_ATTR(writethrough_cache_enable);
986 LPROC_SEQ_FOPS_RO_TYPE(ofd, recovery_status);
987 LUSTRE_RW_ATTR(recovery_time_hard);
988 LUSTRE_RW_ATTR(recovery_time_soft);
989 LUSTRE_RW_ATTR(ir_factor);
991 LPROC_SEQ_FOPS_WR_ONLY(ofd, evict_client);
992 LPROC_SEQ_FOPS_RW_TYPE(ofd, checksum_dump);
993 LUSTRE_RW_ATTR(job_cleanup_interval);
995 LUSTRE_RO_ATTR(tot_dirty);
996 LUSTRE_RO_ATTR(tot_granted);
997 LUSTRE_RO_ATTR(tot_pending);
998 LUSTRE_RW_ATTR(grant_compat_disable);
999 LUSTRE_RO_ATTR(instance);
1001 LUSTRE_RO_ATTR(num_exports);
1003 struct lprocfs_vars lprocfs_ofd_obd_vars[] = {
1004 { .name = "last_id",
1005 .fops = &ofd_last_id_fops },
1006 { .name = "recovery_status",
1007 .fops = &ofd_recovery_status_fops },
1008 { .name = "evict_client",
1009 .fops = &ofd_evict_client_fops },
1010 { .name = "brw_size",
1011 .fops = &ofd_brw_size_fops },
1012 { .name = "checksum_dump",
1013 .fops = &ofd_checksum_dump_fops },
1014 { .name = "lfsck_layout",
1015 .fops = &ofd_lfsck_layout_fops },
1016 { .name = "lfsck_verify_pfid",
1017 .fops = &ofd_lfsck_verify_pfid_fops },
1018 { .name = "site_stats",
1019 .fops = &ofd_site_stats_fops },
1024 * Initialize OFD statistics counters
1026 * param[in] stats statistics counters
1028 void ofd_stats_counter_init(struct lprocfs_stats *stats, unsigned int offset)
1030 LASSERT(stats && stats->ls_num >= LPROC_OFD_STATS_LAST);
1032 lprocfs_counter_init(stats, LPROC_OFD_STATS_READ_BYTES,
1033 LPROCFS_TYPE_BYTES_FULL, "read_bytes", "bytes");
1034 lprocfs_counter_init(stats, LPROC_OFD_STATS_WRITE_BYTES,
1035 LPROCFS_TYPE_BYTES_FULL, "write_bytes", "bytes");
1036 lprocfs_counter_init(stats, LPROC_OFD_STATS_READ,
1037 LPROCFS_TYPE_LATENCY, "read", "usecs");
1038 lprocfs_counter_init(stats, LPROC_OFD_STATS_WRITE,
1039 LPROCFS_TYPE_LATENCY, "write", "usecs");
1040 lprocfs_counter_init(stats, LPROC_OFD_STATS_GETATTR,
1041 LPROCFS_TYPE_LATENCY, "getattr", "usecs");
1042 lprocfs_counter_init(stats, LPROC_OFD_STATS_SETATTR,
1043 LPROCFS_TYPE_LATENCY, "setattr", "usecs");
1044 lprocfs_counter_init(stats, LPROC_OFD_STATS_PUNCH,
1045 LPROCFS_TYPE_LATENCY, "punch", "usecs");
1046 lprocfs_counter_init(stats, LPROC_OFD_STATS_SYNC,
1047 LPROCFS_TYPE_LATENCY, "sync", "usecs");
1048 lprocfs_counter_init(stats, LPROC_OFD_STATS_DESTROY,
1049 LPROCFS_TYPE_LATENCY, "destroy", "usecs");
1050 lprocfs_counter_init(stats, LPROC_OFD_STATS_CREATE,
1051 LPROCFS_TYPE_LATENCY, "create", "usecs");
1052 lprocfs_counter_init(stats, LPROC_OFD_STATS_STATFS,
1053 LPROCFS_TYPE_LATENCY, "statfs", "usecs");
1054 lprocfs_counter_init(stats, LPROC_OFD_STATS_GET_INFO,
1055 LPROCFS_TYPE_LATENCY, "get_info", "usecs");
1056 lprocfs_counter_init(stats, LPROC_OFD_STATS_SET_INFO,
1057 LPROCFS_TYPE_LATENCY, "set_info", "usecs");
1058 lprocfs_counter_init(stats, LPROC_OFD_STATS_QUOTACTL,
1059 LPROCFS_TYPE_LATENCY, "quotactl", "usecs");
1060 lprocfs_counter_init(stats, LPROC_OFD_STATS_PREALLOC,
1061 LPROCFS_TYPE_LATENCY, "prealloc", "usecs");
1064 LPROC_SEQ_FOPS(lprocfs_nid_stats_clear);
1066 static struct attribute *ofd_attrs[] = {
1067 &lustre_attr_tot_dirty.attr,
1068 &lustre_attr_tot_granted.attr,
1069 &lustre_attr_tot_pending.attr,
1070 &lustre_attr_grant_compat_disable.attr,
1071 &lustre_attr_instance.attr,
1072 &lustre_attr_recovery_time_hard.attr,
1073 &lustre_attr_recovery_time_soft.attr,
1074 &lustre_attr_ir_factor.attr,
1075 &lustre_attr_num_exports.attr,
1076 &lustre_attr_seqs_allocated.attr,
1077 &lustre_attr_grant_precreate.attr,
1078 &lustre_attr_precreate_batch.attr,
1079 &lustre_attr_atime_diff.attr,
1080 &lustre_attr_degraded.attr,
1081 &lustre_attr_fstype.attr,
1082 &lustre_attr_no_precreate.attr,
1083 &lustre_attr_sync_journal.attr,
1084 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 16, 53, 0)
1085 &lustre_attr_sync_on_lock_cancel.attr,
1087 &lustre_attr_soft_sync_limit.attr,
1088 &lustre_attr_lfsck_speed_limit.attr,
1089 &lustre_attr_access_log_mask.attr,
1090 &lustre_attr_access_log_size.attr,
1091 &lustre_attr_job_cleanup_interval.attr,
1092 &lustre_attr_checksum_t10pi_enforce.attr,
1093 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 14, 53, 0)
1094 &lustre_attr_read_cache_enable.attr,
1095 &lustre_attr_readcache_max_filesize.attr,
1096 &lustre_attr_writethrough_cache_enable.attr,
1102 * Initialize all needed procfs entries for OFD device.
1104 * \param[in] ofd OFD device
1106 * \retval 0 if successful
1107 * \retval negative value on error
1109 int ofd_tunables_init(struct ofd_device *ofd)
1111 struct obd_device *obd = ofd_obd(ofd);
1112 struct proc_dir_entry *entry;
1116 /* lprocfs must be setup before the ofd so state can be safely added
1117 * to /proc incrementally as the ofd is setup
1119 obd->obd_ktype.default_attrs = ofd_attrs;
1120 obd->obd_vars = lprocfs_ofd_obd_vars;
1121 rc = lprocfs_obd_setup(obd, false);
1123 CERROR("%s: lprocfs_obd_setup failed: %d.\n",
1128 rc = tgt_tunables_init(&ofd->ofd_lut);
1130 CERROR("%s: tgt_tunables_init failed: rc = %d\n",
1132 GOTO(obd_cleanup, rc);
1135 rc = lprocfs_alloc_obd_stats(obd, LPROC_OFD_STATS_LAST);
1137 CERROR("%s: lprocfs_alloc_obd_stats failed: %d.\n",
1139 GOTO(tgt_cleanup, rc);
1142 entry = lprocfs_register("exports", obd->obd_proc_entry, NULL, NULL);
1143 if (IS_ERR(entry)) {
1144 rc = PTR_ERR(entry);
1145 CERROR("%s: error %d setting up lprocfs for %s\n",
1146 obd->obd_name, rc, "exports");
1147 GOTO(obd_free_stats, rc);
1149 obd->obd_proc_exports_entry = entry;
1151 entry = lprocfs_add_simple(obd->obd_proc_exports_entry, "clear",
1152 obd, &lprocfs_nid_stats_clear_fops);
1153 if (IS_ERR(entry)) {
1154 rc = PTR_ERR(entry);
1155 CERROR("%s: add proc entry 'clear' failed: %d.\n",
1157 GOTO(obd_free_stats, rc);
1160 ofd_stats_counter_init(obd->obd_stats, 0);
1162 rc = lprocfs_job_stats_init(obd, LPROC_OFD_STATS_LAST,
1163 ofd_stats_counter_init);
1165 GOTO(obd_free_stats, rc);
1170 lprocfs_free_obd_stats(obd);
1172 tgt_tunables_fini(&ofd->ofd_lut);
1174 lprocfs_obd_cleanup(obd);
1178 #endif /* CONFIG_PROC_FS */