From patchwork Tue Jan 7 19:42:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11321673 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 207FC109A for ; Tue, 7 Jan 2020 19:42:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F24F9214D8 for ; Tue, 7 Jan 2020 19:42:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20150623.gappssmtp.com header.i=@toxicpanda-com.20150623.gappssmtp.com header.b="SX/lKe+J" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728485AbgAGTmn (ORCPT ); Tue, 7 Jan 2020 14:42:43 -0500 Received: from mail-qt1-f194.google.com ([209.85.160.194]:40564 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728358AbgAGTmn (ORCPT ); Tue, 7 Jan 2020 14:42:43 -0500 Received: by mail-qt1-f194.google.com with SMTP id e6so748503qtq.7 for ; Tue, 07 Jan 2020 11:42:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ieUAFwhIKx4DpFgDaDO4d7DYtH2i4i+TfaHpqbulT6s=; b=SX/lKe+JYN+41P66C7lddUJSYYHRW2Z9Ma2+gGT4GwChhumOjZrz9sdPtLXApehbgP T83do7elNN3V05xwFV/Bxf6zsj7UxLlD12KW4c/7QiyVYPSMpWn+knHBIPBECSOuiztT YHjzUfRtC2mNCk1PGNa/gUqpXpGDs7EbTJz0wId7fkEr2MKTBWvlKbi3C3Rkw2Z+wLws qKIndl/Fwr9X5ZCu02lM736wJkEPrk5THMoTvNt5/QiH3is8uWePLGq5sOQeS4BhfVH0 UC50HVcasGrBFhHiOUDPWlGDva1Vr6XBIpZyjvcM/SFVul6yBDi5iAM/TJVWGXH3XoxI XJlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ieUAFwhIKx4DpFgDaDO4d7DYtH2i4i+TfaHpqbulT6s=; b=NLcgAtLcH/726ermYWhFj8IBwYqUKYHZv/kgttrHLo3ZYo7Q0z6Yt1BDArDT7Vwwgi KfCzwn3w4tRgDwUoVRyzNuAuZ1VSXOnHiQWwKi8/JXq0NOZW4kiRpFIeaHAaIhB1ZLSo ObN4wP6VgvQ6gRKnQY1DN0eBSxnlCgpuJ3rH9YIxJh9lEF0kR3UCYgFODcCJibxFBaLD 4LMamLv1wEfbcEMYvXHIzDBoWUEWBY3WdWuQZISc0mN6f6rWKkZGMwpGvfSQqLCTV4sR dV82rddN+y+jg2xd5opzgTB1JXFTrivN5kWOITFuLreW9HpJrmawr57lCi9Dasg/KLDA m66A== X-Gm-Message-State: APjAAAWMKRD0HNc8iPlKPlhvkbGr7+U9+xg6ijudmkCk36wDCq51ZKmr JpLn6dMYS91cryXsMiRaRYWHE1jdXCUG4A== X-Google-Smtp-Source: APXvYqyope9CWSk1n4NCZmIJb/c+T+tzXEF+a56kjDzzQ+ycCqOgH3INy9i+IPXLLM/3YfrmIo2NxA== X-Received: by 2002:aed:218f:: with SMTP id l15mr494440qtc.247.1578426161890; Tue, 07 Jan 2020 11:42:41 -0800 (PST) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id i90sm359706qtd.49.2020.01.07.11.42.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2020 11:42:41 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 1/5] btrfs: use btrfs_ordered_update_i_size in clone_finish_inode_update Date: Tue, 7 Jan 2020 14:42:33 -0500 Message-Id: <20200107194237.145694-2-josef@toxicpanda.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200107194237.145694-1-josef@toxicpanda.com> References: <20200107194237.145694-1-josef@toxicpanda.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We were using btrfs_i_size_write(), which unconditionally jacks up inode->disk_i_size. However since clone can operate on ranges we could have pending ordered extents for a range prior to the start of our clone operation and thus increase disk_i_size too far and have a hole with no file extent. Fix this by using the btrfs_ordered_update_i_size helper which will do the right thing in the face of pending ordered extents outside of our clone range. Signed-off-by: Josef Bacik Reviewed-by: Filipe Manana --- fs/btrfs/ioctl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 8ec61f3f0291..291dda3b6547 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -3332,8 +3332,10 @@ static int clone_finish_inode_update(struct btrfs_trans_handle *trans, */ if (endoff > destoff + olen) endoff = destoff + olen; - if (endoff > inode->i_size) - btrfs_i_size_write(BTRFS_I(inode), endoff); + if (endoff > inode->i_size) { + i_size_write(inode, endoff); + btrfs_ordered_update_i_size(inode, endoff, NULL); + } ret = btrfs_update_inode(trans, root, inode); if (ret) { From patchwork Tue Jan 7 19:42:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11321675 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 201EB109A for ; Tue, 7 Jan 2020 19:42:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E7A9920848 for ; Tue, 7 Jan 2020 19:42:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20150623.gappssmtp.com header.i=@toxicpanda-com.20150623.gappssmtp.com header.b="uDDDiBqw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728561AbgAGTmp (ORCPT ); Tue, 7 Jan 2020 14:42:45 -0500 Received: from mail-qk1-f194.google.com ([209.85.222.194]:45811 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728358AbgAGTmp (ORCPT ); Tue, 7 Jan 2020 14:42:45 -0500 Received: by mail-qk1-f194.google.com with SMTP id x1so447142qkl.12 for ; Tue, 07 Jan 2020 11:42:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Mn+kMHIiUJgKd+wMMeWQ6ti1vsV3R72fJfMtgyNqzYw=; b=uDDDiBqwhzm65F55g3keCYGel70hLF+O36v0KBf+nDty4P6f4CDlYuRpytCuyuXUD4 IvAhCC8CpZbxQeJAKSf4Seiqp9BvnEnXHhdzg0VfWsxu1YSXc+Fg3bwHvvoTtAbbfrSa CZL1jUeYMAUXdvnzlGAaqrH32Uwy+RNsfW0WCdFA/pjeZWuL9O8M5VW4MID1iMlwGiPf 6doL4CfgpKi9Qn4si6iG0PEuNNVb5CfKq9ryZwxz7+yCIU4PJXRysL5ml/EPc6gDpKoE xFGbUQR+dnsm/WmdYUm8Uu1m1Q8+g//iaKmrXIvNh/ehFFHPi+ecnODKgMSl9cI9btMk yU9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Mn+kMHIiUJgKd+wMMeWQ6ti1vsV3R72fJfMtgyNqzYw=; b=YcmHBWZwAB+ob7/Q1uQs8stAyN9lH9Cxh2rtZmUW3tGYZPqRFY9zI5gr7GSJCWEWTq J6krhZtXgBuUsynAhDMeJne6GXlKcoaq+ArHAOQHXlUnPQcSF9y9GzMX/fkbqYGnfWe9 Qd+fCQCqEEm/EL6djVVGmXlKHfima7KsTA0vDuGKLIXww24HdcXfVVwodLOGNQ1tAVHs 7cgnFzFpV0Q8ruTSuBH3Smku6IUn6V1Pt/Cb0NkSHPZVjZ1HGtsl5e/FdDeuNivPDLer KfoUhj1nvuKroQJjB7cAoa+zrwNxp6MIp97L7Is2sTxe7wxKVdnn6nhMSCF85XXkcjqQ HPVQ== X-Gm-Message-State: APjAAAVmqXwtxdxSVLPHMN71ibk+sWjLKxqqFpU7rDE8/RnZJLmwuHMp gPeLKq0M4zjHr2Ca2Oi2d19W80pNoOFZhQ== X-Google-Smtp-Source: APXvYqxyhFyHJEoG1+uZQi5eNUNUyoCPkMCtguTJDH/nUvzfyMCg5hfEvJviKBze1uGYFPbcal0biQ== X-Received: by 2002:a05:620a:14a4:: with SMTP id x4mr901828qkj.493.1578426163552; Tue, 07 Jan 2020 11:42:43 -0800 (PST) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id t29sm282881qkm.27.2020.01.07.11.42.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2020 11:42:42 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 2/5] btrfs: introduce the inode->file_extent_tree Date: Tue, 7 Jan 2020 14:42:34 -0500 Message-Id: <20200107194237.145694-3-josef@toxicpanda.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200107194237.145694-1-josef@toxicpanda.com> References: <20200107194237.145694-1-josef@toxicpanda.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org In order to keep track of where we have file extents on disk, and thus where it is safe to adjust the i_size to, we need to have a tree in place to keep track of the contiguous areas we have file extents for. Add helpers to use this tree, as it's not required for NO_HOLES file systems. We will use this by setting DIRTY for areas we know we have file extent item's set, and clearing it when we remove file extent items for truncation. Signed-off-by: Josef Bacik Reviewed-by: Filipe Manana --- fs/btrfs/btrfs_inode.h | 5 +++ fs/btrfs/ctree.h | 5 +++ fs/btrfs/extent-io-tree.h | 1 + fs/btrfs/extent_io.c | 11 +++++ fs/btrfs/file-item.c | 91 +++++++++++++++++++++++++++++++++++++++ fs/btrfs/inode.c | 6 +++ 6 files changed, 119 insertions(+) diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h index 4e12a477d32e..d9dcbac513ed 100644 --- a/fs/btrfs/btrfs_inode.h +++ b/fs/btrfs/btrfs_inode.h @@ -60,6 +60,11 @@ struct btrfs_inode { */ struct extent_io_tree io_failure_tree; + /* keeps track of where we have extent items mapped in order to make + * sure our i_size adjustments are accurate. + */ + struct extent_io_tree file_extent_tree; + /* held while logging the inode in tree-log.c */ struct mutex log_mutex; diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index a01ff3e0ead4..7142124d03c5 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -2807,6 +2807,11 @@ void btrfs_extent_item_to_extent_map(struct btrfs_inode *inode, struct btrfs_file_extent_item *fi, const bool new_inline, struct extent_map *em); +int btrfs_inode_clear_file_extent_range(struct btrfs_inode *inode, u64 start, + u64 len); +int btrfs_inode_set_file_extent_range(struct btrfs_inode *inode, u64 start, + u64 len); +void btrfs_inode_safe_disk_i_size_write(struct inode *inode, u64 new_isize); /* inode.c */ struct extent_map *btrfs_get_extent_fiemap(struct btrfs_inode *inode, diff --git a/fs/btrfs/extent-io-tree.h b/fs/btrfs/extent-io-tree.h index a3febe746c79..c8bcd2e3184c 100644 --- a/fs/btrfs/extent-io-tree.h +++ b/fs/btrfs/extent-io-tree.h @@ -44,6 +44,7 @@ enum { IO_TREE_TRANS_DIRTY_PAGES, IO_TREE_ROOT_DIRTY_LOG_PAGES, IO_TREE_SELFTEST, + IO_TREE_INODE_FILE_EXTENT, }; struct extent_io_tree { diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index e374411ed08c..410f5a64d3a6 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -265,6 +265,15 @@ void __cold extent_io_exit(void) bioset_exit(&btrfs_bioset); } +/* + * For the file_extent_tree, we want to hold the inode lock when we lookup and + * update the disk_i_size, but lockdep will complain because our io_tree we hold + * the tree lock and get the inode lock when setting delalloc. These two things + * are unrelated, so make a class for the file_extent_tree so we don't get the + * two locking patterns mixed up. + */ +static struct lock_class_key file_extent_tree_class; + void extent_io_tree_init(struct btrfs_fs_info *fs_info, struct extent_io_tree *tree, unsigned int owner, void *private_data) @@ -276,6 +285,8 @@ void extent_io_tree_init(struct btrfs_fs_info *fs_info, spin_lock_init(&tree->lock); tree->private_data = private_data; tree->owner = owner; + if (owner == IO_TREE_INODE_FILE_EXTENT) + lockdep_set_class(&tree->lock, &file_extent_tree_class); } void extent_io_tree_release(struct extent_io_tree *tree) diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index 1a599f50837b..b733d85510ed 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -23,6 +23,97 @@ #define MAX_CSUM_ITEMS(r, size) (min_t(u32, __MAX_CSUM_ITEMS(r, size), \ PAGE_SIZE)) +/** + * @inode - the inode we want to update the disk_i_size for + * @new_isize - the isize we want to set to, 0 if we use i_size + * + * With NO_HOLES set this simply sets the disk_is_size to whatever i_size_read() + * returns as it is perfectly fine with a file that has holes without hole file + * extent items. + * + * However for !NO_HOLES we need to only return the area that is contiguous from + * the 0 offset of the file. Otherwise we could end up adjust i_size up to an + * extent that has a gap in between. + * + * Finally new_isize should only be set in the case of truncate where we're not + * ready to use i_size_read() as the limiter yet. + */ +void btrfs_inode_safe_disk_i_size_write(struct inode *inode, u64 new_isize) +{ + struct btrfs_fs_info *fs_info = BTRFS_I(inode)->root->fs_info; + u64 start, end, isize; + int ret; + + isize = new_isize ? new_isize : i_size_read(inode); + if (btrfs_fs_incompat(fs_info, NO_HOLES)) { + BTRFS_I(inode)->disk_i_size = isize; + return; + } + + spin_lock(&BTRFS_I(inode)->lock); + ret = find_first_extent_bit(&BTRFS_I(inode)->file_extent_tree, 0, + &start, &end, EXTENT_DIRTY, NULL); + if (!ret && start == 0) + isize = min(isize, end + 1); + else + isize = 0; + BTRFS_I(inode)->disk_i_size = isize; + spin_unlock(&BTRFS_I(inode)->lock); +} + +/** + * @inode - the inode we're modifying + * @start - the start file offset of the file extent we've inserted + * @len - the logical length of the file extent item + * + * Call when we are insering a new file extent where there was none before. + * Does not need to call this in the case where we're replacing an existing file + * extent, however if you're unsure it's fine to call this multiple times. + * + * The start and len must match the file extent item, so thus must be sectorsize + * aligned. + */ +int btrfs_inode_set_file_extent_range(struct btrfs_inode *inode, u64 start, + u64 len) +{ + if (len == 0) + return 0; + + ASSERT(IS_ALIGNED(start + len, inode->root->fs_info->sectorsize)); + + if (btrfs_fs_incompat(inode->root->fs_info, NO_HOLES)) + return 0; + return set_extent_bits(&inode->file_extent_tree, start, start + len - 1, + EXTENT_DIRTY); +} + +/** + * @inode - the inode we're modifying + * @start - the start file offset of the file extent we've inserted + * @len - the logical length of the file extent item + * + * Called when we drop a file extent, for example when we truncate. Doesn't + * need to be called for cases where we're replacing a file extent, like when + * we've cow'ed a file extent. + * + * The start and len must match the file extent item, so thus must be sectorsize + * aligned. + */ +int btrfs_inode_clear_file_extent_range(struct btrfs_inode *inode, u64 start, + u64 len) +{ + if (len == 0) + return 0; + + ASSERT(IS_ALIGNED(start + len, inode->root->fs_info->sectorsize) || + len == (u64)-1); + + if (btrfs_fs_incompat(inode->root->fs_info, NO_HOLES)) + return 0; + return clear_extent_bit(&inode->file_extent_tree, start, + start + len - 1, EXTENT_DIRTY, 0, 0, NULL); +} + static inline u32 max_ordered_sum_bytes(struct btrfs_fs_info *fs_info, u16 csum_size) { diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index db67e1984c91..ab8b972863b1 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -3784,6 +3784,9 @@ static int btrfs_read_locked_inode(struct inode *inode, i_uid_write(inode, btrfs_inode_uid(leaf, inode_item)); i_gid_write(inode, btrfs_inode_gid(leaf, inode_item)); btrfs_i_size_write(BTRFS_I(inode), btrfs_inode_size(leaf, inode_item)); + btrfs_inode_set_file_extent_range(BTRFS_I(inode), 0, + round_up(i_size_read(inode), + fs_info->sectorsize)); inode->i_atime.tv_sec = btrfs_timespec_sec(leaf, &inode_item->atime); inode->i_atime.tv_nsec = btrfs_timespec_nsec(leaf, &inode_item->atime); @@ -9363,6 +9366,8 @@ struct inode *btrfs_alloc_inode(struct super_block *sb) extent_io_tree_init(fs_info, &ei->io_tree, IO_TREE_INODE_IO, inode); extent_io_tree_init(fs_info, &ei->io_failure_tree, IO_TREE_INODE_IO_FAILURE, inode); + extent_io_tree_init(fs_info, &ei->file_extent_tree, + IO_TREE_INODE_FILE_EXTENT, inode); ei->io_tree.track_uptodate = true; ei->io_failure_tree.track_uptodate = true; atomic_set(&ei->sync_writers, 0); @@ -9429,6 +9434,7 @@ void btrfs_destroy_inode(struct inode *inode) btrfs_qgroup_check_reserved_leak(inode); inode_tree_del(inode); btrfs_drop_extent_cache(BTRFS_I(inode), 0, (u64)-1, 0); + btrfs_inode_clear_file_extent_range(BTRFS_I(inode), 0, (u64)-1); btrfs_put_root(BTRFS_I(inode)->root); } From patchwork Tue Jan 7 19:42:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11321677 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 F3A8A109A for ; Tue, 7 Jan 2020 19:42:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C8B952187F for ; Tue, 7 Jan 2020 19:42:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20150623.gappssmtp.com header.i=@toxicpanda-com.20150623.gappssmtp.com header.b="x+HJukZO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728580AbgAGTmr (ORCPT ); Tue, 7 Jan 2020 14:42:47 -0500 Received: from mail-qv1-f67.google.com ([209.85.219.67]:43411 "EHLO mail-qv1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728563AbgAGTmq (ORCPT ); Tue, 7 Jan 2020 14:42:46 -0500 Received: by mail-qv1-f67.google.com with SMTP id p2so370274qvo.10 for ; Tue, 07 Jan 2020 11:42:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=t4kKdnd9NuIjnJO3bt3E6qBFsV9EhYZstDi/vaGPtkU=; b=x+HJukZOQWBOWX8IJnzhMeIZ5tCF4I8GqXLpwQUHM12XTDgXWt/aoXho4LcVi98sXX G2YKgUZ0YlzxtEwCq/166mXM+Kz2T4YCPSHd8ciCBTpX+59ybspui5eQZXVPdPfNL66f avF65/V6G21vZnQi2eo4xfFn7Vk3lMOF8raFbTTCVDQhYx76ZnQRQRgSw/2/VBMTs6RV i9WLP9Vh4EzI/SO01D8gUQ0N88JZnFWZeRuLk/Mc7s6nXd8YpAmuDUM7sRYnhEQZN1bG RxmRvq2Fn729aQ+NK8K/Af3kSKr38ObDr5yYof4vnrEWfe1/FWB5RF0PTtjRpFeCSmJK gSUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=t4kKdnd9NuIjnJO3bt3E6qBFsV9EhYZstDi/vaGPtkU=; b=G4TfgDnm1vqPez1QWHImAzeDkUNquxR6IiMv6LjFCKEscWf51+OD8iFzWdHAizoijF rFNE3Md9KSgoPrS9/nbsWTugn19HEtNHAlxVqr92aiLiWpgqDBMLrvs/rjunAA9QwMcx G5MEu/M4sp7ZGrGlixz3t+z5qZMBFBDr01Uwpu1ITXPHEyjlVdJkQm8YUH0j7jWfzaSq +tMoZMEtoLnqky5KwTi11RtZbMRSbx1eqKb6TshOJAf9oyzQA7V24p99QfUcXbNviHr2 Xp5DTfyuElwOO5Y6Da/6du24RcRo0gU7wD/R5B6pOoGToai6yk6vasNiSlvqEK7y8i7H WDTQ== X-Gm-Message-State: APjAAAUqE+eiWeMTHMbb9KJWJAa/Y/k20QRC5IDEVJ+4t5GZ6io5IMwo sdsZvkX6LLgsQDcZp9raUL2vaS+BaH0tRw== X-Google-Smtp-Source: APXvYqxdUSgMKUccuJ1b60DbG3GePyDyAEXzv/m5Zf+3ukaraEvAT3bvj5DAAXjSMckZXoDkFAjp+g== X-Received: by 2002:ad4:55e8:: with SMTP id bu8mr990408qvb.61.1578426165203; Tue, 07 Jan 2020 11:42:45 -0800 (PST) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id j185sm286626qkc.96.2020.01.07.11.42.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2020 11:42:44 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 3/5] btrfs: use the file extent tree infrastructure Date: Tue, 7 Jan 2020 14:42:35 -0500 Message-Id: <20200107194237.145694-4-josef@toxicpanda.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200107194237.145694-1-josef@toxicpanda.com> References: <20200107194237.145694-1-josef@toxicpanda.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We want to use this everywhere we modify the file extent items permanently. These include 1) Inserting new file extents for writes and prealloc extents. 2) Truncating inode items. 3) btrfs_cont_expand(). 4) Insert inline extents. 5) Insert new extents from log replay. 6) Insert a new extent for clone, as it could be past isize. We do not however call the clear helper for hole punching because it simply swaps out an existing file extent for a hole, so there's effectively no change as far as the i_size is concerned. Signed-off-by: Josef Bacik Reviewed-by: Filipe Manana --- fs/btrfs/delayed-inode.c | 4 +++ fs/btrfs/file.c | 6 ++++ fs/btrfs/inode.c | 59 +++++++++++++++++++++++++++++++++++++++- fs/btrfs/tree-log.c | 5 ++++ 4 files changed, 73 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c index d3e15e1d4a91..8b4dcf4f6b3e 100644 --- a/fs/btrfs/delayed-inode.c +++ b/fs/btrfs/delayed-inode.c @@ -1762,6 +1762,7 @@ int btrfs_fill_inode(struct inode *inode, u32 *rdev) { struct btrfs_delayed_node *delayed_node; struct btrfs_inode_item *inode_item; + struct btrfs_fs_info *fs_info = BTRFS_I(inode)->root->fs_info; delayed_node = btrfs_get_delayed_node(BTRFS_I(inode)); if (!delayed_node) @@ -1779,6 +1780,9 @@ int btrfs_fill_inode(struct inode *inode, u32 *rdev) i_uid_write(inode, btrfs_stack_inode_uid(inode_item)); i_gid_write(inode, btrfs_stack_inode_gid(inode_item)); btrfs_i_size_write(BTRFS_I(inode), btrfs_stack_inode_size(inode_item)); + btrfs_inode_set_file_extent_range(BTRFS_I(inode), 0, + round_up(i_size_read(inode), + fs_info->sectorsize)); inode->i_mode = btrfs_stack_inode_mode(inode_item); set_nlink(inode, btrfs_stack_inode_nlink(inode_item)); inode_set_bytes(inode, btrfs_stack_inode_nbytes(inode_item)); diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 4fadb892af24..f1c880c06ca2 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -2486,6 +2486,12 @@ static int btrfs_insert_clone_extent(struct btrfs_trans_handle *trans, btrfs_mark_buffer_dirty(leaf); btrfs_release_path(path); + ret = btrfs_inode_set_file_extent_range(BTRFS_I(inode), + clone_info->file_offset, + clone_len); + if (ret) + return ret; + /* If it's a hole, nothing more needs to be done. */ if (clone_info->disk_offset == 0) return 0; diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index ab8b972863b1..5d34007aa7ec 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -243,6 +243,15 @@ static int insert_inline_extent(struct btrfs_trans_handle *trans, btrfs_mark_buffer_dirty(leaf); btrfs_release_path(path); + /* + * We align size to sectorsize for inline extents just for simplicity + * sake. + */ + size = ALIGN(size, root->fs_info->sectorsize); + ret = btrfs_inode_set_file_extent_range(BTRFS_I(inode), start, size); + if (ret) + goto fail; + /* * we're an inline extent, so nobody can * extend the file past i_size without locking @@ -2377,6 +2386,11 @@ static int insert_reserved_file_extent(struct btrfs_trans_handle *trans, ins.offset = disk_num_bytes; ins.type = BTRFS_EXTENT_ITEM_KEY; + ret = btrfs_inode_set_file_extent_range(BTRFS_I(inode), file_pos, + ram_bytes); + if (ret) + goto out; + /* * Release the reserved range from inode dirty range map, as it is * already moved into delayed_ref_head @@ -4753,6 +4767,8 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, } while (1) { + u64 clear_start = 0, clear_len = 0; + fi = NULL; leaf = path->nodes[0]; btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]); @@ -4803,6 +4819,8 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, if (extent_type != BTRFS_FILE_EXTENT_INLINE) { u64 num_dec; + + clear_start = found_key.offset; extent_start = btrfs_file_extent_disk_bytenr(leaf, fi); if (!del_item) { u64 orig_num_bytes = @@ -4810,6 +4828,8 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, extent_num_bytes = ALIGN(new_size - found_key.offset, fs_info->sectorsize); + clear_start = ALIGN(new_size, + fs_info->sectorsize); btrfs_set_file_extent_num_bytes(leaf, fi, extent_num_bytes); num_dec = (orig_num_bytes - @@ -4835,6 +4855,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, inode_sub_bytes(inode, num_dec); } } + clear_len = num_dec; } else if (extent_type == BTRFS_FILE_EXTENT_INLINE) { /* * we can't truncate inline items that have had @@ -4856,12 +4877,34 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, */ ret = NEED_TRUNCATE_BLOCK; break; + } else { + /* + * Inline extents are special, we just treat + * them as a full sector worth in the file + * extent tree just for simplicity sake. + */ + clear_len = fs_info->sectorsize; } if (test_bit(BTRFS_ROOT_REF_COWS, &root->state)) inode_sub_bytes(inode, item_end + 1 - new_size); } delete: + /* + * We use btrfs_truncate_inode_items() to clean up log trees for + * multiple fsyncs, and in this case we don't want to clear the + * file extent range because it's just the log. + */ + if (root == BTRFS_I(inode)->root) { + ret = btrfs_inode_clear_file_extent_range(BTRFS_I(inode), + clear_start, + clear_len); + if (ret) { + btrfs_abort_transaction(trans, ret); + break; + } + } + if (del_item) last_size = found_key.offset; else @@ -5183,14 +5226,22 @@ int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size) } last_byte = min(extent_map_end(em), block_end); last_byte = ALIGN(last_byte, fs_info->sectorsize); + hole_size = last_byte - cur_offset; + if (!test_bit(EXTENT_FLAG_PREALLOC, &em->flags)) { struct extent_map *hole_em; - hole_size = last_byte - cur_offset; err = maybe_insert_hole(root, inode, cur_offset, hole_size); if (err) break; + + err = btrfs_inode_set_file_extent_range(BTRFS_I(inode), + cur_offset, + hole_size); + if (err) + break; + btrfs_drop_extent_cache(BTRFS_I(inode), cur_offset, cur_offset + hole_size - 1, 0); hole_em = alloc_extent_map(); @@ -5223,6 +5274,12 @@ int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size) hole_size - 1, 0); } free_extent_map(hole_em); + } else { + err = btrfs_inode_set_file_extent_range(BTRFS_I(inode), + cur_offset, + hole_size); + if (err) + break; } next: free_extent_map(em); diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 19364940f9a1..ad25974ff936 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -829,6 +829,11 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans, goto out; } + ret = btrfs_inode_set_file_extent_range(BTRFS_I(inode), start, + extent_end - start); + if (ret) + goto out; + inode_add_bytes(inode, nbytes); update_inode: ret = btrfs_update_inode(trans, root, inode); From patchwork Tue Jan 7 19:42:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11321679 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 2304C138C for ; Tue, 7 Jan 2020 19:42:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 012D12187F for ; Tue, 7 Jan 2020 19:42:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20150623.gappssmtp.com header.i=@toxicpanda-com.20150623.gappssmtp.com header.b="dLQhuiF3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728585AbgAGTms (ORCPT ); Tue, 7 Jan 2020 14:42:48 -0500 Received: from mail-qk1-f193.google.com ([209.85.222.193]:45814 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728563AbgAGTms (ORCPT ); Tue, 7 Jan 2020 14:42:48 -0500 Received: by mail-qk1-f193.google.com with SMTP id x1so447271qkl.12 for ; Tue, 07 Jan 2020 11:42:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=J5nt0JikFM1EwVaHv1LLQoVpGR0fpJ3Z26VmICyoOls=; b=dLQhuiF3/vdBmX7JuDvLAGLYDIy4PXXj0jwfUrZFF7bvjosobbJu10KVjBxeMUNnRd Ttcd+wIjYIfk8jGP1wkr4MdkzaeImjwjUlYuSslBgfUrBBKIq2oU+cb+Kpl7g4BES0kM qt1vWJpTsKrr2IJW2svMyTd8vdbb3aT48sth+A6OpLYs//LxGpDDI4ZVm1XVXgpsUuTY 1QvaDztf0Wb++EeOz+0VdDENEjlKDZcgTjrtkVp0mpxEeTfkZhLIlRE1vqmxXZLYjVzW 2LzyoSxiVscy6G/iezn7uSZwXw5/BovU/YS0fUCcEW6tRcsnTDkE81wtsdN76VGN5s1o hHag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=J5nt0JikFM1EwVaHv1LLQoVpGR0fpJ3Z26VmICyoOls=; b=WswrT28DbBK+Wbc7iXlna8e7on52OHT7xbqBOGEIc7KFgqpeY9MKglDhKwlplQ1mM7 CtuDkRIt45QGyNcsj9pdc32VBwkxKG/1Hiei3O+ndykZ8ZheSoWMXLCbLjK9hV968YH+ d2HOFrmYdqqb4T5X4hMBj7YluMV7i3kx7LuO7Wq4+qvo12KesfGQg0YUqsJwNFIlsM28 BvJ7xYu7iGo+48kV+/tNFIDCT9l5zxZjKFewL8epWijmXfZyBWWsc7zdfPCkb0eSTVj2 ewS5IsrEQOZAtvhR0E7o/iwdOETGbeyl9dTiZlABV1hjPuedJhTYL3DlUEsMN/XS1ov6 yZ0g== X-Gm-Message-State: APjAAAUK+0uuUanar2umDA0DV/xrGVRDwQw1/sIDfLXEG6+CHJE1OTYP vuY+LqGu1/u0Oxxht+tN8hJMmQ3xXMg9aQ== X-Google-Smtp-Source: APXvYqxoknbO2r4M4P2XjANBxmYLxTGCpxUYE1mFqdSINocQBa716L16OyLsX0aW5nHRvB8QRm7UPQ== X-Received: by 2002:a37:a807:: with SMTP id r7mr998871qke.346.1578426166721; Tue, 07 Jan 2020 11:42:46 -0800 (PST) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id r205sm305117qke.34.2020.01.07.11.42.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2020 11:42:46 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 4/5] btrfs: replace all uses of btrfs_ordered_update_i_size Date: Tue, 7 Jan 2020 14:42:36 -0500 Message-Id: <20200107194237.145694-5-josef@toxicpanda.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200107194237.145694-1-josef@toxicpanda.com> References: <20200107194237.145694-1-josef@toxicpanda.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Now that we have a safe way to update the i_size, replace all uses of btrfs_ordered_update_i_size with btrfs_inode_safe_disk_i_size_write. Signed-off-by: Josef Bacik Reviewed-by: Filipe Manana --- fs/btrfs/file.c | 2 +- fs/btrfs/inode.c | 12 ++++++------ fs/btrfs/ioctl.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index f1c880c06ca2..35fdc5b99804 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -2941,7 +2941,7 @@ static int btrfs_fallocate_update_isize(struct inode *inode, inode->i_ctime = current_time(inode); i_size_write(inode, end); - btrfs_ordered_update_i_size(inode, end, NULL); + btrfs_inode_safe_disk_i_size_write(inode, 0); ret = btrfs_update_inode(trans, root, inode); ret2 = btrfs_end_transaction(trans); diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 5d34007aa7ec..4a3ef3174d73 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -3119,7 +3119,7 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) */ btrfs_qgroup_free_data(inode, NULL, ordered_extent->file_offset, ordered_extent->len); - btrfs_ordered_update_i_size(inode, 0, ordered_extent); + btrfs_inode_safe_disk_i_size_write(inode, 0); if (freespace_inode) trans = btrfs_join_transaction_spacecache(root); else @@ -3207,7 +3207,7 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) goto out; } - btrfs_ordered_update_i_size(inode, 0, ordered_extent); + btrfs_inode_safe_disk_i_size_write(inode, 0); ret = btrfs_update_inode_fallback(trans, root, inode); if (ret) { /* -ENOMEM or corruption */ btrfs_abort_transaction(trans, ret); @@ -5007,7 +5007,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, ASSERT(last_size >= new_size); if (!ret && last_size > new_size) last_size = new_size; - btrfs_ordered_update_i_size(inode, last_size, NULL); + btrfs_inode_safe_disk_i_size_write(inode, last_size); } btrfs_free_path(path); @@ -5337,7 +5337,7 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr) } i_size_write(inode, newsize); - btrfs_ordered_update_i_size(inode, i_size_read(inode), NULL); + btrfs_inode_safe_disk_i_size_write(inode, 0); pagecache_isize_extended(inode, oldsize, newsize); ret = btrfs_update_inode(trans, root, inode); btrfs_end_write_no_snapshotting(root); @@ -9319,7 +9319,7 @@ static int btrfs_truncate(struct inode *inode, bool skip_writeback) ret = PTR_ERR(trans); goto out; } - btrfs_ordered_update_i_size(inode, inode->i_size, NULL); + btrfs_inode_safe_disk_i_size_write(inode, 0); } if (trans) { @@ -10578,7 +10578,7 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode, else i_size = cur_offset; i_size_write(inode, i_size); - btrfs_ordered_update_i_size(inode, i_size, NULL); + btrfs_inode_safe_disk_i_size_write(inode, 0); } ret = btrfs_update_inode(trans, root, inode); diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 291dda3b6547..2a02a21cac59 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -3334,7 +3334,7 @@ static int clone_finish_inode_update(struct btrfs_trans_handle *trans, endoff = destoff + olen; if (endoff > inode->i_size) { i_size_write(inode, endoff); - btrfs_ordered_update_i_size(inode, endoff, NULL); + btrfs_inode_safe_disk_i_size_write(inode, 0); } ret = btrfs_update_inode(trans, root, inode); From patchwork Tue Jan 7 19:42:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11321681 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 1FB1E109A for ; Tue, 7 Jan 2020 19:42:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E91C62187F for ; Tue, 7 Jan 2020 19:42:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20150623.gappssmtp.com header.i=@toxicpanda-com.20150623.gappssmtp.com header.b="Yg7FWIp9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728596AbgAGTmu (ORCPT ); Tue, 7 Jan 2020 14:42:50 -0500 Received: from mail-qk1-f196.google.com ([209.85.222.196]:37115 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728563AbgAGTmu (ORCPT ); Tue, 7 Jan 2020 14:42:50 -0500 Received: by mail-qk1-f196.google.com with SMTP id 21so508487qky.4 for ; Tue, 07 Jan 2020 11:42:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=wX8kxsXzTAH8cXKUNYxwg9ut9y6Ze9uaz7hZwHtNmO8=; b=Yg7FWIp9ODVXSyAw0YoBPz2BHgG+bFT03CbCSnPOUfZwmxwvQyouGtS4J/JotS5Xa9 J6BLfwuKOlo7FaG/xOZChfgHUDYrOx0ZHVnQ365zWV5d/RB3eQPp30BDUsa2ip+CPjKE Ktf/TCZ0N4sscxM00R5UwySXu3zVEQLqAncEtWuFsfGmtBMknEvtb4FVKpUaC9426gtG 0TJDNFnjUDu/NRDHm2Q/zOac4ghoEJ5X4UisBIpUvwAy5RdwCaC5jXjsZMVe5NzeA5zw PC8wapu9Mving6GjoCU+AzBHmDJ6P5myMI8Oaak5FhexmGvBL/KoYGjgagS5uYUoPyU2 JUQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wX8kxsXzTAH8cXKUNYxwg9ut9y6Ze9uaz7hZwHtNmO8=; b=o0wLjHbgVEynJPnHESf6M5ln5RiZPYKSHzzitLQAP6UWyO+KVbsjJHf/MIxx42cO5o KCbbamiyWrCPbuOUj6yoQng/RLpDalT4BC/h96z9YS2VCLt32GPWh0b5NH3YXVUbs7p6 Ft17HMzPtiAkr+THsInzvvGeR77gRZYgmkWSxvysngyMBk0QP2190Yf7zHLri2odpKdT EHdFduaqhTI9Jb0bGF4ulwR0fEwnUhKt0j7kJs4IfjEGMZF92X5tdEBaoF+apoezFgmX V6Tcmud9WIr3ock603E7BNv34mPNG3FU0PMsVEyBEqVdjWgxZE7FvlH1X2pnrFiRRC+x gyZg== X-Gm-Message-State: APjAAAVBdY5Pww+RH5NipAR3UKA8XgJprQodkD48obhW6n03PVnkbINo pTinvX1K/708iga41Cqo1gFA8yWQxJBTEg== X-Google-Smtp-Source: APXvYqy+K8yxnTEyED1Tj1YNuB44XQ5mwXoZEQhMDnRhhMZLBPWrEfik3meqM+KiSHXrihGmWDsjuA== X-Received: by 2002:a05:620a:a02:: with SMTP id i2mr978093qka.264.1578426168299; Tue, 07 Jan 2020 11:42:48 -0800 (PST) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id m20sm294525qkk.15.2020.01.07.11.42.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2020 11:42:47 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 5/5] btrfs: delete the ordered isize update code Date: Tue, 7 Jan 2020 14:42:37 -0500 Message-Id: <20200107194237.145694-6-josef@toxicpanda.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200107194237.145694-1-josef@toxicpanda.com> References: <20200107194237.145694-1-josef@toxicpanda.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Now that we have a safe way to update the isize, remove all of this code as it's no longer needed. Signed-off-by: Josef Bacik Reviewed-by: Filipe Manana --- fs/btrfs/ordered-data.c | 128 ----------------------------------- fs/btrfs/ordered-data.h | 7 -- include/trace/events/btrfs.h | 1 - 3 files changed, 136 deletions(-) diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c index 3a3c648bb9d3..b8de2aea36b3 100644 --- a/fs/btrfs/ordered-data.c +++ b/fs/btrfs/ordered-data.c @@ -791,134 +791,6 @@ btrfs_lookup_first_ordered_extent(struct inode *inode, u64 file_offset) return entry; } -/* - * After an extent is done, call this to conditionally update the on disk - * i_size. i_size is updated to cover any fully written part of the file. - */ -int btrfs_ordered_update_i_size(struct inode *inode, u64 offset, - struct btrfs_ordered_extent *ordered) -{ - struct btrfs_ordered_inode_tree *tree = &BTRFS_I(inode)->ordered_tree; - u64 disk_i_size; - u64 new_i_size; - u64 i_size = i_size_read(inode); - struct rb_node *node; - struct rb_node *prev = NULL; - struct btrfs_ordered_extent *test; - int ret = 1; - u64 orig_offset = offset; - - spin_lock_irq(&tree->lock); - if (ordered) { - offset = entry_end(ordered); - if (test_bit(BTRFS_ORDERED_TRUNCATED, &ordered->flags)) - offset = min(offset, - ordered->file_offset + - ordered->truncated_len); - } else { - offset = ALIGN(offset, btrfs_inode_sectorsize(inode)); - } - disk_i_size = BTRFS_I(inode)->disk_i_size; - - /* - * truncate file. - * If ordered is not NULL, then this is called from endio and - * disk_i_size will be updated by either truncate itself or any - * in-flight IOs which are inside the disk_i_size. - * - * Because btrfs_setsize() may set i_size with disk_i_size if truncate - * fails somehow, we need to make sure we have a precise disk_i_size by - * updating it as usual. - * - */ - if (!ordered && disk_i_size > i_size) { - BTRFS_I(inode)->disk_i_size = orig_offset; - ret = 0; - goto out; - } - - /* - * if the disk i_size is already at the inode->i_size, or - * this ordered extent is inside the disk i_size, we're done - */ - if (disk_i_size == i_size) - goto out; - - /* - * We still need to update disk_i_size if outstanding_isize is greater - * than disk_i_size. - */ - if (offset <= disk_i_size && - (!ordered || ordered->outstanding_isize <= disk_i_size)) - goto out; - - /* - * walk backward from this ordered extent to disk_i_size. - * if we find an ordered extent then we can't update disk i_size - * yet - */ - if (ordered) { - node = rb_prev(&ordered->rb_node); - } else { - prev = tree_search(tree, offset); - /* - * we insert file extents without involving ordered struct, - * so there should be no ordered struct cover this offset - */ - if (prev) { - test = rb_entry(prev, struct btrfs_ordered_extent, - rb_node); - BUG_ON(offset_in_entry(test, offset)); - } - node = prev; - } - for (; node; node = rb_prev(node)) { - test = rb_entry(node, struct btrfs_ordered_extent, rb_node); - - /* We treat this entry as if it doesn't exist */ - if (test_bit(BTRFS_ORDERED_UPDATED_ISIZE, &test->flags)) - continue; - - if (entry_end(test) <= disk_i_size) - break; - if (test->file_offset >= i_size) - break; - - /* - * We don't update disk_i_size now, so record this undealt - * i_size. Or we will not know the real i_size. - */ - if (test->outstanding_isize < offset) - test->outstanding_isize = offset; - if (ordered && - ordered->outstanding_isize > test->outstanding_isize) - test->outstanding_isize = ordered->outstanding_isize; - goto out; - } - new_i_size = min_t(u64, offset, i_size); - - /* - * Some ordered extents may completed before the current one, and - * we hold the real i_size in ->outstanding_isize. - */ - if (ordered && ordered->outstanding_isize > new_i_size) - new_i_size = min_t(u64, ordered->outstanding_isize, i_size); - BTRFS_I(inode)->disk_i_size = new_i_size; - ret = 0; -out: - /* - * We need to do this because we can't remove ordered extents until - * after the i_disk_size has been updated and then the inode has been - * updated to reflect the change, so we need to tell anybody who finds - * this ordered extent that we've already done all the real work, we - * just haven't completed all the other work. - */ - if (ordered) - set_bit(BTRFS_ORDERED_UPDATED_ISIZE, &ordered->flags); - spin_unlock_irq(&tree->lock); - return ret; -} - /* * search the ordered extents for one corresponding to 'offset' and * try to find a checksum. This is used because we allow pages to diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h index 5204171ea962..7f7f9ad091a6 100644 --- a/fs/btrfs/ordered-data.h +++ b/fs/btrfs/ordered-data.h @@ -52,11 +52,6 @@ enum { BTRFS_ORDERED_DIRECT, /* We had an io error when writing this out */ BTRFS_ORDERED_IOERR, - /* - * indicates whether this ordered extent has done its due diligence in - * updating the isize - */ - BTRFS_ORDERED_UPDATED_ISIZE, /* Set when we have to truncate an extent */ BTRFS_ORDERED_TRUNCATED, /* Regular IO for COW */ @@ -180,8 +175,6 @@ struct btrfs_ordered_extent *btrfs_lookup_ordered_range( struct btrfs_inode *inode, u64 file_offset, u64 len); -int btrfs_ordered_update_i_size(struct inode *inode, u64 offset, - struct btrfs_ordered_extent *ordered); int btrfs_find_ordered_sum(struct inode *inode, u64 offset, u64 disk_bytenr, u8 *sum, int len); u64 btrfs_wait_ordered_extents(struct btrfs_root *root, u64 nr, diff --git a/include/trace/events/btrfs.h b/include/trace/events/btrfs.h index 620bf1b38fba..02ac28f0e99e 100644 --- a/include/trace/events/btrfs.h +++ b/include/trace/events/btrfs.h @@ -468,7 +468,6 @@ DEFINE_EVENT( { (1 << BTRFS_ORDERED_PREALLOC), "PREALLOC" }, \ { (1 << BTRFS_ORDERED_DIRECT), "DIRECT" }, \ { (1 << BTRFS_ORDERED_IOERR), "IOERR" }, \ - { (1 << BTRFS_ORDERED_UPDATED_ISIZE), "UPDATED_ISIZE" }, \ { (1 << BTRFS_ORDERED_TRUNCATED), "TRUNCATED" })