Message ID | 1422387983-32153-32-git-send-email-mreitz@redhat.com |
---|---|
State | New |
Headers | show |
On 01/27/2015 12:46 PM, Max Reitz wrote: > This function associates the given BlockDriverState with the given > BlockBackend. > > Signed-off-by: Max Reitz <mreitz@redhat.com> > --- > block/block-backend.c | 16 ++++++++++++++++ > include/sysemu/block-backend.h | 1 + > 2 files changed, 17 insertions(+) > > diff --git a/block/block-backend.c b/block/block-backend.c > index 760558f..656ebfc 100644 > --- a/block/block-backend.c > +++ b/block/block-backend.c > @@ -312,6 +312,22 @@ void blk_hide_on_behalf_of_do_drive_del(BlockBackend *blk) > } > > /* > + * Associates a new BlockDriverState with @blk. > + */ > +void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs) > +{ > + if (bs->blk == blk) { > + return; > + } > + > + assert(!blk->bs); I guess this interesting code allows for idempotent use of blk_insert_bs more than once? What situations require that usage pattern? At any rate, the new function looks fine. Reviewed-by: Eric Blake <eblake@redhat.com>
On 2015-01-28 at 11:52, Eric Blake wrote: > On 01/27/2015 12:46 PM, Max Reitz wrote: >> This function associates the given BlockDriverState with the given >> BlockBackend. >> >> Signed-off-by: Max Reitz <mreitz@redhat.com> >> --- >> block/block-backend.c | 16 ++++++++++++++++ >> include/sysemu/block-backend.h | 1 + >> 2 files changed, 17 insertions(+) >> >> diff --git a/block/block-backend.c b/block/block-backend.c >> index 760558f..656ebfc 100644 >> --- a/block/block-backend.c >> +++ b/block/block-backend.c >> @@ -312,6 +312,22 @@ void blk_hide_on_behalf_of_do_drive_del(BlockBackend *blk) >> } >> >> /* >> + * Associates a new BlockDriverState with @blk. >> + */ >> +void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs) >> +{ >> + if (bs->blk == blk) { >> + return; >> + } >> + >> + assert(!blk->bs); > I guess this interesting code allows for idempotent use of blk_insert_bs > more than once? What situations require that usage pattern? Well, to be honest, there is no such requirement. I could (probably) have just omitted the condition before the assertion; but I just felt like it would be perfectly valid for this function to be idempotent which is why the condition is there. > At any rate, the new function looks fine. > Reviewed-by: Eric Blake <eblake@redhat.com> Once again, thank you! Max
diff --git a/block/block-backend.c b/block/block-backend.c index 760558f..656ebfc 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -312,6 +312,22 @@ void blk_hide_on_behalf_of_do_drive_del(BlockBackend *blk) } /* + * Associates a new BlockDriverState with @blk. + */ +void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs) +{ + if (bs->blk == blk) { + return; + } + + assert(!blk->bs); + assert(!bs->blk); + bdrv_ref(bs); + blk->bs = bs; + bs->blk = blk; +} + +/* * Attach device model @dev to @blk. * Return 0 on success, -EBUSY when a device model is attached already. */ diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index afb62e1..b6cf5bf 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -72,6 +72,7 @@ BlockBackend *blk_by_name(const char *name); BlockBackend *blk_next(BlockBackend *blk); BlockDriverState *blk_bs(BlockBackend *blk); +void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs); void blk_hide_on_behalf_of_do_drive_del(BlockBackend *blk);
This function associates the given BlockDriverState with the given BlockBackend. Signed-off-by: Max Reitz <mreitz@redhat.com> --- block/block-backend.c | 16 ++++++++++++++++ include/sysemu/block-backend.h | 1 + 2 files changed, 17 insertions(+)