From patchwork Tue Oct 27 21:07: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: 11861893 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 AEB3EC55178 for ; Tue, 27 Oct 2020 21:08:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 51EA520738 for ; Tue, 27 Oct 2020 21:08:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="NUKRwpUs"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="NvIH+dUw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1832067AbgJ0VIh (ORCPT ); Tue, 27 Oct 2020 17:08:37 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:57579 "EHLO out5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1832061AbgJ0VIh (ORCPT ); Tue, 27 Oct 2020 17:08:37 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 278675C00CC; Tue, 27 Oct 2020 17:08:36 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Tue, 27 Oct 2020 17:08:36 -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=NUKRwpUs0caKSSDrWa1pA4of3VRBq I/dXKUucialyA1fdpxHVX3zPnIj7iuYIZtLOg/Pjq/PMGwt9bHl3WXqEDBYKwfRU Ol/pP39COsspYDjq6zO9bP1IQk0TUWom+C3C/gfwyM+88EqDyd3NM7hz1kk/yQpB k4CQmc5A12z/wDSZJyPDUPsYCbllqjyYbPPJqMufx/XGWbEIlRnI2sBJSbbVZk03 X3xkoQ0I4EbevQQ7+wb2sY+u7Kad6vmP/aMIWAmf1PI9NfbOACE/9TTdlQnBmh4y mfSXpNFWHPTp1uC441Ixp0c6NGCE3SWXBUSfaDVRjbXJyCx9JfYagQREw== 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=NvIH+dUw fAoBPY1SUa+lQaHHVaMDv+4gXSPnAU4LLU2wygdrxWmWxyBA6YMkWaaunNwdold7 SQL09pnRsY46PIpYJRpspNHBzmqsWbmlD+9nqnI2TmXQarjmHH2cE6o7Hf3Qh/1g GJ+04bOuv7MnHzBFIgxqQOBokvgAOw8lEpdtW0rMiujlx0Xf+fXRxe+XR7h6Umfy P934pH4sh66SjoFBIqpFxm8QV44kZSJUVIIP29aB5CKFhSHo7ZomPyjmA6PHG7w3 x43ja5XLqwzTwrWf1Y0CIx2OIkSl54AJq85WUgbRv2Hp+mHIPddXW6iDLfZjItkG HL3kufEG9q51dg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrkeelgddugeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepuehorhhishcuuehurhhkohhvuceosghorhhishessghurhdr ihhoqeenucggtffrrghtthgvrhhnpeeiueffuedvieeujefhheeigfekvedujeejjeffve dvhedtudefiefhkeegueehleenucfkphepudeifedruddugedrudefvddrieenucevlhhu shhtvghrufhiiigvpedvnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhrihhssegsuh hrrdhioh X-ME-Proxy: Received: from localhost (unknown [163.114.132.6]) by mail.messagingengine.com (Postfix) with ESMTPA id 778803280059; Tue, 27 Oct 2020 17:08:35 -0400 (EDT) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Boris Burkov Subject: [PATCH v5 03/10] btrfs: create free space tree on ro->rw remount Date: Tue, 27 Oct 2020 14:07:57 -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) {