From patchwork Mon Nov 14 18:43:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 9428237 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 14E756047D for ; Mon, 14 Nov 2016 18:43:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0953528A66 for ; Mon, 14 Nov 2016 18:43:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F09F928ABE; Mon, 14 Nov 2016 18:43:45 +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 70DFB28A66 for ; Mon, 14 Nov 2016 18:43:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754566AbcKNSnj (ORCPT ); Mon, 14 Nov 2016 13:43:39 -0500 Received: from mail-pg0-f54.google.com ([74.125.83.54]:36282 "EHLO mail-pg0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932515AbcKNSng (ORCPT ); Mon, 14 Nov 2016 13:43:36 -0500 Received: by mail-pg0-f54.google.com with SMTP id f188so56725822pgc.3 for ; Mon, 14 Nov 2016 10:43:35 -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=GmSFM0WujcBnFfU1kVrav+EmU9IaO3DcmUVFOM9Sfrk=; b=hRh2+KmWoXdD5Stn1I+rAkOmsY7IW/scQmHte1odKnX+F70Owwb1dbkoQ8e1Sb8vvG ZgRM3c2uKceYgKqnUnTacnn5ml7Nfs4JqeWcRM2scKdgMmufJp1GtFHiMsknj/1t57iL nIdCiCbEtooQqsS7hdY6cwcpEJ34jEh1zXe0Ghu++c6r3ZWCUcEcqd2sn93dJlFPna2a msU5E4pOD30ro+7XYgRzm2RmhhthhovmeiRDAE++9BIkby7gEPNpBiiElRB9746qePn6 X9ACcr2AAVj2oBDaiDa3wGOJpXZ9vsXU5YofNVUrhX8PVjhcoAQYz6eNAbaUp2h/jHyJ cUtg== 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=GmSFM0WujcBnFfU1kVrav+EmU9IaO3DcmUVFOM9Sfrk=; b=fSMuPyrc2uj9UyjEOuQwFxMWZR192Y7uVmXiPEcODkdLqNG4g4HJ0Wts8dvKhztL9g XSpkcf6rKGcw5cUdwXxrVDQsD1bQDJUtRK7Eb5k9v++qIym3ffqFZSE5/GjjoJtixdIh QkgTsV94rdeyke9jzVQU2qGTF5/SWj5P+d0DrAuj9lhb2W4dtlpxtNQ369l68Wlvlz+C LwoV2TUS6X57uE6xQxUjTcMrkRsepOmyDfrQYno9yxN2AdOixvVn/4OnTMHpwGeHq9sV 8UecGM3B7Y1PCJLpPJaV+gGd1XKg3LmWesIymddUAS6+yMi6KSuKtyJJ9QnR0/kYiTQ5 0Gfw== X-Gm-Message-State: ABUngvfHYwvcw2v4Pzoyi08RQPS3l/QHXPxFD6hO3ibur8qnnITUepfIqfPQqveFbXbQOJvO X-Received: by 10.99.208.21 with SMTP id z21mr71333547pgf.79.1479149015176; Mon, 14 Nov 2016 10:43:35 -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.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Nov 2016 10:43:34 -0800 (PST) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com Subject: [PATCH v2 5/6] btrfs-progs: implement btrfs check --clear-space-cache v2 Date: Mon, 14 Nov 2016 10:43:22 -0800 Message-Id: <2135f82dce6ff2d1bca06d57a74cf70748c43b83.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 Reviewed-by: Qu Wenruo Signed-off-by: Omar Sandoval --- Documentation/btrfs-check.asciidoc | 14 +++++++++----- cmds-check.c | 34 +++++++++++++++++++++++++--------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/Documentation/btrfs-check.asciidoc b/Documentation/btrfs-check.asciidoc index 5ef414e..633cbbf 100644 --- a/Documentation/btrfs-check.asciidoc +++ b/Documentation/btrfs-check.asciidoc @@ -80,12 +80,16 @@ superblock is damaged. --clear-space-cache v1|v2:: completely wipe all free space cache of given type - -NOTE: Only v1 free space cache supported is implemented. + -Kernel mount option 'clear_cache' is only designed to rebuild free space cache -which is modified during the lifetime of that mount option. It doesn't rebuild -all free space cache, nor clear them out. +For free space cache 'v1', the 'clear_cache' kernel mount option only rebuilds +the free space cache for block groups that are modified while the filesystem is +mounted with that option. Thus, using this option with 'v1' makes it possible +to actually clear the entire free space cache. ++ +For free space cache 'v2', the 'clear_cache' kernel mount option does destroy +the entire free space cache. This option with 'v2' provides an alternative +method of clearing the free space cache that doesn't require mounting the +filesystem. DANGEROUS OPTIONS diff --git a/cmds-check.c b/cmds-check.c index 57c4300..0eca102 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -11170,7 +11170,6 @@ const char * const cmd_check_usage[] = { "--chunk-root use the given bytenr for the chunk tree root", "-p|--progress indicate progress", "--clear-space-cache v1|v2 clear space cache for v1 or v2", - " NOTE: v1 support implemented", NULL }; @@ -11292,13 +11291,16 @@ int cmd_check(int argc, char **argv) } break; case GETOPT_VAL_CLEAR_SPACE_CACHE: - if (strcmp(optarg, "v1") != 0) { - error( - "only v1 support implmented, unrecognized value %s", - optarg); + if (strcmp(optarg, "v1") == 0) { + clear_space_cache = 1; + } else if (strcmp(optarg, "v2") == 0) { + clear_space_cache = 2; + ctree_flags |= OPEN_CTREE_INVALIDATE_FST; + } else { + error("invalid argument to --clear-space-cache; " + "must be v1 or v2"); exit(1); } - clear_space_cache = 1; ctree_flags |= OPEN_CTREE_WRITES; break; } @@ -11352,11 +11354,10 @@ int cmd_check(int argc, char **argv) global_info = info; root = info->fs_root; - if (clear_space_cache) { + if (clear_space_cache == 1) { if (btrfs_fs_compat_ro(info, BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE)) { - error( - "free space cache v2 detected, clearing not implemented"); + error("free space cache v2 detected; use --clear-space-cache v2"); ret = 1; goto close_out; } @@ -11369,6 +11370,21 @@ int cmd_check(int argc, char **argv) printf("Free space cache cleared\n"); } goto close_out; + } else if (clear_space_cache == 2) { + if (!btrfs_fs_compat_ro(info, BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE)) { + printf("No free space cache v2 to clear\n"); + ret = 0; + goto close_out; + } + printf("Clear free space cache v2\n"); + ret = btrfs_clear_free_space_tree(info); + if (ret) { + error("Failed to clear free space cache v2"); + ret = 1; + } else { + printf("Free space cache v2 cleared\n"); + } + goto close_out; } /*