From patchwork Mon Aug 12 06:19:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 11089359 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6CD3D912 for ; Mon, 12 Aug 2019 06:19:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5EB6B228C9 for ; Mon, 12 Aug 2019 06:19:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5352426E47; Mon, 12 Aug 2019 06:19:27 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 F235C228C9 for ; Mon, 12 Aug 2019 06:19:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726486AbfHLGT0 (ORCPT ); Mon, 12 Aug 2019 02:19:26 -0400 Received: from mx2.suse.de ([195.135.220.15]:50316 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726185AbfHLGT0 (ORCPT ); Mon, 12 Aug 2019 02:19:26 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 1B5C6AC63 for ; Mon, 12 Aug 2019 06:19:25 +0000 (UTC) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH v2 2/3] btrfs-progs: check/original: Check and repair root item geneartion Date: Mon, 12 Aug 2019 14:19:07 +0800 Message-Id: <20190812061908.21002-3-wqu@suse.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190812061908.21002-1-wqu@suse.com> References: <20190812061908.21002-1-wqu@suse.com> MIME-Version: 1.0 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 Add such ability to original mode to fix root generation mismatch, which can be rejected by kernel. Signed-off-by: Qu Wenruo --- check/main.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/check/main.c b/check/main.c index 98b07fcb58c8..ae3ce13e9466 100644 --- a/check/main.c +++ b/check/main.c @@ -3437,8 +3437,10 @@ static int check_fs_root(struct btrfs_root *root, { int ret = 0; int err = 0; + bool generation_err = false; int wret; int level; + u64 super_generation; struct btrfs_path path; struct shared_node root_node; struct root_record *rec; @@ -3449,6 +3451,23 @@ static int check_fs_root(struct btrfs_root *root, struct unaligned_extent_rec_t *urec; struct unaligned_extent_rec_t *tmp; + super_generation = btrfs_super_generation(root->fs_info->super_copy); + if (btrfs_root_generation(root_item) > super_generation + 1) { + error( + "invalid generation for root %llu, have %llu expect (0, %llu]", + root->root_key.objectid, btrfs_root_generation(root_item), + super_generation + 1); + generation_err = true; + if (repair) { + root->node->flags |= EXTENT_BAD_TRANSID; + ret = recow_extent_buffer(root, root->node); + if (!ret) { + printf("Reset generation for root %llu\n", + root->root_key.objectid); + generation_err = false; + } + } + } /* * Reuse the corrupt_block cache tree to record corrupted tree block * @@ -3597,6 +3616,8 @@ skip_walking: free_corrupt_blocks_tree(&corrupt_blocks); root->fs_info->corrupt_blocks = NULL; + if (!ret && generation_err) + ret = -1; return ret; }