Home | History | Annotate | Line # | Download | only in libpuffs
opdump.c revision 1.13
      1 /*	$NetBSD: opdump.c,v 1.13 2007/08/22 17:57:48 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.13 2007/08/22 17:57:48 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! */
     49 const 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! */
     66 const 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 };
    115 const char *cacheop_revmap[] = {
    116 	"PUFFS_CACHE_WRITE"
    117 };
    118 
    119 void
    120 puffsdump_req(struct puffs_req *preq)
    121 {
    122 	static struct timeval tv_prev;
    123 	struct timeval tv_now, tv;
    124 	const char **map;
    125 	int isvn = 0;
    126 
    127 	map = NULL; /* yes, we are all interested in your opinion, gcc */
    128 	switch (PUFFSOP_OPCLASS(preq->preq_opclass)) {
    129 	case PUFFSOP_VFS:
    130 		map = vfsop_revmap;
    131 		break;
    132 	case PUFFSOP_VN:
    133 		map = vnop_revmap;
    134 		isvn = 1;
    135 		break;
    136 	case PUFFSOP_CACHE:
    137 		map = cacheop_revmap;
    138 		break;
    139 	}
    140 
    141 	printf("\treqid: %" PRIu64 ", opclass %d%s, optype: %s, "
    142 	    "cookie: %p,\n\t\taux: %p, auxlen: %zu\n",
    143 	    preq->preq_id, PUFFSOP_OPCLASS(preq->preq_opclass),
    144 	    PUFFSOP_WANTREPLY(preq->preq_opclass) ? "" : " (FAF)",
    145 	    map[preq->preq_optype], preq->preq_cookie,
    146 	    preq->preq_buf, preq->preq_buflen);
    147 
    148 	if (isvn) {
    149 		switch (preq->preq_optype) {
    150 		case PUFFS_VN_LOOKUP:
    151 			puffsdump_lookup(preq);
    152 			break;
    153 		case PUFFS_VN_READ:
    154 		case PUFFS_VN_WRITE:
    155 			puffsdump_readwrite(preq);
    156 			break;
    157 		default:
    158 			break;
    159 		}
    160 	}
    161 
    162 	gettimeofday(&tv_now, NULL);
    163 	timersub(&tv_now, &tv_prev, &tv);
    164 	printf("\t\tsince previous call: %ld.%06ld\n", tv.tv_sec, tv.tv_usec);
    165 	gettimeofday(&tv_prev, NULL);
    166 }
    167 
    168 void
    169 puffsdump_rv(struct puffs_req *preq)
    170 {
    171 
    172 	printf("\tRV reqid: %" PRIu64 ", result: %d %s\n",
    173 	    preq->preq_id, preq->preq_rv,
    174 	    preq->preq_rv ? strerror(preq->preq_rv) : "");
    175 
    176 #ifdef notyet
    177 	if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VN) {
    178 		switch (preq->preq_optype) {
    179 		case PUFFS_VN_LOOKUP:
    180 			puffsdump_lookup_rv(preq);
    181 			break;
    182 		default:
    183 			break;
    184 		}
    185 	}
    186 #endif
    187 }
    188 
    189 void
    190 puffsdump_cookie(void *c, const char *cookiename)
    191 {
    192 
    193 	printf("\t%scookie: at %p\n", cookiename, c);
    194 }
    195 
    196 static const char *cn_opnames[] = {
    197 	"LOOKUP",
    198 	"CREATE",
    199 	"DELETE",
    200 	"RENAME"
    201 };
    202 
    203 void
    204 puffsdump_cn(struct puffs_kcn *pkcn)
    205 {
    206 
    207 	printf("\t\tpuffs_cn: \"%s\", len %zu op %s (flags 0x%x)\n",
    208 	    pkcn->pkcn_name, pkcn->pkcn_namelen,
    209 	    cn_opnames[pkcn->pkcn_nameiop & NAMEI_OPMASK],
    210 	    pkcn->pkcn_flags);
    211 }
    212 
    213 void
    214 puffsdump_lookup(struct puffs_req *preq)
    215 {
    216 	struct puffs_vnreq_lookup *lookup_vnreq = (void *)preq;
    217 
    218 	puffsdump_cn(&lookup_vnreq->pvnr_cn);
    219 }
    220 
    221 void
    222 puffsdump_lookup_rv(struct puffs_req *preq)
    223 {
    224 	struct puffs_vnreq_lookup *lookup_vnreq = (void *)preq;
    225 
    226 	printf("\t\tnew node %p, type 0x%x,\n\t\tsize 0x%"PRIu64", dev 0x%x\n",
    227 	    lookup_vnreq->pvnr_newnode, lookup_vnreq->pvnr_vtype,
    228 	    lookup_vnreq->pvnr_size, lookup_vnreq->pvnr_rdev);
    229 }
    230 
    231 void
    232 puffsdump_readwrite(struct puffs_req *preq)
    233 {
    234 	struct puffs_vnreq_readwrite *rw_vnreq = (void *)preq;
    235 
    236 	printf("\t\toffset: %" PRId64 ", resid %zu, ioflag 0x%x\n",
    237 	    rw_vnreq->pvnr_offset, rw_vnreq->pvnr_resid, rw_vnreq->pvnr_ioflag);
    238 }
    239 
    240 void
    241 /*ARGSUSED*/
    242 puffsdump_creds(struct puffs_cred *pcr)
    243 {
    244 
    245 }
    246 
    247 void
    248 puffsdump_int(int value, const char *name)
    249 {
    250 
    251 	printf("\tint (%s): %d\n", name, value);
    252 }
    253