diff options
author | Rick Macklem <rmacklem@FreeBSD.org> | 2019-07-01 20:41:43 +0000 |
---|---|---|
committer | Rick Macklem <rmacklem@FreeBSD.org> | 2019-07-01 20:41:43 +0000 |
commit | 555d8f2859d5276ef2fcc1e6c0c0cef6887f4d86 (patch) | |
tree | b5f172d4cb8480d20ee4e73bd1a7ffd08dc99525 /sys/kern/vfs_vnops.c | |
parent | 23ced944518f5ea6a5d5c62e1e348f29ed0eee2c (diff) | |
download | src-555d8f2859d5276ef2fcc1e6c0c0cef6887f4d86.tar.gz src-555d8f2859d5276ef2fcc1e6c0c0cef6887f4d86.zip |
Factor out the code that does a VOP_SETATTR(size) from vn_truncate().
This patch factors the code in vn_truncate() that does the actual
VOP_SETATTR() of size into a separate function called vn_truncate_locked().
This will allow the NFS server and the patch that adds a
copy_file_range(2) syscall to call this function instead of duplicating
the code and carrying over changes, such as the recent r347151.
Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D20808
Notes
Notes:
svn path=/head/; revision=349582
Diffstat (limited to 'sys/kern/vfs_vnops.c')
-rw-r--r-- | sys/kern/vfs_vnops.c | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index c510ea618bdd..5d54ba986408 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -1289,7 +1289,6 @@ static int vn_truncate(struct file *fp, off_t length, struct ucred *active_cred, struct thread *td) { - struct vattr vattr; struct mount *mp; struct vnode *vp; void *rl_cookie; @@ -1316,20 +1315,35 @@ vn_truncate(struct file *fp, off_t length, struct ucred *active_cred, if (error) goto out; #endif + error = vn_truncate_locked(vp, length, (fp->f_flag & O_FSYNC) != 0, + fp->f_cred); +out: + VOP_UNLOCK(vp, 0); + vn_finished_write(mp); +out1: + vn_rangelock_unlock(vp, rl_cookie); + return (error); +} + +/* + * Truncate a file that is already locked. + */ +int +vn_truncate_locked(struct vnode *vp, off_t length, bool sync, + struct ucred *cred) +{ + struct vattr vattr; + int error; + error = VOP_ADD_WRITECOUNT(vp, 1); if (error == 0) { VATTR_NULL(&vattr); vattr.va_size = length; - if ((fp->f_flag & O_FSYNC) != 0) + if (sync) vattr.va_vaflags |= VA_SYNC; - error = VOP_SETATTR(vp, &vattr, fp->f_cred); + error = VOP_SETATTR(vp, &vattr, cred); VOP_ADD_WRITECOUNT_CHECKED(vp, -1); } -out: - VOP_UNLOCK(vp, 0); - vn_finished_write(mp); -out1: - vn_rangelock_unlock(vp, rl_cookie); return (error); } |