@@ -293,63 +293,66 @@ xfs_perag_clear_inode_tag(
293293}
294294
295295/*
296- * Search from @first to find the next perag with the given tag set .
296+ * Find the next AG after @pag, or the first AG if @pag is NULL .
297297 */
298298static struct xfs_perag *
299- xfs_perag_get_tag (
299+ xfs_perag_get_next_tag (
300300 struct xfs_mount * mp ,
301- xfs_agnumber_t first ,
301+ struct xfs_perag * pag ,
302302 unsigned int tag )
303303{
304- struct xfs_perag * pag ;
304+ unsigned long index = 0 ;
305305 int found ;
306306
307+ if (pag ) {
308+ index = pag -> pag_agno + 1 ;
309+ xfs_perag_rele (pag );
310+ }
311+
307312 rcu_read_lock ();
308313 found = radix_tree_gang_lookup_tag (& mp -> m_perag_tree ,
309- (void * * )& pag , first , 1 , tag );
314+ (void * * )& pag , index , 1 , tag );
310315 if (found <= 0 ) {
311316 rcu_read_unlock ();
312317 return NULL ;
313318 }
314- trace_xfs_perag_get_tag (pag , _RET_IP_ );
319+ trace_xfs_perag_get_next_tag (pag , _RET_IP_ );
315320 atomic_inc (& pag -> pag_ref );
316321 rcu_read_unlock ();
317322 return pag ;
318323}
319324
320325/*
321- * Search from @first to find the next perag with the given tag set .
326+ * Find the next AG after @pag, or the first AG if @pag is NULL .
322327 */
323328static struct xfs_perag *
324- xfs_perag_grab_tag (
329+ xfs_perag_grab_next_tag (
325330 struct xfs_mount * mp ,
326- xfs_agnumber_t first ,
331+ struct xfs_perag * pag ,
327332 int tag )
328333{
329- struct xfs_perag * pag ;
334+ unsigned long index = 0 ;
330335 int found ;
331336
337+ if (pag ) {
338+ index = pag -> pag_agno + 1 ;
339+ xfs_perag_rele (pag );
340+ }
341+
332342 rcu_read_lock ();
333343 found = radix_tree_gang_lookup_tag (& mp -> m_perag_tree ,
334- (void * * )& pag , first , 1 , tag );
344+ (void * * )& pag , index , 1 , tag );
335345 if (found <= 0 ) {
336346 rcu_read_unlock ();
337347 return NULL ;
338348 }
339- trace_xfs_perag_grab_tag (pag , _RET_IP_ );
349+ trace_xfs_perag_grab_next_tag (pag , _RET_IP_ );
340350 if (!atomic_inc_not_zero (& pag -> pag_active_ref ))
341351 pag = NULL ;
342352 rcu_read_unlock ();
343353 return pag ;
344354}
345355
346- #define for_each_perag_tag (mp , agno , pag , tag ) \
347- for ((agno) = 0, (pag) = xfs_perag_grab_tag((mp), 0, (tag)); \
348- (pag) != NULL; \
349- (agno) = (pag)->pag_agno + 1, \
350- xfs_perag_rele(pag), \
351- (pag) = xfs_perag_grab_tag((mp), (agno), (tag)))
352-
353356/*
354357 * When we recycle a reclaimable inode, we need to re-initialise the VFS inode
355358 * part of the structure. This is made more complex by the fact we store
@@ -1077,15 +1080,11 @@ long
10771080xfs_reclaim_inodes_count (
10781081 struct xfs_mount * mp )
10791082{
1080- struct xfs_perag * pag ;
1081- xfs_agnumber_t ag = 0 ;
1083+ struct xfs_perag * pag = NULL ;
10821084 long reclaimable = 0 ;
10831085
1084- while ((pag = xfs_perag_get_tag (mp , ag , XFS_ICI_RECLAIM_TAG ))) {
1085- ag = pag -> pag_agno + 1 ;
1086+ while ((pag = xfs_perag_get_next_tag (mp , pag , XFS_ICI_RECLAIM_TAG )))
10861087 reclaimable += pag -> pag_ici_reclaimable ;
1087- xfs_perag_put (pag );
1088- }
10891088 return reclaimable ;
10901089}
10911090
@@ -1427,14 +1426,13 @@ void
14271426xfs_blockgc_start (
14281427 struct xfs_mount * mp )
14291428{
1430- struct xfs_perag * pag ;
1431- xfs_agnumber_t agno ;
1429+ struct xfs_perag * pag = NULL ;
14321430
14331431 if (xfs_set_blockgc_enabled (mp ))
14341432 return ;
14351433
14361434 trace_xfs_blockgc_start (mp , __return_address );
1437- for_each_perag_tag ( mp , agno , pag , XFS_ICI_BLOCKGC_TAG )
1435+ while (( pag = xfs_perag_grab_next_tag ( mp , pag , XFS_ICI_BLOCKGC_TAG )) )
14381436 xfs_blockgc_queue (pag );
14391437}
14401438
@@ -1550,21 +1548,19 @@ int
15501548xfs_blockgc_flush_all (
15511549 struct xfs_mount * mp )
15521550{
1553- struct xfs_perag * pag ;
1554- xfs_agnumber_t agno ;
1551+ struct xfs_perag * pag = NULL ;
15551552
15561553 trace_xfs_blockgc_flush_all (mp , __return_address );
15571554
15581555 /*
1559- * For each blockgc worker, move its queue time up to now. If it
1560- * wasn't queued, it will not be requeued. Then flush whatever's
1561- * left.
1556+ * For each blockgc worker, move its queue time up to now. If it wasn't
1557+ * queued, it will not be requeued. Then flush whatever is left.
15621558 */
1563- for_each_perag_tag ( mp , agno , pag , XFS_ICI_BLOCKGC_TAG )
1559+ while (( pag = xfs_perag_grab_next_tag ( mp , pag , XFS_ICI_BLOCKGC_TAG )) )
15641560 mod_delayed_work (pag -> pag_mount -> m_blockgc_wq ,
15651561 & pag -> pag_blockgc_work , 0 );
15661562
1567- for_each_perag_tag ( mp , agno , pag , XFS_ICI_BLOCKGC_TAG )
1563+ while (( pag = xfs_perag_grab_next_tag ( mp , pag , XFS_ICI_BLOCKGC_TAG )) )
15681564 flush_delayed_work (& pag -> pag_blockgc_work );
15691565
15701566 return xfs_inodegc_flush (mp );
@@ -1810,12 +1806,11 @@ xfs_icwalk(
18101806 enum xfs_icwalk_goal goal ,
18111807 struct xfs_icwalk * icw )
18121808{
1813- struct xfs_perag * pag ;
1809+ struct xfs_perag * pag = NULL ;
18141810 int error = 0 ;
18151811 int last_error = 0 ;
1816- xfs_agnumber_t agno ;
18171812
1818- for_each_perag_tag ( mp , agno , pag , goal ) {
1813+ while (( pag = xfs_perag_grab_next_tag ( mp , pag , goal )) ) {
18191814 error = xfs_icwalk_ag (pag , goal , icw );
18201815 if (error ) {
18211816 last_error = error ;
0 commit comments