linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: liubo <liubo2009@cn.fujitsu.com>
To: linux-btrfs@vger.kernel.org
Cc: Josef Bacik <josef@redhat.com>, jim owens <owens6336@gmail.com>,
	Chris Mason <chris.mason@oracle.com>,
	"Yan, Zheng" <zheng.yan@oracle.com>
Subject: [PATCH] btrfs/direct-IO: fix a bug of btrfs_dio_read
Date: Thu, 06 May 2010 10:12:10 +0800	[thread overview]
Message-ID: <4BE2257A.7030005@cn.fujitsu.com> (raw)

As I mentioned in the bug-report, when the file size is 
not n * BUFFERSIZE, this file cannot be read correctly 
and the system will crash or hang up.

After investigation, I fount that data_len should be 
checked before lock_extent, in order to prevent the 
situation that when it comes to the file end, 
diocb->lockstart changes to lockend+1, then lock_extent
 will cause system's crash or hang.

So move the data_len's check ahead.

Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
---
 fs/btrfs/dio.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/btrfs/dio.c b/fs/btrfs/dio.c
index c930ff5..7178a25 100644
--- a/fs/btrfs/dio.c
+++ b/fs/btrfs/dio.c
@@ -517,11 +517,6 @@ static void btrfs_dio_read(struct btrfs_diocb *diocb)
 	lockend = ALIGN(end, blocksize) - 1;
 
 getlock:
-	/* writeout everything we read for checksum or compressed extents */
-	filemap_write_and_wait_range(diocb->inode->i_mapping,
-				diocb->lockstart, lockend);
-	lock_extent(io_tree, diocb->lockstart, lockend, GFP_NOFS);
-
 	data_len = min_t(u64, end, i_size_read(diocb->inode));
 	if (data_len <= diocb->start) {
 		/* whatever we finished (or 0) is returned past EOF */
@@ -529,6 +524,11 @@ getlock:
 	}
 	data_len -= diocb->start;
 
+	/* writeout everything we read for checksum or compressed extents */
+	filemap_write_and_wait_range(diocb->inode->i_mapping,
+				diocb->lockstart, lockend);
+	lock_extent(io_tree, diocb->lockstart, lockend, GFP_NOFS);
+
 	safe_to_read = 0;
 	while (data_len && !diocb->error) { /* error in reaper stops submit */
 		struct extent_map *em;
-- 
1.6.2.5



             reply	other threads:[~2010-05-06  2:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-06  2:12 liubo [this message]
2010-05-06  2:11 ` [PATCH] btrfs/direct-IO: fix a bug of btrfs_dio_read Josef Bacik
2010-05-06  2:24   ` liubo

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=4BE2257A.7030005@cn.fujitsu.com \
    --to=liubo2009@cn.fujitsu.com \
    --cc=chris.mason@oracle.com \
    --cc=josef@redhat.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=owens6336@gmail.com \
    --cc=zheng.yan@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).