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 strlcpy(path, root, len_root);
71 if (p > path + len_root) {
73 while ((*s++ = *p++) != '\0');
76 *(path + len_root + len_path) = '\0';
77 strcat(path, "/brw_stats");
78 lprocfs_add_symlink("brw_stats", osd->od_proc_entry,
79 "/sys/kernel/debug/%s", path);
82 OBD_FREE(path, PATH_MAX);
86 static int osd_stats_init(struct osd_device *osd)
91 osd->od_stats = lprocfs_stats_alloc(LPROC_OSD_LAST, 0);
93 lprocfs_counter_init(osd->od_stats, LPROC_OSD_GET_PAGE,
94 LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV |
95 LPROCFS_TYPE_USECS, "get_page");
96 lprocfs_counter_init(osd->od_stats, LPROC_OSD_NO_PAGE,
97 LPROCFS_CNTR_AVGMINMAX | LPROCFS_TYPE_REQS,
99 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_ACCESS,
100 LPROCFS_CNTR_AVGMINMAX | LPROCFS_TYPE_PAGES,
102 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_HIT,
103 LPROCFS_CNTR_AVGMINMAX | LPROCFS_TYPE_PAGES,
105 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_MISS,
106 LPROCFS_CNTR_AVGMINMAX | LPROCFS_TYPE_PAGES,
108 lprocfs_counter_init(osd->od_stats, LPROC_OSD_COPY_IO,
109 LPROCFS_CNTR_AVGMINMAX | LPROCFS_TYPE_PAGES,
111 lprocfs_counter_init(osd->od_stats, LPROC_OSD_ZEROCOPY_IO,
112 LPROCFS_CNTR_AVGMINMAX | LPROCFS_TYPE_PAGES,
114 lprocfs_counter_init(osd->od_stats, LPROC_OSD_TAIL_IO,
115 LPROCFS_CNTR_AVGMINMAX | LPROCFS_TYPE_PAGES,
117 #ifdef OSD_THANDLE_STATS
118 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_STARTING,
119 LPROCFS_CNTR_AVGMINMAX | LPROCFS_TYPE_USECS,
121 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_OPEN,
122 LPROCFS_CNTR_AVGMINMAX | LPROCFS_TYPE_USECS,
124 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_CLOSING,
125 LPROCFS_CNTR_AVGMINMAX | LPROCFS_TYPE_USECS,
131 ldebugfs_register_osd_stats(osd->od_dt_dev.dd_debugfs_entry,
132 &osd->od_brw_stats, osd->od_stats);
134 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 17, 53, 0)
135 osd_symlink_brw_stats(osd);
138 /* These fields are not supported for ZFS */
139 osd->od_brw_stats.bs_props[BRW_R_DISCONT_BLOCKS / 2].bsp_name = NULL;
140 osd->od_brw_stats.bs_props[BRW_R_DIO_FRAGS / 2].bsp_name = NULL;
145 static int zfs_osd_oi_scrub_seq_show(struct seq_file *m, void *data)
147 struct osd_device *dev = osd_dt_dev((struct dt_device *)m->private);
149 LASSERT(dev != NULL);
153 scrub_dump(m, &dev->od_scrub);
156 LDEBUGFS_SEQ_FOPS_RO(zfs_osd_oi_scrub);
158 static ssize_t auto_scrub_show(struct kobject *kobj, struct attribute *attr,
161 struct dt_device *dt = container_of(kobj, struct dt_device,
163 struct osd_device *dev = osd_dt_dev(dt);
169 return scnprintf(buf, PAGE_SIZE, "%lld\n",
170 dev->od_scrub.os_auto_scrub_interval);
173 static ssize_t auto_scrub_store(struct kobject *kobj, struct attribute *attr,
174 const char *buffer, size_t count)
176 struct dt_device *dt = container_of(kobj, struct dt_device,
178 struct osd_device *dev = osd_dt_dev(dt);
186 rc = kstrtoull(buffer, 0, &val);
190 dev->od_scrub.os_auto_scrub_interval = val;
193 LUSTRE_RW_ATTR(auto_scrub);
195 static ssize_t fstype_show(struct kobject *kobj, struct attribute *attr,
198 return sprintf(buf, "zfs\n");
200 LUSTRE_RO_ATTR(fstype);
202 static ssize_t mntdev_show(struct kobject *kobj, struct attribute *attr,
205 struct dt_device *dt = container_of(kobj, struct dt_device,
207 struct osd_device *osd = osd_dt_dev(dt);
211 return sprintf(buf, "%s\n", osd->od_mntdev);
213 LUSTRE_RO_ATTR(mntdev);
215 static ssize_t force_sync_store(struct kobject *kobj, struct attribute *attr,
216 const char *buffer, size_t count)
218 struct dt_device *dt = container_of(kobj, struct dt_device,
223 rc = lu_env_init(&env, LCT_LOCAL);
227 rc = dt_sync(&env, dt);
230 return rc == 0 ? count : rc;
232 LUSTRE_WO_ATTR(force_sync);
234 static ssize_t sync_on_lseek_show(struct kobject *kobj, struct attribute *attr,
237 struct dt_device *dt = container_of(kobj, struct dt_device, dd_kobj);
238 struct osd_device *osd = osd_dt_dev(dt);
243 return sprintf(buf, "%u\n", osd->od_sync_on_lseek);
246 static ssize_t sync_on_lseek_store(struct kobject *kobj, struct attribute *attr,
247 const char *buffer, size_t count)
249 struct dt_device *dt = container_of(kobj, struct dt_device, dd_kobj);
250 struct osd_device *osd = osd_dt_dev(dt);
257 rc = kstrtobool(buffer, &val);
261 osd->od_sync_on_lseek = !!val;
265 LUSTRE_RW_ATTR(sync_on_lseek);
267 static ssize_t nonrotational_show(struct kobject *kobj, struct attribute *attr,
270 struct dt_device *dt = container_of(kobj, struct dt_device,
272 struct osd_device *osd = osd_dt_dev(dt);
278 return sprintf(buf, "%u\n", osd->od_nonrotational);
281 static ssize_t nonrotational_store(struct kobject *kobj,
282 struct attribute *attr, const char *buffer,
285 struct dt_device *dt = container_of(kobj, struct dt_device,
287 struct osd_device *osd = osd_dt_dev(dt);
295 rc = kstrtobool(buffer, &val);
299 osd->od_nonrotational = val;
302 LUSTRE_RW_ATTR(nonrotational);
304 static ssize_t index_backup_show(struct kobject *kobj, struct attribute *attr,
307 struct dt_device *dt = container_of(kobj, struct dt_device,
309 struct osd_device *dev = osd_dt_dev(dt);
315 return sprintf(buf, "%d\n", dev->od_index_backup_policy);
318 static ssize_t index_backup_store(struct kobject *kobj, struct attribute *attr,
319 const char *buffer, size_t count)
321 struct dt_device *dt = container_of(kobj, struct dt_device,
323 struct osd_device *dev = osd_dt_dev(dt);
331 rc = kstrtoint(buffer, 0, &val);
335 dev->od_index_backup_policy = val;
338 LUSTRE_RW_ATTR(index_backup);
340 static int zfs_osd_readcache_seq_show(struct seq_file *m, void *data)
342 struct osd_device *osd = osd_dt_dev((struct dt_device *)m->private);
344 LASSERT(osd != NULL);
345 if (unlikely(osd->od_os == NULL))
348 seq_printf(m, "%llu\n", osd->od_readcache_max_filesize);
353 zfs_osd_readcache_seq_write(struct file *file, const char __user *buffer,
354 size_t count, loff_t *off)
356 struct seq_file *m = file->private_data;
357 struct dt_device *dt = m->private;
358 struct osd_device *osd = osd_dt_dev(dt);
359 char kernbuf[22] = "";
363 LASSERT(osd != NULL);
364 if (unlikely(osd->od_os == NULL))
367 if (count >= sizeof(kernbuf))
370 if (copy_from_user(kernbuf, buffer, count))
374 rc = sysfs_memparse(kernbuf, count, &val, "B");
378 osd->od_readcache_max_filesize = val > OSD_MAX_CACHE_SIZE ?
379 OSD_MAX_CACHE_SIZE : val;
382 LDEBUGFS_SEQ_FOPS(zfs_osd_readcache);
384 static struct attribute *zfs_attrs[] = {
385 &lustre_attr_fstype.attr,
386 &lustre_attr_mntdev.attr,
387 &lustre_attr_force_sync.attr,
388 &lustre_attr_nonrotational.attr,
389 &lustre_attr_index_backup.attr,
390 &lustre_attr_auto_scrub.attr,
391 &lustre_attr_sync_on_lseek.attr,
395 struct ldebugfs_vars ldebugfs_osd_obd_vars[] = {
396 { .name = "oi_scrub",
397 .fops = &zfs_osd_oi_scrub_fops },
398 { .name = "readcache_max_filesize",
399 .fops = &zfs_osd_readcache_fops },
403 KOBJ_ATTRIBUTE_GROUPS(zfs); /* creates zfs_groups from zfs_attrs */
405 int osd_procfs_init(struct osd_device *osd, const char *name)
407 struct obd_type *type;
412 /* at the moment there is no linkage between lu_type
413 * and obd_type, so we lookup obd_type this way
415 type = class_search_type(LUSTRE_OSD_ZFS_NAME);
420 /* put reference taken by class_search_type */
421 kobject_put(&type->typ_kobj);
423 osd->od_dt_dev.dd_ktype.default_groups = KOBJ_ATTR_GROUPS(zfs);
424 rc = dt_tunables_init(&osd->od_dt_dev, type, name,
425 ldebugfs_osd_obd_vars);
427 CERROR("%s: cannot setup sysfs / debugfs entry: %d\n",
432 if (osd->od_proc_entry)
435 osd->od_proc_entry = lprocfs_register(name, type->typ_procroot,
436 NULL, &osd->od_dt_dev);
437 if (IS_ERR(osd->od_proc_entry)) {
438 rc = PTR_ERR(osd->od_proc_entry);
439 CERROR("Error %d setting up lprocfs for %s\n", rc, name);
440 osd->od_proc_entry = NULL;
444 rc = osd_stats_init(osd);
449 osd_procfs_fini(osd);
453 int osd_procfs_fini(struct osd_device *osd)
457 lprocfs_fini_brw_stats(&osd->od_brw_stats);
460 lprocfs_stats_free(&osd->od_stats);
462 if (osd->od_proc_entry) {
463 lprocfs_remove(&osd->od_proc_entry);
464 osd->od_proc_entry = NULL;
467 return dt_tunables_fini(&osd->od_dt_dev);