]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Speed up test suite by avoiding fsync
authorColin Watson <cjwatson@ubuntu.com>
Wed, 27 Nov 2013 10:06:07 +0000 (10:06 +0000)
committerColin Watson <cjwatson@ubuntu.com>
Wed, 27 Nov 2013 10:10:22 +0000 (10:10 +0000)
Add grub_util_disable_fd_syncs call to turn grub_util_fd_sync calls into
no-ops, and use it in programs that copy files but do not need to take
special care to sync writes (grub-mknetdir, grub-rescue,
grub-mkstandalone).

On my laptop, this reduces partmap_test's runtime from 1236 seconds to
204 seconds.

ChangeLog
grub-core/osdep/aros/hostdisk.c
grub-core/osdep/unix/hostdisk.c
grub-core/osdep/windows/hostdisk.c
include/grub/emu/hostfile.h
util/grub-install-common.c
util/grub-mknetdir.c
util/grub-mkrescue.c
util/grub-mkstandalone.c

index 2e0d96e5135804442a36c391eb6ad2c374dbd249..4bbec8607ace869dcb9aa7b90f638859ad53e0e2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2013-11-27  Colin Watson  <cjwatson@ubuntu.com>
+
+       Add grub_util_disable_fd_syncs call to turn grub_util_fd_sync calls
+       into no-ops, and use it in programs that copy files but do not need
+       to take special care to sync writes (grub-mknetdir, grub-rescue,
+       grub-mkstandalone).
+
 2013-11-26  Colin Watson  <cjwatson@ubuntu.com>
 
        * tests/util/grub-fs-tester.in: Execute xorriso from $PATH rather
index 9c0a6c895e8840919d09b3bb75778cdb222a5cbe..b1539076683ad24758364669511930951768d74e 100644 (file)
@@ -455,6 +455,8 @@ grub_util_fd_close (grub_util_fd_t fd)
     }
 }
 
+static int allow_fd_syncs = 1;
+
 static void
 grub_util_fd_sync_volume (grub_util_fd_t fd)
 {
@@ -469,17 +471,26 @@ grub_util_fd_sync_volume (grub_util_fd_t fd)
 void
 grub_util_fd_sync (grub_util_fd_t fd)
 {
-  switch (fd->type)
+  if (allow_fd_syncs)
     {
-    case GRUB_UTIL_FD_FILE:
-      fsync (fd->fd);
-      return;
-    case GRUB_UTIL_FD_DISK:
-      grub_util_fd_sync_volume (fd);
-      return;
+      switch (fd->type)
+       {
+       case GRUB_UTIL_FD_FILE:
+         fsync (fd->fd);
+         return;
+       case GRUB_UTIL_FD_DISK:
+         grub_util_fd_sync_volume (fd);
+         return;
+       }
     }
 }
 
+void
+grub_util_disable_fd_syncs (void)
+{
+  allow_fd_syncs = 0;
+}
+
 void
 grub_hostdisk_flush_initial_buffer (const char *os_dev __attribute__ ((unused)))
 {
index 78d4adb71b41fa72685323e8233b402f2d880dcb..fc88ed4cc2a53f2012d40b4945a9d40852358244 100644 (file)
@@ -191,10 +191,19 @@ grub_util_fd_strerror (void)
   return strerror (errno);
 }
 
+static int allow_fd_syncs = 1;
+
 void
 grub_util_fd_sync (grub_util_fd_t fd)
 {
-  fsync (fd);
+  if (allow_fd_syncs)
+    fsync (fd);
+}
+
+void
+grub_util_disable_fd_syncs (void)
+{
+  allow_fd_syncs = 0;
 }
 
 void
index 6d7d12097297fe0ba655fb544941891fc4381f24..4748a616fe0464b362e09411becd3bc949dd7d80 100644 (file)
@@ -240,10 +240,19 @@ grub_util_fd_write (grub_util_fd_t fd, const char *buf, size_t len)
   return real_read;
 }
 
+static int allow_fd_syncs = 1;
+
 void
 grub_util_fd_sync (grub_util_fd_t fd)
 {
-  FlushFileBuffers (fd);
+  if (allow_fd_syncs)
+    FlushFileBuffers (fd);
+}
+
+void
+grub_util_disable_fd_syncs (void)
+{
+  allow_fd_syncs = 0;
 }
 
 void
index ab01fbce8d41c5970cb890c7cec1181c44f154ac..8e37d5acb42b18c71de5d377dc1ab69cd75e1586 100644 (file)
@@ -50,6 +50,8 @@ EXPORT_FUNC(grub_util_fd_strerror) (void);
 void
 grub_util_fd_sync (grub_util_fd_t fd);
 void
+grub_util_disable_fd_syncs (void);
+void
 EXPORT_FUNC(grub_util_fd_close) (grub_util_fd_t fd);
 
 grub_uint64_t
index 7ecef3e59b89d6e458f089083b9c24bc24be3265..fcf994d5b5be311359ea1c6b1828fe31e1893524 100644 (file)
@@ -492,7 +492,7 @@ grub_install_make_image_wrap (const char *dir, const char *prefix,
                                     memdisk_path, config_path,
                                     mkimage_target, note, comp);
   fflush (fp);
-  fsync (fileno (fp));
+  grub_util_fd_sync (fileno (fp));
   fclose (fp);
 }
 
index 3f9170597aac6090134fd8f9cb83d41ac1a024a1..40ca7248b0d16570b0fcb3eb354d4332e445d6ab 100644 (file)
@@ -171,6 +171,7 @@ main (int argc, char *argv[])
   const char *pkglibdir;
 
   grub_util_host_init (&argc, &argv);
+  grub_util_disable_fd_syncs ();
   rootdir = xstrdup ("/srv/tftp");
   pkglibdir = grub_util_get_pkglibdir ();
 
index 7a76bc37a49f97aae1a9cf2cc3e597b6e035de69..b081b3b213d7ee168508f18fffa05fa5965dff5d 100644 (file)
@@ -369,6 +369,7 @@ main (int argc, char *argv[])
   const char *pkgdatadir;
 
   grub_util_host_init (&argc, &argv);
+  grub_util_disable_fd_syncs ();
 
   pkgdatadir = grub_util_get_pkgdatadir ();
 
@@ -529,7 +530,7 @@ main (int argc, char *argv[])
                                            GRUB_COMPRESSION_AUTO);
              sz = ftello (sa);
              fflush (sa);
-             fsync (fileno (sa));
+             grub_util_fd_sync (fileno (sa));
              fclose (sa);
              
              if (sz > 32768)
index 774af2f790016cbd2fb223b3b441a3c3692c507e..3097f704d8e4d28fb30d1d113d16c2c560549423 100644 (file)
@@ -305,6 +305,7 @@ main (int argc, char *argv[])
   int i;
 
   grub_util_host_init (&argc, &argv);
+  grub_util_disable_fd_syncs ();
 
   files = xmalloc ((argc + 1) * sizeof (files[0]));