COLO: fix setting checkpoint-delay not working properly
If we set checkpoint-delay through command 'migrate-set-parameters', It will not take effect until we finish last sleep chekpoint-delay, That's will be offensive espeically when we want to change its value from an extreme big one to a proper value. Fix it by using timer to realize checkpoint-delay. Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com> Message-Id: <1484657864-21708-2-git-send-email-zhang.zhanghailiang@huawei.com> Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
This commit is contained in:
parent
59046ec29a
commit
479125d53e
@ -35,4 +35,6 @@ COLOMode get_colo_mode(void);
|
|||||||
|
|
||||||
/* failover */
|
/* failover */
|
||||||
void colo_do_failover(MigrationState *s);
|
void colo_do_failover(MigrationState *s);
|
||||||
|
|
||||||
|
void colo_checkpoint_notify(void *opaque);
|
||||||
#endif
|
#endif
|
||||||
|
@ -188,6 +188,11 @@ struct MigrationState
|
|||||||
/* The RAMBlock used in the last src_page_request */
|
/* The RAMBlock used in the last src_page_request */
|
||||||
RAMBlock *last_req_rb;
|
RAMBlock *last_req_rb;
|
||||||
|
|
||||||
|
/* The semaphore is used to notify COLO thread to do checkpoint */
|
||||||
|
QemuSemaphore colo_checkpoint_sem;
|
||||||
|
int64_t colo_checkpoint_time;
|
||||||
|
QEMUTimer *colo_delay_timer;
|
||||||
|
|
||||||
/* The last error that occurred */
|
/* The last error that occurred */
|
||||||
Error *error;
|
Error *error;
|
||||||
};
|
};
|
||||||
|
@ -302,7 +302,7 @@ static void colo_process_checkpoint(MigrationState *s)
|
|||||||
{
|
{
|
||||||
QIOChannelBuffer *bioc;
|
QIOChannelBuffer *bioc;
|
||||||
QEMUFile *fb = NULL;
|
QEMUFile *fb = NULL;
|
||||||
int64_t current_time, checkpoint_time = qemu_clock_get_ms(QEMU_CLOCK_HOST);
|
int64_t current_time = qemu_clock_get_ms(QEMU_CLOCK_HOST);
|
||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -332,26 +332,21 @@ static void colo_process_checkpoint(MigrationState *s)
|
|||||||
qemu_mutex_unlock_iothread();
|
qemu_mutex_unlock_iothread();
|
||||||
trace_colo_vm_state_change("stop", "run");
|
trace_colo_vm_state_change("stop", "run");
|
||||||
|
|
||||||
|
timer_mod(s->colo_delay_timer,
|
||||||
|
current_time + s->parameters.x_checkpoint_delay);
|
||||||
|
|
||||||
while (s->state == MIGRATION_STATUS_COLO) {
|
while (s->state == MIGRATION_STATUS_COLO) {
|
||||||
if (failover_get_state() != FAILOVER_STATUS_NONE) {
|
if (failover_get_state() != FAILOVER_STATUS_NONE) {
|
||||||
error_report("failover request");
|
error_report("failover request");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
current_time = qemu_clock_get_ms(QEMU_CLOCK_HOST);
|
qemu_sem_wait(&s->colo_checkpoint_sem);
|
||||||
if (current_time - checkpoint_time <
|
|
||||||
s->parameters.x_checkpoint_delay) {
|
|
||||||
int64_t delay_ms;
|
|
||||||
|
|
||||||
delay_ms = s->parameters.x_checkpoint_delay -
|
|
||||||
(current_time - checkpoint_time);
|
|
||||||
g_usleep(delay_ms * 1000);
|
|
||||||
}
|
|
||||||
ret = colo_do_checkpoint_transaction(s, bioc, fb);
|
ret = colo_do_checkpoint_transaction(s, bioc, fb);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
checkpoint_time = qemu_clock_get_ms(QEMU_CLOCK_HOST);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
@ -364,14 +359,32 @@ out:
|
|||||||
qemu_fclose(fb);
|
qemu_fclose(fb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
timer_del(s->colo_delay_timer);
|
||||||
|
|
||||||
if (s->rp_state.from_dst_file) {
|
if (s->rp_state.from_dst_file) {
|
||||||
qemu_fclose(s->rp_state.from_dst_file);
|
qemu_fclose(s->rp_state.from_dst_file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void colo_checkpoint_notify(void *opaque)
|
||||||
|
{
|
||||||
|
MigrationState *s = opaque;
|
||||||
|
int64_t next_notify_time;
|
||||||
|
|
||||||
|
qemu_sem_post(&s->colo_checkpoint_sem);
|
||||||
|
s->colo_checkpoint_time = qemu_clock_get_ms(QEMU_CLOCK_HOST);
|
||||||
|
next_notify_time = s->colo_checkpoint_time +
|
||||||
|
s->parameters.x_checkpoint_delay;
|
||||||
|
timer_mod(s->colo_delay_timer, next_notify_time);
|
||||||
|
}
|
||||||
|
|
||||||
void migrate_start_colo_process(MigrationState *s)
|
void migrate_start_colo_process(MigrationState *s)
|
||||||
{
|
{
|
||||||
qemu_mutex_unlock_iothread();
|
qemu_mutex_unlock_iothread();
|
||||||
|
qemu_sem_init(&s->colo_checkpoint_sem, 0);
|
||||||
|
s->colo_delay_timer = timer_new_ms(QEMU_CLOCK_HOST,
|
||||||
|
colo_checkpoint_notify, s);
|
||||||
|
|
||||||
migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE,
|
migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE,
|
||||||
MIGRATION_STATUS_COLO);
|
MIGRATION_STATUS_COLO);
|
||||||
colo_process_checkpoint(s);
|
colo_process_checkpoint(s);
|
||||||
|
@ -891,6 +891,9 @@ void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp)
|
|||||||
|
|
||||||
if (params->has_x_checkpoint_delay) {
|
if (params->has_x_checkpoint_delay) {
|
||||||
s->parameters.x_checkpoint_delay = params->x_checkpoint_delay;
|
s->parameters.x_checkpoint_delay = params->x_checkpoint_delay;
|
||||||
|
if (migration_in_colo_state()) {
|
||||||
|
colo_checkpoint_notify(s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user