qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC PATCH v3 1/2] block: parse "backing" option to referen


From: Fam Zheng
Subject: [Qemu-devel] [RFC PATCH v3 1/2] block: parse "backing" option to reference existing BDS
Date: Thu, 17 Oct 2013 13:36:42 +0800

Signed-off-by: Fam Zheng <address@hidden>
---
 block.c | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/block.c b/block.c
index fd05a80..38b3e80 100644
--- a/block.c
+++ b/block.c
@@ -1158,11 +1158,28 @@ int bdrv_open(BlockDriverState *bs, const char 
*filename, QDict *options,
     /* If there is a backing file, use it */
     if ((flags & BDRV_O_NO_BACKING) == 0) {
         QDict *backing_options;
-
-        qdict_extract_subqdict(options, &backing_options, "backing.");
-        ret = bdrv_open_backing_file(bs, backing_options, &local_err);
-        if (ret < 0) {
-            goto close_and_fail;
+        const char *backing_bs;
+
+        backing_bs = qdict_get_try_str(options, "backing");
+        if (backing_bs) {
+            bs->backing_hd = bdrv_find(backing_bs);
+            bdrv_ref(bs->backing_hd);
+            qdict_del(options, "backing");
+            if (bs->backing_hd) {
+                pstrcpy(bs->backing_file, sizeof(bs->backing_file),
+                        bs->backing_hd->filename);
+                pstrcpy(bs->backing_format, sizeof(bs->backing_format),
+                        bs->backing_hd->drv->format_name);
+            } else {
+                error_setg(errp, "Backing device not found: %s", backing_bs);
+                goto close_and_fail;
+            }
+        } else {
+            qdict_extract_subqdict(options, &backing_options, "backing.");
+            ret = bdrv_open_backing_file(bs, backing_options, &local_err);
+            if (ret < 0) {
+                goto close_and_fail;
+            }
         }
     }
 
-- 
1.8.3.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]