From patchwork Fri Sep 26 09:59:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WeiWei Wang X-Patchwork-Id: 4980251 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 7B15F9F32B for ; Fri, 26 Sep 2014 10:00:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B2A8A202E5 for ; Fri, 26 Sep 2014 10:00:01 +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 90E66201FE for ; Fri, 26 Sep 2014 10:00:00 +0000 (UTC) Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s8Q9xO5J009830 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 26 Sep 2014 09:59:25 GMT Received: from oss.oracle.com (oss-external.oracle.com [137.254.96.51]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s8Q9xOXn015195 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 26 Sep 2014 09:59:24 GMT Received: from localhost ([127.0.0.1] helo=oss.oracle.com) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1XXSJA-00072t-8K; Fri, 26 Sep 2014 02:59:24 -0700 Received: from acsinet21.oracle.com ([141.146.126.237]) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1XXSJ5-00071z-9U for ocfs2-devel@oss.oracle.com; Fri, 26 Sep 2014 02:59:19 -0700 Received: from userp1030.oracle.com (userp1030.oracle.com [156.151.31.80]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s8Q9xIHg014983 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 26 Sep 2014 09:59:19 GMT Received: from userp2020.oracle.com (userp2020.oracle.com [156.151.31.84]) by userp1030.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s8Q9xIo1013038 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 26 Sep 2014 09:59:18 GMT Received: from pps.filterd (userp2020.oracle.com [127.0.0.1]) by userp2020.oracle.com (8.14.7/8.14.7) with SMTP id s8Q9xALi044006 for ; Fri, 26 Sep 2014 09:59:18 GMT Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [119.145.14.64]) by userp2020.oracle.com with ESMTP id 1pn3ybhcwe-1 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for ; Fri, 26 Sep 2014 09:59:17 +0000 Received: from 172.24.2.119 (EHLO szxeml405-hub.china.huawei.com) ([172.24.2.119]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CCE65370; Fri, 26 Sep 2014 17:59:13 +0800 (CST) Received: from [127.0.0.1] (10.177.31.189) by szxeml405-hub.china.huawei.com (10.82.67.60) with Microsoft SMTP Server id 14.3.158.1; Fri, 26 Sep 2014 17:59:11 +0800 Message-ID: <542538ED.9000302@huawei.com> Date: Fri, 26 Sep 2014 17:59:09 +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=7572 signatures=670529 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-1409260092 Cc: mfasheh@suse.com, ocfs2-devel@oss.oracle.com Subject: [Ocfs2-devel] [PATCH 4/7 v3] 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: acsinet21.oracle.com [141.146.126.237] 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(-) 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,