[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 12/21] block: save the associated child name in Bloc
From: |
Marc-André Lureau |
Subject: |
[Qemu-devel] [PATCH 12/21] block: save the associated child name in BlockDriverState |
Date: |
Mon, 18 Nov 2013 13:25:22 +0100 |
From: Marc-André Lureau <address@hidden>
This allows the Spice block driver to eject the associated device.
Signed-off-by: Marc-André Lureau <address@hidden>
---
block.c | 58 ++++++++++++++++++++++++++++++++---------------
include/block/block_int.h | 1 +
2 files changed, 41 insertions(+), 18 deletions(-)
diff --git a/block.c b/block.c
index 6d5c804..0558525 100644
--- a/block.c
+++ b/block.c
@@ -318,7 +318,8 @@ void bdrv_register(BlockDriver *bdrv)
}
/* create a new block device (by default it is empty) */
-BlockDriverState *bdrv_new(const char *device_name)
+static BlockDriverState *bdrv_new_int(const char *device_name,
+ BlockDriverState *child)
{
BlockDriverState *bs;
@@ -334,9 +335,24 @@ BlockDriverState *bdrv_new(const char *device_name)
qemu_co_queue_init(&bs->throttled_reqs[1]);
bs->refcnt = 1;
+ if (child) {
+ if (strlen(child->child_device_name)) {
+ pstrcpy(bs->child_device_name, sizeof(bs->child_device_name),
+ child->child_device_name);
+ } else {
+ pstrcpy(bs->child_device_name, sizeof(bs->child_device_name),
+ child->device_name);
+ }
+ }
+
return bs;
}
+BlockDriverState *bdrv_new(const char *device_name)
+{
+ return bdrv_new_int(device_name, NULL);
+}
+
void bdrv_add_close_notifier(BlockDriverState *bs, Notifier *notify)
{
notifier_list_add(&bs->close_notifiers, notify);
@@ -847,16 +863,8 @@ free_and_fail:
return ret;
}
-/*
- * Opens a file using a protocol (file, host_device, nbd, ...)
- *
- * 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 belongs to the block layer
- * after the call (even on failure), so if the caller intends to reuse the
- * dictionary, it needs to use QINCREF() before calling bdrv_file_open.
- */
-int bdrv_file_open(BlockDriverState **pbs, const char *filename,
- QDict *options, int flags, Error **errp)
+static int bdrv_file_open_int(BlockDriverState **pbs, const char *filename,
+ QDict *options, int flags, BlockDriverState *child, Error **errp)
{
BlockDriverState *bs;
BlockDriver *drv;
@@ -870,7 +878,7 @@ int bdrv_file_open(BlockDriverState **pbs, const char
*filename,
options = qdict_new();
}
- bs = bdrv_new("");
+ bs = bdrv_new_int("", child);
bs->options = options;
options = qdict_clone_shallow(options);
@@ -957,6 +965,20 @@ fail:
}
/*
+ * Opens a file using a protocol (file, host_device, nbd, ...)
+ *
+ * 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 belongs to the block layer
+ * after the call (even on failure), so if the caller intends to reuse the
+ * dictionary, it needs to use QINCREF() before calling bdrv_file_open.
+ */
+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);
+}
+
+/*
* 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
@@ -992,8 +1014,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict
*options, Error **errp)
sizeof(backing_filename));
}
- bs->backing_hd = bdrv_new("");
-
+ bs->backing_hd = bdrv_new_int("", bs);
if (bs->backing_format[0] != '\0') {
back_drv = bdrv_find_format(bs->backing_format);
}
@@ -1063,7 +1084,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename,
QDict *options,
instead of opening 'filename' directly */
/* if there is a backing file, use it */
- bs1 = bdrv_new("");
+ bs1 = bdrv_new_int("", bs);
ret = bdrv_open(bs1, filename, NULL, 0, drv, &local_err);
if (ret < 0) {
bdrv_unref(bs1);
@@ -1124,8 +1145,9 @@ int bdrv_open(BlockDriverState *bs, const char *filename,
QDict *options,
qdict_extract_subqdict(options, &file_options, "file.");
- ret = bdrv_file_open(&file, filename, file_options,
- bdrv_open_flags(bs, flags | BDRV_O_UNMAP),
&local_err);
+ ret = bdrv_file_open_int(&file, filename, file_options,
+ bdrv_open_flags(bs, flags | BDRV_O_UNMAP),
+ bs, &local_err);
if (ret < 0) {
goto fail;
}
@@ -1883,7 +1905,7 @@ int bdrv_commit(BlockDriverState *bs)
if (!drv)
return -ENOMEDIUM;
-
+
if (!bs->backing_hd) {
return -ENOTSUP;
}
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 1666066..e0f31dc 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -301,6 +301,7 @@ struct BlockDriverState {
bool iostatus_enabled;
BlockDeviceIoStatus iostatus;
char device_name[32];
+ char child_device_name[32];
HBitmap *dirty_bitmap;
int refcnt;
int in_use; /* users other than guest access, eg. block migration */
--
1.8.3.1
- [Qemu-devel] [PATCH 03/21] qmp_change_blockdev() remove unused has_format, (continued)
- [Qemu-devel] [PATCH 03/21] qmp_change_blockdev() remove unused has_format, Marc-André Lureau, 2013/11/18
- [Qemu-devel] [PATCH 04/21] include: add missing config-host.h include, Marc-André Lureau, 2013/11/18
- [Qemu-devel] [PATCH 05/21] char: add qemu_chr_fe_event(), Marc-André Lureau, 2013/11/18
- [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 <=
- [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, 2013/11/18
- [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