From patchwork Wed Jul 19 17:41:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: weiping zhang X-Patchwork-Id: 9852905 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B56CF602C8 for ; Wed, 19 Jul 2017 17:56:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA66F286CB for ; Wed, 19 Jul 2017 17:56:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AF13B286CF; Wed, 19 Jul 2017 17:56:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B809D286CB for ; Wed, 19 Jul 2017 17:56:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753509AbdGSR4l (ORCPT ); Wed, 19 Jul 2017 13:56:41 -0400 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 X-Greylist: delayed 903 seconds by postgrey-1.27 at vger.kernel.org; Wed, 19 Jul 2017 13:56:40 EDT Received: from bogon.didichuxing.com (172.22.50.20) by BJSGEXMBX04.didichuxing.com (172.20.15.134) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Thu, 20 Jul 2017 01:41:34 +0800 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-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Originating-IP: [172.22.50.20] X-ClientProxiedBy: BJEXCAS004.didichuxing.com (172.20.1.44) To BJSGEXMBX04.didichuxing.com (172.20.15.134) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 (;;) {