From patchwork Mon Nov 14 18:43:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 9428243 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 6F9606047D for ; Mon, 14 Nov 2016 18:43:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6426228A66 for ; Mon, 14 Nov 2016 18:43:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 590B228ABA; Mon, 14 Nov 2016 18:43:53 +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 E15A128A66 for ; Mon, 14 Nov 2016 18:43:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933682AbcKNSns (ORCPT ); Mon, 14 Nov 2016 13:43:48 -0500 Received: from mail-pg0-f48.google.com ([74.125.83.48]:33393 "EHLO mail-pg0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753468AbcKNSne (ORCPT ); Mon, 14 Nov 2016 13:43:34 -0500 Received: by mail-pg0-f48.google.com with SMTP id 3so56981444pgd.0 for ; Mon, 14 Nov 2016 10:43:34 -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=YD5uP++WdtblYCiyO7c02ETRQBwF6ZLnAlsljOHgKEc=; b=Ye5EehunaQpOeUhlQsEEUD7wFBvr34LL5ZsVMhfUEQYqp6/fdcTMnX5a2hGX6ZkCjt if8aAvHRLbDHJbvy0e28A37+wDBqAuJ4y4Skg4VmmsXIj2YyB3Pck9yABMIqkMZDKUF1 fUqJksJFxDB8Po2gegZFsJ/qU1VaZXvFgqWVjxPJkzl+o36QeVESvQz9DW2YyZg2xMSz OZ3cQfrLeKHfdHwe5u/T8Col4VIxEfliHEufui22VG86qb/H2mIbDsdG1rSzV21EAM42 NJjQfOxy/QJ56cLHdwfsUNu6jXVMRNQkXHgNH39hbSsk+vXs18mVFOQtBrWo4kIiFVUC e3ww== 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=YD5uP++WdtblYCiyO7c02ETRQBwF6ZLnAlsljOHgKEc=; b=RH9Yi1cjxARBO9BeGKR4AHDP8Siz6PHafx1vv6ZFyodm37Zm27KrXgtSVImlpnTIPW 2U5q/Qe9QpQJd+5F+dlzmNON/x6ctFpgL3bBh6JfZp8jCF74FmdV/Q+p/6JiQEhKH79B CvWiv+uDvrFheLQbmX5DeJEcusjHvtOxHvfFC6T1vca0pBlyO1nwc8Gf0D1NJJB22j6m LSKaRi0yGc/cqXJBgpl1G5eA+1w5nESAh/HaiS0NC3wdIr/FKtQimMIhXrymy0kX/heW cxbZeO0kCtRdA9A+2incrAzsE+PnN37e8RN4dyYp2URfeAJ8xJ7pIMoQVL8sZbzEysm0 MjLA== X-Gm-Message-State: ABUngvce6g79Q9lTP3XeC39FiLpAoxL8pZ7QMsIdYxgAB/PP4+NPjIWvvtCA0HJqxFr8OZQQ X-Received: by 10.99.127.72 with SMTP id p8mr71238257pgn.183.1479149013721; Mon, 14 Nov 2016 10:43:33 -0800 (PST) Received: from vader.thefacebook.com ([2620:10d:c090:200::a:38b9]) by smtp.gmail.com with ESMTPSA id v76sm15488481pfk.77.2016.11.14.10.43.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Nov 2016 10:43:33 -0800 (PST) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com Subject: [PATCH v2 3/6] btrfs-progs: add OPEN_CTREE_INVALIDATE_FST flag Date: Mon, 14 Nov 2016 10:43:20 -0800 Message-Id: <761a130a531803e85e75b7332a2393e8e950396d.1479148594.git.osandov@fb.com> 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. Reviewed-by: Qu Wenruo Signed-off-by: Omar Sandoval --- chunk-recover.c | 2 +- disk-io.c | 29 +++++++++++++++++++---------- disk-io.h | 9 ++++++++- 3 files changed, 28 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..de25fcd 100644 --- a/disk-io.c +++ b/disk-io.c @@ -904,7 +904,8 @@ 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 int flags) { u64 features; @@ -923,13 +924,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 +1330,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..d4a0e7f 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,8 @@ 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 int 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);