From: Tao Ma <tao.ma@oracle.com>
To: ocfs2-devel@oss.oracle.com
Subject: [Ocfs2-devel] [PATCH] ocfs2: avoid direct write if we fall back to buffered
Date: Fri, 09 Apr 2010 11:32:10 +0800 [thread overview]
Message-ID: <4BBE9FBA.9070004@oracle.com> (raw)
In-Reply-To: <201004091100.28988.lidongyang@novell.com>
Hi Dongyang,
Li Dongyang wrote:
> Hi, Tao,
> On Friday 09 April 2010 10:38:33 Tao Ma wrote:
>> Hi Dongyang,
>>
>> Li Dongyang wrote:
>>> This is because ocfs2_file_aio_write calls ocfs2_prepare_inode_for_write
>>> which sets direct_io to 0 if it finds out that direct IO would extend the
>>> file. But later we call __generic_file_aio_write which end's up calling
>>> generic_file_direct_write because the file has O_DIRECT flag.So every
>>> time we do a direct write extending the file, the inode->i_size gets
>>> inconsistent with the i_size on disk because we call
>>> generic_file_direct_write, and if we do a truncate after this, we will
>>> meet a bug in ocfs2_truncate_file.
>> yes we have O_DIRECT flag set and in __generic_file_aio_write it will
>> call generic_file_direct_write first and then trigger to
>> ocfs2_direct_IO. In this function we will check again and return 0. And
>> _generic_file_aio_write will fall back to buffered write if the directIO
>> can't write. Am I wrong somehow?
>>
> yes ocfs2_direct_IO has some check, but it just check if we are appending(the
> i_size <= offset), if the offset < i_size and offset + count > i_size, it will
> do direct io anyway. seems we also can fix this by adding a check to
> ocfs2_direct_IO.
It is done by ocfs2_direct_IO_get_blocks. Just debug the kernel and you
will get what I mean. ;)
Regards,
Tao
> Br,
> Li Dongyang
>> Regards,
>> Tao
>>
>>> On Friday 09 April 2010 02:41:26 Sunil Mushran wrote:
>>>> I cannot read the bugzilla. Now it maybe that that bz
>>>> cannot be made public. That's ok. But if that's the case,
>>>> can you explain the problem encountered. I am not qs
>>>> the fix... rather trying to understand why this has not
>>>> been reported before.
>>>>
>>>> Li Dongyang wrote:
>>>>> when we fall back to buffered write from direct write, we call
>>>>> __generic_file_aio_write but that will end up doing direct write
>>>>> even we are only prepared to do buffered write because the file
>>>>> has O_DIRECT flag set. This is a fix for
>>>>> https://bugzilla.novell.com/show_bug.cgi?id=591039
>>>>>
>>>>>
>>>>> Signed-off-by: Li Dongyang <lidongyang@novell.com>
>>>>> ---
>>>>> fs/ocfs2/file.c | 27 +++++++++++++++++----------
>>>>> 1 files changed, 17 insertions(+), 10 deletions(-)
>>>>>
>>>>> diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
>>>>> index de059f4..707f2a2 100644
>>>>> --- a/fs/ocfs2/file.c
>>>>> +++ b/fs/ocfs2/file.c
>>>>> @@ -1973,18 +1973,24 @@ relock:
>>>>> /* communicate with ocfs2_dio_end_io */
>>>>> ocfs2_iocb_set_rw_locked(iocb, rw_level);
>>>>>
>>>>> - if (direct_io) {
>>>>> - ret = generic_segment_checks(iov, &nr_segs, &ocount,
>>>>> - VERIFY_READ);
>>>>> - if (ret)
>>>>> - goto out_dio;
>>>>> + ret = generic_segment_checks(iov, &nr_segs, &ocount,
>>>>> + VERIFY_READ);
>>>>> + if (ret)
>>>>> + goto out_dio;
>>>>>
>>>>> - count = ocount;
>>>>> - ret = generic_write_checks(file, ppos, &count,
>>>>> + count = ocount;
>>>>> + ret = generic_write_checks(file, ppos, &count,
>>>>> S_ISBLK(inode->i_mode));
>>>>> - if (ret)
>>>>> - goto out_dio;
>>>>> + if (ret)
>>>>> + goto out_dio;
>>>>> +
>>>>> + ret = file_remove_suid(file);
>>>>> + if (ret)
>>>>> + goto out_dio;
>>>>>
>>>>> + file_update_time(file);
>>>>> +
>>>>> + if (direct_io) {
>>>>> written = generic_file_direct_write(iocb, iov, &nr_segs, *ppos,
>>>>> ppos, count, ocount);
>>>>> if (written < 0) {
>>>>> @@ -1999,7 +2005,8 @@ relock:
>>>>> goto out_dio;
>>>>> }
>>>>> } else {
>>>>> - written = __generic_file_aio_write(iocb, iov, nr_segs, ppos);
>>>>> + written = generic_file_buffered_write(iocb, iov, nr_segs,
>>>>> + *ppos, ppos, count, 0);
>>>>> }
>>>>>
>>>>> out_dio:
>>> _______________________________________________
>>> Ocfs2-devel mailing list
>>> Ocfs2-devel at oss.oracle.com
>>> http://oss.oracle.com/mailman/listinfo/ocfs2-devel
next prev parent reply other threads:[~2010-04-09 3:32 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-08 7:47 [Ocfs2-devel] [PATCH] ocfs2: avoid direct write if we fall back to buffered Li Dongyang
2010-04-08 18:41 ` Sunil Mushran
2010-04-09 2:27 ` Li Dongyang
2010-04-09 2:38 ` Tao Ma
2010-04-09 3:00 ` Li Dongyang
2010-04-09 3:32 ` Tao Ma [this message]
2010-04-09 9:20 ` Li Dongyang
2010-04-09 17:36 ` Sunil Mushran
2010-04-09 7:58 ` Coly Li
2010-04-09 7:56 ` Tao Ma
2010-04-14 1:58 ` Joel Becker
2010-04-14 7:42 ` Li Dongyang
-- strict thread matches above, loose matches on Subject: below --
2010-04-10 7:37 Dong Yang Li
2010-04-10 9:37 ` Joel Becker
2010-04-10 9:48 ` Li Dongyang
2010-04-12 5:16 ` Tao Ma
2010-04-12 5:31 ` Li Dongyang
2010-04-12 6:24 ` Tao Ma
2010-04-14 2:44 ` Tao Ma
2010-04-14 5:47 ` Li Dongyang
2010-04-14 6:08 ` Tao Ma
2010-04-13 23:54 ` Joel Becker
2010-04-14 0:13 ` Tao Ma
2010-04-14 5:58 ` Li Dongyang
2010-04-14 19:20 ` Joel Becker
2010-04-22 14:13 ` Li Dongyang
2010-04-23 20:06 ` Joel Becker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4BBE9FBA.9070004@oracle.com \
--to=tao.ma@oracle.com \
--cc=ocfs2-devel@oss.oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).