aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2013-09-04 19:00:21 +0200
committerStefan Hajnoczi <stefanha@redhat.com>2013-09-06 15:25:08 +0200
commitdf2a6f29a5019707d69f6eeb30cf792841cae5aa (patch)
tree196a71f34402aae6cfded4d54d65df548b24483a
parente641c1e81e54fc14908ff6785ef7d51e42c2e1bb (diff)
block: keep bs->total_sectors up to date even for growable block devices
If a BlockDriverState is growable, after every write we need to check if bs->total_sectors might have changed. With this change, bdrv_getlength does not need anymore a system call. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
-rw-r--r--block.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/block.c b/block.c
index 905bf34251..d9a3a7f9db 100644
--- a/block.c
+++ b/block.c
@@ -2739,6 +2739,9 @@ static int coroutine_fn bdrv_co_do_writev(BlockDriverState *bs,
if (bs->wr_highest_sector < sector_num + nb_sectors - 1) {
bs->wr_highest_sector = sector_num + nb_sectors - 1;
}
+ if (bs->growable && ret >= 0) {
+ bs->total_sectors = MAX(bs->total_sectors, sector_num + nb_sectors);
+ }
tracked_request_end(&req);
@@ -2813,7 +2816,7 @@ int64_t bdrv_getlength(BlockDriverState *bs)
if (!drv)
return -ENOMEDIUM;
- if (bs->growable || bdrv_dev_has_removable_media(bs)) {
+ if (bdrv_dev_has_removable_media(bs)) {
if (drv->bdrv_getlength) {
return drv->bdrv_getlength(bs);
}