From patchwork Fri Apr 15 19:09:42 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 711331 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p3FJL2Cs012783 for ; Fri, 15 Apr 2011 19:21:03 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756698Ab1DOTU5 (ORCPT ); Fri, 15 Apr 2011 15:20:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:11776 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756689Ab1DOTUw (ORCPT ); Fri, 15 Apr 2011 15:20:52 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p3FJKjkX030262 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 15 Apr 2011 15:20:45 -0400 Received: from test1244.test.redhat.com (test1244.test.redhat.com [10.10.10.244]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p3FJKhhZ022217; Fri, 15 Apr 2011 15:20:44 -0400 From: Josef Bacik To: linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org, chris.mason@oracle.com, hch@infradead.org Subject: [PATCH 2/2] Btrfs: switch to the ->fsync_nolock helper Date: Fri, 15 Apr 2011 15:09:42 -0400 Message-Id: <1302894582-24341-3-git-send-email-josef@redhat.com> In-Reply-To: <1302894582-24341-1-git-send-email-josef@redhat.com> References: <1302894582-24341-1-git-send-email-josef@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Fri, 15 Apr 2011 19:21:03 +0000 (UTC) Btrfs needs to be able to control how IO is submitted in the fsync case, so in preperation of this work convert to the ->fsync_nolock file op. Thanks, Signed-off-by: Josef Bacik --- fs/btrfs/ctree.h | 2 +- fs/btrfs/file.c | 27 ++++++++++++++++++--------- fs/btrfs/inode.c | 2 +- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index d5f043e..b409721 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -2567,7 +2567,7 @@ void btrfs_update_iflags(struct inode *inode); void btrfs_inherit_iflags(struct inode *inode, struct inode *dir); /* file.c */ -int btrfs_sync_file(struct file *file, int datasync); +int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end, int skip_pinned); int btrfs_check_file(struct btrfs_root *root, struct inode *inode); diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index cd5e82e..d50eea8 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -1194,19 +1194,23 @@ int btrfs_release_file(struct inode *inode, struct file *filp) * important optimization for directories because holding the mutex prevents * new operations on the dir while we write to disk. */ -int btrfs_sync_file(struct file *file, int datasync) +int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) { struct dentry *dentry = file->f_path.dentry; struct inode *inode = dentry->d_inode; struct btrfs_root *root = BTRFS_I(inode)->root; + int err; int ret = 0; struct btrfs_trans_handle *trans; trace_btrfs_sync_file(file, datasync); + err = filemap_write_and_wait_range(inode->i_mapping, start, end); + + mutex_lock(&inode->i_mutex); + /* we wait first, since the writeback may change the inode */ root->log_batch++; - /* the VFS called filemap_fdatawrite for us */ btrfs_wait_ordered_range(inode, 0, (u64)-1); root->log_batch++; @@ -1215,7 +1219,7 @@ int btrfs_sync_file(struct file *file, int datasync) * and see if its already been committed */ if (!BTRFS_I(inode)->last_trans) - goto out; + goto out_lock; /* * if the last transaction that changed this file was before @@ -1226,7 +1230,7 @@ int btrfs_sync_file(struct file *file, int datasync) if (BTRFS_I(inode)->last_trans <= root->fs_info->last_trans_committed) { BTRFS_I(inode)->last_trans = 0; - goto out; + goto out_lock; } /* @@ -1238,12 +1242,12 @@ int btrfs_sync_file(struct file *file, int datasync) trans = btrfs_start_transaction(root, 0); if (IS_ERR(trans)) { ret = PTR_ERR(trans); - goto out; + goto out_lock; } ret = btrfs_log_dentry_safe(trans, root, dentry); if (ret < 0) - goto out; + goto out_lock; /* we've logged all the items and now have a consistent * version of the file in the log. It is possible that @@ -1255,7 +1259,7 @@ int btrfs_sync_file(struct file *file, int datasync) * file again, but that will end up using the synchronization * inside btrfs_sync_log to keep things safe. */ - mutex_unlock(&dentry->d_inode->i_mutex); + mutex_unlock(&inode->i_mutex); if (ret != BTRFS_NO_LOG_SYNC) { if (ret > 0) { @@ -1270,8 +1274,13 @@ int btrfs_sync_file(struct file *file, int datasync) } else { ret = btrfs_end_transaction(trans, root); } - mutex_lock(&dentry->d_inode->i_mutex); + goto out; + +out_lock: + mutex_unlock(&inode->i_mutex); out: + if (!ret) + ret = err; return ret > 0 ? -EIO : ret; } @@ -1416,7 +1425,7 @@ const struct file_operations btrfs_file_operations = { .mmap = btrfs_file_mmap, .open = generic_file_open, .release = btrfs_release_file, - .fsync = btrfs_sync_file, + .fsync_nolock = btrfs_sync_file, .fallocate = btrfs_fallocate, .unlocked_ioctl = btrfs_ioctl, #ifdef CONFIG_COMPAT diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index b1e5b11..e80b999 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -7490,7 +7490,7 @@ static const struct file_operations btrfs_dir_file_operations = { .compat_ioctl = btrfs_ioctl, #endif .release = btrfs_release_file, - .fsync = btrfs_sync_file, + .fsync_nolock = btrfs_sync_file, }; static struct extent_io_ops btrfs_extent_io_ops = {