Skip to contentSkip to conversation

fs: disable create file with O_DIRECT for tmpfs

RFC In review weiping zhang 2 participants 3 messages Jul 19, 2017 – Jul 22, 2017 VFS

lore
Share & tools
lore
#0 lore raw

RFC 1/1 fs: disable create file with O_DIRECT for tmpfs

tmpfs not support O_DIRECT, when user open with O_DIRECT , the 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 tmpfs that can avoid creating that file.

---
 fs/namei.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/namei.c +4 -0
index ddb6a7c..a2a8cb9 100644
@@ -3106,6 +3106,10 @@ static int lookup_open(struct nameidata *nd, struct path *path,
 	if (unlikely(IS_DEADDIR(dir_inode)))
 		return -ENOENT;
 
+	if (unlikely(open_flag & (O_CREAT | O_DIRECT) &&
+		strcmp(dir->d_sb->s_type->name, "tmpfs") == 0))
+		return -EINVAL;
+
 	*opened &= ~FILE_CREATED;
 	dentry = d_lookup(dir, &nd->last);
 	for (;;) {
Signature · 1 line
2.9.4
maintainer
#1 lore raw
Quoted 15 lines · weiping zhang

tmpfs not support O_DIRECT, when user open with O_DIRECT , the 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 tmpfs that can avoid creating that file.

---
 fs/namei.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/namei.c +0 -0
index ddb6a7c..a2a8cb9 100644

fs/namei.c static int lookup_open(struct nameidata *nd, struct path *path, · line 3111

Quoted 6 lines
fs/namei.c +3 -0
@@ -3106,6 +3106,10 @@ static int lookup_open(struct nameidata *nd, struct path *path,
 	if (unlikely(IS_DEADDIR(dir_inode)))
 		return -ENOENT;
 
+	if (unlikely(open_flag & (O_CREAT | O_DIRECT) &&
+		strcmp(dir->d_sb->s_type->name, "tmpfs") == 0))
+		return -EINVAL;

Hell, _no_. Kludges of that sort are flat-out wrong - string comparisons on the fs type name, no less... For one thing, tmpfs is not the only such filesystem. Should we turn that into a long list of "forbidden" types, patching it every time somebody comes up with a filesystem that fails O_DIRECT open? Not to mention the modules, or filesystems where that depends upon e.g. mount flags...

#2 lore raw
Quoted 19 lines · Al Viro
Quoted 18 lines · weiping zhang

tmpfs not support O_DIRECT, when user open with O_DIRECT , the 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 tmpfs that can avoid creating that file.

---
 fs/namei.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/namei.c +0 -0
index ddb6a7c..a2a8cb9 100644
@@ -3106,6 +3106,10 @@ static int lookup_open(struct nameidata *nd, struct path *path,
 	if (unlikely(IS_DEADDIR(dir_inode)))
 		return -ENOENT;
 
Quoted 9 lines

fs/namei.c static int lookup_open(struct nameidata *nd, struct path *path, · line 3111

Quoted 3 lines
fs/namei.c +3 -0
+	if (unlikely(open_flag & (O_CREAT | O_DIRECT) &&
+		strcmp(dir->d_sb->s_type->name, "tmpfs") == 0))
+		return -EINVAL;

Hell, _no_. Kludges of that sort are flat-out wrong - string comparisons on the fs type name, no less... For one thing, tmpfs is not the only such filesystem. Should we turn that into a long list of "forbidden" types, patching it every time somebody comes up with a filesystem that fails O_DIRECT open? Not to mention the modules, or filesystems where that depends upon e.g. mount flags...

Hi Viro,

Thanks your comments, sorry to late reply, as you say, tmpfs is not the only such filesystem, we cann't add long list to prevent create file.
I try to find a mount flag to get a fs whether support direct_io
directly or indirectly, but I have no result. Do you mean add a new
mount flag to indicate a fs support direct_io or not? and then check that flag at may_o_create. Looking forward to hearing from you.