aboutsummaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2014-10-07 13:59:06 +0200
committerKevin Wolf <kwolf@redhat.com>2014-10-20 13:41:26 +0200
commit18e46a033d67060c1430740cf8084b702955ae8f (patch)
tree23b97330842f6dff75096ba99718f96df3f891b9 /block
parent7e7d56d9e05b340290669442cfa05f5869204572 (diff)
block: Connect BlockBackend and DriveInfo
Make the BlockBackend own the DriveInfo. Change blockdev_init() to return the BlockBackend instead of the DriveInfo. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block')
-rw-r--r--block/block-backend.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/block/block-backend.c b/block/block-backend.c
index a12215a546..edaf73c1d7 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -12,11 +12,13 @@
#include "sysemu/block-backend.h"
#include "block/block_int.h"
+#include "sysemu/blockdev.h"
struct BlockBackend {
char *name;
int refcnt;
BlockDriverState *bs;
+ DriveInfo *legacy_dinfo;
QTAILQ_ENTRY(BlockBackend) link; /* for blk_backends */
};
@@ -87,6 +89,7 @@ static void blk_delete(BlockBackend *blk)
QTAILQ_REMOVE(&blk_backends, blk, link);
}
g_free(blk->name);
+ drive_info_del(blk->legacy_dinfo);
g_free(blk);
}
@@ -167,6 +170,41 @@ BlockDriverState *blk_bs(BlockBackend *blk)
}
/*
+ * Return @blk's DriveInfo if any, else null.
+ */
+DriveInfo *blk_legacy_dinfo(BlockBackend *blk)
+{
+ return blk->legacy_dinfo;
+}
+
+/*
+ * Set @blk's DriveInfo to @dinfo, and return it.
+ * @blk must not have a DriveInfo set already.
+ * No other BlockBackend may have the same DriveInfo set.
+ */
+DriveInfo *blk_set_legacy_dinfo(BlockBackend *blk, DriveInfo *dinfo)
+{
+ assert(!blk->legacy_dinfo);
+ return blk->legacy_dinfo = dinfo;
+}
+
+/*
+ * Return the BlockBackend with DriveInfo @dinfo.
+ * It must exist.
+ */
+BlockBackend *blk_by_legacy_dinfo(DriveInfo *dinfo)
+{
+ BlockBackend *blk;
+
+ QTAILQ_FOREACH(blk, &blk_backends, link) {
+ if (blk->legacy_dinfo == dinfo) {
+ return blk;
+ }
+ }
+ abort();
+}
+
+/*
* Hide @blk.
* @blk must not have been hidden already.
* Make attached BlockDriverState, if any, anonymous.