Skip to contentSkip to conversation

don't allow sys_readahead() on files opened with O_DIRECT

PATCH Superseded Jan Blunck 2 participants 3 messages Jun 6, 2005

Subsystems (2)
lore
Share & tools
lore

Jan Blunck

author
#0 lore raw

PATCH 1/1 don't allow sys_readahead() on files opened with O_DIRECT

do_readahead() doesn't make sense if the file is opened with O_DIRECT, since only the page cache is stuffed but never used.

 mm/filemap.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletion(-)
mm/filemap.c +2 -1
Index: experimental-um/mm/filemap.c
===================================================================
@@ -1110,7 +1110,8 @@ static ssize_t
 do_readahead(struct address_space *mapping, struct file *filp,
 	     unsigned long index, unsigned long nr)
 {
-	if (!mapping || !mapping->a_ops || !mapping->a_ops->readpage)
+	if (!mapping || !mapping->a_ops || !mapping->a_ops->readpage
+	    || mapping->a_ops->direct_IO)
 		return -EINVAL;
 
 	force_page_cache_readahead(mapping, filp, index,
#1 lore raw

your check is wrong, it's testing whether the filesystem supports O_DIRECT, not whether sys_readahead is used on a file descriptor that has been opened with O_DIRECT

author
#2 lore raw
Quoted 2 lines · Christoph Hellwig

your check is wrong, it's testing whether the filesystem supports O_DIRECT, not whether sys_readahead is used on a file descriptor that has been opened with O_DIRECT

D'oh! You're right.

Jan

do_readahead() doesn't make sense if the file is opened with O_DIRECT, since only the page cache is stuffed but never used.

 mm/filemap.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletion(-)
mm/filemap.c +2 -1
Index: experimental-um/mm/filemap.c
===================================================================
@@ -1110,7 +1110,8 @@ static ssize_t
 do_readahead(struct address_space *mapping, struct file *filp,
 	     unsigned long index, unsigned long nr)
 {
-	if (!mapping || !mapping->a_ops || !mapping->a_ops->readpage)
+	if (!mapping || !mapping->a_ops || !mapping->a_ops->readpage
+	    || (filp->f_flags & O_DIRECT))
 		return -EINVAL;
 
 	force_page_cache_readahead(mapping, filp, index,