Skip to content

Commit 6b1bdb5

Browse files
rwmjonesMiklos Szeredi
authored andcommitted
fuse: allow fallocate(FALLOC_FL_ZERO_RANGE)
The current fuse module filters out fallocate(FALLOC_FL_ZERO_RANGE) returning -EOPNOTSUPP. libnbd's nbdfuse would like to translate FALLOC_FL_ZERO_RANGE requests into the NBD command NBD_CMD_WRITE_ZEROES which allows NBD servers that support it to do zeroing efficiently. This commit treats this flag exactly like FALLOC_FL_PUNCH_HOLE. A way to test this, requiring fuse >= 3, nbdkit >= 1.8 and the latest nbdfuse from https://gitlab.com/nbdkit/libnbd/-/tree/master/fuse is to create a file containing some data and "mirror" it to a fuse file: $ dd if=/dev/urandom of=disk.img bs=1M count=1 $ nbdkit file disk.img $ touch mirror.img $ nbdfuse mirror.img nbd://localhost & (mirror.img -> nbdfuse -> NBD over loopback -> nbdkit -> disk.img) You can then run commands such as: $ fallocate -z -o 1024 -l 1024 mirror.img and check that the content of the original file ("disk.img") stays synchronized. To show NBD commands, export LIBNBD_DEBUG=1 before running nbdfuse. To clean up: $ fusermount3 -u mirror.img $ killall nbdkit Signed-off-by: Richard W.M. Jones <rjones@redhat.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent 1b53991 commit 6b1bdb5

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

fs/fuse/file.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2907,11 +2907,13 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
29072907
};
29082908
int err;
29092909
bool lock_inode = !(mode & FALLOC_FL_KEEP_SIZE) ||
2910-
(mode & FALLOC_FL_PUNCH_HOLE);
2910+
(mode & (FALLOC_FL_PUNCH_HOLE |
2911+
FALLOC_FL_ZERO_RANGE));
29112912

29122913
bool block_faults = FUSE_IS_DAX(inode) && lock_inode;
29132914

2914-
if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
2915+
if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE |
2916+
FALLOC_FL_ZERO_RANGE))
29152917
return -EOPNOTSUPP;
29162918

29172919
if (fm->fc->no_fallocate)
@@ -2926,7 +2928,7 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
29262928
goto out;
29272929
}
29282930

2929-
if (mode & FALLOC_FL_PUNCH_HOLE) {
2931+
if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_ZERO_RANGE)) {
29302932
loff_t endbyte = offset + length - 1;
29312933

29322934
err = fuse_writeback_range(inode, offset, endbyte);
@@ -2966,7 +2968,7 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
29662968
file_update_time(file);
29672969
}
29682970

2969-
if (mode & FALLOC_FL_PUNCH_HOLE)
2971+
if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_ZERO_RANGE))
29702972
truncate_pagecache_range(inode, offset, offset + length - 1);
29712973

29722974
fuse_invalidate_attr(inode);

0 commit comments

Comments
 (0)