linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4] fuse: Allow fallocate(FALLOC_FL_ZERO_RANGE)
@ 2021-05-12 16:18 Richard W.M. Jones
  2021-05-12 16:18 ` Richard W.M. Jones
  0 siblings, 1 reply; 5+ messages in thread
From: Richard W.M. Jones @ 2021-05-12 16:18 UTC (permalink / raw)
  To: miklos; +Cc: linux-fsdevel, linux-kernel, eblake, libguestfs, synarete

v3 -> v4:

 - Cleans up the commit message.

 - As the patch itself is unchanged from v3, I did not retest it.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v4] fuse: Allow fallocate(FALLOC_FL_ZERO_RANGE)
  2021-05-12 16:18 [PATCH v4] fuse: Allow fallocate(FALLOC_FL_ZERO_RANGE) Richard W.M. Jones
@ 2021-05-12 16:18 ` Richard W.M. Jones
  2021-05-18 13:56   ` Miklos Szeredi
  0 siblings, 1 reply; 5+ messages in thread
From: Richard W.M. Jones @ 2021-05-12 16:18 UTC (permalink / raw)
  To: miklos; +Cc: linux-fsdevel, linux-kernel, eblake, libguestfs, synarete

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>
---
 fs/fuse/file.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 09ef2a4d25ed..ec20a1801c1b 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -2907,11 +2907,13 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
 	};
 	int err;
 	bool lock_inode = !(mode & FALLOC_FL_KEEP_SIZE) ||
-			   (mode & FALLOC_FL_PUNCH_HOLE);
+			   (mode & (FALLOC_FL_PUNCH_HOLE |
+				    FALLOC_FL_ZERO_RANGE));
 
 	bool block_faults = FUSE_IS_DAX(inode) && lock_inode;
 
-	if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
+	if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE |
+		     FALLOC_FL_ZERO_RANGE))
 		return -EOPNOTSUPP;
 
 	if (fm->fc->no_fallocate)
@@ -2926,7 +2928,7 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
 				goto out;
 		}
 
-		if (mode & FALLOC_FL_PUNCH_HOLE) {
+		if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_ZERO_RANGE)) {
 			loff_t endbyte = offset + length - 1;
 
 			err = fuse_writeback_range(inode, offset, endbyte);
@@ -2966,7 +2968,7 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
 			file_update_time(file);
 	}
 
-	if (mode & FALLOC_FL_PUNCH_HOLE)
+	if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_ZERO_RANGE))
 		truncate_pagecache_range(inode, offset, offset + length - 1);
 
 	fuse_invalidate_attr(inode);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v4] fuse: Allow fallocate(FALLOC_FL_ZERO_RANGE)
  2021-05-12 16:18 ` Richard W.M. Jones
@ 2021-05-18 13:56   ` Miklos Szeredi
  2021-06-15 10:33     ` Richard W.M. Jones
  0 siblings, 1 reply; 5+ messages in thread
From: Miklos Szeredi @ 2021-05-18 13:56 UTC (permalink / raw)
  To: Richard W.M. Jones
  Cc: linux-fsdevel, linux-kernel, eblake, libguestfs, Shachar Sharon

On Wed, 12 May 2021 at 18:19, Richard W.M. Jones <rjones@redhat.com> wrote:
>
> 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.

Thanks, applied.

Miklos

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v4] fuse: Allow fallocate(FALLOC_FL_ZERO_RANGE)
  2021-05-18 13:56   ` Miklos Szeredi
@ 2021-06-15 10:33     ` Richard W.M. Jones
  2021-06-18  7:12       ` Miklos Szeredi
  0 siblings, 1 reply; 5+ messages in thread
From: Richard W.M. Jones @ 2021-06-15 10:33 UTC (permalink / raw)
  To: Miklos Szeredi
  Cc: linux-fsdevel, linux-kernel, eblake, libguestfs, Shachar Sharon

On Tue, May 18, 2021 at 03:56:25PM +0200, Miklos Szeredi wrote:
> On Wed, 12 May 2021 at 18:19, Richard W.M. Jones <rjones@redhat.com> wrote:
> >
> > 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.
> 
> Thanks, applied.

Hi Miklos, did this patch get forgotten?

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v4] fuse: Allow fallocate(FALLOC_FL_ZERO_RANGE)
  2021-06-15 10:33     ` Richard W.M. Jones
@ 2021-06-18  7:12       ` Miklos Szeredi
  0 siblings, 0 replies; 5+ messages in thread
From: Miklos Szeredi @ 2021-06-18  7:12 UTC (permalink / raw)
  To: Richard W.M. Jones
  Cc: linux-fsdevel, linux-kernel, eblake, libguestfs, Shachar Sharon

On Tue, 15 Jun 2021 at 12:34, Richard W.M. Jones <rjones@redhat.com> wrote:
>
> On Tue, May 18, 2021 at 03:56:25PM +0200, Miklos Szeredi wrote:
> > On Wed, 12 May 2021 at 18:19, Richard W.M. Jones <rjones@redhat.com> wrote:
> > >
> > > 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.
> >
> > Thanks, applied.
>
> Hi Miklos, did this patch get forgotten?

It's in my internal patch queue.   Will push to fuse.git#for-next in a few days.

Thanks,
Miklos

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-06-18  7:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-12 16:18 [PATCH v4] fuse: Allow fallocate(FALLOC_FL_ZERO_RANGE) Richard W.M. Jones
2021-05-12 16:18 ` Richard W.M. Jones
2021-05-18 13:56   ` Miklos Szeredi
2021-06-15 10:33     ` Richard W.M. Jones
2021-06-18  7:12       ` Miklos Szeredi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).