From patchwork Tue Feb 2 17:35:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 8192261 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4600A9FBE9 for ; Tue, 2 Feb 2016 17:44:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9995A20270 for ; Tue, 2 Feb 2016 17:44:12 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D8E4220109 for ; Tue, 2 Feb 2016 17:44:10 +0000 (UTC) Received: from localhost ([::1]:58543 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQezq-000604-8D for patchwork-qemu-devel@patchwork.kernel.org; Tue, 02 Feb 2016 12:44:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49574) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQesQ-0008FQ-Em for qemu-devel@nongnu.org; Tue, 02 Feb 2016 12:36:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aQesP-0008K0-99 for qemu-devel@nongnu.org; Tue, 02 Feb 2016 12:36:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40437) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQesJ-0008IA-PS; Tue, 02 Feb 2016 12:36:23 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 6B4BC461C8; Tue, 2 Feb 2016 17:36:23 +0000 (UTC) Received: from localhost (ovpn-116-64.ams2.redhat.com [10.36.116.64]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u12HaLkf026684 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 2 Feb 2016 12:36:23 -0500 From: Max Reitz To: qemu-block@nongnu.org Date: Tue, 2 Feb 2016 18:35:11 +0100 Message-Id: <1454434543-25963-19-git-send-email-mreitz@redhat.com> In-Reply-To: <1454434543-25963-1-git-send-email-mreitz@redhat.com> References: <1454434543-25963-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: qemu-devel@nongnu.org, Max Reitz Subject: [Qemu-devel] [PULL v2 18/50] block: Add BB-BDS remove/insert notifiers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Fam Zheng Signed-off-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);