Skip to content

Commit cab64df

Browse files
Christoph HellwigAl Viro
authored andcommitted
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: Christoph Hellwig <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 793057e commit cab64df

File tree

3 files changed

+19
-33
lines changed

3 files changed

+19
-33
lines changed

fs/internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ extern struct file *do_filp_open(int dfd, struct filename *pathname,
111111
extern struct file *do_file_open_root(struct dentry *, struct vfsmount *,
112112
const char *, const struct open_flags *);
113113

114-
extern int open_check_o_direct(struct file *f);
115114
extern int vfs_open(const struct path *, struct file *, const struct cred *);
116115
extern struct file *filp_clone_open(struct file *);
117116

fs/namei.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3382,9 +3382,7 @@ static int do_last(struct nameidata *nd,
33823382
goto out;
33833383
*opened |= FILE_OPENED;
33843384
opened:
3385-
error = open_check_o_direct(file);
3386-
if (!error)
3387-
error = ima_file_check(file, op->acc_mode, *opened);
3385+
error = ima_file_check(file, op->acc_mode, *opened);
33883386
if (!error && will_truncate)
33893387
error = handle_truncate(file);
33903388
out:
@@ -3464,9 +3462,6 @@ static int do_tmpfile(struct nameidata *nd, unsigned flags,
34643462
error = finish_open(file, child, NULL, opened);
34653463
if (error)
34663464
goto out2;
3467-
error = open_check_o_direct(file);
3468-
if (error)
3469-
fput(file);
34703465
out2:
34713466
mnt_drop_write(path.mnt);
34723467
out:

fs/open.c

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -682,16 +682,6 @@ SYSCALL_DEFINE3(fchown, unsigned int, fd, uid_t, user, gid_t, group)
682682
return error;
683683
}
684684

685-
int open_check_o_direct(struct file *f)
686-
{
687-
/* NB: we're sure to have correct a_ops only after f_op->open */
688-
if (f->f_flags & O_DIRECT) {
689-
if (!f->f_mapping->a_ops || !f->f_mapping->a_ops->direct_IO)
690-
return -EINVAL;
691-
}
692-
return 0;
693-
}
694-
695685
static int do_dentry_open(struct file *f,
696686
struct inode *inode,
697687
int (*open)(struct inode *, struct file *),
@@ -713,7 +703,7 @@ static int do_dentry_open(struct file *f,
713703
if (unlikely(f->f_flags & O_PATH)) {
714704
f->f_mode = FMODE_PATH;
715705
f->f_op = &empty_fops;
716-
return 0;
706+
goto done;
717707
}
718708

719709
if (f->f_mode & FMODE_WRITE && !special_file(inode->i_mode)) {
@@ -766,7 +756,12 @@ static int do_dentry_open(struct file *f,
766756
f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC);
767757

768758
file_ra_state_init(&f->f_ra, f->f_mapping->host->i_mapping);
769-
759+
done:
760+
/* NB: we're sure to have correct a_ops only after f_op->open */
761+
error = -EINVAL;
762+
if ((f->f_flags & O_DIRECT) &&
763+
(!f->f_mapping->a_ops || !f->f_mapping->a_ops->direct_IO))
764+
goto out_fput;
770765
return 0;
771766

772767
cleanup_all:
@@ -781,6 +776,9 @@ static int do_dentry_open(struct file *f,
781776
f->f_path.dentry = NULL;
782777
f->f_inode = NULL;
783778
return error;
779+
out_fput:
780+
fput(f);
781+
return error;
784782
}
785783

786784
/**
@@ -878,20 +876,14 @@ struct file *dentry_open(const struct path *path, int flags,
878876
BUG_ON(!path->mnt);
879877

880878
f = get_empty_filp();
881-
if (!IS_ERR(f)) {
882-
f->f_flags = flags;
883-
error = vfs_open(path, f, cred);
884-
if (!error) {
885-
/* from now on we need fput() to dispose of f */
886-
error = open_check_o_direct(f);
887-
if (error) {
888-
fput(f);
889-
f = ERR_PTR(error);
890-
}
891-
} else {
892-
put_filp(f);
893-
f = ERR_PTR(error);
894-
}
879+
if (IS_ERR(f))
880+
return f;
881+
882+
f->f_flags = flags;
883+
error = vfs_open(path, f, cred);
884+
if (error) {
885+
put_filp(f);
886+
return ERR_PTR(error);
895887
}
896888
return f;
897889
}

0 commit comments

Comments
 (0)