From patchwork Thu Jun 27 21:58:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 2795861 Return-Path: X-Original-To: patchwork-ocfs2-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 71CF89F3A0 for ; Thu, 27 Jun 2013 22:00:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 20A26201BA for ; Thu, 27 Jun 2013 22:00:19 +0000 (UTC) Received: from aserp1040.oracle.com (aserp1040.oracle.com [141.146.126.69]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EF98B201A7 for ; Thu, 27 Jun 2013 22:00:16 +0000 (UTC) Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r5RLxYCe004775 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 27 Jun 2013 21:59:35 GMT Received: from oss.oracle.com (oss-external.oracle.com [137.254.96.51]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r5RLxVGM012442 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 27 Jun 2013 21:59:32 GMT Received: from localhost ([127.0.0.1] helo=oss.oracle.com) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1UsKDz-0002iT-Hu; Thu, 27 Jun 2013 14:59:31 -0700 Received: from acsinet22.oracle.com ([141.146.126.238]) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1UsKDS-0002ht-JP for ocfs2-devel@oss.oracle.com; Thu, 27 Jun 2013 14:58:58 -0700 Received: from aserp1030.oracle.com (aserp1030.oracle.com [141.146.126.68]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r5RLwwNT022488 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 27 Jun 2013 21:58:58 GMT Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) by aserp1030.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r5RLwvmA028697 for ; Thu, 27 Jun 2013 21:58:57 GMT Received: from akpm3.mtv.corp.google.com (unknown [216.239.45.95]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 76B3498F; Thu, 27 Jun 2013 21:58:56 +0000 (UTC) Date: Thu, 27 Jun 2013 14:58:55 -0700 From: Andrew Morton To: Younger Liu Message-Id: <20130627145855.6ed028022d3a63fa97dcee13@linux-foundation.org> In-Reply-To: <51CBAC04.6010805@huawei.com> References: <51CBAC04.6010805@huawei.com> X-Mailer: Sylpheed 3.2.0beta5 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 X-Flow-Control-Info: class=Pass-to-MM reputation=ipRisk-All ip=140.211.169.12 ct-class=T1 ct-vol1=0 ct-vol2=4 ct-vol3=4 ct-risk=10 ct-spam1=0 ct-spam2=0 ct-bulk=83 rcpts=1 size=3950 X-Sendmail-CM-Score: 0.00% X-Sendmail-CM-Analysis: v=2.1 cv=JY+F8y6V c=1 sm=1 tr=0 a=5MPDoNpceV4HFXFrvkM3CQ==:117 a=5MPDoNpceV4HFXFrvkM3CQ==:17 a=u56rKy4LqhkA:10 a=NEiEQogP1MkA:10 a=kj9zAlcOel0A:10 a=Z4Rwk6OoAAAA:8 a=1XWaLZrsAAAA:8 a=ag1SF4gXAAAA:8 a=eeV2hNisBKwA:10 a=i0EeH86SAAAA:8 a=3y z0QEAw43EEcrbj-jYA:9 a=CjuIK1q_8ugA:10 a=hPjdaMEvmhQA:10 X-Sendmail-CT-Classification: not spam X-Sendmail-CT-RefID: str=0001.0A090208.51CCB5A1.0095:SCFSTAT19734153, ss=1, re=-4.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 Cc: Ocfs2-Devel Subject: Re: [Ocfs2-devel] [PATCH] ocfs2: fix readonly issue in ocfs2_unlink() 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: acsinet21.oracle.com [141.146.126.237] X-Spam-Status: No, score=-5.5 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 On Thu, 27 Jun 2013 11:05:40 +0800 Younger Liu wrote: > While deleting a file with ocfs2_unlink(), there is a bug in this > function. This bug will result in filesystem read-only. > > After calling ocfs2_orphan_add(), the file which will be deleted > is added into orphan dir. If ocfs2_delete_entry() fails, > the file still exists in the parent dir. > And this scenario introduces a conflict of metadata. > > If a file is added into orphan dir, when we put inode of the file > with iput(), the inode i_flags is setted (~OCFS2_VALID_FL) in > ocfs2_remove_inode(), and then write back to disk. > > But as previously mentioned, the file still exists in the parent dir. > On other nodes, the file can be still accessed. When first read the file > with ocfs2_read_blocks() from disk, It will check and avalidate inode > using ocfs2_validate_inode_block(). > So File system will be readonly because the inode is invalid. > In other words, the inode i_flags has been setted (~OCFS2_VALID_FL). > > ... > > --- a/fs/ocfs2/namei.c > +++ b/fs/ocfs2/namei.c > @@ -790,7 +790,7 @@ static int ocfs2_unlink(struct inode *dir, > struct dentry *dentry) > { > int status; > - int child_locked = 0; > + int child_locked = 0, is_unlinkable = 0; Please note that the surrounding code was carful to use the one-definition-per-line convention. That's a good convention - more readable, less patch rejects during code evolution, leaves room for a nice little comment. Also, type `bool' would have been appropraite here. > struct inode *inode = dentry->d_inode; > struct inode *orphan_dir = NULL; > struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); > @@ -873,6 +873,7 @@ static int ocfs2_unlink(struct inode *dir, > mlog_errno(status); > goto leave; > } > + is_unlinkable = 1; > } > > handle = ocfs2_start_trans(osb, ocfs2_unlink_credits(osb->sb)); > @@ -892,15 +893,6 @@ static int ocfs2_unlink(struct inode *dir, > > fe = (struct ocfs2_dinode *) fe_bh->b_data; > > - if (inode_is_unlinkable(inode)) { > - status = ocfs2_orphan_add(osb, handle, inode, fe_bh, orphan_name, > - &orphan_insert, orphan_dir); > - if (status < 0) { > - mlog_errno(status); > - goto leave; > - } > - } > - > /* delete the name from the parent dir */ > status = ocfs2_delete_entry(handle, dir, &lookup); > if (status < 0) { > @@ -923,6 +915,14 @@ static int ocfs2_unlink(struct inode *dir, > mlog_errno(status); > if (S_ISDIR(inode->i_mode)) > inc_nlink(dir); > + goto leave; > + } > + > + if (is_unlinkable) { > + status = ocfs2_orphan_add(osb, handle, inode, fe_bh, orphan_name, > + &orphan_insert, orphan_dir); > + if (status < 0) > + mlog_errno(status); > } This is yet another ocfs2 function which reports the same error two times. ho hum. Please review: Reviewed-by: Younger Liu --- a/fs/ocfs2/namei.c~ocfs2-fix-readonly-issue-in-ocfs2_unlink-fix +++ a/fs/ocfs2/namei.c @@ -790,7 +790,8 @@ static int ocfs2_unlink(struct inode *di struct dentry *dentry) { int status; - int child_locked = 0, is_unlinkable = 0; + int child_locked = 0; + bool is_unlinkable = false; struct inode *inode = dentry->d_inode; struct inode *orphan_dir = NULL; struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); @@ -873,7 +874,7 @@ static int ocfs2_unlink(struct inode *di mlog_errno(status); goto leave; } - is_unlinkable = 1; + is_unlinkable = true; } handle = ocfs2_start_trans(osb, ocfs2_unlink_credits(osb->sb)); @@ -919,8 +920,8 @@ static int ocfs2_unlink(struct inode *di } if (is_unlinkable) { - status = ocfs2_orphan_add(osb, handle, inode, fe_bh, orphan_name, - &orphan_insert, orphan_dir); + status = ocfs2_orphan_add(osb, handle, inode, fe_bh, + orphan_name, &orphan_insert, orphan_dir); if (status < 0) mlog_errno(status); }