[PATCH v3] xfs: Use for_each_perag() to iterate all available AGs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



xfs_filestream_pick_ag() iterates all available AGs when no
unassociated AGs are available by using for_each_perag_wrap().
To iterate all the available AGs, just use for_each_perag() instead.

Also, create xfs_perag_get_first_avail(). It encapslate the iteration
since it is common operation.

Chnages since v2 [1]:
Use for_each_perag() to iterate all available AGs.
Encapsulate these operations into xfs_perag_get_first_avail().
Set err to zero in its declaration.

[1] https://lore.kernel.org/linux-xfs/20230410160727.3748239-1-ryasuoka@xxxxxxxxxx/raw

Signed-off-by: Ryosuke Yasuoka <ryasuoka@xxxxxxxxxx>
---
 fs/xfs/xfs_filestream.c |  5 ++---
 fs/xfs/xfs_filestream.h | 16 ++++++++++++++++
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/fs/xfs/xfs_filestream.c b/fs/xfs/xfs_filestream.c
index 22c13933c8f8..66e0d74fe235 100644
--- a/fs/xfs/xfs_filestream.c
+++ b/fs/xfs/xfs_filestream.c
@@ -67,7 +67,7 @@ xfs_filestream_pick_ag(
 	xfs_extlen_t		free = 0, minfree, maxfree = 0;
 	xfs_agnumber_t		agno;
 	bool			first_pass = true;
-	int			err;
+	int			err = 0;
 
 	/* 2% of an AG's blocks must be free for it to be chosen. */
 	minfree = mp->m_sb.sb_agblocks / 50;
@@ -151,8 +151,7 @@ xfs_filestream_pick_ag(
 		 * grab.
 		 */
 		if (!max_pag) {
-			for_each_perag_wrap(args->mp, 0, start_agno, args->pag)
-				break;
+			args->pag = xfs_perag_get_first_avail(mp);
 			atomic_inc(&args->pag->pagf_fstrms);
 			*longest = 0;
 		} else {
diff --git a/fs/xfs/xfs_filestream.h b/fs/xfs/xfs_filestream.h
index 84149ed0e340..92faf84c287f 100644
--- a/fs/xfs/xfs_filestream.h
+++ b/fs/xfs/xfs_filestream.h
@@ -6,6 +6,8 @@
 #ifndef __XFS_FILESTREAM_H__
 #define __XFS_FILESTREAM_H__
 
+#include "xfs_ag.h"
+
 struct xfs_mount;
 struct xfs_inode;
 struct xfs_bmalloca;
@@ -25,4 +27,18 @@ xfs_inode_is_filestream(
 		(ip->i_diflags & XFS_DIFLAG_FILESTREAM);
 }
 
+static inline struct xfs_perag *
+xfs_perag_get_first_avail(
+		struct xfs_mount	*mp)
+{
+	struct xfs_perag	*pag;
+	xfs_agnumber_t		agno;
+
+	for_each_perag(mp, agno, pag)
+		return pag;
+
+	ASSERT(0);
+	return NULL;
+}
+
 #endif /* __XFS_FILESTREAM_H__ */
-- 
2.39.2




[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux