From patchwork Fri Aug 14 08:08:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11713815 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 C41C0739 for ; Fri, 14 Aug 2020 08:09:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AC22E2068E for ; Fri, 14 Aug 2020 08:09:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="B+BwYPqg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726895AbgHNIJn (ORCPT ); Fri, 14 Aug 2020 04:09:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726124AbgHNIJm (ORCPT ); Fri, 14 Aug 2020 04:09:42 -0400 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 6000CC061383 for ; Fri, 14 Aug 2020 01:09:42 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id d19so4161117pgl.10 for ; Fri, 14 Aug 2020 01:09:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jHxSR/pm2ySJla9ecEacKlDwTrfPRZHpq7fjIF3KGuc=; b=B+BwYPqgPa4nvP2Fs9GFbi3EQsmJpmUseCqklQCij+rtwoyUqx8jTxPYiJxicxqvHg W8+XarEdVFZ4lox3UPcZX/aVT708Anrr9aUAkD/VfLd/p50zImNs9kfhmh76d52hEVde iARMij4j5tBSHTXF8OgUWiZT6RaWIHpNNAXikeETwZu/ndNW0rXjVBGmXkAGDl3DsE/R UXO1OaBCZ4GCfXMrz78jRS0UK7Q+PMIG8br500m859Uzqfn9R5JQ7lwhl9zArxn2sfvY Waa7eNf1RyhQEa4CUjwndH5TSpDmiWsq44RybKrIUdkNqDVV/Swds18JPp/88nCcNR+i FxYQ== 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=jHxSR/pm2ySJla9ecEacKlDwTrfPRZHpq7fjIF3KGuc=; b=UB4UsKZAgWGPzheoSnGGjht6N1RvsoJDLcX2KdsLar55H8o/LgJoZh97QcPTF8yEm/ T9iVjzsxTV1sq2bSncHODgCXtX5HrTk5WGjQ+xL6HhuRfd0+UDw42y6cJUK9/TA1yrHV 1dlcZSqFevZXI2FlDyXXchVycdJY7GZmxHm24oSZp3+2DpouHE28+SKUGFVl5/QzfW1Y TTkyOKOQJ4hosd3o2EQjDEWYlfW56h0N25ogDDH7AHSAsWxLmrm+/BvfWZC8ccfjLTQz vJflmdnndyzCYykFA4a/3nUUNS21pUVK/3fvcaqm44MQd4zQ596Ei0+A/109bwApbeN1 81oA== X-Gm-Message-State: AOAM5331OcaJCpE8aaHfO3rcj8XBrHanaYPzk7ZyqdaVUJ3irv1D9Vir OYBks2xBzeQS5qBZDEa22hqf9d/YLYg= X-Google-Smtp-Source: ABdhPJxw1hEyZFi0NYP8hxPzAesaor2yRsvQFkYXPAC12JrlInP1lB0FkhvAnw2I+IKeNqJqlDSmFQ== X-Received: by 2002:a62:3303:: with SMTP id z3mr1054349pfz.252.1597392581653; Fri, 14 Aug 2020 01:09:41 -0700 (PDT) Received: from localhost.localdomain ([122.179.47.119]) by smtp.gmail.com with ESMTPSA id z17sm8594289pfq.38.2020.08.14.01.09.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Aug 2020 01:09:41 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com Subject: [PATCH V2 01/10] xfs: Add helper for checking per-inode extent count overflow Date: Fri, 14 Aug 2020 13:38:24 +0530 Message-Id: <20200814080833.84760-2-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200814080833.84760-1-chandanrlinux@gmail.com> References: <20200814080833.84760-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Sender: linux-xfs-owner@vger.kernel.org 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 2035 [003] 9643.390490: probe:xfs_iflush_int: (ffffffffac6225c0) if_nextents=98511 inode=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 will not cause the extent counter to overflow. Suggested-by: Darrick J. Wong Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_trans_resv.c | 33 +++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_trans_resv.h | 2 ++ 2 files changed, 35 insertions(+) diff --git a/fs/xfs/libxfs/xfs_trans_resv.c b/fs/xfs/libxfs/xfs_trans_resv.c index d1a0848cb52e..d21990d9df7a 100644 --- a/fs/xfs/libxfs/xfs_trans_resv.c +++ b/fs/xfs/libxfs/xfs_trans_resv.c @@ -832,6 +832,39 @@ xfs_calc_sb_reservation( return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize); } +int +xfs_iext_count_may_overflow( + struct xfs_inode *ip, + int whichfork, + int nr_to_add) +{ + struct xfs_ifork *ifp; + uint64_t max_exts = 0; + uint64_t nr_exts; + + switch (whichfork) { + case XFS_DATA_FORK: + max_exts = MAXEXTNUM; + break; + + case XFS_ATTR_FORK: + max_exts = MAXAEXTNUM; + break; + + default: + ASSERT(0); + break; + } + + ifp = XFS_IFORK_PTR(ip, whichfork); + nr_exts = ifp->if_nextents + nr_to_add; + + if (nr_exts > max_exts) + return -EFBIG; + + return 0; +} + void xfs_trans_resv_calc( struct xfs_mount *mp, diff --git a/fs/xfs/libxfs/xfs_trans_resv.h b/fs/xfs/libxfs/xfs_trans_resv.h index 7241ab28cf84..9d71b51990ac 100644 --- a/fs/xfs/libxfs/xfs_trans_resv.h +++ b/fs/xfs/libxfs/xfs_trans_resv.h @@ -93,5 +93,7 @@ struct xfs_trans_resv { void xfs_trans_resv_calc(struct xfs_mount *mp, struct xfs_trans_resv *resp); uint xfs_allocfree_log_count(struct xfs_mount *mp, uint num_ops); +int xfs_iext_count_may_overflow(struct xfs_inode *ip, int whichfork, + int nr_exts); #endif /* __XFS_TRANS_RESV_H__ */ From patchwork Fri Aug 14 08:08:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11713817 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 5E46C739 for ; Fri, 14 Aug 2020 08:09:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4728B207DA for ; Fri, 14 Aug 2020 08:09:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="c5AbLLsp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726969AbgHNIJp (ORCPT ); Fri, 14 Aug 2020 04:09:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726124AbgHNIJo (ORCPT ); Fri, 14 Aug 2020 04:09:44 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9162C061383 for ; Fri, 14 Aug 2020 01:09:44 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id u20so4202198pfn.0 for ; Fri, 14 Aug 2020 01:09:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zwsByGDQ/Brl0QGJOkczOMSoK9UiaUPqznnIa4fy0hQ=; b=c5AbLLspqYVnAwTHiv8ix6jzHdPF0BtUB3QDgVD1gOh4FzUREPDQejTwd8RyolDPpD 5FdiCADp3oKZEdbTpUtCaXtr0aGttwa6fv0RoNGYL1GVu5ZJDJca+09sk5IpeBUGarFn sV/DukqfesH+45p9RZeX4unWnJrxnz5G5EguX/oC2/10nrCJhjQYGnQNsNfuFAUvDz++ qVjsNPBDlNGqnB+OENkf/Ylgr8RPouX+kUx5S9UAwMOUe5ZeSVjcgLe69WXDk/hwSFAr 4NJhxvP6gsjkyqsOtOWPFwJlJ6RJK7pi7REempHJICIeEZ6DDw5H7wafGgPRfWmThayh IElA== 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=zwsByGDQ/Brl0QGJOkczOMSoK9UiaUPqznnIa4fy0hQ=; b=Svgg7DNMX/cRTOm0bc7ne3hnwGQ2wo/7dPXheSb5QYBkiUAm43K2eFyIYtlO1tjxwX KWKpgcOkMVh3cfTDLDsmYdHC3rg4AblFWL6oiEXHmCai1CnTrJPl+K+gRX9HXDWEKBVa Heuat4Rb5EbRls+ve+nD0gbGSQ6wMMDBumm7/3CbZZoG3BUOfvsdLYKpPyV8+VNjmuNl tUx/ZBM92BQUGPzIIBfLPOreK1dIKDXFLvTYRBZ38dGNwjDKT+UP5eEW4MLx3X1yj0b7 WYXqi67MNaHwlpJl9viteW7o7DtR9SnPHvD9H03MzhEysonlfEiQxaFDkC3sX5xytp6B wv3w== X-Gm-Message-State: AOAM532XTmiSKEBoSBscDFptl5KljoYcOhH1TyyRwzPKSSAle6YqAD3H bgwmOXB7c1B0pls7KnGr3aZSDqsFRh4= X-Google-Smtp-Source: ABdhPJy7dpt67l+hlRQ5oyfJ/mCfXgYv7WS9MEQIc6U0lFoAnH3vtfAFG25h0JnIvHfNIS88PytFbw== X-Received: by 2002:a62:82c1:: with SMTP id w184mr1048752pfd.202.1597392583993; Fri, 14 Aug 2020 01:09:43 -0700 (PDT) Received: from localhost.localdomain ([122.179.47.119]) by smtp.gmail.com with ESMTPSA id z17sm8594289pfq.38.2020.08.14.01.09.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Aug 2020 01:09:43 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com Subject: [PATCH V2 02/10] xfs: Check for extent overflow when trivally adding a new extent Date: Fri, 14 Aug 2020 13:38:25 +0530 Message-Id: <20200814080833.84760-3-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200814080833.84760-1-chandanrlinux@gmail.com> References: <20200814080833.84760-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org When adding a new data extent (without modifying an inode's existing extents) the extent count increases only by 1. This commit checks for extent count overflow in such cases. Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_bmap.c | 8 ++++++++ fs/xfs/libxfs/xfs_inode_fork.h | 2 ++ 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 +++++ 6 files changed, 32 insertions(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 9c40d5971035..e64f645415b1 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -4527,6 +4527,14 @@ xfs_bmapi_convert_delalloc( return error; xfs_ilock(ip, XFS_ILOCK_EXCL); + + if (whichfork == XFS_DATA_FORK) { + error = xfs_iext_count_may_overflow(ip, whichfork, + XFS_IEXT_ADD_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 a4953e95c4f3..3e7e4b980d49 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -34,6 +34,8 @@ 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 */ +#define XFS_IEXT_ADD_CNT 1 + /* * Fork handling. */ diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index afdc7f8e0e70..c470f2cd6e66 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_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 04dc2be19c3a..1293e7a752c8 100644 --- a/fs/xfs/xfs_dquot.c +++ b/fs/xfs/xfs_dquot.c @@ -290,8 +290,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_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 0e3f62cde375..0af679ef9a33 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_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 6209e7b6b895..c2bca6ad2533 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -787,6 +787,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_CNT); + if (error) + goto out_trans_cancel; + /* * Allocate blocks to the bitmap file. */ From patchwork Fri Aug 14 08:08:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11713819 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 A66E0739 for ; Fri, 14 Aug 2020 08:09:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8E878207DA for ; Fri, 14 Aug 2020 08:09:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="n0PwIP06" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726971AbgHNIJr (ORCPT ); Fri, 14 Aug 2020 04:09:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726124AbgHNIJr (ORCPT ); Fri, 14 Aug 2020 04:09:47 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3AB4C061383 for ; Fri, 14 Aug 2020 01:09:46 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id i92so5348882pje.0 for ; Fri, 14 Aug 2020 01:09:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=axLzhupzIrWw+rrgJQfKNHh/9nAL8yvvXXMYamkBd/M=; b=n0PwIP06lmxRl4agzJZMLtCHDwVmMo6VYSXdqm77bHXVhonPKxyv0fasX6ExmTRzE+ EvqpMNHZLTOw27inf7ThIiKtszBj6MdbKajJXYKkTO8cNul0uT9gxmYOtc7YKt1lgqiN sMv4MACwa3Nmms47/KiyiNDpWbH6cHykvc58aRU2+S16IqwTVZ8XyQdqzla4PFMxmScC uHRxsg8XJ7kPBTOiGdsJm5oFPpB5vp2XV0HORK6S9fDus+Qbc/EIppkSYq1x6zAWNW+N X5vuc2ghtd9eDafd4eDPKrOPejPotpxM9Bz8NxAKTzvhRPtnGM3QISld4UhUp5SVk7oE d2uA== 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=axLzhupzIrWw+rrgJQfKNHh/9nAL8yvvXXMYamkBd/M=; b=odGV61byQS2UI79xK7T+gVd/mDJEP+qVUM3or3aXt5kkdH/rHgS/0xgBZXHnwuIx7n dfUceQ8Z/LRjbxvBemzrsIZ/+Naqflp12PH+QMNIRmq9H1VHWDVNLaLBi9czf7M9rdqV 6bgcT5mZDjO0ksNTRj/BZcalk5LSGmc4HAwSxuhdl/CCwzpBb7EDMw4gWqfv1fyogGbJ lrf9YYe4qz1HmsmciEKrKlQ80SdVh5bp6u8jLoThW0PvvbQiDTABil8p6kWFb5bnqOzv oxxoVEGgdxGOiyp0EjH5b7y46Xifm18rwMAySVBlpH0cVCmA1d0GkmLJcD5eDRa/8nQq tYiA== X-Gm-Message-State: AOAM531NNGPuye//7X1PJAWcZfviXCELTINn5FFspGENN5gkPc0UeEeV d88J0rawlxxJSa+YatGysJ7M50OXqT8= X-Google-Smtp-Source: ABdhPJwHDeXs5gHpZEHjTsroZ3nSqwaWLm/x4488YJ0xmjbSnl+bBwXCER3oeBMcCZVFTPv26eX+Cw== X-Received: by 2002:a17:90b:816:: with SMTP id bk22mr1360140pjb.185.1597392586299; Fri, 14 Aug 2020 01:09:46 -0700 (PDT) Received: from localhost.localdomain ([122.179.47.119]) by smtp.gmail.com with ESMTPSA id z17sm8594289pfq.38.2020.08.14.01.09.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Aug 2020 01:09:45 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com Subject: [PATCH V2 03/10] xfs: Check for extent overflow when deleting an extent Date: Fri, 14 Aug 2020 13:38:26 +0530 Message-Id: <20200814080833.84760-4-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200814080833.84760-1-chandanrlinux@gmail.com> References: <20200814080833.84760-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Deleting a file range from the middle of an existing extent can cause the per-inode extent count to increase by 1. This commit checks for extent count overflow in such cases. Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_inode_fork.h | 6 ++++++ fs/xfs/xfs_bmap_item.c | 4 ++++ fs/xfs/xfs_bmap_util.c | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index 3e7e4b980d49..228359cf9738 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -35,6 +35,12 @@ struct xfs_ifork { #define XFS_IFBROOT 0x04 /* i_broot points to the bmap b-tree root */ #define XFS_IEXT_ADD_CNT 1 +/* + * Removing 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_REMOVE_CNT 1 /* * Fork handling. diff --git a/fs/xfs/xfs_bmap_item.c b/fs/xfs/xfs_bmap_item.c index ec3691372e7c..b9c35fb10de4 100644 --- a/fs/xfs/xfs_bmap_item.c +++ b/fs/xfs/xfs_bmap_item.c @@ -519,6 +519,10 @@ xfs_bui_item_recover( } xfs_trans_ijoin(tp, ip, 0); + error = xfs_iext_count_may_overflow(ip, whichfork, XFS_IEXT_REMOVE_CNT); + if (error) + goto err_inode; + count = bmap->me_len; error = xfs_trans_log_finish_bmap_update(tp, budp, type, ip, whichfork, bmap->me_startoff, bmap->me_startblock, &count, state); diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index c470f2cd6e66..94abdb547c7f 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_REMOVE_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; From patchwork Fri Aug 14 08:08:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11713821 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 8A2FC13B1 for ; Fri, 14 Aug 2020 08:09:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 71D9320771 for ; Fri, 14 Aug 2020 08:09:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="oz6kZl6j" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726973AbgHNIJu (ORCPT ); Fri, 14 Aug 2020 04:09:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726124AbgHNIJt (ORCPT ); Fri, 14 Aug 2020 04:09:49 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 569B7C061383 for ; Fri, 14 Aug 2020 01:09:49 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id r11so4176749pfl.11 for ; Fri, 14 Aug 2020 01:09:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8W5cvIIWzE9EtYvDSv/lTYlra3JGo7xOtylNStP0mK4=; b=oz6kZl6jExRxBAibBSYiOTbsMA2nQ3qd0kcI/SFuP6SA8Yk9xZrD9aCT68HXAaW/0a iuhTr+9y2eDm81bZBKave1k2hJAoAnhBoYu5XUxOpJ2gHlH5KQcCb8MyCr9QwhVXMBOI 92evs5m68vUIGVFls9VZlRUqmgApV5iqkPQneZASLezxNEH0Q79I5PWVW/Cxiin/Ph4o TVOBXfx9vi2R1aYq+M190ffDDCbMTWsFh3ybH3co5law7KpkBptBuCtNlRbGfzIuF7wI kTIMS91oiHUCMPts8Synh5PptXKYOUK/WkQ3ASa781PVZC8QWW0u200aOq6Wpo1dHPxf qGbQ== 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=8W5cvIIWzE9EtYvDSv/lTYlra3JGo7xOtylNStP0mK4=; b=iicOeWZOiUS7iDm0hMIUl41vEleVS1W9mFvxnVjDbVxYf/hnPlcZsIWLhKiEMQUcyK ZFYH7XvRQN6Kf5Rdzd1WqnYBQiRvBsfjgl/eLg/DES75d4QINssG6DJUXG+U7tIwr1KE zd4tjh28TqIVEOugWAuX8VOvZuDUp55HicS2yvo8/iokPcfu7qdMMfon9HULbwate90Q QznJMr74sxx1OPx1kHDo4Bv4OsxxlN9GbfVB8FKFcIscw33+vkhyKXy1zmlzsauvmThs e2fHI39guF1RrypjtvjTcNOiYxyR+eLHoc656wqkfKmh+AcoXAF8p3SImuG1/ZZOWCwa Cpgw== X-Gm-Message-State: AOAM530pJWypK905QSnxKkZbHdlZZjlPrTveC4Vg0ksHJ+xwqw5xPymE JSAXJeLc+FhmyofRa2+MiUUoclvfAoM= X-Google-Smtp-Source: ABdhPJwB8WH9RZLXAR2qEm2IjVNJtOZcnbiAy3egBEPswIrWK3QMvssCpdl6AjXwWRgkhVHtqIvoAg== X-Received: by 2002:a63:dc4a:: with SMTP id f10mr986504pgj.394.1597392588597; Fri, 14 Aug 2020 01:09:48 -0700 (PDT) Received: from localhost.localdomain ([122.179.47.119]) by smtp.gmail.com with ESMTPSA id z17sm8594289pfq.38.2020.08.14.01.09.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Aug 2020 01:09:48 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com Subject: [PATCH V2 04/10] xfs: Check for extent overflow when adding/removing xattrs Date: Fri, 14 Aug 2020 13:38:27 +0530 Message-Id: <20200814080833.84760-5-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200814080833.84760-1-chandanrlinux@gmail.com> References: <20200814080833.84760-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Adding/removing an xattr can cause XFS_DA_NODE_MAXDEPTH extents to be added. One extra extent for dabtree in case a local attr is large enough to cause a double split. It can also cause extent count to increase proportional to the size of a remote xattr's value. Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_attr.c | 13 +++++++++++++ fs/xfs/libxfs/xfs_inode_fork.h | 9 +++++++++ 2 files changed, 22 insertions(+) diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c index d4583a0d1b3f..c481389da40f 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 228359cf9738..72a9daf5df16 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -41,6 +41,15 @@ struct xfs_ifork { * i.e. | Old extent | Hole | Old extent | */ #define XFS_IEXT_REMOVE_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 Fri Aug 14 08:08:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11713823 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 3E12E13B1 for ; Fri, 14 Aug 2020 08:09:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 25EF520771 for ; Fri, 14 Aug 2020 08:09:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dZ0TI9ao" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726976AbgHNIJw (ORCPT ); Fri, 14 Aug 2020 04:09:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726124AbgHNIJv (ORCPT ); Fri, 14 Aug 2020 04:09:51 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6A1BC061383 for ; Fri, 14 Aug 2020 01:09:51 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id f10so3831271plj.8 for ; Fri, 14 Aug 2020 01:09:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bFfR12tqZBInOj7X6PLo9DGMHuPa9ErXDt7MBFGap3Q=; b=dZ0TI9aorHOILacrh8gq6vHDv0LrFq9ePCCcpremLFAZqLfE9GhNaBtNGOD5p89Fy2 mfi9afOtOB0ihtTy0bx4Khnz2st6UKd8XkxICAFTVJn5TmFOCXpXyD9cNe5ELaygxpsz MDwz5TX1JMCqBVrrpvnF74l0hrhaKuJPGmunX4a5xXK6fu+Tx0Dh7wRj2CsXsPdaNaG/ D2Z+QBL2j2T+41Sx3WxuP2b3+1HzQz0iPb4uD44vQ1WfASj+dksv8nlLyU6oiXEUXkj0 233KOmWFtfKyfv6LYCBfQrwArV55y7EVfrum643YILOtn+OmsW2zfHbDMYNOQgeHLI0d zqhQ== 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=bFfR12tqZBInOj7X6PLo9DGMHuPa9ErXDt7MBFGap3Q=; b=PTN5jaCpIYa/G4lTsL9LMu94IW+1x7t0kfVA55d7Bp7+LMwYIzNAUse8WYfCqJwHxt g78+O0gMjXPqJe6PvzePf0kBv/aorFi/MOsjq2N+nXux9UDmB9vIEdECV50WZigkJpSv PXE1k358o4qECpekUH1N7MxeqTXCb5mU7QN/yiF67BiW9WFk/A8FugQdGDDgED1XsVX+ lHEC7IRI+X3GyCtQmpJeiZd14EKTYi275of2UpBdQRRfyZtovPyDfGxS5RN9onCd37PQ oC9REbXupBLMbVEeHN/Fif0sB6AYmLiCR1hT9CzRgvyLRjo8hD9kh4ItF5FaBYfOANCr f/WQ== X-Gm-Message-State: AOAM531W9QeEyswHP0TEGcQ8M2ddCqdw6n+oIdXFl7M4sAItpeFdOswO fzHOgq1AZRTISMtUZHBKr0oxsQUdijc= X-Google-Smtp-Source: ABdhPJy5OQIiwIZRJhg/PmxXJ7sV8b9Z+PZEp09EYcB3vxvxncaQdsLi2UFE0LCJYpLXiG2ZXwK7yA== X-Received: by 2002:a17:90a:36ee:: with SMTP id t101mr1401435pjb.47.1597392590987; Fri, 14 Aug 2020 01:09:50 -0700 (PDT) Received: from localhost.localdomain ([122.179.47.119]) by smtp.gmail.com with ESMTPSA id z17sm8594289pfq.38.2020.08.14.01.09.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Aug 2020 01:09:50 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com Subject: [PATCH V2 05/10] xfs: Check for extent overflow when adding/removing dir entries Date: Fri, 14 Aug 2020 13:38:28 +0530 Message-Id: <20200814080833.84760-6-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200814080833.84760-1-chandanrlinux@gmail.com> References: <20200814080833.84760-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Sender: linux-xfs-owner@vger.kernel.org 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. 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 72a9daf5df16..e39ce09a824f 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -50,6 +50,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 407d6299606d..8d195b6ef326 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -1175,6 +1175,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 @@ -1391,6 +1396,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 Fri Aug 14 08:08:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11713825 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 3CEB7739 for ; Fri, 14 Aug 2020 08:09:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2444420771 for ; Fri, 14 Aug 2020 08:09:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hnYH9ZRz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726979AbgHNIJy (ORCPT ); Fri, 14 Aug 2020 04:09:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726124AbgHNIJy (ORCPT ); Fri, 14 Aug 2020 04:09:54 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01051C061383 for ; Fri, 14 Aug 2020 01:09:54 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id c6so4051883pje.1 for ; Fri, 14 Aug 2020 01:09:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rO4iHtZIMFEfgqsFUNnGKzsFXKqfUXz/pnT3iA7Os4o=; b=hnYH9ZRz/A3K1al8xWJOujVIVGMFzCATuCL5jgg0y9MJeflIaCRIksw+M1tln/3Pxw 0C0a4ieZ0z2IJrTge8SSh72QcF4bA+xiJg3oFHtRrERb16nkbhywdX4NjFvfUIsEDB/P LJ1muCrJSaCbeucLaMuvwqBqcT95FzkrE3XMzQmGI3qPQY/SLskAGTFw1frbhpplkea8 r8CoZxJWXdzRiG/3CQNF4DsgOIVSso40c1k39KCh7hSmHcPKa1xZ/vFBsKGt7GIFtpS0 SokcaUJjUcmKy8PQD7DEHyNBtk+bsyGv+HHE2Dstslxmx0MAvqWySmeRyo14zS4HWIIV EwCw== 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=rO4iHtZIMFEfgqsFUNnGKzsFXKqfUXz/pnT3iA7Os4o=; b=pLsbFt2KZ9nbYpCh+IC0C3uo3zpyJownaxNvGvrQd29VFPzdVy8NdxZW3DJgomjt71 GAT+bfhLllaumVO4Bo2cNgJB4eFhhgTNlD7eMt8BBkaUjunekixtq3i6lvWVML/i73r4 cae8T1MV7Q2z/wmAOc+n4eJsvnbECgsUX0UQeNSV3B9+CUlCvgNF4Ha2iHuyGTn3E1Wg lEJtzQ1QQOVUjyz8KMYwFeb2ksaSlc041ciO/rXtkZxaQd0MF6ME+RJBLd5rQRHSAtce RPuryJixpMzpQZafW7z8M9bPTa5iR0y94n7a0Xchvc1B/LFdJl5QII70pigQMJrLFVyy jA/A== X-Gm-Message-State: AOAM532rm3GoYCPWI3yBDoC6PmOyp5E913aLnmBcXa20IYQQsunzmZt+ qs+gTq0zD7Im/YZUSD2TcP235Ye+9k8= X-Google-Smtp-Source: ABdhPJxNq6IAY05T0+6HSMUKa3T20drFbhGB4Qu0XB/Tj2dpizmOs7AakUjtKOZNB0GWTGTs1OHbIg== X-Received: by 2002:a17:90a:f68a:: with SMTP id cl10mr1352893pjb.40.1597392593303; Fri, 14 Aug 2020 01:09:53 -0700 (PDT) Received: from localhost.localdomain ([122.179.47.119]) by smtp.gmail.com with ESMTPSA id z17sm8594289pfq.38.2020.08.14.01.09.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Aug 2020 01:09:52 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com Subject: [PATCH V2 06/10] xfs: Check for extent overflow when writing to unwritten extent Date: Fri, 14 Aug 2020 13:38:29 +0530 Message-Id: <20200814080833.84760-7-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200814080833.84760-1-chandanrlinux@gmail.com> References: <20200814080833.84760-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Sender: linux-xfs-owner@vger.kernel.org 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. Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_inode_fork.h | 7 +++++++ fs/xfs/xfs_iomap.c | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index e39ce09a824f..a929fa094cf6 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -63,6 +63,13 @@ 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 0af679ef9a33..81cccd4abcc6 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 Fri Aug 14 08:08:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11713827 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 82EB7739 for ; Fri, 14 Aug 2020 08:09:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6BAE6207DA for ; Fri, 14 Aug 2020 08:09:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="C7GJXEE7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726982AbgHNIJ4 (ORCPT ); Fri, 14 Aug 2020 04:09:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726124AbgHNIJ4 (ORCPT ); Fri, 14 Aug 2020 04:09:56 -0400 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B31AC061383 for ; Fri, 14 Aug 2020 01:09:56 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id o5so4179821pgb.2 for ; Fri, 14 Aug 2020 01:09:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4CkmlP/B7k+Voc2v/ccKv01lAP2YLLq8ob4/AXbjbJw=; b=C7GJXEE7M3ZnXe0ttzpxogf4fl65CZLZiNmkKTnMyXtLlC4qJ7Gan5Enpr7rhysIUw i49WXPPgt7NQJI5hsT9Ii1PS/wNbQlQstHoQRr70gyfKxr6k6nW3+BxHJ82ORIk0Hk8Z U+ErcKwn7Dg7ib7y2Hl+YuqvgbqCq4zWliwWDHsVf9IgcuTay0eBkfLx/qbHTgLIwnGk yoKgffr6G/XYOCYAxSY9fvBXMOMansW70PjOpceEnEXDIvURyQyWYw6aEm2GQopd4WrY 4Wr3DT8GrKK2wKJY5zM/EZN8/vDgHpbiE4Aod+JwjyKBqjCIlCJR1Ku2fb/BFe6tBchN Rvbw== 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=4CkmlP/B7k+Voc2v/ccKv01lAP2YLLq8ob4/AXbjbJw=; b=I1JJZVAx48QKAF2gb0Gmcm4WdftCGBBBtbpJ1MTUq1VjyOIwzxdFVwNHmgDL/pXeA1 Uo5onCwDg5m9rBWPUtDWQw3vec9JOiJ2DQYLlJr1FTqOaex5HRaUUBaznceTH1Dkk8Fx lV4tetxcIYnBmjFUhIcksn8IM80I6Zt1qcI/uEEZg1aZ35S9YIiai8tGxrlI7Jn2Xmlq 7zk+Gf5dCMn2kcbXFOd4QJyd7FkWK8uTcW/58khXx8kmtbynF8mOYRXlhSWYCyPkjLqZ i4Cy39iMDHmE7mndz+nwPnCiDO2tM/5x51ZIOX0CuRA/iUMYNFwUCwGlP5t5fB4FMzWY F19Q== X-Gm-Message-State: AOAM530ZPCwa+iTTHLlu+miQKgr6hco4PEij+OAxyiOBYRfrdjr6Z56K TQWsYC2+8lAz9GoGtAa5nWAp/d6/vTY= X-Google-Smtp-Source: ABdhPJyUTW8G5st3wSzc6VT2H1ru9F00nmLOuxFiW3z+7UdKG8GwPcNMmF4kvcu254uI6fe+XpJB/A== X-Received: by 2002:a63:4f1b:: with SMTP id d27mr970697pgb.389.1597392595639; Fri, 14 Aug 2020 01:09:55 -0700 (PDT) Received: from localhost.localdomain ([122.179.47.119]) by smtp.gmail.com with ESMTPSA id z17sm8594289pfq.38.2020.08.14.01.09.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Aug 2020 01:09:55 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com Subject: [PATCH V2 07/10] xfs: Check for extent overflow when inserting a hole Date: Fri, 14 Aug 2020 13:38:30 +0530 Message-Id: <20200814080833.84760-8-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200814080833.84760-1-chandanrlinux@gmail.com> References: <20200814080833.84760-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org The extent mapping the file offset at which a hole has to be inserted will be split into two extents causing extent count to increase by 1. Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_inode_fork.h | 6 ++++++ fs/xfs/xfs_bmap_util.c | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index a929fa094cf6..63f83a13e0a8 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -70,6 +70,12 @@ struct xfs_ifork { * Hence extent count can increase by 2. */ #define XFS_IEXT_WRITE_UNWRITTEN_CNT 2 +/* + * 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. + */ +#define XFS_IEXT_INSERT_HOLE_CNT 1 /* * Fork handling. diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index 94abdb547c7f..f6352b5e5552 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -1165,6 +1165,15 @@ xfs_insert_file_space( xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, 0); + /* + * Splitting the extent mapping containing stop_fsb will cause + * extent count to increase by 1. + */ + error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + XFS_IEXT_INSERT_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 Fri Aug 14 08:08:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11713829 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 081D213B1 for ; Fri, 14 Aug 2020 08:10:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E4A9D207DA for ; Fri, 14 Aug 2020 08:09:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dBm0Fa2e" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726983AbgHNIJ7 (ORCPT ); Fri, 14 Aug 2020 04:09:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726124AbgHNIJ6 (ORCPT ); Fri, 14 Aug 2020 04:09:58 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A88B7C061383 for ; Fri, 14 Aug 2020 01:09:58 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id kr4so4050452pjb.2 for ; Fri, 14 Aug 2020 01:09:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tlyHPZEKvK+K/Yh1ZPL8iZ8QU0zmi8O2NrxJ/v+wsaM=; b=dBm0Fa2eyAt+EGIiU5TWWgkTtK+sCDbuZdamQGNCy82csoJZ2kng/KBarV2Lh562av /u/1q8qPz0uWY/01viNx2gqJwPoh8x2WjeG/alhT8wqzR3NgfRagYPJTUiikh/pYoqpN xJ8tKJvlqoucW4r3EoT1g4vK/DDXaimJcrQlHCEq8nmeYr0DVP92Y7chpKYZdqZinATU ylpWSpjMLDX3QfJAnaYnd5saE3USlkRalFY04m9hn/2gMP6ZGa6Aw+0SO9h+TrPIergu FPXtol85WSiAMotC4nkXRtrYeAIJm6dnOsPJFg4g7yYYu/ntJ4iiLVaIuELobbWcicbZ Tpmg== 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=tlyHPZEKvK+K/Yh1ZPL8iZ8QU0zmi8O2NrxJ/v+wsaM=; b=S9vUoklYukEa9po638x9OxaBlkVTrQM9muA8NZWswkp+bqBJ79CLqfYxBpYOrzuQ5w 1oO7xGTMQB8jdPryQmYGgSiX8Iy1OV1aiHik4SWnk9HmWL596p/+e0KmNTyEnpMiTh2J T+Fi4LecTDiql/i1Y9b4EswyH2t9R+ZiOsl/OVpDuvGeisRHkj+J34wDFSC2Fjcrlf/o S79C497XYe2pZJ48n9nMhFLJRIpwCFWPwq1q/chdhtzWqBTui9JvPMNKFoSB9BQHHb1r uYekmaIpX6XqX0c3Y4iFtmKE8F97whEp56vm+h/oCcN0gUwpHHNCYqAsDc0v2Az3/gFL Wuvg== X-Gm-Message-State: AOAM5311GlwhzaV3jecRvvJNKQsakyzkvMuas7+6kPSb45g3wwNP1zDr 53yXgaTdYffdOY8xTEHR5pYQvdPe41Q= X-Google-Smtp-Source: ABdhPJw/CdVvAktiEAic7ExoUPrYr3rFbJJw4EFDs3nh1WpE25gZuna3hycUjkxOpHAcscHC1QWR7A== X-Received: by 2002:a17:90a:3549:: with SMTP id q67mr1339346pjb.56.1597392597933; Fri, 14 Aug 2020 01:09:57 -0700 (PDT) Received: from localhost.localdomain ([122.179.47.119]) by smtp.gmail.com with ESMTPSA id z17sm8594289pfq.38.2020.08.14.01.09.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Aug 2020 01:09:57 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com Subject: [PATCH V2 08/10] xfs: Check for extent overflow when moving extent from cow to data fork Date: Fri, 14 Aug 2020 13:38:31 +0530 Message-Id: <20200814080833.84760-9-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200814080833.84760-1-chandanrlinux@gmail.com> References: <20200814080833.84760-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Sender: linux-xfs-owner@vger.kernel.org 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. Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_inode_fork.h | 10 +++++++++- fs/xfs/xfs_reflink.c | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index 63f83a13e0a8..d750bdff17c9 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -76,7 +76,15 @@ struct xfs_ifork { * increase by 1. */ #define XFS_IEXT_INSERT_HOLE_CNT 1 - +/* + * 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 aac83f9d6107..04a7754ee681 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -29,6 +29,7 @@ #include "xfs_iomap.h" #include "xfs_sb.h" #include "xfs_ag_resv.h" +#include "xfs_trans_resv.h" /* * Copy on Write of Shared Blocks @@ -628,6 +629,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 Fri Aug 14 08:08:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11713831 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 6136E739 for ; Fri, 14 Aug 2020 08:10:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 47C2D2068E for ; Fri, 14 Aug 2020 08:10:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iOjVvRid" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726989AbgHNIKB (ORCPT ); Fri, 14 Aug 2020 04:10:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726124AbgHNIKB (ORCPT ); Fri, 14 Aug 2020 04:10:01 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 046B2C061383 for ; Fri, 14 Aug 2020 01:10:01 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id u10so3835978plr.7 for ; Fri, 14 Aug 2020 01:10:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JsRw6B599oq+UPDByCJYf/bZpP5uc5Yihgn4D62MRKs=; b=iOjVvRidRMPl8oVXq2CdDkzGlLSn3z0oiWGcefHfFO85mfL8/yBdHU1EiiWatLy+s5 I04WH2/lUDi3q2qHmrXzgRUBGOJ/CrgX0AFXC6eQKFAXkVJUb3Gyrbx7jFKzUL6nXFPo huFFdI1RoIpswzPW+AWMj5CGF1jOsoHgCE2fgyWNwQkNsbb46taAlgBTZ40gYA4huor8 CYOZV+VkBZYsK7gVr5+biX01jXJRN/Zpw8klvcfcYfpmOZE4oQv2tFKM5bTHR85+bk33 Q2dLDnUZ43EqN1urUj33xgZ1Wa+5UTt5YIGvUxV2eGVWGCbvVrtLIpSkTxsspU4rni+f pZyA== 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=JsRw6B599oq+UPDByCJYf/bZpP5uc5Yihgn4D62MRKs=; b=VlBqumqsKwlJhms925vEMLPU2/oT0s/CrC7XdZ+WaXiv2aN/AvmDYYm5B8gIKxHEzL w8Mt36A4hIqQG5d+X4rDzGGR/Bit6f5bdLwZzgD1X0AYQrtqRFN79drvvyqMineD1tbL niXA253ayVN+M6i1iunt++LDHXOU6RJHcs3OVv/442W2NRseUw6Thp28tZKdgmQhifWH EHk9Sk8koSvb5caBq4po/ZRbpbuSwF8k4VE2vscf5+BNNuXl4O7zo0HpuBXOS+z7+jIR 21YJddanru7UXv1leQu5j3aIqqrbZEaQQUPuaUF/sw7r7zsWZ0BKlgdDt6D90Gy/NCJb blaw== X-Gm-Message-State: AOAM533OOX/Wqq4yTH+TzVpLBeu0sd2KbXD8WqcRi5eXn0cSqG23ez33 WJp9UP11qjKIZQ/hQESWNxaqKBVCqzk= X-Google-Smtp-Source: ABdhPJyW0j2pufYY+YlubFoehDO/GELR/5iFeUVCFkAaIZ1GWBpCThmJUhatRq0Kvdbfy0zolsZZDQ== X-Received: by 2002:a17:90b:b18:: with SMTP id bf24mr1322778pjb.94.1597392600272; Fri, 14 Aug 2020 01:10:00 -0700 (PDT) Received: from localhost.localdomain ([122.179.47.119]) by smtp.gmail.com with ESMTPSA id z17sm8594289pfq.38.2020.08.14.01.09.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Aug 2020 01:09:59 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com Subject: [PATCH V2 09/10] xfs: Check for extent overflow when remapping an extent Date: Fri, 14 Aug 2020 13:38:32 +0530 Message-Id: <20200814080833.84760-10-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200814080833.84760-1-chandanrlinux@gmail.com> References: <20200814080833.84760-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Remapping an extent involves unmapping the existing extent and mapping in the new extent. When unmapping, an extent containing the entire unmap range can be split into two extents, i.e. | Old extent | hole | Old extent | Hence extent count increases by 1. Mapping in the new extent into the destination file can increase the extent count by 1. Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_inode_fork.h | 15 +++++++++++++++ fs/xfs/xfs_reflink.c | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index d750bdff17c9..afff20703270 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -85,6 +85,21 @@ struct xfs_ifork { * Hence number of extents increases by 2. */ #define XFS_IEXT_REFLINK_END_COW_CNT 2 +/* + * Remapping an extent involves unmapping the existing extent and + * mapping in the new extent. + * When unmapping, an extent containing the entire unmap + * range can be split into two extents, + * i.e. | Old extent | hole | Old extent | + * Hence extent count increases by 1. + * + * Mapping in the new extent into the destination file can increase + * the extent count by 1. + */ +#define XFS_IEXT_REFLINK_REMAP_CNT(smap_real, dmap_written) \ + (((smap_real) ? 1 : 0) + ((dmap_written) ? 1 : 0)) + + /* * Fork handling. */ diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index 04a7754ee681..134d49f8c941 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -1100,6 +1100,11 @@ xfs_reflink_remap_extent( goto out_cancel; } + error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + XFS_IEXT_REFLINK_REMAP_CNT(smap_real, dmap_written)); + if (error) + goto out_cancel; + if (smap_real) { /* * If the extent we're unmapping is backed by storage (written From patchwork Fri Aug 14 08:08:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11713833 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 031C613B1 for ; Fri, 14 Aug 2020 08:10:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DFE8520771 for ; Fri, 14 Aug 2020 08:10:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LAMheQXH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726990AbgHNIKF (ORCPT ); Fri, 14 Aug 2020 04:10:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726124AbgHNIKF (ORCPT ); Fri, 14 Aug 2020 04:10:05 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E16FC061383 for ; Fri, 14 Aug 2020 01:10:05 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id ep8so4029990pjb.3 for ; Fri, 14 Aug 2020 01:10:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9NQNiEsE2oSpO8KD806KMNjp9qpAmlHnF7jbyd7kmx0=; b=LAMheQXHQh42fmWBBoEYHcKfKesNLobvsM6kj5U2cjlUvLwM5TpolbH+O04HqfKnPB J9v7MFZRGOPC1asl2XOx+zACe2g3KRc133KrNF9I9OlEnRInZpXEznEM3Uc49C8HqLY7 ASArVxsOiniqAHKgB1fBdUHuly+1k/68X3SerX7oONkwAKa8L7oVv1M3zUcVHArVJBg2 LgD3XNymI03Yg34dZPz4TGU6KB4D4AFQuquRnPVB+zFklOLJ7UhySJ7oz+gvgujUQMWz gN7KgzBUAIdnxopS9cJL7A3AEW357V2GYVyc0yLMqRnAxO4K8y83hXZKf11XxDb0jjEa hxyg== 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=9NQNiEsE2oSpO8KD806KMNjp9qpAmlHnF7jbyd7kmx0=; b=cZcrW8nZy3RhWuhSWKfa4t/KM1tJK1Kv4FHgTkTx1d6Yip2jLlunvwOmW5/mmp4tPn LhYcNNTwxeImdd1TuaBdrj1k5aOk8nMguYMxGvs3J4AgRh10+8+gz1/9LZYn86qIkowo Fo25q/IJI7e+pDvXcghqSd+byHcl+nrzi95d80hhxVCOYvTmbqPYx2iUtL4MmwjZ9uYg YAQnH05UvaC8ecgYkyNiiVBy893BJk5u5xoXhrfq02nYkjGJi+pfk1S5JzA2JtKGS/FB k/dgoH4hr4xitHZ7ODT2b+VOvejEKWoCM39bQxanth1m6/A1mUR6ACXWUxYiEj0Kebx7 7njQ== X-Gm-Message-State: AOAM53196UOOr2iYSxzOr3f4VEOZEZoqmBcKXPr+ltuESDHM8hsjaHAQ fBBLzsH77E+Kg28hYXoRL66ldR2Ps8E= X-Google-Smtp-Source: ABdhPJyz6+ybJ0oGzLVL29I8eBUmmDfgn0m7IDHN+1Ec6vS41qfsbMRhmlyvFoQ6Ex2mol6Qz9aUyQ== X-Received: by 2002:a17:90a:d78e:: with SMTP id z14mr1232014pju.133.1597392602591; Fri, 14 Aug 2020 01:10:02 -0700 (PDT) Received: from localhost.localdomain ([122.179.47.119]) by smtp.gmail.com with ESMTPSA id z17sm8594289pfq.38.2020.08.14.01.10.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Aug 2020 01:10:02 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com Subject: [PATCH V2 10/10] xfs: Check for extent overflow when swapping extents Date: Fri, 14 Aug 2020 13:38:33 +0530 Message-Id: <20200814080833.84760-11-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200814080833.84760-1-chandanrlinux@gmail.com> References: <20200814080833.84760-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Removing an initial range of source/donor file's extent and adding a new extent (from donor/source file) in its place will cause extent count to increase by 1. Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_inode_fork.h | 6 ++++++ fs/xfs/xfs_bmap_util.c | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index afff20703270..82b26536f218 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -98,6 +98,12 @@ struct xfs_ifork { */ #define XFS_IEXT_REFLINK_REMAP_CNT(smap_real, dmap_written) \ (((smap_real) ? 1 : 0) + ((dmap_written) ? 1 : 0)) +/* + * Removing an initial range of source/donor file's extent and + * adding a new extent (from donor/source file) in its place + * will cause extent count to increase by 1. + */ +#define XFS_IEXT_SWAP_RMAP_CNT 1 /* diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index f6352b5e5552..8159306a8c41 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -1375,6 +1375,17 @@ xfs_swap_extent_rmap( /* Unmap the old blocks in the source file. */ while (tirec.br_blockcount) { ASSERT(tp->t_firstblock == NULLFSBLOCK); + + error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + XFS_IEXT_SWAP_RMAP_CNT); + if (error) + goto out; + + error = xfs_iext_count_may_overflow(tip, XFS_DATA_FORK, + XFS_IEXT_SWAP_RMAP_CNT); + if (error) + goto out; + trace_xfs_swap_extent_rmap_remap_piece(tip, &tirec); /* Read extent from the source file */