From patchwork Thu Oct 29 23:57:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11867911 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=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,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 52DFDC4741F for ; Thu, 29 Oct 2020 23:58:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A2AE92076A for ; Thu, 29 Oct 2020 23:58:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="OwInHmBD"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="F+XiRsE6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725897AbgJ2X6G (ORCPT ); Thu, 29 Oct 2020 19:58:06 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:40221 "EHLO out1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725372AbgJ2X6G (ORCPT ); Thu, 29 Oct 2020 19:58:06 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id B0C885C00AE; Thu, 29 Oct 2020 19:58:04 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Thu, 29 Oct 2020 19:58:04 -0400 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=ZuO/DuznAXTj6dUlvuHz0gK2qR fZJCIo5KHjwpqzhoE=; b=OwInHmBDt8339JjLXaLL0gdlrXq8t0jkb59b8CXBfV LSM16e5Eq/yWpBcTSHr5qrIeBotGVftuBSqWfQ0x+3KKY1Cvh0XO3Li2ColBHbPU iNXivTfzVRixWiW0lKfr5xFEtXPKLJQvXw65YqZxD93W13cAtnEtr10ojmZlf23A GSbS7FhdTJy8hxmgav1+xBX7rr4PzAgJ+5jvaH8ueyBn2GUMjsDLYkh5q55WnL94 fu+pC9gybVqFR6WReUMpOW8ozTFqp5u38I9bmwE+gb0RPxi729F9IU0vRwcQUIER e/khU6OoKj6GDU56/XWkslKD4a3OhPtWIWjkpfDYE42A== 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=ZuO/DuznAXTj6dUlvuHz0gK2qRfZJCIo5KHjwpqzhoE=; b=F+XiRsE6 G2Ch3ifvx1WK1sCNFoW2OreKLx502aD0FnR6bT78EPj3BP111lFj75PancZxEQMM f9gfTsTwpOpyGCvsy4EmGDwFVWbR2WtwQjBzSG+Lxnd40gb3tOAcjMD4NGu6Nen2 heRczwudLXyFgpjYo+UAtELNMCAI4fQ/3oS83tcqYFEnUiImoWz8TFwNejD5zdv0 Bx70zMp1fAGMVojqcfxwInJFGNcsME3aQzHVMNh3N0xe+9IJhyHUabxgLDhtqV9O QACdvr2Ahbznv6b320UjphRgZqOYjCHsIARkJIhCxvEqyHqEYgaiIsswCeUKTHxM PfGLm0UgfUPRJg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrleeggdduiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffojghfggfgsedtkeertd ertddtnecuhfhrohhmpeeuohhrihhsuceuuhhrkhhovhcuoegsohhrihhssegsuhhrrdhi oheqnecuggftrfgrthhtvghrnhepieeuffeuvdeiueejhfehiefgkeevudejjeejffevvd ehtddufeeihfekgeeuheelnecukfhppeduieefrdduudegrddufedvrdefnecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepsghorhhishessghurh drihho X-ME-Proxy: Received: from localhost (unknown [163.114.132.3]) by mail.messagingengine.com (Postfix) with ESMTPA id EF4103064682; Thu, 29 Oct 2020 19:58:03 -0400 (EDT) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v6 01/10] btrfs: lift rw mount setup from mount and remount Date: Thu, 29 Oct 2020 16:57:48 -0700 Message-Id: <30c4efc1374a7e894e25fafb2de5781d3093519f.1604015464.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 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 601a7ab2adb4..b741a711bad5 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2894,6 +2894,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) { @@ -3298,22 +3345,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); @@ -3366,35 +3397,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 182540bdcea0..a4e6cdbe3a48 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( struct btrfs_fs_info *fs_info, u64 bytenr); 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 1ffa50bae1dd..22299fc13b6d 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1880,7 +1880,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; @@ -1973,39 +1972,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 Thu Oct 29 23:57:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11867901 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=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,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 EE77DC2D0A3 for ; Thu, 29 Oct 2020 23:58:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3DCD92076A for ; Thu, 29 Oct 2020 23:58:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="xY4ZP5vJ"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="FE13fS2y" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725932AbgJ2X6J (ORCPT ); Thu, 29 Oct 2020 19:58:09 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:36743 "EHLO out1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725372AbgJ2X6I (ORCPT ); Thu, 29 Oct 2020 19:58:08 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id A01AA5C009E; Thu, 29 Oct 2020 19:58:07 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 29 Oct 2020 19:58:07 -0400 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=nEZIWEe7CILcdCBa27Aq7QpWzY w++1lEBc229Ryartw=; b=xY4ZP5vJNaOl4dHTxORrQq5Y0Q3mgs2qnNOxzfADEv OAC+SOpvfqxbsR2oJJhL2N3VE9ci6dkcP8T8ZxvkoIflqinQitAFlIX7TvW++yRf znDuYMB0Efamfvn/GjutYQZDgWxAo6GuW2K0GCCN+n1aGI6b8poMkxr+cBYdyQ4V T0lFmKy+nV4LL23ViYSYHRp8nOvneMzcWVR+ZaCdpH3DNKjX2C1HhOpkdtqKOwnM RgSweJxJA9JAuwcVBanRq7pkAkD0LJspyV+ypac9MK04OybeilG/t0aA5qqhQoaA VLGlsOudNQx+C1YykLzhFHaN7s1KtomQi2xSK4C8g/NQ== 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=nEZIWEe7CILcdCBa27Aq7QpWzYw++1lEBc229Ryartw=; b=FE13fS2y Z0RUNVZeKFkz7Q3fJQKo6mu6mMFjh5knNwjVGTx/WUUVF45djvN8ir4qhyJPtDCu To5b8i1lzI4xuukejD3p3ni30e4Jyx8A8CKDEekW84CFEK2gwnqY4/6WAmZXUcp9 EewzWJGXfc3HuH2Fhe4uRRIfJTmIIBhayKBdfTpGipuHBvy6xQSpYWpidwvjAgB8 ivOGWATm5ZwQ7yHQ+j7yZQ1ENvKSpXo56nTrEyxBffxwlW2RANuKu2qiDaEHHRDl j1YGwrzu4kwG9eqkxT4a78Oe+IdXszWMudadSnQnRO6/m4JhC866jYF7eYuC7hps egRj2Oz9KCB/Dg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrleeggdduiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffojghfggfgsedtkeertd ertddtnecuhfhrohhmpeeuohhrihhsuceuuhhrkhhovhcuoegsohhrihhssegsuhhrrdhi oheqnecuggftrfgrthhtvghrnhepieeuffeuvdeiueejhfehiefgkeevudejjeejffevvd ehtddufeeihfekgeeuheelnecukfhppeduieefrdduudegrddufedvrdefnecuvehluhhs thgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepsghorhhishessghurh drihho X-ME-Proxy: Received: from localhost (unknown [163.114.132.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 3DA02328005E; Thu, 29 Oct 2020 19:58:07 -0400 (EDT) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v6 02/10] btrfs: cleanup all orphan inodes on ro->rw remount Date: Thu, 29 Oct 2020 16:57:49 -0700 Message-Id: <2e7a82b65f92bda808bdd6db19a7c84a779a70d3.1604015464.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 b741a711bad5..e42548287161 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2906,6 +2906,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); @@ -3388,15 +3396,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 Thu Oct 29 23:57:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11867915 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=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,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 5DF67C4742C for ; Thu, 29 Oct 2020 23:58:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D039B2076A for ; Thu, 29 Oct 2020 23:58:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="hc9O3n3L"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="G16DTQJA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725952AbgJ2X6M (ORCPT ); Thu, 29 Oct 2020 19:58:12 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:38583 "EHLO out1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725372AbgJ2X6L (ORCPT ); Thu, 29 Oct 2020 19:58:11 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id AF3255C009E; Thu, 29 Oct 2020 19:58:10 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 29 Oct 2020 19:58:10 -0400 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=h7FMY6l6GhuxmnOsgSApRcJOTc +8aE0nMMynJ1gceQg=; b=hc9O3n3Leo9XlIEE56OpxclDSgiySGbJMAJwMLLq6O 6V+YWBFzcz95MY7/b3vZBIWtA7s3OEsll7eORwbchYJLMzBjff4/39VYzyoF68tA UfDpq0M0nFYDd4dgGlBJypxphAQ7DNxJJ/ibXuFBl9oR9OYJmYAFb579yIQdxcZx UxOH9doPkd4LkSjBAIBG78/WL3p+zZGMMM/fjOgZH5e5K6/ty5YsYQKztFva8M1a uJcad0SHH4yzN6bOzURW2Pb+bVNZHNr3uCslJIOfMznB0/4G/SRXb0FjyYocb2Lw JkGTsktlNmmE09G8PRc4B5GpsuaK7wYsPnzZF64zJ6nQ== 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=h7FMY6l6GhuxmnOsgSApRcJOTc+8aE0nMMynJ1gceQg=; b=G16DTQJA YMx1Ix76CHEn38GW2SYJVcZGr0rh0XtZ/FM2wS6hpeyE8bjLxtdC5PuwWITxaH2W wenB2fnmi4Il+1a99uAaHNyepM+ZhD83NMQx93QsQMrTt8fr/1Xn2xBvLCyT76nA FYmfZ38Yl7+1KRLfe4hNK4qrlC2hQIEL90F7jIzxLmKqjOX8wMUP3+YW/BCJjOMu qLAMHwijTxIxSEYNa9GdQev5AlyuDOnztAt0qNaksgqIXtFmX896mIvpCfsi5QE5 QkYwzNVeJjF7uW6r6m1x2hP1cZ8UJQz3DMWR2eidwH4iofkzhFaDCXulWeJP8lNQ MyF6pwR/W1ZLLA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrleeggdduiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffojghfggfgsedtkeertd ertddtnecuhfhrohhmpeeuohhrihhsuceuuhhrkhhovhcuoegsohhrihhssegsuhhrrdhi oheqnecuggftrfgrthhtvghrnhepieeuffeuvdeiueejhfehiefgkeevudejjeejffevvd ehtddufeeihfekgeeuheelnecukfhppeduieefrdduudegrddufedvrdefnecuvehluhhs thgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepsghorhhishessghurh drihho X-ME-Proxy: Received: from localhost (unknown [163.114.132.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 4A82A3280060; Thu, 29 Oct 2020 19:58:10 -0400 (EDT) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v6 03/10] btrfs: create free space tree on ro->rw remount Date: Thu, 29 Oct 2020 16:57:50 -0700 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 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 e42548287161..69a878d8cc79 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2922,6 +2922,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; @@ -3384,18 +3395,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 Thu Oct 29 23:57:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11867913 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=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,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 B99E8C2D0A3 for ; Thu, 29 Oct 2020 23:58:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3B37D2076A for ; Thu, 29 Oct 2020 23:58:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="d5gLg5qu"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="BXL//2Br" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725989AbgJ2X6P (ORCPT ); Thu, 29 Oct 2020 19:58:15 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:60989 "EHLO out1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725372AbgJ2X6O (ORCPT ); Thu, 29 Oct 2020 19:58:14 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id F25835C008C; Thu, 29 Oct 2020 19:58:13 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 29 Oct 2020 19:58:13 -0400 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=fwV4xy0O6qicfBFEo2f4u9h9AV 08MvrWD+FP5tonJfQ=; b=d5gLg5quVyNs0kWlHlaMIKhXSWBckKgmQfd4ISRl9C BmUWwuO6gbZJ5xUPnYLyyhGtWXBxm8wX2zGSF/cdevKvlSiw1cgqJFCJlNMCxQQG 251jxP1EbGGyjm6lylbm5oGvkF0A4C8+XuoKG2yXJpzr2A/sprg5bSF/9PONNHNG 7hGCk2ZNxehUTZiQqMdFaWBtYaLeQyBNKZROfM0fx2g4F9Z9vqOePM9nVMeLEM0s R/kegv7bh6JFlblG8NoJG1AZsZ8ZP587MJdQO+t12h9ZQy1cJwWf0ekNf6B3MZ3M cCHuTs0X2DojjkrumwXU0V/7kH+9myKoIAWbtx61rREA== 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=fwV4xy0O6qicfBFEo2f4u9h9AV08MvrWD+FP5tonJfQ=; b=BXL//2Br 2G0mA5oBScsXYUj14JJYJOhRF/psIre9o+aXNSPBNuzAVxnB59xbivTzObi7ujxA MtrAJadz1qqgs6w2/TcFMTeWgzQgmPPIHz6gY13i14F9JfsNgBT019bgu13jW2eQ V4+0J5nKxvszIwsaJzDb/8SfAV8Xdqf/Ybg4WqPmhhsBqtf32C+VQbBnQPi6r5jW BgteKXQY/o89yVEn1vIY7kz+rGc/MulI49vGPS03sobUZpLrFEUizyTG34GBUmII EjOU5SiPy+TYMJEFUFqGGBjck4jRvIUBebuscZkAaQ5g9+3z6kVNPifDyJD+qsjY x6DsBcnHqBjpxg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrleeggdduiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffojghfggfgsedtkeertd ertddtnecuhfhrohhmpeeuohhrihhsuceuuhhrkhhovhcuoegsohhrihhssegsuhhrrdhi oheqnecuggftrfgrthhtvghrnhepieeuffeuvdeiueejhfehiefgkeevudejjeejffevvd ehtddufeeihfekgeeuheelnecukfhppeduieefrdduudegrddufedvrdefnecuvehluhhs thgvrhfuihiivgepfeenucfrrghrrghmpehmrghilhhfrhhomhepsghorhhishessghurh drihho X-ME-Proxy: Received: from localhost (unknown [163.114.132.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 810F2328005E; Thu, 29 Oct 2020 19:58:13 -0400 (EDT) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v6 04/10] btrfs: clear oneshot options on mount and remount Date: Thu, 29 Oct 2020 16:57:51 -0700 Message-Id: <9b8b036b575599ce4a2a748263e3bd0e80288b0d.1604015464.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 69a878d8cc79..63f1e37f0e22 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2894,6 +2894,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. @@ -3373,7 +3383,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)) { @@ -3417,6 +3427,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 a4e6cdbe3a48..22df6a570aaf 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( struct btrfs_fs_info *fs_info, u64 bytenr); 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 22299fc13b6d..3d56b98e152d 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1994,6 +1994,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 Thu Oct 29 23:57:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11867917 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=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,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 9DB8EC2D0A3 for ; Thu, 29 Oct 2020 23:58:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F3EF62076A for ; Thu, 29 Oct 2020 23:58:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="XqGI1oqR"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="atu0rQRL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726010AbgJ2X6U (ORCPT ); Thu, 29 Oct 2020 19:58:20 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:54367 "EHLO out1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725372AbgJ2X6S (ORCPT ); Thu, 29 Oct 2020 19:58:18 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 1B64D5C00E2; Thu, 29 Oct 2020 19:58:17 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 29 Oct 2020 19:58:17 -0400 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=VFkGuB8Tusas8HqcFrP7jPcie6 MWoyWAGtqtkj+4TTQ=; b=XqGI1oqR/2cheXIy5lkl1hETACRxJIbq6mtTlm+DUg EAKCr7xG/RCsVphk2rnqE+boU0A2++S7w9BTwmFMibXgvCI9CVCMnYDmp1bSwZbM 48y7C7IGGpBegPRY1ee0L+gMa+Qqax/UT7S99BY0BN32rcmklVAF3yEV8hGEdGr7 ru4yyyuokqGefY9Ru8Un6fFauKZH2UMHdm1KEvjOu+FpUIBuTozs+Qv3z7G17ybl nV615bQ/rVv5oM6iwdW77jvGgleXUwKGLcAOeDddDs3WIvMQA/Jvm1SYv6LpcHpu V10nzFVDRXIWfU9f4s3/unxCpOe0yw1BncnyNe3ebBlg== 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=VFkGuB8Tusas8HqcFrP7jPcie6MWoyWAGtqtkj+4TTQ=; b=atu0rQRL LqywhgN926pXX78nEi0gkiClK6FliDf8skjw9dUptftb2F+ZDgkAtWC3PrM9HBuM tGbUbrs8pFvzvE5rt1uiHHFI5TOHAa1gZ4omp7MCSWaKCmVHGXkPGwe6Vi0y3WHO UU3pGV/iXnNF0Xg+QH8eNpcMiLAU8H9XxJAXmMNoB44DMIp6I1pI8ApFZyFgzxQ1 WH5TMnXUiqnO40x4dzou58YJC6u7WwoMGndN93kiGJYFnlhwsSzJX1PLeHGQl0Kz 11VGziaKS84ejfPejjngZjSZ8MMnxIq6Ygv8LTA5s7pk8unYUshpps9Ut++fI5zH UvoG529vdW/l2Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrleeggdduiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffojghfggfgsedtkeertd ertddtnecuhfhrohhmpeeuohhrihhsuceuuhhrkhhovhcuoegsohhrihhssegsuhhrrdhi oheqnecuggftrfgrthhtvghrnhepieeuffeuvdeiueejhfehiefgkeevudejjeejffevvd ehtddufeeihfekgeeuheelnecukfhppeduieefrdduudegrddufedvrdefnecuvehluhhs thgvrhfuihiivgepfeenucfrrghrrghmpehmrghilhhfrhhomhepsghorhhishessghurh drihho X-ME-Proxy: Received: from localhost (unknown [163.114.132.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 9B9B6328005D; Thu, 29 Oct 2020 19:58:16 -0400 (EDT) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v6 05/10] btrfs: clear free space tree on ro->rw remount Date: Thu, 29 Oct 2020 16:57:52 -0700 Message-Id: <7898615eb36f15cdcf2c2497b5d1f127b2442e3c.1604015464.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 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 63f1e37f0e22..d6b73701563c 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2911,6 +2911,28 @@ 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) && + 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) @@ -2985,7 +3007,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); @@ -3385,26 +3406,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 Thu Oct 29 23:57:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11867903 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=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,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 A3C38C4741F for ; Thu, 29 Oct 2020 23:58:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1CCC22076A for ; Thu, 29 Oct 2020 23:58:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="JKFGY3xI"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="T6+LwItQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726018AbgJ2X6W (ORCPT ); Thu, 29 Oct 2020 19:58:22 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:57573 "EHLO out1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725372AbgJ2X6V (ORCPT ); Thu, 29 Oct 2020 19:58:21 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 5D03D5C009D; Thu, 29 Oct 2020 19:58:20 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 29 Oct 2020 19:58:20 -0400 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=ksYImFW6lXcAU4pNykS8SPFd0D RQUpaAsetXXJYMSDs=; b=JKFGY3xIA/ANkJAGgEhX4nJHVVVrixccdEmpfaN30N XWhCq89wDnzTUukfQEyd5Jb3qIv41cchV2WXUbmkrZqFq90Gjgb3UJZ4buB5V0Hf 5evBsSAU11uJtcCOZMFQk/Xr8slbWfwljyeiiPkYO+um6yibT/lFb5NldROUiMmz CNZC5vexq1v8pUe4+6UT/XhlGtFxpXHDxBJUsN4qkoW+IBX6Y1u/oxvM2wRbAjnp l2dm0k+J0NohWtAO3Q2rXOX3e6R6PhZH1w8hLpOIyeOY3KSKMWwv4n+DhyrEh4Gq Y5V0jEQN1uKqtmvFlTrYH5BONspmPQ5c5MyHkHpz6TGg== 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=ksYImFW6lXcAU4pNykS8SPFd0DRQUpaAsetXXJYMSDs=; b=T6+LwItQ WU1l1AGRdwiaJUIQZ2ZXZO9uNaV2BUTSjw2Jl8/35gkN7/h/bkeJ9GSJOgkxzWa/ 6mZSn+DzyPu87112rFC0F1fWp5d90MjUaT/aiNT6MIp1wsEkPZ5PVfpBBcFkXui4 J783XibjjRyUuxHz91VEruo+NCzwuIPhHJ2bjry8ubVssOwJNb/LH2YUYrQo3gCU OYg3Zbci1uEhWLlQX6jOiMDtxXok8+cyPXUACvoiDdj/e60gGgsa5jglvJpw2kwU j24KLfh4+16KEgd/BzLijbpgQBi70e9QEe7SnW8FiQ4Wqa58WnpB9ky16Z9yRMT/ KwFxp7Elh3afFQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrleeggdduiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffojghfggfgsedtkeertd ertddtnecuhfhrohhmpeeuohhrihhsuceuuhhrkhhovhcuoegsohhrihhssegsuhhrrdhi oheqnecuggftrfgrthhtvghrnhepieeuffeuvdeiueejhfehiefgkeevudejjeejffevvd ehtddufeeihfekgeeuheelnecukfhppeduieefrdduudegrddufedvrdefnecuvehluhhs thgvrhfuihiivgepheenucfrrghrrghmpehmrghilhhfrhhomhepsghorhhishessghurh drihho X-ME-Proxy: Received: from localhost (unknown [163.114.132.3]) by mail.messagingengine.com (Postfix) with ESMTPA id B2AC8328005D; Thu, 29 Oct 2020 19:58:19 -0400 (EDT) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v6 06/10] btrfs: keep sb cache_generation consistent with space_cache Date: Thu, 29 Oct 2020 16:57:53 -0700 Message-Id: <4c580bccc9f08075226fc60b7703a001e7e2dee4.1604015464.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 | 7 +++++++ 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, 50 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 8a83bce3225c..a99918b7a2af 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 d6b73701563c..a256b1a064a8 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2965,6 +2965,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; @@ -3426,6 +3432,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 5ea36a06e514..5185e798cc57 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -3992,6 +3992,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 e3d5e0ad8f8e..5c546898ded9 100644 --- a/fs/btrfs/free-space-cache.h +++ b/fs/btrfs/free-space-cache.h @@ -148,6 +148,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 3d56b98e152d..95465c5a3166 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); /* @@ -1859,6 +1857,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. @@ -1875,6 +1875,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 8f70d7135497..0e85482b6713 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -1761,6 +1761,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 Thu Oct 29 23:57:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11867905 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=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,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 14A99C4742C for ; Thu, 29 Oct 2020 23:58:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B26F2076A for ; Thu, 29 Oct 2020 23:58:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="PZJpsJL0"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="gfdE3VtW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726026AbgJ2X6Y (ORCPT ); Thu, 29 Oct 2020 19:58:24 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:47617 "EHLO out1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725372AbgJ2X6Y (ORCPT ); Thu, 29 Oct 2020 19:58:24 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 618695C00AC; Thu, 29 Oct 2020 19:58:23 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 29 Oct 2020 19:58:23 -0400 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=GMXWF2a5bNBR50Qj/zV5fD7WXt 7VYDMpCurJd/0N7zk=; b=PZJpsJL0gg+HNjzVydNGoVUgimkGO8IA0/RHqmfbh3 1wv7yM/dzsM3D9AHK6qgpsj4a3CMG2EZjc1w6jHEInJOsgjFCF7grWT7XI+Gd+l8 2Vfcu88O/nDi2pRD+B25dkHnd2BTEEaZn2BozVMrhcekWHlzkgg5PKzaLRyFU8Jz vZzXRZHDEIfQMOssdZfXMNm+RCJ6AlZA++VuwKkxUq+ajpm0RdVAanWZPWwaoNoC kx2EG9Tv//d3v3gezXdKumzy9WtFvDOUtRjHP6zzAvXN+xzZAlhlwfPVxO3zp0b5 aJ9YRCJWF26iONzveaw0LooKLrEwGgq4WN7Kvfun+sEQ== 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=GMXWF2a5bNBR50Qj/zV5fD7WXt7VYDMpCurJd/0N7zk=; b=gfdE3VtW FOdKOUJDLCEDhrEwT7gypbK7Xj+aJdq4u/ENSpVm4F3NksygfubL1LWyjYCUhlWY VXrDV2x/MnIjrDj8OFbye0yWToLRq97iNPrl9dbLy9rslrG3w1gi5gDAuLqoAx9E W2cfJRaQAMaAMAUqp5R6Tiadiz5FFJNn7PLRpg3OShA9h0ptfLYnbS3pjV0xXBYN mOx6V+w3rKgiQRol8PXaoeZQU95CLgG2jKpeY76lfOr/Lhp4AV3khOHqZWDZw20h vj7CCyw4f8+Ip+1hokXOpm9/KdnprLjmuMus1breO1yLSeXVLSjTgVXO2XX0rVaP qlxz9sEb/sO+Ow== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrleeggdduiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffojghfggfgsedtkeertd ertddtnecuhfhrohhmpeeuohhrihhsuceuuhhrkhhovhcuoegsohhrihhssegsuhhrrdhi oheqnecuggftrfgrthhtvghrnhepieeuffeuvdeiueejhfehiefgkeevudejjeejffevvd ehtddufeeihfekgeeuheelnecukfhppeduieefrdduudegrddufedvrdefnecuvehluhhs thgvrhfuihiivgepheenucfrrghrrghmpehmrghilhhfrhhomhepsghorhhishessghurh drihho X-ME-Proxy: Received: from localhost (unknown [163.114.132.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 0499A3280065; Thu, 29 Oct 2020 19:58:23 -0400 (EDT) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v6 07/10] btrfs: use sb state to print space_cache mount option Date: Thu, 29 Oct 2020 16:57:54 -0700 Message-Id: <9361af6776a977c4ecab2d4bbd4161f0784e4482.1604015464.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 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 95465c5a3166..527ab305ac68 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1476,9 +1476,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 Thu Oct 29 23:57:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11867909 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=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,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 1B023C2D0A3 for ; Thu, 29 Oct 2020 23:58:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 944992076A for ; Thu, 29 Oct 2020 23:58:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="Mu8UvkLF"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="rFtStaxz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726036AbgJ2X61 (ORCPT ); Thu, 29 Oct 2020 19:58:27 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:59305 "EHLO out1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725372AbgJ2X61 (ORCPT ); Thu, 29 Oct 2020 19:58:27 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 6381D5C00DD; Thu, 29 Oct 2020 19:58:26 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 29 Oct 2020 19:58:26 -0400 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=E42VkJKfxNqb9pRNLMWP7Aw4rQ hI7nJQushHWEDcPBE=; b=Mu8UvkLFamEsmpfx/QvU9B5ZYvsovibKAcPxtd6iHs VahmxPF6lecCJGORD3FY6D2bDU+EW1oEtWUPwJYyTL+e958h53S1b1Ec/OIr9imd 30pgFnfwp9gx2UkjkEg9bXgCya7jApZUbypU8VaO5BL/gM9ttmisc113Y45wvMIk 1UoE/AfPCMMtSkdMNH0Xp5lClW45MyPtr/8thdEP0vUD8sh9Udl1Al2vsj6yU2M0 zDslxBfSEREOKCB8zTVB7npW2J8OlRUl9W4TK7O0GW2WzhEjf+/SE/JhHbhZbZ1k 9hYfNLCP6KLNG3Luiv3qJzmM1JhcaYHHCWB4PWytgTMA== 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=E42VkJKfxNqb9pRNLMWP7Aw4rQhI7nJQushHWEDcPBE=; b=rFtStaxz HXJBaIuv91I3uVYapirUPdxcX63CCPOvCo7itINl+BAdGyHtStt/4wPtUuVq3FlL KlxpQDpeutdvaeuIC+oBJ7v4dUbSqJ6re0ARCetVTz8hB9/SEDEt2CaMo/rpfbFO SeVa6jVJZ3urU9fCIGDP93iLXyTDPNHH+NTe1BbWtp6YLWnYhP13LsC1fuwVANhP Zj80z30g0Q0Fkyw1xBx10ofsWqpOFmHTWyWhYW6vdjke88u/Vk1LhkfLMwYbCZ/5 a2h9WABV6mGrKBNwhj8k83WPqEdZUr5NLcsjSDSTIuHNWLxfvKiRf/SH0xcINIoF QjD/HQf2qrVwcw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrleeggdduiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffojghfggfgsedtkeertd ertddtnecuhfhrohhmpeeuohhrihhsuceuuhhrkhhovhcuoegsohhrihhssegsuhhrrdhi oheqnecuggftrfgrthhtvghrnhepieeuffeuvdeiueejhfehiefgkeevudejjeejffevvd ehtddufeeihfekgeeuheelnecukfhppeduieefrdduudegrddufedvrdefnecuvehluhhs thgvrhfuihiivgepjeenucfrrghrrghmpehmrghilhhfrhhomhepsghorhhishessghurh drihho X-ME-Proxy: Received: from localhost (unknown [163.114.132.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 004B33280063; Thu, 29 Oct 2020 19:58:26 -0400 (EDT) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v6 08/10] btrfs: warn when remount will not change the free space tree Date: Thu, 29 Oct 2020 16:57:55 -0700 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 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 527ab305ac68..ed5c80f92f78 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1914,6 +1914,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 Thu Oct 29 23:57:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11867919 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=-17.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,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 17087C2D0A3 for ; Thu, 29 Oct 2020 23:58:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9FB592076A for ; Thu, 29 Oct 2020 23:58:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="RX9Cy9vg"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="A3Jvui8R" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726038AbgJ2X6b (ORCPT ); Thu, 29 Oct 2020 19:58:31 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:39437 "EHLO out1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725372AbgJ2X6b (ORCPT ); Thu, 29 Oct 2020 19:58:31 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id CC0A75C00AC; Thu, 29 Oct 2020 19:58:29 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 29 Oct 2020 19:58:29 -0400 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=VbhibWHPQDmPWxK+X2yNUiStnY V//NJ1/twaUpnzY5U=; b=RX9Cy9vgTfGRsTAmafoHgddfiwbD3Y0P+gGgT1rDDz hh/tFuTWqzHJA25T0rC+lIqsP4x8TmOdtr7TFOUOlD4Nz5KImKmff1PntxF1ucFD oTg7jDqN2gfO9nHZ4po5S08T1NxYbaUbD070EnCCwHFSVLBsSJsxHrtMCFa2ToGz tcH6xHPxycNOz9Kdtvl2F6TlIIhr1drxatYK2x4sF8IQwSlrVGrpLQWQ5XiCL6xl OEraYaH1l8FaTUTN0tAWMRKqiGun9MfsSb2tJ/XCBEEOQbUF4cCXyCErNHOUTCQ4 QUfFWMXzjfmwdxXCY1pYiPL/WU8bvTASybAtNQZcFMRg== 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=VbhibWHPQDmPWxK+X2yNUiStnYV//NJ1/twaUpnzY5U=; b=A3Jvui8R ThoVahhMqtpYtQLhEohceI4j3ZoMvhEnzNFuAU7yrfP8DKevnZ/7dcNzFrdzau1m Ya+10wRz0xE4EAYjLSFdmmq5m2ztcuLNnh09k80sAgjAdyIEYncAdtY3WLCJ+QK5 HdbKvfy0ldHMDG+jraLaSr0EO2SlFk2jK4PdkrA5YK0IiTq/GkyUNNbLpaLyxfH+ 9aM/r8lY0ooREyqbwcEf1izVetMIb40iVvXTe8ztRiSGSMqQZa9pT8cUiwjF3gKh rxnybkETnvQVEed+b7HvodA8v78ET8bv98+Z55oqpg16LIj4qyAl4+G1vXzklQO8 J6oWxvWSu1wsDg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrleeggdduiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffojghfggfgsedtkeertd ertddtnecuhfhrohhmpeeuohhrihhsuceuuhhrkhhovhcuoegsohhrihhssegsuhhrrdhi oheqnecuggftrfgrthhtvghrnhepteehhedugfellefhheffteettdefledvgffhleekfe eggfdvveegffefvddtfeegnecuffhomhgrihhnpehgihhthhhusgdrtghomhenucfkphep udeifedruddugedrudefvddrfeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpegsohhrihhssegsuhhrrdhioh X-ME-Proxy: Received: from localhost (unknown [163.114.132.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 355DF3280063; Thu, 29 Oct 2020 19:58:29 -0400 (EDT) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v6 09/10] btrfs: remove free space items when disabling space cache v1 Date: Thu, 29 Oct 2020 16:57:56 -0700 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 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 bb6685711824..2dde5c6f1da8 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -892,8 +892,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; @@ -971,42 +969,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 5185e798cc57..660cc722ef3f 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -207,6 +207,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) { @@ -3997,6 +4056,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) { @@ -4004,18 +4085,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 5c546898ded9..8df4b2925eca 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 Thu Oct 29 23:57:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11867921 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=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,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 D6A20C2D0A3 for ; Thu, 29 Oct 2020 23:58:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 74BF32076A for ; Thu, 29 Oct 2020 23:58:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="Q122rEUh"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="mBs7HhKw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726048AbgJ2X6f (ORCPT ); Thu, 29 Oct 2020 19:58:35 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:49729 "EHLO out1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725372AbgJ2X6e (ORCPT ); Thu, 29 Oct 2020 19:58:34 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 3A1305C00DD; Thu, 29 Oct 2020 19:58:33 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 29 Oct 2020 19:58:33 -0400 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=jpS/w6iqmvKNHpceFjPc/umWEP efzVobPQYltFIFD/A=; b=Q122rEUhYWzlxK+7kEVVqnh4XiMKFM5wxok6J0lyT4 xoxCcffS6Tnr6vxmHaqYnDgrCJKJlBzRbZNk6psmwFw3hDl7ZzRTGeNkHTkIGAVL VTGGjgyeg8Fjk8o+5aHu42QfPB8luBO+goxkq736C+oe27d7bo9kmBEcSyhq4bxz FPs53MdkAqk131QULGpc9ixlaJKSqrvaeF3Lr/clGI4SjbWGkfhWzR8Daq9ATMw8 G0KEBDDAKnU9nxwVonNDkcEDXbwvZB6P1HZKSyU3yeP1J5/1c2fwEimLQOkNKpwI MvVlYEuxlWK3pSWAMdQ9azPde0Gde62AeTL4wlyn3uHw== 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=jpS/w6iqmvKNHpceFjPc/umWEPefzVobPQYltFIFD/A=; b=mBs7HhKw TL0aZrMSN0SXITkzYXuBKh7Z11E8b6f1KHR3IXcaGj7yk91CGKrRFTFyJUMya032 +/dFvlmSbaxApOM3nJzUX5nFyoYWqb4CmRqcWjGHJSlUCjb2vbZHXj4EOza/9yOr oI9dPAQfuNr2E2fe55QMPR+xB7Llgu9fPlyX8k+dCzjK7T8LWLFPiYeRelAEMqEq 1PafbenYJz6iewZWn3SnD4UCDZroLJcwQjwxcK9z3NMZdn6xex4PyjmQGZELXM7b qzkBbzZ5ynVDRBitlltDyyaq+5dcFZ1heXUBMNWZzYDs93tW0PcvwFsr8lyiLELO nV+V1ogH4uAN5g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrleeggdduiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffojghfggfgsedtkeertd ertddtnecuhfhrohhmpeeuohhrihhsuceuuhhrkhhovhcuoegsohhrihhssegsuhhrrdhi oheqnecuggftrfgrthhtvghrnhepieeuffeuvdeiueejhfehiefgkeevudejjeejffevvd ehtddufeeihfekgeeuheelnecukfhppeduieefrdduudegrddufedvrdefnecuvehluhhs thgvrhfuihiivgepkeenucfrrghrrghmpehmrghilhhfrhhomhepsghorhhishessghurh drihho X-ME-Proxy: Received: from localhost (unknown [163.114.132.3]) by mail.messagingengine.com (Postfix) with ESMTPA id C83CC3280066; Thu, 29 Oct 2020 19:58:32 -0400 (EDT) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v6 10/10] btrfs: skip space_cache v1 setup when not using it Date: Thu, 29 Oct 2020 16:57:57 -0700 Message-Id: <97ff859cf0df9b5db6313df215fa62754213fb4b.1604015464.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 2dde5c6f1da8..13a16158f4c7 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -2374,6 +2374,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.