From patchwork Sun Jan 10 03:29:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 12008859 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 186C5C433E0 for ; Sun, 10 Jan 2021 03:30:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CCE5F229EF for ; Sun, 10 Jan 2021 03:30:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726198AbhAJDaZ (ORCPT ); Sat, 9 Jan 2021 22:30:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726062AbhAJDaY (ORCPT ); Sat, 9 Jan 2021 22:30:24 -0500 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D6BFC06179F for ; Sat, 9 Jan 2021 19:29:44 -0800 (PST) Received: by mail-pl1-x629.google.com with SMTP id g3so7748598plp.2 for ; Sat, 09 Jan 2021 19:29:44 -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=UajVql0+fX8/PSAE042XQ9DAknMby2LMCreHtOKK9j0=; b=b6NVTV1QqZmWwigPTR7SRWNUpxT9yFQVYU5USqU5ShDholW0FCCm0YDPLuUyIiD/x9 GNNI+MnxTbuk89ZmpAK/75Yw7HpAwGV0Mn+qVjQK1lEvyMBucv2CFh1/uZ+vmzzxuNZa C1BSGgWFf3tNfO0OI9Orjt+n/nVSXqYlDf5HXt3A5pOwQRNJbb9lwksi5OqY1vLTLqAw nbnwdB0XlhHUv5SaDuLyswTRmBM6LP78LS1DtasYKx3AwPLuzCrWGJ/rvOUEa5YKO1qh terx32Rngk9XVJ9EWOp/YtlxJKMTUgYu1Z6KUF6g3Z58FGKMu0zLJtA5D4pfL1U9qzM6 V0Kg== 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=UajVql0+fX8/PSAE042XQ9DAknMby2LMCreHtOKK9j0=; b=X2fMeMOz4suxeCKLxLu4KhaXQqhuBWhMusF4jYygU0P8okSYH2vlv7sO58Eq42+mAm 5fnuD+A1QXVL+X3zNbmV7dOPQcIMvlFe4r2X8rridgFBnQqmxgLUovc/ve7ZN0aPTkmx uOlMQDkcGYK/nor/WUWjFNmGT8bm2+HCelZT0qWMd7RvUaUUc+8mMnqpbvUPz/CVREuN 7rxOlCNGNF6eBpzexQ9P277xFdR6yLx63yr90mguPwJVPIjnBvwkRtxX+oDOSKfkLYDg M9LeeOA4INx3UJ5OwR5Em26aMaobUS5UmrnrG4TvawjJEjXn3e5Ewx7Zww1rgs8r+Dpe c85Q== X-Gm-Message-State: AOAM531a18LxLKnthlxie1uEmGjcjdZsuvjzlJDKUmtqq7DgRAxCGa00 eHONuma5rdsL+AS1948xOfRNIeJLfWj3bw== X-Google-Smtp-Source: ABdhPJwABx3AhfRoeHIWbvxsD0i4cFL2MaNDgzA7GUeT84Sfv25oVqxMXXeUb2qORXWVlFRpBUEqfw== X-Received: by 2002:a17:902:ff0e:b029:da:d4ee:eca3 with SMTP id f14-20020a170902ff0eb02900dad4eeeca3mr10910918plj.41.1610249383940; Sat, 09 Jan 2021 19:29:43 -0800 (PST) Received: from localhost.localdomain ([122.179.92.100]) by smtp.gmail.com with ESMTPSA id x6sm14079861pfq.57.2021.01.09.19.29.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Jan 2021 19:29:43 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, djwong@kernel.org, hch@lst.de, allison.henderson@oracle.com Subject: [PATCH V13 01/16] xfs: Add helper for checking per-inode extent count overflow Date: Sun, 10 Jan 2021 08:59:13 +0530 Message-Id: <20210110032928.3120861-2-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210110032928.3120861-1-chandanrlinux@gmail.com> References: <20210110032928.3120861-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org XFS does not check for possible overflow of per-inode extent counter fields when adding extents to either data or attr fork. For e.g. 1. Insert 5 million xattrs (each having a value size of 255 bytes) and then delete 50% of them in an alternating manner. 2. On a 4k block sized XFS filesystem instance, the above causes 98511 extents to be created in the attr fork of the inode. xfsaild/loop0 2008 [003] 1475.127209: probe:xfs_inode_to_disk: (ffffffffa43fb6b0) if_nextents=98511 i_ino=131 3. The incore inode fork extent counter is a signed 32-bit quantity. However the on-disk extent counter is an unsigned 16-bit quantity and hence cannot hold 98511 extents. 4. The following incorrect value is stored in the attr extent counter, # xfs_db -f -c 'inode 131' -c 'print core.naextents' /dev/loop0 core.naextents = -32561 This commit adds a new helper function (i.e. xfs_iext_count_may_overflow()) to check for overflow of the per-inode data and xattr extent counters. Future patches will use this function to make sure that an FS operation won't cause the extent counter to overflow. Suggested-by: Darrick J. Wong Reviewed-by: Allison Henderson Reviewed-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_inode_fork.c | 23 +++++++++++++++++++++++ fs/xfs/libxfs/xfs_inode_fork.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c index 7575de5cecb1..8d48716547e5 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.c +++ b/fs/xfs/libxfs/xfs_inode_fork.c @@ -23,6 +23,7 @@ #include "xfs_da_btree.h" #include "xfs_dir2_priv.h" #include "xfs_attr_leaf.h" +#include "xfs_types.h" kmem_zone_t *xfs_ifork_zone; @@ -728,3 +729,25 @@ xfs_ifork_verify_local_attr( return 0; } + +int +xfs_iext_count_may_overflow( + struct xfs_inode *ip, + int whichfork, + int nr_to_add) +{ + struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork); + uint64_t max_exts; + uint64_t nr_exts; + + if (whichfork == XFS_COW_FORK) + return 0; + + max_exts = (whichfork == XFS_ATTR_FORK) ? MAXAEXTNUM : MAXEXTNUM; + + nr_exts = ifp->if_nextents + nr_to_add; + if (nr_exts < ifp->if_nextents || nr_exts > max_exts) + return -EFBIG; + + return 0; +} diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index a4953e95c4f3..0beb8e2a00be 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -172,5 +172,7 @@ extern void xfs_ifork_init_cow(struct xfs_inode *ip); int xfs_ifork_verify_local_data(struct xfs_inode *ip); int xfs_ifork_verify_local_attr(struct xfs_inode *ip); +int xfs_iext_count_may_overflow(struct xfs_inode *ip, int whichfork, + int nr_to_add); #endif /* __XFS_INODE_FORK_H__ */ From patchwork Sun Jan 10 03:29:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 12008857 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 1D2A5C433E6 for ; Sun, 10 Jan 2021 03:30:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E5EC422AAA for ; Sun, 10 Jan 2021 03:30:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726283AbhAJDa1 (ORCPT ); Sat, 9 Jan 2021 22:30:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726245AbhAJDa1 (ORCPT ); Sat, 9 Jan 2021 22:30:27 -0500 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D67EAC0617A2 for ; Sat, 9 Jan 2021 19:29:46 -0800 (PST) Received: by mail-pj1-x102a.google.com with SMTP id m5so8411554pjv.5 for ; Sat, 09 Jan 2021 19:29:46 -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=f2y3tRispCdnrzAnaMKzGUWJKa7b7cfGubZ2uu6yCUg=; b=bCrLYPL0o62zpd+Kg6R4wFU4mubtrgaDKOpAqhI044P7MPMwtSoD2cY1uGX+xpzwMN zgF76v6GTNOCKxuBxioit0js2BcxfNdiudV4sjchxBpX9DgCeCh/VVDWrB+vNdkrc6DL DuNCBb7le9URwhmxViJstJVLseQFeNQzXCMbNF9x5IB4SBZxcTiZeWuOvn8JDZElXGcU geHKHx8gHK0Y7tXv0VQSIwyr8u/L9xGOm0m/uxkGDDiW9t7rDX18tNC0/OFSEWZvB2yf io7bLbhhJWcn67MF1poBlhKGbcvRU3h/wDcnwAtuRcTQaVMPJ/Vx0HkvHxE2jxmrPhY3 W9wg== 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=f2y3tRispCdnrzAnaMKzGUWJKa7b7cfGubZ2uu6yCUg=; b=C3lqcB7P0RQJou4j7jVWICsrN4h+o050urkxLuUkY2YKQ/79G5hiX/iqP41HNqSlKY MRnov7Mb/W7dLa2A3k4KM+fPo2cTaDd3unFiSoSelCFagMMg/kQrui+TCA2fR8ul1tQd n2po6H33EQHdcCwPpsw2JDLMkldpAy/j6RTuYjr1lKrFxWzXk0Ew0NFb482n6IPwyMfH 7WfKi+2IgJKRg2jl2BBpKX4KC7xHyU/T7/YojQYCW1CLrXuXiEbhaImmnn8OfirSVAp9 W51NC1O+TCWFzwjpjwnOWWBD5tAUjOfoE0R3N/BVle/LVkQ4SOJRRPJyQVaKEKyTotCV FROg== X-Gm-Message-State: AOAM532eWwigfCuUfAdVhaKUCuUZCZqQe2ejJc/gC6oqOJjCv2Pp2sNG 0aEUbWEL+ZKOJfuW0uCsWCBSdLPD07LOfQ== X-Google-Smtp-Source: ABdhPJxmj406Su49tgtKIi/i3lUBVbBvISsl2TtytKbiGPG8Gyvuq2IaMApl1qPA1ta6z7htHcCsjA== X-Received: by 2002:a17:90a:fc83:: with SMTP id ci3mr11457837pjb.145.1610249386315; Sat, 09 Jan 2021 19:29:46 -0800 (PST) Received: from localhost.localdomain ([122.179.92.100]) by smtp.gmail.com with ESMTPSA id x6sm14079861pfq.57.2021.01.09.19.29.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Jan 2021 19:29:45 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, djwong@kernel.org, hch@lst.de, allison.henderson@oracle.com Subject: [PATCH V13 02/16] xfs: Check for extent overflow when trivally adding a new extent Date: Sun, 10 Jan 2021 08:59:14 +0530 Message-Id: <20210110032928.3120861-3-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210110032928.3120861-1-chandanrlinux@gmail.com> References: <20210110032928.3120861-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org When adding a new data extent (without modifying an inode's existing extents) the extent count increases only by 1. This commit checks for extent count overflow in such cases. Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Allison Henderson Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_bmap.c | 6 ++++++ fs/xfs/libxfs/xfs_inode_fork.h | 6 ++++++ fs/xfs/xfs_bmap_item.c | 7 +++++++ fs/xfs/xfs_bmap_util.c | 5 +++++ fs/xfs/xfs_dquot.c | 8 +++++++- fs/xfs/xfs_iomap.c | 5 +++++ fs/xfs/xfs_rtalloc.c | 5 +++++ 7 files changed, 41 insertions(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index bc446418e227..32aeacf6f055 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -4527,6 +4527,12 @@ xfs_bmapi_convert_delalloc( return error; xfs_ilock(ip, XFS_ILOCK_EXCL); + + error = xfs_iext_count_may_overflow(ip, whichfork, + XFS_IEXT_ADD_NOSPLIT_CNT); + if (error) + goto out_trans_cancel; + xfs_trans_ijoin(tp, ip, 0); if (!xfs_iext_lookup_extent(ip, ifp, offset_fsb, &bma.icur, &bma.got) || diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index 0beb8e2a00be..7fc2b129a2e7 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -34,6 +34,12 @@ struct xfs_ifork { #define XFS_IFEXTENTS 0x02 /* All extent pointers are read in */ #define XFS_IFBROOT 0x04 /* i_broot points to the bmap b-tree root */ +/* + * Worst-case increase in the fork extent count when we're adding a single + * extent to a fork and there's no possibility of splitting an existing mapping. + */ +#define XFS_IEXT_ADD_NOSPLIT_CNT (1) + /* * Fork handling. */ diff --git a/fs/xfs/xfs_bmap_item.c b/fs/xfs/xfs_bmap_item.c index 93e4d8ae6e92..0534304ed0a7 100644 --- a/fs/xfs/xfs_bmap_item.c +++ b/fs/xfs/xfs_bmap_item.c @@ -508,6 +508,13 @@ 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; + } + count = bmap->me_len; error = xfs_trans_log_finish_bmap_update(tp, budp, bui_type, ip, whichfork, bmap->me_startoff, bmap->me_startblock, diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index 7371a7f7c652..db44bfaabe88 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -822,6 +822,11 @@ xfs_alloc_file_space( if (error) goto error1; + error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + XFS_IEXT_ADD_NOSPLIT_CNT); + if (error) + goto error0; + xfs_trans_ijoin(tp, ip, 0); error = xfs_bmapi_write(tp, ip, startoffset_fsb, diff --git a/fs/xfs/xfs_dquot.c b/fs/xfs/xfs_dquot.c index 1d95ed387d66..175f544f7c45 100644 --- a/fs/xfs/xfs_dquot.c +++ b/fs/xfs/xfs_dquot.c @@ -314,8 +314,14 @@ xfs_dquot_disk_alloc( return -ESRCH; } - /* Create the block mapping. */ xfs_trans_ijoin(tp, quotip, XFS_ILOCK_EXCL); + + error = xfs_iext_count_may_overflow(quotip, XFS_DATA_FORK, + XFS_IEXT_ADD_NOSPLIT_CNT); + if (error) + return error; + + /* Create the block mapping. */ error = xfs_bmapi_write(tp, quotip, dqp->q_fileoffset, XFS_DQUOT_CLUSTER_SIZE_FSB, XFS_BMAPI_METADATA, 0, &map, &nmaps); diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index 7b9ff824e82d..f53690febb22 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -250,6 +250,11 @@ xfs_iomap_write_direct( if (error) goto out_trans_cancel; + error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + XFS_IEXT_ADD_NOSPLIT_CNT); + if (error) + goto out_trans_cancel; + xfs_trans_ijoin(tp, ip, 0); /* diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index b4999fb01ff7..161b0e8992ba 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -804,6 +804,11 @@ xfs_growfs_rt_alloc( xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); + error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + XFS_IEXT_ADD_NOSPLIT_CNT); + if (error) + goto out_trans_cancel; + /* * Allocate blocks to the bitmap file. */ From patchwork Sun Jan 10 03:29:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 12008863 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 397BDC433E9 for ; Sun, 10 Jan 2021 03:30:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 06EDA22B2E for ; Sun, 10 Jan 2021 03:30:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726293AbhAJDaa (ORCPT ); Sat, 9 Jan 2021 22:30:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726245AbhAJDaa (ORCPT ); Sat, 9 Jan 2021 22:30:30 -0500 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DC92C0617A3 for ; Sat, 9 Jan 2021 19:29:50 -0800 (PST) Received: by mail-pl1-x634.google.com with SMTP id be12so7734596plb.4 for ; Sat, 09 Jan 2021 19:29:50 -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=hfxy4dQ7UU+MA/AWL+J4vikfJv/jhTTSkVAkRx6cF/Y=; b=QtBE4uxqLmFY1k3+SvWaeUmIIr/REoMjE6kCNYx9Q6x2qgmnpT3QEkR0+MqxhYBWjn OQCW2nrPMiMzJy5O92Wc1I+SF7Lf4matebA3Bsr/hNUcwSYFoXYMyl1BATz5uQ7JTIeL 3rYDAuu/gPv/HzhgVjw5YJAMlM0B4g/tpqueG9DQ67bcaYc+y+53jCE4ijoxG/75bOsF hHfD4HM9T/wPRMhwse5+AfZoMzNoF2ozDXnTQVTeelmwCztPyr35todeXIPOkpnCUmPH igjJcLuy5REc+ZuexgE7HTGYF/yPsiu1OD/fAtHLPHtgr8XJIyqfJgRFqoTVUgIqow1U AVMQ== 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=hfxy4dQ7UU+MA/AWL+J4vikfJv/jhTTSkVAkRx6cF/Y=; b=SKep8oquvQvYB5xP9qEDfTYJQAblhJn1tFAuicaA+Q0RJIHDpH1cHEhfVnNsOVi0ZG 4E/XGumX0odK3nmvbZvXLBra+3JzYrMcGafN+DHBLj/rN/WoqscS9VMYAOqelqDHZMRf 4nIdGF5lK3b/u06nuiDjZbZRBsca/t69s92qkn7fVZkWAY7wEHXU8NvnbVpCXaush5Kt /gmCg252aAXeJH+Bcks+wP5vEsW5f5BpUCfErBS6aeAUKLMxLju25pYVwAvw5+QY0MuB aeneoaYICCMhczk8PHLa9G6Hbg2vP04ZBDaYXa422Dw0xhdbiQOhjqSFwQ2ELuLYhGoj U1Xg== X-Gm-Message-State: AOAM533idsuPU3B53FX2LJO4WAed3ODaksSMY/jiOkF27PNeZR3mS2k0 tBYjFV/Eg7a+FE22RjGuvBPRW2kZ/h1SHg== X-Google-Smtp-Source: ABdhPJzjnDLm4d1+WjzkFDR0V1heffE5wXt/UFqGjlnuWPbyUgAoAHRCT5OBfUG8YU0vbx1U+UDb6A== X-Received: by 2002:a17:902:7592:b029:dc:3c87:1c63 with SMTP id j18-20020a1709027592b02900dc3c871c63mr10800201pll.47.1610249388662; Sat, 09 Jan 2021 19:29:48 -0800 (PST) Received: from localhost.localdomain ([122.179.92.100]) by smtp.gmail.com with ESMTPSA id x6sm14079861pfq.57.2021.01.09.19.29.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Jan 2021 19:29:48 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, djwong@kernel.org, hch@lst.de, allison.henderson@oracle.com Subject: [PATCH V13 03/16] xfs: Check for extent overflow when punching a hole Date: Sun, 10 Jan 2021 08:59:15 +0530 Message-Id: <20210110032928.3120861-4-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210110032928.3120861-1-chandanrlinux@gmail.com> References: <20210110032928.3120861-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 0534304ed0a7..2344757ede63 100644 --- a/fs/xfs/xfs_bmap_item.c +++ b/fs/xfs/xfs_bmap_item.c @@ -471,6 +471,7 @@ xfs_bui_item_recover( xfs_exntst_t state; unsigned int bui_type; int whichfork; + int iext_delta; int error = 0; if (!xfs_bui_validate(mp, buip)) { @@ -508,12 +509,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 db44bfaabe88..6ac7a6ac2658 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; @@ -1168,6 +1173,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 From patchwork Sun Jan 10 03:29:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 12008861 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 4D7FDC433DB for ; Sun, 10 Jan 2021 03:30:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1E56E229EF for ; Sun, 10 Jan 2021 03:30:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726375AbhAJDac (ORCPT ); Sat, 9 Jan 2021 22:30:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726245AbhAJDab (ORCPT ); Sat, 9 Jan 2021 22:30:31 -0500 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1212C0617A4 for ; Sat, 9 Jan 2021 19:29:51 -0800 (PST) Received: by mail-pf1-x429.google.com with SMTP id m6so3298252pfk.1 for ; Sat, 09 Jan 2021 19:29:51 -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=CaaIKtEA+QkHkbNZmc4x83WOODezXN2Z3yH7D8rxDjE=; b=H4070fxqkMR9HlRls+tyBn8hZAwxSjd2lU+s26ZTbY+HFrFDNfT4YKADERZUgffXyT 8DtXT2YNnG6HVUqg6+wQnTQIKzsGMniyfHRQDMsFKSR3uiEGUt0xtj1sEoc+oPg2Ib0X bjsQJsW7YGgKV5aaqgQndeRY+2kfVizm2TRGTSJosVkdmlN6k8jz+7l4pGTV79Lxvr7I f7sJ+14cunINePgfnc+u68vI2TtqNTidiV3xwNhwju+EQTTpS45H0TFiHbKFa9RlL0Pr 8yVIe43y2cDLFgrv+GSGsqWkel4TOG7+lEaVeBl2YxG4/h7bljcCRsnLgJJcQGyQtL1E K4tA== 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=CaaIKtEA+QkHkbNZmc4x83WOODezXN2Z3yH7D8rxDjE=; b=o+TBmlL1ID5kL2qpkQMxZKqTEGzAgMCTyQeFc7wuNIO4GZeObNUV4J7x8mpgosGEs2 V1OhkXL1vDZV/yvZF0IFlH5p/cLihc4bbD5nOkSRKUSh332rDau6QET0rsFjA+k38C9g q7oNpxtC6zRwV7WLL9pvYdTz2keeRKCm5ynIsIGca5osLYv1m8dPC1dX6oFDmL9HzR6Y LdpwcgjNQYnAlMshPkbqM4uj1aTspdVjA3va2GFxDJw8tsbBDy5b/4Zmaix5FPJTjX4Q wbruH3NX4N1pEtpw3rY1E4m0xo82k4bwr6jXIyqupzACqrWYx324DQzbJnY1LE+jxZet /RBw== X-Gm-Message-State: AOAM533Z/Yg4aFYuYqviUwTRX6VWywHtVD/FaVp44m8+SIYz32TcXX9S 9URVkFGIBduU905kfa+YnPNYgFv2uZKZWg== X-Google-Smtp-Source: ABdhPJwKgVkeE1m70tJODqBUm+eW65Y8lOkIZ8Ph9tz+7w4IUcQWFarY3DDh5qC5pLBApi3zTRD1Zg== X-Received: by 2002:a63:5416:: with SMTP id i22mr14057219pgb.43.1610249391001; Sat, 09 Jan 2021 19:29:51 -0800 (PST) Received: from localhost.localdomain ([122.179.92.100]) by smtp.gmail.com with ESMTPSA id x6sm14079861pfq.57.2021.01.09.19.29.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Jan 2021 19:29:50 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, djwong@kernel.org, hch@lst.de, allison.henderson@oracle.com Subject: [PATCH V13 04/16] xfs: Check for extent overflow when adding dir entries Date: Sun, 10 Jan 2021 08:59:16 +0530 Message-Id: <20210110032928.3120861-5-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210110032928.3120861-1-chandanrlinux@gmail.com> References: <20210110032928.3120861-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Directory entry addition can cause the following, 1. Data block can be added/removed. A new extent can cause extent count to increase by 1. 2. Free disk block can be added/removed. Same behaviour as described above for Data block. 3. Dabtree blocks. XFS_DA_NODE_MAXDEPTH blocks can be added. Each of these can be new extents. Hence extent count can increase by XFS_DA_NODE_MAXDEPTH. Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_inode_fork.h | 13 +++++++++++++ fs/xfs/xfs_inode.c | 10 ++++++++++ fs/xfs/xfs_symlink.c | 5 +++++ 3 files changed, 28 insertions(+) diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index bcac769a7df6..ea1a9dd8a763 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -47,6 +47,19 @@ struct xfs_ifork { */ #define XFS_IEXT_PUNCH_HOLE_CNT (1) +/* + * Directory entry addition can cause the following, + * 1. Data block can be added/removed. + * A new extent can cause extent count to increase by 1. + * 2. Free disk block can be added/removed. + * Same behaviour as described above for Data block. + * 3. Dabtree blocks. + * XFS_DA_NODE_MAXDEPTH blocks can be added. Each of these can be new + * extents. Hence extent count can increase by XFS_DA_NODE_MAXDEPTH. + */ +#define XFS_IEXT_DIR_MANIP_CNT(mp) \ + ((XFS_DA_NODE_MAXDEPTH + 1 + 1) * (mp)->m_dir_geo->fsbcount) + /* * Fork handling. */ diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index b7352bc4c815..4cc787cc4eee 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -1042,6 +1042,11 @@ xfs_create( if (error) goto out_trans_cancel; + error = xfs_iext_count_may_overflow(dp, XFS_DATA_FORK, + XFS_IEXT_DIR_MANIP_CNT(mp)); + if (error) + goto out_trans_cancel; + /* * A newly created regular or special file just has one directory * entry pointing to them, but a directory also the "." entry @@ -1258,6 +1263,11 @@ xfs_link( xfs_trans_ijoin(tp, sip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, tdp, XFS_ILOCK_EXCL); + error = xfs_iext_count_may_overflow(tdp, XFS_DATA_FORK, + XFS_IEXT_DIR_MANIP_CNT(mp)); + if (error) + goto error_return; + /* * If we are using project inheritance, we only allow hard link * creation in our tree when the project IDs are the same; else diff --git a/fs/xfs/xfs_symlink.c b/fs/xfs/xfs_symlink.c index 1f43fd7f3209..0b8136a32484 100644 --- a/fs/xfs/xfs_symlink.c +++ b/fs/xfs/xfs_symlink.c @@ -220,6 +220,11 @@ xfs_symlink( if (error) goto out_trans_cancel; + error = xfs_iext_count_may_overflow(dp, XFS_DATA_FORK, + XFS_IEXT_DIR_MANIP_CNT(mp)); + if (error) + goto out_trans_cancel; + /* * Allocate an inode for the symlink. */ From patchwork Sun Jan 10 03:29:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 12008865 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 E50F4C433DB for ; Sun, 10 Jan 2021 03:31:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B80BE229EF for ; Sun, 10 Jan 2021 03:31:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726249AbhAJDbD (ORCPT ); Sat, 9 Jan 2021 22:31:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726132AbhAJDbD (ORCPT ); Sat, 9 Jan 2021 22:31:03 -0500 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE05CC0617A5 for ; Sat, 9 Jan 2021 19:29:53 -0800 (PST) Received: by mail-pf1-x434.google.com with SMTP id c79so8860243pfc.2 for ; Sat, 09 Jan 2021 19:29:53 -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=5kFpmp/fOA8CTCegvBQNEGv0i+BdgucZ7JkzQebLYZU=; b=YJYXahcM/a0vEZpnezHv52trOWMdnasUhmCTI9nHncqJ7SSecTJoUJBgY1gH7JbpeY 5FNW1ngIblfrTFCjynNqNCL0EaK7Sr/xCM8SF0YGGo6YdfvE4sdogTzymHhzbHJf1DKL Ey3yJhdoLgek/pcXDVvCihv/pZxnRZLbjdVNHBA8tbIhaT5Z75mHq/4YL8OfZtZRD9kS sU9KT6PGHj08evOTy+dNk1Ik5XCwyZPC+cuu4Iyxs144e4mwYAboBYzZwEaV3DSgRVQ8 da1RcsmZxSotcyZbUXjaxg2R/amWPCdEjreTTcX4ONyvMPC4qNqL06/HOMxHBzPznMLF z4Qw== 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=5kFpmp/fOA8CTCegvBQNEGv0i+BdgucZ7JkzQebLYZU=; b=FHsLMxq7Lx8FNes5oli99f7cflIimIen6UEq+XGX45DUddWczKxNsM91KM7QpnOjzW xTpUAp859dDvtAHSOIto0gv0knR0tC7PnaoKWoQKbd5dejQen0JQhFq7GGueIjQqh8Yp Pvc4mRomDf3ILUBKuGZ35bn1KM0BLXQfLRFgoydp7nn2qIU6SdahOwTjhO8LW1PFZDq6 n7OC8U7rlUnXckSoipr1dwvG+/ZbhrLZn7G19BA58BM1Yl7eNuWtQSnvSlxT3HtuXAE6 ZdigcSkPwXwEPYxejj6Ayl6qjRSMn4iQm0pxg2fr/NlqOzNOrhgfnmEAvHw8fyDQgHbN 6OPA== X-Gm-Message-State: AOAM531Sz/iAHOTV3AT+wIwO6EWkRvRHQW6N4gGbIJCo0kDyU/SDYGSN 9WmCzw8eGAuO7EA/9qKYS9bvQ4pqC8Ik1Q== X-Google-Smtp-Source: ABdhPJwcWKdrvB9RWttAfN6nYS2iB5u4955NhHBRhuemIwv4omP60+XWSiAUAxTXXz7qavhlFs8iGA== X-Received: by 2002:a63:f608:: with SMTP id m8mr13779998pgh.11.1610249393322; Sat, 09 Jan 2021 19:29:53 -0800 (PST) Received: from localhost.localdomain ([122.179.92.100]) by smtp.gmail.com with ESMTPSA id x6sm14079861pfq.57.2021.01.09.19.29.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Jan 2021 19:29:52 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, djwong@kernel.org, hch@lst.de, allison.henderson@oracle.com Subject: [PATCH V13 05/16] xfs: Check for extent overflow when removing dir entries Date: Sun, 10 Jan 2021 08:59:17 +0530 Message-Id: <20210110032928.3120861-6-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210110032928.3120861-1-chandanrlinux@gmail.com> References: <20210110032928.3120861-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Directory entry removal must always succeed; Hence XFS does the following during low disk space scenario: 1. Data/Free blocks linger until a future remove operation. 2. Dabtree blocks would be swapped with the last block in the leaf space and then the new last block will be unmapped. This facility is reused during low inode extent count scenario i.e. this commit causes xfs_bmap_del_extent_real() to return -ENOSPC error code so that the above mentioned behaviour is exercised causing no change to the directory's extent count. Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_bmap.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 32aeacf6f055..94063ac1d085 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -5151,6 +5151,23 @@ xfs_bmap_del_extent_real( /* * Deleting the middle of the extent. */ + + /* + * For directories, -ENOSPC is returned since a directory entry + * remove operation must not fail due to low extent count + * availability. -ENOSPC will be handled by higher layers of XFS + * by letting the corresponding empty Data/Free blocks to linger + * until a future remove operation. Dabtree blocks would be + * swapped with the last block in the leaf space and then the + * new last block will be unmapped. + */ + error = xfs_iext_count_may_overflow(ip, whichfork, 1); + if (error == -ENOSPC) { + ASSERT(S_ISDIR(VFS_I(ip)->i_mode) && + whichfork == XFS_DATA_FORK); + goto done; + } + old = got; got.br_blockcount = del->br_startoff - got.br_startoff; From patchwork Sun Jan 10 03:29:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 12008867 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 233F0C433E6 for ; Sun, 10 Jan 2021 03:31:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EAFC7229EF for ; Sun, 10 Jan 2021 03:31:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726132AbhAJDbD (ORCPT ); Sat, 9 Jan 2021 22:31:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726245AbhAJDbD (ORCPT ); Sat, 9 Jan 2021 22:31:03 -0500 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FA85C0617A6 for ; Sat, 9 Jan 2021 19:29:56 -0800 (PST) Received: by mail-pl1-x62e.google.com with SMTP id s15so7714790plr.9 for ; Sat, 09 Jan 2021 19:29:56 -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=tPqQFUkTyQMKAVlwHoryKUGzUBtBK79OUw3IcgmGk9A=; b=cVZpZZfZpswcSnjjeChlRTgJcEvrf2YczpaH/V0u/nP5RgYwR+6FTLvNcNh/96cfkT WjsTPVNZVxkSPT2/WswOgQ6Qg2e1raZcZrevGB16VHcKirbrL6yeXy1m5JYsQVWxyfuO 2nzolLKLDOR8+rMlgHdMhvzJjH8H8on7M/uKIpyfAl4e83yNTmT5zNCMO76X4sBg4RV+ Z3IjnnRN3yGX5Wt8V13TkOj4Z/ylK//vIOZ9ltU9ZU3oIGTK2+ao0fRHCZ1YrXIWEQPD 7E52ehTuE5t0kJjARuJg2W8Ikx7sG910p+xSQgzxli2zj8RSX/B9oxPW+bmxFkaIYs/P UOPw== 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=tPqQFUkTyQMKAVlwHoryKUGzUBtBK79OUw3IcgmGk9A=; b=J1uzCTGJ/xeEvfzlf4E+TB/AHgREcfwAQpiJ0wnIev+gRmFJY27GqIo5cmgxzJDDU2 fZUQ6/ZuEKkwjtiZiFjgyJ1R7uSs0nx+LC1U1vy1gcnaALkMmFLYmdRtxYmfcTV6Db1R LbfBodpKJh/lHt/Axb935uCuzRkj6OKYwnsTsWfjoayqwCC1izgaI5/7oWZLtNlojOtr mhUESUPiukMGpq9NIdaonjf1HBrKAxaz9MVzEdo20NmLzvo7u1pZmdDHQb24mEmM5JkB XW/0CCFjlSbU2co9LIa2VoZK4QzD6IdcVlz55KNQbsPT3lIO5kELcNaGUQgwSvc45BJT gkjg== X-Gm-Message-State: AOAM532ew8IdA8gDmmCrL2LsSXHBzthsgXSVOxecD5UR/z6zTkNW0pdW 548eUop0zI9kdvp9z9RhzDlTAkL+nJi8AA== X-Google-Smtp-Source: ABdhPJzP+kBhJYBan2bYg6amfp1ArhdOC9nbTYqklnEHhAQ8ieU/pVbhjabMV/KDvaQeUnOnYBwviw== X-Received: by 2002:a17:90b:1187:: with SMTP id gk7mr11305241pjb.162.1610249395731; Sat, 09 Jan 2021 19:29:55 -0800 (PST) Received: from localhost.localdomain ([122.179.92.100]) by smtp.gmail.com with ESMTPSA id x6sm14079861pfq.57.2021.01.09.19.29.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Jan 2021 19:29:55 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, djwong@kernel.org, hch@lst.de, allison.henderson@oracle.com Subject: [PATCH V13 06/16] xfs: Check for extent overflow when renaming dir entries Date: Sun, 10 Jan 2021 08:59:18 +0530 Message-Id: <20210110032928.3120861-7-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210110032928.3120861-1-chandanrlinux@gmail.com> References: <20210110032928.3120861-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org A rename operation is essentially a directory entry remove operation from the perspective of parent directory (i.e. src_dp) of rename's source. Hence the only place where we check for extent count overflow for src_dp is in xfs_bmap_del_extent_real(). xfs_bmap_del_extent_real() returns -ENOSPC when it detects a possible extent count overflow and in response, the higher layers of directory handling code do the following: 1. Data/Free blocks: XFS lets these blocks linger until a future remove operation removes them. 2. Dabtree blocks: XFS swaps the blocks with the last block in the Leaf space and unmaps the last block. For target_dp, there are two cases depending on whether the destination directory entry exists or not. When destination directory entry does not exist (i.e. target_ip == NULL), extent count overflow check is performed only when transaction has a non-zero sized space reservation associated with it. With a zero-sized space reservation, XFS allows a rename operation to continue only when the directory has sufficient free space in its data/leaf/free space blocks to hold the new entry. When destination directory entry exists (i.e. target_ip != NULL), all we need to do is change the inode number associated with the already existing entry. Hence there is no need to perform an extent count overflow check. Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_bmap.c | 3 +++ fs/xfs/xfs_inode.c | 44 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 94063ac1d085..44ed30d0f662 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -5160,6 +5160,9 @@ xfs_bmap_del_extent_real( * until a future remove operation. Dabtree blocks would be * swapped with the last block in the leaf space and then the * new last block will be unmapped. + * + * The above logic also applies to the source directory entry of + * a rename operation. */ error = xfs_iext_count_may_overflow(ip, whichfork, 1); if (error == -ENOSPC) { diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 4cc787cc4eee..f0a6d528cbc4 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -3116,6 +3116,35 @@ xfs_rename( /* * Check for expected errors before we dirty the transaction * so we can return an error without a transaction abort. + * + * Extent count overflow check: + * + * From the perspective of src_dp, a rename operation is essentially a + * directory entry remove operation. Hence the only place where we check + * for extent count overflow for src_dp is in + * xfs_bmap_del_extent_real(). xfs_bmap_del_extent_real() returns + * -ENOSPC when it detects a possible extent count overflow and in + * response, the higher layers of directory handling code do the + * following: + * 1. Data/Free blocks: XFS lets these blocks linger until a + * future remove operation removes them. + * 2. Dabtree blocks: XFS swaps the blocks with the last block in the + * Leaf space and unmaps the last block. + * + * For target_dp, there are two cases depending on whether the + * destination directory entry exists or not. + * + * When destination directory entry does not exist (i.e. target_ip == + * NULL), extent count overflow check is performed only when transaction + * has a non-zero sized space reservation associated with it. With a + * zero-sized space reservation, XFS allows a rename operation to + * continue only when the directory has sufficient free space in its + * data/leaf/free space blocks to hold the new entry. + * + * When destination directory entry exists (i.e. target_ip != NULL), all + * we need to do is change the inode number associated with the already + * existing entry. Hence there is no need to perform an extent count + * overflow check. */ if (target_ip == NULL) { /* @@ -3126,6 +3155,12 @@ xfs_rename( error = xfs_dir_canenter(tp, target_dp, target_name); if (error) goto out_trans_cancel; + } else { + error = xfs_iext_count_may_overflow(target_dp, + XFS_DATA_FORK, + XFS_IEXT_DIR_MANIP_CNT(mp)); + if (error) + goto out_trans_cancel; } } else { /* @@ -3283,9 +3318,16 @@ xfs_rename( if (wip) { error = xfs_dir_replace(tp, src_dp, src_name, wip->i_ino, spaceres); - } else + } else { + /* + * NOTE: We don't need to check for extent count overflow here + * because the dir remove name code will leave the dir block in + * place if the extent count would overflow. + */ error = xfs_dir_removename(tp, src_dp, src_name, src_ip->i_ino, spaceres); + } + if (error) goto out_trans_cancel; From patchwork Sun Jan 10 03:29:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 12008869 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 28447C433DB for ; Sun, 10 Jan 2021 03:31:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F3D3F22AAA for ; Sun, 10 Jan 2021 03:31:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726475AbhAJDbF (ORCPT ); Sat, 9 Jan 2021 22:31:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726245AbhAJDbF (ORCPT ); Sat, 9 Jan 2021 22:31:05 -0500 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF128C0617A7 for ; Sat, 9 Jan 2021 19:29:58 -0800 (PST) Received: by mail-pg1-x534.google.com with SMTP id v19so10294315pgj.12 for ; Sat, 09 Jan 2021 19:29:58 -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=ubOW171teC9ubdwQpqHiQv4fYIYHgh/wHn9tXIiatU4=; b=SspcM/lfG5rAR7UJ0oLwrYXl8T14OZPsoEWQy0Qxun79eNq2tMQjDYJe0464vlmIac PRgs/FC0WGfnS0O8q1skfyiRXmp5VVyAcemWhI7DEiCFm6CkWubmpWdK1t7spaZvcuO0 /yFpJd9CAOkNWvbylbzdmvIEeZOFtaIz/Atozjkxgh26IBIGk2l+eF+kjMblTWB0ZhkU t0sQv2xv6vhcr5V5aBmiLH/jy1lVUSlnBRjoqzSok9yhQZ0koZ/SRj9Qic7utyuTqyeL hsKWQJj5JDllqnRlomIb6PF6+/IdmteVzbNHCFD7Vdb4uxHGvz3JLBO8/SnBuFPrgpgO pb1g== 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=ubOW171teC9ubdwQpqHiQv4fYIYHgh/wHn9tXIiatU4=; b=klKGTbvT+jO6Sj4Eae9f6eDfNDTqc54aI90aU9kt/0MJ21o4+GtsMkCAenaIwXefE2 OaBkpFDr8Tk2rLQD0LjVzqqeDYseg4Lkh8zEOllyaU1zyrV40wFmAelgSwhHHhQ2HB8J 0hE8v5a5XjaPsEcnRkzBP5diRnX7aDq+3z0xXby8ZfOOtbPaie/hz8vluSQOs432fqnV M0GtPd/0tr/eWJJrYwcV3uZvwSuw2QT+5ymWSlAFLM+oIQhrR1vCvKODxeK39/LA6HiX rdwim3PFU8ZVEEWnBo3c1hGXCAO6U8aAiOVHVQuxBsAbQ+gyLnqM0MMD48fcwfRRt6UR u2JA== X-Gm-Message-State: AOAM5323hZT6KZt/rhixHexaXgUJA4KdXjNDYQyPkOD8Df2eTkjxS11l v+sf+mASvb0dYdQ8iAM4MYsG/EUn65dWUw== X-Google-Smtp-Source: ABdhPJyoqI+imvtiPbv+SNjhbMna3TaQmPUMFZYAfREGyt6XCdUf4rEUKuj5v+YId0tpbhu0TIKlMw== X-Received: by 2002:a62:1816:0:b029:1ae:6d39:b92e with SMTP id 22-20020a6218160000b02901ae6d39b92emr10652994pfy.81.1610249398032; Sat, 09 Jan 2021 19:29:58 -0800 (PST) Received: from localhost.localdomain ([122.179.92.100]) by smtp.gmail.com with ESMTPSA id x6sm14079861pfq.57.2021.01.09.19.29.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Jan 2021 19:29:57 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, djwong@kernel.org, hch@lst.de, allison.henderson@oracle.com Subject: [PATCH V13 07/16] xfs: Check for extent overflow when adding/removing xattrs Date: Sun, 10 Jan 2021 08:59:19 +0530 Message-Id: <20210110032928.3120861-8-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210110032928.3120861-1-chandanrlinux@gmail.com> References: <20210110032928.3120861-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Adding/removing an xattr can cause XFS_DA_NODE_MAXDEPTH extents to be added. One extra extent for dabtree in case a local attr is large enough to cause a double split. It can also cause extent count to increase proportional to the size of a remote xattr's value. Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Allison Henderson Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_attr.c | 13 +++++++++++++ fs/xfs/libxfs/xfs_inode_fork.h | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c index fd8e6418a0d3..be51e7068dcd 100644 --- a/fs/xfs/libxfs/xfs_attr.c +++ b/fs/xfs/libxfs/xfs_attr.c @@ -396,6 +396,7 @@ xfs_attr_set( struct xfs_trans_res tres; bool rsvd = (args->attr_filter & XFS_ATTR_ROOT); int error, local; + int rmt_blks = 0; unsigned int total; if (XFS_FORCED_SHUTDOWN(dp->i_mount)) @@ -442,11 +443,15 @@ xfs_attr_set( tres.tr_logcount = XFS_ATTRSET_LOG_COUNT; tres.tr_logflags = XFS_TRANS_PERM_LOG_RES; total = args->total; + + if (!local) + rmt_blks = xfs_attr3_rmt_blocks(mp, args->valuelen); } else { XFS_STATS_INC(mp, xs_attr_remove); tres = M_RES(mp)->tr_attrrm; total = XFS_ATTRRM_SPACE_RES(mp); + rmt_blks = xfs_attr3_rmt_blocks(mp, XFS_XATTR_SIZE_MAX); } /* @@ -460,6 +465,14 @@ xfs_attr_set( xfs_ilock(dp, XFS_ILOCK_EXCL); xfs_trans_ijoin(args->trans, dp, 0); + + if (args->value || xfs_inode_hasattr(dp)) { + error = xfs_iext_count_may_overflow(dp, XFS_ATTR_FORK, + XFS_IEXT_ATTR_MANIP_CNT(rmt_blks)); + if (error) + goto out_trans_cancel; + } + if (args->value) { unsigned int quota_flags = XFS_QMOPT_RES_REGBLKS; diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index ea1a9dd8a763..8d89838e23f8 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -60,6 +60,16 @@ struct xfs_ifork { #define XFS_IEXT_DIR_MANIP_CNT(mp) \ ((XFS_DA_NODE_MAXDEPTH + 1 + 1) * (mp)->m_dir_geo->fsbcount) +/* + * Adding/removing an xattr can cause XFS_DA_NODE_MAXDEPTH extents to + * be added. One extra extent for dabtree in case a local attr is + * large enough to cause a double split. It can also cause extent + * count to increase proportional to the size of a remote xattr's + * value. + */ +#define XFS_IEXT_ATTR_MANIP_CNT(rmt_blks) \ + (XFS_DA_NODE_MAXDEPTH + max(1, rmt_blks)) + /* * Fork handling. */ From patchwork Sun Jan 10 03:29:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 12008871 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 54F1DC433E0 for ; Sun, 10 Jan 2021 03:31:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2E0F122AAA for ; Sun, 10 Jan 2021 03:31:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726245AbhAJDbF (ORCPT ); Sat, 9 Jan 2021 22:31:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726447AbhAJDbF (ORCPT ); Sat, 9 Jan 2021 22:31:05 -0500 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 207FDC0617A9 for ; Sat, 9 Jan 2021 19:30:01 -0800 (PST) Received: by mail-pg1-x531.google.com with SMTP id z21so10317547pgj.4 for ; Sat, 09 Jan 2021 19:30:01 -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=z+k0Pox3xLg6g4VRM1QJf7emz8PSzx7P6FqqWv5XY+g=; b=ltVUgkB6S/b1wQjf/4qyTnNJon4ps5RGvHGJZ76rXfwh0jFTIGQenNXUA6bpcE3p8/ esWKiq9Szl5NtPWJKOTnN04xr8SsOwTA+TJl/BVOIZxabvdW4BaHyO9c3Os+yib8yp5r 1oEI/LG9Ooez+WdDk1thxt9CFwG0KJRCuQH8RvR8Iz3HEAgdXWTiJ2TOugHVIAAFn6jg SMfDYajgI2mTyG2pmVXfF1fRJag2qORv6TRTpS6nGyDI/HWM9K/u41HX0gcgJi5H+bPO GJT3IoKQvQvZrDFF3EOgThhNaiI1EDwkf2QzhHHnrhRIta0xmVTXCc+kXnx94WzZ7hq5 OpIw== 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=z+k0Pox3xLg6g4VRM1QJf7emz8PSzx7P6FqqWv5XY+g=; b=Q3GJ23oRvv+qNtvJPSsprjYY06ifcm7v/72x72OCV89M3+q6Q8QYsCNJ8bIOuUuoR5 Eh7x8BYb6bHJ5ZTw6xMYU447reI1IwsTYG99A2ln9N/7awRsvvNrtHLFyqBpnDPtOXbC 5bGQmO114IUdFmV4gSR2IeRqHhUxOzukG4H2OzZBnVNzEPlhlm89VY7Ttfet7ZXrfZ3w lC5RRhde0MB3Dt5ii/fEDGXaYsMXiyzm6FdMUDEpwFFXnC+roBLI36VitmW1o9qSg2OM fwgCrlwzoMV9mpYYqshv8O99bJR3egTYJJjzVGMSCuAwFuT2xpE0cU5q+p6P4+AMO+zL 7wQw== X-Gm-Message-State: AOAM530ou3XydyS1q74qxu1/0gd0X3FyA9B4XGvaZwn/SbOvcxNgU8lt DLy0f9R+CUKcfhW5DmB4Ifw+66/y5eebOA== X-Google-Smtp-Source: ABdhPJzQPWJ9M4YKH6ybFKF8HeoU4jxRAis3mDkVaSevFaASXbqE/RgArwMKKt9x6gSk/D6BCw48Dg== X-Received: by 2002:aa7:95a4:0:b029:19e:abd2:4a88 with SMTP id a4-20020aa795a40000b029019eabd24a88mr14202805pfk.2.1610249400560; Sat, 09 Jan 2021 19:30:00 -0800 (PST) Received: from localhost.localdomain ([122.179.92.100]) by smtp.gmail.com with ESMTPSA id x6sm14079861pfq.57.2021.01.09.19.29.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Jan 2021 19:30:00 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, djwong@kernel.org, hch@lst.de, allison.henderson@oracle.com Subject: [PATCH V13 08/16] xfs: Check for extent overflow when writing to unwritten extent Date: Sun, 10 Jan 2021 08:59:20 +0530 Message-Id: <20210110032928.3120861-9-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210110032928.3120861-1-chandanrlinux@gmail.com> References: <20210110032928.3120861-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org A write to a sub-interval of an existing unwritten extent causes the original extent to be split into 3 extents i.e. | Unwritten | Real | Unwritten | Hence extent count can increase by 2. 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 | 9 +++++++++ fs/xfs/xfs_iomap.c | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index 8d89838e23f8..917e289ad962 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -70,6 +70,15 @@ struct xfs_ifork { #define XFS_IEXT_ATTR_MANIP_CNT(rmt_blks) \ (XFS_DA_NODE_MAXDEPTH + max(1, rmt_blks)) +/* + * A write to a sub-interval of an existing unwritten extent causes the original + * extent to be split into 3 extents + * i.e. | Unwritten | Real | Unwritten | + * Hence extent count can increase by 2. + */ +#define XFS_IEXT_WRITE_UNWRITTEN_CNT (2) + + /* * Fork handling. */ diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index f53690febb22..5bf84622421d 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -566,6 +566,11 @@ xfs_iomap_write_unwritten( if (error) goto error_on_bmapi_transaction; + error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + XFS_IEXT_WRITE_UNWRITTEN_CNT); + if (error) + goto error_on_bmapi_transaction; + /* * Modify the unwritten extent state of the buffer. */ From patchwork Sun Jan 10 03:29:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 12008873 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 52694C433E0 for ; Sun, 10 Jan 2021 03:31:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 24B84229EF for ; Sun, 10 Jan 2021 03:31:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726476AbhAJDbH (ORCPT ); Sat, 9 Jan 2021 22:31:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726301AbhAJDbH (ORCPT ); Sat, 9 Jan 2021 22:31:07 -0500 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72884C0617AA for ; Sat, 9 Jan 2021 19:30:03 -0800 (PST) Received: by mail-pg1-x529.google.com with SMTP id z21so10317583pgj.4 for ; Sat, 09 Jan 2021 19:30:03 -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=ZflUbONAaK9/L9BOxfPqTzOfgjlgC/1JMj3JWXw1dMQ=; b=ujVEwGINJQck72U6EUgcIAdx1YAKYf90fVzwn2kw4FYDCMT3nHSrGfDEMlQR+cHzys O14xtYNHICflWdxLuUqiByTLl7g6KEqX93RgyRqjncTdgkThazl8LL8Xjv8L4d6jt3Ko HKLQJ62iRxA2ykcD3mtJ1yr8/R/8GZKkqPM81MBN8y7v/bLPDNa5jfQVXQaAG4vhDcpT AVEkhwDynuP161Vud6EPXyI2kyKCPTKW5NyMlb7POp23N+KEa/BKOmgJSmaWGd5CuYNd CKkNCw6SSK/hlA4SIs8rzGRiEoAyNZo+p1Fx35I0NfXGgDepYvLGtGQOG2pzMHeADxEh Xkxg== 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=ZflUbONAaK9/L9BOxfPqTzOfgjlgC/1JMj3JWXw1dMQ=; b=bkDcn2qa6xTK15QhiZHxXBOkcdgoR22YgIwcSF0a5MCIb7bOWGTMB9gW5723HH02nb TPb/Y4gATiSOondrGIlxAhHVMnlnAt4lDUfvHziw+mV6H9xJ0dz8fhTv+49jqEMXj25P U/QWvYNOcJtnG3vC7/gtcxKHo2Nki8qs5w1nk8ZTcA3YOZsrWdAKYA/+Zj/0eoRx5bbK PAOxgETzUdYYQojWsp3MwKMEdtf1VQ176TmIBug2knTb2i9bSGHoXVHaH1QaNIFjskw/ mDrfNq2YkxsTl0e0atQncC/8rMohDLdQWDz2ZWAd57sHQXdzYOD30LhlGFmks7F92B9A iE2A== X-Gm-Message-State: AOAM53159kTV2LKjG6ldkRL+lJgMOYs+aPNopeYnr1P8vgv1ziApqe4p oIWTqbDhjg+DcJsFeRs9dmL6wz622HVzdw== X-Google-Smtp-Source: ABdhPJyob+ibKq3r1ulJ6LquAV5zssuGnkqhA7g7TY0Bk90llV8umSunY4k9+q0Kh/SlxhjngMz8KA== X-Received: by 2002:a65:6a53:: with SMTP id o19mr13945736pgu.212.1610249402905; Sat, 09 Jan 2021 19:30:02 -0800 (PST) Received: from localhost.localdomain ([122.179.92.100]) by smtp.gmail.com with ESMTPSA id x6sm14079861pfq.57.2021.01.09.19.30.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Jan 2021 19:30:02 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, djwong@kernel.org, hch@lst.de, allison.henderson@oracle.com Subject: [PATCH V13 09/16] xfs: Check for extent overflow when moving extent from cow to data fork Date: Sun, 10 Jan 2021 08:59:21 +0530 Message-Id: <20210110032928.3120861-10-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210110032928.3120861-1-chandanrlinux@gmail.com> References: <20210110032928.3120861-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Moving an extent to data fork can cause a sub-interval of an existing extent to be unmapped. This will increase extent count by 1. Mapping in the new extent can increase the extent count by 1 again i.e. | Old extent | New extent | Old extent | Hence number of extents increases by 2. 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 | 9 +++++++++ fs/xfs/xfs_reflink.c | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index 917e289ad962..c8f279edc5c1 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -79,6 +79,15 @@ struct xfs_ifork { #define XFS_IEXT_WRITE_UNWRITTEN_CNT (2) +/* + * Moving an extent to data fork can cause a sub-interval of an existing extent + * to be unmapped. This will increase extent count by 1. Mapping in the new + * extent can increase the extent count by 1 again i.e. + * | Old extent | New extent | Old extent | + * Hence number of extents increases by 2. + */ +#define XFS_IEXT_REFLINK_END_COW_CNT (2) + /* * Fork handling. */ diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index 6fa05fb78189..ca0ac1426d74 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -628,6 +628,11 @@ xfs_reflink_end_cow_extent( xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, 0); + error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + XFS_IEXT_REFLINK_END_COW_CNT); + if (error) + goto out_cancel; + /* * In case of racing, overlapping AIO writes no COW extents might be * left by the time I/O completes for the loser of the race. In that From patchwork Sun Jan 10 03:29:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 12008875 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 CF9FDC433DB for ; Sun, 10 Jan 2021 03:31:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A5F2622A99 for ; Sun, 10 Jan 2021 03:31:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726301AbhAJDbI (ORCPT ); Sat, 9 Jan 2021 22:31:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726447AbhAJDbH (ORCPT ); Sat, 9 Jan 2021 22:31:07 -0500 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C98DBC0617AB for ; Sat, 9 Jan 2021 19:30:05 -0800 (PST) Received: by mail-pl1-x633.google.com with SMTP id s15so7714886plr.9 for ; Sat, 09 Jan 2021 19:30:05 -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=BZXvtq1IJJ8A9t02QtWduGxtYXovGQz5DbuSLAdCy3M=; b=cZS/fLcYjmK/PYBrrQNS0DrD/Nh4JANVWu4FvWPs/9EhEaa2r0TggELsLFG0Byss6o YBPoFoia0Wc3Qr0tkvp/ijY3uD8qdsKbokEKfYu/LmL1/Qxgf3RbqJ5JiKjr9ADJcqwQ hnkbl19axti64+8oUnr6MulnJZMGVHwVF/hvOtsuzD+MMyb7D6G5/P8F+tK3QrzXjG/0 cLKKl3fmt7pNWJI5PG6O8NBiN0vzOackxT73iZAspgulBkuOwvICgHrY5rSU6VQXf2Md zacwCWB/EoTlIWR0WOKdPTXbLZjkVbJdy4x8N9KSeNXuzik/GWKbp7gff99qPui+Mjuf 5xtA== 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=BZXvtq1IJJ8A9t02QtWduGxtYXovGQz5DbuSLAdCy3M=; b=cI5XFQFMTAEoZyFQ810KZAschlaWkykWo13alTV/9ClLypwmPsTHCenxkb0PBYMWmo a60EarxJTb5x/OL4hThpyspDDrCJXuSq08lmb/3soDnaseaJ+etZGM84dLjyPNHnxP/J dlDay3lE8meLMMidbx+U3dEQImzbIWrOY1pTnh10+8xOB3C18nB5e8zqiyZk8OMSlN+z vSIeMn6W0bGS+AhWQ2qK5k6e3mRvLV7p+MBxR7Izw3ZQ+JWyT2/fEBCve+kwqH6E9CwE 01eTA4fMlTbmUu0ovC3GIWMGEofN1frmpqUXIJRUaWM0A9kZk4Ls0bj1peD3Tee7nCVt p2zA== X-Gm-Message-State: AOAM533leeHLUMw4erBTipvJe5a+G65dXCenCKAoFNurUxPH8G7iCRVA AxLR346TACzC5NRJH9D5WwJO8OZuScCI+g== X-Google-Smtp-Source: ABdhPJxg4N2t3DOpKpWJWpnM8uH1pbAFjxpL53+gK19Z2OQCVd5oCmu+OSCd0T6kEpHNj4K9J25PAQ== X-Received: by 2002:a17:902:6b89:b029:da:fc41:baec with SMTP id p9-20020a1709026b89b02900dafc41baecmr10907723plk.39.1610249405274; Sat, 09 Jan 2021 19:30:05 -0800 (PST) Received: from localhost.localdomain ([122.179.92.100]) by smtp.gmail.com with ESMTPSA id x6sm14079861pfq.57.2021.01.09.19.30.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Jan 2021 19:30:04 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, djwong@kernel.org, hch@lst.de, allison.henderson@oracle.com Subject: [PATCH V13 10/16] xfs: Check for extent overflow when remapping an extent Date: Sun, 10 Jan 2021 08:59:22 +0530 Message-Id: <20210110032928.3120861-11-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210110032928.3120861-1-chandanrlinux@gmail.com> References: <20210110032928.3120861-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Remapping an extent involves unmapping the existing extent and mapping in the new extent. When unmapping, an extent containing the entire unmap range can be split into two extents, i.e. | Old extent | hole | Old extent | Hence extent count increases by 1. Mapping in the new extent into the destination file can increase the extent count by 1. Reviewed-by: Allison Henderson Reviewed-by: Darrick J. Wong Signed-off-by: Chandan Babu R --- fs/xfs/xfs_reflink.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index ca0ac1426d74..e1c98dbf79e4 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -1006,6 +1006,7 @@ xfs_reflink_remap_extent( unsigned int resblks; bool smap_real; bool dmap_written = xfs_bmap_is_written_extent(dmap); + int iext_delta = 0; int nimaps; int error; @@ -1099,6 +1100,16 @@ xfs_reflink_remap_extent( goto out_cancel; } + if (smap_real) + ++iext_delta; + + if (dmap_written) + ++iext_delta; + + error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, iext_delta); + if (error) + goto out_cancel; + if (smap_real) { /* * If the extent we're unmapping is backed by storage (written From patchwork Sun Jan 10 03:29:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 12008877 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 8C637C433DB for ; Sun, 10 Jan 2021 03:31:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6627722A99 for ; Sun, 10 Jan 2021 03:31:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726479AbhAJDbL (ORCPT ); Sat, 9 Jan 2021 22:31:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726447AbhAJDbK (ORCPT ); Sat, 9 Jan 2021 22:31:10 -0500 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A05CC0617B0 for ; Sat, 9 Jan 2021 19:30:08 -0800 (PST) Received: by mail-pl1-x634.google.com with SMTP id t6so7743295plq.1 for ; Sat, 09 Jan 2021 19:30:08 -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=H4La7elDz5rLfoG4JrFZntjDujjZDW53T6MIJGSY3AE=; b=Bm5nCpxeCT/rsrrjX0Bvn8jIGBx504gjKPql84A3ey8HGoIpmxH2a1SYozXuaz3HHy 4/ZXWPGjHrqHi2YSjUJLqM1OPW89heeC8iBgt1gAscKvpJ6t2qdkJ1uppct7JLJ/g9tB KtJ0CbAbjgFdKj34hmetbKixyrmfE0qMcN/CRwyLuxARUOFjSH77ZlmGTJZ/L1iVPNq9 kg5Mxi+f1guJUvKJ0Hexp8MTu1lz1OpetErElgLJHj/Mc1f8C33VNN9QMPu3h3COCLE/ JtaA5DuJ4P4DsLVj/tmJAYAIy8R/Z21lwL0BE7oQZWKfWFBIZtF7rgj78BnuJ1uugbk7 zESA== 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=H4La7elDz5rLfoG4JrFZntjDujjZDW53T6MIJGSY3AE=; b=JOcv3NXqDYdAznZrneuAAwWZuKhVV9XAJwTXY5ZOt4go7vm/Yxx08YpXIkkO4HWfbS UBplae15nT73z6Tst/6Bx/z7HcZeAOxdeSlJGx8JvkaN80lkxtvSS7bRh/TbSJBEQAWc 9kovI7z2f3JnhLOjlfS03soxK1cMDA2GS5NdQ5mbkHYFHY8iRgUivh44YLO+oXHFGbDw 5k8LlsgazTd4f98ciLCF18KZgU6xWXKvZLYCg3WXXksUUtiChdmdhFYAgPHZzMTul7lH ldQy02wgBqIzB/sYjXEqEGlQltxDEoOROdL5SzNI1lzLFYFhQceGtr/41/rkUT/aQQ5q /RfA== X-Gm-Message-State: AOAM530aE1jrYHvpeUld6xBxHAOIJtM4mD3RqOG/qo0DuEnzcc5VMyF9 XHgKcXWJem/ug+1pjcX2TgbeQbPcv8STeg== X-Google-Smtp-Source: ABdhPJx+U+hxCoW+v3oAkozCYf1S89vLgenHuy76aC4cob2r8mHq6/JyH+dwcf7VT9okytYimwlL/A== X-Received: by 2002:a17:902:bd8d:b029:da:fcd1:664 with SMTP id q13-20020a170902bd8db02900dafcd10664mr11064773pls.30.1610249407630; Sat, 09 Jan 2021 19:30:07 -0800 (PST) Received: from localhost.localdomain ([122.179.92.100]) by smtp.gmail.com with ESMTPSA id x6sm14079861pfq.57.2021.01.09.19.30.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Jan 2021 19:30:07 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, djwong@kernel.org, hch@lst.de, allison.henderson@oracle.com Subject: [PATCH V13 11/16] xfs: Check for extent overflow when swapping extents Date: Sun, 10 Jan 2021 08:59:23 +0530 Message-Id: <20210110032928.3120861-12-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210110032928.3120861-1-chandanrlinux@gmail.com> References: <20210110032928.3120861-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Removing an initial range of source/donor file's extent and adding a new extent (from donor/source file) in its place will cause extent count to increase by 1. Reviewed-by: Darrick J. Wong Reviewed-by: Allison Henderson Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_inode_fork.h | 7 +++++++ fs/xfs/xfs_bmap_util.c | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index c8f279edc5c1..9e2137cd7372 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -88,6 +88,13 @@ struct xfs_ifork { */ #define XFS_IEXT_REFLINK_END_COW_CNT (2) +/* + * Removing an initial range of source/donor file's extent and adding a new + * extent (from donor/source file) in its place will cause extent count to + * increase by 1. + */ +#define XFS_IEXT_SWAP_RMAP_CNT (1) + /* * Fork handling. */ diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index 6ac7a6ac2658..f3f8c48ff5bf 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -1399,6 +1399,22 @@ xfs_swap_extent_rmap( irec.br_blockcount); trace_xfs_swap_extent_rmap_remap_piece(tip, &uirec); + if (xfs_bmap_is_real_extent(&uirec)) { + error = xfs_iext_count_may_overflow(ip, + XFS_DATA_FORK, + XFS_IEXT_SWAP_RMAP_CNT); + if (error) + goto out; + } + + if (xfs_bmap_is_real_extent(&irec)) { + error = xfs_iext_count_may_overflow(tip, + XFS_DATA_FORK, + XFS_IEXT_SWAP_RMAP_CNT); + if (error) + goto out; + } + /* Remove the mapping from the donor file. */ xfs_bmap_unmap_extent(tp, tip, &uirec); From patchwork Sun Jan 10 03:29:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 12008879 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 C3EB1C433E0 for ; Sun, 10 Jan 2021 03:31:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9FC7022A99 for ; Sun, 10 Jan 2021 03:31:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726447AbhAJDbL (ORCPT ); Sat, 9 Jan 2021 22:31:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726477AbhAJDbK (ORCPT ); Sat, 9 Jan 2021 22:31:10 -0500 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA2F9C0617B1 for ; Sat, 9 Jan 2021 19:30:10 -0800 (PST) Received: by mail-pl1-x62a.google.com with SMTP id r4so7713839pls.11 for ; Sat, 09 Jan 2021 19:30:10 -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=hgR1oPCOzCW8TWEtHNzhJCtVP7q9OL+0geB2MdujRgQ=; b=A6jgBknJ2UbP8+6YzV+QP6DRrr494tsz+uDSZVd3zM1eCuimduB8+KIhH0RYc6f+B0 QDQJkDK1Fl6tEYigY6Kw65aPxr7gACl45wx8Q30kag/fNAy/QVzt0Nk2XVFXUI8YHqzN AhFtj8KvAr7RLQl94W1JWFkw5LkUwDMPQc1mByFaFEGtQP4IlSRRYBRJdfowMH0AZNXI HIT9b4i8+hz43airM3U6LBXCd3cTEnxUpMtLNdOCU5/ydkjGR8CsP3jow+/g3PEiQLwU 0qwyh5CBO3JV9dH0SobOp8B4NrPlDiRBE1CoXcD1GIKS2DkJuf7Cjmx/upeGJJTpHWRc rXIQ== 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=hgR1oPCOzCW8TWEtHNzhJCtVP7q9OL+0geB2MdujRgQ=; b=FkuQ32oU6Z9S0a+IsEDtQZ+VBYaKTvnW97spSHnlgKtlNH5uh4brfn6y0oQXl8MM2z w3T293bvW09ivorBUnyxQHDRlGUpoWyUVBPVJgl9Qtt5ROqA4QyKURxJD4JArjkagFpv qslCopspuOLpVUbeK6LKkOcKLFyvmb+0oHnkf3wduO/Kg+SGuaAlKBKffJgS6G7QSHng TwypBF3vDeZv3r3/JEV03z1+fckvquK2BoYRuJgrLu2pJufyliZ08C2NfDxIynwwq/yJ WZudBT+AHKmUwO+epm7QvPzccs/H7L69YsyzgYL001vKJ7+/vKVWPPb753+aPqWhAzRs otTw== X-Gm-Message-State: AOAM530WNKZ5ljgHTHY+52E5O0huHEDVWH3BW7qJCFgMaLP85m9xrrI9 XmfcomDAJFDC5otFzVCcp5mUi/9ilcyP0g== X-Google-Smtp-Source: ABdhPJzVeFHzKMNmTZd4AHLPCQHLBKEuK0bABQ09QAPtpfwHj1+xbMBtuRWzfhiYeYC5hBuOJ/DZdA== X-Received: by 2002:a17:902:59dd:b029:db:cda3:39c0 with SMTP id d29-20020a17090259ddb02900dbcda339c0mr13970409plj.81.1610249410046; Sat, 09 Jan 2021 19:30:10 -0800 (PST) Received: from localhost.localdomain ([122.179.92.100]) by smtp.gmail.com with ESMTPSA id x6sm14079861pfq.57.2021.01.09.19.30.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Jan 2021 19:30:09 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, djwong@kernel.org, hch@lst.de, allison.henderson@oracle.com Subject: [PATCH V13 12/16] xfs: Introduce error injection to reduce maximum inode fork extent count Date: Sun, 10 Jan 2021 08:59:24 +0530 Message-Id: <20210110032928.3120861-13-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210110032928.3120861-1-chandanrlinux@gmail.com> References: <20210110032928.3120861-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org This commit adds XFS_ERRTAG_REDUCE_MAX_IEXTENTS error tag which enables userspace programs to test "Inode fork extent count overflow detection" by reducing maximum possible inode fork extent count to 10. Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Allison Henderson Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_errortag.h | 4 +++- fs/xfs/libxfs/xfs_inode_fork.c | 4 ++++ fs/xfs/xfs_error.c | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_errortag.h b/fs/xfs/libxfs/xfs_errortag.h index 53b305dea381..1c56fcceeea6 100644 --- a/fs/xfs/libxfs/xfs_errortag.h +++ b/fs/xfs/libxfs/xfs_errortag.h @@ -56,7 +56,8 @@ #define XFS_ERRTAG_FORCE_SUMMARY_RECALC 33 #define XFS_ERRTAG_IUNLINK_FALLBACK 34 #define XFS_ERRTAG_BUF_IOERROR 35 -#define XFS_ERRTAG_MAX 36 +#define XFS_ERRTAG_REDUCE_MAX_IEXTENTS 36 +#define XFS_ERRTAG_MAX 37 /* * Random factors for above tags, 1 means always, 2 means 1/2 time, etc. @@ -97,5 +98,6 @@ #define XFS_RANDOM_FORCE_SUMMARY_RECALC 1 #define XFS_RANDOM_IUNLINK_FALLBACK (XFS_RANDOM_DEFAULT/10) #define XFS_RANDOM_BUF_IOERROR XFS_RANDOM_DEFAULT +#define XFS_RANDOM_REDUCE_MAX_IEXTENTS 1 #endif /* __XFS_ERRORTAG_H_ */ diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c index 8d48716547e5..e080d7e07643 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.c +++ b/fs/xfs/libxfs/xfs_inode_fork.c @@ -24,6 +24,7 @@ #include "xfs_dir2_priv.h" #include "xfs_attr_leaf.h" #include "xfs_types.h" +#include "xfs_errortag.h" kmem_zone_t *xfs_ifork_zone; @@ -745,6 +746,9 @@ xfs_iext_count_may_overflow( max_exts = (whichfork == XFS_ATTR_FORK) ? MAXAEXTNUM : MAXEXTNUM; + if (XFS_TEST_ERROR(false, ip->i_mount, XFS_ERRTAG_REDUCE_MAX_IEXTENTS)) + max_exts = 10; + nr_exts = ifp->if_nextents + nr_to_add; if (nr_exts < ifp->if_nextents || nr_exts > max_exts) return -EFBIG; diff --git a/fs/xfs/xfs_error.c b/fs/xfs/xfs_error.c index 7f6e20899473..3780b118cc47 100644 --- a/fs/xfs/xfs_error.c +++ b/fs/xfs/xfs_error.c @@ -54,6 +54,7 @@ static unsigned int xfs_errortag_random_default[] = { XFS_RANDOM_FORCE_SUMMARY_RECALC, XFS_RANDOM_IUNLINK_FALLBACK, XFS_RANDOM_BUF_IOERROR, + XFS_RANDOM_REDUCE_MAX_IEXTENTS, }; struct xfs_errortag_attr { @@ -164,6 +165,7 @@ XFS_ERRORTAG_ATTR_RW(force_repair, XFS_ERRTAG_FORCE_SCRUB_REPAIR); XFS_ERRORTAG_ATTR_RW(bad_summary, XFS_ERRTAG_FORCE_SUMMARY_RECALC); XFS_ERRORTAG_ATTR_RW(iunlink_fallback, XFS_ERRTAG_IUNLINK_FALLBACK); XFS_ERRORTAG_ATTR_RW(buf_ioerror, XFS_ERRTAG_BUF_IOERROR); +XFS_ERRORTAG_ATTR_RW(reduce_max_iextents, XFS_ERRTAG_REDUCE_MAX_IEXTENTS); static struct attribute *xfs_errortag_attrs[] = { XFS_ERRORTAG_ATTR_LIST(noerror), @@ -202,6 +204,7 @@ static struct attribute *xfs_errortag_attrs[] = { XFS_ERRORTAG_ATTR_LIST(bad_summary), XFS_ERRORTAG_ATTR_LIST(iunlink_fallback), XFS_ERRORTAG_ATTR_LIST(buf_ioerror), + XFS_ERRORTAG_ATTR_LIST(reduce_max_iextents), NULL, }; From patchwork Sun Jan 10 03:29:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 12008881 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 4EC2DC433DB for ; Sun, 10 Jan 2021 03:31:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 24D4B22A99 for ; Sun, 10 Jan 2021 03:31:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726484AbhAJDbM (ORCPT ); Sat, 9 Jan 2021 22:31:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726477AbhAJDbM (ORCPT ); Sat, 9 Jan 2021 22:31:12 -0500 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0F5BC0617B9 for ; Sat, 9 Jan 2021 19:30:12 -0800 (PST) Received: by mail-pf1-x434.google.com with SMTP id h10so8850676pfo.9 for ; Sat, 09 Jan 2021 19:30:12 -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=2WVMaspHNxdyvXTwMeniwIJ4ii/47tlUYvcEvLyZ18s=; b=k7nQFz6aqJgURF+TcSJnFDM811Tt4s7hWXZE8uwEAX1N0c7+LPYhoB1iKyLNg09mn1 26U5G6s5LdT7/icHcH2ipbRdUU+KD4Hve8TWD6iMddiwCegIork4TZaym9IBqJthqNK4 vvOuVjqtA6yea4itCKWeXGFhKL8WI4/sAhFhzjbkgLrapRrlZfaTbD62/WhD9KFGU2pg QirxSZPqr7MvK/hqkL4+UbtgVr2Y9v8TFrR0QvXmLhZ5MUtHABU3b2ossrEUFf/msOYE WSEkBG3RW1gQ1XtUw72js9czoxKGFEl8Mr3HWyUwgaoTIw0IG+AbHkRfK4hRLW62DizT DDSQ== 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=2WVMaspHNxdyvXTwMeniwIJ4ii/47tlUYvcEvLyZ18s=; b=I5qcREDhxmMGzoBdp12GiYZwxHAzh3Nas1uIZk4SONbOphvN5KrFCZrpVgRq3njR5G VoFavRLkFIm4lW5YCMzrQbNVY8hl/NF1BuRRljO4XeBATwDlSvo3Djmilkvwa7nlmmBZ QPGSbvDPOcTvVgvaSjsudESjN4qv/O/8yRR1E+mCqjtzpuBZ8JIrCuZMNXzUzXKpzgm5 Hd78AJ7uULSFc6Sna/+w5UhiPKAN7tbjhuFhDhqiMBzjt2dk1wlElRuogRO7wgnLHFg/ NRzzF2I81IcWrEFw/uwC36FpS4npMr4FGZr9OW37GgL70FCdSgcYj5KWdAKg2pZ/iy5/ CQ5w== X-Gm-Message-State: AOAM5308A+nmkHGN4cfw/EXahZqclWSKPP+3v2ZCYTwlIt9pmaA/WVKB 6Rd9IbZusp7p+4HF0ZoOl0N1A3dppOyfLA== X-Google-Smtp-Source: ABdhPJww4phYLJiKSc7aAwjGsH0ggi05EJJZIf9gjfOOadOtxvjn5U8YxAnVwZuzGLFRspWZWE1ofg== X-Received: by 2002:aa7:8159:0:b029:1a5:54e4:7cf2 with SMTP id d25-20020aa781590000b02901a554e47cf2mr10495579pfn.69.1610249412422; Sat, 09 Jan 2021 19:30:12 -0800 (PST) Received: from localhost.localdomain ([122.179.92.100]) by smtp.gmail.com with ESMTPSA id x6sm14079861pfq.57.2021.01.09.19.30.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Jan 2021 19:30:11 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, djwong@kernel.org, hch@lst.de, allison.henderson@oracle.com Subject: [PATCH V13 13/16] xfs: Remove duplicate assert statement in xfs_bmap_btalloc() Date: Sun, 10 Jan 2021 08:59:25 +0530 Message-Id: <20210110032928.3120861-14-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210110032928.3120861-1-chandanrlinux@gmail.com> References: <20210110032928.3120861-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org The check for verifying if the allocated extent is from an AG whose index is greater than or equal to that of tp->t_firstblock is already done a couple of statements earlier in the same function. Hence this commit removes the redundant assert statement. Reviewed-by: Allison Henderson Reviewed-by: Darrick J. Wong Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_bmap.c | 1 - 1 file changed, 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 44ed30d0f662..0102aefcf4a6 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -3699,7 +3699,6 @@ xfs_bmap_btalloc( ap->blkno = args.fsbno; if (ap->tp->t_firstblock == NULLFSBLOCK) ap->tp->t_firstblock = args.fsbno; - ASSERT(nullfb || fb_agno <= args.agno); ap->length = args.len; /* * If the extent size hint is active, we tried to round the From patchwork Sun Jan 10 03:29:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 12008883 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 77148C433E6 for ; Sun, 10 Jan 2021 03:31:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 54B6E22A99 for ; Sun, 10 Jan 2021 03:31:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726477AbhAJDbM (ORCPT ); Sat, 9 Jan 2021 22:31:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726481AbhAJDbM (ORCPT ); Sat, 9 Jan 2021 22:31:12 -0500 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6753BC0617BA for ; Sat, 9 Jan 2021 19:30:15 -0800 (PST) Received: by mail-pl1-x636.google.com with SMTP id e2so7707456plt.12 for ; Sat, 09 Jan 2021 19:30:15 -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=w5kbC0J5zG4QEoJGS8pq+48lwW5EdhSbHeM6VkT9c1A=; b=buM2+LSDVyCAOvN9qmqXpIB5h2XKSAJ8w4TFiZjxev0rBbsZ8jm6fMwxRUDi45J2xc v/+Oq9o1Khl1W73A79l+qCHMXwLaBg/83za3A8proWdx0CBsrryuchU0Gs/1JrOQ3zW7 M4H3psJBVqa8ppTnBowmWazAlEMVfeA+vfG1bW48V/iu8eRF+FWYRLk+63dm9iL/d5gV E5OtRrjdXzvx3jwU9ASbRaafeMil71dAglAFNNPk/OUq6h+6hPBfsnyByQaoaTiccKU3 GmxWxY41zgqIo23sv96q+AhQyqEuhNnNQ06scSD7d//L0mHmuuQViIX50UHM9lVTJ++E GaZw== 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=w5kbC0J5zG4QEoJGS8pq+48lwW5EdhSbHeM6VkT9c1A=; b=M8cxbL8GFoHaEQt6If2oqZeo4gW/5uzBqDuniQ+x/rUPccq5/n34sbdsH/zMfJX8Mq PAKdslhYZSyPQoFVZQHK8FsKVuMyyA8NKt9KYC67hrCq7kJmFRXs7UuEnXHM4uGNcz1f Q+ioqUFZngp/uwiCGOxy3dy+hcqL3rTwEfWsOJzeuzegj7GZBq4E50omclVRmXPvq1ny 1tL5cVNcGJh2ee1sSNw7AhB1LR7WSjhULczAVepTiEkjZ5PzLopz8/Eafb2gs3Tb/q9Y 6tbiPf87+VZloehhGKfHnlUzmYkhwQAVbyOYtVj8+N3qjmP1Nnz5HLPc5KM8zM9lV2Mz SESw== X-Gm-Message-State: AOAM532uFqSYZwqAlb5mAg/0/29PHZagyRp7cUKYxEcx0VQcbpcbYBDu ODTfpljmxYBXJc7T1FQuRdBL2b2D33krPw== X-Google-Smtp-Source: ABdhPJw1MzEK9kmKMXp7VNS3aKA7VUqY9IfQx7LEN4nxQ+mq0E0TPZSWWFPacOQRsZdndCI9rDg3ng== X-Received: by 2002:a17:90a:c8d:: with SMTP id v13mr11358054pja.75.1610249414814; Sat, 09 Jan 2021 19:30:14 -0800 (PST) Received: from localhost.localdomain ([122.179.92.100]) by smtp.gmail.com with ESMTPSA id x6sm14079861pfq.57.2021.01.09.19.30.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Jan 2021 19:30:14 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, djwong@kernel.org, hch@lst.de, allison.henderson@oracle.com Subject: [PATCH V13 14/16] xfs: Compute bmap extent alignments in a separate function Date: Sun, 10 Jan 2021 08:59:26 +0530 Message-Id: <20210110032928.3120861-15-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210110032928.3120861-1-chandanrlinux@gmail.com> References: <20210110032928.3120861-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org This commit moves over the code which computes stripe alignment and extent size hint alignment into a separate function. Apart from xfs_bmap_btalloc(), the new function will be used by another function introduced in a future commit. Reviewed-by: Darrick J. Wong Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_bmap.c | 89 +++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 37 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 0102aefcf4a6..ff4ca6c456c3 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -3463,13 +3463,59 @@ xfs_bmap_btalloc_accounting( args->len); } +static int +xfs_bmap_compute_alignments( + struct xfs_bmalloca *ap, + struct xfs_alloc_arg *args) +{ + struct xfs_mount *mp = args->mp; + xfs_extlen_t align = 0; /* minimum allocation alignment */ + int stripe_align = 0; + int error; + + /* stripe alignment for allocation is determined by mount parameters */ + if (mp->m_swidth && (mp->m_flags & XFS_MOUNT_SWALLOC)) + stripe_align = mp->m_swidth; + else if (mp->m_dalign) + stripe_align = mp->m_dalign; + + if (ap->flags & XFS_BMAPI_COWFORK) + align = xfs_get_cowextsz_hint(ap->ip); + else if (ap->datatype & XFS_ALLOC_USERDATA) + align = xfs_get_extsz_hint(ap->ip); + if (align) { + error = xfs_bmap_extsize_align(mp, &ap->got, &ap->prev, + align, 0, ap->eof, 0, ap->conv, + &ap->offset, &ap->length); + ASSERT(!error); + ASSERT(ap->length); + } + + /* apply extent size hints if obtained earlier */ + if (align) { + args->prod = align; + div_u64_rem(ap->offset, args->prod, &args->mod); + if (args->mod) + args->mod = args->prod - args->mod; + } else if (mp->m_sb.sb_blocksize >= PAGE_SIZE) { + args->prod = 1; + args->mod = 0; + } else { + args->prod = PAGE_SIZE >> mp->m_sb.sb_blocklog; + div_u64_rem(ap->offset, args->prod, &args->mod); + if (args->mod) + args->mod = args->prod - args->mod; + } + + return stripe_align; +} + STATIC int xfs_bmap_btalloc( struct xfs_bmalloca *ap) /* bmap alloc argument struct */ { xfs_mount_t *mp; /* mount point structure */ xfs_alloctype_t atype = 0; /* type for allocation routines */ - xfs_extlen_t align = 0; /* minimum allocation alignment */ xfs_agnumber_t fb_agno; /* ag number of ap->firstblock */ xfs_agnumber_t ag; xfs_alloc_arg_t args; @@ -3489,25 +3535,11 @@ xfs_bmap_btalloc( mp = ap->ip->i_mount; - /* stripe alignment for allocation is determined by mount parameters */ - stripe_align = 0; - if (mp->m_swidth && (mp->m_flags & XFS_MOUNT_SWALLOC)) - stripe_align = mp->m_swidth; - else if (mp->m_dalign) - stripe_align = mp->m_dalign; - - if (ap->flags & XFS_BMAPI_COWFORK) - align = xfs_get_cowextsz_hint(ap->ip); - else if (ap->datatype & XFS_ALLOC_USERDATA) - align = xfs_get_extsz_hint(ap->ip); - if (align) { - error = xfs_bmap_extsize_align(mp, &ap->got, &ap->prev, - align, 0, ap->eof, 0, ap->conv, - &ap->offset, &ap->length); - ASSERT(!error); - ASSERT(ap->length); - } + memset(&args, 0, sizeof(args)); + args.tp = ap->tp; + args.mp = mp; + stripe_align = xfs_bmap_compute_alignments(ap, &args); nullfb = ap->tp->t_firstblock == NULLFSBLOCK; fb_agno = nullfb ? NULLAGNUMBER : XFS_FSB_TO_AGNO(mp, @@ -3538,9 +3570,6 @@ xfs_bmap_btalloc( * Normal allocation, done through xfs_alloc_vextent. */ tryagain = isaligned = 0; - memset(&args, 0, sizeof(args)); - args.tp = ap->tp; - args.mp = mp; args.fsbno = ap->blkno; args.oinfo = XFS_RMAP_OINFO_SKIP_UPDATE; @@ -3571,21 +3600,7 @@ xfs_bmap_btalloc( args.total = ap->total; args.minlen = ap->minlen; } - /* apply extent size hints if obtained earlier */ - if (align) { - args.prod = align; - div_u64_rem(ap->offset, args.prod, &args.mod); - if (args.mod) - args.mod = args.prod - args.mod; - } else if (mp->m_sb.sb_blocksize >= PAGE_SIZE) { - args.prod = 1; - args.mod = 0; - } else { - args.prod = PAGE_SIZE >> mp->m_sb.sb_blocklog; - div_u64_rem(ap->offset, args.prod, &args.mod); - if (args.mod) - args.mod = args.prod - args.mod; - } + /* * If we are not low on available data blocks, and the underlying * logical volume manager is a stripe, and the file offset is zero then From patchwork Sun Jan 10 03:29:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 12008885 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 1573FC433DB for ; Sun, 10 Jan 2021 03:31:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E109122A99 for ; Sun, 10 Jan 2021 03:31:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726481AbhAJDbS (ORCPT ); Sat, 9 Jan 2021 22:31:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726267AbhAJDbS (ORCPT ); Sat, 9 Jan 2021 22:31:18 -0500 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B67D2C0617BB for ; Sat, 9 Jan 2021 19:30:17 -0800 (PST) Received: by mail-pg1-x536.google.com with SMTP id v19so10294633pgj.12 for ; Sat, 09 Jan 2021 19:30:17 -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=9P5ZxB5U8FlibcHn25BfII6i6eHF++h7Z1D7nnaozPM=; b=Dhk5enHRxvqTgD4IeP4tezQbLNEtDg8LnpPqHfwD6VoUMR4dIaT3/6U309ftQlfgOk zfBWtkEIYwhAp84ev8q8yFe7RbtZFc/Mfuhicd/6m4wDU2U4GTqIt30jXvYec1L8FNSy MKImcMUswgUqWhqp/TCwB728lPb+F6V/TyZCAaoQs8RSDT0zR/DukfGFvFspJUrUR0Yi qMpo+hEvuOuvuFcDNUVhfPcQh0ywJU5zdgzSnhrat3EG8sR9LLXZUWNP7tgkEI8XU9Ne ggX80QKdFCOyB9oFBuZoxvf/ES9yzMxeFjpnSKoq8ASKn5xNBdKe3XjdjWKt45+JwdKd YWTQ== 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=9P5ZxB5U8FlibcHn25BfII6i6eHF++h7Z1D7nnaozPM=; b=ddm9Ec94XHhzfeK437jGX4pq6k5HkA5RcfVKba9Heo4wW2vtRYt9tko08LJhMaaWe9 0vPJOmyn9fy8azH/uO+JduWT2B9lmEQ+0xQ5MIyxj/J69j1yV6Hiu3ObLZU6HZ/lFJo+ M9sehISFwtyky3/F063LCgUsnQc8jBI1nTvCup2wU6oxlJOQhhH8YKgdqNJdCwO7uD6w FOT5YMm9RgE0YXJaR4y6WXNYicSSKbfA/BjTjqjnsfUjiGTpI1tCoU7scl4r3UC89evU IQUFYnGfSBXu8uiZk93xTk8zKm0Ez1kgkkJXBfmXQGLhOSzAhtYBUepL+91srei2lG9q Ffvg== X-Gm-Message-State: AOAM531CofRb3A0pW4VBOs5cWlmuiUjoxOuhDgokp6nCe5fW0SPOOz1X ii0V141gVJxrpctnahS3WzqkObW88D9lkQ== X-Google-Smtp-Source: ABdhPJwYg4ctbH+jk09lu47/HoTFMPiONI3kIxqDo0P5aWuviah4xP8ZMEQ6hQishd48KVXJ6gKu6Q== X-Received: by 2002:a65:430b:: with SMTP id j11mr13677050pgq.130.1610249417189; Sat, 09 Jan 2021 19:30:17 -0800 (PST) Received: from localhost.localdomain ([122.179.92.100]) by smtp.gmail.com with ESMTPSA id x6sm14079861pfq.57.2021.01.09.19.30.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Jan 2021 19:30:16 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, djwong@kernel.org, hch@lst.de, allison.henderson@oracle.com Subject: [PATCH V13 15/16] xfs: Process allocated extent in a separate function Date: Sun, 10 Jan 2021 08:59:27 +0530 Message-Id: <20210110032928.3120861-16-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210110032928.3120861-1-chandanrlinux@gmail.com> References: <20210110032928.3120861-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org This commit moves over the code in xfs_bmap_btalloc() which is responsible for processing an allocated extent to a new function. Apart from xfs_bmap_btalloc(), the new function will be invoked by another function introduced in a future commit. Reviewed-by: Allison Henderson Reviewed-by: Darrick J. Wong Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_bmap.c | 74 ++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 29 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index ff4ca6c456c3..19b5a516cb30 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -3510,6 +3510,48 @@ xfs_bmap_compute_alignments( return stripe_align; } +static void +xfs_bmap_process_allocated_extent( + struct xfs_bmalloca *ap, + struct xfs_alloc_arg *args, + xfs_fileoff_t orig_offset, + xfs_extlen_t orig_length) +{ + int nullfb; + + nullfb = ap->tp->t_firstblock == NULLFSBLOCK; + + /* + * check the allocation happened at the same or higher AG than + * the first block that was allocated. + */ + ASSERT(nullfb || + XFS_FSB_TO_AGNO(args->mp, ap->tp->t_firstblock) <= + XFS_FSB_TO_AGNO(args->mp, args->fsbno)); + + ap->blkno = args->fsbno; + if (nullfb) + ap->tp->t_firstblock = args->fsbno; + ap->length = args->len; + /* + * If the extent size hint is active, we tried to round the + * caller's allocation request offset down to extsz and the + * length up to another extsz boundary. If we found a free + * extent we mapped it in starting at this new offset. If the + * newly mapped space isn't long enough to cover any of the + * range of offsets that was originally requested, move the + * mapping up so that we can fill as much of the caller's + * original request as possible. Free space is apparently + * very fragmented so we're unlikely to be able to satisfy the + * hints anyway. + */ + if (ap->length <= orig_length) + ap->offset = orig_offset; + else if (ap->offset + ap->length < orig_offset + orig_length) + ap->offset = orig_offset + orig_length - ap->length; + xfs_bmap_btalloc_accounting(ap, args); +} + STATIC int xfs_bmap_btalloc( struct xfs_bmalloca *ap) /* bmap alloc argument struct */ @@ -3702,36 +3744,10 @@ xfs_bmap_btalloc( return error; ap->tp->t_flags |= XFS_TRANS_LOWMODE; } + if (args.fsbno != NULLFSBLOCK) { - /* - * check the allocation happened at the same or higher AG than - * the first block that was allocated. - */ - ASSERT(ap->tp->t_firstblock == NULLFSBLOCK || - XFS_FSB_TO_AGNO(mp, ap->tp->t_firstblock) <= - XFS_FSB_TO_AGNO(mp, args.fsbno)); - - ap->blkno = args.fsbno; - if (ap->tp->t_firstblock == NULLFSBLOCK) - ap->tp->t_firstblock = args.fsbno; - ap->length = args.len; - /* - * If the extent size hint is active, we tried to round the - * caller's allocation request offset down to extsz and the - * length up to another extsz boundary. If we found a free - * extent we mapped it in starting at this new offset. If the - * newly mapped space isn't long enough to cover any of the - * range of offsets that was originally requested, move the - * mapping up so that we can fill as much of the caller's - * original request as possible. Free space is apparently - * very fragmented so we're unlikely to be able to satisfy the - * hints anyway. - */ - if (ap->length <= orig_length) - ap->offset = orig_offset; - else if (ap->offset + ap->length < orig_offset + orig_length) - ap->offset = orig_offset + orig_length - ap->length; - xfs_bmap_btalloc_accounting(ap, &args); + xfs_bmap_process_allocated_extent(ap, &args, orig_offset, + orig_length); } else { ap->blkno = NULLFSBLOCK; ap->length = 0; From patchwork Sun Jan 10 03:29:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 12008887 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 57609C433E0 for ; Sun, 10 Jan 2021 03:31:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 15FAB229EF for ; Sun, 10 Jan 2021 03:31:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726210AbhAJDbn (ORCPT ); Sat, 9 Jan 2021 22:31:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726090AbhAJDbn (ORCPT ); Sat, 9 Jan 2021 22:31:43 -0500 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BCBCC0617BC for ; Sat, 9 Jan 2021 19:30:20 -0800 (PST) Received: by mail-pl1-x635.google.com with SMTP id be12so7734969plb.4 for ; Sat, 09 Jan 2021 19:30:20 -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=4wE82JGdq0PZJM2hcErYarzCffnoStrqluz/sOS3kg8=; b=hVGyqZXP/eLOXA9l8AgANIWHt2qs3CJOT9NeRAoKcENNK8hY0Dq7KpobLh9SehEI7P FN0CMBoL4d127BpNaqkAKsWMOc2EDU5b423vwXsGUQne5u36o9unyiOJ5iqRN36GB1zb bUX7TbiODP+QFX/pttf7HaGfqUb16HzlfHP6tS4ebsFKEBsfkTXTvBUjsycS6b4wQDP7 GW+OsAUUahIb1uYwyYpOs7KN47LUIprPCV5NtB27wSoDreR7w9JYpwaACVVrwvyJGttq 0C5VAznYkbKzldXzy13vMjRQLz5p4TJsXM0UUqG1GIIaRo7ke/f9aPrTJFm0BjLP1nQ7 RyZA== 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=4wE82JGdq0PZJM2hcErYarzCffnoStrqluz/sOS3kg8=; b=JVo98p6izMIpZO6GrLl5/FyWmb1lErkGNUZZes/A12ybagluo2kPjBmAiJP0nLQPZs 4QHSw7T3nUB9U+kYApXzfvABMz0jObV3XYj6jlsjcC83KoAK6PeksmaNSkJ2UzCn+B8P FE+C/JqATmQ/aGQ1kUxHLbm0xXerBRHLmY5ylmilashlUqluyYvUjCiE8CdRyVe8Kp63 cM7cXCf6EhGy2Mu32MwGoyLBYwViwTPXH50XsHeVk6loi+PkhEFfT80QTeDOpipsoo3u /y6khytw7U7doT4Wk5TN3aSjwD/j8GwYgrGLxr7RFc8dg8v8VY3QIehuyypqCbcCFhdX RLlg== X-Gm-Message-State: AOAM533rfqgGqsjyzCNYqeSSel2FF4iL3+vtmOaezjt+2NCsU5xdRJ6F 7LPUMvSlAxLE4IvnhzqozBJgfLwaMkuo8Q== X-Google-Smtp-Source: ABdhPJztwaEDzdYeAiFgNz8UywwQhy4DV7rVpHxZXZc3l1Kw8B4+VDHIpeOb5Yiz9GUccJ4ojQ625w== X-Received: by 2002:a17:90b:50a:: with SMTP id r10mr11257476pjz.103.1610249419657; Sat, 09 Jan 2021 19:30:19 -0800 (PST) Received: from localhost.localdomain ([122.179.92.100]) by smtp.gmail.com with ESMTPSA id x6sm14079861pfq.57.2021.01.09.19.30.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Jan 2021 19:30:19 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, djwong@kernel.org, hch@lst.de, allison.henderson@oracle.com Subject: [PATCH V13 16/16] xfs: Introduce error injection to allocate only minlen size extents for files Date: Sun, 10 Jan 2021 08:59:28 +0530 Message-Id: <20210110032928.3120861-17-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210110032928.3120861-1-chandanrlinux@gmail.com> References: <20210110032928.3120861-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org This commit adds XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT error tag which helps userspace test programs to get xfs_bmap_btalloc() to always allocate minlen sized extents. This is required for test programs which need a guarantee that minlen extents allocated for a file do not get merged with their existing neighbours in the inode's BMBT. "Inode fork extent overflow check" for Directories, Xattrs and extension of realtime inodes need this since the file offset at which the extents are being allocated cannot be explicitly controlled from userspace. One way to use this error tag is to, 1. Consume all of the free space by sequentially writing to a file. 2. Punch alternate blocks of the file. This causes CNTBT to contain sufficient number of one block sized extent records. 3. Inject XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT error tag. After step 3, xfs_bmap_btalloc() will issue space allocation requests for minlen sized extents only. ENOSPC error code is returned to userspace when there aren't any "one block sized" extents left in any of the AGs. Reviewed-by: Darrick J. Wong Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_alloc.c | 50 ++++++++++++++ fs/xfs/libxfs/xfs_alloc.h | 3 + fs/xfs/libxfs/xfs_bmap.c | 124 ++++++++++++++++++++++++++++------- fs/xfs/libxfs/xfs_errortag.h | 4 +- fs/xfs/xfs_error.c | 3 + 5 files changed, 159 insertions(+), 25 deletions(-) diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c index 7cb9f064ac64..0c623d3c1036 100644 --- a/fs/xfs/libxfs/xfs_alloc.c +++ b/fs/xfs/libxfs/xfs_alloc.c @@ -2474,6 +2474,47 @@ xfs_defer_agfl_block( xfs_defer_add(tp, XFS_DEFER_OPS_TYPE_AGFL_FREE, &new->xefi_list); } +#ifdef DEBUG +/* + * Check if an AGF has a free extent record whose length is equal to + * args->minlen. + */ +STATIC int +xfs_exact_minlen_extent_available( + struct xfs_alloc_arg *args, + struct xfs_buf *agbp, + int *stat) +{ + struct xfs_btree_cur *cnt_cur; + xfs_agblock_t fbno; + xfs_extlen_t flen; + int error = 0; + + cnt_cur = xfs_allocbt_init_cursor(args->mp, args->tp, agbp, + args->agno, XFS_BTNUM_CNT); + error = xfs_alloc_lookup_ge(cnt_cur, 0, args->minlen, stat); + if (error) + goto out; + + if (*stat == 0) { + error = -EFSCORRUPTED; + goto out; + } + + error = xfs_alloc_get_rec(cnt_cur, &fbno, &flen, stat); + if (error) + goto out; + + if (*stat == 1 && flen != args->minlen) + *stat = 0; + +out: + xfs_btree_del_cursor(cnt_cur, error); + + return error; +} +#endif + /* * Decide whether to use this allocation group for this allocation. * If so, fix up the btree freelist's size. @@ -2545,6 +2586,15 @@ xfs_alloc_fix_freelist( if (!xfs_alloc_space_available(args, need, flags)) goto out_agbp_relse; +#ifdef DEBUG + if (args->alloc_minlen_only) { + int stat; + + error = xfs_exact_minlen_extent_available(args, agbp, &stat); + if (error || !stat) + goto out_agbp_relse; + } +#endif /* * Make the freelist shorter if it's too long. * diff --git a/fs/xfs/libxfs/xfs_alloc.h b/fs/xfs/libxfs/xfs_alloc.h index 6c22b12176b8..a4427c5775c2 100644 --- a/fs/xfs/libxfs/xfs_alloc.h +++ b/fs/xfs/libxfs/xfs_alloc.h @@ -75,6 +75,9 @@ typedef struct xfs_alloc_arg { char wasfromfl; /* set if allocation is from freelist */ struct xfs_owner_info oinfo; /* owner of blocks being allocated */ enum xfs_ag_resv_type resv; /* block reservation to use */ +#ifdef DEBUG + bool alloc_minlen_only; /* allocate exact minlen extent */ +#endif } xfs_alloc_arg_t; /* diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 19b5a516cb30..87558f978af0 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -3552,34 +3552,101 @@ xfs_bmap_process_allocated_extent( xfs_bmap_btalloc_accounting(ap, args); } -STATIC int -xfs_bmap_btalloc( - struct xfs_bmalloca *ap) /* bmap alloc argument struct */ +#ifdef DEBUG +static int +xfs_bmap_exact_minlen_extent_alloc( + struct xfs_bmalloca *ap) { - xfs_mount_t *mp; /* mount point structure */ - xfs_alloctype_t atype = 0; /* type for allocation routines */ - xfs_agnumber_t fb_agno; /* ag number of ap->firstblock */ - xfs_agnumber_t ag; - xfs_alloc_arg_t args; - xfs_fileoff_t orig_offset; - xfs_extlen_t orig_length; - xfs_extlen_t blen; - xfs_extlen_t nextminlen = 0; - int nullfb; /* true if ap->firstblock isn't set */ - int isaligned; - int tryagain; - int error; - int stripe_align; + struct xfs_mount *mp = ap->ip->i_mount; + struct xfs_alloc_arg args = { .tp = ap->tp, .mp = mp }; + xfs_fileoff_t orig_offset; + xfs_extlen_t orig_length; + int error; ASSERT(ap->length); + + if (ap->minlen != 1) { + ap->blkno = NULLFSBLOCK; + ap->length = 0; + return 0; + } + orig_offset = ap->offset; orig_length = ap->length; - mp = ap->ip->i_mount; + args.alloc_minlen_only = 1; - memset(&args, 0, sizeof(args)); - args.tp = ap->tp; - args.mp = mp; + xfs_bmap_compute_alignments(ap, &args); + + if (ap->tp->t_firstblock == NULLFSBLOCK) { + /* + * Unlike the longest extent available in an AG, we don't track + * the length of an AG's shortest extent. + * XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT is a debug only knob and + * hence we can afford to start traversing from the 0th AG since + * we need not be concerned about a drop in performance in + * "debug only" code paths. + */ + ap->blkno = XFS_AGB_TO_FSB(mp, 0, 0); + } else { + ap->blkno = ap->tp->t_firstblock; + } + + args.fsbno = ap->blkno; + args.oinfo = XFS_RMAP_OINFO_SKIP_UPDATE; + args.type = XFS_ALLOCTYPE_FIRST_AG; + args.total = args.minlen = args.maxlen = ap->minlen; + + args.alignment = 1; + args.minalignslop = 0; + + args.minleft = ap->minleft; + args.wasdel = ap->wasdel; + args.resv = XFS_AG_RESV_NONE; + args.datatype = ap->datatype; + + error = xfs_alloc_vextent(&args); + if (error) + return error; + + if (args.fsbno != NULLFSBLOCK) { + xfs_bmap_process_allocated_extent(ap, &args, orig_offset, + orig_length); + } else { + ap->blkno = NULLFSBLOCK; + ap->length = 0; + } + + return 0; +} +#else + +#define xfs_bmap_exact_minlen_extent_alloc(bma) (-EFSCORRUPTED) + +#endif + +STATIC int +xfs_bmap_btalloc( + struct xfs_bmalloca *ap) +{ + struct xfs_mount *mp = ap->ip->i_mount; + struct xfs_alloc_arg args = { .tp = ap->tp, .mp = mp }; + xfs_alloctype_t atype = 0; + xfs_agnumber_t fb_agno; /* ag number of ap->firstblock */ + xfs_agnumber_t ag; + xfs_fileoff_t orig_offset; + xfs_extlen_t orig_length; + xfs_extlen_t blen; + xfs_extlen_t nextminlen = 0; + int nullfb; /* true if ap->firstblock isn't set */ + int isaligned; + int tryagain; + int error; + int stripe_align; + + ASSERT(ap->length); + orig_offset = ap->offset; + orig_length = ap->length; stripe_align = xfs_bmap_compute_alignments(ap, &args); @@ -4113,6 +4180,10 @@ xfs_bmap_alloc_userdata( return xfs_bmap_rtalloc(bma); } + if (unlikely(XFS_TEST_ERROR(false, mp, + XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT))) + return xfs_bmap_exact_minlen_extent_alloc(bma); + return xfs_bmap_btalloc(bma); } @@ -4149,10 +4220,15 @@ xfs_bmapi_allocate( else bma->minlen = 1; - if (bma->flags & XFS_BMAPI_METADATA) - error = xfs_bmap_btalloc(bma); - else + if (bma->flags & XFS_BMAPI_METADATA) { + if (unlikely(XFS_TEST_ERROR(false, mp, + XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT))) + error = xfs_bmap_exact_minlen_extent_alloc(bma); + else + error = xfs_bmap_btalloc(bma); + } else { error = xfs_bmap_alloc_userdata(bma); + } if (error || bma->blkno == NULLFSBLOCK) return error; diff --git a/fs/xfs/libxfs/xfs_errortag.h b/fs/xfs/libxfs/xfs_errortag.h index 1c56fcceeea6..6ca9084b6934 100644 --- a/fs/xfs/libxfs/xfs_errortag.h +++ b/fs/xfs/libxfs/xfs_errortag.h @@ -57,7 +57,8 @@ #define XFS_ERRTAG_IUNLINK_FALLBACK 34 #define XFS_ERRTAG_BUF_IOERROR 35 #define XFS_ERRTAG_REDUCE_MAX_IEXTENTS 36 -#define XFS_ERRTAG_MAX 37 +#define XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT 37 +#define XFS_ERRTAG_MAX 38 /* * Random factors for above tags, 1 means always, 2 means 1/2 time, etc. @@ -99,5 +100,6 @@ #define XFS_RANDOM_IUNLINK_FALLBACK (XFS_RANDOM_DEFAULT/10) #define XFS_RANDOM_BUF_IOERROR XFS_RANDOM_DEFAULT #define XFS_RANDOM_REDUCE_MAX_IEXTENTS 1 +#define XFS_RANDOM_BMAP_ALLOC_MINLEN_EXTENT 1 #endif /* __XFS_ERRORTAG_H_ */ diff --git a/fs/xfs/xfs_error.c b/fs/xfs/xfs_error.c index 3780b118cc47..185b4915b7bf 100644 --- a/fs/xfs/xfs_error.c +++ b/fs/xfs/xfs_error.c @@ -55,6 +55,7 @@ static unsigned int xfs_errortag_random_default[] = { XFS_RANDOM_IUNLINK_FALLBACK, XFS_RANDOM_BUF_IOERROR, XFS_RANDOM_REDUCE_MAX_IEXTENTS, + XFS_RANDOM_BMAP_ALLOC_MINLEN_EXTENT, }; struct xfs_errortag_attr { @@ -166,6 +167,7 @@ XFS_ERRORTAG_ATTR_RW(bad_summary, XFS_ERRTAG_FORCE_SUMMARY_RECALC); XFS_ERRORTAG_ATTR_RW(iunlink_fallback, XFS_ERRTAG_IUNLINK_FALLBACK); XFS_ERRORTAG_ATTR_RW(buf_ioerror, XFS_ERRTAG_BUF_IOERROR); XFS_ERRORTAG_ATTR_RW(reduce_max_iextents, XFS_ERRTAG_REDUCE_MAX_IEXTENTS); +XFS_ERRORTAG_ATTR_RW(bmap_alloc_minlen_extent, XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT); static struct attribute *xfs_errortag_attrs[] = { XFS_ERRORTAG_ATTR_LIST(noerror), @@ -205,6 +207,7 @@ static struct attribute *xfs_errortag_attrs[] = { XFS_ERRORTAG_ATTR_LIST(iunlink_fallback), XFS_ERRORTAG_ATTR_LIST(buf_ioerror), XFS_ERRORTAG_ATTR_LIST(reduce_max_iextents), + XFS_ERRORTAG_ATTR_LIST(bmap_alloc_minlen_extent), NULL, };