From patchwork Wed Oct 21 23:06:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11849951 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 4A558C4363A for ; Wed, 21 Oct 2020 23:07:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C7D10221FB for ; Wed, 21 Oct 2020 23:07:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="IzVaxHa1"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="n3CCLnZE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2507017AbgJUXHG (ORCPT ); Wed, 21 Oct 2020 19:07:06 -0400 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]:57305 "EHLO wout3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2507008AbgJUXHF (ORCPT ); Wed, 21 Oct 2020 19:07:05 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id 665F712A1; Wed, 21 Oct 2020 19:07:03 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 21 Oct 2020 19:07:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm2; bh=bdG9zCvWQfP6R oOXDcCaOlaQgWijIm5uHnUYLgOe5Qg=; b=IzVaxHa1CWBTAYHvGyXU4pqo41/bF yqGBRyROuUJT4ICZ3ALo+JpzRdPe4cFi8aHhTXx5cYtKlVsN6oOj1gN/67U0me4X 6uE25hhwPJDoCLIF3jzrgw4wu3VuKvc5xkI4jYISYIdwvrtMt+7+xZPxjBAJLQMZ Ub0sakS+uAlmXEQMMmZG2Ha7mq6rIFeqa9ZrSdGUK4YLU4fSOX3yE7BRHUyE6btz UQ2FVz9RcxlDAf3TA5E3DkwUV0j4W7vad+Er0M1ip1sdxb8G7t1Qabiz7tDMMI9o 3gqXpmllh/SPTKsGQOR4l1jgoQbFPrFIXZx81XnRjQyqYTQrNstXUm3/A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=bdG9zCvWQfP6RoOXDcCaOlaQgWijIm5uHnUYLgOe5Qg=; b=n3CCLnZE vgdYXV70ayMdYDTuBxA5LjEU5Tpcqs3Ba6ghP0p6ry3E3miQgBo8WVG01IXyNDPK k6yE4QzV3TjNfl4h+3Xbd9Ly8ZRyKMePr/FZF440TnfkEEtDia/Q4EFbQRPWlMKK 3cQmDYyWI5JVd8DaONH3lWFr04zOOlDBp9RPCkHffWEiIobgOMUMWJCvkl/YFPs8 OOmnrWMGBtSVE/VOY58K98gg3/8AkpOR30SLvFnTWicAnGAi/oH7nShy0cbVS6fL h/4GMV5sidGdNuqh8KgXpj8120NbInfvsLdHaIpzA5OwbmohljMr8BRcfnTLocUo jNBhshFng7BsEQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrjeeigdduiecutefuodetggdotefrodftvf 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 685853280063; Wed, 21 Oct 2020 19:07:02 -0400 (EDT) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Boris Burkov Subject: [PATCH v4 1/8] btrfs: lift rw mount setup from mount and remount Date: Wed, 21 Oct 2020 16:06:29 -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 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 | 93 ++++++++++++++++++++++++++-------------------- fs/btrfs/disk-io.h | 1 + fs/btrfs/super.c | 37 +++--------------- 3 files changed, 60 insertions(+), 71 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 3d39f5d47ad3..bff7a3a7be18 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2814,6 +2814,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) { @@ -3218,22 +3265,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); @@ -3286,35 +3317,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); + btrfs_discard_resume(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 fee69ced58b4..b3ee9c19be0c 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 8840a4fa81eb..56bfa23bc52f 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1831,7 +1831,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; @@ -1924,39 +1923,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 Oct 21 23:06:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11849947 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 2AC73C2D0A3 for ; Wed, 21 Oct 2020 23:07:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AF172221FB for ; Wed, 21 Oct 2020 23:07:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="SDs7g5cc"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="JDxjFxOW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2507020AbgJUXHI (ORCPT ); Wed, 21 Oct 2020 19:07:08 -0400 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]:40299 "EHLO wout3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2507008AbgJUXHH (ORCPT ); Wed, 21 Oct 2020 19:07:07 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id 94A8D1271; Wed, 21 Oct 2020 19:07:06 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 21 Oct 2020 19:07:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm2; bh=NwF33qAkYY5Jg 9aMFkZt1nVLSAqpXE9HhMnBgW6gFJg=; b=SDs7g5ccWG/f2+BuiWO9rmxoNCvRO 1g6KdityGE1yY0WhqHeVvNg6pjk3vKyMeruBpnh0lgu6XligFjCxuLpLpRMzfIl1 XoIDbbOQK0Y3n8DM9b6s152ab+wXfo19G+rLm3Y91AIqB2HGP4/HYaJmh0MX3aIN piYKSekLtChyR/DTOn3BJXlrra/5A3k39Z7bL3EcM8aQ8xNrH/Xd9mB8tpZ8ewtB lv8uetZxoGzywM7JIJz1o/8WALNaBOUsIhkVcdOEPY02Z9IkGHmccUZ3M+SU0YFl JhroW1ymCKe6g4Gv1IVlNUS0BMIcx0KYSAV887Rj8OEB1mpElLZtbrvLw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=NwF33qAkYY5Jg9aMFkZt1nVLSAqpXE9HhMnBgW6gFJg=; b=JDxjFxOW t7qzHVahhcvlAh9gqB+UVvV/8Wb7nVvoRjfMCSDhyc6J3xY3EHwKzlLTMS0guEeD kMlu5mChuI1f2kivpG9R3zglROaHRuhlzZ7x/x6OY59SLLP+DJBjt+ohWb8iGGcU ape8/ewNeQOqZl+1sYzQAYJfVnKTp0sjtbMn7cNCTdtGwR46vdTqiIV85VrkpWN9 NJ/QyBP82R56a6wZ8amrOH91soqQFun5EwOSLx4fBcILmJ/oqpcwzdxJHs13j+so 0y68ii97BMqUsrlpXkAmY1k88uwZ17F8J2WdFPsMkUuomwphAEEh/6kU8halgUvb ABpGq9IRNeP93Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrjeeigdduiecutefuodetggdotefrodftvf 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 CFE963064674; Wed, 21 Oct 2020 19:07:05 -0400 (EDT) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Boris Burkov Subject: [PATCH v4 2/8] btrfs: cleanup all orphan inodes on ro->rw remount Date: Wed, 21 Oct 2020 16:06:30 -0700 Message-Id: <56e0a8c18483c395d20fc6c69a42740d19742eb1.1603318242.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 bff7a3a7be18..95b9cc5db397 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2826,6 +2826,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); @@ -3308,15 +3316,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); - btrfs_discard_resume(fs_info); ret = btrfs_mount_rw(fs_info); if (ret) { From patchwork Wed Oct 21 23:06:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11849941 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 CF6EAC4363A for ; Wed, 21 Oct 2020 23:07:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3041E221FB for ; Wed, 21 Oct 2020 23:07:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="brBKznmu"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="HmW4Ande" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2507023AbgJUXHL (ORCPT ); Wed, 21 Oct 2020 19:07:11 -0400 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]:45907 "EHLO wout3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2507008AbgJUXHL (ORCPT ); Wed, 21 Oct 2020 19:07:11 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id D8E2212A9; Wed, 21 Oct 2020 19:07:09 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 21 Oct 2020 19:07:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm2; bh=pbEEpRRMeVfr/ JLu2Y9mitizi6bfqPhgMj7PIg4UQss=; b=brBKznmuyoOXgbQ7wlq7K71yDnnGS uDy4D2KCygNSFgNxacuQLFxLxv1ndEcrac6pijK4Kr+AShVLPPrLu8D4BisLdBFB afCM1r7oLcy3aT5SXvgHR3FAOaRZSyIfkjHvzBdAeXVpE+HuFU5c9JgrkTpbUOle DpVMQiOfZx4NexcH4REpMbbrOcoP2o+Pe12XOwsegRbraTrTXGET7cLzxONd6pKl 3wkMUkFxOIWI8Y+3U9TcP/M3qyQul0wQARFh0nXo9CGE8xwP/+QNyohJZ7nkhdLy f/DMw4ikIbDD6e/D0fhmVEPNw3xTppuFbmQ210g6OM2ys+Jb1ilx0ISQw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=pbEEpRRMeVfr/JLu2Y9mitizi6bfqPhgMj7PIg4UQss=; b=HmW4Ande UHq8zvVUfxIvQlLHGuxh7VlTjZ5qcN0iL+HksNReWvA3yw+r0OyJ6KuiYvLmL2TJ AEryOvkPV0mcC6By4iTKPbMhsUi5nwbg8d+uCXlT872BmtkU5H9CqovEyMNSDi/P mSHeUEWYBg1ltmcxkmUpcvW3IeJUGpesNZxt9hirfVj5GLlL8NV5qJ+lzO1jpVRn P1kJzQfdAO2Z0E4XLcuiYwrZlftGbW3wWH9B35UpJ4CdyxvLZt9Q0lCtF+gkZ/+7 a2vd9JU1BSqpRDqHSiZI6j0/yJraEYyhoZtYNstSJn4RfGp1PgeO0NaJn7JskqHK Ee8Su5zkZafHkQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrjeeigdduiecutefuodetggdotefrodftvf 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 1864D3064674; Wed, 21 Oct 2020 19:07:09 -0400 (EDT) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Boris Burkov Subject: [PATCH v4 3/8] btrfs: create free space tree on ro->rw remount Date: Wed, 21 Oct 2020 16:06:31 -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 95b9cc5db397..5fe0a2640c8a 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2842,6 +2842,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; @@ -3304,18 +3315,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; - } - } - btrfs_discard_resume(fs_info); ret = btrfs_mount_rw(fs_info); if (ret) { From patchwork Wed Oct 21 23:06:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11849953 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 31BE7C2D0A3 for ; Wed, 21 Oct 2020 23:07:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A83C4221FB for ; Wed, 21 Oct 2020 23:07:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="CxwJFQKR"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="peY5HlJG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2507025AbgJUXHP (ORCPT ); Wed, 21 Oct 2020 19:07:15 -0400 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]:33247 "EHLO wout3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2507008AbgJUXHO (ORCPT ); Wed, 21 Oct 2020 19:07:14 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id 273BE12A9; Wed, 21 Oct 2020 19:07:13 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 21 Oct 2020 19:07:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm2; bh=cUalwwj9NKtu4 GZyJd22wlWTDhhEwMEdZHSuXEnuKh0=; b=CxwJFQKR7q7tS1jQIpGJCfIAmIEWy 8upJmxdYPLogsD33ffXXjx1s4wCdAb9lpcc52+XECxsUOnW05VzbhQHrwAtDPFB2 VnMWgjziWCpRzMtKEPlWA+z7iwNJQX+UiCnmm+qhpqggim1QCH6XmarCfG2KiSvL TwcyTH6TqGOhVr5ug3aAkSlKEJFmoX06YvJjazv+gpLLPZQycuSKq6vNatmTcZUE 8nFr6lNlLaCia8cLinJGfH5D2dWMXNstsJ41B0+N2prIHrP44hWLg8ZDUx9bjZlm MbUL/KxdwWV2Y0cGy673pNAagu+1slSRirlXs9L/jsPYYwoqLqtpGhzXg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=cUalwwj9NKtu4GZyJd22wlWTDhhEwMEdZHSuXEnuKh0=; b=peY5HlJG wR70wrs2YkG+GAys3dwR7p2T5EuBnXUfqacXCwwgw+REx40DGQMSqgH8Y3ViNTma +hPURbqxHgXccJlPqoIgAfI65COhODfAmQN6qVauc8rimCL9wyY0HeIQu6KLZ0ND Ak8Kdd3SKxya1ULTV1nEyoza1puqltEgs3vlq835jPugOC1t0MKoCfUx0zVW1r3H siPa9wA6VygCLKr/FVlDtoSGxCn4WYUzh6MdGlMkz4az66YaIeJOGpxEHLGApsIQ 5n35eQzvsyFK65VPuoai0hEvxIn64WM1FMW9evUJQwaetiDjO2gVQPEMy3muL9cD 1amCgq9wW5Tziw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrjeeigdduiecutefuodetggdotefrodftvf 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 5607C3064674; Wed, 21 Oct 2020 19:07:12 -0400 (EDT) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Boris Burkov Subject: [PATCH v4 4/8] btrfs: keep sb cache_generation consistent with space_cache Date: Wed, 21 Oct 2020 16:06:32 -0700 Message-Id: <99b747e128a4fa1891e6eef76c0fa1e9d65e8a7d.1603318242.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 | 4 +--- fs/btrfs/transaction.c | 2 ++ 6 files changed, 45 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index aac3d6f4e35b..0ee85bf82cab 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 5fe0a2640c8a..f645ffdd2c7e 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2821,6 +2821,7 @@ static int btrfs_check_uuid_tree(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); ret = btrfs_cleanup_fs_roots(fs_info); if (ret) @@ -2853,6 +2854,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; @@ -3335,6 +3342,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); /* diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index af0013d3df63..3acf935536ea 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 56bfa23bc52f..fd3dbf419072 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -511,7 +511,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; @@ -521,10 +520,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); /* diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 52ada47aff50..c350fc59784b 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 Wed Oct 21 23:06:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11849957 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 76AB6C4363A for ; Wed, 21 Oct 2020 23:07:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0ECBC221FB for ; Wed, 21 Oct 2020 23:07:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="gCRXFvNO"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="DTNB3v2S" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2507028AbgJUXHR (ORCPT ); Wed, 21 Oct 2020 19:07:17 -0400 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]:40415 "EHLO wout3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2507008AbgJUXHR (ORCPT ); Wed, 21 Oct 2020 19:07:17 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id 58E1812A4; Wed, 21 Oct 2020 19:07:16 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 21 Oct 2020 19:07:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm2; bh=o+4Gls1Ddh0+i 8PYylHoHW3FXgfqFqg1B1hDR+WgZ9k=; b=gCRXFvNO3z/j1+7exjs/DJepSO+iH n1KoPkKN8/v/Wx1byy+IoeRV+Rw95mZ6a+e4mRtUq8qqUoB6ilVEy9QdfJFbwSIP Fyukd0ji33cJ98/06+/3NCCCNvKsEN7APk0Km6aSi+UZ2zq2d+AeQy+WO9FVJ45i SST8miFghdEcxzapFRHMth9362Z/CUThKJokKUDrDb6M03qANQ981UN92BmXCwRi GBbm9JgOkhsLjyW46H8ytlT7PBlGBG4Dv/tbyhp7DuVuFtsUPhX11tXJm6iWJkSY mAZB3iwabLgCS2SouRaoqXyLYcqKj7ZxcWPV3fT17hPq9sL+UC4s6JkUg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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+4Gls1Ddh0+i8PYylHoHW3FXgfqFqg1B1hDR+WgZ9k=; b=DTNB3v2S HEFoDkmXve11apmOIuqnn8UlqE/A7TSFwXSNo7TpuExlRzZLhKWLU9uTobG/3iRN Vv3Yzp4xCEem6mgTlAz5rFXTVj2ZsqGSH8hjEGWY1VzpFuLsOXShe27zQIGKnIFp e+wpcrQNIG2scZCMumUBDNxQ4gYwpS9THt+i+ho1OtlsD26yN3IQmRu21Zv+XcsF 1mpXv/iRMGspGxJJrv5MlMrb/uxdleLnttjhFGD11WLtPnAUd1XmH1H0vtzfzRlv kljbUnfhU0ptxSxOUmXxR6Smzg21zRVtBk/ImDjEIQCMn3o/BMkTKCzKs/4pAz1U FWakjpIIW20L9w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrjeeigdduiecutefuodetggdotefrodftvf 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 96FC23064674; Wed, 21 Oct 2020 19:07:15 -0400 (EDT) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Boris Burkov Subject: [PATCH v4 5/8] btrfs: use sb state to print space_cache mount option Date: Wed, 21 Oct 2020 16:06:33 -0700 Message-Id: <07f096a4826b78137d86f07878142655a5d059d8.1603318242.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 fd3dbf419072..c78e3379fa93 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1427,9 +1427,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 Oct 21 23:06:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11849955 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 4E1F2C4363A for ; Wed, 21 Oct 2020 23:07:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D47A3221FB for ; Wed, 21 Oct 2020 23:07:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="FJC/L4w0"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="X1BuKbDC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2507031AbgJUXHV (ORCPT ); Wed, 21 Oct 2020 19:07:21 -0400 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]:57525 "EHLO wout3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2507008AbgJUXHU (ORCPT ); Wed, 21 Oct 2020 19:07:20 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id 68A6912A9; Wed, 21 Oct 2020 19:07:19 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 21 Oct 2020 19:07:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm2; bh=pqUS+qLKnhfJZ w6LuzTGU4lKfTwCWKWCZ4sh8oRYeMU=; b=FJC/L4w0rQx8IUydQGw/KhXf//KOF B2axJqas7CVVxWje4EzZyMnOmhYfbTuktOi1e5BHRbKN6jdhj5vAZKc0oanMz+oV 9hPMbrEvvJWNutWz9n/1XX0I7vrAF6fdMd6dpj3AwgxOTOHYDTq67QHwO8YSJOAt dwxwZSYrXVOYnCNv+IqkAskVyBbA/y5zrzkvN+cqnpDHpMI0eNCIrWH0H4F3bqLL LtAOY4uLMaUNoJuUp4qP/bc1gvAeocwRj0LRx+UgKOLpquTZEy60cOQqCRsa9uKk RBFDdbGEKhbWgABM66SH4jh1sEKZqLGl0Ydo88sRyfzcNGdwh3PDnLEJw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=pqUS+qLKnhfJZw6LuzTGU4lKfTwCWKWCZ4sh8oRYeMU=; b=X1BuKbDC 1cRRIPo8TUs63zrifexXV0uDnN22EE2gNWDYojkaQBPa/atSoA6cwbn+FBgqKpZL 7pSVkUaVSkhwgqsirmC2b5eE/CcX22qCJJ7Dpx0TV0Q1hzZCD2qfy8C0xeXDu9xD So+KfhZy10vPXzHPsE3cSNCVWiACXOlYDwsangnXyKLBQu9OHmeUlMWBRlwvHPmo tSvPdgEDsD8H0bbMLmzoY3qX+ImXICTOlJKkrzmGrqA6TD3RwI7qpVsg966gfcyg pFbcCJJ/wnnWekC/hakDOOaL58cn33gzu4w6ovprfGrKOH1acYf5dDiZYGwnQpc6 nn006PhW/9DPzg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrjeeigdduiecutefuodetggdotefrodftvf 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 AD0E83064674; Wed, 21 Oct 2020 19:07:18 -0400 (EDT) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Boris Burkov Subject: [PATCH v4 6/8] btrfs: warn when remount will not create the free space tree Date: Wed, 21 Oct 2020 16:06:34 -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 the free space tree. This can be surprising, so print a warning to dmesg to make the failure more visible. Signed-off-by: Boris Burkov --- fs/btrfs/super.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index c78e3379fa93..5db278243a34 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1859,6 +1859,20 @@ 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 enabling free space tree only from ro to rw"); + /* + * if we aren't building the free space tree, reset + * the space cache options to what they were before + */ + btrfs_clear_opt(fs_info->mount_opt, FREE_SPACE_TREE); + if (btrfs_free_space_cache_v1_active(fs_info)) + btrfs_set_opt(fs_info->mount_opt, SPACE_CACHE); + } + if ((bool)(*flags & SB_RDONLY) == sb_rdonly(sb)) goto out; From patchwork Wed Oct 21 23:06:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11849949 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.8 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 4C611C4363A for ; Wed, 21 Oct 2020 23:07:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DFC7F22248 for ; Wed, 21 Oct 2020 23:07:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="gbj520jN"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="CYpbbojv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2507035AbgJUXHY (ORCPT ); Wed, 21 Oct 2020 19:07:24 -0400 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]:47179 "EHLO wout3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2507032AbgJUXHX (ORCPT ); Wed, 21 Oct 2020 19:07:23 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id 80D3912A6; Wed, 21 Oct 2020 19:07:22 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 21 Oct 2020 19:07:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm2; bh=fD/ynqnWQddNK rGuAAeWQqjuEl7+7yLEXTQ46LFt+Jc=; b=gbj520jNf5k705Q+RQyjBjwl4AA/n THO0sTkbBlzzdJ1p1Km0MVfwbU4Ii+o2+Mcm+3jP3atwZtrCwFzkDtzSrfICd2oH CYhQyBkOmX3Z8w9DWzmM8KGeWFpqcx0eQSBnPSxu7bXk6I+CpL3Wvs7d6l8iSl/F 1sw983jsho0yfwVYyB+yzRG6Bc6jrDdkOnMuIK+0ght2GrdwNAJeW4uobm7t3fyV RNdkeIhJDagdGrQ2NYnImd3mXmOkDvG1RV8LYH3udv6KzPnNDc5g7qq/gF8kcszd FFm+jrahw7U9odCPmhxiVuVgpC8BLJ2Hwis5LMqzxXwk2h47+g4Mh8hOA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=fD/ynqnWQddNKrGuAAeWQqjuEl7+7yLEXTQ46LFt+Jc=; b=CYpbbojv iWDsF63tLEuES9DQ4dbmQIgnsI+rbDLSIQk0X117vqtPk3hIOkE5Z6KY5k99r4Y9 XvlpnU+0np7ZgtHGtT/9/yflyqKChFR38DxG2CNrpzjtGhxTRZOZwy6UpD/cOhQF Rg8PpK7KfpCPRIaYiUR9MO62agUthc22KuoDRbbz9SyTxDHQ9P9z/gOHtfc7sIa9 VU/j0RXlZDwwEurSJ3sFq+7pKy0hENdnAc0UU1JH8s0uKIh30KD6d+0YflgFTSve U6ekcHfuXgS+qXjIA/yAbEFTyObVbuhatBAkTj30nzBrdYY6U49iVnhMB8mVQhab Z6VbnbQH20VNVg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrjeeigdduiecutefuodetggdotefrodftvf 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 9AB103064610; Wed, 21 Oct 2020 19:07:21 -0400 (EDT) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Boris Burkov Subject: [PATCH v4 7/8] btrfs: remove free space items when disabling space cache v1 Date: Wed, 21 Oct 2020 16:06:35 -0700 Message-Id: <4f335af44f7dd1ea9eabed46a32d7291a6d1cc55.1603318242.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 c0f1d6818df7..8938b11a3339 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 3acf935536ea..5d357786c9da 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 Wed Oct 21 23:06:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11849943 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 7880EC56201 for ; Wed, 21 Oct 2020 23:07:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 17C8422248 for ; Wed, 21 Oct 2020 23:07:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="RtPGbgd0"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="qvq0RmXu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2507048AbgJUXH2 (ORCPT ); Wed, 21 Oct 2020 19:07:28 -0400 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]:56927 "EHLO wout3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2507032AbgJUXH0 (ORCPT ); Wed, 21 Oct 2020 19:07:26 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id B94F312A4; Wed, 21 Oct 2020 19:07:25 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 21 Oct 2020 19:07:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm2; bh=cyLT8ihDVMziZ JFq7nEmekggQ/kxhXwGRc2vSDc47tA=; b=RtPGbgd06gen2iie1bvsxqDsJ0Joq V+Z/LTnGZh5fyril1sv9SCZC39btahhnsMFoUO9wy19ctbft659l1waxOWQMQNy5 X4TzndFHtZXeUbeoJbLOPMJ7o/neaaQ1N2/rPaSjlC/CR+zTdTOfJmvwQMWQTtGu mWvRHR+ukOEcvo59UX8WImIZdQhzLlNbnrxJflt+qsV22CbeiD8+t5aSSE1sGbJd qAjyewthgEXX7Lw9eMaAVnywoV7P70qiH2pkelpt2h/V3+IwkOE5hL2aMboHGp/A rflVvGEkK84ikEG3uzzj3e2fi8/0EX2REbso5qmiuyFTHGS6tq6ZB1ycA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=cyLT8ihDVMziZJFq7nEmekggQ/kxhXwGRc2vSDc47tA=; b=qvq0RmXu WG66nE8X/X8MR562LSv8hb930bMI1basylox1KD9bTwavyURvWDTvRDFecNoNq8l ii4kxXxOnBo5or+qLbxq2B9TCsk0z4t+2fllhn1ZioSR4KdmRC8emnvI3roGzknT cBwl34IWAjTpgM84/R40wbveCI2W/cCrzIpFeCLEEYwfVwkx8NR+y0edeR2uK0og 4aQ6TAkJ90zMR66wtz9TTAJawpx843BUYVBv6EptcmqoIczNhSppf5/ZeewBtddS zMG/P9YzpVeVWChvDtS2nFfvhc5ByWohL0K3dcNHXDZbZglhhifEj6Q26oXFlVFQ Utc5jqJ3aOi1Gw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrjeeigdduiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffojghfggfgsedtkeertd ertddtnecuhfhrohhmpeeuohhrihhsuceuuhhrkhhovhcuoegsohhrihhssegsuhhrrdhi oheqnecuggftrfgrthhtvghrnhepieeuffeuvdeiueejhfehiefgkeevudejjeejffevvd ehtddufeeihfekgeeuheelnecukfhppeduieefrdduudegrddufedvrdefnecuvehluhhs thgvrhfuihiivgepieenucfrrghrrghmpehmrghilhhfrhhomhepsghorhhishessghurh drihho X-ME-Proxy: Received: from localhost (unknown [163.114.132.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 0EB8B3064683; Wed, 21 Oct 2020 19:07:25 -0400 (EDT) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Boris Burkov Subject: [PATCH v4 8/8] btrfs: skip space_cache v1 setup when not using it Date: Wed, 21 Oct 2020 16:06:36 -0700 Message-Id: <92f5a39baff2daef37c5b5073afd5bbe876cd57b.1603318242.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 8938b11a3339..59a130fdcd5c 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -2325,6 +2325,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.