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_CNTR_AVGMINMAX|LPROCFS_CNTR_STDDEV,
90 lprocfs_counter_init(osd->od_stats, LPROC_OSD_NO_PAGE,
91 LPROCFS_CNTR_AVGMINMAX,
92 "get_page_failures", "num");
93 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_ACCESS,
94 LPROCFS_CNTR_AVGMINMAX,
95 "cache_access", "pages");
96 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_HIT,
97 LPROCFS_CNTR_AVGMINMAX,
98 "cache_hit", "pages");
99 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_MISS,
100 LPROCFS_CNTR_AVGMINMAX,
101 "cache_miss", "pages");
102 #if OSD_THANDLE_STATS
103 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_STARTING,
104 LPROCFS_CNTR_AVGMINMAX,
105 "thandle starting", "usec");
106 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_OPEN,
107 LPROCFS_CNTR_AVGMINMAX,
108 "thandle open", "usec");
109 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_CLOSING,
110 LPROCFS_CNTR_AVGMINMAX,
111 "thandle closing", "usec");
116 ldebugfs_register_osd_stats(osd->od_dt_dev.dd_debugfs_entry,
117 &osd->od_brw_stats, osd->od_stats);
122 static ssize_t fstype_show(struct kobject *kobj, struct attribute *attr,
125 return sprintf(buf, "ldiskfs\n");
127 LUSTRE_RO_ATTR(fstype);
129 static ssize_t mntdev_show(struct kobject *kobj, struct attribute *attr,
132 struct dt_device *dt = container_of(kobj, struct dt_device,
134 struct osd_device *osd = osd_dt_dev(dt);
137 if (unlikely(!osd->od_mnt))
140 return sprintf(buf, "%s\n", osd->od_mntdev);
142 LUSTRE_RO_ATTR(mntdev);
144 static ssize_t read_cache_enable_show(struct kobject *kobj,
145 struct attribute *attr,
148 struct dt_device *dt = container_of(kobj, struct dt_device,
150 struct osd_device *osd = osd_dt_dev(dt);
153 if (unlikely(!osd->od_mnt))
156 return sprintf(buf, "%u\n", osd->od_read_cache);
159 static ssize_t read_cache_enable_store(struct kobject *kobj,
160 struct attribute *attr,
161 const char *buffer, size_t count)
163 struct dt_device *dt = container_of(kobj, struct dt_device,
165 struct osd_device *osd = osd_dt_dev(dt);
170 if (unlikely(!osd->od_mnt))
173 rc = kstrtobool(buffer, &val);
177 osd->od_read_cache = !!val;
180 LUSTRE_RW_ATTR(read_cache_enable);
182 static ssize_t writethrough_cache_enable_show(struct kobject *kobj,
183 struct attribute *attr,
186 struct dt_device *dt = container_of(kobj, struct dt_device,
188 struct osd_device *osd = osd_dt_dev(dt);
191 if (unlikely(!osd->od_mnt))
194 return sprintf(buf, "%u\n", osd->od_writethrough_cache);
197 static ssize_t writethrough_cache_enable_store(struct kobject *kobj,
198 struct attribute *attr,
202 struct dt_device *dt = container_of(kobj, struct dt_device,
204 struct osd_device *osd = osd_dt_dev(dt);
209 if (unlikely(!osd->od_mnt))
212 rc = kstrtobool(buffer, &val);
216 osd->od_writethrough_cache = !!val;
219 LUSTRE_RW_ATTR(writethrough_cache_enable);
221 static ssize_t fallocate_zero_blocks_show(struct kobject *kobj,
222 struct attribute *attr,
225 struct dt_device *dt = container_of(kobj, struct dt_device,
227 struct osd_device *osd = osd_dt_dev(dt);
230 if (unlikely(!osd->od_mnt))
233 return scnprintf(buf, PAGE_SIZE, "%d\n", osd->od_fallocate_zero_blocks);
237 * Set how fallocate() interacts with the backing filesystem:
238 * -1: fallocate is disabled and returns -EOPNOTSUPP
239 * 0: fallocate allocates unwritten extents (like ext4)
240 * 1: fallocate zeroes allocated extents on disk
242 static ssize_t fallocate_zero_blocks_store(struct kobject *kobj,
243 struct attribute *attr,
244 const char *buffer, size_t count)
246 struct dt_device *dt = container_of(kobj, struct dt_device,
248 struct osd_device *osd = osd_dt_dev(dt);
253 if (unlikely(!osd->od_mnt))
256 rc = kstrtol(buffer, 0, &val);
260 if (val < -1 || val > 1)
263 osd->od_fallocate_zero_blocks = val;
266 LUSTRE_RW_ATTR(fallocate_zero_blocks);
268 ssize_t force_sync_store(struct kobject *kobj, struct attribute *attr,
269 const char *buffer, size_t count)
271 struct dt_device *dt = container_of(kobj, struct dt_device,
273 struct osd_device *osd = osd_dt_dev(dt);
278 if (unlikely(!osd->od_mnt))
281 rc = lu_env_init(&env, LCT_LOCAL);
285 rc = dt_sync(&env, dt);
288 return rc == 0 ? count : rc;
290 LUSTRE_WO_ATTR(force_sync);
292 static ssize_t nonrotational_show(struct kobject *kobj, struct attribute *attr,
295 struct dt_device *dt = container_of(kobj, struct dt_device,
297 struct osd_device *osd = osd_dt_dev(dt);
300 if (unlikely(!osd->od_mnt))
303 return sprintf(buf, "%u\n", osd->od_nonrotational);
306 static ssize_t nonrotational_store(struct kobject *kobj,
307 struct attribute *attr, const char *buffer,
310 struct dt_device *dt = container_of(kobj, struct dt_device,
312 struct osd_device *osd = osd_dt_dev(dt);
317 if (unlikely(!osd->od_mnt))
320 rc = kstrtobool(buffer, &val);
324 osd->od_nonrotational = val;
327 LUSTRE_RW_ATTR(nonrotational);
329 static ssize_t pdo_show(struct kobject *kobj, struct attribute *attr,
332 return sprintf(buf, "%s\n", ldiskfs_pdo ? "ON" : "OFF");
335 static ssize_t pdo_store(struct kobject *kobj, struct attribute *attr,
336 const char *buffer, size_t count)
341 rc = kstrtobool(buffer, &pdo);
351 static ssize_t auto_scrub_show(struct kobject *kobj, struct attribute *attr,
354 struct dt_device *dt = container_of(kobj, struct dt_device,
356 struct osd_device *dev = osd_dt_dev(dt);
359 if (unlikely(!dev->od_mnt))
362 return scnprintf(buf, PAGE_SIZE, "%lld\n",
363 dev->od_scrub.os_scrub.os_auto_scrub_interval);
366 static ssize_t auto_scrub_store(struct kobject *kobj, struct attribute *attr,
367 const char *buffer, size_t count)
369 struct dt_device *dt = container_of(kobj, struct dt_device,
371 struct osd_device *dev = osd_dt_dev(dt);
376 if (unlikely(!dev->od_mnt))
379 rc = kstrtoll(buffer, 0, &val);
383 dev->od_scrub.os_scrub.os_auto_scrub_interval = val;
386 LUSTRE_RW_ATTR(auto_scrub);
388 static ssize_t full_scrub_ratio_show(struct kobject *kobj,
389 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 sprintf(buf, "%llu\n", dev->od_full_scrub_ratio);
403 static ssize_t full_scrub_ratio_store(struct kobject *kobj,
404 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);
424 dev->od_full_scrub_ratio = val;
427 LUSTRE_RW_ATTR(full_scrub_ratio);
429 static ssize_t full_scrub_threshold_rate_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 (bad OI mappings/minute)\n",
442 dev->od_full_scrub_threshold_rate);
445 static ssize_t full_scrub_threshold_rate_store(struct kobject *kobj,
446 struct attribute *attr,
447 const char *buffer, size_t count)
449 struct dt_device *dt = container_of(kobj, struct dt_device,
451 struct osd_device *dev = osd_dt_dev(dt);
456 if (unlikely(!dev->od_mnt))
459 rc = kstrtoull(buffer, 0, &val);
463 dev->od_full_scrub_threshold_rate = val;
466 LUSTRE_RW_ATTR(full_scrub_threshold_rate);
468 static ssize_t extent_bytes_allocation_show(struct kobject *kobj,
469 struct attribute *attr, char *buf)
471 struct dt_device *dt = container_of(kobj, struct dt_device,
473 struct osd_device *dev = osd_dt_dev(dt);
475 unsigned int min = (unsigned int)(~0), cur;
477 for_each_online_cpu(i) {
478 cur = *per_cpu_ptr(dev->od_extent_bytes_percpu, i);
482 return snprintf(buf, PAGE_SIZE, "%u\n", min);
484 LUSTRE_RO_ATTR(extent_bytes_allocation);
486 static int ldiskfs_osd_oi_scrub_seq_show(struct seq_file *m, void *data)
488 struct osd_device *dev = osd_dt_dev((struct dt_device *)m->private);
490 LASSERT(dev != NULL);
491 if (unlikely(dev->od_mnt == NULL))
494 osd_scrub_dump(m, dev);
498 LDEBUGFS_SEQ_FOPS_RO(ldiskfs_osd_oi_scrub);
500 static int ldiskfs_osd_readcache_seq_show(struct seq_file *m, void *data)
502 struct osd_device *osd = osd_dt_dev((struct dt_device *)m->private);
504 LASSERT(osd != NULL);
505 if (unlikely(osd->od_mnt == NULL))
508 seq_printf(m, "%llu\n", osd->od_readcache_max_filesize);
513 ldiskfs_osd_readcache_seq_write(struct file *file, const char __user *buffer,
514 size_t count, loff_t *off)
516 struct seq_file *m = file->private_data;
517 struct dt_device *dt = m->private;
518 struct osd_device *osd = osd_dt_dev(dt);
519 char kernbuf[22] = "";
523 LASSERT(osd != NULL);
524 if (unlikely(osd->od_mnt == NULL))
527 if (count >= sizeof(kernbuf))
530 if (copy_from_user(kernbuf, buffer, count))
534 rc = sysfs_memparse(kernbuf, count, &val, "B");
538 osd->od_readcache_max_filesize = val > OSD_MAX_CACHE_SIZE ?
539 OSD_MAX_CACHE_SIZE : val;
543 LDEBUGFS_SEQ_FOPS(ldiskfs_osd_readcache);
545 static int ldiskfs_osd_readcache_max_io_seq_show(struct seq_file *m, void *data)
547 struct osd_device *osd = osd_dt_dev((struct dt_device *)m->private);
549 LASSERT(osd != NULL);
550 if (unlikely(osd->od_mnt == NULL))
553 seq_printf(m, "%lu\n", osd->od_readcache_max_iosize >> 20);
558 ldiskfs_osd_readcache_max_io_seq_write(struct file *file,
559 const char __user *buffer,
560 size_t count, loff_t *off)
562 struct seq_file *m = file->private_data;
563 struct dt_device *dt = m->private;
564 struct osd_device *osd = osd_dt_dev(dt);
565 char kernbuf[22] = "";
569 LASSERT(osd != NULL);
570 if (unlikely(osd->od_mnt == NULL))
573 if (count >= sizeof(kernbuf))
576 if (copy_from_user(kernbuf, buffer, count))
580 rc = sysfs_memparse(kernbuf, count, &val, "MiB");
584 if (val > PTLRPC_MAX_BRW_SIZE)
586 osd->od_readcache_max_iosize = val;
590 LDEBUGFS_SEQ_FOPS(ldiskfs_osd_readcache_max_io);
592 static int ldiskfs_osd_writethrough_max_io_seq_show(struct seq_file *m,
595 struct osd_device *osd = osd_dt_dev((struct dt_device *)m->private);
597 LASSERT(osd != NULL);
598 if (unlikely(osd->od_mnt == NULL))
601 seq_printf(m, "%lu\n", osd->od_writethrough_max_iosize >> 20);
606 ldiskfs_osd_writethrough_max_io_seq_write(struct file *file,
607 const char __user *buffer,
608 size_t count, loff_t *off)
610 struct seq_file *m = file->private_data;
611 struct dt_device *dt = m->private;
612 struct osd_device *osd = osd_dt_dev(dt);
613 char kernbuf[22] = "";
617 LASSERT(osd != NULL);
618 if (unlikely(osd->od_mnt == NULL))
621 if (count >= sizeof(kernbuf))
624 if (copy_from_user(kernbuf, buffer, count))
628 rc = sysfs_memparse(kernbuf, count, &val, "MiB");
632 if (val > PTLRPC_MAX_BRW_SIZE)
634 osd->od_writethrough_max_iosize = val;
638 LDEBUGFS_SEQ_FOPS(ldiskfs_osd_writethrough_max_io);
640 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 52, 0)
641 static ssize_t index_in_idif_show(struct kobject *kobj, struct attribute *attr,
644 struct dt_device *dt = container_of(kobj, struct dt_device,
646 struct osd_device *dev = osd_dt_dev(dt);
649 if (unlikely(!dev->od_mnt))
652 return sprintf(buf, "%d\n", (int)(dev->od_index_in_idif));
655 static ssize_t index_in_idif_store(struct kobject *kobj,
656 struct attribute *attr,
657 const char *buffer, size_t count)
659 struct dt_device *dt = container_of(kobj, struct dt_device,
661 struct osd_device *dev = osd_dt_dev(dt);
662 struct lu_target *tgt;
668 if (unlikely(!dev->od_mnt))
671 rc = kstrtobool(buffer, &val);
675 if (dev->od_index_in_idif) {
679 LCONSOLE_WARN("%s: OST-index in IDIF has been enabled, "
680 "it cannot be reverted back.\n", osd_name(dev));
687 rc = lu_env_init(&env, LCT_DT_THREAD);
691 tgt = dev->od_dt_dev.dd_lu_dev.ld_site->ls_tgt;
692 tgt->lut_lsd.lsd_feature_rocompat |= OBD_ROCOMPAT_IDX_IN_IDIF;
693 rc = tgt_server_data_update(&env, tgt, 1);
698 LCONSOLE_INFO("%s: enable OST-index in IDIF successfully, "
699 "it cannot be reverted back.\n", osd_name(dev));
701 dev->od_index_in_idif = 1;
704 LUSTRE_RW_ATTR(index_in_idif);
706 int osd_register_proc_index_in_idif(struct osd_device *osd)
708 struct dt_device *dt = &osd->od_dt_dev;
710 return sysfs_create_file(&dt->dd_kobj, &lustre_attr_index_in_idif.attr);
714 static ssize_t index_backup_show(struct kobject *kobj, struct attribute *attr,
717 struct dt_device *dt = container_of(kobj, struct dt_device,
719 struct osd_device *dev = osd_dt_dev(dt);
722 if (unlikely(!dev->od_mnt))
725 return sprintf(buf, "%d\n", dev->od_index_backup_policy);
728 ssize_t index_backup_store(struct kobject *kobj, struct attribute *attr,
729 const char *buffer, size_t count)
731 struct dt_device *dt = container_of(kobj, struct dt_device,
733 struct osd_device *dev = osd_dt_dev(dt);
738 if (unlikely(!dev->od_mnt))
741 rc = kstrtoint(buffer, 0, &val);
745 dev->od_index_backup_policy = val;
748 LUSTRE_RW_ATTR(index_backup);
750 struct ldebugfs_vars ldebugfs_osd_obd_vars[] = {
751 { .name = "oi_scrub",
752 .fops = &ldiskfs_osd_oi_scrub_fops },
753 { .name = "readcache_max_filesize",
754 .fops = &ldiskfs_osd_readcache_fops },
755 { .name = "readcache_max_io_mb",
756 .fops = &ldiskfs_osd_readcache_max_io_fops },
757 { .name = "writethrough_max_io_mb",
758 .fops = &ldiskfs_osd_writethrough_max_io_fops },
762 static struct attribute *ldiskfs_attrs[] = {
763 &lustre_attr_read_cache_enable.attr,
764 &lustre_attr_writethrough_cache_enable.attr,
765 &lustre_attr_fstype.attr,
766 &lustre_attr_mntdev.attr,
767 &lustre_attr_fallocate_zero_blocks.attr,
768 &lustre_attr_force_sync.attr,
769 &lustre_attr_nonrotational.attr,
770 &lustre_attr_index_backup.attr,
771 &lustre_attr_auto_scrub.attr,
772 &lustre_attr_pdo.attr,
773 &lustre_attr_full_scrub_ratio.attr,
774 &lustre_attr_full_scrub_threshold_rate.attr,
775 &lustre_attr_extent_bytes_allocation.attr,
779 int osd_procfs_init(struct osd_device *osd, const char *name)
781 struct obd_type *type;
786 /* at the moment there is no linkage between lu_type
787 * and obd_type, so we lookup obd_type this way
789 type = class_search_type(LUSTRE_OSD_LDISKFS_NAME);
794 CDEBUG(D_CONFIG, "%s: register osd-ldiskfs tunable parameters\n", name);
796 /* put reference taken by class_search_type */
797 kobject_put(&type->typ_kobj);
799 osd->od_dt_dev.dd_ktype.default_attrs = ldiskfs_attrs;
800 rc = dt_tunables_init(&osd->od_dt_dev, type, name,
801 ldebugfs_osd_obd_vars);
803 CERROR("%s: cannot setup sysfs / debugfs entry: %d\n",
808 if (osd->od_proc_entry)
811 /* Find the type procroot and add the proc entry for this device */
812 osd->od_proc_entry = lprocfs_register(name, type->typ_procroot,
813 NULL, &osd->od_dt_dev);
814 if (IS_ERR(osd->od_proc_entry)) {
815 rc = PTR_ERR(osd->od_proc_entry);
816 CERROR("Error %d setting up lprocfs for %s\n",
818 osd->od_proc_entry = NULL;
822 rc = osd_stats_init(osd);
827 osd_procfs_fini(osd);
831 int osd_procfs_fini(struct osd_device *osd)
833 lprocfs_fini_brw_stats(&osd->od_brw_stats);
836 lprocfs_free_stats(&osd->od_stats);
838 if (osd->od_proc_entry)
839 lprocfs_remove(&osd->od_proc_entry);
841 return dt_tunables_fini(&osd->od_dt_dev);