From patchwork Thu Apr 24 03:19:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Shilong X-Patchwork-Id: 4045571 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 62B5D9F387 for ; Thu, 24 Apr 2014 03:22:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7CE73201B4 for ; Thu, 24 Apr 2014 03:22:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AB10920179 for ; Thu, 24 Apr 2014 03:22:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751893AbaDXDWa (ORCPT ); Wed, 23 Apr 2014 23:22:30 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:21762 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751451AbaDXDW3 (ORCPT ); Wed, 23 Apr 2014 23:22:29 -0400 X-IronPort-AV: E=Sophos;i="4.97,916,1389715200"; d="scan'208";a="29658030" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 24 Apr 2014 11:19:47 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s3O3MEq6005664 for ; Thu, 24 Apr 2014 11:22:14 +0800 Received: from wangs.fnst.cn.fujitsu.com (10.167.226.104) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.146.2; Thu, 24 Apr 2014 11:22:14 +0800 From: Wang Shilong To: Subject: [PATCH 1/3] Btrfs-progs: fsck: clear out log tree in repair mode Date: Thu, 24 Apr 2014 11:19:16 +0800 Message-ID: <1398309558-29509-1-git-send-email-wangsl.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.9.0 MIME-Version: 1.0 X-Originating-IP: [10.167.226.104] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Repair mode will commit transaction which will make us fail to load log tree anymore. Give a warning to common users, if they really want to coninue, we will clear out log tree. Signed-off-by: Wang Shilong --- cmds-check.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/cmds-check.c b/cmds-check.c index 93f9ae6..15806a4 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -6615,6 +6615,22 @@ out: return ret; } +static int zero_log_tree(struct btrfs_root *root) +{ + struct btrfs_trans_handle *trans; + int ret; + + trans = btrfs_start_transaction(root, 1); + if (IS_ERR(trans)) { + ret = PTR_ERR(trans); + return ret; + } + btrfs_set_super_log_root(root->fs_info->super_copy, 0); + btrfs_set_super_log_root_level(root->fs_info->super_copy, 0); + ret = btrfs_commit_transaction(trans, root); + return ret; +} + static struct option long_options[] = { { "super", 1, NULL, 's' }, { "repair", 0, NULL, 0 }, @@ -6719,6 +6735,23 @@ int cmd_check(int argc, char **argv) } root = info->fs_root; + /* + * repair mode will force us to commit transaction which + * will make us fail to load log tree when mounting. + */ + if (repair && btrfs_super_log_root(info->super_copy)) { + ret = ask_user("repair mode will force to clear out log tree, Are you sure?"); + if (!ret) { + ret = 1; + goto close_out; + } + ret = zero_log_tree(root); + if (ret) { + fprintf(stderr, "fail to zero log tree\n"); + goto close_out; + } + } + uuid_unparse(info->super_copy->fsid, uuidbuf); printf("Checking filesystem on %s\nUUID: %s\n", argv[optind], uuidbuf);