From patchwork Mon Mar 26 08:27:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 10307375 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 C9CD1600CC for ; Mon, 26 Mar 2018 08:28:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B0F8E2881E for ; Mon, 26 Mar 2018 08:28:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A5B8C295C2; Mon, 26 Mar 2018 08:28:20 +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, UNPARSEABLE_RELAY 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 2C3C12881E for ; Mon, 26 Mar 2018 08:28:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752286AbeCZI1t (ORCPT ); Mon, 26 Mar 2018 04:27:49 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:41186 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750980AbeCZIZ4 (ORCPT ); Mon, 26 Mar 2018 04:25:56 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w2Q8Jpe1039946 for ; Mon, 26 Mar 2018 08:25:56 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2017-10-26; bh=v+ZAQ6RLFTuQuGTmey6orHdI0uVlk2iR0svUUIZGOy8=; b=RJFx1FccIJyIQgixQpJRRBuI17iE7cBVN1C0Zg34g6wkRxSLas6bqHDfVnRKdABcAqsb H9xeJZh1zVVwBvaXf0e6MqwbDQO1hFfjOuo3+SIZsUU5qD9e1yGhwUQXzIrvZKdXox8T rNHoW15QaqUv1gAho9hRH3mqTGPnRPYpZef/U+505rJxqlJc+8motTZFvcQmngudHADF ST6KNeKLsTIkX5R5w/dWwngfEVAnpa5/fjD2Y1lEWPMIBHwCgTICghwZEhwLh+UkK/5Q CJZ5ZtWSyVjLHSrYCb5+/41k2z5Dc+o0mY4eoIStqMcf+qIyqzw12H8o8dZx47HngBtL Cg== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2130.oracle.com with ESMTP id 2gxw8gg0r7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 26 Mar 2018 08:25:55 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w2Q8PtKC025107 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 26 Mar 2018 08:25:55 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w2Q8PsCc010921 for ; Mon, 26 Mar 2018 08:25:54 GMT Received: from tp.sg.oracle.com (/10.186.53.63) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 26 Mar 2018 01:25:54 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 2/8] btrfs: return required error from btrfs_check_super_csum Date: Mon, 26 Mar 2018 16:27:35 +0800 Message-Id: <20180326082742.9235-3-anand.jain@oracle.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20180326082742.9235-1-anand.jain@oracle.com> References: <20180326082742.9235-1-anand.jain@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8843 signatures=668695 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1803260088 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 Return the required -EINVAL and -EUCLEAN from the function btrfs_check_super_csum(). And more the error log into the parent function. Signed-off-by: Anand Jain --- fs/btrfs/disk-io.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index b9b435579527..8b4e602ed60a 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -392,9 +392,10 @@ static int verify_parent_transid(struct extent_io_tree *io_tree, /* * Return 0 if the superblock checksum type matches the checksum value of that * algorithm. Pass the raw disk superblock data. + * Otherwise: -EINVAL if csum type is not found + * -EUCLEAN if csum does not match */ -static int btrfs_check_super_csum(struct btrfs_fs_info *fs_info, - char *raw_disk_sb) +static int btrfs_check_super_csum(char *raw_disk_sb) { struct btrfs_super_block *disk_sb = (struct btrfs_super_block *)raw_disk_sb; @@ -402,11 +403,8 @@ static int btrfs_check_super_csum(struct btrfs_fs_info *fs_info, u32 crc = ~(u32)0; char result[sizeof(crc)]; - if (csum_type >= ARRAY_SIZE(btrfs_csum_sizes)) { - btrfs_err(fs_info, "unsupported checksum algorithm %u", - csum_type); - return 1; - } + if (csum_type >= ARRAY_SIZE(btrfs_csum_sizes)) + return -EINVAL; /* * The super_block structure does not span the whole @@ -418,7 +416,7 @@ static int btrfs_check_super_csum(struct btrfs_fs_info *fs_info, btrfs_csum_final(crc, result); if (memcmp(raw_disk_sb, result, sizeof(result))) - return 1; + return -EUCLEAN; return 0; } @@ -2570,9 +2568,16 @@ int open_ctree(struct super_block *sb, * We want to check superblock checksum, the type is stored inside. * Pass the whole disk block of size BTRFS_SUPER_INFO_SIZE (4k). */ - if (btrfs_check_super_csum(fs_info, bh->b_data)) { - btrfs_err(fs_info, "superblock checksum mismatch"); - err = -EINVAL; + err = btrfs_check_super_csum(bh->b_data); + if (err) { + if (err == -EINVAL) + pr_err("BTRFS error (device %pg): "\ + "unsupported checksum algorithm", + fs_devices->latest_bdev); + else + pr_err("BTRFS error (device %pg): "\ + "superblock checksum mismatch", + fs_devices->latest_bdev); brelse(bh); goto fail_alloc; }