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 static int osd_stats_init(struct osd_device *osd)
51 osd->od_stats = lprocfs_alloc_stats(LPROC_OSD_LAST, 0);
53 lprocfs_counter_init(osd->od_stats, LPROC_OSD_GET_PAGE,
54 LPROCFS_CNTR_AVGMINMAX|LPROCFS_CNTR_STDDEV,
56 lprocfs_counter_init(osd->od_stats, LPROC_OSD_NO_PAGE,
57 LPROCFS_CNTR_AVGMINMAX,
58 "get_page_failures", "num");
59 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_ACCESS,
60 LPROCFS_CNTR_AVGMINMAX,
61 "cache_access", "pages");
62 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_HIT,
63 LPROCFS_CNTR_AVGMINMAX,
64 "cache_hit", "pages");
65 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_MISS,
66 LPROCFS_CNTR_AVGMINMAX,
67 "cache_miss", "pages");
68 lprocfs_counter_init(osd->od_stats, LPROC_OSD_COPY_IO,
69 LPROCFS_CNTR_AVGMINMAX,
71 lprocfs_counter_init(osd->od_stats, LPROC_OSD_ZEROCOPY_IO,
72 LPROCFS_CNTR_AVGMINMAX,
74 lprocfs_counter_init(osd->od_stats, LPROC_OSD_TAIL_IO,
75 LPROCFS_CNTR_AVGMINMAX,
77 #ifdef OSD_THANDLE_STATS
78 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_STARTING,
79 LPROCFS_CNTR_AVGMINMAX,
80 "thandle_starting", "usec");
81 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_OPEN,
82 LPROCFS_CNTR_AVGMINMAX,
83 "thandle_open", "usec");
84 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_CLOSING,
85 LPROCFS_CNTR_AVGMINMAX,
86 "thandle_closing", "usec");
91 ldebugfs_register_osd_stats(osd->od_dt_dev.dd_debugfs_entry,
92 &osd->od_brw_stats, osd->od_stats);
93 /* These fields are not supported for ZFS */
94 osd->od_brw_stats.bs_props[BRW_R_DISCONT_BLOCKS / 2].bsp_name = NULL;
95 osd->od_brw_stats.bs_props[BRW_R_DIO_FRAGS / 2].bsp_name = NULL;
100 static int zfs_osd_oi_scrub_seq_show(struct seq_file *m, void *data)
102 struct osd_device *dev = osd_dt_dev((struct dt_device *)m->private);
104 LASSERT(dev != NULL);
108 scrub_dump(m, &dev->od_scrub);
111 LDEBUGFS_SEQ_FOPS_RO(zfs_osd_oi_scrub);
113 static ssize_t auto_scrub_show(struct kobject *kobj, struct attribute *attr,
116 struct dt_device *dt = container_of(kobj, struct dt_device,
118 struct osd_device *dev = osd_dt_dev(dt);
124 return scnprintf(buf, PAGE_SIZE, "%lld\n",
125 dev->od_scrub.os_auto_scrub_interval);
128 static ssize_t auto_scrub_store(struct kobject *kobj, struct attribute *attr,
129 const char *buffer, size_t count)
131 struct dt_device *dt = container_of(kobj, struct dt_device,
133 struct osd_device *dev = osd_dt_dev(dt);
141 rc = kstrtoull(buffer, 0, &val);
145 dev->od_scrub.os_auto_scrub_interval = val;
148 LUSTRE_RW_ATTR(auto_scrub);
150 static ssize_t fstype_show(struct kobject *kobj, struct attribute *attr,
153 return sprintf(buf, "zfs\n");
155 LUSTRE_RO_ATTR(fstype);
157 static ssize_t mntdev_show(struct kobject *kobj, struct attribute *attr,
160 struct dt_device *dt = container_of(kobj, struct dt_device,
162 struct osd_device *osd = osd_dt_dev(dt);
166 return sprintf(buf, "%s\n", osd->od_mntdev);
168 LUSTRE_RO_ATTR(mntdev);
170 ssize_t force_sync_store(struct kobject *kobj, struct attribute *attr,
171 const char *buffer, size_t count)
173 struct dt_device *dt = container_of(kobj, struct dt_device,
178 rc = lu_env_init(&env, LCT_LOCAL);
182 rc = dt_sync(&env, dt);
185 return rc == 0 ? count : rc;
187 LUSTRE_WO_ATTR(force_sync);
189 static ssize_t sync_on_lseek_show(struct kobject *kobj, struct attribute *attr,
192 struct dt_device *dt = container_of(kobj, struct dt_device, dd_kobj);
193 struct osd_device *osd = osd_dt_dev(dt);
198 return sprintf(buf, "%u\n", osd->od_sync_on_lseek);
201 ssize_t sync_on_lseek_store(struct kobject *kobj, struct attribute *attr,
202 const char *buffer, size_t count)
204 struct dt_device *dt = container_of(kobj, struct dt_device, dd_kobj);
205 struct osd_device *osd = osd_dt_dev(dt);
212 rc = kstrtobool(buffer, &val);
216 osd->od_sync_on_lseek = !!val;
220 LUSTRE_RW_ATTR(sync_on_lseek);
222 static ssize_t nonrotational_show(struct kobject *kobj, struct attribute *attr,
225 struct dt_device *dt = container_of(kobj, struct dt_device,
227 struct osd_device *osd = osd_dt_dev(dt);
233 return sprintf(buf, "%u\n", osd->od_nonrotational);
236 static ssize_t nonrotational_store(struct kobject *kobj,
237 struct attribute *attr, const char *buffer,
240 struct dt_device *dt = container_of(kobj, struct dt_device,
242 struct osd_device *osd = osd_dt_dev(dt);
250 rc = kstrtobool(buffer, &val);
254 osd->od_nonrotational = val;
257 LUSTRE_RW_ATTR(nonrotational);
259 static ssize_t index_backup_show(struct kobject *kobj, struct attribute *attr,
262 struct dt_device *dt = container_of(kobj, struct dt_device,
264 struct osd_device *dev = osd_dt_dev(dt);
270 return sprintf(buf, "%d\n", dev->od_index_backup_policy);
273 ssize_t index_backup_store(struct kobject *kobj, struct attribute *attr,
274 const char *buffer, size_t count)
276 struct dt_device *dt = container_of(kobj, struct dt_device,
278 struct osd_device *dev = osd_dt_dev(dt);
286 rc = kstrtoint(buffer, 0, &val);
290 dev->od_index_backup_policy = val;
293 LUSTRE_RW_ATTR(index_backup);
295 static int zfs_osd_readcache_seq_show(struct seq_file *m, void *data)
297 struct osd_device *osd = osd_dt_dev((struct dt_device *)m->private);
299 LASSERT(osd != NULL);
300 if (unlikely(osd->od_os == NULL))
303 seq_printf(m, "%llu\n", osd->od_readcache_max_filesize);
308 zfs_osd_readcache_seq_write(struct file *file, const char __user *buffer,
309 size_t count, loff_t *off)
311 struct seq_file *m = file->private_data;
312 struct dt_device *dt = m->private;
313 struct osd_device *osd = osd_dt_dev(dt);
314 char kernbuf[22] = "";
318 LASSERT(osd != NULL);
319 if (unlikely(osd->od_os == NULL))
322 if (count >= sizeof(kernbuf))
325 if (copy_from_user(kernbuf, buffer, count))
329 rc = sysfs_memparse(kernbuf, count, &val, "B");
333 osd->od_readcache_max_filesize = val > OSD_MAX_CACHE_SIZE ?
334 OSD_MAX_CACHE_SIZE : val;
337 LDEBUGFS_SEQ_FOPS(zfs_osd_readcache);
339 static struct attribute *zfs_attrs[] = {
340 &lustre_attr_fstype.attr,
341 &lustre_attr_mntdev.attr,
342 &lustre_attr_force_sync.attr,
343 &lustre_attr_nonrotational.attr,
344 &lustre_attr_index_backup.attr,
345 &lustre_attr_auto_scrub.attr,
346 &lustre_attr_sync_on_lseek.attr,
350 struct ldebugfs_vars ldebugfs_osd_obd_vars[] = {
351 { .name = "oi_scrub",
352 .fops = &zfs_osd_oi_scrub_fops },
353 { .name = "readcache_max_filesize",
354 .fops = &zfs_osd_readcache_fops },
358 int osd_procfs_init(struct osd_device *osd, const char *name)
360 struct obd_type *type;
365 /* at the moment there is no linkage between lu_type
366 * and obd_type, so we lookup obd_type this way
368 type = class_search_type(LUSTRE_OSD_ZFS_NAME);
373 /* put reference taken by class_search_type */
374 kobject_put(&type->typ_kobj);
376 osd->od_dt_dev.dd_ktype.default_attrs = zfs_attrs;
377 rc = dt_tunables_init(&osd->od_dt_dev, type, name,
378 ldebugfs_osd_obd_vars);
380 CERROR("%s: cannot setup sysfs / debugfs entry: %d\n",
385 if (osd->od_proc_entry)
388 osd->od_proc_entry = lprocfs_register(name, type->typ_procroot,
389 NULL, &osd->od_dt_dev);
390 if (IS_ERR(osd->od_proc_entry)) {
391 rc = PTR_ERR(osd->od_proc_entry);
392 CERROR("Error %d setting up lprocfs for %s\n", rc, name);
393 osd->od_proc_entry = NULL;
397 rc = osd_stats_init(osd);
402 osd_procfs_fini(osd);
406 int osd_procfs_fini(struct osd_device *osd)
410 lprocfs_fini_brw_stats(&osd->od_brw_stats);
413 lprocfs_free_stats(&osd->od_stats);
415 if (osd->od_proc_entry) {
416 lprocfs_remove(&osd->od_proc_entry);
417 osd->od_proc_entry = NULL;
420 return dt_tunables_fini(&osd->od_dt_dev);