@@ -538,6 +538,52 @@ xfs_rtallocate_extent_near(
538
538
return - ENOSPC ;
539
539
}
540
540
541
+ static int
542
+ xfs_rtalloc_sumlevel (
543
+ struct xfs_rtalloc_args * args ,
544
+ int l , /* level number */
545
+ xfs_rtxlen_t minlen , /* minimum length to allocate */
546
+ xfs_rtxlen_t maxlen , /* maximum length to allocate */
547
+ xfs_rtxlen_t prod , /* extent product factor */
548
+ xfs_rtxlen_t * len , /* out: actual length allocated */
549
+ xfs_rtxnum_t * rtx ) /* out: start rtext allocated */
550
+ {
551
+ xfs_fileoff_t i ; /* bitmap block number */
552
+
553
+ for (i = 0 ; i < args -> mp -> m_sb .sb_rbmblocks ; i ++ ) {
554
+ xfs_suminfo_t sum ; /* summary information for extents */
555
+ xfs_rtxnum_t n ; /* next rtext to be tried */
556
+ int error ;
557
+
558
+ error = xfs_rtget_summary (args , l , i , & sum );
559
+ if (error )
560
+ return error ;
561
+
562
+ /*
563
+ * Nothing there, on to the next block.
564
+ */
565
+ if (!sum )
566
+ continue ;
567
+
568
+ /*
569
+ * Try allocating the extent.
570
+ */
571
+ error = xfs_rtallocate_extent_block (args , i , minlen , maxlen ,
572
+ len , & n , prod , rtx );
573
+ if (error != - ENOSPC )
574
+ return error ;
575
+
576
+ /*
577
+ * If the "next block to try" returned from the allocator is
578
+ * beyond the next bitmap block, skip to that bitmap block.
579
+ */
580
+ if (xfs_rtx_to_rbmblock (args -> mp , n ) > i + 1 )
581
+ i = xfs_rtx_to_rbmblock (args -> mp , n ) - 1 ;
582
+ }
583
+
584
+ return - ENOSPC ;
585
+ }
586
+
541
587
/*
542
588
* Allocate an extent of length minlen<=len<=maxlen, with no position
543
589
* specified. If we don't get maxlen then use prod to trim
@@ -552,59 +598,32 @@ xfs_rtallocate_extent_size(
552
598
xfs_rtxlen_t prod , /* extent product factor */
553
599
xfs_rtxnum_t * rtx ) /* out: start rtext allocated */
554
600
{
555
- struct xfs_mount * mp = args -> mp ;
556
601
int error ;
557
- xfs_fileoff_t i ; /* bitmap block number */
558
602
int l ; /* level number (loop control) */
559
- xfs_rtxnum_t n ; /* next rtext to be tried */
560
- xfs_suminfo_t sum ; /* summary information for extents */
561
603
562
604
ASSERT (minlen % prod == 0 );
563
605
ASSERT (maxlen % prod == 0 );
564
606
ASSERT (maxlen != 0 );
565
607
566
608
/*
567
609
* Loop over all the levels starting with maxlen.
568
- * At each level, look at all the bitmap blocks, to see if there
569
- * are extents starting there that are long enough (>= maxlen).
570
- * Note, only on the initial level can the allocation fail if
571
- * the summary says there's an extent.
610
+ *
611
+ * At each level, look at all the bitmap blocks, to see if there are
612
+ * extents starting there that are long enough (>= maxlen).
613
+ *
614
+ * Note, only on the initial level can the allocation fail if the
615
+ * summary says there's an extent.
572
616
*/
573
- for (l = xfs_highbit32 (maxlen ); l < mp -> m_rsumlevels ; l ++ ) {
574
- /*
575
- * Loop over all the bitmap blocks.
576
- */
577
- for (i = 0 ; i < mp -> m_sb .sb_rbmblocks ; i ++ ) {
578
- /*
579
- * Get the summary for this level/block.
580
- */
581
- error = xfs_rtget_summary (args , l , i , & sum );
582
- if (error )
583
- return error ;
584
- /*
585
- * Nothing there, on to the next block.
586
- */
587
- if (!sum )
588
- continue ;
589
- /*
590
- * Try allocating the extent.
591
- */
592
- error = xfs_rtallocate_extent_block (args , i , maxlen ,
593
- maxlen , len , & n , prod , rtx );
594
- if (error != - ENOSPC )
595
- return error ;
596
- /*
597
- * If the "next block to try" returned from the
598
- * allocator is beyond the next bitmap block,
599
- * skip to that bitmap block.
600
- */
601
- if (xfs_rtx_to_rbmblock (mp , n ) > i + 1 )
602
- i = xfs_rtx_to_rbmblock (mp , n ) - 1 ;
603
- }
617
+ for (l = xfs_highbit32 (maxlen ); l < args -> mp -> m_rsumlevels ; l ++ ) {
618
+ error = xfs_rtalloc_sumlevel (args , l , minlen , maxlen , prod , len ,
619
+ rtx );
620
+ if (error != - ENOSPC )
621
+ return error ;
604
622
}
623
+
605
624
/*
606
- * Didn't find any maxlen blocks. Try smaller ones, unless
607
- * we're asking for a fixed size extent.
625
+ * Didn't find any maxlen blocks. Try smaller ones, unless we are
626
+ * looking for a fixed size extent.
608
627
*/
609
628
if (minlen > -- maxlen )
610
629
return - ENOSPC ;
@@ -613,51 +632,19 @@ xfs_rtallocate_extent_size(
613
632
614
633
/*
615
634
* Loop over sizes, from maxlen down to minlen.
616
- * This time, when we do the allocations, allow smaller ones
617
- * to succeed.
635
+ *
636
+ * This time, when we do the allocations, allow smaller ones to succeed,
637
+ * but make sure the specified minlen/maxlen are in the possible range
638
+ * for this summary level.
618
639
*/
619
640
for (l = xfs_highbit32 (maxlen ); l >= xfs_highbit32 (minlen ); l -- ) {
620
- /*
621
- * Loop over all the bitmap blocks, try an allocation
622
- * starting in that block.
623
- */
624
- for (i = 0 ; i < mp -> m_sb .sb_rbmblocks ; i ++ ) {
625
- /*
626
- * Get the summary information for this level/block.
627
- */
628
- error = xfs_rtget_summary (args , l , i , & sum );
629
- if (error )
630
- return error ;
631
-
632
- /*
633
- * If nothing there, go on to next.
634
- */
635
- if (!sum )
636
- continue ;
637
- /*
638
- * Try the allocation. Make sure the specified
639
- * minlen/maxlen are in the possible range for
640
- * this summary level.
641
- */
642
- error = xfs_rtallocate_extent_block (args , i ,
643
- XFS_RTMAX (minlen , 1 << l ),
644
- XFS_RTMIN (maxlen , (1 << (l + 1 )) - 1 ),
645
- len , & n , prod , rtx );
646
- if (error != - ENOSPC )
647
- return error ;
648
-
649
- /*
650
- * If the "next block to try" returned from the
651
- * allocator is beyond the next bitmap block,
652
- * skip to that bitmap block.
653
- */
654
- if (xfs_rtx_to_rbmblock (mp , n ) > i + 1 )
655
- i = xfs_rtx_to_rbmblock (mp , n ) - 1 ;
656
- }
641
+ error = xfs_rtalloc_sumlevel (args , l , XFS_RTMAX (minlen , 1 << l ),
642
+ XFS_RTMIN (maxlen , (1 << (l + 1 )) - 1 ), prod ,
643
+ len , rtx );
644
+ if (error != - ENOSPC )
645
+ return error ;
657
646
}
658
- /*
659
- * Got nothing, return failure.
660
- */
647
+
661
648
return - ENOSPC ;
662
649
}
663
650
0 commit comments