From patchwork Thu Jul 26 20:38:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10546447 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 5E3E5180E for ; Thu, 26 Jul 2018 20:38:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 31E4B2BAA5 for ; Thu, 26 Jul 2018 20:38:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 256362BACA; Thu, 26 Jul 2018 20:38:24 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,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 952792BAA5 for ; Thu, 26 Jul 2018 20:38:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730587AbeGZV4x (ORCPT ); Thu, 26 Jul 2018 17:56:53 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:42760 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730533AbeGZV4x (ORCPT ); Thu, 26 Jul 2018 17:56:53 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w6QKYBNN170218; Thu, 26 Jul 2018 20:38:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2018-07-02; bh=zpauoWKOwb93ZZhnZkwTfaJA6kL/lKCPL0iVW4uJxr4=; b=HnqCfeclKCr7IbYC1JRRSaQYpz09h2rYP3o9qDD6bcIxbpP3f1/8EmKRG7hF1GTAhoOl Ff+Y90rrStNkJxAL8iPLlpNLRfGzit/rYxbSRSotNSlOW/C50RV0FyRzVaRDP1J0/biB CscJm5oA0iZkxnvcZjQRZ8mBMp4eD8dBQNQ/95kBlSgqKXjc7Us+1q+z/dAQBb2REYho 936cZ1QQMIuABcw5jmzVoXPDc3R9HV+cZnrHE/AwkV9YIJsx2qme7XQLCuZU8q5fIOaD TH/DRs7W+7VHJszwDF7Y/zeBJ9ckTqbjvcfJwSd/9exLRXeFBRNZ5vNuW6Ot5FDL4HF1 Hg== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2kbv8tcrtx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 26 Jul 2018 20:38:17 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w6QKcG4Z031077 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 26 Jul 2018 20:38:16 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w6QKcGAL015758; Thu, 26 Jul 2018 20:38:16 GMT Received: from localhost (/10.159.237.146) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 26 Jul 2018 13:38:15 -0700 Date: Thu, 26 Jul 2018 13:38:14 -0700 From: "Darrick J. Wong" To: sandeen@redhat.com Cc: linux-xfs@vger.kernel.org Subject: [PATCH v2 12/10] xfs_repair: use libxfs extsize/cowextsize validation helpers Message-ID: <20180726203814.GH30972@magnolia> References: <153006766483.20121.9285982017465570544.stgit@magnolia> <20180628173008.GJ5711@magnolia> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180628173008.GJ5711@magnolia> User-Agent: Mutt/1.9.4 (2018-02-28) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8966 signatures=668706 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-1806210000 definitions=main-1807260210 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Darrick J. Wong Now that we've ported the extent size hint verifiers to libxfs, call them from xfs_repair instead of open-coding the checks. Tweak the repair message slightly to reflect the fact that we zero the field and clear the inode flag if the hint is garbage or is inconsistent with the inode flags. Signed-off-by: Darrick J. Wong Reviewed-by: Eric Sandeen --- v2: fix error message to reflect what actually happened --- libxfs/libxfs_api_defs.h | 2 + repair/dinode.c | 75 ++++++++++++++++------------------------------ 2 files changed, 28 insertions(+), 49 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index e5cf1554..fe8336ab 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -98,6 +98,8 @@ #define xfs_dinode_calc_crc libxfs_dinode_calc_crc #define xfs_idata_realloc libxfs_idata_realloc #define xfs_idestroy_fork libxfs_idestroy_fork +#define xfs_inode_validate_extsize libxfs_inode_validate_extsize +#define xfs_inode_validate_cowextsize libxfs_inode_validate_cowextsize #define xfs_rmap_ag_owner libxfs_rmap_ag_owner #define xfs_rmap_alloc libxfs_rmap_alloc diff --git a/repair/dinode.c b/repair/dinode.c index fb65ee22..cf1a0ad8 100644 --- a/repair/dinode.c +++ b/repair/dinode.c @@ -2841,24 +2841,21 @@ _("bad (negative) size %" PRId64 " on inode %" PRIu64 "\n"), * only regular files with REALTIME or EXTSIZE flags set can have * extsize set, or directories with EXTSZINHERIT. */ - if (be32_to_cpu(dino->di_extsize) != 0) { - if ((type == XR_INO_RTDATA) || - (type == XR_INO_DIR && (be16_to_cpu(dino->di_flags) & - XFS_DIFLAG_EXTSZINHERIT)) || - (type == XR_INO_DATA && (be16_to_cpu(dino->di_flags) & - XFS_DIFLAG_EXTSIZE))) { - /* s'okay */ ; - } else { - do_warn( -_("bad non-zero extent size %u for non-realtime/extsize inode %" PRIu64 ", "), - be32_to_cpu(dino->di_extsize), lino); - if (!no_modify) { - do_warn(_("resetting to zero\n")); - dino->di_extsize = 0; - *dirty = 1; - } else - do_warn(_("would reset to zero\n")); - } + if (libxfs_inode_validate_extsize(mp, + be32_to_cpu(dino->di_extsize), + be16_to_cpu(dino->di_mode), + be16_to_cpu(dino->di_flags)) != NULL) { + do_warn( +_("Bad extent size %u on inode %" PRIu64 ", "), + be32_to_cpu(dino->di_extsize), lino); + if (!no_modify) { + do_warn(_("resetting to zero\n")); + dino->di_extsize = 0; + dino->di_flags &= ~cpu_to_be16(XFS_DIFLAG_EXTSIZE | + XFS_DIFLAG_EXTSZINHERIT); + *dirty = 1; + } else + do_warn(_("would reset to zero\n")); } /* @@ -2866,41 +2863,21 @@ _("bad non-zero extent size %u for non-realtime/extsize inode %" PRIu64 ", "), * set can have extsize set. */ if (dino->di_version >= 3 && - be32_to_cpu(dino->di_cowextsize) != 0) { - if ((type == XR_INO_DIR || type == XR_INO_DATA) && - (be64_to_cpu(dino->di_flags2) & - XFS_DIFLAG2_COWEXTSIZE)) { - /* s'okay */ ; - } else { - do_warn( -_("Cannot have non-zero CoW extent size %u on non-cowextsize inode %" PRIu64 ", "), - be32_to_cpu(dino->di_cowextsize), lino); - if (!no_modify) { - do_warn(_("resetting to zero\n")); - dino->di_flags2 &= ~cpu_to_be64(XFS_DIFLAG2_COWEXTSIZE); - dino->di_cowextsize = 0; - *dirty = 1; - } else - do_warn(_("would reset to zero\n")); - } - } - - /* - * Can't have the COWEXTSIZE flag set with no hint. - */ - if (dino->di_version >= 3 && - be32_to_cpu(dino->di_cowextsize) == 0 && - (be64_to_cpu(dino->di_flags2) & XFS_DIFLAG2_COWEXTSIZE)) { + libxfs_inode_validate_cowextsize(mp, + be32_to_cpu(dino->di_cowextsize), + be16_to_cpu(dino->di_mode), + be16_to_cpu(dino->di_flags), + be64_to_cpu(dino->di_flags2)) != NULL) { do_warn( -_("Cannot have CoW extent size of zero on cowextsize inode %" PRIu64 ", "), - lino); +_("Bad CoW extent size %u on inode %" PRIu64 ", "), + be32_to_cpu(dino->di_cowextsize), lino); if (!no_modify) { - do_warn(_("clearing cowextsize flag\n")); + do_warn(_("resetting to zero\n")); dino->di_flags2 &= ~cpu_to_be64(XFS_DIFLAG2_COWEXTSIZE); + dino->di_cowextsize = 0; *dirty = 1; - } else { - do_warn(_("would clear cowextsize flag\n")); - } + } else + do_warn(_("would reset to zero\n")); } /* nsec fields cannot be larger than 1 billion */