From: Ye Bin <yebin@huaweicloud.com>
To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org
Cc: jack@suse.cz
Subject: [PATCH 2/3] ext4: show inode orphan list detail information
Date: Fri, 3 Apr 2026 16:25:06 +0800 [thread overview]
Message-ID: <20260403082507.1882703-3-yebin@huaweicloud.com> (raw)
In-Reply-To: <20260403082507.1882703-1-yebin@huaweicloud.com>
From: Ye Bin <yebin10@huawei.com>
Some inodes added to the orphan list are due to truncation, while others
are due to deletion.Therefore, we printed the information of inode as
follows: inode number/i_nlink/i_size/i_blocks/projid/file path. By using
this information, it is possible to quickly identify files that have been
deleted but are still being referenced.
Signed-off-by: Ye Bin <yebin10@huawei.com>
---
fs/ext4/orphan.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 86 insertions(+), 2 deletions(-)
diff --git a/fs/ext4/orphan.c b/fs/ext4/orphan.c
index 1d231aeaf282..272de32d1a47 100644
--- a/fs/ext4/orphan.c
+++ b/fs/ext4/orphan.c
@@ -662,25 +662,108 @@ int ext4_orphan_file_empty(struct super_block *sb)
struct ext4_proc_orphan {
struct ext4_inode_info cursor;
+ bool print_title;
};
-static void *ext4_orphan_seq_start(struct seq_file *seq, loff_t *pos)
+static inline bool ext4_is_cursor(struct ext4_inode_info *inode)
+{
+ return (inode->vfs_inode.i_ino == 0);
+}
+
+static struct inode *ext4_list_next(struct list_head *head, struct list_head *p)
{
+ struct ext4_inode_info *inode;
+
+ list_for_each_continue(p, head) {
+ inode = list_entry(p, typeof(*inode), i_orphan);
+ if (!ext4_is_cursor(inode))
+ return &inode->vfs_inode;
+ }
+
return NULL;
}
+static void *ext4_orphan_seq_start(struct seq_file *seq, loff_t *pos)
+{
+ struct ext4_proc_orphan *s = seq->private;
+ struct super_block *sb = pde_data(file_inode(seq->file));
+ struct ext4_sb_info *sbi = EXT4_SB(sb);
+ struct list_head *prev;
+
+ mutex_lock(&sbi->s_orphan_lock);
+
+ if (!*pos) {
+ prev = &sbi->s_orphan;
+ } else {
+ prev = &s->cursor.i_orphan;
+ if (list_empty(prev))
+ return NULL;
+ }
+
+ return ext4_list_next(&sbi->s_orphan, prev);
+}
+
static void *ext4_orphan_seq_next(struct seq_file *seq, void *v, loff_t *pos)
{
- return NULL;
+ struct super_block *sb = pde_data(file_inode(seq->file));
+ struct ext4_sb_info *sbi = EXT4_SB(sb);
+ struct inode *inode = v;
+
+ ++*pos;
+
+ return ext4_list_next(&sbi->s_orphan, &EXT4_I(inode)->i_orphan);
+}
+
+static void ext4_show_filename(struct seq_file *seq, struct inode *inode)
+{
+ struct dentry *dentry;
+
+ dentry = d_find_alias(inode);
+ if (!dentry)
+ dentry = d_find_any_alias(inode);
+
+ if (dentry)
+ seq_dentry(seq, dentry, "\t\n\\");
+ else
+ seq_puts(seq, "unknown");
+
+ dput(dentry);
+ seq_putc(seq, '\n');
}
static int ext4_orphan_seq_show(struct seq_file *seq, void *v)
{
+ struct inode *inode = v;
+ struct ext4_proc_orphan *s = seq->private;
+
+ if (s->print_title) {
+ seq_puts(seq, "INO\tNLINK\tSIZE\tBLOCKS\tPROJID\tPATH\n");
+ s->print_title = false;
+ }
+
+ seq_printf(seq, "%llu\t%u\t%llu\t%llu\t%u\t",
+ inode->i_ino, inode->i_nlink,
+ i_size_read(inode), inode->i_blocks,
+ __kprojid_val(EXT4_I(inode)->i_projid));
+
+ ext4_show_filename(seq, inode);
+
return 0;
}
static void ext4_orphan_seq_stop(struct seq_file *seq, void *v)
{
+ struct super_block *sb = pde_data(file_inode(seq->file));
+ struct ext4_sb_info *sbi = EXT4_SB(sb);
+ struct inode *inode = v;
+ struct ext4_proc_orphan *s = seq->private;
+
+ if (inode)
+ list_move_tail(&s->cursor.i_orphan, &EXT4_I(inode)->i_orphan);
+ else
+ list_del_init(&s->cursor.i_orphan);
+
+ mutex_unlock(&sbi->s_orphan_lock);
}
const struct seq_operations ext4_orphan_seq_ops = {
@@ -703,6 +786,7 @@ static int ext4_seq_orphan_open(struct inode *inode, struct file *file)
private = m->private;
INIT_LIST_HEAD(&private->cursor.i_orphan);
private->cursor.vfs_inode.i_ino = 0;
+ private->print_title = true;
}
return rc;
--
2.34.1
next prev parent reply other threads:[~2026-04-03 8:27 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-03 8:25 [PATCH 0/3] show orphan file inode detail info Ye Bin
2026-04-03 8:25 ` [PATCH 1/3] ext4: register 'orphan_list' procfs Ye Bin
2026-04-03 12:55 ` Theodore Tso
2026-04-03 8:25 ` Ye Bin [this message]
2026-04-03 16:22 ` [PATCH 2/3] ext4: show inode orphan list detail information Andreas Dilger
2026-04-03 8:25 ` [PATCH 3/3] ext4: show orphan file inode detail info Ye Bin
2026-04-03 13:03 ` [PATCH 0/3] " Theodore Tso
2026-04-07 10:29 ` Jan Kara
2026-04-07 20:28 ` Theodore Tso
2026-04-08 13:36 ` Jan Kara
2026-04-09 2:51 ` Theodore Tso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260403082507.1882703-3-yebin@huaweicloud.com \
--to=yebin@huaweicloud.com \
--cc=adilger.kernel@dilger.ca \
--cc=jack@suse.cz \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox