opdump.c revision 1.11
1/*	$NetBSD: opdump.c,v 1.11 2007/06/30 12:42:25 pooka Exp $	*/
2
3/*
4 * Copyright (c) 2005, 2006  Antti Kantee.  All Rights Reserved.
5 *
6 * Development of this software was supported by the
7 * Google Summer of Code program and the Ulla Tuominen Foundation.
8 * The Google SoC project was mentored by Bill Studenmund.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
20 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32/* Pretty-printing helper routines for VFS/VOP request contents */
33
34/* yes, this is pretty much a mess */
35
36#include <sys/cdefs.h>
37#if !defined(lint)
38__RCSID("$NetBSD: opdump.c,v 1.11 2007/06/30 12:42:25 pooka Exp $");
39#endif /* !lint */
40
41#include <sys/types.h>
42#include <sys/time.h>
43
44#include <puffs.h>
45#include <puffsdump.h>
46#include <stdio.h>
47
48/* XXX! */
49const char *vfsop_revmap[] = {
50	"PUFFS_VFS_MOUNT",
51	"PUFFS_VFS_START",
52	"PUFFS_VFS_UNMOUNT",
53	"PUFFS_VFS_ROOT",
54	"PUFFS_VFS_STATVFS",
55	"PUFFS_VFS_SYNC",
56	"PUFFS_VFS_VGET",
57	"PUFFS_VFS_FHTOVP",
58	"PUFFS_VFS_VPTOFH",
59	"PUFFS_VFS_INIT",
60	"PUFFS_VFS_DONE",
61	"PUFFS_VFS_SNAPSHOT",
62	"PUFFS_VFS_EXTATTCTL",
63	"PUFFS_VFS_SUSPEND"
64};
65/* XXX! */
66const char *vnop_revmap[] = {
67	"PUFFS_VN_LOOKUP",
68	"PUFFS_VN_CREATE",
69	"PUFFS_VN_MKNOD",
70	"PUFFS_VN_OPEN",
71	"PUFFS_VN_CLOSE",
72	"PUFFS_VN_ACCESS",
73	"PUFFS_VN_GETATTR",
74	"PUFFS_VN_SETATTR",
75	"PUFFS_VN_READ",
76	"PUFFS_VN_WRITE",
77	"PUFFS_VN_IOCTL",
78	"PUFFS_VN_FCNTL",
79	"PUFFS_VN_POLL",
80	"PUFFS_VN_KQFILTER",
81	"PUFFS_VN_REVOKE",
82	"PUFFS_VN_MMAP",
83	"PUFFS_VN_FSYNC",
84	"PUFFS_VN_SEEK",
85	"PUFFS_VN_REMOVE",
86	"PUFFS_VN_LINK",
87	"PUFFS_VN_RENAME",
88	"PUFFS_VN_MKDIR",
89	"PUFFS_VN_RMDIR",
90	"PUFFS_VN_SYMLINK",
91	"PUFFS_VN_READDIR",
92	"PUFFS_VN_READLINK",
93	"PUFFS_VN_ABORTOP",
94	"PUFFS_VN_INACTIVE",
95	"PUFFS_VN_RECLAIM",
96	"PUFFS_VN_LOCK",
97	"PUFFS_VN_UNLOCK",
98	"PUFFS_VN_BMAP",
99	"PUFFS_VN_STRATEGY",
100	"PUFFS_VN_PRINT",
101	"PUFFS_VN_ISLOCKED",
102	"PUFFS_VN_PATHCONF",
103	"PUFFS_VN_ADVLOCK",
104	"PUFFS_VN_LEASE",
105	"PUFFS_VN_WHITEOUT",
106	"PUFFS_VN_GETPAGES",
107	"PUFFS_VN_PUTPAGES",
108	"PUFFS_VN_BWRITE",
109	"PUFFS_VN_GETEXTATTR",
110	"PUFFS_VN_LISTEXTATTR",
111	"PUFFS_VN_OPENEXTATTR",
112	"PUFFS_VN_DELETEEXTATTR",
113	"PUFFS_VN_SETEXTATTR",
114};
115const char *cacheop_revmap[] = {
116	"PUFFS_CACHE_WRITE"
117};
118
119void
120puffsdump_req(struct puffs_req *preq)
121{
122	static struct timeval tv_prev;
123	struct timeval tv_now, tv;
124	const char **map;
125
126	map = NULL; /* yes, we are all interested in your opinion, gcc */
127	switch (PUFFSOP_OPCLASS(preq->preq_opclass)) {
128	case PUFFSOP_VFS:
129		map = vfsop_revmap;
130		break;
131	case PUFFSOP_VN:
132		map = vnop_revmap;
133		break;
134	case PUFFSOP_CACHE:
135		map = cacheop_revmap;
136		break;
137	}
138
139	printf("\treqid: %" PRIu64 ", opclass %d%s, optype: %s, "
140	    "cookie: %p,\n\t\taux: %p, auxlen: %zu\n",
141	    preq->preq_id, PUFFSOP_OPCLASS(preq->preq_opclass),
142	    PUFFSOP_WANTREPLY(preq->preq_opclass) ? "" : " (FAF)",
143	    map[preq->preq_optype], preq->preq_cookie,
144	    preq->preq_buf, preq->preq_buflen);
145
146	gettimeofday(&tv_now, NULL);
147	timersub(&tv_now, &tv_prev, &tv);
148	printf("\t\tsince previous call: %ld.%06ld\n", tv.tv_sec, tv.tv_usec);
149	gettimeofday(&tv_prev, NULL);
150}
151
152void
153puffsdump_rv(struct puffs_req *preq)
154{
155
156	printf("\tRV reqid: %" PRIu64 ", result: %d %s\n",
157	    preq->preq_id, preq->preq_rv,
158	    preq->preq_rv ? strerror(preq->preq_rv) : "");
159}
160
161void
162puffsdump_cookie(void *c, const char *cookiename)
163{
164
165	printf("\t%scookie: at %p\n", cookiename, c);
166}
167
168#if 0
169static const char *cn_opnames[] = {
170	"LOOKUP",
171	"CREATE",
172	"DELETE",
173	"RENAME"
174};
175void
176puffsdump_cn(struct puffs_cn *pcn)
177{
178
179	printf("\tpuffs_cn: %s (%sfollow)\n",
180	    cn_opnames[pcn->pcn_nameio & PUFFSLOOKUP_OPMASK],
181	    pcn->pcn_nameio&PUFFSLOOKUP_OPTIONS==PUFFSLOOKUP_NOFOLLOW?"no":"");
182	/*
183	TOFINISH
184	*/
185}
186#endif
187
188void
189/*ARGSUSED*/
190puffsdump_creds(struct puffs_cred *pcr)
191{
192
193}
194
195void
196puffsdump_int(int value, const char *name)
197{
198
199	printf("\tint (%s): %d\n", name, value);
200}
201