From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755395AbZBPH3W (ORCPT ); Mon, 16 Feb 2009 02:29:22 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752594AbZBPH3K (ORCPT ); Mon, 16 Feb 2009 02:29:10 -0500 Received: from serv2.oss.ntt.co.jp ([222.151.198.100]:43122 "EHLO serv2.oss.ntt.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752426AbZBPH3J (ORCPT ); Mon, 16 Feb 2009 02:29:09 -0500 Subject: [2/3] ext3: call block_flush_device() on fsync From: Fernando Luis =?ISO-8859-1?Q?V=E1zquez?= Cao To: Theodore Tso Cc: Jan Kara , Alan Cox , Pavel Machek , kernel list , Jens Axboe , sandeen@redhat.com, fernando@kic.ac.jp, rwheeler@redhat.com, linux-fsdevel@vger.kernel.org In-Reply-To: <1234768181.32677.7.camel@sebastian.kern.oss.ntt.co.jp> References: <1232109069.13775.35.camel@sebastian.kern.oss.ntt.co.jp> <1232114101.13775.63.camel@sebastian.kern.oss.ntt.co.jp> <20090116163039.GE10617@duck.suse.cz> <1232185639.4831.18.camel@sebastian.kern.oss.ntt.co.jp> <1232186449.4831.29.camel@sebastian.kern.oss.ntt.co.jp> <20090119120349.GA10193@duck.suse.cz> <1233135913.5399.57.camel@sebastian.kern.oss.ntt.co.jp> <20090128095518.GA16554@duck.suse.cz> <1234434811.15270.7.camel@sebastian.kern.oss.ntt.co.jp> <1234435245.15433.19.camel@sebastian.kern.oss.ntt.co.jp> <20090215224659.GG10706@mini-me.lan> <1234768181.32677.7.camel@sebastian.kern.oss.ntt.co.jp> Content-Type: text/plain Organization: NTT Open Source Software Center Date: Mon, 16 Feb 2009 16:29:05 +0900 Message-Id: <1234769345.32677.28.camel@sebastian.kern.oss.ntt.co.jp> Mime-Version: 1.0 X-Mailer: Evolution 2.22.3.1 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To ensure that bits are truly on-disk after an fsync or fdatasync, we should force a disk flush explicitly when there is dirty data/metadata and the journal didn't emit a write barrier (either because metadata is not being synched or barriers are disabled). Signed-off-by: Fernando Luis Vazquez Cao --- diff -urNp linux-2.6.29-rc5-orig/fs/ext3/fsync.c linux-2.6.29-rc5/fs/ext3/fsync.c --- linux-2.6.29-rc5-orig/fs/ext3/fsync.c 2008-12-25 08:26:37.000000000 +0900 +++ linux-2.6.29-rc5/fs/ext3/fsync.c 2009-02-16 15:56:05.000000000 +0900 @@ -45,6 +45,8 @@ int ext3_sync_file(struct file * file, struct dentry *dentry, int datasync) { struct inode *inode = dentry->d_inode; + journal_t *journal = EXT3_SB(inode->i_sb)->s_journal; + unsigned long i_state = inode->i_state; int ret = 0; J_ASSERT(ext3_journal_current_handle() == NULL); @@ -69,23 +71,30 @@ int ext3_sync_file(struct file * file, s */ if (ext3_should_journal_data(inode)) { ret = ext3_force_commit(inode->i_sb); - goto out; + if (!(journal->j_flags & JFS_BARRIER)) + block_flush_device(inode->i_sb); + return ret; } - if (datasync && !(inode->i_state & I_DIRTY_DATASYNC)) - goto out; + if (datasync && !(i_state & I_DIRTY_DATASYNC)) { + if (i_state & I_DIRTY_PAGES) + block_flush_device(inode->i_sb); + return ret; + } /* * The VFS has written the file data. If the inode is unaltered * then we need not start a commit. */ - if (inode->i_state & (I_DIRTY_SYNC|I_DIRTY_DATASYNC)) { + if (i_state & (I_DIRTY_SYNC|I_DIRTY_DATASYNC)) { struct writeback_control wbc = { .sync_mode = WB_SYNC_ALL, .nr_to_write = 0, /* sys_fsync did this */ }; ret = sync_inode(inode, &wbc); + if (journal && !(journal->j_flags & JFS_BARRIER)) + block_flush_device(inode->i_sb); } -out: + return ret; }