4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
27 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/ofd/lproc_ofd.c
39 #define DEBUG_SUBSYSTEM S_CLASS
42 #include <lprocfs_status.h>
43 #include <linux/seq_file.h>
44 #include <lustre_lfsck.h>
46 #include "ofd_internal.h"
50 static int lprocfs_ofd_rd_seqs(char *page, char **start, off_t off,
51 int count, int *eof, void *data)
53 struct obd_device *obd = (struct obd_device *)data;
54 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
57 return snprintf(page, count, "%u\n", ofd->ofd_seq_count);
60 static int lprocfs_ofd_rd_tot_dirty(char *page, char **start, off_t off,
61 int count, int *eof, void *data)
63 struct obd_device *obd = (struct obd_device *)data;
64 struct ofd_device *ofd;
67 ofd = ofd_dev(obd->obd_lu_dev);
69 return snprintf(page, count, LPU64"\n", ofd->ofd_tot_dirty);
72 static int lprocfs_ofd_rd_tot_granted(char *page, char **start, off_t off,
73 int count, int *eof, void *data)
75 struct obd_device *obd = (struct obd_device *)data;
76 struct ofd_device *ofd;
79 ofd = ofd_dev(obd->obd_lu_dev);
81 return snprintf(page, count, LPU64"\n", ofd->ofd_tot_granted);
84 static int lprocfs_ofd_rd_tot_pending(char *page, char **start, off_t off,
85 int count, int *eof, void *data)
87 struct obd_device *obd = (struct obd_device *)data;
88 struct ofd_device *ofd;
91 ofd = ofd_dev(obd->obd_lu_dev);
93 return snprintf(page, count, LPU64"\n", ofd->ofd_tot_pending);
96 static int lprocfs_ofd_rd_grant_precreate(char *page, char **start, off_t off,
97 int count, int *eof, void *data)
99 struct obd_device *obd = (struct obd_device *)data;
101 LASSERT(obd != NULL);
103 return snprintf(page, count, "%ld\n",
104 obd->obd_self_export->exp_filter_data.fed_grant);
107 static int lprocfs_ofd_rd_grant_ratio(char *page, char **start, off_t off,
108 int count, int *eof, void *data)
110 struct obd_device *obd = (struct obd_device *)data;
111 struct ofd_device *ofd;
113 LASSERT(obd != NULL);
114 ofd = ofd_dev(obd->obd_lu_dev);
116 return snprintf(page, count, "%d%%\n",
117 (int) ofd_grant_reserved(ofd, 100));
120 static int lprocfs_ofd_wr_grant_ratio(struct file *file,
121 const char __user *buffer,
122 unsigned long count, void *data)
124 struct obd_device *obd = (struct obd_device *)data;
125 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
129 rc = lprocfs_write_helper(buffer, count, &val);
133 if (val > 100 || val < 0)
137 CWARN("%s: disabling grant error margin\n", obd->obd_name);
139 CWARN("%s: setting grant error margin >50%%, be warned that "
140 "a huge part of the free space is now reserved for "
141 "grants\n", obd->obd_name);
143 spin_lock(&ofd->ofd_grant_lock);
144 ofd->ofd_grant_ratio = ofd_grant_ratio_conv(val);
145 spin_unlock(&ofd->ofd_grant_lock);
149 static int lprocfs_ofd_rd_precreate_batch(char *page, char **start, off_t off,
150 int count, int *eof, void *data)
152 struct obd_device *obd = (struct obd_device *)data;
153 struct ofd_device *ofd;
155 LASSERT(obd != NULL);
156 ofd = ofd_dev(obd->obd_lu_dev);
158 return snprintf(page, count, "%d\n", ofd->ofd_precreate_batch);
161 static int lprocfs_ofd_wr_precreate_batch(struct file *file,
162 const char __user *buffer,
163 unsigned long count, void *data)
165 struct obd_device *obd = (struct obd_device *)data;
166 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
170 rc = lprocfs_write_helper(buffer, count, &val);
177 spin_lock(&ofd->ofd_batch_lock);
178 ofd->ofd_precreate_batch = val;
179 spin_unlock(&ofd->ofd_batch_lock);
183 static int lprocfs_ofd_rd_last_id(char *page, char **start, off_t off,
184 int count, int *eof, void *data)
186 struct obd_device *obd = data;
187 struct ofd_device *ofd;
188 struct ofd_seq *oseq = NULL;
194 ofd = ofd_dev(obd->obd_lu_dev);
196 read_lock(&ofd->ofd_seq_list_lock);
197 cfs_list_for_each_entry(oseq, &ofd->ofd_seq_list, os_list) {
200 seq = ostid_seq(&oseq->os_oi) == 0 ?
201 fid_idif_seq(ostid_id(&oseq->os_oi),
202 ofd->ofd_lut.lut_lsd.lsd_osd_index) :
203 ostid_seq(&oseq->os_oi);
204 rc = snprintf(page, count, DOSTID"\n", seq,
205 ostid_id(&oseq->os_oi));
214 read_unlock(&ofd->ofd_seq_list_lock);
218 int lprocfs_ofd_rd_fmd_max_num(char *page, char **start, off_t off,
219 int count, int *eof, void *data)
221 struct obd_device *obd = data;
222 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
225 rc = snprintf(page, count, "%u\n", ofd->ofd_fmd_max_num);
229 int lprocfs_ofd_wr_fmd_max_num(struct file *file, const char __user *buffer,
230 unsigned long count, void *data)
232 struct obd_device *obd = data;
233 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
237 rc = lprocfs_write_helper(buffer, count, &val);
241 if (val > 65536 || val < 1)
244 ofd->ofd_fmd_max_num = val;
248 int lprocfs_ofd_rd_fmd_max_age(char *page, char **start, off_t off,
249 int count, int *eof, void *data)
251 struct obd_device *obd = data;
252 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
255 rc = snprintf(page, count, "%ld\n", ofd->ofd_fmd_max_age / HZ);
259 int lprocfs_ofd_wr_fmd_max_age(struct file *file, const char __user *buffer,
260 unsigned long count, void *data)
262 struct obd_device *obd = data;
263 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
267 rc = lprocfs_write_helper(buffer, count, &val);
271 if (val > 65536 || val < 1)
274 ofd->ofd_fmd_max_age = val * HZ;
278 static int lprocfs_ofd_rd_capa(char *page, char **start, off_t off,
279 int count, int *eof, void *data)
281 struct obd_device *obd = data;
284 rc = snprintf(page, count, "capability on: %s\n",
285 obd->u.filter.fo_fl_oss_capa ? "oss" : "");
289 static int lprocfs_ofd_wr_capa(struct file *file, const char __user *buffer,
290 unsigned long count, void *data)
292 struct obd_device *obd = data;
295 rc = lprocfs_write_helper(buffer, count, &val);
300 CERROR("invalid capability mode, only 0/1 are accepted.\n"
301 " 1: enable oss fid capability\n"
302 " 0: disable oss fid capability\n");
306 obd->u.filter.fo_fl_oss_capa = val;
307 LCONSOLE_INFO("OSS %s %s fid capability.\n", obd->obd_name,
308 val ? "enabled" : "disabled");
312 static int lprocfs_ofd_rd_capa_count(char *page, char **start, off_t off,
313 int count, int *eof, void *data)
315 return snprintf(page, count, "%d %d\n",
316 capa_count[CAPA_SITE_CLIENT],
317 capa_count[CAPA_SITE_SERVER]);
320 int lprocfs_ofd_rd_degraded(char *page, char **start, off_t off,
321 int count, int *eof, void *data)
323 struct obd_device *obd = data;
324 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
326 return snprintf(page, count, "%u\n", ofd->ofd_raid_degraded);
329 int lprocfs_ofd_wr_degraded(struct file *file, const char __user *buffer,
330 unsigned long count, void *data)
332 struct obd_device *obd = data;
333 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
336 rc = lprocfs_write_helper(buffer, count, &val);
340 spin_lock(&ofd->ofd_flags_lock);
341 ofd->ofd_raid_degraded = !!val;
342 spin_unlock(&ofd->ofd_flags_lock);
347 int lprocfs_ofd_rd_fstype(char *page, char **start, off_t off, int count,
348 int *eof, void *data)
350 struct obd_device *obd = data;
351 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
354 LASSERT(ofd->ofd_osd);
355 d = &ofd->ofd_osd->dd_lu_dev;
357 return snprintf(page, count, "%s\n", d->ld_type->ldt_name);
360 int lprocfs_ofd_rd_syncjournal(char *page, char **start, off_t off,
361 int count, int *eof, void *data)
363 struct obd_device *obd = data;
364 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
367 rc = snprintf(page, count, "%u\n", ofd->ofd_syncjournal);
371 int lprocfs_ofd_wr_syncjournal(struct file *file, const char __user *buffer,
372 unsigned long count, void *data)
374 struct obd_device *obd = data;
375 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
379 rc = lprocfs_write_helper(buffer, count, &val);
386 spin_lock(&ofd->ofd_flags_lock);
387 ofd->ofd_syncjournal = !!val;
389 spin_unlock(&ofd->ofd_flags_lock);
394 /* This must be longer than the longest string below */
395 #define SYNC_STATES_MAXLEN 16
396 static char *sync_on_cancel_states[] = {"never",
400 int lprocfs_ofd_rd_sync_lock_cancel(char *page, char **start, off_t off,
401 int count, int *eof, void *data)
403 struct obd_device *obd = data;
404 struct lu_target *tgt = obd->u.obt.obt_lut;
407 rc = snprintf(page, count, "%s\n",
408 sync_on_cancel_states[tgt->lut_sync_lock_cancel]);
412 int lprocfs_ofd_wr_sync_lock_cancel(struct file *file,
413 const char __user *buffer,
414 unsigned long count, void *data)
416 struct obd_device *obd = data;
417 struct lu_target *tgt = obd->u.obt.obt_lut;
418 char kernbuf[SYNC_STATES_MAXLEN];
422 if (count == 0 || count >= sizeof(kernbuf))
425 if (copy_from_user(kernbuf, buffer, count))
429 if (kernbuf[count - 1] == '\n')
430 kernbuf[count - 1] = 0;
432 for (i = 0 ; i < NUM_SYNC_ON_CANCEL_STATES; i++) {
433 if (strcmp(kernbuf, sync_on_cancel_states[i]) == 0) {
439 /* Legacy numeric codes */
443 /* Safe to use userspace buffer as lprocfs_write_helper will
444 * use copy from user for parsing */
445 rc = lprocfs_write_helper(buffer, count, &val);
450 if (val < 0 || val > 2)
453 spin_lock(&tgt->lut_flags_lock);
454 tgt->lut_sync_lock_cancel = val;
455 spin_unlock(&tgt->lut_flags_lock);
459 int lprocfs_ofd_rd_grant_compat_disable(char *page, char **start, off_t off,
460 int count, int *eof, void *data)
462 struct obd_device *obd = data;
463 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
466 rc = snprintf(page, count, "%u\n", ofd->ofd_grant_compat_disable);
470 int lprocfs_ofd_wr_grant_compat_disable(struct file *file,
471 const char __user *buffer,
472 unsigned long count, void *data)
474 struct obd_device *obd = data;
475 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
479 rc = lprocfs_write_helper(buffer, count, &val);
486 spin_lock(&ofd->ofd_flags_lock);
487 ofd->ofd_grant_compat_disable = !!val;
488 spin_unlock(&ofd->ofd_flags_lock);
493 int lprocfs_ofd_rd_soft_sync_limit(char *page, char **start, off_t off,
494 int count, int *eof, void *data)
496 struct obd_device *obd = data;
497 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
499 return lprocfs_rd_uint(page, start, off, count, eof,
500 &ofd->ofd_soft_sync_limit);
503 int lprocfs_ofd_wr_soft_sync_limit(struct file *file, const char __user *buffer,
504 unsigned long count, void *data)
506 struct obd_device *obd = data;
507 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
509 return lprocfs_wr_uint(file, buffer, count, &ofd->ofd_soft_sync_limit);
512 static int lprocfs_rd_lfsck_speed_limit(char *page, char **start, off_t off,
513 int count, int *eof, void *data)
515 struct obd_device *obd = data;
516 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
520 return lfsck_get_speed(ofd->ofd_osd, page, count);
523 static int lprocfs_wr_lfsck_speed_limit(struct file *file,
524 const char __user *buffer,
525 unsigned long count, void *data)
527 struct obd_device *obd = data;
528 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
532 rc = lprocfs_write_helper(buffer, count, &val);
536 rc = lfsck_set_speed(ofd->ofd_osd, val);
538 return rc != 0 ? rc : count;
541 static int lprocfs_rd_lfsck_layout(char *page, char **start, off_t off,
542 int count, int *eof, void *data)
544 struct obd_device *obd = data;
545 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
549 return lfsck_dump(ofd->ofd_osd, page, count, LT_LAYOUT);
552 static int lprocfs_rd_lfsck_verify_pfid(char *page, char **start, off_t off,
553 int count, int *eof, void *data)
555 struct obd_device *obd = data;
556 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
560 return snprintf(page, count,
561 "switch: %s\ndetected: "LPU64"\nrepaired: "LPU64"\n",
562 ofd->ofd_lfsck_verify_pfid ? "on" : "off",
563 ofd->ofd_inconsistency_self_detected,
564 ofd->ofd_inconsistency_self_repaired);
567 static int lprocfs_wr_lfsck_verify_pfid(struct file *file,
568 const char __user *buffer,
569 unsigned long count, void *data)
571 struct obd_device *obd = data;
572 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
576 rc = lprocfs_write_helper(buffer, count, &val);
580 ofd->ofd_lfsck_verify_pfid = !!val;
585 static struct lprocfs_vars lprocfs_ofd_obd_vars[] = {
586 { "uuid", lprocfs_rd_uuid, 0, 0 },
587 { "blocksize", lprocfs_rd_blksize, 0, 0 },
588 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
589 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
590 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
591 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
592 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
593 { "seqs_allocated", lprocfs_ofd_rd_seqs, 0, 0 },
594 { "fstype", lprocfs_ofd_rd_fstype, 0, 0 },
595 { "last_id", lprocfs_ofd_rd_last_id, 0, 0 },
596 { "tot_dirty", lprocfs_ofd_rd_tot_dirty, 0, 0 },
597 { "tot_pending", lprocfs_ofd_rd_tot_pending, 0, 0 },
598 { "tot_granted", lprocfs_ofd_rd_tot_granted, 0, 0 },
599 { "grant_precreate", lprocfs_ofd_rd_grant_precreate, 0, 0 },
600 { "grant_ratio", lprocfs_ofd_rd_grant_ratio,
601 lprocfs_ofd_wr_grant_ratio, 0, 0 },
602 { "precreate_batch", lprocfs_ofd_rd_precreate_batch,
603 lprocfs_ofd_wr_precreate_batch, 0 },
604 { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
605 { "recovery_time_soft", lprocfs_obd_rd_recovery_time_soft,
606 lprocfs_obd_wr_recovery_time_soft, 0},
607 { "recovery_time_hard", lprocfs_obd_rd_recovery_time_hard,
608 lprocfs_obd_wr_recovery_time_hard, 0},
609 { "evict_client", 0, lprocfs_wr_evict_client, 0,
610 &lprocfs_evict_client_fops},
611 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
612 { "degraded", lprocfs_ofd_rd_degraded,
613 lprocfs_ofd_wr_degraded, 0},
614 { "sync_journal", lprocfs_ofd_rd_syncjournal,
615 lprocfs_ofd_wr_syncjournal, 0 },
616 { "sync_on_lock_cancel", lprocfs_ofd_rd_sync_lock_cancel,
617 lprocfs_ofd_wr_sync_lock_cancel, 0 },
618 { "instance", lprocfs_target_rd_instance, 0 },
619 { "ir_factor", lprocfs_obd_rd_ir_factor,
620 lprocfs_obd_wr_ir_factor, 0},
621 { "grant_compat_disable", lprocfs_ofd_rd_grant_compat_disable,
622 lprocfs_ofd_wr_grant_compat_disable, 0 },
623 { "client_cache_count", lprocfs_ofd_rd_fmd_max_num,
624 lprocfs_ofd_wr_fmd_max_num, 0 },
625 { "client_cache_seconds", lprocfs_ofd_rd_fmd_max_age,
626 lprocfs_ofd_wr_fmd_max_age, 0 },
627 { "capa", lprocfs_ofd_rd_capa,
628 lprocfs_ofd_wr_capa, 0 },
629 { "capa_count", lprocfs_ofd_rd_capa_count, 0, 0 },
630 { "job_cleanup_interval", lprocfs_rd_job_interval,
631 lprocfs_wr_job_interval, 0},
632 { "soft_sync_limit", lprocfs_ofd_rd_soft_sync_limit,
633 lprocfs_ofd_wr_soft_sync_limit, 0},
634 { "lfsck_speed_limit", lprocfs_rd_lfsck_speed_limit,
635 lprocfs_wr_lfsck_speed_limit, 0 },
636 { "lfsck_layout", lprocfs_rd_lfsck_layout, 0, 0 },
637 { "lfsck_verify_pfid", lprocfs_rd_lfsck_verify_pfid,
638 lprocfs_wr_lfsck_verify_pfid, 0 },
642 static struct lprocfs_vars lprocfs_ofd_module_vars[] = {
643 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
647 void lprocfs_ofd_init_vars(struct lprocfs_static_vars *lvars)
649 lvars->module_vars = lprocfs_ofd_module_vars;
650 lvars->obd_vars = lprocfs_ofd_obd_vars;
653 void ofd_stats_counter_init(struct lprocfs_stats *stats)
655 LASSERT(stats && stats->ls_num >= LPROC_OFD_STATS_LAST);
657 lprocfs_counter_init(stats, LPROC_OFD_STATS_READ,
658 LPROCFS_CNTR_AVGMINMAX, "read_bytes", "bytes");
659 lprocfs_counter_init(stats, LPROC_OFD_STATS_WRITE,
660 LPROCFS_CNTR_AVGMINMAX, "write_bytes", "bytes");
661 lprocfs_counter_init(stats, LPROC_OFD_STATS_GETATTR,
662 0, "getattr", "reqs");
663 lprocfs_counter_init(stats, LPROC_OFD_STATS_SETATTR,
664 0, "setattr", "reqs");
665 lprocfs_counter_init(stats, LPROC_OFD_STATS_PUNCH,
667 lprocfs_counter_init(stats, LPROC_OFD_STATS_SYNC,
669 lprocfs_counter_init(stats, LPROC_OFD_STATS_DESTROY,
670 0, "destroy", "reqs");
671 lprocfs_counter_init(stats, LPROC_OFD_STATS_CREATE,
672 0, "create", "reqs");
673 lprocfs_counter_init(stats, LPROC_OFD_STATS_STATFS,
674 0, "statfs", "reqs");
675 lprocfs_counter_init(stats, LPROC_OFD_STATS_GET_INFO,
676 0, "get_info", "reqs");
677 lprocfs_counter_init(stats, LPROC_OFD_STATS_SET_INFO,
678 0, "set_info", "reqs");
679 lprocfs_counter_init(stats, LPROC_OFD_STATS_QUOTACTL,
680 0, "quotactl", "reqs");