Re: [Qemu-block] [PATCH 11/16] block-backend: Add blk_set_bs()

2015-09-23 Thread Max Reitz
On 17.09.2015 15:48, Kevin Wolf wrote:
> It allows changing the BlockDriverState that a BlockBackend points to.
> 
> Signed-off-by: Kevin Wolf 
> ---
>  block/block-backend.c | 16 
>  include/block/block_int.h |  2 ++
>  2 files changed, 18 insertions(+)
> 
> diff --git a/block/block-backend.c b/block/block-backend.c
> index c2e8732..a2afcff 100644
> --- a/block/block-backend.c
> +++ b/block/block-backend.c
> @@ -239,6 +239,22 @@ BlockDriverState *blk_bs(BlockBackend *blk)
>  }
>  
>  /*
> + * Changes the BlockDriverState attached to @blk
> + */
> +void blk_set_bs(BlockBackend *blk, BlockDriverState *bs)
> +{
> +bdrv_ref(bs);
> +
> +if (blk->bs) {
> +blk->bs->blk = NULL;
> +bdrv_unref(blk->bs);
> +}
> +
> +blk->bs = bs;
> +bs->blk = blk;
> +}
> +
> +/*

As discussed in the BlockBackend and media thread, you should probably
assert(bs->blk == NULL), and I'd rather have this implemented as
blk_remove_bs(blk); blk_insert_bs(blk, bs);, but that's probably
something that won't happen until I do so myself.

Max

>   * Return @blk's DriveInfo if any, else null.
>   */
>  DriveInfo *blk_legacy_dinfo(BlockBackend *blk)
> diff --git a/include/block/block_int.h b/include/block/block_int.h
> index 4598101..cfcae52 100644
> --- a/include/block/block_int.h
> +++ b/include/block/block_int.h
> @@ -659,6 +659,8 @@ void backup_start(BlockDriverState *bs, BlockDriverState 
> *target,
>BlockCompletionFunc *cb, void *opaque,
>Error **errp);
>  
> +void blk_set_bs(BlockBackend *blk, BlockDriverState *bs);
> +
>  void blk_dev_change_media_cb(BlockBackend *blk, bool load);
>  bool blk_dev_has_removable_media(BlockBackend *blk);
>  void blk_dev_eject_request(BlockBackend *blk, bool force);
> 




signature.asc
Description: OpenPGP digital signature


[Qemu-block] [PATCH 11/16] block-backend: Add blk_set_bs()

2015-09-17 Thread Kevin Wolf
It allows changing the BlockDriverState that a BlockBackend points to.

Signed-off-by: Kevin Wolf 
---
 block/block-backend.c | 16 
 include/block/block_int.h |  2 ++
 2 files changed, 18 insertions(+)

diff --git a/block/block-backend.c b/block/block-backend.c
index c2e8732..a2afcff 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -239,6 +239,22 @@ BlockDriverState *blk_bs(BlockBackend *blk)
 }
 
 /*
+ * Changes the BlockDriverState attached to @blk
+ */
+void blk_set_bs(BlockBackend *blk, BlockDriverState *bs)
+{
+bdrv_ref(bs);
+
+if (blk->bs) {
+blk->bs->blk = NULL;
+bdrv_unref(blk->bs);
+}
+
+blk->bs = bs;
+bs->blk = blk;
+}
+
+/*
  * Return @blk's DriveInfo if any, else null.
  */
 DriveInfo *blk_legacy_dinfo(BlockBackend *blk)
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 4598101..cfcae52 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -659,6 +659,8 @@ void backup_start(BlockDriverState *bs, BlockDriverState 
*target,
   BlockCompletionFunc *cb, void *opaque,
   Error **errp);
 
+void blk_set_bs(BlockBackend *blk, BlockDriverState *bs);
+
 void blk_dev_change_media_cb(BlockBackend *blk, bool load);
 bool blk_dev_has_removable_media(BlockBackend *blk);
 void blk_dev_eject_request(BlockBackend *blk, bool force);
-- 
1.8.3.1