From patchwork Wed Nov 18 23:06:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11916095 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 647D1C63798 for ; Wed, 18 Nov 2020 23:06:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D8642246A6 for ; Wed, 18 Nov 2020 23:06:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="OsjK0nIZ"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="k+bjQ5BM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726881AbgKRXG1 (ORCPT ); Wed, 18 Nov 2020 18:06:27 -0500 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:36591 "EHLO wout2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725822AbgKRXG1 (ORCPT ); Wed, 18 Nov 2020 18:06:27 -0500 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id 707484B0; Wed, 18 Nov 2020 18:06:43 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 18 Nov 2020 18:06:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=from :to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=fm2; bh=XuPXao7xtTc6Kw3ODPI/9dnM+8 PgN19JmP/ITb5P44M=; b=OsjK0nIZfkfAKOHUVeTkDpfBFUu2lHC3xSbfvpVwOo SQGAi8ckko/Ar0v7TfrRZxQVZVnjQoilYlXz6OjvK4tAXJGvwyKZjRpVfn6REzhC k8Y7DGbWT7VANFV1gi796nkfXRN6RPgrv7I9YutOPZGrPTChRn3RaIk97L27xQzm uXYP/kcexh2y8rkMNck/NLDrfwmCEeP4fKQnaOwRMH6o/MNqhL7SzrAyQHGmtMY+ wq8PwcH5p0l6KAkA7HsN4jdVyZ9PhiXoLqxQOUcxcITbYBwpHAuaJFvHQrhBbK6t cghVeGCMmuODGcAgAtMFNqhararqJtaYtcjvZQeSxwNw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=XuPXao7xtTc6Kw3ODPI/9dnM+8PgN19JmP/ITb5P44M=; b=k+bjQ5BM MpgaZdD6OMchEOiTNgsBCMBCxzwP7jTilFWjX7pWfG7GTsqR+roT9RTLtq721OMb EDN46/1bc2T+vCo04TKS6TEPYCkMQjt05EYXKB2H+Ma8N0JX4GYBALiN+yE++1Q7 2Vopf9G1PuBJqz6urfO3xWKN7576eX2CN4rw8Z8eUqvc/vnPwerKPudBCPb3NECM UxkhN+MLA3oX0lznALgRl98tad6CpbfoZhxJCA6HrGFaJoG+SOpwKz9FToBm/55l FPKX68C3cpfeUZgfNwkAoh9mr/fAfqzqz3I/MVk4qVcOjhwocIA1T/4vTNGTHNEI xBjQ15NBFZhgGg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudefiedgtdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepuehorhhishcuuehurhhkohhvuceosghorhhishessghurhdr ihhoqeenucggtffrrghtthgvrhhnpeeiueffuedvieeujefhheeigfekvedujeejjeffve dvhedtudefiefhkeegueehleenucfkphepudeifedruddugedrudefvddrfeenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhrihhssegsuh hrrdhioh X-ME-Proxy: Received: from localhost (unknown [163.114.132.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 57E3A3064AB4; Wed, 18 Nov 2020 18:06:42 -0500 (EST) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v7 01/12] btrfs: lift rw mount setup from mount and remount Date: Wed, 18 Nov 2020 15:06:16 -0800 Message-Id: X-Mailer: git-send-email 2.24.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Mounting rw and remounting from ro to rw naturally share invariants and functionality which result in a correctly setup rw filesystem. Luckily, there is even a strong unity in the code which implements them. In mount's open_ctree, these operations mostly happen after an early return for ro file systems, and in remount, they happen in a section devoted to remounting ro->rw, after some remount specific validation passes. However, there are unfortunately a few differences. There are small deviations in the order of some of the operations, remount does not cleanup orphan inodes in root_tree or fs_tree, remount does not create the free space tree, and remount does not handle "one-shot" mount options like clear_cache and uuid tree rescan. Since we want to add building the free space tree to remount, and since it is possible to leak orphans on a filesystem mounted as ro then remounted rw (common for the root filesystem when booting), we would benefit from unifying the logic between the two codepaths. This patch only lifts the existing common functionality, and leaves a natural path for fixing the discrepancies. Signed-off-by: Boris Burkov --- fs/btrfs/disk-io.c | 91 ++++++++++++++++++++++++++-------------------- fs/btrfs/disk-io.h | 1 + fs/btrfs/super.c | 37 +++---------------- 3 files changed, 59 insertions(+), 70 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 8c87a1caefff..3e0de4986dbc 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2884,6 +2884,53 @@ static int btrfs_check_uuid_tree(struct btrfs_fs_info *fs_info) return 0; } +/* + * Mounting logic specific to read-write file systems. Shared by open_ctree + * and btrfs_remount when remounting from read-only to read-write. + */ +int btrfs_mount_rw(struct btrfs_fs_info *fs_info) +{ + int ret; + + ret = btrfs_cleanup_fs_roots(fs_info); + if (ret) + goto out; + + mutex_lock(&fs_info->cleaner_mutex); + ret = btrfs_recover_relocation(fs_info->tree_root); + mutex_unlock(&fs_info->cleaner_mutex); + if (ret < 0) { + btrfs_warn(fs_info, "failed to recover relocation: %d", ret); + goto out; + } + + ret = btrfs_resume_balance_async(fs_info); + if (ret) + goto out; + + ret = btrfs_resume_dev_replace_async(fs_info); + if (ret) { + btrfs_warn(fs_info, "failed to resume dev_replace"); + goto out; + } + + btrfs_qgroup_rescan_resume(fs_info); + + if (!fs_info->uuid_root) { + btrfs_info(fs_info, "creating UUID tree"); + ret = btrfs_create_uuid_tree(fs_info); + if (ret) { + btrfs_warn(fs_info, + "failed to create the UUID tree %d", + ret); + goto out; + } + } + +out: + return ret; +} + int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_devices, char *options) { @@ -3290,22 +3337,6 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device if (ret) goto fail_qgroup; - if (!sb_rdonly(sb)) { - ret = btrfs_cleanup_fs_roots(fs_info); - if (ret) - goto fail_qgroup; - - mutex_lock(&fs_info->cleaner_mutex); - ret = btrfs_recover_relocation(tree_root); - mutex_unlock(&fs_info->cleaner_mutex); - if (ret < 0) { - btrfs_warn(fs_info, "failed to recover relocation: %d", - ret); - err = -EINVAL; - goto fail_qgroup; - } - } - fs_info->fs_root = btrfs_get_fs_root(fs_info, BTRFS_FS_TREE_OBJECTID, true); if (IS_ERR(fs_info->fs_root)) { err = PTR_ERR(fs_info->fs_root); @@ -3358,35 +3389,17 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device } up_read(&fs_info->cleanup_work_sem); - ret = btrfs_resume_balance_async(fs_info); - if (ret) { - btrfs_warn(fs_info, "failed to resume balance: %d", ret); - close_ctree(fs_info); - return ret; - } - - ret = btrfs_resume_dev_replace_async(fs_info); + ret = btrfs_mount_rw(fs_info); if (ret) { - btrfs_warn(fs_info, "failed to resume device replace: %d", ret); close_ctree(fs_info); return ret; } - - btrfs_qgroup_rescan_resume(fs_info); btrfs_discard_resume(fs_info); - if (!fs_info->uuid_root) { - btrfs_info(fs_info, "creating UUID tree"); - ret = btrfs_create_uuid_tree(fs_info); - if (ret) { - btrfs_warn(fs_info, - "failed to create the UUID tree: %d", ret); - close_ctree(fs_info); - return ret; - } - } else if (btrfs_test_opt(fs_info, RESCAN_UUID_TREE) || - fs_info->generation != - btrfs_super_uuid_tree_generation(disk_super)) { + if (fs_info->uuid_root && + (btrfs_test_opt(fs_info, RESCAN_UUID_TREE) || + fs_info->generation != + btrfs_super_uuid_tree_generation(disk_super))) { btrfs_info(fs_info, "checking UUID tree"); ret = btrfs_check_uuid_tree(fs_info); if (ret) { diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h index e75ea6092942..945914d1747f 100644 --- a/fs/btrfs/disk-io.h +++ b/fs/btrfs/disk-io.h @@ -50,6 +50,7 @@ struct extent_buffer *btrfs_find_create_tree_block( u64 bytenr, u64 owner_root, int level); void btrfs_clean_tree_block(struct extent_buffer *buf); +int btrfs_mount_rw(struct btrfs_fs_info *fs_info); int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_devices, char *options); diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 6693cfc14dfd..ad5a78970389 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1878,7 +1878,6 @@ static inline void btrfs_remount_cleanup(struct btrfs_fs_info *fs_info, static int btrfs_remount(struct super_block *sb, int *flags, char *data) { struct btrfs_fs_info *fs_info = btrfs_sb(sb); - struct btrfs_root *root = fs_info->tree_root; unsigned old_flags = sb->s_flags; unsigned long old_opts = fs_info->mount_opt; unsigned long old_compress_type = fs_info->compress_type; @@ -1971,39 +1970,15 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data) goto restore; } - ret = btrfs_cleanup_fs_roots(fs_info); - if (ret) - goto restore; - - /* recover relocation */ - mutex_lock(&fs_info->cleaner_mutex); - ret = btrfs_recover_relocation(root); - mutex_unlock(&fs_info->cleaner_mutex); - if (ret) - goto restore; - - ret = btrfs_resume_balance_async(fs_info); + /* + * NOTE: when remounting with a change that does writes, don't + * put it anywhere above this point, as we are not sure to be + * safe to write until we pass the above checks. + */ + ret = btrfs_mount_rw(fs_info); if (ret) goto restore; - ret = btrfs_resume_dev_replace_async(fs_info); - if (ret) { - btrfs_warn(fs_info, "failed to resume dev_replace"); - goto restore; - } - - btrfs_qgroup_rescan_resume(fs_info); - - if (!fs_info->uuid_root) { - btrfs_info(fs_info, "creating UUID tree"); - ret = btrfs_create_uuid_tree(fs_info); - if (ret) { - btrfs_warn(fs_info, - "failed to create the UUID tree %d", - ret); - goto restore; - } - } sb->s_flags &= ~SB_RDONLY; set_bit(BTRFS_FS_OPEN, &fs_info->flags); From patchwork Wed Nov 18 23:06:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11916093 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA169C63697 for ; Wed, 18 Nov 2020 23:06:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4860822255 for ; Wed, 18 Nov 2020 23:06:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="VfYiNDCU"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="BYR28fFx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726889AbgKRXGa (ORCPT ); Wed, 18 Nov 2020 18:06:30 -0500 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:56617 "EHLO wout2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726588AbgKRXGa (ORCPT ); Wed, 18 Nov 2020 18:06:30 -0500 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id E4DCCD37; Wed, 18 Nov 2020 18:06:46 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 18 Nov 2020 18:06:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=from :to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=fm2; bh=eJZSpcjXxOpl9/AEy4OvQwVU6w DDaas8FavaIrwBnbc=; b=VfYiNDCULjFsZ7NU0tZcmQAcqI72BJycbWqfOWHUhD R3riA/dWC3EYIDm6QsqUU8c40UnXIdmKXEP+Gnsuc879w/LUCZhJEryFVBOJJLzm da/x5/nbDUR0B3TAP/kDwDBzfj1HOiUypTAFne8Ti35TLjrmYqQjRyhbNQPnE9Wb 3R4aBVvjRKA4l6ZoEJlBYOOtXomxqopmx1qzxnoOY5vcwx0RoJ/hCTvT1E65jQg8 dii35lzclXrbAH7TuBENolGTQcBTKXW8rLXf56wu13nkdZuvCHy9M74yg1E1h0U6 7JJL1ECc14GAGormjVkQjVZHFRbowxdEKpNxJ8idMDJw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=eJZSpcjXxOpl9/AEy4OvQwVU6wDDaas8FavaIrwBnbc=; b=BYR28fFx QAYLzZ1h9QxGSKCOYRKMZhRrQn6H+RM7l/T4wvXjW01viUYDUy/7ggeDLG//ESS0 ERTbpdTx+3xTPfHekSsIaKmk1mnXzD2ju2etFjxsYPOOKRc7uhoxuh0rzSKOs9OF ree4/H79YdQN4HsOnKFLiqG7HH6FuAQ1uLirSDkxKwskZ7r/hgScRNjZ0f1qTZ84 2cdHhqp+KJ7r1LBYPXHMMOx5kgSufFW0XLcHKrYEAsi39SqAYMF5TDo5fMelp402 D6JfKlc8ki4oMFJ0ag0Fegf5jTsMsDQDayee55kXEJFI4rY2b1Bi55xQypMsj5DD aztt1uBxV5oWBA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudefiedgtdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepuehorhhishcuuehurhhkohhvuceosghorhhishessghurhdr ihhoqeenucggtffrrghtthgvrhhnpeeiueffuedvieeujefhheeigfekvedujeejjeffve dvhedtudefiefhkeegueehleenucfkphepudeifedruddugedrudefvddrfeenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhrihhssegsuh hrrdhioh X-ME-Proxy: Received: from localhost (unknown [163.114.132.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 1A8ED3280060; Wed, 18 Nov 2020 18:06:46 -0500 (EST) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v7 02/12] btrfs: cleanup all orphan inodes on ro->rw remount Date: Wed, 18 Nov 2020 15:06:17 -0800 Message-Id: <623aef2cdca5e4444a1575f09555d24a827130d7.1605736355.git.boris@bur.io> X-Mailer: git-send-email 2.24.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org When we mount a rw file system, we clean the orphan inodes in the filesystem trees, and also on the tree_root and fs_root. However, when we remount a ro file system rw, we only clean the former. Move the calls to btrfs_orphan_cleanup() on tree_root and fs_root to the shared rw mount routine to effectively add them on ro->rw remount. Signed-off-by: Boris Burkov --- fs/btrfs/disk-io.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 3e0de4986dbc..2cf81a4e9393 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2896,6 +2896,14 @@ int btrfs_mount_rw(struct btrfs_fs_info *fs_info) if (ret) goto out; + down_read(&fs_info->cleanup_work_sem); + if ((ret = btrfs_orphan_cleanup(fs_info->fs_root)) || + (ret = btrfs_orphan_cleanup(fs_info->tree_root))) { + up_read(&fs_info->cleanup_work_sem); + goto out; + } + up_read(&fs_info->cleanup_work_sem); + mutex_lock(&fs_info->cleaner_mutex); ret = btrfs_recover_relocation(fs_info->tree_root); mutex_unlock(&fs_info->cleaner_mutex); @@ -3380,15 +3388,6 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device } } - down_read(&fs_info->cleanup_work_sem); - if ((ret = btrfs_orphan_cleanup(fs_info->fs_root)) || - (ret = btrfs_orphan_cleanup(fs_info->tree_root))) { - up_read(&fs_info->cleanup_work_sem); - close_ctree(fs_info); - return ret; - } - up_read(&fs_info->cleanup_work_sem); - ret = btrfs_mount_rw(fs_info); if (ret) { close_ctree(fs_info); From patchwork Wed Nov 18 23:06:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11916091 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1AB78C6379D for ; Wed, 18 Nov 2020 23:06:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B0E5A246A6 for ; Wed, 18 Nov 2020 23:06:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="wRcWWahU"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Hr6xtLxK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726894AbgKRXGe (ORCPT ); Wed, 18 Nov 2020 18:06:34 -0500 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:42875 "EHLO wout2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726588AbgKRXGd (ORCPT ); Wed, 18 Nov 2020 18:06:33 -0500 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id 25696D1B; Wed, 18 Nov 2020 18:06:50 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 18 Nov 2020 18:06:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=from :to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=fm2; bh=o/qP6jVfo7jqebTt1uvcTepx+U 0+6+5bcy7oaUSqaUw=; b=wRcWWahU53oHTPxvGVcqiL+evull3vb19CK1f7RYBA ll+bd8j8ZDAbdBlHw3W8gdjeCnqEnGtzyMkLPrmRdvEU7RVQ+yJF+Knd5RKjbHMm YmKf2UfgaxpV9+GNJZxbsryiCuDUPitI5ngx/3HzbCM0wOMcdsBWj25GtjJ2FL6h ZO0ZkQ9V39mLRKA47GslxmAlTggXmZ6fN5ccF+4Km/R0jTAFFb6dFkZ+C8XrwXjK CVBLiyF3hiUJoIJEDkdjc9oEmdW0BP8OctmrDwWAVD6YR6VPUfAkEPGbDltE6OOc 6UCnA88hsYUJICi/dT2QXU0O0gA9EdWtsLastqgjshXw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=o/qP6jVfo7jqebTt1uvcTepx+U0+6+5bcy7oaUSqaUw=; b=Hr6xtLxK mkI4AsZA4cKrWngWhvyODZW/FUMSfupYPY6MlbXFNPZiIY3tKDi/vuJZS66vjhWm G4/FMnxK8rQfiu1F0gqfbwE9grL+ojyVhWTTKmxujVQcKIR4i777/9D23gXR8H6h 89qomdo7+k7MVp+T92HUFsWirHPJ4kXJstGfOcGyVn1QMV54/Xw/yH3am7otcZVV N6Jpxl5t9hSJWsWXoLjFh8kopfSgF7Fn7i13jEx9ZCKUZfk1aYOZ3ZeXgbVU1Lcw S1qeowsOS7vlh7xrfBBMjEfCCS8BWmjns6nQVBQB3YXJSFPd/PHQ0CHUHwiaw1YU E2uH1yettfoD3Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudefiedgtdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepuehorhhishcuuehurhhkohhvuceosghorhhishessghurhdr ihhoqeenucggtffrrghtthgvrhhnpeeiueffuedvieeujefhheeigfekvedujeejjeffve dvhedtudefiefhkeegueehleenucfkphepudeifedruddugedrudefvddrfeenucevlhhu shhtvghrufhiiigvpedvnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhrihhssegsuh hrrdhioh X-ME-Proxy: Received: from localhost (unknown [163.114.132.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 56E5C3280064; Wed, 18 Nov 2020 18:06:49 -0500 (EST) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v7 03/12] btrfs: only mark bg->needs_free_space if free space tree is on Date: Wed, 18 Nov 2020 15:06:18 -0800 Message-Id: X-Mailer: git-send-email 2.24.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org If we attempt to create a free space tree while any block groups have needs_free_space set, we will double add the new free space item and hit EEXIST. Previously, we only created the free space tree on a new mount, so we never hit the case, but if we try to create it on a remount, such block groups could exist and trip us up. We don't do anything with this field unless the free space tree is enabled, so there is no harm in not setting it. Signed-off-by: Boris Burkov --- fs/btrfs/block-group.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index ccc3271c20ca..00e2fe1d0f32 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -2156,7 +2156,8 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans, u64 bytes_used, cache->flags = type; cache->last_byte_to_unpin = (u64)-1; cache->cached = BTRFS_CACHE_FINISHED; - cache->needs_free_space = 1; + if (btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) + cache->needs_free_space = 1; ret = exclude_super_stripes(cache); if (ret) { /* We may have excluded something, so call this just in case */ From patchwork Wed Nov 18 23:06:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11916097 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9017C64E69 for ; Wed, 18 Nov 2020 23:06:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3C321246A6 for ; Wed, 18 Nov 2020 23:06:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="RNYjwNM5"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="m6kSFwWP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726963AbgKRXGh (ORCPT ); Wed, 18 Nov 2020 18:06:37 -0500 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:55521 "EHLO wout2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726588AbgKRXGg (ORCPT ); Wed, 18 Nov 2020 18:06:36 -0500 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id 75799CB5; Wed, 18 Nov 2020 18:06:53 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 18 Nov 2020 18:06:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=from :to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=fm2; bh=u/1qGS3weBrAzq6EszV7UslQgz 6RAD2sf0UlFOd1vgE=; b=RNYjwNM56XE7YXsUsx2lH35th8EKiK5jT4S+nQuhvW 8j7u22rfs8hHQv9ihdQLV5O00rEktlf07HZhH/ifYsifD3jrgcC6PqP6OQWCeT9X eFJVRmzdNgD2yClPVGgM9UfoMh1Rl8mwuA8pr1f25S7iD6Kp20EwgztH8dKy7p8X 4cXgZf8SiQtKdzFIJC1aFg4Qnrp7bP5sQWQVlAFzxTnpEA7H+DOwtjqW8VzUlFAW hmsPzZcO0P6EYNXznXUjTD6O7Eql659H9p9zwBM40xokF46C335vIdhYhObMyJL0 4szup6rNidgIF1k2Tq9Ks7IwRkdTTbUAPZcF92qbQGBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=u/1qGS3weBrAzq6EszV7UslQgz6RAD2sf0UlFOd1vgE=; b=m6kSFwWP wNP+KNCfBe0ySAXh4hxAdt4PEUlgWlZK2c6cRpyctYa3euIHz8vxtJQ2LQvHmG9d ldOwEWeHYpz+6EU2yW9QlwYOX5sAjGEYytmfV5yM3i79c075ngY+EMIAMTYiWi5a AS2TcFH7FKuJCGWOmKM9yLtbzgGXeE8pTtxFyABoDeO19tt+t3D4X5j/2r1cVr1h UdGoCCume+scUtFiIMgAB8mSvPl8rD0UqFEsrMXGeivfD/yhA46MQ9glz2nFUxXL e1HJiXmqdiEOsey56S2TtKpwHtsZLgcsxCgqbOuwq3fAqw0FNCRG0Drw+W+4dzV/ ugEqY7dejp6GmQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudefiedgtdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepuehorhhishcuuehurhhkohhvuceosghorhhishessghurhdr ihhoqeenucggtffrrghtthgvrhhnpeeiueffuedvieeujefhheeigfekvedujeejjeffve dvhedtudefiefhkeegueehleenucfkphepudeifedruddugedrudefvddrfeenucevlhhu shhtvghrufhiiigvpedvnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhrihhssegsuh hrrdhioh X-ME-Proxy: Received: from localhost (unknown [163.114.132.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 9F73B3280064; Wed, 18 Nov 2020 18:06:52 -0500 (EST) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v7 04/12] btrfs: create free space tree on ro->rw remount Date: Wed, 18 Nov 2020 15:06:19 -0800 Message-Id: <464597922f2cb83486301a2ba6767cfbb9959c7e.1605736355.git.boris@bur.io> X-Mailer: git-send-email 2.24.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org When a user attempts to remount a btrfs filesystem with 'mount -o remount,space_cache=v2', that operation silently succeeds. Unfortunately, this is misleading, because the remount does not create the free space tree. /proc/mounts will incorrectly show space_cache=v2, but on the next mount, the file system will revert to the old space_cache. For now, we handle only the easier case, where the existing mount is read-only and the new mount is read-write. In that case, we can create the free space tree without contending with the block groups changing as we go. Signed-off-by: Boris Burkov --- fs/btrfs/disk-io.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 2cf81a4e9393..d934eb80ff49 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2912,6 +2912,17 @@ int btrfs_mount_rw(struct btrfs_fs_info *fs_info) goto out; } + if (btrfs_test_opt(fs_info, FREE_SPACE_TREE) && + !btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) { + btrfs_info(fs_info, "creating free space tree"); + ret = btrfs_create_free_space_tree(fs_info); + if (ret) { + btrfs_warn(fs_info, + "failed to create free space tree: %d", ret); + goto out; + } + } + ret = btrfs_resume_balance_async(fs_info); if (ret) goto out; @@ -3376,18 +3387,6 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device } } - if (btrfs_test_opt(fs_info, FREE_SPACE_TREE) && - !btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) { - btrfs_info(fs_info, "creating free space tree"); - ret = btrfs_create_free_space_tree(fs_info); - if (ret) { - btrfs_warn(fs_info, - "failed to create free space tree: %d", ret); - close_ctree(fs_info); - return ret; - } - } - ret = btrfs_mount_rw(fs_info); if (ret) { close_ctree(fs_info); From patchwork Wed Nov 18 23:06:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11916099 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A5D9C5519F for ; Wed, 18 Nov 2020 23:07:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 98E3422255 for ; Wed, 18 Nov 2020 23:07:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="UMck/pJ9"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="K7QkvRyj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726980AbgKRXGk (ORCPT ); Wed, 18 Nov 2020 18:06:40 -0500 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:35673 "EHLO wout2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726588AbgKRXGk (ORCPT ); Wed, 18 Nov 2020 18:06:40 -0500 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id C874BCB5; Wed, 18 Nov 2020 18:06:56 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 18 Nov 2020 18:06:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=from :to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=fm2; bh=vhVcxxwmfjNgml4dzNX+QcGySM Ko/A8gDuCO0MGFTbg=; b=UMck/pJ9Fq8Fu/3nF0GgQZ3ldENtJEgK+FmR3LisN8 NEBjiJoK3G9tC9fsa1sEX53o2rIrNI+Z9bRXQtaQcmVuIFJsEk7VO0rWdKO2/pMn 2kH1kx030zva2dx+89jjLcmjXmHhEDWvDeSnku+WglQ0RHfVBfqU59F2Guw3TUzm 9JWxWy4F8jFL5eiGn9pk384jDZuFRasSorTgiBCGyWECCeJViQyt6MLbgRV9OFKt OI3O7Wcw8WuCrYuh8k2Nwr0uJ1ZFny7BztzfoiVZWaoiVrdJsPpv+abv8s2yAeX8 o9/JjxSlsv5WlYLWN90OsnXC1wNs2xC0EbMk9woiEN0A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=vhVcxxwmfjNgml4dzNX+QcGySMKo/A8gDuCO0MGFTbg=; b=K7QkvRyj Jqopm+8pF1/yRBHGggG74xND83ODJB17ADmc7TNEGgKrCozH18EawfYg0WtdYW3A nveVeqkSw7kYO59zkibGrRs5Y1J9m8SGBs6IoiRLQbcSr0QrIQIYNndmZvzo5VMl CCFIpOwjAflmIFkzaV6PxNMN8t0EBTpfMeLnlWLJdueUOTPVy8KDAIshipVy97rt lL6FS7witvWx42p2B8jcg/b4HgXOoe4cfUicZ4WEeP93A1veEtPBMEiCGd08VCPC o+H4KdVp8YFmXSqFazrbeOhFTvhrLEI7yKkM1u/c5jHVoGvazkUUhat0PNiLFYYA fEljgzb4aScnqw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudefiedgtdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepuehorhhishcuuehurhhkohhvuceosghorhhishessghurhdr ihhoqeenucggtffrrghtthgvrhhnpeeiueffuedvieeujefhheeigfekvedujeejjeffve dvhedtudefiefhkeegueehleenucfkphepudeifedruddugedrudefvddrfeenucevlhhu shhtvghrufhiiigvpeegnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhrihhssegsuh hrrdhioh X-ME-Proxy: Received: from localhost (unknown [163.114.132.3]) by mail.messagingengine.com (Postfix) with ESMTPA id EA330328006A; Wed, 18 Nov 2020 18:06:55 -0500 (EST) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v7 05/12] btrfs: clear oneshot options on mount and remount Date: Wed, 18 Nov 2020 15:06:20 -0800 Message-Id: <9c564def626db6d0de5ce0fc336aad4475050821.1605736355.git.boris@bur.io> X-Mailer: git-send-email 2.24.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Some options only apply during mount time and are cleared at the end of mount. For now, the example is USEBACKUPROOT, but CLEAR_CACHE also fits the bill, and this is a preparation patch for also clearing that option. One subtlety is that the current code only resets USEBACKUPROOT on rw mounts, but the option is meaningfully "consumed" by a ro mount, so it feels appropriate to clear in that case as well. A subsequent read-write remount would not go through open_ctree, which is the only place that checks the option, so the change should be benign. Signed-off-by: Boris Burkov --- fs/btrfs/disk-io.c | 14 +++++++++++++- fs/btrfs/disk-io.h | 1 + fs/btrfs/super.c | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index d934eb80ff49..0bc7d9766f8c 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2884,6 +2884,16 @@ static int btrfs_check_uuid_tree(struct btrfs_fs_info *fs_info) return 0; } +/* + * Some options only have meaning at mount time and shouldn't persist across + * remounts, or be displayed. Clear these at the end of mount and remount + * code paths. + */ +void btrfs_clear_oneshot_options(struct btrfs_fs_info *fs_info) +{ + btrfs_clear_opt(fs_info->mount_opt, USEBACKUPROOT); +} + /* * Mounting logic specific to read-write file systems. Shared by open_ctree * and btrfs_remount when remounting from read-only to read-write. @@ -3365,7 +3375,7 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device } if (sb_rdonly(sb)) - return 0; + goto clear_oneshot; if (btrfs_test_opt(fs_info, CLEAR_CACHE) && btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) { @@ -3409,6 +3419,8 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device } set_bit(BTRFS_FS_OPEN, &fs_info->flags); +clear_oneshot: + btrfs_clear_oneshot_options(fs_info); return 0; fail_qgroup: diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h index 945914d1747f..3bb097f22314 100644 --- a/fs/btrfs/disk-io.h +++ b/fs/btrfs/disk-io.h @@ -50,6 +50,7 @@ struct extent_buffer *btrfs_find_create_tree_block( u64 bytenr, u64 owner_root, int level); void btrfs_clean_tree_block(struct extent_buffer *buf); +void btrfs_clear_oneshot_options(struct btrfs_fs_info *fs_info); int btrfs_mount_rw(struct btrfs_fs_info *fs_info); int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_devices, diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index ad5a78970389..cca00cc0c98c 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1992,6 +1992,7 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data) wake_up_process(fs_info->transaction_kthread); btrfs_remount_cleanup(fs_info, old_opts); + btrfs_clear_oneshot_options(fs_info); clear_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state); return 0; From patchwork Wed Nov 18 23:06:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11916101 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5AE36C63697 for ; Wed, 18 Nov 2020 23:07:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E884A246A6 for ; Wed, 18 Nov 2020 23:07:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="UzhqsQGx"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="gLxCX4XE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727005AbgKRXGo (ORCPT ); Wed, 18 Nov 2020 18:06:44 -0500 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:56973 "EHLO wout2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726588AbgKRXGn (ORCPT ); Wed, 18 Nov 2020 18:06:43 -0500 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id 0DC60CB5; Wed, 18 Nov 2020 18:06:59 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 18 Nov 2020 18:07:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=from :to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=fm2; bh=22bWksDngmEiwuMGGZH21wlh00 t8TNXXR/BVrt/ldJc=; b=UzhqsQGx7JioGgFag2/rsaLPwKCZ1V/yas1pUOWb6H u4bF1x+n/Wt4vaHTF1Z4ExhfuxSQoiE+1skRuedwLRbwPMvygUwCA0EdTpZ3p28X k3wFlbHXy2M40WZJdpYEgI2wim/xx9Olp4X9mdttALW7Aw04V+R6Uw3R9XIJHwIm Vxf48Zzw5b0UeLCjHoVGphjL1OTokx1S01KFQw8rfiGSICAWLvGl8mIw5vHCPeQg k9VIsJBjqAeLQ05ulTvfW6mF+G7E9zquO4e/O9x0hb9JfUqiJe6O4l2KpkII/8/O 9J6n4+gnGEpH1Qf2C2y8dJV9pSWi7ca5xdlGqju0/Zpw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=22bWksDngmEiwuMGGZH21wlh00t8TNXXR/BVrt/ldJc=; b=gLxCX4XE 1k518+azOHmqJdhdhhd7UC2bOomLtqZ8VIPlz7CU20uC4tLk8u+w5lGlHznhsXDc ktSS5qmmYSXtMZ+lybxcyzlBkrFHLClZAmZQIzEYltkAx+UzfqBtzbO0EvHdOE11 Fy0l0hLstPWnwtso3ScOZFh+t84+enuqJ3tKE92rnFFm8YCMYWsWCLfMPUQ5yiDC pUtp6IhsjVRBbcKDFVUUSc2SppjhNWLT1o4cGQ6QF9cgbIUIwphe1/SrdE4NnoIE eToa5I0BZkQoRKiENKwy5cfYbWs8I4M72y2VHd39F4q7geecqTZ+VD+1KPGKwoDs Tfn6cqHHyNrb0A== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudefiedgtdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepuehorhhishcuuehurhhkohhvuceosghorhhishessghurhdr ihhoqeenucggtffrrghtthgvrhhnpeeiueffuedvieeujefhheeigfekvedujeejjeffve dvhedtudefiefhkeegueehleenucfkphepudeifedruddugedrudefvddrfeenucevlhhu shhtvghrufhiiigvpeegnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhrihhssegsuh hrrdhioh X-ME-Proxy: Received: from localhost (unknown [163.114.132.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 370D03280060; Wed, 18 Nov 2020 18:06:59 -0500 (EST) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v7 06/12] btrfs: clear free space tree on ro->rw remount Date: Wed, 18 Nov 2020 15:06:21 -0800 Message-Id: X-Mailer: git-send-email 2.24.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org A user might want to revert to v1 or nospace_cache on a root filesystem, and much like turning on the free space tree, that can only be done remounting from ro->rw. Support clearing the free space tree on such mounts by moving it into the shared remount logic. Since the CLEAR_CACHE option sticks around across remounts, this change would result in clearing the tree for ever on every remount, which is not desirable. To fix that, add CLEAR_CACHE to the oneshot options we clear at mount end, which has the other bonus of not cluttering the /proc/mounts output with clear_cache. Signed-off-by: Boris Burkov --- fs/btrfs/disk-io.c | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 0bc7d9766f8c..64e5707f008b 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2892,6 +2892,7 @@ static int btrfs_check_uuid_tree(struct btrfs_fs_info *fs_info) void btrfs_clear_oneshot_options(struct btrfs_fs_info *fs_info) { btrfs_clear_opt(fs_info->mount_opt, USEBACKUPROOT); + btrfs_clear_opt(fs_info->mount_opt, CLEAR_CACHE); } /* @@ -2901,6 +2902,27 @@ void btrfs_clear_oneshot_options(struct btrfs_fs_info *fs_info) int btrfs_mount_rw(struct btrfs_fs_info *fs_info) { int ret; + bool clear_free_space_tree = false; + + if (btrfs_test_opt(fs_info, CLEAR_CACHE) && + btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) { + clear_free_space_tree = true; + } else if (btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE) && + !btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE_VALID)) { + btrfs_warn(fs_info, "free space tree is invalid"); + clear_free_space_tree = true; + } + + if (clear_free_space_tree) { + btrfs_info(fs_info, "clearing free space tree"); + ret = btrfs_clear_free_space_tree(fs_info); + if (ret) { + btrfs_warn(fs_info, + "failed to clear free space tree: %d", ret); + close_ctree(fs_info); + return ret; + } + } ret = btrfs_cleanup_fs_roots(fs_info); if (ret) @@ -2975,7 +2997,6 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device struct btrfs_root *chunk_root; int ret; int err = -EINVAL; - int clear_free_space_tree = 0; int level; ret = init_mount_fs_info(fs_info, sb); @@ -3377,26 +3398,6 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device if (sb_rdonly(sb)) goto clear_oneshot; - if (btrfs_test_opt(fs_info, CLEAR_CACHE) && - btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) { - clear_free_space_tree = 1; - } else if (btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE) && - !btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE_VALID)) { - btrfs_warn(fs_info, "free space tree is invalid"); - clear_free_space_tree = 1; - } - - if (clear_free_space_tree) { - btrfs_info(fs_info, "clearing free space tree"); - ret = btrfs_clear_free_space_tree(fs_info); - if (ret) { - btrfs_warn(fs_info, - "failed to clear free space tree: %d", ret); - close_ctree(fs_info); - return ret; - } - } - ret = btrfs_mount_rw(fs_info); if (ret) { close_ctree(fs_info); From patchwork Wed Nov 18 23:06:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11916107 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B70E5C63798 for ; Wed, 18 Nov 2020 23:07:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D9FC22255 for ; Wed, 18 Nov 2020 23:07:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="U4mmKK1M"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="p5gvfLQ3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727011AbgKRXGr (ORCPT ); Wed, 18 Nov 2020 18:06:47 -0500 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:47931 "EHLO wout2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726588AbgKRXGr (ORCPT ); Wed, 18 Nov 2020 18:06:47 -0500 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id 88710C26; Wed, 18 Nov 2020 18:07:03 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 18 Nov 2020 18:07:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=from :to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=fm2; bh=NtYMKEr1oTPdgO9zfRrUA1bso9 gwh9bSN2J2t4mN214=; b=U4mmKK1MAtLuHjNn6vmNx8jQhaGfDCB4QW1tRk7pxH +8Fj+HmjBfHGij3SHcTkx0NT17Yp/DwHjwk6WMh7sQVvwo64FMXttm7fXFhvgsrj wqH/ln78vjPXWsWlfoe99mcHt9o3YmLyj9SbynsXlN7h8kbyRVj7xi/8rL8s3lwN Fei3gDHm46YxtW0T2DELat6G2mN6uaB8eD5t1FKO5v4p8fgoXQfgOpb/Toy6Wy+O E1j4EgYRmP5zSoOMcUM5k6xKIOD6eCWxCvWXqsx2FRTiVgPF/H45qCFISbItFgQw VqXqyLUEhVZkwaAF8mgTXUPk91MEolCw94f6oxliI6Nw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=NtYMKEr1oTPdgO9zfRrUA1bso9gwh9bSN2J2t4mN214=; b=p5gvfLQ3 hPREmumtAfUx34VHbj0yt8y0zOUyxNIJX7ubRa9dj1N60QXRHmuX3/kOcEitlz6V hGCA4zMHzJAk5Um3zhW+t6xpu79B5WFja5RGy+RoLycFP932EyTzPlnswEwhuWbE I+6pK5v55bnp0Oq1SaXDRAGDX9SXOdZB8qK+P/6q39PFt/mS8Ga7Rz5UY82cu1uL +hAVexv//zPaXr+hyvHNCnREPriI+1dGOYWVmT6mhtH2/sTX/pVHpUHV//Vb6OBC RgNAJhCzjZJ73JugwnnUMK5RJT7kQqJnxIjPH6ZQIktRngFIvc+gHLgHl8zzql9b fG+BdMHSu0/wiQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudefiedgtdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepuehorhhishcuuehurhhkohhvuceosghorhhishessghurhdr ihhoqeenucggtffrrghtthgvrhhnpeeiueffuedvieeujefhheeigfekvedujeejjeffve dvhedtudefiefhkeegueehleenucfkphepudeifedruddugedrudefvddrfeenucevlhhu shhtvghrufhiiigvpeeinecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhrihhssegsuh hrrdhioh X-ME-Proxy: Received: from localhost (unknown [163.114.132.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 7E576328005E; Wed, 18 Nov 2020 18:07:02 -0500 (EST) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v7 07/12] btrfs: keep sb cache_generation consistent with space_cache Date: Wed, 18 Nov 2020 15:06:22 -0800 Message-Id: <0f6e0287a267344f285cc458919e1c5595dfd26d.1605736355.git.boris@bur.io> X-Mailer: git-send-email 2.24.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org When mounting, btrfs uses the cache_generation in the super block to determine if space cache v1 is in use. However, by mounting with nospace_cache or space_cache=v2, it is possible to disable space cache v1, which does not result in un-setting cache_generation back to 0. In order to base some logic, like mount option printing in /proc/mounts, on the current state of the space cache rather than just the values of the mount option, keep the value of cache_generation consistent with the status of space cache v1. We ensure that cache_generation > 0 iff the file system is using space_cache v1. This requires committing a transaction on any mount which changes whether we are using v1. (v1->nospace_cache, v1->v2, nospace_cache->v1, v2->v1). Since the mechanism for writing out the cache generation is transaction commit, but we want some finer grained control over when we un-set it, we can't just rely on the SPACE_CACHE mount option, and introduce an fs_info flag that mount can use when it wants to unset the generation. Signed-off-by: Boris Burkov --- fs/btrfs/ctree.h | 3 +++ fs/btrfs/disk-io.c | 8 ++++++++ fs/btrfs/free-space-cache.c | 28 ++++++++++++++++++++++++++++ fs/btrfs/free-space-cache.h | 3 +++ fs/btrfs/super.c | 10 +++++++--- fs/btrfs/transaction.c | 2 ++ 6 files changed, 51 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index cb90a870b235..318303f53529 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -559,6 +559,9 @@ enum { /* Indicate that the discard workqueue can service discards. */ BTRFS_FS_DISCARD_RUNNING, + + /* Indicate that we need to cleanup space cache v1 */ + BTRFS_FS_CLEANUP_SPACE_CACHE_V1, }; /* diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 64e5707f008b..fea467c421e7 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2902,6 +2902,7 @@ void btrfs_clear_oneshot_options(struct btrfs_fs_info *fs_info) int btrfs_mount_rw(struct btrfs_fs_info *fs_info) { int ret; + bool cache_opt = btrfs_test_opt(fs_info, SPACE_CACHE); bool clear_free_space_tree = false; if (btrfs_test_opt(fs_info, CLEAR_CACHE) && @@ -2955,6 +2956,12 @@ int btrfs_mount_rw(struct btrfs_fs_info *fs_info) } } + if (cache_opt != btrfs_free_space_cache_v1_active(fs_info)) { + ret = btrfs_set_free_space_cache_v1_active(fs_info, cache_opt); + if (ret) + goto out; + } + ret = btrfs_resume_balance_async(fs_info); if (ret) goto out; @@ -3418,6 +3425,7 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device return ret; } } + set_bit(BTRFS_FS_OPEN, &fs_info->flags); clear_oneshot: diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 572c75d2169b..48f7bd050909 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -3971,6 +3971,34 @@ int btrfs_write_out_ino_cache(struct btrfs_root *root, return ret; } +bool btrfs_free_space_cache_v1_active(struct btrfs_fs_info *fs_info) +{ + return btrfs_super_cache_generation(fs_info->super_copy); +} + +int btrfs_set_free_space_cache_v1_active(struct btrfs_fs_info *fs_info, + bool active) +{ + struct btrfs_trans_handle *trans; + int ret; + + /* + * update_super_roots will appropriately set + * fs_info->super_copy->cache_generation based on the SPACE_CACHE + * option, so all we have to do is trigger a transaction commit. + */ + trans = btrfs_start_transaction(fs_info->tree_root, 0); + if (IS_ERR(trans)) + return PTR_ERR(trans); + + if (!active) + set_bit(BTRFS_FS_CLEANUP_SPACE_CACHE_V1, &fs_info->flags); + + ret = btrfs_commit_transaction(trans); + clear_bit(BTRFS_FS_CLEANUP_SPACE_CACHE_V1, &fs_info->flags); + return ret; +} + #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS /* * Use this if you need to make a bitmap or extent entry specifically, it diff --git a/fs/btrfs/free-space-cache.h b/fs/btrfs/free-space-cache.h index bf8d127d2407..8f4bc5781cd3 100644 --- a/fs/btrfs/free-space-cache.h +++ b/fs/btrfs/free-space-cache.h @@ -149,6 +149,9 @@ int btrfs_trim_block_group_bitmaps(struct btrfs_block_group *block_group, u64 *trimmed, u64 start, u64 end, u64 minlen, u64 maxlen, bool async); +bool btrfs_free_space_cache_v1_active(struct btrfs_fs_info *fs_info); +int btrfs_set_free_space_cache_v1_active(struct btrfs_fs_info *fs_info, + bool active); /* Support functions for running our sanity tests */ #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS int test_add_free_space_entry(struct btrfs_block_group *cache, diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index cca00cc0c98c..ff19f900cee1 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -547,7 +547,6 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options, { substring_t args[MAX_OPT_ARGS]; char *p, *num; - u64 cache_gen; int intarg; int ret = 0; char *compress_type; @@ -557,10 +556,9 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options, bool saved_compress_force; int no_compress = 0; - cache_gen = btrfs_super_cache_generation(info->super_copy); if (btrfs_fs_compat_ro(info, FREE_SPACE_TREE)) btrfs_set_opt(info->mount_opt, FREE_SPACE_TREE); - else if (cache_gen) + else if (btrfs_free_space_cache_v1_active(info)) btrfs_set_opt(info->mount_opt, SPACE_CACHE); /* @@ -1857,6 +1855,8 @@ static inline void btrfs_remount_begin(struct btrfs_fs_info *fs_info, static inline void btrfs_remount_cleanup(struct btrfs_fs_info *fs_info, unsigned long old_opts) { + bool cache_opt = btrfs_test_opt(fs_info, SPACE_CACHE); + /* * We need to cleanup all defragable inodes if the autodefragment is * close or the filesystem is read only. @@ -1873,6 +1873,10 @@ static inline void btrfs_remount_cleanup(struct btrfs_fs_info *fs_info, else if (btrfs_raw_test_opt(old_opts, DISCARD_ASYNC) && !btrfs_test_opt(fs_info, DISCARD_ASYNC)) btrfs_discard_cleanup(fs_info); + + /* If we toggled space cache */ + if (cache_opt != btrfs_free_space_cache_v1_active(fs_info)) + btrfs_set_free_space_cache_v1_active(fs_info, cache_opt); } static int btrfs_remount(struct super_block *sb, int *flags, char *data) diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 0e4063651047..43253b9996c3 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -1801,6 +1801,8 @@ static void update_super_roots(struct btrfs_fs_info *fs_info) super->root_level = root_item->level; if (btrfs_test_opt(fs_info, SPACE_CACHE)) super->cache_generation = root_item->generation; + else if (test_bit(BTRFS_FS_CLEANUP_SPACE_CACHE_V1, &fs_info->flags)) + super->cache_generation = 0; if (test_bit(BTRFS_FS_UPDATE_UUID_TREE_GEN, &fs_info->flags)) super->uuid_tree_generation = root_item->generation; } From patchwork Wed Nov 18 23:06:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11916105 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07143C6379D for ; Wed, 18 Nov 2020 23:07:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 98BCA246A6 for ; Wed, 18 Nov 2020 23:07:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="dJ3h+4e1"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="WrTiZGkB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727019AbgKRXGu (ORCPT ); Wed, 18 Nov 2020 18:06:50 -0500 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:51319 "EHLO wout2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726588AbgKRXGu (ORCPT ); Wed, 18 Nov 2020 18:06:50 -0500 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id 87402CE3; Wed, 18 Nov 2020 18:07:06 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 18 Nov 2020 18:07:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=from :to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=fm2; bh=qhJNwfFO32uVvXe17S26UzeX38 a8eFRmWBBGcLmUESc=; b=dJ3h+4e1WQLVbnJpzrnhLLQwp0yWYVmL6Jq8/Ng8Zs 3WMx52qAUT/O6dU5SxxH/gii4n26t77tpSPnryFXFTmEXptkx/b9bZlU1J1CYjVw MPZpUxixw98UOevdGhtoCgTaZSwF/I39jqIfo7rgv0GVOoSLNwM2QuSThNGnyPwn ln2RFxwSYi/16dWp2rXIedohxHJ/0qDLpBo2SGUD4DwXWDBvAi9P+L/wXPK4kpvY DvOsTz5T7mKEH0CY7+f52jIIobJ1zu8m2bCgjCI2SO1a2VCW9OrHiucAkWH9CcZ4 ZO3NkUUez+uIYmmYtBbWMwVbcilRxx9ugSh/AM57RsmA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=qhJNwfFO32uVvXe17S26UzeX38a8eFRmWBBGcLmUESc=; b=WrTiZGkB LALnBhSyY70v31uJIeEVZov0t9WShqo383ym2b7S9GZuV9FN9ytgfksDC77yyi9e HYlDiczKlC53q6EDAX0ZSIgHrq70WvtfDl2TNOTxKBTecYQeUDMzokiWSlOnI839 LXAw1dAokRsWiWHqTSR00EPhaksYEAqgMfvZCs5U11x7iOn3s3W/IdGpPoebVK91 4cugMFpEbpDb2DDS5zleFHmUFHgFOcDgAPqNwFJayCijoaOW7Of8doCf5M+jjRa/ Rasg7ub04+pqFBHfnUHmeyPDC+/PVSJJgjP5hKh2g/cpPhMouL7bC38OyShMQnUm 7VK0hz/LnvDjEA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudefiedgtdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepuehorhhishcuuehurhhkohhvuceosghorhhishessghurhdr ihhoqeenucggtffrrghtthgvrhhnpeeiueffuedvieeujefhheeigfekvedujeejjeffve dvhedtudefiefhkeegueehleenucfkphepudeifedruddugedrudefvddrfeenucevlhhu shhtvghrufhiiigvpeejnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhrihhssegsuh hrrdhioh X-ME-Proxy: Received: from localhost (unknown [163.114.132.3]) by mail.messagingengine.com (Postfix) with ESMTPA id B261D328005E; Wed, 18 Nov 2020 18:07:05 -0500 (EST) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v7 08/12] btrfs: use sb state to print space_cache mount option Date: Wed, 18 Nov 2020 15:06:23 -0800 Message-Id: X-Mailer: git-send-email 2.24.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org To make the contents of /proc/mounts better match the actual state of the file system, base the display of the space cache mount options off the contents of the super block rather than the last mount options passed in. Since there are many scenarios where the mount will ignore a space cache option, simply showing the passed in option is misleading. For example, if we mount with -o remount,space_cache=v2 on a read-write file system without an existing free space tree, we won't build a free space tree, but /proc/mounts will read space_cache=v2 (until we mount again and it goes away) cache_generation is set iff space_cache=v1, FREE_SPACE_TREE is set iff space_cache=v2, and if neither is the case, we print nospace_cache. Signed-off-by: Boris Burkov --- fs/btrfs/super.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index ff19f900cee1..e2a186d254c5 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1474,9 +1474,9 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry) seq_puts(seq, ",discard=async"); if (!(info->sb->s_flags & SB_POSIXACL)) seq_puts(seq, ",noacl"); - if (btrfs_test_opt(info, SPACE_CACHE)) + if (btrfs_free_space_cache_v1_active(info)) seq_puts(seq, ",space_cache"); - else if (btrfs_test_opt(info, FREE_SPACE_TREE)) + else if (btrfs_fs_compat_ro(info, FREE_SPACE_TREE)) seq_puts(seq, ",space_cache=v2"); else seq_puts(seq, ",nospace_cache"); From patchwork Wed Nov 18 23:06:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11916103 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4BC12C56201 for ; Wed, 18 Nov 2020 23:07:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DDC6E22255 for ; Wed, 18 Nov 2020 23:07:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="WmMzrg+s"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Grmx5KY9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727037AbgKRXGx (ORCPT ); Wed, 18 Nov 2020 18:06:53 -0500 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:41881 "EHLO wout2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726588AbgKRXGx (ORCPT ); Wed, 18 Nov 2020 18:06:53 -0500 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id D04ECC14; Wed, 18 Nov 2020 18:07:09 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 18 Nov 2020 18:07:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=from :to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=fm2; bh=MzggpLdY8RnPEsI+gBYMirfU1Z u3DTsymQjSMD4EBZ8=; b=WmMzrg+sDBP3P1j3pUj0P6SYKLhRFj7BUSr8ankf/q uDmxX1+bez3wKvzOOoi2qqURfpN1eEVFUH5XWfjE1eLqndfMYiagPrVC8DQBp20t Vrwppz3SwROW0yYSjb+RRejmwKU9QZyohDvSEM9srQCpUyubvY2KDgtcOi4qeu4o fz2bSgRWuphk8bxRfNYxPdPee+fWHkt3Oj+H+b7DLmn3l1H/Pai7pUvHu2xhqvzd Z4GojqXQ5M/+Lz+KjkO9RUjdUcDNXcOwhpmQ4baMFUMPh5AF6l1gIgCh7KWYPz8E XI1/CMLzQ/aaXEVZfsmtOpQ2GZcN/PYz1DZfzTACQYqg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=MzggpLdY8RnPEsI+gBYMirfU1Zu3DTsymQjSMD4EBZ8=; b=Grmx5KY9 svVuIlPohVbZd7jy5jTi6RX9j7uOUsyLrNZnCu/SlsCrnCQ/wBPCbNWddudiZQJg 5Ft9TTUK/MgDOzGhHOWrAc3iOyqR8NUyRmNqCtCM9ukQeUaRZsHjEkuEpExgntrg vyY/UPiGhlLbSRv3rVbWqLOMpHasI+N8t5oaluahBc5SmXzHiSbhEphvVzHl+gNW HsyXoiRXgjG6OCgtP0+d1o52mHx8ch6c3Na1d+bkubhLkWXCJZlfCU4TxG481/Xu x27UIEXnMbSZtu/c7VzdryzOuEmO0/zs9xb816cHUd8Fj1R4AcoTHhfh3tKmTSmI LPfNO03Po2xhmg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudefiedgtdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepuehorhhishcuuehurhhkohhvuceosghorhhishessghurhdr ihhoqeenucggtffrrghtthgvrhhnpeeiueffuedvieeujefhheeigfekvedujeejjeffve dvhedtudefiefhkeegueehleenucfkphepudeifedruddugedrudefvddrfeenucevlhhu shhtvghrufhiiigvpeejnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhrihhssegsuh hrrdhioh X-ME-Proxy: Received: from localhost (unknown [163.114.132.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 039463280064; Wed, 18 Nov 2020 18:07:09 -0500 (EST) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v7 09/12] btrfs: warn when remount will not change the free space tree Date: Wed, 18 Nov 2020 15:06:24 -0800 Message-Id: <582a98333502e807faa9a899082e6e960e4cc0f3.1605736355.git.boris@bur.io> X-Mailer: git-send-email 2.24.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org If the remount is ro->ro, rw->ro, or rw->rw, we will not create or clear the free space tree. This can be surprising, so print a warning to dmesg to make the failure more visible. It is also important to ensure that the space cache options (SPACE_CACHE, FREE_SPACE_TREE) are consistent, so ensure those are set to properly match the current on disk state (which won't be changing). Signed-off-by: Boris Burkov --- fs/btrfs/super.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index e2a186d254c5..5e88ae69e2e6 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1912,6 +1912,24 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data) btrfs_resize_thread_pool(fs_info, fs_info->thread_pool_size, old_thread_pool_size); + if (btrfs_test_opt(fs_info, FREE_SPACE_TREE) != + btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE) && + ((!sb_rdonly(sb) || *flags & SB_RDONLY))) { + btrfs_warn(fs_info, + "remount supports changing free space tree only from ro to rw"); + /* + * Make sure free space cache options match the state on disk + */ + if (btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) { + btrfs_set_opt(fs_info->mount_opt, FREE_SPACE_TREE); + btrfs_clear_opt(fs_info->mount_opt, SPACE_CACHE); + } + if (btrfs_free_space_cache_v1_active(fs_info)) { + btrfs_clear_opt(fs_info->mount_opt, FREE_SPACE_TREE); + btrfs_set_opt(fs_info->mount_opt, SPACE_CACHE); + } + } + if ((bool)(*flags & SB_RDONLY) == sb_rdonly(sb)) goto out; From patchwork Wed Nov 18 23:06:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11916111 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-23.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27103C64E69 for ; Wed, 18 Nov 2020 23:07:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B4219246A6 for ; Wed, 18 Nov 2020 23:07:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="eTrimpn+"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="mNYHFZXZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727120AbgKRXG7 (ORCPT ); Wed, 18 Nov 2020 18:06:59 -0500 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:52779 "EHLO wout2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727042AbgKRXG5 (ORCPT ); Wed, 18 Nov 2020 18:06:57 -0500 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id 4861DCCF; Wed, 18 Nov 2020 18:07:13 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 18 Nov 2020 18:07:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=from :to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=fm2; bh=1o6QIIFowAbaK9KlSPMxqGQ6al F6w8UAzLsxKO7iqNE=; b=eTrimpn+bsKEsbCo7fpGqpUXUNjbcCWRdvLqMqrkAu eCi5zhNdQfj+2qFE/qQpSmFOEJ9tnJ1PO5Wm9CHVqthDejsWWHPCR2lst6SbJnUs Bbd47h6wIv2C15joqub29HM3RVNmMqqvJPf/lw6UcfB2CteBB9gNONpZisVv7nKZ wzkaOYhSxyZXiigtyzAK7wyXzpyReLUPCj5hxurlUZJN8wM+ODGUZ0JmA+BND8CT 9l30pz0B/eqUZHm+ho0U8G84GEbtzEP7iFwj8tEGIOx+YOKcKxviN1JYmXdWZ2FC TPnNQi7UwYC2WcYS5lnPHJOyVHjgPjFnIQQlK77q827w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=1o6QIIFowAbaK9KlSPMxqGQ6alF6w8UAzLsxKO7iqNE=; b=mNYHFZXZ JUduRE3uh8lcvvjIrU3QH8LyFNc5hDHV41W5hTPbdLYiPNqDcQUnQTUjxu9Akqln SPNokWu5wNAtSusH2KRXnpj+mFwwkCTX/E32mrtbt0DLND2U4tLwIifFMXO4lozI hCEGORPJNZsg89hyxiIuWy2XlfX74ZeUPLcufbd7nM9dXhz6whqNO/d/LQiyr3k8 2c44nLC3Wb4m227aw2/TsWWCiffvE5o0OlMqOh5ipBw9UXi7uj3thZx5WgIzcY1W XBDgXk6gzeZ+GQAjDkzYRBIgK+5xezQoWr0CgU9F3t1/PoqVMB5Ui9NIbkziSZ+0 HHrxrwN3mCKWAA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudefiedgtdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepuehorhhishcuuehurhhkohhvuceosghorhhishessghurhdr ihhoqeenucggtffrrghtthgvrhhnpeetheehudfgleelhfehffettedtfeelvdfghfelke efgefgvdevgefffedvtdefgeenucffohhmrghinhepghhithhhuhgsrdgtohhmnecukfhp peduieefrdduudegrddufedvrdefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrg hmpehmrghilhhfrhhomhepsghorhhishessghurhdrihho X-ME-Proxy: Received: from localhost (unknown [163.114.132.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 3FE0E328005E; Wed, 18 Nov 2020 18:07:12 -0500 (EST) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v7 10/12] btrfs: remove free space items when disabling space cache v1 Date: Wed, 18 Nov 2020 15:06:25 -0800 Message-Id: <09feedd57a06e703eee37d8f40c5e1829bfe36de.1605736355.git.boris@bur.io> X-Mailer: git-send-email 2.24.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org When the file system transitions from space cache v1 to v2 or to nospace_cache, it removes the old cached data, but does not remove the FREE_SPACE items nor the free space inodes they point to. This doesn't cause any issues besides being a bit inefficient, since these items no longer do anything useful. To fix it, when we are mounting, and plan to disable the space cache, destroy each block group's free space item and free space inode. The code to remove the items is lifted from the existing use case of removing the block group, with a light adaptation to handle whether or not we have already looked up the free space inode. References: https://github.com/btrfs/btrfs-todo/issues/5 Signed-off-by: Boris Burkov --- fs/btrfs/block-group.c | 39 +------------- fs/btrfs/free-space-cache.c | 101 ++++++++++++++++++++++++++++++++++-- fs/btrfs/free-space-cache.h | 3 ++ 3 files changed, 102 insertions(+), 41 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index 00e2fe1d0f32..d5104560dfc9 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -848,8 +848,6 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans, struct btrfs_path *path; struct btrfs_block_group *block_group; struct btrfs_free_cluster *cluster; - struct btrfs_root *tree_root = fs_info->tree_root; - struct btrfs_key key; struct inode *inode; struct kobject *kobj = NULL; int ret; @@ -927,42 +925,9 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans, spin_unlock(&trans->transaction->dirty_bgs_lock); mutex_unlock(&trans->transaction->cache_write_mutex); - if (!IS_ERR(inode)) { - ret = btrfs_orphan_add(trans, BTRFS_I(inode)); - if (ret) { - btrfs_add_delayed_iput(inode); - goto out; - } - clear_nlink(inode); - /* One for the block groups ref */ - spin_lock(&block_group->lock); - if (block_group->iref) { - block_group->iref = 0; - block_group->inode = NULL; - spin_unlock(&block_group->lock); - iput(inode); - } else { - spin_unlock(&block_group->lock); - } - /* One for our lookup ref */ - btrfs_add_delayed_iput(inode); - } - - key.objectid = BTRFS_FREE_SPACE_OBJECTID; - key.type = 0; - key.offset = block_group->start; - - ret = btrfs_search_slot(trans, tree_root, &key, path, -1, 1); - if (ret < 0) + ret = btrfs_remove_free_space_inode(trans, inode, block_group); + if (ret) goto out; - if (ret > 0) - btrfs_release_path(path); - if (ret == 0) { - ret = btrfs_del_item(trans, tree_root, path); - if (ret) - goto out; - btrfs_release_path(path); - } spin_lock(&fs_info->block_group_cache_lock); rb_erase(&block_group->cache_node, diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 48f7bd050909..3c226a436c7a 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -213,6 +213,65 @@ int create_free_space_inode(struct btrfs_trans_handle *trans, ino, block_group->start); } +/* + * inode is an optional sink: if it is NULL, btrfs_remove_free_space_inode + * handles lookup, otherwise it takes ownership and iputs the inode. + * Don't reuse an inode pointer after passing it into this function. + */ +int btrfs_remove_free_space_inode(struct btrfs_trans_handle *trans, + struct inode *inode, + struct btrfs_block_group *block_group) +{ + struct btrfs_path *path; + struct btrfs_key key; + int ret = 0; + + path = btrfs_alloc_path(); + if (!path) + return -ENOMEM; + + if (!inode) + inode = lookup_free_space_inode(block_group, path); + if (IS_ERR(inode)) { + if (PTR_ERR(inode) != -ENOENT) + ret = PTR_ERR(inode); + goto out; + } + ret = btrfs_orphan_add(trans, BTRFS_I(inode)); + if (ret) { + btrfs_add_delayed_iput(inode); + goto out; + } + clear_nlink(inode); + /* One for the block groups ref */ + spin_lock(&block_group->lock); + if (block_group->iref) { + block_group->iref = 0; + block_group->inode = NULL; + spin_unlock(&block_group->lock); + iput(inode); + } else { + spin_unlock(&block_group->lock); + } + /* One for the lookup ref */ + btrfs_add_delayed_iput(inode); + + key.objectid = BTRFS_FREE_SPACE_OBJECTID; + key.type = 0; + key.offset = block_group->start; + ret = btrfs_search_slot(trans, trans->fs_info->tree_root, &key, path, + -1, 1); + if (ret) { + if (ret > 0) + ret = 0; + goto out; + } + ret = btrfs_del_item(trans, trans->fs_info->tree_root, path); +out: + btrfs_free_path(path); + return ret; +} + int btrfs_check_trunc_cache_free_space(struct btrfs_fs_info *fs_info, struct btrfs_block_rsv *rsv) { @@ -3976,6 +4035,28 @@ bool btrfs_free_space_cache_v1_active(struct btrfs_fs_info *fs_info) return btrfs_super_cache_generation(fs_info->super_copy); } +static int cleanup_free_space_cache_v1(struct btrfs_fs_info *fs_info, + struct btrfs_trans_handle *trans) +{ + struct btrfs_block_group *block_group; + struct rb_node *node; + int ret; + + btrfs_info(fs_info, "cleaning free space cache v1"); + + node = rb_first(&fs_info->block_group_cache_tree); + while (node) { + block_group = rb_entry(node, struct btrfs_block_group, + cache_node); + ret = btrfs_remove_free_space_inode(trans, NULL, block_group); + if (ret) + goto out; + node = rb_next(node); + } +out: + return ret; +} + int btrfs_set_free_space_cache_v1_active(struct btrfs_fs_info *fs_info, bool active) { @@ -3983,18 +4064,30 @@ int btrfs_set_free_space_cache_v1_active(struct btrfs_fs_info *fs_info, int ret; /* - * update_super_roots will appropriately set - * fs_info->super_copy->cache_generation based on the SPACE_CACHE - * option, so all we have to do is trigger a transaction commit. + * update_super_roots will appropriately set or unset + * fs_info->super_copy->cache_generation based on SPACE_CACHE and + * BTRFS_FS_CLEANUP_SPACE_CACHE_V1. For this reason, we need a + * transaction commit whether we are enabling space cache v1 and don't + * have any other work to do, or are disabling it and removing free + * space inodes. */ trans = btrfs_start_transaction(fs_info->tree_root, 0); if (IS_ERR(trans)) return PTR_ERR(trans); - if (!active) + if (!active) { set_bit(BTRFS_FS_CLEANUP_SPACE_CACHE_V1, &fs_info->flags); + ret = cleanup_free_space_cache_v1(fs_info, trans); + if (ret) + goto abort; + } ret = btrfs_commit_transaction(trans); + goto out; +abort: + btrfs_abort_transaction(trans, ret); + btrfs_end_transaction(trans); +out: clear_bit(BTRFS_FS_CLEANUP_SPACE_CACHE_V1, &fs_info->flags); return ret; } diff --git a/fs/btrfs/free-space-cache.h b/fs/btrfs/free-space-cache.h index 8f4bc5781cd3..93522d22c195 100644 --- a/fs/btrfs/free-space-cache.h +++ b/fs/btrfs/free-space-cache.h @@ -84,6 +84,9 @@ struct inode *lookup_free_space_inode(struct btrfs_block_group *block_group, int create_free_space_inode(struct btrfs_trans_handle *trans, struct btrfs_block_group *block_group, struct btrfs_path *path); +int btrfs_remove_free_space_inode(struct btrfs_trans_handle *trans, + struct inode *inode, + struct btrfs_block_group *block_group); int btrfs_check_trunc_cache_free_space(struct btrfs_fs_info *fs_info, struct btrfs_block_rsv *rsv); From patchwork Wed Nov 18 23:06:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11916109 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F92AC64E7A for ; Wed, 18 Nov 2020 23:07:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0952222255 for ; Wed, 18 Nov 2020 23:07:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="aD8OZGLa"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Q658ZxnR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727136AbgKRXHA (ORCPT ); Wed, 18 Nov 2020 18:07:00 -0500 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:54197 "EHLO wout2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727042AbgKRXHA (ORCPT ); Wed, 18 Nov 2020 18:07:00 -0500 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id 7E2B6CBA; Wed, 18 Nov 2020 18:07:16 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 18 Nov 2020 18:07:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=from :to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=fm2; bh=nXVj75UA0RVNvHxdPgqbuB+m79 bB9FyBPUnsfg1PbRs=; b=aD8OZGLaQNsaLiqIt1QJUVZlTKdHT12budnWQQGH13 pON9XEnlljSztlGxYqnBFwPzSE3Azlm/yygVdj/xGBTIhcKUCz9ODoPofVqMtxvA DBLzrF+rdWrKz9DiU0nEdP3N66l+xsF/XnB667GWvstoGcmkhDYVMOKXOwgOzA0t /yFQ+wIRMr8UbIVOzEQKVzQtOtlRCW144lZF7WJPK6wERCd15gsqkXoLW1ph6r+F 6hMSZxu6V50HRaP5rRPc8o2fdVJlxQU4Noi7iOgOXQt63S5swgpNg1pyg42YeZ6a HopnYxXqnCxtaOxtwufVKWr/plWXnLGRP/cJ4rVZFNvA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=nXVj75UA0RVNvHxdPgqbuB+m79bB9FyBPUnsfg1PbRs=; b=Q658ZxnR HNjIPGkLnQbUDPQlx9sW7QAL0G3JOMkNRlv3AEjvzlf4o9h64JAmzLvlTo8XpGfV +TKV3aRabHmpbgJkCmOS4Xq7Ds+F3O6wNb3/7DgWLEPWW6YrupWa6pGoKys8z2db aGxTrxgjOhRuFXO1NQe97KwFp8xwGa44zEYNYMyDZ/2T8y4WxSiz6weekNjr3xO3 xbvBZSn8CuYlYf1fZo1jvF3Bq7DFnbnVHaW53XZ92EFZPCwK/gFKvYr/XDTbXbWA HP1hci3C/7c86Osc3Ikc4GdiMsF5G//xPz6DdPNzfQ2F94H5a7k43JGan8mbviXC 1XLxHQdwTtR5oQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudefiedgtdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepuehorhhishcuuehurhhkohhvuceosghorhhishessghurhdr ihhoqeenucggtffrrghtthgvrhhnpeeiueffuedvieeujefhheeigfekvedujeejjeffve dvhedtudefiefhkeegueehleenucfkphepudeifedruddugedrudefvddrfeenucevlhhu shhtvghrufhiiigvpeelnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhrihhssegsuh hrrdhioh X-ME-Proxy: Received: from localhost (unknown [163.114.132.3]) by mail.messagingengine.com (Postfix) with ESMTPA id AAC35328005E; Wed, 18 Nov 2020 18:07:15 -0500 (EST) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v7 11/12] btrfs: skip space_cache v1 setup when not using it Date: Wed, 18 Nov 2020 15:06:26 -0800 Message-Id: <4661fbae3fd777faae4ef2f50a41a2ab1842b65f.1605736355.git.boris@bur.io> X-Mailer: git-send-email 2.24.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org If we are not using space cache v1, we should not create the free space object or free space inodes. This comes up when we delete the existing free space objects/inodes when migrating to v2, only to see them get recreated for every dirtied block group. Signed-off-by: Boris Burkov --- fs/btrfs/block-group.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index d5104560dfc9..24e3eb13f173 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -2331,6 +2331,9 @@ static int cache_save_setup(struct btrfs_block_group *block_group, int retries = 0; int ret = 0; + if (!btrfs_test_opt(fs_info, SPACE_CACHE)) + return 0; + /* * If this block group is smaller than 100 megs don't bother caching the * block group. From patchwork Wed Nov 18 23:06:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11916113 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6673C5519F for ; Wed, 18 Nov 2020 23:07:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4EF97246A6 for ; Wed, 18 Nov 2020 23:07:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="nWyNt5fL"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Wn4xhwXx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727147AbgKRXHE (ORCPT ); Wed, 18 Nov 2020 18:07:04 -0500 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:57569 "EHLO wout2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726340AbgKRXHD (ORCPT ); Wed, 18 Nov 2020 18:07:03 -0500 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id D08C5CBC; Wed, 18 Nov 2020 18:07:19 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 18 Nov 2020 18:07:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=from :to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=fm2; bh=nQ6rnp9LrOP5BFhotjmfxHaPwJ mRNX5XSAuJBXGG6XQ=; b=nWyNt5fLnSZm4sNpTcVRsaotcahzSj0BSQXxmGZWcH t9hffuuQdCqgLfLaDCKKcLiFyM4Eed9a5j0VQS08aJSaxPouC0mpXOWJ0frpmpu0 jXXMHopretf3grKJdyR6sbi1+7ZujoT5D6vSn+E0M7Dj8kIrrV0IuzokXi+5Cb/0 QYeQnKgjZzUPMrbqMfA9mSBw0cz1b6A5s1WWRLGTqWzkGOofTCKZWKNV9dbPE26R OUGIAGJWsL5KWi2zHomnxOimOIkQt7tqYh0y1Zl5VvFJXfJiJ2LMTw1Wweipr0TX JxkBFsetj0tg2mL8Z9VHs6+9Vv1dCFn/lcMEBwRoJEtg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=nQ6rnp9LrOP5BFhotjmfxHaPwJmRNX5XSAuJBXGG6XQ=; b=Wn4xhwXx wHCTzZJvt1cK06/fC9fjKOdXg4MVOTHr2E5UHuvENnsNlhZC4E3bbvUmOYlBM0Yw A2V3ZWDqV9wOxapKm22XjTwyEZhDlA9bX7JWmYSqF0gTPmHjHLQOgMwLc2t0mqro bd5mUG+NkU/q3mcTdmgvbOBDRHsl1jAU/DGXgyF3vnu2WBOacTLtcmdLY3tCgm4M +0Fr+VP4hrlzaJn+WNZIOjJVYuXxUyGFRZtsQ9PnIJpkm53cP9gLDDy3A21apDNR 2Emld1RTPKDICe+nKg9/CpoQrZ6boQALcS4AQ3S+aKubwdbGc4QCVE2TWAQaSc+l 7jsYbO7mY3DbtQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudefiedgtdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepuehorhhishcuuehurhhkohhvuceosghorhhishessghurhdr ihhoqeenucggtffrrghtthgvrhhnpeeiueffuedvieeujefhheeigfekvedujeejjeffve dvhedtudefiefhkeegueehleenucfkphepudeifedruddugedrudefvddrfeenucevlhhu shhtvghrufhiiigvpedutdenucfrrghrrghmpehmrghilhhfrhhomhepsghorhhishessg hurhdrihho X-ME-Proxy: Received: from localhost (unknown [163.114.132.3]) by mail.messagingengine.com (Postfix) with ESMTPA id D2D47328005E; Wed, 18 Nov 2020 18:07:18 -0500 (EST) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v7 12/12] btrfs: fix lockdep error creating free space tree Date: Wed, 18 Nov 2020 15:06:27 -0800 Message-Id: <1dc72f7e64535cda2fbc798e1130d4b516197136.1605736355.git.boris@bur.io> X-Mailer: git-send-email 2.24.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org A lock dependency loop exists between the root tree lock, the extent tree lock, and the free space tree lock. The root tree lock depends on the free space tree lock because btrfs_create_tree holds the new tree's lock while adding it to the root tree. The extent tree lock depends on the root tree lock because during umount, we write out space cache v1, which writes inodes in the root tree, which results in holding the root tree lock while doing a lookup in the extent tree. Finally, the free space tree depends on the extent tree because populate_free_space_tree holds a locked path in the extent tree and then does a lookup in the free space tree to add the new item. The simplest of the three to break is the one during tree creation: we unlock the leaf before inserting the tree node into the root tree, which fixes the lockdep. Full contents of lockdep error for reference: [ 30.480136] ====================================================== [ 30.480830] WARNING: possible circular locking dependency detected [ 30.481457] 5.9.0-rc8+ #76 Not tainted [ 30.481897] ------------------------------------------------------ [ 30.482500] mount/520 is trying to acquire lock: [ 30.483064] ffff9babebe03908 (btrfs-free-space-00){++++}-{3:3}, at: __btrfs_tree_read_lock+0x39/0x180 [ 30.484054] but task is already holding lock: [ 30.484637] ffff9babebe24468 (btrfs-extent-01#2){++++}-{3:3}, at: __btrfs_tree_read_lock+0x39/0x180 [ 30.485581] which lock already depends on the new lock. [ 30.486397] the existing dependency chain (in reverse order) is: [ 30.487205] -> #2 (btrfs-extent-01#2){++++}-{3:3}: [ 30.487825] down_read_nested+0x43/0x150 [ 30.488306] __btrfs_tree_read_lock+0x39/0x180 [ 30.488868] __btrfs_read_lock_root_node+0x3a/0x50 [ 30.489477] btrfs_search_slot+0x464/0x9b0 [ 30.490009] check_committed_ref+0x59/0x1d0 [ 30.490603] btrfs_cross_ref_exist+0x65/0xb0 [ 30.491108] run_delalloc_nocow+0x405/0x930 [ 30.491651] btrfs_run_delalloc_range+0x60/0x6b0 [ 30.492203] writepage_delalloc+0xd4/0x150 [ 30.492688] __extent_writepage+0x18d/0x3a0 [ 30.493199] extent_write_cache_pages+0x2af/0x450 [ 30.493743] extent_writepages+0x34/0x70 [ 30.494231] do_writepages+0x31/0xd0 [ 30.494642] __filemap_fdatawrite_range+0xad/0xe0 [ 30.495194] btrfs_fdatawrite_range+0x1b/0x50 [ 30.495677] __btrfs_write_out_cache+0x40d/0x460 [ 30.496227] btrfs_write_out_cache+0x8b/0x110 [ 30.496716] btrfs_start_dirty_block_groups+0x211/0x4e0 [ 30.497317] btrfs_commit_transaction+0xc0/0xba0 [ 30.497861] sync_filesystem+0x71/0x90 [ 30.498303] btrfs_remount+0x81/0x433 [ 30.498767] reconfigure_super+0x9f/0x210 [ 30.499261] path_mount+0x9d1/0xa30 [ 30.499722] do_mount+0x55/0x70 [ 30.500158] __x64_sys_mount+0xc4/0xe0 [ 30.500616] do_syscall_64+0x33/0x40 [ 30.501091] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [ 30.501629] -> #1 (btrfs-root-00){++++}-{3:3}: [ 30.502241] down_read_nested+0x43/0x150 [ 30.502727] __btrfs_tree_read_lock+0x39/0x180 [ 30.503291] __btrfs_read_lock_root_node+0x3a/0x50 [ 30.503903] btrfs_search_slot+0x464/0x9b0 [ 30.504405] btrfs_insert_empty_items+0x60/0xa0 [ 30.504973] btrfs_insert_item+0x60/0xd0 [ 30.505412] btrfs_create_tree+0x1b6/0x210 [ 30.505913] btrfs_create_free_space_tree+0x54/0x110 [ 30.506460] btrfs_mount_rw+0x15d/0x20f [ 30.506937] btrfs_remount+0x356/0x433 [ 30.507369] reconfigure_super+0x9f/0x210 [ 30.507868] path_mount+0x9d1/0xa30 [ 30.508264] do_mount+0x55/0x70 [ 30.508668] __x64_sys_mount+0xc4/0xe0 [ 30.509186] do_syscall_64+0x33/0x40 [ 30.509652] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [ 30.510271] -> #0 (btrfs-free-space-00){++++}-{3:3}: [ 30.510972] __lock_acquire+0x11ad/0x1b60 [ 30.511432] lock_acquire+0xa2/0x360 [ 30.511917] down_read_nested+0x43/0x150 [ 30.512383] __btrfs_tree_read_lock+0x39/0x180 [ 30.512947] __btrfs_read_lock_root_node+0x3a/0x50 [ 30.513455] btrfs_search_slot+0x464/0x9b0 [ 30.513947] search_free_space_info+0x45/0x90 [ 30.514465] __add_to_free_space_tree+0x92/0x39d [ 30.515010] btrfs_create_free_space_tree.cold.22+0x1ee/0x45d [ 30.515639] btrfs_mount_rw+0x15d/0x20f [ 30.516142] btrfs_remount+0x356/0x433 [ 30.516538] reconfigure_super+0x9f/0x210 [ 30.517065] path_mount+0x9d1/0xa30 [ 30.517438] do_mount+0x55/0x70 [ 30.517824] __x64_sys_mount+0xc4/0xe0 [ 30.518293] do_syscall_64+0x33/0x40 [ 30.518776] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [ 30.519335] other info that might help us debug this: [ 30.520210] Chain exists of: btrfs-free-space-00 --> btrfs-root-00 --> btrfs-extent-01#2 [ 30.521407] Possible unsafe locking scenario: [ 30.522037] CPU0 CPU1 [ 30.522456] ---- ---- [ 30.522941] lock(btrfs-extent-01#2); [ 30.523311] lock(btrfs-root-00); [ 30.523952] lock(btrfs-extent-01#2); [ 30.524620] lock(btrfs-free-space-00); [ 30.525068] *** DEADLOCK *** [ 30.525669] 5 locks held by mount/520: [ 30.526116] #0: ffff9babebc520e0 (&type->s_umount_key#37){+.+.}-{3:3}, at: path_mount+0x7ef/0xa30 [ 30.527056] #1: ffff9babebc52640 (sb_internal#2){.+.+}-{0:0}, at: start_transaction+0x3d5/0x5c0 [ 30.527960] #2: ffff9babeae8f2e8 (&cache->free_space_lock#2){+.+.}-{3:3}, at: btrfs_create_free_space_tree.cold.22+0x101/0x45d [ 30.529118] #3: ffff9babebe24468 (btrfs-extent-01#2){++++}-{3:3}, at: __btrfs_tree_read_lock+0x39/0x180 [ 30.530113] #4: ffff9babebd52eb8 (btrfs-extent-00){++++}-{3:3}, at: btrfs_try_tree_read_lock+0x16/0x100 [ 30.531124] stack backtrace: [ 30.531528] CPU: 0 PID: 520 Comm: mount Not tainted 5.9.0-rc8+ #76 [ 30.532166] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.11.1-4.module_el8.1.0+248+298dec18 04/01/2014 [ 30.533215] Call Trace: [ 30.533452] dump_stack+0x8d/0xc0 [ 30.533797] check_noncircular+0x13c/0x150 [ 30.534233] __lock_acquire+0x11ad/0x1b60 [ 30.534667] lock_acquire+0xa2/0x360 [ 30.535063] ? __btrfs_tree_read_lock+0x39/0x180 [ 30.535525] down_read_nested+0x43/0x150 [ 30.535939] ? __btrfs_tree_read_lock+0x39/0x180 [ 30.536400] __btrfs_tree_read_lock+0x39/0x180 [ 30.536862] __btrfs_read_lock_root_node+0x3a/0x50 [ 30.537304] btrfs_search_slot+0x464/0x9b0 [ 30.537713] ? trace_hardirqs_on+0x1c/0xf0 [ 30.538148] search_free_space_info+0x45/0x90 [ 30.538572] __add_to_free_space_tree+0x92/0x39d [ 30.539071] ? printk+0x48/0x4a [ 30.539367] btrfs_create_free_space_tree.cold.22+0x1ee/0x45d [ 30.539972] btrfs_mount_rw+0x15d/0x20f [ 30.540350] btrfs_remount+0x356/0x433 [ 30.540773] ? shrink_dcache_sb+0xd9/0x100 [ 30.541203] reconfigure_super+0x9f/0x210 [ 30.541642] path_mount+0x9d1/0xa30 [ 30.542040] do_mount+0x55/0x70 [ 30.542366] __x64_sys_mount+0xc4/0xe0 [ 30.542822] do_syscall_64+0x33/0x40 [ 30.543197] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [ 30.543691] RIP: 0033:0x7f109f7ab93a [ 30.544053] Code: 48 8b 0d 49 e5 0b 00 f7 d8 64 89 01 48 83 c8 ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 49 89 ca b8 a5 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 16 e5 0b 00 f7 d8 64 89 01 48 [ 30.546042] RSP: 002b:00007ffc47c4f858 EFLAGS: 00000246 ORIG_RAX: 00000000000000a5 [ 30.546770] RAX: ffffffffffffffda RBX: 00007f109f8cf264 RCX: 00007f109f7ab93a [ 30.547485] RDX: 0000557e6fc10770 RSI: 0000557e6fc19cf0 RDI: 0000557e6fc19cd0 [ 30.548185] RBP: 0000557e6fc10520 R08: 0000557e6fc18e30 R09: 0000557e6fc18cb0 [ 30.548911] R10: 0000000000200020 R11: 0000000000000246 R12: 0000000000000000 [ 30.549606] R13: 0000557e6fc19cd0 R14: 0000557e6fc10770 R15: 0000557e6fc10520 Signed-off-by: Boris Burkov --- fs/btrfs/disk-io.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index fea467c421e7..1934bf6a99da 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1142,7 +1142,7 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans, if (IS_ERR(leaf)) { ret = PTR_ERR(leaf); leaf = NULL; - goto fail; + goto fail_unlock; } root->node = leaf; @@ -1166,6 +1166,8 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans, export_guid(root->root_item.uuid, &guid_null); btrfs_set_root_drop_level(&root->root_item, 0); + btrfs_tree_unlock(leaf); + key.objectid = objectid; key.type = BTRFS_ROOT_ITEM_KEY; key.offset = 0; @@ -1173,13 +1175,12 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans, if (ret) goto fail; - btrfs_tree_unlock(leaf); - return root; -fail: +fail_unlock: if (leaf) btrfs_tree_unlock(leaf); +fail: btrfs_put_root(root); return ERR_PTR(ret);