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

[PATCH 3/4] dpkg: Write back all files before first fsync



This basically ensures that the delayed allocation has been resolved;
that is, the data blocks have been allocated and written, and the
inode updated (in memory), but not necessarily pushed out to disk.

This way, on ext4 the first fsync() can force the inodes to disk and
the remaining fsync() become almost no-ops.

Suggested-and-explained-by: Ted Ts'o <tytso@mit.edu>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 src/archives.c |   20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/src/archives.c b/src/archives.c
index 17e8c89..ed00ce7 100644
--- a/src/archives.c
+++ b/src/archives.c
@@ -896,6 +896,24 @@ tar_deferred_extract(struct fileinlist *files, struct pkginfo *pkg)
   const char *usename;
 
   for (cfile = files; cfile; cfile = cfile->next) {
+    int fd;
+
+    if (!(cfile->namenode->flags & fnnf_deferred_fsync))
+      continue;
+    usenode = namenodetouse(cfile->namenode, pkg);
+    usename = usenode->name + 1; /* Skip the leading '/'. */
+    setupfnamevbs(usename);
+
+    fd = open(fnamenewvb.buf, O_WRONLY);
+    if (fd < 0)
+      ohshite(_("unable to open '%.255s'"), fnamenewvb.buf);
+    if (finish_writeback(fd))
+      ohshite(_("unable to write out file '%.255s'"), fnamenewvb.buf);
+    if (close(fd))
+      ohshite(_("error closing/writing `%.255s'"), fnamenewvb.buf);
+  }
+
+  for (cfile = files; cfile; cfile = cfile->next) {
     debug(dbg_eachfile, "deferred extract of '%.255s'", cfile->namenode->name);
 
     if (!(cfile->namenode->flags & fnnf_deferred_rename))
@@ -914,8 +932,6 @@ tar_deferred_extract(struct fileinlist *files, struct pkginfo *pkg)
       fd = open(fnamenewvb.buf, O_WRONLY);
       if (fd < 0)
         ohshite(_("unable to open '%.255s'"), fnamenewvb.buf);
-      if (finish_writeback(fd))
-        ohshite(_("unable to write out file '%.255s'"), fnamenewvb.buf);
       if (fsync(fd))
         ohshite(_("unable to sync file '%.255s'"), fnamenewvb.buf);
       if (close(fd))
-- 
1.7.2.3


Reply to: