From patchwork Mon Oct 19 06:40:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11843629 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 55D0761C for ; Mon, 19 Oct 2020 06:41:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3508322263 for ; Mon, 19 Oct 2020 06:41:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QkqG+KLH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726906AbgJSGlO (ORCPT ); Mon, 19 Oct 2020 02:41:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726840AbgJSGlO (ORCPT ); Mon, 19 Oct 2020 02:41:14 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87DC5C061755 for ; Sun, 18 Oct 2020 23:41:14 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id hk7so5093072pjb.2 for ; Sun, 18 Oct 2020 23:41:14 -0700 (PDT) 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=muy6wMcrNuR8gPubUATlN8GUSP+GDUcpmrnL7WzPYjQ=; b=QkqG+KLHJJNKXdJlYH3bpbcqyr6xCf39QSCv+PfG8dp3JteooL8alQayrNd3CbhTeF 85NI3bOAQ9GjYTlK4Qhs3RoUbI5gMMHrBKmtJzN4b6kpCI3XkuLwRi3I9oSCeVmZpT0L nreKdao2Mc6AHkyr9lvVb026Szp5mMDjc9sWlBMcHHBuSJVIm2aTIOKxerDipylbR0BD LJzmnhDPrhnZBPvwPmVeTA6ZKKlbJg+SFbVb5C7XecvmSm+uAzghJy1brpyY9Z4wo+Ds D+Oz9r5e1StbhBuo2g1YDWyFpt7CszRQHOFeFhzUwM5ZrVlqrPlj4ACFIbFD2Q1NgBDj 3FRg== 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=muy6wMcrNuR8gPubUATlN8GUSP+GDUcpmrnL7WzPYjQ=; b=jIDuAu9ix080pa0jjhGp6L+lq96arbE+0znc0U4noEOHvp9CTTdOB98y+eq4jT0p8F 5QrloL9UrQKtgMAzkH+QA88EhD5lj8NpQYv7kNhfevhJNIBj4Py4741917JO2N8qXUXm 1dLF6q2XZEVLlqc7RSed4yetqeloufl3pxmfk/xpkdFwgdaST/XPRih5mC+/1zIQisbw 1palE/OikVcIoT7MZuyW6UsIeD/UvW2gPULsr3nDWv7hCuQQ2UDmN99J31Ixru42P+dg P1mGDzFqgDGB6L2tuL7Q153s6fwDnHR/wn9WXsgOl34gWkB+Q8iG02qurXQLJyjHrQwY OZXQ== X-Gm-Message-State: AOAM532JIaYHStleH/bTldsarhmTdIJBa+sCud2wbgFi0yTEZcR3sDd0 r5WDacPAFBnf7ttP03wQaZ+fphySFjc= X-Google-Smtp-Source: ABdhPJz3AWRPjycVjrsz2AKwSCM8q8JTAX8u7qJxNf3vwIlouqjOWBTI68WQ68dw+RrS1/tOoBVCdA== X-Received: by 2002:a17:90a:cb91:: with SMTP id a17mr15505424pju.220.1603089673743; Sun, 18 Oct 2020 23:41:13 -0700 (PDT) Received: from localhost.localdomain ([122.179.121.224]) by smtp.gmail.com with ESMTPSA id w74sm11164189pff.200.2020.10.18.23.41.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Oct 2020 23:41:13 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, Christoph Hellwig Subject: [PATCH V7 01/14] xfs: Add helper for checking per-inode extent count overflow Date: Mon, 19 Oct 2020 12:10:35 +0530 Message-Id: <20201019064048.6591-2-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201019064048.6591-1-chandanrlinux@gmail.com> References: <20201019064048.6591-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: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Chandan Babu R Reviewed-by: Allison Henderson --- 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 Oct 19 06:40:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11843631 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3EDB961C for ; Mon, 19 Oct 2020 06:41:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 200D122260 for ; Mon, 19 Oct 2020 06:41:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HNyDz1gj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726932AbgJSGlR (ORCPT ); Mon, 19 Oct 2020 02:41:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726840AbgJSGlR (ORCPT ); Mon, 19 Oct 2020 02:41:17 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81CA5C061755 for ; Sun, 18 Oct 2020 23:41:17 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id az3so4788921pjb.4 for ; Sun, 18 Oct 2020 23:41:17 -0700 (PDT) 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=g5YTdrzrWA9BMbhsrwrp7DEeVgTBhwWlywTHp+27QjE=; b=HNyDz1gjoFdLfuRkafYYWnwzzNXiS0Xmm/ZdoYODAIbcFf81d+JMSKeapL6WWCwSLZ VCPXtG6ReVl21yxKhsW7sUY/FERWmZE8B03VCYIVaxM4pmh83E8/HqtTZeZij5cVZmP9 fPzC1HZNfFi/b3HYpziJvkCj2NvuGqti/i6eS2iDboevAI/kwfB7YtKv4WzdeZCK0JxS sy83/2NEVI3wogWyA+3Um4h23RIY2lC+qUbvn6k5W5Ds62Omta+DkYCj3EfacUMEliO/ RgwYJF8zkAEB7Hdmt3bbEuo/6p32xmz4/zhwXzG2ErvMzr3luQ+glZ7CdtKTsp4+7vAr oNgg== 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=g5YTdrzrWA9BMbhsrwrp7DEeVgTBhwWlywTHp+27QjE=; b=nNeVL8m8Peg0e052ppTeNfE9DVmInR49enuPNOZXGOW7gP0xjQSk7//25CxzYrrwwl MjXmsnKvIMSX6Nua1AmWaysIHg9PABpz1f3HByLKR/UG/SEqHa4OVwdprQUfq4MQAd/6 zcIC0bHspfUcT68E19+O7qoqOPrML5gm2bxBcWOxjwlnycN0jVChNIJrO+zvszzeYLkU NjdaxGBHYu484PB0t4iKcgy9b9Q0It3KwxWBBvjJ4CRDypOA4989i4liatFlC0NiLiuI 2W3KOdvMUoRRco1vsgfpYdD3+jz9B0z/BSpw5WM8sHyghq/BF/JVAWLEyw+o3DSvfgcK TRuA== X-Gm-Message-State: AOAM531W4f40KP32c/DCCl1J9cXCMAY+t84hov8kzV7csZslfJPk5ej9 L9MLEMKVnsu+RPAgh25eCbVewfgKQpE= X-Google-Smtp-Source: ABdhPJyeu03FEm9UZsi8C0/OJUigurpEqmEN7GIRjft90VK/jVzzVC7eekuGOl5uNT1NTB/HSCLqLQ== X-Received: by 2002:a17:902:6508:b029:d3:b362:72b5 with SMTP id b8-20020a1709026508b02900d3b36272b5mr15878037plk.55.1603089676769; Sun, 18 Oct 2020 23:41:16 -0700 (PDT) Received: from localhost.localdomain ([122.179.121.224]) by smtp.gmail.com with ESMTPSA id w74sm11164189pff.200.2020.10.18.23.41.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Oct 2020 23:41:16 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, Christoph Hellwig Subject: [PATCH V7 02/14] xfs: Check for extent overflow when trivally adding a new extent Date: Mon, 19 Oct 2020 12:10:36 +0530 Message-Id: <20201019064048.6591-3-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201019064048.6591-1-chandanrlinux@gmail.com> References: <20201019064048.6591-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 Signed-off-by: Chandan Babu R Reviewed-by: Allison Henderson --- 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 d9a692484eae..505358839d2f 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 9e16a4d0f97c..1610d6ad089b 100644 --- a/fs/xfs/xfs_bmap_item.c +++ b/fs/xfs/xfs_bmap_item.c @@ -497,6 +497,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 f2a8a0e75e1f..dcd6e61df711 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 3abb8b9d6f4c..a302a96823b8 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 9d4e33d70d2a..3e841a75f272 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 Oct 19 06:40:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11843633 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4D73414B7 for ; Mon, 19 Oct 2020 06:41:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3340F22263 for ; Mon, 19 Oct 2020 06:41:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NhcicWTW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727049AbgJSGlU (ORCPT ); Mon, 19 Oct 2020 02:41:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726840AbgJSGlU (ORCPT ); Mon, 19 Oct 2020 02:41:20 -0400 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B5B3C061755 for ; Sun, 18 Oct 2020 23:41:20 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id q21so5422402pgi.13 for ; Sun, 18 Oct 2020 23:41:20 -0700 (PDT) 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=kkZp74bfuwYpotYVA4sm/s+ckInyUHSobHDhs1qTZVo=; b=NhcicWTW9ngIUP76K/pPc6o2CAwrcBwPBpe1IgN+CPxtyjk6dshT80gSu3fmhVRFD+ C/IYc8/39JlhqHThkR41cdta0acEyxuh7bGc5xiAQzv4DhWZyRipiasgAQMB1M8SVdvI 0g29w8TJ2SutbtgNlKLj9sUMOL/qWTPlm0J+EmOVOfzZ9+YtNTck3DY/92GzNKWp+pOn R6IOuVLbLPbDMU84KYwXxAN31jr+P1yXqUuwml8MApakpTQkRIZNBNASpoCJiBXmEl4q ee4qG7mT5yshj3Aa1w2IA/PPBobolju+fDRIK7VZEmtLxSP+ByN+F4ySFSW6lNyMWMza AOIg== 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=kkZp74bfuwYpotYVA4sm/s+ckInyUHSobHDhs1qTZVo=; b=oN12mvyVYa+AeYUBNiiAqfrIfHDOVFYT5AQh+VJLUhcUf9zmjbNbXUOhnjeVFWccaj qy3jdovd3rh8CoaXWKgc411RrCfKX9ypyxl6ArWYqcKW2fispLZJyFK5s2pdZNAWQ021 XDbQs/8LCSuPTq2YW6n9U5/Wx8ZKLQqk/NhkRgeopvf8ws4q8dr8qrHPGPa0s0ZUEmuU Z1gyh1eXilgBkr9WqG+pc4ecbg/fvkCLy4EBDGj1PWyrK9KdUx7hoOUJRfe048k8LNEH 70d5BfY1uG9gsLYAJfzyLapv1lZLRyun6cG9CQopsN6vc+x+5MzBenq6ZSKaWTVKTclG 4oqw== X-Gm-Message-State: AOAM531gv4rm7aDt4GzK5Y+Xv7WPQm+Ha37AQUoOFEWduP8BJErX49+/ CiCG0+/s7aBgL+4JndM+kUH7FFYQDjg= X-Google-Smtp-Source: ABdhPJz8duwf0I02+Kwk3Gs+EU4PX7mal2dd85o8XfHBFJUVX6F02EStLMAA7cdwsbmehtpbI+q1sw== X-Received: by 2002:a63:4644:: with SMTP id v4mr13078169pgk.351.1603089679728; Sun, 18 Oct 2020 23:41:19 -0700 (PDT) Received: from localhost.localdomain ([122.179.121.224]) by smtp.gmail.com with ESMTPSA id w74sm11164189pff.200.2020.10.18.23.41.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Oct 2020 23:41:19 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, Christoph Hellwig Subject: [PATCH V7 03/14] xfs: Check for extent overflow when punching a hole Date: Mon, 19 Oct 2020 12:10:37 +0530 Message-Id: <20201019064048.6591-4-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201019064048.6591-1-chandanrlinux@gmail.com> References: <20201019064048.6591-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 Signed-off-by: Chandan Babu R Reviewed-by: Allison Henderson --- fs/xfs/libxfs/xfs_inode_fork.h | 7 +++++++ fs/xfs/xfs_bmap_item.c | 15 +++++++++------ fs/xfs/xfs_bmap_util.c | 10 ++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index 7fc2b129a2e7..bcac769a7df6 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -40,6 +40,13 @@ struct xfs_ifork { */ #define XFS_IEXT_ADD_NOSPLIT_CNT (1) +/* + * Punching out an extent from the middle of an existing extent can cause the + * extent count to increase by 1. + * i.e. | Old extent | Hole | Old extent | + */ +#define XFS_IEXT_PUNCH_HOLE_CNT (1) + /* * Fork handling. */ diff --git a/fs/xfs/xfs_bmap_item.c b/fs/xfs/xfs_bmap_item.c index 1610d6ad089b..80d828394158 100644 --- a/fs/xfs/xfs_bmap_item.c +++ b/fs/xfs/xfs_bmap_item.c @@ -439,6 +439,7 @@ xfs_bui_item_recover( xfs_exntst_t state; unsigned int bui_type; int whichfork; + int iext_delta; int error = 0; /* Only one mapping operation per BUI... */ @@ -497,12 +498,14 @@ xfs_bui_item_recover( xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, 0); - if (bui_type == XFS_BMAP_MAP) { - error = xfs_iext_count_may_overflow(ip, whichfork, - XFS_IEXT_ADD_NOSPLIT_CNT); - if (error) - goto err_cancel; - } + if (bui_type == XFS_BMAP_MAP) + iext_delta = XFS_IEXT_ADD_NOSPLIT_CNT; + else + iext_delta = XFS_IEXT_PUNCH_HOLE_CNT; + + error = xfs_iext_count_may_overflow(ip, whichfork, iext_delta); + if (error) + goto err_cancel; count = bmap->me_len; error = xfs_trans_log_finish_bmap_update(tp, budp, bui_type, ip, diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index dcd6e61df711..0776abd0103c 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -891,6 +891,11 @@ xfs_unmap_extent( xfs_trans_ijoin(tp, ip, 0); + error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + XFS_IEXT_PUNCH_HOLE_CNT); + if (error) + goto out_trans_cancel; + error = xfs_bunmapi(tp, ip, startoffset_fsb, len_fsb, 0, 2, done); if (error) goto out_trans_cancel; @@ -1176,6 +1181,11 @@ xfs_insert_file_space( xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, 0); + error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + XFS_IEXT_PUNCH_HOLE_CNT); + if (error) + goto out_trans_cancel; + /* * The extent shifting code works on extent granularity. So, if stop_fsb * is not the starting block of extent, we need to split the extent at From patchwork Mon Oct 19 06:40:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11843635 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 45D5914B7 for ; Mon, 19 Oct 2020 06:41:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1DD3622260 for ; Mon, 19 Oct 2020 06:41:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="f1otJFtU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727075AbgJSGlX (ORCPT ); Mon, 19 Oct 2020 02:41:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726840AbgJSGlX (ORCPT ); Mon, 19 Oct 2020 02:41:23 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52CFAC061755 for ; Sun, 18 Oct 2020 23:41:23 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id h4so5094263pjk.0 for ; Sun, 18 Oct 2020 23:41:23 -0700 (PDT) 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=5B+t231keE1jTHf5wlh6nlSBqHnUwdv0amrbJatXjX4=; b=f1otJFtU1i78BnK9DOg/67By1pA3ZtHSNlZh0x7ezHy05LAaGqvucZc3uwo6VpdzAL P8vmDfMtb4B+3aP5TFA+ZbTYjByvIdyg37P1INSGt2U718W4X3kinmNDJOG6NvbNDEab ZfexDDhfx0ob3FiwTdXVunzt9d+JiPypOHRe3Qk9zFyfHjzIpXpLMYEMRWpBPm0aZaA+ 1qM0A2xELxU+s1n9c7VIPYCzevUyF582qR6D/UO13H4S3fkJJ8WcWlxze4C/cU93Uhkh fv+B/x40HfEjCfOnbLNiqdmdUvXdQaAOvgLO7uTdEkYrLZITWYqb/ZQcZjytoMu1p2f3 ivFw== 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=5B+t231keE1jTHf5wlh6nlSBqHnUwdv0amrbJatXjX4=; b=FNo9t/Sroc6X5e0FjKdn55kYYNGS1339P56nr06vZjhSYPl/dgRBNZyBiHGejf+LNk CmIk6npmz2tOonEaBiUztJei2aj1J+jRND/zfDv+5fkXNzHQbx+nG0sJSdawknEzEbl4 oBrn/BKuBblA1yaU9oTHi2ju2mnDRMa2dw8ETvcPuXRh8GQ/mOjTkFda5i9yLn/S3qMy N0rF/rqf8wh2paZ164gaCCE8pvDQXIxGBqViO/mXWGBqUiyakpUX4HAXwLfz9S68IDsw P4XQRxi2shepKtl6L2K5Bhl7Qsa5cPW2Qfqqzp9yIiOQT5twr3/cM2RTvQxNUGG46Pp8 ptjA== X-Gm-Message-State: AOAM532k4XtAQr95Z3sjGv7ysnrgJQqRV+DLjejZwuxGW/0FZRSyx/dY lpy6f3YQBgIDrogtyqVPb/S03xrDdPY= X-Google-Smtp-Source: ABdhPJzYDA85/KOR2w8Ndlhe+r2qqRPLUzbf0hVu6Ub6AR5FBksReCHgeU65HyKd8JnVXHpECosvgg== X-Received: by 2002:a17:90a:6444:: with SMTP id y4mr15516014pjm.203.1603089682609; Sun, 18 Oct 2020 23:41:22 -0700 (PDT) Received: from localhost.localdomain ([122.179.121.224]) by smtp.gmail.com with ESMTPSA id w74sm11164189pff.200.2020.10.18.23.41.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Oct 2020 23:41:22 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, Christoph Hellwig Subject: [PATCH V7 04/14] xfs: Check for extent overflow when adding/removing xattrs Date: Mon, 19 Oct 2020 12:10:38 +0530 Message-Id: <20201019064048.6591-5-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201019064048.6591-1-chandanrlinux@gmail.com> References: <20201019064048.6591-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 Signed-off-by: Chandan Babu R Reviewed-by: Allison Henderson --- 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 bcac769a7df6..5de2f07d0dd5 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -47,6 +47,16 @@ struct xfs_ifork { */ #define XFS_IEXT_PUNCH_HOLE_CNT (1) +/* + * 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 Oct 19 06:40:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11843637 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6FF9761C for ; Mon, 19 Oct 2020 06:41:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5013222263 for ; Mon, 19 Oct 2020 06:41:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Z1YEYZNa" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727076AbgJSGl1 (ORCPT ); Mon, 19 Oct 2020 02:41:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726840AbgJSGl0 (ORCPT ); Mon, 19 Oct 2020 02:41:26 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADF5BC061755 for ; Sun, 18 Oct 2020 23:41:26 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id o9so4472399plx.10 for ; Sun, 18 Oct 2020 23:41:26 -0700 (PDT) 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=ti45b1pUkN0XCWDswhQqiLSKHoMU4Xp4vqOvltLMQKE=; b=Z1YEYZNaiVeRGdX47nuX9es7Dywmy7bxZYvt96GJDfUn6yPQk4kxLmU5UT8a+WVXQt CANgM2W2v4iX1YCVxZGOgHIi1RGpaxe0D3JWCH69wljIjdCYq+j81eZdNbODcQ2C0+y7 F1vben1S8R69tTzoYYMxJK1Bxh4nwvuvaQG4ClmHcZlGKtzmREMyV2YgITv2wW7isrTO 3gRS9ay7CL8zbL4QJgiiBI85ymmT2+9kF0GGCR3dBsp4qIWpCt6VTsLclDvKBxCbRWDk uFaJ92/6sd6MiVbb1fncm7IEsNw3vxMqNmwM4YEL/Phc4BDJKI2Vl2+/449yLRQACLzC dD2g== 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=ti45b1pUkN0XCWDswhQqiLSKHoMU4Xp4vqOvltLMQKE=; b=k0Pq4HL5oVr2JazZ7Kh5YzS3kn5dxxPoxjEzKpUHkJUD9hUCDzdM8jZLgSdH9yif63 +KEdZNkrXWlQNakshw6AuoKBjQfmhbkucIC7dsAmbHUPrfa4Q/4parEjE8mNP1A7rU3q ca2fkye/Qzn0x4KDQQI1sWKop5ob2Lzi8AiPfrFFohGekYi2S0bC2daaNJTpN0LZDBrc 3PXL4QSVcHBRt0tRZhfVZzc4VmXuhRmM1NtGf1rdj8MB9Vvn/pqEjiiRpkY4M0pCR8AD xn4+V4yTL606rnXsKDJ/gkAayFBgOq9uOF6Cb5CqDJk/AREKH0Ck2X52mobGIWIL9MyR NeCQ== X-Gm-Message-State: AOAM532fdQAJ+I8kC0SDnwvfD+Islqmf8eoEcHBkCsKwiJBFRgaLuRF1 kulbeLiPoMndPxvi6AwHifMdIDD+rNg= X-Google-Smtp-Source: ABdhPJzQb7JtAWBU0Y6r/DvvEHlEbFLbO/dLtSfmM7cIn6SjrawcnC437ZbRjBEEShEkxY4PR0SVag== X-Received: by 2002:a17:90a:be05:: with SMTP id a5mr16769356pjs.118.1603089685937; Sun, 18 Oct 2020 23:41:25 -0700 (PDT) Received: from localhost.localdomain ([122.179.121.224]) by smtp.gmail.com with ESMTPSA id w74sm11164189pff.200.2020.10.18.23.41.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Oct 2020 23:41:25 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, Christoph Hellwig Subject: [PATCH V7 05/14] xfs: Check for extent overflow when adding/removing dir entries Date: Mon, 19 Oct 2020 12:10:39 +0530 Message-Id: <20201019064048.6591-6-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201019064048.6591-1-chandanrlinux@gmail.com> References: <20201019064048.6591-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Directory entry addition/removal 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. Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Chandan Babu R Reviewed-by: Allison Henderson --- fs/xfs/libxfs/xfs_inode_fork.h | 13 +++++++++++++ fs/xfs/xfs_inode.c | 27 +++++++++++++++++++++++++++ fs/xfs/xfs_symlink.c | 5 +++++ 3 files changed, 45 insertions(+) diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index 5de2f07d0dd5..fd93fdc67ee4 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -57,6 +57,19 @@ struct xfs_ifork { #define XFS_IEXT_ATTR_MANIP_CNT(rmt_blks) \ (XFS_DA_NODE_MAXDEPTH + max(1, rmt_blks)) +/* + * Directory entry addition/removal 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 2bfbcf28b1bd..5b41ffaf04d7 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -1177,6 +1177,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 @@ -1393,6 +1398,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 @@ -2861,6 +2871,11 @@ xfs_remove( xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); + error = xfs_iext_count_may_overflow(dp, XFS_DATA_FORK, + XFS_IEXT_DIR_MANIP_CNT(mp)); + if (error) + goto out_trans_cancel; + /* * If we're removing a directory perform some additional validation. */ @@ -3221,6 +3236,18 @@ xfs_rename( if (wip) xfs_trans_ijoin(tp, wip, XFS_ILOCK_EXCL); + error = xfs_iext_count_may_overflow(src_dp, XFS_DATA_FORK, + XFS_IEXT_DIR_MANIP_CNT(mp)); + if (error) + goto out_trans_cancel; + + if (target_ip == NULL) { + error = xfs_iext_count_may_overflow(target_dp, XFS_DATA_FORK, + XFS_IEXT_DIR_MANIP_CNT(mp)); + if (error) + goto out_trans_cancel; + } + /* * If we are using project inheritance, we only allow renames * into our tree when the project IDs are the same; else the diff --git a/fs/xfs/xfs_symlink.c b/fs/xfs/xfs_symlink.c index 8e88a7ca387e..581a4032a817 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 Oct 19 06:40:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11843639 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7C05C61C for ; Mon, 19 Oct 2020 06:41:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 58A2322263 for ; Mon, 19 Oct 2020 06:41:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XbwyXCjq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726996AbgJSGla (ORCPT ); Mon, 19 Oct 2020 02:41:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726840AbgJSGl3 (ORCPT ); Mon, 19 Oct 2020 02:41:29 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8611BC061755 for ; Sun, 18 Oct 2020 23:41:29 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id x13so5434658pgp.7 for ; Sun, 18 Oct 2020 23:41:29 -0700 (PDT) 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=0V3DO6nHiBSINlQ/fV4OzjiC+RHGej2jIrHfYsPI47M=; b=XbwyXCjqWPbwVvr2NkHzl6TGqHC6AAaPNoWNM/Z4yFchmNE2mnBr2hE0ePAbkIFMeV 1+s0AE0btz9B0kirMEafWGUpWBZ7espED/Lvrm8OZYHuqCRIGdWPs9WJANNeVyLiCXga mISRF9JQaQdkC12TVmNRIx5XrMS3FO/qGnUz1MAitLFvC7HwNLVsCgdRIo9iBH5G8t9L bZkgZApK1N5sd6MtluhUsurrcyGMOkmx7R3eU5td8bwP+ZM2WcM5UojW3OjGHogdync0 uMPsGeIYBHvO3YAsd3UcthvLChRdXePOQjfZT0WJMsRAniiob35BFWhAXks9wLOWkrii /Ukg== 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=0V3DO6nHiBSINlQ/fV4OzjiC+RHGej2jIrHfYsPI47M=; b=LCEYf3p/D/xmzNNZUN0iZFNMSrGNSEV/xdwjhnsHWj6rJHgwfKm7BKlnH/am5Bb0Fh odZxNaNXwECgicMRjUG+lQ4A2Z2hwGlsjQ/FfqA/jHzJ4KYbwKoca+Fa+3HYKpBTkBnk Y9BZrgGZJ0kK65ixU5QQ2X6lRU0GlVWySxk9AjlQsiFYDyu1Gs9PPHiX5psJHeipCt5f hiOPwjQq3OOwggv6VaS5+c3hu1rbVeWAbDB+F9G3or1edA6V2hy9B4qBIY6gNsPIi6Zr FVZoCo7SB8qYkN/PmNjbKv87LkR1e6XKLS+TyBVrydkhBNX8ibvDxVSirOtPt5Lxpzi/ rTYQ== X-Gm-Message-State: AOAM531TXP1t+M9kjZLy0dYwc1ABDUWws0G8AOQF9uZ+mDR+TexjIsbK TeQjFz/4V/EHNcEG4JO0tHfPJIa3JTA= X-Google-Smtp-Source: ABdhPJxj5qIH+8t2abOxDqk0y5vKC+WP4FeQlKpD1fL8qwFlqBedx5DmzLqpaB1/CSBEW2/PJivVnw== X-Received: by 2002:a65:55ce:: with SMTP id k14mr13033551pgs.65.1603089688859; Sun, 18 Oct 2020 23:41:28 -0700 (PDT) Received: from localhost.localdomain ([122.179.121.224]) by smtp.gmail.com with ESMTPSA id w74sm11164189pff.200.2020.10.18.23.41.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Oct 2020 23:41:28 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, Christoph Hellwig Subject: [PATCH V7 06/14] xfs: Check for extent overflow when writing to unwritten extent Date: Mon, 19 Oct 2020 12:10:40 +0530 Message-Id: <20201019064048.6591-7-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201019064048.6591-1-chandanrlinux@gmail.com> References: <20201019064048.6591-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 Signed-off-by: Chandan Babu R Reviewed-by: Allison Henderson --- fs/xfs/libxfs/xfs_inode_fork.h | 8 ++++++++ fs/xfs/xfs_iomap.c | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index fd93fdc67ee4..afb647e1e3fa 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -70,6 +70,14 @@ struct xfs_ifork { #define XFS_IEXT_DIR_MANIP_CNT(mp) \ ((XFS_DA_NODE_MAXDEPTH + 1 + 1) * (mp)->m_dir_geo->fsbcount) +/* + * 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 a302a96823b8..2aa788379611 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 Oct 19 06:40:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11843641 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 88C2814B7 for ; Mon, 19 Oct 2020 06:41:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E61F22263 for ; Mon, 19 Oct 2020 06:41:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="e2vwAMn9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727078AbgJSGle (ORCPT ); Mon, 19 Oct 2020 02:41:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726840AbgJSGld (ORCPT ); Mon, 19 Oct 2020 02:41:33 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65043C061755 for ; Sun, 18 Oct 2020 23:41:32 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id b19so4499950pld.0 for ; Sun, 18 Oct 2020 23:41:32 -0700 (PDT) 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=oVyvNGULGulgdR7oslYUMz3NcAvyS5HBRlENdd6QKHA=; b=e2vwAMn9dCwBZ0yEAQPXwnZh2REwNOHfHzKLG03BABg6idUt7ncmRromE5a8wrnoo7 GoV06aIDG/zpE011TVzDnpYV5EKJALA0zLIWGH7rD3IjVvwmwrCAwyymVBbAqG9Jab+E RPIJ+U5z85nXA95SfFRPQ8J8bGjukRBsO2ZvubTS3pUt1XyiM5Vh6y7Oz0XCT3GSosEn //wQeFZMyXcfKyETNmdZFzDVIlF/Cvtrd8L2HxlJ+OtRvlTexRezeRUt+neVnFPk1dce 1jHpqJ85i9hczCQ3EcSbPnHlyvAmgWN+RVgWIVglSfb8YM73fRxdDEuoM3TgWCn+/bpm 26Aw== 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=oVyvNGULGulgdR7oslYUMz3NcAvyS5HBRlENdd6QKHA=; b=KvMwXnBavFvmZxs9s3dxNfYM3/BhePEj9EChS2y8WuSeLx4ws5SyEZb/pb1vTJIbAG Fc4m15mzuWs5T2uGrBqYB6Jw26WqdS5Naa/nnF6aa5zVAJhYkf/GQsRGhUOCTwq6L3NK CJeyjipROyeud2VzxzLZrupnbxTPliMYWqKFQz6ZP+sCVlhqvKYZYqkTGem5A6I3RCJ/ UIwbmi1bLDloJsVVuS5JYMHYQ7+6KYwQ9Dk/xNenOWN0cVC50Ja4u0ClzF+hlJ37uOIp WQJ7hk2FGJVPSXnPFqR8kfmgxYZmESUH/XBZ7IQS9f76PzBWa66rwQlONWbNzejrUN/T uOpA== X-Gm-Message-State: AOAM533U8CBvR10dArD901/XXW7Dbdw2IgXeFmk0JyLd1Ype0rtiWtZe M+aboMqgj3V1l7qoQ3yN5CMWtxKOlGM= X-Google-Smtp-Source: ABdhPJxWTkIQx1mYCqMBawVXxXOU5KpniSF8v7BEB7SDfFee9ZacWf4AXFGKg/Qq89IpmDqCaDY1OA== X-Received: by 2002:a17:90a:f187:: with SMTP id bv7mr16502651pjb.198.1603089691680; Sun, 18 Oct 2020 23:41:31 -0700 (PDT) Received: from localhost.localdomain ([122.179.121.224]) by smtp.gmail.com with ESMTPSA id w74sm11164189pff.200.2020.10.18.23.41.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Oct 2020 23:41:31 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, Christoph Hellwig Subject: [PATCH V7 07/14] xfs: Check for extent overflow when moving extent from cow to data fork Date: Mon, 19 Oct 2020 12:10:41 +0530 Message-Id: <20201019064048.6591-8-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201019064048.6591-1-chandanrlinux@gmail.com> References: <20201019064048.6591-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 Signed-off-by: Chandan Babu R Reviewed-by: Allison Henderson --- 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 afb647e1e3fa..b99e67e7b59b 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -78,6 +78,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 16098dc42add..4f0198f636ad 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 Oct 19 06:40:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11843643 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C0A8D14B7 for ; Mon, 19 Oct 2020 06:41:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9AA1F22263 for ; Mon, 19 Oct 2020 06:41:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jp0Lyyf6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727080AbgJSGlf (ORCPT ); Mon, 19 Oct 2020 02:41:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726840AbgJSGlf (ORCPT ); Mon, 19 Oct 2020 02:41:35 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03EB9C061755 for ; Sun, 18 Oct 2020 23:41:35 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id p21so4798540pju.0 for ; Sun, 18 Oct 2020 23:41:34 -0700 (PDT) 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=Nem5Zsp3TqF1iyC0/EMN7RtDNtSJXMIPs5v8QAhDvpg=; b=jp0Lyyf6MdtAiOyo8DeO4rnoPOMwvYRDjQPWe5+2mEGTqwrtBRDbRXOF1eeiWEp+D7 yi4N557l3D1D+Uvk0H1paou7Rc7TAnY8nja2yoVUabu9rfICFIDWByACcZC0LRmZysE0 Ma8QlyvQdlRnZB+EV4zjhCWTvIhV4/ryDt65rMydfSyszr+NO5Hlw9fRx7UmeCTjaOL7 l9NsX3OmHfZO/aYmMfDUDjWVroNtwswyWBWuD3JDoum4Td/5jge/v/A9vRk8f/cYBDZN bqnvTGUo16VWwcEVVkxJ4Wsn7qvJKn3JTh4e/f3oIQCxqux2isTahzW9EiEhQMBhk4g/ l4Nw== 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=Nem5Zsp3TqF1iyC0/EMN7RtDNtSJXMIPs5v8QAhDvpg=; b=eZTm0FZhioq8eQThb5ksHZhXvA0ENP5No1ydI9k3Z7fEPS63/zNrPluJDHQMC5aiJx XJbtMtAoyH0VhEMphldzM6Xi2IKazp7/YU3fcdf6X334znUzgb0vDk33vB6yqu/UPsW2 P5KM1iWBhd5FOv53GVIPqZB39lCJBkrFpXABkyIEDgVUs2KE2jj5XvECRVgUD9f0/fiG ebsPzujEe8I8jZF52tAXTk4Ofcki8eNaqP/ufKPSFdPKvhQYE+79IuvSFnsY3mewaa7q Huuzp7pSkEVmD6iiBany+DaTvzu3KbpOGNKk/s1iqz9AaUq6rFTDwxA2Rb+ede+VQZy2 LXdg== X-Gm-Message-State: AOAM530Pr7wU0x7LW9rJKoz5PlC+eba13F50olL9/DoQ1/goZDzrBNf7 MECu59P8kYXS0CB/b7wdbDizNnTdsVA= X-Google-Smtp-Source: ABdhPJyrq5v+vwzrndgy65SOoUEYECr2bvHWwrcN1aGJ1zEpv9TbLCKAy7hifAPgCqP2Qoggmsqpeg== X-Received: by 2002:a17:90a:f698:: with SMTP id cl24mr15733723pjb.59.1603089694370; Sun, 18 Oct 2020 23:41:34 -0700 (PDT) Received: from localhost.localdomain ([122.179.121.224]) by smtp.gmail.com with ESMTPSA id w74sm11164189pff.200.2020.10.18.23.41.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Oct 2020 23:41:33 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org Subject: [PATCH V7 08/14] xfs: Check for extent overflow when remapping an extent Date: Mon, 19 Oct 2020 12:10:42 +0530 Message-Id: <20201019064048.6591-9-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201019064048.6591-1-chandanrlinux@gmail.com> References: <20201019064048.6591-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. Signed-off-by: Chandan Babu R Reviewed-by: Allison Henderson Reviewed-by: Darrick J. Wong --- 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 4f0198f636ad..856fe755a5e9 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 Oct 19 06:40:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11843645 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ECEB061C for ; Mon, 19 Oct 2020 06:41:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CB74F22263 for ; Mon, 19 Oct 2020 06:41:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NYxvHDdy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727081AbgJSGlj (ORCPT ); Mon, 19 Oct 2020 02:41:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726840AbgJSGlj (ORCPT ); Mon, 19 Oct 2020 02:41:39 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB8ACC061755 for ; Sun, 18 Oct 2020 23:41:37 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id t4so1859837plq.13 for ; Sun, 18 Oct 2020 23:41:37 -0700 (PDT) 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=afcVxSMdw5ij0Fda1eIlXjC2ynyXV9Z8I6bZTS5RiBw=; b=NYxvHDdyG6kWuQ0a/p4HPbhNnzGJBrL2XFRVHNNVE8vbJBIqpRrMl60VF/ThBNLZvN UdjM8LU/Pos7lb9JiS0Jp+DoJJtIuTA8ksOm1TtTsi8XVMbqcpjk6lG2r6fsh7SaTx/D 3j8OB8Z+ZlUM37Izw1LGD2gbcMp9YmGmBA6g8lt0DQ9rHVDbsza3dbXoIaz1NMmdqHa6 07YfqEjwotF4mK/xM5vvdXFnpTKbsbL1j+nPIf5GUXlt16Hbhj0lulXllDCYdg7x/ze2 x0VqN7aCWurr5bQJKi2txrdW8tgKJdpQleWGlVD3F+I7yjH28FkBqUycWjE9b9w3lQAi cbtg== 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=afcVxSMdw5ij0Fda1eIlXjC2ynyXV9Z8I6bZTS5RiBw=; b=rmd4v6ioepOThcc3PRHrIPzGVqF2ZBgcIF79vNcjf1sIU2tSB6xPJXtfvlRxc95NsH QRN5hkrdmEhQavS3R89dOsoDhqZ+A9AOCHWj5PnoG/OE2Lk7Zi6Dx/sJVhV7m63+OzfF ZdHpeYOeiNoKH0JHMiCZ0o6h1AACYzgQevrwdjmZMgEoYlWCND59wr024zq1KN3OoH1K pFS4HYVuq1hAZOv6XjD2EfGH6Yp8D9Xbj2CiTbRgU6mIVL43rocYMdZxSWTq9jacVstO W7sM3bodApLLXrOw7yLgsKB1yjoaPGryDYwEQ3Bm+mgFFgQcvDZpTjl3is/r1vanENBB 9lRQ== X-Gm-Message-State: AOAM531VmsEihPwF+yW2Ci020QtDXoHo1Gl39pVlCt/CkLtjBuOggi1A ElPKpI0qE0MGQEhjf8IDuhXPHSAV6eM= X-Google-Smtp-Source: ABdhPJwAhhnebIlKzUWISq4Vq+c+BGBOnOzvY7E4RseW0JNezJT9DNZGPU0i2cLu7u9Pwk4+XPlHuA== X-Received: by 2002:a17:902:7c02:b029:d4:bf4e:4fc6 with SMTP id x2-20020a1709027c02b02900d4bf4e4fc6mr15183763pll.75.1603089697161; Sun, 18 Oct 2020 23:41:37 -0700 (PDT) Received: from localhost.localdomain ([122.179.121.224]) by smtp.gmail.com with ESMTPSA id w74sm11164189pff.200.2020.10.18.23.41.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Oct 2020 23:41:36 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org Subject: [PATCH V7 09/14] xfs: Check for extent overflow when swapping extents Date: Mon, 19 Oct 2020 12:10:43 +0530 Message-Id: <20201019064048.6591-10-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201019064048.6591-1-chandanrlinux@gmail.com> References: <20201019064048.6591-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 Signed-off-by: Chandan Babu R Reviewed-by: Allison Henderson --- 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 b99e67e7b59b..969b06160d44 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -87,6 +87,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 0776abd0103c..b6728fdf50ae 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -1407,6 +1407,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 Oct 19 06:40:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11843647 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E10CC61C for ; Mon, 19 Oct 2020 06:41:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BF5D822263 for ; Mon, 19 Oct 2020 06:41:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="q0vBTl+v" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727082AbgJSGll (ORCPT ); Mon, 19 Oct 2020 02:41:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726840AbgJSGll (ORCPT ); Mon, 19 Oct 2020 02:41:41 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A031C061755 for ; Sun, 18 Oct 2020 23:41:41 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id d23so4483553pll.7 for ; Sun, 18 Oct 2020 23:41:41 -0700 (PDT) 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=54hvVruCep9acEanme5+7TKVjKYTNPLwPjk5IJSQZBU=; b=q0vBTl+vkVsKp9MTgMn42QQ6tAy8VqkzjphBfa/9RS8ngV5skJLF0VixfiCTooJo4/ fzLqVjerMVpe+2XVY3i57aG1HhjfAFvcuH4cfvkVHOpzNmp2rFuxKVrbsLSPc+binqSK ZRLKWBrSdEvLGxxgydvzqQbem7FPtf1m0fvs6W8F4kUtgx79tDuPvYov8tTBKxgoPmc+ mHmbHUGtPA6timY//7TOTTo7ffm981u/elmhgkLtZl9ewXkaLQC4VPaiHkyYs8nkUgrt C4yMkBQCnc4UBwn9T+2XaJGLZSOveYHXKGGpVKww1oSLH4jMT30hFwq+MJ8KDj1JiOT+ U1wg== 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=54hvVruCep9acEanme5+7TKVjKYTNPLwPjk5IJSQZBU=; b=SshHDx81Ku59DlFH4YJNrTHG3CGAYev5atMRNqoV2P39s6Kb7z2rfdRHtqJ8pkAEPM G7F1cHk92RfEvcT7PLI/DXs4piY28IAYY9rBQXAsmyPtNel8bVX1jUYP5woJUs4R1W9t Zg9kQtcegFjZi0BcbB7L/D+FFPmkv162NLTUc0XOhile18I4pWwztj0XA9kSM07l4WdO 5dnmHcNdOFOvGqXxe6jI5g3nl2MedQbJRJ7zkuBpMdsxHxFUWE0ibmPYVdrhC7E/2OWh 8QTC/beqY7izUa1BOQX0DHZ8yu39pJufldp2p9jofNSa2ItwaiV39CIlHQimHx2KAxVw c69g== X-Gm-Message-State: AOAM532Fy72P/uPEScuVr0T/PQ1VRai2fn16pZAAxKrft+rzWqEb7pU0 CF2w1il686WFV4h67vPO/I40qJ100tc= X-Google-Smtp-Source: ABdhPJw1FiaWWD2J6TXLh7o6ljhu6GlzY0Add9viL8Yjs6fsZyioZ4KS107xNI8HpTL8uiYvDpq8vA== X-Received: by 2002:a17:902:ee52:b029:d5:dd2d:df92 with SMTP id 18-20020a170902ee52b02900d5dd2ddf92mr6231597plo.37.1603089700326; Sun, 18 Oct 2020 23:41:40 -0700 (PDT) Received: from localhost.localdomain ([122.179.121.224]) by smtp.gmail.com with ESMTPSA id w74sm11164189pff.200.2020.10.18.23.41.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Oct 2020 23:41:39 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, Christoph Hellwig Subject: [PATCH V7 10/14] xfs: Introduce error injection to reduce maximum inode fork extent count Date: Mon, 19 Oct 2020 12:10:44 +0530 Message-Id: <20201019064048.6591-11-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201019064048.6591-1-chandanrlinux@gmail.com> References: <20201019064048.6591-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 Signed-off-by: Chandan Babu R Reviewed-by: Allison Henderson --- 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 Oct 19 06:40:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11843649 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E796314B7 for ; Mon, 19 Oct 2020 06:41:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C63D622260 for ; Mon, 19 Oct 2020 06:41:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aXtUcafa" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727084AbgJSGlp (ORCPT ); Mon, 19 Oct 2020 02:41:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726840AbgJSGlp (ORCPT ); Mon, 19 Oct 2020 02:41:45 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4948C061755 for ; Sun, 18 Oct 2020 23:41:43 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id lw2so432789pjb.3 for ; Sun, 18 Oct 2020 23:41:43 -0700 (PDT) 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=jj+OmV4bSzlVtHqGoh4lq0/qRQzdRIuP8pXxg0hXABo=; b=aXtUcafasqHKRx5KL8VFfZZiV7uiSqRmPU6DF3g751G7G6z/pvO+xgvwlshVIT8xMg 891t6tPDJ7qvahfAV1qJDGEY2I5gYlP+cqQQZFSPoNpAL1LEreyVFSgLLaKFINV+FQYQ r3wpPC4KesH4J9jAKe4pDj90UDGxgA5vZtzzYgJ6etfd1Xj7GNzhOfaI7FcEOS5f8bVa /7M88UB7VCBL0g4nPSbnu4tvSr5YeurQaZFvtpOYQ5072ndctKxpIJYrBjgZoO47QDM1 hMfuIbAfS5uuT9zd5DQWtSmIlc/Q9pfXsMjb/63zFJ8EZgs/VD5crD2T3ojVAE48jtvI q2eg== 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=jj+OmV4bSzlVtHqGoh4lq0/qRQzdRIuP8pXxg0hXABo=; b=pDpCNYLyvDpStr6/SYQZ9vg8ZaMFPakpzw3Vz21N8pYhA0Xrq5BGKU8hvM68z+POzJ DRm1xaTp7jrQdU9F04UjI7/9FP4f3B5byRfPkx06R5+zZNfVsgcpTJNQbez08UUKUxHf Pt+VkhIGQ5zUxasFVS/Yl55DQTKZqVix2rfjgZ4VW38n0DHe7GD+fjAiKQdv0/E7yZ5O 8AuA2FZoqKcp+HNbeZ/jeVtR6Jqq6SKx9WxMUJpu+Qxipphtz1vbdoOOCd+3iuGbqgYw fXxkYSB2HkMek+IL2uwf7prXhu9lLdKPY9J8zmHyXMsPD6QDiPAFSBfbn8LBVgj8ii/b GcVQ== X-Gm-Message-State: AOAM532D5w+o8q3jrwfieB4kUcYNuOQ3fuWHnXwCSCHEnM0ytZYgp6Yt rcxJiby9P9DrMIQBgPNMX6ILJoxBaYE= X-Google-Smtp-Source: ABdhPJyVdYiF1pq5T08ifv5T+PvV5X+WQj2m5zLfmMHFydgISfTfPbjVi99uBx34JQaoxrVAntVqbQ== X-Received: by 2002:a17:90b:4a10:: with SMTP id kk16mr16499561pjb.77.1603089703138; Sun, 18 Oct 2020 23:41:43 -0700 (PDT) Received: from localhost.localdomain ([122.179.121.224]) by smtp.gmail.com with ESMTPSA id w74sm11164189pff.200.2020.10.18.23.41.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Oct 2020 23:41:42 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org Subject: [PATCH V7 11/14] xfs: Remove duplicate assert statement in xfs_bmap_btalloc() Date: Mon, 19 Oct 2020 12:10:45 +0530 Message-Id: <20201019064048.6591-12-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201019064048.6591-1-chandanrlinux@gmail.com> References: <20201019064048.6591-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. Signed-off-by: Chandan Babu R Reviewed-by: Allison Henderson Reviewed-by: Darrick J. Wong --- 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 505358839d2f..64c4d0e384a5 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 Oct 19 06:40:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11843651 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CF65861C for ; Mon, 19 Oct 2020 06:41:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B52E222263 for ; Mon, 19 Oct 2020 06:41:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iXXfPbAe" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727090AbgJSGlr (ORCPT ); Mon, 19 Oct 2020 02:41:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726840AbgJSGlr (ORCPT ); Mon, 19 Oct 2020 02:41:47 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26655C061755 for ; Sun, 18 Oct 2020 23:41:47 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id b26so5427793pff.3 for ; Sun, 18 Oct 2020 23:41:47 -0700 (PDT) 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=wcibcHg+fGfIy+ERBhxnRgw5AuJuCxxwyu5T4vfwYrc=; b=iXXfPbAeoaski9cd9IBS/AgSsAxMfqIYIcdD6yHK4hmkz8N0OukKTJ+clBwhKmMit5 m4x97MQaRmphHpvZRo4X6lxoEo7qZ7bt+bjA5MPlqT8kLPgZqfHG5OWmykqL5WS7GXkX /Uki2M3LIoRW4AdcxNjkVvIltl9pl5aAKzVQNoi1jpjA7r3lfvK+IUCBM9C1Ewihnq/E a92tLq9HyI02dGkGDmPidQ6Qpwu/iY+6+FIpIx/pH2/gr2uL11UgbszKef8VgPcRa0DH h1TVlU1QEeodZysbu+OAmQEIupgCEUybEPCpsQLnev/8x3YA6XhHyFUfyTPzXkpZKRzd 7GVQ== 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=wcibcHg+fGfIy+ERBhxnRgw5AuJuCxxwyu5T4vfwYrc=; b=pX6+0upZZzFd8jlUPYXh0GAm23dv/dywFqL0ymnTjI52CH24NvfgJPp5E28QR43ur2 bYn7b0sbucu7wROBkBvE48w5NqrBBR02wzMGY/JsFkXOoHfMGaXbGkCl8Hm5Tz82mPnn zPRYyzIDb96UkpUkW5jqIC4TUA39u9BpusgmDXoiD8BSodz1oAZEaS729G5on79D4Ic0 v78lDSx1ijdtmPEk6i0ZR64hTifO/t7nlsj1MnBnSRgWwIeITJ/f0k+wDbFAlG9s/vv+ BVrijhzEzgg0w1I3x421zr4Usf+Id43OdDKDBCpkN/tnRIbbwQ4ibGUJtw78/n19NC0M zULA== X-Gm-Message-State: AOAM5313nZlMNvyAteggL/0tRzRv4zaaycmDmf/c6sPhSTDU1bITjZ09 xVE+2TP5x2NqNJwYW/3Iyw78xxRsV18= X-Google-Smtp-Source: ABdhPJyaiHPxUPSC+qzMQhdG2DZATTCBh6ChJFwoXqYXEFqRmGsMDvZ/9V9QGmHGv2Yt1bSYjlNZRQ== X-Received: by 2002:aa7:8492:0:b029:155:79b1:437a with SMTP id u18-20020aa784920000b029015579b1437amr15435919pfn.26.1603089706250; Sun, 18 Oct 2020 23:41:46 -0700 (PDT) Received: from localhost.localdomain ([122.179.121.224]) by smtp.gmail.com with ESMTPSA id w74sm11164189pff.200.2020.10.18.23.41.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Oct 2020 23:41:45 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org Subject: [PATCH V7 12/14] xfs: Compute bmap extent alignments in a separate function Date: Mon, 19 Oct 2020 12:10:46 +0530 Message-Id: <20201019064048.6591-13-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201019064048.6591-1-chandanrlinux@gmail.com> References: <20201019064048.6591-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. Signed-off-by: Chandan Babu R Reviewed-by: Allison Henderson --- fs/xfs/libxfs/xfs_bmap.c | 88 +++++++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 37 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 64c4d0e384a5..935f2d506748 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -3463,13 +3463,58 @@ xfs_bmap_btalloc_accounting( args->len); } +static void +xfs_bmap_compute_alignments( + struct xfs_bmalloca *ap, + struct xfs_alloc_arg *args, + int *stripe_align) +{ + struct xfs_mount *mp = args->mp; + xfs_extlen_t align = 0; /* minimum allocation alignment */ + int error; + + /* 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); + } + + /* 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; + } +} + 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 +3534,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; + xfs_bmap_compute_alignments(ap, &args, &stripe_align); nullfb = ap->tp->t_firstblock == NULLFSBLOCK; fb_agno = nullfb ? NULLAGNUMBER : XFS_FSB_TO_AGNO(mp, @@ -3538,9 +3569,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 +3599,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 Oct 19 06:40:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11843653 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 99CF114B7 for ; Mon, 19 Oct 2020 06:41:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 77BEA22263 for ; Mon, 19 Oct 2020 06:41:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HB0l6rmi" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727091AbgJSGlu (ORCPT ); Mon, 19 Oct 2020 02:41:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726840AbgJSGlt (ORCPT ); Mon, 19 Oct 2020 02:41:49 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0404C061755 for ; Sun, 18 Oct 2020 23:41:49 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id j18so5435223pfa.0 for ; Sun, 18 Oct 2020 23:41:49 -0700 (PDT) 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=Cuw0qYx7vbqAMkfQlHFN5TQrXT6eetenRUTrLL8eCR8=; b=HB0l6rmi7dZV5m8pb/sPXIPzeJaTxuAJzRI9KtaIhur6OTN+jWaoXF8WY7Cl3VBDqO lonmyD4vnUvdz98ZDVEb/1mCSDFSzBA39W0OjuUyz/RNC/t2HiueM+AunKBvrEOcnVrU QOV/d/TPm+ZcnRgAggDyLR8O9oU9jo4LYEAU5YtsDrY8WjErAIFqbxMZIY5pC5WdheeE W6Mf7H41OeJ9emhVj5tcn3QxVMfe7JNzZZHZ0Cbe3R+UoDSSmIwi4mJJYqj+vfiwf5xT DfREqrimAp7qeOoYulxaJUwiShPRKchIuGVS/0wZEgsxT1fMfeJF6nBkyrnjn9mHMlju H66g== 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=Cuw0qYx7vbqAMkfQlHFN5TQrXT6eetenRUTrLL8eCR8=; b=SgxrFfRmVMIAlRbo+Mr+X4+iv45heeRTtkf3nZnuboOzJ8qcMehYn5F5H5JLlUOtfQ alXJdZRyPsJ3Jpv21bBKL3SfkK+JNRCZxsqXnZEltg13y5p7WvYCGH+tf37B1aTNlw7a lv/ZkA5x9DYd0IXW6lFyy0K3nBmhSrwCDH2OTCG72pq9NrjmlYMk1YijfrAGIz0a/Xnt EkCDZ5iOmvRgzJx8G/4FytwfcSvUPxjTJPwWZYHHcX14Kms3Yzi/rQ0ZnLrapjp/VQh0 /00ES6lkEYyClg6Nnf1n6Y2sQ8QZi3cGFLOhfjnY6eANw54G73e+o9tx28DLzdchwceg 5TtA== X-Gm-Message-State: AOAM5339y0Gjf9FH7+O5PxhZi7YNgfUItad5Q+Qp17EThwDhMUL0Z5q3 GaftHGQVoD6RJzKN1Yd9WezQUQTqzlY= X-Google-Smtp-Source: ABdhPJyBz0n8ArDMOP/EJ1qw5YYNUvtCovvSzQm5/I4hZYNwnxHsxXUHx7Nxqa59y0cCLZe+BBU9vA== X-Received: by 2002:a62:c181:0:b029:152:6ba8:a011 with SMTP id i123-20020a62c1810000b02901526ba8a011mr14903006pfg.2.1603089709096; Sun, 18 Oct 2020 23:41:49 -0700 (PDT) Received: from localhost.localdomain ([122.179.121.224]) by smtp.gmail.com with ESMTPSA id w74sm11164189pff.200.2020.10.18.23.41.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Oct 2020 23:41:48 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org Subject: [PATCH V7 13/14] xfs: Process allocated extent in a separate function Date: Mon, 19 Oct 2020 12:10:47 +0530 Message-Id: <20201019064048.6591-14-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201019064048.6591-1-chandanrlinux@gmail.com> References: <20201019064048.6591-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. Signed-off-by: Chandan Babu R Reviewed-by: Allison Henderson --- 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 935f2d506748..88db23afc51c 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -3509,6 +3509,48 @@ xfs_bmap_compute_alignments( } } +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 */ @@ -3701,36 +3743,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 Oct 19 06:40:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11843655 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A184614B7 for ; Mon, 19 Oct 2020 06:41:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7AF2122260 for ; Mon, 19 Oct 2020 06:41:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LV6js8ah" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727092AbgJSGlx (ORCPT ); Mon, 19 Oct 2020 02:41:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726840AbgJSGlw (ORCPT ); Mon, 19 Oct 2020 02:41:52 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3DE2C061755 for ; Sun, 18 Oct 2020 23:41:52 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id ds1so4785045pjb.5 for ; Sun, 18 Oct 2020 23:41:52 -0700 (PDT) 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=E78p6TA0dWbWvLEoELcP6UdISQJks0i1c8pFcd4+AQo=; b=LV6js8ahTpow01Y/4BgrUMq29PhN2oiQNjF4VIUcggU8qzlhxD1G0QDIi+KGYuVhCD lFhVfYuwc7p6URj9f5rvoMajYjsHwn2n7TIsnh3H8Yi8XSdjPGqQK/fDwdOqtOxv03M6 AAAQHs+2aZiXKcioFBLhdZiCtO7eORSFA0QD0Su7P+AJFSxlTGOhCgSsqzVmYePPfp5H RaeS0QM9z14k6+rda95sqZvSNLIp+5bfdVXK2meKM0dSJyWwiKv9Hb2RvKiEnyluykFS ExJ4wNzdIb2bGfOiedoxA17mrr8XSCDyTb/Hx/lyKDheMI13iAKTmlPEGpPI0vSRjDWt Ksuw== 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=E78p6TA0dWbWvLEoELcP6UdISQJks0i1c8pFcd4+AQo=; b=AoKT5Wz3sqgx3JA+dmWEMyg4L9kvU99RXvfjzTV4NoDuNcOhQPOdahSCJ2qWMfcFgn 4Maz+1v4ozhUVgb+inlXR6lVXY4UIr2k9vyI2QL99sSPFR/0gvUJmK5pUSuLzuaUT6tg tu04S9KSinAo9k0or269F686X9kkiiDSgQJHyUyRfhfC49j50Ef58fiNfibgu4ZTgUM8 Zd8plbYiJDkCk2kq0lfCQOBS0oebzPIonaRngICJNX8Me+DFOzuz+3kGZ7DcNYBODPN0 bXiAz7sXcSNYDBO+aUkGT29BqgBAW55bwHfb4K/d/Tol5jXEG2BRoxJJ6OBUnBGzl2G0 EvWQ== X-Gm-Message-State: AOAM533KUO8ci5vQ956W92mUK31msVbsmbK7nav0RjmuNsL/CuHvWi4H z9M9GDN9yZo8926D1Krj3kuC01kpUSw= X-Google-Smtp-Source: ABdhPJzNk68wdhkHEQPTiDf/Y0nQxuM2C9HIK2VbWFLUkpSluhF6QVz1CjhCB1Qjp+36FE11Hdx8JA== X-Received: by 2002:a17:90a:77c9:: with SMTP id e9mr15656479pjs.24.1603089712016; Sun, 18 Oct 2020 23:41:52 -0700 (PDT) Received: from localhost.localdomain ([122.179.121.224]) by smtp.gmail.com with ESMTPSA id w74sm11164189pff.200.2020.10.18.23.41.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Oct 2020 23:41:51 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org Subject: [PATCH V7 14/14] xfs: Introduce error injection to allocate only minlen size extents for files Date: Mon, 19 Oct 2020 12:10:48 +0530 Message-Id: <20201019064048.6591-15-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201019064048.6591-1-chandanrlinux@gmail.com> References: <20201019064048.6591-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. Signed-off-by: Chandan Babu R Reviewed-by: Allison Henderson --- fs/xfs/libxfs/xfs_alloc.c | 50 ++++++++++++++++++ fs/xfs/libxfs/xfs_alloc.h | 3 ++ fs/xfs/libxfs/xfs_bmap.c | 100 +++++++++++++++++++++++++++++++---- fs/xfs/libxfs/xfs_errortag.h | 4 +- fs/xfs/xfs_error.c | 3 ++ 5 files changed, 150 insertions(+), 10 deletions(-) diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c index 852b536551b5..8e132f8b9cc4 100644 --- a/fs/xfs/libxfs/xfs_alloc.c +++ b/fs/xfs/libxfs/xfs_alloc.c @@ -2473,6 +2473,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. @@ -2544,6 +2585,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 i; + + error = xfs_exact_minlen_extent_available(args, agbp, &i); + if (error || !i) + 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 88db23afc51c..74e148cc41b2 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -3474,11 +3474,13 @@ xfs_bmap_compute_alignments( int error; /* 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 (stripe_align) { + *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); @@ -3551,6 +3553,71 @@ xfs_bmap_process_allocated_extent( xfs_bmap_btalloc_accounting(ap, args); } +#ifdef DEBUG +static int +xfs_bmap_exact_minlen_extent_alloc( + struct xfs_bmalloca *ap) +{ + struct xfs_alloc_arg args; + struct xfs_mount *mp = ap->ip->i_mount; + xfs_fileoff_t orig_offset; + xfs_extlen_t orig_length; + int error; + + ASSERT(ap->length); + orig_offset = ap->offset; + orig_length = ap->length; + + memset(&args, 0, sizeof(args)); + args.alloc_minlen_only = 1; + args.tp = ap->tp; + args.mp = mp; + + xfs_bmap_compute_alignments(ap, &args, NULL); + + 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; +} +#endif + STATIC int xfs_bmap_btalloc( struct xfs_bmalloca *ap) /* bmap alloc argument struct */ @@ -4112,7 +4179,13 @@ xfs_bmap_alloc_userdata( return xfs_bmap_rtalloc(bma); } - return xfs_bmap_btalloc(bma); +#ifdef DEBUG + if (unlikely(XFS_TEST_ERROR(false, mp, + XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT))) + return xfs_bmap_exact_minlen_extent_alloc(bma); + else +#endif + return xfs_bmap_btalloc(bma); } static int @@ -4148,10 +4221,19 @@ 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) { +#ifdef DEBUG + if (unlikely(XFS_TEST_ERROR(false, mp, + XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT))) + error = xfs_bmap_exact_minlen_extent_alloc(bma); + else +#endif + 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, };