From 87359425b073cbf612ef9441b2e88d437ea643e2 Mon Sep 17 00:00:00 2001
Message-Id: <87359425b073cbf612ef9441b2e88d437ea643e2.1301178269.git.blauwirbel@gmail.com>
In-Reply-To: <1ae00000c153f56f45a62e9520a773bbfa3d185c.1301178269.git.blauwirbel@gmail.com>
References: <1ae00000c153f56f45a62e9520a773bbfa3d185c.1301178269.git.blauwirbel@gmail.com>
From: Blue Swirl <blauwirbel@gmail.com>
Date: Sat, 26 Mar 2011 15:59:37 +0000
Subject: [PATCH 2/4] Introduce VM state
Move all state related to current VM and migration to vm-state.h.
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
arch_init.c | 1 +
audio/audio.c | 2 +-
blockdev.c | 2 +-
cpus.c | 1 +
gdbstub.c | 2 +-
hw/fw_cfg.c | 1 +
hw/ide/cmd646.c | 2 +-
hw/ide/core.c | 1 +
hw/ide/piix.c | 2 +-
hw/ide/via.c | 2 +-
hw/scsi-disk.c | 1 +
hw/smbios.c | 1 +
hw/sun4m.c | 1 +
hw/usb-msd.c | 1 +
hw/virtio.h | 1 +
hw/watchdog.c | 1 +
hw/xen_domainbuild.c | 2 +-
hw/xenfb.c | 2 +-
kvm-all.c | 1 +
migration.c | 2 +-
monitor.c | 1 +
qemu-timer.c | 1 +
savevm.c | 1 +
sysemu.h | 49 -----------------------------------------
target-i386/kvm.c | 1 +
ui/sdl.c | 1 +
vl.c | 1 +
vm-state.h | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++
28 files changed, 85 insertions(+), 58 deletions(-)
create mode 100644 vm-state.h
@@ -41,6 +41,7 @@
#include "net.h"
#include "gdbstub.h"
#include "hw/smbios.h"
+#include "vm-state.h"
#ifdef TARGET_SPARC
int graphic_width = 1024;
@@ -25,7 +25,7 @@
#include "audio.h"
#include "monitor.h"
#include "qemu-timer.h"
-#include "sysemu.h"
+#include "vm-state.h"
#define AUDIO_CAP "audio"
#include "audio_int.h"
@@ -13,9 +13,9 @@
#include "qerror.h"
#include "qemu-option.h"
#include "qemu-config.h"
-#include "sysemu.h"
#include "hw/qdev.h"
#include "block_int.h"
+#include "vm-state.h"
static QTAILQ_HEAD(drivelist, DriveInfo) drives = QTAILQ_HEAD_INITIALIZER(drives);
@@ -35,6 +35,7 @@
#include "qemu-thread.h"
#include "cpus.h"
#include "compatfd.h"
+#include "vm-state.h"
#ifdef SIGRTMIN
#define SIG_IPI (SIGRTMIN+4)
@@ -31,8 +31,8 @@
#else
#include "monitor.h"
#include "qemu-char.h"
-#include "sysemu.h"
#include "gdbstub.h"
+#include "vm-state.h"
#endif
#define MAX_PACKET_LENGTH 4096
@@ -27,6 +27,7 @@
#include "fw_cfg.h"
#include "sysbus.h"
#include "host-state.h"
+#include "vm-state.h"
/* debug firmware config */
//#define DEBUG_FW_CFG
@@ -28,8 +28,8 @@
#include <hw/isa.h>
#include "block.h"
#include "block_int.h"
-#include "sysemu.h"
#include "dma.h"
+#include "vm-state.h"
#include <hw/ide/pci.h>
@@ -33,6 +33,7 @@
#include "blockdev.h"
#include <hw/ide/internal.h>
+#include "vm-state.h"
/* These values were based on a Seagate ST3500418AS but have been modified
to make more sense in QEMU */
@@ -28,8 +28,8 @@
#include <hw/isa.h>
#include "block.h"
#include "block_int.h"
-#include "sysemu.h"
#include "dma.h"
+#include "vm-state.h"
#include <hw/ide/pci.h>
@@ -29,8 +29,8 @@
#include <hw/isa.h>
#include "block.h"
#include "block_int.h"
-#include "sysemu.h"
#include "dma.h"
+#include "vm-state.h"
#include <hw/ide/pci.h>
@@ -37,6 +37,7 @@ do { fprintf(stderr, "scsi-disk: " fmt , ## __VA_ARGS__); } while (0)
#include "scsi-defs.h"
#include "sysemu.h"
#include "blockdev.h"
+#include "vm-state.h"
#define SCSI_DMA_BUF_SIZE 131072
#define SCSI_MAX_INQUIRY_LEN 256
@@ -14,6 +14,7 @@
#include "sysemu.h"
#include "smbios.h"
#include "loader.h"
+#include "vm-state.h"
/*
* Structures shared with the BIOS
@@ -42,6 +42,7 @@
#include "elf.h"
#include "blockdev.h"
#include "trace.h"
+#include "host-state.h"
/*
* Sun4m architecture was used in the following machines:
@@ -17,6 +17,7 @@
#include "monitor.h"
#include "sysemu.h"
#include "blockdev.h"
+#include "vm-state.h"
//#define DEBUG_MSD
@@ -20,6 +20,7 @@
#include "sysemu.h"
#include "block_int.h"
#include "event_notifier.h"
+#include "vm-state.h"
#ifdef CONFIG_LINUX
#include "9p.h"
#endif
@@ -27,6 +27,7 @@
#include "monitor.h"
#include "sysemu.h"
#include "hw/watchdog.h"
+#include "vm-state.h"
/* Possible values for action parameter. */
#define WDT_RESET 1 /* Hard reset. */
@@ -1,10 +1,10 @@
#include <signal.h>
#include "xen_backend.h"
#include "xen_domainbuild.h"
-#include "sysemu.h"
#include "qemu-timer.h"
#include "qemu-log.h"
#include "host-state.h"
+#include "vm-state.h"
#include <xenguest.h>
@@ -44,10 +44,10 @@
#include <xen/io/protocols.h>
#include "hw.h"
-#include "sysemu.h"
#include "console.h"
#include "qemu-char.h"
#include "xen_backend.h"
+#include "vm-state.h"
#ifndef BTN_LEFT
#define BTN_LEFT 0x110 /* from <linux/input.h> */
@@ -27,6 +27,7 @@
#include "gdbstub.h"
#include "kvm.h"
#include "bswap.h"
+#include "vm-state.h"
/* This check must be after config-host.h is included */
#ifdef CONFIG_EVENTFD
@@ -15,11 +15,11 @@
#include "migration.h"
#include "monitor.h"
#include "buffered_file.h"
-#include "sysemu.h"
#include "block.h"
#include "qemu_socket.h"
#include "block-migration.h"
#include "qemu-objects.h"
+#include "vm-state.h"
//#define DEBUG_MIGRATION
@@ -62,6 +62,7 @@
#endif
#include "ui/qemu-spice.h"
#include "host-state.h"
+#include "vm-state.h"
//#define DEBUG
//#define DEBUG_COMPLETION
@@ -53,6 +53,7 @@
#include <mmsystem.h>
#endif
+#include "vm-state.h"
#include "qemu-timer.h"
/* Conversion factor from emulated instructions to virtual clock ticks. */
@@ -82,6 +82,7 @@
#include "migration.h"
#include "qemu_socket.h"
#include "qemu-queue.h"
+#include "vm-state.h"
#define SELF_ANNOUNCE_ROUNDS 5
@@ -24,35 +24,6 @@ extern const char *bios_name;
#define QEMU_FILE_TYPE_KEYMAP 1
char *qemu_find_file(int type, const char *name);
-extern int vm_running;
-extern uint8_t qemu_uuid[];
-int qemu_uuid_parse(const char *str, uint8_t *uuid);
-#define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
-
-typedef struct vm_change_state_entry VMChangeStateEntry;
-typedef void VMChangeStateHandler(void *opaque, int running, int reason);
-
-VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
- void *opaque);
-void qemu_del_vm_change_state_handler(VMChangeStateEntry *e);
-
-#define VMSTOP_USER 0
-#define VMSTOP_DEBUG 1
-#define VMSTOP_SHUTDOWN 2
-#define VMSTOP_DISKFULL 3
-#define VMSTOP_WATCHDOG 4
-#define VMSTOP_PANIC 5
-#define VMSTOP_SAVEVM 6
-#define VMSTOP_LOADVM 7
-#define VMSTOP_MIGRATE 8
-
-void vm_start(void);
-void vm_stop(int reason);
-
-uint64_t ram_bytes_remaining(void);
-uint64_t ram_bytes_transferred(void);
-uint64_t ram_bytes_total(void);
-
int64_t cpu_get_ticks(void);
void cpu_enable_ticks(void);
void cpu_disable_ticks(void);
@@ -61,7 +32,6 @@ void qemu_system_reset_request(void);
void qemu_system_shutdown_request(void);
void qemu_system_powerdown_request(void);
void qemu_system_debug_request(void);
-void qemu_system_vmstop_request(int reason);
int qemu_shutdown_requested(void);
int qemu_reset_requested(void);
int qemu_powerdown_requested(void);
@@ -70,35 +40,16 @@ void qemu_system_reset(void);
void qemu_add_machine_init_done_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);
-void do_info_snapshots(Monitor *mon);
-
void cpu_synchronize_all_states(void);
void cpu_synchronize_all_post_reset(void);
void cpu_synchronize_all_post_init(void);
-void qemu_announce_self(void);
-
-void main_loop_wait(int nonblocking);
-
-bool qemu_savevm_state_blocked(Monitor *mon);
-int qemu_savevm_state_begin(Monitor *mon, QEMUFile *f, int blk_enable,
- int shared);
-int qemu_savevm_state_iterate(Monitor *mon, QEMUFile *f);
-int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f);
-void qemu_savevm_state_cancel(Monitor *mon, QEMUFile *f);
-int qemu_loadvm_state(QEMUFile *f);
-
/* OS specific functions */
void os_setup_early_signal_handling(void);
char *os_find_datadir(const char *argv0);
void os_parse_cmd_args(int index, const char *optarg);
void os_pidfile_error(void);
-extern int autostart;
-extern int incoming_expected;
extern int bios_size;
typedef enum {
@@ -28,6 +28,7 @@
#include "hw/pc.h"
#include "hw/apic.h"
#include "ioport.h"
+#include "vm-state.h"
#ifdef CONFIG_KVM_PARA
#include <linux/kvm_para.h>
@@ -38,6 +38,7 @@
#include "x_keymap.h"
#include "sdl_zoom.h"
#include "host-state.h"
+#include "vm-state.h"
static DisplayChangeListener *dcl;
static SDL_Surface *real_screen;
@@ -161,6 +161,7 @@ int main(int argc, char **argv)
#include "cpus.h"
#include "arch_init.h"
#include "host-state.h"
+#include "vm-state.h"
#include "ui/qemu-spice.h"
new file mode 100644
@@ -0,0 +1,59 @@
+#ifndef QEMU_VM_STATE_H
+#define QEMU_VM_STATE_H
+/*
+ * VM state: All state related to current VM, migration. Usually not
+ * guest visible except for PV.
+ */
+
+#include "qdict.h"
+
+extern int vm_running;
+extern uint8_t qemu_uuid[];
+int qemu_uuid_parse(const char *str, uint8_t *uuid);
+#define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
+
+typedef struct vm_change_state_entry VMChangeStateEntry;
+typedef void VMChangeStateHandler(void *opaque, int running, int reason);
+
+VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
+ void *opaque);
+void qemu_del_vm_change_state_handler(VMChangeStateEntry *e);
+
+#define VMSTOP_USER 0
+#define VMSTOP_DEBUG 1
+#define VMSTOP_SHUTDOWN 2
+#define VMSTOP_DISKFULL 3
+#define VMSTOP_WATCHDOG 4
+#define VMSTOP_PANIC 5
+#define VMSTOP_SAVEVM 6
+#define VMSTOP_LOADVM 7
+#define VMSTOP_MIGRATE 8
+
+void vm_start(void);
+void vm_stop(int reason);
+
+uint64_t ram_bytes_remaining(void);
+uint64_t ram_bytes_transferred(void);
+uint64_t ram_bytes_total(void);
+
+void qemu_system_vmstop_request(int reason);
+void do_savevm(Monitor *mon, const QDict *qdict);
+int load_vmstate(const char *name);
+void do_delvm(Monitor *mon, const QDict *qdict);
+void do_info_snapshots(Monitor *mon);
+
+bool qemu_savevm_state_blocked(Monitor *mon);
+int qemu_savevm_state_begin(Monitor *mon, QEMUFile *f, int blk_enable,
+ int shared);
+int qemu_savevm_state_iterate(Monitor *mon, QEMUFile *f);
+int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f);
+void qemu_savevm_state_cancel(Monitor *mon, QEMUFile *f);
+int qemu_loadvm_state(QEMUFile *f);
+void qemu_announce_self(void);
+
+extern int autostart;
+extern int incoming_expected;
+
+void main_loop_wait(int nonblocking);
+
+#endif
--
1.7.2.5
Move all state related to current VM and migration to vm-state.h. Signed-off-by: Blue Swirl <blauwirbel@gmail.com> --- arch_init.c | 1 + audio/audio.c | 2 +- blockdev.c | 2 +- cpus.c | 1 + gdbstub.c | 2 +- hw/fw_cfg.c | 1 + hw/ide/cmd646.c | 2 +- hw/ide/core.c | 1 + hw/ide/piix.c | 2 +- hw/ide/via.c | 2 +- hw/scsi-disk.c | 1 + hw/smbios.c | 1 + hw/sun4m.c | 1 + hw/usb-msd.c | 1 + hw/virtio.h | 1 + hw/watchdog.c | 1 + hw/xen_domainbuild.c | 2 +- hw/xenfb.c | 2 +- kvm-all.c | 1 + migration.c | 2 +- monitor.c | 1 + qemu-timer.c | 1 + savevm.c | 1 + sysemu.h | 49 ----------------------------------------- target-i386/kvm.c | 1 + ui/sdl.c | 1 + vl.c | 1 + vm-state.h | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ 28 files changed, 85 insertions(+), 58 deletions(-) create mode 100644 vm-state.h +#endif