From patchwork Mon Mar 19 11:48:01 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 147491 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C8EF0B6EF1 for ; Mon, 19 Mar 2012 22:39:24 +1100 (EST) Received: from localhost ([::1]:40885 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9avk-0001Aa-WA for incoming@patchwork.ozlabs.org; Mon, 19 Mar 2012 07:39:16 -0400 Received: from eggs.gnu.org ([208.118.235.92]:45711) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9avB-0008Kq-Hx for qemu-devel@nongnu.org; Mon, 19 Mar 2012 07:39:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S9auo-00005v-0s for qemu-devel@nongnu.org; Mon, 19 Mar 2012 07:38:40 -0400 Received: from smtp.citrix.com ([66.165.176.89]:34516) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9aun-00005b-Ou for qemu-devel@nongnu.org; Mon, 19 Mar 2012 07:38:17 -0400 X-IronPort-AV: E=Sophos;i="4.73,611,1325480400"; d="scan'208";a="23211357" Received: from ftlpmailmx02.citrite.net ([10.13.107.66]) by FTLPIPO01.CITRIX.COM with ESMTP/TLS/RC4-MD5; 19 Mar 2012 07:37:49 -0400 Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.66) with Microsoft SMTP Server id 8.3.213.0; Mon, 19 Mar 2012 07:37:48 -0400 Received: from kaball.uk.xensource.com ([10.80.2.59] helo=localhost.localdomain) by ukmail1.uk.xensource.com with esmtp (Exim 4.69) (envelope-from ) id 1S9auF-0003qU-3X; Mon, 19 Mar 2012 11:37:43 +0000 From: Stefano Stabellini To: qemu-devel@nongnu.org Date: Mon, 19 Mar 2012 11:48:01 +0000 Message-ID: <1332157685-31701-2-git-send-email-stefano.stabellini@eu.citrix.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: References: MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.89 Cc: xen-devel@lists.xensource.com, Stefano Stabellini , jan.kiszka@siemens.com, lcapitulino@redhat.com, avi@redhat.com, anthony@codemonkey.ws Subject: [Qemu-devel] [PATCH v8 2/6] Introduce "xen-save-devices-state" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org - add an "is_ram" flag to SaveStateEntry; - register_savevm_live sets is_ram for live_savevm devices; - introduce a "xen-save-devices-state" QAPI command that can be used to save the state of all devices, but not the RAM or the block devices of the VM. Changes in v8: - rename save-devices-state to xen-save-devices-state. Changes in v7: - rename save_devices to save-devices-state. Changes in v6: - remove the is_ram parameter from register_savevm_live and sets is_ram if the device is a live_savevm device; - introduce save_devices as a QAPI command, write a better description for it; - fix CODING_STYLE; - introduce a new doc to explain the save format used by save_devices. Signed-off-by: Stefano Stabellini Reviewed-by: Anthony Liguori Acked-by: Luiz Capitulino --- docs/xen-save-devices-state.txt | 34 ++++++++++++++++++ qapi-schema.json | 19 ++++++++++ qmp-commands.hx | 27 +++++++++++++++ savevm.c | 71 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 151 insertions(+), 0 deletions(-) create mode 100644 docs/xen-save-devices-state.txt diff --git a/docs/xen-save-devices-state.txt b/docs/xen-save-devices-state.txt new file mode 100644 index 0000000..92e08db --- /dev/null +++ b/docs/xen-save-devices-state.txt @@ -0,0 +1,34 @@ += Save Devices = + +QEMU has code to load/save the state of the guest that it is running. +These are two complementary operations. Saving the state just does +that, saves the state for each device that the guest is running. + +These operations are normally used with migration (see migration.txt), +however it is also possible to save the state of all devices to file, +without saving the RAM or the block devices of the VM. + +This operation is called "xen-save-devices-state" (see +QMP/qmp-commands.txt) + + +The binary format used in the file is the following: + + +------------------------------------------- + +32 bit big endian: QEMU_VM_FILE_MAGIC +32 bit big endian: QEMU_VM_FILE_VERSION + +for_each_device +{ + 8 bit: QEMU_VM_SECTION_FULL + 32 bit big endian: section_id + 8 bit: idstr (ID string) length + string: idstr (ID string) + 32 bit big endian: instance_id + 32 bit big endian: version_id + buffer: device specific data +} + +8 bit: QEMU_VM_EOF diff --git a/qapi-schema.json b/qapi-schema.json index d0b6792..def69a9 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1593,3 +1593,22 @@ { 'command': 'qom-list-types', 'data': { '*implements': 'str', '*abstract': 'bool' }, 'returns': [ 'ObjectTypeInfo' ] } + +## +# @xen-save-devices-state: +# +# Save the state of all devices to file. The RAM and the block devices +# of the VM are not saved by this command. +# +# @filename: the file to save the state of the devices to as binary +# data. See xen-save-devices-state.txt for a description of the binary +# format. +# +# Returns: Nothing on success +# If @filename cannot be opened, OpenFileFailed +# If an I/O error occurs while writing the file, IOError +# +# Since: 1.1 +## +{ 'command': 'xen-save-devices-state', 'data': {'filename': 'str'} } + diff --git a/qmp-commands.hx b/qmp-commands.hx index 705f704..dbb6236 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -444,6 +444,33 @@ Note: inject-nmi is only supported for x86 guest currently, it will EQMP { + .name = "xen-save-devices-state", + .args_type = "filename:F", + .mhandler.cmd_new = qmp_marshal_input_xen_save_devices_state, + }, + +SQMP +xen-save-devices-state +------- + +Save the state of all devices to file. The RAM and the block devices +of the VM are not saved by this command. + +Arguments: + +- "filename": the file to save the state of the devices to as binary +data. See xen-save-devices-state.txt for a description of the binary +format. + +Example: + +-> { "execute": "xen-save-devices-state", + "arguments": { "filename": "/tmp/save" } } +<- { "return": {} } + +EQMP + + { .name = "migrate", .args_type = "detach:-d,blk:-b,inc:-i,uri:s", .params = "[-d] [-b] [-i] uri", diff --git a/savevm.c b/savevm.c index 80be1ff..0e61eb0 100644 --- a/savevm.c +++ b/savevm.c @@ -84,6 +84,7 @@ #include "qemu-timer.h" #include "cpus.h" #include "memory.h" +#include "qmp-commands.h" #define SELF_ANNOUNCE_ROUNDS 5 @@ -1177,6 +1178,7 @@ typedef struct SaveStateEntry { void *opaque; CompatEntry *compat; int no_migrate; + int is_ram; } SaveStateEntry; @@ -1241,6 +1243,10 @@ int register_savevm_live(DeviceState *dev, se->opaque = opaque; se->vmsd = NULL; se->no_migrate = 0; + /* if this is a live_savem then set is_ram */ + if (save_live_state != NULL) { + se->is_ram = 1; + } if (dev && dev->parent_bus && dev->parent_bus->info->get_dev_path) { char *id = dev->parent_bus->info->get_dev_path(dev); @@ -1728,6 +1734,45 @@ out: return ret; } +static int qemu_save_device_state(QEMUFile *f) +{ + SaveStateEntry *se; + + qemu_put_be32(f, QEMU_VM_FILE_MAGIC); + qemu_put_be32(f, QEMU_VM_FILE_VERSION); + + cpu_synchronize_all_states(); + + QTAILQ_FOREACH(se, &savevm_handlers, entry) { + int len; + + if (se->is_ram) { + continue; + } + if (se->save_state == NULL && se->vmsd == NULL) { + continue; + } + + /* Section type */ + qemu_put_byte(f, QEMU_VM_SECTION_FULL); + qemu_put_be32(f, se->section_id); + + /* ID string */ + len = strlen(se->idstr); + qemu_put_byte(f, len); + qemu_put_buffer(f, (uint8_t *)se->idstr, len); + + qemu_put_be32(f, se->instance_id); + qemu_put_be32(f, se->version_id); + + vmstate_save(f, se); + } + + qemu_put_byte(f, QEMU_VM_EOF); + + return qemu_file_get_error(f); +} + static SaveStateEntry *find_se(const char *idstr, int instance_id) { SaveStateEntry *se; @@ -2109,6 +2154,32 @@ void do_savevm(Monitor *mon, const QDict *qdict) vm_start(); } +void qmp_xen_save_devices_state(const char *filename, Error **errp) +{ + QEMUFile *f; + int saved_vm_running; + int ret; + + saved_vm_running = runstate_is_running(); + vm_stop(RUN_STATE_SAVE_VM); + + f = qemu_fopen(filename, "wb"); + if (!f) { + error_set(errp, QERR_OPEN_FILE_FAILED, filename); + goto the_end; + } + ret = qemu_save_device_state(f); + qemu_fclose(f); + if (ret < 0) { + error_set(errp, QERR_IO_ERROR); + } + + the_end: + if (saved_vm_running) + vm_start(); + return; +} + int load_vmstate(const char *name) { BlockDriverState *bs, *bs_vm_state;