diff mbox

[09/12] block: add "snapshot.size" option to avoid extra bdrv_open()

Message ID 1371750371-18491-10-git-send-email-marcandre.lureau@redhat.com
State New
Headers show

Commit Message

Marc-André Lureau June 20, 2013, 5:46 p.m. UTC
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 block.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
diff mbox

Patch

diff --git a/block.c b/block.c
index 5db8fa1..b421083 100644
--- a/block.c
+++ b/block.c
@@ -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) {