Ensure that ftruncate(2) is performed synchronously when file is
opened in O_SYNC mode, at least for UFS. This also handles truncation, done due to the O_SYNC | O_TRUNC flags combination to open(2), in synchronous way. Noted by: bde Sponsored by: The FreeBSD Foundation MFC after: 2 weeks
This commit is contained in:
parent
4938741ac5
commit
3f7ca894de
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=300142
@ -1314,6 +1314,8 @@ vn_truncate(struct file *fp, off_t length, struct ucred *active_cred,
|
||||
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);
|
||||
}
|
||||
out:
|
||||
|
@ -286,6 +286,7 @@ struct vattr {
|
||||
*/
|
||||
#define VA_UTIMES_NULL 0x01 /* utimes argument was NULL */
|
||||
#define VA_EXCLUSIVE 0x02 /* exclusive create request */
|
||||
#define VA_SYNC 0x04 /* O_SYNC truncation */
|
||||
|
||||
/*
|
||||
* Flags for ioflag. (high 16 bits used to ask for read-ahead and
|
||||
|
@ -625,7 +625,8 @@ ufs_setattr(ap)
|
||||
*/
|
||||
return (0);
|
||||
}
|
||||
if ((error = UFS_TRUNCATE(vp, vap->va_size, IO_NORMAL,
|
||||
if ((error = UFS_TRUNCATE(vp, vap->va_size, IO_NORMAL |
|
||||
((vap->va_vaflags & VA_SYNC) != 0 ? IO_SYNC : 0),
|
||||
cred)) != 0)
|
||||
return (error);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user