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);