From patchwork Sun Nov 13 19:35:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 9424921 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 A580560233 for ; Sun, 13 Nov 2016 19:43:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F54F287AC for ; Sun, 13 Nov 2016 19:43:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 811CA288B1; Sun, 13 Nov 2016 19:43:55 +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 E158E287AC for ; Sun, 13 Nov 2016 19:43:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934316AbcKMTnw (ORCPT ); Sun, 13 Nov 2016 14:43:52 -0500 Received: from mail-pg0-f49.google.com ([74.125.83.49]:33883 "EHLO mail-pg0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934208AbcKMTnv (ORCPT ); Sun, 13 Nov 2016 14:43:51 -0500 Received: by mail-pg0-f49.google.com with SMTP id x23so41522655pgx.1 for ; Sun, 13 Nov 2016 11:43:51 -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=U94epnfaLuMNfiNiVb+PlLN39SPRrKYbrk0dzXMi17Y=; b=fAN/RI8iXvUoelZ0rBeGGyYv6Sx4QdGhN76rxb9c95MJ56e7DHwXn14JfHg5IUmFki EOVrVNWrEy0eDyLobzV3OzkKXohu4SvyE9s/t1aIrhaAjgO/JIqbI8//q0yWpaF+yPz/ AM8+MfiQe1XwI8XDfqmETC1g1HcaJpXlamsx0PK03uoqdMS4u5xU18H4xfh2DIh1+Fgh aRlptItaf2M06OVVcABg3QPPyILh0+vzKFnQrDkfZ5jnACOEODsXlkpOiA8zNghiFHes zx9GPASFqM9MbYzA7tUsIrwHDD9xEaTYXqgqdmqKJtyjuoiCasVGhQXRzi71WWyK9oCJ 1IYQ== 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=U94epnfaLuMNfiNiVb+PlLN39SPRrKYbrk0dzXMi17Y=; b=gA+UcJlNbsM52lwPlIDyRBoNkFV9sMwsxtKQHUNw/pBe6ONw1jDiwDUtNU77VODOaC 0X27ao/k+qlzfc7h0+46XvrgaI4jxYT/WOpUpL7aRL2AMICxOiJi3rqjkPYCLeblvEBU bxn9J5y3rrIv/2TNOn8r+3TWK9W8xrA4A/UkQo1APtmCvDRvAIsIoWf64M/oZip9Dz7M Z5sK1oGi1z7u6ogZ1+BQeapYZsCKbrIf6dU6cmK6IAHlRVDPxlycPfGKG6H1OH9/LHEp rX051WhvjP1F87/hMP5tyvfcS1+0C8wM8Vxnxp/GNjdDxAY4li7Y2V9D5qD8sY7CYh/0 vy0Q== X-Gm-Message-State: ABUngvdYrzzr+elsutl8/hUgf1jal5Gbdlp34Zp0xiH2cV/MEtplE+bOaQ6FZqgllCpK0UXv X-Received: by 10.98.202.72 with SMTP id n69mr29074383pfg.24.1479065736948; Sun, 13 Nov 2016 11:35:36 -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.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 Nov 2016 11:35:36 -0800 (PST) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com Subject: [PATCH 5/6] btrfs-progs: implement btrfs check --clear-space-cache v2 Date: Sun, 13 Nov 2016 11:35:23 -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 Signed-off-by: Omar Sandoval Reviewed-by: Qu Wenruo --- 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; } /*