Whamcloud - gitweb
LU-1842 quota: remove quota code
[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 #include <lquota.h>
45
46 #include "ofd_internal.h"
47
48 #ifdef LPROCFS
49
50 static int lprocfs_ofd_rd_groups(char *page, char **start, off_t off,
51                                  int count, int *eof, void *data)
52 {
53         struct obd_device *obd = (struct obd_device *)data;
54         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
55
56         *eof = 1;
57         return snprintf(page, count, "%u\n", ofd->ofd_max_group);
58 }
59
60 static int lprocfs_ofd_rd_tot_dirty(char *page, char **start, off_t off,
61                                     int count, int *eof, void *data)
62 {
63         struct obd_device *obd = (struct obd_device *)data;
64         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
65
66         LASSERT(obd != NULL);
67         *eof = 1;
68         return snprintf(page, count, LPU64"\n", ofd->ofd_tot_dirty);
69 }
70
71 static int lprocfs_ofd_rd_tot_granted(char *page, char **start, off_t off,
72                                       int count, int *eof, void *data)
73 {
74         struct obd_device *obd = (struct obd_device *)data;
75         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
76
77         LASSERT(obd != NULL);
78         *eof = 1;
79         return snprintf(page, count, LPU64"\n", ofd->ofd_tot_granted);
80 }
81
82 static int lprocfs_ofd_rd_tot_pending(char *page, char **start, off_t off,
83                                       int count, int *eof, void *data)
84 {
85         struct obd_device *obd = (struct obd_device *)data;
86         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
87
88         LASSERT(obd != NULL);
89         *eof = 1;
90         return snprintf(page, count, LPU64"\n", ofd->ofd_tot_pending);
91 }
92
93 static int lprocfs_ofd_rd_grant_precreate(char *page, char **start, off_t off,
94                                           int count, int *eof, void *data)
95 {
96         struct obd_device *obd = (struct obd_device *)data;
97
98         LASSERT(obd != NULL);
99         *eof = 1;
100         return snprintf(page, count, "%ld\n",
101                         obd->obd_self_export->exp_filter_data.fed_grant);
102 }
103
104 static int lprocfs_ofd_rd_grant_ratio(char *page, char **start, off_t off,
105                                       int count, int *eof, void *data)
106 {
107         struct obd_device *obd = (struct obd_device *)data;
108         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
109
110         LASSERT(obd != NULL);
111         *eof = 1;
112         return snprintf(page, count, "%d%%\n",
113                         (int) ofd_grant_reserved(ofd, 100));
114 }
115
116 static int lprocfs_ofd_wr_grant_ratio(struct file *file, const char *buffer,
117                                       unsigned long count, void *data)
118 {
119         struct obd_device       *obd = (struct obd_device *)data;
120         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
121         int                      val;
122         int                      rc;
123
124         rc = lprocfs_write_helper(buffer, count, &val);
125         if (rc)
126                 return rc;
127
128         if (val > 100 || val < 0)
129                 return -EINVAL;
130
131         if (val == 0)
132                 CWARN("%s: disabling grant error margin\n", obd->obd_name);
133         if (val > 50)
134                 CWARN("%s: setting grant error margin >50%%, be warned that "
135                       "a huge part of the free space is now reserved for "
136                       "grants\n", obd->obd_name);
137
138         cfs_spin_lock(&ofd->ofd_grant_lock);
139         ofd->ofd_grant_ratio = ofd_grant_ratio_conv(val);
140         cfs_spin_unlock(&ofd->ofd_grant_lock);
141         return count;
142 }
143
144 static int lprocfs_ofd_rd_last_id(char *page, char **start, off_t off,
145                                   int count, int *eof, void *data)
146 {
147         struct obd_device       *obd = data;
148         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
149         int                      retval = 0, rc, i;
150
151         if (obd == NULL)
152                 return 0;
153
154         for (i = FID_SEQ_OST_MDT0; i <= ofd->ofd_max_group; i++) {
155                 rc = snprintf(page, count, LPU64"\n", ofd_last_id(ofd, i));
156                 if (rc < 0) {
157                         retval = rc;
158                         break;
159                 }
160                 page += rc;
161                 count -= rc;
162                 retval += rc;
163         }
164         return retval;
165 }
166
167 int lprocfs_ofd_rd_fmd_max_num(char *page, char **start, off_t off,
168                                int count, int *eof, void *data)
169 {
170         struct obd_device       *obd = data;
171         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
172         int                      rc;
173
174         rc = snprintf(page, count, "%u\n", ofd->ofd_fmd_max_num);
175         return rc;
176 }
177
178 int lprocfs_ofd_wr_fmd_max_num(struct file *file, const char *buffer,
179                                unsigned long count, void *data)
180 {
181         struct obd_device       *obd = data;
182         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
183         int                      val;
184         int                      rc;
185
186         rc = lprocfs_write_helper(buffer, count, &val);
187         if (rc)
188                 return rc;
189
190         if (val > 65536 || val < 1)
191                 return -EINVAL;
192
193         ofd->ofd_fmd_max_num = val;
194         return count;
195 }
196
197 int lprocfs_ofd_rd_fmd_max_age(char *page, char **start, off_t off,
198                                int count, int *eof, void *data)
199 {
200         struct obd_device       *obd = data;
201         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
202         int                      rc;
203
204         rc = snprintf(page, count, "%ld\n", ofd->ofd_fmd_max_age / CFS_HZ);
205         return rc;
206 }
207
208 int lprocfs_ofd_wr_fmd_max_age(struct file *file, const char *buffer,
209                                unsigned long count, void *data)
210 {
211         struct obd_device       *obd = data;
212         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
213         int                      val;
214         int                      rc;
215
216         rc = lprocfs_write_helper(buffer, count, &val);
217         if (rc)
218                 return rc;
219
220         if (val > 65536 || val < 1)
221                 return -EINVAL;
222
223         ofd->ofd_fmd_max_age = val * CFS_HZ;
224         return count;
225 }
226
227 static int lprocfs_ofd_rd_capa(char *page, char **start, off_t off,
228                                int count, int *eof, void *data)
229 {
230         struct obd_device       *obd = data;
231         int                      rc;
232
233         rc = snprintf(page, count, "capability on: %s\n",
234                       obd->u.filter.fo_fl_oss_capa ? "oss" : "");
235         return rc;
236 }
237
238 static int lprocfs_ofd_wr_capa(struct file *file, const char *buffer,
239                                unsigned long count, void *data)
240 {
241         struct obd_device       *obd = data;
242         int                      val, rc;
243
244         rc = lprocfs_write_helper(buffer, count, &val);
245         if (rc)
246                 return rc;
247
248         if (val & ~0x1) {
249                 CERROR("invalid capability mode, only 0/1 are accepted.\n"
250                        " 1: enable oss fid capability\n"
251                        " 0: disable oss fid capability\n");
252                 return -EINVAL;
253         }
254
255         obd->u.filter.fo_fl_oss_capa = val;
256         LCONSOLE_INFO("OSS %s %s fid capability.\n", obd->obd_name,
257                       val ? "enabled" : "disabled");
258         return count;
259 }
260
261 static int lprocfs_ofd_rd_capa_count(char *page, char **start, off_t off,
262                                      int count, int *eof, void *data)
263 {
264         return snprintf(page, count, "%d %d\n",
265                         capa_count[CAPA_SITE_CLIENT],
266                         capa_count[CAPA_SITE_SERVER]);
267 }
268
269 int lprocfs_ofd_rd_degraded(char *page, char **start, off_t off,
270                             int count, int *eof, void *data)
271 {
272         struct obd_device *obd = data;
273         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
274
275         return snprintf(page, count, "%u\n", ofd->ofd_raid_degraded);
276 }
277
278 int lprocfs_ofd_wr_degraded(struct file *file, const char *buffer,
279                             unsigned long count, void *data)
280 {
281         struct obd_device       *obd = data;
282         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
283         int                      val, rc;
284
285         rc = lprocfs_write_helper(buffer, count, &val);
286         if (rc)
287                 return rc;
288
289         cfs_spin_lock(&ofd->ofd_flags_lock);
290         ofd->ofd_raid_degraded = !!val;
291         cfs_spin_unlock(&ofd->ofd_flags_lock);
292
293         return count;
294 }
295
296 int lprocfs_ofd_rd_fstype(char *page, char **start, off_t off, int count,
297                           int *eof, void *data)
298 {
299         struct obd_device *obd = data;
300         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
301         struct lu_device  *d;
302
303         LASSERT(ofd->ofd_osd);
304         d = &ofd->ofd_osd->dd_lu_dev;
305         LASSERT(d->ld_type);
306         return snprintf(page, count, "%s\n", d->ld_type->ldt_name);
307 }
308
309 int lprocfs_ofd_rd_syncjournal(char *page, char **start, off_t off,
310                                int count, int *eof, void *data)
311 {
312         struct obd_device       *obd = data;
313         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
314         int                      rc;
315
316         rc = snprintf(page, count, "%u\n", ofd->ofd_syncjournal);
317         return rc;
318 }
319
320 int lprocfs_ofd_wr_syncjournal(struct file *file, const char *buffer,
321                                unsigned long count, void *data)
322 {
323         struct obd_device       *obd = data;
324         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
325         int                      val;
326         int                      rc;
327
328         rc = lprocfs_write_helper(buffer, count, &val);
329         if (rc)
330                 return rc;
331
332         if (val < 0)
333                 return -EINVAL;
334
335         cfs_spin_lock(&ofd->ofd_flags_lock);
336         ofd->ofd_syncjournal = !!val;
337         ofd_slc_set(ofd);
338         cfs_spin_unlock(&ofd->ofd_flags_lock);
339
340         return count;
341 }
342
343 static char *sync_on_cancel_states[] = {"never",
344                                         "blocking",
345                                         "always" };
346
347 int lprocfs_ofd_rd_sync_lock_cancel(char *page, char **start, off_t off,
348                                     int count, int *eof, void *data)
349 {
350         struct obd_device       *obd = data;
351         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
352         int                      rc;
353
354         rc = snprintf(page, count, "%s\n",
355                       sync_on_cancel_states[ofd->ofd_sync_lock_cancel]);
356         return rc;
357 }
358
359 int lprocfs_ofd_wr_sync_lock_cancel(struct file *file, const char *buffer,
360                                     unsigned long count, void *data)
361 {
362         struct obd_device       *obd = data;
363         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
364         int                      val = -1;
365         int                      i;
366
367         for (i = 0 ; i < NUM_SYNC_ON_CANCEL_STATES; i++) {
368                 if (memcmp(buffer, sync_on_cancel_states[i],
369                            strlen(sync_on_cancel_states[i])) == 0) {
370                         val = i;
371                         break;
372                 }
373         }
374         if (val == -1) {
375                 int rc;
376
377                 rc = lprocfs_write_helper(buffer, count, &val);
378                 if (rc)
379                         return rc;
380         }
381
382         if (val < 0 || val > 2)
383                 return -EINVAL;
384
385         cfs_spin_lock(&ofd->ofd_flags_lock);
386         ofd->ofd_sync_lock_cancel = val;
387         cfs_spin_unlock(&ofd->ofd_flags_lock);
388         return count;
389 }
390
391 int lprocfs_ofd_rd_grant_compat_disable(char *page, char **start, off_t off,
392                                         int count, int *eof, void *data)
393 {
394         struct obd_device       *obd = data;
395         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
396         int                      rc;
397
398         rc = snprintf(page, count, "%u\n", ofd->ofd_grant_compat_disable);
399         return rc;
400 }
401
402 int lprocfs_ofd_wr_grant_compat_disable(struct file *file, const char *buffer,
403                                         unsigned long count, void *data)
404 {
405         struct obd_device       *obd = data;
406         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
407         int                      val;
408         int                      rc;
409
410         rc = lprocfs_write_helper(buffer, count, &val);
411         if (rc)
412                 return rc;
413
414         if (val < 0)
415                 return -EINVAL;
416
417         cfs_spin_lock(&ofd->ofd_flags_lock);
418         ofd->ofd_grant_compat_disable = !!val;
419         cfs_spin_unlock(&ofd->ofd_flags_lock);
420
421         return count;
422 }
423
424 static struct lprocfs_vars lprocfs_ofd_obd_vars[] = {
425         { "uuid",                lprocfs_rd_uuid, 0, 0 },
426         { "blocksize",           lprocfs_rd_blksize, 0, 0 },
427         { "kbytestotal",         lprocfs_rd_kbytestotal, 0, 0 },
428         { "kbytesfree",          lprocfs_rd_kbytesfree, 0, 0 },
429         { "kbytesavail",         lprocfs_rd_kbytesavail, 0, 0 },
430         { "filestotal",          lprocfs_rd_filestotal, 0, 0 },
431         { "filesfree",           lprocfs_rd_filesfree, 0, 0 },
432         { "filegroups",          lprocfs_ofd_rd_groups, 0, 0 },
433         { "fstype",              lprocfs_ofd_rd_fstype, 0, 0 },
434         { "last_id",             lprocfs_ofd_rd_last_id, 0, 0 },
435         { "tot_dirty",           lprocfs_ofd_rd_tot_dirty,   0, 0 },
436         { "tot_pending",         lprocfs_ofd_rd_tot_pending, 0, 0 },
437         { "tot_granted",         lprocfs_ofd_rd_tot_granted, 0, 0 },
438         { "grant_precreate",     lprocfs_ofd_rd_grant_precreate, 0, 0 },
439         { "grant_ratio",         lprocfs_ofd_rd_grant_ratio,
440                                  lprocfs_ofd_wr_grant_ratio, 0, 0 },
441         { "recovery_status",     lprocfs_obd_rd_recovery_status, 0, 0 },
442         { "recovery_time_soft",  lprocfs_obd_rd_recovery_time_soft,
443                                  lprocfs_obd_wr_recovery_time_soft, 0},
444         { "recovery_time_hard",  lprocfs_obd_rd_recovery_time_hard,
445                                  lprocfs_obd_wr_recovery_time_hard, 0},
446         { "evict_client",        0, lprocfs_wr_evict_client, 0,
447                                  &lprocfs_evict_client_fops},
448         { "num_exports",         lprocfs_rd_num_exports,   0, 0 },
449         { "degraded",            lprocfs_ofd_rd_degraded,
450                                  lprocfs_ofd_wr_degraded, 0},
451         { "sync_journal",        lprocfs_ofd_rd_syncjournal,
452                                  lprocfs_ofd_wr_syncjournal, 0 },
453         { "sync_on_lock_cancel", lprocfs_ofd_rd_sync_lock_cancel,
454                                  lprocfs_ofd_wr_sync_lock_cancel, 0 },
455         { "instance",            lprocfs_target_rd_instance, 0 },
456         { "ir_factor",           lprocfs_obd_rd_ir_factor,
457                                  lprocfs_obd_wr_ir_factor, 0},
458         { "grant_compat_disable", lprocfs_ofd_rd_grant_compat_disable,
459                                   lprocfs_ofd_wr_grant_compat_disable, 0 },
460         { "client_cache_count",  lprocfs_ofd_rd_fmd_max_num,
461                                  lprocfs_ofd_wr_fmd_max_num, 0 },
462         { "client_cache_seconds", lprocfs_ofd_rd_fmd_max_age,
463                                   lprocfs_ofd_wr_fmd_max_age, 0 },
464         { "capa",                lprocfs_ofd_rd_capa,
465                                  lprocfs_ofd_wr_capa, 0 },
466         { "capa_count",          lprocfs_ofd_rd_capa_count, 0, 0 },
467         { 0 }
468 };
469
470 static struct lprocfs_vars lprocfs_ofd_module_vars[] = {
471         { "num_refs",     lprocfs_rd_numrefs,   0, 0 },
472         { 0 }
473 };
474
475 #define pct(a,b) (b ? a * 100 / b : 0)
476
477 static void display_brw_stats(struct seq_file *seq, char *name, char *units,
478                               struct obd_histogram *read,
479                               struct obd_histogram *write, int log2)
480 {
481         unsigned long   read_tot, write_tot, r, w, read_cum = 0, write_cum = 0;
482         int             i;
483
484         seq_printf(seq, "\n%26s read      |     write\n", " ");
485         seq_printf(seq, "%-22s %-5s %% cum %% |  %-5s %% cum %%\n",
486                    name, units, units);
487
488         read_tot = lprocfs_oh_sum(read);
489         write_tot = lprocfs_oh_sum(write);
490         for (i = 0; i < OBD_HIST_MAX; i++) {
491                 r = read->oh_buckets[i];
492                 w = write->oh_buckets[i];
493                 read_cum += r;
494                 write_cum += w;
495                 if (read_cum == 0 && write_cum == 0)
496                         continue;
497
498                 if (!log2)
499                         seq_printf(seq, "%u", i);
500                 else if (i < 10)
501                         seq_printf(seq, "%u", 1 << i);
502                 else if (i < 20)
503                         seq_printf(seq, "%uK", 1 << (i - 10));
504                 else
505                         seq_printf(seq, "%uM", 1 << (i - 20));
506
507                 seq_printf(seq, ":\t\t%10lu %3lu %3lu   | %4lu %3lu %3lu\n",
508                            r, pct(r, read_tot), pct(read_cum, read_tot),
509                            w, pct(w, write_tot), pct(write_cum, write_tot));
510
511                 if (read_cum == read_tot && write_cum == write_tot)
512                         break;
513         }
514 }
515
516 static void brw_stats_show(struct seq_file *seq, struct brw_stats *brw_stats)
517 {
518         struct timeval  now;
519         char            title[24];
520
521         /* this sampling races with updates */
522         cfs_gettimeofday(&now);
523         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
524                    now.tv_sec, now.tv_usec);
525
526         display_brw_stats(seq, "pages per bulk r/w", "rpcs",
527                           &brw_stats->hist[BRW_R_PAGES],
528                           &brw_stats->hist[BRW_W_PAGES], 1);
529
530         display_brw_stats(seq, "discontiguous pages", "rpcs",
531                           &brw_stats->hist[BRW_R_DISCONT_PAGES],
532                           &brw_stats->hist[BRW_W_DISCONT_PAGES], 0);
533
534         display_brw_stats(seq, "discontiguous blocks", "rpcs",
535                           &brw_stats->hist[BRW_R_DISCONT_BLOCKS],
536                           &brw_stats->hist[BRW_W_DISCONT_BLOCKS], 0);
537
538         display_brw_stats(seq, "disk fragmented I/Os", "ios",
539                           &brw_stats->hist[BRW_R_DIO_FRAGS],
540                           &brw_stats->hist[BRW_W_DIO_FRAGS], 0);
541
542         display_brw_stats(seq, "disk I/Os in flight", "ios",
543                           &brw_stats->hist[BRW_R_RPC_HIST],
544                           &brw_stats->hist[BRW_W_RPC_HIST], 0);
545
546         sprintf(title, "I/O time (1/%ds)", CFS_HZ);
547         display_brw_stats(seq, title, "ios",
548                           &brw_stats->hist[BRW_R_IO_TIME],
549                           &brw_stats->hist[BRW_W_IO_TIME], 1);
550
551         display_brw_stats(seq, "disk I/O size", "ios",
552                           &brw_stats->hist[BRW_R_DISK_IOSIZE],
553                           &brw_stats->hist[BRW_W_DISK_IOSIZE], 1);
554 }
555
556 #undef pct
557
558 static int ofd_brw_stats_seq_show(struct seq_file *seq, void *v)
559 {
560         struct obd_device *dev = seq->private;
561         struct filter_obd *ofd = &dev->u.filter;
562
563         brw_stats_show(seq, &ofd->fo_filter_stats);
564
565         return 0;
566 }
567
568 static ssize_t ofd_brw_stats_seq_write(struct file *file, const char *buf,
569                                        size_t len, loff_t *off)
570 {
571         struct seq_file         *seq = file->private_data;
572         struct obd_device       *dev = seq->private;
573         struct filter_obd       *ofd = &dev->u.filter;
574         int                      i;
575
576         for (i = 0; i < BRW_LAST; i++)
577                 lprocfs_oh_clear(&ofd->fo_filter_stats.hist[i]);
578
579         return len;
580 }
581
582 LPROC_SEQ_FOPS(ofd_brw_stats);
583
584 int lproc_ofd_attach_seqstat(struct obd_device *dev)
585 {
586         return lprocfs_obd_seq_create(dev, "brw_stats", 0444,
587                                       &ofd_brw_stats_fops, dev);
588 }
589
590 void lprocfs_ofd_init_vars(struct lprocfs_static_vars *lvars)
591 {
592         lvars->module_vars  = lprocfs_ofd_module_vars;
593         lvars->obd_vars     = lprocfs_ofd_obd_vars;
594 }
595
596 static int ofd_per_nid_stats_seq_show(struct seq_file *seq, void *v)
597 {
598         nid_stat_t *stat = seq->private;
599
600         if (stat->nid_brw_stats)
601                 brw_stats_show(seq, stat->nid_brw_stats);
602
603         return 0;
604 }
605
606 static ssize_t ofd_per_nid_stats_seq_write(struct file *file, const char *buf,
607                                            size_t len, loff_t *off)
608 {
609         struct seq_file *seq = file->private_data;
610         nid_stat_t      *stat = seq->private;
611         int              i;
612
613         if (stat->nid_brw_stats)
614                 for (i = 0; i < BRW_LAST; i++)
615                         lprocfs_oh_clear(&stat->nid_brw_stats->hist[i]);
616
617         return len;
618 }
619
620 LPROC_SEQ_FOPS(ofd_per_nid_stats);
621 #endif /* LPROCFS */