[Top][All Lists]

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

[Qemu-devel] [PATCH v3 03/12] block: Add overlay BDS pointer into the Bl

From: Jeff Cody
Subject: [Qemu-devel] [PATCH v3 03/12] block: Add overlay BDS pointer into the BlockDriverState struct
Date: Fri, 30 May 2014 13:35:21 -0400

Now that node-names can reference an individual BlockDriverState without
needing to navigate downwards from the 'device' level, in order to find
the top-most image (active layer) we need a pointer to the overlay of a

This will allow QMP commands to reference an image solely by its
node-name, without also needing to pass in the corresponding 'device'

This also adds a helper function to set the overlay pointer that is, for
now, trivial.  But since we recently moved away from open coding
bs->backing_hd assignment, we should probably also refrain from setting
bs->overlay directly.

Signed-off-by: Jeff Cody <address@hidden>
 block.c                   | 14 ++++++++++++++
 include/block/block.h     |  1 +
 include/block/block_int.h |  1 +
 3 files changed, 16 insertions(+)

diff --git a/block.c b/block.c
index cf4b296..588046e 100644
--- a/block.c
+++ b/block.c
@@ -1108,12 +1108,22 @@ fail:
     return ret;
+void bdrv_set_overlay(BlockDriverState *bs, BlockDriverState *overlay)
+    if (bs) {
+        bs->overlay = overlay;
+    }
 void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd)
     if (bs->backing_hd) {
         bdrv_op_unblock_all(bs->backing_hd, bs->backing_blocker);
+        if (!backing_hd) {
+            bdrv_set_overlay(bs->backing_hd, NULL);
+        }
     } else if (backing_hd) {
                    "device is used as backing hd of '%s'",
@@ -1126,6 +1136,8 @@ void bdrv_set_backing_hd(BlockDriverState *bs, 
BlockDriverState *backing_hd)
         bs->backing_blocker = NULL;
         goto out;
+    bdrv_set_overlay(backing_hd, bs);
     bs->open_flags &= ~BDRV_O_NO_BACKING;
     pstrcpy(bs->backing_file, sizeof(bs->backing_file), backing_hd->filename);
     pstrcpy(bs->backing_format, sizeof(bs->backing_format),
@@ -2085,6 +2097,8 @@ void bdrv_append(BlockDriverState *bs_new, 
BlockDriverState *bs_top)
     /* The contents of 'tmp' will become bs_top, as we are
      * swapping bs_new and bs_top contents. */
     bdrv_set_backing_hd(bs_top, bs_new);
+    /* make sure that bs_new->backing_hd->overlay points to bs_new */
+    bdrv_set_overlay(bs_new->backing_hd, bs_new);
 static void bdrv_delete(BlockDriverState *bs)
diff --git a/include/block/block.h b/include/block/block.h
index 4dc68be..dff5403 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -217,6 +217,7 @@ int bdrv_open_image(BlockDriverState **pbs, const char 
                     QDict *options, const char *bdref_key, int flags,
                     bool allow_none, Error **errp);
 void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd);
+void bdrv_set_overlay(BlockDriverState *bs, BlockDriverState *overlay);
 int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp);
 void bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp);
 int bdrv_open(BlockDriverState **pbs, const char *filename,
diff --git a/include/block/block_int.h b/include/block/block_int.h
index f2e753f..c0fe90b 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -303,6 +303,7 @@ struct BlockDriverState {
     char backing_format[16]; /* if non-zero and backing_file exists */
     BlockDriverState *backing_hd;
+    BlockDriverState *overlay;
     BlockDriverState *file;
     NotifierList close_notifiers;

reply via email to

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