Skip to content

Commit 7ecf160

Browse files
committed
nilfs-resize: allow active segment search function to return block count
Allow nilfs_resize_find_active_segments() to return the total number of used blocks in the active segments it finds through an optional argument. Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
1 parent c93d67b commit 7ecf160

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

sbin/nilfs-resize.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -635,22 +635,26 @@ nilfs_resize_get_latest_segment(struct nilfs *nilfs, uint64_t start,
635635
* numbers
636636
* @maxsegnums: maximum number of segments to search (maximum number of
637637
* segment numbers that can be stored in @segnumv)
638+
* @nblocks: place to store the total number of used blocks in the found
639+
* active segments (optional)
638640
*
639641
* This function searches for segments that are reclaimable and not
640642
* protected by superblock log pointers within the range of the segment
641643
* sequence specified by [@start, @end], and stores their numbers in
642-
* @segnumv.
644+
* @segnumv. Also, if @nblocks is not NULL, it stores the total number of
645+
* used blocks included in the found active segments.
643646
*
644647
* Return: on success, the number of movable segments discovered, -1 on
645648
* error.
646649
*/
647650
static ssize_t
648651
nilfs_resize_find_active_segments(struct nilfs *nilfs, uint64_t start,
649652
uint64_t end, uint64_t *segnumv,
650-
unsigned long maxsegnums)
653+
unsigned long maxsegnums,
654+
unsigned long *nblocks)
651655
{
652656
uint64_t segnum, *snp;
653-
unsigned long rest, count;
657+
unsigned long rest, count, nb = 0;
654658
ssize_t nsi, i;
655659

656660
assert(start <= end);
@@ -669,9 +673,12 @@ nilfs_resize_find_active_segments(struct nilfs *nilfs, uint64_t start,
669673
!nilfs_suinfo_error(&suinfo[i])) {
670674
*snp++ = segnum;
671675
rest--;
676+
nb += suinfo[i].sui_nblocks;
672677
}
673678
}
674679
}
680+
if (nblocks)
681+
*nblocks = nb;
675682
return snp - segnumv; /* return the number of found segments */
676683
}
677684

@@ -1048,7 +1055,7 @@ static int nilfs_resize_move_out_active_segments(struct nilfs *nilfs,
10481055
return -1;
10491056

10501057
nfound = nilfs_resize_find_active_segments(
1051-
nilfs, start, end, segnums, NILFS_RESIZE_NSEGNUMS);
1058+
nilfs, start, end, segnums, NILFS_RESIZE_NSEGNUMS, NULL);
10521059
if (unlikely(nfound < 0))
10531060
return -1;
10541061
if (!nfound)

0 commit comments

Comments
 (0)