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) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2015, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 * lustre/osd/osd_lproc.c
33 * Author: Mikhail Pershin <tappro@sun.com>
36 #define DEBUG_SUBSYSTEM S_OSD
38 #include <lprocfs_status.h>
40 #include "osd_internal.h"
42 void osd_brw_stats_update(struct osd_device *osd, struct osd_iobuf *iobuf)
44 struct brw_stats *bs = &osd->od_brw_stats;
45 sector_t *last_block = NULL;
46 struct page **pages = iobuf->dr_pages;
47 struct page *last_page = NULL;
48 unsigned long discont_pages = 0;
49 unsigned long discont_blocks = 0;
50 sector_t *blocks = iobuf->dr_blocks;
51 int i, nr_pages = iobuf->dr_npages;
53 int rw = iobuf->dr_rw;
55 if (unlikely(nr_pages == 0))
58 blocks_per_page = PAGE_SIZE >> osd_sb(osd)->s_blocksize_bits;
60 lprocfs_oh_tally_log2_pcpu(&bs->bs_hist[BRW_R_PAGES + rw], nr_pages);
62 while (nr_pages-- > 0) {
63 if (last_page && (*pages)->index != (last_page->index + 1))
67 for (i = 0; i < blocks_per_page; i++) {
68 if (last_block && *blocks != (*last_block + 1))
70 last_block = blocks++;
74 lprocfs_oh_tally_pcpu(&bs->bs_hist[BRW_R_DISCONT_PAGES+rw],
76 lprocfs_oh_tally_pcpu(&bs->bs_hist[BRW_R_DISCONT_BLOCKS+rw],
80 static int osd_stats_init(struct osd_device *osd)
85 osd->od_stats = lprocfs_alloc_stats(LPROC_OSD_LAST, 0);
87 lprocfs_counter_init(osd->od_stats, LPROC_OSD_GET_PAGE,
88 LPROCFS_TYPE_LATENCY, "get_page");
89 lprocfs_counter_init(osd->od_stats, LPROC_OSD_NO_PAGE,
90 LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_REQS,
92 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_ACCESS,
93 LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
95 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_HIT,
96 LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
98 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_MISS,
99 LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
101 #if OSD_THANDLE_STATS
102 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_STARTING,
103 LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_USECS,
105 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_OPEN,
106 LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_USECS,
108 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_CLOSING,
109 LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_USECS,
115 ldebugfs_register_osd_stats(osd->od_dt_dev.dd_debugfs_entry,
116 &osd->od_brw_stats, osd->od_stats);
121 static ssize_t fstype_show(struct kobject *kobj, struct attribute *attr,
124 return sprintf(buf, "ldiskfs\n");
126 LUSTRE_RO_ATTR(fstype);
128 static ssize_t mntdev_show(struct kobject *kobj, struct attribute *attr,
131 struct dt_device *dt = container_of(kobj, struct dt_device,
133 struct osd_device *osd = osd_dt_dev(dt);
136 if (unlikely(!osd->od_mnt))
139 return sprintf(buf, "%s\n", osd->od_mntdev);
141 LUSTRE_RO_ATTR(mntdev);
143 static ssize_t read_cache_enable_show(struct kobject *kobj,
144 struct attribute *attr,
147 struct dt_device *dt = container_of(kobj, struct dt_device,
149 struct osd_device *osd = osd_dt_dev(dt);
152 if (unlikely(!osd->od_mnt))
155 return sprintf(buf, "%u\n", osd->od_read_cache);
158 static ssize_t read_cache_enable_store(struct kobject *kobj,
159 struct attribute *attr,
160 const char *buffer, size_t count)
162 struct dt_device *dt = container_of(kobj, struct dt_device,
164 struct osd_device *osd = osd_dt_dev(dt);
169 if (unlikely(!osd->od_mnt))
172 rc = kstrtobool(buffer, &val);
176 osd->od_read_cache = !!val;
179 LUSTRE_RW_ATTR(read_cache_enable);
181 static ssize_t writethrough_cache_enable_show(struct kobject *kobj,
182 struct attribute *attr,
185 struct dt_device *dt = container_of(kobj, struct dt_device,
187 struct osd_device *osd = osd_dt_dev(dt);
190 if (unlikely(!osd->od_mnt))
193 return sprintf(buf, "%u\n", osd->od_writethrough_cache);
196 static ssize_t writethrough_cache_enable_store(struct kobject *kobj,
197 struct attribute *attr,
201 struct dt_device *dt = container_of(kobj, struct dt_device,
203 struct osd_device *osd = osd_dt_dev(dt);
208 if (unlikely(!osd->od_mnt))
211 rc = kstrtobool(buffer, &val);
215 osd->od_writethrough_cache = !!val;
218 LUSTRE_RW_ATTR(writethrough_cache_enable);
220 static ssize_t enable_projid_xattr_show(struct kobject *kobj,
221 struct attribute *attr,
224 struct dt_device *dt = container_of(kobj, struct dt_device,
226 struct osd_device *osd = osd_dt_dev(dt);
229 if (unlikely(!osd->od_mnt))
232 return snprintf(buf, PAGE_SIZE, "%u\n", osd->od_enable_projid_xattr);
235 static ssize_t enable_projid_xattr_store(struct kobject *kobj,
236 struct attribute *attr,
240 struct dt_device *dt = container_of(kobj, struct dt_device,
242 struct osd_device *osd = osd_dt_dev(dt);
247 if (unlikely(!osd->od_mnt))
250 rc = kstrtobool(buffer, &val);
254 osd->od_enable_projid_xattr = !!val;
257 LUSTRE_RW_ATTR(enable_projid_xattr);
259 static ssize_t fallocate_zero_blocks_show(struct kobject *kobj,
260 struct attribute *attr,
263 struct dt_device *dt = container_of(kobj, struct dt_device,
265 struct osd_device *osd = osd_dt_dev(dt);
268 if (unlikely(!osd->od_mnt))
271 return scnprintf(buf, PAGE_SIZE, "%d\n", osd->od_fallocate_zero_blocks);
275 * Set how fallocate() interacts with the backing filesystem:
276 * -1: fallocate is disabled and returns -EOPNOTSUPP
277 * 0: fallocate allocates unwritten extents (like ext4)
278 * 1: fallocate zeroes allocated extents on disk
280 static ssize_t fallocate_zero_blocks_store(struct kobject *kobj,
281 struct attribute *attr,
282 const char *buffer, size_t count)
284 struct dt_device *dt = container_of(kobj, struct dt_device,
286 struct osd_device *osd = osd_dt_dev(dt);
291 if (unlikely(!osd->od_mnt))
294 rc = kstrtol(buffer, 0, &val);
298 if (val < -1 || val > 1)
301 osd->od_fallocate_zero_blocks = val;
304 LUSTRE_RW_ATTR(fallocate_zero_blocks);
306 ssize_t force_sync_store(struct kobject *kobj, struct attribute *attr,
307 const char *buffer, size_t count)
309 struct dt_device *dt = container_of(kobj, struct dt_device,
311 struct osd_device *osd = osd_dt_dev(dt);
316 if (unlikely(!osd->od_mnt))
319 rc = lu_env_init(&env, LCT_LOCAL);
323 rc = dt_sync(&env, dt);
326 return rc == 0 ? count : rc;
328 LUSTRE_WO_ATTR(force_sync);
330 static ssize_t nonrotational_show(struct kobject *kobj, struct attribute *attr,
333 struct dt_device *dt = container_of(kobj, struct dt_device,
335 struct osd_device *osd = osd_dt_dev(dt);
338 if (unlikely(!osd->od_mnt))
341 return sprintf(buf, "%u\n", osd->od_nonrotational);
344 static ssize_t nonrotational_store(struct kobject *kobj,
345 struct attribute *attr, const char *buffer,
348 struct dt_device *dt = container_of(kobj, struct dt_device,
350 struct osd_device *osd = osd_dt_dev(dt);
355 if (unlikely(!osd->od_mnt))
358 rc = kstrtobool(buffer, &val);
362 osd->od_nonrotational = val;
365 LUSTRE_RW_ATTR(nonrotational);
367 static ssize_t pdo_show(struct kobject *kobj, struct attribute *attr,
370 return sprintf(buf, "%s\n", ldiskfs_pdo ? "ON" : "OFF");
373 static ssize_t pdo_store(struct kobject *kobj, struct attribute *attr,
374 const char *buffer, size_t count)
379 rc = kstrtobool(buffer, &pdo);
389 static ssize_t auto_scrub_show(struct kobject *kobj, struct attribute *attr,
392 struct dt_device *dt = container_of(kobj, struct dt_device,
394 struct osd_device *dev = osd_dt_dev(dt);
397 if (unlikely(!dev->od_mnt))
400 return scnprintf(buf, PAGE_SIZE, "%lld\n",
401 dev->od_scrub.os_scrub.os_auto_scrub_interval);
404 static ssize_t auto_scrub_store(struct kobject *kobj, struct attribute *attr,
405 const char *buffer, size_t count)
407 struct dt_device *dt = container_of(kobj, struct dt_device,
409 struct osd_device *dev = osd_dt_dev(dt);
414 if (unlikely(!dev->od_mnt))
417 rc = kstrtoll(buffer, 0, &val);
421 dev->od_scrub.os_scrub.os_auto_scrub_interval = val;
424 LUSTRE_RW_ATTR(auto_scrub);
426 static ssize_t full_scrub_ratio_show(struct kobject *kobj,
427 struct attribute *attr,
430 struct dt_device *dt = container_of(kobj, struct dt_device,
432 struct osd_device *dev = osd_dt_dev(dt);
435 if (unlikely(!dev->od_mnt))
438 return sprintf(buf, "%llu\n", dev->od_full_scrub_ratio);
441 static ssize_t full_scrub_ratio_store(struct kobject *kobj,
442 struct attribute *attr,
443 const char *buffer, size_t count)
445 struct dt_device *dt = container_of(kobj, struct dt_device,
447 struct osd_device *dev = osd_dt_dev(dt);
452 if (unlikely(!dev->od_mnt))
455 rc = kstrtoll(buffer, 0, &val);
462 dev->od_full_scrub_ratio = val;
465 LUSTRE_RW_ATTR(full_scrub_ratio);
467 static ssize_t full_scrub_threshold_rate_show(struct kobject *kobj,
468 struct attribute *attr,
471 struct dt_device *dt = container_of(kobj, struct dt_device,
473 struct osd_device *dev = osd_dt_dev(dt);
476 if (unlikely(!dev->od_mnt))
479 return sprintf(buf, "%llu (bad OI mappings/minute)\n",
480 dev->od_full_scrub_threshold_rate);
483 static ssize_t full_scrub_threshold_rate_store(struct kobject *kobj,
484 struct attribute *attr,
485 const char *buffer, size_t count)
487 struct dt_device *dt = container_of(kobj, struct dt_device,
489 struct osd_device *dev = osd_dt_dev(dt);
494 if (unlikely(!dev->od_mnt))
497 rc = kstrtoull(buffer, 0, &val);
501 dev->od_full_scrub_threshold_rate = val;
504 LUSTRE_RW_ATTR(full_scrub_threshold_rate);
506 static ssize_t extent_bytes_allocation_show(struct kobject *kobj,
507 struct attribute *attr, char *buf)
509 struct dt_device *dt = container_of(kobj, struct dt_device,
511 struct osd_device *dev = osd_dt_dev(dt);
513 unsigned int min = (unsigned int)(~0), cur;
515 for_each_online_cpu(i) {
516 cur = *per_cpu_ptr(dev->od_extent_bytes_percpu, i);
520 return snprintf(buf, PAGE_SIZE, "%u\n", min);
522 LUSTRE_RO_ATTR(extent_bytes_allocation);
524 static int ldiskfs_osd_oi_scrub_seq_show(struct seq_file *m, void *data)
526 struct osd_device *dev = osd_dt_dev((struct dt_device *)m->private);
528 LASSERT(dev != NULL);
529 if (unlikely(dev->od_mnt == NULL))
532 osd_scrub_dump(m, dev);
536 LDEBUGFS_SEQ_FOPS_RO(ldiskfs_osd_oi_scrub);
538 static int ldiskfs_osd_readcache_seq_show(struct seq_file *m, void *data)
540 struct osd_device *osd = osd_dt_dev((struct dt_device *)m->private);
542 LASSERT(osd != NULL);
543 if (unlikely(osd->od_mnt == NULL))
546 seq_printf(m, "%llu\n", osd->od_readcache_max_filesize);
551 ldiskfs_osd_readcache_seq_write(struct file *file, const char __user *buffer,
552 size_t count, loff_t *off)
554 struct seq_file *m = file->private_data;
555 struct dt_device *dt = m->private;
556 struct osd_device *osd = osd_dt_dev(dt);
557 char kernbuf[22] = "";
561 LASSERT(osd != NULL);
562 if (unlikely(osd->od_mnt == NULL))
565 if (count >= sizeof(kernbuf))
568 if (copy_from_user(kernbuf, buffer, count))
572 rc = sysfs_memparse(kernbuf, count, &val, "B");
576 osd->od_readcache_max_filesize = val > OSD_MAX_CACHE_SIZE ?
577 OSD_MAX_CACHE_SIZE : val;
581 LDEBUGFS_SEQ_FOPS(ldiskfs_osd_readcache);
583 static int ldiskfs_osd_readcache_max_io_seq_show(struct seq_file *m, void *data)
585 struct osd_device *osd = osd_dt_dev((struct dt_device *)m->private);
587 LASSERT(osd != NULL);
588 if (unlikely(osd->od_mnt == NULL))
591 seq_printf(m, "%lu\n", osd->od_readcache_max_iosize >> 20);
596 ldiskfs_osd_readcache_max_io_seq_write(struct file *file,
597 const char __user *buffer,
598 size_t count, loff_t *off)
600 struct seq_file *m = file->private_data;
601 struct dt_device *dt = m->private;
602 struct osd_device *osd = osd_dt_dev(dt);
603 char kernbuf[22] = "";
607 LASSERT(osd != NULL);
608 if (unlikely(osd->od_mnt == NULL))
611 if (count >= sizeof(kernbuf))
614 if (copy_from_user(kernbuf, buffer, count))
618 rc = sysfs_memparse(kernbuf, count, &val, "MiB");
622 if (val > PTLRPC_MAX_BRW_SIZE)
624 osd->od_readcache_max_iosize = val;
628 LDEBUGFS_SEQ_FOPS(ldiskfs_osd_readcache_max_io);
630 static int ldiskfs_osd_writethrough_max_io_seq_show(struct seq_file *m,
633 struct osd_device *osd = osd_dt_dev((struct dt_device *)m->private);
635 LASSERT(osd != NULL);
636 if (unlikely(osd->od_mnt == NULL))
639 seq_printf(m, "%lu\n", osd->od_writethrough_max_iosize >> 20);
644 ldiskfs_osd_writethrough_max_io_seq_write(struct file *file,
645 const char __user *buffer,
646 size_t count, loff_t *off)
648 struct seq_file *m = file->private_data;
649 struct dt_device *dt = m->private;
650 struct osd_device *osd = osd_dt_dev(dt);
651 char kernbuf[22] = "";
655 LASSERT(osd != NULL);
656 if (unlikely(osd->od_mnt == NULL))
659 if (count >= sizeof(kernbuf))
662 if (copy_from_user(kernbuf, buffer, count))
666 rc = sysfs_memparse(kernbuf, count, &val, "MiB");
670 if (val > PTLRPC_MAX_BRW_SIZE)
672 osd->od_writethrough_max_iosize = val;
676 LDEBUGFS_SEQ_FOPS(ldiskfs_osd_writethrough_max_io);
678 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 52, 0)
679 static ssize_t index_in_idif_show(struct kobject *kobj, struct attribute *attr,
682 struct dt_device *dt = container_of(kobj, struct dt_device,
684 struct osd_device *dev = osd_dt_dev(dt);
687 if (unlikely(!dev->od_mnt))
690 return sprintf(buf, "%d\n", (int)(dev->od_index_in_idif));
693 static ssize_t index_in_idif_store(struct kobject *kobj,
694 struct attribute *attr,
695 const char *buffer, size_t count)
697 struct dt_device *dt = container_of(kobj, struct dt_device,
699 struct osd_device *dev = osd_dt_dev(dt);
700 struct lu_target *tgt;
706 if (unlikely(!dev->od_mnt))
709 rc = kstrtobool(buffer, &val);
713 if (dev->od_index_in_idif) {
717 LCONSOLE_WARN("%s: OST-index in IDIF has been enabled, "
718 "it cannot be reverted back.\n", osd_name(dev));
725 rc = lu_env_init(&env, LCT_DT_THREAD);
729 tgt = dev->od_dt_dev.dd_lu_dev.ld_site->ls_tgt;
730 tgt->lut_lsd.lsd_feature_rocompat |= OBD_ROCOMPAT_IDX_IN_IDIF;
731 rc = tgt_server_data_update(&env, tgt, 1);
736 LCONSOLE_INFO("%s: enable OST-index in IDIF successfully, "
737 "it cannot be reverted back.\n", osd_name(dev));
739 dev->od_index_in_idif = 1;
742 LUSTRE_RW_ATTR(index_in_idif);
744 int osd_register_proc_index_in_idif(struct osd_device *osd)
746 struct dt_device *dt = &osd->od_dt_dev;
748 return sysfs_create_file(&dt->dd_kobj, &lustre_attr_index_in_idif.attr);
752 static ssize_t index_backup_show(struct kobject *kobj, struct attribute *attr,
755 struct dt_device *dt = container_of(kobj, struct dt_device,
757 struct osd_device *dev = osd_dt_dev(dt);
760 if (unlikely(!dev->od_mnt))
763 return sprintf(buf, "%d\n", dev->od_index_backup_policy);
766 ssize_t index_backup_store(struct kobject *kobj, struct attribute *attr,
767 const char *buffer, size_t count)
769 struct dt_device *dt = container_of(kobj, struct dt_device,
771 struct osd_device *dev = osd_dt_dev(dt);
776 if (unlikely(!dev->od_mnt))
779 rc = kstrtoint(buffer, 0, &val);
783 dev->od_index_backup_policy = val;
786 LUSTRE_RW_ATTR(index_backup);
788 struct ldebugfs_vars ldebugfs_osd_obd_vars[] = {
789 { .name = "oi_scrub",
790 .fops = &ldiskfs_osd_oi_scrub_fops },
791 { .name = "readcache_max_filesize",
792 .fops = &ldiskfs_osd_readcache_fops },
793 { .name = "readcache_max_io_mb",
794 .fops = &ldiskfs_osd_readcache_max_io_fops },
795 { .name = "writethrough_max_io_mb",
796 .fops = &ldiskfs_osd_writethrough_max_io_fops },
800 static struct attribute *ldiskfs_attrs[] = {
801 &lustre_attr_read_cache_enable.attr,
802 &lustre_attr_writethrough_cache_enable.attr,
803 &lustre_attr_enable_projid_xattr.attr,
804 &lustre_attr_fstype.attr,
805 &lustre_attr_mntdev.attr,
806 &lustre_attr_fallocate_zero_blocks.attr,
807 &lustre_attr_force_sync.attr,
808 &lustre_attr_nonrotational.attr,
809 &lustre_attr_index_backup.attr,
810 &lustre_attr_auto_scrub.attr,
811 &lustre_attr_pdo.attr,
812 &lustre_attr_full_scrub_ratio.attr,
813 &lustre_attr_full_scrub_threshold_rate.attr,
814 &lustre_attr_extent_bytes_allocation.attr,
818 int osd_procfs_init(struct osd_device *osd, const char *name)
820 struct obd_type *type;
825 /* at the moment there is no linkage between lu_type
826 * and obd_type, so we lookup obd_type this way
828 type = class_search_type(LUSTRE_OSD_LDISKFS_NAME);
833 CDEBUG(D_CONFIG, "%s: register osd-ldiskfs tunable parameters\n", name);
835 /* put reference taken by class_search_type */
836 kobject_put(&type->typ_kobj);
838 osd->od_dt_dev.dd_ktype.default_attrs = ldiskfs_attrs;
839 rc = dt_tunables_init(&osd->od_dt_dev, type, name,
840 ldebugfs_osd_obd_vars);
842 CERROR("%s: cannot setup sysfs / debugfs entry: %d\n",
847 if (osd->od_proc_entry)
850 /* Find the type procroot and add the proc entry for this device */
851 osd->od_proc_entry = lprocfs_register(name, type->typ_procroot,
852 NULL, &osd->od_dt_dev);
853 if (IS_ERR(osd->od_proc_entry)) {
854 rc = PTR_ERR(osd->od_proc_entry);
855 CERROR("Error %d setting up lprocfs for %s\n",
857 osd->od_proc_entry = NULL;
861 rc = osd_stats_init(osd);
866 osd_procfs_fini(osd);
870 int osd_procfs_fini(struct osd_device *osd)
872 lprocfs_fini_brw_stats(&osd->od_brw_stats);
875 lprocfs_free_stats(&osd->od_stats);
877 if (osd->od_proc_entry)
878 lprocfs_remove(&osd->od_proc_entry);
880 return dt_tunables_fini(&osd->od_dt_dev);