From patchwork Mon Jan 4 10:31:07 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: 11996489 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.8 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,URIBL_BLOCKED,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 07111C433E0 for ; Mon, 4 Jan 2021 10:32:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CB4E321E92 for ; Mon, 4 Jan 2021 10:32:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726026AbhADKcX (ORCPT ); Mon, 4 Jan 2021 05:32:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725468AbhADKcW (ORCPT ); Mon, 4 Jan 2021 05:32:22 -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 72019C061793 for ; Mon, 4 Jan 2021 02:31:42 -0800 (PST) Received: by mail-pl1-x635.google.com with SMTP id j1so14329393pld.3 for ; Mon, 04 Jan 2021 02:31:42 -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=bbSNkwLHPKknCrZYCW0Ph2Ei2mES/zyiCklccXNHK706G584Jq3wal6nCD3sStoQwx 5zQ6x5iMTKughftJ0rKIZIDrVgCI1S7rJfM0aE2723d2bAw3SJcnEyLmjSTBLMgca0OP 0WEZk9/3mqmGw3mu9120cPrB842shEAUZ1FQsjxARbnVQnhnwsaf6pDXywsnOGaCZ58m ueHp0QaZsROMHOiLLUNoMOQpO/kb53OZw82RrjEeT0vi841Rh/6l4NJWGJlUR7d4LQ98 vW4sW0aAjEVlb9nDhuU7n7QhhK2NSqNdl/fstci2XNThFz9z+U5w/2MYVtdqPDOBJLV9 9/Gg== 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=YfLJIjy5wbrGH/sLutp6nvDrzqKBuZR0UY0+lLZHdr+DiIvaE6vrQrigc2h81MID0F xzvC3QU0W1fbRFzRic+KskGA1OLV6nJFqeoHtLIRoNzFHKwHjhIqPwU3K+p9CAkYmk0V UJrOyEX6Y7Dylyn2C8fmDo8XIV+FTG/H6HMfbyA7EfTtsLZ1jx0ocwNDYi/+KtcdgdNA bwjFdd8S5StFkXmMLI/lSO1r2aGFEMC42KVsh6h/EEezQ+T9vMdvoX7sCWoexwpPCJxj L14/spJIAk8gQp1UnyxNScJtGbUwzRO9RG4OJdW4D2TR4htdlV+1jrlht319MoSpp08W zKxQ== X-Gm-Message-State: AOAM532Jm6SVHFFCCtMoTlnXCQy7MSR3EH0hkGWyp2qFnwm5WxiwDweQ s/rWi+EygX133f6T0cEh3CB+CFBxi5GNkQ== X-Google-Smtp-Source: ABdhPJwHbN1F2xbOheo4ftSkgi6fprn/yR082ou+2bmamHgIBbHmNrhDrNfEQ447vo4zC3pDIoZZeg== X-Received: by 2002:a17:90a:510e:: with SMTP id t14mr29580642pjh.159.1609756301945; Mon, 04 Jan 2021 02:31:41 -0800 (PST) Received: from localhost.localdomain ([122.167.42.132]) by smtp.gmail.com with ESMTPSA id q6sm51265782pfu.23.2021.01.04.02.31.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 02:31:41 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, hch@lst.de, allison.henderson@oracle.com Subject: [PATCH V12 01/14] xfs: Add helper for checking per-inode extent count overflow Date: Mon, 4 Jan 2021 16:01:07 +0530 Message-Id: <20210104103120.41158-2-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210104103120.41158-1-chandanrlinux@gmail.com> References: <20210104103120.41158-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 Mon Jan 4 10:31:08 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: 11996491 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.8 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,URIBL_BLOCKED,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 29DAAC433DB for ; Mon, 4 Jan 2021 10:32:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ED20222211 for ; Mon, 4 Jan 2021 10:32:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726124AbhADKc0 (ORCPT ); Mon, 4 Jan 2021 05:32:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725468AbhADKcZ (ORCPT ); Mon, 4 Jan 2021 05:32:25 -0500 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A6E7C061794 for ; Mon, 4 Jan 2021 02:31:45 -0800 (PST) Received: by mail-pj1-x1033.google.com with SMTP id n3so5062399pjm.1 for ; Mon, 04 Jan 2021 02:31:45 -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=Ts6Mx6eiMJ8uSj2M3upUFg/IGu3yFNfv0rCeUdylrjYHLgOOC+V7M6jtJDTExsRmwW aWdcD/gKD1yJOWN2AMvQVZPjbR8Mkmjq9mDpjuBluXFtR2w8EBKcVXwFG25Hjhf8XGGK 5zyM3V1YCHBlKA+bXjdVs/WNoOdrUFLWZQpevenY9CdfB9UR/gsBU3AuAItH/MXOMlJI b+aBhaDdtwU+W1ZZEwaTyW5hFjDAUWMQmZboQkKCBJWYIkkQEGHxEIB9KwMOTib8Cmxh uunoH+0iOBv0rQUV8mA5UgM2qS6RahcgeO7xtLvG//MJzXLSv//UCzH++g5i7HJczpd+ OWnA== 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=lihruCl5qLs4qUhEs0Lg1KcFqNjAMbLNVccYKM5pNixKehQHvFOSoeXjgjw/MWJcLI 3aWJzMwTMWFNhxhJuSa/KHQ2d0E0TRo822KhSIfhZ1lT8EXrZLrQ/lr3NVGpb8M/QAV0 P2res6yejmU4m46m00RoRg6jmT2721aipSMYHFsheF0T4KQXX0+fnAvyznUa8zhFqDi7 aE7gyrVJZHvOGX6GZhaNifAGgC/rEyBGMfyURVnyJ5rNM+P6HnRgZS721vg4Ciw+Zkoc f5Gkkrjm+P3vbpf3AEcYrtSF/PG560rZqYrn/lSOMH3Z6GYpFvdc9SSsMIPBpPZqqqnm i9SA== X-Gm-Message-State: AOAM530e0c4ETbCXwR+0uI2F8tlL03uDF1AibvrYgfZFO4ui5HDD5npy ejvdNrB/5E+uKDka2eBNmH5n7ZaMooeg9g== X-Google-Smtp-Source: ABdhPJxNlz+MfLtpdWckxBNNYi8E5nSxcL3kBAHYQn+ITUSJ9uTtLZPcjZFmAbEYMddE+xRvkaJlrA== X-Received: by 2002:a17:90b:815:: with SMTP id bk21mr28945195pjb.21.1609756304681; Mon, 04 Jan 2021 02:31:44 -0800 (PST) Received: from localhost.localdomain ([122.167.42.132]) by smtp.gmail.com with ESMTPSA id q6sm51265782pfu.23.2021.01.04.02.31.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 02:31:44 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, hch@lst.de, allison.henderson@oracle.com Subject: [PATCH V12 02/14] xfs: Check for extent overflow when trivally adding a new extent Date: Mon, 4 Jan 2021 16:01:08 +0530 Message-Id: <20210104103120.41158-3-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210104103120.41158-1-chandanrlinux@gmail.com> References: <20210104103120.41158-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 Mon Jan 4 10:31:09 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: 11996493 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.8 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,URIBL_BLOCKED,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 4F0BFC433E6 for ; Mon, 4 Jan 2021 10:32:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 13AAD21E92 for ; Mon, 4 Jan 2021 10:32:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726129AbhADKc2 (ORCPT ); Mon, 4 Jan 2021 05:32:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725468AbhADKc1 (ORCPT ); Mon, 4 Jan 2021 05:32:27 -0500 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7A4EC061795 for ; Mon, 4 Jan 2021 02:31:47 -0800 (PST) Received: by mail-pg1-x52b.google.com with SMTP id i5so18820925pgo.1 for ; Mon, 04 Jan 2021 02:31:47 -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=HmP7PKmtCHdmanl5Y3xo4VmOBwdnVMnsDCHWc/ki+kjdUz2hzopud7z3W1A4+y95P+ CsdWs/tVIG/fzPuLfRfLkV8Bl1z0D7vAxUDN3T38h/4M+gV2F89Tp0u0I76Xcycx3ivZ 4SJJG0cZTdqhweeopltLq64gJxmpCHAD0+chXGQLGaA+tnB7zEjREbAmYiCW8yWKStn0 k7Jla5b50dHda1AcXDP8fUogg8YEHrlteUZ9ymeA9iAKdCZtQF21Xf0TJjSv/XOZR3Oy XMSCr2PSoa7qnEQx4gmYzj1T4REIW9DzIO1Mw+OoaPLZtfGiE0/7t01G1D7esHcB+2xA srwg== 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=M8qAovVIeTzjt31DlzxB+VLjEgdJXii0CxOM460+My5ZP0lO/W516N2pfTqj3H9Pv7 fwG1VOkIqtZwX+xzJRFtvQ5m7NUudiB4Oq4ybFN1cKHRzKHa7ig5Ttn7VIJNNpQkuCRb 9k6HGwyOLn24SfvpQG1U2HHhvWCrMIZJeKclIg9AY7ufkL17MP1oF89c6taIT/1Z5bYg TpyPJvjuOm8b1/WqUoe8d51XorjjZdME3Rj8lfV1iu1GHete1NWJ7jI2NHvEbCwXELBh GXB5o1G6+3zxF6/IKJ6wqSFgSOd6r7khYc/50dgcOQlowi7tdd/QqD4/f4pYFG0zpsEb 2GKA== X-Gm-Message-State: AOAM5302PJAJrJgSULTNwXiaDJD5SKd4Hl5vOWoOYdGAqtjZspm9NZiU bbUbybn2UAy8pPnhfVtWM3gNVfcx56LSkg== X-Google-Smtp-Source: ABdhPJzDuApGn29Yu8pYpGdMuE1KlcFxXO9WLEJRHVBdswDgiq82a0e435iCSRqE1cfyQQFbPlEf4Q== X-Received: by 2002:a63:4d1:: with SMTP id 200mr61423349pge.362.1609756307159; Mon, 04 Jan 2021 02:31:47 -0800 (PST) Received: from localhost.localdomain ([122.167.42.132]) by smtp.gmail.com with ESMTPSA id q6sm51265782pfu.23.2021.01.04.02.31.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 02:31:46 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, hch@lst.de, allison.henderson@oracle.com Subject: [PATCH V12 03/14] xfs: Check for extent overflow when punching a hole Date: Mon, 4 Jan 2021 16:01:09 +0530 Message-Id: <20210104103120.41158-4-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210104103120.41158-1-chandanrlinux@gmail.com> References: <20210104103120.41158-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 Mon Jan 4 10:31:10 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: 11996495 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.8 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 60B75C43381 for ; Mon, 4 Jan 2021 10:32:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3739D22211 for ; Mon, 4 Jan 2021 10:32:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726176AbhADKca (ORCPT ); Mon, 4 Jan 2021 05:32:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725468AbhADKca (ORCPT ); Mon, 4 Jan 2021 05:32:30 -0500 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A105C061796 for ; Mon, 4 Jan 2021 02:31:50 -0800 (PST) Received: by mail-pf1-x42b.google.com with SMTP id s21so16197443pfu.13 for ; Mon, 04 Jan 2021 02:31: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=mbnL4tpNi6ygMWadA4Ppj3OqzFP/kaV/4bufxDiHbb8=; b=a9zIgmh11E42hM9qPsuDkiJKsZgA9c2iFOUD68V6N6jNemqzQCQvpAbc2d1FTg6UlI tG0Hj0r8Wl9d77hrCZ8uxb7JlI04aCeCU/NSTTIJ03b4mnqhpquj1+otcDlYCStf/YP4 Zn8dojtYT/FtlVQvsyRNOJtFMJF78B/D/SsvLYpRBN/xYpzRis44RJIo9p2ZFWQdJFHy CF0c65QGg79BevXllt00zReqsQnjKKw4wMmwMayeHNvg3P3i4jjiyhcNbYRcBIOMDQ1s OdrT1EhWVPZaRdPFBne9rnrDAwG1rJJOtc9J7PMWRRVcGCwas8s0uYTvRRZVGdDxmY3f MB0g== 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=mbnL4tpNi6ygMWadA4Ppj3OqzFP/kaV/4bufxDiHbb8=; b=X3H6rmnVflQj7mv+ECRAVjvOulowpmRrTVfwl0B3FU+TjjIJZkxb0lPDeCbV9ZuuWI 6a30Oa61v+2HK3J+gtMBthl1jH27u398GZ7s+Q0Oe0ldwX2aBllysbX1Z6l4rYwVqt4h ijTb8213ZJbx+p7Qn4W0NWBn/4A4WtXn8ozIEKaEp1NWTA9TnTC7VvRQmCi/bdMd6vJE 8Z0olIrYYCQoG4Wctfx0BrODoCMP6+sfEdNck9Rax64obnoFRiEVX7Tsqtxj/riMJo5b Cx6FsaVx3Eh1KbJPm9uSoYo5n8x5+49Pz5tpmJJ3zHw1+oVT0YcQ/XR0zXwGtdg6QFZ4 ZZKQ== X-Gm-Message-State: AOAM531lkxncEBvB/SGZl5bSs/xySvK1lUOyoJH2CeN4ue548QojDC+A GYHC+AZDfkaJuu2304sTbo1amnAdyh2l3w== X-Google-Smtp-Source: ABdhPJybw55HCtvpxqrE9YM7QNPotISXievDueHSTcKO8lrq1R/RvJNDrTvzsusdP56WDtFt8e1Nyw== X-Received: by 2002:a63:a516:: with SMTP id n22mr69179563pgf.125.1609756309755; Mon, 04 Jan 2021 02:31:49 -0800 (PST) Received: from localhost.localdomain ([122.167.42.132]) by smtp.gmail.com with ESMTPSA id q6sm51265782pfu.23.2021.01.04.02.31.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 02:31:49 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, hch@lst.de, allison.henderson@oracle.com Subject: [PATCH V12 04/14] xfs: Check for extent overflow when adding/removing dir entries Date: Mon, 4 Jan 2021 16:01:10 +0530 Message-Id: <20210104103120.41158-5-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210104103120.41158-1-chandanrlinux@gmail.com> References: <20210104103120.41158-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. Directory entry remove and rename (applicable only to the source directory entry) operations are handled specially to allow them to succeed in low extent count availability scenarios i.e. xfs_bmap_del_extent_real() will now return -ENOSPC when a possible extent count overflow is detected. -ENOSPC is already handled by higher layers of XFS by letting, 1. Empty Data/Free space index blocks to linger around until a future remove operation frees them. 2. Dabtree blocks would be swapped with the last block in the leaf space followed by unmapping of the new last block. Also, Extent overflow check is performed for the target directory entry of the rename operation only when the entry does not exist and a non-zero space reservation is obtained successfully. Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_bmap.c | 15 ++++++++++++ fs/xfs/libxfs/xfs_inode_fork.h | 13 ++++++++++ fs/xfs/xfs_inode.c | 45 ++++++++++++++++++++++++++++++++++ fs/xfs/xfs_symlink.c | 5 ++++ 4 files changed, 78 insertions(+) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 32aeacf6f055..5fd804534e67 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -5151,6 +5151,21 @@ xfs_bmap_del_extent_real( /* * Deleting the middle of the extent. */ + + /* + * For directories, -ENOSPC will be handled by higher layers of + * XFS by letting the corresponding empty Data/Free blocks to + * linger around 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. + */ + if (S_ISDIR(VFS_I(ip)->i_mode) && + whichfork == XFS_DATA_FORK && + xfs_iext_count_may_overflow(ip, whichfork, 1)) { + error = -ENOSPC; + goto done; + } + old = got; got.br_blockcount = del->br_startoff - got.br_startoff; 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..0db21368c7e1 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 @@ -3106,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 around 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) { /* @@ -3116,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 { /* 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 Mon Jan 4 10:31:11 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: 11996497 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.8 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,URIBL_BLOCKED,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 E7017C433DB for ; Mon, 4 Jan 2021 10:33:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BE6D422211 for ; Mon, 4 Jan 2021 10:33:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726253AbhADKdB (ORCPT ); Mon, 4 Jan 2021 05:33:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726248AbhADKdB (ORCPT ); Mon, 4 Jan 2021 05:33:01 -0500 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D71BC061798 for ; Mon, 4 Jan 2021 02:31:52 -0800 (PST) Received: by mail-pf1-x433.google.com with SMTP id c79so16228467pfc.2 for ; Mon, 04 Jan 2021 02:31:52 -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=X4qaBkDGK/Dzui19FEKDW24z8WLa0AxIFL1+Jk9Od9e7tU2BZ45EW49BVJ+sHy2qnx 2kaGbBNPHIl+sNW3QlBR87p6EqxZzajHe5F1xan+dQODJek1/KRoFJzjIgKCfgcMs0Wz lFcwu+ic7aCn9Xq+IWGT8VQvNCegYCIxPzMwJSYbGQi0NeM9MkHruK307SZdbV6Xc3rc TQwc5QMn+R5mzLo8Am23tV62Tdx/v09Tk+bs/PNSxj9BiLcysTeONrWTIuwcIAwK7MA6 xYsws36cAc/DJYb2uAc81Yr8q/UbhYv/TeGRpNqYE06h+VuWzzEXvnE4Y6woKS9OJxkM Nvxw== 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=XZEk3Fwk+YezWvwUv9Ccc28F+bQUUQnZ+/Wkrxs2obuwmlv50N/wBmnSUivUTWf7x/ oNt1BBlTIh21vnc2bIW/hhxiV8KqwANCCeIS0u0fPyLRlSkCQwaCJcAvln2KA0C8r5/d HapTo7XDJ+KwfynRM6IbRQqFJYf5J20be9iqDr9+jBXXejGvzYm8n8AW0XqnhICMUdb2 7VLePjJFJrpKcAPjMvoK2F3KjGpBC1Vn6DwZPLOT4erI5hvf0g4xcbRtkC6AsQrvvLCK ClJiTtkiJgK1LHf77SNLRYZqbHakVlCOjDzz9VIFempkrLl7QzpoaKBY/k4DeZHfdVjN ij0w== X-Gm-Message-State: AOAM53146vLMonJUFUtv8Ao1P/PQyeb+46BcgIunChv9oPH1YTzW6VI+ YwMGeFcOScJEuyXW4uRH5eII97rrdPeLyw== X-Google-Smtp-Source: ABdhPJymtxbn3SP4cR6cdEaDmcVfBUwJVRVoFGcWECcIBlidVHNIvupw6tctKVovxOiSZradi4YCkg== X-Received: by 2002:a63:c501:: with SMTP id f1mr62229981pgd.1.1609756312180; Mon, 04 Jan 2021 02:31:52 -0800 (PST) Received: from localhost.localdomain ([122.167.42.132]) by smtp.gmail.com with ESMTPSA id q6sm51265782pfu.23.2021.01.04.02.31.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 02:31:51 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, hch@lst.de, allison.henderson@oracle.com Subject: [PATCH V12 05/14] xfs: Check for extent overflow when adding/removing xattrs Date: Mon, 4 Jan 2021 16:01:11 +0530 Message-Id: <20210104103120.41158-6-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210104103120.41158-1-chandanrlinux@gmail.com> References: <20210104103120.41158-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 Mon Jan 4 10:31:12 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: 11996499 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.8 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,URIBL_BLOCKED,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 2988AC433E0 for ; Mon, 4 Jan 2021 10:33:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E82B722286 for ; Mon, 4 Jan 2021 10:33:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726248AbhADKdB (ORCPT ); Mon, 4 Jan 2021 05:33:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726240AbhADKdB (ORCPT ); Mon, 4 Jan 2021 05:33:01 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 130C5C06179A for ; Mon, 4 Jan 2021 02:31:55 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id j13so10618595pjz.3 for ; Mon, 04 Jan 2021 02:31:55 -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=S7B4+Z4ZkMRQGFXJ0LBV6/5CXFioNR/Wd9ESauBPp0CPMmnBaAUZT1Lrw5qm1FHh/d I6qssJOWMF+GR5vvDNEeDEpVY5g5whE2ybnM0Vd6+invZHqQwVbe1/sGVlz6VZzB07Kb cE2EVv2cB/zkg0lM7oj+6fRwiJg0iTxzm6fgOCgGkX1qrHgktpyavujVE+NsJeugqTY7 /CqoPD+zjCZixUwLDGNNHZ46W13Z4moakvN7y4H+63oeHKsomV9bNpeTaUV1N2g8tv0G y+nYkIpq6UHo23tudsoLvrNf3dr914yIpyEQndrEq3uLxc/jQKOkV6THkyaPE1Ew/b86 aMSA== 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=qOoLxnO5GojRJiOTcFKp28C0Lapu2gjKazYeorWzHTB9lk1wGTfGT/ixV9fT6PO6e3 InoiEcURU6HELgNSLoRE9BG11bTgeYJwHVxDmJKMr5G1D4sSabPgekaguHcNWHQUpt7F G0kUGpTvAnqof+Ch24+29n+qdwwhwgZ8QDIDx6YRoWNNk76DnPIT22S2TpiX4njur50R 1NHWuV8KsHVVCqMkQY04uNnU1iLOnQCmM2D0Lnnt0Rgcz93pqisfSkkRU3TVtFyCB/I1 WzWoV79YSDRwsxR/JnaChQ4jnmC6OKkU1+8SC5DRk5PoYBHAdkQ9YaBA8RZI7nkrshnE nJIg== X-Gm-Message-State: AOAM5301MSGruK819JAiivhEiacgUOVpK6EiZJcBR2RyOwgyiRhzS2ig axWMpVplU/fw912kweSRjxTk1DUOa/5yXw== X-Google-Smtp-Source: ABdhPJx5kitqY1KYOKMnQEVcXISedIYD6GP5AdHgjMRDI8KPscGizkc35bBdQ6Y8pPuq+rUBv+j4ng== X-Received: by 2002:a17:902:7596:b029:da:b7a3:cdd0 with SMTP id j22-20020a1709027596b02900dab7a3cdd0mr71197192pll.14.1609756314597; Mon, 04 Jan 2021 02:31:54 -0800 (PST) Received: from localhost.localdomain ([122.167.42.132]) by smtp.gmail.com with ESMTPSA id q6sm51265782pfu.23.2021.01.04.02.31.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 02:31:54 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, hch@lst.de, allison.henderson@oracle.com Subject: [PATCH V12 06/14] xfs: Check for extent overflow when writing to unwritten extent Date: Mon, 4 Jan 2021 16:01:12 +0530 Message-Id: <20210104103120.41158-7-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210104103120.41158-1-chandanrlinux@gmail.com> References: <20210104103120.41158-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 Mon Jan 4 10:31: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: 11996505 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.8 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,URIBL_BLOCKED,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 1F4B2C433DB for ; Mon, 4 Jan 2021 10:33:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E229E221F9 for ; Mon, 4 Jan 2021 10:33:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726258AbhADKdD (ORCPT ); Mon, 4 Jan 2021 05:33:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726240AbhADKdD (ORCPT ); Mon, 4 Jan 2021 05:33:03 -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 82823C06179E for ; Mon, 4 Jan 2021 02:31:57 -0800 (PST) Received: by mail-pg1-x534.google.com with SMTP id 15so18799065pgx.7 for ; Mon, 04 Jan 2021 02:31:57 -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=rI5Rwd9wRkJWE5PbBaj9W3byr8PcgiS9YJWOJqJaKlrBNQut8lH77PUatB4b1kb04A gcwlo3u4wSkB/1p8fUPFq3olKFGj/sBIYMZBrbHM6lUJCyojVLCJrw+kbh3IOB22HbXq slkZ9E5SJHf/hEq8UBp56WBszE8CoKkbtw7lP8wfz8SPOdCH3bJOqW7jv/GzST2QNpdT U4Rk+0JEg5NFrPz56LLnOA7u+HxYrSIE1wYZy5rmgpJ8MwQigdFCTDJQiOg8XRO82wVr UDkTCspMC8djpLnC5ZDm8gIrhvOWzCOZYVMDDUh8Fak3BRGRJ1Mrj+ssiHhIQEH1tBOk piFQ== 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=KhQ6i4CtiacQ/nF1sV7755y7iM+EslGUodZHfHG73qpCeadIW+hCBEFn8ns3GYIdry 68HCJWotM7AKE3h5vr8DmG7ic0z4ez4T72R0fYjEG5ozb7sWLPv87s1i67ooE/QoERWJ Onfk8MTWZ4RgxaKhgIjqbxzoit6Cemcfnnzbdzm8XVkLaiDWGCCpjwfSv4RJex/SKhJ/ RDfxhniVXw+Yy3ynSLJgR8TjR898j1xxt05SX0WklB+nuZw8Pj3pFh0JFqTst1MchGVG waPIDsyYeeZyYd9taRpBnU3MW1VJsgO07M+mRJVSJy4Io9Q/GxY7co1eS8EHEaPjizqB gIWg== X-Gm-Message-State: AOAM5303ZRx/zGJEuW141Ie95mE9RnDDFzKVs/kYIKqWjSEZ6sCLQJBm MaN3kk6H0DnkwtsatvcI9+q7ycF/wpNlbg== X-Google-Smtp-Source: ABdhPJzkAKD5Gtc77cKvL9F+zUKIgY+tExLklmmOW5ywXdNgSw6aI0v1TSnvSRD+IC3ZcMlulc/NgA== X-Received: by 2002:a62:808d:0:b029:19e:b084:d5b0 with SMTP id j135-20020a62808d0000b029019eb084d5b0mr45903044pfd.80.1609756317032; Mon, 04 Jan 2021 02:31:57 -0800 (PST) Received: from localhost.localdomain ([122.167.42.132]) by smtp.gmail.com with ESMTPSA id q6sm51265782pfu.23.2021.01.04.02.31.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 02:31:56 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, hch@lst.de, allison.henderson@oracle.com Subject: [PATCH V12 07/14] xfs: Check for extent overflow when moving extent from cow to data fork Date: Mon, 4 Jan 2021 16:01:13 +0530 Message-Id: <20210104103120.41158-8-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210104103120.41158-1-chandanrlinux@gmail.com> References: <20210104103120.41158-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 Mon Jan 4 10:31: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: 11996501 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.8 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 4B71CC433E0 for ; Mon, 4 Jan 2021 10:33:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2356E2242A for ; Mon, 4 Jan 2021 10:33:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726240AbhADKdD (ORCPT ); Mon, 4 Jan 2021 05:33:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726256AbhADKdD (ORCPT ); Mon, 4 Jan 2021 05:33:03 -0500 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEFA0C06179F for ; Mon, 4 Jan 2021 02:31:59 -0800 (PST) Received: by mail-pl1-x630.google.com with SMTP id j1so14329823pld.3 for ; Mon, 04 Jan 2021 02:31:59 -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=cEWr7Q6qpyv6yC1EB3+/fBoRSP2d4ZJpA5gAVYh7BHvjWV8nBtTCiL8Qo4biOxD06j hq/d7rCS5gXe1JaYXxb/dV7EGWwGQa2LTmcil9eBB+S666NblGNX9va8UN/79uSxcThh cY4MCA62BP1Shv3bVuWBcHD8R9uXsDS6f27g54S+fxA1yIQorZ90us68boq1AW3CSYWj 0GFvzcnLP8eCCFx6AgxhNogK5j51obDmIW6SnsRwOmmyh8DBV7qrWGtSDzfRdeE3pOGT ZCGdaef+RK/AG+cK76KXcwfaK2pg/wl4E4Xlo3oLI8JjWoLXU7GROfUWR+1tf3LL7aHl helQ== 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=rLXpSo7M3L6JmZ/1q3OW0bsBpzgNwBz+VodB/EdUZAO4EAs4qcaaIbiZ7r802BVvq/ ZhR6ijBxL/bW7Q87SJ3RwbJajXhO+d8Smug45SKF4nfFD3Ov2zOsoXecKM8OZ0WEK09C UogkQUKbPFepRcpG6CzTaPZqh0Uyok4GoXfEYEQxldr+gCi2+NdozzmR/QEdKICWCs+2 15uRDNs4+LiqnHGRW3rD6p7mB7NwlX6rG6247XdqqN9rsNnSFf+vMOHAIMJoPnc6FrYD 3XFrTpLXAXSA15ZCLLABHRVqbxbiAlQjihczYG7J/ARji7fuzGyL3PK/g+jY9yfjky2L A64Q== X-Gm-Message-State: AOAM533EePweua8v6+m+CnEl/LMthVLdk7Ef/HRZ6J/pQS0U8Jo0MiNw 6pQdfFQfbGCTLXqfOhInuOe73xbH03dHHg== X-Google-Smtp-Source: ABdhPJy89li06Z/PamZcufS6V5xuVb9LjzQF0GNi6KjcxezJ8LYZKzUFFB4gsqLFbYw+fJOGbxNrZw== X-Received: by 2002:a17:902:8483:b029:dc:3e69:4095 with SMTP id c3-20020a1709028483b02900dc3e694095mr48500462plo.66.1609756319493; Mon, 04 Jan 2021 02:31:59 -0800 (PST) Received: from localhost.localdomain ([122.167.42.132]) by smtp.gmail.com with ESMTPSA id q6sm51265782pfu.23.2021.01.04.02.31.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 02:31:59 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, hch@lst.de, allison.henderson@oracle.com Subject: [PATCH V12 08/14] xfs: Check for extent overflow when remapping an extent Date: Mon, 4 Jan 2021 16:01:14 +0530 Message-Id: <20210104103120.41158-9-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210104103120.41158-1-chandanrlinux@gmail.com> References: <20210104103120.41158-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 Mon Jan 4 10:31: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: 11996503 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.8 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 370DBC433E0 for ; Mon, 4 Jan 2021 10:33:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E1F912225E for ; Mon, 4 Jan 2021 10:33:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726505AbhADKdG (ORCPT ); Mon, 4 Jan 2021 05:33:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726503AbhADKdG (ORCPT ); Mon, 4 Jan 2021 05:33:06 -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 73A59C0617A0 for ; Mon, 4 Jan 2021 02:32:02 -0800 (PST) Received: by mail-pg1-x536.google.com with SMTP id n7so18816952pgg.2 for ; Mon, 04 Jan 2021 02:32:02 -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=LUSpTahAIUcWorUbXKcc0u441o7pUrbI7mI+LYd2tM4yccN9xZbYNdrYskgmrMTmYS rKpnmX8izGsqZrExJQagqCeIpMGuwOEWvk7o/jZyHiUOl9Ob9Mggu3xkIeF9Q5zLBu5G zrk25nzoXINbVFMViIbHJw5m8qtgA4IQyXD9O3WX2jfcAUz1jM2M+Y20dzHje8LdiYf+ Scd52cBfyMDFbQ2YOJZvjv2MBIFL0l7uL8p9CpplatUupBzfTDHMWXCEjVIpLPh7INsO L7MKLn2JHfBXi84zO4SpvnhWIdR9fE2/t7ZqKJMVqd4UoHSZViNkDxZ23vvKYak8DxL+ BTcw== 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=OhYCOZD7C5W8aRvZEdZnrZci+8+yhvtD90t94i20rTJQomusC+UuQnuK1n7E/t1y0j H2OOTQckTi+YZlZBVszcF0RahLYc3B8DyYIVV44AkcYDkc+NxBzJZFhIdLX7MsQs8nrA Ew5k5o3VnQkDHk4IexCNuBMWUS7cPICb9GKOSCEQ8GTQ4SV4bIKPvjSs6jKhOskNEOPz +uFr+79sJoVHWEebWvLC0bf1aak5BHeWXJEQf7sbM37INBCCj8BZfaU6Chbb3Q170rBE mzUFs5Kw8marQ/L3/9pOCJhp35wHWtoYD2wjYASZmDUshBCzED3HTEnLZrwfn6S7/dag jmbQ== X-Gm-Message-State: AOAM531RNPWCvlE2skGFf+U/CrXehvSw6OvR5UNTrh/t0k+PS9TxwvIe JfyLjRR0zOaJ10FuRUEAHkai4u0YkBkV6A== X-Google-Smtp-Source: ABdhPJwNR6z6bNDhL8RKzA5q7YWJFkwOA8ayYbQkwJDn2VO4bkTd+MEoj3JFMt1CjuLeFQFwtDGDXw== X-Received: by 2002:a63:ca10:: with SMTP id n16mr69842831pgi.105.1609756321962; Mon, 04 Jan 2021 02:32:01 -0800 (PST) Received: from localhost.localdomain ([122.167.42.132]) by smtp.gmail.com with ESMTPSA id q6sm51265782pfu.23.2021.01.04.02.31.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 02:32:01 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, hch@lst.de, allison.henderson@oracle.com Subject: [PATCH V12 09/14] xfs: Check for extent overflow when swapping extents Date: Mon, 4 Jan 2021 16:01:15 +0530 Message-Id: <20210104103120.41158-10-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210104103120.41158-1-chandanrlinux@gmail.com> References: <20210104103120.41158-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 Mon Jan 4 10:31: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: 11996507 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.8 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,URIBL_BLOCKED,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 58472C433E6 for ; Mon, 4 Jan 2021 10:33:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 166702245C for ; Mon, 4 Jan 2021 10:33:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726503AbhADKdG (ORCPT ); Mon, 4 Jan 2021 05:33:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726504AbhADKdG (ORCPT ); Mon, 4 Jan 2021 05:33:06 -0500 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFABDC0617A2 for ; Mon, 4 Jan 2021 02:32:04 -0800 (PST) Received: by mail-pg1-x535.google.com with SMTP id p18so18781507pgm.11 for ; Mon, 04 Jan 2021 02:32:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hgR1oPCOzCW8TWEtHNzhJCtVP7q9OL+0geB2MdujRgQ=; b=Lfjah7F+5TdDuKO+cwUIkRflQ9S+/950/8rkATUIcevoPy5Z0cnIrbAH3jARCbe/BE t3OuxejG9+Z0pd5ZRb+DZP9MCPjK8zexzcCuNTVZ2cEy7ws6OPmafiKq6IK5+VZrV4kT afQfFsSHpEB7DLH7KaPMKUkjBCFUQlG9jpW1cxE7e4gEawwWPk3fi1FDpe2W84eE9kjg YIqS7onEBB+jt9bpf002/GbU+p7o2D015a64w4L6F5U0nBQCdwC5Ra7jC1qv3XlNfTdp bPxg/f1Y70EL9D+MFu4FetYdzPfCE4vsPAleGguomjZro7Jv8riaT6e30gVun2Slrp0K m3Ug== 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=ee+OyWE6JNe1MM2cILV/ByRreC175gPpSy7lcDCpoTEqYaBvC7UFjgRZmgxAP7pAmK AJQfrOi8L5jmd/2QEC+2jcTfyKn3MBntDamcq/yaRL3pEd5nJJT7y6zRsg19ASKH6nxB WUiAITb0p1eByxuLb8X/LRl7VV2M1StHt5ECIvV0tQL8o65OO0iHA1EBUYNUJPdH2W2j OCceF4eWC7yG5PIqOvacgddobnFl/9SnQpUtBfLyuBs0u+u6CXIrHIQ1csUtO1Nqo4kY 8eyjGiVhLwMbHPipUhZ++y5Kto0Zsfw0E64eXYWv15uhp7uI9/26HcOg1cRme6/9n3+c gBEA== X-Gm-Message-State: AOAM53274fWyKF23Yp2ZuKY2nYa0SBdtRZlPpoRNAxQ5+ixt3YBvvij8 iUjF2i+YJw2lY/FavuLvN0daSKaG4ZTWyQ== X-Google-Smtp-Source: ABdhPJwtylPOyzSb+Vn9e0fmCkvSUrWpDv5aOxVh+MO0amZxE9qc7sDWOpaDVZ2OVBhwqIdSZuzUhA== X-Received: by 2002:a65:4906:: with SMTP id p6mr18234291pgs.173.1609756324466; Mon, 04 Jan 2021 02:32:04 -0800 (PST) Received: from localhost.localdomain ([122.167.42.132]) by smtp.gmail.com with ESMTPSA id q6sm51265782pfu.23.2021.01.04.02.32.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 02:32:04 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, hch@lst.de, allison.henderson@oracle.com Subject: [PATCH V12 10/14] xfs: Introduce error injection to reduce maximum inode fork extent count Date: Mon, 4 Jan 2021 16:01:16 +0530 Message-Id: <20210104103120.41158-11-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210104103120.41158-1-chandanrlinux@gmail.com> References: <20210104103120.41158-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 Mon Jan 4 10:31: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: 11996509 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.8 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 69141C433E0 for ; Mon, 4 Jan 2021 10:33:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D23222211 for ; Mon, 4 Jan 2021 10:33:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726504AbhADKdI (ORCPT ); Mon, 4 Jan 2021 05:33:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726509AbhADKdI (ORCPT ); Mon, 4 Jan 2021 05:33:08 -0500 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45494C0617A3 for ; Mon, 4 Jan 2021 02:32:07 -0800 (PST) Received: by mail-pl1-x62f.google.com with SMTP id x18so14325673pln.6 for ; Mon, 04 Jan 2021 02:32:07 -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=kyItOAxhQVFCAwJy3UPQZzsTSvH+HPyEAsRRtLmtugk=; b=btFv+kJFKKQq3WjB55mWUnhDaASxMHc5ikGJ2jNITwPCAepmpP3m9wA9/uxbU4l6s1 P0YKxxUXhDU08qUDWZ+ZrD2Y+qTnz4KwLurzpZgAVCEZbj5rCUpkacpPfpCBxQdfpPPz yFSzAGAQC1g7yFhqoRHElhTYNlfGFdB9KLihhhfZa1pNpG5SBSsMPXyHff8zXuWJEccf YFP1KIQo5025SkI+vCDWWgmHRC7IpgIbMGTrLQVGWWs60LEv1dWCPdjweJBn8VicM5iG /fawvT7Py8F3PY+ad7fHay2LmfeV3cEFlIIJ2dGkCBQjRLwXQGo9F6PpIiDT1JkPlR2/ LQ7w== 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=kyItOAxhQVFCAwJy3UPQZzsTSvH+HPyEAsRRtLmtugk=; b=md8zfnrRrm07mtogAs0G2Plj5mJyH45uEPD6e9k5ikRYlmLg9cLZBtu65WvvqgjOUJ XgCod3NtpzyPOD6u2SCzxkaVgFxYTxZ5aAIKRvZMSWN2snIU+b2LKO9lyi4noTW5Si5E GBorBK/7p0eABYWAaaSgIPfspi5s5xgfenG4TaHQEJFNGpTjNY4vOK++Bf6xJpiIm6oR NSVHbj15DZjigxuM/2B9V9//9hH6XO9QuOXiLgoifq1npfpduCKTyudkg6YJx37XTsH/ N2Dq8EQUybkX5T4GWls8ttETuUnJ3oCgxaKIhiM6wL9JlR2XyBe7zLXwBrAjwxFVJO0e cu1w== X-Gm-Message-State: AOAM53126nXYy4Dwb+o6FF2B5EyOH9Fa87/4uo3xZsKL7pDSQRWG/5+w GBOzJ8zWWYdtzseEsNDepU1oB5X+S90mqw== X-Google-Smtp-Source: ABdhPJz81NKa9dd/xHw8q4NRhjE0dKxMRXyurRmIcQUSlmYeYeozaGiolh4+t+QsqrZo7JAj0yBkaw== X-Received: by 2002:a17:90a:e551:: with SMTP id ei17mr28712859pjb.187.1609756326844; Mon, 04 Jan 2021 02:32:06 -0800 (PST) Received: from localhost.localdomain ([122.167.42.132]) by smtp.gmail.com with ESMTPSA id q6sm51265782pfu.23.2021.01.04.02.32.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 02:32:06 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, hch@lst.de, allison.henderson@oracle.com Subject: [PATCH V12 11/14] xfs: Remove duplicate assert statement in xfs_bmap_btalloc() Date: Mon, 4 Jan 2021 16:01:17 +0530 Message-Id: <20210104103120.41158-12-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210104103120.41158-1-chandanrlinux@gmail.com> References: <20210104103120.41158-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 5fd804534e67..90147b9f5184 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 Mon Jan 4 10:31: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: 11996511 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.8 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,URIBL_BLOCKED,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 99472C433DB for ; Mon, 4 Jan 2021 10:33:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 64E4622286 for ; Mon, 4 Jan 2021 10:33:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726509AbhADKdI (ORCPT ); Mon, 4 Jan 2021 05:33:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726525AbhADKdI (ORCPT ); Mon, 4 Jan 2021 05:33:08 -0500 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9F11C0617A4 for ; Mon, 4 Jan 2021 02:32:09 -0800 (PST) Received: by mail-pj1-x1033.google.com with SMTP id hk16so10612875pjb.4 for ; Mon, 04 Jan 2021 02:32:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LbxKk11StaMj/5/81yWlxunRU6c99l/5LQhoi5OD94w=; b=ZNxpdv+4D/9pwVUDeXNbZLEV1ZJ4lCfjn0UFHIwsy4IvyZxuMDDjP4RzpGOY7pCt+e DCAmvGkA/qwN3AaiXZv5JJtmbFXDjNKsANkHXe1bjoNUjVntecQbXLVU6kgJ2sMfHz2a QO5q/QWbcGD2+kWixoYYNvg4Vh/fhPxKVSRWQr7iF7hOMUnG45dFFGKg1fCo0RTwdYLJ eVupjJpfuqmXmYr9cUDizaOk6oWkcV2S8riDidcon/1YPnZkgEogdslFqPLDdJavgUvA o9+Wa4GMDReRnlHQke7KnAUO41B14TgKwoM09yIza423tmVkpi2vdUOS6Jnc+fEQTP3D Ri6w== 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=LbxKk11StaMj/5/81yWlxunRU6c99l/5LQhoi5OD94w=; b=NJ2u54VLfbgGGvo/I33lvqopdVC1CBrVkitk+ZMMsWtznbmJs2ffMbSi42eQwm90mz qBSjpv+ZD3p0odjZNrs2BPPB1nslLZhJWvb2vNlB2V4Lew4KpzNXLzorB+2CZTxVwBMH xy7Mrnp7VgmgQ+mbcSHQ6U7Y6QjHg5kCRceWH7m3A7Vfm73pGtMaiMMT2W783inXcHK9 tCceJYGb6tlCeDlZfZohdeTmgnqKJ32rw45KYpdiKVfc6wqlZz6QkVmP6HuG6+I7F26U a30kb377AwOiW0ql1E8srenEF2IOv4bYT8fkmBiTNGvXXRGCt0IrL+SkM8tXyycnoF7M tH3Q== X-Gm-Message-State: AOAM5306ldOGx+OuYtNv1B3K9FrWfjkbiqTCa1RKmOzj2q+sDSdSGwJ4 lnTgknu5z2BSR9I79uTjG5FQh5ZaFP/iaQ== X-Google-Smtp-Source: ABdhPJxqgG61AgEAGFMG7Q7bmPfjPqL1fPS2naMsI6Q9FOU5U8NbWKmLCJa8/E80iOUz0lOQzscZrQ== X-Received: by 2002:a17:90a:bf11:: with SMTP id c17mr29916661pjs.211.1609756329328; Mon, 04 Jan 2021 02:32:09 -0800 (PST) Received: from localhost.localdomain ([122.167.42.132]) by smtp.gmail.com with ESMTPSA id q6sm51265782pfu.23.2021.01.04.02.32.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 02:32:09 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, hch@lst.de, allison.henderson@oracle.com Subject: [PATCH V12 12/14] xfs: Compute bmap extent alignments in a separate function Date: Mon, 4 Jan 2021 16:01:18 +0530 Message-Id: <20210104103120.41158-13-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210104103120.41158-1-chandanrlinux@gmail.com> References: <20210104103120.41158-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 90147b9f5184..3479cb1b8178 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 Mon Jan 4 10:31: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: 11996513 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.8 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 421D6C433E0 for ; Mon, 4 Jan 2021 10:33:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0AC2922473 for ; Mon, 4 Jan 2021 10:33:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726560AbhADKdL (ORCPT ); Mon, 4 Jan 2021 05:33:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726525AbhADKdK (ORCPT ); Mon, 4 Jan 2021 05:33:10 -0500 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 752C7C0617A5 for ; Mon, 4 Jan 2021 02:32:12 -0800 (PST) Received: by mail-pf1-x433.google.com with SMTP id q22so16205020pfk.12 for ; Mon, 04 Jan 2021 02:32: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=BEaJiLz4xuB6I2RHadz+mobqnNAUuDqF4rPwKTO9qO8=; b=EJ4T+wzzBXahqdl8i33TOFqc5s4ZrOF8OmnywRcnwz+SnX8pF5CJsJlivw/LojedWo RS2HT31c+v8q9iHJbxgDsB7awa3LB+0KZoSUKLicgAfrYTokSCrPXZxTcDS8QKj8pjK9 kGY1ZId+mFMjmpnD2nHkKqGb/flxYHTmfmUaUEfDV7uOfj90t+ZPYiF9WVU5+liWmRkT DhCXqJg9D8MKb+hV/gCP92Y8AoYUJWrEVVTkTF5g/o7pLJ6TeAIsDOFTDqUL6nv4ufHp etqGUVI+VdRVMmnb1/DAW6Deuig/A160fh0Ip8+sjmeLY5eCufwEnWVG+a7xWNrwHUTI AfgQ== 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=BEaJiLz4xuB6I2RHadz+mobqnNAUuDqF4rPwKTO9qO8=; b=agdH0FbZ5JxXUGVCt2ATWMRb/BEdCjBCp/tJpdG7JX4tMywnkI7/EeG7rMUMGdD/jS rWWWUU6sJjpYAPIbYiPVs979GT9FbK5+zhiiBDBtFAZeIKpaHXy+AxuvDeZ8K/4ruoEX 8pAz6zxndpTmt9EFuNnHeC15FFRJt97VV/hHYrMtd4ljzBvj3sasgVn6nYxsZWKpPlXn r3RFfbxaQ7KvqiWWy6a9dQlFmPMjAVAvw7RrE70d/OTMqVULasKdMpemHX7HCQ0dRe0U WCt0r6bQQZqUj8gfPLEeMfLllksy2b8d+4/9KEzyDlCCadBcEganUQiVOJHAqDH0bg1g xSAQ== X-Gm-Message-State: AOAM530Ut3vUdGh86578ZO76ErZovBaTWdKZ6/G0XFClWxKuyyjv9vTz jFQIarwyO+03iZUEFUD9RlPXSvlp+CXTvw== X-Google-Smtp-Source: ABdhPJwrxaT9FcgsvFLsmR+MyIdIYzuYJrPsrD++BKSSBIpwlb3CqPHhsNOmjg3sxysg/GyULqs3ow== X-Received: by 2002:a62:78ca:0:b029:19d:ce86:fc22 with SMTP id t193-20020a6278ca0000b029019dce86fc22mr65031848pfc.39.1609756331825; Mon, 04 Jan 2021 02:32:11 -0800 (PST) Received: from localhost.localdomain ([122.167.42.132]) by smtp.gmail.com with ESMTPSA id q6sm51265782pfu.23.2021.01.04.02.32.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 02:32:11 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, hch@lst.de, allison.henderson@oracle.com Subject: [PATCH V12 13/14] xfs: Process allocated extent in a separate function Date: Mon, 4 Jan 2021 16:01:19 +0530 Message-Id: <20210104103120.41158-14-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210104103120.41158-1-chandanrlinux@gmail.com> References: <20210104103120.41158-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 3479cb1b8178..a2ff4818b8df 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 Mon Jan 4 10:31: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: 11996515 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.8 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,URIBL_BLOCKED,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 17EB6C433DB for ; Mon, 4 Jan 2021 10:33:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CF5C122241 for ; Mon, 4 Jan 2021 10:33:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726563AbhADKdL (ORCPT ); Mon, 4 Jan 2021 05:33:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726560AbhADKdK (ORCPT ); Mon, 4 Jan 2021 05:33:10 -0500 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BAA8C0617A6 for ; Mon, 4 Jan 2021 02:32:15 -0800 (PST) Received: by mail-pf1-x433.google.com with SMTP id 11so16223060pfu.4 for ; Mon, 04 Jan 2021 02:32: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=Uw2kF2b2PEYrt+3i8rgtwnJV6rcwRRhBNbw50h65UAM=; b=WoaYzoe+j56DsT8F3mMOTACV+Y2kOf1OMcivPIxSPZnybMP4TjIIJVAjmQLMCcrzAF eSJ0M5QMpkbxDNaPS7tByMOhPMo8PcFy5fhAfb0ue+TiOE6AeFDnP/bJPD10PjirfEBF 0/LejEsL0tyqcWUCJg1ZS3jeKOWN9ej5M8wi4ePEtFZcJ8vRG2ilxGSsRQsG/ztbxEq+ SoEIfXIqIZL06vi0yEV83UujGnmmN81GSeVkOqT33WHWIYZjY72/Bhd7yIPSwGzbV58R s7APAfidarXEaAYn2K1mvW2rCALV+j0Or1iJcRABllDX8Z9F/XpTPeDyZgMIatQaTYLA 3gQg== 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=Uw2kF2b2PEYrt+3i8rgtwnJV6rcwRRhBNbw50h65UAM=; b=cTCa8hn/uQozWB5+qjn1vQyM/RhNgC+imZhiqic+r4AC/iWYyGlAN2o5jKkRRxv2xe A1s+pl/OSozGs5YESvwUymgC2fpBIcIqHobGnuV9c86EKLf/Ds6SqTWMu16f86oPHhwu htVw6hwNyMFqbzz5tC+ub91uUXWrr9HcaCjCsK70YMPMrh9QK5nsxT5nZ5kjMvwZfH1C gN8mH86UsvyePFiNFe1qhDhTG+OyTL7n5z6+1rsbeKBeNHpnM6/f08NjjEnnaXNwL3Zu pTymkBPhymywrua7FamRzXh/PbT5gU1IXtocsvyBBwS6RhBh7+QdgXklHXnW2Y1iEnUG uPiw== X-Gm-Message-State: AOAM530cTdXt9EYwcCKsP0AdlarJV6ytggtmmhCqRMfdteNSB6SDzQwh t9GF9CxJQFsiZKHHI0/mjIKvWNClSkfXfg== X-Google-Smtp-Source: ABdhPJxAjtRMO2Z98pS/Orw1DfY2/Pm1WlqZ2RL3KgraIk7Pgk72e+WCSpYkia12oWexZHeh9Fff9A== X-Received: by 2002:a62:79cd:0:b029:1a8:4d9b:921a with SMTP id u196-20020a6279cd0000b02901a84d9b921amr64226294pfc.33.1609756334522; Mon, 04 Jan 2021 02:32:14 -0800 (PST) Received: from localhost.localdomain ([122.167.42.132]) by smtp.gmail.com with ESMTPSA id q6sm51265782pfu.23.2021.01.04.02.32.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 02:32:14 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, hch@lst.de, allison.henderson@oracle.com Subject: [PATCH V12 14/14] xfs: Introduce error injection to allocate only minlen size extents for files Date: Mon, 4 Jan 2021 16:01:20 +0530 Message-Id: <20210104103120.41158-15-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210104103120.41158-1-chandanrlinux@gmail.com> References: <20210104103120.41158-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 a2ff4818b8df..edfc4a01d83f 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, };