From owner-svn-src-all@FreeBSD.ORG Fri Sep 2 07:37:56 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 10469106566B; Fri, 2 Sep 2011 07:37:56 +0000 (UTC) (envelope-from mm@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id EFA768FC12; Fri, 2 Sep 2011 07:37:55 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p827btZj087127; Fri, 2 Sep 2011 07:37:55 GMT (envelope-from mm@svn.freebsd.org) Received: (from mm@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p827bt2o087115; Fri, 2 Sep 2011 07:37:55 GMT (envelope-from mm@svn.freebsd.org) Message-Id: <201109020737.p827bt2o087115@svn.freebsd.org> From: Martin Matuska Date: Fri, 2 Sep 2011 07:37:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r225320 - in stable/8/sys: cddl/contrib/opensolaris/uts/common/fs/zfs fs/msdosfs fs/nfsclient fs/nwfs fs/smbfs fs/tmpfs gnu/fs/xfs/FreeBSD kern nfsclient sys ufs/ffs X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Sep 2011 07:37:56 -0000 Author: mm Date: Fri Sep 2 07:37:55 2011 New Revision: 225320 URL: http://svn.freebsd.org/changeset/base/225320 Log: MFC r207662 (trasz): Move checking against RLIMIT_FSIZE into one place, vn_rlimit_fsize(). Modified: stable/8/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c stable/8/sys/fs/msdosfs/msdosfs_vnops.c stable/8/sys/fs/nfsclient/nfs_clbio.c stable/8/sys/fs/nwfs/nwfs_io.c stable/8/sys/fs/smbfs/smbfs_io.c stable/8/sys/fs/tmpfs/tmpfs_vnops.c stable/8/sys/gnu/fs/xfs/FreeBSD/xfs_vnops.c stable/8/sys/kern/vfs_vnops.c stable/8/sys/nfsclient/nfs_bio.c stable/8/sys/sys/vnode.h stable/8/sys/ufs/ffs/ffs_vnops.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) Modified: stable/8/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c ============================================================================== --- stable/8/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c Fri Sep 2 07:19:27 2011 (r225319) +++ stable/8/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c Fri Sep 2 07:37:55 2011 (r225320) @@ -5696,16 +5696,8 @@ zfs_freebsd_write(ap) } */ *ap; { - if (ap->a_vp->v_type == VREG && ap->a_uio->uio_td != NULL) { - PROC_LOCK(ap->a_uio->uio_td->td_proc); - if (ap->a_uio->uio_offset + ap->a_uio->uio_resid > - lim_cur(ap->a_uio->uio_td->td_proc, RLIMIT_FSIZE)) { - psignal(ap->a_uio->uio_td->td_proc, SIGXFSZ); - PROC_UNLOCK(ap->a_uio->uio_td->td_proc); - return (EFBIG); - } - PROC_UNLOCK(ap->a_uio->uio_td->td_proc); - } + if (vn_rlimit_fsize(ap->a_vp, ap->a_uio, ap->a_uio->uio_td)) + return (EFBIG); return (zfs_write(ap->a_vp, ap->a_uio, ioflags(ap->a_ioflag), ap->a_cred, NULL)); Modified: stable/8/sys/fs/msdosfs/msdosfs_vnops.c ============================================================================== --- stable/8/sys/fs/msdosfs/msdosfs_vnops.c Fri Sep 2 07:19:27 2011 (r225319) +++ stable/8/sys/fs/msdosfs/msdosfs_vnops.c Fri Sep 2 07:37:55 2011 (r225320) @@ -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: stable/8/sys/fs/nfsclient/nfs_clbio.c ============================================================================== --- stable/8/sys/fs/nfsclient/nfs_clbio.c Fri Sep 2 07:19:27 2011 (r225319) +++ stable/8/sys/fs/nfsclient/nfs_clbio.c Fri Sep 2 07:37:55 2011 (r225320) @@ -41,9 +41,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include -#include -#include #include #include @@ -867,7 +864,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; off_t tmp_off; KASSERT(uio->uio_rw == UIO_WRITE, ("ncl_write mode")); @@ -948,16 +944,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: stable/8/sys/fs/nwfs/nwfs_io.c ============================================================================== --- stable/8/sys/fs/nwfs/nwfs_io.c Fri Sep 2 07:19:27 2011 (r225319) +++ stable/8/sys/fs/nwfs/nwfs_io.c Fri Sep 2 07:37:55 2011 (r225320) @@ -34,16 +34,13 @@ */ #include #include -#include /* defines plimit structure in proc struct */ #include #include #include -#include #include #include #include #include -#include #include #include @@ -235,16 +232,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: stable/8/sys/fs/smbfs/smbfs_io.c ============================================================================== --- stable/8/sys/fs/smbfs/smbfs_io.c Fri Sep 2 07:19:27 2011 (r225319) +++ stable/8/sys/fs/smbfs/smbfs_io.c Fri Sep 2 07:37:55 2011 (r225320) @@ -34,9 +34,7 @@ */ #include #include -#include /* defines plimit structure in proc struct */ #include -#include #include #include #include @@ -241,7 +239,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; @@ -255,7 +252,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); @@ -277,16 +273,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: stable/8/sys/fs/tmpfs/tmpfs_vnops.c ============================================================================== --- stable/8/sys/fs/tmpfs/tmpfs_vnops.c Fri Sep 2 07:19:27 2011 (r225319) +++ stable/8/sys/fs/tmpfs/tmpfs_vnops.c Fri Sep 2 07:37:55 2011 (r225320) @@ -42,7 +42,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include @@ -723,16 +722,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: stable/8/sys/gnu/fs/xfs/FreeBSD/xfs_vnops.c ============================================================================== --- stable/8/sys/gnu/fs/xfs/FreeBSD/xfs_vnops.c Fri Sep 2 07:19:27 2011 (r225319) +++ stable/8/sys/gnu/fs/xfs/FreeBSD/xfs_vnops.c Fri Sep 2 07:37:55 2011 (r225320) @@ -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: stable/8/sys/kern/vfs_vnops.c ============================================================================== --- stable/8/sys/kern/vfs_vnops.c Fri Sep 2 07:19:27 2011 (r225319) +++ stable/8/sys/kern/vfs_vnops.c Fri Sep 2 07:37:55 2011 (r225320) @@ -54,6 +54,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -1334,3 +1335,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: stable/8/sys/nfsclient/nfs_bio.c ============================================================================== --- stable/8/sys/nfsclient/nfs_bio.c Fri Sep 2 07:19:27 2011 (r225319) +++ stable/8/sys/nfsclient/nfs_bio.c Fri Sep 2 07:37:55 2011 (r225320) @@ -45,8 +45,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include -#include #include #include @@ -862,7 +860,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; KASSERT(uio->uio_rw == UIO_WRITE, ("nfs_write mode")); KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_td == curthread, @@ -940,16 +937,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: stable/8/sys/sys/vnode.h ============================================================================== --- stable/8/sys/sys/vnode.h Fri Sep 2 07:19:27 2011 (r225319) +++ stable/8/sys/sys/vnode.h Fri Sep 2 07:37:55 2011 (r225320) @@ -778,6 +778,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: stable/8/sys/ufs/ffs/ffs_vnops.c ============================================================================== --- stable/8/sys/ufs/ffs/ffs_vnops.c Fri Sep 2 07:19:27 2011 (r225319) +++ stable/8/sys/ufs/ffs/ffs_vnops.c Fri Sep 2 07:37:55 2011 (r225320) @@ -75,9 +75,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include -#include -#include #include #include #include @@ -651,7 +648,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; @@ -703,17 +699,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;