From patchwork Tue Nov 3 15:06: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: 11877931 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 A8696166C for ; Tue, 3 Nov 2020 15:07:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8D8072242E for ; Tue, 3 Nov 2020 15:07:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TteGliNL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727742AbgKCPHm (ORCPT ); Tue, 3 Nov 2020 10:07:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728174AbgKCPG6 (ORCPT ); Tue, 3 Nov 2020 10:06:58 -0500 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2ED56C0613D1 for ; Tue, 3 Nov 2020 07:06:58 -0800 (PST) Received: by mail-pg1-x544.google.com with SMTP id g12so13888772pgm.8 for ; Tue, 03 Nov 2020 07:06:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XmdKpghfLeanbz+IwL0BYKqdxi1X0QN/uaPdOmARGkM=; b=TteGliNLrGJSEYX5GyBB/K9nWZArrfxIwXaMYRMeYy7k+NGdZGC3Z8wAnF9RzcIePh EqJLoOCzKd+gg/iX5lUqclx7QdjpdjVwGFEXnkxdORJmFfhYv4ncqaZYjTRNrtANZyq+ O9aXqdblhBYO73up9D7bSA6UkxvppXx3f/y1ql3LG8Pn73uGq+4+ljSYC0uiaKHngVSh fPYI5hXO6mebgEgYgZb8wUL1f2l01mr28Mlz1h/gHXCYPUbPuJLDqQHijdWwEG52Db2b vCL+vdKoCcpq7UCgDOaA3Es4bXj4ox4/6KicPcIJCn4ghp086G8bOU+FWlBTUguvN7yE IBtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XmdKpghfLeanbz+IwL0BYKqdxi1X0QN/uaPdOmARGkM=; b=Ty/WQ/toKEVU8Ifp/uyhsnmdfNgHjUrhOXooTl1WQs8EKuimTWbdLWFbpyZ0UoL51s 6t/UW8r6zAPkIQaKfMMuO3w6C/BwM0BO875xbYo/8rX0Vb5r98y4+P8eAHlG7cY2lisn cdK4l/FVM98PtOn7dvK1lzCDRqGca7qd6H5YB3XJ9JMlWJHW1v54/t3vJQAdPBYF0MTo i/USy5HwRgRuKy4H9JO7N2TPJCcpgpGfdpOFR4jzotp9yFeK2J6mjv+nZV5AVDUjYAx+ 9cKuK2yDi0Je8huRr2tNbkfhqNUwGsWNUPUCBvtMISydO26N8JmOLLTtNlnArobCGZOI /oeg== X-Gm-Message-State: AOAM532dAFZRSZf5x2MD4tJRobIb61zJ056aNnRDK7PY+padh+4GoJXv WWIQAnaJ42KusRiI4LFJ/BftIvvEZTvHfw== X-Google-Smtp-Source: ABdhPJwTBh+YKIpeqpemzNITtF7PypnMnYm5zSKJoZN+iVJjIgf2KGmId2TSw6zAleXrmRm1mn0raw== X-Received: by 2002:a62:92c5:0:b029:156:6a7f:ccff with SMTP id o188-20020a6292c50000b02901566a7fccffmr25889003pfd.39.1604416017427; Tue, 03 Nov 2020 07:06:57 -0800 (PST) Received: from localhost.localdomain ([122.179.48.228]) by smtp.gmail.com with ESMTPSA id 15sm15936955pgs.52.2020.11.03.07.06.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 07:06:56 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, allison.henderson@oracle.com, Christoph Hellwig Subject: [PATCH V10 01/14] xfs: Add helper for checking per-inode extent count overflow Date: Tue, 3 Nov 2020 20:36:29 +0530 Message-Id: <20201103150642.2032284-2-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201103150642.2032284-1-chandanrlinux@gmail.com> References: <20201103150642.2032284-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org XFS does not check for possible overflow of per-inode extent counter fields when adding extents to either data or attr fork. For e.g. 1. Insert 5 million xattrs (each having a value size of 255 bytes) and then delete 50% of them in an alternating manner. 2. On a 4k block sized XFS filesystem instance, the above causes 98511 extents to be created in the attr fork of the inode. xfsaild/loop0 2008 [003] 1475.127209: probe:xfs_inode_to_disk: (ffffffffa43fb6b0) if_nextents=98511 i_ino=131 3. The incore inode fork extent counter is a signed 32-bit quantity. However the on-disk extent counter is an unsigned 16-bit quantity and hence cannot hold 98511 extents. 4. The following incorrect value is stored in the attr extent counter, # xfs_db -f -c 'inode 131' -c 'print core.naextents' /dev/loop0 core.naextents = -32561 This commit adds a new helper function (i.e. xfs_iext_count_may_overflow()) to check for overflow of the per-inode data and xattr extent counters. Future patches will use this function to make sure that an FS operation won't cause the extent counter to overflow. Suggested-by: Darrick J. Wong Reviewed-by: Allison Henderson Reviewed-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_inode_fork.c | 23 +++++++++++++++++++++++ fs/xfs/libxfs/xfs_inode_fork.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c index 7575de5cecb1..8d48716547e5 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.c +++ b/fs/xfs/libxfs/xfs_inode_fork.c @@ -23,6 +23,7 @@ #include "xfs_da_btree.h" #include "xfs_dir2_priv.h" #include "xfs_attr_leaf.h" +#include "xfs_types.h" kmem_zone_t *xfs_ifork_zone; @@ -728,3 +729,25 @@ xfs_ifork_verify_local_attr( return 0; } + +int +xfs_iext_count_may_overflow( + struct xfs_inode *ip, + int whichfork, + int nr_to_add) +{ + struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork); + uint64_t max_exts; + uint64_t nr_exts; + + if (whichfork == XFS_COW_FORK) + return 0; + + max_exts = (whichfork == XFS_ATTR_FORK) ? MAXAEXTNUM : MAXEXTNUM; + + nr_exts = ifp->if_nextents + nr_to_add; + if (nr_exts < ifp->if_nextents || nr_exts > max_exts) + return -EFBIG; + + return 0; +} diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index a4953e95c4f3..0beb8e2a00be 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -172,5 +172,7 @@ extern void xfs_ifork_init_cow(struct xfs_inode *ip); int xfs_ifork_verify_local_data(struct xfs_inode *ip); int xfs_ifork_verify_local_attr(struct xfs_inode *ip); +int xfs_iext_count_may_overflow(struct xfs_inode *ip, int whichfork, + int nr_to_add); #endif /* __XFS_INODE_FORK_H__ */ From patchwork Tue Nov 3 15:06: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: 11877929 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 6E3221130 for ; Tue, 3 Nov 2020 15:07:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4AEC72242E for ; Tue, 3 Nov 2020 15:07:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tO5/aBe/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728180AbgKCPHm (ORCPT ); Tue, 3 Nov 2020 10:07:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727742AbgKCPHB (ORCPT ); Tue, 3 Nov 2020 10:07:01 -0500 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 30A6FC0613D1 for ; Tue, 3 Nov 2020 07:07:01 -0800 (PST) Received: by mail-pl1-x641.google.com with SMTP id r10so8692104plx.3 for ; Tue, 03 Nov 2020 07:07:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GhuaEjtbG0//r4IvHlnEcQuD/mUoLWUJcwfcoO/yi10=; b=tO5/aBe/xiHXa5rhMMKNP318gkWwWO9MwD0Zqu6RnTktc3TgHNBEMGb0Rto7l6f4+e 6cxYc1AoB/iqrNWM+lc0O7T/fmpiLnMRiDK+C3x0S+zKMeJYbNjXjZm0auoWC5kJiLwX GcjbzFrmE3xoJt6p/WWMkBQNcjMepoMdhn8joQk4Iro4q3pBVIBkXWt5MM9X/dYHMYde +2mwaAgJ2tFXX2TfZ/d5IO2kiTgOOzu3JMM91DO5QdimQgJ4o3CjxJTIiSbjSXaKquLw htVu1xR+bSfGykk/Knf9NZavGwi38lfqfp3C1dkCtsxXRbRuPJUzwEvM6OgKBHolkQLQ KAzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GhuaEjtbG0//r4IvHlnEcQuD/mUoLWUJcwfcoO/yi10=; b=myoAra9l2pER3SX4aIzUtUeDdcdnnEzbakcUnDksi1i/ZYJ/d7oE4+T1vl+ml71sna cX3iUZV4TwbDgA46XK5UtudtJPLzlJcXEyLdi2SCCfmiakquZbAeG4VmASXj4eA56y1K jYuy9dEE/nNVTAC5tvRA/Mo6tHLWs35BgPd4qYWGKTANK6IQr0Tvx35rI7SrVszCN14R biAllBsOg7YNh7VuWjtx6DO2a7e3AJzm3WGHYVCI1RorrvZw96Ti9DAHvq56hIRndT0O 6bCQdrrIzSsTDBfSDOYaAycf5rSlx5As/iUDY5/7F4zk0IYY9o5AAaVZMRYyRnXCblaD +fhw== X-Gm-Message-State: AOAM531zJ1YqukZveEU7oZlFeEH/cgzh2nuhXzSwl/U/Oeq1MvH87082 Yu4TSJXlO7FAWxrE47EfiIL3QZkwZNaHtw== X-Google-Smtp-Source: ABdhPJzDpcZDMz3s8IJmMMMkYOfzPgnE9pY3Z22Pam17EOh7Wml74SMLWLkQY9WRX+UDxz+vASMXcA== X-Received: by 2002:a17:902:9b93:b029:d6:d0e3:10c6 with SMTP id y19-20020a1709029b93b02900d6d0e310c6mr8494929plp.41.1604416020440; Tue, 03 Nov 2020 07:07:00 -0800 (PST) Received: from localhost.localdomain ([122.179.48.228]) by smtp.gmail.com with ESMTPSA id 15sm15936955pgs.52.2020.11.03.07.06.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 07:06:59 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, allison.henderson@oracle.com, Christoph Hellwig Subject: [PATCH V10 02/14] xfs: Check for extent overflow when trivally adding a new extent Date: Tue, 3 Nov 2020 20:36:30 +0530 Message-Id: <20201103150642.2032284-3-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201103150642.2032284-1-chandanrlinux@gmail.com> References: <20201103150642.2032284-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org When adding a new data extent (without modifying an inode's existing extents) the extent count increases only by 1. This commit checks for extent count overflow in such cases. Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Allison Henderson Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_bmap.c | 6 ++++++ fs/xfs/libxfs/xfs_inode_fork.h | 6 ++++++ fs/xfs/xfs_bmap_item.c | 7 +++++++ fs/xfs/xfs_bmap_util.c | 5 +++++ fs/xfs/xfs_dquot.c | 8 +++++++- fs/xfs/xfs_iomap.c | 5 +++++ fs/xfs/xfs_rtalloc.c | 5 +++++ 7 files changed, 41 insertions(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index d9a692484eae..505358839d2f 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -4527,6 +4527,12 @@ xfs_bmapi_convert_delalloc( return error; xfs_ilock(ip, XFS_ILOCK_EXCL); + + error = xfs_iext_count_may_overflow(ip, whichfork, + XFS_IEXT_ADD_NOSPLIT_CNT); + if (error) + goto out_trans_cancel; + xfs_trans_ijoin(tp, ip, 0); if (!xfs_iext_lookup_extent(ip, ifp, offset_fsb, &bma.icur, &bma.got) || diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index 0beb8e2a00be..7fc2b129a2e7 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -34,6 +34,12 @@ struct xfs_ifork { #define XFS_IFEXTENTS 0x02 /* All extent pointers are read in */ #define XFS_IFBROOT 0x04 /* i_broot points to the bmap b-tree root */ +/* + * Worst-case increase in the fork extent count when we're adding a single + * extent to a fork and there's no possibility of splitting an existing mapping. + */ +#define XFS_IEXT_ADD_NOSPLIT_CNT (1) + /* * Fork handling. */ diff --git a/fs/xfs/xfs_bmap_item.c b/fs/xfs/xfs_bmap_item.c index 9e16a4d0f97c..1610d6ad089b 100644 --- a/fs/xfs/xfs_bmap_item.c +++ b/fs/xfs/xfs_bmap_item.c @@ -497,6 +497,13 @@ xfs_bui_item_recover( xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, 0); + if (bui_type == XFS_BMAP_MAP) { + error = xfs_iext_count_may_overflow(ip, whichfork, + XFS_IEXT_ADD_NOSPLIT_CNT); + if (error) + goto err_cancel; + } + count = bmap->me_len; error = xfs_trans_log_finish_bmap_update(tp, budp, bui_type, ip, whichfork, bmap->me_startoff, bmap->me_startblock, diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index f2a8a0e75e1f..dcd6e61df711 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -822,6 +822,11 @@ xfs_alloc_file_space( if (error) goto error1; + error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + XFS_IEXT_ADD_NOSPLIT_CNT); + if (error) + goto error0; + xfs_trans_ijoin(tp, ip, 0); error = xfs_bmapi_write(tp, ip, startoffset_fsb, diff --git a/fs/xfs/xfs_dquot.c b/fs/xfs/xfs_dquot.c index 1d95ed387d66..175f544f7c45 100644 --- a/fs/xfs/xfs_dquot.c +++ b/fs/xfs/xfs_dquot.c @@ -314,8 +314,14 @@ xfs_dquot_disk_alloc( return -ESRCH; } - /* Create the block mapping. */ xfs_trans_ijoin(tp, quotip, XFS_ILOCK_EXCL); + + error = xfs_iext_count_may_overflow(quotip, XFS_DATA_FORK, + XFS_IEXT_ADD_NOSPLIT_CNT); + if (error) + return error; + + /* Create the block mapping. */ error = xfs_bmapi_write(tp, quotip, dqp->q_fileoffset, XFS_DQUOT_CLUSTER_SIZE_FSB, XFS_BMAPI_METADATA, 0, &map, &nmaps); diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index 3abb8b9d6f4c..a302a96823b8 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -250,6 +250,11 @@ xfs_iomap_write_direct( if (error) goto out_trans_cancel; + error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + XFS_IEXT_ADD_NOSPLIT_CNT); + if (error) + goto out_trans_cancel; + xfs_trans_ijoin(tp, ip, 0); /* diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index 1c3969807fb9..45ef7fa69e1d 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -804,6 +804,11 @@ xfs_growfs_rt_alloc( xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); + error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + XFS_IEXT_ADD_NOSPLIT_CNT); + if (error) + goto out_trans_cancel; + /* * Allocate blocks to the bitmap file. */ From patchwork Tue Nov 3 15:06: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: 11877927 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 35414921 for ; Tue, 3 Nov 2020 15:07:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 05D0F223C7 for ; Tue, 3 Nov 2020 15:07:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UGvoqpRD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728158AbgKCPHl (ORCPT ); Tue, 3 Nov 2020 10:07:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728180AbgKCPHE (ORCPT ); Tue, 3 Nov 2020 10:07:04 -0500 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BE71C0613D1 for ; Tue, 3 Nov 2020 07:07:04 -0800 (PST) Received: by mail-pg1-x544.google.com with SMTP id o3so13868058pgr.11 for ; Tue, 03 Nov 2020 07:07:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ttah+KnBauDQXA8r3dO7gvzvR5vDgdkbnCETl2BO3+U=; b=UGvoqpRDDapPB+ffryDtEfjDtjDgzgF25xlvkjtk7st17DCLhMUFE+4POTIxmcRFRm QV9Cxq7pmfhifukfJyr8cXF1PVptcZe/tNHxdjHsjMzlQUhdD42tLv1lZD5EYa6adJeH k31dGyjBmXqALzmzEdk4ZpfXXVTRitcg4tqokhLxRB9tF3PBZU+xOhUkiR1N0/XAoaUp y5B1NCLQK2SjytSehwXwvlrXGoEGS7GkqIUIl3N25IFBQxfO/DNgxMgzJAamR7m1WQJN 5sdDN0KXnTfV3+fy/ROWzAsNSXQofUyAE78jUH3jep1NehSP0kB63a6dCAGVP566w0QA 225g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ttah+KnBauDQXA8r3dO7gvzvR5vDgdkbnCETl2BO3+U=; b=W5dcGVWQYcVqq7XNTr2g/3vShH3ZnVk9mBJN7IlnOdzL7DgN8T/QfWYiCQ1jF9x5u9 vYeIuMXxvbBxosZ5T/D+Af7qCUypH/AU6835JGD9SubyG6AQymwY2aty8Jh0pvHrIySg NpFF0pMlTuiVkV4jF841uU/Suiw3ITBxcdG3yVuRAseshpHyGS3p1PzyRQ+I4bceA6yX LmBjTjapsBwd1gvGDhkk7xcaSHCVggMnVX4PN55Z8LK8aOOXR8yjZVhFTMM8oehj9Aqr L1cqvzhSBHDCN//ERSDpXvVb2qP6LrYT5FMCSpqtBAxs6ibqqrAdQPyAUE4tiddIj5qN 2UAg== X-Gm-Message-State: AOAM530WuVR1MNndG6KOl56R5x5hrDvcYDpN/v9yU9k+CietRTa6tDio g8uDTeXl3BAWseI1SSJf4ZaqGeyq3etckA== X-Google-Smtp-Source: ABdhPJxgcWZXvg9ARMcWxiroFRpoCyBfu3jcuroKM0towRCM72yoGxmgPJxjgu92BifYMTAKMXHpXg== X-Received: by 2002:a62:f20d:0:b029:18b:39c3:38d5 with SMTP id m13-20020a62f20d0000b029018b39c338d5mr2145787pfh.70.1604416023419; Tue, 03 Nov 2020 07:07:03 -0800 (PST) Received: from localhost.localdomain ([122.179.48.228]) by smtp.gmail.com with ESMTPSA id 15sm15936955pgs.52.2020.11.03.07.07.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 07:07:02 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, allison.henderson@oracle.com, Christoph Hellwig Subject: [PATCH V10 03/14] xfs: Check for extent overflow when punching a hole Date: Tue, 3 Nov 2020 20:36:31 +0530 Message-Id: <20201103150642.2032284-4-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201103150642.2032284-1-chandanrlinux@gmail.com> References: <20201103150642.2032284-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org The extent mapping the file offset at which a hole has to be inserted will be split into two extents causing extent count to increase by 1. Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Allison Henderson Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_inode_fork.h | 7 +++++++ fs/xfs/xfs_bmap_item.c | 15 +++++++++------ fs/xfs/xfs_bmap_util.c | 10 ++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index 7fc2b129a2e7..bcac769a7df6 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -40,6 +40,13 @@ struct xfs_ifork { */ #define XFS_IEXT_ADD_NOSPLIT_CNT (1) +/* + * Punching out an extent from the middle of an existing extent can cause the + * extent count to increase by 1. + * i.e. | Old extent | Hole | Old extent | + */ +#define XFS_IEXT_PUNCH_HOLE_CNT (1) + /* * Fork handling. */ diff --git a/fs/xfs/xfs_bmap_item.c b/fs/xfs/xfs_bmap_item.c index 1610d6ad089b..80d828394158 100644 --- a/fs/xfs/xfs_bmap_item.c +++ b/fs/xfs/xfs_bmap_item.c @@ -439,6 +439,7 @@ xfs_bui_item_recover( xfs_exntst_t state; unsigned int bui_type; int whichfork; + int iext_delta; int error = 0; /* Only one mapping operation per BUI... */ @@ -497,12 +498,14 @@ xfs_bui_item_recover( xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, 0); - if (bui_type == XFS_BMAP_MAP) { - error = xfs_iext_count_may_overflow(ip, whichfork, - XFS_IEXT_ADD_NOSPLIT_CNT); - if (error) - goto err_cancel; - } + if (bui_type == XFS_BMAP_MAP) + iext_delta = XFS_IEXT_ADD_NOSPLIT_CNT; + else + iext_delta = XFS_IEXT_PUNCH_HOLE_CNT; + + error = xfs_iext_count_may_overflow(ip, whichfork, iext_delta); + if (error) + goto err_cancel; count = bmap->me_len; error = xfs_trans_log_finish_bmap_update(tp, budp, bui_type, ip, diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index dcd6e61df711..0776abd0103c 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -891,6 +891,11 @@ xfs_unmap_extent( xfs_trans_ijoin(tp, ip, 0); + error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + XFS_IEXT_PUNCH_HOLE_CNT); + if (error) + goto out_trans_cancel; + error = xfs_bunmapi(tp, ip, startoffset_fsb, len_fsb, 0, 2, done); if (error) goto out_trans_cancel; @@ -1176,6 +1181,11 @@ xfs_insert_file_space( xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, 0); + error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + XFS_IEXT_PUNCH_HOLE_CNT); + if (error) + goto out_trans_cancel; + /* * The extent shifting code works on extent granularity. So, if stop_fsb * is not the starting block of extent, we need to split the extent at From patchwork Tue Nov 3 15:06: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: 11877923 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 B1686166C for ; Tue, 3 Nov 2020 15:07:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 81DB1223C7 for ; Tue, 3 Nov 2020 15:07:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WtD4ZdBT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728184AbgKCPHl (ORCPT ); Tue, 3 Nov 2020 10:07:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728183AbgKCPHH (ORCPT ); Tue, 3 Nov 2020 10:07:07 -0500 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DE81C0613D1 for ; Tue, 3 Nov 2020 07:07:07 -0800 (PST) Received: by mail-pg1-x544.google.com with SMTP id u4so2077364pgr.9 for ; Tue, 03 Nov 2020 07:07:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BnzW6ZRTk6jYpEdb9hSauPeHwb+Af98DVjIElOxlMOU=; b=WtD4ZdBTgLyxurH+ujaLpTY8aWkKLQW9ujQRzb4XO13p3RY6161xUP1ezep2Vyrgrd 0+SU1LO6K12LcibREAyMHuoCJzJ7ZAt9cpRgFKBb6lfdxkScp7oCgyH2Vq2hFhy+5zXI PQFQ8YTv6zINmyuouwHqzQrsiWwlbE9asDevrImSipnoL4BkEPXZZ0mtdk+/SVv+573k ppThLh/JdFdVVR78REkU4SuUSRo0c8tU0L0jatr82ZXOaU+2qwCmgpjpbC5VaUU9W5Pv 3kleETG69pd0WECXEMXV5bugrUtFwATu673xySrXqq9dMMyOsltweKFfyMGOXlV7F3ky c6Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BnzW6ZRTk6jYpEdb9hSauPeHwb+Af98DVjIElOxlMOU=; b=DhwY/crN+5S5z+pXUpv9yFCs1d9iadoUS1Ip8QT7MQnA8gtWyK8ACmfzcbXaS1JozW LBCJ4vMuRjxFnxB/d+WXed2aiRNIwuMEchfk8wdiZHfPBewX/pzPq6Irh2cA6IJHd8t8 8SnoCXeUwiB9n7D0qgbKRJZsRr0f4UkHkPa1mOF4I/d0LnlMBuONjFj2tkb9KJRSQBYa ZdVCuSlPF8LM7rrDvl3D31/SkeoWxwC1nEBmAQmmCgu3E+UR7yEJRa6kLb+NetF4JD09 s23mxzNBH9vDSpYTMChVT74+x8dSXTCXvOwt/RcuyemP41dcZ1a1kZ52OUMKLBZ89i5M 4vwg== X-Gm-Message-State: AOAM533FzPrOiQNue3GpITktAdXerR2qWZhtVpk9vLLgZ4DtwES6sG1f I9ipQChp7VSoNOWVkkClcYDs0vgorKrwKw== X-Google-Smtp-Source: ABdhPJzocrrxL0Bq9DA0izBtpDs3k2rhAfT948pagpBuKqPhcgTOwVL51aZeQAQ3ZC+BSvZkfoOlFA== X-Received: by 2002:aa7:9e03:0:b029:164:427a:8f94 with SMTP id y3-20020aa79e030000b0290164427a8f94mr25362598pfq.5.1604416026403; Tue, 03 Nov 2020 07:07:06 -0800 (PST) Received: from localhost.localdomain ([122.179.48.228]) by smtp.gmail.com with ESMTPSA id 15sm15936955pgs.52.2020.11.03.07.07.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 07:07:05 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, allison.henderson@oracle.com, Christoph Hellwig Subject: [PATCH V10 04/14] xfs: Check for extent overflow when adding/removing xattrs Date: Tue, 3 Nov 2020 20:36:32 +0530 Message-Id: <20201103150642.2032284-5-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201103150642.2032284-1-chandanrlinux@gmail.com> References: <20201103150642.2032284-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Adding/removing an xattr can cause XFS_DA_NODE_MAXDEPTH extents to be added. One extra extent for dabtree in case a local attr is large enough to cause a double split. It can also cause extent count to increase proportional to the size of a remote xattr's value. Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Allison Henderson Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_attr.c | 13 +++++++++++++ fs/xfs/libxfs/xfs_inode_fork.h | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c index fd8e6418a0d3..be51e7068dcd 100644 --- a/fs/xfs/libxfs/xfs_attr.c +++ b/fs/xfs/libxfs/xfs_attr.c @@ -396,6 +396,7 @@ xfs_attr_set( struct xfs_trans_res tres; bool rsvd = (args->attr_filter & XFS_ATTR_ROOT); int error, local; + int rmt_blks = 0; unsigned int total; if (XFS_FORCED_SHUTDOWN(dp->i_mount)) @@ -442,11 +443,15 @@ xfs_attr_set( tres.tr_logcount = XFS_ATTRSET_LOG_COUNT; tres.tr_logflags = XFS_TRANS_PERM_LOG_RES; total = args->total; + + if (!local) + rmt_blks = xfs_attr3_rmt_blocks(mp, args->valuelen); } else { XFS_STATS_INC(mp, xs_attr_remove); tres = M_RES(mp)->tr_attrrm; total = XFS_ATTRRM_SPACE_RES(mp); + rmt_blks = xfs_attr3_rmt_blocks(mp, XFS_XATTR_SIZE_MAX); } /* @@ -460,6 +465,14 @@ xfs_attr_set( xfs_ilock(dp, XFS_ILOCK_EXCL); xfs_trans_ijoin(args->trans, dp, 0); + + if (args->value || xfs_inode_hasattr(dp)) { + error = xfs_iext_count_may_overflow(dp, XFS_ATTR_FORK, + XFS_IEXT_ATTR_MANIP_CNT(rmt_blks)); + if (error) + goto out_trans_cancel; + } + if (args->value) { unsigned int quota_flags = XFS_QMOPT_RES_REGBLKS; diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index bcac769a7df6..5de2f07d0dd5 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -47,6 +47,16 @@ struct xfs_ifork { */ #define XFS_IEXT_PUNCH_HOLE_CNT (1) +/* + * Adding/removing an xattr can cause XFS_DA_NODE_MAXDEPTH extents to + * be added. One extra extent for dabtree in case a local attr is + * large enough to cause a double split. It can also cause extent + * count to increase proportional to the size of a remote xattr's + * value. + */ +#define XFS_IEXT_ATTR_MANIP_CNT(rmt_blks) \ + (XFS_DA_NODE_MAXDEPTH + max(1, rmt_blks)) + /* * Fork handling. */ From patchwork Tue Nov 3 15:06: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: 11877925 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 E920E6A2 for ; Tue, 3 Nov 2020 15:07:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C17F8223C7 for ; Tue, 3 Nov 2020 15:07:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FoSYf0Q2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728264AbgKCPHk (ORCPT ); Tue, 3 Nov 2020 10:07:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728184AbgKCPHK (ORCPT ); Tue, 3 Nov 2020 10:07:10 -0500 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23ABDC0613D1 for ; Tue, 3 Nov 2020 07:07:10 -0800 (PST) Received: by mail-pf1-x442.google.com with SMTP id w65so14447892pfd.3 for ; Tue, 03 Nov 2020 07:07:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4jR8INSWSC6ttwbiQgR4/JGrIIg0yQz4NSER0DYDRnc=; b=FoSYf0Q21qP/d8SX1IynluCtpAwoVz5Bx5/4nf4xPrlejdXUztoK2ijWiiR58bRXpT dbp8gENADiOUe/dAoE9EEoaU0sKONRGa/7xMk/o0Z6tm1gba7XjUeUorw8vPKjamlLYN ZXrn0d8xnbB6STc5QWyZV3ryzXHTTkUmqvsMHK8+EhdRpkFDCtJoFQmOQAOANsvSpbRF 6+iD86eQvLJZK5lceS/82I5mwpg2HJUYxhhmkex0h/B9HWHpzeCmpeWA8hfmnq2VboKx FgA9B4JY0OmkiLuxwL1pe2hR3/vw1XxExkM0OVzMJNm4UDo5vZeyPzcnMmG02HoDfOoL fSKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4jR8INSWSC6ttwbiQgR4/JGrIIg0yQz4NSER0DYDRnc=; b=G3k+AelZhML3Coeoj05iK9+EWGFoSqKt9cYhnHk7t6evZV7TST0RsgDn5c6wYazU+c wB3dVyJt6RiwxWInCJRDrvHaMkTFB8PoTWUCUSxf9hTC2dLgYEaCwfUZgzPe5JSmRmK9 sshl9GO4i6yztoJXlQIrJV2S2HH3zKwgkiYSPk3DAGh3Pw9OxUIsqbw/Rga4wUdrbPAc 2ECj8pWz8Dw7JhXqgcg1EQAS2zPwVWKLgYX1BUh2dNgOLbvOkNzAWs61ldlv1U9Jkc3k kqNUz3tc2Bct95B7Ngc2JP0m2mLDZnW2KCE9FEuoEltkniTlF9hQuCrONWwA7WYf44l7 ey9w== X-Gm-Message-State: AOAM533SaBGu3q8l1b3RCKGMT8gIQMCtHzq7HQYVkKvVy8oHnksWBlF/ 9/kFQTNWKot0jqdFSLvLVLH2GYNeDtqm/Q== X-Google-Smtp-Source: ABdhPJzj2QvyqfW5LAEVKoSd6kg9gaHSFXPtemLYsMgwfydaWD6kzzilTMd1Re5S83HxDHRKDN3axA== X-Received: by 2002:a63:8149:: with SMTP id t70mr12157672pgd.80.1604416029410; Tue, 03 Nov 2020 07:07:09 -0800 (PST) Received: from localhost.localdomain ([122.179.48.228]) by smtp.gmail.com with ESMTPSA id 15sm15936955pgs.52.2020.11.03.07.07.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 07:07:08 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, allison.henderson@oracle.com, Christoph Hellwig Subject: [PATCH V10 05/14] xfs: Check for extent overflow when adding/removing dir entries Date: Tue, 3 Nov 2020 20:36:33 +0530 Message-Id: <20201103150642.2032284-6-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201103150642.2032284-1-chandanrlinux@gmail.com> References: <20201103150642.2032284-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Directory entry addition/removal can cause the following, 1. Data block can be added/removed. A new extent can cause extent count to increase by 1. 2. Free disk block can be added/removed. Same behaviour as described above for Data block. 3. Dabtree blocks. XFS_DA_NODE_MAXDEPTH blocks can be added. Each of these can be new extents. Hence extent count can increase by XFS_DA_NODE_MAXDEPTH. Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Allison Henderson Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_inode_fork.h | 13 +++++++++++++ fs/xfs/xfs_inode.c | 27 +++++++++++++++++++++++++++ fs/xfs/xfs_symlink.c | 5 +++++ 3 files changed, 45 insertions(+) diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index 5de2f07d0dd5..fd93fdc67ee4 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -57,6 +57,19 @@ struct xfs_ifork { #define XFS_IEXT_ATTR_MANIP_CNT(rmt_blks) \ (XFS_DA_NODE_MAXDEPTH + max(1, rmt_blks)) +/* + * Directory entry addition/removal can cause the following, + * 1. Data block can be added/removed. + * A new extent can cause extent count to increase by 1. + * 2. Free disk block can be added/removed. + * Same behaviour as described above for Data block. + * 3. Dabtree blocks. + * XFS_DA_NODE_MAXDEPTH blocks can be added. Each of these can be new + * extents. Hence extent count can increase by XFS_DA_NODE_MAXDEPTH. + */ +#define XFS_IEXT_DIR_MANIP_CNT(mp) \ + ((XFS_DA_NODE_MAXDEPTH + 1 + 1) * (mp)->m_dir_geo->fsbcount) + /* * Fork handling. */ diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 2bfbcf28b1bd..5b41ffaf04d7 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -1177,6 +1177,11 @@ xfs_create( if (error) goto out_trans_cancel; + error = xfs_iext_count_may_overflow(dp, XFS_DATA_FORK, + XFS_IEXT_DIR_MANIP_CNT(mp)); + if (error) + goto out_trans_cancel; + /* * A newly created regular or special file just has one directory * entry pointing to them, but a directory also the "." entry @@ -1393,6 +1398,11 @@ xfs_link( xfs_trans_ijoin(tp, sip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, tdp, XFS_ILOCK_EXCL); + error = xfs_iext_count_may_overflow(tdp, XFS_DATA_FORK, + XFS_IEXT_DIR_MANIP_CNT(mp)); + if (error) + goto error_return; + /* * If we are using project inheritance, we only allow hard link * creation in our tree when the project IDs are the same; else @@ -2861,6 +2871,11 @@ xfs_remove( xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); + error = xfs_iext_count_may_overflow(dp, XFS_DATA_FORK, + XFS_IEXT_DIR_MANIP_CNT(mp)); + if (error) + goto out_trans_cancel; + /* * If we're removing a directory perform some additional validation. */ @@ -3221,6 +3236,18 @@ xfs_rename( if (wip) xfs_trans_ijoin(tp, wip, XFS_ILOCK_EXCL); + error = xfs_iext_count_may_overflow(src_dp, XFS_DATA_FORK, + XFS_IEXT_DIR_MANIP_CNT(mp)); + if (error) + goto out_trans_cancel; + + if (target_ip == NULL) { + error = xfs_iext_count_may_overflow(target_dp, XFS_DATA_FORK, + XFS_IEXT_DIR_MANIP_CNT(mp)); + if (error) + goto out_trans_cancel; + } + /* * If we are using project inheritance, we only allow renames * into our tree when the project IDs are the same; else the diff --git a/fs/xfs/xfs_symlink.c b/fs/xfs/xfs_symlink.c index 8e88a7ca387e..581a4032a817 100644 --- a/fs/xfs/xfs_symlink.c +++ b/fs/xfs/xfs_symlink.c @@ -220,6 +220,11 @@ xfs_symlink( if (error) goto out_trans_cancel; + error = xfs_iext_count_may_overflow(dp, XFS_DATA_FORK, + XFS_IEXT_DIR_MANIP_CNT(mp)); + if (error) + goto out_trans_cancel; + /* * Allocate an inode for the symlink. */ From patchwork Tue Nov 3 15:06:34 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: 11877917 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 810AD166C for ; Tue, 3 Nov 2020 15:07:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5D56C2242B for ; Tue, 3 Nov 2020 15:07:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LwEWAo+K" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728257AbgKCPHk (ORCPT ); Tue, 3 Nov 2020 10:07:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728192AbgKCPHN (ORCPT ); Tue, 3 Nov 2020 10:07:13 -0500 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14BAEC0613D1 for ; Tue, 3 Nov 2020 07:07:13 -0800 (PST) Received: by mail-pf1-x444.google.com with SMTP id 10so14438668pfp.5 for ; Tue, 03 Nov 2020 07:07:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XvpLSvlcyBaKGUc+FLHnNx0Ewse7iXgrENCBElNIo4Y=; b=LwEWAo+KER8UgZl20SX8/sqbglwmNReRFZqeNZSbOuTEoRgWVt3LBid1bDKzmHtoDD NS3/dQfY7v5xR178yha1pAuM9RmfE7+oIjRXhqqLBzggR7RdS0wSJ1pKcb7AWD6KHElb ibl770WpFE47wz8o06isP8f+toeE80EpNP0JbwY4knVya0LtDz6BBb38ivg7oqm6RIka SP7/2a4Spl1OH9GlmkVT4yXMCdCxynpke7d2oGI4Uis+2BNZ7wbLMx0p5kwo1anAhs7Z XL/o8M9/Es22QfbQAnsUQQhGnAqsbsSZAjMOiAzTxuGClyIAFg4m/bcQc/V0NzxXp2hw CVPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XvpLSvlcyBaKGUc+FLHnNx0Ewse7iXgrENCBElNIo4Y=; b=KeZIgMqgAy6pWrD1KbZPvp1lDXfXhDfmGiyjwBrlzEPamd7uTliQl/w+shgH+cMT/r LOpg+UGP/8tdPtLoLxOrhuRhNQW4piK4kCJavxdM0qyt+4wEwB6nqfP1a2wpS1+d4PWK +D/uIwRN+n67uMzE6qPlQEa0x9OoSN/jWEG/PtXwDkmb/JBA0xW1ykLWC//TiMEAvqQH TbA3XLRxfPqHtBOQvprclxaWjeVD7Uqm7swJ6cJV3RS5PcnhmmygtgosTOI5qnuDepjD dvGoAaiB6aLWbbAwjn+V5ZE1Y4fdrh7K57mnG1tvgr0bE6nTIfoGBPg4TBEkTSUlVZhJ ZxGw== X-Gm-Message-State: AOAM531ty9Dw8iQY3b8AuXfZ1nNWf+03cbVDq5NGCgmykfoEGf/YEDG4 3ouBXqFsT/TIptIiO3nDm3T56wfQQe8RdQ== X-Google-Smtp-Source: ABdhPJwFwxizwCcDh1eJEzwUXWJO1q6eazD0AhjHHdatRV1hU9b6C8jDR/T6o7ZLIfplyBY9PKnUHw== X-Received: by 2002:a63:b50a:: with SMTP id y10mr17175662pge.88.1604416032322; Tue, 03 Nov 2020 07:07:12 -0800 (PST) Received: from localhost.localdomain ([122.179.48.228]) by smtp.gmail.com with ESMTPSA id 15sm15936955pgs.52.2020.11.03.07.07.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 07:07:11 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, allison.henderson@oracle.com, Christoph Hellwig Subject: [PATCH V10 06/14] xfs: Check for extent overflow when writing to unwritten extent Date: Tue, 3 Nov 2020 20:36:34 +0530 Message-Id: <20201103150642.2032284-7-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201103150642.2032284-1-chandanrlinux@gmail.com> References: <20201103150642.2032284-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org A write to a sub-interval of an existing unwritten extent causes the original extent to be split into 3 extents i.e. | Unwritten | Real | Unwritten | Hence extent count can increase by 2. Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Allison Henderson Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_inode_fork.h | 8 ++++++++ fs/xfs/xfs_iomap.c | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index fd93fdc67ee4..afb647e1e3fa 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -70,6 +70,14 @@ struct xfs_ifork { #define XFS_IEXT_DIR_MANIP_CNT(mp) \ ((XFS_DA_NODE_MAXDEPTH + 1 + 1) * (mp)->m_dir_geo->fsbcount) +/* + * A write to a sub-interval of an existing unwritten extent causes the original + * extent to be split into 3 extents + * i.e. | Unwritten | Real | Unwritten | + * Hence extent count can increase by 2. + */ +#define XFS_IEXT_WRITE_UNWRITTEN_CNT (2) + /* * Fork handling. */ diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index a302a96823b8..2aa788379611 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -566,6 +566,11 @@ xfs_iomap_write_unwritten( if (error) goto error_on_bmapi_transaction; + error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + XFS_IEXT_WRITE_UNWRITTEN_CNT); + if (error) + goto error_on_bmapi_transaction; + /* * Modify the unwritten extent state of the buffer. */ From patchwork Tue Nov 3 15:06:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11877915 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 3037A921 for ; Tue, 3 Nov 2020 15:07:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0CC7F223EA for ; Tue, 3 Nov 2020 15:07:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tIey9QqO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728083AbgKCPHj (ORCPT ); Tue, 3 Nov 2020 10:07:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727553AbgKCPHQ (ORCPT ); Tue, 3 Nov 2020 10:07:16 -0500 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0122C0613D1 for ; Tue, 3 Nov 2020 07:07:15 -0800 (PST) Received: by mail-pf1-x444.google.com with SMTP id 133so14426652pfx.11 for ; Tue, 03 Nov 2020 07:07:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ILp5iM7cQcNHUrkAX0Lz/6PweGyzSkbIPzR9qhi/Ue0=; b=tIey9QqODpXKQrzeZNmJU7AvQWknbFjvIIIhBWJnWIvp33i/WKXnJkJtUIv9AAhv9y tXUJtDVh0vTbU1O3YgnK0Ywcf4FI78Kq2dCzbA5kIf+m/a0I9tAdWC979KT4ayS14LU1 TbeA1bQN/TtsdJqlwGoyT9SAOiuAhg79mQrSIqtN0oWHMtMpe7J1ooPge3ftOOaqsU8S DTa1tHLhGBKU2DEn+Tx8z+uuIb6YabnARu0D5PgG3tLpOPhcIPJhQ/7B8LFPu6Qz5mn2 +BUAoCoRn535Js2PYR94DMAB9k0tW2d0Oyko4VXZ+7L+j1MD7Ohquc4E04RP7uWDp09Q +W9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ILp5iM7cQcNHUrkAX0Lz/6PweGyzSkbIPzR9qhi/Ue0=; b=MsOUoG9fi/24u9Bx/0NWGgtbh1YGHA/Z3dhqOEfkPonXqWbK955Y5IG1lcWzOrkLbu UmqjFrD6ecZHeKpEKK8X/3Pu1BLyPZLsTOXFEaBTIcCLpgE+/LUaXH2BAAKVv0yLm9f2 UHnKHmTfDyBpUChBfX3cSm0s/dREnr45twulztoJaephwKpx+MIoRVVcEP7qP+iOhnSR kZQ8PMzASLycgc8OyzyeEgAjwQGHfatIq0y4YYquu5PcWehhdjNVBf0uw3nn8M1yGqaZ UFkyd5edMNcC2jgku4P+1ezqlOm1/qawPxVMfFhRValnTEhnFOSVhgr4GMmLZCW/REFU BVqg== X-Gm-Message-State: AOAM5311XwSYQjN7ZSqxR0GW2uLJC0enzaw0AKOdsUDez8lrqmQ+Q61f fdkhI8Ry5mDNTlWugyhKjSzkDh+/zNu9oA== X-Google-Smtp-Source: ABdhPJyh+XKjzjCARwnJDbvwV6DgZlD3iGLXe2A2qBTdr99G7S64tY8vEuAy+BnTJAAUMSUuGV3KLQ== X-Received: by 2002:aa7:9afc:0:b029:152:9d45:6723 with SMTP id y28-20020aa79afc0000b02901529d456723mr25412417pfp.35.1604416035260; Tue, 03 Nov 2020 07:07:15 -0800 (PST) Received: from localhost.localdomain ([122.179.48.228]) by smtp.gmail.com with ESMTPSA id 15sm15936955pgs.52.2020.11.03.07.07.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 07:07:14 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, allison.henderson@oracle.com, Christoph Hellwig Subject: [PATCH V10 07/14] xfs: Check for extent overflow when moving extent from cow to data fork Date: Tue, 3 Nov 2020 20:36:35 +0530 Message-Id: <20201103150642.2032284-8-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201103150642.2032284-1-chandanrlinux@gmail.com> References: <20201103150642.2032284-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Moving an extent to data fork can cause a sub-interval of an existing extent to be unmapped. This will increase extent count by 1. Mapping in the new extent can increase the extent count by 1 again i.e. | Old extent | New extent | Old extent | Hence number of extents increases by 2. Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Allison Henderson Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_inode_fork.h | 9 +++++++++ fs/xfs/xfs_reflink.c | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index afb647e1e3fa..b99e67e7b59b 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -78,6 +78,15 @@ struct xfs_ifork { */ #define XFS_IEXT_WRITE_UNWRITTEN_CNT (2) +/* + * Moving an extent to data fork can cause a sub-interval of an existing extent + * to be unmapped. This will increase extent count by 1. Mapping in the new + * extent can increase the extent count by 1 again i.e. + * | Old extent | New extent | Old extent | + * Hence number of extents increases by 2. + */ +#define XFS_IEXT_REFLINK_END_COW_CNT (2) + /* * Fork handling. */ diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index 16098dc42add..4f0198f636ad 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -628,6 +628,11 @@ xfs_reflink_end_cow_extent( xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, 0); + error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + XFS_IEXT_REFLINK_END_COW_CNT); + if (error) + goto out_cancel; + /* * In case of racing, overlapping AIO writes no COW extents might be * left by the time I/O completes for the loser of the race. In that From patchwork Tue Nov 3 15:06:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11877913 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 F22E11130 for ; Tue, 3 Nov 2020 15:07:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CF7AB223EA for ; Tue, 3 Nov 2020 15:07:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mVs8M7Ay" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727688AbgKCPHj (ORCPT ); Tue, 3 Nov 2020 10:07:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728083AbgKCPHS (ORCPT ); Tue, 3 Nov 2020 10:07:18 -0500 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC3CDC0613D1 for ; Tue, 3 Nov 2020 07:07:18 -0800 (PST) Received: by mail-pg1-x544.google.com with SMTP id u4so2077765pgr.9 for ; Tue, 03 Nov 2020 07:07:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nt70IvY/vtgLa/y5uH7G+5m8dg0wvGwo7q/BlwAPtZA=; b=mVs8M7Aya9EazheQN0WIhwHnOgIdiyMxurbRT6QQ32qA8RPrUDWuNuLh/MUFTXLj12 G66xN5sVLLSRe5OHKyW73O1qRHrcKWT7zS4lHVy9q+/3XiGcPpdjn1ZkUS9mOExWWR8r w2nhEIIwudjBj4OxTXLZsr6ti+5qsT6xLiedBxZld28lPYW7Q37LiXMaWAcNpc6NgreC oeosIL/PwQH1KLJwQrIqwcSU3tjjzkcKJT/tHCX+Kn2JeVS0422cC2jXMxn6EpzbRIET SaJWSnY4mWZPAwdT8OJHK6yaWCnpGWH8nAJCV4QiUnzShYXqXeJt4Ck94YKnHGVU5JCY sqyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nt70IvY/vtgLa/y5uH7G+5m8dg0wvGwo7q/BlwAPtZA=; b=ZIsaAgm2xVSlVnOsn+4yDKBtLFWa5KZSf+wXpVnSz+ZFP6EjeIXZWIxXQoqbWytqwm 3Jwu/UPwRfvjVFkFN2cWQuv3HymYXucL4B82tznHRmQLBojzNi5mRzilzu/lzXIYbhkC YqaGU4fDu8egPR3TXWkValjREHzqchi6vwe7/xxLJ5aabbIKAGK4XytXW3e0s0LlCPDC PbGKNC4YC0MLUatbHrpac9nJ0DVMAiHfq6pnXBZ5QJyXrKDFS7KzF1/PCJyh8E7ylKWv b/rXOXB6UznAUpmB9qGfbotR9l8rtRlhpNXCcjV/qzI5Iz6Ie8kXE20SpxFlnskHrfn6 g5SA== X-Gm-Message-State: AOAM532Co7rFpZ5I7B5YkGgNfv750U2wj0su6pAFrlgkzUQjqEMvaZcT LTk3pG8jsT/fsHcyRm4HSCwM78WSvOxfdw== X-Google-Smtp-Source: ABdhPJz6IxvpDF+TMVqkrnMBwwzWIhjfVk7QiuVL0FnyoOKo2oxCNcyz93Yo4t0D3ABh+ZWjajGcyQ== X-Received: by 2002:a63:d54e:: with SMTP id v14mr17885607pgi.203.1604416038112; Tue, 03 Nov 2020 07:07:18 -0800 (PST) Received: from localhost.localdomain ([122.179.48.228]) by smtp.gmail.com with ESMTPSA id 15sm15936955pgs.52.2020.11.03.07.07.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 07:07:17 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, allison.henderson@oracle.com Subject: [PATCH V10 08/14] xfs: Check for extent overflow when remapping an extent Date: Tue, 3 Nov 2020 20:36:36 +0530 Message-Id: <20201103150642.2032284-9-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201103150642.2032284-1-chandanrlinux@gmail.com> References: <20201103150642.2032284-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Remapping an extent involves unmapping the existing extent and mapping in the new extent. When unmapping, an extent containing the entire unmap range can be split into two extents, i.e. | Old extent | hole | Old extent | Hence extent count increases by 1. Mapping in the new extent into the destination file can increase the extent count by 1. Reviewed-by: Allison Henderson Reviewed-by: Darrick J. Wong Signed-off-by: Chandan Babu R --- fs/xfs/xfs_reflink.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index 4f0198f636ad..856fe755a5e9 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -1006,6 +1006,7 @@ xfs_reflink_remap_extent( unsigned int resblks; bool smap_real; bool dmap_written = xfs_bmap_is_written_extent(dmap); + int iext_delta = 0; int nimaps; int error; @@ -1099,6 +1100,16 @@ xfs_reflink_remap_extent( goto out_cancel; } + if (smap_real) + ++iext_delta; + + if (dmap_written) + ++iext_delta; + + error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, iext_delta); + if (error) + goto out_cancel; + if (smap_real) { /* * If the extent we're unmapping is backed by storage (written From patchwork Tue Nov 3 15:06:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11877911 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 4CEB56A2 for ; Tue, 3 Nov 2020 15:07:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 26FB7223EA for ; Tue, 3 Nov 2020 15:07:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="byNs5f1s" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728130AbgKCPHj (ORCPT ); Tue, 3 Nov 2020 10:07:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727688AbgKCPHV (ORCPT ); Tue, 3 Nov 2020 10:07:21 -0500 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C841C0613D1 for ; Tue, 3 Nov 2020 07:07:21 -0800 (PST) Received: by mail-pl1-x644.google.com with SMTP id r10so8692561plx.3 for ; Tue, 03 Nov 2020 07:07:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gjkXFZh3Yb0k29wFDewcPx5MIG4z7sYEJ/SPODbUO9A=; b=byNs5f1sa2Fs8Liu4Ddsf/kojz0OOsYkNJFBH3V7rDuQ4tSiMOip6T4xsz46uOwoGF vDBnab8bo71ozSSV9QVMWKVJcsYGD6YAny5SisUu9Aq/SyTeQm64JNyrtvdi679udXb5 9ShHaZOjUU/NONpAaYEsRNEHq3tXi6PPzYtXiwa18ubYpyHAgKQxVRS/NUWZMZmJJ1Hm 0IC89BEFRg/ZVsmfNA5Q6oos73UXTiMT+xjWmE9Q39SkxrkV7QGhj1AxOxG/mE7d1LxP t/gBkwPTQ8jcXdoY2+fR4oSb4x5jS+MybzI+rNjj4Mgug7Mne2DhgDJ8quumxVDPuP3Z cPVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gjkXFZh3Yb0k29wFDewcPx5MIG4z7sYEJ/SPODbUO9A=; b=mM77wcnopcnxPbOCoIv9qF75UCvnPCxKFZkxj8Dj+8Nm6tEfYJT9dUkt5sf07IFSWm +rTiB3ah0PQYZooBB6mAXNOI8rbk7O0ltHhsCAlxk+W/ADOS97BKi4VL0CVUWimcaW+B Cozwe/cWJFUlXfqD9MEMYywKZBDeq1eZO02SsMQbKHdoRDEQbGl6Um7FidLnyeeFcoXT ON/knkfhuotsDCXNTEy8se/8sD1Z6JCFpyH1C7ErKp7nQnlUq69I8VLwoNcPrTZIY0Dc V8tLZUba8fCZtuD6z1jT9+Ar3Tqviptv1ttMKc3+1aPd6yfwLm6yd7odWshjxX0K2tDP rZVA== X-Gm-Message-State: AOAM531bdPgwlYV1YFI+JY75PRelCBZOXn4UD6l/wlqtafePC4OlF6Dg ltgp+ASK4rNjqJGXHAw6IH04Vq17ai+9XA== X-Google-Smtp-Source: ABdhPJzTXnPCm8tRgFA8fbbtPtO7xuc3VxJzVzjVnZ2ZApDsZWeRGpnewi9fMAVc58oT0Ijs6y7p5w== X-Received: by 2002:a17:902:8c88:b029:d6:d0e4:7e1b with SMTP id t8-20020a1709028c88b02900d6d0e47e1bmr8386304plo.70.1604416040856; Tue, 03 Nov 2020 07:07:20 -0800 (PST) Received: from localhost.localdomain ([122.179.48.228]) by smtp.gmail.com with ESMTPSA id 15sm15936955pgs.52.2020.11.03.07.07.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 07:07:20 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, allison.henderson@oracle.com Subject: [PATCH V10 09/14] xfs: Check for extent overflow when swapping extents Date: Tue, 3 Nov 2020 20:36:37 +0530 Message-Id: <20201103150642.2032284-10-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201103150642.2032284-1-chandanrlinux@gmail.com> References: <20201103150642.2032284-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Removing an initial range of source/donor file's extent and adding a new extent (from donor/source file) in its place will cause extent count to increase by 1. Reviewed-by: Darrick J. Wong Reviewed-by: Allison Henderson Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_inode_fork.h | 7 +++++++ fs/xfs/xfs_bmap_util.c | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index b99e67e7b59b..969b06160d44 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -87,6 +87,13 @@ struct xfs_ifork { */ #define XFS_IEXT_REFLINK_END_COW_CNT (2) +/* + * Removing an initial range of source/donor file's extent and adding a new + * extent (from donor/source file) in its place will cause extent count to + * increase by 1. + */ +#define XFS_IEXT_SWAP_RMAP_CNT (1) + /* * Fork handling. */ diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index 0776abd0103c..b6728fdf50ae 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -1407,6 +1407,22 @@ xfs_swap_extent_rmap( irec.br_blockcount); trace_xfs_swap_extent_rmap_remap_piece(tip, &uirec); + if (xfs_bmap_is_real_extent(&uirec)) { + error = xfs_iext_count_may_overflow(ip, + XFS_DATA_FORK, + XFS_IEXT_SWAP_RMAP_CNT); + if (error) + goto out; + } + + if (xfs_bmap_is_real_extent(&irec)) { + error = xfs_iext_count_may_overflow(tip, + XFS_DATA_FORK, + XFS_IEXT_SWAP_RMAP_CNT); + if (error) + goto out; + } + /* Remove the mapping from the donor file. */ xfs_bmap_unmap_extent(tp, tip, &uirec); From patchwork Tue Nov 3 15:06:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11877905 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 ABA786A2 for ; Tue, 3 Nov 2020 15:07:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8C0B82242F for ; Tue, 3 Nov 2020 15:07:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Gji8QSyF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728164AbgKCPHf (ORCPT ); Tue, 3 Nov 2020 10:07:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728130AbgKCPHY (ORCPT ); Tue, 3 Nov 2020 10:07:24 -0500 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 951A7C0613D1 for ; Tue, 3 Nov 2020 07:07:24 -0800 (PST) Received: by mail-pl1-x643.google.com with SMTP id p4so1358323plr.1 for ; Tue, 03 Nov 2020 07:07:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/T4H2MiD0QBM8tig6ImJk3HvLU2caAc+kKCOLA74nf0=; b=Gji8QSyFRMPvCG6jGUGZyiNYFOKlcyVCocaTv6dIf2GDPQTFNonSTRUW2i0rcgujcr /zgtX6xpDimeC7AGpzOaLpZe3hE7QAjii1ePrxzD3NvmtUtqcRZJ4Ppkgh0oNc+E7Tvk LWqwtIsGea4WDwB3DiNxhr1FoKss1LROoCQddIG25K/ZN6UVXVcklnrlZWk11yTgk/C/ jhjM4CvnOYht0S1JjIvV589IVjsutij2zD7jCh3J1DU8Si40rFDSUFZlQAOsVq9VEec5 PseG7CJ8vdPCozWO/dMgVwAwk+rI6umkom9C3ujlUCXIcG0U8OTwDuL1BsN7FSU/NpNI Myaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/T4H2MiD0QBM8tig6ImJk3HvLU2caAc+kKCOLA74nf0=; b=niz0oF80cVFcfb+QFL2sKdvH7mSjNmI8mTSUWJ5EL5z/GF6J9Sz8KgsaMRHfZX8cxI fwvXlBHH9D9lUAk1DzXK1mMk9NVPM3gSbFWs7NiIs7RncIiWPOp+AuKZTvLEfoq/9c3p 5BXcvXBy27Z4Ipt5vg4dioLUQHPlEksBLS74ASU1G/E2kXaJ/UgaZgpgtCULjWEG9UqH fdoKKLE4sAUHRaR0Yqq6g0jfqw6UC5z/ioJKvknMr2ou/yi9pyXgU0yTIYY505WAQyO5 tcwodg5tweBTxcRqRD26HA96RHDLJHpKegxofSHKhw8+fReUCUaWrk5WTDDm/CSlP4dK ilzw== X-Gm-Message-State: AOAM532bZjN0p0+GRXRlTCJyI6yogjpJa4wVu+Z/9/HpsvGSf5CB+nhm vCGWVTZeHQUrEDF8ox3EfKLXbaDrGHDR7g== X-Google-Smtp-Source: ABdhPJxqc5EiLpM4bdhWtgoTT1ni8BSHsAZ3SR7bgijIxdWUSdRDnP6TxiR/jkpdSiSValG1ResIeQ== X-Received: by 2002:a17:902:7046:b029:d5:a5e3:4701 with SMTP id h6-20020a1709027046b02900d5a5e34701mr25468811plt.57.1604416043849; Tue, 03 Nov 2020 07:07:23 -0800 (PST) Received: from localhost.localdomain ([122.179.48.228]) by smtp.gmail.com with ESMTPSA id 15sm15936955pgs.52.2020.11.03.07.07.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 07:07:23 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, allison.henderson@oracle.com, Christoph Hellwig Subject: [PATCH V10 10/14] xfs: Introduce error injection to reduce maximum inode fork extent count Date: Tue, 3 Nov 2020 20:36:38 +0530 Message-Id: <20201103150642.2032284-11-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201103150642.2032284-1-chandanrlinux@gmail.com> References: <20201103150642.2032284-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org This commit adds XFS_ERRTAG_REDUCE_MAX_IEXTENTS error tag which enables userspace programs to test "Inode fork extent count overflow detection" by reducing maximum possible inode fork extent count to 10. Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Allison Henderson Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_errortag.h | 4 +++- fs/xfs/libxfs/xfs_inode_fork.c | 4 ++++ fs/xfs/xfs_error.c | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_errortag.h b/fs/xfs/libxfs/xfs_errortag.h index 53b305dea381..1c56fcceeea6 100644 --- a/fs/xfs/libxfs/xfs_errortag.h +++ b/fs/xfs/libxfs/xfs_errortag.h @@ -56,7 +56,8 @@ #define XFS_ERRTAG_FORCE_SUMMARY_RECALC 33 #define XFS_ERRTAG_IUNLINK_FALLBACK 34 #define XFS_ERRTAG_BUF_IOERROR 35 -#define XFS_ERRTAG_MAX 36 +#define XFS_ERRTAG_REDUCE_MAX_IEXTENTS 36 +#define XFS_ERRTAG_MAX 37 /* * Random factors for above tags, 1 means always, 2 means 1/2 time, etc. @@ -97,5 +98,6 @@ #define XFS_RANDOM_FORCE_SUMMARY_RECALC 1 #define XFS_RANDOM_IUNLINK_FALLBACK (XFS_RANDOM_DEFAULT/10) #define XFS_RANDOM_BUF_IOERROR XFS_RANDOM_DEFAULT +#define XFS_RANDOM_REDUCE_MAX_IEXTENTS 1 #endif /* __XFS_ERRORTAG_H_ */ diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c index 8d48716547e5..e080d7e07643 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.c +++ b/fs/xfs/libxfs/xfs_inode_fork.c @@ -24,6 +24,7 @@ #include "xfs_dir2_priv.h" #include "xfs_attr_leaf.h" #include "xfs_types.h" +#include "xfs_errortag.h" kmem_zone_t *xfs_ifork_zone; @@ -745,6 +746,9 @@ xfs_iext_count_may_overflow( max_exts = (whichfork == XFS_ATTR_FORK) ? MAXAEXTNUM : MAXEXTNUM; + if (XFS_TEST_ERROR(false, ip->i_mount, XFS_ERRTAG_REDUCE_MAX_IEXTENTS)) + max_exts = 10; + nr_exts = ifp->if_nextents + nr_to_add; if (nr_exts < ifp->if_nextents || nr_exts > max_exts) return -EFBIG; diff --git a/fs/xfs/xfs_error.c b/fs/xfs/xfs_error.c index 7f6e20899473..3780b118cc47 100644 --- a/fs/xfs/xfs_error.c +++ b/fs/xfs/xfs_error.c @@ -54,6 +54,7 @@ static unsigned int xfs_errortag_random_default[] = { XFS_RANDOM_FORCE_SUMMARY_RECALC, XFS_RANDOM_IUNLINK_FALLBACK, XFS_RANDOM_BUF_IOERROR, + XFS_RANDOM_REDUCE_MAX_IEXTENTS, }; struct xfs_errortag_attr { @@ -164,6 +165,7 @@ XFS_ERRORTAG_ATTR_RW(force_repair, XFS_ERRTAG_FORCE_SCRUB_REPAIR); XFS_ERRORTAG_ATTR_RW(bad_summary, XFS_ERRTAG_FORCE_SUMMARY_RECALC); XFS_ERRORTAG_ATTR_RW(iunlink_fallback, XFS_ERRTAG_IUNLINK_FALLBACK); XFS_ERRORTAG_ATTR_RW(buf_ioerror, XFS_ERRTAG_BUF_IOERROR); +XFS_ERRORTAG_ATTR_RW(reduce_max_iextents, XFS_ERRTAG_REDUCE_MAX_IEXTENTS); static struct attribute *xfs_errortag_attrs[] = { XFS_ERRORTAG_ATTR_LIST(noerror), @@ -202,6 +204,7 @@ static struct attribute *xfs_errortag_attrs[] = { XFS_ERRORTAG_ATTR_LIST(bad_summary), XFS_ERRORTAG_ATTR_LIST(iunlink_fallback), XFS_ERRORTAG_ATTR_LIST(buf_ioerror), + XFS_ERRORTAG_ATTR_LIST(reduce_max_iextents), NULL, }; From patchwork Tue Nov 3 15:06:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 11877901 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 2E0E1921 for ; Tue, 3 Nov 2020 15:07:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 06CE3223FD for ; Tue, 3 Nov 2020 15:07:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZbG5+ayK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728175AbgKCPHf (ORCPT ); Tue, 3 Nov 2020 10:07:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728164AbgKCPH1 (ORCPT ); Tue, 3 Nov 2020 10:07:27 -0500 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36EEBC0613D1 for ; Tue, 3 Nov 2020 07:07:27 -0800 (PST) Received: by mail-pg1-x542.google.com with SMTP id g12so13889756pgm.8 for ; Tue, 03 Nov 2020 07:07:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fYn4Dk1EXYBsRc4PsiEBtvGWQor3CttFr0ltlRTYZIQ=; b=ZbG5+ayKvNvQkxVWfCxyyYPevxHR5nJTAZzGISu/jrMeQbC9jb6Nhl0lHynoF6UuxO 2J/Dvew7JnR53FT0UzSLveLmahHTYavLvn7aUyjt4RBKkDF8nM8WWfcY65SUYhnvQ5PB VWUyKhzYqUyjm3hD8XbURomMJSC7u7P/2rjH7XPE/wOoquxnKlneDl7WvIZBexnnIglF Ek+RvoPiIMBncECmX8bz4JwV5eb3UfMfLOGvSIdrEpOIQJJuohn0lLgDvqDOtK90S/ic NHckuG0Vg659C54Axborsbu/GoC6lFHdTsSzVXatKAu8lOqDrzeDv6NUt0DlovQJYosd IRvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fYn4Dk1EXYBsRc4PsiEBtvGWQor3CttFr0ltlRTYZIQ=; b=OrfvLv6xd0XPAGt9nnwFKxmzyfSWyKsl493kytkmTmkyVFqrwEC6UJwQRNP5NN81zV POZQB9oAvynFnIwYQVx9wi6pkOsuwM+SLPnigl1vRm/QBfYEe0QHLqat8f8BPLuUdTNM FwJIl1kqm8lKOD4l8QLNDCjOQd2c+rRbhGq3FHE5Acg5EZjEmzTP0FdUrMe4v2Nd2mIi asmKuv+8rS8yH3JTMYj47T72Kh9AUcq52AzN/Lwh2gRzflgfbGYHxTkR0zm5Wn2Cr0Rd sd+UncCEZz29n6/SyS5OV5u986QkS9EF4BnB6Rz7FbrhOwlxlG9kP7T3Od7l4p3tysZ2 Phuw== X-Gm-Message-State: AOAM531U1Y+NIDjGbK93StWEAJWY4iU0L60g1OTTr308yx9gSCYNjZZE fRYXBB5o/x/lDuIvrbkG4NlyZ7tQJLyvsw== X-Google-Smtp-Source: ABdhPJzdV7CAk6xV3edDHUPCLWtT/k0UmbVmEaASMsPtz6l1krHcnp+CGY/CGDfJT7Zcv7lgGree2A== X-Received: by 2002:a17:90a:1b8a:: with SMTP id w10mr177425pjc.145.1604416046554; Tue, 03 Nov 2020 07:07:26 -0800 (PST) Received: from localhost.localdomain ([122.179.48.228]) by smtp.gmail.com with ESMTPSA id 15sm15936955pgs.52.2020.11.03.07.07.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 07:07:25 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, allison.henderson@oracle.com Subject: [PATCH V10 11/14] xfs: Remove duplicate assert statement in xfs_bmap_btalloc() Date: Tue, 3 Nov 2020 20:36:39 +0530 Message-Id: <20201103150642.2032284-12-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201103150642.2032284-1-chandanrlinux@gmail.com> References: <20201103150642.2032284-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org The check for verifying if the allocated extent is from an AG whose index is greater than or equal to that of tp->t_firstblock is already done a couple of statements earlier in the same function. Hence this commit removes the redundant assert statement. Reviewed-by: Allison Henderson Reviewed-by: Darrick J. Wong Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_bmap.c | 1 - 1 file changed, 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 505358839d2f..64c4d0e384a5 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -3699,7 +3699,6 @@ xfs_bmap_btalloc( ap->blkno = args.fsbno; if (ap->tp->t_firstblock == NULLFSBLOCK) ap->tp->t_firstblock = args.fsbno; - ASSERT(nullfb || fb_agno <= args.agno); ap->length = args.len; /* * If the extent size hint is active, we tried to round the From patchwork Tue Nov 3 15:06: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: 11877903 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 6AD9D1130 for ; Tue, 3 Nov 2020 15:07:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 46B2E2242C for ; Tue, 3 Nov 2020 15:07:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="T+4dYPYe" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728198AbgKCPHf (ORCPT ); Tue, 3 Nov 2020 10:07:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728175AbgKCPHa (ORCPT ); Tue, 3 Nov 2020 10:07:30 -0500 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AC55C0617A6 for ; Tue, 3 Nov 2020 07:07:30 -0800 (PST) Received: by mail-pg1-x544.google.com with SMTP id h6so13896761pgk.4 for ; Tue, 03 Nov 2020 07:07:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6Px3JAi+COBc1S2ugxxKUucXslM+2riWbmlNnMuhuXM=; b=T+4dYPYeAFAX/P/M6kuT3f2iqHR+TkuEVn00gW9wt5Zy7lZGLoXzyfObYBMnNxT/Wb SGzu6iyWweur6ZIyoTmYgRweX6FQP4IqW4LatOBHjBL74UujDNTznxoU+qw9dsRrB58K QVnL/w7spbxX5Of8GsocPf0Kq0L0G8OlPCaa7KIbezVVzYTC22zBhXw3YhthFhZgxwPM 0VHVShcc//DGA7LVCKcbkmly/FMBEb8/OL+y4AglNOuxfTmUDOgfOQBC9InA70Vdosmo xtI1H7IpXwsJ0U79x4Yq9KD9lMSdy9EUOmU/qODJHkZXgSkEbCBcRZ6Z1AqrNTiFZjye +Hlw== 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=6Px3JAi+COBc1S2ugxxKUucXslM+2riWbmlNnMuhuXM=; b=VWJlf5yM4GV7Xzs/ZWUvOt0Dptl47S2KQSXTkebK4WsNVtwlUNxlKmH0jKuUc2tyr0 nqFgYzZFW5t+rh5ATTA+D3iMbzENeblW85VlHAWsMSo/MfAPDsMKNpPKRLUxkJMNgxhr uG7prz5+9GaZHN3u+vx0Ih+Xv/BW0rcLA3xehM8eVxwDSm5fbwg9KW5GyKtBaNTzbGXB WXpExT/yyntwPNUlnCam8ghW2exjKd1Zp79buARqTFbfeTBwPm9Uk+dvX+8piXo8ou7j dBtg9mbox6e2euSHO4eHRef8mqEzePPBbQoe71451zeOBrFKGlBwQSLfWLG5jJDMtMKV Rp5g== X-Gm-Message-State: AOAM530V8Z1KU067LKBy7w7r5WYMou7eHjnZQkWnrdl62+hSu00syCIl SFSvrlANqmgF+JUq8wMcOln6UFShYV5yig== X-Google-Smtp-Source: ABdhPJw8qLTWqztsKAQXqPkZeLZ8cJvkmxQDbkPkwCzyP+ZW3CBD0bSCX1syJq6mY9BF4A7WeDqshA== X-Received: by 2002:a17:90a:cb93:: with SMTP id a19mr182107pju.99.1604416049373; Tue, 03 Nov 2020 07:07:29 -0800 (PST) Received: from localhost.localdomain ([122.179.48.228]) by smtp.gmail.com with ESMTPSA id 15sm15936955pgs.52.2020.11.03.07.07.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 07:07:28 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, allison.henderson@oracle.com Subject: [PATCH V10 12/14] xfs: Compute bmap extent alignments in a separate function Date: Tue, 3 Nov 2020 20:36:40 +0530 Message-Id: <20201103150642.2032284-13-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201103150642.2032284-1-chandanrlinux@gmail.com> References: <20201103150642.2032284-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org This commit moves over the code which computes stripe alignment and extent size hint alignment into a separate function. Apart from xfs_bmap_btalloc(), the new function will be used by another function introduced in a future commit. Signed-off-by: Chandan Babu R Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_bmap.c | 89 +++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 37 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 64c4d0e384a5..5032539d5e85 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -3463,13 +3463,59 @@ xfs_bmap_btalloc_accounting( args->len); } +static int +xfs_bmap_compute_alignments( + struct xfs_bmalloca *ap, + struct xfs_alloc_arg *args) +{ + struct xfs_mount *mp = args->mp; + xfs_extlen_t align = 0; /* minimum allocation alignment */ + int stripe_align = 0; + int error; + + /* stripe alignment for allocation is determined by mount parameters */ + if (mp->m_swidth && (mp->m_flags & XFS_MOUNT_SWALLOC)) + stripe_align = mp->m_swidth; + else if (mp->m_dalign) + stripe_align = mp->m_dalign; + + if (ap->flags & XFS_BMAPI_COWFORK) + align = xfs_get_cowextsz_hint(ap->ip); + else if (ap->datatype & XFS_ALLOC_USERDATA) + align = xfs_get_extsz_hint(ap->ip); + if (align) { + error = xfs_bmap_extsize_align(mp, &ap->got, &ap->prev, + align, 0, ap->eof, 0, ap->conv, + &ap->offset, &ap->length); + ASSERT(!error); + ASSERT(ap->length); + } + + /* apply extent size hints if obtained earlier */ + if (align) { + args->prod = align; + div_u64_rem(ap->offset, args->prod, &args->mod); + if (args->mod) + args->mod = args->prod - args->mod; + } else if (mp->m_sb.sb_blocksize >= PAGE_SIZE) { + args->prod = 1; + args->mod = 0; + } else { + args->prod = PAGE_SIZE >> mp->m_sb.sb_blocklog; + div_u64_rem(ap->offset, args->prod, &args->mod); + if (args->mod) + args->mod = args->prod - args->mod; + } + + return stripe_align; +} + STATIC int xfs_bmap_btalloc( struct xfs_bmalloca *ap) /* bmap alloc argument struct */ { xfs_mount_t *mp; /* mount point structure */ xfs_alloctype_t atype = 0; /* type for allocation routines */ - xfs_extlen_t align = 0; /* minimum allocation alignment */ xfs_agnumber_t fb_agno; /* ag number of ap->firstblock */ xfs_agnumber_t ag; xfs_alloc_arg_t args; @@ -3489,25 +3535,11 @@ xfs_bmap_btalloc( mp = ap->ip->i_mount; - /* stripe alignment for allocation is determined by mount parameters */ - stripe_align = 0; - if (mp->m_swidth && (mp->m_flags & XFS_MOUNT_SWALLOC)) - stripe_align = mp->m_swidth; - else if (mp->m_dalign) - stripe_align = mp->m_dalign; - - if (ap->flags & XFS_BMAPI_COWFORK) - align = xfs_get_cowextsz_hint(ap->ip); - else if (ap->datatype & XFS_ALLOC_USERDATA) - align = xfs_get_extsz_hint(ap->ip); - if (align) { - error = xfs_bmap_extsize_align(mp, &ap->got, &ap->prev, - align, 0, ap->eof, 0, ap->conv, - &ap->offset, &ap->length); - ASSERT(!error); - ASSERT(ap->length); - } + memset(&args, 0, sizeof(args)); + args.tp = ap->tp; + args.mp = mp; + stripe_align = xfs_bmap_compute_alignments(ap, &args); nullfb = ap->tp->t_firstblock == NULLFSBLOCK; fb_agno = nullfb ? NULLAGNUMBER : XFS_FSB_TO_AGNO(mp, @@ -3538,9 +3570,6 @@ xfs_bmap_btalloc( * Normal allocation, done through xfs_alloc_vextent. */ tryagain = isaligned = 0; - memset(&args, 0, sizeof(args)); - args.tp = ap->tp; - args.mp = mp; args.fsbno = ap->blkno; args.oinfo = XFS_RMAP_OINFO_SKIP_UPDATE; @@ -3571,21 +3600,7 @@ xfs_bmap_btalloc( args.total = ap->total; args.minlen = ap->minlen; } - /* apply extent size hints if obtained earlier */ - if (align) { - args.prod = align; - div_u64_rem(ap->offset, args.prod, &args.mod); - if (args.mod) - args.mod = args.prod - args.mod; - } else if (mp->m_sb.sb_blocksize >= PAGE_SIZE) { - args.prod = 1; - args.mod = 0; - } else { - args.prod = PAGE_SIZE >> mp->m_sb.sb_blocklog; - div_u64_rem(ap->offset, args.prod, &args.mod); - if (args.mod) - args.mod = args.prod - args.mod; - } + /* * If we are not low on available data blocks, and the underlying * logical volume manager is a stripe, and the file offset is zero then From patchwork Tue Nov 3 15:06: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: 11877909 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 D2BB0921 for ; Tue, 3 Nov 2020 15:07:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A9E65223EA for ; Tue, 3 Nov 2020 15:07:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="smn2nRI4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728218AbgKCPHf (ORCPT ); Tue, 3 Nov 2020 10:07:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728217AbgKCPHd (ORCPT ); Tue, 3 Nov 2020 10:07:33 -0500 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE6E6C0613D1 for ; Tue, 3 Nov 2020 07:07:32 -0800 (PST) Received: by mail-pf1-x441.google.com with SMTP id 72so7735982pfv.7 for ; Tue, 03 Nov 2020 07:07:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mzo4XKFqwetL4wgqWPphqhx1Obl5kc6g2AJMDkW2Wts=; b=smn2nRI4aLt6vLXvPFIP57Lau6v/MzGK96efkq2CZxlcPiFpQpHVuGxqqBPIZUi7zm h+hOY5GCOORwgr27WqVww1gdvOjCQqx1yyeUUurQW4FKQ5g8hxSyLmxQfdbVdl+4uDST /B+HxGM/+EIDnhX9r+T/TOZULbsl0nTJ/lVZCvxuR+jWUuJ+LqGaOlRJKN+nDdFI0uco ap7Z8szJFUQQIu+Jzi3cvs5HD+fXJflo+ucarFXy+lMQM0cvztinqohPdZ33z5a7oNSr 7JXfTZnce4EC4M7YwCkOWiKs8JwxeYDf/DzpO4dzI+/FgBKjsqh7wSJFnKtYQuP/uMFF eUqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mzo4XKFqwetL4wgqWPphqhx1Obl5kc6g2AJMDkW2Wts=; b=oAzpJUzh+oh8zCGKAKRZerVHrzVpZ/xGdAXpeahvrmkbCCz55VDH742U8lmnOJ4ydc /gDhUUpY+Ni3BWcAIZgsGBvj2NzWF67CdeBg9bnYdO9njvi3ibf06AwRXEn3z38pa4vx gmhEjTgPDDjOb3TZw0Yy6oBYpNGAWny145g0ue4qnkNFfr24u8CzrtIqRat+5LGSvLuQ MmxXPflTeSKm31bChLpZerc6vYkTuxwqJjx/C9D+0TgHeRknJU8oeOBz/ZtKow1QRe3j QmzO71gU7S2Am8KlxnUlFNRIb3zZsTFDpZr3UCq6EiIETpxwL7lPKwVY037726oX/MF0 WaRg== X-Gm-Message-State: AOAM532YJ9G3kuVjnmhtOAr9ctzf6ISDPhMzvyzBsUS4jhd9F7Aivopm BNVB1vcSt/jzeAOAs4fcAGPVtbeMLGim+w== X-Google-Smtp-Source: ABdhPJzc1HcyHkCs4OIwwUOz9EN5A0x9QFWY5LEio+FGiflTsqMBsMK7YmPeh3Tg+18GU9TpLmciHA== X-Received: by 2002:a17:90a:4684:: with SMTP id z4mr190654pjf.97.1604416052182; Tue, 03 Nov 2020 07:07:32 -0800 (PST) Received: from localhost.localdomain ([122.179.48.228]) by smtp.gmail.com with ESMTPSA id 15sm15936955pgs.52.2020.11.03.07.07.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 07:07:31 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, allison.henderson@oracle.com Subject: [PATCH V10 13/14] xfs: Process allocated extent in a separate function Date: Tue, 3 Nov 2020 20:36:41 +0530 Message-Id: <20201103150642.2032284-14-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201103150642.2032284-1-chandanrlinux@gmail.com> References: <20201103150642.2032284-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org This commit moves over the code in xfs_bmap_btalloc() which is responsible for processing an allocated extent to a new function. Apart from xfs_bmap_btalloc(), the new function will be invoked by another function introduced in a future commit. Reviewed-by: Allison Henderson Reviewed-by: Darrick J. Wong Signed-off-by: Chandan Babu R --- fs/xfs/libxfs/xfs_bmap.c | 74 ++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 29 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 5032539d5e85..f6cd33684571 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -3510,6 +3510,48 @@ xfs_bmap_compute_alignments( return stripe_align; } +static void +xfs_bmap_process_allocated_extent( + struct xfs_bmalloca *ap, + struct xfs_alloc_arg *args, + xfs_fileoff_t orig_offset, + xfs_extlen_t orig_length) +{ + int nullfb; + + nullfb = ap->tp->t_firstblock == NULLFSBLOCK; + + /* + * check the allocation happened at the same or higher AG than + * the first block that was allocated. + */ + ASSERT(nullfb || + XFS_FSB_TO_AGNO(args->mp, ap->tp->t_firstblock) <= + XFS_FSB_TO_AGNO(args->mp, args->fsbno)); + + ap->blkno = args->fsbno; + if (nullfb) + ap->tp->t_firstblock = args->fsbno; + ap->length = args->len; + /* + * If the extent size hint is active, we tried to round the + * caller's allocation request offset down to extsz and the + * length up to another extsz boundary. If we found a free + * extent we mapped it in starting at this new offset. If the + * newly mapped space isn't long enough to cover any of the + * range of offsets that was originally requested, move the + * mapping up so that we can fill as much of the caller's + * original request as possible. Free space is apparently + * very fragmented so we're unlikely to be able to satisfy the + * hints anyway. + */ + if (ap->length <= orig_length) + ap->offset = orig_offset; + else if (ap->offset + ap->length < orig_offset + orig_length) + ap->offset = orig_offset + orig_length - ap->length; + xfs_bmap_btalloc_accounting(ap, args); +} + STATIC int xfs_bmap_btalloc( struct xfs_bmalloca *ap) /* bmap alloc argument struct */ @@ -3702,36 +3744,10 @@ xfs_bmap_btalloc( return error; ap->tp->t_flags |= XFS_TRANS_LOWMODE; } + if (args.fsbno != NULLFSBLOCK) { - /* - * check the allocation happened at the same or higher AG than - * the first block that was allocated. - */ - ASSERT(ap->tp->t_firstblock == NULLFSBLOCK || - XFS_FSB_TO_AGNO(mp, ap->tp->t_firstblock) <= - XFS_FSB_TO_AGNO(mp, args.fsbno)); - - ap->blkno = args.fsbno; - if (ap->tp->t_firstblock == NULLFSBLOCK) - ap->tp->t_firstblock = args.fsbno; - ap->length = args.len; - /* - * If the extent size hint is active, we tried to round the - * caller's allocation request offset down to extsz and the - * length up to another extsz boundary. If we found a free - * extent we mapped it in starting at this new offset. If the - * newly mapped space isn't long enough to cover any of the - * range of offsets that was originally requested, move the - * mapping up so that we can fill as much of the caller's - * original request as possible. Free space is apparently - * very fragmented so we're unlikely to be able to satisfy the - * hints anyway. - */ - if (ap->length <= orig_length) - ap->offset = orig_offset; - else if (ap->offset + ap->length < orig_offset + orig_length) - ap->offset = orig_offset + orig_length - ap->length; - xfs_bmap_btalloc_accounting(ap, &args); + xfs_bmap_process_allocated_extent(ap, &args, orig_offset, + orig_length); } else { ap->blkno = NULLFSBLOCK; ap->length = 0; From patchwork Tue Nov 3 15:06: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: 11877907 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 74B3F6A2 for ; Tue, 3 Nov 2020 15:07:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 44A86223EA for ; Tue, 3 Nov 2020 15:07:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="U2WHU8yM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728246AbgKCPHh (ORCPT ); Tue, 3 Nov 2020 10:07:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728130AbgKCPHg (ORCPT ); Tue, 3 Nov 2020 10:07:36 -0500 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 129F8C0613D1 for ; Tue, 3 Nov 2020 07:07:36 -0800 (PST) Received: by mail-pf1-x441.google.com with SMTP id c20so14429065pfr.8 for ; Tue, 03 Nov 2020 07:07:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kUp2tsAW2OySYVVIjctiIzMx68obd9OOBKUKjhSYFmE=; b=U2WHU8yMpLLB+fIKxYXbHMzKR/GUWQ+Oe37BFwBwtjGNemr2h0YtXMxsvn11iqkLDP PCX3n5Wiu2UM24k1FR+aItrsw5CNyeVyUsmMIcBNzPuI7WBZirU8TOOXczk02a6bmt34 uPRFUEP3JR2CY3vOpWEnmt+lByK86VaIYQXRW+IOAU/Od00tk7TUu3Sn5yhyAvaHdk2P rg48expggxpMDzb1jlYHKjCXqmIYzbWUZRSdPtxCuA9hJHlNVdd6LBD8fAGLCNSeS8df 2G9dWeWMrrkfqeTPmEq69YCKWED7QP1t8pF4xJUT7qKsjBf/T+MwioGDq6BgEIurLMQy jYWQ== 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=kUp2tsAW2OySYVVIjctiIzMx68obd9OOBKUKjhSYFmE=; b=p4YP0lty0jAxydhwJ6GkTRCWNd8lkwVejCHRRnnhcXL31u/rq+HgYUYDqse3jVkU84 V9Do6qMZnlZ7qI+ME6T49yIJyjzzFgU/Rz/7IWI3dWaL8bjLu9S+gM9K9TfZhWj5KvOD wfKmJke+67taY6rvanX9qdcXxNz7Ry94uTjjmQj3dOMPlJTge82A50UeWkquRZsDxleT cl6lDmBx4rr9QE90oT11MPnAQAdOzDt8ZtUHMGDn/4QiZ96febojeqMTmJRcVqQ+kH9v mZ9A9gWj1tsDUpspwlXVw7vIFrw97nQHmcTAuHsCxZdLFv/9RH9KqNeP7r+RgcwSKKUe Pxjw== X-Gm-Message-State: AOAM5324REKNWJ4SSMFLzAPwzFieHodx7RkP8ULMbENQdloZIqruHdiV fNClHUHMB4y7WfS7fVy3MiPj6qpyxntYxg== X-Google-Smtp-Source: ABdhPJyORu+CBglgvZAVZbty3ckQxRopnHHG9eeBiHSxEv+1ng0ykqZnF+tKbJgrlLNjj7mMEsNsdg== X-Received: by 2002:a17:90a:d18c:: with SMTP id fu12mr202183pjb.7.1604416055181; Tue, 03 Nov 2020 07:07:35 -0800 (PST) Received: from localhost.localdomain ([122.179.48.228]) by smtp.gmail.com with ESMTPSA id 15sm15936955pgs.52.2020.11.03.07.07.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 07:07:34 -0800 (PST) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , darrick.wong@oracle.com, david@fromorbit.com, hch@infradead.org, allison.henderson@oracle.com Subject: [PATCH V10 14/14] xfs: Introduce error injection to allocate only minlen size extents for files Date: Tue, 3 Nov 2020 20:36:42 +0530 Message-Id: <20201103150642.2032284-15-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201103150642.2032284-1-chandanrlinux@gmail.com> References: <20201103150642.2032284-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org This commit adds XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT error tag which helps userspace test programs to get xfs_bmap_btalloc() to always allocate minlen sized extents. This is required for test programs which need a guarantee that minlen extents allocated for a file do not get merged with their existing neighbours in the inode's BMBT. "Inode fork extent overflow check" for Directories, Xattrs and extension of realtime inodes need this since the file offset at which the extents are being allocated cannot be explicitly controlled from userspace. One way to use this error tag is to, 1. Consume all of the free space by sequentially writing to a file. 2. Punch alternate blocks of the file. This causes CNTBT to contain sufficient number of one block sized extent records. 3. Inject XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT error tag. After step 3, xfs_bmap_btalloc() will issue space allocation requests for minlen sized extents only. ENOSPC error code is returned to userspace when there aren't any "one block sized" extents left in any of the AGs. Signed-off-by: Chandan Babu R Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_alloc.c | 50 ++++++++++++++ fs/xfs/libxfs/xfs_alloc.h | 3 + fs/xfs/libxfs/xfs_bmap.c | 124 ++++++++++++++++++++++++++++------- fs/xfs/libxfs/xfs_errortag.h | 4 +- fs/xfs/xfs_error.c | 3 + 5 files changed, 159 insertions(+), 25 deletions(-) diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c index 852b536551b5..a7c4eb1d71d5 100644 --- a/fs/xfs/libxfs/xfs_alloc.c +++ b/fs/xfs/libxfs/xfs_alloc.c @@ -2473,6 +2473,47 @@ xfs_defer_agfl_block( xfs_defer_add(tp, XFS_DEFER_OPS_TYPE_AGFL_FREE, &new->xefi_list); } +#ifdef DEBUG +/* + * Check if an AGF has a free extent record whose length is equal to + * args->minlen. + */ +STATIC int +xfs_exact_minlen_extent_available( + struct xfs_alloc_arg *args, + struct xfs_buf *agbp, + int *stat) +{ + struct xfs_btree_cur *cnt_cur; + xfs_agblock_t fbno; + xfs_extlen_t flen; + int error = 0; + + cnt_cur = xfs_allocbt_init_cursor(args->mp, args->tp, agbp, + args->agno, XFS_BTNUM_CNT); + error = xfs_alloc_lookup_ge(cnt_cur, 0, args->minlen, stat); + if (error) + goto out; + + if (*stat == 0) { + error = -EFSCORRUPTED; + goto out; + } + + error = xfs_alloc_get_rec(cnt_cur, &fbno, &flen, stat); + if (error) + goto out; + + if (*stat == 1 && flen != args->minlen) + *stat = 0; + +out: + xfs_btree_del_cursor(cnt_cur, error); + + return error; +} +#endif + /* * Decide whether to use this allocation group for this allocation. * If so, fix up the btree freelist's size. @@ -2544,6 +2585,15 @@ xfs_alloc_fix_freelist( if (!xfs_alloc_space_available(args, need, flags)) goto out_agbp_relse; +#ifdef DEBUG + if (args->alloc_minlen_only) { + int stat; + + error = xfs_exact_minlen_extent_available(args, agbp, &stat); + if (error || !stat) + goto out_agbp_relse; + } +#endif /* * Make the freelist shorter if it's too long. * diff --git a/fs/xfs/libxfs/xfs_alloc.h b/fs/xfs/libxfs/xfs_alloc.h index 6c22b12176b8..a4427c5775c2 100644 --- a/fs/xfs/libxfs/xfs_alloc.h +++ b/fs/xfs/libxfs/xfs_alloc.h @@ -75,6 +75,9 @@ typedef struct xfs_alloc_arg { char wasfromfl; /* set if allocation is from freelist */ struct xfs_owner_info oinfo; /* owner of blocks being allocated */ enum xfs_ag_resv_type resv; /* block reservation to use */ +#ifdef DEBUG + bool alloc_minlen_only; /* allocate exact minlen extent */ +#endif } xfs_alloc_arg_t; /* diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index f6cd33684571..4717c5f1808e 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -3552,35 +3552,102 @@ xfs_bmap_process_allocated_extent( xfs_bmap_btalloc_accounting(ap, args); } +#ifdef DEBUG +static int +xfs_bmap_exact_minlen_extent_alloc( + struct xfs_bmalloca *ap) +{ + struct xfs_mount *mp = ap->ip->i_mount; + struct xfs_alloc_arg args = { .tp = ap->tp, .mp = mp }; + xfs_fileoff_t orig_offset; + xfs_extlen_t orig_length; + int error; + + ASSERT(ap->length); + + if (ap->minlen != 1) { + ap->blkno = NULLFSBLOCK; + ap->length = 0; + return 0; + } + + orig_offset = ap->offset; + orig_length = ap->length; + + args.alloc_minlen_only = 1; + + xfs_bmap_compute_alignments(ap, &args); + + if (ap->tp->t_firstblock == NULLFSBLOCK) { + /* + * Unlike the longest extent available in an AG, we don't track + * the length of an AG's shortest extent. + * XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT is a debug only knob and + * hence we can afford to start traversing from the 0th AG since + * we need not be concerned about a drop in performance in + * "debug only" code paths. + */ + ap->blkno = XFS_AGB_TO_FSB(mp, 0, 0); + } else { + ap->blkno = ap->tp->t_firstblock; + } + + args.fsbno = ap->blkno; + args.oinfo = XFS_RMAP_OINFO_SKIP_UPDATE; + args.type = XFS_ALLOCTYPE_FIRST_AG; + args.total = args.minlen = args.maxlen = ap->minlen; + + args.alignment = 1; + args.minalignslop = 0; + + args.minleft = ap->minleft; + args.wasdel = ap->wasdel; + args.resv = XFS_AG_RESV_NONE; + args.datatype = ap->datatype; + + error = xfs_alloc_vextent(&args); + if (error) + return error; + + if (args.fsbno != NULLFSBLOCK) { + xfs_bmap_process_allocated_extent(ap, &args, orig_offset, + orig_length); + } else { + ap->blkno = NULLFSBLOCK; + ap->length = 0; + } + + return 0; +} +#else + +#define xfs_bmap_exact_minlen_extent_alloc(bma) (-EFSCORRUPTED) + +#endif + STATIC int xfs_bmap_btalloc( struct xfs_bmalloca *ap) /* bmap alloc argument struct */ { - xfs_mount_t *mp; /* mount point structure */ - xfs_alloctype_t atype = 0; /* type for allocation routines */ - xfs_agnumber_t fb_agno; /* ag number of ap->firstblock */ - xfs_agnumber_t ag; - xfs_alloc_arg_t args; - xfs_fileoff_t orig_offset; - xfs_extlen_t orig_length; - xfs_extlen_t blen; - xfs_extlen_t nextminlen = 0; - int nullfb; /* true if ap->firstblock isn't set */ - int isaligned; - int tryagain; - int error; - int stripe_align; + struct xfs_mount *mp = ap->ip->i_mount; /* mount point structure */ + struct xfs_alloc_arg args = { .tp = ap->tp, .mp = mp }; + xfs_alloctype_t atype = 0; /* type for allocation routines */ + xfs_agnumber_t fb_agno; /* ag number of ap->firstblock */ + xfs_agnumber_t ag; + xfs_fileoff_t orig_offset; + xfs_extlen_t orig_length; + xfs_extlen_t blen; + xfs_extlen_t nextminlen = 0; + int nullfb; /* true if ap->firstblock isn't set */ + int isaligned; + int tryagain; + int error; + int stripe_align; ASSERT(ap->length); orig_offset = ap->offset; orig_length = ap->length; - mp = ap->ip->i_mount; - - memset(&args, 0, sizeof(args)); - args.tp = ap->tp; - args.mp = mp; - stripe_align = xfs_bmap_compute_alignments(ap, &args); nullfb = ap->tp->t_firstblock == NULLFSBLOCK; @@ -4113,7 +4180,11 @@ xfs_bmap_alloc_userdata( return xfs_bmap_rtalloc(bma); } - return xfs_bmap_btalloc(bma); + if (unlikely(XFS_TEST_ERROR(false, mp, + XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT))) + return xfs_bmap_exact_minlen_extent_alloc(bma); + else + return xfs_bmap_btalloc(bma); } static int @@ -4149,10 +4220,15 @@ xfs_bmapi_allocate( else bma->minlen = 1; - if (bma->flags & XFS_BMAPI_METADATA) - error = xfs_bmap_btalloc(bma); - else + if (bma->flags & XFS_BMAPI_METADATA) { + if (unlikely(XFS_TEST_ERROR(false, mp, + XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT))) + error = xfs_bmap_exact_minlen_extent_alloc(bma); + else + error = xfs_bmap_btalloc(bma); + } else { error = xfs_bmap_alloc_userdata(bma); + } if (error || bma->blkno == NULLFSBLOCK) return error; diff --git a/fs/xfs/libxfs/xfs_errortag.h b/fs/xfs/libxfs/xfs_errortag.h index 1c56fcceeea6..6ca9084b6934 100644 --- a/fs/xfs/libxfs/xfs_errortag.h +++ b/fs/xfs/libxfs/xfs_errortag.h @@ -57,7 +57,8 @@ #define XFS_ERRTAG_IUNLINK_FALLBACK 34 #define XFS_ERRTAG_BUF_IOERROR 35 #define XFS_ERRTAG_REDUCE_MAX_IEXTENTS 36 -#define XFS_ERRTAG_MAX 37 +#define XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT 37 +#define XFS_ERRTAG_MAX 38 /* * Random factors for above tags, 1 means always, 2 means 1/2 time, etc. @@ -99,5 +100,6 @@ #define XFS_RANDOM_IUNLINK_FALLBACK (XFS_RANDOM_DEFAULT/10) #define XFS_RANDOM_BUF_IOERROR XFS_RANDOM_DEFAULT #define XFS_RANDOM_REDUCE_MAX_IEXTENTS 1 +#define XFS_RANDOM_BMAP_ALLOC_MINLEN_EXTENT 1 #endif /* __XFS_ERRORTAG_H_ */ diff --git a/fs/xfs/xfs_error.c b/fs/xfs/xfs_error.c index 3780b118cc47..185b4915b7bf 100644 --- a/fs/xfs/xfs_error.c +++ b/fs/xfs/xfs_error.c @@ -55,6 +55,7 @@ static unsigned int xfs_errortag_random_default[] = { XFS_RANDOM_IUNLINK_FALLBACK, XFS_RANDOM_BUF_IOERROR, XFS_RANDOM_REDUCE_MAX_IEXTENTS, + XFS_RANDOM_BMAP_ALLOC_MINLEN_EXTENT, }; struct xfs_errortag_attr { @@ -166,6 +167,7 @@ XFS_ERRORTAG_ATTR_RW(bad_summary, XFS_ERRTAG_FORCE_SUMMARY_RECALC); XFS_ERRORTAG_ATTR_RW(iunlink_fallback, XFS_ERRTAG_IUNLINK_FALLBACK); XFS_ERRORTAG_ATTR_RW(buf_ioerror, XFS_ERRTAG_BUF_IOERROR); XFS_ERRORTAG_ATTR_RW(reduce_max_iextents, XFS_ERRTAG_REDUCE_MAX_IEXTENTS); +XFS_ERRORTAG_ATTR_RW(bmap_alloc_minlen_extent, XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT); static struct attribute *xfs_errortag_attrs[] = { XFS_ERRORTAG_ATTR_LIST(noerror), @@ -205,6 +207,7 @@ static struct attribute *xfs_errortag_attrs[] = { XFS_ERRORTAG_ATTR_LIST(iunlink_fallback), XFS_ERRORTAG_ATTR_LIST(buf_ioerror), XFS_ERRORTAG_ATTR_LIST(reduce_max_iextents), + XFS_ERRORTAG_ATTR_LIST(bmap_alloc_minlen_extent), NULL, };