Skip to content

Commit 13d88ac

Browse files
committed
Merge tag 'vfs-6.7.fsid' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs
Pull vfs fanotify fsid updates from Christian Brauner: "This work is part of the plan to enable fanotify to serve as a drop-in replacement for inotify. While inotify is availabe on all filesystems, fanotify currently isn't. In order to support fanotify on all filesystems two things are needed: (1) all filesystems need to support AT_HANDLE_FID (2) all filesystems need to report a non-zero f_fsid This contains (1) and allows filesystems to encode non-decodable file handlers for fanotify without implementing any exportfs operations by encoding a file id of type FILEID_INO64_GEN from i_ino and i_generation. Filesystems that want to opt out of encoding non-decodable file ids for fanotify that don't support NFS export can do so by providing an empty export_operations struct. This also partially addresses (2) by generating f_fsid for simple filesystems as well as freevxfs. Remaining filesystems will be dealt with by separate patches. Finally, this contains the patch from the current exportfs maintainers which moves exportfs under vfs with Chuck, Jeff, and Amir as maintainers and vfs.git as tree" * tag 'vfs-6.7.fsid' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs: MAINTAINERS: create an entry for exportfs fs: fix build error with CONFIG_EXPORTFS=m or not defined freevxfs: derive f_fsid from bdev->bd_dev fs: report f_fsid from s_dev for "simple" filesystems exportfs: support encoding non-decodeable file handles by default exportfs: define FILEID_INO64_GEN* file handle types exportfs: make ->encode_fh() a mandatory method for NFS export exportfs: add helpers to check if filesystem can encode/decode file handles
2 parents 062cca8 + 4ad714d commit 13d88ac

File tree

29 files changed

+168
-65
lines changed

29 files changed

+168
-65
lines changed

Documentation/filesystems/nfs/exporting.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,9 @@ are exportable by setting the s_export_op field in the struct
122122
super_block. This field must point to a "struct export_operations"
123123
struct which has the following members:
124124

125-
encode_fh (optional)
125+
encode_fh (mandatory)
126126
Takes a dentry and creates a filehandle fragment which may later be used
127-
to find or create a dentry for the same object. The default
128-
implementation creates a filehandle fragment that encodes a 32bit inode
129-
and generation number for the inode encoded, and if necessary the
130-
same information for the parent.
127+
to find or create a dentry for the same object.
131128

132129
fh_to_dentry (mandatory)
133130
Given a filehandle fragment, this should find the implied object and

Documentation/filesystems/porting.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,3 +1052,12 @@ kill_anon_super(), or kill_block_super() helpers.
10521052

10531053
Lock ordering has been changed so that s_umount ranks above open_mutex again.
10541054
All places where s_umount was taken under open_mutex have been fixed up.
1055+
1056+
---
1057+
1058+
**mandatory**
1059+
1060+
export_operations ->encode_fh() no longer has a default implementation to
1061+
encode FILEID_INO32_GEN* file handles.
1062+
Filesystems that used the default implementation may use the generic helper
1063+
generic_encode_ino32_fh() explicitly.

MAINTAINERS

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8156,6 +8156,18 @@ F: include/linux/fs_types.h
81568156
F: include/uapi/linux/fs.h
81578157
F: include/uapi/linux/openat2.h
81588158

8159+
FILESYSTEMS [EXPORTFS]
8160+
M: Chuck Lever <chuck.lever@oracle.com>
8161+
M: Jeff Layton <jlayton@kernel.org>
8162+
R: Amir Goldstein <amir73il@gmail.com>
8163+
L: linux-fsdevel@vger.kernel.org
8164+
L: linux-nfs@vger.kernel.org
8165+
S: Supported
8166+
F: Documentation/filesystems/nfs/exporting.rst
8167+
F: fs/exportfs/
8168+
F: fs/fhandle.c
8169+
F: include/linux/exportfs.h
8170+
81598171
FILESYSTEMS [IOMAP]
81608172
M: Christian Brauner <brauner@kernel.org>
81618173
R: Darrick J. Wong <djwong@kernel.org>
@@ -11548,7 +11560,6 @@ S: Supported
1154811560
W: http://nfs.sourceforge.net/
1154911561
T: git git://git.kernel.org/pub/scm/linux/kernel/git/cel/linux.git
1155011562
F: Documentation/filesystems/nfs/
11551-
F: fs/exportfs/
1155211563
F: fs/lockd/
1155311564
F: fs/nfs_common/
1155411565
F: fs/nfsd/

fs/affs/namei.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ static struct dentry *affs_fh_to_parent(struct super_block *sb, struct fid *fid,
568568
}
569569

570570
const struct export_operations affs_export_ops = {
571+
.encode_fh = generic_encode_ino32_fh,
571572
.fh_to_dentry = affs_fh_to_dentry,
572573
.fh_to_parent = affs_fh_to_parent,
573574
.get_parent = affs_get_parent,

fs/befs/linuxvfs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ static const struct address_space_operations befs_symlink_aops = {
9696
};
9797

9898
static const struct export_operations befs_export_operations = {
99+
.encode_fh = generic_encode_ino32_fh,
99100
.fh_to_dentry = befs_fh_to_dentry,
100101
.fh_to_parent = befs_fh_to_parent,
101102
.get_parent = befs_get_parent,

fs/efivarfs/super.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ static int efivarfs_statfs(struct dentry *dentry, struct kstatfs *buf)
4646
EFI_VARIABLE_BOOTSERVICE_ACCESS |
4747
EFI_VARIABLE_RUNTIME_ACCESS;
4848
u64 storage_space, remaining_space, max_variable_size;
49+
u64 id = huge_encode_dev(dentry->d_sb->s_dev);
4950
efi_status_t status;
5051

5152
/* Some UEFI firmware does not implement QueryVariableInfo() */
@@ -69,6 +70,7 @@ static int efivarfs_statfs(struct dentry *dentry, struct kstatfs *buf)
6970
buf->f_blocks = storage_space;
7071
buf->f_bfree = remaining_space;
7172
buf->f_type = dentry->d_sb->s_magic;
73+
buf->f_fsid = u64_to_fsid(id);
7274

7375
/*
7476
* In f_bavail we declare the free space that the kernel will allow writing

fs/efs/super.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ static const struct super_operations efs_superblock_operations = {
123123
};
124124

125125
static const struct export_operations efs_export_ops = {
126+
.encode_fh = generic_encode_ino32_fh,
126127
.fh_to_dentry = efs_fh_to_dentry,
127128
.fh_to_parent = efs_fh_to_parent,
128129
.get_parent = efs_get_parent,

fs/erofs/super.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,7 @@ static struct dentry *erofs_get_parent(struct dentry *child)
567567
}
568568

569569
static const struct export_operations erofs_export_ops = {
570+
.encode_fh = generic_encode_ino32_fh,
570571
.fh_to_dentry = erofs_fh_to_dentry,
571572
.fh_to_parent = erofs_fh_to_parent,
572573
.get_parent = erofs_get_parent,

fs/exportfs/expfs.c

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -342,43 +342,30 @@ static int get_name(const struct path *path, char *name, struct dentry *child)
342342
return error;
343343
}
344344

345+
#define FILEID_INO64_GEN_LEN 3
346+
345347
/**
346-
* export_encode_fh - default export_operations->encode_fh function
348+
* exportfs_encode_ino64_fid - encode non-decodeable 64bit ino file id
347349
* @inode: the object to encode
348350
* @fid: where to store the file handle fragment
349-
* @max_len: maximum length to store there
350-
* @parent: parent directory inode, if wanted
351+
* @max_len: maximum length to store there (in 4 byte units)
351352
*
352-
* This default encode_fh function assumes that the 32 inode number
353-
* is suitable for locating an inode, and that the generation number
354-
* can be used to check that it is still valid. It places them in the
355-
* filehandle fragment where export_decode_fh expects to find them.
353+
* This generic function is used to encode a non-decodeable file id for
354+
* fanotify for filesystems that do not support NFS export.
356355
*/
357-
static int export_encode_fh(struct inode *inode, struct fid *fid,
358-
int *max_len, struct inode *parent)
356+
static int exportfs_encode_ino64_fid(struct inode *inode, struct fid *fid,
357+
int *max_len)
359358
{
360-
int len = *max_len;
361-
int type = FILEID_INO32_GEN;
362-
363-
if (parent && (len < 4)) {
364-
*max_len = 4;
365-
return FILEID_INVALID;
366-
} else if (len < 2) {
367-
*max_len = 2;
359+
if (*max_len < FILEID_INO64_GEN_LEN) {
360+
*max_len = FILEID_INO64_GEN_LEN;
368361
return FILEID_INVALID;
369362
}
370363

371-
len = 2;
372-
fid->i32.ino = inode->i_ino;
373-
fid->i32.gen = inode->i_generation;
374-
if (parent) {
375-
fid->i32.parent_ino = parent->i_ino;
376-
fid->i32.parent_gen = parent->i_generation;
377-
len = 4;
378-
type = FILEID_INO32_GEN_PARENT;
379-
}
380-
*max_len = len;
381-
return type;
364+
fid->i64.ino = inode->i_ino;
365+
fid->i64.gen = inode->i_generation;
366+
*max_len = FILEID_INO64_GEN_LEN;
367+
368+
return FILEID_INO64_GEN;
382369
}
383370

384371
/**
@@ -396,17 +383,13 @@ int exportfs_encode_inode_fh(struct inode *inode, struct fid *fid,
396383
{
397384
const struct export_operations *nop = inode->i_sb->s_export_op;
398385

399-
/*
400-
* If a decodeable file handle was requested, we need to make sure that
401-
* filesystem can decode file handles.
402-
*/
403-
if (nop && !(flags & EXPORT_FH_FID) && !nop->fh_to_dentry)
386+
if (!exportfs_can_encode_fh(nop, flags))
404387
return -EOPNOTSUPP;
405388

406-
if (nop && nop->encode_fh)
407-
return nop->encode_fh(inode, fid->raw, max_len, parent);
389+
if (!nop && (flags & EXPORT_FH_FID))
390+
return exportfs_encode_ino64_fid(inode, fid, max_len);
408391

409-
return export_encode_fh(inode, fid, max_len, parent);
392+
return nop->encode_fh(inode, fid->raw, max_len, parent);
410393
}
411394
EXPORT_SYMBOL_GPL(exportfs_encode_inode_fh);
412395

@@ -456,7 +439,7 @@ exportfs_decode_fh_raw(struct vfsmount *mnt, struct fid *fid, int fh_len,
456439
/*
457440
* Try to get any dentry for the given file handle from the filesystem.
458441
*/
459-
if (!nop || !nop->fh_to_dentry)
442+
if (!exportfs_can_decode_fh(nop))
460443
return ERR_PTR(-ESTALE);
461444
result = nop->fh_to_dentry(mnt->mnt_sb, fid, fh_len, fileid_type);
462445
if (IS_ERR_OR_NULL(result))

fs/ext2/super.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ static struct dentry *ext2_fh_to_parent(struct super_block *sb, struct fid *fid,
397397
}
398398

399399
static const struct export_operations ext2_export_ops = {
400+
.encode_fh = generic_encode_ino32_fh,
400401
.fh_to_dentry = ext2_fh_to_dentry,
401402
.fh_to_parent = ext2_fh_to_parent,
402403
.get_parent = ext2_get_parent,

0 commit comments

Comments
 (0)