From patchwork Tue Jul 10 16:26:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashish Sangwan X-Patchwork-Id: 170244 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 3F5692C00E7 for ; Wed, 11 Jul 2012 02:26:45 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754047Ab2GJQ0n (ORCPT ); Tue, 10 Jul 2012 12:26:43 -0400 Received: from mail-gh0-f174.google.com ([209.85.160.174]:50768 "EHLO mail-gh0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754028Ab2GJQ0m (ORCPT ); Tue, 10 Jul 2012 12:26:42 -0400 Received: by ghrr11 with SMTP id r11so174354ghr.19 for ; Tue, 10 Jul 2012 09:26:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=gvARMsqoH2qbwChdpLOLRJItU4364k0mqfYlGcqEroY=; b=yOFggKZTaF0mBIsD2jFcoMWLLi82NzpTHiwaiwAe2nNSQcBkd6tDwE2EQvZMYLUbMW beyQo1q3iV86xwRi/86lpdFTz52f6jkTkx8YdwtGCBdgvtGI7otXdt8eIXbrHdvINDzL BYun+a2SnQXXgy3X90FMHjWXDkhk+E5S9bPbcXII0XSzei20L7iHwADZ4qZ8GjfnIqNC RFzwWJIjnx4eEgI8bGm87fJ5mvF65JEJf/IlHwqWdDBeFtGHb7lKgDva2oU7wJ7NpA+U q3zaqPdw5mIV1Xkv/kIe+vlRJ/u3UoFJRVHzY7y1KAGnYcERqpkcCS6OD1ZSscb1jBHv xuKQ== Received: by 10.66.80.193 with SMTP id t1mr58748784pax.40.1341937601554; Tue, 10 Jul 2012 09:26:41 -0700 (PDT) Received: from sputnik.202.56.215.29 ([122.177.241.249]) by mx.google.com with ESMTPS id of1sm30149901pbb.15.2012.07.10.09.26.38 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 10 Jul 2012 09:26:40 -0700 (PDT) From: Ashish Sangwan To: Ted Tso Cc: linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, lczerner@redhat.com, Ashish Sangwan , Namjae Jeon Subject: [PATCH v3] ext4: fix hole punch failure when depth is greater than 0 Date: Tue, 10 Jul 2012 21:56:10 +0530 Message-Id: <1341937570-5229-1-git-send-email-ashish.sangwan2@gmail.com> X-Mailer: git-send-email 1.7.10.4 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Whether to continue removing extents or not is decided by the return value of function ext4_ext_more_to_rm() which checks 2 conditions: a) if there are no more indexes to process. b) if the number of entries are decreased in the header of "depth -1". In case of hole punch, if the last block to be removed is not part of the last extent index than this index will not be deleted, hence the number of valid entries in the extent header of "depth - 1" will remain as it is and ext4_ext_more_to_rm will return 0 although the required blocks are not yet removed. This patch fixes the above mentioned problem as instead of removing the extents from the end of file, it starts removing the blocks from the particular extent from which removing blocks is actually required and continue backward until done. Signed-off-by: Ashish Sangwan Signed-off-by: Namjae Jeon Reviewed-by: Lukas Czerner --- fs/ext4/extents.c | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 91341ec..45ac45d 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -2570,10 +2570,10 @@ static int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start, { struct super_block *sb = inode->i_sb; int depth = ext_depth(inode); - struct ext4_ext_path *path; + struct ext4_ext_path *path = NULL; ext4_fsblk_t partial_cluster = 0; handle_t *handle; - int i, err; + int i = 0, err; ext_debug("truncate since %u to %u\n", start, end); @@ -2606,8 +2606,12 @@ again: } depth = ext_depth(inode); ex = path[depth].p_ext; - if (!ex) + if (!ex) { + ext4_ext_drop_refs(path); + kfree(path); + path = NULL; goto cont; + } ee_block = le32_to_cpu(ex->ee_block); @@ -2637,8 +2641,6 @@ again: if (err < 0) goto out; } - ext4_ext_drop_refs(path); - kfree(path); } cont: @@ -2647,19 +2649,27 @@ cont: * after i_size and walking into the tree depth-wise. */ depth = ext_depth(inode); - path = kzalloc(sizeof(struct ext4_ext_path) * (depth + 1), GFP_NOFS); - if (path == NULL) { - ext4_journal_stop(handle); - return -ENOMEM; - } - path[0].p_depth = depth; - path[0].p_hdr = ext_inode_hdr(inode); + if (path) { + int k = i = depth; + while (--k > 0) + path[k].p_block = + le16_to_cpu(path[k].p_hdr->eh_entries)+1; + } else { + path = kzalloc(sizeof(struct ext4_ext_path) * (depth + 1), + GFP_NOFS); + if (path == NULL) { + ext4_journal_stop(handle); + return -ENOMEM; + } + path[0].p_depth = depth; + path[0].p_hdr = ext_inode_hdr(inode); - if (ext4_ext_check(inode, path[0].p_hdr, depth)) { - err = -EIO; - goto out; + if (ext4_ext_check(inode, path[0].p_hdr, depth)) { + err = -EIO; + goto out; + } } - i = err = 0; + err = 0; while (i >= 0 && err == 0) { if (i == depth) { @@ -2773,8 +2783,10 @@ cont: out: ext4_ext_drop_refs(path); kfree(path); - if (err == -EAGAIN) + if (err == -EAGAIN) { + path = NULL; goto again; + } ext4_journal_stop(handle); return err;