All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] 2.6.10 -  direct-io async short read bug
@ 2005-03-07 10:00 Sébastien Dugué
  2005-03-08  6:39 ` Andrew Morton
  0 siblings, 1 reply; 24+ messages in thread
From: Sébastien Dugué @ 2005-03-07 10:00 UTC (permalink / raw)
  To: linux-aio kvack.org, linux-kernel@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 817 bytes --]

 Hi,

 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 applies to
a vanilla 2.6.10 kernel.

 Please CC: me any comments and/or suggestions.

 Sébastien.

------------------------------------------------------

  Sébastien Dugué                BULL/FREC:B1-247
  phone: (+33) 476 29 77 70      Bullcom: 229-7770

  mailto:sebastien.dugue@bull.net

  Linux POSIX AIO: http://www.bullopensource.org/posix
  
------------------------------------------------------

[-- Attachment #2: Type: text/x-patch, Size: 1167 bytes --]

--- linux-2.6.10/fs/direct-io.c.orig	2005-03-03 12:41:05.541074051 +0100
+++ linux-2.6.10/fs/direct-io.c	2005-03-03 12:01:46.206210808 +0100
@@ -230,17 +230,30 @@ static void finished_one_bio(struct dio 
 	spin_lock_irqsave(&dio->bio_lock, flags);
 	if (dio->bio_count == 1) {
 		if (dio->is_async) {
+			ssize_t transferred;
+			ssize_t i_size;
+			loff_t offset;
+
 			/*
 			 * Last reference to the dio is going away.
 			 * Drop spinlock and complete the DIO.
 			 */
 			spin_unlock_irqrestore(&dio->bio_lock, flags);
-			dio_complete(dio, dio->block_in_file << dio->blkbits,
-					dio->result);
+
+			/* Check for short read case */
+			transferred = dio->result;
+			i_size = i_size_read (dio->inode);
+			offset = dio->iocb->ki_pos;
+
+			if ((dio->rw == READ) && ((offset + transferred) > i_size))
+				transferred = i_size - offset;
+
+			dio_complete(dio, offset, transferred);
+
 			/* Complete AIO later if falling back to buffered i/o */
 			if (dio->result == dio->size ||
 				((dio->rw == READ) && dio->result)) {
-				aio_complete(dio->iocb, dio->result, 0);
+				aio_complete(dio->iocb, transferred, 0);
 				kfree(dio);
 				return;
 			} else {

^ permalink raw reply	[flat|nested] 24+ messages in thread
* Re: [PATCH] 2.6.10 -  direct-io async short read bug
@ 2005-03-08  9:46 Sébastien Dugué
  0 siblings, 0 replies; 24+ messages in thread
From: Sébastien Dugué @ 2005-03-08  9:46 UTC (permalink / raw)
  Cc: linux-aio kvack.org, linux-kernel, pbadari, suparna

Le mardi 08 mars 2005 à 01:18 -0800, Andrew Morton a écrit :
> Suparna Bhattacharya <suparna@in.ibm.com> wrote:
> >
> > ...
> > 
> > Bugs in this area seem never-ending don't they - plug one, open up
> > another - hard to be confident/verify :( - someday we'll have to
> > rewrite a part of this code.
> 
> It's solving a complex problem.  Any rewrite would probably end up
just as
> hairy once all the new bugs and corner cases are fixed.  Maybe.
> 
> 
> > Hmm, shouldn't dio->result ideally have been adjusted to be within
> > i_size at the time of io submission, so we don't have to deal with
> > this during completion ? We are creating bios with the right size
> > after all. 
> > 
> > We have this: 
> >             if (!buffer_mapped(map_bh)) {
> >                             ....
> >                             if (dio->block_in_file >=
> >
i_size_read(dio->inode)>>blkbits) {
> >                                         /* We hit eof */
> >                                         page_cache_release(page);
> >                                         goto out;
> >                                 }
> > 
> > and
> >             dio->result += iov[seg].iov_len -
> >                         ((dio->final_block_in_request -
dio->block_in_file) <<
> >                                         blkbits);
> > 
> > 
> > can you spot what is going wrong here that we have to try and
> > workaround this later ?
> 
> Good question.  Do we have the i_sem coverage to prevent a concurrent
> truncate?
> 
> But from Sebastien's description it doesn't soound as if a concurrent
> truncate is involved.

Yes, you're right, there's no concurrent truncate here. My test case
as well as Daniel's is single threaded and is the only thread accessing
the file.

Regards,

Sébastien.

-- 
------------------------------------------------------

  Sébastien Dugué                BULL/FREC:B1-247
  phone: (+33) 476 29 77 70      Bullcom: 229-7770

  mailto:sebastien.dugue@bull.net

  Linux POSIX AIO: http://www.bullopensource.org/posix
  
------------------------------------------------------


^ permalink raw reply	[flat|nested] 24+ messages in thread
* Re: [PATCH] 2.6.10 -  direct-io async short read bug
@ 2005-03-08 10:16 Sébastien Dugué
  0 siblings, 0 replies; 24+ messages in thread
From: Sébastien Dugué @ 2005-03-08 10:16 UTC (permalink / raw)
  To: linux-aio kvack.org, linux-kernel@vger.kernel.org,
	suparna@in.ibm.com, pbadari@us.ibm.com

Le mardi 08 mars 2005 à 01:18 -0800, Andrew Morton a écrit :
> Suparna Bhattacharya <suparna@in.ibm.com> wrote:
> >
> > ...
> > 
> > Bugs in this area seem never-ending don't they - plug one, open up
> > another - hard to be confident/verify :( - someday we'll have to
> > rewrite a part of this code.
> 
> It's solving a complex problem.  Any rewrite would probably end up
just as
> hairy once all the new bugs and corner cases are fixed.  Maybe.
> 
> 
> > Hmm, shouldn't dio->result ideally have been adjusted to be within
> > i_size at the time of io submission, so we don't have to deal with
> > this during completion ? We are creating bios with the right size
> > after all. 
> > 
> > We have this: 
> >             if (!buffer_mapped(map_bh)) {
> >                             ....
> >                             if (dio->block_in_file >=
> >
i_size_read(dio->inode)>>blkbits) {
> >                                         /* We hit eof */
> >                                         page_cache_release(page);
> >                                         goto out;
> >                                 }
> > 
> > and
> >             dio->result += iov[seg].iov_len -
> >                         ((dio->final_block_in_request -
dio->block_in_file) <<
> >                                         blkbits);
> > 
> > 
> > can you spot what is going wrong here that we have to try and
> > workaround this later ?
> 
> Good question.  Do we have the i_sem coverage to prevent a concurrent
> truncate?
> 
> But from Sebastien's description it doesn't soound as if a concurrent
> truncate is involved.

Yes, you're right, there's no concurrent truncate here. My test case
as well as Daniel's is single threaded and is the only thread accessing
the file.

Regards,

Sébastien.

-- 
------------------------------------------------------

  Sébastien Dugué                BULL/FREC:B1-247
  phone: (+33) 476 29 77 70      Bullcom: 229-7770

  mailto:sebastien.dugue@bull.net

  Linux POSIX AIO: http://www.bullopensource.org/posix
  
------------------------------------------------------


^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2005-03-10  4:29 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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é

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.