block/parallels: switch to bdrv_read

Switch the .bdrv_read method implementation from using bdrv_pread() to
bdrv_read() on the underlying file, since the latter is subject to i/o
throttling while the former is not.

Besides, since bdrv_read() operates in sectors rather than bytes, adjust
the helper functions to do so too.

Signed-off-by: Roman Kagan <rkagan@parallels.com>
Reviewed-by: Denis V. Lunev <den@openvz.org>
Signed-off-by: Denis V. Lunev <den@openvz.org>
Message-id: 1430207220-24458-4-git-send-email-den@openvz.org
CC: Kevin Wolf <kwolf@redhat.com>
CC: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
Roman Kagan 2015-04-28 10:46:36 +03:00 committed by Stefan Hajnoczi
parent 0789890467
commit 2944256997
1 changed files with 11 additions and 9 deletions

View File

@ -146,9 +146,8 @@ fail:
return ret; return ret;
} }
static int64_t seek_to_sector(BlockDriverState *bs, int64_t sector_num) static int64_t seek_to_sector(BDRVParallelsState *s, int64_t sector_num)
{ {
BDRVParallelsState *s = bs->opaque;
uint32_t index, offset; uint32_t index, offset;
index = sector_num / s->tracks; index = sector_num / s->tracks;
@ -157,24 +156,27 @@ static int64_t seek_to_sector(BlockDriverState *bs, int64_t sector_num)
/* not allocated */ /* not allocated */
if ((index >= s->catalog_size) || (s->catalog_bitmap[index] == 0)) if ((index >= s->catalog_size) || (s->catalog_bitmap[index] == 0))
return -1; return -1;
return return (uint64_t)s->catalog_bitmap[index] * s->off_multiplier + offset;
((uint64_t)s->catalog_bitmap[index] * s->off_multiplier + offset) * 512;
} }
static int parallels_read(BlockDriverState *bs, int64_t sector_num, static int parallels_read(BlockDriverState *bs, int64_t sector_num,
uint8_t *buf, int nb_sectors) uint8_t *buf, int nb_sectors)
{ {
BDRVParallelsState *s = bs->opaque;
while (nb_sectors > 0) { while (nb_sectors > 0) {
int64_t position = seek_to_sector(bs, sector_num); int64_t position = seek_to_sector(s, sector_num);
if (position >= 0) { if (position >= 0) {
if (bdrv_pread(bs->file, position, buf, 512) != 512) int ret = bdrv_read(bs->file, position, buf, 1);
return -1; if (ret < 0) {
return ret;
}
} else { } else {
memset(buf, 0, 512); memset(buf, 0, BDRV_SECTOR_SIZE);
} }
nb_sectors--; nb_sectors--;
sector_num++; sector_num++;
buf += 512; buf += BDRV_SECTOR_SIZE;
} }
return 0; return 0;
} }