1 /* $NetBSD: opdump.c,v 1.29 2010/01/07 20:47:47 pooka Exp $ */
4 * Copyright (c) 2005, 2006 Antti Kantee. All Rights Reserved.
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.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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
32 /* Pretty-printing helper routines for VFS/VOP request contents */
34 /* yes, this is pretty much a mess */
36 #include <sys/cdefs.h>
38 __RCSID("$NetBSD: opdump.c,v 1.29 2010/01/07 20:47:47 pooka Exp $");
41 #include <sys/types.h>
45 #include <puffsdump.h>
48 #include "puffs_priv.h"
53 const char *vfsop_revmap
[] = {
66 "PUFFS_VFS_EXTATTCTL",
70 const char *vnop_revmap
[] = {
113 "PUFFS_VN_GETEXTATTR",
114 "PUFFS_VN_LISTEXTATTR",
115 "PUFFS_VN_OPENEXTATTR",
116 "PUFFS_VN_DELETEEXTATTR",
117 "PUFFS_VN_SETEXTATTR",
120 const char *cacheop_revmap
[] = {
124 const char *errnot_revmap
[] = {
125 "PUFFS_ERR_MAKENODE",
128 "PUFFS_ERR_READLINK",
134 const char *flush_revmap
[] = {
135 "PUFFS_INVAL_NAMECACHE_NODE",
136 "PUFFS_INVAL_NAMECACHE_DIR",
137 "PUFFS_INVAL_NAMECACHE_ALL",
138 "PUFFS_INVAL_PAGECACHE_NODE_RANGE",
139 "PUFFS_FLUSH_PAGECACHE_NODE_RANGE",
143 puffsdump_req(struct puffs_req
*preq
)
145 static struct timeval tv_prev
;
146 struct timeval tv_now
, tv
;
150 printf("reqid: %" PRIu64
", ", preq
->preq_id
);
151 switch (PUFFSOP_OPCLASS(preq
->preq_opclass
)) {
160 map
= cacheop_revmap
;
169 printf("unhandled opclass\n");
173 printf("opclass %d%s, optype: %s, "
174 "cookie: %p,\n" DINT
"aux: %p, auxlen: %zu, pid: %d, lwpid: %d\n",
175 PUFFSOP_OPCLASS(preq
->preq_opclass
),
176 PUFFSOP_WANTREPLY(preq
->preq_opclass
) ? "" : " (FAF)",
177 map
[preq
->preq_optype
], preq
->preq_cookie
,
178 preq
->preq_buf
, preq
->preq_buflen
,
179 preq
->preq_pid
, preq
->preq_lid
);
182 switch (preq
->preq_optype
) {
183 case PUFFS_VN_LOOKUP
:
184 puffsdump_lookup(preq
);
188 puffsdump_readwrite(preq
);
191 puffsdump_open(preq
);
193 case PUFFS_VN_REMOVE
:
196 puffsdump_targ(preq
);
198 case PUFFS_VN_READDIR
:
199 puffsdump_readdir(preq
);
201 case PUFFS_VN_CREATE
:
204 case PUFFS_VN_SYMLINK
:
205 puffsdump_create(preq
);
207 case PUFFS_VN_SETATTR
:
208 puffsdump_attr(preq
);
216 gettimeofday(&tv_now
, NULL
);
217 timersub(&tv_now
, &tv_prev
, &tv
);
218 printf(DINT
"since previous call: %lld.%06ld\n",
219 (long long)tv
.tv_sec
, (long)tv
.tv_usec
);
220 gettimeofday(&tv_prev
, NULL
);
225 puffsdump_rv(struct puffs_req
*preq
)
228 if (PUFFSOP_OPCLASS(preq
->preq_opclass
) == PUFFSOP_VN
) {
229 switch (preq
->preq_optype
) {
230 case PUFFS_VN_LOOKUP
:
231 puffsdump_lookup_rv(preq
);
233 case PUFFS_VN_CREATE
:
236 case PUFFS_VN_SYMLINK
:
237 puffsdump_create_rv(preq
);
241 puffsdump_readwrite_rv(preq
);
243 case PUFFS_VN_READDIR
:
244 puffsdump_readdir_rv(preq
);
246 case PUFFS_VN_GETATTR
:
247 puffsdump_attr(preq
);
254 printf("RV reqid: %" PRIu64
", result: %d %s\n",
255 preq
->preq_id
, preq
->preq_rv
,
256 preq
->preq_rv
? strerror(preq
->preq_rv
) : "");
260 * Slightly tedious print-routine so that we get a nice NOVAL instead
261 * of some tedious output representations for -1, especially (uint64_t)-1
263 * We use typecasting to make this work beyond time_t/dev_t size changes.
266 dumpattr(struct vattr
*vap
)
268 const char * const vtypes
[] = { VNODE_TYPES
};
271 /* XXX: better readability. and this is debug, so no cycle-sweat */
272 #define DEFAULTBUF() snprintf(buf, sizeof(buf), "NOVAL")
274 printf(DINT
"vattr:\n");
275 printf(DINT DINT
"type: %s, ", vtypes
[vap
->va_type
]);
278 if (vap
->va_mode
!= (mode_t
)PUFFS_VNOVAL
)
279 snprintf(buf
, sizeof(buf
), "0%o", vap
->va_mode
);
280 printf("mode: %s, ", buf
);
283 if (vap
->va_nlink
!= (nlink_t
)PUFFS_VNOVAL
)
284 snprintf(buf
, sizeof(buf
), "%d", vap
->va_nlink
);
285 printf("nlink: %s, ", buf
);
288 if (vap
->va_uid
!= (uid_t
)PUFFS_VNOVAL
)
289 snprintf(buf
, sizeof(buf
), "%d", vap
->va_uid
);
290 printf("uid: %s, ", buf
);
293 if (vap
->va_gid
!= (gid_t
)PUFFS_VNOVAL
)
294 snprintf(buf
, sizeof(buf
), "%d", vap
->va_gid
);
295 printf("gid: %s\n", buf
);
298 if (vap
->va_fsid
!= (dev_t
)PUFFS_VNOVAL
)
299 snprintf(buf
, sizeof(buf
), "0x%llx",
300 (unsigned long long)vap
->va_fsid
);
301 printf(DINT DINT
"fsid: %s, ", buf
);
304 if (vap
->va_fileid
!= (ino_t
)PUFFS_VNOVAL
)
305 snprintf(buf
, sizeof(buf
), "%" PRIu64
, vap
->va_fileid
);
306 printf("ino: %s, ", buf
);
309 if (vap
->va_size
!= (u_quad_t
)PUFFS_VNOVAL
)
310 snprintf(buf
, sizeof(buf
), "%" PRIu64
, vap
->va_size
);
311 printf("size: %s, ", buf
);
314 if (vap
->va_blocksize
!= (long)PUFFS_VNOVAL
)
315 snprintf(buf
, sizeof(buf
), "%ld", vap
->va_blocksize
);
316 printf("bsize: %s\n", buf
);
319 if (vap
->va_atime
.tv_sec
!= (time_t)PUFFS_VNOVAL
)
320 snprintf(buf
, sizeof(buf
), "%lld",
321 (long long)vap
->va_atime
.tv_sec
);
322 printf(DINT DINT
"a.s: %s, ", buf
);
325 if (vap
->va_atime
.tv_nsec
!= (long)PUFFS_VNOVAL
)
326 snprintf(buf
, sizeof(buf
), "%ld", vap
->va_atime
.tv_nsec
);
327 printf("a.ns: %s, ", buf
);
330 if (vap
->va_mtime
.tv_sec
!= (time_t)PUFFS_VNOVAL
)
331 snprintf(buf
, sizeof(buf
), "%lld",
332 (long long)vap
->va_mtime
.tv_sec
);
333 printf("m.s: %s, ", buf
);
336 if (vap
->va_mtime
.tv_nsec
!= (long)PUFFS_VNOVAL
)
337 snprintf(buf
, sizeof(buf
), "%ld", vap
->va_mtime
.tv_nsec
);
338 printf("m.ns: %s\n", buf
);
341 if (vap
->va_ctime
.tv_sec
!= (time_t)PUFFS_VNOVAL
)
342 snprintf(buf
, sizeof(buf
), "%lld",
343 (long long)vap
->va_ctime
.tv_sec
);
344 printf(DINT DINT
"c.s: %s, ", buf
);
347 if (vap
->va_ctime
.tv_nsec
!= (long)PUFFS_VNOVAL
)
348 snprintf(buf
, sizeof(buf
), "%ld", vap
->va_ctime
.tv_nsec
);
349 printf("c.ns: %s, ", buf
);
352 if (vap
->va_birthtime
.tv_sec
!= (time_t)PUFFS_VNOVAL
)
353 snprintf(buf
, sizeof(buf
), "%lld",
354 (long long)vap
->va_birthtime
.tv_sec
);
355 printf("b.s: %s, ", buf
);
358 if (vap
->va_birthtime
.tv_nsec
!= (long)PUFFS_VNOVAL
)
359 snprintf(buf
, sizeof(buf
), "%ld", vap
->va_birthtime
.tv_nsec
);
360 printf("b.ns: %s\n", buf
);
363 if (vap
->va_gen
!= (u_long
)PUFFS_VNOVAL
)
364 snprintf(buf
, sizeof(buf
), "%lu", vap
->va_gen
);
365 printf(DINT DINT
"gen: %s, ", buf
);
368 if (vap
->va_flags
!= (u_long
)PUFFS_VNOVAL
)
369 snprintf(buf
, sizeof(buf
), "0x%lx", vap
->va_flags
);
370 printf("flags: %s, ", buf
);
373 if (vap
->va_rdev
!= (dev_t
)PUFFS_VNOVAL
)
374 snprintf(buf
, sizeof(buf
), "0x%llx",
375 (unsigned long long)vap
->va_rdev
);
376 printf("rdev: %s\n", buf
);
379 if (vap
->va_bytes
!= (u_quad_t
)PUFFS_VNOVAL
)
380 snprintf(buf
, sizeof(buf
), "%" PRIu64
, vap
->va_bytes
);
381 printf(DINT DINT
"bytes: %s, ", buf
);
383 snprintf(buf
, sizeof(buf
), "%" PRIu64
, vap
->va_filerev
);
384 printf("filerev: %s, ", buf
);
386 snprintf(buf
, sizeof(buf
), "0x%x", vap
->va_vaflags
);
387 printf("vaflags: %s\n", buf
);
391 puffsdump_cookie(puffs_cookie_t c
, const char *cookiename
)
394 printf("%scookie: at %p\n", cookiename
, c
);
397 static const char *cn_opnames
[] = {
405 puffsdump_cn(struct puffs_kcn
*pkcn
)
408 printf(DINT
"puffs_cn: \"%s\", len %zu op %s (flags 0x%x)\n",
409 pkcn
->pkcn_name
, pkcn
->pkcn_namelen
,
410 cn_opnames
[pkcn
->pkcn_nameiop
& NAMEI_OPMASK
],
415 puffsdump_lookup(struct puffs_req
*preq
)
417 struct puffs_vnmsg_lookup
*lookup_msg
= (void *)preq
;
419 puffsdump_cn(&lookup_msg
->pvnr_cn
);
423 puffsdump_lookup_rv(struct puffs_req
*preq
)
425 struct puffs_vnmsg_lookup
*lookup_msg
= (void *)preq
;
427 printf(DINT
"new %p, type 0x%x, size 0x%"PRIu64
", dev 0x%llx\n",
428 lookup_msg
->pvnr_newnode
, lookup_msg
->pvnr_vtype
,
429 lookup_msg
->pvnr_size
, (unsigned long long)lookup_msg
->pvnr_rdev
);
433 puffsdump_create(struct puffs_req
*preq
)
435 /* XXX: wrong type, but we know it fits the slot */
436 struct puffs_vnmsg_create
*create_msg
= (void *)preq
;
438 dumpattr(&create_msg
->pvnr_va
);
442 puffsdump_create_rv(struct puffs_req
*preq
)
444 /* XXX: wrong type, but we know it fits the slot */
445 struct puffs_vnmsg_create
*create_msg
= (void *)preq
;
447 printf(DINT
"new %p\n", create_msg
->pvnr_newnode
);
451 puffsdump_readwrite(struct puffs_req
*preq
)
453 struct puffs_vnmsg_rw
*rw_msg
= (void *)preq
;
455 printf(DINT
"offset: %" PRId64
", resid %zu, ioflag 0x%x\n",
456 rw_msg
->pvnr_offset
, rw_msg
->pvnr_resid
, rw_msg
->pvnr_ioflag
);
460 puffsdump_readwrite_rv(struct puffs_req
*preq
)
462 struct puffs_vnmsg_rw
*rw_msg
= (void *)preq
;
464 printf(DINT
"resid after op: %zu\n", rw_msg
->pvnr_resid
);
468 puffsdump_readdir_rv(struct puffs_req
*preq
)
470 struct puffs_vnmsg_readdir
*readdir_msg
= (void *)preq
;
472 printf(DINT
"resid after op: %zu, eofflag %d\n",
473 readdir_msg
->pvnr_resid
, readdir_msg
->pvnr_eofflag
);
477 puffsdump_open(struct puffs_req
*preq
)
479 struct puffs_vnmsg_open
*open_msg
= (void *)preq
;
481 printf(DINT
"mode: 0x%x\n", open_msg
->pvnr_mode
);
485 puffsdump_targ(struct puffs_req
*preq
)
487 struct puffs_vnmsg_remove
*remove_msg
= (void *)preq
; /* XXX! */
489 printf(DINT
"target cookie: %p\n", remove_msg
->pvnr_cookie_targ
);
493 puffsdump_readdir(struct puffs_req
*preq
)
495 struct puffs_vnmsg_readdir
*readdir_msg
= (void *)preq
;
497 printf(DINT
"read offset: %" PRId64
"\n", readdir_msg
->pvnr_offset
);
501 puffsdump_attr(struct puffs_req
*preq
)
503 struct puffs_vnmsg_setgetattr
*attr_msg
= (void *)preq
;
505 dumpattr(&attr_msg
->pvnr_va
);