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

Marc-André Lureau marcandre.lureau at gmail.com
Thu Jun 20 10:46:08 PDT 2013


Signed-off-by: Marc-André Lureau <marcandre.lureau at redhat.com>
---
 block.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

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) {
-- 
1.8.3.rc1.49.g8d97506



More information about the Spice-devel mailing list