From patchwork Tue Nov 17 13:44:03 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: 11912227 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 421221668 for ; Tue, 17 Nov 2020 13:45:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1860520729 for ; Tue, 17 Nov 2020 13:45:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ol2YuILF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733188AbgKQNow (ORCPT ); Tue, 17 Nov 2020 08:44:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733185AbgKQNov (ORCPT ); Tue, 17 Nov 2020 08:44:51 -0500 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5337C0617A6 for ; Tue, 17 Nov 2020 05:44:51 -0800 (PST) Received: by mail-pg1-x544.google.com with SMTP id 81so7717493pgf.0 for ; Tue, 17 Nov 2020 05:44:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XmdKpghfLeanbz+IwL0BYKqdxi1X0QN/uaPdOmARGkM=; b=ol2YuILF0ncOBz3+Zamh0fkdCq2//KkMrEdD+PHM5Yo5I0MfyTxvZPB/ime1DTj7vq HbgCndbVU3CKxHTYCCF2Zs/m9NBtForwPNwd1/fZ9XXD6Xob1LkqMJkm1pe79iRMkE/t v2KzbsL8IulZua7naW9Au3vcX+dB9Rywg5kIokEHxk7FoK71w/jnunup+a4GOsRraOgt UjJIUDo9/CphZciO26qQmgqfAJZfsijVmpm21xb3AUTYmh53ksqjLdiUXKvrSRGKeG56 f4Mn66ejIAtH3HytYedN/hJcaaeDzjSB6QckRYULpYaBdgP4+zhk3ow+PiPvmME8IhF+ 39JQ== 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=XmdKpghfLeanbz+IwL0BYKqdxi1X0QN/uaPdOmARGkM=; b=hArtQgECtMgiCkmr5/bYvwiLhuMgxcvxepWwLtySPMpkSYxS56pktemrSHxT23ti5m V3y2uRQg4qBlrNQ+Br9oSRRDe0ztELy4Da7NOv8xuPJVVv6IXpxiQHKTcAxScVJNJfFg QdIIHwgUcZTHGB8++9dj63IZq2QBeaKdIr78zOLGQVf53ATWs9i7vUyAApZoNUHutNF/ nVIEr0SSy+Ks+w6L28nOzB5z73p1upkNenKfuv4C7BkuA9pt8xqWh8s9OYGEXx2mMYZt a6z88RV2nhxtTEgIXWnb3kGSlLaPHcX+dBXdY0HrTzNvtJD3/GtTw3bvVokKYA2wccRp l7NQ== X-Gm-Message-State: AOAM533rYFnsUl57wzMpZqjOG3fYqp0fquHHkRVT/8TDGT8buLeE8C05 74ODio1ftt/eUoPTOzHocfrwY6iGMAk= X-Google-Smtp-Source: ABdhPJzv+aovbgg7GLS4z15ytL3kZMLp1U8elvj15ETlJniuHSopxBGqQWrSr3y6HEGLO9bY2Llk+g== X-Received: by 2002:a63:f84d:: with SMTP id v13mr3550851pgj.234.1605620691039; Tue, 17 Nov 2020 05:44:51 -0800 (PST) Received: from localhost.localdomain ([122.179.49.210]) by smtp.gmail.com with ESMTPSA id y3sm3669399pjb.18.2020.11.17.05.44.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2020 05:44:50 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, Allison Henderson , Christoph Hellwig Subject: [PATCH V11 01/14] xfs: Add helper for checking per-inode extent count overflow Date: Tue, 17 Nov 2020 19:14:03 +0530 Message-Id: <20201117134416.207945-2-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201117134416.207945-1-chandanrlinux@gmail.com> References: <20201117134416.207945-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org XFS does not check for possible overflow of per-inode extent counter fields when adding extents to either data or attr fork. For e.g. 1. Insert 5 million xattrs (each having a value size of 255 bytes) and then delete 50% of them in an alternating manner. 2. On a 4k block sized XFS filesystem instance, the above causes 98511 extents to be created in the attr fork of the inode. xfsaild/loop0 2008 [003] 1475.127209: probe:xfs_inode_to_disk: (ffffffffa43fb6b0) if_nextents=98511 i_ino=131 3. The incore inode fork extent counter is a signed 32-bit quantity. However the on-disk extent counter is an unsigned 16-bit quantity and hence cannot hold 98511 extents. 4. The following incorrect value is stored in the attr extent counter, # xfs_db -f -c 'inode 131' -c 'print core.naextents' /dev/loop0 core.naextents = -32561 This commit adds a new helper function (i.e. xfs_iext_count_may_overflow()) to check for overflow of the per-inode data and xattr extent counters. Future patches will use this function to make sure that an FS operation won't cause the extent counter to overflow. Suggested-by: Darrick J. Wong Reviewed-by: Allison Henderson Reviewed-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_inode_fork.c | 23 +++++++++++++++++++++++ fs/xfs/libxfs/xfs_inode_fork.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c index 7575de5cecb1..8d48716547e5 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.c +++ b/fs/xfs/libxfs/xfs_inode_fork.c @@ -23,6 +23,7 @@ #include "xfs_da_btree.h" #include "xfs_dir2_priv.h" #include "xfs_attr_leaf.h" +#include "xfs_types.h" kmem_zone_t *xfs_ifork_zone; @@ -728,3 +729,25 @@ xfs_ifork_verify_local_attr( return 0; } + +int +xfs_iext_count_may_overflow( + struct xfs_inode *ip, + int whichfork, + int nr_to_add) +{ + struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork); + uint64_t max_exts; + uint64_t nr_exts; + + if (whichfork == XFS_COW_FORK) + return 0; + + max_exts = (whichfork == XFS_ATTR_FORK) ? MAXAEXTNUM : MAXEXTNUM; + + nr_exts = ifp->if_nextents + nr_to_add; + if (nr_exts < ifp->if_nextents || nr_exts > max_exts) + return -EFBIG; + + return 0; +} diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index a4953e95c4f3..0beb8e2a00be 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -172,5 +172,7 @@ extern void xfs_ifork_init_cow(struct xfs_inode *ip); int xfs_ifork_verify_local_data(struct xfs_inode *ip); int xfs_ifork_verify_local_attr(struct xfs_inode *ip); +int xfs_iext_count_may_overflow(struct xfs_inode *ip, int whichfork, + int nr_to_add); #endif /* __XFS_INODE_FORK_H__ */ From patchwork Tue Nov 17 13:44:04 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: 11912229 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 891AB1391 for ; Tue, 17 Nov 2020 13:45:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 615D620729 for ; Tue, 17 Nov 2020 13:45:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZkYL6Szl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733190AbgKQNo5 (ORCPT ); Tue, 17 Nov 2020 08:44:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732520AbgKQNo4 (ORCPT ); Tue, 17 Nov 2020 08:44:56 -0500 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 8D8B1C0613CF for ; Tue, 17 Nov 2020 05:44:54 -0800 (PST) Received: by mail-pg1-x541.google.com with SMTP id p68so5647062pga.6 for ; Tue, 17 Nov 2020 05:44:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GhuaEjtbG0//r4IvHlnEcQuD/mUoLWUJcwfcoO/yi10=; b=ZkYL6SzluCFa34+fsCxLU9qV3ZdsInyek9Ls37VheDGo6+XhNp9J8uVa4v3pS2gxZ6 Q9tM3C0IWCHm3sfy6LiGgoKEcb9WEK0xulILZlpY2ufMx5H/pm1hNJWzznM0+L7P+yCy nuJvf1nfGY9Sjb7KZM3lHzDm+xV6/bwf+eSbTf9pIci0CSkaEe224rQ+QNVvdau7kAPN f1ybGNcZEP8lwtG1cnGh1NWTaUu5J+JPGQh7qQD/fhSulSSj77ykqXnTQbNxf+lhRLtk PhOQRrKhUuWRwqHD9zuEGLTx64capw3loQkn6aLUot+CxkxxdtQpNShdPqeX3NJ7opDj tbIQ== 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=GhuaEjtbG0//r4IvHlnEcQuD/mUoLWUJcwfcoO/yi10=; b=UERALRmFSvmOq4HFaayQPWcSrIByWq/WIpFwm2a8y6RHEyZ9U8RXqh6QA6N+JfDOG+ 2oH3GitGPbAiaICgMGk9UEnSMBOnLogrSod34m63NOzJdaQzcUYCcGaE+ocGtopG1QsH 3KYA9ObukAFYXurPIC1ZXFsgj/1tEMBLhQgSUclvCVexVpTLFB5pjxmUkisEt1oxugjO fgHq/U2usXTZHoI2GXx64PF8HjCcAIKrE+OzYEnBJzFqierRsYlK7E2jBkxelDf1f1gr QB+63JtpsPbeZOwtecVj+K4L7FdevUiWB76ME+0RPPQhdaSSBww/85ZuUzpD+z7bhxE9 N60g== X-Gm-Message-State: AOAM532zwAs5SPv/g3yppvDDBJlyvgEeHi5Xoh+I8gn0AnIGHc01cwtB +NaEWOBrC4pJA8VsnSWoHdiiw2QXYoY= X-Google-Smtp-Source: ABdhPJzFm+ofhJIRQka7sbRRqM6wfuSqKa6K2HwCZ7G1Pe9JTI9aeOLmfiAFhmP+Y9Xri0xqIynQEA== X-Received: by 2002:aa7:9f8b:0:b029:18b:9c0e:a617 with SMTP id z11-20020aa79f8b0000b029018b9c0ea617mr18011693pfr.16.1605620693775; Tue, 17 Nov 2020 05:44:53 -0800 (PST) Received: from localhost.localdomain ([122.179.49.210]) by smtp.gmail.com with ESMTPSA id y3sm3669399pjb.18.2020.11.17.05.44.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2020 05:44:53 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, Christoph Hellwig , Allison Henderson Subject: [PATCH V11 02/14] xfs: Check for extent overflow when trivally adding a new extent Date: Tue, 17 Nov 2020 19:14:04 +0530 Message-Id: <20201117134416.207945-3-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201117134416.207945-1-chandanrlinux@gmail.com> References: <20201117134416.207945-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org When adding a new data extent (without modifying an inode's existing extents) the extent count increases only by 1. This commit checks for extent count overflow in such cases. Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Allison Henderson Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_bmap.c | 6 ++++++ fs/xfs/libxfs/xfs_inode_fork.h | 6 ++++++ fs/xfs/xfs_bmap_item.c | 7 +++++++ fs/xfs/xfs_bmap_util.c | 5 +++++ fs/xfs/xfs_dquot.c | 8 +++++++- fs/xfs/xfs_iomap.c | 5 +++++ fs/xfs/xfs_rtalloc.c | 5 +++++ 7 files changed, 41 insertions(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 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 1c3969807fb9..45ef7fa69e1d 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 Tue Nov 17 13:44:05 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: 11912231 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 CCDB66C1 for ; Tue, 17 Nov 2020 13:45:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A0FE4206A5 for ; Tue, 17 Nov 2020 13:45:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LmORvJv+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733193AbgKQNo7 (ORCPT ); Tue, 17 Nov 2020 08:44:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732808AbgKQNo6 (ORCPT ); Tue, 17 Nov 2020 08:44:58 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFE62C0613CF for ; Tue, 17 Nov 2020 05:44:57 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id js21so469979pjb.0 for ; Tue, 17 Nov 2020 05:44:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ttah+KnBauDQXA8r3dO7gvzvR5vDgdkbnCETl2BO3+U=; b=LmORvJv+k8ZJ6vAoXK+MOBKS+C3zPwBYlcTjeW08UFvLThsX8Kohh7hbeANOcDP3Z4 K3ZiHa////1TjOTisWZn3KKqQSeBggzlNnPwopY1L3V985InhHKULGDRRAdZQoojlRrK 8aRaIgTWPweUh977wqTO7hnNq12lyiIHqvNYEkpyq5BR/1Nn/m2v1MxSL0qzOAkINrlF 6GSWqcXD17MXTwbYUAS6iKLSLF0AYluXXqw9pl9gJhHNa5ouWTlp5r0rwHOtBFREjUGi 7niQgUo2RR1MyVQFgLdZeo4Rho2MQkp6EW3dgGKnXc4g42jxuIuj2T9cqPLbT7EP8KVz h/yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ttah+KnBauDQXA8r3dO7gvzvR5vDgdkbnCETl2BO3+U=; b=GKDmXSGAzk5KP5OB8ZFbvfXTi/b5xSFqyDr/GEAxySMyRmhN1kvSPie/DLJuHiFG71 /5amgeHCb2gIKUNDWAUtsUsVIkRFVqA/68w0G0QHO7gpTk/HD8i2rlg3/TxaPbCltn+K YNyETo+Q05ksvAsLVodr5uziVqFqvl45YpFx8x201JmSFFABRbFuLNQAgEFXK/dmf3Cs iZ9+w6XA+umvQCms8E/hDXwmYdTnbl9//7VSpBjYVHlW8VhGC1L/PxC7M/wVpguHac2+ XguC2WX1fnbzv3TJRVkTszrN+MPZw/fJQoc2JISnUJ82ijJcaPEiJeLRTsifuDp6s9eB IcNw== X-Gm-Message-State: AOAM531Jhm63Bz3BoqLWFAoGR5EQTNvjv/mJt6WGg+FkDvWCnkLMY7iA ZYYNAmRJnOfCONXCdnoCbdQoWqiFpWk= X-Google-Smtp-Source: ABdhPJz63gsCOm7EgEpZx+EeNBVdS6t/1Ol9yrQWAgYqbMTbA6JMTHBYXXu+a9JtErUUirLKaw+cxA== X-Received: by 2002:a17:90b:94f:: with SMTP id dw15mr4687449pjb.125.1605620696543; Tue, 17 Nov 2020 05:44:56 -0800 (PST) Received: from localhost.localdomain ([122.179.49.210]) by smtp.gmail.com with ESMTPSA id y3sm3669399pjb.18.2020.11.17.05.44.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2020 05:44:55 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, Christoph Hellwig , Allison Henderson Subject: [PATCH V11 03/14] xfs: Check for extent overflow when punching a hole Date: Tue, 17 Nov 2020 19:14:05 +0530 Message-Id: <20201117134416.207945-4-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201117134416.207945-1-chandanrlinux@gmail.com> References: <20201117134416.207945-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org The extent mapping the file offset at which a hole has to be inserted will be split into two extents causing extent count to increase by 1. Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Allison Henderson Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_inode_fork.h | 7 +++++++ fs/xfs/xfs_bmap_item.c | 15 +++++++++------ fs/xfs/xfs_bmap_util.c | 10 ++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index 7fc2b129a2e7..bcac769a7df6 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -40,6 +40,13 @@ struct xfs_ifork { */ #define XFS_IEXT_ADD_NOSPLIT_CNT (1) +/* + * Punching out an extent from the middle of an existing extent can cause the + * extent count to increase by 1. + * i.e. | Old extent | Hole | Old extent | + */ +#define XFS_IEXT_PUNCH_HOLE_CNT (1) + /* * Fork handling. */ diff --git a/fs/xfs/xfs_bmap_item.c b/fs/xfs/xfs_bmap_item.c index 1610d6ad089b..80d828394158 100644 --- a/fs/xfs/xfs_bmap_item.c +++ b/fs/xfs/xfs_bmap_item.c @@ -439,6 +439,7 @@ xfs_bui_item_recover( xfs_exntst_t state; unsigned int bui_type; int whichfork; + int iext_delta; int error = 0; /* Only one mapping operation per BUI... */ @@ -497,12 +498,14 @@ xfs_bui_item_recover( xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, 0); - if (bui_type == XFS_BMAP_MAP) { - error = xfs_iext_count_may_overflow(ip, whichfork, - XFS_IEXT_ADD_NOSPLIT_CNT); - if (error) - goto err_cancel; - } + if (bui_type == XFS_BMAP_MAP) + iext_delta = XFS_IEXT_ADD_NOSPLIT_CNT; + else + iext_delta = XFS_IEXT_PUNCH_HOLE_CNT; + + error = xfs_iext_count_may_overflow(ip, whichfork, iext_delta); + if (error) + goto err_cancel; count = bmap->me_len; error = xfs_trans_log_finish_bmap_update(tp, budp, bui_type, ip, diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index dcd6e61df711..0776abd0103c 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -891,6 +891,11 @@ xfs_unmap_extent( xfs_trans_ijoin(tp, ip, 0); + error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + XFS_IEXT_PUNCH_HOLE_CNT); + if (error) + goto out_trans_cancel; + error = xfs_bunmapi(tp, ip, startoffset_fsb, len_fsb, 0, 2, done); if (error) goto out_trans_cancel; @@ -1176,6 +1181,11 @@ xfs_insert_file_space( xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, 0); + error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + XFS_IEXT_PUNCH_HOLE_CNT); + if (error) + goto out_trans_cancel; + /* * The extent shifting code works on extent granularity. So, if stop_fsb * is not the starting block of extent, we need to split the extent at From patchwork Tue Nov 17 13:44:06 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: 11912233 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 174DC1668 for ; Tue, 17 Nov 2020 13:45:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E57E9206A5 for ; Tue, 17 Nov 2020 13:45:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="m8mKvDsk" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733195AbgKQNpA (ORCPT ); Tue, 17 Nov 2020 08:45:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732808AbgKQNo7 (ORCPT ); Tue, 17 Nov 2020 08:44:59 -0500 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CADB3C0613CF for ; Tue, 17 Nov 2020 05:44:59 -0800 (PST) Received: by mail-pl1-x642.google.com with SMTP id k7so10256149plk.3 for ; Tue, 17 Nov 2020 05:44:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sW8VLSVzgzwY91vdEfqsNHlu7FJTr4mIT1Hq/R3vhyo=; b=m8mKvDskH58HEKPEC77r1PykYiVMZvUKJ7k1MDYAeLYlst/jMSGW3OVN74ZMuSUdlE 183MQzRDMzBopYwr/5Z9wCZcH0mL9knm183tkBQuHtwct1CuCNy58MvtAViBt/c2wYkp mN4lhm7e8yYXFzF0ecTEi+Ypy6po8pcIvT9/gL+8oCOn1tBodMoccEYDWGQ14LXZOMFn zaa0XgG8JAjxFVrz7UKge0utKgr5zLUjYC/n9KkszxJiuzeSde0qVOAf7dgh/qUSPDk0 fvKrlwXTmfzi5vBwCpF7fTAb0LzbXjyH43NIaBTyJQJXunDr7f7CNlbzvYGO8x2JySA6 j45A== 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=sW8VLSVzgzwY91vdEfqsNHlu7FJTr4mIT1Hq/R3vhyo=; b=pqasDImvHT4FGeKs/mXWu061+Gr5nPAXfQYShi3cVmJgZo/sZCvJteYUCTvFroKDAc ElfKXYiGV5zLTqTnEPmhPbAlXBIDGw2N0/aW9y+MrTTi/P/ne5FRDNpM4UPdzfR+GGWt LLsEix8DcCxtA1ctcJgBPIh3QeTjrsOu3ypCErzP1ae0GjmIXVtN/W9O7tXAE5HA9SbT CncOQrw70wtV6OPbM3PQFCAzS33Dh5Z0rnSHgqjxKQ/ldX4i7KXk7Ssbdgg9webQJ6bM GRzg9CVN7OHBJoRjAD7TRtyRiQI68gYDIPSH91NN24ZDJmB6L40iq79YurfA2pJhZcxr /ttA== X-Gm-Message-State: AOAM531u7wDhvQpFIkxVTLJqDMWMZOQn2HuXMEXcvSmKOh1R4wdJorpt p2EKCPE/CAm6lI+ucilPLLqGgcc7yRI= X-Google-Smtp-Source: ABdhPJwpHkXzaBBokMcashZA3uiOoWSWWwFO2XA3Otpzkb4iePqKwJlRzrAQ+nqlnmr/D6EzO65GGA== X-Received: by 2002:a17:90a:4816:: with SMTP id a22mr4840445pjh.228.1605620699058; Tue, 17 Nov 2020 05:44:59 -0800 (PST) Received: from localhost.localdomain ([122.179.49.210]) by smtp.gmail.com with ESMTPSA id y3sm3669399pjb.18.2020.11.17.05.44.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2020 05:44:58 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com Subject: [PATCH V11 04/14] xfs: Check for extent overflow when adding/removing xattrs Date: Tue, 17 Nov 2020 19:14:06 +0530 Message-Id: <20201117134416.207945-5-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201117134416.207945-1-chandanrlinux@gmail.com> References: <20201117134416.207945-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. To be able to always remove an existing xattr, when adding an xattr we make sure to reserve inode fork extent count required for removing max sized xattr in addition to that required by the xattr add operation. Signed-off-by: Chandan Babu R Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_attr.c | 20 ++++++++++++++++++++ fs/xfs/libxfs/xfs_inode_fork.h | 10 ++++++++++ 2 files changed, 30 insertions(+) diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c index fd8e6418a0d3..d53b3867b308 100644 --- a/fs/xfs/libxfs/xfs_attr.c +++ b/fs/xfs/libxfs/xfs_attr.c @@ -396,6 +396,8 @@ xfs_attr_set( struct xfs_trans_res tres; bool rsvd = (args->attr_filter & XFS_ATTR_ROOT); int error, local; + int iext_cnt; + int rmt_blks; unsigned int total; if (XFS_FORCED_SHUTDOWN(dp->i_mount)) @@ -416,6 +418,9 @@ xfs_attr_set( */ args->op_flags = XFS_DA_OP_OKNOENT; + rmt_blks = xfs_attr3_rmt_blocks(mp, XFS_XATTR_SIZE_MAX); + iext_cnt = XFS_IEXT_ATTR_MANIP_CNT(rmt_blks); + if (args->value) { XFS_STATS_INC(mp, xs_attr_set); @@ -442,6 +447,13 @@ 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 = 0; + else + rmt_blks = xfs_attr3_rmt_blocks(mp, args->valuelen); + + iext_cnt += XFS_IEXT_ATTR_MANIP_CNT(rmt_blks); } else { XFS_STATS_INC(mp, xs_attr_remove); @@ -460,6 +472,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, + iext_cnt); + 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 Tue Nov 17 13:44:07 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: 11912235 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 4FD7417EC for ; Tue, 17 Nov 2020 13:45:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 29B62206A5 for ; Tue, 17 Nov 2020 13:45:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="p4djkLPm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727661AbgKQNpD (ORCPT ); Tue, 17 Nov 2020 08:45:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732589AbgKQNpC (ORCPT ); Tue, 17 Nov 2020 08:45:02 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32429C0613CF for ; Tue, 17 Nov 2020 05:45:02 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id js21so470118pjb.0 for ; Tue, 17 Nov 2020 05:45:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VsmLEV28ZOMfZvVWHzIja+OeUgfAduMADRIVQ5dd5EU=; b=p4djkLPmPoDuSeF32q0oXhQk7DCQISph6t5r98U/TdHM8ikmp1zh4aWA2sISLh8Yke 9vnkH4X4oTqt/tf8q+Z/qR5Vza4BxM6WJWRgowSgI8syIOtiw1Q6YIxvB58V/9KFnq8o cyvmGG0wSvOdMx9yxekmqabYb1zM6NyQm3ISFEw3eOwYik8sKhoKeniA+ej59Et1QkeG uBWQn4tzBKNkmh7Ne+Krj+fXy9sCctRhi6MKlEqyV6+4GCRxt9k5QZOnZD46raEzwqm5 9FNWEfk5rNwq7kBJO2WSBkZSJEGHF3yFuMzISYP1Vi2UTbxk3Ns+LVe6ggQOXBn7Mts7 om4w== 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=VsmLEV28ZOMfZvVWHzIja+OeUgfAduMADRIVQ5dd5EU=; b=YA/f11r8DnrNgd/onYVbn0pAqXPKItiegpHqUAvWJr/wFVObNbjKQ8tE5MVpnZh/Oa Cr6/UkEy8HopDwdq44RfH9epsG8kmTAd8GaQ/FX0OUQK9QPq0Su2LbBLBiBmfm51vpow wfMLvyQqPbOmi5wMANP0d1a/5suL/0byKf7HhsaXBakH2YEoGVqZWWqZIKPxkMOu+May rM4mmcHgiGK5RVfgEpZFQQK63dwuV25hB5iM3F0EiC66hzaho0w79DoHbT9gqX8cYZje m6BPhCd7zSLJ8SZY16GSrxS6bysGkm07Cu6UTRn6wyLKfgCXG7Nd2zaX9zFnr8kNk6aY usPA== X-Gm-Message-State: AOAM5317dxnS0V13VmGj6GsMVYu5+wb9bKkhf6hNfcZfdGjlNVjf/ukD ee7SajMeCKRuqYpf+lJM+oI2sK6+9RQ= X-Google-Smtp-Source: ABdhPJysvOTTsKip0Iamk/31RaGdW3JQjCpLkLhHhfPEXALGTvQSqw6dKd7MsMkYLzuqsviq3+uqQQ== X-Received: by 2002:a17:90b:1108:: with SMTP id gi8mr4508092pjb.56.1605620701364; Tue, 17 Nov 2020 05:45:01 -0800 (PST) Received: from localhost.localdomain ([122.179.49.210]) by smtp.gmail.com with ESMTPSA id y3sm3669399pjb.18.2020.11.17.05.44.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2020 05:45:00 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com Subject: [PATCH V11 05/14] xfs: Check for extent overflow when adding/removing dir entries Date: Tue, 17 Nov 2020 19:14:07 +0530 Message-Id: <20201117134416.207945-6-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201117134416.207945-1-chandanrlinux@gmail.com> References: <20201117134416.207945-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. To be able to always remove an existing directory entry, when adding a new directory entry we make sure to reserve inode fork extent count required for removing a directory entry in addition to that required for the directory entry add operation. Signed-off-by: Chandan Babu R --- 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..f7b0b7fce940 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) << 1); + 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) << 1); + 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) << 1); + 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..08aa808fe290 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) << 1); + if (error) + goto out_trans_cancel; + /* * Allocate an inode for the symlink. */ From patchwork Tue Nov 17 13:44:08 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: 11912243 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 4B59C17EC for ; Tue, 17 Nov 2020 13:45:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 299AC206A5 for ; Tue, 17 Nov 2020 13:45:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="rGI669Bg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732795AbgKQNpF (ORCPT ); Tue, 17 Nov 2020 08:45:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732589AbgKQNpE (ORCPT ); Tue, 17 Nov 2020 08:45:04 -0500 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA936C0613CF for ; Tue, 17 Nov 2020 05:45:04 -0800 (PST) Received: by mail-pj1-x102a.google.com with SMTP id b12so502183pjl.0 for ; Tue, 17 Nov 2020 05:45:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XvpLSvlcyBaKGUc+FLHnNx0Ewse7iXgrENCBElNIo4Y=; b=rGI669BgmHynESPTUV0fAkNTi+dsyJ7dh31dKP5nEN3zW5NEsy0uNknwdXxfRjUYAV YJyL7BiJmQtxxtuTFehNsB/7oj8gWUNBtRq29/acLc8m/7gyAQ9JrKd64xi6r4QK4Bei IYoHLs5FQFgU+bP1/0yHPoy2CfBbtHSSMHsKUR1LfPAmbZkGy17C9f07jsXHDvi+9XFZ g/PLOnhOOkvUYyYPT4D2K3R8aiGSZNEsZjRHznQZ0hHr64XpFpJjDVUhyONa9zxv6NU0 wOAvq7CNJZuzR5WfDlfpPXT4gNj70L8DR1ku09OKgVtIontFZiEa64KT8zNc7Q/QnyPu 25Fg== 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=XvpLSvlcyBaKGUc+FLHnNx0Ewse7iXgrENCBElNIo4Y=; b=WFionHzvptARzhkfwuBONV40bAHaMoychqBGIDNu5Io5XmgRpJ0xdIzG4zQzeXJOqg Pq2k/ns5Qy6T2Xvj8WCAmYvUJ+xsZ5ZOTzRezZsn/kYeCm/Rg6BPuWSqLYDbYX1d0/P+ 2QUCbrZ6SRhnFEa/aPJat9c+Wp7dwBwJY/01ys6ONEm3pl+6xq8lO2hifCPTPyxHBXUm SKsNUec7vyPjh7cVPGNrNNo9qab4UWQ7Ykie2daVvePJRwi2NBaKJFgj7RSFLxrYdP9Q p3jbm3zSYAptTbJkHl2iC0FMQrjvKuia6+AXCUxNhvWCmWyQpTcHM9I++ijUeMYxDrmt HqxQ== X-Gm-Message-State: AOAM531nrP87UMqjao5p+kVYVC/lFZo52vsI02oVHaxPtJ0Qgk4Ww+XB gPRnzEA1j6feQRkD8CRJNW6jbgWPWpU= X-Google-Smtp-Source: ABdhPJwzfVgHwKdRauU+P0sNmWWHVPn//fauyBahSNH6j71cWJIpgRRYi9VZWZigzZhX3cQjcuZOkw== X-Received: by 2002:a17:90a:4d47:: with SMTP id l7mr4636461pjh.121.1605620703999; Tue, 17 Nov 2020 05:45:03 -0800 (PST) Received: from localhost.localdomain ([122.179.49.210]) by smtp.gmail.com with ESMTPSA id y3sm3669399pjb.18.2020.11.17.05.45.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2020 05:45:03 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, Christoph Hellwig , Allison Henderson Subject: [PATCH V11 06/14] xfs: Check for extent overflow when writing to unwritten extent Date: Tue, 17 Nov 2020 19:14:08 +0530 Message-Id: <20201117134416.207945-7-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201117134416.207945-1-chandanrlinux@gmail.com> References: <20201117134416.207945-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org A write to a sub-interval of an existing unwritten extent causes the original extent to be split into 3 extents i.e. | Unwritten | Real | Unwritten | Hence extent count can increase by 2. Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Allison Henderson Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_inode_fork.h | 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 Tue Nov 17 13:44:09 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: 11912237 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 89C7D1391 for ; Tue, 17 Nov 2020 13:45:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6297B206A5 for ; Tue, 17 Nov 2020 13:45:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="J3K6dKIC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733198AbgKQNpK (ORCPT ); Tue, 17 Nov 2020 08:45:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732494AbgKQNpH (ORCPT ); Tue, 17 Nov 2020 08:45:07 -0500 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F6E4C0613CF for ; Tue, 17 Nov 2020 05:45:07 -0800 (PST) Received: by mail-pl1-x62a.google.com with SMTP id 35so6076469ple.12 for ; Tue, 17 Nov 2020 05:45:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ILp5iM7cQcNHUrkAX0Lz/6PweGyzSkbIPzR9qhi/Ue0=; b=J3K6dKIC0iguqxWkDzjmmnqg2fcDts07PzNrwvamDhJ744Mzkt0lwRZtSIA/A502Xp 1ROdDcwIE69z596zs/S7GIT2NJDwciuWrLdj46anKLRgSHH1BrHuSPQJwqD61MrKQB6r IFFm+fvugjCkNk5m+rU1SJ5sqjsutwnW0r9/C63QgI5NG9Yz5i8myg17k0wQa584ep+r nEKfW16qrE8QQcPQ9RV0kgUoKq0EGENM9DL++CjL2y5S6X8895mnlEWSI9H8jczKOYN3 NTJiHIdi/bp9rY40lhfFMPCASTQC5rOXWhUIBeIflNLHYz9RWDOayp7kPLUWeZex7ZWA Th2g== 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=ILp5iM7cQcNHUrkAX0Lz/6PweGyzSkbIPzR9qhi/Ue0=; b=Rez7TkZlQY/H4JOdftvPWefiqvChxe0dqDhvJvv2QP2gkVI/mVC7ZYEuoFF9+muJEx rgS0Vif+VgF15bU6iP6hC6IpW9EbTHIcTUEPbR/Pg5wCiOzZHpmrPyBnmAftQo9Qh44I OLi6cnOBNDdpW7rDEc2+mNpRsseWmVcMdcESEIAHeRXYlm4Sz7vuBXeJaKEh3tfq9YJO quQxtE6+qEcYMRRP1rS5TkkWUbJcFuqdO5knqWvt39G3DPNmjcmtgSDubzrDzhTRk59R Tgoo6PsWychDtDf5SxI5ysXTGcmbfq5qV3RVbzPMY56Z//+8TqmPhv548l2wsebu/Mt3 4fDg== X-Gm-Message-State: AOAM532eabv+RF8cN6k7XXahG/9ndwAG0UGS1HQPGSKBy3tKAfxAdiwa nqknESy0d0AeikBjilAGsZDXXzLBVTA= X-Google-Smtp-Source: ABdhPJzJQZrfcrwldGx1OINlkmy30u2zmlwyi54ku81CXyIloeHW5Dxvd7wnWBRMlb4pbg8saWC7hQ== X-Received: by 2002:a17:902:7004:b029:d8:fc7c:4fef with SMTP id y4-20020a1709027004b02900d8fc7c4fefmr1454499plk.75.1605620706732; Tue, 17 Nov 2020 05:45:06 -0800 (PST) Received: from localhost.localdomain ([122.179.49.210]) by smtp.gmail.com with ESMTPSA id y3sm3669399pjb.18.2020.11.17.05.45.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2020 05:45:06 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, Christoph Hellwig , Allison Henderson Subject: [PATCH V11 07/14] xfs: Check for extent overflow when moving extent from cow to data fork Date: Tue, 17 Nov 2020 19:14:09 +0530 Message-Id: <20201117134416.207945-8-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201117134416.207945-1-chandanrlinux@gmail.com> References: <20201117134416.207945-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Moving an extent to data fork can cause a sub-interval of an existing extent to be unmapped. This will increase extent count by 1. Mapping in the new extent can increase the extent count by 1 again i.e. | Old extent | New extent | Old extent | Hence number of extents increases by 2. Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Allison Henderson Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_inode_fork.h | 9 +++++++++ fs/xfs/xfs_reflink.c | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index 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 Tue Nov 17 13:44:10 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: 11912239 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 C69776C1 for ; Tue, 17 Nov 2020 13:45:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E4FA206A5 for ; Tue, 17 Nov 2020 13:45:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dGrPH6WL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732494AbgKQNpK (ORCPT ); Tue, 17 Nov 2020 08:45:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733022AbgKQNpK (ORCPT ); Tue, 17 Nov 2020 08:45:10 -0500 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 EFC70C0613CF for ; Tue, 17 Nov 2020 05:45:09 -0800 (PST) Received: by mail-pl1-x643.google.com with SMTP id s2so10237585plr.9 for ; Tue, 17 Nov 2020 05:45:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nt70IvY/vtgLa/y5uH7G+5m8dg0wvGwo7q/BlwAPtZA=; b=dGrPH6WLDmIGJRgWhbPVHsaYbZXjZO43nMs8sfffQ4rSZsV3Jh+dqkMIOnYR80LYmz A8H14y90Sr1alGAurQCbXvL1RaSLBI5rNpywSTyt3GY5GzYQpqs2aLUxaseNK+yQYQDU qoXXJ7WvfGk1XCiIvSWdtngefNzWsw3Kl8wkcM/Kyhy8yfPYbEDkKwHQo+s5UVZueSRg qSGCH+jKHXGOGuu++HcFK8k1AXNP/jCHWEX3v89LPTdK50hOvpUY7ZB3RqvAXR51rNuX 2Mg6KW2rqYalhN+4+vYmNWcXS+5+6t5/+YdVYQMbTHLRNe/q21+VWvNc7NsnfFDXaHyj CB2Q== 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=nt70IvY/vtgLa/y5uH7G+5m8dg0wvGwo7q/BlwAPtZA=; b=Nv9sV3jyKDiBnK3s7RjCDZ6HBaxiNDTz1732Wjbu8/iAO4q65UkW6umBjjtjL8Hxdr Y7EFTLvpqbM7xDqhV8bpsxJaBKIPMslSDwH05LDSva/q0m9KU7q/3Wbvl7d/rSGXiUTm bM541ooDTMOSdlenRR0ZP391c9YLnqxUe/7eZiN84Q2aeEN55euxX+vl9+w8wtPczv5+ Hh4O1vW4MnsdXAZWWfFIh1uBrtEvGvwTcLGAbps4PbgsEl85nWsadzTlikV1fqSk+AdM mhqN7/ozuGwaIACTsbC6RkjkyZ1CVNxFuYn8cSVi/7Ed9wejMjWakIX0IvoKBLjK8PIN QNRw== X-Gm-Message-State: AOAM532KXR4auU2fBvgSdDBu66a2ln0ST1bRZmSMmawtp3YS6b/Ozarc RAuXv/aS2rxxbL3clwMsZrZmkfYYBa4= X-Google-Smtp-Source: ABdhPJyM3tmoaDPzBstRvPYSAjXsheL3Y6d96H1qI3q3JU58O9SCWN1HMxCWuFBNJnhhL0ePk1CLHw== X-Received: by 2002:a17:902:9a4c:b029:d6:1f21:8021 with SMTP id x12-20020a1709029a4cb02900d61f218021mr17326871plv.58.1605620709200; Tue, 17 Nov 2020 05:45:09 -0800 (PST) Received: from localhost.localdomain ([122.179.49.210]) by smtp.gmail.com with ESMTPSA id y3sm3669399pjb.18.2020.11.17.05.45.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2020 05:45:08 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, Allison Henderson Subject: [PATCH V11 08/14] xfs: Check for extent overflow when remapping an extent Date: Tue, 17 Nov 2020 19:14:10 +0530 Message-Id: <20201117134416.207945-9-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201117134416.207945-1-chandanrlinux@gmail.com> References: <20201117134416.207945-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Remapping an extent involves unmapping the existing extent and mapping in the new extent. When unmapping, an extent containing the entire unmap range can be split into two extents, i.e. | Old extent | hole | Old extent | Hence extent count increases by 1. Mapping in the new extent into the destination file can increase the extent count by 1. Reviewed-by: Allison Henderson Reviewed-by: Darrick J. Wong Signed-off-by: Chandan Babu R --- fs/xfs/xfs_reflink.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index 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 Tue Nov 17 13:44:11 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: 11912241 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 11D2F175A for ; Tue, 17 Nov 2020 13:45:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D9245206A5 for ; Tue, 17 Nov 2020 13:45:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RQCfLNH4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732628AbgKQNpN (ORCPT ); Tue, 17 Nov 2020 08:45:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732150AbgKQNpM (ORCPT ); Tue, 17 Nov 2020 08:45:12 -0500 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80D65C0613CF for ; Tue, 17 Nov 2020 05:45:12 -0800 (PST) Received: by mail-pg1-x530.google.com with SMTP id 34so12835908pgp.10 for ; Tue, 17 Nov 2020 05:45:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gjkXFZh3Yb0k29wFDewcPx5MIG4z7sYEJ/SPODbUO9A=; b=RQCfLNH4SZZk9qqdLoMxZp3PNKUWf73izakzsGJT4DTURKKNvVQC1g67VtqTZMKPeX 4pskWWvIGVDFWsAF+T7vP5AqI59xNW2RUieBpGEb/wsFiwP4KAMEkkKaFSRUEpkAfmo9 iQaDrlIgvm7rCeMygVMeZwSmerXI24R8Yq5RwT0UfYgWF2mN6h5ebIRrREIu5qkjXgi3 Si1Ji25fq90bKuEwAWYFNQKPhUzVyeme1qhqpYUgSFBRpOZDISENiqjbIe55hKupkxTF wnBLX6AD8YGJXvfj8N4sEY9JYokoa3syqrPOCnORZA/5UaMYic1q3EcDKHmLmb/JMtgG N4kg== 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=gjkXFZh3Yb0k29wFDewcPx5MIG4z7sYEJ/SPODbUO9A=; b=JoRs43Q7wVkJm2/rgeWADSKoT55AyOR2BEzGvUvEdURs4wiNTpStl7cyU/Ang5U6ek OpXsJe8OHURk3VJfQhPUyZRoraKBoS7xoRiPLXBijAv8Awts9LorVX/roJog7CTpBS+L mCWStWdhgfVpfJfVe7r4bRB2edFN5l8EFX8fOKbKTs/GhEIgSY0I5KoAj/vSEgPGs1Ss UgRttUUGOuiu3Uuc59LIolJGnXD4y+hJIanuhbMy9XwS1svDod+rebbNccmpu08fdgwj bCdkHgB0322SQUYbvF0uLcljAs8U+A8IBhAE7ZNYoO9bIKubopcL0Rt/H1oVWJHHySUn KtJw== X-Gm-Message-State: AOAM530KhAfVWaRKNJHMHYYCrV2/35vAxDBe9sL6Ro0pkl2xDt0aedBr hRFkq3zxIThPuSn5iCCw26mdUnCJEg8= X-Google-Smtp-Source: ABdhPJz1l4yFOP5YRlKVPEnhcj2vNXWEHM9xzSADsJumDa3CVOPzsAiCiELctC9F0NPrV7SB+ISNxQ== X-Received: by 2002:a63:9241:: with SMTP id s1mr3458069pgn.291.1605620711746; Tue, 17 Nov 2020 05:45:11 -0800 (PST) Received: from localhost.localdomain ([122.179.49.210]) by smtp.gmail.com with ESMTPSA id y3sm3669399pjb.18.2020.11.17.05.45.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2020 05:45:11 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, Allison Henderson Subject: [PATCH V11 09/14] xfs: Check for extent overflow when swapping extents Date: Tue, 17 Nov 2020 19:14:11 +0530 Message-Id: <20201117134416.207945-10-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201117134416.207945-1-chandanrlinux@gmail.com> References: <20201117134416.207945-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Removing an initial range of source/donor file's extent and adding a new extent (from donor/source file) in its place will cause extent count to increase by 1. Reviewed-by: Darrick J. Wong Reviewed-by: Allison Henderson Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_inode_fork.h | 7 +++++++ fs/xfs/xfs_bmap_util.c | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index 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 Tue Nov 17 13:44:12 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: 11912251 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 3BCCD17EC for ; Tue, 17 Nov 2020 13:45:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 136B2206A5 for ; Tue, 17 Nov 2020 13:45:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HEOgu4E5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733210AbgKQNpT (ORCPT ); Tue, 17 Nov 2020 08:45:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733022AbgKQNpP (ORCPT ); Tue, 17 Nov 2020 08:45:15 -0500 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E28FCC0613CF for ; Tue, 17 Nov 2020 05:45:14 -0800 (PST) Received: by mail-pg1-x52e.google.com with SMTP id m9so6503619pgb.4 for ; Tue, 17 Nov 2020 05:45:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1+73tUpCP28xwGN/QBPz9W2Stq7CFunwSFbP10k5M0o=; b=HEOgu4E5GZaNV1L+suqo8TuDbP1Xso7SdYAfVs5WeqiL5rcdmuWGU1Pi+VPCcvr7Ra SGW90XyqB0wRvI4ovUtTgij+9zAKfvm+kd0Yhn4c8wGpzQAqOIokC13Ee9d8qjxgAqCZ SKja+kX2wXpVmSCUjobi/GwpN9T7/CprehBnHqiie6JsHeRlOaJOx3VsNV/lSqeop2j5 Kw/3e4KQ9ALSYHGkOMLePLPyH9Yx18vNiDFysblYsy7vfb2AJAObsRjBZxvt7ou3mNa4 FMuO2hC2uHND3DaXKvbPRjyBhKGqzPX9oIN4J9dOUOQJNdI6wzyZQakDGyByki3Otiu4 TWzA== 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=1+73tUpCP28xwGN/QBPz9W2Stq7CFunwSFbP10k5M0o=; b=iHcO/Aa4WmwBaGzRW2Q+QOMhkF8/iryqZkgxki/mL1CafPgXhUgkV31tkEdsrw9Far FUJlOvZpIjZdTo+B6gRgNuDMiu9CxCMDI6UHz8Kj8vImXDsqhBr6aRGSw1tnHYlk8xN6 w49LrRa6V8X2SdLky+oTzpdnJbmwvURIpyY5PN4ZTnLF/TpdAgA/WXx5MWhfLwNklZKD OP+9qXSa1LAZdHYcd8K71OMeFcQ3DTLKL1U6o08qvrKCVLkc3gLzOua2JpEe8TGEW7Bd 9eIwsv/kRCYstf2cjG20ytIOc1eWtTz/5Utl8cbW6cDsvbTi0IY6vvNKfrK3j9IOnit+ JUew== X-Gm-Message-State: AOAM531ii+JKqkHeByhCg4XbpDBXnxsNfVfsMUgZsHzjyfHWR6uvBsYA hFg/afqyq3rECG0pb8rjJSIYLUcjjFE= X-Google-Smtp-Source: ABdhPJyvnxH+uOsAYsodAb7m2r97TH0WsFCiR07QFmdaQqA7yXyTXQlnCPL6cn0hujjzOzJnNCYhdg== X-Received: by 2002:a63:ff03:: with SMTP id k3mr3568294pgi.304.1605620714018; Tue, 17 Nov 2020 05:45:14 -0800 (PST) Received: from localhost.localdomain ([122.179.49.210]) by smtp.gmail.com with ESMTPSA id y3sm3669399pjb.18.2020.11.17.05.45.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2020 05:45:13 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com Subject: [PATCH V11 10/14] xfs: Introduce error injection to reduce maximum inode fork extent count Date: Tue, 17 Nov 2020 19:14:12 +0530 Message-Id: <20201117134416.207945-11-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201117134416.207945-1-chandanrlinux@gmail.com> References: <20201117134416.207945-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 35. With block size of 4k, xattr (with local value) insert operation would require in the worst case "XFS_DA_NODE_MAXDEPTH + 1" plus "XFS_DA_NODE_MAXDEPTH + (64k / 4k)" (required for guaranteeing removal of a maximum sized xattr) number of extents. This evaluates to ~28 extents. To allow for additions of two or more xattrs during extent overflow testing, the pseudo max extent count is set to 35. Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_errortag.h | 4 +++- fs/xfs/libxfs/xfs_inode_fork.c | 4 ++++ fs/xfs/xfs_error.c | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_errortag.h b/fs/xfs/libxfs/xfs_errortag.h index 53b305dea381..1c56fcceeea6 100644 --- a/fs/xfs/libxfs/xfs_errortag.h +++ b/fs/xfs/libxfs/xfs_errortag.h @@ -56,7 +56,8 @@ #define XFS_ERRTAG_FORCE_SUMMARY_RECALC 33 #define XFS_ERRTAG_IUNLINK_FALLBACK 34 #define XFS_ERRTAG_BUF_IOERROR 35 -#define XFS_ERRTAG_MAX 36 +#define XFS_ERRTAG_REDUCE_MAX_IEXTENTS 36 +#define XFS_ERRTAG_MAX 37 /* * Random factors for above tags, 1 means always, 2 means 1/2 time, etc. @@ -97,5 +98,6 @@ #define XFS_RANDOM_FORCE_SUMMARY_RECALC 1 #define XFS_RANDOM_IUNLINK_FALLBACK (XFS_RANDOM_DEFAULT/10) #define XFS_RANDOM_BUF_IOERROR XFS_RANDOM_DEFAULT +#define XFS_RANDOM_REDUCE_MAX_IEXTENTS 1 #endif /* __XFS_ERRORTAG_H_ */ diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c index 8d48716547e5..989b20977654 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 = 35; + 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 Tue Nov 17 13:44:13 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: 11912245 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 7C6091391 for ; Tue, 17 Nov 2020 13:45:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5A2B8206A5 for ; Tue, 17 Nov 2020 13:45:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QHHGXui3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733208AbgKQNpS (ORCPT ); Tue, 17 Nov 2020 08:45:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732768AbgKQNpR (ORCPT ); Tue, 17 Nov 2020 08:45:17 -0500 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F8E5C0613CF for ; Tue, 17 Nov 2020 05:45:17 -0800 (PST) Received: by mail-pf1-x442.google.com with SMTP id i8so3588039pfk.10 for ; Tue, 17 Nov 2020 05:45:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fYn4Dk1EXYBsRc4PsiEBtvGWQor3CttFr0ltlRTYZIQ=; b=QHHGXui3WtoLe1izQRcewyKQpjwoORI8JGZ3ttSe5uL9PZuMwj+KsaKQNkFwNEtQmu 9sgA6SN3wKcylyvzv9Gqn18FKAEXf4zZWB1maum2rqIzaqOnbNiqrjKlKzZtNOJ68DZ4 fIUOOmwHiQ/soWGvKCrGi25tDC4ym2Xw6rtfWiQOQB5+hzgn0RJix4oIWFt91LjTukDs 1CihnR+q9cXDjSc6IoGhKpr9i1UroKg0Py9C7U4CGNChmZeGeyS6xlMIAIrKfqU7BVAJ iTAADa+mJ9t31PaO2m7J/DIO6Djk9qlN0W6ZxjoYoGw827C8vn1kmViwkzgF79ePBSVR uxpQ== 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=fYn4Dk1EXYBsRc4PsiEBtvGWQor3CttFr0ltlRTYZIQ=; b=ufwQ6ADC/QgxeAIBfEKnHFzmne1VBQnh9A4iuJFwgG18pdO0t/nNp1Wfy3VuwGrKVZ /SlGvFulfxIGBYdU15XkYPcTpWS7maNaPirsRqWhU9u1mwYYnCKLHaT95ELUeQoYAdmO O2ftygXHcDnhDUQwBGSIuPigGHvXLreSVM27cadDGHGfBAtNp5lHlzxsLKIypBZroctG 1cdglpmV+lIulF2kOlUIuXa+plo12W1AC/awRiMVzz3VaajpE+RcxaJnhRFFti7LtFCk lcYaSNxODNg+BMLFy8kOmE91Kr4J2tuAa4vsKuRcSxQdo0byn3ByGpF2+RDBF4eq3sxi rBZg== X-Gm-Message-State: AOAM5309ARSHDeevrI13xO1JXlppDLxDWSINdGNt6+CvFE3N2fq2pz3v PlSip9KLTgWQLUI2gZTO5PMyWrZ70HM= X-Google-Smtp-Source: ABdhPJzNR36Btgc+FBt3/qk4uqviXmmA/kPxUQ9+9Tf3pW8ZUyOoTa4ExcLEebnMs3ACsbZ5M1MKxg== X-Received: by 2002:a62:18d1:0:b029:18b:7897:579d with SMTP id 200-20020a6218d10000b029018b7897579dmr1521262pfy.10.1605620716550; Tue, 17 Nov 2020 05:45:16 -0800 (PST) Received: from localhost.localdomain ([122.179.49.210]) by smtp.gmail.com with ESMTPSA id y3sm3669399pjb.18.2020.11.17.05.45.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2020 05:45:15 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, Allison Henderson Subject: [PATCH V11 11/14] xfs: Remove duplicate assert statement in xfs_bmap_btalloc() Date: Tue, 17 Nov 2020 19:14:13 +0530 Message-Id: <20201117134416.207945-12-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201117134416.207945-1-chandanrlinux@gmail.com> References: <20201117134416.207945-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org The check for verifying if the allocated extent is from an AG whose index is greater than or equal to that of tp->t_firstblock is already done a couple of statements earlier in the same function. Hence this commit removes the redundant assert statement. Reviewed-by: Allison Henderson Reviewed-by: Darrick J. Wong Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_bmap.c | 1 - 1 file changed, 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 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 Tue Nov 17 13:44:14 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: 11912249 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 0146D1668 for ; Tue, 17 Nov 2020 13:45:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CAFBB206A5 for ; Tue, 17 Nov 2020 13:45:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WqO60eJb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732472AbgKQNpV (ORCPT ); Tue, 17 Nov 2020 08:45:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733209AbgKQNpT (ORCPT ); Tue, 17 Nov 2020 08:45:19 -0500 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D0B7C0613CF for ; Tue, 17 Nov 2020 05:45:19 -0800 (PST) Received: by mail-pf1-x444.google.com with SMTP id w6so17328410pfu.1 for ; Tue, 17 Nov 2020 05:45:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QiHkQlus2qgqmYvIyhwPk8dKwWaSPHNiqdeEZjmv2gQ=; b=WqO60eJbXErxXFtw5XNKxV5ML46antVrVuKvaItNwPD28yP/mTOBeTqSzyW7DVhuDe 7Tvo/As4hfhTniMmF36+f+xegOLeN8AlSYMNxoauxqmC9lMnc9TPfbo4EIDobtDPtoVR hETxw1bb8aqGtFo0iXLeh4BBfq5NxeR2YYr+Z2260xhs6SD6kQDZI2THzlw8rQbB4MJw Z0Y06vYtkpEZrskY2hzrHw+mC8O7fjNadWOQU/yeYkEi+xItEcP2FmzpAP2Q6m0o8zen Hj65AC3txK3AlD32rM77B7rpljRdDUKy4WCWMracy/8P5hZYGOWZ2wNN/VidepnjWQ2X sCJQ== 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=QiHkQlus2qgqmYvIyhwPk8dKwWaSPHNiqdeEZjmv2gQ=; b=FLYOHG1K5CvRekSvcmCgMfVTtCT0FlbSPYTyy9sYa7DKxdW1110W+gDpcvF4ZgyynK bPvbSddKJ61xiV7CU5xgkrw2hpVmTScQ81U4i7xRieT5F1+O3yj+Dkq1mODnhXRJWxYy dmILuqQ+kMJe2xOJ6SeCTcxuZUYZIcbbaf/KXqEQHXA0GaVTzvNlkSHac9UsGtUvxMSE 3DLlX0k8wL2tedJrENCUkbGO/nGnJA8NCL1KASqaqb7yrP3a0TFWkCwInJuLjNUVkmIp xkwUw8adFq1Uf6jKPw5TU5if5IW6BmRHp8ymWws9MhtcAiK/oeIbZjg6LjiPY+07ks3B bbEg== X-Gm-Message-State: AOAM531zcIM8XH6t4PdrApXHWexcQo/Ut75REtiOS27QxMbxAkp9QovK umAl38/taAMKuHJGEPVwiV8JgwcRjqo= X-Google-Smtp-Source: ABdhPJy/KHUhijCLzdsI88SyAZHxXiEGs+q1+0nAiQS9wbemmKUUzYQXGtGLJXLfMbdCfL5smP/m2Q== X-Received: by 2002:a62:2c16:0:b029:15d:8d2:2e6d with SMTP id s22-20020a622c160000b029015d08d22e6dmr18541949pfs.52.1605620718827; Tue, 17 Nov 2020 05:45:18 -0800 (PST) Received: from localhost.localdomain ([122.179.49.210]) by smtp.gmail.com with ESMTPSA id y3sm3669399pjb.18.2020.11.17.05.45.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2020 05:45:18 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com Subject: [PATCH V11 12/14] xfs: Compute bmap extent alignments in a separate function Date: Tue, 17 Nov 2020 19:14:14 +0530 Message-Id: <20201117134416.207945-13-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201117134416.207945-1-chandanrlinux@gmail.com> References: <20201117134416.207945-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org This commit moves over the code which computes stripe alignment and extent size hint alignment into a separate function. Apart from xfs_bmap_btalloc(), the new function will be used by another function introduced in a future commit. Reviewed-by: Darrick J. Wong Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_bmap.c | 89 +++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 37 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 64c4d0e384a5..5032539d5e85 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -3463,13 +3463,59 @@ xfs_bmap_btalloc_accounting( args->len); } +static int +xfs_bmap_compute_alignments( + struct xfs_bmalloca *ap, + struct xfs_alloc_arg *args) +{ + struct xfs_mount *mp = args->mp; + xfs_extlen_t align = 0; /* minimum allocation alignment */ + int stripe_align = 0; + int error; + + /* stripe alignment for allocation is determined by mount parameters */ + if (mp->m_swidth && (mp->m_flags & XFS_MOUNT_SWALLOC)) + stripe_align = mp->m_swidth; + else if (mp->m_dalign) + stripe_align = mp->m_dalign; + + if (ap->flags & XFS_BMAPI_COWFORK) + align = xfs_get_cowextsz_hint(ap->ip); + else if (ap->datatype & XFS_ALLOC_USERDATA) + align = xfs_get_extsz_hint(ap->ip); + if (align) { + error = xfs_bmap_extsize_align(mp, &ap->got, &ap->prev, + align, 0, ap->eof, 0, ap->conv, + &ap->offset, &ap->length); + ASSERT(!error); + ASSERT(ap->length); + } + + /* apply extent size hints if obtained earlier */ + if (align) { + args->prod = align; + div_u64_rem(ap->offset, args->prod, &args->mod); + if (args->mod) + args->mod = args->prod - args->mod; + } else if (mp->m_sb.sb_blocksize >= PAGE_SIZE) { + args->prod = 1; + args->mod = 0; + } else { + args->prod = PAGE_SIZE >> mp->m_sb.sb_blocklog; + div_u64_rem(ap->offset, args->prod, &args->mod); + if (args->mod) + args->mod = args->prod - args->mod; + } + + return stripe_align; +} + STATIC int xfs_bmap_btalloc( struct xfs_bmalloca *ap) /* bmap alloc argument struct */ { xfs_mount_t *mp; /* mount point structure */ xfs_alloctype_t atype = 0; /* type for allocation routines */ - xfs_extlen_t align = 0; /* minimum allocation alignment */ xfs_agnumber_t fb_agno; /* ag number of ap->firstblock */ xfs_agnumber_t ag; xfs_alloc_arg_t args; @@ -3489,25 +3535,11 @@ xfs_bmap_btalloc( mp = ap->ip->i_mount; - /* stripe alignment for allocation is determined by mount parameters */ - stripe_align = 0; - if (mp->m_swidth && (mp->m_flags & XFS_MOUNT_SWALLOC)) - stripe_align = mp->m_swidth; - else if (mp->m_dalign) - stripe_align = mp->m_dalign; - - if (ap->flags & XFS_BMAPI_COWFORK) - align = xfs_get_cowextsz_hint(ap->ip); - else if (ap->datatype & XFS_ALLOC_USERDATA) - align = xfs_get_extsz_hint(ap->ip); - if (align) { - error = xfs_bmap_extsize_align(mp, &ap->got, &ap->prev, - align, 0, ap->eof, 0, ap->conv, - &ap->offset, &ap->length); - ASSERT(!error); - ASSERT(ap->length); - } + memset(&args, 0, sizeof(args)); + args.tp = ap->tp; + args.mp = mp; + stripe_align = xfs_bmap_compute_alignments(ap, &args); nullfb = ap->tp->t_firstblock == NULLFSBLOCK; fb_agno = nullfb ? NULLAGNUMBER : XFS_FSB_TO_AGNO(mp, @@ -3538,9 +3570,6 @@ xfs_bmap_btalloc( * Normal allocation, done through xfs_alloc_vextent. */ tryagain = isaligned = 0; - memset(&args, 0, sizeof(args)); - args.tp = ap->tp; - args.mp = mp; args.fsbno = ap->blkno; args.oinfo = XFS_RMAP_OINFO_SKIP_UPDATE; @@ -3571,21 +3600,7 @@ xfs_bmap_btalloc( args.total = ap->total; args.minlen = ap->minlen; } - /* apply extent size hints if obtained earlier */ - if (align) { - args.prod = align; - div_u64_rem(ap->offset, args.prod, &args.mod); - if (args.mod) - args.mod = args.prod - args.mod; - } else if (mp->m_sb.sb_blocksize >= PAGE_SIZE) { - args.prod = 1; - args.mod = 0; - } else { - args.prod = PAGE_SIZE >> mp->m_sb.sb_blocklog; - div_u64_rem(ap->offset, args.prod, &args.mod); - if (args.mod) - args.mod = args.prod - args.mod; - } + /* * If we are not low on available data blocks, and the underlying * logical volume manager is a stripe, and the file offset is zero then From patchwork Tue Nov 17 13:44:15 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: 11912247 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 B693A6C1 for ; Tue, 17 Nov 2020 13:45:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8C7E5206A5 for ; Tue, 17 Nov 2020 13:45:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ACqDc2jS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732772AbgKQNpX (ORCPT ); Tue, 17 Nov 2020 08:45:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732722AbgKQNpW (ORCPT ); Tue, 17 Nov 2020 08:45:22 -0500 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 15AE1C0613CF for ; Tue, 17 Nov 2020 05:45:22 -0800 (PST) Received: by mail-pl1-x643.google.com with SMTP id d17so8722902plr.5 for ; Tue, 17 Nov 2020 05:45:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mzo4XKFqwetL4wgqWPphqhx1Obl5kc6g2AJMDkW2Wts=; b=ACqDc2jS0I7BW738aDNux8J8oJj9vcERDSwDVn2zd50FyC3TOcF+NTi5ssn1JvqkcA U4Umob/SadNFdCTgprtkhOfZY0dcFYQG2+xTXSeGFz2EhcchKlXgBeTFz+tT3na5O/qm VwP3iEATBs30CCZvxEaULHB1zLcNj7tyGhP2XjqXSYwBhx5pvHrphUFq08uaH/u5PeET 8PuZyf12yHUQqVPSHSGXrEo9fNT9OYMogx8lQFxsRVpPv9vyZFYJeW2vJbR73IzcS/4U kuCuNIckjYkq39AeD2CNKMGpg0uvNlRYQiT1WjZ1uOSS7ydQ7J35zEOB3z/UKx/dVhXl azwQ== 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=mzo4XKFqwetL4wgqWPphqhx1Obl5kc6g2AJMDkW2Wts=; b=PBTSNpORcgCz5X7Iwd0WNb4pkBfx3U3WhtGS8hioCMVki7E0qgGsM2asRyqNJE0sFQ 6Pip5qZwmEIYLDe3aTBc01gcrjodcmDtABXz55fRe1xFYQnj0ex7Yz76yU2KgbpY1uj6 UzTnJmXABDaUdqutzyLVn2KbDdEwv0D68l0PWdqLTOpoynLyIjjdBLEX8widC02N0jsk hGk+jjiafCaWY9nyIWnNEfskPjyHk3+smmcNI8to3gBHa78adPX+7Oat0FntpU7wjShs sh2FHDBl2LKV4BpQ5diL05r9Bbc3aQthNRpS+xEUgkhlWzQX5wVjM6OOiuhn/jzjnAIG gWlw== X-Gm-Message-State: AOAM5329oFuaregFC4IZDJpqBP+K9LIQPdZInPKk96OPbKzsOZtEWGmG iCqcHcbAgu+wqa50eIUF4I/wO/YbBso= X-Google-Smtp-Source: ABdhPJzuIRhdSnUsfZH0XEYyYDRgE+0DBTZKLACuihioQENFSYg1RQanGnc8+kQfRu2UOujYP0OWhw== X-Received: by 2002:a17:90b:4c92:: with SMTP id my18mr4330120pjb.152.1605620721334; Tue, 17 Nov 2020 05:45:21 -0800 (PST) Received: from localhost.localdomain ([122.179.49.210]) by smtp.gmail.com with ESMTPSA id y3sm3669399pjb.18.2020.11.17.05.45.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2020 05:45:20 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, Allison Henderson Subject: [PATCH V11 13/14] xfs: Process allocated extent in a separate function Date: Tue, 17 Nov 2020 19:14:15 +0530 Message-Id: <20201117134416.207945-14-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201117134416.207945-1-chandanrlinux@gmail.com> References: <20201117134416.207945-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org This commit moves over the code in xfs_bmap_btalloc() which is responsible for processing an allocated extent to a new function. Apart from xfs_bmap_btalloc(), the new function will be invoked by another function introduced in a future commit. Reviewed-by: Allison Henderson Reviewed-by: Darrick J. Wong Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_bmap.c | 74 ++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 29 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 5032539d5e85..f6cd33684571 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -3510,6 +3510,48 @@ xfs_bmap_compute_alignments( return stripe_align; } +static void +xfs_bmap_process_allocated_extent( + struct xfs_bmalloca *ap, + struct xfs_alloc_arg *args, + xfs_fileoff_t orig_offset, + xfs_extlen_t orig_length) +{ + int nullfb; + + nullfb = ap->tp->t_firstblock == NULLFSBLOCK; + + /* + * check the allocation happened at the same or higher AG than + * the first block that was allocated. + */ + ASSERT(nullfb || + XFS_FSB_TO_AGNO(args->mp, ap->tp->t_firstblock) <= + XFS_FSB_TO_AGNO(args->mp, args->fsbno)); + + ap->blkno = args->fsbno; + if (nullfb) + ap->tp->t_firstblock = args->fsbno; + ap->length = args->len; + /* + * If the extent size hint is active, we tried to round the + * caller's allocation request offset down to extsz and the + * length up to another extsz boundary. If we found a free + * extent we mapped it in starting at this new offset. If the + * newly mapped space isn't long enough to cover any of the + * range of offsets that was originally requested, move the + * mapping up so that we can fill as much of the caller's + * original request as possible. Free space is apparently + * very fragmented so we're unlikely to be able to satisfy the + * hints anyway. + */ + if (ap->length <= orig_length) + ap->offset = orig_offset; + else if (ap->offset + ap->length < orig_offset + orig_length) + ap->offset = orig_offset + orig_length - ap->length; + xfs_bmap_btalloc_accounting(ap, args); +} + STATIC int xfs_bmap_btalloc( struct xfs_bmalloca *ap) /* bmap alloc argument struct */ @@ -3702,36 +3744,10 @@ xfs_bmap_btalloc( return error; ap->tp->t_flags |= XFS_TRANS_LOWMODE; } + if (args.fsbno != NULLFSBLOCK) { - /* - * check the allocation happened at the same or higher AG than - * the first block that was allocated. - */ - ASSERT(ap->tp->t_firstblock == NULLFSBLOCK || - XFS_FSB_TO_AGNO(mp, ap->tp->t_firstblock) <= - XFS_FSB_TO_AGNO(mp, args.fsbno)); - - ap->blkno = args.fsbno; - if (ap->tp->t_firstblock == NULLFSBLOCK) - ap->tp->t_firstblock = args.fsbno; - ap->length = args.len; - /* - * If the extent size hint is active, we tried to round the - * caller's allocation request offset down to extsz and the - * length up to another extsz boundary. If we found a free - * extent we mapped it in starting at this new offset. If the - * newly mapped space isn't long enough to cover any of the - * range of offsets that was originally requested, move the - * mapping up so that we can fill as much of the caller's - * original request as possible. Free space is apparently - * very fragmented so we're unlikely to be able to satisfy the - * hints anyway. - */ - if (ap->length <= orig_length) - ap->offset = orig_offset; - else if (ap->offset + ap->length < orig_offset + orig_length) - ap->offset = orig_offset + orig_length - ap->length; - xfs_bmap_btalloc_accounting(ap, &args); + xfs_bmap_process_allocated_extent(ap, &args, orig_offset, + orig_length); } else { ap->blkno = NULLFSBLOCK; ap->length = 0; From patchwork Tue Nov 17 13:44:16 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: 11912253 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 778951391 for ; Tue, 17 Nov 2020 13:45:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 508E4206A5 for ; Tue, 17 Nov 2020 13:45:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fZSpy1gX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732809AbgKQNpZ (ORCPT ); Tue, 17 Nov 2020 08:45:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732722AbgKQNpY (ORCPT ); Tue, 17 Nov 2020 08:45:24 -0500 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C27EEC0613CF for ; Tue, 17 Nov 2020 05:45:24 -0800 (PST) Received: by mail-pg1-x52a.google.com with SMTP id i13so16104533pgm.9 for ; Tue, 17 Nov 2020 05:45:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=olhR5HB1EgorMwTXCqPaj+ypVe6b565JiLE0znLzIhI=; b=fZSpy1gXdjml8ew3wgojPlV9+WYpE+9FOfRgJ9h79iWyNzpVfQIyYMHYpJXcsy29UE HKvJDMqXzYgRLwLhfxFkc0L4eQDROxCCd5bXIh8YjMUXPcMj2CJYdI3sM3cw26IfFLHp 5A56FePnqWVkJzryBFWEy/emsLGUxUAE/zdgd6zVpPOMC49zZm19yoURmo7Zglf/1hFj W/GdkNIae69GdN1C/DTbdCut5BjYsjX8A7YLwWkixUNnPKLhgliyX4FEbAzVlwaeLyQU YednPKhpBVXlfT/xXrofp7pL3KES8voRmZWlfccLoXWhRYds5k3QjWlZ/lxIPgm/anZK CAZA== 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=olhR5HB1EgorMwTXCqPaj+ypVe6b565JiLE0znLzIhI=; b=WpwrRtxj0SYzl2A1K8vuq1xvwIWOkJDFVb6bV6AyUM5akANWvWE1Y0bTWosZ+AsIV/ qtkYF2FZydXsq0VGDXyog2JkvmHOjpD1iXnwYcFvZFr1Qv0+iJCTAtHMAr29Tz27qCZX S6cPbGP69y8SiNanx+VOivhdwN4W7sEIj0yNjzhwDCrV0Ps+izTYoSxnTYcPRNFGNm+a rHZa83/lG+QptOD0F/R8oVQKmAJVmYOoJ5Qw/PbwmfwlttahJQ3uBiPv2rj4BKlYbJkt WiTwWH7/Wq/MuP2MFrpf24ozyeWLrRgX1v/Nk863MSp0v3szJca7caA61xRjSZi7HjV3 e6jg== X-Gm-Message-State: AOAM533OGsyhue5DmXjiYbF58xbQgsy4NEKCDSUaUwmw7CobU8heaFFJ ehtUXTCDLb0kcz5sAFnNkqQmenLRP14= X-Google-Smtp-Source: ABdhPJy4xaloClHI5vItRX3V5PVbUNCQzDDA3ngyzZfdbKSwWDXwZmbsNQ9dcLPDXqoGZ8G3L1T6ew== X-Received: by 2002:a62:64c1:0:b029:18a:d791:8162 with SMTP id y184-20020a6264c10000b029018ad7918162mr19151646pfb.24.1605620723837; Tue, 17 Nov 2020 05:45:23 -0800 (PST) Received: from localhost.localdomain ([122.179.49.210]) by smtp.gmail.com with ESMTPSA id y3sm3669399pjb.18.2020.11.17.05.45.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2020 05:45:23 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com Subject: [PATCH V11 14/14] xfs: Introduce error injection to allocate only minlen size extents for files Date: Tue, 17 Nov 2020 19:14:16 +0530 Message-Id: <20201117134416.207945-15-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201117134416.207945-1-chandanrlinux@gmail.com> References: <20201117134416.207945-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org This commit adds XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT error tag which helps userspace test programs to get xfs_bmap_btalloc() to always allocate minlen sized extents. This is required for test programs which need a guarantee that minlen extents allocated for a file do not get merged with their existing neighbours in the inode's BMBT. "Inode fork extent overflow check" for Directories, Xattrs and extension of realtime inodes need this since the file offset at which the extents are being allocated cannot be explicitly controlled from userspace. One way to use this error tag is to, 1. Consume all of the free space by sequentially writing to a file. 2. Punch alternate blocks of the file. This causes CNTBT to contain sufficient number of one block sized extent records. 3. Inject XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT error tag. After step 3, xfs_bmap_btalloc() will issue space allocation requests for minlen sized extents only. ENOSPC error code is returned to userspace when there aren't any "one block sized" extents left in any of the AGs. Reviewed-by: Darrick J. Wong Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_alloc.c | 50 ++++++++++++++ fs/xfs/libxfs/xfs_alloc.h | 3 + fs/xfs/libxfs/xfs_bmap.c | 124 ++++++++++++++++++++++++++++------- fs/xfs/libxfs/xfs_errortag.h | 4 +- fs/xfs/xfs_error.c | 3 + 5 files changed, 159 insertions(+), 25 deletions(-) diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c index 852b536551b5..a7c4eb1d71d5 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 stat; + + error = xfs_exact_minlen_extent_available(args, agbp, &stat); + if (error || !stat) + goto out_agbp_relse; + } +#endif /* * Make the freelist shorter if it's too long. * diff --git a/fs/xfs/libxfs/xfs_alloc.h b/fs/xfs/libxfs/xfs_alloc.h index 6c22b12176b8..a4427c5775c2 100644 --- a/fs/xfs/libxfs/xfs_alloc.h +++ b/fs/xfs/libxfs/xfs_alloc.h @@ -75,6 +75,9 @@ typedef struct xfs_alloc_arg { char wasfromfl; /* set if allocation is from freelist */ struct xfs_owner_info oinfo; /* owner of blocks being allocated */ enum xfs_ag_resv_type resv; /* block reservation to use */ +#ifdef DEBUG + bool alloc_minlen_only; /* allocate exact minlen extent */ +#endif } xfs_alloc_arg_t; /* diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index f6cd33684571..c57dcd3f46bc 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -3552,34 +3552,101 @@ xfs_bmap_process_allocated_extent( xfs_bmap_btalloc_accounting(ap, args); } -STATIC int -xfs_bmap_btalloc( - struct xfs_bmalloca *ap) /* bmap alloc argument struct */ +#ifdef DEBUG +static int +xfs_bmap_exact_minlen_extent_alloc( + struct xfs_bmalloca *ap) { - xfs_mount_t *mp; /* mount point structure */ - xfs_alloctype_t atype = 0; /* type for allocation routines */ - xfs_agnumber_t fb_agno; /* ag number of ap->firstblock */ - xfs_agnumber_t ag; - xfs_alloc_arg_t args; - xfs_fileoff_t orig_offset; - xfs_extlen_t orig_length; - xfs_extlen_t blen; - xfs_extlen_t nextminlen = 0; - int nullfb; /* true if ap->firstblock isn't set */ - int isaligned; - int tryagain; - int error; - int stripe_align; + struct xfs_mount *mp = ap->ip->i_mount; + struct xfs_alloc_arg args = { .tp = ap->tp, .mp = mp }; + xfs_fileoff_t orig_offset; + xfs_extlen_t orig_length; + int error; ASSERT(ap->length); + + if (ap->minlen != 1) { + ap->blkno = NULLFSBLOCK; + ap->length = 0; + return 0; + } + orig_offset = ap->offset; orig_length = ap->length; - mp = ap->ip->i_mount; + args.alloc_minlen_only = 1; - memset(&args, 0, sizeof(args)); - args.tp = ap->tp; - args.mp = mp; + xfs_bmap_compute_alignments(ap, &args); + + if (ap->tp->t_firstblock == NULLFSBLOCK) { + /* + * Unlike the longest extent available in an AG, we don't track + * the length of an AG's shortest extent. + * XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT is a debug only knob and + * hence we can afford to start traversing from the 0th AG since + * we need not be concerned about a drop in performance in + * "debug only" code paths. + */ + ap->blkno = XFS_AGB_TO_FSB(mp, 0, 0); + } else { + ap->blkno = ap->tp->t_firstblock; + } + + args.fsbno = ap->blkno; + args.oinfo = XFS_RMAP_OINFO_SKIP_UPDATE; + args.type = XFS_ALLOCTYPE_FIRST_AG; + args.total = args.minlen = args.maxlen = ap->minlen; + + args.alignment = 1; + args.minalignslop = 0; + + args.minleft = ap->minleft; + args.wasdel = ap->wasdel; + args.resv = XFS_AG_RESV_NONE; + args.datatype = ap->datatype; + + error = xfs_alloc_vextent(&args); + if (error) + return error; + + if (args.fsbno != NULLFSBLOCK) { + xfs_bmap_process_allocated_extent(ap, &args, orig_offset, + orig_length); + } else { + ap->blkno = NULLFSBLOCK; + ap->length = 0; + } + + return 0; +} +#else + +#define xfs_bmap_exact_minlen_extent_alloc(bma) (-EFSCORRUPTED) + +#endif + +STATIC int +xfs_bmap_btalloc( + struct xfs_bmalloca *ap) +{ + struct xfs_mount *mp = ap->ip->i_mount; + struct xfs_alloc_arg args = { .tp = ap->tp, .mp = mp }; + xfs_alloctype_t atype = 0; + xfs_agnumber_t fb_agno; /* ag number of ap->firstblock */ + xfs_agnumber_t ag; + xfs_fileoff_t orig_offset; + xfs_extlen_t orig_length; + xfs_extlen_t blen; + xfs_extlen_t nextminlen = 0; + int nullfb; /* true if ap->firstblock isn't set */ + int isaligned; + int tryagain; + int error; + int stripe_align; + + ASSERT(ap->length); + orig_offset = ap->offset; + orig_length = ap->length; stripe_align = xfs_bmap_compute_alignments(ap, &args); @@ -4113,6 +4180,10 @@ xfs_bmap_alloc_userdata( return xfs_bmap_rtalloc(bma); } + if (unlikely(XFS_TEST_ERROR(false, mp, + XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT))) + return xfs_bmap_exact_minlen_extent_alloc(bma); + return xfs_bmap_btalloc(bma); } @@ -4149,10 +4220,15 @@ xfs_bmapi_allocate( else bma->minlen = 1; - if (bma->flags & XFS_BMAPI_METADATA) - error = xfs_bmap_btalloc(bma); - else + if (bma->flags & XFS_BMAPI_METADATA) { + if (unlikely(XFS_TEST_ERROR(false, mp, + XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT))) + error = xfs_bmap_exact_minlen_extent_alloc(bma); + else + error = xfs_bmap_btalloc(bma); + } else { error = xfs_bmap_alloc_userdata(bma); + } if (error || bma->blkno == NULLFSBLOCK) return error; diff --git a/fs/xfs/libxfs/xfs_errortag.h b/fs/xfs/libxfs/xfs_errortag.h index 1c56fcceeea6..6ca9084b6934 100644 --- a/fs/xfs/libxfs/xfs_errortag.h +++ b/fs/xfs/libxfs/xfs_errortag.h @@ -57,7 +57,8 @@ #define XFS_ERRTAG_IUNLINK_FALLBACK 34 #define XFS_ERRTAG_BUF_IOERROR 35 #define XFS_ERRTAG_REDUCE_MAX_IEXTENTS 36 -#define XFS_ERRTAG_MAX 37 +#define XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT 37 +#define XFS_ERRTAG_MAX 38 /* * Random factors for above tags, 1 means always, 2 means 1/2 time, etc. @@ -99,5 +100,6 @@ #define XFS_RANDOM_IUNLINK_FALLBACK (XFS_RANDOM_DEFAULT/10) #define XFS_RANDOM_BUF_IOERROR XFS_RANDOM_DEFAULT #define XFS_RANDOM_REDUCE_MAX_IEXTENTS 1 +#define XFS_RANDOM_BMAP_ALLOC_MINLEN_EXTENT 1 #endif /* __XFS_ERRORTAG_H_ */ diff --git a/fs/xfs/xfs_error.c b/fs/xfs/xfs_error.c index 3780b118cc47..185b4915b7bf 100644 --- a/fs/xfs/xfs_error.c +++ b/fs/xfs/xfs_error.c @@ -55,6 +55,7 @@ static unsigned int xfs_errortag_random_default[] = { XFS_RANDOM_IUNLINK_FALLBACK, XFS_RANDOM_BUF_IOERROR, XFS_RANDOM_REDUCE_MAX_IEXTENTS, + XFS_RANDOM_BMAP_ALLOC_MINLEN_EXTENT, }; struct xfs_errortag_attr { @@ -166,6 +167,7 @@ XFS_ERRORTAG_ATTR_RW(bad_summary, XFS_ERRTAG_FORCE_SUMMARY_RECALC); XFS_ERRORTAG_ATTR_RW(iunlink_fallback, XFS_ERRTAG_IUNLINK_FALLBACK); XFS_ERRORTAG_ATTR_RW(buf_ioerror, XFS_ERRTAG_BUF_IOERROR); XFS_ERRORTAG_ATTR_RW(reduce_max_iextents, XFS_ERRTAG_REDUCE_MAX_IEXTENTS); +XFS_ERRORTAG_ATTR_RW(bmap_alloc_minlen_extent, XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT); static struct attribute *xfs_errortag_attrs[] = { XFS_ERRORTAG_ATTR_LIST(noerror), @@ -205,6 +207,7 @@ static struct attribute *xfs_errortag_attrs[] = { XFS_ERRORTAG_ATTR_LIST(iunlink_fallback), XFS_ERRORTAG_ATTR_LIST(buf_ioerror), XFS_ERRORTAG_ATTR_LIST(reduce_max_iextents), + XFS_ERRORTAG_ATTR_LIST(bmap_alloc_minlen_extent), NULL, };