summaryrefslogtreecommitdiff
path: root/block.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2014-06-26 13:23:25 +0200
committerKevin Wolf <kwolf@redhat.com>2014-08-15 15:07:13 +0200
commit52bf1e722d996d1accfc35e29283f172d003d9b2 (patch)
tree6244812b64390f1274615ba0bad9028d501505eb /block.c
parentd739f1c41094141268a33fa8fc6715fbab714fbe (diff)
downloadqemu-52bf1e722d996d1accfc35e29283f172d003d9b2.zip
block: Avoid bdrv_get_geometry() where errors should be detected
bdrv_get_geometry() hides errors. Use bdrv_nb_sectors() or bdrv_getlength() instead where that's obviously inappropriate. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Benoit Canet <benoit@irqsave.net> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'block.c')
-rw-r--r--block.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/block.c b/block.c
index 1af74e601b..7cafc49612 100644
--- a/block.c
+++ b/block.c
@@ -5595,7 +5595,7 @@ void bdrv_img_create(const char *filename, const char *fmt,
if (size == -1) {
if (backing_file) {
BlockDriverState *bs;
- uint64_t size;
+ int64_t size;
int back_flags;
/* backing files always opened read-only */
@@ -5613,8 +5613,13 @@ void bdrv_img_create(const char *filename, const char *fmt,
local_err = NULL;
goto out;
}
- bdrv_get_geometry(bs, &size);
- size *= 512;
+ size = bdrv_getlength(bs);
+ if (size < 0) {
+ error_setg_errno(errp, -size, "Could not get size of '%s'",
+ backing_file);
+ bdrv_unref(bs);
+ goto out;
+ }
qemu_opt_set_number(opts, BLOCK_OPT_SIZE, size);