From patchwork Wed Aug 26 22:12:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 7080441 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 09413BF036 for ; Wed, 26 Aug 2015 22:12:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F0B21208E2 for ; Wed, 26 Aug 2015 22:12:50 +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 BB60F208DA for ; Wed, 26 Aug 2015 22:12:49 +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 t7QMCbWQ012805 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 26 Aug 2015 22:12:38 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 t7QMCbWV007835 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 26 Aug 2015 22:12:37 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 1ZUivs-00071s-W3; Wed, 26 Aug 2015 15:12:36 -0700 Received: from aserv0021.oracle.com ([141.146.126.233]) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1ZUivs-00071g-0P for ocfs2-devel@oss.oracle.com; Wed, 26 Aug 2015 15:12:36 -0700 Received: from aserp1020.oracle.com (aserp1020.oracle.com [141.146.126.67]) by aserv0021.oracle.com (8.13.8/8.13.8) with ESMTP id t7QMCZeW025995 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 26 Aug 2015 22:12:35 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 t7QMCZjS010297 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Wed, 26 Aug 2015 22:12:35 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 t7QMB7l4044122 for ; Wed, 26 Aug 2015 22:12:34 GMT Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) by userp2040.oracle.com with ESMTP id 1whb7wgwjq-1 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 26 Aug 2015 22:12:34 +0000 Received: from akpm3.mtv.corp.google.com (unknown [216.239.45.65]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id DA15BE3E; Wed, 26 Aug 2015 22:12:33 +0000 (UTC) Date: Wed, 26 Aug 2015 15:12:33 -0700 From: akpm@linux-foundation.org To: ocfs2-devel@oss.oracle.com, akpm@linux-foundation.org, ghe@suse.com, jlbec@evilplan.org, mfasheh@suse.com, rgoldwyn@suse.de Message-ID: <55de39d1.sgyQzdpyPstnVjyQ%akpm@linux-foundation.org> User-Agent: Heirloom mailx 12.5 6/20/10 MIME-Version: 1.0 X-Proofpoint-SPF-Result: pass X-Proofpoint-SPF-Record: v=spf1 ip4:140.211.169.12/30 include:_spf.google.com ~all X-ServerName: mail.linuxfoundation.org X-Proofpoint-Virus-Version: vendor=nai engine=5700 definitions=7905 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-1508260346 Subject: [Ocfs2-devel] [patch 27/28] 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: , 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.6 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 From: Gang He Subject: ocfs2: filecheck validate_extent_block function Add validate_extent_block/repair_extent_block functions for online filecheck. Signed-off-by: Gang He Cc: Mark Fasheh Cc: Joel Becker Cc: Goldwyn Rodrigues Signed-off-by: Andrew Morton --- fs/ocfs2/alloc.c | 116 +++++++++++++++++++++++++++++++++++++++ fs/ocfs2/alloc.h | 4 + fs/ocfs2/ocfs2_trace.h | 24 ++++++++ 3 files changed, 144 insertions(+) diff -puN fs/ocfs2/alloc.c~ocfs2-filecheck-validate_extent_block-function fs/ocfs2/alloc.c --- a/fs/ocfs2/alloc.c~ocfs2-filecheck-validate_extent_block-function +++ a/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 -puN fs/ocfs2/alloc.h~ocfs2-filecheck-validate_extent_block-function fs/ocfs2/alloc.h --- a/fs/ocfs2/alloc.h~ocfs2-filecheck-validate_extent_block-function +++ a/fs/ocfs2/alloc.h @@ -92,6 +92,10 @@ void ocfs2_init_refcount_extent_tree(str 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 -puN fs/ocfs2/ocfs2_trace.h~ocfs2-filecheck-validate_extent_block-function fs/ocfs2/ocfs2_trace.h --- a/fs/ocfs2/ocfs2_trace.h~ocfs2-filecheck-validate_extent_block-function +++ a/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,