aboutsummaryrefslogtreecommitdiff
path: root/block.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2013-09-04 19:00:23 +0200
committerStefan Hajnoczi <stefanha@redhat.com>2013-09-06 15:25:08 +0200
commit617ccb466e1937a5c99332ce77a47ebd29861ae4 (patch)
tree13686ac810955b6dcc9c1f155129f216d5d50904 /block.c
parentbdad13b9deec47d5d9eaf7f43867d19a79471244 (diff)
block: do not use ->total_sectors in bdrv_co_is_allocated
This is more robust when the device has removable media. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'block.c')
-rw-r--r--block.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/block.c b/block.c
index f27bab6809..4a10fb1a2f 100644
--- a/block.c
+++ b/block.c
@@ -3065,9 +3065,15 @@ static int coroutine_fn bdrv_co_is_allocated(BlockDriverState *bs,
int64_t sector_num,
int nb_sectors, int *pnum)
{
+ int64_t length;
int64_t n;
- if (sector_num >= bs->total_sectors) {
+ length = bdrv_getlength(bs);
+ if (length < 0) {
+ return length;
+ }
+
+ if (sector_num >= (length >> BDRV_SECTOR_BITS)) {
*pnum = 0;
return 0;
}