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_stats_alloc(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,
112 lprocfs_counter_init(osd->od_stats, LPROC_OSD_TOO_MANY_CREDITS,
113 LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_REQS,
118 ldebugfs_register_osd_stats(osd->od_dt_dev.dd_debugfs_entry,
119 &osd->od_brw_stats, osd->od_stats);
124 static ssize_t fstype_show(struct kobject *kobj, struct attribute *attr,
127 return sprintf(buf, "ldiskfs\n");
129 LUSTRE_RO_ATTR(fstype);
131 static ssize_t mntdev_show(struct kobject *kobj, struct attribute *attr,
134 struct dt_device *dt = container_of(kobj, struct dt_device,
136 struct osd_device *osd = osd_dt_dev(dt);
139 if (unlikely(!osd->od_mnt))
142 return sprintf(buf, "%s\n", osd->od_mntdev);
144 LUSTRE_RO_ATTR(mntdev);
146 static ssize_t read_cache_enable_show(struct kobject *kobj,
147 struct attribute *attr,
150 struct dt_device *dt = container_of(kobj, struct dt_device,
152 struct osd_device *osd = osd_dt_dev(dt);
155 if (unlikely(!osd->od_mnt))
158 return sprintf(buf, "%u\n", osd->od_read_cache);
161 static ssize_t read_cache_enable_store(struct kobject *kobj,
162 struct attribute *attr,
163 const char *buffer, size_t count)
165 struct dt_device *dt = container_of(kobj, struct dt_device,
167 struct osd_device *osd = osd_dt_dev(dt);
172 if (unlikely(!osd->od_mnt))
175 rc = kstrtobool(buffer, &val);
179 osd->od_read_cache = !!val;
182 LUSTRE_RW_ATTR(read_cache_enable);
184 static ssize_t writethrough_cache_enable_show(struct kobject *kobj,
185 struct attribute *attr,
188 struct dt_device *dt = container_of(kobj, struct dt_device,
190 struct osd_device *osd = osd_dt_dev(dt);
193 if (unlikely(!osd->od_mnt))
196 return sprintf(buf, "%u\n", osd->od_writethrough_cache);
199 static ssize_t writethrough_cache_enable_store(struct kobject *kobj,
200 struct attribute *attr,
204 struct dt_device *dt = container_of(kobj, struct dt_device,
206 struct osd_device *osd = osd_dt_dev(dt);
211 if (unlikely(!osd->od_mnt))
214 rc = kstrtobool(buffer, &val);
218 osd->od_writethrough_cache = !!val;
221 LUSTRE_RW_ATTR(writethrough_cache_enable);
223 static ssize_t enable_projid_xattr_show(struct kobject *kobj,
224 struct attribute *attr,
227 struct dt_device *dt = container_of(kobj, struct dt_device,
229 struct osd_device *osd = osd_dt_dev(dt);
232 if (unlikely(!osd->od_mnt))
235 return snprintf(buf, PAGE_SIZE, "%u\n", osd->od_enable_projid_xattr);
238 static ssize_t enable_projid_xattr_store(struct kobject *kobj,
239 struct attribute *attr,
243 struct dt_device *dt = container_of(kobj, struct dt_device,
245 struct osd_device *osd = osd_dt_dev(dt);
250 if (unlikely(!osd->od_mnt))
253 rc = kstrtobool(buffer, &val);
257 osd->od_enable_projid_xattr = !!val;
260 LUSTRE_RW_ATTR(enable_projid_xattr);
262 static ssize_t fallocate_zero_blocks_show(struct kobject *kobj,
263 struct attribute *attr,
266 struct dt_device *dt = container_of(kobj, struct dt_device,
268 struct osd_device *osd = osd_dt_dev(dt);
271 if (unlikely(!osd->od_mnt))
274 return scnprintf(buf, PAGE_SIZE, "%d\n", osd->od_fallocate_zero_blocks);
278 * Set how fallocate() interacts with the backing filesystem:
279 * -1: fallocate is disabled and returns -EOPNOTSUPP
280 * 0: fallocate allocates unwritten extents (like ext4)
281 * 1: fallocate zeroes allocated extents on disk
283 static ssize_t fallocate_zero_blocks_store(struct kobject *kobj,
284 struct attribute *attr,
285 const char *buffer, size_t count)
287 struct dt_device *dt = container_of(kobj, struct dt_device,
289 struct osd_device *osd = osd_dt_dev(dt);
294 if (unlikely(!osd->od_mnt))
297 rc = kstrtol(buffer, 0, &val);
301 if (val < -1 || val > 1)
304 osd->od_fallocate_zero_blocks = val;
307 LUSTRE_RW_ATTR(fallocate_zero_blocks);
309 ssize_t force_sync_store(struct kobject *kobj, struct attribute *attr,
310 const char *buffer, size_t count)
312 struct dt_device *dt = container_of(kobj, struct dt_device,
314 struct osd_device *osd = osd_dt_dev(dt);
319 if (unlikely(!osd->od_mnt))
322 rc = lu_env_init(&env, LCT_LOCAL);
326 rc = dt_sync(&env, dt);
329 return rc == 0 ? count : rc;
331 LUSTRE_WO_ATTR(force_sync);
333 static ssize_t nonrotational_show(struct kobject *kobj, struct attribute *attr,
336 struct dt_device *dt = container_of(kobj, struct dt_device,
338 struct osd_device *osd = osd_dt_dev(dt);
341 if (unlikely(!osd->od_mnt))
344 return sprintf(buf, "%u\n", osd->od_nonrotational);
347 static ssize_t nonrotational_store(struct kobject *kobj,
348 struct attribute *attr, const char *buffer,
351 struct dt_device *dt = container_of(kobj, struct dt_device,
353 struct osd_device *osd = osd_dt_dev(dt);
358 if (unlikely(!osd->od_mnt))
361 rc = kstrtobool(buffer, &val);
365 osd->od_nonrotational = val;
368 LUSTRE_RW_ATTR(nonrotational);
370 static ssize_t pdo_show(struct kobject *kobj, struct attribute *attr,
373 return sprintf(buf, "%s\n", ldiskfs_pdo ? "ON" : "OFF");
376 static ssize_t pdo_store(struct kobject *kobj, struct attribute *attr,
377 const char *buffer, size_t count)
382 rc = kstrtobool(buffer, &pdo);
392 static ssize_t auto_scrub_show(struct kobject *kobj, struct attribute *attr,
395 struct dt_device *dt = container_of(kobj, struct dt_device,
397 struct osd_device *dev = osd_dt_dev(dt);
400 if (unlikely(!dev->od_mnt))
403 return scnprintf(buf, PAGE_SIZE, "%lld\n",
404 dev->od_scrub.os_scrub.os_auto_scrub_interval);
407 static ssize_t auto_scrub_store(struct kobject *kobj, struct attribute *attr,
408 const char *buffer, size_t count)
410 struct dt_device *dt = container_of(kobj, struct dt_device,
412 struct osd_device *dev = osd_dt_dev(dt);
417 if (unlikely(!dev->od_mnt))
420 rc = kstrtoll(buffer, 0, &val);
424 dev->od_scrub.os_scrub.os_auto_scrub_interval = val;
427 LUSTRE_RW_ATTR(auto_scrub);
429 static ssize_t full_scrub_ratio_show(struct kobject *kobj,
430 struct attribute *attr,
433 struct dt_device *dt = container_of(kobj, struct dt_device,
435 struct osd_device *dev = osd_dt_dev(dt);
438 if (unlikely(!dev->od_mnt))
441 return sprintf(buf, "%llu\n", dev->od_full_scrub_ratio);
444 static ssize_t full_scrub_ratio_store(struct kobject *kobj,
445 struct attribute *attr,
446 const char *buffer, size_t count)
448 struct dt_device *dt = container_of(kobj, struct dt_device,
450 struct osd_device *dev = osd_dt_dev(dt);
455 if (unlikely(!dev->od_mnt))
458 rc = kstrtoll(buffer, 0, &val);
465 dev->od_full_scrub_ratio = val;
468 LUSTRE_RW_ATTR(full_scrub_ratio);
470 static ssize_t full_scrub_threshold_rate_show(struct kobject *kobj,
471 struct attribute *attr,
474 struct dt_device *dt = container_of(kobj, struct dt_device,
476 struct osd_device *dev = osd_dt_dev(dt);
479 if (unlikely(!dev->od_mnt))
482 return sprintf(buf, "%llu (bad OI mappings/minute)\n",
483 dev->od_full_scrub_threshold_rate);
486 static ssize_t full_scrub_threshold_rate_store(struct kobject *kobj,
487 struct attribute *attr,
488 const char *buffer, size_t count)
490 struct dt_device *dt = container_of(kobj, struct dt_device,
492 struct osd_device *dev = osd_dt_dev(dt);
497 if (unlikely(!dev->od_mnt))
500 rc = kstrtoull(buffer, 0, &val);
504 dev->od_full_scrub_threshold_rate = val;
507 LUSTRE_RW_ATTR(full_scrub_threshold_rate);
509 static ssize_t extent_bytes_allocation_show(struct kobject *kobj,
510 struct attribute *attr, char *buf)
512 struct dt_device *dt = container_of(kobj, struct dt_device,
514 struct osd_device *dev = osd_dt_dev(dt);
516 unsigned int min = (unsigned int)(~0), cur;
518 for_each_online_cpu(i) {
519 cur = *per_cpu_ptr(dev->od_extent_bytes_percpu, i);
523 return snprintf(buf, PAGE_SIZE, "%u\n", min);
525 LUSTRE_RO_ATTR(extent_bytes_allocation);
527 static int ldiskfs_osd_oi_scrub_seq_show(struct seq_file *m, void *data)
529 struct osd_device *dev = osd_dt_dev((struct dt_device *)m->private);
531 LASSERT(dev != NULL);
532 if (unlikely(dev->od_mnt == NULL))
535 osd_scrub_dump(m, dev);
539 LDEBUGFS_SEQ_FOPS_RO(ldiskfs_osd_oi_scrub);
541 static int ldiskfs_osd_readcache_seq_show(struct seq_file *m, void *data)
543 struct osd_device *osd = osd_dt_dev((struct dt_device *)m->private);
545 LASSERT(osd != NULL);
546 if (unlikely(osd->od_mnt == NULL))
549 seq_printf(m, "%llu\n", osd->od_readcache_max_filesize);
554 ldiskfs_osd_readcache_seq_write(struct file *file, const char __user *buffer,
555 size_t count, loff_t *off)
557 struct seq_file *m = file->private_data;
558 struct dt_device *dt = m->private;
559 struct osd_device *osd = osd_dt_dev(dt);
560 char kernbuf[22] = "";
564 LASSERT(osd != NULL);
565 if (unlikely(osd->od_mnt == NULL))
568 if (count >= sizeof(kernbuf))
571 if (copy_from_user(kernbuf, buffer, count))
575 rc = sysfs_memparse(kernbuf, count, &val, "B");
579 osd->od_readcache_max_filesize = val > OSD_MAX_CACHE_SIZE ?
580 OSD_MAX_CACHE_SIZE : val;
584 LDEBUGFS_SEQ_FOPS(ldiskfs_osd_readcache);
586 static int ldiskfs_osd_readcache_max_io_seq_show(struct seq_file *m, void *data)
588 struct osd_device *osd = osd_dt_dev((struct dt_device *)m->private);
590 LASSERT(osd != NULL);
591 if (unlikely(osd->od_mnt == NULL))
594 seq_printf(m, "%lu\n", osd->od_readcache_max_iosize >> 20);
599 ldiskfs_osd_readcache_max_io_seq_write(struct file *file,
600 const char __user *buffer,
601 size_t count, loff_t *off)
603 struct seq_file *m = file->private_data;
604 struct dt_device *dt = m->private;
605 struct osd_device *osd = osd_dt_dev(dt);
606 char kernbuf[22] = "";
610 LASSERT(osd != NULL);
611 if (unlikely(osd->od_mnt == NULL))
614 if (count >= sizeof(kernbuf))
617 if (copy_from_user(kernbuf, buffer, count))
621 rc = sysfs_memparse(kernbuf, count, &val, "MiB");
625 if (val > PTLRPC_MAX_BRW_SIZE)
627 osd->od_readcache_max_iosize = val;
631 LDEBUGFS_SEQ_FOPS(ldiskfs_osd_readcache_max_io);
633 static int ldiskfs_osd_writethrough_max_io_seq_show(struct seq_file *m,
636 struct osd_device *osd = osd_dt_dev((struct dt_device *)m->private);
638 LASSERT(osd != NULL);
639 if (unlikely(osd->od_mnt == NULL))
642 seq_printf(m, "%lu\n", osd->od_writethrough_max_iosize >> 20);
647 ldiskfs_osd_writethrough_max_io_seq_write(struct file *file,
648 const char __user *buffer,
649 size_t count, loff_t *off)
651 struct seq_file *m = file->private_data;
652 struct dt_device *dt = m->private;
653 struct osd_device *osd = osd_dt_dev(dt);
654 char kernbuf[22] = "";
658 LASSERT(osd != NULL);
659 if (unlikely(osd->od_mnt == NULL))
662 if (count >= sizeof(kernbuf))
665 if (copy_from_user(kernbuf, buffer, count))
669 rc = sysfs_memparse(kernbuf, count, &val, "MiB");
673 if (val > PTLRPC_MAX_BRW_SIZE)
675 osd->od_writethrough_max_iosize = val;
679 LDEBUGFS_SEQ_FOPS(ldiskfs_osd_writethrough_max_io);
681 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 52, 0)
682 static ssize_t index_in_idif_show(struct kobject *kobj, struct attribute *attr,
685 struct dt_device *dt = container_of(kobj, struct dt_device,
687 struct osd_device *dev = osd_dt_dev(dt);
690 if (unlikely(!dev->od_mnt))
693 return sprintf(buf, "%d\n", (int)(dev->od_index_in_idif));
696 static ssize_t index_in_idif_store(struct kobject *kobj,
697 struct attribute *attr,
698 const char *buffer, size_t count)
700 struct dt_device *dt = container_of(kobj, struct dt_device,
702 struct osd_device *dev = osd_dt_dev(dt);
703 struct lu_target *tgt;
709 if (unlikely(!dev->od_mnt))
712 rc = kstrtobool(buffer, &val);
716 if (dev->od_index_in_idif) {
720 LCONSOLE_WARN("%s: OST-index in IDIF has been enabled, "
721 "it cannot be reverted back.\n", osd_name(dev));
728 rc = lu_env_init(&env, LCT_DT_THREAD);
732 tgt = dev->od_dt_dev.dd_lu_dev.ld_site->ls_tgt;
733 tgt->lut_lsd.lsd_feature_rocompat |= OBD_ROCOMPAT_IDX_IN_IDIF;
734 rc = tgt_server_data_update(&env, tgt, 1);
739 LCONSOLE_INFO("%s: enable OST-index in IDIF successfully, "
740 "it cannot be reverted back.\n", osd_name(dev));
742 dev->od_index_in_idif = 1;
745 LUSTRE_RW_ATTR(index_in_idif);
747 int osd_register_proc_index_in_idif(struct osd_device *osd)
749 struct dt_device *dt = &osd->od_dt_dev;
751 return sysfs_create_file(&dt->dd_kobj, &lustre_attr_index_in_idif.attr);
755 static ssize_t index_backup_show(struct kobject *kobj, struct attribute *attr,
758 struct dt_device *dt = container_of(kobj, struct dt_device,
760 struct osd_device *dev = osd_dt_dev(dt);
763 if (unlikely(!dev->od_mnt))
766 return sprintf(buf, "%d\n", dev->od_index_backup_policy);
769 ssize_t index_backup_store(struct kobject *kobj, struct attribute *attr,
770 const char *buffer, size_t count)
772 struct dt_device *dt = container_of(kobj, struct dt_device,
774 struct osd_device *dev = osd_dt_dev(dt);
779 if (unlikely(!dev->od_mnt))
782 rc = kstrtoint(buffer, 0, &val);
786 dev->od_index_backup_policy = val;
789 LUSTRE_RW_ATTR(index_backup);
791 struct ldebugfs_vars ldebugfs_osd_obd_vars[] = {
792 { .name = "oi_scrub",
793 .fops = &ldiskfs_osd_oi_scrub_fops },
794 { .name = "readcache_max_filesize",
795 .fops = &ldiskfs_osd_readcache_fops },
796 { .name = "readcache_max_io_mb",
797 .fops = &ldiskfs_osd_readcache_max_io_fops },
798 { .name = "writethrough_max_io_mb",
799 .fops = &ldiskfs_osd_writethrough_max_io_fops },
803 static struct attribute *ldiskfs_attrs[] = {
804 &lustre_attr_read_cache_enable.attr,
805 &lustre_attr_writethrough_cache_enable.attr,
806 &lustre_attr_enable_projid_xattr.attr,
807 &lustre_attr_fstype.attr,
808 &lustre_attr_mntdev.attr,
809 &lustre_attr_fallocate_zero_blocks.attr,
810 &lustre_attr_force_sync.attr,
811 &lustre_attr_nonrotational.attr,
812 &lustre_attr_index_backup.attr,
813 &lustre_attr_auto_scrub.attr,
814 &lustre_attr_pdo.attr,
815 &lustre_attr_full_scrub_ratio.attr,
816 &lustre_attr_full_scrub_threshold_rate.attr,
817 &lustre_attr_extent_bytes_allocation.attr,
821 KOBJ_ATTRIBUTE_GROUPS(ldiskfs); /* creates ldiskfs_groups from ldiskfs_attrs */
823 int osd_procfs_init(struct osd_device *osd, const char *name)
825 struct obd_type *type;
830 /* at the moment there is no linkage between lu_type
831 * and obd_type, so we lookup obd_type this way
833 type = class_search_type(LUSTRE_OSD_LDISKFS_NAME);
838 CDEBUG(D_CONFIG, "%s: register osd-ldiskfs tunable parameters\n", name);
840 /* put reference taken by class_search_type */
841 kobject_put(&type->typ_kobj);
843 osd->od_dt_dev.dd_ktype.default_groups = KOBJ_ATTR_GROUPS(ldiskfs);
844 rc = dt_tunables_init(&osd->od_dt_dev, type, name,
845 ldebugfs_osd_obd_vars);
847 CERROR("%s: cannot setup sysfs / debugfs entry: %d\n",
852 if (osd->od_proc_entry)
855 /* Find the type procroot and add the proc entry for this device */
856 osd->od_proc_entry = lprocfs_register(name, type->typ_procroot,
857 NULL, &osd->od_dt_dev);
858 if (IS_ERR(osd->od_proc_entry)) {
859 rc = PTR_ERR(osd->od_proc_entry);
860 CERROR("Error %d setting up lprocfs for %s\n",
862 osd->od_proc_entry = NULL;
866 rc = osd_stats_init(osd);
871 osd_procfs_fini(osd);
875 int osd_procfs_fini(struct osd_device *osd)
877 lprocfs_fini_brw_stats(&osd->od_brw_stats);
880 lprocfs_stats_free(&osd->od_stats);
882 if (osd->od_proc_entry)
883 lprocfs_remove(&osd->od_proc_entry);
885 return dt_tunables_fini(&osd->od_dt_dev);