Whamcloud - gitweb
LU-6068 misc: update Intel copyright messages 2014
[fs/lustre-release.git] / lustre / osd-zfs / osd_lproc.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, 2014, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/osd-zfs/osd_lproc.c
37  *
38  * Author: Alex Zhuravlev <bzzz@whamcloud.com>
39  * Author: Mike Pershin <tappro@whamcloud.com>
40  */
41
42 #define DEBUG_SUBSYSTEM S_OSD
43
44 #include <obd.h>
45 #include <obd_class.h>
46 #include <lprocfs_status.h>
47 #include <lustre/lustre_idl.h>
48
49 #include "osd_internal.h"
50
51 #ifdef LPROCFS
52
53 static int osd_stats_init(struct osd_device *osd)
54 {
55         int result;
56         ENTRY;
57
58         osd->od_stats = lprocfs_alloc_stats(LPROC_OSD_LAST, 0);
59         if (osd->od_stats != NULL) {
60                 result = lprocfs_register_stats(osd->od_proc_entry, "stats",
61                                 osd->od_stats);
62                 if (result)
63                         GOTO(out, result);
64
65                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_GET_PAGE,
66                                 LPROCFS_CNTR_AVGMINMAX|LPROCFS_CNTR_STDDEV,
67                                 "get_page", "usec");
68                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_NO_PAGE,
69                                 LPROCFS_CNTR_AVGMINMAX,
70                                 "get_page_failures", "num");
71                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_ACCESS,
72                                 LPROCFS_CNTR_AVGMINMAX,
73                                 "cache_access", "pages");
74                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_HIT,
75                                 LPROCFS_CNTR_AVGMINMAX,
76                                 "cache_hit", "pages");
77                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_MISS,
78                                 LPROCFS_CNTR_AVGMINMAX,
79                                 "cache_miss", "pages");
80                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_COPY_IO,
81                                 LPROCFS_CNTR_AVGMINMAX,
82                                 "copy", "pages");
83                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_ZEROCOPY_IO,
84                                 LPROCFS_CNTR_AVGMINMAX,
85                                 "zerocopy", "pages");
86                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_TAIL_IO,
87                                 LPROCFS_CNTR_AVGMINMAX,
88                                 "tail", "pages");
89 #ifdef OSD_THANDLE_STATS
90                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_STARTING,
91                                 LPROCFS_CNTR_AVGMINMAX,
92                                 "thandle_starting", "usec");
93                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_OPEN,
94                                 LPROCFS_CNTR_AVGMINMAX,
95                                 "thandle_open", "usec");
96                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_CLOSING,
97                                 LPROCFS_CNTR_AVGMINMAX,
98                                 "thandle_closing", "usec");
99 #endif
100         } else {
101                 result = -ENOMEM;
102         }
103
104 out:
105         RETURN(result);
106 }
107
108 static int zfs_osd_fstype_seq_show(struct seq_file *m, void *data)
109 {
110         return seq_printf(m, "zfs\n");
111 }
112 LPROC_SEQ_FOPS_RO(zfs_osd_fstype);
113
114 static int zfs_osd_mntdev_seq_show(struct seq_file *m, void *data)
115 {
116         struct osd_device *osd = osd_dt_dev((struct dt_device *)m->private);
117
118         LASSERT(osd != NULL);
119         return seq_printf(m, "%s\n", osd->od_mntdev);
120 }
121 LPROC_SEQ_FOPS_RO(zfs_osd_mntdev);
122
123 static ssize_t
124 lprocfs_osd_force_sync_seq_write(struct file *file, const char __user *buffer,
125                                 size_t count, loff_t *off)
126 {
127         struct seq_file   *m = file->private_data;
128         struct dt_device  *dt = m->private;
129         struct lu_env      env;
130         int rc;
131
132         rc = lu_env_init(&env, LCT_LOCAL);
133         if (rc)
134                 return rc;
135         rc = dt_sync(&env, dt);
136         lu_env_fini(&env);
137
138         return rc == 0 ? count : rc;
139 }
140 LPROC_SEQ_FOPS_WO_TYPE(zfs, osd_force_sync);
141
142 static int zfs_osd_iused_est_seq_show(struct seq_file *m, void *data)
143 {
144         struct osd_device *osd = osd_dt_dev((struct dt_device *)m->private);
145         LASSERT(osd != NULL);
146
147         return seq_printf(m, "%d\n", osd->od_quota_iused_est);
148 }
149
150 static ssize_t
151 zfs_osd_iused_est_seq_write(struct file *file, const char __user *buffer,
152                              size_t count, loff_t *off)
153 {
154         struct seq_file   *m = file->private_data;
155         struct dt_device  *dt = m->private;
156         struct osd_device *osd = osd_dt_dev(dt);
157         int                rc, val;
158
159         LASSERT(osd != NULL);
160
161         rc = lprocfs_write_helper(buffer, count, &val);
162         if (rc)
163                 return rc;
164
165         osd->od_quota_iused_est = !!val;
166
167         return count;
168 }
169 LPROC_SEQ_FOPS(zfs_osd_iused_est);
170
171 LPROC_SEQ_FOPS_RO_TYPE(zfs, dt_blksize);
172 LPROC_SEQ_FOPS_RO_TYPE(zfs, dt_kbytestotal);
173 LPROC_SEQ_FOPS_RO_TYPE(zfs, dt_kbytesfree);
174 LPROC_SEQ_FOPS_RO_TYPE(zfs, dt_kbytesavail);
175 LPROC_SEQ_FOPS_RO_TYPE(zfs, dt_filestotal);
176 LPROC_SEQ_FOPS_RO_TYPE(zfs, dt_filesfree);
177
178 struct lprocfs_seq_vars lprocfs_osd_obd_vars[] = {
179         { .name =       "blocksize",
180           .fops =       &zfs_dt_blksize_fops            },
181         { .name =       "kbytestotal",
182           .fops =       &zfs_dt_kbytestotal_fops        },
183         { .name =       "kbytesfree",
184           .fops =       &zfs_dt_kbytesfree_fops         },
185         { .name =       "kbytesavail",
186           .fops =       &zfs_dt_kbytesavail_fops        },
187         { .name =       "filestotal",
188           .fops =       &zfs_dt_filestotal_fops         },
189         { .name =       "filesfree",
190           .fops =       &zfs_dt_filesfree_fops          },
191         { .name =       "fstype",
192           .fops =       &zfs_osd_fstype_fops            },
193         { .name =       "mntdev",
194           .fops =       &zfs_osd_mntdev_fops            },
195         { .name =       "force_sync",
196           .fops =       &zfs_osd_force_sync_fops        },
197         { .name =       "quota_iused_estimate",
198           .fops =       &zfs_osd_iused_est_fops         },
199         { 0 }
200 };
201
202 int osd_procfs_init(struct osd_device *osd, const char *name)
203 {
204         struct obd_type *type;
205         int              rc;
206         ENTRY;
207
208         if (osd->od_proc_entry)
209                 RETURN(0);
210
211         /* at the moment there is no linkage between lu_type
212          * and obd_type, so we lookup obd_type this way */
213         type = class_search_type(LUSTRE_OSD_ZFS_NAME);
214
215         LASSERT(name != NULL);
216         LASSERT(type != NULL);
217
218         osd->od_proc_entry = lprocfs_seq_register(name, type->typ_procroot,
219                         lprocfs_osd_obd_vars, &osd->od_dt_dev);
220         if (IS_ERR(osd->od_proc_entry)) {
221                 rc = PTR_ERR(osd->od_proc_entry);
222                 CERROR("Error %d setting up lprocfs for %s\n", rc, name);
223                 osd->od_proc_entry = NULL;
224                 GOTO(out, rc);
225         }
226
227         rc = osd_stats_init(osd);
228
229         GOTO(out, rc);
230 out:
231         if (rc)
232                 osd_procfs_fini(osd);
233         return rc;
234 }
235
236 int osd_procfs_fini(struct osd_device *osd)
237 {
238         ENTRY;
239
240         if (osd->od_stats)
241                 lprocfs_free_stats(&osd->od_stats);
242
243         if (osd->od_proc_entry) {
244                 lprocfs_remove(&osd->od_proc_entry);
245                 osd->od_proc_entry = NULL;
246         }
247
248         RETURN(0);
249 }
250
251 #endif