From: Elena Ufimtseva <address@hidden>
Relocate machine_int and exit notifiers into common code
Signed-off-by: Elena Ufimtseva <address@hidden>
Signed-off-by: John G Johnson <address@hidden>
Signed-off-by: Jagannathan Raman <address@hidden>
---
MAINTAINERS | 1 +
Makefile.objs | 1 +
include/sysemu/sysemu.h | 2 ++
softmmu/vl.c | 42 ----------------------
stubs/Makefile.objs | 2 ++
stubs/machine-init-add.c | 7 ++++
stubs/machine-init-done.c | 5 ++-
stubs/machine-init-remove.c | 8 +++++
util/machine-notify.c | 69 +++++++++++++++++++++++++++++++++++++
9 files changed, 92 insertions(+), 45 deletions(-)
create mode 100644 stubs/machine-init-add.c
create mode 100644 stubs/machine-init-remove.c
create mode 100644 util/machine-notify.c
diff --git a/MAINTAINERS b/MAINTAINERS
index 8cbc1fac2b..04b19ac56c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2133,6 +2133,7 @@ F: util/qemu-timer.c
F: softmmu/vl.c
F: softmmu/main.c
F: qapi/run-state.json
+F: util/machine-notify.c
Human Monitor (HMP)
M: Dr. David Alan Gilbert <address@hidden>
diff --git a/Makefile.objs b/Makefile.objs
index a7c967633a..bfb9271862 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -79,6 +79,7 @@ qemu-seccomp.o-libs := $(SECCOMP_LIBS)
common-obj-$(CONFIG_FDT) += device_tree.o
common-obj-y += qapi/
+common-obj-y += util/machine-notify.o
endif # CONFIG_SOFTMMU
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index ef81302e1a..2438dd7bea 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -17,11 +17,13 @@ extern bool qemu_uuid_set;
void qemu_add_exit_notifier(Notifier *notify);
void qemu_remove_exit_notifier(Notifier *notify);
+void qemu_run_exit_notifiers(void);
extern bool machine_init_done;
void qemu_add_machine_init_done_notifier(Notifier *notify);
void qemu_remove_machine_init_done_notifier(Notifier *notify);
+void qemu_run_machine_init_done_notifiers(void);
extern int autostart;
diff --git a/softmmu/vl.c b/softmmu/vl.c
index 32c0047889..39cbb6b50d 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -172,12 +172,6 @@ int icount_align_option;
QemuUUID qemu_uuid;
bool qemu_uuid_set;
-static NotifierList exit_notifiers =
- NOTIFIER_LIST_INITIALIZER(exit_notifiers);
-
-static NotifierList machine_init_done_notifiers =
- NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
-
bool xen_allowed;
uint32_t xen_domid;
enum xen_mode xen_mode = XEN_EMULATE;
@@ -2325,21 +2319,6 @@ static MachineClass *machine_parse(const char *name,
GSList *machines)
return mc;
}
-void qemu_add_exit_notifier(Notifier *notify)
-{
- notifier_list_add(&exit_notifiers, notify);
-}
-
-void qemu_remove_exit_notifier(Notifier *notify)
-{
- notifier_remove(notify);
-}
-
-static void qemu_run_exit_notifiers(void)
-{
- notifier_list_notify(&exit_notifiers, NULL);
-}
-
static const char *pid_file;
static Notifier qemu_unlink_pidfile_notifier;
@@ -2350,27 +2329,6 @@ static void qemu_unlink_pidfile(Notifier *n, void *data)
}
}
-bool machine_init_done;
-
-void qemu_add_machine_init_done_notifier(Notifier *notify)
-{
- notifier_list_add(&machine_init_done_notifiers, notify);
- if (machine_init_done) {
- notify->notify(notify, NULL);
- }
-}
-
-void qemu_remove_machine_init_done_notifier(Notifier *notify)
-{
- notifier_remove(notify);
-}
-
-static void qemu_run_machine_init_done_notifiers(void)
-{
- machine_init_done = true;
- notifier_list_notify(&machine_init_done_notifiers, NULL);
-}
-
static const QEMUOption *lookup_opt(int argc, char **argv,
const char **poptarg, int *poptind)
{
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index 45be5dc0ed..f884bb6180 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -43,4 +43,6 @@ stub-obj-y += pci-host-piix.o
stub-obj-y += ram-block.o
stub-obj-y += ramfb.o
stub-obj-y += fw_cfg.o
+stub-obj-y += machine-init-add.o
+stub-obj-y += machine-init-remove.o
stub-obj-$(CONFIG_SOFTMMU) += semihost.o
diff --git a/stubs/machine-init-add.c b/stubs/machine-init-add.c
new file mode 100644
index 0000000000..520dcb9801
--- /dev/null
+++ b/stubs/machine-init-add.c
@@ -0,0 +1,7 @@
+#include "qemu/osdep.h"
+#include "sysemu/sysemu.h"
+
+void qemu_add_machine_init_done_notifier(Notifier *notify)
+{
+}
+
diff --git a/stubs/machine-init-done.c b/stubs/machine-init-done.c
index cd8e81392d..a34d838f7a 100644
--- a/stubs/machine-init-done.c
+++ b/stubs/machine-init-done.c
@@ -3,6 +3,5 @@
bool machine_init_done = true;
-void qemu_add_machine_init_done_notifier(Notifier *notify)
-{
-}
+NotifierList machine_init_done_notifiers =
+ NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
diff --git a/stubs/machine-init-remove.c b/stubs/machine-init-remove.c
new file mode 100644
index 0000000000..30aee27c2d
--- /dev/null
+++ b/stubs/machine-init-remove.c
@@ -0,0 +1,8 @@
+#include "qemu/osdep.h"
+#include "sysemu/sysemu.h"
+
+void qemu_remove_machine_init_done_notifier(Notifier *notify)
+{
+}
+
+
diff --git a/util/machine-notify.c b/util/machine-notify.c
new file mode 100644
index 0000000000..718af79335
--- /dev/null
+++ b/util/machine-notify.c
@@ -0,0 +1,69 @@
+/*
+ * Machine notifiers.
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/notify.h"
+#include "sysemu/sysemu.h"
+
+static NotifierList machine_init_done_notifiers =
+ NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
+
+static NotifierList exit_notifiers =
+ NOTIFIER_LIST_INITIALIZER(exit_notifiers);
+
+bool machine_init_done;
+
+void qemu_add_machine_init_done_notifier(Notifier *notify)
+{
+ notifier_list_add(&machine_init_done_notifiers, notify);
+ if (machine_init_done) {
+ notify->notify(notify, NULL);
+ }
+}
+
+void qemu_remove_machine_init_done_notifier(Notifier *notify)
+{
+ notifier_remove(notify);
+}
+
+void qemu_run_machine_init_done_notifiers(void)
+{
+ machine_init_done = true;
+ notifier_list_notify(&machine_init_done_notifiers, NULL);
+}
+
+void qemu_add_exit_notifier(Notifier *notify)
+{
+ notifier_list_add(&exit_notifiers, notify);
+}
+
+void qemu_remove_exit_notifier(Notifier *notify)
+{
+ notifier_remove(notify);
+}
+
+void qemu_run_exit_notifiers(void)
+{
+ notifier_list_notify(&exit_notifiers, NULL);
+}