Skip to content

Commit 81d5553

Browse files
ntsironsnitm
authored andcommitted
dm clone metadata: Fix return type of dm_clone_nr_of_hydrated_regions()
dm_clone_nr_of_hydrated_regions() returns the number of regions that have been hydrated so far. In order to do so it employs bitmap_weight(). Until now, the return type of dm_clone_nr_of_hydrated_regions() was unsigned long. Because bitmap_weight() returns an int, in case BITS_PER_LONG == 64 and the return value of bitmap_weight() is 2^31 (the maximum allowed number of regions for a device), the result is sign extended from 32 bits to 64 bits and an incorrect value is displayed, in the status output of dm-clone, as the number of hydrated regions. Fix this by having dm_clone_nr_of_hydrated_regions() return an unsigned int. Fixes: 7431b78 ("dm: add clone target") Cc: [email protected] # v5.4+ Signed-off-by: Nikos Tsironis <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent 9fc06ff commit 81d5553

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

drivers/md/dm-clone-metadata.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ bool dm_clone_is_range_hydrated(struct dm_clone_metadata *cmd,
656656
return (bit >= (start + nr_regions));
657657
}
658658

659-
unsigned long dm_clone_nr_of_hydrated_regions(struct dm_clone_metadata *cmd)
659+
unsigned int dm_clone_nr_of_hydrated_regions(struct dm_clone_metadata *cmd)
660660
{
661661
return bitmap_weight(cmd->region_map, cmd->nr_regions);
662662
}

drivers/md/dm-clone-metadata.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ bool dm_clone_is_range_hydrated(struct dm_clone_metadata *cmd,
156156
/*
157157
* Returns the number of hydrated regions.
158158
*/
159-
unsigned long dm_clone_nr_of_hydrated_regions(struct dm_clone_metadata *cmd);
159+
unsigned int dm_clone_nr_of_hydrated_regions(struct dm_clone_metadata *cmd);
160160

161161
/*
162162
* Returns the first unhydrated region with region_nr >= @start

drivers/md/dm-clone-target.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,7 @@ static void clone_status(struct dm_target *ti, status_type_t type,
14731473
goto error;
14741474
}
14751475

1476-
DMEMIT("%u %llu/%llu %llu %lu/%lu %u ",
1476+
DMEMIT("%u %llu/%llu %llu %u/%lu %u ",
14771477
DM_CLONE_METADATA_BLOCK_SIZE,
14781478
(unsigned long long)(nr_metadata_blocks - nr_free_metadata_blocks),
14791479
(unsigned long long)nr_metadata_blocks,

0 commit comments

Comments
 (0)