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, lnet_nid_t *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 || *nid == LNET_NID_ANY)
533 libcfs_nid2str_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 lnet_nid4_to_nid(*nid, &new_stat->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_real(), brw_stats->bs_init, 25,
782 for (i = 0; i < ARRAY_SIZE(brw_stats->bs_props); i++) {
783 if (!brw_stats->bs_props[i].bsp_name)
786 display_brw_stats(seq, brw_stats->bs_props[i].bsp_name,
787 brw_stats->bs_props[i].bsp_units,
788 &brw_stats->bs_hist[i * 2],
789 &brw_stats->bs_hist[i * 2 + 1],
790 brw_stats->bs_props[i].bsp_scale);
796 static ssize_t brw_stats_seq_write(struct file *file,
797 const char __user *buf,
798 size_t len, loff_t *off)
800 struct seq_file *seq = file->private_data;
801 struct brw_stats *brw_stats = seq->private;
804 for (i = 0; i < BRW_RW_STATS_NUM; i++)
805 lprocfs_oh_clear_pcpu(&brw_stats->bs_hist[i]);
806 brw_stats->bs_init = ktime_get_real();
811 LDEBUGFS_SEQ_FOPS(brw_stats);
813 int lprocfs_init_brw_stats(struct brw_stats *brw_stats)
817 for (i = 0; i < BRW_RW_STATS_NUM; i++) {
818 result = lprocfs_oh_alloc_pcpu(&brw_stats->bs_hist[i]);
825 EXPORT_SYMBOL(lprocfs_init_brw_stats);
827 void lprocfs_fini_brw_stats(struct brw_stats *brw_stats)
831 for (i = 0; i < BRW_RW_STATS_NUM; i++)
832 lprocfs_oh_release_pcpu(&brw_stats->bs_hist[i]);
834 EXPORT_SYMBOL(lprocfs_fini_brw_stats);
836 void ldebugfs_register_osd_stats(struct dentry *parent,
837 struct brw_stats *brw_stats,
838 struct lprocfs_stats *stats)
843 brw_stats->bs_init = ktime_get_real();
844 for (i = 0; i < BRW_RW_STATS_NUM; i++) {
845 struct brw_stats_props *props = brw_stats->bs_props;
848 props[i / 2].bsp_name = brw_props[i / 2].bsp_name;
849 props[i / 2].bsp_units = brw_props[i / 2].bsp_units;
850 props[i / 2].bsp_scale = brw_props[i / 2].bsp_scale;
857 debugfs_create_file("brw_stats", 0644, parent, brw_stats,
861 debugfs_create_file("stats", 0644, parent, stats,
862 &ldebugfs_stats_seq_fops);
864 EXPORT_SYMBOL(ldebugfs_register_osd_stats);
866 int lprocfs_hash_seq_show(struct seq_file *m, void *data)
868 struct obd_device *obd = m->private;
873 /* header for rhashtable state */
874 seq_printf(m, "%-*s cur min max theta t-min t-max flags rehash count maxdep distribution\n",
875 HASH_NAME_LEN, "name");
876 ldebugfs_rhash_seq_show("UUID_HASH", &obd->obd_uuid_hash, m);
877 ldebugfs_rhash_seq_show("NID_HASH", &obd->obd_nid_hash.ht, m);
879 cfs_hash_debug_header(m);
880 cfs_hash_debug_str(obd->obd_nid_stats_hash, m);
883 EXPORT_SYMBOL(lprocfs_hash_seq_show);
885 int lprocfs_recovery_status_seq_show(struct seq_file *m, void *data)
887 struct obd_device *obd = m->private;
888 struct target_distribute_txn_data *tdtd;
890 LASSERT(obd != NULL);
892 seq_printf(m, "status: ");
893 if (atomic_read(&obd->obd_max_recoverable_clients) == 0) {
894 seq_printf(m, "INACTIVE\n");
898 /* There is gap between client data read from storage and setting
899 * obd_recovering so check obd_recovery_end as well to make sure
900 * recovery is really finished
902 if (obd->obd_recovery_end > 0 && !obd->obd_recovering) {
903 seq_printf(m, "COMPLETE\n");
904 seq_printf(m, "recovery_start: %lld\n",
905 (s64)ktime_get_real_seconds() -
906 (ktime_get_seconds() - obd->obd_recovery_start));
907 seq_printf(m, "recovery_duration: %lld\n",
908 obd->obd_recovery_end ?
909 obd->obd_recovery_end - obd->obd_recovery_start :
910 ktime_get_seconds() - obd->obd_recovery_start);
911 /* Number of clients that have completed recovery */
912 seq_printf(m, "completed_clients: %d/%d\n",
913 atomic_read(&obd->obd_max_recoverable_clients) -
914 obd->obd_stale_clients,
915 atomic_read(&obd->obd_max_recoverable_clients));
916 seq_printf(m, "replayed_requests: %d\n",
917 obd->obd_replayed_requests);
918 seq_printf(m, "last_transno: %lld\n",
919 obd->obd_next_recovery_transno - 1);
920 seq_printf(m, "VBR: %s\n", obd->obd_version_recov ?
921 "ENABLED" : "DISABLED");
922 seq_printf(m, "IR: %s\n", obd->obd_no_ir ?
923 "DISABLED" : "ENABLED");
927 tdtd = obd->u.obt.obt_lut->lut_tdtd;
928 if (tdtd && tdtd->tdtd_show_update_logs_retrievers) {
933 buf = tdtd->tdtd_show_update_logs_retrievers(
934 tdtd->tdtd_show_retrievers_cbdata,
937 seq_printf(m, "WAITING\n");
938 seq_printf(m, "non-ready MDTs: %s\n",
939 buf ? buf : "unknown (not enough RAM)");
940 seq_printf(m, "recovery_start: %lld\n",
941 (s64)ktime_get_real_seconds() -
942 (ktime_get_seconds() -
943 obd->obd_recovery_start));
944 seq_printf(m, "time_waited: %lld\n",
945 (s64)(ktime_get_seconds() -
946 obd->obd_recovery_start));
952 if (likely(count > 0))
956 /* recovery won't start until the clients connect */
957 if (obd->obd_recovery_start == 0) {
958 seq_printf(m, "WAITING_FOR_CLIENTS\n");
962 seq_printf(m, "RECOVERING\n");
963 seq_printf(m, "recovery_start: %lld\n", (s64)ktime_get_real_seconds() -
964 (ktime_get_seconds() - obd->obd_recovery_start));
965 seq_printf(m, "time_remaining: %lld\n",
966 ktime_get_seconds() >=
967 obd->obd_recovery_start +
968 obd->obd_recovery_timeout ? 0 :
969 (s64)(obd->obd_recovery_start +
970 obd->obd_recovery_timeout -
971 ktime_get_seconds()));
972 seq_printf(m, "connected_clients: %d/%d\n",
973 atomic_read(&obd->obd_connected_clients),
974 atomic_read(&obd->obd_max_recoverable_clients));
975 /* Number of clients that have completed recovery */
976 seq_printf(m, "req_replay_clients: %d\n",
977 atomic_read(&obd->obd_req_replay_clients));
978 seq_printf(m, "lock_repay_clients: %d\n",
979 atomic_read(&obd->obd_lock_replay_clients));
980 seq_printf(m, "completed_clients: %d\n",
981 atomic_read(&obd->obd_connected_clients) -
982 atomic_read(&obd->obd_lock_replay_clients));
983 seq_printf(m, "evicted_clients: %d\n", obd->obd_stale_clients);
984 seq_printf(m, "replayed_requests: %d\n", obd->obd_replayed_requests);
985 seq_printf(m, "queued_requests: %d\n",
986 obd->obd_requests_queued_for_recovery);
987 seq_printf(m, "next_transno: %lld\n",
988 obd->obd_next_recovery_transno);
992 EXPORT_SYMBOL(lprocfs_recovery_status_seq_show);
994 ssize_t ir_factor_show(struct kobject *kobj, struct attribute *attr,
997 struct obd_device *obd = container_of(kobj, struct obd_device,
1000 return scnprintf(buf, PAGE_SIZE, "%d\n", obd->obd_recovery_ir_factor);
1002 EXPORT_SYMBOL(ir_factor_show);
1004 ssize_t ir_factor_store(struct kobject *kobj, struct attribute *attr,
1005 const char *buffer, size_t count)
1007 struct obd_device *obd = container_of(kobj, struct obd_device,
1012 rc = kstrtoint(buffer, 10, &val);
1016 if (val < OBD_IR_FACTOR_MIN || val > OBD_IR_FACTOR_MAX)
1019 obd->obd_recovery_ir_factor = val;
1022 EXPORT_SYMBOL(ir_factor_store);
1024 int lprocfs_checksum_dump_seq_show(struct seq_file *m, void *data)
1026 struct obd_device *obd = m->private;
1028 LASSERT(obd != NULL);
1029 seq_printf(m, "%d\n", obd->obd_checksum_dump);
1032 EXPORT_SYMBOL(lprocfs_checksum_dump_seq_show);
1035 lprocfs_checksum_dump_seq_write(struct file *file, const char __user *buffer,
1036 size_t count, loff_t *off)
1038 struct seq_file *m = file->private_data;
1039 struct obd_device *obd = m->private;
1043 LASSERT(obd != NULL);
1044 rc = kstrtobool_from_user(buffer, count, &val);
1048 obd->obd_checksum_dump = val;
1051 EXPORT_SYMBOL(lprocfs_checksum_dump_seq_write);
1053 ssize_t recovery_time_soft_show(struct kobject *kobj, struct attribute *attr,
1056 struct obd_device *obd = container_of(kobj, struct obd_device,
1059 return scnprintf(buf, PAGE_SIZE, "%d\n", obd->obd_recovery_timeout);
1061 EXPORT_SYMBOL(recovery_time_soft_show);
1063 ssize_t recovery_time_soft_store(struct kobject *kobj,
1064 struct attribute *attr,
1065 const char *buffer, size_t count)
1067 struct obd_device *obd = container_of(kobj, struct obd_device,
1072 rc = kstrtouint(buffer, 0, &val);
1076 obd->obd_recovery_timeout = val;
1079 EXPORT_SYMBOL(recovery_time_soft_store);
1081 ssize_t recovery_time_hard_show(struct kobject *kobj, struct attribute *attr,
1084 struct obd_device *obd = container_of(kobj, struct obd_device,
1087 return scnprintf(buf, PAGE_SIZE, "%d\n", obd->obd_recovery_time_hard);
1089 EXPORT_SYMBOL(recovery_time_hard_show);
1091 ssize_t recovery_time_hard_store(struct kobject *kobj,
1092 struct attribute *attr,
1093 const char *buffer, size_t count)
1095 struct obd_device *obd = container_of(kobj, struct obd_device,
1100 rc = kstrtouint(buffer, 0, &val);
1104 obd->obd_recovery_time_hard = val;
1107 EXPORT_SYMBOL(recovery_time_hard_store);
1109 ssize_t instance_show(struct kobject *kobj, struct attribute *attr,
1112 struct obd_device *obd = container_of(kobj, struct obd_device,
1114 struct obd_device_target *target = &obd->u.obt;
1116 LASSERT(target->obt_magic == OBT_MAGIC);
1117 return scnprintf(buf, PAGE_SIZE, "%u\n", obd->u.obt.obt_instance);
1119 EXPORT_SYMBOL(instance_show);
1121 #endif /* CONFIG_PROC_FS*/