Whamcloud - gitweb
LU-4221 osd: add case LCFG_PARAM to osd_process_config
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_lproc.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2013, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/osd/osd_lproc.c
37  *
38  * Author: Mikhail Pershin <tappro@sun.com>
39  */
40
41 #define DEBUG_SUBSYSTEM S_CLASS
42
43 #include <lprocfs_status.h>
44 #include <lustre/lustre_idl.h>
45
46 #include "osd_internal.h"
47
48 #ifdef LPROCFS
49
50 void osd_brw_stats_update(struct osd_device *osd, struct osd_iobuf *iobuf)
51 {
52         struct brw_stats *s = &osd->od_brw_stats;
53         unsigned long    *last_block = NULL;
54         struct page     **pages = iobuf->dr_pages;
55         struct page      *last_page = NULL;
56         unsigned long     discont_pages = 0;
57         unsigned long     discont_blocks = 0;
58         unsigned long    *blocks = iobuf->dr_blocks;
59         int               i, nr_pages = iobuf->dr_npages;
60         int               blocks_per_page;
61         int               rw = iobuf->dr_rw;
62
63         if (unlikely(nr_pages == 0))
64                 return;
65
66         blocks_per_page = PAGE_CACHE_SIZE >> osd_sb(osd)->s_blocksize_bits;
67
68         lprocfs_oh_tally_log2(&s->hist[BRW_R_PAGES+rw], nr_pages);
69
70         while (nr_pages-- > 0) {
71                 if (last_page && (*pages)->index != (last_page->index + 1))
72                         discont_pages++;
73                 last_page = *pages;
74                 pages++;
75                 for (i = 0; i < blocks_per_page; i++) {
76                         if (last_block && *blocks != (*last_block + 1))
77                                 discont_blocks++;
78                         last_block = blocks++;
79                 }
80         }
81
82         lprocfs_oh_tally(&s->hist[BRW_R_DISCONT_PAGES+rw], discont_pages);
83         lprocfs_oh_tally(&s->hist[BRW_R_DISCONT_BLOCKS+rw], discont_blocks);
84 }
85
86 #define pct(a, b) (b ? a * 100 / b : 0)
87
88 static void display_brw_stats(struct seq_file *seq, char *name, char *units,
89         struct obd_histogram *read, struct obd_histogram *write, int scale)
90 {
91         unsigned long read_tot, write_tot, r, w, read_cum = 0, write_cum = 0;
92         int i;
93
94         seq_printf(seq, "\n%26s read      |     write\n", " ");
95         seq_printf(seq, "%-22s %-5s %% cum %% |  %-11s %% cum %%\n",
96                    name, units, units);
97
98         read_tot = lprocfs_oh_sum(read);
99         write_tot = lprocfs_oh_sum(write);
100         for (i = 0; i < OBD_HIST_MAX; i++) {
101                 r = read->oh_buckets[i];
102                 w = write->oh_buckets[i];
103                 read_cum += r;
104                 write_cum += w;
105                 if (read_cum == 0 && write_cum == 0)
106                         continue;
107
108                 if (!scale)
109                         seq_printf(seq, "%u", i);
110                 else if (i < 10)
111                         seq_printf(seq, "%u", scale << i);
112                 else if (i < 20)
113                         seq_printf(seq, "%uK", scale << (i-10));
114                 else
115                         seq_printf(seq, "%uM", scale << (i-20));
116
117                 seq_printf(seq, ":\t\t%10lu %3lu %3lu   | %4lu %3lu %3lu\n",
118                            r, pct(r, read_tot), pct(read_cum, read_tot),
119                            w, pct(w, write_tot), pct(write_cum, write_tot));
120
121                 if (read_cum == read_tot && write_cum == write_tot)
122                         break;
123         }
124 }
125
126 static void brw_stats_show(struct seq_file *seq, struct brw_stats *brw_stats)
127 {
128         struct timeval now;
129
130         /* this sampling races with updates */
131         do_gettimeofday(&now);
132         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
133                    now.tv_sec, now.tv_usec);
134
135         display_brw_stats(seq, "pages per bulk r/w", "rpcs",
136                           &brw_stats->hist[BRW_R_PAGES],
137                           &brw_stats->hist[BRW_W_PAGES], 1);
138
139         display_brw_stats(seq, "discontiguous pages", "rpcs",
140                           &brw_stats->hist[BRW_R_DISCONT_PAGES],
141                           &brw_stats->hist[BRW_W_DISCONT_PAGES], 0);
142
143         display_brw_stats(seq, "discontiguous blocks", "rpcs",
144                           &brw_stats->hist[BRW_R_DISCONT_BLOCKS],
145                           &brw_stats->hist[BRW_W_DISCONT_BLOCKS], 0);
146
147         display_brw_stats(seq, "disk fragmented I/Os", "ios",
148                           &brw_stats->hist[BRW_R_DIO_FRAGS],
149                           &brw_stats->hist[BRW_W_DIO_FRAGS], 0);
150
151         display_brw_stats(seq, "disk I/Os in flight", "ios",
152                           &brw_stats->hist[BRW_R_RPC_HIST],
153                           &brw_stats->hist[BRW_W_RPC_HIST], 0);
154
155         display_brw_stats(seq, "I/O time (1/1000s)", "ios",
156                           &brw_stats->hist[BRW_R_IO_TIME],
157                           &brw_stats->hist[BRW_W_IO_TIME], 1000 / HZ);
158
159         display_brw_stats(seq, "disk I/O size", "ios",
160                           &brw_stats->hist[BRW_R_DISK_IOSIZE],
161                           &brw_stats->hist[BRW_W_DISK_IOSIZE], 1);
162 }
163
164 #undef pct
165
166 static int osd_brw_stats_seq_show(struct seq_file *seq, void *v)
167 {
168         struct osd_device *osd = seq->private;
169
170         brw_stats_show(seq, &osd->od_brw_stats);
171
172         return 0;
173 }
174
175 static ssize_t osd_brw_stats_seq_write(struct file *file, const char *buf,
176                                        size_t len, loff_t *off)
177 {
178         struct seq_file *seq = file->private_data;
179         struct osd_device *osd = seq->private;
180         int i;
181
182         for (i = 0; i < BRW_LAST; i++)
183                 lprocfs_oh_clear(&osd->od_brw_stats.hist[i]);
184
185         return len;
186 }
187
188 LPROC_SEQ_FOPS(osd_brw_stats);
189
190 static int osd_stats_init(struct osd_device *osd)
191 {
192         int i, result;
193         ENTRY;
194
195         for (i = 0; i < BRW_LAST; i++)
196                 spin_lock_init(&osd->od_brw_stats.hist[i].oh_lock);
197
198         osd->od_stats = lprocfs_alloc_stats(LPROC_OSD_LAST, 0);
199         if (osd->od_stats != NULL) {
200                 result = lprocfs_register_stats(osd->od_proc_entry, "stats",
201                                                 osd->od_stats);
202                 if (result)
203                         GOTO(out, result);
204
205                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_GET_PAGE,
206                                      LPROCFS_CNTR_AVGMINMAX|LPROCFS_CNTR_STDDEV,
207                                      "get_page", "usec");
208                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_NO_PAGE,
209                                      LPROCFS_CNTR_AVGMINMAX,
210                                      "get_page_failures", "num");
211                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_ACCESS,
212                                      LPROCFS_CNTR_AVGMINMAX,
213                                      "cache_access", "pages");
214                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_HIT,
215                                      LPROCFS_CNTR_AVGMINMAX,
216                                      "cache_hit", "pages");
217                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_MISS,
218                                      LPROCFS_CNTR_AVGMINMAX,
219                                      "cache_miss", "pages");
220 #if OSD_THANDLE_STATS
221                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_STARTING,
222                                      LPROCFS_CNTR_AVGMINMAX,
223                                      "thandle starting", "usec");
224                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_OPEN,
225                                      LPROCFS_CNTR_AVGMINMAX,
226                                      "thandle open", "usec");
227                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_CLOSING,
228                                      LPROCFS_CNTR_AVGMINMAX,
229                                      "thandle closing", "usec");
230 #endif
231                 result = lprocfs_seq_create(osd->od_proc_entry, "brw_stats",
232                                             0644, &osd_brw_stats_fops, osd);
233         } else
234                 result = -ENOMEM;
235
236 out:
237         RETURN(result);
238 }
239
240 int osd_procfs_init(struct osd_device *osd, const char *name)
241 {
242         struct obd_type     *type;
243         int                  rc;
244         ENTRY;
245
246         /* at the moment there is no linkage between lu_type
247          * and obd_type, so we lookup obd_type this way */
248         type = class_search_type(LUSTRE_OSD_LDISKFS_NAME);
249
250         LASSERT(name != NULL);
251         LASSERT(type != NULL);
252
253         /* Find the type procroot and add the proc entry for this device */
254         osd->od_proc_entry = lprocfs_register(name, type->typ_procroot,
255                                               lprocfs_osd_obd_vars,
256                                               &osd->od_dt_dev);
257         if (IS_ERR(osd->od_proc_entry)) {
258                 rc = PTR_ERR(osd->od_proc_entry);
259                 CERROR("Error %d setting up lprocfs for %s\n",
260                        rc, name);
261                 osd->od_proc_entry = NULL;
262                 GOTO(out, rc);
263         }
264
265         rc = osd_stats_init(osd);
266
267         EXIT;
268 out:
269         if (rc)
270                osd_procfs_fini(osd);
271         return rc;
272 }
273
274 int osd_procfs_fini(struct osd_device *osd)
275 {
276         if (osd->od_stats)
277                 lprocfs_free_stats(&osd->od_stats);
278
279         if (osd->od_proc_entry) {
280                  lprocfs_remove(&osd->od_proc_entry);
281                  osd->od_proc_entry = NULL;
282         }
283         RETURN(0);
284 }
285
286 static int lprocfs_osd_rd_fstype(char *page, char **start, off_t off, int count,
287                                  int *eof, void *data)
288 {
289         struct osd_device *osd = osd_dt_dev(data);
290
291         LASSERT(osd != NULL);
292         return snprintf(page, count, "ldiskfs\n");
293 }
294
295 static int lprocfs_osd_rd_mntdev(char *page, char **start, off_t off, int count,
296                                  int *eof, void *data)
297 {
298         struct osd_device *osd = osd_dt_dev(data);
299
300         LASSERT(osd != NULL);
301         if (unlikely(osd->od_mnt == NULL))
302                 return -EINPROGRESS;
303
304         *eof = 1;
305
306         return snprintf(page, count, "%s\n", osd->od_mntdev);
307 }
308
309 static int lprocfs_osd_rd_cache(char *page, char **start, off_t off,
310                                 int count, int *eof, void *data)
311 {
312         struct osd_device *osd = osd_dt_dev(data);
313
314         LASSERT(osd != NULL);
315         if (unlikely(osd->od_mnt == NULL))
316                 return -EINPROGRESS;
317
318         return snprintf(page, count, "%u\n", osd->od_read_cache);
319 }
320
321 static int lprocfs_osd_wr_cache(struct file *file, const char *buffer,
322                                 unsigned long count, void *data)
323 {
324         struct osd_device       *osd = osd_dt_dev(data);
325         int                      val, rc;
326
327         LASSERT(osd != NULL);
328         if (unlikely(osd->od_mnt == NULL))
329                 return -EINPROGRESS;
330
331         rc = lprocfs_write_helper(buffer, count, &val);
332         if (rc)
333                 return rc;
334
335         osd->od_read_cache = !!val;
336         return count;
337 }
338
339 static int lprocfs_osd_rd_wcache(char *page, char **start, off_t off,
340                                  int count, int *eof, void *data)
341 {
342         struct osd_device *osd = osd_dt_dev(data);
343
344         LASSERT(osd != NULL);
345         if (unlikely(osd->od_mnt == NULL))
346                 return -EINPROGRESS;
347
348         return snprintf(page, count, "%u\n", osd->od_writethrough_cache);
349 }
350
351 static int lprocfs_osd_wr_wcache(struct file *file, const char *buffer,
352                                  unsigned long count, void *data)
353 {
354         struct osd_device       *osd = osd_dt_dev(data);
355         int                      val, rc;
356
357         LASSERT(osd != NULL);
358         if (unlikely(osd->od_mnt == NULL))
359                 return -EINPROGRESS;
360
361         rc = lprocfs_write_helper(buffer, count, &val);
362         if (rc)
363                 return rc;
364
365         osd->od_writethrough_cache = !!val;
366         return count;
367 }
368
369 static int lprocfs_osd_wr_force_sync(struct file *file, const char *buffer,
370                                      unsigned long count, void *data)
371 {
372         struct osd_device       *osd = osd_dt_dev(data);
373         struct dt_device        *dt = data;
374         struct lu_env            env;
375         int                      rc;
376
377         LASSERT(osd != NULL);
378         if (unlikely(osd->od_mnt == NULL))
379                 return -EINPROGRESS;
380
381         rc = lu_env_init(&env, LCT_LOCAL);
382         if (rc)
383                 return rc;
384         rc = dt_sync(&env, dt);
385         lu_env_fini(&env);
386
387         return rc == 0 ? count : rc;
388 }
389
390 static int lprocfs_osd_rd_pdo(char *page, char **start, off_t off, int count,
391                               int *eof, void *data)
392 {
393         *eof = 1;
394
395         return snprintf(page, count, "%s\n", ldiskfs_pdo ? "ON" : "OFF");
396 }
397
398 static int lprocfs_osd_wr_pdo(struct file *file, const char *buffer,
399                               unsigned long count, void *data)
400 {
401         int     pdo;
402         int     rc;
403
404         rc = lprocfs_write_helper(buffer, count, &pdo);
405         if (rc != 0)
406                 return rc;
407
408         ldiskfs_pdo = !!pdo;
409
410         return count;
411 }
412
413 static int lprocfs_osd_rd_auto_scrub(char *page, char **start, off_t off,
414                                      int count, int *eof, void *data)
415 {
416         struct osd_device *dev = osd_dt_dev(data);
417
418         LASSERT(dev != NULL);
419         if (unlikely(dev->od_mnt == NULL))
420                 return -EINPROGRESS;
421
422         *eof = 1;
423         return snprintf(page, count, "%d\n", !dev->od_noscrub);
424 }
425
426 static int lprocfs_osd_wr_auto_scrub(struct file *file, const char *buffer,
427                                      unsigned long count, void *data)
428 {
429         struct osd_device *dev = osd_dt_dev(data);
430         int val, rc;
431
432         LASSERT(dev != NULL);
433         if (unlikely(dev->od_mnt == NULL))
434                 return -EINPROGRESS;
435
436         rc = lprocfs_write_helper(buffer, count, &val);
437         if (rc)
438                 return rc;
439
440         dev->od_noscrub = !val;
441         return count;
442 }
443
444 static int lprocfs_osd_rd_track_declares_assert(char *page, char **start,
445                                                 off_t off, int count,
446                                                 int *eof, void *data)
447 {
448         *eof = 1;
449
450         return snprintf(page, count, "%d\n", ldiskfs_track_declares_assert);
451 }
452
453 static int lprocfs_osd_wr_track_declares_assert(struct file *file,
454                                                 const char *buffer,
455                                                 unsigned long count, void *data)
456 {
457         int     track_declares_assert;
458         int     rc;
459
460         rc = lprocfs_write_helper(buffer, count, &track_declares_assert);
461         if (rc != 0)
462                 return rc;
463
464         ldiskfs_track_declares_assert = !!track_declares_assert;
465
466         return count;
467 }
468
469 static int lprocfs_osd_rd_oi_scrub(char *page, char **start, off_t off,
470                                    int count, int *eof, void *data)
471 {
472         struct osd_device *dev = osd_dt_dev(data);
473
474         LASSERT(dev != NULL);
475         if (unlikely(dev->od_mnt == NULL))
476                 return -EINPROGRESS;
477
478         *eof = 1;
479         return osd_scrub_dump(dev, page, count);
480 }
481
482 int lprocfs_osd_rd_readcache(char *page, char **start, off_t off, int count,
483                              int *eof, void *data)
484 {
485         struct osd_device       *osd = osd_dt_dev(data);
486         int                      rc;
487
488         LASSERT(osd != NULL);
489         if (unlikely(osd->od_mnt == NULL))
490                 return -EINPROGRESS;
491
492         rc = snprintf(page, count, LPU64"\n", osd->od_readcache_max_filesize);
493         return rc;
494 }
495
496 int lprocfs_osd_wr_readcache(struct file *file, const char *buffer,
497                              unsigned long count, void *data)
498 {
499         struct osd_device       *osd = osd_dt_dev(data);
500         __u64                    val;
501         int                      rc;
502
503         LASSERT(osd != NULL);
504         if (unlikely(osd->od_mnt == NULL))
505                 return -EINPROGRESS;
506
507         rc = lprocfs_write_u64_helper(buffer, count, &val);
508         if (rc)
509                 return rc;
510
511         osd->od_readcache_max_filesize = val > OSD_MAX_CACHE_SIZE ?
512                                          OSD_MAX_CACHE_SIZE : val;
513         return count;
514 }
515
516 static int lprocfs_osd_rd_lma_self_repair(char *page, char **start, off_t off,
517                                           int count, int *eof, void *data)
518 {
519         struct osd_device *dev = osd_dt_dev(data);
520
521         LASSERT(dev != NULL);
522         if (unlikely(dev->od_mnt == NULL))
523                 return -EINPROGRESS;
524
525         *eof = 1;
526         return snprintf(page, count, "%d\n", !!dev->od_lma_self_repair);
527 }
528
529 static int lprocfs_osd_wr_lma_self_repair(struct file *file, const char *buffer,
530                                           unsigned long count, void *data)
531 {
532         struct osd_device *dev = osd_dt_dev(data);
533         int                val;
534         int                rc;
535
536         LASSERT(dev != NULL);
537         if (unlikely(dev->od_mnt == NULL))
538                 return -EINPROGRESS;
539
540         rc = lprocfs_write_helper(buffer, count, &val);
541         if (rc)
542                 return rc;
543
544         dev->od_lma_self_repair = !!val;
545         return count;
546 }
547
548 struct lprocfs_vars lprocfs_osd_obd_vars[] = {
549         { "blocksize",          lprocfs_dt_rd_blksize,  0, 0 },
550         { "kbytestotal",        lprocfs_dt_rd_kbytestotal,      0, 0 },
551         { "kbytesfree",         lprocfs_dt_rd_kbytesfree,       0, 0 },
552         { "kbytesavail",        lprocfs_dt_rd_kbytesavail,      0, 0 },
553         { "filestotal",         lprocfs_dt_rd_filestotal,       0, 0 },
554         { "filesfree",          lprocfs_dt_rd_filesfree,        0, 0 },
555         { "fstype",          lprocfs_osd_rd_fstype,      0, 0 },
556         { "mntdev",          lprocfs_osd_rd_mntdev,      0, 0 },
557         { "force_sync",      0, lprocfs_osd_wr_force_sync     },
558         { "pdo",             lprocfs_osd_rd_pdo, lprocfs_osd_wr_pdo, 0 },
559         { "auto_scrub",      lprocfs_osd_rd_auto_scrub,
560                              lprocfs_osd_wr_auto_scrub,  0 },
561         { "oi_scrub",        lprocfs_osd_rd_oi_scrub,    0, 0 },
562         { "force_sync",         0, lprocfs_osd_wr_force_sync },
563         { "read_cache_enable",  lprocfs_osd_rd_cache, lprocfs_osd_wr_cache, 0 },
564         { "writethrough_cache_enable",  lprocfs_osd_rd_wcache,
565                                         lprocfs_osd_wr_wcache, 0 },
566         { "readcache_max_filesize",     lprocfs_osd_rd_readcache,
567                                         lprocfs_osd_wr_readcache, 0 },
568         { "lma_self_repair",    lprocfs_osd_rd_lma_self_repair,
569                                 lprocfs_osd_wr_lma_self_repair, 0, 0 },
570         { 0 }
571 };
572
573 struct lprocfs_vars lprocfs_osd_module_vars[] = {
574         { "num_refs",        lprocfs_rd_numrefs,     0, 0 },
575         { "track_declares_assert",      lprocfs_osd_rd_track_declares_assert,
576                                         lprocfs_osd_wr_track_declares_assert,
577                                         0 },
578         { 0 }
579 };
580
581 #endif