Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp10787489imu; Thu, 6 Dec 2018 06:50:02 -0800 (PST) X-Google-Smtp-Source: AFSGD/V6k0bnTplDBpt+dI0UTq/BfFQ0LPdhKKLR/msEgOK1DPhniZg3RgQChuVJQET46wwt2FFj X-Received: by 2002:a17:902:7d90:: with SMTP id a16mr18884356plm.249.1544107801964; Thu, 06 Dec 2018 06:50:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544107801; cv=none; d=google.com; s=arc-20160816; b=oCWLzFfEPR30sCid5ZP+9jjUTwm86IlMVoCDxDQRXZWJe9D9xYaF6k2nKpvvNFALe9 knWmiwmbSrXiq038TmMDMFBIRi4X8hbHXhTTrOnng4XcfOen40CTDKDF5xokkErFd0sn 8PnzaUmaTzLqHC6VsGwYaqX82eBUb5v4yrErxC/CzKGy2zisgplO/t2ajwsdeYD5UOwL O14haCqjOuqUjg9TBgu0wTZR7qyD4+k+7XbYrXQRMoIsTZMbRawA6gP+o4QvpTkeZQjz elIs3YQTFGw7Y8FZXj7sAaYhOhSmdQGcMAP1YKzWEqv0ivmrQJAb0nsMuTr+tUPL/tbs HOtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=AR0BGuQwVlCM1IhoSbshtKKJcK7NtvS8KnDxeocH/zI=; b=aQEE14sMhl98V+NUcfr/YfsACo/naYQE7EK21fy7prLZrf41BxSZZRPohkxBK1hk+O VEnOnmmnN3McXllAAz17D28Cn7IUY/JJ8Yz3F2Ezp+9owisfcJMZAp6Gl6dnW+MQawmL 4U2ALMUeetSRJOzhMPvGa8suHiN4sspjgPC2fUEyBfd6sMspOcZPTSAq3Sh6mESEMx30 sGFEM086fN03rVwBnT0W6wAcNDyFdf6jyNIdv3bdY/6Q6zPl9bXXz9yiRY9qz1jvJ25a kXYSYS1aeqUNeffNu+pKIG3Jd7NOLh9nVOYfLopTa7jcRCmvUTnm4kdRqDyWvSprWaJ/ hSwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FLaSpIb7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e13si381599pgh.251.2018.12.06.06.49.46; Thu, 06 Dec 2018 06:50:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FLaSpIb7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731608AbeLFOsf (ORCPT + 99 others); Thu, 6 Dec 2018 09:48:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:53752 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730868AbeLFOsd (ORCPT ); Thu, 6 Dec 2018 09:48:33 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7E83E20661; Thu, 6 Dec 2018 14:48:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544107712; bh=fRu4WCy68cY01Wtz4220ySWBY3Bj3Tua/DX/RA+AxqM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FLaSpIb7JQ6llieanXrOYM5IWe7jk63aE3Yb2RTbM2P6WQzsiGZh0zh4mc+ZBCOmv MJRLVfmaCGFdEfZLEBm/pE0yG71FFybJQ0iEDbV/5wFmo+vupG5BR0dCE2rDmu/g/+ VTGOCBMoQmj9KHfsf+6ThBh2v8WYKMQphHXoboeU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qu Wenruo , David Sterba , Ben Hutchings Subject: [PATCH 4.9 073/101] btrfs: tree-checker: Enhance btrfs_check_node output Date: Thu, 6 Dec 2018 15:39:12 +0100 Message-Id: <20181206143016.245720372@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181206143011.174892052@linuxfoundation.org> References: <20181206143011.174892052@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Qu Wenruo commit bba4f29896c986c4cec17bc0f19f2ce644fceae1 upstream. Use inline function to replace macro since we don't need stringification. (Macro still exists until all callers get updated) And add more info about the error, and replace EIO with EUCLEAN. For nr_items error, report if it's too large or too small, and output the valid value range. For node block pointer, added a new alignment checker. For key order, also output the next key to make the problem more obvious. Signed-off-by: Qu Wenruo [ wording adjustments, unindented long strings ] Signed-off-by: David Sterba [bwh: Backported to 4.9: - Use root->sectorsize instead of root->fs_info->sectorsize - BTRFS_NODEPTRS_PER_BLOCK() takes a root instead of an fs_info] Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/tree-checker.c | 68 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 7 deletions(-) --- a/fs/btrfs/tree-checker.c +++ b/fs/btrfs/tree-checker.c @@ -37,6 +37,46 @@ btrfs_header_level(eb) == 0 ? "leaf" : "node", \ reason, btrfs_header_bytenr(eb), root->objectid, slot) +/* + * Error message should follow the following format: + * corrupt : , [, ] + * + * @type: leaf or node + * @identifier: the necessary info to locate the leaf/node. + * It's recommened to decode key.objecitd/offset if it's + * meaningful. + * @reason: describe the error + * @bad_value: optional, it's recommened to output bad value and its + * expected value (range). + * + * Since comma is used to separate the components, only space is allowed + * inside each component. + */ + +/* + * Append generic "corrupt leaf/node root=%llu block=%llu slot=%d: " to @fmt. + * Allows callers to customize the output. + */ +__printf(4, 5) +static void generic_err(const struct btrfs_root *root, + const struct extent_buffer *eb, int slot, + const char *fmt, ...) +{ + struct va_format vaf; + va_list args; + + va_start(args, fmt); + + vaf.fmt = fmt; + vaf.va = &args; + + btrfs_crit(root->fs_info, + "corrupt %s: root=%llu block=%llu slot=%d, %pV", + btrfs_header_level(eb) == 0 ? "leaf" : "node", + root->objectid, btrfs_header_bytenr(eb), slot, &vaf); + va_end(args); +} + static int check_extent_data_item(struct btrfs_root *root, struct extent_buffer *leaf, struct btrfs_key *key, int slot) @@ -282,9 +322,11 @@ int btrfs_check_node(struct btrfs_root * if (nr == 0 || nr > BTRFS_NODEPTRS_PER_BLOCK(root)) { btrfs_crit(root->fs_info, - "corrupt node: block %llu root %llu nritems %lu", - node->start, root->objectid, nr); - return -EIO; +"corrupt node: root=%llu block=%llu, nritems too %s, have %lu expect range [1,%u]", + root->objectid, node->start, + nr == 0 ? "small" : "large", nr, + BTRFS_NODEPTRS_PER_BLOCK(root)); + return -EUCLEAN; } for (slot = 0; slot < nr - 1; slot++) { @@ -293,14 +335,26 @@ int btrfs_check_node(struct btrfs_root * btrfs_node_key_to_cpu(node, &next_key, slot + 1); if (!bytenr) { - CORRUPT("invalid item slot", node, root, slot); - ret = -EIO; + generic_err(root, node, slot, + "invalid NULL node pointer"); + ret = -EUCLEAN; + goto out; + } + if (!IS_ALIGNED(bytenr, root->sectorsize)) { + generic_err(root, node, slot, + "unaligned pointer, have %llu should be aligned to %u", + bytenr, root->sectorsize); + ret = -EUCLEAN; goto out; } if (btrfs_comp_cpu_keys(&key, &next_key) >= 0) { - CORRUPT("bad key order", node, root, slot); - ret = -EIO; + generic_err(root, node, slot, + "bad key order, current (%llu %u %llu) next (%llu %u %llu)", + key.objectid, key.type, key.offset, + next_key.objectid, next_key.type, + next_key.offset); + ret = -EUCLEAN; goto out; } }