Whamcloud - gitweb
6b9d85396dcdd13e541ab2f7b385756c1b9172a8
[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 the Lustre file system, http://www.lustre.org
7  *   Lustre is a trademark of Cluster File Systems, Inc.
8  *
9  *   You may have signed or agreed to another license before downloading
10  *   this software.  If so, you are bound by the terms and conditions
11  *   of that agreement, and the following does not apply to you.  See the
12  *   LICENSE file included with this distribution for more information.
13  *
14  *   If you did not agree to a different license, then this copy of Lustre
15  *   is open source software; you can redistribute it and/or modify it
16  *   under the terms of version 2 of the GNU General Public License as
17  *   published by the Free Software Foundation.
18  *
19  *   In either case, Lustre is distributed in the hope that it will be
20  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
21  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  *   license text for more details.
23  *
24  */
25 #define DEBUG_SUBSYSTEM S_CLASS
26
27 #include <linux/version.h>
28 #include <asm/statfs.h>
29 #include <obd_class.h>
30 #include <lprocfs_status.h>
31 #include <linux/seq_file.h>
32 #include "osc_internal.h"
33
34 #ifdef LPROCFS
35 static int osc_rd_active(char *page, char **start, off_t off,
36                          int count, int *eof, void *data)
37 {
38         struct obd_device *dev = data;
39         int rc;
40
41         LPROCFS_CLIMP_CHECK(dev);
42         rc = snprintf(page, count, "%d\n", !dev->u.cli.cl_import->imp_deactive);
43         LPROCFS_CLIMP_EXIT(dev);
44         return rc;
45 }
46
47 static int osc_wr_active(struct file *file, const char *buffer,
48                          unsigned long count, void *data)
49 {
50         struct obd_device *dev = data;
51         int val, rc;
52         
53         rc = lprocfs_write_helper(buffer, count, &val);
54         if (rc)
55                 return rc;
56         if (val < 0 || val > 1)
57                 return -ERANGE;
58
59         LPROCFS_CLIMP_CHECK(dev);
60         /* opposite senses */
61         if (dev->u.cli.cl_import->imp_deactive == val) 
62                 rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
63         else
64                 CDEBUG(D_CONFIG, "activate %d: ignoring repeat request\n", val);
65         
66         LPROCFS_CLIMP_EXIT(dev);
67         return count;
68 }
69
70 static int osc_rd_max_pages_per_rpc(char *page, char **start, off_t off,
71                                     int count, int *eof, void *data)
72 {
73         struct obd_device *dev = data;
74         struct client_obd *cli = &dev->u.cli;
75         int rc;
76
77         client_obd_list_lock(&cli->cl_loi_list_lock);
78         rc = snprintf(page, count, "%d\n", cli->cl_max_pages_per_rpc);
79         client_obd_list_unlock(&cli->cl_loi_list_lock);
80         return rc;
81 }
82
83 static int osc_wr_max_pages_per_rpc(struct file *file, const char *buffer,
84                                     unsigned long count, void *data)
85 {
86         struct obd_device *dev = data;
87         struct client_obd *cli = &dev->u.cli;
88         struct obd_connect_data *ocd = &cli->cl_import->imp_connect_data;
89         int val, rc;
90
91         rc = lprocfs_write_helper(buffer, count, &val);
92         if (rc)
93                 return rc;
94
95         LPROCFS_CLIMP_CHECK(dev);
96         if (val < 1 || val > ocd->ocd_brw_size >> CFS_PAGE_SHIFT) {
97                 LPROCFS_CLIMP_EXIT(dev);
98                 return -ERANGE;
99         }
100         client_obd_list_lock(&cli->cl_loi_list_lock);
101         cli->cl_max_pages_per_rpc = val;
102         client_obd_list_unlock(&cli->cl_loi_list_lock);
103         
104         LPROCFS_CLIMP_EXIT(dev);
105         return count;
106 }
107
108 static int osc_rd_max_rpcs_in_flight(char *page, char **start, off_t off,
109                                      int count, int *eof, void *data)
110 {
111         struct obd_device *dev = data;
112         struct client_obd *cli = &dev->u.cli;
113         int rc;
114
115         client_obd_list_lock(&cli->cl_loi_list_lock);
116         rc = snprintf(page, count, "%u\n", cli->cl_max_rpcs_in_flight);
117         client_obd_list_unlock(&cli->cl_loi_list_lock);
118         return rc;
119 }
120
121 static int osc_wr_max_rpcs_in_flight(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         struct ptlrpc_request_pool *pool = cli->cl_import->imp_rq_pool;
127         int val, rc;
128
129         rc = lprocfs_write_helper(buffer, count, &val);
130         if (rc)
131                 return rc;
132
133         if (val < 1 || val > OSC_MAX_RIF_MAX)
134                 return -ERANGE;
135
136         LPROCFS_CLIMP_CHECK(dev);
137         if (pool && val > cli->cl_max_rpcs_in_flight)
138                 pool->prp_populate(pool, val-cli->cl_max_rpcs_in_flight);
139
140         client_obd_list_lock(&cli->cl_loi_list_lock);
141         cli->cl_max_rpcs_in_flight = val;
142         client_obd_list_unlock(&cli->cl_loi_list_lock);
143         
144         LPROCFS_CLIMP_EXIT(dev);
145         return count;
146 }
147
148 static int osc_rd_max_dirty_mb(char *page, char **start, off_t off, int count,
149                                int *eof, void *data)
150 {
151         struct obd_device *dev = data;
152         struct client_obd *cli = &dev->u.cli;
153         long val;
154         int mult;
155
156         client_obd_list_lock(&cli->cl_loi_list_lock);
157         val = cli->cl_dirty_max;
158         client_obd_list_unlock(&cli->cl_loi_list_lock);
159
160         mult = 1 << 20;
161         return lprocfs_read_frac_helper(page, count, val, mult);
162 }
163
164 static int osc_wr_max_dirty_mb(struct file *file, const char *buffer,
165                                unsigned long count, void *data)
166 {
167         struct obd_device *dev = data;
168         struct client_obd *cli = &dev->u.cli;
169         int pages_number, mult, rc;
170
171         mult = 1 << (20 - CFS_PAGE_SHIFT);
172         rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
173         if (rc)
174                 return rc;
175
176         if (pages_number < 0 ||
177             pages_number > OSC_MAX_DIRTY_MB_MAX << (20 - CFS_PAGE_SHIFT) ||
178             pages_number > num_physpages / 4) /* 1/4 of RAM */
179                 return -ERANGE;
180
181         client_obd_list_lock(&cli->cl_loi_list_lock);
182         cli->cl_dirty_max = (obd_count)(pages_number << CFS_PAGE_SHIFT);
183         osc_wake_cache_waiters(cli);
184         client_obd_list_unlock(&cli->cl_loi_list_lock);
185
186         return count;
187 }
188
189 static int osc_rd_cur_dirty_bytes(char *page, char **start, off_t off,
190                                   int count, int *eof, void *data)
191 {
192         struct obd_device *dev = data;
193         struct client_obd *cli = &dev->u.cli;
194         int rc;
195
196         client_obd_list_lock(&cli->cl_loi_list_lock);
197         rc = snprintf(page, count, "%lu\n", cli->cl_dirty);
198         client_obd_list_unlock(&cli->cl_loi_list_lock);
199         return rc;
200 }
201
202 static int osc_rd_cur_grant_bytes(char *page, char **start, off_t off,
203                                   int count, int *eof, void *data)
204 {
205         struct obd_device *dev = data;
206         struct client_obd *cli = &dev->u.cli;
207         int rc;
208
209         client_obd_list_lock(&cli->cl_loi_list_lock);
210         rc = snprintf(page, count, "%lu\n", cli->cl_avail_grant);
211         client_obd_list_unlock(&cli->cl_loi_list_lock);
212         return rc;
213 }
214
215 static int osc_rd_create_count(char *page, char **start, off_t off, int count,
216                                int *eof, void *data)
217 {
218         struct obd_device *obd = data;
219
220         if (obd == NULL)
221                 return 0;
222
223         return snprintf(page, count, "%d\n",
224                         obd->u.cli.cl_oscc.oscc_grow_count);
225 }
226
227 static int osc_wr_create_count(struct file *file, const char *buffer,
228                                unsigned long count, void *data)
229 {
230         struct obd_device *obd = data;
231         int val, rc;
232
233         if (obd == NULL)
234                 return 0;
235
236         rc = lprocfs_write_helper(buffer, count, &val);
237         if (rc)
238                 return rc;
239
240         if (val < 0)
241                 return -ERANGE;
242         if (val > OST_MAX_PRECREATE)
243                 return -ERANGE;
244
245         obd->u.cli.cl_oscc.oscc_grow_count = val;
246
247         return count;
248 }
249
250 static int osc_rd_prealloc_next_id(char *page, char **start, off_t off,
251                                    int count, int *eof, void *data)
252 {
253         struct obd_device *obd = data;
254
255         if (obd == NULL)
256                 return 0;
257
258         return snprintf(page, count, LPU64"\n",
259                         obd->u.cli.cl_oscc.oscc_next_id);
260 }
261
262 static int osc_rd_prealloc_last_id(char *page, char **start, off_t off,
263                                    int count, int *eof, void *data)
264 {
265         struct obd_device *obd = data;
266
267         if (obd == NULL)
268                 return 0;
269
270         return snprintf(page, count, LPU64"\n",
271                         obd->u.cli.cl_oscc.oscc_last_id);
272 }
273
274 static int osc_rd_checksum(char *page, char **start, off_t off, int count,
275                            int *eof, void *data)
276 {
277         struct obd_device *obd = data;
278
279         if (obd == NULL)
280                 return 0;
281
282         return snprintf(page, count, "%d\n",
283                         obd->u.cli.cl_checksum ? 1 : 0);
284 }
285
286 static int osc_wr_checksum(struct file *file, const char *buffer,
287                            unsigned long count, void *data)
288 {
289         struct obd_device *obd = data;
290         int val, rc;
291
292         if (obd == NULL)
293                 return 0;
294
295         rc = lprocfs_write_helper(buffer, count, &val);
296         if (rc)
297                 return rc;
298
299         obd->u.cli.cl_checksum = (val ? 1 : 0);
300
301         return count;
302 }
303
304 static int osc_rd_resend_count(char *page, char **start, off_t off, int count,
305                                int *eof, void *data)
306 {
307         struct obd_device *obd = data;
308
309         return snprintf(page, count, "%u\n", atomic_read(&obd->u.cli.cl_resends)); 
310 }
311
312 static int osc_wr_resend_count(struct file *file, const char *buffer,
313                                unsigned long count, void *data)
314 {
315         struct obd_device *obd = data;
316         int val, rc;
317
318         rc = lprocfs_write_helper(buffer, count, &val);
319         if (rc)
320                 return rc;
321
322         if (val < 0)
323                return -EINVAL;
324
325         atomic_set(&obd->u.cli.cl_resends, val);
326
327         return count;
328 }
329
330 static struct lprocfs_vars lprocfs_obd_vars[] = {
331         { "uuid",            lprocfs_rd_uuid,        0, 0 },
332         { "ping",            0, lprocfs_wr_ping,        0 },
333         { "connect_flags",   lprocfs_rd_connect_flags, 0, 0 },
334         { "blocksize",       lprocfs_rd_blksize,     0, 0 },
335         { "kbytestotal",     lprocfs_rd_kbytestotal, 0, 0 },
336         { "kbytesfree",      lprocfs_rd_kbytesfree,  0, 0 },
337         { "kbytesavail",     lprocfs_rd_kbytesavail, 0, 0 },
338         { "filestotal",      lprocfs_rd_filestotal,  0, 0 },
339         { "filesfree",       lprocfs_rd_filesfree,   0, 0 },
340         //{ "filegroups",      lprocfs_rd_filegroups,  0, 0 },
341         { "ost_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
342         { "ost_conn_uuid",   lprocfs_rd_conn_uuid, 0, 0 },
343         { "active",          osc_rd_active, 
344                              osc_wr_active, 0 },
345         { "max_pages_per_rpc", osc_rd_max_pages_per_rpc,
346                                osc_wr_max_pages_per_rpc, 0 },
347         { "max_rpcs_in_flight", osc_rd_max_rpcs_in_flight,
348                                 osc_wr_max_rpcs_in_flight, 0 },
349         { "max_dirty_mb",    osc_rd_max_dirty_mb, osc_wr_max_dirty_mb, 0 },
350         { "cur_dirty_bytes", osc_rd_cur_dirty_bytes, 0, 0 },
351         { "cur_grant_bytes", osc_rd_cur_grant_bytes, 0, 0 },
352         { "create_count",    osc_rd_create_count, osc_wr_create_count, 0 },
353         { "prealloc_next_id", osc_rd_prealloc_next_id, 0, 0 },
354         { "prealloc_last_id", osc_rd_prealloc_last_id, 0, 0 },
355         { "checksums",       osc_rd_checksum, osc_wr_checksum, 0 },
356         { "sptlrpc",         sptlrpc_lprocfs_rd, 0, 0 },
357         { "resend_count",    osc_rd_resend_count, osc_wr_resend_count, 0},
358         { 0 }
359 };
360
361 static struct lprocfs_vars lprocfs_module_vars[] = {
362         { "num_refs",        lprocfs_rd_numrefs,     0, 0 },
363         { 0 }
364 };
365
366 #define pct(a,b) (b ? a * 100 / b : 0)
367
368 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
369 {
370         struct timeval now;
371         struct obd_device *dev = seq->private;
372         struct client_obd *cli = &dev->u.cli;
373         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
374         int i;
375
376         do_gettimeofday(&now);
377
378         client_obd_list_lock(&cli->cl_loi_list_lock);
379
380         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
381                    now.tv_sec, now.tv_usec);
382         seq_printf(seq, "read RPCs in flight:  %d\n",
383                    cli->cl_r_in_flight);
384         seq_printf(seq, "write RPCs in flight: %d\n",
385                    cli->cl_w_in_flight);
386         seq_printf(seq, "pending write pages:  %d\n",
387                    cli->cl_pending_w_pages);
388         seq_printf(seq, "pending read pages:   %d\n",
389                    cli->cl_pending_r_pages);
390
391         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
392         seq_printf(seq, "pages per rpc         rpcs   %% cum %% |");
393         seq_printf(seq, "       rpcs   %% cum %%\n");
394
395         read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
396         write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
397
398         read_cum = 0;
399         write_cum = 0;
400         for (i = 0; i < OBD_HIST_MAX; i++) {
401                 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
402                 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
403                 read_cum += r;
404                 write_cum += w;
405                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
406                                  1 << i, r, pct(r, read_tot),
407                                  pct(read_cum, read_tot), w,
408                                  pct(w, write_tot),
409                                  pct(write_cum, write_tot));
410                 if (read_cum == read_tot && write_cum == write_tot)
411                         break;
412         }
413
414         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
415         seq_printf(seq, "rpcs in flight        rpcs   %% cum %% |");
416         seq_printf(seq, "       rpcs   %% cum %%\n");
417
418         read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
419         write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
420
421         read_cum = 0;
422         write_cum = 0;
423         for (i = 0; i < OBD_HIST_MAX; i++) {
424                 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
425                 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
426                 read_cum += r;
427                 write_cum += w;
428                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
429                                  i, r, pct(r, read_tot),
430                                  pct(read_cum, read_tot), w,
431                                  pct(w, write_tot),
432                                  pct(write_cum, write_tot));
433                 if (read_cum == read_tot && write_cum == write_tot)
434                         break;
435         }
436
437         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
438         seq_printf(seq, "offset                rpcs   %% cum %% |");
439         seq_printf(seq, "       rpcs   %% cum %%\n");
440
441         read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
442         write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
443
444         read_cum = 0;
445         write_cum = 0;
446         for (i = 0; i < OBD_HIST_MAX; i++) {
447                 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
448                 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
449                 read_cum += r;
450                 write_cum += w;
451                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
452                            (i == 0) ? 0 : 1 << (i - 1),
453                            r, pct(r, read_tot), pct(read_cum, read_tot), 
454                            w, pct(w, write_tot), pct(write_cum, write_tot));
455                 if (read_cum == read_tot && write_cum == write_tot)
456                         break;
457         }
458
459         client_obd_list_unlock(&cli->cl_loi_list_lock);
460
461         return 0;
462 }
463 #undef pct
464
465 static ssize_t osc_rpc_stats_seq_write(struct file *file, const char *buf,
466                                        size_t len, loff_t *off)
467 {
468         struct seq_file *seq = file->private_data;
469         struct obd_device *dev = seq->private;
470         struct client_obd *cli = &dev->u.cli;
471
472         lprocfs_oh_clear(&cli->cl_read_rpc_hist);
473         lprocfs_oh_clear(&cli->cl_write_rpc_hist);
474         lprocfs_oh_clear(&cli->cl_read_page_hist);
475         lprocfs_oh_clear(&cli->cl_write_page_hist);
476         lprocfs_oh_clear(&cli->cl_read_offset_hist);
477         lprocfs_oh_clear(&cli->cl_write_offset_hist);
478
479         return len;
480 }
481
482 LPROC_SEQ_FOPS(osc_rpc_stats);
483
484 int lproc_osc_attach_seqstat(struct obd_device *dev)
485 {
486         return lprocfs_obd_seq_create(dev, "rpc_stats", 0444,
487                                       &osc_rpc_stats_fops, dev);
488 }
489
490 LPROCFS_INIT_VARS(osc, lprocfs_module_vars, lprocfs_obd_vars)
491 #endif /* LPROCFS */
492