From patchwork Tue May 17 22:59:26 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaying Zhang X-Patchwork-Id: 96080 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 DD5E6B6EE9 for ; Wed, 18 May 2011 08:59:32 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932551Ab1EQW7b (ORCPT ); Tue, 17 May 2011 18:59:31 -0400 Received: from smtp-out.google.com ([74.125.121.67]:57060 "EHLO smtp-out.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932544Ab1EQW7a (ORCPT ); Tue, 17 May 2011 18:59:30 -0400 Received: from kpbe14.cbf.corp.google.com (kpbe14.cbf.corp.google.com [172.25.105.78]) by smtp-out.google.com with ESMTP id p4HMxSJ1023635; Tue, 17 May 2011 15:59:28 -0700 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=google.com; s=beta; t=1305673168; bh=f3Yu63DbBtAUTF8aW7A9Tapj1+o=; h=To:Subject:Cc:Message-Id:Date:From; b=RUiaOdcc3D1FnZfcL629qjLoBtFJD18oH2YdTrOkL8sSTJDt6AEvLUtM9pY+ghXuH hPeOySDz2/++Tuj6peGsw== DomainKey-Signature: a=rsa-sha1; s=beta; d=google.com; c=nofws; q=dns; h=to:subject:cc:message-id:date:from:x-system-of-record; b=LJ2WyX9lEWm1HcfsgLyMY2MXuxGkjdDIlmamnfOgzbE0oyJIe7YYs7d0PYn+n3KgB PfKram4tX7PxsM3VzGTrQ== Received: from ruihe.smo.corp.google.com (ruihe.smo.corp.google.com [172.29.60.109]) by kpbe14.cbf.corp.google.com with ESMTP id p4HMxQWY023470; Tue, 17 May 2011 15:59:27 -0700 Received: by ruihe.smo.corp.google.com (Postfix, from userid 44100) id 8B4A94225B; Tue, 17 May 2011 15:59:26 -0700 (PDT) To: tytso@mit.edu Subject: [PATCH] ext4: use vmtruncate() instead of ext4_truncate() in ext4_setattr() Cc: linux-ext4@vger.kernel.org Message-Id: <20110517225926.8B4A94225B@ruihe.smo.corp.google.com> Date: Tue, 17 May 2011 15:59:26 -0700 (PDT) From: jiayingz@google.com (Jiaying Zhang) X-System-Of-Record: true Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org There is a bug in commit c8d46e41 "ext4: Add flag to files with blocks intentionally past EOF" that if we fallocate a file with FALLOC_FL_KEEP_SIZE flag and then ftruncate the file to a size larger than the file's i_size, any allocated but unwritten blocks will be freed but the file size is set to the size that ftruncate specifies. Here is a simple test to reproduce the problem: 1. fallocate a 12k size file with KEEP_SIZE flag 2. write the first 4k 3. ftruncate the file to 8k Then 'ls -l' shows that the i_size of the file becomes 8k but debugfs shows the file has only the first written block left. Below is the proposed patch to fix the bug: ext4: use vmtruncate() instead of ext4_truncate() in ext4_setattr(). Change ext4_setattr() to use vmtruncate(inode, attr->ia_size) instead of ext4_truncate(inode) when it needs to truncate an inode so that if the inode has EXT4_EOFBLOCKS_FL flag set and we are trying to truncate to a size larger than the inode's i_size, we will only truncate the blocks beyond the specified truncate size instead of all of blocks beyond i_size. Signed-off-by: Jiaying Zhang --- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 3424e82..3bfad57 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5347,8 +5347,11 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr) } } /* ext4_truncate will clear the flag */ - if ((ext4_test_inode_flag(inode, EXT4_INODE_EOFBLOCKS))) - ext4_truncate(inode); + if ((ext4_test_inode_flag(inode, EXT4_INODE_EOFBLOCKS))) { + rc = vmtruncate(inode, attr->ia_size); + if (rc) + goto err_out; + } } if ((attr->ia_valid & ATTR_SIZE) &&