1/*	$OpenBSD: nfs_debug.c,v 1.7 2024/05/01 13:15:59 jsg Exp $ */
2/*
3 * Copyright (c) 2009 Thordur I. Bjornsson. <thib@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17#include <sys/param.h>
18#include <sys/systm.h>
19#include <sys/mount.h>
20#include <sys/pool.h>
21#include <sys/vnode.h>
22
23#include <nfs/nfsproto.h>
24#include <nfs/nfs.h>
25#include <nfs/nfsnode.h>
26
27#include <machine/db_machdep.h>
28#include <ddb/db_interface.h>
29#include <ddb/db_output.h>
30
31void
32db_show_all_nfsreqs(db_expr_t expr, int haddr, db_expr_t count, char *modif)
33{
34	int full = 0;
35
36	if (modif[0] == 'f')
37		full = 1;
38
39	pool_walk(&nfsreqpl, full, db_printf, nfs_request_print);
40}
41
42void
43nfs_request_print(void *v, int full, int (*pr)(const char *, ...))
44{
45	struct nfsreq	*rep = v;
46
47	(*pr)("xid 0x%x flags 0x%x rexmit %i procnum %i proc %p\n",
48	    rep->r_xid, rep->r_flags, rep->r_rexmit, rep->r_procnum,
49	    rep->r_procp);
50
51	if (full) {
52		(*pr)("mreq %p mrep %p md %p nfsmount %p vnode %p timer %i",
53		    " rtt %i\n",
54		    rep->r_mreq, rep->r_mrep, rep->r_md, rep->r_nmp,
55		    rep->r_vp, rep->r_timer, rep->r_rtt);
56	}
57}
58
59void
60db_show_all_nfsnodes(db_expr_t expr, int haddr, db_expr_t count, char *modif)
61{
62	int full = 0;
63
64	if (modif[0] == 'f')
65		full = 1;
66
67	pool_walk(&nfs_node_pool, full, db_printf, nfs_node_print);
68}
69
70
71
72void
73nfs_node_print(void *v, int full, int (*pr)(const char *, ...))
74{
75	struct nfsnode	*np = v;
76
77	(*pr)("size %llu flag %i vnode %p accstamp %lld\n",
78	    np->n_size, np->n_flag, np->n_vnode, (long long)np->n_accstamp);
79
80	if (full) {
81		(*pr)("pushedlo %llu pushedhi %llu pushlo %llu pushhi %llu\n",
82		    np->n_pushedlo, np->n_pushedhi, np->n_pushlo,
83		    np->n_pushhi);
84		(*pr)("commitflags %i\n", np->n_commitflags);
85	}
86}
87