The patch titled Subject: ocfs2-nowait-aio-support-v2 has been added to the -mm tree. Its filename is ocfs2-nowait-aio-support-v2.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/ocfs2-nowait-aio-support-v2.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/ocfs2-nowait-aio-support-v2.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/SubmitChecklist when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Gang He <ghe@xxxxxxxx> Subject: ocfs2-nowait-aio-support-v2 Return -EAGAIN if any of the following checks fail for direct I/O with nowait flag: Can not get the related locks immediately, Blocks are not allocated at the write location, it will trigger block allocation, this will block IO operations. Link: http://lkml.kernel.org/r/1511944612-9629-4-git-send-email-ghe@xxxxxxxx Signed-off-by: Gang He <ghe@xxxxxxxx> Cc: Mark Fasheh <mfasheh@xxxxxxxxxxx> Cc: Joel Becker <jlbec@xxxxxxxxxxxx> Cc: Junxiao Bi <junxiao.bi@xxxxxxxxxx> Cc: Joseph Qi <jiangqi903@xxxxxxxxx> Cc: Changwei Ge <ge.changwei@xxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- fs/ocfs2/file.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff -puN fs/ocfs2/file.c~ocfs2-nowait-aio-support-v2 fs/ocfs2/file.c --- a/fs/ocfs2/file.c~ocfs2-nowait-aio-support-v2 +++ a/fs/ocfs2/file.c @@ -2136,9 +2136,10 @@ out: static int ocfs2_prepare_inode_for_write(struct file *file, loff_t pos, size_t count, int wait) { - int ret = 0, meta_level = 0; + int ret = 0, meta_level = 0, overwrite_io = 0; struct dentry *dentry = file->f_path.dentry; struct inode *inode = d_inode(dentry); + struct buffer_head *di_bh = NULL; loff_t end; /* @@ -2149,7 +2150,8 @@ static int ocfs2_prepare_inode_for_write if (wait) ret = ocfs2_inode_lock(inode, NULL, meta_level); else - ret = ocfs2_try_inode_lock(inode, NULL, meta_level); + ret = ocfs2_try_inode_lock(inode, + overwrite_io ? NULL : &di_bh, meta_level); if (ret < 0) { meta_level = -1; if (ret != -EAGAIN) @@ -2157,6 +2159,28 @@ static int ocfs2_prepare_inode_for_write goto out; } + /* + * Check if IO will overwrite allocated blocks in case + * IOCB_NOWAIT flag is set. + */ + if (!wait && !overwrite_io) { + overwrite_io = 1; + if (!down_read_trylock(&OCFS2_I(inode)->ip_alloc_sem)) { + ret = -EAGAIN; + goto out_unlock; + } + + ret = ocfs2_overwrite_io(inode, di_bh, pos, count); + brelse(di_bh); + di_bh = NULL; + up_read(&OCFS2_I(inode)->ip_alloc_sem); + if (ret < 0) { + if (ret != -EAGAIN) + mlog_errno(ret); + goto out_unlock; + } + } + /* Clear suid / sgid if necessary. We do this here * instead of later in the write path because * remove_suid() calls ->setattr without any hint that @@ -2206,6 +2230,8 @@ out_unlock: trace_ocfs2_prepare_inode_for_write(OCFS2_I(inode)->ip_blkno, pos, count, wait); + brelse(di_bh); + if (meta_level >= 0) ocfs2_inode_unlock(inode, meta_level); @@ -2297,13 +2323,6 @@ static ssize_t ocfs2_file_write_iter(str } count = ret; - if (direct_io && nowait) { - if (!ocfs2_overwrite_io(inode, iocb->ki_pos, count, 0)) { - ret = -EAGAIN; - goto out; - } - } - ret = ocfs2_prepare_inode_for_write(file, iocb->ki_pos, count, !nowait); if (ret < 0) { if (ret != -EAGAIN) _ Patches currently in -mm which might be from ghe@xxxxxxxx are ocfs2-get-rid-of-ocfs2_is_o2cb_active-function.patch ocfs2-give-an-obvious-tip-for-dismatch-cluster-names.patch ocfs2-give-an-obvious-tip-for-dismatch-cluster-names-v2.patch ocfs2-move-some-definitions-to-header-file.patch ocfs2-fix-some-small-problems.patch ocfs2-add-kobject-for-online-file-check.patch ocfs2-add-duplicative-ino-number-check.patch ocfs2-add-ocfs2_try_rw_lock-and-ocfs2_try_inode_lock.patch ocfs2-add-ocfs2_try_rw_lock-and-ocfs2_try_inode_lock-v2.patch ocfs2-add-ocfs2_overwrite_io-function.patch ocfs2-add-ocfs2_overwrite_io-function-v2.patch ocfs2-nowait-aio-support.patch ocfs2-nowait-aio-support-v2.patch -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html