From: David Woodhouse Subject: Re: [RFC] FADV_REMOVE Date: Sat, 16 Aug 2008 16:35:14 +0100 Message-ID: <1218900914.3184.242.camel@pmac.infradead.org> References: <1218900827.3184.240.camel@pmac.infradead.org> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit Cc: viro@zeniv.linux.org.uk To: linux-fsdevel Return-path: Received: from bombadil.infradead.org ([18.85.46.34]:50156 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752006AbYHPPfP (ORCPT ); Sat, 16 Aug 2008 11:35:15 -0400 In-Reply-To: <1218900827.3184.240.camel@pmac.infradead.org> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: 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... diff --git a/include/linux/fadvise.h b/include/linux/fadvise.h index e8e7471..344ab0e 100644 --- a/include/linux/fadvise.h +++ b/include/linux/fadvise.h @@ -18,4 +18,6 @@ #define POSIX_FADV_NOREUSE 5 /* Data will be accessed once. */ #endif +#define LINUX_FADV_REMOVE 16 /* Discard data permanently */ + #endif /* FADVISE_H_INCLUDED */ diff --git a/mm/fadvise.c b/mm/fadvise.c index 343cfdf..c2e1baf 100644 --- a/mm/fadvise.c +++ b/mm/fadvise.c @@ -57,6 +57,7 @@ asmlinkage long sys_fadvise64_64(int fd, loff_t offset, loff_t len, int advice) case POSIX_FADV_WILLNEED: case POSIX_FADV_NOREUSE: case POSIX_FADV_DONTNEED: + case LINUX_FADV_REMOVE: /* no bad return value, but ignore advice */ break; default: @@ -119,6 +120,29 @@ asmlinkage long sys_fadvise64_64(int fd, loff_t offset, loff_t len, int advice) invalidate_mapping_pages(mapping, start_index, end_index); break; + 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); + break; default: ret = -EINVAL; } -- David Woodhouse Open Source Technology Centre David.Woodhouse@intel.com Intel Corporation