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