Date: Fri, 2 Sep 2011 07:37:55 +0000 (UTC) From: Martin Matuska <mm@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org 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 Message-ID: <201109020737.p827bt2o087115@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <sys/mutex.h> #include <sys/namei.h> #include <sys/priv.h> -#include <sys/proc.h> -#include <sys/resourcevar.h> -#include <sys/signalvar.h> #include <sys/stat.h> #include <sys/unistd.h> #include <sys/vnode.h> @@ -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 <sys/buf.h> #include <sys/kernel.h> #include <sys/mount.h> -#include <sys/proc.h> -#include <sys/resourcevar.h> -#include <sys/signalvar.h> #include <sys/vmmeter.h> #include <sys/vnode.h> @@ -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 <sys/param.h> #include <sys/systm.h> -#include <sys/resourcevar.h> /* defines plimit structure in proc struct */ #include <sys/kernel.h> #include <sys/bio.h> #include <sys/buf.h> -#include <sys/proc.h> #include <sys/mount.h> #include <sys/namei.h> #include <sys/vnode.h> #include <sys/dirent.h> -#include <sys/signalvar.h> #include <sys/sysctl.h> #include <vm/vm.h> @@ -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 <sys/param.h> #include <sys/systm.h> -#include <sys/resourcevar.h> /* defines plimit structure in proc struct */ #include <sys/kernel.h> -#include <sys/proc.h> #include <sys/fcntl.h> #include <sys/bio.h> #include <sys/buf.h> @@ -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 <sys/namei.h> #include <sys/priv.h> #include <sys/proc.h> -#include <sys/resourcevar.h> #include <sys/sched.h> #include <sys/sf_buf.h> #include <sys/stat.h> @@ -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 <sys/bio.h> #include <sys/buf.h> #include <sys/filio.h> +#include <sys/resourcevar.h> #include <sys/sx.h> #include <sys/ttycom.h> #include <sys/conf.h> @@ -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 <sys/mbuf.h> #include <sys/mount.h> #include <sys/proc.h> -#include <sys/resourcevar.h> -#include <sys/signalvar.h> #include <sys/vmmeter.h> #include <sys/vnode.h> @@ -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 <sys/malloc.h> #include <sys/mount.h> #include <sys/priv.h> -#include <sys/proc.h> -#include <sys/resourcevar.h> -#include <sys/signalvar.h> #include <sys/stat.h> #include <sys/vmmeter.h> #include <sys/vnode.h> @@ -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;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201109020737.p827bt2o087115>