Re: [patch] call truncate_inode_pages in the DIO fallback to buffered I/O path

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



==> Regarding Re: [patch] call truncate_inode_pages in the DIO fallback to buffered I/O path; Andrew Morton <[email protected]> adds:

akpm> So I'd propose:

> diff -puN mm/filemap.c~direct-io-sync-and-invalidate-file-region-when-falling-back-to-buffered-write-fix mm/filemap.c
> --- a/mm/filemap.c~direct-io-sync-and-invalidate-file-region-when-falling-back-to-buffered-write-fix
> +++ a/mm/filemap.c
> @@ -2291,19 +2291,30 @@ __generic_file_aio_write_nolock(struct k
>  		written_buffered = generic_file_buffered_write(iocb, iov,
>  						nr_segs, pos, ppos, count,
>  						written);
> +		/*
> +		 * If generic_file_buffered_write() retuned a synchronous error
> +		 * then we want to return the number of bytes which were
> +		 * direct-written, or the error code if that was zero.  Note
> +		 * that this differs from normal direct-io semantics, which
> +		 * will return -EFOO even if some bytes were written.
> +		 */
> +		if (written_buffered < 0) {
> +			err = written_buffered;
> +			goto out;
> +		}

>  		/*
>  		 * We need to ensure that the page cache pages are written to
>  		 * disk and invalidated to preserve the expected O_DIRECT
>  		 * semantics.
>  		 */
> -		endbyte = pos + written_buffered - 1;
> +		endbyte = pos + written_buffered - written - 1;
>  		err = do_sync_file_range(file, pos, endbyte,
>  					 SYNC_FILE_RANGE_WAIT_BEFORE|
>  					 SYNC_FILE_RANGE_WRITE|
>  					 SYNC_FILE_RANGE_WAIT_AFTER);
>  		if (err == 0) {
> -			written += written_buffered;
> +			written = written_buffered;
>  			invalidate_mapping_pages(mapping,
>  						 pos >> PAGE_CACHE_SHIFT,
>  						 endbyte >> PAGE_CACHE_SHIFT);
> _

This passes my tests and the Oracle tests that triggered the problem in the
first place.  Thanks!

Acked-by: Jeff Moyer <[email protected]>
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux