Whamcloud - gitweb
e806a61d0aec0f6322fa4d3b327c36dbe360765b
[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 static int lprocfs_ofd_rd_capa(char *page, char **start, off_t off,
83                                int count, int *eof, void *data)
84 {
85         struct obd_device       *obd = data;
86         int                      rc;
87
88         rc = snprintf(page, count, "capability on: %s\n",
89                       obd->u.filter.fo_fl_oss_capa ? "oss" : "");
90         return rc;
91 }
92
93 static int lprocfs_ofd_wr_capa(struct file *file, const char *buffer,
94                                unsigned long count, void *data)
95 {
96         struct obd_device       *obd = data;
97         int                      val, rc;
98
99         rc = lprocfs_write_helper(buffer, count, &val);
100         if (rc)
101                 return rc;
102
103         if (val & ~0x1) {
104                 CERROR("invalid capability mode, only 0/1 are accepted.\n"
105                        " 1: enable oss fid capability\n"
106                        " 0: disable oss fid capability\n");
107                 return -EINVAL;
108         }
109
110         obd->u.filter.fo_fl_oss_capa = val;
111         LCONSOLE_INFO("OSS %s %s fid capability.\n", obd->obd_name,
112                       val ? "enabled" : "disabled");
113         return count;
114 }
115
116 static int lprocfs_ofd_rd_capa_count(char *page, char **start, off_t off,
117                                      int count, int *eof, void *data)
118 {
119         return snprintf(page, count, "%d %d\n",
120                         capa_count[CAPA_SITE_CLIENT],
121                         capa_count[CAPA_SITE_SERVER]);
122 }
123
124 int lprocfs_ofd_rd_degraded(char *page, char **start, off_t off,
125                             int count, int *eof, void *data)
126 {
127         struct obd_device *obd = data;
128         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
129
130         return snprintf(page, count, "%u\n", ofd->ofd_raid_degraded);
131 }
132
133 int lprocfs_ofd_wr_degraded(struct file *file, const char *buffer,
134                             unsigned long count, void *data)
135 {
136         struct obd_device       *obd = data;
137         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
138         int                      val, rc;
139
140         rc = lprocfs_write_helper(buffer, count, &val);
141         if (rc)
142                 return rc;
143
144         cfs_spin_lock(&ofd->ofd_flags_lock);
145         ofd->ofd_raid_degraded = !!val;
146         cfs_spin_unlock(&ofd->ofd_flags_lock);
147
148         return count;
149 }
150
151 int lprocfs_ofd_rd_fstype(char *page, char **start, off_t off, int count,
152                           int *eof, void *data)
153 {
154         struct obd_device *obd = data;
155         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
156         struct lu_device  *d;
157
158         LASSERT(ofd->ofd_osd);
159         d = &ofd->ofd_osd->dd_lu_dev;
160         LASSERT(d->ld_type);
161         return snprintf(page, count, "%s\n", d->ld_type->ldt_name);
162 }
163
164 int lprocfs_ofd_rd_syncjournal(char *page, char **start, off_t off,
165                                int count, int *eof, void *data)
166 {
167         struct obd_device       *obd = data;
168         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
169         int                      rc;
170
171         rc = snprintf(page, count, "%u\n", ofd->ofd_syncjournal);
172         return rc;
173 }
174
175 int lprocfs_ofd_wr_syncjournal(struct file *file, const char *buffer,
176                                unsigned long count, void *data)
177 {
178         struct obd_device       *obd = data;
179         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
180         int                      val;
181         int                      rc;
182
183         rc = lprocfs_write_helper(buffer, count, &val);
184         if (rc)
185                 return rc;
186
187         if (val < 0)
188                 return -EINVAL;
189
190         cfs_spin_lock(&ofd->ofd_flags_lock);
191         ofd->ofd_syncjournal = !!val;
192         ofd_slc_set(ofd);
193         cfs_spin_unlock(&ofd->ofd_flags_lock);
194
195         return count;
196 }
197
198 static char *sync_on_cancel_states[] = {"never",
199                                         "blocking",
200                                         "always" };
201
202 int lprocfs_ofd_rd_sync_lock_cancel(char *page, char **start, off_t off,
203                                     int count, int *eof, void *data)
204 {
205         struct obd_device       *obd = data;
206         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
207         int                      rc;
208
209         rc = snprintf(page, count, "%s\n",
210                       sync_on_cancel_states[ofd->ofd_sync_lock_cancel]);
211         return rc;
212 }
213
214 int lprocfs_ofd_wr_sync_lock_cancel(struct file *file, const char *buffer,
215                                     unsigned long count, void *data)
216 {
217         struct obd_device       *obd = data;
218         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
219         int                      val = -1;
220         int                      i;
221
222         for (i = 0 ; i < NUM_SYNC_ON_CANCEL_STATES; i++) {
223                 if (memcmp(buffer, sync_on_cancel_states[i],
224                            strlen(sync_on_cancel_states[i])) == 0) {
225                         val = i;
226                         break;
227                 }
228         }
229         if (val == -1) {
230                 int rc;
231
232                 rc = lprocfs_write_helper(buffer, count, &val);
233                 if (rc)
234                         return rc;
235         }
236
237         if (val < 0 || val > 2)
238                 return -EINVAL;
239
240         cfs_spin_lock(&ofd->ofd_flags_lock);
241         ofd->ofd_sync_lock_cancel = val;
242         cfs_spin_unlock(&ofd->ofd_flags_lock);
243         return count;
244 }
245
246 static struct lprocfs_vars lprocfs_ofd_obd_vars[] = {
247         { "uuid",                lprocfs_rd_uuid, 0, 0 },
248         { "blocksize",           lprocfs_rd_blksize, 0, 0 },
249         { "kbytestotal",         lprocfs_rd_kbytestotal, 0, 0 },
250         { "kbytesfree",          lprocfs_rd_kbytesfree, 0, 0 },
251         { "kbytesavail",         lprocfs_rd_kbytesavail, 0, 0 },
252         { "filestotal",          lprocfs_rd_filestotal, 0, 0 },
253         { "filesfree",           lprocfs_rd_filesfree, 0, 0 },
254         { "filegroups",          lprocfs_ofd_rd_groups, 0, 0 },
255         { "fstype",              lprocfs_ofd_rd_fstype, 0, 0 },
256         { "last_id",             lprocfs_ofd_rd_last_id, 0, 0 },
257         { "recovery_status",     lprocfs_obd_rd_recovery_status, 0, 0 },
258         { "recovery_time_soft",  lprocfs_obd_rd_recovery_time_soft,
259                                  lprocfs_obd_wr_recovery_time_soft, 0},
260         { "recovery_time_hard",  lprocfs_obd_rd_recovery_time_hard,
261                                  lprocfs_obd_wr_recovery_time_hard, 0},
262         { "evict_client",        0, lprocfs_wr_evict_client, 0,
263                                  &lprocfs_evict_client_fops},
264         { "num_exports",         lprocfs_rd_num_exports,   0, 0 },
265         { "degraded",            lprocfs_ofd_rd_degraded,
266                                  lprocfs_ofd_wr_degraded, 0},
267         { "sync_journal",        lprocfs_ofd_rd_syncjournal,
268                                  lprocfs_ofd_wr_syncjournal, 0 },
269         { "sync_on_lock_cancel", lprocfs_ofd_rd_sync_lock_cancel,
270                                  lprocfs_ofd_wr_sync_lock_cancel, 0 },
271         { "instance",            lprocfs_target_rd_instance, 0 },
272         { "ir_factor",           lprocfs_obd_rd_ir_factor,
273                                  lprocfs_obd_wr_ir_factor, 0},
274         { "capa",                lprocfs_ofd_rd_capa,
275                                  lprocfs_ofd_wr_capa, 0 },
276         { "capa_count",          lprocfs_ofd_rd_capa_count, 0, 0 },
277         { 0 }
278 };
279
280 static struct lprocfs_vars lprocfs_ofd_module_vars[] = {
281         { "num_refs",     lprocfs_rd_numrefs,   0, 0 },
282         { 0 }
283 };
284
285 #define pct(a,b) (b ? a * 100 / b : 0)
286
287 static void display_brw_stats(struct seq_file *seq, char *name, char *units,
288                               struct obd_histogram *read,
289                               struct obd_histogram *write, int log2)
290 {
291         unsigned long   read_tot, write_tot, r, w, read_cum = 0, write_cum = 0;
292         int             i;
293
294         seq_printf(seq, "\n%26s read      |     write\n", " ");
295         seq_printf(seq, "%-22s %-5s %% cum %% |  %-5s %% cum %%\n",
296                    name, units, units);
297
298         read_tot = lprocfs_oh_sum(read);
299         write_tot = lprocfs_oh_sum(write);
300         for (i = 0; i < OBD_HIST_MAX; i++) {
301                 r = read->oh_buckets[i];
302                 w = write->oh_buckets[i];
303                 read_cum += r;
304                 write_cum += w;
305                 if (read_cum == 0 && write_cum == 0)
306                         continue;
307
308                 if (!log2)
309                         seq_printf(seq, "%u", i);
310                 else if (i < 10)
311                         seq_printf(seq, "%u", 1 << i);
312                 else if (i < 20)
313                         seq_printf(seq, "%uK", 1 << (i - 10));
314                 else
315                         seq_printf(seq, "%uM", 1 << (i - 20));
316
317                 seq_printf(seq, ":\t\t%10lu %3lu %3lu   | %4lu %3lu %3lu\n",
318                            r, pct(r, read_tot), pct(read_cum, read_tot),
319                            w, pct(w, write_tot), pct(write_cum, write_tot));
320
321                 if (read_cum == read_tot && write_cum == write_tot)
322                         break;
323         }
324 }
325
326 static void brw_stats_show(struct seq_file *seq, struct brw_stats *brw_stats)
327 {
328         struct timeval  now;
329         char            title[24];
330
331         /* this sampling races with updates */
332         cfs_gettimeofday(&now);
333         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
334                    now.tv_sec, now.tv_usec);
335
336         display_brw_stats(seq, "pages per bulk r/w", "rpcs",
337                           &brw_stats->hist[BRW_R_PAGES],
338                           &brw_stats->hist[BRW_W_PAGES], 1);
339
340         display_brw_stats(seq, "discontiguous pages", "rpcs",
341                           &brw_stats->hist[BRW_R_DISCONT_PAGES],
342                           &brw_stats->hist[BRW_W_DISCONT_PAGES], 0);
343
344         display_brw_stats(seq, "discontiguous blocks", "rpcs",
345                           &brw_stats->hist[BRW_R_DISCONT_BLOCKS],
346                           &brw_stats->hist[BRW_W_DISCONT_BLOCKS], 0);
347
348         display_brw_stats(seq, "disk fragmented I/Os", "ios",
349                           &brw_stats->hist[BRW_R_DIO_FRAGS],
350                           &brw_stats->hist[BRW_W_DIO_FRAGS], 0);
351
352         display_brw_stats(seq, "disk I/Os in flight", "ios",
353                           &brw_stats->hist[BRW_R_RPC_HIST],
354                           &brw_stats->hist[BRW_W_RPC_HIST], 0);
355
356         sprintf(title, "I/O time (1/%ds)", CFS_HZ);
357         display_brw_stats(seq, title, "ios",
358                           &brw_stats->hist[BRW_R_IO_TIME],
359                           &brw_stats->hist[BRW_W_IO_TIME], 1);
360
361         display_brw_stats(seq, "disk I/O size", "ios",
362                           &brw_stats->hist[BRW_R_DISK_IOSIZE],
363                           &brw_stats->hist[BRW_W_DISK_IOSIZE], 1);
364 }
365
366 #undef pct
367
368 static int ofd_brw_stats_seq_show(struct seq_file *seq, void *v)
369 {
370         struct obd_device *dev = seq->private;
371         struct filter_obd *ofd = &dev->u.filter;
372
373         brw_stats_show(seq, &ofd->fo_filter_stats);
374
375         return 0;
376 }
377
378 static ssize_t ofd_brw_stats_seq_write(struct file *file, const char *buf,
379                                        size_t len, loff_t *off)
380 {
381         struct seq_file         *seq = file->private_data;
382         struct obd_device       *dev = seq->private;
383         struct filter_obd       *ofd = &dev->u.filter;
384         int                      i;
385
386         for (i = 0; i < BRW_LAST; i++)
387                 lprocfs_oh_clear(&ofd->fo_filter_stats.hist[i]);
388
389         return len;
390 }
391
392 LPROC_SEQ_FOPS(ofd_brw_stats);
393
394 int lproc_ofd_attach_seqstat(struct obd_device *dev)
395 {
396         return lprocfs_obd_seq_create(dev, "brw_stats", 0444,
397                                       &ofd_brw_stats_fops, dev);
398 }
399
400 void lprocfs_ofd_init_vars(struct lprocfs_static_vars *lvars)
401 {
402         lvars->module_vars  = lprocfs_ofd_module_vars;
403         lvars->obd_vars     = lprocfs_ofd_obd_vars;
404 }
405
406 static int ofd_per_nid_stats_seq_show(struct seq_file *seq, void *v)
407 {
408         nid_stat_t *stat = seq->private;
409
410         if (stat->nid_brw_stats)
411                 brw_stats_show(seq, stat->nid_brw_stats);
412
413         return 0;
414 }
415
416 static ssize_t ofd_per_nid_stats_seq_write(struct file *file, const char *buf,
417                                            size_t len, loff_t *off)
418 {
419         struct seq_file *seq = file->private_data;
420         nid_stat_t      *stat = seq->private;
421         int              i;
422
423         if (stat->nid_brw_stats)
424                 for (i = 0; i < BRW_LAST; i++)
425                         lprocfs_oh_clear(&stat->nid_brw_stats->hist[i]);
426
427         return len;
428 }
429
430 LPROC_SEQ_FOPS(ofd_per_nid_stats);
431 #endif /* LPROCFS */