From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=58818 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OOGiP-0007th-QE for qemu-devel@nongnu.org; Mon, 14 Jun 2010 16:57:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OOGiO-0007pQ-FX for qemu-devel@nongnu.org; Mon, 14 Jun 2010 16:57:05 -0400 Received: from mail-iw0-f173.google.com ([209.85.214.173]:56474) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OOGiO-0007ly-Cd for qemu-devel@nongnu.org; Mon, 14 Jun 2010 16:57:04 -0400 Received: by mail-iw0-f173.google.com with SMTP id 10so4582648iwn.4 for ; Mon, 14 Jun 2010 13:57:04 -0700 (PDT) Message-ID: <4C1697A1.30506@codemonkey.ws> Date: Mon, 14 Jun 2010 15:57:05 -0500 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH] Add exit notifiers. References: <1275653287-30862-1-git-send-email-kraxel@redhat.com> In-Reply-To: <1275653287-30862-1-git-send-email-kraxel@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gerd Hoffmann Cc: qemu-devel@nongnu.org On 06/04/2010 07:08 AM, Gerd Hoffmann wrote: > 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 ] > Applied. Thanks. Regards, Anthony Liguori > --- > sysemu.h | 4 ++++ > vl.c | 19 +++++++++++++++++++ > 3 files changed, 24 insertions(+), 1 deletions(-) > > diff --git a/sysemu.h b/sysemu.h > index fd9dd9d..140b7ff 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 > @@ -51,6 +52,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 ac1a998..52c6b22 100644 > --- a/vl.c > +++ b/vl.c > @@ -243,6 +243,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; > @@ -2117,6 +2120,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); > +} > + > #ifdef _WIN32 > static BOOL WINAPI qemu_ctrl_handler(DWORD type) > { > @@ -2583,6 +2601,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(); >