savevm: add public save_vmstate function
This patch introduces save_vmstate function to allow saving and loading vmstates from the replay module. Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru> Message-Id: <20170124071741.4572.13714.stgit@PASHA-ISP> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
1dfb1b2d34
commit
ac8c19ba74
@ -74,6 +74,7 @@ void qemu_add_machine_init_done_notifier(Notifier *notify);
|
|||||||
void qemu_remove_machine_init_done_notifier(Notifier *notify);
|
void qemu_remove_machine_init_done_notifier(Notifier *notify);
|
||||||
|
|
||||||
void hmp_savevm(Monitor *mon, const QDict *qdict);
|
void hmp_savevm(Monitor *mon, const QDict *qdict);
|
||||||
|
int save_vmstate(Monitor *mon, const char *name);
|
||||||
int load_vmstate(const char *name);
|
int load_vmstate(const char *name);
|
||||||
void hmp_delvm(Monitor *mon, const QDict *qdict);
|
void hmp_delvm(Monitor *mon, const QDict *qdict);
|
||||||
void hmp_info_snapshots(Monitor *mon, const QDict *qdict);
|
void hmp_info_snapshots(Monitor *mon, const QDict *qdict);
|
||||||
|
@ -2042,38 +2042,40 @@ int qemu_loadvm_state(QEMUFile *f)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hmp_savevm(Monitor *mon, const QDict *qdict)
|
int save_vmstate(Monitor *mon, const char *name)
|
||||||
{
|
{
|
||||||
BlockDriverState *bs, *bs1;
|
BlockDriverState *bs, *bs1;
|
||||||
QEMUSnapshotInfo sn1, *sn = &sn1, old_sn1, *old_sn = &old_sn1;
|
QEMUSnapshotInfo sn1, *sn = &sn1, old_sn1, *old_sn = &old_sn1;
|
||||||
int ret;
|
int ret = -1;
|
||||||
QEMUFile *f;
|
QEMUFile *f;
|
||||||
int saved_vm_running;
|
int saved_vm_running;
|
||||||
uint64_t vm_state_size;
|
uint64_t vm_state_size;
|
||||||
qemu_timeval tv;
|
qemu_timeval tv;
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
const char *name = qdict_get_try_str(qdict, "name");
|
|
||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
AioContext *aio_context;
|
AioContext *aio_context;
|
||||||
|
|
||||||
if (!bdrv_all_can_snapshot(&bs)) {
|
if (!bdrv_all_can_snapshot(&bs)) {
|
||||||
monitor_printf(mon, "Device '%s' is writable but does not "
|
monitor_printf(mon, "Device '%s' is writable but does not "
|
||||||
"support snapshots.\n", bdrv_get_device_name(bs));
|
"support snapshots.\n", bdrv_get_device_name(bs));
|
||||||
return;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Delete old snapshots of the same name */
|
/* Delete old snapshots of the same name */
|
||||||
if (name && bdrv_all_delete_snapshot(name, &bs1, &local_err) < 0) {
|
if (name) {
|
||||||
error_reportf_err(local_err,
|
ret = bdrv_all_delete_snapshot(name, &bs1, &local_err);
|
||||||
"Error while deleting snapshot on device '%s': ",
|
if (ret < 0) {
|
||||||
bdrv_get_device_name(bs1));
|
error_reportf_err(local_err,
|
||||||
return;
|
"Error while deleting snapshot on device '%s': ",
|
||||||
|
bdrv_get_device_name(bs1));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bs = bdrv_all_find_vmstate_bs();
|
bs = bdrv_all_find_vmstate_bs();
|
||||||
if (bs == NULL) {
|
if (bs == NULL) {
|
||||||
monitor_printf(mon, "No block device can accept snapshots\n");
|
monitor_printf(mon, "No block device can accept snapshots\n");
|
||||||
return;
|
return ret;
|
||||||
}
|
}
|
||||||
aio_context = bdrv_get_aio_context(bs);
|
aio_context = bdrv_get_aio_context(bs);
|
||||||
|
|
||||||
@ -2082,7 +2084,7 @@ void hmp_savevm(Monitor *mon, const QDict *qdict)
|
|||||||
ret = global_state_store();
|
ret = global_state_store();
|
||||||
if (ret) {
|
if (ret) {
|
||||||
monitor_printf(mon, "Error saving global state\n");
|
monitor_printf(mon, "Error saving global state\n");
|
||||||
return;
|
return ret;
|
||||||
}
|
}
|
||||||
vm_stop(RUN_STATE_SAVE_VM);
|
vm_stop(RUN_STATE_SAVE_VM);
|
||||||
|
|
||||||
@ -2128,13 +2130,22 @@ void hmp_savevm(Monitor *mon, const QDict *qdict)
|
|||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
monitor_printf(mon, "Error while creating snapshot on '%s'\n",
|
monitor_printf(mon, "Error while creating snapshot on '%s'\n",
|
||||||
bdrv_get_device_name(bs));
|
bdrv_get_device_name(bs));
|
||||||
|
goto the_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
the_end:
|
the_end:
|
||||||
aio_context_release(aio_context);
|
aio_context_release(aio_context);
|
||||||
if (saved_vm_running) {
|
if (saved_vm_running) {
|
||||||
vm_start();
|
vm_start();
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void hmp_savevm(Monitor *mon, const QDict *qdict)
|
||||||
|
{
|
||||||
|
save_vmstate(mon, qdict_get_try_str(qdict, "name"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void qmp_xen_save_devices_state(const char *filename, Error **errp)
|
void qmp_xen_save_devices_state(const char *filename, Error **errp)
|
||||||
|
Loading…
Reference in New Issue
Block a user