From patchwork Mon Jan 28 03:44:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Liu X-Patchwork-Id: 216105 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 9EF262C007C for ; Mon, 28 Jan 2013 14:30:32 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753458Ab3A1Dab (ORCPT ); Sun, 27 Jan 2013 22:30:31 -0500 Received: from mail-da0-f51.google.com ([209.85.210.51]:33828 "EHLO mail-da0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753196Ab3A1Da3 (ORCPT ); Sun, 27 Jan 2013 22:30:29 -0500 Received: by mail-da0-f51.google.com with SMTP id i30so1034226dad.10 for ; Sun, 27 Jan 2013 19:30:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer; bh=tN7OOT+MM5Wa3U+oAyWUjfZUY9EilK6vzM4fmSoK2rw=; b=ixL/oY4m3D0FXAo6X8CExBPWMkVBPzbbKQDUyc5gSCaN7JwV6CRY02siIX4qgQFReC WUUAjLfsMJKSmji9J27NYQuXj702RPlBvpPPXBc8oQg06vH4HmM5likokUUYiMLZwAF6 tssXK9bgtAQb+2IivwVAO4XMieLgnLWTg4GZ0RjIvwMGBYMKTXYYUYDFD6e/GlCb2OHX FdglDqZI6cKPJNYFwgbhw8QL998yda2nAQmV+/qWbOS8UF3XH+tjD2yEUZd1Attbh0Z4 DTkChfQxiu0Ja46+5GSW7hbNreqA3NiGtBrIDdYTTHoXuci5OfylvrxcYHbHngmqFCwV IKHw== X-Received: by 10.68.241.232 with SMTP id wl8mr33926854pbc.144.1359343828882; Sun, 27 Jan 2013 19:30:28 -0800 (PST) Received: from lz-desktop.taobao.ali.com ([182.92.247.2]) by mx.google.com with ESMTPS id v2sm5816779paz.36.2013.01.27.19.30.24 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 27 Jan 2013 19:30:27 -0800 (PST) From: Zheng Liu To: linux-ext4@vger.kernel.org Cc: Zheng Liu , "Theodore Ts'o" Subject: [PATCH] ext4: correct the number of blocks that has been deallocated in ext4_free_hole_blocks Date: Mon, 28 Jan 2013 11:44:27 +0800 Message-Id: <1359344667-12068-1-git-send-email-wenqing.lz@taobao.com> X-Mailer: git-send-email 1.7.12.rc2.18.g61b472e Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Zheng Liu This commit fixes a bug in ext4_free_hole_blocks that iff the number of hole blocks is equal to EXT4_NDIR_BLOCKS and the first block of the hole is a direct block, the number of deallocated blocks is wrong. This bug can be triggered by the following commands: dd if=/dev/zero of=/mnt/testfile bs=4k count=16 xfs_io -c "fpunch 4k 48k" -c "fiemap -v" /mnt/testfile [wrong result] EXT: FILE-OFFSET BLOCK-RANGE TOTAL FLAGS 0: [0..7]: 274560..274567 8 0x1000 1: [8..95]: hole 88 2: [96..127]: 274656..274687 32 0x1001 [expected result] EXT: FILE-OFFSET BLOCK-RANGE TOTAL FLAGS 0: [0..7]: 278528..278535 8 0x1000 1: [8..103]: hole 96 2: [104..127]: 278632..278655 24 0x1001 Moreover this commit calls ext4_es_remove_extents() to remove some delayed extents from extent status tree because now extent status tree has been applied in the lastest kernel. Meanwhile we never disable dioread_nolock in ext4_ind_punch_hole() because this feature couldn't be enabled for a indirect-based file, and we don't flush any unwritten io because for a indirect-based file it needn't convert unwritten extents. Signed-off-by: Zheng Liu Cc: "Theodore Ts'o" --- [This patch bases against dev branch] fs/ext4/indirect.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c index 3a33ca2..96a5c1f 100644 --- a/fs/ext4/indirect.c +++ b/fs/ext4/indirect.c @@ -1582,7 +1582,7 @@ static int ext4_free_hole_blocks(handle_t *handle, struct inode *inode, level, first, count, num); if (ret) goto err; - if (count > max) + if (count > max - first) count -= max - first; else break; @@ -1661,15 +1661,11 @@ int ext4_ind_punch_hole(struct file *file, loff_t offset, loff_t length) } /* Wait all existing dio works, newcomers will block on i_mutex */ - ext4_inode_block_unlocked_dio(inode); - err = ext4_flush_unwritten_io(inode); - if (err) - goto out_dio; inode_dio_wait(inode); handle = start_transaction(inode); if (IS_ERR(handle)) - goto out_dio; + goto out_mutex; /* * Now we need to zero out the non-page-aligned data in the @@ -1738,6 +1734,8 @@ int ext4_ind_punch_hole(struct file *file, loff_t offset, loff_t length) down_write(&EXT4_I(inode)->i_data_sem); ext4_discard_preallocations(inode); + err = ext4_es_remove_extent(inode, first_block, + stop_block - first_block); err = ext4_free_hole_blocks(handle, inode, first_block, stop_block); ext4_discard_preallocations(inode); @@ -1752,8 +1750,6 @@ out: ext4_mark_inode_dirty(handle, inode); ext4_journal_stop(handle); -out_dio: - ext4_inode_resume_unlocked_dio(inode); out_mutex: mutex_unlock(&inode->i_mutex);