Commit 6ef5d4bb authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] check for O_DIRECT capability in open(), not write()

For O_DIRECT opens we're currently checking that the fs supports
O_DIRECT at write(2)-time.

This is a forward-port of Andrea's patch which moves the check to
open() time.  Seems more sensible.
parent b5b6fa52
......@@ -245,6 +245,11 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
}
if (arg & O_DIRECT) {
if (inode->i_mapping && inode->i_mapping->a_ops) {
if (!inode->i_mapping->a_ops->direct_IO)
return -EINVAL;
}
/*
* alloc_kiovec() can sleep and we are only serialized by
* the big kernel lock here, so abuse the i_sem to serialize
......
......@@ -665,6 +665,14 @@ struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags)
}
f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC);
/* NB: we're sure to have correct a_ops only after f_op->open */
if (f->f_flags & O_DIRECT) {
error = -EINVAL;
if (inode->i_mapping && inode->i_mapping->a_ops)
if (!inode->i_mapping->a_ops->direct_IO)
goto cleanup_all;
}
return f;
cleanup_all:
......
......@@ -1121,8 +1121,6 @@ static ssize_t generic_file_direct_IO(int rw, struct file * filp, char * buf, si
retval = -EINVAL;
if ((offset & blocksize_mask) || (count & blocksize_mask))
goto out_free;
if (!mapping->a_ops->direct_IO)
goto out_free;
/*
* Flush to disk exclusively the _data_, metadata must remain
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment