Commit cab64df1 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Al Viro

fs: fold open_check_o_direct into do_dentry_open

do_dentry_open is where we do the actual open of the file, so this is
where we should do our O_DIRECT sanity check to cover all potential
callers.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 793057e1
...@@ -111,7 +111,6 @@ extern struct file *do_filp_open(int dfd, struct filename *pathname, ...@@ -111,7 +111,6 @@ extern struct file *do_filp_open(int dfd, struct filename *pathname,
extern struct file *do_file_open_root(struct dentry *, struct vfsmount *, extern struct file *do_file_open_root(struct dentry *, struct vfsmount *,
const char *, const struct open_flags *); const char *, const struct open_flags *);
extern int open_check_o_direct(struct file *f);
extern int vfs_open(const struct path *, struct file *, const struct cred *); extern int vfs_open(const struct path *, struct file *, const struct cred *);
extern struct file *filp_clone_open(struct file *); extern struct file *filp_clone_open(struct file *);
......
...@@ -3382,9 +3382,7 @@ static int do_last(struct nameidata *nd, ...@@ -3382,9 +3382,7 @@ static int do_last(struct nameidata *nd,
goto out; goto out;
*opened |= FILE_OPENED; *opened |= FILE_OPENED;
opened: opened:
error = open_check_o_direct(file); error = ima_file_check(file, op->acc_mode, *opened);
if (!error)
error = ima_file_check(file, op->acc_mode, *opened);
if (!error && will_truncate) if (!error && will_truncate)
error = handle_truncate(file); error = handle_truncate(file);
out: out:
...@@ -3464,9 +3462,6 @@ static int do_tmpfile(struct nameidata *nd, unsigned flags, ...@@ -3464,9 +3462,6 @@ static int do_tmpfile(struct nameidata *nd, unsigned flags,
error = finish_open(file, child, NULL, opened); error = finish_open(file, child, NULL, opened);
if (error) if (error)
goto out2; goto out2;
error = open_check_o_direct(file);
if (error)
fput(file);
out2: out2:
mnt_drop_write(path.mnt); mnt_drop_write(path.mnt);
out: out:
......
...@@ -682,16 +682,6 @@ SYSCALL_DEFINE3(fchown, unsigned int, fd, uid_t, user, gid_t, group) ...@@ -682,16 +682,6 @@ SYSCALL_DEFINE3(fchown, unsigned int, fd, uid_t, user, gid_t, group)
return error; return error;
} }
int open_check_o_direct(struct file *f)
{
/* NB: we're sure to have correct a_ops only after f_op->open */
if (f->f_flags & O_DIRECT) {
if (!f->f_mapping->a_ops || !f->f_mapping->a_ops->direct_IO)
return -EINVAL;
}
return 0;
}
static int do_dentry_open(struct file *f, static int do_dentry_open(struct file *f,
struct inode *inode, struct inode *inode,
int (*open)(struct inode *, struct file *), int (*open)(struct inode *, struct file *),
...@@ -713,7 +703,7 @@ static int do_dentry_open(struct file *f, ...@@ -713,7 +703,7 @@ static int do_dentry_open(struct file *f,
if (unlikely(f->f_flags & O_PATH)) { if (unlikely(f->f_flags & O_PATH)) {
f->f_mode = FMODE_PATH; f->f_mode = FMODE_PATH;
f->f_op = &empty_fops; f->f_op = &empty_fops;
return 0; goto done;
} }
if (f->f_mode & FMODE_WRITE && !special_file(inode->i_mode)) { if (f->f_mode & FMODE_WRITE && !special_file(inode->i_mode)) {
...@@ -766,7 +756,12 @@ static int do_dentry_open(struct file *f, ...@@ -766,7 +756,12 @@ static int do_dentry_open(struct file *f,
f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC); f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC);
file_ra_state_init(&f->f_ra, f->f_mapping->host->i_mapping); file_ra_state_init(&f->f_ra, f->f_mapping->host->i_mapping);
done:
/* NB: we're sure to have correct a_ops only after f_op->open */
error = -EINVAL;
if ((f->f_flags & O_DIRECT) &&
(!f->f_mapping->a_ops || !f->f_mapping->a_ops->direct_IO))
goto out_fput;
return 0; return 0;
cleanup_all: cleanup_all:
...@@ -781,6 +776,9 @@ static int do_dentry_open(struct file *f, ...@@ -781,6 +776,9 @@ static int do_dentry_open(struct file *f,
f->f_path.dentry = NULL; f->f_path.dentry = NULL;
f->f_inode = NULL; f->f_inode = NULL;
return error; return error;
out_fput:
fput(f);
return error;
} }
/** /**
...@@ -878,20 +876,14 @@ struct file *dentry_open(const struct path *path, int flags, ...@@ -878,20 +876,14 @@ struct file *dentry_open(const struct path *path, int flags,
BUG_ON(!path->mnt); BUG_ON(!path->mnt);
f = get_empty_filp(); f = get_empty_filp();
if (!IS_ERR(f)) { if (IS_ERR(f))
f->f_flags = flags; return f;
error = vfs_open(path, f, cred);
if (!error) { f->f_flags = flags;
/* from now on we need fput() to dispose of f */ error = vfs_open(path, f, cred);
error = open_check_o_direct(f); if (error) {
if (error) { put_filp(f);
fput(f); return ERR_PTR(error);
f = ERR_PTR(error);
}
} else {
put_filp(f);
f = ERR_PTR(error);
}
} }
return f; return f;
} }
......
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