Date: Wed, 18 May 2016 12:03:58 +0000 (UTC) From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r300142 - in head/sys: kern sys ufs/ufs Message-ID: <201605181203.u4IC3wwF061937@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kib Date: Wed May 18 12:03:57 2016 New Revision: 300142 URL: https://svnweb.freebsd.org/changeset/base/300142 Log: 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 Modified: head/sys/kern/vfs_vnops.c head/sys/sys/vnode.h head/sys/ufs/ufs/ufs_vnops.c Modified: head/sys/kern/vfs_vnops.c ============================================================================== --- head/sys/kern/vfs_vnops.c Wed May 18 12:02:05 2016 (r300141) +++ head/sys/kern/vfs_vnops.c Wed May 18 12:03:57 2016 (r300142) @@ -1314,6 +1314,8 @@ vn_truncate(struct file *fp, off_t lengt 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: Modified: head/sys/sys/vnode.h ============================================================================== --- head/sys/sys/vnode.h Wed May 18 12:02:05 2016 (r300141) +++ head/sys/sys/vnode.h Wed May 18 12:03:57 2016 (r300142) @@ -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 Modified: head/sys/ufs/ufs/ufs_vnops.c ============================================================================== --- head/sys/ufs/ufs/ufs_vnops.c Wed May 18 12:02:05 2016 (r300141) +++ head/sys/ufs/ufs/ufs_vnops.c Wed May 18 12:03:57 2016 (r300142) @@ -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); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201605181203.u4IC3wwF061937>