manpage: update FALLOC_FL_COLLAPSE_RANGE flag in fallocate
PATCH v5 10/10 manpage: update FALLOC_FL_COLLAPSE_RANGE flag in fallocate
From: Namjae Jeon <[email protected]>
Update FALLOC_FL_COLLAPSE_RANGE flag in fallocate.
--- man2/fallocate.2 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
man2/fallocate.2 +21 -0
@@ -1,5 +1,6 @@ .\" Copyright (c) 2007 Silicon Graphics, Inc. All Rights Reserved .\" Written by Dave Chinner <[email protected]> +.\" Updated by Namjae Jeon <[email protected]> .\" .\" %%%LICENSE_START(GPLv2_ONELINE) .\" May be distributed as per GNU General Public License version 2.
@@ -7,6 +8,7 @@ .\" .\" 2011-09-19: Added FALLOC_FL_PUNCH_HOLE .\" 2011-09-19: Substantial restructuring of the page +.\" 2014-02-19: Added FALLOC_FL_COLLAPSE_RANGE .\" .TH FALLOCATE 2 2014-01-24 "Linux" "Linux Programmer's Manual" .SH NAME
@@ -124,6 +126,25 @@ Btrfs (since Linux 3.7) .IP * tmpfs (since Linux 3.5) .\" commit 83e4fa9c16e4af7122e31be3eca5d57881d236fe +.SS Collapsing file space +Specifiying the +.BR FALLOC_FL_COLLAPSE_RANGE +flag in +.I mode +collpse space in the byte range starting at +.I offset +and continuing for +.I len +bytes. Within the specified range, it first de-allocates blocks and eliminates +the hole created in this process by shifting data blocks into the hole. + +Different filesystem may implement different limitatios on the granularity of +the operation. Most filesystem will limit operations to filesystem block size +boundaries, but this boundary may be larger or smaller depending +on the filesystem and/or the configuration of the filesystem or file. + +If filesystem has such limitation on granularity, It will return error(EINVAL). + .SH RETURN VALUE On success, .BR fallocate ()
Signature · 6 lines
1.7.9.5 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
A message that is not in the archive (sent off-list or not yet received): 1392741594-20335-1-git-send-email-linkinjeon-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Michael, can you apply this now that we merged FALLOC_FL_COLLAPSE_RANGE into the kernel tree?
Quoted 62 lines · Namjae Jeon
From: Namjae Jeon <[email protected]>
Update
FALLOC_FL_COLLAPSE_RANGEflag in fallocate.Signed-off-by Namjae Jeon <[email protected]>Signed-off-by Ashish Sangwan <[email protected]>--- man2/fallocate.2 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)man2/fallocate.2 +21
-0@@ -1,5 +1,6 @@ .\" Copyright (c) 2007 Silicon Graphics, Inc. All Rights Reserved .\" Written by Dave Chinner <dgc-sJ/[email protected]> +.\" Updated by Namjae Jeon <[email protected]> .\" .\" %%%LICENSE_START(GPLv2_ONELINE) .\" May be distributed as per GNU General Public License version 2.@@ -7,6 +8,7 @@ .\" .\" 2011-09-19: Added FALLOC_FL_PUNCH_HOLE .\" 2011-09-19: Substantial restructuring of the page +.\" 2014-02-19: Added FALLOC_FL_COLLAPSE_RANGE .\" .TH FALLOCATE 2 2014-01-24 "Linux" "Linux Programmer's Manual" .SH NAME@@ -124,6 +126,25 @@ Btrfs (since Linux 3.7) .IP * tmpfs (since Linux 3.5) .\" commit 83e4fa9c16e4af7122e31be3eca5d57881d236fe +.SS Collapsing file space +Specifiying the +.BR FALLOC_FL_COLLAPSE_RANGE +flag in +.I mode +collpse space in the byte range starting at +.I offset +and continuing for +.I len +bytes. Within the specified range, it first de-allocates blocks and eliminates +the hole created in this process by shifting data blocks into the hole. + +Different filesystem may implement different limitatios on the granularity of +the operation. Most filesystem will limit operations to filesystem block size +boundaries, but this boundary may be larger or smaller depending +on the filesystem and/or the configuration of the filesystem or file. + +If filesystem has such limitation on granularity, It will return error(EINVAL). + .SH RETURN VALUE On success, .BR fallocate ()Signature · 6 lines
1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
---end quoted text---
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): [email protected]
Michael Kerrisk (man-pages)
AppliedQuoted 2 lines · Christoph Hellwig
Michael, can you apply this now that we merged
FALLOC_FL_COLLAPSE_RANGEinto the kernel tree?
I've applied Namjae Jeon's patch (thanks Namjae!), and done a lot of tweaking to generate the patch below.
Along the way I noticed that there is an inconsistency between XFS and JFS that should be fixed (and so have added Dave and Ted to CC, as well as linux-fsdevel@).
If 'fd' does not refer to a regular file, then XFS fails with the error EINVAL (fs/xfs/xfs_file.c::xfs_file_fallocate()), but ext4 fails with the error EOPNOTSUP (fs/ext4/extents::ext4_collapse_range()). I suspect that EINVAL is the right error for this case.
I'd appreciate review on my revised patch, below.
Cheers,
Michael
man2/fallocate.2 +96 -0
@@ -124,6 +124,62 @@ Btrfs (since Linux 3.7) .IP * tmpfs (since Linux 3.5) .\" commit 83e4fa9c16e4af7122e31be3eca5d57881d236fe +.SS Collapsing file space +.\" commit 00f5e61998dd17f5375d9dfc01331f104b83f841 +Specifying the +.BR FALLOC_FL_COLLAPSE_RANGE +flag (available since Linux 3.15) in +.I mode +removes a byte range from a file, without leaving a hole. +The byte range to be collapsed starts at +.I offset +and continues for +.I len +bytes. +At the completion of the operation, +the contents of the file starting at the location +.I offset+len +will be appended at the location +.IR offset , +and the file will be +.I len +bytes smaller. + +A filesystem may place limitations on the granularity of the operation, +in order to ensure efficient implementation. +Typically, +.I offset +and +.I len +must be a multiple of the filesystem logical block size, +which varies according to the filesystem type and configuration. +If a filesystem has such a requirement, +.BR fallocate () +will fail with the error +.BR EINVAL +if this requirement is violated. + +If the region specified by +.I offset +plus +.I len +reaches or passes the end of file, an error is returned; +instead, use +.BR ftruncate (2) +to truncate a file. + +No other flags may be specified in +.IR mode +in conjunction with +.BR FALLOC_FL_COLLAPSE_RANGE . + +As at Linux 3.15, +.B FALLOC_FL_COLLAPSE_RANGE +is supported by +ext4 (only for extent-based files) +.\" commit 9eb79482a97152930b113b51dff530aba9e28c8e +and XFS. +.\" commit e1d8fb88a64c1f8094b9f6c3b6d2d9e6719c970d .SH RETURN VALUE On success, .BR fallocate ()
@@ -156,6 +212,36 @@ was less than 0, or .\" http://thread.gmane.org/gmane.linux.file-systems/48331/focus=1193526 was less than or equal to 0. .TP +.B EINVAL +.I mode +is +.BR FALLOC_FL_COLLAPSE_RANGE +and the range specified by +.I offset +plus +.I len +reaches or passes the end of the file. +.TP +.B EINVAL +.I mode +is +.BR FALLOC_FL_COLLAPSE_RANGE , +but either +.I offset +or +.I len +is not a multiple of the filesystem block size. +.TP +.B EINVAL +mode contains both +.B FALLOC_FL_COLLAPSE_RANGE +and other flags; +no other flags are permitted with +.BR FALLOC_FL_COLLAPSE_RANGE . +.\" FIXME Document error when FALLOC_FL_COLLAPSE_RANGE +.\" is given a nonregular file. As at 3.15-rc1, XFS gives +.\" EINVAL, but ext4 gives EOPNOTSUPP. +.TP .B EIO An I/O error occurred while reading from or writing to a filesystem. .TP
@@ -193,6 +279,8 @@ Or: .I mode specifies .BR FALLOC_FL_PUNCH_HOLE +or +.BR FALLOC_FL_COLLAPSE_RANGE and the file referred to by .I fd
@@ -203,6 +291,14 @@ is marked append-only .B ESPIPE .I fd refers to a pipe or FIFO. +.TP +.B ETXTBSY +.I mode +specifies +.BR FALLOC_FL_COLLAPSE_RANGE , +but the file referred to by +.IR fd +is currently being executed. .SH VERSIONS .BR fallocate () is available on Linux since kernel 2.6.23.
Signature · 7 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/ -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 9 lines · Michael Kerrisk (man-pages)
Quoted 2 lines · Christoph Hellwig
Michael, can you apply this now that we merged
FALLOC_FL_COLLAPSE_RANGEinto the kernel tree?I've applied Namjae Jeon's patch (thanks Namjae!), and done a lot of tweaking to generate the patch below.
Along the way I noticed that there is an inconsistency between XFS and JFS that should be fixed (and so have added Dave and Ted to CC,
ext4?
Anyway, the documentation looks good to in general, but do you really think mentioning git commit hashs in a man page is a good idea?
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 5 lines · Christoph Hellwig
Quoted 4 lines · Michael Kerrisk (man-pages)
Quoted 2 lines · Christoph Hellwig
Michael, can you apply this now that we merged
FALLOC_FL_COLLAPSE_RANGEinto the kernel tree?
Quoted 7 lines
Quoted 5 lines
I've applied Namjae Jeon's patch (thanks Namjae!), and done a lot of tweaking to generate the patch below.
Along the way I noticed that there is an inconsistency between XFS and JFS that should be fixed (and so have added Dave and Ted to CC,
ext4?
D'oh -- yes!
Quoted 2 lines
Anyway, the documentation looks good to in general, but do you really think mentioning git commit hashs in a man page is a good idea?
Those are only comments in the source file, for reference (sometimes, that's really helpful). They don't appear the rendered output.
Cheers,
Michael
Signature · 7 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/ -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): CAKgNAkgis+LvQeiabWaRbb3=rvEV2_Z_XQ8O6d5JGR=eEFSxCg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 2 lines · Michael Kerrisk (man-pages)
Those are only comments in the source file, for reference (sometimes, that's really helpful). They don't appear the rendered output.
Ok, that makes a lot more sense.
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 11 lines · Michael Kerrisk (man-pages)
Quoted 2 lines · Christoph Hellwig
Michael, can you apply this now that we merged
FALLOC_FL_COLLAPSE_RANGEinto the kernel tree?I've applied Namjae Jeon's patch (thanks Namjae!), and done a lot of tweaking to generate the patch below.
Along the way I noticed that there is an inconsistency between XFS and JFS that should be fixed (and so have added Dave and Ted to CC, as well as linux-fsdevel@).
Quoted 5 lines
If 'fd' does not refer to a regular file, then XFS fails with the error EINVAL (fs/xfs/xfs_file.c::xfs_file_fallocate()), but ext4 fails with the error EOPNOTSUP (fs/ext4/extents::ext4_collapse_range()). I suspect that EINVAL is the right error for this case.
I think EINVAL is correct here - we support the syscall, just the type of file we are being asked to operate on is invalid.
FWIW, the reason this check is in the filesystems is that there is no theoretical reason why we can't do things like preallocation for directories (e.g. to reduce fragmentation as they grow). It's just not implemented by any filesystem yet.
[ Hmmmm - I just had a great idea - removing entire directory contents via punching blocks. No more "remove one dirent at a time" for rm -rf, just punch the directory from start to end and there goes millions of directory entries in a single syscall and a handful of transactions. FALLOC_FL_DIR_PUNCH, anyone? ]
Quoted 1 line
I'd appreciate review on my revised patch, below.
Looks fine to me.
Cheers,
Dave.
Signature · 6 lines
Dave Chinner [email protected] -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 21 lines · Dave Chinner
Date: Fri, 18 Apr 2014 08:57:01 +1000
From: Dave Chinner <[email protected]>
To: "Michael Kerrisk (man-pages)" <[email protected]>
Cc: Christoph Hellwig <[email protected]>, Namjae Jeon <[email protected]>,
[email protected], Theodore T'so <[email protected]>, Linux-Fsdevel <[email protected]>
Subject: Re: [PATCH v5 10/10] manpage: updateFALLOC_FL_COLLAPSE_RANGEflag in
fallocateQuoted 11 lines · Michael Kerrisk (man-pages)
Quoted 2 lines · Christoph Hellwig
Michael, can you apply this now that we merged
FALLOC_FL_COLLAPSE_RANGEinto the kernel tree?I've applied Namjae Jeon's patch (thanks Namjae!), and done a lot of tweaking to generate the patch below.
Along the way I noticed that there is an inconsistency between XFS and JFS that should be fixed (and so have added Dave and Ted to CC, as well as linux-fsdevel@).
Quoted 8 lines
Quoted 5 lines
If 'fd' does not refer to a regular file, then XFS fails with the error EINVAL (fs/xfs/xfs_file.c::xfs_file_fallocate()), but ext4 fails with the error EOPNOTSUP (fs/ext4/extents::ext4_collapse_range()). I suspect that EINVAL is the right error for this case.
I think EINVAL is correct here - we support the syscall, just the type of file we are being asked to operate on is invalid.
I'd like to point out that do_fallocate() in vfs uses ENODEV in the case it is not regular file nor directory.
Also I thought of the EOPNOTSUP to be the right way to go. For example we do not support it on non-extent based files in ext4 so we return EOPNOTSUP.
The same is for the case that we do not support the particular fallocate mode.
So I am not really sure about what's the right error to use.
Thanks!
-Lukas
Quoted 12 lines
FWIW, the reason this check is in the filesystems is that there is no theoretical reason why we can't do things like preallocation for directories (e.g. to reduce fragmentation as they grow). It's just not implemented by any filesystem yet.
[ Hmmmm - I just had a great idea - removing entire directory contents via punching blocks. No more "remove one dirent at a time" for rm -rf, just punch the directory from start to end and there goes millions of directory entries in a single syscall and a handful of transactions.
FALLOC_FL_DIR_PUNCH, anyone? ]
Quoted 8 lines
Quoted 1 line
I'd appreciate review on my revised patch, below.
Looks fine to me.
Cheers,
Dave.
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 4 lines · Lukáš Czerner
I'd like to point out that
do_fallocate()in vfs uses ENODEV in the case it is not regular file nor directory.
Quoted 8 lines
Also I thought of the EOPNOTSUP to be the right way to go. For example we do not support it on non-extent based files in ext4 so we return EOPNOTSUP.
The same is for the case that we do not support the particular fallocate mode.
So I am not really sure about what's the right error to use.
Yes, there is some inconsistency here. I'll change this particular case (a non-REGULAR file to use EINVAL) to be consistent with xfs, but I suspect programs are going to have to be flexible.
As far as non-extent based files, at least in theory at some point we could support COLLAPSE_RANGE on regular files, so I'll leave it as EOPNOTSUPP for now, but the choice is admittedly somewhat arbitrary.
Cheers,
- Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 9 lines · Theodore Ts'o
Quoted 8 lines · Lukáš Czerner
I'd like to point out that
do_fallocate()in vfs uses ENODEV in the case it is not regular file nor directory.Also I thought of the EOPNOTSUP to be the right way to go. For example we do not support it on non-extent based files in ext4 so we return EOPNOTSUP.
Quoted 8 lines
Quoted 4 lines
The same is for the case that we do not support the particular fallocate mode.
So I am not really sure about what's the right error to use.
Yes, there is some inconsistency here. I'll change this particular case (a non-REGULAR file to use EINVAL) to be consistent with xfs, but I suspect programs are going to have to be flexible.
Okay -- I'll document EINVAL as the (sole) error for this case.
Thanks, Ted.
Quoted 3 lines
As far as non-extent based files, at least in theory at some point we could support
COLLAPSE_RANGEon regular files, so I'll leave it as EOPNOTSUPP for now, but the choice is admittedly somewhat arbitrary.
Agreed that its somewhat inconsistent, though not as egregiously so as the other case.
Cheers,
Michael
Signature · 7 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/ -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 12 lines · Dave Chinner
Quoted 11 lines · Michael Kerrisk (man-pages)
Quoted 2 lines · Christoph Hellwig
Michael, can you apply this now that we merged
FALLOC_FL_COLLAPSE_RANGEinto the kernel tree?I've applied Namjae Jeon's patch (thanks Namjae!), and done a lot of tweaking to generate the patch below.
Along the way I noticed that there is an inconsistency between XFS and JFS that should be fixed (and so have added Dave and Ted to CC, as well as linux-fsdevel@).
Quoted 8 lines
Quoted 5 lines
If 'fd' does not refer to a regular file, then XFS fails with the error EINVAL (fs/xfs/xfs_file.c::xfs_file_fallocate()), but ext4 fails with the error EOPNOTSUP (fs/ext4/extents::ext4_collapse_range()). I suspect that EINVAL is the right error for this case.
I think EINVAL is correct here - we support the syscall, just the type of file we are being asked to operate on is invalid.
Hmmm -- you and Lukasz seem to differ on this point.
Quoted 10 lines
FWIW, the reason this check is in the filesystems is that there is no theoretical reason why we can't do things like preallocation for directories (e.g. to reduce fragmentation as they grow). It's just not implemented by any filesystem yet.
[ Hmmmm - I just had a great idea - removing entire directory contents via punching blocks. No more "remove one dirent at a time" for rm -rf, just punch the directory from start to end and there goes millions of directory entries in a single syscall and a handful of transactions.
FALLOC_FL_DIR_PUNCH, anyone? ]
Interesting idea. CC me and linux-api on the patch, if you do one.
Quoted 3 lines
Quoted 1 line
I'd appreciate review on my revised patch, below.
Looks fine to me.
Thanks,
Michael
Signature · 7 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/ -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html