Module Name: src Committed By: hannken Date: Sat Jun 14 07:39:29 UTC 2014
Modified Files: src/sys/fs/cd9660: cd9660_bmap.c cd9660_lookup.c cd9660_node.c cd9660_node.h cd9660_vfsops.c cd9660_vnops.c Log Message: Remove the hints "isodir" and "relocated" from cd9660_vget_internal() and always reread the directory entry by inumber. For directories the directory entry is always its "." entry. Always read directories via the device vnode to prevent buffer cache inconsistency. Keep i_devvp as a hint for fstat(1) and friends and always use im_devvp for reads. No need to vref()/vrele() i_devvp. The additional bread is either cached because cd9660_lookup() just released the buffer or will be used in the near future when the directory gets traversed during lookup. No objections on tech-kern@ To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/fs/cd9660/cd9660_bmap.c cvs rdiff -u -r1.27 -r1.28 src/sys/fs/cd9660/cd9660_lookup.c cvs rdiff -u -r1.31 -r1.32 src/sys/fs/cd9660/cd9660_node.c cvs rdiff -u -r1.14 -r1.15 src/sys/fs/cd9660/cd9660_node.h cvs rdiff -u -r1.85 -r1.86 src/sys/fs/cd9660/cd9660_vfsops.c cvs rdiff -u -r1.47 -r1.48 src/sys/fs/cd9660/cd9660_vnops.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/fs/cd9660/cd9660_bmap.c diff -u src/sys/fs/cd9660/cd9660_bmap.c:1.4 src/sys/fs/cd9660/cd9660_bmap.c:1.5 --- src/sys/fs/cd9660/cd9660_bmap.c:1.4 Wed Feb 27 19:43:36 2008 +++ src/sys/fs/cd9660/cd9660_bmap.c Sat Jun 14 07:39:28 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: cd9660_bmap.c,v 1.4 2008/02/27 19:43:36 matt Exp $ */ +/* $NetBSD: cd9660_bmap.c,v 1.5 2014/06/14 07:39:28 hannken Exp $ */ /*- * Copyright (c) 1994 @@ -37,7 +37,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: cd9660_bmap.c,v 1.4 2008/02/27 19:43:36 matt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cd9660_bmap.c,v 1.5 2014/06/14 07:39:28 hannken Exp $"); #include <sys/param.h> #include <sys/namei.h> @@ -74,7 +74,7 @@ cd9660_bmap(void *v) * to physical mapping is requested. */ if (ap->a_vpp != NULL) - *ap->a_vpp = ip->i_devvp; + *ap->a_vpp = ip->i_mnt->im_devvp; if (ap->a_bnp == NULL) return (0); Index: src/sys/fs/cd9660/cd9660_lookup.c diff -u src/sys/fs/cd9660/cd9660_lookup.c:1.27 src/sys/fs/cd9660/cd9660_lookup.c:1.28 --- src/sys/fs/cd9660/cd9660_lookup.c:1.27 Tue Jun 3 19:30:30 2014 +++ src/sys/fs/cd9660/cd9660_lookup.c Sat Jun 14 07:39:28 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: cd9660_lookup.c,v 1.27 2014/06/03 19:30:30 joerg Exp $ */ +/* $NetBSD: cd9660_lookup.c,v 1.28 2014/06/14 07:39:28 hannken Exp $ */ /*- * Copyright (c) 1989, 1993, 1994 @@ -39,7 +39,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: cd9660_lookup.c,v 1.27 2014/06/03 19:30:30 joerg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cd9660_lookup.c,v 1.28 2014/06/14 07:39:28 hannken Exp $"); #include <sys/param.h> #include <sys/namei.h> @@ -379,8 +379,7 @@ found: brelse(bp, 0); if (flags & ISDOTDOT) { VOP_UNLOCK(pdp); /* race to get the inode */ - error = cd9660_vget_internal(vdp->v_mount, dp->i_ino, &tdp, - dp->i_ino != ino, ep); + error = cd9660_vget_internal(vdp->v_mount, dp->i_ino, &tdp); vn_lock(pdp, LK_EXCLUSIVE | LK_RETRY); if (error) return error; @@ -389,8 +388,7 @@ found: vref(vdp); /* we want ourself, ie "." */ *vpp = vdp; } else { - error = cd9660_vget_internal(vdp->v_mount, dp->i_ino, &tdp, - dp->i_ino != ino, ep); + error = cd9660_vget_internal(vdp->v_mount, dp->i_ino, &tdp); if (error) return (error); *vpp = tdp; @@ -416,6 +414,7 @@ cd9660_blkatoff(struct vnode *vp, off_t { struct iso_node *ip; struct iso_mnt *imp; + struct vnode *devvp; struct buf *bp; daddr_t lbn; int bsize, error; @@ -425,7 +424,11 @@ cd9660_blkatoff(struct vnode *vp, off_t lbn = cd9660_lblkno(imp, offset); bsize = cd9660_blksize(imp, ip, lbn); - if ((error = bread(vp, lbn, bsize, NOCRED, 0, &bp)) != 0) { + if ((error = VOP_BMAP(vp, lbn, &devvp, &lbn, NULL)) != 0) { + *bpp = NULL; + return error; + } + if ((error = bread(devvp, lbn, bsize, NOCRED, 0, &bp)) != 0) { *bpp = NULL; return (error); } Index: src/sys/fs/cd9660/cd9660_node.c diff -u src/sys/fs/cd9660/cd9660_node.c:1.31 src/sys/fs/cd9660/cd9660_node.c:1.32 --- src/sys/fs/cd9660/cd9660_node.c:1.31 Sat May 10 14:11:58 2014 +++ src/sys/fs/cd9660/cd9660_node.c Sat Jun 14 07:39:28 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: cd9660_node.c,v 1.31 2014/05/10 14:11:58 martin Exp $ */ +/* $NetBSD: cd9660_node.c,v 1.32 2014/06/14 07:39:28 hannken Exp $ */ /*- * Copyright (c) 1982, 1986, 1989, 1994 @@ -37,7 +37,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: cd9660_node.c,v 1.31 2014/05/10 14:11:58 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cd9660_node.c,v 1.32 2014/06/14 07:39:28 hannken Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -241,10 +241,6 @@ cd9660_reclaim(void *v) /* * Purge old data structures associated with the inode. */ - if (ip->i_devvp) { - vrele(ip->i_devvp); - ip->i_devvp = 0; - } genfs_node_destroy(vp); pool_put(&cd9660_node_pool, vp->v_data); vp->v_data = NULL; Index: src/sys/fs/cd9660/cd9660_node.h diff -u src/sys/fs/cd9660/cd9660_node.h:1.14 src/sys/fs/cd9660/cd9660_node.h:1.15 --- src/sys/fs/cd9660/cd9660_node.h:1.14 Wed Feb 27 19:43:36 2008 +++ src/sys/fs/cd9660/cd9660_node.h Sat Jun 14 07:39:28 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: cd9660_node.h,v 1.14 2008/02/27 19:43:36 matt Exp $ */ +/* $NetBSD: cd9660_node.h,v 1.15 2014/06/14 07:39:28 hannken Exp $ */ /*- * Copyright (c) 1994 @@ -133,8 +133,7 @@ void cd9660_ihashins(struct iso_node *); void cd9660_ihashrem(struct iso_node *); int cd9660_tstamp_conv7(const u_char *, struct timespec *); int cd9660_tstamp_conv17(const u_char *, struct timespec *); -int cd9660_vget_internal(struct mount *, ino_t, struct vnode **, int, - struct iso_directory_record *); +int cd9660_vget_internal(struct mount *, ino_t, struct vnode **); extern kmutex_t cd9660_hashlock; Index: src/sys/fs/cd9660/cd9660_vfsops.c diff -u src/sys/fs/cd9660/cd9660_vfsops.c:1.85 src/sys/fs/cd9660/cd9660_vfsops.c:1.86 --- src/sys/fs/cd9660/cd9660_vfsops.c:1.85 Tue May 13 17:05:26 2014 +++ src/sys/fs/cd9660/cd9660_vfsops.c Sat Jun 14 07:39:28 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: cd9660_vfsops.c,v 1.85 2014/05/13 17:05:26 martin Exp $ */ +/* $NetBSD: cd9660_vfsops.c,v 1.86 2014/06/14 07:39:28 hannken Exp $ */ /*- * Copyright (c) 1994 @@ -37,7 +37,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: cd9660_vfsops.c,v 1.85 2014/05/13 17:05:26 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cd9660_vfsops.c,v 1.86 2014/06/14 07:39:28 hannken Exp $"); #if defined(_KERNEL_OPT) #include "opt_compat_netbsd.h" @@ -586,12 +586,7 @@ cd9660_root(struct mount *mp, struct vno (struct iso_directory_record *)imp->root; ino_t ino = isodirino(dp, imp); - /* - * With RRIP we must use the `.' entry of the root directory. - * Simply tell vget, that it's a relocated directory. - */ - return (cd9660_vget_internal(mp, ino, vpp, - imp->iso_ftype == ISO_FTYPE_RRIP, dp)); + return cd9660_vget(mp, ino, vpp); } /* @@ -683,30 +678,19 @@ int cd9660_vget(struct mount *mp, ino_t ino, struct vnode **vpp) { - /* - * XXXX - * It would be nice if we didn't always set the `relocated' flag - * and force the extra read, but I don't want to think about fixing - * that right now. - */ - return (cd9660_vget_internal(mp, ino, vpp, -#if 0 - VFSTOISOFS(mp)->iso_ftype == ISO_FTYPE_RRIP, -#else - 0, -#endif - NULL)); + return cd9660_vget_internal(mp, ino, vpp); } int -cd9660_vget_internal(struct mount *mp, ino_t ino, struct vnode **vpp, - int relocated, struct iso_directory_record *isodir) +cd9660_vget_internal(struct mount *mp, ino_t ino, struct vnode **vpp) { struct iso_mnt *imp; struct iso_node *ip; + struct iso_directory_record *isodir; struct buf *bp; struct vnode *vp; dev_t dev; + int lbn, off; int error; imp = VFSTOISOFS(mp); @@ -754,75 +738,52 @@ cd9660_vget_internal(struct mount *mp, i cd9660_ihashins(ip); mutex_exit(&cd9660_hashlock); - if (isodir == 0) { - int lbn, off; - - lbn = cd9660_lblkno(imp, ino); - if (lbn >= imp->volume_space_size) { - vput(vp); - printf("fhtovp: lbn exceed volume space %d\n", lbn); - return (ESTALE); - } + lbn = cd9660_lblkno(imp, ino); + if (lbn >= imp->volume_space_size) { + vput(vp); + printf("fhtovp: lbn exceed volume space %d\n", lbn); + return (ESTALE); + } - off = cd9660_blkoff(imp, ino); - if (off + ISO_DIRECTORY_RECORD_SIZE > imp->logical_block_size) { - vput(vp); - printf("fhtovp: crosses block boundary %d\n", - off + ISO_DIRECTORY_RECORD_SIZE); - return (ESTALE); - } + off = cd9660_blkoff(imp, ino); + if (off + ISO_DIRECTORY_RECORD_SIZE > imp->logical_block_size) { + vput(vp); + printf("fhtovp: crosses block boundary %d\n", + off + ISO_DIRECTORY_RECORD_SIZE); + return (ESTALE); + } - error = bread(imp->im_devvp, - lbn << (imp->im_bshift - DEV_BSHIFT), - imp->logical_block_size, NOCRED, 0, &bp); - if (error) { - vput(vp); - printf("fhtovp: bread error %d\n",error); - return (error); - } - isodir = (struct iso_directory_record *)((char *)bp->b_data + off); + error = bread(imp->im_devvp, + lbn << (imp->im_bshift - DEV_BSHIFT), + imp->logical_block_size, NOCRED, 0, &bp); + if (error) { + vput(vp); + printf("fhtovp: bread error %d\n",error); + return (error); + } + isodir = (struct iso_directory_record *)((char *)bp->b_data + off); - if (off + isonum_711(isodir->length) > - imp->logical_block_size) { - vput(vp); - if (bp != 0) - brelse(bp, 0); - printf("fhtovp: directory crosses block boundary %d[off=%d/len=%d]\n", - off +isonum_711(isodir->length), off, - isonum_711(isodir->length)); - return (ESTALE); - } + if (off + isonum_711(isodir->length) > imp->logical_block_size) { + vput(vp); + if (bp != 0) + brelse(bp, 0); + printf("fhtovp: directory crosses block boundary %d[off=%d/len=%d]\n", + off +isonum_711(isodir->length), off, + isonum_711(isodir->length)); + return (ESTALE); + } #if 0 - if (isonum_733(isodir->extent) + - isonum_711(isodir->ext_attr_length) != ifhp->ifid_start) { - if (bp != 0) - brelse(bp, 0); - printf("fhtovp: file start miss %d vs %d\n", - isonum_733(isodir->extent) + isonum_711(isodir->ext_attr_length), - ifhp->ifid_start); - return (ESTALE); - } -#endif - } else - bp = 0; - - vref(ip->i_devvp); - - if (relocated) { - /* - * On relocated directories we must - * read the `.' entry out of a dir. - */ - ip->iso_start = ino >> imp->im_bshift; + if (isonum_733(isodir->extent) + + isonum_711(isodir->ext_attr_length) != ifhp->ifid_start) { if (bp != 0) brelse(bp, 0); - if ((error = cd9660_blkatoff(vp, (off_t)0, NULL, &bp)) != 0) { - vput(vp); - return (error); - } - isodir = (struct iso_directory_record *)bp->b_data; + printf("fhtovp: file start miss %d vs %d\n", + isonum_733(isodir->extent) + isonum_711(isodir->ext_attr_length), + ifhp->ifid_start); + return (ESTALE); } +#endif ip->iso_extent = isonum_733(isodir->extent); ip->i_size = isonum_733(isodir->size); @@ -836,7 +797,6 @@ cd9660_vget_internal(struct mount *mp, i default: /* ISO_FTYPE_9660 */ { struct buf *bp2; - int off; if ((imp->im_flags & ISOFSMNT_EXTATT) && (off = isonum_711(isodir->ext_attr_length))) cd9660_blkatoff(vp, (off_t)-(off << imp->im_bshift), Index: src/sys/fs/cd9660/cd9660_vnops.c diff -u src/sys/fs/cd9660/cd9660_vnops.c:1.47 src/sys/fs/cd9660/cd9660_vnops.c:1.48 --- src/sys/fs/cd9660/cd9660_vnops.c:1.47 Thu Jan 23 10:13:56 2014 +++ src/sys/fs/cd9660/cd9660_vnops.c Sat Jun 14 07:39:29 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: cd9660_vnops.c,v 1.47 2014/01/23 10:13:56 hannken Exp $ */ +/* $NetBSD: cd9660_vnops.c,v 1.48 2014/06/14 07:39:29 hannken Exp $ */ /*- * Copyright (c) 1994 @@ -37,7 +37,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: cd9660_vnops.c,v 1.47 2014/01/23 10:13:56 hannken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cd9660_vnops.c,v 1.48 2014/06/14 07:39:29 hannken Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -723,7 +723,7 @@ cd9660_strategy(void *v) biodone(bp); return (0); } - vp = ip->i_devvp; + vp = ip->i_mnt->im_devvp; return (VOP_STRATEGY(vp, bp)); }