@@ -2900,6 +2900,14 @@ F: net/colo*
F: net/filter-rewriter.c
F: net/filter-mirror.c
+CPR
+M: Steve Sistare <steven.sistare@oracle.com>
+M: Mark Kanda <mark.kanda@oracle.com>
+S: Maintained
+F: include/migration/cpr.h
+F: migration/cpr.c
+F: qapi/cpr.json
+
Record/replay
M: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
R: Paolo Bonzini <pbonzini@redhat.com>
new file mode 100644
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2021 Oracle and/or its affiliates.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef MIGRATION_CPR_H
+#define MIGRATION_CPR_H
+
+#include "qapi/qapi-types-cpr.h"
+
+#define CPR_MODE_NONE ((CprMode)(-1))
+
+CprMode cpr_mode(void);
+
+#endif
new file mode 100644
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) 2021 Oracle and/or its affiliates.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "exec/memory.h"
+#include "io/channel-buffer.h"
+#include "io/channel-file.h"
+#include "migration.h"
+#include "migration/cpr.h"
+#include "migration/global_state.h"
+#include "migration/misc.h"
+#include "migration/snapshot.h"
+#include "qapi/error.h"
+#include "qapi/qapi-commands-cpr.h"
+#include "qapi/qmp/qerror.h"
+#include "qemu-file-channel.h"
+#include "qemu-file.h"
+#include "savevm.h"
+#include "sysemu/cpu-timers.h"
+#include "sysemu/replay.h"
+#include "sysemu/runstate.h"
+#include "sysemu/runstate-action.h"
+#include "sysemu/sysemu.h"
+#include "sysemu/xen.h"
+
+static CprMode cpr_active_mode = CPR_MODE_NONE;
+
+CprMode cpr_mode(void)
+{
+ return cpr_active_mode;
+}
+
+void qmp_cpr_save(const char *filename, CprMode mode, Error **errp)
+{
+ int ret;
+ QEMUFile *f;
+ int flags = O_CREAT | O_WRONLY | O_TRUNC;
+ int saved_vm_running = runstate_is_running();
+
+ if (qemu_check_ram_volatile(errp)) {
+ return;
+ }
+
+ if (migrate_colo_enabled()) {
+ error_setg(errp, "cpr-save does not support x-colo");
+ return;
+ }
+
+ if (replay_mode != REPLAY_MODE_NONE) {
+ error_setg(errp, "cpr-save does not support replay");
+ return;
+ }
+
+ if (global_state_store()) {
+ error_setg(errp, "Error saving global state");
+ return;
+ }
+
+ f = qemu_file_open(filename, flags, 0600, "cpr-save", errp);
+ if (!f) {
+ return;
+ }
+
+ if (runstate_check(RUN_STATE_SUSPENDED)) {
+ /* Update timers_state before saving. Suspend did not so do. */
+ cpu_disable_ticks();
+ }
+ vm_stop(RUN_STATE_SAVE_VM);
+
+ cpr_active_mode = mode;
+ ret = qemu_save_device_state(f);
+ qemu_fclose(f);
+ if (ret < 0) {
+ error_setg(errp, "Error %d while saving VM state", ret);
+ goto err;
+ }
+
+ return;
+
+err:
+ if (saved_vm_running) {
+ vm_start();
+ }
+ cpr_active_mode = CPR_MODE_NONE;
+}
+
+void qmp_cpr_load(const char *filename, Error **errp)
+{
+ QEMUFile *f;
+ int ret;
+ RunState state;
+
+ if (runstate_is_running()) {
+ error_setg(errp, "cpr-load called for a running VM");
+ return;
+ }
+
+ f = qemu_file_open(filename, O_RDONLY, 0, "cpr-load", errp);
+ if (!f) {
+ return;
+ }
+
+ if (qemu_get_be32(f) != QEMU_VM_FILE_MAGIC ||
+ qemu_get_be32(f) != QEMU_VM_FILE_VERSION) {
+ error_setg(errp, "%s is not a vmstate file", filename);
+ qemu_fclose(f);
+ return;
+ }
+
+ cpr_active_mode = CPR_MODE_REBOOT; /* generalized in a later patch */
+
+ ret = qemu_load_device_state(f);
+ qemu_fclose(f);
+ if (ret < 0) {
+ error_setg(errp, "Error %d while loading VM state", ret);
+ goto out;
+ }
+
+ state = global_state_get_runstate();
+ if (state == RUN_STATE_RUNNING) {
+ vm_start();
+ } else {
+ runstate_set(state);
+ if (runstate_check(RUN_STATE_SUSPENDED)) {
+ /* Force vm_start to be called later. */
+ qemu_system_start_on_wakeup_request();
+ }
+ }
+
+out:
+ cpr_active_mode = CPR_MODE_NONE;
+}
@@ -15,6 +15,7 @@ softmmu_ss.add(files(
'channel.c',
'colo-failover.c',
'colo.c',
+ 'cpr.c',
'exec.c',
'fd.c',
'global_state.c',
new file mode 100644
@@ -0,0 +1,56 @@
+# -*- Mode: Python -*-
+#
+# Copyright (c) 2021 Oracle and/or its affiliates.
+#
+# This work is licensed under the terms of the GNU GPL, version 2.
+# See the COPYING file in the top-level directory.
+
+##
+# = CPR - CheckPoint and Restart
+##
+
+{ 'include': 'common.json' }
+
+##
+# @CprMode:
+#
+# @reboot: checkpoint can be cpr-load'ed after a host kexec reboot.
+#
+# Since: 6.2
+##
+{ 'enum': 'CprMode',
+ 'data': [ 'reboot' ] }
+
+##
+# @cpr-save:
+#
+# Create a checkpoint of the virtual machine device state in @filename.
+# Unlike snapshot-save, this command completes synchronously, saves state
+# to an ordinary file, and does not save guest RAM or guest block device
+# blocks. The caller must not modify guest block devices between cpr-save
+# and cpr-load.
+#
+# For reboot mode, all guest RAM objects must be non-volatile across reboot,
+# and created with the share=on parameter.
+#
+# @filename: name of checkpoint file
+# @mode: @CprMode mode
+#
+# Since: 6.2
+##
+{ 'command': 'cpr-save',
+ 'data': { 'filename': 'str',
+ 'mode': 'CprMode' } }
+
+##
+# @cpr-load:
+#
+# Start virtual machine from checkpoint file that was created earlier using
+# the cpr-save command.
+#
+# @filename: name of checkpoint file
+#
+# Since: 6.2
+##
+{ 'command': 'cpr-load',
+ 'data': { 'filename': 'str' } }
@@ -27,6 +27,7 @@ qapi_all_modules = [
'common',
'compat',
'control',
+ 'cpr',
'crypto',
'dump',
'error',
@@ -77,6 +77,7 @@
{ 'include': 'ui.json' }
{ 'include': 'authz.json' }
{ 'include': 'migration.json' }
+{ 'include': 'cpr.json' }
{ 'include': 'transaction.json' }
{ 'include': 'trace.json' }
{ 'include': 'compat.json' }
Provide the cpr-save and cpr-load functions for live update. These save and restore VM state, with minimal guest pause time, so that qemu may be updated to a new version in between. cpr-save stops the VM and saves vmstate to an ordinary file. It supports any type of guest image and block device, but the caller must not modify guest block devices between cpr-save and cpr-load. cpr-save supports several modes, the first of which is reboot. In this mode, the caller invokes cpr-save and then terminates qemu. The caller may then update the host kernel and system software and reboot. The caller resumes the guest by running qemu with the same arguments as the original process and invoking cpr-load. To use this mode, guest ram must be mapped to a persistent shared memory file such as /dev/dax0.0 or /dev/shm PKRAM. The reboot mode supports vfio devices if the caller first suspends the guest, such as by issuing guest-suspend-ram to the qemu guest agent. The guest drivers' suspend methods flush outstanding requests and re-initialize the devices, and thus there is no device state to save and restore. cpr-load loads state from the file. If the VM was running at cpr-save time, then VM execution resumes. If the VM was suspended at cpr-save time, then the caller must issue a system_wakeup command to resume. cpr-save syntax: { 'enum': 'CprMode', 'data': [ 'reboot' ] } { 'command': 'cpr-save', 'data': { 'filename': 'str', 'mode': 'CprMode' }} cpr-load syntax: { 'command': 'cpr-load', 'data': { 'filename': 'str' } } Signed-off-by: Steve Sistare <steven.sistare@oracle.com> --- MAINTAINERS | 8 +++ include/migration/cpr.h | 17 ++++++ migration/cpr.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++ migration/meson.build | 1 + qapi/cpr.json | 56 ++++++++++++++++++++ qapi/meson.build | 1 + qapi/qapi-schema.json | 1 + 7 files changed, 220 insertions(+) create mode 100644 include/migration/cpr.h create mode 100644 migration/cpr.c create mode 100644 qapi/cpr.json