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_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_checksum_type(char *page, char **start, off_t off, int count,
305                                 int *eof, void *data)
306 {
307         struct obd_device *obd = data;
308         int i, len =0;
309         DECLARE_CKSUM_NAME;
310
311         if (obd == NULL)
312                 return 0;
313
314         for (i = 0; i < ARRAY_SIZE(cksum_name) && len < count; i++) {
315                 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
316                         continue;
317                 if (obd->u.cli.cl_cksum_type == (1 << i))
318                         len += snprintf(page + len, count - len, "[%s] ",
319                                         cksum_name[i]);
320                 else
321                         len += snprintf(page + len, count - len, "%s ",
322                                         cksum_name[i]);
323         }
324         if (len < count)
325                 len += sprintf(page + len, "\n");
326         return len;
327 }
328
329 static int osc_wd_checksum_type(struct file *file, const char *buffer,
330                                 unsigned long count, void *data)
331 {
332         struct obd_device *obd = data;
333         int i;
334         DECLARE_CKSUM_NAME;
335         char kernbuf[10];
336
337         if (obd == NULL)
338                 return 0;
339
340         if (count > sizeof(kernbuf) - 1)
341                 return -EINVAL;
342         if (copy_from_user(kernbuf, buffer, count))
343                 return -EFAULT;
344         if (count > 0 && kernbuf[count - 1] == '\n')
345                 kernbuf[count - 1] = '\0';
346         else
347                 kernbuf[count] = '\0';
348
349         for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
350                 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
351                         continue;
352                 if (!strcmp(kernbuf, cksum_name[i])) {
353                        obd->u.cli.cl_cksum_type = 1 << i;
354                        return count;
355                 }
356         }
357         return -EINVAL;
358 }
359
360 static int osc_rd_resend_count(char *page, char **start, off_t off, int count,
361                                int *eof, void *data)
362 {
363         struct obd_device *obd = data;
364
365         return snprintf(page, count, "%u\n", atomic_read(&obd->u.cli.cl_resends)); 
366 }
367
368 static int osc_wr_resend_count(struct file *file, const char *buffer,
369                                unsigned long count, void *data)
370 {
371         struct obd_device *obd = data;
372         int val, rc;
373
374         rc = lprocfs_write_helper(buffer, count, &val);
375         if (rc)
376                 return rc;
377
378         if (val < 0)
379                return -EINVAL;
380
381         atomic_set(&obd->u.cli.cl_resends, val);
382
383         return count;
384 }
385
386 static struct lprocfs_vars lprocfs_osc_obd_vars[] = {
387         { "uuid",            lprocfs_rd_uuid,        0, 0 },
388         { "ping",            0, lprocfs_wr_ping,        0 },
389         { "connect_flags",   lprocfs_rd_connect_flags, 0, 0 },
390         { "blocksize",       lprocfs_rd_blksize,     0, 0 },
391         { "kbytestotal",     lprocfs_rd_kbytestotal, 0, 0 },
392         { "kbytesfree",      lprocfs_rd_kbytesfree,  0, 0 },
393         { "kbytesavail",     lprocfs_rd_kbytesavail, 0, 0 },
394         { "filestotal",      lprocfs_rd_filestotal,  0, 0 },
395         { "filesfree",       lprocfs_rd_filesfree,   0, 0 },
396         //{ "filegroups",      lprocfs_rd_filegroups,  0, 0 },
397         { "ost_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
398         { "ost_conn_uuid",   lprocfs_rd_conn_uuid, 0, 0 },
399         { "active",          osc_rd_active, 
400                              osc_wr_active, 0 },
401         { "max_pages_per_rpc", osc_rd_max_pages_per_rpc,
402                                osc_wr_max_pages_per_rpc, 0 },
403         { "max_rpcs_in_flight", osc_rd_max_rpcs_in_flight,
404                                 osc_wr_max_rpcs_in_flight, 0 },
405         { "max_dirty_mb",    osc_rd_max_dirty_mb, osc_wr_max_dirty_mb, 0 },
406         { "cur_dirty_bytes", osc_rd_cur_dirty_bytes, 0, 0 },
407         { "cur_grant_bytes", osc_rd_cur_grant_bytes, 0, 0 },
408         { "create_count",    osc_rd_create_count, osc_wr_create_count, 0 },
409         { "prealloc_next_id", osc_rd_prealloc_next_id, 0, 0 },
410         { "prealloc_last_id", osc_rd_prealloc_last_id, 0, 0 },
411         { "checksums",       osc_rd_checksum, osc_wr_checksum, 0 },
412         { "checksum_type",   osc_rd_checksum_type, osc_wd_checksum_type, 0 },
413         { "resend_count",    osc_rd_resend_count, osc_wr_resend_count, 0},
414         { 0 }
415 };
416
417 static struct lprocfs_vars lprocfs_osc_module_vars[] = {
418         { "num_refs",        lprocfs_rd_numrefs,     0, 0 },
419         { 0 }
420 };
421
422 #define pct(a,b) (b ? a * 100 / b : 0)
423
424 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
425 {
426         struct timeval now;
427         struct obd_device *dev = seq->private;
428         struct client_obd *cli = &dev->u.cli;
429         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
430         int i;
431
432         do_gettimeofday(&now);
433
434         client_obd_list_lock(&cli->cl_loi_list_lock);
435
436         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
437                    now.tv_sec, now.tv_usec);
438         seq_printf(seq, "read RPCs in flight:  %d\n",
439                    cli->cl_r_in_flight);
440         seq_printf(seq, "write RPCs in flight: %d\n",
441                    cli->cl_w_in_flight);
442         seq_printf(seq, "pending write pages:  %d\n",
443                    cli->cl_pending_w_pages);
444         seq_printf(seq, "pending read pages:   %d\n",
445                    cli->cl_pending_r_pages);
446
447         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
448         seq_printf(seq, "pages per rpc         rpcs   %% cum %% |");
449         seq_printf(seq, "       rpcs   %% cum %%\n");
450
451         read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
452         write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
453
454         read_cum = 0;
455         write_cum = 0;
456         for (i = 0; i < OBD_HIST_MAX; i++) {
457                 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
458                 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
459                 read_cum += r;
460                 write_cum += w;
461                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
462                                  1 << i, r, pct(r, read_tot),
463                                  pct(read_cum, read_tot), w,
464                                  pct(w, write_tot),
465                                  pct(write_cum, write_tot));
466                 if (read_cum == read_tot && write_cum == write_tot)
467                         break;
468         }
469
470         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
471         seq_printf(seq, "rpcs in flight        rpcs   %% cum %% |");
472         seq_printf(seq, "       rpcs   %% cum %%\n");
473
474         read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
475         write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
476
477         read_cum = 0;
478         write_cum = 0;
479         for (i = 0; i < OBD_HIST_MAX; i++) {
480                 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
481                 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
482                 read_cum += r;
483                 write_cum += w;
484                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
485                                  i, r, pct(r, read_tot),
486                                  pct(read_cum, read_tot), w,
487                                  pct(w, write_tot),
488                                  pct(write_cum, write_tot));
489                 if (read_cum == read_tot && write_cum == write_tot)
490                         break;
491         }
492
493         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
494         seq_printf(seq, "offset                rpcs   %% cum %% |");
495         seq_printf(seq, "       rpcs   %% cum %%\n");
496
497         read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
498         write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
499
500         read_cum = 0;
501         write_cum = 0;
502         for (i = 0; i < OBD_HIST_MAX; i++) {
503                 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
504                 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
505                 read_cum += r;
506                 write_cum += w;
507                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
508                            (i == 0) ? 0 : 1 << (i - 1),
509                            r, pct(r, read_tot), pct(read_cum, read_tot), 
510                            w, pct(w, write_tot), pct(write_cum, write_tot));
511                 if (read_cum == read_tot && write_cum == write_tot)
512                         break;
513         }
514
515         client_obd_list_unlock(&cli->cl_loi_list_lock);
516
517         return 0;
518 }
519 #undef pct
520
521 static ssize_t osc_rpc_stats_seq_write(struct file *file, const char *buf,
522                                        size_t len, loff_t *off)
523 {
524         struct seq_file *seq = file->private_data;
525         struct obd_device *dev = seq->private;
526         struct client_obd *cli = &dev->u.cli;
527
528         lprocfs_oh_clear(&cli->cl_read_rpc_hist);
529         lprocfs_oh_clear(&cli->cl_write_rpc_hist);
530         lprocfs_oh_clear(&cli->cl_read_page_hist);
531         lprocfs_oh_clear(&cli->cl_write_page_hist);
532         lprocfs_oh_clear(&cli->cl_read_offset_hist);
533         lprocfs_oh_clear(&cli->cl_write_offset_hist);
534
535         return len;
536 }
537
538 LPROC_SEQ_FOPS(osc_rpc_stats);
539
540 int lproc_osc_attach_seqstat(struct obd_device *dev)
541 {
542         return lprocfs_obd_seq_create(dev, "rpc_stats", 0444,
543                                       &osc_rpc_stats_fops, dev);
544 }
545
546 void lprocfs_osc_init_vars(struct lprocfs_static_vars *lvars)
547 {
548         lvars->module_vars = lprocfs_osc_module_vars;
549         lvars->obd_vars    = lprocfs_osc_obd_vars;
550 }
551 #endif /* LPROCFS */
552