提交 57322b78 编写于 作者: M Markus Armbruster 提交者: Kevin Wolf

block: Use bdrv_nb_sectors() where sectors, not bytes are wanted

Instead of bdrv_getlength().

Aside: a few of these callers don't handle errors.  I didn't
investigate whether they should.
Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
Reviewed-by: NEric Blake <eblake@redhat.com>
Reviewed-by: NBenoit Canet <benoit@irqsave.net>
Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
上级 43716fa8
...@@ -186,7 +186,7 @@ static int bmds_aio_inflight(BlkMigDevState *bmds, int64_t sector) ...@@ -186,7 +186,7 @@ static int bmds_aio_inflight(BlkMigDevState *bmds, int64_t sector)
{ {
int64_t chunk = sector / (int64_t)BDRV_SECTORS_PER_DIRTY_CHUNK; int64_t chunk = sector / (int64_t)BDRV_SECTORS_PER_DIRTY_CHUNK;
if ((sector << BDRV_SECTOR_BITS) < bdrv_getlength(bmds->bs)) { if (sector < bdrv_nb_sectors(bmds->bs)) {
return !!(bmds->aio_bitmap[chunk / (sizeof(unsigned long) * 8)] & return !!(bmds->aio_bitmap[chunk / (sizeof(unsigned long) * 8)] &
(1UL << (chunk % (sizeof(unsigned long) * 8)))); (1UL << (chunk % (sizeof(unsigned long) * 8))));
} else { } else {
...@@ -223,8 +223,7 @@ static void alloc_aio_bitmap(BlkMigDevState *bmds) ...@@ -223,8 +223,7 @@ static void alloc_aio_bitmap(BlkMigDevState *bmds)
BlockDriverState *bs = bmds->bs; BlockDriverState *bs = bmds->bs;
int64_t bitmap_size; int64_t bitmap_size;
bitmap_size = (bdrv_getlength(bs) >> BDRV_SECTOR_BITS) + bitmap_size = bdrv_nb_sectors(bs) + BDRV_SECTORS_PER_DIRTY_CHUNK * 8 - 1;
BDRV_SECTORS_PER_DIRTY_CHUNK * 8 - 1;
bitmap_size /= BDRV_SECTORS_PER_DIRTY_CHUNK * 8; bitmap_size /= BDRV_SECTORS_PER_DIRTY_CHUNK * 8;
bmds->aio_bitmap = g_malloc0(bitmap_size); bmds->aio_bitmap = g_malloc0(bitmap_size);
...@@ -350,7 +349,7 @@ static void init_blk_migration_it(void *opaque, BlockDriverState *bs) ...@@ -350,7 +349,7 @@ static void init_blk_migration_it(void *opaque, BlockDriverState *bs)
int64_t sectors; int64_t sectors;
if (!bdrv_is_read_only(bs)) { if (!bdrv_is_read_only(bs)) {
sectors = bdrv_getlength(bs) >> BDRV_SECTOR_BITS; sectors = bdrv_nb_sectors(bs);
if (sectors <= 0) { if (sectors <= 0) {
return; return;
} }
...@@ -799,7 +798,7 @@ static int block_load(QEMUFile *f, void *opaque, int version_id) ...@@ -799,7 +798,7 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
if (bs != bs_prev) { if (bs != bs_prev) {
bs_prev = bs; bs_prev = bs;
total_sectors = bdrv_getlength(bs) >> BDRV_SECTOR_BITS; total_sectors = bdrv_nb_sectors(bs);
if (total_sectors <= 0) { if (total_sectors <= 0) {
error_report("Error getting length of block device %s", error_report("Error getting length of block device %s",
device_name); device_name);
......
...@@ -5283,13 +5283,12 @@ BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs, int granularity, ...@@ -5283,13 +5283,12 @@ BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs, int granularity,
granularity >>= BDRV_SECTOR_BITS; granularity >>= BDRV_SECTOR_BITS;
assert(granularity); assert(granularity);
bitmap_size = bdrv_getlength(bs); bitmap_size = bdrv_nb_sectors(bs);
if (bitmap_size < 0) { if (bitmap_size < 0) {
error_setg_errno(errp, -bitmap_size, "could not get length of device"); error_setg_errno(errp, -bitmap_size, "could not get length of device");
errno = -bitmap_size; errno = -bitmap_size;
return NULL; return NULL;
} }
bitmap_size >>= BDRV_SECTOR_BITS;
bitmap = g_malloc0(sizeof(BdrvDirtyBitmap)); bitmap = g_malloc0(sizeof(BdrvDirtyBitmap));
bitmap->bitmap = hbitmap_alloc(bitmap_size, ffs(granularity) - 1); bitmap->bitmap = hbitmap_alloc(bitmap_size, ffs(granularity) - 1);
QLIST_INSERT_HEAD(&bs->dirty_bitmaps, bitmap, list); QLIST_INSERT_HEAD(&bs->dirty_bitmaps, bitmap, list);
......
...@@ -1557,7 +1557,7 @@ static int preallocate(BlockDriverState *bs) ...@@ -1557,7 +1557,7 @@ static int preallocate(BlockDriverState *bs)
int ret; int ret;
QCowL2Meta *meta; QCowL2Meta *meta;
nb_sectors = bdrv_getlength(bs) >> BDRV_SECTOR_BITS; nb_sectors = bdrv_nb_sectors(bs);
offset = 0; offset = 0;
while (nb_sectors) { while (nb_sectors) {
......
...@@ -669,8 +669,7 @@ static int vmdk_open_vmdk4(BlockDriverState *bs, ...@@ -669,8 +669,7 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,
if (le32_to_cpu(header.flags) & VMDK4_FLAG_RGD) { if (le32_to_cpu(header.flags) & VMDK4_FLAG_RGD) {
l1_backup_offset = le64_to_cpu(header.rgd_offset) << 9; l1_backup_offset = le64_to_cpu(header.rgd_offset) << 9;
} }
if (bdrv_getlength(file) < if (bdrv_nb_sectors(file) < le64_to_cpu(header.grain_offset)) {
le64_to_cpu(header.grain_offset) * BDRV_SECTOR_SIZE) {
error_setg(errp, "File truncated, expecting at least %" PRId64 " bytes", error_setg(errp, "File truncated, expecting at least %" PRId64 " bytes",
(int64_t)(le64_to_cpu(header.grain_offset) (int64_t)(le64_to_cpu(header.grain_offset)
* BDRV_SECTOR_SIZE)); * BDRV_SECTOR_SIZE));
...@@ -1999,7 +1998,7 @@ static int vmdk_check(BlockDriverState *bs, BdrvCheckResult *result, ...@@ -1999,7 +1998,7 @@ static int vmdk_check(BlockDriverState *bs, BdrvCheckResult *result,
BDRVVmdkState *s = bs->opaque; BDRVVmdkState *s = bs->opaque;
VmdkExtent *extent = NULL; VmdkExtent *extent = NULL;
int64_t sector_num = 0; int64_t sector_num = 0;
int64_t total_sectors = bdrv_getlength(bs) / BDRV_SECTOR_SIZE; int64_t total_sectors = bdrv_nb_sectors(bs);
int ret; int ret;
uint64_t cluster_offset; uint64_t cluster_offset;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册