From patchwork Tue Nov 24 13:38:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Qi X-Patchwork-Id: 7691081 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 28D53BF90C for ; Tue, 24 Nov 2015 13:41:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2FF0A207D2 for ; Tue, 24 Nov 2015 13:41:04 +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 0455C2077C for ; Tue, 24 Nov 2015 13:41:02 +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 tAODenuY011702 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 24 Nov 2015 13:40:50 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 tAODekfd018354 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 24 Nov 2015 13:40:46 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 1a1Dpu-0006te-A0; Tue, 24 Nov 2015 05:40:46 -0800 Received: from userv0021.oracle.com ([156.151.31.71]) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1a1DpF-0006sf-0Y for ocfs2-devel@oss.oracle.com; Tue, 24 Nov 2015 05:40:05 -0800 Received: from aserp1020.oracle.com (aserp1020.oracle.com [141.146.126.67]) by userv0021.oracle.com (8.13.8/8.13.8) with ESMTP id tAODe4tm015907 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 24 Nov 2015 13:40:04 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 tAODe340004444 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Tue, 24 Nov 2015 13:40:03 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 tAODcluT005924 for ; Tue, 24 Nov 2015 13:40:03 GMT Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [119.145.14.65]) by userp2040.oracle.com with ESMTP id 1yc6jmqkm5-1 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for ; Tue, 24 Nov 2015 13:40:02 +0000 Received: from 172.24.1.49 (EHLO szxeml432-hub.china.huawei.com) ([172.24.1.49]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CWU65344; Tue, 24 Nov 2015 21:38:21 +0800 (CST) Received: from [127.0.0.1] (10.177.22.101) by szxeml432-hub.china.huawei.com (10.82.67.209) with Microsoft SMTP Server id 14.3.235.1; Tue, 24 Nov 2015 21:38:19 +0800 Message-ID: <5654684A.1070305@huawei.com> Date: Tue, 24 Nov 2015 21:38:18 +0800 From: Joseph Qi User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130328 Thunderbird/17.0.5 MIME-Version: 1.0 To: Andrew Morton X-Originating-IP: [10.177.22.101] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020204.5654684F.013E, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 98de442861aa9730af6ef5a5ae4ae7a0 X-Proofpoint-SPF-Result: pass X-Proofpoint-SPF-Record: v=spf1 ip4:119.145.14.64/30 ip4:58.251.152.64/30 ip4:119.145.14.93 ip4:58.251.152.93 ip4:206.16.17.74 ip4:194.213.3.16 ip4:194.213.3.17 ip4:206.16.17.72 ip4:119.145.14.199 ip4:58.251.152.179 ip4:119.145.14.52 ip4:58.251.152.52 ~all X-ServerName: szxga02-in.huawei.com X-Proofpoint-Virus-Version: vendor=nai engine=5700 definitions=7994 signatures=670662 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-1511240231 Cc: Mark Fasheh , "ocfs2-devel@oss.oracle.com" Subject: [Ocfs2-devel] [PATCH] ocfs2: fix BUG due to uncleaned localalloc during mount 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=-4.8 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 Tariq has reported a BUG before and posted a fix at: https://oss.oracle.com/pipermail/ocfs2-devel/2015-April/010696.html This is because during umount, localalloc shutdown relies on journal shutdown. But during journal shutdown, it just stops commit thread without checking its result. So it may happen that localalloc shutdown uncleaned during I/O error and after that, journal then has been marked clean if I/O restores. Then during mount, localalloc won't be recovered because of clean journal and then trigger BUG when claiming clusters from localalloc. In Tariq's fix, we have to run fsck offline and a separate fix to fsck is needed because it currently does not support clearing out localalloc inode. And my way to fix this issue is checking localalloc before actually loading it during mount. And this is somewhat online. Signed-off-by: Joseph Qi --- fs/ocfs2/localalloc.c | 19 ++++++++++++------- fs/ocfs2/localalloc.h | 2 +- fs/ocfs2/super.c | 17 ++++++++++++++--- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c index 0a4457f..ceebaef 100644 --- a/fs/ocfs2/localalloc.c +++ b/fs/ocfs2/localalloc.c @@ -281,7 +281,7 @@ bail: return ret; } -int ocfs2_load_local_alloc(struct ocfs2_super *osb) +int ocfs2_load_local_alloc(struct ocfs2_super *osb, int check, int *recovery) { int status = 0; struct ocfs2_dinode *alloc = NULL; @@ -345,21 +345,26 @@ int ocfs2_load_local_alloc(struct ocfs2_super *osb) if (num_used || alloc->id1.bitmap1.i_used || alloc->id1.bitmap1.i_total - || la->la_bm_off) + || la->la_bm_off) { mlog(ML_ERROR, "Local alloc hasn't been recovered!\n" "found = %u, set = %u, taken = %u, off = %u\n", num_used, le32_to_cpu(alloc->id1.bitmap1.i_used), le32_to_cpu(alloc->id1.bitmap1.i_total), OCFS2_LOCAL_ALLOC(alloc)->la_bm_off); + status = -EINVAL; + *recovery = 1; + goto bail; + } - osb->local_alloc_bh = alloc_bh; - osb->local_alloc_state = OCFS2_LA_ENABLED; + if (!check) { + osb->local_alloc_bh = alloc_bh; + osb->local_alloc_state = OCFS2_LA_ENABLED; + } bail: - if (status < 0) + if (status < 0 || check) brelse(alloc_bh); - if (inode) - iput(inode); + iput(inode); trace_ocfs2_load_local_alloc(osb->local_alloc_bits); diff --git a/fs/ocfs2/localalloc.h b/fs/ocfs2/localalloc.h index 44a7d1f..a913841 100644 --- a/fs/ocfs2/localalloc.h +++ b/fs/ocfs2/localalloc.h @@ -26,7 +26,7 @@ #ifndef OCFS2_LOCALALLOC_H #define OCFS2_LOCALALLOC_H -int ocfs2_load_local_alloc(struct ocfs2_super *osb); +int ocfs2_load_local_alloc(struct ocfs2_super *osb, int check, int *recovery); void ocfs2_shutdown_local_alloc(struct ocfs2_super *osb); diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c index 2de4c8a..4004b29 100644 --- a/fs/ocfs2/super.c +++ b/fs/ocfs2/super.c @@ -2428,6 +2428,7 @@ static int ocfs2_check_volume(struct ocfs2_super *osb) int status; int dirty; int local; + int la_dirty = 0, recovery = 0; struct ocfs2_dinode *local_alloc = NULL; /* only used if we * recover * ourselves. */ @@ -2449,6 +2450,16 @@ static int ocfs2_check_volume(struct ocfs2_super *osb) * recover anything. Otherwise, journal_load will do that * dirty work for us :) */ if (!dirty) { + /* It may happen that local alloc is unclean shutdown, but + * journal has been marked clean, so check it here and do + * recovery if needed */ + status = ocfs2_load_local_alloc(osb, 1, &recovery); + if (recovery) { + printk(KERN_NOTICE "ocfs2: local alloc needs recovery " + "on device (%s).\n", osb->dev_str); + la_dirty = 1; + } + status = ocfs2_journal_wipe(osb->journal, 0); if (status < 0) { mlog_errno(status); @@ -2477,7 +2488,7 @@ static int ocfs2_check_volume(struct ocfs2_super *osb) JBD2_FEATURE_COMPAT_CHECKSUM, 0, JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT); - if (dirty) { + if (dirty || la_dirty) { /* recover my local alloc if we didn't unmount cleanly. */ status = ocfs2_begin_local_alloc_recovery(osb, osb->slot_num, @@ -2490,13 +2501,13 @@ static int ocfs2_check_volume(struct ocfs2_super *osb) * ourselves as mounted. */ } - status = ocfs2_load_local_alloc(osb); + status = ocfs2_load_local_alloc(osb, 0, &recovery); if (status < 0) { mlog_errno(status); goto finally; } - if (dirty) { + if (dirty || la_dirty) { /* Recovery will be completed after we've mounted the * rest of the volume. */ osb->dirty = 1;