Simplify offset and length limit in zfs_write

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Matt Macy <mmacy@FreeBSD.org>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Signed-off-by: Ryan Moeller <ryan@iXsystems.com>
Closes #11176
This commit is contained in:
Ryan Moeller 2020-11-09 16:01:56 -05:00 committed by Brian Behlendorf
parent 9585538d0e
commit cc1f85be8b
1 changed files with 3 additions and 3 deletions

View File

@ -234,8 +234,6 @@ zfs_write(znode_t *zp, uio_t *uio, int ioflag, cred_t *cr)
if (n == 0) if (n == 0)
return (0); return (0);
const rlim64_t limit = MAXOFFSET_T;
zfsvfs_t *zfsvfs = ZTOZSB(zp); zfsvfs_t *zfsvfs = ZTOZSB(zp);
ZFS_ENTER(zfsvfs); ZFS_ENTER(zfsvfs);
ZFS_VERIFY_ZP(zp); ZFS_VERIFY_ZP(zp);
@ -325,13 +323,15 @@ zfs_write(znode_t *zp, uio_t *uio, int ioflag, cred_t *cr)
return (EFBIG); return (EFBIG);
} }
const rlim64_t limit = MAXOFFSET_T;
if (woff >= limit) { if (woff >= limit) {
zfs_rangelock_exit(lr); zfs_rangelock_exit(lr);
ZFS_EXIT(zfsvfs); ZFS_EXIT(zfsvfs);
return (SET_ERROR(EFBIG)); return (SET_ERROR(EFBIG));
} }
if ((woff + n) > limit || woff > (limit - n)) if (n > limit - woff)
n = limit - woff; n = limit - woff;
uint64_t end_size = MAX(zp->z_size, woff + n); uint64_t end_size = MAX(zp->z_size, woff + n);