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 enable_projid_xattr_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 snprintf(buf, PAGE_SIZE, "%u\n", osd->od_enable_projid_xattr);
236 static ssize_t enable_projid_xattr_store(struct kobject *kobj,
237 struct attribute *attr,
241 struct dt_device *dt = container_of(kobj, struct dt_device,
243 struct osd_device *osd = osd_dt_dev(dt);
248 if (unlikely(!osd->od_mnt))
251 rc = kstrtobool(buffer, &val);
255 osd->od_enable_projid_xattr = !!val;
258 LUSTRE_RW_ATTR(enable_projid_xattr);
260 static ssize_t fallocate_zero_blocks_show(struct kobject *kobj,
261 struct attribute *attr,
264 struct dt_device *dt = container_of(kobj, struct dt_device,
266 struct osd_device *osd = osd_dt_dev(dt);
269 if (unlikely(!osd->od_mnt))
272 return scnprintf(buf, PAGE_SIZE, "%d\n", osd->od_fallocate_zero_blocks);
276 * Set how fallocate() interacts with the backing filesystem:
277 * -1: fallocate is disabled and returns -EOPNOTSUPP
278 * 0: fallocate allocates unwritten extents (like ext4)
279 * 1: fallocate zeroes allocated extents on disk
281 static ssize_t fallocate_zero_blocks_store(struct kobject *kobj,
282 struct attribute *attr,
283 const char *buffer, size_t count)
285 struct dt_device *dt = container_of(kobj, struct dt_device,
287 struct osd_device *osd = osd_dt_dev(dt);
292 if (unlikely(!osd->od_mnt))
295 rc = kstrtol(buffer, 0, &val);
299 if (val < -1 || val > 1)
302 osd->od_fallocate_zero_blocks = val;
305 LUSTRE_RW_ATTR(fallocate_zero_blocks);
307 ssize_t force_sync_store(struct kobject *kobj, struct attribute *attr,
308 const char *buffer, size_t count)
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 = lu_env_init(&env, LCT_LOCAL);
324 rc = dt_sync(&env, dt);
327 return rc == 0 ? count : rc;
329 LUSTRE_WO_ATTR(force_sync);
331 static ssize_t nonrotational_show(struct kobject *kobj, struct attribute *attr,
334 struct dt_device *dt = container_of(kobj, struct dt_device,
336 struct osd_device *osd = osd_dt_dev(dt);
339 if (unlikely(!osd->od_mnt))
342 return sprintf(buf, "%u\n", osd->od_nonrotational);
345 static ssize_t nonrotational_store(struct kobject *kobj,
346 struct attribute *attr, const char *buffer,
349 struct dt_device *dt = container_of(kobj, struct dt_device,
351 struct osd_device *osd = osd_dt_dev(dt);
356 if (unlikely(!osd->od_mnt))
359 rc = kstrtobool(buffer, &val);
363 osd->od_nonrotational = val;
366 LUSTRE_RW_ATTR(nonrotational);
368 static ssize_t pdo_show(struct kobject *kobj, struct attribute *attr,
371 return sprintf(buf, "%s\n", ldiskfs_pdo ? "ON" : "OFF");
374 static ssize_t pdo_store(struct kobject *kobj, struct attribute *attr,
375 const char *buffer, size_t count)
380 rc = kstrtobool(buffer, &pdo);
390 static ssize_t auto_scrub_show(struct kobject *kobj, struct attribute *attr,
393 struct dt_device *dt = container_of(kobj, struct dt_device,
395 struct osd_device *dev = osd_dt_dev(dt);
398 if (unlikely(!dev->od_mnt))
401 return scnprintf(buf, PAGE_SIZE, "%lld\n",
402 dev->od_scrub.os_scrub.os_auto_scrub_interval);
405 static ssize_t auto_scrub_store(struct kobject *kobj, struct attribute *attr,
406 const char *buffer, size_t count)
408 struct dt_device *dt = container_of(kobj, struct dt_device,
410 struct osd_device *dev = osd_dt_dev(dt);
415 if (unlikely(!dev->od_mnt))
418 rc = kstrtoll(buffer, 0, &val);
422 dev->od_scrub.os_scrub.os_auto_scrub_interval = val;
425 LUSTRE_RW_ATTR(auto_scrub);
427 static ssize_t full_scrub_ratio_show(struct kobject *kobj,
428 struct attribute *attr,
431 struct dt_device *dt = container_of(kobj, struct dt_device,
433 struct osd_device *dev = osd_dt_dev(dt);
436 if (unlikely(!dev->od_mnt))
439 return sprintf(buf, "%llu\n", dev->od_full_scrub_ratio);
442 static ssize_t full_scrub_ratio_store(struct kobject *kobj,
443 struct attribute *attr,
444 const char *buffer, size_t count)
446 struct dt_device *dt = container_of(kobj, struct dt_device,
448 struct osd_device *dev = osd_dt_dev(dt);
453 if (unlikely(!dev->od_mnt))
456 rc = kstrtoll(buffer, 0, &val);
463 dev->od_full_scrub_ratio = val;
466 LUSTRE_RW_ATTR(full_scrub_ratio);
468 static ssize_t full_scrub_threshold_rate_show(struct kobject *kobj,
469 struct attribute *attr,
472 struct dt_device *dt = container_of(kobj, struct dt_device,
474 struct osd_device *dev = osd_dt_dev(dt);
477 if (unlikely(!dev->od_mnt))
480 return sprintf(buf, "%llu (bad OI mappings/minute)\n",
481 dev->od_full_scrub_threshold_rate);
484 static ssize_t full_scrub_threshold_rate_store(struct kobject *kobj,
485 struct attribute *attr,
486 const char *buffer, size_t count)
488 struct dt_device *dt = container_of(kobj, struct dt_device,
490 struct osd_device *dev = osd_dt_dev(dt);
495 if (unlikely(!dev->od_mnt))
498 rc = kstrtoull(buffer, 0, &val);
502 dev->od_full_scrub_threshold_rate = val;
505 LUSTRE_RW_ATTR(full_scrub_threshold_rate);
507 static ssize_t extent_bytes_allocation_show(struct kobject *kobj,
508 struct attribute *attr, char *buf)
510 struct dt_device *dt = container_of(kobj, struct dt_device,
512 struct osd_device *dev = osd_dt_dev(dt);
514 unsigned int min = (unsigned int)(~0), cur;
516 for_each_online_cpu(i) {
517 cur = *per_cpu_ptr(dev->od_extent_bytes_percpu, i);
521 return snprintf(buf, PAGE_SIZE, "%u\n", min);
523 LUSTRE_RO_ATTR(extent_bytes_allocation);
525 static int ldiskfs_osd_oi_scrub_seq_show(struct seq_file *m, void *data)
527 struct osd_device *dev = osd_dt_dev((struct dt_device *)m->private);
529 LASSERT(dev != NULL);
530 if (unlikely(dev->od_mnt == NULL))
533 osd_scrub_dump(m, dev);
537 LDEBUGFS_SEQ_FOPS_RO(ldiskfs_osd_oi_scrub);
539 static int ldiskfs_osd_readcache_seq_show(struct seq_file *m, void *data)
541 struct osd_device *osd = osd_dt_dev((struct dt_device *)m->private);
543 LASSERT(osd != NULL);
544 if (unlikely(osd->od_mnt == NULL))
547 seq_printf(m, "%llu\n", osd->od_readcache_max_filesize);
552 ldiskfs_osd_readcache_seq_write(struct file *file, const char __user *buffer,
553 size_t count, loff_t *off)
555 struct seq_file *m = file->private_data;
556 struct dt_device *dt = m->private;
557 struct osd_device *osd = osd_dt_dev(dt);
558 char kernbuf[22] = "";
562 LASSERT(osd != NULL);
563 if (unlikely(osd->od_mnt == NULL))
566 if (count >= sizeof(kernbuf))
569 if (copy_from_user(kernbuf, buffer, count))
573 rc = sysfs_memparse(kernbuf, count, &val, "B");
577 osd->od_readcache_max_filesize = val > OSD_MAX_CACHE_SIZE ?
578 OSD_MAX_CACHE_SIZE : val;
582 LDEBUGFS_SEQ_FOPS(ldiskfs_osd_readcache);
584 static int ldiskfs_osd_readcache_max_io_seq_show(struct seq_file *m, void *data)
586 struct osd_device *osd = osd_dt_dev((struct dt_device *)m->private);
588 LASSERT(osd != NULL);
589 if (unlikely(osd->od_mnt == NULL))
592 seq_printf(m, "%lu\n", osd->od_readcache_max_iosize >> 20);
597 ldiskfs_osd_readcache_max_io_seq_write(struct file *file,
598 const char __user *buffer,
599 size_t count, loff_t *off)
601 struct seq_file *m = file->private_data;
602 struct dt_device *dt = m->private;
603 struct osd_device *osd = osd_dt_dev(dt);
604 char kernbuf[22] = "";
608 LASSERT(osd != NULL);
609 if (unlikely(osd->od_mnt == NULL))
612 if (count >= sizeof(kernbuf))
615 if (copy_from_user(kernbuf, buffer, count))
619 rc = sysfs_memparse(kernbuf, count, &val, "MiB");
623 if (val > PTLRPC_MAX_BRW_SIZE)
625 osd->od_readcache_max_iosize = val;
629 LDEBUGFS_SEQ_FOPS(ldiskfs_osd_readcache_max_io);
631 static int ldiskfs_osd_writethrough_max_io_seq_show(struct seq_file *m,
634 struct osd_device *osd = osd_dt_dev((struct dt_device *)m->private);
636 LASSERT(osd != NULL);
637 if (unlikely(osd->od_mnt == NULL))
640 seq_printf(m, "%lu\n", osd->od_writethrough_max_iosize >> 20);
645 ldiskfs_osd_writethrough_max_io_seq_write(struct file *file,
646 const char __user *buffer,
647 size_t count, loff_t *off)
649 struct seq_file *m = file->private_data;
650 struct dt_device *dt = m->private;
651 struct osd_device *osd = osd_dt_dev(dt);
652 char kernbuf[22] = "";
656 LASSERT(osd != NULL);
657 if (unlikely(osd->od_mnt == NULL))
660 if (count >= sizeof(kernbuf))
663 if (copy_from_user(kernbuf, buffer, count))
667 rc = sysfs_memparse(kernbuf, count, &val, "MiB");
671 if (val > PTLRPC_MAX_BRW_SIZE)
673 osd->od_writethrough_max_iosize = val;
677 LDEBUGFS_SEQ_FOPS(ldiskfs_osd_writethrough_max_io);
679 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 52, 0)
680 static ssize_t index_in_idif_show(struct kobject *kobj, struct attribute *attr,
683 struct dt_device *dt = container_of(kobj, struct dt_device,
685 struct osd_device *dev = osd_dt_dev(dt);
688 if (unlikely(!dev->od_mnt))
691 return sprintf(buf, "%d\n", (int)(dev->od_index_in_idif));
694 static ssize_t index_in_idif_store(struct kobject *kobj,
695 struct attribute *attr,
696 const char *buffer, size_t count)
698 struct dt_device *dt = container_of(kobj, struct dt_device,
700 struct osd_device *dev = osd_dt_dev(dt);
701 struct lu_target *tgt;
707 if (unlikely(!dev->od_mnt))
710 rc = kstrtobool(buffer, &val);
714 if (dev->od_index_in_idif) {
718 LCONSOLE_WARN("%s: OST-index in IDIF has been enabled, "
719 "it cannot be reverted back.\n", osd_name(dev));
726 rc = lu_env_init(&env, LCT_DT_THREAD);
730 tgt = dev->od_dt_dev.dd_lu_dev.ld_site->ls_tgt;
731 tgt->lut_lsd.lsd_feature_rocompat |= OBD_ROCOMPAT_IDX_IN_IDIF;
732 rc = tgt_server_data_update(&env, tgt, 1);
737 LCONSOLE_INFO("%s: enable OST-index in IDIF successfully, "
738 "it cannot be reverted back.\n", osd_name(dev));
740 dev->od_index_in_idif = 1;
743 LUSTRE_RW_ATTR(index_in_idif);
745 int osd_register_proc_index_in_idif(struct osd_device *osd)
747 struct dt_device *dt = &osd->od_dt_dev;
749 return sysfs_create_file(&dt->dd_kobj, &lustre_attr_index_in_idif.attr);
753 static ssize_t index_backup_show(struct kobject *kobj, struct attribute *attr,
756 struct dt_device *dt = container_of(kobj, struct dt_device,
758 struct osd_device *dev = osd_dt_dev(dt);
761 if (unlikely(!dev->od_mnt))
764 return sprintf(buf, "%d\n", dev->od_index_backup_policy);
767 ssize_t index_backup_store(struct kobject *kobj, struct attribute *attr,
768 const char *buffer, size_t count)
770 struct dt_device *dt = container_of(kobj, struct dt_device,
772 struct osd_device *dev = osd_dt_dev(dt);
777 if (unlikely(!dev->od_mnt))
780 rc = kstrtoint(buffer, 0, &val);
784 dev->od_index_backup_policy = val;
787 LUSTRE_RW_ATTR(index_backup);
789 struct ldebugfs_vars ldebugfs_osd_obd_vars[] = {
790 { .name = "oi_scrub",
791 .fops = &ldiskfs_osd_oi_scrub_fops },
792 { .name = "readcache_max_filesize",
793 .fops = &ldiskfs_osd_readcache_fops },
794 { .name = "readcache_max_io_mb",
795 .fops = &ldiskfs_osd_readcache_max_io_fops },
796 { .name = "writethrough_max_io_mb",
797 .fops = &ldiskfs_osd_writethrough_max_io_fops },
801 static struct attribute *ldiskfs_attrs[] = {
802 &lustre_attr_read_cache_enable.attr,
803 &lustre_attr_writethrough_cache_enable.attr,
804 &lustre_attr_enable_projid_xattr.attr,
805 &lustre_attr_fstype.attr,
806 &lustre_attr_mntdev.attr,
807 &lustre_attr_fallocate_zero_blocks.attr,
808 &lustre_attr_force_sync.attr,
809 &lustre_attr_nonrotational.attr,
810 &lustre_attr_index_backup.attr,
811 &lustre_attr_auto_scrub.attr,
812 &lustre_attr_pdo.attr,
813 &lustre_attr_full_scrub_ratio.attr,
814 &lustre_attr_full_scrub_threshold_rate.attr,
815 &lustre_attr_extent_bytes_allocation.attr,
819 int osd_procfs_init(struct osd_device *osd, const char *name)
821 struct obd_type *type;
826 /* at the moment there is no linkage between lu_type
827 * and obd_type, so we lookup obd_type this way
829 type = class_search_type(LUSTRE_OSD_LDISKFS_NAME);
834 CDEBUG(D_CONFIG, "%s: register osd-ldiskfs tunable parameters\n", name);
836 /* put reference taken by class_search_type */
837 kobject_put(&type->typ_kobj);
839 osd->od_dt_dev.dd_ktype.default_attrs = ldiskfs_attrs;
840 rc = dt_tunables_init(&osd->od_dt_dev, type, name,
841 ldebugfs_osd_obd_vars);
843 CERROR("%s: cannot setup sysfs / debugfs entry: %d\n",
848 if (osd->od_proc_entry)
851 /* Find the type procroot and add the proc entry for this device */
852 osd->od_proc_entry = lprocfs_register(name, type->typ_procroot,
853 NULL, &osd->od_dt_dev);
854 if (IS_ERR(osd->od_proc_entry)) {
855 rc = PTR_ERR(osd->od_proc_entry);
856 CERROR("Error %d setting up lprocfs for %s\n",
858 osd->od_proc_entry = NULL;
862 rc = osd_stats_init(osd);
867 osd_procfs_fini(osd);
871 int osd_procfs_fini(struct osd_device *osd)
873 lprocfs_fini_brw_stats(&osd->od_brw_stats);
876 lprocfs_free_stats(&osd->od_stats);
878 if (osd->od_proc_entry)
879 lprocfs_remove(&osd->od_proc_entry);
881 return dt_tunables_fini(&osd->od_dt_dev);