提交 dc912121 编写于 作者: A Alex Williamson 提交者: Michael S. Tsirkin

savevm: Fix no_migrate

The no_migrate save state flag is currently only checked in the
last phase of migration.  This means that we potentially waste
a lot of time and bandwidth with the live state handlers before
we ever check the no_migrate flags.  The error message printed
when we catch a non-migratable device doesn't get printed for
a detached migration.  And, no_migrate does nothing to prevent
an incoming migration to a target that includes a non-migratable
device.  This attempts to fix all of these.

One notable difference in behavior is that an outgoing migration
now checks for non-migratable devices before ever connecting to
the target system.  This means the target will remain listening
rather than exit from failure.
Signed-off-by: NAlex Williamson <alex.williamson@redhat.com>
Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
上级 668643b0
...@@ -88,6 +88,10 @@ int do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data) ...@@ -88,6 +88,10 @@ int do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data)
return -1; return -1;
} }
if (qemu_savevm_state_blocked(mon)) {
return -1;
}
if (strstart(uri, "tcp:", &p)) { if (strstart(uri, "tcp:", &p)) {
s = tcp_start_outgoing_migration(mon, p, max_throttle, detach, s = tcp_start_outgoing_migration(mon, p, max_throttle, detach,
blk, inc); blk, inc);
......
...@@ -1401,19 +1401,13 @@ static int vmstate_load(QEMUFile *f, SaveStateEntry *se, int version_id) ...@@ -1401,19 +1401,13 @@ static int vmstate_load(QEMUFile *f, SaveStateEntry *se, int version_id)
return vmstate_load_state(f, se->vmsd, se->opaque, version_id); return vmstate_load_state(f, se->vmsd, se->opaque, version_id);
} }
static int vmstate_save(QEMUFile *f, SaveStateEntry *se) static void vmstate_save(QEMUFile *f, SaveStateEntry *se)
{ {
if (se->no_migrate) {
return -1;
}
if (!se->vmsd) { /* Old style */ if (!se->vmsd) { /* Old style */
se->save_state(f, se->opaque); se->save_state(f, se->opaque);
return 0; return;
} }
vmstate_save_state(f,se->vmsd, se->opaque); vmstate_save_state(f,se->vmsd, se->opaque);
return 0;
} }
#define QEMU_VM_FILE_MAGIC 0x5145564d #define QEMU_VM_FILE_MAGIC 0x5145564d
...@@ -1427,6 +1421,20 @@ static int vmstate_save(QEMUFile *f, SaveStateEntry *se) ...@@ -1427,6 +1421,20 @@ static int vmstate_save(QEMUFile *f, SaveStateEntry *se)
#define QEMU_VM_SECTION_FULL 0x04 #define QEMU_VM_SECTION_FULL 0x04
#define QEMU_VM_SUBSECTION 0x05 #define QEMU_VM_SUBSECTION 0x05
bool qemu_savevm_state_blocked(Monitor *mon)
{
SaveStateEntry *se;
QTAILQ_FOREACH(se, &savevm_handlers, entry) {
if (se->no_migrate) {
monitor_printf(mon, "state blocked by non-migratable device '%s'\n",
se->idstr);
return true;
}
}
return false;
}
int qemu_savevm_state_begin(Monitor *mon, QEMUFile *f, int blk_enable, int qemu_savevm_state_begin(Monitor *mon, QEMUFile *f, int blk_enable,
int shared) int shared)
{ {
...@@ -1508,7 +1516,6 @@ int qemu_savevm_state_iterate(Monitor *mon, QEMUFile *f) ...@@ -1508,7 +1516,6 @@ int qemu_savevm_state_iterate(Monitor *mon, QEMUFile *f)
int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f) int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f)
{ {
SaveStateEntry *se; SaveStateEntry *se;
int r;
cpu_synchronize_all_states(); cpu_synchronize_all_states();
...@@ -1541,11 +1548,7 @@ int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f) ...@@ -1541,11 +1548,7 @@ int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f)
qemu_put_be32(f, se->instance_id); qemu_put_be32(f, se->instance_id);
qemu_put_be32(f, se->version_id); qemu_put_be32(f, se->version_id);
r = vmstate_save(f, se); vmstate_save(f, se);
if (r < 0) {
monitor_printf(mon, "cannot migrate with device '%s'\n", se->idstr);
return r;
}
} }
qemu_put_byte(f, QEMU_VM_EOF); qemu_put_byte(f, QEMU_VM_EOF);
...@@ -1575,6 +1578,11 @@ static int qemu_savevm_state(Monitor *mon, QEMUFile *f) ...@@ -1575,6 +1578,11 @@ static int qemu_savevm_state(Monitor *mon, QEMUFile *f)
saved_vm_running = vm_running; saved_vm_running = vm_running;
vm_stop(0); vm_stop(0);
if (qemu_savevm_state_blocked(mon)) {
ret = -EINVAL;
goto out;
}
ret = qemu_savevm_state_begin(mon, f, 0, 0); ret = qemu_savevm_state_begin(mon, f, 0, 0);
if (ret < 0) if (ret < 0)
goto out; goto out;
...@@ -1692,6 +1700,10 @@ int qemu_loadvm_state(QEMUFile *f) ...@@ -1692,6 +1700,10 @@ int qemu_loadvm_state(QEMUFile *f)
unsigned int v; unsigned int v;
int ret; int ret;
if (qemu_savevm_state_blocked(default_mon)) {
return -EINVAL;
}
v = qemu_get_be32(f); v = qemu_get_be32(f);
if (v != QEMU_VM_FILE_MAGIC) if (v != QEMU_VM_FILE_MAGIC)
return -EINVAL; return -EINVAL;
......
...@@ -75,6 +75,7 @@ void qemu_announce_self(void); ...@@ -75,6 +75,7 @@ void qemu_announce_self(void);
void main_loop_wait(int nonblocking); 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 qemu_savevm_state_begin(Monitor *mon, QEMUFile *f, int blk_enable,
int shared); int shared);
int qemu_savevm_state_iterate(Monitor *mon, QEMUFile *f); int qemu_savevm_state_iterate(Monitor *mon, QEMUFile *f);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册