From patchwork Mon Dec 18 12:06:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Changwei Ge X-Patchwork-Id: 10118981 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 5D9CF6019C for ; Mon, 18 Dec 2017 12:08:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D86428F8C for ; Mon, 18 Dec 2017 12:08:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 416D628FA4; Mon, 18 Dec 2017 12:08:24 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from userp2120.oracle.com (userp2120.oracle.com [156.151.31.85]) (using TLSv1.2 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3AD9328F8C for ; Mon, 18 Dec 2017 12:08:21 +0000 (UTC) Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.21/8.16.0.21) with SMTP id vBIC1wwb152894; Mon, 18 Dec 2017 12:07:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : date : message-id : mime-version : cc : subject : list-id : list-unsubscribe : list-archive : list-post : list-help : list-subscribe : content-type : content-transfer-encoding : sender; s=corp-2017-10-26; bh=Xswxywv+yvR7HNP9kHvC6E/KS+IBLLO7ng4xGUagjVQ=; b=JTjJ5PzgWQ9WG3BadN1lAlUqeeuoiLyLbVypvAJ7PgCsS9KGWGEHsPArBQGuTouv9Qhe ZY4S3La7fV7C20dfYOe0VG2xLtzK9i4aKC4WsTiSNJJWe3+DMNeyRYa4hrvMTbTFw5JC uU+djXJk0UPkG4oiNpJ9tcWJsKQvawuJ6MS4FnfmPG/igXdgJhcCXEkViPtFWT5ObuXo fqj1UbAxtvQ9zYZrTrBeQq+hGz5VHAMvHhScB7tDo57QaAFhfKG57gLkjQInX5kyxz9o 4T9TWrsNzNIWLzndRZ9XPXzxQqh2PJo/gcIXNldgqy8DbDwYkaRbJNXOQ9wo2eNljo1S fg== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2exd2wg4cg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 18 Dec 2017 12:07:45 +0000 Received: from oss.oracle.com (oss-old-reserved.oracle.com [137.254.22.2]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id vBIC7htU007604 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 18 Dec 2017 12:07:43 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 1eQuCt-0002eo-9k; Mon, 18 Dec 2017 04:07:43 -0800 Received: from userv0021.oracle.com ([156.151.31.71]) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1eQuCr-0002ef-3j for ocfs2-devel@oss.oracle.com; Mon, 18 Dec 2017 04:07:41 -0800 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 vBIC7epq007485 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Mon, 18 Dec 2017 12:07:40 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 vBIC7cLR024911; Mon, 18 Dec 2017 12:07:40 GMT Received: from h3cmg01-ex.h3c.com (smtp.h3c.com [60.191.123.56]) by userp2030.oracle.com with ESMTP id 2exagknnba-1; Mon, 18 Dec 2017 12:07:40 +0000 Received: from BJHUB02-EX.srv.huawei-3com.com (unknown [10.63.20.170]) by h3cmg01-ex.h3c.com with smtp id 5bf7_028b_576f1ac6_40aa_44d4_843a_340fbdadee19; Mon, 18 Dec 2017 20:06:31 +0800 Received: from H3CMLB14-EX.srv.huawei-3com.com ([fe80::f804:6772:bd71:f07f]) by BJHUB02-EX.srv.huawei-3com.com ([::1]) with mapi id 14.03.0248.002; Mon, 18 Dec 2017 20:06:22 +0800 From: Changwei Ge To: Mark Fasheh , Joseph Qi , "Joel Becker" , Junxiao Bi Thread-Topic: [PATCH] ocfs2: fall back to buffer IO when append dio is disabled with file hole existing Thread-Index: AdN3+J28SxJVGAGERUCpZ91TYT1sTw== Date: Mon, 18 Dec 2017 12:06:21 +0000 Message-ID: <63ADC13FD55D6546B7DECE290D39E373F1F5C2CE@H3CMLB14-EX.srv.huawei-3com.com> Accept-Language: en-US, zh-CN Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.125.136.231] MIME-Version: 1.0 X-CLX-Shades: MLX X-CLX-Response: 1TFkXGxIbEQpMehcaEQpZTRdnZnIRCllJFxpxGhAadwYbHBtxHhoQGncGGBo GGhEKWV4XaG55EQpJRhdFWEtJRk91WlhFTl9JXkNFRBl1T0sRCkNOF0YbWmV8YEYHQ2BjXkJMfh hQbXATS0xNYGgbaE8HTlBrEQpYXBcfBBoEGxgYBxxLSEtPHhwaBRsaBBsaGgQeEgQfEBseGh8aE QpeWRd4SHx7RBEKTVwXGR4ZEQpMWhdoaWhNeREKTEYXY2sRCkNaFxwaBBsTGwQbGBkEHxwRCkJe FxsRCkRYFxgRCkReFx4RCkRJFxkRCkJGF2cTbWAbW2VCH359EQpCXBcaEQpCRRduGVhMXmEBcFJ MYREKQk4XZEJ8WkVEQWIdZFARCkJMF29+XU0YBV1mGlJ7EQpCbBdkYU9LYEJIEngdZxEKQkAXZ0 8eaGNfc3hjbGYRCnBoF2lwa0QSe0tnElJwEBkaEQpwaBdiSHhsYlNfbhhzYRAZGhEKcGgXbVJQR ktoQWt6E2wQGRoRCnBoF3pacERJaXp4bHB5EBkaEQpwaBdhAQF4QkVEchJkWBAZGhEKcGwXbU4b b1MBR1JIHXMQGRoRCnBMF2JLHmlQeGBgQ25QEB4SEQptfhcaEQpYTRdLESA= X-PDR: PASS X-Source-IP: 60.191.123.56 X-ServerName: smtp.h3c.com X-Proofpoint-SPF-Result: pass X-Proofpoint-SPF-Record: v=spf1 ip4:60.191.123.56 ip4:60.191.123.50 ip4:221.12.31.13 ip4:221.12.31.56 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8748 signatures=668649 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=0 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=181 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=858 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1712180163 X-Spam: Clean Cc: "ocfs2-devel@oss.oracle.com" Subject: [Ocfs2-devel] [PATCH] ocfs2: fall back to buffer IO when append dio is disabled with file hole existing 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-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8748 signatures=668649 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1712180161 X-Virus-Scanned: ClamAV using ClamSMTP Before ocfs2 supporting allocating clusters while doing append-dio, all append dio will fall back to buffer io to allocate clusters firstly. Also, when it steps on a file hole, it will fall back to buffer io, too. But for current code, writing to file hole will leverage dio to allocate clusters. This is not right, since whether append-io is enabled tells the capability whether ocfs2 can allocate space while doing dio. So introduce file hole check function back into ocfs2. Once ocfs2 is doing dio upon a file hole with append-dio disabled, it will fall back to buffer IO to allocate clusters. Signed-off-by: Changwei Ge --- fs/ocfs2/aops.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c index d151632..a982cf6 100644 --- a/fs/ocfs2/aops.c +++ b/fs/ocfs2/aops.c @@ -2414,6 +2414,44 @@ static int ocfs2_dio_end_io(struct kiocb *iocb, return ret; } +/* + * Will look for holes and unwritten extents in the range starting at + * pos for count bytes (inclusive). + */ +static int ocfs2_check_range_for_holes(struct inode *inode, loff_t pos, + size_t count) +{ + int ret = 0; + unsigned int extent_flags; + u32 cpos, clusters, extent_len, phys_cpos; + struct super_block *sb = inode->i_sb; + + cpos = pos >> OCFS2_SB(sb)->s_clustersize_bits; + clusters = ocfs2_clusters_for_bytes(sb, pos + count) - cpos; + + while (clusters) { + ret = ocfs2_get_clusters(inode, cpos, &phys_cpos, &extent_len, + &extent_flags); + if (ret < 0) { + mlog_errno(ret); + goto out; + } + + if (phys_cpos == 0 || (extent_flags & OCFS2_EXT_UNWRITTEN)) { + ret = 1; + break; + } + + if (extent_len > clusters) + extent_len = clusters; + + clusters -= extent_len; + cpos += extent_len; + } +out: + return ret; +} + static ssize_t ocfs2_direct_IO(struct kiocb *iocb, struct iov_iter *iter) { struct file *file = iocb->ki_filp; @@ -2429,8 +2467,10 @@ static ssize_t ocfs2_direct_IO(struct kiocb *iocb, struct iov_iter *iter) return 0; /* Fallback to buffered I/O if we do not support append dio. */ - if (iocb->ki_pos + iter->count > i_size_read(inode) && - !ocfs2_supports_append_dio(osb)) + if (!ocfs2_supports_append_dio(osb) && + (iocb->ki_pos + iter->count > i_size_read(inode) || + ocfs2_check_range_for_holes(inode, iocb->ki_pos, + iter->count))) return 0; if (iov_iter_rw(iter) == READ)