From patchwork Thu Aug 20 05:43: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: 11725423 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 F1A7A1575 for ; Thu, 20 Aug 2020 05:44:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DA638207DE for ; Thu, 20 Aug 2020 05:44:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="s0WNr0Oo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726347AbgHTFoN (ORCPT ); Thu, 20 Aug 2020 01:44:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725768AbgHTFoL (ORCPT ); Thu, 20 Aug 2020 01:44:11 -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 53588C061757 for ; Wed, 19 Aug 2020 22:44:10 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id g33so631871pgb.4 for ; Wed, 19 Aug 2020 22:44:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TAmXYEMXGu7IwTZlJVbpCTIERA0KfgjTZYIkKIzuPJY=; b=s0WNr0OoFDT+rIanjV+BDjD4yn0SyETBeA+vh/xkN0zeP/I4YbdplzYvDGsW6pKvmk NdTgirwiIobEO+pjJBUZdkM6uQNrAErtObKn2ObcicLY8dRvZp2TdbN+5DFPsEOGKBKf Muu5M2WLmSkcfhFg3fWusWI6jK/uj4xCnGaI94r8wtRJsnwiDQv5LSQ7/xDd/ch91I29 uMGBFrgEj26lki/XKYkQ2PWUQe0RkG7K4mghzv/kCXQY1QwEpmv4P7xc4bB9M1eKlxpu 0NA0vp970NH9j7LvFNLHIgof6R5yyqvlzC2KgP8giL9UnKaDGTG7cUT1egNvyv2nIpGV Oo0w== 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=TAmXYEMXGu7IwTZlJVbpCTIERA0KfgjTZYIkKIzuPJY=; b=lz45PfUTzVgfP6ZEplkAFCrryAjEZkaXOfdTdUPoCulz0iGvMWT4mRMTRfm/IZ55aT +9LM+8cRtA95vNrPch8zKuO2tf4ZAmek50BXOhUXGV2OdVOaPPKjBrzLOTwQg6TvZPif aiTMsqlOvRVfjpurr6BAnpSwT31ed+CR3ihXiKBsBGe/J5pTuDwV08HT+jdH1xFLojGS t6yBQdY0DB1pBhntCun5lEoKDSTGai0A1MmrfWMs25ORCtR0dc+RtB13pPJb/HQwqn5L ITBENMWKDb7IhVN+SKd3NM1hLMjGEdycR9kZM+isfmy1GyMwP9khE7kT7C38j7Q3Mw2O jmKA== X-Gm-Message-State: AOAM532mMLHCDg2Pi3fUgMPxgCusYzw8zcK/5jht+XBcPTMSa76VFOub 1l7bWMuHKtVDogUbV8DRqsOGUP2arfQ= X-Google-Smtp-Source: ABdhPJxSjUX7iFslp1Q3+Cnzdme4BmCtv4MezLh+1WHKgd2siUWboJsxOulnXaoHnoNdk6qrsw773Q== X-Received: by 2002:aa7:9ac2:: with SMTP id x2mr1062084pfp.57.1597902249393; Wed, 19 Aug 2020 22:44:09 -0700 (PDT) Received: from localhost.localdomain ([122.171.166.150]) by smtp.gmail.com with ESMTPSA id l4sm1044034pgk.74.2020.08.19.22.44.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 22:44:08 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org Subject: [PATCH V3 01/10] xfs: Add helper for checking per-inode extent count overflow Date: Thu, 20 Aug 2020 11:13:40 +0530 Message-Id: <20200820054349.5525-2-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820054349.5525-1-chandanrlinux@gmail.com> References: <20200820054349.5525-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 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 Signed-off-by: Chandan Babu R Reviewed-by: Darrick J. Wong --- 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 0cf853d42d62..3a084aea8f85 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 Thu Aug 20 05:43: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: 11725425 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 2BDC61392 for ; Thu, 20 Aug 2020 05:44:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 147DC207DE for ; Thu, 20 Aug 2020 05:44:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sMATffRR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725768AbgHTFoP (ORCPT ); Thu, 20 Aug 2020 01:44:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726752AbgHTFoN (ORCPT ); Thu, 20 Aug 2020 01:44:13 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECEABC061757 for ; Wed, 19 Aug 2020 22:44:12 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id d4so498155pjx.5 for ; Wed, 19 Aug 2020 22:44:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=44Iv1kgKTiqTo6p00WcQz6bKyzKvV4a7ttaZdiIZZJ8=; b=sMATffRR/HpHiGx6aSSO6O3ZDZtBAP6ThMDzp1dRlh0WjccQiLU7J2PS0W0ys7Hjog vW9zECrnlr3/6yc067Dh7Yo44RwpUQ+xUpsD3TLwVVd5d28wc7UJp+ub7Mv12quAbnZG p4nijZAYGQtGG4tpoMcAZBtw/9W4hDFWOnTxgTHxgvk0gX0omFL6jCtGk5HiEkE0Rcnu C25kr/2jYI/snuM21GsN3fNuj9HaJuXssH1uV9yM7qzy/SUSBe2IbOR2IBe5VMOyqNzD eMof8FtEWvl2cSUEBo+l/jCTKy1WV2lfpHwUEPtn3suFnTdCEumvNOygp89QsKBU2KCj uOug== 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=44Iv1kgKTiqTo6p00WcQz6bKyzKvV4a7ttaZdiIZZJ8=; b=S+e49DLBXXuDaqj4LVoV+UlGFqVu864ztQXjeKJVjw292wI6nYAhAzXztiOGa7s6xa bfv/DtVkfc5YvVLhw7OGJVHLBPnUqag3l0+/uwSkqUxEzhE2UBLkA9c1stIMsEK2kGcz MDqjpJUGp+gzFNRfURnlbn/sOBQlc2+VyQdPyjVhaK6XEV+7kF6+zKtrZ94IV6s14cpu 4aFRwVrcz6bcoR3xx4g9Jz8J3nQAbXquvFzmBBNXMZyJS0xQ/8qyOEhQNARUQJcrTKCm caiIga6EocQgYesechN8Iah2l3qHr5+YvgFvsZMnS2yIACdp1NXP1b8Y+5ge+L9gmUTV bOpA== X-Gm-Message-State: AOAM533lDjY4zkp+b+Gvw/GJijp1tQ21+m2dLx2XB/nBuYNFAzGZvCay Jq3ulyU8s0HVfxCqRpy7KnU/6IubUIU= X-Google-Smtp-Source: ABdhPJxrBXjzxecJfr3gHUKrmsxHG4evbUOco9OFro5/RjEAwQMknWX8/wLBVZzDlGl4kNGiKwsfLg== X-Received: by 2002:a17:902:7202:: with SMTP id ba2mr1377198plb.4.1597902252172; Wed, 19 Aug 2020 22:44:12 -0700 (PDT) Received: from localhost.localdomain ([122.171.166.150]) by smtp.gmail.com with ESMTPSA id l4sm1044034pgk.74.2020.08.19.22.44.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 22:44:11 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org Subject: [PATCH V3 02/10] xfs: Check for extent overflow when trivally adding a new extent Date: Thu, 20 Aug 2020 11:13:41 +0530 Message-Id: <20200820054349.5525-3-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820054349.5525-1-chandanrlinux@gmail.com> References: <20200820054349.5525-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 Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_bmap.c | 6 ++++++ fs/xfs/libxfs/xfs_inode_fork.h | 6 ++++++ 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, 34 insertions(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 9c40d5971035..dcc8eeecd571 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_util.c b/fs/xfs/xfs_bmap_util.c index afdc7f8e0e70..7b76a48b0885 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 04dc2be19c3a..59ea9485ebda 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_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 0e3f62cde375..37b0c743c116 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 6209e7b6b895..9508ab00a00b 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_NOSPLIT_CNT); + if (error) + goto out_trans_cancel; + /* * Allocate blocks to the bitmap file. */ From patchwork Thu Aug 20 05:43: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: 11725427 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 27E5C1392 for ; Thu, 20 Aug 2020 05:44:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0D302207DA for ; Thu, 20 Aug 2020 05:44:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IwLkK1En" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726766AbgHTFoQ (ORCPT ); Thu, 20 Aug 2020 01:44:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726752AbgHTFoP (ORCPT ); Thu, 20 Aug 2020 01:44:15 -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 93CFCC061757 for ; Wed, 19 Aug 2020 22:44:15 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id g33so631951pgb.4 for ; Wed, 19 Aug 2020 22:44:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DQTbRCGA8eC9HmrtOZiWR3oUGqm1kAxku1j65nRLYlI=; b=IwLkK1En48HNegdyOIFw1JFi2aecCkgh3LeZqfVoOeMGr/jO7HjdHfGZjFxchxdDsG 1urWiM5ICQsFAdjkAZ6BXwqMkl8wEzDYFWX7qSapsMTCOXlxMwyryEFQhPeVKHlkt1ch nTLTmqcZZ83TrNLwJpv/MSlTnXQVmfbLHJETeoIZ3fBlalIRfQOrRRepO/7dMnEZpRWw qOEs8zxRrTLwfQCqws9KdsoirpKBhtRzeR9B05/0hX5Yy583KKJaFmUG3d/z1sKGNjpB 4oQ9R+MaVUgRdd6vnlsqKdWTEQAtNTojKQwIwNceInedYYrSX7SfOWomwuziLwbLWRuA nWTQ== 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=DQTbRCGA8eC9HmrtOZiWR3oUGqm1kAxku1j65nRLYlI=; b=csObCjDFjgDI87qY38k7cNDY5icO3NUNfJDwXubVa46MwkzLch9IB0dgo67/LqwGm2 uyGLe/4GEEDbTM6Ok2PoLR8Kr9FiqZX4rM8rzCHBe52iV+EZ02JumvqHXEbMGmyAcH8K qYBTwu6isRvgc856R5r/xTMKQVx2QzHnAmakWETpRPpbVT80AMT/DxDmhcxl+uOv4OmI eIwuCa351otKl+kkxrfTr+g3jvEGuG+Mz455i9mrGHfKdYwfkil9mxIlkFWRTG+WXqiV Snbya3JavahNpxtV3g3jZBu7zAuzRHDme3FaqrW5B/r13/gR7IB1Yr+Ku2VCvdvdufw3 DGzw== X-Gm-Message-State: AOAM530f2Y1hPtQlZX8zMgDwlfTGLL4FxFfTap0rB+dcySEOoYfGyPqj qwn2/c1PdHcPNO0pmBnBzcIV9tOxY38= X-Google-Smtp-Source: ABdhPJwVc3pMfGctdxazTXqE7Qx5BKNTR/dLDo0QGgtG4HJXFRWXLxJ6a/SNcqGrH/FN2DLiSP6IrA== X-Received: by 2002:a63:e24d:: with SMTP id y13mr1392563pgj.248.1597902254871; Wed, 19 Aug 2020 22:44:14 -0700 (PDT) Received: from localhost.localdomain ([122.171.166.150]) by smtp.gmail.com with ESMTPSA id l4sm1044034pgk.74.2020.08.19.22.44.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 22:44:14 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org Subject: [PATCH V3 03/10] xfs: Check for extent overflow when deleting an extent Date: Thu, 20 Aug 2020 11:13:42 +0530 Message-Id: <20200820054349.5525-4-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820054349.5525-1-chandanrlinux@gmail.com> References: <20200820054349.5525-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 7fc2b129a2e7..2642e4847ee0 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -39,6 +39,12 @@ struct xfs_ifork { * extent to a fork and there's no possibility of splitting an existing mapping. */ #define XFS_IEXT_ADD_NOSPLIT_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 7b76a48b0885..59d4da38aadf 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 Thu Aug 20 05:43: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: 11725429 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 1383E1392 for ; Thu, 20 Aug 2020 05:44:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EEE2B2075E for ; Thu, 20 Aug 2020 05:44:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lscIa2uq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726781AbgHTFoT (ORCPT ); Thu, 20 Aug 2020 01:44:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726752AbgHTFoT (ORCPT ); Thu, 20 Aug 2020 01:44:19 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 782E1C061757 for ; Wed, 19 Aug 2020 22:44:18 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id m34so614339pgl.11 for ; Wed, 19 Aug 2020 22:44:18 -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=Pu2hd/KCl6mXkYJcW5ULiq2me8SngIvCViXvCcRpi6Y=; b=lscIa2uqJYVcGWMupeqgHEJfG3UWe32ON96yrJTZBtAC4NPn1QulUCgq1w/3FE+9BE Oac1GOpsnELPtkcvXX80IbSgYnZL2D5G4sX6xZWDz/Mdm6raPWCvfoQbxpdYfwL9dSsf aGzSllPwAK1yEMxDmpJSAIpqJlsE4rxWxGm68z1J2X6ZvNJCIOdzaWm0ULGUMUXz1Iyk 5+OS+ogh16ij6iutjtlnpm5q0vtvZ5x0XPCyW+8/ni4TS/nsuXALs03C7R7p83c1DkPi 044KZXKVTxB07NK3yWwHXOwETfaYpP9oPTJT+3XX1/fGR4TDhPU1RZtTRMfIWrgi8ygT WVjg== 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=Pu2hd/KCl6mXkYJcW5ULiq2me8SngIvCViXvCcRpi6Y=; b=XpkBxqpSIDlyq1ILzjV60U41VgFV6etvgeXYAXFTC2GxgojyeFbHIEVajRJGIJLEtM VGghZrOPPeYV5WvZU9EPm7NX/xITB76kpsfiXDbh78ejACBfYeZpk+enoUZHN2Lt5Scr 0UFIfSMM5R0eolJ8tilC63e0v0QEducR1pBzD2i9e+DchXcvglv1I1Eq9Y/y6VUcw6u0 XT8vZLjXJz5+XqcS8GC4Qle4CDGNWySIRTptOVDlYn+5C1N7rR/L/+wLf8qUVZSXyv9L 3tkceMc/FyoRVKoeLSHjVbdV6UTVEp9xHgYeT9F+AyDRQm2co2qw8H/huAF6Veq3pYHq PZ6Q== X-Gm-Message-State: AOAM530vsnHRKu9ljIaHdthofFLCtZGgPqCvO54V1kIuVJxeJihy2wWV ttoxchMkQ8dEY3BzpPnbEshx3iPzY9o= X-Google-Smtp-Source: ABdhPJyFzABK6k2ImYxfR6a8YA/iXFDNmE0+/BmxdVUjD2gohxTI+m7U+oVsmlmXv60X3UX7LXOKww== X-Received: by 2002:a63:4726:: with SMTP id u38mr1397100pga.246.1597902257781; Wed, 19 Aug 2020 22:44:17 -0700 (PDT) Received: from localhost.localdomain ([122.171.166.150]) by smtp.gmail.com with ESMTPSA id l4sm1044034pgk.74.2020.08.19.22.44.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 22:44:17 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org Subject: [PATCH V3 04/10] xfs: Check for extent overflow when adding/removing xattrs Date: Thu, 20 Aug 2020 11:13:43 +0530 Message-Id: <20200820054349.5525-5-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820054349.5525-1-chandanrlinux@gmail.com> References: <20200820054349.5525-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 2642e4847ee0..aae8e6e80b71 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -45,6 +45,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 Thu Aug 20 05:43: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: 11725431 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 2671C1575 for ; Thu, 20 Aug 2020 05:44:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 10F98207DA for ; Thu, 20 Aug 2020 05:44:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="t4K5bR1A" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726786AbgHTFoV (ORCPT ); Thu, 20 Aug 2020 01:44:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726745AbgHTFoV (ORCPT ); Thu, 20 Aug 2020 01:44:21 -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 439ABC061757 for ; Wed, 19 Aug 2020 22:44:21 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id y10so417133plr.11 for ; Wed, 19 Aug 2020 22:44:21 -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=9rX+/WpEhbK1jNNfavW4BofCGrwob0yBeBWvyb4SHVU=; b=t4K5bR1Aspq4Mpvf0C1J3vU5QJspI/eC6EZpUlE4sTyBwwP/Q3fkPb2iGcvxDoW+kS exiGPqwZXuDNAlYY0gGwMR0Crqs25RqbubEidTof/WuW5fSFcxpnbakHulblOsCiChXp DH2gWPvpDtN+ZiLPwSmP/RnEU81tddA4XzBfWB0+WCuWG740q87tIxNEFpDR2AF9QH0O kZSjtnb0WI7D56jGHl2Mt81m+KsVkNWZ9x13LnaJuTQiWycwDUGT75+Ofr17H2X0Yoxb 1hUOfyHf/wnSmPXWSd6/jVjo+AeVupI4GSszIKLsWr7HMZnyeY0ndkBBOJWIQ9/3veFb 4Qww== 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=9rX+/WpEhbK1jNNfavW4BofCGrwob0yBeBWvyb4SHVU=; b=UhEy/huyH6ObLOylb7scnLPYqz8HWxa7VCS0Qbjtcy+JshHkDZnO41dFa6HSl3fW+y JgNLoJsoq0/OPKWD2jRyuhPhe6kl1KzhRvW/w8FHqSCd3HrU6jPmxwJiacOaeq6MHj9J tYERh7xNy+ZxGOTTW3XKjL3Rz+sPeRwb1hAekDhOt21MVdy/SM+qc0s+YT0u4KSDd6DI WPLSDzcJEgw0FI8CuzU4BDtx0yjtMbNIR6QBxy2N8hkpM0fu4n3tQ2mTsspmSZ35NpLK v+FszBmdpziuKOoxvaGpidfVzDiNpvSgyoAcSlx1+Cjs1x/LsyykISsc5wqXcuJuRHuM r6mw== X-Gm-Message-State: AOAM532fWK8bdBPS9xuivvg8fQNzkoYxH6OpXeESrNglEjdXqvQVKuSj eCmeRev8VYk6eiS6tKdwVodQRm1jhnU= X-Google-Smtp-Source: ABdhPJzYUgw/fAqLjzwHZDwNpEoOH8sl7gvD5z7aPqjJ4/X6Esb6uoLpFRx720dGgNFDxzcId+BqSQ== X-Received: by 2002:a17:90a:a792:: with SMTP id f18mr1208493pjq.65.1597902260522; Wed, 19 Aug 2020 22:44:20 -0700 (PDT) Received: from localhost.localdomain ([122.171.166.150]) by smtp.gmail.com with ESMTPSA id l4sm1044034pgk.74.2020.08.19.22.44.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 22:44:19 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org Subject: [PATCH V3 05/10] xfs: Check for extent overflow when adding/removing dir entries Date: Thu, 20 Aug 2020 11:13:44 +0530 Message-Id: <20200820054349.5525-6-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820054349.5525-1-chandanrlinux@gmail.com> References: <20200820054349.5525-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 Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_inode_fork.h | 12 ++++++++++++ fs/xfs/xfs_inode.c | 27 +++++++++++++++++++++++++++ fs/xfs/xfs_symlink.c | 5 +++++ 3 files changed, 44 insertions(+) diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index aae8e6e80b71..f686c7418d2b 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -54,6 +54,18 @@ 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 Thu Aug 20 05:43: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: 11725433 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 60A0E1392 for ; Thu, 20 Aug 2020 05:44:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 490A5207DA for ; Thu, 20 Aug 2020 05:44:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dythoEv7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726745AbgHTFoZ (ORCPT ); Thu, 20 Aug 2020 01:44:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726752AbgHTFoY (ORCPT ); Thu, 20 Aug 2020 01:44:24 -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 DC3FCC061757 for ; Wed, 19 Aug 2020 22:44:23 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id q1so159873pjd.1 for ; Wed, 19 Aug 2020 22:44:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3vwkX7+KSEBYbeLsNYS+2jKbh2t+OB1cw7PHNOQevcU=; b=dythoEv7XIOHJLWXB4PNMFZcAAkHAN6NUPKki6bFhCD8LAhcVHaoZnGcG3383796U0 M1KhMDlmpWE5O6rbKVhGAKt5mkh59S93Urf8BFf6XTlmYFKseZ4pbbZ7NPZuLOA9YTrx TQpKrAr49x6Ve/y0hv62vQ8kKxeh5UFHAQoLN/8birJQXNvzdE6KRPBspmoJhfyrih0H FMcmxiJez/GJyhzIzAL1o0XXKglpSqi+iut5dHAX5CGFBZvZw+HUxcQvqbP58mNOdR4Q pS9rJLnCxDo/xH8n4iVrEKXXVklzm6wtxJpmPUGMvpgYXUDl8hvCal2H74bdbdxyl6qd wKug== 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=3vwkX7+KSEBYbeLsNYS+2jKbh2t+OB1cw7PHNOQevcU=; b=HDd1efi8leiaz3rNw5uwmgFYGc7c6y+X7djkrUM/BUMyVBebQT+CsLE9efll2WzJFf uW0nI6JFbqh//4OnFxQ+bM4gqAfP38G3XlKEZ2x6P4vw2nnj71cwk+ULxwFII+xPSi4I 0yjKpc/Mqh7XJBXG8GwEGWBS8YPcAkkuu+CmayMqN22obk/qT/qJ8M0QLUaJglbapJ7h WF/R76DHpwBjg8L3l2a/7SHhpERL0ibfzJIrda3S85hOBFcU3fVERx1PVvdB6kCQ+Jk0 sVCZWYPJI3e3+P+nq7lJvGiTu2p69jIdHEkV7wP2U3iGMRhkimMKs223mAIaXRORKeBV yv3A== X-Gm-Message-State: AOAM5336zt2NmlIoXwfmSIj14ZzX7bh3M1iX0HCQE6wtgCo4mTJH0o1c WzEcK2bu/dh1Eje8fGBfdfeDwKF4a/4= X-Google-Smtp-Source: ABdhPJw85Fesxl7Q2Zk7jfJ2ZVb04QuladXzVoDToqGmaUt8h7nJSaZJf5o1NYw9UbNAJgQrgrW/tQ== X-Received: by 2002:a17:90b:3891:: with SMTP id mu17mr1148860pjb.160.1597902263208; Wed, 19 Aug 2020 22:44:23 -0700 (PDT) Received: from localhost.localdomain ([122.171.166.150]) by smtp.gmail.com with ESMTPSA id l4sm1044034pgk.74.2020.08.19.22.44.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 22:44:22 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org Subject: [PATCH V3 06/10] xfs: Check for extent overflow when writing to unwritten extent Date: Thu, 20 Aug 2020 11:13:45 +0530 Message-Id: <20200820054349.5525-7-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820054349.5525-1-chandanrlinux@gmail.com> References: <20200820054349.5525-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 Reviewed-by: Darrick J. Wong --- 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 f686c7418d2b..83ff90e2a5fe 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -66,6 +66,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 37b0c743c116..694b25fbb4a3 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 Thu Aug 20 05:43: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: 11725435 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 96CDD1392 for ; Thu, 20 Aug 2020 05:44:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7F9CF207DA for ; Thu, 20 Aug 2020 05:44:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GHbkWGkz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726752AbgHTFo2 (ORCPT ); Thu, 20 Aug 2020 01:44:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726792AbgHTFo0 (ORCPT ); Thu, 20 Aug 2020 01:44:26 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87530C061757 for ; Wed, 19 Aug 2020 22:44:26 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id t11so535435plr.5 for ; Wed, 19 Aug 2020 22:44:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pXPi9yq6qolo1lMFgGE9r/lwIm5vPdpEZXV7tE05Sk4=; b=GHbkWGkza1yHwQwFzL4siw6lTlfbdAPtuOaNvmwTllMVFaggT4IxVGTMG+cIuMHh8E VG5zJL5xUYepg2MCmrMICa4pvJF3CpM5N8hNJB14CqEvYtN8eV+rzqcsxmMExphHpqV8 Ej85duJiMZeJlz/pfdKmYqS23VEGzyRpxv5bnznYkW5k7svuWt4BvJkY7VerLLIs10/S AGNXPOgtrnwNHpzvF52OZATTO0nDDHXHr8n7BMPRybKWztkMFisUEPLd9LXyUS/XI1RG uv0IU+Jvah+Bi9mTvuLoZj1iKUo9lZWpLr92saHGPPiHzJTXO7Smtpm3kh7fA9tsT2E9 wOWg== 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=pXPi9yq6qolo1lMFgGE9r/lwIm5vPdpEZXV7tE05Sk4=; b=VytSGgtZ9Khe9PjToukd9xFdevaA+tXtjjZogF/vyo5aBhaMcvJ06kt8+P5K2w1ZAd ADva491OKFII2YIn2HIoeG5WT0pgyY/A9w3Y3Seo/4/gB4cLSPen7Dlc6euwaobNLnNJ 9PGFoh85KEx7Nd8hnXAXLSFphSxYlqoitllnBJSSk0JCa97MB7GaLuhhsig8hrcTKvxu PgxmwxmuncD3qvH8MeGNwAvcBzOHE9pR6gA3C9IkLgrWk/v4kXLzs9+sr6U6JRwWtMsV EE6TMc4ISKd8TGUvyQhczyyzAXVXqZhT6Okb+jELlyD+YvfrHsP9RxwP2Qqd6DLMOVbh KxHQ== X-Gm-Message-State: AOAM533iUa2VpGGldG6RL7IemFe5Z4NHlwrJk5PXLwXW+SlU3vrVB6Nc Sadboqm4XK+olPqsq/6nC/iVskI7FYU= X-Google-Smtp-Source: ABdhPJwl7wmW/0anLxa/PffqluaokB4VzY8SLyXDRzVZUJwUIR1F0uA25c6AYTLtTCrOFlDm4TEzAA== X-Received: by 2002:a17:90a:f489:: with SMTP id bx9mr1149528pjb.115.1597902265832; Wed, 19 Aug 2020 22:44:25 -0700 (PDT) Received: from localhost.localdomain ([122.171.166.150]) by smtp.gmail.com with ESMTPSA id l4sm1044034pgk.74.2020.08.19.22.44.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 22:44:25 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org Subject: [PATCH V3 07/10] xfs: Check for extent overflow when inserting a hole Date: Thu, 20 Aug 2020 11:13:46 +0530 Message-Id: <20200820054349.5525-8-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820054349.5525-1-chandanrlinux@gmail.com> References: <20200820054349.5525-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 83ff90e2a5fe..d0e49b015b62 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -73,6 +73,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 59d4da38aadf..e682eecebb1f 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 Thu Aug 20 05:43: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: 11725437 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 0E2521392 for ; Thu, 20 Aug 2020 05:44:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EB299207DA for ; Thu, 20 Aug 2020 05:44:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kj3Mkcuh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726795AbgHTFo3 (ORCPT ); Thu, 20 Aug 2020 01:44:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726792AbgHTFo3 (ORCPT ); Thu, 20 Aug 2020 01:44:29 -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 3252FC061757 for ; Wed, 19 Aug 2020 22:44:29 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id v16so545185plo.1 for ; Wed, 19 Aug 2020 22:44:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JIrVieHhvT8R70iEP7YntiN6S3pkk+mFo7AMAS/mcuY=; b=kj3MkcuhQMV+5LWTRuGnXsHuNf/gyBs8T9wLRQU5rnC4ClUCv6GR/6iJ2qzNTlmLjh H1b3PJYitQ6YYPFbMbZ7E8CGtKf83X2ltBvWv9EwcQPewjIZ1bJCMIiXgnRzAwZGV2ui PeD9G8Dd9/yd22U/TFeVM8/W64i0pDfVo/TDss8dH7YVHPvHFmViULiyOTX516Ie4RtF DZSi7rp8DIfVSPZ6RRNXEOeHWfnJhQH8OEek28aM3j8+175d83LhBaubUJBBiSIGNJ6B wfJ/BjXQ0yRPHlNmAY4/v9xgCK+ifR1oxI6+wrYdsRVgAImtLi5F6sk3XHG37hhrmOoi ys4g== 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=JIrVieHhvT8R70iEP7YntiN6S3pkk+mFo7AMAS/mcuY=; b=kJ0lNsb+9V0j7+LZuLfAWoIhhZiFAtYcz5b9ffQ29rQ8IFQP/Jq1c3u71hDUvrlsZS gUlJ2hX7pGx6Vg6eqmib73CF5IIip+7RQdpSFeY/SU9uO7D+GxVk95GgZGvIGhWBtzP4 RvZKL+85PEefQ9KvRaMYtj5OelvilGKNU3/K7KwyzpX+iAAQ2h33AtB2ty07jfpIGRWZ qQmBjA7lUL/RMBETPZOm8/AXId2G6nvp39SfwPiWwauV+fDqCAEMUVqsHfYMUrw4LqVI gN2kjSzbuAfuWiQkeOo9tql/AdpTRfaiJqHkxlNxdj2b7hXdyaEaXztUdGRPi4aqV6av XODQ== X-Gm-Message-State: AOAM5337CAI1I84y/zG8mPOewxPK2mkV32knwJ1y82JuWXuBvfUfTpI3 2pJWs9zmm8KFN9Jd2PuKHhuMPlhpTa4= X-Google-Smtp-Source: ABdhPJyCcIHfdqsC6thNfiz0F+P1DK6HGXnC0BJaVWZOeDREf83rg2aU/Mw5C1RffjbjS3xMPRhOdA== X-Received: by 2002:a17:902:ba98:: with SMTP id k24mr1400473pls.277.1597902268480; Wed, 19 Aug 2020 22:44:28 -0700 (PDT) Received: from localhost.localdomain ([122.171.166.150]) by smtp.gmail.com with ESMTPSA id l4sm1044034pgk.74.2020.08.19.22.44.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 22:44:27 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org Subject: [PATCH V3 08/10] xfs: Check for extent overflow when moving extent from cow to data fork Date: Thu, 20 Aug 2020 11:13:47 +0530 Message-Id: <20200820054349.5525-9-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820054349.5525-1-chandanrlinux@gmail.com> References: <20200820054349.5525-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 Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_inode_fork.h | 9 ++++++++- fs/xfs/xfs_reflink.c | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index d0e49b015b62..850d53162545 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -78,7 +78,14 @@ struct xfs_ifork { * split into two extents causing extent count to 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..c1d2a741e1af 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 Thu Aug 20 05:43: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: 11725439 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 E998E1392 for ; Thu, 20 Aug 2020 05:44:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D1FD4207DA for ; Thu, 20 Aug 2020 05:44:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QaYAMABG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726792AbgHTFoc (ORCPT ); Thu, 20 Aug 2020 01:44:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726664AbgHTFoc (ORCPT ); Thu, 20 Aug 2020 01:44:32 -0400 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 00F25C061757 for ; Wed, 19 Aug 2020 22:44:32 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id k18so500749pfp.7 for ; Wed, 19 Aug 2020 22:44:31 -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=mfv1u4ZxUw56HFujRb/h1GTHbvSe3gGbHoUGMz89LXY=; b=QaYAMABGtLWkhjCeKUnIE5+UODmNz723rHusGzSMls29rsLYv9lEQvwLyRUAFF32gr QsNB3CzVCKIWPXM9E0d401/2j5jvIfX7vj0UuRVkZ4gogeZclyz6F33rBldcrbD+uvo+ 5/VoRx7W+IMcO8LgziDufbcpBgcRJgWy6WHR6EZiXbN5jfQIcjjgKJHVeidqloZhpQjW gRAiP/3ut89XPzxNSQwwi7uvEv41Qi8cuc0B46IqvUc+0LkF2pJcpCrDU2fe25AjNlW0 98BUdxcDFnhBggNpyKY8TkQ1UhFhl8h4CntOxM6Sebf+rsqY3nJe2VuExvDGmYRZUYwr iOEw== 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=mfv1u4ZxUw56HFujRb/h1GTHbvSe3gGbHoUGMz89LXY=; b=gRmDPpDMnJZ6tlpwrqX+vPCaOTbVZtBX/hmEreJYDPuoGkLg1hegf1PruKUHfkNcCn fuZVmey+NzspWak7f+3NkfRlXgenOck22Ew/d4TLKsDczAWYof8UiISA48/Nr9zKll2N r4EgaGJYff7GfNKaBCWAA4oEZrbHBN6ryVXLrZEKydObm6vOL6sD2BQZcJQHBC/lVt8l I/E1NZhyFPsD/fWsIE6T7OMjw7+98YdagKn7R9urfPlUq36tI4aOt3yQQG75o1obAt1F fbCaOG08QR1vfzL86s+SpkTKkaEbXo9QPRDtu7nMpflw6IKa4tFo2W+2WScveR2EJsaL JbFQ== X-Gm-Message-State: AOAM531FTqLQ9MABQtC0vwjpZuMtt8i4P3ogQM0pG7W3tZtUhNjZYYv9 owrtQTTIk2Ng7d+Qcz63mZs4TCJX1os= X-Google-Smtp-Source: ABdhPJwc5y3rzy4ZLtCvS6GwIULf6rSAtt2d66ZW67wPfuSYPgpprtz3YL3lpepX1N4M0nnRD2wFmw== X-Received: by 2002:a65:664a:: with SMTP id z10mr1339855pgv.352.1597902271226; Wed, 19 Aug 2020 22:44:31 -0700 (PDT) Received: from localhost.localdomain ([122.171.166.150]) by smtp.gmail.com with ESMTPSA id l4sm1044034pgk.74.2020.08.19.22.44.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 22:44:30 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org Subject: [PATCH V3 09/10] xfs: Check for extent overflow when remapping an extent Date: Thu, 20 Aug 2020 11:13:48 +0530 Message-Id: <20200820054349.5525-10-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820054349.5525-1-chandanrlinux@gmail.com> References: <20200820054349.5525-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 Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_inode_fork.h | 14 ++++++++++++++ fs/xfs/xfs_reflink.c | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index 850d53162545..d1c675cf803a 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -86,6 +86,20 @@ 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 c1d2a741e1af..9884fd51efee 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -1099,6 +1099,11 @@ xfs_reflink_remap_extent( goto out_cancel; } + error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + XFS_IEXT_REFLINK_REMAP_CNT(smap_real, dmap_written)); + if (error) + goto out_cancel; + if (smap_real) { /* * If the extent we're unmapping is backed by storage (written From patchwork Thu Aug 20 05:43:49 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: 11725441 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 935F51392 for ; Thu, 20 Aug 2020 05:44:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7ADDE207DA for ; Thu, 20 Aug 2020 05:44:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lYgWYGAF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726664AbgHTFof (ORCPT ); Thu, 20 Aug 2020 01:44:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725820AbgHTFoe (ORCPT ); Thu, 20 Aug 2020 01:44:34 -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 A0CE3C061757 for ; Wed, 19 Aug 2020 22:44:34 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id s14so538999plp.4 for ; Wed, 19 Aug 2020 22:44:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eHUYKe1vuTxgO0DxzELBSxXT4SwhAPsSh5gu81qEa3M=; b=lYgWYGAFdY/ySXHFo6C5Vq7B22Sy19D3prv9FFv4X41MaKdPTAb9PBcr/yovzWkS+L 4jbWGVUgWwMvtOHAGHBd0Q3Zb4gk4yGGkq84erj1NFImnhmHbzYO1mS9b7uImtJvZoXw vRkdUeMfglyv05esFvOHfNIlOPPRTaQSgAY3w5n/3l5173K0Oq33aSqZsB8NdsutP0Bp dBkeZYWBX7TtF3YBA9i0OpuhU/5QOwdj11XmZeyK1XCSkUT2AF61rRv9eREk8+dJadu8 LtUxnEjN7OFn8RBKj+lchZeVbmA+dR2f6XSjQ5SPDCEkzOOeRgc6OsP+HR2KsI5s3e1e WDUA== 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=eHUYKe1vuTxgO0DxzELBSxXT4SwhAPsSh5gu81qEa3M=; b=AkudH2ayPGMZe9GYjiSqIA3O0NqgAU6hlVQzCuxZTZ6vynILbWDZ5Y69VW5sSIzkAG 0AnOA6lv8O6Szjlm7BkeCxveXPSJ7VwXWhD1inpnSPzOzhQTFvGDKDm/YSfxilP3UDUm Kr900c9TEefDF77HVG+HNiURnS3DmfMKMtiutnNttxCJXjW7WO3dYGhM3W7NroDurL3Z Z4froEaFEwnUg3yMOC8pPzlb0grLZ4DU0ERN6violA17bPZelF1t0RNShe0wS2N/Hqip VGexNj8p3aCKqQzScoupH7Z4T8zklPSr81lUUgLJSda7wOVuhH6ivTbSG9A/XFIeVz2v 2MLQ== X-Gm-Message-State: AOAM53226eRaT3MmcpB7L+sCG01LC5zY4DAaGIpDTWYtIfbMHirL26cT MyJsWuDTlT04AnSgcMPlv6W+csMuNKU= X-Google-Smtp-Source: ABdhPJx8WqpPLfK4X+L4Se4lU/fNPSr0a7Uj3wPy0TU3rID39JMcrJ776EP4qo9V7WD3OK3Q5efjRw== X-Received: by 2002:a17:902:e905:: with SMTP id k5mr1333491pld.342.1597902273927; Wed, 19 Aug 2020 22:44:33 -0700 (PDT) Received: from localhost.localdomain ([122.171.166.150]) by smtp.gmail.com with ESMTPSA id l4sm1044034pgk.74.2020.08.19.22.44.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 22:44:33 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org Subject: [PATCH V3 10/10] xfs: Check for extent overflow when swapping extents Date: Thu, 20 Aug 2020 11:13:49 +0530 Message-Id: <20200820054349.5525-11-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820054349.5525-1-chandanrlinux@gmail.com> References: <20200820054349.5525-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 d1c675cf803a..4219b01f1034 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -100,6 +100,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) /* * Fork handling. diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index e682eecebb1f..7105525dadd5 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 */