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, i;
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         /* The MDT ALWAYS needs to limit the precreate count to
242          * OST_MAX_PRECREATE, and the constant cannot be changed
243          * because it is a value shared between the OSC and OST
244          * that is the maximum possible number of objects that will
245          * ever be handled by MDT->OST recovery processing.
246          *
247          * If the OST ever gets a request to delete more orphans,
248          * this implies that something has gone badly on the MDT
249          * and the OST will refuse to delete so much data from the
250          * filesystem as a safety measure. */
251         if (val < OST_MIN_PRECREATE || val > OST_MAX_PRECREATE)
252                 return -ERANGE;
253         if (val > obd->u.cli.cl_oscc.oscc_max_grow_count)
254                 return -ERANGE;
255
256         for (i = 1; (i << 1) <= val; i <<= 1)
257                 ;
258         obd->u.cli.cl_oscc.oscc_grow_count = i;
259
260         return count;
261 }
262
263 static int osc_rd_max_create_count(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, "%d\n",
272                         obd->u.cli.cl_oscc.oscc_max_grow_count);
273 }
274
275 static int osc_wr_max_create_count(struct file *file, const char *buffer,
276                                    unsigned long count, void *data)
277 {
278         struct obd_device *obd = data;
279         int val, rc;
280
281         if (obd == NULL)
282                 return 0;
283
284         rc = lprocfs_write_helper(buffer, count, &val);
285         if (rc)
286                 return rc;
287
288         if (val < 0)
289                 return -ERANGE;
290         if (val > OST_MAX_PRECREATE)
291                 return -ERANGE;
292
293         if (obd->u.cli.cl_oscc.oscc_grow_count > val)
294                 obd->u.cli.cl_oscc.oscc_grow_count = val;
295
296         obd->u.cli.cl_oscc.oscc_max_grow_count = val;
297
298         return count;
299 }
300
301 static int osc_rd_prealloc_next_id(char *page, char **start, off_t off,
302                                    int count, int *eof, void *data)
303 {
304         struct obd_device *obd = data;
305
306         if (obd == NULL)
307                 return 0;
308
309         return snprintf(page, count, LPU64"\n",
310                         obd->u.cli.cl_oscc.oscc_next_id);
311 }
312
313 static int osc_rd_prealloc_last_id(char *page, char **start, off_t off,
314                                    int count, int *eof, void *data)
315 {
316         struct obd_device *obd = data;
317
318         if (obd == NULL)
319                 return 0;
320
321         return snprintf(page, count, LPU64"\n",
322                         obd->u.cli.cl_oscc.oscc_last_id);
323 }
324
325 static int osc_rd_checksum(char *page, char **start, off_t off, int count,
326                            int *eof, void *data)
327 {
328         struct obd_device *obd = data;
329
330         if (obd == NULL)
331                 return 0;
332
333         return snprintf(page, count, "%d\n",
334                         obd->u.cli.cl_checksum ? 1 : 0);
335 }
336
337 static int osc_wr_checksum(struct file *file, const char *buffer,
338                            unsigned long count, void *data)
339 {
340         struct obd_device *obd = data;
341         int val, rc;
342
343         if (obd == NULL)
344                 return 0;
345
346         rc = lprocfs_write_helper(buffer, count, &val);
347         if (rc)
348                 return rc;
349
350         obd->u.cli.cl_checksum = (val ? 1 : 0);
351
352         return count;
353 }
354
355 static int osc_rd_checksum_type(char *page, char **start, off_t off, int count,
356                                 int *eof, void *data)
357 {
358         struct obd_device *obd = data;
359         int i, len =0;
360         DECLARE_CKSUM_NAME;
361
362         if (obd == NULL)
363                 return 0;
364
365         for (i = 0; i < ARRAY_SIZE(cksum_name) && len < count; i++) {
366                 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
367                         continue;
368                 if (obd->u.cli.cl_cksum_type == (1 << i))
369                         len += snprintf(page + len, count - len, "[%s] ",
370                                         cksum_name[i]);
371                 else
372                         len += snprintf(page + len, count - len, "%s ",
373                                         cksum_name[i]);
374         }
375         if (len < count)
376                 len += sprintf(page + len, "\n");
377         return len;
378 }
379
380 static int osc_wd_checksum_type(struct file *file, const char *buffer,
381                                 unsigned long count, void *data)
382 {
383         struct obd_device *obd = data;
384         int i;
385         DECLARE_CKSUM_NAME;
386         char kernbuf[10];
387
388         if (obd == NULL)
389                 return 0;
390
391         if (count > sizeof(kernbuf) - 1)
392                 return -EINVAL;
393         if (copy_from_user(kernbuf, buffer, count))
394                 return -EFAULT;
395         if (count > 0 && kernbuf[count - 1] == '\n')
396                 kernbuf[count - 1] = '\0';
397         else
398                 kernbuf[count] = '\0';
399
400         for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
401                 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
402                         continue;
403                 if (!strcmp(kernbuf, cksum_name[i])) {
404                        obd->u.cli.cl_cksum_type = 1 << i;
405                        return count;
406                 }
407         }
408         return -EINVAL;
409 }
410
411 static int osc_rd_resend_count(char *page, char **start, off_t off, int count,
412                                int *eof, void *data)
413 {
414         struct obd_device *obd = data;
415
416         return snprintf(page, count, "%u\n", atomic_read(&obd->u.cli.cl_resends)); 
417 }
418
419 static int osc_wr_resend_count(struct file *file, const char *buffer,
420                                unsigned long count, void *data)
421 {
422         struct obd_device *obd = data;
423         int val, rc;
424
425         rc = lprocfs_write_helper(buffer, count, &val);
426         if (rc)
427                 return rc;
428
429         if (val < 0)
430                return -EINVAL;
431
432         atomic_set(&obd->u.cli.cl_resends, val);
433
434         return count;
435 }
436
437 static struct lprocfs_vars lprocfs_osc_obd_vars[] = {
438         { "uuid",            lprocfs_rd_uuid,        0, 0 },
439         { "ping",            0, lprocfs_wr_ping,        0 },
440         { "connect_flags",   lprocfs_rd_connect_flags, 0, 0 },
441         { "blocksize",       lprocfs_rd_blksize,     0, 0 },
442         { "kbytestotal",     lprocfs_rd_kbytestotal, 0, 0 },
443         { "kbytesfree",      lprocfs_rd_kbytesfree,  0, 0 },
444         { "kbytesavail",     lprocfs_rd_kbytesavail, 0, 0 },
445         { "filestotal",      lprocfs_rd_filestotal,  0, 0 },
446         { "filesfree",       lprocfs_rd_filesfree,   0, 0 },
447         //{ "filegroups",      lprocfs_rd_filegroups,  0, 0 },
448         { "ost_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
449         { "ost_conn_uuid",   lprocfs_rd_conn_uuid, 0, 0 },
450         { "active",          osc_rd_active, 
451                              osc_wr_active, 0 },
452         { "max_pages_per_rpc", osc_rd_max_pages_per_rpc,
453                                osc_wr_max_pages_per_rpc, 0 },
454         { "max_rpcs_in_flight", osc_rd_max_rpcs_in_flight,
455                                 osc_wr_max_rpcs_in_flight, 0 },
456         { "max_dirty_mb",    osc_rd_max_dirty_mb, osc_wr_max_dirty_mb, 0 },
457         { "cur_dirty_bytes", osc_rd_cur_dirty_bytes, 0, 0 },
458         { "cur_grant_bytes", osc_rd_cur_grant_bytes, 0, 0 },
459         { "create_count",    osc_rd_create_count, osc_wr_create_count, 0 },
460         { "max_create_count", osc_rd_max_create_count,
461                               osc_wr_max_create_count, 0},
462         { "prealloc_next_id", osc_rd_prealloc_next_id, 0, 0 },
463         { "prealloc_last_id", osc_rd_prealloc_last_id, 0, 0 },
464         { "checksums",       osc_rd_checksum, osc_wr_checksum, 0 },
465         { "checksum_type",   osc_rd_checksum_type, osc_wd_checksum_type, 0 },
466         { "resend_count",    osc_rd_resend_count, osc_wr_resend_count, 0},
467         { "timeouts",        lprocfs_rd_timeouts,      0, 0 },
468         { 0 }
469 };
470
471 static struct lprocfs_vars lprocfs_osc_module_vars[] = {
472         { "num_refs",        lprocfs_rd_numrefs,     0, 0 },
473         { 0 }
474 };
475
476 #define pct(a,b) (b ? a * 100 / b : 0)
477
478 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
479 {
480         struct timeval now;
481         struct obd_device *dev = seq->private;
482         struct client_obd *cli = &dev->u.cli;
483         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
484         int i;
485
486         do_gettimeofday(&now);
487
488         client_obd_list_lock(&cli->cl_loi_list_lock);
489
490         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
491                    now.tv_sec, now.tv_usec);
492         seq_printf(seq, "read RPCs in flight:  %d\n",
493                    cli->cl_r_in_flight);
494         seq_printf(seq, "write RPCs in flight: %d\n",
495                    cli->cl_w_in_flight);
496         seq_printf(seq, "pending write pages:  %d\n",
497                    cli->cl_pending_w_pages);
498         seq_printf(seq, "pending read pages:   %d\n",
499                    cli->cl_pending_r_pages);
500
501         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
502         seq_printf(seq, "pages per rpc         rpcs   %% cum %% |");
503         seq_printf(seq, "       rpcs   %% cum %%\n");
504
505         read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
506         write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
507
508         read_cum = 0;
509         write_cum = 0;
510         for (i = 0; i < OBD_HIST_MAX; i++) {
511                 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
512                 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
513                 read_cum += r;
514                 write_cum += w;
515                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
516                                  1 << i, r, pct(r, read_tot),
517                                  pct(read_cum, read_tot), w,
518                                  pct(w, write_tot),
519                                  pct(write_cum, write_tot));
520                 if (read_cum == read_tot && write_cum == write_tot)
521                         break;
522         }
523
524         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
525         seq_printf(seq, "rpcs in flight        rpcs   %% cum %% |");
526         seq_printf(seq, "       rpcs   %% cum %%\n");
527
528         read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
529         write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
530
531         read_cum = 0;
532         write_cum = 0;
533         for (i = 0; i < OBD_HIST_MAX; i++) {
534                 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
535                 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
536                 read_cum += r;
537                 write_cum += w;
538                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
539                                  i, r, pct(r, read_tot),
540                                  pct(read_cum, read_tot), w,
541                                  pct(w, write_tot),
542                                  pct(write_cum, write_tot));
543                 if (read_cum == read_tot && write_cum == write_tot)
544                         break;
545         }
546
547         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
548         seq_printf(seq, "offset                rpcs   %% cum %% |");
549         seq_printf(seq, "       rpcs   %% cum %%\n");
550
551         read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
552         write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
553
554         read_cum = 0;
555         write_cum = 0;
556         for (i = 0; i < OBD_HIST_MAX; i++) {
557                 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
558                 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
559                 read_cum += r;
560                 write_cum += w;
561                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
562                            (i == 0) ? 0 : 1 << (i - 1),
563                            r, pct(r, read_tot), pct(read_cum, read_tot), 
564                            w, pct(w, write_tot), pct(write_cum, write_tot));
565                 if (read_cum == read_tot && write_cum == write_tot)
566                         break;
567         }
568
569         client_obd_list_unlock(&cli->cl_loi_list_lock);
570
571         return 0;
572 }
573 #undef pct
574
575 static ssize_t osc_rpc_stats_seq_write(struct file *file, const char *buf,
576                                        size_t len, loff_t *off)
577 {
578         struct seq_file *seq = file->private_data;
579         struct obd_device *dev = seq->private;
580         struct client_obd *cli = &dev->u.cli;
581
582         lprocfs_oh_clear(&cli->cl_read_rpc_hist);
583         lprocfs_oh_clear(&cli->cl_write_rpc_hist);
584         lprocfs_oh_clear(&cli->cl_read_page_hist);
585         lprocfs_oh_clear(&cli->cl_write_page_hist);
586         lprocfs_oh_clear(&cli->cl_read_offset_hist);
587         lprocfs_oh_clear(&cli->cl_write_offset_hist);
588
589         return len;
590 }
591
592 LPROC_SEQ_FOPS(osc_rpc_stats);
593
594 int lproc_osc_attach_seqstat(struct obd_device *dev)
595 {
596         return lprocfs_obd_seq_create(dev, "rpc_stats", 0444,
597                                       &osc_rpc_stats_fops, dev);
598 }
599
600 void lprocfs_osc_init_vars(struct lprocfs_static_vars *lvars)
601 {
602         lvars->module_vars = lprocfs_osc_module_vars;
603         lvars->obd_vars    = lprocfs_osc_obd_vars;
604 }
605 #endif /* LPROCFS */
606