@@ -1046,20 +1046,25 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
BlockDriverState *bs1;
int64_t total_size;
+ total_size = qdict_get_try_int(options, "snapshot.size", -1);
+ qdict_del(options, "snapshot.size");
+
if (qdict_size(options) != 0) {
error_report("Can't use snapshot=on with driver-specific options");
ret = -EINVAL;
goto fail;
}
- bs1 = bdrv_new_int("", NULL);
- ret = bdrv_open(bs1, filename, NULL, 0, drv);
- if (ret < 0) {
+ if (total_size == -1) {
+ bs1 = bdrv_new_int("", NULL);
+ ret = bdrv_open(bs1, filename, NULL, 0, drv);
+ if (ret < 0) {
+ bdrv_delete(bs1);
+ goto fail;
+ }
+ total_size = bdrv_getlength(bs1);
bdrv_delete(bs1);
- goto fail;
}
- total_size = bdrv_getlength(bs1);
- bdrv_delete(bs1);
ret = make_snapshot(bs, total_size, &filename, &drv);
if (ret < 0) {
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- block.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)