fs: Avoid create file when open() with O_DIRECT if fs not support
RFC PATCH v3 1/1 fs: Avoid create file when open() with O_DIRECT if fs not support
Some filesystems not support O_DIRECT, when user open with O_DIRECT , an errno -EINVAL return to userspace by open_check_o_direct, but the file has been created, it's a strange thing. Add a checking for that can avoid creating file if fs not support O_DIRECT.
--- fs/internal.h | 1 + fs/namei.c | 9 +++++++++ fs/open.c | 11 +++++++++++ 3 files changed, 21 insertions(+)
fs/internal.h +1 -0
@@ -109,6 +109,7 @@ extern struct file *do_file_open_root(struct dentry *, struct vfsmount *, const char *, const struct open_flags *);extern int open_check_o_direct (struct file *f); +extern bool open_create_check_o_direct (struct dentry *dentry);extern int vfs_open (const struct path *,struct file *,const struct cred *);extern struct file *filp_clone_open (struct file *);
fs/namei.c +9 -0
@@ -3201,6 +3201,15 @@ static int lookup_open(struct nameidata *nd, struct path *path, open_flag & O_EXCL);if (error) goto out_dput; +/* if fs not support direct io, delete this inode */ +if (unlikely (open_flag &O_DIRECT ) && + !(open_create_check_o_direct (dentry)) && + dir_inode->i_op->unlink) { + error = dir_inode->i_op->unlink (dir_inode, dentry); +if (error ==0 ) + error = -EINVAL ; + goto out_dput; + }fsnotify_create (dir_inode, dentry); }if (unlikely (create_error) && !dentry->d_inode) {
fs/open.c +11 -0
@@ -692,6 +692,17 @@ int open_check_o_direct(struct file *f)return 0 ; } +bool open_create_check_o_direct (struct dentry *dentry) +{ +struct inode *inode = dentry->d_inode; + +if (inode->i_mapping && inode->i_mapping->a_ops && + inode->i_mapping->a_ops->direct_IO) +return true; + +return false; +} + static int do_dentry_open(struct file *f, struct inode *inode, int (*open)(struct inode *, struct file *),
Signature · 1 line
2.9.4
Quoted 5 lines · weiping zhang
Some filesystems not support
O_DIRECT, when user open withO_DIRECT, an errno-EINVALreturn to userspace byopen_check_o_direct, but the file has been created, it's a strange thing. Add a checking for that can avoid creating file if fs not supportO_DIRECT.
Hi AI,
would you please give some comments for this patch,
---
v2 -> v3:
introduce a new function for checking inode support direct io or not.
v1 -> v2:
a common way checking if fs support direct io, no matter what underlaying filesystem is.
Thanks