[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 16/21] block: learn to open a driver with a given op
From: |
Marc-André Lureau |
Subject: |
[Qemu-devel] [PATCH 16/21] block: learn to open a driver with a given opaque |
Date: |
Mon, 18 Nov 2013 13:25:26 +0100 |
From: Marc-André Lureau <address@hidden>
If the block driver is given an opaque data, there is no need to
allocate a new one. This allows to pass an existing driver state to the
new driver.
Signed-off-by: Marc-André Lureau <address@hidden>
---
block.c | 48 +++++++++++++++++++++++++++++-------------------
1 file changed, 29 insertions(+), 19 deletions(-)
diff --git a/block.c b/block.c
index 9e7632e..f154979 100644
--- a/block.c
+++ b/block.c
@@ -319,7 +319,7 @@ void bdrv_register(BlockDriver *bdrv)
/* create a new block device (by default it is empty) */
static BlockDriverState *bdrv_new_int(const char *device_name,
- BlockDriverState *child)
+ BlockDriverState *child, void *opaque)
{
BlockDriverState *bs;
@@ -344,13 +344,14 @@ static BlockDriverState *bdrv_new_int(const char
*device_name,
child->device_name);
}
}
+ bs->opaque = opaque;
return bs;
}
BlockDriverState *bdrv_new(const char *device_name)
{
- return bdrv_new_int(device_name, NULL);
+ return bdrv_new_int(device_name, NULL, NULL);
}
void bdrv_add_close_notifier(BlockDriverState *bs, Notifier *notify)
@@ -810,7 +811,9 @@ static int bdrv_open_common(BlockDriverState *bs,
BlockDriverState *file,
}
bs->drv = drv;
- bs->opaque = g_malloc0(drv->instance_size);
+ if (bs->opaque == NULL) {
+ bs->opaque = g_malloc0(drv->instance_size);
+ }
bs->enable_write_cache = !!(flags & BDRV_O_CACHE_WB);
@@ -864,7 +867,8 @@ free_and_fail:
}
static int bdrv_file_open_int(BlockDriverState **pbs, const char *filename,
- QDict *options, int flags, BlockDriverState *child, Error **errp)
+ QDict *options, int flags, BlockDriverState *child, void *opaque,
+ Error **errp)
{
BlockDriverState *bs;
BlockDriver *drv;
@@ -878,7 +882,7 @@ static int bdrv_file_open_int(BlockDriverState **pbs, const
char *filename,
options = qdict_new();
}
- bs = bdrv_new_int("", child);
+ bs = bdrv_new_int("", child, opaque);
bs->options = options;
options = qdict_clone_shallow(options);
@@ -975,18 +979,11 @@ fail:
int bdrv_file_open(BlockDriverState **pbs, const char *filename,
QDict *options, int flags, Error **errp)
{
- return bdrv_file_open_int(pbs, filename, options, flags, NULL, errp);
+ return bdrv_file_open_int(pbs, filename, options, flags, NULL, NULL, errp);
}
-/*
- * Opens the backing file for a BlockDriverState if not yet open
- *
- * options is a QDict of options to pass to the block drivers, or NULL for an
- * empty set of options. The reference to the QDict is transferred to this
- * function (even on failure), so if the caller intends to reuse the
dictionary,
- * it needs to use QINCREF() before calling bdrv_file_open.
- */
-int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
+static int bdrv_open_backing_file_int(BlockDriverState *bs,
+ QDict *options, void *opaque, Error **errp)
{
char backing_filename[PATH_MAX];
int back_flags, ret;
@@ -1014,7 +1011,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict
*options, Error **errp)
sizeof(backing_filename));
}
- bs->backing_hd = bdrv_new_int("", bs);
+ bs->backing_hd = bdrv_new_int("", bs, opaque);
if (bs->backing_format[0] != '\0') {
back_drv = bdrv_find_format(bs->backing_format);
}
@@ -1038,6 +1035,19 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict
*options, Error **errp)
return 0;
}
+/*
+ * Opens the backing file for a BlockDriverState if not yet open
+ *
+ * options is a QDict of options to pass to the block drivers, or NULL for an
+ * empty set of options. The reference to the QDict is transferred to this
+ * function (even on failure), so if the caller intends to reuse the
dictionary,
+ * it needs to use QINCREF() before calling bdrv_file_open.
+ */
+int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
+{
+ return bdrv_open_backing_file_int(bs, options, NULL, errp);
+}
+
static int make_snapshot(BlockDriverState *bs, int64_t total_size,
const char **pfilename, BlockDriver **pdrv,
Error **errp)
@@ -1145,7 +1155,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename,
QDict *options,
}
if (total_size == -1) {
- bs1 = bdrv_new_int("", NULL);
+ bs1 = bdrv_new_int("", NULL, NULL);
ret = bdrv_open(bs1, filename, NULL, 0, drv, &local_err);
if (ret < 0) {
bdrv_unref(bs1);
@@ -1171,7 +1181,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename,
QDict *options,
ret = bdrv_file_open_int(&file, filename, file_options,
bdrv_open_flags(bs, flags | BDRV_O_UNMAP),
- bs, &local_err);
+ bs, NULL, &local_err);
if (ret < 0) {
goto fail;
}
@@ -1207,7 +1217,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename,
QDict *options,
QDict *backing_options;
qdict_extract_subqdict(options, &backing_options, "backing.");
- ret = bdrv_open_backing_file(bs, backing_options, &local_err);
+ ret = bdrv_open_backing_file_int(bs, backing_options, NULL,
&local_err);
if (ret < 0) {
goto close_and_fail;
}
--
1.8.3.1
- [Qemu-devel] [PATCH 06/21] Split nbd block client code, (continued)
- [Qemu-devel] [PATCH 06/21] Split nbd block client code, Marc-André Lureau, 2013/11/18
- [Qemu-devel] [PATCH 07/21] nbd: don't change socket block during negotiate, Marc-André Lureau, 2013/11/18
- [Qemu-devel] [PATCH 08/21] nbd: pass export name as init argument, Marc-André Lureau, 2013/11/18
- [Qemu-devel] [PATCH 09/21] nbd: make session_close() idempotent, Marc-André Lureau, 2013/11/18
- [Qemu-devel] [PATCH 10/21] nbd: finish any pending coroutine, Marc-André Lureau, 2013/11/18
- [Qemu-devel] [PATCH 11/21] nbd: avoid uninitialized warnings, Marc-André Lureau, 2013/11/18
- [Qemu-devel] [PATCH 12/21] block: save the associated child name in BlockDriverState, Marc-André Lureau, 2013/11/18
- [Qemu-devel] [PATCH 13/21] blockdev: add qmp_change_blockdev_int(), Marc-André Lureau, 2013/11/18
- [Qemu-devel] [PATCH 14/21] block: extract make_snapshot() from bdrv_open(), Marc-André Lureau, 2013/11/18
- [Qemu-devel] [PATCH 15/21] block: add "snapshot.size" option to avoid extra bdrv_open(), Marc-André Lureau, 2013/11/18
- [Qemu-devel] [PATCH 16/21] block: learn to open a driver with a given opaque,
Marc-André Lureau <=
- [Qemu-devel] [PATCH 17/21] block: allow to call bdrv_open() with an opaque, Marc-André Lureau, 2013/11/18
- [Qemu-devel] [PATCH 18/21] block: do not notify change during migration, Marc-André Lureau, 2013/11/18
- [Qemu-devel] [PATCH 19/21] sysemu: add vm_start_hold/release, Marc-André Lureau, 2013/11/18
- [Qemu-devel] [PATCH 20/21] spice-core: allow an interface to be in AIO context, Marc-André Lureau, 2013/11/18
- [Qemu-devel] [PATCH 21/21] block: add spice block device backend, Marc-André Lureau, 2013/11/18
- Re: [Qemu-devel] [PATCH 00/21] RFCv2: add Spice block device, Marc-André Lureau, 2013/11/22