From patchwork Thu Mar 11 15:40:30 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Monakhov X-Patchwork-Id: 47343 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 2B4DFB7CB6 for ; Fri, 12 Mar 2010 02:40:46 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933103Ab0CKPkf (ORCPT ); Thu, 11 Mar 2010 10:40:35 -0500 Received: from mail-bw0-f209.google.com ([209.85.218.209]:64955 "EHLO mail-bw0-f209.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933074Ab0CKPke (ORCPT ); Thu, 11 Mar 2010 10:40:34 -0500 Received: by bwz1 with SMTP id 1so152375bwz.21 for ; Thu, 11 Mar 2010 07:40:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:from:to:subject:cc :date:message-id:user-agent:mime-version:content-type; bh=IluO6CeMk0IcV9lxM0s1+TEJaNKCt+k3ben2oNw6xv8=; b=I/XJ3vaYPvV+lc/uWoK4m26Z+DjKByQz6Cdnm9kJCWyhW0kpt+lAfJaHWd6JUId+9F 9Eyq2I+GdyJGGOlaQH4+dVUr3RaEVoL3t4itb9Pe90ATXOPM2odSDP48EDOdmS3oZuMj UZKsHJVXWevbLRh/kTAUgD2pagrr4NBC8dlUE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:subject:cc:date:message-id:user-agent:mime-version :content-type; b=nG+vSkD5E5EhEhUb1bWOBdk0YsJR+NFtrmK7djXEJRVlL9EFzishIZ85qYEFSrHRFC ZNsH/y6Na3jzdYTDZk3kISy/NmJGtvuib/iIeQhAYT0lw4f545yIp+eRd5SJU8drAQMQ eWQ2Zsuxx+yV4/gDj4JfBfJ9JinrY6rTcBLmE= Received: by 10.204.140.4 with SMTP id g4mr1329276bku.170.1268322032310; Thu, 11 Mar 2010 07:40:32 -0800 (PST) Received: from dmon-lp (swsoft-msk-nat.sw.ru [195.214.232.10]) by mx.google.com with ESMTPS id 16sm61842bwz.9.2010.03.11.07.40.31 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 11 Mar 2010 07:40:31 -0800 (PST) From: Dmitry Monakhov To: linux-ext4@vger.kernel.org Subject: [PATCH] ext4: fix io-barrier logic for external journal case CC: Theodore Ts'o , Jan Kara Date: Thu, 11 Mar 2010 18:40:30 +0300 Message-ID: <87wrxij28h.fsf@openvz.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux) MIME-Version: 1.0 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org We have to submit barrier before we start journal commit process. otherwise transaction may be committed before data flushed to disk. There is no difference from performance of view, but definitely fsync becomes more correct. If jbd2_log_start_commit return 0 then it means that transaction was already committed. So we don't have to issue barrier for ordered mode, because it was already done during commit. By unknown reason we ignored ret val from jbd2_log_wait_commit() so even in case of EIO fsync will succeed. Signed-off-by: Dmitry Monakhov --- fs/ext4/fsync.c | 28 +++++++++++++--------------- 1 files changed, 13 insertions(+), 15 deletions(-) diff --git a/fs/ext4/fsync.c b/fs/ext4/fsync.c index 0d0c323..621a8ed 100644 --- a/fs/ext4/fsync.c +++ b/fs/ext4/fsync.c @@ -88,21 +88,19 @@ int ext4_sync_file(struct file *file, struct dentry *dentry, int datasync) return ext4_force_commit(inode->i_sb); commit_tid = datasync ? ei->i_datasync_tid : ei->i_sync_tid; - if (jbd2_log_start_commit(journal, commit_tid)) { - /* - * When the journal is on a different device than the - * fs data disk, we need to issue the barrier in - * writeback mode. (In ordered mode, the jbd2 layer - * will take care of issuing the barrier. In - * data=journal, all of the data blocks are written to - * the journal device.) - */ - if (ext4_should_writeback_data(inode) && - (journal->j_fs_dev != journal->j_dev) && - (journal->j_flags & JBD2_BARRIER)) - blkdev_issue_flush(inode->i_sb->s_bdev, NULL); - jbd2_log_wait_commit(journal, commit_tid); - } else if (journal->j_flags & JBD2_BARRIER) + /* + * When the journal is on a different device than the + * fs data disk, we need to issue the barrier in + * writeback mode. (In ordered mode, the jbd2 layer + * will take care of issuing the barrier. In + * data=journal, all of the data blocks are written to + * the journal device.) + */ + if (ext4_should_writeback_data(inode) && + (journal->j_fs_dev != journal->j_dev) && + (journal->j_flags & JBD2_BARRIER)) blkdev_issue_flush(inode->i_sb->s_bdev, NULL); + if (jbd2_log_start_commit(journal, commit_tid)) + ret = jbd2_log_wait_commit(journal, commit_tid); return ret; }