[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH COLO-Frame v11 29/39] COLO: Process shutdown command
From: |
zhanghailiang |
Subject: |
[Qemu-devel] [PATCH COLO-Frame v11 29/39] COLO: Process shutdown command for VM in COLO state |
Date: |
Tue, 24 Nov 2015 17:25:39 +0800 |
If VM is in COLO FT state, we should do some extra work before normal shutdown
process. SVM will ignore the shutdown command if this command is issued directly
to it, PVM will send the shutdown command to SVM if it gets this command.
Cc: Paolo Bonzini <address@hidden>
Signed-off-by: zhanghailiang <address@hidden>
Signed-off-by: Li Zhijian <address@hidden>
---
include/sysemu/sysemu.h | 3 +++
migration/colo.c | 25 +++++++++++++++++++++++--
qapi-schema.json | 4 +++-
vl.c | 26 ++++++++++++++++++++++++--
4 files changed, 53 insertions(+), 5 deletions(-)
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 3bb8897..91eeda3 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -52,6 +52,8 @@ typedef enum WakeupReason {
QEMU_WAKEUP_REASON_OTHER,
} WakeupReason;
+extern int colo_shutdown_requested;
+
void qemu_system_reset_request(void);
void qemu_system_suspend_request(void);
void qemu_register_suspend_notifier(Notifier *notifier);
@@ -59,6 +61,7 @@ void qemu_system_wakeup_request(WakeupReason reason);
void qemu_system_wakeup_enable(WakeupReason reason, bool enabled);
void qemu_register_wakeup_notifier(Notifier *notifier);
void qemu_system_shutdown_request(void);
+void qemu_system_shutdown_request_core(void);
void qemu_system_powerdown_request(void);
void qemu_register_powerdown_notifier(Notifier *notifier);
void qemu_system_debug_request(void);
diff --git a/migration/colo.c b/migration/colo.c
index e247d70..771ff42 100644
--- a/migration/colo.c
+++ b/migration/colo.c
@@ -206,6 +206,7 @@ static int colo_do_checkpoint_transaction(MigrationState *s,
{
int ret;
uint64_t value;
+ int colo_shutdown;
size_t size;
QEMUFile *trans = NULL;
@@ -233,6 +234,7 @@ static int colo_do_checkpoint_transaction(MigrationState *s,
ret = -1;
goto out;
}
+ colo_shutdown = colo_shutdown_requested;
vm_stop_force_state(RUN_STATE_COLO);
qemu_mutex_unlock_iothread();
trace_colo_vm_state_change("run", "stop");
@@ -286,6 +288,15 @@ static int colo_do_checkpoint_transaction(MigrationState
*s,
goto out;
}
+ if (colo_shutdown) {
+ colo_ctl_put(s->to_dst_file, COLO_COMMAND_GUEST_SHUTDOWN, 0);
+ qemu_fflush(s->to_dst_file);
+ colo_shutdown_requested = 0;
+ qemu_system_shutdown_request_core();
+ /* Fix me: Just let the colo thread exit ? */
+ qemu_thread_exit(0);
+ }
+
ret = 0;
/* Resume primary guest */
qemu_mutex_lock_iothread();
@@ -347,8 +358,9 @@ static void colo_process_checkpoint(MigrationState *s)
}
current_time = qemu_clock_get_ms(QEMU_CLOCK_HOST);
- if (current_time - checkpoint_time <
- s->parameters[MIGRATION_PARAMETER_CHECKPOINT_DELAY]) {
+ if ((current_time - checkpoint_time <
+ s->parameters[MIGRATION_PARAMETER_CHECKPOINT_DELAY]) &&
+ !colo_shutdown_requested) {
int64_t delay_ms;
delay_ms = s->parameters[MIGRATION_PARAMETER_CHECKPOINT_DELAY] -
@@ -443,6 +455,15 @@ static int colo_wait_handle_cmd(QEMUFile *f, int
*checkpoint_request)
case COLO_COMMAND_CHECKPOINT_REQUEST:
*checkpoint_request = 1;
return 0;
+ case COLO_COMMAND_GUEST_SHUTDOWN:
+ qemu_mutex_lock_iothread();
+ vm_stop_force_state(RUN_STATE_COLO);
+ qemu_system_shutdown_request_core();
+ qemu_mutex_unlock_iothread();
+ /* the main thread will exit and termiante the whole
+ * process, do we need some cleanup?
+ */
+ qemu_thread_exit(0);
default:
return -EINVAL;
}
diff --git a/qapi-schema.json b/qapi-schema.json
index 981e9b2..cabca1e 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -758,12 +758,14 @@
#
# @vmstate-loaded: VM's state has been loaded by SVM
#
+# @guest-shutdown: shutdown require from PVM to SVM
+#
# Since: 2.6
##
{ 'enum': 'COLOCommand',
'data': [ 'invalid', 'checkpoint-ready', 'checkpoint-request',
'checkpoint-reply', 'vmstate-send', 'vmstate-size',
- 'vmstate-received', 'vmstate-loaded' ] }
+ 'vmstate-received', 'vmstate-loaded', 'guest-shutdown' ] }
##
# @COLOMode
diff --git a/vl.c b/vl.c
index 083a60c..8dc34ce 100644
--- a/vl.c
+++ b/vl.c
@@ -1636,6 +1636,8 @@ static NotifierList wakeup_notifiers =
NOTIFIER_LIST_INITIALIZER(wakeup_notifiers);
static uint32_t wakeup_reason_mask = ~(1 << QEMU_WAKEUP_REASON_NONE);
+int colo_shutdown_requested;
+
int qemu_shutdown_requested_get(void)
{
return shutdown_requested;
@@ -1767,6 +1769,10 @@ void qemu_system_guest_panicked(void)
void qemu_system_reset_request(void)
{
if (no_reboot) {
+ qemu_system_shutdown_request();
+ if (!shutdown_requested) {/* colo handle it ? */
+ return;
+ }
shutdown_requested = 1;
} else {
reset_requested = 1;
@@ -1840,14 +1846,30 @@ void qemu_system_killed(int signal, pid_t pid)
qemu_notify_event();
}
-void qemu_system_shutdown_request(void)
+void qemu_system_shutdown_request_core(void)
{
- trace_qemu_system_shutdown_request();
replay_shutdown_request();
shutdown_requested = 1;
qemu_notify_event();
}
+void qemu_system_shutdown_request(void)
+{
+ trace_qemu_system_shutdown_request();
+ /*
+ * if in colo mode, we need do some significant work before respond to the
+ * shutdown request.
+ */
+ if (migration_incoming_in_colo_state()) {
+ return ; /* primary's responsibility */
+ }
+ if (migration_in_colo_state()) {
+ colo_shutdown_requested = 1;
+ return;
+ }
+ qemu_system_shutdown_request_core();
+}
+
static void qemu_system_powerdown(void)
{
qapi_event_send_powerdown(&error_abort);
--
1.8.3.1
- [Qemu-devel] [PATCH COLO-Frame v11 18/39] COLO: Flush PVM's cached RAM into SVM's memory, (continued)
- [Qemu-devel] [PATCH COLO-Frame v11 18/39] COLO: Flush PVM's cached RAM into SVM's memory, zhanghailiang, 2015/11/24
- [Qemu-devel] [PATCH COLO-Frame v11 15/39] COLO: Load PVM's dirty pages into SVM's RAM cache temporarily, zhanghailiang, 2015/11/24
- [Qemu-devel] [PATCH COLO-Frame v11 16/39] ram/COLO: Record the dirty pages that SVM received, zhanghailiang, 2015/11/24
- [Qemu-devel] [PATCH COLO-Frame v11 21/39] COLO failover: Introduce a new command to trigger a failover, zhanghailiang, 2015/11/24
- [Qemu-devel] [PATCH COLO-Frame v11 24/39] COLO: Implement failover work for Secondary VM, zhanghailiang, 2015/11/24
- [Qemu-devel] [PATCH COLO-Frame v11 17/39] COLO: Load VMState into qsb before restore it, zhanghailiang, 2015/11/24
- [Qemu-devel] [PATCH COLO-Frame v11 22/39] COLO failover: Introduce state to record failover process, zhanghailiang, 2015/11/24
- [Qemu-devel] [PATCH COLO-Frame v11 27/39] COLO failover: Shutdown related socket fd when do failover, zhanghailiang, 2015/11/24
- [Qemu-devel] [PATCH COLO-Frame v11 33/39] COLO: Split qemu_savevm_state_begin out of checkpoint process, zhanghailiang, 2015/11/24
- [Qemu-devel] [PATCH COLO-Frame v11 29/39] COLO: Process shutdown command for VM in COLO state,
zhanghailiang <=
- [Qemu-devel] [PATCH COLO-Frame v11 37/39] filter-buffer: Introduce a helper function to release packets, zhanghailiang, 2015/11/24
- [Qemu-devel] [PATCH COLO-Frame v11 31/39] savevm: Split load vm state function qemu_loadvm_state, zhanghailiang, 2015/11/24
- [Qemu-devel] [PATCH COLO-Frame v11 39/39] COLO: Add block replication into colo process, zhanghailiang, 2015/11/24
- [Qemu-devel] [PATCH COLO-Frame v11 36/39] filter-buffer: Introduce a helper function to enable/disable default filter, zhanghailiang, 2015/11/24
- [Qemu-devel] [PATCH COLO-Frame v11 35/39] filter-buffer: Accept zero interval, zhanghailiang, 2015/11/24