From: Christoph Hellwig Subject: Re: [RFC] FADV_REMOVE Date: Sat, 16 Aug 2008 11:53:44 -0400 Message-ID: <20080816155342.GA15943@infradead.org> References: <1218900827.3184.240.camel@pmac.infradead.org> <1218900914.3184.242.camel@pmac.infradead.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: linux-fsdevel , viro@zeniv.linux.org.uk To: David Woodhouse Return-path: Received: from bombadil.infradead.org ([18.85.46.34]:44942 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752204AbYHPPxr (ORCPT ); Sat, 16 Aug 2008 11:53:47 -0400 Content-Disposition: inline In-Reply-To: <1218900914.3184.242.camel@pmac.infradead.org> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Sat, Aug 16, 2008 at 04:35:14PM +0100, David Woodhouse wrote: > On Sat, 2008-08-16 at 16:33 +0100, David Woodhouse wrote: > > Any particular reason why I shouldn't do this? > > > ... and (something similar to) this... I really don't like hooking this into fadvice. facvice is to quote the manpage to "predeclare an access pattern for file data". Punching a whole and discaring data doesn't really fall into that category for me. > + case LINUX_FADV_REMOVE: > + if (!(file->f_mode & FMODE_WRITE)) { > + ret = -EBADF; > + goto out; > + } > + if ((offset & ~PAGE_MASK) || (len & ~PAGE_MASK)) { > + /* truncate_inode_pages_range() can't cope */ > + ret = -EINVAL; > + goto out; > + } > + if (endbyte == -1) { > + /* FIXME: truncate to end */ > + ret = -EINVAL; > + goto out; > + } > + > + if (!mapping->host || !mapping->host->i_op || > + !mapping->host->i_op->truncate_range) { > + ret = -EINVAL; > + goto out; > + } > + vmtruncate_range(mapping->host, offset, endbyte); Calling vmtruncate_range directrly is a bad idea, we already carefull don't do this in the truncate path (we do in the buffer write error handling for some tme and it _does_ cause problems). I'd rather have a higher level punch hole functionality, and that litle bit of functionaily in vmtruncate_range can be opencoded in the fs, especially as the locking will be different for most non-trivial ones. I know most of these problems already are there for MADV_REMOVE which unfortunately went in without me notices, and is a rather tmpfs-specific hack according to the commit message.