The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: "Sébastien Dugué" <sebastien.dugue@bull.net>
Cc: linux-aio@kvack.org, linux-kernel@vger.kernel.org,
	Suparna Bhattacharya <suparna@in.ibm.com>,
	Badari Pulavarty <pbadari@us.ibm.com>
Subject: Re: [PATCH] 2.6.10 -  direct-io async short read bug
Date: Mon, 7 Mar 2005 22:39:17 -0800	[thread overview]
Message-ID: <20050307223917.1e800784.akpm@osdl.org> (raw)
In-Reply-To: <1110189607.11938.14.camel@frecb000686>

Sébastien Dugué <sebastien.dugue@bull.net> wrote:
>
> When reading a file in async mode (using kernel AIO), and the file
>  size is lower than the requested size (short read),  the direct IO
>  layer reports an incorrect number of bytes read (transferred).
> 
>   That case is handled for the sync path in 'direct_io_worker' 
>  (fs/direct-io.c) where a check is made against the file size.
> 
>   This patch does the same thing for the async path.

It looks sane to me.  It needs a couple of fixes, below.  One of them is
horrid and isn't really a fix at all, but it improves things.

Would Suparna and Badari have time to check the logic of these two patches
please?




- i_size is 64 bit, ssize_t is 32-bit

- whitespace tweaks.

- i_size_read() in interrupt context is a no-no.

Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 25-akpm/fs/direct-io.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diff -puN fs/direct-io.c~direct-io-async-short-read-fix-fix fs/direct-io.c
--- 25/fs/direct-io.c~direct-io-async-short-read-fix-fix	2005-03-07 22:28:52.000000000 -0800
+++ 25-akpm/fs/direct-io.c	2005-03-07 22:37:18.000000000 -0800
@@ -231,7 +231,7 @@ static void finished_one_bio(struct dio 
 	if (dio->bio_count == 1) {
 		if (dio->is_async) {
 			ssize_t transferred;
-			ssize_t i_size;
+			loff_t i_size;
 			loff_t offset;
 
 			/*
@@ -241,11 +241,19 @@ static void finished_one_bio(struct dio 
 			spin_unlock_irqrestore(&dio->bio_lock, flags);
 
 			/* Check for short read case */
+
+			/*
+			 * We should use i_size_read() here.  But we're called
+			 * in interrupt context.  If this CPU happened to be
+			 * in the middle of i_size_write() when the interrupt
+			 * occurred, i_size_read() would lock up.
+			 * So we just risk getting a wrong result instead :(
+			 */
+			i_size = dio->inode->i_size;
 			transferred = dio->result;
-			i_size = i_size_read (dio->inode);
 			offset = dio->iocb->ki_pos;
 
-			if ((dio->rw == READ) && ((offset + transferred) > i_size))
+			if ((dio->rw == READ) && (offset+transferred > i_size))
 				transferred = i_size - offset;
 
 			dio_complete(dio, offset, transferred);
_


  reply	other threads:[~2005-03-08  6:44 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-07 10:00 [PATCH] 2.6.10 - direct-io async short read bug Sébastien Dugué
2005-03-08  6:39 ` Andrew Morton [this message]
2005-03-08  9:09   ` Suparna Bhattacharya
2005-03-08  9:18     ` Andrew Morton
2005-03-08  9:41       ` Suparna Bhattacharya
2005-03-08  9:41         ` Andrew Morton
2005-03-08 10:27           ` Suparna Bhattacharya
2005-03-08 10:27             ` Andrew Morton
2005-03-08 17:23     ` Badari Pulavarty
2005-03-08 19:18       ` Badari Pulavarty
2005-03-08 23:27         ` Daniel McNeil
2005-03-08 23:54           ` Badari Pulavarty
2005-03-09  4:07             ` Joel Becker
2005-03-09  9:50               ` Sébastien Dugué
2005-03-09 15:20               ` Suparna Bhattacharya
2005-03-09 19:53                 ` Andrew Morton
2005-03-09 21:18                   ` Joel Becker
2005-03-09 21:31                   ` Badari Pulavarty
2005-03-09 22:39                     ` Andrew Morton
2005-03-09 22:45                       ` Badari Pulavarty
2005-03-09  1:44         ` Daniel McNeil
2005-03-09 15:58           ` Badari Pulavarty
  -- strict thread matches above, loose matches on Subject: below --
2005-03-08  9:46 Sébastien Dugué
2005-03-08 10:16 Sébastien Dugué

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=20050307223917.1e800784.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=linux-aio@kvack.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbadari@us.ibm.com \
    --cc=sebastien.dugue@bull.net \
    --cc=suparna@in.ibm.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