Whamcloud - gitweb
089271abe9d63ffeee2b3352788d67ae698c313c
[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) 2012, 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/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_seqs(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_seq_count);
57 }
58
59 static int lprocfs_ofd_rd_tot_dirty(char *page, char **start, off_t off,
60                                     int count, int *eof, void *data)
61 {
62         struct obd_device *obd = (struct obd_device *)data;
63         struct ofd_device *ofd;
64
65         LASSERT(obd != NULL);
66         ofd = ofd_dev(obd->obd_lu_dev);
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;
76
77         LASSERT(obd != NULL);
78         ofd = ofd_dev(obd->obd_lu_dev);
79         *eof = 1;
80         return snprintf(page, count, LPU64"\n", ofd->ofd_tot_granted);
81 }
82
83 static int lprocfs_ofd_rd_tot_pending(char *page, char **start, off_t off,
84                                       int count, int *eof, void *data)
85 {
86         struct obd_device *obd = (struct obd_device *)data;
87         struct ofd_device *ofd;
88
89         LASSERT(obd != NULL);
90         ofd = ofd_dev(obd->obd_lu_dev);
91         *eof = 1;
92         return snprintf(page, count, LPU64"\n", ofd->ofd_tot_pending);
93 }
94
95 static int lprocfs_ofd_rd_grant_precreate(char *page, char **start, off_t off,
96                                           int count, int *eof, void *data)
97 {
98         struct obd_device *obd = (struct obd_device *)data;
99
100         LASSERT(obd != NULL);
101         *eof = 1;
102         return snprintf(page, count, "%ld\n",
103                         obd->obd_self_export->exp_filter_data.fed_grant);
104 }
105
106 static int lprocfs_ofd_rd_grant_ratio(char *page, char **start, off_t off,
107                                       int count, int *eof, void *data)
108 {
109         struct obd_device *obd = (struct obd_device *)data;
110         struct ofd_device *ofd;
111
112         LASSERT(obd != NULL);
113         ofd = ofd_dev(obd->obd_lu_dev);
114         *eof = 1;
115         return snprintf(page, count, "%d%%\n",
116                         (int) ofd_grant_reserved(ofd, 100));
117 }
118
119 static int lprocfs_ofd_wr_grant_ratio(struct file *file, const char *buffer,
120                                       unsigned long count, void *data)
121 {
122         struct obd_device       *obd = (struct obd_device *)data;
123         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
124         int                      val;
125         int                      rc;
126
127         rc = lprocfs_write_helper(buffer, count, &val);
128         if (rc)
129                 return rc;
130
131         if (val > 100 || val < 0)
132                 return -EINVAL;
133
134         if (val == 0)
135                 CWARN("%s: disabling grant error margin\n", obd->obd_name);
136         if (val > 50)
137                 CWARN("%s: setting grant error margin >50%%, be warned that "
138                       "a huge part of the free space is now reserved for "
139                       "grants\n", obd->obd_name);
140
141         spin_lock(&ofd->ofd_grant_lock);
142         ofd->ofd_grant_ratio = ofd_grant_ratio_conv(val);
143         spin_unlock(&ofd->ofd_grant_lock);
144         return count;
145 }
146
147 static int lprocfs_ofd_rd_precreate_batch(char *page, char **start, off_t off,
148                                           int count, int *eof, void *data)
149 {
150         struct obd_device *obd = (struct obd_device *)data;
151         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
152
153         LASSERT(obd != NULL);
154         *eof = 1;
155         return snprintf(page, count, "%d\n", ofd->ofd_precreate_batch);
156 }
157
158 static int lprocfs_ofd_wr_precreate_batch(struct file *file, const char *buffer,
159                                           unsigned long count, void *data)
160 {
161         struct obd_device *obd = (struct obd_device *)data;
162         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
163         int val;
164         int rc;
165
166         rc = lprocfs_write_helper(buffer, count, &val);
167         if (rc)
168                 return rc;
169
170         if (val < 1)
171                 return -EINVAL;
172
173         spin_lock(&ofd->ofd_batch_lock);
174         ofd->ofd_precreate_batch = val;
175         spin_unlock(&ofd->ofd_batch_lock);
176         return count;
177 }
178
179 static int lprocfs_ofd_rd_last_id(char *page, char **start, off_t off,
180                                   int count, int *eof, void *data)
181 {
182         struct obd_device       *obd = data;
183         struct ofd_device       *ofd;
184         struct ofd_seq          *oseq = NULL;
185         int                     retval = 0, rc;
186
187         if (obd == NULL)
188                 return 0;
189
190         ofd = ofd_dev(obd->obd_lu_dev);
191
192         read_lock(&ofd->ofd_seq_list_lock);
193         cfs_list_for_each_entry(oseq, &ofd->ofd_seq_list, os_list) {
194                 __u64 seq;
195
196                 seq = ostid_seq(&oseq->os_oi) == 0 ?
197                       fid_idif_seq(ostid_id(&oseq->os_oi),
198                                    ofd->ofd_lut.lut_lsd.lsd_osd_index) :
199                       ostid_seq(&oseq->os_oi);
200                 rc = snprintf(page, count, DOSTID"\n", seq,
201                               ostid_id(&oseq->os_oi));
202                 if (rc < 0) {
203                         retval = rc;
204                         break;
205                 }
206                 page += rc;
207                 count -= rc;
208                 retval += rc;
209         }
210         read_unlock(&ofd->ofd_seq_list_lock);
211         return retval;
212 }
213
214 int lprocfs_ofd_rd_fmd_max_num(char *page, char **start, off_t off,
215                                int count, int *eof, void *data)
216 {
217         struct obd_device       *obd = data;
218         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
219         int                      rc;
220
221         rc = snprintf(page, count, "%u\n", ofd->ofd_fmd_max_num);
222         return rc;
223 }
224
225 int lprocfs_ofd_wr_fmd_max_num(struct file *file, const char *buffer,
226                                unsigned long count, void *data)
227 {
228         struct obd_device       *obd = data;
229         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
230         int                      val;
231         int                      rc;
232
233         rc = lprocfs_write_helper(buffer, count, &val);
234         if (rc)
235                 return rc;
236
237         if (val > 65536 || val < 1)
238                 return -EINVAL;
239
240         ofd->ofd_fmd_max_num = val;
241         return count;
242 }
243
244 int lprocfs_ofd_rd_fmd_max_age(char *page, char **start, off_t off,
245                                int count, int *eof, void *data)
246 {
247         struct obd_device       *obd = data;
248         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
249         int                      rc;
250
251         rc = snprintf(page, count, "%ld\n", ofd->ofd_fmd_max_age / HZ);
252         return rc;
253 }
254
255 int lprocfs_ofd_wr_fmd_max_age(struct file *file, const char *buffer,
256                                unsigned long count, void *data)
257 {
258         struct obd_device       *obd = data;
259         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
260         int                      val;
261         int                      rc;
262
263         rc = lprocfs_write_helper(buffer, count, &val);
264         if (rc)
265                 return rc;
266
267         if (val > 65536 || val < 1)
268                 return -EINVAL;
269
270         ofd->ofd_fmd_max_age = val * HZ;
271         return count;
272 }
273
274 static int lprocfs_ofd_rd_capa(char *page, char **start, off_t off,
275                                int count, int *eof, void *data)
276 {
277         struct obd_device       *obd = data;
278         int                      rc;
279
280         rc = snprintf(page, count, "capability on: %s\n",
281                       obd->u.filter.fo_fl_oss_capa ? "oss" : "");
282         return rc;
283 }
284
285 static int lprocfs_ofd_wr_capa(struct file *file, const char *buffer,
286                                unsigned long count, void *data)
287 {
288         struct obd_device       *obd = data;
289         int                      val, rc;
290
291         rc = lprocfs_write_helper(buffer, count, &val);
292         if (rc)
293                 return rc;
294
295         if (val & ~0x1) {
296                 CERROR("invalid capability mode, only 0/1 are accepted.\n"
297                        " 1: enable oss fid capability\n"
298                        " 0: disable oss fid capability\n");
299                 return -EINVAL;
300         }
301
302         obd->u.filter.fo_fl_oss_capa = val;
303         LCONSOLE_INFO("OSS %s %s fid capability.\n", obd->obd_name,
304                       val ? "enabled" : "disabled");
305         return count;
306 }
307
308 static int lprocfs_ofd_rd_capa_count(char *page, char **start, off_t off,
309                                      int count, int *eof, void *data)
310 {
311         return snprintf(page, count, "%d %d\n",
312                         capa_count[CAPA_SITE_CLIENT],
313                         capa_count[CAPA_SITE_SERVER]);
314 }
315
316 int lprocfs_ofd_rd_degraded(char *page, char **start, off_t off,
317                             int count, int *eof, void *data)
318 {
319         struct obd_device *obd = data;
320         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
321
322         return snprintf(page, count, "%u\n", ofd->ofd_raid_degraded);
323 }
324
325 int lprocfs_ofd_wr_degraded(struct file *file, const char *buffer,
326                             unsigned long count, void *data)
327 {
328         struct obd_device       *obd = data;
329         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
330         int                      val, rc;
331
332         rc = lprocfs_write_helper(buffer, count, &val);
333         if (rc)
334                 return rc;
335
336         spin_lock(&ofd->ofd_flags_lock);
337         ofd->ofd_raid_degraded = !!val;
338         spin_unlock(&ofd->ofd_flags_lock);
339
340         return count;
341 }
342
343 int lprocfs_ofd_rd_fstype(char *page, char **start, off_t off, int count,
344                           int *eof, void *data)
345 {
346         struct obd_device *obd = data;
347         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
348         struct lu_device  *d;
349
350         LASSERT(ofd->ofd_osd);
351         d = &ofd->ofd_osd->dd_lu_dev;
352         LASSERT(d->ld_type);
353         return snprintf(page, count, "%s\n", d->ld_type->ldt_name);
354 }
355
356 int lprocfs_ofd_rd_syncjournal(char *page, char **start, off_t off,
357                                int count, int *eof, void *data)
358 {
359         struct obd_device       *obd = data;
360         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
361         int                      rc;
362
363         rc = snprintf(page, count, "%u\n", ofd->ofd_syncjournal);
364         return rc;
365 }
366
367 int lprocfs_ofd_wr_syncjournal(struct file *file, const char *buffer,
368                                unsigned long count, void *data)
369 {
370         struct obd_device       *obd = data;
371         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
372         int                      val;
373         int                      rc;
374
375         rc = lprocfs_write_helper(buffer, count, &val);
376         if (rc)
377                 return rc;
378
379         if (val < 0)
380                 return -EINVAL;
381
382         spin_lock(&ofd->ofd_flags_lock);
383         ofd->ofd_syncjournal = !!val;
384         ofd_slc_set(ofd);
385         spin_unlock(&ofd->ofd_flags_lock);
386
387         return count;
388 }
389
390 static char *sync_on_cancel_states[] = {"never",
391                                         "blocking",
392                                         "always" };
393
394 int lprocfs_ofd_rd_sync_lock_cancel(char *page, char **start, off_t off,
395                                     int count, int *eof, void *data)
396 {
397         struct obd_device       *obd = data;
398         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
399         int                      rc;
400
401         rc = snprintf(page, count, "%s\n",
402                       sync_on_cancel_states[ofd->ofd_sync_lock_cancel]);
403         return rc;
404 }
405
406 int lprocfs_ofd_wr_sync_lock_cancel(struct file *file, const char *buffer,
407                                     unsigned long count, void *data)
408 {
409         struct obd_device       *obd = data;
410         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
411         int                      val = -1;
412         int                      i;
413
414         for (i = 0 ; i < NUM_SYNC_ON_CANCEL_STATES; i++) {
415                 if (memcmp(buffer, sync_on_cancel_states[i],
416                            strlen(sync_on_cancel_states[i])) == 0) {
417                         val = i;
418                         break;
419                 }
420         }
421         if (val == -1) {
422                 int rc;
423
424                 rc = lprocfs_write_helper(buffer, count, &val);
425                 if (rc)
426                         return rc;
427         }
428
429         if (val < 0 || val > 2)
430                 return -EINVAL;
431
432         spin_lock(&ofd->ofd_flags_lock);
433         ofd->ofd_sync_lock_cancel = val;
434         spin_unlock(&ofd->ofd_flags_lock);
435         return count;
436 }
437
438 int lprocfs_ofd_rd_grant_compat_disable(char *page, char **start, off_t off,
439                                         int count, int *eof, void *data)
440 {
441         struct obd_device       *obd = data;
442         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
443         int                      rc;
444
445         rc = snprintf(page, count, "%u\n", ofd->ofd_grant_compat_disable);
446         return rc;
447 }
448
449 int lprocfs_ofd_wr_grant_compat_disable(struct file *file, const char *buffer,
450                                         unsigned long count, void *data)
451 {
452         struct obd_device       *obd = data;
453         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
454         int                      val;
455         int                      rc;
456
457         rc = lprocfs_write_helper(buffer, count, &val);
458         if (rc)
459                 return rc;
460
461         if (val < 0)
462                 return -EINVAL;
463
464         spin_lock(&ofd->ofd_flags_lock);
465         ofd->ofd_grant_compat_disable = !!val;
466         spin_unlock(&ofd->ofd_flags_lock);
467
468         return count;
469 }
470
471 static struct lprocfs_vars lprocfs_ofd_obd_vars[] = {
472         { "uuid",                lprocfs_rd_uuid, 0, 0 },
473         { "blocksize",           lprocfs_rd_blksize, 0, 0 },
474         { "kbytestotal",         lprocfs_rd_kbytestotal, 0, 0 },
475         { "kbytesfree",          lprocfs_rd_kbytesfree, 0, 0 },
476         { "kbytesavail",         lprocfs_rd_kbytesavail, 0, 0 },
477         { "filestotal",          lprocfs_rd_filestotal, 0, 0 },
478         { "filesfree",           lprocfs_rd_filesfree, 0, 0 },
479         { "seqs_allocated",      lprocfs_ofd_rd_seqs, 0, 0 },
480         { "fstype",              lprocfs_ofd_rd_fstype, 0, 0 },
481         { "last_id",             lprocfs_ofd_rd_last_id, 0, 0 },
482         { "tot_dirty",           lprocfs_ofd_rd_tot_dirty,   0, 0 },
483         { "tot_pending",         lprocfs_ofd_rd_tot_pending, 0, 0 },
484         { "tot_granted",         lprocfs_ofd_rd_tot_granted, 0, 0 },
485         { "grant_precreate",     lprocfs_ofd_rd_grant_precreate, 0, 0 },
486         { "grant_ratio",         lprocfs_ofd_rd_grant_ratio,
487                                  lprocfs_ofd_wr_grant_ratio, 0, 0 },
488         { "precreate_batch",     lprocfs_ofd_rd_precreate_batch,
489                                  lprocfs_ofd_wr_precreate_batch, 0 },
490         { "recovery_status",     lprocfs_obd_rd_recovery_status, 0, 0 },
491         { "recovery_time_soft",  lprocfs_obd_rd_recovery_time_soft,
492                                  lprocfs_obd_wr_recovery_time_soft, 0},
493         { "recovery_time_hard",  lprocfs_obd_rd_recovery_time_hard,
494                                  lprocfs_obd_wr_recovery_time_hard, 0},
495         { "evict_client",        0, lprocfs_wr_evict_client, 0,
496                                  &lprocfs_evict_client_fops},
497         { "num_exports",         lprocfs_rd_num_exports,   0, 0 },
498         { "degraded",            lprocfs_ofd_rd_degraded,
499                                  lprocfs_ofd_wr_degraded, 0},
500         { "sync_journal",        lprocfs_ofd_rd_syncjournal,
501                                  lprocfs_ofd_wr_syncjournal, 0 },
502         { "sync_on_lock_cancel", lprocfs_ofd_rd_sync_lock_cancel,
503                                  lprocfs_ofd_wr_sync_lock_cancel, 0 },
504         { "instance",            lprocfs_target_rd_instance, 0 },
505         { "ir_factor",           lprocfs_obd_rd_ir_factor,
506                                  lprocfs_obd_wr_ir_factor, 0},
507         { "grant_compat_disable", lprocfs_ofd_rd_grant_compat_disable,
508                                   lprocfs_ofd_wr_grant_compat_disable, 0 },
509         { "client_cache_count",  lprocfs_ofd_rd_fmd_max_num,
510                                  lprocfs_ofd_wr_fmd_max_num, 0 },
511         { "client_cache_seconds", lprocfs_ofd_rd_fmd_max_age,
512                                   lprocfs_ofd_wr_fmd_max_age, 0 },
513         { "capa",                lprocfs_ofd_rd_capa,
514                                  lprocfs_ofd_wr_capa, 0 },
515         { "capa_count",          lprocfs_ofd_rd_capa_count, 0, 0 },
516         { "job_cleanup_interval", lprocfs_rd_job_interval,
517                                   lprocfs_wr_job_interval, 0},
518         { 0 }
519 };
520
521 static struct lprocfs_vars lprocfs_ofd_module_vars[] = {
522         { "num_refs",     lprocfs_rd_numrefs,   0, 0 },
523         { 0 }
524 };
525
526 void lprocfs_ofd_init_vars(struct lprocfs_static_vars *lvars)
527 {
528         lvars->module_vars  = lprocfs_ofd_module_vars;
529         lvars->obd_vars     = lprocfs_ofd_obd_vars;
530 }
531
532 void ofd_stats_counter_init(struct lprocfs_stats *stats)
533 {
534         LASSERT(stats && stats->ls_num == LPROC_OFD_STATS_LAST);
535         lprocfs_counter_init(stats, LPROC_OFD_STATS_READ,
536                              LPROCFS_CNTR_AVGMINMAX, "read", "bytes");
537         lprocfs_counter_init(stats, LPROC_OFD_STATS_WRITE,
538                              LPROCFS_CNTR_AVGMINMAX, "write", "bytes");
539         lprocfs_counter_init(stats, LPROC_OFD_STATS_SETATTR,
540                              0, "setattr", "reqs");
541         lprocfs_counter_init(stats, LPROC_OFD_STATS_PUNCH,
542                              0, "punch", "reqs");
543         lprocfs_counter_init(stats, LPROC_OFD_STATS_SYNC,
544                              0, "sync", "reqs");
545 }
546 #endif /* LPROCFS */