Steffen Daode Nurpmeso <sdao...@googlemail.com> added the comment:
I'll attach 11877.4.diff:
- Docu change (i hope to be better)
- Kept NetBSD after looking into
http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/kern/vfs_syscalls.c?rev=1.423&content-type=text/x-cvsweb-markup&only_with_tag=MAIN
because fsync_range() with FDISKSYNC set causes a FSYNC_CACHE
flag to be passed through to VOP_FSYNC() in addition to
FSYNC_WAIT, which is what plain fsync() passes exclusively.
(I have not furtherly discovered that. FDISKSYNC was introduced
2005. I believe existence of such a flag will sooner or later
force somebody to make a difference in wether it is set or not.)
- Drop of AIX. According to the systems manual (link in
msg134213) there does not seem to be a difference in between
fsync() and fsync_range()
- Drop of Linux sync_file_range() (see messages above).
By the way, does Linux still require
----------
Added file: http://bugs.python.org/file21771/11877.4.diff
_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue11877>
_______________________________________
diff --git a/Doc/library/os.rst b/Doc/library/os.rst
--- a/Doc/library/os.rst
+++ b/Doc/library/os.rst
@@ -798,7 +798,7 @@
Availability: Unix.
-.. function:: fsync(fd)
+.. function:: fsync(fd, full_fsync=False)
Force write of file with filedescriptor *fd* to disk. On Unix, this calls
the
native :c:func:`fsync` function; on Windows, the MS :c:func:`_commit`
function.
@@ -807,6 +807,12 @@
``f.flush()``, and then do ``os.fsync(f.fileno())``, to ensure that all
internal
buffers associated with *f* are written to disk.
+ The POSIX standart only requires that :c:func:`fsync` must transfer the
+ buffered data to the storage device, not that the data is actually
+ written by the device itself. On operating systems where it is
+ necessary and possible the optional *full_fsync* argument can be used to
+ initiate additional steps to synchronize the physical backing store.
+
Availability: Unix, and Windows.
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -2119,13 +2119,55 @@
#ifdef HAVE_FSYNC
PyDoc_STRVAR(posix_fsync__doc__,
-"fsync(fildes)\n\n\
-force write of file with filedescriptor to disk.");
-
-static PyObject *
-posix_fsync(PyObject *self, PyObject *fdobj)
-{
- return posix_fildes(fdobj, fsync);
+"fsync(fildes, full_fsync=False)\n\n"
+"force write of file buffers with fildes to disk;\n"
+"full_fsync forces flush of disk caches in case fsync() alone is not enough.");
+
+static PyObject *
+posix_fsync(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+ PyObject *retval = NULL;
+ auto PyObject *fdobj;
+ auto int full_fsync = 1;
+ static char *keywords[] = {"fd", "full_fsync", NULL };
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|i", keywords,
+ &fdobj, &full_fsync))
+ goto jleave;
+
+ /* See issue 11877 discussion */
+# if ((defined __APPLE__ && defined F_FULLFSYNC) || \
+ (defined __NetBSD__ && defined FDISKSYNC))
+ if (full_fsync != 0) {
+ int res, fd = PyObject_AsFileDescriptor(fdobj);
+ if (fd < 0)
+ goto jleave;
+ if (!_PyVerify_fd(fd)) {
+ retval = posix_error();
+ goto jleave;
+ }
+
+ Py_BEGIN_ALLOW_THREADS
+# ifdef __APPLE__
+ res = fcntl(fd, F_FULLFSYNC);
+# endif
+# ifdef __NetBSD__
+ res = fsync_range(fd, FFILESYNC|FDISKSYNC, 0, 0);
+# endif
+ Py_END_ALLOW_THREADS
+
+ if (res < 0) {
+ retval = posix_error();
+ goto jleave;
+ }
+ Py_INCREF(Py_None);
+ retval = Py_None;
+ } else
+# endif
+ retval = posix_fildes(fdobj, fsync);
+
+jleave:
+ return retval;
}
#endif /* HAVE_FSYNC */
@@ -9470,7 +9512,8 @@
{"fchdir", posix_fchdir, METH_O, posix_fchdir__doc__},
#endif
#ifdef HAVE_FSYNC
- {"fsync", posix_fsync, METH_O, posix_fsync__doc__},
+ {"fsync", (PyCFunction)posix_fsync, METH_VARARGS|METH_KEYWORDS,
+ posix_fsync__doc__},
#endif
#ifdef HAVE_SYNC
{"sync", posix_sync, METH_NOARGS, posix_sync__doc__},
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com