diff mbox

[e2fsprogs] Add flag to ext2fs_flush and ext2fs_close to avoid fsync.

Message ID 20110923102342.GC31740@amd.home.annexia.org
State Accepted, archived
Headers show

Commit Message

Richard W.M. Jones Sept. 23, 2011, 10:23 a.m. UTC
[Hopefully sent to the right place this time ...]

This patch allows users of the ext2fs library to avoid doing an fsync
on close (obviously this is optional, and doesn't affect existing callers).

Where this helps us is when constructing a throwaway ext2 filesystem
just to boot a virtual machine.  By avoiding the 2 x fsync, we save
over 5 seconds and many many unnecessary disk writes.

Rich.

Comments

Theodore Ts'o Sept. 24, 2011, 4:53 p.m. UTC | #1
On Fri, Sep 23, 2011 at 11:23:42AM +0100, Richard W.M. Jones wrote:
> [Hopefully sent to the right place this time ...]
> 
> This patch allows users of the ext2fs library to avoid doing an fsync
> on close (obviously this is optional, and doesn't affect existing callers).
> 
> Where this helps us is when constructing a throwaway ext2 filesystem
> just to boot a virtual machine.  By avoiding the 2 x fsync, we save
> over 5 seconds and many many unnecessary disk writes.

Added to the e2fsprogs next branch, thanks.  It will be part of the
e2fsprogs 1.42 release.

						- Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/lib/ext2fs/closefs.c b/lib/ext2fs/closefs.c
index 51ef63c..128452a 100644
--- a/lib/ext2fs/closefs.c
+++ b/lib/ext2fs/closefs.c
@@ -261,6 +261,11 @@  static errcode_t write_backup_super(ext2_filsys fs, dgrp_t group,
 
 errcode_t ext2fs_flush(ext2_filsys fs)
 {
+	return ext2fs_flush2(fs, 0);
+}
+
+errcode_t ext2fs_flush2(ext2_filsys fs, int flags)
+{
 	dgrp_t		i;
 	errcode_t	retval;
 	unsigned long	fs_state;
@@ -401,14 +406,16 @@  write_primary_superblock_only:
 	ext2fs_swap_super(super_shadow);
 #endif
 
-	retval = io_channel_flush(fs->io);
+	if (!(flags & EXT2_FLAG_FLUSH_NO_SYNC))
+		retval = io_channel_flush(fs->io);
 	retval = write_primary_superblock(fs, super_shadow);
 	if (retval)
 		goto errout;
 
 	fs->flags &= ~EXT2_FLAG_DIRTY;
 
-	retval = io_channel_flush(fs->io);
+	if (!(flags & EXT2_FLAG_FLUSH_NO_SYNC))
+		retval = io_channel_flush(fs->io);
 errout:
 	fs->super->s_state = fs_state;
 #ifdef WORDS_BIGENDIAN
@@ -422,6 +429,11 @@  errout:
 
 errcode_t ext2fs_close(ext2_filsys fs)
 {
+	return ext2fs_close2(fs, 0);
+}
+
+errcode_t ext2fs_close2(ext2_filsys fs, int flags)
+{
 	errcode_t	retval;
 	int		meta_blks;
 	io_stats stats = 0;
@@ -446,7 +458,7 @@  errcode_t ext2fs_close(ext2_filsys fs)
 			fs->flags |= EXT2_FLAG_SUPER_ONLY | EXT2_FLAG_DIRTY;
 	}
 	if (fs->flags & EXT2_FLAG_DIRTY) {
-		retval = ext2fs_flush(fs);
+		retval = ext2fs_flush2(fs, flags);
 		if (retval)
 			return retval;
 	}
diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
index 1b9acc3..7fc398e 100644
--- a/lib/ext2fs/ext2fs.h
+++ b/lib/ext2fs/ext2fs.h
@@ -593,6 +593,12 @@  typedef struct stat ext2fs_struct_stat;
 #endif
 
 /*
+ * For ext2fs_close2 and ext2fs_flush2, this flag allows you to avoid
+ * the fsync call.
+ */
+#define EXT2_FLAG_FLUSH_NO_SYNC          1
+
+/*
  * function prototypes
  */
 
@@ -876,7 +882,9 @@  extern errcode_t ext2fs_check_desc(ext2_filsys fs);
 
 /* closefs.c */
 extern errcode_t ext2fs_close(ext2_filsys fs);
+extern errcode_t ext2fs_close2(ext2_filsys fs, int flags);
 extern errcode_t ext2fs_flush(ext2_filsys fs);
+extern errcode_t ext2fs_flush2(ext2_filsys fs, int flags);
 extern int ext2fs_bg_has_super(ext2_filsys fs, int group_block);
 extern errcode_t ext2fs_super_and_bgd_loc2(ext2_filsys fs,
 				    dgrp_t group,