Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2346307ybz; Thu, 23 Apr 2020 16:27:40 -0700 (PDT) X-Google-Smtp-Source: APiQypI1SO7upqpVoqLlnjV6ALnfGp5lXecwMG4y6/h0STMtq3gWwESmlez0Xdc/AUoGwJSPlLwP X-Received: by 2002:a50:8d02:: with SMTP id s2mr5125141eds.81.1587684460362; Thu, 23 Apr 2020 16:27:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587684460; cv=none; d=google.com; s=arc-20160816; b=ZDV+UHAYwXSiWgmCilQKf7spWiMv10L48xDG9Ymxvd9DwztlPDhr3oAoGIGVIHlPSu HuWckNAxXYgEQCjv5+YdebGlt3JV+vZhq469e7Tu+Yr2buX9UcwRBVlLSpDFovZZWma0 iVorGmrMwiUzAAFjJihio8/MlZGq1Gij025RRwkmVCcqWT8N51hoX4cjv65MhnyOIAOE a6wxmzojCECLyQ8kM/qc9kWXAv6blKu9XZ3rsyo0awoaZWh/Q0JWNDCbig2Undy5gS7g RUhgOcxA2sQ0NDwyYTQHsbDZ2Wn2duw5orFjsjgJIZeZsXH8w6N6zWp5g4g7qe4atQT/ sa1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=deUXP6Vk0rePxReuxiEmtUAj04Sivek44Nfz3scAKyM=; b=Kj9aYPM04Xv3GXUyDBlqL/2MARspHjRcmJur9p8oVPVtZo8SfT/Zn5vBWgixx4D4f+ ogsjvQIaUlGsMSbFgJ2dkJ4Lr2+ZhEI3YV+yU9Wkz4/U/l2IuZ7enDACwa80nTK8vgeV MuLkNQ7/FDK2XjwH3ly0BTjYYtt+1//IOpu9lxrqI6ukZXtz7XiAgDXaYcG8AJAMEc1t WqNzF3BLj34iUHdqj5fxkLEFB8FhDRom6Eki0wfPu8ELaERKXnTomDyBZy0pd/9gZ4TQ GAvblxnAn8o8OUBUawv+fyeCc0/jXiSHJVOx+uson6MzXJn4TnZRp+Nx0mI7oyPI7iJR FzMA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l4si2068872ede.294.2020.04.23.16.27.17; Thu, 23 Apr 2020 16:27:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729912AbgDWXXs (ORCPT + 99 others); Thu, 23 Apr 2020 19:23:48 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:48392 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728162AbgDWXGa (ORCPT ); Thu, 23 Apr 2020 19:06:30 -0400 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1jRkvK-0004aw-BN; Fri, 24 Apr 2020 00:06:26 +0100 Received: from ben by deadeye with local (Exim 4.93) (envelope-from ) id 1jRkvJ-00E6ha-93; Fri, 24 Apr 2020 00:06:25 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, Denis Kirjanov , "David Sterba" , "Greg Kroah-Hartman" , "Ben Hutchings" , "Qu Wenruo" Date: Fri, 24 Apr 2020 00:04:30 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 043/245] btrfs: tree-checker: Enhance btrfs_check_node output In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.83-rc1 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.4: - Use root->sectorsize instead of root->fs_info->sectorsize - BTRFS_NODEPTRS_PER_BLOCK() takes a root instead of an fs_info, and yields a value of type size_t instead of unsigned int] Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman Signed-off-by: Ben Hutchings --- 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,%zu]", + 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; } }