From patchwork Fri Oct 20 09:03:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Chen X-Patchwork-Id: 10019327 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 B923B60224 for ; Fri, 20 Oct 2017 09:07:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AAAA528E88 for ; Fri, 20 Oct 2017 09:07:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9DFE028EBC; Fri, 20 Oct 2017 09:07:57 +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 C566528E88 for ; Fri, 20 Oct 2017 09:07:56 +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 v9K97ODV008509 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2017 09:07:24 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 v9K973lu002742 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 20 Oct 2017 09:07:03 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 1e5TGh-00024s-0x; Fri, 20 Oct 2017 02:07:03 -0700 Received: from userv0021.oracle.com ([156.151.31.71]) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1e5TGe-00024j-FO for ocfs2-devel@oss.oracle.com; Fri, 20 Oct 2017 02:07:01 -0700 Received: from userp2040.oracle.com (userp2040.oracle.com [156.151.31.90]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id v9K970MR004601 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Fri, 20 Oct 2017 09:07:00 GMT Received: from pps.filterd (userp2040.oracle.com [127.0.0.1]) by userp2040.oracle.com (8.16.0.21/8.16.0.21) with SMTP id v9K95NVx018310 for ; Fri, 20 Oct 2017 09:07:00 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 userp2040.oracle.com with ESMTP id 2dqe2m8681-1 (version=TLSv1 cipher=RC4-SHA bits=128 verify=NOT) for ; Fri, 20 Oct 2017 09:06:59 +0000 Received: from 172.30.72.58 (EHLO DGGEMS407-HUB.china.huawei.com) ([172.30.72.58]) by dggrg04-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DJM61730; Fri, 20 Oct 2017 17:05:40 +0800 (CST) Received: from [127.0.0.1] (10.177.26.59) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.301.0; Fri, 20 Oct 2017 17:03:44 +0800 Message-ID: <59E9BBEF.1060601@huawei.com> Date: Fri, 20 Oct 2017 17:03:43 +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 X-Originating-IP: [10.177.26.59] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090205.59E9BC64.00C6, 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: 1481c7bc8e8b6b30bf3bd6c5df36c3ce X-CLX-Shades: MLX X-CLX-Response: 1TFkXGxkbEQpMehcbHx0RCllNF2dmchEKWUkXGnEaEBp3BhsbHHEYEhAbdwY bHwYaEQpZXhdobmYRCklGF0VYS0lGT3VaWEVOX0leQ0VEHhEKQ04XU2lSZ1h6XmdIGwdHQhlmXm VPaEFaHkViEmhcZ19+T2ARClhcFx8EGgQbGxMHG0gaThhOS08FGxoEGxoaBB4SBBsQGx4aHxoRC l5ZF3hiGGx6EQpNXBceHhMRCkxaF2hpQk1TEQpFWRdoaxEKTU4XaBEKQ1oXHh8EGB4TBBgbGAQb ExoRCkJeFxsRCkRJFxIRCkJGF2cTbWAbW2VCH359EQpCXBcaEQpCRRdiEn1iEmJrHEVrfREKQk4 XbEJIWVMaTWV4eB0RCkJMF2kBARhuGVsYUkd6EQpCbBdrHEJDTnpIHF56QBEKQkAXbktkfURDbX 9NUh0RCkJYF2J9b3kBTxgZcHB7EQpaWBcbEQpwaBdjXENmeloffURmRxAaEQpwaBdrWE8TYh19Q 0R+UBAaEQpwaBdtARgBHVodR08aZRAaEQpwaBdtRxtMZFh6WhhvYxAaEQpwaBdkEh1AG11dcEl7 UBAaEQpwbBdmQU5kU0tZcmB6HRAaEQptfhcaEQpYTRdLESA= 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=8689 signatures=668589 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=157 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=131 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1710200132 Cc: "ocfs2-devel@oss.oracle.com" Subject: [Ocfs2-devel] [PATCH] 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)) Signed-off-by: Alex Chen Reviewed-by: Jun Piao Acked-by: Changwei Ge --- fs/ocfs2/aops.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) -- 1.9.5.msysgit.1 diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c index 88a31e9..5cb939f 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; + 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,8 @@ 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); - + ret = ocfs2_get_block_lock(inode, iblock, bh_result, create); if (buffer_mapped(bh_result) && !buffer_new(bh_result) && ret == 0) @@ -2424,7 +2433,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;