From: Ye Bin This patch is prepared for displaying orphan_list information. Because temporary nodes may be inserted when the orphan_list is traversed and displayed, these temporary nodes need to be skipped. Signed-off-by: Ye Bin --- fs/ext4/orphan.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/fs/ext4/orphan.c b/fs/ext4/orphan.c index f7e7f77e021e..a6bffe67ef75 100644 --- a/fs/ext4/orphan.c +++ b/fs/ext4/orphan.c @@ -220,6 +220,23 @@ static int ext4_orphan_file_del(handle_t *handle, struct inode *inode) return ret; } +static inline bool ext4_is_cursor(struct inode *inode) +{ + return (inode->i_ino == 0); +} + +static inline struct list_head *ext4_orphan_prev_node( + struct ext4_inode_info *pos, + struct list_head *head) +{ + list_for_each_entry_continue_reverse(pos, head, i_orphan) { + if (likely(!ext4_is_cursor(&pos->vfs_inode))) + return &pos->i_orphan; + } + + return head; +} + /* * ext4_orphan_del() removes an unlinked or truncated inode from the list * of such inodes stored on disk, because it is finally being cleaned up. @@ -253,7 +270,8 @@ int ext4_orphan_del(handle_t *handle, struct inode *inode) mutex_lock(&sbi->s_orphan_lock); ext4_debug("remove inode %llu from orphan list\n", inode->i_ino); - prev = ei->i_orphan.prev; + prev = ext4_orphan_prev_node(ei, &sbi->s_orphan); + list_del_init(&ei->i_orphan); /* If we're on an error path, we may not have a valid -- 2.34.1