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) 2012, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 * lustre/osd-zfs/osd_lproc.c
33 * Author: Alex Zhuravlev <bzzz@whamcloud.com>
34 * Author: Mike Pershin <tappro@whamcloud.com>
37 #define DEBUG_SUBSYSTEM S_OSD
40 #include <obd_class.h>
41 #include <lprocfs_status.h>
42 #include <lustre_scrub.h>
44 #include "osd_internal.h"
46 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 17, 53, 0)
47 static void osd_symlink_brw_stats(struct osd_device *osd)
56 OBD_ALLOC(path, PATH_MAX);
60 p = dentry_path_raw(osd->od_dt_dev.dd_debugfs_entry, path, PATH_MAX);
64 root = osd->od_dt_dev.dd_debugfs_entry->d_sb->s_fs_info;
65 len_root = strlen(root);
67 if (len_root > (p - path) || len_root + len_path + 16 > PATH_MAX)
70 strscpy(path, root, len_root);
71 if (p > path + len_root) {
73 while ((*s++ = *p++) != '\0')
77 *(path + len_root + len_path) = '\0';
78 strcat(path, "/brw_stats");
79 lprocfs_add_symlink("brw_stats", osd->od_proc_entry,
80 "/sys/kernel/debug/%s", path);
83 OBD_FREE(path, PATH_MAX);
87 static int osd_stats_init(struct osd_device *osd)
92 osd->od_stats = lprocfs_stats_alloc(LPROC_OSD_LAST, 0);
94 lprocfs_counter_init(osd->od_stats, LPROC_OSD_GET_PAGE,
95 LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV |
96 LPROCFS_TYPE_USECS, "get_page");
97 lprocfs_counter_init(osd->od_stats, LPROC_OSD_NO_PAGE,
98 LPROCFS_CNTR_AVGMINMAX | LPROCFS_TYPE_REQS,
100 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_ACCESS,
101 LPROCFS_CNTR_AVGMINMAX | LPROCFS_TYPE_PAGES,
103 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_HIT,
104 LPROCFS_CNTR_AVGMINMAX | LPROCFS_TYPE_PAGES,
106 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_MISS,
107 LPROCFS_CNTR_AVGMINMAX | LPROCFS_TYPE_PAGES,
109 lprocfs_counter_init(osd->od_stats, LPROC_OSD_COPY_IO,
110 LPROCFS_CNTR_AVGMINMAX | LPROCFS_TYPE_PAGES,
112 lprocfs_counter_init(osd->od_stats, LPROC_OSD_ZEROCOPY_IO,
113 LPROCFS_CNTR_AVGMINMAX | LPROCFS_TYPE_PAGES,
115 lprocfs_counter_init(osd->od_stats, LPROC_OSD_TAIL_IO,
116 LPROCFS_CNTR_AVGMINMAX | LPROCFS_TYPE_PAGES,
118 #ifdef OSD_THANDLE_STATS
119 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_STARTING,
120 LPROCFS_CNTR_AVGMINMAX | LPROCFS_TYPE_USECS,
122 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_OPEN,
123 LPROCFS_CNTR_AVGMINMAX | LPROCFS_TYPE_USECS,
125 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_CLOSING,
126 LPROCFS_CNTR_AVGMINMAX | LPROCFS_TYPE_USECS,
132 ldebugfs_register_osd_stats(osd->od_dt_dev.dd_debugfs_entry,
133 &osd->od_brw_stats, osd->od_stats);
135 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 17, 53, 0)
136 osd_symlink_brw_stats(osd);
139 /* These fields are not supported for ZFS */
140 osd->od_brw_stats.bs_props[BRW_R_DISCONT_BLOCKS / 2].bsp_name = NULL;
141 osd->od_brw_stats.bs_props[BRW_R_DIO_FRAGS / 2].bsp_name = NULL;
146 static int zfs_osd_oi_scrub_seq_show(struct seq_file *m, void *data)
148 struct osd_device *dev = osd_dt_dev((struct dt_device *)m->private);
150 LASSERT(dev != NULL);
154 scrub_dump(m, &dev->od_scrub);
157 LDEBUGFS_SEQ_FOPS_RO(zfs_osd_oi_scrub);
159 static ssize_t auto_scrub_show(struct kobject *kobj, struct attribute *attr,
162 struct dt_device *dt = container_of(kobj, struct dt_device,
164 struct osd_device *dev = osd_dt_dev(dt);
170 return scnprintf(buf, PAGE_SIZE, "%lld\n",
171 dev->od_scrub.os_auto_scrub_interval);
174 static ssize_t auto_scrub_store(struct kobject *kobj, struct attribute *attr,
175 const char *buffer, size_t count)
177 struct dt_device *dt = container_of(kobj, struct dt_device,
179 struct osd_device *dev = osd_dt_dev(dt);
187 rc = kstrtoull(buffer, 0, &val);
191 dev->od_scrub.os_auto_scrub_interval = val;
194 LUSTRE_RW_ATTR(auto_scrub);
196 static ssize_t fstype_show(struct kobject *kobj, struct attribute *attr,
199 return sprintf(buf, "zfs\n");
201 LUSTRE_RO_ATTR(fstype);
203 static ssize_t mntdev_show(struct kobject *kobj, struct attribute *attr,
206 struct dt_device *dt = container_of(kobj, struct dt_device,
208 struct osd_device *osd = osd_dt_dev(dt);
212 return sprintf(buf, "%s\n", osd->od_mntdev);
214 LUSTRE_RO_ATTR(mntdev);
216 static ssize_t force_sync_store(struct kobject *kobj, struct attribute *attr,
217 const char *buffer, size_t count)
219 struct dt_device *dt = container_of(kobj, struct dt_device,
224 rc = lu_env_init(&env, LCT_LOCAL);
228 rc = dt_sync(&env, dt);
231 return rc == 0 ? count : rc;
233 LUSTRE_WO_ATTR(force_sync);
235 static ssize_t sync_on_lseek_show(struct kobject *kobj, struct attribute *attr,
238 struct dt_device *dt = container_of(kobj, struct dt_device, dd_kobj);
239 struct osd_device *osd = osd_dt_dev(dt);
244 return sprintf(buf, "%u\n", osd->od_sync_on_lseek);
247 static ssize_t sync_on_lseek_store(struct kobject *kobj, struct attribute *attr,
248 const char *buffer, size_t count)
250 struct dt_device *dt = container_of(kobj, struct dt_device, dd_kobj);
251 struct osd_device *osd = osd_dt_dev(dt);
258 rc = kstrtobool(buffer, &val);
262 osd->od_sync_on_lseek = !!val;
266 LUSTRE_RW_ATTR(sync_on_lseek);
268 static ssize_t nonrotational_show(struct kobject *kobj, struct attribute *attr,
271 struct dt_device *dt = container_of(kobj, struct dt_device,
273 struct osd_device *osd = osd_dt_dev(dt);
279 return sprintf(buf, "%u\n", osd->od_nonrotational);
282 static ssize_t nonrotational_store(struct kobject *kobj,
283 struct attribute *attr, const char *buffer,
286 struct dt_device *dt = container_of(kobj, struct dt_device,
288 struct osd_device *osd = osd_dt_dev(dt);
296 rc = kstrtobool(buffer, &val);
300 osd->od_nonrotational = val;
303 LUSTRE_RW_ATTR(nonrotational);
305 static ssize_t index_backup_show(struct kobject *kobj, struct attribute *attr,
308 struct dt_device *dt = container_of(kobj, struct dt_device,
310 struct osd_device *dev = osd_dt_dev(dt);
316 return sprintf(buf, "%d\n", dev->od_index_backup_policy);
319 static ssize_t index_backup_store(struct kobject *kobj, struct attribute *attr,
320 const char *buffer, size_t count)
322 struct dt_device *dt = container_of(kobj, struct dt_device,
324 struct osd_device *dev = osd_dt_dev(dt);
332 rc = kstrtoint(buffer, 0, &val);
336 dev->od_index_backup_policy = val;
339 LUSTRE_RW_ATTR(index_backup);
341 static int zfs_osd_readcache_seq_show(struct seq_file *m, void *data)
343 struct osd_device *osd = osd_dt_dev((struct dt_device *)m->private);
345 LASSERT(osd != NULL);
346 if (unlikely(osd->od_os == NULL))
349 seq_printf(m, "%llu\n", osd->od_readcache_max_filesize);
354 zfs_osd_readcache_seq_write(struct file *file, const char __user *buffer,
355 size_t count, loff_t *off)
357 struct seq_file *m = file->private_data;
358 struct dt_device *dt = m->private;
359 struct osd_device *osd = osd_dt_dev(dt);
360 char kernbuf[22] = "";
364 LASSERT(osd != NULL);
365 if (unlikely(osd->od_os == NULL))
368 if (count >= sizeof(kernbuf))
371 if (copy_from_user(kernbuf, buffer, count))
375 rc = sysfs_memparse(kernbuf, count, &val, "B");
379 osd->od_readcache_max_filesize = val > OSD_MAX_CACHE_SIZE ?
380 OSD_MAX_CACHE_SIZE : val;
383 LDEBUGFS_SEQ_FOPS(zfs_osd_readcache);
385 static struct attribute *zfs_attrs[] = {
386 &lustre_attr_fstype.attr,
387 &lustre_attr_mntdev.attr,
388 &lustre_attr_force_sync.attr,
389 &lustre_attr_nonrotational.attr,
390 &lustre_attr_index_backup.attr,
391 &lustre_attr_auto_scrub.attr,
392 &lustre_attr_sync_on_lseek.attr,
396 struct ldebugfs_vars ldebugfs_osd_obd_vars[] = {
397 { .name = "oi_scrub",
398 .fops = &zfs_osd_oi_scrub_fops },
399 { .name = "readcache_max_filesize",
400 .fops = &zfs_osd_readcache_fops },
404 KOBJ_ATTRIBUTE_GROUPS(zfs); /* creates zfs_groups from zfs_attrs */
406 int osd_procfs_init(struct osd_device *osd, const char *name)
408 struct obd_type *type;
413 /* at the moment there is no linkage between lu_type
414 * and obd_type, so we lookup obd_type this way
416 type = class_search_type(LUSTRE_OSD_ZFS_NAME);
421 /* put reference taken by class_search_type */
422 kobject_put(&type->typ_kobj);
424 osd->od_dt_dev.dd_ktype.default_groups = KOBJ_ATTR_GROUPS(zfs);
425 rc = dt_tunables_init(&osd->od_dt_dev, type, name,
426 ldebugfs_osd_obd_vars);
428 CERROR("%s: cannot setup sysfs / debugfs entry: %d\n",
433 if (osd->od_proc_entry)
436 osd->od_proc_entry = lprocfs_register(name, type->typ_procroot,
437 NULL, &osd->od_dt_dev);
438 if (IS_ERR(osd->od_proc_entry)) {
439 rc = PTR_ERR(osd->od_proc_entry);
440 CERROR("%s: error setting up lprocfs: rc = %d\n", name, rc);
441 osd->od_proc_entry = NULL;
445 rc = osd_stats_init(osd);
450 osd_procfs_fini(osd);
454 int osd_procfs_fini(struct osd_device *osd)
458 lprocfs_fini_brw_stats(&osd->od_brw_stats);
461 lprocfs_stats_free(&osd->od_stats);
463 if (osd->od_proc_entry) {
464 lprocfs_remove(&osd->od_proc_entry);
465 osd->od_proc_entry = NULL;
468 return dt_tunables_fini(&osd->od_dt_dev);