2009-10-09 01:14:03

by Mingming Cao

[permalink] [raw]
Subject: [PATCH 1/4 v2] Direct IO return value fix for holes/fallocate

ext4: Direct IO return value fix for holes/fallocate

When direct IO complete, ext4 will convert unwritten extents to written,
for
writes over preallocated space, or holes.

ext4_direct_IO should returns the number of bytes read/write on success.
However there is a bug that cause ext4_direct_IO returns the number of
bytes converted to written extents, which is 0 on success. This bug
causes
direct IO falls back to buffered IO even on sucessful rewrites or
preallocated space.

Signed-off-by: Mingming Cao <[email protected]>
---
fs/ext4/extents.c | 1 +
fs/ext4/inode.c | 8 ++++++--
2 files changed, 7 insertions(+), 2 deletions(-)

Index: linux-2.6.31-rc4/fs/ext4/extents.c
===================================================================
--- linux-2.6.31-rc4.orig/fs/ext4/extents.c
+++ linux-2.6.31-rc4/fs/ext4/extents.c
@@ -3500,6 +3500,7 @@ retry:
*
* This function is called from the direct IO end io call back
* function, to convert the fallocated extents after IO is completed.
+ * Returns 0 on success.
*/
int ext4_convert_unwritten_extents(struct inode *inode, loff_t offset,
loff_t len)
Index: linux-2.6.31-rc4/fs/ext4/inode.c
===================================================================
--- linux-2.6.31-rc4.orig/fs/ext4/inode.c
+++ linux-2.6.31-rc4/fs/ext4/inode.c
@@ -3693,13 +3693,17 @@ static ssize_t ext4_ext_direct_IO(int rw
if (ret != -EIOCBQUEUED && ret <= 0 && iocb->private) {
ext4_free_io_end(iocb->private);
iocb->private = NULL;
- } else if (ret > 0)
+ } else if (ret > 0){
+ int err;
/*
* for non AIO case, since the IO is already
* completed, we could do the convertion right here
*/
- ret = ext4_convert_unwritten_extents(inode,
+ err = ext4_convert_unwritten_extents(inode,
offset, ret);
+ if (err < 0)
+ ret = err;
+ }
return ret;
}





2009-11-04 02:09:16

by Theodore Ts'o

[permalink] [raw]
Subject: Re: [PATCH 1/4 v2] Direct IO return value fix for holes/fallocate

On Thu, Oct 08, 2009 at 06:13:16PM -0700, Mingming wrote:
> ext4: Direct IO return value fix for holes/fallocate
>
> When direct IO complete, ext4 will convert unwritten extents to written,
> for
> writes over preallocated space, or holes.
>
> ext4_direct_IO should returns the number of bytes read/write on success.
> However there is a bug that cause ext4_direct_IO returns the number of
> bytes converted to written extents, which is 0 on success. This bug
> causes
> direct IO falls back to buffered IO even on sucessful rewrites or
> preallocated space.
>
> Signed-off-by: Mingming Cao <[email protected]>

I fixed up some white space issues, and rewrote the patch descriptions
as follows:

ext4: fix ext4_ext_direct_IO()'s return value after converting uninit extents

After a direct I/O request covering an uninitalized extent (i.e.,
created using the fallocate system call) or a hole in a file, ext4
will convert the uninitialized extent so it is marked as initialized
by calling ext4_convert_unwritten_extents(). This function returns
zero on success.

This return value was getting returned by ext4_direct_IO(); however
the file system's direct_IO function is supposed to return the number
of bytes read or written on a success. By returning zero, it confused
the direct I/O code into falling back to buffered I/O unnecessarily.

Signed-off-by: Mingming Cao <[email protected]>
Signed-off-by: "Theodore Ts'o" <[email protected]>

Added to the patch queue.

- Ted