From: Richard W.M. Jones Date: Sat, 24 Sep 2011 14:50:42 +0000 (-0400) Subject: libext2fs: add flag to ext2fs_flush() and ext2fs_close() to avoid fsync X-Git-Tag: v1.42-WIP-0925~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9d9a53e651fa877eb4f9df0bfd97fbcc5f514293;p=thirdparty%2Fe2fsprogs.git libext2fs: add flag to ext2fs_flush() and ext2fs_close() to avoid fsync This adds new APIs: ext2fs_flush2 and ext2fs_close2 which take an extra 'int flags' parameter. This allows us to pass in an EXT2_FLAG_FLUSH_NO_SYNC flag which avoids fsync'ing the filesystem when closing it. For the case we have in mind where we are just constructing a throwaway ext2 filesystem in a file in order to boot a VM, this saves over 5 seconds during the boot process and avoids many unnecessary disk writes. Existing code using ext2fs_flush and ext2fs_close remains unaffected by this change. Signed-off-by: Richard W.M. Jones Signed-off-by: Theodore Ts'o --- diff --git a/debian/e2fslibs.symbols b/debian/e2fslibs.symbols index 59855df7c..62de921b6 100644 --- a/debian/e2fslibs.symbols +++ b/debian/e2fslibs.symbols @@ -105,6 +105,7 @@ libext2fs.so.2 e2fslibs #MINVER# ext2fs_clear_generic_bitmap@Base 1.41.0 ext2fs_clear_generic_bmap@Base 1.41.99 ext2fs_clear_inode_bitmap@Base 1.37 + ext2fs_close2@Base 1.41.99 ext2fs_close@Base 1.37 ext2fs_close_inode_scan@Base 1.37 ext2fs_compare_block_bitmap@Base 1.37 @@ -195,6 +196,7 @@ libext2fs.so.2 e2fslibs #MINVER# ext2fs_file_set_size@Base 1.37 ext2fs_file_write@Base 1.37 ext2fs_find_block_device@Base 1.37 + ext2fs_flush2@Base 1.41.99 ext2fs_flush@Base 1.37 ext2fs_flush_icache@Base 1.37 ext2fs_follow_link@Base 1.37 diff --git a/lib/ext2fs/closefs.c b/lib/ext2fs/closefs.c index 9141944ea..97ad37f71 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; @@ -402,14 +407,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; @@ -447,7 +459,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 1b9acc305..c3237dbf7 100644 --- a/lib/ext2fs/ext2fs.h +++ b/lib/ext2fs/ext2fs.h @@ -592,6 +592,12 @@ typedef struct stat64 ext2fs_struct_stat; 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,