From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54796) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aOcv8-0003OB-Cy for qemu-devel@nongnu.org; Wed, 27 Jan 2016 22:06:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aOcv7-0006ym-8B for qemu-devel@nongnu.org; Wed, 27 Jan 2016 22:06:54 -0500 Date: Thu, 28 Jan 2016 11:06:43 +0800 From: Fam Zheng Message-ID: <20160128030643.GF7877@ad.usersys.redhat.com> References: <1453917600-2663-1-git-send-email-mreitz@redhat.com> <1453917600-2663-4-git-send-email-mreitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1453917600-2663-4-git-send-email-mreitz@redhat.com> Subject: Re: [Qemu-devel] [PATCH v8 03/16] block: Add BB-BDS remove/insert notifiers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, John Snow , qemu-devel@nongnu.org, Paolo Bonzini On Wed, 01/27 18:59, Max Reitz wrote: > bdrv_close() no longer signifies ejection of a medium, this is now done > by removing the BDS from the BB. Therefore, we want to have a notifier > for that in the BB instead of a close notifier in the BDS. The former is > added now, the latter is removed later. > > Symmetrically, another notifier list is added that is invoked whenever a > BDS is inserted. We will need that for virtio-blk and virtio-scsi, which > can then remove their op blockers on BDS ejection and set them up on > insertion. > > Signed-off-by: Max Reitz > Reviewed-by: Kevin Wolf > --- > block/block-backend.c | 20 ++++++++++++++++++++ > include/sysemu/block-backend.h | 2 ++ > 2 files changed, 22 insertions(+) > > diff --git a/block/block-backend.c b/block/block-backend.c > index a4208f1..1872191 100644 > --- a/block/block-backend.c > +++ b/block/block-backend.c > @@ -49,6 +49,8 @@ struct BlockBackend { > BlockdevOnError on_read_error, on_write_error; > bool iostatus_enabled; > BlockDeviceIoStatus iostatus; > + > + NotifierList remove_bs_notifiers, insert_bs_notifiers; > }; > > typedef struct BlockBackendAIOCB { > @@ -99,6 +101,8 @@ BlockBackend *blk_new(const char *name, Error **errp) > blk = g_new0(BlockBackend, 1); > blk->name = g_strdup(name); > blk->refcnt = 1; > + notifier_list_init(&blk->remove_bs_notifiers); > + notifier_list_init(&blk->insert_bs_notifiers); > QTAILQ_INSERT_TAIL(&blk_backends, blk, link); > return blk; > } > @@ -167,6 +171,8 @@ static void blk_delete(BlockBackend *blk) > bdrv_unref(blk->bs); > blk->bs = NULL; > } > + assert(QLIST_EMPTY(&blk->remove_bs_notifiers.notifiers)); > + assert(QLIST_EMPTY(&blk->insert_bs_notifiers.notifiers)); > if (blk->root_state.throttle_state) { > g_free(blk->root_state.throttle_group); > throttle_group_unref(blk->root_state.throttle_state); > @@ -345,6 +351,8 @@ void blk_hide_on_behalf_of_hmp_drive_del(BlockBackend *blk) > */ > void blk_remove_bs(BlockBackend *blk) > { > + notifier_list_notify(&blk->remove_bs_notifiers, blk); > + > blk_update_root_state(blk); > > blk->bs->blk = NULL; > @@ -361,6 +369,8 @@ void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs) > bdrv_ref(bs); > blk->bs = bs; > bs->blk = blk; > + > + notifier_list_notify(&blk->insert_bs_notifiers, blk); > } > > /* > @@ -1126,6 +1136,16 @@ void blk_remove_aio_context_notifier(BlockBackend *blk, > } > } > > +void blk_add_remove_bs_notifier(BlockBackend *blk, Notifier *notify) > +{ > + notifier_list_add(&blk->remove_bs_notifiers, notify); > +} > + > +void blk_add_insert_bs_notifier(BlockBackend *blk, Notifier *notify) > +{ > + notifier_list_add(&blk->insert_bs_notifiers, notify); > +} > + > void blk_add_close_notifier(BlockBackend *blk, Notifier *notify) > { > if (blk->bs) { > diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h > index 1568554..e12be67 100644 > --- a/include/sysemu/block-backend.h > +++ b/include/sysemu/block-backend.h > @@ -164,6 +164,8 @@ void blk_remove_aio_context_notifier(BlockBackend *blk, > void *), > void (*detach_aio_context)(void *), > void *opaque); > +void blk_add_remove_bs_notifier(BlockBackend *blk, Notifier *notify); > +void blk_add_insert_bs_notifier(BlockBackend *blk, Notifier *notify); > void blk_add_close_notifier(BlockBackend *blk, Notifier *notify); > void blk_io_plug(BlockBackend *blk); > void blk_io_unplug(BlockBackend *blk); > -- > 2.7.0 > Reviewed-by: Fam Zheng