From patchwork Sun Nov 13 19:35:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 9424915 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6A35B60233 for ; Sun, 13 Nov 2016 19:42:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 56F58288AF for ; Sun, 13 Nov 2016 19:42:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C302288E9; Sun, 13 Nov 2016 19:42:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D6BC6288E7 for ; Sun, 13 Nov 2016 19:42:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934799AbcKMTmJ (ORCPT ); Sun, 13 Nov 2016 14:42:09 -0500 Received: from mail-pf0-f172.google.com ([209.85.192.172]:36726 "EHLO mail-pf0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932504AbcKMTmI (ORCPT ); Sun, 13 Nov 2016 14:42:08 -0500 Received: by mail-pf0-f172.google.com with SMTP id 189so24689865pfz.3 for ; Sun, 13 Nov 2016 11:42:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=whcivYNqDvexbff2pAsuvVeoUApcOc2YxiTM83qwmtc=; b=ryVAqmKh4HaAe5CZ2L5rA8W0F5DmJfuQODiC+lbg0sRIyHNnSMCnU9JUo+b2Sp3x+1 XEJW1wMCi7bl7B4EIlAa6H0PHPB5z+AWDKp76aOWjT5RwZ/e6LFzaEjWH5SMkbXYDwTB 3cJDP5WPRLfa5FLva6LOUXoFoTJHjNAxMyWSe1ahXfmtLn/9OiRCUfs2xxUlPsTVva4h GPofu5uM1PUveVxd/S0P1CqEdXsH7EK7w0/YdNyuFDLggiCd1zN+dBNFM21pqLt7PY7s 3hAtjA4DzDqj3sOt8j2oanRIbnx753Nfj8goTGnrNhBbbCYyNQ5uk33eNXrgVWlKZDc0 3Clw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=whcivYNqDvexbff2pAsuvVeoUApcOc2YxiTM83qwmtc=; b=IoTaQ2q9MuwPrNFY9onm7Yl7XUX9JkwBPRwrzmJPecBv2mqB9r0HuqcdVHP8xFlMG5 jmyi6g7gPOwH/D6XQRZdNWRR9mpWlKsFZWkuuf7XZJ98Ey/sC0p/0iJxDPDIyLM79kAD x2NKYmhjMhfTp1b3sssNg8wDTXrBIRyuyxM/aqMULlGQ9t+NmUeqIo75ur0J8BO2sgkf O06ZNh5fdQoa8AjhIXgr+8alNVaoc5s78GkfFRpJpo5DdZuttTf0xSZ6Htq8LxyNsnzu vIgwabijWXeX3rZJzJndD28hkRsXwU7RMicZxJUEWc1s96PIRppNqhRKLQfMT8FHMPmW 4x6Q== X-Gm-Message-State: ABUngvczqhOcY2UWTO2Fdx2hc/lhMiQwaBWOvBhFMFFCNPkg4lOeT8JaEJUXih9ZJA5baKCD X-Received: by 10.98.78.88 with SMTP id c85mr28687254pfb.138.1479065735339; Sun, 13 Nov 2016 11:35:35 -0800 (PST) Received: from localhost.localdomain ([2601:602:8801:8110:1a5e:fff:fea7:e0ef]) by smtp.gmail.com with ESMTPSA id v76sm8289029pfk.77.2016.11.13.11.35.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 Nov 2016 11:35:34 -0800 (PST) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com Subject: [PATCH 3/6] btrfs-progs: add OPEN_CTREE_INVALIDATE_FST flag Date: Sun, 13 Nov 2016 11:35:21 -0800 Message-Id: X-Mailer: git-send-email 2.10.2 In-Reply-To: References: In-Reply-To: References: Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Omar Sandoval If this flag is passed to open_ctree(), we'll clear the FREE_SPACE_TREE_VALID compat_ro bit. The kernel will then reconstruct the free space tree the next time the filesystem is mounted. Signed-off-by: Omar Sandoval Reviewed-by: Qu Wenruo --- chunk-recover.c | 2 +- disk-io.c | 28 ++++++++++++++++++---------- disk-io.h | 8 +++++++- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/chunk-recover.c b/chunk-recover.c index e33ee8b..e6b26ac 100644 --- a/chunk-recover.c +++ b/chunk-recover.c @@ -1477,7 +1477,7 @@ open_ctree_with_broken_chunk(struct recover_control *rc) memcpy(fs_info->fsid, &disk_super->fsid, BTRFS_FSID_SIZE); - ret = btrfs_check_fs_compatibility(disk_super, 1); + ret = btrfs_check_fs_compatibility(disk_super, OPEN_CTREE_WRITES); if (ret) goto out_devices; diff --git a/disk-io.c b/disk-io.c index a576300..a55fcc1 100644 --- a/disk-io.c +++ b/disk-io.c @@ -904,7 +904,7 @@ free_all: return NULL; } -int btrfs_check_fs_compatibility(struct btrfs_super_block *sb, int writable) +int btrfs_check_fs_compatibility(struct btrfs_super_block *sb, unsigned flags) { u64 features; @@ -923,13 +923,22 @@ int btrfs_check_fs_compatibility(struct btrfs_super_block *sb, int writable) btrfs_set_super_incompat_flags(sb, features); } - features = btrfs_super_compat_ro_flags(sb) & - ~BTRFS_FEATURE_COMPAT_RO_SUPP; - if (writable && features) { - printk("couldn't open RDWR because of unsupported " - "option features (%Lx).\n", - (unsigned long long)features); - return -ENOTSUP; + features = btrfs_super_compat_ro_flags(sb); + if (flags & OPEN_CTREE_WRITES) { + if (flags & OPEN_CTREE_INVALIDATE_FST) { + /* Clear the FREE_SPACE_TREE_VALID bit on disk... */ + features &= ~BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE_VALID; + btrfs_set_super_compat_ro_flags(sb, features); + /* ... and ignore the free space tree bit. */ + features &= ~BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE; + } + if (features & ~BTRFS_FEATURE_COMPAT_RO_SUPP) { + printk("couldn't open RDWR because of unsupported " + "option features (%Lx).\n", + (unsigned long long)features); + return -ENOTSUP; + } + } return 0; } @@ -1320,8 +1329,7 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path, memcpy(fs_info->fsid, &disk_super->fsid, BTRFS_FSID_SIZE); - ret = btrfs_check_fs_compatibility(fs_info->super_copy, - flags & OPEN_CTREE_WRITES); + ret = btrfs_check_fs_compatibility(fs_info->super_copy, flags); if (ret) goto out_devices; diff --git a/disk-io.h b/disk-io.h index 8ab36aa..5d4b281 100644 --- a/disk-io.h +++ b/disk-io.h @@ -74,6 +74,12 @@ enum btrfs_open_ctree_flags { /* Allow to open a partially created filesystem */ OPEN_CTREE_FS_PARTIAL = (1U << 12), + + /* + * Invalidate the free space tree (i.e., clear the FREE_SPACE_TREE_VALID + * compat_ro bit). + */ + OPEN_CTREE_INVALIDATE_FST = (1U << 13), }; /* @@ -128,7 +134,7 @@ int clean_tree_block(struct btrfs_trans_handle *trans, void btrfs_free_fs_info(struct btrfs_fs_info *fs_info); struct btrfs_fs_info *btrfs_new_fs_info(int writable, u64 sb_bytenr); -int btrfs_check_fs_compatibility(struct btrfs_super_block *sb, int writable); +int btrfs_check_fs_compatibility(struct btrfs_super_block *sb, unsigned flags); int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info, u64 root_tree_bytenr, unsigned flags); void btrfs_release_all_roots(struct btrfs_fs_info *fs_info);