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

Marc-André Lureau marcandre.lureau at gmail.com
Mon Nov 18 04:25:25 PST 2013


From: Marc-André Lureau <marcandre.lureau at redhat.com>

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

diff --git a/block.c b/block.c
index 09aada5..9e7632e 100644
--- a/block.c
+++ b/block.c
@@ -1135,27 +1135,32 @@ 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_setg(errp, "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, &local_err);
-        if (ret < 0) {
+        if (total_size == -1) {
+            bs1 = bdrv_new_int("", NULL);
+            ret = bdrv_open(bs1, filename, NULL, 0, drv, &local_err);
+            if (ret < 0) {
+                bdrv_unref(bs1);
+                goto fail;
+            }
+            total_size = bdrv_getlength(bs1);
             bdrv_unref(bs1);
-            goto fail;
         }
 
-        total_size = bdrv_getlength(bs1) & BDRV_SECTOR_MASK;
-        bdrv_unref(bs1);
-
         ret = make_snapshot(bs, total_size, &filename, &drv, errp);
         if (ret < 0) {
             goto fail;
         }
     }
+    qdict_del(options, "snapshot.size");
 
     /* Open image file without format layer */
     if (flags & BDRV_O_RDWR) {
-- 
1.8.3.1



More information about the Spice-devel mailing list