From owner-svn-soc-all@FreeBSD.ORG Sun Jul 3 14:06:48 2011 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 8434A106564A for ; Sun, 3 Jul 2011 14:06:46 +0000 (UTC) (envelope-from gk@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Sun, 03 Jul 2011 14:06:46 +0000 Date: Sun, 03 Jul 2011 14:06:46 +0000 From: gk@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20110703140646.8434A106564A@hub.freebsd.org> Cc: Subject: socsvn commit: r223908 - in soc2011/gk/ino64-head/sys: cddl/contrib/opensolaris/uts/common/fs cddl/contrib/opensolaris/uts/common/fs/zfs cddl/contrib/opensolaris/uts/common/sys compat/linux compat/... X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Jul 2011 14:06:48 -0000 Author: gk Date: Sun Jul 3 14:06:46 2011 New Revision: 223908 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=223908 Log: Remove readdir cookies, use directory seek offset from struct dirent Add d_off field to struct dirent. Field name is misleading because d_off represents seek offset of the next directory entry but not current one. Darwin has d_seekoff, but d_off is more widespread (Linux, OpenSolaris). Traditionally current directory offset was returned by VOP_READDIR in cookies array. All actual cookies users had off by one error and thus always skipped first entry at non zero offset: if (cookies) { /* * When using cookies, the vfs has the option of reading from * a different offset than that supplied (UFS truncates the * offset to a block boundary to make sure that it never reads * partway through a directory entry, even if the directory * has been compacted). */ while (len > 0 && ncookies > 0 && *cookiep <= off) { ^^^^^^^^^^^^^^^ (skip first entry with *cookiep == off) } } This code snippet also assumes that directory offsets monotonically increase which is incorrect at least for ZFS and tmpfs. Change all filesystems to set dirent.d_off value in VOP_READDIR. Simplify linux, svr4 and ibcs2 compat shims by using d_off. Modified: soc2011/gk/ino64-head/sys/cddl/contrib/opensolaris/uts/common/fs/gfs.c soc2011/gk/ino64-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ctldir.c soc2011/gk/ino64-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c soc2011/gk/ino64-head/sys/cddl/contrib/opensolaris/uts/common/sys/gfs.h soc2011/gk/ino64-head/sys/compat/linux/linux_file.c soc2011/gk/ino64-head/sys/compat/linux/linux_getcwd.c soc2011/gk/ino64-head/sys/compat/svr4/svr4_misc.c soc2011/gk/ino64-head/sys/fs/cd9660/cd9660_vnops.c soc2011/gk/ino64-head/sys/fs/coda/coda_vnops.c soc2011/gk/ino64-head/sys/fs/devfs/devfs_vnops.c soc2011/gk/ino64-head/sys/fs/ext2fs/ext2_lookup.c soc2011/gk/ino64-head/sys/fs/fdescfs/fdesc_vnops.c soc2011/gk/ino64-head/sys/fs/hpfs/hpfs_vnops.c soc2011/gk/ino64-head/sys/fs/msdosfs/msdosfs_vnops.c soc2011/gk/ino64-head/sys/fs/ntfs/ntfs_vnops.c soc2011/gk/ino64-head/sys/fs/nwfs/nwfs_io.c soc2011/gk/ino64-head/sys/fs/nwfs/nwfs_vnops.c soc2011/gk/ino64-head/sys/fs/portalfs/portal_vnops.c soc2011/gk/ino64-head/sys/fs/pseudofs/pseudofs_vnops.c soc2011/gk/ino64-head/sys/fs/smbfs/smbfs_io.c soc2011/gk/ino64-head/sys/fs/smbfs/smbfs_vnops.c soc2011/gk/ino64-head/sys/fs/tmpfs/tmpfs_subr.c soc2011/gk/ino64-head/sys/fs/tmpfs/tmpfs_vnops.c soc2011/gk/ino64-head/sys/fs/udf/udf_vnops.c soc2011/gk/ino64-head/sys/fs/unionfs/union_subr.c soc2011/gk/ino64-head/sys/fs/unionfs/union_vnops.c soc2011/gk/ino64-head/sys/i386/ibcs2/ibcs2_misc.c soc2011/gk/ino64-head/sys/kern/vfs_default.c soc2011/gk/ino64-head/sys/kern/vfs_subr.c soc2011/gk/ino64-head/sys/kern/vfs_syscalls.c soc2011/gk/ino64-head/sys/kern/vnode_if.src soc2011/gk/ino64-head/sys/sys/dirent.h soc2011/gk/ino64-head/sys/sys/vnode.h soc2011/gk/ino64-head/sys/ufs/ufs/ufs_extattr.c soc2011/gk/ino64-head/sys/ufs/ufs/ufs_vnops.c Modified: soc2011/gk/ino64-head/sys/cddl/contrib/opensolaris/uts/common/fs/gfs.c ============================================================================== --- soc2011/gk/ino64-head/sys/cddl/contrib/opensolaris/uts/common/fs/gfs.c Sun Jul 3 13:27:23 2011 (r223907) +++ soc2011/gk/ino64-head/sys/cddl/contrib/opensolaris/uts/common/fs/gfs.c Sun Jul 3 14:06:46 2011 (r223908) @@ -258,8 +258,7 @@ * next - the offset of the next entry */ static int -gfs_readdir_emit_int(gfs_readdir_state_t *st, uio_t *uiop, offset_t next, - int *ncookies, u_long **cookies) +gfs_readdir_emit_int(gfs_readdir_state_t *st, uio_t *uiop, offset_t next) { int reclen, namlen; dirent64_t *dp; @@ -289,6 +288,7 @@ edp->ed_reclen = (ushort_t)reclen; } else { /* XXX: This can change in the future. */ + dp->d_off = next; dp->d_reclen = (ushort_t)reclen; dp->d_type = DT_DIR; dp->d_namlen = namlen; @@ -298,12 +298,6 @@ return (EFAULT); uiop->uio_loffset = next; - if (*cookies != NULL) { - **cookies = next; - (*cookies)++; - (*ncookies)--; - KASSERT(*ncookies >= 0, ("ncookies=%d", *ncookies)); - } return (0); } @@ -322,7 +316,7 @@ */ int gfs_readdir_emit(gfs_readdir_state_t *st, uio_t *uiop, offset_t voff, - ino64_t ino, const char *name, int eflags, int *ncookies, u_long **cookies) + ino64_t ino, const char *name, int eflags) { offset_t off = (voff + 2) * st->grd_ureclen; @@ -343,8 +337,7 @@ * Inter-entry offsets are invalid, so we assume a record size of * grd_ureclen and explicitly set the offset appropriately. */ - return (gfs_readdir_emit_int(st, uiop, off + st->grd_ureclen, ncookies, - cookies)); + return (gfs_readdir_emit_int(st, uiop, off + st->grd_ureclen)); } #ifdef sun @@ -373,8 +366,7 @@ * gfs_readdir_fini(). */ int -gfs_readdir_pred(gfs_readdir_state_t *st, uio_t *uiop, offset_t *voffp, - int *ncookies, u_long **cookies) +gfs_readdir_pred(gfs_readdir_state_t *st, uio_t *uiop, offset_t *voffp) { offset_t off, voff; int error; @@ -387,11 +379,11 @@ voff = off - 2; if (off == 0) { if ((error = gfs_readdir_emit(st, uiop, voff, st->grd_self, - ".", 0, ncookies, cookies)) == 0) + ".", 0)) == 0) goto top; } else if (off == 1) { if ((error = gfs_readdir_emit(st, uiop, voff, st->grd_parent, - "..", 0, ncookies, cookies)) == 0) + "..", 0)) == 0) goto top; } else { *voffp = voff; @@ -1014,8 +1006,8 @@ * Return 0 on success, or error on failure. */ int -gfs_dir_readdir(vnode_t *dvp, uio_t *uiop, int *eofp, int *ncookies, - u_long **cookies, void *data, cred_t *cr, int flags) +gfs_dir_readdir(vnode_t *dvp, uio_t *uiop, int *eofp, void *data, cred_t *cr, + int flags) { gfs_readdir_state_t gstate; int error, eof = 0; @@ -1031,15 +1023,15 @@ pino, ino, flags)) != 0) return (error); - while ((error = gfs_readdir_pred(&gstate, uiop, &off, ncookies, - cookies)) == 0 && !eof) { + while ((error = gfs_readdir_pred(&gstate, uiop, &off)) == 0 && + !eof) { if (off >= 0 && off < dp->gfsd_nstatic) { ino = dp->gfsd_inode(dvp, off); if ((error = gfs_readdir_emit(&gstate, uiop, - off, ino, dp->gfsd_static[off].gfse_name, 0, - ncookies, cookies)) != 0) + off, ino, dp->gfsd_static[off].gfse_name, 0)) + != 0) break; } else if (dp->gfsd_readdir) { @@ -1054,7 +1046,7 @@ next += dp->gfsd_nstatic + 2; if ((error = gfs_readdir_emit_int(&gstate, uiop, - next, ncookies, cookies)) != 0) + next)) != 0) break; } else { /* @@ -1098,42 +1090,14 @@ struct uio *a_uio; struct ucred *a_cred; int *a_eofflag; - int *ncookies; - u_long **a_cookies; } */ *ap; { vnode_t *vp = ap->a_vp; uio_t *uiop = ap->a_uio; cred_t *cr = ap->a_cred; int *eofp = ap->a_eofflag; - int ncookies = 0; - u_long *cookies = NULL; - int error; - if (ap->a_ncookies) { - /* - * Minimum entry size is dirent size and 1 byte for a file name. - */ - ncookies = uiop->uio_resid / (sizeof(struct dirent) - sizeof(((struct dirent *)NULL)->d_name) + 1); - cookies = malloc(ncookies * sizeof(u_long), M_TEMP, M_WAITOK); - *ap->a_cookies = cookies; - *ap->a_ncookies = ncookies; - } - - error = gfs_dir_readdir(vp, uiop, eofp, &ncookies, &cookies, NULL, - cr, 0); - - if (error == 0) { - /* Subtract unused cookies */ - if (ap->a_ncookies) - *ap->a_ncookies -= ncookies; - } else if (ap->a_ncookies) { - free(*ap->a_cookies, M_TEMP); - *ap->a_cookies = NULL; - *ap->a_ncookies = 0; - } - - return (error); + return (gfs_dir_readdir(vp, uiop, eofp, NULL, cr, 0)); } Modified: soc2011/gk/ino64-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ctldir.c ============================================================================== --- soc2011/gk/ino64-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ctldir.c Sun Jul 3 13:27:23 2011 (r223907) +++ soc2011/gk/ino64-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ctldir.c Sun Jul 3 14:06:46 2011 (r223908) @@ -1168,8 +1168,6 @@ struct uio *a_uio; struct ucred *a_cred; int *a_eofflag; - int *a_ncookies; - u_long **a_cookies; } */ *ap; { vnode_t *vp = ap->a_vp; @@ -1188,7 +1186,7 @@ } if ((error = zfs_zget(zfsvfs, zfsvfs->z_shares_dir, &dzp)) == 0) { vn_lock(ZTOV(dzp), LK_SHARED | LK_RETRY); - error = VOP_READDIR(ZTOV(dzp), uiop, cr, eofp, ap->a_ncookies, ap->a_cookies); + error = VOP_READDIR(ZTOV(dzp), uiop, cr, eofp); VN_URELE(ZTOV(dzp)); } else { *eofp = 1; Modified: soc2011/gk/ino64-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c ============================================================================== --- soc2011/gk/ino64-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c Sun Jul 3 13:27:23 2011 (r223907) +++ soc2011/gk/ino64-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c Sun Jul 3 14:06:46 2011 (r223908) @@ -2297,7 +2297,7 @@ */ /* ARGSUSED */ static int -zfs_readdir(vnode_t *vp, uio_t *uio, cred_t *cr, int *eofp, int *ncookies, u_long **cookies) +zfs_readdir(vnode_t *vp, uio_t *uio, cred_t *cr, int *eofp) { znode_t *zp = VTOZ(vp); iovec_t *iovp; @@ -2318,8 +2318,6 @@ uint8_t prefetch; boolean_t check_sysattrs; uint8_t type; - int ncooks; - u_long *cooks = NULL; int flags = 0; ZFS_ENTER(zfsvfs); @@ -2389,15 +2387,6 @@ } eodp = (struct edirent *)odp; - if (ncookies != NULL) { - /* - * Minimum entry size is dirent size and 1 byte for a file name. - */ - ncooks = uio->uio_resid / (sizeof(struct dirent) - sizeof(((struct dirent *)NULL)->d_name) + 1); - cooks = malloc(ncooks * sizeof(u_long), M_TEMP, M_WAITOK); - *cookies = cooks; - *ncookies = ncooks; - } /* * If this VFS supports the system attribute view interface; and * we're looking at an extended attribute directory; and we care @@ -2529,6 +2518,8 @@ */ odp->d_ino = objnum; odp->d_reclen = reclen; + /* NOTE: d_off is the offset for the *next* entry */ + next = &(odp->d_off); odp->d_namlen = strlen(zap.za_name); (void) strlcpy(odp->d_name, zap.za_name, odp->d_namlen + 1); odp->d_type = type; @@ -2553,18 +2544,11 @@ offset += 1; } - if (cooks != NULL) { - *cooks++ = offset; - ncooks--; - KASSERT(ncooks >= 0, ("ncookies=%d", ncooks)); - } + if (next) + *next = offset; } zp->z_zn_prefetch = B_FALSE; /* a lookup will re-enable pre-fetching */ - /* Subtract unused cookies */ - if (ncookies != NULL) - *ncookies -= ncooks; - if (uio->uio_segflg == UIO_SYSSPACE && uio->uio_iovcnt == 1) { iovp->iov_base += outcount; iovp->iov_len -= outcount; @@ -2588,11 +2572,6 @@ uio->uio_loffset = offset; ZFS_EXIT(zfsvfs); - if (error != 0 && cookies != NULL) { - free(*cookies, M_TEMP); - *cookies = NULL; - *ncookies = 0; - } return (error); } @@ -5825,13 +5804,10 @@ struct uio *a_uio; struct ucred *a_cred; int *a_eofflag; - int *a_ncookies; - u_long **a_cookies; } */ *ap; { - return (zfs_readdir(ap->a_vp, ap->a_uio, ap->a_cred, ap->a_eofflag, - ap->a_ncookies, ap->a_cookies)); + return (zfs_readdir(ap->a_vp, ap->a_uio, ap->a_cred, ap->a_eofflag)); } static int @@ -6550,7 +6526,7 @@ aiov.iov_base = (void *)dirbuf; aiov.iov_len = sizeof(dirbuf); auio.uio_resid = sizeof(dirbuf); - error = VOP_READDIR(vp, &auio, ap->a_cred, &eof, NULL, NULL); + error = VOP_READDIR(vp, &auio, ap->a_cred, &eof); done = sizeof(dirbuf) - auio.uio_resid; if (error != 0) break; Modified: soc2011/gk/ino64-head/sys/cddl/contrib/opensolaris/uts/common/sys/gfs.h ============================================================================== --- soc2011/gk/ino64-head/sys/cddl/contrib/opensolaris/uts/common/sys/gfs.h Sun Jul 3 13:27:23 2011 (r223907) +++ soc2011/gk/ino64-head/sys/cddl/contrib/opensolaris/uts/common/sys/gfs.h Sun Jul 3 14:06:46 2011 (r223908) @@ -102,8 +102,8 @@ int, int *, pathname_t *); extern int gfs_vop_lookup(vnode_t *, char *, vnode_t **, pathname_t *, int, vnode_t *, cred_t *, caller_context_t *, int *, pathname_t *); -extern int gfs_dir_readdir(vnode_t *, uio_t *, int *, int *, u_long **, void *, - cred_t *, int flags); +extern int gfs_dir_readdir(vnode_t *, uio_t *, int *, void *, cred_t *, + int flags); #define gfs_dir_lock(gd) mutex_enter(&(gd)->gfsd_lock) #define gfs_dir_unlock(gd) mutex_exit(&(gd)->gfsd_lock) @@ -132,9 +132,8 @@ extern int gfs_readdir_init(gfs_readdir_state_t *, int, int, uio_t *, ino64_t, ino64_t, int); extern int gfs_readdir_emit(gfs_readdir_state_t *, uio_t *, offset_t, ino64_t, - const char *, int, int *, u_long **); -extern int gfs_readdir_pred(gfs_readdir_state_t *, uio_t *, offset_t *, int *, - u_long **); + const char *, int); +extern int gfs_readdir_pred(gfs_readdir_state_t *, uio_t *, offset_t *); extern int gfs_readdir_fini(gfs_readdir_state_t *, int, int *, int); extern int gfs_get_parent_ino(vnode_t *, cred_t *, caller_context_t *, ino64_t *, ino64_t *); Modified: soc2011/gk/ino64-head/sys/compat/linux/linux_file.c ============================================================================== --- soc2011/gk/ino64-head/sys/compat/linux/linux_file.c Sun Jul 3 13:27:23 2011 (r223907) +++ soc2011/gk/ino64-head/sys/compat/linux/linux_file.c Sun Jul 3 14:06:46 2011 (r223908) @@ -332,8 +332,7 @@ struct l_dirent *linux_dirent; struct l_dirent64 *linux_dirent64; int buflen, error, eofflag, nbytes, justone; - u_long *cookies = NULL, *cookiep; - int ncookies, vfslocked; + int vfslocked; nbytes = args->count; if (nbytes == 1) { @@ -379,11 +378,6 @@ auio.uio_resid = buflen; auio.uio_offset = off; - if (cookies) { - free(cookies, M_TEMP); - cookies = NULL; - } - #ifdef MAC /* * Do directory search MAC check using non-cached credentials. @@ -391,8 +385,7 @@ if ((error = mac_vnode_check_readdir(td->td_ucred, vp))) goto out; #endif /* MAC */ - if ((error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies, - &cookies))) + if ((error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag))) goto out; inp = buf; @@ -401,28 +394,7 @@ if ((len = buflen - auio.uio_resid) <= 0) goto eof; - cookiep = cookies; - - if (cookies) { - /* - * When using cookies, the vfs has the option of reading from - * a different offset than that supplied (UFS truncates the - * offset to a block boundary to make sure that it never reads - * partway through a directory entry, even if the directory - * has been compacted). - */ - while (len > 0 && ncookies > 0 && *cookiep <= off) { - bdp = (struct dirent *) inp; - len -= bdp->d_reclen; - inp += bdp->d_reclen; - cookiep++; - ncookies--; - } - } - while (len > 0) { - if (cookiep && ncookies == 0) - break; bdp = (struct dirent *) inp; reclen = bdp->d_reclen; if (reclen & 3) { @@ -432,12 +404,7 @@ if (bdp->d_fileno == 0) { inp += reclen; - if (cookiep) { - off = *cookiep++; - ncookies--; - } else - off += reclen; - + off = bdp->d_off; len -= reclen; continue; } @@ -464,9 +431,7 @@ if (is64bit) { linux_dirent64 = (struct l_dirent64*)lbuf; linux_dirent64->d_ino = bdp->d_fileno; - linux_dirent64->d_off = (cookiep) - ? (l_off_t)*cookiep - : (l_off_t)(off + reclen); + linux_dirent64->d_off = bdp->d_off; linux_dirent64->d_reclen = (l_ushort)linuxreclen; linux_dirent64->d_type = bdp->d_type; strlcpy(linux_dirent64->d_name, bdp->d_name, @@ -475,9 +440,7 @@ } else if (!justone) { linux_dirent = (struct l_dirent*)lbuf; linux_dirent->d_ino = bdp->d_fileno; - linux_dirent->d_off = (cookiep) - ? (l_off_t)*cookiep - : (l_off_t)(off + reclen); + linux_dirent->d_off = bdp->d_off; linux_dirent->d_reclen = (l_ushort)linuxreclen; /* * Copy d_type to last byte of l_dirent buffer @@ -492,12 +455,7 @@ goto out; inp += reclen; - if (cookiep) { - off = *cookiep++; - ncookies--; - } else - off += reclen; - + off = bdp->d_off; outp += linuxreclen; resid -= linuxreclen; len -= reclen; @@ -518,9 +476,6 @@ td->td_retval[0] = nbytes - resid; out: - if (cookies) - free(cookies, M_TEMP); - VOP_UNLOCK(vp, 0); VFS_UNLOCK_GIANT(vfslocked); fdrop(fp, td); Modified: soc2011/gk/ino64-head/sys/compat/linux/linux_getcwd.c ============================================================================== --- soc2011/gk/ino64-head/sys/compat/linux/linux_getcwd.c Sun Jul 3 13:27:23 2011 (r223907) +++ soc2011/gk/ino64-head/sys/compat/linux/linux_getcwd.c Sun Jul 3 14:06:46 2011 (r223908) @@ -211,8 +211,7 @@ error = mac_vnode_check_readdir(td->td_ucred, uvp); if (error == 0) #endif /* MAC */ - error = VOP_READDIR(uvp, &uio, td->td_ucred, &eofflag, - 0, 0); + error = VOP_READDIR(uvp, &uio, td->td_ucred, &eofflag); off = uio.uio_offset; Modified: soc2011/gk/ino64-head/sys/compat/svr4/svr4_misc.c ============================================================================== --- soc2011/gk/ino64-head/sys/compat/svr4/svr4_misc.c Sun Jul 3 13:27:23 2011 (r223907) +++ soc2011/gk/ino64-head/sys/compat/svr4/svr4_misc.c Sun Jul 3 14:06:46 2011 (r223908) @@ -241,8 +241,6 @@ off_t off; struct svr4_dirent64 svr4_dirent; int buflen, error, eofflag, nbytes, justone, vfslocked; - u_long *cookies = NULL, *cookiep; - int ncookies; DPRINTF(("svr4_sys_getdents64(%d, *, %d)\n", uap->fd, uap->nbytes)); @@ -288,19 +286,13 @@ auio.uio_resid = buflen; auio.uio_offset = off; - if (cookies) { - free(cookies, M_TEMP); - cookies = NULL; - } - #ifdef MAC error = mac_vnode_check_readdir(td->td_ucred, vp); if (error) goto out; #endif - error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, - &ncookies, &cookies); + error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag); if (error) { goto out; } @@ -312,28 +304,7 @@ goto eof; } - cookiep = cookies; - - if (cookies) { - /* - * When using cookies, the vfs has the option of reading from - * a different offset than that supplied (UFS truncates the - * offset to a block boundary to make sure that it never reads - * partway through a directory entry, even if the directory - * has been compacted). - */ - while (len > 0 && ncookies > 0 && *cookiep <= off) { - bdp = (struct dirent *) inp; - len -= bdp->d_reclen; - inp += bdp->d_reclen; - cookiep++; - ncookies--; - } - } - while (len > 0) { - if (cookiep && ncookies == 0) - break; bdp = (struct dirent *) inp; reclen = bdp->d_reclen; if (reclen & 3) { @@ -344,11 +315,7 @@ if (bdp->d_fileno == 0) { inp += reclen; - if (cookiep) { - off = *cookiep++; - ncookies--; - } else - off += reclen; + off = bdp->d_off; len -= reclen; continue; } @@ -365,18 +332,14 @@ svr4_dirent.d_off = (svr4_off_t) svr4reclen; svr4_dirent.d_reclen = (u_short) bdp->d_namlen; } else { - svr4_dirent.d_off = (svr4_off_t)(off + reclen); + svr4_dirent.d_off = (svr4_off_t) bdp->d_off; svr4_dirent.d_reclen = (u_short) svr4reclen; } strlcpy(svr4_dirent.d_name, bdp->d_name, sizeof(svr4_dirent.d_name)); if ((error = copyout((caddr_t)&svr4_dirent, outp, svr4reclen))) goto out; inp += reclen; - if (cookiep) { - off = *cookiep++; - ncookies--; - } else - off += reclen; + off = bdp->d_off; outp += svr4reclen; resid -= svr4reclen; len -= reclen; @@ -397,8 +360,6 @@ VOP_UNLOCK(vp, 0); VFS_UNLOCK_GIANT(vfslocked); fdrop(fp, td); - if (cookies) - free(cookies, M_TEMP); free(buf, M_TEMP); return error; } @@ -421,8 +382,7 @@ struct svr4_dirent idb; off_t off; /* true file offset */ int buflen, error, eofflag, vfslocked; - u_long *cookiebuf = NULL, *cookie; - int ncookies = 0, *retval = td->td_retval; + int *retval = td->td_retval; if (uap->nbytes < 0) return (EINVAL); @@ -468,8 +428,7 @@ * First we read into the malloc'ed buffer, then * we massage it into user space, one record at a time. */ - error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies, - &cookiebuf); + error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag); if (error) { goto out; } @@ -480,22 +439,19 @@ if ((len = buflen - auio.uio_resid) == 0) goto eof; - for (cookie = cookiebuf; len > 0; len -= reclen) { + for (; len > 0; len -= reclen) { bdp = (struct dirent *)inp; reclen = bdp->d_reclen; if (reclen & 3) panic("svr4_sys_getdents64: bad reclen"); - if (cookie) - off = *cookie++; /* each entry points to the next */ - else - off += reclen; - if ((off >> 32) != 0) { + if ((bdp->d_off >> 32) != 0) { uprintf("svr4_sys_getdents64: dir offset too large for emulated program"); error = EINVAL; goto out; } if (bdp->d_fileno == 0) { inp += reclen; /* it is a hole; squish it out */ + off = bdp->d_off; continue; } svr4_reclen = SVR4_RECLEN(&idb, bdp->d_namlen); @@ -510,13 +466,14 @@ * the copyout() call). */ idb.d_ino = (svr4_ino_t)bdp->d_fileno; - idb.d_off = (svr4_off_t)off; + idb.d_off = (svr4_off_t)bdp->d_off; idb.d_reclen = (u_short)svr4_reclen; strlcpy(idb.d_name, bdp->d_name, sizeof(idb.d_name)); if ((error = copyout((caddr_t)&idb, outp, svr4_reclen))) goto out; /* advance past this real entry */ inp += reclen; + off = dbp->d_off; /* advance output past SVR4-shaped entry */ outp += svr4_reclen; resid -= svr4_reclen; @@ -533,8 +490,6 @@ VOP_UNLOCK(vp, 0); VFS_UNLOCK_GIANT(vfslocked); fdrop(fp, td); - if (cookiebuf) - free(cookiebuf, M_TEMP); free(buf, M_TEMP); return error; } Modified: soc2011/gk/ino64-head/sys/fs/cd9660/cd9660_vnops.c ============================================================================== --- soc2011/gk/ino64-head/sys/fs/cd9660/cd9660_vnops.c Sun Jul 3 13:27:23 2011 (r223907) +++ soc2011/gk/ino64-head/sys/fs/cd9660/cd9660_vnops.c Sun Jul 3 14:06:46 2011 (r223908) @@ -368,8 +368,6 @@ struct uio *uio; off_t uio_off; int eofflag; - u_long *cookies; - int ncookies; }; static int @@ -382,22 +380,13 @@ dp->d_name[dp->d_namlen] = 0; dp->d_reclen = GENERIC_DIRSIZ(dp); + dp->d_off = off; if (idp->uio->uio_resid < dp->d_reclen) { idp->eofflag = 0; return (-1); } - if (idp->cookies) { - if (idp->ncookies <= 0) { - idp->eofflag = 0; - return (-1); - } - - *idp->cookies++ = off; - --idp->ncookies; - } - if ((error = uiomove(dp, dp->d_reclen, idp->uio)) != 0) return (error); idp->uio_off = off; @@ -464,8 +453,6 @@ struct uio *a_uio; struct ucred *a_cred; int *a_eofflag; - int *a_ncookies; - u_long **a_cookies; } */ *ap; { struct uio *uio = ap->a_uio; @@ -482,8 +469,6 @@ int error = 0; int reclen; u_short namelen; - int ncookies = 0; - u_long *cookies = NULL; dp = VTOI(vdp); imp = dp->i_mnt; @@ -498,18 +483,6 @@ idp->saveent.d_type = idp->assocent.d_type = idp->current.d_type = DT_UNKNOWN; idp->uio = uio; - if (ap->a_ncookies == NULL) { - idp->cookies = NULL; - } else { - /* - * Guess the number of cookies needed. - */ - ncookies = uio->uio_resid / 16; - cookies = malloc(ncookies * sizeof(u_long), - M_TEMP, M_WAITOK); - idp->cookies = cookies; - idp->ncookies = ncookies; - } idp->eofflag = 1; idp->curroff = uio->uio_offset; idp->uio_off = uio->uio_offset; @@ -622,23 +595,12 @@ if (error < 0) error = 0; - if (ap->a_ncookies != NULL) { - if (error) - free(cookies, M_TEMP); - else { - /* - * Work out the number of cookies actually used. - */ - *ap->a_ncookies = ncookies - idp->ncookies; - *ap->a_cookies = cookies; - } - } - if (bp) brelse (bp); uio->uio_offset = idp->uio_off; - *ap->a_eofflag = idp->eofflag; + if (ap->a_eofflag != NULL) + *ap->a_eofflag = idp->eofflag; free(idp, M_TEMP); Modified: soc2011/gk/ino64-head/sys/fs/coda/coda_vnops.c ============================================================================== --- soc2011/gk/ino64-head/sys/fs/coda/coda_vnops.c Sun Jul 3 13:27:23 2011 (r223907) +++ soc2011/gk/ino64-head/sys/fs/coda/coda_vnops.c Sun Jul 3 14:06:46 2011 (r223908) @@ -1462,8 +1462,6 @@ struct uio *uiop = ap->a_uio; struct ucred *cred = ap->a_cred; int *eofflag = ap->a_eofflag; - u_long **cookies = ap->a_cookies; - int *ncookies = ap->a_ncookies; struct thread *td = ap->a_uio->uio_td; /* upcall decl */ /* locals */ @@ -1508,8 +1506,7 @@ CODADEBUG(CODA_READDIR, myprintf(("indirect readdir: fid = %s, " "refcnt = %d\n", coda_f2s(&cp->c_fid), vp->v_usecount));); vn_lock(cp->c_ovp, LK_SHARED | LK_RETRY); - error = VOP_READDIR(cp->c_ovp, uiop, cred, eofflag, ncookies, - cookies); + error = VOP_READDIR(cp->c_ovp, uiop, cred, eofflag); VOP_UNLOCK(cp->c_ovp, 0); if (error) MARK_INT_FAIL(CODA_READDIR_STATS); Modified: soc2011/gk/ino64-head/sys/fs/devfs/devfs_vnops.c ============================================================================== --- soc2011/gk/ino64-head/sys/fs/devfs/devfs_vnops.c Sun Jul 3 13:27:23 2011 (r223907) +++ soc2011/gk/ino64-head/sys/fs/devfs/devfs_vnops.c Sun Jul 3 14:06:46 2011 (r223908) @@ -1171,7 +1171,6 @@ struct devfs_dirent *de; struct devfs_mount *dmp; off_t off; - int *tmp_ncookies = NULL; if (ap->a_vp->v_type != VDIR) return (ENOTDIR); @@ -1180,27 +1179,9 @@ if (uio->uio_offset < 0) return (EINVAL); - /* - * XXX: This is a temporary hack to get around this filesystem not - * supporting cookies. We store the location of the ncookies pointer - * in a temporary variable before calling vfs_subr.c:vfs_read_dirent() - * and set the number of cookies to 0. We then set the pointer to - * NULL so that vfs_read_dirent doesn't try to call realloc() on - * ap->a_cookies. Later in this function, we restore the ap->a_ncookies - * pointer to its original location before returning to the caller. - */ - if (ap->a_ncookies != NULL) { - tmp_ncookies = ap->a_ncookies; - *ap->a_ncookies = 0; - ap->a_ncookies = NULL; - } - dmp = VFSTODEVFS(ap->a_vp->v_mount); - if (devfs_populate_vp(ap->a_vp) != 0) { - if (tmp_ncookies != NULL) - ap->a_ncookies = tmp_ncookies; + if (devfs_populate_vp(ap->a_vp) != 0) return (EIO); - } error = 0; de = ap->a_vp->v_data; off = 0; @@ -1215,26 +1196,21 @@ else de = dd; dp = dd->de_dirent; - if (dp->d_reclen > uio->uio_resid) - break; dp->d_fileno = de->de_inode; + dp->d_off = off + dp->d_reclen; if (off >= uio->uio_offset) { - error = vfs_read_dirent(ap, dp, off); - if (error) + error = vfs_read_dirent(ap, dp); + if (error != 0) { + if (error < 0) + error = 0; break; + } } off += dp->d_reclen; } sx_xunlock(&dmp->dm_lock); uio->uio_offset = off; - /* - * Restore ap->a_ncookies if it wasn't originally NULL in the first - * place. - */ - if (tmp_ncookies != NULL) - ap->a_ncookies = tmp_ncookies; - return (error); } @@ -1429,7 +1405,7 @@ if (ap->a_vp->v_type != VDIR) return (EINVAL); - return (VOP_READDIR(ap->a_vp, ap->a_uio, ap->a_cred, NULL, NULL, NULL)); + return (VOP_READDIR(ap->a_vp, ap->a_uio, ap->a_cred, NULL)); } static int Modified: soc2011/gk/ino64-head/sys/fs/ext2fs/ext2_lookup.c ============================================================================== --- soc2011/gk/ino64-head/sys/fs/ext2fs/ext2_lookup.c Sun Jul 3 13:27:23 2011 (r223907) +++ soc2011/gk/ino64-head/sys/fs/ext2fs/ext2_lookup.c Sun Jul 3 14:06:46 2011 (r223908) @@ -140,7 +140,6 @@ int count, error; struct ext2fs_direct_2 *edp, *dp; - int ncookies; struct dirent dstdp; struct uio auio; struct iovec aiov; @@ -148,6 +147,7 @@ int DIRBLKSIZ = VTOI(ap->a_vp)->i_e2fs->e2fs_bsize; int readcnt; off_t startoffset = uio->uio_offset; + off_t offset; count = uio->uio_resid; /* @@ -161,6 +161,8 @@ count -= (uio->uio_offset + count) & (DIRBLKSIZ -1); if (count <= 0) count += DIRBLKSIZ; + else if (count > MAXBSIZE) + count = MAXBSIZE; auio = *uio; auio.uio_iov = &aiov; auio.uio_iovcnt = 1; @@ -172,8 +174,8 @@ error = VOP_READ(ap->a_vp, &auio, 0, ap->a_cred); if (error == 0) { readcnt = count - auio.uio_resid; + offset = startoffset; edp = (struct ext2fs_direct_2 *)&dirbuf[readcnt]; - ncookies = 0; bzero(&dstdp, offsetof(struct dirent, d_name)); for (dp = (struct ext2fs_direct_2 *)dirbuf; !error && uio->uio_resid > 0 && dp < edp; ) { @@ -197,22 +199,23 @@ dstdp.d_type = FTTODT(dp->e2d_type); dstdp.d_namlen = dp->e2d_namlen; dstdp.d_reclen = GENERIC_DIRSIZ(&dstdp); + dstdp.d_off = offset + dp->e2d_reclen; bcopy(dp->e2d_name, dstdp.d_name, dstdp.d_namlen); bzero(dstdp.d_name + dstdp.d_namlen, dstdp.d_reclen - offsetof(struct dirent, d_name) - dstdp.d_namlen); if (dp->e2d_reclen > 0) { - if(dstdp.d_reclen <= uio->uio_resid) { - /* advance dp */ - dp = (struct ext2fs_direct_2 *) - ((char *)dp + dp->e2d_reclen); - error = - uiomove(&dstdp, dstdp.d_reclen, uio); - if (!error) - ncookies++; - } else + error = vfs_read_dirent(ap, &dstdp); + if (error != 0) { + if (error < 0) + error = 0; break; + } + /* advance dp */ + offset += dp->e2d_reclen; + dp = (struct ext2fs_direct_2 *) + ((char *)dp + dp->e2d_reclen); } else { error = EIO; break; @@ -220,26 +223,7 @@ } /* we need to correct uio_offset */ uio->uio_offset = startoffset + (caddr_t)dp - dirbuf; - - if (!error && ap->a_ncookies != NULL) { - u_long *cookiep, *cookies, *ecookies; - off_t off; - - if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1) - panic("ext2_readdir: unexpected uio from NFS server"); - cookies = malloc(ncookies * sizeof(u_long), M_TEMP, - M_WAITOK); - off = startoffset; - for (dp = (struct ext2fs_direct_2 *)dirbuf, - cookiep = cookies, ecookies = cookies + ncookies; - cookiep < ecookies; - dp = (struct ext2fs_direct_2 *)((caddr_t) dp + dp->e2d_reclen)) { - off += dp->e2d_reclen; - *cookiep++ = (u_long) off; - } - *ap->a_ncookies = ncookies; - *ap->a_cookies = cookies; - } + MPASS(offset == uio->uio_offset); } free(dirbuf, M_TEMP); if (ap->a_eofflag) Modified: soc2011/gk/ino64-head/sys/fs/fdescfs/fdesc_vnops.c ============================================================================== --- soc2011/gk/ino64-head/sys/fs/fdescfs/fdesc_vnops.c Sun Jul 3 13:27:23 2011 (r223907) +++ soc2011/gk/ino64-head/sys/fs/fdescfs/fdesc_vnops.c Sun Jul 3 14:06:46 2011 (r223908) @@ -490,8 +490,6 @@ struct uio *a_uio; struct ucred *a_cred; int *a_eofflag; - u_long *a_cookies; - int a_ncookies; } */ *ap; { struct uio *uio = ap->a_uio; @@ -503,9 +501,6 @@ if (VTOFDESC(ap->a_vp)->fd_type != Froot) panic("fdesc_readdir: not dir"); - if (ap->a_ncookies != NULL) - *ap->a_ncookies = 0; - off = (int)uio->uio_offset; if (off != uio->uio_offset || off < 0 || (u_int)off % UIO_MX != 0 || uio->uio_resid < UIO_MX) @@ -528,6 +523,7 @@ bcopy("..", dp->d_name, dp->d_namlen); dp->d_name[i + 1] = '\0'; dp->d_type = DT_DIR; + dp->d_off = (i + 1) * UIO_MX; break; default: if (fdp->fd_ofiles[fcnt] == NULL) @@ -536,6 +532,7 @@ dp->d_reclen = UIO_MX; dp->d_type = DT_UNKNOWN; dp->d_fileno = i + FD_DESC; + dp->d_off = (i + 1) * UIO_MX; break; } if (dp->d_namlen != 0) { Modified: soc2011/gk/ino64-head/sys/fs/hpfs/hpfs_vnops.c ============================================================================== --- soc2011/gk/ino64-head/sys/fs/hpfs/hpfs_vnops.c Sun Jul 3 13:27:23 2011 (r223907) +++ soc2011/gk/ino64-head/sys/fs/hpfs/hpfs_vnops.c Sun Jul 3 14:06:46 2011 (r223908) @@ -58,7 +58,7 @@ #include static int hpfs_de_uiomove(struct hpfsmount *, struct hpfsdirent *, - struct uio *); + int num, struct uio *); static vop_ioctl_t hpfs_ioctl; static vop_read_t hpfs_read; static vop_write_t hpfs_write; @@ -769,6 +769,7 @@ hpfs_de_uiomove ( struct hpfsmount *hpmp, struct hpfsdirent *dep, + int num, struct uio *uio) { struct dirent cde; @@ -787,6 +788,7 @@ cde.d_fileno = dep->de_fnode; cde.d_type = (dep->de_flag & DE_DIR) ? DT_DIR : DT_REG; cde.d_reclen = sizeof(struct dirent); + cde.d_off = (num + 1) * sizeof(struct dirent); error = uiomove((char *)&cde, sizeof(struct dirent), uio); if (error) @@ -799,6 +801,7 @@ static struct dirent hpfs_de_dot = { .d_fileno = 0, + .d_off = sizeof(struct dirent), .d_reclen = sizeof(struct dirent), .d_type = DT_DIR, .d_namlen = 1, @@ -806,6 +809,7 @@ }; static struct dirent hpfs_de_dotdot = { .d_fileno = 0, + .d_off = sizeof(struct dirent) * 2, .d_reclen = sizeof(struct dirent), .d_type = DT_DIR, .d_namlen = 2, @@ -817,15 +821,14 @@ struct vnode *a_vp; struct uio *a_uio; struct ucred *a_cred; - int *a_ncookies; *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-soc-all@FreeBSD.ORG Sun Jul 3 14:07:06 2011 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id B47BF1065687 for ; Sun, 3 Jul 2011 14:07:04 +0000 (UTC) (envelope-from gk@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Sun, 03 Jul 2011 14:07:04 +0000 Date: Sun, 03 Jul 2011 14:07:04 +0000 From: gk@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20110703140704.B47BF1065687@hub.freebsd.org> Cc: Subject: socsvn commit: r223909 - in soc2011/gk/ino64-head/sys/fs: cd9660 devfs ext2fs udf X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Jul 2011 14:07:06 -0000 Author: gk Date: Sun Jul 3 14:07:04 2011 New Revision: 223909 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=223909 Log: In VOP_READDIR return EINVAL if buffer is too small for first entry Modified: soc2011/gk/ino64-head/sys/fs/cd9660/cd9660_vnops.c soc2011/gk/ino64-head/sys/fs/devfs/devfs_vnops.c soc2011/gk/ino64-head/sys/fs/ext2fs/ext2_lookup.c soc2011/gk/ino64-head/sys/fs/udf/udf_vnops.c Modified: soc2011/gk/ino64-head/sys/fs/cd9660/cd9660_vnops.c ============================================================================== --- soc2011/gk/ino64-head/sys/fs/cd9660/cd9660_vnops.c Sun Jul 3 14:06:46 2011 (r223908) +++ soc2011/gk/ino64-head/sys/fs/cd9660/cd9660_vnops.c Sun Jul 3 14:07:04 2011 (r223909) @@ -367,6 +367,7 @@ off_t curroff; struct uio *uio; off_t uio_off; + ssize_t startresid; int eofflag; }; @@ -384,6 +385,8 @@ if (idp->uio->uio_resid < dp->d_reclen) { idp->eofflag = 0; + if (idp->uio->uio_resid == idp->startresid) + return (EINVAL); return (-1); } @@ -486,6 +489,7 @@ idp->eofflag = 1; idp->curroff = uio->uio_offset; idp->uio_off = uio->uio_offset; + idp->startresid = uio->uio_resid; if ((entryoffsetinblock = idp->curroff & bmask) && (error = cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp))) { Modified: soc2011/gk/ino64-head/sys/fs/devfs/devfs_vnops.c ============================================================================== --- soc2011/gk/ino64-head/sys/fs/devfs/devfs_vnops.c Sun Jul 3 14:06:46 2011 (r223908) +++ soc2011/gk/ino64-head/sys/fs/devfs/devfs_vnops.c Sun Jul 3 14:07:04 2011 (r223909) @@ -1171,6 +1171,7 @@ struct devfs_dirent *de; struct devfs_mount *dmp; off_t off; + ssize_t startresid; if (ap->a_vp->v_type != VDIR) return (ENOTDIR); @@ -1185,6 +1186,7 @@ error = 0; de = ap->a_vp->v_data; off = 0; + startresid = uio->uio_resid; TAILQ_FOREACH(dd, &de->de_dlist, de_list) { KASSERT(dd->de_cdp != (void *)0xdeadc0de, ("%s %d\n", __func__, __LINE__)); if (dd->de_flags & (DE_COVERED | DE_WHITEOUT)) @@ -1201,8 +1203,12 @@ if (off >= uio->uio_offset) { error = vfs_read_dirent(ap, dp); if (error != 0) { - if (error < 0) - error = 0; + if (error < 0) { + if (uio->uio_resid == startresid) + error = EINVAL; + else + error = 0; + } break; } } Modified: soc2011/gk/ino64-head/sys/fs/ext2fs/ext2_lookup.c ============================================================================== --- soc2011/gk/ino64-head/sys/fs/ext2fs/ext2_lookup.c Sun Jul 3 14:06:46 2011 (r223908) +++ soc2011/gk/ino64-head/sys/fs/ext2fs/ext2_lookup.c Sun Jul 3 14:07:04 2011 (r223909) @@ -201,15 +201,17 @@ dstdp.d_reclen = GENERIC_DIRSIZ(&dstdp); dstdp.d_off = offset + dp->e2d_reclen; bcopy(dp->e2d_name, dstdp.d_name, dstdp.d_namlen); - bzero(dstdp.d_name + dstdp.d_namlen, - dstdp.d_reclen - offsetof(struct dirent, d_name) - - dstdp.d_namlen); + dstdp.d_name[dstdp.d_namlen] = '\0'; if (dp->e2d_reclen > 0) { error = vfs_read_dirent(ap, &dstdp); if (error != 0) { - if (error < 0) - error = 0; + if (error < 0) { + if (offset == startoffset) + error = EINVAL; + else + error = 0; + } break; } /* advance dp */ Modified: soc2011/gk/ino64-head/sys/fs/udf/udf_vnops.c ============================================================================== --- soc2011/gk/ino64-head/sys/fs/udf/udf_vnops.c Sun Jul 3 14:06:46 2011 (r223908) +++ soc2011/gk/ino64-head/sys/fs/udf/udf_vnops.c Sun Jul 3 14:07:04 2011 (r223909) @@ -744,6 +744,7 @@ struct udf_mnt *udfmp; struct fileid_desc *fid; struct udf_dirstream *ds; + ssize_t startresid; int error = 0; int dotoff = 0; @@ -755,6 +756,7 @@ if (a->a_eofflag != NULL) *a->a_eofflag = 1; /* reset by vfs_read_dirent */ + startresid = uio->uio_resid; if (uio->uio_offset == 1 || uio->uio_offset == 2) { dotoff = uio->uio_offset; uio->uio_offset = 0; @@ -826,8 +828,12 @@ uio->uio_offset = dir.d_off; } - if (error < 0) - error = 0; + if (error < 0) { + if (uio->uio_resid == startresid) + error = EINVAL; + else + error = 0; + } if (!error) error = ds->error; From owner-svn-soc-all@FreeBSD.ORG Sun Jul 3 14:07:18 2011 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id EF4061065687 for ; Sun, 3 Jul 2011 14:07:15 +0000 (UTC) (envelope-from gk@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Sun, 03 Jul 2011 14:07:15 +0000 Date: Sun, 03 Jul 2011 14:07:15 +0000 From: gk@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20110703140715.EF4061065687@hub.freebsd.org> Cc: Subject: socsvn commit: r223910 - soc2011/gk/ino64-head/tools/regression/readdir-lint X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Jul 2011 14:07:18 -0000 Author: gk Date: Sun Jul 3 14:07:15 2011 New Revision: 223910 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=223910 Log: Add readdir-lint tool -- test VOP_READDIR implementation Added: soc2011/gk/ino64-head/tools/regression/readdir-lint/ soc2011/gk/ino64-head/tools/regression/readdir-lint/Makefile (contents, props changed) soc2011/gk/ino64-head/tools/regression/readdir-lint/readdir-lint.c (contents, props changed) Added: soc2011/gk/ino64-head/tools/regression/readdir-lint/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/gk/ino64-head/tools/regression/readdir-lint/Makefile Sun Jul 3 14:07:15 2011 (r223910) @@ -0,0 +1,9 @@ +# $FreeBSD$ + +WARNS?= 6 + +PROG= readdir-lint +NO_MAN= +DEBUG_FLAGS= -O0 -g -I${.CURDIR}/../../../sys + +.include Added: soc2011/gk/ino64-head/tools/regression/readdir-lint/readdir-lint.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/gk/ino64-head/tools/regression/readdir-lint/readdir-lint.c Sun Jul 3 14:07:15 2011 (r223910) @@ -0,0 +1,369 @@ +/*- + * Copyright (c) 2011 Gleb Kurtsou + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef __FreeBSD__ +#define HAVE_DIRENT_NAMLEN +#define HAVE_GETPROGNAME +#endif + +#define DIRSIZE_MAX (4*1024*1024) +#define DIRSIZE_ENTRY (sizeof(struct dirent)) +#define DIRSIZE_MIN ((sizeof (struct dirent) - (MAXNAMLEN+1)) + 4) +#define DIRSIZE_BLOCK 512 +#define DIRSIZE_PAGE 4096 + +#define DIRENT_MAX 512 + +#define DP_NEXT(a) ((struct dirent *)(((char *)(a)) + a->d_reclen)) + +#define WARNX(var, fmt, ...) \ + do { \ + if ((var) == 0) { \ + printf(fmt "\n", ## __VA_ARGS__ ); \ + var = 1; \ + } \ + } while (0) + +static int opt_verbose; +static int opt_skip; +static char *opt_path; + +#ifdef HAVE_DIRENT_NAMLEN +static int warn_nameterm; +#endif +static int warn_noerr; +static int warn_seekoff; +static int warn_zeroino; +static int warn_zerooff; +static int warn_reclen; + +struct dirbuf { + struct dirent *dp, *begin, *end; + long base; + int fd; + int eof; + size_t bufsize; +}; + +static void +dir_init(struct dirbuf *dir, const char *path, int bufsize) +{ + dir->fd = open(path, O_RDONLY); + if (dir->fd == -1) + err(1, "open %s", path); + + dir->begin = malloc(bufsize); + if (dir->begin == NULL) + err(1, "malloc failed"); + dir->dp = NULL; + dir->end = NULL; + dir->base = 0; + dir->eof = 0; + dir->bufsize = bufsize; +} + +static void +dir_destroy(struct dirbuf *dir) +{ + free(dir->begin); +} + +static off_t +dir_offset(struct dirbuf *dir) +{ + return lseek(dir->fd, 0, SEEK_CUR); +} + +static int +dir_readx(struct dirbuf *dir) +{ + struct dirent *di; + off_t seekoff; + int rv; + + rv = getdirentries(dir->fd, (char *)dir->begin, dir->bufsize, &dir->base); + if (opt_verbose >= 3) + printf("dir_read %d: len=%d base=%ld\n", dir->fd, rv, dir->base); + if (rv == -1) + return (rv); + if (rv == 0) { + dir->eof = 1; + dir->dp = NULL; + dir->end = NULL; + } else { + dir->dp = dir->begin; + dir->end = (struct dirent *)((char *)dir->begin + rv); + seekoff = dir_offset(dir); + for (di = dir->dp; di < dir->end; di = DP_NEXT(di)) { + if (di->d_reclen <= 0 || + di->d_reclen > (char *)dir->end - (char *)di) { + WARNX(warn_reclen, "Invalid entry size: %d", di->d_reclen); + dir->end = di; + break; + } +#ifdef HAVE_DIRENT_NAMLEN + if (di->d_namlen > MAXNAMLEN) + errx(1, "Ivalid name lenghth: %d", di->d_namlen); + if (di->d_name[di->d_namlen] != '\0') { + di->d_name[di->d_namlen] = '\0'; + WARNX(warn_nameterm, "Entry names are not NUL-terminated"); + } +#else +#endif + if (di->d_fileno == 0) { + WARNX(warn_zeroino, "Zero d_fileno: %08jx %s", + (uintmax_t)di->d_off, di->d_name); + } + if (di->d_off == 0) + WARNX(warn_zerooff, "Zero d_off: %ju %s", + (uintmax_t)di->d_fileno, di->d_name); + if (DP_NEXT(di) >= dir->end && di->d_off != seekoff) { + WARNX(warn_seekoff, "Directory(%zd) and last entry offsets mismatch: %ju -- %ju", + dir->bufsize, (uintmax_t)seekoff, (uintmax_t)di->d_off); + } + } + } + + return (rv); +} + +static int +dir_read(struct dirbuf *dir) +{ + int rv; + + rv = dir_readx(dir); + if (rv == -1) + err(1, "Directory read"); + return (rv); +} + + +static struct dirent * +dir_next(struct dirbuf *dir) +{ + if (dir->eof) + return NULL; + + if (dir->dp == NULL || DP_NEXT(dir->dp) >= dir->end) { + dir_read(dir); + if (dir->eof) + return NULL; + } else { + dir->dp = DP_NEXT(dir->dp); + } + + return dir->dp; +} + +static void +dir_seek(struct dirbuf *dir, off_t off) +{ + int rv; + + rv = lseek(dir->fd, off, SEEK_SET); + if (rv == -1) + err(3, "seek(%jd, SEEK_SET)", (uintmax_t)off); + dir->dp = NULL; + dir->end = NULL; + dir->base = 0; + dir->eof = 0; +} + +static int +dir_cmpent(struct dirbuf *dir1, struct dirbuf *dir2) +{ + struct dirent *dp1, *dp2; + + dp1 = dir1->dp; + dp2 = dir2->dp; + + if (dir1->eof != dir2->eof) + errx(3, "Invalid EOF: %d %ld -- %d %ld", + dir1->eof, dir1->base, dir2->eof, dir2->base); + else if (dir1->eof) + return (1); + if (opt_verbose >= 2) + printf(" %08jx (%d bytes) %-12s -- %08jx (%d bytes) %-12s\n", + (uintmax_t)dp1->d_off, dp1->d_reclen, dp1->d_name, + (uintmax_t)dp2->d_off, dp2->d_reclen, dp2->d_name); + if (strcmp(dp1->d_name, dp2->d_name) != 0 || + dp1->d_off != dp2->d_off) + printf("Entries mismatch: %08jx (%d bytes) %-12s -- %08jx (%d bytes) %-12s\n", + (uintmax_t)dp1->d_off, dp1->d_reclen, dp1->d_name, + (uintmax_t)dp2->d_off, dp2->d_reclen, dp2->d_name); + + return (0); +} + +static void +dir_lint(struct dirbuf *dir1, struct dirbuf *dir2) +{ + dir_read(dir1); + dir_read(dir2); + + while (dir_cmpent(dir1, dir2) == 0) { + dir_next(dir1); + dir_next(dir2); + } +} + +#ifndef HAVE_GETPROGNAME +#define getprogname() "readdir-lint" +#endif + +static void +test_bufsize(struct dirbuf *dir_expect, struct dirbuf *dir) +{ + int tests_bufsize[] = { DIRSIZE_PAGE, DIRSIZE_BLOCK, DIRSIZE_ENTRY, 0 }; + int *ip; + + for (ip = tests_bufsize; *ip != 0; ip++) { + if (opt_skip > 0) { + opt_skip--; + continue; + } + printf("Test buffer sizes: %d -- %d\n", DIRSIZE_MAX, *ip); + dir_init(dir, opt_path, *ip); + dir_seek(dir_expect, 0); + dir_lint(dir_expect, dir); + dir_destroy(dir); + } +} + +static void +test_minbufsize(struct dirbuf *dir_expect, struct dirbuf *dir) +{ + int len; + + if (opt_skip > 0) { + opt_skip--; + return; + } + + printf("Test minimal buffer size\n"); + dir_init(dir, opt_path, DIRSIZE_ENTRY); + dir_seek(dir_expect, 0); + dir_read(dir_expect); + while(!dir_expect->eof) { + off_t prevoff = dir_offset(dir); + + for (dir->bufsize = DIRSIZE_MIN; dir->bufsize <= DIRSIZE_ENTRY; + dir->bufsize += 4) { + len = dir_readx(dir); + if (len <= 0) { + if (prevoff != dir_offset(dir)) + errx(2, "Directory offset changed but no data read: %jd %jd", + (uintmax_t)prevoff, (uintmax_t)dir_offset(dir)); + if (len == 0) { + WARNX(warn_noerr, "EINVAL expected for small buffer read, 0 byte result"); + continue; + } + if (errno == EINVAL) + continue; + err(1, "Directory read"); + } + if (opt_verbose >= 1) + printf(" min size %08jx (%d of %zd bytes) %s\n", + (uintmax_t)dir->dp->d_off, dir->dp->d_reclen, dir->bufsize, + dir->dp->d_name); + break; + } + if (dir->bufsize > DIRSIZE_ENTRY) { + errx(2, "Couldn't read entry at offset %jd", + (uintmax_t)dir_offset(dir)); + } + dir->eof = 0; + if (dir_cmpent(dir_expect, dir) != 0) + break; + dir_next(dir_expect); + dir_seek(dir, dir->dp->d_off); + } + dir_destroy(dir); +} + +static void +usage(int exitcode) +{ + fprintf(stderr, "usage: %s directory\n", getprogname()); + exit(exitcode); +} + +int +main(int argc, char **argv) +{ + struct dirbuf dir_max; + struct dirbuf dir_i; + int len, opt; + long prevbase; + + while ((opt = getopt(argc, argv, "hs:v")) != -1) { + switch (opt) { + case 's': + opt_skip = atoi(optarg); + break; + case 'v': + opt_verbose++; + break; + case 'h': + usage(0); + break; + case '?': + default: + usage(-1); + break; + } + } + argc -= optind; + argv += optind; + + if (argc == 0) + usage(1); + opt_path = argv[0]; + + dir_init(&dir_max, opt_path, DIRSIZE_MAX); + dir_read(&dir_max); + prevbase = dir_max.base; + len = dir_read(&dir_max); + if (!dir_max.eof || len != 0) + errx(1, "Directory is too large"); + + test_bufsize(&dir_max, &dir_i); + test_minbufsize(&dir_max, &dir_i); + + return (0); +} From owner-svn-soc-all@FreeBSD.ORG Tue Jul 5 14:48:39 2011 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 630DE106567A for ; Tue, 5 Jul 2011 14:48:37 +0000 (UTC) (envelope-from xxp@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Tue, 05 Jul 2011 14:48:37 +0000 Date: Tue, 05 Jul 2011 14:48:37 +0000 From: xxp@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20110705144837.630DE106567A@hub.freebsd.org> Cc: Subject: socsvn commit: r223960 - in soc2011/xxp/xxp-head/libexec/rtld-elf: amd64 i386 X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Jul 2011 14:48:39 -0000 Author: xxp Date: Tue Jul 5 14:48:37 2011 New Revision: 223960 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=223960 Log: Annotate rtld-elf. Modified: soc2011/xxp/xxp-head/libexec/rtld-elf/amd64/rtld_start.S soc2011/xxp/xxp-head/libexec/rtld-elf/i386/rtld_start.S Modified: soc2011/xxp/xxp-head/libexec/rtld-elf/amd64/rtld_start.S ============================================================================== --- soc2011/xxp/xxp-head/libexec/rtld-elf/amd64/rtld_start.S Tue Jul 5 13:45:10 2011 (r223959) +++ soc2011/xxp/xxp-head/libexec/rtld-elf/amd64/rtld_start.S Tue Jul 5 14:48:37 2011 (r223960) @@ -31,13 +31,16 @@ .type .rtld_start,@function .rtld_start: xorq %rbp,%rbp # Clear frame pointer for good form + cfi_def_cfa(%rsp,0) subq $24,%rsp # A place to store exit procedure addr + cfi_adjust_cfa_offset(24) movq %rdi,%r12 movq %rsp,%rsi # save address of exit proc movq %rsp,%rdx # construct address of obj_main addq $8,%rdx call _rtld@PLT # Call rtld(sp); returns entry point popq %rsi # Get exit procedure address + cfi_adjust_cfa_offset(-8) movq %r12,%rdi # *ap /* * At this point, %rax contains the entry point of the main program, and @@ -80,16 +83,27 @@ .type _rtld_bind_start,@function _rtld_bind_start: subq $8,%rsp + cfi_adjust_cfa_offset(8) pushfq # Save rflags + cfi_adjust_cfa_offset(8) pushq %rax # Save %rax + cfi_adjust_cfa_offset(8) pushq %rdx # Save %rdx + cfi_adjust_cfa_offset(8) pushq %rcx # Save %rcx + cfi_adjust_cfa_offset(8) pushq %rsi # Save %rsi + cfi_adjust_cfa_offset(8) pushq %rdi # Save %rdi + cfi_adjust_cfa_offset(8) pushq %r8 # Save %r8 + cfi_adjust_cfa_offset(8) pushq %r9 # Save %r9 + cfi_adjust_cfa_offset(8) pushq %r10 # Save %r10 + cfi_adjust_cfa_offset(8) pushq %r11 # Save %r11 + cfi_adjust_cfa_offset(8) movq 0x58(%rsp),%rdi # Fetch obj argument movq 0x60(%rsp),%rsi # Fetch reloff argument @@ -101,15 +115,25 @@ movq %rax,0x60(%rsp) # Store target over reloff argument popq %r11 # Restore %r11 + cfi_adjust_cfa_offset(-8) popq %r10 # Restore %r10 + cfi_adjust_cfa_offset(-8) popq %r9 # Restore %r9 + cfi_adjust_cfa_offset(-8) popq %r8 # Restore %r8 + cfi_adjust_cfa_offset(-8) popq %rdi # Restore %rdi + cfi_adjust_cfa_offset(-8) popq %rsi # Restore %rsi + cfi_adjust_cfa_offset(-8) popq %rcx # Restore %rcx + cfi_adjust_cfa_offset(-8) popq %rdx # Restore %rdx + cfi_adjust_cfa_offset(-8) popq %rax # Restore %rax + cfi_adjust_cfa_offset(-8) popfq # Restore rflags + cfi_adjust_cfa_offset(-8) leaq 16(%rsp),%rsp # Discard spare, obj, do not change rflags ret # "Return" to target address Modified: soc2011/xxp/xxp-head/libexec/rtld-elf/i386/rtld_start.S ============================================================================== --- soc2011/xxp/xxp-head/libexec/rtld-elf/i386/rtld_start.S Tue Jul 5 13:45:10 2011 (r223959) +++ soc2011/xxp/xxp-head/libexec/rtld-elf/i386/rtld_start.S Tue Jul 5 14:48:37 2011 (r223960) @@ -34,18 +34,27 @@ movl %esp,%eax # Save initial stack pointer movl %esp,%esi # Save initial stack pointer andl $0xfffffff0,%esp # Align stack pointer + cfi_def_cfa(%esp,0) subl $16,%esp # A place to store exit procedure addr + cfi_adjust_cfa_offset(16) movl %esp,%ebx # save address of exit proc movl %esp,%ecx # construct address of obj_main addl $4,%ecx subl $4,%esp # Keep stack aligned + cfi_adjust_cfa_offset(4) pushl %ecx # Pass address of obj_main + cfi_adjust_cfa_offset(4) pushl %ebx # Pass address of exit proc + cfi_adjust_cfa_offset(4) pushl %eax # Pass initial stack pointer to rtld + cfi_adjust_cfa_offset(4) call _rtld@PLT # Call rtld(sp); returns entry point addl $16,%esp # Remove arguments from stack + cfi_adjust_cfa_offset(-16) popl %edx # Get exit procedure address + cfi_adjust_cfa_offset(-4) movl %esi,%esp # Ignore obj_main + cfi_def_cfa(%esp,0) /* * At this point, %eax contains the entry point of the main program, and * %edx contains a pointer to a termination function that should be @@ -72,21 +81,32 @@ .type _rtld_bind_start,@function _rtld_bind_start: pushf # Save eflags + cfi_adjust_cfa_offset(4) pushl %eax # Save %eax + cfi_adjust_cfa_offset(4) pushl %edx # Save %edx + cfi_adjust_cfa_offset(4) pushl %ecx # Save %ecx + cfi_adjust_cfa_offset(4) pushl 20(%esp) # Copy reloff argument + cfi_adjust_cfa_offset(4) pushl 20(%esp) # Copy obj argument + cfi_adjust_cfa_offset(4) call _rtld_bind@PLT # Transfer control to the binder /* Now %eax contains the entry point of the function being called. */ addl $8,%esp # Discard binder arguments + cfi_adjust_cfa_offset(-8) movl %eax,20(%esp) # Store target over obj argument popl %ecx # Restore %ecx + cfi_adjust_cfa_offset(-4) popl %edx # Restore %edx + cfi_adjust_cfa_offset(-4) popl %eax # Restore %eax + cfi_adjust_cfa_offset(-4) popf # Restore eflags + cfi_adjust_cfa_offset(-4) leal 4(%esp),%esp # Discard reloff, do not change eflags ret # "Return" to target address From owner-svn-soc-all@FreeBSD.ORG Wed Jul 6 05:48:29 2011 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 93C571065670 for ; Wed, 6 Jul 2011 05:48:27 +0000 (UTC) (envelope-from aalvarez@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Wed, 06 Jul 2011 05:48:27 +0000 Date: Wed, 06 Jul 2011 05:48:27 +0000 From: aalvarez@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20110706054827.93C571065670@hub.freebsd.org> Cc: Subject: socsvn commit: r223991 - in soc2011/aalvarez/pbmac: lib/libugidfw sys/security/mac_bsdextended usr.sbin/ugidfw X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Jul 2011 05:48:29 -0000 Author: aalvarez Date: Wed Jul 6 05:48:27 2011 New Revision: 223991 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=223991 Log: Only store filepath and make checks against it with the help of vn_fullpath_global Modified: soc2011/aalvarez/pbmac/lib/libugidfw/ugidfw.c soc2011/aalvarez/pbmac/sys/security/mac_bsdextended/mac_bsdextended.c soc2011/aalvarez/pbmac/sys/security/mac_bsdextended/mac_bsdextended.h soc2011/aalvarez/pbmac/usr.sbin/ugidfw/ugidfw.c Modified: soc2011/aalvarez/pbmac/lib/libugidfw/ugidfw.c ============================================================================== --- soc2011/aalvarez/pbmac/lib/libugidfw/ugidfw.c Wed Jul 6 00:50:54 2011 (r223990) +++ soc2011/aalvarez/pbmac/lib/libugidfw/ugidfw.c Wed Jul 6 05:48:27 2011 (r223991) @@ -351,9 +351,9 @@ left -= len; cur += len; } - if (rule->mbr_object.mbo_flags & MBO_FSID_DEFINED) { + if (rule->mbr_object.mbo_flags & MBO_FPATH_DEFINED) { len = snprintf(cur, left, "filepath %s ", - rule->mbr_object.mbo_fpath); + rule->mbr_object.mbo_fpath ? rule->mbr_object.mbo_fpath : "???"); if (len < 0 || len > left) goto truncated; left -= len; @@ -804,16 +804,9 @@ { size_t len; - len = strlen(spec); - *fpath = malloc(len * sizeof(*spec)); - - if (*fpath == NULL) { - len = snprintf(errstr, buflen, "Unable to allocate memory for filepath %s: %s", - spec, strerror(errno)); - return (-1); - } - - strncpy(*fpath, spec, len); + *fpath = realpath(spec, NULL); + if (*fpath == NULL) + len = snprintf(errstr, buflen, "%s", strerror(errno)); return (0); } Modified: soc2011/aalvarez/pbmac/sys/security/mac_bsdextended/mac_bsdextended.c ============================================================================== --- soc2011/aalvarez/pbmac/sys/security/mac_bsdextended/mac_bsdextended.c Wed Jul 6 00:50:54 2011 (r223990) +++ soc2011/aalvarez/pbmac/sys/security/mac_bsdextended/mac_bsdextended.c Wed Jul 6 05:48:27 2011 (r223991) @@ -137,53 +137,13 @@ } static int -ugidfw_rslv_fpath(struct mac_bsdextended_rule *ruleptr, struct mac_bsdextended_rule *temprule, struct thread *td) -{ - struct nameidata nd; - int error; - struct vnode* vp; - struct vattr vap; - /* Check empty paths */ - if (temprule->mbr_object.mbo_fpath_len < 1) - return EINVAL; - - ruleptr->mbr_object.mbo_fpath_len = temprule->mbr_object.mbo_fpath_len; - ruleptr->mbr_object.mbo_fpath = malloc(sizeof(char)*(ruleptr->mbr_object.mbo_fpath_len+1), - M_MACBSDEXTENDED, M_WAITOK); - - KASSERT(ruleptr == NULL, ("sysctl_rule: ruleptr != NULL")); - memcpy(ruleptr->mbr_object.mbo_fpath, temprule->mbr_object.mbo_fpath, - ruleptr->mbr_object.mbo_fpath_len+1); - - /* Resolve path to fsid and fileid */ - NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, ruleptr->mbr_object.mbo_fpath, td); - error = namei(&nd); - if (error) - goto out; - - vp = nd.ni_vp; - error = VOP_GETATTR(vp, &vap, td->td_proc->p_ucred); - if (error) - goto out; - - ruleptr->mbr_object.mbo_fsid = vp->v_mount->mnt_stat.f_fsid; - ruleptr->mbr_object.mbo_fid = vap.va_fileid; - -out: - NDFREE(&nd, 0); - if (error) - KMBRFREE((*ruleptr), M_MACBSDEXTENDED); - - return error; -} - -static int sysctl_rule(SYSCTL_HANDLER_ARGS) { struct mac_bsdextended_rule temprule, *ruleptr; u_int namelen; int error, index, *name; - + char * fpath = NULL; + error = 0; name = (int *)arg1; namelen = arg2; @@ -200,10 +160,13 @@ return (error); ruleptr = malloc(sizeof(*ruleptr), M_MACBSDEXTENDED, M_WAITOK | M_ZERO); + + fpath = malloc(sizeof(*fpath)*temprule.mbr_object.mbo_fpath_len, + M_MACBSDEXTENDED, M_WAITOK | M_ZERO); } mtx_lock(&ugidfw_mtx); - if (req->oldptr) { /* Modify rule request */ + if (req->oldptr) { /* Get rule request */ if (index < 0 || index > rule_slots + 1) { error = ENOENT; goto out; @@ -229,23 +192,32 @@ goto out; if (rules[index] == NULL) { *ruleptr = temprule; - if (ruleptr->mbr_object.mbo_flags & MBO_FPATH_DEFINED) { - error = ugidfw_rslv_fpath(ruleptr, &temprule, req->td); - if (error) - goto out; - } rules[index] = ruleptr; ruleptr = NULL; if (index + 1 > rule_slots) rule_slots = index + 1; rule_count++; - } else + } else { + if (rules[index]->mbr_object.mbo_fpath != NULL) + free(rules[index]->mbr_object.mbo_fpath, M_MACBSDEXTENDED); + *rules[index] = temprule; + } + + /* If there's a filepath, make a copy */ + if (temprule.mbr_object.mbo_flags & MBO_FPATH_DEFINED && + temprule.mbr_object.mbo_fpath != NULL) { + copyinstr(temprule.mbr_object.mbo_fpath, fpath, + temprule.mbr_object.mbo_fpath_len, NULL); + rules[index]->mbr_object.mbo_fpath = fpath; + } } out: mtx_unlock(&ugidfw_mtx); - if (ruleptr != NULL) + if (ruleptr != NULL) { + KMBRFREE((*ruleptr), M_MACBSDEXTENDED); free(ruleptr, M_MACBSDEXTENDED); + } if (req->oldptr && error == 0) error = SYSCTL_OUT(req, &temprule, sizeof(temprule)); return (error); @@ -277,7 +249,7 @@ static int ugidfw_rulecheck(struct mac_bsdextended_rule *rule, - struct ucred *cred, struct vnode *vp, struct vattr *vap, int acc_mode) + struct ucred *cred, struct vnode *vp, struct vattr *vap, int acc_mode, char *fpath_hint) { int mac_granted, match, priv_granted; int i; @@ -361,12 +333,8 @@ return (0); } - if (rule->mbr_object.mbo_flags & MBO_FPATH_DEFINED) { - match = (bcmp(&(vp->v_mount->mnt_stat.f_fsid), - &(rule->mbr_object.mbo_fsid), - sizeof(rule->mbr_object.mbo_fsid)) == 0 && - bcmp(&(vap->va_fileid), &(rule->mbr_object.mbo_fid), - sizeof(rule->mbr_object.mbo_fid)) == 0); + if (rule->mbr_object.mbo_flags & MBO_FPATH_DEFINED && fpath_hint != NULL) { + match = strcmp(fpath_hint, rule->mbr_object.mbo_fpath); if (rule->mbr_object.mbo_neg & MBO_FPATH_DEFINED) match = !match; @@ -491,6 +459,8 @@ int acc_mode) { int error, i; + char * fullpath, *freepath; + fullpath = freepath = NULL; /* * Since we do not separately handle append, map append to write. @@ -503,8 +473,16 @@ for (i = 0; i < rule_slots; i++) { if (rules[i] == NULL) continue; + + if (rules[i]->mbr_object.mbo_flags & MBO_FPATH_DEFINED && fullpath == NULL) { + mtx_unlock(&ugidfw_mtx); + vn_fullpath_global(curthread, vp, &fullpath, &freepath); + mtx_lock(&ugidfw_mtx); + } + error = ugidfw_rulecheck(rules[i], cred, - vp, vap, acc_mode); + vp, vap, acc_mode, fullpath); + if (error == EJUSTRETURN) break; if (error) { @@ -513,6 +491,10 @@ } } mtx_unlock(&ugidfw_mtx); + + if (freepath) + free(freepath, M_TEMP); + return (0); } @@ -569,7 +551,7 @@ .mpo_vnode_check_getextattr = ugidfw_vnode_check_getextattr, .mpo_vnode_check_link = ugidfw_vnode_check_link, .mpo_vnode_check_listextattr = ugidfw_vnode_check_listextattr, - .mpo_vnode_check_lookup = ugidfw_vnode_check_lookup, + /* .mpo_vnode_check_lookup = ugidfw_vnode_check_lookup, */ .mpo_vnode_check_open = ugidfw_vnode_check_open, .mpo_vnode_check_readdir = ugidfw_vnode_check_readdir, .mpo_vnode_check_readlink = ugidfw_vnode_check_readdlink, Modified: soc2011/aalvarez/pbmac/sys/security/mac_bsdextended/mac_bsdextended.h ============================================================================== --- soc2011/aalvarez/pbmac/sys/security/mac_bsdextended/mac_bsdextended.h Wed Jul 6 00:50:54 2011 (r223990) +++ soc2011/aalvarez/pbmac/sys/security/mac_bsdextended/mac_bsdextended.h Wed Jul 6 05:48:27 2011 (r223991) @@ -104,7 +104,6 @@ gid_t mbo_gid_max; struct fsid mbo_fsid; int mbo_type; - long mbo_fid; size_t mbo_fpath_len; char* mbo_fpath; }; Modified: soc2011/aalvarez/pbmac/usr.sbin/ugidfw/ugidfw.c ============================================================================== --- soc2011/aalvarez/pbmac/usr.sbin/ugidfw/ugidfw.c Wed Jul 6 00:50:54 2011 (r223990) +++ soc2011/aalvarez/pbmac/usr.sbin/ugidfw/ugidfw.c Wed Jul 6 05:48:27 2011 (r223991) @@ -78,19 +78,20 @@ error = bsde_parse_rule(argc, argv, &rule, BUFSIZ, errstr); if (error) { warnx("%s", errstr); - return; + goto out; } error = bsde_add_rule(&rulenum, &rule, BUFSIZ, errstr); if (error) { warnx("%s", errstr); - return; + goto out; } if (bsde_rule_to_string(&rule, charstr, BUFSIZ) == -1) warnx("Added rule, but unable to print string."); else printf("%d %s\n", rulenum, charstr); +out: MBRFREE(rule); } @@ -131,8 +132,6 @@ else printf("%d %s\n", i, charstr); } - - MBRFREE(rule); } void From owner-svn-soc-all@FreeBSD.ORG Thu Jul 7 23:40:13 2011 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 3FCB51065672 for ; Thu, 7 Jul 2011 23:40:11 +0000 (UTC) (envelope-from aalvarez@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Thu, 07 Jul 2011 23:40:11 +0000 Date: Thu, 07 Jul 2011 23:40:11 +0000 From: aalvarez@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20110707234011.3FCB51065672@hub.freebsd.org> Cc: Subject: socsvn commit: r224025 - soc2011/aalvarez/pbmac/sys/security/mac_bsdextended X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Jul 2011 23:40:13 -0000 Author: aalvarez Date: Thu Jul 7 23:40:10 2011 New Revision: 224025 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=224025 Log: Fix match logic Modified: soc2011/aalvarez/pbmac/sys/security/mac_bsdextended/mac_bsdextended.c Modified: soc2011/aalvarez/pbmac/sys/security/mac_bsdextended/mac_bsdextended.c ============================================================================== --- soc2011/aalvarez/pbmac/sys/security/mac_bsdextended/mac_bsdextended.c Thu Jul 7 22:30:12 2011 (r224024) +++ soc2011/aalvarez/pbmac/sys/security/mac_bsdextended/mac_bsdextended.c Thu Jul 7 23:40:10 2011 (r224025) @@ -161,8 +161,14 @@ ruleptr = malloc(sizeof(*ruleptr), M_MACBSDEXTENDED, M_WAITOK | M_ZERO); - fpath = malloc(sizeof(*fpath)*temprule.mbr_object.mbo_fpath_len, - M_MACBSDEXTENDED, M_WAITOK | M_ZERO); + /* If there's a filepath, make a copy */ + if (temprule.mbr_object.mbo_flags & MBO_FPATH_DEFINED && + temprule.mbr_object.mbo_fpath != NULL) { + fpath = malloc(sizeof(*fpath)*temprule.mbr_object.mbo_fpath_len, + M_MACBSDEXTENDED, M_WAITOK | M_ZERO); + copyinstr(temprule.mbr_object.mbo_fpath, fpath, + temprule.mbr_object.mbo_fpath_len, NULL); + } } mtx_lock(&ugidfw_mtx); @@ -204,13 +210,7 @@ *rules[index] = temprule; } - /* If there's a filepath, make a copy */ - if (temprule.mbr_object.mbo_flags & MBO_FPATH_DEFINED && - temprule.mbr_object.mbo_fpath != NULL) { - copyinstr(temprule.mbr_object.mbo_fpath, fpath, - temprule.mbr_object.mbo_fpath_len, NULL); - rules[index]->mbr_object.mbo_fpath = fpath; - } + rules[index]->mbr_object.mbo_fpath = fpath; } out: mtx_unlock(&ugidfw_mtx); @@ -334,7 +334,7 @@ } if (rule->mbr_object.mbo_flags & MBO_FPATH_DEFINED && fpath_hint != NULL) { - match = strcmp(fpath_hint, rule->mbr_object.mbo_fpath); + match = (strcmp(fpath_hint, rule->mbr_object.mbo_fpath) == 0); if (rule->mbr_object.mbo_neg & MBO_FPATH_DEFINED) match = !match; From owner-svn-soc-all@FreeBSD.ORG Fri Jul 8 15:49:41 2011 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id BB272106566B for ; Fri, 8 Jul 2011 15:49:39 +0000 (UTC) (envelope-from gk@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Fri, 08 Jul 2011 15:49:39 +0000 Date: Fri, 08 Jul 2011 15:49:39 +0000 From: gk@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20110708154939.BB272106566B@hub.freebsd.org> Cc: Subject: socsvn commit: r224050 - in soc2011/gk/ino64-head/sys: fs/nfs fs/nfsclient fs/nfsserver nfsclient nfsserver X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Jul 2011 15:49:42 -0000 Author: gk Date: Fri Jul 8 15:49:39 2011 New Revision: 224050 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=224050 Log: Remove readdir cookies and set d_off in NFS Modified: soc2011/gk/ino64-head/sys/fs/nfs/nfs.h soc2011/gk/ino64-head/sys/fs/nfs/nfs_commonport.c soc2011/gk/ino64-head/sys/fs/nfs/nfs_commonsubs.c soc2011/gk/ino64-head/sys/fs/nfs/nfs_var.h soc2011/gk/ino64-head/sys/fs/nfs/nfsport.h soc2011/gk/ino64-head/sys/fs/nfsclient/nfs_clrpcops.c soc2011/gk/ino64-head/sys/fs/nfsserver/nfs_nfsdport.c soc2011/gk/ino64-head/sys/fs/nfsserver/nfs_nfsdsubs.c soc2011/gk/ino64-head/sys/nfsclient/nfs_vnops.c soc2011/gk/ino64-head/sys/nfsserver/nfs_serv.c Modified: soc2011/gk/ino64-head/sys/fs/nfs/nfs.h ============================================================================== --- soc2011/gk/ino64-head/sys/fs/nfs/nfs.h Fri Jul 8 14:30:06 2011 (r224049) +++ soc2011/gk/ino64-head/sys/fs/nfs/nfs.h Fri Jul 8 15:49:39 2011 (r224050) @@ -251,7 +251,7 @@ u_char *nfr_srvlist; /* List of servers */ int nfr_srvcnt; /* number of servers */ vnode_t nfr_vp; /* vnode for referral */ - u_int32_t nfr_dfileno; /* assigned dir inode# */ + u_int64_t nfr_dfileno; /* assigned dir inode# */ }; /* Modified: soc2011/gk/ino64-head/sys/fs/nfs/nfs_commonport.c ============================================================================== --- soc2011/gk/ino64-head/sys/fs/nfs/nfs_commonport.c Fri Jul 8 14:30:06 2011 (r224049) +++ soc2011/gk/ino64-head/sys/fs/nfs/nfs_commonport.c Fri Jul 8 15:49:39 2011 (r224050) @@ -291,7 +291,7 @@ /* Fake nfsrv_atroot. Just return 0 */ int -nfsrv_atroot(struct vnode *vp, long *retp) +nfsrv_atroot(struct vnode *vp, ino_t *retp) { return (0); @@ -372,7 +372,7 @@ * Get referral. For now, just fail. */ struct nfsreferral * -nfsv4root_getreferral(struct vnode *vp, struct vnode *dvp, u_int32_t fileno) +nfsv4root_getreferral(struct vnode *vp, struct vnode *dvp, u_int64_t fileno) { return (NULL); Modified: soc2011/gk/ino64-head/sys/fs/nfs/nfs_commonsubs.c ============================================================================== --- soc2011/gk/ino64-head/sys/fs/nfs/nfs_commonsubs.c Fri Jul 8 14:30:06 2011 (r224049) +++ soc2011/gk/ino64-head/sys/fs/nfs/nfs_commonsubs.c Fri Jul 8 15:49:39 2011 (r224050) @@ -767,7 +767,7 @@ struct timespec temptime; uid_t uid; gid_t gid; - long fid; + ino_t fid; u_int32_t freenum = 0, tuint; u_int64_t uquad = 0, thyp, thyp2; #ifdef QUOTA @@ -1671,7 +1671,7 @@ } else { if (!vp || !nfsrv_atroot(vp, &fid)) fid = nap->na_fileid; - if ((u_int64_t)fid != thyp) + if (fid != thyp) *retcmpp = NFSERR_NOTSAME; } } Modified: soc2011/gk/ino64-head/sys/fs/nfs/nfs_var.h ============================================================================== --- soc2011/gk/ino64-head/sys/fs/nfs/nfs_var.h Fri Jul 8 14:30:06 2011 (r224049) +++ soc2011/gk/ino64-head/sys/fs/nfs/nfs_var.h Fri Jul 8 15:49:39 2011 (r224050) @@ -324,8 +324,8 @@ struct ucred *newnfs_getcred(void); void newnfs_setroot(struct ucred *); int nfs_catnap(int, int, const char *); -struct nfsreferral *nfsv4root_getreferral(vnode_t, vnode_t, u_int32_t); -int nfsrv_atroot(vnode_t, long *); +struct nfsreferral *nfsv4root_getreferral(vnode_t, vnode_t, u_int64_t); +int nfsrv_atroot(vnode_t, ino_t *); void newnfs_timer(void *); int nfs_supportsnfsv4acls(vnode_t); Modified: soc2011/gk/ino64-head/sys/fs/nfs/nfsport.h ============================================================================== --- soc2011/gk/ino64-head/sys/fs/nfs/nfsport.h Fri Jul 8 14:30:06 2011 (r224049) +++ soc2011/gk/ino64-head/sys/fs/nfs/nfsport.h Fri Jul 8 15:49:39 2011 (r224050) @@ -385,7 +385,7 @@ struct nfsvattr { struct vattr na_vattr; nfsattrbit_t na_suppattr; - u_int32_t na_mntonfileno; + u_int64_t na_mntonfileno; u_int64_t na_filesid[2]; }; Modified: soc2011/gk/ino64-head/sys/fs/nfsclient/nfs_clrpcops.c ============================================================================== --- soc2011/gk/ino64-head/sys/fs/nfsclient/nfs_clrpcops.c Fri Jul 8 14:30:06 2011 (r224049) +++ soc2011/gk/ino64-head/sys/fs/nfsclient/nfs_clrpcops.c Fri Jul 8 15:49:39 2011 (r224050) @@ -2635,6 +2635,7 @@ dp->d_name[0] = '.'; dp->d_name[1] = '\0'; dp->d_reclen = DIRENT_SIZE(dp) + NFSX_HYPER; + dp->d_off = 0; /* * Just make these offset cookie 0. */ @@ -2654,6 +2655,7 @@ dp->d_name[1] = '.'; dp->d_name[2] = '\0'; dp->d_reclen = DIRENT_SIZE(dp) + NFSX_HYPER; + dp->d_off = 0; /* * Just make these offset cookie 0. */ @@ -2764,6 +2766,7 @@ uio_iov_len_add(uiop, -(left)); uio_uio_resid_add(uiop, -(left)); uiop->uio_offset += left; + dp->d_off = uiop->uio_offset; blksiz = 0; } if ((int)(tlen + DIRHDSIZ + NFSX_HYPER) > uio_uio_resid(uiop)) @@ -2792,6 +2795,7 @@ uio_iov_len_add(uiop, -(tlen + NFSX_HYPER)); uio_uio_resid_add(uiop, -(tlen + NFSX_HYPER)); uiop->uio_offset += (tlen + NFSX_HYPER); + dp->d_off = uiop->uio_offset; } else { error = nfsm_advance(nd, NFSM_RNDUP(len), -1); if (error) @@ -2878,6 +2882,7 @@ uio_iov_len_add(uiop, -(left)); uio_uio_resid_add(uiop, -(left)); uiop->uio_offset += left; + dp->d_off = uiop->uio_offset; } /* @@ -2902,6 +2907,7 @@ dp = (struct dirent *) CAST_DOWN(caddr_t, uio_iov_base(uiop)); dp->d_type = DT_UNKNOWN; dp->d_fileno = 0; + dp->d_off = 0; dp->d_namlen = 0; dp->d_name[0] = '\0'; tl = (u_int32_t *)&dp->d_name[4]; Modified: soc2011/gk/ino64-head/sys/fs/nfsserver/nfs_nfsdport.c ============================================================================== --- soc2011/gk/ino64-head/sys/fs/nfsserver/nfs_nfsdport.c Fri Jul 8 14:30:06 2011 (r224049) +++ soc2011/gk/ino64-head/sys/fs/nfsserver/nfs_nfsdport.c Fri Jul 8 15:49:39 2011 (r224050) @@ -1456,12 +1456,10 @@ char *cpos, *cend, *rbuf; struct nfsvattr at; int nlen, error = 0, getret = 1; - int siz, cnt, fullsiz, eofflag, ncookies; + int siz, cnt, fullsiz, eofflag; u_int64_t off, toff, verf; - u_long *cookies = NULL, *cookiep; struct uio io; struct iovec iv; - int not_zfs; if (nd->nd_repstat) { nfsrv_postopattr(nd, getret, &at); @@ -1514,14 +1512,8 @@ nfsrv_postopattr(nd, getret, &at); return (0); } - not_zfs = strcmp(vp->v_mount->mnt_vfc->vfc_name, "zfs"); MALLOC(rbuf, caddr_t, siz, M_TEMP, M_WAITOK); -again: eofflag = 0; - if (cookies) { - free((caddr_t)cookies, M_TEMP); - cookies = NULL; - } iv.iov_base = rbuf; iv.iov_len = siz; @@ -1532,14 +1524,11 @@ io.uio_segflg = UIO_SYSSPACE; io.uio_rw = UIO_READ; io.uio_td = NULL; - nd->nd_repstat = VOP_READDIR(vp, &io, nd->nd_cred, &eofflag, &ncookies, - &cookies); + nd->nd_repstat = VOP_READDIR(vp, &io, nd->nd_cred, &eofflag); off = (u_int64_t)io.uio_offset; if (io.uio_resid) siz -= io.uio_resid; - if (!cookies && !nd->nd_repstat) - nd->nd_repstat = NFSERR_PERM; if (nd->nd_flag & ND_NFSV3) { getret = nfsvno_getattr(vp, &at, nd->nd_cred, p, 1); if (!nd->nd_repstat) @@ -1552,8 +1541,6 @@ if (nd->nd_repstat) { vput(vp); free((caddr_t)rbuf, M_TEMP); - if (cookies) - free((caddr_t)cookies, M_TEMP); if (nd->nd_flag & ND_NFSV3) nfsrv_postopattr(nd, getret, &at); return (0); @@ -1575,7 +1562,6 @@ *tl++ = newnfs_false; *tl = newnfs_true; FREE((caddr_t)rbuf, M_TEMP); - FREE((caddr_t)cookies, M_TEMP); return (0); } @@ -1586,30 +1572,7 @@ cpos = rbuf; cend = rbuf + siz; dp = (struct dirent *)cpos; - cookiep = cookies; - /* - * For some reason FreeBSD's ufs_readdir() chooses to back the - * directory offset up to a block boundary, so it is necessary to - * skip over the records that precede the requested offset. This - * requires the assumption that file offset cookies monotonically - * increase. - * Since the offset cookies don't monotonically increase for ZFS, - * this is not done when ZFS is the file system. - */ - while (cpos < cend && ncookies > 0 && - (dp->d_fileno == 0 || dp->d_type == DT_WHT || - (not_zfs != 0 && ((u_quad_t)(*cookiep)) <= toff))) { - cpos += dp->d_reclen; - dp = (struct dirent *)cpos; - cookiep++; - ncookies--; - } - if (cpos >= cend || ncookies == 0) { - siz = fullsiz; - toff = off; - goto again; - } vput(vp); /* @@ -1628,7 +1591,7 @@ } /* Loop through the records and build reply */ - while (cpos < cend && ncookies > 0) { + while (cpos < cend) { nlen = dp->d_namlen; if (dp->d_fileno != 0 && dp->d_type != DT_WHT && nlen <= NFS_MAXNAMLEN) { @@ -1648,24 +1611,23 @@ if (nd->nd_flag & ND_NFSV3) { NFSM_BUILD(tl, u_int32_t *, 3 * NFSX_UNSIGNED); *tl++ = newnfs_true; - *tl++ = 0; + txdr_hyper(dp->d_fileno, tl); } else { NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED); *tl++ = newnfs_true; + *tl = txdr_unsigned(dp->d_fileno); } - *tl = txdr_unsigned(dp->d_fileno); (void) nfsm_strtom(nd, dp->d_name, nlen); if (nd->nd_flag & ND_NFSV3) { NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED); - *tl++ = 0; - } else + txdr_hyper(dp->d_off, tl); + } else { NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED); - *tl = txdr_unsigned(*cookiep); + *tl = txdr_unsigned(dp->d_off); + } } cpos += dp->d_reclen; dp = (struct dirent *)cpos; - cookiep++; - ncookies--; } if (cpos < cend) eofflag = 0; @@ -1676,7 +1638,6 @@ else *tl = newnfs_false; FREE((caddr_t)rbuf, M_TEMP); - FREE((caddr_t)cookies, M_TEMP); return (0); nfsmout: vput(vp); @@ -1700,15 +1661,14 @@ struct mbuf *mb0, *mb1; struct nfsreferral *refp; int nlen, r, error = 0, getret = 1, usevget = 1; - int siz, cnt, fullsiz, eofflag, ncookies, entrycnt; + int siz, cnt, fullsiz, eofflag, entrycnt; caddr_t bpos0, bpos1; u_int64_t off, toff, verf; - u_long *cookies = NULL, *cookiep; nfsattrbit_t attrbits, rderrbits, savbits; struct uio io; struct iovec iv; struct componentname cn; - int at_root, needs_unbusy, not_zfs, supports_nfsv4acls; + int at_root, needs_unbusy, supports_nfsv4acls; struct mount *mp, *new_mp; uint64_t mounted_on_fileno; @@ -1788,15 +1748,9 @@ nfsrv_postopattr(nd, getret, &at); return (0); } - not_zfs = strcmp(vp->v_mount->mnt_vfc->vfc_name, "zfs"); MALLOC(rbuf, caddr_t, siz, M_TEMP, M_WAITOK); -again: eofflag = 0; - if (cookies) { - free((caddr_t)cookies, M_TEMP); - cookies = NULL; - } iv.iov_base = rbuf; iv.iov_len = siz; @@ -1807,22 +1761,17 @@ io.uio_segflg = UIO_SYSSPACE; io.uio_rw = UIO_READ; io.uio_td = NULL; - nd->nd_repstat = VOP_READDIR(vp, &io, nd->nd_cred, &eofflag, &ncookies, - &cookies); + nd->nd_repstat = VOP_READDIR(vp, &io, nd->nd_cred, &eofflag); off = (u_int64_t)io.uio_offset; if (io.uio_resid) siz -= io.uio_resid; getret = nfsvno_getattr(vp, &at, nd->nd_cred, p, 1); - if (!cookies && !nd->nd_repstat) - nd->nd_repstat = NFSERR_PERM; if (!nd->nd_repstat) nd->nd_repstat = getret; if (nd->nd_repstat) { vput(vp); - if (cookies) - free((caddr_t)cookies, M_TEMP); free((caddr_t)rbuf, M_TEMP); if (nd->nd_flag & ND_NFSV3) nfsrv_postopattr(nd, getret, &at); @@ -1841,7 +1790,6 @@ tl += 2; *tl++ = newnfs_false; *tl = newnfs_true; - free((caddr_t)cookies, M_TEMP); free((caddr_t)rbuf, M_TEMP); return (0); } @@ -1853,33 +1801,6 @@ cpos = rbuf; cend = rbuf + siz; dp = (struct dirent *)cpos; - cookiep = cookies; - - /* - * For some reason FreeBSD's ufs_readdir() chooses to back the - * directory offset up to a block boundary, so it is necessary to - * skip over the records that precede the requested offset. This - * requires the assumption that file offset cookies monotonically - * increase. - * Since the offset cookies don't monotonically increase for ZFS, - * this is not done when ZFS is the file system. - */ - while (cpos < cend && ncookies > 0 && - (dp->d_fileno == 0 || dp->d_type == DT_WHT || - (not_zfs != 0 && ((u_quad_t)(*cookiep)) <= toff) || - ((nd->nd_flag & ND_NFSV4) && - ((dp->d_namlen == 1 && dp->d_name[0] == '.') || - (dp->d_namlen==2 && dp->d_name[0]=='.' && dp->d_name[1]=='.'))))) { - cpos += dp->d_reclen; - dp = (struct dirent *)cpos; - cookiep++; - ncookies--; - } - if (cpos >= cend || ncookies == 0) { - siz = fullsiz; - toff = off; - goto again; - } /* * Busy the file system so that the mount point won't go away @@ -1892,7 +1813,6 @@ vfs_rel(mp); if (nd->nd_repstat != 0) { vrele(vp); - free(cookies, M_TEMP); free(rbuf, M_TEMP); if (nd->nd_flag & ND_NFSV3) nfsrv_postopattr(nd, getret, &at); @@ -1929,7 +1849,7 @@ /* Loop through the records and build reply */ entrycnt = 0; - while (cpos < cend && ncookies > 0 && dirlen < cnt) { + while (cpos < cend && dirlen < cnt) { nlen = dp->d_namlen; if (dp->d_fileno != 0 && dp->d_type != DT_WHT && nlen <= NFS_MAXNAMLEN && @@ -2060,12 +1980,12 @@ if (nd->nd_flag & ND_NFSV3) { NFSM_BUILD(tl, u_int32_t *, 3 * NFSX_UNSIGNED); *tl++ = newnfs_true; - *tl++ = 0; - *tl = txdr_unsigned(dp->d_fileno); + txdr_hyper(dp->d_fileno, tl); + tl += 2; dirlen += nfsm_strtom(nd, dp->d_name, nlen); NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED); - *tl++ = 0; - *tl = txdr_unsigned(*cookiep); + txdr_hyper(dp->d_off, tl); + tl += 2; nfsrv_postopattr(nd, 0, nvap); dirlen += nfsm_fhtom(nd,(u_int8_t *)&nfh,0,1); dirlen += (5*NFSX_UNSIGNED+NFSX_V3POSTOPATTR); @@ -2074,8 +1994,8 @@ } else { NFSM_BUILD(tl, u_int32_t *, 3 * NFSX_UNSIGNED); *tl++ = newnfs_true; - *tl++ = 0; - *tl = txdr_unsigned(*cookiep); + txdr_hyper(dp->d_off, tl); + tl += 2; dirlen += nfsm_strtom(nd, dp->d_name, nlen); if (nvp != NULL) { supports_nfsv4acls = @@ -2118,8 +2038,6 @@ } cpos += dp->d_reclen; dp = (struct dirent *)cpos; - cookiep++; - ncookies--; } vrele(vp); vfs_unbusy(mp); @@ -2146,7 +2064,6 @@ else *tl = newnfs_false; } - FREE((caddr_t)cookies, M_TEMP); FREE((caddr_t)rbuf, M_TEMP); return (0); nfsmout: Modified: soc2011/gk/ino64-head/sys/fs/nfsserver/nfs_nfsdsubs.c ============================================================================== --- soc2011/gk/ino64-head/sys/fs/nfsserver/nfs_nfsdsubs.c Fri Jul 8 14:30:06 2011 (r224049) +++ soc2011/gk/ino64-head/sys/fs/nfsserver/nfs_nfsdsubs.c Fri Jul 8 15:49:39 2011 (r224050) @@ -1751,8 +1751,8 @@ break; case NFSATTRBIT_MOUNTEDONFILEID: NFSM_BUILD(tl, u_int32_t *, NFSX_HYPER); - *tl++ = 0; - *tl = txdr_unsigned(refp->nfr_dfileno); + txdr_hyper(refp->nfr_dfileno, tl); + tl += 2; retnum += NFSX_HYPER; break; default: Modified: soc2011/gk/ino64-head/sys/nfsclient/nfs_vnops.c ============================================================================== --- soc2011/gk/ino64-head/sys/nfsclient/nfs_vnops.c Fri Jul 8 14:30:06 2011 (r224049) +++ soc2011/gk/ino64-head/sys/nfsclient/nfs_vnops.c Fri Jul 8 15:49:39 2011 (r224050) @@ -2364,13 +2364,14 @@ uiop->uio_iov->iov_len -= left; uiop->uio_offset += left; uiop->uio_resid -= left; + dp->d_off = uiop->uio_offset; blksiz = 0; } if ((tlen + DIRHDSIZ) > uiop->uio_resid) bigenough = 0; if (bigenough) { dp = (struct dirent *)uiop->uio_iov->iov_base; - dp->d_fileno = (int)fileno; + dp->d_fileno = fileno; dp->d_namlen = len; dp->d_reclen = tlen + DIRHDSIZ; dp->d_type = DT_UNKNOWN; @@ -2391,6 +2392,7 @@ uiop->uio_iov->iov_len -= tlen; uiop->uio_offset += tlen; uiop->uio_resid -= tlen; + dp->d_off = uiop->uio_offset; } else nfsm_adv(nfsm_rndup(len)); if (v3) { @@ -2431,6 +2433,7 @@ uiop->uio_iov->iov_len -= left; uiop->uio_offset += left; uiop->uio_resid -= left; + dp->d_off = uiop->uio_offset; } /* @@ -2558,7 +2561,7 @@ bigenough = 0; if (bigenough) { dp = (struct dirent *)uiop->uio_iov->iov_base; - dp->d_fileno = (int)fileno; + dp->d_fileno = fileno; dp->d_namlen = len; dp->d_reclen = tlen + DIRHDSIZ; dp->d_type = DT_UNKNOWN; Modified: soc2011/gk/ino64-head/sys/nfsserver/nfs_serv.c ============================================================================== --- soc2011/gk/ino64-head/sys/nfsserver/nfs_serv.c Fri Jul 8 14:30:06 2011 (r224049) +++ soc2011/gk/ino64-head/sys/nfsserver/nfs_serv.c Fri Jul 8 15:49:39 2011 (r224050) @@ -2735,11 +2735,10 @@ struct uio io; struct iovec iv; int len, nlen, rem, xfer, tsiz, i, error = 0, getret = 1; - int siz, cnt, fullsiz, eofflag, rdonly, ncookies; + int siz, cnt, fullsiz, eofflag, rdonly; int v3 = (nfsd->nd_flag & ND_NFSV3); u_quad_t off, toff, verf; - u_long *cookies = NULL, *cookiep; /* needs to be int64_t or off_t */ - int vfslocked, not_zfs; + int vfslocked; nfsdbprintf(("%s %d\n", __FILE__, __LINE__)); vfslocked = 0; @@ -2803,14 +2802,12 @@ error = 0; goto nfsmout; } - not_zfs = strcmp(vp->v_mount->mnt_vfc->vfc_name, "zfs") != 0; VOP_UNLOCK(vp, 0); /* * end section. Allocate rbuf and continue */ rbuf = malloc(siz, M_TEMP, M_WAITOK); -again: iv.iov_base = rbuf; iv.iov_len = fullsiz; io.uio_iov = &iv; @@ -2821,15 +2818,9 @@ io.uio_rw = UIO_READ; io.uio_td = NULL; eofflag = 0; - if (cookies) { - free((caddr_t)cookies, M_TEMP); - cookies = NULL; - } vn_lock(vp, LK_SHARED | LK_RETRY); - error = VOP_READDIR(vp, &io, cred, &eofflag, &ncookies, &cookies); + error = VOP_READDIR(vp, &io, cred, &eofflag); off = (off_t)io.uio_offset; - if (!cookies && !error) - error = NFSERR_PERM; if (v3) { getret = VOP_GETATTR(vp, &at, cred); if (!error) @@ -2840,8 +2831,6 @@ vrele(vp); vp = NULL; free((caddr_t)rbuf, M_TEMP); - if (cookies) - free((caddr_t)cookies, M_TEMP); nfsm_reply(NFSX_POSTOPATTR(v3)); if (v3) nfsm_srvpostop_attr(getret, &at); @@ -2870,7 +2859,6 @@ *tl++ = nfsrv_nfs_false; *tl = nfsrv_nfs_true; free((caddr_t)rbuf, M_TEMP); - free((caddr_t)cookies, M_TEMP); error = 0; goto nfsmout; } @@ -2883,29 +2871,6 @@ cpos = rbuf; cend = rbuf + siz; dp = (struct dirent *)cpos; - cookiep = cookies; - /* - * For some reason FreeBSD's ufs_readdir() chooses to back the - * directory offset up to a block boundary, so it is necessary to - * skip over the records that precede the requested offset. This - * requires the assumption that file offset cookies monotonically - * increase. - * Since the offset cookies don't monotonically increase for ZFS, - * this is not done when ZFS is the file system. - */ - while (cpos < cend && ncookies > 0 && - (dp->d_fileno == 0 || dp->d_type == DT_WHT || - (not_zfs != 0 && ((u_quad_t)(*cookiep)) <= toff))) { - cpos += dp->d_reclen; - dp = (struct dirent *)cpos; - cookiep++; - ncookies--; - } - if (cpos >= cend || ncookies == 0) { - toff = off; - siz = fullsiz; - goto again; - } len = 3 * NFSX_UNSIGNED; /* paranoia, probably can be 0 */ nfsm_reply(NFSX_POSTOPATTR(v3) + NFSX_COOKIEVERF(v3) + siz); @@ -2919,7 +2884,7 @@ be = bp + M_TRAILINGSPACE(mp); /* Loop through the records and build reply */ - while (cpos < cend && ncookies > 0) { + while (cpos < cend) { if (dp->d_fileno != 0 && dp->d_type != DT_WHT) { nlen = dp->d_namlen; rem = nfsm_rndup(nlen) - nlen; @@ -2937,15 +2902,15 @@ nfsm_clget; *tl = nfsrv_nfs_true; bp += NFSX_UNSIGNED; + nfsm_clget; if (v3) { - nfsm_clget; - *tl = 0; + txdr_hyper(dp->d_fileno, tl); + bp += 2 * NFSX_UNSIGNED; + } else { + *tl = txdr_unsigned(dp->d_fileno); bp += NFSX_UNSIGNED; } nfsm_clget; - *tl = txdr_unsigned(dp->d_fileno); - bp += NFSX_UNSIGNED; - nfsm_clget; *tl = txdr_unsigned(nlen); bp += NFSX_UNSIGNED; @@ -2971,17 +2936,16 @@ /* Finish off the record */ if (v3) { - *tl = 0; - bp += NFSX_UNSIGNED; + txdr_hyper(dp->d_off, tl); + bp += 2 * NFSX_UNSIGNED; nfsm_clget; + } else { + *tl = txdr_unsigned(dp->d_off); + bp += NFSX_UNSIGNED; } - *tl = txdr_unsigned(*cookiep); - bp += NFSX_UNSIGNED; } cpos += dp->d_reclen; dp = (struct dirent *)cpos; - cookiep++; - ncookies--; } vrele(vp); vp = NULL; @@ -3000,7 +2964,6 @@ } else mp->m_len += bp - bpos; free((caddr_t)rbuf, M_TEMP); - free((caddr_t)cookies, M_TEMP); nfsmout: if (vp) @@ -3035,14 +2998,12 @@ struct nfs_fattr *fp; int len, nlen, rem, xfer, tsiz, i, error = 0, error1, getret = 1; int vp_locked; - int siz, cnt, fullsiz, eofflag, rdonly, dirlen, ncookies; + int siz, cnt, fullsiz, eofflag, rdonly, dirlen; u_quad_t off, toff, verf; - u_long *cookies = NULL, *cookiep; /* needs to be int64_t or off_t */ int v3 = (nfsd->nd_flag & ND_NFSV3); int usevget = 1, vfslocked; struct componentname cn; struct mount *mntp = NULL; - int not_zfs; nfsdbprintf(("%s %d\n", __FILE__, __LINE__)); vfslocked = 0; @@ -3103,11 +3064,9 @@ error = 0; goto nfsmout; } - not_zfs = strcmp(vp->v_mount->mnt_vfc->vfc_name, "zfs") != 0; VOP_UNLOCK(vp, 0); vp_locked = 0; rbuf = malloc(siz, M_TEMP, M_WAITOK); -again: iv.iov_base = rbuf; iv.iov_len = fullsiz; io.uio_iov = &iv; @@ -3119,25 +3078,17 @@ io.uio_td = NULL; eofflag = 0; vp_locked = 1; - if (cookies) { - free((caddr_t)cookies, M_TEMP); - cookies = NULL; - } vn_lock(vp, LK_SHARED | LK_RETRY); - error = VOP_READDIR(vp, &io, cred, &eofflag, &ncookies, &cookies); + error = VOP_READDIR(vp, &io, cred, &eofflag); off = (u_quad_t)io.uio_offset; getret = VOP_GETATTR(vp, &at, cred); VOP_UNLOCK(vp, 0); vp_locked = 0; - if (!cookies && !error) - error = NFSERR_PERM; if (!error) error = getret; if (error) { vrele(vp); vp = NULL; - if (cookies) - free((caddr_t)cookies, M_TEMP); free((caddr_t)rbuf, M_TEMP); nfsm_reply(NFSX_V3POSTOPATTR); nfsm_srvpostop_attr(getret, &at); @@ -3162,7 +3113,6 @@ tl += 2; *tl++ = nfsrv_nfs_false; *tl = nfsrv_nfs_true; - free((caddr_t)cookies, M_TEMP); free((caddr_t)rbuf, M_TEMP); error = 0; goto nfsmout; @@ -3176,29 +3126,6 @@ cpos = rbuf; cend = rbuf + siz; dp = (struct dirent *)cpos; - cookiep = cookies; - /* - * For some reason FreeBSD's ufs_readdir() chooses to back the - * directory offset up to a block boundary, so it is necessary to - * skip over the records that precede the requested offset. This - * requires the assumption that file offset cookies monotonically - * increase. - * Since the offset cookies don't monotonically increase for ZFS, - * this is not done when ZFS is the file system. - */ - while (cpos < cend && ncookies > 0 && - (dp->d_fileno == 0 || dp->d_type == DT_WHT || - (not_zfs != 0 && ((u_quad_t)(*cookiep)) <= toff))) { - cpos += dp->d_reclen; - dp = (struct dirent *)cpos; - cookiep++; - ncookies--; - } - if (cpos >= cend || ncookies == 0) { - toff = off; - siz = fullsiz; - goto again; - } dirlen = len = NFSX_V3POSTOPATTR + NFSX_V3COOKIEVERF + 2 * NFSX_UNSIGNED; @@ -3211,7 +3138,7 @@ be = bp + M_TRAILINGSPACE(mp); /* Loop through the records and build reply */ - while (cpos < cend && ncookies > 0) { + while (cpos < cend) { if (dp->d_fileno != 0 && dp->d_type != DT_WHT) { nlen = dp->d_namlen; rem = nfsm_rndup(nlen)-nlen; @@ -3298,18 +3225,14 @@ fl.fl_fhsize = txdr_unsigned(NFSX_V3FH); fl.fl_fhok = nfsrv_nfs_true; fl.fl_postopok = nfsrv_nfs_true; - fl.fl_off.nfsuquad[0] = 0; - fl.fl_off.nfsuquad[1] = txdr_unsigned(*cookiep); + txdr_hyper(dp->d_off, &fl.fl_off); nfsm_clget; *tl = nfsrv_nfs_true; bp += NFSX_UNSIGNED; nfsm_clget; - *tl = 0; - bp += NFSX_UNSIGNED; - nfsm_clget; - *tl = txdr_unsigned(dp->d_fileno); - bp += NFSX_UNSIGNED; + txdr_hyper(dp->d_fileno, tl); + bp += 2 * NFSX_UNSIGNED; nfsm_clget; *tl = txdr_unsigned(nlen); bp += NFSX_UNSIGNED; @@ -3354,8 +3277,6 @@ invalid: cpos += dp->d_reclen; dp = (struct dirent *)cpos; - cookiep++; - ncookies--; } if (!usevget && vp_locked) vput(vp); @@ -3376,7 +3297,6 @@ mp->m_len = bp - mtod(mp, caddr_t); } else mp->m_len += bp - bpos; - free((caddr_t)cookies, M_TEMP); free((caddr_t)rbuf, M_TEMP); nfsmout: if (vp) From owner-svn-soc-all@FreeBSD.ORG Fri Jul 8 15:49:53 2011 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 89038106566C for ; Fri, 8 Jul 2011 15:49:51 +0000 (UTC) (envelope-from gk@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Fri, 08 Jul 2011 15:49:51 +0000 Date: Fri, 08 Jul 2011 15:49:51 +0000 From: gk@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20110708154951.89038106566C@hub.freebsd.org> Cc: Subject: socsvn commit: r224051 - soc2011/gk/ino64-head/tools/regression/readdir-lint X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Jul 2011 15:49:53 -0000 Author: gk Date: Fri Jul 8 15:49:51 2011 New Revision: 224051 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=224051 Log: Update readdir-lint, support building on old systems without dirent.d_off Modified: soc2011/gk/ino64-head/tools/regression/readdir-lint/Makefile soc2011/gk/ino64-head/tools/regression/readdir-lint/readdir-lint.c Modified: soc2011/gk/ino64-head/tools/regression/readdir-lint/Makefile ============================================================================== --- soc2011/gk/ino64-head/tools/regression/readdir-lint/Makefile Fri Jul 8 15:49:39 2011 (r224050) +++ soc2011/gk/ino64-head/tools/regression/readdir-lint/Makefile Fri Jul 8 15:49:51 2011 (r224051) @@ -4,6 +4,10 @@ PROG= readdir-lint NO_MAN= -DEBUG_FLAGS= -O0 -g -I${.CURDIR}/../../../sys +NO_WERROR= +DEBUG_FLAGS= -O0 -g -I/usr/src/sys + +# disable dirent.d_off +# CFLAGS+= -DNO_DIRENT_OFF .include Modified: soc2011/gk/ino64-head/tools/regression/readdir-lint/readdir-lint.c ============================================================================== --- soc2011/gk/ino64-head/tools/regression/readdir-lint/readdir-lint.c Fri Jul 8 15:49:39 2011 (r224050) +++ soc2011/gk/ino64-head/tools/regression/readdir-lint/readdir-lint.c Fri Jul 8 15:49:51 2011 (r224051) @@ -40,21 +40,26 @@ #define HAVE_GETPROGNAME #endif +#ifdef NO_DIRENT_OFF +#define d_off d_fileno +#endif + #define DIRSIZE_MAX (4*1024*1024) #define DIRSIZE_ENTRY (sizeof(struct dirent)) #define DIRSIZE_MIN ((sizeof (struct dirent) - (MAXNAMLEN+1)) + 4) #define DIRSIZE_BLOCK 512 #define DIRSIZE_PAGE 4096 -#define DIRENT_MAX 512 +#define DIRENT_HDRSIZE (sizeof(struct dirent) - MAXNAMLEN - 1) #define DP_NEXT(a) ((struct dirent *)(((char *)(a)) + a->d_reclen)) +#define WARN_NOISE 10 #define WARNX(var, fmt, ...) \ do { \ - if ((var) == 0) { \ + if ((var) < WARN_NOISE) { \ printf(fmt "\n", ## __VA_ARGS__ ); \ - var = 1; \ + var++; \ } \ } while (0) @@ -64,12 +69,16 @@ #ifdef HAVE_DIRENT_NAMLEN static int warn_nameterm; +static int warn_namelen; #endif -static int warn_noerr; +#ifndef NO_DIRENT_OFF static int warn_seekoff; -static int warn_zeroino; static int warn_zerooff; +#endif +static int warn_noerr; +static int warn_zeroino; static int warn_reclen; +static int warn_overflow; struct dirbuf { struct dirent *dp, *begin, *end; @@ -115,9 +124,11 @@ off_t seekoff; int rv; + memset(dir->begin, 0xAA, dir->bufsize); rv = getdirentries(dir->fd, (char *)dir->begin, dir->bufsize, &dir->base); if (opt_verbose >= 3) - printf("dir_read %d: len=%d base=%ld\n", dir->fd, rv, dir->base); + printf("dir_read %d: len=%d base=%ld\n", + dir->fd, rv, dir->base); if (rv == -1) return (rv); if (rv == 0) { @@ -125,36 +136,61 @@ dir->dp = NULL; dir->end = NULL; } else { + if (rv > (int)dir->bufsize) + WARNX(warn_overflow, "Buffer overflow: buffer size %zd," + " %d bytes written", dir->bufsize, rv); dir->dp = dir->begin; dir->end = (struct dirent *)((char *)dir->begin + rv); seekoff = dir_offset(dir); for (di = dir->dp; di < dir->end; di = DP_NEXT(di)) { if (di->d_reclen <= 0 || di->d_reclen > (char *)dir->end - (char *)di) { - WARNX(warn_reclen, "Invalid entry size: %d", di->d_reclen); - dir->end = di; - break; + WARNX(warn_reclen, "Invalid entry size: %d, " + "space left %d: d_fileno=%ju d_off=%08jx", + di->d_reclen, + (int)((char *)dir->end - (char *)di), + (uintmax_t)di->d_fileno, + (uintmax_t)di->d_off); + if (di->d_reclen <= 0) { + rv -= (char *)dir->end - (char *)di; + dir->end = di; + break; + } + + di->d_reclen = (char *)dir->end - (char *)di; } #ifdef HAVE_DIRENT_NAMLEN - if (di->d_namlen > MAXNAMLEN) - errx(1, "Ivalid name lenghth: %d", di->d_namlen); + if (di->d_namlen > MAXNAMLEN || di->d_namlen >= + di->d_reclen - DIRENT_HDRSIZE) + WARNX(warn_namelen, "Ivalid name length: %d " + "(reclen %d, max %d)", + di->d_namlen, di->d_reclen, + di->d_reclen - (int)DIRENT_HDRSIZE); if (di->d_name[di->d_namlen] != '\0') { di->d_name[di->d_namlen] = '\0'; - WARNX(warn_nameterm, "Entry names are not NUL-terminated"); + WARNX(warn_nameterm, + "Entry names are not NUL-terminated"); } #else #endif if (di->d_fileno == 0) { - WARNX(warn_zeroino, "Zero d_fileno: %08jx %s", - (uintmax_t)di->d_off, di->d_name); + WARNX(warn_zeroino, + "Zero d_fileno: 0x%08jx #%ju %s", + (uintmax_t)di->d_off, + (uintmax_t)di->d_fileno, di->d_name); } +#ifndef NO_DIRENT_OFF if (di->d_off == 0) - WARNX(warn_zerooff, "Zero d_off: %ju %s", + WARNX(warn_zerooff, + "Zero d_off: 0x%08jx #%ju %s", + (uintmax_t)di->d_off, (uintmax_t)di->d_fileno, di->d_name); if (DP_NEXT(di) >= dir->end && di->d_off != seekoff) { - WARNX(warn_seekoff, "Directory(%zd) and last entry offsets mismatch: %ju -- %ju", - dir->bufsize, (uintmax_t)seekoff, (uintmax_t)di->d_off); + WARNX(warn_seekoff, "Directory and last " + "entry offsets mismatch: %08jx -- %08jx", + (uintmax_t)seekoff, (uintmax_t)di->d_off); } +#endif } } @@ -196,6 +232,9 @@ int rv; rv = lseek(dir->fd, off, SEEK_SET); + if (opt_verbose >= 3) + printf("dir_seek %d: offset 0x%08jx, result %d\n", + dir->fd, (uintmax_t)off, rv); if (rv == -1) err(3, "seek(%jd, SEEK_SET)", (uintmax_t)off); dir->dp = NULL; @@ -213,19 +252,27 @@ dp2 = dir2->dp; if (dir1->eof != dir2->eof) - errx(3, "Invalid EOF: %d %ld -- %d %ld", + errx(3, "Invalid EOF: %d base: 0x%08lx -- %d base: 0x%08lx", dir1->eof, dir1->base, dir2->eof, dir2->base); else if (dir1->eof) return (1); if (opt_verbose >= 2) - printf(" %08jx (%d bytes) %-12s -- %08jx (%d bytes) %-12s\n", - (uintmax_t)dp1->d_off, dp1->d_reclen, dp1->d_name, - (uintmax_t)dp2->d_off, dp2->d_reclen, dp2->d_name); + printf(" 0x%08jx #%-8ju %-12s (reclen %d) -- " + "0x%08jx #%-8ju %-12s (reclen %d)\n", + (uintmax_t)dp1->d_off, (uintmax_t)dp1->d_fileno, + dp1->d_name, dp1->d_reclen, + (uintmax_t)dp2->d_off, (uintmax_t)dp2->d_fileno, + dp2->d_name, dp2->d_reclen); if (strcmp(dp1->d_name, dp2->d_name) != 0 || - dp1->d_off != dp2->d_off) - printf("Entries mismatch: %08jx (%d bytes) %-12s -- %08jx (%d bytes) %-12s\n", - (uintmax_t)dp1->d_off, dp1->d_reclen, dp1->d_name, - (uintmax_t)dp2->d_off, dp2->d_reclen, dp2->d_name); + dp1->d_fileno != dp2->d_fileno || + dp1->d_off != dp2->d_off) { + printf("Entries mismatch: 0x%08jx #%-8ju %-12s (reclen %d) " + "-- 0x%08jx #%-8ju %-12s (reclen %d)\n", + (uintmax_t)dp1->d_off, (uintmax_t)dp1->d_fileno, + dp1->d_name, dp1->d_reclen, + (uintmax_t)dp2->d_off, (uintmax_t)dp2->d_fileno, + dp2->d_name, dp2->d_reclen); + } return (0); } @@ -266,31 +313,44 @@ } static void -test_minbufsize(struct dirbuf *dir_expect, struct dirbuf *dir) +test_minbufsize(struct dirbuf *dir_expect, struct dirbuf *dir, int fuzzy) { - int len; + off_t prevoff; + int len, cnt; if (opt_skip > 0) { opt_skip--; return; } - printf("Test minimal buffer size\n"); + printf("Test minimal buffer size (fuzzy %d)\n", fuzzy); dir_init(dir, opt_path, DIRSIZE_ENTRY); dir_seek(dir_expect, 0); dir_read(dir_expect); + cnt = 0; while(!dir_expect->eof) { - off_t prevoff = dir_offset(dir); - + cnt++; +#ifndef NO_DIRENT_OFF + if (fuzzy >= 2 && cnt % fuzzy == 0) { + dir_seek(dir, dir_expect->dp->d_off); + dir_next(dir_expect); + continue; + } +#endif + prevoff = dir_offset(dir); for (dir->bufsize = DIRSIZE_MIN; dir->bufsize <= DIRSIZE_ENTRY; dir->bufsize += 4) { len = dir_readx(dir); if (len <= 0) { if (prevoff != dir_offset(dir)) - errx(2, "Directory offset changed but no data read: %jd %jd", - (uintmax_t)prevoff, (uintmax_t)dir_offset(dir)); + errx(2, "Directory offset changed but " + "no data read: 0x%08jx 0x%08jx", + (uintmax_t)prevoff, + (uintmax_t)dir_offset(dir)); if (len == 0) { - WARNX(warn_noerr, "EINVAL expected for small buffer read, 0 byte result"); + WARNX(warn_noerr, + "EINVAL expected for small buffer " + "read, 0 byte result"); continue; } if (errno == EINVAL) @@ -298,20 +358,25 @@ err(1, "Directory read"); } if (opt_verbose >= 1) - printf(" min size %08jx (%d of %zd bytes) %s\n", - (uintmax_t)dir->dp->d_off, dir->dp->d_reclen, dir->bufsize, - dir->dp->d_name); + printf(" min size: 0x%08jx #%-8ju %s " + "(buffer: %d of %zd bytes)\n", + (uintmax_t)dir->dp->d_off, + (uintmax_t)dir->dp->d_fileno, + dir->dp->d_name, + dir->dp->d_reclen, dir->bufsize); break; } if (dir->bufsize > DIRSIZE_ENTRY) { - errx(2, "Couldn't read entry at offset %jd", + errx(2, "Couldn't read entry at offset 0x%08jx", (uintmax_t)dir_offset(dir)); } dir->eof = 0; if (dir_cmpent(dir_expect, dir) != 0) break; +#ifndef NO_DIRENT_OFF + dir_seek(dir, dir_expect->dp->d_off); +#endif dir_next(dir_expect); - dir_seek(dir, dir->dp->d_off); } dir_destroy(dir); } @@ -363,7 +428,11 @@ errx(1, "Directory is too large"); test_bufsize(&dir_max, &dir_i); - test_minbufsize(&dir_max, &dir_i); + test_minbufsize(&dir_max, &dir_i, 0); +#ifndef NO_DIRENT_OFF + test_minbufsize(&dir_max, &dir_i, 2); + test_minbufsize(&dir_max, &dir_i, 5); +#endif return (0); } From owner-svn-soc-all@FreeBSD.ORG Fri Jul 8 17:55:59 2011 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id DDE7C106566B for ; Fri, 8 Jul 2011 17:55:56 +0000 (UTC) (envelope-from oleksandr@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Fri, 08 Jul 2011 17:55:56 +0000 Date: Fri, 08 Jul 2011 17:55:56 +0000 From: oleksandr@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20110708175556.DDE7C106566B@hub.freebsd.org> Cc: Subject: socsvn commit: r224053 - soc2011/oleksandr/oleksandr-head/head/sys/dev/usb/storage X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Jul 2011 17:55:59 -0000 Author: oleksandr Date: Fri Jul 8 17:55:56 2011 New Revision: 224053 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=224053 Log: Variable status_test for testing in ata driver Modified: soc2011/oleksandr/oleksandr-head/head/sys/dev/usb/storage/umass.c Modified: soc2011/oleksandr/oleksandr-head/head/sys/dev/usb/storage/umass.c ============================================================================== --- soc2011/oleksandr/oleksandr-head/head/sys/dev/usb/storage/umass.c Fri Jul 8 16:30:54 2011 (r224052) +++ soc2011/oleksandr/oleksandr-head/head/sys/dev/usb/storage/umass.c Fri Jul 8 17:55:56 2011 (r224053) @@ -2550,10 +2550,10 @@ uint8_t status) { ccb->csio.resid = residue; - switch (status) { case STATUS_CMD_OK: ccb->ccb_h.status = CAM_REQ_CMP; + ccb->ccb_h.status_test = CAM_REQ_CMP_ERR; if ((sc->sc_quirks & READ_CAPACITY_OFFBY1) && (ccb->ccb_h.func_code == XPT_SCSI_IO) && (ccb->csio.cdb_io.cdb_bytes[0] == READ_CAPACITY)) { From owner-svn-soc-all@FreeBSD.ORG Fri Jul 8 18:05:06 2011 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 7470C1065672 for ; Fri, 8 Jul 2011 18:05:05 +0000 (UTC) (envelope-from oleksandr@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Fri, 08 Jul 2011 18:05:05 +0000 Date: Fri, 08 Jul 2011 18:05:05 +0000 From: oleksandr@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20110708180505.7470C1065672@hub.freebsd.org> Cc: Subject: socsvn commit: r224055 - soc2011/oleksandr/oleksandr-head/head/sys/dev/usb/storage X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Jul 2011 18:05:06 -0000 Author: oleksandr Date: Fri Jul 8 18:05:05 2011 New Revision: 224055 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=224055 Log: Sorry, I was wrong, variable status_test in umass driver Modified: soc2011/oleksandr/oleksandr-head/head/sys/dev/usb/storage/umass.c Modified: soc2011/oleksandr/oleksandr-head/head/sys/dev/usb/storage/umass.c ============================================================================== --- soc2011/oleksandr/oleksandr-head/head/sys/dev/usb/storage/umass.c Fri Jul 8 17:45:38 2011 (r224054) +++ soc2011/oleksandr/oleksandr-head/head/sys/dev/usb/storage/umass.c Fri Jul 8 18:05:05 2011 (r224055) @@ -2553,7 +2553,6 @@ switch (status) { case STATUS_CMD_OK: ccb->ccb_h.status = CAM_REQ_CMP; - ccb->ccb_h.status_test = CAM_REQ_CMP_ERR; if ((sc->sc_quirks & READ_CAPACITY_OFFBY1) && (ccb->ccb_h.func_code == XPT_SCSI_IO) && (ccb->csio.cdb_io.cdb_bytes[0] == READ_CAPACITY)) { @@ -2564,6 +2563,7 @@ maxsector = scsi_4btoul(rcap->addr) - 1; scsi_ulto4b(maxsector, rcap->addr); } + ccb->ccb_h.status_test = CAM_REQ_CMP_ERR; /* * We have to add SVPD_UNIT_SERIAL_NUMBER to the list * of pages supported by the device - otherwise, CAM From owner-svn-soc-all@FreeBSD.ORG Fri Jul 8 18:06:55 2011 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 97EA2106564A for ; Fri, 8 Jul 2011 18:06:53 +0000 (UTC) (envelope-from oleksandr@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Fri, 08 Jul 2011 18:06:53 +0000 Date: Fri, 08 Jul 2011 18:06:53 +0000 From: oleksandr@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20110708180653.97EA2106564A@hub.freebsd.org> Cc: Subject: socsvn commit: r224056 - soc2011/oleksandr/oleksandr-head/head/sys/dev/ata X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Jul 2011 18:06:55 -0000 Author: oleksandr Date: Fri Jul 8 18:06:53 2011 New Revision: 224056 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=224056 Log: Variable status_test for testing in ata driver Modified: soc2011/oleksandr/oleksandr-head/head/sys/dev/ata/ata-all.c Modified: soc2011/oleksandr/oleksandr-head/head/sys/dev/ata/ata-all.c ============================================================================== --- soc2011/oleksandr/oleksandr-head/head/sys/dev/ata/ata-all.c Fri Jul 8 18:05:05 2011 (r224055) +++ soc2011/oleksandr/oleksandr-head/head/sys/dev/ata/ata-all.c Fri Jul 8 18:06:53 2011 (r224056) @@ -1553,7 +1553,7 @@ struct ata_channel *ch = device_get_softc(dev); union ccb *ccb = request->ccb; int fatalerr = 0; - + ccb->ccb_h.status_test=CAM_REQ_INVALID; if (ch->requestsense) { ata_cam_process_sense(dev, request); return; From owner-svn-soc-all@FreeBSD.ORG Fri Jul 8 19:08:45 2011 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 0C31E106566C for ; Fri, 8 Jul 2011 19:08:43 +0000 (UTC) (envelope-from rudot@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Fri, 08 Jul 2011 19:08:43 +0000 Date: Fri, 08 Jul 2011 19:08:43 +0000 From: rudot@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20110708190843.0C31E106566C@hub.freebsd.org> Cc: Subject: socsvn commit: r224057 - soc2011/rudot/kern X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Jul 2011 19:08:45 -0000 Author: rudot Date: Fri Jul 8 19:08:42 2011 New Revision: 224057 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=224057 Log: added cpu topology information Modified: soc2011/rudot/kern/sched_fbfs.c Modified: soc2011/rudot/kern/sched_fbfs.c ============================================================================== --- soc2011/rudot/kern/sched_fbfs.c Fri Jul 8 18:06:53 2011 (r224056) +++ soc2011/rudot/kern/sched_fbfs.c Fri Jul 8 19:08:42 2011 (r224057) @@ -91,6 +91,9 @@ #endif }; +static struct cpu_group * cpu_top; +static struct cpu_group * cpu_topology[MAXCPU]; + /* flags kept in td_flags */ #define TDF_DIDRUN TDF_SCHED0 /* thread actually ran. */ #define TDF_BOUND TDF_SCHED1 /* Bound to one CPU. */ @@ -186,6 +189,15 @@ { int i; + cpu_top = smp_topo(); + for (i = 0; i < MAXCPU; i++) { + if (CPU_ABSENT(i)) + continue; + cpu_topology[i] = smp_topo_find(cpu_top, i); + if (cpu_topology[i] == NULL) + panic("Can't find cpu group for %d\n", i); + } + realstathz = hz; sched_slice = (realstathz/10); @@ -609,7 +621,7 @@ pcpu = pcpu_find(c); if (pcpu->pc_curthread == pcpu->pc_idlethread) { if (PCPU_GET(cpuid) != c) - ipi_cpu(c, IPI_AST); + ipi_cpu(c, IPI_PREEMPT); return (1); } cpri = pcpu->pc_curthread->td_priority; @@ -676,6 +688,7 @@ { struct td_sched *ts; struct thread *thr_worst; + struct cpu_group *cg; cpumask_t dontuse, map, me; u_char c; @@ -696,16 +709,26 @@ */ if (preempt_lastcpu(td)) { if (map) - ipi_selected(map, IPI_AST); + ipi_selected(map, IPI_PREEMPT); return; } - + /* + * Is there any idle cpu ? + */ if (map) { - ipi_selected(map, IPI_AST); + cg = cpu_topology[td->td_lastcpu]; + while ((cg != NULL) && ((map & cg->cg_mask) == 0)) + cg = cg->cg_parent; + if (map & cg->cg_mask) { + ipi_selected(map & cg->cg_mask, IPI_PREEMPT); + return; + } + ipi_selected(map, IPI_PREEMPT); return; } - - /* We did not wake lastcpu and there is no suitable idle cpu */ + /* + * We did not wake lastcpu and there is no suitable idle cpu + */ thr_worst = worst_running_thread(); c = thr_worst->td_oncpu; if (thr_worst->td_priority < td->td_priority) @@ -716,8 +739,9 @@ ipi_cpu(c, IPI_AST); return; } - - /* thr_worst->td_priority == td->td_priority */ + /* + * thr_worst->td_priority == td->td_priority + */ if (ts->ts_vdeadline < thr_worst->td_sched->ts_vdeadline) { thr_worst->td_flags |= TDF_NEEDRESCHED; if ((thr_worst != curthread) && (c != NOCPU)) From owner-svn-soc-all@FreeBSD.ORG Fri Jul 8 21:41:14 2011 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 528B2106564A for ; Fri, 8 Jul 2011 21:41:12 +0000 (UTC) (envelope-from oleksandr@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Fri, 08 Jul 2011 21:41:12 +0000 Date: Fri, 08 Jul 2011 21:41:12 +0000 From: oleksandr@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20110708214112.528B2106564A@hub.freebsd.org> Cc: Subject: socsvn commit: r224060 - soc2011/oleksandr/oleksandr-head/head/sys/kern X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Jul 2011 21:41:14 -0000 Author: oleksandr Date: Fri Jul 8 21:41:12 2011 New Revision: 224060 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=224060 Log: Added new function in devstat for record error Modified: soc2011/oleksandr/oleksandr-head/head/sys/kern/subr_devstat.c Modified: soc2011/oleksandr/oleksandr-head/head/sys/kern/subr_devstat.c ============================================================================== --- soc2011/oleksandr/oleksandr-head/head/sys/kern/subr_devstat.c Fri Jul 8 20:41:12 2011 (r224059) +++ soc2011/oleksandr/oleksandr-head/head/sys/kern/subr_devstat.c Fri Jul 8 21:41:12 2011 (r224060) @@ -201,7 +201,31 @@ devstat_generation++; mtx_unlock(&devstat_mutex); } - +/* + * Search in the devstat desired structure. + */ +struct devstat * +devstat_search(const char *dev_name, u_int32_t unit_number) +{ + struct devstatlist *devstat_head; + struct devstat *dv_error; + mtx_assert(&devstat_mutex, MA_NOTOWNED); + int status_match = 0; + devstat_head = &device_statq; + if (STAILQ_EMPTY(&device_statq)==0) { + STAILQ_FOREACH(dv_error, devstat_head, dev_links) { + if ((strcmp(dev_name,dv_error->device_name)==0)&& + (unit_number==dv_error->unit_number)) { + status_match=1; + break; + } + } + } + if (status_match) { + return (dv_error); + } else + return NULL; +} /* * Record a transaction start. * @@ -340,9 +364,20 @@ devstat_end_transaction(ds, bp->bio_bcount - bp->bio_resid, DEVSTAT_TAG_SIMPLE, flg, NULL, &bp->bio_t0); } - +/* + * Increase indications counter by unit. + */ +void +devstat_add_error(struct devstat *ds, devstat_error_flags error_flag) +{ + if (error_flag==DEVSTAT_ERROR_RETRIABLE) + ds->dev_error.retriable++; + if (error_flag==DEVSTAT_ERROR_NON_RETRIABLE) + ds->dev_error.non_retriable++; +} /* * This is the sysctl handler for the devstat package. The data pushed out + * on the kern.devstat.all sysctl variable consists of the current devstat * generation number, and then an array of devstat structures, one for each * device in the system. From owner-svn-soc-all@FreeBSD.ORG Fri Jul 8 21:44:23 2011 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 8E18B106566C for ; Fri, 8 Jul 2011 21:44:21 +0000 (UTC) (envelope-from oleksandr@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Fri, 08 Jul 2011 21:44:21 +0000 Date: Fri, 08 Jul 2011 21:44:21 +0000 From: oleksandr@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20110708214421.8E18B106566C@hub.freebsd.org> Cc: Subject: socsvn commit: r224061 - soc2011/oleksandr/oleksandr-head/head/sys/sys X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Jul 2011 21:44:23 -0000 Author: oleksandr Date: Fri Jul 8 21:44:21 2011 New Revision: 224061 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=224061 Log: Added new structure in header file for record error Modified: soc2011/oleksandr/oleksandr-head/head/sys/sys/devicestat.h Modified: soc2011/oleksandr/oleksandr-head/head/sys/sys/devicestat.h ============================================================================== --- soc2011/oleksandr/oleksandr-head/head/sys/sys/devicestat.h Fri Jul 8 21:41:12 2011 (r224060) +++ soc2011/oleksandr/oleksandr-head/head/sys/sys/devicestat.h Fri Jul 8 21:44:21 2011 (r224061) @@ -94,7 +94,13 @@ DEVSTAT_PRIORITY_ARRAY = 0x120, DEVSTAT_PRIORITY_MAX = 0xfff } devstat_priority; - +/* + * These flags indicates the type of disk error. + */ +typedef enum { + DEVSTAT_ERROR_RETRIABLE = 0x01, + DEVSTAT_ERROR_NON_RETRIABLE = 0x02 +} devstat_error_flags; /* * These types are intended to aid statistics gathering/display programs. * The first 13 types (up to the 'target' flag) are identical numerically @@ -128,7 +134,13 @@ DEVSTAT_TYPE_IF_MASK = 0x0f0, DEVSTAT_TYPE_PASS = 0x100 } devstat_type_flags; - +/* + * The structure that contains the disk errors counter. + */ +struct devstat_device_error { + int retriable; + int non_retriable; +}; /* * XXX: Next revision should add * off_t offset[DEVSTAT_N_TRANS_FLAGS]; @@ -159,6 +171,7 @@ * Time the device was * created. */ + struct devstat_device_error dev_error; /* Disk error structure.*/ u_int32_t block_size; /* Block size, bytes */ u_int64_t tag_types[3]; /* * The number of @@ -190,7 +203,7 @@ devstat_support_flags flags, devstat_type_flags device_type, devstat_priority priority); - +struct devstat *devstat_search(const char *dev_name, u_int32_t unit_namber); void devstat_remove_entry(struct devstat *ds); void devstat_start_transaction(struct devstat *ds, struct bintime *now); void devstat_start_transaction_bio(struct devstat *ds, struct bio *bp); @@ -199,6 +212,7 @@ devstat_trans_flags flags, struct bintime *now, struct bintime *then); void devstat_end_transaction_bio(struct devstat *ds, struct bio *bp); +void devstat_add_error(struct devstat *ds, devstat_error_flags error_flag); #endif #endif /* _DEVICESTAT_H */ From owner-svn-soc-all@FreeBSD.ORG Fri Jul 8 21:49:17 2011 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id A78461065670 for ; Fri, 8 Jul 2011 21:49:15 +0000 (UTC) (envelope-from oleksandr@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Fri, 08 Jul 2011 21:49:15 +0000 Date: Fri, 08 Jul 2011 21:49:15 +0000 From: oleksandr@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20110708214915.A78461065670@hub.freebsd.org> Cc: Subject: socsvn commit: r224062 - soc2011/oleksandr/oleksandr-head/head/sys/cam X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Jul 2011 21:49:17 -0000 Author: oleksandr Date: Fri Jul 8 21:49:15 2011 New Revision: 224062 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=224062 Log: Identification type of errors and increased the counter in devstat Modified: soc2011/oleksandr/oleksandr-head/head/sys/cam/cam_ccb.h soc2011/oleksandr/oleksandr-head/head/sys/cam/cam_xpt.c Modified: soc2011/oleksandr/oleksandr-head/head/sys/cam/cam_ccb.h ============================================================================== --- soc2011/oleksandr/oleksandr-head/head/sys/cam/cam_ccb.h Fri Jul 8 21:44:21 2011 (r224061) +++ soc2011/oleksandr/oleksandr-head/head/sys/cam/cam_ccb.h Fri Jul 8 21:49:15 2011 (r224062) @@ -304,6 +304,7 @@ /* Callback on completion function */ xpt_opcode func_code; /* XPT function code */ u_int32_t status; /* Status returned by CAM subsystem */ + u_int32_t status_test; /* CAM status for test disk error */ struct cam_path *path; /* Compiled path for this ccb */ path_id_t path_id; /* Path ID for the request */ target_id_t target_id; /* Target device ID */ Modified: soc2011/oleksandr/oleksandr-head/head/sys/cam/cam_xpt.c ============================================================================== --- soc2011/oleksandr/oleksandr-head/head/sys/cam/cam_xpt.c Fri Jul 8 21:44:21 2011 (r224061) +++ soc2011/oleksandr/oleksandr-head/head/sys/cam/cam_xpt.c Fri Jul 8 21:49:15 2011 (r224062) @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -4140,8 +4141,45 @@ xpt_done(union ccb *done_ccb) { struct cam_sim *sim; - int first; - + int first; + struct devstat *device_error; + devstat_error_flags error_flag=0; + /* + * If the error is fatal refer it to the type of non retry able. + */ + if ((done_ccb->ccb_h.status_test==CAM_REQ_CMP_ERR)|| + (done_ccb->ccb_h.status_test==CAM_TID_INVALID)|| + (done_ccb->ccb_h.status_test==CAM_SCSI_STATUS_ERROR)|| + (done_ccb->ccb_h.status_test==CAM_AUTOSENSE_FAIL)|| + (done_ccb->ccb_h.status_test==CAM_LUN_INVALID)) { + error_flag=DEVSTAT_ERROR_NON_RETRIABLE; + } + /* + * If the error is not fatal refer it to the type of retry able. + */ + if ((done_ccb->ccb_h.status_test==CAM_SEL_TIMEOUT)|| + (done_ccb->ccb_h.status_test==CAM_SCSI_BUSY)|| + (done_ccb->ccb_h.status_test==CAM_SIM_QUEUED)|| + (done_ccb->ccb_h.status_test==CAM_FUNC_NOTAVAIL)|| + (done_ccb->ccb_h.status_test==CAM_REQ_INVALID)|| + (done_ccb->ccb_h.status_test==CAM_REQUEUE_REQ)) { + error_flag=DEVSTAT_ERROR_RETRIABLE; + } + /* + * If an error is present, search for an appropriate structure + * in devstat and increase the corresponding counter of errors. + */ + if (error_flag) { + device_error= devstat_search( + done_ccb->ccb_h.path->periph->periph_name, + done_ccb->ccb_h.path->periph->unit_number); + if (device_error!=NULL) { + devstat_start_transaction(device_error, NULL); + devstat_add_error(device_error, error_flag); + devstat_end_transaction(device_error,done_ccb->csio.dxfer_len, + DEVSTAT_TAG_ORDERED,DEVSTAT_WRITE, NULL, NULL); + } + } CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("xpt_done\n")); if ((done_ccb->ccb_h.func_code & XPT_FC_QUEUED) != 0) { /* From owner-svn-soc-all@FreeBSD.ORG Fri Jul 8 23:43:08 2011 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id E35C1106566C for ; Fri, 8 Jul 2011 23:43:05 +0000 (UTC) (envelope-from shm@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Fri, 08 Jul 2011 23:43:05 +0000 Date: Fri, 08 Jul 2011 23:43:05 +0000 From: shm@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20110708234305.E35C1106566C@hub.freebsd.org> Cc: Subject: socsvn commit: r224063 - soc2011/shm/TESLA X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Jul 2011 23:43:08 -0000 Author: shm Date: Fri Jul 8 23:43:05 2011 New Revision: 224063 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=224063 Log: * merge: new building script Modified: soc2011/shm/TESLA/build_clang.sh Modified: soc2011/shm/TESLA/build_clang.sh ============================================================================== --- soc2011/shm/TESLA/build_clang.sh Fri Jul 8 21:49:15 2011 (r224062) +++ soc2011/shm/TESLA/build_clang.sh Fri Jul 8 23:43:05 2011 (r224063) @@ -1,21 +1,21 @@ #!/bin/sh -# Build our patched LLVM/CLANG -# Run from ctsrd.svn/tesla/trunk if [ ! -d llvm ]; then - git clone http://github.com/CTSRD-TESLA/llvm.git + svn co https://socsvn.freebsd.org/socsvn/soc2011/shm/llvm/ cd llvm/tools - git clone http://github.com/CTSRD-TESLA/clang + svn co https://socsvn.freebsd.org/socsvn/soc2011/shm/clang/ cd ../../ elif [ "$1" != "--no-update" ]; then + echo "Updating llvm..." cd llvm - git pull + svn update + echo "Updaring clang..." cd tools/clang - git pull + svn update cd ../../.. fi mkdir -p build cd build -cmake -j5 -DCLANG_BUILD_EXAMPLES=true ../llvm -make +cmake -j3 -DCLANG_BUILD_EXAMPLES=true -DLLVM_INCLUDE_TESTS=true ../llvm +make -j3 From owner-svn-soc-all@FreeBSD.ORG Sat Jul 9 01:20:21 2011 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 41467106564A for ; Sat, 9 Jul 2011 01:20:19 +0000 (UTC) (envelope-from shm@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Sat, 09 Jul 2011 01:20:19 +0000 Date: Sat, 09 Jul 2011 01:20:19 +0000 From: shm@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20110709012019.41467106564A@hub.freebsd.org> Cc: Subject: socsvn commit: r224064 - in soc2011/shm: TESLA/assertions/audit TESLA/assertions/mwc TESLA/examples TESLA/examples/example2 TESLA/instrumenter-tests TESLA/instrumenter-tests/tests TESLA/kernel TESL... X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 09 Jul 2011 01:20:21 -0000 Author: shm Date: Sat Jul 9 01:20:18 2011 New Revision: 224064 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=224064 Log: * merge: the great merge 1/3 Added: soc2011/shm/TESLA/examples/ soc2011/shm/TESLA/examples/example2/ soc2011/shm/TESLA/examples/example2/Makefile soc2011/shm/TESLA/examples/example2/example2.c soc2011/shm/TESLA/examples/example2/example2.spec soc2011/shm/TESLA/examples/example2/example2.spl soc2011/shm/TESLA/examples/example2/example2_assert.c soc2011/shm/TESLA/examples/example2/example2_test.h soc2011/shm/TESLA/instrumenter-tests/ soc2011/shm/TESLA/instrumenter-tests/run-tests.sh (contents, props changed) soc2011/shm/TESLA/instrumenter-tests/tests/ soc2011/shm/TESLA/instrumenter-tests/tests/dec.c soc2011/shm/TESLA/instrumenter-tests/tests/dec.ins soc2011/shm/TESLA/instrumenter-tests/tests/dec.out soc2011/shm/TESLA/instrumenter-tests/tests/double.c soc2011/shm/TESLA/instrumenter-tests/tests/double.ins soc2011/shm/TESLA/instrumenter-tests/tests/double.out soc2011/shm/TESLA/instrumenter-tests/tests/empty.c soc2011/shm/TESLA/instrumenter-tests/tests/empty.ins soc2011/shm/TESLA/instrumenter-tests/tests/empty.out soc2011/shm/TESLA/instrumenter-tests/tests/empty2.c soc2011/shm/TESLA/instrumenter-tests/tests/empty2.ins soc2011/shm/TESLA/instrumenter-tests/tests/empty2.out soc2011/shm/TESLA/instrumenter-tests/tests/field.c soc2011/shm/TESLA/instrumenter-tests/tests/field.ins soc2011/shm/TESLA/instrumenter-tests/tests/field.out soc2011/shm/TESLA/instrumenter-tests/tests/field2.c soc2011/shm/TESLA/instrumenter-tests/tests/field2.ins soc2011/shm/TESLA/instrumenter-tests/tests/field2.out soc2011/shm/TESLA/instrumenter-tests/tests/field3.c soc2011/shm/TESLA/instrumenter-tests/tests/field3.ins soc2011/shm/TESLA/instrumenter-tests/tests/for.c soc2011/shm/TESLA/instrumenter-tests/tests/for.ins soc2011/shm/TESLA/instrumenter-tests/tests/for.out soc2011/shm/TESLA/instrumenter-tests/tests/for2.c soc2011/shm/TESLA/instrumenter-tests/tests/for2.ins soc2011/shm/TESLA/instrumenter-tests/tests/for2.out soc2011/shm/TESLA/instrumenter-tests/tests/func.c soc2011/shm/TESLA/instrumenter-tests/tests/func.ins soc2011/shm/TESLA/instrumenter-tests/tests/func.out soc2011/shm/TESLA/instrumenter-tests/tests/if.c soc2011/shm/TESLA/instrumenter-tests/tests/if.ins soc2011/shm/TESLA/instrumenter-tests/tests/if.out soc2011/shm/TESLA/instrumenter-tests/tests/if2.c soc2011/shm/TESLA/instrumenter-tests/tests/if2.ins soc2011/shm/TESLA/instrumenter-tests/tests/if2.out soc2011/shm/TESLA/instrumenter-tests/tests/inc.c soc2011/shm/TESLA/instrumenter-tests/tests/inc.ins soc2011/shm/TESLA/instrumenter-tests/tests/inc.out soc2011/shm/TESLA/instrumenter-tests/tests/none.c soc2011/shm/TESLA/instrumenter-tests/tests/none.ins soc2011/shm/TESLA/instrumenter-tests/tests/none.out soc2011/shm/TESLA/instrumenter-tests/tests/not-exist.out soc2011/shm/TESLA/instrumenter-tests/tests/switch.c soc2011/shm/TESLA/instrumenter-tests/tests/switch.ins soc2011/shm/TESLA/instrumenter-tests/tests/switch.out soc2011/shm/TESLA/instrumenter-tests/tests/switch2.c soc2011/shm/TESLA/instrumenter-tests/tests/while.c soc2011/shm/TESLA/instrumenter-tests/tests/while.ins soc2011/shm/TESLA/instrumenter-tests/tests/while.out soc2011/shm/TESLA/instrumenter-tests/tests/while2.c soc2011/shm/TESLA/instrumenter-tests/tests/while2.ins soc2011/shm/TESLA/instrumenter-tests/tests/while2.out soc2011/shm/TESLA/instrumenter-tests/tests/while3.c soc2011/shm/TESLA/instrumenter-tests/tests/while3.ins soc2011/shm/TESLA/instrumenter-tests/tests/while3.out soc2011/shm/TESLA/instrumenter-tests/tests/while4.c soc2011/shm/TESLA/instrumenter-tests/tests/while4.ins soc2011/shm/TESLA/instrumenter-tests/tests/while4.out soc2011/shm/TESLA/kernel/tesla-clang-print-ast (contents, props changed) soc2011/shm/mac_test/ soc2011/shm/reports/ soc2011/shm/reports/mid-report/ Deleted: soc2011/shm/TESLA/libtesla/TODO soc2011/shm/tesla-tests/ Modified: soc2011/shm/TESLA/assertions/audit/syscalls.c soc2011/shm/TESLA/assertions/mwc/syscalls.c soc2011/shm/TESLA/assertions/mwc/syscalls.h soc2011/shm/TESLA/strawman/Makefile soc2011/shm/clang/examples/TeslaInstrumenter/Instrumentation.cpp soc2011/shm/clang/examples/TeslaInstrumenter/Instrumentation.h soc2011/shm/clang/examples/TeslaInstrumenter/TeslaInstrumenter.cpp Modified: soc2011/shm/TESLA/assertions/audit/syscalls.c ============================================================================== --- soc2011/shm/TESLA/assertions/audit/syscalls.c Fri Jul 8 23:43:05 2011 (r224063) +++ soc2011/shm/TESLA/assertions/audit/syscalls.c Sat Jul 9 01:20:18 2011 (r224064) @@ -14,8 +14,9 @@ void helper_which_asserts() { - TESLA_ASSERT(syscall) { - eventually(audit_submit()); + TESLA_ASSERT(syscall) { + 1 == 1; +// eventually(audit_submit()); } } Modified: soc2011/shm/TESLA/assertions/mwc/syscalls.c ============================================================================== --- soc2011/shm/TESLA/assertions/mwc/syscalls.c Fri Jul 8 23:43:05 2011 (r224063) +++ soc2011/shm/TESLA/assertions/mwc/syscalls.c Sat Jul 9 01:20:18 2011 (r224064) @@ -36,10 +36,13 @@ return (0); } -void +//void +int syscallret(struct thread *td, int error, struct syscall_args *sa) { - + int i; + i++; + return (0); } void Modified: soc2011/shm/TESLA/assertions/mwc/syscalls.h ============================================================================== --- soc2011/shm/TESLA/assertions/mwc/syscalls.h Fri Jul 8 23:43:05 2011 (r224063) +++ soc2011/shm/TESLA/assertions/mwc/syscalls.h Sat Jul 9 01:20:18 2011 (r224064) @@ -21,6 +21,6 @@ struct thread; struct syscall_args; int syscallenter(struct thread *td, struct syscall_args *sa); -void syscallret(struct thread *td, int error, struct syscall_args *sa); +int syscallret(struct thread *td, int error, struct syscall_args *sa); #endif /* SYSCALLS_H */ Added: soc2011/shm/TESLA/examples/example2/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/examples/example2/Makefile Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,30 @@ +SPLC ?= ../../cfa/splc +TESLA_CLANG ?= ../../kernel/tesla-clang +OPTLEVEL ?= -O0 +CC = $(TESLA_CLANG) + +CFLAGS=-Wall -g -I../.. -I. $(OPTLEVEL) + +TESLALIBS= \ + ../../libtesla/tesla_state.o \ + ../../libtesla/tesla_state_global.o \ + ../../libtesla/tesla_state_perthread.o \ + ../../libtesla/tesla_util.o + +.PHONY: all clean +all: example2 + +example2_automata.c example2_defs.h: example2.spl + $(SPLC) -t tesla -s example2 example2.spl + +example2_assert.o: example2_assert.c + $(CC) -c $(CFLAGS) -o $@ $< + +example2_automata.o: example2_automata.c example2_defs.h + $(CC) -c $(CFLAGS) -o $@ $< + +example2: example2_automata.o example2_assert.o example2.o ${TESLALIBS} + $(CC) -o $@ $^ + +clean: + rm -f example2 *.o Added: soc2011/shm/TESLA/examples/example2/example2.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/examples/example2/example2.c Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2011, Mateusz Kocielski + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include +#include +#include "example2_test.h" + +void example2_init(int); + +int +process(char **x, struct test *t) +{ + int i; + + for (i = 0; x[i]; i++) + t->state = atoi(x[i]); + + return i; +} + +int +main(int argc, char **argv) +{ + struct test t; + + if (argc < 2) + { + fprintf(stderr, "This is an example program using TEAL\n"); + fprintf(stderr, "usage: %s [state] ...\n", argv[0]); + fprintf(stderr, "\n"); + fprintf(stderr, "example usage:\n"); + fprintf(stderr, "\t%s 1 4 6\n", argv[0]); + fprintf(stderr, "\t%s 1 6 2\n", argv[0]); + return EXIT_FAILURE; + } + + example2_init(TESLA_SCOPE_GLOBAL); + + printf("Processed %d states\n", process(&argv[1], &t)); + + return EXIT_SUCCESS; +} Added: soc2011/shm/TESLA/examples/example2/example2.spec ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/examples/example2/example2.spec Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1 @@ +field_assign,struct test,state Added: soc2011/shm/TESLA/examples/example2/example2.spl ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/examples/example2/example2.spl Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,19 @@ +automaton simple_protocol() { + void main(struct test *t) { + t->state = P1; + multiple { + either { + t->state = P2; + } or { + t->state = P3; + } + } + either { + t->state = P4; + } or { + t->state = P5; + } + t->state = P6; + exit; + } +} Added: soc2011/shm/TESLA/examples/example2/example2_assert.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/examples/example2/example2_assert.c Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2011, Mateusz Kocielski + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include +#include +#include "example2_defs.h" +#include "example2_test.h" + +static struct tesla_state *example_state; + +#define EXAMPLE_LIMIT 23 +#define EXAMPLE_NAME "TEAL automata example" +#define EXAMPLE_DESC "this is just a simple example" + +void +example2_init(int scope) +{ + assert(tesla_state_new(&example_state, scope, EXAMPLE_LIMIT, EXAMPLE_NAME, + EXAMPLE_DESC) == 0); +} + +void +__tesla_event_field_assign_struct_test_state(struct test *t, u_int state) +{ + struct tesla_instance *tip; + int alloc; + int event; + printf("-> %d\n", state); + assert(tesla_instance_get1(example_state, (register_t)t, &tip, &alloc) == + 0); + + if (alloc == 1) + example2_automata_init(tip); + + switch(state) + { + case P1: + event = EXAMPLE2_EVENT_T_STATE_ASSIGN_P1; + break; + case P2: + event = EXAMPLE2_EVENT_T_STATE_ASSIGN_P2; + break; + case P3: + event = EXAMPLE2_EVENT_T_STATE_ASSIGN_P3; + break; + case P4: + event = EXAMPLE2_EVENT_T_STATE_ASSIGN_P4; + break; + case P5: + event = EXAMPLE2_EVENT_T_STATE_ASSIGN_P5; + break; + case P6: + event = EXAMPLE2_EVENT_T_STATE_ASSIGN_P6; + break; + default: + printf("UNKNOWN STATE\n"); + tesla_assert_fail(example_state, tip); + } + + if(example2_automata_prod(tip, event)) + tesla_assert_fail(example_state, tip); + + tesla_instance_put(example_state, tip); +} Added: soc2011/shm/TESLA/examples/example2/example2_test.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/examples/example2/example2_test.h Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2011, Mateusz Kocielski + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#define P1 (1) +#define P2 (2) +#define P3 (3) +#define P4 (4) +#define P5 (5) +#define P6 (6) +#define P7 (7) + +struct test { + int state; +}; Added: soc2011/shm/TESLA/instrumenter-tests/run-tests.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/run-tests.sh Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,97 @@ +#! /bin/sh +# $Id$ + +# Copyright (c) 2011, Mateusz Kocielski +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +TEST_DIR="tests/" +TEST_OUT="_test.out" +TEST_OUT_ERR="_test_err.out" + +compile_test() +{ + TESLA_ARGS="-cc1 -load TeslaInstrumenter.so -add-plugin tesla + -plugin-arg-tesla ${TEST_DIR}/${1} -ast-print" + ARGS="$TESLA_ARGS ${TEST_DIR}/${2}" + LD_LIBRARY_PATH=$(dirname $0)/../build/lib + export LD_LIBRARY_PATH + $(dirname $0)/../build/bin/clang $ARGS +} + +success_test() +{ + echo "OK" +} + +fail_test() +{ + echo "FAIL" +} + +run_test() +{ + echo -n "TEST `basename ${1} .c`: " + # compile + compile_test ${2} ${1} > ${TEST_OUT} 2> ${TEST_OUT_ERR} + if [ "$?" -ne "${4}" ]; then + fail_test + return; + fi; + + if [ ${4} -eq 1 ]; then + # special case - we expected compiler to fail + success_test + return; + fi; + + cp $TEST_OUT ${TEST_DIR}/${3} + + diff ${TEST_DIR}/${3} ${TEST_OUT} > /dev/null + + if [ "$?" -eq "${4}" ]; then + success_test + else + fail_test + fi; +} + +clean_up() +{ + rm ${TEST_OUT} ${TEST_OUT_ERR} ${TEST_DIR}/*.h +} + +run_test none.c none.ins none.out 0 +run_test not-exist.c not-exist.ins not-exist.out 1 +run_test empty.c empty.ins empty.out 0 +run_test empty2.c empty2.ins empty2.out 0 +run_test func.c func.ins func.out 0 +run_test while.c while.ins while.out 0 +run_test while2.c while2.ins while2.out 0 +run_test while3.c while3.ins while3.out 0 +run_test while4.c while4.ins while4.out 0 +run_test for.c for.ins for.out 0 +run_test for2.c for2.ins for2.out 0 +run_test inc.c inc.ins inc.out 0 +run_test dec.c dec.ins dec.out 0 +run_test switch.c switch.ins switch.out 0 +run_test if.c if.ins if.out 0 +run_test if2.c if2.ins if2.out 0 +run_test field.c field.ins field.out 0 +run_test field2.c field2.ins field2.out 0 +run_test field3.c field3.ins field3.out 0 +run_test double.c double.ins double.out 0 + +clean_up + +exit 0 Added: soc2011/shm/TESLA/instrumenter-tests/tests/dec.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/dec.c Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,10 @@ +struct test { int x; }; + +int +test(int a) +{ + struct test *c; + c->x = 1; + c->x++; + return c->x; +} Added: soc2011/shm/TESLA/instrumenter-tests/tests/dec.ins ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/dec.ins Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1 @@ +field_assign,struct test,x Added: soc2011/shm/TESLA/instrumenter-tests/tests/dec.out ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/dec.out Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,21 @@ +struct __va_list_tag { + unsigned int gp_offset; + unsigned int fp_offset; + void *overflow_arg_area; + void *reg_save_area; +}; +typedef struct __va_list_tag __va_list_tag; +struct test { + int x; +}; +int test(int a) { + struct test *c; + int __tesla_tmp_assign; + __tesla_tmp_assign = 1; + __tesla_event_field_assign_struct_test_x(c); + c->x = __tesla_tmp_assign; + c->x++; + return c->x; +} + + Added: soc2011/shm/TESLA/instrumenter-tests/tests/double.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/double.c Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,9 @@ +int test(void) +{ + if (test() != 0) + { + return 1; + } + else + return 0; +} Added: soc2011/shm/TESLA/instrumenter-tests/tests/double.ins ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/double.ins Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,2 @@ +function,test +function,test Added: soc2011/shm/TESLA/instrumenter-tests/tests/double.out ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/double.out Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,25 @@ +struct __va_list_tag { + unsigned int gp_offset; + unsigned int fp_offset; + void *overflow_arg_area; + void *reg_save_area; +}; +typedef struct __va_list_tag __va_list_tag; +int test() { + void *__tesla_data; + __tesla_event_function_prologue_test(&__tesla_data); + if (test() != 0) { + int __tesla_tmp_retval; + __tesla_tmp_retval = 1; + __tesla_event_function_return_test(&__tesla_data, __tesla_tmp_retval); + return __tesla_tmp_retval; + } else { + int __tesla_tmp_retval; + __tesla_tmp_retval = 0; + __tesla_event_function_return_test(&__tesla_data, __tesla_tmp_retval); + return __tesla_tmp_retval; + } + __tesla_event_function_return_test(&__tesla_data); +} + + Added: soc2011/shm/TESLA/instrumenter-tests/tests/empty.c ============================================================================== Added: soc2011/shm/TESLA/instrumenter-tests/tests/empty.ins ============================================================================== Added: soc2011/shm/TESLA/instrumenter-tests/tests/empty.out ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/empty.out Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,7 @@ +struct __va_list_tag { + unsigned int gp_offset; + unsigned int fp_offset; + void *overflow_arg_area; + void *reg_save_area; +}; +typedef struct __va_list_tag __va_list_tag; Added: soc2011/shm/TESLA/instrumenter-tests/tests/empty2.c ============================================================================== Added: soc2011/shm/TESLA/instrumenter-tests/tests/empty2.ins ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/empty2.ins Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,4 @@ +function,a +function,b +function,c +function,d Added: soc2011/shm/TESLA/instrumenter-tests/tests/empty2.out ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/empty2.out Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,7 @@ +struct __va_list_tag { + unsigned int gp_offset; + unsigned int fp_offset; + void *overflow_arg_area; + void *reg_save_area; +}; +typedef struct __va_list_tag __va_list_tag; Added: soc2011/shm/TESLA/instrumenter-tests/tests/field.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/field.c Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,9 @@ +struct test { int x; }; + +int test(int a) +{ + struct test *c; + + c->x = (c->x = c->x + 1) + 2; + return c->x = 2; +} Added: soc2011/shm/TESLA/instrumenter-tests/tests/field.ins ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/field.ins Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1 @@ +field_assign,struct test,x Added: soc2011/shm/TESLA/instrumenter-tests/tests/field.out ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/field.out Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,20 @@ +struct __va_list_tag { + unsigned int gp_offset; + unsigned int fp_offset; + void *overflow_arg_area; + void *reg_save_area; +}; +typedef struct __va_list_tag __va_list_tag; +struct test { + int x; +}; +int test(int a) { + struct test *c; + int __tesla_tmp_assign; + __tesla_tmp_assign = (c->x = c->x + 1) + 2; + __tesla_event_field_assign_struct_test_x(c); + c->x = __tesla_tmp_assign; + return c->x = 2; +} + + Added: soc2011/shm/TESLA/instrumenter-tests/tests/field2.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/field2.c Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,9 @@ +struct test { int x; }; + +int test(int a) +{ + struct test *c; + + c->x = c->x; + return 2; +} Added: soc2011/shm/TESLA/instrumenter-tests/tests/field2.ins ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/field2.ins Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1 @@ +field_assign,struct test,x Added: soc2011/shm/TESLA/instrumenter-tests/tests/field2.out ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/field2.out Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,20 @@ +struct __va_list_tag { + unsigned int gp_offset; + unsigned int fp_offset; + void *overflow_arg_area; + void *reg_save_area; +}; +typedef struct __va_list_tag __va_list_tag; +struct test { + int x; +}; +int test(int a) { + struct test *c; + int __tesla_tmp_assign; + __tesla_tmp_assign = c->x; + __tesla_event_field_assign_struct_test_x(c); + c->x = __tesla_tmp_assign; + return 2; +} + + Added: soc2011/shm/TESLA/instrumenter-tests/tests/field3.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/field3.c Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,10 @@ +struct test { int x; }; + +int test(int a) +{ + struct test c; + + c.x = (c.x = c.x + 1) + 2; + (&c)->x = 5; + return c.x = 2; +} Added: soc2011/shm/TESLA/instrumenter-tests/tests/field3.ins ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/field3.ins Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1 @@ +field_assign,struct test,x Added: soc2011/shm/TESLA/instrumenter-tests/tests/for.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/for.c Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,11 @@ +struct test { int x; }; + +int +test(int a) +{ + int b; + struct test *c; + while(a!=10) + c->x = a++; + return b; +} Added: soc2011/shm/TESLA/instrumenter-tests/tests/for.ins ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/for.ins Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1 @@ +field_assign,struct test,x Added: soc2011/shm/TESLA/instrumenter-tests/tests/for.out ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/for.out Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,24 @@ +struct __va_list_tag { + unsigned int gp_offset; + unsigned int fp_offset; + void *overflow_arg_area; + void *reg_save_area; +}; +typedef struct __va_list_tag __va_list_tag; +struct test { + int x; +}; +int test(int a) { + int b; + struct test *c; + while (a != 10) + { + int __tesla_tmp_assign; + __tesla_tmp_assign = a++; + __tesla_event_field_assign_struct_test_x(c); + c->x = __tesla_tmp_assign; + } + return b; +} + + Added: soc2011/shm/TESLA/instrumenter-tests/tests/for2.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/for2.c Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,14 @@ +struct test { int x; }; + +int +test(int a) +{ + int b; + struct test *c; + while(a!=10) + { + c->x = a--; + } + + return b; +} Added: soc2011/shm/TESLA/instrumenter-tests/tests/for2.ins ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/for2.ins Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1 @@ +field_assign,struct test,x Added: soc2011/shm/TESLA/instrumenter-tests/tests/for2.out ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/for2.out Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,24 @@ +struct __va_list_tag { + unsigned int gp_offset; + unsigned int fp_offset; + void *overflow_arg_area; + void *reg_save_area; +}; +typedef struct __va_list_tag __va_list_tag; +struct test { + int x; +}; +int test(int a) { + int b; + struct test *c; + while (a != 10) + { + int __tesla_tmp_assign; + __tesla_tmp_assign = a--; + __tesla_event_field_assign_struct_test_x(c); + c->x = __tesla_tmp_assign; + } + return b; +} + + Added: soc2011/shm/TESLA/instrumenter-tests/tests/func.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/func.c Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,26 @@ +int f1(int a) +{ + return a; +} + +char f2(char b) +{ + return b; +} + +char f3(int c) +{ + if (c > 0) + return 5; + else + return 10; +} + +void f4(void) +{ +} + +void f5(void) +{ + return; +} Added: soc2011/shm/TESLA/instrumenter-tests/tests/func.ins ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/func.ins Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,9 @@ +function,f1 +function,f2 +function,f3 +function,f4 +function,f5 +function,f6 +function,f7 +function,f8 +function,f9 Added: soc2011/shm/TESLA/instrumenter-tests/tests/func.out ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/func.out Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,63 @@ +struct __va_list_tag { + unsigned int gp_offset; + unsigned int fp_offset; + void *overflow_arg_area; + void *reg_save_area; +}; +typedef struct __va_list_tag __va_list_tag; +int f1(int a) { + void *__tesla_data; + __tesla_event_function_prologue_f1(&__tesla_data, a); + int __tesla_tmp_retval; + __tesla_tmp_retval = a; + __tesla_event_function_return_f1(&__tesla_data, __tesla_tmp_retval); + return __tesla_tmp_retval; + __tesla_event_function_return_f1(&__tesla_data); +} + + +char f2(char b) { + void *__tesla_data; + __tesla_event_function_prologue_f2(&__tesla_data, b); + char __tesla_tmp_retval; + __tesla_tmp_retval = b; + __tesla_event_function_return_f2(&__tesla_data, __tesla_tmp_retval); + return __tesla_tmp_retval; + __tesla_event_function_return_f2(&__tesla_data); +} + + +char f3(int c) { + void *__tesla_data; + __tesla_event_function_prologue_f3(&__tesla_data, c); + if (c > 0) { + char __tesla_tmp_retval; + __tesla_tmp_retval = 5; + __tesla_event_function_return_f3(&__tesla_data, __tesla_tmp_retval); + return __tesla_tmp_retval; + } else { + char __tesla_tmp_retval; + __tesla_tmp_retval = 10; + __tesla_event_function_return_f3(&__tesla_data, __tesla_tmp_retval); + return __tesla_tmp_retval; + } + __tesla_event_function_return_f3(&__tesla_data); +} + + +void f4() { + void *__tesla_data; + __tesla_event_function_prologue_f4(&__tesla_data); + __tesla_event_function_return_f4(&__tesla_data); +} + + +void f5() { + void *__tesla_data; + __tesla_event_function_prologue_f5(&__tesla_data); + __tesla_event_function_return_f5(&__tesla_data); + return; + __tesla_event_function_return_f5(&__tesla_data); +} + + Added: soc2011/shm/TESLA/instrumenter-tests/tests/if.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/if.c Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,9 @@ +int test(void) +{ + if (test() != 0) + return 1; + else + { + return 0; + } +} Added: soc2011/shm/TESLA/instrumenter-tests/tests/if.ins ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/if.ins Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1 @@ +function,test Added: soc2011/shm/TESLA/instrumenter-tests/tests/if.out ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/if.out Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,25 @@ +struct __va_list_tag { + unsigned int gp_offset; + unsigned int fp_offset; + void *overflow_arg_area; + void *reg_save_area; +}; +typedef struct __va_list_tag __va_list_tag; +int test() { + void *__tesla_data; + __tesla_event_function_prologue_test(&__tesla_data); + if (test() != 0) { + int __tesla_tmp_retval; + __tesla_tmp_retval = 1; + __tesla_event_function_return_test(&__tesla_data, __tesla_tmp_retval); + return __tesla_tmp_retval; + } else { + int __tesla_tmp_retval; + __tesla_tmp_retval = 0; + __tesla_event_function_return_test(&__tesla_data, __tesla_tmp_retval); + return __tesla_tmp_retval; + } + __tesla_event_function_return_test(&__tesla_data); +} + + Added: soc2011/shm/TESLA/instrumenter-tests/tests/if2.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/if2.c Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,9 @@ +int test(void) +{ + if (test() != 0) + { + return 1; + } + else + return 0; +} Added: soc2011/shm/TESLA/instrumenter-tests/tests/if2.ins ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/if2.ins Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1 @@ +function,test Added: soc2011/shm/TESLA/instrumenter-tests/tests/if2.out ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/if2.out Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,25 @@ +struct __va_list_tag { + unsigned int gp_offset; + unsigned int fp_offset; + void *overflow_arg_area; + void *reg_save_area; +}; +typedef struct __va_list_tag __va_list_tag; +int test() { + void *__tesla_data; + __tesla_event_function_prologue_test(&__tesla_data); + if (test() != 0) { + int __tesla_tmp_retval; + __tesla_tmp_retval = 1; + __tesla_event_function_return_test(&__tesla_data, __tesla_tmp_retval); + return __tesla_tmp_retval; + } else { + int __tesla_tmp_retval; + __tesla_tmp_retval = 0; + __tesla_event_function_return_test(&__tesla_data, __tesla_tmp_retval); + return __tesla_tmp_retval; + } + __tesla_event_function_return_test(&__tesla_data); +} + + Added: soc2011/shm/TESLA/instrumenter-tests/tests/inc.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/inc.c Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,10 @@ +struct test { int x; }; + +int +test(int a) +{ + struct test *c; + c->x = 1; + c->x++; + return c->x; +} Added: soc2011/shm/TESLA/instrumenter-tests/tests/inc.ins ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/inc.ins Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1 @@ +field_assign,struct test,x Added: soc2011/shm/TESLA/instrumenter-tests/tests/inc.out ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/inc.out Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,21 @@ +struct __va_list_tag { + unsigned int gp_offset; + unsigned int fp_offset; + void *overflow_arg_area; + void *reg_save_area; +}; +typedef struct __va_list_tag __va_list_tag; +struct test { + int x; +}; +int test(int a) { + struct test *c; + int __tesla_tmp_assign; + __tesla_tmp_assign = 1; + __tesla_event_field_assign_struct_test_x(c); + c->x = __tesla_tmp_assign; + c->x++; + return c->x; +} + + Added: soc2011/shm/TESLA/instrumenter-tests/tests/none.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/none.c Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,5 @@ +int +main() +{ + return 0; +} Added: soc2011/shm/TESLA/instrumenter-tests/tests/none.ins ============================================================================== Added: soc2011/shm/TESLA/instrumenter-tests/tests/none.out ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/none.out Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,12 @@ +struct __va_list_tag { + unsigned int gp_offset; + unsigned int fp_offset; + void *overflow_arg_area; + void *reg_save_area; +}; +typedef struct __va_list_tag __va_list_tag; +int main() { + return 0; +} + + Added: soc2011/shm/TESLA/instrumenter-tests/tests/not-exist.out ============================================================================== Added: soc2011/shm/TESLA/instrumenter-tests/tests/switch.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/switch.c Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,16 @@ +int test(void) +{ + int a = 1; + switch(a) + { + case 1: + return 1; + case 2: + return 2; + case 3: + return 3; + default: + break; + } + return 4; +} Added: soc2011/shm/TESLA/instrumenter-tests/tests/switch.ins ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/switch.ins Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1 @@ +function,test Added: soc2011/shm/TESLA/instrumenter-tests/tests/switch.out ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/shm/TESLA/instrumenter-tests/tests/switch.out Sat Jul 9 01:20:18 2011 (r224064) @@ -0,0 +1,46 @@ +struct __va_list_tag { + unsigned int gp_offset; + unsigned int fp_offset; + void *overflow_arg_area; + void *reg_save_area; +}; +typedef struct __va_list_tag __va_list_tag; +int test() { + void *__tesla_data; + __tesla_event_function_prologue_test(&__tesla_data); + int a = 1; + switch (a) { + case 1: + { + int __tesla_tmp_retval; + __tesla_tmp_retval = 1; + __tesla_event_function_return_test(&__tesla_data, __tesla_tmp_retval); + return __tesla_tmp_retval; + } + case 2: + { + int __tesla_tmp_retval; + __tesla_tmp_retval = 2; + __tesla_event_function_return_test(&__tesla_data, __tesla_tmp_retval); + return __tesla_tmp_retval; + } + case 3: + { + int __tesla_tmp_retval; + __tesla_tmp_retval = 3; + __tesla_event_function_return_test(&__tesla_data, __tesla_tmp_retval); + return __tesla_tmp_retval; + } + default: + { + break; + } + } + int __tesla_tmp_retval; + __tesla_tmp_retval = 4; + __tesla_event_function_return_test(&__tesla_data, __tesla_tmp_retval); *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***