From patchwork Wed Nov 18 23:06:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 11916097 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9017C64E69 for ; Wed, 18 Nov 2020 23:06:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3C321246A6 for ; Wed, 18 Nov 2020 23:06:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="RNYjwNM5"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="m6kSFwWP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726963AbgKRXGh (ORCPT ); Wed, 18 Nov 2020 18:06:37 -0500 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:55521 "EHLO wout2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726588AbgKRXGg (ORCPT ); Wed, 18 Nov 2020 18:06:36 -0500 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id 75799CB5; Wed, 18 Nov 2020 18:06:53 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 18 Nov 2020 18:06:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=from :to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=fm2; bh=u/1qGS3weBrAzq6EszV7UslQgz 6RAD2sf0UlFOd1vgE=; b=RNYjwNM56XE7YXsUsx2lH35th8EKiK5jT4S+nQuhvW 8j7u22rfs8hHQv9ihdQLV5O00rEktlf07HZhH/ifYsifD3jrgcC6PqP6OQWCeT9X eFJVRmzdNgD2yClPVGgM9UfoMh1Rl8mwuA8pr1f25S7iD6Kp20EwgztH8dKy7p8X 4cXgZf8SiQtKdzFIJC1aFg4Qnrp7bP5sQWQVlAFzxTnpEA7H+DOwtjqW8VzUlFAW hmsPzZcO0P6EYNXznXUjTD6O7Eql659H9p9zwBM40xokF46C335vIdhYhObMyJL0 4szup6rNidgIF1k2Tq9Ks7IwRkdTTbUAPZcF92qbQGBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=u/1qGS3weBrAzq6EszV7UslQgz6RAD2sf0UlFOd1vgE=; b=m6kSFwWP wNP+KNCfBe0ySAXh4hxAdt4PEUlgWlZK2c6cRpyctYa3euIHz8vxtJQ2LQvHmG9d ldOwEWeHYpz+6EU2yW9QlwYOX5sAjGEYytmfV5yM3i79c075ngY+EMIAMTYiWi5a AS2TcFH7FKuJCGWOmKM9yLtbzgGXeE8pTtxFyABoDeO19tt+t3D4X5j/2r1cVr1h UdGoCCume+scUtFiIMgAB8mSvPl8rD0UqFEsrMXGeivfD/yhA46MQ9glz2nFUxXL e1HJiXmqdiEOsey56S2TtKpwHtsZLgcsxCgqbOuwq3fAqw0FNCRG0Drw+W+4dzV/ ugEqY7dejp6GmQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudefiedgtdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepuehorhhishcuuehurhhkohhvuceosghorhhishessghurhdr ihhoqeenucggtffrrghtthgvrhhnpeeiueffuedvieeujefhheeigfekvedujeejjeffve dvhedtudefiefhkeegueehleenucfkphepudeifedruddugedrudefvddrfeenucevlhhu shhtvghrufhiiigvpedvnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhrihhssegsuh hrrdhioh X-ME-Proxy: Received: from localhost (unknown [163.114.132.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 9F73B3280064; Wed, 18 Nov 2020 18:06:52 -0500 (EST) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v7 04/12] btrfs: create free space tree on ro->rw remount Date: Wed, 18 Nov 2020 15:06:19 -0800 Message-Id: <464597922f2cb83486301a2ba6767cfbb9959c7e.1605736355.git.boris@bur.io> X-Mailer: git-send-email 2.24.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org When a user attempts to remount a btrfs filesystem with 'mount -o remount,space_cache=v2', that operation silently succeeds. Unfortunately, this is misleading, because the remount does not create the free space tree. /proc/mounts will incorrectly show space_cache=v2, but on the next mount, the file system will revert to the old space_cache. For now, we handle only the easier case, where the existing mount is read-only and the new mount is read-write. In that case, we can create the free space tree without contending with the block groups changing as we go. Signed-off-by: Boris Burkov --- fs/btrfs/disk-io.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 2cf81a4e9393..d934eb80ff49 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2912,6 +2912,17 @@ int btrfs_mount_rw(struct btrfs_fs_info *fs_info) goto out; } + if (btrfs_test_opt(fs_info, FREE_SPACE_TREE) && + !btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) { + btrfs_info(fs_info, "creating free space tree"); + ret = btrfs_create_free_space_tree(fs_info); + if (ret) { + btrfs_warn(fs_info, + "failed to create free space tree: %d", ret); + goto out; + } + } + ret = btrfs_resume_balance_async(fs_info); if (ret) goto out; @@ -3376,18 +3387,6 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device } } - if (btrfs_test_opt(fs_info, FREE_SPACE_TREE) && - !btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) { - btrfs_info(fs_info, "creating free space tree"); - ret = btrfs_create_free_space_tree(fs_info); - if (ret) { - btrfs_warn(fs_info, - "failed to create free space tree: %d", ret); - close_ctree(fs_info); - return ret; - } - } - ret = btrfs_mount_rw(fs_info); if (ret) { close_ctree(fs_info);