Whamcloud - gitweb
9216ec0b8d6b5ef12ca29dbf01f7ed654956d9e5
[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 > PTL_MD_MAX_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         int val;
112         int rc;
113
114         spin_lock(&cli->cl_loi_list_lock);
115         val = cli->cl_dirty_max >> 20;
116         rc = snprintf(page, count, "%d\n", val);
117         spin_unlock(&cli->cl_loi_list_lock);
118         return rc;
119 }
120
121 int osc_wr_max_dirty_mb(struct file *file, const char *buffer,
122                         unsigned long count, void *data)
123 {
124         struct obd_device *dev = data;
125         struct client_obd *cli = &dev->u.cli;
126         int val, rc;
127
128         rc = lprocfs_write_helper(buffer, count, &val);
129         if (rc)
130                 return rc;
131
132         if (val < 0 || val > OSC_MAX_DIRTY_MB_MAX)
133                 return -ERANGE;
134
135         spin_lock(&cli->cl_loi_list_lock);
136         cli->cl_dirty_max = (obd_count)val * 1024 * 1024;
137         osc_wake_cache_waiters(cli);
138         spin_unlock(&cli->cl_loi_list_lock);
139
140         return count;
141 }
142
143 int osc_rd_cur_dirty_bytes(char *page, char **start, off_t off, int count,
144                            int *eof, void *data)
145 {
146         struct obd_device *dev = data;
147         struct client_obd *cli = &dev->u.cli;
148         int rc;
149
150         spin_lock(&cli->cl_loi_list_lock);
151         rc = snprintf(page, count, "%lu\n", cli->cl_dirty);
152         spin_unlock(&cli->cl_loi_list_lock);
153         return rc;
154 }
155
156 int osc_rd_cur_grant_bytes(char *page, char **start, off_t off, int count,
157                            int *eof, void *data)
158 {
159         struct obd_device *dev = data;
160         struct client_obd *cli = &dev->u.cli;
161         int rc;
162
163         spin_lock(&cli->cl_loi_list_lock);
164         rc = snprintf(page, count, "%lu\n", cli->cl_avail_grant);
165         spin_unlock(&cli->cl_loi_list_lock);
166         return rc;
167 }
168
169 int osc_rd_create_low_wm(char *page, char **start, off_t off, int count,
170                          int *eof, void *data)
171 {
172         struct obd_device *obd = data;
173         struct obd_export *exp;
174
175         if (obd == NULL || list_empty(&obd->obd_exports))
176                 return 0;
177
178         spin_lock(&obd->obd_dev_lock);
179         exp = list_entry(obd->obd_exports.next, struct obd_export,
180                          exp_obd_chain);
181         spin_unlock(&obd->obd_dev_lock);
182
183         return snprintf(page, count, "%d\n",
184                         exp->exp_osc_data.oed_oscc.oscc_kick_barrier);
185 }
186
187 int osc_wr_create_low_wm(struct file *file, const char *buffer,
188                          unsigned long count, void *data)
189 {
190         struct obd_device *obd = data;
191         struct obd_export *exp;
192         int val, rc;
193
194         if (obd == NULL || list_empty(&obd->obd_exports))
195                 return 0;
196
197         rc = lprocfs_write_helper(buffer, count, &val);
198         if (rc)
199                 return rc;
200
201         if (val < 0)
202                 return -ERANGE;
203
204         spin_lock(&obd->obd_dev_lock);
205         exp = list_entry(obd->obd_exports.next, struct obd_export,
206                          exp_obd_chain);
207         exp->exp_osc_data.oed_oscc.oscc_kick_barrier = val;
208         spin_unlock(&obd->obd_dev_lock);
209
210         return count;
211 }
212
213 int osc_rd_create_count(char *page, char **start, off_t off, int count,
214                         int *eof, void *data)
215 {
216         struct obd_device *obd = data;
217         struct obd_export *exp;
218
219         if (obd == NULL || list_empty(&obd->obd_exports))
220                 return 0;
221
222         spin_lock(&obd->obd_dev_lock);
223         exp = list_entry(obd->obd_exports.next, struct obd_export,
224                          exp_obd_chain);
225         spin_unlock(&obd->obd_dev_lock);
226
227         return snprintf(page, count, "%d\n",
228                         exp->exp_osc_data.oed_oscc.oscc_grow_count);
229 }
230
231 int osc_wr_create_count(struct file *file, const char *buffer,
232                         unsigned long count, void *data)
233 {
234         struct obd_device *obd = data;
235         struct obd_export *exp;
236         int val, rc;
237
238         if (obd == NULL || list_empty(&obd->obd_exports))
239                 return 0;
240
241         rc = lprocfs_write_helper(buffer, count, &val);
242         if (rc)
243                 return rc;
244
245         if (val < 0)
246                 return -ERANGE;
247
248         spin_lock(&obd->obd_dev_lock);
249         exp = list_entry(obd->obd_exports.next, struct obd_export,
250                          exp_obd_chain);
251         exp->exp_osc_data.oed_oscc.oscc_grow_count = val;
252         spin_unlock(&obd->obd_dev_lock);
253
254         return count;
255 }
256
257 int osc_rd_prealloc_next_id(char *page, char **start, off_t off, int count,
258                             int *eof, void *data)
259 {
260         struct obd_device *obd = data;
261         struct obd_export *exp;
262
263         if (obd == NULL || list_empty(&obd->obd_exports))
264                 return 0;
265
266         spin_lock(&obd->obd_dev_lock);
267         exp = list_entry(obd->obd_exports.next, struct obd_export,
268                          exp_obd_chain);
269         spin_unlock(&obd->obd_dev_lock);
270
271         return snprintf(page, count, LPU64"\n",
272                         exp->exp_osc_data.oed_oscc.oscc_next_id);
273 }
274
275 int osc_rd_prealloc_last_id(char *page, char **start, off_t off, int count,
276                             int *eof, void *data)
277 {
278         struct obd_device *obd = data;
279         struct obd_export *exp;
280
281         if (obd == NULL || list_empty(&obd->obd_exports))
282                 return 0;
283
284         spin_lock(&obd->obd_dev_lock);
285         exp = list_entry(obd->obd_exports.next, struct obd_export,
286                          exp_obd_chain);
287         spin_unlock(&obd->obd_dev_lock);
288
289         return snprintf(page, count, LPU64"\n",
290                         exp->exp_osc_data.oed_oscc.oscc_last_id);
291 }
292
293 static struct lprocfs_vars lprocfs_obd_vars[] = {
294         { "uuid",            lprocfs_rd_uuid,        0, 0 },
295         { "blocksize",       lprocfs_rd_blksize,     0, 0 },
296         { "kbytestotal",     lprocfs_rd_kbytestotal, 0, 0 },
297         { "kbytesfree",      lprocfs_rd_kbytesfree,  0, 0 },
298         { "kbytesavail",     lprocfs_rd_kbytesavail, 0, 0 },
299         { "filestotal",      lprocfs_rd_filestotal,  0, 0 },
300         { "filesfree",       lprocfs_rd_filesfree,   0, 0 },
301         //{ "filegroups",      lprocfs_rd_filegroups,  0, 0 },
302         { "ost_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
303         { "ost_conn_uuid",   lprocfs_rd_conn_uuid, 0, 0 },
304         { "max_pages_per_rpc", osc_rd_max_pages_per_rpc,
305                                osc_wr_max_pages_per_rpc, 0 },
306         { "max_rpcs_in_flight", osc_rd_max_rpcs_in_flight,
307                                 osc_wr_max_rpcs_in_flight, 0 },
308         { "max_dirty_mb", osc_rd_max_dirty_mb, osc_wr_max_dirty_mb, 0 },
309         { "cur_dirty_bytes", osc_rd_cur_dirty_bytes, 0, 0 },
310         { "cur_grant_bytes", osc_rd_cur_grant_bytes, 0, 0 },
311         {"create_low_watermark", osc_rd_create_low_wm, osc_wr_create_low_wm, 0},
312         { "create_count", osc_rd_create_count, osc_wr_create_count, 0 },
313         { "prealloc_next_id", osc_rd_prealloc_next_id, 0, 0 },
314         { "prealloc_last_id", osc_rd_prealloc_last_id, 0, 0 },
315         { 0 }
316 };
317
318 static struct lprocfs_vars lprocfs_module_vars[] = {
319         { "num_refs",        lprocfs_rd_numrefs,     0, 0 },
320         { 0 }
321 };
322
323 #define pct(a,b) (b ? a * 100 / b : 0)
324
325 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
326 {
327         struct timeval now;
328         struct obd_device *dev = seq->private;
329         struct client_obd *cli = &dev->u.cli;
330         unsigned long flags;
331         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
332         int i, rpcs, r, w;
333
334         do_gettimeofday(&now);
335
336         spin_lock_irqsave(&cli->cl_loi_list_lock, flags);
337
338         rpcs = cli->cl_brw_in_flight;
339         r = cli->cl_pending_r_pages;
340         w = cli->cl_pending_w_pages;
341                                                                                 
342         seq_printf(seq, "snapshot_time:         %lu:%lu (secs:usecs)\n",
343                    now.tv_sec, now.tv_usec);
344         seq_printf(seq, "RPCs in flight:        %d\n", rpcs);
345         seq_printf(seq, "pending write pages:   %d\n", w);
346         seq_printf(seq, "pending read pages:   %d\n", r);
347
348         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
349         seq_printf(seq, "pages per rpc         rpcs   %% cum %% |");
350         seq_printf(seq, "       rpcs   %% cum %%\n");
351
352         read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
353         write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
354
355         read_cum = 0;
356         write_cum = 0;
357         for (i = 0; i < OBD_HIST_MAX; i++) {
358                 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
359                 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
360                 read_cum += r;
361                 write_cum += w;
362                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n", 
363                                  1 << i, r, pct(r, read_tot), 
364                                  pct(read_cum, read_tot), w, 
365                                  pct(w, write_tot),
366                                  pct(write_cum, write_tot));
367                 if (read_cum == read_tot && write_cum == write_tot)
368                         break;
369         }
370
371         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
372         seq_printf(seq, "rpcs in flight        rpcs   %% cum %% |");
373         seq_printf(seq, "       rpcs   %% cum %%\n");
374
375         read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
376         write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
377
378         read_cum = 0;
379         write_cum = 0;
380         for (i = 0; i < OBD_HIST_MAX; i++) {
381                 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
382                 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
383                 read_cum += r;
384                 write_cum += w;
385                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n", 
386                                  i, r, pct(r, read_tot), 
387                                  pct(read_cum, read_tot), w, 
388                                  pct(w, write_tot),
389                                  pct(write_cum, write_tot));
390                 if (read_cum == read_tot && write_cum == write_tot)
391                         break;
392         }
393
394         spin_unlock_irqrestore(&cli->cl_loi_list_lock, flags);
395
396         return 0;
397 }
398 #undef pct
399
400 static void *osc_rpc_stats_seq_start(struct seq_file *p, loff_t *pos)
401 {
402         if (*pos == 0)
403                 return (void *)1;
404         return NULL;
405 }
406 static void *osc_rpc_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
407 {
408         ++*pos;
409         return NULL;
410 }
411 static void osc_rpc_stats_seq_stop(struct seq_file *p, void *v)
412 {
413 }
414 struct seq_operations osc_rpc_stats_seq_sops = {
415         .start = osc_rpc_stats_seq_start,
416         .stop = osc_rpc_stats_seq_stop,
417         .next = osc_rpc_stats_seq_next,
418         .show = osc_rpc_stats_seq_show,
419 };
420
421 static int osc_rpc_stats_seq_open(struct inode *inode, struct file *file)
422 {
423         struct proc_dir_entry *dp = PDE(inode);
424         struct seq_file *seq;
425         int rc;
426  
427         rc = seq_open(file, &osc_rpc_stats_seq_sops);
428         if (rc)
429                 return rc;
430         seq = file->private_data;
431         seq->private = dp->data;
432         return 0;
433 }
434
435 static ssize_t osc_rpc_stats_seq_write(struct file *file, const char *buf,
436                                        size_t len, loff_t *off)
437 {
438         struct seq_file *seq = file->private_data;
439         struct obd_device *dev = seq->private;
440         struct client_obd *cli = &dev->u.cli;
441
442         lprocfs_oh_clear(&cli->cl_read_rpc_hist);
443         lprocfs_oh_clear(&cli->cl_write_rpc_hist);
444         lprocfs_oh_clear(&cli->cl_read_page_hist);
445         lprocfs_oh_clear(&cli->cl_write_page_hist);
446
447         return len;
448 }
449
450 struct file_operations osc_rpc_stats_fops = {
451         .open    = osc_rpc_stats_seq_open,
452         .read    = seq_read,
453         .write   = osc_rpc_stats_seq_write,
454         .llseek  = seq_lseek,
455         .release = seq_release,
456 };
457
458 int lproc_osc_attach_seqstat(struct obd_device *dev)
459 {
460         return lprocfs_obd_seq_create(dev, "rpc_stats", 0444, 
461                                       &osc_rpc_stats_fops, dev);
462 }
463
464
465 #endif /* LPROCFS */
466 LPROCFS_INIT_VARS(osc,lprocfs_module_vars, lprocfs_obd_vars)