From patchwork Wed May 25 08:43:08 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 97311 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 38168B6F93 for ; Wed, 25 May 2011 18:43:22 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933129Ab1EYInU (ORCPT ); Wed, 25 May 2011 04:43:20 -0400 Received: from cantor.suse.de ([195.135.220.2]:45036 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932931Ab1EYInT (ORCPT ); Wed, 25 May 2011 04:43:19 -0400 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.suse.de (Postfix) with ESMTP id A6A198E8CC; Wed, 25 May 2011 10:43:17 +0200 (CEST) Received: by quack.suse.cz (Postfix, from userid 1000) id B026C20548; Wed, 25 May 2011 10:43:16 +0200 (CEST) From: Jan Kara To: linux-ext4@vger.kernel.org Cc: Christoph Hellwig , Ted Tso , Jan Kara Subject: [PATCH] ext4: Convert ext4 to new truncate calling convention Date: Wed, 25 May 2011 10:43:08 +0200 Message-Id: <1306312988-5508-1-git-send-email-jack@suse.cz> X-Mailer: git-send-email 1.7.1 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Mostly trivial conversion. We fix a bug that IS_IMMUTABLE and IS_APPEND files could not be truncated during failed writes as we change the code. Signed-off-by: Jan Kara --- fs/ext4/file.c | 1 - fs/ext4/inode.c | 24 ++++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) Ted, can you please merge this patch? Thanks. diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 7b80d54..2c09723 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -272,7 +272,6 @@ const struct file_operations ext4_file_operations = { }; const struct inode_operations ext4_file_inode_operations = { - .truncate = ext4_truncate, .setattr = ext4_setattr, .getattr = ext4_getattr, #ifdef CONFIG_EXT4_FS_XATTR diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 4eca654..0aa52b4 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3513,7 +3513,7 @@ retry: loff_t end = offset + iov_length(iov, nr_segs); if (end > isize) - vmtruncate(inode, isize); + ext4_truncate_failed_write(inode); } } if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)) @@ -4380,8 +4380,6 @@ static void ext4_free_branches(handle_t *handle, struct inode *inode, int ext4_can_truncate(struct inode *inode) { - if (IS_APPEND(inode) || IS_IMMUTABLE(inode)) - return 0; if (S_ISREG(inode->i_mode)) return 1; if (S_ISDIR(inode->i_mode)) @@ -5236,6 +5234,24 @@ int ext4_write_inode(struct inode *inode, struct writeback_control *wbc) return err; } +static int ext4_setsize(struct inode *inode, loff_t newsize) +{ + loff_t oldsize; + int rc; + + rc = inode_newsize_ok(inode, newsize); + if (rc) + return rc; + if (IS_APPEND(inode) || IS_IMMUTABLE(inode)) + return -EPERM; + oldsize = inode->i_size; + i_size_write(inode, newsize); + truncate_pagecache(inode, oldsize, newsize); + ext4_truncate(inode); + + return 0; +} + /* * ext4_setattr() * @@ -5353,7 +5369,7 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr) if ((attr->ia_valid & ATTR_SIZE) && attr->ia_size != i_size_read(inode)) - rc = vmtruncate(inode, attr->ia_size); + rc = ext4_setsize(inode, attr->ia_size); if (!rc) { setattr_copy(inode, attr);