[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC PATCH 08/14] block: add a new API to create a hidden B
From: |
Wen Congyang |
Subject: |
[Qemu-devel] [RFC PATCH 08/14] block: add a new API to create a hidden BlockBackend |
Date: |
Thu, 12 Feb 2015 11:07:12 +0800 |
Signed-off-by: Wen Congyang <address@hidden>
Signed-off-by: zhanghailiang <address@hidden>
Signed-off-by: Gonglei <address@hidden>
---
block/block-backend.c | 29 ++++++++++++++++++++++++++++-
include/sysemu/block-backend.h | 2 ++
2 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/block/block-backend.c b/block/block-backend.c
index c28e240..1bbc078 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -72,6 +72,19 @@ BlockBackend *blk_new(const char *name, Error **errp)
}
/*
+ * Create a new hidden BlockBackend, with a reference count of one.
+ * Return the new BlockBackend on success, null on failure.
+ */
+BlockBackend *blk_hide_new(void)
+{
+ BlockBackend *blk;
+
+ blk = g_new0(BlockBackend, 1);
+ blk->refcnt = 1;
+ return blk;
+}
+
+/*
* Create a new BlockBackend with a new BlockDriverState attached.
* Otherwise just like blk_new(), which see.
*/
@@ -91,6 +104,20 @@ BlockBackend *blk_new_with_bs(const char *name, Error
**errp)
return blk;
}
+/*
+ * Create a new hidden BlockBackend with a new BlockDriverState attached.
+ * Otherwise just like blk_hide_new(), which see.
+ */
+BlockBackend *blk_hide_new_with_bs(void)
+{
+ BlockBackend *blk = blk_hide_new();
+ BlockDriverState *bs = bdrv_new();
+
+ blk->bs = bs;
+ bs->blk = blk;
+ return blk;
+}
+
static void blk_delete(BlockBackend *blk)
{
assert(!blk->refcnt);
@@ -102,7 +129,7 @@ static void blk_delete(BlockBackend *blk)
blk->bs = NULL;
}
/* Avoid double-remove after blk_hide_on_behalf_of_do_drive_del() */
- if (blk->name[0]) {
+ if (blk->name && blk->name[0]) {
QTAILQ_REMOVE(&blk_backends, blk, link);
}
g_free(blk->name);
diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h
index aab12b9..acc50f5 100644
--- a/include/sysemu/block-backend.h
+++ b/include/sysemu/block-backend.h
@@ -61,7 +61,9 @@ typedef struct BlockDevOps {
} BlockDevOps;
BlockBackend *blk_new(const char *name, Error **errp);
+BlockBackend *blk_hide_new(void);
BlockBackend *blk_new_with_bs(const char *name, Error **errp);
+BlockBackend *blk_hide_new_with_bs(void);
void blk_ref(BlockBackend *blk);
void blk_unref(BlockBackend *blk);
const char *blk_name(BlockBackend *blk);
--
2.1.0
- Re: [Qemu-devel] [RFC PATCH 06/14] NBD client: connect to nbd server later, (continued)
- [Qemu-devel] [RFC PATCH 09/14] block: give backing image its own BlockBackend, Wen Congyang, 2015/02/11
- [Qemu-devel] [RFC PATCH 07/14] NBD client: implement block driver interfaces for block replication, Wen Congyang, 2015/02/11
- [Qemu-devel] [RFC PATCH 10/14] allow the backing image access the origin BlockDriverState, Wen Congyang, 2015/02/11
- [Qemu-devel] [RFC PATCH 11/14] allow writing to the backing file, Wen Congyang, 2015/02/11
- [Qemu-devel] [RFC PATCH 13/14] COW: move cow interfaces to a seperate file, Wen Congyang, 2015/02/11
- [Qemu-devel] [RFC PATCH 08/14] block: add a new API to create a hidden BlockBackend,
Wen Congyang <=
- [Qemu-devel] [RFC PATCH 12/14] Add disk buffer for block replication, Wen Congyang, 2015/02/11
- [Qemu-devel] [RFC PATCH 14/14] COLO: implement a new block driver, Wen Congyang, 2015/02/11
- Re: [Qemu-devel] [RFC PATCH 00/14] Block replication for continuous checkpoints, Paolo Bonzini, 2015/02/18