Skip to content

Commit e21fc20

Browse files
amir73ilbrauner
authored andcommitted
exportfs: make ->encode_fh() a mandatory method for NFS export
Rename the default helper for encoding FILEID_INO32_GEN* file handles to generic_encode_ino32_fh() and convert the filesystems that used the default implementation to use the generic helper explicitly. After this change, exportfs_encode_inode_fh() no longer has a default implementation to encode FILEID_INO32_GEN* file handles. This is a step towards allowing filesystems to encode non-decodeable file handles for fanotify without having to implement any export_operations. Reviewed-by: Jan Kara <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Acked-by: Chuck Lever <[email protected]> Signed-off-by: Amir Goldstein <[email protected]> Link: https://lore.kernel.org/r/[email protected] Acked-by: Dave Kleikamp <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 66c6276 commit e21fc20

File tree

19 files changed

+47
-19
lines changed

19 files changed

+47
-19
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
@@ -1045,3 +1045,12 @@ filesystem type is now moved to a later point when the devices are closed:
10451045
As this is a VFS level change it has no practical consequences for filesystems
10461046
other than that all of them must use one of the provided kill_litter_super(),
10471047
kill_anon_super(), or kill_block_super() helpers.
1048+
1049+
---
1050+
1051+
**mandatory**
1052+
1053+
export_operations ->encode_fh() no longer has a default implementation to
1054+
encode FILEID_INO32_GEN* file handles.
1055+
Filesystems that used the default implementation may use the generic helper
1056+
generic_encode_ino32_fh() explicitly.

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/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
@@ -626,6 +626,7 @@ static struct dentry *erofs_get_parent(struct dentry *child)
626626
}
627627

628628
static const struct export_operations erofs_export_ops = {
629+
.encode_fh = generic_encode_ino32_fh,
629630
.fh_to_dentry = erofs_fh_to_dentry,
630631
.fh_to_parent = erofs_fh_to_parent,
631632
.get_parent = erofs_get_parent,

fs/exportfs/expfs.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -343,20 +343,21 @@ static int get_name(const struct path *path, char *name, struct dentry *child)
343343
}
344344

345345
/**
346-
* export_encode_fh - default export_operations->encode_fh function
346+
* generic_encode_ino32_fh - generic export_operations->encode_fh function
347347
* @inode: the object to encode
348-
* @fid: where to store the file handle fragment
349-
* @max_len: maximum length to store there
348+
* @fh: where to store the file handle fragment
349+
* @max_len: maximum length to store there (in 4 byte units)
350350
* @parent: parent directory inode, if wanted
351351
*
352-
* This default encode_fh function assumes that the 32 inode number
352+
* This generic encode_fh function assumes that the 32 inode number
353353
* is suitable for locating an inode, and that the generation number
354354
* can be used to check that it is still valid. It places them in the
355355
* filehandle fragment where export_decode_fh expects to find them.
356356
*/
357-
static int export_encode_fh(struct inode *inode, struct fid *fid,
358-
int *max_len, struct inode *parent)
357+
int generic_encode_ino32_fh(struct inode *inode, __u32 *fh, int *max_len,
358+
struct inode *parent)
359359
{
360+
struct fid *fid = (void *)fh;
360361
int len = *max_len;
361362
int type = FILEID_INO32_GEN;
362363

@@ -380,6 +381,7 @@ static int export_encode_fh(struct inode *inode, struct fid *fid,
380381
*max_len = len;
381382
return type;
382383
}
384+
EXPORT_SYMBOL_GPL(generic_encode_ino32_fh);
383385

384386
/**
385387
* exportfs_encode_inode_fh - encode a file handle from inode
@@ -402,7 +404,7 @@ int exportfs_encode_inode_fh(struct inode *inode, struct fid *fid,
402404
if (nop && nop->encode_fh)
403405
return nop->encode_fh(inode, fid->raw, max_len, parent);
404406

405-
return export_encode_fh(inode, fid, max_len, parent);
407+
return -EOPNOTSUPP;
406408
}
407409
EXPORT_SYMBOL_GPL(exportfs_encode_inode_fh);
408410

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,

fs/ext4/super.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,7 @@ static const struct super_operations ext4_sops = {
16461646
};
16471647

16481648
static const struct export_operations ext4_export_ops = {
1649+
.encode_fh = generic_encode_ino32_fh,
16491650
.fh_to_dentry = ext4_fh_to_dentry,
16501651
.fh_to_parent = ext4_fh_to_parent,
16511652
.get_parent = ext4_get_parent,

fs/f2fs/super.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3282,6 +3282,7 @@ static struct dentry *f2fs_fh_to_parent(struct super_block *sb, struct fid *fid,
32823282
}
32833283

32843284
static const struct export_operations f2fs_export_ops = {
3285+
.encode_fh = generic_encode_ino32_fh,
32853286
.fh_to_dentry = f2fs_fh_to_dentry,
32863287
.fh_to_parent = f2fs_fh_to_parent,
32873288
.get_parent = f2fs_get_parent,

0 commit comments

Comments
 (0)