vfs_fallocate() returns -ENODEV for anything that is not a regular file or a block device, before it looks at f_op->fallocate. Let a character device through when its driver implements ->fallocate(). All other character devices keep returning -ENODEV, and since no character device in the tree implements ->fallocate() today, nothing changes for existing drivers. The first user is device-dax, in a later patch, where punching a hole releases device memory. An ioctl could do that too, but madvise(MADV_REMOVE) is implemented by calling vfs_fallocate() with FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE on the mapped file. Going through ->fallocate() lets an allocator release part of a device-dax mapping with the madvise() call it already uses for shmem. The permission and sanity checks in vfs_fallocate() are unchanged and still run before the driver is called. Signed-off-by: Sourav Panda --- fs/open.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/open.c b/fs/open.c index bb484b07390ac..0f31caf9e7597 100644 --- a/fs/open.c +++ b/fs/open.c @@ -321,7 +321,13 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len) if (S_ISDIR(inode->i_mode)) return -EISDIR; - if (!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode)) + /* + * Character devices that implement ->fallocate() (device-dax uses it + * for discard, see drivers/dax/device.c) are allowed through; all other + * character devices keep -ENODEV. + */ + if (!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode) && + !(S_ISCHR(inode->i_mode) && file->f_op->fallocate)) return -ENODEV; /* Check for wraparound */ -- 2.56.1.839.g22a8290db9-goog