From patchwork Mon Oct 23 05:40:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Chen X-Patchwork-Id: 10022019 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7471D601E8 for ; Mon, 23 Oct 2017 05:44:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 64B8F28783 for ; Mon, 23 Oct 2017 05:44:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 58A5728786; Mon, 23 Oct 2017 05:44:08 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id A153F28783 for ; Mon, 23 Oct 2017 05:44:06 +0000 (UTC) Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v9N5hhIV027588 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Oct 2017 05:43:43 GMT Received: from oss.oracle.com (oss-old-reserved.oracle.com [137.254.22.2]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id v9N5hNbw001772 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 23 Oct 2017 05:43:23 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 1e6VWF-0006R3-12; Sun, 22 Oct 2017 22:43:23 -0700 Received: from userv0021.oracle.com ([156.151.31.71]) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1e6VWC-0006Qr-TM for ocfs2-devel@oss.oracle.com; Sun, 22 Oct 2017 22:43:21 -0700 Received: from userp2030.oracle.com (userp2030.oracle.com [156.151.31.89]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id v9N5hKeN012661 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Mon, 23 Oct 2017 05:43:20 GMT Received: from pps.filterd (userp2030.oracle.com [127.0.0.1]) by userp2030.oracle.com (8.16.0.21/8.16.0.21) with SMTP id v9N5eDxZ018621 for ; Mon, 23 Oct 2017 05:43:20 GMT Authentication-Results: oracle.com; spf=pass smtp.mailfrom=alex.chen@huawei.com Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by userp2030.oracle.com with ESMTP id 2ds8umhc11-1 (version=TLSv1 cipher=RC4-SHA bits=128 verify=NOT) for ; Mon, 23 Oct 2017 05:43:19 +0000 Received: from 172.30.72.58 (EHLO DGGEMS409-HUB.china.huawei.com) ([172.30.72.58]) by dggrg04-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DJQ61140; Mon, 23 Oct 2017 13:42:26 +0800 (CST) Received: from [127.0.0.1] (10.177.26.59) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.361.1; Mon, 23 Oct 2017 13:41:24 +0800 Message-ID: <59ED80E6.4030600@huawei.com> Date: Mon, 23 Oct 2017 13:40:54 +0800 From: alex chen User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 MIME-Version: 1.0 To: Andrew Morton References: <59E9BBEF.1060601@huawei.com> In-Reply-To: <59E9BBEF.1060601@huawei.com> X-Forwarded-Message-Id: <59E9BBEF.1060601@huawei.com> X-Originating-IP: [10.177.26.59] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020203.59ED8144.00B6, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 0d8f6e242faf7b912fa5a2db73307bee X-CLX-Shades: MLX X-CLX-Response: 1TFkXGx0ZEQpMehcbGBwRCllNF2dmchEKWUkXGnEaEBp3BhsfGXEZGRAadwY YGgYaEQpZXhdobmYRCklGF0VYS0lGT3VaWEVOX0leQ0VEHhEKQ04XU3hJXG5nXhl4WWxOHW4aGH JYYRJjXUdka0ZlHhl4B1MRClhcFx8EGgQbGxMHG0gaThhOS08FGxoEGxoaBB4SBBsQGx4aHxoRC l5ZF3hjU3N+EQpNXBceGh4RCkxaF2lraUJNeREKRVkXaGsRCk1OF2gRCkxGF2xraxEKQ1oXHh8E GB4TBBgbGAQbExoRCkJeFxsRCkRJFxMRCkJGF2BTbh5DGXNnWEZmEQpCXBcaEQpCRRdiEn1iEmJ rHEVrfREKQk4XbEJIWVMaTWV4eB0RCkJMF2kBARhuGVsYUkd6EQpCbBdrHEJDTnpIHF56QBEKQk AXZXMZElMefRN4UxkRCkJYF2J9b3kBTxgZcHB7EQpaWBcbEQpwZxdvYRxZZ1IfehJsGBAZGhEKc GgXY1xDZnpaH31EZkcQHhIRCnBoF2tYTxNiHX1DRH5QEBwaEQpwaBdtARgBHVodR08aZRAcGhEK cGgXaWJBcEtOfUlGaEUQGRoRCnBoF2dPGn1FTmdYZgVSEBkaEQpwbBdmQU5kU0tZcmB6HRAeEhE KbX4XGhEKWE0XSxEg X-PDR: PASS X-ServerName: szxga04-in.huawei.com X-Proofpoint-SPF-Result: pass X-Proofpoint-SPF-Record: v=spf1 ip4:45.249.212.32 ip4:45.249.212.35 ip4:119.145.14.93 ip4:58.251.152.93 ip4:194.213.3.17 ip4:206.16.17.72 ip4:45.249.212.255 ip4:45.249.212.187/29 ip4:45.249.212.191 ~all X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8692 signatures=668600 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=126 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=173 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1710230082 Cc: ryan.ding@oracle.com, "ocfs2-devel@oss.oracle.com" Subject: [Ocfs2-devel] [PATCH v2] ocfs2: the ip_alloc_sem should be taken in ocfs2_get_block() 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: aserv0022.oracle.com [141.146.126.234] X-Virus-Scanned: ClamAV using ClamSMTP The ip_alloc_sem should be taken in ocfs2_get_block() when reading file in DIRECT mode to prevent concurrent access to extent tree with ocfs2_dio_end_io_write(), which may cause BUGON in ocfs2_get_clusters_nocache()->BUG_ON(v_cluster < le32_to_cpu(rec->e_cpos)) Fixes: c15471f79506 ("ocfs2: fix sparse file & data ordering issue in direct io") Signed-off-by: Alex Chen Reviewed-by: Jun Piao Acked-by: Changwei Ge --- fs/ocfs2/aops.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c index 88a31e9..29607d9 100644 --- a/fs/ocfs2/aops.c +++ b/fs/ocfs2/aops.c @@ -134,6 +134,19 @@ static int ocfs2_symlink_get_block(struct inode *inode, sector_t iblock, return err; } +static int ocfs2_get_block_lock(struct inode *inode, sector_t iblock, + struct buffer_head *bh_result, int create) +{ + int ret = 0; + struct ocfs2_inode_info *oi = OCFS2_I(inode); + + down_read(&oi->ip_alloc_sem); + ret = ocfs2_get_block(inode, iblock, bh_result, create); + up_read(&oi->ip_alloc_sem); + + return ret; +} + int ocfs2_get_block(struct inode *inode, sector_t iblock, struct buffer_head *bh_result, int create) { @@ -2154,12 +2167,9 @@ static int ocfs2_dio_get_block(struct inode *inode, sector_t iblock, * while file size will be changed. */ if (pos + total_len <= i_size_read(inode)) { - down_read(&oi->ip_alloc_sem); - /* This is the fast path for re-write. */ - ret = ocfs2_get_block(inode, iblock, bh_result, create); - - up_read(&oi->ip_alloc_sem); + /* This is the fast path for re-write. */ + ret = ocfs2_get_block_lock(inode, iblock, bh_result, create); if (buffer_mapped(bh_result) && !buffer_new(bh_result) && ret == 0) @@ -2424,7 +2434,7 @@ static ssize_t ocfs2_direct_IO(struct kiocb *iocb, struct iov_iter *iter) return 0; if (iov_iter_rw(iter) == READ) - get_block = ocfs2_get_block; + get_block = ocfs2_get_block_lock; else get_block = ocfs2_dio_get_block;