Files
stambha/third_party/patches/linux/0118-link-original-file.patch
T

220 lines
6.4 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:37:44 +0000
Subject: [PATCH] refactor(vfs): link original file lifetime helpers
---
fs/fcntl.c | 11 -----------
fs/file_table.c | 6 ------
fs/file_table_init.c | 20 ++++++++++++++++++++
fs/mount_cache.c | 30 ++++++++++++++++++++++++++++++
fs/namespace.c | 30 ------------------------------
mm/backing-dev-inode.c | 13 +++++++++++++
mm/readahead.c | 12 ------------
7 files changed, 63 insertions(+), 59 deletions(-)
diff --git a/fs/fcntl.c b/fs/fcntl.c
index 9b71bc9d71d1591c16ed106384d6f07a18883d05..d3c3ceb2e4c6d9a26bd7836e814626ba66e2c327 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -113,17 +113,6 @@ int file_f_owner_allocate(struct file *file)
}
EXPORT_SYMBOL(file_f_owner_allocate);
-void file_f_owner_release(struct file *file)
-{
- struct fown_struct *f_owner;
-
- f_owner = file_f_owner(file);
- if (f_owner) {
- put_pid(f_owner->pid);
- kfree(f_owner);
- }
-}
-
void __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
int force)
{
diff --git a/fs/file_table.c b/fs/file_table.c
index 87ee96b31b39a40bfdb19862449e62e66751db3b..fc10fe2b6367f16a3aee810d587f6bd9b0d30f46 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -40,12 +40,6 @@
#define backing_file(f) container_of(f, struct backing_file, file)
-const struct path *backing_file_user_path(const struct file *f)
-{
- return &backing_file(f)->user_path;
-}
-EXPORT_SYMBOL_GPL(backing_file_user_path);
-
void backing_file_set_user_path(struct file *f, const struct path *path)
{
backing_file(f)->user_path = *path;
diff --git a/fs/file_table_init.c b/fs/file_table_init.c
index c17be024af45dcebf8ba2441cad4e9b5aedcd1e2..4a8f467ce24da86770f367008110f3b9ba83d62e 100644
--- a/fs/file_table_init.c
+++ b/fs/file_table_init.c
@@ -6,6 +6,7 @@
*/
#include <linux/export.h>
#include <linux/fs.h>
+#include <linux/pid.h>
#include <linux/slab.h>
#include <linux/swap.h>
#include <asm/runtime-const.h>
@@ -15,6 +16,7 @@
#endif
#include "file_table_init.h"
+#include "internal.h"
/* sysctl tunables... */
struct files_stat_struct files_stat = {
@@ -80,3 +82,21 @@ void __init files_maxfiles_init(void)
files_stat.max_files = max_t(unsigned long, n, NR_FILE);
}
+
+const struct path *backing_file_user_path(const struct file *f)
+{
+ return &container_of(f, struct backing_file, file)->user_path;
+}
+EXPORT_SYMBOL_GPL(backing_file_user_path);
+
+/* Final file owner release from fs/fcntl.c. */
+void file_f_owner_release(struct file *file)
+{
+ struct fown_struct *f_owner;
+
+ f_owner = file_f_owner(file);
+ if (f_owner) {
+ put_pid(f_owner->pid);
+ kfree(f_owner);
+ }
+}
diff --git a/fs/mount_cache.c b/fs/mount_cache.c
index 9fca33e3e877a2acda46b3efb820feff62ca8c2b..5873d2e8b6f562076f37ea5c1d860734a1b9184f 100644
--- a/fs/mount_cache.c
+++ b/fs/mount_cache.c
@@ -1407,3 +1407,33 @@ struct mnt_namespace *get_sequential_mnt_ns(struct mnt_namespace *mntns, bool pr
return mntns;
}
}
+
+void dissolve_on_fput(struct vfsmount *mnt)
+{
+ struct mount *m = real_mount(mnt);
+
+ /*
+ * m used to be the root of anon namespace; if it still is one,
+ * we need to dissolve the mount tree and free that namespace.
+ * Let's try to avoid taking namespace_sem if we can determine
+ * that there's nothing to do without it - rcu_read_lock() is
+ * enough to make anon_ns_root() memory-safe and once m has
+ * left its namespace, it's no longer our concern, since it will
+ * never become a root of anon ns again.
+ */
+
+ scoped_guard(rcu) {
+ if (!anon_ns_root(m))
+ return;
+ }
+
+ scoped_guard(namespace_excl) {
+ if (!anon_ns_root(m))
+ return;
+
+ emptied_ns = m->mnt_ns;
+ lock_mount_hash();
+ umount_tree(m, UMOUNT_CONNECTED);
+ unlock_mount_hash();
+ }
+}
diff --git a/fs/namespace.c b/fs/namespace.c
index 496029e0c11179373c6ae789d17813a57246f716..5b88decc5867fc81d840147b51c0bdfab29706be 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -931,36 +931,6 @@ void drop_collected_paths(const struct path *paths, const struct path *prealloc)
static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *, bool);
-void dissolve_on_fput(struct vfsmount *mnt)
-{
- struct mount *m = real_mount(mnt);
-
- /*
- * m used to be the root of anon namespace; if it still is one,
- * we need to dissolve the mount tree and free that namespace.
- * Let's try to avoid taking namespace_sem if we can determine
- * that there's nothing to do without it - rcu_read_lock() is
- * enough to make anon_ns_root() memory-safe and once m has
- * left its namespace, it's no longer our concern, since it will
- * never become a root of anon ns again.
- */
-
- scoped_guard(rcu) {
- if (!anon_ns_root(m))
- return;
- }
-
- scoped_guard(namespace_excl) {
- if (!anon_ns_root(m))
- return;
-
- emptied_ns = m->mnt_ns;
- lock_mount_hash();
- umount_tree(m, UMOUNT_CONNECTED);
- unlock_mount_hash();
- }
-}
-
/* locks: namespace_shared && pinned(mnt) || mount_locked_reader */
static bool __has_locked_children(struct mount *mnt, struct dentry *dentry)
{
diff --git a/mm/backing-dev-inode.c b/mm/backing-dev-inode.c
index 54eb2ae6e1c9d15594d3118b742abe20007143b3..ae4cda37b488747bf0b004f1bf3a5f017feb2015 100644
--- a/mm/backing-dev-inode.c
+++ b/mm/backing-dev-inode.c
@@ -35,3 +35,16 @@ int __init bdi_init_writeback_workqueue(void)
return -ENOMEM;
return 0;
}
+
+/* From mm/readahead.c. */
+/*
+ * Initialise a struct file's readahead state. Assumes that the caller has
+ * memset *ra to zero.
+ */
+void
+file_ra_state_init(struct file_ra_state *ra, struct address_space *mapping)
+{
+ ra->ra_pages = inode_to_bdi(mapping->host)->ra_pages;
+ ra->prev_pos = -1;
+}
+EXPORT_SYMBOL_GPL(file_ra_state_init);
diff --git a/mm/readahead.c b/mm/readahead.c
index 558c92957518b7b7f148f12ee22259d576f29dcb..9f119a16d17c657fdf1783bf18d56a815d2d4af4 100644
--- a/mm/readahead.c
+++ b/mm/readahead.c
@@ -134,18 +134,6 @@
#include "internal.h"
-/*
- * Initialise a struct file's readahead state. Assumes that the caller has
- * memset *ra to zero.
- */
-void
-file_ra_state_init(struct file_ra_state *ra, struct address_space *mapping)
-{
- ra->ra_pages = inode_to_bdi(mapping->host)->ra_pages;
- ra->prev_pos = -1;
-}
-EXPORT_SYMBOL_GPL(file_ra_state_init);
-
/**
* read_pages() - Start IO for a contiguous range of allocated folios in the
* page cache.