file: add alloc_file_pseudo_noaccount()
authorChristian Brauner <brauner@kernel.org>
Thu, 8 Feb 2024 18:10:45 +0000 (19:10 +0100)
committerChristian Brauner <brauner@kernel.org>
Sun, 25 Feb 2024 11:05:08 +0000 (12:05 +0100)
When we open block devices as files we want to make sure to not charge
them against the open file limit of the caller as that can cause
spurious failures.

Link: https://lore.kernel.org/r/20240123-vfs-bdev-file-v2-1-adbd023e19cc@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/file_table.c
include/linux/file.h

index a94adac3d907591694f64b23b02c604de35ea914..6925522faa0ae53cb9105eaaed56c6a7fcdb305a 100644 (file)
@@ -357,6 +357,30 @@ struct file *alloc_file_pseudo(struct inode *inode, struct vfsmount *mnt,
 }
 EXPORT_SYMBOL(alloc_file_pseudo);
 
+struct file *alloc_file_pseudo_noaccount(struct inode *inode,
+                                        struct vfsmount *mnt, const char *name,
+                                        int flags,
+                                        const struct file_operations *fops)
+{
+       int ret;
+       struct path path;
+       struct file *file;
+
+       ret = alloc_path_pseudo(name, inode, mnt, &path);
+       if (ret)
+               return ERR_PTR(ret);
+
+       file = alloc_empty_file_noaccount(flags, current_cred());
+       if (IS_ERR(file)) {
+               ihold(inode);
+               path_put(&path);
+               return file;
+       }
+       file_init_path(file, &path, fops);
+       return file;
+}
+EXPORT_SYMBOL_GPL(alloc_file_pseudo_noaccount);
+
 struct file *alloc_file_clone(struct file *base, int flags,
                                const struct file_operations *fops)
 {
index 6834a29338c43c3370640a3432c98b606313cfb3..169692cb1906d8015cca7b854c1eaeedb3db09e2 100644 (file)
@@ -24,6 +24,8 @@ struct inode;
 struct path;
 extern struct file *alloc_file_pseudo(struct inode *, struct vfsmount *,
        const char *, int flags, const struct file_operations *);
+extern struct file *alloc_file_pseudo_noaccount(struct inode *, struct vfsmount *,
+       const char *, int flags, const struct file_operations *);
 extern struct file *alloc_file_clone(struct file *, int flags,
        const struct file_operations *);