From patchwork Fri Oct 19 13:32:07 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 192701 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4647F2C008E for ; Sat, 20 Oct 2012 00:48:44 +1100 (EST) Received: from localhost ([::1]:49584 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TPCwM-0005B8-Er for incoming@patchwork.ozlabs.org; Fri, 19 Oct 2012 09:48:42 -0400 Received: from eggs.gnu.org ([208.118.235.92]:47206) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TPCit-00081r-Ni for qemu-devel@nongnu.org; Fri, 19 Oct 2012 09:34:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TPCis-0006pl-7i for qemu-devel@nongnu.org; Fri, 19 Oct 2012 09:34:47 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:36749) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TPCis-0006Qo-1H for qemu-devel@nongnu.org; Fri, 19 Oct 2012 09:34:46 -0400 Received: by mail-pb0-f45.google.com with SMTP id rp2so437208pbb.4 for ; Fri, 19 Oct 2012 06:34:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; bh=ukUcMbbAGZGVI/urGMlncgEXGD6YE0Pk4yHQo3A0bbc=; b=MXa9u0KXgthhfWAif44JS356spqhxbqGHfXhUu/OYlCommr7NN7k5zsXH3NyI5nxI3 4WeojM88zNpi3aV18pRp8HOsycqBtymqsRRVTphZ1xjK69X6cWWfeVoqKKJD8RynRt7n +Cas1Ci5KEoSlrahGdAZvBEWsupjmkjHWOdkpmMuUC3fnGVOeXNK39R6eHPPTUPDBR9r skxyjFxspuEnslSUf+kClNsltCBr7rf3MPLfEMP3TIN6JeyD9Q6MOJw3Zq90EwdyR0dK bKOLFgvgiyBhM6Bqpuke5DOHFC988S6VPwau2jGjz0Yrglw1FAyJgwp0pqsyxIDLHNIu +uOQ== Received: by 10.66.77.168 with SMTP id t8mr3982510paw.28.1350653685629; Fri, 19 Oct 2012 06:34:45 -0700 (PDT) Received: from yakj.usersys.redhat.com (93-34-169-1.ip50.fastwebnet.it. [93.34.169.1]) by mx.google.com with ESMTPS id kr4sm1240726pbc.76.2012.10.19.06.34.41 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 19 Oct 2012 06:34:43 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 19 Oct 2012 15:32:07 +0200 Message-Id: <1350653528-5834-29-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.12.1 In-Reply-To: <1350653528-5834-1-git-send-email-pbonzini@redhat.com> References: <1350653528-5834-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.45 Subject: [Qemu-devel] [PATCH 28/29] block: add close 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The first user of close notifiers will be the embedded NBD server. It would be possible to use them to do some of the ad hoc processing (e.g. for block jobs and I/O limits) that is currently done by bdrv_close. Acked-by: Kevin Wolf Signed-off-by: Paolo Bonzini --- Makefile.objs | 4 ++-- block.c | 9 +++++++++ block.h | 1 + block_int.h | 2 ++ 4 file modificati, 14 inserzioni(+), 2 rimozioni(-) diff --git a/Makefile.objs b/Makefile.objs index 3f16d67..ca67885 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -43,7 +43,7 @@ coroutine-obj-$(CONFIG_WIN32) += coroutine-win32.o block-obj-y = cutils.o iov.o cache-utils.o qemu-option.o module.o async.o block-obj-y += nbd.o block.o blockjob.o aio.o aes.o qemu-config.o -block-obj-y += qemu-progress.o qemu-sockets.o uri.o +block-obj-y += qemu-progress.o qemu-sockets.o uri.o notify.o block-obj-y += $(coroutine-obj-y) $(qobject-obj-y) $(version-obj-y) block-obj-$(CONFIG_POSIX) += posix-aio-compat.o block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o @@ -94,7 +94,7 @@ common-obj-y += bt-host.o bt-vhci.o common-obj-y += dma-helpers.o common-obj-y += iov.o acl.o common-obj-$(CONFIG_POSIX) += compatfd.o -common-obj-y += notify.o event_notifier.o +common-obj-y += event_notifier.o common-obj-y += qemu-timer.o qemu-timer-common.o common-obj-y += qtest.o common-obj-y += vl.o diff --git a/block.c b/block.c index 2e4ddea..56426a9 100644 --- a/block.c +++ b/block.c @@ -30,6 +30,7 @@ #include "module.h" #include "qjson.h" #include "sysemu.h" +#include "notify.h" #include "qemu-coroutine.h" #include "qmp-commands.h" #include "qemu-timer.h" @@ -312,9 +313,16 @@ BlockDriverState *bdrv_new(const char *device_name) QTAILQ_INSERT_TAIL(&bdrv_states, bs, list); } bdrv_iostatus_disable(bs); + notifier_list_init(&bs->close_notifiers); + return bs; } +void bdrv_add_close_notifier(BlockDriverState *bs, Notifier *notify) +{ + notifier_list_add(&bs->close_notifiers, notify); +} + BlockDriver *bdrv_find_format(const char *format_name) { BlockDriver *drv1; @@ -1102,6 +1110,7 @@ void bdrv_close(BlockDriverState *bs) block_job_cancel_sync(bs->job); } bdrv_drain_all(); + notifier_list_notify(&bs->close_notifiers, bs); if (bs->drv) { if (bs == bs_snapshots) { diff --git a/block.h b/block.h index e2d89d7..aa608a8 100644 --- a/block.h +++ b/block.h @@ -144,6 +144,7 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, void bdrv_reopen_commit(BDRVReopenState *reopen_state); void bdrv_reopen_abort(BDRVReopenState *reopen_state); void bdrv_close(BlockDriverState *bs); +void bdrv_add_close_notifier(BlockDriverState *bs, Notifier *notify); int bdrv_attach_dev(BlockDriverState *bs, void *dev); void bdrv_attach_dev_nofail(BlockDriverState *bs, void *dev); void bdrv_detach_dev(BlockDriverState *bs, void *dev); diff --git a/block_int.h b/block_int.h index f4bae04..cedabbd 100644 --- a/block_int.h +++ b/block_int.h @@ -233,6 +233,8 @@ struct BlockDriverState { BlockDriverState *backing_hd; BlockDriverState *file; + NotifierList close_notifiers; + /* number of in-flight copy-on-read requests */ unsigned int copy_on_read_in_flight;