From patchwork Tue Sep 23 09:12:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WeiWei Wang X-Patchwork-Id: 4954471 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 CAD599F2BB for ; Tue, 23 Sep 2014 09:13:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 80122201C0 for ; Tue, 23 Sep 2014 09:13:42 +0000 (UTC) Received: from userp1040.oracle.com (userp1040.oracle.com [156.151.31.81]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 037CE201BB for ; Tue, 23 Sep 2014 09:13:40 +0000 (UTC) Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s8N9D623020993 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 23 Sep 2014 09:13:07 GMT Received: from oss.oracle.com (oss-external.oracle.com [137.254.96.51]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s8N9D4hI001457 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 23 Sep 2014 09:13:04 GMT Received: from localhost ([127.0.0.1] helo=oss.oracle.com) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1XWM9e-0002b3-05; Tue, 23 Sep 2014 02:13:02 -0700 Received: from acsinet22.oracle.com ([141.146.126.238]) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1XWM9Y-0002al-C4 for ocfs2-devel@oss.oracle.com; Tue, 23 Sep 2014 02:12:56 -0700 Received: from userp1030.oracle.com (userp1030.oracle.com [156.151.31.80]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s8N9Ctpa000847 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 23 Sep 2014 09:12:56 GMT Received: from aserp2020.oracle.com (aserp2020.oracle.com [141.146.126.73]) by userp1030.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s8N9Csf9008739 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 23 Sep 2014 09:12:55 GMT Received: from pps.filterd (aserp2020.oracle.com [127.0.0.1]) by aserp2020.oracle.com (8.14.7/8.14.7) with SMTP id s8N9Br7T025614 for ; Tue, 23 Sep 2014 09:12:54 GMT Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [119.145.14.64]) by aserp2020.oracle.com with ESMTP id 1pk51vh1mn-1 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for ; Tue, 23 Sep 2014 09:12:54 +0000 Received: from 172.24.2.119 (EHLO szxeml420-hub.china.huawei.com) ([172.24.2.119]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CCA67325; Tue, 23 Sep 2014 17:12:48 +0800 (CST) Received: from [127.0.0.1] (10.177.31.189) by szxeml420-hub.china.huawei.com (10.82.67.159) with Microsoft SMTP Server id 14.3.158.1; Tue, 23 Sep 2014 17:12:44 +0800 Message-ID: <5421398A.6050604@huawei.com> Date: Tue, 23 Sep 2014 17:12:42 +0800 From: WeiWei Wang User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 MIME-Version: 1.0 To: Andrew Morton X-Originating-IP: [10.177.31.189] X-CFilter-Loop: Reflected X-ServerName: szxga01-in.huawei.com X-Proofpoint-Virus-Version: vendor=nai engine=5600 definitions=7569 signatures=670528 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=2 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=7.0.1-1402240000 definitions=main-1409230094 Cc: mfasheh@suse.com, ocfs2-devel@oss.oracle.com Subject: [Ocfs2-devel] [PATCH 4/7 v2] ocfs2: add and remove inode in orphan dir in ocfs2_direct_IO 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: acsinet22.oracle.com [141.146.126.238] X-Spam-Status: No, score=-4.9 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 This commit add the inode to orphan first, after direct-io write is finished, remove the inode from orphan dir. So the allocate blocks and change inode->i_size will be safe. Signed-off-by: Weiwei Wang --- fs/ocfs2/aops.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 114 insertions(+), 4 deletions(-) -- 1.8.4.3 diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c index 4a231a1..bdb91bd 100644 --- a/fs/ocfs2/aops.c +++ b/fs/ocfs2/aops.c @@ -47,6 +47,9 @@ #include "ocfs2_trace.h" #include "buffer_head_io.h" +#include "dir.h" +#include "namei.h" +#include "sysfile.h" static int ocfs2_symlink_get_block(struct inode *inode, sector_t iblock, struct buffer_head *bh_result, int create) @@ -602,8 +605,16 @@ static ssize_t ocfs2_direct_IO(int rw, struct iov_iter *iter, loff_t offset) { + ssize_t ret = 0; + int status = 0; + int orphan = 0; struct file *file = iocb->ki_filp; struct inode *inode = file_inode(file)->i_mapping->host; + struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); + struct buffer_head *di_bh = NULL; + handle_t *handle = NULL; + size_t count = iter->count; + journal_t *journal = osb->journal->j_journal; /* * Fallback to buffered I/O if we see an inode without @@ -616,10 +627,109 @@ static ssize_t ocfs2_direct_IO(int rw, if (i_size_read(inode) <= offset) return 0; - return __blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, - iter, offset, - ocfs2_direct_IO_get_blocks, - ocfs2_dio_end_io, NULL, 0); + if (rw == WRITE) { + loff_t final_size = offset + count; + /* + * when final_size > inode->i_size, inode->i_size will be + * updated after direct write, so add the inode to orphan + * dir first. + */ + if (final_size > i_size_read(inode)) { + handle = ocfs2_start_trans(osb, + OCFS2_INODE_ADD_TO_ORPHAN_CREDITS); + if (IS_ERR(handle)) { + status = PTR_ERR(handle); + goto out; + } + status = ocfs2_add_inode_to_orphan(osb, handle, inode); + if (status < 0) + goto out; + + orphan = 1; + ocfs2_commit_trans(osb, handle); + handle = NULL; + } + } + + if (rw == READ) + ret = __blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, + iter, offset, + ocfs2_direct_IO_get_blocks, + ocfs2_dio_end_io, NULL, 0); + else { + ret = blockdev_direct_IO(rw, iocb, inode, + iter, offset, + ocfs2_direct_IO_get_blocks); + + if (unlikely((rw & WRITE) && ret < 0)) { + loff_t isize = i_size_read(inode); + + if (offset + count > isize) { + status = ocfs2_inode_lock(inode, &di_bh, 1); + if (status < 0) { + mlog_errno(status); + goto out; + } + if (isize == i_size_read(inode)) + ocfs2_truncate_file(inode, di_bh, + isize); + + ocfs2_inode_unlock(inode, 1); + brelse(di_bh); + di_bh = NULL; + + status = jbd2_journal_force_commit(journal); + if (status < 0) + mlog_errno(status); + } + } + } + + if (orphan) { + handle = ocfs2_start_trans(osb, + OCFS2_INODE_DEL_FROM_ORPHAN_CREDITS); + if (IS_ERR(handle)) { + status = PTR_ERR(handle); + goto out; + } + + status = ocfs2_del_inode_from_orphan(osb, handle, inode); + if (status < 0) + goto out; + + /* after update the inode->i_size, call + * jbd2_journal_force_commit to flush the journal to disk */ + if (ret > 0) { + loff_t end = offset + ret; + + if (end > i_size_read(inode)) { + status = ocfs2_inode_lock(inode, &di_bh, 1); + if (status < 0) { + mlog_errno(status); + goto out; + } + status = ocfs2_set_inode_size(handle, inode, + di_bh, end); + if (status < 0) + mlog_errno(status); + ocfs2_inode_unlock(inode, 1); + brelse(di_bh); + } + } + ocfs2_commit_trans(osb, handle); + handle = NULL; + + status = jbd2_journal_force_commit(journal); + if (status < 0) + mlog_errno(status); + } + +out: + if (status < 0) + ret = status; + if (handle) + ocfs2_commit_trans(osb, handle); + return ret; } static void ocfs2_figure_cluster_boundaries(struct ocfs2_super *osb,