From patchwork Fri Feb 22 05:34:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eryu Guan X-Patchwork-Id: 222467 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 98B262C02A1 for ; Fri, 22 Feb 2013 16:34:37 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751699Ab3BVFeg (ORCPT ); Fri, 22 Feb 2013 00:34:36 -0500 Received: from mail-pa0-f49.google.com ([209.85.220.49]:34742 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750866Ab3BVFeg (ORCPT ); Fri, 22 Feb 2013 00:34:36 -0500 Received: by mail-pa0-f49.google.com with SMTP id kp6so260422pab.36 for ; Thu, 21 Feb 2013 21:34:35 -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=T9kGNhoZYuWJo7igskW5IZJJwZZizCEOQag7khOrUIg=; b=TPtRTXchGB6Pc1LqMfisepu1Kw5KGLnMf4Wjs8t5loDa7cSSnI04G8NxQze/FnXM/z WE113yrrLSmcYr6vmBjNSWx7iVbOe4xye2UB+tFilRooUu10/5sasBG6iyzD+JOsa2X9 LOobdiYcfyVQsGSBIJbmY5Z4lZS5nWsurlxlbgyQ+rRmRZnta/VQdLLwz46uOA1G0p0h B23q8rTQWPcDXMVUIaRFKHuyybB7qR24FMlmeG+Y0q0DcOD9jTcvWudtdF5Kva8EWd2M 2Knzbk9IbAD8WWz/wBgzYgV3TUMDscEoglEN2hMPBQ2JsV0c8Y3FX50SRX4f/kd5+0PY ACkw== X-Received: by 10.68.47.39 with SMTP id a7mr1111022pbn.155.1361511275625; Thu, 21 Feb 2013 21:34:35 -0800 (PST) Received: from localhost ([203.114.244.88]) by mx.google.com with ESMTPS id ax3sm1253024pbd.42.2013.02.21.21.34.32 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 21 Feb 2013 21:34:34 -0800 (PST) From: Eryu Guan To: linux-ext4@vger.kernel.org Cc: Eryu Guan , Zheng Liu , "Theodore Ts'o" Subject: [PATCH] ext4: no need to remove extent if len is 0 in ext4_es_remove_extent() Date: Fri, 22 Feb 2013 13:34:03 +0800 Message-Id: <1361511243-2458-1-git-send-email-guaneryu@gmail.com> X-Mailer: git-send-email 1.8.1.2 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org len is 0 means no extent needs to be removed, so return immediately. Otherwise it could trigger the following BUG_ON() 436 end = offset + len - 1; 437 BUG_ON(end < offset); This could be reproduced by a simple truncate(1) command by an unprivileged user truncate -s $(($((2**32 - 1)) * 4096)) /mnt/ext4/testfile The same is true for __es_insert_extent(). Patched kernel passed xfstests regression test. Also remove comments about EXT4_I(inode)->i_es_lock, this rwlock isn't hold by callers. Cc: Zheng Liu Cc: "Theodore Ts'o" Signed-off-by: Eryu Guan Reviewed-by: Zheng Liu --- fs/ext4/extents_status.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c index 564d981..3ac09ca 100644 --- a/fs/ext4/extents_status.c +++ b/fs/ext4/extents_status.c @@ -328,6 +328,9 @@ static int __es_insert_extent(struct ext4_es_tree *tree, ext4_lblk_t offset, struct extent_status *es; ext4_lblk_t end = offset + len - 1; + if (!len) + return 0; + BUG_ON(end < offset); es = tree->cache_es; if (es && offset == (extent_status_end(es) + 1)) { @@ -386,7 +389,6 @@ out: /* * ext4_es_insert_extent() adds a space to a delayed extent tree. - * Caller holds inode->i_es_lock. * * ext4_es_insert_extent is called by ext4_da_write_begin and * ext4_es_remove_extent. @@ -415,7 +417,6 @@ int ext4_es_insert_extent(struct inode *inode, ext4_lblk_t offset, /* * ext4_es_remove_extent() removes a space from a delayed extent tree. - * Caller holds inode->i_es_lock. * * Return 0 on success, error code on failure. */ @@ -433,6 +434,9 @@ int ext4_es_remove_extent(struct inode *inode, ext4_lblk_t offset, es_debug("remove [%u/%u) from extent status tree of inode %lu\n", offset, len, inode->i_ino); + if (!len) + return err; + end = offset + len - 1; BUG_ON(end < offset); write_lock(&EXT4_I(inode)->i_es_lock);