1 /* $NetBSD: opdump.c,v 1.36 2012/03/15 02:02:21 joerg 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.36 2012/03/15 02:02:21 joerg Exp $");
41 #include <sys/types.h>
45 #include <puffsdump.h>
49 #include "puffs_priv.h"
53 const char *puffsdump_vfsop_revmap
[] = {
67 "PUFFS_VFS_EXTATTRCTL",
70 size_t puffsdump_vfsop_count
= __arraycount(puffsdump_vfsop_revmap
);
72 const char *puffsdump_vnop_revmap
[] = {
114 "PUFFS_VN_GETEXTATTR",
115 "PUFFS_VN_LISTEXTATTR",
116 "PUFFS_VN_OPENEXTATTR",
117 "PUFFS_VN_DELETEEXTATTR",
118 "PUFFS_VN_SETEXTATTR",
119 "PUFFS_VN_CLOSEEXTATTR",
121 size_t puffsdump_vnop_count
= __arraycount(puffsdump_vnop_revmap
);
124 const char *puffsdump_cacheop_revmap
[] = {
128 const char *puffsdump_errnot_revmap
[] = {
130 "PUFFS_ERR_MAKENODE",
133 "PUFFS_ERR_READLINK",
137 "PUFFS_ERR_GETEXTATTR",
138 "PUFFS_ERR_LISTEXTATTR",
140 size_t puffsdump_errnot_count
= __arraycount(puffsdump_errnot_revmap
);
142 const char *puffsdump_flush_revmap
[] = {
143 "PUFFS_INVAL_NAMECACHE_NODE",
144 "PUFFS_INVAL_NAMECACHE_DIR",
145 "PUFFS_INVAL_NAMECACHE_ALL",
146 "PUFFS_INVAL_PAGECACHE_NODE_RANGE",
147 "PUFFS_FLUSH_PAGECACHE_NODE_RANGE",
149 size_t puffsdump_flush_count
= __arraycount(puffsdump_flush_revmap
);
151 static __printflike(1, 2) void
152 mydprintf(const char *fmt
, ...)
157 vfprintf(stderr
, fmt
, ap
);
162 puffsdump_req(struct puffs_req
*preq
)
165 static struct timeval tv_prev
;
166 struct timeval tv_now
, tv
;
170 int opclass
, isvn
= 0;
172 mydprintf("reqid: %" PRIu64
", ", preq
->preq_id
);
173 opclass
= PUFFSOP_OPCLASS(preq
->preq_opclass
);
176 map
= puffsdump_vfsop_revmap
;
177 maxhandle
= puffsdump_vfsop_count
;
180 map
= puffsdump_vnop_revmap
;
181 maxhandle
= puffsdump_vnop_count
;
185 map
= puffsdump_cacheop_revmap
;
186 maxhandle
= __arraycount(puffsdump_cacheop_revmap
);
189 map
= puffsdump_errnot_revmap
;
190 maxhandle
= puffsdump_errnot_count
;
193 map
= puffsdump_flush_revmap
;
194 maxhandle
= puffsdump_flush_count
;
197 mydprintf("unhandled opclass %d\n", opclass
);
201 if (preq
->preq_optype
< maxhandle
) {
202 optype
= map
[preq
->preq_optype
];
204 snprintf(buf
, sizeof(buf
), "UNKNOWN (%d)", preq
->preq_optype
);
208 mydprintf("opclass %d%s, optype: %s, "
209 "cookie: %p,\n" DINT
"aux: %p, auxlen: %zu, pid: %d, lwpid: %d\n",
210 opclass
, PUFFSOP_WANTREPLY(preq
->preq_opclass
) ? "" : " (FAF)",
211 optype
, preq
->preq_cookie
,
212 preq
->preq_buf
, preq
->preq_buflen
,
213 preq
->preq_pid
, preq
->preq_lid
);
216 switch (preq
->preq_optype
) {
217 case PUFFS_VN_LOOKUP
:
218 puffsdump_lookup(preq
);
222 puffsdump_readwrite(preq
);
225 puffsdump_open(preq
);
227 case PUFFS_VN_REMOVE
:
230 puffsdump_targ(preq
);
232 case PUFFS_VN_READDIR
:
233 puffsdump_readdir(preq
);
235 case PUFFS_VN_CREATE
:
238 case PUFFS_VN_SYMLINK
:
239 puffsdump_create(preq
);
241 case PUFFS_VN_SETATTR
:
242 puffsdump_attr(preq
);
250 gettimeofday(&tv_now
, NULL
);
251 timersub(&tv_now
, &tv_prev
, &tv
);
252 mydprintf(DINT
"since previous call: %lld.%06ld\n",
253 (long long)tv
.tv_sec
, (long)tv
.tv_usec
);
254 gettimeofday(&tv_prev
, NULL
);
259 puffsdump_rv(struct puffs_req
*preq
)
262 if (PUFFSOP_OPCLASS(preq
->preq_opclass
) == PUFFSOP_VN
) {
263 switch (preq
->preq_optype
) {
264 case PUFFS_VN_LOOKUP
:
265 puffsdump_lookup_rv(preq
);
267 case PUFFS_VN_CREATE
:
270 case PUFFS_VN_SYMLINK
:
271 puffsdump_create_rv(preq
);
275 puffsdump_readwrite_rv(preq
);
277 case PUFFS_VN_READDIR
:
278 puffsdump_readdir_rv(preq
);
280 case PUFFS_VN_GETATTR
:
281 puffsdump_attr(preq
);
288 mydprintf("RV reqid: %" PRIu64
", result: %d %s\n",
289 preq
->preq_id
, preq
->preq_rv
,
290 preq
->preq_rv
? strerror(preq
->preq_rv
) : "");
294 * Slightly tedious print-routine so that we get a nice NOVAL instead
295 * of some tedious output representations for -1, especially (uint64_t)-1
297 * We use typecasting to make this work beyond time_t/dev_t size changes.
300 dumpattr(struct vattr
*vap
)
302 const char * const vtypes
[] = { VNODE_TYPES
};
305 /* XXX: better readability. and this is debug, so no cycle-sweat */
306 #define DEFAULTBUF() snprintf(buf, sizeof(buf), "NOVAL")
308 mydprintf(DINT
"vattr:\n");
309 mydprintf(DINT DINT
"type: %s, ", vtypes
[vap
->va_type
]);
312 if (vap
->va_mode
!= (mode_t
)PUFFS_VNOVAL
)
313 snprintf(buf
, sizeof(buf
), "0%o", vap
->va_mode
);
314 mydprintf("mode: %s, ", buf
);
317 if (vap
->va_nlink
!= (nlink_t
)PUFFS_VNOVAL
)
318 snprintf(buf
, sizeof(buf
), "%d", vap
->va_nlink
);
319 mydprintf("nlink: %s, ", buf
);
322 if (vap
->va_uid
!= (uid_t
)PUFFS_VNOVAL
)
323 snprintf(buf
, sizeof(buf
), "%d", vap
->va_uid
);
324 mydprintf("uid: %s, ", buf
);
327 if (vap
->va_gid
!= (gid_t
)PUFFS_VNOVAL
)
328 snprintf(buf
, sizeof(buf
), "%d", vap
->va_gid
);
329 mydprintf("gid: %s\n", buf
);
332 if ((unsigned long long)vap
->va_fsid
!=(unsigned long long)PUFFS_VNOVAL
)
333 snprintf(buf
, sizeof(buf
), "0x%llx",
334 (unsigned long long)vap
->va_fsid
);
335 mydprintf(DINT DINT
"fsid: %s, ", buf
);
338 if (vap
->va_fileid
!= (ino_t
)PUFFS_VNOVAL
)
339 snprintf(buf
, sizeof(buf
), "%" PRIu64
, vap
->va_fileid
);
340 mydprintf("ino: %s, ", buf
);
343 if (vap
->va_size
!= (u_quad_t
)PUFFS_VNOVAL
)
344 snprintf(buf
, sizeof(buf
), "%" PRIu64
, vap
->va_size
);
345 mydprintf("size: %s, ", buf
);
348 if (vap
->va_blocksize
!= (long)PUFFS_VNOVAL
)
349 snprintf(buf
, sizeof(buf
), "%ld", vap
->va_blocksize
);
350 mydprintf("bsize: %s\n", buf
);
353 if (vap
->va_atime
.tv_sec
!= (time_t)PUFFS_VNOVAL
)
354 snprintf(buf
, sizeof(buf
), "%lld",
355 (long long)vap
->va_atime
.tv_sec
);
356 mydprintf(DINT DINT
"a.s: %s, ", buf
);
359 if (vap
->va_atime
.tv_nsec
!= (long)PUFFS_VNOVAL
)
360 snprintf(buf
, sizeof(buf
), "%ld", vap
->va_atime
.tv_nsec
);
361 mydprintf("a.ns: %s, ", buf
);
364 if (vap
->va_mtime
.tv_sec
!= (time_t)PUFFS_VNOVAL
)
365 snprintf(buf
, sizeof(buf
), "%lld",
366 (long long)vap
->va_mtime
.tv_sec
);
367 mydprintf("m.s: %s, ", buf
);
370 if (vap
->va_mtime
.tv_nsec
!= (long)PUFFS_VNOVAL
)
371 snprintf(buf
, sizeof(buf
), "%ld", vap
->va_mtime
.tv_nsec
);
372 mydprintf("m.ns: %s\n", buf
);
375 if (vap
->va_ctime
.tv_sec
!= (time_t)PUFFS_VNOVAL
)
376 snprintf(buf
, sizeof(buf
), "%lld",
377 (long long)vap
->va_ctime
.tv_sec
);
378 mydprintf(DINT DINT
"c.s: %s, ", buf
);
381 if (vap
->va_ctime
.tv_nsec
!= (long)PUFFS_VNOVAL
)
382 snprintf(buf
, sizeof(buf
), "%ld", vap
->va_ctime
.tv_nsec
);
383 mydprintf("c.ns: %s, ", buf
);
386 if (vap
->va_birthtime
.tv_sec
!= (time_t)PUFFS_VNOVAL
)
387 snprintf(buf
, sizeof(buf
), "%lld",
388 (long long)vap
->va_birthtime
.tv_sec
);
389 mydprintf("b.s: %s, ", buf
);
392 if (vap
->va_birthtime
.tv_nsec
!= (long)PUFFS_VNOVAL
)
393 snprintf(buf
, sizeof(buf
), "%ld", vap
->va_birthtime
.tv_nsec
);
394 mydprintf("b.ns: %s\n", buf
);
397 if (vap
->va_gen
!= (u_long
)PUFFS_VNOVAL
)
398 snprintf(buf
, sizeof(buf
), "%lu", vap
->va_gen
);
399 mydprintf(DINT DINT
"gen: %s, ", buf
);
402 if (vap
->va_flags
!= (u_long
)PUFFS_VNOVAL
)
403 snprintf(buf
, sizeof(buf
), "0x%lx", vap
->va_flags
);
404 mydprintf("flags: %s, ", buf
);
407 if (vap
->va_rdev
!= (dev_t
)PUFFS_VNOVAL
)
408 snprintf(buf
, sizeof(buf
), "0x%llx",
409 (unsigned long long)vap
->va_rdev
);
410 mydprintf("rdev: %s\n", buf
);
413 if (vap
->va_bytes
!= (u_quad_t
)PUFFS_VNOVAL
)
414 snprintf(buf
, sizeof(buf
), "%" PRIu64
, vap
->va_bytes
);
415 mydprintf(DINT DINT
"bytes: %s, ", buf
);
417 snprintf(buf
, sizeof(buf
), "%" PRIu64
, vap
->va_filerev
);
418 mydprintf("filerev: %s, ", buf
);
420 snprintf(buf
, sizeof(buf
), "0x%x", vap
->va_vaflags
);
421 mydprintf("vaflags: %s\n", buf
);
425 puffsdump_cookie(puffs_cookie_t c
, const char *cookiename
)
428 mydprintf("%scookie: at %p\n", cookiename
, c
);
431 static const char *cn_opnames
[] = {
439 puffsdump_cn(struct puffs_kcn
*pkcn
)
442 mydprintf(DINT
"puffs_cn: \"%s\", len %zu op %s (flags 0x%x)\n",
443 pkcn
->pkcn_name
, pkcn
->pkcn_namelen
,
444 cn_opnames
[pkcn
->pkcn_nameiop
& NAMEI_OPMASK
],
449 puffsdump_lookup(struct puffs_req
*preq
)
451 struct puffs_vnmsg_lookup
*lookup_msg
= (void *)preq
;
453 puffsdump_cn(&lookup_msg
->pvnr_cn
);
457 puffsdump_lookup_rv(struct puffs_req
*preq
)
459 struct puffs_vnmsg_lookup
*lookup_msg
= (void *)preq
;
461 mydprintf(DINT
"new %p, type 0x%x, size 0x%"PRIu64
", dev 0x%llx\n",
462 lookup_msg
->pvnr_newnode
, lookup_msg
->pvnr_vtype
,
463 lookup_msg
->pvnr_size
, (unsigned long long)lookup_msg
->pvnr_rdev
);
467 puffsdump_create(struct puffs_req
*preq
)
469 /* XXX: wrong type, but we know it fits the slot */
470 struct puffs_vnmsg_create
*create_msg
= (void *)preq
;
472 dumpattr(&create_msg
->pvnr_va
);
476 puffsdump_create_rv(struct puffs_req
*preq
)
478 /* XXX: wrong type, but we know it fits the slot */
479 struct puffs_vnmsg_create
*create_msg
= (void *)preq
;
481 mydprintf(DINT
"new %p\n", create_msg
->pvnr_newnode
);
485 puffsdump_readwrite(struct puffs_req
*preq
)
487 struct puffs_vnmsg_rw
*rw_msg
= (void *)preq
;
489 mydprintf(DINT
"offset: %" PRId64
", resid %zu, ioflag 0x%x\n",
490 rw_msg
->pvnr_offset
, rw_msg
->pvnr_resid
, rw_msg
->pvnr_ioflag
);
494 puffsdump_readwrite_rv(struct puffs_req
*preq
)
496 struct puffs_vnmsg_rw
*rw_msg
= (void *)preq
;
498 mydprintf(DINT
"resid after op: %zu\n", rw_msg
->pvnr_resid
);
502 puffsdump_readdir_rv(struct puffs_req
*preq
)
504 struct puffs_vnmsg_readdir
*readdir_msg
= (void *)preq
;
506 mydprintf(DINT
"resid after op: %zu, eofflag %d\n",
507 readdir_msg
->pvnr_resid
, readdir_msg
->pvnr_eofflag
);
511 puffsdump_open(struct puffs_req
*preq
)
513 struct puffs_vnmsg_open
*open_msg
= (void *)preq
;
515 mydprintf(DINT
"mode: 0x%x\n", open_msg
->pvnr_mode
);
519 puffsdump_targ(struct puffs_req
*preq
)
521 struct puffs_vnmsg_remove
*remove_msg
= (void *)preq
; /* XXX! */
523 mydprintf(DINT
"target cookie: %p\n", remove_msg
->pvnr_cookie_targ
);
527 puffsdump_readdir(struct puffs_req
*preq
)
529 struct puffs_vnmsg_readdir
*readdir_msg
= (void *)preq
;
531 mydprintf(DINT
"read offset: %" PRId64
"\n", readdir_msg
->pvnr_offset
);
535 puffsdump_attr(struct puffs_req
*preq
)
537 struct puffs_vnmsg_setgetattr
*attr_msg
= (void *)preq
;
539 dumpattr(&attr_msg
->pvnr_va
);