Skip to content

Commit 50166d5

Browse files
committed
exportfs: add open method
This allows filesystems such as pidfs to provide their custom open. Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Amir Goldstein <[email protected]> Reviewed-by: Jan Kara <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent f07c7cc commit 50166d5

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

fs/fhandle.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ static long do_handle_open(int mountdirfd, struct file_handle __user *ufh,
401401
long retval = 0;
402402
struct path path __free(path_put) = {};
403403
struct file *file;
404+
const struct export_operations *eops;
404405

405406
retval = handle_to_path(mountdirfd, ufh, &path, open_flag);
406407
if (retval)
@@ -410,7 +411,11 @@ static long do_handle_open(int mountdirfd, struct file_handle __user *ufh,
410411
if (fd < 0)
411412
return fd;
412413

413-
file = file_open_root(&path, "", open_flag, 0);
414+
eops = path.mnt->mnt_sb->s_export_op;
415+
if (eops->open)
416+
file = eops->open(&path, open_flag);
417+
else
418+
file = file_open_root(&path, "", open_flag, 0);
414419
if (IS_ERR(file))
415420
return PTR_ERR(file);
416421

include/linux/exportfs.h

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ struct inode;
1010
struct iomap;
1111
struct super_block;
1212
struct vfsmount;
13+
struct path;
1314

1415
/* limit the handle size to NFSv4 handle size now */
1516
#define MAX_HANDLE_SZ 128
@@ -225,6 +226,9 @@ struct fid {
225226
* is also a directory. In the event that it cannot be found, or storage
226227
* space cannot be allocated, a %ERR_PTR should be returned.
227228
*
229+
* open:
230+
* Allow filesystems to specify a custom open function.
231+
*
228232
* commit_metadata:
229233
* @commit_metadata should commit metadata changes to stable storage.
230234
*
@@ -251,6 +255,7 @@ struct export_operations {
251255
bool write, u32 *device_generation);
252256
int (*commit_blocks)(struct inode *inode, struct iomap *iomaps,
253257
int nr_iomaps, struct iattr *iattr);
258+
struct file * (*open)(struct path *path, unsigned int oflags);
254259
#define EXPORT_OP_NOWCC (0x1) /* don't collect v3 wcc data */
255260
#define EXPORT_OP_NOSUBTREECHK (0x2) /* no subtree checking */
256261
#define EXPORT_OP_CLOSE_BEFORE_UNLINK (0x4) /* close files before unlink */

0 commit comments

Comments
 (0)