summaryrefslogtreecommitdiff
path: root/fs/open.c
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@kernel.org>2022-07-14 11:16:23 -0700
committerDarrick J. Wong <djwong@kernel.org>2022-10-14 14:17:29 -0700
commit329347290ff24672bc398056af8a2351c2a8d6e7 (patch)
tree0f133fdbe7f4694d6da3bc9ca8801b22a37a56bd /fs/open.c
parentc44d956ad25bba8e0c1a86d40e66fafce1a09563 (diff)
xfs: fallocate free space into a filedefrag-freespace_2022-10-14
Add a new fallocate mode to map free physical space into a file, at the same file offset as if the file were a sparse image of the physical device backing the filesystem. The intent here is to use this to prototype a free space defragmentation tool. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Diffstat (limited to 'fs/open.c')
-rw-r--r--fs/open.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/fs/open.c b/fs/open.c
index cf7e5c350a54..13c786664e80 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -277,6 +277,11 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
(mode & ~(FALLOC_FL_UNSHARE_RANGE | FALLOC_FL_KEEP_SIZE)))
return -EINVAL;
+ /* Mapping free space should only be used by itself. */
+ if ((mode & FALLOC_FL_MAP_FREE_SPACE) &&
+ (mode & ~FALLOC_FL_MAP_FREE_SPACE))
+ return -EINVAL;
+
if (!(file->f_mode & FMODE_WRITE))
return -EBADF;