Files
stambha/third_party/patches/linux/0120-link-original-final.patch
T

146 lines
4.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tyler Smith <74526874+tylertms@users.noreply.github.com>
Date: Wed, 4 Nov 2026 03:48:17 +0000
Subject: [PATCH] refactor(vfs): link original final file release
---
fs/file_table.c | 44 --------------------------------------------
fs/filp_close.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
fs/internal.h | 1 +
3 files changed, 50 insertions(+), 44 deletions(-)
diff --git a/fs/file_table.c b/fs/file_table.c
index 07026234868f555cd1c14bb4df9770b41ee8472c..880a985b1e9dc2e5c90d6e37d1db4758b76acc4d 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -232,50 +232,6 @@ struct file *alloc_file_clone(struct file *base, int flags,
return f;
}
-/* the real guts of fput() - releasing the last reference to file
- */
-static void __fput(struct file *file)
-{
- struct dentry *dentry = file->f_path.dentry;
- struct vfsmount *mnt = file->f_path.mnt;
- struct inode *inode = file->f_inode;
- fmode_t mode = file->f_mode;
-
- if (unlikely(!(file->f_mode & FMODE_OPENED)))
- goto out;
-
- might_sleep();
-
- fsnotify_close(file);
- /*
- * The function eventpoll_release() should be the first called
- * in the file cleanup chain.
- */
- eventpoll_release(file);
- locks_remove_file(file);
-
- security_file_release(file);
- if (unlikely(file->f_flags & FASYNC)) {
- if (file->f_op->fasync)
- file->f_op->fasync(-1, file, 0);
- }
- if (file->f_op->release)
- file->f_op->release(inode, file);
- if (unlikely(S_ISCHR(inode->i_mode) && inode->i_cdev != NULL &&
- !(mode & FMODE_PATH))) {
- cdev_put(inode->i_cdev);
- }
- fops_put(file->f_op);
- file_f_owner_release(file);
- put_file_access(file);
- dput(dentry);
- if (unlikely(mode & FMODE_NEED_UNMOUNT))
- dissolve_on_fput(mnt);
- mntput(mnt);
-out:
- file_free(file);
-}
-
static LLIST_HEAD(delayed_fput_list);
static void delayed_fput(struct work_struct *unused)
{
diff --git a/fs/filp_close.c b/fs/filp_close.c
index 80a260a12a668592baf4ef426afe47163f26cbdc..e1ee043fe5726e18bf43ab9ec36f7840a1201dcb 100644
--- a/fs/filp_close.c
+++ b/fs/filp_close.c
@@ -1,9 +1,14 @@
// SPDX-License-Identifier: GPL-2.0-only
+#include <linux/cdev.h>
#include <linux/dnotify.h>
+#include <linux/eventpoll.h>
#include <linux/export.h>
#include <linux/file.h>
#include <linux/filelock.h>
+#include <linux/fsnotify.h>
+#include <linux/mount.h>
+#include <linux/security.h>
#include "filp_close.h"
#include "internal.h"
@@ -42,3 +47,47 @@ int filp_close(struct file *filp, fl_owner_t id)
return retval;
}
EXPORT_SYMBOL(filp_close);
+
+/* the real guts of fput() - releasing the last reference to file
+ */
+void __fput(struct file *file)
+{
+ struct dentry *dentry = file->f_path.dentry;
+ struct vfsmount *mnt = file->f_path.mnt;
+ struct inode *inode = file->f_inode;
+ fmode_t mode = file->f_mode;
+
+ if (unlikely(!(file->f_mode & FMODE_OPENED)))
+ goto out;
+
+ might_sleep();
+
+ fsnotify_close(file);
+ /*
+ * The function eventpoll_release() should be the first called
+ * in the file cleanup chain.
+ */
+ eventpoll_release(file);
+ locks_remove_file(file);
+
+ security_file_release(file);
+ if (unlikely(file->f_flags & FASYNC)) {
+ if (file->f_op->fasync)
+ file->f_op->fasync(-1, file, 0);
+ }
+ if (file->f_op->release)
+ file->f_op->release(inode, file);
+ if (unlikely(S_ISCHR(inode->i_mode) && inode->i_cdev != NULL &&
+ !(mode & FMODE_PATH))) {
+ cdev_put(inode->i_cdev);
+ }
+ fops_put(file->f_op);
+ file_f_owner_release(file);
+ put_file_access(file);
+ dput(dentry);
+ if (unlikely(mode & FMODE_NEED_UNMOUNT))
+ dissolve_on_fput(mnt);
+ mntput(mnt);
+out:
+ file_free(file);
+}
diff --git a/fs/internal.h b/fs/internal.h
index b9b84f977925b481a95ba2a16292c1a6969433d1..674be88712505034d948433eb948cca18f44cd6c 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -106,6 +106,7 @@ extern void chroot_fs_refs(const struct path *, const struct path *);
*/
struct file *alloc_empty_file(int flags, const struct cred *cred);
void file_free(struct file *file);
+void __fput(struct file *file);
struct file *alloc_empty_file_noaccount(int flags, const struct cred *cred);
struct file *alloc_empty_backing_file(int flags, const struct cred *cred,
const struct file *user_file);