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 ofd_seqs_seq_show(struct seq_file *m, void *data)
52 struct obd_device *obd = m->private;
53 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
55 return seq_printf(m, "%u\n", ofd->ofd_seq_count);
57 LPROC_SEQ_FOPS_RO(ofd_seqs);
59 static int ofd_tot_dirty_seq_show(struct seq_file *m, void *data)
61 struct obd_device *obd = m->private;
62 struct ofd_device *ofd;
65 ofd = ofd_dev(obd->obd_lu_dev);
66 return seq_printf(m, LPU64"\n", ofd->ofd_tot_dirty);
68 LPROC_SEQ_FOPS_RO(ofd_tot_dirty);
70 static int ofd_tot_granted_seq_show(struct seq_file *m, void *data)
72 struct obd_device *obd = m->private;
73 struct ofd_device *ofd;
76 ofd = ofd_dev(obd->obd_lu_dev);
77 return seq_printf(m, LPU64"\n", ofd->ofd_tot_granted);
79 LPROC_SEQ_FOPS_RO(ofd_tot_granted);
81 static int ofd_tot_pending_seq_show(struct seq_file *m, void *data)
83 struct obd_device *obd = m->private;
84 struct ofd_device *ofd;
87 ofd = ofd_dev(obd->obd_lu_dev);
88 return seq_printf(m, LPU64"\n", ofd->ofd_tot_pending);
90 LPROC_SEQ_FOPS_RO(ofd_tot_pending);
92 static int ofd_grant_precreate_seq_show(struct seq_file *m, void *data)
94 struct obd_device *obd = m->private;
97 return seq_printf(m, "%ld\n",
98 obd->obd_self_export->exp_filter_data.fed_grant);
100 LPROC_SEQ_FOPS_RO(ofd_grant_precreate);
102 static int ofd_grant_ratio_seq_show(struct seq_file *m, void *data)
104 struct obd_device *obd = m->private;
105 struct ofd_device *ofd;
107 LASSERT(obd != NULL);
108 ofd = ofd_dev(obd->obd_lu_dev);
109 return seq_printf(m, "%d%%\n",
110 (int) ofd_grant_reserved(ofd, 100));
114 ofd_grant_ratio_seq_write(struct file *file, const char __user *buffer,
115 size_t count, loff_t *off)
117 struct seq_file *m = file->private_data;
118 struct obd_device *obd = m->private;
119 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
123 rc = lprocfs_write_helper(buffer, count, &val);
127 if (val > 100 || val < 0)
131 CWARN("%s: disabling grant error margin\n", obd->obd_name);
133 CWARN("%s: setting grant error margin >50%%, be warned that "
134 "a huge part of the free space is now reserved for "
135 "grants\n", obd->obd_name);
137 spin_lock(&ofd->ofd_grant_lock);
138 ofd->ofd_grant_ratio = ofd_grant_ratio_conv(val);
139 spin_unlock(&ofd->ofd_grant_lock);
142 LPROC_SEQ_FOPS(ofd_grant_ratio);
144 static int ofd_precreate_batch_seq_show(struct seq_file *m, void *data)
146 struct obd_device *obd = m->private;
147 struct ofd_device *ofd;
149 LASSERT(obd != NULL);
150 ofd = ofd_dev(obd->obd_lu_dev);
151 return seq_printf(m, "%d\n", ofd->ofd_precreate_batch);
155 ofd_precreate_batch_seq_write(struct file *file, const char __user *buffer,
156 size_t count, loff_t *off)
158 struct seq_file *m = file->private_data;
159 struct obd_device *obd = m->private;
160 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
164 rc = lprocfs_write_helper(buffer, count, &val);
171 spin_lock(&ofd->ofd_batch_lock);
172 ofd->ofd_precreate_batch = val;
173 spin_unlock(&ofd->ofd_batch_lock);
176 LPROC_SEQ_FOPS(ofd_precreate_batch);
178 static int ofd_last_id_seq_show(struct seq_file *m, void *data)
180 struct obd_device *obd = m->private;
181 struct ofd_device *ofd;
182 struct ofd_seq *oseq = NULL;
188 ofd = ofd_dev(obd->obd_lu_dev);
190 read_lock(&ofd->ofd_seq_list_lock);
191 cfs_list_for_each_entry(oseq, &ofd->ofd_seq_list, os_list) {
194 seq = ostid_seq(&oseq->os_oi) == 0 ?
195 fid_idif_seq(ostid_id(&oseq->os_oi),
196 ofd->ofd_lut.lut_lsd.lsd_osd_index) :
197 ostid_seq(&oseq->os_oi);
198 rc = seq_printf(m, DOSTID"\n", seq, ostid_id(&oseq->os_oi));
205 read_unlock(&ofd->ofd_seq_list_lock);
208 LPROC_SEQ_FOPS_RO(ofd_last_id);
210 static int ofd_fmd_max_num_seq_show(struct seq_file *m, void *data)
212 struct obd_device *obd = m->private;
213 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
215 return seq_printf(m, "%u\n", ofd->ofd_fmd_max_num);
219 ofd_fmd_max_num_seq_write(struct file *file, const char __user *buffer,
220 size_t count, loff_t *off)
222 struct seq_file *m = file->private_data;
223 struct obd_device *obd = m->private;
224 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
228 rc = lprocfs_write_helper(buffer, count, &val);
232 if (val > 65536 || val < 1)
235 ofd->ofd_fmd_max_num = val;
238 LPROC_SEQ_FOPS(ofd_fmd_max_num);
240 static int ofd_fmd_max_age_seq_show(struct seq_file *m, void *data)
242 struct obd_device *obd = m->private;
243 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
245 return seq_printf(m, "%ld\n", ofd->ofd_fmd_max_age / HZ);
249 ofd_fmd_max_age_seq_write(struct file *file, const char __user *buffer,
250 size_t count, loff_t *off)
252 struct seq_file *m = file->private_data;
253 struct obd_device *obd = m->private;
254 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
258 rc = lprocfs_write_helper(buffer, count, &val);
262 if (val > 65536 || val < 1)
265 ofd->ofd_fmd_max_age = val * HZ;
268 LPROC_SEQ_FOPS(ofd_fmd_max_age);
270 static int ofd_capa_seq_show(struct seq_file *m, void *data)
272 struct obd_device *obd = m->private;
274 return seq_printf(m, "capability on: %s\n",
275 obd->u.filter.fo_fl_oss_capa ? "oss" : "");
279 ofd_capa_seq_write(struct file *file, const char *__user buffer, size_t count,
282 struct seq_file *m = file->private_data;
283 struct obd_device *obd = m->private;
286 rc = lprocfs_write_helper(buffer, count, &val);
291 CERROR("invalid capability mode, only 0/1 are accepted.\n"
292 " 1: enable oss fid capability\n"
293 " 0: disable oss fid capability\n");
297 obd->u.filter.fo_fl_oss_capa = val;
298 LCONSOLE_INFO("OSS %s %s fid capability.\n", obd->obd_name,
299 val ? "enabled" : "disabled");
302 LPROC_SEQ_FOPS(ofd_capa);
304 static int ofd_capa_count_seq_show(struct seq_file *m, void *data)
306 return seq_printf(m, "%d %d\n", capa_count[CAPA_SITE_CLIENT],
307 capa_count[CAPA_SITE_SERVER]);
309 LPROC_SEQ_FOPS_RO(ofd_capa_count);
311 static int ofd_degraded_seq_show(struct seq_file *m, void *data)
313 struct obd_device *obd = m->private;
314 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
316 return seq_printf(m, "%u\n", ofd->ofd_raid_degraded);
320 ofd_degraded_seq_write(struct file *file, const char __user *buffer,
321 size_t count, loff_t *off)
323 struct seq_file *m = file->private_data;
324 struct obd_device *obd = m->private;
325 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
328 rc = lprocfs_write_helper(buffer, count, &val);
332 spin_lock(&ofd->ofd_flags_lock);
333 ofd->ofd_raid_degraded = !!val;
334 spin_unlock(&ofd->ofd_flags_lock);
337 LPROC_SEQ_FOPS(ofd_degraded);
339 static int ofd_fstype_seq_show(struct seq_file *m, void *data)
341 struct obd_device *obd = m->private;
342 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
345 LASSERT(ofd->ofd_osd);
346 d = &ofd->ofd_osd->dd_lu_dev;
348 return seq_printf(m, "%s\n", d->ld_type->ldt_name);
350 LPROC_SEQ_FOPS_RO(ofd_fstype);
352 static int ofd_syncjournal_seq_show(struct seq_file *m, void *data)
354 struct obd_device *obd = m->private;
355 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
357 return seq_printf(m, "%u\n", ofd->ofd_syncjournal);
361 ofd_syncjournal_seq_write(struct file *file, const char __user *buffer,
362 size_t count, loff_t *off)
364 struct seq_file *m = file->private_data;
365 struct obd_device *obd = m->private;
366 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
370 rc = lprocfs_write_helper(buffer, count, &val);
377 spin_lock(&ofd->ofd_flags_lock);
378 ofd->ofd_syncjournal = !!val;
380 spin_unlock(&ofd->ofd_flags_lock);
384 LPROC_SEQ_FOPS(ofd_syncjournal);
386 /* This must be longer than the longest string below */
387 #define SYNC_STATES_MAXLEN 16
388 static char *sync_on_cancel_states[] = {"never",
392 static int ofd_sync_lock_cancel_seq_show(struct seq_file *m, void *data)
394 struct obd_device *obd = m->private;
395 struct lu_target *tgt = obd->u.obt.obt_lut;
397 return seq_printf(m, "%s\n",
398 sync_on_cancel_states[tgt->lut_sync_lock_cancel]);
402 ofd_sync_lock_cancel_seq_write(struct file *file, const char __user *buffer,
403 size_t count, loff_t *off)
405 struct seq_file *m = file->private_data;
406 struct obd_device *obd = m->private;
407 struct lu_target *tgt = obd->u.obt.obt_lut;
408 char kernbuf[SYNC_STATES_MAXLEN];
412 if (count == 0 || count >= sizeof(kernbuf))
415 if (copy_from_user(kernbuf, buffer, count))
419 if (kernbuf[count - 1] == '\n')
420 kernbuf[count - 1] = 0;
422 for (i = 0 ; i < NUM_SYNC_ON_CANCEL_STATES; i++) {
423 if (strcmp(kernbuf, sync_on_cancel_states[i]) == 0) {
429 /* Legacy numeric codes */
433 /* Safe to use userspace buffer as lprocfs_write_helper will
434 * use copy from user for parsing */
435 rc = lprocfs_write_helper(buffer, count, &val);
440 if (val < 0 || val > 2)
443 spin_lock(&tgt->lut_flags_lock);
444 tgt->lut_sync_lock_cancel = val;
445 spin_unlock(&tgt->lut_flags_lock);
448 LPROC_SEQ_FOPS(ofd_sync_lock_cancel);
450 static int ofd_grant_compat_disable_seq_show(struct seq_file *m, void *data)
452 struct obd_device *obd = m->private;
453 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
455 return seq_printf(m, "%u\n", ofd->ofd_grant_compat_disable);
459 ofd_grant_compat_disable_seq_write(struct file *file,
460 const char __user *buffer,
461 size_t count, loff_t *off)
463 struct seq_file *m = file->private_data;
464 struct obd_device *obd = m->private;
465 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
469 rc = lprocfs_write_helper(buffer, count, &val);
476 spin_lock(&ofd->ofd_flags_lock);
477 ofd->ofd_grant_compat_disable = !!val;
478 spin_unlock(&ofd->ofd_flags_lock);
482 LPROC_SEQ_FOPS(ofd_grant_compat_disable);
484 static int ofd_soft_sync_limit_seq_show(struct seq_file *m, void *data)
486 struct obd_device *obd = m->private;
487 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
489 return lprocfs_uint_seq_show(m, &ofd->ofd_soft_sync_limit);
493 ofd_soft_sync_limit_seq_write(struct file *file, const char __user *buffer,
494 size_t count, loff_t *off)
496 struct seq_file *m = file->private_data;
497 struct obd_device *obd = m->private;
498 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
500 return lprocfs_uint_seq_write(file, buffer, count,
501 (loff_t *) &ofd->ofd_soft_sync_limit);
503 LPROC_SEQ_FOPS(ofd_soft_sync_limit);
505 static int ofd_lfsck_speed_limit_seq_show(struct seq_file *m, void *data)
507 struct obd_device *obd = m->private;
508 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
510 return lfsck_get_speed(m, ofd->ofd_osd);
514 ofd_lfsck_speed_limit_seq_write(struct file *file, const char __user *buffer,
515 size_t count, loff_t *off)
517 struct seq_file *m = file->private_data;
518 struct obd_device *obd = m->private;
519 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
523 rc = lprocfs_write_helper(buffer, count, &val);
527 rc = lfsck_set_speed(ofd->ofd_osd, val);
529 return rc != 0 ? rc : count;
531 LPROC_SEQ_FOPS(ofd_lfsck_speed_limit);
533 static int ofd_lfsck_layout_seq_show(struct seq_file *m, void *data)
535 struct obd_device *obd = m->private;
536 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
538 return lfsck_dump(m, ofd->ofd_osd, LFSCK_TYPE_LAYOUT);
540 LPROC_SEQ_FOPS_RO(ofd_lfsck_layout);
542 static int ofd_lfsck_verify_pfid_seq_show(struct seq_file *m, void *data)
544 struct obd_device *obd = m->private;
545 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
548 "switch: %s\ndetected: "LPU64"\nrepaired: "LPU64"\n",
549 ofd->ofd_lfsck_verify_pfid ? "on" : "off",
550 ofd->ofd_inconsistency_self_detected,
551 ofd->ofd_inconsistency_self_repaired);
555 ofd_lfsck_verify_pfid_seq_write(struct file *file, const char __user *buffer,
556 size_t count, loff_t *off)
558 struct seq_file *m = file->private_data;
559 struct obd_device *obd = m->private;
560 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
564 rc = lprocfs_write_helper(buffer, count, &val);
568 ofd->ofd_lfsck_verify_pfid = !!val;
572 LPROC_SEQ_FOPS(ofd_lfsck_verify_pfid);
574 LPROC_SEQ_FOPS_RO_TYPE(ofd, uuid);
575 LPROC_SEQ_FOPS_RO_TYPE(ofd, blksize);
576 LPROC_SEQ_FOPS_RO_TYPE(ofd, kbytestotal);
577 LPROC_SEQ_FOPS_RO_TYPE(ofd, kbytesfree);
578 LPROC_SEQ_FOPS_RO_TYPE(ofd, kbytesavail);
579 LPROC_SEQ_FOPS_RO_TYPE(ofd, filestotal);
580 LPROC_SEQ_FOPS_RO_TYPE(ofd, filesfree);
582 LPROC_SEQ_FOPS_RO_TYPE(ofd, recovery_status);
583 LPROC_SEQ_FOPS_RW_TYPE(ofd, recovery_time_soft);
584 LPROC_SEQ_FOPS_RW_TYPE(ofd, recovery_time_hard);
585 LPROC_SEQ_FOPS_WO_TYPE(ofd, evict_client);
586 LPROC_SEQ_FOPS_RO_TYPE(ofd, num_exports);
587 LPROC_SEQ_FOPS_RO_TYPE(ofd, target_instance);
588 LPROC_SEQ_FOPS_RW_TYPE(ofd, ir_factor);
589 LPROC_SEQ_FOPS_RW_TYPE(ofd, job_interval);
591 struct lprocfs_seq_vars lprocfs_ofd_obd_vars[] = {
593 .fops = &ofd_uuid_fops },
594 { .name = "blocksize",
595 .fops = &ofd_blksize_fops },
596 { .name = "kbytestotal",
597 .fops = &ofd_kbytestotal_fops },
598 { .name = "kbytesfree",
599 .fops = &ofd_kbytesfree_fops },
600 { .name = "kbytesavail",
601 .fops = &ofd_kbytesavail_fops },
602 { .name = "filestotal",
603 .fops = &ofd_filestotal_fops },
604 { .name = "filesfree",
605 .fops = &ofd_filesfree_fops },
606 { .name = "seqs_allocated",
607 .fops = &ofd_seqs_fops },
609 .fops = &ofd_fstype_fops },
611 .fops = &ofd_last_id_fops },
612 { .name = "tot_dirty",
613 .fops = &ofd_tot_dirty_fops },
614 { .name = "tot_pending",
615 .fops = &ofd_tot_pending_fops },
616 { .name = "tot_granted",
617 .fops = &ofd_tot_granted_fops },
618 { .name = "grant_precreate",
619 .fops = &ofd_grant_precreate_fops },
620 { .name = "grant_ratio",
621 .fops = &ofd_grant_ratio_fops },
622 { .name = "precreate_batch",
623 .fops = &ofd_precreate_batch_fops },
624 { .name = "recovery_status",
625 .fops = &ofd_recovery_status_fops },
626 { .name = "recovery_time_soft",
627 .fops = &ofd_recovery_time_soft_fops },
628 { .name = "recovery_time_hard",
629 .fops = &ofd_recovery_time_hard_fops },
630 { .name = "evict_client",
631 .fops = &ofd_evict_client_fops },
632 { .name = "num_exports",
633 .fops = &ofd_num_exports_fops },
634 { .name = "degraded",
635 .fops = &ofd_degraded_fops },
636 { .name = "sync_journal",
637 .fops = &ofd_syncjournal_fops },
638 { .name = "sync_on_lock_cancel",
639 .fops = &ofd_sync_lock_cancel_fops },
640 { .name = "instance",
641 .fops = &ofd_target_instance_fops },
642 { .name = "ir_factor",
643 .fops = &ofd_ir_factor_fops },
644 { .name = "grant_compat_disable",
645 .fops = &ofd_grant_compat_disable_fops },
646 { .name = "client_cache_count",
647 .fops = &ofd_fmd_max_num_fops },
648 { .name = "client_cache_seconds",
649 .fops = &ofd_fmd_max_age_fops },
651 .fops = &ofd_capa_fops },
652 { .name = "capa_count",
653 .fops = &ofd_capa_count_fops },
654 { .name = "job_cleanup_interval",
655 .fops = &ofd_job_interval_fops },
656 { .name = "soft_sync_limit",
657 .fops = &ofd_soft_sync_limit_fops },
658 { .name = "lfsck_speed_limit",
659 .fops = &ofd_lfsck_speed_limit_fops },
660 { .name = "lfsck_layout",
661 .fops = &ofd_lfsck_layout_fops },
662 { .name = "lfsck_verify_pfid",
663 .fops = &ofd_lfsck_verify_pfid_fops },
667 void ofd_stats_counter_init(struct lprocfs_stats *stats)
669 LASSERT(stats && stats->ls_num >= LPROC_OFD_STATS_LAST);
671 lprocfs_counter_init(stats, LPROC_OFD_STATS_READ,
672 LPROCFS_CNTR_AVGMINMAX, "read_bytes", "bytes");
673 lprocfs_counter_init(stats, LPROC_OFD_STATS_WRITE,
674 LPROCFS_CNTR_AVGMINMAX, "write_bytes", "bytes");
675 lprocfs_counter_init(stats, LPROC_OFD_STATS_GETATTR,
676 0, "getattr", "reqs");
677 lprocfs_counter_init(stats, LPROC_OFD_STATS_SETATTR,
678 0, "setattr", "reqs");
679 lprocfs_counter_init(stats, LPROC_OFD_STATS_PUNCH,
681 lprocfs_counter_init(stats, LPROC_OFD_STATS_SYNC,
683 lprocfs_counter_init(stats, LPROC_OFD_STATS_DESTROY,
684 0, "destroy", "reqs");
685 lprocfs_counter_init(stats, LPROC_OFD_STATS_CREATE,
686 0, "create", "reqs");
687 lprocfs_counter_init(stats, LPROC_OFD_STATS_STATFS,
688 0, "statfs", "reqs");
689 lprocfs_counter_init(stats, LPROC_OFD_STATS_GET_INFO,
690 0, "get_info", "reqs");
691 lprocfs_counter_init(stats, LPROC_OFD_STATS_SET_INFO,
692 0, "set_info", "reqs");
693 lprocfs_counter_init(stats, LPROC_OFD_STATS_QUOTACTL,
694 0, "quotactl", "reqs");