From patchwork Mon Nov 2 09:50:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11873273 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 A5964921 for ; Mon, 2 Nov 2020 09:51:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8022E22277 for ; Mon, 2 Nov 2020 09:51:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SzKFKBu1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728081AbgKBJvD (ORCPT ); Mon, 2 Nov 2020 04:51:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727992AbgKBJvC (ORCPT ); Mon, 2 Nov 2020 04:51:02 -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 CD1E0C0617A6 for ; Mon, 2 Nov 2020 01:51:02 -0800 (PST) Received: by mail-pl1-x643.google.com with SMTP id b12so6570814plr.4 for ; Mon, 02 Nov 2020 01:51: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=XmdKpghfLeanbz+IwL0BYKqdxi1X0QN/uaPdOmARGkM=; b=SzKFKBu1MJrLXgFAULn2BZrxah/HtiWyzrSD0PNGPomJahbX6Rn9+XR/RpYzf5s7sO +JOTNJO4gP/ZllBYPKBPhqdMUgZ0Z1DZ8Oow08YRJWQjDMhU6lxLu2xgkxJC+1azPoOr RW47uWNyqCgDx4+vM2ADzlQFlQynKKKh4fS8OIEiMeyH48pYfMzPX2THqHBOgeqjFHJ/ 9UheENCrUK4a7B2wSF/KB6zwUns/i9BH1GOB4rzodtY0mfU11BtalQmEG/Sp+E4XUeBB LOVi3ewJ62cZmPxy2d1/2dVZJqXKvIGD9M+zyVvbePiXpqEIMyTb9+Rl62LP59UhYi3D 3uUg== 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=stqmeuJZSUPv1yJFK884xuP0kfkhLe0VhMKjKOuKhr47uIKbFVvEFvFrVrLkf0U1YP Td6aGz0FyngBewKjHD1cSkH0gVzzYCYQODfsDyuD6dpJH1RFaW1Rxgvy5igj8M7zR2G2 5cV+EzhANmhnkRvCdnJy5ipOFDYeNo5boVarXOgTGNSwajJSLtjmdVFwKwEplU1RCELQ 9goPl8od/OBSCmhOsxxumepYTTlQf0FGS4wbHAKiLH8qn7HHitOrsPdalr1+ftcxoUEP nvDc2S57SXnJ2UB8yKksMHrc3oiJvlsfV0TGuVOMgMYbMDTfvD9ZOxNqkUq5exrJWLJN eLtw== X-Gm-Message-State: AOAM530mKrdm5vrttHvjpx7Oh8pQZMY09AchmJmSrqAJzRP5X2/Mgv1+ 3dO4nXQ18+eUHihV2yAXPLoy3K0Quzs= X-Google-Smtp-Source: ABdhPJxsYLJmzfzrpZnO/R4DoiaqWx6RNPP3b6mxAwEJYphXGSSQLcokzJg7dPVPctYMp74ZoJolOw== X-Received: by 2002:a17:902:758d:b029:d6:57ea:a434 with SMTP id j13-20020a170902758db02900d657eaa434mr19469844pll.83.1604310662107; Mon, 02 Nov 2020 01:51:02 -0800 (PST) Received: from localhost.localdomain ([122.179.32.56]) by smtp.gmail.com with ESMTPSA id x15sm467062pjh.21.2020.11.02.01.50.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2020 01:51:01 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, allison.henderson@oracle.com, Christoph Hellwig Subject: [PATCH V9 01/14] xfs: Add helper for checking per-inode extent count overflow Date: Mon, 2 Nov 2020 15:20:35 +0530 Message-Id: <20201102095048.100956-2-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201102095048.100956-1-chandanrlinux@gmail.com> References: <20201102095048.100956-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org XFS does not check for possible overflow of per-inode extent counter fields when adding extents to either data or attr fork. For e.g. 1. Insert 5 million xattrs (each having a value size of 255 bytes) and then delete 50% of them in an alternating manner. 2. On a 4k block sized XFS filesystem instance, the above causes 98511 extents to be created in the attr fork of the inode. xfsaild/loop0 2008 [003] 1475.127209: probe:xfs_inode_to_disk: (ffffffffa43fb6b0) if_nextents=98511 i_ino=131 3. The incore inode fork extent counter is a signed 32-bit quantity. However the on-disk extent counter is an unsigned 16-bit quantity and hence cannot hold 98511 extents. 4. The following incorrect value is stored in the attr extent counter, # xfs_db -f -c 'inode 131' -c 'print core.naextents' /dev/loop0 core.naextents = -32561 This commit adds a new helper function (i.e. xfs_iext_count_may_overflow()) to check for overflow of the per-inode data and xattr extent counters. Future patches will use this function to make sure that an FS operation won't cause the extent counter to overflow. Suggested-by: Darrick J. Wong Reviewed-by: Allison Henderson Reviewed-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_inode_fork.c | 23 +++++++++++++++++++++++ fs/xfs/libxfs/xfs_inode_fork.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c index 7575de5cecb1..8d48716547e5 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.c +++ b/fs/xfs/libxfs/xfs_inode_fork.c @@ -23,6 +23,7 @@ #include "xfs_da_btree.h" #include "xfs_dir2_priv.h" #include "xfs_attr_leaf.h" +#include "xfs_types.h" kmem_zone_t *xfs_ifork_zone; @@ -728,3 +729,25 @@ xfs_ifork_verify_local_attr( return 0; } + +int +xfs_iext_count_may_overflow( + struct xfs_inode *ip, + int whichfork, + int nr_to_add) +{ + struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork); + uint64_t max_exts; + uint64_t nr_exts; + + if (whichfork == XFS_COW_FORK) + return 0; + + max_exts = (whichfork == XFS_ATTR_FORK) ? MAXAEXTNUM : MAXEXTNUM; + + nr_exts = ifp->if_nextents + nr_to_add; + if (nr_exts < ifp->if_nextents || nr_exts > max_exts) + return -EFBIG; + + return 0; +} diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index a4953e95c4f3..0beb8e2a00be 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -172,5 +172,7 @@ extern void xfs_ifork_init_cow(struct xfs_inode *ip); int xfs_ifork_verify_local_data(struct xfs_inode *ip); int xfs_ifork_verify_local_attr(struct xfs_inode *ip); +int xfs_iext_count_may_overflow(struct xfs_inode *ip, int whichfork, + int nr_to_add); #endif /* __XFS_INODE_FORK_H__ */ From patchwork Mon Nov 2 09:50:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11873275 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 D1BC792A for ; Mon, 2 Nov 2020 09:51:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AF3E8222E8 for ; Mon, 2 Nov 2020 09:51:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="btcgKCh/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728132AbgKBJvG (ORCPT ); Mon, 2 Nov 2020 04:51:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727992AbgKBJvG (ORCPT ); Mon, 2 Nov 2020 04:51:06 -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 0A6B8C0617A6 for ; Mon, 2 Nov 2020 01:51:06 -0800 (PST) Received: by mail-pf1-x442.google.com with SMTP id a200so10625065pfa.10 for ; Mon, 02 Nov 2020 01:51:06 -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=btcgKCh/Ri2F87Ag56LIlkFu5ny37BEX/A1D8wpg8wpN9OaAxfT1LEO8I9G/bCfWV1 d2uk3fdnwd9YYeH0AcTkvp/Ki80OkAocNCYFoe64MjklyJiAf583dZAQ+/cPuZ5lt1ka gR8hu3+/AZZ+HWFivMZUi6SWI9S1DhOm4X4qWtL4VAQ0OOSKQ8Qq4c34YBCzSsgf2kXh dbWQvi0zYZpNs0AF7st4SZLbGVyIaaCbUqdTlqab8Y0BflPwEPllPYhNRDGcmYfyyoCe c0Mu5LFCKdgO49UzNG28ZvxG75OjGBoSkr1xPeq82eEWuwBFSs/2Ep1SDaViqr9ZC/4J aUvg== 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=MiHYdYsZXSI5ZveHA02x1XrrchiUpurjPuXtXdgbdYAwVxwoO5SG9wD3AwGROyV9FN qeblaNvWXqDG2ZA1IB+fKBZUZdDxu/VdqWxmgatiqfiamxnfLx70hFE8nbpQIXJ33UH8 4jmpOMCcGPaZPNfYv+3ah2ropVS43SSO8R0ItKo8GUP8ai6mWKLzTjeAWOq2uEnEA7lt +kMqpQ5PI/a6r+gsKscM3NGAlfix072qmb3BbcnBWLwmSmWF/2I9MjVotoFWJNQJuYFr VJ7sUfVUgmZKHsC/O1msAYOKbCz2BYNUuKsgSfwxhW/m4wZC4SA0J+j1nSqIgERxSMCv lV/g== X-Gm-Message-State: AOAM533S6hGWAvTi0bst7QJErZR+IWeZ904cedZnywWtBcBgNS2Wk4cV xGx+nGIbcS96kq2Vgr8mp1nzWLnrS1A= X-Google-Smtp-Source: ABdhPJx0H9csFFbsZ/CljtzXzZNgDjduxcGO4Fe9SGDiAryKTJx2JJl+9VmlLha3HUFCXV4rtVZ/KA== X-Received: by 2002:a62:19c8:0:b029:18a:ec5e:e68e with SMTP id 191-20020a6219c80000b029018aec5ee68emr4892495pfz.9.1604310665274; Mon, 02 Nov 2020 01:51:05 -0800 (PST) Received: from localhost.localdomain ([122.179.32.56]) by smtp.gmail.com with ESMTPSA id x15sm467062pjh.21.2020.11.02.01.51.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2020 01:51:04 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, allison.henderson@oracle.com, Christoph Hellwig Subject: [PATCH V9 02/14] xfs: Check for extent overflow when trivally adding a new extent Date: Mon, 2 Nov 2020 15:20:36 +0530 Message-Id: <20201102095048.100956-3-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201102095048.100956-1-chandanrlinux@gmail.com> References: <20201102095048.100956-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 Mon Nov 2 09:50:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11873279 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 E6E2E921 for ; Mon, 2 Nov 2020 09:51:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BE964222B9 for ; Mon, 2 Nov 2020 09:51:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ax04Y/2N" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728183AbgKBJvJ (ORCPT ); Mon, 2 Nov 2020 04:51:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727992AbgKBJvJ (ORCPT ); Mon, 2 Nov 2020 04:51:09 -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 1D7DAC0617A6 for ; Mon, 2 Nov 2020 01:51:09 -0800 (PST) Received: by mail-pf1-x444.google.com with SMTP id y14so10619422pfp.13 for ; Mon, 02 Nov 2020 01:51: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=Ttah+KnBauDQXA8r3dO7gvzvR5vDgdkbnCETl2BO3+U=; b=ax04Y/2NsE4dl88eZc4UiFtJxahzOP6+M4jyNmeYTdAOv7TULeclpuo8Ogms4QrCF5 M8FfB+U6iXP57gCdOy+8OsMaK+TKrweuAHoKZ5OGUS+pksn7+hPqmLh+u0PijXUQ1u87 f+E26VxhTy7c9PnpWEvf9ndPztTcbcxg9X26u0H3uVfjJJF8nPsA5xXSwZ0TULrK60Y2 9wfRpUgvVrhxd20v2yqby5pnnFuZnhOPg+k30SGQ6JR6NdldeY24y1tPPqNH17tUgrNB Mq3rtJSolL603lgmaitkb8vEp22Ba7JPtBIGzJ7q2yLe7D9+R1qAPAX7vqnBKvi/fuD2 zMbA== 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=m+QBCWQydhR8ATM34rqVl0beOVyWcheFe5CyKaZmAfc43gYyxRE+plWlBSBuxV9g6m Kqw+Y7ACBOc6RwZBL0H4u3f7hPtvOlzhAbuD4INLDtwJCW43sxYPxNQLUFuFbm2m/fiV 3QaowN9uodQaVkjXhqpgf7I3P+0JP27z3U0S9zU5ho4Pb3b+xExT/k8xFWXzXj8iEJpD pb+v9H7aiT73EhmIupw6UkuNvdq5lyA08Gdxah0OW3TQWE25b6vGCoNQ5DJbcuEtc1vy yFIhzfpJMTUnvwmhT07NOvr3jxk3v2E7sk1hI9x7LhJOmSTv7YNo+Ky1/TujA5kkgzkM P7YA== X-Gm-Message-State: AOAM530eM/IOoiT2vzmsTB0J5R5MW+VVnq427mkZRlhk7qYzKdJTxeol nqGaea0rRh4p3d1MyKu2/ymzaAbhskk= X-Google-Smtp-Source: ABdhPJyqbF9Y5Zy5HjymVfRmaQER+k5zxt4bSRbCrp5852/futohp36AoR3IFRa3ArHmINofcMiEAw== X-Received: by 2002:aa7:9501:0:b029:155:3b11:d5c4 with SMTP id b1-20020aa795010000b02901553b11d5c4mr21525690pfp.76.1604310668415; Mon, 02 Nov 2020 01:51:08 -0800 (PST) Received: from localhost.localdomain ([122.179.32.56]) by smtp.gmail.com with ESMTPSA id x15sm467062pjh.21.2020.11.02.01.51.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2020 01:51:07 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, allison.henderson@oracle.com, Christoph Hellwig Subject: [PATCH V9 03/14] xfs: Check for extent overflow when punching a hole Date: Mon, 2 Nov 2020 15:20:37 +0530 Message-Id: <20201102095048.100956-4-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201102095048.100956-1-chandanrlinux@gmail.com> References: <20201102095048.100956-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 Mon Nov 2 09:50:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11873281 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 F02B392A for ; Mon, 2 Nov 2020 09:51:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C8A7D2231B for ; Mon, 2 Nov 2020 09:51:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IpYAYdHJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728189AbgKBJvM (ORCPT ); Mon, 2 Nov 2020 04:51:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727992AbgKBJvM (ORCPT ); Mon, 2 Nov 2020 04:51:12 -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 2DADEC0617A6 for ; Mon, 2 Nov 2020 01:51:12 -0800 (PST) Received: by mail-pg1-x541.google.com with SMTP id i26so10320806pgl.5 for ; Mon, 02 Nov 2020 01:51: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=BnzW6ZRTk6jYpEdb9hSauPeHwb+Af98DVjIElOxlMOU=; b=IpYAYdHJ9ATF/VIdVOdkuxzDOJXWpG6/NC9pVYalgV2t6iSzEIDgRCjPyrk6qUSb2/ rERx3ihvk5UKEHQXSSadaKF88SWhHFSqm97ERp0DrUIRWFEvuaidVCUpv/XBPQXROdMV Jsxg8CYdXedy+jiAXReSq0tugrTukC+ZhKwXHdAp8dwguEpwiRN6+ko9tZyBkOm7W/wX DPGYBc/Cx6FhW8/RAKcGggf0/f5kTusLDGu6wBPL2VehoFTBzJnLm9y9g32eI6BA83p+ 2ttSNXdBYaSjayufVgtN/BbLb+AjE2CkV9QlWnud477A9CNMyojpILjWK+5l3TN5LRtN nNpg== 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=BnzW6ZRTk6jYpEdb9hSauPeHwb+Af98DVjIElOxlMOU=; b=cVsDETMHpFtqVlmzaO0+N6MXMxzcvAH+1U2SXL2rsg6ltXwfK0uaVJVdumNZhgagxa Bh2ny5qSI1KGGlpo9n6c/RuhPG+CBPMTRMfFPpRaKrCF1ImjDQzaVXehkWIjPAX9f0u9 BBZkLjMZPujz8lnnplYsQPZhsa/B6Z8gXsMJYZiuUGR/gyPay7m7SetlDU/mYCP5eDFH h4y9pUsBLCnoasQANOVkthrJjuNBllZJNoHO9+lMu4Vecm0QSo5GLYqxO+KR52hrsNW5 YPfsTGNRc2dCZdLxeQQ3L40u3h2yAWn/W8/c4EbzKXzYCZkJQrZmnA2dRnTzW1U8k8Sx MhzA== X-Gm-Message-State: AOAM532HY3nKe9yPkPhmJey3MJ5ud1y8J59G+Ly1CCi+vwauCFNSo22F MIvuXg9ZhY2gYVcRi2pLb5kSZstgVUQ= X-Google-Smtp-Source: ABdhPJyzbeA2ri0eH0sbOQwT1wt7v1jw7WTKkAQIJ4+jhfMvMGscgGgCHmQFtCrL1D5T0rdcFTN3uw== X-Received: by 2002:aa7:87c2:0:b029:163:d092:86bb with SMTP id i2-20020aa787c20000b0290163d09286bbmr20885402pfo.68.1604310671506; Mon, 02 Nov 2020 01:51:11 -0800 (PST) Received: from localhost.localdomain ([122.179.32.56]) by smtp.gmail.com with ESMTPSA id x15sm467062pjh.21.2020.11.02.01.51.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2020 01:51:10 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, allison.henderson@oracle.com, Christoph Hellwig Subject: [PATCH V9 04/14] xfs: Check for extent overflow when adding/removing xattrs Date: Mon, 2 Nov 2020 15:20:38 +0530 Message-Id: <20201102095048.100956-5-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201102095048.100956-1-chandanrlinux@gmail.com> References: <20201102095048.100956-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Adding/removing an xattr can cause XFS_DA_NODE_MAXDEPTH extents to be added. One extra extent for dabtree in case a local attr is large enough to cause a double split. It can also cause extent count to increase proportional to the size of a remote xattr's value. Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Allison Henderson Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_attr.c | 13 +++++++++++++ fs/xfs/libxfs/xfs_inode_fork.h | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c index fd8e6418a0d3..be51e7068dcd 100644 --- a/fs/xfs/libxfs/xfs_attr.c +++ b/fs/xfs/libxfs/xfs_attr.c @@ -396,6 +396,7 @@ xfs_attr_set( struct xfs_trans_res tres; bool rsvd = (args->attr_filter & XFS_ATTR_ROOT); int error, local; + int rmt_blks = 0; unsigned int total; if (XFS_FORCED_SHUTDOWN(dp->i_mount)) @@ -442,11 +443,15 @@ xfs_attr_set( tres.tr_logcount = XFS_ATTRSET_LOG_COUNT; tres.tr_logflags = XFS_TRANS_PERM_LOG_RES; total = args->total; + + if (!local) + rmt_blks = xfs_attr3_rmt_blocks(mp, args->valuelen); } else { XFS_STATS_INC(mp, xs_attr_remove); tres = M_RES(mp)->tr_attrrm; total = XFS_ATTRRM_SPACE_RES(mp); + rmt_blks = xfs_attr3_rmt_blocks(mp, XFS_XATTR_SIZE_MAX); } /* @@ -460,6 +465,14 @@ xfs_attr_set( xfs_ilock(dp, XFS_ILOCK_EXCL); xfs_trans_ijoin(args->trans, dp, 0); + + if (args->value || xfs_inode_hasattr(dp)) { + error = xfs_iext_count_may_overflow(dp, XFS_ATTR_FORK, + XFS_IEXT_ATTR_MANIP_CNT(rmt_blks)); + if (error) + goto out_trans_cancel; + } + if (args->value) { unsigned int quota_flags = XFS_QMOPT_RES_REGBLKS; diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index bcac769a7df6..5de2f07d0dd5 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -47,6 +47,16 @@ struct xfs_ifork { */ #define XFS_IEXT_PUNCH_HOLE_CNT (1) +/* + * Adding/removing an xattr can cause XFS_DA_NODE_MAXDEPTH extents to + * be added. One extra extent for dabtree in case a local attr is + * large enough to cause a double split. It can also cause extent + * count to increase proportional to the size of a remote xattr's + * value. + */ +#define XFS_IEXT_ATTR_MANIP_CNT(rmt_blks) \ + (XFS_DA_NODE_MAXDEPTH + max(1, rmt_blks)) + /* * Fork handling. */ From patchwork Mon Nov 2 09:50:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11873285 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 AE56D921 for ; Mon, 2 Nov 2020 09:51:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8687D222E8 for ; Mon, 2 Nov 2020 09:51:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="V11GXDv2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728226AbgKBJvR (ORCPT ); Mon, 2 Nov 2020 04:51:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727992AbgKBJvQ (ORCPT ); Mon, 2 Nov 2020 04:51:16 -0500 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 585F2C0617A6 for ; Mon, 2 Nov 2020 01:51:15 -0800 (PST) Received: by mail-pf1-x441.google.com with SMTP id 72so3940779pfv.7 for ; Mon, 02 Nov 2020 01:51:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4jR8INSWSC6ttwbiQgR4/JGrIIg0yQz4NSER0DYDRnc=; b=V11GXDv2elDKqtu+GVGuLQcJVcdF+E5VRahRS2rAfpUSYYUV5/+qF4UoFVD3t0MJJo LT2PhpMdph+qJul0q4HR0vIpXC6/F3SB58EADknHiwWT48xEMs89r2GSY+sZKROcNOw9 GKXwbvw4PxvJ/tOU4qAmSpEUyol747qQ3ZLd55jcOVYImBV8z+54xMzfYfrqqNHn9inX PvNY5ta1fNqnXUBeaTQS4g/Xf0We2MO8IgZc8ob/fKo93M/helU+Q5s8Qun3J1A5P90c L4a5M+FiSQgju81sQ208bWhlVJSTNObuX3qVfll4dXdX5v1zvEkp6U3JIGo+TBojjW3D nLQg== 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=4jR8INSWSC6ttwbiQgR4/JGrIIg0yQz4NSER0DYDRnc=; b=HC9tX/0CWc+7jCMZTNOcbzGOo2dtvIZV45KSQ6P4Qk7Hj5ziNrYO5mpCsQVzy02ENr 3zI+qBBZOtgz4NhwKHUWuJhobD3cZnHlZ1vZdP3bIQnOdlQXQNR2dLaxgvVCcA5fbQTI YLT+c1vPLi3DqSDTdErbKOiTGslAvktNx9VO5eDADD76m7RFlGc8vYEvaBtTU4KDMNSD EwQXaMobQkPdr6wCwkbtppdwPYYihUSEPKYSdtlRqtiNz+hDFIx9A4iNfmJ+ifmXDUcb JRzAc/ikFK2fGFZMz0tE4XTQWFbgxSmWExHrYNfahaWYgKG8eTHF3DkZ+y3gX1NG2cqv mDNg== X-Gm-Message-State: AOAM532LnSu9JHiKKKl1fYebtn4axp1Dqzjgnyz3yHgvpe3D8Iml2yQS wLZGBlCWMiARoxUzZ5c0sFHTUOVJ9vo= X-Google-Smtp-Source: ABdhPJzNsQ5Vuyq9xSfdNkCfa1C3rAEXM1y/GgmhI3xnpgqJLjevsoFnFCde9JPPwg/ODzm5vsS10w== X-Received: by 2002:a05:6a00:88d:b029:164:5a00:29b8 with SMTP id q13-20020a056a00088db02901645a0029b8mr21708281pfj.10.1604310674626; Mon, 02 Nov 2020 01:51:14 -0800 (PST) Received: from localhost.localdomain ([122.179.32.56]) by smtp.gmail.com with ESMTPSA id x15sm467062pjh.21.2020.11.02.01.51.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2020 01:51:14 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, allison.henderson@oracle.com, Christoph Hellwig Subject: [PATCH V9 05/14] xfs: Check for extent overflow when adding/removing dir entries Date: Mon, 2 Nov 2020 15:20:39 +0530 Message-Id: <20201102095048.100956-6-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201102095048.100956-1-chandanrlinux@gmail.com> References: <20201102095048.100956-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Directory entry addition/removal can cause the following, 1. Data block can be added/removed. A new extent can cause extent count to increase by 1. 2. Free disk block can be added/removed. Same behaviour as described above for Data block. 3. Dabtree blocks. XFS_DA_NODE_MAXDEPTH blocks can be added. Each of these can be new extents. Hence extent count can increase by XFS_DA_NODE_MAXDEPTH. Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Allison Henderson 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..5b41ffaf04d7 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -1177,6 +1177,11 @@ xfs_create( if (error) goto out_trans_cancel; + error = xfs_iext_count_may_overflow(dp, XFS_DATA_FORK, + XFS_IEXT_DIR_MANIP_CNT(mp)); + if (error) + goto out_trans_cancel; + /* * A newly created regular or special file just has one directory * entry pointing to them, but a directory also the "." entry @@ -1393,6 +1398,11 @@ xfs_link( xfs_trans_ijoin(tp, sip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, tdp, XFS_ILOCK_EXCL); + error = xfs_iext_count_may_overflow(tdp, XFS_DATA_FORK, + XFS_IEXT_DIR_MANIP_CNT(mp)); + if (error) + goto error_return; + /* * If we are using project inheritance, we only allow hard link * creation in our tree when the project IDs are the same; else @@ -2861,6 +2871,11 @@ xfs_remove( xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); + error = xfs_iext_count_may_overflow(dp, XFS_DATA_FORK, + XFS_IEXT_DIR_MANIP_CNT(mp)); + if (error) + goto out_trans_cancel; + /* * If we're removing a directory perform some additional validation. */ @@ -3221,6 +3236,18 @@ xfs_rename( if (wip) xfs_trans_ijoin(tp, wip, XFS_ILOCK_EXCL); + error = xfs_iext_count_may_overflow(src_dp, XFS_DATA_FORK, + XFS_IEXT_DIR_MANIP_CNT(mp)); + if (error) + goto out_trans_cancel; + + if (target_ip == NULL) { + error = xfs_iext_count_may_overflow(target_dp, XFS_DATA_FORK, + XFS_IEXT_DIR_MANIP_CNT(mp)); + if (error) + goto out_trans_cancel; + } + /* * If we are using project inheritance, we only allow renames * into our tree when the project IDs are the same; else the diff --git a/fs/xfs/xfs_symlink.c b/fs/xfs/xfs_symlink.c index 8e88a7ca387e..581a4032a817 100644 --- a/fs/xfs/xfs_symlink.c +++ b/fs/xfs/xfs_symlink.c @@ -220,6 +220,11 @@ xfs_symlink( if (error) goto out_trans_cancel; + error = xfs_iext_count_may_overflow(dp, XFS_DATA_FORK, + XFS_IEXT_DIR_MANIP_CNT(mp)); + if (error) + goto out_trans_cancel; + /* * Allocate an inode for the symlink. */ From patchwork Mon Nov 2 09:50:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11873287 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 3DC8492A for ; Mon, 2 Nov 2020 09:51:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 14AA2223AC for ; Mon, 2 Nov 2020 09:51:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JE87khMj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728248AbgKBJvU (ORCPT ); Mon, 2 Nov 2020 04:51:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727992AbgKBJvT (ORCPT ); Mon, 2 Nov 2020 04:51:19 -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 5649CC0617A6 for ; Mon, 2 Nov 2020 01:51:18 -0800 (PST) Received: by mail-pg1-x544.google.com with SMTP id f38so10340543pgm.2 for ; Mon, 02 Nov 2020 01:51:18 -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=JE87khMjH7Ufo01Xe95I8nyBqpIDle3AQ/pkCYcEc5aA/hfL0/FZvIDCSj7i/ZXTrB JziMUrKbqqq511VqnMveuYiB7GOLeU+OQoxVgHGwuz0vqHejyxrHpXXxlBTchagxMdnF umW+LyAVT5Hn8fZLHD68mpR2V0xxJjSrB4tNOHhJsYH3y+wmipOv5KuZP08oZHWN/Tu8 u06sJXkAxiJ7XiestjIrDvB9tP6T45Gl0PMOmNe0i9eCZV3GRF2Mql6+XDg6LAZBC9ZF jxJwP+6ooXkAQZoultpGPpwQPEYr5n/nxqAItksWnYgdU5l6f2aeqHYxBzgZ/YAWmCX/ qejA== 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=c1aluZN2QDkrlKZL8FuK5AzMMxRZdrIunTZ/XfM5INSS84oOETykiZta8RIOh5ofBp CWaFX9LHttH0TkWv10IbKlverfDg/+CVUulTe+7D3qhD7JWAte8Yf5mYaM4aL7uay37k vh4ypNLUy1SpX2hJNg83cKjkeuDnZLlSpBkldVMRF3LN+kBjMM/qurRm4DYWrDBD23TE ScP1MIHj3OxYChZc6ImhSqO7WP/1dIr3WU5wQMFR6GKDSmqI/WQgcgxudkzxrjkAI1G/ VdgKEhvJNGsKwlLmGYUHpAK1i991BrtWKpunlTvp48rNEDhkNkgTqSGsodvsiKGyoqnX 1g9A== X-Gm-Message-State: AOAM530Yr7lhRxpI6eYJzSOp6TTr7E5HzXA4SBHgbSMTclSFCnymnJC4 G5z5b02Qv7R1NrFNm9YftwoC374oAuw= X-Google-Smtp-Source: ABdhPJw2msX+ErFYxzmtp4l8DybB6wpFZfFf+cyb6AvZMbR7oZOCD6iOY99FUBNPV/Nej2JutvqkvQ== X-Received: by 2002:a63:6386:: with SMTP id x128mr2416346pgb.148.1604310677660; Mon, 02 Nov 2020 01:51:17 -0800 (PST) Received: from localhost.localdomain ([122.179.32.56]) by smtp.gmail.com with ESMTPSA id x15sm467062pjh.21.2020.11.02.01.51.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2020 01:51:17 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, allison.henderson@oracle.com, Christoph Hellwig Subject: [PATCH V9 06/14] xfs: Check for extent overflow when writing to unwritten extent Date: Mon, 2 Nov 2020 15:20:40 +0530 Message-Id: <20201102095048.100956-7-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201102095048.100956-1-chandanrlinux@gmail.com> References: <20201102095048.100956-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 Mon Nov 2 09:50:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11873289 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 520EA921 for ; Mon, 2 Nov 2020 09:51:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 30537222E8 for ; Mon, 2 Nov 2020 09:51:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WiUnpRqZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728266AbgKBJvV (ORCPT ); Mon, 2 Nov 2020 04:51:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727992AbgKBJvV (ORCPT ); Mon, 2 Nov 2020 04:51:21 -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 7E2E9C0617A6 for ; Mon, 2 Nov 2020 01:51:21 -0800 (PST) Received: by mail-pf1-x444.google.com with SMTP id j18so10662515pfa.0 for ; Mon, 02 Nov 2020 01:51:21 -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=WiUnpRqZraaNxPt428CkKXYQaFsM5MSk1yF8HRBtorgoehNItBtCOXAXelXBcTGbjT TmAH1T9n+pzQy4rzqjiGcQCfbaSQJrwDWBfNCdsq3w4nf5p0MEXdbWEjjFVCpE9k7Io6 WsUJRojPR/oZ9/atJT0M48f6Nu182ZWPmKaTI7dtD2onpIDgJqsy7JiauJ4Y/j9UZG78 Hn/ff+iNIFQv7r1jESWn95KhfcvP8CdhegthdiHurRR54Tqrh9FZK6p6i8n1iOhuwgEW vcox5gQfQt3uLYFq+Cuj75mWhGygy3tAUXv7OwLgT2hdzMIFpYcMhNdPAsdF+TFq3OsG PYtA== 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=kQKPgKuEeqmO/1jkhvBIwwc1to+YJbn5uS34ulutadkxVmla8Y0tBGcsgA7Sb/mz6t FcV6H5SEEbJYupCK/EudjeuhG7LTYnWM2/ZGUZT6kVV7FZou2JAiD32emQEeUfPn5xMi 4+PclMSws82srokAAMOsRWq6MJuH1u+H89mJGNqrmS342TS4YWAsDLOQp4StxdZGiDZN hBuCJqFbgwZNiiXb3dIRQKpKFeoCM34BXBseIqHffSThSqypvw6/AQbktNIV/90/stJK zRPkHfAVHuhbP91Y+VBoc6gJvaL+MA7ITZe+WhxvvTciu1m00qgULeGr7uCVFO4ERE/L 329w== X-Gm-Message-State: AOAM530E3SSNLILRbXi9sPZ6SWQ+8uQx/dSAn5wqMb2bHv4HA5xhP5Ig 6cyRLWFcxqvvfevuZHGGp52Wl729ek4= X-Google-Smtp-Source: ABdhPJzWGs5wyPdV8GckBkTQ9QWqtMHFlUtuFjhD4WMItUr9PRDuBxVGp57SsVYusoxxwFyX/E8T3A== X-Received: by 2002:a63:4a43:: with SMTP id j3mr13026713pgl.103.1604310680836; Mon, 02 Nov 2020 01:51:20 -0800 (PST) Received: from localhost.localdomain ([122.179.32.56]) by smtp.gmail.com with ESMTPSA id x15sm467062pjh.21.2020.11.02.01.51.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2020 01:51:20 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, allison.henderson@oracle.com, Christoph Hellwig Subject: [PATCH V9 07/14] xfs: Check for extent overflow when moving extent from cow to data fork Date: Mon, 2 Nov 2020 15:20:41 +0530 Message-Id: <20201102095048.100956-8-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201102095048.100956-1-chandanrlinux@gmail.com> References: <20201102095048.100956-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 Mon Nov 2 09:50:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11873291 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 9252D92A for ; Mon, 2 Nov 2020 09:51:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 69BF0222B9 for ; Mon, 2 Nov 2020 09:51:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lcXF/C1u" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728253AbgKBJvZ (ORCPT ); Mon, 2 Nov 2020 04:51:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727992AbgKBJvY (ORCPT ); Mon, 2 Nov 2020 04:51:24 -0500 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 5E20CC0617A6 for ; Mon, 2 Nov 2020 01:51:24 -0800 (PST) Received: by mail-pg1-x543.google.com with SMTP id w4so99560pgg.13 for ; Mon, 02 Nov 2020 01:51: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=nt70IvY/vtgLa/y5uH7G+5m8dg0wvGwo7q/BlwAPtZA=; b=lcXF/C1uEaP3CYOkmyk4fwNEqYT5iHcQMCCMw7tFtnohkTOTsWNj9i7QG3f8cQlVR4 UUCY/6zK7GMpGW0fCNvJDaVCrtY62FLL3/J4zs+sF7xwr4nibEmLV5DTgmJy9zYLRisQ 4OQu9bVRpl6Ka596wF5hveD40caUrvIqdeYYBMUBMoxHBdTbSuXGUo17a9Eysiu1aBdf AhWJwjm+HGKpdEN0JkgAgkbsRQktUQusTKrg9u0Wn3bvbBVwzJsJgx0RfVr56l/aqmga Slmd/wntlhz1xUGfH31kEuhKE5CyNgHVHK6bvSrK/X2HsI6oxVseagSQrJh3abkQFSvc DQPQ== 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=isvEDt5bbmGM3Bom54414PFVp+h0BXkHFy/4CrI9EbR8aXS0pxtIkCOw8jE6AfCrMA snKx3Vmi40cKkXjpIz1WwjYGYmhRIDmsJ0Adwr1VyG7+akbtHZEM5nsVaxHMQL3GeTuh ZSEjxIwJlZzUb0IM+9/1zgKHeDjeG0NFAG3vvlyTcRpbu1RY7MhSdsvRT4mPO94Fgh9f eEdCMjI/aMQm1Z3Heclik3NsxauaLGb9i1qxlGuR3ZsuGXN+TeCNzmbjwqowPm/5ezD0 yhYEzHCMSB2YMzlzO1gMX4AG97bXLXAYqw97+wOK9EfVJTUxlK3mrHdttlY/C3MmtjTI tnzg== X-Gm-Message-State: AOAM532T3McWulbxRfXV7m64tb5svtPunZccbTUwVXkr6lChKOQd7wib dgiU4ZfQ2j2qUReNUXmPR7Cz9BLoyHM= X-Google-Smtp-Source: ABdhPJzFOBxs3GR9klF+3FBvjDpNsoSOwOuSpWa1T7buADQSrv1Ym9ZMW0WYsPfb9RpFvquyS2fxZw== X-Received: by 2002:a65:4305:: with SMTP id j5mr12514915pgq.249.1604310683685; Mon, 02 Nov 2020 01:51:23 -0800 (PST) Received: from localhost.localdomain ([122.179.32.56]) by smtp.gmail.com with ESMTPSA id x15sm467062pjh.21.2020.11.02.01.51.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2020 01:51:23 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, allison.henderson@oracle.com Subject: [PATCH V9 08/14] xfs: Check for extent overflow when remapping an extent Date: Mon, 2 Nov 2020 15:20:42 +0530 Message-Id: <20201102095048.100956-9-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201102095048.100956-1-chandanrlinux@gmail.com> References: <20201102095048.100956-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 Mon Nov 2 09:50:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11873293 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 035CB921 for ; Mon, 2 Nov 2020 09:51:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D11FF222E8 for ; Mon, 2 Nov 2020 09:51:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cn1jDHaF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728288AbgKBJv1 (ORCPT ); Mon, 2 Nov 2020 04:51:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727992AbgKBJv1 (ORCPT ); Mon, 2 Nov 2020 04:51:27 -0500 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B83CC0617A6 for ; Mon, 2 Nov 2020 01:51:27 -0800 (PST) Received: by mail-pg1-x542.google.com with SMTP id o3so10308602pgr.11 for ; Mon, 02 Nov 2020 01:51:27 -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=cn1jDHaFg9HbmM8j/TDQ5L+6K5+KW+3pHzDWeiPWWEBvV/++vS+0k2jWWpku5HOIf5 NlYf1zeVvu+aTVL0QsrqNLEG1QbS1mWjKg+CxIt780FLrSQH9N3ZJs+223rsOru7+yEZ Y+aip5HsbKV6ILvt850c5SAOiCXTfM+2N1Tx3fyQiXfDRDPlVibE28tLJPgxlJ+jqH8R 5lBSD3L7rhyO7fyPCAcpY5bqahUzX6i0E0l6SSV2wPnG1NqFsdq1XvoYagoy1TMwZYyN HYUMKj4AHBX01DC/DKgE+aapspx1GJ/0lPsdruFhtQt4LGEQBnRA1RtlaLUla1byD/kM pRRw== 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=QqznjV80E6oik2JFtkqQ0DBtsn4j/EPbVfIUthwSyX5ufBqussoVfoRY5E0Y8kI51l JSMVbLPvj+42ry/Jf41PBGQ+CYc74cr22SjwiciKqY1yp7eV7bsmKgHo33ygnVU+2qZy IQgaiz7WnIxIrNcN8abiIBFbnWmnBoi/5Nq/Q7BSjpPPy7Nj0LDrcTDfKR3VSPfB1mU4 /RjxLp+CbUyM5TEcbWxHWQhcskPF3xErPsgmvtIh1kCg3Xv0xbkwAz1QPTrffR3x5pdO KxDUD5H8O9W+lSsAsexZWOWddchX6+xxrlA7Fx2e1g2AW4SIuZ9IHLKbN+At5fGA8J81 /yzw== X-Gm-Message-State: AOAM532Z9LDzOaWytyJw6C5MiRIKKhRaN4+x5mMJrKCPdNr0U0JWDbZy nC89AQFbrGhm7yp8sxjRPaUbhwsr9yY= X-Google-Smtp-Source: ABdhPJwTzak8sGwzfxPWRdFslDwSGvtBMRDJ5PjF40oUqXSBqn01UUiKgCfK4oUUx3tTSgKK+mQaxA== X-Received: by 2002:a63:4459:: with SMTP id t25mr13041952pgk.104.1604310686590; Mon, 02 Nov 2020 01:51:26 -0800 (PST) Received: from localhost.localdomain ([122.179.32.56]) by smtp.gmail.com with ESMTPSA id x15sm467062pjh.21.2020.11.02.01.51.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2020 01:51:25 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, allison.henderson@oracle.com Subject: [PATCH V9 09/14] xfs: Check for extent overflow when swapping extents Date: Mon, 2 Nov 2020 15:20:43 +0530 Message-Id: <20201102095048.100956-10-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201102095048.100956-1-chandanrlinux@gmail.com> References: <20201102095048.100956-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 Mon Nov 2 09:50:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11873299 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 928C3921 for ; Mon, 2 Nov 2020 09:51:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6A742222B9 for ; Mon, 2 Nov 2020 09:51:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Vu9Yybv2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728293AbgKBJvc (ORCPT ); Mon, 2 Nov 2020 04:51:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727992AbgKBJvb (ORCPT ); Mon, 2 Nov 2020 04:51:31 -0500 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62F13C0617A6 for ; Mon, 2 Nov 2020 01:51:30 -0800 (PST) Received: by mail-pg1-x542.google.com with SMTP id g12so10325523pgm.8 for ; Mon, 02 Nov 2020 01:51:30 -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=/T4H2MiD0QBM8tig6ImJk3HvLU2caAc+kKCOLA74nf0=; b=Vu9Yybv2Egw80PdVTaFqaIKMn98C28jJfz5bqNeC4s91/RGEa6FsH3ofC60Eg+qG6Y 3orKR1W/MPyfY8znK30/M9ANd4r7kJUBxao4TtxaNEIadUqWbz9x2bHdeXH7Foqw7Axs hJkIisSl9kIQ4yxm5ijGyDu7SKSUzahZ65j2nywdozrcnrd8bwaHmFCP8cdwh3q/pb0Q w8nUiVlnXrKcqqV65JWbnnkHQ4/ey0yTGfUa4Q9bRgnV/cCyBUO0gsTrbr0KwQz2xYRo aMmHr4Nw3fQBXznR+aW0GyU86tFY3xJ5y7hpAm4WaJ2ty/Jm3phfQqUi79UHObLljsVu 8hNg== 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=/T4H2MiD0QBM8tig6ImJk3HvLU2caAc+kKCOLA74nf0=; b=RYXA6Ir2JQTstbaS8vsA4cgx5S0Hgv2J5M0xNgk4saRa+8yAZlCt0OHWlNADsn7h7e H2TTyvZXwDcEpkXDIGrTAuc946LPgTYRA0GPFSgUg704SBd6Wdf8ucieDYoDFJRrJbZk mPGWpaquz4Goa3J1QLYDEw3uhOGgADGQ6zmKOibMHb/nN5aOzQ9kiu7QNqLm8nHaZnaR uNRiFddTswT0/8X8E8qHEAJwj44G6C5eBiRt4Lu/nIo2atUbGRYGrzYCEPQgdTlajFRj +dIDYIrwozqbO+LXcoBpv6Ullu2AStWB0BfuyLARV+OUc3K237GHsUie2wZ1oyoPzhGg v5mg== X-Gm-Message-State: AOAM530wmsNtvBPj7cBwkWIrzpglnq+xeUw6lYbSB92eLQ7uH1BwEieN vFYNBl/DXNo9cASpRqOsiokL29cUNbI= X-Google-Smtp-Source: ABdhPJwrYelhbwVRvT3irO/pkw+74YLM02rLUwaWn/P68AfHYlToGoDH8lxQdWdxrkFAxWGRsrpZlQ== X-Received: by 2002:a63:5819:: with SMTP id m25mr12155287pgb.398.1604310689696; Mon, 02 Nov 2020 01:51:29 -0800 (PST) Received: from localhost.localdomain ([122.179.32.56]) by smtp.gmail.com with ESMTPSA id x15sm467062pjh.21.2020.11.02.01.51.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2020 01:51:29 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, allison.henderson@oracle.com, Christoph Hellwig Subject: [PATCH V9 10/14] xfs: Introduce error injection to reduce maximum inode fork extent count Date: Mon, 2 Nov 2020 15:20:44 +0530 Message-Id: <20201102095048.100956-11-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201102095048.100956-1-chandanrlinux@gmail.com> References: <20201102095048.100956-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org This commit adds XFS_ERRTAG_REDUCE_MAX_IEXTENTS error tag which enables userspace programs to test "Inode fork extent count overflow detection" by reducing maximum possible inode fork extent count to 10. Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Allison Henderson Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_errortag.h | 4 +++- fs/xfs/libxfs/xfs_inode_fork.c | 4 ++++ fs/xfs/xfs_error.c | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_errortag.h b/fs/xfs/libxfs/xfs_errortag.h index 53b305dea381..1c56fcceeea6 100644 --- a/fs/xfs/libxfs/xfs_errortag.h +++ b/fs/xfs/libxfs/xfs_errortag.h @@ -56,7 +56,8 @@ #define XFS_ERRTAG_FORCE_SUMMARY_RECALC 33 #define XFS_ERRTAG_IUNLINK_FALLBACK 34 #define XFS_ERRTAG_BUF_IOERROR 35 -#define XFS_ERRTAG_MAX 36 +#define XFS_ERRTAG_REDUCE_MAX_IEXTENTS 36 +#define XFS_ERRTAG_MAX 37 /* * Random factors for above tags, 1 means always, 2 means 1/2 time, etc. @@ -97,5 +98,6 @@ #define XFS_RANDOM_FORCE_SUMMARY_RECALC 1 #define XFS_RANDOM_IUNLINK_FALLBACK (XFS_RANDOM_DEFAULT/10) #define XFS_RANDOM_BUF_IOERROR XFS_RANDOM_DEFAULT +#define XFS_RANDOM_REDUCE_MAX_IEXTENTS 1 #endif /* __XFS_ERRORTAG_H_ */ diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c index 8d48716547e5..e080d7e07643 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.c +++ b/fs/xfs/libxfs/xfs_inode_fork.c @@ -24,6 +24,7 @@ #include "xfs_dir2_priv.h" #include "xfs_attr_leaf.h" #include "xfs_types.h" +#include "xfs_errortag.h" kmem_zone_t *xfs_ifork_zone; @@ -745,6 +746,9 @@ xfs_iext_count_may_overflow( max_exts = (whichfork == XFS_ATTR_FORK) ? MAXAEXTNUM : MAXEXTNUM; + if (XFS_TEST_ERROR(false, ip->i_mount, XFS_ERRTAG_REDUCE_MAX_IEXTENTS)) + max_exts = 10; + nr_exts = ifp->if_nextents + nr_to_add; if (nr_exts < ifp->if_nextents || nr_exts > max_exts) return -EFBIG; diff --git a/fs/xfs/xfs_error.c b/fs/xfs/xfs_error.c index 7f6e20899473..3780b118cc47 100644 --- a/fs/xfs/xfs_error.c +++ b/fs/xfs/xfs_error.c @@ -54,6 +54,7 @@ static unsigned int xfs_errortag_random_default[] = { XFS_RANDOM_FORCE_SUMMARY_RECALC, XFS_RANDOM_IUNLINK_FALLBACK, XFS_RANDOM_BUF_IOERROR, + XFS_RANDOM_REDUCE_MAX_IEXTENTS, }; struct xfs_errortag_attr { @@ -164,6 +165,7 @@ XFS_ERRORTAG_ATTR_RW(force_repair, XFS_ERRTAG_FORCE_SCRUB_REPAIR); XFS_ERRORTAG_ATTR_RW(bad_summary, XFS_ERRTAG_FORCE_SUMMARY_RECALC); XFS_ERRORTAG_ATTR_RW(iunlink_fallback, XFS_ERRTAG_IUNLINK_FALLBACK); XFS_ERRORTAG_ATTR_RW(buf_ioerror, XFS_ERRTAG_BUF_IOERROR); +XFS_ERRORTAG_ATTR_RW(reduce_max_iextents, XFS_ERRTAG_REDUCE_MAX_IEXTENTS); static struct attribute *xfs_errortag_attrs[] = { XFS_ERRORTAG_ATTR_LIST(noerror), @@ -202,6 +204,7 @@ static struct attribute *xfs_errortag_attrs[] = { XFS_ERRORTAG_ATTR_LIST(bad_summary), XFS_ERRORTAG_ATTR_LIST(iunlink_fallback), XFS_ERRORTAG_ATTR_LIST(buf_ioerror), + XFS_ERRORTAG_ATTR_LIST(reduce_max_iextents), NULL, }; From patchwork Mon Nov 2 09:50:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11873301 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 28D9B921 for ; Mon, 2 Nov 2020 09:51:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 00C40222E8 for ; Mon, 2 Nov 2020 09:51:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TiBxH1bL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728297AbgKBJve (ORCPT ); Mon, 2 Nov 2020 04:51:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727992AbgKBJve (ORCPT ); Mon, 2 Nov 2020 04:51:34 -0500 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 230B7C0617A6 for ; Mon, 2 Nov 2020 01:51:33 -0800 (PST) Received: by mail-pf1-x441.google.com with SMTP id y14so10620352pfp.13 for ; Mon, 02 Nov 2020 01:51:33 -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=TiBxH1bLooei3A/+of/xYTulxYirY+AUkYwmz2bZPa3QTZ67HnbCMujM0TT1+PJ+/w kpQA1WBvgBhtmOG+Qvz8S0qSvhJBcHymNYAdZmhrS9ruTmtGPXyakvW+I2h+64YaeDmZ fT2nJrIZgKJ1E3v1eQ6dZk5rCnisrkq3+kkZ18m2sYVWWuEZNr49FQdUMcOMZa2TaFJm u1PVd+6jKOA0alMx8+2e6lzFd36UvmN/KLbmhLiZm1xRq3OyypsXwvL2Vp/qH6H8sFdP X2RbMufhmipbYjPPsGeKFKzoJM3nZM3xCfmIh47P9CbMziai6Vm3DzqeTCJqS8/OnHrt Jisg== 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=ojEQO9+xHXvbwx3DQMGeW242S0Irua/wiAVEEA9YFvTWjfWpzZZJAJJQW7+t0IW04e 7R9Q3LYXqIr9Rek4xBke2zGFbAFBxoTRMkYIU89eZakbsSFZBswP+s4CRZ8u0PbGXZED eZ8D/9farfQQa17MqHlMziukalxuIyg6nA4dwCpf4PfKVsGnRwbgB8IA2gyVv0lZ2eLG sbzdtYmjZvYTaz5sVwfIROHBWDvKzNnmXqLyWrbc4cPZhMjVW2J68S/URzeKtDD3r1Co LQc9b1Nc/dB5rQ6mLqqaszfqXZzeOrfGBN4Eri/82OqQy3nrdxlix7TLui9zRTEZiYVP fURw== X-Gm-Message-State: AOAM530C9Q28xvcB/YeoaSpqwQNdObQYuFjtBdvRZKJkjHEu+tqHB7BZ n0B5hhBp8N/5Xecp3n5ukMgVlK0gHlw= X-Google-Smtp-Source: ABdhPJxMpOAeSBVUFIoCg3vHSKXPo4YKdQYvYmGZafiNtvW+4rho3le6siwkhgVuAALddlO9EyQVHg== X-Received: by 2002:a63:495d:: with SMTP id y29mr12314306pgk.384.1604310692492; Mon, 02 Nov 2020 01:51:32 -0800 (PST) Received: from localhost.localdomain ([122.179.32.56]) by smtp.gmail.com with ESMTPSA id x15sm467062pjh.21.2020.11.02.01.51.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2020 01:51:31 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, allison.henderson@oracle.com Subject: [PATCH V9 11/14] xfs: Remove duplicate assert statement in xfs_bmap_btalloc() Date: Mon, 2 Nov 2020 15:20:45 +0530 Message-Id: <20201102095048.100956-12-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201102095048.100956-1-chandanrlinux@gmail.com> References: <20201102095048.100956-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 Mon Nov 2 09:50:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11873303 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 5C880921 for ; Mon, 2 Nov 2020 09:51:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 386FA223AB for ; Mon, 2 Nov 2020 09:51:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mpAWRjUo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728316AbgKBJvh (ORCPT ); Mon, 2 Nov 2020 04:51:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727992AbgKBJvh (ORCPT ); Mon, 2 Nov 2020 04:51:37 -0500 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 386DEC0617A6 for ; Mon, 2 Nov 2020 01:51:36 -0800 (PST) Received: by mail-pf1-x441.google.com with SMTP id 13so10646833pfy.4 for ; Mon, 02 Nov 2020 01:51:36 -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=wcibcHg+fGfIy+ERBhxnRgw5AuJuCxxwyu5T4vfwYrc=; b=mpAWRjUolU/GYRqOfYqNMJYjNjRG7sYd8Ow6A28yH/YkacK1CGGip2v45/Nr0sAeMT zZ1Ii6tFYGg2bq106SWhZ5T1ctDRc7kuFM9m33hbGwatD1xaJyzC37Qvy18gfwK84xVP OqUHGafvAyInvtDMKoFA/srC4NrZtpJ8bctWVo/zRqqbzjwT13Qe4898Tu7ELahuC7Ey FoeQ7Nh8+0W76Jf1n27X88kdTq1COXn5cZwT2sKtitTuFPX2P+qn7+r3y/QJXVcJ5QSI gZ5nDqQA23m+L2nbpc8T1WAQWdEqRS8mKOBB0rnZvlOohDya8yds6RoiujaPDDrvBxI5 gskg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wcibcHg+fGfIy+ERBhxnRgw5AuJuCxxwyu5T4vfwYrc=; b=H3A+v2yaXkkBMjeIfZ2cPsnLDWa+hFSnVyMKbMct336AsjISQr4e0z8yNadxF6Fh1P 6Yri0QyhDUlUE4FHf8Y7xloRt3AaThFpcttsJfkYxOoetlQUwQ/vV8RkgGgm7/duO61N ZWOc33YPqnyAJ9YOP5toqbQUG8NyAf6TNNJt/HAPdPO4Ky0xwTbB9FnFrAIjD12pxSMp QMX6GmG/32TkLi3wqzTRtNVJmmEOA1tYmBZIWGytq/2OB0DQgDIPOMoRf8sjdn0S8FTA ZrUItkrPAdkEk+a7mWvfoDgFd3wTX2wyelzwgC9d3NTta+ezcG1rTFvDWLalDDz8+DnY LLjQ== X-Gm-Message-State: AOAM532RAd1TDTFGxJBZd8Rav2+etJUOebmmixKQNGz0gCpdh4RdZ/DO /P01Hz8cPDv5xiZwXIYY2J7H3b3h4vQ= X-Google-Smtp-Source: ABdhPJy8XUbyGS5m5V1wEjapxwc4JXNiu3bP8Z1pnpozg85rAnGp0CA0hS+BGV4Udb3/ivokEJpSrQ== X-Received: by 2002:a63:9a41:: with SMTP id e1mr12652468pgo.371.1604310695466; Mon, 02 Nov 2020 01:51:35 -0800 (PST) Received: from localhost.localdomain ([122.179.32.56]) by smtp.gmail.com with ESMTPSA id x15sm467062pjh.21.2020.11.02.01.51.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2020 01:51:34 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, allison.henderson@oracle.com Subject: [PATCH V9 12/14] xfs: Compute bmap extent alignments in a separate function Date: Mon, 2 Nov 2020 15:20:46 +0530 Message-Id: <20201102095048.100956-13-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201102095048.100956-1-chandanrlinux@gmail.com> References: <20201102095048.100956-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org This commit moves over the code which computes stripe alignment and extent size hint alignment into a separate function. Apart from xfs_bmap_btalloc(), the new function will be used by another function introduced in a future commit. Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_bmap.c | 88 +++++++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 37 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 64c4d0e384a5..935f2d506748 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -3463,13 +3463,58 @@ xfs_bmap_btalloc_accounting( args->len); } +static void +xfs_bmap_compute_alignments( + struct xfs_bmalloca *ap, + struct xfs_alloc_arg *args, + int *stripe_align) +{ + struct xfs_mount *mp = args->mp; + xfs_extlen_t align = 0; /* minimum allocation alignment */ + int error; + + /* stripe alignment for allocation is determined by mount parameters */ + *stripe_align = 0; + if (mp->m_swidth && (mp->m_flags & XFS_MOUNT_SWALLOC)) + *stripe_align = mp->m_swidth; + else if (mp->m_dalign) + *stripe_align = mp->m_dalign; + + if (ap->flags & XFS_BMAPI_COWFORK) + align = xfs_get_cowextsz_hint(ap->ip); + else if (ap->datatype & XFS_ALLOC_USERDATA) + align = xfs_get_extsz_hint(ap->ip); + if (align) { + error = xfs_bmap_extsize_align(mp, &ap->got, &ap->prev, + align, 0, ap->eof, 0, ap->conv, + &ap->offset, &ap->length); + ASSERT(!error); + ASSERT(ap->length); + } + + /* apply extent size hints if obtained earlier */ + if (align) { + args->prod = align; + div_u64_rem(ap->offset, args->prod, &args->mod); + if (args->mod) + args->mod = args->prod - args->mod; + } else if (mp->m_sb.sb_blocksize >= PAGE_SIZE) { + args->prod = 1; + args->mod = 0; + } else { + args->prod = PAGE_SIZE >> mp->m_sb.sb_blocklog; + div_u64_rem(ap->offset, args->prod, &args->mod); + if (args->mod) + args->mod = args->prod - args->mod; + } +} + STATIC int xfs_bmap_btalloc( struct xfs_bmalloca *ap) /* bmap alloc argument struct */ { xfs_mount_t *mp; /* mount point structure */ xfs_alloctype_t atype = 0; /* type for allocation routines */ - xfs_extlen_t align = 0; /* minimum allocation alignment */ xfs_agnumber_t fb_agno; /* ag number of ap->firstblock */ xfs_agnumber_t ag; xfs_alloc_arg_t args; @@ -3489,25 +3534,11 @@ xfs_bmap_btalloc( mp = ap->ip->i_mount; - /* stripe alignment for allocation is determined by mount parameters */ - stripe_align = 0; - if (mp->m_swidth && (mp->m_flags & XFS_MOUNT_SWALLOC)) - stripe_align = mp->m_swidth; - else if (mp->m_dalign) - stripe_align = mp->m_dalign; - - if (ap->flags & XFS_BMAPI_COWFORK) - align = xfs_get_cowextsz_hint(ap->ip); - else if (ap->datatype & XFS_ALLOC_USERDATA) - align = xfs_get_extsz_hint(ap->ip); - if (align) { - error = xfs_bmap_extsize_align(mp, &ap->got, &ap->prev, - align, 0, ap->eof, 0, ap->conv, - &ap->offset, &ap->length); - ASSERT(!error); - ASSERT(ap->length); - } + memset(&args, 0, sizeof(args)); + args.tp = ap->tp; + args.mp = mp; + xfs_bmap_compute_alignments(ap, &args, &stripe_align); nullfb = ap->tp->t_firstblock == NULLFSBLOCK; fb_agno = nullfb ? NULLAGNUMBER : XFS_FSB_TO_AGNO(mp, @@ -3538,9 +3569,6 @@ xfs_bmap_btalloc( * Normal allocation, done through xfs_alloc_vextent. */ tryagain = isaligned = 0; - memset(&args, 0, sizeof(args)); - args.tp = ap->tp; - args.mp = mp; args.fsbno = ap->blkno; args.oinfo = XFS_RMAP_OINFO_SKIP_UPDATE; @@ -3571,21 +3599,7 @@ xfs_bmap_btalloc( args.total = ap->total; args.minlen = ap->minlen; } - /* apply extent size hints if obtained earlier */ - if (align) { - args.prod = align; - div_u64_rem(ap->offset, args.prod, &args.mod); - if (args.mod) - args.mod = args.prod - args.mod; - } else if (mp->m_sb.sb_blocksize >= PAGE_SIZE) { - args.prod = 1; - args.mod = 0; - } else { - args.prod = PAGE_SIZE >> mp->m_sb.sb_blocklog; - div_u64_rem(ap->offset, args.prod, &args.mod); - if (args.mod) - args.mod = args.prod - args.mod; - } + /* * If we are not low on available data blocks, and the underlying * logical volume manager is a stripe, and the file offset is zero then From patchwork Mon Nov 2 09:50:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11873305 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 DBACD921 for ; Mon, 2 Nov 2020 09:51:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B81AF222B9 for ; Mon, 2 Nov 2020 09:51:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="rAKmraU6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728317AbgKBJvj (ORCPT ); Mon, 2 Nov 2020 04:51:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727992AbgKBJvj (ORCPT ); Mon, 2 Nov 2020 04:51:39 -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 1F4B2C0617A6 for ; Mon, 2 Nov 2020 01:51:39 -0800 (PST) Received: by mail-pg1-x541.google.com with SMTP id 62so3044386pgg.12 for ; Mon, 02 Nov 2020 01:51:39 -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=UeDpThAYxs124zwV4PKfLL2jNcC3XH3KhZ5P3V8H6C8=; b=rAKmraU60JO2MFtrLE8SCph04onz1WeAsIgK3w0wPll9auH1GyR0eDadHs9K6PBZFr cj3bXjPbP5aSnTDOlOM7p+6KAeKDkeGna5hMg6jVybBpNHq36oVLAe0u/bm2ISUqSXOA h/Z+Y3OuvGSQKl8xUsc7HNIKNhcqCh5ttkyobDclezlqqlV0b8C4TXdgXeU+rQDkVIwr AryuQWxZ6Ugnql+LOL8S5NpC1t+cR8Q5TXbwZETu87zjt4zDSVyjaLD375lqghkqP/W4 lDEosg1yeCpkFRMiEfF21X5kVhNeqEM69fnywavJNv1yG/68FBtuAKeA2BG+goKFSTlZ 7Pvg== 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=UeDpThAYxs124zwV4PKfLL2jNcC3XH3KhZ5P3V8H6C8=; b=ZNxYtnXESLAJzBPF4kcH7JJkwyukLjRZIZjFxwz2D3mdhewJjtAMv9vyxcRQxyhqxF Qst7b7i6EusvefSHZgzwhTOIC1r/KgDunEPKPpErE9QPWRHeYI6ypux9xIZggOusKjrR hlFL8Nt+q+9xNsAqPfuz+IPIhs6QNOlldMo5h9m3s5glVJmHS0o4OsSU1WhwjsO9ItzX C+xTVZi8aFqRJhztF8ZidbhSSU/11kWH+QdbfyhdgU6QBXBEsH8rh0DwybIREtQaVoVK M0greGTtrYuO0QQKS4tuc0KbEnEysV/jbeqWl7vvJ6ytFltVKLubixSJRyjghc8b79wJ LAPQ== X-Gm-Message-State: AOAM5300zmREaIrlTDMzXqQMwlJYOOGBK+Yfol8G8jwbUpNz79iPaJYd frL+Ng6ED1nTdFnDBqOJGs60TBQiaik= X-Google-Smtp-Source: ABdhPJwmmGIl3QOZwkUjrlKJO0XkNf+OAvwwENmkPQhXvkDs2g1dB6bvLcSHvVTLBlc5IkkkfS8F2Q== X-Received: by 2002:a63:6243:: with SMTP id w64mr7402760pgb.430.1604310698380; Mon, 02 Nov 2020 01:51:38 -0800 (PST) Received: from localhost.localdomain ([122.179.32.56]) by smtp.gmail.com with ESMTPSA id x15sm467062pjh.21.2020.11.02.01.51.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2020 01:51:37 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, allison.henderson@oracle.com Subject: [PATCH V9 13/14] xfs: Process allocated extent in a separate function Date: Mon, 2 Nov 2020 15:20:47 +0530 Message-Id: <20201102095048.100956-14-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201102095048.100956-1-chandanrlinux@gmail.com> References: <20201102095048.100956-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 935f2d506748..88db23afc51c 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -3509,6 +3509,48 @@ xfs_bmap_compute_alignments( } } +static void +xfs_bmap_process_allocated_extent( + struct xfs_bmalloca *ap, + struct xfs_alloc_arg *args, + xfs_fileoff_t orig_offset, + xfs_extlen_t orig_length) +{ + int nullfb; + + nullfb = ap->tp->t_firstblock == NULLFSBLOCK; + + /* + * check the allocation happened at the same or higher AG than + * the first block that was allocated. + */ + ASSERT(nullfb || + XFS_FSB_TO_AGNO(args->mp, ap->tp->t_firstblock) <= + XFS_FSB_TO_AGNO(args->mp, args->fsbno)); + + ap->blkno = args->fsbno; + if (nullfb) + ap->tp->t_firstblock = args->fsbno; + ap->length = args->len; + /* + * If the extent size hint is active, we tried to round the + * caller's allocation request offset down to extsz and the + * length up to another extsz boundary. If we found a free + * extent we mapped it in starting at this new offset. If the + * newly mapped space isn't long enough to cover any of the + * range of offsets that was originally requested, move the + * mapping up so that we can fill as much of the caller's + * original request as possible. Free space is apparently + * very fragmented so we're unlikely to be able to satisfy the + * hints anyway. + */ + if (ap->length <= orig_length) + ap->offset = orig_offset; + else if (ap->offset + ap->length < orig_offset + orig_length) + ap->offset = orig_offset + orig_length - ap->length; + xfs_bmap_btalloc_accounting(ap, args); +} + STATIC int xfs_bmap_btalloc( struct xfs_bmalloca *ap) /* bmap alloc argument struct */ @@ -3701,36 +3743,10 @@ xfs_bmap_btalloc( return error; ap->tp->t_flags |= XFS_TRANS_LOWMODE; } + if (args.fsbno != NULLFSBLOCK) { - /* - * check the allocation happened at the same or higher AG than - * the first block that was allocated. - */ - ASSERT(ap->tp->t_firstblock == NULLFSBLOCK || - XFS_FSB_TO_AGNO(mp, ap->tp->t_firstblock) <= - XFS_FSB_TO_AGNO(mp, args.fsbno)); - - ap->blkno = args.fsbno; - if (ap->tp->t_firstblock == NULLFSBLOCK) - ap->tp->t_firstblock = args.fsbno; - ap->length = args.len; - /* - * If the extent size hint is active, we tried to round the - * caller's allocation request offset down to extsz and the - * length up to another extsz boundary. If we found a free - * extent we mapped it in starting at this new offset. If the - * newly mapped space isn't long enough to cover any of the - * range of offsets that was originally requested, move the - * mapping up so that we can fill as much of the caller's - * original request as possible. Free space is apparently - * very fragmented so we're unlikely to be able to satisfy the - * hints anyway. - */ - if (ap->length <= orig_length) - ap->offset = orig_offset; - else if (ap->offset + ap->length < orig_offset + orig_length) - ap->offset = orig_offset + orig_length - ap->length; - xfs_bmap_btalloc_accounting(ap, &args); + xfs_bmap_process_allocated_extent(ap, &args, orig_offset, + orig_length); } else { ap->blkno = NULLFSBLOCK; ap->length = 0; From patchwork Mon Nov 2 09:50:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11873307 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 555EB92A for ; Mon, 2 Nov 2020 09:51:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 25D0D2231B for ; Mon, 2 Nov 2020 09:51:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LZQGFlq4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728320AbgKBJvm (ORCPT ); Mon, 2 Nov 2020 04:51:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727992AbgKBJvm (ORCPT ); Mon, 2 Nov 2020 04:51:42 -0500 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DE08C0617A6 for ; Mon, 2 Nov 2020 01:51:42 -0800 (PST) Received: by mail-pf1-x42a.google.com with SMTP id 13so10647084pfy.4 for ; Mon, 02 Nov 2020 01:51:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JY7PSL2jtZpjmLJCkuMiClT+t7I6jD0eXHUkh1nADlo=; b=LZQGFlq4yO+UFMLGkuTRSWJc20S0JTVt3iJDPWl5M1o3q22Lw/V7+vwYnqjwxrjVD6 A7t8izxCGexc490jLfrGhBRHn+AemqictYRe6P+RqqBfLpV73oU3KgUxQJa0yEPn1LUS brzt1suYM1ms0qcLVyrRy6NyyjTKr1hW3+d2ModqnWaLbnSvKGja5Z+v81VNtVJnBc22 qGhPVtpH6x/53M2Ily1hazEW3kP3VYgUyYV9lvTClRJMORZYQU4oDjT21eETXouQc4kG KfmoltzwNTKSxkKT4bbetJdWfBlGEGZRQYeYf5qvZaYsf6+OetXhBcTJqxHVMHqCRKxD chMg== 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=JY7PSL2jtZpjmLJCkuMiClT+t7I6jD0eXHUkh1nADlo=; b=gNPQz9eXowXLMzixrJuDt/hDE1naGj8FZF3KEY4cG3dQ1IPAyR46L82Pulc+wsrodB iS3WGeVA/rL/4OFhm1AodecYD0C2LHPIPtOOzeWZbqTXGsX6AOR2h3tZ1/7MgfBd7f0A ut1KzfM0QRoz5mnnSi/7HxtxuH2u/ufHqeGDtthA7exs+xLIqODCkr8TpClHD7UtCg/b XqUdysD65mp+Ra06snRIeHP3HO0+mrkFhJmliBfI37UkRt5KSOLoVKg1YAw9GqLzRaPf uZWw7jZDXwUZzaQtDOlUe+nBoinzLLNkCRd6xpDG31rMGVEh2rxISKzYdqOJHAMuo6Vk 4i4g== X-Gm-Message-State: AOAM533DDpQgcQNLblmYWw0lSfYIOFMgQWEStqGFRkCWhQoM5MhxjbNg cjwbr7fvJZh3xpxN0gGYDFZ+7k/VLLM= X-Google-Smtp-Source: ABdhPJweVpvqW9sBQ5V5QMpfFwE9oo1N0BmdHV4ArdyjxXhG0r0TzvwwLUZ/TKQpBO6upXcmdJjAWA== X-Received: by 2002:a17:90a:182:: with SMTP id 2mr10350818pjc.21.1604310701613; Mon, 02 Nov 2020 01:51:41 -0800 (PST) Received: from localhost.localdomain ([122.179.32.56]) by smtp.gmail.com with ESMTPSA id x15sm467062pjh.21.2020.11.02.01.51.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2020 01:51:40 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, allison.henderson@oracle.com Subject: [PATCH V9 14/14] xfs: Introduce error injection to allocate only minlen size extents for files Date: Mon, 2 Nov 2020 15:20:48 +0530 Message-Id: <20201102095048.100956-15-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201102095048.100956-1-chandanrlinux@gmail.com> References: <20201102095048.100956-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 | 50 +++++++++++++ fs/xfs/libxfs/xfs_alloc.h | 3 + fs/xfs/libxfs/xfs_bmap.c | 139 +++++++++++++++++++++++++++-------- fs/xfs/libxfs/xfs_errortag.h | 4 +- fs/xfs/xfs_error.c | 3 + 5 files changed, 167 insertions(+), 32 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 88db23afc51c..4717c5f1808e 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -3463,22 +3463,21 @@ xfs_bmap_btalloc_accounting( args->len); } -static void +static int xfs_bmap_compute_alignments( struct xfs_bmalloca *ap, - struct xfs_alloc_arg *args, - int *stripe_align) + 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 */ - *stripe_align = 0; if (mp->m_swidth && (mp->m_flags & XFS_MOUNT_SWALLOC)) - *stripe_align = mp->m_swidth; + stripe_align = mp->m_swidth; else if (mp->m_dalign) - *stripe_align = mp->m_dalign; + stripe_align = mp->m_dalign; if (ap->flags & XFS_BMAPI_COWFORK) align = xfs_get_cowextsz_hint(ap->ip); @@ -3507,6 +3506,8 @@ xfs_bmap_compute_alignments( if (args->mod) args->mod = args->prod - args->mod; } + + return stripe_align; } static void @@ -3551,36 +3552,103 @@ xfs_bmap_process_allocated_extent( xfs_bmap_btalloc_accounting(ap, args); } +#ifdef DEBUG +static int +xfs_bmap_exact_minlen_extent_alloc( + struct xfs_bmalloca *ap) +{ + struct xfs_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; + + args.alloc_minlen_only = 1; + + 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) /* bmap alloc argument struct */ { - 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; /* mount point structure */ + struct xfs_alloc_arg args = { .tp = ap->tp, .mp = mp }; + xfs_alloctype_t atype = 0; /* type for allocation routines */ + 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; - mp = ap->ip->i_mount; - - memset(&args, 0, sizeof(args)); - args.tp = ap->tp; - args.mp = mp; - - xfs_bmap_compute_alignments(ap, &args, &stripe_align); + stripe_align = xfs_bmap_compute_alignments(ap, &args); nullfb = ap->tp->t_firstblock == NULLFSBLOCK; fb_agno = nullfb ? NULLAGNUMBER : XFS_FSB_TO_AGNO(mp, @@ -4112,7 +4180,11 @@ xfs_bmap_alloc_userdata( return xfs_bmap_rtalloc(bma); } - return xfs_bmap_btalloc(bma); + if (unlikely(XFS_TEST_ERROR(false, mp, + XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT))) + return xfs_bmap_exact_minlen_extent_alloc(bma); + else + return xfs_bmap_btalloc(bma); } static int @@ -4148,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, };