mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-13 10:02:38 +00:00
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
This commit is contained in:
parent
23ced94451
commit
555d8f2859
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=349582
@ -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,15 +1315,8 @@ vn_truncate(struct file *fp, off_t length, struct ucred *active_cred,
|
||||
if (error)
|
||||
goto out;
|
||||
#endif
|
||||
error = VOP_ADD_WRITECOUNT(vp, 1);
|
||||
if (error == 0) {
|
||||
VATTR_NULL(&vattr);
|
||||
vattr.va_size = length;
|
||||
if ((fp->f_flag & O_FSYNC) != 0)
|
||||
vattr.va_vaflags |= VA_SYNC;
|
||||
error = VOP_SETATTR(vp, &vattr, fp->f_cred);
|
||||
VOP_ADD_WRITECOUNT_CHECKED(vp, -1);
|
||||
}
|
||||
error = vn_truncate_locked(vp, length, (fp->f_flag & O_FSYNC) != 0,
|
||||
fp->f_cred);
|
||||
out:
|
||||
VOP_UNLOCK(vp, 0);
|
||||
vn_finished_write(mp);
|
||||
@ -1333,6 +1325,28 @@ vn_truncate(struct file *fp, off_t length, struct ucred *active_cred,
|
||||
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 (sync)
|
||||
vattr.va_vaflags |= VA_SYNC;
|
||||
error = VOP_SETATTR(vp, &vattr, cred);
|
||||
VOP_ADD_WRITECOUNT_CHECKED(vp, -1);
|
||||
}
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*
|
||||
* File table vnode stat routine.
|
||||
*/
|
||||
|
@ -695,6 +695,8 @@ int vn_stat(struct vnode *vp, struct stat *sb, struct ucred *active_cred,
|
||||
int vn_start_write(struct vnode *vp, struct mount **mpp, int flags);
|
||||
int vn_start_secondary_write(struct vnode *vp, struct mount **mpp,
|
||||
int flags);
|
||||
int vn_truncate_locked(struct vnode *vp, off_t length, bool sync,
|
||||
struct ucred *cred);
|
||||
int vn_writechk(struct vnode *vp);
|
||||
int vn_extattr_get(struct vnode *vp, int ioflg, int attrnamespace,
|
||||
const char *attrname, int *buflen, char *buf, struct thread *td);
|
||||
|
Loading…
Reference in New Issue
Block a user