221 lines
5.5 KiB
Diff
221 lines
5.5 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Tyler Smith <74526874+tylertms@users.noreply.github.com>
|
|
Date: Tue, 3 Nov 2026 18:33:43 +0000
|
|
Subject: [PATCH] refactor(fs): link original inode allocation and retirement
|
|
|
|
---
|
|
fs/inode.c | 75 +++----------------------------------------
|
|
fs/inode_cache_init.c | 68 +++++++++++++++++++++++++++++++++++++++
|
|
fs/internal.h | 1 +
|
|
3 files changed, 73 insertions(+), 71 deletions(-)
|
|
|
|
diff --git a/fs/inode.c b/fs/inode.c
|
|
index 7ef26389701e6ee1426966e02e0117319fcf78ec..91c206010aefa3eab43aaebcb0f52f07ec424722 100644
|
|
--- a/fs/inode.c
|
|
+++ b/fs/inode.c
|
|
@@ -121,73 +121,6 @@ late_initcall(mg_debugfs_init);
|
|
|
|
#endif /* CONFIG_DEBUG_FS */
|
|
|
|
-void free_inode_nonrcu(struct inode *inode)
|
|
-{
|
|
- kmem_cache_free(inode_cachep, inode);
|
|
-}
|
|
-EXPORT_SYMBOL(free_inode_nonrcu);
|
|
-
|
|
-static void i_callback(struct rcu_head *head)
|
|
-{
|
|
- struct inode *inode = container_of(head, struct inode, i_rcu);
|
|
- if (inode->free_inode)
|
|
- inode->free_inode(inode);
|
|
- else
|
|
- free_inode_nonrcu(inode);
|
|
-}
|
|
-
|
|
-/**
|
|
- * alloc_inode - obtain an inode
|
|
- * @sb: superblock
|
|
- *
|
|
- * Allocates a new inode for given superblock.
|
|
- * Inode wont be chained in superblock s_inodes list
|
|
- * This means :
|
|
- * - fs can't be unmount
|
|
- * - quotas, fsnotify, writeback can't work
|
|
- */
|
|
-struct inode *alloc_inode(struct super_block *sb)
|
|
-{
|
|
- const struct super_operations *ops = sb->s_op;
|
|
- struct inode *inode;
|
|
-
|
|
- if (ops->alloc_inode)
|
|
- inode = ops->alloc_inode(sb);
|
|
- else
|
|
- inode = alloc_inode_sb(sb, inode_cachep, GFP_KERNEL);
|
|
-
|
|
- if (!inode)
|
|
- return NULL;
|
|
-
|
|
- if (unlikely(inode_init_always(sb, inode))) {
|
|
- if (ops->destroy_inode) {
|
|
- ops->destroy_inode(inode);
|
|
- if (!ops->free_inode)
|
|
- return NULL;
|
|
- }
|
|
- inode->free_inode = ops->free_inode;
|
|
- i_callback(&inode->i_rcu);
|
|
- return NULL;
|
|
- }
|
|
-
|
|
- return inode;
|
|
-}
|
|
-
|
|
-static void destroy_inode(struct inode *inode)
|
|
-{
|
|
- const struct super_operations *ops = inode->i_sb->s_op;
|
|
-
|
|
- BUG_ON(!list_empty(&inode->i_lru));
|
|
- __destroy_inode(inode);
|
|
- if (ops->destroy_inode) {
|
|
- ops->destroy_inode(inode);
|
|
- if (!ops->free_inode)
|
|
- return;
|
|
- }
|
|
- inode->free_inode = ops->free_inode;
|
|
- call_rcu(&inode->i_rcu, i_callback);
|
|
-}
|
|
-
|
|
static void inode_pin_lru_isolating(struct inode *inode)
|
|
{
|
|
lockdep_assert_held(&inode->i_lock);
|
|
@@ -400,7 +333,7 @@ static void evict(struct inode *inode)
|
|
inode_wake_up_bit(inode, __I_NEW);
|
|
BUG_ON(inode_state_read_once(inode) != (I_FREEING | I_CLEAR));
|
|
|
|
- destroy_inode(inode);
|
|
+ inode_destroy(inode);
|
|
}
|
|
|
|
/*
|
|
@@ -856,7 +789,7 @@ struct inode *iget5_locked(struct super_block *sb, u64 hashval,
|
|
if (new) {
|
|
inode = inode_insert5(new, hashval, test, set, data);
|
|
if (unlikely(inode != new))
|
|
- destroy_inode(new);
|
|
+ inode_destroy(new);
|
|
}
|
|
}
|
|
return inode;
|
|
@@ -902,7 +835,7 @@ again:
|
|
if (new) {
|
|
inode = inode_insert5(new, hashval, test, set, data);
|
|
if (unlikely(inode != new))
|
|
- destroy_inode(new);
|
|
+ inode_destroy(new);
|
|
}
|
|
return inode;
|
|
}
|
|
@@ -971,7 +904,7 @@ again:
|
|
* allocated.
|
|
*/
|
|
spin_unlock(&inode_hash_lock);
|
|
- destroy_inode(inode);
|
|
+ inode_destroy(inode);
|
|
if (IS_ERR(old))
|
|
return NULL;
|
|
inode = old;
|
|
diff --git a/fs/inode_cache_init.c b/fs/inode_cache_init.c
|
|
index 442074ed633a44a2f837dd5266715cb7d8604925..45941341f04f8cb250c8f6428b1761d42be40dfb 100644
|
|
--- a/fs/inode_cache_init.c
|
|
+++ b/fs/inode_cache_init.c
|
|
@@ -13,6 +13,7 @@
|
|
#include <linux/memblock.h>
|
|
#include <linux/pagemap.h>
|
|
#include <linux/posix_acl.h>
|
|
+#include <linux/rcupdate.h>
|
|
#include <linux/rw_hint.h>
|
|
#include <linux/security.h>
|
|
#include <linux/slab.h>
|
|
@@ -386,3 +387,70 @@ unsigned int get_next_ino(void)
|
|
return res;
|
|
}
|
|
EXPORT_SYMBOL(get_next_ino);
|
|
+
|
|
+void free_inode_nonrcu(struct inode *inode)
|
|
+{
|
|
+ kmem_cache_free(inode_cachep, inode);
|
|
+}
|
|
+EXPORT_SYMBOL(free_inode_nonrcu);
|
|
+
|
|
+static void i_callback(struct rcu_head *head)
|
|
+{
|
|
+ struct inode *inode = container_of(head, struct inode, i_rcu);
|
|
+ if (inode->free_inode)
|
|
+ inode->free_inode(inode);
|
|
+ else
|
|
+ free_inode_nonrcu(inode);
|
|
+}
|
|
+
|
|
+/**
|
|
+ * alloc_inode - obtain an inode
|
|
+ * @sb: superblock
|
|
+ *
|
|
+ * Allocates a new inode for given superblock.
|
|
+ * Inode wont be chained in superblock s_inodes list
|
|
+ * This means :
|
|
+ * - fs can't be unmount
|
|
+ * - quotas, fsnotify, writeback can't work
|
|
+ */
|
|
+struct inode *alloc_inode(struct super_block *sb)
|
|
+{
|
|
+ const struct super_operations *ops = sb->s_op;
|
|
+ struct inode *inode;
|
|
+
|
|
+ if (ops->alloc_inode)
|
|
+ inode = ops->alloc_inode(sb);
|
|
+ else
|
|
+ inode = alloc_inode_sb(sb, inode_cachep, GFP_KERNEL);
|
|
+
|
|
+ if (!inode)
|
|
+ return NULL;
|
|
+
|
|
+ if (unlikely(inode_init_always(sb, inode))) {
|
|
+ if (ops->destroy_inode) {
|
|
+ ops->destroy_inode(inode);
|
|
+ if (!ops->free_inode)
|
|
+ return NULL;
|
|
+ }
|
|
+ inode->free_inode = ops->free_inode;
|
|
+ i_callback(&inode->i_rcu);
|
|
+ return NULL;
|
|
+ }
|
|
+
|
|
+ return inode;
|
|
+}
|
|
+
|
|
+void inode_destroy(struct inode *inode)
|
|
+{
|
|
+ const struct super_operations *ops = inode->i_sb->s_op;
|
|
+
|
|
+ BUG_ON(!list_empty(&inode->i_lru));
|
|
+ __destroy_inode(inode);
|
|
+ if (ops->destroy_inode) {
|
|
+ ops->destroy_inode(inode);
|
|
+ if (!ops->free_inode)
|
|
+ return;
|
|
+ }
|
|
+ inode->free_inode = ops->free_inode;
|
|
+ call_rcu(&inode->i_rcu, i_callback);
|
|
+}
|
|
diff --git a/fs/internal.h b/fs/internal.h
|
|
index 2f4c9a4053a0185142a743567c562a288de137d8..4812ff99bc19a612a7e6d9a4596de7b5120ce85c 100644
|
|
--- a/fs/internal.h
|
|
+++ b/fs/internal.h
|
|
@@ -224,6 +224,7 @@ bool in_group_or_capable(struct mnt_idmap *idmap,
|
|
* fs-writeback.c
|
|
*/
|
|
long get_nr_dirty_inodes(void);
|
|
+void inode_destroy(struct inode *inode);
|
|
extern const struct inode_operations bad_inode_ops;
|
|
bool sync_lazytime(struct inode *inode);
|
|
|