From cc1f85be8bee7d2f06c7233d26c77649c8a68540 Mon Sep 17 00:00:00 2001 From: Ryan Moeller Date: Mon, 9 Nov 2020 16:01:56 -0500 Subject: [PATCH] Simplify offset and length limit in zfs_write Reviewed-by: Brian Behlendorf Reviewed-by: Matt Macy Reviewed-by: Alexander Motin Signed-off-by: Ryan Moeller Closes #11176 --- module/zfs/zfs_vnops.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/module/zfs/zfs_vnops.c b/module/zfs/zfs_vnops.c index 8728790b58..a3a3482c3c 100644 --- a/module/zfs/zfs_vnops.c +++ b/module/zfs/zfs_vnops.c @@ -234,8 +234,6 @@ zfs_write(znode_t *zp, uio_t *uio, int ioflag, cred_t *cr) if (n == 0) return (0); - const rlim64_t limit = MAXOFFSET_T; - zfsvfs_t *zfsvfs = ZTOZSB(zp); ZFS_ENTER(zfsvfs); ZFS_VERIFY_ZP(zp); @@ -325,13 +323,15 @@ zfs_write(znode_t *zp, uio_t *uio, int ioflag, cred_t *cr) return (EFBIG); } + const rlim64_t limit = MAXOFFSET_T; + if (woff >= limit) { zfs_rangelock_exit(lr); ZFS_EXIT(zfsvfs); return (SET_ERROR(EFBIG)); } - if ((woff + n) > limit || woff > (limit - n)) + if (n > limit - woff) n = limit - woff; uint64_t end_size = MAX(zp->z_size, woff + n);