<div dir="ltr">Hi<br><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jun 21, 2013 at 12:25 AM, Paolo Bonzini <span dir="ltr"><<a href="mailto:pbonzini@redhat.com" target="_blank">pbonzini@redhat.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Il 20/06/2013 19:46, Marc-André Lureau ha scritto:<br>
<div class="im">> This allows the Spice block driver to eject the associated device.<br>
<br>
</div>The child can change when you have for example a streaming operation.<br></blockquote><div><br></div><div>Ah, can you point me to some function or some way I can reproduce? I don't know what you mean by a streaming operation here.<br>
<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
What exactly are you trying to do here (I guess I'll understand more<br>
when I get to the later patches)?<br></blockquote><div><br></div><div>Getting to the bottom BlockDriverState to be able to eject & change it. (it could also be named the "parent", but other parts of the code suggest the "child" name)<br>
</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Can you draw the relationships between all the BlockDriverStates in a<br>
spicebd: drive?<br></blockquote><div><br></div><div>Hopefully, but I have only tested with raw images (w/wo snapshot).<br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<span class=""><font color="#888888"><br>
Paolo<br>
</font></span><div class=""><div class="h5"><br>
> Signed-off-by: Marc-André Lureau <<a href="mailto:marcandre.lureau@redhat.com">marcandre.lureau@redhat.com</a>><br>
> ---<br>
> block.c | 46 +++++++++++++++++++++++++++++-----------------<br>
> include/block/block_int.h | 1 +<br>
> 2 files changed, 30 insertions(+), 17 deletions(-)<br>
><br>
> diff --git a/block.c b/block.c<br>
> index b88ad2f..f502eed 100644<br>
> --- a/block.c<br>
> +++ b/block.c<br>
> @@ -294,7 +294,8 @@ void bdrv_register(BlockDriver *bdrv)<br>
> }<br>
><br>
> /* create a new block device (by default it is empty) */<br>
> -BlockDriverState *bdrv_new(const char *device_name)<br>
> +static BlockDriverState *bdrv_new_int(const char *device_name,<br>
> + BlockDriverState *child)<br>
> {<br>
> BlockDriverState *bs;<br>
><br>
> @@ -305,10 +306,16 @@ BlockDriverState *bdrv_new(const char *device_name)<br>
> }<br>
> bdrv_iostatus_disable(bs);<br>
> notifier_list_init(&bs->close_notifiers);<br>
> + bs->child = child;<br>
><br>
> return bs;<br>
> }<br>
><br>
> +BlockDriverState *bdrv_new(const char *device_name)<br>
> +{<br>
> + return bdrv_new_int(device_name, NULL);<br>
> +}<br>
> +<br>
> void bdrv_add_close_notifier(BlockDriverState *bs, Notifier *notify)<br>
> {<br>
> notifier_list_add(&bs->close_notifiers, notify);<br>
> @@ -769,16 +776,8 @@ free_and_fail:<br>
> return ret;<br>
> }<br>
><br>
> -/*<br>
> - * Opens a file using a protocol (file, host_device, nbd, ...)<br>
> - *<br>
> - * options is a QDict of options to pass to the block drivers, or NULL for an<br>
> - * empty set of options. The reference to the QDict belongs to the block layer<br>
> - * after the call (even on failure), so if the caller intends to reuse the<br>
> - * dictionary, it needs to use QINCREF() before calling bdrv_file_open.<br>
> - */<br>
> -int bdrv_file_open(BlockDriverState **pbs, const char *filename,<br>
> - QDict *options, int flags)<br>
> +static int bdrv_file_open_int(BlockDriverState **pbs, const char *filename,<br>
> + QDict *options, int flags, BlockDriverState *child)<br>
> {<br>
> BlockDriverState *bs;<br>
> BlockDriver *drv;<br>
> @@ -790,7 +789,7 @@ int bdrv_file_open(BlockDriverState **pbs, const char *filename,<br>
> options = qdict_new();<br>
> }<br>
><br>
> - bs = bdrv_new("");<br>
> + bs = bdrv_new_int("", child);<br>
> bs->options = options;<br>
> options = qdict_clone_shallow(options);<br>
><br>
> @@ -873,6 +872,20 @@ fail:<br>
> }<br>
><br>
> /*<br>
> + * Opens a file using a protocol (file, host_device, nbd, ...)<br>
> + *<br>
> + * options is a QDict of options to pass to the block drivers, or NULL for an<br>
> + * empty set of options. The reference to the QDict belongs to the block layer<br>
> + * after the call (even on failure), so if the caller intends to reuse the<br>
> + * dictionary, it needs to use QINCREF() before calling bdrv_file_open.<br>
> + */<br>
> +int bdrv_file_open(BlockDriverState **pbs, const char *filename,<br>
> + QDict *options, int flags)<br>
> +{<br>
> + return bdrv_file_open_int(pbs, filename, options, flags, NULL);<br>
> +}<br>
> +<br>
> +/*<br>
> * Opens the backing file for a BlockDriverState if not yet open<br>
> *<br>
> * options is a QDict of options to pass to the block drivers, or NULL for an<br>
> @@ -904,7 +917,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options)<br>
> return 0;<br>
> }<br>
><br>
> - bs->backing_hd = bdrv_new("");<br>
> + bs->backing_hd = bdrv_new_int("", bs);<br>
> bdrv_get_full_backing_filename(bs, backing_filename,<br>
> sizeof(backing_filename));<br>
><br>
> @@ -990,7 +1003,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,<br>
> instead of opening 'filename' directly */<br>
><br>
> /* if there is a backing file, use it */<br>
> - bs1 = bdrv_new("");<br>
> + bs1 = bdrv_new_int("", bs);<br>
> ret = bdrv_open(bs1, filename, NULL, 0, drv);<br>
> if (ret < 0) {<br>
> bdrv_delete(bs1);<br>
> @@ -1043,9 +1056,8 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,<br>
> }<br>
><br>
> extract_subqdict(options, &file_options, "file.");<br>
> -<br>
> - ret = bdrv_file_open(&file, filename, file_options,<br>
> - bdrv_open_flags(bs, flags));<br>
> + ret = bdrv_file_open_int(&file, filename, file_options,<br>
> + bdrv_open_flags(bs, flags), bs);<br>
> if (ret < 0) {<br>
> goto fail;<br>
> }<br>
> diff --git a/include/block/block_int.h b/include/block/block_int.h<br>
> index ba52247..9c72b32 100644<br>
> --- a/include/block/block_int.h<br>
> +++ b/include/block/block_int.h<br>
> @@ -245,6 +245,7 @@ struct BlockDriverState {<br>
><br>
> BlockDriverState *backing_hd;<br>
> BlockDriverState *file;<br>
> + BlockDriverState *child;<br>
><br>
> NotifierList close_notifiers;<br>
><br>
><br>
<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Marc-André Lureau
</div></div></div>