From owner-svn-src-head@FreeBSD.ORG Wed May 5 16:44:26 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 642391065675; Wed, 5 May 2010 16:44:26 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [69.147.83.44]) by mx1.freebsd.org (Postfix) with ESMTP id 51D398FC29; Wed, 5 May 2010 16:44:26 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o45GiQlc005186; Wed, 5 May 2010 16:44:26 GMT (envelope-from trasz@svn.freebsd.org) Received: (from trasz@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o45GiQBB005173; Wed, 5 May 2010 16:44:26 GMT (envelope-from trasz@svn.freebsd.org) Message-Id: <201005051644.o45GiQBB005173@svn.freebsd.org> From: Edward Tomasz Napierala Date: Wed, 5 May 2010 16:44:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r207662 - in head/sys: fs/ext2fs fs/msdosfs fs/nfsclient fs/nwfs fs/smbfs fs/tmpfs gnu/fs/xfs/FreeBSD kern nfsclient sys ufs/ffs X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 May 2010 16:44:26 -0000 Author: trasz Date: Wed May 5 16:44:25 2010 New Revision: 207662 URL: http://svn.freebsd.org/changeset/base/207662 Log: Move checking against RLIMIT_FSIZE into one place, vn_rlimit_fsize(). Reviewed by: kib Modified: head/sys/fs/ext2fs/ext2_readwrite.c head/sys/fs/ext2fs/ext2_vnops.c head/sys/fs/msdosfs/msdosfs_vnops.c head/sys/fs/nfsclient/nfs_clbio.c head/sys/fs/nwfs/nwfs_io.c head/sys/fs/smbfs/smbfs_io.c head/sys/fs/tmpfs/tmpfs_vnops.c head/sys/gnu/fs/xfs/FreeBSD/xfs_vnops.c head/sys/kern/vfs_vnops.c head/sys/nfsclient/nfs_bio.c head/sys/sys/vnode.h head/sys/ufs/ffs/ffs_vnops.c Modified: head/sys/fs/ext2fs/ext2_readwrite.c ============================================================================== --- head/sys/fs/ext2fs/ext2_readwrite.c Wed May 5 16:41:14 2010 (r207661) +++ head/sys/fs/ext2fs/ext2_readwrite.c Wed May 5 16:44:25 2010 (r207662) @@ -168,7 +168,6 @@ WRITE(ap) struct inode *ip; FS *fs; struct buf *bp; - struct thread *td; daddr_t lbn; off_t osize; int blkoffset, error, flags, ioflag, resid, size, seqcount, xfersize; @@ -213,17 +212,8 @@ WRITE(ap) * Maybe this should be above the vnode op call, but so long as * file servers have no limits, I don't think it matters. */ - td = uio->uio_td; - if (vp->v_type == VREG && td != NULL) { - PROC_LOCK(td->td_proc); - if (uio->uio_offset + uio->uio_resid > - lim_cur(td->td_proc, RLIMIT_FSIZE)) { - psignal(td->td_proc, SIGXFSZ); - PROC_UNLOCK(td->td_proc); - return (EFBIG); - } - PROC_UNLOCK(td->td_proc); - } + if (vn_rlimit_fsize(vp, uio, uio->uio_td)) + return (EFBIG); resid = uio->uio_resid; osize = ip->i_size; Modified: head/sys/fs/ext2fs/ext2_vnops.c ============================================================================== --- head/sys/fs/ext2fs/ext2_vnops.c Wed May 5 16:41:14 2010 (r207661) +++ head/sys/fs/ext2fs/ext2_vnops.c Wed May 5 16:44:25 2010 (r207662) @@ -46,7 +46,6 @@ #include #include -#include #include #include #include @@ -54,7 +53,6 @@ #include #include #include -#include #include #include #include @@ -71,7 +69,6 @@ #include -#include #include #include Modified: head/sys/fs/msdosfs/msdosfs_vnops.c ============================================================================== --- head/sys/fs/msdosfs/msdosfs_vnops.c Wed May 5 16:41:14 2010 (r207661) +++ head/sys/fs/msdosfs/msdosfs_vnops.c Wed May 5 16:44:25 2010 (r207662) @@ -61,9 +61,6 @@ #include #include #include -#include -#include -#include #include #include #include @@ -699,16 +696,8 @@ msdosfs_write(ap) /* * If they've exceeded their filesize limit, tell them about it. */ - if (td != NULL) { - PROC_LOCK(td->td_proc); - if ((uoff_t)uio->uio_offset + uio->uio_resid > - lim_cur(td->td_proc, RLIMIT_FSIZE)) { - psignal(td->td_proc, SIGXFSZ); - PROC_UNLOCK(td->td_proc); - return (EFBIG); - } - PROC_UNLOCK(td->td_proc); - } + if (vn_rlimit_fsize(vp, uio, td)) + return (EFBIG); /* * If the offset we are starting the write at is beyond the end of Modified: head/sys/fs/nfsclient/nfs_clbio.c ============================================================================== --- head/sys/fs/nfsclient/nfs_clbio.c Wed May 5 16:41:14 2010 (r207661) +++ head/sys/fs/nfsclient/nfs_clbio.c Wed May 5 16:44:25 2010 (r207662) @@ -41,9 +41,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include -#include -#include #include #include @@ -880,7 +877,6 @@ ncl_write(struct vop_write_args *ap) daddr_t lbn; int bcount; int n, on, error = 0; - struct proc *p = td?td->td_proc:NULL; #ifdef DIAGNOSTIC if (uio->uio_rw != UIO_WRITE) @@ -962,16 +958,8 @@ flush_and_restart: * Maybe this should be above the vnode op call, but so long as * file servers have no limits, i don't think it matters */ - if (p != NULL) { - PROC_LOCK(p); - if (uio->uio_offset + uio->uio_resid > - lim_cur(p, RLIMIT_FSIZE)) { - psignal(p, SIGXFSZ); - PROC_UNLOCK(p); - return (EFBIG); - } - PROC_UNLOCK(p); - } + if (vn_rlimit_fsize(vp, uio, td)) + return (EFBIG); biosize = vp->v_mount->mnt_stat.f_iosize; /* Modified: head/sys/fs/nwfs/nwfs_io.c ============================================================================== --- head/sys/fs/nwfs/nwfs_io.c Wed May 5 16:41:14 2010 (r207661) +++ head/sys/fs/nwfs/nwfs_io.c Wed May 5 16:44:25 2010 (r207662) @@ -28,16 +28,13 @@ */ #include #include -#include /* defines plimit structure in proc struct */ #include #include #include -#include #include #include #include #include -#include #include #include @@ -229,16 +226,10 @@ nwfs_writevnode(vp, uiop, cred, ioflag) } } if (uiop->uio_resid == 0) return 0; - if (td != NULL) { - PROC_LOCK(td->td_proc); - if (uiop->uio_offset + uiop->uio_resid > - lim_cur(td->td_proc, RLIMIT_FSIZE)) { - psignal(td->td_proc, SIGXFSZ); - PROC_UNLOCK(td->td_proc); - return (EFBIG); - } - PROC_UNLOCK(td->td_proc); - } + + if (vn_rlimit_fsize(vp, uiop, td)) + return (EFBIG); + error = ncp_write(NWFSTOCONN(nmp), &np->n_fh, uiop, cred); NCPVNDEBUG("after: ofs=%d,resid=%d\n",(int)uiop->uio_offset, uiop->uio_resid); if (!error) { Modified: head/sys/fs/smbfs/smbfs_io.c ============================================================================== --- head/sys/fs/smbfs/smbfs_io.c Wed May 5 16:41:14 2010 (r207661) +++ head/sys/fs/smbfs/smbfs_io.c Wed May 5 16:44:25 2010 (r207662) @@ -28,9 +28,7 @@ */ #include #include -#include /* defines plimit structure in proc struct */ #include -#include #include #include #include @@ -235,7 +233,6 @@ smbfs_writevnode(struct vnode *vp, struc struct smbmount *smp = VTOSMBFS(vp); struct smbnode *np = VTOSMB(vp); struct smb_cred scred; - struct proc *p; struct thread *td; int error = 0; @@ -249,7 +246,6 @@ smbfs_writevnode(struct vnode *vp, struc /* if (uiop->uio_offset + uiop->uio_resid > smp->nm_maxfilesize) return (EFBIG);*/ td = uiop->uio_td; - p = td->td_proc; if (ioflag & (IO_APPEND | IO_SYNC)) { if (np->n_flag & NMODIFIED) { smbfs_attr_cacheremove(vp); @@ -271,16 +267,10 @@ smbfs_writevnode(struct vnode *vp, struc } if (uiop->uio_resid == 0) return 0; - if (p != NULL) { - PROC_LOCK(p); - if (uiop->uio_offset + uiop->uio_resid > - lim_cur(p, RLIMIT_FSIZE)) { - psignal(p, SIGXFSZ); - PROC_UNLOCK(p); - return EFBIG; - } - PROC_UNLOCK(p); - } + + if (vn_rlimit_fsize(vp, uiop, td)) + return (EFBIG); + smb_makescred(&scred, td, cred); error = smb_write(smp->sm_share, np->n_fid, uiop, &scred); SMBVDEBUG("after: ofs=%d,resid=%d\n",(int)uiop->uio_offset, uiop->uio_resid); Modified: head/sys/fs/tmpfs/tmpfs_vnops.c ============================================================================== --- head/sys/fs/tmpfs/tmpfs_vnops.c Wed May 5 16:41:14 2010 (r207661) +++ head/sys/fs/tmpfs/tmpfs_vnops.c Wed May 5 16:44:25 2010 (r207662) @@ -42,7 +42,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include @@ -748,16 +747,8 @@ tmpfs_write(struct vop_write_args *v) VFS_TO_TMPFS(vp->v_mount)->tm_maxfilesize) return (EFBIG); - if (vp->v_type == VREG && td != NULL) { - PROC_LOCK(td->td_proc); - if (uio->uio_offset + uio->uio_resid > - lim_cur(td->td_proc, RLIMIT_FSIZE)) { - psignal(td->td_proc, SIGXFSZ); - PROC_UNLOCK(td->td_proc); - return (EFBIG); - } - PROC_UNLOCK(td->td_proc); - } + if (vn_rlimit_fsize(vp, uio, td)) + return (EFBIG); extended = uio->uio_offset + uio->uio_resid > node->tn_size; if (extended) { Modified: head/sys/gnu/fs/xfs/FreeBSD/xfs_vnops.c ============================================================================== --- head/sys/gnu/fs/xfs/FreeBSD/xfs_vnops.c Wed May 5 16:41:14 2010 (r207661) +++ head/sys/gnu/fs/xfs/FreeBSD/xfs_vnops.c Wed May 5 16:44:25 2010 (r207662) @@ -598,16 +598,8 @@ xfs_write_file(xfs_inode_t *xip, struct */ #if 0 td = uio->uio_td; - if (vp->v_type == VREG && td != NULL) { - PROC_LOCK(td->td_proc); - if (uio->uio_offset + uio->uio_resid > - lim_cur(td->td_proc, RLIMIT_FSIZE)) { - psignal(td->td_proc, SIGXFSZ); - PROC_UNLOCK(td->td_proc); - return (EFBIG); - } - PROC_UNLOCK(td->td_proc); - } + if (vn_rlimit_fsize(vp, uio, uio->uio_td)) + return (EFBIG); #endif resid = uio->uio_resid; Modified: head/sys/kern/vfs_vnops.c ============================================================================== --- head/sys/kern/vfs_vnops.c Wed May 5 16:41:14 2010 (r207661) +++ head/sys/kern/vfs_vnops.c Wed May 5 16:44:25 2010 (r207662) @@ -54,6 +54,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -1338,3 +1339,21 @@ vn_vget_ino(struct vnode *vp, ino_t ino, } return (error); } + +int +vn_rlimit_fsize(const struct vnode *vp, const struct uio *uio, const struct thread *td) +{ + if (vp->v_type != VREG || td == NULL) + return (0); + + PROC_LOCK(td->td_proc); + if (uio->uio_offset + uio->uio_resid > + lim_cur(td->td_proc, RLIMIT_FSIZE)) { + psignal(td->td_proc, SIGXFSZ); + PROC_UNLOCK(td->td_proc); + return (EFBIG); + } + PROC_UNLOCK(td->td_proc); + + return (0); +} Modified: head/sys/nfsclient/nfs_bio.c ============================================================================== --- head/sys/nfsclient/nfs_bio.c Wed May 5 16:41:14 2010 (r207661) +++ head/sys/nfsclient/nfs_bio.c Wed May 5 16:44:25 2010 (r207662) @@ -45,8 +45,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include -#include #include #include @@ -873,7 +871,6 @@ nfs_write(struct vop_write_args *ap) daddr_t lbn; int bcount; int n, on, error = 0; - struct proc *p = td?td->td_proc:NULL; #ifdef DIAGNOSTIC if (uio->uio_rw != UIO_WRITE) @@ -954,16 +951,8 @@ flush_and_restart: * Maybe this should be above the vnode op call, but so long as * file servers have no limits, i don't think it matters */ - if (p != NULL) { - PROC_LOCK(p); - if (uio->uio_offset + uio->uio_resid > - lim_cur(p, RLIMIT_FSIZE)) { - psignal(p, SIGXFSZ); - PROC_UNLOCK(p); - return (EFBIG); - } - PROC_UNLOCK(p); - } + if (vn_rlimit_fsize(vp, uio, td)) + return (EFBIG); biosize = vp->v_mount->mnt_stat.f_iosize; /* Modified: head/sys/sys/vnode.h ============================================================================== --- head/sys/sys/vnode.h Wed May 5 16:41:14 2010 (r207661) +++ head/sys/sys/vnode.h Wed May 5 16:44:25 2010 (r207662) @@ -780,6 +780,7 @@ struct dirent; int vfs_read_dirent(struct vop_readdir_args *ap, struct dirent *dp, off_t off); int vfs_unixify_accmode(accmode_t *accmode); +int vn_rlimit_fsize(const struct vnode *vn, const struct uio *uio, const struct thread *td); #endif /* _KERNEL */ Modified: head/sys/ufs/ffs/ffs_vnops.c ============================================================================== --- head/sys/ufs/ffs/ffs_vnops.c Wed May 5 16:41:14 2010 (r207661) +++ head/sys/ufs/ffs/ffs_vnops.c Wed May 5 16:44:25 2010 (r207662) @@ -75,9 +75,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include -#include -#include #include #include #include @@ -652,7 +649,6 @@ ffs_write(ap) struct inode *ip; struct fs *fs; struct buf *bp; - struct thread *td; ufs_lbn_t lbn; off_t osize; int seqcount; @@ -704,17 +700,8 @@ ffs_write(ap) * Maybe this should be above the vnode op call, but so long as * file servers have no limits, I don't think it matters. */ - td = uio->uio_td; - if (vp->v_type == VREG && td != NULL) { - PROC_LOCK(td->td_proc); - if (uio->uio_offset + uio->uio_resid > - lim_cur(td->td_proc, RLIMIT_FSIZE)) { - psignal(td->td_proc, SIGXFSZ); - PROC_UNLOCK(td->td_proc); - return (EFBIG); - } - PROC_UNLOCK(td->td_proc); - } + if (vn_rlimit_fsize(vp, uio, uio->uio_td)) + return (EFBIG); resid = uio->uio_resid; osize = ip->i_size;