vfs: call vn_truncate_locked from kern_truncate

This fixes a bug where the syscall would not bump writecount.

PR:	263999
This commit is contained in:
Mateusz Guzik 2022-05-16 03:28:22 +02:00
parent 6b715687bd
commit ec3c225711

View file

@ -3460,7 +3460,6 @@ kern_truncate(struct thread *td, const char *path, enum uio_seg pathseg,
struct mount *mp; struct mount *mp;
struct vnode *vp; struct vnode *vp;
void *rl_cookie; void *rl_cookie;
struct vattr vattr;
struct nameidata nd; struct nameidata nd;
int error; int error;
@ -3480,18 +3479,21 @@ kern_truncate(struct thread *td, const char *path, enum uio_seg pathseg,
return (error); return (error);
} }
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
if (vp->v_type == VDIR) if (vp->v_type == VDIR) {
error = EISDIR; error = EISDIR;
goto out;
}
#ifdef MAC #ifdef MAC
else if ((error = mac_vnode_check_write(td->td_ucred, NOCRED, vp))) { error = mac_vnode_check_write(td->td_ucred, NOCRED, vp);
} if (error != 0)
goto out;
#endif #endif
else if ((error = vn_writechk(vp)) == 0 && error = VOP_ACCESS(vp, VWRITE, td->td_ucred, td);
(error = VOP_ACCESS(vp, VWRITE, td->td_ucred, td)) == 0) { if (error != 0)
VATTR_NULL(&vattr); goto out;
vattr.va_size = length;
error = VOP_SETATTR(vp, &vattr, td->td_ucred); error = vn_truncate_locked(vp, 0, false, td->td_ucred);
} out:
VOP_UNLOCK(vp); VOP_UNLOCK(vp);
vn_finished_write(mp); vn_finished_write(mp);
vn_rangelock_unlock(vp, rl_cookie); vn_rangelock_unlock(vp, rl_cookie);