[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 07/10] migration/block: replace uses of blk_nb_sectors that do not
From: |
Kevin Wolf |
Subject: |
[PULL 07/10] migration/block: replace uses of blk_nb_sectors that do not check result |
Date: |
Tue, 11 Apr 2023 17:01:44 +0200 |
From: Paolo Bonzini <pbonzini@redhat.com>
Uses of blk_nb_sectors must check whether the result is negative.
Otherwise, underflow can happen. Fortunately, alloc_aio_bitmap()
and bmds_aio_inflight() both have an alternative way to retrieve the
number of sectors in the file.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20230407153303.391121-6-pbonzini@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
migration/block.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/migration/block.c b/migration/block.c
index 426a25bb19..b2497bbd32 100644
--- a/migration/block.c
+++ b/migration/block.c
@@ -195,7 +195,7 @@ static int bmds_aio_inflight(BlkMigDevState *bmds, int64_t
sector)
{
int64_t chunk = sector / (int64_t)BDRV_SECTORS_PER_DIRTY_CHUNK;
- if (sector < blk_nb_sectors(bmds->blk)) {
+ if (sector < bmds->total_sectors) {
return !!(bmds->aio_bitmap[chunk / (sizeof(unsigned long) * 8)] &
(1UL << (chunk % (sizeof(unsigned long) * 8))));
} else {
@@ -229,10 +229,9 @@ static void bmds_set_aio_inflight(BlkMigDevState *bmds,
int64_t sector_num,
static void alloc_aio_bitmap(BlkMigDevState *bmds)
{
- BlockBackend *bb = bmds->blk;
int64_t bitmap_size;
- bitmap_size = blk_nb_sectors(bb) + BDRV_SECTORS_PER_DIRTY_CHUNK * 8 - 1;
+ bitmap_size = bmds->total_sectors + BDRV_SECTORS_PER_DIRTY_CHUNK * 8 - 1;
bitmap_size /= BDRV_SECTORS_PER_DIRTY_CHUNK * 8;
bmds->aio_bitmap = g_malloc0(bitmap_size);
--
2.39.2
- [PULL 00/10] Block layer fixes for 8.0-rc4, Kevin Wolf, 2023/04/11
- [PULL 03/10] block: move has_variable_length to BlockLimits, Kevin Wolf, 2023/04/11
- [PULL 06/10] block: remove has_variable_length from BlockDriver, Kevin Wolf, 2023/04/11
- [PULL 02/10] iotests: Regression test for vhdx log corruption, Kevin Wolf, 2023/04/11
- [PULL 09/10] block-backend: ignore inserted state in blk_co_nb_sectors, Kevin Wolf, 2023/04/11
- [PULL 01/10] block/vhdx: fix dynamic VHDX BAT corruption, Kevin Wolf, 2023/04/11
- [PULL 05/10] block: refresh bs->total_sectors on reopen, Kevin Wolf, 2023/04/11
- [PULL 10/10] block, block-backend: write some hot coroutine wrappers by hand, Kevin Wolf, 2023/04/11
- [PULL 04/10] block: remove has_variable_length from filters, Kevin Wolf, 2023/04/11
- [PULL 07/10] migration/block: replace uses of blk_nb_sectors that do not check result,
Kevin Wolf <=
- [PULL 08/10] block-backend: inline bdrv_co_get_geometry, Kevin Wolf, 2023/04/11
- Re: [PULL 00/10] Block layer fixes for 8.0-rc4, Peter Maydell, 2023/04/12