Module Name:    src
Committed By:   martin
Date:           Wed Apr 22 18:07:37 UTC 2020

Modified Files:
        src/lib/libc/sys [netbsd-9]: fdatasync.2
        src/sys/kern [netbsd-9]: vfs_syscalls.c

Log Message:
Pull up following revision(s) (requested by gdt in ticket #840):

        sys/kern/vfs_syscalls.c: revision 1.544
        lib/libc/sys/fdatasync.2: revision 1.17

Relax fdatasync restriction that fd be writable

The restriction that a fd passed to fdatasync(2) must be writable was
added in 2003 in order to comply with POSIX.  Since then, POSIX has
removed that requirement, and POSIX-valid programs have been therefore
encountering errors on NetBSD.

Patch by Paul Ripke after discussion on netbsd-users.  Issue
discovered with pkgsrc/databases/mongodb3 as used by pkgsrc/net/unifi.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.16.66.1 src/lib/libc/sys/fdatasync.2
cvs rdiff -u -r1.533 -r1.533.2.1 src/sys/kern/vfs_syscalls.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/sys/fdatasync.2
diff -u src/lib/libc/sys/fdatasync.2:1.16 src/lib/libc/sys/fdatasync.2:1.16.66.1
--- src/lib/libc/sys/fdatasync.2:1.16	Wed Apr 30 13:10:51 2008
+++ src/lib/libc/sys/fdatasync.2	Wed Apr 22 18:07:37 2020
@@ -1,4 +1,4 @@
-.\"	$NetBSD: fdatasync.2,v 1.16 2008/04/30 13:10:51 martin Exp $
+.\"	$NetBSD: fdatasync.2,v 1.16.66.1 2020/04/22 18:07:37 martin Exp $
 .\"
 .\" Copyright (c) 1998 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -68,7 +68,7 @@ function will fail if:
 .It Bq Er EBADF
 The
 .Fa fd
-argument is not a valid file descriptor open for writing.
+argument is not a valid file descriptor.
 .It Bq Er EINVAL
 This implementation does not support synchronized I/O for this file.
 .It Bq Er ENOSYS
@@ -93,4 +93,4 @@ and outstanding I/O operations are not g
 The
 .Fn fdatasync
 function conforms to
-.St -p1003.1b-93 .
+.St -p1003.1-2008 .

Index: src/sys/kern/vfs_syscalls.c
diff -u src/sys/kern/vfs_syscalls.c:1.533 src/sys/kern/vfs_syscalls.c:1.533.2.1
--- src/sys/kern/vfs_syscalls.c:1.533	Sat Jul  6 14:37:24 2019
+++ src/sys/kern/vfs_syscalls.c	Wed Apr 22 18:07:37 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_syscalls.c,v 1.533 2019/07/06 14:37:24 maxv Exp $	*/
+/*	$NetBSD: vfs_syscalls.c,v 1.533.2.1 2020/04/22 18:07:37 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.533 2019/07/06 14:37:24 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.533.2.1 2020/04/22 18:07:37 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_fileassoc.h"
@@ -4044,8 +4044,7 @@ sys_fsync(struct lwp *l, const struct sy
  * Sync a range of file data.  API modeled after that found in AIX.
  *
  * FDATASYNC indicates that we need only save enough metadata to be able
- * to re-read the written data.  Note we duplicate AIX's requirement that
- * the file be open for writing.
+ * to re-read the written data.
  */
 /* ARGSUSED */
 int
@@ -4126,10 +4125,6 @@ sys_fdatasync(struct lwp *l, const struc
 	/* fd_getvnode() will use the descriptor for us */
 	if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
 		return (error);
-	if ((fp->f_flag & FWRITE) == 0) {
-		fd_putfile(SCARG(uap, fd));
-		return (EBADF);
-	}
 	vp = fp->f_vnode;
 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
 	error = VOP_FSYNC(vp, fp->f_cred, FSYNC_WAIT|FSYNC_DATAONLY, 0, 0);

Reply via email to