From patchwork Sat Oct 3 05:56:22 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: 11815061 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 D87B56CB for ; Sat, 3 Oct 2020 05:56:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BD738206DB for ; Sat, 3 Oct 2020 05:56:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Zes5p3Lc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725681AbgJCF4t (ORCPT ); Sat, 3 Oct 2020 01:56:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725446AbgJCF4t (ORCPT ); Sat, 3 Oct 2020 01:56:49 -0400 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 14074C0613D0 for ; Fri, 2 Oct 2020 22:56:49 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id o25so2333689pgm.0 for ; Fri, 02 Oct 2020 22:56:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Xf86IZJ2O3sKEIprAhp2qWm7Jz8QBRKVGV3tBB+AcuY=; b=Zes5p3Lc+TfVvsaBO+U3bSPhZwN1NyTBvNP86tzo1QwtP27p7YdoNzxiiKQuK96w1Z TJPX2klXbE8C0LNF4cwUkUMtkTG+b7l2fgqEIPRMT/r/JTJkN4UCLZRXhL+ShQABK1IK cPMW+oqmZte99qdiYbcp2tzSqreOR4h5Jzq3wMTOMTwIdeGJtiYNKu4+2u28KFqDncqF WYZAiWUJvhyXJLBxVXKL2ucMnnDfEuV+ytxj3c7E1r7mQMmg/paP1sSbSGBbiNhYjBC1 ltEyuqKERfjCtfxlxybLRt3PvxBqMqrZwSJ1aXwULtZlN43V919JHhBT2LWMPV3j3ECH 77bA== 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=Xf86IZJ2O3sKEIprAhp2qWm7Jz8QBRKVGV3tBB+AcuY=; b=dBumDLIE1JdvXLFQ1KlQbz43UIalb6javuJNgKS/NYqim9gai+v4xeJ/SZ0IvVTiqq 5IGx3WHhwQ6/0AwrJ86QGAnwddK8eZI6c4YqWJNxoJlgf6sGviRfwxoks3Kauwfr03Qk Bl/DuJdCvxjt5nRElsX27I8ZPVQB12yHEoU3xMOcW0vvG0ah/sWdljOy5/GqJlB0waLX zfcr/zTgnjG6r0gFRcHU/OD/slezuEYeKsXQ9TAeBr77wg3hlrMVKZC/RUgjoZGLkcby VzmhJydKR+DU8rqw+MK24hSJ3N9+y1YRItyM5DcJNK4n76bbQ/J1n4x5JxhlGIP2FsjN +ylQ== X-Gm-Message-State: AOAM530cYfacHfmPFOB0+755hgHzzK3J3ZJ8IbbQNuZFpOC8im5t9F/3 YB3TtGhwMylc3BanRm/xpV+P8/84YCs= X-Google-Smtp-Source: ABdhPJzen9JOGAAkE1oEpgv4CReHJ1V06RHPV4GTq6qDbf5eu242M6mvZ1gTQ1vv5c22OTodfwtrdw== X-Received: by 2002:a63:ff4e:: with SMTP id s14mr5244711pgk.137.1601704608123; Fri, 02 Oct 2020 22:56:48 -0700 (PDT) Received: from localhost.localdomain ([122.171.168.96]) by smtp.gmail.com with ESMTPSA id 125sm4106664pff.59.2020.10.02.22.56.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 22:56:47 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com Subject: [PATCH V5 01/12] xfs: Add helper for checking per-inode extent count overflow Date: Sat, 3 Oct 2020 11:26:22 +0530 Message-Id: <20201003055633.9379-2-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201003055633.9379-1-chandanrlinux@gmail.com> References: <20201003055633.9379-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: 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 Sat Oct 3 05:56:23 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: 11815063 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 3A87D6CA for ; Sat, 3 Oct 2020 05:56:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 200C4206DD for ; Sat, 3 Oct 2020 05:56:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Bck1M1yt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725710AbgJCF4v (ORCPT ); Sat, 3 Oct 2020 01:56:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725446AbgJCF4v (ORCPT ); Sat, 3 Oct 2020 01:56:51 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74001C0613D0 for ; Fri, 2 Oct 2020 22:56:51 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id q18so2316935pgk.7 for ; Fri, 02 Oct 2020 22:56:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=I4XaXrBhdKh3lZPnlpjXUyaLoXgyYvBk+9LxRONf7fM=; b=Bck1M1ytGSCCeiNJ4k7S3I38Y7iQpL2IjWA6oBDXE5c93j0sO2n2enyDJb20Yhw35h +wEgF5wiO05gqeD2WkVEnpOchIecy6H8iW0Q0n/nI0/l28XRfQoG0VD0ng2P05MpP0Fs r+gtgsgoDb9jPXvmxIncfzxn29/YCyCt6NWEKNKPQgE5nihLslKrLmaailaelsr7kOOU pZXGclrJuVrPeAIq0dx3/4VxNpA8jw9/Szc5X04O1jDcG8kDfNjEiVKihM15wgbltCoA 3q3wRH/XMqu54cGvS2nrtZWj2J2WKuGGfyN14mxEqbACsxXPC9FjPch/VKySAFgbmIyQ Z7sA== 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=I4XaXrBhdKh3lZPnlpjXUyaLoXgyYvBk+9LxRONf7fM=; b=pd/rdkeOrfX3qbGJMFARwzRXLs/m13l1Po14jQpKjewPUYW6+TtDrkd9cy9qI+WxCQ TSUMEkK5JeDR30fRtRk4u1PCk+q3JQM2XHnBnwWGVhpWLlHPPzEDKmcvOJhcZ3R4SFzZ YZWpEqYR1Xco0qgTSH7bvlnp7hePmfaBE1UkufQ76iR2znCu2Q0UpABpgmmzmgiNODre 25VYv266DJo+TK3pX60i0un4FK0HmC8VGiBa20SYhnlkSHzzvU6Hf/gwzG1wIp2QHHIN vwsdUgHme6pAUC2Vmd/Gdc8Mmu/B9yC/3O1wFcLD9flLi3bz09B1gtFfD1tJ5kDOeqbk Gz8g== X-Gm-Message-State: AOAM532E8WX1L1FLv/29jvZwMdwYVWW5r+2nkMS+k85wX5PEpsFvEpyq 3NdEdpEn9U8IQJvxxjuZIoTurp5l8f4= X-Google-Smtp-Source: ABdhPJy+OD3B6T+tYk+dIV9dTeCB8A4odruG9LFzuhJcajA9+0laL2SJ2GoI8cTTikbLw4otQKrmmA== X-Received: by 2002:a63:c34b:: with SMTP id e11mr5464571pgd.25.1601704610610; Fri, 02 Oct 2020 22:56:50 -0700 (PDT) Received: from localhost.localdomain ([122.171.168.96]) by smtp.gmail.com with ESMTPSA id 125sm4106664pff.59.2020.10.02.22.56.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 22:56:49 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com Subject: [PATCH V5 02/12] xfs: Check for extent overflow when trivally adding a new extent Date: Sat, 3 Oct 2020 11:26:23 +0530 Message-Id: <20201003055633.9379-3-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201003055633.9379-1-chandanrlinux@gmail.com> References: <20201003055633.9379-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. Signed-off-by: Chandan Babu R Reviewed-by: Darrick J. Wong --- 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 1b0a01b06a05..51c2d2690f05 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 ec3691372e7c..6a7dcea4ad40 100644 --- a/fs/xfs/xfs_bmap_item.c +++ b/fs/xfs/xfs_bmap_item.c @@ -519,6 +519,13 @@ xfs_bui_item_recover( } 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_inode; + } + count = bmap->me_len; error = xfs_trans_log_finish_bmap_update(tp, budp, type, ip, whichfork, bmap->me_startoff, bmap->me_startblock, &count, state); 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 3072814e407d..5bf22d2e50cb 100644 --- a/fs/xfs/xfs_dquot.c +++ b/fs/xfs/xfs_dquot.c @@ -314,8 +314,14 @@ xfs_dquot_disk_alloc( return -ESRCH; } - /* Create the block mapping. */ xfs_trans_ijoin(tp, quotip, XFS_ILOCK_EXCL); + + error = xfs_iext_count_may_overflow(quotip, XFS_DATA_FORK, + XFS_IEXT_ADD_NOSPLIT_CNT); + if (error) + return error; + + /* Create the block mapping. */ error = xfs_bmapi_write(tp, quotip, dqp->q_fileoffset, XFS_DQUOT_CLUSTER_SIZE_FSB, XFS_BMAPI_METADATA, 0, &map, &nmaps); diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index 3abb8b9d6f4c..a302a96823b8 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -250,6 +250,11 @@ xfs_iomap_write_direct( if (error) goto out_trans_cancel; + error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + XFS_IEXT_ADD_NOSPLIT_CNT); + if (error) + goto out_trans_cancel; + xfs_trans_ijoin(tp, ip, 0); /* diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index 9d4e33d70d2a..3e841a75f272 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -804,6 +804,11 @@ xfs_growfs_rt_alloc( xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); + error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + XFS_IEXT_ADD_NOSPLIT_CNT); + if (error) + goto out_trans_cancel; + /* * Allocate blocks to the bitmap file. */ From patchwork Sat Oct 3 05:56:24 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: 11815065 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 7F2546CA for ; Sat, 3 Oct 2020 05:56:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 64892206F8 for ; Sat, 3 Oct 2020 05:56:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kYdbP1V1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725730AbgJCF4x (ORCPT ); Sat, 3 Oct 2020 01:56:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725446AbgJCF4x (ORCPT ); Sat, 3 Oct 2020 01:56:53 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B86F3C0613D0 for ; Fri, 2 Oct 2020 22:56:53 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id u24so2330274pgi.1 for ; Fri, 02 Oct 2020 22:56:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BwfX1/EcLsyZiWi+KJA2zfiE3bjogd/2F0jOWYeSwno=; b=kYdbP1V1uZGyS94/5VIE4HT1oOX9KvdCSH/Ll12zftuD5H1JrI1mD+dS+T1Qtk2L16 BPqnJvabBtHeNuEbFXHFrg4KVR46n6xmDWqhpOQhJJ2xnahZJP1/7V4KSguT8Z4slTTq CVUh7kBhO+Ke6R6Lo00aPdeXpPVeaa+/ZLWeMtr9x8Y+AlHqepiyium5m3o7THsN2jlG h4B+h3qSDGe6IsNDOWVzz08AFzJST+4nO8u+HxJODrskwgmrv16b57yf2RbTwN3VFQjm Mj3zv9DqEKEJFZzmn7ZmhS1EWEdBoTGPT+aefWeSDuN4fqKHaCa2dNASf1zBaZ0k2dP2 9gAg== 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=BwfX1/EcLsyZiWi+KJA2zfiE3bjogd/2F0jOWYeSwno=; b=U8Vzmdl8DRlSsPBCCT4+/DxyMrfNnZMQT8nztdxYGzZmDIkqzN1bRMFddkoSqH/Dj/ rDxIvX7porwp5hZvgiWtS1z/QsarTIMSvImpmig/ZFJedBLFDRjvxOXwreTJmMoZhRco g9HLZy/i9QuF7fIuDC1H/x+sBuNF4gIpA4Ylt0PBZ6dwgm9ZVQ3mxaZTZZWbOwf46NqI JSI3X0oIG6/4awyiB0UsIeM/wzcapdehuTTEyRJBn3PtADJ3oVsWV38Eyx+SQZwdI4fN tL2IqXzDZ8CfQ6V7KojY6ZSDrlQmNejOnC61GDnRevABDwNr6mJPghQjq1nHBOg1TrLy h2Zg== X-Gm-Message-State: AOAM533BuMO++Bl1aK0nGyrfTEs794J3zDA8WblukpFEYIDeg2Nvf7fl MBQ/qM8tsBYTJEHKEtfrIhdSeMrpu9ZWFg== X-Google-Smtp-Source: ABdhPJws7kbkDOQy2fKLYZ8F3g8JrOYBqSss7c3LQUl1cuBohih3bojNGsZ13IABlSQaPHwOIU0Tyw== X-Received: by 2002:a63:5566:: with SMTP id f38mr5558815pgm.9.1601704612990; Fri, 02 Oct 2020 22:56:52 -0700 (PDT) Received: from localhost.localdomain ([122.171.168.96]) by smtp.gmail.com with ESMTPSA id 125sm4106664pff.59.2020.10.02.22.56.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 22:56:52 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com Subject: [PATCH V5 03/12] xfs: Check for extent overflow when punching a hole Date: Sat, 3 Oct 2020 11:26:24 +0530 Message-Id: <20201003055633.9379-4-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201003055633.9379-1-chandanrlinux@gmail.com> References: <20201003055633.9379-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. Signed-off-by: Chandan Babu R Reviewed-by: Darrick J. Wong --- 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 6a7dcea4ad40..323cee00bd45 100644 --- a/fs/xfs/xfs_bmap_item.c +++ b/fs/xfs/xfs_bmap_item.c @@ -440,6 +440,7 @@ xfs_bui_item_recover( bool op_ok; unsigned int bui_type; int whichfork; + int iext_delta; int error = 0; /* Only one mapping operation per BUI... */ @@ -519,12 +520,14 @@ xfs_bui_item_recover( } 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_inode; - } + 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_inode; count = bmap->me_len; error = xfs_trans_log_finish_bmap_update(tp, budp, type, ip, whichfork, 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 Sat Oct 3 05:56:25 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: 11815067 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 E8F446CB for ; Sat, 3 Oct 2020 05:56:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CFFE4206F8 for ; Sat, 3 Oct 2020 05:56:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="vPc36Hyb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725747AbgJCF45 (ORCPT ); Sat, 3 Oct 2020 01:56:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725446AbgJCF45 (ORCPT ); Sat, 3 Oct 2020 01:56:57 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13AC0C0613D0 for ; Fri, 2 Oct 2020 22:56:56 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id t7so2449604pjd.3 for ; Fri, 02 Oct 2020 22:56:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sYWqESdT3CFEP/9SblnZ7bhEP9vwdWStxz+7/UAVdpM=; b=vPc36HybHmTc2oTgpdElGPaYvybJHXi+OiOPm/vC6zRhm5xTm59M5fBaB2SAqoDx2L 4WKA8uKeOTaPSRj3yquZEmylSGaucAMhdjcnjx6+gYXlMhhKEbeVoftv9lAU91/tBSeJ Wo6nJYkZcQokazqXbywalkbfoKHIalknHrX0XJJxLpRjpotnS0ckaW5YdD0Y181qSEZA bK6TELuUH1hx5JJJdN+7t3HuoZXLYIkkftmkZnO2EnDS0SabIyqX2D2d04ZR0C4VQzdn AW5M47uNYgv2wpvLt3qYhoKaXqT//uXaToaemOv5eO5fHlfgvIuBnw7Pb4Ds2Ji7q7Z9 mGmw== 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=sYWqESdT3CFEP/9SblnZ7bhEP9vwdWStxz+7/UAVdpM=; b=i7KxqriiP8okBQL0Os9ucLO5C4jw1g1SDw+tUhQWwBjjOZ3TvxxO9xcF3HLKhbonQp ptMXkVElr6LxWKXad+rfnzBzCr7CbYdKkbSpJCBIJw0dW5IZ0RkvleWy9uj7mdl33YE4 dMleFXwba6JYOyAcdqVPMJv+lgXgPaORtnmmzRoIuuJgyAV5VUnaVtMiLCyGYU+yNUn+ 8przM9KxFOqSFRjuRqcv3+7Oj5Yt0lywj+WI22s3R7lgEg7G3KfPJ54gWdHeghP4tNye z9oWkn9EF2pFP05mdHGlTyRkMM0SZf9u/RwNkLeFAs8PC+/fWe2CqEcfiPkFlu8biqVX zfCg== X-Gm-Message-State: AOAM530rsMbW7I5WHQSIvAYdaDd6VRSKN1GPX56AF4S6HFyr156L6+VK aF7H6nJrLbAN7tIUHtXcFr/gkUeO780kfw== X-Google-Smtp-Source: ABdhPJxLfjFMWORqMMTFzuaNy3UgrQIeKw0fZOCDDgTNNKVFCrXGZf7B8i5JZTDJZMqMuPWu6Ox4DQ== X-Received: by 2002:a17:90b:1297:: with SMTP id fw23mr5968602pjb.184.1601704615340; Fri, 02 Oct 2020 22:56:55 -0700 (PDT) Received: from localhost.localdomain ([122.171.168.96]) by smtp.gmail.com with ESMTPSA id 125sm4106664pff.59.2020.10.02.22.56.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 22:56:54 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com Subject: [PATCH V5 04/12] xfs: Check for extent overflow when adding/removing xattrs Date: Sat, 3 Oct 2020 11:26:25 +0530 Message-Id: <20201003055633.9379-5-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201003055633.9379-1-chandanrlinux@gmail.com> References: <20201003055633.9379-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. Signed-off-by: Chandan Babu R Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_attr.c | 13 +++++++++++++ fs/xfs/libxfs/xfs_inode_fork.h | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c index fd8e6418a0d3..be51e7068dcd 100644 --- a/fs/xfs/libxfs/xfs_attr.c +++ b/fs/xfs/libxfs/xfs_attr.c @@ -396,6 +396,7 @@ xfs_attr_set( struct xfs_trans_res tres; bool rsvd = (args->attr_filter & XFS_ATTR_ROOT); int error, local; + int rmt_blks = 0; unsigned int total; if (XFS_FORCED_SHUTDOWN(dp->i_mount)) @@ -442,11 +443,15 @@ xfs_attr_set( tres.tr_logcount = XFS_ATTRSET_LOG_COUNT; tres.tr_logflags = XFS_TRANS_PERM_LOG_RES; total = args->total; + + if (!local) + rmt_blks = xfs_attr3_rmt_blocks(mp, args->valuelen); } else { XFS_STATS_INC(mp, xs_attr_remove); tres = M_RES(mp)->tr_attrrm; total = XFS_ATTRRM_SPACE_RES(mp); + rmt_blks = xfs_attr3_rmt_blocks(mp, XFS_XATTR_SIZE_MAX); } /* @@ -460,6 +465,14 @@ xfs_attr_set( xfs_ilock(dp, XFS_ILOCK_EXCL); xfs_trans_ijoin(args->trans, dp, 0); + + if (args->value || xfs_inode_hasattr(dp)) { + error = xfs_iext_count_may_overflow(dp, XFS_ATTR_FORK, + XFS_IEXT_ATTR_MANIP_CNT(rmt_blks)); + if (error) + goto out_trans_cancel; + } + if (args->value) { unsigned int quota_flags = XFS_QMOPT_RES_REGBLKS; diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index bcac769a7df6..5de2f07d0dd5 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -47,6 +47,16 @@ struct xfs_ifork { */ #define XFS_IEXT_PUNCH_HOLE_CNT (1) +/* + * Adding/removing an xattr can cause XFS_DA_NODE_MAXDEPTH extents to + * be added. One extra extent for dabtree in case a local attr is + * large enough to cause a double split. It can also cause extent + * count to increase proportional to the size of a remote xattr's + * value. + */ +#define XFS_IEXT_ATTR_MANIP_CNT(rmt_blks) \ + (XFS_DA_NODE_MAXDEPTH + max(1, rmt_blks)) + /* * Fork handling. */ From patchwork Sat Oct 3 05:56:26 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: 11815069 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 351F86CB for ; Sat, 3 Oct 2020 05:56:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 16F06206F8 for ; Sat, 3 Oct 2020 05:56:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="t5WOnAwL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725764AbgJCF46 (ORCPT ); Sat, 3 Oct 2020 01:56:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725446AbgJCF46 (ORCPT ); Sat, 3 Oct 2020 01:56:58 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 783D7C0613D0 for ; Fri, 2 Oct 2020 22:56:58 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id kk9so2261112pjb.2 for ; Fri, 02 Oct 2020 22:56:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+yzZR2iVQ2ZdH/KMJFzmnk4qPWZEMSnlIB8x5f/rCn8=; b=t5WOnAwLYlQx3JWHuyTnYYLVsPf7HgoepbI1/nQKGEQvXW2FyH9NIgfkx7krnbYUD4 rQU2ZcBV+EmkdKKuRko8YBXw/dfKrcwuEAruf73zc0TaNNVKXXBbrksIECdqXz3HPbrk XwH/RhYdnfFIQwpz/FjVliYQg599vtN/PG82YxpW4fDbHeSVWU35EYgf7uLbqH8bMgxU gGjJghLCLO8WRoc3sOlDHZcdhWk3NugCwkeMMLgz/hrUdhZNpMmCNcAm1nNcPgza8sMV njgneig2OIwuKGOQ8ncewkIg/t6Ezc6kKeaSbnPrMxDYBUPd4yskQv5Pz6SsWE9In98/ DbMg== 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=+yzZR2iVQ2ZdH/KMJFzmnk4qPWZEMSnlIB8x5f/rCn8=; b=RDbb9+rYcWYtJ4KSRuCSHNNrSVAM8aK82Etmf6QaVmpAP6LnHVub4ol3+bJ4dp72ki BpstT9rRYu6esEoD9xS3EtQt3K3PogKHb4FFv2rjaxmbccV8DYT3EOXCH2jP9Jh6Fgpq /dfsj2GTPjyDzb2Z1CD7VDAiSvvd5hjK+y9/db2FYSrNP5pVNJEDkl7OpA22jRCrFQwo 5OUjaclXRWJVtY8kSRnCFs+VE98UUR1QkAoY4t5uFj48vzfMm1VLbeZIriF+90fGC+XG Rxtvk9FJclroXO2hSGMh4/H7Xu/9rJT65xKGJ7/643DlpBBeSifgWOPta+w0ifIK5wRz Rofw== X-Gm-Message-State: AOAM532HbGoRSEoUk+GYW65UfBO7Q1iOxlbIhe7m+qY0+2jEI0IdIiKl ey9i48BUS+wIac8f5uJA1tgP8V2VS/s2Ig== X-Google-Smtp-Source: ABdhPJy+0qCzeshqbE94sp6OiExupY1ikCrzg73yT5Codq7SN4HOjdMJs9UkHMb8GCdz5AgaBy/wWQ== X-Received: by 2002:a17:90a:203:: with SMTP id c3mr6022229pjc.149.1601704617720; Fri, 02 Oct 2020 22:56:57 -0700 (PDT) Received: from localhost.localdomain ([122.171.168.96]) by smtp.gmail.com with ESMTPSA id 125sm4106664pff.59.2020.10.02.22.56.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 22:56:57 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com Subject: [PATCH V5 05/12] xfs: Check for extent overflow when adding/removing dir entries Date: Sat, 3 Oct 2020 11:26:26 +0530 Message-Id: <20201003055633.9379-6-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201003055633.9379-1-chandanrlinux@gmail.com> References: <20201003055633.9379-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Directory entry addition/removal can cause the following, 1. Data block can be added/removed. A new extent can cause extent count to increase by 1. 2. Free disk block can be added/removed. Same behaviour as described above for Data block. 3. Dabtree blocks. XFS_DA_NODE_MAXDEPTH blocks can be added. Each of these can be new extents. Hence extent count can increase by XFS_DA_NODE_MAXDEPTH. Reviewed-by: Darrick J. Wong 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 49624973eecc..f347b1911d9c 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -1159,6 +1159,11 @@ xfs_create( if (error) goto out_trans_cancel; + error = xfs_iext_count_may_overflow(dp, XFS_DATA_FORK, + XFS_IEXT_DIR_MANIP_CNT(mp)); + if (error) + goto out_trans_cancel; + /* * A newly created regular or special file just has one directory * entry pointing to them, but a directory also the "." entry @@ -1375,6 +1380,11 @@ xfs_link( xfs_trans_ijoin(tp, sip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, tdp, XFS_ILOCK_EXCL); + error = xfs_iext_count_may_overflow(tdp, XFS_DATA_FORK, + XFS_IEXT_DIR_MANIP_CNT(mp)); + if (error) + goto error_return; + /* * If we are using project inheritance, we only allow hard link * creation in our tree when the project IDs are the same; else @@ -2850,6 +2860,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. */ @@ -3210,6 +3225,18 @@ xfs_rename( if (wip) xfs_trans_ijoin(tp, wip, XFS_ILOCK_EXCL); + error = xfs_iext_count_may_overflow(src_dp, XFS_DATA_FORK, + XFS_IEXT_DIR_MANIP_CNT(mp)); + if (error) + goto out_trans_cancel; + + if (target_ip == NULL) { + error = xfs_iext_count_may_overflow(target_dp, XFS_DATA_FORK, + XFS_IEXT_DIR_MANIP_CNT(mp)); + if (error) + goto out_trans_cancel; + } + /* * If we are using project inheritance, we only allow renames * into our tree when the project IDs are the same; else the diff --git a/fs/xfs/xfs_symlink.c b/fs/xfs/xfs_symlink.c index 8e88a7ca387e..581a4032a817 100644 --- a/fs/xfs/xfs_symlink.c +++ b/fs/xfs/xfs_symlink.c @@ -220,6 +220,11 @@ xfs_symlink( if (error) goto out_trans_cancel; + error = xfs_iext_count_may_overflow(dp, XFS_DATA_FORK, + XFS_IEXT_DIR_MANIP_CNT(mp)); + if (error) + goto out_trans_cancel; + /* * Allocate an inode for the symlink. */ From patchwork Sat Oct 3 05:56:27 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: 11815071 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 48A836CA for ; Sat, 3 Oct 2020 05:57:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2AC80206F8 for ; Sat, 3 Oct 2020 05:57:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qXya0zxu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725765AbgJCF5B (ORCPT ); Sat, 3 Oct 2020 01:57:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725446AbgJCF5B (ORCPT ); Sat, 3 Oct 2020 01:57:01 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDEBEC0613D0 for ; Fri, 2 Oct 2020 22:57:00 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id u3so2261528pjr.3 for ; Fri, 02 Oct 2020 22:57:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=syOqEuploIW5wOLjFtUhHHVglk6+YbYMa9cQ0Bzwmu0=; b=qXya0zxu5tpJK2h8gsQZKs00ilESCtgL6aITUgVnJ9xFobTNdzoL64HAkvnqY3vqw1 4oyT9MHCfpjTGRtM3eI14NRtrDkTJxgrWqeL4Jn6BNEg6ZJpnoLnX+/FKfOKqtdNXKXm pV3vUpZ5Gwf+rbsg8/02W/nQzKOZs1O9Px+Q3aIjN5k0k8g5x+8StX+4W10ytx6PzL/P H9Jwwj2aDa7Y2+ZK5PLLBxYIjl+W0sKghEvSP1dyY86IqqhA/Yn7vyJm4jsDqdo/cor2 DDEWJGNtX/qntodVE/WKhT/cSboapssVup3xse8wTVkHoEyd39ObYUPu5BHWhMg2Xu/+ QPdw== 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=syOqEuploIW5wOLjFtUhHHVglk6+YbYMa9cQ0Bzwmu0=; b=le1lNJHTRMgmQFi+Blbcueajbn5ACAQHpYuYlGSF9yk+8y1KauYzfA8N0r+3PgS92r yiBVFMjfQQA0OJ1CJrG22yCW7W8AWr2nDOYXSjn457DXhTexVWufpZVwXA5coKSrLrFY G6EM6eWugiUf1LI4C2pEph7Z/GQ1tQNj9Wt/Zs8ZRG20un0K831Rw+kOfB9g0v0xKCRt FWtyQP4Coiz930h3m4igWG3nuzWLDzosVzZtXR1tpAf2eDEr+0tEth1c2xwJRZmNJqEm ws1hdgYdCt7VBskxMjbbkSYhgonjFQAirxWIu9FrkIHMnB25X507CSdtWcFwaoqYm9TS kZ4g== X-Gm-Message-State: AOAM530UNYlHEO1EGvDL5D4XQjeu45QH3ci4Hk4NNemeqSiR7dif1jHY JQ8CcrTqAiuolsSjfBZpweYym8XkakWcqg== X-Google-Smtp-Source: ABdhPJwbM7bUqez4OJdUF+rXXPpHauZm3Gx+1/tim8KgTPUjIFJOYW51LlLpiny2kvyr7np8MKtV0g== X-Received: by 2002:a17:90a:6a4e:: with SMTP id d14mr5995398pjm.63.1601704620088; Fri, 02 Oct 2020 22:57:00 -0700 (PDT) Received: from localhost.localdomain ([122.171.168.96]) by smtp.gmail.com with ESMTPSA id 125sm4106664pff.59.2020.10.02.22.56.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 22:56:59 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com Subject: [PATCH V5 06/12] xfs: Check for extent overflow when writing to unwritten extent Date: Sat, 3 Oct 2020 11:26:27 +0530 Message-Id: <20201003055633.9379-7-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201003055633.9379-1-chandanrlinux@gmail.com> References: <20201003055633.9379-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 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 Sat Oct 3 05:56:28 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: 11815073 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 1E1536CA for ; Sat, 3 Oct 2020 05:57:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 05F3E2072E for ; Sat, 3 Oct 2020 05:57:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FlQM5MGp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725766AbgJCF5D (ORCPT ); Sat, 3 Oct 2020 01:57:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725446AbgJCF5D (ORCPT ); Sat, 3 Oct 2020 01:57:03 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67C04C0613D0 for ; Fri, 2 Oct 2020 22:57:03 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id t23so1687512pji.0 for ; Fri, 02 Oct 2020 22:57:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ybzMGAH7mRYLjz5sy5yNWonaXyIH8jR0aIDyNXY08k0=; b=FlQM5MGp8crSuuMUruutVJ8KJc8FWX7FqcAx007+gCnAufkJiBAJp/vnmSTNPLeGwb AHnjPpfhdc6A/b3zUNtVkgXlnVS7+hwpqJqbAdkNQex15Swhrh8F70wlS5jJlKuXJAob es1sjp+BTXH9ZvfyaEItpv+Sk4+HBKoTZd+hZMIvcIuNd4YKaV4HJJ8acPk+YiajO3ok XoYOM+hvjbZjToWuWyWou8G/0ra2hZxM4qh7GtTZl5Ug5qwKQ1Ne54uS9/W/9PdDeCd/ aSFoP4bcVdazSKdIM+IH2j20QJiQfNiVr++c9tRiVXnF/tMS7i0tdn/9SlaVRJWkBs4Q 1LGw== 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=ybzMGAH7mRYLjz5sy5yNWonaXyIH8jR0aIDyNXY08k0=; b=QLYgaqvuyHZZs7ooDhE8UFM1/LO8vYaoN8fwaffItY0Tj5JFdD/mPzs4FGqnhe9dhZ wpiR25ncvYRwffCGqMzq5md2qqECkuvD1fj20P4unp5dUxqgzDQtnQLS/BsmWdUCD8RU JE+hjfOsdkr46i9krm85fkqCAoid6v/3okNWPxOrRFDN2yVlufIVR8EAIn+vyV9GlvlR 8cVs7I+NIPhnmeyD/HdgaNE13CN1I21washgfz9nlL+GcTTwlUi/0Ujfv26dUaNBA/L3 SeUFnjVuM83NSXPcqZ1ufpu3f0iVjhi7Bkqz1j2Dh56LyBxOTILAKWL0NYYnlsQiHOwb Lyog== X-Gm-Message-State: AOAM533EB3gdbh/38MSrdEwgUBCpHXPbVjtNy6+vHidPmNapAPZzCLZ1 iNs0eZiRipSpivPrtirsGHwSbdNrwJgZbg== X-Google-Smtp-Source: ABdhPJzQ9s9azyOzP8WSpmQszetstX1Y+UyFHc00XxRx9cMNFRas+b6gEy7NfFsFOssLV73iTN4Zkg== X-Received: by 2002:a17:90a:ff17:: with SMTP id ce23mr1073653pjb.221.1601704622504; Fri, 02 Oct 2020 22:57:02 -0700 (PDT) Received: from localhost.localdomain ([122.171.168.96]) by smtp.gmail.com with ESMTPSA id 125sm4106664pff.59.2020.10.02.22.57.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 22:57:01 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com Subject: [PATCH V5 07/12] xfs: Check for extent overflow when moving extent from cow to data fork Date: Sat, 3 Oct 2020 11:26:28 +0530 Message-Id: <20201003055633.9379-8-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201003055633.9379-1-chandanrlinux@gmail.com> References: <20201003055633.9379-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 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 Sat Oct 3 05:56:29 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: 11815075 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 988F66CA for ; Sat, 3 Oct 2020 05:57:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7D96F2072E for ; Sat, 3 Oct 2020 05:57:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cr9k1X6c" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725767AbgJCF5F (ORCPT ); Sat, 3 Oct 2020 01:57:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725446AbgJCF5F (ORCPT ); Sat, 3 Oct 2020 01:57:05 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A096AC0613D0 for ; Fri, 2 Oct 2020 22:57:05 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id p21so2460201pju.0 for ; Fri, 02 Oct 2020 22:57:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=druk7Lat4GoRfwFJZReJkIQMKuIUdAgXOVtXjP44X6M=; b=cr9k1X6cwssjwh/97koyagFcsOmnegJ+Rsw1LBNeRBKHaghp3w2hdnkds35s1gCEKx q8zpOHUtYln4rhMxYjW0M2lYR95oNQvlYQmx3tPzx3PZZytHcIkxq80UMv1UetAFk5SJ Ii95sVpL9IcY+jjC9m7hey4vHkjwl6hgQWDuo+NeJfyGQ3/JEWYOF9Jjq2R7rkRMIuXA 2CPbQTZoNxwm0ZIEaEtwyHMnoidFRtniovvDHhncWCkgmcYTwpeHuMVaGuabehRoD2WG JGgjt9CA9cnoQze989eBAta4dSA48nf2xngAat9B8ahpQI5sTwAS0jfjEJg21r6W5vwW IQVw== 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=druk7Lat4GoRfwFJZReJkIQMKuIUdAgXOVtXjP44X6M=; b=UAdB4jtxw1CG6MieJX2qtk8E06oEuz5y97fx3A+on+7Vaw+E3hHue8y6sg+F+C28QK MGOvsJ7/Zcc7+Ane+h4dLRiEJxWKzmYQmlGBmy3BHcphpAlGifeMWrC7+IbIOFrVxgYO kSmLrrZFY+tpJPG3ylQw6yhyQ6oiHky1YayWn1rdgGnpPWIigp77+wYddxw/lM78lxaZ BY4Ng0Gc7tuXPqj9xxArNqmoyhbtzriawtW79iv7cYU+d55SQG97SzExjk3rUXhDPb9q IWo4ngaJfV5JhWFXcEjcuj4kT5DmdACqr/gaqJZy2SUwKQM6p6Fp41L24IibjQIZLnFf SLAg== X-Gm-Message-State: AOAM532b2P+xFfTSQIGQ0pc+v1rLcG15vOHmX3ImWej8EjK2I1i1p9Ti 96wG1IVPWbYr28sq7VI0nR68+TZOMbCj3g== X-Google-Smtp-Source: ABdhPJz3XpBHgz0fmBus37T3bykLhJF7fURcULgyA7gNqzSxAIPshNupwnCBjqnZY2hRYAWwtXrISA== X-Received: by 2002:a17:90a:7486:: with SMTP id p6mr6406794pjk.162.1601704624891; Fri, 02 Oct 2020 22:57:04 -0700 (PDT) Received: from localhost.localdomain ([122.171.168.96]) by smtp.gmail.com with ESMTPSA id 125sm4106664pff.59.2020.10.02.22.57.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 22:57:04 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com Subject: [PATCH V5 08/12] xfs: Check for extent overflow when remapping an extent Date: Sat, 3 Oct 2020 11:26:29 +0530 Message-Id: <20201003055633.9379-9-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201003055633.9379-1-chandanrlinux@gmail.com> References: <20201003055633.9379-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: Darrick J. Wong Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_inode_fork.h | 15 +++++++++++++++ fs/xfs/xfs_reflink.c | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index b99e67e7b59b..ded3c1b56c94 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -87,6 +87,21 @@ struct xfs_ifork { */ #define XFS_IEXT_REFLINK_END_COW_CNT (2) +/* + * 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. + */ +#define XFS_IEXT_REFLINK_REMAP_CNT(smap_real, dmap_written) \ + (((smap_real) ? 1 : 0) + ((dmap_written) ? 1 : 0)) + /* * Fork handling. */ diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index 4f0198f636ad..c9f9ff68b5bb 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -1099,6 +1099,11 @@ xfs_reflink_remap_extent( goto out_cancel; } + error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + XFS_IEXT_REFLINK_REMAP_CNT(smap_real, dmap_written)); + if (error) + goto out_cancel; + if (smap_real) { /* * If the extent we're unmapping is backed by storage (written From patchwork Sat Oct 3 05:56:30 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: 11815077 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 D6FF76CA for ; Sat, 3 Oct 2020 05:57:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB1B6206F8 for ; Sat, 3 Oct 2020 05:57:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="W6VUFZBa" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725770AbgJCF5I (ORCPT ); Sat, 3 Oct 2020 01:57:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725446AbgJCF5I (ORCPT ); Sat, 3 Oct 2020 01:57:08 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BBC3C0613D0 for ; Fri, 2 Oct 2020 22:57:08 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id f18so2926752pfa.10 for ; Fri, 02 Oct 2020 22:57:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ywwxaWegq7wJFWe6P4AjCvm9F/012YEjv+rllIjHHJo=; b=W6VUFZBaJLki0e8im2GEQAu6rAW56R4UYPRRVZgCyR9ydbMNb6Rr9L26zs5TxRQcxP sRBPWDMO45HvbKBBNJFifqqjhNhmrIvr4Aq9ESGkkVnYBGb6CYpXJynRwVgSnXH/4K8J EYm8KlU0886LXaAIhgNFAIb6AtcGLD1nd+iSChWj1moJ7Q6hDCxAiA718FE6KyshvLOb EVUyoYD8yO0LbyrEA/gJMYFT/TWUygbOzrX69KWGWjj+ss5n1octS3uJuw+F85nbngqS th8EraUXc+++p9Yn89ZxFVNL2GcYUF1+TWn4QEpvP6nX5JanICZwoRY//+r+8DgNDdDs NfQw== 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=ywwxaWegq7wJFWe6P4AjCvm9F/012YEjv+rllIjHHJo=; b=K2UP3AkpO5upkwYkbpepwJ8nbfhVXPPg8zkHqAVzZNiDX4Vv61TCW8QvcbMGwWeotX b8bnrXAQGSSxo92YqVq+iAmAOv9KE7DLwjM6pmYdpwJrH5BCpRsdELfsTArL8mgpIIie oABDK1ijyudEbdxKgemoPdYswOHQ2IGVQpacYyGQxITpVODyOlx68IlHulTjuNvRDhun r58R756AhGkEjsYbmBJsB4CX/fG70PB1Bxawmb/vHhl19YB98lXIXoiJEUG8BoXpqzmu GoHp+Ibu9VlXEfNPycRbosTKqOuJLoQx20AGfZk0LG8YAk+bm42/PMkS/BT0pePheyCU rNVg== X-Gm-Message-State: AOAM5323CxvZy8muJIP6VKOwaqC5UgW+1jwzME9lVqrjLBd/Jn8uZEB3 OPLvg54gK8LUGfftd2wAnAQjqv9qWRMA/Q== X-Google-Smtp-Source: ABdhPJzV8VjzS3zaLNxsexT/PCOyab0ma0E/wtGUzFbURW2/4oMO6BP9ID24TmpFcjQSfRlYTlCXWg== X-Received: by 2002:a63:524c:: with SMTP id s12mr5126116pgl.287.1601704627233; Fri, 02 Oct 2020 22:57:07 -0700 (PDT) Received: from localhost.localdomain ([122.171.168.96]) by smtp.gmail.com with ESMTPSA id 125sm4106664pff.59.2020.10.02.22.57.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 22:57:06 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com Subject: [PATCH V5 09/12] xfs: Check for extent overflow when swapping extents Date: Sat, 3 Oct 2020 11:26:30 +0530 Message-Id: <20201003055633.9379-10-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201003055633.9379-1-chandanrlinux@gmail.com> References: <20201003055633.9379-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. Signed-off-by: Chandan Babu R Reviewed-by: Darrick J. Wong --- 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 ded3c1b56c94..837c01595439 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -102,6 +102,13 @@ struct xfs_ifork { #define XFS_IEXT_REFLINK_REMAP_CNT(smap_real, dmap_written) \ (((smap_real) ? 1 : 0) + ((dmap_written) ? 1 : 0)) +/* + * 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 Sat Oct 3 05:56:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11815079 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 1C8F16CB for ; Sat, 3 Oct 2020 05:57:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 01C732072E for ; Sat, 3 Oct 2020 05:57:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tpsohEN0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725772AbgJCF5K (ORCPT ); Sat, 3 Oct 2020 01:57:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725446AbgJCF5K (ORCPT ); Sat, 3 Oct 2020 01:57:10 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6070CC0613D0 for ; Fri, 2 Oct 2020 22:57:10 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id i3so2257844pjz.4 for ; Fri, 02 Oct 2020 22:57:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+tJN9ELT8vGh3ju1QQP8XSdKwFEEVPot2c6hJZSbnYU=; b=tpsohEN0oHpuOCsDu4I5UoV67+sbgajTkQ+y07GZ+B9rKKc0XTflVlZPryNMJfcKAJ 5Cc5hiIzJmisTc/zPWYar4ew/DGf5CPMCQoiPME4PuaPdVXPvbrHTo71qxzrTJzxkak5 fK3iQTtCAJe85oQkQqX7tNtUK8ZHs4qYDA1RqG58nHaDlMk2VuJDmy0fUG93VpzjugEJ o9MsDl7EedsXDbzWPn+YKPnkPzIfzZcmF4uhGhKL+jdSzKygVmttBjbKz383dxsJY+5z UUTzyOC5azyQzEV7aGmDq2b9DhyOmhAB2XPJgBsiW5zNhTS/+WbVtMKFxxMM2VNpoaTp Dw2Q== 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=+tJN9ELT8vGh3ju1QQP8XSdKwFEEVPot2c6hJZSbnYU=; b=J21qJaK5cH84w+o6PN5e7hwxeaOmy3kWhLIv/Ce4zp5Lu2I9tXIjDM4IQCKBQIhkN3 XBIA0E3O5+4bvGLR0meMlhpO5Mab/LoRyZbu2QcIXCXW/eKR94MJ9mwcrUoRvR8cHZv2 fbywdCvLrTe9BQ2obxUs5WkOVDa0uwCC3zAWG436mdEeBC8Hi+3U5emObXcrQYrerdqe 0HTCaO5ii7KmG8Lg8u2g7rulmM24tHSQnnwt/yi4nGas8ly76kEC452cs7BFeS/TPvOe ugOxju1F8/gnY5pbJmHYnOuJx6F7AzYh1uUbsSKuv2GWpvLCsvuk9/BH65WR/1Is8Znu 5oFg== X-Gm-Message-State: AOAM533KCfLYLU36s3YRu5jM+WWK1qvXA69idFk4s8Yl00NdWwKYduKe pzPHJPf2PyddCocGMZPaFl6/novjkni0uQ== X-Google-Smtp-Source: ABdhPJysOrmmzMhxiEKRuqr7WV5Y0sNugGgyCapWqWx8ZX+bBZNaXsWEi8HbekqGtQYYLuM3pzGBFw== X-Received: by 2002:a17:90b:4204:: with SMTP id iw4mr6302258pjb.175.1601704629581; Fri, 02 Oct 2020 22:57:09 -0700 (PDT) Received: from localhost.localdomain ([122.171.168.96]) by smtp.gmail.com with ESMTPSA id 125sm4106664pff.59.2020.10.02.22.57.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 22:57:09 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com Subject: [PATCH V5 10/12] xfs: Introduce error injection to reduce maximum inode fork extent count Date: Sat, 3 Oct 2020 11:26:31 +0530 Message-Id: <20201003055633.9379-11-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201003055633.9379-1-chandanrlinux@gmail.com> References: <20201003055633.9379-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org This commit adds XFS_ERRTAG_REDUCE_MAX_IEXTENTS error tag which enables userspace programs to test "Inode fork extent count overflow detection" by reducing maximum possible inode fork extent count to 10. Signed-off-by: Chandan Babu R Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_errortag.h | 4 +++- fs/xfs/libxfs/xfs_inode_fork.c | 4 ++++ fs/xfs/xfs_error.c | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_errortag.h b/fs/xfs/libxfs/xfs_errortag.h index 53b305dea381..1c56fcceeea6 100644 --- a/fs/xfs/libxfs/xfs_errortag.h +++ b/fs/xfs/libxfs/xfs_errortag.h @@ -56,7 +56,8 @@ #define XFS_ERRTAG_FORCE_SUMMARY_RECALC 33 #define XFS_ERRTAG_IUNLINK_FALLBACK 34 #define XFS_ERRTAG_BUF_IOERROR 35 -#define XFS_ERRTAG_MAX 36 +#define XFS_ERRTAG_REDUCE_MAX_IEXTENTS 36 +#define XFS_ERRTAG_MAX 37 /* * Random factors for above tags, 1 means always, 2 means 1/2 time, etc. @@ -97,5 +98,6 @@ #define XFS_RANDOM_FORCE_SUMMARY_RECALC 1 #define XFS_RANDOM_IUNLINK_FALLBACK (XFS_RANDOM_DEFAULT/10) #define XFS_RANDOM_BUF_IOERROR XFS_RANDOM_DEFAULT +#define XFS_RANDOM_REDUCE_MAX_IEXTENTS 1 #endif /* __XFS_ERRORTAG_H_ */ diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c index 8d48716547e5..e080d7e07643 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.c +++ b/fs/xfs/libxfs/xfs_inode_fork.c @@ -24,6 +24,7 @@ #include "xfs_dir2_priv.h" #include "xfs_attr_leaf.h" #include "xfs_types.h" +#include "xfs_errortag.h" kmem_zone_t *xfs_ifork_zone; @@ -745,6 +746,9 @@ xfs_iext_count_may_overflow( max_exts = (whichfork == XFS_ATTR_FORK) ? MAXAEXTNUM : MAXEXTNUM; + if (XFS_TEST_ERROR(false, ip->i_mount, XFS_ERRTAG_REDUCE_MAX_IEXTENTS)) + max_exts = 10; + nr_exts = ifp->if_nextents + nr_to_add; if (nr_exts < ifp->if_nextents || nr_exts > max_exts) return -EFBIG; diff --git a/fs/xfs/xfs_error.c b/fs/xfs/xfs_error.c index 7f6e20899473..3780b118cc47 100644 --- a/fs/xfs/xfs_error.c +++ b/fs/xfs/xfs_error.c @@ -54,6 +54,7 @@ static unsigned int xfs_errortag_random_default[] = { XFS_RANDOM_FORCE_SUMMARY_RECALC, XFS_RANDOM_IUNLINK_FALLBACK, XFS_RANDOM_BUF_IOERROR, + XFS_RANDOM_REDUCE_MAX_IEXTENTS, }; struct xfs_errortag_attr { @@ -164,6 +165,7 @@ XFS_ERRORTAG_ATTR_RW(force_repair, XFS_ERRTAG_FORCE_SCRUB_REPAIR); XFS_ERRORTAG_ATTR_RW(bad_summary, XFS_ERRTAG_FORCE_SUMMARY_RECALC); XFS_ERRORTAG_ATTR_RW(iunlink_fallback, XFS_ERRTAG_IUNLINK_FALLBACK); XFS_ERRORTAG_ATTR_RW(buf_ioerror, XFS_ERRTAG_BUF_IOERROR); +XFS_ERRORTAG_ATTR_RW(reduce_max_iextents, XFS_ERRTAG_REDUCE_MAX_IEXTENTS); static struct attribute *xfs_errortag_attrs[] = { XFS_ERRORTAG_ATTR_LIST(noerror), @@ -202,6 +204,7 @@ static struct attribute *xfs_errortag_attrs[] = { XFS_ERRORTAG_ATTR_LIST(bad_summary), XFS_ERRORTAG_ATTR_LIST(iunlink_fallback), XFS_ERRORTAG_ATTR_LIST(buf_ioerror), + XFS_ERRORTAG_ATTR_LIST(reduce_max_iextents), NULL, }; From patchwork Sat Oct 3 05:56:32 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: 11815081 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 D36706CA for ; Sat, 3 Oct 2020 05:57:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B979D2072E for ; Sat, 3 Oct 2020 05:57:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RLv/ErL2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725777AbgJCF5N (ORCPT ); Sat, 3 Oct 2020 01:57:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725446AbgJCF5N (ORCPT ); Sat, 3 Oct 2020 01:57:13 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0489C0613D0 for ; Fri, 2 Oct 2020 22:57:12 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id nl2so460425pjb.1 for ; Fri, 02 Oct 2020 22:57:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3LvJc1UTVx+let4A8iQH95WDRcW3NxmNhVKSEog1EUE=; b=RLv/ErL2f4D1IJ/MN29VsR0x16GvcmB/ONc2VH8yGtmowDtzyyIMSE8cRM0VZ60J8c 4cq1NGyzRbnWtg8ZON84on/uGeOIk1nKfbP8RrJhx0Gcu6gdYooMbATsM1jWdzhe5UnZ O1kQBowxcltHzER3WLoF0neUYFHMasOJpnF4ugDQvq1Xh69vu9F635e/geoSaq2NSXX6 20x+foGK+IQbJWO61hxfY/JxkVXimm5c8xfWy8CzNto0O/t0IJDDJfzLFCZsfdl13b+e 1N6pBIwrL2ettw2lEgTgGlpnrwZkt37D7l+T/zZyd5F08J+zEeNu+BrkxWpetvV8S9d5 jdmg== 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=3LvJc1UTVx+let4A8iQH95WDRcW3NxmNhVKSEog1EUE=; b=O7RoEOGQMFJZRBhqLygmCLkz9H42Dw2HkAz32EnFKTuDMSF+hJD59nPyvinzsVOmOm esZU1xpqr+SuzZ1gNXMDCg+ROgqY04fVyZ80VZPlSj89uQUoitaoyFoRPxfDZd/764WO CgIrvvgGpol/6nzOBnMhNFgr64EkEwTvpa/0bvTyZ5WZHUs3cpeFxKpmyxVt7xHQ4TvA hgr8Bwuq1zYRsCtAIqd9KJp2jqaT1+9eV1vQwkmy547cgOyBDJubolvn4UjDbckHhk1J zI5nf5D5KHeaPfKdyUXD5+kVv9lmKdbrNpfDnas3uYISitbfOjQHfad0xpAeQGIubLHM OkUg== X-Gm-Message-State: AOAM533TQbJGChCI9mYcopIcwrIZwwh0+4WYB4YiPRgAF+c9W0mjkLNE SSaITf9/saX1JWl996QJghSEzkALcT1vYA== X-Google-Smtp-Source: ABdhPJwgvVw0312+jWQmH5KO+qZJV0WUDoPhuzhlXuNa16KyLxAnxmdDTl9ZqjM22R1uyC/sds/V2g== X-Received: by 2002:a17:90a:b942:: with SMTP id f2mr6332980pjw.196.1601704631926; Fri, 02 Oct 2020 22:57:11 -0700 (PDT) Received: from localhost.localdomain ([122.171.168.96]) by smtp.gmail.com with ESMTPSA id 125sm4106664pff.59.2020.10.02.22.57.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 22:57:11 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com Subject: [PATCH V5 11/12] xfs: Set tp->t_firstblock only once during a transaction's lifetime Date: Sat, 3 Oct 2020 11:26:32 +0530 Message-Id: <20201003055633.9379-12-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201003055633.9379-1-chandanrlinux@gmail.com> References: <20201003055633.9379-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org tp->t_firstblock is supposed to hold the first fs block allocated by the transaction. There are two cases in the current code base where tp->t_firstblock is assigned a value unconditionally. This commit makes sure that we assign to tp->t_firstblock only if its current value is NULLFSBLOCK. Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_bmap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 51c2d2690f05..5156cbd476f2 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -724,7 +724,8 @@ xfs_bmap_extents_to_btree( */ ASSERT(tp->t_firstblock == NULLFSBLOCK || args.agno >= XFS_FSB_TO_AGNO(mp, tp->t_firstblock)); - tp->t_firstblock = args.fsbno; + if (tp->t_firstblock == NULLFSBLOCK) + tp->t_firstblock = args.fsbno; cur->bc_ino.allocated++; ip->i_d.di_nblocks++; xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_BCOUNT, 1L); @@ -875,7 +876,8 @@ xfs_bmap_local_to_extents( /* Can't fail, the space was reserved. */ ASSERT(args.fsbno != NULLFSBLOCK); ASSERT(args.len == 1); - tp->t_firstblock = args.fsbno; + if (tp->t_firstblock == NULLFSBLOCK) + tp->t_firstblock = args.fsbno; error = xfs_trans_get_buf(tp, args.mp->m_ddev_targp, XFS_FSB_TO_DADDR(args.mp, args.fsbno), args.mp->m_bsize, 0, &bp); From patchwork Sat Oct 3 05:56:33 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: 11815083 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 23A266CA for ; Sat, 3 Oct 2020 05:57:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 04B682072E for ; Sat, 3 Oct 2020 05:57:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eflDt7FA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725778AbgJCF5P (ORCPT ); Sat, 3 Oct 2020 01:57:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725446AbgJCF5P (ORCPT ); Sat, 3 Oct 2020 01:57:15 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6088FC0613D0 for ; Fri, 2 Oct 2020 22:57:15 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id d9so2948664pfd.3 for ; Fri, 02 Oct 2020 22:57:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tXr55mjl3UmO57eYfVCWv0w8/2eCgxaYhZvrPvTy4lM=; b=eflDt7FAvgy/Btb2DiN/b/Y/lg16RZsySm5ZK46LOrS70imOzfBrG8LRQTCIhOA7jy S01Jj4p58Fbyx7t3VBKbgLTm9GimyJb+vWt/sUw92Oj7KHjB6kCNMD+IPgglWJX9rrm9 0N/qHmVlU+9DSg/urWBwcnxlD6l9abP7bgVwhG+fh/qTpstAhShfjRKEOvlPsyFfnc0l jMCeJu2T9WccW4C/kFqzkPvds2DdQl1AuOegucGr3L9bJ3UW3e2kf6sZEQjPXqKO6FIH m4N7Ym3ORjZn8rpJNJU9C6ELH7qibKxWnArpRbICSgwRZYazGXz0+oT69TW5VVr32B+A IzqQ== 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=tXr55mjl3UmO57eYfVCWv0w8/2eCgxaYhZvrPvTy4lM=; b=UAbl37es8Kws4CP2oCXAUx2DC6AaiJpuxFTfYj4fnEMG+gj3A/llR/tKex7MUUL6Ky 087v1mcWvSMBeeO5IxpMC8OL2P8HbjRpR49HzYeggPKWlYuAOT0XvI8+jwZFJF+6W6iI A2a5YKAoZZ/jDXeMhbxXKjeQl7ZadVtRe/PKXXrb6cgqpVsblCjz7wYHcySOjI1pHvhe GJr3qxPRZZ2okVC5/eDITZ3VfnhJM8watpd6YdWuf3rdQFCym1rP3x8mPMtrismdf912 Ix3PUvUwPRNxz5FJfLeq+qgPnEkgdLxGVk33LaG+tjoOECBzM9J3iv7887SyepOUsKu7 +Kaw== X-Gm-Message-State: AOAM533Y7KU/lmrfToe5OJAAts/QAB3vtwz0cfx+VdQHXdAZECtdYCOR W+Gw0wXrW6+p2RaHLQOQFVrCP42ZWLpyHQ== X-Google-Smtp-Source: ABdhPJwh6dCXjowmQJlfMRSsXeD5XJ9E+gDbpLroRSNsxv+msCcfv4wU3/6vTmeqhVR1hRq0zNL/nw== X-Received: by 2002:a62:b40c:0:b029:142:6a8f:c2f8 with SMTP id h12-20020a62b40c0000b02901426a8fc2f8mr6325987pfn.32.1601704634437; Fri, 02 Oct 2020 22:57:14 -0700 (PDT) Received: from localhost.localdomain ([122.171.168.96]) by smtp.gmail.com with ESMTPSA id 125sm4106664pff.59.2020.10.02.22.57.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 22:57:13 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com Subject: [PATCH V5 12/12] xfs: Introduce error injection to allocate only minlen size extents for files Date: Sat, 3 Oct 2020 11:26:33 +0530 Message-Id: <20201003055633.9379-13-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201003055633.9379-1-chandanrlinux@gmail.com> References: <20201003055633.9379-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org This commit adds XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT error tag which helps userspace test programs to get xfs_bmap_btalloc() to always allocate minlen sized extents. This is required for test programs which need a guarantee that minlen extents allocated for a file do not get merged with their existing neighbours in the inode's BMBT. "Inode fork extent overflow check" for Directories, Xattrs and extension of realtime inodes need this since the file offset at which the extents are being allocated cannot be explicitly controlled from userspace. One way to use this error tag is to, 1. Consume all of the free space by sequentially writing to a file. 2. Punch alternate blocks of the file. This causes CNTBT to contain sufficient number of one block sized extent records. 3. Inject XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT error tag. After step 3, xfs_bmap_btalloc() will issue space allocation requests for minlen sized extents only. ENOSPC error code is returned to userspace when there aren't any "one block sized" extents left in any of the AGs. Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_alloc.c | 46 ++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_alloc.h | 1 + fs/xfs/libxfs/xfs_bmap.c | 26 ++++++++++++++------ fs/xfs/libxfs/xfs_errortag.h | 4 +++- fs/xfs/xfs_error.c | 3 +++ 5 files changed, 72 insertions(+), 8 deletions(-) diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c index 852b536551b5..d8d8ab1478db 100644 --- a/fs/xfs/libxfs/xfs_alloc.c +++ b/fs/xfs/libxfs/xfs_alloc.c @@ -2473,6 +2473,45 @@ xfs_defer_agfl_block( xfs_defer_add(tp, XFS_DEFER_OPS_TYPE_AGFL_FREE, &new->xefi_list); } +STATIC int +minlen_freespace_available( + struct xfs_alloc_arg *args, + struct xfs_buf *agbp, + int *stat) +{ + xfs_btree_cur_t *cnt_cur; + xfs_agblock_t fbno; + xfs_extlen_t flen; + int btree_error = XFS_BTREE_NOERROR; + 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) { + btree_error = XFS_BTREE_ERROR; + goto out; + } + + ASSERT(*stat == 1); + + error = xfs_alloc_get_rec(cnt_cur, &fbno, &flen, stat); + if (error) { + btree_error = XFS_BTREE_ERROR; + goto out; + } + + if (flen == args->minlen) + *stat = 1; + else + *stat = 0; + +out: + xfs_btree_del_cursor(cnt_cur, btree_error); + + return error; +} + /* * Decide whether to use this allocation group for this allocation. * If so, fix up the btree freelist's size. @@ -2490,6 +2529,7 @@ xfs_alloc_fix_freelist( struct xfs_alloc_arg targs; /* local allocation arguments */ xfs_agblock_t bno; /* freelist block */ xfs_extlen_t need; /* total blocks needed in freelist */ + int i; int error = 0; /* deferred ops (AGFL block frees) require permanent transactions */ @@ -2544,6 +2584,12 @@ xfs_alloc_fix_freelist( if (!xfs_alloc_space_available(args, need, flags)) goto out_agbp_relse; + if (args->alloc_minlen_only) { + error = minlen_freespace_available(args, agbp, &i); + if (error || !i) + goto out_agbp_relse; + } + /* * 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..1d04089b7fb4 100644 --- a/fs/xfs/libxfs/xfs_alloc.h +++ b/fs/xfs/libxfs/xfs_alloc.h @@ -75,6 +75,7 @@ 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 */ + bool alloc_minlen_only; } xfs_alloc_arg_t; /* diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 5156cbd476f2..fab4097e7492 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -3510,12 +3510,19 @@ xfs_bmap_btalloc( ASSERT(ap->length); } + memset(&args, 0, sizeof(args)); + + args.alloc_minlen_only = XFS_TEST_ERROR(false, mp, + XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT); nullfb = ap->tp->t_firstblock == NULLFSBLOCK; fb_agno = nullfb ? NULLAGNUMBER : XFS_FSB_TO_AGNO(mp, ap->tp->t_firstblock); if (nullfb) { - if ((ap->datatype & XFS_ALLOC_USERDATA) && + if (args.alloc_minlen_only) { + ag = 0; + ap->blkno = XFS_AGB_TO_FSB(mp, ag, 0); + } else if ((ap->datatype & XFS_ALLOC_USERDATA) && xfs_inode_is_filestream(ap->ip)) { ag = xfs_filestream_lookup_ag(ap->ip); ag = (ag != NULLAGNUMBER) ? ag : 0; @@ -3523,10 +3530,12 @@ xfs_bmap_btalloc( } else { ap->blkno = XFS_INO_TO_FSB(mp, ap->ip->i_ino); } - } else + } else { ap->blkno = ap->tp->t_firstblock; + } - xfs_bmap_adjacent(ap); + if (!args.alloc_minlen_only) + xfs_bmap_adjacent(ap); /* * If allowed, use ap->blkno; otherwise must use firstblock since @@ -3540,7 +3549,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; @@ -3549,7 +3557,10 @@ xfs_bmap_btalloc( /* Trim the allocation back to the maximum an AG can fit. */ args.maxlen = min(ap->length, mp->m_ag_max_usable); blen = 0; - if (nullfb) { + if (args.alloc_minlen_only) { + args.type = XFS_ALLOCTYPE_START_AG; + args.total = args.minlen = args.maxlen = ap->minlen; + } else if (nullfb) { /* * Search for an allocation group with a single extent large * enough for the request. If one isn't found, then adjust @@ -3595,7 +3606,8 @@ xfs_bmap_btalloc( * is only set if the allocation length is >= the stripe unit and the * allocation offset is at the end of file. */ - if (!(ap->tp->t_flags & XFS_TRANS_LOWMODE) && ap->aeof) { + if (!(ap->tp->t_flags & XFS_TRANS_LOWMODE) && ap->aeof && + !args.alloc_minlen_only) { if (!ap->offset) { args.alignment = stripe_align; atype = args.type; @@ -3681,7 +3693,7 @@ xfs_bmap_btalloc( if ((error = xfs_alloc_vextent(&args))) return error; } - if (args.fsbno == NULLFSBLOCK && nullfb) { + if (args.fsbno == NULLFSBLOCK && nullfb && !args.alloc_minlen_only) { args.fsbno = 0; args.type = XFS_ALLOCTYPE_FIRST_AG; args.total = ap->minlen; 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..028560bb596a 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, };