diff mbox series

[01/11] fs: introduce I_CURSOR flag for inode

Message ID 20241118114508.1405494-2-yebin@huaweicloud.com (mailing list archive)
State New
Headers show
Series fix hungtask due to repeated traversal of inodes list | expand

Commit Message

Ye Bin Nov. 18, 2024, 11:44 a.m. UTC
From: Ye Bin <yebin10@huawei.com>

This patch introduce I_CURSOR flag for inode and introduce
sb_for_each_inodes_safe/sb_for_each_inodes/sb_for_each_inodes_continue_safe
API for foreach super_block->s_inodes.

Signed-off-by: Ye Bin <yebin10@huawei.com>
---
 include/linux/fs.h | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
diff mbox series

Patch

diff --git a/include/linux/fs.h b/include/linux/fs.h
index 0a152c31d1bf..cf2734e0b2cd 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2473,6 +2473,7 @@  static inline void kiocb_clone(struct kiocb *kiocb, struct kiocb *kiocb_src,
 #define I_DONTCACHE		(1 << 15)
 #define I_SYNC_QUEUED		(1 << 16)
 #define I_PINNING_NETFS_WB	(1 << 17)
+#define I_CURSOR		(1 << 18)
 
 #define I_DIRTY_INODE (I_DIRTY_SYNC | I_DIRTY_DATASYNC)
 #define I_DIRTY (I_DIRTY_INODE | I_DIRTY_PAGES)
@@ -3809,4 +3810,48 @@  static inline bool vfs_empty_path(int dfd, const char __user *path)
 
 int generic_atomic_write_valid(struct kiocb *iocb, struct iov_iter *iter);
 
+static inline bool inode_is_cursor(struct inode *inode)
+{
+	return inode->i_state & I_CURSOR;
+}
+
+static inline struct inode *next_sb_inode(struct inode *pos,
+					  struct list_head *head)
+{
+	struct inode *inode;
+	struct list_head *start;
+
+	if (!pos)
+		return NULL;
+
+	start = &pos->i_sb_list;
+
+	list_for_each_continue(start, head) {
+		inode = list_entry(start, typeof(*inode), i_sb_list);
+		if (likely(!inode_is_cursor(inode)))
+			return inode;
+	}
+
+	return NULL;
+}
+
+#define sb_for_each_inodes_safe(pos, n, head)                 \
+	for (pos = list_entry(head, typeof(*pos), i_sb_list), \
+		pos = next_sb_inode(pos, head),               \
+		n = next_sb_inode(pos, head);                 \
+	     pos != NULL;                                     \
+	     pos = n, n = next_sb_inode(n, head))
+
+#define sb_for_each_inodes(pos, head)                          \
+	for (pos = list_entry(head, typeof(*pos), i_sb_list), \
+		pos = next_sb_inode(pos, head);                \
+	     pos != NULL;                                     \
+	     pos = next_sb_inode(pos, head))
+
+#define sb_for_each_inodes_continue_safe(pos, n, head)        \
+	for (pos = next_sb_inode(pos, head),                  \
+		n = next_sb_inode(pos, head);                 \
+	     pos != NULL;                                     \
+	     pos = n, n = next_sb_inode(n, head))
+
 #endif /* _LINUX_FS_H */