diff options
author | trasz <trasz@FreeBSD.org> | 2010-05-05 16:44:25 +0000 |
---|---|---|
committer | trasz <trasz@FreeBSD.org> | 2010-05-05 16:44:25 +0000 |
commit | 402e3baadee30786a2a2fa508b9b7bec572da072 (patch) | |
tree | a3e31897fa4432edd5136dad2f999d5ce286bc3c | |
parent | a3da7d7e6937462db7db7ba830332b719a5a46fa (diff) | |
download | FreeBSD-src-402e3baadee30786a2a2fa508b9b7bec572da072.zip FreeBSD-src-402e3baadee30786a2a2fa508b9b7bec572da072.tar.gz |
Move checking against RLIMIT_FSIZE into one place, vn_rlimit_fsize().
Reviewed by: kib
-rw-r--r-- | sys/fs/ext2fs/ext2_readwrite.c | 14 | ||||
-rw-r--r-- | sys/fs/ext2fs/ext2_vnops.c | 3 | ||||
-rw-r--r-- | sys/fs/msdosfs/msdosfs_vnops.c | 15 | ||||
-rw-r--r-- | sys/fs/nfsclient/nfs_clbio.c | 16 | ||||
-rw-r--r-- | sys/fs/nwfs/nwfs_io.c | 17 | ||||
-rw-r--r-- | sys/fs/smbfs/smbfs_io.c | 18 | ||||
-rw-r--r-- | sys/fs/tmpfs/tmpfs_vnops.c | 13 | ||||
-rw-r--r-- | sys/gnu/fs/xfs/FreeBSD/xfs_vnops.c | 12 | ||||
-rw-r--r-- | sys/kern/vfs_vnops.c | 19 | ||||
-rw-r--r-- | sys/nfsclient/nfs_bio.c | 15 | ||||
-rw-r--r-- | sys/sys/vnode.h | 1 | ||||
-rw-r--r-- | sys/ufs/ffs/ffs_vnops.c | 17 |
12 files changed, 42 insertions, 118 deletions
diff --git a/sys/fs/ext2fs/ext2_readwrite.c b/sys/fs/ext2fs/ext2_readwrite.c index 9c9749a..1a713ca 100644 --- a/sys/fs/ext2fs/ext2_readwrite.c +++ b/sys/fs/ext2fs/ext2_readwrite.c @@ -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; diff --git a/sys/fs/ext2fs/ext2_vnops.c b/sys/fs/ext2fs/ext2_vnops.c index 2b2f8c5..2d302c5 100644 --- a/sys/fs/ext2fs/ext2_vnops.c +++ b/sys/fs/ext2fs/ext2_vnops.c @@ -46,7 +46,6 @@ #include <sys/param.h> #include <sys/systm.h> -#include <sys/resourcevar.h> #include <sys/kernel.h> #include <sys/fcntl.h> #include <sys/stat.h> @@ -54,7 +53,6 @@ #include <sys/buf.h> #include <sys/endian.h> #include <sys/priv.h> -#include <sys/proc.h> #include <sys/mount.h> #include <sys/unistd.h> #include <sys/time.h> @@ -71,7 +69,6 @@ #include <fs/fifofs/fifo.h> -#include <sys/signalvar.h> #include <ufs/ufs/dir.h> #include <fs/ext2fs/inode.h> diff --git a/sys/fs/msdosfs/msdosfs_vnops.c b/sys/fs/msdosfs/msdosfs_vnops.c index e9c593b..f38c72b 100644 --- a/sys/fs/msdosfs/msdosfs_vnops.c +++ b/sys/fs/msdosfs/msdosfs_vnops.c @@ -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 diff --git a/sys/fs/nfsclient/nfs_clbio.c b/sys/fs/nfsclient/nfs_clbio.c index e23da72..1413856 100644 --- a/sys/fs/nfsclient/nfs_clbio.c +++ b/sys/fs/nfsclient/nfs_clbio.c @@ -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> @@ -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; /* diff --git a/sys/fs/nwfs/nwfs_io.c b/sys/fs/nwfs/nwfs_io.c index ef1c800..83fbe70 100644 --- a/sys/fs/nwfs/nwfs_io.c +++ b/sys/fs/nwfs/nwfs_io.c @@ -28,16 +28,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> @@ -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) { diff --git a/sys/fs/smbfs/smbfs_io.c b/sys/fs/smbfs/smbfs_io.c index 6537ed4..7e021c1 100644 --- a/sys/fs/smbfs/smbfs_io.c +++ b/sys/fs/smbfs/smbfs_io.c @@ -28,9 +28,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> @@ -235,7 +233,6 @@ smbfs_writevnode(struct vnode *vp, struct uio *uiop, 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, struct uio *uiop, /* 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, struct uio *uiop, } 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); diff --git a/sys/fs/tmpfs/tmpfs_vnops.c b/sys/fs/tmpfs/tmpfs_vnops.c index 85cd23d..3ffef6b 100644 --- a/sys/fs/tmpfs/tmpfs_vnops.c +++ b/sys/fs/tmpfs/tmpfs_vnops.c @@ -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> @@ -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) { diff --git a/sys/gnu/fs/xfs/FreeBSD/xfs_vnops.c b/sys/gnu/fs/xfs/FreeBSD/xfs_vnops.c index 20be557..b935b64 100644 --- a/sys/gnu/fs/xfs/FreeBSD/xfs_vnops.c +++ b/sys/gnu/fs/xfs/FreeBSD/xfs_vnops.c @@ -598,16 +598,8 @@ xfs_write_file(xfs_inode_t *xip, struct uio *uio, int ioflag) */ #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; diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index 838f8f7..edc7ea8 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -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> @@ -1338,3 +1339,21 @@ vn_vget_ino(struct vnode *vp, ino_t ino, int lkflags, struct vnode **rvp) } 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); +} diff --git a/sys/nfsclient/nfs_bio.c b/sys/nfsclient/nfs_bio.c index 3a0705e..13effd0 100644 --- a/sys/nfsclient/nfs_bio.c +++ b/sys/nfsclient/nfs_bio.c @@ -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> @@ -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; /* diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h index b5784e4..7c4ae32 100644 --- a/sys/sys/vnode.h +++ b/sys/sys/vnode.h @@ -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 */ diff --git a/sys/ufs/ffs/ffs_vnops.c b/sys/ufs/ffs/ffs_vnops.c index e6617cb..85f8ffd 100644 --- a/sys/ufs/ffs/ffs_vnops.c +++ b/sys/ufs/ffs/ffs_vnops.c @@ -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> @@ -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; |