Whamcloud - gitweb
LU-1406 ofd: add FMD support
[fs/lustre-release.git] / lustre / ofd / lproc_ofd.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) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2012, Whamcloud, Inc.
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/ofd/lproc_ofd.c
37  */
38
39 #define DEBUG_SUBSYSTEM S_CLASS
40
41 #include <obd.h>
42 #include <lprocfs_status.h>
43 #include <linux/seq_file.h>
44
45 #include "ofd_internal.h"
46
47 #ifdef LPROCFS
48
49 static int lprocfs_ofd_rd_groups(char *page, char **start, off_t off,
50                                  int count, int *eof, void *data)
51 {
52         struct obd_device *obd = (struct obd_device *)data;
53         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
54
55         *eof = 1;
56         return snprintf(page, count, "%u\n", ofd->ofd_max_group);
57 }
58
59 static int lprocfs_ofd_rd_last_id(char *page, char **start, off_t off,
60                                   int count, int *eof, void *data)
61 {
62         struct obd_device       *obd = data;
63         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
64         int                      retval = 0, rc, i;
65
66         if (obd == NULL)
67                 return 0;
68
69         for (i = FID_SEQ_OST_MDT0; i <= ofd->ofd_max_group; i++) {
70                 rc = snprintf(page, count, LPU64"\n", ofd_last_id(ofd, i));
71                 if (rc < 0) {
72                         retval = rc;
73                         break;
74                 }
75                 page += rc;
76                 count -= rc;
77                 retval += rc;
78         }
79         return retval;
80 }
81
82 int lprocfs_ofd_rd_fmd_max_num(char *page, char **start, off_t off,
83                                int count, int *eof, void *data)
84 {
85         struct obd_device       *obd = data;
86         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
87         int                      rc;
88
89         rc = snprintf(page, count, "%u\n", ofd->ofd_fmd_max_num);
90         return rc;
91 }
92
93 int lprocfs_ofd_wr_fmd_max_num(struct file *file, const char *buffer,
94                                unsigned long count, void *data)
95 {
96         struct obd_device       *obd = data;
97         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
98         int                      val;
99         int                      rc;
100
101         rc = lprocfs_write_helper(buffer, count, &val);
102         if (rc)
103                 return rc;
104
105         if (val > 65536 || val < 1)
106                 return -EINVAL;
107
108         ofd->ofd_fmd_max_num = val;
109         return count;
110 }
111
112 int lprocfs_ofd_rd_fmd_max_age(char *page, char **start, off_t off,
113                                int count, int *eof, void *data)
114 {
115         struct obd_device       *obd = data;
116         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
117         int                      rc;
118
119         rc = snprintf(page, count, "%ld\n", ofd->ofd_fmd_max_age / CFS_HZ);
120         return rc;
121 }
122
123 int lprocfs_ofd_wr_fmd_max_age(struct file *file, const char *buffer,
124                                unsigned long count, void *data)
125 {
126         struct obd_device       *obd = data;
127         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
128         int                      val;
129         int                      rc;
130
131         rc = lprocfs_write_helper(buffer, count, &val);
132         if (rc)
133                 return rc;
134
135         if (val > 65536 || val < 1)
136                 return -EINVAL;
137
138         ofd->ofd_fmd_max_age = val * CFS_HZ;
139         return count;
140 }
141
142 static int lprocfs_ofd_rd_capa(char *page, char **start, off_t off,
143                                int count, int *eof, void *data)
144 {
145         struct obd_device       *obd = data;
146         int                      rc;
147
148         rc = snprintf(page, count, "capability on: %s\n",
149                       obd->u.filter.fo_fl_oss_capa ? "oss" : "");
150         return rc;
151 }
152
153 static int lprocfs_ofd_wr_capa(struct file *file, const char *buffer,
154                                unsigned long count, void *data)
155 {
156         struct obd_device       *obd = data;
157         int                      val, rc;
158
159         rc = lprocfs_write_helper(buffer, count, &val);
160         if (rc)
161                 return rc;
162
163         if (val & ~0x1) {
164                 CERROR("invalid capability mode, only 0/1 are accepted.\n"
165                        " 1: enable oss fid capability\n"
166                        " 0: disable oss fid capability\n");
167                 return -EINVAL;
168         }
169
170         obd->u.filter.fo_fl_oss_capa = val;
171         LCONSOLE_INFO("OSS %s %s fid capability.\n", obd->obd_name,
172                       val ? "enabled" : "disabled");
173         return count;
174 }
175
176 static int lprocfs_ofd_rd_capa_count(char *page, char **start, off_t off,
177                                      int count, int *eof, void *data)
178 {
179         return snprintf(page, count, "%d %d\n",
180                         capa_count[CAPA_SITE_CLIENT],
181                         capa_count[CAPA_SITE_SERVER]);
182 }
183
184 int lprocfs_ofd_rd_degraded(char *page, char **start, off_t off,
185                             int count, int *eof, void *data)
186 {
187         struct obd_device *obd = data;
188         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
189
190         return snprintf(page, count, "%u\n", ofd->ofd_raid_degraded);
191 }
192
193 int lprocfs_ofd_wr_degraded(struct file *file, const char *buffer,
194                             unsigned long count, void *data)
195 {
196         struct obd_device       *obd = data;
197         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
198         int                      val, rc;
199
200         rc = lprocfs_write_helper(buffer, count, &val);
201         if (rc)
202                 return rc;
203
204         cfs_spin_lock(&ofd->ofd_flags_lock);
205         ofd->ofd_raid_degraded = !!val;
206         cfs_spin_unlock(&ofd->ofd_flags_lock);
207
208         return count;
209 }
210
211 int lprocfs_ofd_rd_fstype(char *page, char **start, off_t off, int count,
212                           int *eof, void *data)
213 {
214         struct obd_device *obd = data;
215         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
216         struct lu_device  *d;
217
218         LASSERT(ofd->ofd_osd);
219         d = &ofd->ofd_osd->dd_lu_dev;
220         LASSERT(d->ld_type);
221         return snprintf(page, count, "%s\n", d->ld_type->ldt_name);
222 }
223
224 int lprocfs_ofd_rd_syncjournal(char *page, char **start, off_t off,
225                                int count, int *eof, void *data)
226 {
227         struct obd_device       *obd = data;
228         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
229         int                      rc;
230
231         rc = snprintf(page, count, "%u\n", ofd->ofd_syncjournal);
232         return rc;
233 }
234
235 int lprocfs_ofd_wr_syncjournal(struct file *file, const char *buffer,
236                                unsigned long count, void *data)
237 {
238         struct obd_device       *obd = data;
239         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
240         int                      val;
241         int                      rc;
242
243         rc = lprocfs_write_helper(buffer, count, &val);
244         if (rc)
245                 return rc;
246
247         if (val < 0)
248                 return -EINVAL;
249
250         cfs_spin_lock(&ofd->ofd_flags_lock);
251         ofd->ofd_syncjournal = !!val;
252         ofd_slc_set(ofd);
253         cfs_spin_unlock(&ofd->ofd_flags_lock);
254
255         return count;
256 }
257
258 static char *sync_on_cancel_states[] = {"never",
259                                         "blocking",
260                                         "always" };
261
262 int lprocfs_ofd_rd_sync_lock_cancel(char *page, char **start, off_t off,
263                                     int count, int *eof, void *data)
264 {
265         struct obd_device       *obd = data;
266         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
267         int                      rc;
268
269         rc = snprintf(page, count, "%s\n",
270                       sync_on_cancel_states[ofd->ofd_sync_lock_cancel]);
271         return rc;
272 }
273
274 int lprocfs_ofd_wr_sync_lock_cancel(struct file *file, const char *buffer,
275                                     unsigned long count, void *data)
276 {
277         struct obd_device       *obd = data;
278         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
279         int                      val = -1;
280         int                      i;
281
282         for (i = 0 ; i < NUM_SYNC_ON_CANCEL_STATES; i++) {
283                 if (memcmp(buffer, sync_on_cancel_states[i],
284                            strlen(sync_on_cancel_states[i])) == 0) {
285                         val = i;
286                         break;
287                 }
288         }
289         if (val == -1) {
290                 int rc;
291
292                 rc = lprocfs_write_helper(buffer, count, &val);
293                 if (rc)
294                         return rc;
295         }
296
297         if (val < 0 || val > 2)
298                 return -EINVAL;
299
300         cfs_spin_lock(&ofd->ofd_flags_lock);
301         ofd->ofd_sync_lock_cancel = val;
302         cfs_spin_unlock(&ofd->ofd_flags_lock);
303         return count;
304 }
305
306 static struct lprocfs_vars lprocfs_ofd_obd_vars[] = {
307         { "uuid",                lprocfs_rd_uuid, 0, 0 },
308         { "blocksize",           lprocfs_rd_blksize, 0, 0 },
309         { "kbytestotal",         lprocfs_rd_kbytestotal, 0, 0 },
310         { "kbytesfree",          lprocfs_rd_kbytesfree, 0, 0 },
311         { "kbytesavail",         lprocfs_rd_kbytesavail, 0, 0 },
312         { "filestotal",          lprocfs_rd_filestotal, 0, 0 },
313         { "filesfree",           lprocfs_rd_filesfree, 0, 0 },
314         { "filegroups",          lprocfs_ofd_rd_groups, 0, 0 },
315         { "fstype",              lprocfs_ofd_rd_fstype, 0, 0 },
316         { "last_id",             lprocfs_ofd_rd_last_id, 0, 0 },
317         { "recovery_status",     lprocfs_obd_rd_recovery_status, 0, 0 },
318         { "recovery_time_soft",  lprocfs_obd_rd_recovery_time_soft,
319                                  lprocfs_obd_wr_recovery_time_soft, 0},
320         { "recovery_time_hard",  lprocfs_obd_rd_recovery_time_hard,
321                                  lprocfs_obd_wr_recovery_time_hard, 0},
322         { "evict_client",        0, lprocfs_wr_evict_client, 0,
323                                  &lprocfs_evict_client_fops},
324         { "num_exports",         lprocfs_rd_num_exports,   0, 0 },
325         { "degraded",            lprocfs_ofd_rd_degraded,
326                                  lprocfs_ofd_wr_degraded, 0},
327         { "sync_journal",        lprocfs_ofd_rd_syncjournal,
328                                  lprocfs_ofd_wr_syncjournal, 0 },
329         { "sync_on_lock_cancel", lprocfs_ofd_rd_sync_lock_cancel,
330                                  lprocfs_ofd_wr_sync_lock_cancel, 0 },
331         { "instance",            lprocfs_target_rd_instance, 0 },
332         { "ir_factor",           lprocfs_obd_rd_ir_factor,
333                                  lprocfs_obd_wr_ir_factor, 0},
334         { "client_cache_count",  lprocfs_ofd_rd_fmd_max_num,
335                                  lprocfs_ofd_wr_fmd_max_num, 0 },
336         { "client_cache_seconds", lprocfs_ofd_rd_fmd_max_age,
337                                   lprocfs_ofd_wr_fmd_max_age, 0 },
338         { "capa",                lprocfs_ofd_rd_capa,
339                                  lprocfs_ofd_wr_capa, 0 },
340         { "capa_count",          lprocfs_ofd_rd_capa_count, 0, 0 },
341         { 0 }
342 };
343
344 static struct lprocfs_vars lprocfs_ofd_module_vars[] = {
345         { "num_refs",     lprocfs_rd_numrefs,   0, 0 },
346         { 0 }
347 };
348
349 #define pct(a,b) (b ? a * 100 / b : 0)
350
351 static void display_brw_stats(struct seq_file *seq, char *name, char *units,
352                               struct obd_histogram *read,
353                               struct obd_histogram *write, int log2)
354 {
355         unsigned long   read_tot, write_tot, r, w, read_cum = 0, write_cum = 0;
356         int             i;
357
358         seq_printf(seq, "\n%26s read      |     write\n", " ");
359         seq_printf(seq, "%-22s %-5s %% cum %% |  %-5s %% cum %%\n",
360                    name, units, units);
361
362         read_tot = lprocfs_oh_sum(read);
363         write_tot = lprocfs_oh_sum(write);
364         for (i = 0; i < OBD_HIST_MAX; i++) {
365                 r = read->oh_buckets[i];
366                 w = write->oh_buckets[i];
367                 read_cum += r;
368                 write_cum += w;
369                 if (read_cum == 0 && write_cum == 0)
370                         continue;
371
372                 if (!log2)
373                         seq_printf(seq, "%u", i);
374                 else if (i < 10)
375                         seq_printf(seq, "%u", 1 << i);
376                 else if (i < 20)
377                         seq_printf(seq, "%uK", 1 << (i - 10));
378                 else
379                         seq_printf(seq, "%uM", 1 << (i - 20));
380
381                 seq_printf(seq, ":\t\t%10lu %3lu %3lu   | %4lu %3lu %3lu\n",
382                            r, pct(r, read_tot), pct(read_cum, read_tot),
383                            w, pct(w, write_tot), pct(write_cum, write_tot));
384
385                 if (read_cum == read_tot && write_cum == write_tot)
386                         break;
387         }
388 }
389
390 static void brw_stats_show(struct seq_file *seq, struct brw_stats *brw_stats)
391 {
392         struct timeval  now;
393         char            title[24];
394
395         /* this sampling races with updates */
396         cfs_gettimeofday(&now);
397         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
398                    now.tv_sec, now.tv_usec);
399
400         display_brw_stats(seq, "pages per bulk r/w", "rpcs",
401                           &brw_stats->hist[BRW_R_PAGES],
402                           &brw_stats->hist[BRW_W_PAGES], 1);
403
404         display_brw_stats(seq, "discontiguous pages", "rpcs",
405                           &brw_stats->hist[BRW_R_DISCONT_PAGES],
406                           &brw_stats->hist[BRW_W_DISCONT_PAGES], 0);
407
408         display_brw_stats(seq, "discontiguous blocks", "rpcs",
409                           &brw_stats->hist[BRW_R_DISCONT_BLOCKS],
410                           &brw_stats->hist[BRW_W_DISCONT_BLOCKS], 0);
411
412         display_brw_stats(seq, "disk fragmented I/Os", "ios",
413                           &brw_stats->hist[BRW_R_DIO_FRAGS],
414                           &brw_stats->hist[BRW_W_DIO_FRAGS], 0);
415
416         display_brw_stats(seq, "disk I/Os in flight", "ios",
417                           &brw_stats->hist[BRW_R_RPC_HIST],
418                           &brw_stats->hist[BRW_W_RPC_HIST], 0);
419
420         sprintf(title, "I/O time (1/%ds)", CFS_HZ);
421         display_brw_stats(seq, title, "ios",
422                           &brw_stats->hist[BRW_R_IO_TIME],
423                           &brw_stats->hist[BRW_W_IO_TIME], 1);
424
425         display_brw_stats(seq, "disk I/O size", "ios",
426                           &brw_stats->hist[BRW_R_DISK_IOSIZE],
427                           &brw_stats->hist[BRW_W_DISK_IOSIZE], 1);
428 }
429
430 #undef pct
431
432 static int ofd_brw_stats_seq_show(struct seq_file *seq, void *v)
433 {
434         struct obd_device *dev = seq->private;
435         struct filter_obd *ofd = &dev->u.filter;
436
437         brw_stats_show(seq, &ofd->fo_filter_stats);
438
439         return 0;
440 }
441
442 static ssize_t ofd_brw_stats_seq_write(struct file *file, const char *buf,
443                                        size_t len, loff_t *off)
444 {
445         struct seq_file         *seq = file->private_data;
446         struct obd_device       *dev = seq->private;
447         struct filter_obd       *ofd = &dev->u.filter;
448         int                      i;
449
450         for (i = 0; i < BRW_LAST; i++)
451                 lprocfs_oh_clear(&ofd->fo_filter_stats.hist[i]);
452
453         return len;
454 }
455
456 LPROC_SEQ_FOPS(ofd_brw_stats);
457
458 int lproc_ofd_attach_seqstat(struct obd_device *dev)
459 {
460         return lprocfs_obd_seq_create(dev, "brw_stats", 0444,
461                                       &ofd_brw_stats_fops, dev);
462 }
463
464 void lprocfs_ofd_init_vars(struct lprocfs_static_vars *lvars)
465 {
466         lvars->module_vars  = lprocfs_ofd_module_vars;
467         lvars->obd_vars     = lprocfs_ofd_obd_vars;
468 }
469
470 static int ofd_per_nid_stats_seq_show(struct seq_file *seq, void *v)
471 {
472         nid_stat_t *stat = seq->private;
473
474         if (stat->nid_brw_stats)
475                 brw_stats_show(seq, stat->nid_brw_stats);
476
477         return 0;
478 }
479
480 static ssize_t ofd_per_nid_stats_seq_write(struct file *file, const char *buf,
481                                            size_t len, loff_t *off)
482 {
483         struct seq_file *seq = file->private_data;
484         nid_stat_t      *stat = seq->private;
485         int              i;
486
487         if (stat->nid_brw_stats)
488                 for (i = 0; i < BRW_LAST; i++)
489                         lprocfs_oh_clear(&stat->nid_brw_stats->hist[i]);
490
491         return len;
492 }
493
494 LPROC_SEQ_FOPS(ofd_per_nid_stats);
495 #endif /* LPROCFS */