From patchwork Tue Nov 3 15:06:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11877927 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 35414921 for ; Tue, 3 Nov 2020 15:07:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 05D0F223C7 for ; Tue, 3 Nov 2020 15:07:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UGvoqpRD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728158AbgKCPHl (ORCPT ); Tue, 3 Nov 2020 10:07:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728180AbgKCPHE (ORCPT ); Tue, 3 Nov 2020 10:07:04 -0500 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BE71C0613D1 for ; Tue, 3 Nov 2020 07:07:04 -0800 (PST) Received: by mail-pg1-x544.google.com with SMTP id o3so13868058pgr.11 for ; Tue, 03 Nov 2020 07:07:04 -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=UGvoqpRDDapPB+ffryDtEfjDtjDgzgF25xlvkjtk7st17DCLhMUFE+4POTIxmcRFRm QV9Cxq7pmfhifukfJyr8cXF1PVptcZe/tNHxdjHsjMzlQUhdD42tLv1lZD5EYa6adJeH k31dGyjBmXqALzmzEdk4ZpfXXVTRitcg4tqokhLxRB9tF3PBZU+xOhUkiR1N0/XAoaUp y5B1NCLQK2SjytSehwXwvlrXGoEGS7GkqIUIl3N25IFBQxfO/DNgxMgzJAamR7m1WQJN 5sdDN0KXnTfV3+fy/ROWzAsNSXQofUyAE78jUH3jep1NehSP0kB63a6dCAGVP566w0QA 225g== 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=W5dcGVWQYcVqq7XNTr2g/3vShH3ZnVk9mBJN7IlnOdzL7DgN8T/QfWYiCQ1jF9x5u9 vYeIuMXxvbBxosZ5T/D+Af7qCUypH/AU6835JGD9SubyG6AQymwY2aty8Jh0pvHrIySg NpFF0pMlTuiVkV4jF841uU/Suiw3ITBxcdG3yVuRAseshpHyGS3p1PzyRQ+I4bceA6yX LmBjTjapsBwd1gvGDhkk7xcaSHCVggMnVX4PN55Z8LK8aOOXR8yjZVhFTMM8oehj9Aqr L1cqvzhSBHDCN//ERSDpXvVb2qP6LrYT5FMCSpqtBAxs6ibqqrAdQPyAUE4tiddIj5qN 2UAg== X-Gm-Message-State: AOAM530WuVR1MNndG6KOl56R5x5hrDvcYDpN/v9yU9k+CietRTa6tDio g8uDTeXl3BAWseI1SSJf4ZaqGeyq3etckA== X-Google-Smtp-Source: ABdhPJxgcWZXvg9ARMcWxiroFRpoCyBfu3jcuroKM0towRCM72yoGxmgPJxjgu92BifYMTAKMXHpXg== X-Received: by 2002:a62:f20d:0:b029:18b:39c3:38d5 with SMTP id m13-20020a62f20d0000b029018b39c338d5mr2145787pfh.70.1604416023419; Tue, 03 Nov 2020 07:07:03 -0800 (PST) Received: from localhost.localdomain ([122.179.48.228]) by smtp.gmail.com with ESMTPSA id 15sm15936955pgs.52.2020.11.03.07.07.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 07:07:02 -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 V10 03/14] xfs: Check for extent overflow when punching a hole Date: Tue, 3 Nov 2020 20:36:31 +0530 Message-Id: <20201103150642.2032284-4-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201103150642.2032284-1-chandanrlinux@gmail.com> References: <20201103150642.2032284-1-chandanrlinux@gmail.com> MIME-Version: 1.0 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