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 3/3] ext4: show orphan file inode detail info
Date: Fri, 3 Apr 2026 16:25:07 +0800 [thread overview]
Message-ID: <20260403082507.1882703-4-yebin@huaweicloud.com> (raw)
In-Reply-To: <20260403082507.1882703-1-yebin@huaweicloud.com>
From: Ye Bin <yebin10@huawei.com>
Support show inode information in orphan file.
Signed-off-by: Ye Bin <yebin10@huawei.com>
---
fs/ext4/orphan.c | 115 ++++++++++++++++++++++++++++++++++++++---------
1 file changed, 94 insertions(+), 21 deletions(-)
diff --git a/fs/ext4/orphan.c b/fs/ext4/orphan.c
index 272de32d1a47..c01887fb496b 100644
--- a/fs/ext4/orphan.c
+++ b/fs/ext4/orphan.c
@@ -663,6 +663,11 @@ int ext4_orphan_file_empty(struct super_block *sb)
struct ext4_proc_orphan {
struct ext4_inode_info cursor;
bool print_title;
+ struct ext4_orphan_info *oi;
+ int inodes_per_ob;
+ int block_idx;
+ int offset;
+ bool orphan_file;
};
static inline bool ext4_is_cursor(struct ext4_inode_info *inode)
@@ -683,24 +688,65 @@ static struct inode *ext4_list_next(struct list_head *head, struct list_head *p)
return NULL;
}
+static struct inode *ext4_orphan_file_next(struct ext4_proc_orphan *s,
+ struct super_block *sb)
+{
+ struct inode *inode;
+ struct ext4_orphan_info *oi = s->oi;
+
+ for (; s->block_idx < oi->of_blocks; s->block_idx++) {
+ __le32 *bdata = (__le32 *)(oi->of_binfo[s->block_idx].ob_bh->b_data);
+
+ if (atomic_read(&oi->of_binfo[s->block_idx].ob_free_entries) ==
+ s->inodes_per_ob) {
+ s->offset = 0;
+ continue;
+ }
+ for (; s->offset < s->inodes_per_ob; s->offset++) {
+ if (!bdata[s->offset])
+ continue;
+ inode = ext4_iget(sb, le32_to_cpu(bdata[s->offset]),
+ EXT4_IGET_NORMAL);
+ if (IS_ERR(inode))
+ continue;
+ s->offset++;
+ return inode;
+ }
+ s->offset = 0;
+ }
+
+ 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;
+ void *ret;
- mutex_lock(&sbi->s_orphan_lock);
+ if (!s->orphan_file) {
+ mutex_lock(&sbi->s_orphan_lock);
+ if (!*pos)
+ prev = &sbi->s_orphan;
+ else
+ prev = &s->cursor.i_orphan;
- if (!*pos) {
- prev = &sbi->s_orphan;
- } else {
- prev = &s->cursor.i_orphan;
- if (list_empty(prev))
+ if (!list_empty(prev)) {
+ ret = ext4_list_next(&sbi->s_orphan, prev);
+ if (ret)
+ return ret;
+ }
+
+ if (!s->oi)
return NULL;
+ list_del_init(&s->cursor.i_orphan);
+ mutex_unlock(&sbi->s_orphan_lock);
+ s->orphan_file = true;
}
- return ext4_list_next(&sbi->s_orphan, prev);
+ return ext4_orphan_file_next(s, sb);
}
static void *ext4_orphan_seq_next(struct seq_file *seq, void *v, loff_t *pos)
@@ -708,10 +754,26 @@ static void *ext4_orphan_seq_next(struct seq_file *seq, void *v, loff_t *pos)
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;
+ void *ret;
++*pos;
- return ext4_list_next(&sbi->s_orphan, &EXT4_I(inode)->i_orphan);
+ if (!s->orphan_file) {
+ ret = ext4_list_next(&sbi->s_orphan, &EXT4_I(inode)->i_orphan);
+ if (ret)
+ return ret;
+ if (!s->oi)
+ return NULL;
+ list_del_init(&s->cursor.i_orphan);
+ mutex_unlock(&sbi->s_orphan_lock);
+ s->orphan_file = true;
+ v = NULL;
+ }
+
+ iput(v);
+
+ return ext4_orphan_file_next(s, sb);
}
static void ext4_show_filename(struct seq_file *seq, struct inode *inode)
@@ -758,12 +820,16 @@ static void ext4_orphan_seq_stop(struct seq_file *seq, void *v)
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);
+ if (!s->orphan_file) {
+ 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);
+ mutex_unlock(&sbi->s_orphan_lock);
+ } else {
+ iput(v);
+ }
}
const struct seq_operations ext4_orphan_seq_ops = {
@@ -777,16 +843,21 @@ static int ext4_seq_orphan_open(struct inode *inode, struct file *file)
{
int rc;
struct seq_file *m;
- struct ext4_proc_orphan *private;
+ struct ext4_proc_orphan *s;
rc = seq_open_private(file, &ext4_orphan_seq_ops,
sizeof(struct ext4_proc_orphan));
if (!rc) {
+ struct super_block *sb = pde_data(file_inode(file));
m = file->private_data;
- private = m->private;
- INIT_LIST_HEAD(&private->cursor.i_orphan);
- private->cursor.vfs_inode.i_ino = 0;
- private->print_title = true;
+ s = m->private;
+ INIT_LIST_HEAD(&s->cursor.i_orphan);
+ s->cursor.vfs_inode.i_ino = 0;
+ s->print_title = true;
+ if (ext4_has_feature_orphan_file(sb)) {
+ s->oi = &EXT4_SB(sb)->s_orphan_info;
+ s->inodes_per_ob = ext4_inodes_per_orphan_block(sb);
+ }
}
return rc;
@@ -798,9 +869,11 @@ static int ext4_seq_orphan_release(struct inode *inode, struct file *file)
struct ext4_proc_orphan *s = seq->private;
struct ext4_sb_info *sbi = EXT4_SB(pde_data(inode));
- mutex_lock(&sbi->s_orphan_lock);
- list_del(&s->cursor.i_orphan);
- mutex_unlock(&sbi->s_orphan_lock);
+ if (!s->orphan_file) {
+ mutex_lock(&sbi->s_orphan_lock);
+ list_del(&s->cursor.i_orphan);
+ mutex_unlock(&sbi->s_orphan_lock);
+ }
return seq_release_private(inode, file);
}
--
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 ` [PATCH 2/3] ext4: show inode orphan list detail information Ye Bin
2026-04-03 16:22 ` Andreas Dilger
2026-04-03 8:25 ` Ye Bin [this message]
2026-04-03 13:03 ` [PATCH 0/3] show orphan file inode detail info 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-4-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