Re: [PATCH 4/7] xfs: Implement fallocate query support mode

Andreas Dilger
2017-09-18T21:55:47Z

[-- Attachment #1: Type: text/plain, Size: 2525 bytes --]

On Sep 18, 2017, at 2:48 PM, Darrick J. Wong <darrick.wong@oracle.com> wrote:
>
> On Mon, Sep 18, 2017 at 05:52:24PM +0200, Lukas Czerner wrote:
>> Return all fallcoate modes supported by xfs file system.
>>
>> Cc: linux-xfs@vger.kernel.org
>> Signed-off-by: Lukas Czerner <lczerner@redhat.com>
>> ---
>> fs/xfs/xfs_file.c | 6 +++++-
>> 1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
>> index ebdd0bd..85e06c6 100644
>> --- a/fs/xfs/xfs_file.c
>> +++ b/fs/xfs/xfs_file.c
>> @@ -746,7 +746,8 @@ xfs_file_write_iter(
>> #define XFS_FALLOC_FL_SUPPORTED \
>> (FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE | \
>> FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE | \
>> - FALLOC_FL_INSERT_RANGE | FALLOC_FL_UNSHARE_RANGE)
>> + FALLOC_FL_INSERT_RANGE | FALLOC_FL_UNSHARE_RANGE | \
>> + FALLOC_FL_QUERY_SUPPORT | FALLOC_FL_PREALLOC_RANGE)
>>
>> STATIC long
>> xfs_file_fallocate(
>> @@ -768,6 +769,9 @@ xfs_file_fallocate(
>> if (mode & ~XFS_FALLOC_FL_SUPPORTED)
>> return -EOPNOTSUPP;
>>
>> + if (mode & FALLOC_FL_QUERY_SUPPORT)
>> + return XFS_FALLOC_FL_SUPPORTED;
>
> Urk, manpage update describing the goals of the query interface and how
> this is supposed to work is needed.
>
> Are we required to return only the mode flags that would reasonably be
> expected to work on this file, or the fs in general? Do we return zero
> if the file is immutable (I guess the fd has to be O_RDONLY?) or if the
> fs is readonly?
>
> And like hch said, why not {f,}pathconf?

The problem with pathconf() is that this is just made up by GlibC, and
doesn't actually communicate with the kernel or the filesystem at all.
For example, _PC_LINK_MAX does not return different values for ext2/ext4
filesystems based on feature flags, only what is hard-coded into GlibC
based on the filesystem magic. This is not going to work as a per-file
source of information.

For example, even though EXT4_LINK_MAX has been 65000 for many years,
GlibC reports 32000 for an ext4 filesystem since it only uses the magic:

$ df -T /
Filesystem Type 1024-blocks Used Available Capacity Mounted on
/dev/mapper/vg_twoshoes-lvroot
ext4 25991484 22475376 2205504 92% /
$ strace getconf LINK_MAX /
:
:
statfs("/", {f_type="EXT2_SUPER_MAGIC", f_bsize=4096, f_blocks=6497871,
f_bfree=879030, f_bavail=551379, f_files=819200, f_ffree=405130,
f_fsid={1950084367, 1019861045}, f_namelen=255}) = 0
write(1, "32000\n",) = 6

Cheers, Andreas

[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 195 bytes --]