From patchwork Fri Jun 2 09:40:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangguanghui X-Patchwork-Id: 9762055 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 2E4C5602BF for ; Fri, 2 Jun 2017 09:41:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 164E928420 for ; Fri, 2 Jun 2017 09:41:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0A6D928504; Fri, 2 Jun 2017 09:41:34 +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=-2.8 required=2.0 tests=BAYES_00, HTML_FONT_FACE_BAD, HTML_FONT_LOW_CONTRAST, HTML_MESSAGE, MIME_HTML_MOSTLY, 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 5792028420 for ; Fri, 2 Jun 2017 09:41:31 +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 v529ek8k022772 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 2 Jun 2017 09:40:47 GMT 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 v529eg73020069 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 2 Jun 2017 09:40: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 1dGj4U-0006Uk-5A; Fri, 02 Jun 2017 02:40:42 -0700 Received: from aserv0021.oracle.com ([141.146.126.233]) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1dGj4S-0006Ua-0X for ocfs2-devel@oss.oracle.com; Fri, 02 Jun 2017 02:40:40 -0700 Received: from userp2030.oracle.com (userp2030.oracle.com [156.151.31.89]) by aserv0021.oracle.com (8.13.8/8.14.4) with ESMTP id v529edpl029643 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Fri, 2 Jun 2017 09:40:39 GMT Received: from pps.filterd (userp2030.oracle.com [127.0.0.1]) by userp2030.oracle.com (8.16.0.20/8.16.0.20) with SMTP id v529cBFZ002791 for ; Fri, 2 Jun 2017 09:40:39 GMT Authentication-Results: oracle.com; spf=pass smtp.mailfrom=zhang.guanghui@h3c.com Received: from h3cmg01-ex.h3c.com (smtp.h3c.com [60.191.123.56]) by userp2030.oracle.com with ESMTP id 2au3wa1u00-1 for ; Fri, 02 Jun 2017 09:40:36 +0000 Received: from BJHUB01-EX.srv.huawei-3com.com (unknown [10.63.20.169]) by h3cmg01-ex.h3c.com with smtp id 3bda_044b_0069e2b4_b240_4559_9e81_0d931fc300e9; Fri, 02 Jun 2017 17:40:22 +0800 Received: from H3CMLB12-EX.srv.huawei-3com.com ([fe80::10fe:abde:731b:fdde]) by BJHUB01-EX.srv.huawei-3com.com ([::1]) with mapi id 14.03.0248.002; Fri, 2 Jun 2017 17:40:15 +0800 From: Zhangguanghui To: zren Thread-Topic: ocfs2: fix sparse file & data ordering issue in direct io. review Thread-Index: AQHS24HK7sZnMwWvo0uT8K1CiIKmXw== Date: Fri, 2 Jun 2017 09:40:14 +0000 Message-ID: References: , , , Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.153.28.123] MIME-Version: 1.0 X-PDR: PASS 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=5800 definitions=8547 signatures=668467 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1706020180 Cc: "ocfs2-devel@oss.oracle.com" Subject: Re: [Ocfs2-devel] ocfs2: fix sparse file & data ordering issue in direct io. review 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-Virus-Scanned: ClamAV using ClamSMTP Hi Please take a look at this issue. BUG_ON(v_cluster < le32_to_cpu(rec->e_cpos)) in ocfs2_get_clusters_nocache has been triggered, so i think ip_alloc_sem is still needed. the crash have been detailed. crash> bt PID: 1558 TASK: ffff88001245e4a0 CPU: 0 COMMAND: "dd" #0 [ffff8800077df410] machine_kexec at ffffffff8105b311 #1 [ffff8800077df480] crash_kexec at ffffffff8110c358 #2 [ffff8800077df550] oops_end at ffffffff8101a7a8 #3 [ffff8800077df580] die at ffffffff8101ae28 #4 [ffff8800077df5b0] do_trap at ffffffff8101732d #5 [ffff8800077df610] do_error_trap at ffffffff81017663 #6 [ffff8800077df6d0] do_error_trap at ffffffff81017714 #7 [ffff8800077df710] do_invalid_op at ffffffff81017f60 #8 [ffff8800077df720] invalid_op at ffffffff817f9afe [exception RIP: ocfs2_get_clusters_nocache+1538] RIP: ffffffffc08353d2 RSP: ffff8800077df7d8 RFLAGS: 00010297 RAX: 0000000000000081 RBX: ffff8800483c7130 RCX: 0000000000000000 RDX: ffff88007c611f78 RSI: ffff88007c60e708 RDI: ffff88007c60e708 RBP: ffff8800077df888 R8: 0000000000000007 R9: 0000000000000367 R10: 0000000000000006 R11: 0000000000000006 R12: ffff8800077df8b8 R13: ffff8800483c70c0 R14: 0000000000000000 R15: ffff8800483c7000 ORIG_RAX: ffffffffffffffff CS: 0010 SS: 0018 #9 [ffff8800077df890] ocfs2_get_clusters at ffffffffc0835a0b [ocfs2] #10 [ffff8800077df910] ocfs2_extent_map_get_blocks at ffffffffc0835bca [ocfs2] #11 [ffff8800077df980] ocfs2_get_block at ffffffffc081834c [ocfs2] #12 [ffff8800077dfa40] do_blockdev_direct_IO at ffffffff8123fabc #13 [ffff8800077dfc80] __blockdev_direct_IO at ffffffff81240c83 #14 [ffff8800077dfcb0] ocfs2_direct_IO at ffffffffc081722f [ocfs2] #15 [ffff8800077dfce0] generic_file_read_iter at ffffffff8118ba1a #16 [ffff8800077dfdb0] ocfs2_file_read_iter at ffffffffc083887a [ocfs2] #17 [ffff8800077dfe50] __vfs_read at ffffffff8120263b #18 [ffff8800077dfed0] vfs_read at ffffffff812039d5 #19 [ffff8800077dff10] sys_read at ffffffff81203abf #20 [ffff8800077dff50] system_call_fastpath at ffffffff817f81b2 RIP: 00007f49c8af0f30 RSP: 00007ffcb7b343e8 RFLAGS: 00000246 RAX: ffffffffffffffda RBX: 0000000000100000 RCX: 00007f49c8af0f30 RDX: 0000000000100000 RSI: 00007f49c86ec000 RDI: 0000000000000000 RBP: 00007f49c86ec000 R8: 00000000ffffffff R9: 0000000000000000 R10: 00007ffcb7b34180 R11: 0000000000000246 R12: 0000000000000000 R13: 0000000000100000 R14: 0000000000100000 R15: 00007ffcb7b36814 ORIG_RAX: 0000000000000000 CS: 0033 SS: 002b ________________________________ All the best wishes for you. zhangguanghui From: zhangguanghui 10102 Date: 2017-05-27 13:54 To: ocfs2-devel@oss.oracle.com CC: ryan.ding; Andrew Morton; wangww631; Joel Becker; Mark Fasheh Subject: ocfs2: fix sparse file & data ordering issue in direct io. review comments and questions are, as always, welcome. Thanks ________________________________ All the best wishes for you. zhangguanghui From: zhangguanghui 10102 (Cloud) Date: 2017-05-26 16:21 To: ocfs2-devel@oss.oracle.com CC: ryan.ding; Andrew Morton; wangww631; Joel Becker; Mark Fasheh Subject: Re: ocfs2: fix sparse file & data ordering issue in direct io. review Hi This patch replace that function ocfs2_direct_IO_get_blocks with this function ocfs2_get_blocks in ocfs2_direct_IO, and remove the ip_alloc_sem. but i think ip_alloc_sem is still needed because protect allocation changes is very correct. Now, BUG_ON have been tiggered in the process of testing direct-io. Comments and questions are, as always, welcome. Thanks As wangww631 described In ocfs2, ip_alloc_sem is used to protect allocation changes on the node. In direct IO, we add ip_alloc_sem to protect date consistent between direct-io and ocfs2_truncate_file race (buffer io use ip_alloc_sem already). Although inode->i_mutex lock is used to avoid concurrency of above situation, i think ip_alloc_sem is still needed because protect allocation changes is significant. Other filesystem like ext4 also uses rw_semaphore to protect data consistent between get_block-vs-truncate race by other means, So ip_alloc_sem in ocfs2 direct io is needed. Date: Fri, 11 Sep 2015 16:19:18 +0800 From: Ryan Ding Subject: [Ocfs2-devel] [PATCH 7/8] ocfs2: fix sparse file & data ordering issue in direct io. To: ocfs2-devel@oss.oracle.com Cc: mfasheh@suse.de Message-ID: <1441959559-29947-8-git-send-email-ryan.ding@oracle.com> There are mainly 3 issue in the direct io code path after commit 24c40b329e03 ("ocfs2: implement ocfs2_direct_IO_write"): * Do not support sparse file. * Do not support data ordering. eg: when write to a file hole, it will alloc extent first. If system crashed before io finished, data will corrupt. * Potential risk when doing aio+dio. The -EIOCBQUEUED return value is likely to be ignored by ocfs2_direct_IO_write(). To resolve above problems, re-design direct io code with following ideas: * Use buffer io to fill in holes. And this will make better performance also. * Clear unwritten after direct write finished. So we can make sure meta data changes after data write to disk. (Unwritten extent is invisible to user, from user's view, meta data is not changed when allocate an unwritten extent.) * Clear ocfs2_direct_IO_write(). Do all ending work in end_io. This patch has passed fs,dio,ltp-aiodio.part1,ltp-aiodio.part2,ltp-aiodio.part4 test cases of ltp. Signed-off-by: Ryan Ding Reviewed-by: Junxiao Bi cc: Joseph Qi ________________________________ All the best wishes for you. zhangguanghui ------------------------------------------------------------------------------------------------------------------------------------- 本邮件及其附件含有新华三技术有限公司的保密信息,仅限于发送给上面地址中列出 的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、 或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本 邮件! This e-mail and its attachments contain confidential information from New H3C, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it! --- a/aops.c 2017-05-27 01:23:35.591274026 -0400 +++ b/aops.c 2017-05-27 01:29:44.743285821 -0400 @@ -2396,6 +2396,35 @@ return 0; } +/* + * TODO: Make this into a generic get_blocks function. + * + * In ocfs2, ip_alloc_sem is used to protect allocation changes on the node. + * In direct IO, we add ip_alloc_sem to protect date consistent between + * direct-io and ocfs2_truncate_file race (buffer io use ip_alloc_sem + * already). Although inode->i_mutex lock is used to avoid concurrency of + * above situation, i think ip_alloc_sem is still needed because protect + * allocation changes is significant. + * + * This function is called directly from get_more_blocks in direct-io.c. + * + * called like this: dio->get_blocks(dio->inode, fs_startblk, + * fs_count, map_bh, dio->rw == READ); + */ +static int ocfs2_dio_read_get_block(struct inode *inode, sector_t iblock, + struct buffer_head *bh_result, int create) +{ + struct ocfs2_inode_info *oi = OCFS2_I(inode); + int ret = 0; + + down_read(&oi->ip_alloc_sem); + /* This is the fast path for direct-io reading. */ + ret = ocfs2_get_block(inode, iblock, bh_result, create); + up_read(&oi->ip_alloc_sem); + + return ret; +} + static ssize_t ocfs2_direct_IO(struct kiocb *iocb, struct iov_iter *iter) { struct file *file = iocb->ki_filp; @@ -2416,7 +2445,7 @@ return 0; if (iov_iter_rw(iter) == READ) - get_block = ocfs2_get_block; + get_block = ocfs2_dio_read_get_block; else get_block = ocfs2_dio_get_block;