blist_fill()'s return type is too narrow. blist_fill() accepts a 64-bit

quantity as the size of the range to fill, but returns a 32-bit quantity
as the number of blocks that were allocated to fill that range.  This
revision corrects that mismatch.  Currently, swaponsomething() limits
the size of a swap area to prevent arithmetic arithmetic overflow in
other parts of the blist allocator.  That limit has also prevented this
type mismatch from causing problems.

Reviewed by:	kib, markj
MFC after:	6 weeks
Differential Revision:	https://reviews.freebsd.org/D11096
This commit is contained in:
alc 2017-06-09 16:19:24 +00:00
parent b8cd5af05d
commit ca8432638e
2 changed files with 11 additions and 11 deletions

View File

@ -127,8 +127,8 @@ static void blst_meta_free(blmeta_t *scan, daddr_t freeBlk, daddr_t count,
daddr_t radix, int skip, daddr_t blk);
static void blst_copy(blmeta_t *scan, daddr_t blk, daddr_t radix,
daddr_t skip, blist_t dest, daddr_t count);
static int blst_leaf_fill(blmeta_t *scan, daddr_t blk, int count);
static int blst_meta_fill(blmeta_t *scan, daddr_t allocBlk, daddr_t count,
static daddr_t blst_leaf_fill(blmeta_t *scan, daddr_t blk, int count);
static daddr_t blst_meta_fill(blmeta_t *scan, daddr_t allocBlk, daddr_t count,
daddr_t radix, int skip, daddr_t blk);
static daddr_t blst_radix_init(blmeta_t *scan, daddr_t radix,
int skip, daddr_t count);
@ -248,10 +248,10 @@ blist_free(blist_t bl, daddr_t blkno, daddr_t count)
* actually filled that were free before the call.
*/
int
daddr_t
blist_fill(blist_t bl, daddr_t blkno, daddr_t count)
{
int filled;
daddr_t filled;
if (bl) {
if (bl->bl_radix == BLIST_BMAP_RADIX)
@ -726,11 +726,11 @@ static void blst_copy(
* the number of blocks allocated by the call.
*/
static int
static daddr_t
blst_leaf_fill(blmeta_t *scan, daddr_t blk, int count)
{
int n = blk & (BLIST_BMAP_RADIX - 1);
int nblks;
daddr_t nblks;
u_daddr_t mask, bitmap;
mask = ((u_daddr_t)-1 << n) &
@ -753,7 +753,7 @@ blst_leaf_fill(blmeta_t *scan, daddr_t blk, int count)
* range must be within the extent of this node. Returns the
* number of blocks allocated by the call.
*/
static int
static daddr_t
blst_meta_fill(
blmeta_t *scan,
daddr_t allocBlk,
@ -764,7 +764,7 @@ blst_meta_fill(
) {
int i;
int next_skip = ((u_int)skip / BLIST_META_RADIX);
int nblks = 0;
daddr_t nblks = 0;
if (count > radix)
panic("blist_meta_fill: allocation too large");
@ -1047,8 +1047,8 @@ main(int ac, char **av)
break;
case 'l':
if (sscanf(buf + 1, "%llx %lld", &da, &count) == 2) {
printf(" n=%d\n",
blist_fill(bl, da, count));
printf(" n=%jd\n",
(intmax_t)blist_fill(bl, da, count));
} else {
printf("?\n");
}

View File

@ -96,7 +96,7 @@ extern blist_t blist_create(daddr_t blocks, int flags);
extern void blist_destroy(blist_t blist);
extern daddr_t blist_alloc(blist_t blist, daddr_t count);
extern void blist_free(blist_t blist, daddr_t blkno, daddr_t count);
extern int blist_fill(blist_t bl, daddr_t blkno, daddr_t count);
extern daddr_t blist_fill(blist_t bl, daddr_t blkno, daddr_t count);
extern void blist_print(blist_t blist);
extern void blist_resize(blist_t *pblist, daddr_t count, int freenew, int flags);