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(&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(&bs->bs_hist[BRW_R_DISCONT_PAGES+rw], discont_pages);
75 lprocfs_oh_tally(&bs->bs_hist[BRW_R_DISCONT_BLOCKS+rw], discont_blocks);
78 static int osd_stats_init(struct osd_device *osd)
83 osd->od_stats = lprocfs_alloc_stats(LPROC_OSD_LAST, 0);
85 lprocfs_counter_init(osd->od_stats, LPROC_OSD_GET_PAGE,
86 LPROCFS_CNTR_AVGMINMAX|LPROCFS_CNTR_STDDEV,
88 lprocfs_counter_init(osd->od_stats, LPROC_OSD_NO_PAGE,
89 LPROCFS_CNTR_AVGMINMAX,
90 "get_page_failures", "num");
91 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_ACCESS,
92 LPROCFS_CNTR_AVGMINMAX,
93 "cache_access", "pages");
94 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_HIT,
95 LPROCFS_CNTR_AVGMINMAX,
96 "cache_hit", "pages");
97 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_MISS,
98 LPROCFS_CNTR_AVGMINMAX,
99 "cache_miss", "pages");
100 #if OSD_THANDLE_STATS
101 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_STARTING,
102 LPROCFS_CNTR_AVGMINMAX,
103 "thandle starting", "usec");
104 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_OPEN,
105 LPROCFS_CNTR_AVGMINMAX,
106 "thandle open", "usec");
107 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_CLOSING,
108 LPROCFS_CNTR_AVGMINMAX,
109 "thandle closing", "usec");
114 ldebugfs_register_osd_stats(osd->od_dt_dev.dd_debugfs_entry,
115 &osd->od_brw_stats, osd->od_stats);
120 static ssize_t fstype_show(struct kobject *kobj, struct attribute *attr,
123 return sprintf(buf, "ldiskfs\n");
125 LUSTRE_RO_ATTR(fstype);
127 static ssize_t mntdev_show(struct kobject *kobj, struct attribute *attr,
130 struct dt_device *dt = container_of(kobj, struct dt_device,
132 struct osd_device *osd = osd_dt_dev(dt);
135 if (unlikely(!osd->od_mnt))
138 return sprintf(buf, "%s\n", osd->od_mntdev);
140 LUSTRE_RO_ATTR(mntdev);
142 static ssize_t read_cache_enable_show(struct kobject *kobj,
143 struct attribute *attr,
146 struct dt_device *dt = container_of(kobj, struct dt_device,
148 struct osd_device *osd = osd_dt_dev(dt);
151 if (unlikely(!osd->od_mnt))
154 return sprintf(buf, "%u\n", osd->od_read_cache);
157 static ssize_t read_cache_enable_store(struct kobject *kobj,
158 struct attribute *attr,
159 const char *buffer, size_t count)
161 struct dt_device *dt = container_of(kobj, struct dt_device,
163 struct osd_device *osd = osd_dt_dev(dt);
168 if (unlikely(!osd->od_mnt))
171 rc = kstrtobool(buffer, &val);
175 osd->od_read_cache = !!val;
178 LUSTRE_RW_ATTR(read_cache_enable);
180 static ssize_t writethrough_cache_enable_show(struct kobject *kobj,
181 struct attribute *attr,
184 struct dt_device *dt = container_of(kobj, struct dt_device,
186 struct osd_device *osd = osd_dt_dev(dt);
189 if (unlikely(!osd->od_mnt))
192 return sprintf(buf, "%u\n", osd->od_writethrough_cache);
195 static ssize_t writethrough_cache_enable_store(struct kobject *kobj,
196 struct attribute *attr,
200 struct dt_device *dt = container_of(kobj, struct dt_device,
202 struct osd_device *osd = osd_dt_dev(dt);
207 if (unlikely(!osd->od_mnt))
210 rc = kstrtobool(buffer, &val);
214 osd->od_writethrough_cache = !!val;
217 LUSTRE_RW_ATTR(writethrough_cache_enable);
219 static ssize_t fallocate_zero_blocks_show(struct kobject *kobj,
220 struct attribute *attr,
223 struct dt_device *dt = container_of(kobj, struct dt_device,
225 struct osd_device *osd = osd_dt_dev(dt);
228 if (unlikely(!osd->od_mnt))
231 return scnprintf(buf, PAGE_SIZE, "%d\n", osd->od_fallocate_zero_blocks);
235 * Set how fallocate() interacts with the backing filesystem:
236 * -1: fallocate is disabled and returns -EOPNOTSUPP
237 * 0: fallocate allocates unwritten extents (like ext4)
238 * 1: fallocate zeroes allocated extents on disk
240 static ssize_t fallocate_zero_blocks_store(struct kobject *kobj,
241 struct attribute *attr,
242 const char *buffer, size_t count)
244 struct dt_device *dt = container_of(kobj, struct dt_device,
246 struct osd_device *osd = osd_dt_dev(dt);
251 if (unlikely(!osd->od_mnt))
254 rc = kstrtol(buffer, 0, &val);
258 if (val < -1 || val > 1)
261 osd->od_fallocate_zero_blocks = val;
264 LUSTRE_RW_ATTR(fallocate_zero_blocks);
266 ssize_t force_sync_store(struct kobject *kobj, struct attribute *attr,
267 const char *buffer, size_t count)
269 struct dt_device *dt = container_of(kobj, struct dt_device,
271 struct osd_device *osd = osd_dt_dev(dt);
276 if (unlikely(!osd->od_mnt))
279 rc = lu_env_init(&env, LCT_LOCAL);
283 rc = dt_sync(&env, dt);
286 return rc == 0 ? count : rc;
288 LUSTRE_WO_ATTR(force_sync);
290 static ssize_t nonrotational_show(struct kobject *kobj, struct attribute *attr,
293 struct dt_device *dt = container_of(kobj, struct dt_device,
295 struct osd_device *osd = osd_dt_dev(dt);
298 if (unlikely(!osd->od_mnt))
301 return sprintf(buf, "%u\n", osd->od_nonrotational);
304 static ssize_t nonrotational_store(struct kobject *kobj,
305 struct attribute *attr, const char *buffer,
308 struct dt_device *dt = container_of(kobj, struct dt_device,
310 struct osd_device *osd = osd_dt_dev(dt);
315 if (unlikely(!osd->od_mnt))
318 rc = kstrtobool(buffer, &val);
322 osd->od_nonrotational = val;
325 LUSTRE_RW_ATTR(nonrotational);
327 static ssize_t pdo_show(struct kobject *kobj, struct attribute *attr,
330 return sprintf(buf, "%s\n", ldiskfs_pdo ? "ON" : "OFF");
333 static ssize_t pdo_store(struct kobject *kobj, struct attribute *attr,
334 const char *buffer, size_t count)
339 rc = kstrtobool(buffer, &pdo);
349 static ssize_t auto_scrub_show(struct kobject *kobj, struct attribute *attr,
352 struct dt_device *dt = container_of(kobj, struct dt_device,
354 struct osd_device *dev = osd_dt_dev(dt);
357 if (unlikely(!dev->od_mnt))
360 return scnprintf(buf, PAGE_SIZE, "%lld\n",
361 dev->od_scrub.os_scrub.os_auto_scrub_interval);
364 static ssize_t auto_scrub_store(struct kobject *kobj, struct attribute *attr,
365 const char *buffer, size_t count)
367 struct dt_device *dt = container_of(kobj, struct dt_device,
369 struct osd_device *dev = osd_dt_dev(dt);
374 if (unlikely(!dev->od_mnt))
377 rc = kstrtoll(buffer, 0, &val);
381 dev->od_scrub.os_scrub.os_auto_scrub_interval = val;
384 LUSTRE_RW_ATTR(auto_scrub);
386 static ssize_t full_scrub_ratio_show(struct kobject *kobj,
387 struct attribute *attr,
390 struct dt_device *dt = container_of(kobj, struct dt_device,
392 struct osd_device *dev = osd_dt_dev(dt);
395 if (unlikely(!dev->od_mnt))
398 return sprintf(buf, "%llu\n", dev->od_full_scrub_ratio);
401 static ssize_t full_scrub_ratio_store(struct kobject *kobj,
402 struct attribute *attr,
403 const char *buffer, size_t count)
405 struct dt_device *dt = container_of(kobj, struct dt_device,
407 struct osd_device *dev = osd_dt_dev(dt);
412 if (unlikely(!dev->od_mnt))
415 rc = kstrtoll(buffer, 0, &val);
422 dev->od_full_scrub_ratio = val;
425 LUSTRE_RW_ATTR(full_scrub_ratio);
427 static ssize_t full_scrub_threshold_rate_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 (bad OI mappings/minute)\n",
440 dev->od_full_scrub_threshold_rate);
443 static ssize_t full_scrub_threshold_rate_store(struct kobject *kobj,
444 struct attribute *attr,
445 const char *buffer, size_t count)
447 struct dt_device *dt = container_of(kobj, struct dt_device,
449 struct osd_device *dev = osd_dt_dev(dt);
454 if (unlikely(!dev->od_mnt))
457 rc = kstrtoull(buffer, 0, &val);
461 dev->od_full_scrub_threshold_rate = val;
464 LUSTRE_RW_ATTR(full_scrub_threshold_rate);
466 static ssize_t extent_bytes_allocation_show(struct kobject *kobj,
467 struct attribute *attr, char *buf)
469 struct dt_device *dt = container_of(kobj, struct dt_device,
471 struct osd_device *dev = osd_dt_dev(dt);
473 unsigned int min = (unsigned int)(~0), cur;
475 for_each_online_cpu(i) {
476 cur = *per_cpu_ptr(dev->od_extent_bytes_percpu, i);
480 return snprintf(buf, PAGE_SIZE, "%u\n", min);
482 LUSTRE_RO_ATTR(extent_bytes_allocation);
484 static int ldiskfs_osd_oi_scrub_seq_show(struct seq_file *m, void *data)
486 struct osd_device *dev = osd_dt_dev((struct dt_device *)m->private);
488 LASSERT(dev != NULL);
489 if (unlikely(dev->od_mnt == NULL))
492 osd_scrub_dump(m, dev);
496 LDEBUGFS_SEQ_FOPS_RO(ldiskfs_osd_oi_scrub);
498 static int ldiskfs_osd_readcache_seq_show(struct seq_file *m, void *data)
500 struct osd_device *osd = osd_dt_dev((struct dt_device *)m->private);
502 LASSERT(osd != NULL);
503 if (unlikely(osd->od_mnt == NULL))
506 seq_printf(m, "%llu\n", osd->od_readcache_max_filesize);
511 ldiskfs_osd_readcache_seq_write(struct file *file, const char __user *buffer,
512 size_t count, loff_t *off)
514 struct seq_file *m = file->private_data;
515 struct dt_device *dt = m->private;
516 struct osd_device *osd = osd_dt_dev(dt);
517 char kernbuf[22] = "";
521 LASSERT(osd != NULL);
522 if (unlikely(osd->od_mnt == NULL))
525 if (count >= sizeof(kernbuf))
528 if (copy_from_user(kernbuf, buffer, count))
532 rc = sysfs_memparse(kernbuf, count, &val, "B");
536 osd->od_readcache_max_filesize = val > OSD_MAX_CACHE_SIZE ?
537 OSD_MAX_CACHE_SIZE : val;
541 LDEBUGFS_SEQ_FOPS(ldiskfs_osd_readcache);
543 static int ldiskfs_osd_readcache_max_io_seq_show(struct seq_file *m, void *data)
545 struct osd_device *osd = osd_dt_dev((struct dt_device *)m->private);
547 LASSERT(osd != NULL);
548 if (unlikely(osd->od_mnt == NULL))
551 seq_printf(m, "%lu\n", osd->od_readcache_max_iosize >> 20);
556 ldiskfs_osd_readcache_max_io_seq_write(struct file *file,
557 const char __user *buffer,
558 size_t count, loff_t *off)
560 struct seq_file *m = file->private_data;
561 struct dt_device *dt = m->private;
562 struct osd_device *osd = osd_dt_dev(dt);
563 char kernbuf[22] = "";
567 LASSERT(osd != NULL);
568 if (unlikely(osd->od_mnt == NULL))
571 if (count >= sizeof(kernbuf))
574 if (copy_from_user(kernbuf, buffer, count))
578 rc = sysfs_memparse(kernbuf, count, &val, "MiB");
582 if (val > PTLRPC_MAX_BRW_SIZE)
584 osd->od_readcache_max_iosize = val;
588 LDEBUGFS_SEQ_FOPS(ldiskfs_osd_readcache_max_io);
590 static int ldiskfs_osd_writethrough_max_io_seq_show(struct seq_file *m,
593 struct osd_device *osd = osd_dt_dev((struct dt_device *)m->private);
595 LASSERT(osd != NULL);
596 if (unlikely(osd->od_mnt == NULL))
599 seq_printf(m, "%lu\n", osd->od_writethrough_max_iosize >> 20);
604 ldiskfs_osd_writethrough_max_io_seq_write(struct file *file,
605 const char __user *buffer,
606 size_t count, loff_t *off)
608 struct seq_file *m = file->private_data;
609 struct dt_device *dt = m->private;
610 struct osd_device *osd = osd_dt_dev(dt);
611 char kernbuf[22] = "";
615 LASSERT(osd != NULL);
616 if (unlikely(osd->od_mnt == NULL))
619 if (count >= sizeof(kernbuf))
622 if (copy_from_user(kernbuf, buffer, count))
626 rc = sysfs_memparse(kernbuf, count, &val, "MiB");
630 if (val > PTLRPC_MAX_BRW_SIZE)
632 osd->od_writethrough_max_iosize = val;
636 LDEBUGFS_SEQ_FOPS(ldiskfs_osd_writethrough_max_io);
638 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 52, 0)
639 static ssize_t index_in_idif_show(struct kobject *kobj, struct attribute *attr,
642 struct dt_device *dt = container_of(kobj, struct dt_device,
644 struct osd_device *dev = osd_dt_dev(dt);
647 if (unlikely(!dev->od_mnt))
650 return sprintf(buf, "%d\n", (int)(dev->od_index_in_idif));
653 static ssize_t index_in_idif_store(struct kobject *kobj,
654 struct attribute *attr,
655 const char *buffer, size_t count)
657 struct dt_device *dt = container_of(kobj, struct dt_device,
659 struct osd_device *dev = osd_dt_dev(dt);
660 struct lu_target *tgt;
666 if (unlikely(!dev->od_mnt))
669 rc = kstrtobool(buffer, &val);
673 if (dev->od_index_in_idif) {
677 LCONSOLE_WARN("%s: OST-index in IDIF has been enabled, "
678 "it cannot be reverted back.\n", osd_name(dev));
685 rc = lu_env_init(&env, LCT_DT_THREAD);
689 tgt = dev->od_dt_dev.dd_lu_dev.ld_site->ls_tgt;
690 tgt->lut_lsd.lsd_feature_rocompat |= OBD_ROCOMPAT_IDX_IN_IDIF;
691 rc = tgt_server_data_update(&env, tgt, 1);
696 LCONSOLE_INFO("%s: enable OST-index in IDIF successfully, "
697 "it cannot be reverted back.\n", osd_name(dev));
699 dev->od_index_in_idif = 1;
702 LUSTRE_RW_ATTR(index_in_idif);
704 int osd_register_proc_index_in_idif(struct osd_device *osd)
706 struct dt_device *dt = &osd->od_dt_dev;
708 return sysfs_create_file(&dt->dd_kobj, &lustre_attr_index_in_idif.attr);
712 static ssize_t index_backup_show(struct kobject *kobj, struct attribute *attr,
715 struct dt_device *dt = container_of(kobj, struct dt_device,
717 struct osd_device *dev = osd_dt_dev(dt);
720 if (unlikely(!dev->od_mnt))
723 return sprintf(buf, "%d\n", dev->od_index_backup_policy);
726 ssize_t index_backup_store(struct kobject *kobj, struct attribute *attr,
727 const char *buffer, size_t count)
729 struct dt_device *dt = container_of(kobj, struct dt_device,
731 struct osd_device *dev = osd_dt_dev(dt);
736 if (unlikely(!dev->od_mnt))
739 rc = kstrtoint(buffer, 0, &val);
743 dev->od_index_backup_policy = val;
746 LUSTRE_RW_ATTR(index_backup);
748 struct ldebugfs_vars ldebugfs_osd_obd_vars[] = {
749 { .name = "oi_scrub",
750 .fops = &ldiskfs_osd_oi_scrub_fops },
751 { .name = "readcache_max_filesize",
752 .fops = &ldiskfs_osd_readcache_fops },
753 { .name = "readcache_max_io_mb",
754 .fops = &ldiskfs_osd_readcache_max_io_fops },
755 { .name = "writethrough_max_io_mb",
756 .fops = &ldiskfs_osd_writethrough_max_io_fops },
760 static struct attribute *ldiskfs_attrs[] = {
761 &lustre_attr_read_cache_enable.attr,
762 &lustre_attr_writethrough_cache_enable.attr,
763 &lustre_attr_fstype.attr,
764 &lustre_attr_mntdev.attr,
765 &lustre_attr_fallocate_zero_blocks.attr,
766 &lustre_attr_force_sync.attr,
767 &lustre_attr_nonrotational.attr,
768 &lustre_attr_index_backup.attr,
769 &lustre_attr_auto_scrub.attr,
770 &lustre_attr_pdo.attr,
771 &lustre_attr_full_scrub_ratio.attr,
772 &lustre_attr_full_scrub_threshold_rate.attr,
773 &lustre_attr_extent_bytes_allocation.attr,
777 int osd_procfs_init(struct osd_device *osd, const char *name)
779 struct obd_type *type;
784 /* at the moment there is no linkage between lu_type
785 * and obd_type, so we lookup obd_type this way
787 type = class_search_type(LUSTRE_OSD_LDISKFS_NAME);
792 CDEBUG(D_CONFIG, "%s: register osd-ldiskfs tunable parameters\n", name);
794 /* put reference taken by class_search_type */
795 kobject_put(&type->typ_kobj);
797 osd->od_dt_dev.dd_ktype.default_attrs = ldiskfs_attrs;
798 rc = dt_tunables_init(&osd->od_dt_dev, type, name,
799 ldebugfs_osd_obd_vars);
801 CERROR("%s: cannot setup sysfs / debugfs entry: %d\n",
806 if (osd->od_proc_entry)
809 /* Find the type procroot and add the proc entry for this device */
810 osd->od_proc_entry = lprocfs_register(name, type->typ_procroot,
811 NULL, &osd->od_dt_dev);
812 if (IS_ERR(osd->od_proc_entry)) {
813 rc = PTR_ERR(osd->od_proc_entry);
814 CERROR("Error %d setting up lprocfs for %s\n",
816 osd->od_proc_entry = NULL;
820 rc = osd_stats_init(osd);
825 osd_procfs_fini(osd);
829 int osd_procfs_fini(struct osd_device *osd)
832 lprocfs_free_stats(&osd->od_stats);
834 if (osd->od_proc_entry)
835 lprocfs_remove(&osd->od_proc_entry);
837 return dt_tunables_fini(&osd->od_dt_dev);