]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
exportfs: add open method
authorChristian Brauner <brauner@kernel.org>
Fri, 29 Nov 2024 13:38:02 +0000 (14:38 +0100)
committerChristian Brauner <brauner@kernel.org>
Sat, 14 Dec 2024 11:40:41 +0000 (12:40 +0100)
This allows filesystems such as pidfs to provide their custom open.

Link: https://lore.kernel.org/r/20241129-work-pidfs-file_handle-v1-3-87d803a42495@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/fhandle.c
include/linux/exportfs.h

index c00d88fb14e16654b5cbbb71760c0478eac20384..f0b818f08aaa3602ef1e32d6c4ca7014520136d2 100644 (file)
@@ -401,6 +401,7 @@ static long do_handle_open(int mountdirfd, struct file_handle __user *ufh,
        long retval = 0;
        struct path path __free(path_put) = {};
        struct file *file;
+       const struct export_operations *eops;
 
        retval = handle_to_path(mountdirfd, ufh, &path, open_flag);
        if (retval)
@@ -410,7 +411,11 @@ static long do_handle_open(int mountdirfd, struct file_handle __user *ufh,
        if (fd < 0)
                return fd;
 
-       file = file_open_root(&path, "", open_flag, 0);
+       eops = path.mnt->mnt_sb->s_export_op;
+       if (eops->open)
+               file = eops->open(&path, open_flag);
+       else
+               file = file_open_root(&path, "", open_flag, 0);
        if (IS_ERR(file))
                return PTR_ERR(file);
 
index 4cc8801e50e395442f9e3ae69b6c9f04fa590ff9..c69b79b64466d5bc32ffe9b2796a388130fe72d8 100644 (file)
@@ -10,6 +10,7 @@ struct inode;
 struct iomap;
 struct super_block;
 struct vfsmount;
+struct path;
 
 /* limit the handle size to NFSv4 handle size now */
 #define MAX_HANDLE_SZ 128
@@ -225,6 +226,9 @@ struct fid {
  *    is also a directory.  In the event that it cannot be found, or storage
  *    space cannot be allocated, a %ERR_PTR should be returned.
  *
+ * open:
+ *    Allow filesystems to specify a custom open function.
+ *
  * commit_metadata:
  *    @commit_metadata should commit metadata changes to stable storage.
  *
@@ -251,6 +255,7 @@ struct export_operations {
                          bool write, u32 *device_generation);
        int (*commit_blocks)(struct inode *inode, struct iomap *iomaps,
                             int nr_iomaps, struct iattr *iattr);
+       struct file * (*open)(struct path *path, unsigned int oflags);
 #define        EXPORT_OP_NOWCC                 (0x1) /* don't collect v3 wcc data */
 #define        EXPORT_OP_NOSUBTREECHK          (0x2) /* no subtree checking */
 #define        EXPORT_OP_CLOSE_BEFORE_UNLINK   (0x4) /* close files before unlink */