Return-Path: Received: from 22.17.110.36.static.bjtelecom.net ([36.110.17.22]:19372 "EHLO BJEXCAS008.didichuxing.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752596AbdG1T7D (ORCPT ); Fri, 28 Jul 2017 15:59:03 -0400 Date: Sat, 29 Jul 2017 03:58:51 +0800 From: weiping zhang To: Matthew Wilcox CC: , Subject: Re: [RFC v2] fs: Don't create file when open() with O_DIRECT if fs not support Message-ID: <20170728195847.GA19565@bogon.didichuxing.com> References: <20170728182950.GA15165@bogon.didichuxing.com> <20170728191352.GF15980@bombadil.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20170728191352.GF15980@bombadil.infradead.org> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Fri, Jul 28, 2017 at 12:13:52PM -0700, Matthew Wilcox wrote: > On Sat, Jul 29, 2017 at 02:29:58AM +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. > > > 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; > > Surely it's better to change the prototype of ->create to take open_flag > (like atomic_open does) and then have the filesystem check for O_DIRECT? > This solution seems quite inelegant to me. thanks your better suggestion, the only concern for me is Viro said: >>Not to mention the modules, or filesystems where that depends upon e.g. mount flags... So I try to find a common way to do that, the positve: only modify 1 file, no affect any specific filysystems, the negtive: this patch seems ugly. if we add/change prototype of ->create every fs will be patched. And if you are in favor of me changing prototype of ->create ,I will send a new patch.