qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Add exit notifiers.
@ 2010-06-04  9:35 Gerd Hoffmann
  2010-06-04 10:14 ` Stefan Hajnoczi
  0 siblings, 1 reply; 5+ messages in thread
From: Gerd Hoffmann @ 2010-06-04  9:35 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

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.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 roms/seabios |    2 +-
 sysemu.h     |    4 ++++
 vl.c         |   19 +++++++++++++++++++
 3 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/roms/seabios b/roms/seabios
index 8f469b9..7d09d0e 160000
--- a/roms/seabios
+++ b/roms/seabios
@@ -1 +1 @@
-Subproject commit 8f469b9676127ba6bb52609d89ec774e61db0ee1
+Subproject commit 7d09d0e3ba11310e973d4302c7fcc3fc2184e04c
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 <windows.h>
@@ -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..1577566 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;
@@ -2127,6 +2130,21 @@ static BOOL WINAPI qemu_ctrl_handler(DWORD type)
 
 #ifndef _WIN32
 
+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);
+}
+
 static void termsig_handler(int signal)
 {
     qemu_system_shutdown_request();
@@ -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();
-- 
1.6.6.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] Add exit notifiers.
  2010-06-04  9:35 Gerd Hoffmann
@ 2010-06-04 10:14 ` Stefan Hajnoczi
  2010-06-04 12:10   ` Gerd Hoffmann
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Hajnoczi @ 2010-06-04 10:14 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: qemu-devel

On Fri, Jun 4, 2010 at 10:35 AM, Gerd Hoffmann <kraxel@redhat.com> 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.

This looks useful to me.  Just yesterday I added an atexit(3) case for
some local hacking.

> diff --git a/roms/seabios b/roms/seabios
> index 8f469b9..7d09d0e 160000
> --- a/roms/seabios
> +++ b/roms/seabios
> @@ -1 +1 @@
> -Subproject commit 8f469b9676127ba6bb52609d89ec774e61db0ee1
> +Subproject commit 7d09d0e3ba11310e973d4302c7fcc3fc2184e04c

This hunk seems unrelated to your commit.

> diff --git a/vl.c b/vl.c
> index ac1a998..1577566 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -2127,6 +2130,21 @@ static BOOL WINAPI qemu_ctrl_handler(DWORD type)
>
>  #ifndef _WIN32
>
> +void qemu_add_exit_notifier(Notifier *notify)

Why #ifndef _WIN32?  I think this patch will break _WIN32 builds.

Stefan

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH] Add exit notifiers.
@ 2010-06-04 12:08 Gerd Hoffmann
  2010-06-14 20:57 ` Anthony Liguori
  0 siblings, 1 reply; 5+ messages in thread
From: Gerd Hoffmann @ 2010-06-04 12:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

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 ]
---
 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 <windows.h>
@@ -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();
-- 
1.6.6.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] Add exit notifiers.
  2010-06-04 10:14 ` Stefan Hajnoczi
@ 2010-06-04 12:10   ` Gerd Hoffmann
  0 siblings, 0 replies; 5+ messages in thread
From: Gerd Hoffmann @ 2010-06-04 12:10 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: qemu-devel

>> --- a/roms/seabios
>> +++ b/roms/seabios
>> @@ -1 +1 @@
>> -Subproject commit 8f469b9676127ba6bb52609d89ec774e61db0ee1
>> +Subproject commit 7d09d0e3ba11310e973d4302c7fcc3fc2184e04c
>
> This hunk seems unrelated to your commit.

Damn.  Yea.  These seem to creap in now and then, I think when rebasing 
to a new version with new seabios, then carelessly doing 'git commit -a'.

>> +void qemu_add_exit_notifier(Notifier *notify)
>
> Why #ifndef _WIN32?  I think this patch will break _WIN32 builds.

Not intentionally.  Sent fixed version.

cheers,
   Gerd

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] Add exit notifiers.
  2010-06-04 12:08 [Qemu-devel] [PATCH] Add exit notifiers Gerd Hoffmann
@ 2010-06-14 20:57 ` Anthony Liguori
  0 siblings, 0 replies; 5+ messages in thread
From: Anthony Liguori @ 2010-06-14 20:57 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: qemu-devel

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<windows.h>
> @@ -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();
>    

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-06-14 20:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-04 12:08 [Qemu-devel] [PATCH] Add exit notifiers Gerd Hoffmann
2010-06-14 20:57 ` Anthony Liguori
  -- strict thread matches above, loose matches on Subject: below --
2010-06-04  9:35 Gerd Hoffmann
2010-06-04 10:14 ` Stefan Hajnoczi
2010-06-04 12:10   ` Gerd Hoffmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).