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