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. Signed-off-by: weiping zhang <zhangweiping@xxxxxxxxxxxxxxx> --- fs/namei.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/namei.c b/fs/namei.c index ddb6a7c..45c892b 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3201,6 +3201,17 @@ 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) && + !(dentry->d_inode->i_mapping && + dentry->d_inode->i_mapping->a_ops && + dentry->d_inode->i_mapping->a_ops->direct_IO) && + 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) { -- 2.9.4