[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 35/41] migration: create global_state.c
From: |
Juan Quintela |
Subject: |
[Qemu-devel] [PATCH 35/41] migration: create global_state.c |
Date: |
Wed, 26 Apr 2017 00:04:45 +0200 |
It don't belong anywhere else, just the global state where everybody
can stick other things.
Signed-off-by: Juan Quintela <address@hidden>
---
hw/i386/pc_piix.c | 1 +
hw/ppc/spapr.c | 1 +
include/migration/global_state.h | 26 +++++++
include/migration/migration.h | 4 --
migration/Makefile.objs | 2 +-
migration/global_state.c | 143 +++++++++++++++++++++++++++++++++++++++
migration/migration.c | 121 +--------------------------------
migration/savevm.c | 1 +
vl.c | 1 +
xen-common.c | 1 +
10 files changed, 176 insertions(+), 125 deletions(-)
create mode 100644 include/migration/global_state.h
create mode 100644 migration/global_state.c
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 9f102aa..6c72bd3 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -52,6 +52,7 @@
#include <xen/hvm/hvm_info_table.h>
#include "hw/xen/xen_pt.h"
#endif
+#include "migration/global_state.h"
#include "migration/migration.h"
#include "kvm_i386.h"
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 4c4701e..f779c35 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -39,6 +39,7 @@
#include "sysemu/hw_accel.h"
#include "kvm_ppc.h"
#include "migration/migration.h"
+#include "migration/global_state.h"
#include "migration/register.h"
#include "mmu-hash64.h"
#include "qom/cpu.h"
diff --git a/include/migration/global_state.h b/include/migration/global_state.h
new file mode 100644
index 0000000..84a19d0
--- /dev/null
+++ b/include/migration/global_state.h
@@ -0,0 +1,26 @@
+/*
+ * QEMU live migration
+ *
+ * Copyright IBM, Corp. 2008
+ *
+ * Authors:
+ * Anthony Liguori <address@hidden>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef QEMU_MIGRATION_GLOBAL_STATE_H
+#define QEMU_MIGRATION_GLOBAL_STATE_H
+
+#include "sysemu/sysemu.h"
+
+void register_global_state(void);
+void global_state_set_optional(void);
+int global_state_store(void);
+void global_state_store_running(void);
+bool global_state_received(void);
+RunState global_state_get_runstate(void);
+
+#endif
diff --git a/include/migration/migration.h b/include/migration/migration.h
index 7bd87f8..fc31f8e 100644
--- a/include/migration/migration.h
+++ b/include/migration/migration.h
@@ -177,10 +177,6 @@ void migrate_send_rp_req_pages(MigrationIncomingState
*mis, const char* rbname,
ram_addr_t start, size_t len);
void savevm_skip_section_footers(void);
-void register_global_state(void);
-void global_state_set_optional(void);
void savevm_skip_configuration(void);
-int global_state_store(void);
-void global_state_store_running(void);
#endif
diff --git a/migration/Makefile.objs b/migration/Makefile.objs
index 812b2ec..775e4ad 100644
--- a/migration/Makefile.objs
+++ b/migration/Makefile.objs
@@ -2,7 +2,7 @@ common-obj-y += migration.o socket.o fd.o exec.o
common-obj-y += tls.o channel.o
common-obj-y += colo-comm.o colo.o colo-failover.o
common-obj-y += vmstate.o vmstate-types.o page_cache.o
-common-obj-y += qemu-file.o
+common-obj-y += qemu-file.o global_state.o
common-obj-y += qemu-file-channel.o
common-obj-y += xbzrle.o postcopy-ram.o
common-obj-y += qjson.o
diff --git a/migration/global_state.c b/migration/global_state.c
new file mode 100644
index 0000000..3d67ba2
--- /dev/null
+++ b/migration/global_state.c
@@ -0,0 +1,143 @@
+/*
+ * QEMU live migration global state
+ *
+ * Copyright IBM, Corp. 2008
+ *
+ * Authors:
+ * Anthony Liguori <address@hidden>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ *
+ * Contributions after 2012-01-13 are licensed under the terms of the
+ * GNU GPL, version 2 or (at your option) any later version.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/cutils.h"
+#include "qemu/error-report.h"
+#include "qapi/error.h"
+#include "qapi/util.h"
+#include "migration/global_state.h"
+#include "migration/vmstate.h"
+#include "sysemu/sysemu.h"
+#include "trace.h"
+
+typedef struct {
+ bool optional;
+ uint32_t size;
+ uint8_t runstate[100];
+ RunState state;
+ bool received;
+} GlobalState;
+
+static GlobalState global_state;
+
+int global_state_store(void)
+{
+ if (!runstate_store((char *)global_state.runstate,
+ sizeof(global_state.runstate))) {
+ error_report("runstate name too big: %s", global_state.runstate);
+ trace_migrate_state_too_big();
+ return -EINVAL;
+ }
+ return 0;
+}
+
+void global_state_store_running(void)
+{
+ const char *state = RunState_lookup[RUN_STATE_RUNNING];
+ strncpy((char *)global_state.runstate,
+ state, sizeof(global_state.runstate));
+}
+
+bool global_state_received(void)
+{
+ return global_state.received;
+}
+
+RunState global_state_get_runstate(void)
+{
+ return global_state.state;
+}
+
+void global_state_set_optional(void)
+{
+ global_state.optional = true;
+}
+
+static bool global_state_needed(void *opaque)
+{
+ GlobalState *s = opaque;
+ char *runstate = (char *)s->runstate;
+
+ /* If it is not optional, it is mandatory */
+
+ if (s->optional == false) {
+ return true;
+ }
+
+ /* If state is running or paused, it is not needed */
+
+ if (strcmp(runstate, "running") == 0 ||
+ strcmp(runstate, "paused") == 0) {
+ return false;
+ }
+
+ /* for any other state it is needed */
+ return true;
+}
+
+static int global_state_post_load(void *opaque, int version_id)
+{
+ GlobalState *s = opaque;
+ Error *local_err = NULL;
+ int r;
+ char *runstate = (char *)s->runstate;
+
+ s->received = true;
+ trace_migrate_global_state_post_load(runstate);
+
+ r = qapi_enum_parse(RunState_lookup, runstate, RUN_STATE__MAX,
+ -1, &local_err);
+
+ if (r == -1) {
+ if (local_err) {
+ error_report_err(local_err);
+ }
+ return -EINVAL;
+ }
+ s->state = r;
+
+ return 0;
+}
+
+static void global_state_pre_save(void *opaque)
+{
+ GlobalState *s = opaque;
+
+ trace_migrate_global_state_pre_save((char *)s->runstate);
+ s->size = strlen((char *)s->runstate) + 1;
+}
+
+static const VMStateDescription vmstate_globalstate = {
+ .name = "globalstate",
+ .version_id = 1,
+ .minimum_version_id = 1,
+ .post_load = global_state_post_load,
+ .pre_save = global_state_pre_save,
+ .needed = global_state_needed,
+ .fields = (VMStateField[]) {
+ VMSTATE_UINT32(size, GlobalState),
+ VMSTATE_BUFFER(runstate, GlobalState),
+ VMSTATE_END_OF_LIST()
+ },
+};
+
+void register_global_state(void)
+{
+ /* We would use it independently that we receive it */
+ strcpy((char *)&global_state.runstate, "");
+ global_state.received = false;
+ vmstate_register(NULL, 0, &vmstate_globalstate, &global_state);
+}
diff --git a/migration/migration.c b/migration/migration.c
index 6e43ae3..4cda97c 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -23,6 +23,7 @@
#include "socket.h"
#include "ram.h"
#include "rdma.h"
+#include "migration/global_state.h"
#include "migration/migration.h"
#include "savevm.h"
#include "qemu-file-channel.h"
@@ -153,126 +154,6 @@ void migration_incoming_state_destroy(void)
loadvm_free_handlers(mis);
}
-
-typedef struct {
- bool optional;
- uint32_t size;
- uint8_t runstate[100];
- RunState state;
- bool received;
-} GlobalState;
-
-static GlobalState global_state;
-
-int global_state_store(void)
-{
- if (!runstate_store((char *)global_state.runstate,
- sizeof(global_state.runstate))) {
- error_report("runstate name too big: %s", global_state.runstate);
- trace_migrate_state_too_big();
- return -EINVAL;
- }
- return 0;
-}
-
-void global_state_store_running(void)
-{
- const char *state = RunState_lookup[RUN_STATE_RUNNING];
- strncpy((char *)global_state.runstate,
- state, sizeof(global_state.runstate));
-}
-
-static bool global_state_received(void)
-{
- return global_state.received;
-}
-
-static RunState global_state_get_runstate(void)
-{
- return global_state.state;
-}
-
-void global_state_set_optional(void)
-{
- global_state.optional = true;
-}
-
-static bool global_state_needed(void *opaque)
-{
- GlobalState *s = opaque;
- char *runstate = (char *)s->runstate;
-
- /* If it is not optional, it is mandatory */
-
- if (s->optional == false) {
- return true;
- }
-
- /* If state is running or paused, it is not needed */
-
- if (strcmp(runstate, "running") == 0 ||
- strcmp(runstate, "paused") == 0) {
- return false;
- }
-
- /* for any other state it is needed */
- return true;
-}
-
-static int global_state_post_load(void *opaque, int version_id)
-{
- GlobalState *s = opaque;
- Error *local_err = NULL;
- int r;
- char *runstate = (char *)s->runstate;
-
- s->received = true;
- trace_migrate_global_state_post_load(runstate);
-
- r = qapi_enum_parse(RunState_lookup, runstate, RUN_STATE__MAX,
- -1, &local_err);
-
- if (r == -1) {
- if (local_err) {
- error_report_err(local_err);
- }
- return -EINVAL;
- }
- s->state = r;
-
- return 0;
-}
-
-static void global_state_pre_save(void *opaque)
-{
- GlobalState *s = opaque;
-
- trace_migrate_global_state_pre_save((char *)s->runstate);
- s->size = strlen((char *)s->runstate) + 1;
-}
-
-static const VMStateDescription vmstate_globalstate = {
- .name = "globalstate",
- .version_id = 1,
- .minimum_version_id = 1,
- .post_load = global_state_post_load,
- .pre_save = global_state_pre_save,
- .needed = global_state_needed,
- .fields = (VMStateField[]) {
- VMSTATE_UINT32(size, GlobalState),
- VMSTATE_BUFFER(runstate, GlobalState),
- VMSTATE_END_OF_LIST()
- },
-};
-
-void register_global_state(void)
-{
- /* We would use it independently that we receive it */
- strcpy((char *)&global_state.runstate, "");
- global_state.received = false;
- vmstate_register(NULL, 0, &vmstate_globalstate, &global_state);
-}
-
static void migrate_generate_event(int new_state)
{
if (migrate_use_events()) {
diff --git a/migration/savevm.c b/migration/savevm.c
index 1caf8ee..e7c05f3 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -39,6 +39,7 @@
#include "migration/snapshot.h"
#include "migration/misc.h"
#include "migration/register.h"
+#include "migration/global_state.h"
#include "ram.h"
#include "qemu-file-channel.h"
#include "qemu-file.h"
diff --git a/vl.c b/vl.c
index 605c98f..c0796e4 100644
--- a/vl.c
+++ b/vl.c
@@ -88,6 +88,7 @@ int main(int argc, char **argv)
#include "hw/block/block.h"
#include "migration/misc.h"
#include "migration/snapshot.h"
+#include "migration/global_state.h"
#include "sysemu/tpm.h"
#include "sysemu/dma.h"
#include "audio/audio.h"
diff --git a/xen-common.c b/xen-common.c
index fd2c928..172131a 100644
--- a/xen-common.c
+++ b/xen-common.c
@@ -14,6 +14,7 @@
#include "sysemu/char.h"
#include "sysemu/accel.h"
#include "migration/migration.h"
+#include "migration/global_state.h"
//#define DEBUG_XEN
--
2.9.3
- Re: [Qemu-devel] [PATCH 25/41] migration: Export rdma.c functions in its own file, (continued)
- [Qemu-devel] [PATCH 27/41] migration: Move self_announce_delay() to misc.h, Juan Quintela, 2017/04/25
- [Qemu-devel] [PATCH 28/41] migration: Split registration functions from vmstate.h, Juan Quintela, 2017/04/25
- [Qemu-devel] [PATCH 26/41] migration: Move include/migration/block.h into migration/, Juan Quintela, 2017/04/25
- [Qemu-devel] [PATCH 29/41] migration: loadvm_free_handlers is only used in migration/, Juan Quintela, 2017/04/25
- [Qemu-devel] [PATCH 30/41] migration: Move dump_vmsate_json_to_file() to misc.h, Juan Quintela, 2017/04/25
- [Qemu-devel] [PATCH 32/41] migration: Move constants to savevm.h, Juan Quintela, 2017/04/25
- [Qemu-devel] [PATCH 31/41] migration: Move postcopy stuff to postcopy-ram.c, Juan Quintela, 2017/04/25
- [Qemu-devel] [PATCH 33/41] migration: Commands are only used inside migration.c, Juan Quintela, 2017/04/25
- [Qemu-devel] [PATCH 34/41] migration: ram_control_* are implemented in qemu_file, Juan Quintela, 2017/04/25
- [Qemu-devel] [PATCH 35/41] migration: create global_state.c,
Juan Quintela <=
- [Qemu-devel] [PATCH 37/41] migration: Move last funtions to misc.h, Juan Quintela, 2017/04/25
- [Qemu-devel] [PATCH 36/41] migration: Move more exported functions to migration/misc.h, Juan Quintela, 2017/04/25
- [Qemu-devel] [PATCH 38/41] migration: Move migration.h to migration/, Juan Quintela, 2017/04/25
- [Qemu-devel] [PATCH 39/41] exec: Create include for target_page_size(), Juan Quintela, 2017/04/25
- [Qemu-devel] [PATCH 40/41] migration: Make savevm.c target independent, Juan Quintela, 2017/04/25
- [Qemu-devel] [PATCH 41/41] migration: Remove unneeded includes, Juan Quintela, 2017/04/25
- Re: [Qemu-devel] [PATCH 00/41] Migration cleanup, Dr. David Alan Gilbert, 2017/04/27