From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 328EFC00A89 for ; Mon, 2 Nov 2020 09:51:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BEF18222E8 for ; Mon, 2 Nov 2020 09:51:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ax04Y/2N" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728183AbgKBJvJ (ORCPT ); Mon, 2 Nov 2020 04:51:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727992AbgKBJvJ (ORCPT ); Mon, 2 Nov 2020 04:51:09 -0500 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D7DAC0617A6 for ; Mon, 2 Nov 2020 01:51:09 -0800 (PST) Received: by mail-pf1-x444.google.com with SMTP id y14so10619422pfp.13 for ; Mon, 02 Nov 2020 01:51:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ttah+KnBauDQXA8r3dO7gvzvR5vDgdkbnCETl2BO3+U=; b=ax04Y/2NsE4dl88eZc4UiFtJxahzOP6+M4jyNmeYTdAOv7TULeclpuo8Ogms4QrCF5 M8FfB+U6iXP57gCdOy+8OsMaK+TKrweuAHoKZ5OGUS+pksn7+hPqmLh+u0PijXUQ1u87 f+E26VxhTy7c9PnpWEvf9ndPztTcbcxg9X26u0H3uVfjJJF8nPsA5xXSwZ0TULrK60Y2 9wfRpUgvVrhxd20v2yqby5pnnFuZnhOPg+k30SGQ6JR6NdldeY24y1tPPqNH17tUgrNB Mq3rtJSolL603lgmaitkb8vEp22Ba7JPtBIGzJ7q2yLe7D9+R1qAPAX7vqnBKvi/fuD2 zMbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ttah+KnBauDQXA8r3dO7gvzvR5vDgdkbnCETl2BO3+U=; b=m+QBCWQydhR8ATM34rqVl0beOVyWcheFe5CyKaZmAfc43gYyxRE+plWlBSBuxV9g6m Kqw+Y7ACBOc6RwZBL0H4u3f7hPtvOlzhAbuD4INLDtwJCW43sxYPxNQLUFuFbm2m/fiV 3QaowN9uodQaVkjXhqpgf7I3P+0JP27z3U0S9zU5ho4Pb3b+xExT/k8xFWXzXj8iEJpD pb+v9H7aiT73EhmIupw6UkuNvdq5lyA08Gdxah0OW3TQWE25b6vGCoNQ5DJbcuEtc1vy yFIhzfpJMTUnvwmhT07NOvr3jxk3v2E7sk1hI9x7LhJOmSTv7YNo+Ky1/TujA5kkgzkM P7YA== X-Gm-Message-State: AOAM530eM/IOoiT2vzmsTB0J5R5MW+VVnq427mkZRlhk7qYzKdJTxeol nqGaea0rRh4p3d1MyKu2/ymzaAbhskk= X-Google-Smtp-Source: ABdhPJyqbF9Y5Zy5HjymVfRmaQER+k5zxt4bSRbCrp5852/futohp36AoR3IFRa3ArHmINofcMiEAw== X-Received: by 2002:aa7:9501:0:b029:155:3b11:d5c4 with SMTP id b1-20020aa795010000b02901553b11d5c4mr21525690pfp.76.1604310668415; Mon, 02 Nov 2020 01:51:08 -0800 (PST) Received: from localhost.localdomain ([122.179.32.56]) by smtp.gmail.com with ESMTPSA id x15sm467062pjh.21.2020.11.02.01.51.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2020 01:51:07 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, allison.henderson@oracle.com, Christoph Hellwig Subject: [PATCH V9 03/14] xfs: Check for extent overflow when punching a hole Date: Mon, 2 Nov 2020 15:20:37 +0530 Message-Id: <20201102095048.100956-4-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201102095048.100956-1-chandanrlinux@gmail.com> References: <20201102095048.100956-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org The extent mapping the file offset at which a hole has to be inserted will be split into two extents causing extent count to increase by 1. Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Allison Henderson Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_inode_fork.h | 7 +++++++ fs/xfs/xfs_bmap_item.c | 15 +++++++++------ fs/xfs/xfs_bmap_util.c | 10 ++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index 7fc2b129a2e7..bcac769a7df6 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -40,6 +40,13 @@ struct xfs_ifork { */ #define XFS_IEXT_ADD_NOSPLIT_CNT (1) +/* + * Punching out an extent from the middle of an existing extent can cause the + * extent count to increase by 1. + * i.e. | Old extent | Hole | Old extent | + */ +#define XFS_IEXT_PUNCH_HOLE_CNT (1) + /* * Fork handling. */ diff --git a/fs/xfs/xfs_bmap_item.c b/fs/xfs/xfs_bmap_item.c index 1610d6ad089b..80d828394158 100644 --- a/fs/xfs/xfs_bmap_item.c +++ b/fs/xfs/xfs_bmap_item.c @@ -439,6 +439,7 @@ xfs_bui_item_recover( xfs_exntst_t state; unsigned int bui_type; int whichfork; + int iext_delta; int error = 0; /* Only one mapping operation per BUI... */ @@ -497,12 +498,14 @@ xfs_bui_item_recover( xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, 0); - if (bui_type == XFS_BMAP_MAP) { - error = xfs_iext_count_may_overflow(ip, whichfork, - XFS_IEXT_ADD_NOSPLIT_CNT); - if (error) - goto err_cancel; - } + if (bui_type == XFS_BMAP_MAP) + iext_delta = XFS_IEXT_ADD_NOSPLIT_CNT; + else + iext_delta = XFS_IEXT_PUNCH_HOLE_CNT; + + error = xfs_iext_count_may_overflow(ip, whichfork, iext_delta); + if (error) + goto err_cancel; count = bmap->me_len; error = xfs_trans_log_finish_bmap_update(tp, budp, bui_type, ip, diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index dcd6e61df711..0776abd0103c 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -891,6 +891,11 @@ xfs_unmap_extent( xfs_trans_ijoin(tp, ip, 0); + error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + XFS_IEXT_PUNCH_HOLE_CNT); + if (error) + goto out_trans_cancel; + error = xfs_bunmapi(tp, ip, startoffset_fsb, len_fsb, 0, 2, done); if (error) goto out_trans_cancel; @@ -1176,6 +1181,11 @@ xfs_insert_file_space( xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, 0); + error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + XFS_IEXT_PUNCH_HOLE_CNT); + if (error) + goto out_trans_cancel; + /* * The extent shifting code works on extent granularity. So, if stop_fsb * is not the starting block of extent, we need to split the extent at -- 2.28.0