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