* [PATCH] ext4: Fix data corruption with direct IO read in dioread_nolock mode
@ 2013-04-08 16:27 Jan Kara
2013-04-10 21:08 ` Jan Kara
2013-04-11 13:20 ` Zheng Liu
0 siblings, 2 replies; 6+ messages in thread
From: Jan Kara @ 2013-04-08 16:27 UTC (permalink / raw)
To: Ted Tso; +Cc: linux-ext4, Jan Kara
When ext4 is mounted in dioread_nolock mode, it calls
__blockdev_direct_IO() without DIO_LOCKING flag which also means mapping
is not synced before direct IO starts. As a result consistency between
buffered writes and following direct IO reads is broken. More
importantly, if the file is truncated, and extented back, zeroing of the
tail page is not visible to the following direct IO read which will return
stale data.
Fix the problem by flushing dirty pages before issuing direct IO read.
Signed-off-by: Jan Kara <jack@suse.cz>
---
fs/ext4/indirect.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c
index b505a14..c18bf1c 100644
--- a/fs/ext4/indirect.c
+++ b/fs/ext4/indirect.c
@@ -809,6 +809,10 @@ ssize_t ext4_ind_direct_IO(int rw, struct kiocb *iocb,
retry:
if (rw == READ && ext4_should_dioread_nolock(inode)) {
+ ret = filemap_write_and_wait_range(inode->i_mapping, offset,
+ offset + count - 1);
+ if (ret)
+ goto out;
if (unlikely(atomic_read(&EXT4_I(inode)->i_unwritten))) {
mutex_lock(&inode->i_mutex);
ext4_flush_unwritten_io(inode);
--
1.7.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] ext4: Fix data corruption with direct IO read in dioread_nolock mode
2013-04-08 16:27 [PATCH] ext4: Fix data corruption with direct IO read in dioread_nolock mode Jan Kara
@ 2013-04-10 21:08 ` Jan Kara
2013-04-11 0:47 ` Theodore Ts'o
2013-04-11 13:20 ` Zheng Liu
1 sibling, 1 reply; 6+ messages in thread
From: Jan Kara @ 2013-04-10 21:08 UTC (permalink / raw)
To: Ted Tso; +Cc: linux-ext4, Jan Kara
On Mon 08-04-13 18:27:43, Jan Kara wrote:
> When ext4 is mounted in dioread_nolock mode, it calls
> __blockdev_direct_IO() without DIO_LOCKING flag which also means mapping
> is not synced before direct IO starts. As a result consistency between
> buffered writes and following direct IO reads is broken. More
> importantly, if the file is truncated, and extented back, zeroing of the
> tail page is not visible to the following direct IO read which will return
> stale data.
>
> Fix the problem by flushing dirty pages before issuing direct IO read.
>
> Signed-off-by: Jan Kara <jack@suse.cz>
Ted, didn't you miss this patch?
Honza
> ---
> fs/ext4/indirect.c | 4 ++++
> 1 files changed, 4 insertions(+), 0 deletions(-)
>
> diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c
> index b505a14..c18bf1c 100644
> --- a/fs/ext4/indirect.c
> +++ b/fs/ext4/indirect.c
> @@ -809,6 +809,10 @@ ssize_t ext4_ind_direct_IO(int rw, struct kiocb *iocb,
>
> retry:
> if (rw == READ && ext4_should_dioread_nolock(inode)) {
> + ret = filemap_write_and_wait_range(inode->i_mapping, offset,
> + offset + count - 1);
> + if (ret)
> + goto out;
> if (unlikely(atomic_read(&EXT4_I(inode)->i_unwritten))) {
> mutex_lock(&inode->i_mutex);
> ext4_flush_unwritten_io(inode);
> --
> 1.7.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Jan Kara <jack@suse.cz>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ext4: Fix data corruption with direct IO read in dioread_nolock mode
2013-04-10 21:08 ` Jan Kara
@ 2013-04-11 0:47 ` Theodore Ts'o
0 siblings, 0 replies; 6+ messages in thread
From: Theodore Ts'o @ 2013-04-11 0:47 UTC (permalink / raw)
To: Jan Kara; +Cc: linux-ext4
On Wed, Apr 10, 2013 at 11:08:21PM +0200, Jan Kara wrote:
> Ted, didn't you miss this patch?
I didn't miss it, I was just dealing with the older patches first, and
waiting to see if anyone would comment on it before I applied it into
the tree. (That way I'm not the only person reviewing all of the
patches. :-)
But thanks, I've added it to the ext4 patch queue.
- Ted
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ext4: Fix data corruption with direct IO read in dioread_nolock mode
2013-04-08 16:27 [PATCH] ext4: Fix data corruption with direct IO read in dioread_nolock mode Jan Kara
2013-04-10 21:08 ` Jan Kara
@ 2013-04-11 13:20 ` Zheng Liu
2013-04-11 21:07 ` Jan Kara
1 sibling, 1 reply; 6+ messages in thread
From: Zheng Liu @ 2013-04-11 13:20 UTC (permalink / raw)
To: Jan Kara; +Cc: Ted Tso, linux-ext4
On Mon, Apr 08, 2013 at 06:27:43PM +0200, Jan Kara wrote:
> When ext4 is mounted in dioread_nolock mode, it calls
> __blockdev_direct_IO() without DIO_LOCKING flag which also means mapping
> is not synced before direct IO starts. As a result consistency between
> buffered writes and following direct IO reads is broken. More
> importantly, if the file is truncated, and extented back, zeroing of the
> tail page is not visible to the following direct IO read which will return
> stale data.
>
> Fix the problem by flushing dirty pages before issuing direct IO read.
>
> Signed-off-by: Jan Kara <jack@suse.cz>
> ---
> fs/ext4/indirect.c | 4 ++++
> 1 files changed, 4 insertions(+), 0 deletions(-)
>
> diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c
> index b505a14..c18bf1c 100644
> --- a/fs/ext4/indirect.c
> +++ b/fs/ext4/indirect.c
> @@ -809,6 +809,10 @@ ssize_t ext4_ind_direct_IO(int rw, struct kiocb *iocb,
>
> retry:
> if (rw == READ && ext4_should_dioread_nolock(inode)) {
> + ret = filemap_write_and_wait_range(inode->i_mapping, offset,
> + offset + count - 1);
> + if (ret)
> + goto out;
> if (unlikely(atomic_read(&EXT4_I(inode)->i_unwritten))) {
> mutex_lock(&inode->i_mutex);
> ext4_flush_unwritten_io(inode);
Hi Jan,
Sorry for the late reply. I have a question about this patch. In your
patch, we flush dirty pages befoer issuing a dio read. But we have
flushed dirty pages in generic_file_aio_read(). So is it really
necessary to flush dirty pages again?
Regards,
- Zheng
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ext4: Fix data corruption with direct IO read in dioread_nolock mode
2013-04-11 13:20 ` Zheng Liu
@ 2013-04-11 21:07 ` Jan Kara
2013-04-12 3:18 ` Theodore Ts'o
0 siblings, 1 reply; 6+ messages in thread
From: Jan Kara @ 2013-04-11 21:07 UTC (permalink / raw)
To: Zheng Liu; +Cc: Jan Kara, Ted Tso, linux-ext4
On Thu 11-04-13 21:20:36, Zheng Liu wrote:
> On Mon, Apr 08, 2013 at 06:27:43PM +0200, Jan Kara wrote:
> > When ext4 is mounted in dioread_nolock mode, it calls
> > __blockdev_direct_IO() without DIO_LOCKING flag which also means mapping
> > is not synced before direct IO starts. As a result consistency between
> > buffered writes and following direct IO reads is broken. More
> > importantly, if the file is truncated, and extented back, zeroing of the
> > tail page is not visible to the following direct IO read which will return
> > stale data.
> >
> > Fix the problem by flushing dirty pages before issuing direct IO read.
> >
> > Signed-off-by: Jan Kara <jack@suse.cz>
> > ---
> > fs/ext4/indirect.c | 4 ++++
> > 1 files changed, 4 insertions(+), 0 deletions(-)
> >
> > diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c
> > index b505a14..c18bf1c 100644
> > --- a/fs/ext4/indirect.c
> > +++ b/fs/ext4/indirect.c
> > @@ -809,6 +809,10 @@ ssize_t ext4_ind_direct_IO(int rw, struct kiocb *iocb,
> >
> > retry:
> > if (rw == READ && ext4_should_dioread_nolock(inode)) {
> > + ret = filemap_write_and_wait_range(inode->i_mapping, offset,
> > + offset + count - 1);
> > + if (ret)
> > + goto out;
> > if (unlikely(atomic_read(&EXT4_I(inode)->i_unwritten))) {
> > mutex_lock(&inode->i_mutex);
> > ext4_flush_unwritten_io(inode);
>
> Hi Jan,
>
> Sorry for the late reply. I have a question about this patch. In your
> patch, we flush dirty pages befoer issuing a dio read. But we have
> flushed dirty pages in generic_file_aio_read(). So is it really
> necessary to flush dirty pages again?
Doh, you are right. I didn't notice that. Thanks for correcting me. I was
seeing a failure in xfstest 091 (fsx using direct IO) with dioread_nolock
and I thought the missing flush was the culprit (as fsx saw non-zeros in
the tail of the page that was truncated). After adding the flush I didn't
see it anymore. But now I'm not able to trigger the failure again
regardless whether the patch is applied or not. So Ted, please drop the
patch and I'll watch out if I ever see the failure again.
Honza
--
Jan Kara <jack@suse.cz>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ext4: Fix data corruption with direct IO read in dioread_nolock mode
2013-04-11 21:07 ` Jan Kara
@ 2013-04-12 3:18 ` Theodore Ts'o
0 siblings, 0 replies; 6+ messages in thread
From: Theodore Ts'o @ 2013-04-12 3:18 UTC (permalink / raw)
To: Jan Kara; +Cc: Zheng Liu, linux-ext4
On Thu, Apr 11, 2013 at 11:07:56PM +0200, Jan Kara wrote:
> Doh, you are right. I didn't notice that. Thanks for correcting me. I was
> seeing a failure in xfstest 091 (fsx using direct IO) with dioread_nolock
> and I thought the missing flush was the culprit (as fsx saw non-zeros in
> the tail of the page that was truncated). After adding the flush I didn't
> see it anymore. But now I'm not able to trigger the failure again
> regardless whether the patch is applied or not. So Ted, please drop the
> patch and I'll watch out if I ever see the failure again.
Dropped.
- Ted
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-04-12 3:18 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-08 16:27 [PATCH] ext4: Fix data corruption with direct IO read in dioread_nolock mode Jan Kara
2013-04-10 21:08 ` Jan Kara
2013-04-11 0:47 ` Theodore Ts'o
2013-04-11 13:20 ` Zheng Liu
2013-04-11 21:07 ` Jan Kara
2013-04-12 3:18 ` Theodore Ts'o
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).