vfs: add a FALLOC_FL_UNSHARE mode to fallocate to unshare a range of blocks
[linux-block.git] / fs / open.c
index 4fd6e256f4f454e0e8792d1a11c44e377dfbae04..d58525dda28dda7948b37b80b2e054fd53b843d1 100644 (file)
--- a/fs/open.c
+++ b/fs/open.c
@@ -256,6 +256,11 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
            (mode & ~FALLOC_FL_INSERT_RANGE))
                return -EINVAL;
 
+       /* Unshare range should only be used with allocate mode. */
+       if ((mode & FALLOC_FL_UNSHARE_RANGE) &&
+           (mode & ~(FALLOC_FL_UNSHARE_RANGE | FALLOC_FL_KEEP_SIZE)))
+               return -EINVAL;
+
        if (!(file->f_mode & FMODE_WRITE))
                return -EBADF;