Author: kib
Date: Wed Jun  1 04:07:33 2016
New Revision: 301100
URL: https://svnweb.freebsd.org/changeset/base/301100

Log:
  MFC r300142:
  Ensure that ftruncate(2) is performed synchronously when file is
  opened in O_SYNC mode, at least for UFS.

Modified:
  stable/10/sys/kern/vfs_vnops.c
  stable/10/sys/sys/vnode.h
  stable/10/sys/ufs/ufs/ufs_vnops.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/kern/vfs_vnops.c
==============================================================================
--- stable/10/sys/kern/vfs_vnops.c      Wed Jun  1 04:03:55 2016        
(r301099)
+++ stable/10/sys/kern/vfs_vnops.c      Wed Jun  1 04:07:33 2016        
(r301100)
@@ -1372,6 +1372,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: stable/10/sys/sys/vnode.h
==============================================================================
--- stable/10/sys/sys/vnode.h   Wed Jun  1 04:03:55 2016        (r301099)
+++ stable/10/sys/sys/vnode.h   Wed Jun  1 04:07:33 2016        (r301100)
@@ -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: stable/10/sys/ufs/ufs/ufs_vnops.c
==============================================================================
--- stable/10/sys/ufs/ufs/ufs_vnops.c   Wed Jun  1 04:03:55 2016        
(r301099)
+++ stable/10/sys/ufs/ufs/ufs_vnops.c   Wed Jun  1 04:07:33 2016        
(r301100)
@@ -626,7 +626,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);
        }
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to