Whamcloud - gitweb
landing b_cmobd_merge on HEAD
[fs/lustre-release.git] / lustre / osc / lproc_osc.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2002, 2003 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  */
22 #define DEBUG_SUBSYSTEM S_CLASS
23
24 #include <linux/version.h>
25 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
26 #include <asm/statfs.h>
27 #endif
28 #include <linux/obd_class.h>
29 #include <linux/lprocfs_status.h>
30 #include <linux/seq_file.h>
31 #include "osc_internal.h"
32
33 #ifndef LPROCFS
34 static struct lprocfs_vars lprocfs_obd_vars[]  = { {0} };
35 static struct lprocfs_vars lprocfs_module_vars[] = { {0} };
36 #else
37
38 int osc_rd_max_pages_per_rpc(char *page, char **start, off_t off, int count,
39                              int *eof, void *data)
40 {
41         struct obd_device *dev = data;
42         struct client_obd *cli = &dev->u.cli;
43         int rc;
44
45         spin_lock(&cli->cl_loi_list_lock);
46         rc = snprintf(page, count, "%d\n", cli->cl_max_pages_per_rpc);
47         spin_unlock(&cli->cl_loi_list_lock);
48         return rc;
49 }
50
51 int osc_wr_max_pages_per_rpc(struct file *file, const char *buffer,
52                              unsigned long count, void *data)
53 {
54         struct obd_device *dev = data;
55         struct client_obd *cli = &dev->u.cli;
56         int val, rc;
57
58         rc = lprocfs_write_helper(buffer, count, &val);
59         if (rc)
60                 return rc;
61
62         if (val < 1 || val > PTLRPC_MAX_BRW_PAGES)
63                 return -ERANGE;
64
65         spin_lock(&cli->cl_loi_list_lock);
66         cli->cl_max_pages_per_rpc = val;
67         spin_unlock(&cli->cl_loi_list_lock);
68
69         return count;
70 }
71
72 int osc_rd_max_rpcs_in_flight(char *page, char **start, off_t off, int count,
73                               int *eof, void *data)
74 {
75         struct obd_device *dev = data;
76         struct client_obd *cli = &dev->u.cli;
77         int rc;
78
79         spin_lock(&cli->cl_loi_list_lock);
80         rc = snprintf(page, count, "%u\n", cli->cl_max_rpcs_in_flight);
81         spin_unlock(&cli->cl_loi_list_lock);
82         return rc;
83 }
84
85 int osc_wr_max_rpcs_in_flight(struct file *file, const char *buffer,
86                               unsigned long count, void *data)
87 {
88         struct obd_device *dev = data;
89         struct client_obd *cli = &dev->u.cli;
90         int val, rc;
91
92         rc = lprocfs_write_helper(buffer, count, &val);
93         if (rc)
94                 return rc;
95
96         if (val < 1 || val > OSC_MAX_RIF_MAX)
97                 return -ERANGE;
98
99         spin_lock(&cli->cl_loi_list_lock);
100         cli->cl_max_rpcs_in_flight = val;
101         spin_unlock(&cli->cl_loi_list_lock);
102
103         return count;
104 }
105
106 int osc_rd_max_dirty_mb(char *page, char **start, off_t off, int count,
107                         int *eof, void *data)
108 {
109         struct obd_device *dev = data;
110         struct client_obd *cli = &dev->u.cli;
111         unsigned val;
112
113         spin_lock(&cli->cl_loi_list_lock);
114         val = cli->cl_dirty_max >> 20;
115         spin_unlock(&cli->cl_loi_list_lock);
116
117         return snprintf(page, count, "%u\n", val);
118 }
119
120 int osc_wr_max_dirty_mb(struct file *file, const char *buffer,
121                         unsigned long count, void *data)
122 {
123         struct obd_device *dev = data;
124         struct client_obd *cli = &dev->u.cli;
125         int val, rc;
126
127         rc = lprocfs_write_helper(buffer, count, &val);
128         if (rc)
129                 return rc;
130
131         if (val < 0 || val > OSC_MAX_DIRTY_MB_MAX)
132                 return -ERANGE;
133
134         spin_lock(&cli->cl_loi_list_lock);
135         cli->cl_dirty_max = (obd_count)val * 1024 * 1024;
136         osc_wake_cache_waiters(cli);
137         spin_unlock(&cli->cl_loi_list_lock);
138
139         return count;
140 }
141
142 int osc_rd_cur_dirty_bytes(char *page, char **start, off_t off, int count,
143                            int *eof, void *data)
144 {
145         struct obd_device *dev = data;
146         struct client_obd *cli = &dev->u.cli;
147         int rc;
148
149         spin_lock(&cli->cl_loi_list_lock);
150         rc = snprintf(page, count, "%lu\n", cli->cl_dirty);
151         spin_unlock(&cli->cl_loi_list_lock);
152         return rc;
153 }
154
155 int osc_rd_cur_grant_bytes(char *page, char **start, off_t off, int count,
156                            int *eof, void *data)
157 {
158         struct obd_device *dev = data;
159         struct client_obd *cli = &dev->u.cli;
160         int rc;
161
162         spin_lock(&cli->cl_loi_list_lock);
163         rc = snprintf(page, count, "%lu\n", cli->cl_avail_grant);
164         spin_unlock(&cli->cl_loi_list_lock);
165         return rc;
166 }
167
168 int osc_rd_create_low_wm(char *page, char **start, off_t off, int count,
169                          int *eof, void *data)
170 {
171         struct obd_device *obd = data;
172
173         if (obd == NULL)
174                 return 0;
175
176         return snprintf(page, count, "%d\n",
177                         obd->u.cli.cl_oscc.oscc_kick_barrier);
178 }
179
180 int osc_wr_create_low_wm(struct file *file, const char *buffer,
181                          unsigned long count, void *data)
182 {
183         struct obd_device *obd = data;
184         int val, rc;
185
186         if (obd == NULL)
187                 return 0;
188
189         rc = lprocfs_write_helper(buffer, count, &val);
190         if (rc)
191                 return rc;
192
193         if (val < 0)
194                 return -ERANGE;
195
196         spin_lock(&obd->obd_dev_lock);
197         obd->u.cli.cl_oscc.oscc_kick_barrier = val;
198         spin_unlock(&obd->obd_dev_lock);
199
200         return count;
201 }
202
203 int osc_rd_create_count(char *page, char **start, off_t off, int count,
204                         int *eof, void *data)
205 {
206         struct obd_device *obd = data;
207
208         if (obd == NULL)
209                 return 0;
210
211         return snprintf(page, count, "%d\n",
212                         obd->u.cli.cl_oscc.oscc_grow_count);
213 }
214
215 int osc_wr_create_count(struct file *file, const char *buffer,
216                         unsigned long count, void *data)
217 {
218         struct obd_device *obd = data;
219         int val, rc;
220
221         if (obd == NULL)
222                 return 0;
223
224         rc = lprocfs_write_helper(buffer, count, &val);
225         if (rc)
226                 return rc;
227
228         if (val < 0)
229                 return -ERANGE;
230
231         obd->u.cli.cl_oscc.oscc_grow_count = val;
232
233         return count;
234 }
235
236 int osc_rd_prealloc_next_id(char *page, char **start, off_t off, int count,
237                             int *eof, void *data)
238 {
239         struct obd_device *obd = data;
240
241         if (obd == NULL)
242                 return 0;
243
244         return snprintf(page, count, LPU64"\n",
245                         obd->u.cli.cl_oscc.oscc_next_id);
246 }
247
248 int osc_rd_prealloc_last_id(char *page, char **start, off_t off, int count,
249                             int *eof, void *data)
250 {
251         struct obd_device *obd = data;
252
253         if (obd == NULL)
254                 return 0;
255
256         return snprintf(page, count, LPU64"\n",
257                         obd->u.cli.cl_oscc.oscc_last_id);
258 }
259
260 static struct lprocfs_vars lprocfs_obd_vars[] = {
261         { "uuid",            lprocfs_rd_uuid,        0, 0 },
262         { "blocksize",       lprocfs_rd_blksize,     0, 0 },
263         { "kbytestotal",     lprocfs_rd_kbytestotal, 0, 0 },
264         { "kbytesfree",      lprocfs_rd_kbytesfree,  0, 0 },
265         { "kbytesavail",     lprocfs_rd_kbytesavail, 0, 0 },
266         { "filestotal",      lprocfs_rd_filestotal,  0, 0 },
267         { "filesfree",       lprocfs_rd_filesfree,   0, 0 },
268         //{ "filegroups",      lprocfs_rd_filegroups,  0, 0 },
269         { "ost_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
270         { "ost_conn_uuid",   lprocfs_rd_conn_uuid, 0, 0 },
271         { "max_pages_per_rpc", osc_rd_max_pages_per_rpc,
272                                osc_wr_max_pages_per_rpc, 0 },
273         { "max_rpcs_in_flight", osc_rd_max_rpcs_in_flight,
274                                 osc_wr_max_rpcs_in_flight, 0 },
275         { "max_dirty_mb", osc_rd_max_dirty_mb, osc_wr_max_dirty_mb, 0 },
276         { "cur_dirty_bytes", osc_rd_cur_dirty_bytes, 0, 0 },
277         { "cur_grant_bytes", osc_rd_cur_grant_bytes, 0, 0 },
278         {"create_low_watermark", osc_rd_create_low_wm, osc_wr_create_low_wm, 0},
279         { "create_count", osc_rd_create_count, osc_wr_create_count, 0 },
280         { "prealloc_next_id", osc_rd_prealloc_next_id, 0, 0 },
281         { "prealloc_last_id", osc_rd_prealloc_last_id, 0, 0 },
282         { 0 }
283 };
284
285 static struct lprocfs_vars lprocfs_module_vars[] = {
286         { "num_refs",        lprocfs_rd_numrefs,     0, 0 },
287         { 0 }
288 };
289
290 #define pct(a,b) (b ? a * 100 / b : 0)
291
292 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
293 {
294         struct timeval now;
295         struct obd_device *dev = seq->private;
296         struct client_obd *cli = &dev->u.cli;
297         unsigned long flags;
298         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
299         int i, rpcs, r, w;
300
301         do_gettimeofday(&now);
302
303         spin_lock_irqsave(&cli->cl_loi_list_lock, flags);
304
305         rpcs = cli->cl_brw_in_flight;
306         r = cli->cl_pending_r_pages;
307         w = cli->cl_pending_w_pages;
308
309         seq_printf(seq, "snapshot_time:         %lu:%lu (secs:usecs)\n",
310                    now.tv_sec, now.tv_usec);
311         seq_printf(seq, "RPCs in flight:        %d\n", rpcs);
312         seq_printf(seq, "pending write pages:   %d\n", w);
313         seq_printf(seq, "pending read pages:   %d\n", r);
314
315         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
316         seq_printf(seq, "pages per rpc         rpcs   %% cum %% |");
317         seq_printf(seq, "       rpcs   %% cum %%\n");
318
319         read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
320         write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
321
322         read_cum = 0;
323         write_cum = 0;
324         for (i = 0; i < OBD_HIST_MAX; i++) {
325                 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
326                 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
327                 read_cum += r;
328                 write_cum += w;
329                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
330                                  1 << i, r, pct(r, read_tot),
331                                  pct(read_cum, read_tot), w,
332                                  pct(w, write_tot),
333                                  pct(write_cum, write_tot));
334                 if (read_cum == read_tot && write_cum == write_tot)
335                         break;
336         }
337
338         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
339         seq_printf(seq, "rpcs in flight        rpcs   %% cum %% |");
340         seq_printf(seq, "       rpcs   %% cum %%\n");
341
342         read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
343         write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
344
345         read_cum = 0;
346         write_cum = 0;
347         for (i = 0; i < OBD_HIST_MAX; i++) {
348                 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
349                 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
350                 read_cum += r;
351                 write_cum += w;
352                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
353                                  i, r, pct(r, read_tot),
354                                  pct(read_cum, read_tot), w,
355                                  pct(w, write_tot),
356                                  pct(write_cum, write_tot));
357                 if (read_cum == read_tot && write_cum == write_tot)
358                         break;
359         }
360
361         spin_unlock_irqrestore(&cli->cl_loi_list_lock, flags);
362
363         return 0;
364 }
365 #undef pct
366
367 static void *osc_rpc_stats_seq_start(struct seq_file *p, loff_t *pos)
368 {
369         if (*pos == 0)
370                 return (void *)1;
371         return NULL;
372 }
373 static void *osc_rpc_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
374 {
375         ++*pos;
376         return NULL;
377 }
378 static void osc_rpc_stats_seq_stop(struct seq_file *p, void *v)
379 {
380 }
381 struct seq_operations osc_rpc_stats_seq_sops = {
382         .start = osc_rpc_stats_seq_start,
383         .stop = osc_rpc_stats_seq_stop,
384         .next = osc_rpc_stats_seq_next,
385         .show = osc_rpc_stats_seq_show,
386 };
387
388 static int osc_rpc_stats_seq_open(struct inode *inode, struct file *file)
389 {
390         struct proc_dir_entry *dp = PDE(inode);
391         struct seq_file *seq;
392         int rc;
393
394         rc = seq_open(file, &osc_rpc_stats_seq_sops);
395         if (rc)
396                 return rc;
397         seq = file->private_data;
398         seq->private = dp->data;
399         return 0;
400 }
401
402 static ssize_t osc_rpc_stats_seq_write(struct file *file, const char *buf,
403                                        size_t len, loff_t *off)
404 {
405         struct seq_file *seq = file->private_data;
406         struct obd_device *dev = seq->private;
407         struct client_obd *cli = &dev->u.cli;
408
409         lprocfs_oh_clear(&cli->cl_read_rpc_hist);
410         lprocfs_oh_clear(&cli->cl_write_rpc_hist);
411         lprocfs_oh_clear(&cli->cl_read_page_hist);
412         lprocfs_oh_clear(&cli->cl_write_page_hist);
413
414         return len;
415 }
416
417 struct file_operations osc_rpc_stats_fops = {
418         .owner   = THIS_MODULE,
419         .open    = osc_rpc_stats_seq_open,
420         .read    = seq_read,
421         .write   = osc_rpc_stats_seq_write,
422         .llseek  = seq_lseek,
423         .release = seq_release,
424 };
425
426 int lproc_osc_attach_seqstat(struct obd_device *dev)
427 {
428         return lprocfs_obd_seq_create(dev, "rpc_stats", 0444,
429                                       &osc_rpc_stats_fops, dev);
430 }
431
432 #endif /* LPROCFS */
433 LPROCFS_INIT_VARS(osc, lprocfs_module_vars, lprocfs_obd_vars)