* [PATCH RFC v3] fs: Avoid create file when open() with O_DIRECT if fs not support
@ 2017-08-28 13:07 weiping zhang
2017-09-01 1:36 ` weiping zhang
0 siblings, 1 reply; 2+ messages in thread
From: weiping zhang @ 2017-08-28 13:07 UTC (permalink / raw)
To: viro; +Cc: linux-fsdevel
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@didichuxing.com>
---
fs/internal.h | 1 +
fs/namei.c | 9 +++++++++
fs/open.c | 11 +++++++++++
3 files changed, 21 insertions(+)
diff --git a/fs/internal.h b/fs/internal.h
index 9676fe1..6393d05 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -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 *);
diff --git a/fs/namei.c b/fs/namei.c
index ddb6a7c..f5a6f81 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -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) {
diff --git a/fs/open.c b/fs/open.c
index 35bb784..4969502 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -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 *),
--
2.9.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH RFC v3] fs: Avoid create file when open() with O_DIRECT if fs not support
2017-08-28 13:07 [PATCH RFC v3] fs: Avoid create file when open() with O_DIRECT if fs not support weiping zhang
@ 2017-09-01 1:36 ` weiping zhang
0 siblings, 0 replies; 2+ messages in thread
From: weiping zhang @ 2017-09-01 1:36 UTC (permalink / raw)
To: viro; +Cc: linux-fsdevel
On Mon, Aug 28, 2017 at 09:07:27PM +0800, weiping zhang wrote:
> 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.
>
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-09-01 1:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-28 13:07 [PATCH RFC v3] fs: Avoid create file when open() with O_DIRECT if fs not support weiping zhang
2017-09-01 1:36 ` weiping zhang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.