Return-Path: Received: from 22.17.110.36.static.bjtelecom.net ([36.110.17.22]:31498 "EHLO BJEXMBX011.didichuxing.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1753322AbdGSR4l (ORCPT ); Wed, 19 Jul 2017 13:56:41 -0400 Date: Thu, 20 Jul 2017 01:41:26 +0800 From: weiping zhang To: CC: Subject: [RFC] fs: disable create file with O_DIRECT for tmpfs Message-ID: <20170719174120.GA16327@bogon.didichuxing.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline Sender: linux-fsdevel-owner@vger.kernel.org List-ID: 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. Signed-off-by: weiping zhang --- fs/namei.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/namei.c b/fs/namei.c index ddb6a7c..a2a8cb9 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -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 (;;) { -- 2.9.4