[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: RFC: svn_io_file_flush_to_disk

From: Josh Pieper <jpieper_at_andrew.cmu.edu>
Date: 2004-05-01 18:26:59 CEST

Ok, included is a newer version of the patch that fixes up the
concerns that everyone had I think. Does this look alright?

-Josh

--------------------

Add a new function in svn_io, svn_io_file_flush_to_disk, which flushes
all data written to a file to disk. On Unix like systems, this
equates to fsync, for Win32, FlushFileBuffers is used.

* subversion/include/svn_io.h
* subversion/libsvn_subr/io.h
  (svn_io_file_flush_to_disk): New, flushes all data written to a file
    to disk.

* subversion/libsvn_fs_fs/fs_fs.c
  (write_final_current): Flush the 'current' file to disk before
    closing it.
  (svn_fs_fs__commit): Flush the new permanent rev-file to disk before
    closing it.

Index: subversion/include/svn_io.h
===================================================================
--- subversion/include/svn_io.h (revision 9593)
+++ subversion/include/svn_io.h (working copy)
@@ -324,6 +324,12 @@
                                svn_boolean_t exclusive,
                                apr_pool_t *pool);
 
+/** Flush any unwritten data from @a file to disk. Use @a pool for
+ * memory allocations.
+ */
+svn_error_t *svn_io_file_flush_to_disk (apr_file_t *file,
+ apr_pool_t *pool);
+
 /** Copy file @a file from location @a src_path to location @a dest_path.
  * Use @a pool for memory allocations.
  */
Index: subversion/libsvn_subr/io.c
===================================================================
--- subversion/libsvn_subr/io.c (revision 9593)
+++ subversion/libsvn_subr/io.c (working copy)
@@ -21,6 +21,10 @@
 #include <stdio.h>
 #include <assert.h>
 
+#ifndef WIN32
+#include <unistd.h>
+#endif
+
 #include <apr_lib.h>
 #include <apr_pools.h>
 #include <apr_file_io.h>
@@ -968,6 +972,50 @@
 
 
 
+/* Data consistency/coherency operations. */
+
+svn_error_t *svn_io_file_flush_to_disk (apr_file_t *file,
+ apr_pool_t *pool)
+{
+ /* First make sure that any user-space buffered data is flushed. */
+ apr_status_t apr_err;
+ apr_os_file_t filehand;
+
+ apr_err = apr_file_flush (file);
+
+ if (apr_err)
+ return svn_error_wrap_apr
+ (apr_err, "Can't flush file '%s' to disk.", file);
+
+ apr_os_file_get (&filehand, file);
+
+ /* Call the operating system specific function to actually force the
+ data to disk. */
+ {
+#ifdef WIN32
+
+ if (! FlushFileBuffers (filehand))
+ return svn_error_wrap_apr
+ (apr_get_os_error (), "Can't flush file to disk.");
+
+#else
+ apr_size_t rv;
+
+ do {
+ rv = fsync (filehand);
+ } while (rv == (apr_size_t)-1 && (errno == EAGAIN || errno == EINTR));
+
+ if (rv == (apr_size_t)-1)
+ return svn_error_wrap_apr
+ (apr_get_os_error (), "Can't flush file to disk.");
+
+#endif
+ }
+ return APR_SUCCESS;
+}
+
+
+
 /* TODO write test for these two functions, then refactor. */
 
 svn_error_t *
Index: subversion/libsvn_fs_fs/fs_fs.c
===================================================================
--- subversion/libsvn_fs_fs/fs_fs.c (revision 9593)
+++ subversion/libsvn_fs_fs/fs_fs.c (working copy)
@@ -3485,6 +3485,8 @@
 
   SVN_ERR (svn_io_file_write_full (file, buf, strlen (buf), NULL, pool));
 
+ SVN_ERR (svn_io_file_flush_to_disk (file, pool));
+
   SVN_ERR (svn_io_file_close (file, pool));
 
   SVN_ERR (move_into_place (tmp_name, name, name, pool));
@@ -3597,6 +3599,8 @@
                      changed_path_offset);
   SVN_ERR (svn_io_file_write_full (rev_file, buf, strlen (buf), NULL,
                                    subpool));
+
+ SVN_ERR (svn_io_file_flush_to_disk (rev_file, subpool));
   
   SVN_ERR (svn_io_file_close (rev_file, subpool));
 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sat May 1 18:27:12 2004

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.