From patchwork Mon Jun 14 15:27:21 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 55552 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7A9C5B7D48 for ; Tue, 15 Jun 2010 01:29:48 +1000 (EST) Received: from localhost ([127.0.0.1]:39398 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OOBbd-0000Ni-D6 for incoming@patchwork.ozlabs.org; Mon, 14 Jun 2010 11:29:45 -0400 Received: from [140.186.70.92] (port=56096 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OOBZP-0007vt-4B for qemu-devel@nongnu.org; Mon, 14 Jun 2010 11:27:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OOBZN-0007dR-6O for qemu-devel@nongnu.org; Mon, 14 Jun 2010 11:27:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56446) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OOBZM-0007dF-W8 for qemu-devel@nongnu.org; Mon, 14 Jun 2010 11:27:25 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5EFROQ1002378 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 14 Jun 2010 11:27:24 -0400 Received: from rincewind.home.kraxel.org (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5EFRMl2024937; Mon, 14 Jun 2010 11:27:23 -0400 Received: by rincewind.home.kraxel.org (Postfix, from userid 500) id 92E9241628; Mon, 14 Jun 2010 17:27:21 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Mon, 14 Jun 2010 17:27:21 +0200 Message-Id: <1276529241-21988-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [RESENT PATCH] Add exit notifiers. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Hook up any cleanup work which needs to be done here. Advantages over using atexit(3): (1) You get passed in a pointer to the notifier. If you embed that into your state struct you can use container_of() to get get your state info. (2) You can unregister, say when un-plugging a device. [ v2: move code out of #ifndef _WIN32 ] Signed-off-by: Gerd Hoffmann --- sysemu.h | 4 ++++ vl.c | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 0 deletions(-) diff --git a/sysemu.h b/sysemu.h index 346cccd..0bfbd6a 100644 --- a/sysemu.h +++ b/sysemu.h @@ -6,6 +6,7 @@ #include "qemu-option.h" #include "qemu-queue.h" #include "qemu-timer.h" +#include "notify.h" #ifdef _WIN32 #include @@ -56,6 +57,9 @@ int qemu_powerdown_requested(void); extern qemu_irq qemu_system_powerdown; void qemu_system_reset(void); +void qemu_add_exit_notifier(Notifier *notify); +void qemu_remove_exit_notifier(Notifier *notify); + void do_savevm(Monitor *mon, const QDict *qdict); int load_vmstate(const char *name); void do_delvm(Monitor *mon, const QDict *qdict); diff --git a/vl.c b/vl.c index 9cf5334..5daeb7b 100644 --- a/vl.c +++ b/vl.c @@ -238,6 +238,9 @@ uint8_t qemu_uuid[16]; static QEMUBootSetHandler *boot_set_handler; static void *boot_set_opaque; +static NotifierList exit_notifiers = + NOTIFIER_LIST_INITIALIZER(exit_notifiers); + int kvm_allowed = 0; uint32_t xen_domid; enum xen_mode xen_mode = XEN_EMULATE; @@ -1956,6 +1959,21 @@ static int balloon_parse(const char *arg) return -1; } +void qemu_add_exit_notifier(Notifier *notify) +{ + notifier_list_add(&exit_notifiers, notify); +} + +void qemu_remove_exit_notifier(Notifier *notify) +{ + notifier_list_remove(&exit_notifiers, notify); +} + +static void qemu_run_exit_notifiers(void) +{ + notifier_list_notify(&exit_notifiers); +} + char *qemu_find_file(int type, const char *name) { int len; @@ -2287,6 +2305,7 @@ int main(int argc, char **argv, char **envp) int show_vnc_port = 0; int defconfig = 1; + atexit(qemu_run_exit_notifiers); error_set_progname(argv[0]); init_clocks();