Whamcloud - gitweb
LU-3569 ofd: packing ost_idx in IDIF
[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;
152
153         LASSERT(obd != NULL);
154         ofd = ofd_dev(obd->obd_lu_dev);
155         *eof = 1;
156         return snprintf(page, count, "%d\n", ofd->ofd_precreate_batch);
157 }
158
159 static int lprocfs_ofd_wr_precreate_batch(struct file *file, const char *buffer,
160                                           unsigned long count, void *data)
161 {
162         struct obd_device *obd = (struct obd_device *)data;
163         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
164         int val;
165         int rc;
166
167         rc = lprocfs_write_helper(buffer, count, &val);
168         if (rc)
169                 return rc;
170
171         if (val < 1)
172                 return -EINVAL;
173
174         spin_lock(&ofd->ofd_batch_lock);
175         ofd->ofd_precreate_batch = val;
176         spin_unlock(&ofd->ofd_batch_lock);
177         return count;
178 }
179
180 static int lprocfs_ofd_rd_last_id(char *page, char **start, off_t off,
181                                   int count, int *eof, void *data)
182 {
183         struct obd_device       *obd = data;
184         struct ofd_device       *ofd;
185         struct ofd_seq          *oseq = NULL;
186         int                     retval = 0, rc;
187
188         if (obd == NULL)
189                 return 0;
190
191         ofd = ofd_dev(obd->obd_lu_dev);
192
193         read_lock(&ofd->ofd_seq_list_lock);
194         cfs_list_for_each_entry(oseq, &ofd->ofd_seq_list, os_list) {
195                 __u64 seq;
196
197                 seq = ostid_seq(&oseq->os_oi) == 0 ?
198                       fid_idif_seq(ostid_id(&oseq->os_oi),
199                                    ofd->ofd_lut.lut_lsd.lsd_osd_index) :
200                       ostid_seq(&oseq->os_oi);
201                 rc = snprintf(page, count, DOSTID"\n", seq,
202                               ostid_id(&oseq->os_oi));
203                 if (rc < 0) {
204                         retval = rc;
205                         break;
206                 }
207                 page += rc;
208                 count -= rc;
209                 retval += rc;
210         }
211         read_unlock(&ofd->ofd_seq_list_lock);
212         return retval;
213 }
214
215 int lprocfs_ofd_rd_fmd_max_num(char *page, char **start, off_t off,
216                                int count, int *eof, void *data)
217 {
218         struct obd_device       *obd = data;
219         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
220         int                      rc;
221
222         rc = snprintf(page, count, "%u\n", ofd->ofd_fmd_max_num);
223         return rc;
224 }
225
226 int lprocfs_ofd_wr_fmd_max_num(struct file *file, const char *buffer,
227                                unsigned long count, void *data)
228 {
229         struct obd_device       *obd = data;
230         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
231         int                      val;
232         int                      rc;
233
234         rc = lprocfs_write_helper(buffer, count, &val);
235         if (rc)
236                 return rc;
237
238         if (val > 65536 || val < 1)
239                 return -EINVAL;
240
241         ofd->ofd_fmd_max_num = val;
242         return count;
243 }
244
245 int lprocfs_ofd_rd_fmd_max_age(char *page, char **start, off_t off,
246                                int count, int *eof, void *data)
247 {
248         struct obd_device       *obd = data;
249         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
250         int                      rc;
251
252         rc = snprintf(page, count, "%ld\n", ofd->ofd_fmd_max_age / HZ);
253         return rc;
254 }
255
256 int lprocfs_ofd_wr_fmd_max_age(struct file *file, const char *buffer,
257                                unsigned long count, void *data)
258 {
259         struct obd_device       *obd = data;
260         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
261         int                      val;
262         int                      rc;
263
264         rc = lprocfs_write_helper(buffer, count, &val);
265         if (rc)
266                 return rc;
267
268         if (val > 65536 || val < 1)
269                 return -EINVAL;
270
271         ofd->ofd_fmd_max_age = val * HZ;
272         return count;
273 }
274
275 static int lprocfs_ofd_rd_capa(char *page, char **start, off_t off,
276                                int count, int *eof, void *data)
277 {
278         struct obd_device       *obd = data;
279         int                      rc;
280
281         rc = snprintf(page, count, "capability on: %s\n",
282                       obd->u.filter.fo_fl_oss_capa ? "oss" : "");
283         return rc;
284 }
285
286 static int lprocfs_ofd_wr_capa(struct file *file, const char *buffer,
287                                unsigned long count, void *data)
288 {
289         struct obd_device       *obd = data;
290         int                      val, rc;
291
292         rc = lprocfs_write_helper(buffer, count, &val);
293         if (rc)
294                 return rc;
295
296         if (val & ~0x1) {
297                 CERROR("invalid capability mode, only 0/1 are accepted.\n"
298                        " 1: enable oss fid capability\n"
299                        " 0: disable oss fid capability\n");
300                 return -EINVAL;
301         }
302
303         obd->u.filter.fo_fl_oss_capa = val;
304         LCONSOLE_INFO("OSS %s %s fid capability.\n", obd->obd_name,
305                       val ? "enabled" : "disabled");
306         return count;
307 }
308
309 static int lprocfs_ofd_rd_capa_count(char *page, char **start, off_t off,
310                                      int count, int *eof, void *data)
311 {
312         return snprintf(page, count, "%d %d\n",
313                         capa_count[CAPA_SITE_CLIENT],
314                         capa_count[CAPA_SITE_SERVER]);
315 }
316
317 int lprocfs_ofd_rd_degraded(char *page, char **start, off_t off,
318                             int count, int *eof, void *data)
319 {
320         struct obd_device *obd = data;
321         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
322
323         return snprintf(page, count, "%u\n", ofd->ofd_raid_degraded);
324 }
325
326 int lprocfs_ofd_wr_degraded(struct file *file, const char *buffer,
327                             unsigned long count, void *data)
328 {
329         struct obd_device       *obd = data;
330         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
331         int                      val, rc;
332
333         rc = lprocfs_write_helper(buffer, count, &val);
334         if (rc)
335                 return rc;
336
337         spin_lock(&ofd->ofd_flags_lock);
338         ofd->ofd_raid_degraded = !!val;
339         spin_unlock(&ofd->ofd_flags_lock);
340
341         return count;
342 }
343
344 int lprocfs_ofd_rd_fstype(char *page, char **start, off_t off, int count,
345                           int *eof, void *data)
346 {
347         struct obd_device *obd = data;
348         struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
349         struct lu_device  *d;
350
351         LASSERT(ofd->ofd_osd);
352         d = &ofd->ofd_osd->dd_lu_dev;
353         LASSERT(d->ld_type);
354         return snprintf(page, count, "%s\n", d->ld_type->ldt_name);
355 }
356
357 int lprocfs_ofd_rd_syncjournal(char *page, char **start, off_t off,
358                                int count, int *eof, void *data)
359 {
360         struct obd_device       *obd = data;
361         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
362         int                      rc;
363
364         rc = snprintf(page, count, "%u\n", ofd->ofd_syncjournal);
365         return rc;
366 }
367
368 int lprocfs_ofd_wr_syncjournal(struct file *file, const char *buffer,
369                                unsigned long count, void *data)
370 {
371         struct obd_device       *obd = data;
372         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
373         int                      val;
374         int                      rc;
375
376         rc = lprocfs_write_helper(buffer, count, &val);
377         if (rc)
378                 return rc;
379
380         if (val < 0)
381                 return -EINVAL;
382
383         spin_lock(&ofd->ofd_flags_lock);
384         ofd->ofd_syncjournal = !!val;
385         ofd_slc_set(ofd);
386         spin_unlock(&ofd->ofd_flags_lock);
387
388         return count;
389 }
390
391 static char *sync_on_cancel_states[] = {"never",
392                                         "blocking",
393                                         "always" };
394
395 int lprocfs_ofd_rd_sync_lock_cancel(char *page, char **start, off_t off,
396                                     int count, int *eof, void *data)
397 {
398         struct obd_device       *obd = data;
399         struct lu_target        *tgt = obd->u.obt.obt_lut;
400         int                      rc;
401
402         rc = snprintf(page, count, "%s\n",
403                       sync_on_cancel_states[tgt->lut_sync_lock_cancel]);
404         return rc;
405 }
406
407 int lprocfs_ofd_wr_sync_lock_cancel(struct file *file, const char *buffer,
408                                     unsigned long count, void *data)
409 {
410         struct obd_device       *obd = data;
411         struct lu_target        *tgt = obd->u.obt.obt_lut;
412         int                      val = -1;
413         int                      i;
414
415         for (i = 0 ; i < NUM_SYNC_ON_CANCEL_STATES; i++) {
416                 if (memcmp(buffer, sync_on_cancel_states[i],
417                            strlen(sync_on_cancel_states[i])) == 0) {
418                         val = i;
419                         break;
420                 }
421         }
422         if (val == -1) {
423                 int rc;
424
425                 rc = lprocfs_write_helper(buffer, count, &val);
426                 if (rc)
427                         return rc;
428         }
429
430         if (val < 0 || val > 2)
431                 return -EINVAL;
432
433         spin_lock(&tgt->lut_flags_lock);
434         tgt->lut_sync_lock_cancel = val;
435         spin_unlock(&tgt->lut_flags_lock);
436         return count;
437 }
438
439 int lprocfs_ofd_rd_grant_compat_disable(char *page, char **start, off_t off,
440                                         int count, int *eof, void *data)
441 {
442         struct obd_device       *obd = data;
443         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
444         int                      rc;
445
446         rc = snprintf(page, count, "%u\n", ofd->ofd_grant_compat_disable);
447         return rc;
448 }
449
450 int lprocfs_ofd_wr_grant_compat_disable(struct file *file, const char *buffer,
451                                         unsigned long count, void *data)
452 {
453         struct obd_device       *obd = data;
454         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
455         int                      val;
456         int                      rc;
457
458         rc = lprocfs_write_helper(buffer, count, &val);
459         if (rc)
460                 return rc;
461
462         if (val < 0)
463                 return -EINVAL;
464
465         spin_lock(&ofd->ofd_flags_lock);
466         ofd->ofd_grant_compat_disable = !!val;
467         spin_unlock(&ofd->ofd_flags_lock);
468
469         return count;
470 }
471
472 int lprocfs_ofd_rd_soft_sync_limit(char *page, char **start, off_t off,
473                                    int count, int *eof, void *data)
474 {
475         struct obd_device       *obd = data;
476         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
477
478         return lprocfs_rd_uint(page, start, off, count, eof,
479                                &ofd->ofd_soft_sync_limit);
480 }
481
482 int lprocfs_ofd_wr_soft_sync_limit(struct file *file, const char *buffer,
483                                    unsigned long count, void *data)
484 {
485         struct obd_device       *obd = data;
486         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
487
488         return lprocfs_wr_uint(file, buffer, count, &ofd->ofd_soft_sync_limit);
489 }
490
491 static struct lprocfs_vars lprocfs_ofd_obd_vars[] = {
492         { "uuid",                lprocfs_rd_uuid, 0, 0 },
493         { "blocksize",           lprocfs_rd_blksize, 0, 0 },
494         { "kbytestotal",         lprocfs_rd_kbytestotal, 0, 0 },
495         { "kbytesfree",          lprocfs_rd_kbytesfree, 0, 0 },
496         { "kbytesavail",         lprocfs_rd_kbytesavail, 0, 0 },
497         { "filestotal",          lprocfs_rd_filestotal, 0, 0 },
498         { "filesfree",           lprocfs_rd_filesfree, 0, 0 },
499         { "seqs_allocated",      lprocfs_ofd_rd_seqs, 0, 0 },
500         { "fstype",              lprocfs_ofd_rd_fstype, 0, 0 },
501         { "last_id",             lprocfs_ofd_rd_last_id, 0, 0 },
502         { "tot_dirty",           lprocfs_ofd_rd_tot_dirty,   0, 0 },
503         { "tot_pending",         lprocfs_ofd_rd_tot_pending, 0, 0 },
504         { "tot_granted",         lprocfs_ofd_rd_tot_granted, 0, 0 },
505         { "grant_precreate",     lprocfs_ofd_rd_grant_precreate, 0, 0 },
506         { "grant_ratio",         lprocfs_ofd_rd_grant_ratio,
507                                  lprocfs_ofd_wr_grant_ratio, 0, 0 },
508         { "precreate_batch",     lprocfs_ofd_rd_precreate_batch,
509                                  lprocfs_ofd_wr_precreate_batch, 0 },
510         { "recovery_status",     lprocfs_obd_rd_recovery_status, 0, 0 },
511         { "recovery_time_soft",  lprocfs_obd_rd_recovery_time_soft,
512                                  lprocfs_obd_wr_recovery_time_soft, 0},
513         { "recovery_time_hard",  lprocfs_obd_rd_recovery_time_hard,
514                                  lprocfs_obd_wr_recovery_time_hard, 0},
515         { "evict_client",        0, lprocfs_wr_evict_client, 0,
516                                  &lprocfs_evict_client_fops},
517         { "num_exports",         lprocfs_rd_num_exports,   0, 0 },
518         { "degraded",            lprocfs_ofd_rd_degraded,
519                                  lprocfs_ofd_wr_degraded, 0},
520         { "sync_journal",        lprocfs_ofd_rd_syncjournal,
521                                  lprocfs_ofd_wr_syncjournal, 0 },
522         { "sync_on_lock_cancel", lprocfs_ofd_rd_sync_lock_cancel,
523                                  lprocfs_ofd_wr_sync_lock_cancel, 0 },
524         { "instance",            lprocfs_target_rd_instance, 0 },
525         { "ir_factor",           lprocfs_obd_rd_ir_factor,
526                                  lprocfs_obd_wr_ir_factor, 0},
527         { "grant_compat_disable", lprocfs_ofd_rd_grant_compat_disable,
528                                   lprocfs_ofd_wr_grant_compat_disable, 0 },
529         { "client_cache_count",  lprocfs_ofd_rd_fmd_max_num,
530                                  lprocfs_ofd_wr_fmd_max_num, 0 },
531         { "client_cache_seconds", lprocfs_ofd_rd_fmd_max_age,
532                                   lprocfs_ofd_wr_fmd_max_age, 0 },
533         { "capa",                lprocfs_ofd_rd_capa,
534                                  lprocfs_ofd_wr_capa, 0 },
535         { "capa_count",          lprocfs_ofd_rd_capa_count, 0, 0 },
536         { "job_cleanup_interval", lprocfs_rd_job_interval,
537                                   lprocfs_wr_job_interval, 0},
538         { "soft_sync_limit",     lprocfs_ofd_rd_soft_sync_limit,
539                                  lprocfs_ofd_wr_soft_sync_limit, 0},
540         { 0 }
541 };
542
543 static struct lprocfs_vars lprocfs_ofd_module_vars[] = {
544         { "num_refs",     lprocfs_rd_numrefs,   0, 0 },
545         { 0 }
546 };
547
548 void lprocfs_ofd_init_vars(struct lprocfs_static_vars *lvars)
549 {
550         lvars->module_vars  = lprocfs_ofd_module_vars;
551         lvars->obd_vars     = lprocfs_ofd_obd_vars;
552 }
553
554 void ofd_stats_counter_init(struct lprocfs_stats *stats)
555 {
556         LASSERT(stats && stats->ls_num >= LPROC_OFD_STATS_LAST);
557
558         lprocfs_counter_init(stats, LPROC_OFD_STATS_READ,
559                              LPROCFS_CNTR_AVGMINMAX, "read_bytes", "bytes");
560         lprocfs_counter_init(stats, LPROC_OFD_STATS_WRITE,
561                              LPROCFS_CNTR_AVGMINMAX, "write_bytes", "bytes");
562         lprocfs_counter_init(stats, LPROC_OFD_STATS_GETATTR,
563                              0, "getattr", "reqs");
564         lprocfs_counter_init(stats, LPROC_OFD_STATS_SETATTR,
565                              0, "setattr", "reqs");
566         lprocfs_counter_init(stats, LPROC_OFD_STATS_PUNCH,
567                              0, "punch", "reqs");
568         lprocfs_counter_init(stats, LPROC_OFD_STATS_SYNC,
569                              0, "sync", "reqs");
570         lprocfs_counter_init(stats, LPROC_OFD_STATS_DESTROY,
571                              0, "destroy", "reqs");
572         lprocfs_counter_init(stats, LPROC_OFD_STATS_CREATE,
573                              0, "create", "reqs");
574         lprocfs_counter_init(stats, LPROC_OFD_STATS_STATFS,
575                              0, "statfs", "reqs");
576         lprocfs_counter_init(stats, LPROC_OFD_STATS_GET_INFO,
577                              0, "get_info", "reqs");
578         lprocfs_counter_init(stats, LPROC_OFD_STATS_SET_INFO,
579                              0, "set_info", "reqs");
580         lprocfs_counter_init(stats, LPROC_OFD_STATS_QUOTACTL,
581                              0, "quotactl", "reqs");
582 }
583
584 #endif /* LPROCFS */