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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2014, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 * lustre/obdclass/lprocfs_status_server.c
34 #define DEBUG_SUBSYSTEM S_CLASS
36 #include <linux/kobject.h>
37 #include <linux/sysfs.h>
39 #include <obd_class.h>
40 #include <lprocfs_status.h>
41 #include <lustre_nodemap.h>
43 #define MAX_STRING_SIZE 128
45 struct dentry *ldebugfs_add_symlink(const char *name, const char *target,
46 const char *format, ...)
48 struct dentry *entry = NULL;
49 struct dentry *parent;
54 if (!target || !format)
58 dname.len = strlen(dname.name);
59 dname.hash = ll_full_name_hash(debugfs_lustre_root,
60 dname.name, dname.len);
61 parent = d_lookup(debugfs_lustre_root, &dname);
65 OBD_ALLOC_WAIT(dest, MAX_STRING_SIZE + 1);
70 vsnprintf(dest, MAX_STRING_SIZE, format, ap);
73 entry = debugfs_create_symlink(name, parent, dest);
75 OBD_FREE(dest, MAX_STRING_SIZE + 1);
80 EXPORT_SYMBOL(ldebugfs_add_symlink);
84 int lprocfs_evict_client_open(struct inode *inode, struct file *f)
86 struct obd_device *obd = PDE_DATA(file_inode(f));
88 atomic_inc(&obd->obd_evict_inprogress);
92 int lprocfs_evict_client_release(struct inode *inode, struct file *f)
94 struct obd_device *obd = PDE_DATA(file_inode(f));
96 atomic_dec(&obd->obd_evict_inprogress);
97 wake_up(&obd->obd_evict_inprogress_waitq);
102 #define BUFLEN (UUID_MAX + 5)
105 lprocfs_evict_client_seq_write(struct file *file, const char __user *buffer,
106 size_t count, loff_t *off)
108 struct seq_file *m = file->private_data;
109 struct obd_device *obd = m->private;
112 OBD_ALLOC(kbuf, BUFLEN);
117 * OBD_ALLOC() will zero kbuf, but we only copy BUFLEN - 1
118 * bytes into kbuf, to ensure that the string is NUL-terminated.
119 * UUID_MAX should include a trailing NUL already.
121 if (copy_from_user(kbuf, buffer,
122 min_t(unsigned long, BUFLEN - 1, count))) {
126 tmpbuf = skip_spaces(kbuf);
127 tmpbuf = strsep(&tmpbuf, " \t\n\f\v\r");
128 class_incref(obd, __func__, current);
130 if (strncmp(tmpbuf, "nid:", 4) == 0)
131 obd_export_evict_by_nid(obd, tmpbuf + 4);
132 else if (strncmp(tmpbuf, "uuid:", 5) == 0)
133 obd_export_evict_by_uuid(obd, tmpbuf + 5);
135 obd_export_evict_by_uuid(obd, tmpbuf);
137 class_decref(obd, __func__, current);
140 OBD_FREE(kbuf, BUFLEN);
143 EXPORT_SYMBOL(lprocfs_evict_client_seq_write);
147 ssize_t num_exports_show(struct kobject *kobj, struct attribute *attr,
150 struct obd_device *obd = container_of(kobj, struct obd_device,
153 return scnprintf(buf, PAGE_SIZE, "%u\n", obd->obd_num_exports);
155 EXPORT_SYMBOL(num_exports_show);
157 ssize_t grant_check_threshold_show(struct kobject *kobj, struct attribute *attr,
160 struct obd_device *obd = container_of(kobj, struct obd_device,
163 return scnprintf(buf, PAGE_SIZE, "%d\n",
164 obd->obd_grant_check_threshold);
166 EXPORT_SYMBOL(grant_check_threshold_show);
168 ssize_t grant_check_threshold_store(struct kobject *kobj,
169 struct attribute *attr,
170 const char *buffer, size_t count)
172 struct obd_device *obd = container_of(kobj, struct obd_device,
177 rc = kstrtoint(buffer, 10, &val);
183 obd->obd_grant_check_threshold = val;
186 EXPORT_SYMBOL(grant_check_threshold_store);
188 static int obd_export_flags2str(struct obd_export *exp, struct seq_file *m)
192 flag2str(exp, failed);
193 flag2str(exp, in_recovery);
194 flag2str(exp, disconnected);
195 flag2str(exp, connecting);
196 flag2str(exp, no_recovery);
202 lprocfs_exp_print_export_seq(struct obd_export *exp, void *cb_data)
204 struct seq_file *m = cb_data;
205 struct obd_device *obd;
206 struct obd_connect_data *ocd;
208 LASSERT(exp != NULL);
209 if (exp->exp_nid_stats == NULL)
212 ocd = &exp->exp_connect_data;
214 seq_printf(m, "%s:\n"
217 " connect_flags: [ ",
218 obd_uuid2str(&exp->exp_client_uuid),
220 obd_export_nid2str(exp));
221 obd_connect_seq_flags2str(m, ocd->ocd_connect_flags,
222 ocd->ocd_connect_flags2, ", ");
223 seq_printf(m, " ]\n");
224 obd_connect_data_seqprint(m, ocd);
225 seq_printf(m, " export_flags: [ ");
226 obd_export_flags2str(exp, m);
227 seq_printf(m, " ]\n");
230 strcmp(obd->obd_type->typ_name, "obdfilter") == 0) {
231 struct filter_export_data *fed = &exp->exp_filter_data;
233 seq_printf(m, " grant:\n");
234 seq_printf(m, " granted: %ld\n",
235 fed->fed_ted.ted_grant);
236 seq_printf(m, " dirty: %ld\n",
237 fed->fed_ted.ted_dirty);
238 seq_printf(m, " pending: %ld\n",
239 fed->fed_ted.ted_pending);
247 * RPC connections are composed of an import and an export. Using the
248 * lctl utility we can extract important information about the state.
249 * The lprocfs_exp_export_seq_show routine displays the state information
252 * \param[in] m seq file
253 * \param[in] data unused
255 * \retval 0 on success
257 * The format of the export state information is like:
258 * a793e354-49c0-aa11-8c4f-a4f2b1a1a92b:
260 * client: 10.211.55.10@tcp
261 * connect_flags: [ version, barrier, adaptive_timeouts, ... ]
263 * flags: 0x2000011005002020
265 * target_version: 2.10.51.0
266 * export_flags: [ ... ]
269 static int lprocfs_exp_export_seq_show(struct seq_file *m, void *data)
271 struct nid_stat *stats = m->private;
273 return obd_nid_export_for_each(stats->nid_obd, &stats->nid,
274 lprocfs_exp_print_export_seq, m);
276 LPROC_SEQ_FOPS_RO(lprocfs_exp_export);
278 static void lprocfs_free_client_stats(struct nid_stat *client_stat)
280 CDEBUG(D_CONFIG, "stat %p - data %p/%p\n", client_stat,
281 client_stat->nid_proc, client_stat->nid_stats);
283 LASSERTF(atomic_read(&client_stat->nid_exp_ref_count) == 0,
284 "nid %s:count %d\n", libcfs_nidstr(&client_stat->nid),
285 atomic_read(&client_stat->nid_exp_ref_count));
287 if (client_stat->nid_proc)
288 lprocfs_remove(&client_stat->nid_proc);
290 if (client_stat->nid_stats)
291 lprocfs_free_stats(&client_stat->nid_stats);
293 if (client_stat->nid_ldlm_stats)
294 lprocfs_free_stats(&client_stat->nid_ldlm_stats);
296 OBD_FREE_PTR(client_stat);
299 void lprocfs_free_per_client_stats(struct obd_device *obd)
301 struct cfs_hash *hash = obd->obd_nid_stats_hash;
302 struct nid_stat *stat;
305 /* we need extra list - because hash_exit called to early */
306 /* not need locking because all clients is died */
307 while (!list_empty(&obd->obd_nid_stats)) {
308 stat = list_entry(obd->obd_nid_stats.next,
309 struct nid_stat, nid_list);
310 list_del_init(&stat->nid_list);
311 cfs_hash_del(hash, &stat->nid, &stat->nid_hash);
312 lprocfs_free_client_stats(stat);
316 EXPORT_SYMBOL(lprocfs_free_per_client_stats);
319 lprocfs_exp_print_nodemap_seq(struct obd_export *exp, void *cb_data)
321 struct lu_nodemap *nodemap = exp->exp_target_data.ted_nodemap;
322 struct seq_file *m = cb_data;
325 seq_printf(m, "%s\n", nodemap->nm_name);
330 lprocfs_exp_nodemap_seq_show(struct seq_file *m, void *data)
332 struct nid_stat *stats = m->private;
334 return obd_nid_export_for_each(stats->nid_obd, &stats->nid,
335 lprocfs_exp_print_nodemap_seq, m);
337 LPROC_SEQ_FOPS_RO(lprocfs_exp_nodemap);
340 lprocfs_exp_print_uuid_seq(struct obd_export *exp, void *cb_data)
342 struct seq_file *m = cb_data;
344 if (exp->exp_nid_stats)
345 seq_printf(m, "%s\n", obd_uuid2str(&exp->exp_client_uuid));
349 static int lprocfs_exp_uuid_seq_show(struct seq_file *m, void *data)
351 struct nid_stat *stats = m->private;
353 return obd_nid_export_for_each(stats->nid_obd, &stats->nid,
354 lprocfs_exp_print_uuid_seq, m);
356 LPROC_SEQ_FOPS_RO(lprocfs_exp_uuid);
358 #define HASH_NAME_LEN 16
360 static void ldebugfs_rhash_seq_show(const char *name, struct rhashtable *ht,
363 unsigned int max_size = ht->p.max_size ? ht->p.max_size : UINT_MAX;
364 struct bucket_table *tbl;
365 int dist[8] = { 0, };
370 tbl = rht_dereference(ht->tbl, ht);
371 for (i = 0; i < tbl->size; i++) {
372 struct rhash_head *pos;
375 rht_for_each(pos, tbl, i)
379 maxdep = max(maxdep, count);
381 dist[min(fls(count), 7)]++;
384 seq_printf(m, "%-*s %5d %5d %10u %d.%03d 0.300 0.750 0x%03x %7d %7d %7d ",
385 HASH_NAME_LEN, name, tbl->size, ht->p.min_size, max_size,
386 atomic_read(&ht->nelems) / tbl->size,
387 atomic_read(&ht->nelems) * 1000 / tbl->size,
388 ht->p.automatic_shrinking, 0,
389 atomic_read(&ht->nelems), maxdep);
392 for (i = 0; i < 8; i++)
393 seq_printf(m, "%d%c", dist[i], (i == 7) ? '\n' : '/');
397 lprocfs_exp_print_hash_seq(struct obd_export *exp, void *cb_data)
400 struct obd_device *obd = exp->exp_obd;
401 struct seq_file *m = cb_data;
403 if (exp->exp_lock_hash != NULL) {
404 seq_printf(m, "%-*s cur min max theta t-min t-max flags rehash count distribution\n",
405 HASH_NAME_LEN, "name");
406 ldebugfs_rhash_seq_show("NID_HASH", &obd->obd_nid_hash.ht, m);
411 static int lprocfs_exp_hash_seq_show(struct seq_file *m, void *data)
413 struct nid_stat *stats = m->private;
415 return obd_nid_export_for_each(stats->nid_obd, &stats->nid,
416 lprocfs_exp_print_hash_seq, m);
418 LPROC_SEQ_FOPS_RO(lprocfs_exp_hash);
420 int lprocfs_exp_print_replydata_seq(struct obd_export *exp, void *cb_data)
423 struct seq_file *m = cb_data;
424 struct tg_export_data *ted = &exp->exp_target_data;
426 seq_printf(m, "reply_cnt: %d\n"
428 "reply_released_by_xid: %d\n"
429 "reply_released_by_tag: %d\n\n",
432 ted->ted_release_xid,
433 ted->ted_release_tag);
437 int lprocfs_exp_replydata_seq_show(struct seq_file *m, void *data)
439 struct nid_stat *stats = m->private;
441 return obd_nid_export_for_each(stats->nid_obd, &stats->nid,
442 lprocfs_exp_print_replydata_seq, m);
444 LPROC_SEQ_FOPS_RO(lprocfs_exp_replydata);
446 int lprocfs_exp_print_fmd_count_seq(struct obd_export *exp, void *cb_data)
448 struct seq_file *m = cb_data;
449 struct tg_export_data *ted = &exp->exp_target_data;
451 seq_printf(m, "%d\n", ted->ted_fmd_count);
456 int lprocfs_exp_fmd_count_seq_show(struct seq_file *m, void *data)
458 struct nid_stat *stats = m->private;
460 return obd_nid_export_for_each(stats->nid_obd, &stats->nid,
461 lprocfs_exp_print_fmd_count_seq, m);
463 LPROC_SEQ_FOPS_RO(lprocfs_exp_fmd_count);
465 int lprocfs_nid_stats_clear_seq_show(struct seq_file *m, void *data)
467 seq_puts(m, "Write into this file to clear all nid stats and stale nid entries\n");
470 EXPORT_SYMBOL(lprocfs_nid_stats_clear_seq_show);
472 static int lprocfs_nid_stats_clear_write_cb(void *obj, void *data)
474 struct nid_stat *stat = obj;
477 CDEBUG(D_INFO, "refcnt %d\n", atomic_read(&stat->nid_exp_ref_count));
478 if (atomic_read(&stat->nid_exp_ref_count) == 1) {
479 /* object has only hash references. */
480 spin_lock(&stat->nid_obd->obd_nid_lock);
481 list_move(&stat->nid_list, data);
482 spin_unlock(&stat->nid_obd->obd_nid_lock);
485 /* we has reference to object - only clear data*/
487 lprocfs_clear_stats(stat->nid_stats);
493 lprocfs_nid_stats_clear_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 nid_stat *client_stat;
499 LIST_HEAD(free_list);
501 cfs_hash_cond_del(obd->obd_nid_stats_hash,
502 lprocfs_nid_stats_clear_write_cb, &free_list);
504 while (!list_empty(&free_list)) {
505 client_stat = list_entry(free_list.next, struct nid_stat,
507 list_del_init(&client_stat->nid_list);
508 lprocfs_free_client_stats(client_stat);
512 EXPORT_SYMBOL(lprocfs_nid_stats_clear_seq_write);
514 int lprocfs_exp_setup(struct obd_export *exp, struct lnet_nid *nid)
516 struct nid_stat *new_stat, *old_stat;
517 struct obd_device *obd = NULL;
518 struct proc_dir_entry *entry;
519 char nidstr[LNET_NIDSTR_SIZE];
523 if (!exp || !exp->exp_obd || !exp->exp_obd->obd_proc_exports_entry ||
524 !exp->exp_obd->obd_nid_stats_hash)
527 /* not test against zero because eric say:
528 * You may only test nid against another nid, or LNET_NID_ANY.
529 * Anything else is nonsense.*/
530 if (nid == NULL || LNET_NID_IS_ANY(nid))
533 libcfs_nidstr_r(nid, nidstr, sizeof(nidstr));
535 spin_lock(&exp->exp_lock);
536 if (exp->exp_nid_stats != NULL) {
537 spin_unlock(&exp->exp_lock);
540 spin_unlock(&exp->exp_lock);
544 CDEBUG(D_CONFIG, "using hash %p\n", obd->obd_nid_stats_hash);
546 OBD_ALLOC_PTR(new_stat);
547 if (new_stat == NULL)
550 new_stat->nid = *nid;
551 new_stat->nid_obd = exp->exp_obd;
552 /* we need set default refcount to 1 to balance obd_disconnect */
553 atomic_set(&new_stat->nid_exp_ref_count, 1);
555 old_stat = cfs_hash_findadd_unique(obd->obd_nid_stats_hash,
557 &new_stat->nid_hash);
558 CDEBUG(D_INFO, "Found stats %p for nid %s - ref %d\n",
559 old_stat, nidstr, atomic_read(&old_stat->nid_exp_ref_count));
561 /* Return -EALREADY here so that we know that the /proc
562 * entry already has been created */
563 if (old_stat != new_stat) {
564 spin_lock(&exp->exp_lock);
565 if (exp->exp_nid_stats) {
566 LASSERT(exp->exp_nid_stats == old_stat);
567 nidstat_putref(exp->exp_nid_stats);
569 exp->exp_nid_stats = old_stat;
570 spin_unlock(&exp->exp_lock);
571 GOTO(destroy_new, rc = -EALREADY);
573 /* not found - create */
574 new_stat->nid_proc = lprocfs_register(nidstr,
575 obd->obd_proc_exports_entry,
578 if (IS_ERR(new_stat->nid_proc)) {
579 rc = PTR_ERR(new_stat->nid_proc);
580 new_stat->nid_proc = NULL;
581 CERROR("%s: cannot create proc entry for export %s: rc = %d\n",
582 obd->obd_name, nidstr, rc);
583 GOTO(destroy_new_ns, rc);
586 entry = lprocfs_add_simple(new_stat->nid_proc, "nodemap", new_stat,
587 &lprocfs_exp_nodemap_fops);
590 CWARN("%s: error adding the nodemap file: rc = %d\n",
592 GOTO(destroy_new_ns, rc);
595 entry = lprocfs_add_simple(new_stat->nid_proc, "uuid", new_stat,
596 &lprocfs_exp_uuid_fops);
599 CWARN("%s: error adding the NID stats file: rc = %d\n",
601 GOTO(destroy_new_ns, rc);
604 entry = lprocfs_add_simple(new_stat->nid_proc, "hash", new_stat,
605 &lprocfs_exp_hash_fops);
608 CWARN("%s: error adding the hash file: rc = %d\n",
610 GOTO(destroy_new_ns, rc);
613 entry = lprocfs_add_simple(new_stat->nid_proc, "export",
614 new_stat, &lprocfs_exp_export_fops);
617 CWARN("%s: error adding the export file: rc = %d\n",
619 GOTO(destroy_new_ns, rc);
622 entry = lprocfs_add_simple(new_stat->nid_proc, "reply_data", new_stat,
623 &lprocfs_exp_replydata_fops);
626 CWARN("%s: error adding the reply_data file: rc = %d\n",
628 GOTO(destroy_new_ns, rc);
631 entry = lprocfs_add_simple(new_stat->nid_proc, "fmd_count", new_stat,
632 &lprocfs_exp_fmd_count_fops);
635 CWARN("%s: error adding the fmd_count file: rc = %d\n",
637 GOTO(destroy_new_ns, rc);
640 spin_lock(&exp->exp_lock);
641 exp->exp_nid_stats = new_stat;
642 spin_unlock(&exp->exp_lock);
644 /* protect competitive add to list, not need locking on destroy */
645 spin_lock(&obd->obd_nid_lock);
646 list_add(&new_stat->nid_list, &obd->obd_nid_stats);
647 spin_unlock(&obd->obd_nid_lock);
652 if (new_stat->nid_proc != NULL)
653 lprocfs_remove(&new_stat->nid_proc);
654 cfs_hash_del(obd->obd_nid_stats_hash, &new_stat->nid,
655 &new_stat->nid_hash);
658 nidstat_putref(new_stat);
659 OBD_FREE_PTR(new_stat);
662 EXPORT_SYMBOL(lprocfs_exp_setup);
664 int lprocfs_exp_cleanup(struct obd_export *exp)
666 struct nid_stat *stat = exp->exp_nid_stats;
668 if (!stat || !exp->exp_obd)
671 nidstat_putref(exp->exp_nid_stats);
672 exp->exp_nid_stats = NULL;
677 int lprocfs_alloc_obd_stats(struct obd_device *obd, unsigned int num_stats)
679 struct lprocfs_stats *stats;
682 LASSERT(obd->obd_stats == NULL);
683 LASSERT(obd->obd_proc_entry != NULL);
685 stats = lprocfs_alloc_stats(num_stats, 0);
689 rc = lprocfs_register_stats(obd->obd_proc_entry, "stats", stats);
691 lprocfs_free_stats(&stats);
693 obd->obd_stats = stats;
697 EXPORT_SYMBOL(lprocfs_alloc_obd_stats);
699 void lprocfs_free_obd_stats(struct obd_device *obd)
702 lprocfs_free_stats(&obd->obd_stats);
704 EXPORT_SYMBOL(lprocfs_free_obd_stats);
706 static void display_brw_stats(struct seq_file *seq, const char *name,
707 const char *units, struct obd_hist_pcpu *read,
708 struct obd_hist_pcpu *write, bool scale)
710 unsigned long read_tot, write_tot, r, w, read_cum = 0, write_cum = 0;
713 seq_printf(seq, "\n%26s read | write\n", " ");
714 seq_printf(seq, "%-22s %-5s %% cum %% | %-11s %% cum %%\n",
717 read_tot = lprocfs_oh_sum_pcpu(read);
718 write_tot = lprocfs_oh_sum_pcpu(write);
720 if (!read_tot && !write_tot)
723 for (i = 0; i < OBD_HIST_MAX; i++) {
724 r = lprocfs_oh_counter_pcpu(read, i);
725 w = lprocfs_oh_counter_pcpu(write, i);
728 if (read_cum == 0 && write_cum == 0)
732 seq_printf(seq, "%u", i);
734 seq_printf(seq, "%lu", BIT(i));
736 seq_printf(seq, "%luK", BIT(i - 10));
738 seq_printf(seq, "%luM", BIT(i - 20));
740 seq_printf(seq, ":\t\t%10lu %3u %3u | %4lu %3u %3u\n",
741 r, pct(r, read_tot), pct(read_cum, read_tot),
742 w, pct(w, write_tot), pct(write_cum, write_tot));
744 if (read_cum == read_tot && write_cum == write_tot)
749 static const struct brw_stats_props brw_props[] = {
750 { .bsp_name = "pages per bulk r/w",
753 { .bsp_name = "discontiguous pages",
755 .bsp_scale = false },
756 { .bsp_name = "discontiguous blocks",
758 .bsp_scale = false },
759 { .bsp_name = "disk fragmented I/Os",
761 .bsp_scale = false },
762 { .bsp_name = "disk I/Os in flight",
764 .bsp_scale = false },
765 { .bsp_name = "I/O time (1/1000s)",
768 { .bsp_name = "disk I/O size",
773 static int brw_stats_seq_show(struct seq_file *seq, void *v)
775 struct brw_stats *brw_stats = seq->private;
778 /* this sampling races with updates */
779 lprocfs_stats_header(seq, ktime_get(), brw_stats->bs_init, 25, ":", 1);
781 for (i = 0; i < ARRAY_SIZE(brw_stats->bs_props); i++) {
782 if (!brw_stats->bs_props[i].bsp_name)
785 display_brw_stats(seq, brw_stats->bs_props[i].bsp_name,
786 brw_stats->bs_props[i].bsp_units,
787 &brw_stats->bs_hist[i * 2],
788 &brw_stats->bs_hist[i * 2 + 1],
789 brw_stats->bs_props[i].bsp_scale);
795 static ssize_t brw_stats_seq_write(struct file *file,
796 const char __user *buf,
797 size_t len, loff_t *off)
799 struct seq_file *seq = file->private_data;
800 struct brw_stats *brw_stats = seq->private;
803 for (i = 0; i < BRW_RW_STATS_NUM; i++)
804 lprocfs_oh_clear_pcpu(&brw_stats->bs_hist[i]);
809 LDEBUGFS_SEQ_FOPS(brw_stats);
811 int lprocfs_init_brw_stats(struct brw_stats *brw_stats)
815 for (i = 0; i < BRW_RW_STATS_NUM; i++) {
816 result = lprocfs_oh_alloc_pcpu(&brw_stats->bs_hist[i]);
823 EXPORT_SYMBOL(lprocfs_init_brw_stats);
825 void lprocfs_fini_brw_stats(struct brw_stats *brw_stats)
829 for (i = 0; i < BRW_RW_STATS_NUM; i++)
830 lprocfs_oh_release_pcpu(&brw_stats->bs_hist[i]);
832 EXPORT_SYMBOL(lprocfs_fini_brw_stats);
834 void ldebugfs_register_osd_stats(struct dentry *parent,
835 struct brw_stats *brw_stats,
836 struct lprocfs_stats *stats)
841 brw_stats->bs_init = ktime_get();
842 for (i = 0; i < BRW_RW_STATS_NUM; i++) {
843 struct brw_stats_props *props = brw_stats->bs_props;
846 props[i / 2].bsp_name = brw_props[i / 2].bsp_name;
847 props[i / 2].bsp_units = brw_props[i / 2].bsp_units;
848 props[i / 2].bsp_scale = brw_props[i / 2].bsp_scale;
855 debugfs_create_file("brw_stats", 0644, parent, brw_stats,
859 debugfs_create_file("stats", 0644, parent, stats,
860 &ldebugfs_stats_seq_fops);
862 EXPORT_SYMBOL(ldebugfs_register_osd_stats);
864 int lprocfs_hash_seq_show(struct seq_file *m, void *data)
866 struct obd_device *obd = m->private;
871 /* header for rhashtable state */
872 seq_printf(m, "%-*s cur min max theta t-min t-max flags rehash count maxdep distribution\n",
873 HASH_NAME_LEN, "name");
874 ldebugfs_rhash_seq_show("UUID_HASH", &obd->obd_uuid_hash, m);
875 ldebugfs_rhash_seq_show("NID_HASH", &obd->obd_nid_hash.ht, m);
877 cfs_hash_debug_header(m);
878 cfs_hash_debug_str(obd->obd_nid_stats_hash, m);
881 EXPORT_SYMBOL(lprocfs_hash_seq_show);
883 int lprocfs_recovery_status_seq_show(struct seq_file *m, void *data)
885 struct obd_device *obd = m->private;
886 struct target_distribute_txn_data *tdtd;
888 LASSERT(obd != NULL);
890 seq_printf(m, "status: ");
891 if (atomic_read(&obd->obd_max_recoverable_clients) == 0) {
892 seq_printf(m, "INACTIVE\n");
896 /* There is gap between client data read from storage and setting
897 * obd_recovering so check obd_recovery_end as well to make sure
898 * recovery is really finished
900 if (obd->obd_recovery_end > 0 && !obd->obd_recovering) {
901 seq_printf(m, "COMPLETE\n");
902 seq_printf(m, "recovery_start: %lld\n",
903 (s64)ktime_get_real_seconds() -
904 (ktime_get_seconds() - obd->obd_recovery_start));
905 seq_printf(m, "recovery_duration: %lld\n",
906 obd->obd_recovery_end ?
907 obd->obd_recovery_end - obd->obd_recovery_start :
908 ktime_get_seconds() - obd->obd_recovery_start);
909 /* Number of clients that have completed recovery */
910 seq_printf(m, "completed_clients: %d/%d\n",
911 atomic_read(&obd->obd_max_recoverable_clients) -
912 obd->obd_stale_clients,
913 atomic_read(&obd->obd_max_recoverable_clients));
914 seq_printf(m, "replayed_requests: %d\n",
915 obd->obd_replayed_requests);
916 seq_printf(m, "last_transno: %lld\n",
917 obd->obd_next_recovery_transno - 1);
918 seq_printf(m, "VBR: %s\n", obd->obd_version_recov ?
919 "ENABLED" : "DISABLED");
920 seq_printf(m, "IR: %s\n", obd->obd_no_ir ?
921 "DISABLED" : "ENABLED");
925 tdtd = obd->u.obt.obt_lut->lut_tdtd;
926 if (tdtd && tdtd->tdtd_show_update_logs_retrievers) {
931 buf = tdtd->tdtd_show_update_logs_retrievers(
932 tdtd->tdtd_show_retrievers_cbdata,
935 seq_printf(m, "WAITING\n");
936 seq_printf(m, "non-ready MDTs: %s\n",
937 buf ? buf : "unknown (not enough RAM)");
938 seq_printf(m, "recovery_start: %lld\n",
939 (s64)ktime_get_real_seconds() -
940 (ktime_get_seconds() -
941 obd->obd_recovery_start));
942 seq_printf(m, "time_waited: %lld\n",
943 (s64)(ktime_get_seconds() -
944 obd->obd_recovery_start));
950 if (likely(count > 0))
954 /* recovery won't start until the clients connect */
955 if (obd->obd_recovery_start == 0) {
956 seq_printf(m, "WAITING_FOR_CLIENTS\n");
960 seq_printf(m, "RECOVERING\n");
961 seq_printf(m, "recovery_start: %lld\n", (s64)ktime_get_real_seconds() -
962 (ktime_get_seconds() - obd->obd_recovery_start));
963 seq_printf(m, "time_remaining: %lld\n",
964 ktime_get_seconds() >=
965 obd->obd_recovery_start +
966 obd->obd_recovery_timeout ? 0 :
967 (s64)(obd->obd_recovery_start +
968 obd->obd_recovery_timeout -
969 ktime_get_seconds()));
970 seq_printf(m, "connected_clients: %d/%d\n",
971 atomic_read(&obd->obd_connected_clients),
972 atomic_read(&obd->obd_max_recoverable_clients));
973 /* Number of clients that have completed recovery */
974 seq_printf(m, "req_replay_clients: %d\n",
975 atomic_read(&obd->obd_req_replay_clients));
976 seq_printf(m, "lock_repay_clients: %d\n",
977 atomic_read(&obd->obd_lock_replay_clients));
978 seq_printf(m, "completed_clients: %d\n",
979 atomic_read(&obd->obd_connected_clients) -
980 atomic_read(&obd->obd_lock_replay_clients));
981 seq_printf(m, "evicted_clients: %d\n", obd->obd_stale_clients);
982 seq_printf(m, "replayed_requests: %d\n", obd->obd_replayed_requests);
983 seq_printf(m, "queued_requests: %d\n",
984 obd->obd_requests_queued_for_recovery);
985 seq_printf(m, "next_transno: %lld\n",
986 obd->obd_next_recovery_transno);
990 EXPORT_SYMBOL(lprocfs_recovery_status_seq_show);
992 ssize_t ir_factor_show(struct kobject *kobj, struct attribute *attr,
995 struct obd_device *obd = container_of(kobj, struct obd_device,
998 return scnprintf(buf, PAGE_SIZE, "%d\n", obd->obd_recovery_ir_factor);
1000 EXPORT_SYMBOL(ir_factor_show);
1002 ssize_t ir_factor_store(struct kobject *kobj, struct attribute *attr,
1003 const char *buffer, size_t count)
1005 struct obd_device *obd = container_of(kobj, struct obd_device,
1010 rc = kstrtoint(buffer, 10, &val);
1014 if (val < OBD_IR_FACTOR_MIN || val > OBD_IR_FACTOR_MAX)
1017 obd->obd_recovery_ir_factor = val;
1020 EXPORT_SYMBOL(ir_factor_store);
1022 int lprocfs_checksum_dump_seq_show(struct seq_file *m, void *data)
1024 struct obd_device *obd = m->private;
1026 LASSERT(obd != NULL);
1027 seq_printf(m, "%d\n", obd->obd_checksum_dump);
1030 EXPORT_SYMBOL(lprocfs_checksum_dump_seq_show);
1033 lprocfs_checksum_dump_seq_write(struct file *file, const char __user *buffer,
1034 size_t count, loff_t *off)
1036 struct seq_file *m = file->private_data;
1037 struct obd_device *obd = m->private;
1041 LASSERT(obd != NULL);
1042 rc = kstrtobool_from_user(buffer, count, &val);
1046 obd->obd_checksum_dump = val;
1049 EXPORT_SYMBOL(lprocfs_checksum_dump_seq_write);
1051 ssize_t recovery_time_soft_show(struct kobject *kobj, struct attribute *attr,
1054 struct obd_device *obd = container_of(kobj, struct obd_device,
1057 return scnprintf(buf, PAGE_SIZE, "%d\n", obd->obd_recovery_timeout);
1059 EXPORT_SYMBOL(recovery_time_soft_show);
1061 ssize_t recovery_time_soft_store(struct kobject *kobj,
1062 struct attribute *attr,
1063 const char *buffer, size_t count)
1065 struct obd_device *obd = container_of(kobj, struct obd_device,
1070 rc = kstrtouint(buffer, 0, &val);
1074 obd->obd_recovery_timeout = val;
1077 EXPORT_SYMBOL(recovery_time_soft_store);
1079 ssize_t recovery_time_hard_show(struct kobject *kobj, struct attribute *attr,
1082 struct obd_device *obd = container_of(kobj, struct obd_device,
1085 return scnprintf(buf, PAGE_SIZE, "%d\n", obd->obd_recovery_time_hard);
1087 EXPORT_SYMBOL(recovery_time_hard_show);
1089 ssize_t recovery_time_hard_store(struct kobject *kobj,
1090 struct attribute *attr,
1091 const char *buffer, size_t count)
1093 struct obd_device *obd = container_of(kobj, struct obd_device,
1098 rc = kstrtouint(buffer, 0, &val);
1102 obd->obd_recovery_time_hard = val;
1105 EXPORT_SYMBOL(recovery_time_hard_store);
1107 ssize_t instance_show(struct kobject *kobj, struct attribute *attr,
1110 struct obd_device *obd = container_of(kobj, struct obd_device,
1112 struct obd_device_target *target = &obd->u.obt;
1114 LASSERT(target->obt_magic == OBT_MAGIC);
1115 return scnprintf(buf, PAGE_SIZE, "%u\n", obd->u.obt.obt_instance);
1117 EXPORT_SYMBOL(instance_show);
1119 #endif /* CONFIG_PROC_FS*/