[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH COLO-Frame v17 23/34] COLO: Process shutdown command
From: |
zhanghailiang |
Subject: |
[Qemu-devel] [PATCH COLO-Frame v17 23/34] COLO: Process shutdown command for VM in COLO state |
Date: |
Fri, 3 Jun 2016 15:52:35 +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>
Reviewed-by: Dr. David Alan Gilbert <address@hidden>
---
v15:
- Go on the shutdown process even some error happened
while sent 'SHUTDOWN' message to SVM.
- Add Reviewed-by tag
v14:
- Remove 'colo_shutdown' variable, use colo_shutdown_request directly
v13:
- Move COLO shutdown related codes to colo.c file (Dave's suggestion)
---
include/migration/colo.h | 2 ++
include/sysemu/sysemu.h | 3 +++
migration/colo.c | 47 +++++++++++++++++++++++++++++++++++++++++++++--
qapi-schema.json | 4 +++-
stubs/migration-colo.c | 5 +++++
vl.c | 19 ++++++++++++++++---
6 files changed, 74 insertions(+), 6 deletions(-)
diff --git a/include/migration/colo.h b/include/migration/colo.h
index e32eef4..b16c642 100644
--- a/include/migration/colo.h
+++ b/include/migration/colo.h
@@ -35,4 +35,6 @@ COLOMode get_colo_mode(void);
/* failover */
void colo_do_failover(MigrationState *s);
+
+bool colo_handle_shutdown(void);
#endif
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 9428141..b80e145 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -51,6 +51,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);
@@ -58,6 +60,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 dab615b..55c8d35 100644
--- a/migration/colo.c
+++ b/migration/colo.c
@@ -328,6 +328,21 @@ static int colo_do_checkpoint_transaction(MigrationState
*s,
goto out;
}
+ if (colo_shutdown_requested) {
+ colo_send_message(s->to_dst_file, COLO_MESSAGE_GUEST_SHUTDOWN,
+ &local_err);
+ if (local_err) {
+ error_free(local_err);
+ /* Go on the shutdown process and throw the error message */
+ error_report("Failed to send shutdown message to SVM");
+ }
+ 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;
qemu_mutex_lock_iothread();
@@ -383,8 +398,9 @@ static void colo_process_checkpoint(MigrationState *s)
}
current_time = qemu_clock_get_ms(QEMU_CLOCK_HOST);
- if (current_time - checkpoint_time <
- s->parameters.x_checkpoint_delay) {
+ if ((current_time - checkpoint_time <
+ s->parameters.x_checkpoint_delay) &&
+ !colo_shutdown_requested) {
int64_t delay_ms;
delay_ms = s->parameters.x_checkpoint_delay -
@@ -456,6 +472,16 @@ static void colo_wait_handle_message(QEMUFile *f, int
*checkpoint_request,
case COLO_MESSAGE_CHECKPOINT_REQUEST:
*checkpoint_request = 1;
break;
+ case COLO_MESSAGE_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 be exit and terminate the whole
+ * process, do need some cleanup ?
+ */
+ qemu_thread_exit(0);
default:
*checkpoint_request = 0;
error_setg(errp, "Got unknown COLO message: %d", msg);
@@ -626,3 +652,20 @@ out:
return NULL;
}
+
+bool colo_handle_shutdown(void)
+{
+ /*
+ * If VM is in COLO-FT mode, we need do some significant work before
+ * respond to the shutdown request. Besides, Secondary VM will ignore
+ * the shutdown request from users.
+ */
+ if (migration_incoming_in_colo_state()) {
+ return true;
+ }
+ if (migration_in_colo_state()) {
+ colo_shutdown_requested = 1;
+ return true;
+ }
+ return false;
+}
diff --git a/qapi-schema.json b/qapi-schema.json
index 9856567..a43ebcf 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -807,12 +807,14 @@
#
# @vmstate-loaded: VM's state has been loaded by SVM.
#
+# @guest-shutdown: shutdown require from PVM to SVM
+#
# Since: 2.7
##
{ 'enum': 'COLOMessage',
'data': [ 'checkpoint-ready', 'checkpoint-request', 'checkpoint-reply',
'vmstate-send', 'vmstate-size', 'vmstate-received',
- 'vmstate-loaded' ] }
+ 'vmstate-loaded', 'guest-shutdown' ] }
##
# @COLOMode
diff --git a/stubs/migration-colo.c b/stubs/migration-colo.c
index 7811764..167b191 100644
--- a/stubs/migration-colo.c
+++ b/stubs/migration-colo.c
@@ -44,3 +44,8 @@ void qmp_x_colo_lost_heartbeat(Error **errp)
" with --enable-colo option in order to support"
" COLO feature");
}
+
+bool colo_handle_shutdown(void)
+{
+ return false;
+}
diff --git a/vl.c b/vl.c
index 47ca1c1..e058e03 100644
--- a/vl.c
+++ b/vl.c
@@ -1646,6 +1646,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;
@@ -1779,7 +1781,10 @@ void qemu_system_guest_panicked(void)
void qemu_system_reset_request(void)
{
if (no_reboot) {
- shutdown_requested = 1;
+ qemu_system_shutdown_request();
+ if (!shutdown_requested) {/* colo handle it ? */
+ return;
+ }
} else {
reset_requested = 1;
}
@@ -1852,14 +1857,22 @@ 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 (colo_handle_shutdown()) {
+ 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 v17 28/34] COLO: Separate the process of saving/loading ram and device state, (continued)
- [Qemu-devel] [PATCH COLO-Frame v17 28/34] COLO: Separate the process of saving/loading ram and device state, zhanghailiang, 2016/06/03
- [Qemu-devel] [PATCH COLO-Frame v17 25/34] savevm: Introduce two helper functions for save/find loadvm_handlers entry, zhanghailiang, 2016/06/03
- [Qemu-devel] [PATCH COLO-Frame v17 19/34] COLO: Implement failover work for Secondary VM, zhanghailiang, 2016/06/03
- [Qemu-devel] [PATCH COLO-Frame v17 24/34] COLO: Update the global runstate after going into colo state, zhanghailiang, 2016/06/03
- [Qemu-devel] [PATCH COLO-Frame v17 05/34] migration: Integrate COLO checkpoint process into loadvm, zhanghailiang, 2016/06/03
- [Qemu-devel] [PATCH COLO-Frame v17 16/34] COLO failover: Introduce a new command to trigger a failover, zhanghailiang, 2016/06/03
- [Qemu-devel] [PATCH COLO-Frame v17 17/34] COLO failover: Introduce state to record failover process, zhanghailiang, 2016/06/03
- [Qemu-devel] [PATCH COLO-Frame v17 31/34] net: Add notifier/callback for netdev init, zhanghailiang, 2016/06/03
- [Qemu-devel] [PATCH COLO-Frame v17 34/34] COLO: Add block replication into colo process, zhanghailiang, 2016/06/03
- [Qemu-devel] [PATCH COLO-Frame v17 30/34] filter-buffer: Accept zero interval, zhanghailiang, 2016/06/03
- [Qemu-devel] [PATCH COLO-Frame v17 23/34] COLO: Process shutdown command for VM in COLO state,
zhanghailiang <=
- [Qemu-devel] [PATCH COLO-Frame v17 20/34] qmp event: Add COLO_EXIT event to notify users while exited from COLO, zhanghailiang, 2016/06/03
- [Qemu-devel] [PATCH COLO-Frame v17 33/34] COLO: Control the status of buffer filters for PVM, zhanghailiang, 2016/06/03
- [Qemu-devel] [PATCH COLO-Frame v17 32/34] COLO/filter: Add each netdev a buffer filter, zhanghailiang, 2016/06/03
- [Qemu-devel] [PATCH COLO-Frame v17 26/34] migration/savevm: Add new helpers to process the different stages of loadvm, zhanghailiang, 2016/06/03
- Re: [Qemu-devel] [PATCH COLO-Frame v17 00/34] COarse-grain LOck-stepping(COLO) Virtual Machines for Non-stop Service (FT), Dr. David Alan Gilbert, 2016/06/07