From patchwork Fri Aug 21 07:43:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gang He X-Patchwork-Id: 7049531 Return-Path: X-Original-To: patchwork-ocfs2-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1E9C1C05AC for ; Fri, 21 Aug 2015 07:46:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 267CD2054D for ; Fri, 21 Aug 2015 07:46:22 +0000 (UTC) Received: from aserp1040.oracle.com (aserp1040.oracle.com [141.146.126.69]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F06362037C for ; Fri, 21 Aug 2015 07:46:20 +0000 (UTC) Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t7L7ijRY031413 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 21 Aug 2015 07:44:46 GMT Received: from oss.oracle.com (oss-old-reserved.oracle.com [137.254.22.2]) by userv0021.oracle.com (8.13.8/8.13.8) with ESMTP id t7L7ijtN020304 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 21 Aug 2015 07:44:45 GMT Received: from localhost ([127.0.0.1] helo=lb-oss.oracle.com) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1ZSh0H-0005Ss-EO; Fri, 21 Aug 2015 00:44:45 -0700 Received: from aserv0022.oracle.com ([141.146.126.234]) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1ZSgzQ-0005Qg-IM for ocfs2-devel@oss.oracle.com; Fri, 21 Aug 2015 00:43:52 -0700 Received: from aserp1020.oracle.com (aserp1020.oracle.com [141.146.126.67]) by aserv0022.oracle.com (8.13.8/8.13.8) with ESMTP id t7L7hqLk004522 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 21 Aug 2015 07:43:52 GMT Received: from userp2040.oracle.com (userp2040.oracle.com [156.151.31.90]) by aserp1020.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t7L7hp0j030054 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Fri, 21 Aug 2015 07:43:52 GMT Received: from pps.filterd (userp2040.oracle.com [127.0.0.1]) by userp2040.oracle.com (8.15.0.59/8.15.0.59) with SMTP id t7L7NKmb045498 for ; Fri, 21 Aug 2015 07:43:51 GMT Received: from prv3-mh.provo.novell.com (victor.provo.novell.com [137.65.250.26]) by userp2040.oracle.com with ESMTP id 1wcx2vu3st-1 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Fri, 21 Aug 2015 07:43:51 +0000 Received: from ghe-pc.lab.bej.apac.novell.com (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by prv3-mh.provo.novell.com with ESMTP (TLS encrypted); Fri, 21 Aug 2015 01:43:42 -0600 From: Gang He To: mfasheh@suse.com, rgoldwyn@suse.de, ghe@suse.com Date: Fri, 21 Aug 2015 15:43:19 +0800 Message-Id: <1440143000-24956-4-git-send-email-ghe@suse.com> X-Mailer: git-send-email 2.1.2 In-Reply-To: <1440143000-24956-1-git-send-email-ghe@suse.com> References: <1440143000-24956-1-git-send-email-ghe@suse.com> X-ServerName: victor.provo.novell.com X-Proofpoint-Virus-Version: vendor=nai engine=5700 definitions=7899 signatures=670626 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1507310000 definitions=main-1508210127 Cc: linux-kernel@vger.kernel.org, ocfs2-devel@oss.oracle.com Subject: [Ocfs2-devel] [PATCH 3/4] ocfs2: filecheck validate_extent_block function X-BeenThere: ocfs2-devel@oss.oracle.com X-Mailman-Version: 2.1.9 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ocfs2-devel-bounces@oss.oracle.com Errors-To: ocfs2-devel-bounces@oss.oracle.com X-Source-IP: userv0021.oracle.com [156.151.31.71] X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add validate_extent_block/repair_extent_block functions for online filecheck. Signed-off-by: Gang He --- fs/ocfs2/alloc.c | 116 +++++++++++++++++++++++++++++++++++++++++++++++++ fs/ocfs2/alloc.h | 4 ++ fs/ocfs2/ocfs2_trace.h | 24 ++++++++++ 3 files changed, 144 insertions(+) diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c index 0afb4cb..35fbbf1 100644 --- a/fs/ocfs2/alloc.c +++ b/fs/ocfs2/alloc.c @@ -51,6 +51,7 @@ #include "xattr.h" #include "refcounttree.h" #include "ocfs2_trace.h" +#include "filecheck.h" #include "buffer_head_io.h" @@ -934,6 +935,121 @@ bail: return rc; } +static int ocfs2_filecheck_validate_extent_block(struct super_block *sb, + struct buffer_head *bh) +{ + int rc; + struct ocfs2_extent_block *eb = + (struct ocfs2_extent_block *)bh->b_data; + + trace_ocfs2_filecheck_validate_extent_block( + (unsigned long long)bh->b_blocknr); + + BUG_ON(!buffer_uptodate(bh)); + + if (!OCFS2_IS_VALID_EXTENT_BLOCK(eb)) { + mlog(ML_ERROR, + "Filecheck: extent block #%llu has bad signature %.*s\n", + (unsigned long long)bh->b_blocknr, + 7, eb->h_signature); + return -OCFS2_FILECHECK_ERR_INVALIDEXT; + } + + rc = ocfs2_validate_meta_ecc(sb, bh->b_data, &eb->h_check); + if (rc) { + mlog(ML_ERROR, "Filecheck: checksum failed for extent " + "block %llu\n", + (unsigned long long)bh->b_blocknr); + return -OCFS2_FILECHECK_ERR_BLOCKECC; + } + + if (le64_to_cpu(eb->h_blkno) != bh->b_blocknr) { + mlog(ML_ERROR, + "Filecheck: extent block #%llu has an invalid h_blkno " + "of %llu\n", + (unsigned long long)bh->b_blocknr, + (unsigned long long)le64_to_cpu(eb->h_blkno)); + return -OCFS2_FILECHECK_ERR_BLOCKNO; + } + + if (le32_to_cpu(eb->h_fs_generation) != OCFS2_SB(sb)->fs_generation) { + mlog(ML_ERROR, + "Filecheck: extent block #%llu has an invalid " + "h_fs_generation of #%u\n", + (unsigned long long)bh->b_blocknr, + le32_to_cpu(eb->h_fs_generation)); + return -OCFS2_FILECHECK_ERR_GENERATION; + } + + return 0; +} + +static int ocfs2_filecheck_repair_extent_block(struct super_block *sb, + struct buffer_head *bh) +{ + int rc; + int changed = 0; + struct ocfs2_extent_block *eb = + (struct ocfs2_extent_block *)bh->b_data; + + rc = ocfs2_filecheck_validate_extent_block(sb, bh); + /* Can't fix invalid extent block */ + if (!rc || rc == -OCFS2_FILECHECK_ERR_INVALIDEXT) + return rc; + + trace_ocfs2_filecheck_repair_extent_block( + (unsigned long long)bh->b_blocknr); + + if (le64_to_cpu(eb->h_blkno) != bh->b_blocknr) { + eb->h_blkno = cpu_to_le64(bh->b_blocknr); + changed = 1; + mlog(ML_ERROR, + "Filecheck: reset extent block #%llu: h_blkno to %llu\n", + (unsigned long long)bh->b_blocknr, + (unsigned long long)le64_to_cpu(eb->h_blkno)); + } + + if (le32_to_cpu(eb->h_fs_generation) != OCFS2_SB(sb)->fs_generation) { + eb->h_fs_generation = cpu_to_le32(OCFS2_SB(sb)->fs_generation); + changed = 1; + mlog(ML_ERROR, + "Filecheck: reset extent block #%llu: " + "h_fs_generation to %u\n", + (unsigned long long)bh->b_blocknr, + le32_to_cpu(eb->h_fs_generation)); + } + + if (changed || ocfs2_validate_meta_ecc(sb, bh->b_data, &eb->h_check)) { + ocfs2_compute_meta_ecc(sb, bh->b_data, &eb->h_check); + mark_buffer_dirty(bh); + mlog(ML_ERROR, + "Filecheck: reset extent block #%llu: compute meta ecc\n", + (unsigned long long)bh->b_blocknr); + } + + return 0; +} + +int +ocfs2_filecheck_read_extent_block(struct ocfs2_caching_info *ci, u64 eb_blkno, + struct buffer_head **bh, unsigned int flags) +{ + int rc; + struct buffer_head *tmp = *bh; + + if (!flags) /* check extent block */ + rc = ocfs2_read_block(ci, eb_blkno, &tmp, + ocfs2_filecheck_validate_extent_block); + else /* repair extent block */ + rc = ocfs2_read_block(ci, eb_blkno, &tmp, + ocfs2_filecheck_repair_extent_block); + + if (!rc && !*bh) + *bh = tmp; + + return rc; +} + int ocfs2_read_extent_block(struct ocfs2_caching_info *ci, u64 eb_blkno, struct buffer_head **bh) { diff --git a/fs/ocfs2/alloc.h b/fs/ocfs2/alloc.h index fb09b97..c882d52 100644 --- a/fs/ocfs2/alloc.h +++ b/fs/ocfs2/alloc.h @@ -92,6 +92,10 @@ void ocfs2_init_refcount_extent_tree(struct ocfs2_extent_tree *et, int ocfs2_read_extent_block(struct ocfs2_caching_info *ci, u64 eb_blkno, struct buffer_head **bh); +int +ocfs2_filecheck_read_extent_block(struct ocfs2_caching_info *ci, u64 eb_blkno, + struct buffer_head **bh, unsigned int flags); + struct ocfs2_alloc_context; int ocfs2_insert_extent(handle_t *handle, struct ocfs2_extent_tree *et, diff --git a/fs/ocfs2/ocfs2_trace.h b/fs/ocfs2/ocfs2_trace.h index d9205e0..4788748 100644 --- a/fs/ocfs2/ocfs2_trace.h +++ b/fs/ocfs2/ocfs2_trace.h @@ -557,6 +557,30 @@ TRACE_EVENT(ocfs2_validate_extent_block, TP_printk("%llu ", __entry->blkno) ); +TRACE_EVENT(ocfs2_filecheck_validate_extent_block, + TP_PROTO(unsigned long long blkno), + TP_ARGS(blkno), + TP_STRUCT__entry( + __field(unsigned long long, blkno) + ), + TP_fast_assign( + __entry->blkno = blkno; + ), + TP_printk("%llu ", __entry->blkno) +); + +TRACE_EVENT(ocfs2_filecheck_repair_extent_block, + TP_PROTO(unsigned long long blkno), + TP_ARGS(blkno), + TP_STRUCT__entry( + __field(unsigned long long, blkno) + ), + TP_fast_assign( + __entry->blkno = blkno; + ), + TP_printk("%llu ", __entry->blkno) +); + TRACE_EVENT(ocfs2_rotate_leaf, TP_PROTO(unsigned int insert_cpos, int insert_index, int has_empty, int next_free,