Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

PATCH: Relax fdatasync checks to IEEE Std 1003.1-2008



Currently, fdatasync requires a file descriptor open for writing, as
per IEEE Std 1003.1, 2004:
[EBADF]
The fildes argument is not a valid file descriptor open for writing.
https://pubs.opengroup.org/onlinepubs/009695399/functions/fdatasync.html

While, IEEE Std 1003.1-2008 (and later revisions):
[EBADF]
The fildes argument is not a valid file descriptor.
https://pubs.opengroup.org/onlinepubs/9699919799/functions/fdatasync.html

It would appear that mongodb (and likely others) rely on this new
behaviour, and we're now carrying a pkgsrc patch:
https://github.com/NetBSD/pkgsrc/blob/trunk/databases/mongodb3/patches/patch-src_third__party_wiredtiger_src_os__posix_os__fs.c

The attached patch removes the check and updates the manpage. I've
booted it under qemu and run some toy code against it (not an
unpatched mongodb, yet), and it looks fine. Thoughts?

-- 
Paul Ripke
"Great minds discuss ideas, average minds discuss events, small minds
 discuss people."
-- Disputed: Often attributed to Eleanor Roosevelt. 1948.
diff --git a/lib/libc/sys/fdatasync.2 b/lib/libc/sys/fdatasync.2
index 3f12119f0dbb..20da609191f5 100644
--- a/lib/libc/sys/fdatasync.2
+++ b/lib/libc/sys/fdatasync.2
@@ -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 guaranteed to have been completed.
 The
 .Fn fdatasync
 function conforms to
-.St -p1003.1b-93 .
+.St -p1003.1-2008 .
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index d51beedbfca9..267dd5bc6365 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -4141,10 +4141,6 @@ sys_fdatasync(struct lwp *l, const struct sys_fdatasync_args *uap, register_t *r
 	/* 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);


Home | Main Index | Thread Index | Old Index